2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-2000,
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
6 * Copyright (C) Jean François Micouleau 1998-2000,
7 * Copyright (C) Jeremy Allison 2001-2002,
8 * Copyright (C) Gerald Carter 2000-2004,
9 * Copyright (C) Tim Potter 2001-2002.
10 * Copyright (C) Guenther Deschner 2009-2010.
11 * Copyright (C) Andreas Schneider 2010.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 /* Since the SPOOLSS rpc routines are basically DOS 16-bit calls wrapped
28 up, all the errors returned are DOS errors, not NT status codes. */
31 #include "nt_printing.h"
32 #include "srv_spoolss_util.h"
33 #include "../librpc/gen_ndr/srv_spoolss.h"
34 #include "../librpc/gen_ndr/cli_spoolss.h"
35 #include "rpc_client/init_spoolss.h"
36 #include "librpc/gen_ndr/messaging.h"
37 #include "../libcli/security/security.h"
38 #include "librpc/gen_ndr/ndr_security.h"
40 #include "registry/reg_objects.h"
41 #include "include/printing.h"
43 #include "../librpc/gen_ndr/netlogon.h"
46 /* macros stolen from s4 spoolss server */
47 #define SPOOLSS_BUFFER_UNION(fn,info,level) \
48 ((info)?ndr_size_##fn(info, level, 0):0)
50 #define SPOOLSS_BUFFER_UNION_ARRAY(mem_ctx,fn,info,level,count) \
51 ((info)?ndr_size_##fn##_info(mem_ctx, level, count, info):0)
53 #define SPOOLSS_BUFFER_ARRAY(mem_ctx,fn,info,count) \
54 ((info)?ndr_size_##fn##_info(mem_ctx, count, info):0)
56 #define SPOOLSS_BUFFER_OK(val_true,val_false) ((r->in.offered >= *r->out.needed)?val_true:val_false)
59 #define DBGC_CLASS DBGC_RPC_SRV
61 #ifndef MAX_OPEN_PRINTER_EXS
62 #define MAX_OPEN_PRINTER_EXS 50
65 struct notify_back_channel
;
67 /* structure to store the printer handles */
68 /* and a reference to what it's pointing to */
69 /* and the notify info asked about */
70 /* that's the central struct */
71 struct printer_handle
{
72 struct printer_handle
*prev
, *next
;
73 bool document_started
;
75 uint32 jobid
; /* jobid in printing backend */
77 const char *servername
;
80 uint32 access_granted
;
86 struct spoolss_NotifyOption
*option
;
87 struct policy_handle cli_hnd
;
88 struct notify_back_channel
*cli_chan
;
90 /* are we in a FindNextPrinterChangeNotify() call? */
92 struct messaging_context
*msg_ctx
;
99 /* devmode sent in the OpenPrinter() call */
100 struct spoolss_DeviceMode
*devmode
;
102 /* TODO cache the printer info2 structure */
103 struct spoolss_PrinterInfo2
*info2
;
107 static struct printer_handle
*printers_list
;
109 struct printer_session_counter
{
110 struct printer_session_counter
*next
;
111 struct printer_session_counter
*prev
;
117 static struct printer_session_counter
*counter_list
;
119 struct notify_back_channel
{
120 struct notify_back_channel
*prev
, *next
;
122 /* associated client */
123 struct sockaddr_storage client_address
;
125 /* print notify back-channel pipe handle*/
126 struct rpc_pipe_client
*cli_pipe
;
127 uint32_t active_connections
;
130 static struct notify_back_channel
*back_channels
;
132 /* Map generic permissions to printer object specific permissions */
134 const struct standard_mapping printer_std_mapping
= {
141 /* Map generic permissions to print server object specific permissions */
143 const struct standard_mapping printserver_std_mapping
= {
150 /* API table for Xcv Monitor functions */
152 struct xcv_api_table
{
154 WERROR(*fn
) (TALLOC_CTX
*mem_ctx
, struct security_token
*token
, DATA_BLOB
*in
, DATA_BLOB
*out
, uint32_t *needed
);
157 static void prune_printername_cache(void);
159 /********************************************************************
160 * Canonicalize servername.
161 ********************************************************************/
163 static const char *canon_servername(const char *servername
)
165 const char *pservername
= servername
;
166 while (*pservername
== '\\') {
172 /* translate between internal status numbers and NT status numbers */
173 static int nt_printj_status(int v
)
179 return JOB_STATUS_PAUSED
;
181 return JOB_STATUS_SPOOLING
;
183 return JOB_STATUS_PRINTING
;
185 return JOB_STATUS_ERROR
;
187 return JOB_STATUS_DELETING
;
189 return JOB_STATUS_OFFLINE
;
191 return JOB_STATUS_PAPEROUT
;
193 return JOB_STATUS_PRINTED
;
195 return JOB_STATUS_DELETED
;
197 return JOB_STATUS_BLOCKED_DEVQ
;
198 case LPQ_USER_INTERVENTION
:
199 return JOB_STATUS_USER_INTERVENTION
;
204 static int nt_printq_status(int v
)
208 return PRINTER_STATUS_PAUSED
;
217 /***************************************************************************
218 Disconnect from the client
219 ****************************************************************************/
221 static void srv_spoolss_replycloseprinter(int snum
,
222 struct printer_handle
*prn_hnd
)
228 * Tell the specific printing tdb we no longer want messages for this printer
229 * by deregistering our PID.
232 if (!print_notify_deregister_pid(snum
)) {
233 DEBUG(0, ("Failed to register our pid for printer %s\n",
234 lp_const_servicename(snum
)));
237 /* weird if the test succeeds !!! */
238 if (prn_hnd
->notify
.cli_chan
== NULL
||
239 prn_hnd
->notify
.cli_chan
->active_connections
== 0) {
240 DEBUG(0, ("Trying to close unexisting backchannel!\n"));
241 DLIST_REMOVE(back_channels
, prn_hnd
->notify
.cli_chan
);
242 TALLOC_FREE(prn_hnd
->notify
.cli_chan
);
246 status
= rpccli_spoolss_ReplyClosePrinter(
247 prn_hnd
->notify
.cli_chan
->cli_pipe
,
249 &prn_hnd
->notify
.cli_hnd
,
251 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
252 DEBUG(0, ("reply_close_printer failed [%s].\n",
253 win_errstr(result
)));
256 /* if it's the last connection, deconnect the IPC$ share */
257 if (prn_hnd
->notify
.cli_chan
->active_connections
== 1) {
259 cli_shutdown(rpc_pipe_np_smb_conn(prn_hnd
->notify
.cli_chan
->cli_pipe
));
260 DLIST_REMOVE(back_channels
, prn_hnd
->notify
.cli_chan
);
261 TALLOC_FREE(prn_hnd
->notify
.cli_chan
);
263 if (prn_hnd
->notify
.msg_ctx
!= NULL
) {
264 messaging_deregister(prn_hnd
->notify
.msg_ctx
,
265 MSG_PRINTER_NOTIFY2
, NULL
);
268 * Tell the serverid.tdb we're no longer
269 * interested in printer notify messages.
272 serverid_register_msg_flags(
273 messaging_server_id(prn_hnd
->notify
.msg_ctx
),
274 false, FLAG_MSG_PRINT_NOTIFY
);
278 if (prn_hnd
->notify
.cli_chan
) {
279 prn_hnd
->notify
.cli_chan
->active_connections
--;
283 /****************************************************************************
284 Functions to free a printer entry datastruct.
285 ****************************************************************************/
287 static int printer_entry_destructor(struct printer_handle
*Printer
)
289 if (Printer
->notify
.cli_chan
!= NULL
&&
290 Printer
->notify
.cli_chan
->active_connections
> 0) {
293 switch(Printer
->printer_type
) {
295 srv_spoolss_replycloseprinter(snum
, Printer
);
299 snum
= print_queue_snum(Printer
->sharename
);
301 srv_spoolss_replycloseprinter(snum
, Printer
);
309 Printer
->notify
.flags
=0;
310 Printer
->notify
.options
=0;
311 Printer
->notify
.localmachine
[0]='\0';
312 Printer
->notify
.printerlocal
=0;
313 TALLOC_FREE(Printer
->notify
.option
);
314 TALLOC_FREE(Printer
->devmode
);
316 /* Remove from the internal list. */
317 DLIST_REMOVE(printers_list
, Printer
);
321 /****************************************************************************
322 find printer index by handle
323 ****************************************************************************/
325 static struct printer_handle
*find_printer_index_by_hnd(struct pipes_struct
*p
,
326 struct policy_handle
*hnd
)
328 struct printer_handle
*find_printer
= NULL
;
330 if(!find_policy_by_hnd(p
,hnd
,(void **)(void *)&find_printer
)) {
331 DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: "));
338 /****************************************************************************
339 Close printer index by handle.
340 ****************************************************************************/
342 static bool close_printer_handle(struct pipes_struct
*p
, struct policy_handle
*hnd
)
344 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, hnd
);
347 DEBUG(2,("close_printer_handle: Invalid handle (%s:%u:%u)\n",
352 close_policy_hnd(p
, hnd
);
357 /****************************************************************************
358 Delete a printer given a handle.
359 ****************************************************************************/
361 static WERROR
delete_printer_hook(TALLOC_CTX
*ctx
, struct security_token
*token
,
362 const char *sharename
,
363 struct messaging_context
*msg_ctx
)
365 char *cmd
= lp_deleteprinter_cmd();
366 char *command
= NULL
;
368 bool is_print_op
= false;
370 /* can't fail if we don't try */
375 command
= talloc_asprintf(ctx
,
382 is_print_op
= security_token_has_privilege(token
, SEC_PRIV_PRINT_OPERATOR
);
384 DEBUG(10,("Running [%s]\n", command
));
386 /********** BEGIN SePrintOperatorPrivlege BLOCK **********/
391 if ( (ret
= smbrun(command
, NULL
)) == 0 ) {
392 /* Tell everyone we updated smb.conf. */
393 message_send_all(msg_ctx
, MSG_SMB_CONF_UPDATED
, NULL
, 0, NULL
);
399 /********** END SePrintOperatorPrivlege BLOCK **********/
401 DEBUGADD(10,("returned [%d]\n", ret
));
403 TALLOC_FREE(command
);
406 return WERR_BADFID
; /* What to return here? */
408 /* go ahead and re-read the services immediately */
410 reload_services(msg_ctx
, -1, false);
413 if ( lp_servicenumber( sharename
) >= 0 )
414 return WERR_ACCESS_DENIED
;
419 /****************************************************************************
420 Delete a printer given a handle.
421 ****************************************************************************/
423 static WERROR
delete_printer_handle(struct pipes_struct
*p
, struct policy_handle
*hnd
)
425 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, hnd
);
429 DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n",
435 * It turns out that Windows allows delete printer on a handle
436 * opened by an admin user, then used on a pipe handle created
437 * by an anonymous user..... but they're working on security.... riiight !
441 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
442 DEBUG(3, ("delete_printer_handle: denied by handle\n"));
443 return WERR_ACCESS_DENIED
;
446 /* this does not need a become root since the access check has been
447 done on the handle already */
449 result
= winreg_delete_printer_key(p
->mem_ctx
,
450 get_server_info_system(),
454 if (!W_ERROR_IS_OK(result
)) {
455 DEBUG(3,("Error deleting printer %s\n", Printer
->sharename
));
459 result
= delete_printer_hook(p
->mem_ctx
, p
->server_info
->ptok
,
460 Printer
->sharename
, p
->msg_ctx
);
461 if (!W_ERROR_IS_OK(result
)) {
464 prune_printername_cache();
468 /****************************************************************************
469 Return the snum of a printer corresponding to an handle.
470 ****************************************************************************/
472 static bool get_printer_snum(struct pipes_struct
*p
, struct policy_handle
*hnd
,
473 int *number
, struct share_params
**params
)
475 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, hnd
);
478 DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n",
483 switch (Printer
->printer_type
) {
485 DEBUG(4,("short name:%s\n", Printer
->sharename
));
486 *number
= print_queue_snum(Printer
->sharename
);
487 return (*number
!= -1);
495 /****************************************************************************
496 Set printer handle type.
497 Check if it's \\server or \\server\printer
498 ****************************************************************************/
500 static bool set_printer_hnd_printertype(struct printer_handle
*Printer
, const char *handlename
)
502 DEBUG(3,("Setting printer type=%s\n", handlename
));
504 /* it's a print server */
505 if (handlename
&& *handlename
=='\\' && *(handlename
+1)=='\\' && !strchr_m(handlename
+2, '\\')) {
506 DEBUGADD(4,("Printer is a print server\n"));
507 Printer
->printer_type
= SPLHND_SERVER
;
509 /* it's a printer (set_printer_hnd_name() will handle port monitors */
511 DEBUGADD(4,("Printer is a printer\n"));
512 Printer
->printer_type
= SPLHND_PRINTER
;
518 static void prune_printername_cache_fn(const char *key
, const char *value
,
519 time_t timeout
, void *private_data
)
524 static void prune_printername_cache(void)
526 gencache_iterate(prune_printername_cache_fn
, NULL
, "PRINTERNAME/*");
529 /****************************************************************************
530 Set printer handle name.. Accept names like \\server, \\server\printer,
531 \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
532 the MSDN docs regarding OpenPrinter() for details on the XcvData() and
533 XcvDataPort() interface.
534 ****************************************************************************/
536 static WERROR
set_printer_hnd_name(TALLOC_CTX
*mem_ctx
,
537 const struct auth_serversupplied_info
*server_info
,
538 struct messaging_context
*msg_ctx
,
539 struct printer_handle
*Printer
,
540 const char *handlename
)
543 int n_services
=lp_numservices();
545 const char *printername
;
546 const char *servername
= NULL
;
549 struct spoolss_PrinterInfo2
*info2
= NULL
;
554 * Hopefully nobody names his printers like this. Maybe \ or ,
555 * are illegal in printer names even?
557 const char printer_not_found
[] = "Printer \\, !@#$%^&*( not found";
561 DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename
,
562 (unsigned long)strlen(handlename
)));
564 aprinter
= CONST_DISCARD(char *, handlename
);
565 if ( *handlename
== '\\' ) {
566 servername
= canon_servername(handlename
);
567 if ( (aprinter
= strchr_m( servername
, '\\' )) != NULL
) {
571 if (!is_myname_or_ipaddr(servername
)) {
572 return WERR_INVALID_PRINTER_NAME
;
574 Printer
->servername
= talloc_asprintf(Printer
, "\\\\%s", servername
);
575 if (Printer
->servername
== NULL
) {
580 if (Printer
->printer_type
== SPLHND_SERVER
) {
584 if (Printer
->printer_type
!= SPLHND_PRINTER
) {
585 return WERR_INVALID_HANDLE
;
588 DEBUGADD(5, ("searching for [%s]\n", aprinter
));
590 p
= strchr(aprinter
, ',');
597 if (strncmp(p
, "DrvConvert", strlen("DrvConvert")) == 0) {
599 } else if (strncmp(p
, "LocalOnly", strlen("LocalOnly")) == 0) {
605 DEBUGADD(5, ("stripped handlename: [%s]\n", aprinter
));
608 /* check for the Port Monitor Interface */
609 if ( strequal( aprinter
, SPL_XCV_MONITOR_TCPMON
) ) {
610 Printer
->printer_type
= SPLHND_PORTMON_TCP
;
611 fstrcpy(sname
, SPL_XCV_MONITOR_TCPMON
);
614 else if ( strequal( aprinter
, SPL_XCV_MONITOR_LOCALMON
) ) {
615 Printer
->printer_type
= SPLHND_PORTMON_LOCAL
;
616 fstrcpy(sname
, SPL_XCV_MONITOR_LOCALMON
);
621 * With hundreds of printers, the "for" loop iterating all
622 * shares can be quite expensive, as it is done on every
623 * OpenPrinter. The loop maps "aprinter" to "sname", the
624 * result of which we cache in gencache.
627 cache_key
= talloc_asprintf(talloc_tos(), "PRINTERNAME/%s",
629 if ((cache_key
!= NULL
) && gencache_get(cache_key
, &tmp
, NULL
)) {
631 found
= (strcmp(tmp
, printer_not_found
) != 0);
633 DEBUG(4, ("Printer %s not found\n", aprinter
));
635 return WERR_INVALID_PRINTER_NAME
;
641 /* Search all sharenames first as this is easier than pulling
642 the printer_info_2 off of disk. Don't use find_service() since
643 that calls out to map_username() */
645 /* do another loop to look for printernames */
646 for (snum
= 0; !found
&& snum
< n_services
; snum
++) {
647 const char *printer
= lp_const_servicename(snum
);
649 /* no point going on if this is not a printer */
650 if (!(lp_snum_ok(snum
) && lp_print_ok(snum
))) {
654 /* ignore [printers] share */
655 if (strequal(printer
, "printers")) {
659 fstrcpy(sname
, printer
);
660 if (strequal(aprinter
, printer
)) {
665 /* no point looking up the printer object if
666 we aren't allowing printername != sharename */
667 if (lp_force_printername(snum
)) {
671 result
= winreg_get_printer(mem_ctx
,
676 if ( !W_ERROR_IS_OK(result
) ) {
677 DEBUG(2,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
678 sname
, win_errstr(result
)));
682 printername
= strrchr(info2
->printername
, '\\');
683 if (printername
== NULL
) {
684 printername
= info2
->printername
;
689 if (strequal(printername
, aprinter
)) {
694 DEBUGADD(10, ("printername: %s\n", printername
));
700 if (cache_key
!= NULL
) {
701 gencache_set(cache_key
, printer_not_found
,
703 TALLOC_FREE(cache_key
);
705 DEBUGADD(4,("Printer not found\n"));
706 return WERR_INVALID_PRINTER_NAME
;
709 if (cache_key
!= NULL
) {
710 gencache_set(cache_key
, sname
, time(NULL
)+300);
711 TALLOC_FREE(cache_key
);
714 DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter
, sname
));
716 fstrcpy(Printer
->sharename
, sname
);
721 /****************************************************************************
722 Find first available printer slot. creates a printer handle for you.
723 ****************************************************************************/
725 static WERROR
open_printer_hnd(struct pipes_struct
*p
,
726 struct policy_handle
*hnd
,
728 uint32_t access_granted
)
730 struct printer_handle
*new_printer
;
733 DEBUG(10,("open_printer_hnd: name [%s]\n", name
));
735 new_printer
= talloc_zero(p
->mem_ctx
, struct printer_handle
);
736 if (new_printer
== NULL
) {
739 talloc_set_destructor(new_printer
, printer_entry_destructor
);
741 /* This also steals the printer_handle on the policy_handle */
742 if (!create_policy_hnd(p
, hnd
, new_printer
)) {
743 TALLOC_FREE(new_printer
);
744 return WERR_INVALID_HANDLE
;
747 /* Add to the internal list. */
748 DLIST_ADD(printers_list
, new_printer
);
750 new_printer
->notify
.option
=NULL
;
752 if (!set_printer_hnd_printertype(new_printer
, name
)) {
753 close_printer_handle(p
, hnd
);
754 return WERR_INVALID_HANDLE
;
757 result
= set_printer_hnd_name(p
->mem_ctx
,
758 get_server_info_system(),
761 if (!W_ERROR_IS_OK(result
)) {
762 close_printer_handle(p
, hnd
);
766 new_printer
->access_granted
= access_granted
;
768 DEBUG(5, ("%d printer handles active\n",
769 (int)num_pipe_handles(p
)));
774 /***************************************************************************
775 check to see if the client motify handle is monitoring the notification
776 given by (notify_type, notify_field).
777 **************************************************************************/
779 static bool is_monitoring_event_flags(uint32_t flags
, uint16_t notify_type
,
780 uint16_t notify_field
)
785 static bool is_monitoring_event(struct printer_handle
*p
, uint16_t notify_type
,
786 uint16_t notify_field
)
788 struct spoolss_NotifyOption
*option
= p
->notify
.option
;
792 * Flags should always be zero when the change notify
793 * is registered by the client's spooler. A user Win32 app
794 * might use the flags though instead of the NOTIFY_OPTION_INFO
803 return is_monitoring_event_flags(
804 p
->notify
.flags
, notify_type
, notify_field
);
806 for (i
= 0; i
< option
->count
; i
++) {
808 /* Check match for notify_type */
810 if (option
->types
[i
].type
!= notify_type
)
813 /* Check match for field */
815 for (j
= 0; j
< option
->types
[i
].count
; j
++) {
816 if (option
->types
[i
].fields
[j
].field
== notify_field
) {
822 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
823 p
->servername
, p
->sharename
, notify_type
, notify_field
));
828 #define SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(_data, _integer) \
829 _data->data.integer[0] = _integer; \
830 _data->data.integer[1] = 0;
833 #define SETUP_SPOOLSS_NOTIFY_DATA_STRING(_data, _p) \
834 _data->data.string.string = talloc_strdup(mem_ctx, _p); \
835 if (!_data->data.string.string) {\
836 _data->data.string.size = 0; \
838 _data->data.string.size = strlen_m_term(_p) * 2;
840 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
841 _data->data.devmode.devmode = _devmode;
843 #define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _sd) \
844 _data->data.sd.sd = dup_sec_desc(mem_ctx, _sd); \
845 if (!_data->data.sd.sd) { \
846 _data->data.sd.sd_size = 0; \
848 _data->data.sd.sd_size = \
849 ndr_size_security_descriptor(_data->data.sd.sd, 0);
851 static void init_systemtime_buffer(TALLOC_CTX
*mem_ctx
,
856 struct spoolss_Time st
;
860 if (!init_systemtime(&st
, t
)) {
864 p
= talloc_array(mem_ctx
, char, len
);
870 * Systemtime must be linearized as a set of UINT16's.
871 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
874 SSVAL(p
, 0, st
.year
);
875 SSVAL(p
, 2, st
.month
);
876 SSVAL(p
, 4, st
.day_of_week
);
878 SSVAL(p
, 8, st
.hour
);
879 SSVAL(p
, 10, st
.minute
);
880 SSVAL(p
, 12, st
.second
);
881 SSVAL(p
, 14, st
.millisecond
);
887 /* Convert a notification message to a struct spoolss_Notify */
889 static void notify_one_value(struct spoolss_notify_msg
*msg
,
890 struct spoolss_Notify
*data
,
893 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, msg
->notify
.value
[0]);
896 static void notify_string(struct spoolss_notify_msg
*msg
,
897 struct spoolss_Notify
*data
,
900 /* The length of the message includes the trailing \0 */
902 data
->data
.string
.size
= msg
->len
* 2;
903 data
->data
.string
.string
= talloc_strdup(mem_ctx
, msg
->notify
.data
);
904 if (!data
->data
.string
.string
) {
905 data
->data
.string
.size
= 0;
910 static void notify_system_time(struct spoolss_notify_msg
*msg
,
911 struct spoolss_Notify
*data
,
914 data
->data
.string
.string
= NULL
;
915 data
->data
.string
.size
= 0;
917 if (msg
->len
!= sizeof(time_t)) {
918 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
923 init_systemtime_buffer(mem_ctx
, gmtime((time_t *)msg
->notify
.data
),
924 &data
->data
.string
.string
,
925 &data
->data
.string
.size
);
928 struct notify2_message_table
{
930 void (*fn
)(struct spoolss_notify_msg
*msg
,
931 struct spoolss_Notify
*data
, TALLOC_CTX
*mem_ctx
);
934 static struct notify2_message_table printer_notify_table
[] = {
935 /* 0x00 */ { "PRINTER_NOTIFY_FIELD_SERVER_NAME", notify_string
},
936 /* 0x01 */ { "PRINTER_NOTIFY_FIELD_PRINTER_NAME", notify_string
},
937 /* 0x02 */ { "PRINTER_NOTIFY_FIELD_SHARE_NAME", notify_string
},
938 /* 0x03 */ { "PRINTER_NOTIFY_FIELD_PORT_NAME", notify_string
},
939 /* 0x04 */ { "PRINTER_NOTIFY_FIELD_DRIVER_NAME", notify_string
},
940 /* 0x05 */ { "PRINTER_NOTIFY_FIELD_COMMENT", notify_string
},
941 /* 0x06 */ { "PRINTER_NOTIFY_FIELD_LOCATION", notify_string
},
942 /* 0x07 */ { "PRINTER_NOTIFY_FIELD_DEVMODE", NULL
},
943 /* 0x08 */ { "PRINTER_NOTIFY_FIELD_SEPFILE", notify_string
},
944 /* 0x09 */ { "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", notify_string
},
945 /* 0x0a */ { "PRINTER_NOTIFY_FIELD_PARAMETERS", NULL
},
946 /* 0x0b */ { "PRINTER_NOTIFY_FIELD_DATATYPE", notify_string
},
947 /* 0x0c */ { "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL
},
948 /* 0x0d */ { "PRINTER_NOTIFY_FIELD_ATTRIBUTES", notify_one_value
},
949 /* 0x0e */ { "PRINTER_NOTIFY_FIELD_PRIORITY", notify_one_value
},
950 /* 0x0f */ { "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NULL
},
951 /* 0x10 */ { "PRINTER_NOTIFY_FIELD_START_TIME", NULL
},
952 /* 0x11 */ { "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NULL
},
953 /* 0x12 */ { "PRINTER_NOTIFY_FIELD_STATUS", notify_one_value
},
956 static struct notify2_message_table job_notify_table
[] = {
957 /* 0x00 */ { "JOB_NOTIFY_FIELD_PRINTER_NAME", NULL
},
958 /* 0x01 */ { "JOB_NOTIFY_FIELD_MACHINE_NAME", NULL
},
959 /* 0x02 */ { "JOB_NOTIFY_FIELD_PORT_NAME", NULL
},
960 /* 0x03 */ { "JOB_NOTIFY_FIELD_USER_NAME", notify_string
},
961 /* 0x04 */ { "JOB_NOTIFY_FIELD_NOTIFY_NAME", NULL
},
962 /* 0x05 */ { "JOB_NOTIFY_FIELD_DATATYPE", NULL
},
963 /* 0x06 */ { "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NULL
},
964 /* 0x07 */ { "JOB_NOTIFY_FIELD_PARAMETERS", NULL
},
965 /* 0x08 */ { "JOB_NOTIFY_FIELD_DRIVER_NAME", NULL
},
966 /* 0x09 */ { "JOB_NOTIFY_FIELD_DEVMODE", NULL
},
967 /* 0x0a */ { "JOB_NOTIFY_FIELD_STATUS", notify_one_value
},
968 /* 0x0b */ { "JOB_NOTIFY_FIELD_STATUS_STRING", NULL
},
969 /* 0x0c */ { "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL
},
970 /* 0x0d */ { "JOB_NOTIFY_FIELD_DOCUMENT", notify_string
},
971 /* 0x0e */ { "JOB_NOTIFY_FIELD_PRIORITY", NULL
},
972 /* 0x0f */ { "JOB_NOTIFY_FIELD_POSITION", NULL
},
973 /* 0x10 */ { "JOB_NOTIFY_FIELD_SUBMITTED", notify_system_time
},
974 /* 0x11 */ { "JOB_NOTIFY_FIELD_START_TIME", NULL
},
975 /* 0x12 */ { "JOB_NOTIFY_FIELD_UNTIL_TIME", NULL
},
976 /* 0x13 */ { "JOB_NOTIFY_FIELD_TIME", NULL
},
977 /* 0x14 */ { "JOB_NOTIFY_FIELD_TOTAL_PAGES", notify_one_value
},
978 /* 0x15 */ { "JOB_NOTIFY_FIELD_PAGES_PRINTED", NULL
},
979 /* 0x16 */ { "JOB_NOTIFY_FIELD_TOTAL_BYTES", notify_one_value
},
980 /* 0x17 */ { "JOB_NOTIFY_FIELD_BYTES_PRINTED", NULL
},
984 /***********************************************************************
985 Allocate talloc context for container object
986 **********************************************************************/
988 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR
*ctr
)
993 ctr
->ctx
= talloc_init("notify_msg_ctr_init %p", ctr
);
998 /***********************************************************************
999 release all allocated memory and zero out structure
1000 **********************************************************************/
1002 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR
*ctr
)
1008 talloc_destroy(ctr
->ctx
);
1015 /***********************************************************************
1016 **********************************************************************/
1018 static TALLOC_CTX
* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR
*ctr
)
1026 /***********************************************************************
1027 **********************************************************************/
1029 static SPOOLSS_NOTIFY_MSG_GROUP
* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR
*ctr
, uint32_t idx
)
1031 if ( !ctr
|| !ctr
->msg_groups
)
1034 if ( idx
>= ctr
->num_groups
)
1037 return &ctr
->msg_groups
[idx
];
1041 /***********************************************************************
1042 How many groups of change messages do we have ?
1043 **********************************************************************/
1045 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR
*ctr
)
1050 return ctr
->num_groups
;
1053 /***********************************************************************
1054 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
1055 **********************************************************************/
1057 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR
*ctr
, SPOOLSS_NOTIFY_MSG
*msg
)
1059 SPOOLSS_NOTIFY_MSG_GROUP
*groups
= NULL
;
1060 SPOOLSS_NOTIFY_MSG_GROUP
*msg_grp
= NULL
;
1061 SPOOLSS_NOTIFY_MSG
*msg_list
= NULL
;
1067 /* loop over all groups looking for a matching printer name */
1069 for ( i
=0; i
<ctr
->num_groups
; i
++ ) {
1070 if ( strcmp(ctr
->msg_groups
[i
].printername
, msg
->printer
) == 0 )
1074 /* add a new group? */
1076 if ( i
== ctr
->num_groups
) {
1079 if ( !(groups
= TALLOC_REALLOC_ARRAY( ctr
->ctx
, ctr
->msg_groups
, SPOOLSS_NOTIFY_MSG_GROUP
, ctr
->num_groups
)) ) {
1080 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
1083 ctr
->msg_groups
= groups
;
1085 /* clear the new entry and set the printer name */
1087 ZERO_STRUCT( ctr
->msg_groups
[ctr
->num_groups
-1] );
1088 fstrcpy( ctr
->msg_groups
[ctr
->num_groups
-1].printername
, msg
->printer
);
1091 /* add the change messages; 'i' is the correct index now regardless */
1093 msg_grp
= &ctr
->msg_groups
[i
];
1095 msg_grp
->num_msgs
++;
1097 if ( !(msg_list
= TALLOC_REALLOC_ARRAY( ctr
->ctx
, msg_grp
->msgs
, SPOOLSS_NOTIFY_MSG
, msg_grp
->num_msgs
)) ) {
1098 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp
->num_msgs
));
1101 msg_grp
->msgs
= msg_list
;
1103 new_slot
= msg_grp
->num_msgs
-1;
1104 memcpy( &msg_grp
->msgs
[new_slot
], msg
, sizeof(SPOOLSS_NOTIFY_MSG
) );
1106 /* need to allocate own copy of data */
1108 if ( msg
->len
!= 0 )
1109 msg_grp
->msgs
[new_slot
].notify
.data
= (char *)
1110 TALLOC_MEMDUP( ctr
->ctx
, msg
->notify
.data
, msg
->len
);
1112 return ctr
->num_groups
;
1115 static void construct_info_data(struct spoolss_Notify
*info_data
,
1116 enum spoolss_NotifyType type
,
1117 uint16_t field
, int id
);
1119 /***********************************************************************
1120 Send a change notication message on all handles which have a call
1122 **********************************************************************/
1124 static int build_notify2_messages(TALLOC_CTX
*mem_ctx
,
1125 struct printer_handle
*prn_hnd
,
1126 SPOOLSS_NOTIFY_MSG
*messages
,
1128 struct spoolss_Notify
**_notifies
,
1131 struct spoolss_Notify
*notifies
;
1132 SPOOLSS_NOTIFY_MSG
*msg
;
1137 notifies
= talloc_zero_array(mem_ctx
,
1138 struct spoolss_Notify
, num_msgs
);
1143 for (i
= 0; i
< num_msgs
; i
++) {
1147 /* Are we monitoring this event? */
1149 if (!is_monitoring_event(prn_hnd
, msg
->type
, msg
->field
)) {
1153 DEBUG(10, ("Sending message type [0x%x] field [0x%2x] "
1154 "for printer [%s]\n",
1155 msg
->type
, msg
->field
, prn_hnd
->sharename
));
1158 * if the is a printer notification handle and not a job
1159 * notification type, then set the id to 0.
1160 * Otherwise just use what was specified in the message.
1162 * When registering change notification on a print server
1163 * handle we always need to send back the id (snum) matching
1164 * the printer for which the change took place.
1165 * For change notify registered on a printer handle,
1166 * this does not matter and the id should be 0.
1171 if ((msg
->type
== PRINTER_NOTIFY_TYPE
) &&
1172 (prn_hnd
->printer_type
== SPLHND_PRINTER
)) {
1178 /* Convert unix jobid to smb jobid */
1180 if (msg
->flags
& SPOOLSS_NOTIFY_MSG_UNIX_JOBID
) {
1181 id
= sysjob_to_jobid(msg
->id
);
1184 DEBUG(3, ("no such unix jobid %d\n",
1190 construct_info_data(¬ifies
[count
],
1191 msg
->type
, msg
->field
, id
);
1194 case PRINTER_NOTIFY_TYPE
:
1195 if (printer_notify_table
[msg
->field
].fn
) {
1196 printer_notify_table
[msg
->field
].fn(msg
,
1197 ¬ifies
[count
], mem_ctx
);
1201 case JOB_NOTIFY_TYPE
:
1202 if (job_notify_table
[msg
->field
].fn
) {
1203 job_notify_table
[msg
->field
].fn(msg
,
1204 ¬ifies
[count
], mem_ctx
);
1209 DEBUG(5, ("Unknown notification type %d\n",
1217 *_notifies
= notifies
;
1223 static int send_notify2_printer(TALLOC_CTX
*mem_ctx
,
1224 struct printer_handle
*prn_hnd
,
1225 SPOOLSS_NOTIFY_MSG_GROUP
*msg_group
)
1227 struct spoolss_Notify
*notifies
;
1229 union spoolss_ReplyPrinterInfo info
;
1230 struct spoolss_NotifyInfo info0
;
1231 uint32_t reply_result
;
1236 /* Is there notification on this handle? */
1237 if (prn_hnd
->notify
.cli_chan
== NULL
||
1238 prn_hnd
->notify
.cli_chan
->active_connections
== 0) {
1242 DEBUG(10, ("Client connected! [\\\\%s\\%s]\n",
1243 prn_hnd
->servername
, prn_hnd
->sharename
));
1245 /* For this printer? Print servers always receive notifications. */
1246 if ((prn_hnd
->printer_type
== SPLHND_PRINTER
) &&
1247 (!strequal(msg_group
->printername
, prn_hnd
->sharename
))) {
1251 DEBUG(10,("Our printer\n"));
1253 /* build the array of change notifications */
1254 ret
= build_notify2_messages(mem_ctx
, prn_hnd
,
1256 msg_group
->num_msgs
,
1262 info0
.version
= 0x2;
1263 info0
.flags
= count
? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED
;
1264 info0
.count
= count
;
1265 info0
.notifies
= notifies
;
1267 info
.info0
= &info0
;
1269 status
= rpccli_spoolss_RouterReplyPrinterEx(
1270 prn_hnd
->notify
.cli_chan
->cli_pipe
,
1272 &prn_hnd
->notify
.cli_hnd
,
1273 prn_hnd
->notify
.change
, /* color */
1274 prn_hnd
->notify
.flags
,
1276 0, /* reply_type, must be 0 */
1278 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(werr
)) {
1279 DEBUG(1, ("RouterReplyPrinterEx to client: %s "
1281 prn_hnd
->notify
.cli_chan
->cli_pipe
->srv_name_slash
,
1284 switch (reply_result
) {
1287 case PRINTER_NOTIFY_INFO_DISCARDED
:
1288 case PRINTER_NOTIFY_INFO_DISCARDNOTED
:
1289 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH
:
1298 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR
*ctr
, uint32_t idx
)
1300 struct printer_handle
*p
;
1301 TALLOC_CTX
*mem_ctx
= notify_ctr_getctx( ctr
);
1302 SPOOLSS_NOTIFY_MSG_GROUP
*msg_group
= notify_ctr_getgroup( ctr
, idx
);
1306 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
1310 if (!msg_group
->msgs
) {
1311 DEBUG(5, ("send_notify2_changes() called with no messages!\n"));
1315 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group
->printername
));
1317 /* loop over all printers */
1319 for (p
= printers_list
; p
; p
= p
->next
) {
1320 ret
= send_notify2_printer(mem_ctx
, p
, msg_group
);
1327 DEBUG(8,("send_notify2_changes: Exit...\n"));
1331 /***********************************************************************
1332 **********************************************************************/
1334 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG
*msg
, struct timeval
*tv
, void *buf
, size_t len
)
1337 uint32_t tv_sec
, tv_usec
;
1340 /* Unpack message */
1342 offset
+= tdb_unpack((uint8_t *)buf
+ offset
, len
- offset
, "f",
1345 offset
+= tdb_unpack((uint8_t *)buf
+ offset
, len
- offset
, "ddddddd",
1347 &msg
->type
, &msg
->field
, &msg
->id
, &msg
->len
, &msg
->flags
);
1350 tdb_unpack((uint8_t *)buf
+ offset
, len
- offset
, "dd",
1351 &msg
->notify
.value
[0], &msg
->notify
.value
[1]);
1353 tdb_unpack((uint8_t *)buf
+ offset
, len
- offset
, "B",
1354 &msg
->len
, &msg
->notify
.data
);
1356 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1357 msg
->printer
, (unsigned int)msg
->id
, msg
->type
, msg
->field
, msg
->flags
));
1359 tv
->tv_sec
= tv_sec
;
1360 tv
->tv_usec
= tv_usec
;
1363 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg
->notify
.value
[0],
1364 msg
->notify
.value
[1]));
1366 dump_data(3, (uint8_t *)msg
->notify
.data
, msg
->len
);
1371 /********************************************************************
1372 Receive a notify2 message list
1373 ********************************************************************/
1375 static void receive_notify2_message_list(struct messaging_context
*msg
,
1378 struct server_id server_id
,
1381 size_t msg_count
, i
;
1382 char *buf
= (char *)data
->data
;
1385 SPOOLSS_NOTIFY_MSG notify
;
1386 SPOOLSS_NOTIFY_MSG_CTR messages
;
1389 if (data
->length
< 4) {
1390 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1394 msg_count
= IVAL(buf
, 0);
1397 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count
));
1399 if (msg_count
== 0) {
1400 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1404 /* initialize the container */
1406 ZERO_STRUCT( messages
);
1407 notify_msg_ctr_init( &messages
);
1410 * build message groups for each printer identified
1411 * in a change_notify msg. Remember that a PCN message
1412 * includes the handle returned for the srv_spoolss_replyopenprinter()
1413 * call. Therefore messages are grouped according to printer handle.
1416 for ( i
=0; i
<msg_count
; i
++ ) {
1417 struct timeval msg_tv
;
1419 if (msg_ptr
+ 4 - buf
> data
->length
) {
1420 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1424 msg_len
= IVAL(msg_ptr
,0);
1427 if (msg_ptr
+ msg_len
- buf
> data
->length
) {
1428 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1432 /* unpack messages */
1434 ZERO_STRUCT( notify
);
1435 notify2_unpack_msg( ¬ify
, &msg_tv
, msg_ptr
, msg_len
);
1438 /* add to correct list in container */
1440 notify_msg_ctr_addmsg( &messages
, ¬ify
);
1442 /* free memory that might have been allocated by notify2_unpack_msg() */
1444 if ( notify
.len
!= 0 )
1445 SAFE_FREE( notify
.notify
.data
);
1448 /* process each group of messages */
1450 num_groups
= notify_msg_ctr_numgroups( &messages
);
1451 for ( i
=0; i
<num_groups
; i
++ )
1452 send_notify2_changes( &messages
, i
);
1457 DEBUG(10,("receive_notify2_message_list: processed %u messages\n",
1458 (uint32_t)msg_count
));
1460 notify_msg_ctr_destroy( &messages
);
1465 /********************************************************************
1466 Send a message to ourself about new driver being installed
1467 so we can upgrade the information for each printer bound to this
1469 ********************************************************************/
1471 static bool srv_spoolss_drv_upgrade_printer(const char *drivername
,
1472 struct messaging_context
*msg_ctx
)
1474 int len
= strlen(drivername
);
1479 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1482 messaging_send_buf(msg_ctx
, messaging_server_id(msg_ctx
),
1483 MSG_PRINTER_DRVUPGRADE
,
1484 (uint8_t *)drivername
, len
+1);
1489 void srv_spoolss_cleanup(void)
1491 struct printer_session_counter
*session_counter
;
1493 for (session_counter
= counter_list
;
1494 session_counter
!= NULL
;
1495 session_counter
= counter_list
) {
1496 DLIST_REMOVE(counter_list
, session_counter
);
1497 TALLOC_FREE(session_counter
);
1501 /**********************************************************************
1502 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1503 over all printers, upgrading ones as necessary
1504 **********************************************************************/
1506 void do_drv_upgrade_printer(struct messaging_context
*msg
,
1509 struct server_id server_id
,
1512 TALLOC_CTX
*tmp_ctx
;
1513 struct auth_serversupplied_info
*server_info
= NULL
;
1514 struct spoolss_PrinterInfo2
*pinfo2
;
1517 const char *drivername
;
1519 int n_services
= lp_numservices();
1521 tmp_ctx
= talloc_new(NULL
);
1522 if (!tmp_ctx
) return;
1524 status
= make_server_info_system(tmp_ctx
, &server_info
);
1525 if (!NT_STATUS_IS_OK(status
)) {
1526 DEBUG(0, ("do_drv_upgrade_printer: "
1527 "Could not create system server_info\n"));
1531 drivername
= talloc_strndup(tmp_ctx
, (const char *)data
->data
, data
->length
);
1533 DEBUG(0, ("do_drv_upgrade_printer: Out of memoery ?!\n"));
1537 DEBUG(10, ("do_drv_upgrade_printer: "
1538 "Got message for new driver [%s]\n", drivername
));
1540 /* Iterate the printer list */
1542 for (snum
= 0; snum
< n_services
; snum
++) {
1543 if (!lp_snum_ok(snum
) || !lp_print_ok(snum
)) {
1547 /* ignore [printers] share */
1548 if (strequal(lp_const_servicename(snum
), "printers")) {
1552 result
= winreg_get_printer(tmp_ctx
, server_info
, msg
,
1553 lp_const_servicename(snum
),
1556 if (!W_ERROR_IS_OK(result
)) {
1560 if (!pinfo2
->drivername
) {
1564 if (strcmp(drivername
, pinfo2
->drivername
) != 0) {
1568 DEBUG(6,("Updating printer [%s]\n", pinfo2
->printername
));
1570 /* all we care about currently is the change_id */
1571 result
= winreg_printer_update_changeid(tmp_ctx
,
1574 pinfo2
->printername
);
1576 if (!W_ERROR_IS_OK(result
)) {
1577 DEBUG(3, ("do_drv_upgrade_printer: "
1578 "Failed to update changeid [%s]\n",
1579 win_errstr(result
)));
1585 talloc_free(tmp_ctx
);
1588 /********************************************************************
1589 Update the cache for all printq's with a registered client
1591 ********************************************************************/
1593 void update_monitored_printq_cache(struct messaging_context
*msg_ctx
)
1595 struct printer_handle
*printer
= printers_list
;
1598 /* loop through all printers and update the cache where
1599 a client is connected */
1601 if ((printer
->printer_type
== SPLHND_PRINTER
) &&
1602 ((printer
->notify
.cli_chan
!= NULL
) &&
1603 (printer
->notify
.cli_chan
->active_connections
> 0))) {
1604 snum
= print_queue_snum(printer
->sharename
);
1605 print_queue_status(msg_ctx
, snum
, NULL
, NULL
);
1608 printer
= printer
->next
;
1614 /****************************************************************
1615 _spoolss_OpenPrinter
1616 ****************************************************************/
1618 WERROR
_spoolss_OpenPrinter(struct pipes_struct
*p
,
1619 struct spoolss_OpenPrinter
*r
)
1621 struct spoolss_OpenPrinterEx e
;
1624 ZERO_STRUCT(e
.in
.userlevel
);
1626 e
.in
.printername
= r
->in
.printername
;
1627 e
.in
.datatype
= r
->in
.datatype
;
1628 e
.in
.devmode_ctr
= r
->in
.devmode_ctr
;
1629 e
.in
.access_mask
= r
->in
.access_mask
;
1632 e
.out
.handle
= r
->out
.handle
;
1634 werr
= _spoolss_OpenPrinterEx(p
, &e
);
1636 if (W_ERROR_EQUAL(werr
, WERR_INVALID_PARAM
)) {
1637 /* OpenPrinterEx returns this for a bad
1638 * printer name. We must return WERR_INVALID_PRINTER_NAME
1641 werr
= WERR_INVALID_PRINTER_NAME
;
1647 static WERROR
copy_devicemode(TALLOC_CTX
*mem_ctx
,
1648 struct spoolss_DeviceMode
*orig
,
1649 struct spoolss_DeviceMode
**dest
)
1651 struct spoolss_DeviceMode
*dm
;
1653 dm
= talloc(mem_ctx
, struct spoolss_DeviceMode
);
1658 /* copy all values, then duplicate strings and structs */
1661 dm
->devicename
= talloc_strdup(dm
, orig
->devicename
);
1662 if (!dm
->devicename
) {
1665 dm
->formname
= talloc_strdup(dm
, orig
->formname
);
1666 if (!dm
->formname
) {
1669 if (orig
->driverextra_data
.data
) {
1670 dm
->driverextra_data
.data
=
1671 (uint8_t *) talloc_memdup(dm
, orig
->driverextra_data
.data
,
1672 orig
->driverextra_data
.length
);
1673 if (!dm
->driverextra_data
.data
) {
1682 /****************************************************************
1683 _spoolss_OpenPrinterEx
1684 ****************************************************************/
1686 WERROR
_spoolss_OpenPrinterEx(struct pipes_struct
*p
,
1687 struct spoolss_OpenPrinterEx
*r
)
1690 struct printer_handle
*Printer
=NULL
;
1693 if (!r
->in
.printername
) {
1694 return WERR_INVALID_PARAM
;
1697 if (r
->in
.level
< 0 || r
->in
.level
> 3) {
1698 return WERR_INVALID_PARAM
;
1700 if ((r
->in
.level
== 1 && !r
->in
.userlevel
.level1
) ||
1701 (r
->in
.level
== 2 && !r
->in
.userlevel
.level2
) ||
1702 (r
->in
.level
== 3 && !r
->in
.userlevel
.level3
)) {
1703 return WERR_INVALID_PARAM
;
1706 /* some sanity check because you can open a printer or a print server */
1707 /* aka: \\server\printer or \\server */
1709 DEBUGADD(3,("checking name: %s\n", r
->in
.printername
));
1711 result
= open_printer_hnd(p
, r
->out
.handle
, r
->in
.printername
, 0);
1712 if (!W_ERROR_IS_OK(result
)) {
1713 DEBUG(0,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
1714 "for printer %s\n", r
->in
.printername
));
1715 ZERO_STRUCTP(r
->out
.handle
);
1719 Printer
= find_printer_index_by_hnd(p
, r
->out
.handle
);
1721 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1722 "handle we created for printer %s\n", r
->in
.printername
));
1723 close_printer_handle(p
, r
->out
.handle
);
1724 ZERO_STRUCTP(r
->out
.handle
);
1725 return WERR_INVALID_PARAM
;
1729 * First case: the user is opening the print server:
1731 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1732 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1734 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1735 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1736 * or if the user is listed in the smb.conf printer admin parameter.
1738 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1739 * client view printer folder, but does not show the MSAPW.
1741 * Note: this test needs code to check access rights here too. Jeremy
1742 * could you look at this?
1744 * Second case: the user is opening a printer:
1745 * NT doesn't let us connect to a printer if the connecting user
1746 * doesn't have print permission.
1748 * Third case: user is opening a Port Monitor
1749 * access checks same as opening a handle to the print server.
1752 switch (Printer
->printer_type
)
1755 case SPLHND_PORTMON_TCP
:
1756 case SPLHND_PORTMON_LOCAL
:
1757 /* Printserver handles use global struct... */
1761 /* Map standard access rights to object specific access rights */
1763 se_map_standard(&r
->in
.access_mask
,
1764 &printserver_std_mapping
);
1766 /* Deny any object specific bits that don't apply to print
1767 servers (i.e printer and job specific bits) */
1769 r
->in
.access_mask
&= SEC_MASK_SPECIFIC
;
1771 if (r
->in
.access_mask
&
1772 ~(SERVER_ACCESS_ADMINISTER
| SERVER_ACCESS_ENUMERATE
)) {
1773 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1774 close_printer_handle(p
, r
->out
.handle
);
1775 ZERO_STRUCTP(r
->out
.handle
);
1776 return WERR_ACCESS_DENIED
;
1779 /* Allow admin access */
1781 if ( r
->in
.access_mask
& SERVER_ACCESS_ADMINISTER
)
1783 if (!lp_ms_add_printer_wizard()) {
1784 close_printer_handle(p
, r
->out
.handle
);
1785 ZERO_STRUCTP(r
->out
.handle
);
1786 return WERR_ACCESS_DENIED
;
1789 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1790 and not a printer admin, then fail */
1792 if ((p
->server_info
->utok
.uid
!= sec_initial_uid()) &&
1793 !security_token_has_privilege(p
->server_info
->ptok
, SEC_PRIV_PRINT_OPERATOR
) &&
1794 !nt_token_check_sid(&global_sid_Builtin_Print_Operators
, p
->server_info
->ptok
) &&
1795 !token_contains_name_in_list(
1796 uidtoname(p
->server_info
->utok
.uid
),
1797 p
->server_info
->info3
->base
.domain
.string
,
1799 p
->server_info
->ptok
,
1800 lp_printer_admin(snum
))) {
1801 close_printer_handle(p
, r
->out
.handle
);
1802 ZERO_STRUCTP(r
->out
.handle
);
1803 DEBUG(3,("access DENIED as user is not root, "
1804 "has no printoperator privilege, "
1805 "not a member of the printoperator builtin group and "
1806 "is not in printer admin list"));
1807 return WERR_ACCESS_DENIED
;
1810 r
->in
.access_mask
= SERVER_ACCESS_ADMINISTER
;
1814 r
->in
.access_mask
= SERVER_ACCESS_ENUMERATE
;
1817 DEBUG(4,("Setting print server access = %s\n", (r
->in
.access_mask
== SERVER_ACCESS_ADMINISTER
)
1818 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1820 /* We fall through to return WERR_OK */
1823 case SPLHND_PRINTER
:
1824 /* NT doesn't let us connect to a printer if the connecting user
1825 doesn't have print permission. */
1827 if (!get_printer_snum(p
, r
->out
.handle
, &snum
, NULL
)) {
1828 close_printer_handle(p
, r
->out
.handle
);
1829 ZERO_STRUCTP(r
->out
.handle
);
1833 if (r
->in
.access_mask
== SEC_FLAG_MAXIMUM_ALLOWED
) {
1834 r
->in
.access_mask
= PRINTER_ACCESS_ADMINISTER
;
1837 se_map_standard(&r
->in
.access_mask
, &printer_std_mapping
);
1839 /* map an empty access mask to the minimum access mask */
1840 if (r
->in
.access_mask
== 0x0)
1841 r
->in
.access_mask
= PRINTER_ACCESS_USE
;
1844 * If we are not serving the printer driver for this printer,
1845 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1846 * will keep NT clients happy --jerry
1849 if (lp_use_client_driver(snum
)
1850 && (r
->in
.access_mask
& PRINTER_ACCESS_ADMINISTER
))
1852 r
->in
.access_mask
= PRINTER_ACCESS_USE
;
1855 /* check smb.conf parameters and the the sec_desc */
1857 if (!allow_access(lp_hostsdeny(snum
), lp_hostsallow(snum
),
1858 p
->client_id
->name
, p
->client_id
->addr
)) {
1859 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1860 ZERO_STRUCTP(r
->out
.handle
);
1861 return WERR_ACCESS_DENIED
;
1864 if (!user_ok_token(uidtoname(p
->server_info
->utok
.uid
), NULL
,
1865 p
->server_info
->ptok
, snum
) ||
1866 !print_access_check(p
->server_info
,
1869 r
->in
.access_mask
)) {
1870 DEBUG(3, ("access DENIED for printer open\n"));
1871 close_printer_handle(p
, r
->out
.handle
);
1872 ZERO_STRUCTP(r
->out
.handle
);
1873 return WERR_ACCESS_DENIED
;
1876 if ((r
->in
.access_mask
& SEC_MASK_SPECIFIC
)& ~(PRINTER_ACCESS_ADMINISTER
|PRINTER_ACCESS_USE
)) {
1877 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1878 close_printer_handle(p
, r
->out
.handle
);
1879 ZERO_STRUCTP(r
->out
.handle
);
1880 return WERR_ACCESS_DENIED
;
1883 if (r
->in
.access_mask
& PRINTER_ACCESS_ADMINISTER
)
1884 r
->in
.access_mask
= PRINTER_ACCESS_ADMINISTER
;
1886 r
->in
.access_mask
= PRINTER_ACCESS_USE
;
1888 DEBUG(4,("Setting printer access = %s\n", (r
->in
.access_mask
== PRINTER_ACCESS_ADMINISTER
)
1889 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1891 winreg_create_printer(p
->mem_ctx
,
1892 get_server_info_system(),
1894 lp_const_servicename(snum
));
1899 /* sanity check to prevent programmer error */
1900 ZERO_STRUCTP(r
->out
.handle
);
1904 Printer
->access_granted
= r
->in
.access_mask
;
1907 * If the client sent a devmode in the OpenPrinter() call, then
1908 * save it here in case we get a job submission on this handle
1911 if ((Printer
->printer_type
!= SPLHND_SERVER
) &&
1912 r
->in
.devmode_ctr
.devmode
) {
1913 copy_devicemode(NULL
, r
->in
.devmode_ctr
.devmode
,
1917 #if 0 /* JERRY -- I'm doubtful this is really effective */
1918 /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
1919 optimization in Windows 2000 clients --jerry */
1921 if ( (r
->in
.access_mask
== PRINTER_ACCESS_ADMINISTER
)
1922 && (RA_WIN2K
== get_remote_arch()) )
1924 DEBUG(10,("_spoolss_OpenPrinterEx: Enabling LAN/WAN hack for Win2k clients.\n"));
1925 sys_usleep( 500000 );
1932 /****************************************************************
1933 _spoolss_ClosePrinter
1934 ****************************************************************/
1936 WERROR
_spoolss_ClosePrinter(struct pipes_struct
*p
,
1937 struct spoolss_ClosePrinter
*r
)
1939 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
1941 if (Printer
&& Printer
->document_started
) {
1942 struct spoolss_EndDocPrinter e
;
1944 e
.in
.handle
= r
->in
.handle
;
1946 _spoolss_EndDocPrinter(p
, &e
);
1949 if (!close_printer_handle(p
, r
->in
.handle
))
1952 /* clear the returned printer handle. Observed behavior
1953 from Win2k server. Don't think this really matters.
1954 Previous code just copied the value of the closed
1957 ZERO_STRUCTP(r
->out
.handle
);
1962 /****************************************************************
1963 _spoolss_DeletePrinter
1964 ****************************************************************/
1966 WERROR
_spoolss_DeletePrinter(struct pipes_struct
*p
,
1967 struct spoolss_DeletePrinter
*r
)
1969 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
1973 if (Printer
&& Printer
->document_started
) {
1974 struct spoolss_EndDocPrinter e
;
1976 e
.in
.handle
= r
->in
.handle
;
1978 _spoolss_EndDocPrinter(p
, &e
);
1981 if (get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
1982 winreg_delete_printer_key(p
->mem_ctx
,
1983 get_server_info_system(),
1985 lp_const_servicename(snum
),
1989 result
= delete_printer_handle(p
, r
->in
.handle
);
1994 /*******************************************************************
1995 * static function to lookup the version id corresponding to an
1996 * long architecture string
1997 ******************************************************************/
1999 static const struct print_architecture_table_node archi_table
[]= {
2001 {"Windows 4.0", SPL_ARCH_WIN40
, 0 },
2002 {"Windows NT x86", SPL_ARCH_W32X86
, 2 },
2003 {"Windows NT R4000", SPL_ARCH_W32MIPS
, 2 },
2004 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA
, 2 },
2005 {"Windows NT PowerPC", SPL_ARCH_W32PPC
, 2 },
2006 {"Windows IA64", SPL_ARCH_IA64
, 3 },
2007 {"Windows x64", SPL_ARCH_X64
, 3 },
2011 static int get_version_id(const char *arch
)
2015 for (i
=0; archi_table
[i
].long_archi
!= NULL
; i
++)
2017 if (strcmp(arch
, archi_table
[i
].long_archi
) == 0)
2018 return (archi_table
[i
].version
);
2024 /****************************************************************
2025 _spoolss_DeletePrinterDriver
2026 ****************************************************************/
2028 WERROR
_spoolss_DeletePrinterDriver(struct pipes_struct
*p
,
2029 struct spoolss_DeletePrinterDriver
*r
)
2032 struct spoolss_DriverInfo8
*info
= NULL
;
2033 struct spoolss_DriverInfo8
*info_win2k
= NULL
;
2037 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2038 and not a printer admin, then fail */
2040 if ( (p
->server_info
->utok
.uid
!= sec_initial_uid())
2041 && !security_token_has_privilege(p
->server_info
->ptok
, SEC_PRIV_PRINT_OPERATOR
)
2042 && !token_contains_name_in_list(
2043 uidtoname(p
->server_info
->utok
.uid
),
2044 p
->server_info
->info3
->base
.domain
.string
,
2046 p
->server_info
->ptok
,
2047 lp_printer_admin(-1)) )
2049 return WERR_ACCESS_DENIED
;
2052 /* check that we have a valid driver name first */
2054 if ((version
= get_version_id(r
->in
.architecture
)) == -1)
2055 return WERR_INVALID_ENVIRONMENT
;
2057 status
= winreg_get_driver(p
->mem_ctx
,
2058 get_server_info_system(),
2060 r
->in
.architecture
, r
->in
.driver
,
2062 if (!W_ERROR_IS_OK(status
)) {
2063 /* try for Win2k driver if "Windows NT x86" */
2065 if ( version
== 2 ) {
2068 status
= winreg_get_driver(p
->mem_ctx
,
2069 get_server_info_system(),
2074 if (!W_ERROR_IS_OK(status
)) {
2075 status
= WERR_UNKNOWN_PRINTER_DRIVER
;
2079 /* otherwise it was a failure */
2081 status
= WERR_UNKNOWN_PRINTER_DRIVER
;
2087 if (printer_driver_in_use(p
->mem_ctx
,
2088 get_server_info_system(),
2091 status
= WERR_PRINTER_DRIVER_IN_USE
;
2096 status
= winreg_get_driver(p
->mem_ctx
,
2097 get_server_info_system(),
2100 r
->in
.driver
, 3, &info_win2k
);
2101 if (W_ERROR_IS_OK(status
)) {
2102 /* if we get to here, we now have 2 driver info structures to remove */
2103 /* remove the Win2k driver first*/
2105 status
= winreg_del_driver(p
->mem_ctx
,
2106 get_server_info_system(),
2109 talloc_free(info_win2k
);
2111 /* this should not have failed---if it did, report to client */
2112 if (!W_ERROR_IS_OK(status
)) {
2118 status
= winreg_del_driver(p
->mem_ctx
,
2119 get_server_info_system(),
2129 /****************************************************************
2130 _spoolss_DeletePrinterDriverEx
2131 ****************************************************************/
2133 WERROR
_spoolss_DeletePrinterDriverEx(struct pipes_struct
*p
,
2134 struct spoolss_DeletePrinterDriverEx
*r
)
2136 struct spoolss_DriverInfo8
*info
= NULL
;
2137 struct spoolss_DriverInfo8
*info_win2k
= NULL
;
2142 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2143 and not a printer admin, then fail */
2145 if ( (p
->server_info
->utok
.uid
!= sec_initial_uid())
2146 && !security_token_has_privilege(p
->server_info
->ptok
, SEC_PRIV_PRINT_OPERATOR
)
2147 && !token_contains_name_in_list(
2148 uidtoname(p
->server_info
->utok
.uid
),
2149 p
->server_info
->info3
->base
.domain
.string
,
2151 p
->server_info
->ptok
, lp_printer_admin(-1)) )
2153 return WERR_ACCESS_DENIED
;
2156 /* check that we have a valid driver name first */
2157 if ((version
= get_version_id(r
->in
.architecture
)) == -1) {
2158 /* this is what NT returns */
2159 return WERR_INVALID_ENVIRONMENT
;
2162 if (r
->in
.delete_flags
& DPD_DELETE_SPECIFIC_VERSION
)
2163 version
= r
->in
.version
;
2165 status
= winreg_get_driver(p
->mem_ctx
,
2166 get_server_info_system(),
2172 if (!W_ERROR_IS_OK(status
)) {
2173 status
= WERR_UNKNOWN_PRINTER_DRIVER
;
2176 * if the client asked for a specific version,
2177 * or this is something other than Windows NT x86,
2181 if ( (r
->in
.delete_flags
& DPD_DELETE_SPECIFIC_VERSION
) || (version
!=2) )
2184 /* try for Win2k driver if "Windows NT x86" */
2187 status
= winreg_get_driver(info
,
2188 get_server_info_system(),
2193 if (!W_ERROR_IS_OK(status
)) {
2194 status
= WERR_UNKNOWN_PRINTER_DRIVER
;
2199 if (printer_driver_in_use(info
,
2200 get_server_info_system(),
2203 status
= WERR_PRINTER_DRIVER_IN_USE
;
2208 * we have a couple of cases to consider.
2209 * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set,
2210 * then the delete should fail if **any** files overlap with
2212 * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
2213 * non-overlapping files
2214 * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
2215 * is set, the do not delete any files
2216 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
2219 delete_files
= r
->in
.delete_flags
& (DPD_DELETE_ALL_FILES
|DPD_DELETE_UNUSED_FILES
);
2221 /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
2224 (r
->in
.delete_flags
& DPD_DELETE_ALL_FILES
) &&
2225 printer_driver_files_in_use(info
,
2226 get_server_info_system(),
2229 /* no idea of the correct error here */
2230 status
= WERR_ACCESS_DENIED
;
2235 /* also check for W32X86/3 if necessary; maybe we already have? */
2237 if ( (version
== 2) && ((r
->in
.delete_flags
& DPD_DELETE_SPECIFIC_VERSION
) != DPD_DELETE_SPECIFIC_VERSION
) ) {
2238 status
= winreg_get_driver(info
,
2239 get_server_info_system(),
2242 r
->in
.driver
, 3, &info_win2k
);
2243 if (W_ERROR_IS_OK(status
)) {
2246 (r
->in
.delete_flags
& DPD_DELETE_ALL_FILES
) &&
2247 printer_driver_files_in_use(info
,
2248 get_server_info_system(),
2251 /* no idea of the correct error here */
2252 talloc_free(info_win2k
);
2253 status
= WERR_ACCESS_DENIED
;
2257 /* if we get to here, we now have 2 driver info structures to remove */
2258 /* remove the Win2k driver first*/
2260 status
= winreg_del_driver(info
,
2261 get_server_info_system(),
2266 /* this should not have failed---if it did, report to client */
2268 if (!W_ERROR_IS_OK(status
)) {
2273 * now delete any associated files if delete_files is
2274 * true. Even if this part failes, we return succes
2275 * because the driver doesn not exist any more
2278 delete_driver_files(get_server_info_system(),
2284 status
= winreg_del_driver(info
,
2285 get_server_info_system(),
2289 if (!W_ERROR_IS_OK(status
)) {
2294 * now delete any associated files if delete_files is
2295 * true. Even if this part failes, we return succes
2296 * because the driver doesn not exist any more
2299 delete_driver_files(get_server_info_system(), info
);
2308 /********************************************************************
2309 GetPrinterData on a printer server Handle.
2310 ********************************************************************/
2312 static WERROR
getprinterdata_printer_server(TALLOC_CTX
*mem_ctx
,
2314 enum winreg_Type
*type
,
2315 union spoolss_PrinterData
*data
)
2317 DEBUG(8,("getprinterdata_printer_server:%s\n", value
));
2319 if (!StrCaseCmp(value
, "W3SvcInstalled")) {
2325 if (!StrCaseCmp(value
, "BeepEnabled")) {
2331 if (!StrCaseCmp(value
, "EventLog")) {
2333 /* formally was 0x1b */
2338 if (!StrCaseCmp(value
, "NetPopup")) {
2344 if (!StrCaseCmp(value
, "MajorVersion")) {
2347 /* Windows NT 4.0 seems to not allow uploading of drivers
2348 to a server that reports 0x3 as the MajorVersion.
2349 need to investigate more how Win2k gets around this .
2352 if (RA_WINNT
== get_remote_arch()) {
2361 if (!StrCaseCmp(value
, "MinorVersion")) {
2368 * uint32_t size = 0x114
2369 * uint32_t major = 5
2370 * uint32_t minor = [0|1]
2371 * uint32_t build = [2195|2600]
2372 * extra unicode string = e.g. "Service Pack 3"
2374 if (!StrCaseCmp(value
, "OSVersion")) {
2376 enum ndr_err_code ndr_err
;
2377 struct spoolss_OSVersion os
;
2379 os
.major
= 5; /* Windows 2000 == 5.0 */
2381 os
.build
= 2195; /* build */
2382 os
.extra_string
= ""; /* leave extra string empty */
2384 ndr_err
= ndr_push_struct_blob(&blob
, mem_ctx
, &os
,
2385 (ndr_push_flags_fn_t
)ndr_push_spoolss_OSVersion
);
2386 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2387 return WERR_GENERAL_FAILURE
;
2391 data
->binary
= blob
;
2397 if (!StrCaseCmp(value
, "DefaultSpoolDirectory")) {
2400 data
->string
= talloc_strdup(mem_ctx
, "C:\\PRINTERS");
2401 W_ERROR_HAVE_NO_MEMORY(data
->string
);
2406 if (!StrCaseCmp(value
, "Architecture")) {
2408 data
->string
= talloc_strdup(mem_ctx
,
2409 lp_parm_const_string(GLOBAL_SECTION_SNUM
, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_NT_X86
));
2410 W_ERROR_HAVE_NO_MEMORY(data
->string
);
2415 if (!StrCaseCmp(value
, "DsPresent")) {
2418 /* only show the publish check box if we are a
2419 member of a AD domain */
2421 if (lp_security() == SEC_ADS
) {
2429 if (!StrCaseCmp(value
, "DNSMachineName")) {
2430 const char *hostname
= get_mydnsfullname();
2433 return WERR_BADFILE
;
2437 data
->string
= talloc_strdup(mem_ctx
, hostname
);
2438 W_ERROR_HAVE_NO_MEMORY(data
->string
);
2445 return WERR_INVALID_PARAM
;
2448 /****************************************************************
2449 _spoolss_GetPrinterData
2450 ****************************************************************/
2452 WERROR
_spoolss_GetPrinterData(struct pipes_struct
*p
,
2453 struct spoolss_GetPrinterData
*r
)
2455 struct spoolss_GetPrinterDataEx r2
;
2457 r2
.in
.handle
= r
->in
.handle
;
2458 r2
.in
.key_name
= "PrinterDriverData";
2459 r2
.in
.value_name
= r
->in
.value_name
;
2460 r2
.in
.offered
= r
->in
.offered
;
2461 r2
.out
.type
= r
->out
.type
;
2462 r2
.out
.data
= r
->out
.data
;
2463 r2
.out
.needed
= r
->out
.needed
;
2465 return _spoolss_GetPrinterDataEx(p
, &r2
);
2468 /*********************************************************
2469 Connect to the client machine.
2470 **********************************************************/
2472 static bool spoolss_connect_to_client(struct rpc_pipe_client
**pp_pipe
,
2473 struct sockaddr_storage
*client_ss
, const char *remote_machine
)
2476 struct cli_state
*the_cli
;
2477 struct sockaddr_storage rm_addr
;
2478 char addr
[INET6_ADDRSTRLEN
];
2480 if ( is_zero_addr((struct sockaddr
*)client_ss
) ) {
2481 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2483 if ( !resolve_name( remote_machine
, &rm_addr
, 0x20, false) ) {
2484 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine
));
2487 print_sockaddr(addr
, sizeof(addr
), &rm_addr
);
2489 rm_addr
= *client_ss
;
2490 print_sockaddr(addr
, sizeof(addr
), &rm_addr
);
2491 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2495 if (ismyaddr((struct sockaddr
*)(void *)&rm_addr
)) {
2496 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2501 /* setup the connection */
2502 ret
= cli_full_connection( &the_cli
, global_myname(), remote_machine
,
2503 &rm_addr
, 0, "IPC$", "IPC",
2507 0, lp_client_signing());
2509 if ( !NT_STATUS_IS_OK( ret
) ) {
2510 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2515 if ( the_cli
->protocol
!= PROTOCOL_NT1
) {
2516 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine
));
2517 cli_shutdown(the_cli
);
2522 * Ok - we have an anonymous connection to the IPC$ share.
2523 * Now start the NT Domain stuff :-).
2526 ret
= cli_rpc_pipe_open_noauth(the_cli
, &ndr_table_spoolss
.syntax_id
, pp_pipe
);
2527 if (!NT_STATUS_IS_OK(ret
)) {
2528 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2529 remote_machine
, nt_errstr(ret
)));
2530 cli_shutdown(the_cli
);
2537 /***************************************************************************
2538 Connect to the client.
2539 ****************************************************************************/
2541 static bool srv_spoolss_replyopenprinter(int snum
, const char *printer
,
2542 uint32_t localprinter
,
2543 enum winreg_Type type
,
2544 struct policy_handle
*handle
,
2545 struct notify_back_channel
**_chan
,
2546 struct sockaddr_storage
*client_ss
,
2547 struct messaging_context
*msg_ctx
)
2551 struct notify_back_channel
*chan
;
2553 for (chan
= back_channels
; chan
; chan
= chan
->next
) {
2554 if (memcmp(&chan
->client_address
, client_ss
,
2555 sizeof(struct sockaddr_storage
)) == 0) {
2561 * If it's the first connection, contact the client
2562 * and connect to the IPC$ share anonymously
2565 fstring unix_printer
;
2567 /* the +2 is to strip the leading 2 backslashs */
2568 fstrcpy(unix_printer
, printer
+ 2);
2570 chan
= talloc_zero(back_channels
, struct notify_back_channel
);
2574 chan
->client_address
= *client_ss
;
2576 if (!spoolss_connect_to_client(&chan
->cli_pipe
, client_ss
, unix_printer
)) {
2581 DLIST_ADD(back_channels
, chan
);
2583 messaging_register(msg_ctx
, NULL
, MSG_PRINTER_NOTIFY2
,
2584 receive_notify2_message_list
);
2585 /* Tell the connections db we're now interested in printer
2586 * notify messages. */
2587 serverid_register_msg_flags(messaging_server_id(msg_ctx
),
2588 true, FLAG_MSG_PRINT_NOTIFY
);
2592 * Tell the specific printing tdb we want messages for this printer
2593 * by registering our PID.
2596 if (!print_notify_register_pid(snum
)) {
2597 DEBUG(0, ("Failed to register our pid for printer %s\n",
2601 status
= rpccli_spoolss_ReplyOpenPrinter(chan
->cli_pipe
, talloc_tos(),
2609 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
2610 DEBUG(5, ("Client RPC returned [%s]\n", win_errstr(result
)));
2613 chan
->active_connections
++;
2616 return (W_ERROR_IS_OK(result
));
2619 /****************************************************************
2620 ****************************************************************/
2622 static struct spoolss_NotifyOption
*dup_spoolss_NotifyOption(TALLOC_CTX
*mem_ctx
,
2623 const struct spoolss_NotifyOption
*r
)
2625 struct spoolss_NotifyOption
*option
;
2632 option
= talloc_zero(mem_ctx
, struct spoolss_NotifyOption
);
2639 if (!option
->count
) {
2643 option
->types
= talloc_zero_array(option
,
2644 struct spoolss_NotifyOptionType
, option
->count
);
2645 if (!option
->types
) {
2646 talloc_free(option
);
2650 for (i
=0; i
< option
->count
; i
++) {
2651 option
->types
[i
] = r
->types
[i
];
2653 if (option
->types
[i
].count
) {
2654 option
->types
[i
].fields
= talloc_zero_array(option
,
2655 union spoolss_Field
, option
->types
[i
].count
);
2656 if (!option
->types
[i
].fields
) {
2657 talloc_free(option
);
2660 for (k
=0; k
<option
->types
[i
].count
; k
++) {
2661 option
->types
[i
].fields
[k
] =
2662 r
->types
[i
].fields
[k
];
2670 /****************************************************************
2671 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2673 * before replying OK: status=0 a rpc call is made to the workstation
2674 * asking ReplyOpenPrinter
2676 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2677 * called from api_spoolss_rffpcnex
2678 ****************************************************************/
2680 WERROR
_spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct
*p
,
2681 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx
*r
)
2684 struct spoolss_NotifyOption
*option
= r
->in
.notify_options
;
2685 struct sockaddr_storage client_ss
;
2687 /* store the notify value in the printer struct */
2689 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
2692 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2693 "Invalid handle (%s:%u:%u).\n",
2694 OUR_HANDLE(r
->in
.handle
)));
2698 Printer
->notify
.flags
= r
->in
.flags
;
2699 Printer
->notify
.options
= r
->in
.options
;
2700 Printer
->notify
.printerlocal
= r
->in
.printer_local
;
2701 Printer
->notify
.msg_ctx
= p
->msg_ctx
;
2703 TALLOC_FREE(Printer
->notify
.option
);
2704 Printer
->notify
.option
= dup_spoolss_NotifyOption(Printer
, option
);
2706 fstrcpy(Printer
->notify
.localmachine
, r
->in
.local_machine
);
2708 /* Connect to the client machine and send a ReplyOpenPrinter */
2710 if ( Printer
->printer_type
== SPLHND_SERVER
)
2712 else if ( (Printer
->printer_type
== SPLHND_PRINTER
) &&
2713 !get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
) )
2716 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2717 "client_address is %s\n", p
->client_id
->addr
));
2719 if (!interpret_string_addr(&client_ss
, p
->client_id
->addr
,
2721 return WERR_SERVER_UNAVAILABLE
;
2724 if(!srv_spoolss_replyopenprinter(snum
, Printer
->notify
.localmachine
,
2725 Printer
->notify
.printerlocal
, REG_SZ
,
2726 &Printer
->notify
.cli_hnd
,
2727 &Printer
->notify
.cli_chan
,
2728 &client_ss
, p
->msg_ctx
)) {
2729 return WERR_SERVER_UNAVAILABLE
;
2735 /*******************************************************************
2736 * fill a notify_info_data with the servername
2737 ********************************************************************/
2739 static void spoolss_notify_server_name(struct messaging_context
*msg_ctx
,
2741 struct spoolss_Notify
*data
,
2742 print_queue_struct
*queue
,
2743 struct spoolss_PrinterInfo2
*pinfo2
,
2744 TALLOC_CTX
*mem_ctx
)
2746 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->servername
);
2749 /*******************************************************************
2750 * fill a notify_info_data with the printername (not including the servername).
2751 ********************************************************************/
2753 static void spoolss_notify_printer_name(struct messaging_context
*msg_ctx
,
2755 struct spoolss_Notify
*data
,
2756 print_queue_struct
*queue
,
2757 struct spoolss_PrinterInfo2
*pinfo2
,
2758 TALLOC_CTX
*mem_ctx
)
2760 /* the notify name should not contain the \\server\ part */
2761 const char *p
= strrchr(pinfo2
->printername
, '\\');
2764 p
= pinfo2
->printername
;
2769 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, p
);
2772 /*******************************************************************
2773 * fill a notify_info_data with the servicename
2774 ********************************************************************/
2776 static void spoolss_notify_share_name(struct messaging_context
*msg_ctx
,
2778 struct spoolss_Notify
*data
,
2779 print_queue_struct
*queue
,
2780 struct spoolss_PrinterInfo2
*pinfo2
,
2781 TALLOC_CTX
*mem_ctx
)
2783 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, lp_servicename(snum
));
2786 /*******************************************************************
2787 * fill a notify_info_data with the port name
2788 ********************************************************************/
2790 static void spoolss_notify_port_name(struct messaging_context
*msg_ctx
,
2792 struct spoolss_Notify
*data
,
2793 print_queue_struct
*queue
,
2794 struct spoolss_PrinterInfo2
*pinfo2
,
2795 TALLOC_CTX
*mem_ctx
)
2797 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->portname
);
2800 /*******************************************************************
2801 * fill a notify_info_data with the printername
2802 * but it doesn't exist, have to see what to do
2803 ********************************************************************/
2805 static void spoolss_notify_driver_name(struct messaging_context
*msg_ctx
,
2807 struct spoolss_Notify
*data
,
2808 print_queue_struct
*queue
,
2809 struct spoolss_PrinterInfo2
*pinfo2
,
2810 TALLOC_CTX
*mem_ctx
)
2812 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->drivername
);
2815 /*******************************************************************
2816 * fill a notify_info_data with the comment
2817 ********************************************************************/
2819 static void spoolss_notify_comment(struct messaging_context
*msg_ctx
,
2821 struct spoolss_Notify
*data
,
2822 print_queue_struct
*queue
,
2823 struct spoolss_PrinterInfo2
*pinfo2
,
2824 TALLOC_CTX
*mem_ctx
)
2828 if (*pinfo2
->comment
== '\0') {
2829 p
= lp_comment(snum
);
2831 p
= pinfo2
->comment
;
2834 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, p
);
2837 /*******************************************************************
2838 * fill a notify_info_data with the comment
2839 * location = "Room 1, floor 2, building 3"
2840 ********************************************************************/
2842 static void spoolss_notify_location(struct messaging_context
*msg_ctx
,
2844 struct spoolss_Notify
*data
,
2845 print_queue_struct
*queue
,
2846 struct spoolss_PrinterInfo2
*pinfo2
,
2847 TALLOC_CTX
*mem_ctx
)
2849 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->location
);
2852 /*******************************************************************
2853 * fill a notify_info_data with the device mode
2854 * jfm:xxxx don't to it for know but that's a real problem !!!
2855 ********************************************************************/
2857 static void spoolss_notify_devmode(struct messaging_context
*msg_ctx
,
2859 struct spoolss_Notify
*data
,
2860 print_queue_struct
*queue
,
2861 struct spoolss_PrinterInfo2
*pinfo2
,
2862 TALLOC_CTX
*mem_ctx
)
2864 /* for a dummy implementation we have to zero the fields */
2865 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data
, NULL
);
2868 /*******************************************************************
2869 * fill a notify_info_data with the separator file name
2870 ********************************************************************/
2872 static void spoolss_notify_sepfile(struct messaging_context
*msg_ctx
,
2874 struct spoolss_Notify
*data
,
2875 print_queue_struct
*queue
,
2876 struct spoolss_PrinterInfo2
*pinfo2
,
2877 TALLOC_CTX
*mem_ctx
)
2879 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->sepfile
);
2882 /*******************************************************************
2883 * fill a notify_info_data with the print processor
2884 * jfm:xxxx return always winprint to indicate we don't do anything to it
2885 ********************************************************************/
2887 static void spoolss_notify_print_processor(struct messaging_context
*msg_ctx
,
2889 struct spoolss_Notify
*data
,
2890 print_queue_struct
*queue
,
2891 struct spoolss_PrinterInfo2
*pinfo2
,
2892 TALLOC_CTX
*mem_ctx
)
2894 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->printprocessor
);
2897 /*******************************************************************
2898 * fill a notify_info_data with the print processor options
2899 * jfm:xxxx send an empty string
2900 ********************************************************************/
2902 static void spoolss_notify_parameters(struct messaging_context
*msg_ctx
,
2904 struct spoolss_Notify
*data
,
2905 print_queue_struct
*queue
,
2906 struct spoolss_PrinterInfo2
*pinfo2
,
2907 TALLOC_CTX
*mem_ctx
)
2909 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->parameters
);
2912 /*******************************************************************
2913 * fill a notify_info_data with the data type
2914 * jfm:xxxx always send RAW as data type
2915 ********************************************************************/
2917 static void spoolss_notify_datatype(struct messaging_context
*msg_ctx
,
2919 struct spoolss_Notify
*data
,
2920 print_queue_struct
*queue
,
2921 struct spoolss_PrinterInfo2
*pinfo2
,
2922 TALLOC_CTX
*mem_ctx
)
2924 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, pinfo2
->datatype
);
2927 /*******************************************************************
2928 * fill a notify_info_data with the security descriptor
2929 * jfm:xxxx send an null pointer to say no security desc
2930 * have to implement security before !
2931 ********************************************************************/
2933 static void spoolss_notify_security_desc(struct messaging_context
*msg_ctx
,
2935 struct spoolss_Notify
*data
,
2936 print_queue_struct
*queue
,
2937 struct spoolss_PrinterInfo2
*pinfo2
,
2938 TALLOC_CTX
*mem_ctx
)
2940 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data
, pinfo2
->secdesc
);
2943 /*******************************************************************
2944 * fill a notify_info_data with the attributes
2945 * jfm:xxxx a samba printer is always shared
2946 ********************************************************************/
2948 static void spoolss_notify_attributes(struct messaging_context
*msg_ctx
,
2950 struct spoolss_Notify
*data
,
2951 print_queue_struct
*queue
,
2952 struct spoolss_PrinterInfo2
*pinfo2
,
2953 TALLOC_CTX
*mem_ctx
)
2955 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->attributes
);
2958 /*******************************************************************
2959 * fill a notify_info_data with the priority
2960 ********************************************************************/
2962 static void spoolss_notify_priority(struct messaging_context
*msg_ctx
,
2964 struct spoolss_Notify
*data
,
2965 print_queue_struct
*queue
,
2966 struct spoolss_PrinterInfo2
*pinfo2
,
2967 TALLOC_CTX
*mem_ctx
)
2969 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->priority
);
2972 /*******************************************************************
2973 * fill a notify_info_data with the default priority
2974 ********************************************************************/
2976 static void spoolss_notify_default_priority(struct messaging_context
*msg_ctx
,
2978 struct spoolss_Notify
*data
,
2979 print_queue_struct
*queue
,
2980 struct spoolss_PrinterInfo2
*pinfo2
,
2981 TALLOC_CTX
*mem_ctx
)
2983 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->defaultpriority
);
2986 /*******************************************************************
2987 * fill a notify_info_data with the start time
2988 ********************************************************************/
2990 static void spoolss_notify_start_time(struct messaging_context
*msg_ctx
,
2992 struct spoolss_Notify
*data
,
2993 print_queue_struct
*queue
,
2994 struct spoolss_PrinterInfo2
*pinfo2
,
2995 TALLOC_CTX
*mem_ctx
)
2997 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->starttime
);
3000 /*******************************************************************
3001 * fill a notify_info_data with the until time
3002 ********************************************************************/
3004 static void spoolss_notify_until_time(struct messaging_context
*msg_ctx
,
3006 struct spoolss_Notify
*data
,
3007 print_queue_struct
*queue
,
3008 struct spoolss_PrinterInfo2
*pinfo2
,
3009 TALLOC_CTX
*mem_ctx
)
3011 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->untiltime
);
3014 /*******************************************************************
3015 * fill a notify_info_data with the status
3016 ********************************************************************/
3018 static void spoolss_notify_status(struct messaging_context
*msg_ctx
,
3020 struct spoolss_Notify
*data
,
3021 print_queue_struct
*queue
,
3022 struct spoolss_PrinterInfo2
*pinfo2
,
3023 TALLOC_CTX
*mem_ctx
)
3025 print_status_struct status
;
3027 print_queue_length(msg_ctx
, snum
, &status
);
3028 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, status
.status
);
3031 /*******************************************************************
3032 * fill a notify_info_data with the number of jobs queued
3033 ********************************************************************/
3035 static void spoolss_notify_cjobs(struct messaging_context
*msg_ctx
,
3037 struct spoolss_Notify
*data
,
3038 print_queue_struct
*queue
,
3039 struct spoolss_PrinterInfo2
*pinfo2
,
3040 TALLOC_CTX
*mem_ctx
)
3042 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(
3043 data
, print_queue_length(msg_ctx
, snum
, NULL
));
3046 /*******************************************************************
3047 * fill a notify_info_data with the average ppm
3048 ********************************************************************/
3050 static void spoolss_notify_average_ppm(struct messaging_context
*msg_ctx
,
3052 struct spoolss_Notify
*data
,
3053 print_queue_struct
*queue
,
3054 struct spoolss_PrinterInfo2
*pinfo2
,
3055 TALLOC_CTX
*mem_ctx
)
3057 /* always respond 8 pages per minutes */
3058 /* a little hard ! */
3059 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, pinfo2
->averageppm
);
3062 /*******************************************************************
3063 * fill a notify_info_data with username
3064 ********************************************************************/
3066 static void spoolss_notify_username(struct messaging_context
*msg_ctx
,
3068 struct spoolss_Notify
*data
,
3069 print_queue_struct
*queue
,
3070 struct spoolss_PrinterInfo2
*pinfo2
,
3071 TALLOC_CTX
*mem_ctx
)
3073 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, queue
->fs_user
);
3076 /*******************************************************************
3077 * fill a notify_info_data with job status
3078 ********************************************************************/
3080 static void spoolss_notify_job_status(struct messaging_context
*msg_ctx
,
3082 struct spoolss_Notify
*data
,
3083 print_queue_struct
*queue
,
3084 struct spoolss_PrinterInfo2
*pinfo2
,
3085 TALLOC_CTX
*mem_ctx
)
3087 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, nt_printj_status(queue
->status
));
3090 /*******************************************************************
3091 * fill a notify_info_data with job name
3092 ********************************************************************/
3094 static void spoolss_notify_job_name(struct messaging_context
*msg_ctx
,
3096 struct spoolss_Notify
*data
,
3097 print_queue_struct
*queue
,
3098 struct spoolss_PrinterInfo2
*pinfo2
,
3099 TALLOC_CTX
*mem_ctx
)
3101 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, queue
->fs_file
);
3104 /*******************************************************************
3105 * fill a notify_info_data with job status
3106 ********************************************************************/
3108 static void spoolss_notify_job_status_string(struct messaging_context
*msg_ctx
,
3110 struct spoolss_Notify
*data
,
3111 print_queue_struct
*queue
,
3112 struct spoolss_PrinterInfo2
*pinfo2
,
3113 TALLOC_CTX
*mem_ctx
)
3116 * Now we're returning job status codes we just return a "" here. JRA.
3121 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
3124 switch (queue
->status
) {
3129 p
= ""; /* NT provides the paused string */
3138 #endif /* NO LONGER NEEDED. */
3140 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data
, p
);
3143 /*******************************************************************
3144 * fill a notify_info_data with job time
3145 ********************************************************************/
3147 static void spoolss_notify_job_time(struct messaging_context
*msg_ctx
,
3149 struct spoolss_Notify
*data
,
3150 print_queue_struct
*queue
,
3151 struct spoolss_PrinterInfo2
*pinfo2
,
3152 TALLOC_CTX
*mem_ctx
)
3154 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, 0);
3157 /*******************************************************************
3158 * fill a notify_info_data with job size
3159 ********************************************************************/
3161 static void spoolss_notify_job_size(struct messaging_context
*msg_ctx
,
3163 struct spoolss_Notify
*data
,
3164 print_queue_struct
*queue
,
3165 struct spoolss_PrinterInfo2
*pinfo2
,
3166 TALLOC_CTX
*mem_ctx
)
3168 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, queue
->size
);
3171 /*******************************************************************
3172 * fill a notify_info_data with page info
3173 ********************************************************************/
3174 static void spoolss_notify_total_pages(struct messaging_context
*msg_ctx
,
3176 struct spoolss_Notify
*data
,
3177 print_queue_struct
*queue
,
3178 struct spoolss_PrinterInfo2
*pinfo2
,
3179 TALLOC_CTX
*mem_ctx
)
3181 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, queue
->page_count
);
3184 /*******************************************************************
3185 * fill a notify_info_data with pages printed info.
3186 ********************************************************************/
3187 static void spoolss_notify_pages_printed(struct messaging_context
*msg_ctx
,
3189 struct spoolss_Notify
*data
,
3190 print_queue_struct
*queue
,
3191 struct spoolss_PrinterInfo2
*pinfo2
,
3192 TALLOC_CTX
*mem_ctx
)
3194 /* Add code when back-end tracks this */
3195 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, 0);
3198 /*******************************************************************
3199 Fill a notify_info_data with job position.
3200 ********************************************************************/
3202 static void spoolss_notify_job_position(struct messaging_context
*msg_ctx
,
3204 struct spoolss_Notify
*data
,
3205 print_queue_struct
*queue
,
3206 struct spoolss_PrinterInfo2
*pinfo2
,
3207 TALLOC_CTX
*mem_ctx
)
3209 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data
, queue
->job
);
3212 /*******************************************************************
3213 Fill a notify_info_data with submitted time.
3214 ********************************************************************/
3216 static void spoolss_notify_submitted_time(struct messaging_context
*msg_ctx
,
3218 struct spoolss_Notify
*data
,
3219 print_queue_struct
*queue
,
3220 struct spoolss_PrinterInfo2
*pinfo2
,
3221 TALLOC_CTX
*mem_ctx
)
3223 data
->data
.string
.string
= NULL
;
3224 data
->data
.string
.size
= 0;
3226 init_systemtime_buffer(mem_ctx
, gmtime(&queue
->time
),
3227 &data
->data
.string
.string
,
3228 &data
->data
.string
.size
);
3232 struct s_notify_info_data_table
3234 enum spoolss_NotifyType type
;
3237 enum spoolss_NotifyTable variable_type
;
3238 void (*fn
) (struct messaging_context
*msg_ctx
,
3239 int snum
, struct spoolss_Notify
*data
,
3240 print_queue_struct
*queue
,
3241 struct spoolss_PrinterInfo2
*pinfo2
,
3242 TALLOC_CTX
*mem_ctx
);
3245 /* A table describing the various print notification constants and
3246 whether the notification data is a pointer to a variable sized
3247 buffer, a one value uint32_t or a two value uint32_t. */
3249 static const struct s_notify_info_data_table notify_info_data_table
[] =
3251 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_SERVER_NAME
, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_server_name
},
3252 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PRINTER_NAME
, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_printer_name
},
3253 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_SHARE_NAME
, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_share_name
},
3254 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PORT_NAME
, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_port_name
},
3255 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_DRIVER_NAME
, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_driver_name
},
3256 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_COMMENT
, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING
, spoolss_notify_comment
},
3257 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_LOCATION
, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING
, spoolss_notify_location
},
3258 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_DEVMODE
, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE
, spoolss_notify_devmode
},
3259 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_SEPFILE
, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING
, spoolss_notify_sepfile
},
3260 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR
, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING
, spoolss_notify_print_processor
},
3261 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PARAMETERS
, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING
, spoolss_notify_parameters
},
3262 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_DATATYPE
, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING
, spoolss_notify_datatype
},
3263 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR
, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR
, spoolss_notify_security_desc
},
3264 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_ATTRIBUTES
, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD
, spoolss_notify_attributes
},
3265 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PRIORITY
, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD
, spoolss_notify_priority
},
3266 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY
, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD
, spoolss_notify_default_priority
},
3267 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_START_TIME
, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_start_time
},
3268 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_UNTIL_TIME
, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_until_time
},
3269 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_STATUS
, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD
, spoolss_notify_status
},
3270 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_STATUS_STRING
, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING
, NULL
},
3271 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_CJOBS
, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD
, spoolss_notify_cjobs
},
3272 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_AVERAGE_PPM
, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD
, spoolss_notify_average_ppm
},
3273 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_TOTAL_PAGES
, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD
, NULL
},
3274 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_PAGES_PRINTED
, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD
, NULL
},
3275 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_TOTAL_BYTES
, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD
, NULL
},
3276 { PRINTER_NOTIFY_TYPE
, PRINTER_NOTIFY_FIELD_BYTES_PRINTED
, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD
, NULL
},
3277 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PRINTER_NAME
, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_printer_name
},
3278 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_MACHINE_NAME
, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_server_name
},
3279 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PORT_NAME
, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_port_name
},
3280 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_USER_NAME
, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_username
},
3281 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_NOTIFY_NAME
, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_username
},
3282 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_DATATYPE
, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING
, spoolss_notify_datatype
},
3283 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PRINT_PROCESSOR
, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING
, spoolss_notify_print_processor
},
3284 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PARAMETERS
, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING
, spoolss_notify_parameters
},
3285 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_DRIVER_NAME
, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING
, spoolss_notify_driver_name
},
3286 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_DEVMODE
, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE
, spoolss_notify_devmode
},
3287 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_STATUS
, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD
, spoolss_notify_job_status
},
3288 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_STATUS_STRING
, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING
, spoolss_notify_job_status_string
},
3289 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR
, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR
, NULL
},
3290 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_DOCUMENT
, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING
, spoolss_notify_job_name
},
3291 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PRIORITY
, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD
, spoolss_notify_priority
},
3292 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_POSITION
, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD
, spoolss_notify_job_position
},
3293 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_SUBMITTED
, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME
, spoolss_notify_submitted_time
},
3294 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_START_TIME
, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_start_time
},
3295 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_UNTIL_TIME
, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_until_time
},
3296 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_TIME
, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD
, spoolss_notify_job_time
},
3297 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_TOTAL_PAGES
, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD
, spoolss_notify_total_pages
},
3298 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_PAGES_PRINTED
, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD
, spoolss_notify_pages_printed
},
3299 { JOB_NOTIFY_TYPE
, JOB_NOTIFY_FIELD_TOTAL_BYTES
, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD
, spoolss_notify_job_size
},
3302 /*******************************************************************
3303 Return the variable_type of info_data structure.
3304 ********************************************************************/
3306 static enum spoolss_NotifyTable
variable_type_of_notify_info_data(enum spoolss_NotifyType type
,
3311 for (i
= 0; i
< ARRAY_SIZE(notify_info_data_table
); i
++) {
3312 if ( (notify_info_data_table
[i
].type
== type
) &&
3313 (notify_info_data_table
[i
].field
== field
) ) {
3314 return notify_info_data_table
[i
].variable_type
;
3318 DEBUG(5, ("invalid notify data type %d/%d\n", type
, field
));
3320 return (enum spoolss_NotifyTable
) 0;
3323 /****************************************************************************
3324 ****************************************************************************/
3326 static bool search_notify(enum spoolss_NotifyType type
,
3332 for (i
= 0; i
< ARRAY_SIZE(notify_info_data_table
); i
++) {
3333 if (notify_info_data_table
[i
].type
== type
&&
3334 notify_info_data_table
[i
].field
== field
&&
3335 notify_info_data_table
[i
].fn
!= NULL
) {
3344 /****************************************************************************
3345 ****************************************************************************/
3347 static void construct_info_data(struct spoolss_Notify
*info_data
,
3348 enum spoolss_NotifyType type
,
3349 uint16_t field
, int id
)
3351 info_data
->type
= type
;
3352 info_data
->field
.field
= field
;
3353 info_data
->variable_type
= variable_type_of_notify_info_data(type
, field
);
3354 info_data
->job_id
= id
;
3357 /*******************************************************************
3359 * fill a notify_info struct with info asked
3361 ********************************************************************/
3363 static bool construct_notify_printer_info(struct messaging_context
*msg_ctx
,
3364 struct printer_handle
*print_hnd
,
3365 struct spoolss_NotifyInfo
*info
,
3366 struct spoolss_PrinterInfo2
*pinfo2
,
3368 const struct spoolss_NotifyOptionType
*option_type
,
3370 TALLOC_CTX
*mem_ctx
)
3373 enum spoolss_NotifyType type
;
3376 struct spoolss_Notify
*current_data
;
3377 print_queue_struct
*queue
=NULL
;
3379 type
= option_type
->type
;
3381 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3382 (type
== PRINTER_NOTIFY_TYPE
? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3383 option_type
->count
, lp_servicename(snum
)));
3385 for(field_num
=0; field_num
< option_type
->count
; field_num
++) {
3386 field
= option_type
->fields
[field_num
].field
;
3388 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num
, type
, field
));
3390 if (!search_notify(type
, field
, &j
) )
3393 info
->notifies
= TALLOC_REALLOC_ARRAY(info
, info
->notifies
,
3394 struct spoolss_Notify
,
3396 if (info
->notifies
== NULL
) {
3397 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3401 current_data
= &info
->notifies
[info
->count
];
3403 construct_info_data(current_data
, type
, field
, id
);
3405 DEBUG(10, ("construct_notify_printer_info: "
3406 "calling [%s] snum=%d printername=[%s])\n",
3407 notify_info_data_table
[j
].name
, snum
,
3408 pinfo2
->printername
));
3410 notify_info_data_table
[j
].fn(msg_ctx
, snum
, current_data
,
3411 queue
, pinfo2
, mem_ctx
);
3419 /*******************************************************************
3421 * fill a notify_info struct with info asked
3423 ********************************************************************/
3425 static bool construct_notify_jobs_info(struct messaging_context
*msg_ctx
,
3426 print_queue_struct
*queue
,
3427 struct spoolss_NotifyInfo
*info
,
3428 struct spoolss_PrinterInfo2
*pinfo2
,
3430 const struct spoolss_NotifyOptionType
*option_type
,
3432 TALLOC_CTX
*mem_ctx
)
3435 enum spoolss_NotifyType type
;
3437 struct spoolss_Notify
*current_data
;
3439 DEBUG(4,("construct_notify_jobs_info\n"));
3441 type
= option_type
->type
;
3443 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3444 (type
== PRINTER_NOTIFY_TYPE
? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3445 option_type
->count
));
3447 for(field_num
=0; field_num
<option_type
->count
; field_num
++) {
3448 field
= option_type
->fields
[field_num
].field
;
3450 if (!search_notify(type
, field
, &j
) )
3453 info
->notifies
= TALLOC_REALLOC_ARRAY(info
, info
->notifies
,
3454 struct spoolss_Notify
,
3456 if (info
->notifies
== NULL
) {
3457 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3461 current_data
=&(info
->notifies
[info
->count
]);
3463 construct_info_data(current_data
, type
, field
, id
);
3464 notify_info_data_table
[j
].fn(msg_ctx
, snum
, current_data
,
3465 queue
, pinfo2
, mem_ctx
);
3473 * JFM: The enumeration is not that simple, it's even non obvious.
3475 * let's take an example: I want to monitor the PRINTER SERVER for
3476 * the printer's name and the number of jobs currently queued.
3477 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3478 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3480 * I have 3 printers on the back of my server.
3482 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3485 * 1 printer 1 name 1
3486 * 2 printer 1 cjob 1
3487 * 3 printer 2 name 2
3488 * 4 printer 2 cjob 2
3489 * 5 printer 3 name 3
3490 * 6 printer 3 name 3
3492 * that's the print server case, the printer case is even worse.
3495 /*******************************************************************
3497 * enumerate all printers on the printserver
3498 * fill a notify_info struct with info asked
3500 ********************************************************************/
3502 static WERROR
printserver_notify_info(struct pipes_struct
*p
,
3503 struct policy_handle
*hnd
,
3504 struct spoolss_NotifyInfo
*info
,
3505 TALLOC_CTX
*mem_ctx
)
3508 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, hnd
);
3509 int n_services
=lp_numservices();
3511 struct spoolss_NotifyOption
*option
;
3512 struct spoolss_NotifyOptionType option_type
;
3513 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
3516 DEBUG(4,("printserver_notify_info\n"));
3521 option
= Printer
->notify
.option
;
3524 info
->notifies
= NULL
;
3527 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3528 sending a ffpcn() request first */
3533 for (i
=0; i
<option
->count
; i
++) {
3534 option_type
= option
->types
[i
];
3536 if (option_type
.type
!= PRINTER_NOTIFY_TYPE
)
3539 for (snum
= 0; snum
< n_services
; snum
++) {
3540 if (!lp_browseable(snum
) ||
3541 !lp_snum_ok(snum
) ||
3542 !lp_print_ok(snum
)) {
3543 continue; /* skip */
3546 /* Maybe we should use the SYSTEM server_info here... */
3547 result
= winreg_get_printer(mem_ctx
,
3548 get_server_info_system(),
3550 lp_servicename(snum
),
3552 if (!W_ERROR_IS_OK(result
)) {
3553 DEBUG(4, ("printserver_notify_info: "
3554 "Failed to get printer [%s]\n",
3555 lp_servicename(snum
)));
3560 construct_notify_printer_info(p
->msg_ctx
,
3566 TALLOC_FREE(pinfo2
);
3572 * Debugging information, don't delete.
3575 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3576 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info
->version
, info
->flags
, info
->count
));
3577 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3579 for (i
=0; i
<info
->count
; i
++) {
3580 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3581 i
, info
->data
[i
].type
, info
->data
[i
].field
, info
->data
[i
].reserved
,
3582 info
->data
[i
].id
, info
->data
[i
].size
, info
->data
[i
].enc_type
));
3589 /*******************************************************************
3591 * fill a notify_info struct with info asked
3593 ********************************************************************/
3595 static WERROR
printer_notify_info(struct pipes_struct
*p
,
3596 struct policy_handle
*hnd
,
3597 struct spoolss_NotifyInfo
*info
,
3598 TALLOC_CTX
*mem_ctx
)
3601 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, hnd
);
3604 struct spoolss_NotifyOption
*option
;
3605 struct spoolss_NotifyOptionType option_type
;
3607 print_queue_struct
*queue
=NULL
;
3608 print_status_struct status
;
3609 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
3612 DEBUG(4,("printer_notify_info\n"));
3617 option
= Printer
->notify
.option
;
3621 info
->notifies
= NULL
;
3624 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3625 sending a ffpcn() request first */
3630 get_printer_snum(p
, hnd
, &snum
, NULL
);
3632 /* Maybe we should use the SYSTEM server_info here... */
3633 result
= winreg_get_printer(mem_ctx
,
3634 get_server_info_system(),
3636 lp_servicename(snum
), &pinfo2
);
3637 if (!W_ERROR_IS_OK(result
)) {
3641 for (i
=0; i
<option
->count
; i
++) {
3642 option_type
= option
->types
[i
];
3644 switch (option_type
.type
) {
3645 case PRINTER_NOTIFY_TYPE
:
3646 if (construct_notify_printer_info(p
->msg_ctx
,
3655 case JOB_NOTIFY_TYPE
:
3657 count
= print_queue_status(p
->msg_ctx
, snum
, &queue
,
3660 for (j
=0; j
<count
; j
++) {
3661 construct_notify_jobs_info(p
->msg_ctx
,
3675 * Debugging information, don't delete.
3678 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3679 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3680 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3682 for (i=0; i<info->count; i++) {
3683 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3684 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3685 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3689 talloc_free(pinfo2
);
3693 /****************************************************************
3694 _spoolss_RouterRefreshPrinterChangeNotify
3695 ****************************************************************/
3697 WERROR
_spoolss_RouterRefreshPrinterChangeNotify(struct pipes_struct
*p
,
3698 struct spoolss_RouterRefreshPrinterChangeNotify
*r
)
3700 struct spoolss_NotifyInfo
*info
;
3702 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
3703 WERROR result
= WERR_BADFID
;
3705 /* we always have a spoolss_NotifyInfo struct */
3706 info
= talloc_zero(p
->mem_ctx
, struct spoolss_NotifyInfo
);
3708 result
= WERR_NOMEM
;
3712 *r
->out
.info
= info
;
3715 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3716 "Invalid handle (%s:%u:%u).\n",
3717 OUR_HANDLE(r
->in
.handle
)));
3721 DEBUG(4,("Printer type %x\n",Printer
->printer_type
));
3724 * We are now using the change value, and
3725 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3726 * I don't have a global notification system, I'm sending back all the
3727 * informations even when _NOTHING_ has changed.
3730 /* We need to keep track of the change value to send back in
3731 RRPCN replies otherwise our updates are ignored. */
3733 Printer
->notify
.fnpcn
= true;
3735 if (Printer
->notify
.cli_chan
!= NULL
&&
3736 Printer
->notify
.cli_chan
->active_connections
> 0) {
3737 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3738 "Saving change value in request [%x]\n",
3740 Printer
->notify
.change
= r
->in
.change_low
;
3743 /* just ignore the spoolss_NotifyOption */
3745 switch (Printer
->printer_type
) {
3747 result
= printserver_notify_info(p
, r
->in
.handle
,
3751 case SPLHND_PRINTER
:
3752 result
= printer_notify_info(p
, r
->in
.handle
,
3757 Printer
->notify
.fnpcn
= false;
3763 /********************************************************************
3764 ********************************************************************/
3766 static WERROR
create_printername(TALLOC_CTX
*mem_ctx
,
3767 const char *servername
,
3768 const char *printername
,
3769 const char **printername_p
)
3771 /* FIXME: add lp_force_printername() */
3773 if (servername
== NULL
) {
3774 *printername_p
= talloc_strdup(mem_ctx
, printername
);
3775 W_ERROR_HAVE_NO_MEMORY(*printername_p
);
3779 if (servername
[0] == '\\' && servername
[1] == '\\') {
3783 *printername_p
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s", servername
, printername
);
3784 W_ERROR_HAVE_NO_MEMORY(*printername_p
);
3789 /********************************************************************
3790 ********************************************************************/
3792 static void compose_devicemode_devicename(struct spoolss_DeviceMode
*dm
,
3793 const char *printername
)
3799 dm
->devicename
= talloc_strndup(dm
, printername
,
3800 MIN(strlen(printername
), 31));
3803 /********************************************************************
3804 * construct_printer_info_0
3805 * fill a printer_info_0 struct
3806 ********************************************************************/
3808 static WERROR
construct_printer_info0(TALLOC_CTX
*mem_ctx
,
3809 const struct auth_serversupplied_info
*server_info
,
3810 struct messaging_context
*msg_ctx
,
3811 struct spoolss_PrinterInfo2
*info2
,
3812 const char *servername
,
3813 struct spoolss_PrinterInfo0
*r
,
3817 struct printer_session_counter
*session_counter
;
3818 struct timeval setuptime
;
3819 print_status_struct status
;
3822 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->printername
);
3823 if (!W_ERROR_IS_OK(result
)) {
3828 r
->servername
= talloc_strdup(mem_ctx
, servername
);
3829 W_ERROR_HAVE_NO_MEMORY(r
->servername
);
3831 r
->servername
= NULL
;
3834 count
= print_queue_length(msg_ctx
, snum
, &status
);
3836 /* check if we already have a counter for this printer */
3837 for (session_counter
= counter_list
; session_counter
; session_counter
= session_counter
->next
) {
3838 if (session_counter
->snum
== snum
)
3842 /* it's the first time, add it to the list */
3843 if (session_counter
== NULL
) {
3844 session_counter
= talloc_zero(counter_list
, struct printer_session_counter
);
3845 W_ERROR_HAVE_NO_MEMORY(session_counter
);
3846 session_counter
->snum
= snum
;
3847 session_counter
->counter
= 0;
3848 DLIST_ADD(counter_list
, session_counter
);
3852 session_counter
->counter
++;
3858 get_startup_time(&setuptime
);
3859 init_systemtime(&r
->time
, gmtime(&setuptime
.tv_sec
));
3862 * the global_counter should be stored in a TDB as it's common to all the clients
3863 * and should be zeroed on samba startup
3865 r
->global_counter
= session_counter
->counter
;
3867 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3868 SSVAL(&r
->version
, 0, 0x0005); /* NT 5 */
3869 SSVAL(&r
->version
, 2, 0x0893); /* build 2195 */
3870 r
->free_build
= SPOOLSS_RELEASE_BUILD
;
3872 r
->max_spooling
= 0;
3873 r
->session_counter
= session_counter
->counter
;
3874 r
->num_error_out_of_paper
= 0x0;
3875 r
->num_error_not_ready
= 0x0; /* number of print failure */
3877 r
->number_of_processors
= 0x1;
3878 r
->processor_type
= PROCESSOR_INTEL_PENTIUM
; /* 586 Pentium ? */
3879 r
->high_part_total_bytes
= 0x0;
3881 /* ChangeID in milliseconds*/
3882 winreg_printer_get_changeid(mem_ctx
, server_info
, msg_ctx
,
3883 info2
->sharename
, &r
->change_id
);
3885 r
->last_error
= WERR_OK
;
3886 r
->status
= nt_printq_status(status
.status
);
3887 r
->enumerate_network_printers
= 0x0;
3888 r
->c_setprinter
= 0x0;
3889 r
->processor_architecture
= PROCESSOR_ARCHITECTURE_INTEL
;
3890 r
->processor_level
= 0x6; /* 6 ???*/
3899 /********************************************************************
3900 * construct_printer_info1
3901 * fill a spoolss_PrinterInfo1 struct
3902 ********************************************************************/
3904 static WERROR
construct_printer_info1(TALLOC_CTX
*mem_ctx
,
3905 const struct spoolss_PrinterInfo2
*info2
,
3907 const char *servername
,
3908 struct spoolss_PrinterInfo1
*r
,
3915 if (info2
->comment
== NULL
|| info2
->comment
[0] == '\0') {
3916 r
->comment
= talloc_strdup(mem_ctx
, lp_comment(snum
));
3918 r
->comment
= talloc_strdup(mem_ctx
, info2
->comment
); /* saved comment */
3920 W_ERROR_HAVE_NO_MEMORY(r
->comment
);
3922 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->name
);
3923 if (!W_ERROR_IS_OK(result
)) {
3927 r
->description
= talloc_asprintf(mem_ctx
, "%s,%s,%s",
3931 W_ERROR_HAVE_NO_MEMORY(r
->description
);
3936 /********************************************************************
3937 * construct_printer_info2
3938 * fill a spoolss_PrinterInfo2 struct
3939 ********************************************************************/
3941 static WERROR
construct_printer_info2(TALLOC_CTX
*mem_ctx
,
3942 struct messaging_context
*msg_ctx
,
3943 const struct spoolss_PrinterInfo2
*info2
,
3944 const char *servername
,
3945 struct spoolss_PrinterInfo2
*r
,
3949 print_status_struct status
;
3952 count
= print_queue_length(msg_ctx
, snum
, &status
);
3955 r
->servername
= talloc_strdup(mem_ctx
, servername
);
3956 W_ERROR_HAVE_NO_MEMORY(r
->servername
);
3958 r
->servername
= NULL
;
3961 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->printername
);
3962 if (!W_ERROR_IS_OK(result
)) {
3966 r
->sharename
= talloc_strdup(mem_ctx
, lp_servicename(snum
));
3967 W_ERROR_HAVE_NO_MEMORY(r
->sharename
);
3968 r
->portname
= talloc_strdup(mem_ctx
, info2
->portname
);
3969 W_ERROR_HAVE_NO_MEMORY(r
->portname
);
3970 r
->drivername
= talloc_strdup(mem_ctx
, info2
->drivername
);
3971 W_ERROR_HAVE_NO_MEMORY(r
->drivername
);
3973 if (info2
->comment
[0] == '\0') {
3974 r
->comment
= talloc_strdup(mem_ctx
, lp_comment(snum
));
3976 r
->comment
= talloc_strdup(mem_ctx
, info2
->comment
);
3978 W_ERROR_HAVE_NO_MEMORY(r
->comment
);
3980 r
->location
= talloc_strdup(mem_ctx
, info2
->location
);
3981 W_ERROR_HAVE_NO_MEMORY(r
->location
);
3982 r
->sepfile
= talloc_strdup(mem_ctx
, info2
->sepfile
);
3983 W_ERROR_HAVE_NO_MEMORY(r
->sepfile
);
3984 r
->printprocessor
= talloc_strdup(mem_ctx
, info2
->printprocessor
);
3985 W_ERROR_HAVE_NO_MEMORY(r
->printprocessor
);
3986 r
->datatype
= talloc_strdup(mem_ctx
, info2
->datatype
);
3987 W_ERROR_HAVE_NO_MEMORY(r
->datatype
);
3988 r
->parameters
= talloc_strdup(mem_ctx
, info2
->parameters
);
3989 W_ERROR_HAVE_NO_MEMORY(r
->parameters
);
3991 r
->attributes
= info2
->attributes
;
3993 r
->priority
= info2
->priority
;
3994 r
->defaultpriority
= info2
->defaultpriority
;
3995 r
->starttime
= info2
->starttime
;
3996 r
->untiltime
= info2
->untiltime
;
3997 r
->status
= nt_printq_status(status
.status
);
3999 r
->averageppm
= info2
->averageppm
;
4001 copy_devicemode(mem_ctx
, info2
->devmode
, &r
->devmode
);
4003 DEBUG(8,("Returning NULL Devicemode!\n"));
4006 compose_devicemode_devicename(r
->devmode
, r
->printername
);
4010 if (info2
->secdesc
!= NULL
) {
4011 /* don't use talloc_steal() here unless you do a deep steal of all
4012 the SEC_DESC members */
4014 r
->secdesc
= dup_sec_desc(mem_ctx
, info2
->secdesc
);
4020 /********************************************************************
4021 * construct_printer_info3
4022 * fill a spoolss_PrinterInfo3 struct
4023 ********************************************************************/
4025 static WERROR
construct_printer_info3(TALLOC_CTX
*mem_ctx
,
4026 const struct spoolss_PrinterInfo2
*info2
,
4027 const char *servername
,
4028 struct spoolss_PrinterInfo3
*r
,
4031 /* These are the components of the SD we are returning. */
4033 if (info2
->secdesc
!= NULL
) {
4034 /* don't use talloc_steal() here unless you do a deep steal of all
4035 the SEC_DESC members */
4037 r
->secdesc
= dup_sec_desc(mem_ctx
, info2
->secdesc
);
4038 W_ERROR_HAVE_NO_MEMORY(r
->secdesc
);
4044 /********************************************************************
4045 * construct_printer_info4
4046 * fill a spoolss_PrinterInfo4 struct
4047 ********************************************************************/
4049 static WERROR
construct_printer_info4(TALLOC_CTX
*mem_ctx
,
4050 const struct spoolss_PrinterInfo2
*info2
,
4051 const char *servername
,
4052 struct spoolss_PrinterInfo4
*r
,
4057 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->printername
);
4058 if (!W_ERROR_IS_OK(result
)) {
4063 r
->servername
= talloc_strdup(mem_ctx
, servername
);
4064 W_ERROR_HAVE_NO_MEMORY(r
->servername
);
4066 r
->servername
= NULL
;
4069 r
->attributes
= info2
->attributes
;
4074 /********************************************************************
4075 * construct_printer_info5
4076 * fill a spoolss_PrinterInfo5 struct
4077 ********************************************************************/
4079 static WERROR
construct_printer_info5(TALLOC_CTX
*mem_ctx
,
4080 const struct spoolss_PrinterInfo2
*info2
,
4081 const char *servername
,
4082 struct spoolss_PrinterInfo5
*r
,
4087 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &r
->printername
);
4088 if (!W_ERROR_IS_OK(result
)) {
4092 r
->portname
= talloc_strdup(mem_ctx
, info2
->portname
);
4093 W_ERROR_HAVE_NO_MEMORY(r
->portname
);
4095 r
->attributes
= info2
->attributes
;
4097 /* these two are not used by NT+ according to MSDN */
4098 r
->device_not_selected_timeout
= 0x0; /* have seen 0x3a98 */
4099 r
->transmission_retry_timeout
= 0x0; /* have seen 0xafc8 */
4104 /********************************************************************
4105 * construct_printer_info_6
4106 * fill a spoolss_PrinterInfo6 struct
4107 ********************************************************************/
4109 static WERROR
construct_printer_info6(TALLOC_CTX
*mem_ctx
,
4110 struct messaging_context
*msg_ctx
,
4111 const struct spoolss_PrinterInfo2
*info2
,
4112 const char *servername
,
4113 struct spoolss_PrinterInfo6
*r
,
4117 print_status_struct status
;
4119 count
= print_queue_length(msg_ctx
, snum
, &status
);
4121 r
->status
= nt_printq_status(status
.status
);
4126 /********************************************************************
4127 * construct_printer_info7
4128 * fill a spoolss_PrinterInfo7 struct
4129 ********************************************************************/
4131 static WERROR
construct_printer_info7(TALLOC_CTX
*mem_ctx
,
4132 struct messaging_context
*msg_ctx
,
4133 const char *servername
,
4134 struct spoolss_PrinterInfo7
*r
,
4137 struct auth_serversupplied_info
*server_info
;
4141 status
= make_server_info_system(mem_ctx
, &server_info
);
4142 if (!NT_STATUS_IS_OK(status
)) {
4143 DEBUG(0, ("construct_printer_info7: "
4144 "Could not create system server_info\n"));
4148 if (is_printer_published(mem_ctx
, server_info
, msg_ctx
,
4150 lp_servicename(snum
), &guid
, NULL
)) {
4151 r
->guid
= talloc_strdup_upper(mem_ctx
, GUID_string2(mem_ctx
, &guid
));
4152 r
->action
= DSPRINT_PUBLISH
;
4154 r
->guid
= talloc_strdup(mem_ctx
, "");
4155 r
->action
= DSPRINT_UNPUBLISH
;
4157 W_ERROR_HAVE_NO_MEMORY(r
->guid
);
4159 TALLOC_FREE(server_info
);
4163 /********************************************************************
4164 * construct_printer_info8
4165 * fill a spoolss_PrinterInfo8 struct
4166 ********************************************************************/
4168 static WERROR
construct_printer_info8(TALLOC_CTX
*mem_ctx
,
4169 const struct spoolss_PrinterInfo2
*info2
,
4170 const char *servername
,
4171 struct spoolss_DeviceModeInfo
*r
,
4175 const char *printername
;
4177 result
= create_printername(mem_ctx
, servername
, info2
->printername
, &printername
);
4178 if (!W_ERROR_IS_OK(result
)) {
4182 copy_devicemode(mem_ctx
, info2
->devmode
, &r
->devmode
);
4184 DEBUG(8,("Returning NULL Devicemode!\n"));
4187 compose_devicemode_devicename(r
->devmode
, printername
);
4193 /********************************************************************
4194 ********************************************************************/
4196 static bool snum_is_shared_printer(int snum
)
4198 return (lp_browseable(snum
) && lp_snum_ok(snum
) && lp_print_ok(snum
));
4201 /********************************************************************
4202 Spoolss_enumprinters.
4203 ********************************************************************/
4205 static WERROR
enum_all_printers_info_level(TALLOC_CTX
*mem_ctx
,
4206 const struct auth_serversupplied_info
*server_info
,
4207 struct messaging_context
*msg_ctx
,
4208 const char *servername
,
4211 union spoolss_PrinterInfo
**info_p
,
4215 int n_services
= lp_numservices();
4216 union spoolss_PrinterInfo
*info
= NULL
;
4218 WERROR result
= WERR_OK
;
4223 for (snum
= 0; snum
< n_services
; snum
++) {
4225 const char *printer
;
4226 struct spoolss_PrinterInfo2
*info2
;
4228 if (!snum_is_shared_printer(snum
)) {
4232 printer
= lp_const_servicename(snum
);
4234 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
4237 result
= winreg_create_printer(mem_ctx
,
4241 if (!W_ERROR_IS_OK(result
)) {
4245 info
= TALLOC_REALLOC_ARRAY(mem_ctx
, info
,
4246 union spoolss_PrinterInfo
,
4249 result
= WERR_NOMEM
;
4253 result
= winreg_get_printer(mem_ctx
, server_info
, msg_ctx
,
4255 if (!W_ERROR_IS_OK(result
)) {
4261 result
= construct_printer_info0(info
, server_info
,
4264 &info
[count
].info0
, snum
);
4267 result
= construct_printer_info1(info
, info2
, flags
,
4269 &info
[count
].info1
, snum
);
4272 result
= construct_printer_info2(info
, msg_ctx
, info2
,
4274 &info
[count
].info2
, snum
);
4277 result
= construct_printer_info4(info
, info2
,
4279 &info
[count
].info4
, snum
);
4282 result
= construct_printer_info5(info
, info2
,
4284 &info
[count
].info5
, snum
);
4288 result
= WERR_UNKNOWN_LEVEL
;
4292 if (!W_ERROR_IS_OK(result
)) {
4303 if (!W_ERROR_IS_OK(result
)) {
4313 /********************************************************************
4314 * handle enumeration of printers at level 0
4315 ********************************************************************/
4317 static WERROR
enumprinters_level0(TALLOC_CTX
*mem_ctx
,
4318 const struct auth_serversupplied_info
*server_info
,
4319 struct messaging_context
*msg_ctx
,
4321 const char *servername
,
4322 union spoolss_PrinterInfo
**info
,
4325 DEBUG(4,("enum_all_printers_info_0\n"));
4327 return enum_all_printers_info_level(mem_ctx
, server_info
, msg_ctx
,
4328 servername
, 0, flags
, info
, count
);
4332 /********************************************************************
4333 ********************************************************************/
4335 static WERROR
enum_all_printers_info_1(TALLOC_CTX
*mem_ctx
,
4336 const struct auth_serversupplied_info
*server_info
,
4337 struct messaging_context
*msg_ctx
,
4338 const char *servername
,
4340 union spoolss_PrinterInfo
**info
,
4343 DEBUG(4,("enum_all_printers_info_1\n"));
4345 return enum_all_printers_info_level(mem_ctx
, server_info
, msg_ctx
,
4346 servername
, 1, flags
, info
, count
);
4349 /********************************************************************
4350 enum_all_printers_info_1_local.
4351 *********************************************************************/
4353 static WERROR
enum_all_printers_info_1_local(TALLOC_CTX
*mem_ctx
,
4354 const struct auth_serversupplied_info
*server_info
,
4355 struct messaging_context
*msg_ctx
,
4356 const char *servername
,
4357 union spoolss_PrinterInfo
**info
,
4360 DEBUG(4,("enum_all_printers_info_1_local\n"));
4362 return enum_all_printers_info_1(mem_ctx
, server_info
, msg_ctx
,
4363 servername
, PRINTER_ENUM_ICON8
, info
, count
);
4366 /********************************************************************
4367 enum_all_printers_info_1_name.
4368 *********************************************************************/
4370 static WERROR
enum_all_printers_info_1_name(TALLOC_CTX
*mem_ctx
,
4371 const struct auth_serversupplied_info
*server_info
,
4372 struct messaging_context
*msg_ctx
,
4373 const char *servername
,
4374 union spoolss_PrinterInfo
**info
,
4377 const char *s
= servername
;
4379 DEBUG(4,("enum_all_printers_info_1_name\n"));
4381 if ((servername
[0] == '\\') && (servername
[1] == '\\')) {
4385 if (!is_myname_or_ipaddr(s
)) {
4386 return WERR_INVALID_NAME
;
4389 return enum_all_printers_info_1(mem_ctx
, server_info
, msg_ctx
,
4390 servername
, PRINTER_ENUM_ICON8
, info
, count
);
4393 /********************************************************************
4394 enum_all_printers_info_1_network.
4395 *********************************************************************/
4397 static WERROR
enum_all_printers_info_1_network(TALLOC_CTX
*mem_ctx
,
4398 const struct auth_serversupplied_info
*server_info
,
4399 struct messaging_context
*msg_ctx
,
4400 const char *servername
,
4401 union spoolss_PrinterInfo
**info
,
4404 const char *s
= servername
;
4406 DEBUG(4,("enum_all_printers_info_1_network\n"));
4408 /* If we respond to a enum_printers level 1 on our name with flags
4409 set to PRINTER_ENUM_REMOTE with a list of printers then these
4410 printers incorrectly appear in the APW browse list.
4411 Specifically the printers for the server appear at the workgroup
4412 level where all the other servers in the domain are
4413 listed. Windows responds to this call with a
4414 WERR_CAN_NOT_COMPLETE so we should do the same. */
4416 if (servername
[0] == '\\' && servername
[1] == '\\') {
4420 if (is_myname_or_ipaddr(s
)) {
4421 return WERR_CAN_NOT_COMPLETE
;
4424 return enum_all_printers_info_1(mem_ctx
, server_info
, msg_ctx
,
4425 servername
, PRINTER_ENUM_NAME
, info
, count
);
4428 /********************************************************************
4429 * api_spoolss_enumprinters
4431 * called from api_spoolss_enumprinters (see this to understand)
4432 ********************************************************************/
4434 static WERROR
enum_all_printers_info_2(TALLOC_CTX
*mem_ctx
,
4435 const struct auth_serversupplied_info
*server_info
,
4436 struct messaging_context
*msg_ctx
,
4437 const char *servername
,
4438 union spoolss_PrinterInfo
**info
,
4441 DEBUG(4,("enum_all_printers_info_2\n"));
4443 return enum_all_printers_info_level(mem_ctx
, server_info
, msg_ctx
,
4444 servername
, 2, 0, info
, count
);
4447 /********************************************************************
4448 * handle enumeration of printers at level 1
4449 ********************************************************************/
4451 static WERROR
enumprinters_level1(TALLOC_CTX
*mem_ctx
,
4452 const struct auth_serversupplied_info
*server_info
,
4453 struct messaging_context
*msg_ctx
,
4455 const char *servername
,
4456 union spoolss_PrinterInfo
**info
,
4459 /* Not all the flags are equals */
4461 if (flags
& PRINTER_ENUM_LOCAL
) {
4462 return enum_all_printers_info_1_local(mem_ctx
, server_info
,
4463 msg_ctx
, servername
, info
, count
);
4466 if (flags
& PRINTER_ENUM_NAME
) {
4467 return enum_all_printers_info_1_name(mem_ctx
, server_info
,
4468 msg_ctx
, servername
, info
,
4472 if (flags
& PRINTER_ENUM_NETWORK
) {
4473 return enum_all_printers_info_1_network(mem_ctx
, server_info
,
4474 msg_ctx
, servername
, info
,
4478 return WERR_OK
; /* NT4sp5 does that */
4481 /********************************************************************
4482 * handle enumeration of printers at level 2
4483 ********************************************************************/
4485 static WERROR
enumprinters_level2(TALLOC_CTX
*mem_ctx
,
4486 const struct auth_serversupplied_info
*server_info
,
4487 struct messaging_context
*msg_ctx
,
4489 const char *servername
,
4490 union spoolss_PrinterInfo
**info
,
4493 if (flags
& PRINTER_ENUM_LOCAL
) {
4495 return enum_all_printers_info_2(mem_ctx
, server_info
, msg_ctx
,
4500 if (flags
& PRINTER_ENUM_NAME
) {
4501 if (servername
&& !is_myname_or_ipaddr(canon_servername(servername
))) {
4502 return WERR_INVALID_NAME
;
4505 return enum_all_printers_info_2(mem_ctx
, server_info
, msg_ctx
,
4510 if (flags
& PRINTER_ENUM_REMOTE
) {
4511 return WERR_UNKNOWN_LEVEL
;
4517 /********************************************************************
4518 * handle enumeration of printers at level 4
4519 ********************************************************************/
4521 static WERROR
enumprinters_level4(TALLOC_CTX
*mem_ctx
,
4522 const struct auth_serversupplied_info
*server_info
,
4523 struct messaging_context
*msg_ctx
,
4525 const char *servername
,
4526 union spoolss_PrinterInfo
**info
,
4529 DEBUG(4,("enum_all_printers_info_4\n"));
4531 return enum_all_printers_info_level(mem_ctx
, server_info
, msg_ctx
,
4532 servername
, 4, flags
, info
, count
);
4536 /********************************************************************
4537 * handle enumeration of printers at level 5
4538 ********************************************************************/
4540 static WERROR
enumprinters_level5(TALLOC_CTX
*mem_ctx
,
4541 const struct auth_serversupplied_info
*server_info
,
4542 struct messaging_context
*msg_ctx
,
4544 const char *servername
,
4545 union spoolss_PrinterInfo
**info
,
4548 DEBUG(4,("enum_all_printers_info_5\n"));
4550 return enum_all_printers_info_level(mem_ctx
, server_info
, msg_ctx
,
4551 servername
, 5, flags
, info
, count
);
4554 /****************************************************************
4555 _spoolss_EnumPrinters
4556 ****************************************************************/
4558 WERROR
_spoolss_EnumPrinters(struct pipes_struct
*p
,
4559 struct spoolss_EnumPrinters
*r
)
4561 const struct auth_serversupplied_info
*server_info
= get_server_info_system();
4564 /* that's an [in out] buffer */
4566 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
4567 return WERR_INVALID_PARAM
;
4570 DEBUG(4,("_spoolss_EnumPrinters\n"));
4574 *r
->out
.info
= NULL
;
4578 * flags==PRINTER_ENUM_NAME
4579 * if name=="" then enumerates all printers
4580 * if name!="" then enumerate the printer
4581 * flags==PRINTER_ENUM_REMOTE
4582 * name is NULL, enumerate printers
4583 * Level 2: name!="" enumerates printers, name can't be NULL
4584 * Level 3: doesn't exist
4585 * Level 4: does a local registry lookup
4586 * Level 5: same as Level 2
4589 if (r
->in
.server
&& r
->in
.server
[0] == '\0') {
4590 r
->in
.server
= NULL
;
4593 switch (r
->in
.level
) {
4595 result
= enumprinters_level0(p
->mem_ctx
, server_info
,
4596 p
->msg_ctx
, r
->in
.flags
,
4598 r
->out
.info
, r
->out
.count
);
4601 result
= enumprinters_level1(p
->mem_ctx
, server_info
,
4602 p
->msg_ctx
, r
->in
.flags
,
4604 r
->out
.info
, r
->out
.count
);
4607 result
= enumprinters_level2(p
->mem_ctx
, server_info
,
4608 p
->msg_ctx
, r
->in
.flags
,
4610 r
->out
.info
, r
->out
.count
);
4613 result
= enumprinters_level4(p
->mem_ctx
, server_info
,
4614 p
->msg_ctx
, r
->in
.flags
,
4616 r
->out
.info
, r
->out
.count
);
4619 result
= enumprinters_level5(p
->mem_ctx
, server_info
,
4620 p
->msg_ctx
, r
->in
.flags
,
4622 r
->out
.info
, r
->out
.count
);
4625 return WERR_UNKNOWN_LEVEL
;
4628 if (!W_ERROR_IS_OK(result
)) {
4632 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
4633 spoolss_EnumPrinters
,
4634 *r
->out
.info
, r
->in
.level
,
4636 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
4637 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
4639 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
4642 /****************************************************************
4644 ****************************************************************/
4646 WERROR
_spoolss_GetPrinter(struct pipes_struct
*p
,
4647 struct spoolss_GetPrinter
*r
)
4649 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
4650 struct spoolss_PrinterInfo2
*info2
= NULL
;
4651 WERROR result
= WERR_OK
;
4654 /* that's an [in out] buffer */
4656 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
4657 return WERR_INVALID_PARAM
;
4662 if (Printer
== NULL
) {
4666 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
4670 result
= winreg_get_printer(p
->mem_ctx
,
4671 get_server_info_system(),
4673 lp_const_servicename(snum
),
4675 if (!W_ERROR_IS_OK(result
)) {
4679 switch (r
->in
.level
) {
4681 result
= construct_printer_info0(p
->mem_ctx
,
4682 get_server_info_system(),
4685 Printer
->servername
,
4686 &r
->out
.info
->info0
,
4690 result
= construct_printer_info1(p
->mem_ctx
, info2
,
4692 Printer
->servername
,
4693 &r
->out
.info
->info1
, snum
);
4696 result
= construct_printer_info2(p
->mem_ctx
, p
->msg_ctx
, info2
,
4697 Printer
->servername
,
4698 &r
->out
.info
->info2
, snum
);
4701 result
= construct_printer_info3(p
->mem_ctx
, info2
,
4702 Printer
->servername
,
4703 &r
->out
.info
->info3
, snum
);
4706 result
= construct_printer_info4(p
->mem_ctx
, info2
,
4707 Printer
->servername
,
4708 &r
->out
.info
->info4
, snum
);
4711 result
= construct_printer_info5(p
->mem_ctx
, info2
,
4712 Printer
->servername
,
4713 &r
->out
.info
->info5
, snum
);
4716 result
= construct_printer_info6(p
->mem_ctx
, p
->msg_ctx
, info2
,
4717 Printer
->servername
,
4718 &r
->out
.info
->info6
, snum
);
4721 result
= construct_printer_info7(p
->mem_ctx
, p
->msg_ctx
,
4722 Printer
->servername
,
4723 &r
->out
.info
->info7
, snum
);
4726 result
= construct_printer_info8(p
->mem_ctx
, info2
,
4727 Printer
->servername
,
4728 &r
->out
.info
->info8
, snum
);
4731 result
= WERR_UNKNOWN_LEVEL
;
4736 if (!W_ERROR_IS_OK(result
)) {
4737 DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
4738 r
->in
.level
, win_errstr(result
)));
4739 TALLOC_FREE(r
->out
.info
);
4743 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo
,
4744 r
->out
.info
, r
->in
.level
);
4745 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
4747 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
4750 /********************************************************************
4751 ********************************************************************/
4753 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4755 if (in && strlen(in)) { \
4756 out = talloc_strdup(mem_ctx, in); \
4758 out = talloc_strdup(mem_ctx, ""); \
4760 W_ERROR_HAVE_NO_MEMORY(out); \
4763 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, arch, ver, in, out) \
4765 if (in && strlen(in)) { \
4766 out = talloc_asprintf(mem_ctx, "\\\\%s\\print$\\%s\\%d\\%s", server, get_short_archi(arch), ver, in); \
4768 out = talloc_strdup(mem_ctx, ""); \
4770 W_ERROR_HAVE_NO_MEMORY(out); \
4773 static WERROR
string_array_from_driver_info(TALLOC_CTX
*mem_ctx
,
4774 const char **string_array
,
4775 const char ***presult
,
4776 const char *cservername
,
4780 int i
, num_strings
= 0;
4781 const char **array
= NULL
;
4783 if (string_array
== NULL
) {
4784 return WERR_INVALID_PARAMETER
;;
4787 for (i
=0; string_array
[i
] && string_array
[i
][0] != '\0'; i
++) {
4788 const char *str
= NULL
;
4790 if (cservername
== NULL
|| arch
== NULL
) {
4791 FILL_DRIVER_STRING(mem_ctx
, string_array
[i
], str
);
4793 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
, arch
, version
, string_array
[i
], str
);
4796 if (!add_string_to_array(mem_ctx
, str
, &array
, &num_strings
)) {
4803 ADD_TO_ARRAY(mem_ctx
, const char *, NULL
,
4804 &array
, &num_strings
);
4814 /********************************************************************
4815 * fill a spoolss_DriverInfo1 struct
4816 ********************************************************************/
4818 static WERROR
fill_printer_driver_info1(TALLOC_CTX
*mem_ctx
,
4819 struct spoolss_DriverInfo1
*r
,
4820 const struct spoolss_DriverInfo8
*driver
,
4821 const char *servername
)
4823 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
4824 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
4829 /********************************************************************
4830 * fill a spoolss_DriverInfo2 struct
4831 ********************************************************************/
4833 static WERROR
fill_printer_driver_info2(TALLOC_CTX
*mem_ctx
,
4834 struct spoolss_DriverInfo2
*r
,
4835 const struct spoolss_DriverInfo8
*driver
,
4836 const char *servername
)
4839 const char *cservername
= canon_servername(servername
);
4841 r
->version
= driver
->version
;
4843 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
4844 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
4845 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
4846 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
4848 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4849 driver
->architecture
,
4851 driver
->driver_path
,
4854 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4855 driver
->architecture
,
4860 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4861 driver
->architecture
,
4863 driver
->config_file
,
4869 /********************************************************************
4870 * fill a spoolss_DriverInfo3 struct
4871 ********************************************************************/
4873 static WERROR
fill_printer_driver_info3(TALLOC_CTX
*mem_ctx
,
4874 struct spoolss_DriverInfo3
*r
,
4875 const struct spoolss_DriverInfo8
*driver
,
4876 const char *servername
)
4878 const char *cservername
= canon_servername(servername
);
4880 r
->version
= driver
->version
;
4882 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
4883 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
4884 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
4885 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
4887 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4888 driver
->architecture
,
4890 driver
->driver_path
,
4893 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4894 driver
->architecture
,
4899 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4900 driver
->architecture
,
4902 driver
->config_file
,
4905 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4906 driver
->architecture
,
4911 FILL_DRIVER_STRING(mem_ctx
,
4912 driver
->monitor_name
,
4915 FILL_DRIVER_STRING(mem_ctx
,
4916 driver
->default_datatype
,
4917 r
->default_datatype
);
4919 return string_array_from_driver_info(mem_ctx
,
4920 driver
->dependent_files
,
4921 &r
->dependent_files
,
4923 driver
->architecture
,
4927 /********************************************************************
4928 * fill a spoolss_DriverInfo4 struct
4929 ********************************************************************/
4931 static WERROR
fill_printer_driver_info4(TALLOC_CTX
*mem_ctx
,
4932 struct spoolss_DriverInfo4
*r
,
4933 const struct spoolss_DriverInfo8
*driver
,
4934 const char *servername
)
4936 const char *cservername
= canon_servername(servername
);
4939 r
->version
= driver
->version
;
4941 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
4942 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
4943 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
4944 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
4946 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4947 driver
->architecture
,
4949 driver
->driver_path
,
4952 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4953 driver
->architecture
,
4958 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4959 driver
->architecture
,
4961 driver
->config_file
,
4964 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
4965 driver
->architecture
,
4970 result
= string_array_from_driver_info(mem_ctx
,
4971 driver
->dependent_files
,
4972 &r
->dependent_files
,
4974 driver
->architecture
,
4976 if (!W_ERROR_IS_OK(result
)) {
4980 FILL_DRIVER_STRING(mem_ctx
,
4981 driver
->monitor_name
,
4984 FILL_DRIVER_STRING(mem_ctx
,
4985 driver
->default_datatype
,
4986 r
->default_datatype
);
4989 result
= string_array_from_driver_info(mem_ctx
,
4990 driver
->previous_names
,
4997 /********************************************************************
4998 * fill a spoolss_DriverInfo5 struct
4999 ********************************************************************/
5001 static WERROR
fill_printer_driver_info5(TALLOC_CTX
*mem_ctx
,
5002 struct spoolss_DriverInfo5
*r
,
5003 const struct spoolss_DriverInfo8
*driver
,
5004 const char *servername
)
5006 const char *cservername
= canon_servername(servername
);
5008 r
->version
= driver
->version
;
5010 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5011 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5012 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5013 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5015 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5016 driver
->architecture
,
5018 driver
->driver_path
,
5021 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5022 driver
->architecture
,
5027 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5028 driver
->architecture
,
5030 driver
->config_file
,
5033 r
->driver_attributes
= 0;
5034 r
->config_version
= 0;
5035 r
->driver_version
= 0;
5039 /********************************************************************
5040 * fill a spoolss_DriverInfo6 struct
5041 ********************************************************************/
5043 static WERROR
fill_printer_driver_info6(TALLOC_CTX
*mem_ctx
,
5044 struct spoolss_DriverInfo6
*r
,
5045 const struct spoolss_DriverInfo8
*driver
,
5046 const char *servername
)
5048 const char *cservername
= canon_servername(servername
);
5051 r
->version
= driver
->version
;
5053 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5054 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5055 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5056 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5058 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5059 driver
->architecture
,
5061 driver
->driver_path
,
5064 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5065 driver
->architecture
,
5070 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5071 driver
->architecture
,
5073 driver
->config_file
,
5076 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5077 driver
->architecture
,
5082 FILL_DRIVER_STRING(mem_ctx
,
5083 driver
->monitor_name
,
5086 FILL_DRIVER_STRING(mem_ctx
,
5087 driver
->default_datatype
,
5088 r
->default_datatype
);
5090 result
= string_array_from_driver_info(mem_ctx
,
5091 driver
->dependent_files
,
5092 &r
->dependent_files
,
5094 driver
->architecture
,
5096 if (!W_ERROR_IS_OK(result
)) {
5100 result
= string_array_from_driver_info(mem_ctx
,
5101 driver
->previous_names
,
5104 if (!W_ERROR_IS_OK(result
)) {
5108 r
->driver_date
= driver
->driver_date
;
5109 r
->driver_version
= driver
->driver_version
;
5111 FILL_DRIVER_STRING(mem_ctx
,
5112 driver
->manufacturer_name
,
5113 r
->manufacturer_name
);
5114 FILL_DRIVER_STRING(mem_ctx
,
5115 driver
->manufacturer_url
,
5116 r
->manufacturer_url
);
5117 FILL_DRIVER_STRING(mem_ctx
,
5118 driver
->hardware_id
,
5120 FILL_DRIVER_STRING(mem_ctx
,
5127 /********************************************************************
5128 * fill a spoolss_DriverInfo8 struct
5129 ********************************************************************/
5131 static WERROR
fill_printer_driver_info8(TALLOC_CTX
*mem_ctx
,
5132 struct spoolss_DriverInfo8
*r
,
5133 const struct spoolss_DriverInfo8
*driver
,
5134 const char *servername
)
5136 const char *cservername
= canon_servername(servername
);
5139 r
->version
= driver
->version
;
5141 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5142 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5143 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5144 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5146 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5147 driver
->architecture
,
5149 driver
->driver_path
,
5152 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5153 driver
->architecture
,
5158 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5159 driver
->architecture
,
5161 driver
->config_file
,
5164 FILL_DRIVER_UNC_STRING(mem_ctx
, cservername
,
5165 driver
->architecture
,
5170 FILL_DRIVER_STRING(mem_ctx
,
5171 driver
->monitor_name
,
5174 FILL_DRIVER_STRING(mem_ctx
,
5175 driver
->default_datatype
,
5176 r
->default_datatype
);
5178 result
= string_array_from_driver_info(mem_ctx
,
5179 driver
->dependent_files
,
5180 &r
->dependent_files
,
5182 driver
->architecture
,
5184 if (!W_ERROR_IS_OK(result
)) {
5188 result
= string_array_from_driver_info(mem_ctx
,
5189 driver
->previous_names
,
5192 if (!W_ERROR_IS_OK(result
)) {
5196 r
->driver_date
= driver
->driver_date
;
5197 r
->driver_version
= driver
->driver_version
;
5199 FILL_DRIVER_STRING(mem_ctx
,
5200 driver
->manufacturer_name
,
5201 r
->manufacturer_name
);
5202 FILL_DRIVER_STRING(mem_ctx
,
5203 driver
->manufacturer_url
,
5204 r
->manufacturer_url
);
5205 FILL_DRIVER_STRING(mem_ctx
,
5206 driver
->hardware_id
,
5208 FILL_DRIVER_STRING(mem_ctx
,
5212 FILL_DRIVER_STRING(mem_ctx
,
5213 driver
->print_processor
,
5214 r
->print_processor
);
5215 FILL_DRIVER_STRING(mem_ctx
,
5216 driver
->vendor_setup
,
5219 result
= string_array_from_driver_info(mem_ctx
,
5220 driver
->color_profiles
,
5223 if (!W_ERROR_IS_OK(result
)) {
5227 FILL_DRIVER_STRING(mem_ctx
,
5231 r
->printer_driver_attributes
= driver
->printer_driver_attributes
;
5233 result
= string_array_from_driver_info(mem_ctx
,
5234 driver
->core_driver_dependencies
,
5235 &r
->core_driver_dependencies
,
5237 if (!W_ERROR_IS_OK(result
)) {
5241 r
->min_inbox_driver_ver_date
= driver
->min_inbox_driver_ver_date
;
5242 r
->min_inbox_driver_ver_version
= driver
->min_inbox_driver_ver_version
;
5247 #if 0 /* disabled until marshalling issues are resolved - gd */
5248 /********************************************************************
5249 ********************************************************************/
5251 static WERROR
fill_spoolss_DriverFileInfo(TALLOC_CTX
*mem_ctx
,
5252 struct spoolss_DriverFileInfo
*r
,
5253 const char *cservername
,
5254 const char *file_name
,
5255 enum spoolss_DriverFileType file_type
,
5256 uint32_t file_version
)
5258 r
->file_name
= talloc_asprintf(mem_ctx
, "\\\\%s%s",
5259 cservername
, file_name
);
5260 W_ERROR_HAVE_NO_MEMORY(r
->file_name
);
5261 r
->file_type
= file_type
;
5262 r
->file_version
= file_version
;
5267 /********************************************************************
5268 ********************************************************************/
5270 static WERROR
spoolss_DriverFileInfo_from_driver(TALLOC_CTX
*mem_ctx
,
5271 const struct spoolss_DriverInfo8
*driver
,
5272 const char *cservername
,
5273 struct spoolss_DriverFileInfo
**info_p
,
5276 struct spoolss_DriverFileInfo
*info
= NULL
;
5284 if (strlen(driver
->driver_path
)) {
5285 info
= TALLOC_REALLOC_ARRAY(mem_ctx
, info
,
5286 struct spoolss_DriverFileInfo
,
5288 W_ERROR_HAVE_NO_MEMORY(info
);
5289 result
= fill_spoolss_DriverFileInfo(info
,
5292 driver
->driver_path
,
5293 SPOOLSS_DRIVER_FILE_TYPE_RENDERING
,
5295 W_ERROR_NOT_OK_RETURN(result
);
5299 if (strlen(driver
->config_file
)) {
5300 info
= TALLOC_REALLOC_ARRAY(mem_ctx
, info
,
5301 struct spoolss_DriverFileInfo
,
5303 W_ERROR_HAVE_NO_MEMORY(info
);
5304 result
= fill_spoolss_DriverFileInfo(info
,
5307 driver
->config_file
,
5308 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION
,
5310 W_ERROR_NOT_OK_RETURN(result
);
5314 if (strlen(driver
->data_file
)) {
5315 info
= TALLOC_REALLOC_ARRAY(mem_ctx
, info
,
5316 struct spoolss_DriverFileInfo
,
5318 W_ERROR_HAVE_NO_MEMORY(info
);
5319 result
= fill_spoolss_DriverFileInfo(info
,
5323 SPOOLSS_DRIVER_FILE_TYPE_DATA
,
5325 W_ERROR_NOT_OK_RETURN(result
);
5329 if (strlen(driver
->help_file
)) {
5330 info
= TALLOC_REALLOC_ARRAY(mem_ctx
, info
,
5331 struct spoolss_DriverFileInfo
,
5333 W_ERROR_HAVE_NO_MEMORY(info
);
5334 result
= fill_spoolss_DriverFileInfo(info
,
5338 SPOOLSS_DRIVER_FILE_TYPE_HELP
,
5340 W_ERROR_NOT_OK_RETURN(result
);
5344 for (i
=0; driver
->dependent_files
[i
] && driver
->dependent_files
[i
][0] != '\0'; i
++) {
5345 info
= TALLOC_REALLOC_ARRAY(mem_ctx
, info
,
5346 struct spoolss_DriverFileInfo
,
5348 W_ERROR_HAVE_NO_MEMORY(info
);
5349 result
= fill_spoolss_DriverFileInfo(info
,
5352 driver
->dependent_files
[i
],
5353 SPOOLSS_DRIVER_FILE_TYPE_OTHER
,
5355 W_ERROR_NOT_OK_RETURN(result
);
5365 /********************************************************************
5366 * fill a spoolss_DriverInfo101 struct
5367 ********************************************************************/
5369 static WERROR
fill_printer_driver_info101(TALLOC_CTX
*mem_ctx
,
5370 struct spoolss_DriverInfo101
*r
,
5371 const struct spoolss_DriverInfo8
*driver
,
5372 const char *servername
)
5374 const char *cservername
= canon_servername(servername
);
5377 r
->version
= driver
->version
;
5379 r
->driver_name
= talloc_strdup(mem_ctx
, driver
->driver_name
);
5380 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
5381 r
->architecture
= talloc_strdup(mem_ctx
, driver
->architecture
);
5382 W_ERROR_HAVE_NO_MEMORY(r
->architecture
);
5384 result
= spoolss_DriverFileInfo_from_driver(mem_ctx
, driver
,
5388 if (!W_ERROR_IS_OK(result
)) {
5392 FILL_DRIVER_STRING(mem_ctx
,
5393 driver
->monitor_name
,
5396 FILL_DRIVER_STRING(mem_ctx
,
5397 driver
->default_datatype
,
5398 r
->default_datatype
);
5400 result
= string_array_from_driver_info(mem_ctx
,
5401 driver
->previous_names
,
5404 if (!W_ERROR_IS_OK(result
)) {
5408 r
->driver_date
= driver
->driver_date
;
5409 r
->driver_version
= driver
->driver_version
;
5411 FILL_DRIVER_STRING(mem_ctx
,
5412 driver
->manufacturer_name
,
5413 r
->manufacturer_name
);
5414 FILL_DRIVER_STRING(mem_ctx
,
5415 driver
->manufacturer_url
,
5416 r
->manufacturer_url
);
5417 FILL_DRIVER_STRING(mem_ctx
,
5418 driver
->hardware_id
,
5420 FILL_DRIVER_STRING(mem_ctx
,
5427 /********************************************************************
5428 ********************************************************************/
5430 static WERROR
construct_printer_driver_info_level(TALLOC_CTX
*mem_ctx
,
5431 const struct auth_serversupplied_info
*server_info
,
5432 struct messaging_context
*msg_ctx
,
5434 union spoolss_DriverInfo
*r
,
5436 const char *servername
,
5437 const char *architecture
,
5440 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
5441 struct spoolss_DriverInfo8
*driver
;
5445 return WERR_UNKNOWN_LEVEL
;
5448 result
= winreg_get_printer(mem_ctx
,
5451 lp_const_servicename(snum
),
5454 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5455 win_errstr(result
)));
5457 if (!W_ERROR_IS_OK(result
)) {
5458 return WERR_INVALID_PRINTER_NAME
;
5461 result
= winreg_get_driver(mem_ctx
, server_info
, msg_ctx
,
5463 pinfo2
->drivername
, version
, &driver
);
5465 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5466 win_errstr(result
)));
5468 if (!W_ERROR_IS_OK(result
)) {
5470 * Is this a W2k client ?
5474 talloc_free(pinfo2
);
5475 return WERR_UNKNOWN_PRINTER_DRIVER
;
5478 /* Yes - try again with a WinNT driver. */
5480 result
= winreg_get_driver(mem_ctx
, server_info
, msg_ctx
,
5484 DEBUG(8,("construct_printer_driver_level: status: %s\n",
5485 win_errstr(result
)));
5486 if (!W_ERROR_IS_OK(result
)) {
5487 talloc_free(pinfo2
);
5488 return WERR_UNKNOWN_PRINTER_DRIVER
;
5494 result
= fill_printer_driver_info1(mem_ctx
, &r
->info1
, driver
, servername
);
5497 result
= fill_printer_driver_info2(mem_ctx
, &r
->info2
, driver
, servername
);
5500 result
= fill_printer_driver_info3(mem_ctx
, &r
->info3
, driver
, servername
);
5503 result
= fill_printer_driver_info4(mem_ctx
, &r
->info4
, driver
, servername
);
5506 result
= fill_printer_driver_info5(mem_ctx
, &r
->info5
, driver
, servername
);
5509 result
= fill_printer_driver_info6(mem_ctx
, &r
->info6
, driver
, servername
);
5512 result
= fill_printer_driver_info8(mem_ctx
, &r
->info8
, driver
, servername
);
5514 #if 0 /* disabled until marshalling issues are resolved - gd */
5516 result
= fill_printer_driver_info101(mem_ctx
, &r
->info101
, driver
, servername
);
5520 result
= WERR_UNKNOWN_LEVEL
;
5524 talloc_free(pinfo2
);
5525 talloc_free(driver
);
5530 /****************************************************************
5531 _spoolss_GetPrinterDriver2
5532 ****************************************************************/
5534 WERROR
_spoolss_GetPrinterDriver2(struct pipes_struct
*p
,
5535 struct spoolss_GetPrinterDriver2
*r
)
5537 struct printer_handle
*printer
;
5542 /* that's an [in out] buffer */
5544 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
5545 return WERR_INVALID_PARAM
;
5548 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5550 if (!(printer
= find_printer_index_by_hnd(p
, r
->in
.handle
))) {
5551 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5552 return WERR_INVALID_PRINTER_NAME
;
5556 *r
->out
.server_major_version
= 0;
5557 *r
->out
.server_minor_version
= 0;
5559 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
5563 result
= construct_printer_driver_info_level(p
->mem_ctx
,
5564 get_server_info_system(),
5566 r
->in
.level
, r
->out
.info
,
5567 snum
, printer
->servername
,
5569 r
->in
.client_major_version
);
5570 if (!W_ERROR_IS_OK(result
)) {
5571 TALLOC_FREE(r
->out
.info
);
5575 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_DriverInfo
,
5576 r
->out
.info
, r
->in
.level
);
5577 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
5579 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
5583 /****************************************************************
5584 _spoolss_StartPagePrinter
5585 ****************************************************************/
5587 WERROR
_spoolss_StartPagePrinter(struct pipes_struct
*p
,
5588 struct spoolss_StartPagePrinter
*r
)
5590 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5593 DEBUG(3,("_spoolss_StartPagePrinter: "
5594 "Error in startpageprinter printer handle\n"));
5598 Printer
->page_started
= true;
5602 /****************************************************************
5603 _spoolss_EndPagePrinter
5604 ****************************************************************/
5606 WERROR
_spoolss_EndPagePrinter(struct pipes_struct
*p
,
5607 struct spoolss_EndPagePrinter
*r
)
5611 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5614 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5615 OUR_HANDLE(r
->in
.handle
)));
5619 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
))
5622 Printer
->page_started
= false;
5623 print_job_endpage(p
->msg_ctx
, snum
, Printer
->jobid
);
5628 /****************************************************************
5629 _spoolss_StartDocPrinter
5630 ****************************************************************/
5632 WERROR
_spoolss_StartDocPrinter(struct pipes_struct
*p
,
5633 struct spoolss_StartDocPrinter
*r
)
5635 struct spoolss_DocumentInfo1
*info_1
;
5637 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5641 DEBUG(2,("_spoolss_StartDocPrinter: "
5642 "Invalid handle (%s:%u:%u)\n",
5643 OUR_HANDLE(r
->in
.handle
)));
5647 if (Printer
->jobid
) {
5648 DEBUG(2, ("_spoolss_StartDocPrinter: "
5649 "StartDocPrinter called twice! "
5650 "(existing jobid = %d)\n", Printer
->jobid
));
5651 return WERR_INVALID_HANDLE
;
5654 if (r
->in
.level
!= 1) {
5655 return WERR_UNKNOWN_LEVEL
;
5658 info_1
= r
->in
.info
.info1
;
5661 * a nice thing with NT is it doesn't listen to what you tell it.
5662 * when asked to send _only_ RAW datas, it tries to send datas
5665 * So I add checks like in NT Server ...
5668 if (info_1
->datatype
) {
5669 if (strcmp(info_1
->datatype
, "RAW") != 0) {
5671 return WERR_INVALID_DATATYPE
;
5675 /* get the share number of the printer */
5676 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
5680 werr
= print_job_start(p
->server_info
,
5684 info_1
->document_name
,
5685 info_1
->output_file
,
5689 /* An error occured in print_job_start() so return an appropriate
5692 if (!W_ERROR_IS_OK(werr
)) {
5696 Printer
->document_started
= true;
5697 *r
->out
.job_id
= Printer
->jobid
;
5702 /****************************************************************
5703 _spoolss_EndDocPrinter
5704 ****************************************************************/
5706 WERROR
_spoolss_EndDocPrinter(struct pipes_struct
*p
,
5707 struct spoolss_EndDocPrinter
*r
)
5709 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5714 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5715 OUR_HANDLE(r
->in
.handle
)));
5719 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
5723 Printer
->document_started
= false;
5724 status
= print_job_end(p
->msg_ctx
, snum
, Printer
->jobid
, NORMAL_CLOSE
);
5725 if (!NT_STATUS_IS_OK(status
)) {
5726 DEBUG(2, ("_spoolss_EndDocPrinter: "
5727 "print_job_end failed [%s]\n",
5728 nt_errstr(status
)));
5732 return ntstatus_to_werror(status
);
5735 /****************************************************************
5736 _spoolss_WritePrinter
5737 ****************************************************************/
5739 WERROR
_spoolss_WritePrinter(struct pipes_struct
*p
,
5740 struct spoolss_WritePrinter
*r
)
5742 ssize_t buffer_written
;
5744 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5747 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5748 OUR_HANDLE(r
->in
.handle
)));
5749 *r
->out
.num_written
= r
->in
._data_size
;
5753 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
))
5756 /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
5757 buffer_written
= print_job_write(server_event_context(),p
->msg_ctx
,
5758 snum
, Printer
->jobid
,
5759 (const char *)r
->in
.data
.data
,
5760 (size_t)r
->in
._data_size
);
5761 if (buffer_written
== (ssize_t
)-1) {
5762 *r
->out
.num_written
= 0;
5763 if (errno
== ENOSPC
)
5764 return WERR_NO_SPOOL_SPACE
;
5766 return WERR_ACCESS_DENIED
;
5769 *r
->out
.num_written
= r
->in
._data_size
;
5774 /********************************************************************
5775 * api_spoolss_getprinter
5776 * called from the spoolss dispatcher
5778 ********************************************************************/
5780 static WERROR
control_printer(struct policy_handle
*handle
, uint32_t command
,
5781 struct pipes_struct
*p
)
5783 const struct auth_serversupplied_info
*server_info
= p
->server_info
;
5785 WERROR errcode
= WERR_BADFUNC
;
5786 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, handle
);
5789 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5790 OUR_HANDLE(handle
)));
5794 if (!get_printer_snum(p
, handle
, &snum
, NULL
))
5798 case SPOOLSS_PRINTER_CONTROL_PAUSE
:
5799 errcode
= print_queue_pause(server_info
, p
->msg_ctx
, snum
);
5801 case SPOOLSS_PRINTER_CONTROL_RESUME
:
5802 case SPOOLSS_PRINTER_CONTROL_UNPAUSE
:
5803 errcode
= print_queue_resume(server_info
, p
->msg_ctx
, snum
);
5805 case SPOOLSS_PRINTER_CONTROL_PURGE
:
5806 errcode
= print_queue_purge(server_info
, p
->msg_ctx
, snum
);
5809 return WERR_UNKNOWN_LEVEL
;
5816 /****************************************************************
5817 _spoolss_AbortPrinter
5818 * From MSDN: "Deletes printer's spool file if printer is configured
5820 ****************************************************************/
5822 WERROR
_spoolss_AbortPrinter(struct pipes_struct
*p
,
5823 struct spoolss_AbortPrinter
*r
)
5825 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
5827 WERROR errcode
= WERR_OK
;
5830 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5831 OUR_HANDLE(r
->in
.handle
)));
5835 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
))
5838 if (!Printer
->document_started
) {
5839 return WERR_SPL_NO_STARTDOC
;
5842 errcode
= print_job_delete(p
->server_info
,
5850 /********************************************************************
5851 * called by spoolss_api_setprinter
5852 * when updating a printer description
5853 ********************************************************************/
5855 static WERROR
update_printer_sec(struct policy_handle
*handle
,
5856 struct pipes_struct
*p
,
5857 struct sec_desc_buf
*secdesc_ctr
)
5859 struct spoolss_security_descriptor
*new_secdesc
= NULL
;
5860 struct spoolss_security_descriptor
*old_secdesc
= NULL
;
5861 const char *printer
;
5865 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, handle
);
5867 if (!Printer
|| !get_printer_snum(p
, handle
, &snum
, NULL
)) {
5868 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
5869 OUR_HANDLE(handle
)));
5871 result
= WERR_BADFID
;
5875 if (secdesc_ctr
== NULL
) {
5876 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
5877 result
= WERR_INVALID_PARAM
;
5880 printer
= lp_const_servicename(snum
);
5882 /* Check the user has permissions to change the security
5883 descriptor. By experimentation with two NT machines, the user
5884 requires Full Access to the printer to change security
5887 if ( Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
5888 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
5889 result
= WERR_ACCESS_DENIED
;
5893 /* NT seems to like setting the security descriptor even though
5894 nothing may have actually changed. */
5895 result
= winreg_get_printer_secdesc(p
->mem_ctx
,
5896 get_server_info_system(),
5900 if (!W_ERROR_IS_OK(result
)) {
5901 DEBUG(2,("update_printer_sec: winreg_get_printer_secdesc() failed\n"));
5902 result
= WERR_BADFID
;
5906 if (DEBUGLEVEL
>= 10) {
5907 struct security_acl
*the_acl
;
5910 the_acl
= old_secdesc
->dacl
;
5911 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
5912 printer
, the_acl
->num_aces
));
5914 for (i
= 0; i
< the_acl
->num_aces
; i
++) {
5915 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5916 &the_acl
->aces
[i
].trustee
),
5917 the_acl
->aces
[i
].access_mask
));
5920 the_acl
= secdesc_ctr
->sd
->dacl
;
5923 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
5924 printer
, the_acl
->num_aces
));
5926 for (i
= 0; i
< the_acl
->num_aces
; i
++) {
5927 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5928 &the_acl
->aces
[i
].trustee
),
5929 the_acl
->aces
[i
].access_mask
));
5932 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
5936 new_secdesc
= sec_desc_merge(p
->mem_ctx
, secdesc_ctr
->sd
, old_secdesc
);
5937 if (new_secdesc
== NULL
) {
5938 result
= WERR_NOMEM
;
5942 if (security_descriptor_equal(new_secdesc
, old_secdesc
)) {
5947 result
= winreg_set_printer_secdesc(p
->mem_ctx
,
5948 get_server_info_system(),
5957 /********************************************************************
5958 Canonicalize printer info from a client
5959 ********************************************************************/
5961 static bool check_printer_ok(TALLOC_CTX
*mem_ctx
,
5962 struct spoolss_SetPrinterInfo2
*info2
,
5965 fstring printername
;
5968 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
5969 "portname=%s drivername=%s comment=%s location=%s\n",
5970 info2
->servername
, info2
->printername
, info2
->sharename
,
5971 info2
->portname
, info2
->drivername
, info2
->comment
,
5974 /* we force some elements to "correct" values */
5975 info2
->servername
= talloc_asprintf(mem_ctx
, "\\\\%s", global_myname());
5976 if (info2
->servername
== NULL
) {
5979 info2
->sharename
= talloc_strdup(mem_ctx
, lp_const_servicename(snum
));
5980 if (info2
->sharename
== NULL
) {
5984 /* check to see if we allow printername != sharename */
5985 if (lp_force_printername(snum
)) {
5986 info2
->printername
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s",
5987 global_myname(), info2
->sharename
);
5989 /* make sure printername is in \\server\printername format */
5990 fstrcpy(printername
, info2
->printername
);
5992 if ( printername
[0] == '\\' && printername
[1] == '\\' ) {
5993 if ( (p
= strchr_m( &printername
[2], '\\' )) != NULL
)
5997 info2
->printername
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s",
5998 global_myname(), p
);
6000 if (info2
->printername
== NULL
) {
6004 info2
->attributes
|= PRINTER_ATTRIBUTE_SAMBA
;
6005 info2
->attributes
&= ~PRINTER_ATTRIBUTE_NOT_SAMBA
;
6010 /****************************************************************************
6011 ****************************************************************************/
6013 static WERROR
add_port_hook(TALLOC_CTX
*ctx
, struct security_token
*token
, const char *portname
, const char *uri
)
6015 char *cmd
= lp_addport_cmd();
6016 char *command
= NULL
;
6018 bool is_print_op
= false;
6021 return WERR_ACCESS_DENIED
;
6024 command
= talloc_asprintf(ctx
,
6025 "%s \"%s\" \"%s\"", cmd
, portname
, uri
);
6031 is_print_op
= security_token_has_privilege(token
, SEC_PRIV_PRINT_OPERATOR
);
6033 DEBUG(10,("Running [%s]\n", command
));
6035 /********* BEGIN SePrintOperatorPrivilege **********/
6040 ret
= smbrun(command
, NULL
);
6045 /********* END SePrintOperatorPrivilege **********/
6047 DEBUGADD(10,("returned [%d]\n", ret
));
6049 TALLOC_FREE(command
);
6052 return WERR_ACCESS_DENIED
;
6058 /****************************************************************************
6059 ****************************************************************************/
6061 static bool add_printer_hook(TALLOC_CTX
*ctx
, struct security_token
*token
,
6062 struct spoolss_SetPrinterInfo2
*info2
,
6063 const char *remote_machine
,
6064 struct messaging_context
*msg_ctx
)
6066 char *cmd
= lp_addprinter_cmd();
6068 char *command
= NULL
;
6072 bool is_print_op
= false;
6074 if (!remote_machine
) {
6078 command
= talloc_asprintf(ctx
,
6079 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
6080 cmd
, info2
->printername
, info2
->sharename
,
6081 info2
->portname
, info2
->drivername
,
6082 info2
->location
, info2
->comment
, remote_machine
);
6088 is_print_op
= security_token_has_privilege(token
, SEC_PRIV_PRINT_OPERATOR
);
6090 DEBUG(10,("Running [%s]\n", command
));
6092 /********* BEGIN SePrintOperatorPrivilege **********/
6097 if ( (ret
= smbrun(command
, &fd
)) == 0 ) {
6098 /* Tell everyone we updated smb.conf. */
6099 message_send_all(msg_ctx
, MSG_SMB_CONF_UPDATED
, NULL
, 0, NULL
);
6105 /********* END SePrintOperatorPrivilege **********/
6107 DEBUGADD(10,("returned [%d]\n", ret
));
6109 TALLOC_FREE(command
);
6117 /* reload our services immediately */
6119 reload_services(msg_ctx
, -1, false);
6123 /* Get lines and convert them back to dos-codepage */
6124 qlines
= fd_lines_load(fd
, &numlines
, 0, NULL
);
6125 DEBUGADD(10,("Lines returned = [%d]\n", numlines
));
6128 /* Set the portname to what the script says the portname should be. */
6129 /* but don't require anything to be return from the script exit a good error code */
6132 /* Set the portname to what the script says the portname should be. */
6133 info2
->portname
= talloc_strdup(ctx
, qlines
[0]);
6134 DEBUGADD(6,("Line[0] = [%s]\n", qlines
[0]));
6137 TALLOC_FREE(qlines
);
6141 static WERROR
update_dsspooler(TALLOC_CTX
*mem_ctx
,
6142 const struct auth_serversupplied_info
*server_info
,
6143 struct messaging_context
*msg_ctx
,
6145 struct spoolss_SetPrinterInfo2
*printer
,
6146 struct spoolss_PrinterInfo2
*old_printer
)
6148 bool force_update
= (old_printer
== NULL
);
6149 const char *dnsdomname
;
6150 const char *longname
;
6151 const char *uncname
;
6152 const char *spooling
;
6154 WERROR result
= WERR_OK
;
6156 if (force_update
|| !strequal(printer
->drivername
, old_printer
->drivername
)) {
6157 push_reg_sz(mem_ctx
, &buffer
, printer
->drivername
);
6158 winreg_set_printer_dataex(mem_ctx
,
6162 SPOOL_DSSPOOLER_KEY
,
6163 SPOOL_REG_DRIVERNAME
,
6168 if (!force_update
) {
6169 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
6170 printer
->drivername
));
6172 notify_printer_driver(server_event_context(), msg_ctx
,
6173 snum
, printer
->drivername
?
6174 printer
->drivername
: "");
6178 if (force_update
|| !strequal(printer
->comment
, old_printer
->comment
)) {
6179 push_reg_sz(mem_ctx
, &buffer
, printer
->comment
);
6180 winreg_set_printer_dataex(mem_ctx
,
6184 SPOOL_DSSPOOLER_KEY
,
6185 SPOOL_REG_DESCRIPTION
,
6190 if (!force_update
) {
6191 notify_printer_comment(server_event_context(), msg_ctx
,
6192 snum
, printer
->comment
?
6193 printer
->comment
: "");
6197 if (force_update
|| !strequal(printer
->sharename
, old_printer
->sharename
)) {
6198 push_reg_sz(mem_ctx
, &buffer
, printer
->sharename
);
6199 winreg_set_printer_dataex(mem_ctx
,
6203 SPOOL_DSSPOOLER_KEY
,
6204 SPOOL_REG_PRINTSHARENAME
,
6209 if (!force_update
) {
6210 notify_printer_sharename(server_event_context(),
6212 snum
, printer
->sharename
?
6213 printer
->sharename
: "");
6217 if (force_update
|| !strequal(printer
->printername
, old_printer
->printername
)) {
6220 p
= strrchr(printer
->printername
, '\\' );
6224 p
= printer
->printername
;
6227 push_reg_sz(mem_ctx
, &buffer
, p
);
6228 winreg_set_printer_dataex(mem_ctx
,
6232 SPOOL_DSSPOOLER_KEY
,
6233 SPOOL_REG_PRINTERNAME
,
6238 if (!force_update
) {
6239 notify_printer_printername(server_event_context(),
6240 msg_ctx
, snum
, p
? p
: "");
6244 if (force_update
|| !strequal(printer
->portname
, old_printer
->portname
)) {
6245 push_reg_sz(mem_ctx
, &buffer
, printer
->portname
);
6246 winreg_set_printer_dataex(mem_ctx
,
6250 SPOOL_DSSPOOLER_KEY
,
6256 if (!force_update
) {
6257 notify_printer_port(server_event_context(),
6258 msg_ctx
, snum
, printer
->portname
?
6259 printer
->portname
: "");
6263 if (force_update
|| !strequal(printer
->location
, old_printer
->location
)) {
6264 push_reg_sz(mem_ctx
, &buffer
, printer
->location
);
6265 winreg_set_printer_dataex(mem_ctx
,
6269 SPOOL_DSSPOOLER_KEY
,
6275 if (!force_update
) {
6276 notify_printer_location(server_event_context(),
6279 printer
->location
: "");
6283 if (force_update
|| !strequal(printer
->sepfile
, old_printer
->sepfile
)) {
6284 push_reg_sz(mem_ctx
, &buffer
, printer
->sepfile
);
6285 winreg_set_printer_dataex(mem_ctx
,
6289 SPOOL_DSSPOOLER_KEY
,
6290 SPOOL_REG_PRINTSEPARATORFILE
,
6295 if (!force_update
) {
6296 notify_printer_sepfile(server_event_context(),
6299 printer
->sepfile
: "");
6303 if (force_update
|| printer
->starttime
!= old_printer
->starttime
) {
6304 buffer
= data_blob_talloc(mem_ctx
, NULL
, 4);
6305 SIVAL(buffer
.data
, 0, printer
->starttime
);
6306 winreg_set_printer_dataex(mem_ctx
,
6310 SPOOL_DSSPOOLER_KEY
,
6311 SPOOL_REG_PRINTSTARTTIME
,
6317 if (force_update
|| printer
->untiltime
!= old_printer
->untiltime
) {
6318 buffer
= data_blob_talloc(mem_ctx
, NULL
, 4);
6319 SIVAL(buffer
.data
, 0, printer
->untiltime
);
6320 winreg_set_printer_dataex(mem_ctx
,
6324 SPOOL_DSSPOOLER_KEY
,
6325 SPOOL_REG_PRINTENDTIME
,
6331 if (force_update
|| printer
->priority
!= old_printer
->priority
) {
6332 buffer
= data_blob_talloc(mem_ctx
, NULL
, 4);
6333 SIVAL(buffer
.data
, 0, printer
->priority
);
6334 winreg_set_printer_dataex(mem_ctx
,
6338 SPOOL_DSSPOOLER_KEY
,
6345 if (force_update
|| printer
->attributes
!= old_printer
->attributes
) {
6346 buffer
= data_blob_talloc(mem_ctx
, NULL
, 4);
6347 SIVAL(buffer
.data
, 0, (printer
->attributes
&
6348 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS
));
6349 winreg_set_printer_dataex(mem_ctx
,
6353 SPOOL_DSSPOOLER_KEY
,
6354 SPOOL_REG_PRINTKEEPPRINTEDJOBS
,
6359 switch (printer
->attributes
& 0x3) {
6361 spooling
= SPOOL_REGVAL_PRINTWHILESPOOLING
;
6364 spooling
= SPOOL_REGVAL_PRINTAFTERSPOOLED
;
6367 spooling
= SPOOL_REGVAL_PRINTDIRECT
;
6370 spooling
= "unknown";
6372 push_reg_sz(mem_ctx
, &buffer
, spooling
);
6373 winreg_set_printer_dataex(mem_ctx
,
6377 SPOOL_DSSPOOLER_KEY
,
6378 SPOOL_REG_PRINTSPOOLING
,
6384 push_reg_sz(mem_ctx
, &buffer
, global_myname());
6385 winreg_set_printer_dataex(mem_ctx
,
6389 SPOOL_DSSPOOLER_KEY
,
6390 SPOOL_REG_SHORTSERVERNAME
,
6395 dnsdomname
= get_mydnsfullname();
6396 if (dnsdomname
!= NULL
&& dnsdomname
[0] != '\0') {
6397 longname
= talloc_strdup(mem_ctx
, dnsdomname
);
6399 longname
= talloc_strdup(mem_ctx
, global_myname());
6401 if (longname
== NULL
) {
6402 result
= WERR_NOMEM
;
6406 push_reg_sz(mem_ctx
, &buffer
, longname
);
6407 winreg_set_printer_dataex(mem_ctx
,
6411 SPOOL_DSSPOOLER_KEY
,
6412 SPOOL_REG_SERVERNAME
,
6417 uncname
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s",
6418 global_myname(), printer
->sharename
);
6419 push_reg_sz(mem_ctx
, &buffer
, uncname
);
6420 winreg_set_printer_dataex(mem_ctx
,
6424 SPOOL_DSSPOOLER_KEY
,
6434 /********************************************************************
6435 * Called by spoolss_api_setprinter
6436 * when updating a printer description.
6437 ********************************************************************/
6439 static WERROR
update_printer(struct pipes_struct
*p
,
6440 struct policy_handle
*handle
,
6441 struct spoolss_SetPrinterInfoCtr
*info_ctr
,
6442 struct spoolss_DeviceMode
*devmode
)
6444 uint32_t printer_mask
= SPOOLSS_PRINTER_INFO_ALL
;
6445 struct spoolss_SetPrinterInfo2
*printer
= info_ctr
->info
.info2
;
6446 struct spoolss_PrinterInfo2
*old_printer
;
6447 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, handle
);
6449 WERROR result
= WERR_OK
;
6450 TALLOC_CTX
*tmp_ctx
;
6452 DEBUG(8,("update_printer\n"));
6454 tmp_ctx
= talloc_new(p
->mem_ctx
);
6455 if (tmp_ctx
== NULL
) {
6460 result
= WERR_BADFID
;
6464 if (!get_printer_snum(p
, handle
, &snum
, NULL
)) {
6465 result
= WERR_BADFID
;
6469 result
= winreg_get_printer(tmp_ctx
,
6470 get_server_info_system(),
6472 lp_const_servicename(snum
),
6474 if (!W_ERROR_IS_OK(result
)) {
6475 result
= WERR_BADFID
;
6479 /* Do sanity check on the requested changes for Samba */
6480 if (!check_printer_ok(tmp_ctx
, printer
, snum
)) {
6481 result
= WERR_INVALID_PARAM
;
6485 /* FIXME!!! If the driver has changed we really should verify that
6486 it is installed before doing much else --jerry */
6488 /* Check calling user has permission to update printer description */
6489 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
6490 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6491 result
= WERR_ACCESS_DENIED
;
6495 /* Call addprinter hook */
6496 /* Check changes to see if this is really needed */
6498 if (*lp_addprinter_cmd() &&
6499 (!strequal(printer
->drivername
, old_printer
->drivername
) ||
6500 !strequal(printer
->comment
, old_printer
->comment
) ||
6501 !strequal(printer
->portname
, old_printer
->portname
) ||
6502 !strequal(printer
->location
, old_printer
->location
)) )
6504 /* add_printer_hook() will call reload_services() */
6505 if (!add_printer_hook(tmp_ctx
, p
->server_info
->ptok
,
6506 printer
, p
->client_id
->addr
,
6508 result
= WERR_ACCESS_DENIED
;
6513 update_dsspooler(tmp_ctx
,
6514 get_server_info_system(),
6520 printer_mask
&= ~SPOOLSS_PRINTER_INFO_SECDESC
;
6522 if (devmode
== NULL
) {
6523 printer_mask
&= ~SPOOLSS_PRINTER_INFO_DEVMODE
;
6525 result
= winreg_update_printer(tmp_ctx
,
6526 get_server_info_system(),
6535 talloc_free(tmp_ctx
);
6540 /****************************************************************************
6541 ****************************************************************************/
6542 static WERROR
publish_or_unpublish_printer(struct pipes_struct
*p
,
6543 struct policy_handle
*handle
,
6544 struct spoolss_SetPrinterInfo7
*info7
)
6547 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
6550 struct printer_handle
*Printer
;
6552 if ( lp_security() != SEC_ADS
) {
6553 return WERR_UNKNOWN_LEVEL
;
6556 Printer
= find_printer_index_by_hnd(p
, handle
);
6558 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7
->action
));
6563 if (!get_printer_snum(p
, handle
, &snum
, NULL
))
6566 result
= winreg_get_printer(p
->mem_ctx
,
6567 get_server_info_system(),
6569 lp_servicename(snum
),
6571 if (!W_ERROR_IS_OK(result
)) {
6575 nt_printer_publish(pinfo2
,
6576 get_server_info_system(),
6581 TALLOC_FREE(pinfo2
);
6584 return WERR_UNKNOWN_LEVEL
;
6588 /********************************************************************
6589 ********************************************************************/
6591 static WERROR
update_printer_devmode(struct pipes_struct
*p
,
6592 struct policy_handle
*handle
,
6593 struct spoolss_DeviceMode
*devmode
)
6596 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, handle
);
6597 uint32_t info2_mask
= SPOOLSS_PRINTER_INFO_DEVMODE
;
6599 DEBUG(8,("update_printer_devmode\n"));
6605 if (!get_printer_snum(p
, handle
, &snum
, NULL
)) {
6609 /* Check calling user has permission to update printer description */
6610 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
6611 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6612 return WERR_ACCESS_DENIED
;
6615 return winreg_update_printer(p
->mem_ctx
,
6616 get_server_info_system(),
6618 lp_const_servicename(snum
),
6626 /****************************************************************
6628 ****************************************************************/
6630 WERROR
_spoolss_SetPrinter(struct pipes_struct
*p
,
6631 struct spoolss_SetPrinter
*r
)
6635 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
6638 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6639 OUR_HANDLE(r
->in
.handle
)));
6643 /* check the level */
6644 switch (r
->in
.info_ctr
->level
) {
6646 return control_printer(r
->in
.handle
, r
->in
.command
, p
);
6648 result
= update_printer(p
, r
->in
.handle
,
6650 r
->in
.devmode_ctr
->devmode
);
6651 if (!W_ERROR_IS_OK(result
))
6653 if (r
->in
.secdesc_ctr
->sd
)
6654 result
= update_printer_sec(r
->in
.handle
, p
,
6658 return update_printer_sec(r
->in
.handle
, p
,
6661 return publish_or_unpublish_printer(p
, r
->in
.handle
,
6662 r
->in
.info_ctr
->info
.info7
);
6664 return update_printer_devmode(p
, r
->in
.handle
,
6665 r
->in
.devmode_ctr
->devmode
);
6667 return WERR_UNKNOWN_LEVEL
;
6671 /****************************************************************
6672 _spoolss_FindClosePrinterNotify
6673 ****************************************************************/
6675 WERROR
_spoolss_FindClosePrinterNotify(struct pipes_struct
*p
,
6676 struct spoolss_FindClosePrinterNotify
*r
)
6678 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
6681 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6682 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r
->in
.handle
)));
6686 if (Printer
->notify
.cli_chan
!= NULL
&&
6687 Printer
->notify
.cli_chan
->active_connections
> 0) {
6690 if (Printer
->printer_type
== SPLHND_PRINTER
) {
6691 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
6696 srv_spoolss_replycloseprinter(snum
, Printer
);
6699 Printer
->notify
.flags
=0;
6700 Printer
->notify
.options
=0;
6701 Printer
->notify
.localmachine
[0]='\0';
6702 Printer
->notify
.printerlocal
=0;
6703 TALLOC_FREE(Printer
->notify
.option
);
6708 /****************************************************************
6710 ****************************************************************/
6712 WERROR
_spoolss_AddJob(struct pipes_struct
*p
,
6713 struct spoolss_AddJob
*r
)
6715 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
6716 return WERR_INVALID_PARAM
;
6719 /* this is what a NT server returns for AddJob. AddJob must fail on
6720 * non-local printers */
6722 if (r
->in
.level
!= 1) {
6723 return WERR_UNKNOWN_LEVEL
;
6726 return WERR_INVALID_PARAM
;
6729 /****************************************************************************
6731 ****************************************************************************/
6733 static WERROR
fill_job_info1(TALLOC_CTX
*mem_ctx
,
6734 struct spoolss_JobInfo1
*r
,
6735 const print_queue_struct
*queue
,
6736 int position
, int snum
,
6737 struct spoolss_PrinterInfo2
*pinfo2
)
6741 t
= gmtime(&queue
->time
);
6743 r
->job_id
= queue
->job
;
6745 r
->printer_name
= talloc_strdup(mem_ctx
, lp_servicename(snum
));
6746 W_ERROR_HAVE_NO_MEMORY(r
->printer_name
);
6747 r
->server_name
= talloc_strdup(mem_ctx
, pinfo2
->servername
);
6748 W_ERROR_HAVE_NO_MEMORY(r
->server_name
);
6749 r
->user_name
= talloc_strdup(mem_ctx
, queue
->fs_user
);
6750 W_ERROR_HAVE_NO_MEMORY(r
->user_name
);
6751 r
->document_name
= talloc_strdup(mem_ctx
, queue
->fs_file
);
6752 W_ERROR_HAVE_NO_MEMORY(r
->document_name
);
6753 r
->data_type
= talloc_strdup(mem_ctx
, "RAW");
6754 W_ERROR_HAVE_NO_MEMORY(r
->data_type
);
6755 r
->text_status
= talloc_strdup(mem_ctx
, "");
6756 W_ERROR_HAVE_NO_MEMORY(r
->text_status
);
6758 r
->status
= nt_printj_status(queue
->status
);
6759 r
->priority
= queue
->priority
;
6760 r
->position
= position
;
6761 r
->total_pages
= queue
->page_count
;
6762 r
->pages_printed
= 0; /* ??? */
6764 init_systemtime(&r
->submitted
, t
);
6769 /****************************************************************************
6771 ****************************************************************************/
6773 static WERROR
fill_job_info2(TALLOC_CTX
*mem_ctx
,
6774 struct spoolss_JobInfo2
*r
,
6775 const print_queue_struct
*queue
,
6776 int position
, int snum
,
6777 struct spoolss_PrinterInfo2
*pinfo2
,
6778 struct spoolss_DeviceMode
*devmode
)
6782 t
= gmtime(&queue
->time
);
6784 r
->job_id
= queue
->job
;
6786 r
->printer_name
= talloc_strdup(mem_ctx
, lp_servicename(snum
));
6787 W_ERROR_HAVE_NO_MEMORY(r
->printer_name
);
6788 r
->server_name
= talloc_strdup(mem_ctx
, pinfo2
->servername
);
6789 W_ERROR_HAVE_NO_MEMORY(r
->server_name
);
6790 r
->user_name
= talloc_strdup(mem_ctx
, queue
->fs_user
);
6791 W_ERROR_HAVE_NO_MEMORY(r
->user_name
);
6792 r
->document_name
= talloc_strdup(mem_ctx
, queue
->fs_file
);
6793 W_ERROR_HAVE_NO_MEMORY(r
->document_name
);
6794 r
->notify_name
= talloc_strdup(mem_ctx
, queue
->fs_user
);
6795 W_ERROR_HAVE_NO_MEMORY(r
->notify_name
);
6796 r
->data_type
= talloc_strdup(mem_ctx
, "RAW");
6797 W_ERROR_HAVE_NO_MEMORY(r
->data_type
);
6798 r
->print_processor
= talloc_strdup(mem_ctx
, "winprint");
6799 W_ERROR_HAVE_NO_MEMORY(r
->print_processor
);
6800 r
->parameters
= talloc_strdup(mem_ctx
, "");
6801 W_ERROR_HAVE_NO_MEMORY(r
->parameters
);
6802 r
->driver_name
= talloc_strdup(mem_ctx
, pinfo2
->drivername
);
6803 W_ERROR_HAVE_NO_MEMORY(r
->driver_name
);
6805 r
->devmode
= devmode
;
6807 r
->text_status
= talloc_strdup(mem_ctx
, "");
6808 W_ERROR_HAVE_NO_MEMORY(r
->text_status
);
6812 r
->status
= nt_printj_status(queue
->status
);
6813 r
->priority
= queue
->priority
;
6814 r
->position
= position
;
6817 r
->total_pages
= queue
->page_count
;
6818 r
->size
= queue
->size
;
6819 init_systemtime(&r
->submitted
, t
);
6821 r
->pages_printed
= 0; /* ??? */
6826 /****************************************************************************
6828 ****************************************************************************/
6830 static WERROR
fill_job_info3(TALLOC_CTX
*mem_ctx
,
6831 struct spoolss_JobInfo3
*r
,
6832 const print_queue_struct
*queue
,
6833 const print_queue_struct
*next_queue
,
6834 int position
, int snum
,
6835 struct spoolss_PrinterInfo2
*pinfo2
)
6837 r
->job_id
= queue
->job
;
6840 r
->next_job_id
= next_queue
->job
;
6847 /****************************************************************************
6848 Enumjobs at level 1.
6849 ****************************************************************************/
6851 static WERROR
enumjobs_level1(TALLOC_CTX
*mem_ctx
,
6852 const print_queue_struct
*queue
,
6853 uint32_t num_queues
, int snum
,
6854 struct spoolss_PrinterInfo2
*pinfo2
,
6855 union spoolss_JobInfo
**info_p
,
6858 union spoolss_JobInfo
*info
;
6860 WERROR result
= WERR_OK
;
6862 info
= TALLOC_ARRAY(mem_ctx
, union spoolss_JobInfo
, num_queues
);
6863 W_ERROR_HAVE_NO_MEMORY(info
);
6865 *count
= num_queues
;
6867 for (i
=0; i
<*count
; i
++) {
6868 result
= fill_job_info1(info
,
6874 if (!W_ERROR_IS_OK(result
)) {
6880 if (!W_ERROR_IS_OK(result
)) {
6891 /****************************************************************************
6892 Enumjobs at level 2.
6893 ****************************************************************************/
6895 static WERROR
enumjobs_level2(TALLOC_CTX
*mem_ctx
,
6896 const print_queue_struct
*queue
,
6897 uint32_t num_queues
, int snum
,
6898 struct spoolss_PrinterInfo2
*pinfo2
,
6899 union spoolss_JobInfo
**info_p
,
6902 union spoolss_JobInfo
*info
;
6904 WERROR result
= WERR_OK
;
6906 info
= TALLOC_ARRAY(mem_ctx
, union spoolss_JobInfo
, num_queues
);
6907 W_ERROR_HAVE_NO_MEMORY(info
);
6909 *count
= num_queues
;
6911 for (i
=0; i
<*count
; i
++) {
6912 struct spoolss_DeviceMode
*devmode
;
6914 result
= spoolss_create_default_devmode(info
,
6915 pinfo2
->printername
,
6917 if (!W_ERROR_IS_OK(result
)) {
6918 DEBUG(3, ("Can't proceed w/o a devmode!"));
6922 result
= fill_job_info2(info
,
6929 if (!W_ERROR_IS_OK(result
)) {
6935 if (!W_ERROR_IS_OK(result
)) {
6946 /****************************************************************************
6947 Enumjobs at level 3.
6948 ****************************************************************************/
6950 static WERROR
enumjobs_level3(TALLOC_CTX
*mem_ctx
,
6951 const print_queue_struct
*queue
,
6952 uint32_t num_queues
, int snum
,
6953 struct spoolss_PrinterInfo2
*pinfo2
,
6954 union spoolss_JobInfo
**info_p
,
6957 union spoolss_JobInfo
*info
;
6959 WERROR result
= WERR_OK
;
6961 info
= TALLOC_ARRAY(mem_ctx
, union spoolss_JobInfo
, num_queues
);
6962 W_ERROR_HAVE_NO_MEMORY(info
);
6964 *count
= num_queues
;
6966 for (i
=0; i
<*count
; i
++) {
6967 const print_queue_struct
*next_queue
= NULL
;
6970 next_queue
= &queue
[i
+1];
6973 result
= fill_job_info3(info
,
6980 if (!W_ERROR_IS_OK(result
)) {
6986 if (!W_ERROR_IS_OK(result
)) {
6997 /****************************************************************
6999 ****************************************************************/
7001 WERROR
_spoolss_EnumJobs(struct pipes_struct
*p
,
7002 struct spoolss_EnumJobs
*r
)
7005 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
7007 print_status_struct prt_status
;
7008 print_queue_struct
*queue
= NULL
;
7011 /* that's an [in out] buffer */
7013 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
7014 return WERR_INVALID_PARAM
;
7017 DEBUG(4,("_spoolss_EnumJobs\n"));
7021 *r
->out
.info
= NULL
;
7023 /* lookup the printer snum and tdb entry */
7025 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
7029 result
= winreg_get_printer(p
->mem_ctx
,
7030 get_server_info_system(),
7032 lp_const_servicename(snum
),
7034 if (!W_ERROR_IS_OK(result
)) {
7038 count
= print_queue_status(p
->msg_ctx
, snum
, &queue
, &prt_status
);
7039 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
7040 count
, prt_status
.status
, prt_status
.message
));
7044 TALLOC_FREE(pinfo2
);
7048 switch (r
->in
.level
) {
7050 result
= enumjobs_level1(p
->mem_ctx
, queue
, count
, snum
,
7051 pinfo2
, r
->out
.info
, r
->out
.count
);
7054 result
= enumjobs_level2(p
->mem_ctx
, queue
, count
, snum
,
7055 pinfo2
, r
->out
.info
, r
->out
.count
);
7058 result
= enumjobs_level3(p
->mem_ctx
, queue
, count
, snum
,
7059 pinfo2
, r
->out
.info
, r
->out
.count
);
7062 result
= WERR_UNKNOWN_LEVEL
;
7067 TALLOC_FREE(pinfo2
);
7069 if (!W_ERROR_IS_OK(result
)) {
7073 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
7075 *r
->out
.info
, r
->in
.level
,
7077 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
7078 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
7080 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
7083 /****************************************************************
7084 _spoolss_ScheduleJob
7085 ****************************************************************/
7087 WERROR
_spoolss_ScheduleJob(struct pipes_struct
*p
,
7088 struct spoolss_ScheduleJob
*r
)
7093 /****************************************************************
7094 ****************************************************************/
7096 static WERROR
spoolss_setjob_1(TALLOC_CTX
*mem_ctx
,
7097 struct messaging_context
*msg_ctx
,
7098 const char *printer_name
,
7100 struct spoolss_SetJobInfo1
*r
)
7104 if (!print_job_get_name(mem_ctx
, printer_name
, job_id
, &old_doc_name
)) {
7108 if (strequal(old_doc_name
, r
->document_name
)) {
7112 if (!print_job_set_name(server_event_context(), msg_ctx
,
7113 printer_name
, job_id
, r
->document_name
)) {
7120 /****************************************************************
7122 ****************************************************************/
7124 WERROR
_spoolss_SetJob(struct pipes_struct
*p
,
7125 struct spoolss_SetJob
*r
)
7127 const struct auth_serversupplied_info
*server_info
= p
->server_info
;
7129 WERROR errcode
= WERR_BADFUNC
;
7131 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
7135 if (!print_job_exists(lp_const_servicename(snum
), r
->in
.job_id
)) {
7136 return WERR_INVALID_PRINTER_NAME
;
7139 switch (r
->in
.command
) {
7140 case SPOOLSS_JOB_CONTROL_CANCEL
:
7141 case SPOOLSS_JOB_CONTROL_DELETE
:
7142 errcode
= print_job_delete(server_info
, p
->msg_ctx
,
7143 snum
, r
->in
.job_id
);
7144 if (W_ERROR_EQUAL(errcode
, WERR_PRINTER_HAS_JOBS_QUEUED
)) {
7148 case SPOOLSS_JOB_CONTROL_PAUSE
:
7149 if (print_job_pause(server_info
, p
->msg_ctx
,
7150 snum
, r
->in
.job_id
, &errcode
)) {
7154 case SPOOLSS_JOB_CONTROL_RESTART
:
7155 case SPOOLSS_JOB_CONTROL_RESUME
:
7156 if (print_job_resume(server_info
, p
->msg_ctx
,
7157 snum
, r
->in
.job_id
, &errcode
)) {
7165 return WERR_UNKNOWN_LEVEL
;
7168 if (!W_ERROR_IS_OK(errcode
)) {
7172 if (r
->in
.ctr
== NULL
) {
7176 switch (r
->in
.ctr
->level
) {
7178 errcode
= spoolss_setjob_1(p
->mem_ctx
, p
->msg_ctx
,
7179 lp_const_servicename(snum
),
7181 r
->in
.ctr
->info
.info1
);
7187 return WERR_UNKNOWN_LEVEL
;
7193 /****************************************************************************
7194 Enumerates all printer drivers by level and architecture.
7195 ****************************************************************************/
7197 static WERROR
enumprinterdrivers_level_by_architecture(TALLOC_CTX
*mem_ctx
,
7198 const struct auth_serversupplied_info
*server_info
,
7199 struct messaging_context
*msg_ctx
,
7200 const char *servername
,
7201 const char *architecture
,
7203 union spoolss_DriverInfo
**info_p
,
7208 struct spoolss_DriverInfo8
*driver
;
7209 union spoolss_DriverInfo
*info
= NULL
;
7211 WERROR result
= WERR_OK
;
7212 uint32_t num_drivers
;
7213 const char **drivers
;
7218 for (version
=0; version
<DRIVER_MAX_VERSION
; version
++) {
7219 result
= winreg_get_driver_list(mem_ctx
, server_info
, msg_ctx
,
7220 architecture
, version
,
7221 &num_drivers
, &drivers
);
7222 if (!W_ERROR_IS_OK(result
)) {
7225 DEBUG(4, ("we have:[%d] drivers in environment"
7226 " [%s] and version [%d]\n",
7227 num_drivers
, architecture
, version
));
7229 if (num_drivers
!= 0) {
7230 info
= TALLOC_REALLOC_ARRAY(mem_ctx
, info
,
7231 union spoolss_DriverInfo
,
7232 count
+ num_drivers
);
7234 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
7235 "failed to enlarge driver info buffer!\n"));
7236 result
= WERR_NOMEM
;
7241 for (i
= 0; i
< num_drivers
; i
++) {
7242 DEBUG(5, ("\tdriver: [%s]\n", drivers
[i
]));
7244 result
= winreg_get_driver(mem_ctx
, server_info
,
7246 architecture
, drivers
[i
],
7248 if (!W_ERROR_IS_OK(result
)) {
7254 result
= fill_printer_driver_info1(info
, &info
[count
+i
].info1
,
7255 driver
, servername
);
7258 result
= fill_printer_driver_info2(info
, &info
[count
+i
].info2
,
7259 driver
, servername
);
7262 result
= fill_printer_driver_info3(info
, &info
[count
+i
].info3
,
7263 driver
, servername
);
7266 result
= fill_printer_driver_info4(info
, &info
[count
+i
].info4
,
7267 driver
, servername
);
7270 result
= fill_printer_driver_info5(info
, &info
[count
+i
].info5
,
7271 driver
, servername
);
7274 result
= fill_printer_driver_info6(info
, &info
[count
+i
].info6
,
7275 driver
, servername
);
7278 result
= fill_printer_driver_info8(info
, &info
[count
+i
].info8
,
7279 driver
, servername
);
7282 result
= WERR_UNKNOWN_LEVEL
;
7286 TALLOC_FREE(driver
);
7288 if (!W_ERROR_IS_OK(result
)) {
7293 count
+= num_drivers
;
7294 TALLOC_FREE(drivers
);
7298 TALLOC_FREE(drivers
);
7300 if (!W_ERROR_IS_OK(result
)) {
7311 /****************************************************************************
7312 Enumerates all printer drivers by level.
7313 ****************************************************************************/
7315 static WERROR
enumprinterdrivers_level(TALLOC_CTX
*mem_ctx
,
7316 const struct auth_serversupplied_info
*server_info
,
7317 struct messaging_context
*msg_ctx
,
7318 const char *servername
,
7319 const char *architecture
,
7321 union spoolss_DriverInfo
**info_p
,
7325 WERROR result
= WERR_OK
;
7327 if (strequal(architecture
, SPOOLSS_ARCHITECTURE_ALL
)) {
7329 for (a
=0; archi_table
[a
].long_archi
!= NULL
; a
++) {
7331 union spoolss_DriverInfo
*info
= NULL
;
7334 result
= enumprinterdrivers_level_by_architecture(mem_ctx
,
7338 archi_table
[a
].long_archi
,
7342 if (!W_ERROR_IS_OK(result
)) {
7346 for (i
=0; i
< count
; i
++) {
7347 ADD_TO_ARRAY(mem_ctx
, union spoolss_DriverInfo
,
7348 info
[i
], info_p
, count_p
);
7355 return enumprinterdrivers_level_by_architecture(mem_ctx
,
7365 /****************************************************************
7366 _spoolss_EnumPrinterDrivers
7367 ****************************************************************/
7369 WERROR
_spoolss_EnumPrinterDrivers(struct pipes_struct
*p
,
7370 struct spoolss_EnumPrinterDrivers
*r
)
7372 const char *cservername
;
7375 /* that's an [in out] buffer */
7377 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
7378 return WERR_INVALID_PARAM
;
7381 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
7385 *r
->out
.info
= NULL
;
7387 cservername
= canon_servername(r
->in
.server
);
7389 if (!is_myname_or_ipaddr(cservername
)) {
7390 return WERR_UNKNOWN_PRINTER_DRIVER
;
7393 result
= enumprinterdrivers_level(p
->mem_ctx
,
7394 get_server_info_system(),
7401 if (!W_ERROR_IS_OK(result
)) {
7405 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
7406 spoolss_EnumPrinterDrivers
,
7407 *r
->out
.info
, r
->in
.level
,
7409 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
7410 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
7412 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
7415 /****************************************************************
7417 ****************************************************************/
7419 WERROR
_spoolss_EnumForms(struct pipes_struct
*p
,
7420 struct spoolss_EnumForms
*r
)
7426 *r
->out
.info
= NULL
;
7428 /* that's an [in out] buffer */
7430 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0) ) {
7431 return WERR_INVALID_PARAM
;
7434 DEBUG(4,("_spoolss_EnumForms\n"));
7435 DEBUGADD(5,("Offered buffer size [%d]\n", r
->in
.offered
));
7436 DEBUGADD(5,("Info level [%d]\n", r
->in
.level
));
7438 switch (r
->in
.level
) {
7440 result
= winreg_printer_enumforms1(p
->mem_ctx
,
7441 get_server_info_system(),
7447 result
= WERR_UNKNOWN_LEVEL
;
7451 if (!W_ERROR_IS_OK(result
)) {
7455 if (*r
->out
.count
== 0) {
7456 return WERR_NO_MORE_ITEMS
;
7459 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
7461 *r
->out
.info
, r
->in
.level
,
7463 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
7464 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
7466 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
7469 /****************************************************************
7471 ****************************************************************/
7473 WERROR
_spoolss_GetForm(struct pipes_struct
*p
,
7474 struct spoolss_GetForm
*r
)
7478 /* that's an [in out] buffer */
7480 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
7481 return WERR_INVALID_PARAM
;
7484 DEBUG(4,("_spoolss_GetForm\n"));
7485 DEBUGADD(5,("Offered buffer size [%d]\n", r
->in
.offered
));
7486 DEBUGADD(5,("Info level [%d]\n", r
->in
.level
));
7488 switch (r
->in
.level
) {
7490 result
= winreg_printer_getform1(p
->mem_ctx
,
7491 get_server_info_system(),
7494 &r
->out
.info
->info1
);
7497 result
= WERR_UNKNOWN_LEVEL
;
7501 if (!W_ERROR_IS_OK(result
)) {
7502 TALLOC_FREE(r
->out
.info
);
7506 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_FormInfo
,
7507 r
->out
.info
, r
->in
.level
);
7508 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
7510 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
7513 /****************************************************************************
7514 ****************************************************************************/
7516 static WERROR
fill_port_1(TALLOC_CTX
*mem_ctx
,
7517 struct spoolss_PortInfo1
*r
,
7520 r
->port_name
= talloc_strdup(mem_ctx
, name
);
7521 W_ERROR_HAVE_NO_MEMORY(r
->port_name
);
7526 /****************************************************************************
7527 TODO: This probably needs distinguish between TCP/IP and Local ports
7529 ****************************************************************************/
7531 static WERROR
fill_port_2(TALLOC_CTX
*mem_ctx
,
7532 struct spoolss_PortInfo2
*r
,
7535 r
->port_name
= talloc_strdup(mem_ctx
, name
);
7536 W_ERROR_HAVE_NO_MEMORY(r
->port_name
);
7538 r
->monitor_name
= talloc_strdup(mem_ctx
, "Local Monitor");
7539 W_ERROR_HAVE_NO_MEMORY(r
->monitor_name
);
7541 r
->description
= talloc_strdup(mem_ctx
, SPL_LOCAL_PORT
);
7542 W_ERROR_HAVE_NO_MEMORY(r
->description
);
7544 r
->port_type
= SPOOLSS_PORT_TYPE_WRITE
;
7551 /****************************************************************************
7552 wrapper around the enumer ports command
7553 ****************************************************************************/
7555 static WERROR
enumports_hook(TALLOC_CTX
*ctx
, int *count
, char ***lines
)
7557 char *cmd
= lp_enumports_cmd();
7558 char **qlines
= NULL
;
7559 char *command
= NULL
;
7567 /* if no hook then just fill in the default port */
7570 if (!(qlines
= TALLOC_ARRAY( NULL
, char*, 2 ))) {
7573 if (!(qlines
[0] = talloc_strdup(qlines
, SAMBA_PRINTER_PORT_NAME
))) {
7574 TALLOC_FREE(qlines
);
7581 /* we have a valid enumport command */
7583 command
= talloc_asprintf(ctx
, "%s \"%d\"", cmd
, 1);
7588 DEBUG(10,("Running [%s]\n", command
));
7589 ret
= smbrun(command
, &fd
);
7590 DEBUG(10,("Returned [%d]\n", ret
));
7591 TALLOC_FREE(command
);
7596 return WERR_ACCESS_DENIED
;
7600 qlines
= fd_lines_load(fd
, &numlines
, 0, NULL
);
7601 DEBUGADD(10,("Lines returned = [%d]\n", numlines
));
7611 /****************************************************************************
7613 ****************************************************************************/
7615 static WERROR
enumports_level_1(TALLOC_CTX
*mem_ctx
,
7616 union spoolss_PortInfo
**info_p
,
7619 union spoolss_PortInfo
*info
= NULL
;
7621 WERROR result
= WERR_OK
;
7622 char **qlines
= NULL
;
7625 result
= enumports_hook(talloc_tos(), &numlines
, &qlines
);
7626 if (!W_ERROR_IS_OK(result
)) {
7631 info
= TALLOC_ARRAY(mem_ctx
, union spoolss_PortInfo
, numlines
);
7633 DEBUG(10,("Returning WERR_NOMEM\n"));
7634 result
= WERR_NOMEM
;
7638 for (i
=0; i
<numlines
; i
++) {
7639 DEBUG(6,("Filling port number [%d] with port [%s]\n", i
, qlines
[i
]));
7640 result
= fill_port_1(info
, &info
[i
].info1
, qlines
[i
]);
7641 if (!W_ERROR_IS_OK(result
)) {
7646 TALLOC_FREE(qlines
);
7649 if (!W_ERROR_IS_OK(result
)) {
7651 TALLOC_FREE(qlines
);
7663 /****************************************************************************
7665 ****************************************************************************/
7667 static WERROR
enumports_level_2(TALLOC_CTX
*mem_ctx
,
7668 union spoolss_PortInfo
**info_p
,
7671 union spoolss_PortInfo
*info
= NULL
;
7673 WERROR result
= WERR_OK
;
7674 char **qlines
= NULL
;
7677 result
= enumports_hook(talloc_tos(), &numlines
, &qlines
);
7678 if (!W_ERROR_IS_OK(result
)) {
7683 info
= TALLOC_ARRAY(mem_ctx
, union spoolss_PortInfo
, numlines
);
7685 DEBUG(10,("Returning WERR_NOMEM\n"));
7686 result
= WERR_NOMEM
;
7690 for (i
=0; i
<numlines
; i
++) {
7691 DEBUG(6,("Filling port number [%d] with port [%s]\n", i
, qlines
[i
]));
7692 result
= fill_port_2(info
, &info
[i
].info2
, qlines
[i
]);
7693 if (!W_ERROR_IS_OK(result
)) {
7698 TALLOC_FREE(qlines
);
7701 if (!W_ERROR_IS_OK(result
)) {
7703 TALLOC_FREE(qlines
);
7715 /****************************************************************
7717 ****************************************************************/
7719 WERROR
_spoolss_EnumPorts(struct pipes_struct
*p
,
7720 struct spoolss_EnumPorts
*r
)
7724 /* that's an [in out] buffer */
7726 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
7727 return WERR_INVALID_PARAM
;
7730 DEBUG(4,("_spoolss_EnumPorts\n"));
7734 *r
->out
.info
= NULL
;
7736 switch (r
->in
.level
) {
7738 result
= enumports_level_1(p
->mem_ctx
, r
->out
.info
,
7742 result
= enumports_level_2(p
->mem_ctx
, r
->out
.info
,
7746 return WERR_UNKNOWN_LEVEL
;
7749 if (!W_ERROR_IS_OK(result
)) {
7753 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
7755 *r
->out
.info
, r
->in
.level
,
7757 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
7758 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
7760 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
7763 /****************************************************************************
7764 ****************************************************************************/
7766 static WERROR
spoolss_addprinterex_level_2(struct pipes_struct
*p
,
7768 struct spoolss_SetPrinterInfoCtr
*info_ctr
,
7769 struct spoolss_DeviceMode
*devmode
,
7770 struct security_descriptor
*secdesc
,
7771 struct spoolss_UserLevelCtr
*user_ctr
,
7772 struct policy_handle
*handle
)
7774 struct spoolss_SetPrinterInfo2
*info2
= info_ctr
->info
.info2
;
7775 uint32_t info2_mask
= SPOOLSS_PRINTER_INFO_ALL
;
7777 WERROR err
= WERR_OK
;
7779 /* samba does not have a concept of local, non-shared printers yet, so
7780 * make sure we always setup sharename - gd */
7781 if ((info2
->sharename
== NULL
|| info2
->sharename
[0] == '\0') &&
7782 (info2
->printername
!= NULL
&& info2
->printername
[0] != '\0')) {
7783 DEBUG(5, ("spoolss_addprinterex_level_2: "
7784 "no sharename has been set, setting printername %s as sharename\n",
7785 info2
->printername
));
7786 info2
->sharename
= info2
->printername
;
7789 /* check to see if the printer already exists */
7790 if ((snum
= print_queue_snum(info2
->sharename
)) != -1) {
7791 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7793 return WERR_PRINTER_ALREADY_EXISTS
;
7796 if (!lp_force_printername(GLOBAL_SECTION_SNUM
)) {
7797 if ((snum
= print_queue_snum(info2
->printername
)) != -1) {
7798 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7799 info2
->printername
));
7800 return WERR_PRINTER_ALREADY_EXISTS
;
7804 /* validate printer info struct */
7805 if (!info2
->printername
|| strlen(info2
->printername
) == 0) {
7806 return WERR_INVALID_PRINTER_NAME
;
7808 if (!info2
->portname
|| strlen(info2
->portname
) == 0) {
7809 return WERR_UNKNOWN_PORT
;
7811 if (!info2
->drivername
|| strlen(info2
->drivername
) == 0) {
7812 return WERR_UNKNOWN_PRINTER_DRIVER
;
7814 if (!info2
->printprocessor
|| strlen(info2
->printprocessor
) == 0) {
7815 return WERR_UNKNOWN_PRINTPROCESSOR
;
7818 /* FIXME!!! smbd should check to see if the driver is installed before
7819 trying to add a printer like this --jerry */
7821 if (*lp_addprinter_cmd() ) {
7822 if ( !add_printer_hook(p
->mem_ctx
, p
->server_info
->ptok
,
7823 info2
, p
->client_id
->addr
,
7825 return WERR_ACCESS_DENIED
;
7828 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no"
7829 "smb.conf parameter \"addprinter command\" is defined. This"
7830 "parameter must exist for this call to succeed\n",
7831 info2
->sharename
));
7834 if ((snum
= print_queue_snum(info2
->sharename
)) == -1) {
7835 return WERR_ACCESS_DENIED
;
7838 /* you must be a printer admin to add a new printer */
7839 if (!print_access_check(p
->server_info
,
7842 PRINTER_ACCESS_ADMINISTER
)) {
7843 return WERR_ACCESS_DENIED
;
7847 * Do sanity check on the requested changes for Samba.
7850 if (!check_printer_ok(p
->mem_ctx
, info2
, snum
)) {
7851 return WERR_INVALID_PARAM
;
7854 if (devmode
== NULL
) {
7855 info2_mask
= ~SPOOLSS_PRINTER_INFO_DEVMODE
;
7858 update_dsspooler(p
->mem_ctx
,
7859 get_server_info_system(),
7865 err
= winreg_update_printer(p
->mem_ctx
,
7866 get_server_info_system(),
7873 if (!W_ERROR_IS_OK(err
)) {
7877 err
= open_printer_hnd(p
, handle
, info2
->printername
, PRINTER_ACCESS_ADMINISTER
);
7878 if (!W_ERROR_IS_OK(err
)) {
7879 /* Handle open failed - remove addition. */
7880 ZERO_STRUCTP(handle
);
7887 /****************************************************************
7888 _spoolss_AddPrinterEx
7889 ****************************************************************/
7891 WERROR
_spoolss_AddPrinterEx(struct pipes_struct
*p
,
7892 struct spoolss_AddPrinterEx
*r
)
7894 switch (r
->in
.info_ctr
->level
) {
7896 /* we don't handle yet */
7897 /* but I know what to do ... */
7898 return WERR_UNKNOWN_LEVEL
;
7900 return spoolss_addprinterex_level_2(p
, r
->in
.server
,
7902 r
->in
.devmode_ctr
->devmode
,
7903 r
->in
.secdesc_ctr
->sd
,
7904 r
->in
.userlevel_ctr
,
7907 return WERR_UNKNOWN_LEVEL
;
7911 /****************************************************************
7913 ****************************************************************/
7915 WERROR
_spoolss_AddPrinter(struct pipes_struct
*p
,
7916 struct spoolss_AddPrinter
*r
)
7918 struct spoolss_AddPrinterEx a
;
7919 struct spoolss_UserLevelCtr userlevel_ctr
;
7921 ZERO_STRUCT(userlevel_ctr
);
7923 userlevel_ctr
.level
= 1;
7925 a
.in
.server
= r
->in
.server
;
7926 a
.in
.info_ctr
= r
->in
.info_ctr
;
7927 a
.in
.devmode_ctr
= r
->in
.devmode_ctr
;
7928 a
.in
.secdesc_ctr
= r
->in
.secdesc_ctr
;
7929 a
.in
.userlevel_ctr
= &userlevel_ctr
;
7930 a
.out
.handle
= r
->out
.handle
;
7932 return _spoolss_AddPrinterEx(p
, &a
);
7935 /****************************************************************
7936 _spoolss_AddPrinterDriverEx
7937 ****************************************************************/
7939 WERROR
_spoolss_AddPrinterDriverEx(struct pipes_struct
*p
,
7940 struct spoolss_AddPrinterDriverEx
*r
)
7942 WERROR err
= WERR_OK
;
7943 const char *driver_name
= NULL
;
7948 case NDR_SPOOLSS_ADDPRINTERDRIVER
:
7949 fn
= "_spoolss_AddPrinterDriver";
7951 case NDR_SPOOLSS_ADDPRINTERDRIVEREX
:
7952 fn
= "_spoolss_AddPrinterDriverEx";
7955 return WERR_INVALID_PARAM
;
7959 * we only support the semantics of AddPrinterDriver()
7960 * i.e. only copy files that are newer than existing ones
7963 if (r
->in
.flags
== 0) {
7964 return WERR_INVALID_PARAM
;
7967 if (r
->in
.flags
!= APD_COPY_NEW_FILES
) {
7968 return WERR_ACCESS_DENIED
;
7972 if (r
->in
.info_ctr
->level
!= 3 && r
->in
.info_ctr
->level
!= 6) {
7973 /* Clever hack from Martin Zielinski <mz@seh.de>
7974 * to allow downgrade from level 8 (Vista).
7976 DEBUG(0,("%s: level %d not yet implemented\n", fn
,
7977 r
->in
.info_ctr
->level
));
7978 return WERR_UNKNOWN_LEVEL
;
7981 DEBUG(5,("Cleaning driver's information\n"));
7982 err
= clean_up_driver_struct(p
->mem_ctx
, p
, r
->in
.info_ctr
);
7983 if (!W_ERROR_IS_OK(err
))
7986 DEBUG(5,("Moving driver to final destination\n"));
7987 if( !W_ERROR_IS_OK(err
= move_driver_to_download_area(p
, r
->in
.info_ctr
,
7992 err
= winreg_add_driver(p
->mem_ctx
,
7993 get_server_info_system(),
7998 if (!W_ERROR_IS_OK(err
)) {
8003 * I think this is where he DrvUpgradePrinter() hook would be
8004 * be called in a driver's interface DLL on a Windows NT 4.0/2k
8005 * server. Right now, we just need to send ourselves a message
8006 * to update each printer bound to this driver. --jerry
8009 if (!srv_spoolss_drv_upgrade_printer(driver_name
, p
->msg_ctx
)) {
8010 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
8018 /****************************************************************
8019 _spoolss_AddPrinterDriver
8020 ****************************************************************/
8022 WERROR
_spoolss_AddPrinterDriver(struct pipes_struct
*p
,
8023 struct spoolss_AddPrinterDriver
*r
)
8025 struct spoolss_AddPrinterDriverEx a
;
8027 switch (r
->in
.info_ctr
->level
) {
8034 return WERR_UNKNOWN_LEVEL
;
8037 a
.in
.servername
= r
->in
.servername
;
8038 a
.in
.info_ctr
= r
->in
.info_ctr
;
8039 a
.in
.flags
= APD_COPY_NEW_FILES
;
8041 return _spoolss_AddPrinterDriverEx(p
, &a
);
8044 /****************************************************************************
8045 ****************************************************************************/
8047 struct _spoolss_paths
{
8053 enum { SPOOLSS_DRIVER_PATH
, SPOOLSS_PRTPROCS_PATH
};
8055 static const struct _spoolss_paths spoolss_paths
[]= {
8056 { SPOOLSS_DRIVER_PATH
, "print$", "DRIVERS" },
8057 { SPOOLSS_PRTPROCS_PATH
, "prnproc$", "PRTPROCS" }
8060 static WERROR
compose_spoolss_server_path(TALLOC_CTX
*mem_ctx
,
8061 const char *servername
,
8062 const char *environment
,
8066 const char *pservername
= NULL
;
8067 const char *long_archi
= SPOOLSS_ARCHITECTURE_NT_X86
;
8068 const char *short_archi
;
8072 /* environment may be empty */
8073 if (environment
&& strlen(environment
)) {
8074 long_archi
= environment
;
8077 /* servername may be empty */
8078 if (servername
&& strlen(servername
)) {
8079 pservername
= canon_servername(servername
);
8081 if (!is_myname_or_ipaddr(pservername
)) {
8082 return WERR_INVALID_PARAM
;
8086 if (!(short_archi
= get_short_archi(long_archi
))) {
8087 return WERR_INVALID_ENVIRONMENT
;
8090 switch (component
) {
8091 case SPOOLSS_PRTPROCS_PATH
:
8092 case SPOOLSS_DRIVER_PATH
:
8094 *path
= talloc_asprintf(mem_ctx
,
8097 spoolss_paths
[component
].share
,
8100 *path
= talloc_asprintf(mem_ctx
, "%s\\%s\\%s",
8101 SPOOLSS_DEFAULT_SERVER_PATH
,
8102 spoolss_paths
[component
].dir
,
8107 return WERR_INVALID_PARAM
;
8117 /****************************************************************************
8118 ****************************************************************************/
8120 static WERROR
getprinterdriverdir_level_1(TALLOC_CTX
*mem_ctx
,
8121 const char *servername
,
8122 const char *environment
,
8123 struct spoolss_DriverDirectoryInfo1
*r
)
8128 werr
= compose_spoolss_server_path(mem_ctx
,
8131 SPOOLSS_DRIVER_PATH
,
8133 if (!W_ERROR_IS_OK(werr
)) {
8137 DEBUG(4,("printer driver directory: [%s]\n", path
));
8139 r
->directory_name
= path
;
8144 /****************************************************************
8145 _spoolss_GetPrinterDriverDirectory
8146 ****************************************************************/
8148 WERROR
_spoolss_GetPrinterDriverDirectory(struct pipes_struct
*p
,
8149 struct spoolss_GetPrinterDriverDirectory
*r
)
8153 /* that's an [in out] buffer */
8155 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
8156 return WERR_INVALID_PARAM
;
8159 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
8164 /* r->in.level is ignored */
8166 werror
= getprinterdriverdir_level_1(p
->mem_ctx
,
8169 &r
->out
.info
->info1
);
8170 if (!W_ERROR_IS_OK(werror
)) {
8171 TALLOC_FREE(r
->out
.info
);
8175 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo
,
8176 r
->out
.info
, r
->in
.level
);
8177 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
8179 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
8182 /****************************************************************
8183 _spoolss_EnumPrinterData
8184 ****************************************************************/
8186 WERROR
_spoolss_EnumPrinterData(struct pipes_struct
*p
,
8187 struct spoolss_EnumPrinterData
*r
)
8190 struct spoolss_EnumPrinterDataEx r2
;
8192 struct spoolss_PrinterEnumValues
*info
, *val
= NULL
;
8195 r2
.in
.handle
= r
->in
.handle
;
8196 r2
.in
.key_name
= "PrinterDriverData";
8198 r2
.out
.count
= &count
;
8199 r2
.out
.info
= &info
;
8200 r2
.out
.needed
= &needed
;
8202 result
= _spoolss_EnumPrinterDataEx(p
, &r2
);
8203 if (W_ERROR_EQUAL(result
, WERR_MORE_DATA
)) {
8204 r2
.in
.offered
= needed
;
8205 result
= _spoolss_EnumPrinterDataEx(p
, &r2
);
8207 if (!W_ERROR_IS_OK(result
)) {
8212 * The NT machine wants to know the biggest size of value and data
8214 * cf: MSDN EnumPrinterData remark section
8217 if (!r
->in
.value_offered
&& !r
->in
.data_offered
) {
8218 uint32_t biggest_valuesize
= 0;
8219 uint32_t biggest_datasize
= 0;
8222 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
8224 for (i
=0; i
<count
; i
++) {
8226 name_length
= strlen(info
[i
].value_name
);
8227 if (strlen(info
[i
].value_name
) > biggest_valuesize
) {
8228 biggest_valuesize
= name_length
;
8231 if (info
[i
].data_length
> biggest_datasize
) {
8232 biggest_datasize
= info
[i
].data_length
;
8235 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize
,
8239 /* the value is an UNICODE string but real_value_size is the length
8240 in bytes including the trailing 0 */
8242 *r
->out
.value_needed
= 2 * (1 + biggest_valuesize
);
8243 *r
->out
.data_needed
= biggest_datasize
;
8245 DEBUG(6,("final values: [%d], [%d]\n",
8246 *r
->out
.value_needed
, *r
->out
.data_needed
));
8251 if (r
->in
.enum_index
< count
) {
8252 val
= &info
[r
->in
.enum_index
];
8256 /* out_value should default to "" or else NT4 has
8257 problems unmarshalling the response */
8259 if (r
->in
.value_offered
) {
8260 *r
->out
.value_needed
= 1;
8261 r
->out
.value_name
= talloc_strdup(r
, "");
8262 if (!r
->out
.value_name
) {
8266 r
->out
.value_name
= NULL
;
8267 *r
->out
.value_needed
= 0;
8270 /* the data is counted in bytes */
8272 *r
->out
.data_needed
= r
->in
.data_offered
;
8274 result
= WERR_NO_MORE_ITEMS
;
8278 * - counted in bytes in the request
8279 * - counted in UNICODE chars in the max reply
8280 * - counted in bytes in the real size
8282 * take a pause *before* coding not *during* coding
8286 if (r
->in
.value_offered
) {
8287 r
->out
.value_name
= talloc_strdup(r
, val
->value_name
);
8288 if (!r
->out
.value_name
) {
8291 *r
->out
.value_needed
= val
->value_name_len
;
8293 r
->out
.value_name
= NULL
;
8294 *r
->out
.value_needed
= 0;
8299 *r
->out
.type
= val
->type
;
8301 /* data - counted in bytes */
8304 * See the section "Dynamically Typed Query Parameters"
8308 if (r
->out
.data
&& val
->data
&& val
->data
->data
&&
8309 val
->data_length
&& r
->in
.data_offered
) {
8310 memcpy(r
->out
.data
, val
->data
->data
,
8311 MIN(val
->data_length
,r
->in
.data_offered
));
8314 *r
->out
.data_needed
= val
->data_length
;
8322 /****************************************************************
8323 _spoolss_SetPrinterData
8324 ****************************************************************/
8326 WERROR
_spoolss_SetPrinterData(struct pipes_struct
*p
,
8327 struct spoolss_SetPrinterData
*r
)
8329 struct spoolss_SetPrinterDataEx r2
;
8331 r2
.in
.handle
= r
->in
.handle
;
8332 r2
.in
.key_name
= "PrinterDriverData";
8333 r2
.in
.value_name
= r
->in
.value_name
;
8334 r2
.in
.type
= r
->in
.type
;
8335 r2
.in
.data
= r
->in
.data
;
8336 r2
.in
.offered
= r
->in
.offered
;
8338 return _spoolss_SetPrinterDataEx(p
, &r2
);
8341 /****************************************************************
8342 _spoolss_ResetPrinter
8343 ****************************************************************/
8345 WERROR
_spoolss_ResetPrinter(struct pipes_struct
*p
,
8346 struct spoolss_ResetPrinter
*r
)
8348 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
8351 DEBUG(5,("_spoolss_ResetPrinter\n"));
8354 * All we do is to check to see if the handle and queue is valid.
8355 * This call really doesn't mean anything to us because we only
8356 * support RAW printing. --jerry
8360 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
8361 OUR_HANDLE(r
->in
.handle
)));
8365 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
))
8369 /* blindly return success */
8373 /****************************************************************
8374 _spoolss_DeletePrinterData
8375 ****************************************************************/
8377 WERROR
_spoolss_DeletePrinterData(struct pipes_struct
*p
,
8378 struct spoolss_DeletePrinterData
*r
)
8380 struct spoolss_DeletePrinterDataEx r2
;
8382 r2
.in
.handle
= r
->in
.handle
;
8383 r2
.in
.key_name
= "PrinterDriverData";
8384 r2
.in
.value_name
= r
->in
.value_name
;
8386 return _spoolss_DeletePrinterDataEx(p
, &r2
);
8389 /****************************************************************
8391 ****************************************************************/
8393 WERROR
_spoolss_AddForm(struct pipes_struct
*p
,
8394 struct spoolss_AddForm
*r
)
8396 struct spoolss_AddFormInfo1
*form
= r
->in
.info
.info1
;
8398 WERROR status
= WERR_OK
;
8400 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
8402 DEBUG(5,("_spoolss_AddForm\n"));
8405 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
8406 OUR_HANDLE(r
->in
.handle
)));
8410 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8411 and not a printer admin, then fail */
8413 if ((p
->server_info
->utok
.uid
!= sec_initial_uid()) &&
8414 !security_token_has_privilege(p
->server_info
->ptok
, SEC_PRIV_PRINT_OPERATOR
) &&
8415 !token_contains_name_in_list(uidtoname(p
->server_info
->utok
.uid
),
8416 p
->server_info
->info3
->base
.domain
.string
,
8418 p
->server_info
->ptok
,
8419 lp_printer_admin(snum
))) {
8420 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
8421 return WERR_ACCESS_DENIED
;
8424 switch (form
->flags
) {
8425 case SPOOLSS_FORM_USER
:
8426 case SPOOLSS_FORM_BUILTIN
:
8427 case SPOOLSS_FORM_PRINTER
:
8430 return WERR_INVALID_PARAM
;
8433 status
= winreg_printer_addform1(p
->mem_ctx
,
8434 get_server_info_system(),
8437 if (!W_ERROR_IS_OK(status
)) {
8442 * ChangeID must always be set if this is a printer
8444 if (Printer
->printer_type
== SPLHND_PRINTER
) {
8445 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
8449 status
= winreg_printer_update_changeid(p
->mem_ctx
,
8450 get_server_info_system(),
8452 lp_const_servicename(snum
));
8453 if (!W_ERROR_IS_OK(status
)) {
8461 /****************************************************************
8463 ****************************************************************/
8465 WERROR
_spoolss_DeleteForm(struct pipes_struct
*p
,
8466 struct spoolss_DeleteForm
*r
)
8468 const char *form_name
= r
->in
.form_name
;
8469 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
8471 WERROR status
= WERR_OK
;
8473 DEBUG(5,("_spoolss_DeleteForm\n"));
8476 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
8477 OUR_HANDLE(r
->in
.handle
)));
8481 if ((p
->server_info
->utok
.uid
!= sec_initial_uid()) &&
8482 !security_token_has_privilege(p
->server_info
->ptok
, SEC_PRIV_PRINT_OPERATOR
) &&
8483 !token_contains_name_in_list(uidtoname(p
->server_info
->utok
.uid
),
8484 p
->server_info
->info3
->base
.domain
.string
,
8486 p
->server_info
->ptok
,
8487 lp_printer_admin(snum
))) {
8488 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
8489 return WERR_ACCESS_DENIED
;
8492 status
= winreg_printer_deleteform1(p
->mem_ctx
,
8493 get_server_info_system(),
8496 if (!W_ERROR_IS_OK(status
)) {
8501 * ChangeID must always be set if this is a printer
8503 if (Printer
->printer_type
== SPLHND_PRINTER
) {
8504 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
8508 status
= winreg_printer_update_changeid(p
->mem_ctx
,
8509 get_server_info_system(),
8511 lp_const_servicename(snum
));
8512 if (!W_ERROR_IS_OK(status
)) {
8520 /****************************************************************
8522 ****************************************************************/
8524 WERROR
_spoolss_SetForm(struct pipes_struct
*p
,
8525 struct spoolss_SetForm
*r
)
8527 struct spoolss_AddFormInfo1
*form
= r
->in
.info
.info1
;
8528 const char *form_name
= r
->in
.form_name
;
8530 WERROR status
= WERR_OK
;
8532 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
8534 DEBUG(5,("_spoolss_SetForm\n"));
8537 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8538 OUR_HANDLE(r
->in
.handle
)));
8542 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8543 and not a printer admin, then fail */
8545 if ((p
->server_info
->utok
.uid
!= sec_initial_uid()) &&
8546 !security_token_has_privilege(p
->server_info
->ptok
, SEC_PRIV_PRINT_OPERATOR
) &&
8547 !token_contains_name_in_list(uidtoname(p
->server_info
->utok
.uid
),
8548 p
->server_info
->info3
->base
.domain
.string
,
8550 p
->server_info
->ptok
,
8551 lp_printer_admin(snum
))) {
8552 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
8553 return WERR_ACCESS_DENIED
;
8556 status
= winreg_printer_setform1(p
->mem_ctx
,
8557 get_server_info_system(),
8561 if (!W_ERROR_IS_OK(status
)) {
8566 * ChangeID must always be set if this is a printer
8568 if (Printer
->printer_type
== SPLHND_PRINTER
) {
8569 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
8573 status
= winreg_printer_update_changeid(p
->mem_ctx
,
8574 get_server_info_system(),
8576 lp_const_servicename(snum
));
8577 if (!W_ERROR_IS_OK(status
)) {
8585 /****************************************************************************
8586 fill_print_processor1
8587 ****************************************************************************/
8589 static WERROR
fill_print_processor1(TALLOC_CTX
*mem_ctx
,
8590 struct spoolss_PrintProcessorInfo1
*r
,
8591 const char *print_processor_name
)
8593 r
->print_processor_name
= talloc_strdup(mem_ctx
, print_processor_name
);
8594 W_ERROR_HAVE_NO_MEMORY(r
->print_processor_name
);
8599 /****************************************************************************
8600 enumprintprocessors level 1.
8601 ****************************************************************************/
8603 static WERROR
enumprintprocessors_level_1(TALLOC_CTX
*mem_ctx
,
8604 union spoolss_PrintProcessorInfo
**info_p
,
8607 union spoolss_PrintProcessorInfo
*info
;
8610 info
= TALLOC_ARRAY(mem_ctx
, union spoolss_PrintProcessorInfo
, 1);
8611 W_ERROR_HAVE_NO_MEMORY(info
);
8615 result
= fill_print_processor1(info
, &info
[0].info1
, "winprint");
8616 if (!W_ERROR_IS_OK(result
)) {
8621 if (!W_ERROR_IS_OK(result
)) {
8632 /****************************************************************
8633 _spoolss_EnumPrintProcessors
8634 ****************************************************************/
8636 WERROR
_spoolss_EnumPrintProcessors(struct pipes_struct
*p
,
8637 struct spoolss_EnumPrintProcessors
*r
)
8641 /* that's an [in out] buffer */
8643 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
8644 return WERR_INVALID_PARAM
;
8647 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8650 * Enumerate the print processors ...
8652 * Just reply with "winprint", to keep NT happy
8653 * and I can use my nice printer checker.
8658 *r
->out
.info
= NULL
;
8660 if (!get_short_archi(r
->in
.environment
)) {
8661 return WERR_INVALID_ENVIRONMENT
;
8664 switch (r
->in
.level
) {
8666 result
= enumprintprocessors_level_1(p
->mem_ctx
, r
->out
.info
,
8670 return WERR_UNKNOWN_LEVEL
;
8673 if (!W_ERROR_IS_OK(result
)) {
8677 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
8678 spoolss_EnumPrintProcessors
,
8679 *r
->out
.info
, r
->in
.level
,
8681 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
8682 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
8684 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
8687 /****************************************************************************
8688 fill_printprocdatatype1
8689 ****************************************************************************/
8691 static WERROR
fill_printprocdatatype1(TALLOC_CTX
*mem_ctx
,
8692 struct spoolss_PrintProcDataTypesInfo1
*r
,
8693 const char *name_array
)
8695 r
->name_array
= talloc_strdup(mem_ctx
, name_array
);
8696 W_ERROR_HAVE_NO_MEMORY(r
->name_array
);
8701 /****************************************************************************
8702 enumprintprocdatatypes level 1.
8703 ****************************************************************************/
8705 static WERROR
enumprintprocdatatypes_level_1(TALLOC_CTX
*mem_ctx
,
8706 union spoolss_PrintProcDataTypesInfo
**info_p
,
8710 union spoolss_PrintProcDataTypesInfo
*info
;
8712 info
= TALLOC_ARRAY(mem_ctx
, union spoolss_PrintProcDataTypesInfo
, 1);
8713 W_ERROR_HAVE_NO_MEMORY(info
);
8717 result
= fill_printprocdatatype1(info
, &info
[0].info1
, "RAW");
8718 if (!W_ERROR_IS_OK(result
)) {
8723 if (!W_ERROR_IS_OK(result
)) {
8734 /****************************************************************
8735 _spoolss_EnumPrintProcDataTypes
8736 ****************************************************************/
8738 WERROR
_spoolss_EnumPrintProcDataTypes(struct pipes_struct
*p
,
8739 struct spoolss_EnumPrintProcDataTypes
*r
)
8743 /* that's an [in out] buffer */
8745 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
8746 return WERR_INVALID_PARAM
;
8749 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
8753 *r
->out
.info
= NULL
;
8755 if (r
->in
.print_processor_name
== NULL
||
8756 !strequal(r
->in
.print_processor_name
, "winprint")) {
8757 return WERR_UNKNOWN_PRINTPROCESSOR
;
8760 switch (r
->in
.level
) {
8762 result
= enumprintprocdatatypes_level_1(p
->mem_ctx
, r
->out
.info
,
8766 return WERR_UNKNOWN_LEVEL
;
8769 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
8770 spoolss_EnumPrintProcDataTypes
,
8771 *r
->out
.info
, r
->in
.level
,
8773 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
8774 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
8776 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
8779 /****************************************************************************
8781 ****************************************************************************/
8783 static WERROR
fill_monitor_1(TALLOC_CTX
*mem_ctx
,
8784 struct spoolss_MonitorInfo1
*r
,
8785 const char *monitor_name
)
8787 r
->monitor_name
= talloc_strdup(mem_ctx
, monitor_name
);
8788 W_ERROR_HAVE_NO_MEMORY(r
->monitor_name
);
8793 /****************************************************************************
8795 ****************************************************************************/
8797 static WERROR
fill_monitor_2(TALLOC_CTX
*mem_ctx
,
8798 struct spoolss_MonitorInfo2
*r
,
8799 const char *monitor_name
,
8800 const char *environment
,
8801 const char *dll_name
)
8803 r
->monitor_name
= talloc_strdup(mem_ctx
, monitor_name
);
8804 W_ERROR_HAVE_NO_MEMORY(r
->monitor_name
);
8805 r
->environment
= talloc_strdup(mem_ctx
, environment
);
8806 W_ERROR_HAVE_NO_MEMORY(r
->environment
);
8807 r
->dll_name
= talloc_strdup(mem_ctx
, dll_name
);
8808 W_ERROR_HAVE_NO_MEMORY(r
->dll_name
);
8813 /****************************************************************************
8814 enumprintmonitors level 1.
8815 ****************************************************************************/
8817 static WERROR
enumprintmonitors_level_1(TALLOC_CTX
*mem_ctx
,
8818 union spoolss_MonitorInfo
**info_p
,
8821 union spoolss_MonitorInfo
*info
;
8822 WERROR result
= WERR_OK
;
8824 info
= TALLOC_ARRAY(mem_ctx
, union spoolss_MonitorInfo
, 2);
8825 W_ERROR_HAVE_NO_MEMORY(info
);
8829 result
= fill_monitor_1(info
, &info
[0].info1
,
8831 if (!W_ERROR_IS_OK(result
)) {
8835 result
= fill_monitor_1(info
, &info
[1].info1
,
8837 if (!W_ERROR_IS_OK(result
)) {
8842 if (!W_ERROR_IS_OK(result
)) {
8853 /****************************************************************************
8854 enumprintmonitors level 2.
8855 ****************************************************************************/
8857 static WERROR
enumprintmonitors_level_2(TALLOC_CTX
*mem_ctx
,
8858 union spoolss_MonitorInfo
**info_p
,
8861 union spoolss_MonitorInfo
*info
;
8862 WERROR result
= WERR_OK
;
8864 info
= TALLOC_ARRAY(mem_ctx
, union spoolss_MonitorInfo
, 2);
8865 W_ERROR_HAVE_NO_MEMORY(info
);
8869 result
= fill_monitor_2(info
, &info
[0].info2
,
8871 "Windows NT X86", /* FIXME */
8873 if (!W_ERROR_IS_OK(result
)) {
8877 result
= fill_monitor_2(info
, &info
[1].info2
,
8879 "Windows NT X86", /* FIXME */
8881 if (!W_ERROR_IS_OK(result
)) {
8886 if (!W_ERROR_IS_OK(result
)) {
8897 /****************************************************************
8898 _spoolss_EnumMonitors
8899 ****************************************************************/
8901 WERROR
_spoolss_EnumMonitors(struct pipes_struct
*p
,
8902 struct spoolss_EnumMonitors
*r
)
8906 /* that's an [in out] buffer */
8908 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
8909 return WERR_INVALID_PARAM
;
8912 DEBUG(5,("_spoolss_EnumMonitors\n"));
8915 * Enumerate the print monitors ...
8917 * Just reply with "Local Port", to keep NT happy
8918 * and I can use my nice printer checker.
8923 *r
->out
.info
= NULL
;
8925 switch (r
->in
.level
) {
8927 result
= enumprintmonitors_level_1(p
->mem_ctx
, r
->out
.info
,
8931 result
= enumprintmonitors_level_2(p
->mem_ctx
, r
->out
.info
,
8935 return WERR_UNKNOWN_LEVEL
;
8938 if (!W_ERROR_IS_OK(result
)) {
8942 *r
->out
.needed
= SPOOLSS_BUFFER_UNION_ARRAY(p
->mem_ctx
,
8943 spoolss_EnumMonitors
,
8944 *r
->out
.info
, r
->in
.level
,
8946 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
8947 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, 0);
8949 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
8952 /****************************************************************************
8953 ****************************************************************************/
8955 static WERROR
getjob_level_1(TALLOC_CTX
*mem_ctx
,
8956 const print_queue_struct
*queue
,
8957 int count
, int snum
,
8958 struct spoolss_PrinterInfo2
*pinfo2
,
8960 struct spoolss_JobInfo1
*r
)
8965 for (i
=0; i
<count
; i
++) {
8966 if (queue
[i
].job
== (int)jobid
) {
8972 if (found
== false) {
8973 /* NT treats not found as bad param... yet another bad choice */
8974 return WERR_INVALID_PARAM
;
8977 return fill_job_info1(mem_ctx
,
8985 /****************************************************************************
8986 ****************************************************************************/
8988 static WERROR
getjob_level_2(TALLOC_CTX
*mem_ctx
,
8989 const print_queue_struct
*queue
,
8990 int count
, int snum
,
8991 struct spoolss_PrinterInfo2
*pinfo2
,
8993 struct spoolss_JobInfo2
*r
)
8997 struct spoolss_DeviceMode
*devmode
;
9000 for (i
=0; i
<count
; i
++) {
9001 if (queue
[i
].job
== (int)jobid
) {
9007 if (found
== false) {
9008 /* NT treats not found as bad param... yet another bad
9010 return WERR_INVALID_PARAM
;
9014 * if the print job does not have a DEVMODE associated with it,
9015 * just use the one for the printer. A NULL devicemode is not
9016 * a failure condition
9019 devmode
= print_job_devmode(lp_const_servicename(snum
), jobid
);
9021 result
= spoolss_create_default_devmode(mem_ctx
,
9022 pinfo2
->printername
,
9024 if (!W_ERROR_IS_OK(result
)) {
9025 DEBUG(3, ("Can't proceed w/o a devmode!"));
9030 return fill_job_info2(mem_ctx
,
9039 /****************************************************************
9041 ****************************************************************/
9043 WERROR
_spoolss_GetJob(struct pipes_struct
*p
,
9044 struct spoolss_GetJob
*r
)
9046 WERROR result
= WERR_OK
;
9047 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
9050 print_queue_struct
*queue
= NULL
;
9051 print_status_struct prt_status
;
9053 /* that's an [in out] buffer */
9055 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
9056 return WERR_INVALID_PARAM
;
9059 DEBUG(5,("_spoolss_GetJob\n"));
9063 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9067 result
= winreg_get_printer(p
->mem_ctx
,
9068 get_server_info_system(),
9070 lp_const_servicename(snum
),
9072 if (!W_ERROR_IS_OK(result
)) {
9076 count
= print_queue_status(p
->msg_ctx
, snum
, &queue
, &prt_status
);
9078 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
9079 count
, prt_status
.status
, prt_status
.message
));
9081 switch (r
->in
.level
) {
9083 result
= getjob_level_1(p
->mem_ctx
,
9084 queue
, count
, snum
, pinfo2
,
9085 r
->in
.job_id
, &r
->out
.info
->info1
);
9088 result
= getjob_level_2(p
->mem_ctx
,
9089 queue
, count
, snum
, pinfo2
,
9090 r
->in
.job_id
, &r
->out
.info
->info2
);
9093 result
= WERR_UNKNOWN_LEVEL
;
9098 TALLOC_FREE(pinfo2
);
9100 if (!W_ERROR_IS_OK(result
)) {
9101 TALLOC_FREE(r
->out
.info
);
9105 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_JobInfo
, r
->out
.info
,
9107 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
9109 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
9112 /****************************************************************
9113 _spoolss_GetPrinterDataEx
9114 ****************************************************************/
9116 WERROR
_spoolss_GetPrinterDataEx(struct pipes_struct
*p
,
9117 struct spoolss_GetPrinterDataEx
*r
)
9120 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9121 const char *printer
;
9123 WERROR result
= WERR_OK
;
9125 enum winreg_Type val_type
;
9130 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
9132 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
9133 r
->in
.key_name
, r
->in
.value_name
));
9135 /* in case of problem, return some default values */
9138 *r
->out
.type
= REG_NONE
;
9141 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9142 OUR_HANDLE(r
->in
.handle
)));
9143 result
= WERR_BADFID
;
9147 /* Is the handle to a printer or to the server? */
9149 if (Printer
->printer_type
== SPLHND_SERVER
) {
9151 union spoolss_PrinterData data
;
9153 result
= getprinterdata_printer_server(p
->mem_ctx
,
9157 if (!W_ERROR_IS_OK(result
)) {
9161 result
= push_spoolss_PrinterData(p
->mem_ctx
, &blob
,
9162 *r
->out
.type
, &data
);
9163 if (!W_ERROR_IS_OK(result
)) {
9167 *r
->out
.needed
= blob
.length
;
9169 if (r
->in
.offered
>= *r
->out
.needed
) {
9170 memcpy(r
->out
.data
, blob
.data
, blob
.length
);
9173 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_MORE_DATA
);
9176 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9179 printer
= lp_const_servicename(snum
);
9181 /* check to see if the keyname is valid */
9182 if (!strlen(r
->in
.key_name
)) {
9183 return WERR_INVALID_PARAM
;
9186 /* XP sends this and wants the ChangeID value from PRINTER_INFO_0 */
9187 if (strequal(r
->in
.key_name
, SPOOL_PRINTERDATA_KEY
) &&
9188 strequal(r
->in
.value_name
, "ChangeId")) {
9189 *r
->out
.type
= REG_DWORD
;
9191 if (r
->in
.offered
>= *r
->out
.needed
) {
9192 uint32_t changeid
= 0;
9194 result
= winreg_printer_get_changeid(p
->mem_ctx
,
9195 get_server_info_system(),
9199 if (!W_ERROR_IS_OK(result
)) {
9203 SIVAL(r
->out
.data
, 0, changeid
);
9209 result
= winreg_get_printer_dataex(p
->mem_ctx
,
9210 get_server_info_system(),
9218 if (!W_ERROR_IS_OK(result
)) {
9222 *r
->out
.needed
= val_size
;
9223 *r
->out
.type
= val_type
;
9225 if (r
->in
.offered
>= *r
->out
.needed
) {
9226 memcpy(r
->out
.data
, val_data
, val_size
);
9230 /* retain type when returning WERR_MORE_DATA */
9231 r
->out
.data
= SPOOLSS_BUFFER_OK(r
->out
.data
, r
->out
.data
);
9233 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_MORE_DATA
);
9236 /****************************************************************
9237 _spoolss_SetPrinterDataEx
9238 ****************************************************************/
9240 WERROR
_spoolss_SetPrinterDataEx(struct pipes_struct
*p
,
9241 struct spoolss_SetPrinterDataEx
*r
)
9243 struct spoolss_PrinterInfo2
*pinfo2
= NULL
;
9245 WERROR result
= WERR_OK
;
9246 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9249 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
9251 /* From MSDN documentation of SetPrinterDataEx: pass request to
9252 SetPrinterData if key is "PrinterDriverData" */
9255 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9256 OUR_HANDLE(r
->in
.handle
)));
9260 if (Printer
->printer_type
== SPLHND_SERVER
) {
9261 DEBUG(10,("_spoolss_SetPrinterDataEx: "
9262 "Not implemented for server handles yet\n"));
9263 return WERR_INVALID_PARAM
;
9266 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9271 * Access check : NT returns "access denied" if you make a
9272 * SetPrinterData call without the necessary privildge.
9273 * we were originally returning OK if nothing changed
9274 * which made Win2k issue **a lot** of SetPrinterData
9275 * when connecting to a printer --jerry
9278 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
9279 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
9280 "change denied by handle access permissions\n"));
9281 return WERR_ACCESS_DENIED
;
9284 result
= winreg_get_printer(Printer
,
9285 get_server_info_system(),
9287 lp_servicename(snum
),
9289 if (!W_ERROR_IS_OK(result
)) {
9293 /* check for OID in valuename */
9295 oid_string
= strchr(r
->in
.value_name
, ',');
9301 /* save the registry data */
9303 result
= winreg_set_printer_dataex(p
->mem_ctx
,
9304 get_server_info_system(),
9313 if (W_ERROR_IS_OK(result
)) {
9314 /* save the OID if one was specified */
9316 char *str
= talloc_asprintf(p
->mem_ctx
, "%s\\%s",
9317 r
->in
.key_name
, SPOOL_OID_KEY
);
9319 result
= WERR_NOMEM
;
9324 * I'm not checking the status here on purpose. Don't know
9325 * if this is right, but I'm returning the status from the
9326 * previous set_printer_dataex() call. I have no idea if
9327 * this is right. --jerry
9329 winreg_set_printer_dataex(p
->mem_ctx
,
9330 get_server_info_system(),
9336 (uint8_t *) oid_string
,
9337 strlen(oid_string
) + 1);
9340 result
= winreg_printer_update_changeid(p
->mem_ctx
,
9341 get_server_info_system(),
9343 lp_const_servicename(snum
));
9348 talloc_free(pinfo2
);
9352 /****************************************************************
9353 _spoolss_DeletePrinterDataEx
9354 ****************************************************************/
9356 WERROR
_spoolss_DeletePrinterDataEx(struct pipes_struct
*p
,
9357 struct spoolss_DeletePrinterDataEx
*r
)
9359 const char *printer
;
9361 WERROR status
= WERR_OK
;
9362 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9364 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
9367 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
9368 "Invalid handle (%s:%u:%u).\n",
9369 OUR_HANDLE(r
->in
.handle
)));
9373 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
9374 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
9375 "printer properties change denied by handle\n"));
9376 return WERR_ACCESS_DENIED
;
9379 if (!r
->in
.value_name
|| !r
->in
.key_name
) {
9383 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9386 printer
= lp_const_servicename(snum
);
9388 status
= winreg_delete_printer_dataex(p
->mem_ctx
,
9389 get_server_info_system(),
9394 if (W_ERROR_IS_OK(status
)) {
9395 status
= winreg_printer_update_changeid(p
->mem_ctx
,
9396 get_server_info_system(),
9404 /****************************************************************
9405 _spoolss_EnumPrinterKey
9406 ****************************************************************/
9408 WERROR
_spoolss_EnumPrinterKey(struct pipes_struct
*p
,
9409 struct spoolss_EnumPrinterKey
*r
)
9412 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9414 WERROR result
= WERR_BADFILE
;
9415 const char **array
= NULL
;
9418 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
9421 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
9422 OUR_HANDLE(r
->in
.handle
)));
9426 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9430 result
= winreg_enum_printer_key(p
->mem_ctx
,
9431 get_server_info_system(),
9433 lp_const_servicename(snum
),
9437 if (!W_ERROR_IS_OK(result
)) {
9441 if (!push_reg_multi_sz(p
->mem_ctx
, &blob
, array
)) {
9442 result
= WERR_NOMEM
;
9446 *r
->out
._ndr_size
= r
->in
.offered
/ 2;
9447 *r
->out
.needed
= blob
.length
;
9449 if (r
->in
.offered
< *r
->out
.needed
) {
9450 result
= WERR_MORE_DATA
;
9453 r
->out
.key_buffer
->string_array
= array
;
9457 if (!W_ERROR_IS_OK(result
)) {
9459 if (!W_ERROR_EQUAL(result
, WERR_MORE_DATA
)) {
9467 /****************************************************************
9468 _spoolss_DeletePrinterKey
9469 ****************************************************************/
9471 WERROR
_spoolss_DeletePrinterKey(struct pipes_struct
*p
,
9472 struct spoolss_DeletePrinterKey
*r
)
9474 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9477 const char *printer
;
9479 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
9482 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
9483 OUR_HANDLE(r
->in
.handle
)));
9487 /* if keyname == NULL, return error */
9488 if ( !r
->in
.key_name
)
9489 return WERR_INVALID_PARAM
;
9491 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9495 if (Printer
->access_granted
!= PRINTER_ACCESS_ADMINISTER
) {
9496 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9497 "printer properties change denied by handle\n"));
9498 return WERR_ACCESS_DENIED
;
9501 printer
= lp_const_servicename(snum
);
9503 /* delete the key and all subkeys */
9504 status
= winreg_delete_printer_key(p
->mem_ctx
,
9505 get_server_info_system(),
9509 if (W_ERROR_IS_OK(status
)) {
9510 status
= winreg_printer_update_changeid(p
->mem_ctx
,
9511 get_server_info_system(),
9519 /****************************************************************
9520 _spoolss_EnumPrinterDataEx
9521 ****************************************************************/
9523 WERROR
_spoolss_EnumPrinterDataEx(struct pipes_struct
*p
,
9524 struct spoolss_EnumPrinterDataEx
*r
)
9527 struct spoolss_PrinterEnumValues
*info
= NULL
;
9528 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9532 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
9536 *r
->out
.info
= NULL
;
9539 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
9540 OUR_HANDLE(r
->in
.handle
)));
9545 * first check for a keyname of NULL or "". Win2k seems to send
9546 * this a lot and we should send back WERR_INVALID_PARAM
9547 * no need to spend time looking up the printer in this case.
9551 if (!strlen(r
->in
.key_name
)) {
9552 result
= WERR_INVALID_PARAM
;
9556 if (!get_printer_snum(p
, r
->in
.handle
, &snum
, NULL
)) {
9560 /* now look for a match on the key name */
9561 result
= winreg_enum_printer_dataex(p
->mem_ctx
,
9562 get_server_info_system(),
9564 lp_const_servicename(snum
),
9568 if (!W_ERROR_IS_OK(result
)) {
9572 #if 0 /* FIXME - gd */
9573 /* housekeeping information in the reply */
9575 /* Fix from Martin Zielinski <mz@seh.de> - ensure
9576 * the hand marshalled container size is a multiple
9577 * of 4 bytes for RPC alignment.
9581 needed
+= 4-(needed
% 4);
9584 *r
->out
.count
= count
;
9585 *r
->out
.info
= info
;
9588 if (!W_ERROR_IS_OK(result
)) {
9592 *r
->out
.needed
= SPOOLSS_BUFFER_ARRAY(p
->mem_ctx
,
9593 spoolss_EnumPrinterDataEx
,
9596 *r
->out
.info
= SPOOLSS_BUFFER_OK(*r
->out
.info
, NULL
);
9597 *r
->out
.count
= SPOOLSS_BUFFER_OK(*r
->out
.count
, *r
->out
.count
);
9599 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_MORE_DATA
);
9602 /****************************************************************************
9603 ****************************************************************************/
9605 static WERROR
getprintprocessordirectory_level_1(TALLOC_CTX
*mem_ctx
,
9606 const char *servername
,
9607 const char *environment
,
9608 struct spoolss_PrintProcessorDirectoryInfo1
*r
)
9613 werr
= compose_spoolss_server_path(mem_ctx
,
9616 SPOOLSS_PRTPROCS_PATH
,
9618 if (!W_ERROR_IS_OK(werr
)) {
9622 DEBUG(4,("print processor directory: [%s]\n", path
));
9624 r
->directory_name
= path
;
9629 /****************************************************************
9630 _spoolss_GetPrintProcessorDirectory
9631 ****************************************************************/
9633 WERROR
_spoolss_GetPrintProcessorDirectory(struct pipes_struct
*p
,
9634 struct spoolss_GetPrintProcessorDirectory
*r
)
9637 char *prnproc_share
= NULL
;
9638 bool prnproc_share_exists
= false;
9641 /* that's an [in out] buffer */
9643 if (!r
->in
.buffer
&& (r
->in
.offered
!= 0)) {
9644 return WERR_INVALID_PARAM
;
9647 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9652 /* r->in.level is ignored */
9654 /* We always should reply with a local print processor directory so that
9655 * users are not forced to have a [prnproc$] share on the Samba spoolss
9656 * server, if users decide to do so, lets announce it though - Guenther */
9658 snum
= find_service(talloc_tos(), "prnproc$", &prnproc_share
);
9659 if (!prnproc_share
) {
9663 prnproc_share_exists
= true;
9666 result
= getprintprocessordirectory_level_1(p
->mem_ctx
,
9667 prnproc_share_exists
? r
->in
.server
: NULL
,
9669 &r
->out
.info
->info1
);
9670 if (!W_ERROR_IS_OK(result
)) {
9671 TALLOC_FREE(r
->out
.info
);
9675 *r
->out
.needed
= SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo
,
9676 r
->out
.info
, r
->in
.level
);
9677 r
->out
.info
= SPOOLSS_BUFFER_OK(r
->out
.info
, NULL
);
9679 return SPOOLSS_BUFFER_OK(WERR_OK
, WERR_INSUFFICIENT_BUFFER
);
9682 /*******************************************************************
9683 ********************************************************************/
9685 static bool push_monitorui_buf(TALLOC_CTX
*mem_ctx
, DATA_BLOB
*buf
,
9686 const char *dllname
)
9688 enum ndr_err_code ndr_err
;
9689 struct spoolss_MonitorUi ui
;
9691 ui
.dll_name
= dllname
;
9693 ndr_err
= ndr_push_struct_blob(buf
, mem_ctx
, &ui
,
9694 (ndr_push_flags_fn_t
)ndr_push_spoolss_MonitorUi
);
9695 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err
) && (DEBUGLEVEL
>= 10)) {
9696 NDR_PRINT_DEBUG(spoolss_MonitorUi
, &ui
);
9698 return NDR_ERR_CODE_IS_SUCCESS(ndr_err
);
9701 /*******************************************************************
9702 Streams the monitor UI DLL name in UNICODE
9703 *******************************************************************/
9705 static WERROR
xcvtcp_monitorui(TALLOC_CTX
*mem_ctx
,
9706 struct security_token
*token
, DATA_BLOB
*in
,
9707 DATA_BLOB
*out
, uint32_t *needed
)
9709 const char *dllname
= "tcpmonui.dll";
9711 *needed
= (strlen(dllname
)+1) * 2;
9713 if (out
->length
< *needed
) {
9714 return WERR_INSUFFICIENT_BUFFER
;
9717 if (!push_monitorui_buf(mem_ctx
, out
, dllname
)) {
9724 /*******************************************************************
9725 ********************************************************************/
9727 static bool pull_port_data_1(TALLOC_CTX
*mem_ctx
,
9728 struct spoolss_PortData1
*port1
,
9729 const DATA_BLOB
*buf
)
9731 enum ndr_err_code ndr_err
;
9732 ndr_err
= ndr_pull_struct_blob(buf
, mem_ctx
, port1
,
9733 (ndr_pull_flags_fn_t
)ndr_pull_spoolss_PortData1
);
9734 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err
) && (DEBUGLEVEL
>= 10)) {
9735 NDR_PRINT_DEBUG(spoolss_PortData1
, port1
);
9737 return NDR_ERR_CODE_IS_SUCCESS(ndr_err
);
9740 /*******************************************************************
9741 ********************************************************************/
9743 static bool pull_port_data_2(TALLOC_CTX
*mem_ctx
,
9744 struct spoolss_PortData2
*port2
,
9745 const DATA_BLOB
*buf
)
9747 enum ndr_err_code ndr_err
;
9748 ndr_err
= ndr_pull_struct_blob(buf
, mem_ctx
, port2
,
9749 (ndr_pull_flags_fn_t
)ndr_pull_spoolss_PortData2
);
9750 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err
) && (DEBUGLEVEL
>= 10)) {
9751 NDR_PRINT_DEBUG(spoolss_PortData2
, port2
);
9753 return NDR_ERR_CODE_IS_SUCCESS(ndr_err
);
9756 /*******************************************************************
9757 Create a new TCP/IP port
9758 *******************************************************************/
9760 static WERROR
xcvtcp_addport(TALLOC_CTX
*mem_ctx
,
9761 struct security_token
*token
, DATA_BLOB
*in
,
9762 DATA_BLOB
*out
, uint32_t *needed
)
9764 struct spoolss_PortData1 port1
;
9765 struct spoolss_PortData2 port2
;
9766 char *device_uri
= NULL
;
9769 const char *portname
;
9770 const char *hostaddress
;
9772 uint32_t port_number
;
9775 /* peek for spoolss_PortData version */
9777 if (!in
|| (in
->length
< (128 + 4))) {
9778 return WERR_GENERAL_FAILURE
;
9781 version
= IVAL(in
->data
, 128);
9787 if (!pull_port_data_1(mem_ctx
, &port1
, in
)) {
9791 portname
= port1
.portname
;
9792 hostaddress
= port1
.hostaddress
;
9793 queue
= port1
.queue
;
9794 protocol
= port1
.protocol
;
9795 port_number
= port1
.port_number
;
9801 if (!pull_port_data_2(mem_ctx
, &port2
, in
)) {
9805 portname
= port2
.portname
;
9806 hostaddress
= port2
.hostaddress
;
9807 queue
= port2
.queue
;
9808 protocol
= port2
.protocol
;
9809 port_number
= port2
.port_number
;
9813 DEBUG(1,("xcvtcp_addport: "
9814 "unknown version of port_data: %d\n", version
));
9815 return WERR_UNKNOWN_PORT
;
9818 /* create the device URI and call the add_port_hook() */
9821 case PROTOCOL_RAWTCP_TYPE
:
9822 device_uri
= talloc_asprintf(mem_ctx
,
9823 "socket://%s:%d/", hostaddress
,
9827 case PROTOCOL_LPR_TYPE
:
9828 device_uri
= talloc_asprintf(mem_ctx
,
9829 "lpr://%s/%s", hostaddress
, queue
);
9833 return WERR_UNKNOWN_PORT
;
9840 return add_port_hook(mem_ctx
, token
, portname
, device_uri
);
9843 /*******************************************************************
9844 *******************************************************************/
9846 struct xcv_api_table xcvtcp_cmds
[] = {
9847 { "MonitorUI", xcvtcp_monitorui
},
9848 { "AddPort", xcvtcp_addport
},
9852 static WERROR
process_xcvtcp_command(TALLOC_CTX
*mem_ctx
,
9853 struct security_token
*token
, const char *command
,
9860 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command
));
9862 for ( i
=0; xcvtcp_cmds
[i
].name
; i
++ ) {
9863 if ( strcmp( command
, xcvtcp_cmds
[i
].name
) == 0 )
9864 return xcvtcp_cmds
[i
].fn(mem_ctx
, token
, inbuf
, outbuf
, needed
);
9867 return WERR_BADFUNC
;
9870 /*******************************************************************
9871 *******************************************************************/
9872 #if 0 /* don't support management using the "Local Port" monitor */
9874 static WERROR
xcvlocal_monitorui(TALLOC_CTX
*mem_ctx
,
9875 struct security_token
*token
, DATA_BLOB
*in
,
9876 DATA_BLOB
*out
, uint32_t *needed
)
9878 const char *dllname
= "localui.dll";
9880 *needed
= (strlen(dllname
)+1) * 2;
9882 if (out
->length
< *needed
) {
9883 return WERR_INSUFFICIENT_BUFFER
;
9886 if (!push_monitorui_buf(mem_ctx
, out
, dllname
)) {
9893 /*******************************************************************
9894 *******************************************************************/
9896 struct xcv_api_table xcvlocal_cmds
[] = {
9897 { "MonitorUI", xcvlocal_monitorui
},
9901 struct xcv_api_table xcvlocal_cmds
[] = {
9908 /*******************************************************************
9909 *******************************************************************/
9911 static WERROR
process_xcvlocal_command(TALLOC_CTX
*mem_ctx
,
9912 struct security_token
*token
, const char *command
,
9913 DATA_BLOB
*inbuf
, DATA_BLOB
*outbuf
,
9918 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command
));
9920 for ( i
=0; xcvlocal_cmds
[i
].name
; i
++ ) {
9921 if ( strcmp( command
, xcvlocal_cmds
[i
].name
) == 0 )
9922 return xcvlocal_cmds
[i
].fn(mem_ctx
, token
, inbuf
, outbuf
, needed
);
9924 return WERR_BADFUNC
;
9927 /****************************************************************
9929 ****************************************************************/
9931 WERROR
_spoolss_XcvData(struct pipes_struct
*p
,
9932 struct spoolss_XcvData
*r
)
9934 struct printer_handle
*Printer
= find_printer_index_by_hnd(p
, r
->in
.handle
);
9935 DATA_BLOB out_data
= data_blob_null
;
9939 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
9940 OUR_HANDLE(r
->in
.handle
)));
9944 /* Has to be a handle to the TCP/IP port monitor */
9946 if ( !(Printer
->printer_type
& (SPLHND_PORTMON_LOCAL
|SPLHND_PORTMON_TCP
)) ) {
9947 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
9951 /* requires administrative access to the server */
9953 if ( !(Printer
->access_granted
& SERVER_ACCESS_ADMINISTER
) ) {
9954 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
9955 return WERR_ACCESS_DENIED
;
9958 /* Allocate the outgoing buffer */
9960 if (r
->in
.out_data_size
) {
9961 out_data
= data_blob_talloc_zero(p
->mem_ctx
, r
->in
.out_data_size
);
9962 if (out_data
.data
== NULL
) {
9967 switch ( Printer
->printer_type
) {
9968 case SPLHND_PORTMON_TCP
:
9969 werror
= process_xcvtcp_command(p
->mem_ctx
,
9970 p
->server_info
->ptok
,
9971 r
->in
.function_name
,
9972 &r
->in
.in_data
, &out_data
,
9975 case SPLHND_PORTMON_LOCAL
:
9976 werror
= process_xcvlocal_command(p
->mem_ctx
,
9977 p
->server_info
->ptok
,
9978 r
->in
.function_name
,
9979 &r
->in
.in_data
, &out_data
,
9983 werror
= WERR_INVALID_PRINT_MONITOR
;
9986 if (!W_ERROR_IS_OK(werror
)) {
9990 *r
->out
.status_code
= 0;
9992 if (r
->out
.out_data
&& out_data
.data
&& r
->in
.out_data_size
&& out_data
.length
) {
9993 memcpy(r
->out
.out_data
, out_data
.data
,
9994 MIN(r
->in
.out_data_size
, out_data
.length
));
10000 /****************************************************************
10001 _spoolss_AddPrintProcessor
10002 ****************************************************************/
10004 WERROR
_spoolss_AddPrintProcessor(struct pipes_struct
*p
,
10005 struct spoolss_AddPrintProcessor
*r
)
10007 /* for now, just indicate success and ignore the add. We'll
10008 automatically set the winprint processor for printer
10009 entries later. Used to debug the LexMark Optra S 1855 PCL
10015 /****************************************************************
10017 ****************************************************************/
10019 WERROR
_spoolss_AddPort(struct pipes_struct
*p
,
10020 struct spoolss_AddPort
*r
)
10022 /* do what w2k3 does */
10024 return WERR_NOT_SUPPORTED
;
10027 /****************************************************************
10028 _spoolss_GetPrinterDriver
10029 ****************************************************************/
10031 WERROR
_spoolss_GetPrinterDriver(struct pipes_struct
*p
,
10032 struct spoolss_GetPrinterDriver
*r
)
10034 p
->rng_fault_state
= true;
10035 return WERR_NOT_SUPPORTED
;
10038 /****************************************************************
10039 _spoolss_ReadPrinter
10040 ****************************************************************/
10042 WERROR
_spoolss_ReadPrinter(struct pipes_struct
*p
,
10043 struct spoolss_ReadPrinter
*r
)
10045 p
->rng_fault_state
= true;
10046 return WERR_NOT_SUPPORTED
;
10049 /****************************************************************
10050 _spoolss_WaitForPrinterChange
10051 ****************************************************************/
10053 WERROR
_spoolss_WaitForPrinterChange(struct pipes_struct
*p
,
10054 struct spoolss_WaitForPrinterChange
*r
)
10056 p
->rng_fault_state
= true;
10057 return WERR_NOT_SUPPORTED
;
10060 /****************************************************************
10061 _spoolss_ConfigurePort
10062 ****************************************************************/
10064 WERROR
_spoolss_ConfigurePort(struct pipes_struct
*p
,
10065 struct spoolss_ConfigurePort
*r
)
10067 p
->rng_fault_state
= true;
10068 return WERR_NOT_SUPPORTED
;
10071 /****************************************************************
10072 _spoolss_DeletePort
10073 ****************************************************************/
10075 WERROR
_spoolss_DeletePort(struct pipes_struct
*p
,
10076 struct spoolss_DeletePort
*r
)
10078 p
->rng_fault_state
= true;
10079 return WERR_NOT_SUPPORTED
;
10082 /****************************************************************
10083 _spoolss_CreatePrinterIC
10084 ****************************************************************/
10086 WERROR
_spoolss_CreatePrinterIC(struct pipes_struct
*p
,
10087 struct spoolss_CreatePrinterIC
*r
)
10089 p
->rng_fault_state
= true;
10090 return WERR_NOT_SUPPORTED
;
10093 /****************************************************************
10094 _spoolss_PlayGDIScriptOnPrinterIC
10095 ****************************************************************/
10097 WERROR
_spoolss_PlayGDIScriptOnPrinterIC(struct pipes_struct
*p
,
10098 struct spoolss_PlayGDIScriptOnPrinterIC
*r
)
10100 p
->rng_fault_state
= true;
10101 return WERR_NOT_SUPPORTED
;
10104 /****************************************************************
10105 _spoolss_DeletePrinterIC
10106 ****************************************************************/
10108 WERROR
_spoolss_DeletePrinterIC(struct pipes_struct
*p
,
10109 struct spoolss_DeletePrinterIC
*r
)
10111 p
->rng_fault_state
= true;
10112 return WERR_NOT_SUPPORTED
;
10115 /****************************************************************
10116 _spoolss_AddPrinterConnection
10117 ****************************************************************/
10119 WERROR
_spoolss_AddPrinterConnection(struct pipes_struct
*p
,
10120 struct spoolss_AddPrinterConnection
*r
)
10122 p
->rng_fault_state
= true;
10123 return WERR_NOT_SUPPORTED
;
10126 /****************************************************************
10127 _spoolss_DeletePrinterConnection
10128 ****************************************************************/
10130 WERROR
_spoolss_DeletePrinterConnection(struct pipes_struct
*p
,
10131 struct spoolss_DeletePrinterConnection
*r
)
10133 p
->rng_fault_state
= true;
10134 return WERR_NOT_SUPPORTED
;
10137 /****************************************************************
10138 _spoolss_PrinterMessageBox
10139 ****************************************************************/
10141 WERROR
_spoolss_PrinterMessageBox(struct pipes_struct
*p
,
10142 struct spoolss_PrinterMessageBox
*r
)
10144 p
->rng_fault_state
= true;
10145 return WERR_NOT_SUPPORTED
;
10148 /****************************************************************
10149 _spoolss_AddMonitor
10150 ****************************************************************/
10152 WERROR
_spoolss_AddMonitor(struct pipes_struct
*p
,
10153 struct spoolss_AddMonitor
*r
)
10155 p
->rng_fault_state
= true;
10156 return WERR_NOT_SUPPORTED
;
10159 /****************************************************************
10160 _spoolss_DeleteMonitor
10161 ****************************************************************/
10163 WERROR
_spoolss_DeleteMonitor(struct pipes_struct
*p
,
10164 struct spoolss_DeleteMonitor
*r
)
10166 p
->rng_fault_state
= true;
10167 return WERR_NOT_SUPPORTED
;
10170 /****************************************************************
10171 _spoolss_DeletePrintProcessor
10172 ****************************************************************/
10174 WERROR
_spoolss_DeletePrintProcessor(struct pipes_struct
*p
,
10175 struct spoolss_DeletePrintProcessor
*r
)
10177 p
->rng_fault_state
= true;
10178 return WERR_NOT_SUPPORTED
;
10181 /****************************************************************
10182 _spoolss_AddPrintProvidor
10183 ****************************************************************/
10185 WERROR
_spoolss_AddPrintProvidor(struct pipes_struct
*p
,
10186 struct spoolss_AddPrintProvidor
*r
)
10188 p
->rng_fault_state
= true;
10189 return WERR_NOT_SUPPORTED
;
10192 /****************************************************************
10193 _spoolss_DeletePrintProvidor
10194 ****************************************************************/
10196 WERROR
_spoolss_DeletePrintProvidor(struct pipes_struct
*p
,
10197 struct spoolss_DeletePrintProvidor
*r
)
10199 p
->rng_fault_state
= true;
10200 return WERR_NOT_SUPPORTED
;
10203 /****************************************************************
10204 _spoolss_FindFirstPrinterChangeNotification
10205 ****************************************************************/
10207 WERROR
_spoolss_FindFirstPrinterChangeNotification(struct pipes_struct
*p
,
10208 struct spoolss_FindFirstPrinterChangeNotification
*r
)
10210 p
->rng_fault_state
= true;
10211 return WERR_NOT_SUPPORTED
;
10214 /****************************************************************
10215 _spoolss_FindNextPrinterChangeNotification
10216 ****************************************************************/
10218 WERROR
_spoolss_FindNextPrinterChangeNotification(struct pipes_struct
*p
,
10219 struct spoolss_FindNextPrinterChangeNotification
*r
)
10221 p
->rng_fault_state
= true;
10222 return WERR_NOT_SUPPORTED
;
10225 /****************************************************************
10226 _spoolss_RouterFindFirstPrinterChangeNotificationOld
10227 ****************************************************************/
10229 WERROR
_spoolss_RouterFindFirstPrinterChangeNotificationOld(struct pipes_struct
*p
,
10230 struct spoolss_RouterFindFirstPrinterChangeNotificationOld
*r
)
10232 p
->rng_fault_state
= true;
10233 return WERR_NOT_SUPPORTED
;
10236 /****************************************************************
10237 _spoolss_ReplyOpenPrinter
10238 ****************************************************************/
10240 WERROR
_spoolss_ReplyOpenPrinter(struct pipes_struct
*p
,
10241 struct spoolss_ReplyOpenPrinter
*r
)
10243 p
->rng_fault_state
= true;
10244 return WERR_NOT_SUPPORTED
;
10247 /****************************************************************
10248 _spoolss_RouterReplyPrinter
10249 ****************************************************************/
10251 WERROR
_spoolss_RouterReplyPrinter(struct pipes_struct
*p
,
10252 struct spoolss_RouterReplyPrinter
*r
)
10254 p
->rng_fault_state
= true;
10255 return WERR_NOT_SUPPORTED
;
10258 /****************************************************************
10259 _spoolss_ReplyClosePrinter
10260 ****************************************************************/
10262 WERROR
_spoolss_ReplyClosePrinter(struct pipes_struct
*p
,
10263 struct spoolss_ReplyClosePrinter
*r
)
10265 p
->rng_fault_state
= true;
10266 return WERR_NOT_SUPPORTED
;
10269 /****************************************************************
10271 ****************************************************************/
10273 WERROR
_spoolss_AddPortEx(struct pipes_struct
*p
,
10274 struct spoolss_AddPortEx
*r
)
10276 p
->rng_fault_state
= true;
10277 return WERR_NOT_SUPPORTED
;
10280 /****************************************************************
10281 _spoolss_RouterFindFirstPrinterChangeNotification
10282 ****************************************************************/
10284 WERROR
_spoolss_RouterFindFirstPrinterChangeNotification(struct pipes_struct
*p
,
10285 struct spoolss_RouterFindFirstPrinterChangeNotification
*r
)
10287 p
->rng_fault_state
= true;
10288 return WERR_NOT_SUPPORTED
;
10291 /****************************************************************
10292 _spoolss_SpoolerInit
10293 ****************************************************************/
10295 WERROR
_spoolss_SpoolerInit(struct pipes_struct
*p
,
10296 struct spoolss_SpoolerInit
*r
)
10298 p
->rng_fault_state
= true;
10299 return WERR_NOT_SUPPORTED
;
10302 /****************************************************************
10303 _spoolss_ResetPrinterEx
10304 ****************************************************************/
10306 WERROR
_spoolss_ResetPrinterEx(struct pipes_struct
*p
,
10307 struct spoolss_ResetPrinterEx
*r
)
10309 p
->rng_fault_state
= true;
10310 return WERR_NOT_SUPPORTED
;
10313 /****************************************************************
10314 _spoolss_RouterReplyPrinterEx
10315 ****************************************************************/
10317 WERROR
_spoolss_RouterReplyPrinterEx(struct pipes_struct
*p
,
10318 struct spoolss_RouterReplyPrinterEx
*r
)
10320 p
->rng_fault_state
= true;
10321 return WERR_NOT_SUPPORTED
;
10324 /****************************************************************
10326 ****************************************************************/
10328 WERROR
_spoolss_44(struct pipes_struct
*p
,
10329 struct spoolss_44
*r
)
10331 p
->rng_fault_state
= true;
10332 return WERR_NOT_SUPPORTED
;
10335 /****************************************************************
10337 ****************************************************************/
10339 WERROR
_spoolss_SetPort(struct pipes_struct
*p
,
10340 struct spoolss_SetPort
*r
)
10342 p
->rng_fault_state
= true;
10343 return WERR_NOT_SUPPORTED
;
10346 /****************************************************************
10348 ****************************************************************/
10350 WERROR
_spoolss_4a(struct pipes_struct
*p
,
10351 struct spoolss_4a
*r
)
10353 p
->rng_fault_state
= true;
10354 return WERR_NOT_SUPPORTED
;
10357 /****************************************************************
10359 ****************************************************************/
10361 WERROR
_spoolss_4b(struct pipes_struct
*p
,
10362 struct spoolss_4b
*r
)
10364 p
->rng_fault_state
= true;
10365 return WERR_NOT_SUPPORTED
;
10368 /****************************************************************
10370 ****************************************************************/
10372 WERROR
_spoolss_4c(struct pipes_struct
*p
,
10373 struct spoolss_4c
*r
)
10375 p
->rng_fault_state
= true;
10376 return WERR_NOT_SUPPORTED
;
10379 /****************************************************************
10381 ****************************************************************/
10383 WERROR
_spoolss_53(struct pipes_struct
*p
,
10384 struct spoolss_53
*r
)
10386 p
->rng_fault_state
= true;
10387 return WERR_NOT_SUPPORTED
;
10390 /****************************************************************
10391 _spoolss_AddPerMachineConnection
10392 ****************************************************************/
10394 WERROR
_spoolss_AddPerMachineConnection(struct pipes_struct
*p
,
10395 struct spoolss_AddPerMachineConnection
*r
)
10397 p
->rng_fault_state
= true;
10398 return WERR_NOT_SUPPORTED
;
10401 /****************************************************************
10402 _spoolss_DeletePerMachineConnection
10403 ****************************************************************/
10405 WERROR
_spoolss_DeletePerMachineConnection(struct pipes_struct
*p
,
10406 struct spoolss_DeletePerMachineConnection
*r
)
10408 p
->rng_fault_state
= true;
10409 return WERR_NOT_SUPPORTED
;
10412 /****************************************************************
10413 _spoolss_EnumPerMachineConnections
10414 ****************************************************************/
10416 WERROR
_spoolss_EnumPerMachineConnections(struct pipes_struct
*p
,
10417 struct spoolss_EnumPerMachineConnections
*r
)
10419 p
->rng_fault_state
= true;
10420 return WERR_NOT_SUPPORTED
;
10423 /****************************************************************
10425 ****************************************************************/
10427 WERROR
_spoolss_5a(struct pipes_struct
*p
,
10428 struct spoolss_5a
*r
)
10430 p
->rng_fault_state
= true;
10431 return WERR_NOT_SUPPORTED
;
10434 /****************************************************************
10436 ****************************************************************/
10438 WERROR
_spoolss_5b(struct pipes_struct
*p
,
10439 struct spoolss_5b
*r
)
10441 p
->rng_fault_state
= true;
10442 return WERR_NOT_SUPPORTED
;
10445 /****************************************************************
10447 ****************************************************************/
10449 WERROR
_spoolss_5c(struct pipes_struct
*p
,
10450 struct spoolss_5c
*r
)
10452 p
->rng_fault_state
= true;
10453 return WERR_NOT_SUPPORTED
;
10456 /****************************************************************
10458 ****************************************************************/
10460 WERROR
_spoolss_5d(struct pipes_struct
*p
,
10461 struct spoolss_5d
*r
)
10463 p
->rng_fault_state
= true;
10464 return WERR_NOT_SUPPORTED
;
10467 /****************************************************************
10469 ****************************************************************/
10471 WERROR
_spoolss_5e(struct pipes_struct
*p
,
10472 struct spoolss_5e
*r
)
10474 p
->rng_fault_state
= true;
10475 return WERR_NOT_SUPPORTED
;
10478 /****************************************************************
10480 ****************************************************************/
10482 WERROR
_spoolss_5f(struct pipes_struct
*p
,
10483 struct spoolss_5f
*r
)
10485 p
->rng_fault_state
= true;
10486 return WERR_NOT_SUPPORTED
;
10489 /****************************************************************
10491 ****************************************************************/
10493 WERROR
_spoolss_60(struct pipes_struct
*p
,
10494 struct spoolss_60
*r
)
10496 p
->rng_fault_state
= true;
10497 return WERR_NOT_SUPPORTED
;
10500 /****************************************************************
10502 ****************************************************************/
10504 WERROR
_spoolss_61(struct pipes_struct
*p
,
10505 struct spoolss_61
*r
)
10507 p
->rng_fault_state
= true;
10508 return WERR_NOT_SUPPORTED
;
10511 /****************************************************************
10513 ****************************************************************/
10515 WERROR
_spoolss_62(struct pipes_struct
*p
,
10516 struct spoolss_62
*r
)
10518 p
->rng_fault_state
= true;
10519 return WERR_NOT_SUPPORTED
;
10522 /****************************************************************
10524 ****************************************************************/
10526 WERROR
_spoolss_63(struct pipes_struct
*p
,
10527 struct spoolss_63
*r
)
10529 p
->rng_fault_state
= true;
10530 return WERR_NOT_SUPPORTED
;
10533 /****************************************************************
10535 ****************************************************************/
10537 WERROR
_spoolss_64(struct pipes_struct
*p
,
10538 struct spoolss_64
*r
)
10540 p
->rng_fault_state
= true;
10541 return WERR_NOT_SUPPORTED
;
10544 /****************************************************************
10546 ****************************************************************/
10548 WERROR
_spoolss_65(struct pipes_struct
*p
,
10549 struct spoolss_65
*r
)
10551 p
->rng_fault_state
= true;
10552 return WERR_NOT_SUPPORTED
;
10555 /****************************************************************
10556 _spoolss_GetCorePrinterDrivers
10557 ****************************************************************/
10559 WERROR
_spoolss_GetCorePrinterDrivers(struct pipes_struct
*p
,
10560 struct spoolss_GetCorePrinterDrivers
*r
)
10562 p
->rng_fault_state
= true;
10563 return WERR_NOT_SUPPORTED
;
10566 /****************************************************************
10568 ****************************************************************/
10570 WERROR
_spoolss_67(struct pipes_struct
*p
,
10571 struct spoolss_67
*r
)
10573 p
->rng_fault_state
= true;
10574 return WERR_NOT_SUPPORTED
;
10577 /****************************************************************
10578 _spoolss_GetPrinterDriverPackagePath
10579 ****************************************************************/
10581 WERROR
_spoolss_GetPrinterDriverPackagePath(struct pipes_struct
*p
,
10582 struct spoolss_GetPrinterDriverPackagePath
*r
)
10584 p
->rng_fault_state
= true;
10585 return WERR_NOT_SUPPORTED
;
10588 /****************************************************************
10590 ****************************************************************/
10592 WERROR
_spoolss_69(struct pipes_struct
*p
,
10593 struct spoolss_69
*r
)
10595 p
->rng_fault_state
= true;
10596 return WERR_NOT_SUPPORTED
;
10599 /****************************************************************
10601 ****************************************************************/
10603 WERROR
_spoolss_6a(struct pipes_struct
*p
,
10604 struct spoolss_6a
*r
)
10606 p
->rng_fault_state
= true;
10607 return WERR_NOT_SUPPORTED
;
10610 /****************************************************************
10612 ****************************************************************/
10614 WERROR
_spoolss_6b(struct pipes_struct
*p
,
10615 struct spoolss_6b
*r
)
10617 p
->rng_fault_state
= true;
10618 return WERR_NOT_SUPPORTED
;
10621 /****************************************************************
10623 ****************************************************************/
10625 WERROR
_spoolss_6c(struct pipes_struct
*p
,
10626 struct spoolss_6c
*r
)
10628 p
->rng_fault_state
= true;
10629 return WERR_NOT_SUPPORTED
;
10632 /****************************************************************
10634 ****************************************************************/
10636 WERROR
_spoolss_6d(struct pipes_struct
*p
,
10637 struct spoolss_6d
*r
)
10639 p
->rng_fault_state
= true;
10640 return WERR_NOT_SUPPORTED
;