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
;
1638 ZERO_STRUCT(e
.in
.userlevel
);
1640 e
.in
.printername
= r
->in
.printername
;
1641 e
.in
.datatype
= r
->in
.datatype
;
1642 e
.in
.devmode_ctr
= r
->in
.devmode_ctr
;
1643 e
.in
.access_mask
= r
->in
.access_mask
;
1646 e
.out
.handle
= r
->out
.handle
;
1648 werr
= _spoolss_OpenPrinterEx(p
, &e
);
1650 if (W_ERROR_EQUAL(werr
, WERR_INVALID_PARAM
)) {
1651 /* OpenPrinterEx returns this for a bad
1652 * printer name. We must return WERR_INVALID_PRINTER_NAME
1655 werr
= WERR_INVALID_PRINTER_NAME
;
1661 static WERROR
copy_devicemode(TALLOC_CTX
*mem_ctx
,
1662 struct spoolss_DeviceMode
*orig
,
1663 struct spoolss_DeviceMode
**dest
)
1665 struct spoolss_DeviceMode
*dm
;
1667 dm
= talloc(mem_ctx
, struct spoolss_DeviceMode
);
1672 /* copy all values, then duplicate strings and structs */
1675 dm
->devicename
= talloc_strdup(dm
, orig
->devicename
);
1676 if (!dm
->devicename
) {
1679 dm
->formname
= talloc_strdup(dm
, orig
->formname
);
1680 if (!dm
->formname
) {
1683 if (orig
->driverextra_data
.data
) {
1684 dm
->driverextra_data
.data
=
1685 (uint8_t *) talloc_memdup(dm
, orig
->driverextra_data
.data
,
1686 orig
->driverextra_data
.length
);
1687 if (!dm
->driverextra_data
.data
) {
1696 /****************************************************************
1697 _spoolss_OpenPrinterEx
1698 ****************************************************************/
1700 WERROR
_spoolss_OpenPrinterEx(struct pipes_struct
*p
,
1701 struct spoolss_OpenPrinterEx
*r
)
1706 struct printer_handle
*Printer
=NULL
;
1710 if (!r
->in
.printername
) {
1711 return WERR_INVALID_PARAM
;
1714 if (!*r
->in
.printername
) {
1715 return WERR_INVALID_PARAM
;
1718 if (r
->in
.level
> 3) {
1719 return WERR_INVALID_PARAM
;
1721 if ((r
->in
.level
== 1 && !r
->in
.userlevel
.level1
) ||
1722 (r
->in
.level
== 2 && !r
->in
.userlevel
.level2
) ||
1723 (r
->in
.level
== 3 && !r
->in
.userlevel
.level3
)) {
1724 return WERR_INVALID_PARAM
;
1728 * The printcap printer share inventory is updated on client
1729 * enumeration. For clients that do not perform enumeration prior to
1730 * access, such as cupssmbadd, we reinitialise the printer share
1731 * inventory on open as well.
1734 delete_and_reload_printers(server_event_context(), p
->msg_ctx
);
1737 /* some sanity check because you can open a printer or a print server */
1738 /* aka: \\server\printer or \\server */
1740 DEBUGADD(3,("checking name: %s\n", r
->in
.printername
));
1742 result
= open_printer_hnd(p
, r
->out
.handle
, r
->in
.printername
, 0);
1743 if (!W_ERROR_IS_OK(result
)) {
1744 DEBUG(3,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
1745 "for printer %s\n", r
->in
.printername
));
1746 ZERO_STRUCTP(r
->out
.handle
);
1750 Printer
= find_printer_index_by_hnd(p
, r
->out
.handle
);
1752 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1753 "handle we created for printer %s\n", r
->in
.printername
));
1754 close_printer_handle(p
, r
->out
.handle
);
1755 ZERO_STRUCTP(r
->out
.handle
);
1756 return WERR_INVALID_PARAM
;
1760 * First case: the user is opening the print server:
1762 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1763 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1765 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1766 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1767 * or if the user is listed in the smb.conf printer admin parameter.
1769 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1770 * client view printer folder, but does not show the MSAPW.
1772 * Note: this test needs code to check access rights here too. Jeremy
1773 * could you look at this?
1775 * Second case: the user is opening a printer:
1776 * NT doesn't let us connect to a printer if the connecting user
1777 * doesn't have print permission.
1779 * Third case: user is opening a Port Monitor
1780 * access checks same as opening a handle to the print server.
1783 switch (Printer
->printer_type
)
1786 case SPLHND_PORTMON_TCP
:
1787 case SPLHND_PORTMON_LOCAL
:
1788 /* Printserver handles use global struct... */
1792 /* Map standard access rights to object specific access rights */
1794 se_map_standard(&r
->in
.access_mask
,
1795 &printserver_std_mapping
);
1797 /* Deny any object specific bits that don't apply to print
1798 servers (i.e printer and job specific bits) */
1800 r
->in
.access_mask
&= SEC_MASK_SPECIFIC
;
1802 if (r
->in
.access_mask
&
1803 ~(SERVER_ACCESS_ADMINISTER
| SERVER_ACCESS_ENUMERATE
)) {
1804 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1805 close_printer_handle(p
, r
->out
.handle
);
1806 ZERO_STRUCTP(r
->out
.handle
);
1807 return WERR_ACCESS_DENIED
;
1810 /* Allow admin access */
1812 if ( r
->in
.access_mask
& SERVER_ACCESS_ADMINISTER
)
1814 if (!lp_ms_add_printer_wizard()) {
1815 close_printer_handle(p
, r
->out
.handle
);
1816 ZERO_STRUCTP(r
->out
.handle
);
1817 return WERR_ACCESS_DENIED
;
1820 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1821 and not a printer admin, then fail */
1823 if ((p
->session_info
->unix_token
->uid
!= sec_initial_uid()) &&
1824 !security_token_has_privilege(p
->session_info
->security_token
, SEC_PRIV_PRINT_OPERATOR
) &&
1825 !nt_token_check_sid(&global_sid_Builtin_Print_Operators
,
1826 p
->session_info
->security_token
)) {
1827 close_printer_handle(p
, r
->out
.handle
);
1828 ZERO_STRUCTP(r
->out
.handle
);
1829 DEBUG(3,("access DENIED as user is not root, "
1830 "has no printoperator privilege, "
1831 "not a member of the printoperator builtin group and "
1832 "is not in printer admin list"));
1833 return WERR_ACCESS_DENIED
;
1836 r
->in
.access_mask
= SERVER_ACCESS_ADMINISTER
;
1840 r
->in
.access_mask
= SERVER_ACCESS_ENUMERATE
;
1843 DEBUG(4,("Setting print server access = %s\n", (r
->in
.access_mask
== SERVER_ACCESS_ADMINISTER
)
1844 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1846 /* We fall through to return WERR_OK */
1849 case SPLHND_PRINTER
:
1850 /* NT doesn't let us connect to a printer if the connecting user
1851 doesn't have print permission. */
1853 if (!get_printer_snum(p
, r
->out
.handle
, &snum
, NULL
)) {
1854 close_printer_handle(p
, r
->out
.handle
);
1855 ZERO_STRUCTP(r
->out
.handle
);
1859 if (r
->in
.access_mask
== SEC_FLAG_MAXIMUM_ALLOWED
) {
1860 r
->in
.access_mask
= PRINTER_ACCESS_ADMINISTER
;
1863 se_map_standard(&r
->in
.access_mask
, &printer_std_mapping
);
1865 /* map an empty access mask to the minimum access mask */
1866 if (r
->in
.access_mask
== 0x0)
1867 r
->in
.access_mask
= PRINTER_ACCESS_USE
;
1870 * If we are not serving the printer driver for this printer,
1871 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1872 * will keep NT clients happy --jerry
1875 if (lp_use_client_driver(snum
)
1876 && (r
->in
.access_mask
& PRINTER_ACCESS_ADMINISTER
))
1878 r
->in
.access_mask
= PRINTER_ACCESS_USE
;
1881 /* check smb.conf parameters and the the sec_desc */
1882 raddr
= tsocket_address_inet_addr_string(p
->remote_address
,
1884 if (raddr
== NULL
) {
1888 rc
= get_remote_hostname(p
->remote_address
,
1894 if (strequal(rhost
, "UNKNOWN")) {
1898 if (!allow_access(lp_hostsdeny(snum
), lp_hostsallow(snum
),
1900 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1901 ZERO_STRUCTP(r
->out
.handle
);
1902 return WERR_ACCESS_DENIED
;
1905 if (!user_ok_token(uidtoname(p
->session_info
->unix_token
->uid
), NULL
,
1906 p
->session_info
->security_token
, snum
) ||
1907 !print_access_check(p
->session_info
,
1910 r
->in
.access_mask
)) {
1911 DEBUG(3, ("access DENIED for printer open\n"));
1912 close_printer_handle(p
, r
->out
.handle
);
1913 ZERO_STRUCTP(r
->out
.handle
);
1914 return WERR_ACCESS_DENIED
;
1917 if ((r
->in
.access_mask
& SEC_MASK_SPECIFIC
)& ~(PRINTER_ACCESS_ADMINISTER
|PRINTER_ACCESS_USE
)) {
1918 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1919 close_printer_handle(p
, r
->out
.handle
);
1920 ZERO_STRUCTP(r
->out
.handle
);
1921 return WERR_ACCESS_DENIED
;
1924 if (r
->in
.access_mask
& PRINTER_ACCESS_ADMINISTER
)
1925 r
->in
.access_mask
= PRINTER_ACCESS_ADMINISTER
;
1927 r
->in
.access_mask
= PRINTER_ACCESS_USE
;
1929 DEBUG(4,("Setting printer access = %s\n", (r
->in
.access_mask
== PRINTER_ACCESS_ADMINISTER
)
1930 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1932 winreg_create_printer_internal(p
->mem_ctx
,
1933 get_session_info_system(),
1935 lp_const_servicename(snum
));
1940 /* sanity check to prevent programmer error */
1941 ZERO_STRUCTP(r
->out
.handle
);
1945 Printer
->access_granted
= r
->in
.access_mask
;
1948 * If the client sent a devmode in the OpenPrinter() call, then
1949 * save it here in case we get a job submission on this handle
1952 if ((Printer
->printer_type
!= SPLHND_SERVER
)
1953 && (r
->in
.devmode_ctr
.devmode
!= NULL
)) {
1954 copy_devicemode(NULL
, r
->in
.devmode_ctr
.devmode
,
1961 /****************************************************************
1962 _spoolss_ClosePrinter
1963 ****************************************************************/
1965 WERROR
_spoolss_ClosePrinter(struct pipes_struct
*p
,
1966 struct spoolss_ClosePrinter
*r
)
1968 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
1970 if (Printer
&& Printer
->document_started
) {
1971 struct spoolss_EndDocPrinter e
;
1973 e
.in
.handle
= r
->in
.handle
;
1975 _spoolss_EndDocPrinter(p
, &e
);
1978 if (!close_printer_handle(p
, r
->in
.handle
))
1981 /* clear the returned printer handle. Observed behavior
1982 from Win2k server. Don't think this really matters.
1983 Previous code just copied the value of the closed
1986 ZERO_STRUCTP(r
->out
.handle
);
1991 /****************************************************************
1992 _spoolss_DeletePrinter
1993 ****************************************************************/
1995 WERROR
_spoolss_DeletePrinter(struct pipes_struct
*p
,
1996 struct spoolss_DeletePrinter
*r
)
1998 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
2002 if (Printer
&& Printer
->document_started
) {
2003 struct spoolss_EndDocPrinter e
;
2005 e
.in
.handle
= r
->in
.handle
;
2007 _spoolss_EndDocPrinter(p
, &e
);
2010 if (get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
2011 winreg_delete_printer_key_internal(p
->mem_ctx
,
2012 get_session_info_system(),
2014 lp_const_servicename(snum
),
2018 result
= delete_printer_handle(p
, r
->in
.handle
);
2023 /*******************************************************************
2024 * static function to lookup the version id corresponding to an
2025 * long architecture string
2026 ******************************************************************/
2028 static const struct print_architecture_table_node archi_table
[]= {
2030 {"Windows 4.0", SPL_ARCH_WIN40
, 0 },
2031 {"Windows NT x86", SPL_ARCH_W32X86
, 2 },
2032 {"Windows NT R4000", SPL_ARCH_W32MIPS
, 2 },
2033 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA
, 2 },
2034 {"Windows NT PowerPC", SPL_ARCH_W32PPC
, 2 },
2035 {"Windows IA64", SPL_ARCH_IA64
, 3 },
2036 {"Windows x64", SPL_ARCH_X64
, 3 },
2040 static const int drv_cversion
[] = {SPOOLSS_DRIVER_VERSION_9X
,
2041 SPOOLSS_DRIVER_VERSION_NT35
,
2042 SPOOLSS_DRIVER_VERSION_NT4
,
2043 SPOOLSS_DRIVER_VERSION_200X
,
2046 static int get_version_id(const char *arch
)
2050 for (i
=0; archi_table
[i
].long_archi
!= NULL
; i
++)
2052 if (strcmp(arch
, archi_table
[i
].long_archi
) == 0)
2053 return (archi_table
[i
].version
);
2059 /****************************************************************
2060 _spoolss_DeletePrinterDriver
2061 ****************************************************************/
2063 WERROR
_spoolss_DeletePrinterDriver(struct pipes_struct
*p
,
2064 struct spoolss_DeletePrinterDriver
*r
)
2067 struct spoolss_DriverInfo8
*info
= NULL
;
2070 struct dcerpc_binding_handle
*b
;
2071 TALLOC_CTX
*tmp_ctx
= NULL
;
2075 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2076 and not a printer admin, then fail */
2078 if ((p
->session_info
->unix_token
->uid
!= sec_initial_uid()) &&
2079 !security_token_has_privilege(p
->session_info
->security_token
,
2080 SEC_PRIV_PRINT_OPERATOR
)) {
2081 return WERR_ACCESS_DENIED
;
2084 /* check that we have a valid driver name first */
2086 if ((version
= get_version_id(r
->in
.architecture
)) == -1) {
2087 return WERR_INVALID_ENVIRONMENT
;
2090 tmp_ctx
= talloc_new(p
->mem_ctx
);
2095 status
= winreg_printer_binding_handle(tmp_ctx
,
2096 get_session_info_system(),
2099 if (!W_ERROR_IS_OK(status
)) {
2103 for (found
= false, i
= 0; drv_cversion
[i
] >= 0; i
++) {
2104 status
= winreg_get_driver(tmp_ctx
, b
,
2105 r
->in
.architecture
, r
->in
.driver
,
2106 drv_cversion
[i
], &info
);
2107 if (!W_ERROR_IS_OK(status
)) {
2108 DEBUG(5, ("skipping del of driver with version %d\n",
2114 if (printer_driver_in_use(tmp_ctx
, b
, info
)) {
2115 status
= WERR_PRINTER_DRIVER_IN_USE
;
2119 status
= winreg_del_driver(tmp_ctx
, b
, info
, drv_cversion
[i
]);
2120 if (!W_ERROR_IS_OK(status
)) {
2121 DEBUG(0, ("failed del of driver with version %d\n",
2126 if (found
== false) {
2127 DEBUG(0, ("driver %s not found for deletion\n", r
->in
.driver
));
2128 status
= WERR_UNKNOWN_PRINTER_DRIVER
;
2134 talloc_free(tmp_ctx
);
2139 static WERROR
spoolss_dpd_version(TALLOC_CTX
*mem_ctx
,
2140 struct pipes_struct
*p
,
2141 struct spoolss_DeletePrinterDriverEx
*r
,
2142 struct dcerpc_binding_handle
*b
,
2143 struct spoolss_DriverInfo8
*info
)
2148 if (printer_driver_in_use(mem_ctx
, b
, info
)) {
2149 status
= WERR_PRINTER_DRIVER_IN_USE
;
2154 * we have a couple of cases to consider.
2155 * (1) Are any files in use? If so and DPD_DELETE_ALL_FILES is set,
2156 * then the delete should fail if **any** files overlap with
2158 * (2) If DPD_DELETE_UNUSED_FILES is set, then delete all
2159 * non-overlapping files
2160 * (3) If neither DPD_DELETE_ALL_FILES nor DPD_DELETE_UNUSED_FILES
2161 * are set, then do not delete any files
2162 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
2165 delete_files
= r
->in
.delete_flags
2166 & (DPD_DELETE_ALL_FILES
| DPD_DELETE_UNUSED_FILES
);
2170 bool in_use
= printer_driver_files_in_use(mem_ctx
, b
, info
);
2171 if (in_use
&& (r
->in
.delete_flags
& DPD_DELETE_ALL_FILES
)) {
2172 status
= WERR_PRINTER_DRIVER_IN_USE
;
2176 * printer_driver_files_in_use() has trimmed overlapping files
2177 * from info so they are not removed on DPD_DELETE_UNUSED_FILES
2182 status
= winreg_del_driver(mem_ctx
, b
, info
, info
->version
);
2183 if (!W_ERROR_IS_OK(status
)) {
2188 * now delete any associated files if delete_files is
2189 * true. Even if this part failes, we return succes
2190 * because the driver doesn not exist any more
2193 delete_driver_files(p
->session_info
, info
);
2200 /****************************************************************
2201 _spoolss_DeletePrinterDriverEx
2202 ****************************************************************/
2204 WERROR
_spoolss_DeletePrinterDriverEx(struct pipes_struct
*p
,
2205 struct spoolss_DeletePrinterDriverEx
*r
)
2207 struct spoolss_DriverInfo8
*info
= NULL
;
2209 struct dcerpc_binding_handle
*b
;
2210 TALLOC_CTX
*tmp_ctx
= NULL
;
2214 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2215 and not a printer admin, then fail */
2217 if ((p
->session_info
->unix_token
->uid
!= sec_initial_uid()) &&
2218 !security_token_has_privilege(p
->session_info
->security_token
,
2219 SEC_PRIV_PRINT_OPERATOR
)) {
2220 return WERR_ACCESS_DENIED
;
2223 /* check that we have a valid driver name first */
2224 if (get_version_id(r
->in
.architecture
) == -1) {
2225 /* this is what NT returns */
2226 return WERR_INVALID_ENVIRONMENT
;
2229 tmp_ctx
= talloc_new(p
->mem_ctx
);
2234 status
= winreg_printer_binding_handle(tmp_ctx
,
2235 get_session_info_system(),
2238 if (!W_ERROR_IS_OK(status
)) {
2242 for (found
= false, i
= 0; drv_cversion
[i
] >= 0; i
++) {
2243 if ((r
->in
.delete_flags
& DPD_DELETE_SPECIFIC_VERSION
)
2244 && (drv_cversion
[i
] != r
->in
.version
)) {
2248 /* check if a driver with this version exists before delete */
2249 status
= winreg_get_driver(tmp_ctx
, b
,
2250 r
->in
.architecture
, r
->in
.driver
,
2251 drv_cversion
[i
], &info
);
2252 if (!W_ERROR_IS_OK(status
)) {
2253 DEBUG(5, ("skipping del of driver with version %d\n",
2259 status
= spoolss_dpd_version(tmp_ctx
, p
, r
, b
, info
);
2260 if (!W_ERROR_IS_OK(status
)) {
2261 DEBUG(0, ("failed to delete driver with version %d\n",
2266 if (found
== false) {
2267 DEBUG(0, ("driver %s not found for deletion\n", r
->in
.driver
));
2268 status
= WERR_UNKNOWN_PRINTER_DRIVER
;
2274 talloc_free(tmp_ctx
);
2279 /********************************************************************
2280 GetPrinterData on a printer server Handle.
2281 ********************************************************************/
2283 static WERROR
getprinterdata_printer_server(TALLOC_CTX
*mem_ctx
,
2285 enum winreg_Type
*type
,
2286 union spoolss_PrinterData
*data
)
2288 DEBUG(8,("getprinterdata_printer_server:%s\n", value
));
2290 if (!strcasecmp_m(value
, "W3SvcInstalled")) {
2292 SIVAL(&data
->value
, 0, 0x00);
2296 if (!strcasecmp_m(value
, "BeepEnabled")) {
2298 SIVAL(&data
->value
, 0, 0x00);
2302 if (!strcasecmp_m(value
, "EventLog")) {
2304 /* formally was 0x1b */
2305 SIVAL(&data
->value
, 0, 0x00);
2309 if (!strcasecmp_m(value
, "NetPopup")) {
2311 SIVAL(&data
->value
, 0, 0x00);
2315 if (!strcasecmp_m(value
, "MajorVersion")) {
2318 /* Windows NT 4.0 seems to not allow uploading of drivers
2319 to a server that reports 0x3 as the MajorVersion.
2320 need to investigate more how Win2k gets around this .
2323 if (RA_WINNT
== get_remote_arch()) {
2324 SIVAL(&data
->value
, 0, 0x02);
2326 SIVAL(&data
->value
, 0, 0x03);
2332 if (!strcasecmp_m(value
, "MinorVersion")) {
2334 SIVAL(&data
->value
, 0, 0x00);
2339 * uint32_t size = 0x114
2340 * uint32_t major = 5
2341 * uint32_t minor = [0|1]
2342 * uint32_t build = [2195|2600]
2343 * extra unicode string = e.g. "Service Pack 3"
2345 if (!strcasecmp_m(value
, "OSVersion")) {
2347 enum ndr_err_code ndr_err
;
2348 struct spoolss_OSVersion os
;
2350 os
.major
= 5; /* Windows 2000 == 5.0 */
2352 os
.build
= 2195; /* build */
2353 os
.extra_string
= ""; /* leave extra string empty */
2355 ndr_err
= ndr_push_struct_blob(&blob
, mem_ctx
, &os
,
2356 (ndr_push_flags_fn_t
)ndr_push_spoolss_OSVersion
);
2357 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2358 return WERR_GENERAL_FAILURE
;
2362 data
->binary
= blob
;
2368 if (!strcasecmp_m(value
, "DefaultSpoolDirectory")) {
2371 data
->string
= talloc_strdup(mem_ctx
, "C:\\PRINTERS");
2372 W_ERROR_HAVE_NO_MEMORY(data
->string
);
2377 if (!strcasecmp_m(value
, "Architecture")) {
2379 data
->string
= talloc_strdup(mem_ctx
,
2380 lp_parm_const_string(GLOBAL_SECTION_SNUM
, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_NT_X86
));
2381 W_ERROR_HAVE_NO_MEMORY(data
->string
);
2386 if (!strcasecmp_m(value
, "DsPresent")) {
2389 /* only show the publish check box if we are a
2390 member of a AD domain */
2392 if (lp_security() == SEC_ADS
) {
2393 SIVAL(&data
->value
, 0, 0x01);
2395 SIVAL(&data
->value
, 0, 0x00);
2400 if (!strcasecmp_m(value
, "DNSMachineName")) {
2401 const char *hostname
= get_mydnsfullname();
2404 return WERR_BADFILE
;
2408 data
->string
= talloc_strdup(mem_ctx
, hostname
);
2409 W_ERROR_HAVE_NO_MEMORY(data
->string
);
2416 return WERR_INVALID_PARAM
;
2419 /****************************************************************
2420 _spoolss_GetPrinterData
2421 ****************************************************************/
2423 WERROR
_spoolss_GetPrinterData(struct pipes_struct
*p
,
2424 struct spoolss_GetPrinterData
*r
)
2426 struct spoolss_GetPrinterDataEx r2
;
2428 r2
.in
.handle
= r
->in
.handle
;
2429 r2
.in
.key_name
= "PrinterDriverData";
2430 r2
.in
.value_name
= r
->in
.value_name
;
2431 r2
.in
.offered
= r
->in
.offered
;
2432 r2
.out
.type
= r
->out
.type
;
2433 r2
.out
.data
= r
->out
.data
;
2434 r2
.out
.needed
= r
->out
.needed
;
2436 return _spoolss_GetPrinterDataEx(p
, &r2
);
2439 /*********************************************************
2440 Connect to the client machine.
2441 **********************************************************/
2443 static bool spoolss_connect_to_client(struct rpc_pipe_client
**pp_pipe
,
2444 struct sockaddr_storage
*client_ss
, const char *remote_machine
)
2447 struct cli_state
*the_cli
;
2448 struct sockaddr_storage rm_addr
;
2449 char addr
[INET6_ADDRSTRLEN
];
2451 if ( is_zero_addr(client_ss
) ) {
2452 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2454 if ( !resolve_name( remote_machine
, &rm_addr
, 0x20, false) ) {
2455 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine
));
2458 print_sockaddr(addr
, sizeof(addr
), &rm_addr
);
2460 rm_addr
= *client_ss
;
2461 print_sockaddr(addr
, sizeof(addr
), &rm_addr
);
2462 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2466 if (ismyaddr((struct sockaddr
*)(void *)&rm_addr
)) {
2467 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2472 /* setup the connection */
2473 ret
= cli_full_connection( &the_cli
, lp_netbios_name(), remote_machine
,
2474 &rm_addr
, 0, "IPC$", "IPC",
2478 0, lp_client_signing());
2480 if ( !NT_STATUS_IS_OK( ret
) ) {
2481 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2486 if ( smbXcli_conn_protocol(the_cli
->conn
) != PROTOCOL_NT1
) {
2487 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine
));
2488 cli_shutdown(the_cli
);
2493 * Ok - we have an anonymous connection to the IPC$ share.
2494 * Now start the NT Domain stuff :-).
2497 ret
= cli_rpc_pipe_open_noauth(the_cli
, &ndr_table_spoolss
.syntax_id
, pp_pipe
);
2498 if (!NT_STATUS_IS_OK(ret
)) {
2499 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2500 remote_machine
, nt_errstr(ret
)));
2501 cli_shutdown(the_cli
);
2508 /***************************************************************************
2509 Connect to the client.
2510 ****************************************************************************/
2512 static bool srv_spoolss_replyopenprinter(int snum
, const char *printer
,
2513 uint32_t localprinter
,
2514 enum winreg_Type type
,
2515 struct policy_handle
*handle
,
2516 struct notify_back_channel
**_chan
,
2517 struct sockaddr_storage
*client_ss
,
2518 struct messaging_context
*msg_ctx
)
2522 struct notify_back_channel
*chan
;
2524 for (chan
= back_channels
; chan
; chan
= chan
->next
) {
2525 if (memcmp(&chan
->client_address
, client_ss
,
2526 sizeof(struct sockaddr_storage
)) == 0) {
2532 * If it's the first connection, contact the client
2533 * and connect to the IPC$ share anonymously
2536 fstring unix_printer
;
2538 /* the +2 is to strip the leading 2 backslashs */
2539 fstrcpy(unix_printer
, printer
+ 2);
2541 chan
= talloc_zero(NULL
, struct notify_back_channel
);
2545 chan
->client_address
= *client_ss
;
2547 if (!spoolss_connect_to_client(&chan
->cli_pipe
, client_ss
, unix_printer
)) {
2552 DLIST_ADD(back_channels
, chan
);
2554 messaging_register(msg_ctx
, NULL
, MSG_PRINTER_NOTIFY2
,
2555 receive_notify2_message_list
);
2558 if (chan
->cli_pipe
== NULL
||
2559 chan
->cli_pipe
->binding_handle
== NULL
) {
2560 DEBUG(0, ("srv_spoolss_replyopenprinter: error - "
2561 "NULL %s for printer %s\n",
2562 chan
->cli_pipe
== NULL
?
2563 "chan->cli_pipe" : "chan->cli_pipe->binding_handle",
2569 * Tell the specific printing tdb we want messages for this printer
2570 * by registering our PID.
2573 if (!print_notify_register_pid(snum
)) {
2574 DEBUG(0, ("Failed to register our pid for printer %s\n",
2578 status
= dcerpc_spoolss_ReplyOpenPrinter(chan
->cli_pipe
->binding_handle
,
2587 if (!NT_STATUS_IS_OK(status
)) {
2588 DEBUG(5, ("dcerpc_spoolss_ReplyOpenPrinter returned [%s]\n", nt_errstr(status
)));
2589 result
= ntstatus_to_werror(status
);
2590 } else if (!W_ERROR_IS_OK(result
)) {
2591 DEBUG(5, ("ReplyOpenPrinter returned [%s]\n", win_errstr(result
)));
2594 chan
->active_connections
++;
2597 return (W_ERROR_IS_OK(result
));
2600 /****************************************************************
2601 ****************************************************************/
2603 static struct spoolss_NotifyOption
*dup_spoolss_NotifyOption(TALLOC_CTX
*mem_ctx
,
2604 const struct spoolss_NotifyOption
*r
)
2606 struct spoolss_NotifyOption
*option
;
2613 option
= talloc_zero(mem_ctx
, struct spoolss_NotifyOption
);
2620 if (!option
->count
) {
2624 option
->types
= talloc_zero_array(option
,
2625 struct spoolss_NotifyOptionType
, option
->count
);
2626 if (!option
->types
) {
2627 talloc_free(option
);
2631 for (i
=0; i
< option
->count
; i
++) {
2632 option
->types
[i
] = r
->types
[i
];
2634 if (option
->types
[i
].count
) {
2635 option
->types
[i
].fields
= talloc_zero_array(option
,
2636 union spoolss_Field
, option
->types
[i
].count
);
2637 if (!option
->types
[i
].fields
) {
2638 talloc_free(option
);
2641 for (k
=0; k
<option
->types
[i
].count
; k
++) {
2642 option
->types
[i
].fields
[k
] =
2643 r
->types
[i
].fields
[k
];
2651 /****************************************************************
2652 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2654 * before replying OK: status=0 a rpc call is made to the workstation
2655 * asking ReplyOpenPrinter
2657 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2658 * called from api_spoolss_rffpcnex
2659 ****************************************************************/
2661 WERROR
_spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct
*p
,
2662 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx
*r
)
2665 struct spoolss_NotifyOption
*option
= r
->in
.notify_options
;
2666 struct sockaddr_storage client_ss
;
2669 /* store the notify value in the printer struct */
2671 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
2674 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2675 "Invalid handle (%s:%u:%u).\n",
2676 OUR_HANDLE(r
->in
.handle
)));
2680 Printer
->notify
.flags
= r
->in
.flags
;
2681 Printer
->notify
.options
= r
->in
.options
;
2682 Printer
->notify
.printerlocal
= r
->in
.printer_local
;
2683 Printer
->notify
.msg_ctx
= p
->msg_ctx
;
2685 TALLOC_FREE(Printer
->notify
.option
);
2686 Printer
->notify
.option
= dup_spoolss_NotifyOption(Printer
, option
);
2688 fstrcpy(Printer
->notify
.localmachine
, r
->in
.local_machine
);
2690 /* Connect to the client machine and send a ReplyOpenPrinter */
2692 if ( Printer
->printer_type
== SPLHND_SERVER
)
2694 else if ( (Printer
->printer_type
== SPLHND_PRINTER
) &&
2695 !get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
) )
2698 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2699 "remote_address is %s\n",
2700 tsocket_address_string(p
->remote_address
, p
->mem_ctx
)));
2702 if (!lp_print_notify_backchannel(snum
)) {
2703 DEBUG(10, ("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2704 "backchannel disabled\n"));
2705 return WERR_SERVER_UNAVAILABLE
;
2708 client_len
= tsocket_address_bsd_sockaddr(p
->remote_address
,
2709 (struct sockaddr
*) &client_ss
,
2710 sizeof(struct sockaddr_storage
));
2711 if (client_len
< 0) {
2715 if(!srv_spoolss_replyopenprinter(snum
, Printer
->notify
.localmachine
,
2716 Printer
->notify
.printerlocal
, REG_SZ
,
2717 &Printer
->notify
.cli_hnd
,
2718 &Printer
->notify
.cli_chan
,
2719 &client_ss
, p
->msg_ctx
)) {
2720 return WERR_SERVER_UNAVAILABLE
;
2726 /*******************************************************************
2727 * fill a notify_info_data with the servername
2728 ********************************************************************/
2730 static void spoolss_notify_server_name(struct messaging_context
*msg_ctx
,
2732 struct spoolss_Notify
*data
,
2733 print_queue_struct
*queue
,
2734 struct spoolss_PrinterInfo2
*pinfo2
,
2735 TALLOC_CTX
*mem_ctx
)
2737 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->servername
);
2740 /*******************************************************************
2741 * fill a notify_info_data with the printername (not including the servername).
2742 ********************************************************************/
2744 static void spoolss_notify_printer_name(struct messaging_context
*msg_ctx
,
2746 struct spoolss_Notify
*data
,
2747 print_queue_struct
*queue
,
2748 struct spoolss_PrinterInfo2
*pinfo2
,
2749 TALLOC_CTX
*mem_ctx
)
2751 /* the notify name should not contain the \\server\ part */
2752 const char *p
= strrchr(pinfo2
->printername
, '\\');
2755 p
= pinfo2
->printername
;
2760 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, p
);
2763 /*******************************************************************
2764 * fill a notify_info_data with the servicename
2765 ********************************************************************/
2767 static void spoolss_notify_share_name(struct messaging_context
*msg_ctx
,
2769 struct spoolss_Notify
*data
,
2770 print_queue_struct
*queue
,
2771 struct spoolss_PrinterInfo2
*pinfo2
,
2772 TALLOC_CTX
*mem_ctx
)
2774 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, lp_servicename(talloc_tos(), snum
));
2777 /*******************************************************************
2778 * fill a notify_info_data with the port name
2779 ********************************************************************/
2781 static void spoolss_notify_port_name(struct messaging_context
*msg_ctx
,
2783 struct spoolss_Notify
*data
,
2784 print_queue_struct
*queue
,
2785 struct spoolss_PrinterInfo2
*pinfo2
,
2786 TALLOC_CTX
*mem_ctx
)
2788 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->portname
);
2791 /*******************************************************************
2792 * fill a notify_info_data with the printername
2793 * but it doesn't exist, have to see what to do
2794 ********************************************************************/
2796 static void spoolss_notify_driver_name(struct messaging_context
*msg_ctx
,
2798 struct spoolss_Notify
*data
,
2799 print_queue_struct
*queue
,
2800 struct spoolss_PrinterInfo2
*pinfo2
,
2801 TALLOC_CTX
*mem_ctx
)
2803 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->drivername
);
2806 /*******************************************************************
2807 * fill a notify_info_data with the comment
2808 ********************************************************************/
2810 static void spoolss_notify_comment(struct messaging_context
*msg_ctx
,
2812 struct spoolss_Notify
*data
,
2813 print_queue_struct
*queue
,
2814 struct spoolss_PrinterInfo2
*pinfo2
,
2815 TALLOC_CTX
*mem_ctx
)
2819 if (*pinfo2
->comment
== '\0') {
2820 p
= lp_comment(talloc_tos(), snum
);
2822 p
= pinfo2
->comment
;
2825 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, p
);
2828 /*******************************************************************
2829 * fill a notify_info_data with the comment
2830 * location = "Room 1, floor 2, building 3"
2831 ********************************************************************/
2833 static void spoolss_notify_location(struct messaging_context
*msg_ctx
,
2835 struct spoolss_Notify
*data
,
2836 print_queue_struct
*queue
,
2837 struct spoolss_PrinterInfo2
*pinfo2
,
2838 TALLOC_CTX
*mem_ctx
)
2840 const char *loc
= pinfo2
->location
;
2843 status
= printer_list_get_printer(mem_ctx
,
2848 if (NT_STATUS_IS_OK(status
)) {
2850 loc
= pinfo2
->location
;
2854 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, loc
);
2857 /*******************************************************************
2858 * fill a notify_info_data with the device mode
2859 * jfm:xxxx don't to it for know but that's a real problem !!!
2860 ********************************************************************/
2862 static void spoolss_notify_devmode(struct messaging_context
*msg_ctx
,
2864 struct spoolss_Notify
*data
,
2865 print_queue_struct
*queue
,
2866 struct spoolss_PrinterInfo2
*pinfo2
,
2867 TALLOC_CTX
*mem_ctx
)
2869 /* for a dummy implementation we have to zero the fields */
2870 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data
, NULL
);
2873 /*******************************************************************
2874 * fill a notify_info_data with the separator file name
2875 ********************************************************************/
2877 static void spoolss_notify_sepfile(struct messaging_context
*msg_ctx
,
2879 struct spoolss_Notify
*data
,
2880 print_queue_struct
*queue
,
2881 struct spoolss_PrinterInfo2
*pinfo2
,
2882 TALLOC_CTX
*mem_ctx
)
2884 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->sepfile
);
2887 /*******************************************************************
2888 * fill a notify_info_data with the print processor
2889 * jfm:xxxx return always winprint to indicate we don't do anything to it
2890 ********************************************************************/
2892 static void spoolss_notify_print_processor(struct messaging_context
*msg_ctx
,
2894 struct spoolss_Notify
*data
,
2895 print_queue_struct
*queue
,
2896 struct spoolss_PrinterInfo2
*pinfo2
,
2897 TALLOC_CTX
*mem_ctx
)
2899 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->printprocessor
);
2902 /*******************************************************************
2903 * fill a notify_info_data with the print processor options
2904 * jfm:xxxx send an empty string
2905 ********************************************************************/
2907 static void spoolss_notify_parameters(struct messaging_context
*msg_ctx
,
2909 struct spoolss_Notify
*data
,
2910 print_queue_struct
*queue
,
2911 struct spoolss_PrinterInfo2
*pinfo2
,
2912 TALLOC_CTX
*mem_ctx
)
2914 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->parameters
);
2917 /*******************************************************************
2918 * fill a notify_info_data with the data type
2919 * jfm:xxxx always send RAW as data type
2920 ********************************************************************/
2922 static void spoolss_notify_datatype(struct messaging_context
*msg_ctx
,
2924 struct spoolss_Notify
*data
,
2925 print_queue_struct
*queue
,
2926 struct spoolss_PrinterInfo2
*pinfo2
,
2927 TALLOC_CTX
*mem_ctx
)
2929 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->datatype
);
2932 /*******************************************************************
2933 * fill a notify_info_data with the security descriptor
2934 * jfm:xxxx send an null pointer to say no security desc
2935 * have to implement security before !
2936 ********************************************************************/
2938 static void spoolss_notify_security_desc(struct messaging_context
*msg_ctx
,
2940 struct spoolss_Notify
*data
,
2941 print_queue_struct
*queue
,
2942 struct spoolss_PrinterInfo2
*pinfo2
,
2943 TALLOC_CTX
*mem_ctx
)
2945 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data
, pinfo2
->secdesc
);
2948 /*******************************************************************
2949 * fill a notify_info_data with the attributes
2950 * jfm:xxxx a samba printer is always shared
2951 ********************************************************************/
2953 static void spoolss_notify_attributes(struct messaging_context
*msg_ctx
,
2955 struct spoolss_Notify
*data
,
2956 print_queue_struct
*queue
,
2957 struct spoolss_PrinterInfo2
*pinfo2
,
2958 TALLOC_CTX
*mem_ctx
)
2960 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->attributes
);
2963 /*******************************************************************
2964 * fill a notify_info_data with the priority
2965 ********************************************************************/
2967 static void spoolss_notify_priority(struct messaging_context
*msg_ctx
,
2969 struct spoolss_Notify
*data
,
2970 print_queue_struct
*queue
,
2971 struct spoolss_PrinterInfo2
*pinfo2
,
2972 TALLOC_CTX
*mem_ctx
)
2974 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->priority
);
2977 /*******************************************************************
2978 * fill a notify_info_data with the default priority
2979 ********************************************************************/
2981 static void spoolss_notify_default_priority(struct messaging_context
*msg_ctx
,
2983 struct spoolss_Notify
*data
,
2984 print_queue_struct
*queue
,
2985 struct spoolss_PrinterInfo2
*pinfo2
,
2986 TALLOC_CTX
*mem_ctx
)
2988 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->defaultpriority
);
2991 /*******************************************************************
2992 * fill a notify_info_data with the start time
2993 ********************************************************************/
2995 static void spoolss_notify_start_time(struct messaging_context
*msg_ctx
,
2997 struct spoolss_Notify
*data
,
2998 print_queue_struct
*queue
,
2999 struct spoolss_PrinterInfo2
*pinfo2
,
3000 TALLOC_CTX
*mem_ctx
)
3002 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->starttime
);
3005 /*******************************************************************
3006 * fill a notify_info_data with the until time
3007 ********************************************************************/
3009 static void spoolss_notify_until_time(struct messaging_context
*msg_ctx
,
3011 struct spoolss_Notify
*data
,
3012 print_queue_struct
*queue
,
3013 struct spoolss_PrinterInfo2
*pinfo2
,
3014 TALLOC_CTX
*mem_ctx
)
3016 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->untiltime
);
3019 /*******************************************************************
3020 * fill a notify_info_data with the status
3021 ********************************************************************/
3023 static void spoolss_notify_status(struct messaging_context
*msg_ctx
,
3025 struct spoolss_Notify
*data
,
3026 print_queue_struct
*queue
,
3027 struct spoolss_PrinterInfo2
*pinfo2
,
3028 TALLOC_CTX
*mem_ctx
)
3030 print_status_struct status
;
3032 print_queue_length(msg_ctx
, snum
, &status
);
3033 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, status
.status
);
3036 /*******************************************************************
3037 * fill a notify_info_data with the number of jobs queued
3038 ********************************************************************/
3040 static void spoolss_notify_cjobs(struct messaging_context
*msg_ctx
,
3042 struct spoolss_Notify
*data
,
3043 print_queue_struct
*queue
,
3044 struct spoolss_PrinterInfo2
*pinfo2
,
3045 TALLOC_CTX
*mem_ctx
)
3047 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(
3048 data
, print_queue_length(msg_ctx
, snum
, NULL
));
3051 /*******************************************************************
3052 * fill a notify_info_data with the average ppm
3053 ********************************************************************/
3055 static void spoolss_notify_average_ppm(struct messaging_context
*msg_ctx
,
3057 struct spoolss_Notify
*data
,
3058 print_queue_struct
*queue
,
3059 struct spoolss_PrinterInfo2
*pinfo2
,
3060 TALLOC_CTX
*mem_ctx
)
3062 /* always respond 8 pages per minutes */
3063 /* a little hard ! */
3064 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->averageppm
);
3067 /*******************************************************************
3068 * fill a notify_info_data with username
3069 ********************************************************************/
3071 static void spoolss_notify_username(struct messaging_context
*msg_ctx
,
3073 struct spoolss_Notify
*data
,
3074 print_queue_struct
*queue
,
3075 struct spoolss_PrinterInfo2
*pinfo2
,
3076 TALLOC_CTX
*mem_ctx
)
3078 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, queue
->fs_user
);
3081 /*******************************************************************
3082 * fill a notify_info_data with job status
3083 ********************************************************************/
3085 static void spoolss_notify_job_status(struct messaging_context
*msg_ctx
,
3087 struct spoolss_Notify
*data
,
3088 print_queue_struct
*queue
,
3089 struct spoolss_PrinterInfo2
*pinfo2
,
3090 TALLOC_CTX
*mem_ctx
)
3092 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, nt_printj_status(queue
->status
));
3095 /*******************************************************************
3096 * fill a notify_info_data with job name
3097 ********************************************************************/
3099 static void spoolss_notify_job_name(struct messaging_context
*msg_ctx
,
3101 struct spoolss_Notify
*data
,
3102 print_queue_struct
*queue
,
3103 struct spoolss_PrinterInfo2
*pinfo2
,
3104 TALLOC_CTX
*mem_ctx
)
3106 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, queue
->fs_file
);
3109 /*******************************************************************
3110 * fill a notify_info_data with job status
3111 ********************************************************************/
3113 static void spoolss_notify_job_status_string(struct messaging_context
*msg_ctx
,
3115 struct spoolss_Notify
*data
,
3116 print_queue_struct
*queue
,
3117 struct spoolss_PrinterInfo2
*pinfo2
,
3118 TALLOC_CTX
*mem_ctx
)
3121 * Now we're returning job status codes we just return a "" here. JRA.
3126 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
3129 switch (queue
->status
) {
3134 p
= ""; /* NT provides the paused string */
3143 #endif /* NO LONGER NEEDED. */
3145 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, p
);
3148 /*******************************************************************
3149 * fill a notify_info_data with job time
3150 ********************************************************************/
3152 static void spoolss_notify_job_time(struct messaging_context
*msg_ctx
,
3154 struct spoolss_Notify
*data
,
3155 print_queue_struct
*queue
,
3156 struct spoolss_PrinterInfo2
*pinfo2
,
3157 TALLOC_CTX
*mem_ctx
)
3159 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, 0);
3162 /*******************************************************************
3163 * fill a notify_info_data with job size
3164 ********************************************************************/
3166 static void spoolss_notify_job_size(struct messaging_context
*msg_ctx
,
3168 struct spoolss_Notify
*data
,
3169 print_queue_struct
*queue
,
3170 struct spoolss_PrinterInfo2
*pinfo2
,
3171 TALLOC_CTX
*mem_ctx
)
3173 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, queue
->size
);
3176 /*******************************************************************
3177 * fill a notify_info_data with page info
3178 ********************************************************************/
3179 static void spoolss_notify_total_pages(struct messaging_context
*msg_ctx
,
3181 struct spoolss_Notify
*data
,
3182 print_queue_struct
*queue
,
3183 struct spoolss_PrinterInfo2
*pinfo2
,
3184 TALLOC_CTX
*mem_ctx
)
3186 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, queue
->page_count
);
3189 /*******************************************************************
3190 * fill a notify_info_data with pages printed info.
3191 ********************************************************************/
3192 static void spoolss_notify_pages_printed(struct messaging_context
*msg_ctx
,
3194 struct spoolss_Notify
*data
,
3195 print_queue_struct
*queue
,
3196 struct spoolss_PrinterInfo2
*pinfo2
,
3197 TALLOC_CTX
*mem_ctx
)
3199 /* Add code when back-end tracks this */
3200 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, 0);
3203 /*******************************************************************
3204 Fill a notify_info_data with job position.
3205 ********************************************************************/
3207 static void spoolss_notify_job_position(struct messaging_context
*msg_ctx
,
3209 struct spoolss_Notify
*data
,
3210 print_queue_struct
*queue
,
3211 struct spoolss_PrinterInfo2
*pinfo2
,
3212 TALLOC_CTX
*mem_ctx
)
3214 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, queue
->sysjob
);
3217 /*******************************************************************
3218 Fill a notify_info_data with submitted time.
3219 ********************************************************************/
3221 static void spoolss_notify_submitted_time(struct messaging_context
*msg_ctx
,
3223 struct spoolss_Notify
*data
,
3224 print_queue_struct
*queue
,
3225 struct spoolss_PrinterInfo2
*pinfo2
,
3226 TALLOC_CTX
*mem_ctx
)
3228 data
->data
.string
.string
= NULL
;
3229 data
->data
.string
.size
= 0;
3231 init_systemtime_buffer(mem_ctx
, gmtime(&queue
->time
),
3232 &data
->data
.string
.string
,
3233 &data
->data
.string
.size
);
3237 struct s_notify_info_data_table
3239 enum spoolss_NotifyType type
;
3242 enum spoolss_NotifyTable variable_type
;
3243 void (*fn
) (struct messaging_context
*msg_ctx
,
3244 int snum
, struct spoolss_Notify
*data
,
3245 print_queue_struct
*queue
,
3246 struct spoolss_PrinterInfo2
*pinfo2
,
3247 TALLOC_CTX
*mem_ctx
);
3250 /* A table describing the various print notification constants and
3251 whether the notification data is a pointer to a variable sized
3252 buffer, a one value uint32_t or a two value uint32_t. */
3254 static const struct s_notify_info_data_table notify_info_data_table
[] =
3256 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_SERVER_NAME
, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_server_name
},
3257 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PRINTER_NAME
, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_printer_name
},
3258 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_SHARE_NAME
, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_share_name
},
3259 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PORT_NAME
, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_port_name
},
3260 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_DRIVER_NAME
, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_driver_name
},
3261 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_COMMENT
, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING
, spoolss_notify_comment
},
3262 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_LOCATION
, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING
, spoolss_notify_location
},
3263 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_DEVMODE
, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE
, spoolss_notify_devmode
},
3264 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_SEPFILE
, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING
, spoolss_notify_sepfile
},
3265 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR
, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING
, spoolss_notify_print_processor
},
3266 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PARAMETERS
, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING
, spoolss_notify_parameters
},
3267 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_DATATYPE
, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING
, spoolss_notify_datatype
},
3268 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR
, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR
, spoolss_notify_security_desc
},
3269 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_ATTRIBUTES
, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD
, spoolss_notify_attributes
},
3270 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PRIORITY
, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD
, spoolss_notify_priority
},
3271 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY
, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD
, spoolss_notify_default_priority
},
3272 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_START_TIME
, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_start_time
},
3273 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_UNTIL_TIME
, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_until_time
},
3274 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_STATUS
, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD
, spoolss_notify_status
},
3275 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_STATUS_STRING
, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING
, NULL
},
3276 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_CJOBS
, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD
, spoolss_notify_cjobs
},
3277 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_AVERAGE_PPM
, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD
, spoolss_notify_average_ppm
},
3278 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_TOTAL_PAGES
, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD
, NULL
},
3279 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PAGES_PRINTED
, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD
, NULL
},
3280 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_TOTAL_BYTES
, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD
, NULL
},
3281 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_BYTES_PRINTED
, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD
, NULL
},
3282 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PRINTER_NAME
, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_printer_name
},
3283 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_MACHINE_NAME
, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_server_name
},
3284 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PORT_NAME
, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_port_name
},
3285 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_USER_NAME
, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_username
},
3286 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_NOTIFY_NAME
, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_username
},
3287 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_DATATYPE
, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING
, spoolss_notify_datatype
},
3288 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PRINT_PROCESSOR
, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING
, spoolss_notify_print_processor
},
3289 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PARAMETERS
, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING
, spoolss_notify_parameters
},
3290 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_DRIVER_NAME
, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_driver_name
},
3291 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_DEVMODE
, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE
, spoolss_notify_devmode
},
3292 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_STATUS
, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD
, spoolss_notify_job_status
},
3293 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_STATUS_STRING
, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING
, spoolss_notify_job_status_string
},
3294 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR
, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR
, NULL
},
3295 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_DOCUMENT
, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING
, spoolss_notify_job_name
},
3296 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PRIORITY
, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD
, spoolss_notify_priority
},
3297 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_POSITION
, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD
, spoolss_notify_job_position
},
3298 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_SUBMITTED
, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME
, spoolss_notify_submitted_time
},
3299 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_START_TIME
, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_start_time
},
3300 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_UNTIL_TIME
, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_until_time
},
3301 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_TIME
, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_job_time
},
3302 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_TOTAL_PAGES
, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD
, spoolss_notify_total_pages
},
3303 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PAGES_PRINTED
, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD
, spoolss_notify_pages_printed
},
3304 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_TOTAL_BYTES
, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD
, spoolss_notify_job_size
},
3307 /*******************************************************************
3308 Return the variable_type of info_data structure.
3309 ********************************************************************/
3311 static enum spoolss_NotifyTable
variable_type_of_notify_info_data(enum spoolss_NotifyType type
,
3316 for (i
= 0; i
< ARRAY_SIZE(notify_info_data_table
); i
++) {
3317 if ( (notify_info_data_table
[i
].type
== type
) &&
3318 (notify_info_data_table
[i
].field
== field
) ) {
3319 return notify_info_data_table
[i
].variable_type
;
3323 DEBUG(5, ("invalid notify data type %d/%d\n", type
, field
));
3325 return (enum spoolss_NotifyTable
) 0;
3328 /****************************************************************************
3329 ****************************************************************************/
3331 static bool search_notify(enum spoolss_NotifyType type
,
3337 for (i
= 0; i
< ARRAY_SIZE(notify_info_data_table
); i
++) {
3338 if (notify_info_data_table
[i
].type
== type
&&
3339 notify_info_data_table
[i
].field
== field
&&
3340 notify_info_data_table
[i
].fn
!= NULL
) {
3349 /****************************************************************************
3350 ****************************************************************************/
3352 static void construct_info_data(struct spoolss_Notify
*info_data
,
3353 enum spoolss_NotifyType type
,
3354 uint16_t field
, int id
)
3356 info_data
->type
= type
;
3357 info_data
->field
.field
= field
;
3358 info_data
->variable_type
= variable_type_of_notify_info_data(type
, field
);
3359 info_data
->job_id
= id
;
3362 /*******************************************************************
3364 * fill a notify_info struct with info asked
3366 ********************************************************************/
3368 static bool construct_notify_printer_info(struct messaging_context
*msg_ctx
,
3369 struct printer_handle
*print_hnd
,
3370 struct spoolss_NotifyInfo
*info
,
3371 struct spoolss_PrinterInfo2
*pinfo2
,
3373 const struct spoolss_NotifyOptionType
*option_type
,
3375 TALLOC_CTX
*mem_ctx
)
3378 enum spoolss_NotifyType type
;
3381 struct spoolss_Notify
*current_data
;
3383 type
= option_type
->type
;
3385 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3386 (type
== PRINTER_NOTIFY_TYPE
? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3387 option_type
->count
, lp_servicename(talloc_tos(), snum
)));
3389 for(field_num
=0; field_num
< option_type
->count
; field_num
++) {
3390 field
= option_type
->fields
[field_num
].field
;
3392 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num
, type
, field
));
3394 if (!search_notify(type
, field
, &j
) )
3397 info
->notifies
= talloc_realloc(info
, info
->notifies
,
3398 struct spoolss_Notify
,
3400 if (info
->notifies
== NULL
) {
3401 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3405 current_data
= &info
->notifies
[info
->count
];
3407 construct_info_data(current_data
, type
, field
, id
);
3409 DEBUG(10, ("construct_notify_printer_info: "
3410 "calling [%s] snum=%d printername=[%s])\n",
3411 notify_info_data_table
[j
].name
, snum
,
3412 pinfo2
->printername
));
3414 notify_info_data_table
[j
].fn(msg_ctx
, snum
, current_data
,
3415 NULL
, pinfo2
, mem_ctx
);
3423 /*******************************************************************
3425 * fill a notify_info struct with info asked
3427 ********************************************************************/
3429 static bool construct_notify_jobs_info(struct messaging_context
*msg_ctx
,
3430 print_queue_struct
*queue
,
3431 struct spoolss_NotifyInfo
*info
,
3432 struct spoolss_PrinterInfo2
*pinfo2
,
3434 const struct spoolss_NotifyOptionType
*option_type
,
3436 TALLOC_CTX
*mem_ctx
)
3439 enum spoolss_NotifyType type
;
3441 struct spoolss_Notify
*current_data
;
3443 DEBUG(4,("construct_notify_jobs_info\n"));
3445 type
= option_type
->type
;
3447 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3448 (type
== PRINTER_NOTIFY_TYPE
? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3449 option_type
->count
));
3451 for(field_num
=0; field_num
<option_type
->count
; field_num
++) {
3452 field
= option_type
->fields
[field_num
].field
;
3454 if (!search_notify(type
, field
, &j
) )
3457 info
->notifies
= talloc_realloc(info
, info
->notifies
,
3458 struct spoolss_Notify
,
3460 if (info
->notifies
== NULL
) {
3461 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3465 current_data
=&(info
->notifies
[info
->count
]);
3467 construct_info_data(current_data
, type
, field
, id
);
3468 notify_info_data_table
[j
].fn(msg_ctx
, snum
, current_data
,
3469 queue
, pinfo2
, mem_ctx
);
3477 * JFM: The enumeration is not that simple, it's even non obvious.
3479 * let's take an example: I want to monitor the PRINTER SERVER for
3480 * the printer's name and the number of jobs currently queued.
3481 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3482 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3484 * I have 3 printers on the back of my server.
3486 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3489 * 1 printer 1 name 1
3490 * 2 printer 1 cjob 1
3491 * 3 printer 2 name 2
3492 * 4 printer 2 cjob 2
3493 * 5 printer 3 name 3
3494 * 6 printer 3 name 3
3496 * that's the print server case, the printer case is even worse.
3499 /*******************************************************************
3501 * enumerate all printers on the printserver
3502 * fill a notify_info struct with info asked
3504 ********************************************************************/
3506 static WERROR
printserver_notify_info(struct pipes_struct
*p
,
3507 struct policy_handle
*hnd
,
3508 struct spoolss_NotifyInfo
*info
,
3509 TALLOC_CTX
*mem_ctx
)
3512 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, hnd
);
3513 int n_services
=lp_numservices();
3515 struct spoolss_NotifyOption
*option
;
3516 struct spoolss_NotifyOptionType option_type
;
3517 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
3520 DEBUG(4,("printserver_notify_info\n"));
3525 option
= Printer
->notify
.option
;
3528 info
->notifies
= NULL
;
3531 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3532 sending a ffpcn() request first */
3537 for (i
=0; i
<option
->count
; i
++) {
3538 option_type
= option
->types
[i
];
3540 if (option_type
.type
!= PRINTER_NOTIFY_TYPE
)
3543 for (snum
= 0; snum
< n_services
; snum
++) {
3544 if (!lp_browseable(snum
) ||
3545 !lp_snum_ok(snum
) ||
3546 !lp_print_ok(snum
)) {
3547 continue; /* skip */
3550 /* Maybe we should use the SYSTEM session_info here... */
3551 result
= winreg_get_printer_internal(mem_ctx
,
3552 get_session_info_system(),
3554 lp_servicename(talloc_tos(), snum
),
3556 if (!W_ERROR_IS_OK(result
)) {
3557 DEBUG(4, ("printserver_notify_info: "
3558 "Failed to get printer [%s]\n",
3559 lp_servicename(talloc_tos(), snum
)));
3564 construct_notify_printer_info(p
->msg_ctx
,
3570 TALLOC_FREE(pinfo2
);
3576 * Debugging information, don't delete.
3579 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3580 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info
->version
, info
->flags
, info
->count
));
3581 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3583 for (i
=0; i
<info
->count
; i
++) {
3584 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3585 i
, info
->data
[i
].type
, info
->data
[i
].field
, info
->data
[i
].reserved
,
3586 info
->data
[i
].id
, info
->data
[i
].size
, info
->data
[i
].enc_type
));
3593 /*******************************************************************
3595 * fill a notify_info struct with info asked
3597 ********************************************************************/
3599 static WERROR
printer_notify_info(struct pipes_struct
*p
,
3600 struct policy_handle
*hnd
,
3601 struct spoolss_NotifyInfo
*info
,
3602 TALLOC_CTX
*mem_ctx
)
3605 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, hnd
);
3608 struct spoolss_NotifyOption
*option
;
3609 struct spoolss_NotifyOptionType option_type
;
3611 print_queue_struct
*queue
=NULL
;
3612 print_status_struct status
;
3613 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
3615 struct tdb_print_db
*pdb
;
3617 DEBUG(4,("printer_notify_info\n"));
3622 option
= Printer
->notify
.option
;
3626 info
->notifies
= NULL
;
3629 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3630 sending a ffpcn() request first */
3635 if (!get_printer_snum(p
, hnd
, &snum
, NULL
)) {
3639 pdb
= get_print_db_byname(Printer
->sharename
);
3644 /* Maybe we should use the SYSTEM session_info here... */
3645 result
= winreg_get_printer_internal(mem_ctx
,
3646 get_session_info_system(),
3648 lp_servicename(talloc_tos(), snum
), &pinfo2
);
3649 if (!W_ERROR_IS_OK(result
)) {
3650 result
= WERR_BADFID
;
3655 * When sending a PRINTER_NOTIFY_FIELD_SERVER_NAME we should send the
3656 * correct servername.
3658 pinfo2
->servername
= talloc_strdup(pinfo2
, Printer
->servername
);
3659 if (pinfo2
->servername
== NULL
) {
3660 result
= WERR_NOMEM
;
3664 for (i
= 0; i
< option
->count
; i
++) {
3665 option_type
= option
->types
[i
];
3667 switch (option_type
.type
) {
3668 case PRINTER_NOTIFY_TYPE
:
3669 if (construct_notify_printer_info(p
->msg_ctx
,
3678 case JOB_NOTIFY_TYPE
:
3680 count
= print_queue_status(p
->msg_ctx
, snum
, &queue
,
3683 for (j
= 0; j
< count
; j
++) {
3685 jobid
= sysjob_to_jobid_pdb(pdb
,
3687 if (jobid
== (uint32_t)-1) {
3688 DEBUG(2, ("ignoring untracked job %d\n",
3692 /* FIXME check return value */
3693 construct_notify_jobs_info(p
->msg_ctx
,
3707 * Debugging information, don't delete.
3710 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3711 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3712 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3714 for (i=0; i<info->count; i++) {
3715 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3716 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3717 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3721 talloc_free(pinfo2
);
3724 release_print_db(pdb
);
3728 /****************************************************************
3729 _spoolss_RouterRefreshPrinterChangeNotify
3730 ****************************************************************/
3732 WERROR
_spoolss_RouterRefreshPrinterChangeNotify(struct pipes_struct
*p
,
3733 struct spoolss_RouterRefreshPrinterChangeNotify
*r
)
3735 struct spoolss_NotifyInfo
*info
;
3737 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
3738 WERROR result
= WERR_BADFID
;
3740 /* we always have a spoolss_NotifyInfo struct */
3741 info
= talloc_zero(p
->mem_ctx
, struct spoolss_NotifyInfo
);
3743 result
= WERR_NOMEM
;
3747 *r
->out
.info
= info
;
3750 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3751 "Invalid handle (%s:%u:%u).\n",
3752 OUR_HANDLE(r
->in
.handle
)));
3756 DEBUG(4,("Printer type %x\n",Printer
->printer_type
));
3759 * We are now using the change value, and
3760 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3761 * I don't have a global notification system, I'm sending back all the
3762 * information even when _NOTHING_ has changed.
3765 /* We need to keep track of the change value to send back in
3766 RRPCN replies otherwise our updates are ignored. */
3768 Printer
->notify
.fnpcn
= true;
3770 if (Printer
->notify
.cli_chan
!= NULL
&&
3771 Printer
->notify
.cli_chan
->active_connections
> 0) {
3772 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3773 "Saving change value in request [%x]\n",
3775 Printer
->notify
.change
= r
->in
.change_low
;
3778 /* just ignore the spoolss_NotifyOption */
3780 switch (Printer
->printer_type
) {
3782 result
= printserver_notify_info(p
, r
->in
.handle
,
3786 case SPLHND_PRINTER
:
3787 result
= printer_notify_info(p
, r
->in
.handle
,
3792 Printer
->notify
.fnpcn
= false;
3798 /********************************************************************
3799 ********************************************************************/
3801 static WERROR
create_printername(TALLOC_CTX
*mem_ctx
,
3802 const char *servername
,
3803 const char *printername
,
3804 const char **printername_p
)
3806 /* FIXME: add lp_force_printername() */
3808 if (servername
== NULL
) {
3809 *printername_p
= talloc_strdup(mem_ctx
, printername
);
3810 W_ERROR_HAVE_NO_MEMORY(*printername_p
);
3814 if (servername
[0] == '\\' && servername
[1] == '\\') {
3818 *printername_p
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s", servername
, printername
);
3819 W_ERROR_HAVE_NO_MEMORY(*printername_p
);
3824 /********************************************************************
3825 ********************************************************************/
3827 static void compose_devicemode_devicename(struct spoolss_DeviceMode
*dm
,
3828 const char *printername
)
3834 dm
->devicename
= talloc_strndup(dm
, printername
,
3835 MIN(strlen(printername
), 31));
3838 /********************************************************************
3839 * construct_printer_info_0
3840 * fill a printer_info_0 struct
3841 ********************************************************************/
3843 static WERROR
construct_printer_info0(TALLOC_CTX
*mem_ctx
,
3844 const struct auth_session_info
*session_info
,
3845 struct messaging_context
*msg_ctx
,
3846 struct spoolss_PrinterInfo2
*info2
,
3847 const char *servername
,
3848 struct spoolss_PrinterInfo0
*r
,
3852 struct printer_session_counter
*session_counter
;
3853 struct timeval setuptime
;
3854 print_status_struct status
;
3857 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->printername
);
3858 if (!W_ERROR_IS_OK(result
)) {
3863 r
->servername
= talloc_strdup(mem_ctx
, servername
);
3864 W_ERROR_HAVE_NO_MEMORY(r
->servername
);
3866 r
->servername
= NULL
;
3869 count
= print_queue_length(msg_ctx
, snum
, &status
);
3871 /* check if we already have a counter for this printer */
3872 for (session_counter
= counter_list
; session_counter
; session_counter
= session_counter
->next
) {
3873 if (session_counter
->snum
== snum
)
3877 /* it's the first time, add it to the list */
3878 if (session_counter
== NULL
) {
3879 session_counter
= talloc_zero(counter_list
, struct printer_session_counter
);
3880 W_ERROR_HAVE_NO_MEMORY(session_counter
);
3881 session_counter
->snum
= snum
;
3882 session_counter
->counter
= 0;
3883 DLIST_ADD(counter_list
, session_counter
);
3887 session_counter
->counter
++;
3893 get_startup_time(&setuptime
);
3894 init_systemtime(&r
->time
, gmtime(&setuptime
.tv_sec
));
3897 * the global_counter should be stored in a TDB as it's common to all the clients
3898 * and should be zeroed on samba startup
3900 r
->global_counter
= session_counter
->counter
;
3902 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3903 SSVAL(&r
->version
, 0, 0x0005); /* NT 5 */
3904 SSVAL(&r
->version
, 2, 0x0893); /* build 2195 */
3905 r
->free_build
= SPOOLSS_RELEASE_BUILD
;
3907 r
->max_spooling
= 0;
3908 r
->session_counter
= session_counter
->counter
;
3909 r
->num_error_out_of_paper
= 0x0;
3910 r
->num_error_not_ready
= 0x0; /* number of print failure */
3912 r
->number_of_processors
= 0x1;
3913 r
->processor_type
= PROCESSOR_INTEL_PENTIUM
; /* 586 Pentium ? */
3914 r
->high_part_total_bytes
= 0x0;
3916 /* ChangeID in milliseconds*/
3917 winreg_printer_get_changeid_internal(mem_ctx
, session_info
, msg_ctx
,
3918 info2
->sharename
, &r
->change_id
);
3920 r
->last_error
= WERR_OK
;
3921 r
->status
= nt_printq_status(status
.status
);
3922 r
->enumerate_network_printers
= 0x0;
3923 r
->c_setprinter
= 0x0;
3924 r
->processor_architecture
= PROCESSOR_ARCHITECTURE_INTEL
;
3925 r
->processor_level
= 0x6; /* 6 ???*/
3934 /********************************************************************
3935 * construct_printer_info1
3936 * fill a spoolss_PrinterInfo1 struct
3937 ********************************************************************/
3939 static WERROR
construct_printer_info1(TALLOC_CTX
*mem_ctx
,
3940 const struct spoolss_PrinterInfo2
*info2
,
3942 const char *servername
,
3943 struct spoolss_PrinterInfo1
*r
,
3950 if (info2
->comment
== NULL
|| info2
->comment
[0] == '\0') {
3951 r
->comment
= lp_comment(mem_ctx
, snum
);
3953 r
->comment
= talloc_strdup(mem_ctx
, info2
->comment
); /* saved comment */
3955 W_ERROR_HAVE_NO_MEMORY(r
->comment
);
3957 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->name
);
3958 if (!W_ERROR_IS_OK(result
)) {
3962 r
->description
= talloc_asprintf(mem_ctx
, "%s,%s,%s",
3966 W_ERROR_HAVE_NO_MEMORY(r
->description
);
3971 /********************************************************************
3972 * construct_printer_info2
3973 * fill a spoolss_PrinterInfo2 struct
3974 ********************************************************************/
3976 static WERROR
construct_printer_info2(TALLOC_CTX
*mem_ctx
,
3977 struct messaging_context
*msg_ctx
,
3978 const struct spoolss_PrinterInfo2
*info2
,
3979 const char *servername
,
3980 struct spoolss_PrinterInfo2
*r
,
3984 print_status_struct status
;
3987 count
= print_queue_length(msg_ctx
, snum
, &status
);
3990 r
->servername
= talloc_strdup(mem_ctx
, servername
);
3991 W_ERROR_HAVE_NO_MEMORY(r
->servername
);
3993 r
->servername
= NULL
;
3996 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->printername
);
3997 if (!W_ERROR_IS_OK(result
)) {
4001 r
->sharename
= lp_servicename(mem_ctx
, snum
);
4002 W_ERROR_HAVE_NO_MEMORY(r
->sharename
);
4003 r
->portname
= talloc_strdup(mem_ctx
, info2
->portname
);
4004 W_ERROR_HAVE_NO_MEMORY(r
->portname
);
4005 r
->drivername
= talloc_strdup(mem_ctx
, info2
->drivername
);
4006 W_ERROR_HAVE_NO_MEMORY(r
->drivername
);
4008 if (info2
->comment
[0] == '\0') {
4009 r
->comment
= lp_comment(mem_ctx
, snum
);
4011 r
->comment
= talloc_strdup(mem_ctx
, info2
->comment
);
4013 W_ERROR_HAVE_NO_MEMORY(r
->comment
);
4015 r
->location
= talloc_strdup(mem_ctx
, info2
->location
);
4016 if (info2
->location
[0] == '\0') {
4017 const char *loc
= NULL
;
4020 nt_status
= printer_list_get_printer(mem_ctx
,
4025 if (NT_STATUS_IS_OK(nt_status
)) {
4027 r
->location
= talloc_strdup(mem_ctx
, loc
);
4031 W_ERROR_HAVE_NO_MEMORY(r
->location
);
4033 r
->sepfile
= talloc_strdup(mem_ctx
, info2
->sepfile
);
4034 W_ERROR_HAVE_NO_MEMORY(r
->sepfile
);
4035 r
->printprocessor
= talloc_strdup(mem_ctx
, info2
->printprocessor
);
4036 W_ERROR_HAVE_NO_MEMORY(r
->printprocessor
);
4037 r
->datatype
= talloc_strdup(mem_ctx
, info2
->datatype
);
4038 W_ERROR_HAVE_NO_MEMORY(r
->datatype
);
4039 r
->parameters
= talloc_strdup(mem_ctx
, info2
->parameters
);
4040 W_ERROR_HAVE_NO_MEMORY(r
->parameters
);
4042 r
->attributes
= info2
->attributes
;
4044 r
->priority
= info2
->priority
;
4045 r
->defaultpriority
= info2
->defaultpriority
;
4046 r
->starttime
= info2
->starttime
;
4047 r
->untiltime
= info2
->untiltime
;
4048 r
->status
= nt_printq_status(status
.status
);
4050 r
->averageppm
= info2
->averageppm
;
4052 if (info2
->devmode
!= NULL
) {
4053 result
= copy_devicemode(mem_ctx
,
4056 if (!W_ERROR_IS_OK(result
)) {
4059 } else if (lp_default_devmode(snum
)) {
4060 result
= spoolss_create_default_devmode(mem_ctx
,
4063 if (!W_ERROR_IS_OK(result
)) {
4068 DEBUG(8,("Returning NULL Devicemode!\n"));
4071 compose_devicemode_devicename(r
->devmode
, r
->printername
);
4075 if (info2
->secdesc
!= NULL
) {
4076 /* don't use talloc_steal() here unless you do a deep steal of all
4077 the SEC_DESC members */
4079 r
->secdesc
= dup_sec_desc(mem_ctx
, info2
->secdesc
);
4085 /********************************************************************
4086 * construct_printer_info3
4087 * fill a spoolss_PrinterInfo3 struct
4088 ********************************************************************/
4090 static WERROR
construct_printer_info3(TALLOC_CTX
*mem_ctx
,
4091 const struct spoolss_PrinterInfo2
*info2
,
4092 const char *servername
,
4093 struct spoolss_PrinterInfo3
*r
,
4096 /* These are the components of the SD we are returning. */
4098 if (info2
->secdesc
!= NULL
) {
4099 /* don't use talloc_steal() here unless you do a deep steal of all
4100 the SEC_DESC members */
4102 r
->secdesc
= dup_sec_desc(mem_ctx
, info2
->secdesc
);
4103 W_ERROR_HAVE_NO_MEMORY(r
->secdesc
);
4109 /********************************************************************
4110 * construct_printer_info4
4111 * fill a spoolss_PrinterInfo4 struct
4112 ********************************************************************/
4114 static WERROR
construct_printer_info4(TALLOC_CTX
*mem_ctx
,
4115 const struct spoolss_PrinterInfo2
*info2
,
4116 const char *servername
,
4117 struct spoolss_PrinterInfo4
*r
,
4122 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->printername
);
4123 if (!W_ERROR_IS_OK(result
)) {
4128 r
->servername
= talloc_strdup(mem_ctx
, servername
);
4129 W_ERROR_HAVE_NO_MEMORY(r
->servername
);
4131 r
->servername
= NULL
;
4134 r
->attributes
= info2
->attributes
;
4139 /********************************************************************
4140 * construct_printer_info5
4141 * fill a spoolss_PrinterInfo5 struct
4142 ********************************************************************/
4144 static WERROR
construct_printer_info5(TALLOC_CTX
*mem_ctx
,
4145 const struct spoolss_PrinterInfo2
*info2
,
4146 const char *servername
,
4147 struct spoolss_PrinterInfo5
*r
,
4152 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->printername
);
4153 if (!W_ERROR_IS_OK(result
)) {
4157 r
->portname
= talloc_strdup(mem_ctx
, info2
->portname
);
4158 W_ERROR_HAVE_NO_MEMORY(r
->portname
);
4160 r
->attributes
= info2
->attributes
;
4162 /* these two are not used by NT+ according to MSDN */
4163 r
->device_not_selected_timeout
= 0x0; /* have seen 0x3a98 */
4164 r
->transmission_retry_timeout
= 0x0; /* have seen 0xafc8 */
4169 /********************************************************************
4170 * construct_printer_info_6
4171 * fill a spoolss_PrinterInfo6 struct
4172 ********************************************************************/
4174 static WERROR
construct_printer_info6(TALLOC_CTX
*mem_ctx
,
4175 struct messaging_context
*msg_ctx
,
4176 const struct spoolss_PrinterInfo2
*info2
,
4177 const char *servername
,
4178 struct spoolss_PrinterInfo6
*r
,
4181 print_status_struct status
;
4183 print_queue_length(msg_ctx
, snum
, &status
);
4185 r
->status
= nt_printq_status(status
.status
);
4190 /********************************************************************
4191 * construct_printer_info7
4192 * fill a spoolss_PrinterInfo7 struct
4193 ********************************************************************/
4195 static WERROR
construct_printer_info7(TALLOC_CTX
*mem_ctx
,
4196 struct messaging_context
*msg_ctx
,
4197 const char *servername
,
4198 struct spoolss_PrinterInfo7
*r
,
4201 const struct auth_session_info
*session_info
;
4204 TALLOC_CTX
*tmp_ctx
= talloc_new(mem_ctx
);
4205 if (tmp_ctx
== NULL
) {
4209 session_info
= get_session_info_system();
4210 SMB_ASSERT(session_info
!= NULL
);
4212 printer
= lp_servicename(tmp_ctx
, snum
);
4213 if (printer
== NULL
) {
4214 DEBUG(0, ("invalid printer snum %d\n", snum
));
4215 werr
= WERR_INVALID_PARAM
;
4219 if (is_printer_published(tmp_ctx
, session_info
, msg_ctx
,
4220 servername
, printer
, NULL
)) {
4222 werr
= nt_printer_guid_get(tmp_ctx
, session_info
, msg_ctx
,
4224 if (!W_ERROR_IS_OK(werr
)) {
4227 r
->guid
= talloc_strdup_upper(mem_ctx
, GUID_string2(mem_ctx
, &guid
));
4228 r
->action
= DSPRINT_PUBLISH
;
4230 r
->guid
= talloc_strdup(mem_ctx
, "");
4231 r
->action
= DSPRINT_UNPUBLISH
;
4233 if (r
->guid
== NULL
) {
4240 talloc_free(tmp_ctx
);
4244 /********************************************************************
4245 * construct_printer_info8
4246 * fill a spoolss_PrinterInfo8 struct
4247 ********************************************************************/
4249 static WERROR
construct_printer_info8(TALLOC_CTX
*mem_ctx
,
4250 const struct spoolss_PrinterInfo2
*info2
,
4251 const char *servername
,
4252 struct spoolss_DeviceModeInfo
*r
,
4256 const char *printername
;
4258 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &printername
);
4259 if (!W_ERROR_IS_OK(result
)) {
4263 if (info2
->devmode
!= NULL
) {
4264 result
= copy_devicemode(mem_ctx
,
4267 if (!W_ERROR_IS_OK(result
)) {
4270 } else if (lp_default_devmode(snum
)) {
4271 result
= spoolss_create_default_devmode(mem_ctx
,
4274 if (!W_ERROR_IS_OK(result
)) {
4279 DEBUG(8,("Returning NULL Devicemode!\n"));
4282 compose_devicemode_devicename(r
->devmode
, printername
);
4287 /********************************************************************
4288 Spoolss_enumprinters.
4289 ********************************************************************/
4291 static WERROR
enum_all_printers_info_level(TALLOC_CTX
*mem_ctx
,
4292 const struct auth_session_info
*session_info
,
4293 struct messaging_context
*msg_ctx
,
4294 const char *servername
,
4297 union spoolss_PrinterInfo
**info_p
,
4302 union spoolss_PrinterInfo
*info
= NULL
;
4304 WERROR result
= WERR_OK
;
4305 struct dcerpc_binding_handle
*b
= NULL
;
4306 TALLOC_CTX
*tmp_ctx
= NULL
;
4308 tmp_ctx
= talloc_new(mem_ctx
);
4314 * printer shares are updated on client enumeration. The background
4315 * printer process updates printer_list.tdb at regular intervals.
4318 delete_and_reload_printers(server_event_context(), msg_ctx
);
4321 n_services
= lp_numservices();
4325 for (snum
= 0; snum
< n_services
; snum
++) {
4327 const char *printer
;
4328 struct spoolss_PrinterInfo2
*info2
;
4330 if (!snum_is_shared_printer(snum
)) {
4334 printer
= lp_const_servicename(snum
);
4336 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
4340 result
= winreg_printer_binding_handle(tmp_ctx
,
4344 if (!W_ERROR_IS_OK(result
)) {
4349 result
= winreg_create_printer(tmp_ctx
, b
,
4351 if (!W_ERROR_IS_OK(result
)) {
4355 info
= talloc_realloc(tmp_ctx
, info
,
4356 union spoolss_PrinterInfo
,
4359 result
= WERR_NOMEM
;
4363 result
= winreg_get_printer(tmp_ctx
, b
,
4365 if (!W_ERROR_IS_OK(result
)) {
4371 result
= construct_printer_info0(info
, session_info
,
4374 &info
[count
].info0
, snum
);
4377 result
= construct_printer_info1(info
, info2
, flags
,
4379 &info
[count
].info1
, snum
);
4382 result
= construct_printer_info2(info
, msg_ctx
, info2
,
4384 &info
[count
].info2
, snum
);
4387 result
= construct_printer_info4(info
, info2
,
4389 &info
[count
].info4
, snum
);
4392 result
= construct_printer_info5(info
, info2
,
4394 &info
[count
].info5
, snum
);
4398 result
= WERR_UNKNOWN_LEVEL
;
4402 if (!W_ERROR_IS_OK(result
)) {
4410 if (W_ERROR_IS_OK(result
)) {
4411 *info_p
= talloc_move(mem_ctx
, &info
);
4415 talloc_free(tmp_ctx
);
4420 /********************************************************************
4421 * handle enumeration of printers at level 0
4422 ********************************************************************/
4424 static WERROR
enumprinters_level0(TALLOC_CTX
*mem_ctx
,
4425 const struct auth_session_info
*session_info
,
4426 struct messaging_context
*msg_ctx
,
4428 const char *servername
,
4429 union spoolss_PrinterInfo
**info
,
4432 DEBUG(4,("enum_all_printers_info_0\n"));
4434 return enum_all_printers_info_level(mem_ctx
, session_info
, msg_ctx
,
4435 servername
, 0, flags
, info
, count
);
4439 /********************************************************************
4440 ********************************************************************/
4442 static WERROR
enum_all_printers_info_1(TALLOC_CTX
*mem_ctx
,
4443 const struct auth_session_info
*session_info
,
4444 struct messaging_context
*msg_ctx
,
4445 const char *servername
,
4447 union spoolss_PrinterInfo
**info
,
4450 DEBUG(4,("enum_all_printers_info_1\n"));
4452 return enum_all_printers_info_level(mem_ctx
, session_info
, msg_ctx
,
4453 servername
, 1, flags
, info
, count
);
4456 /********************************************************************
4457 enum_all_printers_info_1_local.
4458 *********************************************************************/
4460 static WERROR
enum_all_printers_info_1_local(TALLOC_CTX
*mem_ctx
,
4461 const struct auth_session_info
*session_info
,
4462 struct messaging_context
*msg_ctx
,
4463 const char *servername
,
4464 union spoolss_PrinterInfo
**info
,
4467 DEBUG(4,("enum_all_printers_info_1_local\n"));
4469 return enum_all_printers_info_1(mem_ctx
, session_info
, msg_ctx
,
4470 servername
, PRINTER_ENUM_ICON8
, info
, count
);
4473 /********************************************************************
4474 enum_all_printers_info_1_name.
4475 *********************************************************************/
4477 static WERROR
enum_all_printers_info_1_name(TALLOC_CTX
*mem_ctx
,
4478 const struct auth_session_info
*session_info
,
4479 struct messaging_context
*msg_ctx
,
4480 const char *servername
,
4481 union spoolss_PrinterInfo
**info
,
4484 const char *s
= servername
;
4486 DEBUG(4,("enum_all_printers_info_1_name\n"));
4488 if (servername
!= NULL
&&
4489 (servername
[0] == '\\') && (servername
[1] == '\\')) {
4493 if (!is_myname_or_ipaddr(s
)) {
4494 return WERR_INVALID_NAME
;
4497 return enum_all_printers_info_1(mem_ctx
, session_info
, msg_ctx
,
4498 servername
, PRINTER_ENUM_ICON8
, info
, count
);
4501 /********************************************************************
4502 enum_all_printers_info_1_network.
4503 *********************************************************************/
4505 static WERROR
enum_all_printers_info_1_network(TALLOC_CTX
*mem_ctx
,
4506 const struct auth_session_info
*session_info
,
4507 struct messaging_context
*msg_ctx
,
4508 const char *servername
,
4509 union spoolss_PrinterInfo
**info
,
4512 const char *s
= servername
;
4514 DEBUG(4,("enum_all_printers_info_1_network\n"));
4516 /* If we respond to a enum_printers level 1 on our name with flags
4517 set to PRINTER_ENUM_REMOTE with a list of printers then these
4518 printers incorrectly appear in the APW browse list.
4519 Specifically the printers for the server appear at the workgroup
4520 level where all the other servers in the domain are
4521 listed. Windows responds to this call with a
4522 WERR_CAN_NOT_COMPLETE so we should do the same. */
4524 if (servername
!= NULL
&&
4525 (servername
[0] == '\\') && (servername
[1] == '\\')) {
4529 if (is_myname_or_ipaddr(s
)) {
4530 return WERR_CAN_NOT_COMPLETE
;
4533 return enum_all_printers_info_1(mem_ctx
, session_info
, msg_ctx
,
4534 servername
, PRINTER_ENUM_NAME
, info
, count
);
4537 /********************************************************************
4538 * api_spoolss_enumprinters
4540 * called from api_spoolss_enumprinters (see this to understand)
4541 ********************************************************************/
4543 static WERROR
enum_all_printers_info_2(TALLOC_CTX
*mem_ctx
,
4544 const struct auth_session_info
*session_info
,
4545 struct messaging_context
*msg_ctx
,
4546 const char *servername
,
4547 union spoolss_PrinterInfo
**info
,
4550 DEBUG(4,("enum_all_printers_info_2\n"));
4552 return enum_all_printers_info_level(mem_ctx
, session_info
, msg_ctx
,
4553 servername
, 2, 0, info
, count
);
4556 /********************************************************************
4557 * handle enumeration of printers at level 1
4558 ********************************************************************/
4560 static WERROR
enumprinters_level1(TALLOC_CTX
*mem_ctx
,
4561 const struct auth_session_info
*session_info
,
4562 struct messaging_context
*msg_ctx
,
4564 const char *servername
,
4565 union spoolss_PrinterInfo
**info
,
4568 /* Not all the flags are equals */
4570 if (flags
& PRINTER_ENUM_LOCAL
) {
4571 return enum_all_printers_info_1_local(mem_ctx
, session_info
,
4572 msg_ctx
, servername
, info
, count
);
4575 if (flags
& PRINTER_ENUM_NAME
) {
4576 return enum_all_printers_info_1_name(mem_ctx
, session_info
,
4577 msg_ctx
, servername
, info
,
4581 if (flags
& PRINTER_ENUM_NETWORK
) {
4582 return enum_all_printers_info_1_network(mem_ctx
, session_info
,
4583 msg_ctx
, servername
, info
,
4587 return WERR_OK
; /* NT4sp5 does that */
4590 /********************************************************************
4591 * handle enumeration of printers at level 2
4592 ********************************************************************/
4594 static WERROR
enumprinters_level2(TALLOC_CTX
*mem_ctx
,
4595 const struct auth_session_info
*session_info
,
4596 struct messaging_context
*msg_ctx
,
4598 const char *servername
,
4599 union spoolss_PrinterInfo
**info
,
4602 if (flags
& PRINTER_ENUM_LOCAL
) {
4604 return enum_all_printers_info_2(mem_ctx
, session_info
, msg_ctx
,
4609 if (flags
& PRINTER_ENUM_NAME
) {
4610 if (servername
&& !is_myname_or_ipaddr(canon_servername(servername
))) {
4611 return WERR_INVALID_NAME
;
4614 return enum_all_printers_info_2(mem_ctx
, session_info
, msg_ctx
,
4619 if (flags
& PRINTER_ENUM_REMOTE
) {
4620 return WERR_UNKNOWN_LEVEL
;
4626 /********************************************************************
4627 * handle enumeration of printers at level 4
4628 ********************************************************************/
4630 static WERROR
enumprinters_level4(TALLOC_CTX
*mem_ctx
,
4631 const struct auth_session_info
*session_info
,
4632 struct messaging_context
*msg_ctx
,
4634 const char *servername
,
4635 union spoolss_PrinterInfo
**info
,
4638 DEBUG(4,("enum_all_printers_info_4\n"));
4640 return enum_all_printers_info_level(mem_ctx
, session_info
, msg_ctx
,
4641 servername
, 4, flags
, info
, count
);
4645 /********************************************************************
4646 * handle enumeration of printers at level 5
4647 ********************************************************************/
4649 static WERROR
enumprinters_level5(TALLOC_CTX
*mem_ctx
,
4650 const struct auth_session_info
*session_info
,
4651 struct messaging_context
*msg_ctx
,
4653 const char *servername
,
4654 union spoolss_PrinterInfo
**info
,
4657 DEBUG(4,("enum_all_printers_info_5\n"));
4659 return enum_all_printers_info_level(mem_ctx
, session_info
, msg_ctx
,
4660 servername
, 5, flags
, info
, count
);
4663 /****************************************************************
4664 _spoolss_EnumPrinters
4665 ****************************************************************/
4667 WERROR
_spoolss_EnumPrinters(struct pipes_struct
*p
,
4668 struct spoolss_EnumPrinters
*r
)
4670 const struct auth_session_info
*session_info
= get_session_info_system();
4673 /* that's an [in out] buffer */
4675 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
4676 return WERR_INVALID_PARAM
;
4679 DEBUG(4,("_spoolss_EnumPrinters\n"));
4683 *r
->out
.info
= NULL
;
4687 * flags==PRINTER_ENUM_NAME
4688 * if name=="" then enumerates all printers
4689 * if name!="" then enumerate the printer
4690 * flags==PRINTER_ENUM_REMOTE
4691 * name is NULL, enumerate printers
4692 * Level 2: name!="" enumerates printers, name can't be NULL
4693 * Level 3: doesn't exist
4694 * Level 4: does a local registry lookup
4695 * Level 5: same as Level 2
4698 if (r
->in
.server
&& r
->in
.server
[0] == '\0') {
4699 r
->in
.server
= NULL
;
4702 switch (r
->in
.level
) {
4704 result
= enumprinters_level0(p
->mem_ctx
, session_info
,
4705 p
->msg_ctx
, r
->in
.flags
,
4707 r
->out
.info
, r
->out
.count
);
4710 result
= enumprinters_level1(p
->mem_ctx
, session_info
,
4711 p
->msg_ctx
, r
->in
.flags
,
4713 r
->out
.info
, r
->out
.count
);
4716 result
= enumprinters_level2(p
->mem_ctx
, session_info
,
4717 p
->msg_ctx
, r
->in
.flags
,
4719 r
->out
.info
, r
->out
.count
);
4722 result
= enumprinters_level4(p
->mem_ctx
, session_info
,
4723 p
->msg_ctx
, r
->in
.flags
,
4725 r
->out
.info
, r
->out
.count
);
4728 result
= enumprinters_level5(p
->mem_ctx
, session_info
,
4729 p
->msg_ctx
, r
->in
.flags
,
4731 r
->out
.info
, r
->out
.count
);
4734 return WERR_UNKNOWN_LEVEL
;
4737 if (!W_ERROR_IS_OK(result
)) {
4741 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
4742 spoolss_EnumPrinters
,
4743 *r
->out
.info
, r
->in
.level
,
4745 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
4746 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
4748 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
4751 /****************************************************************
4753 ****************************************************************/
4755 WERROR
_spoolss_GetPrinter(struct pipes_struct
*p
,
4756 struct spoolss_GetPrinter
*r
)
4758 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
4759 struct spoolss_PrinterInfo2
*info2
= NULL
;
4760 WERROR result
= WERR_OK
;
4763 /* that's an [in out] buffer */
4765 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
4766 return WERR_INVALID_PARAM
;
4771 if (Printer
== NULL
) {
4775 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
4779 result
= winreg_get_printer_internal(p
->mem_ctx
,
4780 get_session_info_system(),
4782 lp_const_servicename(snum
),
4784 if (!W_ERROR_IS_OK(result
)) {
4788 switch (r
->in
.level
) {
4790 result
= construct_printer_info0(p
->mem_ctx
,
4791 get_session_info_system(),
4794 Printer
->servername
,
4795 &r
->out
.info
->info0
,
4799 result
= construct_printer_info1(p
->mem_ctx
, info2
,
4801 Printer
->servername
,
4802 &r
->out
.info
->info1
, snum
);
4805 result
= construct_printer_info2(p
->mem_ctx
, p
->msg_ctx
, info2
,
4806 Printer
->servername
,
4807 &r
->out
.info
->info2
, snum
);
4810 result
= construct_printer_info3(p
->mem_ctx
, info2
,
4811 Printer
->servername
,
4812 &r
->out
.info
->info3
, snum
);
4815 result
= construct_printer_info4(p
->mem_ctx
, info2
,
4816 Printer
->servername
,
4817 &r
->out
.info
->info4
, snum
);
4820 result
= construct_printer_info5(p
->mem_ctx
, info2
,
4821 Printer
->servername
,
4822 &r
->out
.info
->info5
, snum
);
4825 result
= construct_printer_info6(p
->mem_ctx
, p
->msg_ctx
, info2
,
4826 Printer
->servername
,
4827 &r
->out
.info
->info6
, snum
);
4830 result
= construct_printer_info7(p
->mem_ctx
, p
->msg_ctx
,
4831 Printer
->servername
,
4832 &r
->out
.info
->info7
, snum
);
4835 result
= construct_printer_info8(p
->mem_ctx
, info2
,
4836 Printer
->servername
,
4837 &r
->out
.info
->info8
, snum
);
4840 result
= WERR_UNKNOWN_LEVEL
;
4846 if (!W_ERROR_IS_OK(result
)) {
4847 DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
4848 r
->in
.level
, win_errstr(result
)));
4849 TALLOC_FREE(r
->out
.info
);
4853 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo
,
4854 r
->out
.info
, r
->in
.level
);
4855 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
4857 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
4860 /********************************************************************
4861 ********************************************************************/
4863 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4865 if (in && strlen(in)) { \
4866 out = talloc_strdup(mem_ctx, in); \
4868 out = talloc_strdup(mem_ctx, ""); \
4870 W_ERROR_HAVE_NO_MEMORY(out); \
4873 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, arch, ver, in, out) \
4875 if (in && strlen(in)) { \
4876 out = talloc_asprintf(mem_ctx, "\\\\%s\\print$\\%s\\%d\\%s", server, get_short_archi(arch), ver, in); \
4878 out = talloc_strdup(mem_ctx, ""); \
4880 W_ERROR_HAVE_NO_MEMORY(out); \
4883 static WERROR
string_array_from_driver_info(TALLOC_CTX
*mem_ctx
,
4884 const char **string_array
,
4885 const char ***presult
,
4886 const char *cservername
,
4890 int i
, num_strings
= 0;
4891 const char **array
= NULL
;
4893 if (string_array
== NULL
) {
4894 return WERR_INVALID_PARAMETER
;
4897 for (i
=0; string_array
[i
] && string_array
[i
][0] != '\0'; i
++) {
4898 const char *str
= NULL
;
4900 if (cservername
== NULL
|| arch
== NULL
) {
4901 FILL_DRIVER_STRING(mem_ctx
, string_array
[i
], str
);
4903 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
, arch
, version
, string_array
[i
], str
);
4906 if (!add_string_to_array(mem_ctx
, str
, &array
, &num_strings
)) {
4913 ADD_TO_ARRAY(mem_ctx
, const char *, NULL
,
4914 &array
, &num_strings
);
4917 if (presult
!= NULL
) {
4926 /********************************************************************
4927 * fill a spoolss_DriverInfo1 struct
4928 ********************************************************************/
4930 static WERROR
fill_printer_driver_info1(TALLOC_CTX
*mem_ctx
,
4931 struct spoolss_DriverInfo1
*r
,
4932 const struct spoolss_DriverInfo8
*driver
,
4933 const char *servername
)
4935 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
4936 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
4941 /********************************************************************
4942 * fill a spoolss_DriverInfo2 struct
4943 ********************************************************************/
4945 static WERROR
fill_printer_driver_info2(TALLOC_CTX
*mem_ctx
,
4946 struct spoolss_DriverInfo2
*r
,
4947 const struct spoolss_DriverInfo8
*driver
,
4948 const char *servername
)
4951 const char *cservername
= canon_servername(servername
);
4953 r
->version
= driver
->version
;
4955 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
4956 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
4957 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
4958 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
4960 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4961 driver
->architecture
,
4963 driver
->driver_path
,
4966 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4967 driver
->architecture
,
4972 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4973 driver
->architecture
,
4975 driver
->config_file
,
4981 /********************************************************************
4982 * fill a spoolss_DriverInfo3 struct
4983 ********************************************************************/
4985 static WERROR
fill_printer_driver_info3(TALLOC_CTX
*mem_ctx
,
4986 struct spoolss_DriverInfo3
*r
,
4987 const struct spoolss_DriverInfo8
*driver
,
4988 const char *servername
)
4990 const char *cservername
= canon_servername(servername
);
4992 r
->version
= driver
->version
;
4994 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
4995 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
4996 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
4997 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
4999 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5000 driver
->architecture
,
5002 driver
->driver_path
,
5005 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5006 driver
->architecture
,
5011 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5012 driver
->architecture
,
5014 driver
->config_file
,
5017 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5018 driver
->architecture
,
5023 FILL_DRIVER_STRING(mem_ctx
,
5024 driver
->monitor_name
,
5027 FILL_DRIVER_STRING(mem_ctx
,
5028 driver
->default_datatype
,
5029 r
->default_datatype
);
5031 return string_array_from_driver_info(mem_ctx
,
5032 driver
->dependent_files
,
5033 &r
->dependent_files
,
5035 driver
->architecture
,
5039 /********************************************************************
5040 * fill a spoolss_DriverInfo4 struct
5041 ********************************************************************/
5043 static WERROR
fill_printer_driver_info4(TALLOC_CTX
*mem_ctx
,
5044 struct spoolss_DriverInfo4
*r
,
5045 const struct spoolss_DriverInfo8
*driver
,
5046 const char *servername
)
5048 const char *cservername
= canon_servername(servername
);
5051 r
->version
= driver
->version
;
5053 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5054 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5055 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5056 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5058 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5059 driver
->architecture
,
5061 driver
->driver_path
,
5064 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5065 driver
->architecture
,
5070 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5071 driver
->architecture
,
5073 driver
->config_file
,
5076 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5077 driver
->architecture
,
5082 result
= string_array_from_driver_info(mem_ctx
,
5083 driver
->dependent_files
,
5084 &r
->dependent_files
,
5086 driver
->architecture
,
5088 if (!W_ERROR_IS_OK(result
)) {
5092 FILL_DRIVER_STRING(mem_ctx
,
5093 driver
->monitor_name
,
5096 FILL_DRIVER_STRING(mem_ctx
,
5097 driver
->default_datatype
,
5098 r
->default_datatype
);
5101 result
= string_array_from_driver_info(mem_ctx
,
5102 driver
->previous_names
,
5109 /********************************************************************
5110 * fill a spoolss_DriverInfo5 struct
5111 ********************************************************************/
5113 static WERROR
fill_printer_driver_info5(TALLOC_CTX
*mem_ctx
,
5114 struct spoolss_DriverInfo5
*r
,
5115 const struct spoolss_DriverInfo8
*driver
,
5116 const char *servername
)
5118 const char *cservername
= canon_servername(servername
);
5120 r
->version
= driver
->version
;
5122 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5123 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5124 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5125 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5127 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5128 driver
->architecture
,
5130 driver
->driver_path
,
5133 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5134 driver
->architecture
,
5139 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5140 driver
->architecture
,
5142 driver
->config_file
,
5145 r
->driver_attributes
= 0;
5146 r
->config_version
= 0;
5147 r
->driver_version
= 0;
5151 /********************************************************************
5152 * fill a spoolss_DriverInfo6 struct
5153 ********************************************************************/
5155 static WERROR
fill_printer_driver_info6(TALLOC_CTX
*mem_ctx
,
5156 struct spoolss_DriverInfo6
*r
,
5157 const struct spoolss_DriverInfo8
*driver
,
5158 const char *servername
)
5160 const char *cservername
= canon_servername(servername
);
5163 r
->version
= driver
->version
;
5165 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5166 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5167 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5168 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5170 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5171 driver
->architecture
,
5173 driver
->driver_path
,
5176 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5177 driver
->architecture
,
5182 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5183 driver
->architecture
,
5185 driver
->config_file
,
5188 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5189 driver
->architecture
,
5194 FILL_DRIVER_STRING(mem_ctx
,
5195 driver
->monitor_name
,
5198 FILL_DRIVER_STRING(mem_ctx
,
5199 driver
->default_datatype
,
5200 r
->default_datatype
);
5202 result
= string_array_from_driver_info(mem_ctx
,
5203 driver
->dependent_files
,
5204 &r
->dependent_files
,
5206 driver
->architecture
,
5208 if (!W_ERROR_IS_OK(result
)) {
5212 result
= string_array_from_driver_info(mem_ctx
,
5213 driver
->previous_names
,
5216 if (!W_ERROR_IS_OK(result
)) {
5220 r
->driver_date
= driver
->driver_date
;
5221 r
->driver_version
= driver
->driver_version
;
5223 FILL_DRIVER_STRING(mem_ctx
,
5224 driver
->manufacturer_name
,
5225 r
->manufacturer_name
);
5226 FILL_DRIVER_STRING(mem_ctx
,
5227 driver
->manufacturer_url
,
5228 r
->manufacturer_url
);
5229 FILL_DRIVER_STRING(mem_ctx
,
5230 driver
->hardware_id
,
5232 FILL_DRIVER_STRING(mem_ctx
,
5239 /********************************************************************
5240 * fill a spoolss_DriverInfo8 struct
5241 ********************************************************************/
5243 static WERROR
fill_printer_driver_info8(TALLOC_CTX
*mem_ctx
,
5244 struct spoolss_DriverInfo8
*r
,
5245 const struct spoolss_DriverInfo8
*driver
,
5246 const char *servername
)
5248 const char *cservername
= canon_servername(servername
);
5251 r
->version
= driver
->version
;
5253 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5254 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5255 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5256 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5258 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5259 driver
->architecture
,
5261 driver
->driver_path
,
5264 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5265 driver
->architecture
,
5270 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5271 driver
->architecture
,
5273 driver
->config_file
,
5276 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5277 driver
->architecture
,
5282 FILL_DRIVER_STRING(mem_ctx
,
5283 driver
->monitor_name
,
5286 FILL_DRIVER_STRING(mem_ctx
,
5287 driver
->default_datatype
,
5288 r
->default_datatype
);
5290 result
= string_array_from_driver_info(mem_ctx
,
5291 driver
->dependent_files
,
5292 &r
->dependent_files
,
5294 driver
->architecture
,
5296 if (!W_ERROR_IS_OK(result
)) {
5300 result
= string_array_from_driver_info(mem_ctx
,
5301 driver
->previous_names
,
5304 if (!W_ERROR_IS_OK(result
)) {
5308 r
->driver_date
= driver
->driver_date
;
5309 r
->driver_version
= driver
->driver_version
;
5311 FILL_DRIVER_STRING(mem_ctx
,
5312 driver
->manufacturer_name
,
5313 r
->manufacturer_name
);
5314 FILL_DRIVER_STRING(mem_ctx
,
5315 driver
->manufacturer_url
,
5316 r
->manufacturer_url
);
5317 FILL_DRIVER_STRING(mem_ctx
,
5318 driver
->hardware_id
,
5320 FILL_DRIVER_STRING(mem_ctx
,
5324 FILL_DRIVER_STRING(mem_ctx
,
5325 driver
->print_processor
,
5326 r
->print_processor
);
5327 FILL_DRIVER_STRING(mem_ctx
,
5328 driver
->vendor_setup
,
5331 result
= string_array_from_driver_info(mem_ctx
,
5332 driver
->color_profiles
,
5335 if (!W_ERROR_IS_OK(result
)) {
5339 FILL_DRIVER_STRING(mem_ctx
,
5343 r
->printer_driver_attributes
= driver
->printer_driver_attributes
;
5345 result
= string_array_from_driver_info(mem_ctx
,
5346 driver
->core_driver_dependencies
,
5347 &r
->core_driver_dependencies
,
5349 if (!W_ERROR_IS_OK(result
)) {
5353 r
->min_inbox_driver_ver_date
= driver
->min_inbox_driver_ver_date
;
5354 r
->min_inbox_driver_ver_version
= driver
->min_inbox_driver_ver_version
;
5359 #if 0 /* disabled until marshalling issues are resolved - gd */
5360 /********************************************************************
5361 ********************************************************************/
5363 static WERROR
fill_spoolss_DriverFileInfo(TALLOC_CTX
*mem_ctx
,
5364 struct spoolss_DriverFileInfo
*r
,
5365 const char *cservername
,
5366 const char *file_name
,
5367 enum spoolss_DriverFileType file_type
,
5368 uint32_t file_version
)
5370 r
->file_name
= talloc_asprintf(mem_ctx
, "\\\\%s%s",
5371 cservername
, file_name
);
5372 W_ERROR_HAVE_NO_MEMORY(r
->file_name
);
5373 r
->file_type
= file_type
;
5374 r
->file_version
= file_version
;
5379 /********************************************************************
5380 ********************************************************************/
5382 static WERROR
spoolss_DriverFileInfo_from_driver(TALLOC_CTX
*mem_ctx
,
5383 const struct spoolss_DriverInfo8
*driver
,
5384 const char *cservername
,
5385 struct spoolss_DriverFileInfo
**info_p
,
5388 struct spoolss_DriverFileInfo
*info
= NULL
;
5396 if (strlen(driver
->driver_path
)) {
5397 info
= talloc_realloc(mem_ctx
, info
,
5398 struct spoolss_DriverFileInfo
,
5400 W_ERROR_HAVE_NO_MEMORY(info
);
5401 result
= fill_spoolss_DriverFileInfo(info
,
5404 driver
->driver_path
,
5405 SPOOLSS_DRIVER_FILE_TYPE_RENDERING
,
5407 W_ERROR_NOT_OK_RETURN(result
);
5411 if (strlen(driver
->config_file
)) {
5412 info
= talloc_realloc(mem_ctx
, info
,
5413 struct spoolss_DriverFileInfo
,
5415 W_ERROR_HAVE_NO_MEMORY(info
);
5416 result
= fill_spoolss_DriverFileInfo(info
,
5419 driver
->config_file
,
5420 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION
,
5422 W_ERROR_NOT_OK_RETURN(result
);
5426 if (strlen(driver
->data_file
)) {
5427 info
= talloc_realloc(mem_ctx
, info
,
5428 struct spoolss_DriverFileInfo
,
5430 W_ERROR_HAVE_NO_MEMORY(info
);
5431 result
= fill_spoolss_DriverFileInfo(info
,
5435 SPOOLSS_DRIVER_FILE_TYPE_DATA
,
5437 W_ERROR_NOT_OK_RETURN(result
);
5441 if (strlen(driver
->help_file
)) {
5442 info
= talloc_realloc(mem_ctx
, info
,
5443 struct spoolss_DriverFileInfo
,
5445 W_ERROR_HAVE_NO_MEMORY(info
);
5446 result
= fill_spoolss_DriverFileInfo(info
,
5450 SPOOLSS_DRIVER_FILE_TYPE_HELP
,
5452 W_ERROR_NOT_OK_RETURN(result
);
5456 for (i
=0; driver
->dependent_files
[i
] && driver
->dependent_files
[i
][0] != '\0'; i
++) {
5457 info
= talloc_realloc(mem_ctx
, info
,
5458 struct spoolss_DriverFileInfo
,
5460 W_ERROR_HAVE_NO_MEMORY(info
);
5461 result
= fill_spoolss_DriverFileInfo(info
,
5464 driver
->dependent_files
[i
],
5465 SPOOLSS_DRIVER_FILE_TYPE_OTHER
,
5467 W_ERROR_NOT_OK_RETURN(result
);
5477 /********************************************************************
5478 * fill a spoolss_DriverInfo101 struct
5479 ********************************************************************/
5481 static WERROR
fill_printer_driver_info101(TALLOC_CTX
*mem_ctx
,
5482 struct spoolss_DriverInfo101
*r
,
5483 const struct spoolss_DriverInfo8
*driver
,
5484 const char *servername
)
5486 const char *cservername
= canon_servername(servername
);
5489 r
->version
= driver
->version
;
5491 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5492 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5493 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5494 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5496 result
= spoolss_DriverFileInfo_from_driver(mem_ctx
, driver
,
5500 if (!W_ERROR_IS_OK(result
)) {
5504 FILL_DRIVER_STRING(mem_ctx
,
5505 driver
->monitor_name
,
5508 FILL_DRIVER_STRING(mem_ctx
,
5509 driver
->default_datatype
,
5510 r
->default_datatype
);
5512 result
= string_array_from_driver_info(mem_ctx
,
5513 driver
->previous_names
,
5516 if (!W_ERROR_IS_OK(result
)) {
5520 r
->driver_date
= driver
->driver_date
;
5521 r
->driver_version
= driver
->driver_version
;
5523 FILL_DRIVER_STRING(mem_ctx
,
5524 driver
->manufacturer_name
,
5525 r
->manufacturer_name
);
5526 FILL_DRIVER_STRING(mem_ctx
,
5527 driver
->manufacturer_url
,
5528 r
->manufacturer_url
);
5529 FILL_DRIVER_STRING(mem_ctx
,
5530 driver
->hardware_id
,
5532 FILL_DRIVER_STRING(mem_ctx
,
5539 /********************************************************************
5540 ********************************************************************/
5542 static WERROR
construct_printer_driver_info_level(TALLOC_CTX
*mem_ctx
,
5543 const struct auth_session_info
*session_info
,
5544 struct messaging_context
*msg_ctx
,
5546 union spoolss_DriverInfo
*r
,
5548 const char *servername
,
5549 const char *architecture
,
5552 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
5553 struct spoolss_DriverInfo8
*driver
;
5555 struct dcerpc_binding_handle
*b
;
5556 TALLOC_CTX
*tmp_ctx
= NULL
;
5559 return WERR_UNKNOWN_LEVEL
;
5562 tmp_ctx
= talloc_new(mem_ctx
);
5567 result
= winreg_printer_binding_handle(tmp_ctx
,
5571 if (!W_ERROR_IS_OK(result
)) {
5575 result
= winreg_get_printer(tmp_ctx
, b
,
5576 lp_const_servicename(snum
),
5579 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5580 win_errstr(result
)));
5582 if (!W_ERROR_IS_OK(result
)) {
5583 result
= WERR_INVALID_PRINTER_NAME
;
5587 result
= winreg_get_driver(tmp_ctx
, b
,
5589 pinfo2
->drivername
, version
, &driver
);
5591 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5592 win_errstr(result
)));
5594 if (!W_ERROR_IS_OK(result
)) {
5596 * Is this a W2k client ?
5600 result
= WERR_UNKNOWN_PRINTER_DRIVER
;
5604 /* Yes - try again with a WinNT driver. */
5606 result
= winreg_get_driver(tmp_ctx
, b
,
5610 DEBUG(8,("construct_printer_driver_level: status: %s\n",
5611 win_errstr(result
)));
5612 if (!W_ERROR_IS_OK(result
)) {
5613 result
= WERR_UNKNOWN_PRINTER_DRIVER
;
5618 /* these are allocated on mem_ctx and not tmp_ctx because they are
5619 * the 'return value' and need to utlive this call */
5622 result
= fill_printer_driver_info1(mem_ctx
, &r
->info1
, driver
, servername
);
5625 result
= fill_printer_driver_info2(mem_ctx
, &r
->info2
, driver
, servername
);
5628 result
= fill_printer_driver_info3(mem_ctx
, &r
->info3
, driver
, servername
);
5631 result
= fill_printer_driver_info4(mem_ctx
, &r
->info4
, driver
, servername
);
5634 result
= fill_printer_driver_info5(mem_ctx
, &r
->info5
, driver
, servername
);
5637 result
= fill_printer_driver_info6(mem_ctx
, &r
->info6
, driver
, servername
);
5640 result
= fill_printer_driver_info8(mem_ctx
, &r
->info8
, driver
, servername
);
5642 #if 0 /* disabled until marshalling issues are resolved - gd */
5644 result
= fill_printer_driver_info101(mem_ctx
, &r
->info101
, driver
, servername
);
5648 result
= WERR_UNKNOWN_LEVEL
;
5653 talloc_free(tmp_ctx
);
5657 /****************************************************************
5658 _spoolss_GetPrinterDriver2
5659 ****************************************************************/
5661 WERROR
_spoolss_GetPrinterDriver2(struct pipes_struct
*p
,
5662 struct spoolss_GetPrinterDriver2
*r
)
5664 struct printer_handle
*printer
;
5666 uint32_t version
= r
->in
.client_major_version
;
5670 /* that's an [in out] buffer */
5672 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
5673 return WERR_INVALID_PARAM
;
5676 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5678 if (!(printer
= find_printer_index_by_hnd(p
, r
->in
.handle
))) {
5679 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5680 return WERR_INVALID_PRINTER_NAME
;
5684 *r
->out
.server_major_version
= 0;
5685 *r
->out
.server_minor_version
= 0;
5687 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
5691 if (r
->in
.client_major_version
== SPOOLSS_DRIVER_VERSION_2012
) {
5692 DEBUG(3,("_spoolss_GetPrinterDriver2: v4 driver requested, "
5693 "downgrading to v3\n"));
5694 version
= SPOOLSS_DRIVER_VERSION_200X
;
5697 result
= construct_printer_driver_info_level(p
->mem_ctx
,
5698 get_session_info_system(),
5700 r
->in
.level
, r
->out
.info
,
5701 snum
, printer
->servername
,
5704 if (!W_ERROR_IS_OK(result
)) {
5705 TALLOC_FREE(r
->out
.info
);
5709 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_DriverInfo
,
5710 r
->out
.info
, r
->in
.level
);
5711 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
5713 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
5717 /****************************************************************
5718 _spoolss_StartPagePrinter
5719 ****************************************************************/
5721 WERROR
_spoolss_StartPagePrinter(struct pipes_struct
*p
,
5722 struct spoolss_StartPagePrinter
*r
)
5724 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5727 DEBUG(3,("_spoolss_StartPagePrinter: "
5728 "Error in startpageprinter printer handle\n"));
5732 Printer
->page_started
= true;
5736 /****************************************************************
5737 _spoolss_EndPagePrinter
5738 ****************************************************************/
5740 WERROR
_spoolss_EndPagePrinter(struct pipes_struct
*p
,
5741 struct spoolss_EndPagePrinter
*r
)
5745 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5748 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5749 OUR_HANDLE(r
->in
.handle
)));
5753 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
))
5756 Printer
->page_started
= false;
5757 print_job_endpage(p
->msg_ctx
, snum
, Printer
->jobid
);
5762 /****************************************************************
5763 _spoolss_StartDocPrinter
5764 ****************************************************************/
5766 WERROR
_spoolss_StartDocPrinter(struct pipes_struct
*p
,
5767 struct spoolss_StartDocPrinter
*r
)
5769 struct spoolss_DocumentInfo1
*info_1
;
5771 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5777 DEBUG(2,("_spoolss_StartDocPrinter: "
5778 "Invalid handle (%s:%u:%u)\n",
5779 OUR_HANDLE(r
->in
.handle
)));
5783 if (Printer
->jobid
) {
5784 DEBUG(2, ("_spoolss_StartDocPrinter: "
5785 "StartDocPrinter called twice! "
5786 "(existing jobid = %d)\n", Printer
->jobid
));
5787 return WERR_INVALID_HANDLE
;
5790 if (r
->in
.level
!= 1) {
5791 return WERR_UNKNOWN_LEVEL
;
5794 info_1
= r
->in
.info
.info1
;
5797 * a nice thing with NT is it doesn't listen to what you tell it.
5798 * when asked to send _only_ RAW datas, it tries to send datas
5801 * So I add checks like in NT Server ...
5804 if (info_1
->datatype
) {
5806 * The v4 driver model used in Windows 8 declares print jobs
5807 * intended to bypass the XPS processing layer by setting
5808 * datatype to "XPS_PASS" instead of "RAW".
5810 if ((strcmp(info_1
->datatype
, "RAW") != 0)
5811 && (strcmp(info_1
->datatype
, "XPS_PASS") != 0)) {
5813 return WERR_INVALID_DATATYPE
;
5817 /* get the share number of the printer */
5818 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
5822 rc
= get_remote_hostname(p
->remote_address
,
5828 if (strequal(rhost
,"UNKNOWN")) {
5829 rhost
= tsocket_address_inet_addr_string(p
->remote_address
,
5831 if (rhost
== NULL
) {
5836 werr
= print_job_start(p
->session_info
,
5840 info_1
->document_name
,
5841 info_1
->output_file
,
5845 /* An error occured in print_job_start() so return an appropriate
5848 if (!W_ERROR_IS_OK(werr
)) {
5852 Printer
->document_started
= true;
5853 *r
->out
.job_id
= Printer
->jobid
;
5858 /****************************************************************
5859 _spoolss_EndDocPrinter
5860 ****************************************************************/
5862 WERROR
_spoolss_EndDocPrinter(struct pipes_struct
*p
,
5863 struct spoolss_EndDocPrinter
*r
)
5865 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5870 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5871 OUR_HANDLE(r
->in
.handle
)));
5875 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
5879 Printer
->document_started
= false;
5880 status
= print_job_end(p
->msg_ctx
, snum
, Printer
->jobid
, NORMAL_CLOSE
);
5881 if (!NT_STATUS_IS_OK(status
)) {
5882 DEBUG(2, ("_spoolss_EndDocPrinter: "
5883 "print_job_end failed [%s]\n",
5884 nt_errstr(status
)));
5888 return ntstatus_to_werror(status
);
5891 /****************************************************************
5892 _spoolss_WritePrinter
5893 ****************************************************************/
5895 WERROR
_spoolss_WritePrinter(struct pipes_struct
*p
,
5896 struct spoolss_WritePrinter
*r
)
5898 ssize_t buffer_written
;
5900 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5903 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5904 OUR_HANDLE(r
->in
.handle
)));
5905 *r
->out
.num_written
= r
->in
._data_size
;
5909 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
))
5912 /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
5913 buffer_written
= print_job_write(server_event_context(),p
->msg_ctx
,
5914 snum
, Printer
->jobid
,
5915 (const char *)r
->in
.data
.data
,
5916 (size_t)r
->in
._data_size
);
5917 if (buffer_written
== (ssize_t
)-1) {
5918 *r
->out
.num_written
= 0;
5919 if (errno
== ENOSPC
)
5920 return WERR_NO_SPOOL_SPACE
;
5922 return WERR_ACCESS_DENIED
;
5925 *r
->out
.num_written
= r
->in
._data_size
;
5930 /********************************************************************
5931 * api_spoolss_getprinter
5932 * called from the spoolss dispatcher
5934 ********************************************************************/
5936 static WERROR
control_printer(struct policy_handle
*handle
, uint32_t command
,
5937 struct pipes_struct
*p
)
5939 const struct auth_session_info
*session_info
= p
->session_info
;
5941 WERROR errcode
= WERR_BADFUNC
;
5942 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, handle
);
5945 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5946 OUR_HANDLE(handle
)));
5950 if (!get_printer_snum(p
, handle
, &snum
, NULL
))
5954 case SPOOLSS_PRINTER_CONTROL_PAUSE
:
5955 errcode
= print_queue_pause(session_info
, p
->msg_ctx
, snum
);
5957 case SPOOLSS_PRINTER_CONTROL_RESUME
:
5958 case SPOOLSS_PRINTER_CONTROL_UNPAUSE
:
5959 errcode
= print_queue_resume(session_info
, p
->msg_ctx
, snum
);
5961 case SPOOLSS_PRINTER_CONTROL_PURGE
:
5962 errcode
= print_queue_purge(session_info
, p
->msg_ctx
, snum
);
5965 return WERR_UNKNOWN_LEVEL
;
5972 /****************************************************************
5973 _spoolss_AbortPrinter
5974 * From MSDN: "Deletes printer's spool file if printer is configured
5976 ****************************************************************/
5978 WERROR
_spoolss_AbortPrinter(struct pipes_struct
*p
,
5979 struct spoolss_AbortPrinter
*r
)
5981 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5983 WERROR errcode
= WERR_OK
;
5986 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5987 OUR_HANDLE(r
->in
.handle
)));
5991 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
))
5994 if (!Printer
->document_started
) {
5995 return WERR_SPL_NO_STARTDOC
;
5998 errcode
= print_job_delete(p
->session_info
,
6006 /********************************************************************
6007 * called by spoolss_api_setprinter
6008 * when updating a printer description
6009 ********************************************************************/
6011 static WERROR
update_printer_sec(struct policy_handle
*handle
,
6012 struct pipes_struct
*p
,
6013 struct sec_desc_buf
*secdesc_ctr
)
6015 struct spoolss_security_descriptor
*new_secdesc
= NULL
;
6016 struct spoolss_security_descriptor
*old_secdesc
= NULL
;
6017 const char *printer
;
6020 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, handle
);
6021 struct dcerpc_binding_handle
*b
;
6022 TALLOC_CTX
*tmp_ctx
= NULL
;
6024 if (!Printer
|| !get_printer_snum(p
, handle
, &snum
, NULL
)) {
6025 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
6026 OUR_HANDLE(handle
)));
6028 result
= WERR_BADFID
;
6032 if (secdesc_ctr
== NULL
) {
6033 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
6034 result
= WERR_INVALID_PARAM
;
6037 printer
= lp_const_servicename(snum
);
6039 /* Check the user has permissions to change the security
6040 descriptor. By experimentation with two NT machines, the user
6041 requires Full Access to the printer to change security
6044 if ( Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
6045 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
6046 result
= WERR_ACCESS_DENIED
;
6050 tmp_ctx
= talloc_new(p
->mem_ctx
);
6055 result
= winreg_printer_binding_handle(tmp_ctx
,
6056 get_session_info_system(),
6059 if (!W_ERROR_IS_OK(result
)) {
6063 /* NT seems to like setting the security descriptor even though
6064 nothing may have actually changed. */
6065 result
= winreg_get_printer_secdesc(tmp_ctx
, b
,
6068 if (!W_ERROR_IS_OK(result
)) {
6069 DEBUG(2,("update_printer_sec: winreg_get_printer_secdesc_internal() failed\n"));
6070 result
= WERR_BADFID
;
6074 if (DEBUGLEVEL
>= 10) {
6075 struct security_acl
*the_acl
;
6078 the_acl
= old_secdesc
->dacl
;
6079 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
6080 printer
, the_acl
->num_aces
));
6082 for (i
= 0; i
< the_acl
->num_aces
; i
++) {
6083 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
6084 &the_acl
->aces
[i
].trustee
),
6085 the_acl
->aces
[i
].access_mask
));
6088 the_acl
= secdesc_ctr
->sd
->dacl
;
6091 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
6092 printer
, the_acl
->num_aces
));
6094 for (i
= 0; i
< the_acl
->num_aces
; i
++) {
6095 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
6096 &the_acl
->aces
[i
].trustee
),
6097 the_acl
->aces
[i
].access_mask
));
6100 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
6104 new_secdesc
= sec_desc_merge(tmp_ctx
, secdesc_ctr
->sd
, old_secdesc
);
6105 if (new_secdesc
== NULL
) {
6106 result
= WERR_NOMEM
;
6110 if (security_descriptor_equal(new_secdesc
, old_secdesc
)) {
6115 result
= winreg_set_printer_secdesc(tmp_ctx
, b
,
6120 talloc_free(tmp_ctx
);
6124 /********************************************************************
6125 Canonicalize printer info from a client
6126 ********************************************************************/
6128 static bool check_printer_ok(TALLOC_CTX
*mem_ctx
,
6129 struct spoolss_SetPrinterInfo2
*info2
,
6132 fstring printername
;
6135 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
6136 "portname=%s drivername=%s comment=%s location=%s\n",
6137 info2
->servername
, info2
->printername
, info2
->sharename
,
6138 info2
->portname
, info2
->drivername
, info2
->comment
,
6141 /* we force some elements to "correct" values */
6142 info2
->servername
= talloc_asprintf(mem_ctx
, "\\\\%s", lp_netbios_name());
6143 if (info2
->servername
== NULL
) {
6146 info2
->sharename
= talloc_strdup(mem_ctx
, lp_const_servicename(snum
));
6147 if (info2
->sharename
== NULL
) {
6151 /* check to see if we allow printername != sharename */
6152 if (lp_force_printername(snum
)) {
6153 info2
->printername
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s",
6154 lp_netbios_name(), info2
->sharename
);
6156 /* make sure printername is in \\server\printername format */
6157 fstrcpy(printername
, info2
->printername
);
6159 if ( printername
[0] == '\\' && printername
[1] == '\\' ) {
6160 if ( (p
= strchr_m( &printername
[2], '\\' )) != NULL
)
6164 info2
->printername
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s",
6165 lp_netbios_name(), p
);
6167 if (info2
->printername
== NULL
) {
6171 info2
->attributes
|= PRINTER_ATTRIBUTE_SAMBA
;
6172 info2
->attributes
&= ~PRINTER_ATTRIBUTE_NOT_SAMBA
;
6177 /****************************************************************************
6178 ****************************************************************************/
6180 static WERROR
add_port_hook(TALLOC_CTX
*ctx
, struct security_token
*token
, const char *portname
, const char *uri
)
6182 char *cmd
= lp_addport_cmd(talloc_tos());
6183 char *command
= NULL
;
6185 bool is_print_op
= false;
6188 return WERR_ACCESS_DENIED
;
6191 command
= talloc_asprintf(ctx
,
6192 "%s \"%s\" \"%s\"", cmd
, portname
, uri
);
6198 is_print_op
= security_token_has_privilege(token
, SEC_PRIV_PRINT_OPERATOR
);
6200 DEBUG(10,("Running [%s]\n", command
));
6202 /********* BEGIN SePrintOperatorPrivilege **********/
6207 ret
= smbrun(command
, NULL
);
6212 /********* END SePrintOperatorPrivilege **********/
6214 DEBUGADD(10,("returned [%d]\n", ret
));
6216 TALLOC_FREE(command
);
6219 return WERR_ACCESS_DENIED
;
6225 /****************************************************************************
6226 ****************************************************************************/
6228 static bool spoolss_conn_snum_used(struct smbd_server_connection
*sconn
,
6232 * As we do not know if we are embedded in the file server process
6233 * or not, we have to pretend that all shares are in use.
6238 static bool add_printer_hook(TALLOC_CTX
*ctx
, struct security_token
*token
,
6239 struct spoolss_SetPrinterInfo2
*info2
,
6240 const char *remote_machine
,
6241 struct messaging_context
*msg_ctx
)
6243 char *cmd
= lp_addprinter_cmd(talloc_tos());
6245 char *command
= NULL
;
6249 bool is_print_op
= false;
6251 if (!remote_machine
) {
6255 command
= talloc_asprintf(ctx
,
6256 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
6257 cmd
, info2
->printername
, info2
->sharename
,
6258 info2
->portname
, info2
->drivername
,
6259 info2
->location
, info2
->comment
, remote_machine
);
6265 is_print_op
= security_token_has_privilege(token
, SEC_PRIV_PRINT_OPERATOR
);
6267 DEBUG(10,("Running [%s]\n", command
));
6269 /********* BEGIN SePrintOperatorPrivilege **********/
6274 if ( (ret
= smbrun(command
, &fd
)) == 0 ) {
6275 /* Tell everyone we updated smb.conf. */
6276 message_send_all(msg_ctx
, MSG_SMB_CONF_UPDATED
, NULL
, 0, NULL
);
6282 /********* END SePrintOperatorPrivilege **********/
6284 DEBUGADD(10,("returned [%d]\n", ret
));
6286 TALLOC_FREE(command
);
6294 /* reload our services immediately */
6296 reload_services(NULL
, spoolss_conn_snum_used
, false);
6300 /* Get lines and convert them back to dos-codepage */
6301 qlines
= fd_lines_load(fd
, &numlines
, 0, NULL
);
6302 DEBUGADD(10,("Lines returned = [%d]\n", numlines
));
6305 /* Set the portname to what the script says the portname should be. */
6306 /* but don't require anything to be return from the script exit a good error code */
6309 /* Set the portname to what the script says the portname should be. */
6310 info2
->portname
= talloc_strdup(ctx
, qlines
[0]);
6311 DEBUGADD(6,("Line[0] = [%s]\n", qlines
[0]));
6314 TALLOC_FREE(qlines
);
6318 static WERROR
update_dsspooler(TALLOC_CTX
*mem_ctx
,
6319 const struct auth_session_info
*session_info
,
6320 struct messaging_context
*msg_ctx
,
6322 struct spoolss_SetPrinterInfo2
*printer
,
6323 struct spoolss_PrinterInfo2
*old_printer
)
6325 bool force_update
= (old_printer
== NULL
);
6326 const char *dnsdomname
;
6327 const char *longname
;
6328 const char *uncname
;
6329 const char *spooling
;
6331 WERROR result
= WERR_OK
;
6332 struct dcerpc_binding_handle
*b
;
6333 TALLOC_CTX
*tmp_ctx
;
6336 tmp_ctx
= talloc_new(mem_ctx
);
6341 result
= winreg_printer_binding_handle(tmp_ctx
,
6345 if (!W_ERROR_IS_OK(result
)) {
6349 if (printer
->drivername
!= NULL
&&
6351 !strequal(printer
->drivername
, old_printer
->drivername
))) {
6352 ok
= push_reg_sz(tmp_ctx
, &buffer
, printer
->drivername
);
6354 DEBUG(0, ("%s data corrupted\n", SPOOL_REG_DRIVERNAME
));
6355 result
= WERR_INVALID_DATA
;
6358 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6360 SPOOL_DSSPOOLER_KEY
,
6361 SPOOL_REG_DRIVERNAME
,
6365 if (!W_ERROR_IS_OK(result
)) {
6366 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_DRIVERNAME
));
6370 if (!force_update
) {
6371 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
6372 printer
->drivername
));
6374 notify_printer_driver(server_event_context(), msg_ctx
,
6375 snum
, printer
->drivername
?
6376 printer
->drivername
: "");
6380 if (printer
->comment
!= NULL
&&
6382 !strequal(printer
->comment
, old_printer
->comment
))) {
6383 ok
= push_reg_sz(tmp_ctx
, &buffer
, printer
->comment
);
6385 DEBUG(0, ("comment data corrupted\n"));
6386 result
= WERR_INVALID_DATA
;
6389 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6391 SPOOL_DSSPOOLER_KEY
,
6392 SPOOL_REG_DESCRIPTION
,
6396 if (!W_ERROR_IS_OK(result
)) {
6397 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_DESCRIPTION
));
6401 if (!force_update
) {
6402 notify_printer_comment(server_event_context(), msg_ctx
,
6403 snum
, printer
->comment
?
6404 printer
->comment
: "");
6408 if (printer
->sharename
!= NULL
&&
6410 !strequal(printer
->sharename
, old_printer
->sharename
))) {
6411 ok
= push_reg_sz(tmp_ctx
, &buffer
, printer
->sharename
);
6413 DEBUG(0, ("sharename data corrupted\n"));
6414 result
= WERR_INVALID_DATA
;
6417 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6419 SPOOL_DSSPOOLER_KEY
,
6420 SPOOL_REG_PRINTSHARENAME
,
6424 if (!W_ERROR_IS_OK(result
)) {
6425 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSHARENAME
));
6429 if (!force_update
) {
6430 notify_printer_sharename(server_event_context(),
6432 snum
, printer
->sharename
?
6433 printer
->sharename
: "");
6437 if (printer
->printername
!= NULL
&&
6439 !strequal(printer
->printername
, old_printer
->printername
))) {
6442 p
= strrchr(printer
->printername
, '\\' );
6446 p
= printer
->printername
;
6449 ok
= push_reg_sz(tmp_ctx
, &buffer
, p
);
6451 DEBUG(0, ("printername data corrupted\n"));
6452 result
= WERR_INVALID_DATA
;
6455 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6457 SPOOL_DSSPOOLER_KEY
,
6458 SPOOL_REG_PRINTERNAME
,
6462 if (!W_ERROR_IS_OK(result
)) {
6463 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSHARENAME
));
6467 if (!force_update
) {
6468 notify_printer_printername(server_event_context(),
6469 msg_ctx
, snum
, p
? p
: "");
6473 if (printer
->portname
!= NULL
&&
6475 !strequal(printer
->portname
, old_printer
->portname
))) {
6476 ok
= push_reg_sz(tmp_ctx
, &buffer
, printer
->portname
);
6478 DEBUG(0, ("portname data corrupted\n"));
6479 result
= WERR_INVALID_DATA
;
6482 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6484 SPOOL_DSSPOOLER_KEY
,
6489 if (!W_ERROR_IS_OK(result
)) {
6490 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PORTNAME
));
6494 if (!force_update
) {
6495 notify_printer_port(server_event_context(),
6496 msg_ctx
, snum
, printer
->portname
?
6497 printer
->portname
: "");
6501 if (printer
->location
!= NULL
&&
6503 !strequal(printer
->location
, old_printer
->location
))) {
6504 ok
= push_reg_sz(tmp_ctx
, &buffer
, printer
->location
);
6506 DEBUG(0, ("location data corrupted\n"));
6507 result
= WERR_INVALID_DATA
;
6510 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6512 SPOOL_DSSPOOLER_KEY
,
6517 if (!W_ERROR_IS_OK(result
)) {
6518 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_LOCATION
));
6522 if (!force_update
) {
6523 notify_printer_location(server_event_context(),
6526 printer
->location
: "");
6530 if (printer
->sepfile
!= NULL
&&
6532 !strequal(printer
->sepfile
, old_printer
->sepfile
))) {
6533 ok
= push_reg_sz(tmp_ctx
, &buffer
, printer
->sepfile
);
6535 DEBUG(0, ("sepfile data corrupted\n"));
6536 result
= WERR_INVALID_DATA
;
6539 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6541 SPOOL_DSSPOOLER_KEY
,
6542 SPOOL_REG_PRINTSEPARATORFILE
,
6546 if (!W_ERROR_IS_OK(result
)) {
6547 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSEPARATORFILE
));
6551 if (!force_update
) {
6552 notify_printer_sepfile(server_event_context(),
6555 printer
->sepfile
: "");
6559 if (printer
->starttime
!= 0 &&
6561 printer
->starttime
!= old_printer
->starttime
)) {
6562 buffer
= data_blob_talloc(tmp_ctx
, NULL
, 4);
6563 SIVAL(buffer
.data
, 0, printer
->starttime
);
6564 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6566 SPOOL_DSSPOOLER_KEY
,
6567 SPOOL_REG_PRINTSTARTTIME
,
6571 if (!W_ERROR_IS_OK(result
)) {
6572 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSTARTTIME
));
6577 if (printer
->untiltime
!= 0 &&
6579 printer
->untiltime
!= old_printer
->untiltime
)) {
6580 buffer
= data_blob_talloc(tmp_ctx
, NULL
, 4);
6581 SIVAL(buffer
.data
, 0, printer
->untiltime
);
6582 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6584 SPOOL_DSSPOOLER_KEY
,
6585 SPOOL_REG_PRINTENDTIME
,
6589 if (!W_ERROR_IS_OK(result
)) {
6590 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTENDTIME
));
6595 if (force_update
|| printer
->priority
!= old_printer
->priority
) {
6596 buffer
= data_blob_talloc(tmp_ctx
, NULL
, 4);
6597 SIVAL(buffer
.data
, 0, printer
->priority
);
6598 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6600 SPOOL_DSSPOOLER_KEY
,
6605 if (!W_ERROR_IS_OK(result
)) {
6606 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTENDTIME
));
6611 if (force_update
|| printer
->attributes
!= old_printer
->attributes
) {
6612 buffer
= data_blob_talloc(tmp_ctx
, NULL
, 4);
6613 SIVAL(buffer
.data
, 0, (printer
->attributes
&
6614 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS
));
6615 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6617 SPOOL_DSSPOOLER_KEY
,
6618 SPOOL_REG_PRINTKEEPPRINTEDJOBS
,
6622 if (!W_ERROR_IS_OK(result
)) {
6623 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTENDTIME
));
6627 switch (printer
->attributes
& 0x3) {
6629 spooling
= SPOOL_REGVAL_PRINTWHILESPOOLING
;
6632 spooling
= SPOOL_REGVAL_PRINTAFTERSPOOLED
;
6635 spooling
= SPOOL_REGVAL_PRINTDIRECT
;
6638 spooling
= "unknown";
6640 ok
= push_reg_sz(tmp_ctx
, &buffer
, spooling
);
6642 DEBUG(0, ("printSpooling data corrupted\n"));
6643 result
= WERR_INVALID_DATA
;
6646 winreg_set_printer_dataex(tmp_ctx
, b
,
6648 SPOOL_DSSPOOLER_KEY
,
6649 SPOOL_REG_PRINTSPOOLING
,
6655 ok
= push_reg_sz(tmp_ctx
, &buffer
, lp_netbios_name());
6657 DEBUG(0, ("shortServerName data corrupted\n"));
6658 result
= WERR_INVALID_DATA
;
6661 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6663 SPOOL_DSSPOOLER_KEY
,
6664 SPOOL_REG_SHORTSERVERNAME
,
6668 if (!W_ERROR_IS_OK(result
)) {
6669 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_SHORTSERVERNAME
));
6673 dnsdomname
= get_mydnsfullname();
6674 if (dnsdomname
!= NULL
&& dnsdomname
[0] != '\0') {
6675 longname
= talloc_strdup(tmp_ctx
, dnsdomname
);
6677 longname
= talloc_strdup(tmp_ctx
, lp_netbios_name());
6679 if (longname
== NULL
) {
6680 result
= WERR_NOMEM
;
6684 ok
= push_reg_sz(tmp_ctx
, &buffer
, longname
);
6686 DEBUG(0, ("longname data corrupted\n"));
6687 result
= WERR_INVALID_DATA
;
6690 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6692 SPOOL_DSSPOOLER_KEY
,
6693 SPOOL_REG_SERVERNAME
,
6697 if (!W_ERROR_IS_OK(result
)) {
6698 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_SERVERNAME
));
6702 uncname
= talloc_asprintf(tmp_ctx
, "\\\\%s\\%s",
6703 lp_netbios_name(), printer
->sharename
);
6704 ok
= push_reg_sz(tmp_ctx
, &buffer
, uncname
);
6706 DEBUG(0, ("uncName data corrupted\n"));
6707 result
= WERR_INVALID_DATA
;
6710 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6712 SPOOL_DSSPOOLER_KEY
,
6717 if (!W_ERROR_IS_OK(result
)) {
6718 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_UNCNAME
));
6723 talloc_free(tmp_ctx
);
6727 /********************************************************************
6728 * Called by spoolss_api_setprinter
6729 * when updating a printer description.
6730 ********************************************************************/
6732 static WERROR
update_printer(struct pipes_struct
*p
,
6733 struct policy_handle
*handle
,
6734 struct spoolss_SetPrinterInfoCtr
*info_ctr
,
6735 struct spoolss_DeviceMode
*devmode
)
6737 uint32_t printer_mask
= SPOOLSS_PRINTER_INFO_ALL
;
6738 struct spoolss_SetPrinterInfo2
*printer
= info_ctr
->info
.info2
;
6739 struct spoolss_PrinterInfo2
*old_printer
;
6740 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, handle
);
6742 WERROR result
= WERR_OK
;
6743 TALLOC_CTX
*tmp_ctx
;
6744 struct dcerpc_binding_handle
*b
;
6746 DEBUG(8,("update_printer\n"));
6748 tmp_ctx
= talloc_new(p
->mem_ctx
);
6749 if (tmp_ctx
== NULL
) {
6754 result
= WERR_BADFID
;
6758 if (!get_printer_snum(p
, handle
, &snum
, NULL
)) {
6759 result
= WERR_BADFID
;
6763 result
= winreg_printer_binding_handle(tmp_ctx
,
6764 get_session_info_system(),
6767 if (!W_ERROR_IS_OK(result
)) {
6771 result
= winreg_get_printer(tmp_ctx
, b
,
6772 lp_const_servicename(snum
),
6774 if (!W_ERROR_IS_OK(result
)) {
6775 result
= WERR_BADFID
;
6779 /* Do sanity check on the requested changes for Samba */
6780 if (!check_printer_ok(tmp_ctx
, printer
, snum
)) {
6781 result
= WERR_INVALID_PARAM
;
6785 /* FIXME!!! If the driver has changed we really should verify that
6786 it is installed before doing much else --jerry */
6788 /* Check calling user has permission to update printer description */
6789 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
6790 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6791 result
= WERR_ACCESS_DENIED
;
6795 /* Call addprinter hook */
6796 /* Check changes to see if this is really needed */
6798 if (*lp_addprinter_cmd(talloc_tos()) &&
6799 (!strequal(printer
->drivername
, old_printer
->drivername
) ||
6800 !strequal(printer
->comment
, old_printer
->comment
) ||
6801 !strequal(printer
->portname
, old_printer
->portname
) ||
6802 !strequal(printer
->location
, old_printer
->location
)) )
6806 raddr
= tsocket_address_inet_addr_string(p
->remote_address
,
6808 if (raddr
== NULL
) {
6812 /* add_printer_hook() will call reload_services() */
6813 if (!add_printer_hook(tmp_ctx
, p
->session_info
->security_token
,
6816 result
= WERR_ACCESS_DENIED
;
6821 result
= update_dsspooler(tmp_ctx
,
6822 get_session_info_system(),
6827 if (!W_ERROR_IS_OK(result
)) {
6831 printer_mask
&= ~SPOOLSS_PRINTER_INFO_SECDESC
;
6833 if (devmode
== NULL
) {
6834 printer_mask
&= ~SPOOLSS_PRINTER_INFO_DEVMODE
;
6836 result
= winreg_update_printer(tmp_ctx
, b
,
6844 talloc_free(tmp_ctx
);
6849 /****************************************************************************
6850 ****************************************************************************/
6851 static WERROR
publish_or_unpublish_printer(struct pipes_struct
*p
,
6852 struct policy_handle
*handle
,
6853 struct spoolss_SetPrinterInfo7
*info7
)
6856 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
6859 struct printer_handle
*Printer
;
6861 if ( lp_security() != SEC_ADS
) {
6862 return WERR_UNKNOWN_LEVEL
;
6865 Printer
= find_printer_index_by_hnd(p
, handle
);
6867 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7
->action
));
6872 if (!get_printer_snum(p
, handle
, &snum
, NULL
))
6875 result
= winreg_get_printer_internal(p
->mem_ctx
,
6876 get_session_info_system(),
6878 lp_servicename(talloc_tos(), snum
),
6880 if (!W_ERROR_IS_OK(result
)) {
6884 nt_printer_publish(pinfo2
,
6885 get_session_info_system(),
6890 TALLOC_FREE(pinfo2
);
6893 return WERR_UNKNOWN_LEVEL
;
6897 /********************************************************************
6898 ********************************************************************/
6900 static WERROR
update_printer_devmode(struct pipes_struct
*p
,
6901 struct policy_handle
*handle
,
6902 struct spoolss_DeviceMode
*devmode
)
6905 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, handle
);
6906 uint32_t info2_mask
= SPOOLSS_PRINTER_INFO_DEVMODE
;
6908 DEBUG(8,("update_printer_devmode\n"));
6914 if (!get_printer_snum(p
, handle
, &snum
, NULL
)) {
6918 /* Check calling user has permission to update printer description */
6919 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
6920 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6921 return WERR_ACCESS_DENIED
;
6924 return winreg_update_printer_internal(p
->mem_ctx
,
6925 get_session_info_system(),
6927 lp_const_servicename(snum
),
6935 /****************************************************************
6937 ****************************************************************/
6939 WERROR
_spoolss_SetPrinter(struct pipes_struct
*p
,
6940 struct spoolss_SetPrinter
*r
)
6944 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
6947 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6948 OUR_HANDLE(r
->in
.handle
)));
6952 /* check the level */
6953 switch (r
->in
.info_ctr
->level
) {
6955 return control_printer(r
->in
.handle
, r
->in
.command
, p
);
6957 result
= update_printer(p
, r
->in
.handle
,
6959 r
->in
.devmode_ctr
->devmode
);
6960 if (!W_ERROR_IS_OK(result
))
6962 if (r
->in
.secdesc_ctr
->sd
)
6963 result
= update_printer_sec(r
->in
.handle
, p
,
6967 return update_printer_sec(r
->in
.handle
, p
,
6970 return publish_or_unpublish_printer(p
, r
->in
.handle
,
6971 r
->in
.info_ctr
->info
.info7
);
6973 return update_printer_devmode(p
, r
->in
.handle
,
6974 r
->in
.devmode_ctr
->devmode
);
6976 return WERR_UNKNOWN_LEVEL
;
6980 /****************************************************************
6981 _spoolss_FindClosePrinterNotify
6982 ****************************************************************/
6984 WERROR
_spoolss_FindClosePrinterNotify(struct pipes_struct
*p
,
6985 struct spoolss_FindClosePrinterNotify
*r
)
6987 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
6990 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6991 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r
->in
.handle
)));
6995 if (Printer
->notify
.cli_chan
!= NULL
&&
6996 Printer
->notify
.cli_chan
->active_connections
> 0) {
6999 if (Printer
->printer_type
== SPLHND_PRINTER
) {
7000 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
7005 srv_spoolss_replycloseprinter(snum
, Printer
);
7008 Printer
->notify
.flags
=0;
7009 Printer
->notify
.options
=0;
7010 Printer
->notify
.localmachine
[0]='\0';
7011 Printer
->notify
.printerlocal
=0;
7012 TALLOC_FREE(Printer
->notify
.option
);
7017 /****************************************************************
7019 ****************************************************************/
7021 WERROR
_spoolss_AddJob(struct pipes_struct
*p
,
7022 struct spoolss_AddJob
*r
)
7024 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
7025 return WERR_INVALID_PARAM
;
7028 /* this is what a NT server returns for AddJob. AddJob must fail on
7029 * non-local printers */
7031 if (r
->in
.level
!= 1) {
7032 return WERR_UNKNOWN_LEVEL
;
7035 return WERR_INVALID_PARAM
;
7038 /****************************************************************************
7040 ****************************************************************************/
7042 static WERROR
fill_job_info1(TALLOC_CTX
*mem_ctx
,
7043 struct spoolss_JobInfo1
*r
,
7044 const print_queue_struct
*queue
,
7046 int position
, int snum
,
7047 struct spoolss_PrinterInfo2
*pinfo2
)
7051 t
= gmtime(&queue
->time
);
7055 r
->printer_name
= lp_servicename(mem_ctx
, snum
);
7056 W_ERROR_HAVE_NO_MEMORY(r
->printer_name
);
7057 r
->server_name
= talloc_strdup(mem_ctx
, pinfo2
->servername
);
7058 W_ERROR_HAVE_NO_MEMORY(r
->server_name
);
7059 r
->user_name
= talloc_strdup(mem_ctx
, queue
->fs_user
);
7060 W_ERROR_HAVE_NO_MEMORY(r
->user_name
);
7061 r
->document_name
= talloc_strdup(mem_ctx
, queue
->fs_file
);
7062 W_ERROR_HAVE_NO_MEMORY(r
->document_name
);
7063 r
->data_type
= talloc_strdup(mem_ctx
, "RAW");
7064 W_ERROR_HAVE_NO_MEMORY(r
->data_type
);
7065 r
->text_status
= talloc_strdup(mem_ctx
, "");
7066 W_ERROR_HAVE_NO_MEMORY(r
->text_status
);
7068 r
->status
= nt_printj_status(queue
->status
);
7069 r
->priority
= queue
->priority
;
7070 r
->position
= position
;
7071 r
->total_pages
= queue
->page_count
;
7072 r
->pages_printed
= 0; /* ??? */
7074 init_systemtime(&r
->submitted
, t
);
7079 /****************************************************************************
7081 ****************************************************************************/
7083 static WERROR
fill_job_info2(TALLOC_CTX
*mem_ctx
,
7084 struct spoolss_JobInfo2
*r
,
7085 const print_queue_struct
*queue
,
7087 int position
, int snum
,
7088 struct spoolss_PrinterInfo2
*pinfo2
,
7089 struct spoolss_DeviceMode
*devmode
)
7093 t
= gmtime(&queue
->time
);
7097 r
->printer_name
= lp_servicename(mem_ctx
, snum
);
7098 W_ERROR_HAVE_NO_MEMORY(r
->printer_name
);
7099 r
->server_name
= talloc_strdup(mem_ctx
, pinfo2
->servername
);
7100 W_ERROR_HAVE_NO_MEMORY(r
->server_name
);
7101 r
->user_name
= talloc_strdup(mem_ctx
, queue
->fs_user
);
7102 W_ERROR_HAVE_NO_MEMORY(r
->user_name
);
7103 r
->document_name
= talloc_strdup(mem_ctx
, queue
->fs_file
);
7104 W_ERROR_HAVE_NO_MEMORY(r
->document_name
);
7105 r
->notify_name
= talloc_strdup(mem_ctx
, queue
->fs_user
);
7106 W_ERROR_HAVE_NO_MEMORY(r
->notify_name
);
7107 r
->data_type
= talloc_strdup(mem_ctx
, "RAW");
7108 W_ERROR_HAVE_NO_MEMORY(r
->data_type
);
7109 r
->print_processor
= talloc_strdup(mem_ctx
, "winprint");
7110 W_ERROR_HAVE_NO_MEMORY(r
->print_processor
);
7111 r
->parameters
= talloc_strdup(mem_ctx
, "");
7112 W_ERROR_HAVE_NO_MEMORY(r
->parameters
);
7113 r
->driver_name
= talloc_strdup(mem_ctx
, pinfo2
->drivername
);
7114 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
7116 r
->devmode
= devmode
;
7118 r
->text_status
= talloc_strdup(mem_ctx
, "");
7119 W_ERROR_HAVE_NO_MEMORY(r
->text_status
);
7123 r
->status
= nt_printj_status(queue
->status
);
7124 r
->priority
= queue
->priority
;
7125 r
->position
= position
;
7128 r
->total_pages
= queue
->page_count
;
7129 r
->size
= queue
->size
;
7130 init_systemtime(&r
->submitted
, t
);
7132 r
->pages_printed
= 0; /* ??? */
7137 /****************************************************************************
7138 Enumjobs at level 1.
7139 ****************************************************************************/
7141 static WERROR
enumjobs_level1(TALLOC_CTX
*mem_ctx
,
7142 const print_queue_struct
*queue
,
7143 uint32_t num_queues
, int snum
,
7144 struct spoolss_PrinterInfo2
*pinfo2
,
7145 union spoolss_JobInfo
**info_p
,
7148 union spoolss_JobInfo
*info
;
7150 WERROR result
= WERR_OK
;
7151 uint32_t num_filled
;
7152 struct tdb_print_db
*pdb
;
7154 info
= talloc_array(mem_ctx
, union spoolss_JobInfo
, num_queues
);
7156 result
= WERR_NOMEM
;
7160 pdb
= get_print_db_byname(pinfo2
->sharename
);
7162 result
= WERR_INVALID_PARAM
;
7167 for (i
= 0; i
< num_queues
; i
++) {
7168 uint32_t jobid
= sysjob_to_jobid_pdb(pdb
, queue
[i
].sysjob
);
7169 if (jobid
== (uint32_t)-1) {
7170 DEBUG(4, ("skipping sysjob %d\n", queue
[i
].sysjob
));
7174 result
= fill_job_info1(info
,
7175 &info
[num_filled
].info1
,
7181 if (!W_ERROR_IS_OK(result
)) {
7188 release_print_db(pdb
);
7190 *count
= num_filled
;
7195 release_print_db(pdb
);
7203 /****************************************************************************
7204 Enumjobs at level 2.
7205 ****************************************************************************/
7207 static WERROR
enumjobs_level2(TALLOC_CTX
*mem_ctx
,
7208 const print_queue_struct
*queue
,
7209 uint32_t num_queues
, int snum
,
7210 struct spoolss_PrinterInfo2
*pinfo2
,
7211 union spoolss_JobInfo
**info_p
,
7214 union spoolss_JobInfo
*info
;
7216 WERROR result
= WERR_OK
;
7217 uint32_t num_filled
;
7218 struct tdb_print_db
*pdb
;
7220 info
= talloc_array(mem_ctx
, union spoolss_JobInfo
, num_queues
);
7222 result
= WERR_NOMEM
;
7226 pdb
= get_print_db_byname(pinfo2
->sharename
);
7228 result
= WERR_INVALID_PARAM
;
7233 for (i
= 0; i
< num_queues
; i
++) {
7234 struct spoolss_DeviceMode
*devmode
;
7235 uint32_t jobid
= sysjob_to_jobid_pdb(pdb
, queue
[i
].sysjob
);
7236 if (jobid
== (uint32_t)-1) {
7237 DEBUG(4, ("skipping sysjob %d\n", queue
[i
].sysjob
));
7241 result
= spoolss_create_default_devmode(info
,
7242 pinfo2
->printername
,
7244 if (!W_ERROR_IS_OK(result
)) {
7245 DEBUG(3, ("Can't proceed w/o a devmode!"));
7249 result
= fill_job_info2(info
,
7250 &info
[num_filled
].info2
,
7257 if (!W_ERROR_IS_OK(result
)) {
7263 release_print_db(pdb
);
7265 *count
= num_filled
;
7270 release_print_db(pdb
);
7278 /****************************************************************************
7279 Enumjobs at level 3.
7280 ****************************************************************************/
7282 static WERROR
enumjobs_level3(TALLOC_CTX
*mem_ctx
,
7283 const print_queue_struct
*queue
,
7284 uint32_t num_queues
, int snum
,
7285 struct spoolss_PrinterInfo2
*pinfo2
,
7286 union spoolss_JobInfo
**info_p
,
7289 union spoolss_JobInfo
*info
;
7291 WERROR result
= WERR_OK
;
7292 uint32_t num_filled
;
7293 struct tdb_print_db
*pdb
;
7295 info
= talloc_array(mem_ctx
, union spoolss_JobInfo
, num_queues
);
7297 result
= WERR_NOMEM
;
7301 pdb
= get_print_db_byname(pinfo2
->sharename
);
7303 result
= WERR_INVALID_PARAM
;
7308 for (i
= 0; i
< num_queues
; i
++) {
7309 uint32_t jobid
= sysjob_to_jobid_pdb(pdb
, queue
[i
].sysjob
);
7310 if (jobid
== (uint32_t)-1) {
7311 DEBUG(4, ("skipping sysjob %d\n", queue
[i
].sysjob
));
7315 info
[num_filled
].info3
.job_id
= jobid
;
7316 /* next_job_id is overwritten on next iteration */
7317 info
[num_filled
].info3
.next_job_id
= 0;
7318 info
[num_filled
].info3
.reserved
= 0;
7320 if (num_filled
> 0) {
7321 info
[num_filled
- 1].info3
.next_job_id
= jobid
;
7326 release_print_db(pdb
);
7328 *count
= num_filled
;
7339 /****************************************************************
7341 ****************************************************************/
7343 WERROR
_spoolss_EnumJobs(struct pipes_struct
*p
,
7344 struct spoolss_EnumJobs
*r
)
7347 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
7349 print_status_struct prt_status
;
7350 print_queue_struct
*queue
= NULL
;
7353 /* that's an [in out] buffer */
7355 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
7356 return WERR_INVALID_PARAM
;
7359 if ((r
->in
.level
!= 1) && (r
->in
.level
!= 2) && (r
->in
.level
!= 3)) {
7360 DEBUG(4, ("EnumJobs level %d not supported\n", r
->in
.level
));
7361 return WERR_UNKNOWN_LEVEL
;
7364 DEBUG(4,("_spoolss_EnumJobs\n"));
7368 *r
->out
.info
= NULL
;
7370 /* lookup the printer snum and tdb entry */
7372 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
7376 result
= winreg_get_printer_internal(p
->mem_ctx
,
7377 get_session_info_system(),
7379 lp_const_servicename(snum
),
7381 if (!W_ERROR_IS_OK(result
)) {
7385 count
= print_queue_status(p
->msg_ctx
, snum
, &queue
, &prt_status
);
7386 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
7387 count
, prt_status
.status
, prt_status
.message
));
7391 TALLOC_FREE(pinfo2
);
7395 switch (r
->in
.level
) {
7397 result
= enumjobs_level1(p
->mem_ctx
, queue
, count
, snum
,
7398 pinfo2
, r
->out
.info
, r
->out
.count
);
7401 result
= enumjobs_level2(p
->mem_ctx
, queue
, count
, snum
,
7402 pinfo2
, r
->out
.info
, r
->out
.count
);
7405 result
= enumjobs_level3(p
->mem_ctx
, queue
, count
, snum
,
7406 pinfo2
, r
->out
.info
, r
->out
.count
);
7409 SMB_ASSERT(false); /* level checked on entry */
7414 TALLOC_FREE(pinfo2
);
7416 if (!W_ERROR_IS_OK(result
)) {
7420 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
7422 *r
->out
.info
, r
->in
.level
,
7424 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
7425 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
7427 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
7430 /****************************************************************
7431 _spoolss_ScheduleJob
7432 ****************************************************************/
7434 WERROR
_spoolss_ScheduleJob(struct pipes_struct
*p
,
7435 struct spoolss_ScheduleJob
*r
)
7440 /****************************************************************
7441 ****************************************************************/
7443 static WERROR
spoolss_setjob_1(TALLOC_CTX
*mem_ctx
,
7444 struct messaging_context
*msg_ctx
,
7445 const char *printer_name
,
7447 struct spoolss_SetJobInfo1
*r
)
7451 if (!print_job_get_name(mem_ctx
, printer_name
, job_id
, &old_doc_name
)) {
7455 if (strequal(old_doc_name
, r
->document_name
)) {
7459 if (!print_job_set_name(server_event_context(), msg_ctx
,
7460 printer_name
, job_id
, r
->document_name
)) {
7467 /****************************************************************
7469 ****************************************************************/
7471 WERROR
_spoolss_SetJob(struct pipes_struct
*p
,
7472 struct spoolss_SetJob
*r
)
7474 const struct auth_session_info
*session_info
= p
->session_info
;
7476 WERROR errcode
= WERR_BADFUNC
;
7478 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
7482 if (!print_job_exists(lp_const_servicename(snum
), r
->in
.job_id
)) {
7483 return WERR_INVALID_PRINTER_NAME
;
7486 switch (r
->in
.command
) {
7487 case SPOOLSS_JOB_CONTROL_CANCEL
:
7488 case SPOOLSS_JOB_CONTROL_DELETE
:
7489 errcode
= print_job_delete(session_info
, p
->msg_ctx
,
7490 snum
, r
->in
.job_id
);
7491 if (W_ERROR_EQUAL(errcode
, WERR_PRINTER_HAS_JOBS_QUEUED
)) {
7495 case SPOOLSS_JOB_CONTROL_PAUSE
:
7496 errcode
= print_job_pause(session_info
, p
->msg_ctx
,
7497 snum
, r
->in
.job_id
);
7499 case SPOOLSS_JOB_CONTROL_RESTART
:
7500 case SPOOLSS_JOB_CONTROL_RESUME
:
7501 errcode
= print_job_resume(session_info
, p
->msg_ctx
,
7502 snum
, r
->in
.job_id
);
7508 return WERR_UNKNOWN_LEVEL
;
7511 if (!W_ERROR_IS_OK(errcode
)) {
7515 if (r
->in
.ctr
== NULL
) {
7519 switch (r
->in
.ctr
->level
) {
7521 errcode
= spoolss_setjob_1(p
->mem_ctx
, p
->msg_ctx
,
7522 lp_const_servicename(snum
),
7524 r
->in
.ctr
->info
.info1
);
7530 return WERR_UNKNOWN_LEVEL
;
7536 /****************************************************************************
7537 Enumerates all printer drivers by level and architecture.
7538 ****************************************************************************/
7540 static WERROR
enumprinterdrivers_level_by_architecture(TALLOC_CTX
*mem_ctx
,
7541 const struct auth_session_info
*session_info
,
7542 struct messaging_context
*msg_ctx
,
7543 const char *servername
,
7544 const char *architecture
,
7546 union spoolss_DriverInfo
**info_p
,
7551 struct spoolss_DriverInfo8
*driver
;
7552 union spoolss_DriverInfo
*info
= NULL
;
7554 WERROR result
= WERR_OK
;
7555 uint32_t num_drivers
;
7556 const char **drivers
;
7557 struct dcerpc_binding_handle
*b
;
7558 TALLOC_CTX
*tmp_ctx
= NULL
;
7563 tmp_ctx
= talloc_new(mem_ctx
);
7568 result
= winreg_printer_binding_handle(tmp_ctx
,
7572 if (!W_ERROR_IS_OK(result
)) {
7576 for (version
=0; version
<DRIVER_MAX_VERSION
; version
++) {
7577 result
= winreg_get_driver_list(tmp_ctx
, b
,
7578 architecture
, version
,
7579 &num_drivers
, &drivers
);
7580 if (!W_ERROR_IS_OK(result
)) {
7583 DEBUG(4, ("we have:[%d] drivers in environment"
7584 " [%s] and version [%d]\n",
7585 num_drivers
, architecture
, version
));
7587 if (num_drivers
!= 0) {
7588 info
= talloc_realloc(tmp_ctx
, info
,
7589 union spoolss_DriverInfo
,
7590 count
+ num_drivers
);
7592 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
7593 "failed to enlarge driver info buffer!\n"));
7594 result
= WERR_NOMEM
;
7599 for (i
= 0; i
< num_drivers
; i
++) {
7600 DEBUG(5, ("\tdriver: [%s]\n", drivers
[i
]));
7602 result
= winreg_get_driver(tmp_ctx
, b
,
7603 architecture
, drivers
[i
],
7605 if (!W_ERROR_IS_OK(result
)) {
7611 result
= fill_printer_driver_info1(info
, &info
[count
+i
].info1
,
7612 driver
, servername
);
7615 result
= fill_printer_driver_info2(info
, &info
[count
+i
].info2
,
7616 driver
, servername
);
7619 result
= fill_printer_driver_info3(info
, &info
[count
+i
].info3
,
7620 driver
, servername
);
7623 result
= fill_printer_driver_info4(info
, &info
[count
+i
].info4
,
7624 driver
, servername
);
7627 result
= fill_printer_driver_info5(info
, &info
[count
+i
].info5
,
7628 driver
, servername
);
7631 result
= fill_printer_driver_info6(info
, &info
[count
+i
].info6
,
7632 driver
, servername
);
7635 result
= fill_printer_driver_info8(info
, &info
[count
+i
].info8
,
7636 driver
, servername
);
7639 result
= WERR_UNKNOWN_LEVEL
;
7643 TALLOC_FREE(driver
);
7645 if (!W_ERROR_IS_OK(result
)) {
7650 count
+= num_drivers
;
7651 TALLOC_FREE(drivers
);
7655 if (W_ERROR_IS_OK(result
)) {
7656 *info_p
= talloc_move(mem_ctx
, &info
);
7660 talloc_free(tmp_ctx
);
7664 /****************************************************************************
7665 Enumerates all printer drivers by level.
7666 ****************************************************************************/
7668 static WERROR
enumprinterdrivers_level(TALLOC_CTX
*mem_ctx
,
7669 const struct auth_session_info
*session_info
,
7670 struct messaging_context
*msg_ctx
,
7671 const char *servername
,
7672 const char *architecture
,
7674 union spoolss_DriverInfo
**info_p
,
7678 WERROR result
= WERR_OK
;
7680 if (strequal(architecture
, SPOOLSS_ARCHITECTURE_ALL
)) {
7682 for (a
=0; archi_table
[a
].long_archi
!= NULL
; a
++) {
7684 union spoolss_DriverInfo
*info
= NULL
;
7687 result
= enumprinterdrivers_level_by_architecture(mem_ctx
,
7691 archi_table
[a
].long_archi
,
7695 if (!W_ERROR_IS_OK(result
)) {
7699 for (i
=0; i
< count
; i
++) {
7700 ADD_TO_ARRAY(mem_ctx
, union spoolss_DriverInfo
,
7701 info
[i
], info_p
, count_p
);
7708 return enumprinterdrivers_level_by_architecture(mem_ctx
,
7718 /****************************************************************
7719 _spoolss_EnumPrinterDrivers
7720 ****************************************************************/
7722 WERROR
_spoolss_EnumPrinterDrivers(struct pipes_struct
*p
,
7723 struct spoolss_EnumPrinterDrivers
*r
)
7725 const char *cservername
;
7728 /* that's an [in out] buffer */
7730 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
7731 return WERR_INVALID_PARAM
;
7734 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
7738 *r
->out
.info
= NULL
;
7740 cservername
= canon_servername(r
->in
.server
);
7742 if (!is_myname_or_ipaddr(cservername
)) {
7743 return WERR_UNKNOWN_PRINTER_DRIVER
;
7746 result
= enumprinterdrivers_level(p
->mem_ctx
,
7747 get_session_info_system(),
7754 if (!W_ERROR_IS_OK(result
)) {
7758 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
7759 spoolss_EnumPrinterDrivers
,
7760 *r
->out
.info
, r
->in
.level
,
7762 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
7763 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
7765 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
7768 /****************************************************************
7770 ****************************************************************/
7772 WERROR
_spoolss_EnumForms(struct pipes_struct
*p
,
7773 struct spoolss_EnumForms
*r
)
7779 *r
->out
.info
= NULL
;
7781 /* that's an [in out] buffer */
7783 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0) ) {
7784 return WERR_INVALID_PARAM
;
7787 DEBUG(4,("_spoolss_EnumForms\n"));
7788 DEBUGADD(5,("Offered buffer size [%d]\n", r
->in
.offered
));
7789 DEBUGADD(5,("Info level [%d]\n", r
->in
.level
));
7791 switch (r
->in
.level
) {
7793 result
= winreg_printer_enumforms1_internal(p
->mem_ctx
,
7794 get_session_info_system(),
7800 result
= WERR_UNKNOWN_LEVEL
;
7804 if (!W_ERROR_IS_OK(result
)) {
7808 if (*r
->out
.count
== 0) {
7809 return WERR_NO_MORE_ITEMS
;
7812 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
7814 *r
->out
.info
, r
->in
.level
,
7816 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
7817 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
7819 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
7822 /****************************************************************
7824 ****************************************************************/
7826 WERROR
_spoolss_GetForm(struct pipes_struct
*p
,
7827 struct spoolss_GetForm
*r
)
7831 /* that's an [in out] buffer */
7833 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
7834 return WERR_INVALID_PARAM
;
7837 DEBUG(4,("_spoolss_GetForm\n"));
7838 DEBUGADD(5,("Offered buffer size [%d]\n", r
->in
.offered
));
7839 DEBUGADD(5,("Info level [%d]\n", r
->in
.level
));
7841 switch (r
->in
.level
) {
7843 result
= winreg_printer_getform1_internal(p
->mem_ctx
,
7844 get_session_info_system(),
7847 &r
->out
.info
->info1
);
7850 result
= WERR_UNKNOWN_LEVEL
;
7854 if (!W_ERROR_IS_OK(result
)) {
7855 TALLOC_FREE(r
->out
.info
);
7859 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_FormInfo
,
7860 r
->out
.info
, r
->in
.level
);
7861 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
7863 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
7866 /****************************************************************************
7867 ****************************************************************************/
7869 static WERROR
fill_port_1(TALLOC_CTX
*mem_ctx
,
7870 struct spoolss_PortInfo1
*r
,
7873 r
->port_name
= talloc_strdup(mem_ctx
, name
);
7874 W_ERROR_HAVE_NO_MEMORY(r
->port_name
);
7879 /****************************************************************************
7880 TODO: This probably needs distinguish between TCP/IP and Local ports
7882 ****************************************************************************/
7884 static WERROR
fill_port_2(TALLOC_CTX
*mem_ctx
,
7885 struct spoolss_PortInfo2
*r
,
7888 r
->port_name
= talloc_strdup(mem_ctx
, name
);
7889 W_ERROR_HAVE_NO_MEMORY(r
->port_name
);
7891 r
->monitor_name
= talloc_strdup(mem_ctx
, "Local Monitor");
7892 W_ERROR_HAVE_NO_MEMORY(r
->monitor_name
);
7894 r
->description
= talloc_strdup(mem_ctx
, SPL_LOCAL_PORT
);
7895 W_ERROR_HAVE_NO_MEMORY(r
->description
);
7897 r
->port_type
= SPOOLSS_PORT_TYPE_WRITE
;
7904 /****************************************************************************
7905 wrapper around the enumer ports command
7906 ****************************************************************************/
7908 static WERROR
enumports_hook(TALLOC_CTX
*ctx
, int *count
, char ***lines
)
7910 char *cmd
= lp_enumports_cmd(talloc_tos());
7911 char **qlines
= NULL
;
7912 char *command
= NULL
;
7920 /* if no hook then just fill in the default port */
7923 if (!(qlines
= talloc_array( NULL
, char*, 2 ))) {
7926 if (!(qlines
[0] = talloc_strdup(qlines
, SAMBA_PRINTER_PORT_NAME
))) {
7927 TALLOC_FREE(qlines
);
7934 /* we have a valid enumport command */
7936 command
= talloc_asprintf(ctx
, "%s \"%d\"", cmd
, 1);
7941 DEBUG(10,("Running [%s]\n", command
));
7942 ret
= smbrun(command
, &fd
);
7943 DEBUG(10,("Returned [%d]\n", ret
));
7944 TALLOC_FREE(command
);
7949 return WERR_ACCESS_DENIED
;
7953 qlines
= fd_lines_load(fd
, &numlines
, 0, NULL
);
7954 DEBUGADD(10,("Lines returned = [%d]\n", numlines
));
7964 /****************************************************************************
7966 ****************************************************************************/
7968 static WERROR
enumports_level_1(TALLOC_CTX
*mem_ctx
,
7969 union spoolss_PortInfo
**info_p
,
7972 union spoolss_PortInfo
*info
= NULL
;
7974 WERROR result
= WERR_OK
;
7975 char **qlines
= NULL
;
7978 result
= enumports_hook(talloc_tos(), &numlines
, &qlines
);
7979 if (!W_ERROR_IS_OK(result
)) {
7984 info
= talloc_array(mem_ctx
, union spoolss_PortInfo
, numlines
);
7986 DEBUG(10,("Returning WERR_NOMEM\n"));
7987 result
= WERR_NOMEM
;
7991 for (i
=0; i
<numlines
; i
++) {
7992 DEBUG(6,("Filling port number [%d] with port [%s]\n", i
, qlines
[i
]));
7993 result
= fill_port_1(info
, &info
[i
].info1
, qlines
[i
]);
7994 if (!W_ERROR_IS_OK(result
)) {
7999 TALLOC_FREE(qlines
);
8002 if (!W_ERROR_IS_OK(result
)) {
8004 TALLOC_FREE(qlines
);
8016 /****************************************************************************
8018 ****************************************************************************/
8020 static WERROR
enumports_level_2(TALLOC_CTX
*mem_ctx
,
8021 union spoolss_PortInfo
**info_p
,
8024 union spoolss_PortInfo
*info
= NULL
;
8026 WERROR result
= WERR_OK
;
8027 char **qlines
= NULL
;
8030 result
= enumports_hook(talloc_tos(), &numlines
, &qlines
);
8031 if (!W_ERROR_IS_OK(result
)) {
8036 info
= talloc_array(mem_ctx
, union spoolss_PortInfo
, numlines
);
8038 DEBUG(10,("Returning WERR_NOMEM\n"));
8039 result
= WERR_NOMEM
;
8043 for (i
=0; i
<numlines
; i
++) {
8044 DEBUG(6,("Filling port number [%d] with port [%s]\n", i
, qlines
[i
]));
8045 result
= fill_port_2(info
, &info
[i
].info2
, qlines
[i
]);
8046 if (!W_ERROR_IS_OK(result
)) {
8051 TALLOC_FREE(qlines
);
8054 if (!W_ERROR_IS_OK(result
)) {
8056 TALLOC_FREE(qlines
);
8068 /****************************************************************
8070 ****************************************************************/
8072 WERROR
_spoolss_EnumPorts(struct pipes_struct
*p
,
8073 struct spoolss_EnumPorts
*r
)
8077 /* that's an [in out] buffer */
8079 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
8080 return WERR_INVALID_PARAM
;
8083 DEBUG(4,("_spoolss_EnumPorts\n"));
8087 *r
->out
.info
= NULL
;
8089 switch (r
->in
.level
) {
8091 result
= enumports_level_1(p
->mem_ctx
, r
->out
.info
,
8095 result
= enumports_level_2(p
->mem_ctx
, r
->out
.info
,
8099 return WERR_UNKNOWN_LEVEL
;
8102 if (!W_ERROR_IS_OK(result
)) {
8106 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
8108 *r
->out
.info
, r
->in
.level
,
8110 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
8111 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
8113 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
8116 /****************************************************************************
8117 ****************************************************************************/
8119 static WERROR
spoolss_addprinterex_level_2(struct pipes_struct
*p
,
8121 struct spoolss_SetPrinterInfoCtr
*info_ctr
,
8122 struct spoolss_DeviceMode
*devmode
,
8123 struct security_descriptor
*secdesc
,
8124 struct spoolss_UserLevelCtr
*user_ctr
,
8125 struct policy_handle
*handle
)
8127 struct spoolss_SetPrinterInfo2
*info2
= info_ctr
->info
.info2
;
8128 uint32_t info2_mask
= SPOOLSS_PRINTER_INFO_ALL
;
8130 WERROR err
= WERR_OK
;
8132 /* samba does not have a concept of local, non-shared printers yet, so
8133 * make sure we always setup sharename - gd */
8134 if ((info2
->sharename
== NULL
|| info2
->sharename
[0] == '\0') &&
8135 (info2
->printername
!= NULL
&& info2
->printername
[0] != '\0')) {
8136 DEBUG(5, ("spoolss_addprinterex_level_2: "
8137 "no sharename has been set, setting printername %s as sharename\n",
8138 info2
->printername
));
8139 info2
->sharename
= info2
->printername
;
8142 /* check to see if the printer already exists */
8143 if ((snum
= print_queue_snum(info2
->sharename
)) != -1) {
8144 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
8146 return WERR_PRINTER_ALREADY_EXISTS
;
8149 if (!lp_force_printername(GLOBAL_SECTION_SNUM
)) {
8150 if ((snum
= print_queue_snum(info2
->printername
)) != -1) {
8151 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
8152 info2
->printername
));
8153 return WERR_PRINTER_ALREADY_EXISTS
;
8157 /* validate printer info struct */
8158 if (!info2
->printername
|| strlen(info2
->printername
) == 0) {
8159 return WERR_INVALID_PRINTER_NAME
;
8161 if (!info2
->portname
|| strlen(info2
->portname
) == 0) {
8162 return WERR_UNKNOWN_PORT
;
8164 if (!info2
->drivername
|| strlen(info2
->drivername
) == 0) {
8165 return WERR_UNKNOWN_PRINTER_DRIVER
;
8167 if (!info2
->printprocessor
|| strlen(info2
->printprocessor
) == 0) {
8168 return WERR_UNKNOWN_PRINTPROCESSOR
;
8171 /* FIXME!!! smbd should check to see if the driver is installed before
8172 trying to add a printer like this --jerry */
8174 if (*lp_addprinter_cmd(talloc_tos()) ) {
8177 raddr
= tsocket_address_inet_addr_string(p
->remote_address
,
8179 if (raddr
== NULL
) {
8183 if ( !add_printer_hook(p
->mem_ctx
, p
->session_info
->security_token
,
8186 return WERR_ACCESS_DENIED
;
8189 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no "
8190 "smb.conf parameter \"addprinter command\" is defined. This "
8191 "parameter must exist for this call to succeed\n",
8192 info2
->sharename
));
8195 if ((snum
= print_queue_snum(info2
->sharename
)) == -1) {
8196 return WERR_ACCESS_DENIED
;
8199 /* you must be a printer admin to add a new printer */
8200 if (!print_access_check(p
->session_info
,
8203 PRINTER_ACCESS_ADMINISTER
)) {
8204 return WERR_ACCESS_DENIED
;
8208 * Do sanity check on the requested changes for Samba.
8211 if (!check_printer_ok(p
->mem_ctx
, info2
, snum
)) {
8212 return WERR_INVALID_PARAM
;
8215 if (devmode
== NULL
) {
8216 info2_mask
= ~SPOOLSS_PRINTER_INFO_DEVMODE
;
8219 err
= update_dsspooler(p
->mem_ctx
,
8220 get_session_info_system(),
8225 if (!W_ERROR_IS_OK(err
)) {
8229 err
= winreg_update_printer_internal(p
->mem_ctx
,
8230 get_session_info_system(),
8237 if (!W_ERROR_IS_OK(err
)) {
8241 err
= open_printer_hnd(p
, handle
, info2
->printername
, PRINTER_ACCESS_ADMINISTER
);
8242 if (!W_ERROR_IS_OK(err
)) {
8243 /* Handle open failed - remove addition. */
8244 ZERO_STRUCTP(handle
);
8251 /****************************************************************
8252 _spoolss_AddPrinterEx
8253 ****************************************************************/
8255 WERROR
_spoolss_AddPrinterEx(struct pipes_struct
*p
,
8256 struct spoolss_AddPrinterEx
*r
)
8258 switch (r
->in
.info_ctr
->level
) {
8260 /* we don't handle yet */
8261 /* but I know what to do ... */
8262 return WERR_UNKNOWN_LEVEL
;
8264 return spoolss_addprinterex_level_2(p
, r
->in
.server
,
8266 r
->in
.devmode_ctr
->devmode
,
8267 r
->in
.secdesc_ctr
->sd
,
8268 r
->in
.userlevel_ctr
,
8271 return WERR_UNKNOWN_LEVEL
;
8275 /****************************************************************
8277 ****************************************************************/
8279 WERROR
_spoolss_AddPrinter(struct pipes_struct
*p
,
8280 struct spoolss_AddPrinter
*r
)
8282 struct spoolss_AddPrinterEx a
;
8283 struct spoolss_UserLevelCtr userlevel_ctr
;
8285 ZERO_STRUCT(userlevel_ctr
);
8287 userlevel_ctr
.level
= 1;
8289 a
.in
.server
= r
->in
.server
;
8290 a
.in
.info_ctr
= r
->in
.info_ctr
;
8291 a
.in
.devmode_ctr
= r
->in
.devmode_ctr
;
8292 a
.in
.secdesc_ctr
= r
->in
.secdesc_ctr
;
8293 a
.in
.userlevel_ctr
= &userlevel_ctr
;
8294 a
.out
.handle
= r
->out
.handle
;
8296 return _spoolss_AddPrinterEx(p
, &a
);
8299 /****************************************************************
8300 _spoolss_AddPrinterDriverEx
8301 ****************************************************************/
8303 WERROR
_spoolss_AddPrinterDriverEx(struct pipes_struct
*p
,
8304 struct spoolss_AddPrinterDriverEx
*r
)
8306 WERROR err
= WERR_OK
;
8307 const char *driver_name
= NULL
;
8312 case NDR_SPOOLSS_ADDPRINTERDRIVER
:
8313 fn
= "_spoolss_AddPrinterDriver";
8315 case NDR_SPOOLSS_ADDPRINTERDRIVEREX
:
8316 fn
= "_spoolss_AddPrinterDriverEx";
8319 return WERR_INVALID_PARAM
;
8323 * we only support the semantics of AddPrinterDriver()
8324 * i.e. only copy files that are newer than existing ones
8327 if (r
->in
.flags
== 0) {
8328 return WERR_INVALID_PARAM
;
8331 if (r
->in
.flags
!= APD_COPY_NEW_FILES
) {
8332 return WERR_ACCESS_DENIED
;
8336 if (r
->in
.info_ctr
->level
!= 3 && r
->in
.info_ctr
->level
!= 6) {
8337 /* Clever hack from Martin Zielinski <mz@seh.de>
8338 * to allow downgrade from level 8 (Vista).
8340 DEBUG(0,("%s: level %d not yet implemented\n", fn
,
8341 r
->in
.info_ctr
->level
));
8342 return WERR_UNKNOWN_LEVEL
;
8345 DEBUG(5,("Cleaning driver's information\n"));
8346 err
= clean_up_driver_struct(p
->mem_ctx
, p
->session_info
, r
->in
.info_ctr
);
8347 if (!W_ERROR_IS_OK(err
))
8350 DEBUG(5,("Moving driver to final destination\n"));
8351 err
= move_driver_to_download_area(p
->session_info
, r
->in
.info_ctr
);
8352 if (!W_ERROR_IS_OK(err
)) {
8356 err
= winreg_add_driver_internal(p
->mem_ctx
,
8357 get_session_info_system(),
8362 if (!W_ERROR_IS_OK(err
)) {
8367 * I think this is where he DrvUpgradePrinter() hook would be
8368 * be called in a driver's interface DLL on a Windows NT 4.0/2k
8369 * server. Right now, we just need to send ourselves a message
8370 * to update each printer bound to this driver. --jerry
8373 if (!srv_spoolss_drv_upgrade_printer(driver_name
, p
->msg_ctx
)) {
8374 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
8382 /****************************************************************
8383 _spoolss_AddPrinterDriver
8384 ****************************************************************/
8386 WERROR
_spoolss_AddPrinterDriver(struct pipes_struct
*p
,
8387 struct spoolss_AddPrinterDriver
*r
)
8389 struct spoolss_AddPrinterDriverEx a
;
8391 switch (r
->in
.info_ctr
->level
) {
8398 return WERR_UNKNOWN_LEVEL
;
8401 a
.in
.servername
= r
->in
.servername
;
8402 a
.in
.info_ctr
= r
->in
.info_ctr
;
8403 a
.in
.flags
= APD_COPY_NEW_FILES
;
8405 return _spoolss_AddPrinterDriverEx(p
, &a
);
8408 /****************************************************************************
8409 ****************************************************************************/
8411 struct _spoolss_paths
{
8417 enum { SPOOLSS_DRIVER_PATH
, SPOOLSS_PRTPROCS_PATH
};
8419 static const struct _spoolss_paths spoolss_paths
[]= {
8420 { SPOOLSS_DRIVER_PATH
, "print$", "DRIVERS" },
8421 { SPOOLSS_PRTPROCS_PATH
, "prnproc$", "PRTPROCS" }
8424 static WERROR
compose_spoolss_server_path(TALLOC_CTX
*mem_ctx
,
8425 const char *servername
,
8426 const char *environment
,
8430 const char *pservername
= NULL
;
8431 const char *long_archi
= SPOOLSS_ARCHITECTURE_NT_X86
;
8432 const char *short_archi
;
8436 /* environment may be empty */
8437 if (environment
&& strlen(environment
)) {
8438 long_archi
= environment
;
8441 /* servername may be empty */
8442 if (servername
&& strlen(servername
)) {
8443 pservername
= canon_servername(servername
);
8445 if (!is_myname_or_ipaddr(pservername
)) {
8446 return WERR_INVALID_PARAM
;
8450 if (!(short_archi
= get_short_archi(long_archi
))) {
8451 return WERR_INVALID_ENVIRONMENT
;
8454 switch (component
) {
8455 case SPOOLSS_PRTPROCS_PATH
:
8456 case SPOOLSS_DRIVER_PATH
:
8458 *path
= talloc_asprintf(mem_ctx
,
8461 spoolss_paths
[component
].share
,
8464 *path
= talloc_asprintf(mem_ctx
, "%s\\%s\\%s",
8465 SPOOLSS_DEFAULT_SERVER_PATH
,
8466 spoolss_paths
[component
].dir
,
8471 return WERR_INVALID_PARAM
;
8481 /****************************************************************************
8482 ****************************************************************************/
8484 static WERROR
getprinterdriverdir_level_1(TALLOC_CTX
*mem_ctx
,
8485 const char *servername
,
8486 const char *environment
,
8487 struct spoolss_DriverDirectoryInfo1
*r
)
8492 werr
= compose_spoolss_server_path(mem_ctx
,
8495 SPOOLSS_DRIVER_PATH
,
8497 if (!W_ERROR_IS_OK(werr
)) {
8501 DEBUG(4,("printer driver directory: [%s]\n", path
));
8503 r
->directory_name
= path
;
8508 /****************************************************************
8509 _spoolss_GetPrinterDriverDirectory
8510 ****************************************************************/
8512 WERROR
_spoolss_GetPrinterDriverDirectory(struct pipes_struct
*p
,
8513 struct spoolss_GetPrinterDriverDirectory
*r
)
8517 /* that's an [in out] buffer */
8519 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
8520 return WERR_INVALID_PARAM
;
8523 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
8528 /* r->in.level is ignored */
8530 werror
= getprinterdriverdir_level_1(p
->mem_ctx
,
8533 &r
->out
.info
->info1
);
8534 if (!W_ERROR_IS_OK(werror
)) {
8535 TALLOC_FREE(r
->out
.info
);
8539 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo
,
8540 r
->out
.info
, r
->in
.level
);
8541 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
8543 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
8546 /****************************************************************
8547 _spoolss_EnumPrinterData
8548 ****************************************************************/
8550 WERROR
_spoolss_EnumPrinterData(struct pipes_struct
*p
,
8551 struct spoolss_EnumPrinterData
*r
)
8554 struct spoolss_EnumPrinterDataEx r2
;
8556 struct spoolss_PrinterEnumValues
*info
, *val
= NULL
;
8559 r2
.in
.handle
= r
->in
.handle
;
8560 r2
.in
.key_name
= "PrinterDriverData";
8562 r2
.out
.count
= &count
;
8563 r2
.out
.info
= &info
;
8564 r2
.out
.needed
= &needed
;
8566 result
= _spoolss_EnumPrinterDataEx(p
, &r2
);
8567 if (W_ERROR_EQUAL(result
, WERR_MORE_DATA
)) {
8568 r2
.in
.offered
= needed
;
8569 result
= _spoolss_EnumPrinterDataEx(p
, &r2
);
8571 if (!W_ERROR_IS_OK(result
)) {
8576 * The NT machine wants to know the biggest size of value and data
8578 * cf: MSDN EnumPrinterData remark section
8581 if (!r
->in
.value_offered
&& !r
->in
.data_offered
) {
8582 uint32_t biggest_valuesize
= 0;
8583 uint32_t biggest_datasize
= 0;
8586 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
8588 for (i
=0; i
<count
; i
++) {
8590 name_length
= strlen(info
[i
].value_name
);
8591 if (strlen(info
[i
].value_name
) > biggest_valuesize
) {
8592 biggest_valuesize
= name_length
;
8595 if (info
[i
].data_length
> biggest_datasize
) {
8596 biggest_datasize
= info
[i
].data_length
;
8599 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize
,
8603 /* the value is an UNICODE string but real_value_size is the length
8604 in bytes including the trailing 0 */
8606 *r
->out
.value_needed
= 2 * (1 + biggest_valuesize
);
8607 *r
->out
.data_needed
= biggest_datasize
;
8609 DEBUG(6,("final values: [%d], [%d]\n",
8610 *r
->out
.value_needed
, *r
->out
.data_needed
));
8615 if (r
->in
.enum_index
< count
) {
8616 val
= &info
[r
->in
.enum_index
];
8620 /* out_value should default to "" or else NT4 has
8621 problems unmarshalling the response */
8623 if (r
->in
.value_offered
) {
8624 *r
->out
.value_needed
= 1;
8625 r
->out
.value_name
= talloc_strdup(r
, "");
8626 if (!r
->out
.value_name
) {
8630 r
->out
.value_name
= NULL
;
8631 *r
->out
.value_needed
= 0;
8634 /* the data is counted in bytes */
8636 *r
->out
.data_needed
= r
->in
.data_offered
;
8638 result
= WERR_NO_MORE_ITEMS
;
8642 * - counted in bytes in the request
8643 * - counted in UNICODE chars in the max reply
8644 * - counted in bytes in the real size
8646 * take a pause *before* coding not *during* coding
8650 if (r
->in
.value_offered
) {
8651 r
->out
.value_name
= talloc_strdup(r
, val
->value_name
);
8652 if (!r
->out
.value_name
) {
8655 *r
->out
.value_needed
= val
->value_name_len
;
8657 r
->out
.value_name
= NULL
;
8658 *r
->out
.value_needed
= 0;
8663 *r
->out
.type
= val
->type
;
8665 /* data - counted in bytes */
8668 * See the section "Dynamically Typed Query Parameters"
8672 if (r
->out
.data
&& val
->data
&& val
->data
->data
&&
8673 val
->data_length
&& r
->in
.data_offered
) {
8674 memcpy(r
->out
.data
, val
->data
->data
,
8675 MIN(val
->data_length
,r
->in
.data_offered
));
8678 *r
->out
.data_needed
= val
->data_length
;
8686 /****************************************************************
8687 _spoolss_SetPrinterData
8688 ****************************************************************/
8690 WERROR
_spoolss_SetPrinterData(struct pipes_struct
*p
,
8691 struct spoolss_SetPrinterData
*r
)
8693 struct spoolss_SetPrinterDataEx r2
;
8695 r2
.in
.handle
= r
->in
.handle
;
8696 r2
.in
.key_name
= "PrinterDriverData";
8697 r2
.in
.value_name
= r
->in
.value_name
;
8698 r2
.in
.type
= r
->in
.type
;
8699 r2
.in
.data
= r
->in
.data
;
8700 r2
.in
.offered
= r
->in
.offered
;
8702 return _spoolss_SetPrinterDataEx(p
, &r2
);
8705 /****************************************************************
8706 _spoolss_ResetPrinter
8707 ****************************************************************/
8709 WERROR
_spoolss_ResetPrinter(struct pipes_struct
*p
,
8710 struct spoolss_ResetPrinter
*r
)
8712 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
8715 DEBUG(5,("_spoolss_ResetPrinter\n"));
8718 * All we do is to check to see if the handle and queue is valid.
8719 * This call really doesn't mean anything to us because we only
8720 * support RAW printing. --jerry
8724 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
8725 OUR_HANDLE(r
->in
.handle
)));
8729 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
))
8733 /* blindly return success */
8737 /****************************************************************
8738 _spoolss_DeletePrinterData
8739 ****************************************************************/
8741 WERROR
_spoolss_DeletePrinterData(struct pipes_struct
*p
,
8742 struct spoolss_DeletePrinterData
*r
)
8744 struct spoolss_DeletePrinterDataEx r2
;
8746 r2
.in
.handle
= r
->in
.handle
;
8747 r2
.in
.key_name
= "PrinterDriverData";
8748 r2
.in
.value_name
= r
->in
.value_name
;
8750 return _spoolss_DeletePrinterDataEx(p
, &r2
);
8753 /****************************************************************
8755 ****************************************************************/
8757 WERROR
_spoolss_AddForm(struct pipes_struct
*p
,
8758 struct spoolss_AddForm
*r
)
8760 struct spoolss_AddFormInfo1
*form
= r
->in
.info
.info1
;
8762 WERROR status
= WERR_OK
;
8763 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
8764 struct dcerpc_binding_handle
*b
;
8765 TALLOC_CTX
*tmp_ctx
= NULL
;
8767 DEBUG(5,("_spoolss_AddForm\n"));
8770 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
8771 OUR_HANDLE(r
->in
.handle
)));
8775 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8776 and not a printer admin, then fail */
8778 if ((p
->session_info
->unix_token
->uid
!= sec_initial_uid()) &&
8779 !security_token_has_privilege(p
->session_info
->security_token
,
8780 SEC_PRIV_PRINT_OPERATOR
)) {
8781 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
8782 return WERR_ACCESS_DENIED
;
8785 switch (form
->flags
) {
8786 case SPOOLSS_FORM_USER
:
8787 case SPOOLSS_FORM_BUILTIN
:
8788 case SPOOLSS_FORM_PRINTER
:
8791 return WERR_INVALID_PARAM
;
8794 tmp_ctx
= talloc_new(p
->mem_ctx
);
8799 status
= winreg_printer_binding_handle(tmp_ctx
,
8800 get_session_info_system(),
8803 if (!W_ERROR_IS_OK(status
)) {
8807 status
= winreg_printer_addform1(tmp_ctx
, b
, form
);
8808 if (!W_ERROR_IS_OK(status
)) {
8813 * ChangeID must always be set if this is a printer
8815 if (Printer
->printer_type
== SPLHND_PRINTER
) {
8816 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
8817 status
= WERR_BADFID
;
8821 status
= winreg_printer_update_changeid(tmp_ctx
, b
,
8822 lp_const_servicename(snum
));
8826 talloc_free(tmp_ctx
);
8830 /****************************************************************
8832 ****************************************************************/
8834 WERROR
_spoolss_DeleteForm(struct pipes_struct
*p
,
8835 struct spoolss_DeleteForm
*r
)
8837 const char *form_name
= r
->in
.form_name
;
8838 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
8840 WERROR status
= WERR_OK
;
8841 struct dcerpc_binding_handle
*b
;
8842 TALLOC_CTX
*tmp_ctx
= NULL
;
8844 DEBUG(5,("_spoolss_DeleteForm\n"));
8847 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
8848 OUR_HANDLE(r
->in
.handle
)));
8852 if ((p
->session_info
->unix_token
->uid
!= sec_initial_uid()) &&
8853 !security_token_has_privilege(p
->session_info
->security_token
,
8854 SEC_PRIV_PRINT_OPERATOR
)) {
8855 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
8856 return WERR_ACCESS_DENIED
;
8859 tmp_ctx
= talloc_new(p
->mem_ctx
);
8864 status
= winreg_printer_binding_handle(tmp_ctx
,
8865 get_session_info_system(),
8868 if (!W_ERROR_IS_OK(status
)) {
8872 status
= winreg_printer_deleteform1(tmp_ctx
, b
, form_name
);
8873 if (!W_ERROR_IS_OK(status
)) {
8878 * ChangeID must always be set if this is a printer
8880 if (Printer
->printer_type
== SPLHND_PRINTER
) {
8881 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
8882 status
= WERR_BADFID
;
8886 status
= winreg_printer_update_changeid(tmp_ctx
, b
,
8887 lp_const_servicename(snum
));
8891 talloc_free(tmp_ctx
);
8895 /****************************************************************
8897 ****************************************************************/
8899 WERROR
_spoolss_SetForm(struct pipes_struct
*p
,
8900 struct spoolss_SetForm
*r
)
8902 struct spoolss_AddFormInfo1
*form
= r
->in
.info
.info1
;
8903 const char *form_name
= r
->in
.form_name
;
8905 WERROR status
= WERR_OK
;
8906 struct dcerpc_binding_handle
*b
;
8907 TALLOC_CTX
*tmp_ctx
= NULL
;
8909 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
8911 DEBUG(5,("_spoolss_SetForm\n"));
8914 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8915 OUR_HANDLE(r
->in
.handle
)));
8919 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8920 and not a printer admin, then fail */
8922 if ((p
->session_info
->unix_token
->uid
!= sec_initial_uid()) &&
8923 !security_token_has_privilege(p
->session_info
->security_token
,
8924 SEC_PRIV_PRINT_OPERATOR
)) {
8925 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
8926 return WERR_ACCESS_DENIED
;
8929 tmp_ctx
= talloc_new(p
->mem_ctx
);
8934 status
= winreg_printer_binding_handle(tmp_ctx
,
8935 get_session_info_system(),
8938 if (!W_ERROR_IS_OK(status
)) {
8942 status
= winreg_printer_setform1(tmp_ctx
, b
,
8945 if (!W_ERROR_IS_OK(status
)) {
8950 * ChangeID must always be set if this is a printer
8952 if (Printer
->printer_type
== SPLHND_PRINTER
) {
8953 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
8954 status
= WERR_BADFID
;
8958 status
= winreg_printer_update_changeid(tmp_ctx
, b
,
8959 lp_const_servicename(snum
));
8963 talloc_free(tmp_ctx
);
8967 /****************************************************************************
8968 fill_print_processor1
8969 ****************************************************************************/
8971 static WERROR
fill_print_processor1(TALLOC_CTX
*mem_ctx
,
8972 struct spoolss_PrintProcessorInfo1
*r
,
8973 const char *print_processor_name
)
8975 r
->print_processor_name
= talloc_strdup(mem_ctx
, print_processor_name
);
8976 W_ERROR_HAVE_NO_MEMORY(r
->print_processor_name
);
8981 /****************************************************************************
8982 enumprintprocessors level 1.
8983 ****************************************************************************/
8985 static WERROR
enumprintprocessors_level_1(TALLOC_CTX
*mem_ctx
,
8986 union spoolss_PrintProcessorInfo
**info_p
,
8989 union spoolss_PrintProcessorInfo
*info
;
8992 info
= talloc_array(mem_ctx
, union spoolss_PrintProcessorInfo
, 1);
8993 W_ERROR_HAVE_NO_MEMORY(info
);
8997 result
= fill_print_processor1(info
, &info
[0].info1
, "winprint");
8998 if (!W_ERROR_IS_OK(result
)) {
9003 if (!W_ERROR_IS_OK(result
)) {
9014 /****************************************************************
9015 _spoolss_EnumPrintProcessors
9016 ****************************************************************/
9018 WERROR
_spoolss_EnumPrintProcessors(struct pipes_struct
*p
,
9019 struct spoolss_EnumPrintProcessors
*r
)
9023 /* that's an [in out] buffer */
9025 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
9026 return WERR_INVALID_PARAM
;
9029 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
9032 * Enumerate the print processors ...
9034 * Just reply with "winprint", to keep NT happy
9035 * and I can use my nice printer checker.
9040 *r
->out
.info
= NULL
;
9042 if (!get_short_archi(r
->in
.environment
)) {
9043 return WERR_INVALID_ENVIRONMENT
;
9046 switch (r
->in
.level
) {
9048 result
= enumprintprocessors_level_1(p
->mem_ctx
, r
->out
.info
,
9052 return WERR_UNKNOWN_LEVEL
;
9055 if (!W_ERROR_IS_OK(result
)) {
9059 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
9060 spoolss_EnumPrintProcessors
,
9061 *r
->out
.info
, r
->in
.level
,
9063 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
9064 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
9066 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
9069 /****************************************************************************
9070 fill_printprocdatatype1
9071 ****************************************************************************/
9073 static WERROR
fill_printprocdatatype1(TALLOC_CTX
*mem_ctx
,
9074 struct spoolss_PrintProcDataTypesInfo1
*r
,
9075 const char *name_array
)
9077 r
->name_array
= talloc_strdup(mem_ctx
, name_array
);
9078 W_ERROR_HAVE_NO_MEMORY(r
->name_array
);
9083 /****************************************************************************
9084 enumprintprocdatatypes level 1.
9085 ****************************************************************************/
9087 static WERROR
enumprintprocdatatypes_level_1(TALLOC_CTX
*mem_ctx
,
9088 union spoolss_PrintProcDataTypesInfo
**info_p
,
9092 union spoolss_PrintProcDataTypesInfo
*info
;
9094 info
= talloc_array(mem_ctx
, union spoolss_PrintProcDataTypesInfo
, 1);
9095 W_ERROR_HAVE_NO_MEMORY(info
);
9099 result
= fill_printprocdatatype1(info
, &info
[0].info1
, "RAW");
9100 if (!W_ERROR_IS_OK(result
)) {
9105 if (!W_ERROR_IS_OK(result
)) {
9116 /****************************************************************
9117 _spoolss_EnumPrintProcDataTypes
9118 ****************************************************************/
9120 WERROR
_spoolss_EnumPrintProcDataTypes(struct pipes_struct
*p
,
9121 struct spoolss_EnumPrintProcDataTypes
*r
)
9125 /* that's an [in out] buffer */
9127 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
9128 return WERR_INVALID_PARAM
;
9131 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
9135 *r
->out
.info
= NULL
;
9137 if (r
->in
.print_processor_name
== NULL
||
9138 !strequal(r
->in
.print_processor_name
, "winprint")) {
9139 return WERR_UNKNOWN_PRINTPROCESSOR
;
9142 switch (r
->in
.level
) {
9144 result
= enumprintprocdatatypes_level_1(p
->mem_ctx
, r
->out
.info
,
9148 return WERR_UNKNOWN_LEVEL
;
9151 if (!W_ERROR_IS_OK(result
)) {
9155 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
9156 spoolss_EnumPrintProcDataTypes
,
9157 *r
->out
.info
, r
->in
.level
,
9159 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
9160 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
9162 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
9165 /****************************************************************************
9167 ****************************************************************************/
9169 static WERROR
fill_monitor_1(TALLOC_CTX
*mem_ctx
,
9170 struct spoolss_MonitorInfo1
*r
,
9171 const char *monitor_name
)
9173 r
->monitor_name
= talloc_strdup(mem_ctx
, monitor_name
);
9174 W_ERROR_HAVE_NO_MEMORY(r
->monitor_name
);
9179 /****************************************************************************
9181 ****************************************************************************/
9183 static WERROR
fill_monitor_2(TALLOC_CTX
*mem_ctx
,
9184 struct spoolss_MonitorInfo2
*r
,
9185 const char *monitor_name
,
9186 const char *environment
,
9187 const char *dll_name
)
9189 r
->monitor_name
= talloc_strdup(mem_ctx
, monitor_name
);
9190 W_ERROR_HAVE_NO_MEMORY(r
->monitor_name
);
9191 r
->environment
= talloc_strdup(mem_ctx
, environment
);
9192 W_ERROR_HAVE_NO_MEMORY(r
->environment
);
9193 r
->dll_name
= talloc_strdup(mem_ctx
, dll_name
);
9194 W_ERROR_HAVE_NO_MEMORY(r
->dll_name
);
9199 /****************************************************************************
9200 enumprintmonitors level 1.
9201 ****************************************************************************/
9203 static WERROR
enumprintmonitors_level_1(TALLOC_CTX
*mem_ctx
,
9204 union spoolss_MonitorInfo
**info_p
,
9207 union spoolss_MonitorInfo
*info
;
9208 WERROR result
= WERR_OK
;
9210 info
= talloc_array(mem_ctx
, union spoolss_MonitorInfo
, 2);
9211 W_ERROR_HAVE_NO_MEMORY(info
);
9215 result
= fill_monitor_1(info
, &info
[0].info1
,
9217 if (!W_ERROR_IS_OK(result
)) {
9221 result
= fill_monitor_1(info
, &info
[1].info1
,
9223 if (!W_ERROR_IS_OK(result
)) {
9228 if (!W_ERROR_IS_OK(result
)) {
9239 /****************************************************************************
9240 enumprintmonitors level 2.
9241 ****************************************************************************/
9243 static WERROR
enumprintmonitors_level_2(TALLOC_CTX
*mem_ctx
,
9244 union spoolss_MonitorInfo
**info_p
,
9247 union spoolss_MonitorInfo
*info
;
9248 WERROR result
= WERR_OK
;
9250 info
= talloc_array(mem_ctx
, union spoolss_MonitorInfo
, 2);
9251 W_ERROR_HAVE_NO_MEMORY(info
);
9255 result
= fill_monitor_2(info
, &info
[0].info2
,
9257 "Windows NT X86", /* FIXME */
9259 if (!W_ERROR_IS_OK(result
)) {
9263 result
= fill_monitor_2(info
, &info
[1].info2
,
9265 "Windows NT X86", /* FIXME */
9267 if (!W_ERROR_IS_OK(result
)) {
9272 if (!W_ERROR_IS_OK(result
)) {
9283 /****************************************************************
9284 _spoolss_EnumMonitors
9285 ****************************************************************/
9287 WERROR
_spoolss_EnumMonitors(struct pipes_struct
*p
,
9288 struct spoolss_EnumMonitors
*r
)
9292 /* that's an [in out] buffer */
9294 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
9295 return WERR_INVALID_PARAM
;
9298 DEBUG(5,("_spoolss_EnumMonitors\n"));
9301 * Enumerate the print monitors ...
9303 * Just reply with "Local Port", to keep NT happy
9304 * and I can use my nice printer checker.
9309 *r
->out
.info
= NULL
;
9311 switch (r
->in
.level
) {
9313 result
= enumprintmonitors_level_1(p
->mem_ctx
, r
->out
.info
,
9317 result
= enumprintmonitors_level_2(p
->mem_ctx
, r
->out
.info
,
9321 return WERR_UNKNOWN_LEVEL
;
9324 if (!W_ERROR_IS_OK(result
)) {
9328 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
9329 spoolss_EnumMonitors
,
9330 *r
->out
.info
, r
->in
.level
,
9332 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
9333 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
9335 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
9338 /****************************************************************************
9339 ****************************************************************************/
9341 static WERROR
getjob_level_1(TALLOC_CTX
*mem_ctx
,
9342 const print_queue_struct
*queue
,
9343 int count
, int snum
,
9344 struct spoolss_PrinterInfo2
*pinfo2
,
9347 struct spoolss_JobInfo1
*r
)
9352 for (i
=0; i
<count
; i
++) {
9353 if (queue
[i
].sysjob
== sysjob
) {
9359 if (found
== false) {
9360 /* NT treats not found as bad param... yet another bad choice */
9361 return WERR_INVALID_PARAM
;
9364 return fill_job_info1(mem_ctx
,
9373 /****************************************************************************
9374 ****************************************************************************/
9376 static WERROR
getjob_level_2(TALLOC_CTX
*mem_ctx
,
9377 const print_queue_struct
*queue
,
9378 int count
, int snum
,
9379 struct spoolss_PrinterInfo2
*pinfo2
,
9382 struct spoolss_JobInfo2
*r
)
9386 struct spoolss_DeviceMode
*devmode
;
9389 for (i
=0; i
<count
; i
++) {
9390 if (queue
[i
].sysjob
== sysjob
) {
9396 if (found
== false) {
9397 /* NT treats not found as bad param... yet another bad
9399 return WERR_INVALID_PARAM
;
9403 * if the print job does not have a DEVMODE associated with it,
9404 * just use the one for the printer. A NULL devicemode is not
9405 * a failure condition
9408 devmode
= print_job_devmode(mem_ctx
, lp_const_servicename(snum
), jobid
);
9410 result
= spoolss_create_default_devmode(mem_ctx
,
9411 pinfo2
->printername
,
9413 if (!W_ERROR_IS_OK(result
)) {
9414 DEBUG(3, ("Can't proceed w/o a devmode!"));
9419 return fill_job_info2(mem_ctx
,
9429 /****************************************************************
9431 ****************************************************************/
9433 WERROR
_spoolss_GetJob(struct pipes_struct
*p
,
9434 struct spoolss_GetJob
*r
)
9436 WERROR result
= WERR_OK
;
9437 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
9438 const char *svc_name
;
9442 struct tdb_print_db
*pdb
;
9443 print_queue_struct
*queue
= NULL
;
9444 print_status_struct prt_status
;
9446 /* that's an [in out] buffer */
9448 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
9449 return WERR_INVALID_PARAM
;
9452 DEBUG(5,("_spoolss_GetJob\n"));
9456 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9460 svc_name
= lp_const_servicename(snum
);
9461 if (svc_name
== NULL
) {
9462 return WERR_INVALID_PARAM
;
9465 result
= winreg_get_printer_internal(p
->mem_ctx
,
9466 get_session_info_system(),
9470 if (!W_ERROR_IS_OK(result
)) {
9474 pdb
= get_print_db_byname(svc_name
);
9476 DEBUG(3, ("failed to get print db for svc %s\n", svc_name
));
9477 TALLOC_FREE(pinfo2
);
9478 return WERR_INVALID_PARAM
;
9481 sysjob
= jobid_to_sysjob_pdb(pdb
, r
->in
.job_id
);
9482 release_print_db(pdb
);
9484 DEBUG(3, ("no sysjob for spoolss jobid %u\n", r
->in
.job_id
));
9485 TALLOC_FREE(pinfo2
);
9486 return WERR_INVALID_PARAM
;
9489 count
= print_queue_status(p
->msg_ctx
, snum
, &queue
, &prt_status
);
9491 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
9492 count
, prt_status
.status
, prt_status
.message
));
9494 switch (r
->in
.level
) {
9496 result
= getjob_level_1(p
->mem_ctx
,
9497 queue
, count
, snum
, pinfo2
,
9498 r
->in
.job_id
, sysjob
,
9499 &r
->out
.info
->info1
);
9502 result
= getjob_level_2(p
->mem_ctx
,
9503 queue
, count
, snum
, pinfo2
,
9504 r
->in
.job_id
, sysjob
,
9505 &r
->out
.info
->info2
);
9508 result
= WERR_UNKNOWN_LEVEL
;
9513 TALLOC_FREE(pinfo2
);
9515 if (!W_ERROR_IS_OK(result
)) {
9516 TALLOC_FREE(r
->out
.info
);
9520 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_JobInfo
, r
->out
.info
,
9522 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
9524 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
9527 /****************************************************************
9528 _spoolss_GetPrinterDataEx
9529 ****************************************************************/
9531 WERROR
_spoolss_GetPrinterDataEx(struct pipes_struct
*p
,
9532 struct spoolss_GetPrinterDataEx
*r
)
9535 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9536 const char *printer
;
9538 WERROR result
= WERR_OK
;
9540 enum winreg_Type val_type
= REG_NONE
;
9541 uint8_t *val_data
= NULL
;
9542 uint32_t val_size
= 0;
9543 struct dcerpc_binding_handle
*b
;
9544 TALLOC_CTX
*tmp_ctx
;
9546 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
9548 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
9549 r
->in
.key_name
, r
->in
.value_name
));
9551 /* in case of problem, return some default values */
9554 *r
->out
.type
= REG_NONE
;
9556 tmp_ctx
= talloc_new(p
->mem_ctx
);
9562 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9563 OUR_HANDLE(r
->in
.handle
)));
9564 result
= WERR_BADFID
;
9568 /* check to see if the keyname is valid */
9569 if (!strlen(r
->in
.key_name
)) {
9570 result
= WERR_INVALID_PARAM
;
9574 /* Is the handle to a printer or to the server? */
9576 if (Printer
->printer_type
== SPLHND_SERVER
) {
9578 union spoolss_PrinterData data
;
9580 result
= getprinterdata_printer_server(tmp_ctx
,
9584 if (!W_ERROR_IS_OK(result
)) {
9588 result
= push_spoolss_PrinterData(tmp_ctx
, &blob
,
9589 *r
->out
.type
, &data
);
9590 if (!W_ERROR_IS_OK(result
)) {
9594 *r
->out
.needed
= blob
.length
;
9596 if (r
->in
.offered
>= *r
->out
.needed
) {
9597 memcpy(r
->out
.data
, blob
.data
, blob
.length
);
9604 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9605 result
= WERR_BADFID
;
9608 printer
= lp_const_servicename(snum
);
9610 result
= winreg_printer_binding_handle(tmp_ctx
,
9611 get_session_info_system(),
9614 if (!W_ERROR_IS_OK(result
)) {
9618 /* XP sends this and wants the ChangeID value from PRINTER_INFO_0 */
9619 if (strequal(r
->in
.key_name
, SPOOL_PRINTERDATA_KEY
) &&
9620 strequal(r
->in
.value_name
, "ChangeId")) {
9621 *r
->out
.type
= REG_DWORD
;
9623 if (r
->in
.offered
>= *r
->out
.needed
) {
9624 uint32_t changeid
= 0;
9626 result
= winreg_printer_get_changeid(tmp_ctx
, b
,
9629 if (!W_ERROR_IS_OK(result
)) {
9633 SIVAL(r
->out
.data
, 0, changeid
);
9639 result
= winreg_get_printer_dataex(tmp_ctx
, b
,
9646 if (!W_ERROR_IS_OK(result
)) {
9650 *r
->out
.needed
= val_size
;
9651 *r
->out
.type
= val_type
;
9653 if (r
->in
.offered
>= *r
->out
.needed
) {
9654 memcpy(r
->out
.data
, val_data
, val_size
);
9658 /* NOTE: do not replace type when returning WERR_MORE_DATA */
9660 if (W_ERROR_IS_OK(result
)) {
9661 result
= SPOOLSS_BUFFER_OK(WERR_OK
, WERR_MORE_DATA
);
9664 talloc_free(tmp_ctx
);
9668 /****************************************************************
9669 _spoolss_SetPrinterDataEx
9670 ****************************************************************/
9672 WERROR
_spoolss_SetPrinterDataEx(struct pipes_struct
*p
,
9673 struct spoolss_SetPrinterDataEx
*r
)
9675 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
9677 WERROR result
= WERR_OK
;
9678 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9680 struct dcerpc_binding_handle
*b
;
9681 TALLOC_CTX
*tmp_ctx
;
9683 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
9685 /* From MSDN documentation of SetPrinterDataEx: pass request to
9686 SetPrinterData if key is "PrinterDriverData" */
9689 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9690 OUR_HANDLE(r
->in
.handle
)));
9694 if (Printer
->printer_type
== SPLHND_SERVER
) {
9695 DEBUG(10,("_spoolss_SetPrinterDataEx: "
9696 "Not implemented for server handles yet\n"));
9697 return WERR_INVALID_PARAM
;
9700 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9705 * Access check : NT returns "access denied" if you make a
9706 * SetPrinterData call without the necessary privildge.
9707 * we were originally returning OK if nothing changed
9708 * which made Win2k issue **a lot** of SetPrinterData
9709 * when connecting to a printer --jerry
9712 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
9713 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
9714 "change denied by handle access permissions\n"));
9715 return WERR_ACCESS_DENIED
;
9718 tmp_ctx
= talloc_new(p
->mem_ctx
);
9723 result
= winreg_printer_binding_handle(tmp_ctx
,
9724 get_session_info_system(),
9727 if (!W_ERROR_IS_OK(result
)) {
9731 result
= winreg_get_printer(tmp_ctx
, b
,
9732 lp_servicename(talloc_tos(), snum
),
9734 if (!W_ERROR_IS_OK(result
)) {
9738 /* check for OID in valuename */
9740 oid_string
= strchr(r
->in
.value_name
, ',');
9746 /* save the registry data */
9748 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
9756 if (W_ERROR_IS_OK(result
)) {
9757 /* save the OID if one was specified */
9759 char *str
= talloc_asprintf(tmp_ctx
, "%s\\%s",
9760 r
->in
.key_name
, SPOOL_OID_KEY
);
9762 result
= WERR_NOMEM
;
9767 * I'm not checking the status here on purpose. Don't know
9768 * if this is right, but I'm returning the status from the
9769 * previous set_printer_dataex() call. I have no idea if
9770 * this is right. --jerry
9772 winreg_set_printer_dataex(tmp_ctx
, b
,
9777 (uint8_t *) oid_string
,
9778 strlen(oid_string
) + 1);
9781 result
= winreg_printer_update_changeid(tmp_ctx
, b
,
9782 lp_const_servicename(snum
));
9787 talloc_free(tmp_ctx
);
9791 /****************************************************************
9792 _spoolss_DeletePrinterDataEx
9793 ****************************************************************/
9795 WERROR
_spoolss_DeletePrinterDataEx(struct pipes_struct
*p
,
9796 struct spoolss_DeletePrinterDataEx
*r
)
9798 const char *printer
;
9800 WERROR status
= WERR_OK
;
9801 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9803 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
9806 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
9807 "Invalid handle (%s:%u:%u).\n",
9808 OUR_HANDLE(r
->in
.handle
)));
9812 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
9813 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
9814 "printer properties change denied by handle\n"));
9815 return WERR_ACCESS_DENIED
;
9818 if (!r
->in
.value_name
|| !r
->in
.key_name
) {
9822 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9825 printer
= lp_const_servicename(snum
);
9827 status
= winreg_delete_printer_dataex_internal(p
->mem_ctx
,
9828 get_session_info_system(),
9833 if (W_ERROR_IS_OK(status
)) {
9834 status
= winreg_printer_update_changeid_internal(p
->mem_ctx
,
9835 get_session_info_system(),
9843 /****************************************************************
9844 _spoolss_EnumPrinterKey
9845 ****************************************************************/
9847 WERROR
_spoolss_EnumPrinterKey(struct pipes_struct
*p
,
9848 struct spoolss_EnumPrinterKey
*r
)
9851 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9853 WERROR result
= WERR_BADFILE
;
9854 const char **array
= NULL
;
9857 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
9860 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
9861 OUR_HANDLE(r
->in
.handle
)));
9865 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9869 result
= winreg_enum_printer_key_internal(p
->mem_ctx
,
9870 get_session_info_system(),
9872 lp_const_servicename(snum
),
9876 if (!W_ERROR_IS_OK(result
)) {
9880 if (!push_reg_multi_sz(p
->mem_ctx
, &blob
, array
)) {
9881 result
= WERR_NOMEM
;
9885 *r
->out
._ndr_size
= r
->in
.offered
/ 2;
9886 *r
->out
.needed
= blob
.length
;
9888 if (r
->in
.offered
< *r
->out
.needed
) {
9889 result
= WERR_MORE_DATA
;
9892 r
->out
.key_buffer
->string_array
= array
;
9896 if (!W_ERROR_IS_OK(result
)) {
9898 if (!W_ERROR_EQUAL(result
, WERR_MORE_DATA
)) {
9906 /****************************************************************
9907 _spoolss_DeletePrinterKey
9908 ****************************************************************/
9910 WERROR
_spoolss_DeletePrinterKey(struct pipes_struct
*p
,
9911 struct spoolss_DeletePrinterKey
*r
)
9913 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9916 const char *printer
;
9917 struct dcerpc_binding_handle
*b
;
9918 TALLOC_CTX
*tmp_ctx
;
9920 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
9923 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
9924 OUR_HANDLE(r
->in
.handle
)));
9928 /* if keyname == NULL, return error */
9929 if ( !r
->in
.key_name
)
9930 return WERR_INVALID_PARAM
;
9932 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9936 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
9937 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9938 "printer properties change denied by handle\n"));
9939 return WERR_ACCESS_DENIED
;
9942 printer
= lp_const_servicename(snum
);
9944 tmp_ctx
= talloc_new(p
->mem_ctx
);
9949 status
= winreg_printer_binding_handle(tmp_ctx
,
9950 get_session_info_system(),
9953 if (!W_ERROR_IS_OK(status
)) {
9957 /* delete the key and all subkeys */
9958 status
= winreg_delete_printer_key(tmp_ctx
, b
,
9961 if (W_ERROR_IS_OK(status
)) {
9962 status
= winreg_printer_update_changeid(tmp_ctx
, b
,
9967 talloc_free(tmp_ctx
);
9971 /****************************************************************
9972 _spoolss_EnumPrinterDataEx
9973 ****************************************************************/
9975 WERROR
_spoolss_EnumPrinterDataEx(struct pipes_struct
*p
,
9976 struct spoolss_EnumPrinterDataEx
*r
)
9979 struct spoolss_PrinterEnumValues
*info
= NULL
;
9980 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9984 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
9988 *r
->out
.info
= NULL
;
9991 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
9992 OUR_HANDLE(r
->in
.handle
)));
9997 * first check for a keyname of NULL or "". Win2k seems to send
9998 * this a lot and we should send back WERR_INVALID_PARAM
9999 * no need to spend time looking up the printer in this case.
10003 if (!strlen(r
->in
.key_name
)) {
10004 result
= WERR_INVALID_PARAM
;
10008 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
10009 return WERR_BADFID
;
10012 /* now look for a match on the key name */
10013 result
= winreg_enum_printer_dataex_internal(p
->mem_ctx
,
10014 get_session_info_system(),
10016 lp_const_servicename(snum
),
10020 if (!W_ERROR_IS_OK(result
)) {
10024 #if 0 /* FIXME - gd */
10025 /* housekeeping information in the reply */
10027 /* Fix from Martin Zielinski <mz@seh.de> - ensure
10028 * the hand marshalled container size is a multiple
10029 * of 4 bytes for RPC alignment.
10033 needed
+= 4-(needed
% 4);
10036 *r
->out
.count
= count
;
10037 *r
->out
.info
= info
;
10040 if (!W_ERROR_IS_OK(result
)) {
10044 *r
->out
.needed
= SPOOLSS_BUFFER_ARRAY(p
->mem_ctx
,
10045 spoolss_EnumPrinterDataEx
,
10048 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
10049 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, *r
->out
.count
);
10051 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_MORE_DATA
);
10054 /****************************************************************************
10055 ****************************************************************************/
10057 static WERROR
getprintprocessordirectory_level_1(TALLOC_CTX
*mem_ctx
,
10058 const char *servername
,
10059 const char *environment
,
10060 struct spoolss_PrintProcessorDirectoryInfo1
*r
)
10065 werr
= compose_spoolss_server_path(mem_ctx
,
10068 SPOOLSS_PRTPROCS_PATH
,
10070 if (!W_ERROR_IS_OK(werr
)) {
10074 DEBUG(4,("print processor directory: [%s]\n", path
));
10076 r
->directory_name
= path
;
10081 /****************************************************************
10082 _spoolss_GetPrintProcessorDirectory
10083 ****************************************************************/
10085 WERROR
_spoolss_GetPrintProcessorDirectory(struct pipes_struct
*p
,
10086 struct spoolss_GetPrintProcessorDirectory
*r
)
10089 char *prnproc_share
= NULL
;
10090 bool prnproc_share_exists
= false;
10093 /* that's an [in out] buffer */
10095 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
10096 return WERR_INVALID_PARAM
;
10099 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
10102 *r
->out
.needed
= 0;
10104 /* r->in.level is ignored */
10106 /* We always should reply with a local print processor directory so that
10107 * users are not forced to have a [prnproc$] share on the Samba spoolss
10108 * server, if users decide to do so, lets announce it though - Guenther */
10110 snum
= find_service(talloc_tos(), "prnproc$", &prnproc_share
);
10111 if (!prnproc_share
) {
10115 prnproc_share_exists
= true;
10118 result
= getprintprocessordirectory_level_1(p
->mem_ctx
,
10119 prnproc_share_exists
? r
->in
.server
: NULL
,
10121 &r
->out
.info
->info1
);
10122 if (!W_ERROR_IS_OK(result
)) {
10123 TALLOC_FREE(r
->out
.info
);
10127 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo
,
10128 r
->out
.info
, r
->in
.level
);
10129 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
10131 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
10134 /*******************************************************************
10135 ********************************************************************/
10137 static bool push_monitorui_buf(TALLOC_CTX
*mem_ctx
, DATA_BLOB
*buf
,
10138 const char *dllname
)
10140 enum ndr_err_code ndr_err
;
10141 struct spoolss_MonitorUi ui
;
10143 ui
.dll_name
= dllname
;
10145 ndr_err
= ndr_push_struct_blob(buf
, mem_ctx
, &ui
,
10146 (ndr_push_flags_fn_t
)ndr_push_spoolss_MonitorUi
);
10147 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err
) && (DEBUGLEVEL
>= 10)) {
10148 NDR_PRINT_DEBUG(spoolss_MonitorUi
, &ui
);
10150 return NDR_ERR_CODE_IS_SUCCESS(ndr_err
);
10153 /*******************************************************************
10154 Streams the monitor UI DLL name in UNICODE
10155 *******************************************************************/
10157 static WERROR
xcvtcp_monitorui(TALLOC_CTX
*mem_ctx
,
10158 struct security_token
*token
, DATA_BLOB
*in
,
10159 DATA_BLOB
*out
, uint32_t *needed
)
10161 const char *dllname
= "tcpmonui.dll";
10163 *needed
= (strlen(dllname
)+1) * 2;
10165 if (out
->length
< *needed
) {
10166 return WERR_INSUFFICIENT_BUFFER
;
10169 if (!push_monitorui_buf(mem_ctx
, out
, dllname
)) {
10176 /*******************************************************************
10177 ********************************************************************/
10179 static bool pull_port_data_1(TALLOC_CTX
*mem_ctx
,
10180 struct spoolss_PortData1
*port1
,
10181 const DATA_BLOB
*buf
)
10183 enum ndr_err_code ndr_err
;
10184 ndr_err
= ndr_pull_struct_blob(buf
, mem_ctx
, port1
,
10185 (ndr_pull_flags_fn_t
)ndr_pull_spoolss_PortData1
);
10186 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err
) && (DEBUGLEVEL
>= 10)) {
10187 NDR_PRINT_DEBUG(spoolss_PortData1
, port1
);
10189 return NDR_ERR_CODE_IS_SUCCESS(ndr_err
);
10192 /*******************************************************************
10193 ********************************************************************/
10195 static bool pull_port_data_2(TALLOC_CTX
*mem_ctx
,
10196 struct spoolss_PortData2
*port2
,
10197 const DATA_BLOB
*buf
)
10199 enum ndr_err_code ndr_err
;
10200 ndr_err
= ndr_pull_struct_blob(buf
, mem_ctx
, port2
,
10201 (ndr_pull_flags_fn_t
)ndr_pull_spoolss_PortData2
);
10202 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err
) && (DEBUGLEVEL
>= 10)) {
10203 NDR_PRINT_DEBUG(spoolss_PortData2
, port2
);
10205 return NDR_ERR_CODE_IS_SUCCESS(ndr_err
);
10208 /*******************************************************************
10209 Create a new TCP/IP port
10210 *******************************************************************/
10212 static WERROR
xcvtcp_addport(TALLOC_CTX
*mem_ctx
,
10213 struct security_token
*token
, DATA_BLOB
*in
,
10214 DATA_BLOB
*out
, uint32_t *needed
)
10216 struct spoolss_PortData1 port1
;
10217 struct spoolss_PortData2 port2
;
10218 char *device_uri
= NULL
;
10221 const char *portname
;
10222 const char *hostaddress
;
10224 uint32_t port_number
;
10227 /* peek for spoolss_PortData version */
10229 if (!in
|| (in
->length
< (128 + 4))) {
10230 return WERR_GENERAL_FAILURE
;
10233 version
= IVAL(in
->data
, 128);
10237 ZERO_STRUCT(port1
);
10239 if (!pull_port_data_1(mem_ctx
, &port1
, in
)) {
10243 portname
= port1
.portname
;
10244 hostaddress
= port1
.hostaddress
;
10245 queue
= port1
.queue
;
10246 protocol
= port1
.protocol
;
10247 port_number
= port1
.port_number
;
10251 ZERO_STRUCT(port2
);
10253 if (!pull_port_data_2(mem_ctx
, &port2
, in
)) {
10257 portname
= port2
.portname
;
10258 hostaddress
= port2
.hostaddress
;
10259 queue
= port2
.queue
;
10260 protocol
= port2
.protocol
;
10261 port_number
= port2
.port_number
;
10265 DEBUG(1,("xcvtcp_addport: "
10266 "unknown version of port_data: %d\n", version
));
10267 return WERR_UNKNOWN_PORT
;
10270 /* create the device URI and call the add_port_hook() */
10272 switch (protocol
) {
10273 case PROTOCOL_RAWTCP_TYPE
:
10274 device_uri
= talloc_asprintf(mem_ctx
,
10275 "socket://%s:%d/", hostaddress
,
10279 case PROTOCOL_LPR_TYPE
:
10280 device_uri
= talloc_asprintf(mem_ctx
,
10281 "lpr://%s/%s", hostaddress
, queue
);
10285 return WERR_UNKNOWN_PORT
;
10292 return add_port_hook(mem_ctx
, token
, portname
, device_uri
);
10295 /*******************************************************************
10296 *******************************************************************/
10298 struct xcv_api_table xcvtcp_cmds
[] = {
10299 { "MonitorUI", xcvtcp_monitorui
},
10300 { "AddPort", xcvtcp_addport
},
10304 static WERROR
process_xcvtcp_command(TALLOC_CTX
*mem_ctx
,
10305 struct security_token
*token
, const char *command
,
10312 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command
));
10314 for ( i
=0; xcvtcp_cmds
[i
].name
; i
++ ) {
10315 if ( strcmp( command
, xcvtcp_cmds
[i
].name
) == 0 )
10316 return xcvtcp_cmds
[i
].fn(mem_ctx
, token
, inbuf
, outbuf
, needed
);
10319 return WERR_BADFUNC
;
10322 /*******************************************************************
10323 *******************************************************************/
10324 #if 0 /* don't support management using the "Local Port" monitor */
10326 static WERROR
xcvlocal_monitorui(TALLOC_CTX
*mem_ctx
,
10327 struct security_token
*token
, DATA_BLOB
*in
,
10328 DATA_BLOB
*out
, uint32_t *needed
)
10330 const char *dllname
= "localui.dll";
10332 *needed
= (strlen(dllname
)+1) * 2;
10334 if (out
->length
< *needed
) {
10335 return WERR_INSUFFICIENT_BUFFER
;
10338 if (!push_monitorui_buf(mem_ctx
, out
, dllname
)) {
10345 /*******************************************************************
10346 *******************************************************************/
10348 struct xcv_api_table xcvlocal_cmds
[] = {
10349 { "MonitorUI", xcvlocal_monitorui
},
10353 struct xcv_api_table xcvlocal_cmds
[] = {
10360 /*******************************************************************
10361 *******************************************************************/
10363 static WERROR
process_xcvlocal_command(TALLOC_CTX
*mem_ctx
,
10364 struct security_token
*token
, const char *command
,
10365 DATA_BLOB
*inbuf
, DATA_BLOB
*outbuf
,
10370 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command
));
10372 for ( i
=0; xcvlocal_cmds
[i
].name
; i
++ ) {
10373 if ( strcmp( command
, xcvlocal_cmds
[i
].name
) == 0 )
10374 return xcvlocal_cmds
[i
].fn(mem_ctx
, token
, inbuf
, outbuf
, needed
);
10376 return WERR_BADFUNC
;
10379 /****************************************************************
10381 ****************************************************************/
10383 WERROR
_spoolss_XcvData(struct pipes_struct
*p
,
10384 struct spoolss_XcvData
*r
)
10386 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
10387 DATA_BLOB out_data
= data_blob_null
;
10391 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
10392 OUR_HANDLE(r
->in
.handle
)));
10393 return WERR_BADFID
;
10396 /* Has to be a handle to the TCP/IP port monitor */
10398 if ( !(Printer
->printer_type
& (SPLHND_PORTMON_LOCAL
|SPLHND_PORTMON_TCP
)) ) {
10399 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
10400 return WERR_BADFID
;
10403 /* requires administrative access to the server */
10405 if ( !(Printer
->access_granted
& SERVER_ACCESS_ADMINISTER
) ) {
10406 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
10407 return WERR_ACCESS_DENIED
;
10410 /* Allocate the outgoing buffer */
10412 if (r
->in
.out_data_size
) {
10413 out_data
= data_blob_talloc_zero(p
->mem_ctx
, r
->in
.out_data_size
);
10414 if (out_data
.data
== NULL
) {
10419 switch ( Printer
->printer_type
) {
10420 case SPLHND_PORTMON_TCP
:
10421 werror
= process_xcvtcp_command(p
->mem_ctx
,
10422 p
->session_info
->security_token
,
10423 r
->in
.function_name
,
10424 &r
->in
.in_data
, &out_data
,
10427 case SPLHND_PORTMON_LOCAL
:
10428 werror
= process_xcvlocal_command(p
->mem_ctx
,
10429 p
->session_info
->security_token
,
10430 r
->in
.function_name
,
10431 &r
->in
.in_data
, &out_data
,
10435 werror
= WERR_INVALID_PRINT_MONITOR
;
10438 if (!W_ERROR_IS_OK(werror
)) {
10442 *r
->out
.status_code
= 0;
10444 if (r
->out
.out_data
&& out_data
.data
&& r
->in
.out_data_size
&& out_data
.length
) {
10445 memcpy(r
->out
.out_data
, out_data
.data
,
10446 MIN(r
->in
.out_data_size
, out_data
.length
));
10452 /****************************************************************
10453 _spoolss_AddPrintProcessor
10454 ****************************************************************/
10456 WERROR
_spoolss_AddPrintProcessor(struct pipes_struct
*p
,
10457 struct spoolss_AddPrintProcessor
*r
)
10459 /* for now, just indicate success and ignore the add. We'll
10460 automatically set the winprint processor for printer
10461 entries later. Used to debug the LexMark Optra S 1855 PCL
10467 /****************************************************************
10469 ****************************************************************/
10471 WERROR
_spoolss_AddPort(struct pipes_struct
*p
,
10472 struct spoolss_AddPort
*r
)
10474 /* do what w2k3 does */
10476 return WERR_NOT_SUPPORTED
;
10479 /****************************************************************
10480 _spoolss_GetPrinterDriver
10481 ****************************************************************/
10483 WERROR
_spoolss_GetPrinterDriver(struct pipes_struct
*p
,
10484 struct spoolss_GetPrinterDriver
*r
)
10486 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10487 return WERR_NOT_SUPPORTED
;
10490 /****************************************************************
10491 _spoolss_ReadPrinter
10492 ****************************************************************/
10494 WERROR
_spoolss_ReadPrinter(struct pipes_struct
*p
,
10495 struct spoolss_ReadPrinter
*r
)
10497 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10498 return WERR_NOT_SUPPORTED
;
10501 /****************************************************************
10502 _spoolss_WaitForPrinterChange
10503 ****************************************************************/
10505 WERROR
_spoolss_WaitForPrinterChange(struct pipes_struct
*p
,
10506 struct spoolss_WaitForPrinterChange
*r
)
10508 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10509 return WERR_NOT_SUPPORTED
;
10512 /****************************************************************
10513 _spoolss_ConfigurePort
10514 ****************************************************************/
10516 WERROR
_spoolss_ConfigurePort(struct pipes_struct
*p
,
10517 struct spoolss_ConfigurePort
*r
)
10519 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10520 return WERR_NOT_SUPPORTED
;
10523 /****************************************************************
10524 _spoolss_DeletePort
10525 ****************************************************************/
10527 WERROR
_spoolss_DeletePort(struct pipes_struct
*p
,
10528 struct spoolss_DeletePort
*r
)
10530 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10531 return WERR_NOT_SUPPORTED
;
10534 /****************************************************************
10535 _spoolss_CreatePrinterIC
10536 ****************************************************************/
10538 WERROR
_spoolss_CreatePrinterIC(struct pipes_struct
*p
,
10539 struct spoolss_CreatePrinterIC
*r
)
10541 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10542 return WERR_NOT_SUPPORTED
;
10545 /****************************************************************
10546 _spoolss_PlayGDIScriptOnPrinterIC
10547 ****************************************************************/
10549 WERROR
_spoolss_PlayGDIScriptOnPrinterIC(struct pipes_struct
*p
,
10550 struct spoolss_PlayGDIScriptOnPrinterIC
*r
)
10552 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10553 return WERR_NOT_SUPPORTED
;
10556 /****************************************************************
10557 _spoolss_DeletePrinterIC
10558 ****************************************************************/
10560 WERROR
_spoolss_DeletePrinterIC(struct pipes_struct
*p
,
10561 struct spoolss_DeletePrinterIC
*r
)
10563 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10564 return WERR_NOT_SUPPORTED
;
10567 /****************************************************************
10568 _spoolss_AddPrinterConnection
10569 ****************************************************************/
10571 WERROR
_spoolss_AddPrinterConnection(struct pipes_struct
*p
,
10572 struct spoolss_AddPrinterConnection
*r
)
10574 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10575 return WERR_NOT_SUPPORTED
;
10578 /****************************************************************
10579 _spoolss_DeletePrinterConnection
10580 ****************************************************************/
10582 WERROR
_spoolss_DeletePrinterConnection(struct pipes_struct
*p
,
10583 struct spoolss_DeletePrinterConnection
*r
)
10585 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10586 return WERR_NOT_SUPPORTED
;
10589 /****************************************************************
10590 _spoolss_PrinterMessageBox
10591 ****************************************************************/
10593 WERROR
_spoolss_PrinterMessageBox(struct pipes_struct
*p
,
10594 struct spoolss_PrinterMessageBox
*r
)
10596 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10597 return WERR_NOT_SUPPORTED
;
10600 /****************************************************************
10601 _spoolss_AddMonitor
10602 ****************************************************************/
10604 WERROR
_spoolss_AddMonitor(struct pipes_struct
*p
,
10605 struct spoolss_AddMonitor
*r
)
10607 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10608 return WERR_NOT_SUPPORTED
;
10611 /****************************************************************
10612 _spoolss_DeleteMonitor
10613 ****************************************************************/
10615 WERROR
_spoolss_DeleteMonitor(struct pipes_struct
*p
,
10616 struct spoolss_DeleteMonitor
*r
)
10618 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10619 return WERR_NOT_SUPPORTED
;
10622 /****************************************************************
10623 _spoolss_DeletePrintProcessor
10624 ****************************************************************/
10626 WERROR
_spoolss_DeletePrintProcessor(struct pipes_struct
*p
,
10627 struct spoolss_DeletePrintProcessor
*r
)
10629 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10630 return WERR_NOT_SUPPORTED
;
10633 /****************************************************************
10634 _spoolss_AddPrintProvidor
10635 ****************************************************************/
10637 WERROR
_spoolss_AddPrintProvidor(struct pipes_struct
*p
,
10638 struct spoolss_AddPrintProvidor
*r
)
10640 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10641 return WERR_NOT_SUPPORTED
;
10644 /****************************************************************
10645 _spoolss_DeletePrintProvidor
10646 ****************************************************************/
10648 WERROR
_spoolss_DeletePrintProvidor(struct pipes_struct
*p
,
10649 struct spoolss_DeletePrintProvidor
*r
)
10651 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10652 return WERR_NOT_SUPPORTED
;
10655 /****************************************************************
10656 _spoolss_FindFirstPrinterChangeNotification
10657 ****************************************************************/
10659 WERROR
_spoolss_FindFirstPrinterChangeNotification(struct pipes_struct
*p
,
10660 struct spoolss_FindFirstPrinterChangeNotification
*r
)
10662 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10663 return WERR_NOT_SUPPORTED
;
10666 /****************************************************************
10667 _spoolss_FindNextPrinterChangeNotification
10668 ****************************************************************/
10670 WERROR
_spoolss_FindNextPrinterChangeNotification(struct pipes_struct
*p
,
10671 struct spoolss_FindNextPrinterChangeNotification
*r
)
10673 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10674 return WERR_NOT_SUPPORTED
;
10677 /****************************************************************
10678 _spoolss_RouterFindFirstPrinterChangeNotificationOld
10679 ****************************************************************/
10681 WERROR
_spoolss_RouterFindFirstPrinterChangeNotificationOld(struct pipes_struct
*p
,
10682 struct spoolss_RouterFindFirstPrinterChangeNotificationOld
*r
)
10684 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10685 return WERR_NOT_SUPPORTED
;
10688 /****************************************************************
10689 _spoolss_ReplyOpenPrinter
10690 ****************************************************************/
10692 WERROR
_spoolss_ReplyOpenPrinter(struct pipes_struct
*p
,
10693 struct spoolss_ReplyOpenPrinter
*r
)
10695 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10696 return WERR_NOT_SUPPORTED
;
10699 /****************************************************************
10700 _spoolss_RouterReplyPrinter
10701 ****************************************************************/
10703 WERROR
_spoolss_RouterReplyPrinter(struct pipes_struct
*p
,
10704 struct spoolss_RouterReplyPrinter
*r
)
10706 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10707 return WERR_NOT_SUPPORTED
;
10710 /****************************************************************
10711 _spoolss_ReplyClosePrinter
10712 ****************************************************************/
10714 WERROR
_spoolss_ReplyClosePrinter(struct pipes_struct
*p
,
10715 struct spoolss_ReplyClosePrinter
*r
)
10717 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10718 return WERR_NOT_SUPPORTED
;
10721 /****************************************************************
10723 ****************************************************************/
10725 WERROR
_spoolss_AddPortEx(struct pipes_struct
*p
,
10726 struct spoolss_AddPortEx
*r
)
10728 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10729 return WERR_NOT_SUPPORTED
;
10732 /****************************************************************
10733 _spoolss_RouterFindFirstPrinterChangeNotification
10734 ****************************************************************/
10736 WERROR
_spoolss_RouterFindFirstPrinterChangeNotification(struct pipes_struct
*p
,
10737 struct spoolss_RouterFindFirstPrinterChangeNotification
*r
)
10739 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10740 return WERR_NOT_SUPPORTED
;
10743 /****************************************************************
10744 _spoolss_SpoolerInit
10745 ****************************************************************/
10747 WERROR
_spoolss_SpoolerInit(struct pipes_struct
*p
,
10748 struct spoolss_SpoolerInit
*r
)
10750 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10751 return WERR_NOT_SUPPORTED
;
10754 /****************************************************************
10755 _spoolss_ResetPrinterEx
10756 ****************************************************************/
10758 WERROR
_spoolss_ResetPrinterEx(struct pipes_struct
*p
,
10759 struct spoolss_ResetPrinterEx
*r
)
10761 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10762 return WERR_NOT_SUPPORTED
;
10765 /****************************************************************
10766 _spoolss_RouterReplyPrinterEx
10767 ****************************************************************/
10769 WERROR
_spoolss_RouterReplyPrinterEx(struct pipes_struct
*p
,
10770 struct spoolss_RouterReplyPrinterEx
*r
)
10772 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10773 return WERR_NOT_SUPPORTED
;
10776 /****************************************************************
10778 ****************************************************************/
10780 WERROR
_spoolss_44(struct pipes_struct
*p
,
10781 struct spoolss_44
*r
)
10783 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10784 return WERR_NOT_SUPPORTED
;
10787 /****************************************************************
10789 ****************************************************************/
10791 WERROR
_spoolss_SetPort(struct pipes_struct
*p
,
10792 struct spoolss_SetPort
*r
)
10794 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10795 return WERR_NOT_SUPPORTED
;
10798 /****************************************************************
10800 ****************************************************************/
10802 WERROR
_spoolss_4a(struct pipes_struct
*p
,
10803 struct spoolss_4a
*r
)
10805 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10806 return WERR_NOT_SUPPORTED
;
10809 /****************************************************************
10811 ****************************************************************/
10813 WERROR
_spoolss_4b(struct pipes_struct
*p
,
10814 struct spoolss_4b
*r
)
10816 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10817 return WERR_NOT_SUPPORTED
;
10820 /****************************************************************
10822 ****************************************************************/
10824 WERROR
_spoolss_4c(struct pipes_struct
*p
,
10825 struct spoolss_4c
*r
)
10827 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10828 return WERR_NOT_SUPPORTED
;
10831 /****************************************************************
10833 ****************************************************************/
10835 WERROR
_spoolss_53(struct pipes_struct
*p
,
10836 struct spoolss_53
*r
)
10838 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10839 return WERR_NOT_SUPPORTED
;
10842 /****************************************************************
10843 _spoolss_AddPerMachineConnection
10844 ****************************************************************/
10846 WERROR
_spoolss_AddPerMachineConnection(struct pipes_struct
*p
,
10847 struct spoolss_AddPerMachineConnection
*r
)
10849 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10850 return WERR_NOT_SUPPORTED
;
10853 /****************************************************************
10854 _spoolss_DeletePerMachineConnection
10855 ****************************************************************/
10857 WERROR
_spoolss_DeletePerMachineConnection(struct pipes_struct
*p
,
10858 struct spoolss_DeletePerMachineConnection
*r
)
10860 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10861 return WERR_NOT_SUPPORTED
;
10864 /****************************************************************
10865 _spoolss_EnumPerMachineConnections
10866 ****************************************************************/
10868 WERROR
_spoolss_EnumPerMachineConnections(struct pipes_struct
*p
,
10869 struct spoolss_EnumPerMachineConnections
*r
)
10871 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10872 return WERR_NOT_SUPPORTED
;
10875 /****************************************************************
10877 ****************************************************************/
10879 WERROR
_spoolss_5a(struct pipes_struct
*p
,
10880 struct spoolss_5a
*r
)
10882 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10883 return WERR_NOT_SUPPORTED
;
10886 /****************************************************************
10888 ****************************************************************/
10890 WERROR
_spoolss_5b(struct pipes_struct
*p
,
10891 struct spoolss_5b
*r
)
10893 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10894 return WERR_NOT_SUPPORTED
;
10897 /****************************************************************
10899 ****************************************************************/
10901 WERROR
_spoolss_5c(struct pipes_struct
*p
,
10902 struct spoolss_5c
*r
)
10904 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10905 return WERR_NOT_SUPPORTED
;
10908 /****************************************************************
10910 ****************************************************************/
10912 WERROR
_spoolss_5d(struct pipes_struct
*p
,
10913 struct spoolss_5d
*r
)
10915 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10916 return WERR_NOT_SUPPORTED
;
10919 /****************************************************************
10921 ****************************************************************/
10923 WERROR
_spoolss_5e(struct pipes_struct
*p
,
10924 struct spoolss_5e
*r
)
10926 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10927 return WERR_NOT_SUPPORTED
;
10930 /****************************************************************
10932 ****************************************************************/
10934 WERROR
_spoolss_5f(struct pipes_struct
*p
,
10935 struct spoolss_5f
*r
)
10937 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10938 return WERR_NOT_SUPPORTED
;
10941 /****************************************************************
10943 ****************************************************************/
10945 WERROR
_spoolss_60(struct pipes_struct
*p
,
10946 struct spoolss_60
*r
)
10948 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10949 return WERR_NOT_SUPPORTED
;
10952 /****************************************************************
10954 ****************************************************************/
10956 WERROR
_spoolss_61(struct pipes_struct
*p
,
10957 struct spoolss_61
*r
)
10959 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10960 return WERR_NOT_SUPPORTED
;
10963 /****************************************************************
10965 ****************************************************************/
10967 WERROR
_spoolss_62(struct pipes_struct
*p
,
10968 struct spoolss_62
*r
)
10970 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10971 return WERR_NOT_SUPPORTED
;
10974 /****************************************************************
10976 ****************************************************************/
10978 WERROR
_spoolss_63(struct pipes_struct
*p
,
10979 struct spoolss_63
*r
)
10981 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10982 return WERR_NOT_SUPPORTED
;
10985 /****************************************************************
10987 ****************************************************************/
10989 WERROR
_spoolss_64(struct pipes_struct
*p
,
10990 struct spoolss_64
*r
)
10992 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
10993 return WERR_NOT_SUPPORTED
;
10996 /****************************************************************
10998 ****************************************************************/
11000 WERROR
_spoolss_65(struct pipes_struct
*p
,
11001 struct spoolss_65
*r
)
11003 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11004 return WERR_NOT_SUPPORTED
;
11007 /****************************************************************
11008 _spoolss_GetCorePrinterDrivers
11009 ****************************************************************/
11011 WERROR
_spoolss_GetCorePrinterDrivers(struct pipes_struct
*p
,
11012 struct spoolss_GetCorePrinterDrivers
*r
)
11014 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11015 return WERR_NOT_SUPPORTED
;
11018 /****************************************************************
11020 ****************************************************************/
11022 WERROR
_spoolss_67(struct pipes_struct
*p
,
11023 struct spoolss_67
*r
)
11025 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11026 return WERR_NOT_SUPPORTED
;
11029 /****************************************************************
11030 _spoolss_GetPrinterDriverPackagePath
11031 ****************************************************************/
11033 WERROR
_spoolss_GetPrinterDriverPackagePath(struct pipes_struct
*p
,
11034 struct spoolss_GetPrinterDriverPackagePath
*r
)
11036 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11037 return WERR_NOT_SUPPORTED
;
11040 /****************************************************************
11042 ****************************************************************/
11044 WERROR
_spoolss_69(struct pipes_struct
*p
,
11045 struct spoolss_69
*r
)
11047 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11048 return WERR_NOT_SUPPORTED
;
11051 /****************************************************************
11053 ****************************************************************/
11055 WERROR
_spoolss_6a(struct pipes_struct
*p
,
11056 struct spoolss_6a
*r
)
11058 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11059 return WERR_NOT_SUPPORTED
;
11062 /****************************************************************
11064 ****************************************************************/
11066 WERROR
_spoolss_6b(struct pipes_struct
*p
,
11067 struct spoolss_6b
*r
)
11069 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11070 return WERR_NOT_SUPPORTED
;
11073 /****************************************************************
11075 ****************************************************************/
11077 WERROR
_spoolss_6c(struct pipes_struct
*p
,
11078 struct spoolss_6c
*r
)
11080 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11081 return WERR_NOT_SUPPORTED
;
11084 /****************************************************************
11086 ****************************************************************/
11088 WERROR
_spoolss_6d(struct pipes_struct
*p
,
11089 struct spoolss_6d
*r
)
11091 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
11092 return WERR_NOT_SUPPORTED
;