2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-2000,
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
6 * Copyright (C) Jean François Micouleau 1998-2000,
7 * Copyright (C) Jeremy Allison 2001-2002,
8 * Copyright (C) Gerald Carter 2000-2004,
9 * Copyright (C) Tim Potter 2001-2002.
10 * Copyright (C) Guenther Deschner 2009-2010.
11 * Copyright (C) Andreas Schneider 2010.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 /* Since the SPOOLSS rpc routines are basically DOS 16-bit calls wrapped
28 up, all the errors returned are DOS errors, not NT status codes. */
32 #include "nt_printing.h"
33 #include "srv_spoolss_util.h"
34 #include "../librpc/gen_ndr/srv_spoolss.h"
35 #include "../librpc/gen_ndr/ndr_spoolss_c.h"
36 #include "rpc_client/init_spoolss.h"
37 #include "rpc_client/cli_pipe.h"
38 #include "../libcli/security/security.h"
39 #include "librpc/gen_ndr/ndr_security.h"
41 #include "registry/reg_objects.h"
42 #include "include/printing.h"
44 #include "../librpc/gen_ndr/netlogon.h"
46 #include "printing/notify.h"
48 #include "../libcli/registry/util_reg.h"
49 #include "smbd/smbd.h"
50 #include "smbd/globals.h"
53 #include "rpc_server/spoolss/srv_spoolss_nt.h"
55 #include "libsmb/libsmb.h"
56 #include "printing/printer_list.h"
57 #include "../lib/tsocket/tsocket.h"
58 #include "rpc_client/cli_winreg_spoolss.h"
60 /* macros stolen from s4 spoolss server */
61 #define SPOOLSS_BUFFER_UNION(fn,info,level) \
62 ((info)?ndr_size_##fn(info, level, 0):0)
64 #define SPOOLSS_BUFFER_UNION_ARRAY(mem_ctx,fn,info,level,count) \
65 ((info)?ndr_size_##fn##_info(mem_ctx, level, count, info):0)
67 #define SPOOLSS_BUFFER_ARRAY(mem_ctx,fn,info,count) \
68 ((info)?ndr_size_##fn##_info(mem_ctx, count, info):0)
70 #define SPOOLSS_BUFFER_OK(val_true,val_false) ((r->in.offered >= *r->out.needed)?val_true:val_false)
73 #define DBGC_CLASS DBGC_RPC_SRV
75 #ifndef MAX_OPEN_PRINTER_EXS
76 #define MAX_OPEN_PRINTER_EXS 50
79 struct notify_back_channel
;
81 /* structure to store the printer handles */
82 /* and a reference to what it's pointing to */
83 /* and the notify info asked about */
84 /* that's the central struct */
85 struct printer_handle
{
86 struct printer_handle
*prev
, *next
;
87 bool document_started
;
89 uint32 jobid
; /* jobid in printing backend */
91 const char *servername
;
94 uint32 access_granted
;
100 struct spoolss_NotifyOption
*option
;
101 struct policy_handle cli_hnd
;
102 struct notify_back_channel
*cli_chan
;
104 /* are we in a FindNextPrinterChangeNotify() call? */
106 struct messaging_context
*msg_ctx
;
113 /* devmode sent in the OpenPrinter() call */
114 struct spoolss_DeviceMode
*devmode
;
116 /* TODO cache the printer info2 structure */
117 struct spoolss_PrinterInfo2
*info2
;
121 static struct printer_handle
*printers_list
;
123 struct printer_session_counter
{
124 struct printer_session_counter
*next
;
125 struct printer_session_counter
*prev
;
131 static struct printer_session_counter
*counter_list
;
133 struct notify_back_channel
{
134 struct notify_back_channel
*prev
, *next
;
136 /* associated client */
137 struct sockaddr_storage client_address
;
139 /* print notify back-channel pipe handle*/
140 struct rpc_pipe_client
*cli_pipe
;
141 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();
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 **********************************************************************/
1518 void do_drv_upgrade_printer(struct messaging_context
*msg
,
1521 struct server_id server_id
,
1524 TALLOC_CTX
*tmp_ctx
;
1525 const struct auth_session_info
*session_info
= get_session_info_system();
1526 struct spoolss_PrinterInfo2
*pinfo2
;
1528 const char *drivername
;
1530 int n_services
= lp_numservices();
1531 struct dcerpc_binding_handle
*b
= NULL
;
1533 tmp_ctx
= talloc_new(NULL
);
1534 if (!tmp_ctx
) return;
1536 drivername
= talloc_strndup(tmp_ctx
, (const char *)data
->data
, data
->length
);
1538 DEBUG(0, ("do_drv_upgrade_printer: Out of memoery ?!\n"));
1542 DEBUG(10, ("do_drv_upgrade_printer: "
1543 "Got message for new driver [%s]\n", drivername
));
1545 /* Iterate the printer list */
1547 for (snum
= 0; snum
< n_services
; snum
++) {
1548 if (!lp_snum_ok(snum
) || !lp_print_ok(snum
)) {
1552 /* ignore [printers] share */
1553 if (strequal(lp_const_servicename(snum
), "printers")) {
1558 result
= winreg_printer_binding_handle(tmp_ctx
,
1562 if (!W_ERROR_IS_OK(result
)) {
1567 result
= winreg_get_printer(tmp_ctx
, b
,
1568 lp_const_servicename(snum
),
1571 if (!W_ERROR_IS_OK(result
)) {
1575 if (!pinfo2
->drivername
) {
1579 if (strcmp(drivername
, pinfo2
->drivername
) != 0) {
1583 DEBUG(6,("Updating printer [%s]\n", pinfo2
->printername
));
1585 /* all we care about currently is the change_id */
1586 result
= winreg_printer_update_changeid(tmp_ctx
, b
,
1587 pinfo2
->printername
);
1589 if (!W_ERROR_IS_OK(result
)) {
1590 DEBUG(3, ("do_drv_upgrade_printer: "
1591 "Failed to update changeid [%s]\n",
1592 win_errstr(result
)));
1598 talloc_free(tmp_ctx
);
1601 /********************************************************************
1602 Update the cache for all printq's with a registered client
1604 ********************************************************************/
1606 void update_monitored_printq_cache(struct messaging_context
*msg_ctx
)
1608 struct printer_handle
*printer
= printers_list
;
1611 /* loop through all printers and update the cache where
1612 a client is connected */
1614 if ((printer
->printer_type
== SPLHND_PRINTER
) &&
1615 ((printer
->notify
.cli_chan
!= NULL
) &&
1616 (printer
->notify
.cli_chan
->active_connections
> 0))) {
1617 snum
= print_queue_snum(printer
->sharename
);
1618 print_queue_status(msg_ctx
, snum
, NULL
, NULL
);
1621 printer
= printer
->next
;
1627 /****************************************************************
1628 _spoolss_OpenPrinter
1629 ****************************************************************/
1631 WERROR
_spoolss_OpenPrinter(struct pipes_struct
*p
,
1632 struct spoolss_OpenPrinter
*r
)
1634 struct spoolss_OpenPrinterEx e
;
1637 ZERO_STRUCT(e
.in
.userlevel
);
1639 e
.in
.printername
= r
->in
.printername
;
1640 e
.in
.datatype
= r
->in
.datatype
;
1641 e
.in
.devmode_ctr
= r
->in
.devmode_ctr
;
1642 e
.in
.access_mask
= r
->in
.access_mask
;
1645 e
.out
.handle
= r
->out
.handle
;
1647 werr
= _spoolss_OpenPrinterEx(p
, &e
);
1649 if (W_ERROR_EQUAL(werr
, WERR_INVALID_PARAM
)) {
1650 /* OpenPrinterEx returns this for a bad
1651 * printer name. We must return WERR_INVALID_PRINTER_NAME
1654 werr
= WERR_INVALID_PRINTER_NAME
;
1660 static WERROR
copy_devicemode(TALLOC_CTX
*mem_ctx
,
1661 struct spoolss_DeviceMode
*orig
,
1662 struct spoolss_DeviceMode
**dest
)
1664 struct spoolss_DeviceMode
*dm
;
1666 dm
= talloc(mem_ctx
, struct spoolss_DeviceMode
);
1671 /* copy all values, then duplicate strings and structs */
1674 dm
->devicename
= talloc_strdup(dm
, orig
->devicename
);
1675 if (!dm
->devicename
) {
1678 dm
->formname
= talloc_strdup(dm
, orig
->formname
);
1679 if (!dm
->formname
) {
1682 if (orig
->driverextra_data
.data
) {
1683 dm
->driverextra_data
.data
=
1684 (uint8_t *) talloc_memdup(dm
, orig
->driverextra_data
.data
,
1685 orig
->driverextra_data
.length
);
1686 if (!dm
->driverextra_data
.data
) {
1695 /****************************************************************
1696 _spoolss_OpenPrinterEx
1697 ****************************************************************/
1699 WERROR
_spoolss_OpenPrinterEx(struct pipes_struct
*p
,
1700 struct spoolss_OpenPrinterEx
*r
)
1705 struct printer_handle
*Printer
=NULL
;
1709 if (!r
->in
.printername
) {
1710 return WERR_INVALID_PARAM
;
1713 if (!*r
->in
.printername
) {
1714 return WERR_INVALID_PARAM
;
1717 if (r
->in
.level
> 3) {
1718 return WERR_INVALID_PARAM
;
1720 if ((r
->in
.level
== 1 && !r
->in
.userlevel
.level1
) ||
1721 (r
->in
.level
== 2 && !r
->in
.userlevel
.level2
) ||
1722 (r
->in
.level
== 3 && !r
->in
.userlevel
.level3
)) {
1723 return WERR_INVALID_PARAM
;
1726 /* some sanity check because you can open a printer or a print server */
1727 /* aka: \\server\printer or \\server */
1729 DEBUGADD(3,("checking name: %s\n", r
->in
.printername
));
1731 result
= open_printer_hnd(p
, r
->out
.handle
, r
->in
.printername
, 0);
1732 if (!W_ERROR_IS_OK(result
)) {
1733 DEBUG(0,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
1734 "for printer %s\n", r
->in
.printername
));
1735 ZERO_STRUCTP(r
->out
.handle
);
1739 Printer
= find_printer_index_by_hnd(p
, r
->out
.handle
);
1741 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1742 "handle we created for printer %s\n", r
->in
.printername
));
1743 close_printer_handle(p
, r
->out
.handle
);
1744 ZERO_STRUCTP(r
->out
.handle
);
1745 return WERR_INVALID_PARAM
;
1749 * First case: the user is opening the print server:
1751 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1752 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1754 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1755 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1756 * or if the user is listed in the smb.conf printer admin parameter.
1758 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1759 * client view printer folder, but does not show the MSAPW.
1761 * Note: this test needs code to check access rights here too. Jeremy
1762 * could you look at this?
1764 * Second case: the user is opening a printer:
1765 * NT doesn't let us connect to a printer if the connecting user
1766 * doesn't have print permission.
1768 * Third case: user is opening a Port Monitor
1769 * access checks same as opening a handle to the print server.
1772 switch (Printer
->printer_type
)
1775 case SPLHND_PORTMON_TCP
:
1776 case SPLHND_PORTMON_LOCAL
:
1777 /* Printserver handles use global struct... */
1781 /* Map standard access rights to object specific access rights */
1783 se_map_standard(&r
->in
.access_mask
,
1784 &printserver_std_mapping
);
1786 /* Deny any object specific bits that don't apply to print
1787 servers (i.e printer and job specific bits) */
1789 r
->in
.access_mask
&= SEC_MASK_SPECIFIC
;
1791 if (r
->in
.access_mask
&
1792 ~(SERVER_ACCESS_ADMINISTER
| SERVER_ACCESS_ENUMERATE
)) {
1793 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1794 close_printer_handle(p
, r
->out
.handle
);
1795 ZERO_STRUCTP(r
->out
.handle
);
1796 return WERR_ACCESS_DENIED
;
1799 /* Allow admin access */
1801 if ( r
->in
.access_mask
& SERVER_ACCESS_ADMINISTER
)
1803 if (!lp_ms_add_printer_wizard()) {
1804 close_printer_handle(p
, r
->out
.handle
);
1805 ZERO_STRUCTP(r
->out
.handle
);
1806 return WERR_ACCESS_DENIED
;
1809 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1810 and not a printer admin, then fail */
1812 if ((p
->session_info
->unix_token
->uid
!= sec_initial_uid()) &&
1813 !security_token_has_privilege(p
->session_info
->security_token
, SEC_PRIV_PRINT_OPERATOR
) &&
1814 !nt_token_check_sid(&global_sid_Builtin_Print_Operators
, p
->session_info
->security_token
) &&
1815 !token_contains_name_in_list(
1816 uidtoname(p
->session_info
->unix_token
->uid
),
1817 p
->session_info
->info
->domain_name
,
1819 p
->session_info
->security_token
,
1820 lp_printer_admin(snum
))) {
1821 close_printer_handle(p
, r
->out
.handle
);
1822 ZERO_STRUCTP(r
->out
.handle
);
1823 DEBUG(3,("access DENIED as user is not root, "
1824 "has no printoperator privilege, "
1825 "not a member of the printoperator builtin group and "
1826 "is not in printer admin list"));
1827 return WERR_ACCESS_DENIED
;
1830 r
->in
.access_mask
= SERVER_ACCESS_ADMINISTER
;
1834 r
->in
.access_mask
= SERVER_ACCESS_ENUMERATE
;
1837 DEBUG(4,("Setting print server access = %s\n", (r
->in
.access_mask
== SERVER_ACCESS_ADMINISTER
)
1838 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1840 /* We fall through to return WERR_OK */
1843 case SPLHND_PRINTER
:
1844 /* NT doesn't let us connect to a printer if the connecting user
1845 doesn't have print permission. */
1847 if (!get_printer_snum(p
, r
->out
.handle
, &snum
, NULL
)) {
1848 close_printer_handle(p
, r
->out
.handle
);
1849 ZERO_STRUCTP(r
->out
.handle
);
1853 if (r
->in
.access_mask
== SEC_FLAG_MAXIMUM_ALLOWED
) {
1854 r
->in
.access_mask
= PRINTER_ACCESS_ADMINISTER
;
1857 se_map_standard(&r
->in
.access_mask
, &printer_std_mapping
);
1859 /* map an empty access mask to the minimum access mask */
1860 if (r
->in
.access_mask
== 0x0)
1861 r
->in
.access_mask
= PRINTER_ACCESS_USE
;
1864 * If we are not serving the printer driver for this printer,
1865 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1866 * will keep NT clients happy --jerry
1869 if (lp_use_client_driver(snum
)
1870 && (r
->in
.access_mask
& PRINTER_ACCESS_ADMINISTER
))
1872 r
->in
.access_mask
= PRINTER_ACCESS_USE
;
1875 /* check smb.conf parameters and the the sec_desc */
1876 raddr
= tsocket_address_inet_addr_string(p
->remote_address
,
1878 if (raddr
== NULL
) {
1882 rc
= get_remote_hostname(p
->remote_address
,
1888 if (strequal(rhost
, "UNKNOWN")) {
1892 if (!allow_access(lp_hostsdeny(snum
), lp_hostsallow(snum
),
1894 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1895 ZERO_STRUCTP(r
->out
.handle
);
1896 return WERR_ACCESS_DENIED
;
1899 if (!user_ok_token(uidtoname(p
->session_info
->unix_token
->uid
), NULL
,
1900 p
->session_info
->security_token
, snum
) ||
1901 !print_access_check(p
->session_info
,
1904 r
->in
.access_mask
)) {
1905 DEBUG(3, ("access DENIED for printer open\n"));
1906 close_printer_handle(p
, r
->out
.handle
);
1907 ZERO_STRUCTP(r
->out
.handle
);
1908 return WERR_ACCESS_DENIED
;
1911 if ((r
->in
.access_mask
& SEC_MASK_SPECIFIC
)& ~(PRINTER_ACCESS_ADMINISTER
|PRINTER_ACCESS_USE
)) {
1912 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1913 close_printer_handle(p
, r
->out
.handle
);
1914 ZERO_STRUCTP(r
->out
.handle
);
1915 return WERR_ACCESS_DENIED
;
1918 if (r
->in
.access_mask
& PRINTER_ACCESS_ADMINISTER
)
1919 r
->in
.access_mask
= PRINTER_ACCESS_ADMINISTER
;
1921 r
->in
.access_mask
= PRINTER_ACCESS_USE
;
1923 DEBUG(4,("Setting printer access = %s\n", (r
->in
.access_mask
== PRINTER_ACCESS_ADMINISTER
)
1924 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1926 winreg_create_printer_internal(p
->mem_ctx
,
1927 get_session_info_system(),
1929 lp_const_servicename(snum
));
1934 /* sanity check to prevent programmer error */
1935 ZERO_STRUCTP(r
->out
.handle
);
1939 Printer
->access_granted
= r
->in
.access_mask
;
1942 * If the client sent a devmode in the OpenPrinter() call, then
1943 * save it here in case we get a job submission on this handle
1946 if ((Printer
->printer_type
!= SPLHND_SERVER
) &&
1947 r
->in
.devmode_ctr
.devmode
) {
1948 copy_devicemode(NULL
, r
->in
.devmode_ctr
.devmode
,
1952 #if 0 /* JERRY -- I'm doubtful this is really effective */
1953 /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
1954 optimization in Windows 2000 clients --jerry */
1956 if ( (r
->in
.access_mask
== PRINTER_ACCESS_ADMINISTER
)
1957 && (RA_WIN2K
== get_remote_arch()) )
1959 DEBUG(10,("_spoolss_OpenPrinterEx: Enabling LAN/WAN hack for Win2k clients.\n"));
1967 /****************************************************************
1968 _spoolss_ClosePrinter
1969 ****************************************************************/
1971 WERROR
_spoolss_ClosePrinter(struct pipes_struct
*p
,
1972 struct spoolss_ClosePrinter
*r
)
1974 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
1976 if (Printer
&& Printer
->document_started
) {
1977 struct spoolss_EndDocPrinter e
;
1979 e
.in
.handle
= r
->in
.handle
;
1981 _spoolss_EndDocPrinter(p
, &e
);
1984 if (!close_printer_handle(p
, r
->in
.handle
))
1987 /* clear the returned printer handle. Observed behavior
1988 from Win2k server. Don't think this really matters.
1989 Previous code just copied the value of the closed
1992 ZERO_STRUCTP(r
->out
.handle
);
1997 /****************************************************************
1998 _spoolss_DeletePrinter
1999 ****************************************************************/
2001 WERROR
_spoolss_DeletePrinter(struct pipes_struct
*p
,
2002 struct spoolss_DeletePrinter
*r
)
2004 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
2008 if (Printer
&& Printer
->document_started
) {
2009 struct spoolss_EndDocPrinter e
;
2011 e
.in
.handle
= r
->in
.handle
;
2013 _spoolss_EndDocPrinter(p
, &e
);
2016 if (get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
2017 winreg_delete_printer_key_internal(p
->mem_ctx
,
2018 get_session_info_system(),
2020 lp_const_servicename(snum
),
2024 result
= delete_printer_handle(p
, r
->in
.handle
);
2029 /*******************************************************************
2030 * static function to lookup the version id corresponding to an
2031 * long architecture string
2032 ******************************************************************/
2034 static const struct print_architecture_table_node archi_table
[]= {
2036 {"Windows 4.0", SPL_ARCH_WIN40
, 0 },
2037 {"Windows NT x86", SPL_ARCH_W32X86
, 2 },
2038 {"Windows NT R4000", SPL_ARCH_W32MIPS
, 2 },
2039 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA
, 2 },
2040 {"Windows NT PowerPC", SPL_ARCH_W32PPC
, 2 },
2041 {"Windows IA64", SPL_ARCH_IA64
, 3 },
2042 {"Windows x64", SPL_ARCH_X64
, 3 },
2046 static const int drv_cversion
[] = {SPOOLSS_DRIVER_VERSION_9X
,
2047 SPOOLSS_DRIVER_VERSION_NT35
,
2048 SPOOLSS_DRIVER_VERSION_NT4
,
2049 SPOOLSS_DRIVER_VERSION_200X
,
2052 static int get_version_id(const char *arch
)
2056 for (i
=0; archi_table
[i
].long_archi
!= NULL
; i
++)
2058 if (strcmp(arch
, archi_table
[i
].long_archi
) == 0)
2059 return (archi_table
[i
].version
);
2065 /****************************************************************
2066 _spoolss_DeletePrinterDriver
2067 ****************************************************************/
2069 WERROR
_spoolss_DeletePrinterDriver(struct pipes_struct
*p
,
2070 struct spoolss_DeletePrinterDriver
*r
)
2073 struct spoolss_DriverInfo8
*info
= NULL
;
2076 struct dcerpc_binding_handle
*b
;
2077 TALLOC_CTX
*tmp_ctx
= NULL
;
2081 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2082 and not a printer admin, then fail */
2084 if ( (p
->session_info
->unix_token
->uid
!= sec_initial_uid())
2085 && !security_token_has_privilege(p
->session_info
->security_token
, SEC_PRIV_PRINT_OPERATOR
)
2086 && !token_contains_name_in_list(
2087 uidtoname(p
->session_info
->unix_token
->uid
),
2088 p
->session_info
->info
->domain_name
,
2090 p
->session_info
->security_token
,
2091 lp_printer_admin(-1)) )
2093 return WERR_ACCESS_DENIED
;
2096 /* check that we have a valid driver name first */
2098 if ((version
= get_version_id(r
->in
.architecture
)) == -1) {
2099 return WERR_INVALID_ENVIRONMENT
;
2102 tmp_ctx
= talloc_new(p
->mem_ctx
);
2107 status
= winreg_printer_binding_handle(tmp_ctx
,
2108 get_session_info_system(),
2111 if (!W_ERROR_IS_OK(status
)) {
2115 for (found
= false, i
= 0; drv_cversion
[i
] >= 0; i
++) {
2116 status
= winreg_get_driver(tmp_ctx
, b
,
2117 r
->in
.architecture
, r
->in
.driver
,
2118 drv_cversion
[i
], &info
);
2119 if (!W_ERROR_IS_OK(status
)) {
2120 DEBUG(5, ("skipping del of driver with version %d\n",
2126 if (printer_driver_in_use(tmp_ctx
, b
, info
)) {
2127 status
= WERR_PRINTER_DRIVER_IN_USE
;
2131 status
= winreg_del_driver(tmp_ctx
, b
, info
, drv_cversion
[i
]);
2132 if (!W_ERROR_IS_OK(status
)) {
2133 DEBUG(0, ("failed del of driver with version %d\n",
2138 if (found
== false) {
2139 DEBUG(0, ("driver %s not found for deletion\n", r
->in
.driver
));
2140 status
= WERR_UNKNOWN_PRINTER_DRIVER
;
2146 talloc_free(tmp_ctx
);
2151 static WERROR
spoolss_dpd_version(TALLOC_CTX
*mem_ctx
,
2152 struct pipes_struct
*p
,
2153 struct spoolss_DeletePrinterDriverEx
*r
,
2154 struct dcerpc_binding_handle
*b
,
2155 struct spoolss_DriverInfo8
*info
)
2160 if (printer_driver_in_use(mem_ctx
, b
, info
)) {
2161 status
= WERR_PRINTER_DRIVER_IN_USE
;
2166 * we have a couple of cases to consider.
2167 * (1) Are any files in use? If so and DPD_DELETE_ALL_FILES is set,
2168 * then the delete should fail if **any** files overlap with
2170 * (2) If DPD_DELETE_UNUSED_FILES is set, then delete all
2171 * non-overlapping files
2172 * (3) If neither DPD_DELETE_ALL_FILES nor DPD_DELETE_UNUSED_FILES
2173 * are set, then do not delete any files
2174 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
2177 delete_files
= r
->in
.delete_flags
2178 & (DPD_DELETE_ALL_FILES
| DPD_DELETE_UNUSED_FILES
);
2182 bool in_use
= printer_driver_files_in_use(mem_ctx
, b
, info
);
2183 if (in_use
&& (r
->in
.delete_flags
& DPD_DELETE_ALL_FILES
)) {
2184 status
= WERR_PRINTER_DRIVER_IN_USE
;
2188 * printer_driver_files_in_use() has trimmed overlapping files
2189 * from info so they are not removed on DPD_DELETE_UNUSED_FILES
2194 status
= winreg_del_driver(mem_ctx
, b
, info
, info
->version
);
2195 if (!W_ERROR_IS_OK(status
)) {
2200 * now delete any associated files if delete_files is
2201 * true. Even if this part failes, we return succes
2202 * because the driver doesn not exist any more
2205 delete_driver_files(get_session_info_system(), info
);
2212 /****************************************************************
2213 _spoolss_DeletePrinterDriverEx
2214 ****************************************************************/
2216 WERROR
_spoolss_DeletePrinterDriverEx(struct pipes_struct
*p
,
2217 struct spoolss_DeletePrinterDriverEx
*r
)
2219 struct spoolss_DriverInfo8
*info
= NULL
;
2221 struct dcerpc_binding_handle
*b
;
2222 TALLOC_CTX
*tmp_ctx
= NULL
;
2226 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2227 and not a printer admin, then fail */
2229 if ( (p
->session_info
->unix_token
->uid
!= sec_initial_uid())
2230 && !security_token_has_privilege(p
->session_info
->security_token
, SEC_PRIV_PRINT_OPERATOR
)
2231 && !token_contains_name_in_list(
2232 uidtoname(p
->session_info
->unix_token
->uid
),
2233 p
->session_info
->info
->domain_name
,
2235 p
->session_info
->security_token
, lp_printer_admin(-1)) )
2237 return WERR_ACCESS_DENIED
;
2240 /* check that we have a valid driver name first */
2241 if (get_version_id(r
->in
.architecture
) == -1) {
2242 /* this is what NT returns */
2243 return WERR_INVALID_ENVIRONMENT
;
2246 tmp_ctx
= talloc_new(p
->mem_ctx
);
2251 status
= winreg_printer_binding_handle(tmp_ctx
,
2252 get_session_info_system(),
2255 if (!W_ERROR_IS_OK(status
)) {
2259 for (found
= false, i
= 0; drv_cversion
[i
] >= 0; i
++) {
2260 if ((r
->in
.delete_flags
& DPD_DELETE_SPECIFIC_VERSION
)
2261 && (drv_cversion
[i
] != r
->in
.version
)) {
2265 /* check if a driver with this version exists before delete */
2266 status
= winreg_get_driver(tmp_ctx
, b
,
2267 r
->in
.architecture
, r
->in
.driver
,
2268 drv_cversion
[i
], &info
);
2269 if (!W_ERROR_IS_OK(status
)) {
2270 DEBUG(5, ("skipping del of driver with version %d\n",
2276 status
= spoolss_dpd_version(tmp_ctx
, p
, r
, b
, info
);
2277 if (!W_ERROR_IS_OK(status
)) {
2278 DEBUG(0, ("failed to delete driver with version %d\n",
2283 if (found
== false) {
2284 DEBUG(0, ("driver %s not found for deletion\n", r
->in
.driver
));
2285 status
= WERR_UNKNOWN_PRINTER_DRIVER
;
2291 talloc_free(tmp_ctx
);
2296 /********************************************************************
2297 GetPrinterData on a printer server Handle.
2298 ********************************************************************/
2300 static WERROR
getprinterdata_printer_server(TALLOC_CTX
*mem_ctx
,
2302 enum winreg_Type
*type
,
2303 union spoolss_PrinterData
*data
)
2305 DEBUG(8,("getprinterdata_printer_server:%s\n", value
));
2307 if (!strcasecmp_m(value
, "W3SvcInstalled")) {
2313 if (!strcasecmp_m(value
, "BeepEnabled")) {
2319 if (!strcasecmp_m(value
, "EventLog")) {
2321 /* formally was 0x1b */
2326 if (!strcasecmp_m(value
, "NetPopup")) {
2332 if (!strcasecmp_m(value
, "MajorVersion")) {
2335 /* Windows NT 4.0 seems to not allow uploading of drivers
2336 to a server that reports 0x3 as the MajorVersion.
2337 need to investigate more how Win2k gets around this .
2340 if (RA_WINNT
== get_remote_arch()) {
2349 if (!strcasecmp_m(value
, "MinorVersion")) {
2356 * uint32_t size = 0x114
2357 * uint32_t major = 5
2358 * uint32_t minor = [0|1]
2359 * uint32_t build = [2195|2600]
2360 * extra unicode string = e.g. "Service Pack 3"
2362 if (!strcasecmp_m(value
, "OSVersion")) {
2364 enum ndr_err_code ndr_err
;
2365 struct spoolss_OSVersion os
;
2367 os
.major
= 5; /* Windows 2000 == 5.0 */
2369 os
.build
= 2195; /* build */
2370 os
.extra_string
= ""; /* leave extra string empty */
2372 ndr_err
= ndr_push_struct_blob(&blob
, mem_ctx
, &os
,
2373 (ndr_push_flags_fn_t
)ndr_push_spoolss_OSVersion
);
2374 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2375 return WERR_GENERAL_FAILURE
;
2379 data
->binary
= blob
;
2385 if (!strcasecmp_m(value
, "DefaultSpoolDirectory")) {
2388 data
->string
= talloc_strdup(mem_ctx
, "C:\\PRINTERS");
2389 W_ERROR_HAVE_NO_MEMORY(data
->string
);
2394 if (!strcasecmp_m(value
, "Architecture")) {
2396 data
->string
= talloc_strdup(mem_ctx
,
2397 lp_parm_const_string(GLOBAL_SECTION_SNUM
, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_NT_X86
));
2398 W_ERROR_HAVE_NO_MEMORY(data
->string
);
2403 if (!strcasecmp_m(value
, "DsPresent")) {
2406 /* only show the publish check box if we are a
2407 member of a AD domain */
2409 if (lp_security() == SEC_ADS
) {
2417 if (!strcasecmp_m(value
, "DNSMachineName")) {
2418 const char *hostname
= get_mydnsfullname();
2421 return WERR_BADFILE
;
2425 data
->string
= talloc_strdup(mem_ctx
, hostname
);
2426 W_ERROR_HAVE_NO_MEMORY(data
->string
);
2433 return WERR_INVALID_PARAM
;
2436 /****************************************************************
2437 _spoolss_GetPrinterData
2438 ****************************************************************/
2440 WERROR
_spoolss_GetPrinterData(struct pipes_struct
*p
,
2441 struct spoolss_GetPrinterData
*r
)
2443 struct spoolss_GetPrinterDataEx r2
;
2445 r2
.in
.handle
= r
->in
.handle
;
2446 r2
.in
.key_name
= "PrinterDriverData";
2447 r2
.in
.value_name
= r
->in
.value_name
;
2448 r2
.in
.offered
= r
->in
.offered
;
2449 r2
.out
.type
= r
->out
.type
;
2450 r2
.out
.data
= r
->out
.data
;
2451 r2
.out
.needed
= r
->out
.needed
;
2453 return _spoolss_GetPrinterDataEx(p
, &r2
);
2456 /*********************************************************
2457 Connect to the client machine.
2458 **********************************************************/
2460 static bool spoolss_connect_to_client(struct rpc_pipe_client
**pp_pipe
,
2461 struct sockaddr_storage
*client_ss
, const char *remote_machine
)
2464 struct cli_state
*the_cli
;
2465 struct sockaddr_storage rm_addr
;
2466 char addr
[INET6_ADDRSTRLEN
];
2468 if ( is_zero_addr(client_ss
) ) {
2469 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2471 if ( !resolve_name( remote_machine
, &rm_addr
, 0x20, false) ) {
2472 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine
));
2475 print_sockaddr(addr
, sizeof(addr
), &rm_addr
);
2477 rm_addr
= *client_ss
;
2478 print_sockaddr(addr
, sizeof(addr
), &rm_addr
);
2479 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2483 if (ismyaddr((struct sockaddr
*)(void *)&rm_addr
)) {
2484 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2489 /* setup the connection */
2490 ret
= cli_full_connection( &the_cli
, lp_netbios_name(), remote_machine
,
2491 &rm_addr
, 0, "IPC$", "IPC",
2495 0, lp_client_signing());
2497 if ( !NT_STATUS_IS_OK( ret
) ) {
2498 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2503 if ( cli_state_protocol(the_cli
) != PROTOCOL_NT1
) {
2504 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine
));
2505 cli_shutdown(the_cli
);
2510 * Ok - we have an anonymous connection to the IPC$ share.
2511 * Now start the NT Domain stuff :-).
2514 ret
= cli_rpc_pipe_open_noauth(the_cli
, &ndr_table_spoolss
.syntax_id
, pp_pipe
);
2515 if (!NT_STATUS_IS_OK(ret
)) {
2516 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2517 remote_machine
, nt_errstr(ret
)));
2518 cli_shutdown(the_cli
);
2525 /***************************************************************************
2526 Connect to the client.
2527 ****************************************************************************/
2529 static bool srv_spoolss_replyopenprinter(int snum
, const char *printer
,
2530 uint32_t localprinter
,
2531 enum winreg_Type type
,
2532 struct policy_handle
*handle
,
2533 struct notify_back_channel
**_chan
,
2534 struct sockaddr_storage
*client_ss
,
2535 struct messaging_context
*msg_ctx
)
2539 struct notify_back_channel
*chan
;
2541 for (chan
= back_channels
; chan
; chan
= chan
->next
) {
2542 if (memcmp(&chan
->client_address
, client_ss
,
2543 sizeof(struct sockaddr_storage
)) == 0) {
2549 * If it's the first connection, contact the client
2550 * and connect to the IPC$ share anonymously
2553 fstring unix_printer
;
2555 /* the +2 is to strip the leading 2 backslashs */
2556 fstrcpy(unix_printer
, printer
+ 2);
2558 chan
= talloc_zero(NULL
, struct notify_back_channel
);
2562 chan
->client_address
= *client_ss
;
2564 if (!spoolss_connect_to_client(&chan
->cli_pipe
, client_ss
, unix_printer
)) {
2569 DLIST_ADD(back_channels
, chan
);
2571 messaging_register(msg_ctx
, NULL
, MSG_PRINTER_NOTIFY2
,
2572 receive_notify2_message_list
);
2575 if (chan
->cli_pipe
== NULL
||
2576 chan
->cli_pipe
->binding_handle
== NULL
) {
2577 DEBUG(0, ("srv_spoolss_replyopenprinter: error - "
2578 "NULL %s for printer %s\n",
2579 chan
->cli_pipe
== NULL
?
2580 "chan->cli_pipe" : "chan->cli_pipe->binding_handle",
2586 * Tell the specific printing tdb we want messages for this printer
2587 * by registering our PID.
2590 if (!print_notify_register_pid(snum
)) {
2591 DEBUG(0, ("Failed to register our pid for printer %s\n",
2595 status
= dcerpc_spoolss_ReplyOpenPrinter(chan
->cli_pipe
->binding_handle
,
2604 if (!NT_STATUS_IS_OK(status
)) {
2605 DEBUG(5, ("dcerpc_spoolss_ReplyOpenPrinter returned [%s]\n", nt_errstr(status
)));
2606 result
= ntstatus_to_werror(status
);
2607 } else if (!W_ERROR_IS_OK(result
)) {
2608 DEBUG(5, ("ReplyOpenPrinter returned [%s]\n", win_errstr(result
)));
2611 chan
->active_connections
++;
2614 return (W_ERROR_IS_OK(result
));
2617 /****************************************************************
2618 ****************************************************************/
2620 static struct spoolss_NotifyOption
*dup_spoolss_NotifyOption(TALLOC_CTX
*mem_ctx
,
2621 const struct spoolss_NotifyOption
*r
)
2623 struct spoolss_NotifyOption
*option
;
2630 option
= talloc_zero(mem_ctx
, struct spoolss_NotifyOption
);
2637 if (!option
->count
) {
2641 option
->types
= talloc_zero_array(option
,
2642 struct spoolss_NotifyOptionType
, option
->count
);
2643 if (!option
->types
) {
2644 talloc_free(option
);
2648 for (i
=0; i
< option
->count
; i
++) {
2649 option
->types
[i
] = r
->types
[i
];
2651 if (option
->types
[i
].count
) {
2652 option
->types
[i
].fields
= talloc_zero_array(option
,
2653 union spoolss_Field
, option
->types
[i
].count
);
2654 if (!option
->types
[i
].fields
) {
2655 talloc_free(option
);
2658 for (k
=0; k
<option
->types
[i
].count
; k
++) {
2659 option
->types
[i
].fields
[k
] =
2660 r
->types
[i
].fields
[k
];
2668 /****************************************************************
2669 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2671 * before replying OK: status=0 a rpc call is made to the workstation
2672 * asking ReplyOpenPrinter
2674 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2675 * called from api_spoolss_rffpcnex
2676 ****************************************************************/
2678 WERROR
_spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct
*p
,
2679 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx
*r
)
2682 struct spoolss_NotifyOption
*option
= r
->in
.notify_options
;
2683 struct sockaddr_storage client_ss
;
2686 /* store the notify value in the printer struct */
2688 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
2691 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2692 "Invalid handle (%s:%u:%u).\n",
2693 OUR_HANDLE(r
->in
.handle
)));
2697 Printer
->notify
.flags
= r
->in
.flags
;
2698 Printer
->notify
.options
= r
->in
.options
;
2699 Printer
->notify
.printerlocal
= r
->in
.printer_local
;
2700 Printer
->notify
.msg_ctx
= p
->msg_ctx
;
2702 TALLOC_FREE(Printer
->notify
.option
);
2703 Printer
->notify
.option
= dup_spoolss_NotifyOption(Printer
, option
);
2705 fstrcpy(Printer
->notify
.localmachine
, r
->in
.local_machine
);
2707 /* Connect to the client machine and send a ReplyOpenPrinter */
2709 if ( Printer
->printer_type
== SPLHND_SERVER
)
2711 else if ( (Printer
->printer_type
== SPLHND_PRINTER
) &&
2712 !get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
) )
2715 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2716 "remote_address is %s\n",
2717 tsocket_address_string(p
->remote_address
, p
->mem_ctx
)));
2719 if (!lp_print_notify_backchannel(snum
)) {
2720 DEBUG(10, ("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2721 "backchannel disabled\n"));
2722 return WERR_SERVER_UNAVAILABLE
;
2725 client_len
= tsocket_address_bsd_sockaddr(p
->remote_address
,
2726 (struct sockaddr
*) &client_ss
,
2727 sizeof(struct sockaddr_storage
));
2728 if (client_len
< 0) {
2732 if(!srv_spoolss_replyopenprinter(snum
, Printer
->notify
.localmachine
,
2733 Printer
->notify
.printerlocal
, REG_SZ
,
2734 &Printer
->notify
.cli_hnd
,
2735 &Printer
->notify
.cli_chan
,
2736 &client_ss
, p
->msg_ctx
)) {
2737 return WERR_SERVER_UNAVAILABLE
;
2743 /*******************************************************************
2744 * fill a notify_info_data with the servername
2745 ********************************************************************/
2747 static void spoolss_notify_server_name(struct messaging_context
*msg_ctx
,
2749 struct spoolss_Notify
*data
,
2750 print_queue_struct
*queue
,
2751 struct spoolss_PrinterInfo2
*pinfo2
,
2752 TALLOC_CTX
*mem_ctx
)
2754 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->servername
);
2757 /*******************************************************************
2758 * fill a notify_info_data with the printername (not including the servername).
2759 ********************************************************************/
2761 static void spoolss_notify_printer_name(struct messaging_context
*msg_ctx
,
2763 struct spoolss_Notify
*data
,
2764 print_queue_struct
*queue
,
2765 struct spoolss_PrinterInfo2
*pinfo2
,
2766 TALLOC_CTX
*mem_ctx
)
2768 /* the notify name should not contain the \\server\ part */
2769 const char *p
= strrchr(pinfo2
->printername
, '\\');
2772 p
= pinfo2
->printername
;
2777 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, p
);
2780 /*******************************************************************
2781 * fill a notify_info_data with the servicename
2782 ********************************************************************/
2784 static void spoolss_notify_share_name(struct messaging_context
*msg_ctx
,
2786 struct spoolss_Notify
*data
,
2787 print_queue_struct
*queue
,
2788 struct spoolss_PrinterInfo2
*pinfo2
,
2789 TALLOC_CTX
*mem_ctx
)
2791 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, lp_servicename(snum
));
2794 /*******************************************************************
2795 * fill a notify_info_data with the port name
2796 ********************************************************************/
2798 static void spoolss_notify_port_name(struct messaging_context
*msg_ctx
,
2800 struct spoolss_Notify
*data
,
2801 print_queue_struct
*queue
,
2802 struct spoolss_PrinterInfo2
*pinfo2
,
2803 TALLOC_CTX
*mem_ctx
)
2805 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->portname
);
2808 /*******************************************************************
2809 * fill a notify_info_data with the printername
2810 * but it doesn't exist, have to see what to do
2811 ********************************************************************/
2813 static void spoolss_notify_driver_name(struct messaging_context
*msg_ctx
,
2815 struct spoolss_Notify
*data
,
2816 print_queue_struct
*queue
,
2817 struct spoolss_PrinterInfo2
*pinfo2
,
2818 TALLOC_CTX
*mem_ctx
)
2820 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->drivername
);
2823 /*******************************************************************
2824 * fill a notify_info_data with the comment
2825 ********************************************************************/
2827 static void spoolss_notify_comment(struct messaging_context
*msg_ctx
,
2829 struct spoolss_Notify
*data
,
2830 print_queue_struct
*queue
,
2831 struct spoolss_PrinterInfo2
*pinfo2
,
2832 TALLOC_CTX
*mem_ctx
)
2836 if (*pinfo2
->comment
== '\0') {
2837 p
= lp_comment(snum
);
2839 p
= pinfo2
->comment
;
2842 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, p
);
2845 /*******************************************************************
2846 * fill a notify_info_data with the comment
2847 * location = "Room 1, floor 2, building 3"
2848 ********************************************************************/
2850 static void spoolss_notify_location(struct messaging_context
*msg_ctx
,
2852 struct spoolss_Notify
*data
,
2853 print_queue_struct
*queue
,
2854 struct spoolss_PrinterInfo2
*pinfo2
,
2855 TALLOC_CTX
*mem_ctx
)
2857 const char *loc
= pinfo2
->location
;
2860 status
= printer_list_get_printer(mem_ctx
,
2865 if (NT_STATUS_IS_OK(status
)) {
2867 loc
= pinfo2
->location
;
2871 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, loc
);
2874 /*******************************************************************
2875 * fill a notify_info_data with the device mode
2876 * jfm:xxxx don't to it for know but that's a real problem !!!
2877 ********************************************************************/
2879 static void spoolss_notify_devmode(struct messaging_context
*msg_ctx
,
2881 struct spoolss_Notify
*data
,
2882 print_queue_struct
*queue
,
2883 struct spoolss_PrinterInfo2
*pinfo2
,
2884 TALLOC_CTX
*mem_ctx
)
2886 /* for a dummy implementation we have to zero the fields */
2887 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data
, NULL
);
2890 /*******************************************************************
2891 * fill a notify_info_data with the separator file name
2892 ********************************************************************/
2894 static void spoolss_notify_sepfile(struct messaging_context
*msg_ctx
,
2896 struct spoolss_Notify
*data
,
2897 print_queue_struct
*queue
,
2898 struct spoolss_PrinterInfo2
*pinfo2
,
2899 TALLOC_CTX
*mem_ctx
)
2901 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->sepfile
);
2904 /*******************************************************************
2905 * fill a notify_info_data with the print processor
2906 * jfm:xxxx return always winprint to indicate we don't do anything to it
2907 ********************************************************************/
2909 static void spoolss_notify_print_processor(struct messaging_context
*msg_ctx
,
2911 struct spoolss_Notify
*data
,
2912 print_queue_struct
*queue
,
2913 struct spoolss_PrinterInfo2
*pinfo2
,
2914 TALLOC_CTX
*mem_ctx
)
2916 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->printprocessor
);
2919 /*******************************************************************
2920 * fill a notify_info_data with the print processor options
2921 * jfm:xxxx send an empty string
2922 ********************************************************************/
2924 static void spoolss_notify_parameters(struct messaging_context
*msg_ctx
,
2926 struct spoolss_Notify
*data
,
2927 print_queue_struct
*queue
,
2928 struct spoolss_PrinterInfo2
*pinfo2
,
2929 TALLOC_CTX
*mem_ctx
)
2931 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->parameters
);
2934 /*******************************************************************
2935 * fill a notify_info_data with the data type
2936 * jfm:xxxx always send RAW as data type
2937 ********************************************************************/
2939 static void spoolss_notify_datatype(struct messaging_context
*msg_ctx
,
2941 struct spoolss_Notify
*data
,
2942 print_queue_struct
*queue
,
2943 struct spoolss_PrinterInfo2
*pinfo2
,
2944 TALLOC_CTX
*mem_ctx
)
2946 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->datatype
);
2949 /*******************************************************************
2950 * fill a notify_info_data with the security descriptor
2951 * jfm:xxxx send an null pointer to say no security desc
2952 * have to implement security before !
2953 ********************************************************************/
2955 static void spoolss_notify_security_desc(struct messaging_context
*msg_ctx
,
2957 struct spoolss_Notify
*data
,
2958 print_queue_struct
*queue
,
2959 struct spoolss_PrinterInfo2
*pinfo2
,
2960 TALLOC_CTX
*mem_ctx
)
2962 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data
, pinfo2
->secdesc
);
2965 /*******************************************************************
2966 * fill a notify_info_data with the attributes
2967 * jfm:xxxx a samba printer is always shared
2968 ********************************************************************/
2970 static void spoolss_notify_attributes(struct messaging_context
*msg_ctx
,
2972 struct spoolss_Notify
*data
,
2973 print_queue_struct
*queue
,
2974 struct spoolss_PrinterInfo2
*pinfo2
,
2975 TALLOC_CTX
*mem_ctx
)
2977 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->attributes
);
2980 /*******************************************************************
2981 * fill a notify_info_data with the priority
2982 ********************************************************************/
2984 static void spoolss_notify_priority(struct messaging_context
*msg_ctx
,
2986 struct spoolss_Notify
*data
,
2987 print_queue_struct
*queue
,
2988 struct spoolss_PrinterInfo2
*pinfo2
,
2989 TALLOC_CTX
*mem_ctx
)
2991 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->priority
);
2994 /*******************************************************************
2995 * fill a notify_info_data with the default priority
2996 ********************************************************************/
2998 static void spoolss_notify_default_priority(struct messaging_context
*msg_ctx
,
3000 struct spoolss_Notify
*data
,
3001 print_queue_struct
*queue
,
3002 struct spoolss_PrinterInfo2
*pinfo2
,
3003 TALLOC_CTX
*mem_ctx
)
3005 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->defaultpriority
);
3008 /*******************************************************************
3009 * fill a notify_info_data with the start time
3010 ********************************************************************/
3012 static void spoolss_notify_start_time(struct messaging_context
*msg_ctx
,
3014 struct spoolss_Notify
*data
,
3015 print_queue_struct
*queue
,
3016 struct spoolss_PrinterInfo2
*pinfo2
,
3017 TALLOC_CTX
*mem_ctx
)
3019 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->starttime
);
3022 /*******************************************************************
3023 * fill a notify_info_data with the until time
3024 ********************************************************************/
3026 static void spoolss_notify_until_time(struct messaging_context
*msg_ctx
,
3028 struct spoolss_Notify
*data
,
3029 print_queue_struct
*queue
,
3030 struct spoolss_PrinterInfo2
*pinfo2
,
3031 TALLOC_CTX
*mem_ctx
)
3033 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->untiltime
);
3036 /*******************************************************************
3037 * fill a notify_info_data with the status
3038 ********************************************************************/
3040 static void spoolss_notify_status(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 print_status_struct status
;
3049 print_queue_length(msg_ctx
, snum
, &status
);
3050 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, status
.status
);
3053 /*******************************************************************
3054 * fill a notify_info_data with the number of jobs queued
3055 ********************************************************************/
3057 static void spoolss_notify_cjobs(struct messaging_context
*msg_ctx
,
3059 struct spoolss_Notify
*data
,
3060 print_queue_struct
*queue
,
3061 struct spoolss_PrinterInfo2
*pinfo2
,
3062 TALLOC_CTX
*mem_ctx
)
3064 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(
3065 data
, print_queue_length(msg_ctx
, snum
, NULL
));
3068 /*******************************************************************
3069 * fill a notify_info_data with the average ppm
3070 ********************************************************************/
3072 static void spoolss_notify_average_ppm(struct messaging_context
*msg_ctx
,
3074 struct spoolss_Notify
*data
,
3075 print_queue_struct
*queue
,
3076 struct spoolss_PrinterInfo2
*pinfo2
,
3077 TALLOC_CTX
*mem_ctx
)
3079 /* always respond 8 pages per minutes */
3080 /* a little hard ! */
3081 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->averageppm
);
3084 /*******************************************************************
3085 * fill a notify_info_data with username
3086 ********************************************************************/
3088 static void spoolss_notify_username(struct messaging_context
*msg_ctx
,
3090 struct spoolss_Notify
*data
,
3091 print_queue_struct
*queue
,
3092 struct spoolss_PrinterInfo2
*pinfo2
,
3093 TALLOC_CTX
*mem_ctx
)
3095 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, queue
->fs_user
);
3098 /*******************************************************************
3099 * fill a notify_info_data with job status
3100 ********************************************************************/
3102 static void spoolss_notify_job_status(struct messaging_context
*msg_ctx
,
3104 struct spoolss_Notify
*data
,
3105 print_queue_struct
*queue
,
3106 struct spoolss_PrinterInfo2
*pinfo2
,
3107 TALLOC_CTX
*mem_ctx
)
3109 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, nt_printj_status(queue
->status
));
3112 /*******************************************************************
3113 * fill a notify_info_data with job name
3114 ********************************************************************/
3116 static void spoolss_notify_job_name(struct messaging_context
*msg_ctx
,
3118 struct spoolss_Notify
*data
,
3119 print_queue_struct
*queue
,
3120 struct spoolss_PrinterInfo2
*pinfo2
,
3121 TALLOC_CTX
*mem_ctx
)
3123 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, queue
->fs_file
);
3126 /*******************************************************************
3127 * fill a notify_info_data with job status
3128 ********************************************************************/
3130 static void spoolss_notify_job_status_string(struct messaging_context
*msg_ctx
,
3132 struct spoolss_Notify
*data
,
3133 print_queue_struct
*queue
,
3134 struct spoolss_PrinterInfo2
*pinfo2
,
3135 TALLOC_CTX
*mem_ctx
)
3138 * Now we're returning job status codes we just return a "" here. JRA.
3143 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
3146 switch (queue
->status
) {
3151 p
= ""; /* NT provides the paused string */
3160 #endif /* NO LONGER NEEDED. */
3162 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, p
);
3165 /*******************************************************************
3166 * fill a notify_info_data with job time
3167 ********************************************************************/
3169 static void spoolss_notify_job_time(struct messaging_context
*msg_ctx
,
3171 struct spoolss_Notify
*data
,
3172 print_queue_struct
*queue
,
3173 struct spoolss_PrinterInfo2
*pinfo2
,
3174 TALLOC_CTX
*mem_ctx
)
3176 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, 0);
3179 /*******************************************************************
3180 * fill a notify_info_data with job size
3181 ********************************************************************/
3183 static void spoolss_notify_job_size(struct messaging_context
*msg_ctx
,
3185 struct spoolss_Notify
*data
,
3186 print_queue_struct
*queue
,
3187 struct spoolss_PrinterInfo2
*pinfo2
,
3188 TALLOC_CTX
*mem_ctx
)
3190 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, queue
->size
);
3193 /*******************************************************************
3194 * fill a notify_info_data with page info
3195 ********************************************************************/
3196 static void spoolss_notify_total_pages(struct messaging_context
*msg_ctx
,
3198 struct spoolss_Notify
*data
,
3199 print_queue_struct
*queue
,
3200 struct spoolss_PrinterInfo2
*pinfo2
,
3201 TALLOC_CTX
*mem_ctx
)
3203 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, queue
->page_count
);
3206 /*******************************************************************
3207 * fill a notify_info_data with pages printed info.
3208 ********************************************************************/
3209 static void spoolss_notify_pages_printed(struct messaging_context
*msg_ctx
,
3211 struct spoolss_Notify
*data
,
3212 print_queue_struct
*queue
,
3213 struct spoolss_PrinterInfo2
*pinfo2
,
3214 TALLOC_CTX
*mem_ctx
)
3216 /* Add code when back-end tracks this */
3217 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, 0);
3220 /*******************************************************************
3221 Fill a notify_info_data with job position.
3222 ********************************************************************/
3224 static void spoolss_notify_job_position(struct messaging_context
*msg_ctx
,
3226 struct spoolss_Notify
*data
,
3227 print_queue_struct
*queue
,
3228 struct spoolss_PrinterInfo2
*pinfo2
,
3229 TALLOC_CTX
*mem_ctx
)
3231 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, queue
->job
);
3234 /*******************************************************************
3235 Fill a notify_info_data with submitted time.
3236 ********************************************************************/
3238 static void spoolss_notify_submitted_time(struct messaging_context
*msg_ctx
,
3240 struct spoolss_Notify
*data
,
3241 print_queue_struct
*queue
,
3242 struct spoolss_PrinterInfo2
*pinfo2
,
3243 TALLOC_CTX
*mem_ctx
)
3245 data
->data
.string
.string
= NULL
;
3246 data
->data
.string
.size
= 0;
3248 init_systemtime_buffer(mem_ctx
, gmtime(&queue
->time
),
3249 &data
->data
.string
.string
,
3250 &data
->data
.string
.size
);
3254 struct s_notify_info_data_table
3256 enum spoolss_NotifyType type
;
3259 enum spoolss_NotifyTable variable_type
;
3260 void (*fn
) (struct messaging_context
*msg_ctx
,
3261 int snum
, struct spoolss_Notify
*data
,
3262 print_queue_struct
*queue
,
3263 struct spoolss_PrinterInfo2
*pinfo2
,
3264 TALLOC_CTX
*mem_ctx
);
3267 /* A table describing the various print notification constants and
3268 whether the notification data is a pointer to a variable sized
3269 buffer, a one value uint32_t or a two value uint32_t. */
3271 static const struct s_notify_info_data_table notify_info_data_table
[] =
3273 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_SERVER_NAME
, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_server_name
},
3274 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PRINTER_NAME
, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_printer_name
},
3275 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_SHARE_NAME
, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_share_name
},
3276 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PORT_NAME
, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_port_name
},
3277 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_DRIVER_NAME
, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_driver_name
},
3278 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_COMMENT
, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING
, spoolss_notify_comment
},
3279 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_LOCATION
, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING
, spoolss_notify_location
},
3280 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_DEVMODE
, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE
, spoolss_notify_devmode
},
3281 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_SEPFILE
, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING
, spoolss_notify_sepfile
},
3282 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR
, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING
, spoolss_notify_print_processor
},
3283 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PARAMETERS
, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING
, spoolss_notify_parameters
},
3284 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_DATATYPE
, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING
, spoolss_notify_datatype
},
3285 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR
, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR
, spoolss_notify_security_desc
},
3286 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_ATTRIBUTES
, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD
, spoolss_notify_attributes
},
3287 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PRIORITY
, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD
, spoolss_notify_priority
},
3288 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY
, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD
, spoolss_notify_default_priority
},
3289 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_START_TIME
, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_start_time
},
3290 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_UNTIL_TIME
, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_until_time
},
3291 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_STATUS
, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD
, spoolss_notify_status
},
3292 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_STATUS_STRING
, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING
, NULL
},
3293 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_CJOBS
, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD
, spoolss_notify_cjobs
},
3294 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_AVERAGE_PPM
, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD
, spoolss_notify_average_ppm
},
3295 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_TOTAL_PAGES
, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD
, NULL
},
3296 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PAGES_PRINTED
, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD
, NULL
},
3297 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_TOTAL_BYTES
, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD
, NULL
},
3298 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_BYTES_PRINTED
, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD
, NULL
},
3299 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PRINTER_NAME
, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_printer_name
},
3300 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_MACHINE_NAME
, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_server_name
},
3301 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PORT_NAME
, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_port_name
},
3302 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_USER_NAME
, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_username
},
3303 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_NOTIFY_NAME
, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_username
},
3304 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_DATATYPE
, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING
, spoolss_notify_datatype
},
3305 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PRINT_PROCESSOR
, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING
, spoolss_notify_print_processor
},
3306 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PARAMETERS
, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING
, spoolss_notify_parameters
},
3307 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_DRIVER_NAME
, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_driver_name
},
3308 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_DEVMODE
, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE
, spoolss_notify_devmode
},
3309 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_STATUS
, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD
, spoolss_notify_job_status
},
3310 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_STATUS_STRING
, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING
, spoolss_notify_job_status_string
},
3311 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR
, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR
, NULL
},
3312 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_DOCUMENT
, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING
, spoolss_notify_job_name
},
3313 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PRIORITY
, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD
, spoolss_notify_priority
},
3314 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_POSITION
, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD
, spoolss_notify_job_position
},
3315 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_SUBMITTED
, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME
, spoolss_notify_submitted_time
},
3316 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_START_TIME
, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_start_time
},
3317 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_UNTIL_TIME
, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_until_time
},
3318 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_TIME
, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_job_time
},
3319 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_TOTAL_PAGES
, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD
, spoolss_notify_total_pages
},
3320 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PAGES_PRINTED
, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD
, spoolss_notify_pages_printed
},
3321 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_TOTAL_BYTES
, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD
, spoolss_notify_job_size
},
3324 /*******************************************************************
3325 Return the variable_type of info_data structure.
3326 ********************************************************************/
3328 static enum spoolss_NotifyTable
variable_type_of_notify_info_data(enum spoolss_NotifyType type
,
3333 for (i
= 0; i
< ARRAY_SIZE(notify_info_data_table
); i
++) {
3334 if ( (notify_info_data_table
[i
].type
== type
) &&
3335 (notify_info_data_table
[i
].field
== field
) ) {
3336 return notify_info_data_table
[i
].variable_type
;
3340 DEBUG(5, ("invalid notify data type %d/%d\n", type
, field
));
3342 return (enum spoolss_NotifyTable
) 0;
3345 /****************************************************************************
3346 ****************************************************************************/
3348 static bool search_notify(enum spoolss_NotifyType type
,
3354 for (i
= 0; i
< ARRAY_SIZE(notify_info_data_table
); i
++) {
3355 if (notify_info_data_table
[i
].type
== type
&&
3356 notify_info_data_table
[i
].field
== field
&&
3357 notify_info_data_table
[i
].fn
!= NULL
) {
3366 /****************************************************************************
3367 ****************************************************************************/
3369 static void construct_info_data(struct spoolss_Notify
*info_data
,
3370 enum spoolss_NotifyType type
,
3371 uint16_t field
, int id
)
3373 info_data
->type
= type
;
3374 info_data
->field
.field
= field
;
3375 info_data
->variable_type
= variable_type_of_notify_info_data(type
, field
);
3376 info_data
->job_id
= id
;
3379 /*******************************************************************
3381 * fill a notify_info struct with info asked
3383 ********************************************************************/
3385 static bool construct_notify_printer_info(struct messaging_context
*msg_ctx
,
3386 struct printer_handle
*print_hnd
,
3387 struct spoolss_NotifyInfo
*info
,
3388 struct spoolss_PrinterInfo2
*pinfo2
,
3390 const struct spoolss_NotifyOptionType
*option_type
,
3392 TALLOC_CTX
*mem_ctx
)
3395 enum spoolss_NotifyType type
;
3398 struct spoolss_Notify
*current_data
;
3400 type
= option_type
->type
;
3402 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3403 (type
== PRINTER_NOTIFY_TYPE
? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3404 option_type
->count
, lp_servicename(snum
)));
3406 for(field_num
=0; field_num
< option_type
->count
; field_num
++) {
3407 field
= option_type
->fields
[field_num
].field
;
3409 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num
, type
, field
));
3411 if (!search_notify(type
, field
, &j
) )
3414 info
->notifies
= talloc_realloc(info
, info
->notifies
,
3415 struct spoolss_Notify
,
3417 if (info
->notifies
== NULL
) {
3418 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3422 current_data
= &info
->notifies
[info
->count
];
3424 construct_info_data(current_data
, type
, field
, id
);
3426 DEBUG(10, ("construct_notify_printer_info: "
3427 "calling [%s] snum=%d printername=[%s])\n",
3428 notify_info_data_table
[j
].name
, snum
,
3429 pinfo2
->printername
));
3431 notify_info_data_table
[j
].fn(msg_ctx
, snum
, current_data
,
3432 NULL
, pinfo2
, mem_ctx
);
3440 /*******************************************************************
3442 * fill a notify_info struct with info asked
3444 ********************************************************************/
3446 static bool construct_notify_jobs_info(struct messaging_context
*msg_ctx
,
3447 print_queue_struct
*queue
,
3448 struct spoolss_NotifyInfo
*info
,
3449 struct spoolss_PrinterInfo2
*pinfo2
,
3451 const struct spoolss_NotifyOptionType
*option_type
,
3453 TALLOC_CTX
*mem_ctx
)
3456 enum spoolss_NotifyType type
;
3458 struct spoolss_Notify
*current_data
;
3460 DEBUG(4,("construct_notify_jobs_info\n"));
3462 type
= option_type
->type
;
3464 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3465 (type
== PRINTER_NOTIFY_TYPE
? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3466 option_type
->count
));
3468 for(field_num
=0; field_num
<option_type
->count
; field_num
++) {
3469 field
= option_type
->fields
[field_num
].field
;
3471 if (!search_notify(type
, field
, &j
) )
3474 info
->notifies
= talloc_realloc(info
, info
->notifies
,
3475 struct spoolss_Notify
,
3477 if (info
->notifies
== NULL
) {
3478 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3482 current_data
=&(info
->notifies
[info
->count
]);
3484 construct_info_data(current_data
, type
, field
, id
);
3485 notify_info_data_table
[j
].fn(msg_ctx
, snum
, current_data
,
3486 queue
, pinfo2
, mem_ctx
);
3494 * JFM: The enumeration is not that simple, it's even non obvious.
3496 * let's take an example: I want to monitor the PRINTER SERVER for
3497 * the printer's name and the number of jobs currently queued.
3498 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3499 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3501 * I have 3 printers on the back of my server.
3503 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3506 * 1 printer 1 name 1
3507 * 2 printer 1 cjob 1
3508 * 3 printer 2 name 2
3509 * 4 printer 2 cjob 2
3510 * 5 printer 3 name 3
3511 * 6 printer 3 name 3
3513 * that's the print server case, the printer case is even worse.
3516 /*******************************************************************
3518 * enumerate all printers on the printserver
3519 * fill a notify_info struct with info asked
3521 ********************************************************************/
3523 static WERROR
printserver_notify_info(struct pipes_struct
*p
,
3524 struct policy_handle
*hnd
,
3525 struct spoolss_NotifyInfo
*info
,
3526 TALLOC_CTX
*mem_ctx
)
3529 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, hnd
);
3530 int n_services
=lp_numservices();
3532 struct spoolss_NotifyOption
*option
;
3533 struct spoolss_NotifyOptionType option_type
;
3534 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
3537 DEBUG(4,("printserver_notify_info\n"));
3542 option
= Printer
->notify
.option
;
3545 info
->notifies
= NULL
;
3548 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3549 sending a ffpcn() request first */
3554 for (i
=0; i
<option
->count
; i
++) {
3555 option_type
= option
->types
[i
];
3557 if (option_type
.type
!= PRINTER_NOTIFY_TYPE
)
3560 for (snum
= 0; snum
< n_services
; snum
++) {
3561 if (!lp_browseable(snum
) ||
3562 !lp_snum_ok(snum
) ||
3563 !lp_print_ok(snum
)) {
3564 continue; /* skip */
3567 /* Maybe we should use the SYSTEM session_info here... */
3568 result
= winreg_get_printer_internal(mem_ctx
,
3569 get_session_info_system(),
3571 lp_servicename(snum
),
3573 if (!W_ERROR_IS_OK(result
)) {
3574 DEBUG(4, ("printserver_notify_info: "
3575 "Failed to get printer [%s]\n",
3576 lp_servicename(snum
)));
3581 construct_notify_printer_info(p
->msg_ctx
,
3587 TALLOC_FREE(pinfo2
);
3593 * Debugging information, don't delete.
3596 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3597 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info
->version
, info
->flags
, info
->count
));
3598 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3600 for (i
=0; i
<info
->count
; i
++) {
3601 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3602 i
, info
->data
[i
].type
, info
->data
[i
].field
, info
->data
[i
].reserved
,
3603 info
->data
[i
].id
, info
->data
[i
].size
, info
->data
[i
].enc_type
));
3610 /*******************************************************************
3612 * fill a notify_info struct with info asked
3614 ********************************************************************/
3616 static WERROR
printer_notify_info(struct pipes_struct
*p
,
3617 struct policy_handle
*hnd
,
3618 struct spoolss_NotifyInfo
*info
,
3619 TALLOC_CTX
*mem_ctx
)
3622 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, hnd
);
3625 struct spoolss_NotifyOption
*option
;
3626 struct spoolss_NotifyOptionType option_type
;
3628 print_queue_struct
*queue
=NULL
;
3629 print_status_struct status
;
3630 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
3633 DEBUG(4,("printer_notify_info\n"));
3638 option
= Printer
->notify
.option
;
3642 info
->notifies
= NULL
;
3645 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3646 sending a ffpcn() request first */
3651 if (!get_printer_snum(p
, hnd
, &snum
, NULL
)) {
3655 /* Maybe we should use the SYSTEM session_info here... */
3656 result
= winreg_get_printer_internal(mem_ctx
,
3657 get_session_info_system(),
3659 lp_servicename(snum
), &pinfo2
);
3660 if (!W_ERROR_IS_OK(result
)) {
3665 * When sending a PRINTER_NOTIFY_FIELD_SERVER_NAME we should send the
3666 * correct servername.
3668 pinfo2
->servername
= talloc_strdup(pinfo2
, Printer
->servername
);
3669 if (pinfo2
->servername
== NULL
) {
3673 for (i
=0; i
<option
->count
; i
++) {
3674 option_type
= option
->types
[i
];
3676 switch (option_type
.type
) {
3677 case PRINTER_NOTIFY_TYPE
:
3678 if (construct_notify_printer_info(p
->msg_ctx
,
3687 case JOB_NOTIFY_TYPE
:
3689 count
= print_queue_status(p
->msg_ctx
, snum
, &queue
,
3692 for (j
=0; j
<count
; j
++) {
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
);
3725 /****************************************************************
3726 _spoolss_RouterRefreshPrinterChangeNotify
3727 ****************************************************************/
3729 WERROR
_spoolss_RouterRefreshPrinterChangeNotify(struct pipes_struct
*p
,
3730 struct spoolss_RouterRefreshPrinterChangeNotify
*r
)
3732 struct spoolss_NotifyInfo
*info
;
3734 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
3735 WERROR result
= WERR_BADFID
;
3737 /* we always have a spoolss_NotifyInfo struct */
3738 info
= talloc_zero(p
->mem_ctx
, struct spoolss_NotifyInfo
);
3740 result
= WERR_NOMEM
;
3744 *r
->out
.info
= info
;
3747 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3748 "Invalid handle (%s:%u:%u).\n",
3749 OUR_HANDLE(r
->in
.handle
)));
3753 DEBUG(4,("Printer type %x\n",Printer
->printer_type
));
3756 * We are now using the change value, and
3757 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3758 * I don't have a global notification system, I'm sending back all the
3759 * information even when _NOTHING_ has changed.
3762 /* We need to keep track of the change value to send back in
3763 RRPCN replies otherwise our updates are ignored. */
3765 Printer
->notify
.fnpcn
= true;
3767 if (Printer
->notify
.cli_chan
!= NULL
&&
3768 Printer
->notify
.cli_chan
->active_connections
> 0) {
3769 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3770 "Saving change value in request [%x]\n",
3772 Printer
->notify
.change
= r
->in
.change_low
;
3775 /* just ignore the spoolss_NotifyOption */
3777 switch (Printer
->printer_type
) {
3779 result
= printserver_notify_info(p
, r
->in
.handle
,
3783 case SPLHND_PRINTER
:
3784 result
= printer_notify_info(p
, r
->in
.handle
,
3789 Printer
->notify
.fnpcn
= false;
3795 /********************************************************************
3796 ********************************************************************/
3798 static WERROR
create_printername(TALLOC_CTX
*mem_ctx
,
3799 const char *servername
,
3800 const char *printername
,
3801 const char **printername_p
)
3803 /* FIXME: add lp_force_printername() */
3805 if (servername
== NULL
) {
3806 *printername_p
= talloc_strdup(mem_ctx
, printername
);
3807 W_ERROR_HAVE_NO_MEMORY(*printername_p
);
3811 if (servername
[0] == '\\' && servername
[1] == '\\') {
3815 *printername_p
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s", servername
, printername
);
3816 W_ERROR_HAVE_NO_MEMORY(*printername_p
);
3821 /********************************************************************
3822 ********************************************************************/
3824 static void compose_devicemode_devicename(struct spoolss_DeviceMode
*dm
,
3825 const char *printername
)
3831 dm
->devicename
= talloc_strndup(dm
, printername
,
3832 MIN(strlen(printername
), 31));
3835 /********************************************************************
3836 * construct_printer_info_0
3837 * fill a printer_info_0 struct
3838 ********************************************************************/
3840 static WERROR
construct_printer_info0(TALLOC_CTX
*mem_ctx
,
3841 const struct auth_session_info
*session_info
,
3842 struct messaging_context
*msg_ctx
,
3843 struct spoolss_PrinterInfo2
*info2
,
3844 const char *servername
,
3845 struct spoolss_PrinterInfo0
*r
,
3849 struct printer_session_counter
*session_counter
;
3850 struct timeval setuptime
;
3851 print_status_struct status
;
3854 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->printername
);
3855 if (!W_ERROR_IS_OK(result
)) {
3860 r
->servername
= talloc_strdup(mem_ctx
, servername
);
3861 W_ERROR_HAVE_NO_MEMORY(r
->servername
);
3863 r
->servername
= NULL
;
3866 count
= print_queue_length(msg_ctx
, snum
, &status
);
3868 /* check if we already have a counter for this printer */
3869 for (session_counter
= counter_list
; session_counter
; session_counter
= session_counter
->next
) {
3870 if (session_counter
->snum
== snum
)
3874 /* it's the first time, add it to the list */
3875 if (session_counter
== NULL
) {
3876 session_counter
= talloc_zero(counter_list
, struct printer_session_counter
);
3877 W_ERROR_HAVE_NO_MEMORY(session_counter
);
3878 session_counter
->snum
= snum
;
3879 session_counter
->counter
= 0;
3880 DLIST_ADD(counter_list
, session_counter
);
3884 session_counter
->counter
++;
3890 get_startup_time(&setuptime
);
3891 init_systemtime(&r
->time
, gmtime(&setuptime
.tv_sec
));
3894 * the global_counter should be stored in a TDB as it's common to all the clients
3895 * and should be zeroed on samba startup
3897 r
->global_counter
= session_counter
->counter
;
3899 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3900 SSVAL(&r
->version
, 0, 0x0005); /* NT 5 */
3901 SSVAL(&r
->version
, 2, 0x0893); /* build 2195 */
3902 r
->free_build
= SPOOLSS_RELEASE_BUILD
;
3904 r
->max_spooling
= 0;
3905 r
->session_counter
= session_counter
->counter
;
3906 r
->num_error_out_of_paper
= 0x0;
3907 r
->num_error_not_ready
= 0x0; /* number of print failure */
3909 r
->number_of_processors
= 0x1;
3910 r
->processor_type
= PROCESSOR_INTEL_PENTIUM
; /* 586 Pentium ? */
3911 r
->high_part_total_bytes
= 0x0;
3913 /* ChangeID in milliseconds*/
3914 winreg_printer_get_changeid_internal(mem_ctx
, session_info
, msg_ctx
,
3915 info2
->sharename
, &r
->change_id
);
3917 r
->last_error
= WERR_OK
;
3918 r
->status
= nt_printq_status(status
.status
);
3919 r
->enumerate_network_printers
= 0x0;
3920 r
->c_setprinter
= 0x0;
3921 r
->processor_architecture
= PROCESSOR_ARCHITECTURE_INTEL
;
3922 r
->processor_level
= 0x6; /* 6 ???*/
3931 /********************************************************************
3932 * construct_printer_info1
3933 * fill a spoolss_PrinterInfo1 struct
3934 ********************************************************************/
3936 static WERROR
construct_printer_info1(TALLOC_CTX
*mem_ctx
,
3937 const struct spoolss_PrinterInfo2
*info2
,
3939 const char *servername
,
3940 struct spoolss_PrinterInfo1
*r
,
3947 if (info2
->comment
== NULL
|| info2
->comment
[0] == '\0') {
3948 r
->comment
= talloc_strdup(mem_ctx
, lp_comment(snum
));
3950 r
->comment
= talloc_strdup(mem_ctx
, info2
->comment
); /* saved comment */
3952 W_ERROR_HAVE_NO_MEMORY(r
->comment
);
3954 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->name
);
3955 if (!W_ERROR_IS_OK(result
)) {
3959 r
->description
= talloc_asprintf(mem_ctx
, "%s,%s,%s",
3963 W_ERROR_HAVE_NO_MEMORY(r
->description
);
3968 /********************************************************************
3969 * construct_printer_info2
3970 * fill a spoolss_PrinterInfo2 struct
3971 ********************************************************************/
3973 static WERROR
construct_printer_info2(TALLOC_CTX
*mem_ctx
,
3974 struct messaging_context
*msg_ctx
,
3975 const struct spoolss_PrinterInfo2
*info2
,
3976 const char *servername
,
3977 struct spoolss_PrinterInfo2
*r
,
3981 print_status_struct status
;
3984 count
= print_queue_length(msg_ctx
, snum
, &status
);
3987 r
->servername
= talloc_strdup(mem_ctx
, servername
);
3988 W_ERROR_HAVE_NO_MEMORY(r
->servername
);
3990 r
->servername
= NULL
;
3993 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->printername
);
3994 if (!W_ERROR_IS_OK(result
)) {
3998 r
->sharename
= talloc_strdup(mem_ctx
, lp_servicename(snum
));
3999 W_ERROR_HAVE_NO_MEMORY(r
->sharename
);
4000 r
->portname
= talloc_strdup(mem_ctx
, info2
->portname
);
4001 W_ERROR_HAVE_NO_MEMORY(r
->portname
);
4002 r
->drivername
= talloc_strdup(mem_ctx
, info2
->drivername
);
4003 W_ERROR_HAVE_NO_MEMORY(r
->drivername
);
4005 if (info2
->comment
[0] == '\0') {
4006 r
->comment
= talloc_strdup(mem_ctx
, lp_comment(snum
));
4008 r
->comment
= talloc_strdup(mem_ctx
, info2
->comment
);
4010 W_ERROR_HAVE_NO_MEMORY(r
->comment
);
4012 r
->location
= talloc_strdup(mem_ctx
, info2
->location
);
4013 if (info2
->location
[0] == '\0') {
4014 const char *loc
= NULL
;
4017 nt_status
= printer_list_get_printer(mem_ctx
,
4022 if (NT_STATUS_IS_OK(nt_status
)) {
4024 r
->location
= talloc_strdup(mem_ctx
, loc
);
4028 W_ERROR_HAVE_NO_MEMORY(r
->location
);
4030 r
->sepfile
= talloc_strdup(mem_ctx
, info2
->sepfile
);
4031 W_ERROR_HAVE_NO_MEMORY(r
->sepfile
);
4032 r
->printprocessor
= talloc_strdup(mem_ctx
, info2
->printprocessor
);
4033 W_ERROR_HAVE_NO_MEMORY(r
->printprocessor
);
4034 r
->datatype
= talloc_strdup(mem_ctx
, info2
->datatype
);
4035 W_ERROR_HAVE_NO_MEMORY(r
->datatype
);
4036 r
->parameters
= talloc_strdup(mem_ctx
, info2
->parameters
);
4037 W_ERROR_HAVE_NO_MEMORY(r
->parameters
);
4039 r
->attributes
= info2
->attributes
;
4041 r
->priority
= info2
->priority
;
4042 r
->defaultpriority
= info2
->defaultpriority
;
4043 r
->starttime
= info2
->starttime
;
4044 r
->untiltime
= info2
->untiltime
;
4045 r
->status
= nt_printq_status(status
.status
);
4047 r
->averageppm
= info2
->averageppm
;
4049 copy_devicemode(mem_ctx
, info2
->devmode
, &r
->devmode
);
4051 DEBUG(8,("Returning NULL Devicemode!\n"));
4054 compose_devicemode_devicename(r
->devmode
, r
->printername
);
4058 if (info2
->secdesc
!= NULL
) {
4059 /* don't use talloc_steal() here unless you do a deep steal of all
4060 the SEC_DESC members */
4062 r
->secdesc
= dup_sec_desc(mem_ctx
, info2
->secdesc
);
4068 /********************************************************************
4069 * construct_printer_info3
4070 * fill a spoolss_PrinterInfo3 struct
4071 ********************************************************************/
4073 static WERROR
construct_printer_info3(TALLOC_CTX
*mem_ctx
,
4074 const struct spoolss_PrinterInfo2
*info2
,
4075 const char *servername
,
4076 struct spoolss_PrinterInfo3
*r
,
4079 /* These are the components of the SD we are returning. */
4081 if (info2
->secdesc
!= NULL
) {
4082 /* don't use talloc_steal() here unless you do a deep steal of all
4083 the SEC_DESC members */
4085 r
->secdesc
= dup_sec_desc(mem_ctx
, info2
->secdesc
);
4086 W_ERROR_HAVE_NO_MEMORY(r
->secdesc
);
4092 /********************************************************************
4093 * construct_printer_info4
4094 * fill a spoolss_PrinterInfo4 struct
4095 ********************************************************************/
4097 static WERROR
construct_printer_info4(TALLOC_CTX
*mem_ctx
,
4098 const struct spoolss_PrinterInfo2
*info2
,
4099 const char *servername
,
4100 struct spoolss_PrinterInfo4
*r
,
4105 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->printername
);
4106 if (!W_ERROR_IS_OK(result
)) {
4111 r
->servername
= talloc_strdup(mem_ctx
, servername
);
4112 W_ERROR_HAVE_NO_MEMORY(r
->servername
);
4114 r
->servername
= NULL
;
4117 r
->attributes
= info2
->attributes
;
4122 /********************************************************************
4123 * construct_printer_info5
4124 * fill a spoolss_PrinterInfo5 struct
4125 ********************************************************************/
4127 static WERROR
construct_printer_info5(TALLOC_CTX
*mem_ctx
,
4128 const struct spoolss_PrinterInfo2
*info2
,
4129 const char *servername
,
4130 struct spoolss_PrinterInfo5
*r
,
4135 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->printername
);
4136 if (!W_ERROR_IS_OK(result
)) {
4140 r
->portname
= talloc_strdup(mem_ctx
, info2
->portname
);
4141 W_ERROR_HAVE_NO_MEMORY(r
->portname
);
4143 r
->attributes
= info2
->attributes
;
4145 /* these two are not used by NT+ according to MSDN */
4146 r
->device_not_selected_timeout
= 0x0; /* have seen 0x3a98 */
4147 r
->transmission_retry_timeout
= 0x0; /* have seen 0xafc8 */
4152 /********************************************************************
4153 * construct_printer_info_6
4154 * fill a spoolss_PrinterInfo6 struct
4155 ********************************************************************/
4157 static WERROR
construct_printer_info6(TALLOC_CTX
*mem_ctx
,
4158 struct messaging_context
*msg_ctx
,
4159 const struct spoolss_PrinterInfo2
*info2
,
4160 const char *servername
,
4161 struct spoolss_PrinterInfo6
*r
,
4164 print_status_struct status
;
4166 print_queue_length(msg_ctx
, snum
, &status
);
4168 r
->status
= nt_printq_status(status
.status
);
4173 /********************************************************************
4174 * construct_printer_info7
4175 * fill a spoolss_PrinterInfo7 struct
4176 ********************************************************************/
4178 static WERROR
construct_printer_info7(TALLOC_CTX
*mem_ctx
,
4179 struct messaging_context
*msg_ctx
,
4180 const char *servername
,
4181 struct spoolss_PrinterInfo7
*r
,
4184 const struct auth_session_info
*session_info
= get_session_info_system();
4187 if (is_printer_published(mem_ctx
, session_info
, msg_ctx
,
4189 lp_servicename(snum
), &guid
, NULL
)) {
4190 r
->guid
= talloc_strdup_upper(mem_ctx
, GUID_string2(mem_ctx
, &guid
));
4191 r
->action
= DSPRINT_PUBLISH
;
4193 r
->guid
= talloc_strdup(mem_ctx
, "");
4194 r
->action
= DSPRINT_UNPUBLISH
;
4196 W_ERROR_HAVE_NO_MEMORY(r
->guid
);
4201 /********************************************************************
4202 * construct_printer_info8
4203 * fill a spoolss_PrinterInfo8 struct
4204 ********************************************************************/
4206 static WERROR
construct_printer_info8(TALLOC_CTX
*mem_ctx
,
4207 const struct spoolss_PrinterInfo2
*info2
,
4208 const char *servername
,
4209 struct spoolss_DeviceModeInfo
*r
,
4213 const char *printername
;
4215 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &printername
);
4216 if (!W_ERROR_IS_OK(result
)) {
4220 copy_devicemode(mem_ctx
, info2
->devmode
, &r
->devmode
);
4222 DEBUG(8,("Returning NULL Devicemode!\n"));
4225 compose_devicemode_devicename(r
->devmode
, printername
);
4231 /********************************************************************
4232 ********************************************************************/
4234 static bool snum_is_shared_printer(int snum
)
4236 return (lp_browseable(snum
) && lp_snum_ok(snum
) && lp_print_ok(snum
));
4239 /********************************************************************
4240 Spoolss_enumprinters.
4241 ********************************************************************/
4243 static WERROR
enum_all_printers_info_level(TALLOC_CTX
*mem_ctx
,
4244 const struct auth_session_info
*session_info
,
4245 struct messaging_context
*msg_ctx
,
4246 const char *servername
,
4249 union spoolss_PrinterInfo
**info_p
,
4253 int n_services
= lp_numservices();
4254 union spoolss_PrinterInfo
*info
= NULL
;
4256 WERROR result
= WERR_OK
;
4257 struct dcerpc_binding_handle
*b
= NULL
;
4258 TALLOC_CTX
*tmp_ctx
= NULL
;
4260 tmp_ctx
= talloc_new(mem_ctx
);
4268 for (snum
= 0; snum
< n_services
; snum
++) {
4270 const char *printer
;
4271 struct spoolss_PrinterInfo2
*info2
;
4273 if (!snum_is_shared_printer(snum
)) {
4277 printer
= lp_const_servicename(snum
);
4279 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
4283 result
= winreg_printer_binding_handle(tmp_ctx
,
4287 if (!W_ERROR_IS_OK(result
)) {
4292 result
= winreg_create_printer(tmp_ctx
, b
,
4294 if (!W_ERROR_IS_OK(result
)) {
4298 info
= talloc_realloc(tmp_ctx
, info
,
4299 union spoolss_PrinterInfo
,
4302 result
= WERR_NOMEM
;
4306 result
= winreg_get_printer(tmp_ctx
, b
,
4308 if (!W_ERROR_IS_OK(result
)) {
4314 result
= construct_printer_info0(info
, session_info
,
4317 &info
[count
].info0
, snum
);
4320 result
= construct_printer_info1(info
, info2
, flags
,
4322 &info
[count
].info1
, snum
);
4325 result
= construct_printer_info2(info
, msg_ctx
, info2
,
4327 &info
[count
].info2
, snum
);
4330 result
= construct_printer_info4(info
, info2
,
4332 &info
[count
].info4
, snum
);
4335 result
= construct_printer_info5(info
, info2
,
4337 &info
[count
].info5
, snum
);
4341 result
= WERR_UNKNOWN_LEVEL
;
4345 if (!W_ERROR_IS_OK(result
)) {
4353 if (W_ERROR_IS_OK(result
)) {
4354 *info_p
= talloc_move(mem_ctx
, &info
);
4358 talloc_free(tmp_ctx
);
4363 /********************************************************************
4364 * handle enumeration of printers at level 0
4365 ********************************************************************/
4367 static WERROR
enumprinters_level0(TALLOC_CTX
*mem_ctx
,
4368 const struct auth_session_info
*session_info
,
4369 struct messaging_context
*msg_ctx
,
4371 const char *servername
,
4372 union spoolss_PrinterInfo
**info
,
4375 DEBUG(4,("enum_all_printers_info_0\n"));
4377 return enum_all_printers_info_level(mem_ctx
, session_info
, msg_ctx
,
4378 servername
, 0, flags
, info
, count
);
4382 /********************************************************************
4383 ********************************************************************/
4385 static WERROR
enum_all_printers_info_1(TALLOC_CTX
*mem_ctx
,
4386 const struct auth_session_info
*session_info
,
4387 struct messaging_context
*msg_ctx
,
4388 const char *servername
,
4390 union spoolss_PrinterInfo
**info
,
4393 DEBUG(4,("enum_all_printers_info_1\n"));
4395 return enum_all_printers_info_level(mem_ctx
, session_info
, msg_ctx
,
4396 servername
, 1, flags
, info
, count
);
4399 /********************************************************************
4400 enum_all_printers_info_1_local.
4401 *********************************************************************/
4403 static WERROR
enum_all_printers_info_1_local(TALLOC_CTX
*mem_ctx
,
4404 const struct auth_session_info
*session_info
,
4405 struct messaging_context
*msg_ctx
,
4406 const char *servername
,
4407 union spoolss_PrinterInfo
**info
,
4410 DEBUG(4,("enum_all_printers_info_1_local\n"));
4412 return enum_all_printers_info_1(mem_ctx
, session_info
, msg_ctx
,
4413 servername
, PRINTER_ENUM_ICON8
, info
, count
);
4416 /********************************************************************
4417 enum_all_printers_info_1_name.
4418 *********************************************************************/
4420 static WERROR
enum_all_printers_info_1_name(TALLOC_CTX
*mem_ctx
,
4421 const struct auth_session_info
*session_info
,
4422 struct messaging_context
*msg_ctx
,
4423 const char *servername
,
4424 union spoolss_PrinterInfo
**info
,
4427 const char *s
= servername
;
4429 DEBUG(4,("enum_all_printers_info_1_name\n"));
4431 if ((servername
[0] == '\\') && (servername
[1] == '\\')) {
4435 if (!is_myname_or_ipaddr(s
)) {
4436 return WERR_INVALID_NAME
;
4439 return enum_all_printers_info_1(mem_ctx
, session_info
, msg_ctx
,
4440 servername
, PRINTER_ENUM_ICON8
, info
, count
);
4443 /********************************************************************
4444 enum_all_printers_info_1_network.
4445 *********************************************************************/
4447 static WERROR
enum_all_printers_info_1_network(TALLOC_CTX
*mem_ctx
,
4448 const struct auth_session_info
*session_info
,
4449 struct messaging_context
*msg_ctx
,
4450 const char *servername
,
4451 union spoolss_PrinterInfo
**info
,
4454 const char *s
= servername
;
4456 DEBUG(4,("enum_all_printers_info_1_network\n"));
4458 /* If we respond to a enum_printers level 1 on our name with flags
4459 set to PRINTER_ENUM_REMOTE with a list of printers then these
4460 printers incorrectly appear in the APW browse list.
4461 Specifically the printers for the server appear at the workgroup
4462 level where all the other servers in the domain are
4463 listed. Windows responds to this call with a
4464 WERR_CAN_NOT_COMPLETE so we should do the same. */
4466 if (servername
[0] == '\\' && servername
[1] == '\\') {
4470 if (is_myname_or_ipaddr(s
)) {
4471 return WERR_CAN_NOT_COMPLETE
;
4474 return enum_all_printers_info_1(mem_ctx
, session_info
, msg_ctx
,
4475 servername
, PRINTER_ENUM_NAME
, info
, count
);
4478 /********************************************************************
4479 * api_spoolss_enumprinters
4481 * called from api_spoolss_enumprinters (see this to understand)
4482 ********************************************************************/
4484 static WERROR
enum_all_printers_info_2(TALLOC_CTX
*mem_ctx
,
4485 const struct auth_session_info
*session_info
,
4486 struct messaging_context
*msg_ctx
,
4487 const char *servername
,
4488 union spoolss_PrinterInfo
**info
,
4491 DEBUG(4,("enum_all_printers_info_2\n"));
4493 return enum_all_printers_info_level(mem_ctx
, session_info
, msg_ctx
,
4494 servername
, 2, 0, info
, count
);
4497 /********************************************************************
4498 * handle enumeration of printers at level 1
4499 ********************************************************************/
4501 static WERROR
enumprinters_level1(TALLOC_CTX
*mem_ctx
,
4502 const struct auth_session_info
*session_info
,
4503 struct messaging_context
*msg_ctx
,
4505 const char *servername
,
4506 union spoolss_PrinterInfo
**info
,
4509 /* Not all the flags are equals */
4511 if (flags
& PRINTER_ENUM_LOCAL
) {
4512 return enum_all_printers_info_1_local(mem_ctx
, session_info
,
4513 msg_ctx
, servername
, info
, count
);
4516 if (flags
& PRINTER_ENUM_NAME
) {
4517 return enum_all_printers_info_1_name(mem_ctx
, session_info
,
4518 msg_ctx
, servername
, info
,
4522 if (flags
& PRINTER_ENUM_NETWORK
) {
4523 return enum_all_printers_info_1_network(mem_ctx
, session_info
,
4524 msg_ctx
, servername
, info
,
4528 return WERR_OK
; /* NT4sp5 does that */
4531 /********************************************************************
4532 * handle enumeration of printers at level 2
4533 ********************************************************************/
4535 static WERROR
enumprinters_level2(TALLOC_CTX
*mem_ctx
,
4536 const struct auth_session_info
*session_info
,
4537 struct messaging_context
*msg_ctx
,
4539 const char *servername
,
4540 union spoolss_PrinterInfo
**info
,
4543 if (flags
& PRINTER_ENUM_LOCAL
) {
4545 return enum_all_printers_info_2(mem_ctx
, session_info
, msg_ctx
,
4550 if (flags
& PRINTER_ENUM_NAME
) {
4551 if (servername
&& !is_myname_or_ipaddr(canon_servername(servername
))) {
4552 return WERR_INVALID_NAME
;
4555 return enum_all_printers_info_2(mem_ctx
, session_info
, msg_ctx
,
4560 if (flags
& PRINTER_ENUM_REMOTE
) {
4561 return WERR_UNKNOWN_LEVEL
;
4567 /********************************************************************
4568 * handle enumeration of printers at level 4
4569 ********************************************************************/
4571 static WERROR
enumprinters_level4(TALLOC_CTX
*mem_ctx
,
4572 const struct auth_session_info
*session_info
,
4573 struct messaging_context
*msg_ctx
,
4575 const char *servername
,
4576 union spoolss_PrinterInfo
**info
,
4579 DEBUG(4,("enum_all_printers_info_4\n"));
4581 return enum_all_printers_info_level(mem_ctx
, session_info
, msg_ctx
,
4582 servername
, 4, flags
, info
, count
);
4586 /********************************************************************
4587 * handle enumeration of printers at level 5
4588 ********************************************************************/
4590 static WERROR
enumprinters_level5(TALLOC_CTX
*mem_ctx
,
4591 const struct auth_session_info
*session_info
,
4592 struct messaging_context
*msg_ctx
,
4594 const char *servername
,
4595 union spoolss_PrinterInfo
**info
,
4598 DEBUG(4,("enum_all_printers_info_5\n"));
4600 return enum_all_printers_info_level(mem_ctx
, session_info
, msg_ctx
,
4601 servername
, 5, flags
, info
, count
);
4604 /****************************************************************
4605 _spoolss_EnumPrinters
4606 ****************************************************************/
4608 WERROR
_spoolss_EnumPrinters(struct pipes_struct
*p
,
4609 struct spoolss_EnumPrinters
*r
)
4611 const struct auth_session_info
*session_info
= get_session_info_system();
4614 /* that's an [in out] buffer */
4616 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
4617 return WERR_INVALID_PARAM
;
4620 DEBUG(4,("_spoolss_EnumPrinters\n"));
4624 *r
->out
.info
= NULL
;
4628 * flags==PRINTER_ENUM_NAME
4629 * if name=="" then enumerates all printers
4630 * if name!="" then enumerate the printer
4631 * flags==PRINTER_ENUM_REMOTE
4632 * name is NULL, enumerate printers
4633 * Level 2: name!="" enumerates printers, name can't be NULL
4634 * Level 3: doesn't exist
4635 * Level 4: does a local registry lookup
4636 * Level 5: same as Level 2
4639 if (r
->in
.server
&& r
->in
.server
[0] == '\0') {
4640 r
->in
.server
= NULL
;
4643 switch (r
->in
.level
) {
4645 result
= enumprinters_level0(p
->mem_ctx
, session_info
,
4646 p
->msg_ctx
, r
->in
.flags
,
4648 r
->out
.info
, r
->out
.count
);
4651 result
= enumprinters_level1(p
->mem_ctx
, session_info
,
4652 p
->msg_ctx
, r
->in
.flags
,
4654 r
->out
.info
, r
->out
.count
);
4657 result
= enumprinters_level2(p
->mem_ctx
, session_info
,
4658 p
->msg_ctx
, r
->in
.flags
,
4660 r
->out
.info
, r
->out
.count
);
4663 result
= enumprinters_level4(p
->mem_ctx
, session_info
,
4664 p
->msg_ctx
, r
->in
.flags
,
4666 r
->out
.info
, r
->out
.count
);
4669 result
= enumprinters_level5(p
->mem_ctx
, session_info
,
4670 p
->msg_ctx
, r
->in
.flags
,
4672 r
->out
.info
, r
->out
.count
);
4675 return WERR_UNKNOWN_LEVEL
;
4678 if (!W_ERROR_IS_OK(result
)) {
4682 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
4683 spoolss_EnumPrinters
,
4684 *r
->out
.info
, r
->in
.level
,
4686 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
4687 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
4689 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
4692 /****************************************************************
4694 ****************************************************************/
4696 WERROR
_spoolss_GetPrinter(struct pipes_struct
*p
,
4697 struct spoolss_GetPrinter
*r
)
4699 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
4700 struct spoolss_PrinterInfo2
*info2
= NULL
;
4701 WERROR result
= WERR_OK
;
4704 /* that's an [in out] buffer */
4706 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
4707 return WERR_INVALID_PARAM
;
4712 if (Printer
== NULL
) {
4716 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
4720 result
= winreg_get_printer_internal(p
->mem_ctx
,
4721 get_session_info_system(),
4723 lp_const_servicename(snum
),
4725 if (!W_ERROR_IS_OK(result
)) {
4729 switch (r
->in
.level
) {
4731 result
= construct_printer_info0(p
->mem_ctx
,
4732 get_session_info_system(),
4735 Printer
->servername
,
4736 &r
->out
.info
->info0
,
4740 result
= construct_printer_info1(p
->mem_ctx
, info2
,
4742 Printer
->servername
,
4743 &r
->out
.info
->info1
, snum
);
4746 result
= construct_printer_info2(p
->mem_ctx
, p
->msg_ctx
, info2
,
4747 Printer
->servername
,
4748 &r
->out
.info
->info2
, snum
);
4751 result
= construct_printer_info3(p
->mem_ctx
, info2
,
4752 Printer
->servername
,
4753 &r
->out
.info
->info3
, snum
);
4756 result
= construct_printer_info4(p
->mem_ctx
, info2
,
4757 Printer
->servername
,
4758 &r
->out
.info
->info4
, snum
);
4761 result
= construct_printer_info5(p
->mem_ctx
, info2
,
4762 Printer
->servername
,
4763 &r
->out
.info
->info5
, snum
);
4766 result
= construct_printer_info6(p
->mem_ctx
, p
->msg_ctx
, info2
,
4767 Printer
->servername
,
4768 &r
->out
.info
->info6
, snum
);
4771 result
= construct_printer_info7(p
->mem_ctx
, p
->msg_ctx
,
4772 Printer
->servername
,
4773 &r
->out
.info
->info7
, snum
);
4776 result
= construct_printer_info8(p
->mem_ctx
, info2
,
4777 Printer
->servername
,
4778 &r
->out
.info
->info8
, snum
);
4781 result
= WERR_UNKNOWN_LEVEL
;
4787 if (!W_ERROR_IS_OK(result
)) {
4788 DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
4789 r
->in
.level
, win_errstr(result
)));
4790 TALLOC_FREE(r
->out
.info
);
4794 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo
,
4795 r
->out
.info
, r
->in
.level
);
4796 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
4798 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
4801 /********************************************************************
4802 ********************************************************************/
4804 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4806 if (in && strlen(in)) { \
4807 out = talloc_strdup(mem_ctx, in); \
4809 out = talloc_strdup(mem_ctx, ""); \
4811 W_ERROR_HAVE_NO_MEMORY(out); \
4814 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, arch, ver, in, out) \
4816 if (in && strlen(in)) { \
4817 out = talloc_asprintf(mem_ctx, "\\\\%s\\print$\\%s\\%d\\%s", server, get_short_archi(arch), ver, in); \
4819 out = talloc_strdup(mem_ctx, ""); \
4821 W_ERROR_HAVE_NO_MEMORY(out); \
4824 static WERROR
string_array_from_driver_info(TALLOC_CTX
*mem_ctx
,
4825 const char **string_array
,
4826 const char ***presult
,
4827 const char *cservername
,
4831 int i
, num_strings
= 0;
4832 const char **array
= NULL
;
4834 if (string_array
== NULL
) {
4835 return WERR_INVALID_PARAMETER
;
4838 for (i
=0; string_array
[i
] && string_array
[i
][0] != '\0'; i
++) {
4839 const char *str
= NULL
;
4841 if (cservername
== NULL
|| arch
== NULL
) {
4842 FILL_DRIVER_STRING(mem_ctx
, string_array
[i
], str
);
4844 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
, arch
, version
, string_array
[i
], str
);
4847 if (!add_string_to_array(mem_ctx
, str
, &array
, &num_strings
)) {
4854 ADD_TO_ARRAY(mem_ctx
, const char *, NULL
,
4855 &array
, &num_strings
);
4865 /********************************************************************
4866 * fill a spoolss_DriverInfo1 struct
4867 ********************************************************************/
4869 static WERROR
fill_printer_driver_info1(TALLOC_CTX
*mem_ctx
,
4870 struct spoolss_DriverInfo1
*r
,
4871 const struct spoolss_DriverInfo8
*driver
,
4872 const char *servername
)
4874 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
4875 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
4880 /********************************************************************
4881 * fill a spoolss_DriverInfo2 struct
4882 ********************************************************************/
4884 static WERROR
fill_printer_driver_info2(TALLOC_CTX
*mem_ctx
,
4885 struct spoolss_DriverInfo2
*r
,
4886 const struct spoolss_DriverInfo8
*driver
,
4887 const char *servername
)
4890 const char *cservername
= canon_servername(servername
);
4892 r
->version
= driver
->version
;
4894 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
4895 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
4896 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
4897 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
4899 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4900 driver
->architecture
,
4902 driver
->driver_path
,
4905 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4906 driver
->architecture
,
4911 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4912 driver
->architecture
,
4914 driver
->config_file
,
4920 /********************************************************************
4921 * fill a spoolss_DriverInfo3 struct
4922 ********************************************************************/
4924 static WERROR
fill_printer_driver_info3(TALLOC_CTX
*mem_ctx
,
4925 struct spoolss_DriverInfo3
*r
,
4926 const struct spoolss_DriverInfo8
*driver
,
4927 const char *servername
)
4929 const char *cservername
= canon_servername(servername
);
4931 r
->version
= driver
->version
;
4933 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
4934 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
4935 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
4936 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
4938 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4939 driver
->architecture
,
4941 driver
->driver_path
,
4944 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4945 driver
->architecture
,
4950 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4951 driver
->architecture
,
4953 driver
->config_file
,
4956 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4957 driver
->architecture
,
4962 FILL_DRIVER_STRING(mem_ctx
,
4963 driver
->monitor_name
,
4966 FILL_DRIVER_STRING(mem_ctx
,
4967 driver
->default_datatype
,
4968 r
->default_datatype
);
4970 return string_array_from_driver_info(mem_ctx
,
4971 driver
->dependent_files
,
4972 &r
->dependent_files
,
4974 driver
->architecture
,
4978 /********************************************************************
4979 * fill a spoolss_DriverInfo4 struct
4980 ********************************************************************/
4982 static WERROR
fill_printer_driver_info4(TALLOC_CTX
*mem_ctx
,
4983 struct spoolss_DriverInfo4
*r
,
4984 const struct spoolss_DriverInfo8
*driver
,
4985 const char *servername
)
4987 const char *cservername
= canon_servername(servername
);
4990 r
->version
= driver
->version
;
4992 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
4993 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
4994 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
4995 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
4997 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4998 driver
->architecture
,
5000 driver
->driver_path
,
5003 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5004 driver
->architecture
,
5009 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5010 driver
->architecture
,
5012 driver
->config_file
,
5015 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5016 driver
->architecture
,
5021 result
= string_array_from_driver_info(mem_ctx
,
5022 driver
->dependent_files
,
5023 &r
->dependent_files
,
5025 driver
->architecture
,
5027 if (!W_ERROR_IS_OK(result
)) {
5031 FILL_DRIVER_STRING(mem_ctx
,
5032 driver
->monitor_name
,
5035 FILL_DRIVER_STRING(mem_ctx
,
5036 driver
->default_datatype
,
5037 r
->default_datatype
);
5040 result
= string_array_from_driver_info(mem_ctx
,
5041 driver
->previous_names
,
5048 /********************************************************************
5049 * fill a spoolss_DriverInfo5 struct
5050 ********************************************************************/
5052 static WERROR
fill_printer_driver_info5(TALLOC_CTX
*mem_ctx
,
5053 struct spoolss_DriverInfo5
*r
,
5054 const struct spoolss_DriverInfo8
*driver
,
5055 const char *servername
)
5057 const char *cservername
= canon_servername(servername
);
5059 r
->version
= driver
->version
;
5061 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5062 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5063 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5064 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5066 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5067 driver
->architecture
,
5069 driver
->driver_path
,
5072 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5073 driver
->architecture
,
5078 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5079 driver
->architecture
,
5081 driver
->config_file
,
5084 r
->driver_attributes
= 0;
5085 r
->config_version
= 0;
5086 r
->driver_version
= 0;
5090 /********************************************************************
5091 * fill a spoolss_DriverInfo6 struct
5092 ********************************************************************/
5094 static WERROR
fill_printer_driver_info6(TALLOC_CTX
*mem_ctx
,
5095 struct spoolss_DriverInfo6
*r
,
5096 const struct spoolss_DriverInfo8
*driver
,
5097 const char *servername
)
5099 const char *cservername
= canon_servername(servername
);
5102 r
->version
= driver
->version
;
5104 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5105 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5106 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5107 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5109 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5110 driver
->architecture
,
5112 driver
->driver_path
,
5115 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5116 driver
->architecture
,
5121 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5122 driver
->architecture
,
5124 driver
->config_file
,
5127 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5128 driver
->architecture
,
5133 FILL_DRIVER_STRING(mem_ctx
,
5134 driver
->monitor_name
,
5137 FILL_DRIVER_STRING(mem_ctx
,
5138 driver
->default_datatype
,
5139 r
->default_datatype
);
5141 result
= string_array_from_driver_info(mem_ctx
,
5142 driver
->dependent_files
,
5143 &r
->dependent_files
,
5145 driver
->architecture
,
5147 if (!W_ERROR_IS_OK(result
)) {
5151 result
= string_array_from_driver_info(mem_ctx
,
5152 driver
->previous_names
,
5155 if (!W_ERROR_IS_OK(result
)) {
5159 r
->driver_date
= driver
->driver_date
;
5160 r
->driver_version
= driver
->driver_version
;
5162 FILL_DRIVER_STRING(mem_ctx
,
5163 driver
->manufacturer_name
,
5164 r
->manufacturer_name
);
5165 FILL_DRIVER_STRING(mem_ctx
,
5166 driver
->manufacturer_url
,
5167 r
->manufacturer_url
);
5168 FILL_DRIVER_STRING(mem_ctx
,
5169 driver
->hardware_id
,
5171 FILL_DRIVER_STRING(mem_ctx
,
5178 /********************************************************************
5179 * fill a spoolss_DriverInfo8 struct
5180 ********************************************************************/
5182 static WERROR
fill_printer_driver_info8(TALLOC_CTX
*mem_ctx
,
5183 struct spoolss_DriverInfo8
*r
,
5184 const struct spoolss_DriverInfo8
*driver
,
5185 const char *servername
)
5187 const char *cservername
= canon_servername(servername
);
5190 r
->version
= driver
->version
;
5192 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5193 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5194 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5195 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5197 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5198 driver
->architecture
,
5200 driver
->driver_path
,
5203 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5204 driver
->architecture
,
5209 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5210 driver
->architecture
,
5212 driver
->config_file
,
5215 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5216 driver
->architecture
,
5221 FILL_DRIVER_STRING(mem_ctx
,
5222 driver
->monitor_name
,
5225 FILL_DRIVER_STRING(mem_ctx
,
5226 driver
->default_datatype
,
5227 r
->default_datatype
);
5229 result
= string_array_from_driver_info(mem_ctx
,
5230 driver
->dependent_files
,
5231 &r
->dependent_files
,
5233 driver
->architecture
,
5235 if (!W_ERROR_IS_OK(result
)) {
5239 result
= string_array_from_driver_info(mem_ctx
,
5240 driver
->previous_names
,
5243 if (!W_ERROR_IS_OK(result
)) {
5247 r
->driver_date
= driver
->driver_date
;
5248 r
->driver_version
= driver
->driver_version
;
5250 FILL_DRIVER_STRING(mem_ctx
,
5251 driver
->manufacturer_name
,
5252 r
->manufacturer_name
);
5253 FILL_DRIVER_STRING(mem_ctx
,
5254 driver
->manufacturer_url
,
5255 r
->manufacturer_url
);
5256 FILL_DRIVER_STRING(mem_ctx
,
5257 driver
->hardware_id
,
5259 FILL_DRIVER_STRING(mem_ctx
,
5263 FILL_DRIVER_STRING(mem_ctx
,
5264 driver
->print_processor
,
5265 r
->print_processor
);
5266 FILL_DRIVER_STRING(mem_ctx
,
5267 driver
->vendor_setup
,
5270 result
= string_array_from_driver_info(mem_ctx
,
5271 driver
->color_profiles
,
5274 if (!W_ERROR_IS_OK(result
)) {
5278 FILL_DRIVER_STRING(mem_ctx
,
5282 r
->printer_driver_attributes
= driver
->printer_driver_attributes
;
5284 result
= string_array_from_driver_info(mem_ctx
,
5285 driver
->core_driver_dependencies
,
5286 &r
->core_driver_dependencies
,
5288 if (!W_ERROR_IS_OK(result
)) {
5292 r
->min_inbox_driver_ver_date
= driver
->min_inbox_driver_ver_date
;
5293 r
->min_inbox_driver_ver_version
= driver
->min_inbox_driver_ver_version
;
5298 #if 0 /* disabled until marshalling issues are resolved - gd */
5299 /********************************************************************
5300 ********************************************************************/
5302 static WERROR
fill_spoolss_DriverFileInfo(TALLOC_CTX
*mem_ctx
,
5303 struct spoolss_DriverFileInfo
*r
,
5304 const char *cservername
,
5305 const char *file_name
,
5306 enum spoolss_DriverFileType file_type
,
5307 uint32_t file_version
)
5309 r
->file_name
= talloc_asprintf(mem_ctx
, "\\\\%s%s",
5310 cservername
, file_name
);
5311 W_ERROR_HAVE_NO_MEMORY(r
->file_name
);
5312 r
->file_type
= file_type
;
5313 r
->file_version
= file_version
;
5318 /********************************************************************
5319 ********************************************************************/
5321 static WERROR
spoolss_DriverFileInfo_from_driver(TALLOC_CTX
*mem_ctx
,
5322 const struct spoolss_DriverInfo8
*driver
,
5323 const char *cservername
,
5324 struct spoolss_DriverFileInfo
**info_p
,
5327 struct spoolss_DriverFileInfo
*info
= NULL
;
5335 if (strlen(driver
->driver_path
)) {
5336 info
= talloc_realloc(mem_ctx
, info
,
5337 struct spoolss_DriverFileInfo
,
5339 W_ERROR_HAVE_NO_MEMORY(info
);
5340 result
= fill_spoolss_DriverFileInfo(info
,
5343 driver
->driver_path
,
5344 SPOOLSS_DRIVER_FILE_TYPE_RENDERING
,
5346 W_ERROR_NOT_OK_RETURN(result
);
5350 if (strlen(driver
->config_file
)) {
5351 info
= talloc_realloc(mem_ctx
, info
,
5352 struct spoolss_DriverFileInfo
,
5354 W_ERROR_HAVE_NO_MEMORY(info
);
5355 result
= fill_spoolss_DriverFileInfo(info
,
5358 driver
->config_file
,
5359 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION
,
5361 W_ERROR_NOT_OK_RETURN(result
);
5365 if (strlen(driver
->data_file
)) {
5366 info
= talloc_realloc(mem_ctx
, info
,
5367 struct spoolss_DriverFileInfo
,
5369 W_ERROR_HAVE_NO_MEMORY(info
);
5370 result
= fill_spoolss_DriverFileInfo(info
,
5374 SPOOLSS_DRIVER_FILE_TYPE_DATA
,
5376 W_ERROR_NOT_OK_RETURN(result
);
5380 if (strlen(driver
->help_file
)) {
5381 info
= talloc_realloc(mem_ctx
, info
,
5382 struct spoolss_DriverFileInfo
,
5384 W_ERROR_HAVE_NO_MEMORY(info
);
5385 result
= fill_spoolss_DriverFileInfo(info
,
5389 SPOOLSS_DRIVER_FILE_TYPE_HELP
,
5391 W_ERROR_NOT_OK_RETURN(result
);
5395 for (i
=0; driver
->dependent_files
[i
] && driver
->dependent_files
[i
][0] != '\0'; i
++) {
5396 info
= talloc_realloc(mem_ctx
, info
,
5397 struct spoolss_DriverFileInfo
,
5399 W_ERROR_HAVE_NO_MEMORY(info
);
5400 result
= fill_spoolss_DriverFileInfo(info
,
5403 driver
->dependent_files
[i
],
5404 SPOOLSS_DRIVER_FILE_TYPE_OTHER
,
5406 W_ERROR_NOT_OK_RETURN(result
);
5416 /********************************************************************
5417 * fill a spoolss_DriverInfo101 struct
5418 ********************************************************************/
5420 static WERROR
fill_printer_driver_info101(TALLOC_CTX
*mem_ctx
,
5421 struct spoolss_DriverInfo101
*r
,
5422 const struct spoolss_DriverInfo8
*driver
,
5423 const char *servername
)
5425 const char *cservername
= canon_servername(servername
);
5428 r
->version
= driver
->version
;
5430 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5431 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5432 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5433 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5435 result
= spoolss_DriverFileInfo_from_driver(mem_ctx
, driver
,
5439 if (!W_ERROR_IS_OK(result
)) {
5443 FILL_DRIVER_STRING(mem_ctx
,
5444 driver
->monitor_name
,
5447 FILL_DRIVER_STRING(mem_ctx
,
5448 driver
->default_datatype
,
5449 r
->default_datatype
);
5451 result
= string_array_from_driver_info(mem_ctx
,
5452 driver
->previous_names
,
5455 if (!W_ERROR_IS_OK(result
)) {
5459 r
->driver_date
= driver
->driver_date
;
5460 r
->driver_version
= driver
->driver_version
;
5462 FILL_DRIVER_STRING(mem_ctx
,
5463 driver
->manufacturer_name
,
5464 r
->manufacturer_name
);
5465 FILL_DRIVER_STRING(mem_ctx
,
5466 driver
->manufacturer_url
,
5467 r
->manufacturer_url
);
5468 FILL_DRIVER_STRING(mem_ctx
,
5469 driver
->hardware_id
,
5471 FILL_DRIVER_STRING(mem_ctx
,
5478 /********************************************************************
5479 ********************************************************************/
5481 static WERROR
construct_printer_driver_info_level(TALLOC_CTX
*mem_ctx
,
5482 const struct auth_session_info
*session_info
,
5483 struct messaging_context
*msg_ctx
,
5485 union spoolss_DriverInfo
*r
,
5487 const char *servername
,
5488 const char *architecture
,
5491 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
5492 struct spoolss_DriverInfo8
*driver
;
5494 struct dcerpc_binding_handle
*b
;
5495 TALLOC_CTX
*tmp_ctx
= NULL
;
5498 return WERR_UNKNOWN_LEVEL
;
5501 tmp_ctx
= talloc_new(mem_ctx
);
5506 result
= winreg_printer_binding_handle(tmp_ctx
,
5510 if (!W_ERROR_IS_OK(result
)) {
5514 result
= winreg_get_printer(tmp_ctx
, b
,
5515 lp_const_servicename(snum
),
5518 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5519 win_errstr(result
)));
5521 if (!W_ERROR_IS_OK(result
)) {
5522 result
= WERR_INVALID_PRINTER_NAME
;
5526 result
= winreg_get_driver(tmp_ctx
, b
,
5528 pinfo2
->drivername
, version
, &driver
);
5530 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5531 win_errstr(result
)));
5533 if (!W_ERROR_IS_OK(result
)) {
5535 * Is this a W2k client ?
5539 result
= WERR_UNKNOWN_PRINTER_DRIVER
;
5543 /* Yes - try again with a WinNT driver. */
5545 result
= winreg_get_driver(tmp_ctx
, b
,
5549 DEBUG(8,("construct_printer_driver_level: status: %s\n",
5550 win_errstr(result
)));
5551 if (!W_ERROR_IS_OK(result
)) {
5552 result
= WERR_UNKNOWN_PRINTER_DRIVER
;
5557 /* these are allocated on mem_ctx and not tmp_ctx because they are
5558 * the 'return value' and need to utlive this call */
5561 result
= fill_printer_driver_info1(mem_ctx
, &r
->info1
, driver
, servername
);
5564 result
= fill_printer_driver_info2(mem_ctx
, &r
->info2
, driver
, servername
);
5567 result
= fill_printer_driver_info3(mem_ctx
, &r
->info3
, driver
, servername
);
5570 result
= fill_printer_driver_info4(mem_ctx
, &r
->info4
, driver
, servername
);
5573 result
= fill_printer_driver_info5(mem_ctx
, &r
->info5
, driver
, servername
);
5576 result
= fill_printer_driver_info6(mem_ctx
, &r
->info6
, driver
, servername
);
5579 result
= fill_printer_driver_info8(mem_ctx
, &r
->info8
, driver
, servername
);
5581 #if 0 /* disabled until marshalling issues are resolved - gd */
5583 result
= fill_printer_driver_info101(mem_ctx
, &r
->info101
, driver
, servername
);
5587 result
= WERR_UNKNOWN_LEVEL
;
5592 talloc_free(tmp_ctx
);
5596 /****************************************************************
5597 _spoolss_GetPrinterDriver2
5598 ****************************************************************/
5600 WERROR
_spoolss_GetPrinterDriver2(struct pipes_struct
*p
,
5601 struct spoolss_GetPrinterDriver2
*r
)
5603 struct printer_handle
*printer
;
5608 /* that's an [in out] buffer */
5610 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
5611 return WERR_INVALID_PARAM
;
5614 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5616 if (!(printer
= find_printer_index_by_hnd(p
, r
->in
.handle
))) {
5617 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5618 return WERR_INVALID_PRINTER_NAME
;
5622 *r
->out
.server_major_version
= 0;
5623 *r
->out
.server_minor_version
= 0;
5625 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
5629 result
= construct_printer_driver_info_level(p
->mem_ctx
,
5630 get_session_info_system(),
5632 r
->in
.level
, r
->out
.info
,
5633 snum
, printer
->servername
,
5635 r
->in
.client_major_version
);
5636 if (!W_ERROR_IS_OK(result
)) {
5637 TALLOC_FREE(r
->out
.info
);
5641 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_DriverInfo
,
5642 r
->out
.info
, r
->in
.level
);
5643 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
5645 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
5649 /****************************************************************
5650 _spoolss_StartPagePrinter
5651 ****************************************************************/
5653 WERROR
_spoolss_StartPagePrinter(struct pipes_struct
*p
,
5654 struct spoolss_StartPagePrinter
*r
)
5656 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5659 DEBUG(3,("_spoolss_StartPagePrinter: "
5660 "Error in startpageprinter printer handle\n"));
5664 Printer
->page_started
= true;
5668 /****************************************************************
5669 _spoolss_EndPagePrinter
5670 ****************************************************************/
5672 WERROR
_spoolss_EndPagePrinter(struct pipes_struct
*p
,
5673 struct spoolss_EndPagePrinter
*r
)
5677 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5680 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5681 OUR_HANDLE(r
->in
.handle
)));
5685 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
))
5688 Printer
->page_started
= false;
5689 print_job_endpage(p
->msg_ctx
, snum
, Printer
->jobid
);
5694 /****************************************************************
5695 _spoolss_StartDocPrinter
5696 ****************************************************************/
5698 WERROR
_spoolss_StartDocPrinter(struct pipes_struct
*p
,
5699 struct spoolss_StartDocPrinter
*r
)
5701 struct spoolss_DocumentInfo1
*info_1
;
5703 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5709 DEBUG(2,("_spoolss_StartDocPrinter: "
5710 "Invalid handle (%s:%u:%u)\n",
5711 OUR_HANDLE(r
->in
.handle
)));
5715 if (Printer
->jobid
) {
5716 DEBUG(2, ("_spoolss_StartDocPrinter: "
5717 "StartDocPrinter called twice! "
5718 "(existing jobid = %d)\n", Printer
->jobid
));
5719 return WERR_INVALID_HANDLE
;
5722 if (r
->in
.level
!= 1) {
5723 return WERR_UNKNOWN_LEVEL
;
5726 info_1
= r
->in
.info
.info1
;
5729 * a nice thing with NT is it doesn't listen to what you tell it.
5730 * when asked to send _only_ RAW datas, it tries to send datas
5733 * So I add checks like in NT Server ...
5736 if (info_1
->datatype
) {
5737 if (strcmp(info_1
->datatype
, "RAW") != 0) {
5739 return WERR_INVALID_DATATYPE
;
5743 /* get the share number of the printer */
5744 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
5748 rc
= get_remote_hostname(p
->remote_address
,
5754 if (strequal(rhost
,"UNKNOWN")) {
5755 rhost
= tsocket_address_inet_addr_string(p
->remote_address
,
5757 if (rhost
== NULL
) {
5762 werr
= print_job_start(p
->session_info
,
5766 info_1
->document_name
,
5767 info_1
->output_file
,
5771 /* An error occured in print_job_start() so return an appropriate
5774 if (!W_ERROR_IS_OK(werr
)) {
5778 Printer
->document_started
= true;
5779 *r
->out
.job_id
= Printer
->jobid
;
5784 /****************************************************************
5785 _spoolss_EndDocPrinter
5786 ****************************************************************/
5788 WERROR
_spoolss_EndDocPrinter(struct pipes_struct
*p
,
5789 struct spoolss_EndDocPrinter
*r
)
5791 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5796 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5797 OUR_HANDLE(r
->in
.handle
)));
5801 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
5805 Printer
->document_started
= false;
5806 status
= print_job_end(p
->msg_ctx
, snum
, Printer
->jobid
, NORMAL_CLOSE
);
5807 if (!NT_STATUS_IS_OK(status
)) {
5808 DEBUG(2, ("_spoolss_EndDocPrinter: "
5809 "print_job_end failed [%s]\n",
5810 nt_errstr(status
)));
5814 return ntstatus_to_werror(status
);
5817 /****************************************************************
5818 _spoolss_WritePrinter
5819 ****************************************************************/
5821 WERROR
_spoolss_WritePrinter(struct pipes_struct
*p
,
5822 struct spoolss_WritePrinter
*r
)
5824 ssize_t buffer_written
;
5826 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5829 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5830 OUR_HANDLE(r
->in
.handle
)));
5831 *r
->out
.num_written
= r
->in
._data_size
;
5835 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
))
5838 /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
5839 buffer_written
= print_job_write(server_event_context(),p
->msg_ctx
,
5840 snum
, Printer
->jobid
,
5841 (const char *)r
->in
.data
.data
,
5842 (size_t)r
->in
._data_size
);
5843 if (buffer_written
== (ssize_t
)-1) {
5844 *r
->out
.num_written
= 0;
5845 if (errno
== ENOSPC
)
5846 return WERR_NO_SPOOL_SPACE
;
5848 return WERR_ACCESS_DENIED
;
5851 *r
->out
.num_written
= r
->in
._data_size
;
5856 /********************************************************************
5857 * api_spoolss_getprinter
5858 * called from the spoolss dispatcher
5860 ********************************************************************/
5862 static WERROR
control_printer(struct policy_handle
*handle
, uint32_t command
,
5863 struct pipes_struct
*p
)
5865 const struct auth_session_info
*session_info
= p
->session_info
;
5867 WERROR errcode
= WERR_BADFUNC
;
5868 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, handle
);
5871 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5872 OUR_HANDLE(handle
)));
5876 if (!get_printer_snum(p
, handle
, &snum
, NULL
))
5880 case SPOOLSS_PRINTER_CONTROL_PAUSE
:
5881 errcode
= print_queue_pause(session_info
, p
->msg_ctx
, snum
);
5883 case SPOOLSS_PRINTER_CONTROL_RESUME
:
5884 case SPOOLSS_PRINTER_CONTROL_UNPAUSE
:
5885 errcode
= print_queue_resume(session_info
, p
->msg_ctx
, snum
);
5887 case SPOOLSS_PRINTER_CONTROL_PURGE
:
5888 errcode
= print_queue_purge(session_info
, p
->msg_ctx
, snum
);
5891 return WERR_UNKNOWN_LEVEL
;
5898 /****************************************************************
5899 _spoolss_AbortPrinter
5900 * From MSDN: "Deletes printer's spool file if printer is configured
5902 ****************************************************************/
5904 WERROR
_spoolss_AbortPrinter(struct pipes_struct
*p
,
5905 struct spoolss_AbortPrinter
*r
)
5907 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5909 WERROR errcode
= WERR_OK
;
5912 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5913 OUR_HANDLE(r
->in
.handle
)));
5917 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
))
5920 if (!Printer
->document_started
) {
5921 return WERR_SPL_NO_STARTDOC
;
5924 errcode
= print_job_delete(p
->session_info
,
5932 /********************************************************************
5933 * called by spoolss_api_setprinter
5934 * when updating a printer description
5935 ********************************************************************/
5937 static WERROR
update_printer_sec(struct policy_handle
*handle
,
5938 struct pipes_struct
*p
,
5939 struct sec_desc_buf
*secdesc_ctr
)
5941 struct spoolss_security_descriptor
*new_secdesc
= NULL
;
5942 struct spoolss_security_descriptor
*old_secdesc
= NULL
;
5943 const char *printer
;
5946 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, handle
);
5947 struct dcerpc_binding_handle
*b
;
5948 TALLOC_CTX
*tmp_ctx
= NULL
;
5950 if (!Printer
|| !get_printer_snum(p
, handle
, &snum
, NULL
)) {
5951 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
5952 OUR_HANDLE(handle
)));
5954 result
= WERR_BADFID
;
5958 if (secdesc_ctr
== NULL
) {
5959 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
5960 result
= WERR_INVALID_PARAM
;
5963 printer
= lp_const_servicename(snum
);
5965 /* Check the user has permissions to change the security
5966 descriptor. By experimentation with two NT machines, the user
5967 requires Full Access to the printer to change security
5970 if ( Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
5971 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
5972 result
= WERR_ACCESS_DENIED
;
5976 tmp_ctx
= talloc_new(p
->mem_ctx
);
5981 result
= winreg_printer_binding_handle(tmp_ctx
,
5982 get_session_info_system(),
5985 if (!W_ERROR_IS_OK(result
)) {
5989 /* NT seems to like setting the security descriptor even though
5990 nothing may have actually changed. */
5991 result
= winreg_get_printer_secdesc(tmp_ctx
, b
,
5994 if (!W_ERROR_IS_OK(result
)) {
5995 DEBUG(2,("update_printer_sec: winreg_get_printer_secdesc_internal() failed\n"));
5996 result
= WERR_BADFID
;
6000 if (DEBUGLEVEL
>= 10) {
6001 struct security_acl
*the_acl
;
6004 the_acl
= old_secdesc
->dacl
;
6005 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
6006 printer
, the_acl
->num_aces
));
6008 for (i
= 0; i
< the_acl
->num_aces
; i
++) {
6009 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
6010 &the_acl
->aces
[i
].trustee
),
6011 the_acl
->aces
[i
].access_mask
));
6014 the_acl
= secdesc_ctr
->sd
->dacl
;
6017 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
6018 printer
, the_acl
->num_aces
));
6020 for (i
= 0; i
< the_acl
->num_aces
; i
++) {
6021 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
6022 &the_acl
->aces
[i
].trustee
),
6023 the_acl
->aces
[i
].access_mask
));
6026 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
6030 new_secdesc
= sec_desc_merge(tmp_ctx
, secdesc_ctr
->sd
, old_secdesc
);
6031 if (new_secdesc
== NULL
) {
6032 result
= WERR_NOMEM
;
6036 if (security_descriptor_equal(new_secdesc
, old_secdesc
)) {
6041 result
= winreg_set_printer_secdesc(tmp_ctx
, b
,
6046 talloc_free(tmp_ctx
);
6050 /********************************************************************
6051 Canonicalize printer info from a client
6052 ********************************************************************/
6054 static bool check_printer_ok(TALLOC_CTX
*mem_ctx
,
6055 struct spoolss_SetPrinterInfo2
*info2
,
6058 fstring printername
;
6061 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
6062 "portname=%s drivername=%s comment=%s location=%s\n",
6063 info2
->servername
, info2
->printername
, info2
->sharename
,
6064 info2
->portname
, info2
->drivername
, info2
->comment
,
6067 /* we force some elements to "correct" values */
6068 info2
->servername
= talloc_asprintf(mem_ctx
, "\\\\%s", lp_netbios_name());
6069 if (info2
->servername
== NULL
) {
6072 info2
->sharename
= talloc_strdup(mem_ctx
, lp_const_servicename(snum
));
6073 if (info2
->sharename
== NULL
) {
6077 /* check to see if we allow printername != sharename */
6078 if (lp_force_printername(snum
)) {
6079 info2
->printername
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s",
6080 lp_netbios_name(), info2
->sharename
);
6082 /* make sure printername is in \\server\printername format */
6083 fstrcpy(printername
, info2
->printername
);
6085 if ( printername
[0] == '\\' && printername
[1] == '\\' ) {
6086 if ( (p
= strchr_m( &printername
[2], '\\' )) != NULL
)
6090 info2
->printername
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s",
6091 lp_netbios_name(), p
);
6093 if (info2
->printername
== NULL
) {
6097 info2
->attributes
|= PRINTER_ATTRIBUTE_SAMBA
;
6098 info2
->attributes
&= ~PRINTER_ATTRIBUTE_NOT_SAMBA
;
6103 /****************************************************************************
6104 ****************************************************************************/
6106 static WERROR
add_port_hook(TALLOC_CTX
*ctx
, struct security_token
*token
, const char *portname
, const char *uri
)
6108 char *cmd
= lp_addport_cmd();
6109 char *command
= NULL
;
6111 bool is_print_op
= false;
6114 return WERR_ACCESS_DENIED
;
6117 command
= talloc_asprintf(ctx
,
6118 "%s \"%s\" \"%s\"", cmd
, portname
, uri
);
6124 is_print_op
= security_token_has_privilege(token
, SEC_PRIV_PRINT_OPERATOR
);
6126 DEBUG(10,("Running [%s]\n", command
));
6128 /********* BEGIN SePrintOperatorPrivilege **********/
6133 ret
= smbrun(command
, NULL
);
6138 /********* END SePrintOperatorPrivilege **********/
6140 DEBUGADD(10,("returned [%d]\n", ret
));
6142 TALLOC_FREE(command
);
6145 return WERR_ACCESS_DENIED
;
6151 /****************************************************************************
6152 ****************************************************************************/
6154 static bool spoolss_conn_snum_used(struct smbd_server_connection
*sconn
,
6158 * As we do not know if we are embedded in the file server process
6159 * or not, we have to pretend that all shares are in use.
6164 static bool add_printer_hook(TALLOC_CTX
*ctx
, struct security_token
*token
,
6165 struct spoolss_SetPrinterInfo2
*info2
,
6166 const char *remote_machine
,
6167 struct messaging_context
*msg_ctx
)
6169 char *cmd
= lp_addprinter_cmd();
6171 char *command
= NULL
;
6175 bool is_print_op
= false;
6177 if (!remote_machine
) {
6181 command
= talloc_asprintf(ctx
,
6182 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
6183 cmd
, info2
->printername
, info2
->sharename
,
6184 info2
->portname
, info2
->drivername
,
6185 info2
->location
, info2
->comment
, remote_machine
);
6191 is_print_op
= security_token_has_privilege(token
, SEC_PRIV_PRINT_OPERATOR
);
6193 DEBUG(10,("Running [%s]\n", command
));
6195 /********* BEGIN SePrintOperatorPrivilege **********/
6200 if ( (ret
= smbrun(command
, &fd
)) == 0 ) {
6201 /* Tell everyone we updated smb.conf. */
6202 message_send_all(msg_ctx
, MSG_SMB_CONF_UPDATED
, NULL
, 0, NULL
);
6208 /********* END SePrintOperatorPrivilege **********/
6210 DEBUGADD(10,("returned [%d]\n", ret
));
6212 TALLOC_FREE(command
);
6220 /* reload our services immediately */
6222 reload_services(NULL
, spoolss_conn_snum_used
, false);
6226 /* Get lines and convert them back to dos-codepage */
6227 qlines
= fd_lines_load(fd
, &numlines
, 0, NULL
);
6228 DEBUGADD(10,("Lines returned = [%d]\n", numlines
));
6231 /* Set the portname to what the script says the portname should be. */
6232 /* but don't require anything to be return from the script exit a good error code */
6235 /* Set the portname to what the script says the portname should be. */
6236 info2
->portname
= talloc_strdup(ctx
, qlines
[0]);
6237 DEBUGADD(6,("Line[0] = [%s]\n", qlines
[0]));
6240 TALLOC_FREE(qlines
);
6244 static WERROR
update_dsspooler(TALLOC_CTX
*mem_ctx
,
6245 const struct auth_session_info
*session_info
,
6246 struct messaging_context
*msg_ctx
,
6248 struct spoolss_SetPrinterInfo2
*printer
,
6249 struct spoolss_PrinterInfo2
*old_printer
)
6251 bool force_update
= (old_printer
== NULL
);
6252 const char *dnsdomname
;
6253 const char *longname
;
6254 const char *uncname
;
6255 const char *spooling
;
6257 WERROR result
= WERR_OK
;
6258 struct dcerpc_binding_handle
*b
;
6259 TALLOC_CTX
*tmp_ctx
;
6262 tmp_ctx
= talloc_new(mem_ctx
);
6267 result
= winreg_printer_binding_handle(tmp_ctx
,
6271 if (!W_ERROR_IS_OK(result
)) {
6275 if (printer
->drivername
!= NULL
&&
6277 !strequal(printer
->drivername
, old_printer
->drivername
))) {
6278 ok
= push_reg_sz(tmp_ctx
, &buffer
, printer
->drivername
);
6280 DEBUG(0, ("%s data corrupted\n", SPOOL_REG_DRIVERNAME
));
6281 result
= WERR_INVALID_DATA
;
6284 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6286 SPOOL_DSSPOOLER_KEY
,
6287 SPOOL_REG_DRIVERNAME
,
6291 if (!W_ERROR_IS_OK(result
)) {
6292 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_DRIVERNAME
));
6296 if (!force_update
) {
6297 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
6298 printer
->drivername
));
6300 notify_printer_driver(server_event_context(), msg_ctx
,
6301 snum
, printer
->drivername
?
6302 printer
->drivername
: "");
6306 if (printer
->comment
!= NULL
&&
6308 !strequal(printer
->comment
, old_printer
->comment
))) {
6309 ok
= push_reg_sz(tmp_ctx
, &buffer
, printer
->comment
);
6311 DEBUG(0, ("comment data corrupted\n"));
6312 result
= WERR_INVALID_DATA
;
6315 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6317 SPOOL_DSSPOOLER_KEY
,
6318 SPOOL_REG_DESCRIPTION
,
6322 if (!W_ERROR_IS_OK(result
)) {
6323 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_DESCRIPTION
));
6327 if (!force_update
) {
6328 notify_printer_comment(server_event_context(), msg_ctx
,
6329 snum
, printer
->comment
?
6330 printer
->comment
: "");
6334 if (printer
->sharename
!= NULL
&&
6336 !strequal(printer
->sharename
, old_printer
->sharename
))) {
6337 ok
= push_reg_sz(tmp_ctx
, &buffer
, printer
->sharename
);
6339 DEBUG(0, ("sharename data corrupted\n"));
6340 result
= WERR_INVALID_DATA
;
6343 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6345 SPOOL_DSSPOOLER_KEY
,
6346 SPOOL_REG_PRINTSHARENAME
,
6350 if (!W_ERROR_IS_OK(result
)) {
6351 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSHARENAME
));
6355 if (!force_update
) {
6356 notify_printer_sharename(server_event_context(),
6358 snum
, printer
->sharename
?
6359 printer
->sharename
: "");
6363 if (printer
->printername
!= NULL
&&
6365 !strequal(printer
->printername
, old_printer
->printername
))) {
6368 p
= strrchr(printer
->printername
, '\\' );
6372 p
= printer
->printername
;
6375 ok
= push_reg_sz(tmp_ctx
, &buffer
, p
);
6377 DEBUG(0, ("printername data corrupted\n"));
6378 result
= WERR_INVALID_DATA
;
6381 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6383 SPOOL_DSSPOOLER_KEY
,
6384 SPOOL_REG_PRINTERNAME
,
6388 if (!W_ERROR_IS_OK(result
)) {
6389 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSHARENAME
));
6393 if (!force_update
) {
6394 notify_printer_printername(server_event_context(),
6395 msg_ctx
, snum
, p
? p
: "");
6399 if (printer
->portname
!= NULL
&&
6401 !strequal(printer
->portname
, old_printer
->portname
))) {
6402 ok
= push_reg_sz(tmp_ctx
, &buffer
, printer
->portname
);
6404 DEBUG(0, ("portname data corrupted\n"));
6405 result
= WERR_INVALID_DATA
;
6408 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6410 SPOOL_DSSPOOLER_KEY
,
6415 if (!W_ERROR_IS_OK(result
)) {
6416 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PORTNAME
));
6420 if (!force_update
) {
6421 notify_printer_port(server_event_context(),
6422 msg_ctx
, snum
, printer
->portname
?
6423 printer
->portname
: "");
6427 if (printer
->location
!= NULL
&&
6429 !strequal(printer
->location
, old_printer
->location
))) {
6430 ok
= push_reg_sz(tmp_ctx
, &buffer
, printer
->location
);
6432 DEBUG(0, ("location data corrupted\n"));
6433 result
= WERR_INVALID_DATA
;
6436 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6438 SPOOL_DSSPOOLER_KEY
,
6443 if (!W_ERROR_IS_OK(result
)) {
6444 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_LOCATION
));
6448 if (!force_update
) {
6449 notify_printer_location(server_event_context(),
6452 printer
->location
: "");
6456 if (printer
->sepfile
!= NULL
&&
6458 !strequal(printer
->sepfile
, old_printer
->sepfile
))) {
6459 ok
= push_reg_sz(tmp_ctx
, &buffer
, printer
->sepfile
);
6461 DEBUG(0, ("sepfile data corrupted\n"));
6462 result
= WERR_INVALID_DATA
;
6465 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6467 SPOOL_DSSPOOLER_KEY
,
6468 SPOOL_REG_PRINTSEPARATORFILE
,
6472 if (!W_ERROR_IS_OK(result
)) {
6473 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSEPARATORFILE
));
6477 if (!force_update
) {
6478 notify_printer_sepfile(server_event_context(),
6481 printer
->sepfile
: "");
6485 if (printer
->starttime
!= 0 &&
6487 printer
->starttime
!= old_printer
->starttime
)) {
6488 buffer
= data_blob_talloc(tmp_ctx
, NULL
, 4);
6489 SIVAL(buffer
.data
, 0, printer
->starttime
);
6490 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6492 SPOOL_DSSPOOLER_KEY
,
6493 SPOOL_REG_PRINTSTARTTIME
,
6497 if (!W_ERROR_IS_OK(result
)) {
6498 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSTARTTIME
));
6503 if (printer
->untiltime
!= 0 &&
6505 printer
->untiltime
!= old_printer
->untiltime
)) {
6506 buffer
= data_blob_talloc(tmp_ctx
, NULL
, 4);
6507 SIVAL(buffer
.data
, 0, printer
->untiltime
);
6508 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6510 SPOOL_DSSPOOLER_KEY
,
6511 SPOOL_REG_PRINTENDTIME
,
6515 if (!W_ERROR_IS_OK(result
)) {
6516 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTENDTIME
));
6521 if (force_update
|| printer
->priority
!= old_printer
->priority
) {
6522 buffer
= data_blob_talloc(tmp_ctx
, NULL
, 4);
6523 SIVAL(buffer
.data
, 0, printer
->priority
);
6524 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6526 SPOOL_DSSPOOLER_KEY
,
6531 if (!W_ERROR_IS_OK(result
)) {
6532 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTENDTIME
));
6537 if (force_update
|| printer
->attributes
!= old_printer
->attributes
) {
6538 buffer
= data_blob_talloc(tmp_ctx
, NULL
, 4);
6539 SIVAL(buffer
.data
, 0, (printer
->attributes
&
6540 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS
));
6541 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6543 SPOOL_DSSPOOLER_KEY
,
6544 SPOOL_REG_PRINTKEEPPRINTEDJOBS
,
6548 if (!W_ERROR_IS_OK(result
)) {
6549 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTENDTIME
));
6553 switch (printer
->attributes
& 0x3) {
6555 spooling
= SPOOL_REGVAL_PRINTWHILESPOOLING
;
6558 spooling
= SPOOL_REGVAL_PRINTAFTERSPOOLED
;
6561 spooling
= SPOOL_REGVAL_PRINTDIRECT
;
6564 spooling
= "unknown";
6566 ok
= push_reg_sz(tmp_ctx
, &buffer
, spooling
);
6568 DEBUG(0, ("printSpooling data corrupted\n"));
6569 result
= WERR_INVALID_DATA
;
6572 winreg_set_printer_dataex(tmp_ctx
, b
,
6574 SPOOL_DSSPOOLER_KEY
,
6575 SPOOL_REG_PRINTSPOOLING
,
6581 ok
= push_reg_sz(tmp_ctx
, &buffer
, lp_netbios_name());
6583 DEBUG(0, ("shortServerName data corrupted\n"));
6584 result
= WERR_INVALID_DATA
;
6587 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6589 SPOOL_DSSPOOLER_KEY
,
6590 SPOOL_REG_SHORTSERVERNAME
,
6594 if (!W_ERROR_IS_OK(result
)) {
6595 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_SHORTSERVERNAME
));
6599 dnsdomname
= get_mydnsfullname();
6600 if (dnsdomname
!= NULL
&& dnsdomname
[0] != '\0') {
6601 longname
= talloc_strdup(tmp_ctx
, dnsdomname
);
6603 longname
= talloc_strdup(tmp_ctx
, lp_netbios_name());
6605 if (longname
== NULL
) {
6606 result
= WERR_NOMEM
;
6610 ok
= push_reg_sz(tmp_ctx
, &buffer
, longname
);
6612 DEBUG(0, ("longname data corrupted\n"));
6613 result
= WERR_INVALID_DATA
;
6616 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6618 SPOOL_DSSPOOLER_KEY
,
6619 SPOOL_REG_SERVERNAME
,
6623 if (!W_ERROR_IS_OK(result
)) {
6624 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_SERVERNAME
));
6628 uncname
= talloc_asprintf(tmp_ctx
, "\\\\%s\\%s",
6629 lp_netbios_name(), printer
->sharename
);
6630 ok
= push_reg_sz(tmp_ctx
, &buffer
, uncname
);
6632 DEBUG(0, ("uncName data corrupted\n"));
6633 result
= WERR_INVALID_DATA
;
6636 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
6638 SPOOL_DSSPOOLER_KEY
,
6643 if (!W_ERROR_IS_OK(result
)) {
6644 DEBUG(0, ("Failed to set %s\n", SPOOL_REG_UNCNAME
));
6649 talloc_free(tmp_ctx
);
6653 /********************************************************************
6654 * Called by spoolss_api_setprinter
6655 * when updating a printer description.
6656 ********************************************************************/
6658 static WERROR
update_printer(struct pipes_struct
*p
,
6659 struct policy_handle
*handle
,
6660 struct spoolss_SetPrinterInfoCtr
*info_ctr
,
6661 struct spoolss_DeviceMode
*devmode
)
6663 uint32_t printer_mask
= SPOOLSS_PRINTER_INFO_ALL
;
6664 struct spoolss_SetPrinterInfo2
*printer
= info_ctr
->info
.info2
;
6665 struct spoolss_PrinterInfo2
*old_printer
;
6666 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, handle
);
6668 WERROR result
= WERR_OK
;
6669 TALLOC_CTX
*tmp_ctx
;
6670 struct dcerpc_binding_handle
*b
;
6672 DEBUG(8,("update_printer\n"));
6674 tmp_ctx
= talloc_new(p
->mem_ctx
);
6675 if (tmp_ctx
== NULL
) {
6680 result
= WERR_BADFID
;
6684 if (!get_printer_snum(p
, handle
, &snum
, NULL
)) {
6685 result
= WERR_BADFID
;
6689 result
= winreg_printer_binding_handle(tmp_ctx
,
6690 get_session_info_system(),
6693 if (!W_ERROR_IS_OK(result
)) {
6697 result
= winreg_get_printer(tmp_ctx
, b
,
6698 lp_const_servicename(snum
),
6700 if (!W_ERROR_IS_OK(result
)) {
6701 result
= WERR_BADFID
;
6705 /* Do sanity check on the requested changes for Samba */
6706 if (!check_printer_ok(tmp_ctx
, printer
, snum
)) {
6707 result
= WERR_INVALID_PARAM
;
6711 /* FIXME!!! If the driver has changed we really should verify that
6712 it is installed before doing much else --jerry */
6714 /* Check calling user has permission to update printer description */
6715 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
6716 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6717 result
= WERR_ACCESS_DENIED
;
6721 /* Call addprinter hook */
6722 /* Check changes to see if this is really needed */
6724 if (*lp_addprinter_cmd() &&
6725 (!strequal(printer
->drivername
, old_printer
->drivername
) ||
6726 !strequal(printer
->comment
, old_printer
->comment
) ||
6727 !strequal(printer
->portname
, old_printer
->portname
) ||
6728 !strequal(printer
->location
, old_printer
->location
)) )
6732 raddr
= tsocket_address_inet_addr_string(p
->remote_address
,
6734 if (raddr
== NULL
) {
6738 /* add_printer_hook() will call reload_services() */
6739 if (!add_printer_hook(tmp_ctx
, p
->session_info
->security_token
,
6742 result
= WERR_ACCESS_DENIED
;
6747 result
= update_dsspooler(tmp_ctx
,
6748 get_session_info_system(),
6753 if (!W_ERROR_IS_OK(result
)) {
6757 printer_mask
&= ~SPOOLSS_PRINTER_INFO_SECDESC
;
6759 if (devmode
== NULL
) {
6760 printer_mask
&= ~SPOOLSS_PRINTER_INFO_DEVMODE
;
6762 result
= winreg_update_printer(tmp_ctx
, b
,
6770 talloc_free(tmp_ctx
);
6775 /****************************************************************************
6776 ****************************************************************************/
6777 static WERROR
publish_or_unpublish_printer(struct pipes_struct
*p
,
6778 struct policy_handle
*handle
,
6779 struct spoolss_SetPrinterInfo7
*info7
)
6782 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
6785 struct printer_handle
*Printer
;
6787 if ( lp_security() != SEC_ADS
) {
6788 return WERR_UNKNOWN_LEVEL
;
6791 Printer
= find_printer_index_by_hnd(p
, handle
);
6793 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7
->action
));
6798 if (!get_printer_snum(p
, handle
, &snum
, NULL
))
6801 result
= winreg_get_printer_internal(p
->mem_ctx
,
6802 get_session_info_system(),
6804 lp_servicename(snum
),
6806 if (!W_ERROR_IS_OK(result
)) {
6810 nt_printer_publish(pinfo2
,
6811 get_session_info_system(),
6816 TALLOC_FREE(pinfo2
);
6819 return WERR_UNKNOWN_LEVEL
;
6823 /********************************************************************
6824 ********************************************************************/
6826 static WERROR
update_printer_devmode(struct pipes_struct
*p
,
6827 struct policy_handle
*handle
,
6828 struct spoolss_DeviceMode
*devmode
)
6831 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, handle
);
6832 uint32_t info2_mask
= SPOOLSS_PRINTER_INFO_DEVMODE
;
6834 DEBUG(8,("update_printer_devmode\n"));
6840 if (!get_printer_snum(p
, handle
, &snum
, NULL
)) {
6844 /* Check calling user has permission to update printer description */
6845 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
6846 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6847 return WERR_ACCESS_DENIED
;
6850 return winreg_update_printer_internal(p
->mem_ctx
,
6851 get_session_info_system(),
6853 lp_const_servicename(snum
),
6861 /****************************************************************
6863 ****************************************************************/
6865 WERROR
_spoolss_SetPrinter(struct pipes_struct
*p
,
6866 struct spoolss_SetPrinter
*r
)
6870 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
6873 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6874 OUR_HANDLE(r
->in
.handle
)));
6878 /* check the level */
6879 switch (r
->in
.info_ctr
->level
) {
6881 return control_printer(r
->in
.handle
, r
->in
.command
, p
);
6883 result
= update_printer(p
, r
->in
.handle
,
6885 r
->in
.devmode_ctr
->devmode
);
6886 if (!W_ERROR_IS_OK(result
))
6888 if (r
->in
.secdesc_ctr
->sd
)
6889 result
= update_printer_sec(r
->in
.handle
, p
,
6893 return update_printer_sec(r
->in
.handle
, p
,
6896 return publish_or_unpublish_printer(p
, r
->in
.handle
,
6897 r
->in
.info_ctr
->info
.info7
);
6899 return update_printer_devmode(p
, r
->in
.handle
,
6900 r
->in
.devmode_ctr
->devmode
);
6902 return WERR_UNKNOWN_LEVEL
;
6906 /****************************************************************
6907 _spoolss_FindClosePrinterNotify
6908 ****************************************************************/
6910 WERROR
_spoolss_FindClosePrinterNotify(struct pipes_struct
*p
,
6911 struct spoolss_FindClosePrinterNotify
*r
)
6913 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
6916 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6917 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r
->in
.handle
)));
6921 if (Printer
->notify
.cli_chan
!= NULL
&&
6922 Printer
->notify
.cli_chan
->active_connections
> 0) {
6925 if (Printer
->printer_type
== SPLHND_PRINTER
) {
6926 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
6931 srv_spoolss_replycloseprinter(snum
, Printer
);
6934 Printer
->notify
.flags
=0;
6935 Printer
->notify
.options
=0;
6936 Printer
->notify
.localmachine
[0]='\0';
6937 Printer
->notify
.printerlocal
=0;
6938 TALLOC_FREE(Printer
->notify
.option
);
6943 /****************************************************************
6945 ****************************************************************/
6947 WERROR
_spoolss_AddJob(struct pipes_struct
*p
,
6948 struct spoolss_AddJob
*r
)
6950 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
6951 return WERR_INVALID_PARAM
;
6954 /* this is what a NT server returns for AddJob. AddJob must fail on
6955 * non-local printers */
6957 if (r
->in
.level
!= 1) {
6958 return WERR_UNKNOWN_LEVEL
;
6961 return WERR_INVALID_PARAM
;
6964 /****************************************************************************
6966 ****************************************************************************/
6968 static WERROR
fill_job_info1(TALLOC_CTX
*mem_ctx
,
6969 struct spoolss_JobInfo1
*r
,
6970 const print_queue_struct
*queue
,
6971 int position
, int snum
,
6972 struct spoolss_PrinterInfo2
*pinfo2
)
6976 t
= gmtime(&queue
->time
);
6978 r
->job_id
= queue
->job
;
6980 r
->printer_name
= talloc_strdup(mem_ctx
, lp_servicename(snum
));
6981 W_ERROR_HAVE_NO_MEMORY(r
->printer_name
);
6982 r
->server_name
= talloc_strdup(mem_ctx
, pinfo2
->servername
);
6983 W_ERROR_HAVE_NO_MEMORY(r
->server_name
);
6984 r
->user_name
= talloc_strdup(mem_ctx
, queue
->fs_user
);
6985 W_ERROR_HAVE_NO_MEMORY(r
->user_name
);
6986 r
->document_name
= talloc_strdup(mem_ctx
, queue
->fs_file
);
6987 W_ERROR_HAVE_NO_MEMORY(r
->document_name
);
6988 r
->data_type
= talloc_strdup(mem_ctx
, "RAW");
6989 W_ERROR_HAVE_NO_MEMORY(r
->data_type
);
6990 r
->text_status
= talloc_strdup(mem_ctx
, "");
6991 W_ERROR_HAVE_NO_MEMORY(r
->text_status
);
6993 r
->status
= nt_printj_status(queue
->status
);
6994 r
->priority
= queue
->priority
;
6995 r
->position
= position
;
6996 r
->total_pages
= queue
->page_count
;
6997 r
->pages_printed
= 0; /* ??? */
6999 init_systemtime(&r
->submitted
, t
);
7004 /****************************************************************************
7006 ****************************************************************************/
7008 static WERROR
fill_job_info2(TALLOC_CTX
*mem_ctx
,
7009 struct spoolss_JobInfo2
*r
,
7010 const print_queue_struct
*queue
,
7011 int position
, int snum
,
7012 struct spoolss_PrinterInfo2
*pinfo2
,
7013 struct spoolss_DeviceMode
*devmode
)
7017 t
= gmtime(&queue
->time
);
7019 r
->job_id
= queue
->job
;
7021 r
->printer_name
= talloc_strdup(mem_ctx
, lp_servicename(snum
));
7022 W_ERROR_HAVE_NO_MEMORY(r
->printer_name
);
7023 r
->server_name
= talloc_strdup(mem_ctx
, pinfo2
->servername
);
7024 W_ERROR_HAVE_NO_MEMORY(r
->server_name
);
7025 r
->user_name
= talloc_strdup(mem_ctx
, queue
->fs_user
);
7026 W_ERROR_HAVE_NO_MEMORY(r
->user_name
);
7027 r
->document_name
= talloc_strdup(mem_ctx
, queue
->fs_file
);
7028 W_ERROR_HAVE_NO_MEMORY(r
->document_name
);
7029 r
->notify_name
= talloc_strdup(mem_ctx
, queue
->fs_user
);
7030 W_ERROR_HAVE_NO_MEMORY(r
->notify_name
);
7031 r
->data_type
= talloc_strdup(mem_ctx
, "RAW");
7032 W_ERROR_HAVE_NO_MEMORY(r
->data_type
);
7033 r
->print_processor
= talloc_strdup(mem_ctx
, "winprint");
7034 W_ERROR_HAVE_NO_MEMORY(r
->print_processor
);
7035 r
->parameters
= talloc_strdup(mem_ctx
, "");
7036 W_ERROR_HAVE_NO_MEMORY(r
->parameters
);
7037 r
->driver_name
= talloc_strdup(mem_ctx
, pinfo2
->drivername
);
7038 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
7040 r
->devmode
= devmode
;
7042 r
->text_status
= talloc_strdup(mem_ctx
, "");
7043 W_ERROR_HAVE_NO_MEMORY(r
->text_status
);
7047 r
->status
= nt_printj_status(queue
->status
);
7048 r
->priority
= queue
->priority
;
7049 r
->position
= position
;
7052 r
->total_pages
= queue
->page_count
;
7053 r
->size
= queue
->size
;
7054 init_systemtime(&r
->submitted
, t
);
7056 r
->pages_printed
= 0; /* ??? */
7061 /****************************************************************************
7063 ****************************************************************************/
7065 static WERROR
fill_job_info3(TALLOC_CTX
*mem_ctx
,
7066 struct spoolss_JobInfo3
*r
,
7067 const print_queue_struct
*queue
,
7068 const print_queue_struct
*next_queue
,
7069 int position
, int snum
,
7070 struct spoolss_PrinterInfo2
*pinfo2
)
7072 r
->job_id
= queue
->job
;
7075 r
->next_job_id
= next_queue
->job
;
7082 /****************************************************************************
7083 Enumjobs at level 1.
7084 ****************************************************************************/
7086 static WERROR
enumjobs_level1(TALLOC_CTX
*mem_ctx
,
7087 const print_queue_struct
*queue
,
7088 uint32_t num_queues
, int snum
,
7089 struct spoolss_PrinterInfo2
*pinfo2
,
7090 union spoolss_JobInfo
**info_p
,
7093 union spoolss_JobInfo
*info
;
7095 WERROR result
= WERR_OK
;
7097 info
= talloc_array(mem_ctx
, union spoolss_JobInfo
, num_queues
);
7098 W_ERROR_HAVE_NO_MEMORY(info
);
7100 *count
= num_queues
;
7102 for (i
=0; i
<*count
; i
++) {
7103 result
= fill_job_info1(info
,
7109 if (!W_ERROR_IS_OK(result
)) {
7115 if (!W_ERROR_IS_OK(result
)) {
7126 /****************************************************************************
7127 Enumjobs at level 2.
7128 ****************************************************************************/
7130 static WERROR
enumjobs_level2(TALLOC_CTX
*mem_ctx
,
7131 const print_queue_struct
*queue
,
7132 uint32_t num_queues
, int snum
,
7133 struct spoolss_PrinterInfo2
*pinfo2
,
7134 union spoolss_JobInfo
**info_p
,
7137 union spoolss_JobInfo
*info
;
7139 WERROR result
= WERR_OK
;
7141 info
= talloc_array(mem_ctx
, union spoolss_JobInfo
, num_queues
);
7142 W_ERROR_HAVE_NO_MEMORY(info
);
7144 *count
= num_queues
;
7146 for (i
=0; i
<*count
; i
++) {
7147 struct spoolss_DeviceMode
*devmode
;
7149 result
= spoolss_create_default_devmode(info
,
7150 pinfo2
->printername
,
7152 if (!W_ERROR_IS_OK(result
)) {
7153 DEBUG(3, ("Can't proceed w/o a devmode!"));
7157 result
= fill_job_info2(info
,
7164 if (!W_ERROR_IS_OK(result
)) {
7170 if (!W_ERROR_IS_OK(result
)) {
7181 /****************************************************************************
7182 Enumjobs at level 3.
7183 ****************************************************************************/
7185 static WERROR
enumjobs_level3(TALLOC_CTX
*mem_ctx
,
7186 const print_queue_struct
*queue
,
7187 uint32_t num_queues
, int snum
,
7188 struct spoolss_PrinterInfo2
*pinfo2
,
7189 union spoolss_JobInfo
**info_p
,
7192 union spoolss_JobInfo
*info
;
7194 WERROR result
= WERR_OK
;
7196 info
= talloc_array(mem_ctx
, union spoolss_JobInfo
, num_queues
);
7197 W_ERROR_HAVE_NO_MEMORY(info
);
7199 *count
= num_queues
;
7201 for (i
=0; i
<*count
; i
++) {
7202 const print_queue_struct
*next_queue
= NULL
;
7205 next_queue
= &queue
[i
+1];
7208 result
= fill_job_info3(info
,
7215 if (!W_ERROR_IS_OK(result
)) {
7221 if (!W_ERROR_IS_OK(result
)) {
7232 /****************************************************************
7234 ****************************************************************/
7236 WERROR
_spoolss_EnumJobs(struct pipes_struct
*p
,
7237 struct spoolss_EnumJobs
*r
)
7240 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
7242 print_status_struct prt_status
;
7243 print_queue_struct
*queue
= NULL
;
7246 /* that's an [in out] buffer */
7248 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
7249 return WERR_INVALID_PARAM
;
7252 DEBUG(4,("_spoolss_EnumJobs\n"));
7256 *r
->out
.info
= NULL
;
7258 /* lookup the printer snum and tdb entry */
7260 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
7264 result
= winreg_get_printer_internal(p
->mem_ctx
,
7265 get_session_info_system(),
7267 lp_const_servicename(snum
),
7269 if (!W_ERROR_IS_OK(result
)) {
7273 count
= print_queue_status(p
->msg_ctx
, snum
, &queue
, &prt_status
);
7274 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
7275 count
, prt_status
.status
, prt_status
.message
));
7279 TALLOC_FREE(pinfo2
);
7283 switch (r
->in
.level
) {
7285 result
= enumjobs_level1(p
->mem_ctx
, queue
, count
, snum
,
7286 pinfo2
, r
->out
.info
, r
->out
.count
);
7289 result
= enumjobs_level2(p
->mem_ctx
, queue
, count
, snum
,
7290 pinfo2
, r
->out
.info
, r
->out
.count
);
7293 result
= enumjobs_level3(p
->mem_ctx
, queue
, count
, snum
,
7294 pinfo2
, r
->out
.info
, r
->out
.count
);
7297 result
= WERR_UNKNOWN_LEVEL
;
7302 TALLOC_FREE(pinfo2
);
7304 if (!W_ERROR_IS_OK(result
)) {
7308 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
7310 *r
->out
.info
, r
->in
.level
,
7312 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
7313 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
7315 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
7318 /****************************************************************
7319 _spoolss_ScheduleJob
7320 ****************************************************************/
7322 WERROR
_spoolss_ScheduleJob(struct pipes_struct
*p
,
7323 struct spoolss_ScheduleJob
*r
)
7328 /****************************************************************
7329 ****************************************************************/
7331 static WERROR
spoolss_setjob_1(TALLOC_CTX
*mem_ctx
,
7332 struct messaging_context
*msg_ctx
,
7333 const char *printer_name
,
7335 struct spoolss_SetJobInfo1
*r
)
7339 if (!print_job_get_name(mem_ctx
, printer_name
, job_id
, &old_doc_name
)) {
7343 if (strequal(old_doc_name
, r
->document_name
)) {
7347 if (!print_job_set_name(server_event_context(), msg_ctx
,
7348 printer_name
, job_id
, r
->document_name
)) {
7355 /****************************************************************
7357 ****************************************************************/
7359 WERROR
_spoolss_SetJob(struct pipes_struct
*p
,
7360 struct spoolss_SetJob
*r
)
7362 const struct auth_session_info
*session_info
= p
->session_info
;
7364 WERROR errcode
= WERR_BADFUNC
;
7366 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
7370 if (!print_job_exists(lp_const_servicename(snum
), r
->in
.job_id
)) {
7371 return WERR_INVALID_PRINTER_NAME
;
7374 switch (r
->in
.command
) {
7375 case SPOOLSS_JOB_CONTROL_CANCEL
:
7376 case SPOOLSS_JOB_CONTROL_DELETE
:
7377 errcode
= print_job_delete(session_info
, p
->msg_ctx
,
7378 snum
, r
->in
.job_id
);
7379 if (W_ERROR_EQUAL(errcode
, WERR_PRINTER_HAS_JOBS_QUEUED
)) {
7383 case SPOOLSS_JOB_CONTROL_PAUSE
:
7384 if (print_job_pause(session_info
, p
->msg_ctx
,
7385 snum
, r
->in
.job_id
, &errcode
)) {
7389 case SPOOLSS_JOB_CONTROL_RESTART
:
7390 case SPOOLSS_JOB_CONTROL_RESUME
:
7391 if (print_job_resume(session_info
, p
->msg_ctx
,
7392 snum
, r
->in
.job_id
, &errcode
)) {
7400 return WERR_UNKNOWN_LEVEL
;
7403 if (!W_ERROR_IS_OK(errcode
)) {
7407 if (r
->in
.ctr
== NULL
) {
7411 switch (r
->in
.ctr
->level
) {
7413 errcode
= spoolss_setjob_1(p
->mem_ctx
, p
->msg_ctx
,
7414 lp_const_servicename(snum
),
7416 r
->in
.ctr
->info
.info1
);
7422 return WERR_UNKNOWN_LEVEL
;
7428 /****************************************************************************
7429 Enumerates all printer drivers by level and architecture.
7430 ****************************************************************************/
7432 static WERROR
enumprinterdrivers_level_by_architecture(TALLOC_CTX
*mem_ctx
,
7433 const struct auth_session_info
*session_info
,
7434 struct messaging_context
*msg_ctx
,
7435 const char *servername
,
7436 const char *architecture
,
7438 union spoolss_DriverInfo
**info_p
,
7443 struct spoolss_DriverInfo8
*driver
;
7444 union spoolss_DriverInfo
*info
= NULL
;
7446 WERROR result
= WERR_OK
;
7447 uint32_t num_drivers
;
7448 const char **drivers
;
7449 struct dcerpc_binding_handle
*b
;
7450 TALLOC_CTX
*tmp_ctx
= NULL
;
7455 tmp_ctx
= talloc_new(mem_ctx
);
7460 result
= winreg_printer_binding_handle(tmp_ctx
,
7464 if (!W_ERROR_IS_OK(result
)) {
7468 for (version
=0; version
<DRIVER_MAX_VERSION
; version
++) {
7469 result
= winreg_get_driver_list(tmp_ctx
, b
,
7470 architecture
, version
,
7471 &num_drivers
, &drivers
);
7472 if (!W_ERROR_IS_OK(result
)) {
7475 DEBUG(4, ("we have:[%d] drivers in environment"
7476 " [%s] and version [%d]\n",
7477 num_drivers
, architecture
, version
));
7479 if (num_drivers
!= 0) {
7480 info
= talloc_realloc(tmp_ctx
, info
,
7481 union spoolss_DriverInfo
,
7482 count
+ num_drivers
);
7484 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
7485 "failed to enlarge driver info buffer!\n"));
7486 result
= WERR_NOMEM
;
7491 for (i
= 0; i
< num_drivers
; i
++) {
7492 DEBUG(5, ("\tdriver: [%s]\n", drivers
[i
]));
7494 result
= winreg_get_driver(tmp_ctx
, b
,
7495 architecture
, drivers
[i
],
7497 if (!W_ERROR_IS_OK(result
)) {
7503 result
= fill_printer_driver_info1(info
, &info
[count
+i
].info1
,
7504 driver
, servername
);
7507 result
= fill_printer_driver_info2(info
, &info
[count
+i
].info2
,
7508 driver
, servername
);
7511 result
= fill_printer_driver_info3(info
, &info
[count
+i
].info3
,
7512 driver
, servername
);
7515 result
= fill_printer_driver_info4(info
, &info
[count
+i
].info4
,
7516 driver
, servername
);
7519 result
= fill_printer_driver_info5(info
, &info
[count
+i
].info5
,
7520 driver
, servername
);
7523 result
= fill_printer_driver_info6(info
, &info
[count
+i
].info6
,
7524 driver
, servername
);
7527 result
= fill_printer_driver_info8(info
, &info
[count
+i
].info8
,
7528 driver
, servername
);
7531 result
= WERR_UNKNOWN_LEVEL
;
7535 TALLOC_FREE(driver
);
7537 if (!W_ERROR_IS_OK(result
)) {
7542 count
+= num_drivers
;
7543 TALLOC_FREE(drivers
);
7547 if (W_ERROR_IS_OK(result
)) {
7548 *info_p
= talloc_move(mem_ctx
, &info
);
7552 talloc_free(tmp_ctx
);
7556 /****************************************************************************
7557 Enumerates all printer drivers by level.
7558 ****************************************************************************/
7560 static WERROR
enumprinterdrivers_level(TALLOC_CTX
*mem_ctx
,
7561 const struct auth_session_info
*session_info
,
7562 struct messaging_context
*msg_ctx
,
7563 const char *servername
,
7564 const char *architecture
,
7566 union spoolss_DriverInfo
**info_p
,
7570 WERROR result
= WERR_OK
;
7572 if (strequal(architecture
, SPOOLSS_ARCHITECTURE_ALL
)) {
7574 for (a
=0; archi_table
[a
].long_archi
!= NULL
; a
++) {
7576 union spoolss_DriverInfo
*info
= NULL
;
7579 result
= enumprinterdrivers_level_by_architecture(mem_ctx
,
7583 archi_table
[a
].long_archi
,
7587 if (!W_ERROR_IS_OK(result
)) {
7591 for (i
=0; i
< count
; i
++) {
7592 ADD_TO_ARRAY(mem_ctx
, union spoolss_DriverInfo
,
7593 info
[i
], info_p
, count_p
);
7600 return enumprinterdrivers_level_by_architecture(mem_ctx
,
7610 /****************************************************************
7611 _spoolss_EnumPrinterDrivers
7612 ****************************************************************/
7614 WERROR
_spoolss_EnumPrinterDrivers(struct pipes_struct
*p
,
7615 struct spoolss_EnumPrinterDrivers
*r
)
7617 const char *cservername
;
7620 /* that's an [in out] buffer */
7622 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
7623 return WERR_INVALID_PARAM
;
7626 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
7630 *r
->out
.info
= NULL
;
7632 cservername
= canon_servername(r
->in
.server
);
7634 if (!is_myname_or_ipaddr(cservername
)) {
7635 return WERR_UNKNOWN_PRINTER_DRIVER
;
7638 result
= enumprinterdrivers_level(p
->mem_ctx
,
7639 get_session_info_system(),
7646 if (!W_ERROR_IS_OK(result
)) {
7650 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
7651 spoolss_EnumPrinterDrivers
,
7652 *r
->out
.info
, r
->in
.level
,
7654 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
7655 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
7657 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
7660 /****************************************************************
7662 ****************************************************************/
7664 WERROR
_spoolss_EnumForms(struct pipes_struct
*p
,
7665 struct spoolss_EnumForms
*r
)
7671 *r
->out
.info
= NULL
;
7673 /* that's an [in out] buffer */
7675 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0) ) {
7676 return WERR_INVALID_PARAM
;
7679 DEBUG(4,("_spoolss_EnumForms\n"));
7680 DEBUGADD(5,("Offered buffer size [%d]\n", r
->in
.offered
));
7681 DEBUGADD(5,("Info level [%d]\n", r
->in
.level
));
7683 switch (r
->in
.level
) {
7685 result
= winreg_printer_enumforms1_internal(p
->mem_ctx
,
7686 get_session_info_system(),
7692 result
= WERR_UNKNOWN_LEVEL
;
7696 if (!W_ERROR_IS_OK(result
)) {
7700 if (*r
->out
.count
== 0) {
7701 return WERR_NO_MORE_ITEMS
;
7704 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
7706 *r
->out
.info
, r
->in
.level
,
7708 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
7709 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
7711 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
7714 /****************************************************************
7716 ****************************************************************/
7718 WERROR
_spoolss_GetForm(struct pipes_struct
*p
,
7719 struct spoolss_GetForm
*r
)
7723 /* that's an [in out] buffer */
7725 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
7726 return WERR_INVALID_PARAM
;
7729 DEBUG(4,("_spoolss_GetForm\n"));
7730 DEBUGADD(5,("Offered buffer size [%d]\n", r
->in
.offered
));
7731 DEBUGADD(5,("Info level [%d]\n", r
->in
.level
));
7733 switch (r
->in
.level
) {
7735 result
= winreg_printer_getform1_internal(p
->mem_ctx
,
7736 get_session_info_system(),
7739 &r
->out
.info
->info1
);
7742 result
= WERR_UNKNOWN_LEVEL
;
7746 if (!W_ERROR_IS_OK(result
)) {
7747 TALLOC_FREE(r
->out
.info
);
7751 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_FormInfo
,
7752 r
->out
.info
, r
->in
.level
);
7753 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
7755 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
7758 /****************************************************************************
7759 ****************************************************************************/
7761 static WERROR
fill_port_1(TALLOC_CTX
*mem_ctx
,
7762 struct spoolss_PortInfo1
*r
,
7765 r
->port_name
= talloc_strdup(mem_ctx
, name
);
7766 W_ERROR_HAVE_NO_MEMORY(r
->port_name
);
7771 /****************************************************************************
7772 TODO: This probably needs distinguish between TCP/IP and Local ports
7774 ****************************************************************************/
7776 static WERROR
fill_port_2(TALLOC_CTX
*mem_ctx
,
7777 struct spoolss_PortInfo2
*r
,
7780 r
->port_name
= talloc_strdup(mem_ctx
, name
);
7781 W_ERROR_HAVE_NO_MEMORY(r
->port_name
);
7783 r
->monitor_name
= talloc_strdup(mem_ctx
, "Local Monitor");
7784 W_ERROR_HAVE_NO_MEMORY(r
->monitor_name
);
7786 r
->description
= talloc_strdup(mem_ctx
, SPL_LOCAL_PORT
);
7787 W_ERROR_HAVE_NO_MEMORY(r
->description
);
7789 r
->port_type
= SPOOLSS_PORT_TYPE_WRITE
;
7796 /****************************************************************************
7797 wrapper around the enumer ports command
7798 ****************************************************************************/
7800 static WERROR
enumports_hook(TALLOC_CTX
*ctx
, int *count
, char ***lines
)
7802 char *cmd
= lp_enumports_cmd();
7803 char **qlines
= NULL
;
7804 char *command
= NULL
;
7812 /* if no hook then just fill in the default port */
7815 if (!(qlines
= talloc_array( NULL
, char*, 2 ))) {
7818 if (!(qlines
[0] = talloc_strdup(qlines
, SAMBA_PRINTER_PORT_NAME
))) {
7819 TALLOC_FREE(qlines
);
7826 /* we have a valid enumport command */
7828 command
= talloc_asprintf(ctx
, "%s \"%d\"", cmd
, 1);
7833 DEBUG(10,("Running [%s]\n", command
));
7834 ret
= smbrun(command
, &fd
);
7835 DEBUG(10,("Returned [%d]\n", ret
));
7836 TALLOC_FREE(command
);
7841 return WERR_ACCESS_DENIED
;
7845 qlines
= fd_lines_load(fd
, &numlines
, 0, NULL
);
7846 DEBUGADD(10,("Lines returned = [%d]\n", numlines
));
7856 /****************************************************************************
7858 ****************************************************************************/
7860 static WERROR
enumports_level_1(TALLOC_CTX
*mem_ctx
,
7861 union spoolss_PortInfo
**info_p
,
7864 union spoolss_PortInfo
*info
= NULL
;
7866 WERROR result
= WERR_OK
;
7867 char **qlines
= NULL
;
7870 result
= enumports_hook(talloc_tos(), &numlines
, &qlines
);
7871 if (!W_ERROR_IS_OK(result
)) {
7876 info
= talloc_array(mem_ctx
, union spoolss_PortInfo
, numlines
);
7878 DEBUG(10,("Returning WERR_NOMEM\n"));
7879 result
= WERR_NOMEM
;
7883 for (i
=0; i
<numlines
; i
++) {
7884 DEBUG(6,("Filling port number [%d] with port [%s]\n", i
, qlines
[i
]));
7885 result
= fill_port_1(info
, &info
[i
].info1
, qlines
[i
]);
7886 if (!W_ERROR_IS_OK(result
)) {
7891 TALLOC_FREE(qlines
);
7894 if (!W_ERROR_IS_OK(result
)) {
7896 TALLOC_FREE(qlines
);
7908 /****************************************************************************
7910 ****************************************************************************/
7912 static WERROR
enumports_level_2(TALLOC_CTX
*mem_ctx
,
7913 union spoolss_PortInfo
**info_p
,
7916 union spoolss_PortInfo
*info
= NULL
;
7918 WERROR result
= WERR_OK
;
7919 char **qlines
= NULL
;
7922 result
= enumports_hook(talloc_tos(), &numlines
, &qlines
);
7923 if (!W_ERROR_IS_OK(result
)) {
7928 info
= talloc_array(mem_ctx
, union spoolss_PortInfo
, numlines
);
7930 DEBUG(10,("Returning WERR_NOMEM\n"));
7931 result
= WERR_NOMEM
;
7935 for (i
=0; i
<numlines
; i
++) {
7936 DEBUG(6,("Filling port number [%d] with port [%s]\n", i
, qlines
[i
]));
7937 result
= fill_port_2(info
, &info
[i
].info2
, qlines
[i
]);
7938 if (!W_ERROR_IS_OK(result
)) {
7943 TALLOC_FREE(qlines
);
7946 if (!W_ERROR_IS_OK(result
)) {
7948 TALLOC_FREE(qlines
);
7960 /****************************************************************
7962 ****************************************************************/
7964 WERROR
_spoolss_EnumPorts(struct pipes_struct
*p
,
7965 struct spoolss_EnumPorts
*r
)
7969 /* that's an [in out] buffer */
7971 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
7972 return WERR_INVALID_PARAM
;
7975 DEBUG(4,("_spoolss_EnumPorts\n"));
7979 *r
->out
.info
= NULL
;
7981 switch (r
->in
.level
) {
7983 result
= enumports_level_1(p
->mem_ctx
, r
->out
.info
,
7987 result
= enumports_level_2(p
->mem_ctx
, r
->out
.info
,
7991 return WERR_UNKNOWN_LEVEL
;
7994 if (!W_ERROR_IS_OK(result
)) {
7998 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
8000 *r
->out
.info
, r
->in
.level
,
8002 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
8003 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
8005 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
8008 /****************************************************************************
8009 ****************************************************************************/
8011 static WERROR
spoolss_addprinterex_level_2(struct pipes_struct
*p
,
8013 struct spoolss_SetPrinterInfoCtr
*info_ctr
,
8014 struct spoolss_DeviceMode
*devmode
,
8015 struct security_descriptor
*secdesc
,
8016 struct spoolss_UserLevelCtr
*user_ctr
,
8017 struct policy_handle
*handle
)
8019 struct spoolss_SetPrinterInfo2
*info2
= info_ctr
->info
.info2
;
8020 uint32_t info2_mask
= SPOOLSS_PRINTER_INFO_ALL
;
8022 WERROR err
= WERR_OK
;
8024 /* samba does not have a concept of local, non-shared printers yet, so
8025 * make sure we always setup sharename - gd */
8026 if ((info2
->sharename
== NULL
|| info2
->sharename
[0] == '\0') &&
8027 (info2
->printername
!= NULL
&& info2
->printername
[0] != '\0')) {
8028 DEBUG(5, ("spoolss_addprinterex_level_2: "
8029 "no sharename has been set, setting printername %s as sharename\n",
8030 info2
->printername
));
8031 info2
->sharename
= info2
->printername
;
8034 /* check to see if the printer already exists */
8035 if ((snum
= print_queue_snum(info2
->sharename
)) != -1) {
8036 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
8038 return WERR_PRINTER_ALREADY_EXISTS
;
8041 if (!lp_force_printername(GLOBAL_SECTION_SNUM
)) {
8042 if ((snum
= print_queue_snum(info2
->printername
)) != -1) {
8043 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
8044 info2
->printername
));
8045 return WERR_PRINTER_ALREADY_EXISTS
;
8049 /* validate printer info struct */
8050 if (!info2
->printername
|| strlen(info2
->printername
) == 0) {
8051 return WERR_INVALID_PRINTER_NAME
;
8053 if (!info2
->portname
|| strlen(info2
->portname
) == 0) {
8054 return WERR_UNKNOWN_PORT
;
8056 if (!info2
->drivername
|| strlen(info2
->drivername
) == 0) {
8057 return WERR_UNKNOWN_PRINTER_DRIVER
;
8059 if (!info2
->printprocessor
|| strlen(info2
->printprocessor
) == 0) {
8060 return WERR_UNKNOWN_PRINTPROCESSOR
;
8063 /* FIXME!!! smbd should check to see if the driver is installed before
8064 trying to add a printer like this --jerry */
8066 if (*lp_addprinter_cmd() ) {
8069 raddr
= tsocket_address_inet_addr_string(p
->remote_address
,
8071 if (raddr
== NULL
) {
8075 if ( !add_printer_hook(p
->mem_ctx
, p
->session_info
->security_token
,
8078 return WERR_ACCESS_DENIED
;
8081 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no "
8082 "smb.conf parameter \"addprinter command\" is defined. This "
8083 "parameter must exist for this call to succeed\n",
8084 info2
->sharename
));
8087 if ((snum
= print_queue_snum(info2
->sharename
)) == -1) {
8088 return WERR_ACCESS_DENIED
;
8091 /* you must be a printer admin to add a new printer */
8092 if (!print_access_check(p
->session_info
,
8095 PRINTER_ACCESS_ADMINISTER
)) {
8096 return WERR_ACCESS_DENIED
;
8100 * Do sanity check on the requested changes for Samba.
8103 if (!check_printer_ok(p
->mem_ctx
, info2
, snum
)) {
8104 return WERR_INVALID_PARAM
;
8107 if (devmode
== NULL
) {
8108 info2_mask
= ~SPOOLSS_PRINTER_INFO_DEVMODE
;
8111 err
= update_dsspooler(p
->mem_ctx
,
8112 get_session_info_system(),
8117 if (!W_ERROR_IS_OK(err
)) {
8121 err
= winreg_update_printer_internal(p
->mem_ctx
,
8122 get_session_info_system(),
8129 if (!W_ERROR_IS_OK(err
)) {
8133 err
= open_printer_hnd(p
, handle
, info2
->printername
, PRINTER_ACCESS_ADMINISTER
);
8134 if (!W_ERROR_IS_OK(err
)) {
8135 /* Handle open failed - remove addition. */
8136 ZERO_STRUCTP(handle
);
8143 /****************************************************************
8144 _spoolss_AddPrinterEx
8145 ****************************************************************/
8147 WERROR
_spoolss_AddPrinterEx(struct pipes_struct
*p
,
8148 struct spoolss_AddPrinterEx
*r
)
8150 switch (r
->in
.info_ctr
->level
) {
8152 /* we don't handle yet */
8153 /* but I know what to do ... */
8154 return WERR_UNKNOWN_LEVEL
;
8156 return spoolss_addprinterex_level_2(p
, r
->in
.server
,
8158 r
->in
.devmode_ctr
->devmode
,
8159 r
->in
.secdesc_ctr
->sd
,
8160 r
->in
.userlevel_ctr
,
8163 return WERR_UNKNOWN_LEVEL
;
8167 /****************************************************************
8169 ****************************************************************/
8171 WERROR
_spoolss_AddPrinter(struct pipes_struct
*p
,
8172 struct spoolss_AddPrinter
*r
)
8174 struct spoolss_AddPrinterEx a
;
8175 struct spoolss_UserLevelCtr userlevel_ctr
;
8177 ZERO_STRUCT(userlevel_ctr
);
8179 userlevel_ctr
.level
= 1;
8181 a
.in
.server
= r
->in
.server
;
8182 a
.in
.info_ctr
= r
->in
.info_ctr
;
8183 a
.in
.devmode_ctr
= r
->in
.devmode_ctr
;
8184 a
.in
.secdesc_ctr
= r
->in
.secdesc_ctr
;
8185 a
.in
.userlevel_ctr
= &userlevel_ctr
;
8186 a
.out
.handle
= r
->out
.handle
;
8188 return _spoolss_AddPrinterEx(p
, &a
);
8191 /****************************************************************
8192 _spoolss_AddPrinterDriverEx
8193 ****************************************************************/
8195 WERROR
_spoolss_AddPrinterDriverEx(struct pipes_struct
*p
,
8196 struct spoolss_AddPrinterDriverEx
*r
)
8198 WERROR err
= WERR_OK
;
8199 const char *driver_name
= NULL
;
8204 case NDR_SPOOLSS_ADDPRINTERDRIVER
:
8205 fn
= "_spoolss_AddPrinterDriver";
8207 case NDR_SPOOLSS_ADDPRINTERDRIVEREX
:
8208 fn
= "_spoolss_AddPrinterDriverEx";
8211 return WERR_INVALID_PARAM
;
8215 * we only support the semantics of AddPrinterDriver()
8216 * i.e. only copy files that are newer than existing ones
8219 if (r
->in
.flags
== 0) {
8220 return WERR_INVALID_PARAM
;
8223 if (r
->in
.flags
!= APD_COPY_NEW_FILES
) {
8224 return WERR_ACCESS_DENIED
;
8228 if (r
->in
.info_ctr
->level
!= 3 && r
->in
.info_ctr
->level
!= 6) {
8229 /* Clever hack from Martin Zielinski <mz@seh.de>
8230 * to allow downgrade from level 8 (Vista).
8232 DEBUG(0,("%s: level %d not yet implemented\n", fn
,
8233 r
->in
.info_ctr
->level
));
8234 return WERR_UNKNOWN_LEVEL
;
8237 DEBUG(5,("Cleaning driver's information\n"));
8238 err
= clean_up_driver_struct(p
->mem_ctx
, p
->session_info
, r
->in
.info_ctr
);
8239 if (!W_ERROR_IS_OK(err
))
8242 DEBUG(5,("Moving driver to final destination\n"));
8243 err
= move_driver_to_download_area(p
->session_info
, r
->in
.info_ctr
);
8244 if (!W_ERROR_IS_OK(err
)) {
8248 err
= winreg_add_driver_internal(p
->mem_ctx
,
8249 get_session_info_system(),
8254 if (!W_ERROR_IS_OK(err
)) {
8259 * I think this is where he DrvUpgradePrinter() hook would be
8260 * be called in a driver's interface DLL on a Windows NT 4.0/2k
8261 * server. Right now, we just need to send ourselves a message
8262 * to update each printer bound to this driver. --jerry
8265 if (!srv_spoolss_drv_upgrade_printer(driver_name
, p
->msg_ctx
)) {
8266 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
8274 /****************************************************************
8275 _spoolss_AddPrinterDriver
8276 ****************************************************************/
8278 WERROR
_spoolss_AddPrinterDriver(struct pipes_struct
*p
,
8279 struct spoolss_AddPrinterDriver
*r
)
8281 struct spoolss_AddPrinterDriverEx a
;
8283 switch (r
->in
.info_ctr
->level
) {
8290 return WERR_UNKNOWN_LEVEL
;
8293 a
.in
.servername
= r
->in
.servername
;
8294 a
.in
.info_ctr
= r
->in
.info_ctr
;
8295 a
.in
.flags
= APD_COPY_NEW_FILES
;
8297 return _spoolss_AddPrinterDriverEx(p
, &a
);
8300 /****************************************************************************
8301 ****************************************************************************/
8303 struct _spoolss_paths
{
8309 enum { SPOOLSS_DRIVER_PATH
, SPOOLSS_PRTPROCS_PATH
};
8311 static const struct _spoolss_paths spoolss_paths
[]= {
8312 { SPOOLSS_DRIVER_PATH
, "print$", "DRIVERS" },
8313 { SPOOLSS_PRTPROCS_PATH
, "prnproc$", "PRTPROCS" }
8316 static WERROR
compose_spoolss_server_path(TALLOC_CTX
*mem_ctx
,
8317 const char *servername
,
8318 const char *environment
,
8322 const char *pservername
= NULL
;
8323 const char *long_archi
= SPOOLSS_ARCHITECTURE_NT_X86
;
8324 const char *short_archi
;
8328 /* environment may be empty */
8329 if (environment
&& strlen(environment
)) {
8330 long_archi
= environment
;
8333 /* servername may be empty */
8334 if (servername
&& strlen(servername
)) {
8335 pservername
= canon_servername(servername
);
8337 if (!is_myname_or_ipaddr(pservername
)) {
8338 return WERR_INVALID_PARAM
;
8342 if (!(short_archi
= get_short_archi(long_archi
))) {
8343 return WERR_INVALID_ENVIRONMENT
;
8346 switch (component
) {
8347 case SPOOLSS_PRTPROCS_PATH
:
8348 case SPOOLSS_DRIVER_PATH
:
8350 *path
= talloc_asprintf(mem_ctx
,
8353 spoolss_paths
[component
].share
,
8356 *path
= talloc_asprintf(mem_ctx
, "%s\\%s\\%s",
8357 SPOOLSS_DEFAULT_SERVER_PATH
,
8358 spoolss_paths
[component
].dir
,
8363 return WERR_INVALID_PARAM
;
8373 /****************************************************************************
8374 ****************************************************************************/
8376 static WERROR
getprinterdriverdir_level_1(TALLOC_CTX
*mem_ctx
,
8377 const char *servername
,
8378 const char *environment
,
8379 struct spoolss_DriverDirectoryInfo1
*r
)
8384 werr
= compose_spoolss_server_path(mem_ctx
,
8387 SPOOLSS_DRIVER_PATH
,
8389 if (!W_ERROR_IS_OK(werr
)) {
8393 DEBUG(4,("printer driver directory: [%s]\n", path
));
8395 r
->directory_name
= path
;
8400 /****************************************************************
8401 _spoolss_GetPrinterDriverDirectory
8402 ****************************************************************/
8404 WERROR
_spoolss_GetPrinterDriverDirectory(struct pipes_struct
*p
,
8405 struct spoolss_GetPrinterDriverDirectory
*r
)
8409 /* that's an [in out] buffer */
8411 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
8412 return WERR_INVALID_PARAM
;
8415 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
8420 /* r->in.level is ignored */
8422 werror
= getprinterdriverdir_level_1(p
->mem_ctx
,
8425 &r
->out
.info
->info1
);
8426 if (!W_ERROR_IS_OK(werror
)) {
8427 TALLOC_FREE(r
->out
.info
);
8431 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo
,
8432 r
->out
.info
, r
->in
.level
);
8433 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
8435 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
8438 /****************************************************************
8439 _spoolss_EnumPrinterData
8440 ****************************************************************/
8442 WERROR
_spoolss_EnumPrinterData(struct pipes_struct
*p
,
8443 struct spoolss_EnumPrinterData
*r
)
8446 struct spoolss_EnumPrinterDataEx r2
;
8448 struct spoolss_PrinterEnumValues
*info
, *val
= NULL
;
8451 r2
.in
.handle
= r
->in
.handle
;
8452 r2
.in
.key_name
= "PrinterDriverData";
8454 r2
.out
.count
= &count
;
8455 r2
.out
.info
= &info
;
8456 r2
.out
.needed
= &needed
;
8458 result
= _spoolss_EnumPrinterDataEx(p
, &r2
);
8459 if (W_ERROR_EQUAL(result
, WERR_MORE_DATA
)) {
8460 r2
.in
.offered
= needed
;
8461 result
= _spoolss_EnumPrinterDataEx(p
, &r2
);
8463 if (!W_ERROR_IS_OK(result
)) {
8468 * The NT machine wants to know the biggest size of value and data
8470 * cf: MSDN EnumPrinterData remark section
8473 if (!r
->in
.value_offered
&& !r
->in
.data_offered
) {
8474 uint32_t biggest_valuesize
= 0;
8475 uint32_t biggest_datasize
= 0;
8478 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
8480 for (i
=0; i
<count
; i
++) {
8482 name_length
= strlen(info
[i
].value_name
);
8483 if (strlen(info
[i
].value_name
) > biggest_valuesize
) {
8484 biggest_valuesize
= name_length
;
8487 if (info
[i
].data_length
> biggest_datasize
) {
8488 biggest_datasize
= info
[i
].data_length
;
8491 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize
,
8495 /* the value is an UNICODE string but real_value_size is the length
8496 in bytes including the trailing 0 */
8498 *r
->out
.value_needed
= 2 * (1 + biggest_valuesize
);
8499 *r
->out
.data_needed
= biggest_datasize
;
8501 DEBUG(6,("final values: [%d], [%d]\n",
8502 *r
->out
.value_needed
, *r
->out
.data_needed
));
8507 if (r
->in
.enum_index
< count
) {
8508 val
= &info
[r
->in
.enum_index
];
8512 /* out_value should default to "" or else NT4 has
8513 problems unmarshalling the response */
8515 if (r
->in
.value_offered
) {
8516 *r
->out
.value_needed
= 1;
8517 r
->out
.value_name
= talloc_strdup(r
, "");
8518 if (!r
->out
.value_name
) {
8522 r
->out
.value_name
= NULL
;
8523 *r
->out
.value_needed
= 0;
8526 /* the data is counted in bytes */
8528 *r
->out
.data_needed
= r
->in
.data_offered
;
8530 result
= WERR_NO_MORE_ITEMS
;
8534 * - counted in bytes in the request
8535 * - counted in UNICODE chars in the max reply
8536 * - counted in bytes in the real size
8538 * take a pause *before* coding not *during* coding
8542 if (r
->in
.value_offered
) {
8543 r
->out
.value_name
= talloc_strdup(r
, val
->value_name
);
8544 if (!r
->out
.value_name
) {
8547 *r
->out
.value_needed
= val
->value_name_len
;
8549 r
->out
.value_name
= NULL
;
8550 *r
->out
.value_needed
= 0;
8555 *r
->out
.type
= val
->type
;
8557 /* data - counted in bytes */
8560 * See the section "Dynamically Typed Query Parameters"
8564 if (r
->out
.data
&& val
->data
&& val
->data
->data
&&
8565 val
->data_length
&& r
->in
.data_offered
) {
8566 memcpy(r
->out
.data
, val
->data
->data
,
8567 MIN(val
->data_length
,r
->in
.data_offered
));
8570 *r
->out
.data_needed
= val
->data_length
;
8578 /****************************************************************
8579 _spoolss_SetPrinterData
8580 ****************************************************************/
8582 WERROR
_spoolss_SetPrinterData(struct pipes_struct
*p
,
8583 struct spoolss_SetPrinterData
*r
)
8585 struct spoolss_SetPrinterDataEx r2
;
8587 r2
.in
.handle
= r
->in
.handle
;
8588 r2
.in
.key_name
= "PrinterDriverData";
8589 r2
.in
.value_name
= r
->in
.value_name
;
8590 r2
.in
.type
= r
->in
.type
;
8591 r2
.in
.data
= r
->in
.data
;
8592 r2
.in
.offered
= r
->in
.offered
;
8594 return _spoolss_SetPrinterDataEx(p
, &r2
);
8597 /****************************************************************
8598 _spoolss_ResetPrinter
8599 ****************************************************************/
8601 WERROR
_spoolss_ResetPrinter(struct pipes_struct
*p
,
8602 struct spoolss_ResetPrinter
*r
)
8604 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
8607 DEBUG(5,("_spoolss_ResetPrinter\n"));
8610 * All we do is to check to see if the handle and queue is valid.
8611 * This call really doesn't mean anything to us because we only
8612 * support RAW printing. --jerry
8616 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
8617 OUR_HANDLE(r
->in
.handle
)));
8621 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
))
8625 /* blindly return success */
8629 /****************************************************************
8630 _spoolss_DeletePrinterData
8631 ****************************************************************/
8633 WERROR
_spoolss_DeletePrinterData(struct pipes_struct
*p
,
8634 struct spoolss_DeletePrinterData
*r
)
8636 struct spoolss_DeletePrinterDataEx r2
;
8638 r2
.in
.handle
= r
->in
.handle
;
8639 r2
.in
.key_name
= "PrinterDriverData";
8640 r2
.in
.value_name
= r
->in
.value_name
;
8642 return _spoolss_DeletePrinterDataEx(p
, &r2
);
8645 /****************************************************************
8647 ****************************************************************/
8649 WERROR
_spoolss_AddForm(struct pipes_struct
*p
,
8650 struct spoolss_AddForm
*r
)
8652 struct spoolss_AddFormInfo1
*form
= r
->in
.info
.info1
;
8654 WERROR status
= WERR_OK
;
8655 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
8656 struct dcerpc_binding_handle
*b
;
8657 TALLOC_CTX
*tmp_ctx
= NULL
;
8659 DEBUG(5,("_spoolss_AddForm\n"));
8662 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
8663 OUR_HANDLE(r
->in
.handle
)));
8667 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8668 and not a printer admin, then fail */
8670 if ((p
->session_info
->unix_token
->uid
!= sec_initial_uid()) &&
8671 !security_token_has_privilege(p
->session_info
->security_token
, SEC_PRIV_PRINT_OPERATOR
) &&
8672 !token_contains_name_in_list(uidtoname(p
->session_info
->unix_token
->uid
),
8673 p
->session_info
->info
->domain_name
,
8675 p
->session_info
->security_token
,
8676 lp_printer_admin(snum
))) {
8677 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
8678 return WERR_ACCESS_DENIED
;
8681 switch (form
->flags
) {
8682 case SPOOLSS_FORM_USER
:
8683 case SPOOLSS_FORM_BUILTIN
:
8684 case SPOOLSS_FORM_PRINTER
:
8687 return WERR_INVALID_PARAM
;
8690 tmp_ctx
= talloc_new(p
->mem_ctx
);
8695 status
= winreg_printer_binding_handle(tmp_ctx
,
8696 get_session_info_system(),
8699 if (!W_ERROR_IS_OK(status
)) {
8703 status
= winreg_printer_addform1(tmp_ctx
, b
, form
);
8704 if (!W_ERROR_IS_OK(status
)) {
8709 * ChangeID must always be set if this is a printer
8711 if (Printer
->printer_type
== SPLHND_PRINTER
) {
8712 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
8713 status
= WERR_BADFID
;
8717 status
= winreg_printer_update_changeid(tmp_ctx
, b
,
8718 lp_const_servicename(snum
));
8722 talloc_free(tmp_ctx
);
8726 /****************************************************************
8728 ****************************************************************/
8730 WERROR
_spoolss_DeleteForm(struct pipes_struct
*p
,
8731 struct spoolss_DeleteForm
*r
)
8733 const char *form_name
= r
->in
.form_name
;
8734 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
8736 WERROR status
= WERR_OK
;
8737 struct dcerpc_binding_handle
*b
;
8738 TALLOC_CTX
*tmp_ctx
= NULL
;
8740 DEBUG(5,("_spoolss_DeleteForm\n"));
8743 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
8744 OUR_HANDLE(r
->in
.handle
)));
8748 if ((p
->session_info
->unix_token
->uid
!= sec_initial_uid()) &&
8749 !security_token_has_privilege(p
->session_info
->security_token
, SEC_PRIV_PRINT_OPERATOR
) &&
8750 !token_contains_name_in_list(uidtoname(p
->session_info
->unix_token
->uid
),
8751 p
->session_info
->info
->domain_name
,
8753 p
->session_info
->security_token
,
8754 lp_printer_admin(snum
))) {
8755 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
8756 return WERR_ACCESS_DENIED
;
8759 tmp_ctx
= talloc_new(p
->mem_ctx
);
8764 status
= winreg_printer_binding_handle(tmp_ctx
,
8765 get_session_info_system(),
8768 if (!W_ERROR_IS_OK(status
)) {
8772 status
= winreg_printer_deleteform1(tmp_ctx
, b
, form_name
);
8773 if (!W_ERROR_IS_OK(status
)) {
8778 * ChangeID must always be set if this is a printer
8780 if (Printer
->printer_type
== SPLHND_PRINTER
) {
8781 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
8782 status
= WERR_BADFID
;
8786 status
= winreg_printer_update_changeid(tmp_ctx
, b
,
8787 lp_const_servicename(snum
));
8791 talloc_free(tmp_ctx
);
8795 /****************************************************************
8797 ****************************************************************/
8799 WERROR
_spoolss_SetForm(struct pipes_struct
*p
,
8800 struct spoolss_SetForm
*r
)
8802 struct spoolss_AddFormInfo1
*form
= r
->in
.info
.info1
;
8803 const char *form_name
= r
->in
.form_name
;
8805 WERROR status
= WERR_OK
;
8806 struct dcerpc_binding_handle
*b
;
8807 TALLOC_CTX
*tmp_ctx
= NULL
;
8809 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
8811 DEBUG(5,("_spoolss_SetForm\n"));
8814 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8815 OUR_HANDLE(r
->in
.handle
)));
8819 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8820 and not a printer admin, then fail */
8822 if ((p
->session_info
->unix_token
->uid
!= sec_initial_uid()) &&
8823 !security_token_has_privilege(p
->session_info
->security_token
, SEC_PRIV_PRINT_OPERATOR
) &&
8824 !token_contains_name_in_list(uidtoname(p
->session_info
->unix_token
->uid
),
8825 p
->session_info
->info
->domain_name
,
8827 p
->session_info
->security_token
,
8828 lp_printer_admin(snum
))) {
8829 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
8830 return WERR_ACCESS_DENIED
;
8833 tmp_ctx
= talloc_new(p
->mem_ctx
);
8838 status
= winreg_printer_binding_handle(tmp_ctx
,
8839 get_session_info_system(),
8842 if (!W_ERROR_IS_OK(status
)) {
8846 status
= winreg_printer_setform1(tmp_ctx
, b
,
8849 if (!W_ERROR_IS_OK(status
)) {
8854 * ChangeID must always be set if this is a printer
8856 if (Printer
->printer_type
== SPLHND_PRINTER
) {
8857 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
8858 status
= WERR_BADFID
;
8862 status
= winreg_printer_update_changeid(tmp_ctx
, b
,
8863 lp_const_servicename(snum
));
8867 talloc_free(tmp_ctx
);
8871 /****************************************************************************
8872 fill_print_processor1
8873 ****************************************************************************/
8875 static WERROR
fill_print_processor1(TALLOC_CTX
*mem_ctx
,
8876 struct spoolss_PrintProcessorInfo1
*r
,
8877 const char *print_processor_name
)
8879 r
->print_processor_name
= talloc_strdup(mem_ctx
, print_processor_name
);
8880 W_ERROR_HAVE_NO_MEMORY(r
->print_processor_name
);
8885 /****************************************************************************
8886 enumprintprocessors level 1.
8887 ****************************************************************************/
8889 static WERROR
enumprintprocessors_level_1(TALLOC_CTX
*mem_ctx
,
8890 union spoolss_PrintProcessorInfo
**info_p
,
8893 union spoolss_PrintProcessorInfo
*info
;
8896 info
= talloc_array(mem_ctx
, union spoolss_PrintProcessorInfo
, 1);
8897 W_ERROR_HAVE_NO_MEMORY(info
);
8901 result
= fill_print_processor1(info
, &info
[0].info1
, "winprint");
8902 if (!W_ERROR_IS_OK(result
)) {
8907 if (!W_ERROR_IS_OK(result
)) {
8918 /****************************************************************
8919 _spoolss_EnumPrintProcessors
8920 ****************************************************************/
8922 WERROR
_spoolss_EnumPrintProcessors(struct pipes_struct
*p
,
8923 struct spoolss_EnumPrintProcessors
*r
)
8927 /* that's an [in out] buffer */
8929 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
8930 return WERR_INVALID_PARAM
;
8933 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8936 * Enumerate the print processors ...
8938 * Just reply with "winprint", to keep NT happy
8939 * and I can use my nice printer checker.
8944 *r
->out
.info
= NULL
;
8946 if (!get_short_archi(r
->in
.environment
)) {
8947 return WERR_INVALID_ENVIRONMENT
;
8950 switch (r
->in
.level
) {
8952 result
= enumprintprocessors_level_1(p
->mem_ctx
, r
->out
.info
,
8956 return WERR_UNKNOWN_LEVEL
;
8959 if (!W_ERROR_IS_OK(result
)) {
8963 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
8964 spoolss_EnumPrintProcessors
,
8965 *r
->out
.info
, r
->in
.level
,
8967 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
8968 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
8970 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
8973 /****************************************************************************
8974 fill_printprocdatatype1
8975 ****************************************************************************/
8977 static WERROR
fill_printprocdatatype1(TALLOC_CTX
*mem_ctx
,
8978 struct spoolss_PrintProcDataTypesInfo1
*r
,
8979 const char *name_array
)
8981 r
->name_array
= talloc_strdup(mem_ctx
, name_array
);
8982 W_ERROR_HAVE_NO_MEMORY(r
->name_array
);
8987 /****************************************************************************
8988 enumprintprocdatatypes level 1.
8989 ****************************************************************************/
8991 static WERROR
enumprintprocdatatypes_level_1(TALLOC_CTX
*mem_ctx
,
8992 union spoolss_PrintProcDataTypesInfo
**info_p
,
8996 union spoolss_PrintProcDataTypesInfo
*info
;
8998 info
= talloc_array(mem_ctx
, union spoolss_PrintProcDataTypesInfo
, 1);
8999 W_ERROR_HAVE_NO_MEMORY(info
);
9003 result
= fill_printprocdatatype1(info
, &info
[0].info1
, "RAW");
9004 if (!W_ERROR_IS_OK(result
)) {
9009 if (!W_ERROR_IS_OK(result
)) {
9020 /****************************************************************
9021 _spoolss_EnumPrintProcDataTypes
9022 ****************************************************************/
9024 WERROR
_spoolss_EnumPrintProcDataTypes(struct pipes_struct
*p
,
9025 struct spoolss_EnumPrintProcDataTypes
*r
)
9029 /* that's an [in out] buffer */
9031 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
9032 return WERR_INVALID_PARAM
;
9035 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
9039 *r
->out
.info
= NULL
;
9041 if (r
->in
.print_processor_name
== NULL
||
9042 !strequal(r
->in
.print_processor_name
, "winprint")) {
9043 return WERR_UNKNOWN_PRINTPROCESSOR
;
9046 switch (r
->in
.level
) {
9048 result
= enumprintprocdatatypes_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_EnumPrintProcDataTypes
,
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 /****************************************************************************
9071 ****************************************************************************/
9073 static WERROR
fill_monitor_1(TALLOC_CTX
*mem_ctx
,
9074 struct spoolss_MonitorInfo1
*r
,
9075 const char *monitor_name
)
9077 r
->monitor_name
= talloc_strdup(mem_ctx
, monitor_name
);
9078 W_ERROR_HAVE_NO_MEMORY(r
->monitor_name
);
9083 /****************************************************************************
9085 ****************************************************************************/
9087 static WERROR
fill_monitor_2(TALLOC_CTX
*mem_ctx
,
9088 struct spoolss_MonitorInfo2
*r
,
9089 const char *monitor_name
,
9090 const char *environment
,
9091 const char *dll_name
)
9093 r
->monitor_name
= talloc_strdup(mem_ctx
, monitor_name
);
9094 W_ERROR_HAVE_NO_MEMORY(r
->monitor_name
);
9095 r
->environment
= talloc_strdup(mem_ctx
, environment
);
9096 W_ERROR_HAVE_NO_MEMORY(r
->environment
);
9097 r
->dll_name
= talloc_strdup(mem_ctx
, dll_name
);
9098 W_ERROR_HAVE_NO_MEMORY(r
->dll_name
);
9103 /****************************************************************************
9104 enumprintmonitors level 1.
9105 ****************************************************************************/
9107 static WERROR
enumprintmonitors_level_1(TALLOC_CTX
*mem_ctx
,
9108 union spoolss_MonitorInfo
**info_p
,
9111 union spoolss_MonitorInfo
*info
;
9112 WERROR result
= WERR_OK
;
9114 info
= talloc_array(mem_ctx
, union spoolss_MonitorInfo
, 2);
9115 W_ERROR_HAVE_NO_MEMORY(info
);
9119 result
= fill_monitor_1(info
, &info
[0].info1
,
9121 if (!W_ERROR_IS_OK(result
)) {
9125 result
= fill_monitor_1(info
, &info
[1].info1
,
9127 if (!W_ERROR_IS_OK(result
)) {
9132 if (!W_ERROR_IS_OK(result
)) {
9143 /****************************************************************************
9144 enumprintmonitors level 2.
9145 ****************************************************************************/
9147 static WERROR
enumprintmonitors_level_2(TALLOC_CTX
*mem_ctx
,
9148 union spoolss_MonitorInfo
**info_p
,
9151 union spoolss_MonitorInfo
*info
;
9152 WERROR result
= WERR_OK
;
9154 info
= talloc_array(mem_ctx
, union spoolss_MonitorInfo
, 2);
9155 W_ERROR_HAVE_NO_MEMORY(info
);
9159 result
= fill_monitor_2(info
, &info
[0].info2
,
9161 "Windows NT X86", /* FIXME */
9163 if (!W_ERROR_IS_OK(result
)) {
9167 result
= fill_monitor_2(info
, &info
[1].info2
,
9169 "Windows NT X86", /* FIXME */
9171 if (!W_ERROR_IS_OK(result
)) {
9176 if (!W_ERROR_IS_OK(result
)) {
9187 /****************************************************************
9188 _spoolss_EnumMonitors
9189 ****************************************************************/
9191 WERROR
_spoolss_EnumMonitors(struct pipes_struct
*p
,
9192 struct spoolss_EnumMonitors
*r
)
9196 /* that's an [in out] buffer */
9198 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
9199 return WERR_INVALID_PARAM
;
9202 DEBUG(5,("_spoolss_EnumMonitors\n"));
9205 * Enumerate the print monitors ...
9207 * Just reply with "Local Port", to keep NT happy
9208 * and I can use my nice printer checker.
9213 *r
->out
.info
= NULL
;
9215 switch (r
->in
.level
) {
9217 result
= enumprintmonitors_level_1(p
->mem_ctx
, r
->out
.info
,
9221 result
= enumprintmonitors_level_2(p
->mem_ctx
, r
->out
.info
,
9225 return WERR_UNKNOWN_LEVEL
;
9228 if (!W_ERROR_IS_OK(result
)) {
9232 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
9233 spoolss_EnumMonitors
,
9234 *r
->out
.info
, r
->in
.level
,
9236 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
9237 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
9239 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
9242 /****************************************************************************
9243 ****************************************************************************/
9245 static WERROR
getjob_level_1(TALLOC_CTX
*mem_ctx
,
9246 const print_queue_struct
*queue
,
9247 int count
, int snum
,
9248 struct spoolss_PrinterInfo2
*pinfo2
,
9250 struct spoolss_JobInfo1
*r
)
9255 for (i
=0; i
<count
; i
++) {
9256 if (queue
[i
].job
== (int)jobid
) {
9262 if (found
== false) {
9263 /* NT treats not found as bad param... yet another bad choice */
9264 return WERR_INVALID_PARAM
;
9267 return fill_job_info1(mem_ctx
,
9275 /****************************************************************************
9276 ****************************************************************************/
9278 static WERROR
getjob_level_2(TALLOC_CTX
*mem_ctx
,
9279 const print_queue_struct
*queue
,
9280 int count
, int snum
,
9281 struct spoolss_PrinterInfo2
*pinfo2
,
9283 struct spoolss_JobInfo2
*r
)
9287 struct spoolss_DeviceMode
*devmode
;
9290 for (i
=0; i
<count
; i
++) {
9291 if (queue
[i
].job
== (int)jobid
) {
9297 if (found
== false) {
9298 /* NT treats not found as bad param... yet another bad
9300 return WERR_INVALID_PARAM
;
9304 * if the print job does not have a DEVMODE associated with it,
9305 * just use the one for the printer. A NULL devicemode is not
9306 * a failure condition
9309 devmode
= print_job_devmode(lp_const_servicename(snum
), jobid
);
9311 result
= spoolss_create_default_devmode(mem_ctx
,
9312 pinfo2
->printername
,
9314 if (!W_ERROR_IS_OK(result
)) {
9315 DEBUG(3, ("Can't proceed w/o a devmode!"));
9320 return fill_job_info2(mem_ctx
,
9329 /****************************************************************
9331 ****************************************************************/
9333 WERROR
_spoolss_GetJob(struct pipes_struct
*p
,
9334 struct spoolss_GetJob
*r
)
9336 WERROR result
= WERR_OK
;
9337 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
9340 print_queue_struct
*queue
= NULL
;
9341 print_status_struct prt_status
;
9343 /* that's an [in out] buffer */
9345 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
9346 return WERR_INVALID_PARAM
;
9349 DEBUG(5,("_spoolss_GetJob\n"));
9353 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9357 result
= winreg_get_printer_internal(p
->mem_ctx
,
9358 get_session_info_system(),
9360 lp_const_servicename(snum
),
9362 if (!W_ERROR_IS_OK(result
)) {
9366 count
= print_queue_status(p
->msg_ctx
, snum
, &queue
, &prt_status
);
9368 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
9369 count
, prt_status
.status
, prt_status
.message
));
9371 switch (r
->in
.level
) {
9373 result
= getjob_level_1(p
->mem_ctx
,
9374 queue
, count
, snum
, pinfo2
,
9375 r
->in
.job_id
, &r
->out
.info
->info1
);
9378 result
= getjob_level_2(p
->mem_ctx
,
9379 queue
, count
, snum
, pinfo2
,
9380 r
->in
.job_id
, &r
->out
.info
->info2
);
9383 result
= WERR_UNKNOWN_LEVEL
;
9388 TALLOC_FREE(pinfo2
);
9390 if (!W_ERROR_IS_OK(result
)) {
9391 TALLOC_FREE(r
->out
.info
);
9395 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_JobInfo
, r
->out
.info
,
9397 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
9399 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
9402 /****************************************************************
9403 _spoolss_GetPrinterDataEx
9404 ****************************************************************/
9406 WERROR
_spoolss_GetPrinterDataEx(struct pipes_struct
*p
,
9407 struct spoolss_GetPrinterDataEx
*r
)
9410 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9411 const char *printer
;
9413 WERROR result
= WERR_OK
;
9415 enum winreg_Type val_type
= REG_NONE
;
9416 uint8_t *val_data
= NULL
;
9417 uint32_t val_size
= 0;
9418 struct dcerpc_binding_handle
*b
;
9419 TALLOC_CTX
*tmp_ctx
;
9421 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
9423 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
9424 r
->in
.key_name
, r
->in
.value_name
));
9426 /* in case of problem, return some default values */
9429 *r
->out
.type
= REG_NONE
;
9431 tmp_ctx
= talloc_new(p
->mem_ctx
);
9437 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9438 OUR_HANDLE(r
->in
.handle
)));
9439 result
= WERR_BADFID
;
9443 /* check to see if the keyname is valid */
9444 if (!strlen(r
->in
.key_name
)) {
9445 result
= WERR_INVALID_PARAM
;
9449 /* Is the handle to a printer or to the server? */
9451 if (Printer
->printer_type
== SPLHND_SERVER
) {
9453 union spoolss_PrinterData data
;
9455 result
= getprinterdata_printer_server(tmp_ctx
,
9459 if (!W_ERROR_IS_OK(result
)) {
9463 result
= push_spoolss_PrinterData(tmp_ctx
, &blob
,
9464 *r
->out
.type
, &data
);
9465 if (!W_ERROR_IS_OK(result
)) {
9469 *r
->out
.needed
= blob
.length
;
9471 if (r
->in
.offered
>= *r
->out
.needed
) {
9472 memcpy(r
->out
.data
, blob
.data
, blob
.length
);
9479 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9480 result
= WERR_BADFID
;
9483 printer
= lp_const_servicename(snum
);
9485 result
= winreg_printer_binding_handle(tmp_ctx
,
9486 get_session_info_system(),
9489 if (!W_ERROR_IS_OK(result
)) {
9493 /* XP sends this and wants the ChangeID value from PRINTER_INFO_0 */
9494 if (strequal(r
->in
.key_name
, SPOOL_PRINTERDATA_KEY
) &&
9495 strequal(r
->in
.value_name
, "ChangeId")) {
9496 *r
->out
.type
= REG_DWORD
;
9498 if (r
->in
.offered
>= *r
->out
.needed
) {
9499 uint32_t changeid
= 0;
9501 result
= winreg_printer_get_changeid(tmp_ctx
, b
,
9504 if (!W_ERROR_IS_OK(result
)) {
9508 SIVAL(r
->out
.data
, 0, changeid
);
9514 result
= winreg_get_printer_dataex(tmp_ctx
, b
,
9521 if (!W_ERROR_IS_OK(result
)) {
9525 *r
->out
.needed
= val_size
;
9526 *r
->out
.type
= val_type
;
9528 if (r
->in
.offered
>= *r
->out
.needed
) {
9529 memcpy(r
->out
.data
, val_data
, val_size
);
9533 /* NOTE: do not replace type when returning WERR_MORE_DATA */
9535 if (W_ERROR_IS_OK(result
)) {
9536 result
= SPOOLSS_BUFFER_OK(WERR_OK
, WERR_MORE_DATA
);
9539 talloc_free(tmp_ctx
);
9543 /****************************************************************
9544 _spoolss_SetPrinterDataEx
9545 ****************************************************************/
9547 WERROR
_spoolss_SetPrinterDataEx(struct pipes_struct
*p
,
9548 struct spoolss_SetPrinterDataEx
*r
)
9550 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
9552 WERROR result
= WERR_OK
;
9553 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9555 struct dcerpc_binding_handle
*b
;
9556 TALLOC_CTX
*tmp_ctx
;
9558 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
9560 /* From MSDN documentation of SetPrinterDataEx: pass request to
9561 SetPrinterData if key is "PrinterDriverData" */
9564 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9565 OUR_HANDLE(r
->in
.handle
)));
9569 if (Printer
->printer_type
== SPLHND_SERVER
) {
9570 DEBUG(10,("_spoolss_SetPrinterDataEx: "
9571 "Not implemented for server handles yet\n"));
9572 return WERR_INVALID_PARAM
;
9575 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9580 * Access check : NT returns "access denied" if you make a
9581 * SetPrinterData call without the necessary privildge.
9582 * we were originally returning OK if nothing changed
9583 * which made Win2k issue **a lot** of SetPrinterData
9584 * when connecting to a printer --jerry
9587 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
9588 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
9589 "change denied by handle access permissions\n"));
9590 return WERR_ACCESS_DENIED
;
9593 tmp_ctx
= talloc_new(p
->mem_ctx
);
9598 result
= winreg_printer_binding_handle(tmp_ctx
,
9599 get_session_info_system(),
9602 if (!W_ERROR_IS_OK(result
)) {
9606 result
= winreg_get_printer(tmp_ctx
, b
,
9607 lp_servicename(snum
),
9609 if (!W_ERROR_IS_OK(result
)) {
9613 /* check for OID in valuename */
9615 oid_string
= strchr(r
->in
.value_name
, ',');
9621 /* save the registry data */
9623 result
= winreg_set_printer_dataex(tmp_ctx
, b
,
9631 if (W_ERROR_IS_OK(result
)) {
9632 /* save the OID if one was specified */
9634 char *str
= talloc_asprintf(tmp_ctx
, "%s\\%s",
9635 r
->in
.key_name
, SPOOL_OID_KEY
);
9637 result
= WERR_NOMEM
;
9642 * I'm not checking the status here on purpose. Don't know
9643 * if this is right, but I'm returning the status from the
9644 * previous set_printer_dataex() call. I have no idea if
9645 * this is right. --jerry
9647 winreg_set_printer_dataex(tmp_ctx
, b
,
9652 (uint8_t *) oid_string
,
9653 strlen(oid_string
) + 1);
9656 result
= winreg_printer_update_changeid(tmp_ctx
, b
,
9657 lp_const_servicename(snum
));
9662 talloc_free(tmp_ctx
);
9666 /****************************************************************
9667 _spoolss_DeletePrinterDataEx
9668 ****************************************************************/
9670 WERROR
_spoolss_DeletePrinterDataEx(struct pipes_struct
*p
,
9671 struct spoolss_DeletePrinterDataEx
*r
)
9673 const char *printer
;
9675 WERROR status
= WERR_OK
;
9676 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9678 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
9681 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
9682 "Invalid handle (%s:%u:%u).\n",
9683 OUR_HANDLE(r
->in
.handle
)));
9687 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
9688 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
9689 "printer properties change denied by handle\n"));
9690 return WERR_ACCESS_DENIED
;
9693 if (!r
->in
.value_name
|| !r
->in
.key_name
) {
9697 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9700 printer
= lp_const_servicename(snum
);
9702 status
= winreg_delete_printer_dataex_internal(p
->mem_ctx
,
9703 get_session_info_system(),
9708 if (W_ERROR_IS_OK(status
)) {
9709 status
= winreg_printer_update_changeid_internal(p
->mem_ctx
,
9710 get_session_info_system(),
9718 /****************************************************************
9719 _spoolss_EnumPrinterKey
9720 ****************************************************************/
9722 WERROR
_spoolss_EnumPrinterKey(struct pipes_struct
*p
,
9723 struct spoolss_EnumPrinterKey
*r
)
9726 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9728 WERROR result
= WERR_BADFILE
;
9729 const char **array
= NULL
;
9732 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
9735 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
9736 OUR_HANDLE(r
->in
.handle
)));
9740 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9744 result
= winreg_enum_printer_key_internal(p
->mem_ctx
,
9745 get_session_info_system(),
9747 lp_const_servicename(snum
),
9751 if (!W_ERROR_IS_OK(result
)) {
9755 if (!push_reg_multi_sz(p
->mem_ctx
, &blob
, array
)) {
9756 result
= WERR_NOMEM
;
9760 *r
->out
._ndr_size
= r
->in
.offered
/ 2;
9761 *r
->out
.needed
= blob
.length
;
9763 if (r
->in
.offered
< *r
->out
.needed
) {
9764 result
= WERR_MORE_DATA
;
9767 r
->out
.key_buffer
->string_array
= array
;
9771 if (!W_ERROR_IS_OK(result
)) {
9773 if (!W_ERROR_EQUAL(result
, WERR_MORE_DATA
)) {
9781 /****************************************************************
9782 _spoolss_DeletePrinterKey
9783 ****************************************************************/
9785 WERROR
_spoolss_DeletePrinterKey(struct pipes_struct
*p
,
9786 struct spoolss_DeletePrinterKey
*r
)
9788 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9791 const char *printer
;
9792 struct dcerpc_binding_handle
*b
;
9793 TALLOC_CTX
*tmp_ctx
;
9795 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
9798 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
9799 OUR_HANDLE(r
->in
.handle
)));
9803 /* if keyname == NULL, return error */
9804 if ( !r
->in
.key_name
)
9805 return WERR_INVALID_PARAM
;
9807 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9811 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
9812 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9813 "printer properties change denied by handle\n"));
9814 return WERR_ACCESS_DENIED
;
9817 printer
= lp_const_servicename(snum
);
9819 tmp_ctx
= talloc_new(p
->mem_ctx
);
9824 status
= winreg_printer_binding_handle(tmp_ctx
,
9825 get_session_info_system(),
9828 if (!W_ERROR_IS_OK(status
)) {
9832 /* delete the key and all subkeys */
9833 status
= winreg_delete_printer_key(tmp_ctx
, b
,
9836 if (W_ERROR_IS_OK(status
)) {
9837 status
= winreg_printer_update_changeid(tmp_ctx
, b
,
9842 talloc_free(tmp_ctx
);
9846 /****************************************************************
9847 _spoolss_EnumPrinterDataEx
9848 ****************************************************************/
9850 WERROR
_spoolss_EnumPrinterDataEx(struct pipes_struct
*p
,
9851 struct spoolss_EnumPrinterDataEx
*r
)
9854 struct spoolss_PrinterEnumValues
*info
= NULL
;
9855 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9859 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
9863 *r
->out
.info
= NULL
;
9866 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
9867 OUR_HANDLE(r
->in
.handle
)));
9872 * first check for a keyname of NULL or "". Win2k seems to send
9873 * this a lot and we should send back WERR_INVALID_PARAM
9874 * no need to spend time looking up the printer in this case.
9878 if (!strlen(r
->in
.key_name
)) {
9879 result
= WERR_INVALID_PARAM
;
9883 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9887 /* now look for a match on the key name */
9888 result
= winreg_enum_printer_dataex_internal(p
->mem_ctx
,
9889 get_session_info_system(),
9891 lp_const_servicename(snum
),
9895 if (!W_ERROR_IS_OK(result
)) {
9899 #if 0 /* FIXME - gd */
9900 /* housekeeping information in the reply */
9902 /* Fix from Martin Zielinski <mz@seh.de> - ensure
9903 * the hand marshalled container size is a multiple
9904 * of 4 bytes for RPC alignment.
9908 needed
+= 4-(needed
% 4);
9911 *r
->out
.count
= count
;
9912 *r
->out
.info
= info
;
9915 if (!W_ERROR_IS_OK(result
)) {
9919 *r
->out
.needed
= SPOOLSS_BUFFER_ARRAY(p
->mem_ctx
,
9920 spoolss_EnumPrinterDataEx
,
9923 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
9924 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, *r
->out
.count
);
9926 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_MORE_DATA
);
9929 /****************************************************************************
9930 ****************************************************************************/
9932 static WERROR
getprintprocessordirectory_level_1(TALLOC_CTX
*mem_ctx
,
9933 const char *servername
,
9934 const char *environment
,
9935 struct spoolss_PrintProcessorDirectoryInfo1
*r
)
9940 werr
= compose_spoolss_server_path(mem_ctx
,
9943 SPOOLSS_PRTPROCS_PATH
,
9945 if (!W_ERROR_IS_OK(werr
)) {
9949 DEBUG(4,("print processor directory: [%s]\n", path
));
9951 r
->directory_name
= path
;
9956 /****************************************************************
9957 _spoolss_GetPrintProcessorDirectory
9958 ****************************************************************/
9960 WERROR
_spoolss_GetPrintProcessorDirectory(struct pipes_struct
*p
,
9961 struct spoolss_GetPrintProcessorDirectory
*r
)
9964 char *prnproc_share
= NULL
;
9965 bool prnproc_share_exists
= false;
9968 /* that's an [in out] buffer */
9970 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
9971 return WERR_INVALID_PARAM
;
9974 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9979 /* r->in.level is ignored */
9981 /* We always should reply with a local print processor directory so that
9982 * users are not forced to have a [prnproc$] share on the Samba spoolss
9983 * server, if users decide to do so, lets announce it though - Guenther */
9985 snum
= find_service(talloc_tos(), "prnproc$", &prnproc_share
);
9986 if (!prnproc_share
) {
9990 prnproc_share_exists
= true;
9993 result
= getprintprocessordirectory_level_1(p
->mem_ctx
,
9994 prnproc_share_exists
? r
->in
.server
: NULL
,
9996 &r
->out
.info
->info1
);
9997 if (!W_ERROR_IS_OK(result
)) {
9998 TALLOC_FREE(r
->out
.info
);
10002 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo
,
10003 r
->out
.info
, r
->in
.level
);
10004 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
10006 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
10009 /*******************************************************************
10010 ********************************************************************/
10012 static bool push_monitorui_buf(TALLOC_CTX
*mem_ctx
, DATA_BLOB
*buf
,
10013 const char *dllname
)
10015 enum ndr_err_code ndr_err
;
10016 struct spoolss_MonitorUi ui
;
10018 ui
.dll_name
= dllname
;
10020 ndr_err
= ndr_push_struct_blob(buf
, mem_ctx
, &ui
,
10021 (ndr_push_flags_fn_t
)ndr_push_spoolss_MonitorUi
);
10022 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err
) && (DEBUGLEVEL
>= 10)) {
10023 NDR_PRINT_DEBUG(spoolss_MonitorUi
, &ui
);
10025 return NDR_ERR_CODE_IS_SUCCESS(ndr_err
);
10028 /*******************************************************************
10029 Streams the monitor UI DLL name in UNICODE
10030 *******************************************************************/
10032 static WERROR
xcvtcp_monitorui(TALLOC_CTX
*mem_ctx
,
10033 struct security_token
*token
, DATA_BLOB
*in
,
10034 DATA_BLOB
*out
, uint32_t *needed
)
10036 const char *dllname
= "tcpmonui.dll";
10038 *needed
= (strlen(dllname
)+1) * 2;
10040 if (out
->length
< *needed
) {
10041 return WERR_INSUFFICIENT_BUFFER
;
10044 if (!push_monitorui_buf(mem_ctx
, out
, dllname
)) {
10051 /*******************************************************************
10052 ********************************************************************/
10054 static bool pull_port_data_1(TALLOC_CTX
*mem_ctx
,
10055 struct spoolss_PortData1
*port1
,
10056 const DATA_BLOB
*buf
)
10058 enum ndr_err_code ndr_err
;
10059 ndr_err
= ndr_pull_struct_blob(buf
, mem_ctx
, port1
,
10060 (ndr_pull_flags_fn_t
)ndr_pull_spoolss_PortData1
);
10061 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err
) && (DEBUGLEVEL
>= 10)) {
10062 NDR_PRINT_DEBUG(spoolss_PortData1
, port1
);
10064 return NDR_ERR_CODE_IS_SUCCESS(ndr_err
);
10067 /*******************************************************************
10068 ********************************************************************/
10070 static bool pull_port_data_2(TALLOC_CTX
*mem_ctx
,
10071 struct spoolss_PortData2
*port2
,
10072 const DATA_BLOB
*buf
)
10074 enum ndr_err_code ndr_err
;
10075 ndr_err
= ndr_pull_struct_blob(buf
, mem_ctx
, port2
,
10076 (ndr_pull_flags_fn_t
)ndr_pull_spoolss_PortData2
);
10077 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err
) && (DEBUGLEVEL
>= 10)) {
10078 NDR_PRINT_DEBUG(spoolss_PortData2
, port2
);
10080 return NDR_ERR_CODE_IS_SUCCESS(ndr_err
);
10083 /*******************************************************************
10084 Create a new TCP/IP port
10085 *******************************************************************/
10087 static WERROR
xcvtcp_addport(TALLOC_CTX
*mem_ctx
,
10088 struct security_token
*token
, DATA_BLOB
*in
,
10089 DATA_BLOB
*out
, uint32_t *needed
)
10091 struct spoolss_PortData1 port1
;
10092 struct spoolss_PortData2 port2
;
10093 char *device_uri
= NULL
;
10096 const char *portname
;
10097 const char *hostaddress
;
10099 uint32_t port_number
;
10102 /* peek for spoolss_PortData version */
10104 if (!in
|| (in
->length
< (128 + 4))) {
10105 return WERR_GENERAL_FAILURE
;
10108 version
= IVAL(in
->data
, 128);
10112 ZERO_STRUCT(port1
);
10114 if (!pull_port_data_1(mem_ctx
, &port1
, in
)) {
10118 portname
= port1
.portname
;
10119 hostaddress
= port1
.hostaddress
;
10120 queue
= port1
.queue
;
10121 protocol
= port1
.protocol
;
10122 port_number
= port1
.port_number
;
10126 ZERO_STRUCT(port2
);
10128 if (!pull_port_data_2(mem_ctx
, &port2
, in
)) {
10132 portname
= port2
.portname
;
10133 hostaddress
= port2
.hostaddress
;
10134 queue
= port2
.queue
;
10135 protocol
= port2
.protocol
;
10136 port_number
= port2
.port_number
;
10140 DEBUG(1,("xcvtcp_addport: "
10141 "unknown version of port_data: %d\n", version
));
10142 return WERR_UNKNOWN_PORT
;
10145 /* create the device URI and call the add_port_hook() */
10147 switch (protocol
) {
10148 case PROTOCOL_RAWTCP_TYPE
:
10149 device_uri
= talloc_asprintf(mem_ctx
,
10150 "socket://%s:%d/", hostaddress
,
10154 case PROTOCOL_LPR_TYPE
:
10155 device_uri
= talloc_asprintf(mem_ctx
,
10156 "lpr://%s/%s", hostaddress
, queue
);
10160 return WERR_UNKNOWN_PORT
;
10167 return add_port_hook(mem_ctx
, token
, portname
, device_uri
);
10170 /*******************************************************************
10171 *******************************************************************/
10173 struct xcv_api_table xcvtcp_cmds
[] = {
10174 { "MonitorUI", xcvtcp_monitorui
},
10175 { "AddPort", xcvtcp_addport
},
10179 static WERROR
process_xcvtcp_command(TALLOC_CTX
*mem_ctx
,
10180 struct security_token
*token
, const char *command
,
10187 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command
));
10189 for ( i
=0; xcvtcp_cmds
[i
].name
; i
++ ) {
10190 if ( strcmp( command
, xcvtcp_cmds
[i
].name
) == 0 )
10191 return xcvtcp_cmds
[i
].fn(mem_ctx
, token
, inbuf
, outbuf
, needed
);
10194 return WERR_BADFUNC
;
10197 /*******************************************************************
10198 *******************************************************************/
10199 #if 0 /* don't support management using the "Local Port" monitor */
10201 static WERROR
xcvlocal_monitorui(TALLOC_CTX
*mem_ctx
,
10202 struct security_token
*token
, DATA_BLOB
*in
,
10203 DATA_BLOB
*out
, uint32_t *needed
)
10205 const char *dllname
= "localui.dll";
10207 *needed
= (strlen(dllname
)+1) * 2;
10209 if (out
->length
< *needed
) {
10210 return WERR_INSUFFICIENT_BUFFER
;
10213 if (!push_monitorui_buf(mem_ctx
, out
, dllname
)) {
10220 /*******************************************************************
10221 *******************************************************************/
10223 struct xcv_api_table xcvlocal_cmds
[] = {
10224 { "MonitorUI", xcvlocal_monitorui
},
10228 struct xcv_api_table xcvlocal_cmds
[] = {
10235 /*******************************************************************
10236 *******************************************************************/
10238 static WERROR
process_xcvlocal_command(TALLOC_CTX
*mem_ctx
,
10239 struct security_token
*token
, const char *command
,
10240 DATA_BLOB
*inbuf
, DATA_BLOB
*outbuf
,
10245 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command
));
10247 for ( i
=0; xcvlocal_cmds
[i
].name
; i
++ ) {
10248 if ( strcmp( command
, xcvlocal_cmds
[i
].name
) == 0 )
10249 return xcvlocal_cmds
[i
].fn(mem_ctx
, token
, inbuf
, outbuf
, needed
);
10251 return WERR_BADFUNC
;
10254 /****************************************************************
10256 ****************************************************************/
10258 WERROR
_spoolss_XcvData(struct pipes_struct
*p
,
10259 struct spoolss_XcvData
*r
)
10261 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
10262 DATA_BLOB out_data
= data_blob_null
;
10266 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
10267 OUR_HANDLE(r
->in
.handle
)));
10268 return WERR_BADFID
;
10271 /* Has to be a handle to the TCP/IP port monitor */
10273 if ( !(Printer
->printer_type
& (SPLHND_PORTMON_LOCAL
|SPLHND_PORTMON_TCP
)) ) {
10274 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
10275 return WERR_BADFID
;
10278 /* requires administrative access to the server */
10280 if ( !(Printer
->access_granted
& SERVER_ACCESS_ADMINISTER
) ) {
10281 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
10282 return WERR_ACCESS_DENIED
;
10285 /* Allocate the outgoing buffer */
10287 if (r
->in
.out_data_size
) {
10288 out_data
= data_blob_talloc_zero(p
->mem_ctx
, r
->in
.out_data_size
);
10289 if (out_data
.data
== NULL
) {
10294 switch ( Printer
->printer_type
) {
10295 case SPLHND_PORTMON_TCP
:
10296 werror
= process_xcvtcp_command(p
->mem_ctx
,
10297 p
->session_info
->security_token
,
10298 r
->in
.function_name
,
10299 &r
->in
.in_data
, &out_data
,
10302 case SPLHND_PORTMON_LOCAL
:
10303 werror
= process_xcvlocal_command(p
->mem_ctx
,
10304 p
->session_info
->security_token
,
10305 r
->in
.function_name
,
10306 &r
->in
.in_data
, &out_data
,
10310 werror
= WERR_INVALID_PRINT_MONITOR
;
10313 if (!W_ERROR_IS_OK(werror
)) {
10317 *r
->out
.status_code
= 0;
10319 if (r
->out
.out_data
&& out_data
.data
&& r
->in
.out_data_size
&& out_data
.length
) {
10320 memcpy(r
->out
.out_data
, out_data
.data
,
10321 MIN(r
->in
.out_data_size
, out_data
.length
));
10327 /****************************************************************
10328 _spoolss_AddPrintProcessor
10329 ****************************************************************/
10331 WERROR
_spoolss_AddPrintProcessor(struct pipes_struct
*p
,
10332 struct spoolss_AddPrintProcessor
*r
)
10334 /* for now, just indicate success and ignore the add. We'll
10335 automatically set the winprint processor for printer
10336 entries later. Used to debug the LexMark Optra S 1855 PCL
10342 /****************************************************************
10344 ****************************************************************/
10346 WERROR
_spoolss_AddPort(struct pipes_struct
*p
,
10347 struct spoolss_AddPort
*r
)
10349 /* do what w2k3 does */
10351 return WERR_NOT_SUPPORTED
;
10354 /****************************************************************
10355 _spoolss_GetPrinterDriver
10356 ****************************************************************/
10358 WERROR
_spoolss_GetPrinterDriver(struct pipes_struct
*p
,
10359 struct spoolss_GetPrinterDriver
*r
)
10361 p
->rng_fault_state
= true;
10362 return WERR_NOT_SUPPORTED
;
10365 /****************************************************************
10366 _spoolss_ReadPrinter
10367 ****************************************************************/
10369 WERROR
_spoolss_ReadPrinter(struct pipes_struct
*p
,
10370 struct spoolss_ReadPrinter
*r
)
10372 p
->rng_fault_state
= true;
10373 return WERR_NOT_SUPPORTED
;
10376 /****************************************************************
10377 _spoolss_WaitForPrinterChange
10378 ****************************************************************/
10380 WERROR
_spoolss_WaitForPrinterChange(struct pipes_struct
*p
,
10381 struct spoolss_WaitForPrinterChange
*r
)
10383 p
->rng_fault_state
= true;
10384 return WERR_NOT_SUPPORTED
;
10387 /****************************************************************
10388 _spoolss_ConfigurePort
10389 ****************************************************************/
10391 WERROR
_spoolss_ConfigurePort(struct pipes_struct
*p
,
10392 struct spoolss_ConfigurePort
*r
)
10394 p
->rng_fault_state
= true;
10395 return WERR_NOT_SUPPORTED
;
10398 /****************************************************************
10399 _spoolss_DeletePort
10400 ****************************************************************/
10402 WERROR
_spoolss_DeletePort(struct pipes_struct
*p
,
10403 struct spoolss_DeletePort
*r
)
10405 p
->rng_fault_state
= true;
10406 return WERR_NOT_SUPPORTED
;
10409 /****************************************************************
10410 _spoolss_CreatePrinterIC
10411 ****************************************************************/
10413 WERROR
_spoolss_CreatePrinterIC(struct pipes_struct
*p
,
10414 struct spoolss_CreatePrinterIC
*r
)
10416 p
->rng_fault_state
= true;
10417 return WERR_NOT_SUPPORTED
;
10420 /****************************************************************
10421 _spoolss_PlayGDIScriptOnPrinterIC
10422 ****************************************************************/
10424 WERROR
_spoolss_PlayGDIScriptOnPrinterIC(struct pipes_struct
*p
,
10425 struct spoolss_PlayGDIScriptOnPrinterIC
*r
)
10427 p
->rng_fault_state
= true;
10428 return WERR_NOT_SUPPORTED
;
10431 /****************************************************************
10432 _spoolss_DeletePrinterIC
10433 ****************************************************************/
10435 WERROR
_spoolss_DeletePrinterIC(struct pipes_struct
*p
,
10436 struct spoolss_DeletePrinterIC
*r
)
10438 p
->rng_fault_state
= true;
10439 return WERR_NOT_SUPPORTED
;
10442 /****************************************************************
10443 _spoolss_AddPrinterConnection
10444 ****************************************************************/
10446 WERROR
_spoolss_AddPrinterConnection(struct pipes_struct
*p
,
10447 struct spoolss_AddPrinterConnection
*r
)
10449 p
->rng_fault_state
= true;
10450 return WERR_NOT_SUPPORTED
;
10453 /****************************************************************
10454 _spoolss_DeletePrinterConnection
10455 ****************************************************************/
10457 WERROR
_spoolss_DeletePrinterConnection(struct pipes_struct
*p
,
10458 struct spoolss_DeletePrinterConnection
*r
)
10460 p
->rng_fault_state
= true;
10461 return WERR_NOT_SUPPORTED
;
10464 /****************************************************************
10465 _spoolss_PrinterMessageBox
10466 ****************************************************************/
10468 WERROR
_spoolss_PrinterMessageBox(struct pipes_struct
*p
,
10469 struct spoolss_PrinterMessageBox
*r
)
10471 p
->rng_fault_state
= true;
10472 return WERR_NOT_SUPPORTED
;
10475 /****************************************************************
10476 _spoolss_AddMonitor
10477 ****************************************************************/
10479 WERROR
_spoolss_AddMonitor(struct pipes_struct
*p
,
10480 struct spoolss_AddMonitor
*r
)
10482 p
->rng_fault_state
= true;
10483 return WERR_NOT_SUPPORTED
;
10486 /****************************************************************
10487 _spoolss_DeleteMonitor
10488 ****************************************************************/
10490 WERROR
_spoolss_DeleteMonitor(struct pipes_struct
*p
,
10491 struct spoolss_DeleteMonitor
*r
)
10493 p
->rng_fault_state
= true;
10494 return WERR_NOT_SUPPORTED
;
10497 /****************************************************************
10498 _spoolss_DeletePrintProcessor
10499 ****************************************************************/
10501 WERROR
_spoolss_DeletePrintProcessor(struct pipes_struct
*p
,
10502 struct spoolss_DeletePrintProcessor
*r
)
10504 p
->rng_fault_state
= true;
10505 return WERR_NOT_SUPPORTED
;
10508 /****************************************************************
10509 _spoolss_AddPrintProvidor
10510 ****************************************************************/
10512 WERROR
_spoolss_AddPrintProvidor(struct pipes_struct
*p
,
10513 struct spoolss_AddPrintProvidor
*r
)
10515 p
->rng_fault_state
= true;
10516 return WERR_NOT_SUPPORTED
;
10519 /****************************************************************
10520 _spoolss_DeletePrintProvidor
10521 ****************************************************************/
10523 WERROR
_spoolss_DeletePrintProvidor(struct pipes_struct
*p
,
10524 struct spoolss_DeletePrintProvidor
*r
)
10526 p
->rng_fault_state
= true;
10527 return WERR_NOT_SUPPORTED
;
10530 /****************************************************************
10531 _spoolss_FindFirstPrinterChangeNotification
10532 ****************************************************************/
10534 WERROR
_spoolss_FindFirstPrinterChangeNotification(struct pipes_struct
*p
,
10535 struct spoolss_FindFirstPrinterChangeNotification
*r
)
10537 p
->rng_fault_state
= true;
10538 return WERR_NOT_SUPPORTED
;
10541 /****************************************************************
10542 _spoolss_FindNextPrinterChangeNotification
10543 ****************************************************************/
10545 WERROR
_spoolss_FindNextPrinterChangeNotification(struct pipes_struct
*p
,
10546 struct spoolss_FindNextPrinterChangeNotification
*r
)
10548 p
->rng_fault_state
= true;
10549 return WERR_NOT_SUPPORTED
;
10552 /****************************************************************
10553 _spoolss_RouterFindFirstPrinterChangeNotificationOld
10554 ****************************************************************/
10556 WERROR
_spoolss_RouterFindFirstPrinterChangeNotificationOld(struct pipes_struct
*p
,
10557 struct spoolss_RouterFindFirstPrinterChangeNotificationOld
*r
)
10559 p
->rng_fault_state
= true;
10560 return WERR_NOT_SUPPORTED
;
10563 /****************************************************************
10564 _spoolss_ReplyOpenPrinter
10565 ****************************************************************/
10567 WERROR
_spoolss_ReplyOpenPrinter(struct pipes_struct
*p
,
10568 struct spoolss_ReplyOpenPrinter
*r
)
10570 p
->rng_fault_state
= true;
10571 return WERR_NOT_SUPPORTED
;
10574 /****************************************************************
10575 _spoolss_RouterReplyPrinter
10576 ****************************************************************/
10578 WERROR
_spoolss_RouterReplyPrinter(struct pipes_struct
*p
,
10579 struct spoolss_RouterReplyPrinter
*r
)
10581 p
->rng_fault_state
= true;
10582 return WERR_NOT_SUPPORTED
;
10585 /****************************************************************
10586 _spoolss_ReplyClosePrinter
10587 ****************************************************************/
10589 WERROR
_spoolss_ReplyClosePrinter(struct pipes_struct
*p
,
10590 struct spoolss_ReplyClosePrinter
*r
)
10592 p
->rng_fault_state
= true;
10593 return WERR_NOT_SUPPORTED
;
10596 /****************************************************************
10598 ****************************************************************/
10600 WERROR
_spoolss_AddPortEx(struct pipes_struct
*p
,
10601 struct spoolss_AddPortEx
*r
)
10603 p
->rng_fault_state
= true;
10604 return WERR_NOT_SUPPORTED
;
10607 /****************************************************************
10608 _spoolss_RouterFindFirstPrinterChangeNotification
10609 ****************************************************************/
10611 WERROR
_spoolss_RouterFindFirstPrinterChangeNotification(struct pipes_struct
*p
,
10612 struct spoolss_RouterFindFirstPrinterChangeNotification
*r
)
10614 p
->rng_fault_state
= true;
10615 return WERR_NOT_SUPPORTED
;
10618 /****************************************************************
10619 _spoolss_SpoolerInit
10620 ****************************************************************/
10622 WERROR
_spoolss_SpoolerInit(struct pipes_struct
*p
,
10623 struct spoolss_SpoolerInit
*r
)
10625 p
->rng_fault_state
= true;
10626 return WERR_NOT_SUPPORTED
;
10629 /****************************************************************
10630 _spoolss_ResetPrinterEx
10631 ****************************************************************/
10633 WERROR
_spoolss_ResetPrinterEx(struct pipes_struct
*p
,
10634 struct spoolss_ResetPrinterEx
*r
)
10636 p
->rng_fault_state
= true;
10637 return WERR_NOT_SUPPORTED
;
10640 /****************************************************************
10641 _spoolss_RouterReplyPrinterEx
10642 ****************************************************************/
10644 WERROR
_spoolss_RouterReplyPrinterEx(struct pipes_struct
*p
,
10645 struct spoolss_RouterReplyPrinterEx
*r
)
10647 p
->rng_fault_state
= true;
10648 return WERR_NOT_SUPPORTED
;
10651 /****************************************************************
10653 ****************************************************************/
10655 WERROR
_spoolss_44(struct pipes_struct
*p
,
10656 struct spoolss_44
*r
)
10658 p
->rng_fault_state
= true;
10659 return WERR_NOT_SUPPORTED
;
10662 /****************************************************************
10664 ****************************************************************/
10666 WERROR
_spoolss_SetPort(struct pipes_struct
*p
,
10667 struct spoolss_SetPort
*r
)
10669 p
->rng_fault_state
= true;
10670 return WERR_NOT_SUPPORTED
;
10673 /****************************************************************
10675 ****************************************************************/
10677 WERROR
_spoolss_4a(struct pipes_struct
*p
,
10678 struct spoolss_4a
*r
)
10680 p
->rng_fault_state
= true;
10681 return WERR_NOT_SUPPORTED
;
10684 /****************************************************************
10686 ****************************************************************/
10688 WERROR
_spoolss_4b(struct pipes_struct
*p
,
10689 struct spoolss_4b
*r
)
10691 p
->rng_fault_state
= true;
10692 return WERR_NOT_SUPPORTED
;
10695 /****************************************************************
10697 ****************************************************************/
10699 WERROR
_spoolss_4c(struct pipes_struct
*p
,
10700 struct spoolss_4c
*r
)
10702 p
->rng_fault_state
= true;
10703 return WERR_NOT_SUPPORTED
;
10706 /****************************************************************
10708 ****************************************************************/
10710 WERROR
_spoolss_53(struct pipes_struct
*p
,
10711 struct spoolss_53
*r
)
10713 p
->rng_fault_state
= true;
10714 return WERR_NOT_SUPPORTED
;
10717 /****************************************************************
10718 _spoolss_AddPerMachineConnection
10719 ****************************************************************/
10721 WERROR
_spoolss_AddPerMachineConnection(struct pipes_struct
*p
,
10722 struct spoolss_AddPerMachineConnection
*r
)
10724 p
->rng_fault_state
= true;
10725 return WERR_NOT_SUPPORTED
;
10728 /****************************************************************
10729 _spoolss_DeletePerMachineConnection
10730 ****************************************************************/
10732 WERROR
_spoolss_DeletePerMachineConnection(struct pipes_struct
*p
,
10733 struct spoolss_DeletePerMachineConnection
*r
)
10735 p
->rng_fault_state
= true;
10736 return WERR_NOT_SUPPORTED
;
10739 /****************************************************************
10740 _spoolss_EnumPerMachineConnections
10741 ****************************************************************/
10743 WERROR
_spoolss_EnumPerMachineConnections(struct pipes_struct
*p
,
10744 struct spoolss_EnumPerMachineConnections
*r
)
10746 p
->rng_fault_state
= true;
10747 return WERR_NOT_SUPPORTED
;
10750 /****************************************************************
10752 ****************************************************************/
10754 WERROR
_spoolss_5a(struct pipes_struct
*p
,
10755 struct spoolss_5a
*r
)
10757 p
->rng_fault_state
= true;
10758 return WERR_NOT_SUPPORTED
;
10761 /****************************************************************
10763 ****************************************************************/
10765 WERROR
_spoolss_5b(struct pipes_struct
*p
,
10766 struct spoolss_5b
*r
)
10768 p
->rng_fault_state
= true;
10769 return WERR_NOT_SUPPORTED
;
10772 /****************************************************************
10774 ****************************************************************/
10776 WERROR
_spoolss_5c(struct pipes_struct
*p
,
10777 struct spoolss_5c
*r
)
10779 p
->rng_fault_state
= true;
10780 return WERR_NOT_SUPPORTED
;
10783 /****************************************************************
10785 ****************************************************************/
10787 WERROR
_spoolss_5d(struct pipes_struct
*p
,
10788 struct spoolss_5d
*r
)
10790 p
->rng_fault_state
= true;
10791 return WERR_NOT_SUPPORTED
;
10794 /****************************************************************
10796 ****************************************************************/
10798 WERROR
_spoolss_5e(struct pipes_struct
*p
,
10799 struct spoolss_5e
*r
)
10801 p
->rng_fault_state
= true;
10802 return WERR_NOT_SUPPORTED
;
10805 /****************************************************************
10807 ****************************************************************/
10809 WERROR
_spoolss_5f(struct pipes_struct
*p
,
10810 struct spoolss_5f
*r
)
10812 p
->rng_fault_state
= true;
10813 return WERR_NOT_SUPPORTED
;
10816 /****************************************************************
10818 ****************************************************************/
10820 WERROR
_spoolss_60(struct pipes_struct
*p
,
10821 struct spoolss_60
*r
)
10823 p
->rng_fault_state
= true;
10824 return WERR_NOT_SUPPORTED
;
10827 /****************************************************************
10829 ****************************************************************/
10831 WERROR
_spoolss_61(struct pipes_struct
*p
,
10832 struct spoolss_61
*r
)
10834 p
->rng_fault_state
= true;
10835 return WERR_NOT_SUPPORTED
;
10838 /****************************************************************
10840 ****************************************************************/
10842 WERROR
_spoolss_62(struct pipes_struct
*p
,
10843 struct spoolss_62
*r
)
10845 p
->rng_fault_state
= true;
10846 return WERR_NOT_SUPPORTED
;
10849 /****************************************************************
10851 ****************************************************************/
10853 WERROR
_spoolss_63(struct pipes_struct
*p
,
10854 struct spoolss_63
*r
)
10856 p
->rng_fault_state
= true;
10857 return WERR_NOT_SUPPORTED
;
10860 /****************************************************************
10862 ****************************************************************/
10864 WERROR
_spoolss_64(struct pipes_struct
*p
,
10865 struct spoolss_64
*r
)
10867 p
->rng_fault_state
= true;
10868 return WERR_NOT_SUPPORTED
;
10871 /****************************************************************
10873 ****************************************************************/
10875 WERROR
_spoolss_65(struct pipes_struct
*p
,
10876 struct spoolss_65
*r
)
10878 p
->rng_fault_state
= true;
10879 return WERR_NOT_SUPPORTED
;
10882 /****************************************************************
10883 _spoolss_GetCorePrinterDrivers
10884 ****************************************************************/
10886 WERROR
_spoolss_GetCorePrinterDrivers(struct pipes_struct
*p
,
10887 struct spoolss_GetCorePrinterDrivers
*r
)
10889 p
->rng_fault_state
= true;
10890 return WERR_NOT_SUPPORTED
;
10893 /****************************************************************
10895 ****************************************************************/
10897 WERROR
_spoolss_67(struct pipes_struct
*p
,
10898 struct spoolss_67
*r
)
10900 p
->rng_fault_state
= true;
10901 return WERR_NOT_SUPPORTED
;
10904 /****************************************************************
10905 _spoolss_GetPrinterDriverPackagePath
10906 ****************************************************************/
10908 WERROR
_spoolss_GetPrinterDriverPackagePath(struct pipes_struct
*p
,
10909 struct spoolss_GetPrinterDriverPackagePath
*r
)
10911 p
->rng_fault_state
= true;
10912 return WERR_NOT_SUPPORTED
;
10915 /****************************************************************
10917 ****************************************************************/
10919 WERROR
_spoolss_69(struct pipes_struct
*p
,
10920 struct spoolss_69
*r
)
10922 p
->rng_fault_state
= true;
10923 return WERR_NOT_SUPPORTED
;
10926 /****************************************************************
10928 ****************************************************************/
10930 WERROR
_spoolss_6a(struct pipes_struct
*p
,
10931 struct spoolss_6a
*r
)
10933 p
->rng_fault_state
= true;
10934 return WERR_NOT_SUPPORTED
;
10937 /****************************************************************
10939 ****************************************************************/
10941 WERROR
_spoolss_6b(struct pipes_struct
*p
,
10942 struct spoolss_6b
*r
)
10944 p
->rng_fault_state
= true;
10945 return WERR_NOT_SUPPORTED
;
10948 /****************************************************************
10950 ****************************************************************/
10952 WERROR
_spoolss_6c(struct pipes_struct
*p
,
10953 struct spoolss_6c
*r
)
10955 p
->rng_fault_state
= true;
10956 return WERR_NOT_SUPPORTED
;
10959 /****************************************************************
10961 ****************************************************************/
10963 WERROR
_spoolss_6d(struct pipes_struct
*p
,
10964 struct spoolss_6d
*r
)
10966 p
->rng_fault_state
= true;
10967 return WERR_NOT_SUPPORTED
;