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"
57 #include "../lib/tsocket/tsocket.h"
58 #include "rpc_client/cli_winreg_spoolss.h"
60 /* macros stolen from s4 spoolss server */
61 #define SPOOLSS_BUFFER_UNION(fn,info,level) \
62 ((info)?ndr_size_##fn(info, level, 0):0)
64 #define SPOOLSS_BUFFER_UNION_ARRAY(mem_ctx,fn,info,level,count) \
65 ((info)?ndr_size_##fn##_info(mem_ctx, level, count, info):0)
67 #define SPOOLSS_BUFFER_ARRAY(mem_ctx,fn,info,count) \
68 ((info)?ndr_size_##fn##_info(mem_ctx, count, info):0)
70 #define SPOOLSS_BUFFER_OK(val_true,val_false) ((r->in.offered >= *r->out.needed)?val_true:val_false)
73 #define DBGC_CLASS DBGC_RPC_SRV
75 #ifndef MAX_OPEN_PRINTER_EXS
76 #define MAX_OPEN_PRINTER_EXS 50
79 struct notify_back_channel
;
81 /* structure to store the printer handles */
82 /* and a reference to what it's pointing to */
83 /* and the notify info asked about */
84 /* that's the central struct */
85 struct printer_handle
{
86 struct printer_handle
*prev
, *next
;
87 bool document_started
;
89 uint32 jobid
; /* jobid in printing backend */
91 const char *servername
;
94 uint32 access_granted
;
100 struct spoolss_NotifyOption
*option
;
101 struct policy_handle cli_hnd
;
102 struct notify_back_channel
*cli_chan
;
104 /* are we in a FindNextPrinterChangeNotify() call? */
106 struct messaging_context
*msg_ctx
;
113 /* devmode sent in the OpenPrinter() call */
114 struct spoolss_DeviceMode
*devmode
;
116 /* TODO cache the printer info2 structure */
117 struct spoolss_PrinterInfo2
*info2
;
121 static struct printer_handle
*printers_list
;
123 struct printer_session_counter
{
124 struct printer_session_counter
*next
;
125 struct printer_session_counter
*prev
;
131 static struct printer_session_counter
*counter_list
;
133 struct notify_back_channel
{
134 struct notify_back_channel
*prev
, *next
;
136 /* associated client */
137 struct sockaddr_storage client_address
;
139 /* print notify back-channel pipe handle*/
140 struct rpc_pipe_client
*cli_pipe
;
141 struct dcerpc_binding_handle
*binding_handle
;
142 uint32_t active_connections
;
145 static struct notify_back_channel
*back_channels
;
147 /* Map generic permissions to printer object specific permissions */
149 const struct standard_mapping printer_std_mapping
= {
156 /* Map generic permissions to print server object specific permissions */
158 const struct standard_mapping printserver_std_mapping
= {
165 /* API table for Xcv Monitor functions */
167 struct xcv_api_table
{
169 WERROR(*fn
) (TALLOC_CTX
*mem_ctx
, struct security_token
*token
, DATA_BLOB
*in
, DATA_BLOB
*out
, uint32_t *needed
);
172 static void prune_printername_cache(void);
174 /********************************************************************
175 * Canonicalize servername.
176 ********************************************************************/
178 static const char *canon_servername(const char *servername
)
180 const char *pservername
= servername
;
181 while (*pservername
== '\\') {
187 /* translate between internal status numbers and NT status numbers */
188 static int nt_printj_status(int v
)
194 return JOB_STATUS_PAUSED
;
196 return JOB_STATUS_SPOOLING
;
198 return JOB_STATUS_PRINTING
;
200 return JOB_STATUS_ERROR
;
202 return JOB_STATUS_DELETING
;
204 return JOB_STATUS_OFFLINE
;
206 return JOB_STATUS_PAPEROUT
;
208 return JOB_STATUS_PRINTED
;
210 return JOB_STATUS_DELETED
;
212 return JOB_STATUS_BLOCKED_DEVQ
;
213 case LPQ_USER_INTERVENTION
:
214 return JOB_STATUS_USER_INTERVENTION
;
219 static int nt_printq_status(int v
)
223 return PRINTER_STATUS_PAUSED
;
232 /***************************************************************************
233 Disconnect from the client
234 ****************************************************************************/
236 static void srv_spoolss_replycloseprinter(int snum
,
237 struct printer_handle
*prn_hnd
)
243 * Tell the specific printing tdb we no longer want messages for this printer
244 * by deregistering our PID.
247 if (!print_notify_deregister_pid(snum
)) {
248 DEBUG(0, ("Failed to register our pid for printer %s\n",
249 lp_const_servicename(snum
)));
252 /* weird if the test succeeds !!! */
253 if (prn_hnd
->notify
.cli_chan
== NULL
||
254 prn_hnd
->notify
.cli_chan
->active_connections
== 0) {
255 DEBUG(0, ("Trying to close unexisting backchannel!\n"));
256 DLIST_REMOVE(back_channels
, prn_hnd
->notify
.cli_chan
);
257 TALLOC_FREE(prn_hnd
->notify
.cli_chan
);
261 status
= dcerpc_spoolss_ReplyClosePrinter(
262 prn_hnd
->notify
.cli_chan
->binding_handle
,
264 &prn_hnd
->notify
.cli_hnd
,
266 if (!NT_STATUS_IS_OK(status
)) {
267 DEBUG(0, ("dcerpc_spoolss_ReplyClosePrinter failed [%s].\n",
269 result
= ntstatus_to_werror(status
);
270 } else if (!W_ERROR_IS_OK(result
)) {
271 DEBUG(0, ("reply_close_printer failed [%s].\n",
272 win_errstr(result
)));
275 /* if it's the last connection, deconnect the IPC$ share */
276 if (prn_hnd
->notify
.cli_chan
->active_connections
== 1) {
278 prn_hnd
->notify
.cli_chan
->binding_handle
= NULL
;
279 cli_shutdown(rpc_pipe_np_smb_conn(prn_hnd
->notify
.cli_chan
->cli_pipe
));
280 DLIST_REMOVE(back_channels
, prn_hnd
->notify
.cli_chan
);
281 TALLOC_FREE(prn_hnd
->notify
.cli_chan
);
283 if (prn_hnd
->notify
.msg_ctx
!= NULL
) {
284 messaging_deregister(prn_hnd
->notify
.msg_ctx
,
285 MSG_PRINTER_NOTIFY2
, NULL
);
288 * Tell the serverid.tdb we're no longer
289 * interested in printer notify messages.
292 serverid_register_msg_flags(
293 messaging_server_id(prn_hnd
->notify
.msg_ctx
),
294 false, FLAG_MSG_PRINT_NOTIFY
);
298 if (prn_hnd
->notify
.cli_chan
) {
299 prn_hnd
->notify
.cli_chan
->active_connections
--;
303 /****************************************************************************
304 Functions to free a printer entry datastruct.
305 ****************************************************************************/
307 static int printer_entry_destructor(struct printer_handle
*Printer
)
309 if (Printer
->notify
.cli_chan
!= NULL
&&
310 Printer
->notify
.cli_chan
->active_connections
> 0) {
313 switch(Printer
->printer_type
) {
315 srv_spoolss_replycloseprinter(snum
, Printer
);
319 snum
= print_queue_snum(Printer
->sharename
);
321 srv_spoolss_replycloseprinter(snum
, Printer
);
329 Printer
->notify
.flags
=0;
330 Printer
->notify
.options
=0;
331 Printer
->notify
.localmachine
[0]='\0';
332 Printer
->notify
.printerlocal
=0;
333 TALLOC_FREE(Printer
->notify
.option
);
334 TALLOC_FREE(Printer
->devmode
);
336 /* Remove from the internal list. */
337 DLIST_REMOVE(printers_list
, Printer
);
341 /****************************************************************************
342 find printer index by handle
343 ****************************************************************************/
345 static struct printer_handle
*find_printer_index_by_hnd(struct pipes_struct
*p
,
346 struct policy_handle
*hnd
)
348 struct printer_handle
*find_printer
= NULL
;
350 if(!find_policy_by_hnd(p
,hnd
,(void **)(void *)&find_printer
)) {
351 DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: "));
358 /****************************************************************************
359 Close printer index by handle.
360 ****************************************************************************/
362 static bool close_printer_handle(struct pipes_struct
*p
, struct policy_handle
*hnd
)
364 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, hnd
);
367 DEBUG(2,("close_printer_handle: Invalid handle (%s:%u:%u)\n",
372 close_policy_hnd(p
, hnd
);
377 /****************************************************************************
378 Delete a printer given a handle.
379 ****************************************************************************/
381 static WERROR
delete_printer_hook(TALLOC_CTX
*ctx
, struct security_token
*token
,
382 const char *sharename
,
383 struct messaging_context
*msg_ctx
)
385 char *cmd
= lp_deleteprinter_cmd();
386 char *command
= NULL
;
388 bool is_print_op
= false;
390 /* can't fail if we don't try */
395 command
= talloc_asprintf(ctx
,
402 is_print_op
= security_token_has_privilege(token
, SEC_PRIV_PRINT_OPERATOR
);
404 DEBUG(10,("Running [%s]\n", command
));
406 /********** BEGIN SePrintOperatorPrivlege BLOCK **********/
411 if ( (ret
= smbrun(command
, NULL
)) == 0 ) {
412 /* Tell everyone we updated smb.conf. */
413 message_send_all(msg_ctx
, MSG_SMB_CONF_UPDATED
, NULL
, 0, NULL
);
419 /********** END SePrintOperatorPrivlege BLOCK **********/
421 DEBUGADD(10,("returned [%d]\n", ret
));
423 TALLOC_FREE(command
);
426 return WERR_BADFID
; /* What to return here? */
428 /* go ahead and re-read the services immediately */
430 reload_services(msg_ctx
, -1, false);
433 if ( lp_servicenumber( sharename
) >= 0 )
434 return WERR_ACCESS_DENIED
;
439 /****************************************************************************
440 Delete a printer given a handle.
441 ****************************************************************************/
443 static WERROR
delete_printer_handle(struct pipes_struct
*p
, struct policy_handle
*hnd
)
445 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, hnd
);
449 DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n",
455 * It turns out that Windows allows delete printer on a handle
456 * opened by an admin user, then used on a pipe handle created
457 * by an anonymous user..... but they're working on security.... riiight !
461 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
462 DEBUG(3, ("delete_printer_handle: denied by handle\n"));
463 return WERR_ACCESS_DENIED
;
466 /* this does not need a become root since the access check has been
467 done on the handle already */
469 result
= winreg_delete_printer_key_internal(p
->mem_ctx
,
470 get_session_info_system(),
474 if (!W_ERROR_IS_OK(result
)) {
475 DEBUG(3,("Error deleting printer %s\n", Printer
->sharename
));
479 result
= delete_printer_hook(p
->mem_ctx
, p
->session_info
->security_token
,
480 Printer
->sharename
, p
->msg_ctx
);
481 if (!W_ERROR_IS_OK(result
)) {
484 prune_printername_cache();
488 /****************************************************************************
489 Return the snum of a printer corresponding to an handle.
490 ****************************************************************************/
492 static bool get_printer_snum(struct pipes_struct
*p
, struct policy_handle
*hnd
,
493 int *number
, struct share_params
**params
)
495 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, hnd
);
498 DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n",
503 switch (Printer
->printer_type
) {
505 DEBUG(4,("short name:%s\n", Printer
->sharename
));
506 *number
= print_queue_snum(Printer
->sharename
);
507 return (*number
!= -1);
515 /****************************************************************************
516 Set printer handle type.
517 Check if it's \\server or \\server\printer
518 ****************************************************************************/
520 static bool set_printer_hnd_printertype(struct printer_handle
*Printer
, const char *handlename
)
522 DEBUG(3,("Setting printer type=%s\n", handlename
));
524 /* it's a print server */
525 if (handlename
&& *handlename
=='\\' && *(handlename
+1)=='\\' && !strchr_m(handlename
+2, '\\')) {
526 DEBUGADD(4,("Printer is a print server\n"));
527 Printer
->printer_type
= SPLHND_SERVER
;
529 /* it's a printer (set_printer_hnd_name() will handle port monitors */
531 DEBUGADD(4,("Printer is a printer\n"));
532 Printer
->printer_type
= SPLHND_PRINTER
;
538 static void prune_printername_cache_fn(const char *key
, const char *value
,
539 time_t timeout
, void *private_data
)
544 static void prune_printername_cache(void)
546 gencache_iterate(prune_printername_cache_fn
, NULL
, "PRINTERNAME/*");
549 /****************************************************************************
550 Set printer handle name.. Accept names like \\server, \\server\printer,
551 \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
552 the MSDN docs regarding OpenPrinter() for details on the XcvData() and
553 XcvDataPort() interface.
554 ****************************************************************************/
556 static WERROR
set_printer_hnd_name(TALLOC_CTX
*mem_ctx
,
557 const struct auth_session_info
*session_info
,
558 struct messaging_context
*msg_ctx
,
559 struct printer_handle
*Printer
,
560 const char *handlename
)
563 int n_services
=lp_numservices();
565 const char *printername
;
566 const char *servername
= NULL
;
569 struct spoolss_PrinterInfo2
*info2
= NULL
;
574 * Hopefully nobody names his printers like this. Maybe \ or ,
575 * are illegal in printer names even?
577 const char printer_not_found
[] = "Printer \\, !@#$%^&*( not found";
581 DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename
,
582 (unsigned long)strlen(handlename
)));
584 aprinter
= discard_const_p(char, handlename
);
585 if ( *handlename
== '\\' ) {
586 servername
= canon_servername(handlename
);
587 if ( (aprinter
= strchr_m( servername
, '\\' )) != NULL
) {
591 if (!is_myname_or_ipaddr(servername
)) {
592 return WERR_INVALID_PRINTER_NAME
;
594 Printer
->servername
= talloc_asprintf(Printer
, "\\\\%s", servername
);
595 if (Printer
->servername
== NULL
) {
600 if (Printer
->printer_type
== SPLHND_SERVER
) {
604 if (Printer
->printer_type
!= SPLHND_PRINTER
) {
605 return WERR_INVALID_HANDLE
;
608 DEBUGADD(5, ("searching for [%s]\n", aprinter
));
610 p
= strchr(aprinter
, ',');
617 if (strncmp(p
, "DrvConvert", strlen("DrvConvert")) == 0) {
619 } else if (strncmp(p
, "LocalOnly", strlen("LocalOnly")) == 0) {
625 DEBUGADD(5, ("stripped handlename: [%s]\n", aprinter
));
628 /* check for the Port Monitor Interface */
629 if ( strequal( aprinter
, SPL_XCV_MONITOR_TCPMON
) ) {
630 Printer
->printer_type
= SPLHND_PORTMON_TCP
;
631 fstrcpy(sname
, SPL_XCV_MONITOR_TCPMON
);
634 else if ( strequal( aprinter
, SPL_XCV_MONITOR_LOCALMON
) ) {
635 Printer
->printer_type
= SPLHND_PORTMON_LOCAL
;
636 fstrcpy(sname
, SPL_XCV_MONITOR_LOCALMON
);
641 * With hundreds of printers, the "for" loop iterating all
642 * shares can be quite expensive, as it is done on every
643 * OpenPrinter. The loop maps "aprinter" to "sname", the
644 * result of which we cache in gencache.
647 cache_key
= talloc_asprintf(talloc_tos(), "PRINTERNAME/%s",
649 if ((cache_key
!= NULL
) && gencache_get(cache_key
, &tmp
, NULL
)) {
651 found
= (strcmp(tmp
, printer_not_found
) != 0);
653 DEBUG(4, ("Printer %s not found\n", aprinter
));
655 return WERR_INVALID_PRINTER_NAME
;
661 /* Search all sharenames first as this is easier than pulling
662 the printer_info_2 off of disk. Don't use find_service() since
663 that calls out to map_username() */
665 /* do another loop to look for printernames */
666 for (snum
= 0; !found
&& snum
< n_services
; snum
++) {
667 const char *printer
= lp_const_servicename(snum
);
669 /* no point going on if this is not a printer */
670 if (!(lp_snum_ok(snum
) && lp_print_ok(snum
))) {
674 /* ignore [printers] share */
675 if (strequal(printer
, "printers")) {
679 fstrcpy(sname
, printer
);
680 if (strequal(aprinter
, printer
)) {
685 /* no point looking up the printer object if
686 we aren't allowing printername != sharename */
687 if (lp_force_printername(snum
)) {
691 result
= winreg_get_printer_internal(mem_ctx
,
696 if ( !W_ERROR_IS_OK(result
) ) {
697 DEBUG(2,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
698 sname
, win_errstr(result
)));
702 printername
= strrchr(info2
->printername
, '\\');
703 if (printername
== NULL
) {
704 printername
= info2
->printername
;
709 if (strequal(printername
, aprinter
)) {
714 DEBUGADD(10, ("printername: %s\n", printername
));
720 if (cache_key
!= NULL
) {
721 gencache_set(cache_key
, printer_not_found
,
723 TALLOC_FREE(cache_key
);
725 DEBUGADD(4,("Printer not found\n"));
726 return WERR_INVALID_PRINTER_NAME
;
729 if (cache_key
!= NULL
) {
730 gencache_set(cache_key
, sname
, time(NULL
)+300);
731 TALLOC_FREE(cache_key
);
734 DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter
, sname
));
736 strlcpy(Printer
->sharename
, sname
, sizeof(Printer
->sharename
));
741 /****************************************************************************
742 Find first available printer slot. creates a printer handle for you.
743 ****************************************************************************/
745 static WERROR
open_printer_hnd(struct pipes_struct
*p
,
746 struct policy_handle
*hnd
,
748 uint32_t access_granted
)
750 struct printer_handle
*new_printer
;
753 DEBUG(10,("open_printer_hnd: name [%s]\n", name
));
755 new_printer
= talloc_zero(p
->mem_ctx
, struct printer_handle
);
756 if (new_printer
== NULL
) {
759 talloc_set_destructor(new_printer
, printer_entry_destructor
);
761 /* This also steals the printer_handle on the policy_handle */
762 if (!create_policy_hnd(p
, hnd
, new_printer
)) {
763 TALLOC_FREE(new_printer
);
764 return WERR_INVALID_HANDLE
;
767 /* Add to the internal list. */
768 DLIST_ADD(printers_list
, new_printer
);
770 new_printer
->notify
.option
=NULL
;
772 if (!set_printer_hnd_printertype(new_printer
, name
)) {
773 close_printer_handle(p
, hnd
);
774 return WERR_INVALID_HANDLE
;
777 result
= set_printer_hnd_name(p
->mem_ctx
,
778 get_session_info_system(),
781 if (!W_ERROR_IS_OK(result
)) {
782 close_printer_handle(p
, hnd
);
786 new_printer
->access_granted
= access_granted
;
788 DEBUG(5, ("%d printer handles active\n",
789 (int)num_pipe_handles(p
)));
794 /***************************************************************************
795 check to see if the client motify handle is monitoring the notification
796 given by (notify_type, notify_field).
797 **************************************************************************/
799 static bool is_monitoring_event_flags(uint32_t flags
, uint16_t notify_type
,
800 uint16_t notify_field
)
805 static bool is_monitoring_event(struct printer_handle
*p
, uint16_t notify_type
,
806 uint16_t notify_field
)
808 struct spoolss_NotifyOption
*option
= p
->notify
.option
;
812 * Flags should always be zero when the change notify
813 * is registered by the client's spooler. A user Win32 app
814 * might use the flags though instead of the NOTIFY_OPTION_INFO
823 return is_monitoring_event_flags(
824 p
->notify
.flags
, notify_type
, notify_field
);
826 for (i
= 0; i
< option
->count
; i
++) {
828 /* Check match for notify_type */
830 if (option
->types
[i
].type
!= notify_type
)
833 /* Check match for field */
835 for (j
= 0; j
< option
->types
[i
].count
; j
++) {
836 if (option
->types
[i
].fields
[j
].field
== notify_field
) {
842 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
843 p
->servername
, p
->sharename
, notify_type
, notify_field
));
848 #define SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(_data, _integer) \
849 _data->data.integer[0] = _integer; \
850 _data->data.integer[1] = 0;
853 #define SETUP_SPOOLSS_NOTIFY_DATA_STRING(_data, _p) \
854 _data->data.string.string = talloc_strdup(mem_ctx, _p); \
855 if (!_data->data.string.string) {\
856 _data->data.string.size = 0; \
858 _data->data.string.size = strlen_m_term(_p) * 2;
860 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
861 _data->data.devmode.devmode = _devmode;
863 #define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _sd) \
864 _data->data.sd.sd = dup_sec_desc(mem_ctx, _sd); \
865 if (!_data->data.sd.sd) { \
866 _data->data.sd.sd_size = 0; \
868 _data->data.sd.sd_size = \
869 ndr_size_security_descriptor(_data->data.sd.sd, 0);
871 static void init_systemtime_buffer(TALLOC_CTX
*mem_ctx
,
876 struct spoolss_Time st
;
880 if (!init_systemtime(&st
, t
)) {
884 p
= talloc_array(mem_ctx
, char, len
);
890 * Systemtime must be linearized as a set of UINT16's.
891 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
894 SSVAL(p
, 0, st
.year
);
895 SSVAL(p
, 2, st
.month
);
896 SSVAL(p
, 4, st
.day_of_week
);
898 SSVAL(p
, 8, st
.hour
);
899 SSVAL(p
, 10, st
.minute
);
900 SSVAL(p
, 12, st
.second
);
901 SSVAL(p
, 14, st
.millisecond
);
907 /* Convert a notification message to a struct spoolss_Notify */
909 static void notify_one_value(struct spoolss_notify_msg
*msg
,
910 struct spoolss_Notify
*data
,
913 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, msg
->notify
.value
[0]);
916 static void notify_string(struct spoolss_notify_msg
*msg
,
917 struct spoolss_Notify
*data
,
920 /* The length of the message includes the trailing \0 */
922 data
->data
.string
.size
= msg
->len
* 2;
923 data
->data
.string
.string
= talloc_strdup(mem_ctx
, msg
->notify
.data
);
924 if (!data
->data
.string
.string
) {
925 data
->data
.string
.size
= 0;
930 static void notify_system_time(struct spoolss_notify_msg
*msg
,
931 struct spoolss_Notify
*data
,
934 data
->data
.string
.string
= NULL
;
935 data
->data
.string
.size
= 0;
937 if (msg
->len
!= sizeof(time_t)) {
938 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
943 init_systemtime_buffer(mem_ctx
, gmtime((time_t *)msg
->notify
.data
),
944 &data
->data
.string
.string
,
945 &data
->data
.string
.size
);
948 struct notify2_message_table
{
950 void (*fn
)(struct spoolss_notify_msg
*msg
,
951 struct spoolss_Notify
*data
, TALLOC_CTX
*mem_ctx
);
954 static struct notify2_message_table printer_notify_table
[] = {
955 /* 0x00 */ { "PRINTER_NOTIFY_FIELD_SERVER_NAME", notify_string
},
956 /* 0x01 */ { "PRINTER_NOTIFY_FIELD_PRINTER_NAME", notify_string
},
957 /* 0x02 */ { "PRINTER_NOTIFY_FIELD_SHARE_NAME", notify_string
},
958 /* 0x03 */ { "PRINTER_NOTIFY_FIELD_PORT_NAME", notify_string
},
959 /* 0x04 */ { "PRINTER_NOTIFY_FIELD_DRIVER_NAME", notify_string
},
960 /* 0x05 */ { "PRINTER_NOTIFY_FIELD_COMMENT", notify_string
},
961 /* 0x06 */ { "PRINTER_NOTIFY_FIELD_LOCATION", notify_string
},
962 /* 0x07 */ { "PRINTER_NOTIFY_FIELD_DEVMODE", NULL
},
963 /* 0x08 */ { "PRINTER_NOTIFY_FIELD_SEPFILE", notify_string
},
964 /* 0x09 */ { "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", notify_string
},
965 /* 0x0a */ { "PRINTER_NOTIFY_FIELD_PARAMETERS", NULL
},
966 /* 0x0b */ { "PRINTER_NOTIFY_FIELD_DATATYPE", notify_string
},
967 /* 0x0c */ { "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL
},
968 /* 0x0d */ { "PRINTER_NOTIFY_FIELD_ATTRIBUTES", notify_one_value
},
969 /* 0x0e */ { "PRINTER_NOTIFY_FIELD_PRIORITY", notify_one_value
},
970 /* 0x0f */ { "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NULL
},
971 /* 0x10 */ { "PRINTER_NOTIFY_FIELD_START_TIME", NULL
},
972 /* 0x11 */ { "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NULL
},
973 /* 0x12 */ { "PRINTER_NOTIFY_FIELD_STATUS", notify_one_value
},
976 static struct notify2_message_table job_notify_table
[] = {
977 /* 0x00 */ { "JOB_NOTIFY_FIELD_PRINTER_NAME", NULL
},
978 /* 0x01 */ { "JOB_NOTIFY_FIELD_MACHINE_NAME", NULL
},
979 /* 0x02 */ { "JOB_NOTIFY_FIELD_PORT_NAME", NULL
},
980 /* 0x03 */ { "JOB_NOTIFY_FIELD_USER_NAME", notify_string
},
981 /* 0x04 */ { "JOB_NOTIFY_FIELD_NOTIFY_NAME", NULL
},
982 /* 0x05 */ { "JOB_NOTIFY_FIELD_DATATYPE", NULL
},
983 /* 0x06 */ { "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NULL
},
984 /* 0x07 */ { "JOB_NOTIFY_FIELD_PARAMETERS", NULL
},
985 /* 0x08 */ { "JOB_NOTIFY_FIELD_DRIVER_NAME", NULL
},
986 /* 0x09 */ { "JOB_NOTIFY_FIELD_DEVMODE", NULL
},
987 /* 0x0a */ { "JOB_NOTIFY_FIELD_STATUS", notify_one_value
},
988 /* 0x0b */ { "JOB_NOTIFY_FIELD_STATUS_STRING", NULL
},
989 /* 0x0c */ { "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL
},
990 /* 0x0d */ { "JOB_NOTIFY_FIELD_DOCUMENT", notify_string
},
991 /* 0x0e */ { "JOB_NOTIFY_FIELD_PRIORITY", NULL
},
992 /* 0x0f */ { "JOB_NOTIFY_FIELD_POSITION", NULL
},
993 /* 0x10 */ { "JOB_NOTIFY_FIELD_SUBMITTED", notify_system_time
},
994 /* 0x11 */ { "JOB_NOTIFY_FIELD_START_TIME", NULL
},
995 /* 0x12 */ { "JOB_NOTIFY_FIELD_UNTIL_TIME", NULL
},
996 /* 0x13 */ { "JOB_NOTIFY_FIELD_TIME", NULL
},
997 /* 0x14 */ { "JOB_NOTIFY_FIELD_TOTAL_PAGES", notify_one_value
},
998 /* 0x15 */ { "JOB_NOTIFY_FIELD_PAGES_PRINTED", NULL
},
999 /* 0x16 */ { "JOB_NOTIFY_FIELD_TOTAL_BYTES", notify_one_value
},
1000 /* 0x17 */ { "JOB_NOTIFY_FIELD_BYTES_PRINTED", NULL
},
1004 /***********************************************************************
1005 Allocate talloc context for container object
1006 **********************************************************************/
1008 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR
*ctr
)
1013 ctr
->ctx
= talloc_init("notify_msg_ctr_init %p", ctr
);
1018 /***********************************************************************
1019 release all allocated memory and zero out structure
1020 **********************************************************************/
1022 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR
*ctr
)
1028 talloc_destroy(ctr
->ctx
);
1035 /***********************************************************************
1036 **********************************************************************/
1038 static TALLOC_CTX
* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR
*ctr
)
1046 /***********************************************************************
1047 **********************************************************************/
1049 static SPOOLSS_NOTIFY_MSG_GROUP
* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR
*ctr
, uint32_t idx
)
1051 if ( !ctr
|| !ctr
->msg_groups
)
1054 if ( idx
>= ctr
->num_groups
)
1057 return &ctr
->msg_groups
[idx
];
1061 /***********************************************************************
1062 How many groups of change messages do we have ?
1063 **********************************************************************/
1065 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR
*ctr
)
1070 return ctr
->num_groups
;
1073 /***********************************************************************
1074 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
1075 **********************************************************************/
1077 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR
*ctr
, SPOOLSS_NOTIFY_MSG
*msg
)
1079 SPOOLSS_NOTIFY_MSG_GROUP
*groups
= NULL
;
1080 SPOOLSS_NOTIFY_MSG_GROUP
*msg_grp
= NULL
;
1081 SPOOLSS_NOTIFY_MSG
*msg_list
= NULL
;
1087 /* loop over all groups looking for a matching printer name */
1089 for ( i
=0; i
<ctr
->num_groups
; i
++ ) {
1090 if ( strcmp(ctr
->msg_groups
[i
].printername
, msg
->printer
) == 0 )
1094 /* add a new group? */
1096 if ( i
== ctr
->num_groups
) {
1099 if ( !(groups
= talloc_realloc( ctr
->ctx
, ctr
->msg_groups
, SPOOLSS_NOTIFY_MSG_GROUP
, ctr
->num_groups
)) ) {
1100 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
1103 ctr
->msg_groups
= groups
;
1105 /* clear the new entry and set the printer name */
1107 ZERO_STRUCT( ctr
->msg_groups
[ctr
->num_groups
-1] );
1108 fstrcpy( ctr
->msg_groups
[ctr
->num_groups
-1].printername
, msg
->printer
);
1111 /* add the change messages; 'i' is the correct index now regardless */
1113 msg_grp
= &ctr
->msg_groups
[i
];
1115 msg_grp
->num_msgs
++;
1117 if ( !(msg_list
= talloc_realloc( ctr
->ctx
, msg_grp
->msgs
, SPOOLSS_NOTIFY_MSG
, msg_grp
->num_msgs
)) ) {
1118 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp
->num_msgs
));
1121 msg_grp
->msgs
= msg_list
;
1123 new_slot
= msg_grp
->num_msgs
-1;
1124 memcpy( &msg_grp
->msgs
[new_slot
], msg
, sizeof(SPOOLSS_NOTIFY_MSG
) );
1126 /* need to allocate own copy of data */
1128 if ( msg
->len
!= 0 )
1129 msg_grp
->msgs
[new_slot
].notify
.data
= (char *)
1130 talloc_memdup( ctr
->ctx
, msg
->notify
.data
, msg
->len
);
1132 return ctr
->num_groups
;
1135 static void construct_info_data(struct spoolss_Notify
*info_data
,
1136 enum spoolss_NotifyType type
,
1137 uint16_t field
, int id
);
1139 /***********************************************************************
1140 Send a change notication message on all handles which have a call
1142 **********************************************************************/
1144 static int build_notify2_messages(TALLOC_CTX
*mem_ctx
,
1145 struct printer_handle
*prn_hnd
,
1146 SPOOLSS_NOTIFY_MSG
*messages
,
1148 struct spoolss_Notify
**_notifies
,
1151 struct spoolss_Notify
*notifies
;
1152 SPOOLSS_NOTIFY_MSG
*msg
;
1157 notifies
= talloc_zero_array(mem_ctx
,
1158 struct spoolss_Notify
, num_msgs
);
1163 for (i
= 0; i
< num_msgs
; i
++) {
1167 /* Are we monitoring this event? */
1169 if (!is_monitoring_event(prn_hnd
, msg
->type
, msg
->field
)) {
1173 DEBUG(10, ("Sending message type [0x%x] field [0x%2x] "
1174 "for printer [%s]\n",
1175 msg
->type
, msg
->field
, prn_hnd
->sharename
));
1178 * if the is a printer notification handle and not a job
1179 * notification type, then set the id to 0.
1180 * Otherwise just use what was specified in the message.
1182 * When registering change notification on a print server
1183 * handle we always need to send back the id (snum) matching
1184 * the printer for which the change took place.
1185 * For change notify registered on a printer handle,
1186 * this does not matter and the id should be 0.
1191 if ((msg
->type
== PRINTER_NOTIFY_TYPE
) &&
1192 (prn_hnd
->printer_type
== SPLHND_PRINTER
)) {
1198 /* Convert unix jobid to smb jobid */
1200 if (msg
->flags
& SPOOLSS_NOTIFY_MSG_UNIX_JOBID
) {
1201 id
= sysjob_to_jobid(msg
->id
);
1204 DEBUG(3, ("no such unix jobid %d\n",
1210 construct_info_data(¬ifies
[count
],
1211 msg
->type
, msg
->field
, id
);
1214 case PRINTER_NOTIFY_TYPE
:
1215 if (printer_notify_table
[msg
->field
].fn
) {
1216 printer_notify_table
[msg
->field
].fn(msg
,
1217 ¬ifies
[count
], mem_ctx
);
1221 case JOB_NOTIFY_TYPE
:
1222 if (job_notify_table
[msg
->field
].fn
) {
1223 job_notify_table
[msg
->field
].fn(msg
,
1224 ¬ifies
[count
], mem_ctx
);
1229 DEBUG(5, ("Unknown notification type %d\n",
1237 *_notifies
= notifies
;
1243 static int send_notify2_printer(TALLOC_CTX
*mem_ctx
,
1244 struct printer_handle
*prn_hnd
,
1245 SPOOLSS_NOTIFY_MSG_GROUP
*msg_group
)
1247 struct spoolss_Notify
*notifies
;
1249 union spoolss_ReplyPrinterInfo info
;
1250 struct spoolss_NotifyInfo info0
;
1251 uint32_t reply_result
;
1256 /* Is there notification on this handle? */
1257 if (prn_hnd
->notify
.cli_chan
== NULL
||
1258 prn_hnd
->notify
.cli_chan
->active_connections
== 0) {
1262 DEBUG(10, ("Client connected! [\\\\%s\\%s]\n",
1263 prn_hnd
->servername
, prn_hnd
->sharename
));
1265 /* For this printer? Print servers always receive notifications. */
1266 if ((prn_hnd
->printer_type
== SPLHND_PRINTER
) &&
1267 (!strequal(msg_group
->printername
, prn_hnd
->sharename
))) {
1271 DEBUG(10,("Our printer\n"));
1273 /* build the array of change notifications */
1274 ret
= build_notify2_messages(mem_ctx
, prn_hnd
,
1276 msg_group
->num_msgs
,
1282 info0
.version
= 0x2;
1283 info0
.flags
= count
? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED
;
1284 info0
.count
= count
;
1285 info0
.notifies
= notifies
;
1287 info
.info0
= &info0
;
1289 status
= dcerpc_spoolss_RouterReplyPrinterEx(
1290 prn_hnd
->notify
.cli_chan
->binding_handle
,
1292 &prn_hnd
->notify
.cli_hnd
,
1293 prn_hnd
->notify
.change
, /* color */
1294 prn_hnd
->notify
.flags
,
1296 0, /* reply_type, must be 0 */
1298 if (!NT_STATUS_IS_OK(status
)) {
1299 DEBUG(1, ("dcerpc_spoolss_RouterReplyPrinterEx to client: %s "
1301 prn_hnd
->notify
.cli_chan
->cli_pipe
->srv_name_slash
,
1302 nt_errstr(status
)));
1303 werr
= ntstatus_to_werror(status
);
1304 } else if (!W_ERROR_IS_OK(werr
)) {
1305 DEBUG(1, ("RouterReplyPrinterEx to client: %s "
1307 prn_hnd
->notify
.cli_chan
->cli_pipe
->srv_name_slash
,
1310 switch (reply_result
) {
1313 case PRINTER_NOTIFY_INFO_DISCARDED
:
1314 case PRINTER_NOTIFY_INFO_DISCARDNOTED
:
1315 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH
:
1324 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR
*ctr
, uint32_t idx
)
1326 struct printer_handle
*p
;
1327 TALLOC_CTX
*mem_ctx
= notify_ctr_getctx( ctr
);
1328 SPOOLSS_NOTIFY_MSG_GROUP
*msg_group
= notify_ctr_getgroup( ctr
, idx
);
1332 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
1336 if (!msg_group
->msgs
) {
1337 DEBUG(5, ("send_notify2_changes() called with no messages!\n"));
1341 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group
->printername
));
1343 /* loop over all printers */
1345 for (p
= printers_list
; p
; p
= p
->next
) {
1346 ret
= send_notify2_printer(mem_ctx
, p
, msg_group
);
1353 DEBUG(8,("send_notify2_changes: Exit...\n"));
1357 /***********************************************************************
1358 **********************************************************************/
1360 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG
*msg
, struct timeval
*tv
, void *buf
, size_t len
)
1363 uint32_t tv_sec
, tv_usec
;
1366 /* Unpack message */
1368 offset
+= tdb_unpack((uint8_t *)buf
+ offset
, len
- offset
, "f",
1371 offset
+= tdb_unpack((uint8_t *)buf
+ offset
, len
- offset
, "ddddddd",
1373 &msg
->type
, &msg
->field
, &msg
->id
, &msg
->len
, &msg
->flags
);
1376 tdb_unpack((uint8_t *)buf
+ offset
, len
- offset
, "dd",
1377 &msg
->notify
.value
[0], &msg
->notify
.value
[1]);
1379 tdb_unpack((uint8_t *)buf
+ offset
, len
- offset
, "B",
1380 &msg
->len
, &msg
->notify
.data
);
1382 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1383 msg
->printer
, (unsigned int)msg
->id
, msg
->type
, msg
->field
, msg
->flags
));
1385 tv
->tv_sec
= tv_sec
;
1386 tv
->tv_usec
= tv_usec
;
1389 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg
->notify
.value
[0],
1390 msg
->notify
.value
[1]));
1392 dump_data(3, (uint8_t *)msg
->notify
.data
, msg
->len
);
1397 /********************************************************************
1398 Receive a notify2 message list
1399 ********************************************************************/
1401 static void receive_notify2_message_list(struct messaging_context
*msg
,
1404 struct server_id server_id
,
1407 size_t msg_count
, i
;
1408 char *buf
= (char *)data
->data
;
1411 SPOOLSS_NOTIFY_MSG notify
;
1412 SPOOLSS_NOTIFY_MSG_CTR messages
;
1415 if (data
->length
< 4) {
1416 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1420 msg_count
= IVAL(buf
, 0);
1423 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count
));
1425 if (msg_count
== 0) {
1426 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1430 /* initialize the container */
1432 ZERO_STRUCT( messages
);
1433 notify_msg_ctr_init( &messages
);
1436 * build message groups for each printer identified
1437 * in a change_notify msg. Remember that a PCN message
1438 * includes the handle returned for the srv_spoolss_replyopenprinter()
1439 * call. Therefore messages are grouped according to printer handle.
1442 for ( i
=0; i
<msg_count
; i
++ ) {
1443 struct timeval msg_tv
;
1445 if (msg_ptr
+ 4 - buf
> data
->length
) {
1446 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1450 msg_len
= IVAL(msg_ptr
,0);
1453 if (msg_ptr
+ msg_len
- buf
> data
->length
) {
1454 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1458 /* unpack messages */
1460 ZERO_STRUCT( notify
);
1461 notify2_unpack_msg( ¬ify
, &msg_tv
, msg_ptr
, msg_len
);
1464 /* add to correct list in container */
1466 notify_msg_ctr_addmsg( &messages
, ¬ify
);
1468 /* free memory that might have been allocated by notify2_unpack_msg() */
1470 if ( notify
.len
!= 0 )
1471 SAFE_FREE( notify
.notify
.data
);
1474 /* process each group of messages */
1476 num_groups
= notify_msg_ctr_numgroups( &messages
);
1477 for ( i
=0; i
<num_groups
; i
++ )
1478 send_notify2_changes( &messages
, i
);
1483 DEBUG(10,("receive_notify2_message_list: processed %u messages\n",
1484 (uint32_t)msg_count
));
1486 notify_msg_ctr_destroy( &messages
);
1491 /********************************************************************
1492 Send a message to ourself about new driver being installed
1493 so we can upgrade the information for each printer bound to this
1495 ********************************************************************/
1497 static bool srv_spoolss_drv_upgrade_printer(const char *drivername
,
1498 struct messaging_context
*msg_ctx
)
1500 int len
= strlen(drivername
);
1505 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1508 messaging_send_buf(msg_ctx
, messaging_server_id(msg_ctx
),
1509 MSG_PRINTER_DRVUPGRADE
,
1510 (const uint8_t *)drivername
, len
+1);
1515 void srv_spoolss_cleanup(void)
1517 struct printer_session_counter
*session_counter
;
1519 for (session_counter
= counter_list
;
1520 session_counter
!= NULL
;
1521 session_counter
= counter_list
) {
1522 DLIST_REMOVE(counter_list
, session_counter
);
1523 TALLOC_FREE(session_counter
);
1527 /**********************************************************************
1528 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1529 over all printers, upgrading ones as necessary
1530 **********************************************************************/
1532 void do_drv_upgrade_printer(struct messaging_context
*msg
,
1535 struct server_id server_id
,
1538 TALLOC_CTX
*tmp_ctx
;
1539 const struct auth_session_info
*session_info
= get_session_info_system();
1540 struct spoolss_PrinterInfo2
*pinfo2
;
1542 const char *drivername
;
1544 int n_services
= lp_numservices();
1545 struct dcerpc_binding_handle
*b
= NULL
;
1547 tmp_ctx
= talloc_new(NULL
);
1548 if (!tmp_ctx
) return;
1550 drivername
= talloc_strndup(tmp_ctx
, (const char *)data
->data
, data
->length
);
1552 DEBUG(0, ("do_drv_upgrade_printer: Out of memoery ?!\n"));
1556 DEBUG(10, ("do_drv_upgrade_printer: "
1557 "Got message for new driver [%s]\n", drivername
));
1559 /* Iterate the printer list */
1561 for (snum
= 0; snum
< n_services
; snum
++) {
1562 if (!lp_snum_ok(snum
) || !lp_print_ok(snum
)) {
1566 /* ignore [printers] share */
1567 if (strequal(lp_const_servicename(snum
), "printers")) {
1572 result
= winreg_printer_binding_handle(tmp_ctx
,
1576 if (!W_ERROR_IS_OK(result
)) {
1581 result
= winreg_get_printer(tmp_ctx
, b
,
1582 lp_const_servicename(snum
),
1585 if (!W_ERROR_IS_OK(result
)) {
1589 if (!pinfo2
->drivername
) {
1593 if (strcmp(drivername
, pinfo2
->drivername
) != 0) {
1597 DEBUG(6,("Updating printer [%s]\n", pinfo2
->printername
));
1599 /* all we care about currently is the change_id */
1600 result
= winreg_printer_update_changeid(tmp_ctx
, b
,
1601 pinfo2
->printername
);
1603 if (!W_ERROR_IS_OK(result
)) {
1604 DEBUG(3, ("do_drv_upgrade_printer: "
1605 "Failed to update changeid [%s]\n",
1606 win_errstr(result
)));
1612 talloc_free(tmp_ctx
);
1615 /********************************************************************
1616 Update the cache for all printq's with a registered client
1618 ********************************************************************/
1620 void update_monitored_printq_cache(struct messaging_context
*msg_ctx
)
1622 struct printer_handle
*printer
= printers_list
;
1625 /* loop through all printers and update the cache where
1626 a client is connected */
1628 if ((printer
->printer_type
== SPLHND_PRINTER
) &&
1629 ((printer
->notify
.cli_chan
!= NULL
) &&
1630 (printer
->notify
.cli_chan
->active_connections
> 0))) {
1631 snum
= print_queue_snum(printer
->sharename
);
1632 print_queue_status(msg_ctx
, snum
, NULL
, NULL
);
1635 printer
= printer
->next
;
1641 /****************************************************************
1642 _spoolss_OpenPrinter
1643 ****************************************************************/
1645 WERROR
_spoolss_OpenPrinter(struct pipes_struct
*p
,
1646 struct spoolss_OpenPrinter
*r
)
1648 struct spoolss_OpenPrinterEx e
;
1651 ZERO_STRUCT(e
.in
.userlevel
);
1653 e
.in
.printername
= r
->in
.printername
;
1654 e
.in
.datatype
= r
->in
.datatype
;
1655 e
.in
.devmode_ctr
= r
->in
.devmode_ctr
;
1656 e
.in
.access_mask
= r
->in
.access_mask
;
1659 e
.out
.handle
= r
->out
.handle
;
1661 werr
= _spoolss_OpenPrinterEx(p
, &e
);
1663 if (W_ERROR_EQUAL(werr
, WERR_INVALID_PARAM
)) {
1664 /* OpenPrinterEx returns this for a bad
1665 * printer name. We must return WERR_INVALID_PRINTER_NAME
1668 werr
= WERR_INVALID_PRINTER_NAME
;
1674 static WERROR
copy_devicemode(TALLOC_CTX
*mem_ctx
,
1675 struct spoolss_DeviceMode
*orig
,
1676 struct spoolss_DeviceMode
**dest
)
1678 struct spoolss_DeviceMode
*dm
;
1680 dm
= talloc(mem_ctx
, struct spoolss_DeviceMode
);
1685 /* copy all values, then duplicate strings and structs */
1688 dm
->devicename
= talloc_strdup(dm
, orig
->devicename
);
1689 if (!dm
->devicename
) {
1692 dm
->formname
= talloc_strdup(dm
, orig
->formname
);
1693 if (!dm
->formname
) {
1696 if (orig
->driverextra_data
.data
) {
1697 dm
->driverextra_data
.data
=
1698 (uint8_t *) talloc_memdup(dm
, orig
->driverextra_data
.data
,
1699 orig
->driverextra_data
.length
);
1700 if (!dm
->driverextra_data
.data
) {
1709 /****************************************************************
1710 _spoolss_OpenPrinterEx
1711 ****************************************************************/
1713 WERROR
_spoolss_OpenPrinterEx(struct pipes_struct
*p
,
1714 struct spoolss_OpenPrinterEx
*r
)
1719 struct printer_handle
*Printer
=NULL
;
1723 if (!r
->in
.printername
) {
1724 return WERR_INVALID_PARAM
;
1727 if (r
->in
.level
> 3) {
1728 return WERR_INVALID_PARAM
;
1730 if ((r
->in
.level
== 1 && !r
->in
.userlevel
.level1
) ||
1731 (r
->in
.level
== 2 && !r
->in
.userlevel
.level2
) ||
1732 (r
->in
.level
== 3 && !r
->in
.userlevel
.level3
)) {
1733 return WERR_INVALID_PARAM
;
1736 /* some sanity check because you can open a printer or a print server */
1737 /* aka: \\server\printer or \\server */
1739 DEBUGADD(3,("checking name: %s\n", r
->in
.printername
));
1741 result
= open_printer_hnd(p
, r
->out
.handle
, r
->in
.printername
, 0);
1742 if (!W_ERROR_IS_OK(result
)) {
1743 DEBUG(0,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
1744 "for printer %s\n", r
->in
.printername
));
1745 ZERO_STRUCTP(r
->out
.handle
);
1749 Printer
= find_printer_index_by_hnd(p
, r
->out
.handle
);
1751 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1752 "handle we created for printer %s\n", r
->in
.printername
));
1753 close_printer_handle(p
, r
->out
.handle
);
1754 ZERO_STRUCTP(r
->out
.handle
);
1755 return WERR_INVALID_PARAM
;
1759 * First case: the user is opening the print server:
1761 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1762 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1764 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1765 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1766 * or if the user is listed in the smb.conf printer admin parameter.
1768 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1769 * client view printer folder, but does not show the MSAPW.
1771 * Note: this test needs code to check access rights here too. Jeremy
1772 * could you look at this?
1774 * Second case: the user is opening a printer:
1775 * NT doesn't let us connect to a printer if the connecting user
1776 * doesn't have print permission.
1778 * Third case: user is opening a Port Monitor
1779 * access checks same as opening a handle to the print server.
1782 switch (Printer
->printer_type
)
1785 case SPLHND_PORTMON_TCP
:
1786 case SPLHND_PORTMON_LOCAL
:
1787 /* Printserver handles use global struct... */
1791 /* Map standard access rights to object specific access rights */
1793 se_map_standard(&r
->in
.access_mask
,
1794 &printserver_std_mapping
);
1796 /* Deny any object specific bits that don't apply to print
1797 servers (i.e printer and job specific bits) */
1799 r
->in
.access_mask
&= SEC_MASK_SPECIFIC
;
1801 if (r
->in
.access_mask
&
1802 ~(SERVER_ACCESS_ADMINISTER
| SERVER_ACCESS_ENUMERATE
)) {
1803 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1804 close_printer_handle(p
, r
->out
.handle
);
1805 ZERO_STRUCTP(r
->out
.handle
);
1806 return WERR_ACCESS_DENIED
;
1809 /* Allow admin access */
1811 if ( r
->in
.access_mask
& SERVER_ACCESS_ADMINISTER
)
1813 if (!lp_ms_add_printer_wizard()) {
1814 close_printer_handle(p
, r
->out
.handle
);
1815 ZERO_STRUCTP(r
->out
.handle
);
1816 return WERR_ACCESS_DENIED
;
1819 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1820 and not a printer admin, then fail */
1822 if ((p
->session_info
->unix_token
->uid
!= sec_initial_uid()) &&
1823 !security_token_has_privilege(p
->session_info
->security_token
, SEC_PRIV_PRINT_OPERATOR
) &&
1824 !nt_token_check_sid(&global_sid_Builtin_Print_Operators
, p
->session_info
->security_token
) &&
1825 !token_contains_name_in_list(
1826 uidtoname(p
->session_info
->unix_token
->uid
),
1827 p
->session_info
->info
->domain_name
,
1829 p
->session_info
->security_token
,
1830 lp_printer_admin(snum
))) {
1831 close_printer_handle(p
, r
->out
.handle
);
1832 ZERO_STRUCTP(r
->out
.handle
);
1833 DEBUG(3,("access DENIED as user is not root, "
1834 "has no printoperator privilege, "
1835 "not a member of the printoperator builtin group and "
1836 "is not in printer admin list"));
1837 return WERR_ACCESS_DENIED
;
1840 r
->in
.access_mask
= SERVER_ACCESS_ADMINISTER
;
1844 r
->in
.access_mask
= SERVER_ACCESS_ENUMERATE
;
1847 DEBUG(4,("Setting print server access = %s\n", (r
->in
.access_mask
== SERVER_ACCESS_ADMINISTER
)
1848 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1850 /* We fall through to return WERR_OK */
1853 case SPLHND_PRINTER
:
1854 /* NT doesn't let us connect to a printer if the connecting user
1855 doesn't have print permission. */
1857 if (!get_printer_snum(p
, r
->out
.handle
, &snum
, NULL
)) {
1858 close_printer_handle(p
, r
->out
.handle
);
1859 ZERO_STRUCTP(r
->out
.handle
);
1863 if (r
->in
.access_mask
== SEC_FLAG_MAXIMUM_ALLOWED
) {
1864 r
->in
.access_mask
= PRINTER_ACCESS_ADMINISTER
;
1867 se_map_standard(&r
->in
.access_mask
, &printer_std_mapping
);
1869 /* map an empty access mask to the minimum access mask */
1870 if (r
->in
.access_mask
== 0x0)
1871 r
->in
.access_mask
= PRINTER_ACCESS_USE
;
1874 * If we are not serving the printer driver for this printer,
1875 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1876 * will keep NT clients happy --jerry
1879 if (lp_use_client_driver(snum
)
1880 && (r
->in
.access_mask
& PRINTER_ACCESS_ADMINISTER
))
1882 r
->in
.access_mask
= PRINTER_ACCESS_USE
;
1885 /* check smb.conf parameters and the the sec_desc */
1886 raddr
= tsocket_address_inet_addr_string(p
->remote_address
,
1888 if (raddr
== NULL
) {
1892 rc
= get_remote_hostname(p
->remote_address
,
1898 if (strequal(rhost
, "UNKNOWN")) {
1902 if (!allow_access(lp_hostsdeny(snum
), lp_hostsallow(snum
),
1904 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1905 ZERO_STRUCTP(r
->out
.handle
);
1906 return WERR_ACCESS_DENIED
;
1909 if (!user_ok_token(uidtoname(p
->session_info
->unix_token
->uid
), NULL
,
1910 p
->session_info
->security_token
, snum
) ||
1911 !print_access_check(p
->session_info
,
1914 r
->in
.access_mask
)) {
1915 DEBUG(3, ("access DENIED for printer open\n"));
1916 close_printer_handle(p
, r
->out
.handle
);
1917 ZERO_STRUCTP(r
->out
.handle
);
1918 return WERR_ACCESS_DENIED
;
1921 if ((r
->in
.access_mask
& SEC_MASK_SPECIFIC
)& ~(PRINTER_ACCESS_ADMINISTER
|PRINTER_ACCESS_USE
)) {
1922 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1923 close_printer_handle(p
, r
->out
.handle
);
1924 ZERO_STRUCTP(r
->out
.handle
);
1925 return WERR_ACCESS_DENIED
;
1928 if (r
->in
.access_mask
& PRINTER_ACCESS_ADMINISTER
)
1929 r
->in
.access_mask
= PRINTER_ACCESS_ADMINISTER
;
1931 r
->in
.access_mask
= PRINTER_ACCESS_USE
;
1933 DEBUG(4,("Setting printer access = %s\n", (r
->in
.access_mask
== PRINTER_ACCESS_ADMINISTER
)
1934 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1936 winreg_create_printer_internal(p
->mem_ctx
,
1937 get_session_info_system(),
1939 lp_const_servicename(snum
));
1944 /* sanity check to prevent programmer error */
1945 ZERO_STRUCTP(r
->out
.handle
);
1949 Printer
->access_granted
= r
->in
.access_mask
;
1952 * If the client sent a devmode in the OpenPrinter() call, then
1953 * save it here in case we get a job submission on this handle
1956 if ((Printer
->printer_type
!= SPLHND_SERVER
) &&
1957 r
->in
.devmode_ctr
.devmode
) {
1958 copy_devicemode(NULL
, r
->in
.devmode_ctr
.devmode
,
1962 #if 0 /* JERRY -- I'm doubtful this is really effective */
1963 /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
1964 optimization in Windows 2000 clients --jerry */
1966 if ( (r
->in
.access_mask
== PRINTER_ACCESS_ADMINISTER
)
1967 && (RA_WIN2K
== get_remote_arch()) )
1969 DEBUG(10,("_spoolss_OpenPrinterEx: Enabling LAN/WAN hack for Win2k clients.\n"));
1970 sys_usleep( 500000 );
1977 /****************************************************************
1978 _spoolss_ClosePrinter
1979 ****************************************************************/
1981 WERROR
_spoolss_ClosePrinter(struct pipes_struct
*p
,
1982 struct spoolss_ClosePrinter
*r
)
1984 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
1986 if (Printer
&& Printer
->document_started
) {
1987 struct spoolss_EndDocPrinter e
;
1989 e
.in
.handle
= r
->in
.handle
;
1991 _spoolss_EndDocPrinter(p
, &e
);
1994 if (!close_printer_handle(p
, r
->in
.handle
))
1997 /* clear the returned printer handle. Observed behavior
1998 from Win2k server. Don't think this really matters.
1999 Previous code just copied the value of the closed
2002 ZERO_STRUCTP(r
->out
.handle
);
2007 /****************************************************************
2008 _spoolss_DeletePrinter
2009 ****************************************************************/
2011 WERROR
_spoolss_DeletePrinter(struct pipes_struct
*p
,
2012 struct spoolss_DeletePrinter
*r
)
2014 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
2018 if (Printer
&& Printer
->document_started
) {
2019 struct spoolss_EndDocPrinter e
;
2021 e
.in
.handle
= r
->in
.handle
;
2023 _spoolss_EndDocPrinter(p
, &e
);
2026 if (get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
2027 winreg_delete_printer_key_internal(p
->mem_ctx
,
2028 get_session_info_system(),
2030 lp_const_servicename(snum
),
2034 result
= delete_printer_handle(p
, r
->in
.handle
);
2039 /*******************************************************************
2040 * static function to lookup the version id corresponding to an
2041 * long architecture string
2042 ******************************************************************/
2044 static const struct print_architecture_table_node archi_table
[]= {
2046 {"Windows 4.0", SPL_ARCH_WIN40
, 0 },
2047 {"Windows NT x86", SPL_ARCH_W32X86
, 2 },
2048 {"Windows NT R4000", SPL_ARCH_W32MIPS
, 2 },
2049 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA
, 2 },
2050 {"Windows NT PowerPC", SPL_ARCH_W32PPC
, 2 },
2051 {"Windows IA64", SPL_ARCH_IA64
, 3 },
2052 {"Windows x64", SPL_ARCH_X64
, 3 },
2056 static int get_version_id(const char *arch
)
2060 for (i
=0; archi_table
[i
].long_archi
!= NULL
; i
++)
2062 if (strcmp(arch
, archi_table
[i
].long_archi
) == 0)
2063 return (archi_table
[i
].version
);
2069 /****************************************************************
2070 _spoolss_DeletePrinterDriver
2071 ****************************************************************/
2073 WERROR
_spoolss_DeletePrinterDriver(struct pipes_struct
*p
,
2074 struct spoolss_DeletePrinterDriver
*r
)
2077 struct spoolss_DriverInfo8
*info
= NULL
;
2078 struct spoolss_DriverInfo8
*info_win2k
= NULL
;
2081 struct dcerpc_binding_handle
*b
;
2082 TALLOC_CTX
*tmp_ctx
= NULL
;
2084 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2085 and not a printer admin, then fail */
2087 if ( (p
->session_info
->unix_token
->uid
!= sec_initial_uid())
2088 && !security_token_has_privilege(p
->session_info
->security_token
, SEC_PRIV_PRINT_OPERATOR
)
2089 && !token_contains_name_in_list(
2090 uidtoname(p
->session_info
->unix_token
->uid
),
2091 p
->session_info
->info
->domain_name
,
2093 p
->session_info
->security_token
,
2094 lp_printer_admin(-1)) )
2096 return WERR_ACCESS_DENIED
;
2099 /* check that we have a valid driver name first */
2101 if ((version
= get_version_id(r
->in
.architecture
)) == -1) {
2102 return WERR_INVALID_ENVIRONMENT
;
2105 tmp_ctx
= talloc_new(p
->mem_ctx
);
2110 status
= winreg_printer_binding_handle(tmp_ctx
,
2111 get_session_info_system(),
2114 if (!W_ERROR_IS_OK(status
)) {
2118 status
= winreg_get_driver(tmp_ctx
, b
,
2119 r
->in
.architecture
, r
->in
.driver
,
2121 if (!W_ERROR_IS_OK(status
)) {
2122 /* try for Win2k driver if "Windows NT x86" */
2124 if ( version
== 2 ) {
2127 status
= winreg_get_driver(tmp_ctx
, b
,
2131 if (!W_ERROR_IS_OK(status
)) {
2132 status
= WERR_UNKNOWN_PRINTER_DRIVER
;
2136 /* otherwise it was a failure */
2138 status
= WERR_UNKNOWN_PRINTER_DRIVER
;
2144 if (printer_driver_in_use(tmp_ctx
,
2147 status
= WERR_PRINTER_DRIVER_IN_USE
;
2152 status
= winreg_get_driver(tmp_ctx
, b
,
2154 r
->in
.driver
, 3, &info_win2k
);
2155 if (W_ERROR_IS_OK(status
)) {
2156 /* if we get to here, we now have 2 driver info structures to remove */
2157 /* remove the Win2k driver first*/
2159 status
= winreg_del_driver(tmp_ctx
, b
,
2161 talloc_free(info_win2k
);
2163 /* this should not have failed---if it did, report to client */
2164 if (!W_ERROR_IS_OK(status
)) {
2170 status
= winreg_del_driver(tmp_ctx
, b
,
2174 talloc_free(tmp_ctx
);
2179 /****************************************************************
2180 _spoolss_DeletePrinterDriverEx
2181 ****************************************************************/
2183 WERROR
_spoolss_DeletePrinterDriverEx(struct pipes_struct
*p
,
2184 struct spoolss_DeletePrinterDriverEx
*r
)
2186 struct spoolss_DriverInfo8
*info
= NULL
;
2187 struct spoolss_DriverInfo8
*info_win2k
= NULL
;
2191 struct dcerpc_binding_handle
*b
;
2192 TALLOC_CTX
*tmp_ctx
= NULL
;
2194 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2195 and not a printer admin, then fail */
2197 if ( (p
->session_info
->unix_token
->uid
!= sec_initial_uid())
2198 && !security_token_has_privilege(p
->session_info
->security_token
, SEC_PRIV_PRINT_OPERATOR
)
2199 && !token_contains_name_in_list(
2200 uidtoname(p
->session_info
->unix_token
->uid
),
2201 p
->session_info
->info
->domain_name
,
2203 p
->session_info
->security_token
, lp_printer_admin(-1)) )
2205 return WERR_ACCESS_DENIED
;
2208 /* check that we have a valid driver name first */
2209 if ((version
= get_version_id(r
->in
.architecture
)) == -1) {
2210 /* this is what NT returns */
2211 return WERR_INVALID_ENVIRONMENT
;
2214 if (r
->in
.delete_flags
& DPD_DELETE_SPECIFIC_VERSION
) {
2215 version
= r
->in
.version
;
2218 tmp_ctx
= talloc_new(p
->mem_ctx
);
2223 status
= winreg_printer_binding_handle(tmp_ctx
,
2224 get_session_info_system(),
2227 if (!W_ERROR_IS_OK(status
)) {
2231 status
= winreg_get_driver(tmp_ctx
, b
,
2236 if (!W_ERROR_IS_OK(status
)) {
2237 status
= WERR_UNKNOWN_PRINTER_DRIVER
;
2240 * if the client asked for a specific version,
2241 * or this is something other than Windows NT x86,
2245 if ( (r
->in
.delete_flags
& DPD_DELETE_SPECIFIC_VERSION
) || (version
!=2) )
2248 /* try for Win2k driver if "Windows NT x86" */
2251 status
= winreg_get_driver(tmp_ctx
, b
,
2255 if (!W_ERROR_IS_OK(status
)) {
2256 status
= WERR_UNKNOWN_PRINTER_DRIVER
;
2261 if (printer_driver_in_use(tmp_ctx
,
2264 status
= WERR_PRINTER_DRIVER_IN_USE
;
2269 * we have a couple of cases to consider.
2270 * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set,
2271 * then the delete should fail if **any** files overlap with
2273 * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
2274 * non-overlapping files
2275 * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
2276 * is set, the do not delete any files
2277 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
2280 delete_files
= r
->in
.delete_flags
& (DPD_DELETE_ALL_FILES
|DPD_DELETE_UNUSED_FILES
);
2282 /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
2285 (r
->in
.delete_flags
& DPD_DELETE_ALL_FILES
) &&
2286 printer_driver_files_in_use(tmp_ctx
,
2289 /* no idea of the correct error here */
2290 status
= WERR_ACCESS_DENIED
;
2295 /* also check for W32X86/3 if necessary; maybe we already have? */
2297 if ( (version
== 2) && ((r
->in
.delete_flags
& DPD_DELETE_SPECIFIC_VERSION
) != DPD_DELETE_SPECIFIC_VERSION
) ) {
2298 status
= winreg_get_driver(tmp_ctx
, b
,
2300 r
->in
.driver
, 3, &info_win2k
);
2301 if (W_ERROR_IS_OK(status
)) {
2304 (r
->in
.delete_flags
& DPD_DELETE_ALL_FILES
) &&
2305 printer_driver_files_in_use(info
,
2308 /* no idea of the correct error here */
2309 talloc_free(info_win2k
);
2310 status
= WERR_ACCESS_DENIED
;
2314 /* if we get to here, we now have 2 driver info structures to remove */
2315 /* remove the Win2k driver first*/
2317 status
= winreg_del_driver(tmp_ctx
, b
,
2321 /* this should not have failed---if it did, report to client */
2323 if (!W_ERROR_IS_OK(status
)) {
2328 * now delete any associated files if delete_files is
2329 * true. Even if this part failes, we return succes
2330 * because the driver doesn not exist any more
2333 delete_driver_files(get_session_info_system(),
2339 status
= winreg_del_driver(tmp_ctx
, b
,
2342 if (!W_ERROR_IS_OK(status
)) {
2347 * now delete any associated files if delete_files is
2348 * true. Even if this part failes, we return succes
2349 * because the driver doesn not exist any more
2352 delete_driver_files(get_session_info_system(), info
);
2356 talloc_free(tmp_ctx
);
2361 /********************************************************************
2362 GetPrinterData on a printer server Handle.
2363 ********************************************************************/
2365 static WERROR
getprinterdata_printer_server(TALLOC_CTX
*mem_ctx
,
2367 enum winreg_Type
*type
,
2368 union spoolss_PrinterData
*data
)
2370 DEBUG(8,("getprinterdata_printer_server:%s\n", value
));
2372 if (!strcasecmp_m(value
, "W3SvcInstalled")) {
2378 if (!strcasecmp_m(value
, "BeepEnabled")) {
2384 if (!strcasecmp_m(value
, "EventLog")) {
2386 /* formally was 0x1b */
2391 if (!strcasecmp_m(value
, "NetPopup")) {
2397 if (!strcasecmp_m(value
, "MajorVersion")) {
2400 /* Windows NT 4.0 seems to not allow uploading of drivers
2401 to a server that reports 0x3 as the MajorVersion.
2402 need to investigate more how Win2k gets around this .
2405 if (RA_WINNT
== get_remote_arch()) {
2414 if (!strcasecmp_m(value
, "MinorVersion")) {
2421 * uint32_t size = 0x114
2422 * uint32_t major = 5
2423 * uint32_t minor = [0|1]
2424 * uint32_t build = [2195|2600]
2425 * extra unicode string = e.g. "Service Pack 3"
2427 if (!strcasecmp_m(value
, "OSVersion")) {
2429 enum ndr_err_code ndr_err
;
2430 struct spoolss_OSVersion os
;
2432 os
.major
= 5; /* Windows 2000 == 5.0 */
2434 os
.build
= 2195; /* build */
2435 os
.extra_string
= ""; /* leave extra string empty */
2437 ndr_err
= ndr_push_struct_blob(&blob
, mem_ctx
, &os
,
2438 (ndr_push_flags_fn_t
)ndr_push_spoolss_OSVersion
);
2439 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2440 return WERR_GENERAL_FAILURE
;
2444 data
->binary
= blob
;
2450 if (!strcasecmp_m(value
, "DefaultSpoolDirectory")) {
2453 data
->string
= talloc_strdup(mem_ctx
, "C:\\PRINTERS");
2454 W_ERROR_HAVE_NO_MEMORY(data
->string
);
2459 if (!strcasecmp_m(value
, "Architecture")) {
2461 data
->string
= talloc_strdup(mem_ctx
,
2462 lp_parm_const_string(GLOBAL_SECTION_SNUM
, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_NT_X86
));
2463 W_ERROR_HAVE_NO_MEMORY(data
->string
);
2468 if (!strcasecmp_m(value
, "DsPresent")) {
2471 /* only show the publish check box if we are a
2472 member of a AD domain */
2474 if (lp_security() == SEC_ADS
) {
2482 if (!strcasecmp_m(value
, "DNSMachineName")) {
2483 const char *hostname
= get_mydnsfullname();
2486 return WERR_BADFILE
;
2490 data
->string
= talloc_strdup(mem_ctx
, hostname
);
2491 W_ERROR_HAVE_NO_MEMORY(data
->string
);
2498 return WERR_INVALID_PARAM
;
2501 /****************************************************************
2502 _spoolss_GetPrinterData
2503 ****************************************************************/
2505 WERROR
_spoolss_GetPrinterData(struct pipes_struct
*p
,
2506 struct spoolss_GetPrinterData
*r
)
2508 struct spoolss_GetPrinterDataEx r2
;
2510 r2
.in
.handle
= r
->in
.handle
;
2511 r2
.in
.key_name
= "PrinterDriverData";
2512 r2
.in
.value_name
= r
->in
.value_name
;
2513 r2
.in
.offered
= r
->in
.offered
;
2514 r2
.out
.type
= r
->out
.type
;
2515 r2
.out
.data
= r
->out
.data
;
2516 r2
.out
.needed
= r
->out
.needed
;
2518 return _spoolss_GetPrinterDataEx(p
, &r2
);
2521 /*********************************************************
2522 Connect to the client machine.
2523 **********************************************************/
2525 static bool spoolss_connect_to_client(struct rpc_pipe_client
**pp_pipe
,
2526 struct sockaddr_storage
*client_ss
, const char *remote_machine
)
2529 struct cli_state
*the_cli
;
2530 struct sockaddr_storage rm_addr
;
2531 char addr
[INET6_ADDRSTRLEN
];
2533 if ( is_zero_addr(client_ss
) ) {
2534 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2536 if ( !resolve_name( remote_machine
, &rm_addr
, 0x20, false) ) {
2537 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine
));
2540 print_sockaddr(addr
, sizeof(addr
), &rm_addr
);
2542 rm_addr
= *client_ss
;
2543 print_sockaddr(addr
, sizeof(addr
), &rm_addr
);
2544 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2548 if (ismyaddr((struct sockaddr
*)(void *)&rm_addr
)) {
2549 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2554 /* setup the connection */
2555 ret
= cli_full_connection( &the_cli
, lp_netbios_name(), remote_machine
,
2556 &rm_addr
, 0, "IPC$", "IPC",
2560 0, lp_client_signing());
2562 if ( !NT_STATUS_IS_OK( ret
) ) {
2563 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2568 if ( cli_state_protocol(the_cli
) != PROTOCOL_NT1
) {
2569 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine
));
2570 cli_shutdown(the_cli
);
2575 * Ok - we have an anonymous connection to the IPC$ share.
2576 * Now start the NT Domain stuff :-).
2579 ret
= cli_rpc_pipe_open_noauth(the_cli
, &ndr_table_spoolss
.syntax_id
, pp_pipe
);
2580 if (!NT_STATUS_IS_OK(ret
)) {
2581 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2582 remote_machine
, nt_errstr(ret
)));
2583 cli_shutdown(the_cli
);
2590 /***************************************************************************
2591 Connect to the client.
2592 ****************************************************************************/
2594 static bool srv_spoolss_replyopenprinter(int snum
, const char *printer
,
2595 uint32_t localprinter
,
2596 enum winreg_Type type
,
2597 struct policy_handle
*handle
,
2598 struct notify_back_channel
**_chan
,
2599 struct sockaddr_storage
*client_ss
,
2600 struct messaging_context
*msg_ctx
)
2604 struct notify_back_channel
*chan
;
2606 for (chan
= back_channels
; chan
; chan
= chan
->next
) {
2607 if (memcmp(&chan
->client_address
, client_ss
,
2608 sizeof(struct sockaddr_storage
)) == 0) {
2614 * If it's the first connection, contact the client
2615 * and connect to the IPC$ share anonymously
2618 fstring unix_printer
;
2620 /* the +2 is to strip the leading 2 backslashs */
2621 fstrcpy(unix_printer
, printer
+ 2);
2623 chan
= talloc_zero(back_channels
, struct notify_back_channel
);
2627 chan
->client_address
= *client_ss
;
2629 if (!spoolss_connect_to_client(&chan
->cli_pipe
, client_ss
, unix_printer
)) {
2633 chan
->binding_handle
= chan
->cli_pipe
->binding_handle
;
2635 DLIST_ADD(back_channels
, chan
);
2637 messaging_register(msg_ctx
, NULL
, MSG_PRINTER_NOTIFY2
,
2638 receive_notify2_message_list
);
2639 /* Tell the connections db we're now interested in printer
2640 * notify messages. */
2641 serverid_register_msg_flags(messaging_server_id(msg_ctx
),
2642 true, FLAG_MSG_PRINT_NOTIFY
);
2646 * Tell the specific printing tdb we want messages for this printer
2647 * by registering our PID.
2650 if (!print_notify_register_pid(snum
)) {
2651 DEBUG(0, ("Failed to register our pid for printer %s\n",
2655 status
= dcerpc_spoolss_ReplyOpenPrinter(chan
->binding_handle
,
2664 if (!NT_STATUS_IS_OK(status
)) {
2665 DEBUG(5, ("dcerpc_spoolss_ReplyOpenPrinter returned [%s]\n", nt_errstr(status
)));
2666 result
= ntstatus_to_werror(status
);
2667 } else if (!W_ERROR_IS_OK(result
)) {
2668 DEBUG(5, ("ReplyOpenPrinter returned [%s]\n", win_errstr(result
)));
2671 chan
->active_connections
++;
2674 return (W_ERROR_IS_OK(result
));
2677 /****************************************************************
2678 ****************************************************************/
2680 static struct spoolss_NotifyOption
*dup_spoolss_NotifyOption(TALLOC_CTX
*mem_ctx
,
2681 const struct spoolss_NotifyOption
*r
)
2683 struct spoolss_NotifyOption
*option
;
2690 option
= talloc_zero(mem_ctx
, struct spoolss_NotifyOption
);
2697 if (!option
->count
) {
2701 option
->types
= talloc_zero_array(option
,
2702 struct spoolss_NotifyOptionType
, option
->count
);
2703 if (!option
->types
) {
2704 talloc_free(option
);
2708 for (i
=0; i
< option
->count
; i
++) {
2709 option
->types
[i
] = r
->types
[i
];
2711 if (option
->types
[i
].count
) {
2712 option
->types
[i
].fields
= talloc_zero_array(option
,
2713 union spoolss_Field
, option
->types
[i
].count
);
2714 if (!option
->types
[i
].fields
) {
2715 talloc_free(option
);
2718 for (k
=0; k
<option
->types
[i
].count
; k
++) {
2719 option
->types
[i
].fields
[k
] =
2720 r
->types
[i
].fields
[k
];
2728 /****************************************************************
2729 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2731 * before replying OK: status=0 a rpc call is made to the workstation
2732 * asking ReplyOpenPrinter
2734 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2735 * called from api_spoolss_rffpcnex
2736 ****************************************************************/
2738 WERROR
_spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct
*p
,
2739 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx
*r
)
2742 struct spoolss_NotifyOption
*option
= r
->in
.notify_options
;
2743 struct sockaddr_storage client_ss
;
2744 socklen_t client_len
;
2746 /* store the notify value in the printer struct */
2748 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
2751 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2752 "Invalid handle (%s:%u:%u).\n",
2753 OUR_HANDLE(r
->in
.handle
)));
2757 Printer
->notify
.flags
= r
->in
.flags
;
2758 Printer
->notify
.options
= r
->in
.options
;
2759 Printer
->notify
.printerlocal
= r
->in
.printer_local
;
2760 Printer
->notify
.msg_ctx
= p
->msg_ctx
;
2762 TALLOC_FREE(Printer
->notify
.option
);
2763 Printer
->notify
.option
= dup_spoolss_NotifyOption(Printer
, option
);
2765 fstrcpy(Printer
->notify
.localmachine
, r
->in
.local_machine
);
2767 /* Connect to the client machine and send a ReplyOpenPrinter */
2769 if ( Printer
->printer_type
== SPLHND_SERVER
)
2771 else if ( (Printer
->printer_type
== SPLHND_PRINTER
) &&
2772 !get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
) )
2775 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2776 "remote_address is %s\n",
2777 tsocket_address_string(p
->remote_address
, p
->mem_ctx
)));
2779 if (!lp_print_notify_backchannel(snum
)) {
2780 DEBUG(10, ("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2781 "backchannel disabled\n"));
2782 return WERR_SERVER_UNAVAILABLE
;
2785 client_len
= tsocket_address_bsd_sockaddr(p
->remote_address
,
2786 (struct sockaddr
*) &client_ss
,
2787 sizeof(struct sockaddr_storage
));
2788 if (client_len
< 0) {
2792 if(!srv_spoolss_replyopenprinter(snum
, Printer
->notify
.localmachine
,
2793 Printer
->notify
.printerlocal
, REG_SZ
,
2794 &Printer
->notify
.cli_hnd
,
2795 &Printer
->notify
.cli_chan
,
2796 &client_ss
, p
->msg_ctx
)) {
2797 return WERR_SERVER_UNAVAILABLE
;
2803 /*******************************************************************
2804 * fill a notify_info_data with the servername
2805 ********************************************************************/
2807 static void spoolss_notify_server_name(struct messaging_context
*msg_ctx
,
2809 struct spoolss_Notify
*data
,
2810 print_queue_struct
*queue
,
2811 struct spoolss_PrinterInfo2
*pinfo2
,
2812 TALLOC_CTX
*mem_ctx
)
2814 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->servername
);
2817 /*******************************************************************
2818 * fill a notify_info_data with the printername (not including the servername).
2819 ********************************************************************/
2821 static void spoolss_notify_printer_name(struct messaging_context
*msg_ctx
,
2823 struct spoolss_Notify
*data
,
2824 print_queue_struct
*queue
,
2825 struct spoolss_PrinterInfo2
*pinfo2
,
2826 TALLOC_CTX
*mem_ctx
)
2828 /* the notify name should not contain the \\server\ part */
2829 const char *p
= strrchr(pinfo2
->printername
, '\\');
2832 p
= pinfo2
->printername
;
2837 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, p
);
2840 /*******************************************************************
2841 * fill a notify_info_data with the servicename
2842 ********************************************************************/
2844 static void spoolss_notify_share_name(struct messaging_context
*msg_ctx
,
2846 struct spoolss_Notify
*data
,
2847 print_queue_struct
*queue
,
2848 struct spoolss_PrinterInfo2
*pinfo2
,
2849 TALLOC_CTX
*mem_ctx
)
2851 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, lp_servicename(snum
));
2854 /*******************************************************************
2855 * fill a notify_info_data with the port name
2856 ********************************************************************/
2858 static void spoolss_notify_port_name(struct messaging_context
*msg_ctx
,
2860 struct spoolss_Notify
*data
,
2861 print_queue_struct
*queue
,
2862 struct spoolss_PrinterInfo2
*pinfo2
,
2863 TALLOC_CTX
*mem_ctx
)
2865 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->portname
);
2868 /*******************************************************************
2869 * fill a notify_info_data with the printername
2870 * but it doesn't exist, have to see what to do
2871 ********************************************************************/
2873 static void spoolss_notify_driver_name(struct messaging_context
*msg_ctx
,
2875 struct spoolss_Notify
*data
,
2876 print_queue_struct
*queue
,
2877 struct spoolss_PrinterInfo2
*pinfo2
,
2878 TALLOC_CTX
*mem_ctx
)
2880 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->drivername
);
2883 /*******************************************************************
2884 * fill a notify_info_data with the comment
2885 ********************************************************************/
2887 static void spoolss_notify_comment(struct messaging_context
*msg_ctx
,
2889 struct spoolss_Notify
*data
,
2890 print_queue_struct
*queue
,
2891 struct spoolss_PrinterInfo2
*pinfo2
,
2892 TALLOC_CTX
*mem_ctx
)
2896 if (*pinfo2
->comment
== '\0') {
2897 p
= lp_comment(snum
);
2899 p
= pinfo2
->comment
;
2902 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, p
);
2905 /*******************************************************************
2906 * fill a notify_info_data with the comment
2907 * location = "Room 1, floor 2, building 3"
2908 ********************************************************************/
2910 static void spoolss_notify_location(struct messaging_context
*msg_ctx
,
2912 struct spoolss_Notify
*data
,
2913 print_queue_struct
*queue
,
2914 struct spoolss_PrinterInfo2
*pinfo2
,
2915 TALLOC_CTX
*mem_ctx
)
2917 const char *loc
= pinfo2
->location
;
2920 status
= printer_list_get_printer(mem_ctx
,
2925 if (NT_STATUS_IS_OK(status
)) {
2927 loc
= pinfo2
->location
;
2931 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, loc
);
2934 /*******************************************************************
2935 * fill a notify_info_data with the device mode
2936 * jfm:xxxx don't to it for know but that's a real problem !!!
2937 ********************************************************************/
2939 static void spoolss_notify_devmode(struct messaging_context
*msg_ctx
,
2941 struct spoolss_Notify
*data
,
2942 print_queue_struct
*queue
,
2943 struct spoolss_PrinterInfo2
*pinfo2
,
2944 TALLOC_CTX
*mem_ctx
)
2946 /* for a dummy implementation we have to zero the fields */
2947 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data
, NULL
);
2950 /*******************************************************************
2951 * fill a notify_info_data with the separator file name
2952 ********************************************************************/
2954 static void spoolss_notify_sepfile(struct messaging_context
*msg_ctx
,
2956 struct spoolss_Notify
*data
,
2957 print_queue_struct
*queue
,
2958 struct spoolss_PrinterInfo2
*pinfo2
,
2959 TALLOC_CTX
*mem_ctx
)
2961 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->sepfile
);
2964 /*******************************************************************
2965 * fill a notify_info_data with the print processor
2966 * jfm:xxxx return always winprint to indicate we don't do anything to it
2967 ********************************************************************/
2969 static void spoolss_notify_print_processor(struct messaging_context
*msg_ctx
,
2971 struct spoolss_Notify
*data
,
2972 print_queue_struct
*queue
,
2973 struct spoolss_PrinterInfo2
*pinfo2
,
2974 TALLOC_CTX
*mem_ctx
)
2976 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->printprocessor
);
2979 /*******************************************************************
2980 * fill a notify_info_data with the print processor options
2981 * jfm:xxxx send an empty string
2982 ********************************************************************/
2984 static void spoolss_notify_parameters(struct messaging_context
*msg_ctx
,
2986 struct spoolss_Notify
*data
,
2987 print_queue_struct
*queue
,
2988 struct spoolss_PrinterInfo2
*pinfo2
,
2989 TALLOC_CTX
*mem_ctx
)
2991 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->parameters
);
2994 /*******************************************************************
2995 * fill a notify_info_data with the data type
2996 * jfm:xxxx always send RAW as data type
2997 ********************************************************************/
2999 static void spoolss_notify_datatype(struct messaging_context
*msg_ctx
,
3001 struct spoolss_Notify
*data
,
3002 print_queue_struct
*queue
,
3003 struct spoolss_PrinterInfo2
*pinfo2
,
3004 TALLOC_CTX
*mem_ctx
)
3006 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->datatype
);
3009 /*******************************************************************
3010 * fill a notify_info_data with the security descriptor
3011 * jfm:xxxx send an null pointer to say no security desc
3012 * have to implement security before !
3013 ********************************************************************/
3015 static void spoolss_notify_security_desc(struct messaging_context
*msg_ctx
,
3017 struct spoolss_Notify
*data
,
3018 print_queue_struct
*queue
,
3019 struct spoolss_PrinterInfo2
*pinfo2
,
3020 TALLOC_CTX
*mem_ctx
)
3022 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data
, pinfo2
->secdesc
);
3025 /*******************************************************************
3026 * fill a notify_info_data with the attributes
3027 * jfm:xxxx a samba printer is always shared
3028 ********************************************************************/
3030 static void spoolss_notify_attributes(struct messaging_context
*msg_ctx
,
3032 struct spoolss_Notify
*data
,
3033 print_queue_struct
*queue
,
3034 struct spoolss_PrinterInfo2
*pinfo2
,
3035 TALLOC_CTX
*mem_ctx
)
3037 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->attributes
);
3040 /*******************************************************************
3041 * fill a notify_info_data with the priority
3042 ********************************************************************/
3044 static void spoolss_notify_priority(struct messaging_context
*msg_ctx
,
3046 struct spoolss_Notify
*data
,
3047 print_queue_struct
*queue
,
3048 struct spoolss_PrinterInfo2
*pinfo2
,
3049 TALLOC_CTX
*mem_ctx
)
3051 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->priority
);
3054 /*******************************************************************
3055 * fill a notify_info_data with the default priority
3056 ********************************************************************/
3058 static void spoolss_notify_default_priority(struct messaging_context
*msg_ctx
,
3060 struct spoolss_Notify
*data
,
3061 print_queue_struct
*queue
,
3062 struct spoolss_PrinterInfo2
*pinfo2
,
3063 TALLOC_CTX
*mem_ctx
)
3065 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->defaultpriority
);
3068 /*******************************************************************
3069 * fill a notify_info_data with the start time
3070 ********************************************************************/
3072 static void spoolss_notify_start_time(struct messaging_context
*msg_ctx
,
3074 struct spoolss_Notify
*data
,
3075 print_queue_struct
*queue
,
3076 struct spoolss_PrinterInfo2
*pinfo2
,
3077 TALLOC_CTX
*mem_ctx
)
3079 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->starttime
);
3082 /*******************************************************************
3083 * fill a notify_info_data with the until time
3084 ********************************************************************/
3086 static void spoolss_notify_until_time(struct messaging_context
*msg_ctx
,
3088 struct spoolss_Notify
*data
,
3089 print_queue_struct
*queue
,
3090 struct spoolss_PrinterInfo2
*pinfo2
,
3091 TALLOC_CTX
*mem_ctx
)
3093 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->untiltime
);
3096 /*******************************************************************
3097 * fill a notify_info_data with the status
3098 ********************************************************************/
3100 static void spoolss_notify_status(struct messaging_context
*msg_ctx
,
3102 struct spoolss_Notify
*data
,
3103 print_queue_struct
*queue
,
3104 struct spoolss_PrinterInfo2
*pinfo2
,
3105 TALLOC_CTX
*mem_ctx
)
3107 print_status_struct status
;
3109 print_queue_length(msg_ctx
, snum
, &status
);
3110 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, status
.status
);
3113 /*******************************************************************
3114 * fill a notify_info_data with the number of jobs queued
3115 ********************************************************************/
3117 static void spoolss_notify_cjobs(struct messaging_context
*msg_ctx
,
3119 struct spoolss_Notify
*data
,
3120 print_queue_struct
*queue
,
3121 struct spoolss_PrinterInfo2
*pinfo2
,
3122 TALLOC_CTX
*mem_ctx
)
3124 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(
3125 data
, print_queue_length(msg_ctx
, snum
, NULL
));
3128 /*******************************************************************
3129 * fill a notify_info_data with the average ppm
3130 ********************************************************************/
3132 static void spoolss_notify_average_ppm(struct messaging_context
*msg_ctx
,
3134 struct spoolss_Notify
*data
,
3135 print_queue_struct
*queue
,
3136 struct spoolss_PrinterInfo2
*pinfo2
,
3137 TALLOC_CTX
*mem_ctx
)
3139 /* always respond 8 pages per minutes */
3140 /* a little hard ! */
3141 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->averageppm
);
3144 /*******************************************************************
3145 * fill a notify_info_data with username
3146 ********************************************************************/
3148 static void spoolss_notify_username(struct messaging_context
*msg_ctx
,
3150 struct spoolss_Notify
*data
,
3151 print_queue_struct
*queue
,
3152 struct spoolss_PrinterInfo2
*pinfo2
,
3153 TALLOC_CTX
*mem_ctx
)
3155 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, queue
->fs_user
);
3158 /*******************************************************************
3159 * fill a notify_info_data with job status
3160 ********************************************************************/
3162 static void spoolss_notify_job_status(struct messaging_context
*msg_ctx
,
3164 struct spoolss_Notify
*data
,
3165 print_queue_struct
*queue
,
3166 struct spoolss_PrinterInfo2
*pinfo2
,
3167 TALLOC_CTX
*mem_ctx
)
3169 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, nt_printj_status(queue
->status
));
3172 /*******************************************************************
3173 * fill a notify_info_data with job name
3174 ********************************************************************/
3176 static void spoolss_notify_job_name(struct messaging_context
*msg_ctx
,
3178 struct spoolss_Notify
*data
,
3179 print_queue_struct
*queue
,
3180 struct spoolss_PrinterInfo2
*pinfo2
,
3181 TALLOC_CTX
*mem_ctx
)
3183 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, queue
->fs_file
);
3186 /*******************************************************************
3187 * fill a notify_info_data with job status
3188 ********************************************************************/
3190 static void spoolss_notify_job_status_string(struct messaging_context
*msg_ctx
,
3192 struct spoolss_Notify
*data
,
3193 print_queue_struct
*queue
,
3194 struct spoolss_PrinterInfo2
*pinfo2
,
3195 TALLOC_CTX
*mem_ctx
)
3198 * Now we're returning job status codes we just return a "" here. JRA.
3203 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
3206 switch (queue
->status
) {
3211 p
= ""; /* NT provides the paused string */
3220 #endif /* NO LONGER NEEDED. */
3222 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, p
);
3225 /*******************************************************************
3226 * fill a notify_info_data with job time
3227 ********************************************************************/
3229 static void spoolss_notify_job_time(struct messaging_context
*msg_ctx
,
3231 struct spoolss_Notify
*data
,
3232 print_queue_struct
*queue
,
3233 struct spoolss_PrinterInfo2
*pinfo2
,
3234 TALLOC_CTX
*mem_ctx
)
3236 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, 0);
3239 /*******************************************************************
3240 * fill a notify_info_data with job size
3241 ********************************************************************/
3243 static void spoolss_notify_job_size(struct messaging_context
*msg_ctx
,
3245 struct spoolss_Notify
*data
,
3246 print_queue_struct
*queue
,
3247 struct spoolss_PrinterInfo2
*pinfo2
,
3248 TALLOC_CTX
*mem_ctx
)
3250 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, queue
->size
);
3253 /*******************************************************************
3254 * fill a notify_info_data with page info
3255 ********************************************************************/
3256 static void spoolss_notify_total_pages(struct messaging_context
*msg_ctx
,
3258 struct spoolss_Notify
*data
,
3259 print_queue_struct
*queue
,
3260 struct spoolss_PrinterInfo2
*pinfo2
,
3261 TALLOC_CTX
*mem_ctx
)
3263 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, queue
->page_count
);
3266 /*******************************************************************
3267 * fill a notify_info_data with pages printed info.
3268 ********************************************************************/
3269 static void spoolss_notify_pages_printed(struct messaging_context
*msg_ctx
,
3271 struct spoolss_Notify
*data
,
3272 print_queue_struct
*queue
,
3273 struct spoolss_PrinterInfo2
*pinfo2
,
3274 TALLOC_CTX
*mem_ctx
)
3276 /* Add code when back-end tracks this */
3277 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, 0);
3280 /*******************************************************************
3281 Fill a notify_info_data with job position.
3282 ********************************************************************/
3284 static void spoolss_notify_job_position(struct messaging_context
*msg_ctx
,
3286 struct spoolss_Notify
*data
,
3287 print_queue_struct
*queue
,
3288 struct spoolss_PrinterInfo2
*pinfo2
,
3289 TALLOC_CTX
*mem_ctx
)
3291 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, queue
->job
);
3294 /*******************************************************************
3295 Fill a notify_info_data with submitted time.
3296 ********************************************************************/
3298 static void spoolss_notify_submitted_time(struct messaging_context
*msg_ctx
,
3300 struct spoolss_Notify
*data
,
3301 print_queue_struct
*queue
,
3302 struct spoolss_PrinterInfo2
*pinfo2
,
3303 TALLOC_CTX
*mem_ctx
)
3305 data
->data
.string
.string
= NULL
;
3306 data
->data
.string
.size
= 0;
3308 init_systemtime_buffer(mem_ctx
, gmtime(&queue
->time
),
3309 &data
->data
.string
.string
,
3310 &data
->data
.string
.size
);
3314 struct s_notify_info_data_table
3316 enum spoolss_NotifyType type
;
3319 enum spoolss_NotifyTable variable_type
;
3320 void (*fn
) (struct messaging_context
*msg_ctx
,
3321 int snum
, struct spoolss_Notify
*data
,
3322 print_queue_struct
*queue
,
3323 struct spoolss_PrinterInfo2
*pinfo2
,
3324 TALLOC_CTX
*mem_ctx
);
3327 /* A table describing the various print notification constants and
3328 whether the notification data is a pointer to a variable sized
3329 buffer, a one value uint32_t or a two value uint32_t. */
3331 static const struct s_notify_info_data_table notify_info_data_table
[] =
3333 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_SERVER_NAME
, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_server_name
},
3334 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PRINTER_NAME
, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_printer_name
},
3335 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_SHARE_NAME
, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_share_name
},
3336 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PORT_NAME
, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_port_name
},
3337 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_DRIVER_NAME
, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_driver_name
},
3338 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_COMMENT
, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING
, spoolss_notify_comment
},
3339 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_LOCATION
, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING
, spoolss_notify_location
},
3340 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_DEVMODE
, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE
, spoolss_notify_devmode
},
3341 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_SEPFILE
, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING
, spoolss_notify_sepfile
},
3342 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR
, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING
, spoolss_notify_print_processor
},
3343 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PARAMETERS
, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING
, spoolss_notify_parameters
},
3344 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_DATATYPE
, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING
, spoolss_notify_datatype
},
3345 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR
, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR
, spoolss_notify_security_desc
},
3346 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_ATTRIBUTES
, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD
, spoolss_notify_attributes
},
3347 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PRIORITY
, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD
, spoolss_notify_priority
},
3348 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY
, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD
, spoolss_notify_default_priority
},
3349 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_START_TIME
, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_start_time
},
3350 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_UNTIL_TIME
, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_until_time
},
3351 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_STATUS
, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD
, spoolss_notify_status
},
3352 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_STATUS_STRING
, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING
, NULL
},
3353 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_CJOBS
, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD
, spoolss_notify_cjobs
},
3354 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_AVERAGE_PPM
, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD
, spoolss_notify_average_ppm
},
3355 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_TOTAL_PAGES
, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD
, NULL
},
3356 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PAGES_PRINTED
, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD
, NULL
},
3357 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_TOTAL_BYTES
, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD
, NULL
},
3358 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_BYTES_PRINTED
, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD
, NULL
},
3359 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PRINTER_NAME
, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_printer_name
},
3360 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_MACHINE_NAME
, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_server_name
},
3361 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PORT_NAME
, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_port_name
},
3362 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_USER_NAME
, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_username
},
3363 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_NOTIFY_NAME
, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_username
},
3364 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_DATATYPE
, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING
, spoolss_notify_datatype
},
3365 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PRINT_PROCESSOR
, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING
, spoolss_notify_print_processor
},
3366 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PARAMETERS
, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING
, spoolss_notify_parameters
},
3367 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_DRIVER_NAME
, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_driver_name
},
3368 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_DEVMODE
, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE
, spoolss_notify_devmode
},
3369 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_STATUS
, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD
, spoolss_notify_job_status
},
3370 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_STATUS_STRING
, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING
, spoolss_notify_job_status_string
},
3371 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR
, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR
, NULL
},
3372 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_DOCUMENT
, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING
, spoolss_notify_job_name
},
3373 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PRIORITY
, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD
, spoolss_notify_priority
},
3374 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_POSITION
, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD
, spoolss_notify_job_position
},
3375 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_SUBMITTED
, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME
, spoolss_notify_submitted_time
},
3376 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_START_TIME
, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_start_time
},
3377 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_UNTIL_TIME
, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_until_time
},
3378 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_TIME
, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_job_time
},
3379 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_TOTAL_PAGES
, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD
, spoolss_notify_total_pages
},
3380 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PAGES_PRINTED
, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD
, spoolss_notify_pages_printed
},
3381 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_TOTAL_BYTES
, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD
, spoolss_notify_job_size
},
3384 /*******************************************************************
3385 Return the variable_type of info_data structure.
3386 ********************************************************************/
3388 static enum spoolss_NotifyTable
variable_type_of_notify_info_data(enum spoolss_NotifyType type
,
3393 for (i
= 0; i
< ARRAY_SIZE(notify_info_data_table
); i
++) {
3394 if ( (notify_info_data_table
[i
].type
== type
) &&
3395 (notify_info_data_table
[i
].field
== field
) ) {
3396 return notify_info_data_table
[i
].variable_type
;
3400 DEBUG(5, ("invalid notify data type %d/%d\n", type
, field
));
3402 return (enum spoolss_NotifyTable
) 0;
3405 /****************************************************************************
3406 ****************************************************************************/
3408 static bool search_notify(enum spoolss_NotifyType type
,
3414 for (i
= 0; i
< ARRAY_SIZE(notify_info_data_table
); i
++) {
3415 if (notify_info_data_table
[i
].type
== type
&&
3416 notify_info_data_table
[i
].field
== field
&&
3417 notify_info_data_table
[i
].fn
!= NULL
) {
3426 /****************************************************************************
3427 ****************************************************************************/
3429 static void construct_info_data(struct spoolss_Notify
*info_data
,
3430 enum spoolss_NotifyType type
,
3431 uint16_t field
, int id
)
3433 info_data
->type
= type
;
3434 info_data
->field
.field
= field
;
3435 info_data
->variable_type
= variable_type_of_notify_info_data(type
, field
);
3436 info_data
->job_id
= id
;
3439 /*******************************************************************
3441 * fill a notify_info struct with info asked
3443 ********************************************************************/
3445 static bool construct_notify_printer_info(struct messaging_context
*msg_ctx
,
3446 struct printer_handle
*print_hnd
,
3447 struct spoolss_NotifyInfo
*info
,
3448 struct spoolss_PrinterInfo2
*pinfo2
,
3450 const struct spoolss_NotifyOptionType
*option_type
,
3452 TALLOC_CTX
*mem_ctx
)
3455 enum spoolss_NotifyType type
;
3458 struct spoolss_Notify
*current_data
;
3460 type
= option_type
->type
;
3462 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3463 (type
== PRINTER_NOTIFY_TYPE
? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3464 option_type
->count
, lp_servicename(snum
)));
3466 for(field_num
=0; field_num
< option_type
->count
; field_num
++) {
3467 field
= option_type
->fields
[field_num
].field
;
3469 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num
, type
, field
));
3471 if (!search_notify(type
, field
, &j
) )
3474 info
->notifies
= talloc_realloc(info
, info
->notifies
,
3475 struct spoolss_Notify
,
3477 if (info
->notifies
== NULL
) {
3478 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3482 current_data
= &info
->notifies
[info
->count
];
3484 construct_info_data(current_data
, type
, field
, id
);
3486 DEBUG(10, ("construct_notify_printer_info: "
3487 "calling [%s] snum=%d printername=[%s])\n",
3488 notify_info_data_table
[j
].name
, snum
,
3489 pinfo2
->printername
));
3491 notify_info_data_table
[j
].fn(msg_ctx
, snum
, current_data
,
3492 NULL
, pinfo2
, mem_ctx
);
3500 /*******************************************************************
3502 * fill a notify_info struct with info asked
3504 ********************************************************************/
3506 static bool construct_notify_jobs_info(struct messaging_context
*msg_ctx
,
3507 print_queue_struct
*queue
,
3508 struct spoolss_NotifyInfo
*info
,
3509 struct spoolss_PrinterInfo2
*pinfo2
,
3511 const struct spoolss_NotifyOptionType
*option_type
,
3513 TALLOC_CTX
*mem_ctx
)
3516 enum spoolss_NotifyType type
;
3518 struct spoolss_Notify
*current_data
;
3520 DEBUG(4,("construct_notify_jobs_info\n"));
3522 type
= option_type
->type
;
3524 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3525 (type
== PRINTER_NOTIFY_TYPE
? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3526 option_type
->count
));
3528 for(field_num
=0; field_num
<option_type
->count
; field_num
++) {
3529 field
= option_type
->fields
[field_num
].field
;
3531 if (!search_notify(type
, field
, &j
) )
3534 info
->notifies
= talloc_realloc(info
, info
->notifies
,
3535 struct spoolss_Notify
,
3537 if (info
->notifies
== NULL
) {
3538 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3542 current_data
=&(info
->notifies
[info
->count
]);
3544 construct_info_data(current_data
, type
, field
, id
);
3545 notify_info_data_table
[j
].fn(msg_ctx
, snum
, current_data
,
3546 queue
, pinfo2
, mem_ctx
);
3554 * JFM: The enumeration is not that simple, it's even non obvious.
3556 * let's take an example: I want to monitor the PRINTER SERVER for
3557 * the printer's name and the number of jobs currently queued.
3558 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3559 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3561 * I have 3 printers on the back of my server.
3563 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3566 * 1 printer 1 name 1
3567 * 2 printer 1 cjob 1
3568 * 3 printer 2 name 2
3569 * 4 printer 2 cjob 2
3570 * 5 printer 3 name 3
3571 * 6 printer 3 name 3
3573 * that's the print server case, the printer case is even worse.
3576 /*******************************************************************
3578 * enumerate all printers on the printserver
3579 * fill a notify_info struct with info asked
3581 ********************************************************************/
3583 static WERROR
printserver_notify_info(struct pipes_struct
*p
,
3584 struct policy_handle
*hnd
,
3585 struct spoolss_NotifyInfo
*info
,
3586 TALLOC_CTX
*mem_ctx
)
3589 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, hnd
);
3590 int n_services
=lp_numservices();
3592 struct spoolss_NotifyOption
*option
;
3593 struct spoolss_NotifyOptionType option_type
;
3594 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
3597 DEBUG(4,("printserver_notify_info\n"));
3602 option
= Printer
->notify
.option
;
3605 info
->notifies
= NULL
;
3608 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3609 sending a ffpcn() request first */
3614 for (i
=0; i
<option
->count
; i
++) {
3615 option_type
= option
->types
[i
];
3617 if (option_type
.type
!= PRINTER_NOTIFY_TYPE
)
3620 for (snum
= 0; snum
< n_services
; snum
++) {
3621 if (!lp_browseable(snum
) ||
3622 !lp_snum_ok(snum
) ||
3623 !lp_print_ok(snum
)) {
3624 continue; /* skip */
3627 /* Maybe we should use the SYSTEM session_info here... */
3628 result
= winreg_get_printer_internal(mem_ctx
,
3629 get_session_info_system(),
3631 lp_servicename(snum
),
3633 if (!W_ERROR_IS_OK(result
)) {
3634 DEBUG(4, ("printserver_notify_info: "
3635 "Failed to get printer [%s]\n",
3636 lp_servicename(snum
)));
3641 construct_notify_printer_info(p
->msg_ctx
,
3647 TALLOC_FREE(pinfo2
);
3653 * Debugging information, don't delete.
3656 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3657 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info
->version
, info
->flags
, info
->count
));
3658 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3660 for (i
=0; i
<info
->count
; i
++) {
3661 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3662 i
, info
->data
[i
].type
, info
->data
[i
].field
, info
->data
[i
].reserved
,
3663 info
->data
[i
].id
, info
->data
[i
].size
, info
->data
[i
].enc_type
));
3670 /*******************************************************************
3672 * fill a notify_info struct with info asked
3674 ********************************************************************/
3676 static WERROR
printer_notify_info(struct pipes_struct
*p
,
3677 struct policy_handle
*hnd
,
3678 struct spoolss_NotifyInfo
*info
,
3679 TALLOC_CTX
*mem_ctx
)
3682 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, hnd
);
3685 struct spoolss_NotifyOption
*option
;
3686 struct spoolss_NotifyOptionType option_type
;
3688 print_queue_struct
*queue
=NULL
;
3689 print_status_struct status
;
3690 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
3693 DEBUG(4,("printer_notify_info\n"));
3698 option
= Printer
->notify
.option
;
3702 info
->notifies
= NULL
;
3705 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3706 sending a ffpcn() request first */
3711 if (!get_printer_snum(p
, hnd
, &snum
, NULL
)) {
3715 /* Maybe we should use the SYSTEM session_info here... */
3716 result
= winreg_get_printer_internal(mem_ctx
,
3717 get_session_info_system(),
3719 lp_servicename(snum
), &pinfo2
);
3720 if (!W_ERROR_IS_OK(result
)) {
3724 for (i
=0; i
<option
->count
; i
++) {
3725 option_type
= option
->types
[i
];
3727 switch (option_type
.type
) {
3728 case PRINTER_NOTIFY_TYPE
:
3729 if (construct_notify_printer_info(p
->msg_ctx
,
3738 case JOB_NOTIFY_TYPE
:
3740 count
= print_queue_status(p
->msg_ctx
, snum
, &queue
,
3743 for (j
=0; j
<count
; j
++) {
3744 construct_notify_jobs_info(p
->msg_ctx
,
3758 * Debugging information, don't delete.
3761 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3762 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3763 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3765 for (i=0; i<info->count; i++) {
3766 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3767 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3768 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3772 talloc_free(pinfo2
);
3776 /****************************************************************
3777 _spoolss_RouterRefreshPrinterChangeNotify
3778 ****************************************************************/
3780 WERROR
_spoolss_RouterRefreshPrinterChangeNotify(struct pipes_struct
*p
,
3781 struct spoolss_RouterRefreshPrinterChangeNotify
*r
)
3783 struct spoolss_NotifyInfo
*info
;
3785 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
3786 WERROR result
= WERR_BADFID
;
3788 /* we always have a spoolss_NotifyInfo struct */
3789 info
= talloc_zero(p
->mem_ctx
, struct spoolss_NotifyInfo
);
3791 result
= WERR_NOMEM
;
3795 *r
->out
.info
= info
;
3798 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3799 "Invalid handle (%s:%u:%u).\n",
3800 OUR_HANDLE(r
->in
.handle
)));
3804 DEBUG(4,("Printer type %x\n",Printer
->printer_type
));
3807 * We are now using the change value, and
3808 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3809 * I don't have a global notification system, I'm sending back all the
3810 * information even when _NOTHING_ has changed.
3813 /* We need to keep track of the change value to send back in
3814 RRPCN replies otherwise our updates are ignored. */
3816 Printer
->notify
.fnpcn
= true;
3818 if (Printer
->notify
.cli_chan
!= NULL
&&
3819 Printer
->notify
.cli_chan
->active_connections
> 0) {
3820 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3821 "Saving change value in request [%x]\n",
3823 Printer
->notify
.change
= r
->in
.change_low
;
3826 /* just ignore the spoolss_NotifyOption */
3828 switch (Printer
->printer_type
) {
3830 result
= printserver_notify_info(p
, r
->in
.handle
,
3834 case SPLHND_PRINTER
:
3835 result
= printer_notify_info(p
, r
->in
.handle
,
3840 Printer
->notify
.fnpcn
= false;
3846 /********************************************************************
3847 ********************************************************************/
3849 static WERROR
create_printername(TALLOC_CTX
*mem_ctx
,
3850 const char *servername
,
3851 const char *printername
,
3852 const char **printername_p
)
3854 /* FIXME: add lp_force_printername() */
3856 if (servername
== NULL
) {
3857 *printername_p
= talloc_strdup(mem_ctx
, printername
);
3858 W_ERROR_HAVE_NO_MEMORY(*printername_p
);
3862 if (servername
[0] == '\\' && servername
[1] == '\\') {
3866 *printername_p
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s", servername
, printername
);
3867 W_ERROR_HAVE_NO_MEMORY(*printername_p
);
3872 /********************************************************************
3873 ********************************************************************/
3875 static void compose_devicemode_devicename(struct spoolss_DeviceMode
*dm
,
3876 const char *printername
)
3882 dm
->devicename
= talloc_strndup(dm
, printername
,
3883 MIN(strlen(printername
), 31));
3886 /********************************************************************
3887 * construct_printer_info_0
3888 * fill a printer_info_0 struct
3889 ********************************************************************/
3891 static WERROR
construct_printer_info0(TALLOC_CTX
*mem_ctx
,
3892 const struct auth_session_info
*session_info
,
3893 struct messaging_context
*msg_ctx
,
3894 struct spoolss_PrinterInfo2
*info2
,
3895 const char *servername
,
3896 struct spoolss_PrinterInfo0
*r
,
3900 struct printer_session_counter
*session_counter
;
3901 struct timeval setuptime
;
3902 print_status_struct status
;
3905 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->printername
);
3906 if (!W_ERROR_IS_OK(result
)) {
3911 r
->servername
= talloc_strdup(mem_ctx
, servername
);
3912 W_ERROR_HAVE_NO_MEMORY(r
->servername
);
3914 r
->servername
= NULL
;
3917 count
= print_queue_length(msg_ctx
, snum
, &status
);
3919 /* check if we already have a counter for this printer */
3920 for (session_counter
= counter_list
; session_counter
; session_counter
= session_counter
->next
) {
3921 if (session_counter
->snum
== snum
)
3925 /* it's the first time, add it to the list */
3926 if (session_counter
== NULL
) {
3927 session_counter
= talloc_zero(counter_list
, struct printer_session_counter
);
3928 W_ERROR_HAVE_NO_MEMORY(session_counter
);
3929 session_counter
->snum
= snum
;
3930 session_counter
->counter
= 0;
3931 DLIST_ADD(counter_list
, session_counter
);
3935 session_counter
->counter
++;
3941 get_startup_time(&setuptime
);
3942 init_systemtime(&r
->time
, gmtime(&setuptime
.tv_sec
));
3945 * the global_counter should be stored in a TDB as it's common to all the clients
3946 * and should be zeroed on samba startup
3948 r
->global_counter
= session_counter
->counter
;
3950 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3951 SSVAL(&r
->version
, 0, 0x0005); /* NT 5 */
3952 SSVAL(&r
->version
, 2, 0x0893); /* build 2195 */
3953 r
->free_build
= SPOOLSS_RELEASE_BUILD
;
3955 r
->max_spooling
= 0;
3956 r
->session_counter
= session_counter
->counter
;
3957 r
->num_error_out_of_paper
= 0x0;
3958 r
->num_error_not_ready
= 0x0; /* number of print failure */
3960 r
->number_of_processors
= 0x1;
3961 r
->processor_type
= PROCESSOR_INTEL_PENTIUM
; /* 586 Pentium ? */
3962 r
->high_part_total_bytes
= 0x0;
3964 /* ChangeID in milliseconds*/
3965 winreg_printer_get_changeid_internal(mem_ctx
, session_info
, msg_ctx
,
3966 info2
->sharename
, &r
->change_id
);
3968 r
->last_error
= WERR_OK
;
3969 r
->status
= nt_printq_status(status
.status
);
3970 r
->enumerate_network_printers
= 0x0;
3971 r
->c_setprinter
= 0x0;
3972 r
->processor_architecture
= PROCESSOR_ARCHITECTURE_INTEL
;
3973 r
->processor_level
= 0x6; /* 6 ???*/
3982 /********************************************************************
3983 * construct_printer_info1
3984 * fill a spoolss_PrinterInfo1 struct
3985 ********************************************************************/
3987 static WERROR
construct_printer_info1(TALLOC_CTX
*mem_ctx
,
3988 const struct spoolss_PrinterInfo2
*info2
,
3990 const char *servername
,
3991 struct spoolss_PrinterInfo1
*r
,
3998 if (info2
->comment
== NULL
|| info2
->comment
[0] == '\0') {
3999 r
->comment
= talloc_strdup(mem_ctx
, lp_comment(snum
));
4001 r
->comment
= talloc_strdup(mem_ctx
, info2
->comment
); /* saved comment */
4003 W_ERROR_HAVE_NO_MEMORY(r
->comment
);
4005 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->name
);
4006 if (!W_ERROR_IS_OK(result
)) {
4010 r
->description
= talloc_asprintf(mem_ctx
, "%s,%s,%s",
4014 W_ERROR_HAVE_NO_MEMORY(r
->description
);
4019 /********************************************************************
4020 * construct_printer_info2
4021 * fill a spoolss_PrinterInfo2 struct
4022 ********************************************************************/
4024 static WERROR
construct_printer_info2(TALLOC_CTX
*mem_ctx
,
4025 struct messaging_context
*msg_ctx
,
4026 const struct spoolss_PrinterInfo2
*info2
,
4027 const char *servername
,
4028 struct spoolss_PrinterInfo2
*r
,
4032 print_status_struct status
;
4035 count
= print_queue_length(msg_ctx
, snum
, &status
);
4038 r
->servername
= talloc_strdup(mem_ctx
, servername
);
4039 W_ERROR_HAVE_NO_MEMORY(r
->servername
);
4041 r
->servername
= NULL
;
4044 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->printername
);
4045 if (!W_ERROR_IS_OK(result
)) {
4049 r
->sharename
= talloc_strdup(mem_ctx
, lp_servicename(snum
));
4050 W_ERROR_HAVE_NO_MEMORY(r
->sharename
);
4051 r
->portname
= talloc_strdup(mem_ctx
, info2
->portname
);
4052 W_ERROR_HAVE_NO_MEMORY(r
->portname
);
4053 r
->drivername
= talloc_strdup(mem_ctx
, info2
->drivername
);
4054 W_ERROR_HAVE_NO_MEMORY(r
->drivername
);
4056 if (info2
->comment
[0] == '\0') {
4057 r
->comment
= talloc_strdup(mem_ctx
, lp_comment(snum
));
4059 r
->comment
= talloc_strdup(mem_ctx
, info2
->comment
);
4061 W_ERROR_HAVE_NO_MEMORY(r
->comment
);
4063 r
->location
= talloc_strdup(mem_ctx
, info2
->location
);
4064 if (info2
->location
[0] == '\0') {
4065 const char *loc
= NULL
;
4068 nt_status
= printer_list_get_printer(mem_ctx
,
4073 if (NT_STATUS_IS_OK(nt_status
)) {
4075 r
->location
= talloc_strdup(mem_ctx
, loc
);
4079 W_ERROR_HAVE_NO_MEMORY(r
->location
);
4081 r
->sepfile
= talloc_strdup(mem_ctx
, info2
->sepfile
);
4082 W_ERROR_HAVE_NO_MEMORY(r
->sepfile
);
4083 r
->printprocessor
= talloc_strdup(mem_ctx
, info2
->printprocessor
);
4084 W_ERROR_HAVE_NO_MEMORY(r
->printprocessor
);
4085 r
->datatype
= talloc_strdup(mem_ctx
, info2
->datatype
);
4086 W_ERROR_HAVE_NO_MEMORY(r
->datatype
);
4087 r
->parameters
= talloc_strdup(mem_ctx
, info2
->parameters
);
4088 W_ERROR_HAVE_NO_MEMORY(r
->parameters
);
4090 r
->attributes
= info2
->attributes
;
4092 r
->priority
= info2
->priority
;
4093 r
->defaultpriority
= info2
->defaultpriority
;
4094 r
->starttime
= info2
->starttime
;
4095 r
->untiltime
= info2
->untiltime
;
4096 r
->status
= nt_printq_status(status
.status
);
4098 r
->averageppm
= info2
->averageppm
;
4100 copy_devicemode(mem_ctx
, info2
->devmode
, &r
->devmode
);
4102 DEBUG(8,("Returning NULL Devicemode!\n"));
4105 compose_devicemode_devicename(r
->devmode
, r
->printername
);
4109 if (info2
->secdesc
!= NULL
) {
4110 /* don't use talloc_steal() here unless you do a deep steal of all
4111 the SEC_DESC members */
4113 r
->secdesc
= dup_sec_desc(mem_ctx
, info2
->secdesc
);
4119 /********************************************************************
4120 * construct_printer_info3
4121 * fill a spoolss_PrinterInfo3 struct
4122 ********************************************************************/
4124 static WERROR
construct_printer_info3(TALLOC_CTX
*mem_ctx
,
4125 const struct spoolss_PrinterInfo2
*info2
,
4126 const char *servername
,
4127 struct spoolss_PrinterInfo3
*r
,
4130 /* These are the components of the SD we are returning. */
4132 if (info2
->secdesc
!= NULL
) {
4133 /* don't use talloc_steal() here unless you do a deep steal of all
4134 the SEC_DESC members */
4136 r
->secdesc
= dup_sec_desc(mem_ctx
, info2
->secdesc
);
4137 W_ERROR_HAVE_NO_MEMORY(r
->secdesc
);
4143 /********************************************************************
4144 * construct_printer_info4
4145 * fill a spoolss_PrinterInfo4 struct
4146 ********************************************************************/
4148 static WERROR
construct_printer_info4(TALLOC_CTX
*mem_ctx
,
4149 const struct spoolss_PrinterInfo2
*info2
,
4150 const char *servername
,
4151 struct spoolss_PrinterInfo4
*r
,
4156 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->printername
);
4157 if (!W_ERROR_IS_OK(result
)) {
4162 r
->servername
= talloc_strdup(mem_ctx
, servername
);
4163 W_ERROR_HAVE_NO_MEMORY(r
->servername
);
4165 r
->servername
= NULL
;
4168 r
->attributes
= info2
->attributes
;
4173 /********************************************************************
4174 * construct_printer_info5
4175 * fill a spoolss_PrinterInfo5 struct
4176 ********************************************************************/
4178 static WERROR
construct_printer_info5(TALLOC_CTX
*mem_ctx
,
4179 const struct spoolss_PrinterInfo2
*info2
,
4180 const char *servername
,
4181 struct spoolss_PrinterInfo5
*r
,
4186 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->printername
);
4187 if (!W_ERROR_IS_OK(result
)) {
4191 r
->portname
= talloc_strdup(mem_ctx
, info2
->portname
);
4192 W_ERROR_HAVE_NO_MEMORY(r
->portname
);
4194 r
->attributes
= info2
->attributes
;
4196 /* these two are not used by NT+ according to MSDN */
4197 r
->device_not_selected_timeout
= 0x0; /* have seen 0x3a98 */
4198 r
->transmission_retry_timeout
= 0x0; /* have seen 0xafc8 */
4203 /********************************************************************
4204 * construct_printer_info_6
4205 * fill a spoolss_PrinterInfo6 struct
4206 ********************************************************************/
4208 static WERROR
construct_printer_info6(TALLOC_CTX
*mem_ctx
,
4209 struct messaging_context
*msg_ctx
,
4210 const struct spoolss_PrinterInfo2
*info2
,
4211 const char *servername
,
4212 struct spoolss_PrinterInfo6
*r
,
4215 print_status_struct status
;
4217 print_queue_length(msg_ctx
, snum
, &status
);
4219 r
->status
= nt_printq_status(status
.status
);
4224 /********************************************************************
4225 * construct_printer_info7
4226 * fill a spoolss_PrinterInfo7 struct
4227 ********************************************************************/
4229 static WERROR
construct_printer_info7(TALLOC_CTX
*mem_ctx
,
4230 struct messaging_context
*msg_ctx
,
4231 const char *servername
,
4232 struct spoolss_PrinterInfo7
*r
,
4235 const struct auth_session_info
*session_info
= get_session_info_system();
4238 if (is_printer_published(mem_ctx
, session_info
, msg_ctx
,
4240 lp_servicename(snum
), &guid
, NULL
)) {
4241 r
->guid
= talloc_strdup_upper(mem_ctx
, GUID_string2(mem_ctx
, &guid
));
4242 r
->action
= DSPRINT_PUBLISH
;
4244 r
->guid
= talloc_strdup(mem_ctx
, "");
4245 r
->action
= DSPRINT_UNPUBLISH
;
4247 W_ERROR_HAVE_NO_MEMORY(r
->guid
);
4252 /********************************************************************
4253 * construct_printer_info8
4254 * fill a spoolss_PrinterInfo8 struct
4255 ********************************************************************/
4257 static WERROR
construct_printer_info8(TALLOC_CTX
*mem_ctx
,
4258 const struct spoolss_PrinterInfo2
*info2
,
4259 const char *servername
,
4260 struct spoolss_DeviceModeInfo
*r
,
4264 const char *printername
;
4266 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &printername
);
4267 if (!W_ERROR_IS_OK(result
)) {
4271 copy_devicemode(mem_ctx
, info2
->devmode
, &r
->devmode
);
4273 DEBUG(8,("Returning NULL Devicemode!\n"));
4276 compose_devicemode_devicename(r
->devmode
, printername
);
4282 /********************************************************************
4283 ********************************************************************/
4285 static bool snum_is_shared_printer(int snum
)
4287 return (lp_browseable(snum
) && lp_snum_ok(snum
) && lp_print_ok(snum
));
4290 /********************************************************************
4291 Spoolss_enumprinters.
4292 ********************************************************************/
4294 static WERROR
enum_all_printers_info_level(TALLOC_CTX
*mem_ctx
,
4295 const struct auth_session_info
*session_info
,
4296 struct messaging_context
*msg_ctx
,
4297 const char *servername
,
4300 union spoolss_PrinterInfo
**info_p
,
4304 int n_services
= lp_numservices();
4305 union spoolss_PrinterInfo
*info
= NULL
;
4307 WERROR result
= WERR_OK
;
4308 struct dcerpc_binding_handle
*b
= NULL
;
4309 TALLOC_CTX
*tmp_ctx
= NULL
;
4311 tmp_ctx
= talloc_new(mem_ctx
);
4319 for (snum
= 0; snum
< n_services
; snum
++) {
4321 const char *printer
;
4322 struct spoolss_PrinterInfo2
*info2
;
4324 if (!snum_is_shared_printer(snum
)) {
4328 printer
= lp_const_servicename(snum
);
4330 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
4334 result
= winreg_printer_binding_handle(tmp_ctx
,
4338 if (!W_ERROR_IS_OK(result
)) {
4343 result
= winreg_create_printer(tmp_ctx
, b
,
4345 if (!W_ERROR_IS_OK(result
)) {
4349 info
= talloc_realloc(tmp_ctx
, info
,
4350 union spoolss_PrinterInfo
,
4353 result
= WERR_NOMEM
;
4357 result
= winreg_get_printer(tmp_ctx
, b
,
4359 if (!W_ERROR_IS_OK(result
)) {
4365 result
= construct_printer_info0(info
, session_info
,
4368 &info
[count
].info0
, snum
);
4371 result
= construct_printer_info1(info
, info2
, flags
,
4373 &info
[count
].info1
, snum
);
4376 result
= construct_printer_info2(info
, msg_ctx
, info2
,
4378 &info
[count
].info2
, snum
);
4381 result
= construct_printer_info4(info
, info2
,
4383 &info
[count
].info4
, snum
);
4386 result
= construct_printer_info5(info
, info2
,
4388 &info
[count
].info5
, snum
);
4392 result
= WERR_UNKNOWN_LEVEL
;
4396 if (!W_ERROR_IS_OK(result
)) {
4404 if (W_ERROR_IS_OK(result
)) {
4405 *info_p
= talloc_move(mem_ctx
, &info
);
4409 talloc_free(tmp_ctx
);
4414 /********************************************************************
4415 * handle enumeration of printers at level 0
4416 ********************************************************************/
4418 static WERROR
enumprinters_level0(TALLOC_CTX
*mem_ctx
,
4419 const struct auth_session_info
*session_info
,
4420 struct messaging_context
*msg_ctx
,
4422 const char *servername
,
4423 union spoolss_PrinterInfo
**info
,
4426 DEBUG(4,("enum_all_printers_info_0\n"));
4428 return enum_all_printers_info_level(mem_ctx
, session_info
, msg_ctx
,
4429 servername
, 0, flags
, info
, count
);
4433 /********************************************************************
4434 ********************************************************************/
4436 static WERROR
enum_all_printers_info_1(TALLOC_CTX
*mem_ctx
,
4437 const struct auth_session_info
*session_info
,
4438 struct messaging_context
*msg_ctx
,
4439 const char *servername
,
4441 union spoolss_PrinterInfo
**info
,
4444 DEBUG(4,("enum_all_printers_info_1\n"));
4446 return enum_all_printers_info_level(mem_ctx
, session_info
, msg_ctx
,
4447 servername
, 1, flags
, info
, count
);
4450 /********************************************************************
4451 enum_all_printers_info_1_local.
4452 *********************************************************************/
4454 static WERROR
enum_all_printers_info_1_local(TALLOC_CTX
*mem_ctx
,
4455 const struct auth_session_info
*session_info
,
4456 struct messaging_context
*msg_ctx
,
4457 const char *servername
,
4458 union spoolss_PrinterInfo
**info
,
4461 DEBUG(4,("enum_all_printers_info_1_local\n"));
4463 return enum_all_printers_info_1(mem_ctx
, session_info
, msg_ctx
,
4464 servername
, PRINTER_ENUM_ICON8
, info
, count
);
4467 /********************************************************************
4468 enum_all_printers_info_1_name.
4469 *********************************************************************/
4471 static WERROR
enum_all_printers_info_1_name(TALLOC_CTX
*mem_ctx
,
4472 const struct auth_session_info
*session_info
,
4473 struct messaging_context
*msg_ctx
,
4474 const char *servername
,
4475 union spoolss_PrinterInfo
**info
,
4478 const char *s
= servername
;
4480 DEBUG(4,("enum_all_printers_info_1_name\n"));
4482 if ((servername
[0] == '\\') && (servername
[1] == '\\')) {
4486 if (!is_myname_or_ipaddr(s
)) {
4487 return WERR_INVALID_NAME
;
4490 return enum_all_printers_info_1(mem_ctx
, session_info
, msg_ctx
,
4491 servername
, PRINTER_ENUM_ICON8
, info
, count
);
4494 /********************************************************************
4495 enum_all_printers_info_1_network.
4496 *********************************************************************/
4498 static WERROR
enum_all_printers_info_1_network(TALLOC_CTX
*mem_ctx
,
4499 const struct auth_session_info
*session_info
,
4500 struct messaging_context
*msg_ctx
,
4501 const char *servername
,
4502 union spoolss_PrinterInfo
**info
,
4505 const char *s
= servername
;
4507 DEBUG(4,("enum_all_printers_info_1_network\n"));
4509 /* If we respond to a enum_printers level 1 on our name with flags
4510 set to PRINTER_ENUM_REMOTE with a list of printers then these
4511 printers incorrectly appear in the APW browse list.
4512 Specifically the printers for the server appear at the workgroup
4513 level where all the other servers in the domain are
4514 listed. Windows responds to this call with a
4515 WERR_CAN_NOT_COMPLETE so we should do the same. */
4517 if (servername
[0] == '\\' && servername
[1] == '\\') {
4521 if (is_myname_or_ipaddr(s
)) {
4522 return WERR_CAN_NOT_COMPLETE
;
4525 return enum_all_printers_info_1(mem_ctx
, session_info
, msg_ctx
,
4526 servername
, PRINTER_ENUM_NAME
, info
, count
);
4529 /********************************************************************
4530 * api_spoolss_enumprinters
4532 * called from api_spoolss_enumprinters (see this to understand)
4533 ********************************************************************/
4535 static WERROR
enum_all_printers_info_2(TALLOC_CTX
*mem_ctx
,
4536 const struct auth_session_info
*session_info
,
4537 struct messaging_context
*msg_ctx
,
4538 const char *servername
,
4539 union spoolss_PrinterInfo
**info
,
4542 DEBUG(4,("enum_all_printers_info_2\n"));
4544 return enum_all_printers_info_level(mem_ctx
, session_info
, msg_ctx
,
4545 servername
, 2, 0, info
, count
);
4548 /********************************************************************
4549 * handle enumeration of printers at level 1
4550 ********************************************************************/
4552 static WERROR
enumprinters_level1(TALLOC_CTX
*mem_ctx
,
4553 const struct auth_session_info
*session_info
,
4554 struct messaging_context
*msg_ctx
,
4556 const char *servername
,
4557 union spoolss_PrinterInfo
**info
,
4560 /* Not all the flags are equals */
4562 if (flags
& PRINTER_ENUM_LOCAL
) {
4563 return enum_all_printers_info_1_local(mem_ctx
, session_info
,
4564 msg_ctx
, servername
, info
, count
);
4567 if (flags
& PRINTER_ENUM_NAME
) {
4568 return enum_all_printers_info_1_name(mem_ctx
, session_info
,
4569 msg_ctx
, servername
, info
,
4573 if (flags
& PRINTER_ENUM_NETWORK
) {
4574 return enum_all_printers_info_1_network(mem_ctx
, session_info
,
4575 msg_ctx
, servername
, info
,
4579 return WERR_OK
; /* NT4sp5 does that */
4582 /********************************************************************
4583 * handle enumeration of printers at level 2
4584 ********************************************************************/
4586 static WERROR
enumprinters_level2(TALLOC_CTX
*mem_ctx
,
4587 const struct auth_session_info
*session_info
,
4588 struct messaging_context
*msg_ctx
,
4590 const char *servername
,
4591 union spoolss_PrinterInfo
**info
,
4594 if (flags
& PRINTER_ENUM_LOCAL
) {
4596 return enum_all_printers_info_2(mem_ctx
, session_info
, msg_ctx
,
4601 if (flags
& PRINTER_ENUM_NAME
) {
4602 if (servername
&& !is_myname_or_ipaddr(canon_servername(servername
))) {
4603 return WERR_INVALID_NAME
;
4606 return enum_all_printers_info_2(mem_ctx
, session_info
, msg_ctx
,
4611 if (flags
& PRINTER_ENUM_REMOTE
) {
4612 return WERR_UNKNOWN_LEVEL
;
4618 /********************************************************************
4619 * handle enumeration of printers at level 4
4620 ********************************************************************/
4622 static WERROR
enumprinters_level4(TALLOC_CTX
*mem_ctx
,
4623 const struct auth_session_info
*session_info
,
4624 struct messaging_context
*msg_ctx
,
4626 const char *servername
,
4627 union spoolss_PrinterInfo
**info
,
4630 DEBUG(4,("enum_all_printers_info_4\n"));
4632 return enum_all_printers_info_level(mem_ctx
, session_info
, msg_ctx
,
4633 servername
, 4, flags
, info
, count
);
4637 /********************************************************************
4638 * handle enumeration of printers at level 5
4639 ********************************************************************/
4641 static WERROR
enumprinters_level5(TALLOC_CTX
*mem_ctx
,
4642 const struct auth_session_info
*session_info
,
4643 struct messaging_context
*msg_ctx
,
4645 const char *servername
,
4646 union spoolss_PrinterInfo
**info
,
4649 DEBUG(4,("enum_all_printers_info_5\n"));
4651 return enum_all_printers_info_level(mem_ctx
, session_info
, msg_ctx
,
4652 servername
, 5, flags
, info
, count
);
4655 /****************************************************************
4656 _spoolss_EnumPrinters
4657 ****************************************************************/
4659 WERROR
_spoolss_EnumPrinters(struct pipes_struct
*p
,
4660 struct spoolss_EnumPrinters
*r
)
4662 const struct auth_session_info
*session_info
= get_session_info_system();
4665 /* that's an [in out] buffer */
4667 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
4668 return WERR_INVALID_PARAM
;
4671 DEBUG(4,("_spoolss_EnumPrinters\n"));
4675 *r
->out
.info
= NULL
;
4679 * flags==PRINTER_ENUM_NAME
4680 * if name=="" then enumerates all printers
4681 * if name!="" then enumerate the printer
4682 * flags==PRINTER_ENUM_REMOTE
4683 * name is NULL, enumerate printers
4684 * Level 2: name!="" enumerates printers, name can't be NULL
4685 * Level 3: doesn't exist
4686 * Level 4: does a local registry lookup
4687 * Level 5: same as Level 2
4690 if (r
->in
.server
&& r
->in
.server
[0] == '\0') {
4691 r
->in
.server
= NULL
;
4694 switch (r
->in
.level
) {
4696 result
= enumprinters_level0(p
->mem_ctx
, session_info
,
4697 p
->msg_ctx
, r
->in
.flags
,
4699 r
->out
.info
, r
->out
.count
);
4702 result
= enumprinters_level1(p
->mem_ctx
, session_info
,
4703 p
->msg_ctx
, r
->in
.flags
,
4705 r
->out
.info
, r
->out
.count
);
4708 result
= enumprinters_level2(p
->mem_ctx
, session_info
,
4709 p
->msg_ctx
, r
->in
.flags
,
4711 r
->out
.info
, r
->out
.count
);
4714 result
= enumprinters_level4(p
->mem_ctx
, session_info
,
4715 p
->msg_ctx
, r
->in
.flags
,
4717 r
->out
.info
, r
->out
.count
);
4720 result
= enumprinters_level5(p
->mem_ctx
, session_info
,
4721 p
->msg_ctx
, r
->in
.flags
,
4723 r
->out
.info
, r
->out
.count
);
4726 return WERR_UNKNOWN_LEVEL
;
4729 if (!W_ERROR_IS_OK(result
)) {
4733 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
4734 spoolss_EnumPrinters
,
4735 *r
->out
.info
, r
->in
.level
,
4737 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
4738 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
4740 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
4743 /****************************************************************
4745 ****************************************************************/
4747 WERROR
_spoolss_GetPrinter(struct pipes_struct
*p
,
4748 struct spoolss_GetPrinter
*r
)
4750 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
4751 struct spoolss_PrinterInfo2
*info2
= NULL
;
4752 WERROR result
= WERR_OK
;
4755 /* that's an [in out] buffer */
4757 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
4758 return WERR_INVALID_PARAM
;
4763 if (Printer
== NULL
) {
4767 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
4771 result
= winreg_get_printer_internal(p
->mem_ctx
,
4772 get_session_info_system(),
4774 lp_const_servicename(snum
),
4776 if (!W_ERROR_IS_OK(result
)) {
4780 switch (r
->in
.level
) {
4782 result
= construct_printer_info0(p
->mem_ctx
,
4783 get_session_info_system(),
4786 Printer
->servername
,
4787 &r
->out
.info
->info0
,
4791 result
= construct_printer_info1(p
->mem_ctx
, info2
,
4793 Printer
->servername
,
4794 &r
->out
.info
->info1
, snum
);
4797 result
= construct_printer_info2(p
->mem_ctx
, p
->msg_ctx
, info2
,
4798 Printer
->servername
,
4799 &r
->out
.info
->info2
, snum
);
4802 result
= construct_printer_info3(p
->mem_ctx
, info2
,
4803 Printer
->servername
,
4804 &r
->out
.info
->info3
, snum
);
4807 result
= construct_printer_info4(p
->mem_ctx
, info2
,
4808 Printer
->servername
,
4809 &r
->out
.info
->info4
, snum
);
4812 result
= construct_printer_info5(p
->mem_ctx
, info2
,
4813 Printer
->servername
,
4814 &r
->out
.info
->info5
, snum
);
4817 result
= construct_printer_info6(p
->mem_ctx
, p
->msg_ctx
, info2
,
4818 Printer
->servername
,
4819 &r
->out
.info
->info6
, snum
);
4822 result
= construct_printer_info7(p
->mem_ctx
, p
->msg_ctx
,
4823 Printer
->servername
,
4824 &r
->out
.info
->info7
, snum
);
4827 result
= construct_printer_info8(p
->mem_ctx
, info2
,
4828 Printer
->servername
,
4829 &r
->out
.info
->info8
, snum
);
4832 result
= WERR_UNKNOWN_LEVEL
;
4838 if (!W_ERROR_IS_OK(result
)) {
4839 DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
4840 r
->in
.level
, win_errstr(result
)));
4841 TALLOC_FREE(r
->out
.info
);
4845 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo
,
4846 r
->out
.info
, r
->in
.level
);
4847 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
4849 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
4852 /********************************************************************
4853 ********************************************************************/
4855 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4857 if (in && strlen(in)) { \
4858 out = talloc_strdup(mem_ctx, in); \
4860 out = talloc_strdup(mem_ctx, ""); \
4862 W_ERROR_HAVE_NO_MEMORY(out); \
4865 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, arch, ver, in, out) \
4867 if (in && strlen(in)) { \
4868 out = talloc_asprintf(mem_ctx, "\\\\%s\\print$\\%s\\%d\\%s", server, get_short_archi(arch), ver, in); \
4870 out = talloc_strdup(mem_ctx, ""); \
4872 W_ERROR_HAVE_NO_MEMORY(out); \
4875 static WERROR
string_array_from_driver_info(TALLOC_CTX
*mem_ctx
,
4876 const char **string_array
,
4877 const char ***presult
,
4878 const char *cservername
,
4882 int i
, num_strings
= 0;
4883 const char **array
= NULL
;
4885 if (string_array
== NULL
) {
4886 return WERR_INVALID_PARAMETER
;
4889 for (i
=0; string_array
[i
] && string_array
[i
][0] != '\0'; i
++) {
4890 const char *str
= NULL
;
4892 if (cservername
== NULL
|| arch
== NULL
) {
4893 FILL_DRIVER_STRING(mem_ctx
, string_array
[i
], str
);
4895 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
, arch
, version
, string_array
[i
], str
);
4898 if (!add_string_to_array(mem_ctx
, str
, &array
, &num_strings
)) {
4905 ADD_TO_ARRAY(mem_ctx
, const char *, NULL
,
4906 &array
, &num_strings
);
4916 /********************************************************************
4917 * fill a spoolss_DriverInfo1 struct
4918 ********************************************************************/
4920 static WERROR
fill_printer_driver_info1(TALLOC_CTX
*mem_ctx
,
4921 struct spoolss_DriverInfo1
*r
,
4922 const struct spoolss_DriverInfo8
*driver
,
4923 const char *servername
)
4925 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
4926 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
4931 /********************************************************************
4932 * fill a spoolss_DriverInfo2 struct
4933 ********************************************************************/
4935 static WERROR
fill_printer_driver_info2(TALLOC_CTX
*mem_ctx
,
4936 struct spoolss_DriverInfo2
*r
,
4937 const struct spoolss_DriverInfo8
*driver
,
4938 const char *servername
)
4941 const char *cservername
= canon_servername(servername
);
4943 r
->version
= driver
->version
;
4945 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
4946 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
4947 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
4948 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
4950 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4951 driver
->architecture
,
4953 driver
->driver_path
,
4956 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4957 driver
->architecture
,
4962 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4963 driver
->architecture
,
4965 driver
->config_file
,
4971 /********************************************************************
4972 * fill a spoolss_DriverInfo3 struct
4973 ********************************************************************/
4975 static WERROR
fill_printer_driver_info3(TALLOC_CTX
*mem_ctx
,
4976 struct spoolss_DriverInfo3
*r
,
4977 const struct spoolss_DriverInfo8
*driver
,
4978 const char *servername
)
4980 const char *cservername
= canon_servername(servername
);
4982 r
->version
= driver
->version
;
4984 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
4985 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
4986 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
4987 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
4989 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4990 driver
->architecture
,
4992 driver
->driver_path
,
4995 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4996 driver
->architecture
,
5001 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5002 driver
->architecture
,
5004 driver
->config_file
,
5007 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5008 driver
->architecture
,
5013 FILL_DRIVER_STRING(mem_ctx
,
5014 driver
->monitor_name
,
5017 FILL_DRIVER_STRING(mem_ctx
,
5018 driver
->default_datatype
,
5019 r
->default_datatype
);
5021 return string_array_from_driver_info(mem_ctx
,
5022 driver
->dependent_files
,
5023 &r
->dependent_files
,
5025 driver
->architecture
,
5029 /********************************************************************
5030 * fill a spoolss_DriverInfo4 struct
5031 ********************************************************************/
5033 static WERROR
fill_printer_driver_info4(TALLOC_CTX
*mem_ctx
,
5034 struct spoolss_DriverInfo4
*r
,
5035 const struct spoolss_DriverInfo8
*driver
,
5036 const char *servername
)
5038 const char *cservername
= canon_servername(servername
);
5041 r
->version
= driver
->version
;
5043 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5044 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5045 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5046 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5048 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5049 driver
->architecture
,
5051 driver
->driver_path
,
5054 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5055 driver
->architecture
,
5060 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5061 driver
->architecture
,
5063 driver
->config_file
,
5066 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5067 driver
->architecture
,
5072 result
= string_array_from_driver_info(mem_ctx
,
5073 driver
->dependent_files
,
5074 &r
->dependent_files
,
5076 driver
->architecture
,
5078 if (!W_ERROR_IS_OK(result
)) {
5082 FILL_DRIVER_STRING(mem_ctx
,
5083 driver
->monitor_name
,
5086 FILL_DRIVER_STRING(mem_ctx
,
5087 driver
->default_datatype
,
5088 r
->default_datatype
);
5091 result
= string_array_from_driver_info(mem_ctx
,
5092 driver
->previous_names
,
5099 /********************************************************************
5100 * fill a spoolss_DriverInfo5 struct
5101 ********************************************************************/
5103 static WERROR
fill_printer_driver_info5(TALLOC_CTX
*mem_ctx
,
5104 struct spoolss_DriverInfo5
*r
,
5105 const struct spoolss_DriverInfo8
*driver
,
5106 const char *servername
)
5108 const char *cservername
= canon_servername(servername
);
5110 r
->version
= driver
->version
;
5112 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5113 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5114 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5115 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5117 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5118 driver
->architecture
,
5120 driver
->driver_path
,
5123 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5124 driver
->architecture
,
5129 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5130 driver
->architecture
,
5132 driver
->config_file
,
5135 r
->driver_attributes
= 0;
5136 r
->config_version
= 0;
5137 r
->driver_version
= 0;
5141 /********************************************************************
5142 * fill a spoolss_DriverInfo6 struct
5143 ********************************************************************/
5145 static WERROR
fill_printer_driver_info6(TALLOC_CTX
*mem_ctx
,
5146 struct spoolss_DriverInfo6
*r
,
5147 const struct spoolss_DriverInfo8
*driver
,
5148 const char *servername
)
5150 const char *cservername
= canon_servername(servername
);
5153 r
->version
= driver
->version
;
5155 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5156 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5157 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5158 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5160 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5161 driver
->architecture
,
5163 driver
->driver_path
,
5166 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5167 driver
->architecture
,
5172 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5173 driver
->architecture
,
5175 driver
->config_file
,
5178 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5179 driver
->architecture
,
5184 FILL_DRIVER_STRING(mem_ctx
,
5185 driver
->monitor_name
,
5188 FILL_DRIVER_STRING(mem_ctx
,
5189 driver
->default_datatype
,
5190 r
->default_datatype
);
5192 result
= string_array_from_driver_info(mem_ctx
,
5193 driver
->dependent_files
,
5194 &r
->dependent_files
,
5196 driver
->architecture
,
5198 if (!W_ERROR_IS_OK(result
)) {
5202 result
= string_array_from_driver_info(mem_ctx
,
5203 driver
->previous_names
,
5206 if (!W_ERROR_IS_OK(result
)) {
5210 r
->driver_date
= driver
->driver_date
;
5211 r
->driver_version
= driver
->driver_version
;
5213 FILL_DRIVER_STRING(mem_ctx
,
5214 driver
->manufacturer_name
,
5215 r
->manufacturer_name
);
5216 FILL_DRIVER_STRING(mem_ctx
,
5217 driver
->manufacturer_url
,
5218 r
->manufacturer_url
);
5219 FILL_DRIVER_STRING(mem_ctx
,
5220 driver
->hardware_id
,
5222 FILL_DRIVER_STRING(mem_ctx
,
5229 /********************************************************************
5230 * fill a spoolss_DriverInfo8 struct
5231 ********************************************************************/
5233 static WERROR
fill_printer_driver_info8(TALLOC_CTX
*mem_ctx
,
5234 struct spoolss_DriverInfo8
*r
,
5235 const struct spoolss_DriverInfo8
*driver
,
5236 const char *servername
)
5238 const char *cservername
= canon_servername(servername
);
5241 r
->version
= driver
->version
;
5243 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5244 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5245 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5246 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5248 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5249 driver
->architecture
,
5251 driver
->driver_path
,
5254 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5255 driver
->architecture
,
5260 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5261 driver
->architecture
,
5263 driver
->config_file
,
5266 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5267 driver
->architecture
,
5272 FILL_DRIVER_STRING(mem_ctx
,
5273 driver
->monitor_name
,
5276 FILL_DRIVER_STRING(mem_ctx
,
5277 driver
->default_datatype
,
5278 r
->default_datatype
);
5280 result
= string_array_from_driver_info(mem_ctx
,
5281 driver
->dependent_files
,
5282 &r
->dependent_files
,
5284 driver
->architecture
,
5286 if (!W_ERROR_IS_OK(result
)) {
5290 result
= string_array_from_driver_info(mem_ctx
,
5291 driver
->previous_names
,
5294 if (!W_ERROR_IS_OK(result
)) {
5298 r
->driver_date
= driver
->driver_date
;
5299 r
->driver_version
= driver
->driver_version
;
5301 FILL_DRIVER_STRING(mem_ctx
,
5302 driver
->manufacturer_name
,
5303 r
->manufacturer_name
);
5304 FILL_DRIVER_STRING(mem_ctx
,
5305 driver
->manufacturer_url
,
5306 r
->manufacturer_url
);
5307 FILL_DRIVER_STRING(mem_ctx
,
5308 driver
->hardware_id
,
5310 FILL_DRIVER_STRING(mem_ctx
,
5314 FILL_DRIVER_STRING(mem_ctx
,
5315 driver
->print_processor
,
5316 r
->print_processor
);
5317 FILL_DRIVER_STRING(mem_ctx
,
5318 driver
->vendor_setup
,
5321 result
= string_array_from_driver_info(mem_ctx
,
5322 driver
->color_profiles
,
5325 if (!W_ERROR_IS_OK(result
)) {
5329 FILL_DRIVER_STRING(mem_ctx
,
5333 r
->printer_driver_attributes
= driver
->printer_driver_attributes
;
5335 result
= string_array_from_driver_info(mem_ctx
,
5336 driver
->core_driver_dependencies
,
5337 &r
->core_driver_dependencies
,
5339 if (!W_ERROR_IS_OK(result
)) {
5343 r
->min_inbox_driver_ver_date
= driver
->min_inbox_driver_ver_date
;
5344 r
->min_inbox_driver_ver_version
= driver
->min_inbox_driver_ver_version
;
5349 #if 0 /* disabled until marshalling issues are resolved - gd */
5350 /********************************************************************
5351 ********************************************************************/
5353 static WERROR
fill_spoolss_DriverFileInfo(TALLOC_CTX
*mem_ctx
,
5354 struct spoolss_DriverFileInfo
*r
,
5355 const char *cservername
,
5356 const char *file_name
,
5357 enum spoolss_DriverFileType file_type
,
5358 uint32_t file_version
)
5360 r
->file_name
= talloc_asprintf(mem_ctx
, "\\\\%s%s",
5361 cservername
, file_name
);
5362 W_ERROR_HAVE_NO_MEMORY(r
->file_name
);
5363 r
->file_type
= file_type
;
5364 r
->file_version
= file_version
;
5369 /********************************************************************
5370 ********************************************************************/
5372 static WERROR
spoolss_DriverFileInfo_from_driver(TALLOC_CTX
*mem_ctx
,
5373 const struct spoolss_DriverInfo8
*driver
,
5374 const char *cservername
,
5375 struct spoolss_DriverFileInfo
**info_p
,
5378 struct spoolss_DriverFileInfo
*info
= NULL
;
5386 if (strlen(driver
->driver_path
)) {
5387 info
= talloc_realloc(mem_ctx
, info
,
5388 struct spoolss_DriverFileInfo
,
5390 W_ERROR_HAVE_NO_MEMORY(info
);
5391 result
= fill_spoolss_DriverFileInfo(info
,
5394 driver
->driver_path
,
5395 SPOOLSS_DRIVER_FILE_TYPE_RENDERING
,
5397 W_ERROR_NOT_OK_RETURN(result
);
5401 if (strlen(driver
->config_file
)) {
5402 info
= talloc_realloc(mem_ctx
, info
,
5403 struct spoolss_DriverFileInfo
,
5405 W_ERROR_HAVE_NO_MEMORY(info
);
5406 result
= fill_spoolss_DriverFileInfo(info
,
5409 driver
->config_file
,
5410 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION
,
5412 W_ERROR_NOT_OK_RETURN(result
);
5416 if (strlen(driver
->data_file
)) {
5417 info
= talloc_realloc(mem_ctx
, info
,
5418 struct spoolss_DriverFileInfo
,
5420 W_ERROR_HAVE_NO_MEMORY(info
);
5421 result
= fill_spoolss_DriverFileInfo(info
,
5425 SPOOLSS_DRIVER_FILE_TYPE_DATA
,
5427 W_ERROR_NOT_OK_RETURN(result
);
5431 if (strlen(driver
->help_file
)) {
5432 info
= talloc_realloc(mem_ctx
, info
,
5433 struct spoolss_DriverFileInfo
,
5435 W_ERROR_HAVE_NO_MEMORY(info
);
5436 result
= fill_spoolss_DriverFileInfo(info
,
5440 SPOOLSS_DRIVER_FILE_TYPE_HELP
,
5442 W_ERROR_NOT_OK_RETURN(result
);
5446 for (i
=0; driver
->dependent_files
[i
] && driver
->dependent_files
[i
][0] != '\0'; i
++) {
5447 info
= talloc_realloc(mem_ctx
, info
,
5448 struct spoolss_DriverFileInfo
,
5450 W_ERROR_HAVE_NO_MEMORY(info
);
5451 result
= fill_spoolss_DriverFileInfo(info
,
5454 driver
->dependent_files
[i
],
5455 SPOOLSS_DRIVER_FILE_TYPE_OTHER
,
5457 W_ERROR_NOT_OK_RETURN(result
);
5467 /********************************************************************
5468 * fill a spoolss_DriverInfo101 struct
5469 ********************************************************************/
5471 static WERROR
fill_printer_driver_info101(TALLOC_CTX
*mem_ctx
,
5472 struct spoolss_DriverInfo101
*r
,
5473 const struct spoolss_DriverInfo8
*driver
,
5474 const char *servername
)
5476 const char *cservername
= canon_servername(servername
);
5479 r
->version
= driver
->version
;
5481 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5482 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5483 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5484 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5486 result
= spoolss_DriverFileInfo_from_driver(mem_ctx
, driver
,
5490 if (!W_ERROR_IS_OK(result
)) {
5494 FILL_DRIVER_STRING(mem_ctx
,
5495 driver
->monitor_name
,
5498 FILL_DRIVER_STRING(mem_ctx
,
5499 driver
->default_datatype
,
5500 r
->default_datatype
);
5502 result
= string_array_from_driver_info(mem_ctx
,
5503 driver
->previous_names
,
5506 if (!W_ERROR_IS_OK(result
)) {
5510 r
->driver_date
= driver
->driver_date
;
5511 r
->driver_version
= driver
->driver_version
;
5513 FILL_DRIVER_STRING(mem_ctx
,
5514 driver
->manufacturer_name
,
5515 r
->manufacturer_name
);
5516 FILL_DRIVER_STRING(mem_ctx
,
5517 driver
->manufacturer_url
,
5518 r
->manufacturer_url
);
5519 FILL_DRIVER_STRING(mem_ctx
,
5520 driver
->hardware_id
,
5522 FILL_DRIVER_STRING(mem_ctx
,
5529 /********************************************************************
5530 ********************************************************************/
5532 static WERROR
construct_printer_driver_info_level(TALLOC_CTX
*mem_ctx
,
5533 const struct auth_session_info
*session_info
,
5534 struct messaging_context
*msg_ctx
,
5536 union spoolss_DriverInfo
*r
,
5538 const char *servername
,
5539 const char *architecture
,
5542 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
5543 struct spoolss_DriverInfo8
*driver
;
5545 struct dcerpc_binding_handle
*b
;
5546 TALLOC_CTX
*tmp_ctx
= NULL
;
5549 return WERR_UNKNOWN_LEVEL
;
5552 tmp_ctx
= talloc_new(mem_ctx
);
5557 result
= winreg_printer_binding_handle(tmp_ctx
,
5561 if (!W_ERROR_IS_OK(result
)) {
5565 result
= winreg_get_printer(tmp_ctx
, b
,
5566 lp_const_servicename(snum
),
5569 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5570 win_errstr(result
)));
5572 if (!W_ERROR_IS_OK(result
)) {
5573 result
= WERR_INVALID_PRINTER_NAME
;
5577 result
= winreg_get_driver(tmp_ctx
, b
,
5579 pinfo2
->drivername
, version
, &driver
);
5581 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5582 win_errstr(result
)));
5584 if (!W_ERROR_IS_OK(result
)) {
5586 * Is this a W2k client ?
5590 result
= WERR_UNKNOWN_PRINTER_DRIVER
;
5594 /* Yes - try again with a WinNT driver. */
5596 result
= winreg_get_driver(tmp_ctx
, b
,
5600 DEBUG(8,("construct_printer_driver_level: status: %s\n",
5601 win_errstr(result
)));
5602 if (!W_ERROR_IS_OK(result
)) {
5603 result
= WERR_UNKNOWN_PRINTER_DRIVER
;
5608 /* these are allocated on mem_ctx and not tmp_ctx because they are
5609 * the 'return value' and need to utlive this call */
5612 result
= fill_printer_driver_info1(mem_ctx
, &r
->info1
, driver
, servername
);
5615 result
= fill_printer_driver_info2(mem_ctx
, &r
->info2
, driver
, servername
);
5618 result
= fill_printer_driver_info3(mem_ctx
, &r
->info3
, driver
, servername
);
5621 result
= fill_printer_driver_info4(mem_ctx
, &r
->info4
, driver
, servername
);
5624 result
= fill_printer_driver_info5(mem_ctx
, &r
->info5
, driver
, servername
);
5627 result
= fill_printer_driver_info6(mem_ctx
, &r
->info6
, driver
, servername
);
5630 result
= fill_printer_driver_info8(mem_ctx
, &r
->info8
, driver
, servername
);
5632 #if 0 /* disabled until marshalling issues are resolved - gd */
5634 result
= fill_printer_driver_info101(mem_ctx
, &r
->info101
, driver
, servername
);
5638 result
= WERR_UNKNOWN_LEVEL
;
5643 talloc_free(tmp_ctx
);
5647 /****************************************************************
5648 _spoolss_GetPrinterDriver2
5649 ****************************************************************/
5651 WERROR
_spoolss_GetPrinterDriver2(struct pipes_struct
*p
,
5652 struct spoolss_GetPrinterDriver2
*r
)
5654 struct printer_handle
*printer
;
5659 /* that's an [in out] buffer */
5661 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
5662 return WERR_INVALID_PARAM
;
5665 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5667 if (!(printer
= find_printer_index_by_hnd(p
, r
->in
.handle
))) {
5668 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5669 return WERR_INVALID_PRINTER_NAME
;
5673 *r
->out
.server_major_version
= 0;
5674 *r
->out
.server_minor_version
= 0;
5676 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
5680 result
= construct_printer_driver_info_level(p
->mem_ctx
,
5681 get_session_info_system(),
5683 r
->in
.level
, r
->out
.info
,
5684 snum
, printer
->servername
,
5686 r
->in
.client_major_version
);
5687 if (!W_ERROR_IS_OK(result
)) {
5688 TALLOC_FREE(r
->out
.info
);
5692 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_DriverInfo
,
5693 r
->out
.info
, r
->in
.level
);
5694 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
5696 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
5700 /****************************************************************
5701 _spoolss_StartPagePrinter
5702 ****************************************************************/
5704 WERROR
_spoolss_StartPagePrinter(struct pipes_struct
*p
,
5705 struct spoolss_StartPagePrinter
*r
)
5707 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5710 DEBUG(3,("_spoolss_StartPagePrinter: "
5711 "Error in startpageprinter printer handle\n"));
5715 Printer
->page_started
= true;
5719 /****************************************************************
5720 _spoolss_EndPagePrinter
5721 ****************************************************************/
5723 WERROR
_spoolss_EndPagePrinter(struct pipes_struct
*p
,
5724 struct spoolss_EndPagePrinter
*r
)
5728 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5731 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5732 OUR_HANDLE(r
->in
.handle
)));
5736 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
))
5739 Printer
->page_started
= false;
5740 print_job_endpage(p
->msg_ctx
, snum
, Printer
->jobid
);
5745 /****************************************************************
5746 _spoolss_StartDocPrinter
5747 ****************************************************************/
5749 WERROR
_spoolss_StartDocPrinter(struct pipes_struct
*p
,
5750 struct spoolss_StartDocPrinter
*r
)
5752 struct spoolss_DocumentInfo1
*info_1
;
5754 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5760 DEBUG(2,("_spoolss_StartDocPrinter: "
5761 "Invalid handle (%s:%u:%u)\n",
5762 OUR_HANDLE(r
->in
.handle
)));
5766 if (Printer
->jobid
) {
5767 DEBUG(2, ("_spoolss_StartDocPrinter: "
5768 "StartDocPrinter called twice! "
5769 "(existing jobid = %d)\n", Printer
->jobid
));
5770 return WERR_INVALID_HANDLE
;
5773 if (r
->in
.level
!= 1) {
5774 return WERR_UNKNOWN_LEVEL
;
5777 info_1
= r
->in
.info
.info1
;
5780 * a nice thing with NT is it doesn't listen to what you tell it.
5781 * when asked to send _only_ RAW datas, it tries to send datas
5784 * So I add checks like in NT Server ...
5787 if (info_1
->datatype
) {
5788 if (strcmp(info_1
->datatype
, "RAW") != 0) {
5790 return WERR_INVALID_DATATYPE
;
5794 /* get the share number of the printer */
5795 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
5799 rc
= get_remote_hostname(p
->remote_address
,
5805 if (strequal(rhost
,"UNKNOWN")) {
5806 rhost
= tsocket_address_inet_addr_string(p
->remote_address
,
5808 if (rhost
== NULL
) {
5813 werr
= print_job_start(p
->session_info
,
5817 info_1
->document_name
,
5818 info_1
->output_file
,
5822 /* An error occured in print_job_start() so return an appropriate
5825 if (!W_ERROR_IS_OK(werr
)) {
5829 Printer
->document_started
= true;
5830 *r
->out
.job_id
= Printer
->jobid
;
5835 /****************************************************************
5836 _spoolss_EndDocPrinter
5837 ****************************************************************/
5839 WERROR
_spoolss_EndDocPrinter(struct pipes_struct
*p
,
5840 struct spoolss_EndDocPrinter
*r
)
5842 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5847 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5848 OUR_HANDLE(r
->in
.handle
)));
5852 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
5856 Printer
->document_started
= false;
5857 status
= print_job_end(p
->msg_ctx
, snum
, Printer
->jobid
, NORMAL_CLOSE
);
5858 if (!NT_STATUS_IS_OK(status
)) {
5859 DEBUG(2, ("_spoolss_EndDocPrinter: "
5860 "print_job_end failed [%s]\n",
5861 nt_errstr(status
)));
5865 return ntstatus_to_werror(status
);
5868 /****************************************************************
5869 _spoolss_WritePrinter
5870 ****************************************************************/
5872 WERROR
_spoolss_WritePrinter(struct pipes_struct
*p
,
5873 struct spoolss_WritePrinter
*r
)
5875 ssize_t buffer_written
;
5877 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5880 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5881 OUR_HANDLE(r
->in
.handle
)));
5882 *r
->out
.num_written
= r
->in
._data_size
;
5886 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
))
5889 /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
5890 buffer_written
= print_job_write(server_event_context(),p
->msg_ctx
,
5891 snum
, Printer
->jobid
,
5892 (const char *)r
->in
.data
.data
,
5893 (size_t)r
->in
._data_size
);
5894 if (buffer_written
== (ssize_t
)-1) {
5895 *r
->out
.num_written
= 0;
5896 if (errno
== ENOSPC
)
5897 return WERR_NO_SPOOL_SPACE
;
5899 return WERR_ACCESS_DENIED
;
5902 *r
->out
.num_written
= r
->in
._data_size
;
5907 /********************************************************************
5908 * api_spoolss_getprinter
5909 * called from the spoolss dispatcher
5911 ********************************************************************/
5913 static WERROR
control_printer(struct policy_handle
*handle
, uint32_t command
,
5914 struct pipes_struct
*p
)
5916 const struct auth_session_info
*session_info
= p
->session_info
;
5918 WERROR errcode
= WERR_BADFUNC
;
5919 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, handle
);
5922 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5923 OUR_HANDLE(handle
)));
5927 if (!get_printer_snum(p
, handle
, &snum
, NULL
))
5931 case SPOOLSS_PRINTER_CONTROL_PAUSE
:
5932 errcode
= print_queue_pause(session_info
, p
->msg_ctx
, snum
);
5934 case SPOOLSS_PRINTER_CONTROL_RESUME
:
5935 case SPOOLSS_PRINTER_CONTROL_UNPAUSE
:
5936 errcode
= print_queue_resume(session_info
, p
->msg_ctx
, snum
);
5938 case SPOOLSS_PRINTER_CONTROL_PURGE
:
5939 errcode
= print_queue_purge(session_info
, p
->msg_ctx
, snum
);
5942 return WERR_UNKNOWN_LEVEL
;
5949 /****************************************************************
5950 _spoolss_AbortPrinter
5951 * From MSDN: "Deletes printer's spool file if printer is configured
5953 ****************************************************************/
5955 WERROR
_spoolss_AbortPrinter(struct pipes_struct
*p
,
5956 struct spoolss_AbortPrinter
*r
)
5958 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5960 WERROR errcode
= WERR_OK
;
5963 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5964 OUR_HANDLE(r
->in
.handle
)));
5968 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
))
5971 if (!Printer
->document_started
) {
5972 return WERR_SPL_NO_STARTDOC
;
5975 errcode
= print_job_delete(p
->session_info
,
5983 /********************************************************************
5984 * called by spoolss_api_setprinter
5985 * when updating a printer description
5986 ********************************************************************/
5988 static WERROR
update_printer_sec(struct policy_handle
*handle
,
5989 struct pipes_struct
*p
,
5990 struct sec_desc_buf
*secdesc_ctr
)
5992 struct spoolss_security_descriptor
*new_secdesc
= NULL
;
5993 struct spoolss_security_descriptor
*old_secdesc
= NULL
;
5994 const char *printer
;
5997 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, handle
);
5998 struct dcerpc_binding_handle
*b
;
5999 TALLOC_CTX
*tmp_ctx
= NULL
;
6001 if (!Printer
|| !get_printer_snum(p
, handle
, &snum
, NULL
)) {
6002 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
6003 OUR_HANDLE(handle
)));
6005 result
= WERR_BADFID
;
6009 if (secdesc_ctr
== NULL
) {
6010 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
6011 result
= WERR_INVALID_PARAM
;
6014 printer
= lp_const_servicename(snum
);
6016 /* Check the user has permissions to change the security
6017 descriptor. By experimentation with two NT machines, the user
6018 requires Full Access to the printer to change security
6021 if ( Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
6022 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
6023 result
= WERR_ACCESS_DENIED
;
6027 tmp_ctx
= talloc_new(p
->mem_ctx
);
6032 result
= winreg_printer_binding_handle(tmp_ctx
,
6033 get_session_info_system(),
6036 if (!W_ERROR_IS_OK(result
)) {
6040 /* NT seems to like setting the security descriptor even though
6041 nothing may have actually changed. */
6042 result
= winreg_get_printer_secdesc(tmp_ctx
, b
,
6045 if (!W_ERROR_IS_OK(result
)) {
6046 DEBUG(2,("update_printer_sec: winreg_get_printer_secdesc_internal() failed\n"));
6047 result
= WERR_BADFID
;
6051 if (DEBUGLEVEL
>= 10) {
6052 struct security_acl
*the_acl
;
6055 the_acl
= old_secdesc
->dacl
;
6056 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
6057 printer
, the_acl
->num_aces
));
6059 for (i
= 0; i
< the_acl
->num_aces
; i
++) {
6060 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
6061 &the_acl
->aces
[i
].trustee
),
6062 the_acl
->aces
[i
].access_mask
));
6065 the_acl
= secdesc_ctr
->sd
->dacl
;
6068 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
6069 printer
, the_acl
->num_aces
));
6071 for (i
= 0; i
< the_acl
->num_aces
; i
++) {
6072 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
6073 &the_acl
->aces
[i
].trustee
),
6074 the_acl
->aces
[i
].access_mask
));
6077 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
6081 new_secdesc
= sec_desc_merge(tmp_ctx
, secdesc_ctr
->sd
, old_secdesc
);
6082 if (new_secdesc
== NULL
) {
6083 result
= WERR_NOMEM
;
6087 if (security_descriptor_equal(new_secdesc
, old_secdesc
)) {
6092 result
= winreg_set_printer_secdesc(tmp_ctx
, b
,
6097 talloc_free(tmp_ctx
);
6101 /********************************************************************
6102 Canonicalize printer info from a client
6103 ********************************************************************/
6105 static bool check_printer_ok(TALLOC_CTX
*mem_ctx
,
6106 struct spoolss_SetPrinterInfo2
*info2
,
6109 fstring printername
;
6112 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
6113 "portname=%s drivername=%s comment=%s location=%s\n",
6114 info2
->servername
, info2
->printername
, info2
->sharename
,
6115 info2
->portname
, info2
->drivername
, info2
->comment
,
6118 /* we force some elements to "correct" values */
6119 info2
->servername
= talloc_asprintf(mem_ctx
, "\\\\%s", lp_netbios_name());
6120 if (info2
->servername
== NULL
) {
6123 info2
->sharename
= talloc_strdup(mem_ctx
, lp_const_servicename(snum
));
6124 if (info2
->sharename
== NULL
) {
6128 /* check to see if we allow printername != sharename */
6129 if (lp_force_printername(snum
)) {
6130 info2
->printername
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s",
6131 lp_netbios_name(), info2
->sharename
);
6133 /* make sure printername is in \\server\printername format */
6134 fstrcpy(printername
, info2
->printername
);
6136 if ( printername
[0] == '\\' && printername
[1] == '\\' ) {
6137 if ( (p
= strchr_m( &printername
[2], '\\' )) != NULL
)
6141 info2
->printername
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s",
6142 lp_netbios_name(), p
);
6144 if (info2
->printername
== NULL
) {
6148 info2
->attributes
|= PRINTER_ATTRIBUTE_SAMBA
;
6149 info2
->attributes
&= ~PRINTER_ATTRIBUTE_NOT_SAMBA
;
6154 /****************************************************************************
6155 ****************************************************************************/
6157 static WERROR
add_port_hook(TALLOC_CTX
*ctx
, struct security_token
*token
, const char *portname
, const char *uri
)
6159 char *cmd
= lp_addport_cmd();
6160 char *command
= NULL
;
6162 bool is_print_op
= false;
6165 return WERR_ACCESS_DENIED
;
6168 command
= talloc_asprintf(ctx
,
6169 "%s \"%s\" \"%s\"", cmd
, portname
, uri
);
6175 is_print_op
= security_token_has_privilege(token
, SEC_PRIV_PRINT_OPERATOR
);
6177 DEBUG(10,("Running [%s]\n", command
));
6179 /********* BEGIN SePrintOperatorPrivilege **********/
6184 ret
= smbrun(command
, NULL
);
6189 /********* END SePrintOperatorPrivilege **********/
6191 DEBUGADD(10,("returned [%d]\n", ret
));
6193 TALLOC_FREE(command
);
6196 return WERR_ACCESS_DENIED
;
6202 /****************************************************************************
6203 ****************************************************************************/
6205 static bool add_printer_hook(TALLOC_CTX
*ctx
, struct security_token
*token
,
6206 struct spoolss_SetPrinterInfo2
*info2
,
6207 const char *remote_machine
,
6208 struct messaging_context
*msg_ctx
)
6210 char *cmd
= lp_addprinter_cmd();
6212 char *command
= NULL
;
6216 bool is_print_op
= false;
6218 if (!remote_machine
) {
6222 command
= talloc_asprintf(ctx
,
6223 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
6224 cmd
, info2
->printername
, info2
->sharename
,
6225 info2
->portname
, info2
->drivername
,
6226 info2
->location
, info2
->comment
, remote_machine
);
6232 is_print_op
= security_token_has_privilege(token
, SEC_PRIV_PRINT_OPERATOR
);
6234 DEBUG(10,("Running [%s]\n", command
));
6236 /********* BEGIN SePrintOperatorPrivilege **********/
6241 if ( (ret
= smbrun(command
, &fd
)) == 0 ) {
6242 /* Tell everyone we updated smb.conf. */
6243 message_send_all(msg_ctx
, MSG_SMB_CONF_UPDATED
, NULL
, 0, NULL
);
6249 /********* END SePrintOperatorPrivilege **********/
6251 DEBUGADD(10,("returned [%d]\n", ret
));
6253 TALLOC_FREE(command
);
6261 /* reload our services immediately */
6263 reload_services(msg_ctx
, -1, false);
6267 /* Get lines and convert them back to dos-codepage */
6268 qlines
= fd_lines_load(fd
, &numlines
, 0, NULL
);
6269 DEBUGADD(10,("Lines returned = [%d]\n", numlines
));
6272 /* Set the portname to what the script says the portname should be. */
6273 /* but don't require anything to be return from the script exit a good error code */
6276 /* Set the portname to what the script says the portname should be. */
6277 info2
->portname
= talloc_strdup(ctx
, qlines
[0]);
6278 DEBUGADD(6,("Line[0] = [%s]\n", qlines
[0]));
6281 TALLOC_FREE(qlines
);
6285 static WERROR
update_dsspooler(TALLOC_CTX
*mem_ctx
,
6286 const struct auth_session_info
*session_info
,
6287 struct messaging_context
*msg_ctx
,
6289 struct spoolss_SetPrinterInfo2
*printer
,
6290 struct spoolss_PrinterInfo2
*old_printer
)
6292 bool force_update
= (old_printer
== NULL
);
6293 const char *dnsdomname
;
6294 const char *longname
;
6295 const char *uncname
;
6296 const char *spooling
;
6298 WERROR result
= WERR_OK
;
6299 struct dcerpc_binding_handle
*b
;
6300 TALLOC_CTX
*tmp_ctx
;
6302 tmp_ctx
= talloc_new(mem_ctx
);
6307 result
= winreg_printer_binding_handle(tmp_ctx
,
6311 if (!W_ERROR_IS_OK(result
)) {
6315 if (force_update
|| !strequal(printer
->drivername
, old_printer
->drivername
)) {
6316 push_reg_sz(tmp_ctx
, &buffer
, printer
->drivername
);
6317 winreg_set_printer_dataex(tmp_ctx
, b
,
6319 SPOOL_DSSPOOLER_KEY
,
6320 SPOOL_REG_DRIVERNAME
,
6325 if (!force_update
) {
6326 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
6327 printer
->drivername
));
6329 notify_printer_driver(server_event_context(), msg_ctx
,
6330 snum
, printer
->drivername
?
6331 printer
->drivername
: "");
6335 if (force_update
|| !strequal(printer
->comment
, old_printer
->comment
)) {
6336 push_reg_sz(tmp_ctx
, &buffer
, printer
->comment
);
6337 winreg_set_printer_dataex(tmp_ctx
, b
,
6339 SPOOL_DSSPOOLER_KEY
,
6340 SPOOL_REG_DESCRIPTION
,
6345 if (!force_update
) {
6346 notify_printer_comment(server_event_context(), msg_ctx
,
6347 snum
, printer
->comment
?
6348 printer
->comment
: "");
6352 if (force_update
|| !strequal(printer
->sharename
, old_printer
->sharename
)) {
6353 push_reg_sz(tmp_ctx
, &buffer
, printer
->sharename
);
6354 winreg_set_printer_dataex(tmp_ctx
, b
,
6356 SPOOL_DSSPOOLER_KEY
,
6357 SPOOL_REG_PRINTSHARENAME
,
6362 if (!force_update
) {
6363 notify_printer_sharename(server_event_context(),
6365 snum
, printer
->sharename
?
6366 printer
->sharename
: "");
6370 if (force_update
|| !strequal(printer
->printername
, old_printer
->printername
)) {
6373 p
= strrchr(printer
->printername
, '\\' );
6377 p
= printer
->printername
;
6380 push_reg_sz(tmp_ctx
, &buffer
, p
);
6381 winreg_set_printer_dataex(tmp_ctx
, b
,
6383 SPOOL_DSSPOOLER_KEY
,
6384 SPOOL_REG_PRINTERNAME
,
6389 if (!force_update
) {
6390 notify_printer_printername(server_event_context(),
6391 msg_ctx
, snum
, p
? p
: "");
6395 if (force_update
|| !strequal(printer
->portname
, old_printer
->portname
)) {
6396 push_reg_sz(tmp_ctx
, &buffer
, printer
->portname
);
6397 winreg_set_printer_dataex(tmp_ctx
, b
,
6399 SPOOL_DSSPOOLER_KEY
,
6405 if (!force_update
) {
6406 notify_printer_port(server_event_context(),
6407 msg_ctx
, snum
, printer
->portname
?
6408 printer
->portname
: "");
6412 if (force_update
|| !strequal(printer
->location
, old_printer
->location
)) {
6413 push_reg_sz(tmp_ctx
, &buffer
, printer
->location
);
6414 winreg_set_printer_dataex(tmp_ctx
, b
,
6416 SPOOL_DSSPOOLER_KEY
,
6422 if (!force_update
) {
6423 notify_printer_location(server_event_context(),
6426 printer
->location
: "");
6430 if (force_update
|| !strequal(printer
->sepfile
, old_printer
->sepfile
)) {
6431 push_reg_sz(tmp_ctx
, &buffer
, printer
->sepfile
);
6432 winreg_set_printer_dataex(tmp_ctx
, b
,
6434 SPOOL_DSSPOOLER_KEY
,
6435 SPOOL_REG_PRINTSEPARATORFILE
,
6440 if (!force_update
) {
6441 notify_printer_sepfile(server_event_context(),
6444 printer
->sepfile
: "");
6448 if (force_update
|| printer
->starttime
!= old_printer
->starttime
) {
6449 buffer
= data_blob_talloc(tmp_ctx
, NULL
, 4);
6450 SIVAL(buffer
.data
, 0, printer
->starttime
);
6451 winreg_set_printer_dataex(tmp_ctx
, b
,
6453 SPOOL_DSSPOOLER_KEY
,
6454 SPOOL_REG_PRINTSTARTTIME
,
6460 if (force_update
|| printer
->untiltime
!= old_printer
->untiltime
) {
6461 buffer
= data_blob_talloc(tmp_ctx
, NULL
, 4);
6462 SIVAL(buffer
.data
, 0, printer
->untiltime
);
6463 winreg_set_printer_dataex(tmp_ctx
, b
,
6465 SPOOL_DSSPOOLER_KEY
,
6466 SPOOL_REG_PRINTENDTIME
,
6472 if (force_update
|| printer
->priority
!= old_printer
->priority
) {
6473 buffer
= data_blob_talloc(tmp_ctx
, NULL
, 4);
6474 SIVAL(buffer
.data
, 0, printer
->priority
);
6475 winreg_set_printer_dataex(tmp_ctx
, b
,
6477 SPOOL_DSSPOOLER_KEY
,
6484 if (force_update
|| printer
->attributes
!= old_printer
->attributes
) {
6485 buffer
= data_blob_talloc(tmp_ctx
, NULL
, 4);
6486 SIVAL(buffer
.data
, 0, (printer
->attributes
&
6487 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS
));
6488 winreg_set_printer_dataex(tmp_ctx
, b
,
6490 SPOOL_DSSPOOLER_KEY
,
6491 SPOOL_REG_PRINTKEEPPRINTEDJOBS
,
6496 switch (printer
->attributes
& 0x3) {
6498 spooling
= SPOOL_REGVAL_PRINTWHILESPOOLING
;
6501 spooling
= SPOOL_REGVAL_PRINTAFTERSPOOLED
;
6504 spooling
= SPOOL_REGVAL_PRINTDIRECT
;
6507 spooling
= "unknown";
6509 push_reg_sz(tmp_ctx
, &buffer
, spooling
);
6510 winreg_set_printer_dataex(tmp_ctx
, b
,
6512 SPOOL_DSSPOOLER_KEY
,
6513 SPOOL_REG_PRINTSPOOLING
,
6519 push_reg_sz(tmp_ctx
, &buffer
, lp_netbios_name());
6520 winreg_set_printer_dataex(tmp_ctx
, b
,
6522 SPOOL_DSSPOOLER_KEY
,
6523 SPOOL_REG_SHORTSERVERNAME
,
6528 dnsdomname
= get_mydnsfullname();
6529 if (dnsdomname
!= NULL
&& dnsdomname
[0] != '\0') {
6530 longname
= talloc_strdup(tmp_ctx
, dnsdomname
);
6532 longname
= talloc_strdup(tmp_ctx
, lp_netbios_name());
6534 if (longname
== NULL
) {
6535 result
= WERR_NOMEM
;
6539 push_reg_sz(tmp_ctx
, &buffer
, longname
);
6540 winreg_set_printer_dataex(tmp_ctx
, b
,
6542 SPOOL_DSSPOOLER_KEY
,
6543 SPOOL_REG_SERVERNAME
,
6548 uncname
= talloc_asprintf(tmp_ctx
, "\\\\%s\\%s",
6549 lp_netbios_name(), printer
->sharename
);
6550 push_reg_sz(tmp_ctx
, &buffer
, uncname
);
6551 winreg_set_printer_dataex(tmp_ctx
, b
,
6553 SPOOL_DSSPOOLER_KEY
,
6560 talloc_free(tmp_ctx
);
6564 /********************************************************************
6565 * Called by spoolss_api_setprinter
6566 * when updating a printer description.
6567 ********************************************************************/
6569 static WERROR
update_printer(struct pipes_struct
*p
,
6570 struct policy_handle
*handle
,
6571 struct spoolss_SetPrinterInfoCtr
*info_ctr
,
6572 struct spoolss_DeviceMode
*devmode
)
6574 uint32_t printer_mask
= SPOOLSS_PRINTER_INFO_ALL
;
6575 struct spoolss_SetPrinterInfo2
*printer
= info_ctr
->info
.info2
;
6576 struct spoolss_PrinterInfo2
*old_printer
;
6577 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, handle
);
6579 WERROR result
= WERR_OK
;
6580 TALLOC_CTX
*tmp_ctx
;
6581 struct dcerpc_binding_handle
*b
;
6583 DEBUG(8,("update_printer\n"));
6585 tmp_ctx
= talloc_new(p
->mem_ctx
);
6586 if (tmp_ctx
== NULL
) {
6591 result
= WERR_BADFID
;
6595 if (!get_printer_snum(p
, handle
, &snum
, NULL
)) {
6596 result
= WERR_BADFID
;
6600 result
= winreg_printer_binding_handle(tmp_ctx
,
6601 get_session_info_system(),
6604 if (!W_ERROR_IS_OK(result
)) {
6608 result
= winreg_get_printer(tmp_ctx
, b
,
6609 lp_const_servicename(snum
),
6611 if (!W_ERROR_IS_OK(result
)) {
6612 result
= WERR_BADFID
;
6616 /* Do sanity check on the requested changes for Samba */
6617 if (!check_printer_ok(tmp_ctx
, printer
, snum
)) {
6618 result
= WERR_INVALID_PARAM
;
6622 /* FIXME!!! If the driver has changed we really should verify that
6623 it is installed before doing much else --jerry */
6625 /* Check calling user has permission to update printer description */
6626 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
6627 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6628 result
= WERR_ACCESS_DENIED
;
6632 /* Call addprinter hook */
6633 /* Check changes to see if this is really needed */
6635 if (*lp_addprinter_cmd() &&
6636 (!strequal(printer
->drivername
, old_printer
->drivername
) ||
6637 !strequal(printer
->comment
, old_printer
->comment
) ||
6638 !strequal(printer
->portname
, old_printer
->portname
) ||
6639 !strequal(printer
->location
, old_printer
->location
)) )
6643 raddr
= tsocket_address_inet_addr_string(p
->remote_address
,
6645 if (raddr
== NULL
) {
6649 /* add_printer_hook() will call reload_services() */
6650 if (!add_printer_hook(tmp_ctx
, p
->session_info
->security_token
,
6653 result
= WERR_ACCESS_DENIED
;
6658 update_dsspooler(tmp_ctx
,
6659 get_session_info_system(),
6665 printer_mask
&= ~SPOOLSS_PRINTER_INFO_SECDESC
;
6667 if (devmode
== NULL
) {
6668 printer_mask
&= ~SPOOLSS_PRINTER_INFO_DEVMODE
;
6670 result
= winreg_update_printer(tmp_ctx
, b
,
6678 talloc_free(tmp_ctx
);
6683 /****************************************************************************
6684 ****************************************************************************/
6685 static WERROR
publish_or_unpublish_printer(struct pipes_struct
*p
,
6686 struct policy_handle
*handle
,
6687 struct spoolss_SetPrinterInfo7
*info7
)
6690 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
6693 struct printer_handle
*Printer
;
6695 if ( lp_security() != SEC_ADS
) {
6696 return WERR_UNKNOWN_LEVEL
;
6699 Printer
= find_printer_index_by_hnd(p
, handle
);
6701 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7
->action
));
6706 if (!get_printer_snum(p
, handle
, &snum
, NULL
))
6709 result
= winreg_get_printer_internal(p
->mem_ctx
,
6710 get_session_info_system(),
6712 lp_servicename(snum
),
6714 if (!W_ERROR_IS_OK(result
)) {
6718 nt_printer_publish(pinfo2
,
6719 get_session_info_system(),
6724 TALLOC_FREE(pinfo2
);
6727 return WERR_UNKNOWN_LEVEL
;
6731 /********************************************************************
6732 ********************************************************************/
6734 static WERROR
update_printer_devmode(struct pipes_struct
*p
,
6735 struct policy_handle
*handle
,
6736 struct spoolss_DeviceMode
*devmode
)
6739 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, handle
);
6740 uint32_t info2_mask
= SPOOLSS_PRINTER_INFO_DEVMODE
;
6742 DEBUG(8,("update_printer_devmode\n"));
6748 if (!get_printer_snum(p
, handle
, &snum
, NULL
)) {
6752 /* Check calling user has permission to update printer description */
6753 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
6754 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6755 return WERR_ACCESS_DENIED
;
6758 return winreg_update_printer_internal(p
->mem_ctx
,
6759 get_session_info_system(),
6761 lp_const_servicename(snum
),
6769 /****************************************************************
6771 ****************************************************************/
6773 WERROR
_spoolss_SetPrinter(struct pipes_struct
*p
,
6774 struct spoolss_SetPrinter
*r
)
6778 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
6781 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6782 OUR_HANDLE(r
->in
.handle
)));
6786 /* check the level */
6787 switch (r
->in
.info_ctr
->level
) {
6789 return control_printer(r
->in
.handle
, r
->in
.command
, p
);
6791 result
= update_printer(p
, r
->in
.handle
,
6793 r
->in
.devmode_ctr
->devmode
);
6794 if (!W_ERROR_IS_OK(result
))
6796 if (r
->in
.secdesc_ctr
->sd
)
6797 result
= update_printer_sec(r
->in
.handle
, p
,
6801 return update_printer_sec(r
->in
.handle
, p
,
6804 return publish_or_unpublish_printer(p
, r
->in
.handle
,
6805 r
->in
.info_ctr
->info
.info7
);
6807 return update_printer_devmode(p
, r
->in
.handle
,
6808 r
->in
.devmode_ctr
->devmode
);
6810 return WERR_UNKNOWN_LEVEL
;
6814 /****************************************************************
6815 _spoolss_FindClosePrinterNotify
6816 ****************************************************************/
6818 WERROR
_spoolss_FindClosePrinterNotify(struct pipes_struct
*p
,
6819 struct spoolss_FindClosePrinterNotify
*r
)
6821 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
6824 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6825 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r
->in
.handle
)));
6829 if (Printer
->notify
.cli_chan
!= NULL
&&
6830 Printer
->notify
.cli_chan
->active_connections
> 0) {
6833 if (Printer
->printer_type
== SPLHND_PRINTER
) {
6834 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
6839 srv_spoolss_replycloseprinter(snum
, Printer
);
6842 Printer
->notify
.flags
=0;
6843 Printer
->notify
.options
=0;
6844 Printer
->notify
.localmachine
[0]='\0';
6845 Printer
->notify
.printerlocal
=0;
6846 TALLOC_FREE(Printer
->notify
.option
);
6851 /****************************************************************
6853 ****************************************************************/
6855 WERROR
_spoolss_AddJob(struct pipes_struct
*p
,
6856 struct spoolss_AddJob
*r
)
6858 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
6859 return WERR_INVALID_PARAM
;
6862 /* this is what a NT server returns for AddJob. AddJob must fail on
6863 * non-local printers */
6865 if (r
->in
.level
!= 1) {
6866 return WERR_UNKNOWN_LEVEL
;
6869 return WERR_INVALID_PARAM
;
6872 /****************************************************************************
6874 ****************************************************************************/
6876 static WERROR
fill_job_info1(TALLOC_CTX
*mem_ctx
,
6877 struct spoolss_JobInfo1
*r
,
6878 const print_queue_struct
*queue
,
6879 int position
, int snum
,
6880 struct spoolss_PrinterInfo2
*pinfo2
)
6884 t
= gmtime(&queue
->time
);
6886 r
->job_id
= queue
->job
;
6888 r
->printer_name
= talloc_strdup(mem_ctx
, lp_servicename(snum
));
6889 W_ERROR_HAVE_NO_MEMORY(r
->printer_name
);
6890 r
->server_name
= talloc_strdup(mem_ctx
, pinfo2
->servername
);
6891 W_ERROR_HAVE_NO_MEMORY(r
->server_name
);
6892 r
->user_name
= talloc_strdup(mem_ctx
, queue
->fs_user
);
6893 W_ERROR_HAVE_NO_MEMORY(r
->user_name
);
6894 r
->document_name
= talloc_strdup(mem_ctx
, queue
->fs_file
);
6895 W_ERROR_HAVE_NO_MEMORY(r
->document_name
);
6896 r
->data_type
= talloc_strdup(mem_ctx
, "RAW");
6897 W_ERROR_HAVE_NO_MEMORY(r
->data_type
);
6898 r
->text_status
= talloc_strdup(mem_ctx
, "");
6899 W_ERROR_HAVE_NO_MEMORY(r
->text_status
);
6901 r
->status
= nt_printj_status(queue
->status
);
6902 r
->priority
= queue
->priority
;
6903 r
->position
= position
;
6904 r
->total_pages
= queue
->page_count
;
6905 r
->pages_printed
= 0; /* ??? */
6907 init_systemtime(&r
->submitted
, t
);
6912 /****************************************************************************
6914 ****************************************************************************/
6916 static WERROR
fill_job_info2(TALLOC_CTX
*mem_ctx
,
6917 struct spoolss_JobInfo2
*r
,
6918 const print_queue_struct
*queue
,
6919 int position
, int snum
,
6920 struct spoolss_PrinterInfo2
*pinfo2
,
6921 struct spoolss_DeviceMode
*devmode
)
6925 t
= gmtime(&queue
->time
);
6927 r
->job_id
= queue
->job
;
6929 r
->printer_name
= talloc_strdup(mem_ctx
, lp_servicename(snum
));
6930 W_ERROR_HAVE_NO_MEMORY(r
->printer_name
);
6931 r
->server_name
= talloc_strdup(mem_ctx
, pinfo2
->servername
);
6932 W_ERROR_HAVE_NO_MEMORY(r
->server_name
);
6933 r
->user_name
= talloc_strdup(mem_ctx
, queue
->fs_user
);
6934 W_ERROR_HAVE_NO_MEMORY(r
->user_name
);
6935 r
->document_name
= talloc_strdup(mem_ctx
, queue
->fs_file
);
6936 W_ERROR_HAVE_NO_MEMORY(r
->document_name
);
6937 r
->notify_name
= talloc_strdup(mem_ctx
, queue
->fs_user
);
6938 W_ERROR_HAVE_NO_MEMORY(r
->notify_name
);
6939 r
->data_type
= talloc_strdup(mem_ctx
, "RAW");
6940 W_ERROR_HAVE_NO_MEMORY(r
->data_type
);
6941 r
->print_processor
= talloc_strdup(mem_ctx
, "winprint");
6942 W_ERROR_HAVE_NO_MEMORY(r
->print_processor
);
6943 r
->parameters
= talloc_strdup(mem_ctx
, "");
6944 W_ERROR_HAVE_NO_MEMORY(r
->parameters
);
6945 r
->driver_name
= talloc_strdup(mem_ctx
, pinfo2
->drivername
);
6946 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
6948 r
->devmode
= devmode
;
6950 r
->text_status
= talloc_strdup(mem_ctx
, "");
6951 W_ERROR_HAVE_NO_MEMORY(r
->text_status
);
6955 r
->status
= nt_printj_status(queue
->status
);
6956 r
->priority
= queue
->priority
;
6957 r
->position
= position
;
6960 r
->total_pages
= queue
->page_count
;
6961 r
->size
= queue
->size
;
6962 init_systemtime(&r
->submitted
, t
);
6964 r
->pages_printed
= 0; /* ??? */
6969 /****************************************************************************
6971 ****************************************************************************/
6973 static WERROR
fill_job_info3(TALLOC_CTX
*mem_ctx
,
6974 struct spoolss_JobInfo3
*r
,
6975 const print_queue_struct
*queue
,
6976 const print_queue_struct
*next_queue
,
6977 int position
, int snum
,
6978 struct spoolss_PrinterInfo2
*pinfo2
)
6980 r
->job_id
= queue
->job
;
6983 r
->next_job_id
= next_queue
->job
;
6990 /****************************************************************************
6991 Enumjobs at level 1.
6992 ****************************************************************************/
6994 static WERROR
enumjobs_level1(TALLOC_CTX
*mem_ctx
,
6995 const print_queue_struct
*queue
,
6996 uint32_t num_queues
, int snum
,
6997 struct spoolss_PrinterInfo2
*pinfo2
,
6998 union spoolss_JobInfo
**info_p
,
7001 union spoolss_JobInfo
*info
;
7003 WERROR result
= WERR_OK
;
7005 info
= talloc_array(mem_ctx
, union spoolss_JobInfo
, num_queues
);
7006 W_ERROR_HAVE_NO_MEMORY(info
);
7008 *count
= num_queues
;
7010 for (i
=0; i
<*count
; i
++) {
7011 result
= fill_job_info1(info
,
7017 if (!W_ERROR_IS_OK(result
)) {
7023 if (!W_ERROR_IS_OK(result
)) {
7034 /****************************************************************************
7035 Enumjobs at level 2.
7036 ****************************************************************************/
7038 static WERROR
enumjobs_level2(TALLOC_CTX
*mem_ctx
,
7039 const print_queue_struct
*queue
,
7040 uint32_t num_queues
, int snum
,
7041 struct spoolss_PrinterInfo2
*pinfo2
,
7042 union spoolss_JobInfo
**info_p
,
7045 union spoolss_JobInfo
*info
;
7047 WERROR result
= WERR_OK
;
7049 info
= talloc_array(mem_ctx
, union spoolss_JobInfo
, num_queues
);
7050 W_ERROR_HAVE_NO_MEMORY(info
);
7052 *count
= num_queues
;
7054 for (i
=0; i
<*count
; i
++) {
7055 struct spoolss_DeviceMode
*devmode
;
7057 result
= spoolss_create_default_devmode(info
,
7058 pinfo2
->printername
,
7060 if (!W_ERROR_IS_OK(result
)) {
7061 DEBUG(3, ("Can't proceed w/o a devmode!"));
7065 result
= fill_job_info2(info
,
7072 if (!W_ERROR_IS_OK(result
)) {
7078 if (!W_ERROR_IS_OK(result
)) {
7089 /****************************************************************************
7090 Enumjobs at level 3.
7091 ****************************************************************************/
7093 static WERROR
enumjobs_level3(TALLOC_CTX
*mem_ctx
,
7094 const print_queue_struct
*queue
,
7095 uint32_t num_queues
, int snum
,
7096 struct spoolss_PrinterInfo2
*pinfo2
,
7097 union spoolss_JobInfo
**info_p
,
7100 union spoolss_JobInfo
*info
;
7102 WERROR result
= WERR_OK
;
7104 info
= talloc_array(mem_ctx
, union spoolss_JobInfo
, num_queues
);
7105 W_ERROR_HAVE_NO_MEMORY(info
);
7107 *count
= num_queues
;
7109 for (i
=0; i
<*count
; i
++) {
7110 const print_queue_struct
*next_queue
= NULL
;
7113 next_queue
= &queue
[i
+1];
7116 result
= fill_job_info3(info
,
7123 if (!W_ERROR_IS_OK(result
)) {
7129 if (!W_ERROR_IS_OK(result
)) {
7140 /****************************************************************
7142 ****************************************************************/
7144 WERROR
_spoolss_EnumJobs(struct pipes_struct
*p
,
7145 struct spoolss_EnumJobs
*r
)
7148 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
7150 print_status_struct prt_status
;
7151 print_queue_struct
*queue
= NULL
;
7154 /* that's an [in out] buffer */
7156 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
7157 return WERR_INVALID_PARAM
;
7160 DEBUG(4,("_spoolss_EnumJobs\n"));
7164 *r
->out
.info
= NULL
;
7166 /* lookup the printer snum and tdb entry */
7168 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
7172 result
= winreg_get_printer_internal(p
->mem_ctx
,
7173 get_session_info_system(),
7175 lp_const_servicename(snum
),
7177 if (!W_ERROR_IS_OK(result
)) {
7181 count
= print_queue_status(p
->msg_ctx
, snum
, &queue
, &prt_status
);
7182 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
7183 count
, prt_status
.status
, prt_status
.message
));
7187 TALLOC_FREE(pinfo2
);
7191 switch (r
->in
.level
) {
7193 result
= enumjobs_level1(p
->mem_ctx
, queue
, count
, snum
,
7194 pinfo2
, r
->out
.info
, r
->out
.count
);
7197 result
= enumjobs_level2(p
->mem_ctx
, queue
, count
, snum
,
7198 pinfo2
, r
->out
.info
, r
->out
.count
);
7201 result
= enumjobs_level3(p
->mem_ctx
, queue
, count
, snum
,
7202 pinfo2
, r
->out
.info
, r
->out
.count
);
7205 result
= WERR_UNKNOWN_LEVEL
;
7210 TALLOC_FREE(pinfo2
);
7212 if (!W_ERROR_IS_OK(result
)) {
7216 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
7218 *r
->out
.info
, r
->in
.level
,
7220 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
7221 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
7223 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
7226 /****************************************************************
7227 _spoolss_ScheduleJob
7228 ****************************************************************/
7230 WERROR
_spoolss_ScheduleJob(struct pipes_struct
*p
,
7231 struct spoolss_ScheduleJob
*r
)
7236 /****************************************************************
7237 ****************************************************************/
7239 static WERROR
spoolss_setjob_1(TALLOC_CTX
*mem_ctx
,
7240 struct messaging_context
*msg_ctx
,
7241 const char *printer_name
,
7243 struct spoolss_SetJobInfo1
*r
)
7247 if (!print_job_get_name(mem_ctx
, printer_name
, job_id
, &old_doc_name
)) {
7251 if (strequal(old_doc_name
, r
->document_name
)) {
7255 if (!print_job_set_name(server_event_context(), msg_ctx
,
7256 printer_name
, job_id
, r
->document_name
)) {
7263 /****************************************************************
7265 ****************************************************************/
7267 WERROR
_spoolss_SetJob(struct pipes_struct
*p
,
7268 struct spoolss_SetJob
*r
)
7270 const struct auth_session_info
*session_info
= p
->session_info
;
7272 WERROR errcode
= WERR_BADFUNC
;
7274 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
7278 if (!print_job_exists(lp_const_servicename(snum
), r
->in
.job_id
)) {
7279 return WERR_INVALID_PRINTER_NAME
;
7282 switch (r
->in
.command
) {
7283 case SPOOLSS_JOB_CONTROL_CANCEL
:
7284 case SPOOLSS_JOB_CONTROL_DELETE
:
7285 errcode
= print_job_delete(session_info
, p
->msg_ctx
,
7286 snum
, r
->in
.job_id
);
7287 if (W_ERROR_EQUAL(errcode
, WERR_PRINTER_HAS_JOBS_QUEUED
)) {
7291 case SPOOLSS_JOB_CONTROL_PAUSE
:
7292 if (print_job_pause(session_info
, p
->msg_ctx
,
7293 snum
, r
->in
.job_id
, &errcode
)) {
7297 case SPOOLSS_JOB_CONTROL_RESTART
:
7298 case SPOOLSS_JOB_CONTROL_RESUME
:
7299 if (print_job_resume(session_info
, p
->msg_ctx
,
7300 snum
, r
->in
.job_id
, &errcode
)) {
7308 return WERR_UNKNOWN_LEVEL
;
7311 if (!W_ERROR_IS_OK(errcode
)) {
7315 if (r
->in
.ctr
== NULL
) {
7319 switch (r
->in
.ctr
->level
) {
7321 errcode
= spoolss_setjob_1(p
->mem_ctx
, p
->msg_ctx
,
7322 lp_const_servicename(snum
),
7324 r
->in
.ctr
->info
.info1
);
7330 return WERR_UNKNOWN_LEVEL
;
7336 /****************************************************************************
7337 Enumerates all printer drivers by level and architecture.
7338 ****************************************************************************/
7340 static WERROR
enumprinterdrivers_level_by_architecture(TALLOC_CTX
*mem_ctx
,
7341 const struct auth_session_info
*session_info
,
7342 struct messaging_context
*msg_ctx
,
7343 const char *servername
,
7344 const char *architecture
,
7346 union spoolss_DriverInfo
**info_p
,
7351 struct spoolss_DriverInfo8
*driver
;
7352 union spoolss_DriverInfo
*info
= NULL
;
7354 WERROR result
= WERR_OK
;
7355 uint32_t num_drivers
;
7356 const char **drivers
;
7357 struct dcerpc_binding_handle
*b
;
7358 TALLOC_CTX
*tmp_ctx
= NULL
;
7363 tmp_ctx
= talloc_new(mem_ctx
);
7368 result
= winreg_printer_binding_handle(tmp_ctx
,
7372 if (!W_ERROR_IS_OK(result
)) {
7376 for (version
=0; version
<DRIVER_MAX_VERSION
; version
++) {
7377 result
= winreg_get_driver_list(tmp_ctx
, b
,
7378 architecture
, version
,
7379 &num_drivers
, &drivers
);
7380 if (!W_ERROR_IS_OK(result
)) {
7383 DEBUG(4, ("we have:[%d] drivers in environment"
7384 " [%s] and version [%d]\n",
7385 num_drivers
, architecture
, version
));
7387 if (num_drivers
!= 0) {
7388 info
= talloc_realloc(tmp_ctx
, info
,
7389 union spoolss_DriverInfo
,
7390 count
+ num_drivers
);
7392 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
7393 "failed to enlarge driver info buffer!\n"));
7394 result
= WERR_NOMEM
;
7399 for (i
= 0; i
< num_drivers
; i
++) {
7400 DEBUG(5, ("\tdriver: [%s]\n", drivers
[i
]));
7402 result
= winreg_get_driver(tmp_ctx
, b
,
7403 architecture
, drivers
[i
],
7405 if (!W_ERROR_IS_OK(result
)) {
7411 result
= fill_printer_driver_info1(info
, &info
[count
+i
].info1
,
7412 driver
, servername
);
7415 result
= fill_printer_driver_info2(info
, &info
[count
+i
].info2
,
7416 driver
, servername
);
7419 result
= fill_printer_driver_info3(info
, &info
[count
+i
].info3
,
7420 driver
, servername
);
7423 result
= fill_printer_driver_info4(info
, &info
[count
+i
].info4
,
7424 driver
, servername
);
7427 result
= fill_printer_driver_info5(info
, &info
[count
+i
].info5
,
7428 driver
, servername
);
7431 result
= fill_printer_driver_info6(info
, &info
[count
+i
].info6
,
7432 driver
, servername
);
7435 result
= fill_printer_driver_info8(info
, &info
[count
+i
].info8
,
7436 driver
, servername
);
7439 result
= WERR_UNKNOWN_LEVEL
;
7443 TALLOC_FREE(driver
);
7445 if (!W_ERROR_IS_OK(result
)) {
7450 count
+= num_drivers
;
7451 TALLOC_FREE(drivers
);
7455 if (W_ERROR_IS_OK(result
)) {
7456 *info_p
= talloc_move(mem_ctx
, &info
);
7460 talloc_free(tmp_ctx
);
7464 /****************************************************************************
7465 Enumerates all printer drivers by level.
7466 ****************************************************************************/
7468 static WERROR
enumprinterdrivers_level(TALLOC_CTX
*mem_ctx
,
7469 const struct auth_session_info
*session_info
,
7470 struct messaging_context
*msg_ctx
,
7471 const char *servername
,
7472 const char *architecture
,
7474 union spoolss_DriverInfo
**info_p
,
7478 WERROR result
= WERR_OK
;
7480 if (strequal(architecture
, SPOOLSS_ARCHITECTURE_ALL
)) {
7482 for (a
=0; archi_table
[a
].long_archi
!= NULL
; a
++) {
7484 union spoolss_DriverInfo
*info
= NULL
;
7487 result
= enumprinterdrivers_level_by_architecture(mem_ctx
,
7491 archi_table
[a
].long_archi
,
7495 if (!W_ERROR_IS_OK(result
)) {
7499 for (i
=0; i
< count
; i
++) {
7500 ADD_TO_ARRAY(mem_ctx
, union spoolss_DriverInfo
,
7501 info
[i
], info_p
, count_p
);
7508 return enumprinterdrivers_level_by_architecture(mem_ctx
,
7518 /****************************************************************
7519 _spoolss_EnumPrinterDrivers
7520 ****************************************************************/
7522 WERROR
_spoolss_EnumPrinterDrivers(struct pipes_struct
*p
,
7523 struct spoolss_EnumPrinterDrivers
*r
)
7525 const char *cservername
;
7528 /* that's an [in out] buffer */
7530 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
7531 return WERR_INVALID_PARAM
;
7534 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
7538 *r
->out
.info
= NULL
;
7540 cservername
= canon_servername(r
->in
.server
);
7542 if (!is_myname_or_ipaddr(cservername
)) {
7543 return WERR_UNKNOWN_PRINTER_DRIVER
;
7546 result
= enumprinterdrivers_level(p
->mem_ctx
,
7547 get_session_info_system(),
7554 if (!W_ERROR_IS_OK(result
)) {
7558 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
7559 spoolss_EnumPrinterDrivers
,
7560 *r
->out
.info
, r
->in
.level
,
7562 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
7563 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
7565 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
7568 /****************************************************************
7570 ****************************************************************/
7572 WERROR
_spoolss_EnumForms(struct pipes_struct
*p
,
7573 struct spoolss_EnumForms
*r
)
7579 *r
->out
.info
= NULL
;
7581 /* that's an [in out] buffer */
7583 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0) ) {
7584 return WERR_INVALID_PARAM
;
7587 DEBUG(4,("_spoolss_EnumForms\n"));
7588 DEBUGADD(5,("Offered buffer size [%d]\n", r
->in
.offered
));
7589 DEBUGADD(5,("Info level [%d]\n", r
->in
.level
));
7591 switch (r
->in
.level
) {
7593 result
= winreg_printer_enumforms1_internal(p
->mem_ctx
,
7594 get_session_info_system(),
7600 result
= WERR_UNKNOWN_LEVEL
;
7604 if (!W_ERROR_IS_OK(result
)) {
7608 if (*r
->out
.count
== 0) {
7609 return WERR_NO_MORE_ITEMS
;
7612 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
7614 *r
->out
.info
, r
->in
.level
,
7616 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
7617 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
7619 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
7622 /****************************************************************
7624 ****************************************************************/
7626 WERROR
_spoolss_GetForm(struct pipes_struct
*p
,
7627 struct spoolss_GetForm
*r
)
7631 /* that's an [in out] buffer */
7633 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
7634 return WERR_INVALID_PARAM
;
7637 DEBUG(4,("_spoolss_GetForm\n"));
7638 DEBUGADD(5,("Offered buffer size [%d]\n", r
->in
.offered
));
7639 DEBUGADD(5,("Info level [%d]\n", r
->in
.level
));
7641 switch (r
->in
.level
) {
7643 result
= winreg_printer_getform1_internal(p
->mem_ctx
,
7644 get_session_info_system(),
7647 &r
->out
.info
->info1
);
7650 result
= WERR_UNKNOWN_LEVEL
;
7654 if (!W_ERROR_IS_OK(result
)) {
7655 TALLOC_FREE(r
->out
.info
);
7659 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_FormInfo
,
7660 r
->out
.info
, r
->in
.level
);
7661 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
7663 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
7666 /****************************************************************************
7667 ****************************************************************************/
7669 static WERROR
fill_port_1(TALLOC_CTX
*mem_ctx
,
7670 struct spoolss_PortInfo1
*r
,
7673 r
->port_name
= talloc_strdup(mem_ctx
, name
);
7674 W_ERROR_HAVE_NO_MEMORY(r
->port_name
);
7679 /****************************************************************************
7680 TODO: This probably needs distinguish between TCP/IP and Local ports
7682 ****************************************************************************/
7684 static WERROR
fill_port_2(TALLOC_CTX
*mem_ctx
,
7685 struct spoolss_PortInfo2
*r
,
7688 r
->port_name
= talloc_strdup(mem_ctx
, name
);
7689 W_ERROR_HAVE_NO_MEMORY(r
->port_name
);
7691 r
->monitor_name
= talloc_strdup(mem_ctx
, "Local Monitor");
7692 W_ERROR_HAVE_NO_MEMORY(r
->monitor_name
);
7694 r
->description
= talloc_strdup(mem_ctx
, SPL_LOCAL_PORT
);
7695 W_ERROR_HAVE_NO_MEMORY(r
->description
);
7697 r
->port_type
= SPOOLSS_PORT_TYPE_WRITE
;
7704 /****************************************************************************
7705 wrapper around the enumer ports command
7706 ****************************************************************************/
7708 static WERROR
enumports_hook(TALLOC_CTX
*ctx
, int *count
, char ***lines
)
7710 char *cmd
= lp_enumports_cmd();
7711 char **qlines
= NULL
;
7712 char *command
= NULL
;
7720 /* if no hook then just fill in the default port */
7723 if (!(qlines
= talloc_array( NULL
, char*, 2 ))) {
7726 if (!(qlines
[0] = talloc_strdup(qlines
, SAMBA_PRINTER_PORT_NAME
))) {
7727 TALLOC_FREE(qlines
);
7734 /* we have a valid enumport command */
7736 command
= talloc_asprintf(ctx
, "%s \"%d\"", cmd
, 1);
7741 DEBUG(10,("Running [%s]\n", command
));
7742 ret
= smbrun(command
, &fd
);
7743 DEBUG(10,("Returned [%d]\n", ret
));
7744 TALLOC_FREE(command
);
7749 return WERR_ACCESS_DENIED
;
7753 qlines
= fd_lines_load(fd
, &numlines
, 0, NULL
);
7754 DEBUGADD(10,("Lines returned = [%d]\n", numlines
));
7764 /****************************************************************************
7766 ****************************************************************************/
7768 static WERROR
enumports_level_1(TALLOC_CTX
*mem_ctx
,
7769 union spoolss_PortInfo
**info_p
,
7772 union spoolss_PortInfo
*info
= NULL
;
7774 WERROR result
= WERR_OK
;
7775 char **qlines
= NULL
;
7778 result
= enumports_hook(talloc_tos(), &numlines
, &qlines
);
7779 if (!W_ERROR_IS_OK(result
)) {
7784 info
= talloc_array(mem_ctx
, union spoolss_PortInfo
, numlines
);
7786 DEBUG(10,("Returning WERR_NOMEM\n"));
7787 result
= WERR_NOMEM
;
7791 for (i
=0; i
<numlines
; i
++) {
7792 DEBUG(6,("Filling port number [%d] with port [%s]\n", i
, qlines
[i
]));
7793 result
= fill_port_1(info
, &info
[i
].info1
, qlines
[i
]);
7794 if (!W_ERROR_IS_OK(result
)) {
7799 TALLOC_FREE(qlines
);
7802 if (!W_ERROR_IS_OK(result
)) {
7804 TALLOC_FREE(qlines
);
7816 /****************************************************************************
7818 ****************************************************************************/
7820 static WERROR
enumports_level_2(TALLOC_CTX
*mem_ctx
,
7821 union spoolss_PortInfo
**info_p
,
7824 union spoolss_PortInfo
*info
= NULL
;
7826 WERROR result
= WERR_OK
;
7827 char **qlines
= NULL
;
7830 result
= enumports_hook(talloc_tos(), &numlines
, &qlines
);
7831 if (!W_ERROR_IS_OK(result
)) {
7836 info
= talloc_array(mem_ctx
, union spoolss_PortInfo
, numlines
);
7838 DEBUG(10,("Returning WERR_NOMEM\n"));
7839 result
= WERR_NOMEM
;
7843 for (i
=0; i
<numlines
; i
++) {
7844 DEBUG(6,("Filling port number [%d] with port [%s]\n", i
, qlines
[i
]));
7845 result
= fill_port_2(info
, &info
[i
].info2
, qlines
[i
]);
7846 if (!W_ERROR_IS_OK(result
)) {
7851 TALLOC_FREE(qlines
);
7854 if (!W_ERROR_IS_OK(result
)) {
7856 TALLOC_FREE(qlines
);
7868 /****************************************************************
7870 ****************************************************************/
7872 WERROR
_spoolss_EnumPorts(struct pipes_struct
*p
,
7873 struct spoolss_EnumPorts
*r
)
7877 /* that's an [in out] buffer */
7879 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
7880 return WERR_INVALID_PARAM
;
7883 DEBUG(4,("_spoolss_EnumPorts\n"));
7887 *r
->out
.info
= NULL
;
7889 switch (r
->in
.level
) {
7891 result
= enumports_level_1(p
->mem_ctx
, r
->out
.info
,
7895 result
= enumports_level_2(p
->mem_ctx
, r
->out
.info
,
7899 return WERR_UNKNOWN_LEVEL
;
7902 if (!W_ERROR_IS_OK(result
)) {
7906 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
7908 *r
->out
.info
, r
->in
.level
,
7910 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
7911 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
7913 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
7916 /****************************************************************************
7917 ****************************************************************************/
7919 static WERROR
spoolss_addprinterex_level_2(struct pipes_struct
*p
,
7921 struct spoolss_SetPrinterInfoCtr
*info_ctr
,
7922 struct spoolss_DeviceMode
*devmode
,
7923 struct security_descriptor
*secdesc
,
7924 struct spoolss_UserLevelCtr
*user_ctr
,
7925 struct policy_handle
*handle
)
7927 struct spoolss_SetPrinterInfo2
*info2
= info_ctr
->info
.info2
;
7928 uint32_t info2_mask
= SPOOLSS_PRINTER_INFO_ALL
;
7930 WERROR err
= WERR_OK
;
7932 /* samba does not have a concept of local, non-shared printers yet, so
7933 * make sure we always setup sharename - gd */
7934 if ((info2
->sharename
== NULL
|| info2
->sharename
[0] == '\0') &&
7935 (info2
->printername
!= NULL
&& info2
->printername
[0] != '\0')) {
7936 DEBUG(5, ("spoolss_addprinterex_level_2: "
7937 "no sharename has been set, setting printername %s as sharename\n",
7938 info2
->printername
));
7939 info2
->sharename
= info2
->printername
;
7942 /* check to see if the printer already exists */
7943 if ((snum
= print_queue_snum(info2
->sharename
)) != -1) {
7944 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7946 return WERR_PRINTER_ALREADY_EXISTS
;
7949 if (!lp_force_printername(GLOBAL_SECTION_SNUM
)) {
7950 if ((snum
= print_queue_snum(info2
->printername
)) != -1) {
7951 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7952 info2
->printername
));
7953 return WERR_PRINTER_ALREADY_EXISTS
;
7957 /* validate printer info struct */
7958 if (!info2
->printername
|| strlen(info2
->printername
) == 0) {
7959 return WERR_INVALID_PRINTER_NAME
;
7961 if (!info2
->portname
|| strlen(info2
->portname
) == 0) {
7962 return WERR_UNKNOWN_PORT
;
7964 if (!info2
->drivername
|| strlen(info2
->drivername
) == 0) {
7965 return WERR_UNKNOWN_PRINTER_DRIVER
;
7967 if (!info2
->printprocessor
|| strlen(info2
->printprocessor
) == 0) {
7968 return WERR_UNKNOWN_PRINTPROCESSOR
;
7971 /* FIXME!!! smbd should check to see if the driver is installed before
7972 trying to add a printer like this --jerry */
7974 if (*lp_addprinter_cmd() ) {
7977 raddr
= tsocket_address_inet_addr_string(p
->remote_address
,
7979 if (raddr
== NULL
) {
7983 if ( !add_printer_hook(p
->mem_ctx
, p
->session_info
->security_token
,
7986 return WERR_ACCESS_DENIED
;
7989 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no "
7990 "smb.conf parameter \"addprinter command\" is defined. This "
7991 "parameter must exist for this call to succeed\n",
7992 info2
->sharename
));
7995 if ((snum
= print_queue_snum(info2
->sharename
)) == -1) {
7996 return WERR_ACCESS_DENIED
;
7999 /* you must be a printer admin to add a new printer */
8000 if (!print_access_check(p
->session_info
,
8003 PRINTER_ACCESS_ADMINISTER
)) {
8004 return WERR_ACCESS_DENIED
;
8008 * Do sanity check on the requested changes for Samba.
8011 if (!check_printer_ok(p
->mem_ctx
, info2
, snum
)) {
8012 return WERR_INVALID_PARAM
;
8015 if (devmode
== NULL
) {
8016 info2_mask
= ~SPOOLSS_PRINTER_INFO_DEVMODE
;
8019 update_dsspooler(p
->mem_ctx
,
8020 get_session_info_system(),
8026 err
= winreg_update_printer_internal(p
->mem_ctx
,
8027 get_session_info_system(),
8034 if (!W_ERROR_IS_OK(err
)) {
8038 err
= open_printer_hnd(p
, handle
, info2
->printername
, PRINTER_ACCESS_ADMINISTER
);
8039 if (!W_ERROR_IS_OK(err
)) {
8040 /* Handle open failed - remove addition. */
8041 ZERO_STRUCTP(handle
);
8048 /****************************************************************
8049 _spoolss_AddPrinterEx
8050 ****************************************************************/
8052 WERROR
_spoolss_AddPrinterEx(struct pipes_struct
*p
,
8053 struct spoolss_AddPrinterEx
*r
)
8055 switch (r
->in
.info_ctr
->level
) {
8057 /* we don't handle yet */
8058 /* but I know what to do ... */
8059 return WERR_UNKNOWN_LEVEL
;
8061 return spoolss_addprinterex_level_2(p
, r
->in
.server
,
8063 r
->in
.devmode_ctr
->devmode
,
8064 r
->in
.secdesc_ctr
->sd
,
8065 r
->in
.userlevel_ctr
,
8068 return WERR_UNKNOWN_LEVEL
;
8072 /****************************************************************
8074 ****************************************************************/
8076 WERROR
_spoolss_AddPrinter(struct pipes_struct
*p
,
8077 struct spoolss_AddPrinter
*r
)
8079 struct spoolss_AddPrinterEx a
;
8080 struct spoolss_UserLevelCtr userlevel_ctr
;
8082 ZERO_STRUCT(userlevel_ctr
);
8084 userlevel_ctr
.level
= 1;
8086 a
.in
.server
= r
->in
.server
;
8087 a
.in
.info_ctr
= r
->in
.info_ctr
;
8088 a
.in
.devmode_ctr
= r
->in
.devmode_ctr
;
8089 a
.in
.secdesc_ctr
= r
->in
.secdesc_ctr
;
8090 a
.in
.userlevel_ctr
= &userlevel_ctr
;
8091 a
.out
.handle
= r
->out
.handle
;
8093 return _spoolss_AddPrinterEx(p
, &a
);
8096 /****************************************************************
8097 _spoolss_AddPrinterDriverEx
8098 ****************************************************************/
8100 WERROR
_spoolss_AddPrinterDriverEx(struct pipes_struct
*p
,
8101 struct spoolss_AddPrinterDriverEx
*r
)
8103 WERROR err
= WERR_OK
;
8104 const char *driver_name
= NULL
;
8109 case NDR_SPOOLSS_ADDPRINTERDRIVER
:
8110 fn
= "_spoolss_AddPrinterDriver";
8112 case NDR_SPOOLSS_ADDPRINTERDRIVEREX
:
8113 fn
= "_spoolss_AddPrinterDriverEx";
8116 return WERR_INVALID_PARAM
;
8120 * we only support the semantics of AddPrinterDriver()
8121 * i.e. only copy files that are newer than existing ones
8124 if (r
->in
.flags
== 0) {
8125 return WERR_INVALID_PARAM
;
8128 if (r
->in
.flags
!= APD_COPY_NEW_FILES
) {
8129 return WERR_ACCESS_DENIED
;
8133 if (r
->in
.info_ctr
->level
!= 3 && r
->in
.info_ctr
->level
!= 6) {
8134 /* Clever hack from Martin Zielinski <mz@seh.de>
8135 * to allow downgrade from level 8 (Vista).
8137 DEBUG(0,("%s: level %d not yet implemented\n", fn
,
8138 r
->in
.info_ctr
->level
));
8139 return WERR_UNKNOWN_LEVEL
;
8142 DEBUG(5,("Cleaning driver's information\n"));
8143 err
= clean_up_driver_struct(p
->mem_ctx
, p
->session_info
, r
->in
.info_ctr
);
8144 if (!W_ERROR_IS_OK(err
))
8147 DEBUG(5,("Moving driver to final destination\n"));
8148 err
= move_driver_to_download_area(p
->session_info
, r
->in
.info_ctr
);
8149 if (!W_ERROR_IS_OK(err
)) {
8153 err
= winreg_add_driver_internal(p
->mem_ctx
,
8154 get_session_info_system(),
8159 if (!W_ERROR_IS_OK(err
)) {
8164 * I think this is where he DrvUpgradePrinter() hook would be
8165 * be called in a driver's interface DLL on a Windows NT 4.0/2k
8166 * server. Right now, we just need to send ourselves a message
8167 * to update each printer bound to this driver. --jerry
8170 if (!srv_spoolss_drv_upgrade_printer(driver_name
, p
->msg_ctx
)) {
8171 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
8179 /****************************************************************
8180 _spoolss_AddPrinterDriver
8181 ****************************************************************/
8183 WERROR
_spoolss_AddPrinterDriver(struct pipes_struct
*p
,
8184 struct spoolss_AddPrinterDriver
*r
)
8186 struct spoolss_AddPrinterDriverEx a
;
8188 switch (r
->in
.info_ctr
->level
) {
8195 return WERR_UNKNOWN_LEVEL
;
8198 a
.in
.servername
= r
->in
.servername
;
8199 a
.in
.info_ctr
= r
->in
.info_ctr
;
8200 a
.in
.flags
= APD_COPY_NEW_FILES
;
8202 return _spoolss_AddPrinterDriverEx(p
, &a
);
8205 /****************************************************************************
8206 ****************************************************************************/
8208 struct _spoolss_paths
{
8214 enum { SPOOLSS_DRIVER_PATH
, SPOOLSS_PRTPROCS_PATH
};
8216 static const struct _spoolss_paths spoolss_paths
[]= {
8217 { SPOOLSS_DRIVER_PATH
, "print$", "DRIVERS" },
8218 { SPOOLSS_PRTPROCS_PATH
, "prnproc$", "PRTPROCS" }
8221 static WERROR
compose_spoolss_server_path(TALLOC_CTX
*mem_ctx
,
8222 const char *servername
,
8223 const char *environment
,
8227 const char *pservername
= NULL
;
8228 const char *long_archi
= SPOOLSS_ARCHITECTURE_NT_X86
;
8229 const char *short_archi
;
8233 /* environment may be empty */
8234 if (environment
&& strlen(environment
)) {
8235 long_archi
= environment
;
8238 /* servername may be empty */
8239 if (servername
&& strlen(servername
)) {
8240 pservername
= canon_servername(servername
);
8242 if (!is_myname_or_ipaddr(pservername
)) {
8243 return WERR_INVALID_PARAM
;
8247 if (!(short_archi
= get_short_archi(long_archi
))) {
8248 return WERR_INVALID_ENVIRONMENT
;
8251 switch (component
) {
8252 case SPOOLSS_PRTPROCS_PATH
:
8253 case SPOOLSS_DRIVER_PATH
:
8255 *path
= talloc_asprintf(mem_ctx
,
8258 spoolss_paths
[component
].share
,
8261 *path
= talloc_asprintf(mem_ctx
, "%s\\%s\\%s",
8262 SPOOLSS_DEFAULT_SERVER_PATH
,
8263 spoolss_paths
[component
].dir
,
8268 return WERR_INVALID_PARAM
;
8278 /****************************************************************************
8279 ****************************************************************************/
8281 static WERROR
getprinterdriverdir_level_1(TALLOC_CTX
*mem_ctx
,
8282 const char *servername
,
8283 const char *environment
,
8284 struct spoolss_DriverDirectoryInfo1
*r
)
8289 werr
= compose_spoolss_server_path(mem_ctx
,
8292 SPOOLSS_DRIVER_PATH
,
8294 if (!W_ERROR_IS_OK(werr
)) {
8298 DEBUG(4,("printer driver directory: [%s]\n", path
));
8300 r
->directory_name
= path
;
8305 /****************************************************************
8306 _spoolss_GetPrinterDriverDirectory
8307 ****************************************************************/
8309 WERROR
_spoolss_GetPrinterDriverDirectory(struct pipes_struct
*p
,
8310 struct spoolss_GetPrinterDriverDirectory
*r
)
8314 /* that's an [in out] buffer */
8316 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
8317 return WERR_INVALID_PARAM
;
8320 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
8325 /* r->in.level is ignored */
8327 werror
= getprinterdriverdir_level_1(p
->mem_ctx
,
8330 &r
->out
.info
->info1
);
8331 if (!W_ERROR_IS_OK(werror
)) {
8332 TALLOC_FREE(r
->out
.info
);
8336 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo
,
8337 r
->out
.info
, r
->in
.level
);
8338 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
8340 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
8343 /****************************************************************
8344 _spoolss_EnumPrinterData
8345 ****************************************************************/
8347 WERROR
_spoolss_EnumPrinterData(struct pipes_struct
*p
,
8348 struct spoolss_EnumPrinterData
*r
)
8351 struct spoolss_EnumPrinterDataEx r2
;
8353 struct spoolss_PrinterEnumValues
*info
, *val
= NULL
;
8356 r2
.in
.handle
= r
->in
.handle
;
8357 r2
.in
.key_name
= "PrinterDriverData";
8359 r2
.out
.count
= &count
;
8360 r2
.out
.info
= &info
;
8361 r2
.out
.needed
= &needed
;
8363 result
= _spoolss_EnumPrinterDataEx(p
, &r2
);
8364 if (W_ERROR_EQUAL(result
, WERR_MORE_DATA
)) {
8365 r2
.in
.offered
= needed
;
8366 result
= _spoolss_EnumPrinterDataEx(p
, &r2
);
8368 if (!W_ERROR_IS_OK(result
)) {
8373 * The NT machine wants to know the biggest size of value and data
8375 * cf: MSDN EnumPrinterData remark section
8378 if (!r
->in
.value_offered
&& !r
->in
.data_offered
) {
8379 uint32_t biggest_valuesize
= 0;
8380 uint32_t biggest_datasize
= 0;
8383 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
8385 for (i
=0; i
<count
; i
++) {
8387 name_length
= strlen(info
[i
].value_name
);
8388 if (strlen(info
[i
].value_name
) > biggest_valuesize
) {
8389 biggest_valuesize
= name_length
;
8392 if (info
[i
].data_length
> biggest_datasize
) {
8393 biggest_datasize
= info
[i
].data_length
;
8396 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize
,
8400 /* the value is an UNICODE string but real_value_size is the length
8401 in bytes including the trailing 0 */
8403 *r
->out
.value_needed
= 2 * (1 + biggest_valuesize
);
8404 *r
->out
.data_needed
= biggest_datasize
;
8406 DEBUG(6,("final values: [%d], [%d]\n",
8407 *r
->out
.value_needed
, *r
->out
.data_needed
));
8412 if (r
->in
.enum_index
< count
) {
8413 val
= &info
[r
->in
.enum_index
];
8417 /* out_value should default to "" or else NT4 has
8418 problems unmarshalling the response */
8420 if (r
->in
.value_offered
) {
8421 *r
->out
.value_needed
= 1;
8422 r
->out
.value_name
= talloc_strdup(r
, "");
8423 if (!r
->out
.value_name
) {
8427 r
->out
.value_name
= NULL
;
8428 *r
->out
.value_needed
= 0;
8431 /* the data is counted in bytes */
8433 *r
->out
.data_needed
= r
->in
.data_offered
;
8435 result
= WERR_NO_MORE_ITEMS
;
8439 * - counted in bytes in the request
8440 * - counted in UNICODE chars in the max reply
8441 * - counted in bytes in the real size
8443 * take a pause *before* coding not *during* coding
8447 if (r
->in
.value_offered
) {
8448 r
->out
.value_name
= talloc_strdup(r
, val
->value_name
);
8449 if (!r
->out
.value_name
) {
8452 *r
->out
.value_needed
= val
->value_name_len
;
8454 r
->out
.value_name
= NULL
;
8455 *r
->out
.value_needed
= 0;
8460 *r
->out
.type
= val
->type
;
8462 /* data - counted in bytes */
8465 * See the section "Dynamically Typed Query Parameters"
8469 if (r
->out
.data
&& val
->data
&& val
->data
->data
&&
8470 val
->data_length
&& r
->in
.data_offered
) {
8471 memcpy(r
->out
.data
, val
->data
->data
,
8472 MIN(val
->data_length
,r
->in
.data_offered
));
8475 *r
->out
.data_needed
= val
->data_length
;
8483 /****************************************************************
8484 _spoolss_SetPrinterData
8485 ****************************************************************/
8487 WERROR
_spoolss_SetPrinterData(struct pipes_struct
*p
,
8488 struct spoolss_SetPrinterData
*r
)
8490 struct spoolss_SetPrinterDataEx r2
;
8492 r2
.in
.handle
= r
->in
.handle
;
8493 r2
.in
.key_name
= "PrinterDriverData";
8494 r2
.in
.value_name
= r
->in
.value_name
;
8495 r2
.in
.type
= r
->in
.type
;
8496 r2
.in
.data
= r
->in
.data
;
8497 r2
.in
.offered
= r
->in
.offered
;
8499 return _spoolss_SetPrinterDataEx(p
, &r2
);
8502 /****************************************************************
8503 _spoolss_ResetPrinter
8504 ****************************************************************/
8506 WERROR
_spoolss_ResetPrinter(struct pipes_struct
*p
,
8507 struct spoolss_ResetPrinter
*r
)
8509 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
8512 DEBUG(5,("_spoolss_ResetPrinter\n"));
8515 * All we do is to check to see if the handle and queue is valid.
8516 * This call really doesn't mean anything to us because we only
8517 * support RAW printing. --jerry
8521 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
8522 OUR_HANDLE(r
->in
.handle
)));
8526 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
))
8530 /* blindly return success */
8534 /****************************************************************
8535 _spoolss_DeletePrinterData
8536 ****************************************************************/
8538 WERROR
_spoolss_DeletePrinterData(struct pipes_struct
*p
,
8539 struct spoolss_DeletePrinterData
*r
)
8541 struct spoolss_DeletePrinterDataEx r2
;
8543 r2
.in
.handle
= r
->in
.handle
;
8544 r2
.in
.key_name
= "PrinterDriverData";
8545 r2
.in
.value_name
= r
->in
.value_name
;
8547 return _spoolss_DeletePrinterDataEx(p
, &r2
);
8550 /****************************************************************
8552 ****************************************************************/
8554 WERROR
_spoolss_AddForm(struct pipes_struct
*p
,
8555 struct spoolss_AddForm
*r
)
8557 struct spoolss_AddFormInfo1
*form
= r
->in
.info
.info1
;
8559 WERROR status
= WERR_OK
;
8560 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
8561 struct dcerpc_binding_handle
*b
;
8562 TALLOC_CTX
*tmp_ctx
= NULL
;
8564 DEBUG(5,("_spoolss_AddForm\n"));
8567 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
8568 OUR_HANDLE(r
->in
.handle
)));
8572 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8573 and not a printer admin, then fail */
8575 if ((p
->session_info
->unix_token
->uid
!= sec_initial_uid()) &&
8576 !security_token_has_privilege(p
->session_info
->security_token
, SEC_PRIV_PRINT_OPERATOR
) &&
8577 !token_contains_name_in_list(uidtoname(p
->session_info
->unix_token
->uid
),
8578 p
->session_info
->info
->domain_name
,
8580 p
->session_info
->security_token
,
8581 lp_printer_admin(snum
))) {
8582 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
8583 return WERR_ACCESS_DENIED
;
8586 switch (form
->flags
) {
8587 case SPOOLSS_FORM_USER
:
8588 case SPOOLSS_FORM_BUILTIN
:
8589 case SPOOLSS_FORM_PRINTER
:
8592 return WERR_INVALID_PARAM
;
8595 tmp_ctx
= talloc_new(p
->mem_ctx
);
8600 status
= winreg_printer_binding_handle(tmp_ctx
,
8601 get_session_info_system(),
8604 if (!W_ERROR_IS_OK(status
)) {
8608 status
= winreg_printer_addform1(tmp_ctx
, b
, form
);
8609 if (!W_ERROR_IS_OK(status
)) {
8614 * ChangeID must always be set if this is a printer
8616 if (Printer
->printer_type
== SPLHND_PRINTER
) {
8617 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
8618 status
= WERR_BADFID
;
8622 status
= winreg_printer_update_changeid(tmp_ctx
, b
,
8623 lp_const_servicename(snum
));
8627 talloc_free(tmp_ctx
);
8631 /****************************************************************
8633 ****************************************************************/
8635 WERROR
_spoolss_DeleteForm(struct pipes_struct
*p
,
8636 struct spoolss_DeleteForm
*r
)
8638 const char *form_name
= r
->in
.form_name
;
8639 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
8641 WERROR status
= WERR_OK
;
8642 struct dcerpc_binding_handle
*b
;
8643 TALLOC_CTX
*tmp_ctx
= NULL
;
8645 DEBUG(5,("_spoolss_DeleteForm\n"));
8648 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
8649 OUR_HANDLE(r
->in
.handle
)));
8653 if ((p
->session_info
->unix_token
->uid
!= sec_initial_uid()) &&
8654 !security_token_has_privilege(p
->session_info
->security_token
, SEC_PRIV_PRINT_OPERATOR
) &&
8655 !token_contains_name_in_list(uidtoname(p
->session_info
->unix_token
->uid
),
8656 p
->session_info
->info
->domain_name
,
8658 p
->session_info
->security_token
,
8659 lp_printer_admin(snum
))) {
8660 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
8661 return WERR_ACCESS_DENIED
;
8664 tmp_ctx
= talloc_new(p
->mem_ctx
);
8669 status
= winreg_printer_binding_handle(tmp_ctx
,
8670 get_session_info_system(),
8673 if (!W_ERROR_IS_OK(status
)) {
8677 status
= winreg_printer_deleteform1(tmp_ctx
, b
, form_name
);
8678 if (!W_ERROR_IS_OK(status
)) {
8683 * ChangeID must always be set if this is a printer
8685 if (Printer
->printer_type
== SPLHND_PRINTER
) {
8686 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
8687 status
= WERR_BADFID
;
8691 status
= winreg_printer_update_changeid(tmp_ctx
, b
,
8692 lp_const_servicename(snum
));
8696 talloc_free(tmp_ctx
);
8700 /****************************************************************
8702 ****************************************************************/
8704 WERROR
_spoolss_SetForm(struct pipes_struct
*p
,
8705 struct spoolss_SetForm
*r
)
8707 struct spoolss_AddFormInfo1
*form
= r
->in
.info
.info1
;
8708 const char *form_name
= r
->in
.form_name
;
8710 WERROR status
= WERR_OK
;
8711 struct dcerpc_binding_handle
*b
;
8712 TALLOC_CTX
*tmp_ctx
= NULL
;
8714 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
8716 DEBUG(5,("_spoolss_SetForm\n"));
8719 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8720 OUR_HANDLE(r
->in
.handle
)));
8724 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8725 and not a printer admin, then fail */
8727 if ((p
->session_info
->unix_token
->uid
!= sec_initial_uid()) &&
8728 !security_token_has_privilege(p
->session_info
->security_token
, SEC_PRIV_PRINT_OPERATOR
) &&
8729 !token_contains_name_in_list(uidtoname(p
->session_info
->unix_token
->uid
),
8730 p
->session_info
->info
->domain_name
,
8732 p
->session_info
->security_token
,
8733 lp_printer_admin(snum
))) {
8734 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
8735 return WERR_ACCESS_DENIED
;
8738 tmp_ctx
= talloc_new(p
->mem_ctx
);
8743 status
= winreg_printer_binding_handle(tmp_ctx
,
8744 get_session_info_system(),
8747 if (!W_ERROR_IS_OK(status
)) {
8751 status
= winreg_printer_setform1(tmp_ctx
, b
,
8754 if (!W_ERROR_IS_OK(status
)) {
8759 * ChangeID must always be set if this is a printer
8761 if (Printer
->printer_type
== SPLHND_PRINTER
) {
8762 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
8763 status
= WERR_BADFID
;
8767 status
= winreg_printer_update_changeid(tmp_ctx
, b
,
8768 lp_const_servicename(snum
));
8772 talloc_free(tmp_ctx
);
8776 /****************************************************************************
8777 fill_print_processor1
8778 ****************************************************************************/
8780 static WERROR
fill_print_processor1(TALLOC_CTX
*mem_ctx
,
8781 struct spoolss_PrintProcessorInfo1
*r
,
8782 const char *print_processor_name
)
8784 r
->print_processor_name
= talloc_strdup(mem_ctx
, print_processor_name
);
8785 W_ERROR_HAVE_NO_MEMORY(r
->print_processor_name
);
8790 /****************************************************************************
8791 enumprintprocessors level 1.
8792 ****************************************************************************/
8794 static WERROR
enumprintprocessors_level_1(TALLOC_CTX
*mem_ctx
,
8795 union spoolss_PrintProcessorInfo
**info_p
,
8798 union spoolss_PrintProcessorInfo
*info
;
8801 info
= talloc_array(mem_ctx
, union spoolss_PrintProcessorInfo
, 1);
8802 W_ERROR_HAVE_NO_MEMORY(info
);
8806 result
= fill_print_processor1(info
, &info
[0].info1
, "winprint");
8807 if (!W_ERROR_IS_OK(result
)) {
8812 if (!W_ERROR_IS_OK(result
)) {
8823 /****************************************************************
8824 _spoolss_EnumPrintProcessors
8825 ****************************************************************/
8827 WERROR
_spoolss_EnumPrintProcessors(struct pipes_struct
*p
,
8828 struct spoolss_EnumPrintProcessors
*r
)
8832 /* that's an [in out] buffer */
8834 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
8835 return WERR_INVALID_PARAM
;
8838 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8841 * Enumerate the print processors ...
8843 * Just reply with "winprint", to keep NT happy
8844 * and I can use my nice printer checker.
8849 *r
->out
.info
= NULL
;
8851 if (!get_short_archi(r
->in
.environment
)) {
8852 return WERR_INVALID_ENVIRONMENT
;
8855 switch (r
->in
.level
) {
8857 result
= enumprintprocessors_level_1(p
->mem_ctx
, r
->out
.info
,
8861 return WERR_UNKNOWN_LEVEL
;
8864 if (!W_ERROR_IS_OK(result
)) {
8868 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
8869 spoolss_EnumPrintProcessors
,
8870 *r
->out
.info
, r
->in
.level
,
8872 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
8873 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
8875 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
8878 /****************************************************************************
8879 fill_printprocdatatype1
8880 ****************************************************************************/
8882 static WERROR
fill_printprocdatatype1(TALLOC_CTX
*mem_ctx
,
8883 struct spoolss_PrintProcDataTypesInfo1
*r
,
8884 const char *name_array
)
8886 r
->name_array
= talloc_strdup(mem_ctx
, name_array
);
8887 W_ERROR_HAVE_NO_MEMORY(r
->name_array
);
8892 /****************************************************************************
8893 enumprintprocdatatypes level 1.
8894 ****************************************************************************/
8896 static WERROR
enumprintprocdatatypes_level_1(TALLOC_CTX
*mem_ctx
,
8897 union spoolss_PrintProcDataTypesInfo
**info_p
,
8901 union spoolss_PrintProcDataTypesInfo
*info
;
8903 info
= talloc_array(mem_ctx
, union spoolss_PrintProcDataTypesInfo
, 1);
8904 W_ERROR_HAVE_NO_MEMORY(info
);
8908 result
= fill_printprocdatatype1(info
, &info
[0].info1
, "RAW");
8909 if (!W_ERROR_IS_OK(result
)) {
8914 if (!W_ERROR_IS_OK(result
)) {
8925 /****************************************************************
8926 _spoolss_EnumPrintProcDataTypes
8927 ****************************************************************/
8929 WERROR
_spoolss_EnumPrintProcDataTypes(struct pipes_struct
*p
,
8930 struct spoolss_EnumPrintProcDataTypes
*r
)
8934 /* that's an [in out] buffer */
8936 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
8937 return WERR_INVALID_PARAM
;
8940 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
8944 *r
->out
.info
= NULL
;
8946 if (r
->in
.print_processor_name
== NULL
||
8947 !strequal(r
->in
.print_processor_name
, "winprint")) {
8948 return WERR_UNKNOWN_PRINTPROCESSOR
;
8951 switch (r
->in
.level
) {
8953 result
= enumprintprocdatatypes_level_1(p
->mem_ctx
, r
->out
.info
,
8957 return WERR_UNKNOWN_LEVEL
;
8960 if (!W_ERROR_IS_OK(result
)) {
8964 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
8965 spoolss_EnumPrintProcDataTypes
,
8966 *r
->out
.info
, r
->in
.level
,
8968 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
8969 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
8971 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
8974 /****************************************************************************
8976 ****************************************************************************/
8978 static WERROR
fill_monitor_1(TALLOC_CTX
*mem_ctx
,
8979 struct spoolss_MonitorInfo1
*r
,
8980 const char *monitor_name
)
8982 r
->monitor_name
= talloc_strdup(mem_ctx
, monitor_name
);
8983 W_ERROR_HAVE_NO_MEMORY(r
->monitor_name
);
8988 /****************************************************************************
8990 ****************************************************************************/
8992 static WERROR
fill_monitor_2(TALLOC_CTX
*mem_ctx
,
8993 struct spoolss_MonitorInfo2
*r
,
8994 const char *monitor_name
,
8995 const char *environment
,
8996 const char *dll_name
)
8998 r
->monitor_name
= talloc_strdup(mem_ctx
, monitor_name
);
8999 W_ERROR_HAVE_NO_MEMORY(r
->monitor_name
);
9000 r
->environment
= talloc_strdup(mem_ctx
, environment
);
9001 W_ERROR_HAVE_NO_MEMORY(r
->environment
);
9002 r
->dll_name
= talloc_strdup(mem_ctx
, dll_name
);
9003 W_ERROR_HAVE_NO_MEMORY(r
->dll_name
);
9008 /****************************************************************************
9009 enumprintmonitors level 1.
9010 ****************************************************************************/
9012 static WERROR
enumprintmonitors_level_1(TALLOC_CTX
*mem_ctx
,
9013 union spoolss_MonitorInfo
**info_p
,
9016 union spoolss_MonitorInfo
*info
;
9017 WERROR result
= WERR_OK
;
9019 info
= talloc_array(mem_ctx
, union spoolss_MonitorInfo
, 2);
9020 W_ERROR_HAVE_NO_MEMORY(info
);
9024 result
= fill_monitor_1(info
, &info
[0].info1
,
9026 if (!W_ERROR_IS_OK(result
)) {
9030 result
= fill_monitor_1(info
, &info
[1].info1
,
9032 if (!W_ERROR_IS_OK(result
)) {
9037 if (!W_ERROR_IS_OK(result
)) {
9048 /****************************************************************************
9049 enumprintmonitors level 2.
9050 ****************************************************************************/
9052 static WERROR
enumprintmonitors_level_2(TALLOC_CTX
*mem_ctx
,
9053 union spoolss_MonitorInfo
**info_p
,
9056 union spoolss_MonitorInfo
*info
;
9057 WERROR result
= WERR_OK
;
9059 info
= talloc_array(mem_ctx
, union spoolss_MonitorInfo
, 2);
9060 W_ERROR_HAVE_NO_MEMORY(info
);
9064 result
= fill_monitor_2(info
, &info
[0].info2
,
9066 "Windows NT X86", /* FIXME */
9068 if (!W_ERROR_IS_OK(result
)) {
9072 result
= fill_monitor_2(info
, &info
[1].info2
,
9074 "Windows NT X86", /* FIXME */
9076 if (!W_ERROR_IS_OK(result
)) {
9081 if (!W_ERROR_IS_OK(result
)) {
9092 /****************************************************************
9093 _spoolss_EnumMonitors
9094 ****************************************************************/
9096 WERROR
_spoolss_EnumMonitors(struct pipes_struct
*p
,
9097 struct spoolss_EnumMonitors
*r
)
9101 /* that's an [in out] buffer */
9103 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
9104 return WERR_INVALID_PARAM
;
9107 DEBUG(5,("_spoolss_EnumMonitors\n"));
9110 * Enumerate the print monitors ...
9112 * Just reply with "Local Port", to keep NT happy
9113 * and I can use my nice printer checker.
9118 *r
->out
.info
= NULL
;
9120 switch (r
->in
.level
) {
9122 result
= enumprintmonitors_level_1(p
->mem_ctx
, r
->out
.info
,
9126 result
= enumprintmonitors_level_2(p
->mem_ctx
, r
->out
.info
,
9130 return WERR_UNKNOWN_LEVEL
;
9133 if (!W_ERROR_IS_OK(result
)) {
9137 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
9138 spoolss_EnumMonitors
,
9139 *r
->out
.info
, r
->in
.level
,
9141 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
9142 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
9144 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
9147 /****************************************************************************
9148 ****************************************************************************/
9150 static WERROR
getjob_level_1(TALLOC_CTX
*mem_ctx
,
9151 const print_queue_struct
*queue
,
9152 int count
, int snum
,
9153 struct spoolss_PrinterInfo2
*pinfo2
,
9155 struct spoolss_JobInfo1
*r
)
9160 for (i
=0; i
<count
; i
++) {
9161 if (queue
[i
].job
== (int)jobid
) {
9167 if (found
== false) {
9168 /* NT treats not found as bad param... yet another bad choice */
9169 return WERR_INVALID_PARAM
;
9172 return fill_job_info1(mem_ctx
,
9180 /****************************************************************************
9181 ****************************************************************************/
9183 static WERROR
getjob_level_2(TALLOC_CTX
*mem_ctx
,
9184 const print_queue_struct
*queue
,
9185 int count
, int snum
,
9186 struct spoolss_PrinterInfo2
*pinfo2
,
9188 struct spoolss_JobInfo2
*r
)
9192 struct spoolss_DeviceMode
*devmode
;
9195 for (i
=0; i
<count
; i
++) {
9196 if (queue
[i
].job
== (int)jobid
) {
9202 if (found
== false) {
9203 /* NT treats not found as bad param... yet another bad
9205 return WERR_INVALID_PARAM
;
9209 * if the print job does not have a DEVMODE associated with it,
9210 * just use the one for the printer. A NULL devicemode is not
9211 * a failure condition
9214 devmode
= print_job_devmode(lp_const_servicename(snum
), jobid
);
9216 result
= spoolss_create_default_devmode(mem_ctx
,
9217 pinfo2
->printername
,
9219 if (!W_ERROR_IS_OK(result
)) {
9220 DEBUG(3, ("Can't proceed w/o a devmode!"));
9225 return fill_job_info2(mem_ctx
,
9234 /****************************************************************
9236 ****************************************************************/
9238 WERROR
_spoolss_GetJob(struct pipes_struct
*p
,
9239 struct spoolss_GetJob
*r
)
9241 WERROR result
= WERR_OK
;
9242 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
9245 print_queue_struct
*queue
= NULL
;
9246 print_status_struct prt_status
;
9248 /* that's an [in out] buffer */
9250 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
9251 return WERR_INVALID_PARAM
;
9254 DEBUG(5,("_spoolss_GetJob\n"));
9258 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9262 result
= winreg_get_printer_internal(p
->mem_ctx
,
9263 get_session_info_system(),
9265 lp_const_servicename(snum
),
9267 if (!W_ERROR_IS_OK(result
)) {
9271 count
= print_queue_status(p
->msg_ctx
, snum
, &queue
, &prt_status
);
9273 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
9274 count
, prt_status
.status
, prt_status
.message
));
9276 switch (r
->in
.level
) {
9278 result
= getjob_level_1(p
->mem_ctx
,
9279 queue
, count
, snum
, pinfo2
,
9280 r
->in
.job_id
, &r
->out
.info
->info1
);
9283 result
= getjob_level_2(p
->mem_ctx
,
9284 queue
, count
, snum
, pinfo2
,
9285 r
->in
.job_id
, &r
->out
.info
->info2
);
9288 result
= WERR_UNKNOWN_LEVEL
;
9293 TALLOC_FREE(pinfo2
);
9295 if (!W_ERROR_IS_OK(result
)) {
9296 TALLOC_FREE(r
->out
.info
);
9300 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_JobInfo
, r
->out
.info
,
9302 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
9304 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
9307 /****************************************************************
9308 _spoolss_GetPrinterDataEx
9309 ****************************************************************/
9311 WERROR
_spoolss_GetPrinterDataEx(struct pipes_struct
*p
,
9312 struct spoolss_GetPrinterDataEx
*r
)
9315 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9316 const char *printer
;
9318 WERROR result
= WERR_OK
;
9320 enum winreg_Type val_type
= REG_NONE
;
9321 uint8_t *val_data
= NULL
;
9322 uint32_t val_size
= 0;
9323 struct dcerpc_binding_handle
*b
;
9324 TALLOC_CTX
*tmp_ctx
;
9326 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
9328 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
9329 r
->in
.key_name
, r
->in
.value_name
));
9331 /* in case of problem, return some default values */
9334 *r
->out
.type
= REG_NONE
;
9336 tmp_ctx
= talloc_new(p
->mem_ctx
);
9342 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9343 OUR_HANDLE(r
->in
.handle
)));
9344 result
= WERR_BADFID
;
9348 /* check to see if the keyname is valid */
9349 if (!strlen(r
->in
.key_name
)) {
9350 result
= WERR_INVALID_PARAM
;
9354 /* Is the handle to a printer or to the server? */
9356 if (Printer
->printer_type
== SPLHND_SERVER
) {
9358 union spoolss_PrinterData data
;
9360 result
= getprinterdata_printer_server(tmp_ctx
,
9364 if (!W_ERROR_IS_OK(result
)) {
9368 result
= push_spoolss_PrinterData(tmp_ctx
, &blob
,
9369 *r
->out
.type
, &data
);
9370 if (!W_ERROR_IS_OK(result
)) {
9374 *r
->out
.needed
= blob
.length
;
9376 if (r
->in
.offered
>= *r
->out
.needed
) {
9377 memcpy(r
->out
.data
, blob
.data
, blob
.length
);
9384 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9385 result
= WERR_BADFID
;
9388 printer
= lp_const_servicename(snum
);
9390 result
= winreg_printer_binding_handle(tmp_ctx
,
9391 get_session_info_system(),
9394 if (!W_ERROR_IS_OK(result
)) {
9398 /* XP sends this and wants the ChangeID value from PRINTER_INFO_0 */
9399 if (strequal(r
->in
.key_name
, SPOOL_PRINTERDATA_KEY
) &&
9400 strequal(r
->in
.value_name
, "ChangeId")) {
9401 *r
->out
.type
= REG_DWORD
;
9403 if (r
->in
.offered
>= *r
->out
.needed
) {
9404 uint32_t changeid
= 0;
9406 result
= winreg_printer_get_changeid(tmp_ctx
, b
,
9409 if (!W_ERROR_IS_OK(result
)) {
9413 SIVAL(r
->out
.data
, 0, changeid
);
9419 result
= winreg_get_printer_dataex(tmp_ctx
, b
,
9426 if (!W_ERROR_IS_OK(result
)) {
9430 *r
->out
.needed
= val_size
;
9431 *r
->out
.type
= val_type
;
9433 if (r
->in
.offered
>= *r
->out
.needed
) {
9434 memcpy(r
->out
.data
, val_data
, val_size
);
9438 /* NOTE: do not replace type when returning WERR_MORE_DATA */
9440 if (W_ERROR_IS_OK(result
)) {
9441 result
= SPOOLSS_BUFFER_OK(WERR_OK
, WERR_MORE_DATA
);
9444 talloc_free(tmp_ctx
);
9448 /****************************************************************
9449 _spoolss_SetPrinterDataEx
9450 ****************************************************************/
9452 WERROR
_spoolss_SetPrinterDataEx(struct pipes_struct
*p
,
9453 struct spoolss_SetPrinterDataEx
*r
)
9455 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
9457 WERROR result
= WERR_OK
;
9458 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9460 struct dcerpc_binding_handle
*b
;
9461 TALLOC_CTX
*tmp_ctx
;
9463 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
9465 /* From MSDN documentation of SetPrinterDataEx: pass request to
9466 SetPrinterData if key is "PrinterDriverData" */
9469 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9470 OUR_HANDLE(r
->in
.handle
)));
9474 if (Printer
->printer_type
== SPLHND_SERVER
) {
9475 DEBUG(10,("_spoolss_SetPrinterDataEx: "
9476 "Not implemented for server handles yet\n"));
9477 return WERR_INVALID_PARAM
;
9480 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9485 * Access check : NT returns "access denied" if you make a
9486 * SetPrinterData call without the necessary privildge.
9487 * we were originally returning OK if nothing changed
9488 * which made Win2k issue **a lot** of SetPrinterData
9489 * when connecting to a printer --jerry
9492 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
9493 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
9494 "change denied by handle access permissions\n"));
9495 return WERR_ACCESS_DENIED
;
9498 tmp_ctx
= talloc_new(p
->mem_ctx
);
9503 result
= winreg_printer_binding_handle(tmp_ctx
,
9504 get_session_info_system(),
9507 if (!W_ERROR_IS_OK(result
)) {
9511 result
= winreg_get_printer(tmp_ctx
, b
,
9512 lp_servicename(snum
),
9514 if (!W_ERROR_IS_OK(result
)) {
9518 /* check for OID in valuename */
9520 oid_string
= strchr(r
->in
.value_name
, ',');
9526 /* save the registry data */
9528 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
9536 if (W_ERROR_IS_OK(result
)) {
9537 /* save the OID if one was specified */
9539 char *str
= talloc_asprintf(tmp_ctx
, "%s\\%s",
9540 r
->in
.key_name
, SPOOL_OID_KEY
);
9542 result
= WERR_NOMEM
;
9547 * I'm not checking the status here on purpose. Don't know
9548 * if this is right, but I'm returning the status from the
9549 * previous set_printer_dataex() call. I have no idea if
9550 * this is right. --jerry
9552 winreg_set_printer_dataex(tmp_ctx
, b
,
9557 (uint8_t *) oid_string
,
9558 strlen(oid_string
) + 1);
9561 result
= winreg_printer_update_changeid(tmp_ctx
, b
,
9562 lp_const_servicename(snum
));
9567 talloc_free(tmp_ctx
);
9571 /****************************************************************
9572 _spoolss_DeletePrinterDataEx
9573 ****************************************************************/
9575 WERROR
_spoolss_DeletePrinterDataEx(struct pipes_struct
*p
,
9576 struct spoolss_DeletePrinterDataEx
*r
)
9578 const char *printer
;
9580 WERROR status
= WERR_OK
;
9581 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9583 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
9586 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
9587 "Invalid handle (%s:%u:%u).\n",
9588 OUR_HANDLE(r
->in
.handle
)));
9592 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
9593 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
9594 "printer properties change denied by handle\n"));
9595 return WERR_ACCESS_DENIED
;
9598 if (!r
->in
.value_name
|| !r
->in
.key_name
) {
9602 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9605 printer
= lp_const_servicename(snum
);
9607 status
= winreg_delete_printer_dataex_internal(p
->mem_ctx
,
9608 get_session_info_system(),
9613 if (W_ERROR_IS_OK(status
)) {
9614 status
= winreg_printer_update_changeid_internal(p
->mem_ctx
,
9615 get_session_info_system(),
9623 /****************************************************************
9624 _spoolss_EnumPrinterKey
9625 ****************************************************************/
9627 WERROR
_spoolss_EnumPrinterKey(struct pipes_struct
*p
,
9628 struct spoolss_EnumPrinterKey
*r
)
9631 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9633 WERROR result
= WERR_BADFILE
;
9634 const char **array
= NULL
;
9637 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
9640 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
9641 OUR_HANDLE(r
->in
.handle
)));
9645 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9649 result
= winreg_enum_printer_key_internal(p
->mem_ctx
,
9650 get_session_info_system(),
9652 lp_const_servicename(snum
),
9656 if (!W_ERROR_IS_OK(result
)) {
9660 if (!push_reg_multi_sz(p
->mem_ctx
, &blob
, array
)) {
9661 result
= WERR_NOMEM
;
9665 *r
->out
._ndr_size
= r
->in
.offered
/ 2;
9666 *r
->out
.needed
= blob
.length
;
9668 if (r
->in
.offered
< *r
->out
.needed
) {
9669 result
= WERR_MORE_DATA
;
9672 r
->out
.key_buffer
->string_array
= array
;
9676 if (!W_ERROR_IS_OK(result
)) {
9678 if (!W_ERROR_EQUAL(result
, WERR_MORE_DATA
)) {
9686 /****************************************************************
9687 _spoolss_DeletePrinterKey
9688 ****************************************************************/
9690 WERROR
_spoolss_DeletePrinterKey(struct pipes_struct
*p
,
9691 struct spoolss_DeletePrinterKey
*r
)
9693 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9696 const char *printer
;
9697 struct dcerpc_binding_handle
*b
;
9698 TALLOC_CTX
*tmp_ctx
;
9700 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
9703 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
9704 OUR_HANDLE(r
->in
.handle
)));
9708 /* if keyname == NULL, return error */
9709 if ( !r
->in
.key_name
)
9710 return WERR_INVALID_PARAM
;
9712 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9716 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
9717 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9718 "printer properties change denied by handle\n"));
9719 return WERR_ACCESS_DENIED
;
9722 printer
= lp_const_servicename(snum
);
9724 tmp_ctx
= talloc_new(p
->mem_ctx
);
9729 status
= winreg_printer_binding_handle(tmp_ctx
,
9730 get_session_info_system(),
9733 if (!W_ERROR_IS_OK(status
)) {
9737 /* delete the key and all subkeys */
9738 status
= winreg_delete_printer_key(tmp_ctx
, b
,
9741 if (W_ERROR_IS_OK(status
)) {
9742 status
= winreg_printer_update_changeid(tmp_ctx
, b
,
9747 talloc_free(tmp_ctx
);
9751 /****************************************************************
9752 _spoolss_EnumPrinterDataEx
9753 ****************************************************************/
9755 WERROR
_spoolss_EnumPrinterDataEx(struct pipes_struct
*p
,
9756 struct spoolss_EnumPrinterDataEx
*r
)
9759 struct spoolss_PrinterEnumValues
*info
= NULL
;
9760 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9764 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
9768 *r
->out
.info
= NULL
;
9771 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
9772 OUR_HANDLE(r
->in
.handle
)));
9777 * first check for a keyname of NULL or "". Win2k seems to send
9778 * this a lot and we should send back WERR_INVALID_PARAM
9779 * no need to spend time looking up the printer in this case.
9783 if (!strlen(r
->in
.key_name
)) {
9784 result
= WERR_INVALID_PARAM
;
9788 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9792 /* now look for a match on the key name */
9793 result
= winreg_enum_printer_dataex_internal(p
->mem_ctx
,
9794 get_session_info_system(),
9796 lp_const_servicename(snum
),
9800 if (!W_ERROR_IS_OK(result
)) {
9804 #if 0 /* FIXME - gd */
9805 /* housekeeping information in the reply */
9807 /* Fix from Martin Zielinski <mz@seh.de> - ensure
9808 * the hand marshalled container size is a multiple
9809 * of 4 bytes for RPC alignment.
9813 needed
+= 4-(needed
% 4);
9816 *r
->out
.count
= count
;
9817 *r
->out
.info
= info
;
9820 if (!W_ERROR_IS_OK(result
)) {
9824 *r
->out
.needed
= SPOOLSS_BUFFER_ARRAY(p
->mem_ctx
,
9825 spoolss_EnumPrinterDataEx
,
9828 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
9829 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, *r
->out
.count
);
9831 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_MORE_DATA
);
9834 /****************************************************************************
9835 ****************************************************************************/
9837 static WERROR
getprintprocessordirectory_level_1(TALLOC_CTX
*mem_ctx
,
9838 const char *servername
,
9839 const char *environment
,
9840 struct spoolss_PrintProcessorDirectoryInfo1
*r
)
9845 werr
= compose_spoolss_server_path(mem_ctx
,
9848 SPOOLSS_PRTPROCS_PATH
,
9850 if (!W_ERROR_IS_OK(werr
)) {
9854 DEBUG(4,("print processor directory: [%s]\n", path
));
9856 r
->directory_name
= path
;
9861 /****************************************************************
9862 _spoolss_GetPrintProcessorDirectory
9863 ****************************************************************/
9865 WERROR
_spoolss_GetPrintProcessorDirectory(struct pipes_struct
*p
,
9866 struct spoolss_GetPrintProcessorDirectory
*r
)
9869 char *prnproc_share
= NULL
;
9870 bool prnproc_share_exists
= false;
9873 /* that's an [in out] buffer */
9875 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
9876 return WERR_INVALID_PARAM
;
9879 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9884 /* r->in.level is ignored */
9886 /* We always should reply with a local print processor directory so that
9887 * users are not forced to have a [prnproc$] share on the Samba spoolss
9888 * server, if users decide to do so, lets announce it though - Guenther */
9890 snum
= find_service(talloc_tos(), "prnproc$", &prnproc_share
);
9891 if (!prnproc_share
) {
9895 prnproc_share_exists
= true;
9898 result
= getprintprocessordirectory_level_1(p
->mem_ctx
,
9899 prnproc_share_exists
? r
->in
.server
: NULL
,
9901 &r
->out
.info
->info1
);
9902 if (!W_ERROR_IS_OK(result
)) {
9903 TALLOC_FREE(r
->out
.info
);
9907 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo
,
9908 r
->out
.info
, r
->in
.level
);
9909 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
9911 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
9914 /*******************************************************************
9915 ********************************************************************/
9917 static bool push_monitorui_buf(TALLOC_CTX
*mem_ctx
, DATA_BLOB
*buf
,
9918 const char *dllname
)
9920 enum ndr_err_code ndr_err
;
9921 struct spoolss_MonitorUi ui
;
9923 ui
.dll_name
= dllname
;
9925 ndr_err
= ndr_push_struct_blob(buf
, mem_ctx
, &ui
,
9926 (ndr_push_flags_fn_t
)ndr_push_spoolss_MonitorUi
);
9927 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err
) && (DEBUGLEVEL
>= 10)) {
9928 NDR_PRINT_DEBUG(spoolss_MonitorUi
, &ui
);
9930 return NDR_ERR_CODE_IS_SUCCESS(ndr_err
);
9933 /*******************************************************************
9934 Streams the monitor UI DLL name in UNICODE
9935 *******************************************************************/
9937 static WERROR
xcvtcp_monitorui(TALLOC_CTX
*mem_ctx
,
9938 struct security_token
*token
, DATA_BLOB
*in
,
9939 DATA_BLOB
*out
, uint32_t *needed
)
9941 const char *dllname
= "tcpmonui.dll";
9943 *needed
= (strlen(dllname
)+1) * 2;
9945 if (out
->length
< *needed
) {
9946 return WERR_INSUFFICIENT_BUFFER
;
9949 if (!push_monitorui_buf(mem_ctx
, out
, dllname
)) {
9956 /*******************************************************************
9957 ********************************************************************/
9959 static bool pull_port_data_1(TALLOC_CTX
*mem_ctx
,
9960 struct spoolss_PortData1
*port1
,
9961 const DATA_BLOB
*buf
)
9963 enum ndr_err_code ndr_err
;
9964 ndr_err
= ndr_pull_struct_blob(buf
, mem_ctx
, port1
,
9965 (ndr_pull_flags_fn_t
)ndr_pull_spoolss_PortData1
);
9966 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err
) && (DEBUGLEVEL
>= 10)) {
9967 NDR_PRINT_DEBUG(spoolss_PortData1
, port1
);
9969 return NDR_ERR_CODE_IS_SUCCESS(ndr_err
);
9972 /*******************************************************************
9973 ********************************************************************/
9975 static bool pull_port_data_2(TALLOC_CTX
*mem_ctx
,
9976 struct spoolss_PortData2
*port2
,
9977 const DATA_BLOB
*buf
)
9979 enum ndr_err_code ndr_err
;
9980 ndr_err
= ndr_pull_struct_blob(buf
, mem_ctx
, port2
,
9981 (ndr_pull_flags_fn_t
)ndr_pull_spoolss_PortData2
);
9982 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err
) && (DEBUGLEVEL
>= 10)) {
9983 NDR_PRINT_DEBUG(spoolss_PortData2
, port2
);
9985 return NDR_ERR_CODE_IS_SUCCESS(ndr_err
);
9988 /*******************************************************************
9989 Create a new TCP/IP port
9990 *******************************************************************/
9992 static WERROR
xcvtcp_addport(TALLOC_CTX
*mem_ctx
,
9993 struct security_token
*token
, DATA_BLOB
*in
,
9994 DATA_BLOB
*out
, uint32_t *needed
)
9996 struct spoolss_PortData1 port1
;
9997 struct spoolss_PortData2 port2
;
9998 char *device_uri
= NULL
;
10001 const char *portname
;
10002 const char *hostaddress
;
10004 uint32_t port_number
;
10007 /* peek for spoolss_PortData version */
10009 if (!in
|| (in
->length
< (128 + 4))) {
10010 return WERR_GENERAL_FAILURE
;
10013 version
= IVAL(in
->data
, 128);
10017 ZERO_STRUCT(port1
);
10019 if (!pull_port_data_1(mem_ctx
, &port1
, in
)) {
10023 portname
= port1
.portname
;
10024 hostaddress
= port1
.hostaddress
;
10025 queue
= port1
.queue
;
10026 protocol
= port1
.protocol
;
10027 port_number
= port1
.port_number
;
10031 ZERO_STRUCT(port2
);
10033 if (!pull_port_data_2(mem_ctx
, &port2
, in
)) {
10037 portname
= port2
.portname
;
10038 hostaddress
= port2
.hostaddress
;
10039 queue
= port2
.queue
;
10040 protocol
= port2
.protocol
;
10041 port_number
= port2
.port_number
;
10045 DEBUG(1,("xcvtcp_addport: "
10046 "unknown version of port_data: %d\n", version
));
10047 return WERR_UNKNOWN_PORT
;
10050 /* create the device URI and call the add_port_hook() */
10052 switch (protocol
) {
10053 case PROTOCOL_RAWTCP_TYPE
:
10054 device_uri
= talloc_asprintf(mem_ctx
,
10055 "socket://%s:%d/", hostaddress
,
10059 case PROTOCOL_LPR_TYPE
:
10060 device_uri
= talloc_asprintf(mem_ctx
,
10061 "lpr://%s/%s", hostaddress
, queue
);
10065 return WERR_UNKNOWN_PORT
;
10072 return add_port_hook(mem_ctx
, token
, portname
, device_uri
);
10075 /*******************************************************************
10076 *******************************************************************/
10078 struct xcv_api_table xcvtcp_cmds
[] = {
10079 { "MonitorUI", xcvtcp_monitorui
},
10080 { "AddPort", xcvtcp_addport
},
10084 static WERROR
process_xcvtcp_command(TALLOC_CTX
*mem_ctx
,
10085 struct security_token
*token
, const char *command
,
10092 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command
));
10094 for ( i
=0; xcvtcp_cmds
[i
].name
; i
++ ) {
10095 if ( strcmp( command
, xcvtcp_cmds
[i
].name
) == 0 )
10096 return xcvtcp_cmds
[i
].fn(mem_ctx
, token
, inbuf
, outbuf
, needed
);
10099 return WERR_BADFUNC
;
10102 /*******************************************************************
10103 *******************************************************************/
10104 #if 0 /* don't support management using the "Local Port" monitor */
10106 static WERROR
xcvlocal_monitorui(TALLOC_CTX
*mem_ctx
,
10107 struct security_token
*token
, DATA_BLOB
*in
,
10108 DATA_BLOB
*out
, uint32_t *needed
)
10110 const char *dllname
= "localui.dll";
10112 *needed
= (strlen(dllname
)+1) * 2;
10114 if (out
->length
< *needed
) {
10115 return WERR_INSUFFICIENT_BUFFER
;
10118 if (!push_monitorui_buf(mem_ctx
, out
, dllname
)) {
10125 /*******************************************************************
10126 *******************************************************************/
10128 struct xcv_api_table xcvlocal_cmds
[] = {
10129 { "MonitorUI", xcvlocal_monitorui
},
10133 struct xcv_api_table xcvlocal_cmds
[] = {
10140 /*******************************************************************
10141 *******************************************************************/
10143 static WERROR
process_xcvlocal_command(TALLOC_CTX
*mem_ctx
,
10144 struct security_token
*token
, const char *command
,
10145 DATA_BLOB
*inbuf
, DATA_BLOB
*outbuf
,
10150 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command
));
10152 for ( i
=0; xcvlocal_cmds
[i
].name
; i
++ ) {
10153 if ( strcmp( command
, xcvlocal_cmds
[i
].name
) == 0 )
10154 return xcvlocal_cmds
[i
].fn(mem_ctx
, token
, inbuf
, outbuf
, needed
);
10156 return WERR_BADFUNC
;
10159 /****************************************************************
10161 ****************************************************************/
10163 WERROR
_spoolss_XcvData(struct pipes_struct
*p
,
10164 struct spoolss_XcvData
*r
)
10166 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
10167 DATA_BLOB out_data
= data_blob_null
;
10171 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
10172 OUR_HANDLE(r
->in
.handle
)));
10173 return WERR_BADFID
;
10176 /* Has to be a handle to the TCP/IP port monitor */
10178 if ( !(Printer
->printer_type
& (SPLHND_PORTMON_LOCAL
|SPLHND_PORTMON_TCP
)) ) {
10179 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
10180 return WERR_BADFID
;
10183 /* requires administrative access to the server */
10185 if ( !(Printer
->access_granted
& SERVER_ACCESS_ADMINISTER
) ) {
10186 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
10187 return WERR_ACCESS_DENIED
;
10190 /* Allocate the outgoing buffer */
10192 if (r
->in
.out_data_size
) {
10193 out_data
= data_blob_talloc_zero(p
->mem_ctx
, r
->in
.out_data_size
);
10194 if (out_data
.data
== NULL
) {
10199 switch ( Printer
->printer_type
) {
10200 case SPLHND_PORTMON_TCP
:
10201 werror
= process_xcvtcp_command(p
->mem_ctx
,
10202 p
->session_info
->security_token
,
10203 r
->in
.function_name
,
10204 &r
->in
.in_data
, &out_data
,
10207 case SPLHND_PORTMON_LOCAL
:
10208 werror
= process_xcvlocal_command(p
->mem_ctx
,
10209 p
->session_info
->security_token
,
10210 r
->in
.function_name
,
10211 &r
->in
.in_data
, &out_data
,
10215 werror
= WERR_INVALID_PRINT_MONITOR
;
10218 if (!W_ERROR_IS_OK(werror
)) {
10222 *r
->out
.status_code
= 0;
10224 if (r
->out
.out_data
&& out_data
.data
&& r
->in
.out_data_size
&& out_data
.length
) {
10225 memcpy(r
->out
.out_data
, out_data
.data
,
10226 MIN(r
->in
.out_data_size
, out_data
.length
));
10232 /****************************************************************
10233 _spoolss_AddPrintProcessor
10234 ****************************************************************/
10236 WERROR
_spoolss_AddPrintProcessor(struct pipes_struct
*p
,
10237 struct spoolss_AddPrintProcessor
*r
)
10239 /* for now, just indicate success and ignore the add. We'll
10240 automatically set the winprint processor for printer
10241 entries later. Used to debug the LexMark Optra S 1855 PCL
10247 /****************************************************************
10249 ****************************************************************/
10251 WERROR
_spoolss_AddPort(struct pipes_struct
*p
,
10252 struct spoolss_AddPort
*r
)
10254 /* do what w2k3 does */
10256 return WERR_NOT_SUPPORTED
;
10259 /****************************************************************
10260 _spoolss_GetPrinterDriver
10261 ****************************************************************/
10263 WERROR
_spoolss_GetPrinterDriver(struct pipes_struct
*p
,
10264 struct spoolss_GetPrinterDriver
*r
)
10266 p
->rng_fault_state
= true;
10267 return WERR_NOT_SUPPORTED
;
10270 /****************************************************************
10271 _spoolss_ReadPrinter
10272 ****************************************************************/
10274 WERROR
_spoolss_ReadPrinter(struct pipes_struct
*p
,
10275 struct spoolss_ReadPrinter
*r
)
10277 p
->rng_fault_state
= true;
10278 return WERR_NOT_SUPPORTED
;
10281 /****************************************************************
10282 _spoolss_WaitForPrinterChange
10283 ****************************************************************/
10285 WERROR
_spoolss_WaitForPrinterChange(struct pipes_struct
*p
,
10286 struct spoolss_WaitForPrinterChange
*r
)
10288 p
->rng_fault_state
= true;
10289 return WERR_NOT_SUPPORTED
;
10292 /****************************************************************
10293 _spoolss_ConfigurePort
10294 ****************************************************************/
10296 WERROR
_spoolss_ConfigurePort(struct pipes_struct
*p
,
10297 struct spoolss_ConfigurePort
*r
)
10299 p
->rng_fault_state
= true;
10300 return WERR_NOT_SUPPORTED
;
10303 /****************************************************************
10304 _spoolss_DeletePort
10305 ****************************************************************/
10307 WERROR
_spoolss_DeletePort(struct pipes_struct
*p
,
10308 struct spoolss_DeletePort
*r
)
10310 p
->rng_fault_state
= true;
10311 return WERR_NOT_SUPPORTED
;
10314 /****************************************************************
10315 _spoolss_CreatePrinterIC
10316 ****************************************************************/
10318 WERROR
_spoolss_CreatePrinterIC(struct pipes_struct
*p
,
10319 struct spoolss_CreatePrinterIC
*r
)
10321 p
->rng_fault_state
= true;
10322 return WERR_NOT_SUPPORTED
;
10325 /****************************************************************
10326 _spoolss_PlayGDIScriptOnPrinterIC
10327 ****************************************************************/
10329 WERROR
_spoolss_PlayGDIScriptOnPrinterIC(struct pipes_struct
*p
,
10330 struct spoolss_PlayGDIScriptOnPrinterIC
*r
)
10332 p
->rng_fault_state
= true;
10333 return WERR_NOT_SUPPORTED
;
10336 /****************************************************************
10337 _spoolss_DeletePrinterIC
10338 ****************************************************************/
10340 WERROR
_spoolss_DeletePrinterIC(struct pipes_struct
*p
,
10341 struct spoolss_DeletePrinterIC
*r
)
10343 p
->rng_fault_state
= true;
10344 return WERR_NOT_SUPPORTED
;
10347 /****************************************************************
10348 _spoolss_AddPrinterConnection
10349 ****************************************************************/
10351 WERROR
_spoolss_AddPrinterConnection(struct pipes_struct
*p
,
10352 struct spoolss_AddPrinterConnection
*r
)
10354 p
->rng_fault_state
= true;
10355 return WERR_NOT_SUPPORTED
;
10358 /****************************************************************
10359 _spoolss_DeletePrinterConnection
10360 ****************************************************************/
10362 WERROR
_spoolss_DeletePrinterConnection(struct pipes_struct
*p
,
10363 struct spoolss_DeletePrinterConnection
*r
)
10365 p
->rng_fault_state
= true;
10366 return WERR_NOT_SUPPORTED
;
10369 /****************************************************************
10370 _spoolss_PrinterMessageBox
10371 ****************************************************************/
10373 WERROR
_spoolss_PrinterMessageBox(struct pipes_struct
*p
,
10374 struct spoolss_PrinterMessageBox
*r
)
10376 p
->rng_fault_state
= true;
10377 return WERR_NOT_SUPPORTED
;
10380 /****************************************************************
10381 _spoolss_AddMonitor
10382 ****************************************************************/
10384 WERROR
_spoolss_AddMonitor(struct pipes_struct
*p
,
10385 struct spoolss_AddMonitor
*r
)
10387 p
->rng_fault_state
= true;
10388 return WERR_NOT_SUPPORTED
;
10391 /****************************************************************
10392 _spoolss_DeleteMonitor
10393 ****************************************************************/
10395 WERROR
_spoolss_DeleteMonitor(struct pipes_struct
*p
,
10396 struct spoolss_DeleteMonitor
*r
)
10398 p
->rng_fault_state
= true;
10399 return WERR_NOT_SUPPORTED
;
10402 /****************************************************************
10403 _spoolss_DeletePrintProcessor
10404 ****************************************************************/
10406 WERROR
_spoolss_DeletePrintProcessor(struct pipes_struct
*p
,
10407 struct spoolss_DeletePrintProcessor
*r
)
10409 p
->rng_fault_state
= true;
10410 return WERR_NOT_SUPPORTED
;
10413 /****************************************************************
10414 _spoolss_AddPrintProvidor
10415 ****************************************************************/
10417 WERROR
_spoolss_AddPrintProvidor(struct pipes_struct
*p
,
10418 struct spoolss_AddPrintProvidor
*r
)
10420 p
->rng_fault_state
= true;
10421 return WERR_NOT_SUPPORTED
;
10424 /****************************************************************
10425 _spoolss_DeletePrintProvidor
10426 ****************************************************************/
10428 WERROR
_spoolss_DeletePrintProvidor(struct pipes_struct
*p
,
10429 struct spoolss_DeletePrintProvidor
*r
)
10431 p
->rng_fault_state
= true;
10432 return WERR_NOT_SUPPORTED
;
10435 /****************************************************************
10436 _spoolss_FindFirstPrinterChangeNotification
10437 ****************************************************************/
10439 WERROR
_spoolss_FindFirstPrinterChangeNotification(struct pipes_struct
*p
,
10440 struct spoolss_FindFirstPrinterChangeNotification
*r
)
10442 p
->rng_fault_state
= true;
10443 return WERR_NOT_SUPPORTED
;
10446 /****************************************************************
10447 _spoolss_FindNextPrinterChangeNotification
10448 ****************************************************************/
10450 WERROR
_spoolss_FindNextPrinterChangeNotification(struct pipes_struct
*p
,
10451 struct spoolss_FindNextPrinterChangeNotification
*r
)
10453 p
->rng_fault_state
= true;
10454 return WERR_NOT_SUPPORTED
;
10457 /****************************************************************
10458 _spoolss_RouterFindFirstPrinterChangeNotificationOld
10459 ****************************************************************/
10461 WERROR
_spoolss_RouterFindFirstPrinterChangeNotificationOld(struct pipes_struct
*p
,
10462 struct spoolss_RouterFindFirstPrinterChangeNotificationOld
*r
)
10464 p
->rng_fault_state
= true;
10465 return WERR_NOT_SUPPORTED
;
10468 /****************************************************************
10469 _spoolss_ReplyOpenPrinter
10470 ****************************************************************/
10472 WERROR
_spoolss_ReplyOpenPrinter(struct pipes_struct
*p
,
10473 struct spoolss_ReplyOpenPrinter
*r
)
10475 p
->rng_fault_state
= true;
10476 return WERR_NOT_SUPPORTED
;
10479 /****************************************************************
10480 _spoolss_RouterReplyPrinter
10481 ****************************************************************/
10483 WERROR
_spoolss_RouterReplyPrinter(struct pipes_struct
*p
,
10484 struct spoolss_RouterReplyPrinter
*r
)
10486 p
->rng_fault_state
= true;
10487 return WERR_NOT_SUPPORTED
;
10490 /****************************************************************
10491 _spoolss_ReplyClosePrinter
10492 ****************************************************************/
10494 WERROR
_spoolss_ReplyClosePrinter(struct pipes_struct
*p
,
10495 struct spoolss_ReplyClosePrinter
*r
)
10497 p
->rng_fault_state
= true;
10498 return WERR_NOT_SUPPORTED
;
10501 /****************************************************************
10503 ****************************************************************/
10505 WERROR
_spoolss_AddPortEx(struct pipes_struct
*p
,
10506 struct spoolss_AddPortEx
*r
)
10508 p
->rng_fault_state
= true;
10509 return WERR_NOT_SUPPORTED
;
10512 /****************************************************************
10513 _spoolss_RouterFindFirstPrinterChangeNotification
10514 ****************************************************************/
10516 WERROR
_spoolss_RouterFindFirstPrinterChangeNotification(struct pipes_struct
*p
,
10517 struct spoolss_RouterFindFirstPrinterChangeNotification
*r
)
10519 p
->rng_fault_state
= true;
10520 return WERR_NOT_SUPPORTED
;
10523 /****************************************************************
10524 _spoolss_SpoolerInit
10525 ****************************************************************/
10527 WERROR
_spoolss_SpoolerInit(struct pipes_struct
*p
,
10528 struct spoolss_SpoolerInit
*r
)
10530 p
->rng_fault_state
= true;
10531 return WERR_NOT_SUPPORTED
;
10534 /****************************************************************
10535 _spoolss_ResetPrinterEx
10536 ****************************************************************/
10538 WERROR
_spoolss_ResetPrinterEx(struct pipes_struct
*p
,
10539 struct spoolss_ResetPrinterEx
*r
)
10541 p
->rng_fault_state
= true;
10542 return WERR_NOT_SUPPORTED
;
10545 /****************************************************************
10546 _spoolss_RouterReplyPrinterEx
10547 ****************************************************************/
10549 WERROR
_spoolss_RouterReplyPrinterEx(struct pipes_struct
*p
,
10550 struct spoolss_RouterReplyPrinterEx
*r
)
10552 p
->rng_fault_state
= true;
10553 return WERR_NOT_SUPPORTED
;
10556 /****************************************************************
10558 ****************************************************************/
10560 WERROR
_spoolss_44(struct pipes_struct
*p
,
10561 struct spoolss_44
*r
)
10563 p
->rng_fault_state
= true;
10564 return WERR_NOT_SUPPORTED
;
10567 /****************************************************************
10569 ****************************************************************/
10571 WERROR
_spoolss_SetPort(struct pipes_struct
*p
,
10572 struct spoolss_SetPort
*r
)
10574 p
->rng_fault_state
= true;
10575 return WERR_NOT_SUPPORTED
;
10578 /****************************************************************
10580 ****************************************************************/
10582 WERROR
_spoolss_4a(struct pipes_struct
*p
,
10583 struct spoolss_4a
*r
)
10585 p
->rng_fault_state
= true;
10586 return WERR_NOT_SUPPORTED
;
10589 /****************************************************************
10591 ****************************************************************/
10593 WERROR
_spoolss_4b(struct pipes_struct
*p
,
10594 struct spoolss_4b
*r
)
10596 p
->rng_fault_state
= true;
10597 return WERR_NOT_SUPPORTED
;
10600 /****************************************************************
10602 ****************************************************************/
10604 WERROR
_spoolss_4c(struct pipes_struct
*p
,
10605 struct spoolss_4c
*r
)
10607 p
->rng_fault_state
= true;
10608 return WERR_NOT_SUPPORTED
;
10611 /****************************************************************
10613 ****************************************************************/
10615 WERROR
_spoolss_53(struct pipes_struct
*p
,
10616 struct spoolss_53
*r
)
10618 p
->rng_fault_state
= true;
10619 return WERR_NOT_SUPPORTED
;
10622 /****************************************************************
10623 _spoolss_AddPerMachineConnection
10624 ****************************************************************/
10626 WERROR
_spoolss_AddPerMachineConnection(struct pipes_struct
*p
,
10627 struct spoolss_AddPerMachineConnection
*r
)
10629 p
->rng_fault_state
= true;
10630 return WERR_NOT_SUPPORTED
;
10633 /****************************************************************
10634 _spoolss_DeletePerMachineConnection
10635 ****************************************************************/
10637 WERROR
_spoolss_DeletePerMachineConnection(struct pipes_struct
*p
,
10638 struct spoolss_DeletePerMachineConnection
*r
)
10640 p
->rng_fault_state
= true;
10641 return WERR_NOT_SUPPORTED
;
10644 /****************************************************************
10645 _spoolss_EnumPerMachineConnections
10646 ****************************************************************/
10648 WERROR
_spoolss_EnumPerMachineConnections(struct pipes_struct
*p
,
10649 struct spoolss_EnumPerMachineConnections
*r
)
10651 p
->rng_fault_state
= true;
10652 return WERR_NOT_SUPPORTED
;
10655 /****************************************************************
10657 ****************************************************************/
10659 WERROR
_spoolss_5a(struct pipes_struct
*p
,
10660 struct spoolss_5a
*r
)
10662 p
->rng_fault_state
= true;
10663 return WERR_NOT_SUPPORTED
;
10666 /****************************************************************
10668 ****************************************************************/
10670 WERROR
_spoolss_5b(struct pipes_struct
*p
,
10671 struct spoolss_5b
*r
)
10673 p
->rng_fault_state
= true;
10674 return WERR_NOT_SUPPORTED
;
10677 /****************************************************************
10679 ****************************************************************/
10681 WERROR
_spoolss_5c(struct pipes_struct
*p
,
10682 struct spoolss_5c
*r
)
10684 p
->rng_fault_state
= true;
10685 return WERR_NOT_SUPPORTED
;
10688 /****************************************************************
10690 ****************************************************************/
10692 WERROR
_spoolss_5d(struct pipes_struct
*p
,
10693 struct spoolss_5d
*r
)
10695 p
->rng_fault_state
= true;
10696 return WERR_NOT_SUPPORTED
;
10699 /****************************************************************
10701 ****************************************************************/
10703 WERROR
_spoolss_5e(struct pipes_struct
*p
,
10704 struct spoolss_5e
*r
)
10706 p
->rng_fault_state
= true;
10707 return WERR_NOT_SUPPORTED
;
10710 /****************************************************************
10712 ****************************************************************/
10714 WERROR
_spoolss_5f(struct pipes_struct
*p
,
10715 struct spoolss_5f
*r
)
10717 p
->rng_fault_state
= true;
10718 return WERR_NOT_SUPPORTED
;
10721 /****************************************************************
10723 ****************************************************************/
10725 WERROR
_spoolss_60(struct pipes_struct
*p
,
10726 struct spoolss_60
*r
)
10728 p
->rng_fault_state
= true;
10729 return WERR_NOT_SUPPORTED
;
10732 /****************************************************************
10734 ****************************************************************/
10736 WERROR
_spoolss_61(struct pipes_struct
*p
,
10737 struct spoolss_61
*r
)
10739 p
->rng_fault_state
= true;
10740 return WERR_NOT_SUPPORTED
;
10743 /****************************************************************
10745 ****************************************************************/
10747 WERROR
_spoolss_62(struct pipes_struct
*p
,
10748 struct spoolss_62
*r
)
10750 p
->rng_fault_state
= true;
10751 return WERR_NOT_SUPPORTED
;
10754 /****************************************************************
10756 ****************************************************************/
10758 WERROR
_spoolss_63(struct pipes_struct
*p
,
10759 struct spoolss_63
*r
)
10761 p
->rng_fault_state
= true;
10762 return WERR_NOT_SUPPORTED
;
10765 /****************************************************************
10767 ****************************************************************/
10769 WERROR
_spoolss_64(struct pipes_struct
*p
,
10770 struct spoolss_64
*r
)
10772 p
->rng_fault_state
= true;
10773 return WERR_NOT_SUPPORTED
;
10776 /****************************************************************
10778 ****************************************************************/
10780 WERROR
_spoolss_65(struct pipes_struct
*p
,
10781 struct spoolss_65
*r
)
10783 p
->rng_fault_state
= true;
10784 return WERR_NOT_SUPPORTED
;
10787 /****************************************************************
10788 _spoolss_GetCorePrinterDrivers
10789 ****************************************************************/
10791 WERROR
_spoolss_GetCorePrinterDrivers(struct pipes_struct
*p
,
10792 struct spoolss_GetCorePrinterDrivers
*r
)
10794 p
->rng_fault_state
= true;
10795 return WERR_NOT_SUPPORTED
;
10798 /****************************************************************
10800 ****************************************************************/
10802 WERROR
_spoolss_67(struct pipes_struct
*p
,
10803 struct spoolss_67
*r
)
10805 p
->rng_fault_state
= true;
10806 return WERR_NOT_SUPPORTED
;
10809 /****************************************************************
10810 _spoolss_GetPrinterDriverPackagePath
10811 ****************************************************************/
10813 WERROR
_spoolss_GetPrinterDriverPackagePath(struct pipes_struct
*p
,
10814 struct spoolss_GetPrinterDriverPackagePath
*r
)
10816 p
->rng_fault_state
= true;
10817 return WERR_NOT_SUPPORTED
;
10820 /****************************************************************
10822 ****************************************************************/
10824 WERROR
_spoolss_69(struct pipes_struct
*p
,
10825 struct spoolss_69
*r
)
10827 p
->rng_fault_state
= true;
10828 return WERR_NOT_SUPPORTED
;
10831 /****************************************************************
10833 ****************************************************************/
10835 WERROR
_spoolss_6a(struct pipes_struct
*p
,
10836 struct spoolss_6a
*r
)
10838 p
->rng_fault_state
= true;
10839 return WERR_NOT_SUPPORTED
;
10842 /****************************************************************
10844 ****************************************************************/
10846 WERROR
_spoolss_6b(struct pipes_struct
*p
,
10847 struct spoolss_6b
*r
)
10849 p
->rng_fault_state
= true;
10850 return WERR_NOT_SUPPORTED
;
10853 /****************************************************************
10855 ****************************************************************/
10857 WERROR
_spoolss_6c(struct pipes_struct
*p
,
10858 struct spoolss_6c
*r
)
10860 p
->rng_fault_state
= true;
10861 return WERR_NOT_SUPPORTED
;
10864 /****************************************************************
10866 ****************************************************************/
10868 WERROR
_spoolss_6d(struct pipes_struct
*p
,
10869 struct spoolss_6d
*r
)
10871 p
->rng_fault_state
= true;
10872 return WERR_NOT_SUPPORTED
;