2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-2000,
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
6 * Copyright (C) Jean François Micouleau 1998-2000,
7 * Copyright (C) Jeremy Allison 2001-2002,
8 * Copyright (C) Gerald Carter 2000-2004,
9 * Copyright (C) Tim Potter 2001-2002.
10 * Copyright (C) Guenther Deschner 2009-2010.
11 * Copyright (C) Andreas Schneider 2010.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 /* Since the SPOOLSS rpc routines are basically DOS 16-bit calls wrapped
28 up, all the errors returned are DOS errors, not NT status codes. */
32 #include "nt_printing.h"
33 #include "srv_spoolss_util.h"
34 #include "../librpc/gen_ndr/srv_spoolss.h"
35 #include "../librpc/gen_ndr/ndr_spoolss_c.h"
36 #include "rpc_client/init_spoolss.h"
37 #include "rpc_client/cli_pipe.h"
38 #include "../libcli/security/security.h"
39 #include "librpc/gen_ndr/ndr_security.h"
41 #include "include/printing.h"
43 #include "../librpc/gen_ndr/netlogon.h"
45 #include "printing/notify.h"
47 #include "../libcli/registry/util_reg.h"
48 #include "smbd/smbd.h"
49 #include "smbd/globals.h"
52 #include "rpc_server/spoolss/srv_spoolss_nt.h"
54 #include "libsmb/libsmb.h"
55 #include "printing/printer_list.h"
56 #include "../lib/tsocket/tsocket.h"
57 #include "rpc_client/cli_winreg_spoolss.h"
58 #include "../libcli/smb/smbXcli_base.h"
60 /* macros stolen from s4 spoolss server */
61 #define SPOOLSS_BUFFER_UNION(fn,info,level) \
62 ((info)?ndr_size_##fn(info, level, 0):0)
64 #define SPOOLSS_BUFFER_UNION_ARRAY(mem_ctx,fn,info,level,count) \
65 ((info)?ndr_size_##fn##_info(mem_ctx, level, count, info):0)
67 #define SPOOLSS_BUFFER_ARRAY(mem_ctx,fn,info,count) \
68 ((info)?ndr_size_##fn##_info(mem_ctx, count, info):0)
70 #define SPOOLSS_BUFFER_OK(val_true,val_false) ((r->in.offered >= *r->out.needed)?val_true:val_false)
73 #define DBGC_CLASS DBGC_RPC_SRV
75 #ifndef MAX_OPEN_PRINTER_EXS
76 #define MAX_OPEN_PRINTER_EXS 50
79 struct notify_back_channel
;
81 /* structure to store the printer handles */
82 /* and a reference to what it's pointing to */
83 /* and the notify info asked about */
84 /* that's the central struct */
85 struct printer_handle
{
86 struct printer_handle
*prev
, *next
;
87 bool document_started
;
89 uint32 jobid
; /* jobid in printing backend */
91 const char *servername
;
94 uint32 access_granted
;
100 struct spoolss_NotifyOption
*option
;
101 struct policy_handle cli_hnd
;
102 struct notify_back_channel
*cli_chan
;
104 /* are we in a FindNextPrinterChangeNotify() call? */
106 struct messaging_context
*msg_ctx
;
113 /* devmode sent in the OpenPrinter() call */
114 struct spoolss_DeviceMode
*devmode
;
116 /* TODO cache the printer info2 structure */
117 struct spoolss_PrinterInfo2
*info2
;
121 static struct printer_handle
*printers_list
;
123 struct printer_session_counter
{
124 struct printer_session_counter
*next
;
125 struct printer_session_counter
*prev
;
131 static struct printer_session_counter
*counter_list
;
133 struct notify_back_channel
{
134 struct notify_back_channel
*prev
, *next
;
136 /* associated client */
137 struct sockaddr_storage client_address
;
139 /* print notify back-channel pipe handle*/
140 struct rpc_pipe_client
*cli_pipe
;
141 uint32_t active_connections
;
144 static struct notify_back_channel
*back_channels
;
146 /* Map generic permissions to printer object specific permissions */
148 const struct standard_mapping printer_std_mapping
= {
155 /* Map generic permissions to print server object specific permissions */
157 const struct standard_mapping printserver_std_mapping
= {
164 /* API table for Xcv Monitor functions */
166 struct xcv_api_table
{
168 WERROR(*fn
) (TALLOC_CTX
*mem_ctx
, struct security_token
*token
, DATA_BLOB
*in
, DATA_BLOB
*out
, uint32_t *needed
);
171 static void prune_printername_cache(void);
173 /********************************************************************
174 * Canonicalize servername.
175 ********************************************************************/
177 static const char *canon_servername(const char *servername
)
179 const char *pservername
= servername
;
180 while (*pservername
== '\\') {
186 /* translate between internal status numbers and NT status numbers */
187 static int nt_printj_status(int v
)
193 return JOB_STATUS_PAUSED
;
195 return JOB_STATUS_SPOOLING
;
197 return JOB_STATUS_PRINTING
;
199 return JOB_STATUS_ERROR
;
201 return JOB_STATUS_DELETING
;
203 return JOB_STATUS_OFFLINE
;
205 return JOB_STATUS_PAPEROUT
;
207 return JOB_STATUS_PRINTED
;
209 return JOB_STATUS_DELETED
;
211 return JOB_STATUS_BLOCKED_DEVQ
;
212 case LPQ_USER_INTERVENTION
:
213 return JOB_STATUS_USER_INTERVENTION
;
218 static int nt_printq_status(int v
)
222 return PRINTER_STATUS_PAUSED
;
231 /***************************************************************************
232 Disconnect from the client
233 ****************************************************************************/
235 static void srv_spoolss_replycloseprinter(int snum
,
236 struct printer_handle
*prn_hnd
)
242 * Tell the specific printing tdb we no longer want messages for this printer
243 * by deregistering our PID.
246 if (!print_notify_deregister_pid(snum
)) {
247 DEBUG(0, ("Failed to register our pid for printer %s\n",
248 lp_const_servicename(snum
)));
251 /* weird if the test succeeds !!! */
252 if (prn_hnd
->notify
.cli_chan
== NULL
||
253 prn_hnd
->notify
.cli_chan
->cli_pipe
== NULL
||
254 prn_hnd
->notify
.cli_chan
->cli_pipe
->binding_handle
== NULL
||
255 prn_hnd
->notify
.cli_chan
->active_connections
== 0) {
256 DEBUG(0, ("Trying to close unexisting backchannel!\n"));
257 DLIST_REMOVE(back_channels
, prn_hnd
->notify
.cli_chan
);
258 TALLOC_FREE(prn_hnd
->notify
.cli_chan
);
262 status
= dcerpc_spoolss_ReplyClosePrinter(
263 prn_hnd
->notify
.cli_chan
->cli_pipe
->binding_handle
,
265 &prn_hnd
->notify
.cli_hnd
,
267 if (!NT_STATUS_IS_OK(status
)) {
268 DEBUG(0, ("dcerpc_spoolss_ReplyClosePrinter failed [%s].\n",
270 result
= ntstatus_to_werror(status
);
271 } else if (!W_ERROR_IS_OK(result
)) {
272 DEBUG(0, ("reply_close_printer failed [%s].\n",
273 win_errstr(result
)));
276 /* if it's the last connection, deconnect the IPC$ share */
277 if (prn_hnd
->notify
.cli_chan
->active_connections
== 1) {
279 cli_shutdown(rpc_pipe_np_smb_conn(prn_hnd
->notify
.cli_chan
->cli_pipe
));
280 DLIST_REMOVE(back_channels
, prn_hnd
->notify
.cli_chan
);
281 TALLOC_FREE(prn_hnd
->notify
.cli_chan
);
283 if (prn_hnd
->notify
.msg_ctx
!= NULL
) {
284 messaging_deregister(prn_hnd
->notify
.msg_ctx
,
285 MSG_PRINTER_NOTIFY2
, NULL
);
289 if (prn_hnd
->notify
.cli_chan
) {
290 prn_hnd
->notify
.cli_chan
->active_connections
--;
291 prn_hnd
->notify
.cli_chan
= NULL
;
295 /****************************************************************************
296 Functions to free a printer entry datastruct.
297 ****************************************************************************/
299 static int printer_entry_destructor(struct printer_handle
*Printer
)
301 if (Printer
->notify
.cli_chan
!= NULL
&&
302 Printer
->notify
.cli_chan
->active_connections
> 0) {
305 switch(Printer
->printer_type
) {
307 srv_spoolss_replycloseprinter(snum
, Printer
);
311 snum
= print_queue_snum(Printer
->sharename
);
313 srv_spoolss_replycloseprinter(snum
, Printer
);
321 Printer
->notify
.flags
=0;
322 Printer
->notify
.options
=0;
323 Printer
->notify
.localmachine
[0]='\0';
324 Printer
->notify
.printerlocal
=0;
325 TALLOC_FREE(Printer
->notify
.option
);
326 TALLOC_FREE(Printer
->devmode
);
328 /* Remove from the internal list. */
329 DLIST_REMOVE(printers_list
, Printer
);
333 /****************************************************************************
334 find printer index by handle
335 ****************************************************************************/
337 static struct printer_handle
*find_printer_index_by_hnd(struct pipes_struct
*p
,
338 struct policy_handle
*hnd
)
340 struct printer_handle
*find_printer
= NULL
;
342 if(!find_policy_by_hnd(p
,hnd
,(void **)(void *)&find_printer
)) {
343 DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: "));
350 /****************************************************************************
351 Close printer index by handle.
352 ****************************************************************************/
354 static bool close_printer_handle(struct pipes_struct
*p
, struct policy_handle
*hnd
)
356 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, hnd
);
359 DEBUG(2,("close_printer_handle: Invalid handle (%s:%u:%u)\n",
364 close_policy_hnd(p
, hnd
);
369 /****************************************************************************
370 Delete a printer given a handle.
371 ****************************************************************************/
373 static WERROR
delete_printer_hook(TALLOC_CTX
*ctx
, struct security_token
*token
,
374 const char *sharename
,
375 struct messaging_context
*msg_ctx
)
377 char *cmd
= lp_deleteprinter_cmd(talloc_tos());
378 char *command
= NULL
;
380 bool is_print_op
= false;
382 /* can't fail if we don't try */
387 command
= talloc_asprintf(ctx
,
394 is_print_op
= security_token_has_privilege(token
, SEC_PRIV_PRINT_OPERATOR
);
396 DEBUG(10,("Running [%s]\n", command
));
398 /********** BEGIN SePrintOperatorPrivlege BLOCK **********/
403 if ( (ret
= smbrun(command
, NULL
)) == 0 ) {
404 /* Tell everyone we updated smb.conf. */
405 message_send_all(msg_ctx
, MSG_SMB_CONF_UPDATED
, NULL
, 0, NULL
);
411 /********** END SePrintOperatorPrivlege BLOCK **********/
413 DEBUGADD(10,("returned [%d]\n", ret
));
415 TALLOC_FREE(command
);
418 return WERR_BADFID
; /* What to return here? */
423 /****************************************************************************
424 Delete a printer given a handle.
425 ****************************************************************************/
427 static WERROR
delete_printer_handle(struct pipes_struct
*p
, struct policy_handle
*hnd
)
429 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, hnd
);
433 DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n",
439 * It turns out that Windows allows delete printer on a handle
440 * opened by an admin user, then used on a pipe handle created
441 * by an anonymous user..... but they're working on security.... riiight !
445 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
446 DEBUG(3, ("delete_printer_handle: denied by handle\n"));
447 return WERR_ACCESS_DENIED
;
450 /* this does not need a become root since the access check has been
451 done on the handle already */
453 result
= winreg_delete_printer_key_internal(p
->mem_ctx
,
454 get_session_info_system(),
458 if (!W_ERROR_IS_OK(result
)) {
459 DEBUG(3,("Error deleting printer %s\n", Printer
->sharename
));
463 result
= delete_printer_hook(p
->mem_ctx
, p
->session_info
->security_token
,
464 Printer
->sharename
, p
->msg_ctx
);
465 if (!W_ERROR_IS_OK(result
)) {
468 prune_printername_cache();
472 /****************************************************************************
473 Return the snum of a printer corresponding to an handle.
474 ****************************************************************************/
476 static bool get_printer_snum(struct pipes_struct
*p
, struct policy_handle
*hnd
,
477 int *number
, struct share_params
**params
)
479 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, hnd
);
482 DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n",
487 switch (Printer
->printer_type
) {
489 DEBUG(4,("short name:%s\n", Printer
->sharename
));
490 *number
= print_queue_snum(Printer
->sharename
);
491 return (*number
!= -1);
499 /****************************************************************************
500 Set printer handle type.
501 Check if it's \\server or \\server\printer
502 ****************************************************************************/
504 static bool set_printer_hnd_printertype(struct printer_handle
*Printer
, const char *handlename
)
506 DEBUG(3,("Setting printer type=%s\n", handlename
));
508 /* it's a print server */
509 if (handlename
&& *handlename
=='\\' && *(handlename
+1)=='\\' && !strchr_m(handlename
+2, '\\')) {
510 DEBUGADD(4,("Printer is a print server\n"));
511 Printer
->printer_type
= SPLHND_SERVER
;
513 /* it's a printer (set_printer_hnd_name() will handle port monitors */
515 DEBUGADD(4,("Printer is a printer\n"));
516 Printer
->printer_type
= SPLHND_PRINTER
;
522 static void prune_printername_cache_fn(const char *key
, const char *value
,
523 time_t timeout
, void *private_data
)
528 static void prune_printername_cache(void)
530 gencache_iterate(prune_printername_cache_fn
, NULL
, "PRINTERNAME/*");
533 /****************************************************************************
534 Set printer handle name.. Accept names like \\server, \\server\printer,
535 \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
536 the MSDN docs regarding OpenPrinter() for details on the XcvData() and
537 XcvDataPort() interface.
538 ****************************************************************************/
540 static WERROR
set_printer_hnd_name(TALLOC_CTX
*mem_ctx
,
541 const struct auth_session_info
*session_info
,
542 struct messaging_context
*msg_ctx
,
543 struct printer_handle
*Printer
,
544 const char *handlename
)
547 int n_services
=lp_numservices();
549 const char *printername
;
550 const char *servername
= NULL
;
553 struct spoolss_PrinterInfo2
*info2
= NULL
;
558 * Hopefully nobody names his printers like this. Maybe \ or ,
559 * are illegal in printer names even?
561 const char printer_not_found
[] = "Printer \\, !@#$%^&*( not found";
565 DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename
,
566 (unsigned long)strlen(handlename
)));
568 aprinter
= discard_const_p(char, handlename
);
569 if ( *handlename
== '\\' ) {
570 servername
= canon_servername(handlename
);
571 if ( (aprinter
= strchr_m( servername
, '\\' )) != NULL
) {
575 if (!is_myname_or_ipaddr(servername
)) {
576 return WERR_INVALID_PRINTER_NAME
;
578 Printer
->servername
= talloc_asprintf(Printer
, "\\\\%s", servername
);
579 if (Printer
->servername
== NULL
) {
584 if (Printer
->printer_type
== SPLHND_SERVER
) {
588 if (Printer
->printer_type
!= SPLHND_PRINTER
) {
589 return WERR_INVALID_HANDLE
;
592 DEBUGADD(5, ("searching for [%s]\n", aprinter
));
594 p
= strchr(aprinter
, ',');
601 if (strncmp(p
, "DrvConvert", strlen("DrvConvert")) == 0) {
603 } else if (strncmp(p
, "LocalOnly", strlen("LocalOnly")) == 0) {
609 DEBUGADD(5, ("stripped handlename: [%s]\n", aprinter
));
612 /* check for the Port Monitor Interface */
613 if ( strequal( aprinter
, SPL_XCV_MONITOR_TCPMON
) ) {
614 Printer
->printer_type
= SPLHND_PORTMON_TCP
;
615 fstrcpy(sname
, SPL_XCV_MONITOR_TCPMON
);
618 else if ( strequal( aprinter
, SPL_XCV_MONITOR_LOCALMON
) ) {
619 Printer
->printer_type
= SPLHND_PORTMON_LOCAL
;
620 fstrcpy(sname
, SPL_XCV_MONITOR_LOCALMON
);
625 * With hundreds of printers, the "for" loop iterating all
626 * shares can be quite expensive, as it is done on every
627 * OpenPrinter. The loop maps "aprinter" to "sname", the
628 * result of which we cache in gencache.
631 cache_key
= talloc_asprintf(talloc_tos(), "PRINTERNAME/%s",
633 if ((cache_key
!= NULL
) && gencache_get(cache_key
, &tmp
, NULL
)) {
635 found
= (strcmp(tmp
, printer_not_found
) != 0);
637 DEBUG(4, ("Printer %s not found\n", aprinter
));
639 return WERR_INVALID_PRINTER_NAME
;
645 /* Search all sharenames first as this is easier than pulling
646 the printer_info_2 off of disk. Don't use find_service() since
647 that calls out to map_username() */
649 /* do another loop to look for printernames */
650 for (snum
= 0; !found
&& snum
< n_services
; snum
++) {
651 const char *printer
= lp_const_servicename(snum
);
653 /* no point going on if this is not a printer */
654 if (!(lp_snum_ok(snum
) && lp_print_ok(snum
))) {
658 /* ignore [printers] share */
659 if (strequal(printer
, "printers")) {
663 fstrcpy(sname
, printer
);
664 if (strequal(aprinter
, printer
)) {
669 /* no point looking up the printer object if
670 we aren't allowing printername != sharename */
671 if (lp_force_printername(snum
)) {
675 result
= winreg_get_printer_internal(mem_ctx
,
680 if ( !W_ERROR_IS_OK(result
) ) {
681 DEBUG(2,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
682 sname
, win_errstr(result
)));
686 printername
= strrchr(info2
->printername
, '\\');
687 if (printername
== NULL
) {
688 printername
= info2
->printername
;
693 if (strequal(printername
, aprinter
)) {
698 DEBUGADD(10, ("printername: %s\n", printername
));
704 if (cache_key
!= NULL
) {
705 gencache_set(cache_key
, printer_not_found
,
707 TALLOC_FREE(cache_key
);
709 DEBUGADD(4,("Printer not found\n"));
710 return WERR_INVALID_PRINTER_NAME
;
713 if (cache_key
!= NULL
) {
714 gencache_set(cache_key
, sname
, time(NULL
)+300);
715 TALLOC_FREE(cache_key
);
718 DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter
, sname
));
720 strlcpy(Printer
->sharename
, sname
, sizeof(Printer
->sharename
));
725 /****************************************************************************
726 Find first available printer slot. creates a printer handle for you.
727 ****************************************************************************/
729 static WERROR
open_printer_hnd(struct pipes_struct
*p
,
730 struct policy_handle
*hnd
,
732 uint32_t access_granted
)
734 struct printer_handle
*new_printer
;
737 DEBUG(10,("open_printer_hnd: name [%s]\n", name
));
739 new_printer
= talloc_zero(p
->mem_ctx
, struct printer_handle
);
740 if (new_printer
== NULL
) {
743 talloc_set_destructor(new_printer
, printer_entry_destructor
);
745 /* This also steals the printer_handle on the policy_handle */
746 if (!create_policy_hnd(p
, hnd
, new_printer
)) {
747 TALLOC_FREE(new_printer
);
748 return WERR_INVALID_HANDLE
;
751 /* Add to the internal list. */
752 DLIST_ADD(printers_list
, new_printer
);
754 new_printer
->notify
.option
=NULL
;
756 if (!set_printer_hnd_printertype(new_printer
, name
)) {
757 close_printer_handle(p
, hnd
);
758 return WERR_INVALID_HANDLE
;
761 result
= set_printer_hnd_name(p
->mem_ctx
,
762 get_session_info_system(),
765 if (!W_ERROR_IS_OK(result
)) {
766 close_printer_handle(p
, hnd
);
770 new_printer
->access_granted
= access_granted
;
772 DEBUG(5, ("%d printer handles active\n",
773 (int)num_pipe_handles(p
)));
778 /***************************************************************************
779 check to see if the client motify handle is monitoring the notification
780 given by (notify_type, notify_field).
781 **************************************************************************/
783 static bool is_monitoring_event_flags(uint32_t flags
, uint16_t notify_type
,
784 uint16_t notify_field
)
789 static bool is_monitoring_event(struct printer_handle
*p
, uint16_t notify_type
,
790 uint16_t notify_field
)
792 struct spoolss_NotifyOption
*option
= p
->notify
.option
;
796 * Flags should always be zero when the change notify
797 * is registered by the client's spooler. A user Win32 app
798 * might use the flags though instead of the NOTIFY_OPTION_INFO
807 return is_monitoring_event_flags(
808 p
->notify
.flags
, notify_type
, notify_field
);
810 for (i
= 0; i
< option
->count
; i
++) {
812 /* Check match for notify_type */
814 if (option
->types
[i
].type
!= notify_type
)
817 /* Check match for field */
819 for (j
= 0; j
< option
->types
[i
].count
; j
++) {
820 if (option
->types
[i
].fields
[j
].field
== notify_field
) {
826 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
827 p
->servername
, p
->sharename
, notify_type
, notify_field
));
832 #define SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(_data, _integer) \
833 _data->data.integer[0] = _integer; \
834 _data->data.integer[1] = 0;
837 #define SETUP_SPOOLSS_NOTIFY_DATA_STRING(_data, _p) \
838 _data->data.string.string = talloc_strdup(mem_ctx, _p); \
839 if (!_data->data.string.string) {\
840 _data->data.string.size = 0; \
842 _data->data.string.size = strlen_m_term(_p) * 2;
844 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
845 _data->data.devmode.devmode = _devmode;
847 #define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _sd) \
848 _data->data.sd.sd = dup_sec_desc(mem_ctx, _sd); \
849 if (!_data->data.sd.sd) { \
850 _data->data.sd.sd_size = 0; \
852 _data->data.sd.sd_size = \
853 ndr_size_security_descriptor(_data->data.sd.sd, 0);
855 static void init_systemtime_buffer(TALLOC_CTX
*mem_ctx
,
860 struct spoolss_Time st
;
864 if (!init_systemtime(&st
, t
)) {
868 p
= talloc_array(mem_ctx
, char, len
);
874 * Systemtime must be linearized as a set of UINT16's.
875 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
878 SSVAL(p
, 0, st
.year
);
879 SSVAL(p
, 2, st
.month
);
880 SSVAL(p
, 4, st
.day_of_week
);
882 SSVAL(p
, 8, st
.hour
);
883 SSVAL(p
, 10, st
.minute
);
884 SSVAL(p
, 12, st
.second
);
885 SSVAL(p
, 14, st
.millisecond
);
891 /* Convert a notification message to a struct spoolss_Notify */
893 static void notify_one_value(struct spoolss_notify_msg
*msg
,
894 struct spoolss_Notify
*data
,
897 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, msg
->notify
.value
[0]);
900 static void notify_string(struct spoolss_notify_msg
*msg
,
901 struct spoolss_Notify
*data
,
904 /* The length of the message includes the trailing \0 */
906 data
->data
.string
.size
= msg
->len
* 2;
907 data
->data
.string
.string
= talloc_strdup(mem_ctx
, msg
->notify
.data
);
908 if (!data
->data
.string
.string
) {
909 data
->data
.string
.size
= 0;
914 static void notify_system_time(struct spoolss_notify_msg
*msg
,
915 struct spoolss_Notify
*data
,
918 data
->data
.string
.string
= NULL
;
919 data
->data
.string
.size
= 0;
921 if (msg
->len
!= sizeof(time_t)) {
922 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
927 init_systemtime_buffer(mem_ctx
, gmtime((time_t *)msg
->notify
.data
),
928 &data
->data
.string
.string
,
929 &data
->data
.string
.size
);
932 struct notify2_message_table
{
934 void (*fn
)(struct spoolss_notify_msg
*msg
,
935 struct spoolss_Notify
*data
, TALLOC_CTX
*mem_ctx
);
938 static struct notify2_message_table printer_notify_table
[] = {
939 /* 0x00 */ { "PRINTER_NOTIFY_FIELD_SERVER_NAME", notify_string
},
940 /* 0x01 */ { "PRINTER_NOTIFY_FIELD_PRINTER_NAME", notify_string
},
941 /* 0x02 */ { "PRINTER_NOTIFY_FIELD_SHARE_NAME", notify_string
},
942 /* 0x03 */ { "PRINTER_NOTIFY_FIELD_PORT_NAME", notify_string
},
943 /* 0x04 */ { "PRINTER_NOTIFY_FIELD_DRIVER_NAME", notify_string
},
944 /* 0x05 */ { "PRINTER_NOTIFY_FIELD_COMMENT", notify_string
},
945 /* 0x06 */ { "PRINTER_NOTIFY_FIELD_LOCATION", notify_string
},
946 /* 0x07 */ { "PRINTER_NOTIFY_FIELD_DEVMODE", NULL
},
947 /* 0x08 */ { "PRINTER_NOTIFY_FIELD_SEPFILE", notify_string
},
948 /* 0x09 */ { "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", notify_string
},
949 /* 0x0a */ { "PRINTER_NOTIFY_FIELD_PARAMETERS", NULL
},
950 /* 0x0b */ { "PRINTER_NOTIFY_FIELD_DATATYPE", notify_string
},
951 /* 0x0c */ { "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL
},
952 /* 0x0d */ { "PRINTER_NOTIFY_FIELD_ATTRIBUTES", notify_one_value
},
953 /* 0x0e */ { "PRINTER_NOTIFY_FIELD_PRIORITY", notify_one_value
},
954 /* 0x0f */ { "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NULL
},
955 /* 0x10 */ { "PRINTER_NOTIFY_FIELD_START_TIME", NULL
},
956 /* 0x11 */ { "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NULL
},
957 /* 0x12 */ { "PRINTER_NOTIFY_FIELD_STATUS", notify_one_value
},
960 static struct notify2_message_table job_notify_table
[] = {
961 /* 0x00 */ { "JOB_NOTIFY_FIELD_PRINTER_NAME", NULL
},
962 /* 0x01 */ { "JOB_NOTIFY_FIELD_MACHINE_NAME", NULL
},
963 /* 0x02 */ { "JOB_NOTIFY_FIELD_PORT_NAME", NULL
},
964 /* 0x03 */ { "JOB_NOTIFY_FIELD_USER_NAME", notify_string
},
965 /* 0x04 */ { "JOB_NOTIFY_FIELD_NOTIFY_NAME", NULL
},
966 /* 0x05 */ { "JOB_NOTIFY_FIELD_DATATYPE", NULL
},
967 /* 0x06 */ { "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NULL
},
968 /* 0x07 */ { "JOB_NOTIFY_FIELD_PARAMETERS", NULL
},
969 /* 0x08 */ { "JOB_NOTIFY_FIELD_DRIVER_NAME", NULL
},
970 /* 0x09 */ { "JOB_NOTIFY_FIELD_DEVMODE", NULL
},
971 /* 0x0a */ { "JOB_NOTIFY_FIELD_STATUS", notify_one_value
},
972 /* 0x0b */ { "JOB_NOTIFY_FIELD_STATUS_STRING", NULL
},
973 /* 0x0c */ { "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL
},
974 /* 0x0d */ { "JOB_NOTIFY_FIELD_DOCUMENT", notify_string
},
975 /* 0x0e */ { "JOB_NOTIFY_FIELD_PRIORITY", NULL
},
976 /* 0x0f */ { "JOB_NOTIFY_FIELD_POSITION", NULL
},
977 /* 0x10 */ { "JOB_NOTIFY_FIELD_SUBMITTED", notify_system_time
},
978 /* 0x11 */ { "JOB_NOTIFY_FIELD_START_TIME", NULL
},
979 /* 0x12 */ { "JOB_NOTIFY_FIELD_UNTIL_TIME", NULL
},
980 /* 0x13 */ { "JOB_NOTIFY_FIELD_TIME", NULL
},
981 /* 0x14 */ { "JOB_NOTIFY_FIELD_TOTAL_PAGES", notify_one_value
},
982 /* 0x15 */ { "JOB_NOTIFY_FIELD_PAGES_PRINTED", NULL
},
983 /* 0x16 */ { "JOB_NOTIFY_FIELD_TOTAL_BYTES", notify_one_value
},
984 /* 0x17 */ { "JOB_NOTIFY_FIELD_BYTES_PRINTED", NULL
},
988 /***********************************************************************
989 Allocate talloc context for container object
990 **********************************************************************/
992 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR
*ctr
)
997 ctr
->ctx
= talloc_init("notify_msg_ctr_init %p", ctr
);
1002 /***********************************************************************
1003 release all allocated memory and zero out structure
1004 **********************************************************************/
1006 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR
*ctr
)
1012 talloc_destroy(ctr
->ctx
);
1019 /***********************************************************************
1020 **********************************************************************/
1022 static TALLOC_CTX
* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR
*ctr
)
1030 /***********************************************************************
1031 **********************************************************************/
1033 static SPOOLSS_NOTIFY_MSG_GROUP
* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR
*ctr
, uint32_t idx
)
1035 if ( !ctr
|| !ctr
->msg_groups
)
1038 if ( idx
>= ctr
->num_groups
)
1041 return &ctr
->msg_groups
[idx
];
1045 /***********************************************************************
1046 How many groups of change messages do we have ?
1047 **********************************************************************/
1049 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR
*ctr
)
1054 return ctr
->num_groups
;
1057 /***********************************************************************
1058 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
1059 **********************************************************************/
1061 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR
*ctr
, SPOOLSS_NOTIFY_MSG
*msg
)
1063 SPOOLSS_NOTIFY_MSG_GROUP
*groups
= NULL
;
1064 SPOOLSS_NOTIFY_MSG_GROUP
*msg_grp
= NULL
;
1065 SPOOLSS_NOTIFY_MSG
*msg_list
= NULL
;
1071 /* loop over all groups looking for a matching printer name */
1073 for ( i
=0; i
<ctr
->num_groups
; i
++ ) {
1074 if ( strcmp(ctr
->msg_groups
[i
].printername
, msg
->printer
) == 0 )
1078 /* add a new group? */
1080 if ( i
== ctr
->num_groups
) {
1083 if ( !(groups
= talloc_realloc( ctr
->ctx
, ctr
->msg_groups
, SPOOLSS_NOTIFY_MSG_GROUP
, ctr
->num_groups
)) ) {
1084 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
1087 ctr
->msg_groups
= groups
;
1089 /* clear the new entry and set the printer name */
1091 ZERO_STRUCT( ctr
->msg_groups
[ctr
->num_groups
-1] );
1092 fstrcpy( ctr
->msg_groups
[ctr
->num_groups
-1].printername
, msg
->printer
);
1095 /* add the change messages; 'i' is the correct index now regardless */
1097 msg_grp
= &ctr
->msg_groups
[i
];
1099 msg_grp
->num_msgs
++;
1101 if ( !(msg_list
= talloc_realloc( ctr
->ctx
, msg_grp
->msgs
, SPOOLSS_NOTIFY_MSG
, msg_grp
->num_msgs
)) ) {
1102 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp
->num_msgs
));
1105 msg_grp
->msgs
= msg_list
;
1107 new_slot
= msg_grp
->num_msgs
-1;
1108 memcpy( &msg_grp
->msgs
[new_slot
], msg
, sizeof(SPOOLSS_NOTIFY_MSG
) );
1110 /* need to allocate own copy of data */
1112 if ( msg
->len
!= 0 )
1113 msg_grp
->msgs
[new_slot
].notify
.data
= (char *)
1114 talloc_memdup( ctr
->ctx
, msg
->notify
.data
, msg
->len
);
1116 return ctr
->num_groups
;
1119 static void construct_info_data(struct spoolss_Notify
*info_data
,
1120 enum spoolss_NotifyType type
,
1121 uint16_t field
, int id
);
1123 /***********************************************************************
1124 Send a change notication message on all handles which have a call
1126 **********************************************************************/
1128 static int build_notify2_messages(TALLOC_CTX
*mem_ctx
,
1129 struct printer_handle
*prn_hnd
,
1130 SPOOLSS_NOTIFY_MSG
*messages
,
1132 struct spoolss_Notify
**_notifies
,
1135 struct spoolss_Notify
*notifies
;
1136 SPOOLSS_NOTIFY_MSG
*msg
;
1141 notifies
= talloc_zero_array(mem_ctx
,
1142 struct spoolss_Notify
, num_msgs
);
1147 for (i
= 0; i
< num_msgs
; i
++) {
1151 /* Are we monitoring this event? */
1153 if (!is_monitoring_event(prn_hnd
, msg
->type
, msg
->field
)) {
1157 DEBUG(10, ("Sending message type [0x%x] field [0x%2x] "
1158 "for printer [%s]\n",
1159 msg
->type
, msg
->field
, prn_hnd
->sharename
));
1162 * if the is a printer notification handle and not a job
1163 * notification type, then set the id to 0.
1164 * Otherwise just use what was specified in the message.
1166 * When registering change notification on a print server
1167 * handle we always need to send back the id (snum) matching
1168 * the printer for which the change took place.
1169 * For change notify registered on a printer handle,
1170 * this does not matter and the id should be 0.
1175 if ((msg
->type
== PRINTER_NOTIFY_TYPE
) &&
1176 (prn_hnd
->printer_type
== SPLHND_PRINTER
)) {
1182 /* Convert unix jobid to smb jobid */
1184 if (msg
->flags
& SPOOLSS_NOTIFY_MSG_UNIX_JOBID
) {
1185 id
= sysjob_to_jobid(msg
->id
);
1188 DEBUG(3, ("no such unix jobid %d\n",
1194 construct_info_data(¬ifies
[count
],
1195 msg
->type
, msg
->field
, id
);
1198 case PRINTER_NOTIFY_TYPE
:
1199 if (printer_notify_table
[msg
->field
].fn
) {
1200 printer_notify_table
[msg
->field
].fn(msg
,
1201 ¬ifies
[count
], mem_ctx
);
1205 case JOB_NOTIFY_TYPE
:
1206 if (job_notify_table
[msg
->field
].fn
) {
1207 job_notify_table
[msg
->field
].fn(msg
,
1208 ¬ifies
[count
], mem_ctx
);
1213 DEBUG(5, ("Unknown notification type %d\n",
1221 *_notifies
= notifies
;
1227 static int send_notify2_printer(TALLOC_CTX
*mem_ctx
,
1228 struct printer_handle
*prn_hnd
,
1229 SPOOLSS_NOTIFY_MSG_GROUP
*msg_group
)
1231 struct spoolss_Notify
*notifies
;
1233 union spoolss_ReplyPrinterInfo info
;
1234 struct spoolss_NotifyInfo info0
;
1235 uint32_t reply_result
;
1240 /* Is there notification on this handle? */
1241 if (prn_hnd
->notify
.cli_chan
== NULL
||
1242 prn_hnd
->notify
.cli_chan
->cli_pipe
== NULL
||
1243 prn_hnd
->notify
.cli_chan
->cli_pipe
->binding_handle
== NULL
||
1244 prn_hnd
->notify
.cli_chan
->active_connections
== 0) {
1248 DEBUG(10, ("Client connected! [\\\\%s\\%s]\n",
1249 prn_hnd
->servername
, prn_hnd
->sharename
));
1251 /* For this printer? Print servers always receive notifications. */
1252 if ((prn_hnd
->printer_type
== SPLHND_PRINTER
) &&
1253 (!strequal(msg_group
->printername
, prn_hnd
->sharename
))) {
1257 DEBUG(10,("Our printer\n"));
1259 /* build the array of change notifications */
1260 ret
= build_notify2_messages(mem_ctx
, prn_hnd
,
1262 msg_group
->num_msgs
,
1268 info0
.version
= 0x2;
1269 info0
.flags
= count
? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED
;
1270 info0
.count
= count
;
1271 info0
.notifies
= notifies
;
1273 info
.info0
= &info0
;
1275 status
= dcerpc_spoolss_RouterReplyPrinterEx(
1276 prn_hnd
->notify
.cli_chan
->cli_pipe
->binding_handle
,
1278 &prn_hnd
->notify
.cli_hnd
,
1279 prn_hnd
->notify
.change
, /* color */
1280 prn_hnd
->notify
.flags
,
1282 0, /* reply_type, must be 0 */
1284 if (!NT_STATUS_IS_OK(status
)) {
1285 DEBUG(1, ("dcerpc_spoolss_RouterReplyPrinterEx to client: %s "
1287 prn_hnd
->notify
.cli_chan
->cli_pipe
->srv_name_slash
,
1288 nt_errstr(status
)));
1289 werr
= ntstatus_to_werror(status
);
1290 } else if (!W_ERROR_IS_OK(werr
)) {
1291 DEBUG(1, ("RouterReplyPrinterEx to client: %s "
1293 prn_hnd
->notify
.cli_chan
->cli_pipe
->srv_name_slash
,
1296 switch (reply_result
) {
1299 case PRINTER_NOTIFY_INFO_DISCARDED
:
1300 case PRINTER_NOTIFY_INFO_DISCARDNOTED
:
1301 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH
:
1310 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR
*ctr
, uint32_t idx
)
1312 struct printer_handle
*p
;
1313 TALLOC_CTX
*mem_ctx
= notify_ctr_getctx( ctr
);
1314 SPOOLSS_NOTIFY_MSG_GROUP
*msg_group
= notify_ctr_getgroup( ctr
, idx
);
1318 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
1322 if (!msg_group
->msgs
) {
1323 DEBUG(5, ("send_notify2_changes() called with no messages!\n"));
1327 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group
->printername
));
1329 /* loop over all printers */
1331 for (p
= printers_list
; p
; p
= p
->next
) {
1332 ret
= send_notify2_printer(mem_ctx
, p
, msg_group
);
1339 DEBUG(8,("send_notify2_changes: Exit...\n"));
1343 /***********************************************************************
1344 **********************************************************************/
1346 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG
*msg
, struct timeval
*tv
, void *buf
, size_t len
)
1349 uint32_t tv_sec
, tv_usec
;
1352 /* Unpack message */
1354 offset
+= tdb_unpack((uint8_t *)buf
+ offset
, len
- offset
, "f",
1357 offset
+= tdb_unpack((uint8_t *)buf
+ offset
, len
- offset
, "ddddddd",
1359 &msg
->type
, &msg
->field
, &msg
->id
, &msg
->len
, &msg
->flags
);
1362 tdb_unpack((uint8_t *)buf
+ offset
, len
- offset
, "dd",
1363 &msg
->notify
.value
[0], &msg
->notify
.value
[1]);
1365 tdb_unpack((uint8_t *)buf
+ offset
, len
- offset
, "B",
1366 &msg
->len
, &msg
->notify
.data
);
1368 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1369 msg
->printer
, (unsigned int)msg
->id
, msg
->type
, msg
->field
, msg
->flags
));
1371 tv
->tv_sec
= tv_sec
;
1372 tv
->tv_usec
= tv_usec
;
1375 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg
->notify
.value
[0],
1376 msg
->notify
.value
[1]));
1378 dump_data(3, (uint8_t *)msg
->notify
.data
, msg
->len
);
1383 /********************************************************************
1384 Receive a notify2 message list
1385 ********************************************************************/
1387 static void receive_notify2_message_list(struct messaging_context
*msg
,
1390 struct server_id server_id
,
1393 size_t msg_count
, i
;
1394 char *buf
= (char *)data
->data
;
1397 SPOOLSS_NOTIFY_MSG notify
;
1398 SPOOLSS_NOTIFY_MSG_CTR messages
;
1401 if (data
->length
< 4) {
1402 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1406 msg_count
= IVAL(buf
, 0);
1409 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count
));
1411 if (msg_count
== 0) {
1412 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1416 /* initialize the container */
1418 ZERO_STRUCT( messages
);
1419 notify_msg_ctr_init( &messages
);
1422 * build message groups for each printer identified
1423 * in a change_notify msg. Remember that a PCN message
1424 * includes the handle returned for the srv_spoolss_replyopenprinter()
1425 * call. Therefore messages are grouped according to printer handle.
1428 for ( i
=0; i
<msg_count
; i
++ ) {
1429 struct timeval msg_tv
;
1431 if (msg_ptr
+ 4 - buf
> data
->length
) {
1432 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1436 msg_len
= IVAL(msg_ptr
,0);
1439 if (msg_ptr
+ msg_len
- buf
> data
->length
) {
1440 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1444 /* unpack messages */
1446 ZERO_STRUCT( notify
);
1447 notify2_unpack_msg( ¬ify
, &msg_tv
, msg_ptr
, msg_len
);
1450 /* add to correct list in container */
1452 notify_msg_ctr_addmsg( &messages
, ¬ify
);
1454 /* free memory that might have been allocated by notify2_unpack_msg() */
1456 if ( notify
.len
!= 0 )
1457 SAFE_FREE( notify
.notify
.data
);
1460 /* process each group of messages */
1462 num_groups
= notify_msg_ctr_numgroups( &messages
);
1463 for ( i
=0; i
<num_groups
; i
++ )
1464 send_notify2_changes( &messages
, i
);
1469 DEBUG(10,("receive_notify2_message_list: processed %u messages\n",
1470 (uint32_t)msg_count
));
1472 notify_msg_ctr_destroy( &messages
);
1477 /********************************************************************
1478 Send a message to ourself about new driver being installed
1479 so we can upgrade the information for each printer bound to this
1481 ********************************************************************/
1483 static bool srv_spoolss_drv_upgrade_printer(const char *drivername
,
1484 struct messaging_context
*msg_ctx
)
1486 int len
= strlen(drivername
);
1491 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1494 messaging_send_buf(msg_ctx
, messaging_server_id(msg_ctx
),
1495 MSG_PRINTER_DRVUPGRADE
,
1496 (const uint8_t *)drivername
, len
+1);
1501 void srv_spoolss_cleanup(void)
1503 struct printer_session_counter
*session_counter
;
1505 for (session_counter
= counter_list
;
1506 session_counter
!= NULL
;
1507 session_counter
= counter_list
) {
1508 DLIST_REMOVE(counter_list
, session_counter
);
1509 TALLOC_FREE(session_counter
);
1513 /**********************************************************************
1514 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1515 over all printers, upgrading ones as necessary
1516 This is now *ONLY* called inside the background lpq updater. JRA.
1517 **********************************************************************/
1519 void do_drv_upgrade_printer(struct messaging_context
*msg
,
1522 struct server_id server_id
,
1525 TALLOC_CTX
*tmp_ctx
;
1526 const struct auth_session_info
*session_info
= get_session_info_system();
1527 struct spoolss_PrinterInfo2
*pinfo2
;
1529 const char *drivername
;
1531 int n_services
= lp_numservices();
1532 struct dcerpc_binding_handle
*b
= NULL
;
1534 tmp_ctx
= talloc_new(NULL
);
1535 if (!tmp_ctx
) return;
1537 drivername
= talloc_strndup(tmp_ctx
, (const char *)data
->data
, data
->length
);
1539 DEBUG(0, ("do_drv_upgrade_printer: Out of memoery ?!\n"));
1543 DEBUG(10, ("do_drv_upgrade_printer: "
1544 "Got message for new driver [%s]\n", drivername
));
1546 /* Iterate the printer list */
1548 for (snum
= 0; snum
< n_services
; snum
++) {
1549 if (!lp_snum_ok(snum
) || !lp_print_ok(snum
)) {
1553 /* ignore [printers] share */
1554 if (strequal(lp_const_servicename(snum
), "printers")) {
1559 result
= winreg_printer_binding_handle(tmp_ctx
,
1563 if (!W_ERROR_IS_OK(result
)) {
1568 result
= winreg_get_printer(tmp_ctx
, b
,
1569 lp_const_servicename(snum
),
1572 if (!W_ERROR_IS_OK(result
)) {
1576 if (!pinfo2
->drivername
) {
1580 if (strcmp(drivername
, pinfo2
->drivername
) != 0) {
1584 DEBUG(6,("Updating printer [%s]\n", pinfo2
->printername
));
1586 /* all we care about currently is the change_id */
1587 result
= winreg_printer_update_changeid(tmp_ctx
, b
,
1588 pinfo2
->printername
);
1590 if (!W_ERROR_IS_OK(result
)) {
1591 DEBUG(3, ("do_drv_upgrade_printer: "
1592 "Failed to update changeid [%s]\n",
1593 win_errstr(result
)));
1599 talloc_free(tmp_ctx
);
1602 /********************************************************************
1603 Update the cache for all printq's with a registered client
1605 ********************************************************************/
1607 void update_monitored_printq_cache(struct messaging_context
*msg_ctx
)
1609 struct printer_handle
*printer
= printers_list
;
1612 /* loop through all printers and update the cache where
1613 a client is connected */
1615 if ((printer
->printer_type
== SPLHND_PRINTER
) &&
1616 ((printer
->notify
.cli_chan
!= NULL
) &&
1617 (printer
->notify
.cli_chan
->active_connections
> 0))) {
1618 snum
= print_queue_snum(printer
->sharename
);
1619 print_queue_status(msg_ctx
, snum
, NULL
, NULL
);
1622 printer
= printer
->next
;
1628 /****************************************************************
1629 _spoolss_OpenPrinter
1630 ****************************************************************/
1632 WERROR
_spoolss_OpenPrinter(struct pipes_struct
*p
,
1633 struct spoolss_OpenPrinter
*r
)
1635 struct spoolss_OpenPrinterEx e
;
1636 struct spoolss_UserLevel1 level1
;
1639 ZERO_STRUCT(level1
);
1641 e
.in
.printername
= r
->in
.printername
;
1642 e
.in
.datatype
= r
->in
.datatype
;
1643 e
.in
.devmode_ctr
= r
->in
.devmode_ctr
;
1644 e
.in
.access_mask
= r
->in
.access_mask
;
1645 e
.in
.userlevel_ctr
.level
= 1;
1646 e
.in
.userlevel_ctr
.user_info
.level1
= &level1
;
1648 e
.out
.handle
= r
->out
.handle
;
1650 werr
= _spoolss_OpenPrinterEx(p
, &e
);
1652 if (W_ERROR_EQUAL(werr
, WERR_INVALID_PARAM
)) {
1653 /* OpenPrinterEx returns this for a bad
1654 * printer name. We must return WERR_INVALID_PRINTER_NAME
1657 werr
= WERR_INVALID_PRINTER_NAME
;
1663 static WERROR
copy_devicemode(TALLOC_CTX
*mem_ctx
,
1664 struct spoolss_DeviceMode
*orig
,
1665 struct spoolss_DeviceMode
**dest
)
1667 struct spoolss_DeviceMode
*dm
;
1669 dm
= talloc(mem_ctx
, struct spoolss_DeviceMode
);
1674 /* copy all values, then duplicate strings and structs */
1677 dm
->devicename
= talloc_strdup(dm
, orig
->devicename
);
1678 if (!dm
->devicename
) {
1681 dm
->formname
= talloc_strdup(dm
, orig
->formname
);
1682 if (!dm
->formname
) {
1685 if (orig
->driverextra_data
.data
) {
1686 dm
->driverextra_data
.data
=
1687 (uint8_t *) talloc_memdup(dm
, orig
->driverextra_data
.data
,
1688 orig
->driverextra_data
.length
);
1689 if (!dm
->driverextra_data
.data
) {
1698 /****************************************************************
1699 _spoolss_OpenPrinterEx
1700 ****************************************************************/
1702 WERROR
_spoolss_OpenPrinterEx(struct pipes_struct
*p
,
1703 struct spoolss_OpenPrinterEx
*r
)
1708 struct printer_handle
*Printer
=NULL
;
1712 if (!r
->in
.printername
) {
1713 return WERR_INVALID_PARAM
;
1716 if (!*r
->in
.printername
) {
1717 return WERR_INVALID_PARAM
;
1720 if (r
->in
.userlevel_ctr
.level
> 3) {
1721 return WERR_INVALID_PARAM
;
1723 if ((r
->in
.userlevel_ctr
.level
== 1 && !r
->in
.userlevel_ctr
.user_info
.level1
) ||
1724 (r
->in
.userlevel_ctr
.level
== 2 && !r
->in
.userlevel_ctr
.user_info
.level2
) ||
1725 (r
->in
.userlevel_ctr
.level
== 3 && !r
->in
.userlevel_ctr
.user_info
.level3
)) {
1726 return WERR_INVALID_PARAM
;
1730 * The printcap printer share inventory is updated on client
1731 * enumeration. For clients that do not perform enumeration prior to
1732 * access, such as cupssmbadd, we reinitialise the printer share
1733 * inventory on open as well.
1736 delete_and_reload_printers(server_event_context(), p
->msg_ctx
);
1739 /* some sanity check because you can open a printer or a print server */
1740 /* aka: \\server\printer or \\server */
1742 DEBUGADD(3,("checking name: %s\n", r
->in
.printername
));
1744 result
= open_printer_hnd(p
, r
->out
.handle
, r
->in
.printername
, 0);
1745 if (!W_ERROR_IS_OK(result
)) {
1746 DEBUG(3,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
1747 "for printer %s\n", r
->in
.printername
));
1748 ZERO_STRUCTP(r
->out
.handle
);
1752 Printer
= find_printer_index_by_hnd(p
, r
->out
.handle
);
1754 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1755 "handle we created for printer %s\n", r
->in
.printername
));
1756 close_printer_handle(p
, r
->out
.handle
);
1757 ZERO_STRUCTP(r
->out
.handle
);
1758 return WERR_INVALID_PARAM
;
1762 * First case: the user is opening the print server:
1764 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1765 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1767 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1768 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1769 * or if the user is listed in the smb.conf printer admin parameter.
1771 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1772 * client view printer folder, but does not show the MSAPW.
1774 * Note: this test needs code to check access rights here too. Jeremy
1775 * could you look at this?
1777 * Second case: the user is opening a printer:
1778 * NT doesn't let us connect to a printer if the connecting user
1779 * doesn't have print permission.
1781 * Third case: user is opening a Port Monitor
1782 * access checks same as opening a handle to the print server.
1785 switch (Printer
->printer_type
)
1788 case SPLHND_PORTMON_TCP
:
1789 case SPLHND_PORTMON_LOCAL
:
1790 /* Printserver handles use global struct... */
1794 /* Map standard access rights to object specific access rights */
1796 se_map_standard(&r
->in
.access_mask
,
1797 &printserver_std_mapping
);
1799 /* Deny any object specific bits that don't apply to print
1800 servers (i.e printer and job specific bits) */
1802 r
->in
.access_mask
&= SEC_MASK_SPECIFIC
;
1804 if (r
->in
.access_mask
&
1805 ~(SERVER_ACCESS_ADMINISTER
| SERVER_ACCESS_ENUMERATE
)) {
1806 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1807 close_printer_handle(p
, r
->out
.handle
);
1808 ZERO_STRUCTP(r
->out
.handle
);
1809 return WERR_ACCESS_DENIED
;
1812 /* Allow admin access */
1814 if ( r
->in
.access_mask
& SERVER_ACCESS_ADMINISTER
)
1816 if (!lp_ms_add_printer_wizard()) {
1817 close_printer_handle(p
, r
->out
.handle
);
1818 ZERO_STRUCTP(r
->out
.handle
);
1819 return WERR_ACCESS_DENIED
;
1822 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1823 and not a printer admin, then fail */
1825 if ((p
->session_info
->unix_token
->uid
!= sec_initial_uid()) &&
1826 !security_token_has_privilege(p
->session_info
->security_token
, SEC_PRIV_PRINT_OPERATOR
) &&
1827 !nt_token_check_sid(&global_sid_Builtin_Print_Operators
,
1828 p
->session_info
->security_token
)) {
1829 close_printer_handle(p
, r
->out
.handle
);
1830 ZERO_STRUCTP(r
->out
.handle
);
1831 DEBUG(3,("access DENIED as user is not root, "
1832 "has no printoperator privilege, "
1833 "not a member of the printoperator builtin group and "
1834 "is not in printer admin list"));
1835 return WERR_ACCESS_DENIED
;
1838 r
->in
.access_mask
= SERVER_ACCESS_ADMINISTER
;
1842 r
->in
.access_mask
= SERVER_ACCESS_ENUMERATE
;
1845 DEBUG(4,("Setting print server access = %s\n", (r
->in
.access_mask
== SERVER_ACCESS_ADMINISTER
)
1846 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1848 /* We fall through to return WERR_OK */
1851 case SPLHND_PRINTER
:
1852 /* NT doesn't let us connect to a printer if the connecting user
1853 doesn't have print permission. */
1855 if (!get_printer_snum(p
, r
->out
.handle
, &snum
, NULL
)) {
1856 close_printer_handle(p
, r
->out
.handle
);
1857 ZERO_STRUCTP(r
->out
.handle
);
1861 if (r
->in
.access_mask
== SEC_FLAG_MAXIMUM_ALLOWED
) {
1862 r
->in
.access_mask
= PRINTER_ACCESS_ADMINISTER
;
1865 se_map_standard(&r
->in
.access_mask
, &printer_std_mapping
);
1867 /* map an empty access mask to the minimum access mask */
1868 if (r
->in
.access_mask
== 0x0)
1869 r
->in
.access_mask
= PRINTER_ACCESS_USE
;
1872 * If we are not serving the printer driver for this printer,
1873 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1874 * will keep NT clients happy --jerry
1877 if (lp_use_client_driver(snum
)
1878 && (r
->in
.access_mask
& PRINTER_ACCESS_ADMINISTER
))
1880 r
->in
.access_mask
= PRINTER_ACCESS_USE
;
1883 /* check smb.conf parameters and the the sec_desc */
1884 raddr
= tsocket_address_inet_addr_string(p
->remote_address
,
1886 if (raddr
== NULL
) {
1890 rc
= get_remote_hostname(p
->remote_address
,
1896 if (strequal(rhost
, "UNKNOWN")) {
1900 if (!allow_access(lp_hostsdeny(snum
), lp_hostsallow(snum
),
1902 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1903 ZERO_STRUCTP(r
->out
.handle
);
1904 return WERR_ACCESS_DENIED
;
1907 if (!user_ok_token(uidtoname(p
->session_info
->unix_token
->uid
), NULL
,
1908 p
->session_info
->security_token
, snum
) ||
1909 !print_access_check(p
->session_info
,
1912 r
->in
.access_mask
)) {
1913 DEBUG(3, ("access DENIED for printer open\n"));
1914 close_printer_handle(p
, r
->out
.handle
);
1915 ZERO_STRUCTP(r
->out
.handle
);
1916 return WERR_ACCESS_DENIED
;
1919 if ((r
->in
.access_mask
& SEC_MASK_SPECIFIC
)& ~(PRINTER_ACCESS_ADMINISTER
|PRINTER_ACCESS_USE
)) {
1920 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1921 close_printer_handle(p
, r
->out
.handle
);
1922 ZERO_STRUCTP(r
->out
.handle
);
1923 return WERR_ACCESS_DENIED
;
1926 if (r
->in
.access_mask
& PRINTER_ACCESS_ADMINISTER
)
1927 r
->in
.access_mask
= PRINTER_ACCESS_ADMINISTER
;
1929 r
->in
.access_mask
= PRINTER_ACCESS_USE
;
1931 DEBUG(4,("Setting printer access = %s\n", (r
->in
.access_mask
== PRINTER_ACCESS_ADMINISTER
)
1932 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1934 winreg_create_printer_internal(p
->mem_ctx
,
1935 get_session_info_system(),
1937 lp_const_servicename(snum
));
1942 /* sanity check to prevent programmer error */
1943 ZERO_STRUCTP(r
->out
.handle
);
1947 Printer
->access_granted
= r
->in
.access_mask
;
1950 * If the client sent a devmode in the OpenPrinter() call, then
1951 * save it here in case we get a job submission on this handle
1954 if ((Printer
->printer_type
!= SPLHND_SERVER
)
1955 && (r
->in
.devmode_ctr
.devmode
!= NULL
)) {
1956 copy_devicemode(NULL
, r
->in
.devmode_ctr
.devmode
,
1963 /****************************************************************
1964 _spoolss_ClosePrinter
1965 ****************************************************************/
1967 WERROR
_spoolss_ClosePrinter(struct pipes_struct
*p
,
1968 struct spoolss_ClosePrinter
*r
)
1970 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
1972 if (Printer
&& Printer
->document_started
) {
1973 struct spoolss_EndDocPrinter e
;
1975 e
.in
.handle
= r
->in
.handle
;
1977 _spoolss_EndDocPrinter(p
, &e
);
1980 if (!close_printer_handle(p
, r
->in
.handle
))
1983 /* clear the returned printer handle. Observed behavior
1984 from Win2k server. Don't think this really matters.
1985 Previous code just copied the value of the closed
1988 ZERO_STRUCTP(r
->out
.handle
);
1993 /****************************************************************
1994 _spoolss_DeletePrinter
1995 ****************************************************************/
1997 WERROR
_spoolss_DeletePrinter(struct pipes_struct
*p
,
1998 struct spoolss_DeletePrinter
*r
)
2000 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
2004 if (Printer
&& Printer
->document_started
) {
2005 struct spoolss_EndDocPrinter e
;
2007 e
.in
.handle
= r
->in
.handle
;
2009 _spoolss_EndDocPrinter(p
, &e
);
2012 if (get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
2013 winreg_delete_printer_key_internal(p
->mem_ctx
,
2014 get_session_info_system(),
2016 lp_const_servicename(snum
),
2020 result
= delete_printer_handle(p
, r
->in
.handle
);
2025 /*******************************************************************
2026 * static function to lookup the version id corresponding to an
2027 * long architecture string
2028 ******************************************************************/
2030 static const struct print_architecture_table_node archi_table
[]= {
2032 {"Windows 4.0", SPL_ARCH_WIN40
, 0 },
2033 {"Windows NT x86", SPL_ARCH_W32X86
, 2 },
2034 {"Windows NT R4000", SPL_ARCH_W32MIPS
, 2 },
2035 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA
, 2 },
2036 {"Windows NT PowerPC", SPL_ARCH_W32PPC
, 2 },
2037 {"Windows IA64", SPL_ARCH_IA64
, 3 },
2038 {"Windows x64", SPL_ARCH_X64
, 3 },
2042 static const int drv_cversion
[] = {SPOOLSS_DRIVER_VERSION_9X
,
2043 SPOOLSS_DRIVER_VERSION_NT35
,
2044 SPOOLSS_DRIVER_VERSION_NT4
,
2045 SPOOLSS_DRIVER_VERSION_200X
,
2048 static int get_version_id(const char *arch
)
2052 for (i
=0; archi_table
[i
].long_archi
!= NULL
; i
++)
2054 if (strcmp(arch
, archi_table
[i
].long_archi
) == 0)
2055 return (archi_table
[i
].version
);
2061 /****************************************************************
2062 _spoolss_DeletePrinterDriver
2063 ****************************************************************/
2065 WERROR
_spoolss_DeletePrinterDriver(struct pipes_struct
*p
,
2066 struct spoolss_DeletePrinterDriver
*r
)
2069 struct spoolss_DriverInfo8
*info
= NULL
;
2072 struct dcerpc_binding_handle
*b
;
2073 TALLOC_CTX
*tmp_ctx
= NULL
;
2077 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2078 and not a printer admin, then fail */
2080 if ((p
->session_info
->unix_token
->uid
!= sec_initial_uid()) &&
2081 !security_token_has_privilege(p
->session_info
->security_token
,
2082 SEC_PRIV_PRINT_OPERATOR
)) {
2083 return WERR_ACCESS_DENIED
;
2086 /* check that we have a valid driver name first */
2088 if ((version
= get_version_id(r
->in
.architecture
)) == -1) {
2089 return WERR_INVALID_ENVIRONMENT
;
2092 tmp_ctx
= talloc_new(p
->mem_ctx
);
2097 status
= winreg_printer_binding_handle(tmp_ctx
,
2098 get_session_info_system(),
2101 if (!W_ERROR_IS_OK(status
)) {
2105 for (found
= false, i
= 0; drv_cversion
[i
] >= 0; i
++) {
2106 status
= winreg_get_driver(tmp_ctx
, b
,
2107 r
->in
.architecture
, r
->in
.driver
,
2108 drv_cversion
[i
], &info
);
2109 if (!W_ERROR_IS_OK(status
)) {
2110 DEBUG(5, ("skipping del of driver with version %d\n",
2116 if (printer_driver_in_use(tmp_ctx
, b
, info
)) {
2117 status
= WERR_PRINTER_DRIVER_IN_USE
;
2121 status
= winreg_del_driver(tmp_ctx
, b
, info
, drv_cversion
[i
]);
2122 if (!W_ERROR_IS_OK(status
)) {
2123 DEBUG(0, ("failed del of driver with version %d\n",
2128 if (found
== false) {
2129 DEBUG(0, ("driver %s not found for deletion\n", r
->in
.driver
));
2130 status
= WERR_UNKNOWN_PRINTER_DRIVER
;
2136 talloc_free(tmp_ctx
);
2141 static WERROR
spoolss_dpd_version(TALLOC_CTX
*mem_ctx
,
2142 struct pipes_struct
*p
,
2143 struct spoolss_DeletePrinterDriverEx
*r
,
2144 struct dcerpc_binding_handle
*b
,
2145 struct spoolss_DriverInfo8
*info
)
2150 if (printer_driver_in_use(mem_ctx
, b
, info
)) {
2151 status
= WERR_PRINTER_DRIVER_IN_USE
;
2156 * we have a couple of cases to consider.
2157 * (1) Are any files in use? If so and DPD_DELETE_ALL_FILES is set,
2158 * then the delete should fail if **any** files overlap with
2160 * (2) If DPD_DELETE_UNUSED_FILES is set, then delete all
2161 * non-overlapping files
2162 * (3) If neither DPD_DELETE_ALL_FILES nor DPD_DELETE_UNUSED_FILES
2163 * are set, then do not delete any files
2164 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
2167 delete_files
= r
->in
.delete_flags
2168 & (DPD_DELETE_ALL_FILES
| DPD_DELETE_UNUSED_FILES
);
2172 bool in_use
= printer_driver_files_in_use(mem_ctx
, b
, info
);
2173 if (in_use
&& (r
->in
.delete_flags
& DPD_DELETE_ALL_FILES
)) {
2174 status
= WERR_PRINTER_DRIVER_IN_USE
;
2178 * printer_driver_files_in_use() has trimmed overlapping files
2179 * from info so they are not removed on DPD_DELETE_UNUSED_FILES
2184 status
= winreg_del_driver(mem_ctx
, b
, info
, info
->version
);
2185 if (!W_ERROR_IS_OK(status
)) {
2190 * now delete any associated files if delete_files is
2191 * true. Even if this part failes, we return succes
2192 * because the driver doesn not exist any more
2195 delete_driver_files(p
->session_info
, info
);
2202 /****************************************************************
2203 _spoolss_DeletePrinterDriverEx
2204 ****************************************************************/
2206 WERROR
_spoolss_DeletePrinterDriverEx(struct pipes_struct
*p
,
2207 struct spoolss_DeletePrinterDriverEx
*r
)
2209 struct spoolss_DriverInfo8
*info
= NULL
;
2211 struct dcerpc_binding_handle
*b
;
2212 TALLOC_CTX
*tmp_ctx
= NULL
;
2216 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2217 and not a printer admin, then fail */
2219 if ((p
->session_info
->unix_token
->uid
!= sec_initial_uid()) &&
2220 !security_token_has_privilege(p
->session_info
->security_token
,
2221 SEC_PRIV_PRINT_OPERATOR
)) {
2222 return WERR_ACCESS_DENIED
;
2225 /* check that we have a valid driver name first */
2226 if (get_version_id(r
->in
.architecture
) == -1) {
2227 /* this is what NT returns */
2228 return WERR_INVALID_ENVIRONMENT
;
2231 tmp_ctx
= talloc_new(p
->mem_ctx
);
2236 status
= winreg_printer_binding_handle(tmp_ctx
,
2237 get_session_info_system(),
2240 if (!W_ERROR_IS_OK(status
)) {
2244 for (found
= false, i
= 0; drv_cversion
[i
] >= 0; i
++) {
2245 if ((r
->in
.delete_flags
& DPD_DELETE_SPECIFIC_VERSION
)
2246 && (drv_cversion
[i
] != r
->in
.version
)) {
2250 /* check if a driver with this version exists before delete */
2251 status
= winreg_get_driver(tmp_ctx
, b
,
2252 r
->in
.architecture
, r
->in
.driver
,
2253 drv_cversion
[i
], &info
);
2254 if (!W_ERROR_IS_OK(status
)) {
2255 DEBUG(5, ("skipping del of driver with version %d\n",
2261 status
= spoolss_dpd_version(tmp_ctx
, p
, r
, b
, info
);
2262 if (!W_ERROR_IS_OK(status
)) {
2263 DEBUG(0, ("failed to delete driver with version %d\n",
2268 if (found
== false) {
2269 DEBUG(0, ("driver %s not found for deletion\n", r
->in
.driver
));
2270 status
= WERR_UNKNOWN_PRINTER_DRIVER
;
2276 talloc_free(tmp_ctx
);
2281 /********************************************************************
2282 GetPrinterData on a printer server Handle.
2283 ********************************************************************/
2285 static WERROR
getprinterdata_printer_server(TALLOC_CTX
*mem_ctx
,
2287 enum winreg_Type
*type
,
2288 union spoolss_PrinterData
*data
)
2290 DEBUG(8,("getprinterdata_printer_server:%s\n", value
));
2292 if (!strcasecmp_m(value
, "W3SvcInstalled")) {
2294 SIVAL(&data
->value
, 0, 0x00);
2298 if (!strcasecmp_m(value
, "BeepEnabled")) {
2300 SIVAL(&data
->value
, 0, 0x00);
2304 if (!strcasecmp_m(value
, "EventLog")) {
2306 /* formally was 0x1b */
2307 SIVAL(&data
->value
, 0, 0x00);
2311 if (!strcasecmp_m(value
, "NetPopup")) {
2313 SIVAL(&data
->value
, 0, 0x00);
2317 if (!strcasecmp_m(value
, "MajorVersion")) {
2320 /* Windows NT 4.0 seems to not allow uploading of drivers
2321 to a server that reports 0x3 as the MajorVersion.
2322 need to investigate more how Win2k gets around this .
2325 if (RA_WINNT
== get_remote_arch()) {
2326 SIVAL(&data
->value
, 0, 0x02);
2328 SIVAL(&data
->value
, 0, 0x03);
2334 if (!strcasecmp_m(value
, "MinorVersion")) {
2336 SIVAL(&data
->value
, 0, 0x00);
2341 * uint32_t size = 0x114
2342 * uint32_t major = 5
2343 * uint32_t minor = [0|1]
2344 * uint32_t build = [2195|2600]
2345 * extra unicode string = e.g. "Service Pack 3"
2347 if (!strcasecmp_m(value
, "OSVersion")) {
2349 enum ndr_err_code ndr_err
;
2350 struct spoolss_OSVersion os
;
2352 os
.major
= lp_parm_int(GLOBAL_SECTION_SNUM
,
2353 "spoolss", "os_major", 5);
2354 /* Windows 2000 == 5.0 */
2355 os
.minor
= lp_parm_int(GLOBAL_SECTION_SNUM
,
2356 "spoolss", "os_minor", 0);
2357 os
.build
= lp_parm_int(GLOBAL_SECTION_SNUM
,
2358 "spoolss", "os_build", 2195);
2359 os
.extra_string
= ""; /* leave extra string empty */
2361 ndr_err
= ndr_push_struct_blob(&blob
, mem_ctx
, &os
,
2362 (ndr_push_flags_fn_t
)ndr_push_spoolss_OSVersion
);
2363 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2364 return WERR_GENERAL_FAILURE
;
2367 if (DEBUGLEVEL
>= 10) {
2368 NDR_PRINT_DEBUG(spoolss_OSVersion
, &os
);
2372 data
->binary
= blob
;
2378 if (!strcasecmp_m(value
, "DefaultSpoolDirectory")) {
2381 data
->string
= talloc_strdup(mem_ctx
, "C:\\PRINTERS");
2382 W_ERROR_HAVE_NO_MEMORY(data
->string
);
2387 if (!strcasecmp_m(value
, "Architecture")) {
2389 data
->string
= talloc_strdup(mem_ctx
,
2390 lp_parm_const_string(GLOBAL_SECTION_SNUM
, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_NT_X86
));
2391 W_ERROR_HAVE_NO_MEMORY(data
->string
);
2396 if (!strcasecmp_m(value
, "DsPresent")) {
2399 /* only show the publish check box if we are a
2400 member of a AD domain */
2402 if (lp_security() == SEC_ADS
) {
2403 SIVAL(&data
->value
, 0, 0x01);
2405 SIVAL(&data
->value
, 0, 0x00);
2410 if (!strcasecmp_m(value
, "DNSMachineName")) {
2411 const char *hostname
= get_mydnsfullname();
2414 return WERR_BADFILE
;
2418 data
->string
= talloc_strdup(mem_ctx
, hostname
);
2419 W_ERROR_HAVE_NO_MEMORY(data
->string
);
2426 return WERR_INVALID_PARAM
;
2429 /****************************************************************
2430 _spoolss_GetPrinterData
2431 ****************************************************************/
2433 WERROR
_spoolss_GetPrinterData(struct pipes_struct
*p
,
2434 struct spoolss_GetPrinterData
*r
)
2436 struct spoolss_GetPrinterDataEx r2
;
2438 r2
.in
.handle
= r
->in
.handle
;
2439 r2
.in
.key_name
= "PrinterDriverData";
2440 r2
.in
.value_name
= r
->in
.value_name
;
2441 r2
.in
.offered
= r
->in
.offered
;
2442 r2
.out
.type
= r
->out
.type
;
2443 r2
.out
.data
= r
->out
.data
;
2444 r2
.out
.needed
= r
->out
.needed
;
2446 return _spoolss_GetPrinterDataEx(p
, &r2
);
2449 /*********************************************************
2450 Connect to the client machine.
2451 **********************************************************/
2453 static bool spoolss_connect_to_client(struct rpc_pipe_client
**pp_pipe
,
2454 struct sockaddr_storage
*client_ss
, const char *remote_machine
)
2457 struct cli_state
*the_cli
;
2458 struct sockaddr_storage rm_addr
;
2459 char addr
[INET6_ADDRSTRLEN
];
2461 if ( is_zero_addr(client_ss
) ) {
2462 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2464 if ( !resolve_name( remote_machine
, &rm_addr
, 0x20, false) ) {
2465 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine
));
2468 print_sockaddr(addr
, sizeof(addr
), &rm_addr
);
2470 rm_addr
= *client_ss
;
2471 print_sockaddr(addr
, sizeof(addr
), &rm_addr
);
2472 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2476 if (ismyaddr((struct sockaddr
*)(void *)&rm_addr
)) {
2477 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2482 /* setup the connection */
2483 ret
= cli_full_connection( &the_cli
, lp_netbios_name(), remote_machine
,
2484 &rm_addr
, 0, "IPC$", "IPC",
2488 0, lp_client_signing());
2490 if ( !NT_STATUS_IS_OK( ret
) ) {
2491 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2496 if ( smbXcli_conn_protocol(the_cli
->conn
) != PROTOCOL_NT1
) {
2497 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine
));
2498 cli_shutdown(the_cli
);
2503 * Ok - we have an anonymous connection to the IPC$ share.
2504 * Now start the NT Domain stuff :-).
2507 ret
= cli_rpc_pipe_open_noauth(the_cli
, &ndr_table_spoolss
.syntax_id
, pp_pipe
);
2508 if (!NT_STATUS_IS_OK(ret
)) {
2509 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2510 remote_machine
, nt_errstr(ret
)));
2511 cli_shutdown(the_cli
);
2518 /***************************************************************************
2519 Connect to the client.
2520 ****************************************************************************/
2522 static bool srv_spoolss_replyopenprinter(int snum
, const char *printer
,
2523 uint32_t localprinter
,
2524 enum winreg_Type type
,
2525 struct policy_handle
*handle
,
2526 struct notify_back_channel
**_chan
,
2527 struct sockaddr_storage
*client_ss
,
2528 struct messaging_context
*msg_ctx
)
2532 struct notify_back_channel
*chan
;
2534 for (chan
= back_channels
; chan
; chan
= chan
->next
) {
2535 if (memcmp(&chan
->client_address
, client_ss
,
2536 sizeof(struct sockaddr_storage
)) == 0) {
2542 * If it's the first connection, contact the client
2543 * and connect to the IPC$ share anonymously
2546 fstring unix_printer
;
2548 /* the +2 is to strip the leading 2 backslashs */
2549 fstrcpy(unix_printer
, printer
+ 2);
2551 chan
= talloc_zero(NULL
, struct notify_back_channel
);
2555 chan
->client_address
= *client_ss
;
2557 if (!spoolss_connect_to_client(&chan
->cli_pipe
, client_ss
, unix_printer
)) {
2562 DLIST_ADD(back_channels
, chan
);
2564 messaging_register(msg_ctx
, NULL
, MSG_PRINTER_NOTIFY2
,
2565 receive_notify2_message_list
);
2568 if (chan
->cli_pipe
== NULL
||
2569 chan
->cli_pipe
->binding_handle
== NULL
) {
2570 DEBUG(0, ("srv_spoolss_replyopenprinter: error - "
2571 "NULL %s for printer %s\n",
2572 chan
->cli_pipe
== NULL
?
2573 "chan->cli_pipe" : "chan->cli_pipe->binding_handle",
2579 * Tell the specific printing tdb we want messages for this printer
2580 * by registering our PID.
2583 if (!print_notify_register_pid(snum
)) {
2584 DEBUG(0, ("Failed to register our pid for printer %s\n",
2588 status
= dcerpc_spoolss_ReplyOpenPrinter(chan
->cli_pipe
->binding_handle
,
2597 if (!NT_STATUS_IS_OK(status
)) {
2598 DEBUG(5, ("dcerpc_spoolss_ReplyOpenPrinter returned [%s]\n", nt_errstr(status
)));
2599 result
= ntstatus_to_werror(status
);
2600 } else if (!W_ERROR_IS_OK(result
)) {
2601 DEBUG(5, ("ReplyOpenPrinter returned [%s]\n", win_errstr(result
)));
2604 chan
->active_connections
++;
2607 return (W_ERROR_IS_OK(result
));
2610 /****************************************************************
2611 ****************************************************************/
2613 static struct spoolss_NotifyOption
*dup_spoolss_NotifyOption(TALLOC_CTX
*mem_ctx
,
2614 const struct spoolss_NotifyOption
*r
)
2616 struct spoolss_NotifyOption
*option
;
2623 option
= talloc_zero(mem_ctx
, struct spoolss_NotifyOption
);
2630 if (!option
->count
) {
2634 option
->types
= talloc_zero_array(option
,
2635 struct spoolss_NotifyOptionType
, option
->count
);
2636 if (!option
->types
) {
2637 talloc_free(option
);
2641 for (i
=0; i
< option
->count
; i
++) {
2642 option
->types
[i
] = r
->types
[i
];
2644 if (option
->types
[i
].count
) {
2645 option
->types
[i
].fields
= talloc_zero_array(option
,
2646 union spoolss_Field
, option
->types
[i
].count
);
2647 if (!option
->types
[i
].fields
) {
2648 talloc_free(option
);
2651 for (k
=0; k
<option
->types
[i
].count
; k
++) {
2652 option
->types
[i
].fields
[k
] =
2653 r
->types
[i
].fields
[k
];
2661 /****************************************************************
2662 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2664 * before replying OK: status=0 a rpc call is made to the workstation
2665 * asking ReplyOpenPrinter
2667 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2668 * called from api_spoolss_rffpcnex
2669 ****************************************************************/
2671 WERROR
_spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct
*p
,
2672 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx
*r
)
2675 struct spoolss_NotifyOption
*option
= r
->in
.notify_options
;
2676 struct sockaddr_storage client_ss
;
2679 /* store the notify value in the printer struct */
2681 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
2684 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2685 "Invalid handle (%s:%u:%u).\n",
2686 OUR_HANDLE(r
->in
.handle
)));
2690 Printer
->notify
.flags
= r
->in
.flags
;
2691 Printer
->notify
.options
= r
->in
.options
;
2692 Printer
->notify
.printerlocal
= r
->in
.printer_local
;
2693 Printer
->notify
.msg_ctx
= p
->msg_ctx
;
2695 TALLOC_FREE(Printer
->notify
.option
);
2696 Printer
->notify
.option
= dup_spoolss_NotifyOption(Printer
, option
);
2698 fstrcpy(Printer
->notify
.localmachine
, r
->in
.local_machine
);
2700 /* Connect to the client machine and send a ReplyOpenPrinter */
2702 if ( Printer
->printer_type
== SPLHND_SERVER
)
2704 else if ( (Printer
->printer_type
== SPLHND_PRINTER
) &&
2705 !get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
) )
2708 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2709 "remote_address is %s\n",
2710 tsocket_address_string(p
->remote_address
, p
->mem_ctx
)));
2712 if (!lp_print_notify_backchannel(snum
)) {
2713 DEBUG(10, ("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2714 "backchannel disabled\n"));
2715 return WERR_SERVER_UNAVAILABLE
;
2718 client_len
= tsocket_address_bsd_sockaddr(p
->remote_address
,
2719 (struct sockaddr
*) &client_ss
,
2720 sizeof(struct sockaddr_storage
));
2721 if (client_len
< 0) {
2725 if(!srv_spoolss_replyopenprinter(snum
, Printer
->notify
.localmachine
,
2726 Printer
->notify
.printerlocal
, REG_SZ
,
2727 &Printer
->notify
.cli_hnd
,
2728 &Printer
->notify
.cli_chan
,
2729 &client_ss
, p
->msg_ctx
)) {
2730 return WERR_SERVER_UNAVAILABLE
;
2736 /*******************************************************************
2737 * fill a notify_info_data with the servername
2738 ********************************************************************/
2740 static void spoolss_notify_server_name(struct messaging_context
*msg_ctx
,
2742 struct spoolss_Notify
*data
,
2743 print_queue_struct
*queue
,
2744 struct spoolss_PrinterInfo2
*pinfo2
,
2745 TALLOC_CTX
*mem_ctx
)
2747 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->servername
);
2750 /*******************************************************************
2751 * fill a notify_info_data with the printername (not including the servername).
2752 ********************************************************************/
2754 static void spoolss_notify_printer_name(struct messaging_context
*msg_ctx
,
2756 struct spoolss_Notify
*data
,
2757 print_queue_struct
*queue
,
2758 struct spoolss_PrinterInfo2
*pinfo2
,
2759 TALLOC_CTX
*mem_ctx
)
2761 /* the notify name should not contain the \\server\ part */
2762 const char *p
= strrchr(pinfo2
->printername
, '\\');
2765 p
= pinfo2
->printername
;
2770 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, p
);
2773 /*******************************************************************
2774 * fill a notify_info_data with the servicename
2775 ********************************************************************/
2777 static void spoolss_notify_share_name(struct messaging_context
*msg_ctx
,
2779 struct spoolss_Notify
*data
,
2780 print_queue_struct
*queue
,
2781 struct spoolss_PrinterInfo2
*pinfo2
,
2782 TALLOC_CTX
*mem_ctx
)
2784 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, lp_servicename(talloc_tos(), snum
));
2787 /*******************************************************************
2788 * fill a notify_info_data with the port name
2789 ********************************************************************/
2791 static void spoolss_notify_port_name(struct messaging_context
*msg_ctx
,
2793 struct spoolss_Notify
*data
,
2794 print_queue_struct
*queue
,
2795 struct spoolss_PrinterInfo2
*pinfo2
,
2796 TALLOC_CTX
*mem_ctx
)
2798 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->portname
);
2801 /*******************************************************************
2802 * fill a notify_info_data with the printername
2803 * but it doesn't exist, have to see what to do
2804 ********************************************************************/
2806 static void spoolss_notify_driver_name(struct messaging_context
*msg_ctx
,
2808 struct spoolss_Notify
*data
,
2809 print_queue_struct
*queue
,
2810 struct spoolss_PrinterInfo2
*pinfo2
,
2811 TALLOC_CTX
*mem_ctx
)
2813 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->drivername
);
2816 /*******************************************************************
2817 * fill a notify_info_data with the comment
2818 ********************************************************************/
2820 static void spoolss_notify_comment(struct messaging_context
*msg_ctx
,
2822 struct spoolss_Notify
*data
,
2823 print_queue_struct
*queue
,
2824 struct spoolss_PrinterInfo2
*pinfo2
,
2825 TALLOC_CTX
*mem_ctx
)
2829 if (*pinfo2
->comment
== '\0') {
2830 p
= lp_comment(talloc_tos(), snum
);
2832 p
= pinfo2
->comment
;
2835 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, p
);
2838 /*******************************************************************
2839 * fill a notify_info_data with the comment
2840 * location = "Room 1, floor 2, building 3"
2841 ********************************************************************/
2843 static void spoolss_notify_location(struct messaging_context
*msg_ctx
,
2845 struct spoolss_Notify
*data
,
2846 print_queue_struct
*queue
,
2847 struct spoolss_PrinterInfo2
*pinfo2
,
2848 TALLOC_CTX
*mem_ctx
)
2850 const char *loc
= pinfo2
->location
;
2853 status
= printer_list_get_printer(mem_ctx
,
2858 if (NT_STATUS_IS_OK(status
)) {
2860 loc
= pinfo2
->location
;
2864 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, loc
);
2867 /*******************************************************************
2868 * fill a notify_info_data with the device mode
2869 * jfm:xxxx don't to it for know but that's a real problem !!!
2870 ********************************************************************/
2872 static void spoolss_notify_devmode(struct messaging_context
*msg_ctx
,
2874 struct spoolss_Notify
*data
,
2875 print_queue_struct
*queue
,
2876 struct spoolss_PrinterInfo2
*pinfo2
,
2877 TALLOC_CTX
*mem_ctx
)
2879 /* for a dummy implementation we have to zero the fields */
2880 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data
, NULL
);
2883 /*******************************************************************
2884 * fill a notify_info_data with the separator file name
2885 ********************************************************************/
2887 static void spoolss_notify_sepfile(struct messaging_context
*msg_ctx
,
2889 struct spoolss_Notify
*data
,
2890 print_queue_struct
*queue
,
2891 struct spoolss_PrinterInfo2
*pinfo2
,
2892 TALLOC_CTX
*mem_ctx
)
2894 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->sepfile
);
2897 /*******************************************************************
2898 * fill a notify_info_data with the print processor
2899 * jfm:xxxx return always winprint to indicate we don't do anything to it
2900 ********************************************************************/
2902 static void spoolss_notify_print_processor(struct messaging_context
*msg_ctx
,
2904 struct spoolss_Notify
*data
,
2905 print_queue_struct
*queue
,
2906 struct spoolss_PrinterInfo2
*pinfo2
,
2907 TALLOC_CTX
*mem_ctx
)
2909 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->printprocessor
);
2912 /*******************************************************************
2913 * fill a notify_info_data with the print processor options
2914 * jfm:xxxx send an empty string
2915 ********************************************************************/
2917 static void spoolss_notify_parameters(struct messaging_context
*msg_ctx
,
2919 struct spoolss_Notify
*data
,
2920 print_queue_struct
*queue
,
2921 struct spoolss_PrinterInfo2
*pinfo2
,
2922 TALLOC_CTX
*mem_ctx
)
2924 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->parameters
);
2927 /*******************************************************************
2928 * fill a notify_info_data with the data type
2929 * jfm:xxxx always send RAW as data type
2930 ********************************************************************/
2932 static void spoolss_notify_datatype(struct messaging_context
*msg_ctx
,
2934 struct spoolss_Notify
*data
,
2935 print_queue_struct
*queue
,
2936 struct spoolss_PrinterInfo2
*pinfo2
,
2937 TALLOC_CTX
*mem_ctx
)
2939 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->datatype
);
2942 /*******************************************************************
2943 * fill a notify_info_data with the security descriptor
2944 * jfm:xxxx send an null pointer to say no security desc
2945 * have to implement security before !
2946 ********************************************************************/
2948 static void spoolss_notify_security_desc(struct messaging_context
*msg_ctx
,
2950 struct spoolss_Notify
*data
,
2951 print_queue_struct
*queue
,
2952 struct spoolss_PrinterInfo2
*pinfo2
,
2953 TALLOC_CTX
*mem_ctx
)
2955 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data
, pinfo2
->secdesc
);
2958 /*******************************************************************
2959 * fill a notify_info_data with the attributes
2960 * jfm:xxxx a samba printer is always shared
2961 ********************************************************************/
2963 static void spoolss_notify_attributes(struct messaging_context
*msg_ctx
,
2965 struct spoolss_Notify
*data
,
2966 print_queue_struct
*queue
,
2967 struct spoolss_PrinterInfo2
*pinfo2
,
2968 TALLOC_CTX
*mem_ctx
)
2970 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->attributes
);
2973 /*******************************************************************
2974 * fill a notify_info_data with the priority
2975 ********************************************************************/
2977 static void spoolss_notify_priority(struct messaging_context
*msg_ctx
,
2979 struct spoolss_Notify
*data
,
2980 print_queue_struct
*queue
,
2981 struct spoolss_PrinterInfo2
*pinfo2
,
2982 TALLOC_CTX
*mem_ctx
)
2984 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->priority
);
2987 /*******************************************************************
2988 * fill a notify_info_data with the default priority
2989 ********************************************************************/
2991 static void spoolss_notify_default_priority(struct messaging_context
*msg_ctx
,
2993 struct spoolss_Notify
*data
,
2994 print_queue_struct
*queue
,
2995 struct spoolss_PrinterInfo2
*pinfo2
,
2996 TALLOC_CTX
*mem_ctx
)
2998 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->defaultpriority
);
3001 /*******************************************************************
3002 * fill a notify_info_data with the start time
3003 ********************************************************************/
3005 static void spoolss_notify_start_time(struct messaging_context
*msg_ctx
,
3007 struct spoolss_Notify
*data
,
3008 print_queue_struct
*queue
,
3009 struct spoolss_PrinterInfo2
*pinfo2
,
3010 TALLOC_CTX
*mem_ctx
)
3012 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->starttime
);
3015 /*******************************************************************
3016 * fill a notify_info_data with the until time
3017 ********************************************************************/
3019 static void spoolss_notify_until_time(struct messaging_context
*msg_ctx
,
3021 struct spoolss_Notify
*data
,
3022 print_queue_struct
*queue
,
3023 struct spoolss_PrinterInfo2
*pinfo2
,
3024 TALLOC_CTX
*mem_ctx
)
3026 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->untiltime
);
3029 /*******************************************************************
3030 * fill a notify_info_data with the status
3031 ********************************************************************/
3033 static void spoolss_notify_status(struct messaging_context
*msg_ctx
,
3035 struct spoolss_Notify
*data
,
3036 print_queue_struct
*queue
,
3037 struct spoolss_PrinterInfo2
*pinfo2
,
3038 TALLOC_CTX
*mem_ctx
)
3040 print_status_struct status
;
3042 print_queue_length(msg_ctx
, snum
, &status
);
3043 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, status
.status
);
3046 /*******************************************************************
3047 * fill a notify_info_data with the number of jobs queued
3048 ********************************************************************/
3050 static void spoolss_notify_cjobs(struct messaging_context
*msg_ctx
,
3052 struct spoolss_Notify
*data
,
3053 print_queue_struct
*queue
,
3054 struct spoolss_PrinterInfo2
*pinfo2
,
3055 TALLOC_CTX
*mem_ctx
)
3057 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(
3058 data
, print_queue_length(msg_ctx
, snum
, NULL
));
3061 /*******************************************************************
3062 * fill a notify_info_data with the average ppm
3063 ********************************************************************/
3065 static void spoolss_notify_average_ppm(struct messaging_context
*msg_ctx
,
3067 struct spoolss_Notify
*data
,
3068 print_queue_struct
*queue
,
3069 struct spoolss_PrinterInfo2
*pinfo2
,
3070 TALLOC_CTX
*mem_ctx
)
3072 /* always respond 8 pages per minutes */
3073 /* a little hard ! */
3074 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->averageppm
);
3077 /*******************************************************************
3078 * fill a notify_info_data with username
3079 ********************************************************************/
3081 static void spoolss_notify_username(struct messaging_context
*msg_ctx
,
3083 struct spoolss_Notify
*data
,
3084 print_queue_struct
*queue
,
3085 struct spoolss_PrinterInfo2
*pinfo2
,
3086 TALLOC_CTX
*mem_ctx
)
3088 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, queue
->fs_user
);
3091 /*******************************************************************
3092 * fill a notify_info_data with job status
3093 ********************************************************************/
3095 static void spoolss_notify_job_status(struct messaging_context
*msg_ctx
,
3097 struct spoolss_Notify
*data
,
3098 print_queue_struct
*queue
,
3099 struct spoolss_PrinterInfo2
*pinfo2
,
3100 TALLOC_CTX
*mem_ctx
)
3102 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, nt_printj_status(queue
->status
));
3105 /*******************************************************************
3106 * fill a notify_info_data with job name
3107 ********************************************************************/
3109 static void spoolss_notify_job_name(struct messaging_context
*msg_ctx
,
3111 struct spoolss_Notify
*data
,
3112 print_queue_struct
*queue
,
3113 struct spoolss_PrinterInfo2
*pinfo2
,
3114 TALLOC_CTX
*mem_ctx
)
3116 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, queue
->fs_file
);
3119 /*******************************************************************
3120 * fill a notify_info_data with job status
3121 ********************************************************************/
3123 static void spoolss_notify_job_status_string(struct messaging_context
*msg_ctx
,
3125 struct spoolss_Notify
*data
,
3126 print_queue_struct
*queue
,
3127 struct spoolss_PrinterInfo2
*pinfo2
,
3128 TALLOC_CTX
*mem_ctx
)
3131 * Now we're returning job status codes we just return a "" here. JRA.
3136 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
3139 switch (queue
->status
) {
3144 p
= ""; /* NT provides the paused string */
3153 #endif /* NO LONGER NEEDED. */
3155 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, p
);
3158 /*******************************************************************
3159 * fill a notify_info_data with job time
3160 ********************************************************************/
3162 static void spoolss_notify_job_time(struct messaging_context
*msg_ctx
,
3164 struct spoolss_Notify
*data
,
3165 print_queue_struct
*queue
,
3166 struct spoolss_PrinterInfo2
*pinfo2
,
3167 TALLOC_CTX
*mem_ctx
)
3169 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, 0);
3172 /*******************************************************************
3173 * fill a notify_info_data with job size
3174 ********************************************************************/
3176 static void spoolss_notify_job_size(struct messaging_context
*msg_ctx
,
3178 struct spoolss_Notify
*data
,
3179 print_queue_struct
*queue
,
3180 struct spoolss_PrinterInfo2
*pinfo2
,
3181 TALLOC_CTX
*mem_ctx
)
3183 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, queue
->size
);
3186 /*******************************************************************
3187 * fill a notify_info_data with page info
3188 ********************************************************************/
3189 static void spoolss_notify_total_pages(struct messaging_context
*msg_ctx
,
3191 struct spoolss_Notify
*data
,
3192 print_queue_struct
*queue
,
3193 struct spoolss_PrinterInfo2
*pinfo2
,
3194 TALLOC_CTX
*mem_ctx
)
3196 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, queue
->page_count
);
3199 /*******************************************************************
3200 * fill a notify_info_data with pages printed info.
3201 ********************************************************************/
3202 static void spoolss_notify_pages_printed(struct messaging_context
*msg_ctx
,
3204 struct spoolss_Notify
*data
,
3205 print_queue_struct
*queue
,
3206 struct spoolss_PrinterInfo2
*pinfo2
,
3207 TALLOC_CTX
*mem_ctx
)
3209 /* Add code when back-end tracks this */
3210 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, 0);
3213 /*******************************************************************
3214 Fill a notify_info_data with job position.
3215 ********************************************************************/
3217 static void spoolss_notify_job_position(struct messaging_context
*msg_ctx
,
3219 struct spoolss_Notify
*data
,
3220 print_queue_struct
*queue
,
3221 struct spoolss_PrinterInfo2
*pinfo2
,
3222 TALLOC_CTX
*mem_ctx
)
3224 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, queue
->sysjob
);
3227 /*******************************************************************
3228 Fill a notify_info_data with submitted time.
3229 ********************************************************************/
3231 static void spoolss_notify_submitted_time(struct messaging_context
*msg_ctx
,
3233 struct spoolss_Notify
*data
,
3234 print_queue_struct
*queue
,
3235 struct spoolss_PrinterInfo2
*pinfo2
,
3236 TALLOC_CTX
*mem_ctx
)
3238 data
->data
.string
.string
= NULL
;
3239 data
->data
.string
.size
= 0;
3241 init_systemtime_buffer(mem_ctx
, gmtime(&queue
->time
),
3242 &data
->data
.string
.string
,
3243 &data
->data
.string
.size
);
3247 struct s_notify_info_data_table
3249 enum spoolss_NotifyType type
;
3252 enum spoolss_NotifyTable variable_type
;
3253 void (*fn
) (struct messaging_context
*msg_ctx
,
3254 int snum
, struct spoolss_Notify
*data
,
3255 print_queue_struct
*queue
,
3256 struct spoolss_PrinterInfo2
*pinfo2
,
3257 TALLOC_CTX
*mem_ctx
);
3260 /* A table describing the various print notification constants and
3261 whether the notification data is a pointer to a variable sized
3262 buffer, a one value uint32_t or a two value uint32_t. */
3264 static const struct s_notify_info_data_table notify_info_data_table
[] =
3266 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_SERVER_NAME
, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_server_name
},
3267 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PRINTER_NAME
, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_printer_name
},
3268 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_SHARE_NAME
, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_share_name
},
3269 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PORT_NAME
, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_port_name
},
3270 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_DRIVER_NAME
, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_driver_name
},
3271 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_COMMENT
, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING
, spoolss_notify_comment
},
3272 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_LOCATION
, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING
, spoolss_notify_location
},
3273 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_DEVMODE
, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE
, spoolss_notify_devmode
},
3274 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_SEPFILE
, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING
, spoolss_notify_sepfile
},
3275 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR
, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING
, spoolss_notify_print_processor
},
3276 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PARAMETERS
, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING
, spoolss_notify_parameters
},
3277 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_DATATYPE
, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING
, spoolss_notify_datatype
},
3278 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR
, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR
, spoolss_notify_security_desc
},
3279 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_ATTRIBUTES
, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD
, spoolss_notify_attributes
},
3280 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PRIORITY
, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD
, spoolss_notify_priority
},
3281 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY
, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD
, spoolss_notify_default_priority
},
3282 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_START_TIME
, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_start_time
},
3283 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_UNTIL_TIME
, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_until_time
},
3284 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_STATUS
, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD
, spoolss_notify_status
},
3285 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_STATUS_STRING
, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING
, NULL
},
3286 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_CJOBS
, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD
, spoolss_notify_cjobs
},
3287 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_AVERAGE_PPM
, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD
, spoolss_notify_average_ppm
},
3288 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_TOTAL_PAGES
, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD
, NULL
},
3289 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PAGES_PRINTED
, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD
, NULL
},
3290 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_TOTAL_BYTES
, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD
, NULL
},
3291 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_BYTES_PRINTED
, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD
, NULL
},
3292 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PRINTER_NAME
, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_printer_name
},
3293 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_MACHINE_NAME
, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_server_name
},
3294 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PORT_NAME
, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_port_name
},
3295 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_USER_NAME
, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_username
},
3296 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_NOTIFY_NAME
, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_username
},
3297 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_DATATYPE
, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING
, spoolss_notify_datatype
},
3298 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PRINT_PROCESSOR
, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING
, spoolss_notify_print_processor
},
3299 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PARAMETERS
, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING
, spoolss_notify_parameters
},
3300 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_DRIVER_NAME
, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_driver_name
},
3301 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_DEVMODE
, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE
, spoolss_notify_devmode
},
3302 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_STATUS
, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD
, spoolss_notify_job_status
},
3303 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_STATUS_STRING
, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING
, spoolss_notify_job_status_string
},
3304 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR
, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR
, NULL
},
3305 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_DOCUMENT
, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING
, spoolss_notify_job_name
},
3306 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PRIORITY
, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD
, spoolss_notify_priority
},
3307 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_POSITION
, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD
, spoolss_notify_job_position
},
3308 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_SUBMITTED
, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME
, spoolss_notify_submitted_time
},
3309 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_START_TIME
, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_start_time
},
3310 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_UNTIL_TIME
, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_until_time
},
3311 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_TIME
, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_job_time
},
3312 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_TOTAL_PAGES
, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD
, spoolss_notify_total_pages
},
3313 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PAGES_PRINTED
, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD
, spoolss_notify_pages_printed
},
3314 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_TOTAL_BYTES
, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD
, spoolss_notify_job_size
},
3317 /*******************************************************************
3318 Return the variable_type of info_data structure.
3319 ********************************************************************/
3321 static enum spoolss_NotifyTable
variable_type_of_notify_info_data(enum spoolss_NotifyType type
,
3326 for (i
= 0; i
< ARRAY_SIZE(notify_info_data_table
); i
++) {
3327 if ( (notify_info_data_table
[i
].type
== type
) &&
3328 (notify_info_data_table
[i
].field
== field
) ) {
3329 return notify_info_data_table
[i
].variable_type
;
3333 DEBUG(5, ("invalid notify data type %d/%d\n", type
, field
));
3335 return (enum spoolss_NotifyTable
) 0;
3338 /****************************************************************************
3339 ****************************************************************************/
3341 static bool search_notify(enum spoolss_NotifyType type
,
3347 for (i
= 0; i
< ARRAY_SIZE(notify_info_data_table
); i
++) {
3348 if (notify_info_data_table
[i
].type
== type
&&
3349 notify_info_data_table
[i
].field
== field
&&
3350 notify_info_data_table
[i
].fn
!= NULL
) {
3359 /****************************************************************************
3360 ****************************************************************************/
3362 static void construct_info_data(struct spoolss_Notify
*info_data
,
3363 enum spoolss_NotifyType type
,
3364 uint16_t field
, int id
)
3366 info_data
->type
= type
;
3367 info_data
->field
.field
= field
;
3368 info_data
->variable_type
= variable_type_of_notify_info_data(type
, field
);
3369 info_data
->job_id
= id
;
3372 /*******************************************************************
3374 * fill a notify_info struct with info asked
3376 ********************************************************************/
3378 static bool construct_notify_printer_info(struct messaging_context
*msg_ctx
,
3379 struct printer_handle
*print_hnd
,
3380 struct spoolss_NotifyInfo
*info
,
3381 struct spoolss_PrinterInfo2
*pinfo2
,
3383 const struct spoolss_NotifyOptionType
*option_type
,
3385 TALLOC_CTX
*mem_ctx
)
3388 enum spoolss_NotifyType type
;
3391 struct spoolss_Notify
*current_data
;
3393 type
= option_type
->type
;
3395 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3396 (type
== PRINTER_NOTIFY_TYPE
? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3397 option_type
->count
, lp_servicename(talloc_tos(), snum
)));
3399 for(field_num
=0; field_num
< option_type
->count
; field_num
++) {
3400 field
= option_type
->fields
[field_num
].field
;
3402 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num
, type
, field
));
3404 if (!search_notify(type
, field
, &j
) )
3407 info
->notifies
= talloc_realloc(info
, info
->notifies
,
3408 struct spoolss_Notify
,
3410 if (info
->notifies
== NULL
) {
3411 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3415 current_data
= &info
->notifies
[info
->count
];
3417 construct_info_data(current_data
, type
, field
, id
);
3419 DEBUG(10, ("construct_notify_printer_info: "
3420 "calling [%s] snum=%d printername=[%s])\n",
3421 notify_info_data_table
[j
].name
, snum
,
3422 pinfo2
->printername
));
3424 notify_info_data_table
[j
].fn(msg_ctx
, snum
, current_data
,
3425 NULL
, pinfo2
, mem_ctx
);
3433 /*******************************************************************
3435 * fill a notify_info struct with info asked
3437 ********************************************************************/
3439 static bool construct_notify_jobs_info(struct messaging_context
*msg_ctx
,
3440 print_queue_struct
*queue
,
3441 struct spoolss_NotifyInfo
*info
,
3442 struct spoolss_PrinterInfo2
*pinfo2
,
3444 const struct spoolss_NotifyOptionType
*option_type
,
3446 TALLOC_CTX
*mem_ctx
)
3449 enum spoolss_NotifyType type
;
3451 struct spoolss_Notify
*current_data
;
3453 DEBUG(4,("construct_notify_jobs_info\n"));
3455 type
= option_type
->type
;
3457 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3458 (type
== PRINTER_NOTIFY_TYPE
? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3459 option_type
->count
));
3461 for(field_num
=0; field_num
<option_type
->count
; field_num
++) {
3462 field
= option_type
->fields
[field_num
].field
;
3464 if (!search_notify(type
, field
, &j
) )
3467 info
->notifies
= talloc_realloc(info
, info
->notifies
,
3468 struct spoolss_Notify
,
3470 if (info
->notifies
== NULL
) {
3471 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3475 current_data
=&(info
->notifies
[info
->count
]);
3477 construct_info_data(current_data
, type
, field
, id
);
3478 notify_info_data_table
[j
].fn(msg_ctx
, snum
, current_data
,
3479 queue
, pinfo2
, mem_ctx
);
3487 * JFM: The enumeration is not that simple, it's even non obvious.
3489 * let's take an example: I want to monitor the PRINTER SERVER for
3490 * the printer's name and the number of jobs currently queued.
3491 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3492 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3494 * I have 3 printers on the back of my server.
3496 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3499 * 1 printer 1 name 1
3500 * 2 printer 1 cjob 1
3501 * 3 printer 2 name 2
3502 * 4 printer 2 cjob 2
3503 * 5 printer 3 name 3
3504 * 6 printer 3 name 3
3506 * that's the print server case, the printer case is even worse.
3509 /*******************************************************************
3511 * enumerate all printers on the printserver
3512 * fill a notify_info struct with info asked
3514 ********************************************************************/
3516 static WERROR
printserver_notify_info(struct pipes_struct
*p
,
3517 struct policy_handle
*hnd
,
3518 struct spoolss_NotifyInfo
*info
,
3519 TALLOC_CTX
*mem_ctx
)
3522 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, hnd
);
3523 int n_services
=lp_numservices();
3525 struct spoolss_NotifyOption
*option
;
3526 struct spoolss_NotifyOptionType option_type
;
3527 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
3530 DEBUG(4,("printserver_notify_info\n"));
3535 option
= Printer
->notify
.option
;
3538 info
->notifies
= NULL
;
3541 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3542 sending a ffpcn() request first */
3547 for (i
=0; i
<option
->count
; i
++) {
3548 option_type
= option
->types
[i
];
3550 if (option_type
.type
!= PRINTER_NOTIFY_TYPE
)
3553 for (snum
= 0; snum
< n_services
; snum
++) {
3554 if (!lp_browseable(snum
) ||
3555 !lp_snum_ok(snum
) ||
3556 !lp_print_ok(snum
)) {
3557 continue; /* skip */
3560 /* Maybe we should use the SYSTEM session_info here... */
3561 result
= winreg_get_printer_internal(mem_ctx
,
3562 get_session_info_system(),
3564 lp_servicename(talloc_tos(), snum
),
3566 if (!W_ERROR_IS_OK(result
)) {
3567 DEBUG(4, ("printserver_notify_info: "
3568 "Failed to get printer [%s]\n",
3569 lp_servicename(talloc_tos(), snum
)));
3574 construct_notify_printer_info(p
->msg_ctx
,
3580 TALLOC_FREE(pinfo2
);
3586 * Debugging information, don't delete.
3589 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3590 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info
->version
, info
->flags
, info
->count
));
3591 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3593 for (i
=0; i
<info
->count
; i
++) {
3594 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3595 i
, info
->data
[i
].type
, info
->data
[i
].field
, info
->data
[i
].reserved
,
3596 info
->data
[i
].id
, info
->data
[i
].size
, info
->data
[i
].enc_type
));
3603 /*******************************************************************
3605 * fill a notify_info struct with info asked
3607 ********************************************************************/
3609 static WERROR
printer_notify_info(struct pipes_struct
*p
,
3610 struct policy_handle
*hnd
,
3611 struct spoolss_NotifyInfo
*info
,
3612 TALLOC_CTX
*mem_ctx
)
3615 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, hnd
);
3618 struct spoolss_NotifyOption
*option
;
3619 struct spoolss_NotifyOptionType option_type
;
3621 print_queue_struct
*queue
=NULL
;
3622 print_status_struct status
;
3623 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
3625 struct tdb_print_db
*pdb
;
3627 DEBUG(4,("printer_notify_info\n"));
3632 option
= Printer
->notify
.option
;
3636 info
->notifies
= NULL
;
3639 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3640 sending a ffpcn() request first */
3645 if (!get_printer_snum(p
, hnd
, &snum
, NULL
)) {
3649 pdb
= get_print_db_byname(Printer
->sharename
);
3654 /* Maybe we should use the SYSTEM session_info here... */
3655 result
= winreg_get_printer_internal(mem_ctx
,
3656 get_session_info_system(),
3658 lp_servicename(talloc_tos(), snum
), &pinfo2
);
3659 if (!W_ERROR_IS_OK(result
)) {
3660 result
= WERR_BADFID
;
3665 * When sending a PRINTER_NOTIFY_FIELD_SERVER_NAME we should send the
3666 * correct servername.
3668 pinfo2
->servername
= talloc_strdup(pinfo2
, Printer
->servername
);
3669 if (pinfo2
->servername
== NULL
) {
3670 result
= WERR_NOMEM
;
3674 for (i
= 0; i
< option
->count
; i
++) {
3675 option_type
= option
->types
[i
];
3677 switch (option_type
.type
) {
3678 case PRINTER_NOTIFY_TYPE
:
3679 if (construct_notify_printer_info(p
->msg_ctx
,
3688 case JOB_NOTIFY_TYPE
:
3690 count
= print_queue_status(p
->msg_ctx
, snum
, &queue
,
3693 for (j
= 0; j
< count
; j
++) {
3695 jobid
= sysjob_to_jobid_pdb(pdb
,
3697 if (jobid
== (uint32_t)-1) {
3698 DEBUG(2, ("ignoring untracked job %d\n",
3702 /* FIXME check return value */
3703 construct_notify_jobs_info(p
->msg_ctx
,
3717 * Debugging information, don't delete.
3720 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3721 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3722 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3724 for (i=0; i<info->count; i++) {
3725 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3726 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3727 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3731 talloc_free(pinfo2
);
3734 release_print_db(pdb
);
3738 /****************************************************************
3739 _spoolss_RouterRefreshPrinterChangeNotify
3740 ****************************************************************/
3742 WERROR
_spoolss_RouterRefreshPrinterChangeNotify(struct pipes_struct
*p
,
3743 struct spoolss_RouterRefreshPrinterChangeNotify
*r
)
3745 struct spoolss_NotifyInfo
*info
;
3747 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
3748 WERROR result
= WERR_BADFID
;
3750 /* we always have a spoolss_NotifyInfo struct */
3751 info
= talloc_zero(p
->mem_ctx
, struct spoolss_NotifyInfo
);
3753 result
= WERR_NOMEM
;
3757 *r
->out
.info
= info
;
3760 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3761 "Invalid handle (%s:%u:%u).\n",
3762 OUR_HANDLE(r
->in
.handle
)));
3766 DEBUG(4,("Printer type %x\n",Printer
->printer_type
));
3769 * We are now using the change value, and
3770 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3771 * I don't have a global notification system, I'm sending back all the
3772 * information even when _NOTHING_ has changed.
3775 /* We need to keep track of the change value to send back in
3776 RRPCN replies otherwise our updates are ignored. */
3778 Printer
->notify
.fnpcn
= true;
3780 if (Printer
->notify
.cli_chan
!= NULL
&&
3781 Printer
->notify
.cli_chan
->active_connections
> 0) {
3782 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3783 "Saving change value in request [%x]\n",
3785 Printer
->notify
.change
= r
->in
.change_low
;
3788 /* just ignore the spoolss_NotifyOption */
3790 switch (Printer
->printer_type
) {
3792 result
= printserver_notify_info(p
, r
->in
.handle
,
3796 case SPLHND_PRINTER
:
3797 result
= printer_notify_info(p
, r
->in
.handle
,
3802 Printer
->notify
.fnpcn
= false;
3808 /********************************************************************
3809 ********************************************************************/
3811 static WERROR
create_printername(TALLOC_CTX
*mem_ctx
,
3812 const char *servername
,
3813 const char *printername
,
3814 const char **printername_p
)
3816 /* FIXME: add lp_force_printername() */
3818 if (servername
== NULL
) {
3819 *printername_p
= talloc_strdup(mem_ctx
, printername
);
3820 W_ERROR_HAVE_NO_MEMORY(*printername_p
);
3824 if (servername
[0] == '\\' && servername
[1] == '\\') {
3828 *printername_p
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s", servername
, printername
);
3829 W_ERROR_HAVE_NO_MEMORY(*printername_p
);
3834 /********************************************************************
3835 ********************************************************************/
3837 static void compose_devicemode_devicename(struct spoolss_DeviceMode
*dm
,
3838 const char *printername
)
3844 dm
->devicename
= talloc_strndup(dm
, printername
,
3845 MIN(strlen(printername
), 31));
3848 /********************************************************************
3849 * construct_printer_info_0
3850 * fill a printer_info_0 struct
3851 ********************************************************************/
3853 static WERROR
construct_printer_info0(TALLOC_CTX
*mem_ctx
,
3854 const struct auth_session_info
*session_info
,
3855 struct messaging_context
*msg_ctx
,
3856 struct spoolss_PrinterInfo2
*info2
,
3857 const char *servername
,
3858 struct spoolss_PrinterInfo0
*r
,
3862 struct printer_session_counter
*session_counter
;
3863 struct timeval setuptime
;
3864 print_status_struct status
;
3867 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->printername
);
3868 if (!W_ERROR_IS_OK(result
)) {
3873 r
->servername
= talloc_strdup(mem_ctx
, servername
);
3874 W_ERROR_HAVE_NO_MEMORY(r
->servername
);
3876 r
->servername
= NULL
;
3879 count
= print_queue_length(msg_ctx
, snum
, &status
);
3881 /* check if we already have a counter for this printer */
3882 for (session_counter
= counter_list
; session_counter
; session_counter
= session_counter
->next
) {
3883 if (session_counter
->snum
== snum
)
3887 /* it's the first time, add it to the list */
3888 if (session_counter
== NULL
) {
3889 session_counter
= talloc_zero(counter_list
, struct printer_session_counter
);
3890 W_ERROR_HAVE_NO_MEMORY(session_counter
);
3891 session_counter
->snum
= snum
;
3892 session_counter
->counter
= 0;
3893 DLIST_ADD(counter_list
, session_counter
);
3897 session_counter
->counter
++;
3903 get_startup_time(&setuptime
);
3904 init_systemtime(&r
->time
, gmtime(&setuptime
.tv_sec
));
3907 * the global_counter should be stored in a TDB as it's common to all the clients
3908 * and should be zeroed on samba startup
3910 r
->global_counter
= session_counter
->counter
;
3912 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3913 SSVAL(&r
->version
, 0, 0x0005); /* NT 5 */
3914 SSVAL(&r
->version
, 2, 0x0893); /* build 2195 */
3915 r
->free_build
= SPOOLSS_RELEASE_BUILD
;
3917 r
->max_spooling
= 0;
3918 r
->session_counter
= session_counter
->counter
;
3919 r
->num_error_out_of_paper
= 0x0;
3920 r
->num_error_not_ready
= 0x0; /* number of print failure */
3922 r
->number_of_processors
= 0x1;
3923 r
->processor_type
= PROCESSOR_INTEL_PENTIUM
; /* 586 Pentium ? */
3924 r
->high_part_total_bytes
= 0x0;
3926 /* ChangeID in milliseconds*/
3927 winreg_printer_get_changeid_internal(mem_ctx
, session_info
, msg_ctx
,
3928 info2
->sharename
, &r
->change_id
);
3930 r
->last_error
= WERR_OK
;
3931 r
->status
= nt_printq_status(status
.status
);
3932 r
->enumerate_network_printers
= 0x0;
3933 r
->c_setprinter
= 0x0;
3934 r
->processor_architecture
= PROCESSOR_ARCHITECTURE_INTEL
;
3935 r
->processor_level
= 0x6; /* 6 ???*/
3944 /********************************************************************
3945 * construct_printer_info1
3946 * fill a spoolss_PrinterInfo1 struct
3947 ********************************************************************/
3949 static WERROR
construct_printer_info1(TALLOC_CTX
*mem_ctx
,
3950 const struct spoolss_PrinterInfo2
*info2
,
3952 const char *servername
,
3953 struct spoolss_PrinterInfo1
*r
,
3960 if (info2
->comment
== NULL
|| info2
->comment
[0] == '\0') {
3961 r
->comment
= lp_comment(mem_ctx
, snum
);
3963 r
->comment
= talloc_strdup(mem_ctx
, info2
->comment
); /* saved comment */
3965 W_ERROR_HAVE_NO_MEMORY(r
->comment
);
3967 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->name
);
3968 if (!W_ERROR_IS_OK(result
)) {
3972 r
->description
= talloc_asprintf(mem_ctx
, "%s,%s,%s",
3976 W_ERROR_HAVE_NO_MEMORY(r
->description
);
3981 /********************************************************************
3982 * construct_printer_info2
3983 * fill a spoolss_PrinterInfo2 struct
3984 ********************************************************************/
3986 static WERROR
construct_printer_info2(TALLOC_CTX
*mem_ctx
,
3987 struct messaging_context
*msg_ctx
,
3988 const struct spoolss_PrinterInfo2
*info2
,
3989 const char *servername
,
3990 struct spoolss_PrinterInfo2
*r
,
3994 print_status_struct status
;
3997 count
= print_queue_length(msg_ctx
, snum
, &status
);
4000 r
->servername
= talloc_strdup(mem_ctx
, servername
);
4001 W_ERROR_HAVE_NO_MEMORY(r
->servername
);
4003 r
->servername
= NULL
;
4006 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->printername
);
4007 if (!W_ERROR_IS_OK(result
)) {
4011 r
->sharename
= lp_servicename(mem_ctx
, snum
);
4012 W_ERROR_HAVE_NO_MEMORY(r
->sharename
);
4013 r
->portname
= talloc_strdup(mem_ctx
, info2
->portname
);
4014 W_ERROR_HAVE_NO_MEMORY(r
->portname
);
4015 r
->drivername
= talloc_strdup(mem_ctx
, info2
->drivername
);
4016 W_ERROR_HAVE_NO_MEMORY(r
->drivername
);
4018 if (info2
->comment
[0] == '\0') {
4019 r
->comment
= lp_comment(mem_ctx
, snum
);
4021 r
->comment
= talloc_strdup(mem_ctx
, info2
->comment
);
4023 W_ERROR_HAVE_NO_MEMORY(r
->comment
);
4025 r
->location
= talloc_strdup(mem_ctx
, info2
->location
);
4026 if (info2
->location
[0] == '\0') {
4027 const char *loc
= NULL
;
4030 nt_status
= printer_list_get_printer(mem_ctx
,
4035 if (NT_STATUS_IS_OK(nt_status
)) {
4037 r
->location
= talloc_strdup(mem_ctx
, loc
);
4041 W_ERROR_HAVE_NO_MEMORY(r
->location
);
4043 r
->sepfile
= talloc_strdup(mem_ctx
, info2
->sepfile
);
4044 W_ERROR_HAVE_NO_MEMORY(r
->sepfile
);
4045 r
->printprocessor
= talloc_strdup(mem_ctx
, info2
->printprocessor
);
4046 W_ERROR_HAVE_NO_MEMORY(r
->printprocessor
);
4047 r
->datatype
= talloc_strdup(mem_ctx
, info2
->datatype
);
4048 W_ERROR_HAVE_NO_MEMORY(r
->datatype
);
4049 r
->parameters
= talloc_strdup(mem_ctx
, info2
->parameters
);
4050 W_ERROR_HAVE_NO_MEMORY(r
->parameters
);
4052 r
->attributes
= info2
->attributes
;
4054 r
->priority
= info2
->priority
;
4055 r
->defaultpriority
= info2
->defaultpriority
;
4056 r
->starttime
= info2
->starttime
;
4057 r
->untiltime
= info2
->untiltime
;
4058 r
->status
= nt_printq_status(status
.status
);
4060 r
->averageppm
= info2
->averageppm
;
4062 if (info2
->devmode
!= NULL
) {
4063 result
= copy_devicemode(mem_ctx
,
4066 if (!W_ERROR_IS_OK(result
)) {
4069 } else if (lp_default_devmode(snum
)) {
4070 result
= spoolss_create_default_devmode(mem_ctx
,
4073 if (!W_ERROR_IS_OK(result
)) {
4078 DEBUG(8,("Returning NULL Devicemode!\n"));
4081 compose_devicemode_devicename(r
->devmode
, r
->printername
);
4085 if (info2
->secdesc
!= NULL
) {
4086 /* don't use talloc_steal() here unless you do a deep steal of all
4087 the SEC_DESC members */
4089 r
->secdesc
= dup_sec_desc(mem_ctx
, info2
->secdesc
);
4095 /********************************************************************
4096 * construct_printer_info3
4097 * fill a spoolss_PrinterInfo3 struct
4098 ********************************************************************/
4100 static WERROR
construct_printer_info3(TALLOC_CTX
*mem_ctx
,
4101 const struct spoolss_PrinterInfo2
*info2
,
4102 const char *servername
,
4103 struct spoolss_PrinterInfo3
*r
,
4106 /* These are the components of the SD we are returning. */
4108 if (info2
->secdesc
!= NULL
) {
4109 /* don't use talloc_steal() here unless you do a deep steal of all
4110 the SEC_DESC members */
4112 r
->secdesc
= dup_sec_desc(mem_ctx
, info2
->secdesc
);
4113 W_ERROR_HAVE_NO_MEMORY(r
->secdesc
);
4119 /********************************************************************
4120 * construct_printer_info4
4121 * fill a spoolss_PrinterInfo4 struct
4122 ********************************************************************/
4124 static WERROR
construct_printer_info4(TALLOC_CTX
*mem_ctx
,
4125 const struct spoolss_PrinterInfo2
*info2
,
4126 const char *servername
,
4127 struct spoolss_PrinterInfo4
*r
,
4132 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->printername
);
4133 if (!W_ERROR_IS_OK(result
)) {
4138 r
->servername
= talloc_strdup(mem_ctx
, servername
);
4139 W_ERROR_HAVE_NO_MEMORY(r
->servername
);
4141 r
->servername
= NULL
;
4144 r
->attributes
= info2
->attributes
;
4149 /********************************************************************
4150 * construct_printer_info5
4151 * fill a spoolss_PrinterInfo5 struct
4152 ********************************************************************/
4154 static WERROR
construct_printer_info5(TALLOC_CTX
*mem_ctx
,
4155 const struct spoolss_PrinterInfo2
*info2
,
4156 const char *servername
,
4157 struct spoolss_PrinterInfo5
*r
,
4162 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->printername
);
4163 if (!W_ERROR_IS_OK(result
)) {
4167 r
->portname
= talloc_strdup(mem_ctx
, info2
->portname
);
4168 W_ERROR_HAVE_NO_MEMORY(r
->portname
);
4170 r
->attributes
= info2
->attributes
;
4172 /* these two are not used by NT+ according to MSDN */
4173 r
->device_not_selected_timeout
= 0x0; /* have seen 0x3a98 */
4174 r
->transmission_retry_timeout
= 0x0; /* have seen 0xafc8 */
4179 /********************************************************************
4180 * construct_printer_info_6
4181 * fill a spoolss_PrinterInfo6 struct
4182 ********************************************************************/
4184 static WERROR
construct_printer_info6(TALLOC_CTX
*mem_ctx
,
4185 struct messaging_context
*msg_ctx
,
4186 const struct spoolss_PrinterInfo2
*info2
,
4187 const char *servername
,
4188 struct spoolss_PrinterInfo6
*r
,
4191 print_status_struct status
;
4193 print_queue_length(msg_ctx
, snum
, &status
);
4195 r
->status
= nt_printq_status(status
.status
);
4200 /********************************************************************
4201 * construct_printer_info7
4202 * fill a spoolss_PrinterInfo7 struct
4203 ********************************************************************/
4205 static WERROR
construct_printer_info7(TALLOC_CTX
*mem_ctx
,
4206 struct messaging_context
*msg_ctx
,
4207 const char *servername
,
4208 struct spoolss_PrinterInfo7
*r
,
4211 const struct auth_session_info
*session_info
;
4214 TALLOC_CTX
*tmp_ctx
= talloc_new(mem_ctx
);
4215 if (tmp_ctx
== NULL
) {
4219 session_info
= get_session_info_system();
4220 SMB_ASSERT(session_info
!= NULL
);
4222 printer
= lp_servicename(tmp_ctx
, snum
);
4223 if (printer
== NULL
) {
4224 DEBUG(0, ("invalid printer snum %d\n", snum
));
4225 werr
= WERR_INVALID_PARAM
;
4229 if (is_printer_published(tmp_ctx
, session_info
, msg_ctx
,
4230 servername
, printer
, NULL
)) {
4232 werr
= nt_printer_guid_get(tmp_ctx
, session_info
, msg_ctx
,
4234 if (!W_ERROR_IS_OK(werr
)) {
4237 r
->guid
= talloc_strdup_upper(mem_ctx
, GUID_string2(mem_ctx
, &guid
));
4238 r
->action
= DSPRINT_PUBLISH
;
4240 r
->guid
= talloc_strdup(mem_ctx
, "");
4241 r
->action
= DSPRINT_UNPUBLISH
;
4243 if (r
->guid
== NULL
) {
4250 talloc_free(tmp_ctx
);
4254 /********************************************************************
4255 * construct_printer_info8
4256 * fill a spoolss_PrinterInfo8 struct
4257 ********************************************************************/
4259 static WERROR
construct_printer_info8(TALLOC_CTX
*mem_ctx
,
4260 const struct spoolss_PrinterInfo2
*info2
,
4261 const char *servername
,
4262 struct spoolss_DeviceModeInfo
*r
,
4266 const char *printername
;
4268 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &printername
);
4269 if (!W_ERROR_IS_OK(result
)) {
4273 if (info2
->devmode
!= NULL
) {
4274 result
= copy_devicemode(mem_ctx
,
4277 if (!W_ERROR_IS_OK(result
)) {
4280 } else if (lp_default_devmode(snum
)) {
4281 result
= spoolss_create_default_devmode(mem_ctx
,
4284 if (!W_ERROR_IS_OK(result
)) {
4289 DEBUG(8,("Returning NULL Devicemode!\n"));
4292 compose_devicemode_devicename(r
->devmode
, printername
);
4297 /********************************************************************
4298 Spoolss_enumprinters.
4299 ********************************************************************/
4301 static WERROR
enum_all_printers_info_level(TALLOC_CTX
*mem_ctx
,
4302 const struct auth_session_info
*session_info
,
4303 struct messaging_context
*msg_ctx
,
4304 const char *servername
,
4307 union spoolss_PrinterInfo
**info_p
,
4312 union spoolss_PrinterInfo
*info
= NULL
;
4314 WERROR result
= WERR_OK
;
4315 struct dcerpc_binding_handle
*b
= NULL
;
4316 TALLOC_CTX
*tmp_ctx
= NULL
;
4318 tmp_ctx
= talloc_new(mem_ctx
);
4324 * printer shares are updated on client enumeration. The background
4325 * printer process updates printer_list.tdb at regular intervals.
4328 delete_and_reload_printers(server_event_context(), msg_ctx
);
4331 n_services
= lp_numservices();
4335 for (snum
= 0; snum
< n_services
; snum
++) {
4337 const char *printer
;
4338 struct spoolss_PrinterInfo2
*info2
;
4340 if (!snum_is_shared_printer(snum
)) {
4344 printer
= lp_const_servicename(snum
);
4346 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
4350 result
= winreg_printer_binding_handle(tmp_ctx
,
4354 if (!W_ERROR_IS_OK(result
)) {
4359 result
= winreg_create_printer(tmp_ctx
, b
,
4361 if (!W_ERROR_IS_OK(result
)) {
4365 info
= talloc_realloc(tmp_ctx
, info
,
4366 union spoolss_PrinterInfo
,
4369 result
= WERR_NOMEM
;
4373 result
= winreg_get_printer(tmp_ctx
, b
,
4375 if (!W_ERROR_IS_OK(result
)) {
4381 result
= construct_printer_info0(info
, session_info
,
4384 &info
[count
].info0
, snum
);
4387 result
= construct_printer_info1(info
, info2
, flags
,
4389 &info
[count
].info1
, snum
);
4392 result
= construct_printer_info2(info
, msg_ctx
, info2
,
4394 &info
[count
].info2
, snum
);
4397 result
= construct_printer_info4(info
, info2
,
4399 &info
[count
].info4
, snum
);
4402 result
= construct_printer_info5(info
, info2
,
4404 &info
[count
].info5
, snum
);
4408 result
= WERR_UNKNOWN_LEVEL
;
4412 if (!W_ERROR_IS_OK(result
)) {
4420 if (W_ERROR_IS_OK(result
)) {
4421 *info_p
= talloc_move(mem_ctx
, &info
);
4425 talloc_free(tmp_ctx
);
4430 /********************************************************************
4431 * handle enumeration of printers at level 0
4432 ********************************************************************/
4434 static WERROR
enumprinters_level0(TALLOC_CTX
*mem_ctx
,
4435 const struct auth_session_info
*session_info
,
4436 struct messaging_context
*msg_ctx
,
4438 const char *servername
,
4439 union spoolss_PrinterInfo
**info
,
4442 DEBUG(4,("enum_all_printers_info_0\n"));
4444 return enum_all_printers_info_level(mem_ctx
, session_info
, msg_ctx
,
4445 servername
, 0, flags
, info
, count
);
4449 /********************************************************************
4450 ********************************************************************/
4452 static WERROR
enum_all_printers_info_1(TALLOC_CTX
*mem_ctx
,
4453 const struct auth_session_info
*session_info
,
4454 struct messaging_context
*msg_ctx
,
4455 const char *servername
,
4457 union spoolss_PrinterInfo
**info
,
4460 DEBUG(4,("enum_all_printers_info_1\n"));
4462 return enum_all_printers_info_level(mem_ctx
, session_info
, msg_ctx
,
4463 servername
, 1, flags
, info
, count
);
4466 /********************************************************************
4467 enum_all_printers_info_1_local.
4468 *********************************************************************/
4470 static WERROR
enum_all_printers_info_1_local(TALLOC_CTX
*mem_ctx
,
4471 const struct auth_session_info
*session_info
,
4472 struct messaging_context
*msg_ctx
,
4473 const char *servername
,
4474 union spoolss_PrinterInfo
**info
,
4477 DEBUG(4,("enum_all_printers_info_1_local\n"));
4479 return enum_all_printers_info_1(mem_ctx
, session_info
, msg_ctx
,
4480 servername
, PRINTER_ENUM_ICON8
, info
, count
);
4483 /********************************************************************
4484 enum_all_printers_info_1_name.
4485 *********************************************************************/
4487 static WERROR
enum_all_printers_info_1_name(TALLOC_CTX
*mem_ctx
,
4488 const struct auth_session_info
*session_info
,
4489 struct messaging_context
*msg_ctx
,
4490 const char *servername
,
4491 union spoolss_PrinterInfo
**info
,
4494 const char *s
= servername
;
4496 DEBUG(4,("enum_all_printers_info_1_name\n"));
4498 if (servername
!= NULL
&&
4499 (servername
[0] == '\\') && (servername
[1] == '\\')) {
4503 if (!is_myname_or_ipaddr(s
)) {
4504 return WERR_INVALID_NAME
;
4507 return enum_all_printers_info_1(mem_ctx
, session_info
, msg_ctx
,
4508 servername
, PRINTER_ENUM_ICON8
, info
, count
);
4511 /********************************************************************
4512 enum_all_printers_info_1_network.
4513 *********************************************************************/
4515 static WERROR
enum_all_printers_info_1_network(TALLOC_CTX
*mem_ctx
,
4516 const struct auth_session_info
*session_info
,
4517 struct messaging_context
*msg_ctx
,
4518 const char *servername
,
4519 union spoolss_PrinterInfo
**info
,
4522 const char *s
= servername
;
4524 DEBUG(4,("enum_all_printers_info_1_network\n"));
4526 /* If we respond to a enum_printers level 1 on our name with flags
4527 set to PRINTER_ENUM_REMOTE with a list of printers then these
4528 printers incorrectly appear in the APW browse list.
4529 Specifically the printers for the server appear at the workgroup
4530 level where all the other servers in the domain are
4531 listed. Windows responds to this call with a
4532 WERR_CAN_NOT_COMPLETE so we should do the same. */
4534 if (servername
!= NULL
&&
4535 (servername
[0] == '\\') && (servername
[1] == '\\')) {
4539 if (is_myname_or_ipaddr(s
)) {
4540 return WERR_CAN_NOT_COMPLETE
;
4543 return enum_all_printers_info_1(mem_ctx
, session_info
, msg_ctx
,
4544 servername
, PRINTER_ENUM_NAME
, info
, count
);
4547 /********************************************************************
4548 * api_spoolss_enumprinters
4550 * called from api_spoolss_enumprinters (see this to understand)
4551 ********************************************************************/
4553 static WERROR
enum_all_printers_info_2(TALLOC_CTX
*mem_ctx
,
4554 const struct auth_session_info
*session_info
,
4555 struct messaging_context
*msg_ctx
,
4556 const char *servername
,
4557 union spoolss_PrinterInfo
**info
,
4560 DEBUG(4,("enum_all_printers_info_2\n"));
4562 return enum_all_printers_info_level(mem_ctx
, session_info
, msg_ctx
,
4563 servername
, 2, 0, info
, count
);
4566 /********************************************************************
4567 * handle enumeration of printers at level 1
4568 ********************************************************************/
4570 static WERROR
enumprinters_level1(TALLOC_CTX
*mem_ctx
,
4571 const struct auth_session_info
*session_info
,
4572 struct messaging_context
*msg_ctx
,
4574 const char *servername
,
4575 union spoolss_PrinterInfo
**info
,
4578 /* Not all the flags are equals */
4580 if (flags
& PRINTER_ENUM_LOCAL
) {
4581 return enum_all_printers_info_1_local(mem_ctx
, session_info
,
4582 msg_ctx
, servername
, info
, count
);
4585 if (flags
& PRINTER_ENUM_NAME
) {
4586 return enum_all_printers_info_1_name(mem_ctx
, session_info
,
4587 msg_ctx
, servername
, info
,
4591 if (flags
& PRINTER_ENUM_NETWORK
) {
4592 return enum_all_printers_info_1_network(mem_ctx
, session_info
,
4593 msg_ctx
, servername
, info
,
4597 return WERR_OK
; /* NT4sp5 does that */
4600 /********************************************************************
4601 * handle enumeration of printers at level 2
4602 ********************************************************************/
4604 static WERROR
enumprinters_level2(TALLOC_CTX
*mem_ctx
,
4605 const struct auth_session_info
*session_info
,
4606 struct messaging_context
*msg_ctx
,
4608 const char *servername
,
4609 union spoolss_PrinterInfo
**info
,
4612 if (flags
& PRINTER_ENUM_LOCAL
) {
4614 return enum_all_printers_info_2(mem_ctx
, session_info
, msg_ctx
,
4619 if (flags
& PRINTER_ENUM_NAME
) {
4620 if (servername
&& !is_myname_or_ipaddr(canon_servername(servername
))) {
4621 return WERR_INVALID_NAME
;
4624 return enum_all_printers_info_2(mem_ctx
, session_info
, msg_ctx
,
4629 if (flags
& PRINTER_ENUM_REMOTE
) {
4630 return WERR_UNKNOWN_LEVEL
;
4636 /********************************************************************
4637 * handle enumeration of printers at level 4
4638 ********************************************************************/
4640 static WERROR
enumprinters_level4(TALLOC_CTX
*mem_ctx
,
4641 const struct auth_session_info
*session_info
,
4642 struct messaging_context
*msg_ctx
,
4644 const char *servername
,
4645 union spoolss_PrinterInfo
**info
,
4648 DEBUG(4,("enum_all_printers_info_4\n"));
4650 return enum_all_printers_info_level(mem_ctx
, session_info
, msg_ctx
,
4651 servername
, 4, flags
, info
, count
);
4655 /********************************************************************
4656 * handle enumeration of printers at level 5
4657 ********************************************************************/
4659 static WERROR
enumprinters_level5(TALLOC_CTX
*mem_ctx
,
4660 const struct auth_session_info
*session_info
,
4661 struct messaging_context
*msg_ctx
,
4663 const char *servername
,
4664 union spoolss_PrinterInfo
**info
,
4667 DEBUG(4,("enum_all_printers_info_5\n"));
4669 return enum_all_printers_info_level(mem_ctx
, session_info
, msg_ctx
,
4670 servername
, 5, flags
, info
, count
);
4673 /****************************************************************
4674 _spoolss_EnumPrinters
4675 ****************************************************************/
4677 WERROR
_spoolss_EnumPrinters(struct pipes_struct
*p
,
4678 struct spoolss_EnumPrinters
*r
)
4680 const struct auth_session_info
*session_info
= get_session_info_system();
4683 /* that's an [in out] buffer */
4685 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
4686 return WERR_INVALID_PARAM
;
4689 DEBUG(4,("_spoolss_EnumPrinters\n"));
4693 *r
->out
.info
= NULL
;
4697 * flags==PRINTER_ENUM_NAME
4698 * if name=="" then enumerates all printers
4699 * if name!="" then enumerate the printer
4700 * flags==PRINTER_ENUM_REMOTE
4701 * name is NULL, enumerate printers
4702 * Level 2: name!="" enumerates printers, name can't be NULL
4703 * Level 3: doesn't exist
4704 * Level 4: does a local registry lookup
4705 * Level 5: same as Level 2
4708 if (r
->in
.server
&& r
->in
.server
[0] == '\0') {
4709 r
->in
.server
= NULL
;
4712 switch (r
->in
.level
) {
4714 result
= enumprinters_level0(p
->mem_ctx
, session_info
,
4715 p
->msg_ctx
, r
->in
.flags
,
4717 r
->out
.info
, r
->out
.count
);
4720 result
= enumprinters_level1(p
->mem_ctx
, session_info
,
4721 p
->msg_ctx
, r
->in
.flags
,
4723 r
->out
.info
, r
->out
.count
);
4726 result
= enumprinters_level2(p
->mem_ctx
, session_info
,
4727 p
->msg_ctx
, r
->in
.flags
,
4729 r
->out
.info
, r
->out
.count
);
4732 result
= enumprinters_level4(p
->mem_ctx
, session_info
,
4733 p
->msg_ctx
, r
->in
.flags
,
4735 r
->out
.info
, r
->out
.count
);
4738 result
= enumprinters_level5(p
->mem_ctx
, session_info
,
4739 p
->msg_ctx
, r
->in
.flags
,
4741 r
->out
.info
, r
->out
.count
);
4744 return WERR_UNKNOWN_LEVEL
;
4747 if (!W_ERROR_IS_OK(result
)) {
4751 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
4752 spoolss_EnumPrinters
,
4753 *r
->out
.info
, r
->in
.level
,
4755 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
4756 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
4758 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
4761 /****************************************************************
4763 ****************************************************************/
4765 WERROR
_spoolss_GetPrinter(struct pipes_struct
*p
,
4766 struct spoolss_GetPrinter
*r
)
4768 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
4769 struct spoolss_PrinterInfo2
*info2
= NULL
;
4770 WERROR result
= WERR_OK
;
4773 /* that's an [in out] buffer */
4775 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
4776 return WERR_INVALID_PARAM
;
4781 if (Printer
== NULL
) {
4785 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
4789 result
= winreg_get_printer_internal(p
->mem_ctx
,
4790 get_session_info_system(),
4792 lp_const_servicename(snum
),
4794 if (!W_ERROR_IS_OK(result
)) {
4798 switch (r
->in
.level
) {
4800 result
= construct_printer_info0(p
->mem_ctx
,
4801 get_session_info_system(),
4804 Printer
->servername
,
4805 &r
->out
.info
->info0
,
4809 result
= construct_printer_info1(p
->mem_ctx
, info2
,
4811 Printer
->servername
,
4812 &r
->out
.info
->info1
, snum
);
4815 result
= construct_printer_info2(p
->mem_ctx
, p
->msg_ctx
, info2
,
4816 Printer
->servername
,
4817 &r
->out
.info
->info2
, snum
);
4820 result
= construct_printer_info3(p
->mem_ctx
, info2
,
4821 Printer
->servername
,
4822 &r
->out
.info
->info3
, snum
);
4825 result
= construct_printer_info4(p
->mem_ctx
, info2
,
4826 Printer
->servername
,
4827 &r
->out
.info
->info4
, snum
);
4830 result
= construct_printer_info5(p
->mem_ctx
, info2
,
4831 Printer
->servername
,
4832 &r
->out
.info
->info5
, snum
);
4835 result
= construct_printer_info6(p
->mem_ctx
, p
->msg_ctx
, info2
,
4836 Printer
->servername
,
4837 &r
->out
.info
->info6
, snum
);
4840 result
= construct_printer_info7(p
->mem_ctx
, p
->msg_ctx
,
4841 Printer
->servername
,
4842 &r
->out
.info
->info7
, snum
);
4845 result
= construct_printer_info8(p
->mem_ctx
, info2
,
4846 Printer
->servername
,
4847 &r
->out
.info
->info8
, snum
);
4850 result
= WERR_UNKNOWN_LEVEL
;
4856 if (!W_ERROR_IS_OK(result
)) {
4857 DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
4858 r
->in
.level
, win_errstr(result
)));
4859 TALLOC_FREE(r
->out
.info
);
4863 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo
,
4864 r
->out
.info
, r
->in
.level
);
4865 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
4867 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
4870 /********************************************************************
4871 ********************************************************************/
4873 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4875 if (in && strlen(in)) { \
4876 out = talloc_strdup(mem_ctx, in); \
4878 out = talloc_strdup(mem_ctx, ""); \
4880 W_ERROR_HAVE_NO_MEMORY(out); \
4883 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, arch, ver, in, out) \
4885 if (in && strlen(in)) { \
4886 out = talloc_asprintf(mem_ctx, "\\\\%s\\print$\\%s\\%d\\%s", server, get_short_archi(arch), ver, in); \
4888 out = talloc_strdup(mem_ctx, ""); \
4890 W_ERROR_HAVE_NO_MEMORY(out); \
4893 static WERROR
string_array_from_driver_info(TALLOC_CTX
*mem_ctx
,
4894 const char **string_array
,
4895 const char ***presult
,
4896 const char *cservername
,
4901 size_t num_strings
= 0;
4902 const char **array
= NULL
;
4904 if (string_array
== NULL
) {
4905 return WERR_INVALID_PARAMETER
;
4908 for (i
=0; string_array
[i
] && string_array
[i
][0] != '\0'; i
++) {
4909 const char *str
= NULL
;
4911 if (cservername
== NULL
|| arch
== NULL
) {
4912 FILL_DRIVER_STRING(mem_ctx
, string_array
[i
], str
);
4914 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
, arch
, version
, string_array
[i
], str
);
4917 if (!add_string_to_array(mem_ctx
, str
, &array
, &num_strings
)) {
4924 ADD_TO_ARRAY(mem_ctx
, const char *, NULL
,
4925 &array
, &num_strings
);
4928 if (presult
!= NULL
) {
4937 /********************************************************************
4938 * fill a spoolss_DriverInfo1 struct
4939 ********************************************************************/
4941 static WERROR
fill_printer_driver_info1(TALLOC_CTX
*mem_ctx
,
4942 struct spoolss_DriverInfo1
*r
,
4943 const struct spoolss_DriverInfo8
*driver
,
4944 const char *servername
)
4946 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
4947 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
4952 /********************************************************************
4953 * fill a spoolss_DriverInfo2 struct
4954 ********************************************************************/
4956 static WERROR
fill_printer_driver_info2(TALLOC_CTX
*mem_ctx
,
4957 struct spoolss_DriverInfo2
*r
,
4958 const struct spoolss_DriverInfo8
*driver
,
4959 const char *servername
)
4962 const char *cservername
= canon_servername(servername
);
4964 r
->version
= driver
->version
;
4966 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
4967 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
4968 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
4969 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
4971 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4972 driver
->architecture
,
4974 driver
->driver_path
,
4977 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4978 driver
->architecture
,
4983 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4984 driver
->architecture
,
4986 driver
->config_file
,
4992 /********************************************************************
4993 * fill a spoolss_DriverInfo3 struct
4994 ********************************************************************/
4996 static WERROR
fill_printer_driver_info3(TALLOC_CTX
*mem_ctx
,
4997 struct spoolss_DriverInfo3
*r
,
4998 const struct spoolss_DriverInfo8
*driver
,
4999 const char *servername
)
5001 const char *cservername
= canon_servername(servername
);
5003 r
->version
= driver
->version
;
5005 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5006 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5007 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5008 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5010 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5011 driver
->architecture
,
5013 driver
->driver_path
,
5016 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5017 driver
->architecture
,
5022 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5023 driver
->architecture
,
5025 driver
->config_file
,
5028 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5029 driver
->architecture
,
5034 FILL_DRIVER_STRING(mem_ctx
,
5035 driver
->monitor_name
,
5038 FILL_DRIVER_STRING(mem_ctx
,
5039 driver
->default_datatype
,
5040 r
->default_datatype
);
5042 return string_array_from_driver_info(mem_ctx
,
5043 driver
->dependent_files
,
5044 &r
->dependent_files
,
5046 driver
->architecture
,
5050 /********************************************************************
5051 * fill a spoolss_DriverInfo4 struct
5052 ********************************************************************/
5054 static WERROR
fill_printer_driver_info4(TALLOC_CTX
*mem_ctx
,
5055 struct spoolss_DriverInfo4
*r
,
5056 const struct spoolss_DriverInfo8
*driver
,
5057 const char *servername
)
5059 const char *cservername
= canon_servername(servername
);
5062 r
->version
= driver
->version
;
5064 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5065 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5066 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5067 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5069 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5070 driver
->architecture
,
5072 driver
->driver_path
,
5075 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5076 driver
->architecture
,
5081 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5082 driver
->architecture
,
5084 driver
->config_file
,
5087 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5088 driver
->architecture
,
5093 result
= string_array_from_driver_info(mem_ctx
,
5094 driver
->dependent_files
,
5095 &r
->dependent_files
,
5097 driver
->architecture
,
5099 if (!W_ERROR_IS_OK(result
)) {
5103 FILL_DRIVER_STRING(mem_ctx
,
5104 driver
->monitor_name
,
5107 FILL_DRIVER_STRING(mem_ctx
,
5108 driver
->default_datatype
,
5109 r
->default_datatype
);
5112 result
= string_array_from_driver_info(mem_ctx
,
5113 driver
->previous_names
,
5120 /********************************************************************
5121 * fill a spoolss_DriverInfo5 struct
5122 ********************************************************************/
5124 static WERROR
fill_printer_driver_info5(TALLOC_CTX
*mem_ctx
,
5125 struct spoolss_DriverInfo5
*r
,
5126 const struct spoolss_DriverInfo8
*driver
,
5127 const char *servername
)
5129 const char *cservername
= canon_servername(servername
);
5131 r
->version
= driver
->version
;
5133 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5134 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5135 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5136 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5138 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5139 driver
->architecture
,
5141 driver
->driver_path
,
5144 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5145 driver
->architecture
,
5150 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5151 driver
->architecture
,
5153 driver
->config_file
,
5156 r
->driver_attributes
= 0;
5157 r
->config_version
= 0;
5158 r
->driver_version
= 0;
5162 /********************************************************************
5163 * fill a spoolss_DriverInfo6 struct
5164 ********************************************************************/
5166 static WERROR
fill_printer_driver_info6(TALLOC_CTX
*mem_ctx
,
5167 struct spoolss_DriverInfo6
*r
,
5168 const struct spoolss_DriverInfo8
*driver
,
5169 const char *servername
)
5171 const char *cservername
= canon_servername(servername
);
5174 r
->version
= driver
->version
;
5176 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5177 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5178 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5179 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5181 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5182 driver
->architecture
,
5184 driver
->driver_path
,
5187 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5188 driver
->architecture
,
5193 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5194 driver
->architecture
,
5196 driver
->config_file
,
5199 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5200 driver
->architecture
,
5205 FILL_DRIVER_STRING(mem_ctx
,
5206 driver
->monitor_name
,
5209 FILL_DRIVER_STRING(mem_ctx
,
5210 driver
->default_datatype
,
5211 r
->default_datatype
);
5213 result
= string_array_from_driver_info(mem_ctx
,
5214 driver
->dependent_files
,
5215 &r
->dependent_files
,
5217 driver
->architecture
,
5219 if (!W_ERROR_IS_OK(result
)) {
5223 result
= string_array_from_driver_info(mem_ctx
,
5224 driver
->previous_names
,
5227 if (!W_ERROR_IS_OK(result
)) {
5231 r
->driver_date
= driver
->driver_date
;
5232 r
->driver_version
= driver
->driver_version
;
5234 FILL_DRIVER_STRING(mem_ctx
,
5235 driver
->manufacturer_name
,
5236 r
->manufacturer_name
);
5237 FILL_DRIVER_STRING(mem_ctx
,
5238 driver
->manufacturer_url
,
5239 r
->manufacturer_url
);
5240 FILL_DRIVER_STRING(mem_ctx
,
5241 driver
->hardware_id
,
5243 FILL_DRIVER_STRING(mem_ctx
,
5250 /********************************************************************
5251 * fill a spoolss_DriverInfo8 struct
5252 ********************************************************************/
5254 static WERROR
fill_printer_driver_info8(TALLOC_CTX
*mem_ctx
,
5255 struct spoolss_DriverInfo8
*r
,
5256 const struct spoolss_DriverInfo8
*driver
,
5257 const char *servername
)
5259 const char *cservername
= canon_servername(servername
);
5262 r
->version
= driver
->version
;
5264 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5265 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5266 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5267 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5269 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5270 driver
->architecture
,
5272 driver
->driver_path
,
5275 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5276 driver
->architecture
,
5281 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5282 driver
->architecture
,
5284 driver
->config_file
,
5287 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5288 driver
->architecture
,
5293 FILL_DRIVER_STRING(mem_ctx
,
5294 driver
->monitor_name
,
5297 FILL_DRIVER_STRING(mem_ctx
,
5298 driver
->default_datatype
,
5299 r
->default_datatype
);
5301 result
= string_array_from_driver_info(mem_ctx
,
5302 driver
->dependent_files
,
5303 &r
->dependent_files
,
5305 driver
->architecture
,
5307 if (!W_ERROR_IS_OK(result
)) {
5311 result
= string_array_from_driver_info(mem_ctx
,
5312 driver
->previous_names
,
5315 if (!W_ERROR_IS_OK(result
)) {
5319 r
->driver_date
= driver
->driver_date
;
5320 r
->driver_version
= driver
->driver_version
;
5322 FILL_DRIVER_STRING(mem_ctx
,
5323 driver
->manufacturer_name
,
5324 r
->manufacturer_name
);
5325 FILL_DRIVER_STRING(mem_ctx
,
5326 driver
->manufacturer_url
,
5327 r
->manufacturer_url
);
5328 FILL_DRIVER_STRING(mem_ctx
,
5329 driver
->hardware_id
,
5331 FILL_DRIVER_STRING(mem_ctx
,
5335 FILL_DRIVER_STRING(mem_ctx
,
5336 driver
->print_processor
,
5337 r
->print_processor
);
5338 FILL_DRIVER_STRING(mem_ctx
,
5339 driver
->vendor_setup
,
5342 result
= string_array_from_driver_info(mem_ctx
,
5343 driver
->color_profiles
,
5346 if (!W_ERROR_IS_OK(result
)) {
5350 FILL_DRIVER_STRING(mem_ctx
,
5354 r
->printer_driver_attributes
= driver
->printer_driver_attributes
;
5356 result
= string_array_from_driver_info(mem_ctx
,
5357 driver
->core_driver_dependencies
,
5358 &r
->core_driver_dependencies
,
5360 if (!W_ERROR_IS_OK(result
)) {
5364 r
->min_inbox_driver_ver_date
= driver
->min_inbox_driver_ver_date
;
5365 r
->min_inbox_driver_ver_version
= driver
->min_inbox_driver_ver_version
;
5370 #if 0 /* disabled until marshalling issues are resolved - gd */
5371 /********************************************************************
5372 ********************************************************************/
5374 static WERROR
fill_spoolss_DriverFileInfo(TALLOC_CTX
*mem_ctx
,
5375 struct spoolss_DriverFileInfo
*r
,
5376 const char *cservername
,
5377 const char *file_name
,
5378 enum spoolss_DriverFileType file_type
,
5379 uint32_t file_version
)
5381 r
->file_name
= talloc_asprintf(mem_ctx
, "\\\\%s%s",
5382 cservername
, file_name
);
5383 W_ERROR_HAVE_NO_MEMORY(r
->file_name
);
5384 r
->file_type
= file_type
;
5385 r
->file_version
= file_version
;
5390 /********************************************************************
5391 ********************************************************************/
5393 static WERROR
spoolss_DriverFileInfo_from_driver(TALLOC_CTX
*mem_ctx
,
5394 const struct spoolss_DriverInfo8
*driver
,
5395 const char *cservername
,
5396 struct spoolss_DriverFileInfo
**info_p
,
5399 struct spoolss_DriverFileInfo
*info
= NULL
;
5407 if (strlen(driver
->driver_path
)) {
5408 info
= talloc_realloc(mem_ctx
, info
,
5409 struct spoolss_DriverFileInfo
,
5411 W_ERROR_HAVE_NO_MEMORY(info
);
5412 result
= fill_spoolss_DriverFileInfo(info
,
5415 driver
->driver_path
,
5416 SPOOLSS_DRIVER_FILE_TYPE_RENDERING
,
5418 W_ERROR_NOT_OK_RETURN(result
);
5422 if (strlen(driver
->config_file
)) {
5423 info
= talloc_realloc(mem_ctx
, info
,
5424 struct spoolss_DriverFileInfo
,
5426 W_ERROR_HAVE_NO_MEMORY(info
);
5427 result
= fill_spoolss_DriverFileInfo(info
,
5430 driver
->config_file
,
5431 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION
,
5433 W_ERROR_NOT_OK_RETURN(result
);
5437 if (strlen(driver
->data_file
)) {
5438 info
= talloc_realloc(mem_ctx
, info
,
5439 struct spoolss_DriverFileInfo
,
5441 W_ERROR_HAVE_NO_MEMORY(info
);
5442 result
= fill_spoolss_DriverFileInfo(info
,
5446 SPOOLSS_DRIVER_FILE_TYPE_DATA
,
5448 W_ERROR_NOT_OK_RETURN(result
);
5452 if (strlen(driver
->help_file
)) {
5453 info
= talloc_realloc(mem_ctx
, info
,
5454 struct spoolss_DriverFileInfo
,
5456 W_ERROR_HAVE_NO_MEMORY(info
);
5457 result
= fill_spoolss_DriverFileInfo(info
,
5461 SPOOLSS_DRIVER_FILE_TYPE_HELP
,
5463 W_ERROR_NOT_OK_RETURN(result
);
5467 for (i
=0; driver
->dependent_files
[i
] && driver
->dependent_files
[i
][0] != '\0'; i
++) {
5468 info
= talloc_realloc(mem_ctx
, info
,
5469 struct spoolss_DriverFileInfo
,
5471 W_ERROR_HAVE_NO_MEMORY(info
);
5472 result
= fill_spoolss_DriverFileInfo(info
,
5475 driver
->dependent_files
[i
],
5476 SPOOLSS_DRIVER_FILE_TYPE_OTHER
,
5478 W_ERROR_NOT_OK_RETURN(result
);
5488 /********************************************************************
5489 * fill a spoolss_DriverInfo101 struct
5490 ********************************************************************/
5492 static WERROR
fill_printer_driver_info101(TALLOC_CTX
*mem_ctx
,
5493 struct spoolss_DriverInfo101
*r
,
5494 const struct spoolss_DriverInfo8
*driver
,
5495 const char *servername
)
5497 const char *cservername
= canon_servername(servername
);
5500 r
->version
= driver
->version
;
5502 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5503 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5504 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5505 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5507 result
= spoolss_DriverFileInfo_from_driver(mem_ctx
, driver
,
5511 if (!W_ERROR_IS_OK(result
)) {
5515 FILL_DRIVER_STRING(mem_ctx
,
5516 driver
->monitor_name
,
5519 FILL_DRIVER_STRING(mem_ctx
,
5520 driver
->default_datatype
,
5521 r
->default_datatype
);
5523 result
= string_array_from_driver_info(mem_ctx
,
5524 driver
->previous_names
,
5527 if (!W_ERROR_IS_OK(result
)) {
5531 r
->driver_date
= driver
->driver_date
;
5532 r
->driver_version
= driver
->driver_version
;
5534 FILL_DRIVER_STRING(mem_ctx
,
5535 driver
->manufacturer_name
,
5536 r
->manufacturer_name
);
5537 FILL_DRIVER_STRING(mem_ctx
,
5538 driver
->manufacturer_url
,
5539 r
->manufacturer_url
);
5540 FILL_DRIVER_STRING(mem_ctx
,
5541 driver
->hardware_id
,
5543 FILL_DRIVER_STRING(mem_ctx
,
5550 /********************************************************************
5551 ********************************************************************/
5553 static WERROR
construct_printer_driver_info_level(TALLOC_CTX
*mem_ctx
,
5554 const struct auth_session_info
*session_info
,
5555 struct messaging_context
*msg_ctx
,
5557 union spoolss_DriverInfo
*r
,
5559 const char *servername
,
5560 const char *architecture
,
5563 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
5564 struct spoolss_DriverInfo8
*driver
;
5566 struct dcerpc_binding_handle
*b
;
5567 TALLOC_CTX
*tmp_ctx
= NULL
;
5570 return WERR_UNKNOWN_LEVEL
;
5573 tmp_ctx
= talloc_new(mem_ctx
);
5578 result
= winreg_printer_binding_handle(tmp_ctx
,
5582 if (!W_ERROR_IS_OK(result
)) {
5586 result
= winreg_get_printer(tmp_ctx
, b
,
5587 lp_const_servicename(snum
),
5590 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5591 win_errstr(result
)));
5593 if (!W_ERROR_IS_OK(result
)) {
5594 result
= WERR_INVALID_PRINTER_NAME
;
5598 result
= winreg_get_driver(tmp_ctx
, b
,
5600 pinfo2
->drivername
, version
, &driver
);
5602 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5603 win_errstr(result
)));
5605 if (!W_ERROR_IS_OK(result
)) {
5607 * Is this a W2k client ?
5611 result
= WERR_UNKNOWN_PRINTER_DRIVER
;
5615 /* Yes - try again with a WinNT driver. */
5617 result
= winreg_get_driver(tmp_ctx
, b
,
5621 DEBUG(8,("construct_printer_driver_level: status: %s\n",
5622 win_errstr(result
)));
5623 if (!W_ERROR_IS_OK(result
)) {
5624 result
= WERR_UNKNOWN_PRINTER_DRIVER
;
5629 /* these are allocated on mem_ctx and not tmp_ctx because they are
5630 * the 'return value' and need to utlive this call */
5633 result
= fill_printer_driver_info1(mem_ctx
, &r
->info1
, driver
, servername
);
5636 result
= fill_printer_driver_info2(mem_ctx
, &r
->info2
, driver
, servername
);
5639 result
= fill_printer_driver_info3(mem_ctx
, &r
->info3
, driver
, servername
);
5642 result
= fill_printer_driver_info4(mem_ctx
, &r
->info4
, driver
, servername
);
5645 result
= fill_printer_driver_info5(mem_ctx
, &r
->info5
, driver
, servername
);
5648 result
= fill_printer_driver_info6(mem_ctx
, &r
->info6
, driver
, servername
);
5651 result
= fill_printer_driver_info8(mem_ctx
, &r
->info8
, driver
, servername
);
5653 #if 0 /* disabled until marshalling issues are resolved - gd */
5655 result
= fill_printer_driver_info101(mem_ctx
, &r
->info101
, driver
, servername
);
5659 result
= WERR_UNKNOWN_LEVEL
;
5664 talloc_free(tmp_ctx
);
5668 /****************************************************************
5669 _spoolss_GetPrinterDriver2
5670 ****************************************************************/
5672 WERROR
_spoolss_GetPrinterDriver2(struct pipes_struct
*p
,
5673 struct spoolss_GetPrinterDriver2
*r
)
5675 struct printer_handle
*printer
;
5677 uint32_t version
= r
->in
.client_major_version
;
5681 /* that's an [in out] buffer */
5683 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
5684 return WERR_INVALID_PARAM
;
5687 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5689 if (!(printer
= find_printer_index_by_hnd(p
, r
->in
.handle
))) {
5690 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5691 return WERR_INVALID_PRINTER_NAME
;
5695 *r
->out
.server_major_version
= 0;
5696 *r
->out
.server_minor_version
= 0;
5698 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
5702 if (r
->in
.client_major_version
== SPOOLSS_DRIVER_VERSION_2012
) {
5703 DEBUG(3,("_spoolss_GetPrinterDriver2: v4 driver requested, "
5704 "downgrading to v3\n"));
5705 version
= SPOOLSS_DRIVER_VERSION_200X
;
5708 result
= construct_printer_driver_info_level(p
->mem_ctx
,
5709 get_session_info_system(),
5711 r
->in
.level
, r
->out
.info
,
5712 snum
, printer
->servername
,
5715 if (!W_ERROR_IS_OK(result
)) {
5716 TALLOC_FREE(r
->out
.info
);
5720 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_DriverInfo
,
5721 r
->out
.info
, r
->in
.level
);
5722 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
5724 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
5728 /****************************************************************
5729 _spoolss_StartPagePrinter
5730 ****************************************************************/
5732 WERROR
_spoolss_StartPagePrinter(struct pipes_struct
*p
,
5733 struct spoolss_StartPagePrinter
*r
)
5735 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5738 DEBUG(3,("_spoolss_StartPagePrinter: "
5739 "Error in startpageprinter printer handle\n"));
5743 Printer
->page_started
= true;
5747 /****************************************************************
5748 _spoolss_EndPagePrinter
5749 ****************************************************************/
5751 WERROR
_spoolss_EndPagePrinter(struct pipes_struct
*p
,
5752 struct spoolss_EndPagePrinter
*r
)
5756 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5759 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5760 OUR_HANDLE(r
->in
.handle
)));
5764 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
))
5767 Printer
->page_started
= false;
5768 print_job_endpage(p
->msg_ctx
, snum
, Printer
->jobid
);
5773 /****************************************************************
5774 _spoolss_StartDocPrinter
5775 ****************************************************************/
5777 WERROR
_spoolss_StartDocPrinter(struct pipes_struct
*p
,
5778 struct spoolss_StartDocPrinter
*r
)
5780 struct spoolss_DocumentInfo1
*info_1
;
5782 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5788 DEBUG(2,("_spoolss_StartDocPrinter: "
5789 "Invalid handle (%s:%u:%u)\n",
5790 OUR_HANDLE(r
->in
.handle
)));
5794 if (Printer
->jobid
) {
5795 DEBUG(2, ("_spoolss_StartDocPrinter: "
5796 "StartDocPrinter called twice! "
5797 "(existing jobid = %d)\n", Printer
->jobid
));
5798 return WERR_INVALID_HANDLE
;
5801 if (r
->in
.info_ctr
->level
!= 1) {
5802 return WERR_UNKNOWN_LEVEL
;
5805 info_1
= r
->in
.info_ctr
->info
.info1
;
5808 * a nice thing with NT is it doesn't listen to what you tell it.
5809 * when asked to send _only_ RAW datas, it tries to send datas
5812 * So I add checks like in NT Server ...
5815 if (info_1
->datatype
) {
5817 * The v4 driver model used in Windows 8 declares print jobs
5818 * intended to bypass the XPS processing layer by setting
5819 * datatype to "XPS_PASS" instead of "RAW".
5821 if ((strcmp(info_1
->datatype
, "RAW") != 0)
5822 && (strcmp(info_1
->datatype
, "XPS_PASS") != 0)) {
5824 return WERR_INVALID_DATATYPE
;
5828 /* get the share number of the printer */
5829 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
5833 rc
= get_remote_hostname(p
->remote_address
,
5839 if (strequal(rhost
,"UNKNOWN")) {
5840 rhost
= tsocket_address_inet_addr_string(p
->remote_address
,
5842 if (rhost
== NULL
) {
5847 werr
= print_job_start(p
->session_info
,
5851 info_1
->document_name
,
5852 info_1
->output_file
,
5856 /* An error occured in print_job_start() so return an appropriate
5859 if (!W_ERROR_IS_OK(werr
)) {
5863 Printer
->document_started
= true;
5864 *r
->out
.job_id
= Printer
->jobid
;
5869 /****************************************************************
5870 _spoolss_EndDocPrinter
5871 ****************************************************************/
5873 WERROR
_spoolss_EndDocPrinter(struct pipes_struct
*p
,
5874 struct spoolss_EndDocPrinter
*r
)
5876 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5881 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5882 OUR_HANDLE(r
->in
.handle
)));
5886 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
5890 Printer
->document_started
= false;
5891 status
= print_job_end(p
->msg_ctx
, snum
, Printer
->jobid
, NORMAL_CLOSE
);
5892 if (!NT_STATUS_IS_OK(status
)) {
5893 DEBUG(2, ("_spoolss_EndDocPrinter: "
5894 "print_job_end failed [%s]\n",
5895 nt_errstr(status
)));
5899 return ntstatus_to_werror(status
);
5902 /****************************************************************
5903 _spoolss_WritePrinter
5904 ****************************************************************/
5906 WERROR
_spoolss_WritePrinter(struct pipes_struct
*p
,
5907 struct spoolss_WritePrinter
*r
)
5909 ssize_t buffer_written
;
5911 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5914 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5915 OUR_HANDLE(r
->in
.handle
)));
5916 *r
->out
.num_written
= r
->in
._data_size
;
5920 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
))
5923 /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
5924 buffer_written
= print_job_write(server_event_context(),p
->msg_ctx
,
5925 snum
, Printer
->jobid
,
5926 (const char *)r
->in
.data
.data
,
5927 (size_t)r
->in
._data_size
);
5928 if (buffer_written
== (ssize_t
)-1) {
5929 *r
->out
.num_written
= 0;
5930 if (errno
== ENOSPC
)
5931 return WERR_NO_SPOOL_SPACE
;
5933 return WERR_ACCESS_DENIED
;
5936 *r
->out
.num_written
= r
->in
._data_size
;
5941 /********************************************************************
5942 * api_spoolss_getprinter
5943 * called from the spoolss dispatcher
5945 ********************************************************************/
5947 static WERROR
control_printer(struct policy_handle
*handle
, uint32_t command
,
5948 struct pipes_struct
*p
)
5950 const struct auth_session_info
*session_info
= p
->session_info
;
5952 WERROR errcode
= WERR_BADFUNC
;
5953 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, handle
);
5956 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5957 OUR_HANDLE(handle
)));
5961 if (!get_printer_snum(p
, handle
, &snum
, NULL
))
5965 case SPOOLSS_PRINTER_CONTROL_PAUSE
:
5966 errcode
= print_queue_pause(session_info
, p
->msg_ctx
, snum
);
5968 case SPOOLSS_PRINTER_CONTROL_RESUME
:
5969 case SPOOLSS_PRINTER_CONTROL_UNPAUSE
:
5970 errcode
= print_queue_resume(session_info
, p
->msg_ctx
, snum
);
5972 case SPOOLSS_PRINTER_CONTROL_PURGE
:
5973 errcode
= print_queue_purge(session_info
, p
->msg_ctx
, snum
);
5976 return WERR_UNKNOWN_LEVEL
;
5983 /****************************************************************
5984 _spoolss_AbortPrinter
5985 * From MSDN: "Deletes printer's spool file if printer is configured
5987 ****************************************************************/
5989 WERROR
_spoolss_AbortPrinter(struct pipes_struct
*p
,
5990 struct spoolss_AbortPrinter
*r
)
5992 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5994 WERROR errcode
= WERR_OK
;
5997 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5998 OUR_HANDLE(r
->in
.handle
)));
6002 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
))
6005 if (!Printer
->document_started
) {
6006 return WERR_SPL_NO_STARTDOC
;
6009 errcode
= print_job_delete(p
->session_info
,
6017 /********************************************************************
6018 * called by spoolss_api_setprinter
6019 * when updating a printer description
6020 ********************************************************************/
6022 static WERROR
update_printer_sec(struct policy_handle
*handle
,
6023 struct pipes_struct
*p
,
6024 struct sec_desc_buf
*secdesc_ctr
)
6026 struct spoolss_security_descriptor
*new_secdesc
= NULL
;
6027 struct spoolss_security_descriptor
*old_secdesc
= NULL
;
6028 const char *printer
;
6031 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, handle
);
6032 struct dcerpc_binding_handle
*b
;
6033 TALLOC_CTX
*tmp_ctx
= NULL
;
6035 if (!Printer
|| !get_printer_snum(p
, handle
, &snum
, NULL
)) {
6036 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
6037 OUR_HANDLE(handle
)));
6039 result
= WERR_BADFID
;
6043 if (secdesc_ctr
== NULL
) {
6044 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
6045 result
= WERR_INVALID_PARAM
;
6048 printer
= lp_const_servicename(snum
);
6050 /* Check the user has permissions to change the security
6051 descriptor. By experimentation with two NT machines, the user
6052 requires Full Access to the printer to change security
6055 if ( Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
6056 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
6057 result
= WERR_ACCESS_DENIED
;
6061 tmp_ctx
= talloc_new(p
->mem_ctx
);
6066 result
= winreg_printer_binding_handle(tmp_ctx
,
6067 get_session_info_system(),
6070 if (!W_ERROR_IS_OK(result
)) {
6074 /* NT seems to like setting the security descriptor even though
6075 nothing may have actually changed. */
6076 result
= winreg_get_printer_secdesc(tmp_ctx
, b
,
6079 if (!W_ERROR_IS_OK(result
)) {
6080 DEBUG(2,("update_printer_sec: winreg_get_printer_secdesc_internal() failed\n"));
6081 result
= WERR_BADFID
;
6085 if (DEBUGLEVEL
>= 10) {
6086 struct security_acl
*the_acl
;
6089 the_acl
= old_secdesc
->dacl
;
6090 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
6091 printer
, the_acl
->num_aces
));
6093 for (i
= 0; i
< the_acl
->num_aces
; i
++) {
6094 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
6095 &the_acl
->aces
[i
].trustee
),
6096 the_acl
->aces
[i
].access_mask
));
6099 the_acl
= secdesc_ctr
->sd
->dacl
;
6102 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
6103 printer
, the_acl
->num_aces
));
6105 for (i
= 0; i
< the_acl
->num_aces
; i
++) {
6106 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
6107 &the_acl
->aces
[i
].trustee
),
6108 the_acl
->aces
[i
].access_mask
));
6111 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
6115 new_secdesc
= sec_desc_merge(tmp_ctx
, secdesc_ctr
->sd
, old_secdesc
);
6116 if (new_secdesc
== NULL
) {
6117 result
= WERR_NOMEM
;
6121 if (security_descriptor_equal(new_secdesc
, old_secdesc
)) {
6126 result
= winreg_set_printer_secdesc(tmp_ctx
, b
,
6131 talloc_free(tmp_ctx
);
6135 /********************************************************************
6136 Canonicalize printer info from a client
6137 ********************************************************************/
6139 static bool check_printer_ok(TALLOC_CTX
*mem_ctx
,
6140 struct spoolss_SetPrinterInfo2
*info2
,
6143 fstring printername
;
6146 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
6147 "portname=%s drivername=%s comment=%s location=%s\n",
6148 info2
->servername
, info2
->printername
, info2
->sharename
,
6149 info2
->portname
, info2
->drivername
, info2
->comment
,
6152 /* we force some elements to "correct" values */
6153 info2
->servername
= talloc_asprintf(mem_ctx
, "\\\\%s", lp_netbios_name());
6154 if (info2
->servername
== NULL
) {
6157 info2
->sharename
= talloc_strdup(mem_ctx
, lp_const_servicename(snum
));
6158 if (info2
->sharename
== NULL
) {
6162 /* check to see if we allow printername != sharename */
6163 if (lp_force_printername(snum
)) {
6164 info2
->printername
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s",
6165 lp_netbios_name(), info2
->sharename
);
6167 /* make sure printername is in \\server\printername format */
6168 fstrcpy(printername
, info2
->printername
);
6170 if ( printername
[0] == '\\' && printername
[1] == '\\' ) {
6171 if ( (p
= strchr_m( &printername
[2], '\\' )) != NULL
)
6175 info2
->printername
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s",
6176 lp_netbios_name(), p
);
6178 if (info2
->printername
== NULL
) {
6182 info2
->attributes
|= PRINTER_ATTRIBUTE_SAMBA
;
6183 info2
->attributes
&= ~PRINTER_ATTRIBUTE_NOT_SAMBA
;
6188 /****************************************************************************
6189 ****************************************************************************/
6191 static WERROR
add_port_hook(TALLOC_CTX
*ctx
, struct security_token
*token
, const char *portname
, const char *uri
)
6193 char *cmd
= lp_addport_cmd(talloc_tos());
6194 char *command
= NULL
;
6196 bool is_print_op
= false;
6199 return WERR_ACCESS_DENIED
;
6202 command
= talloc_asprintf(ctx
,
6203 "%s \"%s\" \"%s\"", cmd
, portname
, uri
);
6209 is_print_op
= security_token_has_privilege(token
, SEC_PRIV_PRINT_OPERATOR
);
6211 DEBUG(10,("Running [%s]\n", command
));
6213 /********* BEGIN SePrintOperatorPrivilege **********/
6218 ret
= smbrun(command
, NULL
);
6223 /********* END SePrintOperatorPrivilege **********/
6225 DEBUGADD(10,("returned [%d]\n", ret
));
6227 TALLOC_FREE(command
);
6230 return WERR_ACCESS_DENIED
;
6236 /****************************************************************************
6237 ****************************************************************************/
6239 static bool spoolss_conn_snum_used(struct smbd_server_connection
*sconn
,
6243 * As we do not know if we are embedded in the file server process
6244 * or not, we have to pretend that all shares are in use.
6249 static bool add_printer_hook(TALLOC_CTX
*ctx
, struct security_token
*token
,
6250 struct spoolss_SetPrinterInfo2
*info2
,
6251 const char *remote_machine
,
6252 struct messaging_context
*msg_ctx
)
6254 char *cmd
= lp_addprinter_cmd(talloc_tos());
6256 char *command
= NULL
;
6260 bool is_print_op
= false;
6262 if (!remote_machine
) {
6266 command
= talloc_asprintf(ctx
,
6267 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
6268 cmd
, info2
->printername
, info2
->sharename
,
6269 info2
->portname
, info2
->drivername
,
6270 info2
->location
, info2
->comment
, remote_machine
);
6276 is_print_op
= security_token_has_privilege(token
, SEC_PRIV_PRINT_OPERATOR
);
6278 DEBUG(10,("Running [%s]\n", command
));
6280 /********* BEGIN SePrintOperatorPrivilege **********/
6285 if ( (ret
= smbrun(command
, &fd
)) == 0 ) {
6286 /* Tell everyone we updated smb.conf. */
6287 message_send_all(msg_ctx
, MSG_SMB_CONF_UPDATED
, NULL
, 0, NULL
);
6293 /********* END SePrintOperatorPrivilege **********/
6295 DEBUGADD(10,("returned [%d]\n", ret
));
6297 TALLOC_FREE(command
);
6305 /* reload our services immediately */
6307 reload_services(NULL
, spoolss_conn_snum_used
, false);
6311 /* Get lines and convert them back to dos-codepage */
6312 qlines
= fd_lines_load(fd
, &numlines
, 0, NULL
);
6313 DEBUGADD(10,("Lines returned = [%d]\n", numlines
));
6316 /* Set the portname to what the script says the portname should be. */
6317 /* but don't require anything to be return from the script exit a good error code */
6320 /* Set the portname to what the script says the portname should be. */
6321 info2
->portname
= talloc_strdup(ctx
, qlines
[0]);
6322 DEBUGADD(6,("Line[0] = [%s]\n", qlines
[0]));
6325 TALLOC_FREE(qlines
);
6329 static WERROR
update_dsspooler(TALLOC_CTX
*mem_ctx
,
6330 const struct auth_session_info
*session_info
,
6331 struct messaging_context
*msg_ctx
,
6333 struct spoolss_SetPrinterInfo2
*printer
,
6334 struct spoolss_PrinterInfo2
*old_printer
)
6336 bool force_update
= (old_printer
== NULL
);
6337 const char *dnsdomname
;
6338 const char *longname
;
6339 const char *uncname
;
6340 const char *spooling
;
6342 WERROR result
= WERR_OK
;
6343 struct dcerpc_binding_handle
*b
;
6344 TALLOC_CTX
*tmp_ctx
;
6347 tmp_ctx
= talloc_new(mem_ctx
);
6352 result
= winreg_printer_binding_handle(tmp_ctx
,
6356 if (!W_ERROR_IS_OK(result
)) {
6360 if (printer
->drivername
!= NULL
&&
6362 !strequal(printer
->drivername
, old_printer
->drivername
))) {
6363 ok
= push_reg_sz(tmp_ctx
, &buffer
, printer
->drivername
);
6365 DEBUG(0, ("%s data corrupted\n", SPOOL_REG_DRIVERNAME
));
6366 result
= WERR_INVALID_DATA
;
6369 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6371 SPOOL_DSSPOOLER_KEY
,
6372 SPOOL_REG_DRIVERNAME
,
6376 if (!W_ERROR_IS_OK(result
)) {
6377 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_DRIVERNAME
));
6381 if (!force_update
) {
6382 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
6383 printer
->drivername
));
6385 notify_printer_driver(server_event_context(), msg_ctx
,
6386 snum
, printer
->drivername
?
6387 printer
->drivername
: "");
6391 if (printer
->comment
!= NULL
&&
6393 !strequal(printer
->comment
, old_printer
->comment
))) {
6394 ok
= push_reg_sz(tmp_ctx
, &buffer
, printer
->comment
);
6396 DEBUG(0, ("comment data corrupted\n"));
6397 result
= WERR_INVALID_DATA
;
6400 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6402 SPOOL_DSSPOOLER_KEY
,
6403 SPOOL_REG_DESCRIPTION
,
6407 if (!W_ERROR_IS_OK(result
)) {
6408 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_DESCRIPTION
));
6412 if (!force_update
) {
6413 notify_printer_comment(server_event_context(), msg_ctx
,
6414 snum
, printer
->comment
?
6415 printer
->comment
: "");
6419 if (printer
->sharename
!= NULL
&&
6421 !strequal(printer
->sharename
, old_printer
->sharename
))) {
6422 ok
= push_reg_sz(tmp_ctx
, &buffer
, printer
->sharename
);
6424 DEBUG(0, ("sharename data corrupted\n"));
6425 result
= WERR_INVALID_DATA
;
6428 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6430 SPOOL_DSSPOOLER_KEY
,
6431 SPOOL_REG_PRINTSHARENAME
,
6435 if (!W_ERROR_IS_OK(result
)) {
6436 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSHARENAME
));
6440 if (!force_update
) {
6441 notify_printer_sharename(server_event_context(),
6443 snum
, printer
->sharename
?
6444 printer
->sharename
: "");
6448 if (printer
->printername
!= NULL
&&
6450 !strequal(printer
->printername
, old_printer
->printername
))) {
6453 p
= strrchr(printer
->printername
, '\\' );
6457 p
= printer
->printername
;
6460 ok
= push_reg_sz(tmp_ctx
, &buffer
, p
);
6462 DEBUG(0, ("printername data corrupted\n"));
6463 result
= WERR_INVALID_DATA
;
6466 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6468 SPOOL_DSSPOOLER_KEY
,
6469 SPOOL_REG_PRINTERNAME
,
6473 if (!W_ERROR_IS_OK(result
)) {
6474 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSHARENAME
));
6478 if (!force_update
) {
6479 notify_printer_printername(server_event_context(),
6480 msg_ctx
, snum
, p
? p
: "");
6484 if (printer
->portname
!= NULL
&&
6486 !strequal(printer
->portname
, old_printer
->portname
))) {
6487 ok
= push_reg_sz(tmp_ctx
, &buffer
, printer
->portname
);
6489 DEBUG(0, ("portname data corrupted\n"));
6490 result
= WERR_INVALID_DATA
;
6493 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6495 SPOOL_DSSPOOLER_KEY
,
6500 if (!W_ERROR_IS_OK(result
)) {
6501 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PORTNAME
));
6505 if (!force_update
) {
6506 notify_printer_port(server_event_context(),
6507 msg_ctx
, snum
, printer
->portname
?
6508 printer
->portname
: "");
6512 if (printer
->location
!= NULL
&&
6514 !strequal(printer
->location
, old_printer
->location
))) {
6515 ok
= push_reg_sz(tmp_ctx
, &buffer
, printer
->location
);
6517 DEBUG(0, ("location data corrupted\n"));
6518 result
= WERR_INVALID_DATA
;
6521 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6523 SPOOL_DSSPOOLER_KEY
,
6528 if (!W_ERROR_IS_OK(result
)) {
6529 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_LOCATION
));
6533 if (!force_update
) {
6534 notify_printer_location(server_event_context(),
6537 printer
->location
: "");
6541 if (printer
->sepfile
!= NULL
&&
6543 !strequal(printer
->sepfile
, old_printer
->sepfile
))) {
6544 ok
= push_reg_sz(tmp_ctx
, &buffer
, printer
->sepfile
);
6546 DEBUG(0, ("sepfile data corrupted\n"));
6547 result
= WERR_INVALID_DATA
;
6550 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6552 SPOOL_DSSPOOLER_KEY
,
6553 SPOOL_REG_PRINTSEPARATORFILE
,
6557 if (!W_ERROR_IS_OK(result
)) {
6558 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSEPARATORFILE
));
6562 if (!force_update
) {
6563 notify_printer_sepfile(server_event_context(),
6566 printer
->sepfile
: "");
6570 if (printer
->starttime
!= 0 &&
6572 printer
->starttime
!= old_printer
->starttime
)) {
6573 buffer
= data_blob_talloc(tmp_ctx
, NULL
, 4);
6574 SIVAL(buffer
.data
, 0, printer
->starttime
);
6575 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6577 SPOOL_DSSPOOLER_KEY
,
6578 SPOOL_REG_PRINTSTARTTIME
,
6582 if (!W_ERROR_IS_OK(result
)) {
6583 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSTARTTIME
));
6588 if (printer
->untiltime
!= 0 &&
6590 printer
->untiltime
!= old_printer
->untiltime
)) {
6591 buffer
= data_blob_talloc(tmp_ctx
, NULL
, 4);
6592 SIVAL(buffer
.data
, 0, printer
->untiltime
);
6593 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6595 SPOOL_DSSPOOLER_KEY
,
6596 SPOOL_REG_PRINTENDTIME
,
6600 if (!W_ERROR_IS_OK(result
)) {
6601 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTENDTIME
));
6606 if (force_update
|| printer
->priority
!= old_printer
->priority
) {
6607 buffer
= data_blob_talloc(tmp_ctx
, NULL
, 4);
6608 SIVAL(buffer
.data
, 0, printer
->priority
);
6609 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6611 SPOOL_DSSPOOLER_KEY
,
6616 if (!W_ERROR_IS_OK(result
)) {
6617 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTENDTIME
));
6622 if (force_update
|| printer
->attributes
!= old_printer
->attributes
) {
6623 buffer
= data_blob_talloc(tmp_ctx
, NULL
, 4);
6624 SIVAL(buffer
.data
, 0, (printer
->attributes
&
6625 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS
));
6626 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6628 SPOOL_DSSPOOLER_KEY
,
6629 SPOOL_REG_PRINTKEEPPRINTEDJOBS
,
6633 if (!W_ERROR_IS_OK(result
)) {
6634 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTENDTIME
));
6638 switch (printer
->attributes
& 0x3) {
6640 spooling
= SPOOL_REGVAL_PRINTWHILESPOOLING
;
6643 spooling
= SPOOL_REGVAL_PRINTAFTERSPOOLED
;
6646 spooling
= SPOOL_REGVAL_PRINTDIRECT
;
6649 spooling
= "unknown";
6651 ok
= push_reg_sz(tmp_ctx
, &buffer
, spooling
);
6653 DEBUG(0, ("printSpooling data corrupted\n"));
6654 result
= WERR_INVALID_DATA
;
6657 winreg_set_printer_dataex(tmp_ctx
, b
,
6659 SPOOL_DSSPOOLER_KEY
,
6660 SPOOL_REG_PRINTSPOOLING
,
6666 ok
= push_reg_sz(tmp_ctx
, &buffer
, lp_netbios_name());
6668 DEBUG(0, ("shortServerName data corrupted\n"));
6669 result
= WERR_INVALID_DATA
;
6672 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6674 SPOOL_DSSPOOLER_KEY
,
6675 SPOOL_REG_SHORTSERVERNAME
,
6679 if (!W_ERROR_IS_OK(result
)) {
6680 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_SHORTSERVERNAME
));
6684 dnsdomname
= get_mydnsfullname();
6685 if (dnsdomname
!= NULL
&& dnsdomname
[0] != '\0') {
6686 longname
= talloc_strdup(tmp_ctx
, dnsdomname
);
6688 longname
= talloc_strdup(tmp_ctx
, lp_netbios_name());
6690 if (longname
== NULL
) {
6691 result
= WERR_NOMEM
;
6695 ok
= push_reg_sz(tmp_ctx
, &buffer
, longname
);
6697 DEBUG(0, ("longname data corrupted\n"));
6698 result
= WERR_INVALID_DATA
;
6701 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6703 SPOOL_DSSPOOLER_KEY
,
6704 SPOOL_REG_SERVERNAME
,
6708 if (!W_ERROR_IS_OK(result
)) {
6709 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_SERVERNAME
));
6713 uncname
= talloc_asprintf(tmp_ctx
, "\\\\%s\\%s",
6714 lp_netbios_name(), printer
->sharename
);
6715 ok
= push_reg_sz(tmp_ctx
, &buffer
, uncname
);
6717 DEBUG(0, ("uncName data corrupted\n"));
6718 result
= WERR_INVALID_DATA
;
6721 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6723 SPOOL_DSSPOOLER_KEY
,
6728 if (!W_ERROR_IS_OK(result
)) {
6729 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_UNCNAME
));
6734 talloc_free(tmp_ctx
);
6738 /********************************************************************
6739 * Called by spoolss_api_setprinter
6740 * when updating a printer description.
6741 ********************************************************************/
6743 static WERROR
update_printer(struct pipes_struct
*p
,
6744 struct policy_handle
*handle
,
6745 struct spoolss_SetPrinterInfoCtr
*info_ctr
,
6746 struct spoolss_DeviceMode
*devmode
)
6748 uint32_t printer_mask
= SPOOLSS_PRINTER_INFO_ALL
;
6749 struct spoolss_SetPrinterInfo2
*printer
= info_ctr
->info
.info2
;
6750 struct spoolss_PrinterInfo2
*old_printer
;
6751 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, handle
);
6753 WERROR result
= WERR_OK
;
6754 TALLOC_CTX
*tmp_ctx
;
6755 struct dcerpc_binding_handle
*b
;
6757 DEBUG(8,("update_printer\n"));
6759 tmp_ctx
= talloc_new(p
->mem_ctx
);
6760 if (tmp_ctx
== NULL
) {
6765 result
= WERR_BADFID
;
6769 if (!get_printer_snum(p
, handle
, &snum
, NULL
)) {
6770 result
= WERR_BADFID
;
6774 result
= winreg_printer_binding_handle(tmp_ctx
,
6775 get_session_info_system(),
6778 if (!W_ERROR_IS_OK(result
)) {
6782 result
= winreg_get_printer(tmp_ctx
, b
,
6783 lp_const_servicename(snum
),
6785 if (!W_ERROR_IS_OK(result
)) {
6786 result
= WERR_BADFID
;
6790 /* Do sanity check on the requested changes for Samba */
6791 if (!check_printer_ok(tmp_ctx
, printer
, snum
)) {
6792 result
= WERR_INVALID_PARAM
;
6796 /* FIXME!!! If the driver has changed we really should verify that
6797 it is installed before doing much else --jerry */
6799 /* Check calling user has permission to update printer description */
6800 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
6801 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6802 result
= WERR_ACCESS_DENIED
;
6806 /* Call addprinter hook */
6807 /* Check changes to see if this is really needed */
6809 if (*lp_addprinter_cmd(talloc_tos()) &&
6810 (!strequal(printer
->drivername
, old_printer
->drivername
) ||
6811 !strequal(printer
->comment
, old_printer
->comment
) ||
6812 !strequal(printer
->portname
, old_printer
->portname
) ||
6813 !strequal(printer
->location
, old_printer
->location
)) )
6817 raddr
= tsocket_address_inet_addr_string(p
->remote_address
,
6819 if (raddr
== NULL
) {
6823 /* add_printer_hook() will call reload_services() */
6824 if (!add_printer_hook(tmp_ctx
, p
->session_info
->security_token
,
6827 result
= WERR_ACCESS_DENIED
;
6832 result
= update_dsspooler(tmp_ctx
,
6833 get_session_info_system(),
6838 if (!W_ERROR_IS_OK(result
)) {
6842 printer_mask
&= ~SPOOLSS_PRINTER_INFO_SECDESC
;
6844 if (devmode
== NULL
) {
6845 printer_mask
&= ~SPOOLSS_PRINTER_INFO_DEVMODE
;
6847 result
= winreg_update_printer(tmp_ctx
, b
,
6855 talloc_free(tmp_ctx
);
6860 /****************************************************************************
6861 ****************************************************************************/
6862 static WERROR
publish_or_unpublish_printer(struct pipes_struct
*p
,
6863 struct policy_handle
*handle
,
6864 struct spoolss_SetPrinterInfo7
*info7
)
6867 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
6870 struct printer_handle
*Printer
;
6872 if ( lp_security() != SEC_ADS
) {
6873 return WERR_UNKNOWN_LEVEL
;
6876 Printer
= find_printer_index_by_hnd(p
, handle
);
6878 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7
->action
));
6883 if (!get_printer_snum(p
, handle
, &snum
, NULL
))
6886 result
= winreg_get_printer_internal(p
->mem_ctx
,
6887 get_session_info_system(),
6889 lp_servicename(talloc_tos(), snum
),
6891 if (!W_ERROR_IS_OK(result
)) {
6895 nt_printer_publish(pinfo2
,
6896 get_session_info_system(),
6901 TALLOC_FREE(pinfo2
);
6904 return WERR_UNKNOWN_LEVEL
;
6908 /********************************************************************
6909 ********************************************************************/
6911 static WERROR
update_printer_devmode(struct pipes_struct
*p
,
6912 struct policy_handle
*handle
,
6913 struct spoolss_DeviceMode
*devmode
)
6916 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, handle
);
6917 uint32_t info2_mask
= SPOOLSS_PRINTER_INFO_DEVMODE
;
6919 DEBUG(8,("update_printer_devmode\n"));
6925 if (!get_printer_snum(p
, handle
, &snum
, NULL
)) {
6929 /* Check calling user has permission to update printer description */
6930 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
6931 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6932 return WERR_ACCESS_DENIED
;
6935 return winreg_update_printer_internal(p
->mem_ctx
,
6936 get_session_info_system(),
6938 lp_const_servicename(snum
),
6946 /****************************************************************
6948 ****************************************************************/
6950 WERROR
_spoolss_SetPrinter(struct pipes_struct
*p
,
6951 struct spoolss_SetPrinter
*r
)
6955 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
6958 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6959 OUR_HANDLE(r
->in
.handle
)));
6963 /* check the level */
6964 switch (r
->in
.info_ctr
->level
) {
6966 return control_printer(r
->in
.handle
, r
->in
.command
, p
);
6968 result
= update_printer(p
, r
->in
.handle
,
6970 r
->in
.devmode_ctr
->devmode
);
6971 if (!W_ERROR_IS_OK(result
))
6973 if (r
->in
.secdesc_ctr
->sd
)
6974 result
= update_printer_sec(r
->in
.handle
, p
,
6978 return update_printer_sec(r
->in
.handle
, p
,
6981 return publish_or_unpublish_printer(p
, r
->in
.handle
,
6982 r
->in
.info_ctr
->info
.info7
);
6984 return update_printer_devmode(p
, r
->in
.handle
,
6985 r
->in
.devmode_ctr
->devmode
);
6987 return WERR_UNKNOWN_LEVEL
;
6991 /****************************************************************
6992 _spoolss_FindClosePrinterNotify
6993 ****************************************************************/
6995 WERROR
_spoolss_FindClosePrinterNotify(struct pipes_struct
*p
,
6996 struct spoolss_FindClosePrinterNotify
*r
)
6998 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
7001 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
7002 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r
->in
.handle
)));
7006 if (Printer
->notify
.cli_chan
!= NULL
&&
7007 Printer
->notify
.cli_chan
->active_connections
> 0) {
7010 if (Printer
->printer_type
== SPLHND_PRINTER
) {
7011 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
7016 srv_spoolss_replycloseprinter(snum
, Printer
);
7019 Printer
->notify
.flags
=0;
7020 Printer
->notify
.options
=0;
7021 Printer
->notify
.localmachine
[0]='\0';
7022 Printer
->notify
.printerlocal
=0;
7023 TALLOC_FREE(Printer
->notify
.option
);
7028 /****************************************************************
7030 ****************************************************************/
7032 WERROR
_spoolss_AddJob(struct pipes_struct
*p
,
7033 struct spoolss_AddJob
*r
)
7035 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
7036 return WERR_INVALID_PARAM
;
7039 /* this is what a NT server returns for AddJob. AddJob must fail on
7040 * non-local printers */
7042 if (r
->in
.level
!= 1) {
7043 return WERR_UNKNOWN_LEVEL
;
7046 return WERR_INVALID_PARAM
;
7049 /****************************************************************************
7051 ****************************************************************************/
7053 static WERROR
fill_job_info1(TALLOC_CTX
*mem_ctx
,
7054 struct spoolss_JobInfo1
*r
,
7055 const print_queue_struct
*queue
,
7057 int position
, int snum
,
7058 struct spoolss_PrinterInfo2
*pinfo2
)
7062 t
= gmtime(&queue
->time
);
7066 r
->printer_name
= lp_servicename(mem_ctx
, snum
);
7067 W_ERROR_HAVE_NO_MEMORY(r
->printer_name
);
7068 r
->server_name
= talloc_strdup(mem_ctx
, pinfo2
->servername
);
7069 W_ERROR_HAVE_NO_MEMORY(r
->server_name
);
7070 r
->user_name
= talloc_strdup(mem_ctx
, queue
->fs_user
);
7071 W_ERROR_HAVE_NO_MEMORY(r
->user_name
);
7072 r
->document_name
= talloc_strdup(mem_ctx
, queue
->fs_file
);
7073 W_ERROR_HAVE_NO_MEMORY(r
->document_name
);
7074 r
->data_type
= talloc_strdup(mem_ctx
, "RAW");
7075 W_ERROR_HAVE_NO_MEMORY(r
->data_type
);
7076 r
->text_status
= talloc_strdup(mem_ctx
, "");
7077 W_ERROR_HAVE_NO_MEMORY(r
->text_status
);
7079 r
->status
= nt_printj_status(queue
->status
);
7080 r
->priority
= queue
->priority
;
7081 r
->position
= position
;
7082 r
->total_pages
= queue
->page_count
;
7083 r
->pages_printed
= 0; /* ??? */
7085 init_systemtime(&r
->submitted
, t
);
7090 /****************************************************************************
7092 ****************************************************************************/
7094 static WERROR
fill_job_info2(TALLOC_CTX
*mem_ctx
,
7095 struct spoolss_JobInfo2
*r
,
7096 const print_queue_struct
*queue
,
7098 int position
, int snum
,
7099 struct spoolss_PrinterInfo2
*pinfo2
,
7100 struct spoolss_DeviceMode
*devmode
)
7104 t
= gmtime(&queue
->time
);
7108 r
->printer_name
= lp_servicename(mem_ctx
, snum
);
7109 W_ERROR_HAVE_NO_MEMORY(r
->printer_name
);
7110 r
->server_name
= talloc_strdup(mem_ctx
, pinfo2
->servername
);
7111 W_ERROR_HAVE_NO_MEMORY(r
->server_name
);
7112 r
->user_name
= talloc_strdup(mem_ctx
, queue
->fs_user
);
7113 W_ERROR_HAVE_NO_MEMORY(r
->user_name
);
7114 r
->document_name
= talloc_strdup(mem_ctx
, queue
->fs_file
);
7115 W_ERROR_HAVE_NO_MEMORY(r
->document_name
);
7116 r
->notify_name
= talloc_strdup(mem_ctx
, queue
->fs_user
);
7117 W_ERROR_HAVE_NO_MEMORY(r
->notify_name
);
7118 r
->data_type
= talloc_strdup(mem_ctx
, "RAW");
7119 W_ERROR_HAVE_NO_MEMORY(r
->data_type
);
7120 r
->print_processor
= talloc_strdup(mem_ctx
, "winprint");
7121 W_ERROR_HAVE_NO_MEMORY(r
->print_processor
);
7122 r
->parameters
= talloc_strdup(mem_ctx
, "");
7123 W_ERROR_HAVE_NO_MEMORY(r
->parameters
);
7124 r
->driver_name
= talloc_strdup(mem_ctx
, pinfo2
->drivername
);
7125 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
7127 r
->devmode
= devmode
;
7129 r
->text_status
= talloc_strdup(mem_ctx
, "");
7130 W_ERROR_HAVE_NO_MEMORY(r
->text_status
);
7134 r
->status
= nt_printj_status(queue
->status
);
7135 r
->priority
= queue
->priority
;
7136 r
->position
= position
;
7139 r
->total_pages
= queue
->page_count
;
7140 r
->size
= queue
->size
;
7141 init_systemtime(&r
->submitted
, t
);
7143 r
->pages_printed
= 0; /* ??? */
7148 /****************************************************************************
7149 Enumjobs at level 1.
7150 ****************************************************************************/
7152 static WERROR
enumjobs_level1(TALLOC_CTX
*mem_ctx
,
7153 const print_queue_struct
*queue
,
7154 uint32_t num_queues
, int snum
,
7155 struct spoolss_PrinterInfo2
*pinfo2
,
7156 union spoolss_JobInfo
**info_p
,
7159 union spoolss_JobInfo
*info
;
7161 WERROR result
= WERR_OK
;
7162 uint32_t num_filled
;
7163 struct tdb_print_db
*pdb
;
7165 info
= talloc_array(mem_ctx
, union spoolss_JobInfo
, num_queues
);
7167 result
= WERR_NOMEM
;
7171 pdb
= get_print_db_byname(pinfo2
->sharename
);
7173 result
= WERR_INVALID_PARAM
;
7178 for (i
= 0; i
< num_queues
; i
++) {
7179 uint32_t jobid
= sysjob_to_jobid_pdb(pdb
, queue
[i
].sysjob
);
7180 if (jobid
== (uint32_t)-1) {
7181 DEBUG(4, ("skipping sysjob %d\n", queue
[i
].sysjob
));
7185 result
= fill_job_info1(info
,
7186 &info
[num_filled
].info1
,
7192 if (!W_ERROR_IS_OK(result
)) {
7199 release_print_db(pdb
);
7201 *count
= num_filled
;
7206 release_print_db(pdb
);
7214 /****************************************************************************
7215 Enumjobs at level 2.
7216 ****************************************************************************/
7218 static WERROR
enumjobs_level2(TALLOC_CTX
*mem_ctx
,
7219 const print_queue_struct
*queue
,
7220 uint32_t num_queues
, int snum
,
7221 struct spoolss_PrinterInfo2
*pinfo2
,
7222 union spoolss_JobInfo
**info_p
,
7225 union spoolss_JobInfo
*info
;
7227 WERROR result
= WERR_OK
;
7228 uint32_t num_filled
;
7229 struct tdb_print_db
*pdb
;
7231 info
= talloc_array(mem_ctx
, union spoolss_JobInfo
, num_queues
);
7233 result
= WERR_NOMEM
;
7237 pdb
= get_print_db_byname(pinfo2
->sharename
);
7239 result
= WERR_INVALID_PARAM
;
7244 for (i
= 0; i
< num_queues
; i
++) {
7245 struct spoolss_DeviceMode
*devmode
;
7246 uint32_t jobid
= sysjob_to_jobid_pdb(pdb
, queue
[i
].sysjob
);
7247 if (jobid
== (uint32_t)-1) {
7248 DEBUG(4, ("skipping sysjob %d\n", queue
[i
].sysjob
));
7252 result
= spoolss_create_default_devmode(info
,
7253 pinfo2
->printername
,
7255 if (!W_ERROR_IS_OK(result
)) {
7256 DEBUG(3, ("Can't proceed w/o a devmode!"));
7260 result
= fill_job_info2(info
,
7261 &info
[num_filled
].info2
,
7268 if (!W_ERROR_IS_OK(result
)) {
7274 release_print_db(pdb
);
7276 *count
= num_filled
;
7281 release_print_db(pdb
);
7289 /****************************************************************************
7290 Enumjobs at level 3.
7291 ****************************************************************************/
7293 static WERROR
enumjobs_level3(TALLOC_CTX
*mem_ctx
,
7294 const print_queue_struct
*queue
,
7295 uint32_t num_queues
, int snum
,
7296 struct spoolss_PrinterInfo2
*pinfo2
,
7297 union spoolss_JobInfo
**info_p
,
7300 union spoolss_JobInfo
*info
;
7302 WERROR result
= WERR_OK
;
7303 uint32_t num_filled
;
7304 struct tdb_print_db
*pdb
;
7306 info
= talloc_array(mem_ctx
, union spoolss_JobInfo
, num_queues
);
7308 result
= WERR_NOMEM
;
7312 pdb
= get_print_db_byname(pinfo2
->sharename
);
7314 result
= WERR_INVALID_PARAM
;
7319 for (i
= 0; i
< num_queues
; i
++) {
7320 uint32_t jobid
= sysjob_to_jobid_pdb(pdb
, queue
[i
].sysjob
);
7321 if (jobid
== (uint32_t)-1) {
7322 DEBUG(4, ("skipping sysjob %d\n", queue
[i
].sysjob
));
7326 info
[num_filled
].info3
.job_id
= jobid
;
7327 /* next_job_id is overwritten on next iteration */
7328 info
[num_filled
].info3
.next_job_id
= 0;
7329 info
[num_filled
].info3
.reserved
= 0;
7331 if (num_filled
> 0) {
7332 info
[num_filled
- 1].info3
.next_job_id
= jobid
;
7337 release_print_db(pdb
);
7339 *count
= num_filled
;
7350 /****************************************************************
7352 ****************************************************************/
7354 WERROR
_spoolss_EnumJobs(struct pipes_struct
*p
,
7355 struct spoolss_EnumJobs
*r
)
7358 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
7360 print_status_struct prt_status
;
7361 print_queue_struct
*queue
= NULL
;
7364 /* that's an [in out] buffer */
7366 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
7367 return WERR_INVALID_PARAM
;
7370 if ((r
->in
.level
!= 1) && (r
->in
.level
!= 2) && (r
->in
.level
!= 3)) {
7371 DEBUG(4, ("EnumJobs level %d not supported\n", r
->in
.level
));
7372 return WERR_UNKNOWN_LEVEL
;
7375 DEBUG(4,("_spoolss_EnumJobs\n"));
7379 *r
->out
.info
= NULL
;
7381 /* lookup the printer snum and tdb entry */
7383 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
7387 result
= winreg_get_printer_internal(p
->mem_ctx
,
7388 get_session_info_system(),
7390 lp_const_servicename(snum
),
7392 if (!W_ERROR_IS_OK(result
)) {
7396 count
= print_queue_status(p
->msg_ctx
, snum
, &queue
, &prt_status
);
7397 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
7398 count
, prt_status
.status
, prt_status
.message
));
7402 TALLOC_FREE(pinfo2
);
7406 switch (r
->in
.level
) {
7408 result
= enumjobs_level1(p
->mem_ctx
, queue
, count
, snum
,
7409 pinfo2
, r
->out
.info
, r
->out
.count
);
7412 result
= enumjobs_level2(p
->mem_ctx
, queue
, count
, snum
,
7413 pinfo2
, r
->out
.info
, r
->out
.count
);
7416 result
= enumjobs_level3(p
->mem_ctx
, queue
, count
, snum
,
7417 pinfo2
, r
->out
.info
, r
->out
.count
);
7420 SMB_ASSERT(false); /* level checked on entry */
7425 TALLOC_FREE(pinfo2
);
7427 if (!W_ERROR_IS_OK(result
)) {
7431 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
7433 *r
->out
.info
, r
->in
.level
,
7435 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
7436 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
7438 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
7441 /****************************************************************
7442 _spoolss_ScheduleJob
7443 ****************************************************************/
7445 WERROR
_spoolss_ScheduleJob(struct pipes_struct
*p
,
7446 struct spoolss_ScheduleJob
*r
)
7451 /****************************************************************
7452 ****************************************************************/
7454 static WERROR
spoolss_setjob_1(TALLOC_CTX
*mem_ctx
,
7455 struct messaging_context
*msg_ctx
,
7456 const char *printer_name
,
7458 struct spoolss_SetJobInfo1
*r
)
7462 if (!print_job_get_name(mem_ctx
, printer_name
, job_id
, &old_doc_name
)) {
7466 if (strequal(old_doc_name
, r
->document_name
)) {
7470 if (!print_job_set_name(server_event_context(), msg_ctx
,
7471 printer_name
, job_id
, r
->document_name
)) {
7478 /****************************************************************
7480 ****************************************************************/
7482 WERROR
_spoolss_SetJob(struct pipes_struct
*p
,
7483 struct spoolss_SetJob
*r
)
7485 const struct auth_session_info
*session_info
= p
->session_info
;
7487 WERROR errcode
= WERR_BADFUNC
;
7489 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
7493 if (!print_job_exists(lp_const_servicename(snum
), r
->in
.job_id
)) {
7494 return WERR_INVALID_PRINTER_NAME
;
7497 switch (r
->in
.command
) {
7498 case SPOOLSS_JOB_CONTROL_CANCEL
:
7499 case SPOOLSS_JOB_CONTROL_DELETE
:
7500 errcode
= print_job_delete(session_info
, p
->msg_ctx
,
7501 snum
, r
->in
.job_id
);
7502 if (W_ERROR_EQUAL(errcode
, WERR_PRINTER_HAS_JOBS_QUEUED
)) {
7506 case SPOOLSS_JOB_CONTROL_PAUSE
:
7507 errcode
= print_job_pause(session_info
, p
->msg_ctx
,
7508 snum
, r
->in
.job_id
);
7510 case SPOOLSS_JOB_CONTROL_RESTART
:
7511 case SPOOLSS_JOB_CONTROL_RESUME
:
7512 errcode
= print_job_resume(session_info
, p
->msg_ctx
,
7513 snum
, r
->in
.job_id
);
7519 return WERR_UNKNOWN_LEVEL
;
7522 if (!W_ERROR_IS_OK(errcode
)) {
7526 if (r
->in
.ctr
== NULL
) {
7530 switch (r
->in
.ctr
->level
) {
7532 errcode
= spoolss_setjob_1(p
->mem_ctx
, p
->msg_ctx
,
7533 lp_const_servicename(snum
),
7535 r
->in
.ctr
->info
.info1
);
7541 return WERR_UNKNOWN_LEVEL
;
7547 /****************************************************************************
7548 Enumerates all printer drivers by level and architecture.
7549 ****************************************************************************/
7551 static WERROR
enumprinterdrivers_level_by_architecture(TALLOC_CTX
*mem_ctx
,
7552 const struct auth_session_info
*session_info
,
7553 struct messaging_context
*msg_ctx
,
7554 const char *servername
,
7555 const char *architecture
,
7557 union spoolss_DriverInfo
**info_p
,
7562 struct spoolss_DriverInfo8
*driver
;
7563 union spoolss_DriverInfo
*info
= NULL
;
7565 WERROR result
= WERR_OK
;
7566 uint32_t num_drivers
;
7567 const char **drivers
;
7568 struct dcerpc_binding_handle
*b
;
7569 TALLOC_CTX
*tmp_ctx
= NULL
;
7574 tmp_ctx
= talloc_new(mem_ctx
);
7579 result
= winreg_printer_binding_handle(tmp_ctx
,
7583 if (!W_ERROR_IS_OK(result
)) {
7587 for (version
=0; version
<DRIVER_MAX_VERSION
; version
++) {
7588 result
= winreg_get_driver_list(tmp_ctx
, b
,
7589 architecture
, version
,
7590 &num_drivers
, &drivers
);
7591 if (!W_ERROR_IS_OK(result
)) {
7594 DEBUG(4, ("we have:[%d] drivers in environment"
7595 " [%s] and version [%d]\n",
7596 num_drivers
, architecture
, version
));
7598 if (num_drivers
!= 0) {
7599 info
= talloc_realloc(tmp_ctx
, info
,
7600 union spoolss_DriverInfo
,
7601 count
+ num_drivers
);
7603 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
7604 "failed to enlarge driver info buffer!\n"));
7605 result
= WERR_NOMEM
;
7610 for (i
= 0; i
< num_drivers
; i
++) {
7611 DEBUG(5, ("\tdriver: [%s]\n", drivers
[i
]));
7613 result
= winreg_get_driver(tmp_ctx
, b
,
7614 architecture
, drivers
[i
],
7616 if (!W_ERROR_IS_OK(result
)) {
7622 result
= fill_printer_driver_info1(info
, &info
[count
+i
].info1
,
7623 driver
, servername
);
7626 result
= fill_printer_driver_info2(info
, &info
[count
+i
].info2
,
7627 driver
, servername
);
7630 result
= fill_printer_driver_info3(info
, &info
[count
+i
].info3
,
7631 driver
, servername
);
7634 result
= fill_printer_driver_info4(info
, &info
[count
+i
].info4
,
7635 driver
, servername
);
7638 result
= fill_printer_driver_info5(info
, &info
[count
+i
].info5
,
7639 driver
, servername
);
7642 result
= fill_printer_driver_info6(info
, &info
[count
+i
].info6
,
7643 driver
, servername
);
7646 result
= fill_printer_driver_info8(info
, &info
[count
+i
].info8
,
7647 driver
, servername
);
7650 result
= WERR_UNKNOWN_LEVEL
;
7654 TALLOC_FREE(driver
);
7656 if (!W_ERROR_IS_OK(result
)) {
7661 count
+= num_drivers
;
7662 TALLOC_FREE(drivers
);
7666 if (W_ERROR_IS_OK(result
)) {
7667 *info_p
= talloc_move(mem_ctx
, &info
);
7671 talloc_free(tmp_ctx
);
7675 /****************************************************************************
7676 Enumerates all printer drivers by level.
7677 ****************************************************************************/
7679 static WERROR
enumprinterdrivers_level(TALLOC_CTX
*mem_ctx
,
7680 const struct auth_session_info
*session_info
,
7681 struct messaging_context
*msg_ctx
,
7682 const char *servername
,
7683 const char *architecture
,
7685 union spoolss_DriverInfo
**info_p
,
7689 WERROR result
= WERR_OK
;
7691 if (strequal(architecture
, SPOOLSS_ARCHITECTURE_ALL
)) {
7693 for (a
=0; archi_table
[a
].long_archi
!= NULL
; a
++) {
7695 union spoolss_DriverInfo
*info
= NULL
;
7698 result
= enumprinterdrivers_level_by_architecture(mem_ctx
,
7702 archi_table
[a
].long_archi
,
7706 if (!W_ERROR_IS_OK(result
)) {
7710 for (i
=0; i
< count
; i
++) {
7711 ADD_TO_ARRAY(mem_ctx
, union spoolss_DriverInfo
,
7712 info
[i
], info_p
, count_p
);
7719 return enumprinterdrivers_level_by_architecture(mem_ctx
,
7729 /****************************************************************
7730 _spoolss_EnumPrinterDrivers
7731 ****************************************************************/
7733 WERROR
_spoolss_EnumPrinterDrivers(struct pipes_struct
*p
,
7734 struct spoolss_EnumPrinterDrivers
*r
)
7736 const char *cservername
;
7739 /* that's an [in out] buffer */
7741 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
7742 return WERR_INVALID_PARAM
;
7745 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
7749 *r
->out
.info
= NULL
;
7751 cservername
= canon_servername(r
->in
.server
);
7753 if (!is_myname_or_ipaddr(cservername
)) {
7754 return WERR_UNKNOWN_PRINTER_DRIVER
;
7757 result
= enumprinterdrivers_level(p
->mem_ctx
,
7758 get_session_info_system(),
7765 if (!W_ERROR_IS_OK(result
)) {
7769 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
7770 spoolss_EnumPrinterDrivers
,
7771 *r
->out
.info
, r
->in
.level
,
7773 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
7774 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
7776 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
7779 /****************************************************************
7781 ****************************************************************/
7783 WERROR
_spoolss_EnumForms(struct pipes_struct
*p
,
7784 struct spoolss_EnumForms
*r
)
7790 *r
->out
.info
= NULL
;
7792 /* that's an [in out] buffer */
7794 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0) ) {
7795 return WERR_INVALID_PARAM
;
7798 DEBUG(4,("_spoolss_EnumForms\n"));
7799 DEBUGADD(5,("Offered buffer size [%d]\n", r
->in
.offered
));
7800 DEBUGADD(5,("Info level [%d]\n", r
->in
.level
));
7802 switch (r
->in
.level
) {
7804 result
= winreg_printer_enumforms1_internal(p
->mem_ctx
,
7805 get_session_info_system(),
7811 result
= WERR_UNKNOWN_LEVEL
;
7815 if (!W_ERROR_IS_OK(result
)) {
7819 if (*r
->out
.count
== 0) {
7820 return WERR_NO_MORE_ITEMS
;
7823 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
7825 *r
->out
.info
, r
->in
.level
,
7827 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
7828 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
7830 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
7833 /****************************************************************
7835 ****************************************************************/
7837 WERROR
_spoolss_GetForm(struct pipes_struct
*p
,
7838 struct spoolss_GetForm
*r
)
7842 /* that's an [in out] buffer */
7844 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
7845 return WERR_INVALID_PARAM
;
7848 DEBUG(4,("_spoolss_GetForm\n"));
7849 DEBUGADD(5,("Offered buffer size [%d]\n", r
->in
.offered
));
7850 DEBUGADD(5,("Info level [%d]\n", r
->in
.level
));
7852 switch (r
->in
.level
) {
7854 result
= winreg_printer_getform1_internal(p
->mem_ctx
,
7855 get_session_info_system(),
7858 &r
->out
.info
->info1
);
7861 result
= WERR_UNKNOWN_LEVEL
;
7865 if (!W_ERROR_IS_OK(result
)) {
7866 TALLOC_FREE(r
->out
.info
);
7870 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_FormInfo
,
7871 r
->out
.info
, r
->in
.level
);
7872 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
7874 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
7877 /****************************************************************************
7878 ****************************************************************************/
7880 static WERROR
fill_port_1(TALLOC_CTX
*mem_ctx
,
7881 struct spoolss_PortInfo1
*r
,
7884 r
->port_name
= talloc_strdup(mem_ctx
, name
);
7885 W_ERROR_HAVE_NO_MEMORY(r
->port_name
);
7890 /****************************************************************************
7891 TODO: This probably needs distinguish between TCP/IP and Local ports
7893 ****************************************************************************/
7895 static WERROR
fill_port_2(TALLOC_CTX
*mem_ctx
,
7896 struct spoolss_PortInfo2
*r
,
7899 r
->port_name
= talloc_strdup(mem_ctx
, name
);
7900 W_ERROR_HAVE_NO_MEMORY(r
->port_name
);
7902 r
->monitor_name
= talloc_strdup(mem_ctx
, "Local Monitor");
7903 W_ERROR_HAVE_NO_MEMORY(r
->monitor_name
);
7905 r
->description
= talloc_strdup(mem_ctx
, SPL_LOCAL_PORT
);
7906 W_ERROR_HAVE_NO_MEMORY(r
->description
);
7908 r
->port_type
= SPOOLSS_PORT_TYPE_WRITE
;
7915 /****************************************************************************
7916 wrapper around the enumer ports command
7917 ****************************************************************************/
7919 static WERROR
enumports_hook(TALLOC_CTX
*ctx
, int *count
, char ***lines
)
7921 char *cmd
= lp_enumports_cmd(talloc_tos());
7922 char **qlines
= NULL
;
7923 char *command
= NULL
;
7931 /* if no hook then just fill in the default port */
7934 if (!(qlines
= talloc_array( NULL
, char*, 2 ))) {
7937 if (!(qlines
[0] = talloc_strdup(qlines
, SAMBA_PRINTER_PORT_NAME
))) {
7938 TALLOC_FREE(qlines
);
7945 /* we have a valid enumport command */
7947 command
= talloc_asprintf(ctx
, "%s \"%d\"", cmd
, 1);
7952 DEBUG(10,("Running [%s]\n", command
));
7953 ret
= smbrun(command
, &fd
);
7954 DEBUG(10,("Returned [%d]\n", ret
));
7955 TALLOC_FREE(command
);
7960 return WERR_ACCESS_DENIED
;
7964 qlines
= fd_lines_load(fd
, &numlines
, 0, NULL
);
7965 DEBUGADD(10,("Lines returned = [%d]\n", numlines
));
7975 /****************************************************************************
7977 ****************************************************************************/
7979 static WERROR
enumports_level_1(TALLOC_CTX
*mem_ctx
,
7980 union spoolss_PortInfo
**info_p
,
7983 union spoolss_PortInfo
*info
= NULL
;
7985 WERROR result
= WERR_OK
;
7986 char **qlines
= NULL
;
7989 result
= enumports_hook(talloc_tos(), &numlines
, &qlines
);
7990 if (!W_ERROR_IS_OK(result
)) {
7995 info
= talloc_array(mem_ctx
, union spoolss_PortInfo
, numlines
);
7997 DEBUG(10,("Returning WERR_NOMEM\n"));
7998 result
= WERR_NOMEM
;
8002 for (i
=0; i
<numlines
; i
++) {
8003 DEBUG(6,("Filling port number [%d] with port [%s]\n", i
, qlines
[i
]));
8004 result
= fill_port_1(info
, &info
[i
].info1
, qlines
[i
]);
8005 if (!W_ERROR_IS_OK(result
)) {
8010 TALLOC_FREE(qlines
);
8013 if (!W_ERROR_IS_OK(result
)) {
8015 TALLOC_FREE(qlines
);
8027 /****************************************************************************
8029 ****************************************************************************/
8031 static WERROR
enumports_level_2(TALLOC_CTX
*mem_ctx
,
8032 union spoolss_PortInfo
**info_p
,
8035 union spoolss_PortInfo
*info
= NULL
;
8037 WERROR result
= WERR_OK
;
8038 char **qlines
= NULL
;
8041 result
= enumports_hook(talloc_tos(), &numlines
, &qlines
);
8042 if (!W_ERROR_IS_OK(result
)) {
8047 info
= talloc_array(mem_ctx
, union spoolss_PortInfo
, numlines
);
8049 DEBUG(10,("Returning WERR_NOMEM\n"));
8050 result
= WERR_NOMEM
;
8054 for (i
=0; i
<numlines
; i
++) {
8055 DEBUG(6,("Filling port number [%d] with port [%s]\n", i
, qlines
[i
]));
8056 result
= fill_port_2(info
, &info
[i
].info2
, qlines
[i
]);
8057 if (!W_ERROR_IS_OK(result
)) {
8062 TALLOC_FREE(qlines
);
8065 if (!W_ERROR_IS_OK(result
)) {
8067 TALLOC_FREE(qlines
);
8079 /****************************************************************
8081 ****************************************************************/
8083 WERROR
_spoolss_EnumPorts(struct pipes_struct
*p
,
8084 struct spoolss_EnumPorts
*r
)
8088 /* that's an [in out] buffer */
8090 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
8091 return WERR_INVALID_PARAM
;
8094 DEBUG(4,("_spoolss_EnumPorts\n"));
8098 *r
->out
.info
= NULL
;
8100 switch (r
->in
.level
) {
8102 result
= enumports_level_1(p
->mem_ctx
, r
->out
.info
,
8106 result
= enumports_level_2(p
->mem_ctx
, r
->out
.info
,
8110 return WERR_UNKNOWN_LEVEL
;
8113 if (!W_ERROR_IS_OK(result
)) {
8117 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
8119 *r
->out
.info
, r
->in
.level
,
8121 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
8122 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
8124 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
8127 /****************************************************************************
8128 ****************************************************************************/
8130 static WERROR
spoolss_addprinterex_level_2(struct pipes_struct
*p
,
8132 struct spoolss_SetPrinterInfoCtr
*info_ctr
,
8133 struct spoolss_DeviceMode
*devmode
,
8134 struct security_descriptor
*secdesc
,
8135 struct spoolss_UserLevelCtr
*user_ctr
,
8136 struct policy_handle
*handle
)
8138 struct spoolss_SetPrinterInfo2
*info2
= info_ctr
->info
.info2
;
8139 uint32_t info2_mask
= SPOOLSS_PRINTER_INFO_ALL
;
8141 WERROR err
= WERR_OK
;
8143 /* samba does not have a concept of local, non-shared printers yet, so
8144 * make sure we always setup sharename - gd */
8145 if ((info2
->sharename
== NULL
|| info2
->sharename
[0] == '\0') &&
8146 (info2
->printername
!= NULL
&& info2
->printername
[0] != '\0')) {
8147 DEBUG(5, ("spoolss_addprinterex_level_2: "
8148 "no sharename has been set, setting printername %s as sharename\n",
8149 info2
->printername
));
8150 info2
->sharename
= info2
->printername
;
8153 /* check to see if the printer already exists */
8154 if ((snum
= print_queue_snum(info2
->sharename
)) != -1) {
8155 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
8157 return WERR_PRINTER_ALREADY_EXISTS
;
8160 if (!lp_force_printername(GLOBAL_SECTION_SNUM
)) {
8161 if ((snum
= print_queue_snum(info2
->printername
)) != -1) {
8162 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
8163 info2
->printername
));
8164 return WERR_PRINTER_ALREADY_EXISTS
;
8168 /* validate printer info struct */
8169 if (!info2
->printername
|| strlen(info2
->printername
) == 0) {
8170 return WERR_INVALID_PRINTER_NAME
;
8172 if (!info2
->portname
|| strlen(info2
->portname
) == 0) {
8173 return WERR_UNKNOWN_PORT
;
8175 if (!info2
->drivername
|| strlen(info2
->drivername
) == 0) {
8176 return WERR_UNKNOWN_PRINTER_DRIVER
;
8178 if (!info2
->printprocessor
|| strlen(info2
->printprocessor
) == 0) {
8179 return WERR_UNKNOWN_PRINTPROCESSOR
;
8182 /* FIXME!!! smbd should check to see if the driver is installed before
8183 trying to add a printer like this --jerry */
8185 if (*lp_addprinter_cmd(talloc_tos()) ) {
8188 raddr
= tsocket_address_inet_addr_string(p
->remote_address
,
8190 if (raddr
== NULL
) {
8194 if ( !add_printer_hook(p
->mem_ctx
, p
->session_info
->security_token
,
8197 return WERR_ACCESS_DENIED
;
8200 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no "
8201 "smb.conf parameter \"addprinter command\" is defined. This "
8202 "parameter must exist for this call to succeed\n",
8203 info2
->sharename
));
8206 if ((snum
= print_queue_snum(info2
->sharename
)) == -1) {
8207 return WERR_ACCESS_DENIED
;
8210 /* you must be a printer admin to add a new printer */
8211 if (!print_access_check(p
->session_info
,
8214 PRINTER_ACCESS_ADMINISTER
)) {
8215 return WERR_ACCESS_DENIED
;
8219 * Do sanity check on the requested changes for Samba.
8222 if (!check_printer_ok(p
->mem_ctx
, info2
, snum
)) {
8223 return WERR_INVALID_PARAM
;
8226 if (devmode
== NULL
) {
8227 info2_mask
= ~SPOOLSS_PRINTER_INFO_DEVMODE
;
8230 err
= update_dsspooler(p
->mem_ctx
,
8231 get_session_info_system(),
8236 if (!W_ERROR_IS_OK(err
)) {
8240 err
= winreg_update_printer_internal(p
->mem_ctx
,
8241 get_session_info_system(),
8248 if (!W_ERROR_IS_OK(err
)) {
8252 err
= open_printer_hnd(p
, handle
, info2
->printername
, PRINTER_ACCESS_ADMINISTER
);
8253 if (!W_ERROR_IS_OK(err
)) {
8254 /* Handle open failed - remove addition. */
8255 ZERO_STRUCTP(handle
);
8262 /****************************************************************
8263 _spoolss_AddPrinterEx
8264 ****************************************************************/
8266 WERROR
_spoolss_AddPrinterEx(struct pipes_struct
*p
,
8267 struct spoolss_AddPrinterEx
*r
)
8269 switch (r
->in
.info_ctr
->level
) {
8271 /* we don't handle yet */
8272 /* but I know what to do ... */
8273 return WERR_UNKNOWN_LEVEL
;
8275 return spoolss_addprinterex_level_2(p
, r
->in
.server
,
8277 r
->in
.devmode_ctr
->devmode
,
8278 r
->in
.secdesc_ctr
->sd
,
8279 r
->in
.userlevel_ctr
,
8282 return WERR_UNKNOWN_LEVEL
;
8286 /****************************************************************
8288 ****************************************************************/
8290 WERROR
_spoolss_AddPrinter(struct pipes_struct
*p
,
8291 struct spoolss_AddPrinter
*r
)
8293 struct spoolss_AddPrinterEx a
;
8294 struct spoolss_UserLevelCtr userlevel_ctr
;
8296 ZERO_STRUCT(userlevel_ctr
);
8298 userlevel_ctr
.level
= 1;
8300 a
.in
.server
= r
->in
.server
;
8301 a
.in
.info_ctr
= r
->in
.info_ctr
;
8302 a
.in
.devmode_ctr
= r
->in
.devmode_ctr
;
8303 a
.in
.secdesc_ctr
= r
->in
.secdesc_ctr
;
8304 a
.in
.userlevel_ctr
= &userlevel_ctr
;
8305 a
.out
.handle
= r
->out
.handle
;
8307 return _spoolss_AddPrinterEx(p
, &a
);
8310 /****************************************************************
8311 _spoolss_AddPrinterDriverEx
8312 ****************************************************************/
8314 WERROR
_spoolss_AddPrinterDriverEx(struct pipes_struct
*p
,
8315 struct spoolss_AddPrinterDriverEx
*r
)
8317 WERROR err
= WERR_OK
;
8318 const char *driver_name
= NULL
;
8323 case NDR_SPOOLSS_ADDPRINTERDRIVER
:
8324 fn
= "_spoolss_AddPrinterDriver";
8326 case NDR_SPOOLSS_ADDPRINTERDRIVEREX
:
8327 fn
= "_spoolss_AddPrinterDriverEx";
8330 return WERR_INVALID_PARAM
;
8334 * we only support the semantics of AddPrinterDriver()
8335 * i.e. only copy files that are newer than existing ones
8338 if (r
->in
.flags
== 0) {
8339 return WERR_INVALID_PARAM
;
8342 if (r
->in
.flags
!= APD_COPY_NEW_FILES
) {
8343 return WERR_ACCESS_DENIED
;
8347 if (r
->in
.info_ctr
->level
!= 3 && r
->in
.info_ctr
->level
!= 6) {
8348 /* Clever hack from Martin Zielinski <mz@seh.de>
8349 * to allow downgrade from level 8 (Vista).
8351 DEBUG(0,("%s: level %d not yet implemented\n", fn
,
8352 r
->in
.info_ctr
->level
));
8353 return WERR_UNKNOWN_LEVEL
;
8356 DEBUG(5,("Cleaning driver's information\n"));
8357 err
= clean_up_driver_struct(p
->mem_ctx
, p
->session_info
, r
->in
.info_ctr
);
8358 if (!W_ERROR_IS_OK(err
))
8361 DEBUG(5,("Moving driver to final destination\n"));
8362 err
= move_driver_to_download_area(p
->session_info
, r
->in
.info_ctr
);
8363 if (!W_ERROR_IS_OK(err
)) {
8367 err
= winreg_add_driver_internal(p
->mem_ctx
,
8368 get_session_info_system(),
8373 if (!W_ERROR_IS_OK(err
)) {
8378 * I think this is where he DrvUpgradePrinter() hook would be
8379 * be called in a driver's interface DLL on a Windows NT 4.0/2k
8380 * server. Right now, we just need to send ourselves a message
8381 * to update each printer bound to this driver. --jerry
8384 if (!srv_spoolss_drv_upgrade_printer(driver_name
, p
->msg_ctx
)) {
8385 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
8393 /****************************************************************
8394 _spoolss_AddPrinterDriver
8395 ****************************************************************/
8397 WERROR
_spoolss_AddPrinterDriver(struct pipes_struct
*p
,
8398 struct spoolss_AddPrinterDriver
*r
)
8400 struct spoolss_AddPrinterDriverEx a
;
8402 switch (r
->in
.info_ctr
->level
) {
8409 return WERR_UNKNOWN_LEVEL
;
8412 a
.in
.servername
= r
->in
.servername
;
8413 a
.in
.info_ctr
= r
->in
.info_ctr
;
8414 a
.in
.flags
= APD_COPY_NEW_FILES
;
8416 return _spoolss_AddPrinterDriverEx(p
, &a
);
8419 /****************************************************************************
8420 ****************************************************************************/
8422 struct _spoolss_paths
{
8428 enum { SPOOLSS_DRIVER_PATH
, SPOOLSS_PRTPROCS_PATH
};
8430 static const struct _spoolss_paths spoolss_paths
[]= {
8431 { SPOOLSS_DRIVER_PATH
, "print$", "DRIVERS" },
8432 { SPOOLSS_PRTPROCS_PATH
, "prnproc$", "PRTPROCS" }
8435 static WERROR
compose_spoolss_server_path(TALLOC_CTX
*mem_ctx
,
8436 const char *servername
,
8437 const char *environment
,
8441 const char *pservername
= NULL
;
8442 const char *long_archi
;
8443 const char *short_archi
;
8447 /* environment may be empty */
8448 if (environment
&& strlen(environment
)) {
8449 long_archi
= environment
;
8451 long_archi
= lp_parm_const_string(GLOBAL_SECTION_SNUM
,
8452 "spoolss", "architecture",
8453 SPOOLSS_ARCHITECTURE_NT_X86
);
8456 /* servername may be empty */
8457 if (servername
&& strlen(servername
)) {
8458 pservername
= canon_servername(servername
);
8460 if (!is_myname_or_ipaddr(pservername
)) {
8461 return WERR_INVALID_PARAM
;
8465 if (!(short_archi
= get_short_archi(long_archi
))) {
8466 return WERR_INVALID_ENVIRONMENT
;
8469 switch (component
) {
8470 case SPOOLSS_PRTPROCS_PATH
:
8471 case SPOOLSS_DRIVER_PATH
:
8473 *path
= talloc_asprintf(mem_ctx
,
8476 spoolss_paths
[component
].share
,
8479 *path
= talloc_asprintf(mem_ctx
, "%s\\%s\\%s",
8480 SPOOLSS_DEFAULT_SERVER_PATH
,
8481 spoolss_paths
[component
].dir
,
8486 return WERR_INVALID_PARAM
;
8496 /****************************************************************************
8497 ****************************************************************************/
8499 static WERROR
getprinterdriverdir_level_1(TALLOC_CTX
*mem_ctx
,
8500 const char *servername
,
8501 const char *environment
,
8502 struct spoolss_DriverDirectoryInfo1
*r
)
8507 werr
= compose_spoolss_server_path(mem_ctx
,
8510 SPOOLSS_DRIVER_PATH
,
8512 if (!W_ERROR_IS_OK(werr
)) {
8516 DEBUG(4,("printer driver directory: [%s]\n", path
));
8518 r
->directory_name
= path
;
8523 /****************************************************************
8524 _spoolss_GetPrinterDriverDirectory
8525 ****************************************************************/
8527 WERROR
_spoolss_GetPrinterDriverDirectory(struct pipes_struct
*p
,
8528 struct spoolss_GetPrinterDriverDirectory
*r
)
8532 /* that's an [in out] buffer */
8534 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
8535 return WERR_INVALID_PARAM
;
8538 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
8543 /* r->in.level is ignored */
8545 werror
= getprinterdriverdir_level_1(p
->mem_ctx
,
8548 &r
->out
.info
->info1
);
8549 if (!W_ERROR_IS_OK(werror
)) {
8550 TALLOC_FREE(r
->out
.info
);
8554 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo
,
8555 r
->out
.info
, r
->in
.level
);
8556 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
8558 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
8561 /****************************************************************
8562 _spoolss_EnumPrinterData
8563 ****************************************************************/
8565 WERROR
_spoolss_EnumPrinterData(struct pipes_struct
*p
,
8566 struct spoolss_EnumPrinterData
*r
)
8569 struct spoolss_EnumPrinterDataEx r2
;
8571 struct spoolss_PrinterEnumValues
*info
, *val
= NULL
;
8574 r2
.in
.handle
= r
->in
.handle
;
8575 r2
.in
.key_name
= "PrinterDriverData";
8577 r2
.out
.count
= &count
;
8578 r2
.out
.info
= &info
;
8579 r2
.out
.needed
= &needed
;
8581 result
= _spoolss_EnumPrinterDataEx(p
, &r2
);
8582 if (W_ERROR_EQUAL(result
, WERR_MORE_DATA
)) {
8583 r2
.in
.offered
= needed
;
8584 result
= _spoolss_EnumPrinterDataEx(p
, &r2
);
8586 if (!W_ERROR_IS_OK(result
)) {
8591 * The NT machine wants to know the biggest size of value and data
8593 * cf: MSDN EnumPrinterData remark section
8596 if (!r
->in
.value_offered
&& !r
->in
.data_offered
) {
8597 uint32_t biggest_valuesize
= 0;
8598 uint32_t biggest_datasize
= 0;
8601 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
8603 for (i
=0; i
<count
; i
++) {
8605 name_length
= strlen(info
[i
].value_name
);
8606 if (strlen(info
[i
].value_name
) > biggest_valuesize
) {
8607 biggest_valuesize
= name_length
;
8610 if (info
[i
].data_length
> biggest_datasize
) {
8611 biggest_datasize
= info
[i
].data_length
;
8614 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize
,
8618 /* the value is an UNICODE string but real_value_size is the length
8619 in bytes including the trailing 0 */
8621 *r
->out
.value_needed
= 2 * (1 + biggest_valuesize
);
8622 *r
->out
.data_needed
= biggest_datasize
;
8624 DEBUG(6,("final values: [%d], [%d]\n",
8625 *r
->out
.value_needed
, *r
->out
.data_needed
));
8630 if (r
->in
.enum_index
< count
) {
8631 val
= &info
[r
->in
.enum_index
];
8635 /* out_value should default to "" or else NT4 has
8636 problems unmarshalling the response */
8638 if (r
->in
.value_offered
) {
8639 *r
->out
.value_needed
= 1;
8640 r
->out
.value_name
= talloc_strdup(r
, "");
8641 if (!r
->out
.value_name
) {
8645 r
->out
.value_name
= NULL
;
8646 *r
->out
.value_needed
= 0;
8649 /* the data is counted in bytes */
8651 *r
->out
.data_needed
= r
->in
.data_offered
;
8653 result
= WERR_NO_MORE_ITEMS
;
8657 * - counted in bytes in the request
8658 * - counted in UNICODE chars in the max reply
8659 * - counted in bytes in the real size
8661 * take a pause *before* coding not *during* coding
8665 if (r
->in
.value_offered
) {
8666 r
->out
.value_name
= talloc_strdup(r
, val
->value_name
);
8667 if (!r
->out
.value_name
) {
8670 *r
->out
.value_needed
= val
->value_name_len
;
8672 r
->out
.value_name
= NULL
;
8673 *r
->out
.value_needed
= 0;
8678 *r
->out
.type
= val
->type
;
8680 /* data - counted in bytes */
8683 * See the section "Dynamically Typed Query Parameters"
8687 if (r
->out
.data
&& val
->data
&& val
->data
->data
&&
8688 val
->data_length
&& r
->in
.data_offered
) {
8689 memcpy(r
->out
.data
, val
->data
->data
,
8690 MIN(val
->data_length
,r
->in
.data_offered
));
8693 *r
->out
.data_needed
= val
->data_length
;
8701 /****************************************************************
8702 _spoolss_SetPrinterData
8703 ****************************************************************/
8705 WERROR
_spoolss_SetPrinterData(struct pipes_struct
*p
,
8706 struct spoolss_SetPrinterData
*r
)
8708 struct spoolss_SetPrinterDataEx r2
;
8710 r2
.in
.handle
= r
->in
.handle
;
8711 r2
.in
.key_name
= "PrinterDriverData";
8712 r2
.in
.value_name
= r
->in
.value_name
;
8713 r2
.in
.type
= r
->in
.type
;
8714 r2
.in
.data
= r
->in
.data
;
8715 r2
.in
.offered
= r
->in
.offered
;
8717 return _spoolss_SetPrinterDataEx(p
, &r2
);
8720 /****************************************************************
8721 _spoolss_ResetPrinter
8722 ****************************************************************/
8724 WERROR
_spoolss_ResetPrinter(struct pipes_struct
*p
,
8725 struct spoolss_ResetPrinter
*r
)
8727 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
8730 DEBUG(5,("_spoolss_ResetPrinter\n"));
8733 * All we do is to check to see if the handle and queue is valid.
8734 * This call really doesn't mean anything to us because we only
8735 * support RAW printing. --jerry
8739 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
8740 OUR_HANDLE(r
->in
.handle
)));
8744 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
))
8748 /* blindly return success */
8752 /****************************************************************
8753 _spoolss_DeletePrinterData
8754 ****************************************************************/
8756 WERROR
_spoolss_DeletePrinterData(struct pipes_struct
*p
,
8757 struct spoolss_DeletePrinterData
*r
)
8759 struct spoolss_DeletePrinterDataEx r2
;
8761 r2
.in
.handle
= r
->in
.handle
;
8762 r2
.in
.key_name
= "PrinterDriverData";
8763 r2
.in
.value_name
= r
->in
.value_name
;
8765 return _spoolss_DeletePrinterDataEx(p
, &r2
);
8768 /****************************************************************
8770 ****************************************************************/
8772 WERROR
_spoolss_AddForm(struct pipes_struct
*p
,
8773 struct spoolss_AddForm
*r
)
8775 struct spoolss_AddFormInfo1
*form
;
8777 WERROR status
= WERR_OK
;
8778 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
8779 struct dcerpc_binding_handle
*b
;
8780 TALLOC_CTX
*tmp_ctx
= NULL
;
8782 DEBUG(5,("_spoolss_AddForm\n"));
8785 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
8786 OUR_HANDLE(r
->in
.handle
)));
8790 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8791 and not a printer admin, then fail */
8793 if ((p
->session_info
->unix_token
->uid
!= sec_initial_uid()) &&
8794 !security_token_has_privilege(p
->session_info
->security_token
,
8795 SEC_PRIV_PRINT_OPERATOR
)) {
8796 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
8797 return WERR_ACCESS_DENIED
;
8800 if (r
->in
.info_ctr
->level
!= 1) {
8801 return WERR_INVALID_LEVEL
;
8804 form
= r
->in
.info_ctr
->info
.info1
;
8806 return WERR_INVALID_PARAM
;
8809 switch (form
->flags
) {
8810 case SPOOLSS_FORM_USER
:
8811 case SPOOLSS_FORM_BUILTIN
:
8812 case SPOOLSS_FORM_PRINTER
:
8815 return WERR_INVALID_PARAM
;
8818 tmp_ctx
= talloc_new(p
->mem_ctx
);
8823 status
= winreg_printer_binding_handle(tmp_ctx
,
8824 get_session_info_system(),
8827 if (!W_ERROR_IS_OK(status
)) {
8831 status
= winreg_printer_addform1(tmp_ctx
, b
, form
);
8832 if (!W_ERROR_IS_OK(status
)) {
8837 * ChangeID must always be set if this is a printer
8839 if (Printer
->printer_type
== SPLHND_PRINTER
) {
8840 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
8841 status
= WERR_BADFID
;
8845 status
= winreg_printer_update_changeid(tmp_ctx
, b
,
8846 lp_const_servicename(snum
));
8850 talloc_free(tmp_ctx
);
8854 /****************************************************************
8856 ****************************************************************/
8858 WERROR
_spoolss_DeleteForm(struct pipes_struct
*p
,
8859 struct spoolss_DeleteForm
*r
)
8861 const char *form_name
= r
->in
.form_name
;
8862 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
8864 WERROR status
= WERR_OK
;
8865 struct dcerpc_binding_handle
*b
;
8866 TALLOC_CTX
*tmp_ctx
= NULL
;
8868 DEBUG(5,("_spoolss_DeleteForm\n"));
8871 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
8872 OUR_HANDLE(r
->in
.handle
)));
8876 if ((p
->session_info
->unix_token
->uid
!= sec_initial_uid()) &&
8877 !security_token_has_privilege(p
->session_info
->security_token
,
8878 SEC_PRIV_PRINT_OPERATOR
)) {
8879 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
8880 return WERR_ACCESS_DENIED
;
8883 tmp_ctx
= talloc_new(p
->mem_ctx
);
8888 status
= winreg_printer_binding_handle(tmp_ctx
,
8889 get_session_info_system(),
8892 if (!W_ERROR_IS_OK(status
)) {
8896 status
= winreg_printer_deleteform1(tmp_ctx
, b
, form_name
);
8897 if (!W_ERROR_IS_OK(status
)) {
8902 * ChangeID must always be set if this is a printer
8904 if (Printer
->printer_type
== SPLHND_PRINTER
) {
8905 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
8906 status
= WERR_BADFID
;
8910 status
= winreg_printer_update_changeid(tmp_ctx
, b
,
8911 lp_const_servicename(snum
));
8915 talloc_free(tmp_ctx
);
8919 /****************************************************************
8921 ****************************************************************/
8923 WERROR
_spoolss_SetForm(struct pipes_struct
*p
,
8924 struct spoolss_SetForm
*r
)
8926 struct spoolss_AddFormInfo1
*form
;
8927 const char *form_name
= r
->in
.form_name
;
8929 WERROR status
= WERR_OK
;
8930 struct dcerpc_binding_handle
*b
;
8931 TALLOC_CTX
*tmp_ctx
= NULL
;
8933 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
8935 DEBUG(5,("_spoolss_SetForm\n"));
8938 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8939 OUR_HANDLE(r
->in
.handle
)));
8943 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8944 and not a printer admin, then fail */
8946 if ((p
->session_info
->unix_token
->uid
!= sec_initial_uid()) &&
8947 !security_token_has_privilege(p
->session_info
->security_token
,
8948 SEC_PRIV_PRINT_OPERATOR
)) {
8949 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
8950 return WERR_ACCESS_DENIED
;
8953 if (r
->in
.info_ctr
->level
!= 1) {
8954 return WERR_INVALID_LEVEL
;
8957 form
= r
->in
.info_ctr
->info
.info1
;
8959 return WERR_INVALID_PARAM
;
8962 tmp_ctx
= talloc_new(p
->mem_ctx
);
8967 status
= winreg_printer_binding_handle(tmp_ctx
,
8968 get_session_info_system(),
8971 if (!W_ERROR_IS_OK(status
)) {
8975 status
= winreg_printer_setform1(tmp_ctx
, b
,
8978 if (!W_ERROR_IS_OK(status
)) {
8983 * ChangeID must always be set if this is a printer
8985 if (Printer
->printer_type
== SPLHND_PRINTER
) {
8986 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
8987 status
= WERR_BADFID
;
8991 status
= winreg_printer_update_changeid(tmp_ctx
, b
,
8992 lp_const_servicename(snum
));
8996 talloc_free(tmp_ctx
);
9000 /****************************************************************************
9001 fill_print_processor1
9002 ****************************************************************************/
9004 static WERROR
fill_print_processor1(TALLOC_CTX
*mem_ctx
,
9005 struct spoolss_PrintProcessorInfo1
*r
,
9006 const char *print_processor_name
)
9008 r
->print_processor_name
= talloc_strdup(mem_ctx
, print_processor_name
);
9009 W_ERROR_HAVE_NO_MEMORY(r
->print_processor_name
);
9014 /****************************************************************************
9015 enumprintprocessors level 1.
9016 ****************************************************************************/
9018 static WERROR
enumprintprocessors_level_1(TALLOC_CTX
*mem_ctx
,
9019 union spoolss_PrintProcessorInfo
**info_p
,
9022 union spoolss_PrintProcessorInfo
*info
;
9025 info
= talloc_array(mem_ctx
, union spoolss_PrintProcessorInfo
, 1);
9026 W_ERROR_HAVE_NO_MEMORY(info
);
9030 result
= fill_print_processor1(info
, &info
[0].info1
, "winprint");
9031 if (!W_ERROR_IS_OK(result
)) {
9036 if (!W_ERROR_IS_OK(result
)) {
9047 /****************************************************************
9048 _spoolss_EnumPrintProcessors
9049 ****************************************************************/
9051 WERROR
_spoolss_EnumPrintProcessors(struct pipes_struct
*p
,
9052 struct spoolss_EnumPrintProcessors
*r
)
9056 /* that's an [in out] buffer */
9058 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
9059 return WERR_INVALID_PARAM
;
9062 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
9065 * Enumerate the print processors ...
9067 * Just reply with "winprint", to keep NT happy
9068 * and I can use my nice printer checker.
9073 *r
->out
.info
= NULL
;
9075 if (!get_short_archi(r
->in
.environment
)) {
9076 return WERR_INVALID_ENVIRONMENT
;
9079 switch (r
->in
.level
) {
9081 result
= enumprintprocessors_level_1(p
->mem_ctx
, r
->out
.info
,
9085 return WERR_UNKNOWN_LEVEL
;
9088 if (!W_ERROR_IS_OK(result
)) {
9092 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
9093 spoolss_EnumPrintProcessors
,
9094 *r
->out
.info
, r
->in
.level
,
9096 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
9097 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
9099 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
9102 /****************************************************************************
9103 fill_printprocdatatype1
9104 ****************************************************************************/
9106 static WERROR
fill_printprocdatatype1(TALLOC_CTX
*mem_ctx
,
9107 struct spoolss_PrintProcDataTypesInfo1
*r
,
9108 const char *name_array
)
9110 r
->name_array
= talloc_strdup(mem_ctx
, name_array
);
9111 W_ERROR_HAVE_NO_MEMORY(r
->name_array
);
9116 /****************************************************************************
9117 enumprintprocdatatypes level 1.
9118 ****************************************************************************/
9120 static WERROR
enumprintprocdatatypes_level_1(TALLOC_CTX
*mem_ctx
,
9121 union spoolss_PrintProcDataTypesInfo
**info_p
,
9125 union spoolss_PrintProcDataTypesInfo
*info
;
9127 info
= talloc_array(mem_ctx
, union spoolss_PrintProcDataTypesInfo
, 1);
9128 W_ERROR_HAVE_NO_MEMORY(info
);
9132 result
= fill_printprocdatatype1(info
, &info
[0].info1
, "RAW");
9133 if (!W_ERROR_IS_OK(result
)) {
9138 if (!W_ERROR_IS_OK(result
)) {
9149 /****************************************************************
9150 _spoolss_EnumPrintProcDataTypes
9151 ****************************************************************/
9153 WERROR
_spoolss_EnumPrintProcDataTypes(struct pipes_struct
*p
,
9154 struct spoolss_EnumPrintProcDataTypes
*r
)
9158 /* that's an [in out] buffer */
9160 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
9161 return WERR_INVALID_PARAM
;
9164 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
9168 *r
->out
.info
= NULL
;
9170 if (r
->in
.print_processor_name
== NULL
||
9171 !strequal(r
->in
.print_processor_name
, "winprint")) {
9172 return WERR_UNKNOWN_PRINTPROCESSOR
;
9175 switch (r
->in
.level
) {
9177 result
= enumprintprocdatatypes_level_1(p
->mem_ctx
, r
->out
.info
,
9181 return WERR_UNKNOWN_LEVEL
;
9184 if (!W_ERROR_IS_OK(result
)) {
9188 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
9189 spoolss_EnumPrintProcDataTypes
,
9190 *r
->out
.info
, r
->in
.level
,
9192 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
9193 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
9195 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
9198 /****************************************************************************
9200 ****************************************************************************/
9202 static WERROR
fill_monitor_1(TALLOC_CTX
*mem_ctx
,
9203 struct spoolss_MonitorInfo1
*r
,
9204 const char *monitor_name
)
9206 r
->monitor_name
= talloc_strdup(mem_ctx
, monitor_name
);
9207 W_ERROR_HAVE_NO_MEMORY(r
->monitor_name
);
9212 /****************************************************************************
9214 ****************************************************************************/
9216 static WERROR
fill_monitor_2(TALLOC_CTX
*mem_ctx
,
9217 struct spoolss_MonitorInfo2
*r
,
9218 const char *monitor_name
,
9219 const char *environment
,
9220 const char *dll_name
)
9222 r
->monitor_name
= talloc_strdup(mem_ctx
, monitor_name
);
9223 W_ERROR_HAVE_NO_MEMORY(r
->monitor_name
);
9224 r
->environment
= talloc_strdup(mem_ctx
, environment
);
9225 W_ERROR_HAVE_NO_MEMORY(r
->environment
);
9226 r
->dll_name
= talloc_strdup(mem_ctx
, dll_name
);
9227 W_ERROR_HAVE_NO_MEMORY(r
->dll_name
);
9232 /****************************************************************************
9233 enumprintmonitors level 1.
9234 ****************************************************************************/
9236 static WERROR
enumprintmonitors_level_1(TALLOC_CTX
*mem_ctx
,
9237 union spoolss_MonitorInfo
**info_p
,
9240 union spoolss_MonitorInfo
*info
;
9241 WERROR result
= WERR_OK
;
9243 info
= talloc_array(mem_ctx
, union spoolss_MonitorInfo
, 2);
9244 W_ERROR_HAVE_NO_MEMORY(info
);
9248 result
= fill_monitor_1(info
, &info
[0].info1
,
9250 if (!W_ERROR_IS_OK(result
)) {
9254 result
= fill_monitor_1(info
, &info
[1].info1
,
9256 if (!W_ERROR_IS_OK(result
)) {
9261 if (!W_ERROR_IS_OK(result
)) {
9272 /****************************************************************************
9273 enumprintmonitors level 2.
9274 ****************************************************************************/
9276 static WERROR
enumprintmonitors_level_2(TALLOC_CTX
*mem_ctx
,
9277 union spoolss_MonitorInfo
**info_p
,
9280 union spoolss_MonitorInfo
*info
;
9281 WERROR result
= WERR_OK
;
9283 info
= talloc_array(mem_ctx
, union spoolss_MonitorInfo
, 2);
9284 W_ERROR_HAVE_NO_MEMORY(info
);
9288 result
= fill_monitor_2(info
, &info
[0].info2
,
9290 "Windows NT X86", /* FIXME */
9292 if (!W_ERROR_IS_OK(result
)) {
9296 result
= fill_monitor_2(info
, &info
[1].info2
,
9298 "Windows NT X86", /* FIXME */
9300 if (!W_ERROR_IS_OK(result
)) {
9305 if (!W_ERROR_IS_OK(result
)) {
9316 /****************************************************************
9317 _spoolss_EnumMonitors
9318 ****************************************************************/
9320 WERROR
_spoolss_EnumMonitors(struct pipes_struct
*p
,
9321 struct spoolss_EnumMonitors
*r
)
9325 /* that's an [in out] buffer */
9327 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
9328 return WERR_INVALID_PARAM
;
9331 DEBUG(5,("_spoolss_EnumMonitors\n"));
9334 * Enumerate the print monitors ...
9336 * Just reply with "Local Port", to keep NT happy
9337 * and I can use my nice printer checker.
9342 *r
->out
.info
= NULL
;
9344 switch (r
->in
.level
) {
9346 result
= enumprintmonitors_level_1(p
->mem_ctx
, r
->out
.info
,
9350 result
= enumprintmonitors_level_2(p
->mem_ctx
, r
->out
.info
,
9354 return WERR_UNKNOWN_LEVEL
;
9357 if (!W_ERROR_IS_OK(result
)) {
9361 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
9362 spoolss_EnumMonitors
,
9363 *r
->out
.info
, r
->in
.level
,
9365 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
9366 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
9368 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
9371 /****************************************************************************
9372 ****************************************************************************/
9374 static WERROR
getjob_level_1(TALLOC_CTX
*mem_ctx
,
9375 const print_queue_struct
*queue
,
9376 int count
, int snum
,
9377 struct spoolss_PrinterInfo2
*pinfo2
,
9380 struct spoolss_JobInfo1
*r
)
9385 for (i
=0; i
<count
; i
++) {
9386 if (queue
[i
].sysjob
== sysjob
) {
9392 if (found
== false) {
9393 /* NT treats not found as bad param... yet another bad choice */
9394 return WERR_INVALID_PARAM
;
9397 return fill_job_info1(mem_ctx
,
9406 /****************************************************************************
9407 ****************************************************************************/
9409 static WERROR
getjob_level_2(TALLOC_CTX
*mem_ctx
,
9410 const print_queue_struct
*queue
,
9411 int count
, int snum
,
9412 struct spoolss_PrinterInfo2
*pinfo2
,
9415 struct spoolss_JobInfo2
*r
)
9419 struct spoolss_DeviceMode
*devmode
;
9422 for (i
=0; i
<count
; i
++) {
9423 if (queue
[i
].sysjob
== sysjob
) {
9429 if (found
== false) {
9430 /* NT treats not found as bad param... yet another bad
9432 return WERR_INVALID_PARAM
;
9436 * if the print job does not have a DEVMODE associated with it,
9437 * just use the one for the printer. A NULL devicemode is not
9438 * a failure condition
9441 devmode
= print_job_devmode(mem_ctx
, lp_const_servicename(snum
), jobid
);
9443 result
= spoolss_create_default_devmode(mem_ctx
,
9444 pinfo2
->printername
,
9446 if (!W_ERROR_IS_OK(result
)) {
9447 DEBUG(3, ("Can't proceed w/o a devmode!"));
9452 return fill_job_info2(mem_ctx
,
9462 /****************************************************************
9464 ****************************************************************/
9466 WERROR
_spoolss_GetJob(struct pipes_struct
*p
,
9467 struct spoolss_GetJob
*r
)
9469 WERROR result
= WERR_OK
;
9470 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
9471 const char *svc_name
;
9475 struct tdb_print_db
*pdb
;
9476 print_queue_struct
*queue
= NULL
;
9477 print_status_struct prt_status
;
9479 /* that's an [in out] buffer */
9481 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
9482 result
= WERR_INVALID_PARAM
;
9483 goto err_jinfo_free
;
9486 DEBUG(5,("_spoolss_GetJob\n"));
9490 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9491 result
= WERR_BADFID
;
9492 goto err_jinfo_free
;
9495 svc_name
= lp_const_servicename(snum
);
9496 if (svc_name
== NULL
) {
9497 result
= WERR_INVALID_PARAM
;
9498 goto err_jinfo_free
;
9501 result
= winreg_get_printer_internal(p
->mem_ctx
,
9502 get_session_info_system(),
9506 if (!W_ERROR_IS_OK(result
)) {
9507 goto err_jinfo_free
;
9510 pdb
= get_print_db_byname(svc_name
);
9512 DEBUG(3, ("failed to get print db for svc %s\n", svc_name
));
9513 result
= WERR_INVALID_PARAM
;
9514 goto err_pinfo_free
;
9517 sysjob
= jobid_to_sysjob_pdb(pdb
, r
->in
.job_id
);
9518 release_print_db(pdb
);
9520 DEBUG(3, ("no sysjob for spoolss jobid %u\n", r
->in
.job_id
));
9521 result
= WERR_INVALID_PARAM
;
9522 goto err_pinfo_free
;
9525 count
= print_queue_status(p
->msg_ctx
, snum
, &queue
, &prt_status
);
9527 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
9528 count
, prt_status
.status
, prt_status
.message
));
9530 switch (r
->in
.level
) {
9532 result
= getjob_level_1(p
->mem_ctx
,
9533 queue
, count
, snum
, pinfo2
,
9534 r
->in
.job_id
, sysjob
,
9535 &r
->out
.info
->info1
);
9538 result
= getjob_level_2(p
->mem_ctx
,
9539 queue
, count
, snum
, pinfo2
,
9540 r
->in
.job_id
, sysjob
,
9541 &r
->out
.info
->info2
);
9544 result
= WERR_UNKNOWN_LEVEL
;
9549 TALLOC_FREE(pinfo2
);
9551 if (!W_ERROR_IS_OK(result
)) {
9552 goto err_jinfo_free
;
9555 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_JobInfo
, r
->out
.info
,
9557 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
9559 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
9562 TALLOC_FREE(pinfo2
);
9564 TALLOC_FREE(r
->out
.info
);
9568 /****************************************************************
9569 _spoolss_GetPrinterDataEx
9570 ****************************************************************/
9572 WERROR
_spoolss_GetPrinterDataEx(struct pipes_struct
*p
,
9573 struct spoolss_GetPrinterDataEx
*r
)
9576 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9577 const char *printer
;
9579 WERROR result
= WERR_OK
;
9581 enum winreg_Type val_type
= REG_NONE
;
9582 uint8_t *val_data
= NULL
;
9583 uint32_t val_size
= 0;
9584 struct dcerpc_binding_handle
*b
;
9585 TALLOC_CTX
*tmp_ctx
;
9587 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
9589 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
9590 r
->in
.key_name
, r
->in
.value_name
));
9592 /* in case of problem, return some default values */
9595 *r
->out
.type
= REG_NONE
;
9597 tmp_ctx
= talloc_new(p
->mem_ctx
);
9603 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9604 OUR_HANDLE(r
->in
.handle
)));
9605 result
= WERR_BADFID
;
9609 /* check to see if the keyname is valid */
9610 if (!strlen(r
->in
.key_name
)) {
9611 result
= WERR_INVALID_PARAM
;
9615 /* Is the handle to a printer or to the server? */
9617 if (Printer
->printer_type
== SPLHND_SERVER
) {
9619 union spoolss_PrinterData data
;
9621 result
= getprinterdata_printer_server(tmp_ctx
,
9625 if (!W_ERROR_IS_OK(result
)) {
9629 result
= push_spoolss_PrinterData(tmp_ctx
, &blob
,
9630 *r
->out
.type
, &data
);
9631 if (!W_ERROR_IS_OK(result
)) {
9635 *r
->out
.needed
= blob
.length
;
9637 if (r
->in
.offered
>= *r
->out
.needed
) {
9638 memcpy(r
->out
.data
, blob
.data
, blob
.length
);
9645 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9646 result
= WERR_BADFID
;
9649 printer
= lp_const_servicename(snum
);
9651 result
= winreg_printer_binding_handle(tmp_ctx
,
9652 get_session_info_system(),
9655 if (!W_ERROR_IS_OK(result
)) {
9659 /* XP sends this and wants the ChangeID value from PRINTER_INFO_0 */
9660 if (strequal(r
->in
.key_name
, SPOOL_PRINTERDATA_KEY
) &&
9661 strequal(r
->in
.value_name
, "ChangeId")) {
9662 *r
->out
.type
= REG_DWORD
;
9664 if (r
->in
.offered
>= *r
->out
.needed
) {
9665 uint32_t changeid
= 0;
9667 result
= winreg_printer_get_changeid(tmp_ctx
, b
,
9670 if (!W_ERROR_IS_OK(result
)) {
9674 SIVAL(r
->out
.data
, 0, changeid
);
9680 result
= winreg_get_printer_dataex(tmp_ctx
, b
,
9687 if (!W_ERROR_IS_OK(result
)) {
9691 *r
->out
.needed
= val_size
;
9692 *r
->out
.type
= val_type
;
9694 if (r
->in
.offered
>= *r
->out
.needed
) {
9695 memcpy(r
->out
.data
, val_data
, val_size
);
9699 /* NOTE: do not replace type when returning WERR_MORE_DATA */
9701 if (W_ERROR_IS_OK(result
)) {
9702 result
= SPOOLSS_BUFFER_OK(WERR_OK
, WERR_MORE_DATA
);
9705 talloc_free(tmp_ctx
);
9709 /****************************************************************
9710 _spoolss_SetPrinterDataEx
9711 ****************************************************************/
9713 WERROR
_spoolss_SetPrinterDataEx(struct pipes_struct
*p
,
9714 struct spoolss_SetPrinterDataEx
*r
)
9716 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
9718 WERROR result
= WERR_OK
;
9719 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9721 struct dcerpc_binding_handle
*b
;
9722 TALLOC_CTX
*tmp_ctx
;
9724 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
9726 /* From MSDN documentation of SetPrinterDataEx: pass request to
9727 SetPrinterData if key is "PrinterDriverData" */
9730 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9731 OUR_HANDLE(r
->in
.handle
)));
9735 if (Printer
->printer_type
== SPLHND_SERVER
) {
9736 DEBUG(10,("_spoolss_SetPrinterDataEx: "
9737 "Not implemented for server handles yet\n"));
9738 return WERR_INVALID_PARAM
;
9741 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9746 * Access check : NT returns "access denied" if you make a
9747 * SetPrinterData call without the necessary privildge.
9748 * we were originally returning OK if nothing changed
9749 * which made Win2k issue **a lot** of SetPrinterData
9750 * when connecting to a printer --jerry
9753 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
9754 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
9755 "change denied by handle access permissions\n"));
9756 return WERR_ACCESS_DENIED
;
9759 tmp_ctx
= talloc_new(p
->mem_ctx
);
9764 result
= winreg_printer_binding_handle(tmp_ctx
,
9765 get_session_info_system(),
9768 if (!W_ERROR_IS_OK(result
)) {
9772 result
= winreg_get_printer(tmp_ctx
, b
,
9773 lp_servicename(talloc_tos(), snum
),
9775 if (!W_ERROR_IS_OK(result
)) {
9779 /* check for OID in valuename */
9781 oid_string
= strchr(r
->in
.value_name
, ',');
9787 /* save the registry data */
9789 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
9797 if (W_ERROR_IS_OK(result
)) {
9798 /* save the OID if one was specified */
9800 char *str
= talloc_asprintf(tmp_ctx
, "%s\\%s",
9801 r
->in
.key_name
, SPOOL_OID_KEY
);
9803 result
= WERR_NOMEM
;
9808 * I'm not checking the status here on purpose. Don't know
9809 * if this is right, but I'm returning the status from the
9810 * previous set_printer_dataex() call. I have no idea if
9811 * this is right. --jerry
9813 winreg_set_printer_dataex(tmp_ctx
, b
,
9818 (uint8_t *) oid_string
,
9819 strlen(oid_string
) + 1);
9822 result
= winreg_printer_update_changeid(tmp_ctx
, b
,
9823 lp_const_servicename(snum
));
9828 talloc_free(tmp_ctx
);
9832 /****************************************************************
9833 _spoolss_DeletePrinterDataEx
9834 ****************************************************************/
9836 WERROR
_spoolss_DeletePrinterDataEx(struct pipes_struct
*p
,
9837 struct spoolss_DeletePrinterDataEx
*r
)
9839 const char *printer
;
9841 WERROR status
= WERR_OK
;
9842 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9844 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
9847 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
9848 "Invalid handle (%s:%u:%u).\n",
9849 OUR_HANDLE(r
->in
.handle
)));
9853 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
9854 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
9855 "printer properties change denied by handle\n"));
9856 return WERR_ACCESS_DENIED
;
9859 if (!r
->in
.value_name
|| !r
->in
.key_name
) {
9863 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9866 printer
= lp_const_servicename(snum
);
9868 status
= winreg_delete_printer_dataex_internal(p
->mem_ctx
,
9869 get_session_info_system(),
9874 if (W_ERROR_IS_OK(status
)) {
9875 status
= winreg_printer_update_changeid_internal(p
->mem_ctx
,
9876 get_session_info_system(),
9884 /****************************************************************
9885 _spoolss_EnumPrinterKey
9886 ****************************************************************/
9888 WERROR
_spoolss_EnumPrinterKey(struct pipes_struct
*p
,
9889 struct spoolss_EnumPrinterKey
*r
)
9892 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9894 WERROR result
= WERR_BADFILE
;
9895 const char **array
= NULL
;
9898 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
9901 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
9902 OUR_HANDLE(r
->in
.handle
)));
9906 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9910 result
= winreg_enum_printer_key_internal(p
->mem_ctx
,
9911 get_session_info_system(),
9913 lp_const_servicename(snum
),
9917 if (!W_ERROR_IS_OK(result
)) {
9921 if (!push_reg_multi_sz(p
->mem_ctx
, &blob
, array
)) {
9922 result
= WERR_NOMEM
;
9926 *r
->out
._ndr_size
= r
->in
.offered
/ 2;
9927 *r
->out
.needed
= blob
.length
;
9929 if (r
->in
.offered
< *r
->out
.needed
) {
9930 result
= WERR_MORE_DATA
;
9933 r
->out
.key_buffer
->string_array
= array
;
9937 if (!W_ERROR_IS_OK(result
)) {
9939 if (!W_ERROR_EQUAL(result
, WERR_MORE_DATA
)) {
9947 /****************************************************************
9948 _spoolss_DeletePrinterKey
9949 ****************************************************************/
9951 WERROR
_spoolss_DeletePrinterKey(struct pipes_struct
*p
,
9952 struct spoolss_DeletePrinterKey
*r
)
9954 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9957 const char *printer
;
9958 struct dcerpc_binding_handle
*b
;
9959 TALLOC_CTX
*tmp_ctx
;
9961 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
9964 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
9965 OUR_HANDLE(r
->in
.handle
)));
9969 /* if keyname == NULL, return error */
9970 if ( !r
->in
.key_name
)
9971 return WERR_INVALID_PARAM
;
9973 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9977 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
9978 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9979 "printer properties change denied by handle\n"));
9980 return WERR_ACCESS_DENIED
;
9983 printer
= lp_const_servicename(snum
);
9985 tmp_ctx
= talloc_new(p
->mem_ctx
);
9990 status
= winreg_printer_binding_handle(tmp_ctx
,
9991 get_session_info_system(),
9994 if (!W_ERROR_IS_OK(status
)) {
9998 /* delete the key and all subkeys */
9999 status
= winreg_delete_printer_key(tmp_ctx
, b
,
10002 if (W_ERROR_IS_OK(status
)) {
10003 status
= winreg_printer_update_changeid(tmp_ctx
, b
,
10008 talloc_free(tmp_ctx
);
10012 /****************************************************************
10013 _spoolss_EnumPrinterDataEx
10014 ****************************************************************/
10016 WERROR
_spoolss_EnumPrinterDataEx(struct pipes_struct
*p
,
10017 struct spoolss_EnumPrinterDataEx
*r
)
10019 uint32_t count
= 0;
10020 struct spoolss_PrinterEnumValues
*info
= NULL
;
10021 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
10025 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
10028 *r
->out
.needed
= 0;
10029 *r
->out
.info
= NULL
;
10032 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
10033 OUR_HANDLE(r
->in
.handle
)));
10034 return WERR_BADFID
;
10038 * first check for a keyname of NULL or "". Win2k seems to send
10039 * this a lot and we should send back WERR_INVALID_PARAM
10040 * no need to spend time looking up the printer in this case.
10044 if (!strlen(r
->in
.key_name
)) {
10045 result
= WERR_INVALID_PARAM
;
10049 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
10050 return WERR_BADFID
;
10053 /* now look for a match on the key name */
10054 result
= winreg_enum_printer_dataex_internal(p
->mem_ctx
,
10055 get_session_info_system(),
10057 lp_const_servicename(snum
),
10061 if (!W_ERROR_IS_OK(result
)) {
10065 #if 0 /* FIXME - gd */
10066 /* housekeeping information in the reply */
10068 /* Fix from Martin Zielinski <mz@seh.de> - ensure
10069 * the hand marshalled container size is a multiple
10070 * of 4 bytes for RPC alignment.
10074 needed
+= 4-(needed
% 4);
10077 *r
->out
.count
= count
;
10078 *r
->out
.info
= info
;
10081 if (!W_ERROR_IS_OK(result
)) {
10085 *r
->out
.needed
= SPOOLSS_BUFFER_ARRAY(p
->mem_ctx
,
10086 spoolss_EnumPrinterDataEx
,
10089 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
10090 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, *r
->out
.count
);
10092 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_MORE_DATA
);
10095 /****************************************************************************
10096 ****************************************************************************/
10098 static WERROR
getprintprocessordirectory_level_1(TALLOC_CTX
*mem_ctx
,
10099 const char *servername
,
10100 const char *environment
,
10101 struct spoolss_PrintProcessorDirectoryInfo1
*r
)
10106 werr
= compose_spoolss_server_path(mem_ctx
,
10109 SPOOLSS_PRTPROCS_PATH
,
10111 if (!W_ERROR_IS_OK(werr
)) {
10115 DEBUG(4,("print processor directory: [%s]\n", path
));
10117 r
->directory_name
= path
;
10122 /****************************************************************
10123 _spoolss_GetPrintProcessorDirectory
10124 ****************************************************************/
10126 WERROR
_spoolss_GetPrintProcessorDirectory(struct pipes_struct
*p
,
10127 struct spoolss_GetPrintProcessorDirectory
*r
)
10130 char *prnproc_share
= NULL
;
10131 bool prnproc_share_exists
= false;
10134 /* that's an [in out] buffer */
10136 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
10137 return WERR_INVALID_PARAM
;
10140 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
10143 *r
->out
.needed
= 0;
10145 /* r->in.level is ignored */
10147 /* We always should reply with a local print processor directory so that
10148 * users are not forced to have a [prnproc$] share on the Samba spoolss
10149 * server, if users decide to do so, lets announce it though - Guenther */
10151 snum
= find_service(talloc_tos(), "prnproc$", &prnproc_share
);
10152 if (!prnproc_share
) {
10156 prnproc_share_exists
= true;
10159 result
= getprintprocessordirectory_level_1(p
->mem_ctx
,
10160 prnproc_share_exists
? r
->in
.server
: NULL
,
10162 &r
->out
.info
->info1
);
10163 if (!W_ERROR_IS_OK(result
)) {
10164 TALLOC_FREE(r
->out
.info
);
10168 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo
,
10169 r
->out
.info
, r
->in
.level
);
10170 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
10172 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
10175 /*******************************************************************
10176 ********************************************************************/
10178 static bool push_monitorui_buf(TALLOC_CTX
*mem_ctx
, DATA_BLOB
*buf
,
10179 const char *dllname
)
10181 enum ndr_err_code ndr_err
;
10182 struct spoolss_MonitorUi ui
;
10184 ui
.dll_name
= dllname
;
10186 ndr_err
= ndr_push_struct_blob(buf
, mem_ctx
, &ui
,
10187 (ndr_push_flags_fn_t
)ndr_push_spoolss_MonitorUi
);
10188 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err
) && (DEBUGLEVEL
>= 10)) {
10189 NDR_PRINT_DEBUG(spoolss_MonitorUi
, &ui
);
10191 return NDR_ERR_CODE_IS_SUCCESS(ndr_err
);
10194 /*******************************************************************
10195 Streams the monitor UI DLL name in UNICODE
10196 *******************************************************************/
10198 static WERROR
xcvtcp_monitorui(TALLOC_CTX
*mem_ctx
,
10199 struct security_token
*token
, DATA_BLOB
*in
,
10200 DATA_BLOB
*out
, uint32_t *needed
)
10202 const char *dllname
= "tcpmonui.dll";
10204 *needed
= (strlen(dllname
)+1) * 2;
10206 if (out
->length
< *needed
) {
10207 return WERR_INSUFFICIENT_BUFFER
;
10210 if (!push_monitorui_buf(mem_ctx
, out
, dllname
)) {
10217 /*******************************************************************
10218 ********************************************************************/
10220 static bool pull_port_data_1(TALLOC_CTX
*mem_ctx
,
10221 struct spoolss_PortData1
*port1
,
10222 const DATA_BLOB
*buf
)
10224 enum ndr_err_code ndr_err
;
10225 ndr_err
= ndr_pull_struct_blob(buf
, mem_ctx
, port1
,
10226 (ndr_pull_flags_fn_t
)ndr_pull_spoolss_PortData1
);
10227 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err
) && (DEBUGLEVEL
>= 10)) {
10228 NDR_PRINT_DEBUG(spoolss_PortData1
, port1
);
10230 return NDR_ERR_CODE_IS_SUCCESS(ndr_err
);
10233 /*******************************************************************
10234 ********************************************************************/
10236 static bool pull_port_data_2(TALLOC_CTX
*mem_ctx
,
10237 struct spoolss_PortData2
*port2
,
10238 const DATA_BLOB
*buf
)
10240 enum ndr_err_code ndr_err
;
10241 ndr_err
= ndr_pull_struct_blob(buf
, mem_ctx
, port2
,
10242 (ndr_pull_flags_fn_t
)ndr_pull_spoolss_PortData2
);
10243 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err
) && (DEBUGLEVEL
>= 10)) {
10244 NDR_PRINT_DEBUG(spoolss_PortData2
, port2
);
10246 return NDR_ERR_CODE_IS_SUCCESS(ndr_err
);
10249 /*******************************************************************
10250 Create a new TCP/IP port
10251 *******************************************************************/
10253 static WERROR
xcvtcp_addport(TALLOC_CTX
*mem_ctx
,
10254 struct security_token
*token
, DATA_BLOB
*in
,
10255 DATA_BLOB
*out
, uint32_t *needed
)
10257 struct spoolss_PortData1 port1
;
10258 struct spoolss_PortData2 port2
;
10259 char *device_uri
= NULL
;
10262 const char *portname
;
10263 const char *hostaddress
;
10265 uint32_t port_number
;
10268 /* peek for spoolss_PortData version */
10270 if (!in
|| (in
->length
< (128 + 4))) {
10271 return WERR_GENERAL_FAILURE
;
10274 version
= IVAL(in
->data
, 128);
10278 ZERO_STRUCT(port1
);
10280 if (!pull_port_data_1(mem_ctx
, &port1
, in
)) {
10284 portname
= port1
.portname
;
10285 hostaddress
= port1
.hostaddress
;
10286 queue
= port1
.queue
;
10287 protocol
= port1
.protocol
;
10288 port_number
= port1
.port_number
;
10292 ZERO_STRUCT(port2
);
10294 if (!pull_port_data_2(mem_ctx
, &port2
, in
)) {
10298 portname
= port2
.portname
;
10299 hostaddress
= port2
.hostaddress
;
10300 queue
= port2
.queue
;
10301 protocol
= port2
.protocol
;
10302 port_number
= port2
.port_number
;
10306 DEBUG(1,("xcvtcp_addport: "
10307 "unknown version of port_data: %d\n", version
));
10308 return WERR_UNKNOWN_PORT
;
10311 /* create the device URI and call the add_port_hook() */
10313 switch (protocol
) {
10314 case PROTOCOL_RAWTCP_TYPE
:
10315 device_uri
= talloc_asprintf(mem_ctx
,
10316 "socket://%s:%d/", hostaddress
,
10320 case PROTOCOL_LPR_TYPE
:
10321 device_uri
= talloc_asprintf(mem_ctx
,
10322 "lpr://%s/%s", hostaddress
, queue
);
10326 return WERR_UNKNOWN_PORT
;
10333 return add_port_hook(mem_ctx
, token
, portname
, device_uri
);
10336 /*******************************************************************
10337 *******************************************************************/
10339 struct xcv_api_table xcvtcp_cmds
[] = {
10340 { "MonitorUI", xcvtcp_monitorui
},
10341 { "AddPort", xcvtcp_addport
},
10345 static WERROR
process_xcvtcp_command(TALLOC_CTX
*mem_ctx
,
10346 struct security_token
*token
, const char *command
,
10353 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command
));
10355 for ( i
=0; xcvtcp_cmds
[i
].name
; i
++ ) {
10356 if ( strcmp( command
, xcvtcp_cmds
[i
].name
) == 0 )
10357 return xcvtcp_cmds
[i
].fn(mem_ctx
, token
, inbuf
, outbuf
, needed
);
10360 return WERR_BADFUNC
;
10363 /*******************************************************************
10364 *******************************************************************/
10365 #if 0 /* don't support management using the "Local Port" monitor */
10367 static WERROR
xcvlocal_monitorui(TALLOC_CTX
*mem_ctx
,
10368 struct security_token
*token
, DATA_BLOB
*in
,
10369 DATA_BLOB
*out
, uint32_t *needed
)
10371 const char *dllname
= "localui.dll";
10373 *needed
= (strlen(dllname
)+1) * 2;
10375 if (out
->length
< *needed
) {
10376 return WERR_INSUFFICIENT_BUFFER
;
10379 if (!push_monitorui_buf(mem_ctx
, out
, dllname
)) {
10386 /*******************************************************************
10387 *******************************************************************/
10389 struct xcv_api_table xcvlocal_cmds
[] = {
10390 { "MonitorUI", xcvlocal_monitorui
},
10394 struct xcv_api_table xcvlocal_cmds
[] = {
10401 /*******************************************************************
10402 *******************************************************************/
10404 static WERROR
process_xcvlocal_command(TALLOC_CTX
*mem_ctx
,
10405 struct security_token
*token
, const char *command
,
10406 DATA_BLOB
*inbuf
, DATA_BLOB
*outbuf
,
10411 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command
));
10413 for ( i
=0; xcvlocal_cmds
[i
].name
; i
++ ) {
10414 if ( strcmp( command
, xcvlocal_cmds
[i
].name
) == 0 )
10415 return xcvlocal_cmds
[i
].fn(mem_ctx
, token
, inbuf
, outbuf
, needed
);
10417 return WERR_BADFUNC
;
10420 /****************************************************************
10422 ****************************************************************/
10424 WERROR
_spoolss_XcvData(struct pipes_struct
*p
,
10425 struct spoolss_XcvData
*r
)
10427 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
10428 DATA_BLOB out_data
= data_blob_null
;
10432 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
10433 OUR_HANDLE(r
->in
.handle
)));
10434 return WERR_BADFID
;
10437 /* Has to be a handle to the TCP/IP port monitor */
10439 if ( !(Printer
->printer_type
& (SPLHND_PORTMON_LOCAL
|SPLHND_PORTMON_TCP
)) ) {
10440 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
10441 return WERR_BADFID
;
10444 /* requires administrative access to the server */
10446 if ( !(Printer
->access_granted
& SERVER_ACCESS_ADMINISTER
) ) {
10447 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
10448 return WERR_ACCESS_DENIED
;
10451 /* Allocate the outgoing buffer */
10453 if (r
->in
.out_data_size
) {
10454 out_data
= data_blob_talloc_zero(p
->mem_ctx
, r
->in
.out_data_size
);
10455 if (out_data
.data
== NULL
) {
10460 switch ( Printer
->printer_type
) {
10461 case SPLHND_PORTMON_TCP
:
10462 werror
= process_xcvtcp_command(p
->mem_ctx
,
10463 p
->session_info
->security_token
,
10464 r
->in
.function_name
,
10465 &r
->in
.in_data
, &out_data
,
10468 case SPLHND_PORTMON_LOCAL
:
10469 werror
= process_xcvlocal_command(p
->mem_ctx
,
10470 p
->session_info
->security_token
,
10471 r
->in
.function_name
,
10472 &r
->in
.in_data
, &out_data
,
10476 werror
= WERR_INVALID_PRINT_MONITOR
;
10479 if (!W_ERROR_IS_OK(werror
)) {
10483 *r
->out
.status_code
= 0;
10485 if (r
->out
.out_data
&& out_data
.data
&& r
->in
.out_data_size
&& out_data
.length
) {
10486 memcpy(r
->out
.out_data
, out_data
.data
,
10487 MIN(r
->in
.out_data_size
, out_data
.length
));
10493 /****************************************************************
10494 _spoolss_AddPrintProcessor
10495 ****************************************************************/
10497 WERROR
_spoolss_AddPrintProcessor(struct pipes_struct
*p
,
10498 struct spoolss_AddPrintProcessor
*r
)
10500 /* for now, just indicate success and ignore the add. We'll
10501 automatically set the winprint processor for printer
10502 entries later. Used to debug the LexMark Optra S 1855 PCL
10508 /****************************************************************
10510 ****************************************************************/
10512 WERROR
_spoolss_AddPort(struct pipes_struct
*p
,
10513 struct spoolss_AddPort
*r
)
10515 /* do what w2k3 does */
10517 return WERR_NOT_SUPPORTED
;
10520 /****************************************************************
10521 _spoolss_GetPrinterDriver
10522 ****************************************************************/
10524 WERROR
_spoolss_GetPrinterDriver(struct pipes_struct
*p
,
10525 struct spoolss_GetPrinterDriver
*r
)
10527 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10528 return WERR_NOT_SUPPORTED
;
10531 /****************************************************************
10532 _spoolss_ReadPrinter
10533 ****************************************************************/
10535 WERROR
_spoolss_ReadPrinter(struct pipes_struct
*p
,
10536 struct spoolss_ReadPrinter
*r
)
10538 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10539 return WERR_NOT_SUPPORTED
;
10542 /****************************************************************
10543 _spoolss_WaitForPrinterChange
10544 ****************************************************************/
10546 WERROR
_spoolss_WaitForPrinterChange(struct pipes_struct
*p
,
10547 struct spoolss_WaitForPrinterChange
*r
)
10549 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10550 return WERR_NOT_SUPPORTED
;
10553 /****************************************************************
10554 _spoolss_ConfigurePort
10555 ****************************************************************/
10557 WERROR
_spoolss_ConfigurePort(struct pipes_struct
*p
,
10558 struct spoolss_ConfigurePort
*r
)
10560 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10561 return WERR_NOT_SUPPORTED
;
10564 /****************************************************************
10565 _spoolss_DeletePort
10566 ****************************************************************/
10568 WERROR
_spoolss_DeletePort(struct pipes_struct
*p
,
10569 struct spoolss_DeletePort
*r
)
10571 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10572 return WERR_NOT_SUPPORTED
;
10575 /****************************************************************
10576 _spoolss_CreatePrinterIC
10577 ****************************************************************/
10579 WERROR
_spoolss_CreatePrinterIC(struct pipes_struct
*p
,
10580 struct spoolss_CreatePrinterIC
*r
)
10582 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10583 return WERR_NOT_SUPPORTED
;
10586 /****************************************************************
10587 _spoolss_PlayGDIScriptOnPrinterIC
10588 ****************************************************************/
10590 WERROR
_spoolss_PlayGDIScriptOnPrinterIC(struct pipes_struct
*p
,
10591 struct spoolss_PlayGDIScriptOnPrinterIC
*r
)
10593 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10594 return WERR_NOT_SUPPORTED
;
10597 /****************************************************************
10598 _spoolss_DeletePrinterIC
10599 ****************************************************************/
10601 WERROR
_spoolss_DeletePrinterIC(struct pipes_struct
*p
,
10602 struct spoolss_DeletePrinterIC
*r
)
10604 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10605 return WERR_NOT_SUPPORTED
;
10608 /****************************************************************
10609 _spoolss_AddPrinterConnection
10610 ****************************************************************/
10612 WERROR
_spoolss_AddPrinterConnection(struct pipes_struct
*p
,
10613 struct spoolss_AddPrinterConnection
*r
)
10615 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10616 return WERR_NOT_SUPPORTED
;
10619 /****************************************************************
10620 _spoolss_DeletePrinterConnection
10621 ****************************************************************/
10623 WERROR
_spoolss_DeletePrinterConnection(struct pipes_struct
*p
,
10624 struct spoolss_DeletePrinterConnection
*r
)
10626 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10627 return WERR_NOT_SUPPORTED
;
10630 /****************************************************************
10631 _spoolss_PrinterMessageBox
10632 ****************************************************************/
10634 WERROR
_spoolss_PrinterMessageBox(struct pipes_struct
*p
,
10635 struct spoolss_PrinterMessageBox
*r
)
10637 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10638 return WERR_NOT_SUPPORTED
;
10641 /****************************************************************
10642 _spoolss_AddMonitor
10643 ****************************************************************/
10645 WERROR
_spoolss_AddMonitor(struct pipes_struct
*p
,
10646 struct spoolss_AddMonitor
*r
)
10648 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10649 return WERR_NOT_SUPPORTED
;
10652 /****************************************************************
10653 _spoolss_DeleteMonitor
10654 ****************************************************************/
10656 WERROR
_spoolss_DeleteMonitor(struct pipes_struct
*p
,
10657 struct spoolss_DeleteMonitor
*r
)
10659 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10660 return WERR_NOT_SUPPORTED
;
10663 /****************************************************************
10664 _spoolss_DeletePrintProcessor
10665 ****************************************************************/
10667 WERROR
_spoolss_DeletePrintProcessor(struct pipes_struct
*p
,
10668 struct spoolss_DeletePrintProcessor
*r
)
10670 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10671 return WERR_NOT_SUPPORTED
;
10674 /****************************************************************
10675 _spoolss_AddPrintProvidor
10676 ****************************************************************/
10678 WERROR
_spoolss_AddPrintProvidor(struct pipes_struct
*p
,
10679 struct spoolss_AddPrintProvidor
*r
)
10681 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10682 return WERR_NOT_SUPPORTED
;
10685 /****************************************************************
10686 _spoolss_DeletePrintProvidor
10687 ****************************************************************/
10689 WERROR
_spoolss_DeletePrintProvidor(struct pipes_struct
*p
,
10690 struct spoolss_DeletePrintProvidor
*r
)
10692 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10693 return WERR_NOT_SUPPORTED
;
10696 /****************************************************************
10697 _spoolss_FindFirstPrinterChangeNotification
10698 ****************************************************************/
10700 WERROR
_spoolss_FindFirstPrinterChangeNotification(struct pipes_struct
*p
,
10701 struct spoolss_FindFirstPrinterChangeNotification
*r
)
10703 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10704 return WERR_NOT_SUPPORTED
;
10707 /****************************************************************
10708 _spoolss_FindNextPrinterChangeNotification
10709 ****************************************************************/
10711 WERROR
_spoolss_FindNextPrinterChangeNotification(struct pipes_struct
*p
,
10712 struct spoolss_FindNextPrinterChangeNotification
*r
)
10714 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10715 return WERR_NOT_SUPPORTED
;
10718 /****************************************************************
10719 _spoolss_RouterFindFirstPrinterChangeNotificationOld
10720 ****************************************************************/
10722 WERROR
_spoolss_RouterFindFirstPrinterChangeNotificationOld(struct pipes_struct
*p
,
10723 struct spoolss_RouterFindFirstPrinterChangeNotificationOld
*r
)
10725 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10726 return WERR_NOT_SUPPORTED
;
10729 /****************************************************************
10730 _spoolss_ReplyOpenPrinter
10731 ****************************************************************/
10733 WERROR
_spoolss_ReplyOpenPrinter(struct pipes_struct
*p
,
10734 struct spoolss_ReplyOpenPrinter
*r
)
10736 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10737 return WERR_NOT_SUPPORTED
;
10740 /****************************************************************
10741 _spoolss_RouterReplyPrinter
10742 ****************************************************************/
10744 WERROR
_spoolss_RouterReplyPrinter(struct pipes_struct
*p
,
10745 struct spoolss_RouterReplyPrinter
*r
)
10747 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10748 return WERR_NOT_SUPPORTED
;
10751 /****************************************************************
10752 _spoolss_ReplyClosePrinter
10753 ****************************************************************/
10755 WERROR
_spoolss_ReplyClosePrinter(struct pipes_struct
*p
,
10756 struct spoolss_ReplyClosePrinter
*r
)
10758 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10759 return WERR_NOT_SUPPORTED
;
10762 /****************************************************************
10764 ****************************************************************/
10766 WERROR
_spoolss_AddPortEx(struct pipes_struct
*p
,
10767 struct spoolss_AddPortEx
*r
)
10769 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10770 return WERR_NOT_SUPPORTED
;
10773 /****************************************************************
10774 _spoolss_RouterFindFirstPrinterChangeNotification
10775 ****************************************************************/
10777 WERROR
_spoolss_RouterFindFirstPrinterChangeNotification(struct pipes_struct
*p
,
10778 struct spoolss_RouterFindFirstPrinterChangeNotification
*r
)
10780 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10781 return WERR_NOT_SUPPORTED
;
10784 /****************************************************************
10785 _spoolss_SpoolerInit
10786 ****************************************************************/
10788 WERROR
_spoolss_SpoolerInit(struct pipes_struct
*p
,
10789 struct spoolss_SpoolerInit
*r
)
10791 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10792 return WERR_NOT_SUPPORTED
;
10795 /****************************************************************
10796 _spoolss_ResetPrinterEx
10797 ****************************************************************/
10799 WERROR
_spoolss_ResetPrinterEx(struct pipes_struct
*p
,
10800 struct spoolss_ResetPrinterEx
*r
)
10802 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10803 return WERR_NOT_SUPPORTED
;
10806 /****************************************************************
10807 _spoolss_RouterReplyPrinterEx
10808 ****************************************************************/
10810 WERROR
_spoolss_RouterReplyPrinterEx(struct pipes_struct
*p
,
10811 struct spoolss_RouterReplyPrinterEx
*r
)
10813 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10814 return WERR_NOT_SUPPORTED
;
10817 /****************************************************************
10819 ****************************************************************/
10821 WERROR
_spoolss_44(struct pipes_struct
*p
,
10822 struct spoolss_44
*r
)
10824 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10825 return WERR_NOT_SUPPORTED
;
10828 /****************************************************************
10830 ****************************************************************/
10832 WERROR
_spoolss_SetPort(struct pipes_struct
*p
,
10833 struct spoolss_SetPort
*r
)
10835 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10836 return WERR_NOT_SUPPORTED
;
10839 /****************************************************************
10841 ****************************************************************/
10843 WERROR
_spoolss_4a(struct pipes_struct
*p
,
10844 struct spoolss_4a
*r
)
10846 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10847 return WERR_NOT_SUPPORTED
;
10850 /****************************************************************
10852 ****************************************************************/
10854 WERROR
_spoolss_4b(struct pipes_struct
*p
,
10855 struct spoolss_4b
*r
)
10857 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10858 return WERR_NOT_SUPPORTED
;
10861 /****************************************************************
10863 ****************************************************************/
10865 WERROR
_spoolss_4c(struct pipes_struct
*p
,
10866 struct spoolss_4c
*r
)
10868 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10869 return WERR_NOT_SUPPORTED
;
10872 /****************************************************************
10874 ****************************************************************/
10876 WERROR
_spoolss_53(struct pipes_struct
*p
,
10877 struct spoolss_53
*r
)
10879 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10880 return WERR_NOT_SUPPORTED
;
10883 /****************************************************************
10884 _spoolss_AddPerMachineConnection
10885 ****************************************************************/
10887 WERROR
_spoolss_AddPerMachineConnection(struct pipes_struct
*p
,
10888 struct spoolss_AddPerMachineConnection
*r
)
10890 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10891 return WERR_NOT_SUPPORTED
;
10894 /****************************************************************
10895 _spoolss_DeletePerMachineConnection
10896 ****************************************************************/
10898 WERROR
_spoolss_DeletePerMachineConnection(struct pipes_struct
*p
,
10899 struct spoolss_DeletePerMachineConnection
*r
)
10901 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10902 return WERR_NOT_SUPPORTED
;
10905 /****************************************************************
10906 _spoolss_EnumPerMachineConnections
10907 ****************************************************************/
10909 WERROR
_spoolss_EnumPerMachineConnections(struct pipes_struct
*p
,
10910 struct spoolss_EnumPerMachineConnections
*r
)
10912 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10913 return WERR_NOT_SUPPORTED
;
10916 /****************************************************************
10918 ****************************************************************/
10920 WERROR
_spoolss_5a(struct pipes_struct
*p
,
10921 struct spoolss_5a
*r
)
10923 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10924 return WERR_NOT_SUPPORTED
;
10927 /****************************************************************
10929 ****************************************************************/
10931 WERROR
_spoolss_5b(struct pipes_struct
*p
,
10932 struct spoolss_5b
*r
)
10934 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10935 return WERR_NOT_SUPPORTED
;
10938 /****************************************************************
10940 ****************************************************************/
10942 WERROR
_spoolss_5c(struct pipes_struct
*p
,
10943 struct spoolss_5c
*r
)
10945 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10946 return WERR_NOT_SUPPORTED
;
10949 /****************************************************************
10951 ****************************************************************/
10953 WERROR
_spoolss_5d(struct pipes_struct
*p
,
10954 struct spoolss_5d
*r
)
10956 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10957 return WERR_NOT_SUPPORTED
;
10960 /****************************************************************
10962 ****************************************************************/
10964 WERROR
_spoolss_5e(struct pipes_struct
*p
,
10965 struct spoolss_5e
*r
)
10967 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10968 return WERR_NOT_SUPPORTED
;
10971 /****************************************************************
10973 ****************************************************************/
10975 WERROR
_spoolss_5f(struct pipes_struct
*p
,
10976 struct spoolss_5f
*r
)
10978 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10979 return WERR_NOT_SUPPORTED
;
10982 /****************************************************************
10984 ****************************************************************/
10986 WERROR
_spoolss_60(struct pipes_struct
*p
,
10987 struct spoolss_60
*r
)
10989 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10990 return WERR_NOT_SUPPORTED
;
10993 /****************************************************************
10994 _spoolss_RpcSendRecvBidiData
10995 ****************************************************************/
10997 WERROR
_spoolss_RpcSendRecvBidiData(struct pipes_struct
*p
,
10998 struct spoolss_RpcSendRecvBidiData
*r
)
11000 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11001 return WERR_NOT_SUPPORTED
;
11004 /****************************************************************
11006 ****************************************************************/
11008 WERROR
_spoolss_62(struct pipes_struct
*p
,
11009 struct spoolss_62
*r
)
11011 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11012 return WERR_NOT_SUPPORTED
;
11015 /****************************************************************
11017 ****************************************************************/
11019 WERROR
_spoolss_63(struct pipes_struct
*p
,
11020 struct spoolss_63
*r
)
11022 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11023 return WERR_NOT_SUPPORTED
;
11026 /****************************************************************
11028 ****************************************************************/
11030 WERROR
_spoolss_64(struct pipes_struct
*p
,
11031 struct spoolss_64
*r
)
11033 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11034 return WERR_NOT_SUPPORTED
;
11037 /****************************************************************
11039 ****************************************************************/
11041 WERROR
_spoolss_65(struct pipes_struct
*p
,
11042 struct spoolss_65
*r
)
11044 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11045 return WERR_NOT_SUPPORTED
;
11048 /****************************************************************
11049 _spoolss_GetCorePrinterDrivers
11050 ****************************************************************/
11052 WERROR
_spoolss_GetCorePrinterDrivers(struct pipes_struct
*p
,
11053 struct spoolss_GetCorePrinterDrivers
*r
)
11055 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11056 return WERR_NOT_SUPPORTED
;
11059 /****************************************************************
11061 ****************************************************************/
11063 WERROR
_spoolss_67(struct pipes_struct
*p
,
11064 struct spoolss_67
*r
)
11066 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11067 return WERR_NOT_SUPPORTED
;
11070 /****************************************************************
11071 _spoolss_GetPrinterDriverPackagePath
11072 ****************************************************************/
11074 WERROR
_spoolss_GetPrinterDriverPackagePath(struct pipes_struct
*p
,
11075 struct spoolss_GetPrinterDriverPackagePath
*r
)
11077 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11078 return WERR_NOT_SUPPORTED
;
11081 /****************************************************************
11083 ****************************************************************/
11085 WERROR
_spoolss_69(struct pipes_struct
*p
,
11086 struct spoolss_69
*r
)
11088 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11089 return WERR_NOT_SUPPORTED
;
11092 /****************************************************************
11094 ****************************************************************/
11096 WERROR
_spoolss_6a(struct pipes_struct
*p
,
11097 struct spoolss_6a
*r
)
11099 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11100 return WERR_NOT_SUPPORTED
;
11103 /****************************************************************
11105 ****************************************************************/
11107 WERROR
_spoolss_6b(struct pipes_struct
*p
,
11108 struct spoolss_6b
*r
)
11110 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11111 return WERR_NOT_SUPPORTED
;
11114 /****************************************************************
11116 ****************************************************************/
11118 WERROR
_spoolss_6c(struct pipes_struct
*p
,
11119 struct spoolss_6c
*r
)
11121 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11122 return WERR_NOT_SUPPORTED
;
11125 /****************************************************************
11127 ****************************************************************/
11129 WERROR
_spoolss_6d(struct pipes_struct
*p
,
11130 struct spoolss_6d
*r
)
11132 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11133 return WERR_NOT_SUPPORTED
;
11136 /****************************************************************
11137 _spoolss_RpcGetJobNamedPropertyValue
11138 ****************************************************************/
11140 WERROR
_spoolss_RpcGetJobNamedPropertyValue(struct pipes_struct
*p
,
11141 struct spoolss_RpcGetJobNamedPropertyValue
*r
)
11143 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11144 return WERR_NOT_SUPPORTED
;
11147 /****************************************************************
11148 _spoolss_RpcSetJobNamedProperty
11149 ****************************************************************/
11151 WERROR
_spoolss_RpcSetJobNamedProperty(struct pipes_struct
*p
,
11152 struct spoolss_RpcSetJobNamedProperty
*r
)
11154 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11155 return WERR_NOT_SUPPORTED
;
11158 /****************************************************************
11159 _spoolss_RpcDeleteJobNamedProperty
11160 ****************************************************************/
11162 WERROR
_spoolss_RpcDeleteJobNamedProperty(struct pipes_struct
*p
,
11163 struct spoolss_RpcDeleteJobNamedProperty
*r
)
11165 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11166 return WERR_NOT_SUPPORTED
;
11169 /****************************************************************
11170 _spoolss_RpcEnumJobNamedProperties
11171 ****************************************************************/
11173 WERROR
_spoolss_RpcEnumJobNamedProperties(struct pipes_struct
*p
,
11174 struct spoolss_RpcEnumJobNamedProperties
*r
)
11176 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11177 return WERR_NOT_SUPPORTED
;