2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-2000,
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
6 * Copyright (C) Jean François Micouleau 1998-2000,
7 * Copyright (C) Jeremy Allison 2001-2002,
8 * Copyright (C) Gerald Carter 2000-2004,
9 * Copyright (C) Tim Potter 2001-2002.
10 * Copyright (C) Guenther Deschner 2009-2010.
11 * Copyright (C) Andreas Schneider 2010.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 /* Since the SPOOLSS rpc routines are basically DOS 16-bit calls wrapped
28 up, all the errors returned are DOS errors, not NT status codes. */
31 #include "libsmb/namequery.h"
33 #include "nt_printing.h"
34 #include "srv_spoolss_util.h"
35 #include "librpc/gen_ndr/ndr_spoolss.h"
36 #include "librpc/gen_ndr/ndr_spoolss_scompat.h"
37 #include "../librpc/gen_ndr/ndr_spoolss_c.h"
38 #include "rpc_client/init_spoolss.h"
39 #include "rpc_client/cli_pipe.h"
40 #include "../libcli/security/security.h"
41 #include "librpc/gen_ndr/ndr_security.h"
43 #include "include/printing.h"
45 #include "../librpc/gen_ndr/netlogon.h"
47 #include "printing/notify.h"
49 #include "../libcli/registry/util_reg.h"
50 #include "smbd/smbd.h"
51 #include "smbd/globals.h"
54 #include "rpc_server/spoolss/srv_spoolss_nt.h"
56 #include "libsmb/libsmb.h"
57 #include "printing/printer_list.h"
58 #include "../lib/tsocket/tsocket.h"
59 #include "rpc_client/cli_winreg_spoolss.h"
60 #include "../libcli/smb/smbXcli_base.h"
61 #include "rpc_server/spoolss/srv_spoolss_handle.h"
62 #include "lib/gencache.h"
63 #include "rpc_server/rpc_server.h"
64 #include "librpc/rpc/dcesrv_core.h"
65 #include "printing/nt_printing_migrate_internal.h"
66 #include "lib/util/string_wrappers.h"
68 /* macros stolen from s4 spoolss server */
69 #define SPOOLSS_BUFFER_UNION(fn,info,level) \
70 ((info)?ndr_size_##fn(info, level, 0):0)
72 #define SPOOLSS_BUFFER_UNION_ARRAY(mem_ctx,fn,info,level,count) \
73 ((info)?ndr_size_##fn##_info(mem_ctx, level, count, info):0)
75 #define SPOOLSS_BUFFER_ARRAY(mem_ctx,fn,info,count) \
76 ((info)?ndr_size_##fn##_info(mem_ctx, count, info):0)
78 #define SPOOLSS_BUFFER_OK(val_true,val_false) ((r->in.offered >= *r->out.needed)?val_true:val_false)
81 #define DBGC_CLASS DBGC_RPC_SRV
83 #ifndef MAX_OPEN_PRINTER_EXS
84 #define MAX_OPEN_PRINTER_EXS 50
87 #define GLOBAL_SPOOLSS_OS_MAJOR_DEFAULT 5
88 #define GLOBAL_SPOOLSS_OS_MINOR_DEFAULT 2
89 #define GLOBAL_SPOOLSS_OS_BUILD_DEFAULT 3790
90 #define GLOBAL_SPOOLSS_ARCHITECTURE SPOOLSS_ARCHITECTURE_x64
92 static struct printer_handle
*printers_list
;
94 struct printer_session_counter
{
95 struct printer_session_counter
*next
;
96 struct printer_session_counter
*prev
;
102 static struct printer_session_counter
*counter_list
;
104 struct notify_back_channel
{
105 struct notify_back_channel
*prev
, *next
;
107 /* associated client */
108 struct sockaddr_storage client_address
;
110 /* print notify back-channel pipe handle*/
111 struct rpc_pipe_client
*cli_pipe
;
112 struct cli_state
*cli
;
113 uint32_t active_connections
;
116 static struct notify_back_channel
*back_channels
;
118 /* Map generic permissions to printer object specific permissions */
120 const struct standard_mapping printer_std_mapping
= {
127 /* Map generic permissions to print server object specific permissions */
129 const struct standard_mapping printserver_std_mapping
= {
136 /* API table for Xcv Monitor functions */
138 struct xcv_api_table
{
140 WERROR(*fn
) (TALLOC_CTX
*mem_ctx
, struct security_token
*token
, DATA_BLOB
*in
, DATA_BLOB
*out
, uint32_t *needed
);
143 static void prune_printername_cache(void);
145 /********************************************************************
146 * Canonicalize servername.
147 ********************************************************************/
149 static const char *canon_servername(const char *servername
)
151 const char *pservername
= servername
;
153 if (servername
== NULL
) {
157 while (*pservername
== '\\') {
163 /* translate between internal status numbers and NT status numbers */
164 static int nt_printj_status(int v
)
170 return JOB_STATUS_PAUSED
;
172 return JOB_STATUS_SPOOLING
;
174 return JOB_STATUS_PRINTING
;
176 return JOB_STATUS_ERROR
;
178 return JOB_STATUS_DELETING
;
180 return JOB_STATUS_OFFLINE
;
182 return JOB_STATUS_PAPEROUT
;
184 return JOB_STATUS_PRINTED
;
186 return JOB_STATUS_DELETED
;
188 return JOB_STATUS_BLOCKED_DEVQ
;
189 case LPQ_USER_INTERVENTION
:
190 return JOB_STATUS_USER_INTERVENTION
;
195 static int nt_printq_status(int v
)
199 return PRINTER_STATUS_PAUSED
;
208 /***************************************************************************
209 Disconnect from the client
210 ****************************************************************************/
212 static void srv_spoolss_replycloseprinter(int snum
,
213 struct printer_handle
*prn_hnd
)
219 * Tell the specific printing tdb we no longer want messages for this printer
220 * by deregistering our PID.
223 if (!print_notify_deregister_pid(snum
)) {
224 DEBUG(0, ("Failed to register our pid for printer %s\n",
225 lp_const_servicename(snum
)));
228 /* weird if the test succeeds !!! */
229 if (prn_hnd
->notify
.cli_chan
== NULL
||
230 prn_hnd
->notify
.cli_chan
->cli_pipe
== NULL
||
231 prn_hnd
->notify
.cli_chan
->cli_pipe
->binding_handle
== NULL
||
232 prn_hnd
->notify
.cli_chan
->active_connections
== 0) {
233 DEBUG(0, ("Trying to close unexisting backchannel!\n"));
234 DLIST_REMOVE(back_channels
, prn_hnd
->notify
.cli_chan
);
235 TALLOC_FREE(prn_hnd
->notify
.cli_chan
);
239 status
= dcerpc_spoolss_ReplyClosePrinter(
240 prn_hnd
->notify
.cli_chan
->cli_pipe
->binding_handle
,
242 &prn_hnd
->notify
.cli_hnd
,
244 if (!NT_STATUS_IS_OK(status
)) {
245 DEBUG(0, ("dcerpc_spoolss_ReplyClosePrinter failed [%s].\n",
247 result
= ntstatus_to_werror(status
);
248 } else if (!W_ERROR_IS_OK(result
)) {
249 DEBUG(0, ("reply_close_printer failed [%s].\n",
250 win_errstr(result
)));
253 /* if it's the last connection, deconnect the IPC$ share */
254 if (prn_hnd
->notify
.cli_chan
->active_connections
== 1) {
256 cli_shutdown(prn_hnd
->notify
.cli_chan
->cli
);
257 DLIST_REMOVE(back_channels
, prn_hnd
->notify
.cli_chan
);
258 TALLOC_FREE(prn_hnd
->notify
.cli_chan
);
260 if (prn_hnd
->notify
.msg_ctx
!= NULL
) {
261 messaging_deregister(prn_hnd
->notify
.msg_ctx
,
262 MSG_PRINTER_NOTIFY2
, NULL
);
266 if (prn_hnd
->notify
.cli_chan
) {
267 prn_hnd
->notify
.cli_chan
->active_connections
--;
268 prn_hnd
->notify
.cli_chan
= NULL
;
272 /****************************************************************************
273 Functions to free a printer entry datastruct.
274 ****************************************************************************/
276 static int printer_entry_destructor(struct printer_handle
*Printer
)
278 if (Printer
->notify
.cli_chan
!= NULL
&&
279 Printer
->notify
.cli_chan
->active_connections
> 0) {
282 switch(Printer
->printer_type
) {
284 srv_spoolss_replycloseprinter(snum
, Printer
);
288 snum
= print_queue_snum(Printer
->sharename
);
290 srv_spoolss_replycloseprinter(snum
, Printer
);
298 Printer
->notify
.flags
=0;
299 Printer
->notify
.options
=0;
300 Printer
->notify
.localmachine
[0]='\0';
301 Printer
->notify
.printerlocal
=0;
302 TALLOC_FREE(Printer
->notify
.option
);
303 TALLOC_FREE(Printer
->devmode
);
305 /* Remove from the internal list. */
306 DLIST_REMOVE(printers_list
, Printer
);
310 /****************************************************************************
311 find printer index by handle
312 ****************************************************************************/
314 static struct printer_handle
*find_printer_index_by_hnd(struct pipes_struct
*p
,
315 struct policy_handle
*hnd
)
317 struct printer_handle
*find_printer
= NULL
;
320 find_printer
= find_policy_by_hnd(p
,
323 struct printer_handle
,
325 if (!NT_STATUS_IS_OK(status
)) {
326 DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: "));
333 /****************************************************************************
334 Close printer index by handle.
335 ****************************************************************************/
337 static bool close_printer_handle(struct pipes_struct
*p
, struct policy_handle
*hnd
)
339 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, hnd
);
342 DEBUG(2,("close_printer_handle: Invalid handle (%s:%u:%u)\n",
347 close_policy_hnd(p
, hnd
);
352 /****************************************************************************
353 Delete a printer given a handle.
354 ****************************************************************************/
356 static WERROR
delete_printer_hook(TALLOC_CTX
*ctx
, struct security_token
*token
,
357 const char *sharename
,
358 struct messaging_context
*msg_ctx
)
360 const struct loadparm_substitution
*lp_sub
=
361 loadparm_s3_global_substitution();
362 char *cmd
= lp_deleteprinter_command(talloc_tos(), lp_sub
);
363 char *command
= NULL
;
365 bool is_print_op
= false;
367 /* can't fail if we don't try */
372 command
= talloc_asprintf(ctx
,
376 return WERR_NOT_ENOUGH_MEMORY
;
379 is_print_op
= security_token_has_privilege(token
, SEC_PRIV_PRINT_OPERATOR
);
381 DEBUG(10,("Running [%s]\n", command
));
383 /********** BEGIN SePrintOperatorPrivlege BLOCK **********/
388 ret
= smbrun(command
, NULL
, NULL
);
390 /* Tell everyone we updated smb.conf. */
391 messaging_send_all(msg_ctx
, MSG_SMB_CONF_UPDATED
, NULL
, 0);
397 /********** END SePrintOperatorPrivlege BLOCK **********/
399 DEBUGADD(10,("returned [%d]\n", ret
));
401 TALLOC_FREE(command
);
404 return WERR_INVALID_HANDLE
; /* What to return here? */
409 /****************************************************************************
410 Delete a printer given a handle.
411 ****************************************************************************/
413 static WERROR
delete_printer_handle(struct pipes_struct
*p
, struct policy_handle
*hnd
)
415 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, hnd
);
419 DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n",
421 return WERR_INVALID_HANDLE
;
425 * It turns out that Windows allows delete printer on a handle
426 * opened by an admin user, then used on a pipe handle created
427 * by an anonymous user..... but they're working on security.... riiight !
431 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
432 DEBUG(3, ("delete_printer_handle: denied by handle\n"));
433 return WERR_ACCESS_DENIED
;
436 /* this does not need a become root since the access check has been
437 done on the handle already */
439 result
= winreg_delete_printer_key_internal(p
->mem_ctx
,
440 get_session_info_system(),
444 if (!W_ERROR_IS_OK(result
)) {
445 DEBUG(3,("Error deleting printer %s\n", Printer
->sharename
));
446 return WERR_INVALID_HANDLE
;
449 result
= delete_printer_hook(p
->mem_ctx
, p
->session_info
->security_token
,
450 Printer
->sharename
, p
->msg_ctx
);
451 if (!W_ERROR_IS_OK(result
)) {
454 prune_printername_cache();
458 /****************************************************************************
459 Return the snum of a printer corresponding to an handle.
460 ****************************************************************************/
462 static bool get_printer_snum(struct pipes_struct
*p
, struct policy_handle
*hnd
,
463 int *number
, struct share_params
**params
)
465 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, hnd
);
468 DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n",
473 switch (Printer
->printer_type
) {
475 DEBUG(4,("short name:%s\n", Printer
->sharename
));
476 *number
= print_queue_snum(Printer
->sharename
);
477 return (*number
!= -1);
485 /****************************************************************************
486 Set printer handle type.
487 Check if it's \\server or \\server\printer
488 ****************************************************************************/
490 static bool set_printer_hnd_printertype(struct printer_handle
*Printer
, const char *handlename
)
492 DEBUG(3,("Setting printer type=%s\n", handlename
));
494 /* it's a print server */
495 if (handlename
&& *handlename
=='\\' && *(handlename
+1)=='\\' && !strchr_m(handlename
+2, '\\')) {
496 DEBUGADD(4,("Printer is a print server\n"));
497 Printer
->printer_type
= SPLHND_SERVER
;
499 /* it's a printer (set_printer_hnd_name() will handle port monitors */
501 DEBUGADD(4,("Printer is a printer\n"));
502 Printer
->printer_type
= SPLHND_PRINTER
;
508 static void prune_printername_cache_fn(const char *key
, const char *value
,
509 time_t timeout
, void *private_data
)
514 static void prune_printername_cache(void)
516 gencache_iterate(prune_printername_cache_fn
, NULL
, "PRINTERNAME/*");
519 /****************************************************************************
520 Set printer handle name.. Accept names like \\server, \\server\printer,
521 \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
522 the MSDN docs regarding OpenPrinter() for details on the XcvData() and
523 XcvDataPort() interface.
524 ****************************************************************************/
526 static WERROR
set_printer_hnd_name(TALLOC_CTX
*mem_ctx
,
527 const struct auth_session_info
*session_info
,
528 struct messaging_context
*msg_ctx
,
529 struct printer_handle
*Printer
,
530 const char *handlename
)
533 int n_services
=lp_numservices();
535 const char *printername
;
536 const char *servername
= NULL
;
539 struct spoolss_PrinterInfo2
*info2
= NULL
;
544 * Hopefully nobody names his printers like this. Maybe \ or ,
545 * are illegal in printer names even?
547 const char printer_not_found
[] = "Printer \\, !@#$%^&*( not found";
551 DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename
,
552 (unsigned long)strlen(handlename
)));
554 aprinter
= discard_const_p(char, handlename
);
555 if ( *handlename
== '\\' ) {
556 servername
= canon_servername(handlename
);
557 if ( (aprinter
= strchr_m( servername
, '\\' )) != NULL
) {
561 if (!is_myname_or_ipaddr(servername
)) {
562 return WERR_INVALID_PRINTER_NAME
;
564 Printer
->servername
= talloc_asprintf(Printer
, "\\\\%s", servername
);
565 if (Printer
->servername
== NULL
) {
566 return WERR_NOT_ENOUGH_MEMORY
;
570 if (Printer
->printer_type
== SPLHND_SERVER
) {
574 if (Printer
->printer_type
!= SPLHND_PRINTER
) {
575 return WERR_INVALID_HANDLE
;
578 DEBUGADD(5, ("searching for [%s]\n", aprinter
));
580 p
= strchr(aprinter
, ',');
587 if (strncmp(p
, "DrvConvert", strlen("DrvConvert")) == 0) {
589 } else if (strncmp(p
, "LocalOnly", strlen("LocalOnly")) == 0) {
595 DEBUGADD(5, ("stripped handlename: [%s]\n", aprinter
));
598 /* check for the Port Monitor Interface */
599 if ( strequal( aprinter
, SPL_XCV_MONITOR_TCPMON
) ) {
600 Printer
->printer_type
= SPLHND_PORTMON_TCP
;
601 fstrcpy(sname
, SPL_XCV_MONITOR_TCPMON
);
604 else if ( strequal( aprinter
, SPL_XCV_MONITOR_LOCALMON
) ) {
605 Printer
->printer_type
= SPLHND_PORTMON_LOCAL
;
606 fstrcpy(sname
, SPL_XCV_MONITOR_LOCALMON
);
610 cache_key
= talloc_asprintf(talloc_tos(), "PRINTERNAME/%s", aprinter
);
611 if (cache_key
== NULL
) {
612 return WERR_NOT_ENOUGH_MEMORY
;
616 * With hundreds of printers, the "for" loop iterating all
617 * shares can be quite expensive, as it is done on every
618 * OpenPrinter. The loop maps "aprinter" to "sname", the
619 * result of which we cache in gencache.
621 if (gencache_get(cache_key
, talloc_tos(), &tmp
, NULL
)) {
622 found
= (strcmp(tmp
, printer_not_found
) != 0);
624 DEBUG(4, ("Printer %s not found\n", aprinter
));
626 return WERR_INVALID_PRINTER_NAME
;
632 /* Search all sharenames first as this is easier than pulling
633 the printer_info_2 off of disk. Don't use find_service() since
634 that calls out to map_username() */
636 /* do another loop to look for printernames */
637 for (snum
= 0; !found
&& snum
< n_services
; snum
++) {
638 const char *printer
= lp_const_servicename(snum
);
640 /* no point going on if this is not a printer */
641 if (!(lp_snum_ok(snum
) && lp_printable(snum
))) {
645 /* ignore [printers] share */
646 if (strequal(printer
, "printers")) {
650 fstrcpy(sname
, printer
);
651 if (strequal(aprinter
, printer
)) {
656 /* no point looking up the printer object if
657 we aren't allowing printername != sharename */
658 if (lp_force_printername(snum
)) {
662 result
= winreg_get_printer_internal(mem_ctx
,
667 if ( !W_ERROR_IS_OK(result
) ) {
668 DEBUG(2,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
669 sname
, win_errstr(result
)));
673 printername
= strrchr(info2
->printername
, '\\');
674 if (printername
== NULL
) {
675 printername
= info2
->printername
;
680 if (strequal(printername
, aprinter
)) {
685 DEBUGADD(10, ("printername: %s\n", printername
));
691 gencache_set(cache_key
, printer_not_found
,
693 TALLOC_FREE(cache_key
);
694 DEBUGADD(4,("Printer not found\n"));
695 return WERR_INVALID_PRINTER_NAME
;
698 gencache_set(cache_key
, sname
, time(NULL
) + 300);
699 TALLOC_FREE(cache_key
);
701 DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter
, sname
));
703 strlcpy(Printer
->sharename
, sname
, sizeof(Printer
->sharename
));
708 /****************************************************************************
709 Find first available printer slot. creates a printer handle for you.
710 ****************************************************************************/
712 static WERROR
open_printer_hnd(struct pipes_struct
*p
,
713 struct policy_handle
*hnd
,
715 uint32_t access_granted
)
717 struct printer_handle
*new_printer
;
720 DEBUG(10,("open_printer_hnd: name [%s]\n", name
));
722 new_printer
= talloc_zero(p
->mem_ctx
, struct printer_handle
);
723 if (new_printer
== NULL
) {
724 return WERR_NOT_ENOUGH_MEMORY
;
726 talloc_set_destructor(new_printer
, printer_entry_destructor
);
728 /* This also steals the printer_handle on the policy_handle */
729 if (!create_policy_hnd(p
, hnd
, 0, new_printer
)) {
730 TALLOC_FREE(new_printer
);
731 return WERR_INVALID_HANDLE
;
734 /* Add to the internal list. */
735 DLIST_ADD(printers_list
, new_printer
);
737 new_printer
->notify
.option
=NULL
;
739 if (!set_printer_hnd_printertype(new_printer
, name
)) {
740 close_printer_handle(p
, hnd
);
741 return WERR_INVALID_HANDLE
;
744 result
= set_printer_hnd_name(p
->mem_ctx
,
745 get_session_info_system(),
748 if (!W_ERROR_IS_OK(result
)) {
749 close_printer_handle(p
, hnd
);
753 new_printer
->access_granted
= access_granted
;
755 DBG_INFO("%d printer handles active\n", (int)num_pipe_handles());
760 /***************************************************************************
761 check to see if the client motify handle is monitoring the notification
762 given by (notify_type, notify_field).
763 **************************************************************************/
765 static bool is_monitoring_event_flags(uint32_t flags
, uint16_t notify_type
,
766 uint16_t notify_field
)
771 static bool is_monitoring_event(struct printer_handle
*p
, uint16_t notify_type
,
772 uint16_t notify_field
)
774 struct spoolss_NotifyOption
*option
= p
->notify
.option
;
778 * Flags should always be zero when the change notify
779 * is registered by the client's spooler. A user Win32 app
780 * might use the flags though instead of the NOTIFY_OPTION_INFO
789 return is_monitoring_event_flags(
790 p
->notify
.flags
, notify_type
, notify_field
);
792 for (i
= 0; i
< option
->count
; i
++) {
794 /* Check match for notify_type */
796 if (option
->types
[i
].type
!= notify_type
)
799 /* Check match for field */
801 for (j
= 0; j
< option
->types
[i
].count
; j
++) {
802 if (option
->types
[i
].fields
[j
].field
== notify_field
) {
808 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
809 p
->servername
, p
->sharename
, notify_type
, notify_field
));
814 #define SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(_data, _integer) \
815 _data->data.integer[0] = _integer; \
816 _data->data.integer[1] = 0;
819 #define SETUP_SPOOLSS_NOTIFY_DATA_STRING(_data, _p) \
820 _data->data.string.string = talloc_strdup(mem_ctx, _p); \
821 if (!_data->data.string.string) {\
822 _data->data.string.size = 0; \
824 _data->data.string.size = strlen_m_term(_p) * 2;
826 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
827 _data->data.devmode.devmode = _devmode;
829 static void init_systemtime_buffer(TALLOC_CTX
*mem_ctx
,
834 struct spoolss_Time st
;
838 if (!init_systemtime(&st
, t
)) {
842 p
= talloc_array(mem_ctx
, char, len
);
848 * Systemtime must be linearized as a set of UINT16's.
849 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
852 SSVAL(p
, 0, st
.year
);
853 SSVAL(p
, 2, st
.month
);
854 SSVAL(p
, 4, st
.day_of_week
);
856 SSVAL(p
, 8, st
.hour
);
857 SSVAL(p
, 10, st
.minute
);
858 SSVAL(p
, 12, st
.second
);
859 SSVAL(p
, 14, st
.millisecond
);
865 /* Convert a notification message to a struct spoolss_Notify */
867 static void notify_one_value(struct spoolss_notify_msg
*msg
,
868 struct spoolss_Notify
*data
,
871 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, msg
->notify
.value
[0]);
874 static void notify_string(struct spoolss_notify_msg
*msg
,
875 struct spoolss_Notify
*data
,
878 /* The length of the message includes the trailing \0 */
880 data
->data
.string
.size
= msg
->len
* 2;
881 data
->data
.string
.string
= talloc_strdup(mem_ctx
, msg
->notify
.data
);
882 if (!data
->data
.string
.string
) {
883 data
->data
.string
.size
= 0;
888 static void notify_system_time(struct spoolss_notify_msg
*msg
,
889 struct spoolss_Notify
*data
,
892 data
->data
.string
.string
= NULL
;
893 data
->data
.string
.size
= 0;
895 if (msg
->len
!= sizeof(time_t)) {
896 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
901 init_systemtime_buffer(mem_ctx
, gmtime((time_t *)msg
->notify
.data
),
902 &data
->data
.string
.string
,
903 &data
->data
.string
.size
);
906 struct notify2_message_table
{
908 void (*fn
)(struct spoolss_notify_msg
*msg
,
909 struct spoolss_Notify
*data
, TALLOC_CTX
*mem_ctx
);
912 static struct notify2_message_table printer_notify_table
[] = {
913 /* 0x00 */ { "PRINTER_NOTIFY_FIELD_SERVER_NAME", notify_string
},
914 /* 0x01 */ { "PRINTER_NOTIFY_FIELD_PRINTER_NAME", notify_string
},
915 /* 0x02 */ { "PRINTER_NOTIFY_FIELD_SHARE_NAME", notify_string
},
916 /* 0x03 */ { "PRINTER_NOTIFY_FIELD_PORT_NAME", notify_string
},
917 /* 0x04 */ { "PRINTER_NOTIFY_FIELD_DRIVER_NAME", notify_string
},
918 /* 0x05 */ { "PRINTER_NOTIFY_FIELD_COMMENT", notify_string
},
919 /* 0x06 */ { "PRINTER_NOTIFY_FIELD_LOCATION", notify_string
},
920 /* 0x07 */ { "PRINTER_NOTIFY_FIELD_DEVMODE", NULL
},
921 /* 0x08 */ { "PRINTER_NOTIFY_FIELD_SEPFILE", notify_string
},
922 /* 0x09 */ { "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", notify_string
},
923 /* 0x0a */ { "PRINTER_NOTIFY_FIELD_PARAMETERS", NULL
},
924 /* 0x0b */ { "PRINTER_NOTIFY_FIELD_DATATYPE", notify_string
},
925 /* 0x0c */ { "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL
},
926 /* 0x0d */ { "PRINTER_NOTIFY_FIELD_ATTRIBUTES", notify_one_value
},
927 /* 0x0e */ { "PRINTER_NOTIFY_FIELD_PRIORITY", notify_one_value
},
928 /* 0x0f */ { "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NULL
},
929 /* 0x10 */ { "PRINTER_NOTIFY_FIELD_START_TIME", NULL
},
930 /* 0x11 */ { "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NULL
},
931 /* 0x12 */ { "PRINTER_NOTIFY_FIELD_STATUS", notify_one_value
},
934 static struct notify2_message_table job_notify_table
[] = {
935 /* 0x00 */ { "JOB_NOTIFY_FIELD_PRINTER_NAME", NULL
},
936 /* 0x01 */ { "JOB_NOTIFY_FIELD_MACHINE_NAME", NULL
},
937 /* 0x02 */ { "JOB_NOTIFY_FIELD_PORT_NAME", NULL
},
938 /* 0x03 */ { "JOB_NOTIFY_FIELD_USER_NAME", notify_string
},
939 /* 0x04 */ { "JOB_NOTIFY_FIELD_NOTIFY_NAME", NULL
},
940 /* 0x05 */ { "JOB_NOTIFY_FIELD_DATATYPE", NULL
},
941 /* 0x06 */ { "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NULL
},
942 /* 0x07 */ { "JOB_NOTIFY_FIELD_PARAMETERS", NULL
},
943 /* 0x08 */ { "JOB_NOTIFY_FIELD_DRIVER_NAME", NULL
},
944 /* 0x09 */ { "JOB_NOTIFY_FIELD_DEVMODE", NULL
},
945 /* 0x0a */ { "JOB_NOTIFY_FIELD_STATUS", notify_one_value
},
946 /* 0x0b */ { "JOB_NOTIFY_FIELD_STATUS_STRING", NULL
},
947 /* 0x0c */ { "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL
},
948 /* 0x0d */ { "JOB_NOTIFY_FIELD_DOCUMENT", notify_string
},
949 /* 0x0e */ { "JOB_NOTIFY_FIELD_PRIORITY", NULL
},
950 /* 0x0f */ { "JOB_NOTIFY_FIELD_POSITION", NULL
},
951 /* 0x10 */ { "JOB_NOTIFY_FIELD_SUBMITTED", notify_system_time
},
952 /* 0x11 */ { "JOB_NOTIFY_FIELD_START_TIME", NULL
},
953 /* 0x12 */ { "JOB_NOTIFY_FIELD_UNTIL_TIME", NULL
},
954 /* 0x13 */ { "JOB_NOTIFY_FIELD_TIME", NULL
},
955 /* 0x14 */ { "JOB_NOTIFY_FIELD_TOTAL_PAGES", notify_one_value
},
956 /* 0x15 */ { "JOB_NOTIFY_FIELD_PAGES_PRINTED", NULL
},
957 /* 0x16 */ { "JOB_NOTIFY_FIELD_TOTAL_BYTES", notify_one_value
},
958 /* 0x17 */ { "JOB_NOTIFY_FIELD_BYTES_PRINTED", NULL
},
962 /***********************************************************************
963 Allocate talloc context for container object
964 **********************************************************************/
966 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR
*ctr
)
971 ctr
->ctx
= talloc_init("notify_msg_ctr_init %p", ctr
);
976 /***********************************************************************
977 release all allocated memory and zero out structure
978 **********************************************************************/
980 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR
*ctr
)
986 talloc_destroy(ctr
->ctx
);
993 /***********************************************************************
994 **********************************************************************/
996 static TALLOC_CTX
* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR
*ctr
)
1004 /***********************************************************************
1005 **********************************************************************/
1007 static SPOOLSS_NOTIFY_MSG_GROUP
* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR
*ctr
, uint32_t idx
)
1009 if ( !ctr
|| !ctr
->msg_groups
)
1012 if ( idx
>= ctr
->num_groups
)
1015 return &ctr
->msg_groups
[idx
];
1019 /***********************************************************************
1020 How many groups of change messages do we have ?
1021 **********************************************************************/
1023 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR
*ctr
)
1028 return ctr
->num_groups
;
1031 /***********************************************************************
1032 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
1033 **********************************************************************/
1035 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR
*ctr
, SPOOLSS_NOTIFY_MSG
*msg
)
1037 SPOOLSS_NOTIFY_MSG_GROUP
*groups
= NULL
;
1038 SPOOLSS_NOTIFY_MSG_GROUP
*msg_grp
= NULL
;
1039 SPOOLSS_NOTIFY_MSG
*msg_list
= NULL
;
1045 /* loop over all groups looking for a matching printer name */
1047 for ( i
=0; i
<ctr
->num_groups
; i
++ ) {
1048 if ( strcmp(ctr
->msg_groups
[i
].printername
, msg
->printer
) == 0 )
1052 /* add a new group? */
1054 if ( i
== ctr
->num_groups
) {
1057 if ( !(groups
= talloc_realloc( ctr
->ctx
, ctr
->msg_groups
, SPOOLSS_NOTIFY_MSG_GROUP
, ctr
->num_groups
)) ) {
1058 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
1061 ctr
->msg_groups
= groups
;
1063 /* clear the new entry and set the printer name */
1065 ZERO_STRUCT( ctr
->msg_groups
[ctr
->num_groups
-1] );
1066 fstrcpy( ctr
->msg_groups
[ctr
->num_groups
-1].printername
, msg
->printer
);
1069 /* add the change messages; 'i' is the correct index now regardless */
1071 msg_grp
= &ctr
->msg_groups
[i
];
1073 msg_grp
->num_msgs
++;
1075 if ( !(msg_list
= talloc_realloc( ctr
->ctx
, msg_grp
->msgs
, SPOOLSS_NOTIFY_MSG
, msg_grp
->num_msgs
)) ) {
1076 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp
->num_msgs
));
1079 msg_grp
->msgs
= msg_list
;
1081 new_slot
= msg_grp
->num_msgs
-1;
1082 memcpy( &msg_grp
->msgs
[new_slot
], msg
, sizeof(SPOOLSS_NOTIFY_MSG
) );
1084 /* need to allocate own copy of data */
1086 if ( msg
->len
!= 0 )
1087 msg_grp
->msgs
[new_slot
].notify
.data
= (char *)
1088 talloc_memdup( ctr
->ctx
, msg
->notify
.data
, msg
->len
);
1090 return ctr
->num_groups
;
1093 static void construct_info_data(struct spoolss_Notify
*info_data
,
1094 enum spoolss_NotifyType type
,
1095 uint16_t field
, int id
);
1097 /***********************************************************************
1098 Send a change notication message on all handles which have a call
1100 **********************************************************************/
1102 static int build_notify2_messages(TALLOC_CTX
*mem_ctx
,
1103 struct printer_handle
*prn_hnd
,
1104 SPOOLSS_NOTIFY_MSG
*messages
,
1106 struct spoolss_Notify
**_notifies
,
1109 struct spoolss_Notify
*notifies
;
1110 SPOOLSS_NOTIFY_MSG
*msg
;
1115 notifies
= talloc_zero_array(mem_ctx
,
1116 struct spoolss_Notify
, num_msgs
);
1121 for (i
= 0; i
< num_msgs
; i
++) {
1125 /* Are we monitoring this event? */
1127 if (!is_monitoring_event(prn_hnd
, msg
->type
, msg
->field
)) {
1131 DEBUG(10, ("Sending message type [0x%x] field [0x%2x] "
1132 "for printer [%s]\n",
1133 msg
->type
, msg
->field
, prn_hnd
->sharename
));
1136 * if the is a printer notification handle and not a job
1137 * notification type, then set the id to 0.
1138 * Otherwise just use what was specified in the message.
1140 * When registering change notification on a print server
1141 * handle we always need to send back the id (snum) matching
1142 * the printer for which the change took place.
1143 * For change notify registered on a printer handle,
1144 * this does not matter and the id should be 0.
1149 if ((msg
->type
== PRINTER_NOTIFY_TYPE
) &&
1150 (prn_hnd
->printer_type
== SPLHND_PRINTER
)) {
1156 /* Convert unix jobid to smb jobid */
1158 if (msg
->flags
& SPOOLSS_NOTIFY_MSG_UNIX_JOBID
) {
1159 id
= sysjob_to_jobid(msg
->id
);
1162 DEBUG(3, ("no such unix jobid %d\n",
1168 construct_info_data(¬ifies
[count
],
1169 msg
->type
, msg
->field
, id
);
1172 case PRINTER_NOTIFY_TYPE
:
1173 if (printer_notify_table
[msg
->field
].fn
) {
1174 printer_notify_table
[msg
->field
].fn(msg
,
1175 ¬ifies
[count
], mem_ctx
);
1179 case JOB_NOTIFY_TYPE
:
1180 if (job_notify_table
[msg
->field
].fn
) {
1181 job_notify_table
[msg
->field
].fn(msg
,
1182 ¬ifies
[count
], mem_ctx
);
1187 DEBUG(5, ("Unknown notification type %d\n",
1195 *_notifies
= notifies
;
1201 static int send_notify2_printer(TALLOC_CTX
*mem_ctx
,
1202 struct printer_handle
*prn_hnd
,
1203 SPOOLSS_NOTIFY_MSG_GROUP
*msg_group
)
1205 struct spoolss_Notify
*notifies
;
1207 union spoolss_ReplyPrinterInfo info
;
1208 struct spoolss_NotifyInfo info0
;
1209 uint32_t reply_result
;
1214 /* Is there notification on this handle? */
1215 if (prn_hnd
->notify
.cli_chan
== NULL
||
1216 prn_hnd
->notify
.cli_chan
->cli_pipe
== NULL
||
1217 prn_hnd
->notify
.cli_chan
->cli_pipe
->binding_handle
== NULL
||
1218 prn_hnd
->notify
.cli_chan
->active_connections
== 0) {
1222 DEBUG(10, ("Client connected! [\\\\%s\\%s]\n",
1223 prn_hnd
->servername
, prn_hnd
->sharename
));
1225 /* For this printer? Print servers always receive notifications. */
1226 if ((prn_hnd
->printer_type
== SPLHND_PRINTER
) &&
1227 (!strequal(msg_group
->printername
, prn_hnd
->sharename
))) {
1231 DEBUG(10,("Our printer\n"));
1233 /* build the array of change notifications */
1234 ret
= build_notify2_messages(mem_ctx
, prn_hnd
,
1236 msg_group
->num_msgs
,
1242 info0
.version
= 0x2;
1243 info0
.flags
= count
? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED
;
1244 info0
.count
= count
;
1245 info0
.notifies
= notifies
;
1247 info
.info0
= &info0
;
1249 status
= dcerpc_spoolss_RouterReplyPrinterEx(
1250 prn_hnd
->notify
.cli_chan
->cli_pipe
->binding_handle
,
1252 &prn_hnd
->notify
.cli_hnd
,
1253 prn_hnd
->notify
.change
, /* color */
1254 prn_hnd
->notify
.flags
,
1256 0, /* reply_type, must be 0 */
1258 if (!NT_STATUS_IS_OK(status
)) {
1259 DEBUG(1, ("dcerpc_spoolss_RouterReplyPrinterEx to client: %s "
1261 prn_hnd
->notify
.cli_chan
->cli_pipe
->srv_name_slash
,
1262 nt_errstr(status
)));
1263 werr
= ntstatus_to_werror(status
);
1264 } else if (!W_ERROR_IS_OK(werr
)) {
1265 DEBUG(1, ("RouterReplyPrinterEx to client: %s "
1267 prn_hnd
->notify
.cli_chan
->cli_pipe
->srv_name_slash
,
1270 switch (reply_result
) {
1273 case PRINTER_NOTIFY_INFO_DISCARDED
:
1274 case PRINTER_NOTIFY_INFO_DISCARDNOTED
:
1275 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH
:
1284 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR
*ctr
, uint32_t idx
)
1286 struct printer_handle
*p
;
1287 TALLOC_CTX
*mem_ctx
= notify_ctr_getctx( ctr
);
1288 SPOOLSS_NOTIFY_MSG_GROUP
*msg_group
= notify_ctr_getgroup( ctr
, idx
);
1292 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
1296 if (!msg_group
->msgs
) {
1297 DEBUG(5, ("send_notify2_changes() called with no messages!\n"));
1301 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group
->printername
));
1303 /* loop over all printers */
1305 for (p
= printers_list
; p
; p
= p
->next
) {
1306 ret
= send_notify2_printer(mem_ctx
, p
, msg_group
);
1313 DEBUG(8,("send_notify2_changes: Exit...\n"));
1317 /***********************************************************************
1318 **********************************************************************/
1320 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG
*msg
, struct timeval
*tv
, void *buf
, size_t len
)
1323 uint32_t tv_sec
, tv_usec
;
1326 /* Unpack message */
1328 offset
+= tdb_unpack((uint8_t *)buf
+ offset
, len
- offset
, "f",
1331 offset
+= tdb_unpack((uint8_t *)buf
+ offset
, len
- offset
, "ddddddd",
1333 &msg
->type
, &msg
->field
, &msg
->id
, &msg
->len
, &msg
->flags
);
1336 tdb_unpack((uint8_t *)buf
+ offset
, len
- offset
, "dd",
1337 &msg
->notify
.value
[0], &msg
->notify
.value
[1]);
1339 tdb_unpack((uint8_t *)buf
+ offset
, len
- offset
, "B",
1340 &msg
->len
, &msg
->notify
.data
);
1342 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1343 msg
->printer
, (unsigned int)msg
->id
, msg
->type
, msg
->field
, msg
->flags
));
1345 tv
->tv_sec
= tv_sec
;
1346 tv
->tv_usec
= tv_usec
;
1349 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg
->notify
.value
[0],
1350 msg
->notify
.value
[1]));
1352 dump_data(3, (uint8_t *)msg
->notify
.data
, msg
->len
);
1357 /********************************************************************
1358 Receive a notify2 message list
1359 ********************************************************************/
1361 static void receive_notify2_message_list(struct messaging_context
*msg
,
1364 struct server_id server_id
,
1367 size_t msg_count
, i
;
1368 char *buf
= (char *)data
->data
;
1371 SPOOLSS_NOTIFY_MSG notify
;
1372 SPOOLSS_NOTIFY_MSG_CTR messages
;
1375 if (data
->length
< 4) {
1376 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1380 msg_count
= IVAL(buf
, 0);
1383 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count
));
1385 if (msg_count
== 0) {
1386 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1390 /* initialize the container */
1392 ZERO_STRUCT( messages
);
1393 notify_msg_ctr_init( &messages
);
1396 * build message groups for each printer identified
1397 * in a change_notify msg. Remember that a PCN message
1398 * includes the handle returned for the srv_spoolss_replyopenprinter()
1399 * call. Therefore messages are grouped according to printer handle.
1402 for ( i
=0; i
<msg_count
; i
++ ) {
1403 struct timeval msg_tv
;
1405 if (msg_ptr
+ 4 - buf
> data
->length
) {
1406 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1410 msg_len
= IVAL(msg_ptr
,0);
1413 if (msg_ptr
+ msg_len
- buf
> data
->length
) {
1414 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1418 /* unpack messages */
1420 ZERO_STRUCT( notify
);
1421 notify2_unpack_msg( ¬ify
, &msg_tv
, msg_ptr
, msg_len
);
1424 /* add to correct list in container */
1426 notify_msg_ctr_addmsg( &messages
, ¬ify
);
1428 /* free memory that might have been allocated by notify2_unpack_msg() */
1430 if ( notify
.len
!= 0 )
1431 SAFE_FREE( notify
.notify
.data
);
1434 /* process each group of messages */
1436 num_groups
= notify_msg_ctr_numgroups( &messages
);
1437 for ( i
=0; i
<num_groups
; i
++ )
1438 send_notify2_changes( &messages
, i
);
1443 DEBUG(10,("receive_notify2_message_list: processed %u messages\n",
1444 (uint32_t)msg_count
));
1446 notify_msg_ctr_destroy( &messages
);
1451 /********************************************************************
1452 Send a message to ourself about new driver being installed
1453 so we can upgrade the information for each printer bound to this
1455 ********************************************************************/
1457 static bool srv_spoolss_drv_upgrade_printer(const char *drivername
,
1458 struct messaging_context
*msg_ctx
)
1460 int len
= strlen(drivername
);
1465 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1468 messaging_send_buf(msg_ctx
, messaging_server_id(msg_ctx
),
1469 MSG_PRINTER_DRVUPGRADE
,
1470 (const uint8_t *)drivername
, len
+1);
1475 void srv_spoolss_cleanup(void)
1477 struct printer_session_counter
*session_counter
;
1479 for (session_counter
= counter_list
;
1480 session_counter
!= NULL
;
1481 session_counter
= counter_list
) {
1482 DLIST_REMOVE(counter_list
, session_counter
);
1483 TALLOC_FREE(session_counter
);
1487 /**********************************************************************
1488 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1489 over all printers, upgrading ones as necessary
1490 This is now *ONLY* called inside the background lpq updater. JRA.
1491 **********************************************************************/
1493 void do_drv_upgrade_printer(struct messaging_context
*msg
,
1496 struct server_id server_id
,
1499 TALLOC_CTX
*tmp_ctx
;
1500 const struct auth_session_info
*session_info
= get_session_info_system();
1501 struct spoolss_PrinterInfo2
*pinfo2
;
1503 const char *drivername
;
1505 int n_services
= lp_numservices();
1506 struct dcerpc_binding_handle
*b
= NULL
;
1508 tmp_ctx
= talloc_new(NULL
);
1509 if (!tmp_ctx
) return;
1511 drivername
= talloc_strndup(tmp_ctx
, (const char *)data
->data
, data
->length
);
1513 DEBUG(0, ("do_drv_upgrade_printer: Out of memoery ?!\n"));
1517 DEBUG(10, ("do_drv_upgrade_printer: "
1518 "Got message for new driver [%s]\n", drivername
));
1520 /* Iterate the printer list */
1522 for (snum
= 0; snum
< n_services
; snum
++) {
1523 if (!lp_snum_ok(snum
) || !lp_printable(snum
)) {
1527 /* ignore [printers] share */
1528 if (strequal(lp_const_servicename(snum
), "printers")) {
1533 result
= winreg_printer_binding_handle(tmp_ctx
,
1537 if (!W_ERROR_IS_OK(result
)) {
1542 result
= winreg_get_printer(tmp_ctx
, b
,
1543 lp_const_servicename(snum
),
1546 if (!W_ERROR_IS_OK(result
)) {
1550 if (!pinfo2
->drivername
) {
1554 if (strcmp(drivername
, pinfo2
->drivername
) != 0) {
1558 DEBUG(6,("Updating printer [%s]\n", pinfo2
->printername
));
1560 /* all we care about currently is the change_id */
1561 result
= winreg_printer_update_changeid(tmp_ctx
, b
,
1562 pinfo2
->printername
);
1564 if (!W_ERROR_IS_OK(result
)) {
1565 DEBUG(3, ("do_drv_upgrade_printer: "
1566 "Failed to update changeid [%s]\n",
1567 win_errstr(result
)));
1573 talloc_free(tmp_ctx
);
1576 /********************************************************************
1577 Update the cache for all printq's with a registered client
1579 ********************************************************************/
1581 void update_monitored_printq_cache(struct messaging_context
*msg_ctx
)
1583 struct printer_handle
*printer
= printers_list
;
1586 /* loop through all printers and update the cache where
1587 a client is connected */
1589 if ((printer
->printer_type
== SPLHND_PRINTER
) &&
1590 ((printer
->notify
.cli_chan
!= NULL
) &&
1591 (printer
->notify
.cli_chan
->active_connections
> 0))) {
1592 snum
= print_queue_snum(printer
->sharename
);
1593 print_queue_status(msg_ctx
, snum
, NULL
, NULL
);
1596 printer
= printer
->next
;
1602 /****************************************************************
1603 _spoolss_OpenPrinter
1604 ****************************************************************/
1606 WERROR
_spoolss_OpenPrinter(struct pipes_struct
*p
,
1607 struct spoolss_OpenPrinter
*r
)
1609 struct spoolss_OpenPrinterEx e
;
1610 struct spoolss_UserLevel1 level1
;
1613 ZERO_STRUCT(level1
);
1615 e
.in
.printername
= r
->in
.printername
;
1616 e
.in
.datatype
= r
->in
.datatype
;
1617 e
.in
.devmode_ctr
= r
->in
.devmode_ctr
;
1618 e
.in
.access_mask
= r
->in
.access_mask
;
1619 e
.in
.userlevel_ctr
.level
= 1;
1620 e
.in
.userlevel_ctr
.user_info
.level1
= &level1
;
1622 e
.out
.handle
= r
->out
.handle
;
1624 werr
= _spoolss_OpenPrinterEx(p
, &e
);
1626 if (W_ERROR_EQUAL(werr
, WERR_INVALID_PARAMETER
)) {
1627 /* OpenPrinterEx returns this for a bad
1628 * printer name. We must return WERR_INVALID_PRINTER_NAME
1631 werr
= WERR_INVALID_PRINTER_NAME
;
1637 static WERROR
copy_devicemode(TALLOC_CTX
*mem_ctx
,
1638 struct spoolss_DeviceMode
*orig
,
1639 struct spoolss_DeviceMode
**dest
)
1641 struct spoolss_DeviceMode
*dm
;
1643 dm
= talloc(mem_ctx
, struct spoolss_DeviceMode
);
1645 return WERR_NOT_ENOUGH_MEMORY
;
1648 /* copy all values, then duplicate strings and structs */
1651 dm
->devicename
= talloc_strdup(dm
, orig
->devicename
);
1652 if (!dm
->devicename
) {
1653 return WERR_NOT_ENOUGH_MEMORY
;
1655 dm
->formname
= talloc_strdup(dm
, orig
->formname
);
1656 if (!dm
->formname
) {
1657 return WERR_NOT_ENOUGH_MEMORY
;
1659 if (orig
->driverextra_data
.data
) {
1660 dm
->driverextra_data
.data
=
1661 (uint8_t *) talloc_memdup(dm
, orig
->driverextra_data
.data
,
1662 orig
->driverextra_data
.length
);
1663 if (!dm
->driverextra_data
.data
) {
1664 return WERR_NOT_ENOUGH_MEMORY
;
1672 /****************************************************************
1673 _spoolss_OpenPrinterEx
1674 ****************************************************************/
1676 WERROR
_spoolss_OpenPrinterEx(struct pipes_struct
*p
,
1677 struct spoolss_OpenPrinterEx
*r
)
1682 struct printer_handle
*Printer
=NULL
;
1686 if (!r
->in
.printername
) {
1687 return WERR_INVALID_PARAMETER
;
1690 if (!*r
->in
.printername
) {
1691 return WERR_INVALID_PARAMETER
;
1694 if (r
->in
.userlevel_ctr
.level
> 3) {
1695 return WERR_INVALID_PARAMETER
;
1697 if ((r
->in
.userlevel_ctr
.level
== 1 && !r
->in
.userlevel_ctr
.user_info
.level1
) ||
1698 (r
->in
.userlevel_ctr
.level
== 2 && !r
->in
.userlevel_ctr
.user_info
.level2
) ||
1699 (r
->in
.userlevel_ctr
.level
== 3 && !r
->in
.userlevel_ctr
.user_info
.level3
)) {
1700 return WERR_INVALID_PARAMETER
;
1704 * The printcap printer share inventory is updated on client
1705 * enumeration. For clients that do not perform enumeration prior to
1706 * access, such as cupssmbadd, we reinitialise the printer share
1707 * inventory on open as well.
1710 delete_and_reload_printers();
1713 /* some sanity check because you can open a printer or a print server */
1714 /* aka: \\server\printer or \\server */
1716 DEBUGADD(3,("checking name: %s\n", r
->in
.printername
));
1718 result
= open_printer_hnd(p
, r
->out
.handle
, r
->in
.printername
, 0);
1719 if (!W_ERROR_IS_OK(result
)) {
1720 DEBUG(3,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
1721 "for printer %s\n", r
->in
.printername
));
1722 ZERO_STRUCTP(r
->out
.handle
);
1726 Printer
= find_printer_index_by_hnd(p
, r
->out
.handle
);
1728 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1729 "handle we created for printer %s\n", r
->in
.printername
));
1730 close_printer_handle(p
, r
->out
.handle
);
1731 ZERO_STRUCTP(r
->out
.handle
);
1732 return WERR_INVALID_PARAMETER
;
1736 * First case: the user is opening the print server:
1738 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1739 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1741 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1742 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1743 * or if the user is listed in the smb.conf printer admin parameter.
1745 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1746 * client view printer folder, but does not show the MSAPW.
1748 * Note: this test needs code to check access rights here too. Jeremy
1749 * could you look at this?
1751 * Second case: the user is opening a printer:
1752 * NT doesn't let us connect to a printer if the connecting user
1753 * doesn't have print permission.
1755 * Third case: user is opening a Port Monitor
1756 * access checks same as opening a handle to the print server.
1759 switch (Printer
->printer_type
)
1762 case SPLHND_PORTMON_TCP
:
1763 case SPLHND_PORTMON_LOCAL
:
1764 /* Printserver handles use global struct... */
1768 if (r
->in
.access_mask
& SEC_FLAG_MAXIMUM_ALLOWED
) {
1769 r
->in
.access_mask
|= SERVER_ACCESS_ADMINISTER
;
1770 r
->in
.access_mask
|= SERVER_ACCESS_ENUMERATE
;
1773 /* Map standard access rights to object specific access rights */
1775 se_map_standard(&r
->in
.access_mask
,
1776 &printserver_std_mapping
);
1778 /* Deny any object specific bits that don't apply to print
1779 servers (i.e printer and job specific bits) */
1781 r
->in
.access_mask
&= SEC_MASK_SPECIFIC
;
1783 if (r
->in
.access_mask
&
1784 ~(SERVER_ACCESS_ADMINISTER
| SERVER_ACCESS_ENUMERATE
)) {
1785 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1786 close_printer_handle(p
, r
->out
.handle
);
1787 ZERO_STRUCTP(r
->out
.handle
);
1788 return WERR_ACCESS_DENIED
;
1791 /* Allow admin access */
1793 if ( r
->in
.access_mask
& SERVER_ACCESS_ADMINISTER
)
1795 if (!lp_show_add_printer_wizard()) {
1796 close_printer_handle(p
, r
->out
.handle
);
1797 ZERO_STRUCTP(r
->out
.handle
);
1798 return WERR_ACCESS_DENIED
;
1801 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1802 and not a printer admin, then fail */
1804 if ((p
->session_info
->unix_token
->uid
!= sec_initial_uid()) &&
1805 !security_token_has_privilege(p
->session_info
->security_token
, SEC_PRIV_PRINT_OPERATOR
) &&
1806 !nt_token_check_sid(&global_sid_Builtin_Print_Operators
,
1807 p
->session_info
->security_token
)) {
1808 close_printer_handle(p
, r
->out
.handle
);
1809 ZERO_STRUCTP(r
->out
.handle
);
1810 DEBUG(3,("access DENIED as user is not root, "
1811 "has no printoperator privilege and is "
1812 "not a member of the printoperator builtin group\n"));
1813 return WERR_ACCESS_DENIED
;
1816 r
->in
.access_mask
= SERVER_ACCESS_ADMINISTER
;
1820 r
->in
.access_mask
= SERVER_ACCESS_ENUMERATE
;
1823 DEBUG(4,("Setting print server access = %s\n", (r
->in
.access_mask
== SERVER_ACCESS_ADMINISTER
)
1824 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1828 case SPLHND_PRINTER
:
1829 /* NT doesn't let us connect to a printer if the connecting user
1830 doesn't have print permission. */
1832 if (!get_printer_snum(p
, r
->out
.handle
, &snum
, NULL
)) {
1833 close_printer_handle(p
, r
->out
.handle
);
1834 ZERO_STRUCTP(r
->out
.handle
);
1835 return WERR_INVALID_HANDLE
;
1838 if (r
->in
.access_mask
== SEC_FLAG_MAXIMUM_ALLOWED
) {
1839 r
->in
.access_mask
= PRINTER_ACCESS_ADMINISTER
;
1842 se_map_standard(&r
->in
.access_mask
, &printer_std_mapping
);
1844 /* map an empty access mask to the minimum access mask */
1845 if (r
->in
.access_mask
== 0x0)
1846 r
->in
.access_mask
= PRINTER_ACCESS_USE
;
1849 * If we are not serving the printer driver for this printer,
1850 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1851 * will keep NT clients happy --jerry
1854 if (lp_use_client_driver(snum
)
1855 && (r
->in
.access_mask
& PRINTER_ACCESS_ADMINISTER
))
1857 r
->in
.access_mask
= PRINTER_ACCESS_USE
;
1860 /* check smb.conf parameters and the the sec_desc */
1861 raddr
= tsocket_address_inet_addr_string(p
->remote_address
,
1863 if (raddr
== NULL
) {
1864 return WERR_NOT_ENOUGH_MEMORY
;
1867 rc
= get_remote_hostname(p
->remote_address
,
1871 return WERR_NOT_ENOUGH_MEMORY
;
1873 if (strequal(rhost
, "UNKNOWN")) {
1877 if (!allow_access(lp_hosts_deny(snum
), lp_hosts_allow(snum
),
1879 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1880 ZERO_STRUCTP(r
->out
.handle
);
1881 return WERR_ACCESS_DENIED
;
1884 if (!user_ok_token(uidtoname(p
->session_info
->unix_token
->uid
), NULL
,
1885 p
->session_info
->security_token
, snum
) ||
1886 !W_ERROR_IS_OK(print_access_check(p
->session_info
,
1889 r
->in
.access_mask
))) {
1890 DEBUG(3, ("access DENIED for printer open\n"));
1891 close_printer_handle(p
, r
->out
.handle
);
1892 ZERO_STRUCTP(r
->out
.handle
);
1893 return WERR_ACCESS_DENIED
;
1896 if ((r
->in
.access_mask
& SEC_MASK_SPECIFIC
)& ~(PRINTER_ACCESS_ADMINISTER
|PRINTER_ACCESS_USE
)) {
1897 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1898 close_printer_handle(p
, r
->out
.handle
);
1899 ZERO_STRUCTP(r
->out
.handle
);
1900 return WERR_ACCESS_DENIED
;
1903 if (r
->in
.access_mask
& PRINTER_ACCESS_ADMINISTER
)
1904 r
->in
.access_mask
= PRINTER_ACCESS_ADMINISTER
;
1906 r
->in
.access_mask
= PRINTER_ACCESS_USE
;
1908 DEBUG(4,("Setting printer access = %s\n", (r
->in
.access_mask
== PRINTER_ACCESS_ADMINISTER
)
1909 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1911 winreg_create_printer_internal(p
->mem_ctx
,
1912 get_session_info_system(),
1914 lp_const_servicename(snum
));
1919 /* sanity check to prevent programmer error */
1920 ZERO_STRUCTP(r
->out
.handle
);
1921 return WERR_INVALID_HANDLE
;
1924 Printer
->access_granted
= r
->in
.access_mask
;
1927 * If the client sent a devmode in the OpenPrinter() call, then
1928 * save it here in case we get a job submission on this handle
1931 if ((Printer
->printer_type
!= SPLHND_SERVER
)
1932 && (r
->in
.devmode_ctr
.devmode
!= NULL
)) {
1933 copy_devicemode(NULL
, r
->in
.devmode_ctr
.devmode
,
1940 /****************************************************************
1941 _spoolss_ClosePrinter
1942 ****************************************************************/
1944 WERROR
_spoolss_ClosePrinter(struct pipes_struct
*p
,
1945 struct spoolss_ClosePrinter
*r
)
1947 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
1949 if (Printer
&& Printer
->document_started
) {
1950 struct spoolss_EndDocPrinter e
;
1952 e
.in
.handle
= r
->in
.handle
;
1954 _spoolss_EndDocPrinter(p
, &e
);
1957 if (!close_printer_handle(p
, r
->in
.handle
))
1958 return WERR_INVALID_HANDLE
;
1960 /* clear the returned printer handle. Observed behavior
1961 from Win2k server. Don't think this really matters.
1962 Previous code just copied the value of the closed
1965 ZERO_STRUCTP(r
->out
.handle
);
1970 /****************************************************************
1971 _spoolss_DeletePrinter
1972 ****************************************************************/
1974 WERROR
_spoolss_DeletePrinter(struct pipes_struct
*p
,
1975 struct spoolss_DeletePrinter
*r
)
1977 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
1981 if (Printer
&& Printer
->document_started
) {
1982 struct spoolss_EndDocPrinter e
;
1984 e
.in
.handle
= r
->in
.handle
;
1986 _spoolss_EndDocPrinter(p
, &e
);
1989 if (get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
1990 winreg_delete_printer_key_internal(p
->mem_ctx
,
1991 get_session_info_system(),
1993 lp_const_servicename(snum
),
1997 result
= delete_printer_handle(p
, r
->in
.handle
);
2002 /*******************************************************************
2003 * static function to lookup the version id corresponding to an
2004 * long architecture string
2005 ******************************************************************/
2007 static const struct print_architecture_table_node archi_table
[]= {
2009 {"Windows 4.0", SPL_ARCH_WIN40
, 0 },
2010 {"Windows NT x86", SPL_ARCH_W32X86
, 2 },
2011 {"Windows NT R4000", SPL_ARCH_W32MIPS
, 2 },
2012 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA
, 2 },
2013 {"Windows NT PowerPC", SPL_ARCH_W32PPC
, 2 },
2014 {"Windows IA64", SPL_ARCH_IA64
, 3 },
2015 {"Windows x64", SPL_ARCH_X64
, 3 },
2019 static const int drv_cversion
[] = {SPOOLSS_DRIVER_VERSION_9X
,
2020 SPOOLSS_DRIVER_VERSION_NT35
,
2021 SPOOLSS_DRIVER_VERSION_NT4
,
2022 SPOOLSS_DRIVER_VERSION_200X
,
2025 static int get_version_id(const char *arch
)
2029 for (i
=0; archi_table
[i
].long_archi
!= NULL
; i
++)
2031 if (strcmp(arch
, archi_table
[i
].long_archi
) == 0)
2032 return (archi_table
[i
].version
);
2038 /****************************************************************
2039 _spoolss_DeletePrinterDriver
2040 ****************************************************************/
2042 WERROR
_spoolss_DeletePrinterDriver(struct pipes_struct
*p
,
2043 struct spoolss_DeletePrinterDriver
*r
)
2046 struct spoolss_DriverInfo8
*info
= NULL
;
2049 struct dcerpc_binding_handle
*b
;
2050 TALLOC_CTX
*tmp_ctx
= NULL
;
2054 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2055 and not a printer admin, then fail */
2057 if ((p
->session_info
->unix_token
->uid
!= sec_initial_uid()) &&
2058 !security_token_has_privilege(p
->session_info
->security_token
,
2059 SEC_PRIV_PRINT_OPERATOR
)) {
2060 return WERR_ACCESS_DENIED
;
2063 if (r
->in
.architecture
== NULL
|| r
->in
.driver
== NULL
) {
2064 return WERR_INVALID_ENVIRONMENT
;
2067 /* check that we have a valid driver name first */
2069 if ((version
= get_version_id(r
->in
.architecture
)) == -1) {
2070 return WERR_INVALID_ENVIRONMENT
;
2073 tmp_ctx
= talloc_new(p
->mem_ctx
);
2075 return WERR_NOT_ENOUGH_MEMORY
;
2078 status
= winreg_printer_binding_handle(tmp_ctx
,
2079 get_session_info_system(),
2082 if (!W_ERROR_IS_OK(status
)) {
2086 for (found
= false, i
= 0; drv_cversion
[i
] >= 0; i
++) {
2087 status
= winreg_get_driver(tmp_ctx
, b
,
2088 r
->in
.architecture
, r
->in
.driver
,
2089 drv_cversion
[i
], &info
);
2090 if (!W_ERROR_IS_OK(status
)) {
2091 DEBUG(5, ("skipping del of driver with version %d\n",
2097 if (printer_driver_in_use(tmp_ctx
, b
, info
)) {
2098 status
= WERR_PRINTER_DRIVER_IN_USE
;
2102 status
= winreg_del_driver(tmp_ctx
, b
, info
, drv_cversion
[i
]);
2103 if (!W_ERROR_IS_OK(status
)) {
2104 DEBUG(0, ("failed del of driver with version %d\n",
2109 if (found
== false) {
2110 DEBUG(0, ("driver %s not found for deletion\n", r
->in
.driver
));
2111 status
= WERR_UNKNOWN_PRINTER_DRIVER
;
2117 talloc_free(tmp_ctx
);
2122 static WERROR
spoolss_dpd_version(TALLOC_CTX
*mem_ctx
,
2123 struct pipes_struct
*p
,
2124 struct spoolss_DeletePrinterDriverEx
*r
,
2125 struct dcerpc_binding_handle
*b
,
2126 struct spoolss_DriverInfo8
*info
)
2131 if (printer_driver_in_use(mem_ctx
, b
, info
)) {
2132 status
= WERR_PRINTER_DRIVER_IN_USE
;
2137 * we have a couple of cases to consider.
2138 * (1) Are any files in use? If so and DPD_DELETE_ALL_FILES is set,
2139 * then the delete should fail if **any** files overlap with
2141 * (2) If DPD_DELETE_UNUSED_FILES is set, then delete all
2142 * non-overlapping files
2143 * (3) If neither DPD_DELETE_ALL_FILES nor DPD_DELETE_UNUSED_FILES
2144 * are set, then do not delete any files
2145 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
2148 delete_files
= r
->in
.delete_flags
2149 & (DPD_DELETE_ALL_FILES
| DPD_DELETE_UNUSED_FILES
);
2153 bool in_use
= printer_driver_files_in_use(mem_ctx
, b
, info
);
2154 if (in_use
&& (r
->in
.delete_flags
& DPD_DELETE_ALL_FILES
)) {
2155 status
= WERR_PRINTER_DRIVER_IN_USE
;
2159 * printer_driver_files_in_use() has trimmed overlapping files
2160 * from info so they are not removed on DPD_DELETE_UNUSED_FILES
2165 status
= winreg_del_driver(mem_ctx
, b
, info
, info
->version
);
2166 if (!W_ERROR_IS_OK(status
)) {
2171 * now delete any associated files if delete_files is
2172 * true. Even if this part failes, we return succes
2173 * because the driver doesn not exist any more
2176 delete_driver_files(p
->session_info
, info
);
2183 /****************************************************************
2184 _spoolss_DeletePrinterDriverEx
2185 ****************************************************************/
2187 WERROR
_spoolss_DeletePrinterDriverEx(struct pipes_struct
*p
,
2188 struct spoolss_DeletePrinterDriverEx
*r
)
2190 struct spoolss_DriverInfo8
*info
= NULL
;
2192 struct dcerpc_binding_handle
*b
;
2193 TALLOC_CTX
*tmp_ctx
= NULL
;
2197 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2198 and not a printer admin, then fail */
2200 if ((p
->session_info
->unix_token
->uid
!= sec_initial_uid()) &&
2201 !security_token_has_privilege(p
->session_info
->security_token
,
2202 SEC_PRIV_PRINT_OPERATOR
)) {
2203 return WERR_ACCESS_DENIED
;
2206 if (r
->in
.architecture
== NULL
|| r
->in
.driver
== NULL
) {
2207 return WERR_INVALID_ENVIRONMENT
;
2210 /* check that we have a valid driver name first */
2211 if (get_version_id(r
->in
.architecture
) == -1) {
2212 /* this is what NT returns */
2213 return WERR_INVALID_ENVIRONMENT
;
2216 tmp_ctx
= talloc_new(p
->mem_ctx
);
2218 return WERR_NOT_ENOUGH_MEMORY
;
2221 status
= winreg_printer_binding_handle(tmp_ctx
,
2222 get_session_info_system(),
2225 if (!W_ERROR_IS_OK(status
)) {
2229 for (found
= false, i
= 0; drv_cversion
[i
] >= 0; i
++) {
2230 if ((r
->in
.delete_flags
& DPD_DELETE_SPECIFIC_VERSION
)
2231 && (drv_cversion
[i
] != r
->in
.version
)) {
2235 /* check if a driver with this version exists before delete */
2236 status
= winreg_get_driver(tmp_ctx
, b
,
2237 r
->in
.architecture
, r
->in
.driver
,
2238 drv_cversion
[i
], &info
);
2239 if (!W_ERROR_IS_OK(status
)) {
2240 DEBUG(5, ("skipping del of driver with version %d\n",
2246 status
= spoolss_dpd_version(tmp_ctx
, p
, r
, b
, info
);
2247 if (!W_ERROR_IS_OK(status
)) {
2248 DEBUG(0, ("failed to delete driver with version %d\n",
2253 if (found
== false) {
2254 DEBUG(0, ("driver %s not found for deletion\n", r
->in
.driver
));
2255 status
= WERR_UNKNOWN_PRINTER_DRIVER
;
2261 talloc_free(tmp_ctx
);
2266 /********************************************************************
2267 GetPrinterData on a printer server Handle.
2268 ********************************************************************/
2270 static WERROR
getprinterdata_printer_server(TALLOC_CTX
*mem_ctx
,
2272 enum winreg_Type
*type
,
2273 union spoolss_PrinterData
*data
)
2275 DEBUG(8,("getprinterdata_printer_server:%s\n", value
));
2277 if (!strcasecmp_m(value
, "W3SvcInstalled")) {
2279 SIVAL(&data
->value
, 0, 0x00);
2283 if (!strcasecmp_m(value
, "BeepEnabled")) {
2285 SIVAL(&data
->value
, 0, 0x00);
2289 if (!strcasecmp_m(value
, "EventLog")) {
2291 /* formally was 0x1b */
2292 SIVAL(&data
->value
, 0, 0x00);
2296 if (!strcasecmp_m(value
, "NetPopup")) {
2298 SIVAL(&data
->value
, 0, 0x00);
2302 if (!strcasecmp_m(value
, "MajorVersion")) {
2305 /* Windows NT 4.0 seems to not allow uploading of drivers
2306 to a server that reports 0x3 as the MajorVersion.
2307 need to investigate more how Win2k gets around this .
2310 if (RA_WINNT
== get_remote_arch()) {
2311 SIVAL(&data
->value
, 0, 0x02);
2313 SIVAL(&data
->value
, 0, 0x03);
2319 if (!strcasecmp_m(value
, "MinorVersion")) {
2321 SIVAL(&data
->value
, 0, 0x00);
2326 * uint32_t size = 0x114
2327 * uint32_t major = 5
2328 * uint32_t minor = [0|1]
2329 * uint32_t build = [2195|2600]
2330 * extra unicode string = e.g. "Service Pack 3"
2332 if (!strcasecmp_m(value
, "OSVersion")) {
2334 enum ndr_err_code ndr_err
;
2335 struct spoolss_OSVersion os
;
2338 * Set the default OSVersion to:
2340 * Windows Server 2003R2 SP2 (5.2.3790)
2342 * used to be Windows 2000 (5.0.2195)
2344 os
.major
= lp_parm_int(GLOBAL_SECTION_SNUM
,
2345 "spoolss", "os_major",
2346 GLOBAL_SPOOLSS_OS_MAJOR_DEFAULT
);
2347 os
.minor
= lp_parm_int(GLOBAL_SECTION_SNUM
,
2348 "spoolss", "os_minor",
2349 GLOBAL_SPOOLSS_OS_MINOR_DEFAULT
);
2350 os
.build
= lp_parm_int(GLOBAL_SECTION_SNUM
,
2351 "spoolss", "os_build",
2352 GLOBAL_SPOOLSS_OS_BUILD_DEFAULT
);
2353 os
.extra_string
= ""; /* leave extra string empty */
2355 ndr_err
= ndr_push_struct_blob(&blob
, mem_ctx
, &os
,
2356 (ndr_push_flags_fn_t
)ndr_push_spoolss_OSVersion
);
2357 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2358 return WERR_GEN_FAILURE
;
2361 if (DEBUGLEVEL
>= 10) {
2362 NDR_PRINT_DEBUG(spoolss_OSVersion
, &os
);
2366 data
->binary
= blob
;
2372 if (!strcasecmp_m(value
, "DefaultSpoolDirectory")) {
2375 data
->string
= talloc_strdup(mem_ctx
, SPOOLSS_DEFAULT_SERVER_PATH
);
2376 W_ERROR_HAVE_NO_MEMORY(data
->string
);
2381 if (!strcasecmp_m(value
, "Architecture")) {
2383 data
->string
= talloc_strdup(mem_ctx
,
2384 lp_parm_const_string(GLOBAL_SECTION_SNUM
, "spoolss", "architecture", GLOBAL_SPOOLSS_ARCHITECTURE
));
2385 W_ERROR_HAVE_NO_MEMORY(data
->string
);
2390 if (!strcasecmp_m(value
, "DsPresent")) {
2393 /* only show the publish check box if we are a
2394 member of a AD domain */
2396 if (lp_security() == SEC_ADS
) {
2397 SIVAL(&data
->value
, 0, 0x01);
2399 SIVAL(&data
->value
, 0, 0x00);
2404 if (!strcasecmp_m(value
, "DNSMachineName")) {
2405 const char *hostname
= get_mydnsfullname();
2408 return WERR_FILE_NOT_FOUND
;
2412 data
->string
= talloc_strdup(mem_ctx
, hostname
);
2413 W_ERROR_HAVE_NO_MEMORY(data
->string
);
2420 return WERR_INVALID_PARAMETER
;
2423 /****************************************************************
2424 _spoolss_GetPrinterData
2425 ****************************************************************/
2427 WERROR
_spoolss_GetPrinterData(struct pipes_struct
*p
,
2428 struct spoolss_GetPrinterData
*r
)
2430 struct spoolss_GetPrinterDataEx r2
;
2432 r2
.in
.handle
= r
->in
.handle
;
2433 r2
.in
.key_name
= "PrinterDriverData";
2434 r2
.in
.value_name
= r
->in
.value_name
;
2435 r2
.in
.offered
= r
->in
.offered
;
2436 r2
.out
.type
= r
->out
.type
;
2437 r2
.out
.data
= r
->out
.data
;
2438 r2
.out
.needed
= r
->out
.needed
;
2440 return _spoolss_GetPrinterDataEx(p
, &r2
);
2443 /*********************************************************
2444 Connect to the client machine.
2445 **********************************************************/
2447 static bool spoolss_connect_to_client(struct rpc_pipe_client
**pp_pipe
, struct cli_state
**pp_cli
,
2448 struct sockaddr_storage
*client_ss
, const char *remote_machine
)
2451 struct sockaddr_storage rm_addr
;
2452 char addr
[INET6_ADDRSTRLEN
];
2453 struct cli_credentials
*anon_creds
= NULL
;
2455 if ( is_zero_addr(client_ss
) ) {
2456 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2458 if ( !resolve_name( remote_machine
, &rm_addr
, 0x20, false) ) {
2459 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine
));
2462 print_sockaddr(addr
, sizeof(addr
), &rm_addr
);
2464 rm_addr
= *client_ss
;
2465 print_sockaddr(addr
, sizeof(addr
), &rm_addr
);
2466 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2470 if (ismyaddr((struct sockaddr
*)(void *)&rm_addr
)) {
2471 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2476 anon_creds
= cli_credentials_init_anon(NULL
);
2477 if (anon_creds
== NULL
) {
2478 DBG_ERR("cli_credentials_init_anon() failed\n");
2482 /* setup the connection */
2483 ret
= cli_full_connection_creds( pp_cli
, lp_netbios_name(), remote_machine
,
2484 &rm_addr
, 0, "IPC$", "IPC",
2486 CLI_FULL_CONNECTION_IPC
);
2487 TALLOC_FREE(anon_creds
);
2488 if ( !NT_STATUS_IS_OK( ret
) ) {
2489 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2494 if ( smbXcli_conn_protocol((*pp_cli
)->conn
) < PROTOCOL_NT1
) {
2495 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine
));
2496 cli_shutdown(*pp_cli
);
2501 * Ok - we have an anonymous connection to the IPC$ share.
2502 * Now start the NT Domain stuff :-).
2505 ret
= cli_rpc_pipe_open_noauth(*pp_cli
, &ndr_table_spoolss
, pp_pipe
);
2506 if (!NT_STATUS_IS_OK(ret
)) {
2507 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2508 remote_machine
, nt_errstr(ret
)));
2509 cli_shutdown(*pp_cli
);
2516 /***************************************************************************
2517 Connect to the client.
2518 ****************************************************************************/
2520 static bool srv_spoolss_replyopenprinter(int snum
, const char *printer
,
2521 uint32_t localprinter
,
2522 enum winreg_Type type
,
2523 struct policy_handle
*handle
,
2524 struct notify_back_channel
**_chan
,
2525 struct sockaddr_storage
*client_ss
,
2526 struct messaging_context
*msg_ctx
)
2530 struct notify_back_channel
*chan
;
2532 for (chan
= back_channels
; chan
; chan
= chan
->next
) {
2533 if (memcmp(&chan
->client_address
, client_ss
,
2534 sizeof(struct sockaddr_storage
)) == 0) {
2540 * If it's the first connection, contact the client
2541 * and connect to the IPC$ share anonymously
2544 fstring unix_printer
;
2546 /* the +2 is to strip the leading 2 backslashs */
2547 fstrcpy(unix_printer
, printer
+ 2);
2549 chan
= talloc_zero(NULL
, struct notify_back_channel
);
2553 chan
->client_address
= *client_ss
;
2555 if (!spoolss_connect_to_client(&chan
->cli_pipe
, &chan
->cli
, client_ss
, unix_printer
)) {
2560 DLIST_ADD(back_channels
, chan
);
2562 messaging_register(msg_ctx
, NULL
, MSG_PRINTER_NOTIFY2
,
2563 receive_notify2_message_list
);
2566 if (chan
->cli_pipe
== NULL
||
2567 chan
->cli_pipe
->binding_handle
== NULL
) {
2568 DEBUG(0, ("srv_spoolss_replyopenprinter: error - "
2569 "NULL %s for printer %s\n",
2570 chan
->cli_pipe
== NULL
?
2571 "chan->cli_pipe" : "chan->cli_pipe->binding_handle",
2577 * Tell the specific printing tdb we want messages for this printer
2578 * by registering our PID.
2581 if (!print_notify_register_pid(snum
)) {
2582 DEBUG(0, ("Failed to register our pid for printer %s\n",
2586 status
= dcerpc_spoolss_ReplyOpenPrinter(chan
->cli_pipe
->binding_handle
,
2595 if (!NT_STATUS_IS_OK(status
)) {
2596 DEBUG(5, ("dcerpc_spoolss_ReplyOpenPrinter returned [%s]\n", nt_errstr(status
)));
2597 result
= ntstatus_to_werror(status
);
2598 } else if (!W_ERROR_IS_OK(result
)) {
2599 DEBUG(5, ("ReplyOpenPrinter returned [%s]\n", win_errstr(result
)));
2602 chan
->active_connections
++;
2605 return (W_ERROR_IS_OK(result
));
2608 /****************************************************************
2609 ****************************************************************/
2611 static struct spoolss_NotifyOption
*dup_spoolss_NotifyOption(TALLOC_CTX
*mem_ctx
,
2612 const struct spoolss_NotifyOption
*r
)
2614 struct spoolss_NotifyOption
*option
;
2621 option
= talloc_zero(mem_ctx
, struct spoolss_NotifyOption
);
2628 if (!option
->count
) {
2632 option
->types
= talloc_zero_array(option
,
2633 struct spoolss_NotifyOptionType
, option
->count
);
2634 if (!option
->types
) {
2635 talloc_free(option
);
2639 for (i
=0; i
< option
->count
; i
++) {
2640 option
->types
[i
] = r
->types
[i
];
2642 if (option
->types
[i
].count
) {
2643 option
->types
[i
].fields
= talloc_zero_array(option
,
2644 union spoolss_Field
, option
->types
[i
].count
);
2645 if (!option
->types
[i
].fields
) {
2646 talloc_free(option
);
2649 for (k
=0; k
<option
->types
[i
].count
; k
++) {
2650 option
->types
[i
].fields
[k
] =
2651 r
->types
[i
].fields
[k
];
2659 /****************************************************************
2660 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2662 * before replying OK: status=0 a rpc call is made to the workstation
2663 * asking ReplyOpenPrinter
2665 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2666 * called from api_spoolss_rffpcnex
2667 ****************************************************************/
2669 WERROR
_spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct
*p
,
2670 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx
*r
)
2673 struct spoolss_NotifyOption
*option
= r
->in
.notify_options
;
2674 struct sockaddr_storage client_ss
;
2677 /* store the notify value in the printer struct */
2679 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
2682 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2683 "Invalid handle (%s:%u:%u).\n",
2684 OUR_HANDLE(r
->in
.handle
)));
2685 return WERR_INVALID_HANDLE
;
2688 Printer
->notify
.flags
= r
->in
.flags
;
2689 Printer
->notify
.options
= r
->in
.options
;
2690 Printer
->notify
.printerlocal
= r
->in
.printer_local
;
2691 Printer
->notify
.msg_ctx
= p
->msg_ctx
;
2693 TALLOC_FREE(Printer
->notify
.option
);
2694 Printer
->notify
.option
= dup_spoolss_NotifyOption(Printer
, option
);
2696 fstrcpy(Printer
->notify
.localmachine
, r
->in
.local_machine
);
2698 /* Connect to the client machine and send a ReplyOpenPrinter */
2700 if ( Printer
->printer_type
== SPLHND_SERVER
)
2702 else if ( (Printer
->printer_type
== SPLHND_PRINTER
) &&
2703 !get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
) )
2704 return WERR_INVALID_HANDLE
;
2706 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2707 "remote_address is %s\n",
2708 tsocket_address_string(p
->remote_address
, p
->mem_ctx
)));
2710 if (!lp_print_notify_backchannel(snum
)) {
2711 DEBUG(10, ("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2712 "backchannel disabled\n"));
2713 return WERR_RPC_S_SERVER_UNAVAILABLE
;
2716 client_len
= tsocket_address_bsd_sockaddr(p
->remote_address
,
2717 (struct sockaddr
*) &client_ss
,
2718 sizeof(struct sockaddr_storage
));
2719 if (client_len
< 0) {
2720 return WERR_NOT_ENOUGH_MEMORY
;
2723 if(!srv_spoolss_replyopenprinter(snum
, Printer
->notify
.localmachine
,
2724 Printer
->notify
.printerlocal
, REG_SZ
,
2725 &Printer
->notify
.cli_hnd
,
2726 &Printer
->notify
.cli_chan
,
2727 &client_ss
, p
->msg_ctx
)) {
2728 return WERR_RPC_S_SERVER_UNAVAILABLE
;
2734 /*******************************************************************
2735 * fill a notify_info_data with the servername
2736 ********************************************************************/
2738 static void spoolss_notify_server_name(struct messaging_context
*msg_ctx
,
2740 struct spoolss_Notify
*data
,
2741 print_queue_struct
*queue
,
2742 struct spoolss_PrinterInfo2
*pinfo2
,
2743 TALLOC_CTX
*mem_ctx
)
2745 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->servername
);
2748 /*******************************************************************
2749 * fill a notify_info_data with the printername (not including the servername).
2750 ********************************************************************/
2752 static void spoolss_notify_printer_name(struct messaging_context
*msg_ctx
,
2754 struct spoolss_Notify
*data
,
2755 print_queue_struct
*queue
,
2756 struct spoolss_PrinterInfo2
*pinfo2
,
2757 TALLOC_CTX
*mem_ctx
)
2759 /* the notify name should not contain the \\server\ part */
2760 const char *p
= strrchr(pinfo2
->printername
, '\\');
2763 p
= pinfo2
->printername
;
2768 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, p
);
2771 /*******************************************************************
2772 * fill a notify_info_data with the servicename
2773 ********************************************************************/
2775 static void spoolss_notify_share_name(struct messaging_context
*msg_ctx
,
2777 struct spoolss_Notify
*data
,
2778 print_queue_struct
*queue
,
2779 struct spoolss_PrinterInfo2
*pinfo2
,
2780 TALLOC_CTX
*mem_ctx
)
2782 const struct loadparm_substitution
*lp_sub
=
2783 loadparm_s3_global_substitution();
2785 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, lp_servicename(talloc_tos(), lp_sub
, snum
));
2788 /*******************************************************************
2789 * fill a notify_info_data with the port name
2790 ********************************************************************/
2792 static void spoolss_notify_port_name(struct messaging_context
*msg_ctx
,
2794 struct spoolss_Notify
*data
,
2795 print_queue_struct
*queue
,
2796 struct spoolss_PrinterInfo2
*pinfo2
,
2797 TALLOC_CTX
*mem_ctx
)
2799 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->portname
);
2802 /*******************************************************************
2803 * fill a notify_info_data with the printername
2804 * but it doesn't exist, have to see what to do
2805 ********************************************************************/
2807 static void spoolss_notify_driver_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
->drivername
);
2817 /*******************************************************************
2818 * fill a notify_info_data with the comment
2819 ********************************************************************/
2821 static void spoolss_notify_comment(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 const struct loadparm_substitution
*lp_sub
=
2829 loadparm_s3_global_substitution();
2832 if (*pinfo2
->comment
== '\0') {
2833 p
= lp_comment(talloc_tos(), lp_sub
, snum
);
2835 p
= pinfo2
->comment
;
2838 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, p
);
2841 /*******************************************************************
2842 * fill a notify_info_data with the comment
2843 * location = "Room 1, floor 2, building 3"
2844 ********************************************************************/
2846 static void spoolss_notify_location(struct messaging_context
*msg_ctx
,
2848 struct spoolss_Notify
*data
,
2849 print_queue_struct
*queue
,
2850 struct spoolss_PrinterInfo2
*pinfo2
,
2851 TALLOC_CTX
*mem_ctx
)
2853 const char *loc
= pinfo2
->location
;
2856 status
= printer_list_get_printer(mem_ctx
,
2861 if (NT_STATUS_IS_OK(status
)) {
2863 loc
= pinfo2
->location
;
2867 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, loc
);
2870 /*******************************************************************
2871 * fill a notify_info_data with the device mode
2872 * jfm:xxxx don't to it for know but that's a real problem !!!
2873 ********************************************************************/
2875 static void spoolss_notify_devmode(struct messaging_context
*msg_ctx
,
2877 struct spoolss_Notify
*data
,
2878 print_queue_struct
*queue
,
2879 struct spoolss_PrinterInfo2
*pinfo2
,
2880 TALLOC_CTX
*mem_ctx
)
2882 /* for a dummy implementation we have to zero the fields */
2883 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data
, NULL
);
2886 /*******************************************************************
2887 * fill a notify_info_data with the separator file name
2888 ********************************************************************/
2890 static void spoolss_notify_sepfile(struct messaging_context
*msg_ctx
,
2892 struct spoolss_Notify
*data
,
2893 print_queue_struct
*queue
,
2894 struct spoolss_PrinterInfo2
*pinfo2
,
2895 TALLOC_CTX
*mem_ctx
)
2897 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->sepfile
);
2900 /*******************************************************************
2901 * fill a notify_info_data with the print processor
2902 * jfm:xxxx return always winprint to indicate we don't do anything to it
2903 ********************************************************************/
2905 static void spoolss_notify_print_processor(struct messaging_context
*msg_ctx
,
2907 struct spoolss_Notify
*data
,
2908 print_queue_struct
*queue
,
2909 struct spoolss_PrinterInfo2
*pinfo2
,
2910 TALLOC_CTX
*mem_ctx
)
2912 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->printprocessor
);
2915 /*******************************************************************
2916 * fill a notify_info_data with the print processor options
2917 * jfm:xxxx send an empty string
2918 ********************************************************************/
2920 static void spoolss_notify_parameters(struct messaging_context
*msg_ctx
,
2922 struct spoolss_Notify
*data
,
2923 print_queue_struct
*queue
,
2924 struct spoolss_PrinterInfo2
*pinfo2
,
2925 TALLOC_CTX
*mem_ctx
)
2927 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->parameters
);
2930 /*******************************************************************
2931 * fill a notify_info_data with the data type
2932 * jfm:xxxx always send RAW as data type
2933 ********************************************************************/
2935 static void spoolss_notify_datatype(struct messaging_context
*msg_ctx
,
2937 struct spoolss_Notify
*data
,
2938 print_queue_struct
*queue
,
2939 struct spoolss_PrinterInfo2
*pinfo2
,
2940 TALLOC_CTX
*mem_ctx
)
2942 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->datatype
);
2945 /*******************************************************************
2946 * fill a notify_info_data with the security descriptor
2947 * jfm:xxxx send an null pointer to say no security desc
2948 * have to implement security before !
2949 ********************************************************************/
2951 static void spoolss_notify_security_desc(struct messaging_context
*msg_ctx
,
2953 struct spoolss_Notify
*data
,
2954 print_queue_struct
*queue
,
2955 struct spoolss_PrinterInfo2
*pinfo2
,
2956 TALLOC_CTX
*mem_ctx
)
2958 if (pinfo2
->secdesc
== NULL
) {
2959 data
->data
.sd
.sd
= NULL
;
2961 data
->data
.sd
.sd
= security_descriptor_copy(mem_ctx
,
2964 data
->data
.sd
.sd_size
= ndr_size_security_descriptor(data
->data
.sd
.sd
,
2968 /*******************************************************************
2969 * fill a notify_info_data with the attributes
2970 * jfm:xxxx a samba printer is always shared
2971 ********************************************************************/
2973 static void spoolss_notify_attributes(struct messaging_context
*msg_ctx
,
2975 struct spoolss_Notify
*data
,
2976 print_queue_struct
*queue
,
2977 struct spoolss_PrinterInfo2
*pinfo2
,
2978 TALLOC_CTX
*mem_ctx
)
2980 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->attributes
);
2983 /*******************************************************************
2984 * fill a notify_info_data with the priority
2985 ********************************************************************/
2987 static void spoolss_notify_priority(struct messaging_context
*msg_ctx
,
2989 struct spoolss_Notify
*data
,
2990 print_queue_struct
*queue
,
2991 struct spoolss_PrinterInfo2
*pinfo2
,
2992 TALLOC_CTX
*mem_ctx
)
2994 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->priority
);
2997 /*******************************************************************
2998 * fill a notify_info_data with the default priority
2999 ********************************************************************/
3001 static void spoolss_notify_default_priority(struct messaging_context
*msg_ctx
,
3003 struct spoolss_Notify
*data
,
3004 print_queue_struct
*queue
,
3005 struct spoolss_PrinterInfo2
*pinfo2
,
3006 TALLOC_CTX
*mem_ctx
)
3008 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->defaultpriority
);
3011 /*******************************************************************
3012 * fill a notify_info_data with the start time
3013 ********************************************************************/
3015 static void spoolss_notify_start_time(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_INTEGER(data
, pinfo2
->starttime
);
3025 /*******************************************************************
3026 * fill a notify_info_data with the until time
3027 ********************************************************************/
3029 static void spoolss_notify_until_time(struct messaging_context
*msg_ctx
,
3031 struct spoolss_Notify
*data
,
3032 print_queue_struct
*queue
,
3033 struct spoolss_PrinterInfo2
*pinfo2
,
3034 TALLOC_CTX
*mem_ctx
)
3036 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->untiltime
);
3039 /*******************************************************************
3040 * fill a notify_info_data with the status
3041 ********************************************************************/
3043 static void spoolss_notify_status(struct messaging_context
*msg_ctx
,
3045 struct spoolss_Notify
*data
,
3046 print_queue_struct
*queue
,
3047 struct spoolss_PrinterInfo2
*pinfo2
,
3048 TALLOC_CTX
*mem_ctx
)
3050 print_status_struct status
;
3052 print_queue_length(msg_ctx
, snum
, &status
);
3053 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, status
.status
);
3056 /*******************************************************************
3057 * fill a notify_info_data with the number of jobs queued
3058 ********************************************************************/
3060 static void spoolss_notify_cjobs(struct messaging_context
*msg_ctx
,
3062 struct spoolss_Notify
*data
,
3063 print_queue_struct
*queue
,
3064 struct spoolss_PrinterInfo2
*pinfo2
,
3065 TALLOC_CTX
*mem_ctx
)
3067 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(
3068 data
, print_queue_length(msg_ctx
, snum
, NULL
));
3071 /*******************************************************************
3072 * fill a notify_info_data with the average ppm
3073 ********************************************************************/
3075 static void spoolss_notify_average_ppm(struct messaging_context
*msg_ctx
,
3077 struct spoolss_Notify
*data
,
3078 print_queue_struct
*queue
,
3079 struct spoolss_PrinterInfo2
*pinfo2
,
3080 TALLOC_CTX
*mem_ctx
)
3082 /* always respond 8 pages per minutes */
3083 /* a little hard ! */
3084 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->averageppm
);
3087 /*******************************************************************
3088 * fill a notify_info_data with username
3089 ********************************************************************/
3091 static void spoolss_notify_username(struct messaging_context
*msg_ctx
,
3093 struct spoolss_Notify
*data
,
3094 print_queue_struct
*queue
,
3095 struct spoolss_PrinterInfo2
*pinfo2
,
3096 TALLOC_CTX
*mem_ctx
)
3098 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, queue
->fs_user
);
3101 /*******************************************************************
3102 * fill a notify_info_data with job status
3103 ********************************************************************/
3105 static void spoolss_notify_job_status(struct messaging_context
*msg_ctx
,
3107 struct spoolss_Notify
*data
,
3108 print_queue_struct
*queue
,
3109 struct spoolss_PrinterInfo2
*pinfo2
,
3110 TALLOC_CTX
*mem_ctx
)
3112 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, nt_printj_status(queue
->status
));
3115 /*******************************************************************
3116 * fill a notify_info_data with job name
3117 ********************************************************************/
3119 static void spoolss_notify_job_name(struct messaging_context
*msg_ctx
,
3121 struct spoolss_Notify
*data
,
3122 print_queue_struct
*queue
,
3123 struct spoolss_PrinterInfo2
*pinfo2
,
3124 TALLOC_CTX
*mem_ctx
)
3126 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, queue
->fs_file
);
3129 /*******************************************************************
3130 * fill a notify_info_data with job status
3131 ********************************************************************/
3133 static void spoolss_notify_job_status_string(struct messaging_context
*msg_ctx
,
3135 struct spoolss_Notify
*data
,
3136 print_queue_struct
*queue
,
3137 struct spoolss_PrinterInfo2
*pinfo2
,
3138 TALLOC_CTX
*mem_ctx
)
3141 * Now we're returning job status codes we just return a "" here. JRA.
3146 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
3149 switch (queue
->status
) {
3154 p
= ""; /* NT provides the paused string */
3163 #endif /* NO LONGER NEEDED. */
3165 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, p
);
3168 /*******************************************************************
3169 * fill a notify_info_data with job time
3170 ********************************************************************/
3172 static void spoolss_notify_job_time(struct messaging_context
*msg_ctx
,
3174 struct spoolss_Notify
*data
,
3175 print_queue_struct
*queue
,
3176 struct spoolss_PrinterInfo2
*pinfo2
,
3177 TALLOC_CTX
*mem_ctx
)
3179 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, 0);
3182 /*******************************************************************
3183 * fill a notify_info_data with job size
3184 ********************************************************************/
3186 static void spoolss_notify_job_size(struct messaging_context
*msg_ctx
,
3188 struct spoolss_Notify
*data
,
3189 print_queue_struct
*queue
,
3190 struct spoolss_PrinterInfo2
*pinfo2
,
3191 TALLOC_CTX
*mem_ctx
)
3193 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, queue
->size
);
3196 /*******************************************************************
3197 * fill a notify_info_data with page info
3198 ********************************************************************/
3199 static void spoolss_notify_total_pages(struct messaging_context
*msg_ctx
,
3201 struct spoolss_Notify
*data
,
3202 print_queue_struct
*queue
,
3203 struct spoolss_PrinterInfo2
*pinfo2
,
3204 TALLOC_CTX
*mem_ctx
)
3206 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, queue
->page_count
);
3209 /*******************************************************************
3210 * fill a notify_info_data with pages printed info.
3211 ********************************************************************/
3212 static void spoolss_notify_pages_printed(struct messaging_context
*msg_ctx
,
3214 struct spoolss_Notify
*data
,
3215 print_queue_struct
*queue
,
3216 struct spoolss_PrinterInfo2
*pinfo2
,
3217 TALLOC_CTX
*mem_ctx
)
3219 /* Add code when back-end tracks this */
3220 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, 0);
3223 /*******************************************************************
3224 Fill a notify_info_data with job position.
3225 ********************************************************************/
3227 static void spoolss_notify_job_position(struct messaging_context
*msg_ctx
,
3229 struct spoolss_Notify
*data
,
3230 print_queue_struct
*queue
,
3231 struct spoolss_PrinterInfo2
*pinfo2
,
3232 TALLOC_CTX
*mem_ctx
)
3234 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, queue
->sysjob
);
3237 /*******************************************************************
3238 Fill a notify_info_data with submitted time.
3239 ********************************************************************/
3241 static void spoolss_notify_submitted_time(struct messaging_context
*msg_ctx
,
3243 struct spoolss_Notify
*data
,
3244 print_queue_struct
*queue
,
3245 struct spoolss_PrinterInfo2
*pinfo2
,
3246 TALLOC_CTX
*mem_ctx
)
3248 data
->data
.string
.string
= NULL
;
3249 data
->data
.string
.size
= 0;
3251 init_systemtime_buffer(mem_ctx
, gmtime(&queue
->time
),
3252 &data
->data
.string
.string
,
3253 &data
->data
.string
.size
);
3257 struct s_notify_info_data_table
3259 enum spoolss_NotifyType type
;
3262 enum spoolss_NotifyTable variable_type
;
3263 void (*fn
) (struct messaging_context
*msg_ctx
,
3264 int snum
, struct spoolss_Notify
*data
,
3265 print_queue_struct
*queue
,
3266 struct spoolss_PrinterInfo2
*pinfo2
,
3267 TALLOC_CTX
*mem_ctx
);
3270 /* A table describing the various print notification constants and
3271 whether the notification data is a pointer to a variable sized
3272 buffer, a one value uint32_t or a two value uint32_t. */
3274 static const struct s_notify_info_data_table notify_info_data_table
[] =
3276 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_SERVER_NAME
, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_server_name
},
3277 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PRINTER_NAME
, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_printer_name
},
3278 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_SHARE_NAME
, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_share_name
},
3279 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PORT_NAME
, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_port_name
},
3280 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_DRIVER_NAME
, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_driver_name
},
3281 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_COMMENT
, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING
, spoolss_notify_comment
},
3282 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_LOCATION
, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING
, spoolss_notify_location
},
3283 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_DEVMODE
, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE
, spoolss_notify_devmode
},
3284 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_SEPFILE
, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING
, spoolss_notify_sepfile
},
3285 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR
, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING
, spoolss_notify_print_processor
},
3286 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PARAMETERS
, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING
, spoolss_notify_parameters
},
3287 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_DATATYPE
, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING
, spoolss_notify_datatype
},
3288 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR
, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR
, spoolss_notify_security_desc
},
3289 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_ATTRIBUTES
, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD
, spoolss_notify_attributes
},
3290 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PRIORITY
, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD
, spoolss_notify_priority
},
3291 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY
, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD
, spoolss_notify_default_priority
},
3292 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_START_TIME
, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_start_time
},
3293 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_UNTIL_TIME
, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_until_time
},
3294 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_STATUS
, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD
, spoolss_notify_status
},
3295 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_STATUS_STRING
, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING
, NULL
},
3296 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_CJOBS
, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD
, spoolss_notify_cjobs
},
3297 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_AVERAGE_PPM
, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD
, spoolss_notify_average_ppm
},
3298 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_TOTAL_PAGES
, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD
, NULL
},
3299 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PAGES_PRINTED
, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD
, NULL
},
3300 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_TOTAL_BYTES
, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD
, NULL
},
3301 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_BYTES_PRINTED
, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD
, NULL
},
3302 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PRINTER_NAME
, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_printer_name
},
3303 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_MACHINE_NAME
, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_server_name
},
3304 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PORT_NAME
, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_port_name
},
3305 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_USER_NAME
, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_username
},
3306 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_NOTIFY_NAME
, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_username
},
3307 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_DATATYPE
, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING
, spoolss_notify_datatype
},
3308 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PRINT_PROCESSOR
, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING
, spoolss_notify_print_processor
},
3309 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PARAMETERS
, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING
, spoolss_notify_parameters
},
3310 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_DRIVER_NAME
, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_driver_name
},
3311 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_DEVMODE
, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE
, spoolss_notify_devmode
},
3312 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_STATUS
, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD
, spoolss_notify_job_status
},
3313 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_STATUS_STRING
, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING
, spoolss_notify_job_status_string
},
3314 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR
, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR
, NULL
},
3315 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_DOCUMENT
, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING
, spoolss_notify_job_name
},
3316 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PRIORITY
, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD
, spoolss_notify_priority
},
3317 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_POSITION
, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD
, spoolss_notify_job_position
},
3318 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_SUBMITTED
, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME
, spoolss_notify_submitted_time
},
3319 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_START_TIME
, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_start_time
},
3320 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_UNTIL_TIME
, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_until_time
},
3321 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_TIME
, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_job_time
},
3322 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_TOTAL_PAGES
, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD
, spoolss_notify_total_pages
},
3323 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PAGES_PRINTED
, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD
, spoolss_notify_pages_printed
},
3324 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_TOTAL_BYTES
, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD
, spoolss_notify_job_size
},
3327 /*******************************************************************
3328 Return the variable_type of info_data structure.
3329 ********************************************************************/
3331 static enum spoolss_NotifyTable
variable_type_of_notify_info_data(enum spoolss_NotifyType type
,
3336 for (i
= 0; i
< ARRAY_SIZE(notify_info_data_table
); i
++) {
3337 if ( (notify_info_data_table
[i
].type
== type
) &&
3338 (notify_info_data_table
[i
].field
== field
) ) {
3339 return notify_info_data_table
[i
].variable_type
;
3343 DEBUG(5, ("invalid notify data type %d/%d\n", type
, field
));
3345 return (enum spoolss_NotifyTable
) 0;
3348 /****************************************************************************
3349 ****************************************************************************/
3351 static bool search_notify(enum spoolss_NotifyType type
,
3357 for (i
= 0; i
< ARRAY_SIZE(notify_info_data_table
); i
++) {
3358 if (notify_info_data_table
[i
].type
== type
&&
3359 notify_info_data_table
[i
].field
== field
&&
3360 notify_info_data_table
[i
].fn
!= NULL
) {
3369 /****************************************************************************
3370 ****************************************************************************/
3372 static void construct_info_data(struct spoolss_Notify
*info_data
,
3373 enum spoolss_NotifyType type
,
3374 uint16_t field
, int id
)
3376 info_data
->type
= type
;
3377 info_data
->field
.field
= field
;
3378 info_data
->variable_type
= variable_type_of_notify_info_data(type
, field
);
3379 info_data
->job_id
= id
;
3382 /*******************************************************************
3384 * fill a notify_info struct with info asked
3386 ********************************************************************/
3388 static bool construct_notify_printer_info(struct messaging_context
*msg_ctx
,
3389 struct printer_handle
*print_hnd
,
3390 struct spoolss_NotifyInfo
*info
,
3391 struct spoolss_PrinterInfo2
*pinfo2
,
3393 const struct spoolss_NotifyOptionType
*option_type
,
3395 TALLOC_CTX
*mem_ctx
)
3397 const struct loadparm_substitution
*lp_sub
=
3398 loadparm_s3_global_substitution();
3400 enum spoolss_NotifyType type
;
3403 struct spoolss_Notify
*current_data
;
3405 type
= option_type
->type
;
3407 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3408 (type
== PRINTER_NOTIFY_TYPE
? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3409 option_type
->count
, lp_servicename(talloc_tos(), lp_sub
, snum
)));
3411 for(field_num
=0; field_num
< option_type
->count
; field_num
++) {
3412 field
= option_type
->fields
[field_num
].field
;
3414 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num
, type
, field
));
3416 if (!search_notify(type
, field
, &j
) )
3419 info
->notifies
= talloc_realloc(info
, info
->notifies
,
3420 struct spoolss_Notify
,
3422 if (info
->notifies
== NULL
) {
3423 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3427 current_data
= &info
->notifies
[info
->count
];
3429 construct_info_data(current_data
, type
, field
, id
);
3431 DEBUG(10, ("construct_notify_printer_info: "
3432 "calling [%s] snum=%d printername=[%s])\n",
3433 notify_info_data_table
[j
].name
, snum
,
3434 pinfo2
->printername
));
3436 notify_info_data_table
[j
].fn(msg_ctx
, snum
, current_data
,
3437 NULL
, pinfo2
, mem_ctx
);
3445 /*******************************************************************
3447 * fill a notify_info struct with info asked
3449 ********************************************************************/
3451 static bool construct_notify_jobs_info(struct messaging_context
*msg_ctx
,
3452 print_queue_struct
*queue
,
3453 struct spoolss_NotifyInfo
*info
,
3454 struct spoolss_PrinterInfo2
*pinfo2
,
3456 const struct spoolss_NotifyOptionType
*option_type
,
3458 TALLOC_CTX
*mem_ctx
)
3461 enum spoolss_NotifyType type
;
3463 struct spoolss_Notify
*current_data
;
3465 DEBUG(4,("construct_notify_jobs_info\n"));
3467 type
= option_type
->type
;
3469 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3470 (type
== PRINTER_NOTIFY_TYPE
? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3471 option_type
->count
));
3473 for(field_num
=0; field_num
<option_type
->count
; field_num
++) {
3474 field
= option_type
->fields
[field_num
].field
;
3476 if (!search_notify(type
, field
, &j
) )
3479 info
->notifies
= talloc_realloc(info
, info
->notifies
,
3480 struct spoolss_Notify
,
3482 if (info
->notifies
== NULL
) {
3483 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3487 current_data
=&(info
->notifies
[info
->count
]);
3489 construct_info_data(current_data
, type
, field
, id
);
3490 notify_info_data_table
[j
].fn(msg_ctx
, snum
, current_data
,
3491 queue
, pinfo2
, mem_ctx
);
3499 * JFM: The enumeration is not that simple, it's even non obvious.
3501 * let's take an example: I want to monitor the PRINTER SERVER for
3502 * the printer's name and the number of jobs currently queued.
3503 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3504 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3506 * I have 3 printers on the back of my server.
3508 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3511 * 1 printer 1 name 1
3512 * 2 printer 1 cjob 1
3513 * 3 printer 2 name 2
3514 * 4 printer 2 cjob 2
3515 * 5 printer 3 name 3
3516 * 6 printer 3 name 3
3518 * that's the print server case, the printer case is even worse.
3521 /*******************************************************************
3523 * enumerate all printers on the printserver
3524 * fill a notify_info struct with info asked
3526 ********************************************************************/
3528 static WERROR
printserver_notify_info(struct pipes_struct
*p
,
3529 struct policy_handle
*hnd
,
3530 struct spoolss_NotifyInfo
*info
,
3531 TALLOC_CTX
*mem_ctx
)
3533 const struct loadparm_substitution
*lp_sub
=
3534 loadparm_s3_global_substitution();
3536 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, hnd
);
3537 int n_services
=lp_numservices();
3539 struct spoolss_NotifyOption
*option
;
3540 struct spoolss_NotifyOptionType option_type
;
3541 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
3544 DEBUG(4,("printserver_notify_info\n"));
3547 return WERR_INVALID_HANDLE
;
3549 option
= Printer
->notify
.option
;
3552 info
->notifies
= NULL
;
3555 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3556 sending a ffpcn() request first */
3559 return WERR_INVALID_HANDLE
;
3561 for (i
=0; i
<option
->count
; i
++) {
3562 option_type
= option
->types
[i
];
3564 if (option_type
.type
!= PRINTER_NOTIFY_TYPE
)
3567 for (snum
= 0; snum
< n_services
; snum
++) {
3568 if (!lp_browseable(snum
) ||
3569 !lp_snum_ok(snum
) ||
3570 !lp_printable(snum
)) {
3571 continue; /* skip */
3574 /* Maybe we should use the SYSTEM session_info here... */
3575 result
= winreg_get_printer_internal(mem_ctx
,
3576 get_session_info_system(),
3578 lp_servicename(talloc_tos(), lp_sub
, snum
),
3580 if (!W_ERROR_IS_OK(result
)) {
3581 DEBUG(4, ("printserver_notify_info: "
3582 "Failed to get printer [%s]\n",
3583 lp_servicename(talloc_tos(), lp_sub
, snum
)));
3588 construct_notify_printer_info(p
->msg_ctx
,
3594 TALLOC_FREE(pinfo2
);
3600 * Debugging information, don't delete.
3603 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3604 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info
->version
, info
->flags
, info
->count
));
3605 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3607 for (i
=0; i
<info
->count
; i
++) {
3608 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3609 i
, info
->data
[i
].type
, info
->data
[i
].field
, info
->data
[i
].reserved
,
3610 info
->data
[i
].id
, info
->data
[i
].size
, info
->data
[i
].enc_type
));
3617 /*******************************************************************
3619 * fill a notify_info struct with info asked
3621 ********************************************************************/
3623 static WERROR
printer_notify_info(struct pipes_struct
*p
,
3624 struct policy_handle
*hnd
,
3625 struct spoolss_NotifyInfo
*info
,
3626 TALLOC_CTX
*mem_ctx
)
3628 const struct loadparm_substitution
*lp_sub
=
3629 loadparm_s3_global_substitution();
3631 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, hnd
);
3634 struct spoolss_NotifyOption
*option
;
3635 struct spoolss_NotifyOptionType option_type
;
3637 print_queue_struct
*queue
=NULL
;
3638 print_status_struct status
;
3639 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
3641 struct tdb_print_db
*pdb
;
3643 DEBUG(4,("printer_notify_info\n"));
3646 return WERR_INVALID_HANDLE
;
3648 option
= Printer
->notify
.option
;
3652 info
->notifies
= NULL
;
3655 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3656 sending a ffpcn() request first */
3659 return WERR_INVALID_HANDLE
;
3661 if (!get_printer_snum(p
, hnd
, &snum
, NULL
)) {
3662 return WERR_INVALID_HANDLE
;
3665 pdb
= get_print_db_byname(Printer
->sharename
);
3667 return WERR_INVALID_HANDLE
;
3670 /* Maybe we should use the SYSTEM session_info here... */
3671 result
= winreg_get_printer_internal(mem_ctx
,
3672 get_session_info_system(),
3674 lp_servicename(talloc_tos(), lp_sub
, snum
), &pinfo2
);
3675 if (!W_ERROR_IS_OK(result
)) {
3676 result
= WERR_INVALID_HANDLE
;
3681 * When sending a PRINTER_NOTIFY_FIELD_SERVER_NAME we should send the
3682 * correct servername.
3684 pinfo2
->servername
= talloc_strdup(pinfo2
, Printer
->servername
);
3685 if (pinfo2
->servername
== NULL
) {
3686 result
= WERR_NOT_ENOUGH_MEMORY
;
3690 for (i
= 0; i
< option
->count
; i
++) {
3691 option_type
= option
->types
[i
];
3693 switch (option_type
.type
) {
3694 case PRINTER_NOTIFY_TYPE
:
3695 if (construct_notify_printer_info(p
->msg_ctx
,
3704 case JOB_NOTIFY_TYPE
:
3706 count
= print_queue_status(p
->msg_ctx
, snum
, &queue
,
3709 for (j
= 0; j
< count
; j
++) {
3711 jobid
= sysjob_to_jobid_pdb(pdb
,
3713 if (jobid
== (uint32_t)-1) {
3714 DEBUG(2, ("ignoring untracked job %d\n",
3718 /* FIXME check return value */
3719 construct_notify_jobs_info(p
->msg_ctx
,
3733 * Debugging information, don't delete.
3736 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3737 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3738 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3740 for (i=0; i<info->count; i++) {
3741 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3742 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3743 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3747 talloc_free(pinfo2
);
3750 release_print_db(pdb
);
3754 /****************************************************************
3755 _spoolss_RouterRefreshPrinterChangeNotify
3756 ****************************************************************/
3758 WERROR
_spoolss_RouterRefreshPrinterChangeNotify(struct pipes_struct
*p
,
3759 struct spoolss_RouterRefreshPrinterChangeNotify
*r
)
3761 struct spoolss_NotifyInfo
*info
;
3763 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
3764 WERROR result
= WERR_INVALID_HANDLE
;
3766 /* we always have a spoolss_NotifyInfo struct */
3767 info
= talloc_zero(p
->mem_ctx
, struct spoolss_NotifyInfo
);
3769 result
= WERR_NOT_ENOUGH_MEMORY
;
3773 *r
->out
.info
= info
;
3776 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3777 "Invalid handle (%s:%u:%u).\n",
3778 OUR_HANDLE(r
->in
.handle
)));
3782 DEBUG(4,("Printer type %x\n",Printer
->printer_type
));
3785 * We are now using the change value, and
3786 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3787 * I don't have a global notification system, I'm sending back all the
3788 * information even when _NOTHING_ has changed.
3791 /* We need to keep track of the change value to send back in
3792 RRPCN replies otherwise our updates are ignored. */
3794 Printer
->notify
.fnpcn
= true;
3796 if (Printer
->notify
.cli_chan
!= NULL
&&
3797 Printer
->notify
.cli_chan
->active_connections
> 0) {
3798 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3799 "Saving change value in request [%x]\n",
3801 Printer
->notify
.change
= r
->in
.change_low
;
3804 /* just ignore the spoolss_NotifyOption */
3806 switch (Printer
->printer_type
) {
3808 result
= printserver_notify_info(p
, r
->in
.handle
,
3812 case SPLHND_PRINTER
:
3813 result
= printer_notify_info(p
, r
->in
.handle
,
3818 Printer
->notify
.fnpcn
= false;
3824 /********************************************************************
3825 ********************************************************************/
3827 static WERROR
create_printername(TALLOC_CTX
*mem_ctx
,
3828 const char *servername
,
3829 const char *printername
,
3830 const char **printername_p
)
3832 /* FIXME: add lp_force_printername() */
3834 if (servername
== NULL
) {
3835 *printername_p
= talloc_strdup(mem_ctx
, printername
);
3836 W_ERROR_HAVE_NO_MEMORY(*printername_p
);
3840 if (servername
[0] == '\\' && servername
[1] == '\\') {
3844 *printername_p
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s", servername
, printername
);
3845 W_ERROR_HAVE_NO_MEMORY(*printername_p
);
3850 /********************************************************************
3851 ********************************************************************/
3853 static void compose_devicemode_devicename(struct spoolss_DeviceMode
*dm
,
3854 const char *printername
)
3860 dm
->devicename
= talloc_strndup(dm
, printername
,
3861 MIN(strlen(printername
), 31));
3864 /********************************************************************
3865 * construct_printer_info_0
3866 * fill a printer_info_0 struct
3867 ********************************************************************/
3869 static WERROR
construct_printer_info0(TALLOC_CTX
*mem_ctx
,
3870 const struct auth_session_info
*session_info
,
3871 struct messaging_context
*msg_ctx
,
3872 struct spoolss_PrinterInfo2
*info2
,
3873 const char *servername
,
3874 struct spoolss_PrinterInfo0
*r
,
3878 struct printer_session_counter
*session_counter
;
3879 struct timeval setuptime
;
3880 print_status_struct status
;
3882 int os_major
, os_minor
, os_build
;
3883 const char *architecture
;
3884 uint32_t processor_architecture
, processor_type
;
3886 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->printername
);
3887 if (!W_ERROR_IS_OK(result
)) {
3892 r
->servername
= talloc_strdup(mem_ctx
, servername
);
3893 W_ERROR_HAVE_NO_MEMORY(r
->servername
);
3895 r
->servername
= NULL
;
3898 count
= print_queue_length(msg_ctx
, snum
, &status
);
3900 /* check if we already have a counter for this printer */
3901 for (session_counter
= counter_list
; session_counter
; session_counter
= session_counter
->next
) {
3902 if (session_counter
->snum
== snum
)
3906 /* it's the first time, add it to the list */
3907 if (session_counter
== NULL
) {
3908 session_counter
= talloc_zero(counter_list
, struct printer_session_counter
);
3909 W_ERROR_HAVE_NO_MEMORY(session_counter
);
3910 session_counter
->snum
= snum
;
3911 session_counter
->counter
= 0;
3912 DLIST_ADD(counter_list
, session_counter
);
3916 session_counter
->counter
++;
3922 get_startup_time(&setuptime
);
3923 init_systemtime(&r
->time
, gmtime(&setuptime
.tv_sec
));
3926 * the global_counter should be stored in a TDB as it's common to all the clients
3927 * and should be zeroed on samba startup
3929 r
->global_counter
= session_counter
->counter
;
3932 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3933 os_major
= lp_parm_int(GLOBAL_SECTION_SNUM
,
3934 "spoolss", "os_major",
3935 GLOBAL_SPOOLSS_OS_MAJOR_DEFAULT
);
3936 os_minor
= lp_parm_int(GLOBAL_SECTION_SNUM
,
3937 "spoolss", "os_minor",
3938 GLOBAL_SPOOLSS_OS_MINOR_DEFAULT
);
3939 os_build
= lp_parm_int(GLOBAL_SECTION_SNUM
,
3940 "spoolss", "os_build",
3941 GLOBAL_SPOOLSS_OS_BUILD_DEFAULT
);
3943 SCVAL(&r
->version
, 0, os_major
);
3944 SCVAL(&r
->version
, 1, os_minor
);
3945 SSVAL(&r
->version
, 2, os_build
);
3947 architecture
= lp_parm_const_string(GLOBAL_SECTION_SNUM
,
3950 GLOBAL_SPOOLSS_ARCHITECTURE
);
3952 if (strequal(architecture
, SPOOLSS_ARCHITECTURE_x64
)) {
3953 processor_architecture
= PROCESSOR_ARCHITECTURE_AMD64
;
3954 processor_type
= PROCESSOR_AMD_X8664
;
3956 processor_architecture
= PROCESSOR_ARCHITECTURE_INTEL
;
3957 processor_type
= PROCESSOR_INTEL_PENTIUM
;
3960 r
->free_build
= SPOOLSS_RELEASE_BUILD
;
3962 r
->max_spooling
= 0;
3963 r
->session_counter
= session_counter
->counter
;
3964 r
->num_error_out_of_paper
= 0x0;
3965 r
->num_error_not_ready
= 0x0; /* number of print failure */
3967 r
->number_of_processors
= 0x1;
3968 r
->processor_type
= processor_type
;
3969 r
->high_part_total_bytes
= 0x0;
3971 /* ChangeID in milliseconds*/
3972 winreg_printer_get_changeid_internal(mem_ctx
, session_info
, msg_ctx
,
3973 info2
->sharename
, &r
->change_id
);
3975 r
->last_error
= WERR_OK
;
3976 r
->status
= nt_printq_status(status
.status
);
3977 r
->enumerate_network_printers
= 0x0;
3978 r
->c_setprinter
= 0x0;
3979 r
->processor_architecture
= processor_architecture
;
3980 r
->processor_level
= 0x6; /* 6 ???*/
3989 /********************************************************************
3990 * construct_printer_info1
3991 * fill a spoolss_PrinterInfo1 struct
3992 ********************************************************************/
3994 static WERROR
construct_printer_info1(TALLOC_CTX
*mem_ctx
,
3995 const struct spoolss_PrinterInfo2
*info2
,
3997 const char *servername
,
3998 struct spoolss_PrinterInfo1
*r
,
4001 const struct loadparm_substitution
*lp_sub
=
4002 loadparm_s3_global_substitution();
4007 if (info2
->comment
== NULL
|| info2
->comment
[0] == '\0') {
4008 r
->comment
= lp_comment(mem_ctx
, lp_sub
, snum
);
4010 r
->comment
= talloc_strdup(mem_ctx
, info2
->comment
); /* saved comment */
4012 W_ERROR_HAVE_NO_MEMORY(r
->comment
);
4014 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->name
);
4015 if (!W_ERROR_IS_OK(result
)) {
4019 r
->description
= talloc_asprintf(mem_ctx
, "%s,%s,%s",
4023 W_ERROR_HAVE_NO_MEMORY(r
->description
);
4028 /********************************************************************
4029 * construct_printer_info2
4030 * fill a spoolss_PrinterInfo2 struct
4031 ********************************************************************/
4033 static WERROR
construct_printer_info2(TALLOC_CTX
*mem_ctx
,
4034 struct messaging_context
*msg_ctx
,
4035 const struct spoolss_PrinterInfo2
*info2
,
4036 const char *servername
,
4037 struct spoolss_PrinterInfo2
*r
,
4040 const struct loadparm_substitution
*lp_sub
=
4041 loadparm_s3_global_substitution();
4043 print_status_struct status
;
4046 count
= print_queue_length(msg_ctx
, snum
, &status
);
4049 r
->servername
= talloc_strdup(mem_ctx
, servername
);
4050 W_ERROR_HAVE_NO_MEMORY(r
->servername
);
4052 r
->servername
= NULL
;
4055 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->printername
);
4056 if (!W_ERROR_IS_OK(result
)) {
4060 r
->sharename
= lp_servicename(mem_ctx
, lp_sub
, snum
);
4061 W_ERROR_HAVE_NO_MEMORY(r
->sharename
);
4062 r
->portname
= talloc_strdup(mem_ctx
, info2
->portname
);
4063 W_ERROR_HAVE_NO_MEMORY(r
->portname
);
4064 r
->drivername
= talloc_strdup(mem_ctx
, info2
->drivername
);
4065 W_ERROR_HAVE_NO_MEMORY(r
->drivername
);
4067 if (info2
->comment
[0] == '\0') {
4068 r
->comment
= lp_comment(mem_ctx
, lp_sub
, snum
);
4070 r
->comment
= talloc_strdup(mem_ctx
, info2
->comment
);
4072 W_ERROR_HAVE_NO_MEMORY(r
->comment
);
4074 r
->location
= talloc_strdup(mem_ctx
, info2
->location
);
4075 if (info2
->location
[0] == '\0') {
4076 const char *loc
= NULL
;
4079 nt_status
= printer_list_get_printer(mem_ctx
,
4084 if (NT_STATUS_IS_OK(nt_status
)) {
4086 r
->location
= talloc_strdup(mem_ctx
, loc
);
4090 W_ERROR_HAVE_NO_MEMORY(r
->location
);
4092 r
->sepfile
= talloc_strdup(mem_ctx
, info2
->sepfile
);
4093 W_ERROR_HAVE_NO_MEMORY(r
->sepfile
);
4094 r
->printprocessor
= talloc_strdup(mem_ctx
, info2
->printprocessor
);
4095 W_ERROR_HAVE_NO_MEMORY(r
->printprocessor
);
4096 r
->datatype
= talloc_strdup(mem_ctx
, info2
->datatype
);
4097 W_ERROR_HAVE_NO_MEMORY(r
->datatype
);
4098 r
->parameters
= talloc_strdup(mem_ctx
, info2
->parameters
);
4099 W_ERROR_HAVE_NO_MEMORY(r
->parameters
);
4101 r
->attributes
= info2
->attributes
;
4103 r
->priority
= info2
->priority
;
4104 r
->defaultpriority
= info2
->defaultpriority
;
4105 r
->starttime
= info2
->starttime
;
4106 r
->untiltime
= info2
->untiltime
;
4107 r
->status
= nt_printq_status(status
.status
);
4109 r
->averageppm
= info2
->averageppm
;
4111 if (info2
->devmode
!= NULL
) {
4112 result
= copy_devicemode(mem_ctx
,
4115 if (!W_ERROR_IS_OK(result
)) {
4118 } else if (lp_default_devmode(snum
)) {
4119 result
= spoolss_create_default_devmode(mem_ctx
,
4122 if (!W_ERROR_IS_OK(result
)) {
4127 DEBUG(8,("Returning NULL Devicemode!\n"));
4130 compose_devicemode_devicename(r
->devmode
, r
->printername
);
4134 if (info2
->secdesc
!= NULL
) {
4135 /* don't use talloc_steal() here unless you do a deep steal of all
4136 the SEC_DESC members */
4138 r
->secdesc
= security_descriptor_copy(mem_ctx
, info2
->secdesc
);
4139 if (r
->secdesc
== NULL
) {
4140 return WERR_NOT_ENOUGH_MEMORY
;
4147 /********************************************************************
4148 * construct_printer_info3
4149 * fill a spoolss_PrinterInfo3 struct
4150 ********************************************************************/
4152 static WERROR
construct_printer_info3(TALLOC_CTX
*mem_ctx
,
4153 const struct spoolss_PrinterInfo2
*info2
,
4154 const char *servername
,
4155 struct spoolss_PrinterInfo3
*r
,
4158 /* These are the components of the SD we are returning. */
4160 if (info2
->secdesc
!= NULL
) {
4161 /* don't use talloc_steal() here unless you do a deep steal of all
4162 the SEC_DESC members */
4164 r
->secdesc
= security_descriptor_copy(mem_ctx
, info2
->secdesc
);
4165 if (r
->secdesc
== NULL
) {
4166 return WERR_NOT_ENOUGH_MEMORY
;
4173 /********************************************************************
4174 * construct_printer_info4
4175 * fill a spoolss_PrinterInfo4 struct
4176 ********************************************************************/
4178 static WERROR
construct_printer_info4(TALLOC_CTX
*mem_ctx
,
4179 const struct spoolss_PrinterInfo2
*info2
,
4180 const char *servername
,
4181 struct spoolss_PrinterInfo4
*r
,
4186 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->printername
);
4187 if (!W_ERROR_IS_OK(result
)) {
4192 r
->servername
= talloc_strdup(mem_ctx
, servername
);
4193 W_ERROR_HAVE_NO_MEMORY(r
->servername
);
4195 r
->servername
= NULL
;
4198 r
->attributes
= info2
->attributes
;
4203 /********************************************************************
4204 * construct_printer_info5
4205 * fill a spoolss_PrinterInfo5 struct
4206 ********************************************************************/
4208 static WERROR
construct_printer_info5(TALLOC_CTX
*mem_ctx
,
4209 const struct spoolss_PrinterInfo2
*info2
,
4210 const char *servername
,
4211 struct spoolss_PrinterInfo5
*r
,
4216 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->printername
);
4217 if (!W_ERROR_IS_OK(result
)) {
4221 r
->portname
= talloc_strdup(mem_ctx
, info2
->portname
);
4222 W_ERROR_HAVE_NO_MEMORY(r
->portname
);
4224 r
->attributes
= info2
->attributes
;
4227 * These two are not used by NT+ according to MSDN. However the values
4228 * we saw on Windows Server 2012 and 2016 are always set to the 0xafc8.
4230 r
->device_not_selected_timeout
= 0xafc8; /* 45 sec */
4231 r
->transmission_retry_timeout
= 0xafc8; /* 45 sec */
4236 /********************************************************************
4237 * construct_printer_info_6
4238 * fill a spoolss_PrinterInfo6 struct
4239 ********************************************************************/
4241 static WERROR
construct_printer_info6(TALLOC_CTX
*mem_ctx
,
4242 struct messaging_context
*msg_ctx
,
4243 const struct spoolss_PrinterInfo2
*info2
,
4244 const char *servername
,
4245 struct spoolss_PrinterInfo6
*r
,
4248 print_status_struct status
;
4250 print_queue_length(msg_ctx
, snum
, &status
);
4252 r
->status
= nt_printq_status(status
.status
);
4257 /********************************************************************
4258 * construct_printer_info7
4259 * fill a spoolss_PrinterInfo7 struct
4260 ********************************************************************/
4262 static WERROR
construct_printer_info7(TALLOC_CTX
*mem_ctx
,
4263 struct messaging_context
*msg_ctx
,
4264 const char *servername
,
4265 struct spoolss_PrinterInfo7
*r
,
4268 const struct loadparm_substitution
*lp_sub
=
4269 loadparm_s3_global_substitution();
4270 const struct auth_session_info
*session_info
;
4271 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
4274 TALLOC_CTX
*tmp_ctx
= talloc_new(mem_ctx
);
4275 if (tmp_ctx
== NULL
) {
4276 return WERR_NOT_ENOUGH_MEMORY
;
4279 session_info
= get_session_info_system();
4280 SMB_ASSERT(session_info
!= NULL
);
4282 printer
= lp_servicename(tmp_ctx
, lp_sub
, snum
);
4283 if (printer
== NULL
) {
4284 DEBUG(0, ("invalid printer snum %d\n", snum
));
4285 werr
= WERR_INVALID_PARAMETER
;
4289 if (is_printer_published(tmp_ctx
, session_info
, msg_ctx
,
4290 servername
, printer
, &pinfo2
)) {
4293 werr
= nt_printer_guid_get(tmp_ctx
, session_info
, msg_ctx
,
4295 if (!W_ERROR_IS_OK(werr
)) {
4297 * If we do not have a GUID entry in the registry, then
4298 * try to retrieve it from AD and store it now.
4300 werr
= nt_printer_guid_retrieve(tmp_ctx
, printer
,
4302 if (!W_ERROR_IS_OK(werr
)) {
4303 DBG_NOTICE("Failed to retrieve GUID for "
4304 "printer [%s] from AD - %s\n",
4307 if (W_ERROR_EQUAL(werr
, WERR_FILE_NOT_FOUND
)) {
4309 * If we did not find it in AD, then it
4310 * is unpublished and we should reflect
4311 * this in the registry and return
4314 DBG_WARNING("Unpublish printer [%s]\n",
4316 nt_printer_publish(tmp_ctx
,
4321 r
->guid
= talloc_strdup(mem_ctx
, "");
4322 r
->action
= DSPRINT_UNPUBLISH
;
4324 if (r
->guid
== NULL
) {
4325 werr
= WERR_NOT_ENOUGH_MEMORY
;
4333 werr
= nt_printer_guid_store(msg_ctx
, printer
, guid
);
4334 if (!W_ERROR_IS_OK(werr
)) {
4335 DEBUG(3, ("failed to store printer %s guid\n",
4340 /* [MS-RPRN] section 2.2: must use curly-braced GUIDs */
4341 guidstr
= GUID_string2(mem_ctx
, &guid
);
4342 if (guidstr
== NULL
) {
4343 werr
= WERR_NOT_ENOUGH_MEMORY
;
4346 /* Convert GUID string to uppercase otherwise printers
4348 r
->guid
= talloc_strdup_upper(mem_ctx
, guidstr
);
4349 r
->action
= DSPRINT_PUBLISH
;
4351 TALLOC_FREE(guidstr
);
4353 r
->guid
= talloc_strdup(mem_ctx
, "");
4354 r
->action
= DSPRINT_UNPUBLISH
;
4356 if (r
->guid
== NULL
) {
4357 werr
= WERR_NOT_ENOUGH_MEMORY
;
4363 talloc_free(tmp_ctx
);
4367 /********************************************************************
4368 * construct_printer_info8
4369 * fill a spoolss_PrinterInfo8 struct
4370 ********************************************************************/
4372 static WERROR
construct_printer_info8(TALLOC_CTX
*mem_ctx
,
4373 const struct spoolss_PrinterInfo2
*info2
,
4374 const char *servername
,
4375 struct spoolss_DeviceModeInfo
*r
,
4379 const char *printername
;
4381 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &printername
);
4382 if (!W_ERROR_IS_OK(result
)) {
4386 if (info2
->devmode
!= NULL
) {
4387 result
= copy_devicemode(mem_ctx
,
4390 if (!W_ERROR_IS_OK(result
)) {
4393 } else if (lp_default_devmode(snum
)) {
4394 result
= spoolss_create_default_devmode(mem_ctx
,
4397 if (!W_ERROR_IS_OK(result
)) {
4402 DEBUG(8,("Returning NULL Devicemode!\n"));
4405 compose_devicemode_devicename(r
->devmode
, printername
);
4410 /********************************************************************
4411 Spoolss_enumprinters.
4412 ********************************************************************/
4414 static WERROR
enum_all_printers_info_level(TALLOC_CTX
*mem_ctx
,
4415 const struct auth_session_info
*session_info
,
4416 struct messaging_context
*msg_ctx
,
4417 const char *servername
,
4420 union spoolss_PrinterInfo
**info_p
,
4425 union spoolss_PrinterInfo
*info
= NULL
;
4427 WERROR result
= WERR_OK
;
4428 struct dcerpc_binding_handle
*b
= NULL
;
4429 TALLOC_CTX
*tmp_ctx
= NULL
;
4431 tmp_ctx
= talloc_new(mem_ctx
);
4433 return WERR_NOT_ENOUGH_MEMORY
;
4437 * printer shares are updated on client enumeration. The background
4438 * printer process updates printer_list.tdb at regular intervals.
4441 delete_and_reload_printers();
4444 n_services
= lp_numservices();
4448 for (snum
= 0; snum
< n_services
; snum
++) {
4450 const char *printer
;
4451 struct spoolss_PrinterInfo2
*info2
;
4453 if (!snum_is_shared_printer(snum
)) {
4457 printer
= lp_const_servicename(snum
);
4459 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
4463 result
= winreg_printer_binding_handle(tmp_ctx
,
4467 if (!W_ERROR_IS_OK(result
)) {
4472 result
= winreg_create_printer(tmp_ctx
, b
,
4474 if (!W_ERROR_IS_OK(result
)) {
4478 info
= talloc_realloc(tmp_ctx
, info
,
4479 union spoolss_PrinterInfo
,
4482 result
= WERR_NOT_ENOUGH_MEMORY
;
4486 result
= winreg_get_printer(tmp_ctx
, b
,
4488 if (!W_ERROR_IS_OK(result
)) {
4494 result
= construct_printer_info0(info
, session_info
,
4497 &info
[count
].info0
, snum
);
4500 result
= construct_printer_info1(info
, info2
, flags
,
4502 &info
[count
].info1
, snum
);
4505 result
= construct_printer_info2(info
, msg_ctx
, info2
,
4507 &info
[count
].info2
, snum
);
4510 result
= construct_printer_info4(info
, info2
,
4512 &info
[count
].info4
, snum
);
4515 result
= construct_printer_info5(info
, info2
,
4517 &info
[count
].info5
, snum
);
4521 result
= WERR_INVALID_LEVEL
;
4525 if (!W_ERROR_IS_OK(result
)) {
4533 if (W_ERROR_IS_OK(result
)) {
4534 *info_p
= talloc_move(mem_ctx
, &info
);
4538 talloc_free(tmp_ctx
);
4543 /********************************************************************
4544 * handle enumeration of printers at level 0
4545 ********************************************************************/
4547 static WERROR
enumprinters_level0(TALLOC_CTX
*mem_ctx
,
4548 const struct auth_session_info
*session_info
,
4549 struct messaging_context
*msg_ctx
,
4551 const char *servername
,
4552 union spoolss_PrinterInfo
**info
,
4555 DEBUG(4,("enum_all_printers_info_0\n"));
4557 return enum_all_printers_info_level(mem_ctx
, session_info
, msg_ctx
,
4558 servername
, 0, flags
, info
, count
);
4562 /********************************************************************
4563 ********************************************************************/
4565 static WERROR
enum_all_printers_info_1(TALLOC_CTX
*mem_ctx
,
4566 const struct auth_session_info
*session_info
,
4567 struct messaging_context
*msg_ctx
,
4568 const char *servername
,
4570 union spoolss_PrinterInfo
**info
,
4573 DEBUG(4,("enum_all_printers_info_1\n"));
4575 return enum_all_printers_info_level(mem_ctx
, session_info
, msg_ctx
,
4576 servername
, 1, flags
, info
, count
);
4579 /********************************************************************
4580 enum_all_printers_info_1_local.
4581 *********************************************************************/
4583 static WERROR
enum_all_printers_info_1_local(TALLOC_CTX
*mem_ctx
,
4584 const struct auth_session_info
*session_info
,
4585 struct messaging_context
*msg_ctx
,
4586 const char *servername
,
4587 union spoolss_PrinterInfo
**info
,
4590 DEBUG(4,("enum_all_printers_info_1_local\n"));
4592 return enum_all_printers_info_1(mem_ctx
, session_info
, msg_ctx
,
4593 servername
, PRINTER_ENUM_ICON8
, info
, count
);
4596 /********************************************************************
4597 enum_all_printers_info_1_name.
4598 *********************************************************************/
4600 static WERROR
enum_all_printers_info_1_name(TALLOC_CTX
*mem_ctx
,
4601 const struct auth_session_info
*session_info
,
4602 struct messaging_context
*msg_ctx
,
4603 const char *servername
,
4604 union spoolss_PrinterInfo
**info
,
4607 const char *s
= servername
;
4609 DEBUG(4,("enum_all_printers_info_1_name\n"));
4611 if (servername
!= NULL
&&
4612 (servername
[0] == '\\') && (servername
[1] == '\\')) {
4616 if (!is_myname_or_ipaddr(s
)) {
4617 return WERR_INVALID_NAME
;
4620 return enum_all_printers_info_1(mem_ctx
, session_info
, msg_ctx
,
4621 servername
, PRINTER_ENUM_ICON8
, info
, count
);
4624 /********************************************************************
4625 enum_all_printers_info_1_network.
4626 *********************************************************************/
4628 static WERROR
enum_all_printers_info_1_network(TALLOC_CTX
*mem_ctx
,
4629 const struct auth_session_info
*session_info
,
4630 struct messaging_context
*msg_ctx
,
4631 const char *servername
,
4632 union spoolss_PrinterInfo
**info
,
4635 const char *s
= servername
;
4637 DEBUG(4,("enum_all_printers_info_1_network\n"));
4639 /* If we respond to a enum_printers level 1 on our name with flags
4640 set to PRINTER_ENUM_REMOTE with a list of printers then these
4641 printers incorrectly appear in the APW browse list.
4642 Specifically the printers for the server appear at the workgroup
4643 level where all the other servers in the domain are
4644 listed. Windows responds to this call with a
4645 WERR_CAN_NOT_COMPLETE so we should do the same. */
4647 if (servername
!= NULL
&&
4648 (servername
[0] == '\\') && (servername
[1] == '\\')) {
4652 if (is_myname_or_ipaddr(s
)) {
4653 return WERR_CAN_NOT_COMPLETE
;
4656 return enum_all_printers_info_1(mem_ctx
, session_info
, msg_ctx
,
4657 servername
, PRINTER_ENUM_NAME
, info
, count
);
4660 /********************************************************************
4661 * api_spoolss_enumprinters
4663 * called from api_spoolss_enumprinters (see this to understand)
4664 ********************************************************************/
4666 static WERROR
enum_all_printers_info_2(TALLOC_CTX
*mem_ctx
,
4667 const struct auth_session_info
*session_info
,
4668 struct messaging_context
*msg_ctx
,
4669 const char *servername
,
4670 union spoolss_PrinterInfo
**info
,
4673 DEBUG(4,("enum_all_printers_info_2\n"));
4675 return enum_all_printers_info_level(mem_ctx
, session_info
, msg_ctx
,
4676 servername
, 2, 0, info
, count
);
4679 /********************************************************************
4680 * handle enumeration of printers at level 1
4681 ********************************************************************/
4683 static WERROR
enumprinters_level1(TALLOC_CTX
*mem_ctx
,
4684 const struct auth_session_info
*session_info
,
4685 struct messaging_context
*msg_ctx
,
4687 const char *servername
,
4688 union spoolss_PrinterInfo
**info
,
4691 /* Not all the flags are equals */
4693 if (flags
& PRINTER_ENUM_LOCAL
) {
4694 return enum_all_printers_info_1_local(mem_ctx
, session_info
,
4695 msg_ctx
, servername
, info
, count
);
4698 if (flags
& PRINTER_ENUM_NAME
) {
4699 return enum_all_printers_info_1_name(mem_ctx
, session_info
,
4700 msg_ctx
, servername
, info
,
4704 if (flags
& PRINTER_ENUM_NETWORK
) {
4705 return enum_all_printers_info_1_network(mem_ctx
, session_info
,
4706 msg_ctx
, servername
, info
,
4710 return WERR_OK
; /* NT4sp5 does that */
4713 /********************************************************************
4714 * handle enumeration of printers at level 2
4715 ********************************************************************/
4717 static WERROR
enumprinters_level2(TALLOC_CTX
*mem_ctx
,
4718 const struct auth_session_info
*session_info
,
4719 struct messaging_context
*msg_ctx
,
4721 const char *servername
,
4722 union spoolss_PrinterInfo
**info
,
4725 if (flags
& PRINTER_ENUM_LOCAL
) {
4727 return enum_all_printers_info_2(mem_ctx
, session_info
, msg_ctx
,
4732 if (flags
& PRINTER_ENUM_NAME
) {
4733 if (servername
&& !is_myname_or_ipaddr(canon_servername(servername
))) {
4734 return WERR_INVALID_NAME
;
4737 return enum_all_printers_info_2(mem_ctx
, session_info
, msg_ctx
,
4742 if (flags
& PRINTER_ENUM_REMOTE
) {
4743 return WERR_INVALID_LEVEL
;
4749 /********************************************************************
4750 * handle enumeration of printers at level 4
4751 ********************************************************************/
4753 static WERROR
enumprinters_level4(TALLOC_CTX
*mem_ctx
,
4754 const struct auth_session_info
*session_info
,
4755 struct messaging_context
*msg_ctx
,
4757 const char *servername
,
4758 union spoolss_PrinterInfo
**info
,
4761 DEBUG(4,("enum_all_printers_info_4\n"));
4763 return enum_all_printers_info_level(mem_ctx
, session_info
, msg_ctx
,
4764 servername
, 4, flags
, info
, count
);
4768 /********************************************************************
4769 * handle enumeration of printers at level 5
4770 ********************************************************************/
4772 static WERROR
enumprinters_level5(TALLOC_CTX
*mem_ctx
,
4773 const struct auth_session_info
*session_info
,
4774 struct messaging_context
*msg_ctx
,
4776 const char *servername
,
4777 union spoolss_PrinterInfo
**info
,
4780 DEBUG(4,("enum_all_printers_info_5\n"));
4782 return enum_all_printers_info_level(mem_ctx
, session_info
, msg_ctx
,
4783 servername
, 5, flags
, info
, count
);
4786 /****************************************************************
4787 _spoolss_EnumPrinters
4788 ****************************************************************/
4790 WERROR
_spoolss_EnumPrinters(struct pipes_struct
*p
,
4791 struct spoolss_EnumPrinters
*r
)
4793 const struct auth_session_info
*session_info
= get_session_info_system();
4796 /* that's an [in out] buffer */
4798 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
4799 return WERR_INVALID_PARAMETER
;
4802 DEBUG(4,("_spoolss_EnumPrinters\n"));
4806 *r
->out
.info
= NULL
;
4810 * flags==PRINTER_ENUM_NAME
4811 * if name=="" then enumerates all printers
4812 * if name!="" then enumerate the printer
4813 * flags==PRINTER_ENUM_REMOTE
4814 * name is NULL, enumerate printers
4815 * Level 2: name!="" enumerates printers, name can't be NULL
4816 * Level 3: doesn't exist
4817 * Level 4: does a local registry lookup
4818 * Level 5: same as Level 2
4821 if (r
->in
.server
&& r
->in
.server
[0] == '\0') {
4822 r
->in
.server
= NULL
;
4825 switch (r
->in
.level
) {
4827 result
= enumprinters_level0(p
->mem_ctx
, session_info
,
4828 p
->msg_ctx
, r
->in
.flags
,
4830 r
->out
.info
, r
->out
.count
);
4833 result
= enumprinters_level1(p
->mem_ctx
, session_info
,
4834 p
->msg_ctx
, r
->in
.flags
,
4836 r
->out
.info
, r
->out
.count
);
4839 result
= enumprinters_level2(p
->mem_ctx
, session_info
,
4840 p
->msg_ctx
, r
->in
.flags
,
4842 r
->out
.info
, r
->out
.count
);
4845 result
= enumprinters_level4(p
->mem_ctx
, session_info
,
4846 p
->msg_ctx
, r
->in
.flags
,
4848 r
->out
.info
, r
->out
.count
);
4851 result
= enumprinters_level5(p
->mem_ctx
, session_info
,
4852 p
->msg_ctx
, r
->in
.flags
,
4854 r
->out
.info
, r
->out
.count
);
4857 return WERR_INVALID_LEVEL
;
4860 if (!W_ERROR_IS_OK(result
)) {
4864 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
4865 spoolss_EnumPrinters
,
4866 *r
->out
.info
, r
->in
.level
,
4868 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
4869 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
4871 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
4874 /****************************************************************
4876 ****************************************************************/
4878 WERROR
_spoolss_GetPrinter(struct pipes_struct
*p
,
4879 struct spoolss_GetPrinter
*r
)
4881 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
4882 struct spoolss_PrinterInfo2
*info2
= NULL
;
4883 WERROR result
= WERR_OK
;
4886 /* that's an [in out] buffer */
4888 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
4889 result
= WERR_INVALID_PARAMETER
;
4895 if (Printer
== NULL
) {
4896 result
= WERR_INVALID_HANDLE
;
4900 if (Printer
->printer_type
== SPLHND_SERVER
) {
4902 struct dcerpc_binding_handle
*b
;
4904 if (r
->in
.level
!= 3) {
4905 result
= WERR_INVALID_LEVEL
;
4909 result
= winreg_printer_binding_handle(p
->mem_ctx
,
4910 get_session_info_system(),
4913 if (!W_ERROR_IS_OK(result
)) {
4917 result
= winreg_get_printserver_secdesc(p
->mem_ctx
,
4919 &r
->out
.info
->info3
.secdesc
);
4920 if (!W_ERROR_IS_OK(result
)) {
4927 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
4928 result
= WERR_INVALID_HANDLE
;
4932 result
= winreg_get_printer_internal(p
->mem_ctx
,
4933 get_session_info_system(),
4935 lp_const_servicename(snum
),
4937 if (!W_ERROR_IS_OK(result
)) {
4941 switch (r
->in
.level
) {
4943 result
= construct_printer_info0(p
->mem_ctx
,
4944 get_session_info_system(),
4947 Printer
->servername
,
4948 &r
->out
.info
->info0
,
4952 result
= construct_printer_info1(p
->mem_ctx
, info2
,
4954 Printer
->servername
,
4955 &r
->out
.info
->info1
, snum
);
4958 result
= construct_printer_info2(p
->mem_ctx
, p
->msg_ctx
, info2
,
4959 Printer
->servername
,
4960 &r
->out
.info
->info2
, snum
);
4963 result
= construct_printer_info3(p
->mem_ctx
, info2
,
4964 Printer
->servername
,
4965 &r
->out
.info
->info3
, snum
);
4968 result
= construct_printer_info4(p
->mem_ctx
, info2
,
4969 Printer
->servername
,
4970 &r
->out
.info
->info4
, snum
);
4973 result
= construct_printer_info5(p
->mem_ctx
, info2
,
4974 Printer
->servername
,
4975 &r
->out
.info
->info5
, snum
);
4978 result
= construct_printer_info6(p
->mem_ctx
, p
->msg_ctx
, info2
,
4979 Printer
->servername
,
4980 &r
->out
.info
->info6
, snum
);
4983 result
= construct_printer_info7(p
->mem_ctx
, p
->msg_ctx
,
4984 Printer
->servername
,
4985 &r
->out
.info
->info7
, snum
);
4988 result
= construct_printer_info8(p
->mem_ctx
, info2
,
4989 Printer
->servername
,
4990 &r
->out
.info
->info8
, snum
);
4993 result
= WERR_INVALID_LEVEL
;
4998 if (!W_ERROR_IS_OK(result
)) {
4999 DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
5000 r
->in
.level
, win_errstr(result
)));
5004 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo
,
5005 r
->out
.info
, r
->in
.level
);
5006 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
5008 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
5011 TALLOC_FREE(r
->out
.info
);
5015 /********************************************************************
5016 ********************************************************************/
5018 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
5020 if (in && strlen(in)) { \
5021 out = talloc_strdup(mem_ctx, in); \
5023 out = talloc_strdup(mem_ctx, ""); \
5025 W_ERROR_HAVE_NO_MEMORY(out); \
5028 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, arch, ver, in, out) \
5030 if (in && strlen(in)) { \
5031 out = talloc_asprintf(mem_ctx, "\\\\%s\\print$\\%s\\%d\\%s", server, get_short_archi(arch), ver, in); \
5033 out = talloc_strdup(mem_ctx, ""); \
5035 W_ERROR_HAVE_NO_MEMORY(out); \
5038 static WERROR
string_array_from_driver_info(TALLOC_CTX
*mem_ctx
,
5039 const char **string_array
,
5040 const char ***presult
,
5041 const char *cservername
,
5046 size_t num_strings
= 0;
5047 const char **array
= NULL
;
5049 if (string_array
== NULL
) {
5050 return WERR_INVALID_PARAMETER
;
5053 for (i
=0; string_array
[i
] && string_array
[i
][0] != '\0'; i
++) {
5054 const char *str
= NULL
;
5056 if (cservername
== NULL
|| arch
== NULL
) {
5057 FILL_DRIVER_STRING(mem_ctx
, string_array
[i
], str
);
5059 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
, arch
, version
, string_array
[i
], str
);
5062 if (!add_string_to_array(mem_ctx
, str
, &array
, &num_strings
)) {
5064 return WERR_NOT_ENOUGH_MEMORY
;
5069 ADD_TO_ARRAY(mem_ctx
, const char *, NULL
,
5070 &array
, &num_strings
);
5073 if (presult
!= NULL
) {
5082 /********************************************************************
5083 * fill a spoolss_DriverInfo1 struct
5084 ********************************************************************/
5086 static WERROR
fill_printer_driver_info1(TALLOC_CTX
*mem_ctx
,
5087 struct spoolss_DriverInfo1
*r
,
5088 const struct spoolss_DriverInfo8
*driver
,
5089 const char *servername
)
5091 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5092 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5097 /********************************************************************
5098 * fill a spoolss_DriverInfo2 struct
5099 ********************************************************************/
5101 static WERROR
fill_printer_driver_info2(TALLOC_CTX
*mem_ctx
,
5102 struct spoolss_DriverInfo2
*r
,
5103 const struct spoolss_DriverInfo8
*driver
,
5104 const char *servername
)
5107 const char *cservername
= canon_servername(servername
);
5109 r
->version
= driver
->version
;
5111 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5112 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5113 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5114 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5116 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5117 driver
->architecture
,
5119 driver
->driver_path
,
5122 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5123 driver
->architecture
,
5128 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5129 driver
->architecture
,
5131 driver
->config_file
,
5137 /********************************************************************
5138 * fill a spoolss_DriverInfo3 struct
5139 ********************************************************************/
5141 static WERROR
fill_printer_driver_info3(TALLOC_CTX
*mem_ctx
,
5142 struct spoolss_DriverInfo3
*r
,
5143 const struct spoolss_DriverInfo8
*driver
,
5144 const char *servername
)
5146 const char *cservername
= canon_servername(servername
);
5148 r
->version
= driver
->version
;
5150 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5151 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5152 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5153 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5155 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5156 driver
->architecture
,
5158 driver
->driver_path
,
5161 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5162 driver
->architecture
,
5167 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5168 driver
->architecture
,
5170 driver
->config_file
,
5173 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5174 driver
->architecture
,
5179 FILL_DRIVER_STRING(mem_ctx
,
5180 driver
->monitor_name
,
5183 FILL_DRIVER_STRING(mem_ctx
,
5184 driver
->default_datatype
,
5185 r
->default_datatype
);
5187 return string_array_from_driver_info(mem_ctx
,
5188 driver
->dependent_files
,
5189 &r
->dependent_files
,
5191 driver
->architecture
,
5195 /********************************************************************
5196 * fill a spoolss_DriverInfo4 struct
5197 ********************************************************************/
5199 static WERROR
fill_printer_driver_info4(TALLOC_CTX
*mem_ctx
,
5200 struct spoolss_DriverInfo4
*r
,
5201 const struct spoolss_DriverInfo8
*driver
,
5202 const char *servername
)
5204 const char *cservername
= canon_servername(servername
);
5207 r
->version
= driver
->version
;
5209 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5210 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5211 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5212 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5214 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5215 driver
->architecture
,
5217 driver
->driver_path
,
5220 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5221 driver
->architecture
,
5226 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5227 driver
->architecture
,
5229 driver
->config_file
,
5232 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5233 driver
->architecture
,
5238 result
= string_array_from_driver_info(mem_ctx
,
5239 driver
->dependent_files
,
5240 &r
->dependent_files
,
5242 driver
->architecture
,
5244 if (!W_ERROR_IS_OK(result
)) {
5248 FILL_DRIVER_STRING(mem_ctx
,
5249 driver
->monitor_name
,
5252 FILL_DRIVER_STRING(mem_ctx
,
5253 driver
->default_datatype
,
5254 r
->default_datatype
);
5257 result
= string_array_from_driver_info(mem_ctx
,
5258 driver
->previous_names
,
5265 /********************************************************************
5266 * fill a spoolss_DriverInfo5 struct
5267 ********************************************************************/
5269 static WERROR
fill_printer_driver_info5(TALLOC_CTX
*mem_ctx
,
5270 struct spoolss_DriverInfo5
*r
,
5271 const struct spoolss_DriverInfo8
*driver
,
5272 const char *servername
)
5274 const char *cservername
= canon_servername(servername
);
5276 r
->version
= driver
->version
;
5278 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5279 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5280 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5281 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5283 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5284 driver
->architecture
,
5286 driver
->driver_path
,
5289 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5290 driver
->architecture
,
5295 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5296 driver
->architecture
,
5298 driver
->config_file
,
5301 r
->driver_attributes
= 0;
5302 r
->config_version
= 0;
5303 r
->driver_version
= 0;
5307 /********************************************************************
5308 * fill a spoolss_DriverInfo6 struct
5309 ********************************************************************/
5311 static WERROR
fill_printer_driver_info6(TALLOC_CTX
*mem_ctx
,
5312 struct spoolss_DriverInfo6
*r
,
5313 const struct spoolss_DriverInfo8
*driver
,
5314 const char *servername
)
5316 const char *cservername
= canon_servername(servername
);
5319 r
->version
= driver
->version
;
5321 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5322 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5323 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5324 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5326 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5327 driver
->architecture
,
5329 driver
->driver_path
,
5332 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5333 driver
->architecture
,
5338 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5339 driver
->architecture
,
5341 driver
->config_file
,
5344 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5345 driver
->architecture
,
5350 FILL_DRIVER_STRING(mem_ctx
,
5351 driver
->monitor_name
,
5354 FILL_DRIVER_STRING(mem_ctx
,
5355 driver
->default_datatype
,
5356 r
->default_datatype
);
5358 result
= string_array_from_driver_info(mem_ctx
,
5359 driver
->dependent_files
,
5360 &r
->dependent_files
,
5362 driver
->architecture
,
5364 if (!W_ERROR_IS_OK(result
)) {
5368 result
= string_array_from_driver_info(mem_ctx
,
5369 driver
->previous_names
,
5372 if (!W_ERROR_IS_OK(result
)) {
5376 r
->driver_date
= driver
->driver_date
;
5377 r
->driver_version
= driver
->driver_version
;
5379 FILL_DRIVER_STRING(mem_ctx
,
5380 driver
->manufacturer_name
,
5381 r
->manufacturer_name
);
5382 FILL_DRIVER_STRING(mem_ctx
,
5383 driver
->manufacturer_url
,
5384 r
->manufacturer_url
);
5385 FILL_DRIVER_STRING(mem_ctx
,
5386 driver
->hardware_id
,
5388 FILL_DRIVER_STRING(mem_ctx
,
5395 /********************************************************************
5396 * fill a spoolss_DriverInfo8 struct
5397 ********************************************************************/
5399 static WERROR
fill_printer_driver_info8(TALLOC_CTX
*mem_ctx
,
5400 struct spoolss_DriverInfo8
*r
,
5401 const struct spoolss_DriverInfo8
*driver
,
5402 const char *servername
)
5404 const char *cservername
= canon_servername(servername
);
5407 r
->version
= driver
->version
;
5409 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5410 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5411 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5412 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5414 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5415 driver
->architecture
,
5417 driver
->driver_path
,
5420 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5421 driver
->architecture
,
5426 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5427 driver
->architecture
,
5429 driver
->config_file
,
5432 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5433 driver
->architecture
,
5438 FILL_DRIVER_STRING(mem_ctx
,
5439 driver
->monitor_name
,
5442 FILL_DRIVER_STRING(mem_ctx
,
5443 driver
->default_datatype
,
5444 r
->default_datatype
);
5446 result
= string_array_from_driver_info(mem_ctx
,
5447 driver
->dependent_files
,
5448 &r
->dependent_files
,
5450 driver
->architecture
,
5452 if (!W_ERROR_IS_OK(result
)) {
5456 result
= string_array_from_driver_info(mem_ctx
,
5457 driver
->previous_names
,
5460 if (!W_ERROR_IS_OK(result
)) {
5464 r
->driver_date
= driver
->driver_date
;
5465 r
->driver_version
= driver
->driver_version
;
5467 FILL_DRIVER_STRING(mem_ctx
,
5468 driver
->manufacturer_name
,
5469 r
->manufacturer_name
);
5470 FILL_DRIVER_STRING(mem_ctx
,
5471 driver
->manufacturer_url
,
5472 r
->manufacturer_url
);
5473 FILL_DRIVER_STRING(mem_ctx
,
5474 driver
->hardware_id
,
5476 FILL_DRIVER_STRING(mem_ctx
,
5480 FILL_DRIVER_STRING(mem_ctx
,
5481 driver
->print_processor
,
5482 r
->print_processor
);
5483 FILL_DRIVER_STRING(mem_ctx
,
5484 driver
->vendor_setup
,
5487 result
= string_array_from_driver_info(mem_ctx
,
5488 driver
->color_profiles
,
5491 if (!W_ERROR_IS_OK(result
)) {
5495 FILL_DRIVER_STRING(mem_ctx
,
5499 r
->printer_driver_attributes
= driver
->printer_driver_attributes
;
5501 result
= string_array_from_driver_info(mem_ctx
,
5502 driver
->core_driver_dependencies
,
5503 &r
->core_driver_dependencies
,
5505 if (!W_ERROR_IS_OK(result
)) {
5509 r
->min_inbox_driver_ver_date
= driver
->min_inbox_driver_ver_date
;
5510 r
->min_inbox_driver_ver_version
= driver
->min_inbox_driver_ver_version
;
5515 #if 0 /* disabled until marshalling issues are resolved - gd */
5516 /********************************************************************
5517 ********************************************************************/
5519 static WERROR
fill_spoolss_DriverFileInfo(TALLOC_CTX
*mem_ctx
,
5520 struct spoolss_DriverFileInfo
*r
,
5521 const char *cservername
,
5522 const char *file_name
,
5523 enum spoolss_DriverFileType file_type
,
5524 uint32_t file_version
)
5526 r
->file_name
= talloc_asprintf(mem_ctx
, "\\\\%s%s",
5527 cservername
, file_name
);
5528 W_ERROR_HAVE_NO_MEMORY(r
->file_name
);
5529 r
->file_type
= file_type
;
5530 r
->file_version
= file_version
;
5535 /********************************************************************
5536 ********************************************************************/
5538 static WERROR
spoolss_DriverFileInfo_from_driver(TALLOC_CTX
*mem_ctx
,
5539 const struct spoolss_DriverInfo8
*driver
,
5540 const char *cservername
,
5541 struct spoolss_DriverFileInfo
**info_p
,
5544 struct spoolss_DriverFileInfo
*info
= NULL
;
5552 if (strlen(driver
->driver_path
)) {
5553 info
= talloc_realloc(mem_ctx
, info
,
5554 struct spoolss_DriverFileInfo
,
5556 W_ERROR_HAVE_NO_MEMORY(info
);
5557 result
= fill_spoolss_DriverFileInfo(info
,
5560 driver
->driver_path
,
5561 SPOOLSS_DRIVER_FILE_TYPE_RENDERING
,
5563 W_ERROR_NOT_OK_RETURN(result
);
5567 if (strlen(driver
->config_file
)) {
5568 info
= talloc_realloc(mem_ctx
, info
,
5569 struct spoolss_DriverFileInfo
,
5571 W_ERROR_HAVE_NO_MEMORY(info
);
5572 result
= fill_spoolss_DriverFileInfo(info
,
5575 driver
->config_file
,
5576 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION
,
5578 W_ERROR_NOT_OK_RETURN(result
);
5582 if (strlen(driver
->data_file
)) {
5583 info
= talloc_realloc(mem_ctx
, info
,
5584 struct spoolss_DriverFileInfo
,
5586 W_ERROR_HAVE_NO_MEMORY(info
);
5587 result
= fill_spoolss_DriverFileInfo(info
,
5591 SPOOLSS_DRIVER_FILE_TYPE_DATA
,
5593 W_ERROR_NOT_OK_RETURN(result
);
5597 if (strlen(driver
->help_file
)) {
5598 info
= talloc_realloc(mem_ctx
, info
,
5599 struct spoolss_DriverFileInfo
,
5601 W_ERROR_HAVE_NO_MEMORY(info
);
5602 result
= fill_spoolss_DriverFileInfo(info
,
5606 SPOOLSS_DRIVER_FILE_TYPE_HELP
,
5608 W_ERROR_NOT_OK_RETURN(result
);
5612 for (i
=0; driver
->dependent_files
[i
] && driver
->dependent_files
[i
][0] != '\0'; i
++) {
5613 info
= talloc_realloc(mem_ctx
, info
,
5614 struct spoolss_DriverFileInfo
,
5616 W_ERROR_HAVE_NO_MEMORY(info
);
5617 result
= fill_spoolss_DriverFileInfo(info
,
5620 driver
->dependent_files
[i
],
5621 SPOOLSS_DRIVER_FILE_TYPE_OTHER
,
5623 W_ERROR_NOT_OK_RETURN(result
);
5633 /********************************************************************
5634 * fill a spoolss_DriverInfo101 struct
5635 ********************************************************************/
5637 static WERROR
fill_printer_driver_info101(TALLOC_CTX
*mem_ctx
,
5638 struct spoolss_DriverInfo101
*r
,
5639 const struct spoolss_DriverInfo8
*driver
,
5640 const char *servername
)
5642 const char *cservername
= canon_servername(servername
);
5645 r
->version
= driver
->version
;
5647 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5648 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5649 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5650 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5652 result
= spoolss_DriverFileInfo_from_driver(mem_ctx
, driver
,
5656 if (!W_ERROR_IS_OK(result
)) {
5660 FILL_DRIVER_STRING(mem_ctx
,
5661 driver
->monitor_name
,
5664 FILL_DRIVER_STRING(mem_ctx
,
5665 driver
->default_datatype
,
5666 r
->default_datatype
);
5668 result
= string_array_from_driver_info(mem_ctx
,
5669 driver
->previous_names
,
5672 if (!W_ERROR_IS_OK(result
)) {
5676 r
->driver_date
= driver
->driver_date
;
5677 r
->driver_version
= driver
->driver_version
;
5679 FILL_DRIVER_STRING(mem_ctx
,
5680 driver
->manufacturer_name
,
5681 r
->manufacturer_name
);
5682 FILL_DRIVER_STRING(mem_ctx
,
5683 driver
->manufacturer_url
,
5684 r
->manufacturer_url
);
5685 FILL_DRIVER_STRING(mem_ctx
,
5686 driver
->hardware_id
,
5688 FILL_DRIVER_STRING(mem_ctx
,
5695 /********************************************************************
5696 ********************************************************************/
5698 static WERROR
construct_printer_driver_info_level(TALLOC_CTX
*mem_ctx
,
5699 const struct auth_session_info
*session_info
,
5700 struct messaging_context
*msg_ctx
,
5702 union spoolss_DriverInfo
*r
,
5704 const char *servername
,
5705 const char *architecture
,
5708 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
5709 struct spoolss_DriverInfo8
*driver
;
5711 struct dcerpc_binding_handle
*b
;
5712 TALLOC_CTX
*tmp_ctx
= NULL
;
5715 return WERR_INVALID_LEVEL
;
5718 tmp_ctx
= talloc_new(mem_ctx
);
5720 return WERR_NOT_ENOUGH_MEMORY
;
5723 result
= winreg_printer_binding_handle(tmp_ctx
,
5727 if (!W_ERROR_IS_OK(result
)) {
5731 result
= winreg_get_printer(tmp_ctx
, b
,
5732 lp_const_servicename(snum
),
5734 if (!W_ERROR_IS_OK(result
)) {
5735 DBG_ERR("Failed to get printer info2 for [%s]: %s\n",
5736 lp_const_servicename(snum
), win_errstr(result
));
5737 result
= WERR_INVALID_PRINTER_NAME
;
5741 if (pinfo2
->drivername
== NULL
|| pinfo2
->drivername
[0] == '\0') {
5742 return WERR_UNKNOWN_PRINTER_DRIVER
;
5745 DBG_INFO("Construct printer driver [%s] for [%s]\n",
5749 result
= winreg_get_driver(tmp_ctx
, b
,
5751 pinfo2
->drivername
, version
, &driver
);
5753 DBG_INFO("winreg_get_driver() status: %s\n",
5754 win_errstr(result
));
5756 if (!W_ERROR_IS_OK(result
)) {
5758 * Is this a W2k client ?
5762 result
= WERR_UNKNOWN_PRINTER_DRIVER
;
5766 /* Yes - try again with a WinNT driver. */
5768 result
= winreg_get_driver(tmp_ctx
, b
,
5772 DEBUG(8,("construct_printer_driver_level: status: %s\n",
5773 win_errstr(result
)));
5774 if (!W_ERROR_IS_OK(result
)) {
5775 result
= WERR_UNKNOWN_PRINTER_DRIVER
;
5780 /* these are allocated on mem_ctx and not tmp_ctx because they are
5781 * the 'return value' and need to utlive this call */
5784 result
= fill_printer_driver_info1(mem_ctx
, &r
->info1
, driver
, servername
);
5787 result
= fill_printer_driver_info2(mem_ctx
, &r
->info2
, driver
, servername
);
5790 result
= fill_printer_driver_info3(mem_ctx
, &r
->info3
, driver
, servername
);
5793 result
= fill_printer_driver_info4(mem_ctx
, &r
->info4
, driver
, servername
);
5796 result
= fill_printer_driver_info5(mem_ctx
, &r
->info5
, driver
, servername
);
5799 result
= fill_printer_driver_info6(mem_ctx
, &r
->info6
, driver
, servername
);
5802 result
= fill_printer_driver_info8(mem_ctx
, &r
->info8
, driver
, servername
);
5804 #if 0 /* disabled until marshalling issues are resolved - gd */
5806 result
= fill_printer_driver_info101(mem_ctx
, &r
->info101
, driver
, servername
);
5810 result
= WERR_INVALID_LEVEL
;
5815 talloc_free(tmp_ctx
);
5819 /****************************************************************
5820 _spoolss_GetPrinterDriver2
5821 ****************************************************************/
5823 WERROR
_spoolss_GetPrinterDriver2(struct pipes_struct
*p
,
5824 struct spoolss_GetPrinterDriver2
*r
)
5826 struct printer_handle
*printer
;
5828 uint32_t version
= r
->in
.client_major_version
;
5832 /* that's an [in out] buffer */
5834 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
5835 result
= WERR_INVALID_PARAMETER
;
5839 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5841 if (!(printer
= find_printer_index_by_hnd(p
, r
->in
.handle
))) {
5842 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5843 result
= WERR_INVALID_PRINTER_NAME
;
5848 *r
->out
.server_major_version
= 0;
5849 *r
->out
.server_minor_version
= 0;
5851 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
5852 result
= WERR_INVALID_HANDLE
;
5856 if (r
->in
.client_major_version
== SPOOLSS_DRIVER_VERSION_2012
) {
5857 DEBUG(3,("_spoolss_GetPrinterDriver2: v4 driver requested, "
5858 "downgrading to v3\n"));
5859 version
= SPOOLSS_DRIVER_VERSION_200X
;
5862 result
= construct_printer_driver_info_level(p
->mem_ctx
,
5863 get_session_info_system(),
5865 r
->in
.level
, r
->out
.info
,
5866 snum
, printer
->servername
,
5869 if (!W_ERROR_IS_OK(result
)) {
5873 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_DriverInfo
,
5874 r
->out
.info
, r
->in
.level
);
5875 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
5877 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
5880 TALLOC_FREE(r
->out
.info
);
5885 /****************************************************************
5886 _spoolss_StartPagePrinter
5887 ****************************************************************/
5889 WERROR
_spoolss_StartPagePrinter(struct pipes_struct
*p
,
5890 struct spoolss_StartPagePrinter
*r
)
5892 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5895 DEBUG(3,("_spoolss_StartPagePrinter: "
5896 "Error in startpageprinter printer handle\n"));
5897 return WERR_INVALID_HANDLE
;
5900 Printer
->page_started
= true;
5904 /****************************************************************
5905 _spoolss_EndPagePrinter
5906 ****************************************************************/
5908 WERROR
_spoolss_EndPagePrinter(struct pipes_struct
*p
,
5909 struct spoolss_EndPagePrinter
*r
)
5913 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5916 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5917 OUR_HANDLE(r
->in
.handle
)));
5918 return WERR_INVALID_HANDLE
;
5921 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
))
5922 return WERR_INVALID_HANDLE
;
5924 Printer
->page_started
= false;
5925 print_job_endpage(p
->msg_ctx
, snum
, Printer
->jobid
);
5930 /****************************************************************
5931 _spoolss_StartDocPrinter
5932 ****************************************************************/
5934 WERROR
_spoolss_StartDocPrinter(struct pipes_struct
*p
,
5935 struct spoolss_StartDocPrinter
*r
)
5937 struct spoolss_DocumentInfo1
*info_1
;
5939 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5945 DEBUG(2,("_spoolss_StartDocPrinter: "
5946 "Invalid handle (%s:%u:%u)\n",
5947 OUR_HANDLE(r
->in
.handle
)));
5948 return WERR_INVALID_HANDLE
;
5951 if (Printer
->jobid
) {
5952 DEBUG(2, ("_spoolss_StartDocPrinter: "
5953 "StartDocPrinter called twice! "
5954 "(existing jobid = %d)\n", Printer
->jobid
));
5955 return WERR_INVALID_HANDLE
;
5958 if (r
->in
.info_ctr
->level
!= 1) {
5959 return WERR_INVALID_LEVEL
;
5962 info_1
= r
->in
.info_ctr
->info
.info1
;
5965 * a nice thing with NT is it doesn't listen to what you tell it.
5966 * when asked to send _only_ RAW datas, it tries to send datas
5969 * So I add checks like in NT Server ...
5972 if (info_1
->datatype
) {
5974 * The v4 driver model used in Windows 8 declares print jobs
5975 * intended to bypass the XPS processing layer by setting
5976 * datatype to "XPS_PASS" instead of "RAW".
5978 if ((strcmp(info_1
->datatype
, "RAW") != 0)
5979 && (strcmp(info_1
->datatype
, "XPS_PASS") != 0)) {
5981 return WERR_INVALID_DATATYPE
;
5985 /* get the share number of the printer */
5986 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
5987 return WERR_INVALID_HANDLE
;
5990 rc
= get_remote_hostname(p
->remote_address
,
5994 return WERR_NOT_ENOUGH_MEMORY
;
5996 if (strequal(rhost
,"UNKNOWN")) {
5997 rhost
= tsocket_address_inet_addr_string(p
->remote_address
,
5999 if (rhost
== NULL
) {
6000 return WERR_NOT_ENOUGH_MEMORY
;
6004 werr
= print_job_start(p
->session_info
,
6008 info_1
->document_name
,
6009 info_1
->output_file
,
6013 /* An error occurred in print_job_start() so return an appropriate
6016 if (!W_ERROR_IS_OK(werr
)) {
6020 Printer
->document_started
= true;
6021 *r
->out
.job_id
= Printer
->jobid
;
6026 /****************************************************************
6027 _spoolss_EndDocPrinter
6028 ****************************************************************/
6030 WERROR
_spoolss_EndDocPrinter(struct pipes_struct
*p
,
6031 struct spoolss_EndDocPrinter
*r
)
6033 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
6038 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
6039 OUR_HANDLE(r
->in
.handle
)));
6040 return WERR_INVALID_HANDLE
;
6043 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
6044 return WERR_INVALID_HANDLE
;
6047 Printer
->document_started
= false;
6048 status
= print_job_end(p
->msg_ctx
, snum
, Printer
->jobid
, NORMAL_CLOSE
);
6049 if (!NT_STATUS_IS_OK(status
)) {
6050 DEBUG(2, ("_spoolss_EndDocPrinter: "
6051 "print_job_end failed [%s]\n",
6052 nt_errstr(status
)));
6056 return ntstatus_to_werror(status
);
6059 /****************************************************************
6060 _spoolss_WritePrinter
6061 ****************************************************************/
6063 WERROR
_spoolss_WritePrinter(struct pipes_struct
*p
,
6064 struct spoolss_WritePrinter
*r
)
6066 ssize_t buffer_written
;
6068 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
6071 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
6072 OUR_HANDLE(r
->in
.handle
)));
6073 *r
->out
.num_written
= r
->in
._data_size
;
6074 return WERR_INVALID_HANDLE
;
6077 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
))
6078 return WERR_INVALID_HANDLE
;
6080 /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
6081 buffer_written
= print_job_write(global_event_context(),p
->msg_ctx
,
6082 snum
, Printer
->jobid
,
6083 (const char *)r
->in
.data
.data
,
6084 (size_t)r
->in
._data_size
);
6085 if (buffer_written
== (ssize_t
)-1) {
6086 *r
->out
.num_written
= 0;
6087 if (errno
== ENOSPC
)
6088 return WERR_NO_SPOOL_SPACE
;
6090 return WERR_ACCESS_DENIED
;
6093 *r
->out
.num_written
= r
->in
._data_size
;
6098 /********************************************************************
6099 * api_spoolss_getprinter
6100 * called from the spoolss dispatcher
6102 ********************************************************************/
6104 static WERROR
control_printer(struct policy_handle
*handle
, uint32_t command
,
6105 struct pipes_struct
*p
)
6107 const struct auth_session_info
*session_info
= p
->session_info
;
6109 WERROR errcode
= WERR_INVALID_FUNCTION
;
6110 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, handle
);
6113 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
6114 OUR_HANDLE(handle
)));
6115 return WERR_INVALID_HANDLE
;
6118 if (!get_printer_snum(p
, handle
, &snum
, NULL
))
6119 return WERR_INVALID_HANDLE
;
6122 case SPOOLSS_PRINTER_CONTROL_PAUSE
:
6123 errcode
= print_queue_pause(session_info
, p
->msg_ctx
, snum
);
6125 case SPOOLSS_PRINTER_CONTROL_RESUME
:
6126 case SPOOLSS_PRINTER_CONTROL_UNPAUSE
:
6127 errcode
= print_queue_resume(session_info
, p
->msg_ctx
, snum
);
6129 case SPOOLSS_PRINTER_CONTROL_PURGE
:
6130 errcode
= print_queue_purge(session_info
, p
->msg_ctx
, snum
);
6133 return WERR_INVALID_LEVEL
;
6140 /****************************************************************
6141 _spoolss_AbortPrinter
6142 * From MSDN: "Deletes printer's spool file if printer is configured
6144 ****************************************************************/
6146 WERROR
_spoolss_AbortPrinter(struct pipes_struct
*p
,
6147 struct spoolss_AbortPrinter
*r
)
6149 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
6151 WERROR errcode
= WERR_OK
;
6154 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
6155 OUR_HANDLE(r
->in
.handle
)));
6156 return WERR_INVALID_HANDLE
;
6159 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
))
6160 return WERR_INVALID_HANDLE
;
6162 if (!Printer
->document_started
) {
6163 return WERR_SPL_NO_STARTDOC
;
6166 errcode
= print_job_delete(p
->session_info
,
6174 /********************************************************************
6175 * called by spoolss_api_setprinter
6176 * when updating a printer description
6177 ********************************************************************/
6179 static WERROR
update_printer_sec(struct policy_handle
*handle
,
6180 struct pipes_struct
*p
,
6181 struct sec_desc_buf
*secdesc_ctr
)
6183 struct spoolss_security_descriptor
*new_secdesc
= NULL
;
6184 struct spoolss_security_descriptor
*old_secdesc
= NULL
;
6185 const char *printer
= NULL
;
6188 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, handle
);
6189 struct dcerpc_binding_handle
*b
;
6190 TALLOC_CTX
*tmp_ctx
= NULL
;
6194 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
6195 OUR_HANDLE(handle
)));
6197 result
= WERR_INVALID_HANDLE
;
6201 if (secdesc_ctr
== NULL
) {
6202 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
6203 result
= WERR_INVALID_PARAMETER
;
6207 switch (Printer
->printer_type
) {
6210 case SPLHND_PRINTER
:
6211 if (!get_printer_snum(p
, handle
, &snum
, NULL
)) {
6212 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
6213 OUR_HANDLE(handle
)));
6214 result
= WERR_INVALID_HANDLE
;
6217 printer
= lp_const_servicename(snum
);
6223 /* Check the user has permissions to change the security
6224 descriptor. By experimentation with two NT machines, the user
6225 requires Full Access to the printer to change security
6228 switch (Printer
->printer_type
) {
6230 ok
= Printer
->access_granted
== SERVER_ACCESS_ADMINISTER
;
6232 case SPLHND_PRINTER
:
6233 ok
= Printer
->access_granted
== PRINTER_ACCESS_ADMINISTER
;
6240 DEBUG(4,("update_printer_sec: updated denied by printer permissions "
6241 "(access_granted: 0x%08x)\n", Printer
->access_granted
));
6242 result
= WERR_ACCESS_DENIED
;
6246 tmp_ctx
= talloc_new(p
->mem_ctx
);
6248 return WERR_NOT_ENOUGH_MEMORY
;
6251 result
= winreg_printer_binding_handle(tmp_ctx
,
6252 get_session_info_system(),
6255 if (!W_ERROR_IS_OK(result
)) {
6259 /* NT seems to like setting the security descriptor even though
6260 nothing may have actually changed. */
6262 if (printer
!= NULL
) {
6263 result
= winreg_get_printer_secdesc(tmp_ctx
, b
,
6267 result
= winreg_get_printserver_secdesc(tmp_ctx
, b
,
6270 if (!W_ERROR_IS_OK(result
)) {
6271 DEBUG(2,("update_printer_sec: winreg_get_printer_secdesc_internal() failed\n"));
6272 result
= WERR_INVALID_HANDLE
;
6276 if (DEBUGLEVEL
>= 10) {
6277 struct dom_sid_buf buf
;
6278 struct security_acl
*the_acl
;
6281 the_acl
= old_secdesc
->dacl
;
6282 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
6283 printer
, the_acl
->num_aces
));
6285 for (i
= 0; i
< the_acl
->num_aces
; i
++) {
6286 DEBUG(10, ("%s 0x%08x\n",
6288 &the_acl
->aces
[i
].trustee
,
6290 the_acl
->aces
[i
].access_mask
));
6293 the_acl
= secdesc_ctr
->sd
->dacl
;
6296 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
6297 printer
, the_acl
->num_aces
));
6299 for (i
= 0; i
< the_acl
->num_aces
; i
++) {
6300 DEBUG(10, ("%s 0x%08x\n",
6302 &the_acl
->aces
[i
].trustee
,
6304 the_acl
->aces
[i
].access_mask
));
6307 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
6311 new_secdesc
= sec_desc_merge(tmp_ctx
, secdesc_ctr
->sd
, old_secdesc
);
6312 if (new_secdesc
== NULL
) {
6313 result
= WERR_NOT_ENOUGH_MEMORY
;
6317 if (security_descriptor_equal(new_secdesc
, old_secdesc
)) {
6322 if (printer
!= NULL
) {
6323 result
= winreg_set_printer_secdesc(tmp_ctx
, b
,
6327 result
= winreg_set_printserver_secdesc(tmp_ctx
, b
,
6332 talloc_free(tmp_ctx
);
6336 /********************************************************************
6337 Canonicalize printer info from a client
6338 ********************************************************************/
6340 static bool check_printer_ok(TALLOC_CTX
*mem_ctx
,
6341 struct spoolss_SetPrinterInfo2
*info2
,
6344 fstring printername
;
6347 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
6348 "portname=%s drivername=%s comment=%s location=%s\n",
6349 info2
->servername
, info2
->printername
, info2
->sharename
,
6350 info2
->portname
, info2
->drivername
, info2
->comment
,
6353 /* we force some elements to "correct" values */
6354 info2
->servername
= talloc_asprintf(mem_ctx
, "\\\\%s", lp_netbios_name());
6355 if (info2
->servername
== NULL
) {
6358 info2
->sharename
= talloc_strdup(mem_ctx
, lp_const_servicename(snum
));
6359 if (info2
->sharename
== NULL
) {
6363 /* check to see if we allow printername != sharename */
6364 if (lp_force_printername(snum
)) {
6365 info2
->printername
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s",
6366 lp_netbios_name(), info2
->sharename
);
6368 /* make sure printername is in \\server\printername format */
6369 fstrcpy(printername
, info2
->printername
);
6371 if ( printername
[0] == '\\' && printername
[1] == '\\' ) {
6372 if ( (p
= strchr_m( &printername
[2], '\\' )) != NULL
)
6376 info2
->printername
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s",
6377 lp_netbios_name(), p
);
6379 if (info2
->printername
== NULL
) {
6383 info2
->attributes
|= PRINTER_ATTRIBUTE_SAMBA
;
6384 info2
->attributes
&= ~PRINTER_ATTRIBUTE_NOT_SAMBA
;
6389 /****************************************************************************
6390 ****************************************************************************/
6392 static WERROR
add_port_hook(TALLOC_CTX
*ctx
, struct security_token
*token
, const char *portname
, const char *uri
)
6394 const struct loadparm_substitution
*lp_sub
=
6395 loadparm_s3_global_substitution();
6396 char *cmd
= lp_addport_command(talloc_tos(), lp_sub
);
6397 char *command
= NULL
;
6399 bool is_print_op
= false;
6402 return WERR_ACCESS_DENIED
;
6405 command
= talloc_asprintf(ctx
,
6406 "%s \"%s\" \"%s\"", cmd
, portname
, uri
);
6408 return WERR_NOT_ENOUGH_MEMORY
;
6412 is_print_op
= security_token_has_privilege(token
, SEC_PRIV_PRINT_OPERATOR
);
6414 DEBUG(10,("Running [%s]\n", command
));
6416 /********* BEGIN SePrintOperatorPrivilege **********/
6421 ret
= smbrun(command
, NULL
, NULL
);
6426 /********* END SePrintOperatorPrivilege **********/
6428 DEBUGADD(10,("returned [%d]\n", ret
));
6430 TALLOC_FREE(command
);
6433 return WERR_ACCESS_DENIED
;
6439 /****************************************************************************
6440 ****************************************************************************/
6442 static bool spoolss_conn_snum_used(struct smbd_server_connection
*sconn
,
6446 * As we do not know if we are embedded in the file server process
6447 * or not, we have to pretend that all shares are in use.
6452 static bool add_printer_hook(TALLOC_CTX
*ctx
, struct security_token
*token
,
6453 struct spoolss_SetPrinterInfo2
*info2
,
6454 const char *remote_machine
,
6455 struct messaging_context
*msg_ctx
)
6457 const struct loadparm_substitution
*lp_sub
=
6458 loadparm_s3_global_substitution();
6459 char *cmd
= lp_addprinter_command(talloc_tos(), lp_sub
);
6461 char *command
= NULL
;
6465 bool is_print_op
= false;
6467 if (!remote_machine
) {
6471 command
= talloc_asprintf(ctx
,
6472 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
6473 cmd
, info2
->printername
, info2
->sharename
,
6474 info2
->portname
, info2
->drivername
,
6475 info2
->location
, info2
->comment
, remote_machine
);
6481 is_print_op
= security_token_has_privilege(token
, SEC_PRIV_PRINT_OPERATOR
);
6483 DEBUG(10,("Running [%s]\n", command
));
6485 /********* BEGIN SePrintOperatorPrivilege **********/
6490 ret
= smbrun(command
, &fd
, NULL
);
6492 /* Tell everyone we updated smb.conf. */
6493 messaging_send_all(msg_ctx
, MSG_SMB_CONF_UPDATED
, NULL
, 0);
6499 /********* END SePrintOperatorPrivilege **********/
6501 DEBUGADD(10,("returned [%d]\n", ret
));
6503 TALLOC_FREE(command
);
6511 /* reload our services immediately */
6513 reload_services(NULL
, spoolss_conn_snum_used
, false);
6517 /* Get lines and convert them back to dos-codepage */
6518 qlines
= fd_lines_load(fd
, &numlines
, 0, NULL
);
6519 DEBUGADD(10,("Lines returned = [%d]\n", numlines
));
6522 /* Set the portname to what the script says the portname should be. */
6523 /* but don't require anything to be return from the script exit a good error code */
6526 /* Set the portname to what the script says the portname should be. */
6527 info2
->portname
= talloc_strdup(ctx
, qlines
[0]);
6528 DEBUGADD(6,("Line[0] = [%s]\n", qlines
[0]));
6531 TALLOC_FREE(qlines
);
6535 static WERROR
update_dsspooler(TALLOC_CTX
*mem_ctx
,
6536 const struct auth_session_info
*session_info
,
6537 struct messaging_context
*msg_ctx
,
6539 struct spoolss_SetPrinterInfo2
*printer
,
6540 struct spoolss_PrinterInfo2
*old_printer
)
6542 bool force_update
= (old_printer
== NULL
);
6543 const char *dnsdomname
;
6544 const char *longname
;
6545 const char *uncname
;
6546 const char *spooling
;
6548 WERROR result
= WERR_OK
;
6549 struct dcerpc_binding_handle
*b
;
6550 TALLOC_CTX
*tmp_ctx
;
6553 tmp_ctx
= talloc_new(mem_ctx
);
6555 return WERR_NOT_ENOUGH_MEMORY
;
6558 result
= winreg_printer_binding_handle(tmp_ctx
,
6562 if (!W_ERROR_IS_OK(result
)) {
6566 if (printer
->drivername
!= NULL
&&
6568 !strequal(printer
->drivername
, old_printer
->drivername
))) {
6569 ok
= push_reg_sz(tmp_ctx
, &buffer
, printer
->drivername
);
6571 DEBUG(0, ("%s data corrupted\n", SPOOL_REG_DRIVERNAME
));
6572 result
= WERR_INVALID_DATA
;
6575 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6577 SPOOL_DSSPOOLER_KEY
,
6578 SPOOL_REG_DRIVERNAME
,
6582 if (!W_ERROR_IS_OK(result
)) {
6583 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_DRIVERNAME
));
6587 if (!force_update
) {
6588 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
6589 printer
->drivername
));
6591 notify_printer_driver(global_event_context(), msg_ctx
,
6592 snum
, printer
->drivername
?
6593 printer
->drivername
: "");
6597 if (printer
->comment
!= NULL
&&
6599 !strequal(printer
->comment
, old_printer
->comment
))) {
6600 ok
= push_reg_sz(tmp_ctx
, &buffer
, printer
->comment
);
6602 DEBUG(0, ("comment data corrupted\n"));
6603 result
= WERR_INVALID_DATA
;
6606 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6608 SPOOL_DSSPOOLER_KEY
,
6609 SPOOL_REG_DESCRIPTION
,
6613 if (!W_ERROR_IS_OK(result
)) {
6614 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_DESCRIPTION
));
6618 if (!force_update
) {
6619 notify_printer_comment(global_event_context(), msg_ctx
,
6620 snum
, printer
->comment
?
6621 printer
->comment
: "");
6625 if (printer
->sharename
!= NULL
&&
6627 !strequal(printer
->sharename
, old_printer
->sharename
))) {
6628 ok
= push_reg_sz(tmp_ctx
, &buffer
, printer
->sharename
);
6630 DEBUG(0, ("sharename data corrupted\n"));
6631 result
= WERR_INVALID_DATA
;
6634 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6636 SPOOL_DSSPOOLER_KEY
,
6637 SPOOL_REG_PRINTSHARENAME
,
6641 if (!W_ERROR_IS_OK(result
)) {
6642 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSHARENAME
));
6646 if (!force_update
) {
6647 notify_printer_sharename(global_event_context(),
6649 snum
, printer
->sharename
?
6650 printer
->sharename
: "");
6653 /* name change, purge any cache entries for the old */
6654 prune_printername_cache();
6657 if (printer
->printername
!= NULL
&&
6659 !strequal(printer
->printername
, old_printer
->printername
))) {
6662 p
= strrchr(printer
->printername
, '\\' );
6666 p
= printer
->printername
;
6669 ok
= push_reg_sz(tmp_ctx
, &buffer
, p
);
6671 DEBUG(0, ("printername data corrupted\n"));
6672 result
= WERR_INVALID_DATA
;
6675 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6677 SPOOL_DSSPOOLER_KEY
,
6678 SPOOL_REG_PRINTERNAME
,
6682 if (!W_ERROR_IS_OK(result
)) {
6683 DBG_ERR("Failed to set %s\n", SPOOL_REG_PRINTERNAME
);
6687 if (!force_update
) {
6688 notify_printer_printername(global_event_context(),
6689 msg_ctx
, snum
, p
? p
: "");
6692 /* name change, purge any cache entries for the old */
6693 prune_printername_cache();
6696 if (printer
->portname
!= NULL
&&
6698 !strequal(printer
->portname
, old_printer
->portname
))) {
6699 ok
= push_reg_sz(tmp_ctx
, &buffer
, printer
->portname
);
6701 DEBUG(0, ("portname data corrupted\n"));
6702 result
= WERR_INVALID_DATA
;
6705 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6707 SPOOL_DSSPOOLER_KEY
,
6712 if (!W_ERROR_IS_OK(result
)) {
6713 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PORTNAME
));
6717 if (!force_update
) {
6718 notify_printer_port(global_event_context(),
6719 msg_ctx
, snum
, printer
->portname
?
6720 printer
->portname
: "");
6724 if (printer
->location
!= NULL
&&
6726 !strequal(printer
->location
, old_printer
->location
))) {
6727 ok
= push_reg_sz(tmp_ctx
, &buffer
, printer
->location
);
6729 DEBUG(0, ("location data corrupted\n"));
6730 result
= WERR_INVALID_DATA
;
6733 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6735 SPOOL_DSSPOOLER_KEY
,
6740 if (!W_ERROR_IS_OK(result
)) {
6741 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_LOCATION
));
6745 if (!force_update
) {
6746 notify_printer_location(global_event_context(),
6749 printer
->location
: "");
6753 if (printer
->sepfile
!= NULL
&&
6755 !strequal(printer
->sepfile
, old_printer
->sepfile
))) {
6756 ok
= push_reg_sz(tmp_ctx
, &buffer
, printer
->sepfile
);
6758 DEBUG(0, ("sepfile data corrupted\n"));
6759 result
= WERR_INVALID_DATA
;
6762 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6764 SPOOL_DSSPOOLER_KEY
,
6765 SPOOL_REG_PRINTSEPARATORFILE
,
6769 if (!W_ERROR_IS_OK(result
)) {
6770 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSEPARATORFILE
));
6774 if (!force_update
) {
6775 notify_printer_sepfile(global_event_context(),
6778 printer
->sepfile
: "");
6782 if (printer
->starttime
!= 0 &&
6784 printer
->starttime
!= old_printer
->starttime
)) {
6785 buffer
= data_blob_talloc(tmp_ctx
, NULL
, 4);
6786 SIVAL(buffer
.data
, 0, printer
->starttime
);
6787 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6789 SPOOL_DSSPOOLER_KEY
,
6790 SPOOL_REG_PRINTSTARTTIME
,
6794 if (!W_ERROR_IS_OK(result
)) {
6795 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSTARTTIME
));
6800 if (printer
->untiltime
!= 0 &&
6802 printer
->untiltime
!= old_printer
->untiltime
)) {
6803 buffer
= data_blob_talloc(tmp_ctx
, NULL
, 4);
6804 SIVAL(buffer
.data
, 0, printer
->untiltime
);
6805 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6807 SPOOL_DSSPOOLER_KEY
,
6808 SPOOL_REG_PRINTENDTIME
,
6812 if (!W_ERROR_IS_OK(result
)) {
6813 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTENDTIME
));
6818 if (force_update
|| printer
->priority
!= old_printer
->priority
) {
6819 buffer
= data_blob_talloc(tmp_ctx
, NULL
, 4);
6820 SIVAL(buffer
.data
, 0, printer
->priority
);
6821 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6823 SPOOL_DSSPOOLER_KEY
,
6828 if (!W_ERROR_IS_OK(result
)) {
6829 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTENDTIME
));
6834 if (force_update
|| printer
->attributes
!= old_printer
->attributes
) {
6835 buffer
= data_blob_talloc(tmp_ctx
, NULL
, 4);
6836 SIVAL(buffer
.data
, 0, (printer
->attributes
&
6837 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS
));
6838 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6840 SPOOL_DSSPOOLER_KEY
,
6841 SPOOL_REG_PRINTKEEPPRINTEDJOBS
,
6845 if (!W_ERROR_IS_OK(result
)) {
6846 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTENDTIME
));
6850 switch (printer
->attributes
& 0x3) {
6852 spooling
= SPOOL_REGVAL_PRINTWHILESPOOLING
;
6855 spooling
= SPOOL_REGVAL_PRINTAFTERSPOOLED
;
6858 spooling
= SPOOL_REGVAL_PRINTDIRECT
;
6861 spooling
= "unknown";
6863 ok
= push_reg_sz(tmp_ctx
, &buffer
, spooling
);
6865 DEBUG(0, ("printSpooling data corrupted\n"));
6866 result
= WERR_INVALID_DATA
;
6869 winreg_set_printer_dataex(tmp_ctx
, b
,
6871 SPOOL_DSSPOOLER_KEY
,
6872 SPOOL_REG_PRINTSPOOLING
,
6878 ok
= push_reg_sz(tmp_ctx
, &buffer
, lp_netbios_name());
6880 DEBUG(0, ("shortServerName data corrupted\n"));
6881 result
= WERR_INVALID_DATA
;
6884 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6886 SPOOL_DSSPOOLER_KEY
,
6887 SPOOL_REG_SHORTSERVERNAME
,
6891 if (!W_ERROR_IS_OK(result
)) {
6892 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_SHORTSERVERNAME
));
6896 dnsdomname
= get_mydnsfullname();
6897 if (dnsdomname
!= NULL
&& dnsdomname
[0] != '\0') {
6898 longname
= talloc_strdup(tmp_ctx
, dnsdomname
);
6900 longname
= talloc_strdup(tmp_ctx
, lp_netbios_name());
6902 if (longname
== NULL
) {
6903 result
= WERR_NOT_ENOUGH_MEMORY
;
6907 ok
= push_reg_sz(tmp_ctx
, &buffer
, longname
);
6909 DEBUG(0, ("longname data corrupted\n"));
6910 result
= WERR_INVALID_DATA
;
6913 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6915 SPOOL_DSSPOOLER_KEY
,
6916 SPOOL_REG_SERVERNAME
,
6920 if (!W_ERROR_IS_OK(result
)) {
6921 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_SERVERNAME
));
6925 uncname
= talloc_asprintf(tmp_ctx
, "\\\\%s\\%s",
6926 lp_netbios_name(), printer
->sharename
);
6927 ok
= push_reg_sz(tmp_ctx
, &buffer
, uncname
);
6929 DEBUG(0, ("uncName data corrupted\n"));
6930 result
= WERR_INVALID_DATA
;
6933 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6935 SPOOL_DSSPOOLER_KEY
,
6940 if (!W_ERROR_IS_OK(result
)) {
6941 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_UNCNAME
));
6946 talloc_free(tmp_ctx
);
6950 /********************************************************************
6951 * Called by spoolss_api_setprinter
6952 * when updating a printer description.
6953 ********************************************************************/
6955 static WERROR
update_printer(struct pipes_struct
*p
,
6956 struct policy_handle
*handle
,
6957 struct spoolss_SetPrinterInfoCtr
*info_ctr
,
6958 struct spoolss_DeviceMode
*devmode
)
6960 uint32_t printer_mask
= SPOOLSS_PRINTER_INFO_ALL
;
6961 struct spoolss_SetPrinterInfo2
*printer
= info_ctr
->info
.info2
;
6962 struct spoolss_PrinterInfo2
*old_printer
;
6963 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, handle
);
6964 const struct loadparm_substitution
*lp_sub
=
6965 loadparm_s3_global_substitution();
6967 WERROR result
= WERR_OK
;
6968 TALLOC_CTX
*tmp_ctx
;
6969 struct dcerpc_binding_handle
*b
;
6971 DEBUG(8,("update_printer\n"));
6973 tmp_ctx
= talloc_new(p
->mem_ctx
);
6974 if (tmp_ctx
== NULL
) {
6975 return WERR_NOT_ENOUGH_MEMORY
;
6979 result
= WERR_INVALID_HANDLE
;
6983 if (!get_printer_snum(p
, handle
, &snum
, NULL
)) {
6984 result
= WERR_INVALID_HANDLE
;
6988 result
= winreg_printer_binding_handle(tmp_ctx
,
6989 get_session_info_system(),
6992 if (!W_ERROR_IS_OK(result
)) {
6996 result
= winreg_get_printer(tmp_ctx
, b
,
6997 lp_const_servicename(snum
),
6999 if (!W_ERROR_IS_OK(result
)) {
7000 result
= WERR_INVALID_HANDLE
;
7004 /* Do sanity check on the requested changes for Samba */
7005 if (!check_printer_ok(tmp_ctx
, printer
, snum
)) {
7006 result
= WERR_INVALID_PARAMETER
;
7010 /* FIXME!!! If the driver has changed we really should verify that
7011 it is installed before doing much else --jerry */
7013 /* Check calling user has permission to update printer description */
7014 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
7015 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
7016 result
= WERR_ACCESS_DENIED
;
7020 /* Call addprinter hook */
7021 /* Check changes to see if this is really needed */
7023 if (*lp_addprinter_command(talloc_tos(), lp_sub
) &&
7024 (!strequal(printer
->drivername
, old_printer
->drivername
) ||
7025 !strequal(printer
->comment
, old_printer
->comment
) ||
7026 !strequal(printer
->portname
, old_printer
->portname
) ||
7027 !strequal(printer
->location
, old_printer
->location
)) )
7031 raddr
= tsocket_address_inet_addr_string(p
->remote_address
,
7033 if (raddr
== NULL
) {
7034 return WERR_NOT_ENOUGH_MEMORY
;
7037 /* add_printer_hook() will call reload_services() */
7038 if (!add_printer_hook(tmp_ctx
, p
->session_info
->security_token
,
7041 result
= WERR_ACCESS_DENIED
;
7046 result
= update_dsspooler(tmp_ctx
,
7047 get_session_info_system(),
7052 if (!W_ERROR_IS_OK(result
)) {
7056 printer_mask
&= ~SPOOLSS_PRINTER_INFO_SECDESC
;
7058 if (devmode
== NULL
) {
7059 printer_mask
&= ~SPOOLSS_PRINTER_INFO_DEVMODE
;
7061 result
= winreg_update_printer(tmp_ctx
, b
,
7069 talloc_free(tmp_ctx
);
7074 /****************************************************************************
7075 ****************************************************************************/
7076 static WERROR
publish_or_unpublish_printer(struct pipes_struct
*p
,
7077 struct policy_handle
*handle
,
7078 struct spoolss_SetPrinterInfo7
*info7
)
7081 const struct loadparm_substitution
*lp_sub
=
7082 loadparm_s3_global_substitution();
7083 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
7086 struct printer_handle
*Printer
;
7088 if ( lp_security() != SEC_ADS
) {
7089 return WERR_INVALID_LEVEL
;
7092 Printer
= find_printer_index_by_hnd(p
, handle
);
7094 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7
->action
));
7097 return WERR_INVALID_HANDLE
;
7099 if (!get_printer_snum(p
, handle
, &snum
, NULL
))
7100 return WERR_INVALID_HANDLE
;
7102 result
= winreg_get_printer_internal(p
->mem_ctx
,
7103 get_session_info_system(),
7105 lp_servicename(talloc_tos(), lp_sub
, snum
),
7107 if (!W_ERROR_IS_OK(result
)) {
7108 return WERR_INVALID_HANDLE
;
7111 nt_printer_publish(pinfo2
,
7112 get_session_info_system(),
7117 TALLOC_FREE(pinfo2
);
7120 return WERR_INVALID_LEVEL
;
7124 /********************************************************************
7125 ********************************************************************/
7127 static WERROR
update_printer_devmode(struct pipes_struct
*p
,
7128 struct policy_handle
*handle
,
7129 struct spoolss_DeviceMode
*devmode
)
7132 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, handle
);
7133 uint32_t info2_mask
= SPOOLSS_PRINTER_INFO_DEVMODE
;
7135 DEBUG(8,("update_printer_devmode\n"));
7138 return WERR_INVALID_HANDLE
;
7141 if (!get_printer_snum(p
, handle
, &snum
, NULL
)) {
7142 return WERR_INVALID_HANDLE
;
7145 /* Check calling user has permission to update printer description */
7146 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
7147 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
7148 return WERR_ACCESS_DENIED
;
7151 return winreg_update_printer_internal(p
->mem_ctx
,
7152 get_session_info_system(),
7154 lp_const_servicename(snum
),
7162 /****************************************************************
7164 ****************************************************************/
7166 WERROR
_spoolss_SetPrinter(struct pipes_struct
*p
,
7167 struct spoolss_SetPrinter
*r
)
7171 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
7174 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
7175 OUR_HANDLE(r
->in
.handle
)));
7176 return WERR_INVALID_HANDLE
;
7179 /* check the level */
7180 switch (r
->in
.info_ctr
->level
) {
7182 return control_printer(r
->in
.handle
, r
->in
.command
, p
);
7184 result
= update_printer(p
, r
->in
.handle
,
7186 r
->in
.devmode_ctr
->devmode
);
7187 if (!W_ERROR_IS_OK(result
))
7189 if (r
->in
.secdesc_ctr
->sd
)
7190 result
= update_printer_sec(r
->in
.handle
, p
,
7194 return update_printer_sec(r
->in
.handle
, p
,
7197 struct spoolss_PrinterInfo2
*old_printer
;
7198 struct spoolss_SetPrinterInfo2
*set_old_printer
;
7199 struct spoolss_SetPrinterInfoCtr
*info_ctr
;
7200 struct dcerpc_binding_handle
*b
;
7202 TALLOC_CTX
*tmp_ctx
;
7204 tmp_ctx
= talloc_new(p
->mem_ctx
);
7205 if (tmp_ctx
== NULL
) {
7206 return WERR_NOT_ENOUGH_MEMORY
;
7209 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
7210 TALLOC_FREE(tmp_ctx
);
7211 return WERR_INVALID_HANDLE
;
7214 result
= winreg_printer_binding_handle(tmp_ctx
,
7215 get_session_info_system(),
7218 if (!W_ERROR_IS_OK(result
)) {
7219 TALLOC_FREE(tmp_ctx
);
7223 result
= winreg_get_printer(tmp_ctx
, b
,
7224 lp_const_servicename(snum
),
7226 if (!W_ERROR_IS_OK(result
)) {
7227 TALLOC_FREE(tmp_ctx
);
7228 return WERR_INVALID_HANDLE
;
7231 old_printer
->servername
= talloc_strdup(tmp_ctx
, r
->in
.info_ctr
->info
.info4
->servername
);
7232 if (old_printer
->servername
== NULL
) {
7233 TALLOC_FREE(tmp_ctx
);
7234 return WERR_NOT_ENOUGH_MEMORY
;
7237 old_printer
->printername
= talloc_strdup(tmp_ctx
, r
->in
.info_ctr
->info
.info4
->printername
);
7238 if (old_printer
->printername
== NULL
) {
7239 TALLOC_FREE(tmp_ctx
);
7240 return WERR_NOT_ENOUGH_MEMORY
;
7243 old_printer
->attributes
= r
->in
.info_ctr
->info
.info4
->attributes
;
7245 set_old_printer
= talloc_zero(tmp_ctx
, struct spoolss_SetPrinterInfo2
);
7246 if (set_old_printer
== NULL
) {
7247 TALLOC_FREE(tmp_ctx
);
7248 return WERR_NOT_ENOUGH_MEMORY
;
7251 spoolss_printerinfo2_to_setprinterinfo2(old_printer
, set_old_printer
);
7253 info_ctr
= talloc_zero(tmp_ctx
, struct spoolss_SetPrinterInfoCtr
);
7254 if (info_ctr
== NULL
) {
7255 TALLOC_FREE(tmp_ctx
);
7256 return WERR_NOT_ENOUGH_MEMORY
;
7259 info_ctr
->level
= 2;
7260 info_ctr
->info
.info2
= set_old_printer
;
7262 result
= update_printer(p
, r
->in
.handle
,
7264 r
->in
.devmode_ctr
->devmode
);
7266 if (!W_ERROR_IS_OK(result
)) {
7267 TALLOC_FREE(tmp_ctx
);
7271 if (r
->in
.secdesc_ctr
->sd
) {
7272 result
= update_printer_sec(r
->in
.handle
, p
,
7276 TALLOC_FREE(tmp_ctx
);
7280 return publish_or_unpublish_printer(p
, r
->in
.handle
,
7281 r
->in
.info_ctr
->info
.info7
);
7283 return update_printer_devmode(p
, r
->in
.handle
,
7284 r
->in
.devmode_ctr
->devmode
);
7286 return WERR_INVALID_LEVEL
;
7290 /****************************************************************
7291 _spoolss_FindClosePrinterNotify
7292 ****************************************************************/
7294 WERROR
_spoolss_FindClosePrinterNotify(struct pipes_struct
*p
,
7295 struct spoolss_FindClosePrinterNotify
*r
)
7297 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
7300 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
7301 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r
->in
.handle
)));
7302 return WERR_INVALID_HANDLE
;
7305 if (Printer
->notify
.cli_chan
!= NULL
&&
7306 Printer
->notify
.cli_chan
->active_connections
> 0) {
7309 if (Printer
->printer_type
== SPLHND_PRINTER
) {
7310 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
7311 return WERR_INVALID_HANDLE
;
7315 srv_spoolss_replycloseprinter(snum
, Printer
);
7318 Printer
->notify
.flags
=0;
7319 Printer
->notify
.options
=0;
7320 Printer
->notify
.localmachine
[0]='\0';
7321 Printer
->notify
.printerlocal
=0;
7322 TALLOC_FREE(Printer
->notify
.option
);
7327 /****************************************************************
7329 ****************************************************************/
7331 WERROR
_spoolss_AddJob(struct pipes_struct
*p
,
7332 struct spoolss_AddJob
*r
)
7334 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
7335 return WERR_INVALID_PARAMETER
;
7338 /* this is what a NT server returns for AddJob. AddJob must fail on
7339 * non-local printers */
7341 if (r
->in
.level
!= 1) {
7342 return WERR_INVALID_LEVEL
;
7345 return WERR_INVALID_PARAMETER
;
7348 /****************************************************************************
7350 ****************************************************************************/
7352 static WERROR
fill_job_info1(TALLOC_CTX
*mem_ctx
,
7353 struct spoolss_JobInfo1
*r
,
7354 const print_queue_struct
*queue
,
7356 int position
, int snum
,
7357 struct spoolss_PrinterInfo2
*pinfo2
)
7359 const struct loadparm_substitution
*lp_sub
=
7360 loadparm_s3_global_substitution();
7363 t
= gmtime(&queue
->time
);
7367 r
->printer_name
= lp_servicename(mem_ctx
, lp_sub
, snum
);
7368 W_ERROR_HAVE_NO_MEMORY(r
->printer_name
);
7369 r
->server_name
= talloc_strdup(mem_ctx
, pinfo2
->servername
);
7370 W_ERROR_HAVE_NO_MEMORY(r
->server_name
);
7371 r
->user_name
= talloc_strdup(mem_ctx
, queue
->fs_user
);
7372 W_ERROR_HAVE_NO_MEMORY(r
->user_name
);
7373 r
->document_name
= talloc_strdup(mem_ctx
, queue
->fs_file
);
7374 W_ERROR_HAVE_NO_MEMORY(r
->document_name
);
7375 r
->data_type
= talloc_strdup(mem_ctx
, "RAW");
7376 W_ERROR_HAVE_NO_MEMORY(r
->data_type
);
7377 r
->text_status
= talloc_strdup(mem_ctx
, "");
7378 W_ERROR_HAVE_NO_MEMORY(r
->text_status
);
7380 r
->status
= nt_printj_status(queue
->status
);
7381 r
->priority
= queue
->priority
;
7382 r
->position
= position
;
7383 r
->total_pages
= queue
->page_count
;
7384 r
->pages_printed
= 0; /* ??? */
7386 init_systemtime(&r
->submitted
, t
);
7391 /****************************************************************************
7393 ****************************************************************************/
7395 static WERROR
fill_job_info2(TALLOC_CTX
*mem_ctx
,
7396 struct spoolss_JobInfo2
*r
,
7397 const print_queue_struct
*queue
,
7399 int position
, int snum
,
7400 struct spoolss_PrinterInfo2
*pinfo2
,
7401 struct spoolss_DeviceMode
*devmode
)
7403 const struct loadparm_substitution
*lp_sub
=
7404 loadparm_s3_global_substitution();
7407 t
= gmtime(&queue
->time
);
7411 r
->printer_name
= lp_servicename(mem_ctx
, lp_sub
, snum
);
7412 W_ERROR_HAVE_NO_MEMORY(r
->printer_name
);
7413 r
->server_name
= talloc_strdup(mem_ctx
, pinfo2
->servername
);
7414 W_ERROR_HAVE_NO_MEMORY(r
->server_name
);
7415 r
->user_name
= talloc_strdup(mem_ctx
, queue
->fs_user
);
7416 W_ERROR_HAVE_NO_MEMORY(r
->user_name
);
7417 r
->document_name
= talloc_strdup(mem_ctx
, queue
->fs_file
);
7418 W_ERROR_HAVE_NO_MEMORY(r
->document_name
);
7419 r
->notify_name
= talloc_strdup(mem_ctx
, queue
->fs_user
);
7420 W_ERROR_HAVE_NO_MEMORY(r
->notify_name
);
7421 r
->data_type
= talloc_strdup(mem_ctx
, "RAW");
7422 W_ERROR_HAVE_NO_MEMORY(r
->data_type
);
7423 r
->print_processor
= talloc_strdup(mem_ctx
, "winprint");
7424 W_ERROR_HAVE_NO_MEMORY(r
->print_processor
);
7425 r
->parameters
= talloc_strdup(mem_ctx
, "");
7426 W_ERROR_HAVE_NO_MEMORY(r
->parameters
);
7427 r
->driver_name
= talloc_strdup(mem_ctx
, pinfo2
->drivername
);
7428 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
7430 r
->devmode
= devmode
;
7432 r
->text_status
= talloc_strdup(mem_ctx
, "");
7433 W_ERROR_HAVE_NO_MEMORY(r
->text_status
);
7437 r
->status
= nt_printj_status(queue
->status
);
7438 r
->priority
= queue
->priority
;
7439 r
->position
= position
;
7442 r
->total_pages
= queue
->page_count
;
7443 r
->size
= queue
->size
;
7444 init_systemtime(&r
->submitted
, t
);
7446 r
->pages_printed
= 0; /* ??? */
7451 /****************************************************************************
7452 Enumjobs at level 1.
7453 ****************************************************************************/
7455 static WERROR
enumjobs_level1(TALLOC_CTX
*mem_ctx
,
7456 const print_queue_struct
*queue
,
7457 uint32_t num_queues
, int snum
,
7458 struct spoolss_PrinterInfo2
*pinfo2
,
7459 union spoolss_JobInfo
**info_p
,
7462 union spoolss_JobInfo
*info
;
7464 WERROR result
= WERR_OK
;
7465 uint32_t num_filled
;
7466 struct tdb_print_db
*pdb
;
7468 info
= talloc_array(mem_ctx
, union spoolss_JobInfo
, num_queues
);
7470 result
= WERR_NOT_ENOUGH_MEMORY
;
7474 pdb
= get_print_db_byname(pinfo2
->sharename
);
7476 result
= WERR_INVALID_PARAMETER
;
7481 for (i
= 0; i
< num_queues
; i
++) {
7482 uint32_t jobid
= sysjob_to_jobid_pdb(pdb
, queue
[i
].sysjob
);
7483 if (jobid
== (uint32_t)-1) {
7484 DEBUG(4, ("skipping sysjob %d\n", queue
[i
].sysjob
));
7488 result
= fill_job_info1(info
,
7489 &info
[num_filled
].info1
,
7495 if (!W_ERROR_IS_OK(result
)) {
7502 release_print_db(pdb
);
7504 *count
= num_filled
;
7509 release_print_db(pdb
);
7517 /****************************************************************************
7518 Enumjobs at level 2.
7519 ****************************************************************************/
7521 static WERROR
enumjobs_level2(TALLOC_CTX
*mem_ctx
,
7522 const print_queue_struct
*queue
,
7523 uint32_t num_queues
, int snum
,
7524 struct spoolss_PrinterInfo2
*pinfo2
,
7525 union spoolss_JobInfo
**info_p
,
7528 union spoolss_JobInfo
*info
;
7530 WERROR result
= WERR_OK
;
7531 uint32_t num_filled
;
7532 struct tdb_print_db
*pdb
;
7534 info
= talloc_array(mem_ctx
, union spoolss_JobInfo
, num_queues
);
7536 result
= WERR_NOT_ENOUGH_MEMORY
;
7540 pdb
= get_print_db_byname(pinfo2
->sharename
);
7542 result
= WERR_INVALID_PARAMETER
;
7547 for (i
= 0; i
< num_queues
; i
++) {
7548 struct spoolss_DeviceMode
*devmode
;
7549 uint32_t jobid
= sysjob_to_jobid_pdb(pdb
, queue
[i
].sysjob
);
7550 if (jobid
== (uint32_t)-1) {
7551 DEBUG(4, ("skipping sysjob %d\n", queue
[i
].sysjob
));
7555 result
= spoolss_create_default_devmode(info
,
7556 pinfo2
->printername
,
7558 if (!W_ERROR_IS_OK(result
)) {
7559 DEBUG(3, ("Can't proceed w/o a devmode!"));
7563 result
= fill_job_info2(info
,
7564 &info
[num_filled
].info2
,
7571 if (!W_ERROR_IS_OK(result
)) {
7577 release_print_db(pdb
);
7579 *count
= num_filled
;
7584 release_print_db(pdb
);
7592 /****************************************************************************
7593 Enumjobs at level 3.
7594 ****************************************************************************/
7596 static WERROR
enumjobs_level3(TALLOC_CTX
*mem_ctx
,
7597 const print_queue_struct
*queue
,
7598 uint32_t num_queues
, int snum
,
7599 struct spoolss_PrinterInfo2
*pinfo2
,
7600 union spoolss_JobInfo
**info_p
,
7603 union spoolss_JobInfo
*info
;
7605 WERROR result
= WERR_OK
;
7606 uint32_t num_filled
;
7607 struct tdb_print_db
*pdb
;
7609 info
= talloc_array(mem_ctx
, union spoolss_JobInfo
, num_queues
);
7611 result
= WERR_NOT_ENOUGH_MEMORY
;
7615 pdb
= get_print_db_byname(pinfo2
->sharename
);
7617 result
= WERR_INVALID_PARAMETER
;
7622 for (i
= 0; i
< num_queues
; i
++) {
7623 uint32_t jobid
= sysjob_to_jobid_pdb(pdb
, queue
[i
].sysjob
);
7624 if (jobid
== (uint32_t)-1) {
7625 DEBUG(4, ("skipping sysjob %d\n", queue
[i
].sysjob
));
7629 info
[num_filled
].info3
.job_id
= jobid
;
7630 /* next_job_id is overwritten on next iteration */
7631 info
[num_filled
].info3
.next_job_id
= 0;
7632 info
[num_filled
].info3
.reserved
= 0;
7634 if (num_filled
> 0) {
7635 info
[num_filled
- 1].info3
.next_job_id
= jobid
;
7640 release_print_db(pdb
);
7642 *count
= num_filled
;
7653 /****************************************************************
7655 ****************************************************************/
7657 WERROR
_spoolss_EnumJobs(struct pipes_struct
*p
,
7658 struct spoolss_EnumJobs
*r
)
7661 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
7663 print_status_struct prt_status
;
7664 print_queue_struct
*queue
= NULL
;
7667 /* that's an [in out] buffer */
7669 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
7670 return WERR_INVALID_PARAMETER
;
7673 if ((r
->in
.level
!= 1) && (r
->in
.level
!= 2) && (r
->in
.level
!= 3)) {
7674 DEBUG(4, ("EnumJobs level %d not supported\n", r
->in
.level
));
7675 return WERR_INVALID_LEVEL
;
7678 DEBUG(4,("_spoolss_EnumJobs\n"));
7682 *r
->out
.info
= NULL
;
7684 /* lookup the printer snum and tdb entry */
7686 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
7687 return WERR_INVALID_HANDLE
;
7690 result
= winreg_get_printer_internal(p
->mem_ctx
,
7691 get_session_info_system(),
7693 lp_const_servicename(snum
),
7695 if (!W_ERROR_IS_OK(result
)) {
7699 count
= print_queue_status(p
->msg_ctx
, snum
, &queue
, &prt_status
);
7700 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
7701 count
, prt_status
.status
, prt_status
.message
));
7705 TALLOC_FREE(pinfo2
);
7709 switch (r
->in
.level
) {
7711 result
= enumjobs_level1(p
->mem_ctx
, queue
, count
, snum
,
7712 pinfo2
, r
->out
.info
, r
->out
.count
);
7715 result
= enumjobs_level2(p
->mem_ctx
, queue
, count
, snum
,
7716 pinfo2
, r
->out
.info
, r
->out
.count
);
7719 result
= enumjobs_level3(p
->mem_ctx
, queue
, count
, snum
,
7720 pinfo2
, r
->out
.info
, r
->out
.count
);
7723 SMB_ASSERT(false); /* level checked on entry */
7728 TALLOC_FREE(pinfo2
);
7730 if (!W_ERROR_IS_OK(result
)) {
7734 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
7736 *r
->out
.info
, r
->in
.level
,
7738 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
7739 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
7741 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
7744 /****************************************************************
7745 _spoolss_ScheduleJob
7746 ****************************************************************/
7748 WERROR
_spoolss_ScheduleJob(struct pipes_struct
*p
,
7749 struct spoolss_ScheduleJob
*r
)
7754 /****************************************************************
7755 ****************************************************************/
7757 static WERROR
spoolss_setjob_1(TALLOC_CTX
*mem_ctx
,
7758 struct messaging_context
*msg_ctx
,
7759 const char *printer_name
,
7761 struct spoolss_SetJobInfo1
*r
)
7765 if (!print_job_get_name(mem_ctx
, printer_name
, job_id
, &old_doc_name
)) {
7766 return WERR_INVALID_HANDLE
;
7769 if (strequal(old_doc_name
, r
->document_name
)) {
7773 if (!print_job_set_name(global_event_context(), msg_ctx
,
7774 printer_name
, job_id
, r
->document_name
)) {
7775 return WERR_INVALID_HANDLE
;
7781 /****************************************************************
7783 ****************************************************************/
7785 WERROR
_spoolss_SetJob(struct pipes_struct
*p
,
7786 struct spoolss_SetJob
*r
)
7788 const struct auth_session_info
*session_info
= p
->session_info
;
7790 WERROR errcode
= WERR_INVALID_FUNCTION
;
7792 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
7793 return WERR_INVALID_HANDLE
;
7796 if (!print_job_exists(lp_const_servicename(snum
), r
->in
.job_id
)) {
7797 return WERR_INVALID_PRINTER_NAME
;
7800 switch (r
->in
.command
) {
7801 case SPOOLSS_JOB_CONTROL_CANCEL
:
7802 case SPOOLSS_JOB_CONTROL_DELETE
:
7803 errcode
= print_job_delete(session_info
, p
->msg_ctx
,
7804 snum
, r
->in
.job_id
);
7805 if (W_ERROR_EQUAL(errcode
, WERR_PRINTER_HAS_JOBS_QUEUED
)) {
7809 case SPOOLSS_JOB_CONTROL_PAUSE
:
7810 errcode
= print_job_pause(session_info
, p
->msg_ctx
,
7811 snum
, r
->in
.job_id
);
7813 case SPOOLSS_JOB_CONTROL_RESTART
:
7814 case SPOOLSS_JOB_CONTROL_RESUME
:
7815 errcode
= print_job_resume(session_info
, p
->msg_ctx
,
7816 snum
, r
->in
.job_id
);
7818 case SPOOLSS_JOB_CONTROL_NOOP
:
7822 return WERR_INVALID_LEVEL
;
7825 if (!W_ERROR_IS_OK(errcode
)) {
7829 if (r
->in
.ctr
== NULL
) {
7833 switch (r
->in
.ctr
->level
) {
7835 errcode
= spoolss_setjob_1(p
->mem_ctx
, p
->msg_ctx
,
7836 lp_const_servicename(snum
),
7838 r
->in
.ctr
->info
.info1
);
7844 return WERR_INVALID_LEVEL
;
7850 /****************************************************************************
7851 Enumerates all printer drivers by level and architecture.
7852 ****************************************************************************/
7854 static WERROR
enumprinterdrivers_level_by_architecture(TALLOC_CTX
*mem_ctx
,
7855 const struct auth_session_info
*session_info
,
7856 struct messaging_context
*msg_ctx
,
7857 const char *servername
,
7858 const char *architecture
,
7860 union spoolss_DriverInfo
**info_p
,
7865 struct spoolss_DriverInfo8
*driver
;
7866 union spoolss_DriverInfo
*info
= NULL
;
7868 WERROR result
= WERR_OK
;
7869 uint32_t num_drivers
;
7870 const char **drivers
;
7871 struct dcerpc_binding_handle
*b
;
7872 TALLOC_CTX
*tmp_ctx
= NULL
;
7877 tmp_ctx
= talloc_new(mem_ctx
);
7879 return WERR_NOT_ENOUGH_MEMORY
;
7882 result
= winreg_printer_binding_handle(tmp_ctx
,
7886 if (!W_ERROR_IS_OK(result
)) {
7890 for (version
=0; version
<DRIVER_MAX_VERSION
; version
++) {
7891 result
= winreg_get_driver_list(tmp_ctx
, b
,
7892 architecture
, version
,
7893 &num_drivers
, &drivers
);
7894 if (!W_ERROR_IS_OK(result
)) {
7897 DEBUG(4, ("we have:[%d] drivers in environment"
7898 " [%s] and version [%d]\n",
7899 num_drivers
, architecture
, version
));
7901 if (num_drivers
!= 0) {
7902 info
= talloc_realloc(tmp_ctx
, info
,
7903 union spoolss_DriverInfo
,
7904 count
+ num_drivers
);
7906 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
7907 "failed to enlarge driver info buffer!\n"));
7908 result
= WERR_NOT_ENOUGH_MEMORY
;
7913 for (i
= 0; i
< num_drivers
; i
++) {
7914 DEBUG(5, ("\tdriver: [%s]\n", drivers
[i
]));
7916 result
= winreg_get_driver(tmp_ctx
, b
,
7917 architecture
, drivers
[i
],
7919 if (!W_ERROR_IS_OK(result
)) {
7925 result
= fill_printer_driver_info1(info
, &info
[count
+i
].info1
,
7926 driver
, servername
);
7929 result
= fill_printer_driver_info2(info
, &info
[count
+i
].info2
,
7930 driver
, servername
);
7933 result
= fill_printer_driver_info3(info
, &info
[count
+i
].info3
,
7934 driver
, servername
);
7937 result
= fill_printer_driver_info4(info
, &info
[count
+i
].info4
,
7938 driver
, servername
);
7941 result
= fill_printer_driver_info5(info
, &info
[count
+i
].info5
,
7942 driver
, servername
);
7945 result
= fill_printer_driver_info6(info
, &info
[count
+i
].info6
,
7946 driver
, servername
);
7949 result
= fill_printer_driver_info8(info
, &info
[count
+i
].info8
,
7950 driver
, servername
);
7953 result
= WERR_INVALID_LEVEL
;
7957 TALLOC_FREE(driver
);
7959 if (!W_ERROR_IS_OK(result
)) {
7964 count
+= num_drivers
;
7965 TALLOC_FREE(drivers
);
7969 if (W_ERROR_IS_OK(result
)) {
7970 *info_p
= talloc_move(mem_ctx
, &info
);
7974 talloc_free(tmp_ctx
);
7978 /****************************************************************************
7979 Enumerates all printer drivers by level.
7980 ****************************************************************************/
7982 static WERROR
enumprinterdrivers_level(TALLOC_CTX
*mem_ctx
,
7983 const struct auth_session_info
*session_info
,
7984 struct messaging_context
*msg_ctx
,
7985 const char *servername
,
7986 const char *architecture
,
7988 union spoolss_DriverInfo
**info_p
,
7992 WERROR result
= WERR_OK
;
7994 if (strequal(architecture
, SPOOLSS_ARCHITECTURE_ALL
)) {
7996 for (a
=0; archi_table
[a
].long_archi
!= NULL
; a
++) {
7998 union spoolss_DriverInfo
*info
= NULL
;
8001 result
= enumprinterdrivers_level_by_architecture(mem_ctx
,
8005 archi_table
[a
].long_archi
,
8009 if (!W_ERROR_IS_OK(result
)) {
8013 for (i
=0; i
< count
; i
++) {
8014 ADD_TO_ARRAY(mem_ctx
, union spoolss_DriverInfo
,
8015 info
[i
], info_p
, count_p
);
8022 return enumprinterdrivers_level_by_architecture(mem_ctx
,
8032 /****************************************************************
8033 _spoolss_EnumPrinterDrivers
8034 ****************************************************************/
8036 WERROR
_spoolss_EnumPrinterDrivers(struct pipes_struct
*p
,
8037 struct spoolss_EnumPrinterDrivers
*r
)
8039 const char *cservername
;
8042 /* that's an [in out] buffer */
8044 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
8045 return WERR_INVALID_PARAMETER
;
8048 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
8052 *r
->out
.info
= NULL
;
8054 cservername
= canon_servername(r
->in
.server
);
8056 if (!is_myname_or_ipaddr(cservername
)) {
8057 return WERR_UNKNOWN_PRINTER_DRIVER
;
8060 result
= enumprinterdrivers_level(p
->mem_ctx
,
8061 get_session_info_system(),
8068 if (!W_ERROR_IS_OK(result
)) {
8072 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
8073 spoolss_EnumPrinterDrivers
,
8074 *r
->out
.info
, r
->in
.level
,
8076 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
8077 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
8079 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
8082 /****************************************************************
8084 ****************************************************************/
8086 WERROR
_spoolss_EnumForms(struct pipes_struct
*p
,
8087 struct spoolss_EnumForms
*r
)
8093 *r
->out
.info
= NULL
;
8095 /* that's an [in out] buffer */
8097 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0) ) {
8098 return WERR_INVALID_PARAMETER
;
8101 DEBUG(4,("_spoolss_EnumForms\n"));
8102 DEBUGADD(5,("Offered buffer size [%d]\n", r
->in
.offered
));
8103 DEBUGADD(5,("Info level [%d]\n", r
->in
.level
));
8105 switch (r
->in
.level
) {
8107 result
= winreg_printer_enumforms1_internal(p
->mem_ctx
,
8108 get_session_info_system(),
8114 result
= WERR_INVALID_LEVEL
;
8118 if (!W_ERROR_IS_OK(result
)) {
8122 if (*r
->out
.count
== 0) {
8123 return WERR_NO_MORE_ITEMS
;
8126 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
8128 *r
->out
.info
, r
->in
.level
,
8130 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
8131 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
8133 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
8136 /****************************************************************
8138 ****************************************************************/
8140 WERROR
_spoolss_GetForm(struct pipes_struct
*p
,
8141 struct spoolss_GetForm
*r
)
8145 /* that's an [in out] buffer */
8147 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
8148 TALLOC_FREE(r
->out
.info
);
8149 return WERR_INVALID_PARAMETER
;
8152 DEBUG(4,("_spoolss_GetForm\n"));
8153 DEBUGADD(5,("Offered buffer size [%d]\n", r
->in
.offered
));
8154 DEBUGADD(5,("Info level [%d]\n", r
->in
.level
));
8156 switch (r
->in
.level
) {
8158 result
= winreg_printer_getform1_internal(p
->mem_ctx
,
8159 get_session_info_system(),
8162 &r
->out
.info
->info1
);
8165 result
= WERR_INVALID_LEVEL
;
8169 if (!W_ERROR_IS_OK(result
)) {
8170 TALLOC_FREE(r
->out
.info
);
8174 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_FormInfo
,
8175 r
->out
.info
, r
->in
.level
);
8176 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
8178 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
8181 /****************************************************************************
8182 ****************************************************************************/
8184 static WERROR
fill_port_1(TALLOC_CTX
*mem_ctx
,
8185 struct spoolss_PortInfo1
*r
,
8188 r
->port_name
= talloc_strdup(mem_ctx
, name
);
8189 W_ERROR_HAVE_NO_MEMORY(r
->port_name
);
8194 /****************************************************************************
8195 TODO: This probably needs distinguish between TCP/IP and Local ports
8197 ****************************************************************************/
8199 static WERROR
fill_port_2(TALLOC_CTX
*mem_ctx
,
8200 struct spoolss_PortInfo2
*r
,
8203 r
->port_name
= talloc_strdup(mem_ctx
, name
);
8204 W_ERROR_HAVE_NO_MEMORY(r
->port_name
);
8206 r
->monitor_name
= talloc_strdup(mem_ctx
, "Local Monitor");
8207 W_ERROR_HAVE_NO_MEMORY(r
->monitor_name
);
8209 r
->description
= talloc_strdup(mem_ctx
, SPL_LOCAL_PORT
);
8210 W_ERROR_HAVE_NO_MEMORY(r
->description
);
8212 r
->port_type
= SPOOLSS_PORT_TYPE_WRITE
;
8219 /****************************************************************************
8220 wrapper around the enumer ports command
8221 ****************************************************************************/
8223 static WERROR
enumports_hook(TALLOC_CTX
*ctx
, int *count
, char ***lines
)
8225 const struct loadparm_substitution
*lp_sub
=
8226 loadparm_s3_global_substitution();
8227 char *cmd
= lp_enumports_command(talloc_tos(), lp_sub
);
8228 char **qlines
= NULL
;
8229 char *command
= NULL
;
8237 /* if no hook then just fill in the default port */
8240 if (!(qlines
= talloc_array( NULL
, char*, 2 ))) {
8241 return WERR_NOT_ENOUGH_MEMORY
;
8243 if (!(qlines
[0] = talloc_strdup(qlines
, SAMBA_PRINTER_PORT_NAME
))) {
8244 TALLOC_FREE(qlines
);
8245 return WERR_NOT_ENOUGH_MEMORY
;
8251 /* we have a valid enumport command */
8253 command
= talloc_asprintf(ctx
, "%s \"%d\"", cmd
, 1);
8255 return WERR_NOT_ENOUGH_MEMORY
;
8258 DEBUG(10,("Running [%s]\n", command
));
8259 ret
= smbrun(command
, &fd
, NULL
);
8260 DEBUG(10,("Returned [%d]\n", ret
));
8261 TALLOC_FREE(command
);
8266 return WERR_ACCESS_DENIED
;
8270 qlines
= fd_lines_load(fd
, &numlines
, 0, NULL
);
8271 DEBUGADD(10,("Lines returned = [%d]\n", numlines
));
8281 /****************************************************************************
8283 ****************************************************************************/
8285 static WERROR
enumports_level_1(TALLOC_CTX
*mem_ctx
,
8286 union spoolss_PortInfo
**info_p
,
8289 union spoolss_PortInfo
*info
= NULL
;
8291 WERROR result
= WERR_OK
;
8292 char **qlines
= NULL
;
8295 result
= enumports_hook(talloc_tos(), &numlines
, &qlines
);
8296 if (!W_ERROR_IS_OK(result
)) {
8301 info
= talloc_array(mem_ctx
, union spoolss_PortInfo
, numlines
);
8303 DEBUG(10,("Returning WERR_NOT_ENOUGH_MEMORY\n"));
8304 result
= WERR_NOT_ENOUGH_MEMORY
;
8308 for (i
=0; i
<numlines
; i
++) {
8309 DEBUG(6,("Filling port number [%d] with port [%s]\n", i
, qlines
[i
]));
8310 result
= fill_port_1(info
, &info
[i
].info1
, qlines
[i
]);
8311 if (!W_ERROR_IS_OK(result
)) {
8316 TALLOC_FREE(qlines
);
8319 if (!W_ERROR_IS_OK(result
)) {
8321 TALLOC_FREE(qlines
);
8333 /****************************************************************************
8335 ****************************************************************************/
8337 static WERROR
enumports_level_2(TALLOC_CTX
*mem_ctx
,
8338 union spoolss_PortInfo
**info_p
,
8341 union spoolss_PortInfo
*info
= NULL
;
8343 WERROR result
= WERR_OK
;
8344 char **qlines
= NULL
;
8347 result
= enumports_hook(talloc_tos(), &numlines
, &qlines
);
8348 if (!W_ERROR_IS_OK(result
)) {
8353 info
= talloc_array(mem_ctx
, union spoolss_PortInfo
, numlines
);
8355 DEBUG(10,("Returning WERR_NOT_ENOUGH_MEMORY\n"));
8356 result
= WERR_NOT_ENOUGH_MEMORY
;
8360 for (i
=0; i
<numlines
; i
++) {
8361 DEBUG(6,("Filling port number [%d] with port [%s]\n", i
, qlines
[i
]));
8362 result
= fill_port_2(info
, &info
[i
].info2
, qlines
[i
]);
8363 if (!W_ERROR_IS_OK(result
)) {
8368 TALLOC_FREE(qlines
);
8371 if (!W_ERROR_IS_OK(result
)) {
8373 TALLOC_FREE(qlines
);
8385 /****************************************************************
8387 ****************************************************************/
8389 WERROR
_spoolss_EnumPorts(struct pipes_struct
*p
,
8390 struct spoolss_EnumPorts
*r
)
8394 /* that's an [in out] buffer */
8396 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
8397 return WERR_INVALID_PARAMETER
;
8400 DEBUG(4,("_spoolss_EnumPorts\n"));
8404 *r
->out
.info
= NULL
;
8406 switch (r
->in
.level
) {
8408 result
= enumports_level_1(p
->mem_ctx
, r
->out
.info
,
8412 result
= enumports_level_2(p
->mem_ctx
, r
->out
.info
,
8416 return WERR_INVALID_LEVEL
;
8419 if (!W_ERROR_IS_OK(result
)) {
8423 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
8425 *r
->out
.info
, r
->in
.level
,
8427 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
8428 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
8430 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
8433 /****************************************************************************
8434 ****************************************************************************/
8436 static WERROR
spoolss_addprinterex_level_2(struct pipes_struct
*p
,
8438 struct spoolss_SetPrinterInfoCtr
*info_ctr
,
8439 struct spoolss_DeviceMode
*devmode
,
8440 struct security_descriptor
*secdesc
,
8441 struct spoolss_UserLevelCtr
*user_ctr
,
8442 struct policy_handle
*handle
)
8444 struct spoolss_SetPrinterInfo2
*info2
= info_ctr
->info
.info2
;
8445 uint32_t info2_mask
= SPOOLSS_PRINTER_INFO_ALL
;
8446 const struct loadparm_substitution
*lp_sub
=
8447 loadparm_s3_global_substitution();
8449 WERROR err
= WERR_OK
;
8451 /* samba does not have a concept of local, non-shared printers yet, so
8452 * make sure we always setup sharename - gd */
8453 if ((info2
->sharename
== NULL
|| info2
->sharename
[0] == '\0') &&
8454 (info2
->printername
!= NULL
&& info2
->printername
[0] != '\0')) {
8455 DEBUG(5, ("spoolss_addprinterex_level_2: "
8456 "no sharename has been set, setting printername %s as sharename\n",
8457 info2
->printername
));
8458 info2
->sharename
= info2
->printername
;
8461 /* check to see if the printer already exists */
8462 if ((snum
= print_queue_snum(info2
->sharename
)) != -1) {
8463 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
8465 return WERR_PRINTER_ALREADY_EXISTS
;
8468 if (!lp_force_printername(GLOBAL_SECTION_SNUM
)) {
8469 if ((snum
= print_queue_snum(info2
->printername
)) != -1) {
8470 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
8471 info2
->printername
));
8472 return WERR_PRINTER_ALREADY_EXISTS
;
8476 /* validate printer info struct */
8477 if (!info2
->printername
|| strlen(info2
->printername
) == 0) {
8478 return WERR_INVALID_PRINTER_NAME
;
8480 if (!info2
->portname
|| strlen(info2
->portname
) == 0) {
8481 return WERR_UNKNOWN_PORT
;
8483 if (!info2
->drivername
|| strlen(info2
->drivername
) == 0) {
8484 return WERR_UNKNOWN_PRINTER_DRIVER
;
8486 if (!info2
->printprocessor
|| strlen(info2
->printprocessor
) == 0) {
8487 return WERR_UNKNOWN_PRINTPROCESSOR
;
8490 /* FIXME!!! smbd should check to see if the driver is installed before
8491 trying to add a printer like this --jerry */
8493 if (*lp_addprinter_command(talloc_tos(), lp_sub
) ) {
8496 raddr
= tsocket_address_inet_addr_string(p
->remote_address
,
8498 if (raddr
== NULL
) {
8499 return WERR_NOT_ENOUGH_MEMORY
;
8502 if ( !add_printer_hook(p
->mem_ctx
, p
->session_info
->security_token
,
8505 return WERR_ACCESS_DENIED
;
8508 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no "
8509 "smb.conf parameter \"addprinter command\" is defined. This "
8510 "parameter must exist for this call to succeed\n",
8511 info2
->sharename
));
8514 if ((snum
= print_queue_snum(info2
->sharename
)) == -1) {
8515 return WERR_ACCESS_DENIED
;
8518 /* you must be a printer admin to add a new printer */
8519 if (!W_ERROR_IS_OK(print_access_check(p
->session_info
,
8522 PRINTER_ACCESS_ADMINISTER
))) {
8523 return WERR_ACCESS_DENIED
;
8527 * Do sanity check on the requested changes for Samba.
8530 if (!check_printer_ok(p
->mem_ctx
, info2
, snum
)) {
8531 return WERR_INVALID_PARAMETER
;
8534 if (devmode
== NULL
) {
8535 info2_mask
= ~SPOOLSS_PRINTER_INFO_DEVMODE
;
8538 err
= update_dsspooler(p
->mem_ctx
,
8539 get_session_info_system(),
8544 if (!W_ERROR_IS_OK(err
)) {
8548 err
= winreg_update_printer_internal(p
->mem_ctx
,
8549 get_session_info_system(),
8556 if (!W_ERROR_IS_OK(err
)) {
8560 err
= open_printer_hnd(p
, handle
, info2
->printername
, PRINTER_ACCESS_ADMINISTER
);
8561 if (!W_ERROR_IS_OK(err
)) {
8562 /* Handle open failed - remove addition. */
8563 ZERO_STRUCTP(handle
);
8570 /****************************************************************
8571 _spoolss_AddPrinterEx
8572 ****************************************************************/
8574 WERROR
_spoolss_AddPrinterEx(struct pipes_struct
*p
,
8575 struct spoolss_AddPrinterEx
*r
)
8577 switch (r
->in
.info_ctr
->level
) {
8579 /* we don't handle yet */
8580 /* but I know what to do ... */
8581 return WERR_INVALID_LEVEL
;
8583 return spoolss_addprinterex_level_2(p
, r
->in
.server
,
8585 r
->in
.devmode_ctr
->devmode
,
8586 r
->in
.secdesc_ctr
->sd
,
8587 r
->in
.userlevel_ctr
,
8590 return WERR_INVALID_LEVEL
;
8594 /****************************************************************
8596 ****************************************************************/
8598 WERROR
_spoolss_AddPrinter(struct pipes_struct
*p
,
8599 struct spoolss_AddPrinter
*r
)
8601 struct spoolss_AddPrinterEx a
;
8602 struct spoolss_UserLevelCtr userlevel_ctr
;
8604 ZERO_STRUCT(userlevel_ctr
);
8606 userlevel_ctr
.level
= 1;
8608 a
.in
.server
= r
->in
.server
;
8609 a
.in
.info_ctr
= r
->in
.info_ctr
;
8610 a
.in
.devmode_ctr
= r
->in
.devmode_ctr
;
8611 a
.in
.secdesc_ctr
= r
->in
.secdesc_ctr
;
8612 a
.in
.userlevel_ctr
= &userlevel_ctr
;
8613 a
.out
.handle
= r
->out
.handle
;
8615 return _spoolss_AddPrinterEx(p
, &a
);
8618 /****************************************************************
8619 _spoolss_AddPrinterDriverEx
8620 ****************************************************************/
8622 WERROR
_spoolss_AddPrinterDriverEx(struct pipes_struct
*p
,
8623 struct spoolss_AddPrinterDriverEx
*r
)
8625 WERROR err
= WERR_OK
;
8626 const char *driver_name
= NULL
;
8627 const char *driver_directory
= NULL
;
8631 * we only support the semantics of AddPrinterDriver()
8632 * i.e. only copy files that are newer than existing ones
8635 if (r
->in
.flags
== 0) {
8636 return WERR_INVALID_PARAMETER
;
8639 if (!(r
->in
.flags
& APD_COPY_ALL_FILES
) &&
8640 !(r
->in
.flags
& APD_COPY_NEW_FILES
)) {
8641 return WERR_ACCESS_DENIED
;
8645 if (r
->in
.info_ctr
->level
!= 3 &&
8646 r
->in
.info_ctr
->level
!= 6 &&
8647 r
->in
.info_ctr
->level
!= 8) {
8648 DEBUG(0,("%s: level %d not yet implemented\n", __func__
,
8649 r
->in
.info_ctr
->level
));
8650 return WERR_INVALID_LEVEL
;
8653 DEBUG(5,("Cleaning driver's information\n"));
8654 err
= clean_up_driver_struct(p
->mem_ctx
,
8659 if (!W_ERROR_IS_OK(err
)) {
8660 DBG_ERR("clean_up_driver_struct failed - %s\n",
8665 DEBUG(5,("Moving driver to final destination\n"));
8666 err
= move_driver_to_download_area(p
->session_info
,
8669 if (!W_ERROR_IS_OK(err
)) {
8670 DBG_ERR("move_driver_to_download_area failed - %s\n",
8675 err
= winreg_add_driver_internal(p
->mem_ctx
,
8676 get_session_info_system(),
8681 if (!W_ERROR_IS_OK(err
)) {
8682 DBG_ERR("winreg_add_driver_internal failed - %s\n",
8688 * I think this is where he DrvUpgradePrinter() hook would be
8689 * be called in a driver's interface DLL on a Windows NT 4.0/2k
8690 * server. Right now, we just need to send ourselves a message
8691 * to update each printer bound to this driver. --jerry
8694 if (!srv_spoolss_drv_upgrade_printer(driver_name
, p
->msg_ctx
)) {
8695 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
8696 __func__
, driver_name
));
8703 /****************************************************************
8704 _spoolss_AddPrinterDriver
8705 ****************************************************************/
8707 WERROR
_spoolss_AddPrinterDriver(struct pipes_struct
*p
,
8708 struct spoolss_AddPrinterDriver
*r
)
8710 struct spoolss_AddPrinterDriverEx a
;
8712 switch (r
->in
.info_ctr
->level
) {
8719 return WERR_INVALID_LEVEL
;
8722 a
.in
.servername
= r
->in
.servername
;
8723 a
.in
.info_ctr
= r
->in
.info_ctr
;
8724 a
.in
.flags
= APD_COPY_NEW_FILES
;
8726 return _spoolss_AddPrinterDriverEx(p
, &a
);
8729 /****************************************************************************
8730 ****************************************************************************/
8732 struct _spoolss_paths
{
8738 enum { SPOOLSS_DRIVER_PATH
, SPOOLSS_PRTPROCS_PATH
};
8740 static const struct _spoolss_paths spoolss_paths
[]= {
8741 { SPOOLSS_DRIVER_PATH
, "print$", "DRIVERS" },
8742 { SPOOLSS_PRTPROCS_PATH
, "prnproc$", "PRTPROCS" }
8745 static WERROR
compose_spoolss_server_path(TALLOC_CTX
*mem_ctx
,
8746 const char *servername
,
8747 const char *environment
,
8751 const char *pservername
= NULL
;
8752 const char *long_archi
;
8753 const char *short_archi
;
8757 /* environment may be empty */
8758 if (environment
&& strlen(environment
)) {
8759 long_archi
= environment
;
8761 long_archi
= lp_parm_const_string(GLOBAL_SECTION_SNUM
,
8762 "spoolss", "architecture",
8763 GLOBAL_SPOOLSS_ARCHITECTURE
);
8766 /* servername may be empty */
8767 if (servername
&& strlen(servername
)) {
8768 pservername
= canon_servername(servername
);
8770 if (!is_myname_or_ipaddr(pservername
)) {
8771 return WERR_INVALID_PARAMETER
;
8775 if (!(short_archi
= get_short_archi(long_archi
))) {
8776 return WERR_INVALID_ENVIRONMENT
;
8779 switch (component
) {
8780 case SPOOLSS_PRTPROCS_PATH
:
8781 case SPOOLSS_DRIVER_PATH
:
8783 *path
= talloc_asprintf(mem_ctx
,
8786 spoolss_paths
[component
].share
,
8789 *path
= talloc_asprintf(mem_ctx
, "%s\\%s\\%s",
8790 SPOOLSS_DEFAULT_SERVER_PATH
,
8791 spoolss_paths
[component
].dir
,
8796 return WERR_INVALID_PARAMETER
;
8800 return WERR_NOT_ENOUGH_MEMORY
;
8806 /****************************************************************************
8807 ****************************************************************************/
8809 static WERROR
getprinterdriverdir_level_1(TALLOC_CTX
*mem_ctx
,
8810 const char *servername
,
8811 const char *environment
,
8812 struct spoolss_DriverDirectoryInfo1
*r
)
8817 werr
= compose_spoolss_server_path(mem_ctx
,
8820 SPOOLSS_DRIVER_PATH
,
8822 if (!W_ERROR_IS_OK(werr
)) {
8826 DEBUG(4,("printer driver directory: [%s]\n", path
));
8828 r
->directory_name
= path
;
8833 /****************************************************************
8834 _spoolss_GetPrinterDriverDirectory
8835 ****************************************************************/
8837 WERROR
_spoolss_GetPrinterDriverDirectory(struct pipes_struct
*p
,
8838 struct spoolss_GetPrinterDriverDirectory
*r
)
8842 /* that's an [in out] buffer */
8844 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
8845 TALLOC_FREE(r
->out
.info
);
8846 return WERR_INVALID_PARAMETER
;
8849 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
8854 /* r->in.level is ignored */
8856 werror
= getprinterdriverdir_level_1(p
->mem_ctx
,
8859 &r
->out
.info
->info1
);
8860 if (!W_ERROR_IS_OK(werror
)) {
8861 TALLOC_FREE(r
->out
.info
);
8865 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo
,
8866 r
->out
.info
, r
->in
.level
);
8867 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
8869 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
8872 /****************************************************************
8873 _spoolss_EnumPrinterData
8874 ****************************************************************/
8876 WERROR
_spoolss_EnumPrinterData(struct pipes_struct
*p
,
8877 struct spoolss_EnumPrinterData
*r
)
8880 struct spoolss_EnumPrinterDataEx r2
;
8882 struct spoolss_PrinterEnumValues
*info
, *val
= NULL
;
8885 r2
.in
.handle
= r
->in
.handle
;
8886 r2
.in
.key_name
= "PrinterDriverData";
8888 r2
.out
.count
= &count
;
8889 r2
.out
.info
= &info
;
8890 r2
.out
.needed
= &needed
;
8892 result
= _spoolss_EnumPrinterDataEx(p
, &r2
);
8893 if (W_ERROR_EQUAL(result
, WERR_MORE_DATA
)) {
8894 r2
.in
.offered
= needed
;
8895 result
= _spoolss_EnumPrinterDataEx(p
, &r2
);
8897 if (!W_ERROR_IS_OK(result
)) {
8902 * The NT machine wants to know the biggest size of value and data
8904 * cf: MSDN EnumPrinterData remark section
8907 if (!r
->in
.value_offered
&& !r
->in
.data_offered
) {
8908 uint32_t biggest_valuesize
= 0;
8909 uint32_t biggest_datasize
= 0;
8912 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
8914 for (i
=0; i
<count
; i
++) {
8916 name_length
= strlen(info
[i
].value_name
);
8917 if (strlen(info
[i
].value_name
) > biggest_valuesize
) {
8918 biggest_valuesize
= name_length
;
8921 if (info
[i
].data_length
> biggest_datasize
) {
8922 biggest_datasize
= info
[i
].data_length
;
8925 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize
,
8929 /* the value is an UNICODE string but real_value_size is the length
8930 in bytes including the trailing 0 */
8932 *r
->out
.value_needed
= 2 * (1 + biggest_valuesize
);
8933 *r
->out
.data_needed
= biggest_datasize
;
8935 DEBUG(6,("final values: [%d], [%d]\n",
8936 *r
->out
.value_needed
, *r
->out
.data_needed
));
8941 if (r
->in
.enum_index
< count
) {
8942 val
= &info
[r
->in
.enum_index
];
8946 /* out_value should default to "" or else NT4 has
8947 problems unmarshalling the response */
8949 if (r
->in
.value_offered
) {
8950 *r
->out
.value_needed
= 1;
8951 r
->out
.value_name
= talloc_strdup(r
, "");
8952 if (!r
->out
.value_name
) {
8953 return WERR_NOT_ENOUGH_MEMORY
;
8956 r
->out
.value_name
= NULL
;
8957 *r
->out
.value_needed
= 0;
8960 /* the data is counted in bytes */
8962 *r
->out
.data_needed
= r
->in
.data_offered
;
8964 result
= WERR_NO_MORE_ITEMS
;
8968 * - counted in bytes in the request
8969 * - counted in UNICODE chars in the max reply
8970 * - counted in bytes in the real size
8972 * take a pause *before* coding not *during* coding
8976 if (r
->in
.value_offered
) {
8977 r
->out
.value_name
= talloc_strdup(r
, val
->value_name
);
8978 if (!r
->out
.value_name
) {
8979 return WERR_NOT_ENOUGH_MEMORY
;
8981 *r
->out
.value_needed
= val
->value_name_len
;
8983 r
->out
.value_name
= NULL
;
8984 *r
->out
.value_needed
= 0;
8989 *r
->out
.type
= val
->type
;
8991 /* data - counted in bytes */
8994 * See the section "Dynamically Typed Query Parameters"
8998 if (r
->out
.data
&& val
->data
&& val
->data
->data
&&
8999 val
->data_length
&& r
->in
.data_offered
) {
9000 memcpy(r
->out
.data
, val
->data
->data
,
9001 MIN(val
->data_length
,r
->in
.data_offered
));
9004 *r
->out
.data_needed
= val
->data_length
;
9012 /****************************************************************
9013 _spoolss_SetPrinterData
9014 ****************************************************************/
9016 WERROR
_spoolss_SetPrinterData(struct pipes_struct
*p
,
9017 struct spoolss_SetPrinterData
*r
)
9019 struct spoolss_SetPrinterDataEx r2
;
9021 r2
.in
.handle
= r
->in
.handle
;
9022 r2
.in
.key_name
= "PrinterDriverData";
9023 r2
.in
.value_name
= r
->in
.value_name
;
9024 r2
.in
.type
= r
->in
.type
;
9025 r2
.in
.data
= r
->in
.data
;
9026 r2
.in
.offered
= r
->in
.offered
;
9028 return _spoolss_SetPrinterDataEx(p
, &r2
);
9031 /****************************************************************
9032 _spoolss_ResetPrinter
9033 ****************************************************************/
9035 WERROR
_spoolss_ResetPrinter(struct pipes_struct
*p
,
9036 struct spoolss_ResetPrinter
*r
)
9038 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9041 DEBUG(5,("_spoolss_ResetPrinter\n"));
9044 * All we do is to check to see if the handle and queue is valid.
9045 * This call really doesn't mean anything to us because we only
9046 * support RAW printing. --jerry
9050 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
9051 OUR_HANDLE(r
->in
.handle
)));
9052 return WERR_INVALID_HANDLE
;
9055 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
))
9056 return WERR_INVALID_HANDLE
;
9059 /* blindly return success */
9063 /****************************************************************
9064 _spoolss_DeletePrinterData
9065 ****************************************************************/
9067 WERROR
_spoolss_DeletePrinterData(struct pipes_struct
*p
,
9068 struct spoolss_DeletePrinterData
*r
)
9070 struct spoolss_DeletePrinterDataEx r2
;
9072 r2
.in
.handle
= r
->in
.handle
;
9073 r2
.in
.key_name
= "PrinterDriverData";
9074 r2
.in
.value_name
= r
->in
.value_name
;
9076 return _spoolss_DeletePrinterDataEx(p
, &r2
);
9079 /****************************************************************
9081 ****************************************************************/
9083 WERROR
_spoolss_AddForm(struct pipes_struct
*p
,
9084 struct spoolss_AddForm
*r
)
9086 struct spoolss_AddFormInfo1
*form
;
9088 WERROR status
= WERR_OK
;
9089 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9090 struct dcerpc_binding_handle
*b
;
9091 TALLOC_CTX
*tmp_ctx
= NULL
;
9093 DEBUG(5,("_spoolss_AddForm\n"));
9096 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
9097 OUR_HANDLE(r
->in
.handle
)));
9098 return WERR_INVALID_HANDLE
;
9101 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
9102 and not a printer admin, then fail */
9104 if ((p
->session_info
->unix_token
->uid
!= sec_initial_uid()) &&
9105 !security_token_has_privilege(p
->session_info
->security_token
,
9106 SEC_PRIV_PRINT_OPERATOR
)) {
9107 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
9108 return WERR_ACCESS_DENIED
;
9111 if (r
->in
.info_ctr
->level
!= 1) {
9112 return WERR_INVALID_LEVEL
;
9115 form
= r
->in
.info_ctr
->info
.info1
;
9117 return WERR_INVALID_PARAMETER
;
9120 switch (form
->flags
) {
9121 case SPOOLSS_FORM_USER
:
9122 case SPOOLSS_FORM_BUILTIN
:
9123 case SPOOLSS_FORM_PRINTER
:
9126 return WERR_INVALID_PARAMETER
;
9129 tmp_ctx
= talloc_new(p
->mem_ctx
);
9131 return WERR_NOT_ENOUGH_MEMORY
;
9134 status
= winreg_printer_binding_handle(tmp_ctx
,
9135 get_session_info_system(),
9138 if (!W_ERROR_IS_OK(status
)) {
9142 status
= winreg_printer_addform1(tmp_ctx
, b
, form
);
9143 if (!W_ERROR_IS_OK(status
)) {
9148 * ChangeID must always be set if this is a printer
9150 if (Printer
->printer_type
== SPLHND_PRINTER
) {
9151 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9152 status
= WERR_INVALID_HANDLE
;
9156 status
= winreg_printer_update_changeid(tmp_ctx
, b
,
9157 lp_const_servicename(snum
));
9161 talloc_free(tmp_ctx
);
9165 /****************************************************************
9167 ****************************************************************/
9169 WERROR
_spoolss_DeleteForm(struct pipes_struct
*p
,
9170 struct spoolss_DeleteForm
*r
)
9172 const char *form_name
= r
->in
.form_name
;
9173 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9175 WERROR status
= WERR_OK
;
9176 struct dcerpc_binding_handle
*b
;
9177 TALLOC_CTX
*tmp_ctx
= NULL
;
9179 DEBUG(5,("_spoolss_DeleteForm\n"));
9182 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
9183 OUR_HANDLE(r
->in
.handle
)));
9184 return WERR_INVALID_HANDLE
;
9187 if ((p
->session_info
->unix_token
->uid
!= sec_initial_uid()) &&
9188 !security_token_has_privilege(p
->session_info
->security_token
,
9189 SEC_PRIV_PRINT_OPERATOR
)) {
9190 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
9191 return WERR_ACCESS_DENIED
;
9194 tmp_ctx
= talloc_new(p
->mem_ctx
);
9196 return WERR_NOT_ENOUGH_MEMORY
;
9199 status
= winreg_printer_binding_handle(tmp_ctx
,
9200 get_session_info_system(),
9203 if (!W_ERROR_IS_OK(status
)) {
9207 status
= winreg_printer_deleteform1(tmp_ctx
, b
, form_name
);
9208 if (!W_ERROR_IS_OK(status
)) {
9213 * ChangeID must always be set if this is a printer
9215 if (Printer
->printer_type
== SPLHND_PRINTER
) {
9216 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9217 status
= WERR_INVALID_HANDLE
;
9221 status
= winreg_printer_update_changeid(tmp_ctx
, b
,
9222 lp_const_servicename(snum
));
9226 talloc_free(tmp_ctx
);
9230 /****************************************************************
9232 ****************************************************************/
9234 WERROR
_spoolss_SetForm(struct pipes_struct
*p
,
9235 struct spoolss_SetForm
*r
)
9237 struct spoolss_AddFormInfo1
*form
;
9238 const char *form_name
= r
->in
.form_name
;
9240 WERROR status
= WERR_OK
;
9241 struct dcerpc_binding_handle
*b
;
9242 TALLOC_CTX
*tmp_ctx
= NULL
;
9244 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9246 DEBUG(5,("_spoolss_SetForm\n"));
9249 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
9250 OUR_HANDLE(r
->in
.handle
)));
9251 return WERR_INVALID_HANDLE
;
9254 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
9255 and not a printer admin, then fail */
9257 if ((p
->session_info
->unix_token
->uid
!= sec_initial_uid()) &&
9258 !security_token_has_privilege(p
->session_info
->security_token
,
9259 SEC_PRIV_PRINT_OPERATOR
)) {
9260 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
9261 return WERR_ACCESS_DENIED
;
9264 if (r
->in
.info_ctr
->level
!= 1) {
9265 return WERR_INVALID_LEVEL
;
9268 form
= r
->in
.info_ctr
->info
.info1
;
9270 return WERR_INVALID_PARAMETER
;
9273 tmp_ctx
= talloc_new(p
->mem_ctx
);
9275 return WERR_NOT_ENOUGH_MEMORY
;
9278 status
= winreg_printer_binding_handle(tmp_ctx
,
9279 get_session_info_system(),
9282 if (!W_ERROR_IS_OK(status
)) {
9286 status
= winreg_printer_setform1(tmp_ctx
, b
,
9289 if (!W_ERROR_IS_OK(status
)) {
9294 * ChangeID must always be set if this is a printer
9296 if (Printer
->printer_type
== SPLHND_PRINTER
) {
9297 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9298 status
= WERR_INVALID_HANDLE
;
9302 status
= winreg_printer_update_changeid(tmp_ctx
, b
,
9303 lp_const_servicename(snum
));
9307 talloc_free(tmp_ctx
);
9311 /****************************************************************************
9312 fill_print_processor1
9313 ****************************************************************************/
9315 static WERROR
fill_print_processor1(TALLOC_CTX
*mem_ctx
,
9316 struct spoolss_PrintProcessorInfo1
*r
,
9317 const char *print_processor_name
)
9319 r
->print_processor_name
= talloc_strdup(mem_ctx
, print_processor_name
);
9320 W_ERROR_HAVE_NO_MEMORY(r
->print_processor_name
);
9325 /****************************************************************************
9326 enumprintprocessors level 1.
9327 ****************************************************************************/
9329 static WERROR
enumprintprocessors_level_1(TALLOC_CTX
*mem_ctx
,
9330 union spoolss_PrintProcessorInfo
**info_p
,
9333 union spoolss_PrintProcessorInfo
*info
;
9336 info
= talloc_array(mem_ctx
, union spoolss_PrintProcessorInfo
, 1);
9337 W_ERROR_HAVE_NO_MEMORY(info
);
9341 result
= fill_print_processor1(info
, &info
[0].info1
, "winprint");
9342 if (!W_ERROR_IS_OK(result
)) {
9347 if (!W_ERROR_IS_OK(result
)) {
9358 /****************************************************************
9359 _spoolss_EnumPrintProcessors
9360 ****************************************************************/
9362 WERROR
_spoolss_EnumPrintProcessors(struct pipes_struct
*p
,
9363 struct spoolss_EnumPrintProcessors
*r
)
9367 /* that's an [in out] buffer */
9369 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
9370 return WERR_INVALID_PARAMETER
;
9373 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
9376 * Enumerate the print processors ...
9378 * Just reply with "winprint", to keep NT happy
9379 * and I can use my nice printer checker.
9384 *r
->out
.info
= NULL
;
9386 if (!get_short_archi(r
->in
.environment
)) {
9387 return WERR_INVALID_ENVIRONMENT
;
9390 switch (r
->in
.level
) {
9392 result
= enumprintprocessors_level_1(p
->mem_ctx
, r
->out
.info
,
9396 return WERR_INVALID_LEVEL
;
9399 if (!W_ERROR_IS_OK(result
)) {
9403 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
9404 spoolss_EnumPrintProcessors
,
9405 *r
->out
.info
, r
->in
.level
,
9407 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
9408 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
9410 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
9413 /****************************************************************************
9414 fill_printprocdatatype1
9415 ****************************************************************************/
9417 static WERROR
fill_printprocdatatype1(TALLOC_CTX
*mem_ctx
,
9418 struct spoolss_PrintProcDataTypesInfo1
*r
,
9419 const char *name_array
)
9421 r
->name_array
= talloc_strdup(mem_ctx
, name_array
);
9422 W_ERROR_HAVE_NO_MEMORY(r
->name_array
);
9427 /****************************************************************************
9428 enumprintprocdatatypes level 1.
9429 ****************************************************************************/
9431 static WERROR
enumprintprocdatatypes_level_1(TALLOC_CTX
*mem_ctx
,
9432 union spoolss_PrintProcDataTypesInfo
**info_p
,
9436 union spoolss_PrintProcDataTypesInfo
*info
;
9438 info
= talloc_array(mem_ctx
, union spoolss_PrintProcDataTypesInfo
, 1);
9439 W_ERROR_HAVE_NO_MEMORY(info
);
9443 result
= fill_printprocdatatype1(info
, &info
[0].info1
, "RAW");
9444 if (!W_ERROR_IS_OK(result
)) {
9449 if (!W_ERROR_IS_OK(result
)) {
9460 /****************************************************************
9461 _spoolss_EnumPrintProcessorDataTypes
9462 ****************************************************************/
9464 WERROR
_spoolss_EnumPrintProcessorDataTypes(struct pipes_struct
*p
,
9465 struct spoolss_EnumPrintProcessorDataTypes
*r
)
9469 /* that's an [in out] buffer */
9471 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
9472 return WERR_INVALID_PARAMETER
;
9475 DEBUG(5,("_spoolss_EnumPrintProcessorDataTypes\n"));
9479 *r
->out
.info
= NULL
;
9481 if (r
->in
.print_processor_name
== NULL
||
9482 !strequal(r
->in
.print_processor_name
, "winprint")) {
9483 return WERR_UNKNOWN_PRINTPROCESSOR
;
9486 switch (r
->in
.level
) {
9488 result
= enumprintprocdatatypes_level_1(p
->mem_ctx
, r
->out
.info
,
9492 return WERR_INVALID_LEVEL
;
9495 if (!W_ERROR_IS_OK(result
)) {
9499 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
9500 spoolss_EnumPrintProcessorDataTypes
,
9501 *r
->out
.info
, r
->in
.level
,
9503 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
9504 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
9506 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
9509 /****************************************************************************
9511 ****************************************************************************/
9513 static WERROR
fill_monitor_1(TALLOC_CTX
*mem_ctx
,
9514 struct spoolss_MonitorInfo1
*r
,
9515 const char *monitor_name
)
9517 r
->monitor_name
= talloc_strdup(mem_ctx
, monitor_name
);
9518 W_ERROR_HAVE_NO_MEMORY(r
->monitor_name
);
9523 /****************************************************************************
9525 ****************************************************************************/
9527 static WERROR
fill_monitor_2(TALLOC_CTX
*mem_ctx
,
9528 struct spoolss_MonitorInfo2
*r
,
9529 const char *monitor_name
,
9530 const char *environment
,
9531 const char *dll_name
)
9533 r
->monitor_name
= talloc_strdup(mem_ctx
, monitor_name
);
9534 W_ERROR_HAVE_NO_MEMORY(r
->monitor_name
);
9535 r
->environment
= talloc_strdup(mem_ctx
, environment
);
9536 W_ERROR_HAVE_NO_MEMORY(r
->environment
);
9537 r
->dll_name
= talloc_strdup(mem_ctx
, dll_name
);
9538 W_ERROR_HAVE_NO_MEMORY(r
->dll_name
);
9543 /****************************************************************************
9544 enumprintmonitors level 1.
9545 ****************************************************************************/
9547 static WERROR
enumprintmonitors_level_1(TALLOC_CTX
*mem_ctx
,
9548 union spoolss_MonitorInfo
**info_p
,
9551 union spoolss_MonitorInfo
*info
;
9552 WERROR result
= WERR_OK
;
9554 info
= talloc_array(mem_ctx
, union spoolss_MonitorInfo
, 2);
9555 W_ERROR_HAVE_NO_MEMORY(info
);
9559 result
= fill_monitor_1(info
, &info
[0].info1
,
9561 if (!W_ERROR_IS_OK(result
)) {
9565 result
= fill_monitor_1(info
, &info
[1].info1
,
9567 if (!W_ERROR_IS_OK(result
)) {
9572 if (!W_ERROR_IS_OK(result
)) {
9583 /****************************************************************************
9584 enumprintmonitors level 2.
9585 ****************************************************************************/
9587 static WERROR
enumprintmonitors_level_2(TALLOC_CTX
*mem_ctx
,
9588 union spoolss_MonitorInfo
**info_p
,
9591 union spoolss_MonitorInfo
*info
;
9592 WERROR result
= WERR_OK
;
9593 const char *architecture
;
9595 info
= talloc_array(mem_ctx
, union spoolss_MonitorInfo
, 2);
9596 W_ERROR_HAVE_NO_MEMORY(info
);
9600 architecture
= lp_parm_const_string(GLOBAL_SECTION_SNUM
,
9603 GLOBAL_SPOOLSS_ARCHITECTURE
);
9605 result
= fill_monitor_2(info
, &info
[0].info2
,
9609 if (!W_ERROR_IS_OK(result
)) {
9613 result
= fill_monitor_2(info
, &info
[1].info2
,
9617 if (!W_ERROR_IS_OK(result
)) {
9622 if (!W_ERROR_IS_OK(result
)) {
9633 /****************************************************************
9634 _spoolss_EnumMonitors
9635 ****************************************************************/
9637 WERROR
_spoolss_EnumMonitors(struct pipes_struct
*p
,
9638 struct spoolss_EnumMonitors
*r
)
9642 /* that's an [in out] buffer */
9644 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
9645 return WERR_INVALID_PARAMETER
;
9648 DEBUG(5,("_spoolss_EnumMonitors\n"));
9651 * Enumerate the print monitors ...
9653 * Just reply with "Local Port", to keep NT happy
9654 * and I can use my nice printer checker.
9659 *r
->out
.info
= NULL
;
9661 switch (r
->in
.level
) {
9663 result
= enumprintmonitors_level_1(p
->mem_ctx
, r
->out
.info
,
9667 result
= enumprintmonitors_level_2(p
->mem_ctx
, r
->out
.info
,
9671 return WERR_INVALID_LEVEL
;
9674 if (!W_ERROR_IS_OK(result
)) {
9678 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
9679 spoolss_EnumMonitors
,
9680 *r
->out
.info
, r
->in
.level
,
9682 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
9683 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
9685 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
9688 /****************************************************************************
9689 ****************************************************************************/
9691 static WERROR
getjob_level_1(TALLOC_CTX
*mem_ctx
,
9692 const print_queue_struct
*queue
,
9693 int count
, int snum
,
9694 struct spoolss_PrinterInfo2
*pinfo2
,
9697 struct spoolss_JobInfo1
*r
)
9702 for (i
=0; i
<count
; i
++) {
9703 if (queue
[i
].sysjob
== sysjob
) {
9709 if (found
== false) {
9710 /* NT treats not found as bad param... yet another bad choice */
9711 return WERR_INVALID_PARAMETER
;
9714 return fill_job_info1(mem_ctx
,
9723 /****************************************************************************
9724 ****************************************************************************/
9726 static WERROR
getjob_level_2(TALLOC_CTX
*mem_ctx
,
9727 const print_queue_struct
*queue
,
9728 int count
, int snum
,
9729 struct spoolss_PrinterInfo2
*pinfo2
,
9732 struct spoolss_JobInfo2
*r
)
9736 struct spoolss_DeviceMode
*devmode
;
9739 for (i
=0; i
<count
; i
++) {
9740 if (queue
[i
].sysjob
== sysjob
) {
9746 if (found
== false) {
9747 /* NT treats not found as bad param... yet another bad
9749 return WERR_INVALID_PARAMETER
;
9753 * if the print job does not have a DEVMODE associated with it,
9754 * just use the one for the printer. A NULL devicemode is not
9755 * a failure condition
9758 devmode
= print_job_devmode(mem_ctx
, lp_const_servicename(snum
), jobid
);
9760 result
= spoolss_create_default_devmode(mem_ctx
,
9761 pinfo2
->printername
,
9763 if (!W_ERROR_IS_OK(result
)) {
9764 DEBUG(3, ("Can't proceed w/o a devmode!"));
9769 return fill_job_info2(mem_ctx
,
9779 /****************************************************************
9781 ****************************************************************/
9783 WERROR
_spoolss_GetJob(struct pipes_struct
*p
,
9784 struct spoolss_GetJob
*r
)
9786 WERROR result
= WERR_OK
;
9787 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
9788 const char *svc_name
;
9792 struct tdb_print_db
*pdb
;
9793 print_queue_struct
*queue
= NULL
;
9794 print_status_struct prt_status
;
9796 /* that's an [in out] buffer */
9798 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
9799 result
= WERR_INVALID_PARAMETER
;
9800 goto err_jinfo_free
;
9803 DEBUG(5,("_spoolss_GetJob\n"));
9807 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9808 result
= WERR_INVALID_HANDLE
;
9809 goto err_jinfo_free
;
9812 svc_name
= lp_const_servicename(snum
);
9813 if (svc_name
== NULL
) {
9814 result
= WERR_INVALID_PARAMETER
;
9815 goto err_jinfo_free
;
9818 result
= winreg_get_printer_internal(p
->mem_ctx
,
9819 get_session_info_system(),
9823 if (!W_ERROR_IS_OK(result
)) {
9824 goto err_jinfo_free
;
9827 pdb
= get_print_db_byname(svc_name
);
9829 DEBUG(3, ("failed to get print db for svc %s\n", svc_name
));
9830 result
= WERR_INVALID_PARAMETER
;
9831 goto err_pinfo_free
;
9834 sysjob
= jobid_to_sysjob_pdb(pdb
, r
->in
.job_id
);
9835 release_print_db(pdb
);
9837 DEBUG(3, ("no sysjob for spoolss jobid %u\n", r
->in
.job_id
));
9838 result
= WERR_INVALID_PARAMETER
;
9839 goto err_pinfo_free
;
9842 count
= print_queue_status(p
->msg_ctx
, snum
, &queue
, &prt_status
);
9844 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
9845 count
, prt_status
.status
, prt_status
.message
));
9847 switch (r
->in
.level
) {
9849 result
= getjob_level_1(p
->mem_ctx
,
9850 queue
, count
, snum
, pinfo2
,
9851 r
->in
.job_id
, sysjob
,
9852 &r
->out
.info
->info1
);
9855 result
= getjob_level_2(p
->mem_ctx
,
9856 queue
, count
, snum
, pinfo2
,
9857 r
->in
.job_id
, sysjob
,
9858 &r
->out
.info
->info2
);
9861 result
= WERR_INVALID_LEVEL
;
9866 TALLOC_FREE(pinfo2
);
9868 if (!W_ERROR_IS_OK(result
)) {
9869 goto err_jinfo_free
;
9872 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_JobInfo
, r
->out
.info
,
9874 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
9876 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
9879 TALLOC_FREE(pinfo2
);
9881 TALLOC_FREE(r
->out
.info
);
9885 /****************************************************************
9886 _spoolss_GetPrinterDataEx
9887 ****************************************************************/
9889 WERROR
_spoolss_GetPrinterDataEx(struct pipes_struct
*p
,
9890 struct spoolss_GetPrinterDataEx
*r
)
9893 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9894 const char *printer
;
9896 WERROR result
= WERR_OK
;
9898 enum winreg_Type val_type
= REG_NONE
;
9899 uint8_t *val_data
= NULL
;
9900 uint32_t val_size
= 0;
9901 struct dcerpc_binding_handle
*b
;
9902 TALLOC_CTX
*tmp_ctx
;
9904 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
9906 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
9907 r
->in
.key_name
, r
->in
.value_name
));
9909 /* in case of problem, return some default values */
9912 *r
->out
.type
= REG_NONE
;
9914 tmp_ctx
= talloc_new(p
->mem_ctx
);
9916 return WERR_NOT_ENOUGH_MEMORY
;
9920 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9921 OUR_HANDLE(r
->in
.handle
)));
9922 result
= WERR_INVALID_HANDLE
;
9926 /* Is the handle to a printer or to the server? */
9928 if (Printer
->printer_type
== SPLHND_SERVER
) {
9930 union spoolss_PrinterData data
;
9932 result
= getprinterdata_printer_server(tmp_ctx
,
9936 if (!W_ERROR_IS_OK(result
)) {
9940 result
= push_spoolss_PrinterData(tmp_ctx
, &blob
,
9941 *r
->out
.type
, &data
);
9942 if (!W_ERROR_IS_OK(result
)) {
9946 *r
->out
.needed
= blob
.length
;
9948 if (r
->in
.offered
>= *r
->out
.needed
) {
9949 memcpy(r
->out
.data
, blob
.data
, blob
.length
);
9956 /* check to see if the keyname is valid */
9957 if (!strlen(r
->in
.key_name
)) {
9958 result
= WERR_INVALID_PARAMETER
;
9962 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9963 result
= WERR_INVALID_HANDLE
;
9966 printer
= lp_const_servicename(snum
);
9968 result
= winreg_printer_binding_handle(tmp_ctx
,
9969 get_session_info_system(),
9972 if (!W_ERROR_IS_OK(result
)) {
9976 /* XP sends this and wants the ChangeID value from PRINTER_INFO_0 */
9977 if (strequal(r
->in
.key_name
, SPOOL_PRINTERDATA_KEY
) &&
9978 strequal(r
->in
.value_name
, "ChangeId")) {
9979 *r
->out
.type
= REG_DWORD
;
9981 if (r
->in
.offered
>= *r
->out
.needed
) {
9982 uint32_t changeid
= 0;
9984 result
= winreg_printer_get_changeid(tmp_ctx
, b
,
9987 if (!W_ERROR_IS_OK(result
)) {
9991 SIVAL(r
->out
.data
, 0, changeid
);
9997 result
= winreg_get_printer_dataex(tmp_ctx
, b
,
10004 if (!W_ERROR_IS_OK(result
)) {
10008 *r
->out
.needed
= val_size
;
10009 *r
->out
.type
= val_type
;
10011 if (r
->in
.offered
>= *r
->out
.needed
) {
10012 memcpy(r
->out
.data
, val_data
, val_size
);
10016 /* NOTE: do not replace type when returning WERR_MORE_DATA */
10018 if (W_ERROR_IS_OK(result
)) {
10019 result
= SPOOLSS_BUFFER_OK(WERR_OK
, WERR_MORE_DATA
);
10022 talloc_free(tmp_ctx
);
10026 /****************************************************************
10027 _spoolss_SetPrinterDataEx
10028 ****************************************************************/
10030 WERROR
_spoolss_SetPrinterDataEx(struct pipes_struct
*p
,
10031 struct spoolss_SetPrinterDataEx
*r
)
10033 const struct loadparm_substitution
*lp_sub
=
10034 loadparm_s3_global_substitution();
10035 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
10037 WERROR result
= WERR_OK
;
10038 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
10040 struct dcerpc_binding_handle
*b
;
10041 TALLOC_CTX
*tmp_ctx
;
10043 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
10045 /* From MSDN documentation of SetPrinterDataEx: pass request to
10046 SetPrinterData if key is "PrinterDriverData" */
10049 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
10050 OUR_HANDLE(r
->in
.handle
)));
10051 return WERR_INVALID_HANDLE
;
10054 if (Printer
->printer_type
== SPLHND_SERVER
) {
10055 DEBUG(10,("_spoolss_SetPrinterDataEx: "
10056 "Not implemented for server handles yet\n"));
10057 return WERR_INVALID_PARAMETER
;
10060 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
10061 return WERR_INVALID_HANDLE
;
10065 * Access check : NT returns "access denied" if you make a
10066 * SetPrinterData call without the necessary privildge.
10067 * we were originally returning OK if nothing changed
10068 * which made Win2k issue **a lot** of SetPrinterData
10069 * when connecting to a printer --jerry
10072 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
10073 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
10074 "change denied by handle access permissions\n"));
10075 return WERR_ACCESS_DENIED
;
10078 tmp_ctx
= talloc_new(p
->mem_ctx
);
10080 return WERR_NOT_ENOUGH_MEMORY
;
10083 result
= winreg_printer_binding_handle(tmp_ctx
,
10084 get_session_info_system(),
10087 if (!W_ERROR_IS_OK(result
)) {
10091 result
= winreg_get_printer(tmp_ctx
, b
,
10092 lp_servicename(talloc_tos(), lp_sub
, snum
),
10094 if (!W_ERROR_IS_OK(result
)) {
10098 /* check for OID in valuename */
10100 oid_string
= strchr(r
->in
.value_name
, ',');
10102 *oid_string
= '\0';
10106 /* save the registry data */
10108 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
10116 if (W_ERROR_IS_OK(result
)) {
10117 /* save the OID if one was specified */
10119 char *str
= talloc_asprintf(tmp_ctx
, "%s\\%s",
10120 r
->in
.key_name
, SPOOL_OID_KEY
);
10122 result
= WERR_NOT_ENOUGH_MEMORY
;
10127 * I'm not checking the status here on purpose. Don't know
10128 * if this is right, but I'm returning the status from the
10129 * previous set_printer_dataex() call. I have no idea if
10130 * this is right. --jerry
10132 winreg_set_printer_dataex(tmp_ctx
, b
,
10137 (uint8_t *) oid_string
,
10138 strlen(oid_string
) + 1);
10141 result
= winreg_printer_update_changeid(tmp_ctx
, b
,
10142 lp_const_servicename(snum
));
10147 talloc_free(tmp_ctx
);
10151 /****************************************************************
10152 _spoolss_DeletePrinterDataEx
10153 ****************************************************************/
10155 WERROR
_spoolss_DeletePrinterDataEx(struct pipes_struct
*p
,
10156 struct spoolss_DeletePrinterDataEx
*r
)
10158 const char *printer
;
10160 WERROR status
= WERR_OK
;
10161 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
10163 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
10166 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
10167 "Invalid handle (%s:%u:%u).\n",
10168 OUR_HANDLE(r
->in
.handle
)));
10169 return WERR_INVALID_HANDLE
;
10172 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
10173 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
10174 "printer properties change denied by handle\n"));
10175 return WERR_ACCESS_DENIED
;
10178 if (!r
->in
.value_name
|| !r
->in
.key_name
) {
10179 return WERR_NOT_ENOUGH_MEMORY
;
10182 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
10183 return WERR_INVALID_HANDLE
;
10185 printer
= lp_const_servicename(snum
);
10187 status
= winreg_delete_printer_dataex_internal(p
->mem_ctx
,
10188 get_session_info_system(),
10193 if (W_ERROR_IS_OK(status
)) {
10194 status
= winreg_printer_update_changeid_internal(p
->mem_ctx
,
10195 get_session_info_system(),
10203 /****************************************************************
10204 _spoolss_EnumPrinterKey
10205 ****************************************************************/
10207 WERROR
_spoolss_EnumPrinterKey(struct pipes_struct
*p
,
10208 struct spoolss_EnumPrinterKey
*r
)
10211 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
10213 WERROR result
= WERR_FILE_NOT_FOUND
;
10214 const char **array
= NULL
;
10217 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
10220 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
10221 OUR_HANDLE(r
->in
.handle
)));
10222 return WERR_INVALID_HANDLE
;
10225 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
10226 return WERR_INVALID_HANDLE
;
10229 result
= winreg_enum_printer_key_internal(p
->mem_ctx
,
10230 get_session_info_system(),
10232 lp_const_servicename(snum
),
10236 if (!W_ERROR_IS_OK(result
)) {
10240 if (!push_reg_multi_sz(p
->mem_ctx
, &blob
, array
)) {
10241 result
= WERR_NOT_ENOUGH_MEMORY
;
10245 *r
->out
._ndr_size
= r
->in
.offered
/ 2;
10246 *r
->out
.needed
= blob
.length
;
10248 if (r
->in
.offered
< *r
->out
.needed
) {
10249 result
= WERR_MORE_DATA
;
10252 r
->out
.key_buffer
->string_array
= array
;
10256 if (!W_ERROR_IS_OK(result
)) {
10257 TALLOC_FREE(array
);
10258 if (!W_ERROR_EQUAL(result
, WERR_MORE_DATA
)) {
10259 *r
->out
.needed
= 0;
10266 /****************************************************************
10267 _spoolss_DeletePrinterKey
10268 ****************************************************************/
10270 WERROR
_spoolss_DeletePrinterKey(struct pipes_struct
*p
,
10271 struct spoolss_DeletePrinterKey
*r
)
10273 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
10276 const char *printer
;
10277 struct dcerpc_binding_handle
*b
;
10278 TALLOC_CTX
*tmp_ctx
;
10280 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
10283 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
10284 OUR_HANDLE(r
->in
.handle
)));
10285 return WERR_INVALID_HANDLE
;
10288 /* if keyname == NULL, return error */
10289 if ( !r
->in
.key_name
)
10290 return WERR_INVALID_PARAMETER
;
10292 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
10293 return WERR_INVALID_HANDLE
;
10296 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
10297 DEBUG(3, ("_spoolss_DeletePrinterKey: "
10298 "printer properties change denied by handle\n"));
10299 return WERR_ACCESS_DENIED
;
10302 printer
= lp_const_servicename(snum
);
10304 tmp_ctx
= talloc_new(p
->mem_ctx
);
10306 return WERR_NOT_ENOUGH_MEMORY
;
10309 status
= winreg_printer_binding_handle(tmp_ctx
,
10310 get_session_info_system(),
10313 if (!W_ERROR_IS_OK(status
)) {
10317 /* delete the key and all subkeys */
10318 status
= winreg_delete_printer_key(tmp_ctx
, b
,
10321 if (W_ERROR_IS_OK(status
)) {
10322 status
= winreg_printer_update_changeid(tmp_ctx
, b
,
10327 talloc_free(tmp_ctx
);
10331 /****************************************************************
10332 _spoolss_EnumPrinterDataEx
10333 ****************************************************************/
10335 WERROR
_spoolss_EnumPrinterDataEx(struct pipes_struct
*p
,
10336 struct spoolss_EnumPrinterDataEx
*r
)
10338 uint32_t count
= 0;
10339 struct spoolss_PrinterEnumValues
*info
= NULL
;
10340 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
10344 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
10347 *r
->out
.needed
= 0;
10348 *r
->out
.info
= NULL
;
10351 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
10352 OUR_HANDLE(r
->in
.handle
)));
10353 return WERR_INVALID_HANDLE
;
10357 * first check for a keyname of NULL or "". Win2k seems to send
10358 * this a lot and we should send back WERR_INVALID_PARAMETER
10359 * no need to spend time looking up the printer in this case.
10363 if (!strlen(r
->in
.key_name
)) {
10364 result
= WERR_INVALID_PARAMETER
;
10368 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
10369 return WERR_INVALID_HANDLE
;
10372 /* now look for a match on the key name */
10373 result
= winreg_enum_printer_dataex_internal(p
->mem_ctx
,
10374 get_session_info_system(),
10376 lp_const_servicename(snum
),
10380 if (!W_ERROR_IS_OK(result
)) {
10384 #if 0 /* FIXME - gd */
10385 /* housekeeping information in the reply */
10387 /* Fix from Martin Zielinski <mz@seh.de> - ensure
10388 * the hand marshalled container size is a multiple
10389 * of 4 bytes for RPC alignment.
10393 needed
+= 4-(needed
% 4);
10396 *r
->out
.count
= count
;
10397 *r
->out
.info
= info
;
10400 if (!W_ERROR_IS_OK(result
)) {
10404 *r
->out
.needed
= SPOOLSS_BUFFER_ARRAY(p
->mem_ctx
,
10405 spoolss_EnumPrinterDataEx
,
10408 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
10409 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, *r
->out
.count
);
10411 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_MORE_DATA
);
10414 /****************************************************************************
10415 ****************************************************************************/
10417 static WERROR
getprintprocessordirectory_level_1(TALLOC_CTX
*mem_ctx
,
10418 const char *servername
,
10419 const char *environment
,
10420 struct spoolss_PrintProcessorDirectoryInfo1
*r
)
10425 werr
= compose_spoolss_server_path(mem_ctx
,
10428 SPOOLSS_PRTPROCS_PATH
,
10430 if (!W_ERROR_IS_OK(werr
)) {
10434 DEBUG(4,("print processor directory: [%s]\n", path
));
10436 r
->directory_name
= path
;
10441 /****************************************************************
10442 _spoolss_GetPrintProcessorDirectory
10443 ****************************************************************/
10445 WERROR
_spoolss_GetPrintProcessorDirectory(struct pipes_struct
*p
,
10446 struct spoolss_GetPrintProcessorDirectory
*r
)
10449 char *prnproc_share
= NULL
;
10450 bool prnproc_share_exists
= false;
10453 /* that's an [in out] buffer */
10455 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
10456 result
= WERR_INVALID_PARAMETER
;
10457 goto err_info_free
;
10460 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
10463 *r
->out
.needed
= 0;
10465 /* r->in.level is ignored */
10467 /* We always should reply with a local print processor directory so that
10468 * users are not forced to have a [prnproc$] share on the Samba spoolss
10469 * server, if users decide to do so, lets announce it though - Guenther */
10471 snum
= find_service(talloc_tos(), "prnproc$", &prnproc_share
);
10472 if (!prnproc_share
) {
10473 result
= WERR_NOT_ENOUGH_MEMORY
;
10474 goto err_info_free
;
10477 prnproc_share_exists
= true;
10480 result
= getprintprocessordirectory_level_1(p
->mem_ctx
,
10481 prnproc_share_exists
? r
->in
.server
: NULL
,
10483 &r
->out
.info
->info1
);
10484 if (!W_ERROR_IS_OK(result
)) {
10485 goto err_info_free
;
10488 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo
,
10489 r
->out
.info
, r
->in
.level
);
10490 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
10492 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
10495 TALLOC_FREE(r
->out
.info
);
10499 /*******************************************************************
10500 ********************************************************************/
10502 static bool push_monitorui_buf(TALLOC_CTX
*mem_ctx
, DATA_BLOB
*buf
,
10503 const char *dllname
)
10505 enum ndr_err_code ndr_err
;
10506 struct spoolss_MonitorUi ui
;
10508 ui
.dll_name
= dllname
;
10510 ndr_err
= ndr_push_struct_blob(buf
, mem_ctx
, &ui
,
10511 (ndr_push_flags_fn_t
)ndr_push_spoolss_MonitorUi
);
10512 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err
) && (DEBUGLEVEL
>= 10)) {
10513 NDR_PRINT_DEBUG(spoolss_MonitorUi
, &ui
);
10515 return NDR_ERR_CODE_IS_SUCCESS(ndr_err
);
10518 /*******************************************************************
10519 Streams the monitor UI DLL name in UNICODE
10520 *******************************************************************/
10522 static WERROR
xcvtcp_monitorui(TALLOC_CTX
*mem_ctx
,
10523 struct security_token
*token
, DATA_BLOB
*in
,
10524 DATA_BLOB
*out
, uint32_t *needed
)
10526 const char *dllname
= "tcpmonui.dll";
10528 *needed
= (strlen(dllname
)+1) * 2;
10530 if (out
->length
< *needed
) {
10531 return WERR_INSUFFICIENT_BUFFER
;
10534 if (!push_monitorui_buf(mem_ctx
, out
, dllname
)) {
10535 return WERR_NOT_ENOUGH_MEMORY
;
10541 /*******************************************************************
10542 ********************************************************************/
10544 static bool pull_port_data_1(TALLOC_CTX
*mem_ctx
,
10545 struct spoolss_PortData1
*port1
,
10546 const DATA_BLOB
*buf
)
10548 enum ndr_err_code ndr_err
;
10549 ndr_err
= ndr_pull_struct_blob(buf
, mem_ctx
, port1
,
10550 (ndr_pull_flags_fn_t
)ndr_pull_spoolss_PortData1
);
10551 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err
) && (DEBUGLEVEL
>= 10)) {
10552 NDR_PRINT_DEBUG(spoolss_PortData1
, port1
);
10554 return NDR_ERR_CODE_IS_SUCCESS(ndr_err
);
10557 /*******************************************************************
10558 ********************************************************************/
10560 static bool pull_port_data_2(TALLOC_CTX
*mem_ctx
,
10561 struct spoolss_PortData2
*port2
,
10562 const DATA_BLOB
*buf
)
10564 enum ndr_err_code ndr_err
;
10565 ndr_err
= ndr_pull_struct_blob(buf
, mem_ctx
, port2
,
10566 (ndr_pull_flags_fn_t
)ndr_pull_spoolss_PortData2
);
10567 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err
) && (DEBUGLEVEL
>= 10)) {
10568 NDR_PRINT_DEBUG(spoolss_PortData2
, port2
);
10570 return NDR_ERR_CODE_IS_SUCCESS(ndr_err
);
10573 /*******************************************************************
10574 Create a new TCP/IP port
10575 *******************************************************************/
10577 static WERROR
xcvtcp_addport(TALLOC_CTX
*mem_ctx
,
10578 struct security_token
*token
, DATA_BLOB
*in
,
10579 DATA_BLOB
*out
, uint32_t *needed
)
10581 struct spoolss_PortData1 port1
;
10582 struct spoolss_PortData2 port2
;
10583 char *device_uri
= NULL
;
10586 const char *portname
;
10587 const char *hostaddress
;
10589 uint32_t port_number
;
10592 /* peek for spoolss_PortData version */
10594 if (!in
|| (in
->length
< (128 + 4))) {
10595 return WERR_GEN_FAILURE
;
10598 version
= IVAL(in
->data
, 128);
10602 ZERO_STRUCT(port1
);
10604 if (!pull_port_data_1(mem_ctx
, &port1
, in
)) {
10605 return WERR_NOT_ENOUGH_MEMORY
;
10608 portname
= port1
.portname
;
10609 hostaddress
= port1
.hostaddress
;
10610 queue
= port1
.queue
;
10611 protocol
= port1
.protocol
;
10612 port_number
= port1
.port_number
;
10616 ZERO_STRUCT(port2
);
10618 if (!pull_port_data_2(mem_ctx
, &port2
, in
)) {
10619 return WERR_NOT_ENOUGH_MEMORY
;
10622 portname
= port2
.portname
;
10623 hostaddress
= port2
.hostaddress
;
10624 queue
= port2
.queue
;
10625 protocol
= port2
.protocol
;
10626 port_number
= port2
.port_number
;
10630 DEBUG(1,("xcvtcp_addport: "
10631 "unknown version of port_data: %d\n", version
));
10632 return WERR_UNKNOWN_PORT
;
10635 /* create the device URI and call the add_port_hook() */
10637 switch (protocol
) {
10638 case PROTOCOL_RAWTCP_TYPE
:
10639 device_uri
= talloc_asprintf(mem_ctx
,
10640 "socket://%s:%d/", hostaddress
,
10644 case PROTOCOL_LPR_TYPE
:
10645 device_uri
= talloc_asprintf(mem_ctx
,
10646 "lpr://%s/%s", hostaddress
, queue
);
10650 return WERR_UNKNOWN_PORT
;
10654 return WERR_NOT_ENOUGH_MEMORY
;
10657 return add_port_hook(mem_ctx
, token
, portname
, device_uri
);
10660 /*******************************************************************
10661 *******************************************************************/
10663 struct xcv_api_table xcvtcp_cmds
[] = {
10664 { "MonitorUI", xcvtcp_monitorui
},
10665 { "AddPort", xcvtcp_addport
},
10669 static WERROR
process_xcvtcp_command(TALLOC_CTX
*mem_ctx
,
10670 struct security_token
*token
, const char *command
,
10677 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command
));
10679 for ( i
=0; xcvtcp_cmds
[i
].name
; i
++ ) {
10680 if ( strcmp( command
, xcvtcp_cmds
[i
].name
) == 0 )
10681 return xcvtcp_cmds
[i
].fn(mem_ctx
, token
, inbuf
, outbuf
, needed
);
10684 return WERR_INVALID_FUNCTION
;
10687 /*******************************************************************
10688 *******************************************************************/
10689 #if 0 /* don't support management using the "Local Port" monitor */
10691 static WERROR
xcvlocal_monitorui(TALLOC_CTX
*mem_ctx
,
10692 struct security_token
*token
, DATA_BLOB
*in
,
10693 DATA_BLOB
*out
, uint32_t *needed
)
10695 const char *dllname
= "localui.dll";
10697 *needed
= (strlen(dllname
)+1) * 2;
10699 if (out
->length
< *needed
) {
10700 return WERR_INSUFFICIENT_BUFFER
;
10703 if (!push_monitorui_buf(mem_ctx
, out
, dllname
)) {
10704 return WERR_NOT_ENOUGH_MEMORY
;
10710 /*******************************************************************
10711 *******************************************************************/
10713 struct xcv_api_table xcvlocal_cmds
[] = {
10714 { "MonitorUI", xcvlocal_monitorui
},
10718 struct xcv_api_table xcvlocal_cmds
[] = {
10725 /*******************************************************************
10726 *******************************************************************/
10728 static WERROR
process_xcvlocal_command(TALLOC_CTX
*mem_ctx
,
10729 struct security_token
*token
, const char *command
,
10730 DATA_BLOB
*inbuf
, DATA_BLOB
*outbuf
,
10735 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command
));
10737 for ( i
=0; xcvlocal_cmds
[i
].name
; i
++ ) {
10738 if ( strcmp( command
, xcvlocal_cmds
[i
].name
) == 0 )
10739 return xcvlocal_cmds
[i
].fn(mem_ctx
, token
, inbuf
, outbuf
, needed
);
10741 return WERR_INVALID_FUNCTION
;
10744 /****************************************************************
10746 ****************************************************************/
10748 WERROR
_spoolss_XcvData(struct pipes_struct
*p
,
10749 struct spoolss_XcvData
*r
)
10751 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
10752 DATA_BLOB out_data
= data_blob_null
;
10756 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
10757 OUR_HANDLE(r
->in
.handle
)));
10758 return WERR_INVALID_HANDLE
;
10761 /* Has to be a handle to the TCP/IP port monitor */
10763 if ( !(Printer
->printer_type
& (SPLHND_PORTMON_LOCAL
|SPLHND_PORTMON_TCP
)) ) {
10764 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
10765 return WERR_INVALID_HANDLE
;
10768 /* requires administrative access to the server */
10770 if ( !(Printer
->access_granted
& SERVER_ACCESS_ADMINISTER
) ) {
10771 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
10772 return WERR_ACCESS_DENIED
;
10775 /* Allocate the outgoing buffer */
10777 if (r
->in
.out_data_size
) {
10778 out_data
= data_blob_talloc_zero(p
->mem_ctx
, r
->in
.out_data_size
);
10779 if (out_data
.data
== NULL
) {
10780 return WERR_NOT_ENOUGH_MEMORY
;
10784 switch ( Printer
->printer_type
) {
10785 case SPLHND_PORTMON_TCP
:
10786 werror
= process_xcvtcp_command(p
->mem_ctx
,
10787 p
->session_info
->security_token
,
10788 r
->in
.function_name
,
10789 &r
->in
.in_data
, &out_data
,
10792 case SPLHND_PORTMON_LOCAL
:
10793 werror
= process_xcvlocal_command(p
->mem_ctx
,
10794 p
->session_info
->security_token
,
10795 r
->in
.function_name
,
10796 &r
->in
.in_data
, &out_data
,
10800 werror
= WERR_INVALID_PRINT_MONITOR
;
10803 if (!W_ERROR_IS_OK(werror
)) {
10807 *r
->out
.status_code
= 0;
10809 if (r
->out
.out_data
&& out_data
.data
&& r
->in
.out_data_size
&& out_data
.length
) {
10810 memcpy(r
->out
.out_data
, out_data
.data
,
10811 MIN(r
->in
.out_data_size
, out_data
.length
));
10817 /****************************************************************
10818 _spoolss_AddPrintProcessor
10819 ****************************************************************/
10821 WERROR
_spoolss_AddPrintProcessor(struct pipes_struct
*p
,
10822 struct spoolss_AddPrintProcessor
*r
)
10824 /* for now, just indicate success and ignore the add. We'll
10825 automatically set the winprint processor for printer
10826 entries later. Used to debug the LexMark Optra S 1855 PCL
10832 /****************************************************************
10834 ****************************************************************/
10836 WERROR
_spoolss_AddPort(struct pipes_struct
*p
,
10837 struct spoolss_AddPort
*r
)
10839 /* do what w2k3 does */
10841 return WERR_NOT_SUPPORTED
;
10844 /****************************************************************
10845 _spoolss_GetPrinterDriver
10846 ****************************************************************/
10848 WERROR
_spoolss_GetPrinterDriver(struct pipes_struct
*p
,
10849 struct spoolss_GetPrinterDriver
*r
)
10851 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10852 return WERR_NOT_SUPPORTED
;
10855 /****************************************************************
10856 _spoolss_ReadPrinter
10857 ****************************************************************/
10859 WERROR
_spoolss_ReadPrinter(struct pipes_struct
*p
,
10860 struct spoolss_ReadPrinter
*r
)
10862 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10863 return WERR_NOT_SUPPORTED
;
10866 /****************************************************************
10867 _spoolss_WaitForPrinterChange
10868 ****************************************************************/
10870 WERROR
_spoolss_WaitForPrinterChange(struct pipes_struct
*p
,
10871 struct spoolss_WaitForPrinterChange
*r
)
10873 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10874 return WERR_NOT_SUPPORTED
;
10877 /****************************************************************
10878 _spoolss_ConfigurePort
10879 ****************************************************************/
10881 WERROR
_spoolss_ConfigurePort(struct pipes_struct
*p
,
10882 struct spoolss_ConfigurePort
*r
)
10884 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10885 return WERR_NOT_SUPPORTED
;
10888 /****************************************************************
10889 _spoolss_DeletePort
10890 ****************************************************************/
10892 WERROR
_spoolss_DeletePort(struct pipes_struct
*p
,
10893 struct spoolss_DeletePort
*r
)
10895 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10896 return WERR_NOT_SUPPORTED
;
10899 /****************************************************************
10900 _spoolss_CreatePrinterIC
10901 ****************************************************************/
10903 WERROR
_spoolss_CreatePrinterIC(struct pipes_struct
*p
,
10904 struct spoolss_CreatePrinterIC
*r
)
10906 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10907 return WERR_NOT_SUPPORTED
;
10910 /****************************************************************
10911 _spoolss_PlayGDIScriptOnPrinterIC
10912 ****************************************************************/
10914 WERROR
_spoolss_PlayGDIScriptOnPrinterIC(struct pipes_struct
*p
,
10915 struct spoolss_PlayGDIScriptOnPrinterIC
*r
)
10917 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10918 return WERR_NOT_SUPPORTED
;
10921 /****************************************************************
10922 _spoolss_DeletePrinterIC
10923 ****************************************************************/
10925 WERROR
_spoolss_DeletePrinterIC(struct pipes_struct
*p
,
10926 struct spoolss_DeletePrinterIC
*r
)
10928 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10929 return WERR_NOT_SUPPORTED
;
10932 /****************************************************************
10933 _spoolss_AddPrinterConnection
10934 ****************************************************************/
10936 WERROR
_spoolss_AddPrinterConnection(struct pipes_struct
*p
,
10937 struct spoolss_AddPrinterConnection
*r
)
10939 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10940 return WERR_NOT_SUPPORTED
;
10943 /****************************************************************
10944 _spoolss_DeletePrinterConnection
10945 ****************************************************************/
10947 WERROR
_spoolss_DeletePrinterConnection(struct pipes_struct
*p
,
10948 struct spoolss_DeletePrinterConnection
*r
)
10950 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10951 return WERR_NOT_SUPPORTED
;
10954 /****************************************************************
10955 _spoolss_PrinterMessageBox
10956 ****************************************************************/
10958 WERROR
_spoolss_PrinterMessageBox(struct pipes_struct
*p
,
10959 struct spoolss_PrinterMessageBox
*r
)
10961 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10962 return WERR_NOT_SUPPORTED
;
10965 /****************************************************************
10966 _spoolss_AddMonitor
10967 ****************************************************************/
10969 WERROR
_spoolss_AddMonitor(struct pipes_struct
*p
,
10970 struct spoolss_AddMonitor
*r
)
10972 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10973 return WERR_NOT_SUPPORTED
;
10976 /****************************************************************
10977 _spoolss_DeleteMonitor
10978 ****************************************************************/
10980 WERROR
_spoolss_DeleteMonitor(struct pipes_struct
*p
,
10981 struct spoolss_DeleteMonitor
*r
)
10983 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10984 return WERR_NOT_SUPPORTED
;
10987 /****************************************************************
10988 _spoolss_DeletePrintProcessor
10989 ****************************************************************/
10991 WERROR
_spoolss_DeletePrintProcessor(struct pipes_struct
*p
,
10992 struct spoolss_DeletePrintProcessor
*r
)
10994 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10995 return WERR_NOT_SUPPORTED
;
10998 /****************************************************************
10999 _spoolss_AddPrintProvidor
11000 ****************************************************************/
11002 WERROR
_spoolss_AddPrintProvidor(struct pipes_struct
*p
,
11003 struct spoolss_AddPrintProvidor
*r
)
11005 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11006 return WERR_NOT_SUPPORTED
;
11009 /****************************************************************
11010 _spoolss_DeletePrintProvidor
11011 ****************************************************************/
11013 WERROR
_spoolss_DeletePrintProvidor(struct pipes_struct
*p
,
11014 struct spoolss_DeletePrintProvidor
*r
)
11016 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11017 return WERR_NOT_SUPPORTED
;
11020 /****************************************************************
11021 _spoolss_FindFirstPrinterChangeNotification
11022 ****************************************************************/
11024 WERROR
_spoolss_FindFirstPrinterChangeNotification(struct pipes_struct
*p
,
11025 struct spoolss_FindFirstPrinterChangeNotification
*r
)
11027 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11028 return WERR_NOT_SUPPORTED
;
11031 /****************************************************************
11032 _spoolss_FindNextPrinterChangeNotification
11033 ****************************************************************/
11035 WERROR
_spoolss_FindNextPrinterChangeNotification(struct pipes_struct
*p
,
11036 struct spoolss_FindNextPrinterChangeNotification
*r
)
11038 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11039 return WERR_NOT_SUPPORTED
;
11042 /****************************************************************
11043 _spoolss_RouterFindFirstPrinterChangeNotificationOld
11044 ****************************************************************/
11046 WERROR
_spoolss_RouterFindFirstPrinterChangeNotificationOld(struct pipes_struct
*p
,
11047 struct spoolss_RouterFindFirstPrinterChangeNotificationOld
*r
)
11049 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11050 return WERR_NOT_SUPPORTED
;
11053 /****************************************************************
11054 _spoolss_ReplyOpenPrinter
11055 ****************************************************************/
11057 WERROR
_spoolss_ReplyOpenPrinter(struct pipes_struct
*p
,
11058 struct spoolss_ReplyOpenPrinter
*r
)
11060 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11061 return WERR_NOT_SUPPORTED
;
11064 /****************************************************************
11065 _spoolss_RouterReplyPrinter
11066 ****************************************************************/
11068 WERROR
_spoolss_RouterReplyPrinter(struct pipes_struct
*p
,
11069 struct spoolss_RouterReplyPrinter
*r
)
11071 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11072 return WERR_NOT_SUPPORTED
;
11075 /****************************************************************
11076 _spoolss_ReplyClosePrinter
11077 ****************************************************************/
11079 WERROR
_spoolss_ReplyClosePrinter(struct pipes_struct
*p
,
11080 struct spoolss_ReplyClosePrinter
*r
)
11082 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11083 return WERR_NOT_SUPPORTED
;
11086 /****************************************************************
11088 ****************************************************************/
11090 WERROR
_spoolss_AddPortEx(struct pipes_struct
*p
,
11091 struct spoolss_AddPortEx
*r
)
11093 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11094 return WERR_NOT_SUPPORTED
;
11097 /****************************************************************
11098 _spoolss_RouterFindFirstPrinterChangeNotification
11099 ****************************************************************/
11101 WERROR
_spoolss_RouterFindFirstPrinterChangeNotification(struct pipes_struct
*p
,
11102 struct spoolss_RouterFindFirstPrinterChangeNotification
*r
)
11104 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11105 return WERR_NOT_SUPPORTED
;
11108 /****************************************************************
11109 _spoolss_SpoolerInit
11110 ****************************************************************/
11112 WERROR
_spoolss_SpoolerInit(struct pipes_struct
*p
,
11113 struct spoolss_SpoolerInit
*r
)
11115 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11116 return WERR_NOT_SUPPORTED
;
11119 /****************************************************************
11120 _spoolss_ResetPrinterEx
11121 ****************************************************************/
11123 WERROR
_spoolss_ResetPrinterEx(struct pipes_struct
*p
,
11124 struct spoolss_ResetPrinterEx
*r
)
11126 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11127 return WERR_NOT_SUPPORTED
;
11130 /****************************************************************
11131 _spoolss_RouterReplyPrinterEx
11132 ****************************************************************/
11134 WERROR
_spoolss_RouterReplyPrinterEx(struct pipes_struct
*p
,
11135 struct spoolss_RouterReplyPrinterEx
*r
)
11137 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11138 return WERR_NOT_SUPPORTED
;
11141 /****************************************************************
11143 ****************************************************************/
11145 WERROR
_spoolss_44(struct pipes_struct
*p
,
11146 struct spoolss_44
*r
)
11148 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11149 return WERR_NOT_SUPPORTED
;
11152 /****************************************************************
11154 ****************************************************************/
11156 WERROR
_spoolss_SetPort(struct pipes_struct
*p
,
11157 struct spoolss_SetPort
*r
)
11159 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11160 return WERR_NOT_SUPPORTED
;
11163 /****************************************************************
11165 ****************************************************************/
11167 WERROR
_spoolss_4a(struct pipes_struct
*p
,
11168 struct spoolss_4a
*r
)
11170 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11171 return WERR_NOT_SUPPORTED
;
11174 /****************************************************************
11176 ****************************************************************/
11178 WERROR
_spoolss_4b(struct pipes_struct
*p
,
11179 struct spoolss_4b
*r
)
11181 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11182 return WERR_NOT_SUPPORTED
;
11185 /****************************************************************
11187 ****************************************************************/
11189 WERROR
_spoolss_4c(struct pipes_struct
*p
,
11190 struct spoolss_4c
*r
)
11192 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11193 return WERR_NOT_SUPPORTED
;
11196 /****************************************************************
11198 ****************************************************************/
11200 WERROR
_spoolss_53(struct pipes_struct
*p
,
11201 struct spoolss_53
*r
)
11203 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11204 return WERR_NOT_SUPPORTED
;
11207 /****************************************************************
11208 _spoolss_AddPerMachineConnection
11209 ****************************************************************/
11211 WERROR
_spoolss_AddPerMachineConnection(struct pipes_struct
*p
,
11212 struct spoolss_AddPerMachineConnection
*r
)
11214 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11215 return WERR_NOT_SUPPORTED
;
11218 /****************************************************************
11219 _spoolss_DeletePerMachineConnection
11220 ****************************************************************/
11222 WERROR
_spoolss_DeletePerMachineConnection(struct pipes_struct
*p
,
11223 struct spoolss_DeletePerMachineConnection
*r
)
11225 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11226 return WERR_NOT_SUPPORTED
;
11229 /****************************************************************
11230 _spoolss_EnumPerMachineConnections
11231 ****************************************************************/
11233 WERROR
_spoolss_EnumPerMachineConnections(struct pipes_struct
*p
,
11234 struct spoolss_EnumPerMachineConnections
*r
)
11236 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11237 return WERR_NOT_SUPPORTED
;
11240 /****************************************************************
11242 ****************************************************************/
11244 WERROR
_spoolss_5a(struct pipes_struct
*p
,
11245 struct spoolss_5a
*r
)
11247 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11248 return WERR_NOT_SUPPORTED
;
11251 /****************************************************************
11253 ****************************************************************/
11255 WERROR
_spoolss_5b(struct pipes_struct
*p
,
11256 struct spoolss_5b
*r
)
11258 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11259 return WERR_NOT_SUPPORTED
;
11262 /****************************************************************
11264 ****************************************************************/
11266 WERROR
_spoolss_5c(struct pipes_struct
*p
,
11267 struct spoolss_5c
*r
)
11269 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11270 return WERR_NOT_SUPPORTED
;
11273 /****************************************************************
11275 ****************************************************************/
11277 WERROR
_spoolss_5d(struct pipes_struct
*p
,
11278 struct spoolss_5d
*r
)
11280 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11281 return WERR_NOT_SUPPORTED
;
11284 /****************************************************************
11286 ****************************************************************/
11288 WERROR
_spoolss_5e(struct pipes_struct
*p
,
11289 struct spoolss_5e
*r
)
11291 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11292 return WERR_NOT_SUPPORTED
;
11295 /****************************************************************
11297 ****************************************************************/
11299 WERROR
_spoolss_5f(struct pipes_struct
*p
,
11300 struct spoolss_5f
*r
)
11302 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11303 return WERR_NOT_SUPPORTED
;
11306 /****************************************************************
11308 ****************************************************************/
11310 WERROR
_spoolss_60(struct pipes_struct
*p
,
11311 struct spoolss_60
*r
)
11313 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11314 return WERR_NOT_SUPPORTED
;
11317 /****************************************************************
11318 _spoolss_SendRecvBidiData
11319 ****************************************************************/
11321 WERROR
_spoolss_SendRecvBidiData(struct pipes_struct
*p
,
11322 struct spoolss_SendRecvBidiData
*r
)
11324 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11325 return WERR_NOT_SUPPORTED
;
11328 /****************************************************************
11330 ****************************************************************/
11332 WERROR
_spoolss_62(struct pipes_struct
*p
,
11333 struct spoolss_62
*r
)
11335 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11336 return WERR_NOT_SUPPORTED
;
11339 /****************************************************************
11341 ****************************************************************/
11343 WERROR
_spoolss_63(struct pipes_struct
*p
,
11344 struct spoolss_63
*r
)
11346 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11347 return WERR_NOT_SUPPORTED
;
11350 /****************************************************************
11352 ****************************************************************/
11354 WERROR
_spoolss_64(struct pipes_struct
*p
,
11355 struct spoolss_64
*r
)
11357 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11358 return WERR_NOT_SUPPORTED
;
11361 /****************************************************************
11363 ****************************************************************/
11365 WERROR
_spoolss_65(struct pipes_struct
*p
,
11366 struct spoolss_65
*r
)
11368 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11369 return WERR_NOT_SUPPORTED
;
11372 /****************************************************************
11373 _spoolss_GetCorePrinterDrivers
11374 ****************************************************************/
11376 HRESULT
_spoolss_GetCorePrinterDrivers(struct pipes_struct
*p
,
11377 struct spoolss_GetCorePrinterDrivers
*r
)
11379 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11380 return HRES_ERROR_NOT_SUPPORTED
;
11383 /****************************************************************
11385 ****************************************************************/
11387 WERROR
_spoolss_67(struct pipes_struct
*p
,
11388 struct spoolss_67
*r
)
11390 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11391 return WERR_NOT_SUPPORTED
;
11394 /****************************************************************
11395 _spoolss_GetPrinterDriverPackagePath
11396 ****************************************************************/
11398 HRESULT
_spoolss_GetPrinterDriverPackagePath(struct pipes_struct
*p
,
11399 struct spoolss_GetPrinterDriverPackagePath
*r
)
11401 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11402 return HRES_ERROR_NOT_SUPPORTED
;
11405 /****************************************************************
11407 ****************************************************************/
11409 WERROR
_spoolss_69(struct pipes_struct
*p
,
11410 struct spoolss_69
*r
)
11412 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11413 return WERR_NOT_SUPPORTED
;
11416 /****************************************************************
11418 ****************************************************************/
11420 WERROR
_spoolss_6a(struct pipes_struct
*p
,
11421 struct spoolss_6a
*r
)
11423 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11424 return WERR_NOT_SUPPORTED
;
11427 /****************************************************************
11429 ****************************************************************/
11431 WERROR
_spoolss_6b(struct pipes_struct
*p
,
11432 struct spoolss_6b
*r
)
11434 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11435 return WERR_NOT_SUPPORTED
;
11438 /****************************************************************
11440 ****************************************************************/
11442 WERROR
_spoolss_6c(struct pipes_struct
*p
,
11443 struct spoolss_6c
*r
)
11445 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11446 return WERR_NOT_SUPPORTED
;
11449 /****************************************************************
11451 ****************************************************************/
11453 WERROR
_spoolss_6d(struct pipes_struct
*p
,
11454 struct spoolss_6d
*r
)
11456 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11457 return WERR_NOT_SUPPORTED
;
11460 /****************************************************************
11461 _spoolss_GetJobNamedPropertyValue
11462 ****************************************************************/
11464 WERROR
_spoolss_GetJobNamedPropertyValue(struct pipes_struct
*p
,
11465 struct spoolss_GetJobNamedPropertyValue
*r
)
11467 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11468 return WERR_NOT_SUPPORTED
;
11471 /****************************************************************
11472 _spoolss_SetJobNamedProperty
11473 ****************************************************************/
11475 WERROR
_spoolss_SetJobNamedProperty(struct pipes_struct
*p
,
11476 struct spoolss_SetJobNamedProperty
*r
)
11478 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11479 return WERR_NOT_SUPPORTED
;
11482 /****************************************************************
11483 _spoolss_DeleteJobNamedProperty
11484 ****************************************************************/
11486 WERROR
_spoolss_DeleteJobNamedProperty(struct pipes_struct
*p
,
11487 struct spoolss_DeleteJobNamedProperty
*r
)
11489 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11490 return WERR_NOT_SUPPORTED
;
11493 /****************************************************************
11494 _spoolss_EnumJobNamedProperties
11495 ****************************************************************/
11497 WERROR
_spoolss_EnumJobNamedProperties(struct pipes_struct
*p
,
11498 struct spoolss_EnumJobNamedProperties
*r
)
11500 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11501 return WERR_NOT_SUPPORTED
;
11504 /****************************************************************
11506 ****************************************************************/
11508 WERROR
_spoolss_72(struct pipes_struct
*p
,
11509 struct spoolss_72
*r
)
11511 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11512 return WERR_NOT_SUPPORTED
;
11515 /****************************************************************
11517 ****************************************************************/
11519 WERROR
_spoolss_73(struct pipes_struct
*p
,
11520 struct spoolss_73
*r
)
11522 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11523 return WERR_NOT_SUPPORTED
;
11526 /****************************************************************
11527 _spoolss_RpcLogJobInfoForBranchOffice
11528 ****************************************************************/
11530 WERROR
_spoolss_LogJobInfoForBranchOffice(struct pipes_struct
*p
,
11531 struct spoolss_LogJobInfoForBranchOffice
*r
)
11533 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11534 return WERR_NOT_SUPPORTED
;
11537 static NTSTATUS
spoolss__op_init_server(struct dcesrv_context
*dce_ctx
,
11538 const struct dcesrv_endpoint_server
*ep_server
);
11540 static NTSTATUS
spoolss__op_shutdown_server(struct dcesrv_context
*dce_ctx
,
11541 const struct dcesrv_endpoint_server
*ep_server
);
11543 #define DCESRV_INTERFACE_SPOOLSS_INIT_SERVER \
11544 spoolss_init_server
11546 #define DCESRV_INTERFACE_SPOOLSS_SHUTDOWN_SERVER \
11547 spoolss_shutdown_server
11549 static NTSTATUS
spoolss_init_server(struct dcesrv_context
*dce_ctx
,
11550 const struct dcesrv_endpoint_server
*ep_server
)
11552 struct messaging_context
*msg_ctx
= global_messaging_context();
11556 status
= dcesrv_init_ep_server(dce_ctx
, "winreg");
11557 if (!NT_STATUS_IS_OK(status
)) {
11562 * Migrate the printers first.
11564 ok
= nt_printing_tdb_migrate(msg_ctx
);
11566 return NT_STATUS_UNSUCCESSFUL
;
11569 return spoolss__op_init_server(dce_ctx
, ep_server
);
11572 static NTSTATUS
spoolss_shutdown_server(struct dcesrv_context
*dce_ctx
,
11573 const struct dcesrv_endpoint_server
*ep_server
)
11575 srv_spoolss_cleanup();
11577 return spoolss__op_shutdown_server(dce_ctx
, ep_server
);
11580 /* include the generated boilerplate */
11581 #include "librpc/gen_ndr/ndr_spoolss_scompat.c"