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 "librpc/gen_ndr/ndr_security.h"
39 #include "registry/reg_objects.h"
40 #include "include/printing.h"
42 #include "../librpc/gen_ndr/netlogon.h"
45 /* macros stolen from s4 spoolss server */
46 #define SPOOLSS_BUFFER_UNION(fn,info,level) \
47 ((info)?ndr_size_##fn(info, level, 0):0)
49 #define SPOOLSS_BUFFER_UNION_ARRAY(mem_ctx,fn,info,level,count) \
50 ((info)?ndr_size_##fn##_info(mem_ctx, level, count, info):0)
52 #define SPOOLSS_BUFFER_ARRAY(mem_ctx,fn,info,count) \
53 ((info)?ndr_size_##fn##_info(mem_ctx, count, info):0)
55 #define SPOOLSS_BUFFER_OK(val_true,val_false) ((r->in.offered >= *r->out.needed)?val_true:val_false)
58 #define DBGC_CLASS DBGC_RPC_SRV
60 #ifndef MAX_OPEN_PRINTER_EXS
61 #define MAX_OPEN_PRINTER_EXS 50
64 struct notify_back_channel;
66 /* structure to store the printer handles */
67 /* and a reference to what it's pointing to */
68 /* and the notify info asked about */
69 /* that's the central struct */
70 struct printer_handle {
71 struct printer_handle *prev, *next;
72 bool document_started;
74 uint32 jobid; /* jobid in printing backend */
76 const char *servername;
79 uint32 access_granted;
85 struct spoolss_NotifyOption *option;
86 struct policy_handle cli_hnd;
87 struct notify_back_channel *cli_chan;
89 /* are we in a FindNextPrinterChangeNotify() call? */
91 struct messaging_context *msg_ctx;
98 /* devmode sent in the OpenPrinter() call */
99 struct spoolss_DeviceMode *devmode;
101 /* TODO cache the printer info2 structure */
102 struct spoolss_PrinterInfo2 *info2;
106 static struct printer_handle *printers_list;
108 struct printer_session_counter {
109 struct printer_session_counter *next;
110 struct printer_session_counter *prev;
116 static struct printer_session_counter *counter_list;
118 struct notify_back_channel {
119 struct notify_back_channel *prev, *next;
121 /* associated client */
122 struct sockaddr_storage client_address;
124 /* print notify back-channel pipe handle*/
125 struct rpc_pipe_client *cli_pipe;
126 uint32_t active_connections;
129 static struct notify_back_channel *back_channels;
131 /* Map generic permissions to printer object specific permissions */
133 const struct standard_mapping printer_std_mapping = {
140 /* Map generic permissions to print server object specific permissions */
142 const struct standard_mapping printserver_std_mapping = {
149 /* API table for Xcv Monitor functions */
151 struct xcv_api_table {
153 WERROR(*fn) (TALLOC_CTX *mem_ctx, struct security_token *token, DATA_BLOB *in, DATA_BLOB *out, uint32_t *needed);
156 static void prune_printername_cache(void);
158 /********************************************************************
159 * Canonicalize servername.
160 ********************************************************************/
162 static const char *canon_servername(const char *servername)
164 const char *pservername = servername;
165 while (*pservername == '\\') {
171 /* translate between internal status numbers and NT status numbers */
172 static int nt_printj_status(int v)
178 return JOB_STATUS_PAUSED;
180 return JOB_STATUS_SPOOLING;
182 return JOB_STATUS_PRINTING;
184 return JOB_STATUS_ERROR;
186 return JOB_STATUS_DELETING;
188 return JOB_STATUS_OFFLINE;
190 return JOB_STATUS_PAPEROUT;
192 return JOB_STATUS_PRINTED;
194 return JOB_STATUS_DELETED;
196 return JOB_STATUS_BLOCKED_DEVQ;
197 case LPQ_USER_INTERVENTION:
198 return JOB_STATUS_USER_INTERVENTION;
203 static int nt_printq_status(int v)
207 return PRINTER_STATUS_PAUSED;
216 /***************************************************************************
217 Disconnect from the client
218 ****************************************************************************/
220 static void srv_spoolss_replycloseprinter(int snum,
221 struct printer_handle *prn_hnd)
227 * Tell the specific printing tdb we no longer want messages for this printer
228 * by deregistering our PID.
231 if (!print_notify_deregister_pid(snum)) {
232 DEBUG(0, ("Failed to register our pid for printer %s\n",
233 lp_const_servicename(snum)));
236 /* weird if the test succeeds !!! */
237 if (prn_hnd->notify.cli_chan == NULL ||
238 prn_hnd->notify.cli_chan->active_connections == 0) {
239 DEBUG(0, ("Trying to close unexisting backchannel!\n"));
240 DLIST_REMOVE(back_channels, prn_hnd->notify.cli_chan);
241 TALLOC_FREE(prn_hnd->notify.cli_chan);
245 status = rpccli_spoolss_ReplyClosePrinter(
246 prn_hnd->notify.cli_chan->cli_pipe,
248 &prn_hnd->notify.cli_hnd,
250 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
251 DEBUG(0, ("reply_close_printer failed [%s].\n",
252 win_errstr(result)));
255 /* if it's the last connection, deconnect the IPC$ share */
256 if (prn_hnd->notify.cli_chan->active_connections == 1) {
258 cli_shutdown(rpc_pipe_np_smb_conn(prn_hnd->notify.cli_chan->cli_pipe));
259 DLIST_REMOVE(back_channels, prn_hnd->notify.cli_chan);
260 TALLOC_FREE(prn_hnd->notify.cli_chan);
262 if (prn_hnd->notify.msg_ctx != NULL) {
263 messaging_deregister(prn_hnd->notify.msg_ctx,
264 MSG_PRINTER_NOTIFY2, NULL);
267 * Tell the serverid.tdb we're no longer
268 * interested in printer notify messages.
271 serverid_register_msg_flags(
272 messaging_server_id(prn_hnd->notify.msg_ctx),
273 false, FLAG_MSG_PRINT_NOTIFY);
277 if (prn_hnd->notify.cli_chan) {
278 prn_hnd->notify.cli_chan->active_connections--;
282 /****************************************************************************
283 Functions to free a printer entry datastruct.
284 ****************************************************************************/
286 static int printer_entry_destructor(struct printer_handle *Printer)
288 if (Printer->notify.cli_chan != NULL &&
289 Printer->notify.cli_chan->active_connections > 0) {
292 switch(Printer->printer_type) {
294 srv_spoolss_replycloseprinter(snum, Printer);
298 snum = print_queue_snum(Printer->sharename);
300 srv_spoolss_replycloseprinter(snum, Printer);
308 Printer->notify.flags=0;
309 Printer->notify.options=0;
310 Printer->notify.localmachine[0]='\0';
311 Printer->notify.printerlocal=0;
312 TALLOC_FREE(Printer->notify.option);
313 TALLOC_FREE(Printer->devmode);
315 /* Remove from the internal list. */
316 DLIST_REMOVE(printers_list, Printer);
320 /****************************************************************************
321 find printer index by handle
322 ****************************************************************************/
324 static struct printer_handle *find_printer_index_by_hnd(struct pipes_struct *p,
325 struct policy_handle *hnd)
327 struct printer_handle *find_printer = NULL;
329 if(!find_policy_by_hnd(p,hnd,(void **)(void *)&find_printer)) {
330 DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: "));
337 /****************************************************************************
338 Close printer index by handle.
339 ****************************************************************************/
341 static bool close_printer_handle(struct pipes_struct *p, struct policy_handle *hnd)
343 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
346 DEBUG(2,("close_printer_handle: Invalid handle (%s:%u:%u)\n",
351 close_policy_hnd(p, hnd);
356 /****************************************************************************
357 Delete a printer given a handle.
358 ****************************************************************************/
360 static WERROR delete_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
361 const char *sharename,
362 struct messaging_context *msg_ctx)
364 char *cmd = lp_deleteprinter_cmd();
365 char *command = NULL;
367 bool is_print_op = false;
369 /* can't fail if we don't try */
374 command = talloc_asprintf(ctx,
381 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
383 DEBUG(10,("Running [%s]\n", command));
385 /********** BEGIN SePrintOperatorPrivlege BLOCK **********/
390 if ( (ret = smbrun(command, NULL)) == 0 ) {
391 /* Tell everyone we updated smb.conf. */
392 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
398 /********** END SePrintOperatorPrivlege BLOCK **********/
400 DEBUGADD(10,("returned [%d]\n", ret));
402 TALLOC_FREE(command);
405 return WERR_BADFID; /* What to return here? */
407 /* go ahead and re-read the services immediately */
409 reload_services(msg_ctx, -1, false);
412 if ( lp_servicenumber( sharename ) >= 0 )
413 return WERR_ACCESS_DENIED;
418 /****************************************************************************
419 Delete a printer given a handle.
420 ****************************************************************************/
422 static WERROR delete_printer_handle(struct pipes_struct *p, struct policy_handle *hnd)
424 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
428 DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n",
434 * It turns out that Windows allows delete printer on a handle
435 * opened by an admin user, then used on a pipe handle created
436 * by an anonymous user..... but they're working on security.... riiight !
440 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
441 DEBUG(3, ("delete_printer_handle: denied by handle\n"));
442 return WERR_ACCESS_DENIED;
445 /* this does not need a become root since the access check has been
446 done on the handle already */
448 result = winreg_delete_printer_key(p->mem_ctx,
449 get_server_info_system(),
453 if (!W_ERROR_IS_OK(result)) {
454 DEBUG(3,("Error deleting printer %s\n", Printer->sharename));
458 result = delete_printer_hook(p->mem_ctx, p->server_info->ptok,
459 Printer->sharename, p->msg_ctx);
460 if (!W_ERROR_IS_OK(result)) {
463 prune_printername_cache();
467 /****************************************************************************
468 Return the snum of a printer corresponding to an handle.
469 ****************************************************************************/
471 static bool get_printer_snum(struct pipes_struct *p, struct policy_handle *hnd,
472 int *number, struct share_params **params)
474 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
477 DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n",
482 switch (Printer->printer_type) {
484 DEBUG(4,("short name:%s\n", Printer->sharename));
485 *number = print_queue_snum(Printer->sharename);
486 return (*number != -1);
494 /****************************************************************************
495 Set printer handle type.
496 Check if it's \\server or \\server\printer
497 ****************************************************************************/
499 static bool set_printer_hnd_printertype(struct printer_handle *Printer, const char *handlename)
501 DEBUG(3,("Setting printer type=%s\n", handlename));
503 /* it's a print server */
504 if (handlename && *handlename=='\\' && *(handlename+1)=='\\' && !strchr_m(handlename+2, '\\')) {
505 DEBUGADD(4,("Printer is a print server\n"));
506 Printer->printer_type = SPLHND_SERVER;
508 /* it's a printer (set_printer_hnd_name() will handle port monitors */
510 DEBUGADD(4,("Printer is a printer\n"));
511 Printer->printer_type = SPLHND_PRINTER;
517 static void prune_printername_cache_fn(const char *key, const char *value,
518 time_t timeout, void *private_data)
523 static void prune_printername_cache(void)
525 gencache_iterate(prune_printername_cache_fn, NULL, "PRINTERNAME/*");
528 /****************************************************************************
529 Set printer handle name.. Accept names like \\server, \\server\printer,
530 \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
531 the MSDN docs regarding OpenPrinter() for details on the XcvData() and
532 XcvDataPort() interface.
533 ****************************************************************************/
535 static bool set_printer_hnd_name(TALLOC_CTX *mem_ctx,
536 const struct auth_serversupplied_info *server_info,
537 struct messaging_context *msg_ctx,
538 struct printer_handle *Printer,
539 const char *handlename)
542 int n_services=lp_numservices();
544 const char *printername;
545 const char *servername = NULL;
548 struct spoolss_PrinterInfo2 *info2 = NULL;
553 * Hopefully nobody names his printers like this. Maybe \ or ,
554 * are illegal in printer names even?
556 const char printer_not_found[] = "Printer \\, !@#$%^&*( not found";
560 DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename,
561 (unsigned long)strlen(handlename)));
563 aprinter = CONST_DISCARD(char *, handlename);
564 if ( *handlename == '\\' ) {
565 servername = canon_servername(handlename);
566 if ( (aprinter = strchr_m( servername, '\\' )) != NULL ) {
570 if (!is_myname_or_ipaddr(servername)) {
573 Printer->servername = talloc_asprintf(Printer, "\\\\%s", servername);
574 if (Printer->servername == NULL) {
579 if (Printer->printer_type == SPLHND_SERVER) {
583 if (Printer->printer_type != SPLHND_PRINTER) {
587 DEBUGADD(5, ("searching for [%s]\n", aprinter));
589 if ((p = strchr(aprinter, ',')) != NULL) {
592 if (strnequal(p+1, "DrvConvert", strlen("DrvConvert")) ||
593 strnequal(p+1, " DrvConvert", strlen(" DrvConvert"))) {
595 } else if (strnequal(p+1, "LocalOnly", strlen("LocalOnly")) ||
596 strnequal(p+1, " LocalOnly", strlen(" LocalOnly"))) {
601 /* check for the Port Monitor Interface */
602 if ( strequal( aprinter, SPL_XCV_MONITOR_TCPMON ) ) {
603 Printer->printer_type = SPLHND_PORTMON_TCP;
604 fstrcpy(sname, SPL_XCV_MONITOR_TCPMON);
607 else if ( strequal( aprinter, SPL_XCV_MONITOR_LOCALMON ) ) {
608 Printer->printer_type = SPLHND_PORTMON_LOCAL;
609 fstrcpy(sname, SPL_XCV_MONITOR_LOCALMON);
614 * With hundreds of printers, the "for" loop iterating all
615 * shares can be quite expensive, as it is done on every
616 * OpenPrinter. The loop maps "aprinter" to "sname", the
617 * result of which we cache in gencache.
620 cache_key = talloc_asprintf(talloc_tos(), "PRINTERNAME/%s",
622 if ((cache_key != NULL) && gencache_get(cache_key, &tmp, NULL)) {
624 found = (strcmp(tmp, printer_not_found) != 0);
626 DEBUG(4, ("Printer %s not found\n", aprinter));
634 /* Search all sharenames first as this is easier than pulling
635 the printer_info_2 off of disk. Don't use find_service() since
636 that calls out to map_username() */
638 /* do another loop to look for printernames */
639 for (snum = 0; !found && snum < n_services; snum++) {
640 const char *printer = lp_const_servicename(snum);
642 /* no point going on if this is not a printer */
643 if (!(lp_snum_ok(snum) && lp_print_ok(snum))) {
647 /* ignore [printers] share */
648 if (strequal(printer, "printers")) {
652 fstrcpy(sname, printer);
653 if (strequal(aprinter, printer)) {
658 /* no point looking up the printer object if
659 we aren't allowing printername != sharename */
660 if (lp_force_printername(snum)) {
664 result = winreg_get_printer(mem_ctx,
669 if ( !W_ERROR_IS_OK(result) ) {
670 DEBUG(2,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
671 sname, win_errstr(result)));
675 printername = strrchr(info2->printername, '\\');
676 if (printername == NULL) {
677 printername = info2->printername;
682 if (strequal(printername, aprinter)) {
687 DEBUGADD(10, ("printername: %s\n", printername));
693 if (cache_key != NULL) {
694 gencache_set(cache_key, printer_not_found,
696 TALLOC_FREE(cache_key);
698 DEBUGADD(4,("Printer not found\n"));
702 if (cache_key != NULL) {
703 gencache_set(cache_key, sname, time(NULL)+300);
704 TALLOC_FREE(cache_key);
707 DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter, sname));
709 fstrcpy(Printer->sharename, sname);
714 /****************************************************************************
715 Find first available printer slot. creates a printer handle for you.
716 ****************************************************************************/
718 static bool open_printer_hnd(struct pipes_struct *p, struct policy_handle *hnd,
719 const char *name, uint32_t access_granted)
721 struct printer_handle *new_printer;
723 DEBUG(10,("open_printer_hnd: name [%s]\n", name));
725 new_printer = talloc_zero(p->mem_ctx, struct printer_handle);
726 if (new_printer == NULL) {
729 talloc_set_destructor(new_printer, printer_entry_destructor);
731 /* This also steals the printer_handle on the policy_handle */
732 if (!create_policy_hnd(p, hnd, new_printer)) {
733 TALLOC_FREE(new_printer);
737 /* Add to the internal list. */
738 DLIST_ADD(printers_list, new_printer);
740 new_printer->notify.option=NULL;
742 if (!set_printer_hnd_printertype(new_printer, name)) {
743 close_printer_handle(p, hnd);
747 if (!set_printer_hnd_name(p->mem_ctx,
748 get_server_info_system(),
750 new_printer, name)) {
751 close_printer_handle(p, hnd);
755 new_printer->access_granted = access_granted;
757 DEBUG(5, ("%d printer handles active\n",
758 (int)num_pipe_handles(p)));
763 /***************************************************************************
764 check to see if the client motify handle is monitoring the notification
765 given by (notify_type, notify_field).
766 **************************************************************************/
768 static bool is_monitoring_event_flags(uint32_t flags, uint16_t notify_type,
769 uint16_t notify_field)
774 static bool is_monitoring_event(struct printer_handle *p, uint16_t notify_type,
775 uint16_t notify_field)
777 struct spoolss_NotifyOption *option = p->notify.option;
781 * Flags should always be zero when the change notify
782 * is registered by the client's spooler. A user Win32 app
783 * might use the flags though instead of the NOTIFY_OPTION_INFO
792 return is_monitoring_event_flags(
793 p->notify.flags, notify_type, notify_field);
795 for (i = 0; i < option->count; i++) {
797 /* Check match for notify_type */
799 if (option->types[i].type != notify_type)
802 /* Check match for field */
804 for (j = 0; j < option->types[i].count; j++) {
805 if (option->types[i].fields[j].field == notify_field) {
811 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
812 p->servername, p->sharename, notify_type, notify_field));
817 #define SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(_data, _integer) \
818 _data->data.integer[0] = _integer; \
819 _data->data.integer[1] = 0;
822 #define SETUP_SPOOLSS_NOTIFY_DATA_STRING(_data, _p) \
823 _data->data.string.string = talloc_strdup(mem_ctx, _p); \
824 if (!_data->data.string.string) {\
825 _data->data.string.size = 0; \
827 _data->data.string.size = strlen_m_term(_p) * 2;
829 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
830 _data->data.devmode.devmode = _devmode;
832 #define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _sd) \
833 _data->data.sd.sd = dup_sec_desc(mem_ctx, _sd); \
834 if (!_data->data.sd.sd) { \
835 _data->data.sd.sd_size = 0; \
837 _data->data.sd.sd_size = \
838 ndr_size_security_descriptor(_data->data.sd.sd, 0);
840 static void init_systemtime_buffer(TALLOC_CTX *mem_ctx,
845 struct spoolss_Time st;
849 if (!init_systemtime(&st, t)) {
853 p = talloc_array(mem_ctx, char, len);
859 * Systemtime must be linearized as a set of UINT16's.
860 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
863 SSVAL(p, 0, st.year);
864 SSVAL(p, 2, st.month);
865 SSVAL(p, 4, st.day_of_week);
867 SSVAL(p, 8, st.hour);
868 SSVAL(p, 10, st.minute);
869 SSVAL(p, 12, st.second);
870 SSVAL(p, 14, st.millisecond);
876 /* Convert a notification message to a struct spoolss_Notify */
878 static void notify_one_value(struct spoolss_notify_msg *msg,
879 struct spoolss_Notify *data,
882 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, msg->notify.value[0]);
885 static void notify_string(struct spoolss_notify_msg *msg,
886 struct spoolss_Notify *data,
889 /* The length of the message includes the trailing \0 */
891 data->data.string.size = msg->len * 2;
892 data->data.string.string = talloc_strdup(mem_ctx, msg->notify.data);
893 if (!data->data.string.string) {
894 data->data.string.size = 0;
899 static void notify_system_time(struct spoolss_notify_msg *msg,
900 struct spoolss_Notify *data,
903 data->data.string.string = NULL;
904 data->data.string.size = 0;
906 if (msg->len != sizeof(time_t)) {
907 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
912 init_systemtime_buffer(mem_ctx, gmtime((time_t *)msg->notify.data),
913 &data->data.string.string,
914 &data->data.string.size);
917 struct notify2_message_table {
919 void (*fn)(struct spoolss_notify_msg *msg,
920 struct spoolss_Notify *data, TALLOC_CTX *mem_ctx);
923 static struct notify2_message_table printer_notify_table[] = {
924 /* 0x00 */ { "PRINTER_NOTIFY_FIELD_SERVER_NAME", notify_string },
925 /* 0x01 */ { "PRINTER_NOTIFY_FIELD_PRINTER_NAME", notify_string },
926 /* 0x02 */ { "PRINTER_NOTIFY_FIELD_SHARE_NAME", notify_string },
927 /* 0x03 */ { "PRINTER_NOTIFY_FIELD_PORT_NAME", notify_string },
928 /* 0x04 */ { "PRINTER_NOTIFY_FIELD_DRIVER_NAME", notify_string },
929 /* 0x05 */ { "PRINTER_NOTIFY_FIELD_COMMENT", notify_string },
930 /* 0x06 */ { "PRINTER_NOTIFY_FIELD_LOCATION", notify_string },
931 /* 0x07 */ { "PRINTER_NOTIFY_FIELD_DEVMODE", NULL },
932 /* 0x08 */ { "PRINTER_NOTIFY_FIELD_SEPFILE", notify_string },
933 /* 0x09 */ { "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", notify_string },
934 /* 0x0a */ { "PRINTER_NOTIFY_FIELD_PARAMETERS", NULL },
935 /* 0x0b */ { "PRINTER_NOTIFY_FIELD_DATATYPE", notify_string },
936 /* 0x0c */ { "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
937 /* 0x0d */ { "PRINTER_NOTIFY_FIELD_ATTRIBUTES", notify_one_value },
938 /* 0x0e */ { "PRINTER_NOTIFY_FIELD_PRIORITY", notify_one_value },
939 /* 0x0f */ { "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NULL },
940 /* 0x10 */ { "PRINTER_NOTIFY_FIELD_START_TIME", NULL },
941 /* 0x11 */ { "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NULL },
942 /* 0x12 */ { "PRINTER_NOTIFY_FIELD_STATUS", notify_one_value },
945 static struct notify2_message_table job_notify_table[] = {
946 /* 0x00 */ { "JOB_NOTIFY_FIELD_PRINTER_NAME", NULL },
947 /* 0x01 */ { "JOB_NOTIFY_FIELD_MACHINE_NAME", NULL },
948 /* 0x02 */ { "JOB_NOTIFY_FIELD_PORT_NAME", NULL },
949 /* 0x03 */ { "JOB_NOTIFY_FIELD_USER_NAME", notify_string },
950 /* 0x04 */ { "JOB_NOTIFY_FIELD_NOTIFY_NAME", NULL },
951 /* 0x05 */ { "JOB_NOTIFY_FIELD_DATATYPE", NULL },
952 /* 0x06 */ { "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NULL },
953 /* 0x07 */ { "JOB_NOTIFY_FIELD_PARAMETERS", NULL },
954 /* 0x08 */ { "JOB_NOTIFY_FIELD_DRIVER_NAME", NULL },
955 /* 0x09 */ { "JOB_NOTIFY_FIELD_DEVMODE", NULL },
956 /* 0x0a */ { "JOB_NOTIFY_FIELD_STATUS", notify_one_value },
957 /* 0x0b */ { "JOB_NOTIFY_FIELD_STATUS_STRING", NULL },
958 /* 0x0c */ { "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
959 /* 0x0d */ { "JOB_NOTIFY_FIELD_DOCUMENT", notify_string },
960 /* 0x0e */ { "JOB_NOTIFY_FIELD_PRIORITY", NULL },
961 /* 0x0f */ { "JOB_NOTIFY_FIELD_POSITION", NULL },
962 /* 0x10 */ { "JOB_NOTIFY_FIELD_SUBMITTED", notify_system_time },
963 /* 0x11 */ { "JOB_NOTIFY_FIELD_START_TIME", NULL },
964 /* 0x12 */ { "JOB_NOTIFY_FIELD_UNTIL_TIME", NULL },
965 /* 0x13 */ { "JOB_NOTIFY_FIELD_TIME", NULL },
966 /* 0x14 */ { "JOB_NOTIFY_FIELD_TOTAL_PAGES", notify_one_value },
967 /* 0x15 */ { "JOB_NOTIFY_FIELD_PAGES_PRINTED", NULL },
968 /* 0x16 */ { "JOB_NOTIFY_FIELD_TOTAL_BYTES", notify_one_value },
969 /* 0x17 */ { "JOB_NOTIFY_FIELD_BYTES_PRINTED", NULL },
973 /***********************************************************************
974 Allocate talloc context for container object
975 **********************************************************************/
977 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR *ctr )
982 ctr->ctx = talloc_init("notify_msg_ctr_init %p", ctr);
987 /***********************************************************************
988 release all allocated memory and zero out structure
989 **********************************************************************/
991 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR *ctr )
997 talloc_destroy(ctr->ctx);
1004 /***********************************************************************
1005 **********************************************************************/
1007 static TALLOC_CTX* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1015 /***********************************************************************
1016 **********************************************************************/
1018 static SPOOLSS_NOTIFY_MSG_GROUP* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
1020 if ( !ctr || !ctr->msg_groups )
1023 if ( idx >= ctr->num_groups )
1026 return &ctr->msg_groups[idx];
1030 /***********************************************************************
1031 How many groups of change messages do we have ?
1032 **********************************************************************/
1034 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1039 return ctr->num_groups;
1042 /***********************************************************************
1043 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
1044 **********************************************************************/
1046 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MSG *msg )
1048 SPOOLSS_NOTIFY_MSG_GROUP *groups = NULL;
1049 SPOOLSS_NOTIFY_MSG_GROUP *msg_grp = NULL;
1050 SPOOLSS_NOTIFY_MSG *msg_list = NULL;
1056 /* loop over all groups looking for a matching printer name */
1058 for ( i=0; i<ctr->num_groups; i++ ) {
1059 if ( strcmp(ctr->msg_groups[i].printername, msg->printer) == 0 )
1063 /* add a new group? */
1065 if ( i == ctr->num_groups ) {
1068 if ( !(groups = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->msg_groups, SPOOLSS_NOTIFY_MSG_GROUP, ctr->num_groups)) ) {
1069 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
1072 ctr->msg_groups = groups;
1074 /* clear the new entry and set the printer name */
1076 ZERO_STRUCT( ctr->msg_groups[ctr->num_groups-1] );
1077 fstrcpy( ctr->msg_groups[ctr->num_groups-1].printername, msg->printer );
1080 /* add the change messages; 'i' is the correct index now regardless */
1082 msg_grp = &ctr->msg_groups[i];
1084 msg_grp->num_msgs++;
1086 if ( !(msg_list = TALLOC_REALLOC_ARRAY( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) {
1087 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs));
1090 msg_grp->msgs = msg_list;
1092 new_slot = msg_grp->num_msgs-1;
1093 memcpy( &msg_grp->msgs[new_slot], msg, sizeof(SPOOLSS_NOTIFY_MSG) );
1095 /* need to allocate own copy of data */
1097 if ( msg->len != 0 )
1098 msg_grp->msgs[new_slot].notify.data = (char *)
1099 TALLOC_MEMDUP( ctr->ctx, msg->notify.data, msg->len );
1101 return ctr->num_groups;
1104 static void construct_info_data(struct spoolss_Notify *info_data,
1105 enum spoolss_NotifyType type,
1106 uint16_t field, int id);
1108 /***********************************************************************
1109 Send a change notication message on all handles which have a call
1111 **********************************************************************/
1113 static int build_notify2_messages(TALLOC_CTX *mem_ctx,
1114 struct printer_handle *prn_hnd,
1115 SPOOLSS_NOTIFY_MSG *messages,
1117 struct spoolss_Notify **_notifies,
1120 struct spoolss_Notify *notifies;
1121 SPOOLSS_NOTIFY_MSG *msg;
1126 notifies = talloc_zero_array(mem_ctx,
1127 struct spoolss_Notify, num_msgs);
1132 for (i = 0; i < num_msgs; i++) {
1136 /* Are we monitoring this event? */
1138 if (!is_monitoring_event(prn_hnd, msg->type, msg->field)) {
1142 DEBUG(10, ("Sending message type [0x%x] field [0x%2x] "
1143 "for printer [%s]\n",
1144 msg->type, msg->field, prn_hnd->sharename));
1147 * if the is a printer notification handle and not a job
1148 * notification type, then set the id to 0.
1149 * Otherwise just use what was specified in the message.
1151 * When registering change notification on a print server
1152 * handle we always need to send back the id (snum) matching
1153 * the printer for which the change took place.
1154 * For change notify registered on a printer handle,
1155 * this does not matter and the id should be 0.
1160 if ((msg->type == PRINTER_NOTIFY_TYPE) &&
1161 (prn_hnd->printer_type == SPLHND_PRINTER)) {
1167 /* Convert unix jobid to smb jobid */
1169 if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) {
1170 id = sysjob_to_jobid(msg->id);
1173 DEBUG(3, ("no such unix jobid %d\n",
1179 construct_info_data(¬ifies[count],
1180 msg->type, msg->field, id);
1183 case PRINTER_NOTIFY_TYPE:
1184 if (printer_notify_table[msg->field].fn) {
1185 printer_notify_table[msg->field].fn(msg,
1186 ¬ifies[count], mem_ctx);
1190 case JOB_NOTIFY_TYPE:
1191 if (job_notify_table[msg->field].fn) {
1192 job_notify_table[msg->field].fn(msg,
1193 ¬ifies[count], mem_ctx);
1198 DEBUG(5, ("Unknown notification type %d\n",
1206 *_notifies = notifies;
1212 static int send_notify2_printer(TALLOC_CTX *mem_ctx,
1213 struct printer_handle *prn_hnd,
1214 SPOOLSS_NOTIFY_MSG_GROUP *msg_group)
1216 struct spoolss_Notify *notifies;
1218 union spoolss_ReplyPrinterInfo info;
1219 struct spoolss_NotifyInfo info0;
1220 uint32_t reply_result;
1225 /* Is there notification on this handle? */
1226 if (prn_hnd->notify.cli_chan == NULL ||
1227 prn_hnd->notify.cli_chan->active_connections == 0) {
1231 DEBUG(10, ("Client connected! [\\\\%s\\%s]\n",
1232 prn_hnd->servername, prn_hnd->sharename));
1234 /* For this printer? Print servers always receive notifications. */
1235 if ((prn_hnd->printer_type == SPLHND_PRINTER) &&
1236 (!strequal(msg_group->printername, prn_hnd->sharename))) {
1240 DEBUG(10,("Our printer\n"));
1242 /* build the array of change notifications */
1243 ret = build_notify2_messages(mem_ctx, prn_hnd,
1245 msg_group->num_msgs,
1251 info0.version = 0x2;
1252 info0.flags = count ? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED;
1253 info0.count = count;
1254 info0.notifies = notifies;
1256 info.info0 = &info0;
1258 status = rpccli_spoolss_RouterReplyPrinterEx(
1259 prn_hnd->notify.cli_chan->cli_pipe,
1261 &prn_hnd->notify.cli_hnd,
1262 prn_hnd->notify.change, /* color */
1263 prn_hnd->notify.flags,
1265 0, /* reply_type, must be 0 */
1267 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(werr)) {
1268 DEBUG(1, ("RouterReplyPrinterEx to client: %s "
1270 prn_hnd->notify.cli_chan->cli_pipe->srv_name_slash,
1273 switch (reply_result) {
1276 case PRINTER_NOTIFY_INFO_DISCARDED:
1277 case PRINTER_NOTIFY_INFO_DISCARDNOTED:
1278 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH:
1287 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
1289 struct printer_handle *p;
1290 TALLOC_CTX *mem_ctx = notify_ctr_getctx( ctr );
1291 SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx );
1295 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
1299 if (!msg_group->msgs) {
1300 DEBUG(5, ("send_notify2_changes() called with no messages!\n"));
1304 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername));
1306 /* loop over all printers */
1308 for (p = printers_list; p; p = p->next) {
1309 ret = send_notify2_printer(mem_ctx, p, msg_group);
1316 DEBUG(8,("send_notify2_changes: Exit...\n"));
1320 /***********************************************************************
1321 **********************************************************************/
1323 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, void *buf, size_t len )
1326 uint32_t tv_sec, tv_usec;
1329 /* Unpack message */
1331 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "f",
1334 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "ddddddd",
1336 &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags);
1339 tdb_unpack((uint8_t *)buf + offset, len - offset, "dd",
1340 &msg->notify.value[0], &msg->notify.value[1]);
1342 tdb_unpack((uint8_t *)buf + offset, len - offset, "B",
1343 &msg->len, &msg->notify.data);
1345 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1346 msg->printer, (unsigned int)msg->id, msg->type, msg->field, msg->flags));
1348 tv->tv_sec = tv_sec;
1349 tv->tv_usec = tv_usec;
1352 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg->notify.value[0],
1353 msg->notify.value[1]));
1355 dump_data(3, (uint8_t *)msg->notify.data, msg->len);
1360 /********************************************************************
1361 Receive a notify2 message list
1362 ********************************************************************/
1364 static void receive_notify2_message_list(struct messaging_context *msg,
1367 struct server_id server_id,
1370 size_t msg_count, i;
1371 char *buf = (char *)data->data;
1374 SPOOLSS_NOTIFY_MSG notify;
1375 SPOOLSS_NOTIFY_MSG_CTR messages;
1378 if (data->length < 4) {
1379 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1383 msg_count = IVAL(buf, 0);
1386 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count));
1388 if (msg_count == 0) {
1389 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1393 /* initialize the container */
1395 ZERO_STRUCT( messages );
1396 notify_msg_ctr_init( &messages );
1399 * build message groups for each printer identified
1400 * in a change_notify msg. Remember that a PCN message
1401 * includes the handle returned for the srv_spoolss_replyopenprinter()
1402 * call. Therefore messages are grouped according to printer handle.
1405 for ( i=0; i<msg_count; i++ ) {
1406 struct timeval msg_tv;
1408 if (msg_ptr + 4 - buf > data->length) {
1409 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1413 msg_len = IVAL(msg_ptr,0);
1416 if (msg_ptr + msg_len - buf > data->length) {
1417 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1421 /* unpack messages */
1423 ZERO_STRUCT( notify );
1424 notify2_unpack_msg( ¬ify, &msg_tv, msg_ptr, msg_len );
1427 /* add to correct list in container */
1429 notify_msg_ctr_addmsg( &messages, ¬ify );
1431 /* free memory that might have been allocated by notify2_unpack_msg() */
1433 if ( notify.len != 0 )
1434 SAFE_FREE( notify.notify.data );
1437 /* process each group of messages */
1439 num_groups = notify_msg_ctr_numgroups( &messages );
1440 for ( i=0; i<num_groups; i++ )
1441 send_notify2_changes( &messages, i );
1446 DEBUG(10,("receive_notify2_message_list: processed %u messages\n",
1447 (uint32_t)msg_count ));
1449 notify_msg_ctr_destroy( &messages );
1454 /********************************************************************
1455 Send a message to ourself about new driver being installed
1456 so we can upgrade the information for each printer bound to this
1458 ********************************************************************/
1460 static bool srv_spoolss_drv_upgrade_printer(const char *drivername,
1461 struct messaging_context *msg_ctx)
1463 int len = strlen(drivername);
1468 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1471 messaging_send_buf(msg_ctx, messaging_server_id(msg_ctx),
1472 MSG_PRINTER_DRVUPGRADE,
1473 (uint8_t *)drivername, len+1);
1478 void srv_spoolss_cleanup(void)
1480 struct printer_session_counter *session_counter;
1482 for (session_counter = counter_list;
1483 session_counter != NULL;
1484 session_counter = counter_list) {
1485 DLIST_REMOVE(counter_list, session_counter);
1486 TALLOC_FREE(session_counter);
1490 /**********************************************************************
1491 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1492 over all printers, upgrading ones as necessary
1493 **********************************************************************/
1495 void do_drv_upgrade_printer(struct messaging_context *msg,
1498 struct server_id server_id,
1501 TALLOC_CTX *tmp_ctx;
1502 struct auth_serversupplied_info *server_info = NULL;
1503 struct spoolss_PrinterInfo2 *pinfo2;
1506 const char *drivername;
1508 int n_services = lp_numservices();
1510 tmp_ctx = talloc_new(NULL);
1511 if (!tmp_ctx) return;
1513 status = make_server_info_system(tmp_ctx, &server_info);
1514 if (!NT_STATUS_IS_OK(status)) {
1515 DEBUG(0, ("do_drv_upgrade_printer: "
1516 "Could not create system server_info\n"));
1520 drivername = talloc_strndup(tmp_ctx, (const char *)data->data, data->length);
1522 DEBUG(0, ("do_drv_upgrade_printer: Out of memoery ?!\n"));
1526 DEBUG(10, ("do_drv_upgrade_printer: "
1527 "Got message for new driver [%s]\n", drivername));
1529 /* Iterate the printer list */
1531 for (snum = 0; snum < n_services; snum++) {
1532 if (!lp_snum_ok(snum) || !lp_print_ok(snum)) {
1536 /* ignore [printers] share */
1537 if (strequal(lp_const_servicename(snum), "printers")) {
1541 result = winreg_get_printer(tmp_ctx, server_info, msg,
1542 lp_const_servicename(snum),
1545 if (!W_ERROR_IS_OK(result)) {
1549 if (!pinfo2->drivername) {
1553 if (strcmp(drivername, pinfo2->drivername) != 0) {
1557 DEBUG(6,("Updating printer [%s]\n", pinfo2->printername));
1559 /* all we care about currently is the change_id */
1560 result = winreg_printer_update_changeid(tmp_ctx,
1563 pinfo2->printername);
1565 if (!W_ERROR_IS_OK(result)) {
1566 DEBUG(3, ("do_drv_upgrade_printer: "
1567 "Failed to update changeid [%s]\n",
1568 win_errstr(result)));
1574 talloc_free(tmp_ctx);
1577 /********************************************************************
1578 Update the cache for all printq's with a registered client
1580 ********************************************************************/
1582 void update_monitored_printq_cache(struct messaging_context *msg_ctx)
1584 struct printer_handle *printer = printers_list;
1587 /* loop through all printers and update the cache where
1588 a client is connected */
1590 if ((printer->printer_type == SPLHND_PRINTER) &&
1591 ((printer->notify.cli_chan != NULL) &&
1592 (printer->notify.cli_chan->active_connections > 0))) {
1593 snum = print_queue_snum(printer->sharename);
1594 print_queue_status(msg_ctx, snum, NULL, NULL);
1597 printer = printer->next;
1603 /****************************************************************
1604 _spoolss_OpenPrinter
1605 ****************************************************************/
1607 WERROR _spoolss_OpenPrinter(struct pipes_struct *p,
1608 struct spoolss_OpenPrinter *r)
1610 struct spoolss_OpenPrinterEx e;
1613 ZERO_STRUCT(e.in.userlevel);
1615 e.in.printername = r->in.printername;
1616 e.in.datatype = r->in.datatype;
1617 e.in.devmode_ctr = r->in.devmode_ctr;
1618 e.in.access_mask = r->in.access_mask;
1621 e.out.handle = r->out.handle;
1623 werr = _spoolss_OpenPrinterEx(p, &e);
1625 if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
1626 /* OpenPrinterEx returns this for a bad
1627 * printer name. We must return WERR_INVALID_PRINTER_NAME
1630 werr = WERR_INVALID_PRINTER_NAME;
1636 static WERROR copy_devicemode(TALLOC_CTX *mem_ctx,
1637 struct spoolss_DeviceMode *orig,
1638 struct spoolss_DeviceMode **dest)
1640 struct spoolss_DeviceMode *dm;
1642 dm = talloc(mem_ctx, struct spoolss_DeviceMode);
1647 /* copy all values, then duplicate strings and structs */
1650 dm->devicename = talloc_strdup(dm, orig->devicename);
1651 if (!dm->devicename) {
1654 dm->formname = talloc_strdup(dm, orig->formname);
1655 if (!dm->formname) {
1658 if (orig->driverextra_data.data) {
1659 dm->driverextra_data.data =
1660 (uint8_t *) talloc_memdup(dm, orig->driverextra_data.data,
1661 orig->driverextra_data.length);
1662 if (!dm->driverextra_data.data) {
1671 /****************************************************************
1672 _spoolss_OpenPrinterEx
1673 ****************************************************************/
1675 WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
1676 struct spoolss_OpenPrinterEx *r)
1679 struct printer_handle *Printer=NULL;
1681 if (!r->in.printername) {
1682 return WERR_INVALID_PARAM;
1685 /* some sanity check because you can open a printer or a print server */
1686 /* aka: \\server\printer or \\server */
1688 DEBUGADD(3,("checking name: %s\n", r->in.printername));
1690 if (!open_printer_hnd(p, r->out.handle, r->in.printername, 0)) {
1691 DEBUG(0,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
1692 "for printer %s\n", r->in.printername));
1693 ZERO_STRUCTP(r->out.handle);
1694 return WERR_INVALID_PARAM;
1697 Printer = find_printer_index_by_hnd(p, r->out.handle);
1699 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1700 "handle we created for printer %s\n", r->in.printername));
1701 close_printer_handle(p, r->out.handle);
1702 ZERO_STRUCTP(r->out.handle);
1703 return WERR_INVALID_PARAM;
1707 * First case: the user is opening the print server:
1709 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1710 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1712 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1713 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1714 * or if the user is listed in the smb.conf printer admin parameter.
1716 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1717 * client view printer folder, but does not show the MSAPW.
1719 * Note: this test needs code to check access rights here too. Jeremy
1720 * could you look at this?
1722 * Second case: the user is opening a printer:
1723 * NT doesn't let us connect to a printer if the connecting user
1724 * doesn't have print permission.
1726 * Third case: user is opening a Port Monitor
1727 * access checks same as opening a handle to the print server.
1730 switch (Printer->printer_type )
1733 case SPLHND_PORTMON_TCP:
1734 case SPLHND_PORTMON_LOCAL:
1735 /* Printserver handles use global struct... */
1739 /* Map standard access rights to object specific access rights */
1741 se_map_standard(&r->in.access_mask,
1742 &printserver_std_mapping);
1744 /* Deny any object specific bits that don't apply to print
1745 servers (i.e printer and job specific bits) */
1747 r->in.access_mask &= SEC_MASK_SPECIFIC;
1749 if (r->in.access_mask &
1750 ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) {
1751 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1752 close_printer_handle(p, r->out.handle);
1753 ZERO_STRUCTP(r->out.handle);
1754 return WERR_ACCESS_DENIED;
1757 /* Allow admin access */
1759 if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
1761 if (!lp_ms_add_printer_wizard()) {
1762 close_printer_handle(p, r->out.handle);
1763 ZERO_STRUCTP(r->out.handle);
1764 return WERR_ACCESS_DENIED;
1767 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1768 and not a printer admin, then fail */
1770 if ((p->server_info->utok.uid != sec_initial_uid()) &&
1771 !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR) &&
1772 !token_contains_name_in_list(
1773 uidtoname(p->server_info->utok.uid),
1774 p->server_info->info3->base.domain.string,
1776 p->server_info->ptok,
1777 lp_printer_admin(snum))) {
1778 close_printer_handle(p, r->out.handle);
1779 ZERO_STRUCTP(r->out.handle);
1780 return WERR_ACCESS_DENIED;
1783 r->in.access_mask = SERVER_ACCESS_ADMINISTER;
1787 r->in.access_mask = SERVER_ACCESS_ENUMERATE;
1790 DEBUG(4,("Setting print server access = %s\n", (r->in.access_mask == SERVER_ACCESS_ADMINISTER)
1791 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1793 /* We fall through to return WERR_OK */
1796 case SPLHND_PRINTER:
1797 /* NT doesn't let us connect to a printer if the connecting user
1798 doesn't have print permission. */
1800 if (!get_printer_snum(p, r->out.handle, &snum, NULL)) {
1801 close_printer_handle(p, r->out.handle);
1802 ZERO_STRUCTP(r->out.handle);
1806 if (r->in.access_mask == SEC_FLAG_MAXIMUM_ALLOWED) {
1807 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1810 se_map_standard(&r->in.access_mask, &printer_std_mapping);
1812 /* map an empty access mask to the minimum access mask */
1813 if (r->in.access_mask == 0x0)
1814 r->in.access_mask = PRINTER_ACCESS_USE;
1817 * If we are not serving the printer driver for this printer,
1818 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1819 * will keep NT clients happy --jerry
1822 if (lp_use_client_driver(snum)
1823 && (r->in.access_mask & PRINTER_ACCESS_ADMINISTER))
1825 r->in.access_mask = PRINTER_ACCESS_USE;
1828 /* check smb.conf parameters and the the sec_desc */
1830 if (!allow_access(lp_hostsdeny(snum), lp_hostsallow(snum),
1831 p->client_id->name, p->client_id->addr)) {
1832 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1833 ZERO_STRUCTP(r->out.handle);
1834 return WERR_ACCESS_DENIED;
1837 if (!user_ok_token(uidtoname(p->server_info->utok.uid), NULL,
1838 p->server_info->ptok, snum) ||
1839 !print_access_check(p->server_info,
1842 r->in.access_mask)) {
1843 DEBUG(3, ("access DENIED for printer open\n"));
1844 close_printer_handle(p, r->out.handle);
1845 ZERO_STRUCTP(r->out.handle);
1846 return WERR_ACCESS_DENIED;
1849 if ((r->in.access_mask & SEC_MASK_SPECIFIC)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) {
1850 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1851 close_printer_handle(p, r->out.handle);
1852 ZERO_STRUCTP(r->out.handle);
1853 return WERR_ACCESS_DENIED;
1856 if (r->in.access_mask & PRINTER_ACCESS_ADMINISTER)
1857 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1859 r->in.access_mask = PRINTER_ACCESS_USE;
1861 DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1862 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1864 winreg_create_printer(p->mem_ctx,
1865 get_server_info_system(),
1867 lp_const_servicename(snum));
1872 /* sanity check to prevent programmer error */
1873 ZERO_STRUCTP(r->out.handle);
1877 Printer->access_granted = r->in.access_mask;
1880 * If the client sent a devmode in the OpenPrinter() call, then
1881 * save it here in case we get a job submission on this handle
1884 if ((Printer->printer_type != SPLHND_SERVER) &&
1885 r->in.devmode_ctr.devmode) {
1886 copy_devicemode(NULL, r->in.devmode_ctr.devmode,
1890 #if 0 /* JERRY -- I'm doubtful this is really effective */
1891 /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
1892 optimization in Windows 2000 clients --jerry */
1894 if ( (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1895 && (RA_WIN2K == get_remote_arch()) )
1897 DEBUG(10,("_spoolss_OpenPrinterEx: Enabling LAN/WAN hack for Win2k clients.\n"));
1898 sys_usleep( 500000 );
1905 /****************************************************************
1906 _spoolss_ClosePrinter
1907 ****************************************************************/
1909 WERROR _spoolss_ClosePrinter(struct pipes_struct *p,
1910 struct spoolss_ClosePrinter *r)
1912 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
1914 if (Printer && Printer->document_started) {
1915 struct spoolss_EndDocPrinter e;
1917 e.in.handle = r->in.handle;
1919 _spoolss_EndDocPrinter(p, &e);
1922 if (!close_printer_handle(p, r->in.handle))
1925 /* clear the returned printer handle. Observed behavior
1926 from Win2k server. Don't think this really matters.
1927 Previous code just copied the value of the closed
1930 ZERO_STRUCTP(r->out.handle);
1935 /****************************************************************
1936 _spoolss_DeletePrinter
1937 ****************************************************************/
1939 WERROR _spoolss_DeletePrinter(struct pipes_struct *p,
1940 struct spoolss_DeletePrinter *r)
1942 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
1946 if (Printer && Printer->document_started) {
1947 struct spoolss_EndDocPrinter e;
1949 e.in.handle = r->in.handle;
1951 _spoolss_EndDocPrinter(p, &e);
1954 if (get_printer_snum(p, r->in.handle, &snum, NULL)) {
1955 winreg_delete_printer_key(p->mem_ctx,
1956 get_server_info_system(),
1958 lp_const_servicename(snum),
1962 result = delete_printer_handle(p, r->in.handle);
1967 /*******************************************************************
1968 * static function to lookup the version id corresponding to an
1969 * long architecture string
1970 ******************************************************************/
1972 static const struct print_architecture_table_node archi_table[]= {
1974 {"Windows 4.0", SPL_ARCH_WIN40, 0 },
1975 {"Windows NT x86", SPL_ARCH_W32X86, 2 },
1976 {"Windows NT R4000", SPL_ARCH_W32MIPS, 2 },
1977 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA, 2 },
1978 {"Windows NT PowerPC", SPL_ARCH_W32PPC, 2 },
1979 {"Windows IA64", SPL_ARCH_IA64, 3 },
1980 {"Windows x64", SPL_ARCH_X64, 3 },
1984 static int get_version_id(const char *arch)
1988 for (i=0; archi_table[i].long_archi != NULL; i++)
1990 if (strcmp(arch, archi_table[i].long_archi) == 0)
1991 return (archi_table[i].version);
1997 /****************************************************************
1998 _spoolss_DeletePrinterDriver
1999 ****************************************************************/
2001 WERROR _spoolss_DeletePrinterDriver(struct pipes_struct *p,
2002 struct spoolss_DeletePrinterDriver *r)
2005 struct spoolss_DriverInfo8 *info = NULL;
2006 struct spoolss_DriverInfo8 *info_win2k = NULL;
2010 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2011 and not a printer admin, then fail */
2013 if ( (p->server_info->utok.uid != sec_initial_uid())
2014 && !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR)
2015 && !token_contains_name_in_list(
2016 uidtoname(p->server_info->utok.uid),
2017 p->server_info->info3->base.domain.string,
2019 p->server_info->ptok,
2020 lp_printer_admin(-1)) )
2022 return WERR_ACCESS_DENIED;
2025 /* check that we have a valid driver name first */
2027 if ((version = get_version_id(r->in.architecture)) == -1)
2028 return WERR_INVALID_ENVIRONMENT;
2030 status = winreg_get_driver(p->mem_ctx,
2031 get_server_info_system(),
2033 r->in.architecture, r->in.driver,
2035 if (!W_ERROR_IS_OK(status)) {
2036 /* try for Win2k driver if "Windows NT x86" */
2038 if ( version == 2 ) {
2041 status = winreg_get_driver(p->mem_ctx,
2042 get_server_info_system(),
2047 if (!W_ERROR_IS_OK(status)) {
2048 status = WERR_UNKNOWN_PRINTER_DRIVER;
2052 /* otherwise it was a failure */
2054 status = WERR_UNKNOWN_PRINTER_DRIVER;
2060 if (printer_driver_in_use(p->mem_ctx,
2061 get_server_info_system(),
2064 status = WERR_PRINTER_DRIVER_IN_USE;
2069 status = winreg_get_driver(p->mem_ctx,
2070 get_server_info_system(),
2073 r->in.driver, 3, &info_win2k);
2074 if (W_ERROR_IS_OK(status)) {
2075 /* if we get to here, we now have 2 driver info structures to remove */
2076 /* remove the Win2k driver first*/
2078 status = winreg_del_driver(p->mem_ctx,
2079 get_server_info_system(),
2082 talloc_free(info_win2k);
2084 /* this should not have failed---if it did, report to client */
2085 if (!W_ERROR_IS_OK(status)) {
2091 status = winreg_del_driver(p->mem_ctx,
2092 get_server_info_system(),
2102 /****************************************************************
2103 _spoolss_DeletePrinterDriverEx
2104 ****************************************************************/
2106 WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
2107 struct spoolss_DeletePrinterDriverEx *r)
2109 struct spoolss_DriverInfo8 *info = NULL;
2110 struct spoolss_DriverInfo8 *info_win2k = NULL;
2115 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2116 and not a printer admin, then fail */
2118 if ( (p->server_info->utok.uid != sec_initial_uid())
2119 && !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR)
2120 && !token_contains_name_in_list(
2121 uidtoname(p->server_info->utok.uid),
2122 p->server_info->info3->base.domain.string,
2124 p->server_info->ptok, lp_printer_admin(-1)) )
2126 return WERR_ACCESS_DENIED;
2129 /* check that we have a valid driver name first */
2130 if ((version = get_version_id(r->in.architecture)) == -1) {
2131 /* this is what NT returns */
2132 return WERR_INVALID_ENVIRONMENT;
2135 if (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION)
2136 version = r->in.version;
2138 status = winreg_get_driver(p->mem_ctx,
2139 get_server_info_system(),
2145 if (!W_ERROR_IS_OK(status)) {
2146 status = WERR_UNKNOWN_PRINTER_DRIVER;
2149 * if the client asked for a specific version,
2150 * or this is something other than Windows NT x86,
2154 if ( (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) || (version !=2) )
2157 /* try for Win2k driver if "Windows NT x86" */
2160 status = winreg_get_driver(info,
2161 get_server_info_system(),
2166 if (!W_ERROR_IS_OK(status)) {
2167 status = WERR_UNKNOWN_PRINTER_DRIVER;
2172 if (printer_driver_in_use(info,
2173 get_server_info_system(),
2176 status = WERR_PRINTER_DRIVER_IN_USE;
2181 * we have a couple of cases to consider.
2182 * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set,
2183 * then the delete should fail if **any** files overlap with
2185 * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
2186 * non-overlapping files
2187 * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
2188 * is set, the do not delete any files
2189 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
2192 delete_files = r->in.delete_flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES);
2194 /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
2197 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
2198 printer_driver_files_in_use(info,
2199 get_server_info_system(),
2202 /* no idea of the correct error here */
2203 status = WERR_ACCESS_DENIED;
2208 /* also check for W32X86/3 if necessary; maybe we already have? */
2210 if ( (version == 2) && ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION) ) {
2211 status = winreg_get_driver(info,
2212 get_server_info_system(),
2215 r->in.driver, 3, &info_win2k);
2216 if (W_ERROR_IS_OK(status)) {
2219 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
2220 printer_driver_files_in_use(info,
2221 get_server_info_system(),
2224 /* no idea of the correct error here */
2225 talloc_free(info_win2k);
2226 status = WERR_ACCESS_DENIED;
2230 /* if we get to here, we now have 2 driver info structures to remove */
2231 /* remove the Win2k driver first*/
2233 status = winreg_del_driver(info,
2234 get_server_info_system(),
2239 /* this should not have failed---if it did, report to client */
2241 if (!W_ERROR_IS_OK(status)) {
2246 * now delete any associated files if delete_files is
2247 * true. Even if this part failes, we return succes
2248 * because the driver doesn not exist any more
2251 delete_driver_files(get_server_info_system(),
2257 status = winreg_del_driver(info,
2258 get_server_info_system(),
2262 if (!W_ERROR_IS_OK(status)) {
2267 * now delete any associated files if delete_files is
2268 * true. Even if this part failes, we return succes
2269 * because the driver doesn not exist any more
2272 delete_driver_files(get_server_info_system(), info);
2281 /********************************************************************
2282 GetPrinterData on a printer server Handle.
2283 ********************************************************************/
2285 static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
2287 enum winreg_Type *type,
2288 union spoolss_PrinterData *data)
2290 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2292 if (!StrCaseCmp(value, "W3SvcInstalled")) {
2298 if (!StrCaseCmp(value, "BeepEnabled")) {
2304 if (!StrCaseCmp(value, "EventLog")) {
2306 /* formally was 0x1b */
2311 if (!StrCaseCmp(value, "NetPopup")) {
2317 if (!StrCaseCmp(value, "MajorVersion")) {
2320 /* Windows NT 4.0 seems to not allow uploading of drivers
2321 to a server that reports 0x3 as the MajorVersion.
2322 need to investigate more how Win2k gets around this .
2325 if (RA_WINNT == get_remote_arch()) {
2334 if (!StrCaseCmp(value, "MinorVersion")) {
2341 * uint32_t size = 0x114
2342 * uint32_t major = 5
2343 * uint32_t minor = [0|1]
2344 * uint32_t build = [2195|2600]
2345 * extra unicode string = e.g. "Service Pack 3"
2347 if (!StrCaseCmp(value, "OSVersion")) {
2349 enum ndr_err_code ndr_err;
2350 struct spoolss_OSVersion os;
2352 os.major = 5; /* Windows 2000 == 5.0 */
2354 os.build = 2195; /* build */
2355 os.extra_string = ""; /* leave extra string empty */
2357 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &os,
2358 (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
2359 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2360 return WERR_GENERAL_FAILURE;
2364 data->binary = blob;
2370 if (!StrCaseCmp(value, "DefaultSpoolDirectory")) {
2373 data->string = talloc_strdup(mem_ctx, "C:\\PRINTERS");
2374 W_ERROR_HAVE_NO_MEMORY(data->string);
2379 if (!StrCaseCmp(value, "Architecture")) {
2381 data->string = talloc_strdup(mem_ctx,
2382 lp_parm_const_string(GLOBAL_SECTION_SNUM, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_NT_X86));
2383 W_ERROR_HAVE_NO_MEMORY(data->string);
2388 if (!StrCaseCmp(value, "DsPresent")) {
2391 /* only show the publish check box if we are a
2392 member of a AD domain */
2394 if (lp_security() == SEC_ADS) {
2402 if (!StrCaseCmp(value, "DNSMachineName")) {
2403 const char *hostname = get_mydnsfullname();
2406 return WERR_BADFILE;
2410 data->string = talloc_strdup(mem_ctx, hostname);
2411 W_ERROR_HAVE_NO_MEMORY(data->string);
2418 return WERR_INVALID_PARAM;
2421 /****************************************************************
2422 _spoolss_GetPrinterData
2423 ****************************************************************/
2425 WERROR _spoolss_GetPrinterData(struct pipes_struct *p,
2426 struct spoolss_GetPrinterData *r)
2428 struct spoolss_GetPrinterDataEx r2;
2430 r2.in.handle = r->in.handle;
2431 r2.in.key_name = "PrinterDriverData";
2432 r2.in.value_name = r->in.value_name;
2433 r2.in.offered = r->in.offered;
2434 r2.out.type = r->out.type;
2435 r2.out.data = r->out.data;
2436 r2.out.needed = r->out.needed;
2438 return _spoolss_GetPrinterDataEx(p, &r2);
2441 /*********************************************************
2442 Connect to the client machine.
2443 **********************************************************/
2445 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
2446 struct sockaddr_storage *client_ss, const char *remote_machine)
2449 struct cli_state *the_cli;
2450 struct sockaddr_storage rm_addr;
2451 char addr[INET6_ADDRSTRLEN];
2453 if ( is_zero_addr((struct sockaddr *)client_ss) ) {
2454 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2456 if ( !resolve_name( remote_machine, &rm_addr, 0x20, false) ) {
2457 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2460 print_sockaddr(addr, sizeof(addr), &rm_addr);
2462 rm_addr = *client_ss;
2463 print_sockaddr(addr, sizeof(addr), &rm_addr);
2464 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2468 if (ismyaddr((struct sockaddr *)(void *)&rm_addr)) {
2469 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2474 /* setup the connection */
2475 ret = cli_full_connection( &the_cli, global_myname(), remote_machine,
2476 &rm_addr, 0, "IPC$", "IPC",
2480 0, lp_client_signing(), NULL );
2482 if ( !NT_STATUS_IS_OK( ret ) ) {
2483 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2488 if ( the_cli->protocol != PROTOCOL_NT1 ) {
2489 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2490 cli_shutdown(the_cli);
2495 * Ok - we have an anonymous connection to the IPC$ share.
2496 * Now start the NT Domain stuff :-).
2499 ret = cli_rpc_pipe_open_noauth(the_cli, &ndr_table_spoolss.syntax_id, pp_pipe);
2500 if (!NT_STATUS_IS_OK(ret)) {
2501 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2502 remote_machine, nt_errstr(ret)));
2503 cli_shutdown(the_cli);
2510 /***************************************************************************
2511 Connect to the client.
2512 ****************************************************************************/
2514 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2515 uint32_t localprinter,
2516 enum winreg_Type type,
2517 struct policy_handle *handle,
2518 struct notify_back_channel **_chan,
2519 struct sockaddr_storage *client_ss,
2520 struct messaging_context *msg_ctx)
2524 struct notify_back_channel *chan;
2526 for (chan = back_channels; chan; chan = chan->next) {
2527 if (memcmp(&chan->client_address, client_ss,
2528 sizeof(struct sockaddr_storage)) == 0) {
2534 * If it's the first connection, contact the client
2535 * and connect to the IPC$ share anonymously
2538 fstring unix_printer;
2540 /* the +2 is to strip the leading 2 backslashs */
2541 fstrcpy(unix_printer, printer + 2);
2543 chan = talloc_zero(back_channels, struct notify_back_channel);
2547 chan->client_address = *client_ss;
2549 if (!spoolss_connect_to_client(&chan->cli_pipe, client_ss, unix_printer)) {
2554 DLIST_ADD(back_channels, chan);
2556 messaging_register(msg_ctx, NULL, MSG_PRINTER_NOTIFY2,
2557 receive_notify2_message_list);
2558 /* Tell the connections db we're now interested in printer
2559 * notify messages. */
2560 serverid_register_msg_flags(messaging_server_id(msg_ctx),
2561 true, FLAG_MSG_PRINT_NOTIFY);
2565 * Tell the specific printing tdb we want messages for this printer
2566 * by registering our PID.
2569 if (!print_notify_register_pid(snum)) {
2570 DEBUG(0, ("Failed to register our pid for printer %s\n",
2574 status = rpccli_spoolss_ReplyOpenPrinter(chan->cli_pipe, talloc_tos(),
2582 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
2583 DEBUG(5, ("Client RPC returned [%s]\n", win_errstr(result)));
2586 chan->active_connections++;
2589 return (W_ERROR_IS_OK(result));
2592 /****************************************************************
2593 ****************************************************************/
2595 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2596 const struct spoolss_NotifyOption *r)
2598 struct spoolss_NotifyOption *option;
2605 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2612 if (!option->count) {
2616 option->types = talloc_zero_array(option,
2617 struct spoolss_NotifyOptionType, option->count);
2618 if (!option->types) {
2619 talloc_free(option);
2623 for (i=0; i < option->count; i++) {
2624 option->types[i] = r->types[i];
2626 if (option->types[i].count) {
2627 option->types[i].fields = talloc_zero_array(option,
2628 union spoolss_Field, option->types[i].count);
2629 if (!option->types[i].fields) {
2630 talloc_free(option);
2633 for (k=0; k<option->types[i].count; k++) {
2634 option->types[i].fields[k] =
2635 r->types[i].fields[k];
2643 /****************************************************************
2644 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2646 * before replying OK: status=0 a rpc call is made to the workstation
2647 * asking ReplyOpenPrinter
2649 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2650 * called from api_spoolss_rffpcnex
2651 ****************************************************************/
2653 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct *p,
2654 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2657 struct spoolss_NotifyOption *option = r->in.notify_options;
2658 struct sockaddr_storage client_ss;
2660 /* store the notify value in the printer struct */
2662 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
2665 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2666 "Invalid handle (%s:%u:%u).\n",
2667 OUR_HANDLE(r->in.handle)));
2671 Printer->notify.flags = r->in.flags;
2672 Printer->notify.options = r->in.options;
2673 Printer->notify.printerlocal = r->in.printer_local;
2674 Printer->notify.msg_ctx = p->msg_ctx;
2676 TALLOC_FREE(Printer->notify.option);
2677 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2679 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2681 /* Connect to the client machine and send a ReplyOpenPrinter */
2683 if ( Printer->printer_type == SPLHND_SERVER)
2685 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2686 !get_printer_snum(p, r->in.handle, &snum, NULL) )
2689 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2690 "client_address is %s\n", p->client_id->addr));
2692 if (!interpret_string_addr(&client_ss, p->client_id->addr,
2694 return WERR_SERVER_UNAVAILABLE;
2697 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2698 Printer->notify.printerlocal, REG_SZ,
2699 &Printer->notify.cli_hnd,
2700 &Printer->notify.cli_chan,
2701 &client_ss, p->msg_ctx)) {
2702 return WERR_SERVER_UNAVAILABLE;
2708 /*******************************************************************
2709 * fill a notify_info_data with the servername
2710 ********************************************************************/
2712 static void spoolss_notify_server_name(struct messaging_context *msg_ctx,
2714 struct spoolss_Notify *data,
2715 print_queue_struct *queue,
2716 struct spoolss_PrinterInfo2 *pinfo2,
2717 TALLOC_CTX *mem_ctx)
2719 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->servername);
2722 /*******************************************************************
2723 * fill a notify_info_data with the printername (not including the servername).
2724 ********************************************************************/
2726 static void spoolss_notify_printer_name(struct messaging_context *msg_ctx,
2728 struct spoolss_Notify *data,
2729 print_queue_struct *queue,
2730 struct spoolss_PrinterInfo2 *pinfo2,
2731 TALLOC_CTX *mem_ctx)
2733 /* the notify name should not contain the \\server\ part */
2734 const char *p = strrchr(pinfo2->printername, '\\');
2737 p = pinfo2->printername;
2742 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2745 /*******************************************************************
2746 * fill a notify_info_data with the servicename
2747 ********************************************************************/
2749 static void spoolss_notify_share_name(struct messaging_context *msg_ctx,
2751 struct spoolss_Notify *data,
2752 print_queue_struct *queue,
2753 struct spoolss_PrinterInfo2 *pinfo2,
2754 TALLOC_CTX *mem_ctx)
2756 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(snum));
2759 /*******************************************************************
2760 * fill a notify_info_data with the port name
2761 ********************************************************************/
2763 static void spoolss_notify_port_name(struct messaging_context *msg_ctx,
2765 struct spoolss_Notify *data,
2766 print_queue_struct *queue,
2767 struct spoolss_PrinterInfo2 *pinfo2,
2768 TALLOC_CTX *mem_ctx)
2770 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->portname);
2773 /*******************************************************************
2774 * fill a notify_info_data with the printername
2775 * but it doesn't exist, have to see what to do
2776 ********************************************************************/
2778 static void spoolss_notify_driver_name(struct messaging_context *msg_ctx,
2780 struct spoolss_Notify *data,
2781 print_queue_struct *queue,
2782 struct spoolss_PrinterInfo2 *pinfo2,
2783 TALLOC_CTX *mem_ctx)
2785 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->drivername);
2788 /*******************************************************************
2789 * fill a notify_info_data with the comment
2790 ********************************************************************/
2792 static void spoolss_notify_comment(struct messaging_context *msg_ctx,
2794 struct spoolss_Notify *data,
2795 print_queue_struct *queue,
2796 struct spoolss_PrinterInfo2 *pinfo2,
2797 TALLOC_CTX *mem_ctx)
2801 if (*pinfo2->comment == '\0') {
2802 p = lp_comment(snum);
2804 p = pinfo2->comment;
2807 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2810 /*******************************************************************
2811 * fill a notify_info_data with the comment
2812 * location = "Room 1, floor 2, building 3"
2813 ********************************************************************/
2815 static void spoolss_notify_location(struct messaging_context *msg_ctx,
2817 struct spoolss_Notify *data,
2818 print_queue_struct *queue,
2819 struct spoolss_PrinterInfo2 *pinfo2,
2820 TALLOC_CTX *mem_ctx)
2822 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->location);
2825 /*******************************************************************
2826 * fill a notify_info_data with the device mode
2827 * jfm:xxxx don't to it for know but that's a real problem !!!
2828 ********************************************************************/
2830 static void spoolss_notify_devmode(struct messaging_context *msg_ctx,
2832 struct spoolss_Notify *data,
2833 print_queue_struct *queue,
2834 struct spoolss_PrinterInfo2 *pinfo2,
2835 TALLOC_CTX *mem_ctx)
2837 /* for a dummy implementation we have to zero the fields */
2838 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
2841 /*******************************************************************
2842 * fill a notify_info_data with the separator file name
2843 ********************************************************************/
2845 static void spoolss_notify_sepfile(struct messaging_context *msg_ctx,
2847 struct spoolss_Notify *data,
2848 print_queue_struct *queue,
2849 struct spoolss_PrinterInfo2 *pinfo2,
2850 TALLOC_CTX *mem_ctx)
2852 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->sepfile);
2855 /*******************************************************************
2856 * fill a notify_info_data with the print processor
2857 * jfm:xxxx return always winprint to indicate we don't do anything to it
2858 ********************************************************************/
2860 static void spoolss_notify_print_processor(struct messaging_context *msg_ctx,
2862 struct spoolss_Notify *data,
2863 print_queue_struct *queue,
2864 struct spoolss_PrinterInfo2 *pinfo2,
2865 TALLOC_CTX *mem_ctx)
2867 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->printprocessor);
2870 /*******************************************************************
2871 * fill a notify_info_data with the print processor options
2872 * jfm:xxxx send an empty string
2873 ********************************************************************/
2875 static void spoolss_notify_parameters(struct messaging_context *msg_ctx,
2877 struct spoolss_Notify *data,
2878 print_queue_struct *queue,
2879 struct spoolss_PrinterInfo2 *pinfo2,
2880 TALLOC_CTX *mem_ctx)
2882 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->parameters);
2885 /*******************************************************************
2886 * fill a notify_info_data with the data type
2887 * jfm:xxxx always send RAW as data type
2888 ********************************************************************/
2890 static void spoolss_notify_datatype(struct messaging_context *msg_ctx,
2892 struct spoolss_Notify *data,
2893 print_queue_struct *queue,
2894 struct spoolss_PrinterInfo2 *pinfo2,
2895 TALLOC_CTX *mem_ctx)
2897 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->datatype);
2900 /*******************************************************************
2901 * fill a notify_info_data with the security descriptor
2902 * jfm:xxxx send an null pointer to say no security desc
2903 * have to implement security before !
2904 ********************************************************************/
2906 static void spoolss_notify_security_desc(struct messaging_context *msg_ctx,
2908 struct spoolss_Notify *data,
2909 print_queue_struct *queue,
2910 struct spoolss_PrinterInfo2 *pinfo2,
2911 TALLOC_CTX *mem_ctx)
2913 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data, pinfo2->secdesc);
2916 /*******************************************************************
2917 * fill a notify_info_data with the attributes
2918 * jfm:xxxx a samba printer is always shared
2919 ********************************************************************/
2921 static void spoolss_notify_attributes(struct messaging_context *msg_ctx,
2923 struct spoolss_Notify *data,
2924 print_queue_struct *queue,
2925 struct spoolss_PrinterInfo2 *pinfo2,
2926 TALLOC_CTX *mem_ctx)
2928 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->attributes);
2931 /*******************************************************************
2932 * fill a notify_info_data with the priority
2933 ********************************************************************/
2935 static void spoolss_notify_priority(struct messaging_context *msg_ctx,
2937 struct spoolss_Notify *data,
2938 print_queue_struct *queue,
2939 struct spoolss_PrinterInfo2 *pinfo2,
2940 TALLOC_CTX *mem_ctx)
2942 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->priority);
2945 /*******************************************************************
2946 * fill a notify_info_data with the default priority
2947 ********************************************************************/
2949 static void spoolss_notify_default_priority(struct messaging_context *msg_ctx,
2951 struct spoolss_Notify *data,
2952 print_queue_struct *queue,
2953 struct spoolss_PrinterInfo2 *pinfo2,
2954 TALLOC_CTX *mem_ctx)
2956 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->defaultpriority);
2959 /*******************************************************************
2960 * fill a notify_info_data with the start time
2961 ********************************************************************/
2963 static void spoolss_notify_start_time(struct messaging_context *msg_ctx,
2965 struct spoolss_Notify *data,
2966 print_queue_struct *queue,
2967 struct spoolss_PrinterInfo2 *pinfo2,
2968 TALLOC_CTX *mem_ctx)
2970 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->starttime);
2973 /*******************************************************************
2974 * fill a notify_info_data with the until time
2975 ********************************************************************/
2977 static void spoolss_notify_until_time(struct messaging_context *msg_ctx,
2979 struct spoolss_Notify *data,
2980 print_queue_struct *queue,
2981 struct spoolss_PrinterInfo2 *pinfo2,
2982 TALLOC_CTX *mem_ctx)
2984 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->untiltime);
2987 /*******************************************************************
2988 * fill a notify_info_data with the status
2989 ********************************************************************/
2991 static void spoolss_notify_status(struct messaging_context *msg_ctx,
2993 struct spoolss_Notify *data,
2994 print_queue_struct *queue,
2995 struct spoolss_PrinterInfo2 *pinfo2,
2996 TALLOC_CTX *mem_ctx)
2998 print_status_struct status;
3000 print_queue_length(msg_ctx, snum, &status);
3001 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
3004 /*******************************************************************
3005 * fill a notify_info_data with the number of jobs queued
3006 ********************************************************************/
3008 static void spoolss_notify_cjobs(struct messaging_context *msg_ctx,
3010 struct spoolss_Notify *data,
3011 print_queue_struct *queue,
3012 struct spoolss_PrinterInfo2 *pinfo2,
3013 TALLOC_CTX *mem_ctx)
3015 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(
3016 data, print_queue_length(msg_ctx, snum, NULL));
3019 /*******************************************************************
3020 * fill a notify_info_data with the average ppm
3021 ********************************************************************/
3023 static void spoolss_notify_average_ppm(struct messaging_context *msg_ctx,
3025 struct spoolss_Notify *data,
3026 print_queue_struct *queue,
3027 struct spoolss_PrinterInfo2 *pinfo2,
3028 TALLOC_CTX *mem_ctx)
3030 /* always respond 8 pages per minutes */
3031 /* a little hard ! */
3032 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->averageppm);
3035 /*******************************************************************
3036 * fill a notify_info_data with username
3037 ********************************************************************/
3039 static void spoolss_notify_username(struct messaging_context *msg_ctx,
3041 struct spoolss_Notify *data,
3042 print_queue_struct *queue,
3043 struct spoolss_PrinterInfo2 *pinfo2,
3044 TALLOC_CTX *mem_ctx)
3046 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
3049 /*******************************************************************
3050 * fill a notify_info_data with job status
3051 ********************************************************************/
3053 static void spoolss_notify_job_status(struct messaging_context *msg_ctx,
3055 struct spoolss_Notify *data,
3056 print_queue_struct *queue,
3057 struct spoolss_PrinterInfo2 *pinfo2,
3058 TALLOC_CTX *mem_ctx)
3060 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
3063 /*******************************************************************
3064 * fill a notify_info_data with job name
3065 ********************************************************************/
3067 static void spoolss_notify_job_name(struct messaging_context *msg_ctx,
3069 struct spoolss_Notify *data,
3070 print_queue_struct *queue,
3071 struct spoolss_PrinterInfo2 *pinfo2,
3072 TALLOC_CTX *mem_ctx)
3074 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
3077 /*******************************************************************
3078 * fill a notify_info_data with job status
3079 ********************************************************************/
3081 static void spoolss_notify_job_status_string(struct messaging_context *msg_ctx,
3083 struct spoolss_Notify *data,
3084 print_queue_struct *queue,
3085 struct spoolss_PrinterInfo2 *pinfo2,
3086 TALLOC_CTX *mem_ctx)
3089 * Now we're returning job status codes we just return a "" here. JRA.
3094 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
3097 switch (queue->status) {
3102 p = ""; /* NT provides the paused string */
3111 #endif /* NO LONGER NEEDED. */
3113 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
3116 /*******************************************************************
3117 * fill a notify_info_data with job time
3118 ********************************************************************/
3120 static void spoolss_notify_job_time(struct messaging_context *msg_ctx,
3122 struct spoolss_Notify *data,
3123 print_queue_struct *queue,
3124 struct spoolss_PrinterInfo2 *pinfo2,
3125 TALLOC_CTX *mem_ctx)
3127 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3130 /*******************************************************************
3131 * fill a notify_info_data with job size
3132 ********************************************************************/
3134 static void spoolss_notify_job_size(struct messaging_context *msg_ctx,
3136 struct spoolss_Notify *data,
3137 print_queue_struct *queue,
3138 struct spoolss_PrinterInfo2 *pinfo2,
3139 TALLOC_CTX *mem_ctx)
3141 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
3144 /*******************************************************************
3145 * fill a notify_info_data with page info
3146 ********************************************************************/
3147 static void spoolss_notify_total_pages(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, queue->page_count);
3157 /*******************************************************************
3158 * fill a notify_info_data with pages printed info.
3159 ********************************************************************/
3160 static void spoolss_notify_pages_printed(struct messaging_context *msg_ctx,
3162 struct spoolss_Notify *data,
3163 print_queue_struct *queue,
3164 struct spoolss_PrinterInfo2 *pinfo2,
3165 TALLOC_CTX *mem_ctx)
3167 /* Add code when back-end tracks this */
3168 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3171 /*******************************************************************
3172 Fill a notify_info_data with job position.
3173 ********************************************************************/
3175 static void spoolss_notify_job_position(struct messaging_context *msg_ctx,
3177 struct spoolss_Notify *data,
3178 print_queue_struct *queue,
3179 struct spoolss_PrinterInfo2 *pinfo2,
3180 TALLOC_CTX *mem_ctx)
3182 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->job);
3185 /*******************************************************************
3186 Fill a notify_info_data with submitted time.
3187 ********************************************************************/
3189 static void spoolss_notify_submitted_time(struct messaging_context *msg_ctx,
3191 struct spoolss_Notify *data,
3192 print_queue_struct *queue,
3193 struct spoolss_PrinterInfo2 *pinfo2,
3194 TALLOC_CTX *mem_ctx)
3196 data->data.string.string = NULL;
3197 data->data.string.size = 0;
3199 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
3200 &data->data.string.string,
3201 &data->data.string.size);
3205 struct s_notify_info_data_table
3207 enum spoolss_NotifyType type;
3210 enum spoolss_NotifyTable variable_type;
3211 void (*fn) (struct messaging_context *msg_ctx,
3212 int snum, struct spoolss_Notify *data,
3213 print_queue_struct *queue,
3214 struct spoolss_PrinterInfo2 *pinfo2,
3215 TALLOC_CTX *mem_ctx);
3218 /* A table describing the various print notification constants and
3219 whether the notification data is a pointer to a variable sized
3220 buffer, a one value uint32_t or a two value uint32_t. */
3222 static const struct s_notify_info_data_table notify_info_data_table[] =
3224 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SERVER_NAME, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3225 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINTER_NAME, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3226 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SHARE_NAME, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
3227 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PORT_NAME, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3228 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DRIVER_NAME, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3229 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_COMMENT, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
3230 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_LOCATION, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
3231 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEVMODE, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3232 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SEPFILE, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
3233 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3234 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PARAMETERS, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3235 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DATATYPE, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3236 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
3237 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_ATTRIBUTES, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
3238 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRIORITY, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3239 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
3240 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_START_TIME, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3241 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_UNTIL_TIME, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3242 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
3243 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS_STRING, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
3244 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_CJOBS, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
3245 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_AVERAGE_PPM, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
3246 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_PAGES, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
3247 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PAGES_PRINTED, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3248 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_BYTES, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
3249 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_BYTES_PRINTED, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3250 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINTER_NAME, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3251 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_MACHINE_NAME, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3252 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PORT_NAME, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3253 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_USER_NAME, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3254 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_NOTIFY_NAME, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3255 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DATATYPE, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3256 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINT_PROCESSOR, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3257 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PARAMETERS, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3258 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DRIVER_NAME, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3259 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DEVMODE, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3260 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
3261 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS_STRING, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
3262 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
3263 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DOCUMENT, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
3264 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRIORITY, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3265 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_POSITION, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
3266 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SUBMITTED, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
3267 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_START_TIME, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3268 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_UNTIL_TIME, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3269 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TIME, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
3270 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_PAGES, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
3271 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PAGES_PRINTED, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
3272 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_BYTES, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
3275 /*******************************************************************
3276 Return the variable_type of info_data structure.
3277 ********************************************************************/
3279 static enum spoolss_NotifyTable variable_type_of_notify_info_data(enum spoolss_NotifyType type,
3284 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3285 if ( (notify_info_data_table[i].type == type) &&
3286 (notify_info_data_table[i].field == field) ) {
3287 return notify_info_data_table[i].variable_type;
3291 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
3293 return (enum spoolss_NotifyTable) 0;
3296 /****************************************************************************
3297 ****************************************************************************/
3299 static bool search_notify(enum spoolss_NotifyType type,
3305 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3306 if (notify_info_data_table[i].type == type &&
3307 notify_info_data_table[i].field == field &&
3308 notify_info_data_table[i].fn != NULL) {
3317 /****************************************************************************
3318 ****************************************************************************/
3320 static void construct_info_data(struct spoolss_Notify *info_data,
3321 enum spoolss_NotifyType type,
3322 uint16_t field, int id)
3324 info_data->type = type;
3325 info_data->field.field = field;
3326 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3327 info_data->job_id = id;
3330 /*******************************************************************
3332 * fill a notify_info struct with info asked
3334 ********************************************************************/
3336 static bool construct_notify_printer_info(struct messaging_context *msg_ctx,
3337 struct printer_handle *print_hnd,
3338 struct spoolss_NotifyInfo *info,
3339 struct spoolss_PrinterInfo2 *pinfo2,
3341 const struct spoolss_NotifyOptionType *option_type,
3343 TALLOC_CTX *mem_ctx)
3346 enum spoolss_NotifyType type;
3349 struct spoolss_Notify *current_data;
3350 print_queue_struct *queue=NULL;
3352 type = option_type->type;
3354 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3355 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3356 option_type->count, lp_servicename(snum)));
3358 for(field_num=0; field_num < option_type->count; field_num++) {
3359 field = option_type->fields[field_num].field;
3361 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3363 if (!search_notify(type, field, &j) )
3366 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3367 struct spoolss_Notify,
3369 if (info->notifies == NULL) {
3370 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3374 current_data = &info->notifies[info->count];
3376 construct_info_data(current_data, type, field, id);
3378 DEBUG(10, ("construct_notify_printer_info: "
3379 "calling [%s] snum=%d printername=[%s])\n",
3380 notify_info_data_table[j].name, snum,
3381 pinfo2->printername));
3383 notify_info_data_table[j].fn(msg_ctx, snum, current_data,
3384 queue, pinfo2, mem_ctx);
3392 /*******************************************************************
3394 * fill a notify_info struct with info asked
3396 ********************************************************************/
3398 static bool construct_notify_jobs_info(struct messaging_context *msg_ctx,
3399 print_queue_struct *queue,
3400 struct spoolss_NotifyInfo *info,
3401 struct spoolss_PrinterInfo2 *pinfo2,
3403 const struct spoolss_NotifyOptionType *option_type,
3405 TALLOC_CTX *mem_ctx)
3408 enum spoolss_NotifyType type;
3410 struct spoolss_Notify *current_data;
3412 DEBUG(4,("construct_notify_jobs_info\n"));
3414 type = option_type->type;
3416 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3417 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3418 option_type->count));
3420 for(field_num=0; field_num<option_type->count; field_num++) {
3421 field = option_type->fields[field_num].field;
3423 if (!search_notify(type, field, &j) )
3426 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3427 struct spoolss_Notify,
3429 if (info->notifies == NULL) {
3430 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3434 current_data=&(info->notifies[info->count]);
3436 construct_info_data(current_data, type, field, id);
3437 notify_info_data_table[j].fn(msg_ctx, snum, current_data,
3438 queue, pinfo2, mem_ctx);
3446 * JFM: The enumeration is not that simple, it's even non obvious.
3448 * let's take an example: I want to monitor the PRINTER SERVER for
3449 * the printer's name and the number of jobs currently queued.
3450 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3451 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3453 * I have 3 printers on the back of my server.
3455 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3458 * 1 printer 1 name 1
3459 * 2 printer 1 cjob 1
3460 * 3 printer 2 name 2
3461 * 4 printer 2 cjob 2
3462 * 5 printer 3 name 3
3463 * 6 printer 3 name 3
3465 * that's the print server case, the printer case is even worse.
3468 /*******************************************************************
3470 * enumerate all printers on the printserver
3471 * fill a notify_info struct with info asked
3473 ********************************************************************/
3475 static WERROR printserver_notify_info(struct pipes_struct *p,
3476 struct policy_handle *hnd,
3477 struct spoolss_NotifyInfo *info,
3478 TALLOC_CTX *mem_ctx)
3481 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
3482 int n_services=lp_numservices();
3484 struct spoolss_NotifyOption *option;
3485 struct spoolss_NotifyOptionType option_type;
3486 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3489 DEBUG(4,("printserver_notify_info\n"));
3494 option = Printer->notify.option;
3497 info->notifies = NULL;
3500 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3501 sending a ffpcn() request first */
3506 for (i=0; i<option->count; i++) {
3507 option_type = option->types[i];
3509 if (option_type.type != PRINTER_NOTIFY_TYPE)
3512 for (snum = 0; snum < n_services; snum++) {
3513 if (!lp_browseable(snum) ||
3514 !lp_snum_ok(snum) ||
3515 !lp_print_ok(snum)) {
3516 continue; /* skip */
3519 /* Maybe we should use the SYSTEM server_info here... */
3520 result = winreg_get_printer(mem_ctx,
3521 get_server_info_system(),
3523 lp_servicename(snum),
3525 if (!W_ERROR_IS_OK(result)) {
3526 DEBUG(4, ("printserver_notify_info: "
3527 "Failed to get printer [%s]\n",
3528 lp_servicename(snum)));
3533 construct_notify_printer_info(p->msg_ctx,
3539 TALLOC_FREE(pinfo2);
3545 * Debugging information, don't delete.
3548 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3549 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3550 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3552 for (i=0; i<info->count; i++) {
3553 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3554 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3555 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3562 /*******************************************************************
3564 * fill a notify_info struct with info asked
3566 ********************************************************************/
3568 static WERROR printer_notify_info(struct pipes_struct *p,
3569 struct policy_handle *hnd,
3570 struct spoolss_NotifyInfo *info,
3571 TALLOC_CTX *mem_ctx)
3574 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
3577 struct spoolss_NotifyOption *option;
3578 struct spoolss_NotifyOptionType option_type;
3580 print_queue_struct *queue=NULL;
3581 print_status_struct status;
3582 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3585 DEBUG(4,("printer_notify_info\n"));
3590 option = Printer->notify.option;
3594 info->notifies = NULL;
3597 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3598 sending a ffpcn() request first */
3603 get_printer_snum(p, hnd, &snum, NULL);
3605 /* Maybe we should use the SYSTEM server_info here... */
3606 result = winreg_get_printer(mem_ctx,
3607 get_server_info_system(),
3609 lp_servicename(snum), &pinfo2);
3610 if (!W_ERROR_IS_OK(result)) {
3614 for (i=0; i<option->count; i++) {
3615 option_type = option->types[i];
3617 switch (option_type.type) {
3618 case PRINTER_NOTIFY_TYPE:
3619 if (construct_notify_printer_info(p->msg_ctx,
3628 case JOB_NOTIFY_TYPE:
3630 count = print_queue_status(p->msg_ctx, snum, &queue,
3633 for (j=0; j<count; j++) {
3634 construct_notify_jobs_info(p->msg_ctx,
3648 * Debugging information, don't delete.
3651 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3652 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3653 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3655 for (i=0; i<info->count; i++) {
3656 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3657 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3658 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3662 talloc_free(pinfo2);
3666 /****************************************************************
3667 _spoolss_RouterRefreshPrinterChangeNotify
3668 ****************************************************************/
3670 WERROR _spoolss_RouterRefreshPrinterChangeNotify(struct pipes_struct *p,
3671 struct spoolss_RouterRefreshPrinterChangeNotify *r)
3673 struct spoolss_NotifyInfo *info;
3675 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
3676 WERROR result = WERR_BADFID;
3678 /* we always have a spoolss_NotifyInfo struct */
3679 info = talloc_zero(p->mem_ctx, struct spoolss_NotifyInfo);
3681 result = WERR_NOMEM;
3685 *r->out.info = info;
3688 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3689 "Invalid handle (%s:%u:%u).\n",
3690 OUR_HANDLE(r->in.handle)));
3694 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3697 * We are now using the change value, and
3698 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3699 * I don't have a global notification system, I'm sending back all the
3700 * informations even when _NOTHING_ has changed.
3703 /* We need to keep track of the change value to send back in
3704 RRPCN replies otherwise our updates are ignored. */
3706 Printer->notify.fnpcn = true;
3708 if (Printer->notify.cli_chan != NULL &&
3709 Printer->notify.cli_chan->active_connections > 0) {
3710 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3711 "Saving change value in request [%x]\n",
3713 Printer->notify.change = r->in.change_low;
3716 /* just ignore the spoolss_NotifyOption */
3718 switch (Printer->printer_type) {
3720 result = printserver_notify_info(p, r->in.handle,
3724 case SPLHND_PRINTER:
3725 result = printer_notify_info(p, r->in.handle,
3730 Printer->notify.fnpcn = false;
3736 /********************************************************************
3737 ********************************************************************/
3739 static WERROR create_printername(TALLOC_CTX *mem_ctx,
3740 const char *servername,
3741 const char *printername,
3742 const char **printername_p)
3744 /* FIXME: add lp_force_printername() */
3746 if (servername == NULL) {
3747 *printername_p = talloc_strdup(mem_ctx, printername);
3748 W_ERROR_HAVE_NO_MEMORY(*printername_p);
3752 if (servername[0] == '\\' && servername[1] == '\\') {
3756 *printername_p = talloc_asprintf(mem_ctx, "\\\\%s\\%s", servername, printername);
3757 W_ERROR_HAVE_NO_MEMORY(*printername_p);
3762 /********************************************************************
3763 ********************************************************************/
3765 static void compose_devicemode_devicename(struct spoolss_DeviceMode *dm,
3766 const char *printername)
3772 dm->devicename = talloc_strndup(dm, printername,
3773 MIN(strlen(printername), 31));
3776 /********************************************************************
3777 * construct_printer_info_0
3778 * fill a printer_info_0 struct
3779 ********************************************************************/
3781 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
3782 const struct auth_serversupplied_info *server_info,
3783 struct messaging_context *msg_ctx,
3784 struct spoolss_PrinterInfo2 *info2,
3785 const char *servername,
3786 struct spoolss_PrinterInfo0 *r,
3790 struct printer_session_counter *session_counter;
3791 struct timeval setuptime;
3792 print_status_struct status;
3795 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
3796 if (!W_ERROR_IS_OK(result)) {
3801 r->servername = talloc_strdup(mem_ctx, servername);
3802 W_ERROR_HAVE_NO_MEMORY(r->servername);
3804 r->servername = NULL;
3807 count = print_queue_length(msg_ctx, snum, &status);
3809 /* check if we already have a counter for this printer */
3810 for (session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3811 if (session_counter->snum == snum)
3815 /* it's the first time, add it to the list */
3816 if (session_counter == NULL) {
3817 session_counter = talloc_zero(counter_list, struct printer_session_counter);
3818 W_ERROR_HAVE_NO_MEMORY(session_counter);
3819 session_counter->snum = snum;
3820 session_counter->counter = 0;
3821 DLIST_ADD(counter_list, session_counter);
3825 session_counter->counter++;
3831 get_startup_time(&setuptime);
3832 init_systemtime(&r->time, gmtime(&setuptime.tv_sec));
3835 * the global_counter should be stored in a TDB as it's common to all the clients
3836 * and should be zeroed on samba startup
3838 r->global_counter = session_counter->counter;
3840 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3841 SSVAL(&r->version, 0, 0x0005); /* NT 5 */
3842 SSVAL(&r->version, 2, 0x0893); /* build 2195 */
3843 r->free_build = SPOOLSS_RELEASE_BUILD;
3845 r->max_spooling = 0;
3846 r->session_counter = session_counter->counter;
3847 r->num_error_out_of_paper = 0x0;
3848 r->num_error_not_ready = 0x0; /* number of print failure */
3850 r->number_of_processors = 0x1;
3851 r->processor_type = PROCESSOR_INTEL_PENTIUM; /* 586 Pentium ? */
3852 r->high_part_total_bytes = 0x0;
3854 /* ChangeID in milliseconds*/
3855 winreg_printer_get_changeid(mem_ctx, server_info, msg_ctx,
3856 info2->sharename, &r->change_id);
3858 r->last_error = WERR_OK;
3859 r->status = nt_printq_status(status.status);
3860 r->enumerate_network_printers = 0x0;
3861 r->c_setprinter = 0x0;
3862 r->processor_architecture = PROCESSOR_ARCHITECTURE_INTEL;
3863 r->processor_level = 0x6; /* 6 ???*/
3872 /********************************************************************
3873 * construct_printer_info1
3874 * fill a spoolss_PrinterInfo1 struct
3875 ********************************************************************/
3877 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
3878 const struct spoolss_PrinterInfo2 *info2,
3880 const char *servername,
3881 struct spoolss_PrinterInfo1 *r,
3888 if (info2->comment == NULL || info2->comment[0] == '\0') {
3889 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3891 r->comment = talloc_strdup(mem_ctx, info2->comment); /* saved comment */
3893 W_ERROR_HAVE_NO_MEMORY(r->comment);
3895 result = create_printername(mem_ctx, servername, info2->printername, &r->name);
3896 if (!W_ERROR_IS_OK(result)) {
3900 r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
3904 W_ERROR_HAVE_NO_MEMORY(r->description);
3909 /********************************************************************
3910 * construct_printer_info2
3911 * fill a spoolss_PrinterInfo2 struct
3912 ********************************************************************/
3914 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
3915 struct messaging_context *msg_ctx,
3916 const struct spoolss_PrinterInfo2 *info2,
3917 const char *servername,
3918 struct spoolss_PrinterInfo2 *r,
3922 print_status_struct status;
3925 count = print_queue_length(msg_ctx, snum, &status);
3928 r->servername = talloc_strdup(mem_ctx, servername);
3929 W_ERROR_HAVE_NO_MEMORY(r->servername);
3931 r->servername = NULL;
3934 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
3935 if (!W_ERROR_IS_OK(result)) {
3939 r->sharename = talloc_strdup(mem_ctx, lp_servicename(snum));
3940 W_ERROR_HAVE_NO_MEMORY(r->sharename);
3941 r->portname = talloc_strdup(mem_ctx, info2->portname);
3942 W_ERROR_HAVE_NO_MEMORY(r->portname);
3943 r->drivername = talloc_strdup(mem_ctx, info2->drivername);
3944 W_ERROR_HAVE_NO_MEMORY(r->drivername);
3946 if (info2->comment[0] == '\0') {
3947 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3949 r->comment = talloc_strdup(mem_ctx, info2->comment);
3951 W_ERROR_HAVE_NO_MEMORY(r->comment);
3953 r->location = talloc_strdup(mem_ctx, info2->location);
3954 W_ERROR_HAVE_NO_MEMORY(r->location);
3955 r->sepfile = talloc_strdup(mem_ctx, info2->sepfile);
3956 W_ERROR_HAVE_NO_MEMORY(r->sepfile);
3957 r->printprocessor = talloc_strdup(mem_ctx, info2->printprocessor);
3958 W_ERROR_HAVE_NO_MEMORY(r->printprocessor);
3959 r->datatype = talloc_strdup(mem_ctx, info2->datatype);
3960 W_ERROR_HAVE_NO_MEMORY(r->datatype);
3961 r->parameters = talloc_strdup(mem_ctx, info2->parameters);
3962 W_ERROR_HAVE_NO_MEMORY(r->parameters);
3964 r->attributes = info2->attributes;
3966 r->priority = info2->priority;
3967 r->defaultpriority = info2->defaultpriority;
3968 r->starttime = info2->starttime;
3969 r->untiltime = info2->untiltime;
3970 r->status = nt_printq_status(status.status);
3972 r->averageppm = info2->averageppm;
3974 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
3976 DEBUG(8,("Returning NULL Devicemode!\n"));
3979 compose_devicemode_devicename(r->devmode, r->printername);
3983 if (info2->secdesc != NULL) {
3984 /* don't use talloc_steal() here unless you do a deep steal of all
3985 the SEC_DESC members */
3987 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
3993 /********************************************************************
3994 * construct_printer_info3
3995 * fill a spoolss_PrinterInfo3 struct
3996 ********************************************************************/
3998 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
3999 const struct spoolss_PrinterInfo2 *info2,
4000 const char *servername,
4001 struct spoolss_PrinterInfo3 *r,
4004 /* These are the components of the SD we are returning. */
4006 if (info2->secdesc != NULL) {
4007 /* don't use talloc_steal() here unless you do a deep steal of all
4008 the SEC_DESC members */
4010 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
4011 W_ERROR_HAVE_NO_MEMORY(r->secdesc);
4017 /********************************************************************
4018 * construct_printer_info4
4019 * fill a spoolss_PrinterInfo4 struct
4020 ********************************************************************/
4022 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
4023 const struct spoolss_PrinterInfo2 *info2,
4024 const char *servername,
4025 struct spoolss_PrinterInfo4 *r,
4030 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
4031 if (!W_ERROR_IS_OK(result)) {
4036 r->servername = talloc_strdup(mem_ctx, servername);
4037 W_ERROR_HAVE_NO_MEMORY(r->servername);
4039 r->servername = NULL;
4042 r->attributes = info2->attributes;
4047 /********************************************************************
4048 * construct_printer_info5
4049 * fill a spoolss_PrinterInfo5 struct
4050 ********************************************************************/
4052 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
4053 const struct spoolss_PrinterInfo2 *info2,
4054 const char *servername,
4055 struct spoolss_PrinterInfo5 *r,
4060 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
4061 if (!W_ERROR_IS_OK(result)) {
4065 r->portname = talloc_strdup(mem_ctx, info2->portname);
4066 W_ERROR_HAVE_NO_MEMORY(r->portname);
4068 r->attributes = info2->attributes;
4070 /* these two are not used by NT+ according to MSDN */
4071 r->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
4072 r->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
4077 /********************************************************************
4078 * construct_printer_info_6
4079 * fill a spoolss_PrinterInfo6 struct
4080 ********************************************************************/
4082 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
4083 struct messaging_context *msg_ctx,
4084 const struct spoolss_PrinterInfo2 *info2,
4085 const char *servername,
4086 struct spoolss_PrinterInfo6 *r,
4090 print_status_struct status;
4092 count = print_queue_length(msg_ctx, snum, &status);
4094 r->status = nt_printq_status(status.status);
4099 /********************************************************************
4100 * construct_printer_info7
4101 * fill a spoolss_PrinterInfo7 struct
4102 ********************************************************************/
4104 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
4105 struct messaging_context *msg_ctx,
4106 const char *servername,
4107 struct spoolss_PrinterInfo7 *r,
4110 struct auth_serversupplied_info *server_info;
4114 status = make_server_info_system(mem_ctx, &server_info);
4115 if (!NT_STATUS_IS_OK(status)) {
4116 DEBUG(0, ("construct_printer_info7: "
4117 "Could not create system server_info\n"));
4121 if (is_printer_published(mem_ctx, server_info, msg_ctx,
4123 lp_servicename(snum), &guid, NULL)) {
4124 r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
4125 r->action = DSPRINT_PUBLISH;
4127 r->guid = talloc_strdup(mem_ctx, "");
4128 r->action = DSPRINT_UNPUBLISH;
4130 W_ERROR_HAVE_NO_MEMORY(r->guid);
4132 TALLOC_FREE(server_info);
4136 /********************************************************************
4137 * construct_printer_info8
4138 * fill a spoolss_PrinterInfo8 struct
4139 ********************************************************************/
4141 static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
4142 const struct spoolss_PrinterInfo2 *info2,
4143 const char *servername,
4144 struct spoolss_DeviceModeInfo *r,
4148 const char *printername;
4150 result = create_printername(mem_ctx, servername, info2->printername, &printername);
4151 if (!W_ERROR_IS_OK(result)) {
4155 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
4157 DEBUG(8,("Returning NULL Devicemode!\n"));
4160 compose_devicemode_devicename(r->devmode, printername);
4166 /********************************************************************
4167 ********************************************************************/
4169 static bool snum_is_shared_printer(int snum)
4171 return (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum));
4174 /********************************************************************
4175 Spoolss_enumprinters.
4176 ********************************************************************/
4178 static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
4179 const struct auth_serversupplied_info *server_info,
4180 struct messaging_context *msg_ctx,
4181 const char *servername,
4184 union spoolss_PrinterInfo **info_p,
4188 int n_services = lp_numservices();
4189 union spoolss_PrinterInfo *info = NULL;
4191 WERROR result = WERR_OK;
4196 for (snum = 0; snum < n_services; snum++) {
4198 const char *printer;
4199 struct spoolss_PrinterInfo2 *info2;
4201 if (!snum_is_shared_printer(snum)) {
4205 printer = lp_const_servicename(snum);
4207 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
4210 result = winreg_create_printer(mem_ctx,
4214 if (!W_ERROR_IS_OK(result)) {
4218 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4219 union spoolss_PrinterInfo,
4222 result = WERR_NOMEM;
4226 result = winreg_get_printer(mem_ctx, server_info, msg_ctx,
4228 if (!W_ERROR_IS_OK(result)) {
4234 result = construct_printer_info0(info, server_info,
4237 &info[count].info0, snum);
4240 result = construct_printer_info1(info, info2, flags,
4242 &info[count].info1, snum);
4245 result = construct_printer_info2(info, msg_ctx, info2,
4247 &info[count].info2, snum);
4250 result = construct_printer_info4(info, info2,
4252 &info[count].info4, snum);
4255 result = construct_printer_info5(info, info2,
4257 &info[count].info5, snum);
4261 result = WERR_UNKNOWN_LEVEL;
4265 if (!W_ERROR_IS_OK(result)) {
4276 if (!W_ERROR_IS_OK(result)) {
4286 /********************************************************************
4287 * handle enumeration of printers at level 0
4288 ********************************************************************/
4290 static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
4291 const struct auth_serversupplied_info *server_info,
4292 struct messaging_context *msg_ctx,
4294 const char *servername,
4295 union spoolss_PrinterInfo **info,
4298 DEBUG(4,("enum_all_printers_info_0\n"));
4300 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4301 servername, 0, flags, info, count);
4305 /********************************************************************
4306 ********************************************************************/
4308 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
4309 const struct auth_serversupplied_info *server_info,
4310 struct messaging_context *msg_ctx,
4311 const char *servername,
4313 union spoolss_PrinterInfo **info,
4316 DEBUG(4,("enum_all_printers_info_1\n"));
4318 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4319 servername, 1, flags, info, count);
4322 /********************************************************************
4323 enum_all_printers_info_1_local.
4324 *********************************************************************/
4326 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
4327 const struct auth_serversupplied_info *server_info,
4328 struct messaging_context *msg_ctx,
4329 const char *servername,
4330 union spoolss_PrinterInfo **info,
4333 DEBUG(4,("enum_all_printers_info_1_local\n"));
4335 return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
4336 servername, PRINTER_ENUM_ICON8, info, count);
4339 /********************************************************************
4340 enum_all_printers_info_1_name.
4341 *********************************************************************/
4343 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
4344 const struct auth_serversupplied_info *server_info,
4345 struct messaging_context *msg_ctx,
4346 const char *servername,
4347 union spoolss_PrinterInfo **info,
4350 const char *s = servername;
4352 DEBUG(4,("enum_all_printers_info_1_name\n"));
4354 if ((servername[0] == '\\') && (servername[1] == '\\')) {
4358 if (!is_myname_or_ipaddr(s)) {
4359 return WERR_INVALID_NAME;
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_network.
4368 *********************************************************************/
4370 static WERROR enum_all_printers_info_1_network(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_network\n"));
4381 /* If we respond to a enum_printers level 1 on our name with flags
4382 set to PRINTER_ENUM_REMOTE with a list of printers then these
4383 printers incorrectly appear in the APW browse list.
4384 Specifically the printers for the server appear at the workgroup
4385 level where all the other servers in the domain are
4386 listed. Windows responds to this call with a
4387 WERR_CAN_NOT_COMPLETE so we should do the same. */
4389 if (servername[0] == '\\' && servername[1] == '\\') {
4393 if (is_myname_or_ipaddr(s)) {
4394 return WERR_CAN_NOT_COMPLETE;
4397 return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
4398 servername, PRINTER_ENUM_NAME, info, count);
4401 /********************************************************************
4402 * api_spoolss_enumprinters
4404 * called from api_spoolss_enumprinters (see this to understand)
4405 ********************************************************************/
4407 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
4408 const struct auth_serversupplied_info *server_info,
4409 struct messaging_context *msg_ctx,
4410 const char *servername,
4411 union spoolss_PrinterInfo **info,
4414 DEBUG(4,("enum_all_printers_info_2\n"));
4416 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4417 servername, 2, 0, info, count);
4420 /********************************************************************
4421 * handle enumeration of printers at level 1
4422 ********************************************************************/
4424 static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
4425 const struct auth_serversupplied_info *server_info,
4426 struct messaging_context *msg_ctx,
4428 const char *servername,
4429 union spoolss_PrinterInfo **info,
4432 /* Not all the flags are equals */
4434 if (flags & PRINTER_ENUM_LOCAL) {
4435 return enum_all_printers_info_1_local(mem_ctx, server_info,
4436 msg_ctx, servername, info, count);
4439 if (flags & PRINTER_ENUM_NAME) {
4440 return enum_all_printers_info_1_name(mem_ctx, server_info,
4441 msg_ctx, servername, info,
4445 if (flags & PRINTER_ENUM_NETWORK) {
4446 return enum_all_printers_info_1_network(mem_ctx, server_info,
4447 msg_ctx, servername, info,
4451 return WERR_OK; /* NT4sp5 does that */
4454 /********************************************************************
4455 * handle enumeration of printers at level 2
4456 ********************************************************************/
4458 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
4459 const struct auth_serversupplied_info *server_info,
4460 struct messaging_context *msg_ctx,
4462 const char *servername,
4463 union spoolss_PrinterInfo **info,
4466 if (flags & PRINTER_ENUM_LOCAL) {
4468 return enum_all_printers_info_2(mem_ctx, server_info, msg_ctx,
4473 if (flags & PRINTER_ENUM_NAME) {
4474 if (servername && !is_myname_or_ipaddr(canon_servername(servername))) {
4475 return WERR_INVALID_NAME;
4478 return enum_all_printers_info_2(mem_ctx, server_info, msg_ctx,
4483 if (flags & PRINTER_ENUM_REMOTE) {
4484 return WERR_UNKNOWN_LEVEL;
4490 /********************************************************************
4491 * handle enumeration of printers at level 4
4492 ********************************************************************/
4494 static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
4495 const struct auth_serversupplied_info *server_info,
4496 struct messaging_context *msg_ctx,
4498 const char *servername,
4499 union spoolss_PrinterInfo **info,
4502 DEBUG(4,("enum_all_printers_info_4\n"));
4504 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4505 servername, 4, flags, info, count);
4509 /********************************************************************
4510 * handle enumeration of printers at level 5
4511 ********************************************************************/
4513 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
4514 const struct auth_serversupplied_info *server_info,
4515 struct messaging_context *msg_ctx,
4517 const char *servername,
4518 union spoolss_PrinterInfo **info,
4521 DEBUG(4,("enum_all_printers_info_5\n"));
4523 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4524 servername, 5, flags, info, count);
4527 /****************************************************************
4528 _spoolss_EnumPrinters
4529 ****************************************************************/
4531 WERROR _spoolss_EnumPrinters(struct pipes_struct *p,
4532 struct spoolss_EnumPrinters *r)
4534 const struct auth_serversupplied_info *server_info = get_server_info_system();
4537 /* that's an [in out] buffer */
4539 if (!r->in.buffer && (r->in.offered != 0)) {
4540 return WERR_INVALID_PARAM;
4543 DEBUG(4,("_spoolss_EnumPrinters\n"));
4547 *r->out.info = NULL;
4551 * flags==PRINTER_ENUM_NAME
4552 * if name=="" then enumerates all printers
4553 * if name!="" then enumerate the printer
4554 * flags==PRINTER_ENUM_REMOTE
4555 * name is NULL, enumerate printers
4556 * Level 2: name!="" enumerates printers, name can't be NULL
4557 * Level 3: doesn't exist
4558 * Level 4: does a local registry lookup
4559 * Level 5: same as Level 2
4562 if (r->in.server && r->in.server[0] == '\0') {
4563 r->in.server = NULL;
4566 switch (r->in.level) {
4568 result = enumprinters_level0(p->mem_ctx, server_info,
4569 p->msg_ctx, r->in.flags,
4571 r->out.info, r->out.count);
4574 result = enumprinters_level1(p->mem_ctx, server_info,
4575 p->msg_ctx, r->in.flags,
4577 r->out.info, r->out.count);
4580 result = enumprinters_level2(p->mem_ctx, server_info,
4581 p->msg_ctx, r->in.flags,
4583 r->out.info, r->out.count);
4586 result = enumprinters_level4(p->mem_ctx, server_info,
4587 p->msg_ctx, r->in.flags,
4589 r->out.info, r->out.count);
4592 result = enumprinters_level5(p->mem_ctx, server_info,
4593 p->msg_ctx, r->in.flags,
4595 r->out.info, r->out.count);
4598 return WERR_UNKNOWN_LEVEL;
4601 if (!W_ERROR_IS_OK(result)) {
4605 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
4606 spoolss_EnumPrinters,
4607 *r->out.info, r->in.level,
4609 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
4610 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
4612 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4615 /****************************************************************
4617 ****************************************************************/
4619 WERROR _spoolss_GetPrinter(struct pipes_struct *p,
4620 struct spoolss_GetPrinter *r)
4622 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
4623 struct spoolss_PrinterInfo2 *info2 = NULL;
4624 WERROR result = WERR_OK;
4627 /* that's an [in out] buffer */
4629 if (!r->in.buffer && (r->in.offered != 0)) {
4630 return WERR_INVALID_PARAM;
4635 if (Printer == NULL) {
4639 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
4643 result = winreg_get_printer(p->mem_ctx,
4644 get_server_info_system(),
4646 lp_const_servicename(snum),
4648 if (!W_ERROR_IS_OK(result)) {
4652 switch (r->in.level) {
4654 result = construct_printer_info0(p->mem_ctx,
4655 get_server_info_system(),
4658 Printer->servername,
4659 &r->out.info->info0,
4663 result = construct_printer_info1(p->mem_ctx, info2,
4665 Printer->servername,
4666 &r->out.info->info1, snum);
4669 result = construct_printer_info2(p->mem_ctx, p->msg_ctx, info2,
4670 Printer->servername,
4671 &r->out.info->info2, snum);
4674 result = construct_printer_info3(p->mem_ctx, info2,
4675 Printer->servername,
4676 &r->out.info->info3, snum);
4679 result = construct_printer_info4(p->mem_ctx, info2,
4680 Printer->servername,
4681 &r->out.info->info4, snum);
4684 result = construct_printer_info5(p->mem_ctx, info2,
4685 Printer->servername,
4686 &r->out.info->info5, snum);
4689 result = construct_printer_info6(p->mem_ctx, p->msg_ctx, info2,
4690 Printer->servername,
4691 &r->out.info->info6, snum);
4694 result = construct_printer_info7(p->mem_ctx, p->msg_ctx,
4695 Printer->servername,
4696 &r->out.info->info7, snum);
4699 result = construct_printer_info8(p->mem_ctx, info2,
4700 Printer->servername,
4701 &r->out.info->info8, snum);
4704 result = WERR_UNKNOWN_LEVEL;
4709 if (!W_ERROR_IS_OK(result)) {
4710 DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
4711 r->in.level, win_errstr(result)));
4712 TALLOC_FREE(r->out.info);
4716 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo,
4717 r->out.info, r->in.level);
4718 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4720 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4723 /********************************************************************
4724 ********************************************************************/
4726 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4728 if (in && strlen(in)) { \
4729 out = talloc_strdup(mem_ctx, in); \
4731 out = talloc_strdup(mem_ctx, ""); \
4733 W_ERROR_HAVE_NO_MEMORY(out); \
4736 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, arch, ver, in, out) \
4738 if (in && strlen(in)) { \
4739 out = talloc_asprintf(mem_ctx, "\\\\%s\\print$\\%s\\%d\\%s", server, get_short_archi(arch), ver, in); \
4741 out = talloc_strdup(mem_ctx, ""); \
4743 W_ERROR_HAVE_NO_MEMORY(out); \
4746 static WERROR string_array_from_driver_info(TALLOC_CTX *mem_ctx,
4747 const char **string_array,
4748 const char ***presult,
4749 const char *cservername,
4753 int i, num_strings = 0;
4754 const char **array = NULL;
4756 if (string_array == NULL) {
4757 return WERR_INVALID_PARAMETER;;
4760 for (i=0; string_array[i] && string_array[i][0] != '\0'; i++) {
4761 const char *str = NULL;
4763 if (cservername == NULL || arch == NULL) {
4764 FILL_DRIVER_STRING(mem_ctx, string_array[i], str);
4766 FILL_DRIVER_UNC_STRING(mem_ctx, cservername, arch, version, string_array[i], str);
4769 if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
4776 ADD_TO_ARRAY(mem_ctx, const char *, NULL,
4777 &array, &num_strings);
4787 /********************************************************************
4788 * fill a spoolss_DriverInfo1 struct
4789 ********************************************************************/
4791 static WERROR fill_printer_driver_info1(TALLOC_CTX *mem_ctx,
4792 struct spoolss_DriverInfo1 *r,
4793 const struct spoolss_DriverInfo8 *driver,
4794 const char *servername)
4796 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4797 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4802 /********************************************************************
4803 * fill a spoolss_DriverInfo2 struct
4804 ********************************************************************/
4806 static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
4807 struct spoolss_DriverInfo2 *r,
4808 const struct spoolss_DriverInfo8 *driver,
4809 const char *servername)
4812 const char *cservername = canon_servername(servername);
4814 r->version = driver->version;
4816 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4817 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4818 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4819 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4821 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4822 driver->architecture,
4824 driver->driver_path,
4827 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4828 driver->architecture,
4833 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4834 driver->architecture,
4836 driver->config_file,
4842 /********************************************************************
4843 * fill a spoolss_DriverInfo3 struct
4844 ********************************************************************/
4846 static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
4847 struct spoolss_DriverInfo3 *r,
4848 const struct spoolss_DriverInfo8 *driver,
4849 const char *servername)
4851 const char *cservername = canon_servername(servername);
4853 r->version = driver->version;
4855 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4856 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4857 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4858 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4860 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4861 driver->architecture,
4863 driver->driver_path,
4866 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4867 driver->architecture,
4872 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4873 driver->architecture,
4875 driver->config_file,
4878 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4879 driver->architecture,
4884 FILL_DRIVER_STRING(mem_ctx,
4885 driver->monitor_name,
4888 FILL_DRIVER_STRING(mem_ctx,
4889 driver->default_datatype,
4890 r->default_datatype);
4892 return string_array_from_driver_info(mem_ctx,
4893 driver->dependent_files,
4894 &r->dependent_files,
4896 driver->architecture,
4900 /********************************************************************
4901 * fill a spoolss_DriverInfo4 struct
4902 ********************************************************************/
4904 static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
4905 struct spoolss_DriverInfo4 *r,
4906 const struct spoolss_DriverInfo8 *driver,
4907 const char *servername)
4909 const char *cservername = canon_servername(servername);
4912 r->version = driver->version;
4914 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4915 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4916 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4917 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4919 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4920 driver->architecture,
4922 driver->driver_path,
4925 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4926 driver->architecture,
4931 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4932 driver->architecture,
4934 driver->config_file,
4937 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4938 driver->architecture,
4943 result = string_array_from_driver_info(mem_ctx,
4944 driver->dependent_files,
4945 &r->dependent_files,
4947 driver->architecture,
4949 if (!W_ERROR_IS_OK(result)) {
4953 FILL_DRIVER_STRING(mem_ctx,
4954 driver->monitor_name,
4957 FILL_DRIVER_STRING(mem_ctx,
4958 driver->default_datatype,
4959 r->default_datatype);
4962 result = string_array_from_driver_info(mem_ctx,
4963 driver->previous_names,
4970 /********************************************************************
4971 * fill a spoolss_DriverInfo5 struct
4972 ********************************************************************/
4974 static WERROR fill_printer_driver_info5(TALLOC_CTX *mem_ctx,
4975 struct spoolss_DriverInfo5 *r,
4976 const struct spoolss_DriverInfo8 *driver,
4977 const char *servername)
4979 const char *cservername = canon_servername(servername);
4981 r->version = driver->version;
4983 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4984 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4985 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4986 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4988 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4989 driver->architecture,
4991 driver->driver_path,
4994 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4995 driver->architecture,
5000 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5001 driver->architecture,
5003 driver->config_file,
5006 r->driver_attributes = 0;
5007 r->config_version = 0;
5008 r->driver_version = 0;
5012 /********************************************************************
5013 * fill a spoolss_DriverInfo6 struct
5014 ********************************************************************/
5016 static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
5017 struct spoolss_DriverInfo6 *r,
5018 const struct spoolss_DriverInfo8 *driver,
5019 const char *servername)
5021 const char *cservername = canon_servername(servername);
5024 r->version = driver->version;
5026 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5027 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5028 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5029 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5031 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5032 driver->architecture,
5034 driver->driver_path,
5037 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5038 driver->architecture,
5043 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5044 driver->architecture,
5046 driver->config_file,
5049 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5050 driver->architecture,
5055 FILL_DRIVER_STRING(mem_ctx,
5056 driver->monitor_name,
5059 FILL_DRIVER_STRING(mem_ctx,
5060 driver->default_datatype,
5061 r->default_datatype);
5063 result = string_array_from_driver_info(mem_ctx,
5064 driver->dependent_files,
5065 &r->dependent_files,
5067 driver->architecture,
5069 if (!W_ERROR_IS_OK(result)) {
5073 result = string_array_from_driver_info(mem_ctx,
5074 driver->previous_names,
5077 if (!W_ERROR_IS_OK(result)) {
5081 r->driver_date = driver->driver_date;
5082 r->driver_version = driver->driver_version;
5084 FILL_DRIVER_STRING(mem_ctx,
5085 driver->manufacturer_name,
5086 r->manufacturer_name);
5087 FILL_DRIVER_STRING(mem_ctx,
5088 driver->manufacturer_url,
5089 r->manufacturer_url);
5090 FILL_DRIVER_STRING(mem_ctx,
5091 driver->hardware_id,
5093 FILL_DRIVER_STRING(mem_ctx,
5100 /********************************************************************
5101 * fill a spoolss_DriverInfo8 struct
5102 ********************************************************************/
5104 static WERROR fill_printer_driver_info8(TALLOC_CTX *mem_ctx,
5105 struct spoolss_DriverInfo8 *r,
5106 const struct spoolss_DriverInfo8 *driver,
5107 const char *servername)
5109 const char *cservername = canon_servername(servername);
5112 r->version = driver->version;
5114 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5115 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5116 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5117 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5119 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5120 driver->architecture,
5122 driver->driver_path,
5125 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5126 driver->architecture,
5131 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5132 driver->architecture,
5134 driver->config_file,
5137 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5138 driver->architecture,
5143 FILL_DRIVER_STRING(mem_ctx,
5144 driver->monitor_name,
5147 FILL_DRIVER_STRING(mem_ctx,
5148 driver->default_datatype,
5149 r->default_datatype);
5151 result = string_array_from_driver_info(mem_ctx,
5152 driver->dependent_files,
5153 &r->dependent_files,
5155 driver->architecture,
5157 if (!W_ERROR_IS_OK(result)) {
5161 result = string_array_from_driver_info(mem_ctx,
5162 driver->previous_names,
5165 if (!W_ERROR_IS_OK(result)) {
5169 r->driver_date = driver->driver_date;
5170 r->driver_version = driver->driver_version;
5172 FILL_DRIVER_STRING(mem_ctx,
5173 driver->manufacturer_name,
5174 r->manufacturer_name);
5175 FILL_DRIVER_STRING(mem_ctx,
5176 driver->manufacturer_url,
5177 r->manufacturer_url);
5178 FILL_DRIVER_STRING(mem_ctx,
5179 driver->hardware_id,
5181 FILL_DRIVER_STRING(mem_ctx,
5185 FILL_DRIVER_STRING(mem_ctx,
5186 driver->print_processor,
5187 r->print_processor);
5188 FILL_DRIVER_STRING(mem_ctx,
5189 driver->vendor_setup,
5192 result = string_array_from_driver_info(mem_ctx,
5193 driver->color_profiles,
5196 if (!W_ERROR_IS_OK(result)) {
5200 FILL_DRIVER_STRING(mem_ctx,
5204 r->printer_driver_attributes = driver->printer_driver_attributes;
5206 result = string_array_from_driver_info(mem_ctx,
5207 driver->core_driver_dependencies,
5208 &r->core_driver_dependencies,
5210 if (!W_ERROR_IS_OK(result)) {
5214 r->min_inbox_driver_ver_date = driver->min_inbox_driver_ver_date;
5215 r->min_inbox_driver_ver_version = driver->min_inbox_driver_ver_version;
5220 #if 0 /* disabled until marshalling issues are resolved - gd */
5221 /********************************************************************
5222 ********************************************************************/
5224 static WERROR fill_spoolss_DriverFileInfo(TALLOC_CTX *mem_ctx,
5225 struct spoolss_DriverFileInfo *r,
5226 const char *cservername,
5227 const char *file_name,
5228 enum spoolss_DriverFileType file_type,
5229 uint32_t file_version)
5231 r->file_name = talloc_asprintf(mem_ctx, "\\\\%s%s",
5232 cservername, file_name);
5233 W_ERROR_HAVE_NO_MEMORY(r->file_name);
5234 r->file_type = file_type;
5235 r->file_version = file_version;
5240 /********************************************************************
5241 ********************************************************************/
5243 static WERROR spoolss_DriverFileInfo_from_driver(TALLOC_CTX *mem_ctx,
5244 const struct spoolss_DriverInfo8 *driver,
5245 const char *cservername,
5246 struct spoolss_DriverFileInfo **info_p,
5249 struct spoolss_DriverFileInfo *info = NULL;
5257 if (strlen(driver->driver_path)) {
5258 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5259 struct spoolss_DriverFileInfo,
5261 W_ERROR_HAVE_NO_MEMORY(info);
5262 result = fill_spoolss_DriverFileInfo(info,
5265 driver->driver_path,
5266 SPOOLSS_DRIVER_FILE_TYPE_RENDERING,
5268 W_ERROR_NOT_OK_RETURN(result);
5272 if (strlen(driver->config_file)) {
5273 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5274 struct spoolss_DriverFileInfo,
5276 W_ERROR_HAVE_NO_MEMORY(info);
5277 result = fill_spoolss_DriverFileInfo(info,
5280 driver->config_file,
5281 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION,
5283 W_ERROR_NOT_OK_RETURN(result);
5287 if (strlen(driver->data_file)) {
5288 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5289 struct spoolss_DriverFileInfo,
5291 W_ERROR_HAVE_NO_MEMORY(info);
5292 result = fill_spoolss_DriverFileInfo(info,
5296 SPOOLSS_DRIVER_FILE_TYPE_DATA,
5298 W_ERROR_NOT_OK_RETURN(result);
5302 if (strlen(driver->help_file)) {
5303 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5304 struct spoolss_DriverFileInfo,
5306 W_ERROR_HAVE_NO_MEMORY(info);
5307 result = fill_spoolss_DriverFileInfo(info,
5311 SPOOLSS_DRIVER_FILE_TYPE_HELP,
5313 W_ERROR_NOT_OK_RETURN(result);
5317 for (i=0; driver->dependent_files[i] && driver->dependent_files[i][0] != '\0'; i++) {
5318 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5319 struct spoolss_DriverFileInfo,
5321 W_ERROR_HAVE_NO_MEMORY(info);
5322 result = fill_spoolss_DriverFileInfo(info,
5325 driver->dependent_files[i],
5326 SPOOLSS_DRIVER_FILE_TYPE_OTHER,
5328 W_ERROR_NOT_OK_RETURN(result);
5338 /********************************************************************
5339 * fill a spoolss_DriverInfo101 struct
5340 ********************************************************************/
5342 static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
5343 struct spoolss_DriverInfo101 *r,
5344 const struct spoolss_DriverInfo8 *driver,
5345 const char *servername)
5347 const char *cservername = canon_servername(servername);
5350 r->version = driver->version;
5352 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5353 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5354 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5355 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5357 result = spoolss_DriverFileInfo_from_driver(mem_ctx, driver,
5361 if (!W_ERROR_IS_OK(result)) {
5365 FILL_DRIVER_STRING(mem_ctx,
5366 driver->monitor_name,
5369 FILL_DRIVER_STRING(mem_ctx,
5370 driver->default_datatype,
5371 r->default_datatype);
5373 result = string_array_from_driver_info(mem_ctx,
5374 driver->previous_names,
5377 if (!W_ERROR_IS_OK(result)) {
5381 r->driver_date = driver->driver_date;
5382 r->driver_version = driver->driver_version;
5384 FILL_DRIVER_STRING(mem_ctx,
5385 driver->manufacturer_name,
5386 r->manufacturer_name);
5387 FILL_DRIVER_STRING(mem_ctx,
5388 driver->manufacturer_url,
5389 r->manufacturer_url);
5390 FILL_DRIVER_STRING(mem_ctx,
5391 driver->hardware_id,
5393 FILL_DRIVER_STRING(mem_ctx,
5400 /********************************************************************
5401 ********************************************************************/
5403 static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
5404 const struct auth_serversupplied_info *server_info,
5405 struct messaging_context *msg_ctx,
5407 union spoolss_DriverInfo *r,
5409 const char *servername,
5410 const char *architecture,
5413 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
5414 struct spoolss_DriverInfo8 *driver;
5418 return WERR_UNKNOWN_LEVEL;
5421 result = winreg_get_printer(mem_ctx,
5424 lp_const_servicename(snum),
5427 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5428 win_errstr(result)));
5430 if (!W_ERROR_IS_OK(result)) {
5431 return WERR_INVALID_PRINTER_NAME;
5434 result = winreg_get_driver(mem_ctx, server_info, msg_ctx,
5436 pinfo2->drivername, version, &driver);
5438 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5439 win_errstr(result)));
5441 if (!W_ERROR_IS_OK(result)) {
5443 * Is this a W2k client ?
5447 talloc_free(pinfo2);
5448 return WERR_UNKNOWN_PRINTER_DRIVER;
5451 /* Yes - try again with a WinNT driver. */
5453 result = winreg_get_driver(mem_ctx, server_info, msg_ctx,
5457 DEBUG(8,("construct_printer_driver_level: status: %s\n",
5458 win_errstr(result)));
5459 if (!W_ERROR_IS_OK(result)) {
5460 talloc_free(pinfo2);
5461 return WERR_UNKNOWN_PRINTER_DRIVER;
5467 result = fill_printer_driver_info1(mem_ctx, &r->info1, driver, servername);
5470 result = fill_printer_driver_info2(mem_ctx, &r->info2, driver, servername);
5473 result = fill_printer_driver_info3(mem_ctx, &r->info3, driver, servername);
5476 result = fill_printer_driver_info4(mem_ctx, &r->info4, driver, servername);
5479 result = fill_printer_driver_info5(mem_ctx, &r->info5, driver, servername);
5482 result = fill_printer_driver_info6(mem_ctx, &r->info6, driver, servername);
5485 result = fill_printer_driver_info8(mem_ctx, &r->info8, driver, servername);
5487 #if 0 /* disabled until marshalling issues are resolved - gd */
5489 result = fill_printer_driver_info101(mem_ctx, &r->info101, driver, servername);
5493 result = WERR_UNKNOWN_LEVEL;
5497 talloc_free(pinfo2);
5498 talloc_free(driver);
5503 /****************************************************************
5504 _spoolss_GetPrinterDriver2
5505 ****************************************************************/
5507 WERROR _spoolss_GetPrinterDriver2(struct pipes_struct *p,
5508 struct spoolss_GetPrinterDriver2 *r)
5510 struct printer_handle *printer;
5515 /* that's an [in out] buffer */
5517 if (!r->in.buffer && (r->in.offered != 0)) {
5518 return WERR_INVALID_PARAM;
5521 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5523 if (!(printer = find_printer_index_by_hnd(p, r->in.handle))) {
5524 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5525 return WERR_INVALID_PRINTER_NAME;
5529 *r->out.server_major_version = 0;
5530 *r->out.server_minor_version = 0;
5532 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5536 result = construct_printer_driver_info_level(p->mem_ctx,
5537 get_server_info_system(),
5539 r->in.level, r->out.info,
5540 snum, printer->servername,
5542 r->in.client_major_version);
5543 if (!W_ERROR_IS_OK(result)) {
5544 TALLOC_FREE(r->out.info);
5548 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverInfo,
5549 r->out.info, r->in.level);
5550 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
5552 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
5556 /****************************************************************
5557 _spoolss_StartPagePrinter
5558 ****************************************************************/
5560 WERROR _spoolss_StartPagePrinter(struct pipes_struct *p,
5561 struct spoolss_StartPagePrinter *r)
5563 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5566 DEBUG(3,("_spoolss_StartPagePrinter: "
5567 "Error in startpageprinter printer handle\n"));
5571 Printer->page_started = true;
5575 /****************************************************************
5576 _spoolss_EndPagePrinter
5577 ****************************************************************/
5579 WERROR _spoolss_EndPagePrinter(struct pipes_struct *p,
5580 struct spoolss_EndPagePrinter *r)
5584 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5587 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5588 OUR_HANDLE(r->in.handle)));
5592 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5595 Printer->page_started = false;
5596 print_job_endpage(p->msg_ctx, snum, Printer->jobid);
5601 /****************************************************************
5602 _spoolss_StartDocPrinter
5603 ****************************************************************/
5605 WERROR _spoolss_StartDocPrinter(struct pipes_struct *p,
5606 struct spoolss_StartDocPrinter *r)
5608 struct spoolss_DocumentInfo1 *info_1;
5610 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5614 DEBUG(2,("_spoolss_StartDocPrinter: "
5615 "Invalid handle (%s:%u:%u)\n",
5616 OUR_HANDLE(r->in.handle)));
5620 if (Printer->jobid) {
5621 DEBUG(2, ("_spoolss_StartDocPrinter: "
5622 "StartDocPrinter called twice! "
5623 "(existing jobid = %d)\n", Printer->jobid));
5624 return WERR_INVALID_HANDLE;
5627 if (r->in.level != 1) {
5628 return WERR_UNKNOWN_LEVEL;
5631 info_1 = r->in.info.info1;
5634 * a nice thing with NT is it doesn't listen to what you tell it.
5635 * when asked to send _only_ RAW datas, it tries to send datas
5638 * So I add checks like in NT Server ...
5641 if (info_1->datatype) {
5642 if (strcmp(info_1->datatype, "RAW") != 0) {
5644 return WERR_INVALID_DATATYPE;
5648 /* get the share number of the printer */
5649 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5653 werr = print_job_start(p->server_info,
5657 info_1->document_name,
5658 info_1->output_file,
5662 /* An error occured in print_job_start() so return an appropriate
5665 if (!W_ERROR_IS_OK(werr)) {
5669 Printer->document_started = true;
5670 *r->out.job_id = Printer->jobid;
5675 /****************************************************************
5676 _spoolss_EndDocPrinter
5677 ****************************************************************/
5679 WERROR _spoolss_EndDocPrinter(struct pipes_struct *p,
5680 struct spoolss_EndDocPrinter *r)
5682 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5687 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5688 OUR_HANDLE(r->in.handle)));
5692 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5696 Printer->document_started = false;
5697 status = print_job_end(p->msg_ctx, snum, Printer->jobid, NORMAL_CLOSE);
5698 if (!NT_STATUS_IS_OK(status)) {
5699 DEBUG(2, ("_spoolss_EndDocPrinter: "
5700 "print_job_end failed [%s]\n",
5701 nt_errstr(status)));
5705 return ntstatus_to_werror(status);
5708 /****************************************************************
5709 _spoolss_WritePrinter
5710 ****************************************************************/
5712 WERROR _spoolss_WritePrinter(struct pipes_struct *p,
5713 struct spoolss_WritePrinter *r)
5715 ssize_t buffer_written;
5717 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5720 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5721 OUR_HANDLE(r->in.handle)));
5722 *r->out.num_written = r->in._data_size;
5726 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5729 /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
5730 buffer_written = print_job_write(server_event_context(),p->msg_ctx,
5731 snum, Printer->jobid,
5732 (const char *)r->in.data.data,
5733 (size_t)r->in._data_size);
5734 if (buffer_written == (ssize_t)-1) {
5735 *r->out.num_written = 0;
5736 if (errno == ENOSPC)
5737 return WERR_NO_SPOOL_SPACE;
5739 return WERR_ACCESS_DENIED;
5742 *r->out.num_written = r->in._data_size;
5747 /********************************************************************
5748 * api_spoolss_getprinter
5749 * called from the spoolss dispatcher
5751 ********************************************************************/
5753 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
5754 struct pipes_struct *p)
5756 const struct auth_serversupplied_info *server_info = p->server_info;
5758 WERROR errcode = WERR_BADFUNC;
5759 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
5762 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5763 OUR_HANDLE(handle)));
5767 if (!get_printer_snum(p, handle, &snum, NULL))
5771 case SPOOLSS_PRINTER_CONTROL_PAUSE:
5772 errcode = print_queue_pause(server_info, p->msg_ctx, snum);
5774 case SPOOLSS_PRINTER_CONTROL_RESUME:
5775 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
5776 errcode = print_queue_resume(server_info, p->msg_ctx, snum);
5778 case SPOOLSS_PRINTER_CONTROL_PURGE:
5779 errcode = print_queue_purge(server_info, p->msg_ctx, snum);
5782 return WERR_UNKNOWN_LEVEL;
5789 /****************************************************************
5790 _spoolss_AbortPrinter
5791 * From MSDN: "Deletes printer's spool file if printer is configured
5793 ****************************************************************/
5795 WERROR _spoolss_AbortPrinter(struct pipes_struct *p,
5796 struct spoolss_AbortPrinter *r)
5798 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5800 WERROR errcode = WERR_OK;
5803 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5804 OUR_HANDLE(r->in.handle)));
5808 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5811 if (!Printer->document_started) {
5812 return WERR_SPL_NO_STARTDOC;
5815 errcode = print_job_delete(p->server_info,
5823 /********************************************************************
5824 * called by spoolss_api_setprinter
5825 * when updating a printer description
5826 ********************************************************************/
5828 static WERROR update_printer_sec(struct policy_handle *handle,
5829 struct pipes_struct *p,
5830 struct sec_desc_buf *secdesc_ctr)
5832 struct spoolss_security_descriptor *new_secdesc = NULL;
5833 struct spoolss_security_descriptor *old_secdesc = NULL;
5834 const char *printer;
5838 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
5840 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
5841 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
5842 OUR_HANDLE(handle)));
5844 result = WERR_BADFID;
5848 if (secdesc_ctr == NULL) {
5849 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
5850 result = WERR_INVALID_PARAM;
5853 printer = lp_const_servicename(snum);
5855 /* Check the user has permissions to change the security
5856 descriptor. By experimentation with two NT machines, the user
5857 requires Full Access to the printer to change security
5860 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
5861 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
5862 result = WERR_ACCESS_DENIED;
5866 /* NT seems to like setting the security descriptor even though
5867 nothing may have actually changed. */
5868 result = winreg_get_printer_secdesc(p->mem_ctx,
5869 get_server_info_system(),
5873 if (!W_ERROR_IS_OK(result)) {
5874 DEBUG(2,("update_printer_sec: winreg_get_printer_secdesc() failed\n"));
5875 result = WERR_BADFID;
5879 if (DEBUGLEVEL >= 10) {
5880 struct security_acl *the_acl;
5883 the_acl = old_secdesc->dacl;
5884 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
5885 printer, the_acl->num_aces));
5887 for (i = 0; i < the_acl->num_aces; i++) {
5888 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5889 &the_acl->aces[i].trustee),
5890 the_acl->aces[i].access_mask));
5893 the_acl = secdesc_ctr->sd->dacl;
5896 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
5897 printer, the_acl->num_aces));
5899 for (i = 0; i < the_acl->num_aces; i++) {
5900 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5901 &the_acl->aces[i].trustee),
5902 the_acl->aces[i].access_mask));
5905 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
5909 new_secdesc = sec_desc_merge(p->mem_ctx, secdesc_ctr->sd, old_secdesc);
5910 if (new_secdesc == NULL) {
5911 result = WERR_NOMEM;
5915 if (security_descriptor_equal(new_secdesc, old_secdesc)) {
5920 result = winreg_set_printer_secdesc(p->mem_ctx,
5921 get_server_info_system(),
5930 /********************************************************************
5931 Canonicalize printer info from a client
5932 ********************************************************************/
5934 static bool check_printer_ok(TALLOC_CTX *mem_ctx,
5935 struct spoolss_SetPrinterInfo2 *info2,
5938 fstring printername;
5941 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
5942 "portname=%s drivername=%s comment=%s location=%s\n",
5943 info2->servername, info2->printername, info2->sharename,
5944 info2->portname, info2->drivername, info2->comment,
5947 /* we force some elements to "correct" values */
5948 info2->servername = talloc_asprintf(mem_ctx, "\\\\%s", global_myname());
5949 if (info2->servername == NULL) {
5952 info2->sharename = talloc_strdup(mem_ctx, lp_const_servicename(snum));
5953 if (info2->sharename == NULL) {
5957 /* check to see if we allow printername != sharename */
5958 if (lp_force_printername(snum)) {
5959 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5960 global_myname(), info2->sharename);
5962 /* make sure printername is in \\server\printername format */
5963 fstrcpy(printername, info2->printername);
5965 if ( printername[0] == '\\' && printername[1] == '\\' ) {
5966 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
5970 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5971 global_myname(), p);
5973 if (info2->printername == NULL) {
5977 info2->attributes |= PRINTER_ATTRIBUTE_SAMBA;
5978 info2->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
5983 /****************************************************************************
5984 ****************************************************************************/
5986 static WERROR add_port_hook(TALLOC_CTX *ctx, struct security_token *token, const char *portname, const char *uri)
5988 char *cmd = lp_addport_cmd();
5989 char *command = NULL;
5991 bool is_print_op = false;
5994 return WERR_ACCESS_DENIED;
5997 command = talloc_asprintf(ctx,
5998 "%s \"%s\" \"%s\"", cmd, portname, uri );
6004 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
6006 DEBUG(10,("Running [%s]\n", command));
6008 /********* BEGIN SePrintOperatorPrivilege **********/
6013 ret = smbrun(command, NULL);
6018 /********* END SePrintOperatorPrivilege **********/
6020 DEBUGADD(10,("returned [%d]\n", ret));
6022 TALLOC_FREE(command);
6025 return WERR_ACCESS_DENIED;
6031 /****************************************************************************
6032 ****************************************************************************/
6034 static bool add_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
6035 struct spoolss_SetPrinterInfo2 *info2,
6036 const char *remote_machine,
6037 struct messaging_context *msg_ctx)
6039 char *cmd = lp_addprinter_cmd();
6041 char *command = NULL;
6045 bool is_print_op = false;
6047 if (!remote_machine) {
6051 command = talloc_asprintf(ctx,
6052 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
6053 cmd, info2->printername, info2->sharename,
6054 info2->portname, info2->drivername,
6055 info2->location, info2->comment, remote_machine);
6061 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
6063 DEBUG(10,("Running [%s]\n", command));
6065 /********* BEGIN SePrintOperatorPrivilege **********/
6070 if ( (ret = smbrun(command, &fd)) == 0 ) {
6071 /* Tell everyone we updated smb.conf. */
6072 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
6078 /********* END SePrintOperatorPrivilege **********/
6080 DEBUGADD(10,("returned [%d]\n", ret));
6082 TALLOC_FREE(command);
6090 /* reload our services immediately */
6092 reload_services(msg_ctx, -1, false);
6096 /* Get lines and convert them back to dos-codepage */
6097 qlines = fd_lines_load(fd, &numlines, 0, NULL);
6098 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
6101 /* Set the portname to what the script says the portname should be. */
6102 /* but don't require anything to be return from the script exit a good error code */
6105 /* Set the portname to what the script says the portname should be. */
6106 info2->portname = talloc_strdup(ctx, qlines[0]);
6107 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
6110 TALLOC_FREE(qlines);
6114 static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
6115 const struct auth_serversupplied_info *server_info,
6116 struct messaging_context *msg_ctx,
6118 struct spoolss_SetPrinterInfo2 *printer,
6119 struct spoolss_PrinterInfo2 *old_printer)
6121 bool force_update = (old_printer == NULL);
6122 const char *dnsdomname;
6123 const char *longname;
6124 const char *uncname;
6125 const char *spooling;
6127 WERROR result = WERR_OK;
6129 if (force_update || !strequal(printer->drivername, old_printer->drivername)) {
6130 push_reg_sz(mem_ctx, &buffer, printer->drivername);
6131 winreg_set_printer_dataex(mem_ctx,
6135 SPOOL_DSSPOOLER_KEY,
6136 SPOOL_REG_DRIVERNAME,
6141 if (!force_update) {
6142 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
6143 printer->drivername));
6145 notify_printer_driver(server_event_context(), msg_ctx,
6146 snum, printer->drivername ?
6147 printer->drivername : "");
6151 if (force_update || !strequal(printer->comment, old_printer->comment)) {
6152 push_reg_sz(mem_ctx, &buffer, printer->comment);
6153 winreg_set_printer_dataex(mem_ctx,
6157 SPOOL_DSSPOOLER_KEY,
6158 SPOOL_REG_DESCRIPTION,
6163 if (!force_update) {
6164 notify_printer_comment(server_event_context(), msg_ctx,
6165 snum, printer->comment ?
6166 printer->comment : "");
6170 if (force_update || !strequal(printer->sharename, old_printer->sharename)) {
6171 push_reg_sz(mem_ctx, &buffer, printer->sharename);
6172 winreg_set_printer_dataex(mem_ctx,
6176 SPOOL_DSSPOOLER_KEY,
6177 SPOOL_REG_PRINTSHARENAME,
6182 if (!force_update) {
6183 notify_printer_sharename(server_event_context(),
6185 snum, printer->sharename ?
6186 printer->sharename : "");
6190 if (force_update || !strequal(printer->printername, old_printer->printername)) {
6193 p = strrchr(printer->printername, '\\' );
6197 p = printer->printername;
6200 push_reg_sz(mem_ctx, &buffer, p);
6201 winreg_set_printer_dataex(mem_ctx,
6205 SPOOL_DSSPOOLER_KEY,
6206 SPOOL_REG_PRINTERNAME,
6211 if (!force_update) {
6212 notify_printer_printername(server_event_context(),
6213 msg_ctx, snum, p ? p : "");
6217 if (force_update || !strequal(printer->portname, old_printer->portname)) {
6218 push_reg_sz(mem_ctx, &buffer, printer->portname);
6219 winreg_set_printer_dataex(mem_ctx,
6223 SPOOL_DSSPOOLER_KEY,
6229 if (!force_update) {
6230 notify_printer_port(server_event_context(),
6231 msg_ctx, snum, printer->portname ?
6232 printer->portname : "");
6236 if (force_update || !strequal(printer->location, old_printer->location)) {
6237 push_reg_sz(mem_ctx, &buffer, printer->location);
6238 winreg_set_printer_dataex(mem_ctx,
6242 SPOOL_DSSPOOLER_KEY,
6248 if (!force_update) {
6249 notify_printer_location(server_event_context(),
6252 printer->location : "");
6256 if (force_update || !strequal(printer->sepfile, old_printer->sepfile)) {
6257 push_reg_sz(mem_ctx, &buffer, printer->sepfile);
6258 winreg_set_printer_dataex(mem_ctx,
6262 SPOOL_DSSPOOLER_KEY,
6263 SPOOL_REG_PRINTSEPARATORFILE,
6268 if (!force_update) {
6269 notify_printer_sepfile(server_event_context(),
6272 printer->sepfile : "");
6276 if (force_update || printer->starttime != old_printer->starttime) {
6277 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6278 SIVAL(buffer.data, 0, printer->starttime);
6279 winreg_set_printer_dataex(mem_ctx,
6283 SPOOL_DSSPOOLER_KEY,
6284 SPOOL_REG_PRINTSTARTTIME,
6290 if (force_update || printer->untiltime != old_printer->untiltime) {
6291 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6292 SIVAL(buffer.data, 0, printer->untiltime);
6293 winreg_set_printer_dataex(mem_ctx,
6297 SPOOL_DSSPOOLER_KEY,
6298 SPOOL_REG_PRINTENDTIME,
6304 if (force_update || printer->priority != old_printer->priority) {
6305 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6306 SIVAL(buffer.data, 0, printer->priority);
6307 winreg_set_printer_dataex(mem_ctx,
6311 SPOOL_DSSPOOLER_KEY,
6318 if (force_update || printer->attributes != old_printer->attributes) {
6319 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6320 SIVAL(buffer.data, 0, (printer->attributes &
6321 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS));
6322 winreg_set_printer_dataex(mem_ctx,
6326 SPOOL_DSSPOOLER_KEY,
6327 SPOOL_REG_PRINTKEEPPRINTEDJOBS,
6332 switch (printer->attributes & 0x3) {
6334 spooling = SPOOL_REGVAL_PRINTWHILESPOOLING;
6337 spooling = SPOOL_REGVAL_PRINTAFTERSPOOLED;
6340 spooling = SPOOL_REGVAL_PRINTDIRECT;
6343 spooling = "unknown";
6345 push_reg_sz(mem_ctx, &buffer, spooling);
6346 winreg_set_printer_dataex(mem_ctx,
6350 SPOOL_DSSPOOLER_KEY,
6351 SPOOL_REG_PRINTSPOOLING,
6357 push_reg_sz(mem_ctx, &buffer, global_myname());
6358 winreg_set_printer_dataex(mem_ctx,
6362 SPOOL_DSSPOOLER_KEY,
6363 SPOOL_REG_SHORTSERVERNAME,
6368 dnsdomname = get_mydnsfullname();
6369 if (dnsdomname != NULL && dnsdomname[0] != '\0') {
6370 longname = talloc_strdup(mem_ctx, dnsdomname);
6372 longname = talloc_strdup(mem_ctx, global_myname());
6374 if (longname == NULL) {
6375 result = WERR_NOMEM;
6379 push_reg_sz(mem_ctx, &buffer, longname);
6380 winreg_set_printer_dataex(mem_ctx,
6384 SPOOL_DSSPOOLER_KEY,
6385 SPOOL_REG_SERVERNAME,
6390 uncname = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
6391 global_myname(), printer->sharename);
6392 push_reg_sz(mem_ctx, &buffer, uncname);
6393 winreg_set_printer_dataex(mem_ctx,
6397 SPOOL_DSSPOOLER_KEY,
6407 /********************************************************************
6408 * Called by spoolss_api_setprinter
6409 * when updating a printer description.
6410 ********************************************************************/
6412 static WERROR update_printer(struct pipes_struct *p,
6413 struct policy_handle *handle,
6414 struct spoolss_SetPrinterInfoCtr *info_ctr,
6415 struct spoolss_DeviceMode *devmode)
6417 uint32_t printer_mask = SPOOLSS_PRINTER_INFO_ALL;
6418 struct spoolss_SetPrinterInfo2 *printer = info_ctr->info.info2;
6419 struct spoolss_PrinterInfo2 *old_printer;
6420 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6422 WERROR result = WERR_OK;
6423 TALLOC_CTX *tmp_ctx;
6425 DEBUG(8,("update_printer\n"));
6427 tmp_ctx = talloc_new(p->mem_ctx);
6428 if (tmp_ctx == NULL) {
6433 result = WERR_BADFID;
6437 if (!get_printer_snum(p, handle, &snum, NULL)) {
6438 result = WERR_BADFID;
6442 result = winreg_get_printer(tmp_ctx,
6443 get_server_info_system(),
6445 lp_const_servicename(snum),
6447 if (!W_ERROR_IS_OK(result)) {
6448 result = WERR_BADFID;
6452 /* Do sanity check on the requested changes for Samba */
6453 if (!check_printer_ok(tmp_ctx, printer, snum)) {
6454 result = WERR_INVALID_PARAM;
6458 /* FIXME!!! If the driver has changed we really should verify that
6459 it is installed before doing much else --jerry */
6461 /* Check calling user has permission to update printer description */
6462 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6463 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6464 result = WERR_ACCESS_DENIED;
6468 /* Call addprinter hook */
6469 /* Check changes to see if this is really needed */
6471 if (*lp_addprinter_cmd() &&
6472 (!strequal(printer->drivername, old_printer->drivername) ||
6473 !strequal(printer->comment, old_printer->comment) ||
6474 !strequal(printer->portname, old_printer->portname) ||
6475 !strequal(printer->location, old_printer->location)) )
6477 /* add_printer_hook() will call reload_services() */
6478 if (!add_printer_hook(tmp_ctx, p->server_info->ptok,
6479 printer, p->client_id->addr,
6481 result = WERR_ACCESS_DENIED;
6486 update_dsspooler(tmp_ctx,
6487 get_server_info_system(),
6493 printer_mask &= ~SPOOLSS_PRINTER_INFO_SECDESC;
6495 if (devmode == NULL) {
6496 printer_mask &= ~SPOOLSS_PRINTER_INFO_DEVMODE;
6498 result = winreg_update_printer(tmp_ctx,
6499 get_server_info_system(),
6508 talloc_free(tmp_ctx);
6513 /****************************************************************************
6514 ****************************************************************************/
6515 static WERROR publish_or_unpublish_printer(struct pipes_struct *p,
6516 struct policy_handle *handle,
6517 struct spoolss_SetPrinterInfo7 *info7)
6520 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6523 struct printer_handle *Printer;
6525 if ( lp_security() != SEC_ADS ) {
6526 return WERR_UNKNOWN_LEVEL;
6529 Printer = find_printer_index_by_hnd(p, handle);
6531 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
6536 if (!get_printer_snum(p, handle, &snum, NULL))
6539 result = winreg_get_printer(p->mem_ctx,
6540 get_server_info_system(),
6542 lp_servicename(snum),
6544 if (!W_ERROR_IS_OK(result)) {
6548 nt_printer_publish(pinfo2,
6549 get_server_info_system(),
6554 TALLOC_FREE(pinfo2);
6557 return WERR_UNKNOWN_LEVEL;
6561 /********************************************************************
6562 ********************************************************************/
6564 static WERROR update_printer_devmode(struct pipes_struct *p,
6565 struct policy_handle *handle,
6566 struct spoolss_DeviceMode *devmode)
6569 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6570 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_DEVMODE;
6572 DEBUG(8,("update_printer_devmode\n"));
6578 if (!get_printer_snum(p, handle, &snum, NULL)) {
6582 /* Check calling user has permission to update printer description */
6583 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6584 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6585 return WERR_ACCESS_DENIED;
6588 return winreg_update_printer(p->mem_ctx,
6589 get_server_info_system(),
6591 lp_const_servicename(snum),
6599 /****************************************************************
6601 ****************************************************************/
6603 WERROR _spoolss_SetPrinter(struct pipes_struct *p,
6604 struct spoolss_SetPrinter *r)
6608 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
6611 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6612 OUR_HANDLE(r->in.handle)));
6616 /* check the level */
6617 switch (r->in.info_ctr->level) {
6619 return control_printer(r->in.handle, r->in.command, p);
6621 result = update_printer(p, r->in.handle,
6623 r->in.devmode_ctr->devmode);
6624 if (!W_ERROR_IS_OK(result))
6626 if (r->in.secdesc_ctr->sd)
6627 result = update_printer_sec(r->in.handle, p,
6631 return update_printer_sec(r->in.handle, p,
6634 return publish_or_unpublish_printer(p, r->in.handle,
6635 r->in.info_ctr->info.info7);
6637 return update_printer_devmode(p, r->in.handle,
6638 r->in.devmode_ctr->devmode);
6640 return WERR_UNKNOWN_LEVEL;
6644 /****************************************************************
6645 _spoolss_FindClosePrinterNotify
6646 ****************************************************************/
6648 WERROR _spoolss_FindClosePrinterNotify(struct pipes_struct *p,
6649 struct spoolss_FindClosePrinterNotify *r)
6651 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
6654 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6655 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r->in.handle)));
6659 if (Printer->notify.cli_chan != NULL &&
6660 Printer->notify.cli_chan->active_connections > 0) {
6663 if (Printer->printer_type == SPLHND_PRINTER) {
6664 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6669 srv_spoolss_replycloseprinter(snum, Printer);
6672 Printer->notify.flags=0;
6673 Printer->notify.options=0;
6674 Printer->notify.localmachine[0]='\0';
6675 Printer->notify.printerlocal=0;
6676 TALLOC_FREE(Printer->notify.option);
6681 /****************************************************************
6683 ****************************************************************/
6685 WERROR _spoolss_AddJob(struct pipes_struct *p,
6686 struct spoolss_AddJob *r)
6688 if (!r->in.buffer && (r->in.offered != 0)) {
6689 return WERR_INVALID_PARAM;
6692 /* this is what a NT server returns for AddJob. AddJob must fail on
6693 * non-local printers */
6695 if (r->in.level != 1) {
6696 return WERR_UNKNOWN_LEVEL;
6699 return WERR_INVALID_PARAM;
6702 /****************************************************************************
6704 ****************************************************************************/
6706 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
6707 struct spoolss_JobInfo1 *r,
6708 const print_queue_struct *queue,
6709 int position, int snum,
6710 struct spoolss_PrinterInfo2 *pinfo2)
6714 t = gmtime(&queue->time);
6716 r->job_id = queue->job;
6718 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6719 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6720 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6721 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6722 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6723 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6724 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6725 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6726 r->data_type = talloc_strdup(mem_ctx, "RAW");
6727 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6728 r->text_status = talloc_strdup(mem_ctx, "");
6729 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6731 r->status = nt_printj_status(queue->status);
6732 r->priority = queue->priority;
6733 r->position = position;
6734 r->total_pages = queue->page_count;
6735 r->pages_printed = 0; /* ??? */
6737 init_systemtime(&r->submitted, t);
6742 /****************************************************************************
6744 ****************************************************************************/
6746 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
6747 struct spoolss_JobInfo2 *r,
6748 const print_queue_struct *queue,
6749 int position, int snum,
6750 struct spoolss_PrinterInfo2 *pinfo2,
6751 struct spoolss_DeviceMode *devmode)
6755 t = gmtime(&queue->time);
6757 r->job_id = queue->job;
6759 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6760 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6761 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6762 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6763 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6764 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6765 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6766 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6767 r->notify_name = talloc_strdup(mem_ctx, queue->fs_user);
6768 W_ERROR_HAVE_NO_MEMORY(r->notify_name);
6769 r->data_type = talloc_strdup(mem_ctx, "RAW");
6770 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6771 r->print_processor = talloc_strdup(mem_ctx, "winprint");
6772 W_ERROR_HAVE_NO_MEMORY(r->print_processor);
6773 r->parameters = talloc_strdup(mem_ctx, "");
6774 W_ERROR_HAVE_NO_MEMORY(r->parameters);
6775 r->driver_name = talloc_strdup(mem_ctx, pinfo2->drivername);
6776 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
6778 r->devmode = devmode;
6780 r->text_status = talloc_strdup(mem_ctx, "");
6781 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6785 r->status = nt_printj_status(queue->status);
6786 r->priority = queue->priority;
6787 r->position = position;
6790 r->total_pages = queue->page_count;
6791 r->size = queue->size;
6792 init_systemtime(&r->submitted, t);
6794 r->pages_printed = 0; /* ??? */
6799 /****************************************************************************
6801 ****************************************************************************/
6803 static WERROR fill_job_info3(TALLOC_CTX *mem_ctx,
6804 struct spoolss_JobInfo3 *r,
6805 const print_queue_struct *queue,
6806 const print_queue_struct *next_queue,
6807 int position, int snum,
6808 struct spoolss_PrinterInfo2 *pinfo2)
6810 r->job_id = queue->job;
6813 r->next_job_id = next_queue->job;
6820 /****************************************************************************
6821 Enumjobs at level 1.
6822 ****************************************************************************/
6824 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
6825 const print_queue_struct *queue,
6826 uint32_t num_queues, int snum,
6827 struct spoolss_PrinterInfo2 *pinfo2,
6828 union spoolss_JobInfo **info_p,
6831 union spoolss_JobInfo *info;
6833 WERROR result = WERR_OK;
6835 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6836 W_ERROR_HAVE_NO_MEMORY(info);
6838 *count = num_queues;
6840 for (i=0; i<*count; i++) {
6841 result = fill_job_info1(info,
6847 if (!W_ERROR_IS_OK(result)) {
6853 if (!W_ERROR_IS_OK(result)) {
6864 /****************************************************************************
6865 Enumjobs at level 2.
6866 ****************************************************************************/
6868 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
6869 const print_queue_struct *queue,
6870 uint32_t num_queues, int snum,
6871 struct spoolss_PrinterInfo2 *pinfo2,
6872 union spoolss_JobInfo **info_p,
6875 union spoolss_JobInfo *info;
6877 WERROR result = WERR_OK;
6879 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6880 W_ERROR_HAVE_NO_MEMORY(info);
6882 *count = num_queues;
6884 for (i=0; i<*count; i++) {
6885 struct spoolss_DeviceMode *devmode;
6887 result = spoolss_create_default_devmode(info,
6888 pinfo2->printername,
6890 if (!W_ERROR_IS_OK(result)) {
6891 DEBUG(3, ("Can't proceed w/o a devmode!"));
6895 result = fill_job_info2(info,
6902 if (!W_ERROR_IS_OK(result)) {
6908 if (!W_ERROR_IS_OK(result)) {
6919 /****************************************************************************
6920 Enumjobs at level 3.
6921 ****************************************************************************/
6923 static WERROR enumjobs_level3(TALLOC_CTX *mem_ctx,
6924 const print_queue_struct *queue,
6925 uint32_t num_queues, int snum,
6926 struct spoolss_PrinterInfo2 *pinfo2,
6927 union spoolss_JobInfo **info_p,
6930 union spoolss_JobInfo *info;
6932 WERROR result = WERR_OK;
6934 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6935 W_ERROR_HAVE_NO_MEMORY(info);
6937 *count = num_queues;
6939 for (i=0; i<*count; i++) {
6940 const print_queue_struct *next_queue = NULL;
6943 next_queue = &queue[i+1];
6946 result = fill_job_info3(info,
6953 if (!W_ERROR_IS_OK(result)) {
6959 if (!W_ERROR_IS_OK(result)) {
6970 /****************************************************************
6972 ****************************************************************/
6974 WERROR _spoolss_EnumJobs(struct pipes_struct *p,
6975 struct spoolss_EnumJobs *r)
6978 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6980 print_status_struct prt_status;
6981 print_queue_struct *queue = NULL;
6984 /* that's an [in out] buffer */
6986 if (!r->in.buffer && (r->in.offered != 0)) {
6987 return WERR_INVALID_PARAM;
6990 DEBUG(4,("_spoolss_EnumJobs\n"));
6994 *r->out.info = NULL;
6996 /* lookup the printer snum and tdb entry */
6998 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7002 result = winreg_get_printer(p->mem_ctx,
7003 get_server_info_system(),
7005 lp_const_servicename(snum),
7007 if (!W_ERROR_IS_OK(result)) {
7011 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
7012 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
7013 count, prt_status.status, prt_status.message));
7017 TALLOC_FREE(pinfo2);
7021 switch (r->in.level) {
7023 result = enumjobs_level1(p->mem_ctx, queue, count, snum,
7024 pinfo2, r->out.info, r->out.count);
7027 result = enumjobs_level2(p->mem_ctx, queue, count, snum,
7028 pinfo2, r->out.info, r->out.count);
7031 result = enumjobs_level3(p->mem_ctx, queue, count, snum,
7032 pinfo2, r->out.info, r->out.count);
7035 result = WERR_UNKNOWN_LEVEL;
7040 TALLOC_FREE(pinfo2);
7042 if (!W_ERROR_IS_OK(result)) {
7046 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7048 *r->out.info, r->in.level,
7050 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7051 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7053 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7056 /****************************************************************
7057 _spoolss_ScheduleJob
7058 ****************************************************************/
7060 WERROR _spoolss_ScheduleJob(struct pipes_struct *p,
7061 struct spoolss_ScheduleJob *r)
7066 /****************************************************************
7067 ****************************************************************/
7069 static WERROR spoolss_setjob_1(TALLOC_CTX *mem_ctx,
7070 struct messaging_context *msg_ctx,
7071 const char *printer_name,
7073 struct spoolss_SetJobInfo1 *r)
7077 if (!print_job_get_name(mem_ctx, printer_name, job_id, &old_doc_name)) {
7081 if (strequal(old_doc_name, r->document_name)) {
7085 if (!print_job_set_name(server_event_context(), msg_ctx,
7086 printer_name, job_id, r->document_name)) {
7093 /****************************************************************
7095 ****************************************************************/
7097 WERROR _spoolss_SetJob(struct pipes_struct *p,
7098 struct spoolss_SetJob *r)
7100 const struct auth_serversupplied_info *server_info = p->server_info;
7102 WERROR errcode = WERR_BADFUNC;
7104 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7108 if (!print_job_exists(lp_const_servicename(snum), r->in.job_id)) {
7109 return WERR_INVALID_PRINTER_NAME;
7112 switch (r->in.command) {
7113 case SPOOLSS_JOB_CONTROL_CANCEL:
7114 case SPOOLSS_JOB_CONTROL_DELETE:
7115 errcode = print_job_delete(server_info, p->msg_ctx,
7116 snum, r->in.job_id);
7117 if (W_ERROR_EQUAL(errcode, WERR_PRINTER_HAS_JOBS_QUEUED)) {
7121 case SPOOLSS_JOB_CONTROL_PAUSE:
7122 if (print_job_pause(server_info, p->msg_ctx,
7123 snum, r->in.job_id, &errcode)) {
7127 case SPOOLSS_JOB_CONTROL_RESTART:
7128 case SPOOLSS_JOB_CONTROL_RESUME:
7129 if (print_job_resume(server_info, p->msg_ctx,
7130 snum, r->in.job_id, &errcode)) {
7138 return WERR_UNKNOWN_LEVEL;
7141 if (!W_ERROR_IS_OK(errcode)) {
7145 if (r->in.ctr == NULL) {
7149 switch (r->in.ctr->level) {
7151 errcode = spoolss_setjob_1(p->mem_ctx, p->msg_ctx,
7152 lp_const_servicename(snum),
7154 r->in.ctr->info.info1);
7160 return WERR_UNKNOWN_LEVEL;
7166 /****************************************************************************
7167 Enumerates all printer drivers by level and architecture.
7168 ****************************************************************************/
7170 static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
7171 const struct auth_serversupplied_info *server_info,
7172 struct messaging_context *msg_ctx,
7173 const char *servername,
7174 const char *architecture,
7176 union spoolss_DriverInfo **info_p,
7181 struct spoolss_DriverInfo8 *driver;
7182 union spoolss_DriverInfo *info = NULL;
7184 WERROR result = WERR_OK;
7185 uint32_t num_drivers;
7186 const char **drivers;
7191 for (version=0; version<DRIVER_MAX_VERSION; version++) {
7192 result = winreg_get_driver_list(mem_ctx, server_info, msg_ctx,
7193 architecture, version,
7194 &num_drivers, &drivers);
7195 if (!W_ERROR_IS_OK(result)) {
7198 DEBUG(4, ("we have:[%d] drivers in environment"
7199 " [%s] and version [%d]\n",
7200 num_drivers, architecture, version));
7202 if (num_drivers != 0) {
7203 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
7204 union spoolss_DriverInfo,
7205 count + num_drivers);
7207 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
7208 "failed to enlarge driver info buffer!\n"));
7209 result = WERR_NOMEM;
7214 for (i = 0; i < num_drivers; i++) {
7215 DEBUG(5, ("\tdriver: [%s]\n", drivers[i]));
7217 result = winreg_get_driver(mem_ctx, server_info,
7219 architecture, drivers[i],
7221 if (!W_ERROR_IS_OK(result)) {
7227 result = fill_printer_driver_info1(info, &info[count+i].info1,
7228 driver, servername);
7231 result = fill_printer_driver_info2(info, &info[count+i].info2,
7232 driver, servername);
7235 result = fill_printer_driver_info3(info, &info[count+i].info3,
7236 driver, servername);
7239 result = fill_printer_driver_info4(info, &info[count+i].info4,
7240 driver, servername);
7243 result = fill_printer_driver_info5(info, &info[count+i].info5,
7244 driver, servername);
7247 result = fill_printer_driver_info6(info, &info[count+i].info6,
7248 driver, servername);
7251 result = fill_printer_driver_info8(info, &info[count+i].info8,
7252 driver, servername);
7255 result = WERR_UNKNOWN_LEVEL;
7259 TALLOC_FREE(driver);
7261 if (!W_ERROR_IS_OK(result)) {
7266 count += num_drivers;
7267 TALLOC_FREE(drivers);
7271 TALLOC_FREE(drivers);
7273 if (!W_ERROR_IS_OK(result)) {
7284 /****************************************************************************
7285 Enumerates all printer drivers by level.
7286 ****************************************************************************/
7288 static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
7289 const struct auth_serversupplied_info *server_info,
7290 struct messaging_context *msg_ctx,
7291 const char *servername,
7292 const char *architecture,
7294 union spoolss_DriverInfo **info_p,
7298 WERROR result = WERR_OK;
7300 if (strequal(architecture, SPOOLSS_ARCHITECTURE_ALL)) {
7302 for (a=0; archi_table[a].long_archi != NULL; a++) {
7304 union spoolss_DriverInfo *info = NULL;
7307 result = enumprinterdrivers_level_by_architecture(mem_ctx,
7311 archi_table[a].long_archi,
7315 if (!W_ERROR_IS_OK(result)) {
7319 for (i=0; i < count; i++) {
7320 ADD_TO_ARRAY(mem_ctx, union spoolss_DriverInfo,
7321 info[i], info_p, count_p);
7328 return enumprinterdrivers_level_by_architecture(mem_ctx,
7338 /****************************************************************
7339 _spoolss_EnumPrinterDrivers
7340 ****************************************************************/
7342 WERROR _spoolss_EnumPrinterDrivers(struct pipes_struct *p,
7343 struct spoolss_EnumPrinterDrivers *r)
7345 const char *cservername;
7348 /* that's an [in out] buffer */
7350 if (!r->in.buffer && (r->in.offered != 0)) {
7351 return WERR_INVALID_PARAM;
7354 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
7358 *r->out.info = NULL;
7360 cservername = canon_servername(r->in.server);
7362 if (!is_myname_or_ipaddr(cservername)) {
7363 return WERR_UNKNOWN_PRINTER_DRIVER;
7366 result = enumprinterdrivers_level(p->mem_ctx,
7367 get_server_info_system(),
7374 if (!W_ERROR_IS_OK(result)) {
7378 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7379 spoolss_EnumPrinterDrivers,
7380 *r->out.info, r->in.level,
7382 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7383 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7385 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7388 /****************************************************************
7390 ****************************************************************/
7392 WERROR _spoolss_EnumForms(struct pipes_struct *p,
7393 struct spoolss_EnumForms *r)
7399 *r->out.info = NULL;
7401 /* that's an [in out] buffer */
7403 if (!r->in.buffer && (r->in.offered != 0) ) {
7404 return WERR_INVALID_PARAM;
7407 DEBUG(4,("_spoolss_EnumForms\n"));
7408 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7409 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7411 switch (r->in.level) {
7413 result = winreg_printer_enumforms1(p->mem_ctx,
7414 get_server_info_system(),
7420 result = WERR_UNKNOWN_LEVEL;
7424 if (!W_ERROR_IS_OK(result)) {
7428 if (*r->out.count == 0) {
7429 return WERR_NO_MORE_ITEMS;
7432 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7434 *r->out.info, r->in.level,
7436 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7437 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7439 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7442 /****************************************************************
7444 ****************************************************************/
7446 WERROR _spoolss_GetForm(struct pipes_struct *p,
7447 struct spoolss_GetForm *r)
7451 /* that's an [in out] buffer */
7453 if (!r->in.buffer && (r->in.offered != 0)) {
7454 return WERR_INVALID_PARAM;
7457 DEBUG(4,("_spoolss_GetForm\n"));
7458 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7459 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7461 switch (r->in.level) {
7463 result = winreg_printer_getform1(p->mem_ctx,
7464 get_server_info_system(),
7467 &r->out.info->info1);
7470 result = WERR_UNKNOWN_LEVEL;
7474 if (!W_ERROR_IS_OK(result)) {
7475 TALLOC_FREE(r->out.info);
7479 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo,
7480 r->out.info, r->in.level);
7481 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7483 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7486 /****************************************************************************
7487 ****************************************************************************/
7489 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
7490 struct spoolss_PortInfo1 *r,
7493 r->port_name = talloc_strdup(mem_ctx, name);
7494 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7499 /****************************************************************************
7500 TODO: This probably needs distinguish between TCP/IP and Local ports
7502 ****************************************************************************/
7504 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
7505 struct spoolss_PortInfo2 *r,
7508 r->port_name = talloc_strdup(mem_ctx, name);
7509 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7511 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
7512 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
7514 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT);
7515 W_ERROR_HAVE_NO_MEMORY(r->description);
7517 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
7524 /****************************************************************************
7525 wrapper around the enumer ports command
7526 ****************************************************************************/
7528 static WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines)
7530 char *cmd = lp_enumports_cmd();
7531 char **qlines = NULL;
7532 char *command = NULL;
7540 /* if no hook then just fill in the default port */
7543 if (!(qlines = TALLOC_ARRAY( NULL, char*, 2 ))) {
7546 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
7547 TALLOC_FREE(qlines);
7554 /* we have a valid enumport command */
7556 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
7561 DEBUG(10,("Running [%s]\n", command));
7562 ret = smbrun(command, &fd);
7563 DEBUG(10,("Returned [%d]\n", ret));
7564 TALLOC_FREE(command);
7569 return WERR_ACCESS_DENIED;
7573 qlines = fd_lines_load(fd, &numlines, 0, NULL);
7574 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
7584 /****************************************************************************
7586 ****************************************************************************/
7588 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
7589 union spoolss_PortInfo **info_p,
7592 union spoolss_PortInfo *info = NULL;
7594 WERROR result = WERR_OK;
7595 char **qlines = NULL;
7598 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7599 if (!W_ERROR_IS_OK(result)) {
7604 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7606 DEBUG(10,("Returning WERR_NOMEM\n"));
7607 result = WERR_NOMEM;
7611 for (i=0; i<numlines; i++) {
7612 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7613 result = fill_port_1(info, &info[i].info1, qlines[i]);
7614 if (!W_ERROR_IS_OK(result)) {
7619 TALLOC_FREE(qlines);
7622 if (!W_ERROR_IS_OK(result)) {
7624 TALLOC_FREE(qlines);
7636 /****************************************************************************
7638 ****************************************************************************/
7640 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
7641 union spoolss_PortInfo **info_p,
7644 union spoolss_PortInfo *info = NULL;
7646 WERROR result = WERR_OK;
7647 char **qlines = NULL;
7650 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7651 if (!W_ERROR_IS_OK(result)) {
7656 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7658 DEBUG(10,("Returning WERR_NOMEM\n"));
7659 result = WERR_NOMEM;
7663 for (i=0; i<numlines; i++) {
7664 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7665 result = fill_port_2(info, &info[i].info2, qlines[i]);
7666 if (!W_ERROR_IS_OK(result)) {
7671 TALLOC_FREE(qlines);
7674 if (!W_ERROR_IS_OK(result)) {
7676 TALLOC_FREE(qlines);
7688 /****************************************************************
7690 ****************************************************************/
7692 WERROR _spoolss_EnumPorts(struct pipes_struct *p,
7693 struct spoolss_EnumPorts *r)
7697 /* that's an [in out] buffer */
7699 if (!r->in.buffer && (r->in.offered != 0)) {
7700 return WERR_INVALID_PARAM;
7703 DEBUG(4,("_spoolss_EnumPorts\n"));
7707 *r->out.info = NULL;
7709 switch (r->in.level) {
7711 result = enumports_level_1(p->mem_ctx, r->out.info,
7715 result = enumports_level_2(p->mem_ctx, r->out.info,
7719 return WERR_UNKNOWN_LEVEL;
7722 if (!W_ERROR_IS_OK(result)) {
7726 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7728 *r->out.info, r->in.level,
7730 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7731 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7733 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7736 /****************************************************************************
7737 ****************************************************************************/
7739 static WERROR spoolss_addprinterex_level_2(struct pipes_struct *p,
7741 struct spoolss_SetPrinterInfoCtr *info_ctr,
7742 struct spoolss_DeviceMode *devmode,
7743 struct security_descriptor *secdesc,
7744 struct spoolss_UserLevelCtr *user_ctr,
7745 struct policy_handle *handle)
7747 struct spoolss_SetPrinterInfo2 *info2 = info_ctr->info.info2;
7748 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_ALL;
7750 WERROR err = WERR_OK;
7752 /* samba does not have a concept of local, non-shared printers yet, so
7753 * make sure we always setup sharename - gd */
7754 if ((info2->sharename == NULL || info2->sharename[0] == '\0') &&
7755 (info2->printername != NULL && info2->printername[0] != '\0')) {
7756 DEBUG(5, ("spoolss_addprinterex_level_2: "
7757 "no sharename has been set, setting printername %s as sharename\n",
7758 info2->printername));
7759 info2->sharename = info2->printername;
7762 /* check to see if the printer already exists */
7763 if ((snum = print_queue_snum(info2->sharename)) != -1) {
7764 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7766 return WERR_PRINTER_ALREADY_EXISTS;
7769 if (!lp_force_printername(GLOBAL_SECTION_SNUM)) {
7770 if ((snum = print_queue_snum(info2->printername)) != -1) {
7771 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7772 info2->printername));
7773 return WERR_PRINTER_ALREADY_EXISTS;
7777 /* validate printer info struct */
7778 if (!info2->printername || strlen(info2->printername) == 0) {
7779 return WERR_INVALID_PRINTER_NAME;
7781 if (!info2->portname || strlen(info2->portname) == 0) {
7782 return WERR_UNKNOWN_PORT;
7784 if (!info2->drivername || strlen(info2->drivername) == 0) {
7785 return WERR_UNKNOWN_PRINTER_DRIVER;
7787 if (!info2->printprocessor || strlen(info2->printprocessor) == 0) {
7788 return WERR_UNKNOWN_PRINTPROCESSOR;
7791 /* FIXME!!! smbd should check to see if the driver is installed before
7792 trying to add a printer like this --jerry */
7794 if (*lp_addprinter_cmd() ) {
7795 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
7796 info2, p->client_id->addr,
7798 return WERR_ACCESS_DENIED;
7801 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no"
7802 "smb.conf parameter \"addprinter command\" is defined. This"
7803 "parameter must exist for this call to succeed\n",
7804 info2->sharename ));
7807 if ((snum = print_queue_snum(info2->sharename)) == -1) {
7808 return WERR_ACCESS_DENIED;
7811 /* you must be a printer admin to add a new printer */
7812 if (!print_access_check(p->server_info,
7815 PRINTER_ACCESS_ADMINISTER)) {
7816 return WERR_ACCESS_DENIED;
7820 * Do sanity check on the requested changes for Samba.
7823 if (!check_printer_ok(p->mem_ctx, info2, snum)) {
7824 return WERR_INVALID_PARAM;
7827 if (devmode == NULL) {
7828 info2_mask = ~SPOOLSS_PRINTER_INFO_DEVMODE;
7831 update_dsspooler(p->mem_ctx,
7832 get_server_info_system(),
7838 err = winreg_update_printer(p->mem_ctx,
7839 get_server_info_system(),
7846 if (!W_ERROR_IS_OK(err)) {
7850 if (!open_printer_hnd(p, handle, info2->printername, PRINTER_ACCESS_ADMINISTER)) {
7851 /* Handle open failed - remove addition. */
7852 ZERO_STRUCTP(handle);
7853 return WERR_ACCESS_DENIED;
7859 /****************************************************************
7860 _spoolss_AddPrinterEx
7861 ****************************************************************/
7863 WERROR _spoolss_AddPrinterEx(struct pipes_struct *p,
7864 struct spoolss_AddPrinterEx *r)
7866 switch (r->in.info_ctr->level) {
7868 /* we don't handle yet */
7869 /* but I know what to do ... */
7870 return WERR_UNKNOWN_LEVEL;
7872 return spoolss_addprinterex_level_2(p, r->in.server,
7874 r->in.devmode_ctr->devmode,
7875 r->in.secdesc_ctr->sd,
7876 r->in.userlevel_ctr,
7879 return WERR_UNKNOWN_LEVEL;
7883 /****************************************************************
7885 ****************************************************************/
7887 WERROR _spoolss_AddPrinter(struct pipes_struct *p,
7888 struct spoolss_AddPrinter *r)
7890 struct spoolss_AddPrinterEx a;
7891 struct spoolss_UserLevelCtr userlevel_ctr;
7893 ZERO_STRUCT(userlevel_ctr);
7895 userlevel_ctr.level = 1;
7897 a.in.server = r->in.server;
7898 a.in.info_ctr = r->in.info_ctr;
7899 a.in.devmode_ctr = r->in.devmode_ctr;
7900 a.in.secdesc_ctr = r->in.secdesc_ctr;
7901 a.in.userlevel_ctr = &userlevel_ctr;
7902 a.out.handle = r->out.handle;
7904 return _spoolss_AddPrinterEx(p, &a);
7907 /****************************************************************
7908 _spoolss_AddPrinterDriverEx
7909 ****************************************************************/
7911 WERROR _spoolss_AddPrinterDriverEx(struct pipes_struct *p,
7912 struct spoolss_AddPrinterDriverEx *r)
7914 WERROR err = WERR_OK;
7915 const char *driver_name = NULL;
7920 case NDR_SPOOLSS_ADDPRINTERDRIVER:
7921 fn = "_spoolss_AddPrinterDriver";
7923 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
7924 fn = "_spoolss_AddPrinterDriverEx";
7927 return WERR_INVALID_PARAM;
7931 * we only support the semantics of AddPrinterDriver()
7932 * i.e. only copy files that are newer than existing ones
7935 if (r->in.flags == 0) {
7936 return WERR_INVALID_PARAM;
7939 if (r->in.flags != APD_COPY_NEW_FILES) {
7940 return WERR_ACCESS_DENIED;
7944 if (r->in.info_ctr->level != 3 && r->in.info_ctr->level != 6) {
7945 /* Clever hack from Martin Zielinski <mz@seh.de>
7946 * to allow downgrade from level 8 (Vista).
7948 DEBUG(0,("%s: level %d not yet implemented\n", fn,
7949 r->in.info_ctr->level));
7950 return WERR_UNKNOWN_LEVEL;
7953 DEBUG(5,("Cleaning driver's information\n"));
7954 err = clean_up_driver_struct(p->mem_ctx, p, r->in.info_ctr);
7955 if (!W_ERROR_IS_OK(err))
7958 DEBUG(5,("Moving driver to final destination\n"));
7959 if( !W_ERROR_IS_OK(err = move_driver_to_download_area(p, r->in.info_ctr,
7964 err = winreg_add_driver(p->mem_ctx,
7965 get_server_info_system(),
7970 if (!W_ERROR_IS_OK(err)) {
7975 * I think this is where he DrvUpgradePrinter() hook would be
7976 * be called in a driver's interface DLL on a Windows NT 4.0/2k
7977 * server. Right now, we just need to send ourselves a message
7978 * to update each printer bound to this driver. --jerry
7981 if (!srv_spoolss_drv_upgrade_printer(driver_name, p->msg_ctx)) {
7982 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
7990 /****************************************************************
7991 _spoolss_AddPrinterDriver
7992 ****************************************************************/
7994 WERROR _spoolss_AddPrinterDriver(struct pipes_struct *p,
7995 struct spoolss_AddPrinterDriver *r)
7997 struct spoolss_AddPrinterDriverEx a;
7999 switch (r->in.info_ctr->level) {
8006 return WERR_UNKNOWN_LEVEL;
8009 a.in.servername = r->in.servername;
8010 a.in.info_ctr = r->in.info_ctr;
8011 a.in.flags = APD_COPY_NEW_FILES;
8013 return _spoolss_AddPrinterDriverEx(p, &a);
8016 /****************************************************************************
8017 ****************************************************************************/
8019 struct _spoolss_paths {
8025 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
8027 static const struct _spoolss_paths spoolss_paths[]= {
8028 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
8029 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
8032 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
8033 const char *servername,
8034 const char *environment,
8038 const char *pservername = NULL;
8039 const char *long_archi = SPOOLSS_ARCHITECTURE_NT_X86;
8040 const char *short_archi;
8044 /* environment may be empty */
8045 if (environment && strlen(environment)) {
8046 long_archi = environment;
8049 /* servername may be empty */
8050 if (servername && strlen(servername)) {
8051 pservername = canon_servername(servername);
8053 if (!is_myname_or_ipaddr(pservername)) {
8054 return WERR_INVALID_PARAM;
8058 if (!(short_archi = get_short_archi(long_archi))) {
8059 return WERR_INVALID_ENVIRONMENT;
8062 switch (component) {
8063 case SPOOLSS_PRTPROCS_PATH:
8064 case SPOOLSS_DRIVER_PATH:
8066 *path = talloc_asprintf(mem_ctx,
8069 spoolss_paths[component].share,
8072 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
8073 SPOOLSS_DEFAULT_SERVER_PATH,
8074 spoolss_paths[component].dir,
8079 return WERR_INVALID_PARAM;
8089 /****************************************************************************
8090 ****************************************************************************/
8092 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
8093 const char *servername,
8094 const char *environment,
8095 struct spoolss_DriverDirectoryInfo1 *r)
8100 werr = compose_spoolss_server_path(mem_ctx,
8103 SPOOLSS_DRIVER_PATH,
8105 if (!W_ERROR_IS_OK(werr)) {
8109 DEBUG(4,("printer driver directory: [%s]\n", path));
8111 r->directory_name = path;
8116 /****************************************************************
8117 _spoolss_GetPrinterDriverDirectory
8118 ****************************************************************/
8120 WERROR _spoolss_GetPrinterDriverDirectory(struct pipes_struct *p,
8121 struct spoolss_GetPrinterDriverDirectory *r)
8125 /* that's an [in out] buffer */
8127 if (!r->in.buffer && (r->in.offered != 0)) {
8128 return WERR_INVALID_PARAM;
8131 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
8136 /* r->in.level is ignored */
8138 werror = getprinterdriverdir_level_1(p->mem_ctx,
8141 &r->out.info->info1);
8142 if (!W_ERROR_IS_OK(werror)) {
8143 TALLOC_FREE(r->out.info);
8147 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo,
8148 r->out.info, r->in.level);
8149 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8151 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8154 /****************************************************************
8155 _spoolss_EnumPrinterData
8156 ****************************************************************/
8158 WERROR _spoolss_EnumPrinterData(struct pipes_struct *p,
8159 struct spoolss_EnumPrinterData *r)
8162 struct spoolss_EnumPrinterDataEx r2;
8164 struct spoolss_PrinterEnumValues *info, *val = NULL;
8167 r2.in.handle = r->in.handle;
8168 r2.in.key_name = "PrinterDriverData";
8170 r2.out.count = &count;
8171 r2.out.info = &info;
8172 r2.out.needed = &needed;
8174 result = _spoolss_EnumPrinterDataEx(p, &r2);
8175 if (W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
8176 r2.in.offered = needed;
8177 result = _spoolss_EnumPrinterDataEx(p, &r2);
8179 if (!W_ERROR_IS_OK(result)) {
8184 * The NT machine wants to know the biggest size of value and data
8186 * cf: MSDN EnumPrinterData remark section
8189 if (!r->in.value_offered && !r->in.data_offered) {
8190 uint32_t biggest_valuesize = 0;
8191 uint32_t biggest_datasize = 0;
8194 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
8196 for (i=0; i<count; i++) {
8198 name_length = strlen(info[i].value_name);
8199 if (strlen(info[i].value_name) > biggest_valuesize) {
8200 biggest_valuesize = name_length;
8203 if (info[i].data_length > biggest_datasize) {
8204 biggest_datasize = info[i].data_length;
8207 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
8211 /* the value is an UNICODE string but real_value_size is the length
8212 in bytes including the trailing 0 */
8214 *r->out.value_needed = 2 * (1 + biggest_valuesize);
8215 *r->out.data_needed = biggest_datasize;
8217 DEBUG(6,("final values: [%d], [%d]\n",
8218 *r->out.value_needed, *r->out.data_needed));
8223 if (r->in.enum_index < count) {
8224 val = &info[r->in.enum_index];
8228 /* out_value should default to "" or else NT4 has
8229 problems unmarshalling the response */
8231 if (r->in.value_offered) {
8232 *r->out.value_needed = 1;
8233 r->out.value_name = talloc_strdup(r, "");
8234 if (!r->out.value_name) {
8238 r->out.value_name = NULL;
8239 *r->out.value_needed = 0;
8242 /* the data is counted in bytes */
8244 *r->out.data_needed = r->in.data_offered;
8246 result = WERR_NO_MORE_ITEMS;
8250 * - counted in bytes in the request
8251 * - counted in UNICODE chars in the max reply
8252 * - counted in bytes in the real size
8254 * take a pause *before* coding not *during* coding
8258 if (r->in.value_offered) {
8259 r->out.value_name = talloc_strdup(r, val->value_name);
8260 if (!r->out.value_name) {
8263 *r->out.value_needed = val->value_name_len;
8265 r->out.value_name = NULL;
8266 *r->out.value_needed = 0;
8271 *r->out.type = val->type;
8273 /* data - counted in bytes */
8276 * See the section "Dynamically Typed Query Parameters"
8280 if (r->out.data && val->data && val->data->data &&
8281 val->data_length && r->in.data_offered) {
8282 memcpy(r->out.data, val->data->data,
8283 MIN(val->data_length,r->in.data_offered));
8286 *r->out.data_needed = val->data_length;
8294 /****************************************************************
8295 _spoolss_SetPrinterData
8296 ****************************************************************/
8298 WERROR _spoolss_SetPrinterData(struct pipes_struct *p,
8299 struct spoolss_SetPrinterData *r)
8301 struct spoolss_SetPrinterDataEx r2;
8303 r2.in.handle = r->in.handle;
8304 r2.in.key_name = "PrinterDriverData";
8305 r2.in.value_name = r->in.value_name;
8306 r2.in.type = r->in.type;
8307 r2.in.data = r->in.data;
8308 r2.in.offered = r->in.offered;
8310 return _spoolss_SetPrinterDataEx(p, &r2);
8313 /****************************************************************
8314 _spoolss_ResetPrinter
8315 ****************************************************************/
8317 WERROR _spoolss_ResetPrinter(struct pipes_struct *p,
8318 struct spoolss_ResetPrinter *r)
8320 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8323 DEBUG(5,("_spoolss_ResetPrinter\n"));
8326 * All we do is to check to see if the handle and queue is valid.
8327 * This call really doesn't mean anything to us because we only
8328 * support RAW printing. --jerry
8332 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
8333 OUR_HANDLE(r->in.handle)));
8337 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8341 /* blindly return success */
8345 /****************************************************************
8346 _spoolss_DeletePrinterData
8347 ****************************************************************/
8349 WERROR _spoolss_DeletePrinterData(struct pipes_struct *p,
8350 struct spoolss_DeletePrinterData *r)
8352 struct spoolss_DeletePrinterDataEx r2;
8354 r2.in.handle = r->in.handle;
8355 r2.in.key_name = "PrinterDriverData";
8356 r2.in.value_name = r->in.value_name;
8358 return _spoolss_DeletePrinterDataEx(p, &r2);
8361 /****************************************************************
8363 ****************************************************************/
8365 WERROR _spoolss_AddForm(struct pipes_struct *p,
8366 struct spoolss_AddForm *r)
8368 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8370 WERROR status = WERR_OK;
8372 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8374 DEBUG(5,("_spoolss_AddForm\n"));
8377 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
8378 OUR_HANDLE(r->in.handle)));
8382 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8383 and not a printer admin, then fail */
8385 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8386 !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR) &&
8387 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8388 p->server_info->info3->base.domain.string,
8390 p->server_info->ptok,
8391 lp_printer_admin(snum))) {
8392 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
8393 return WERR_ACCESS_DENIED;
8396 switch (form->flags) {
8397 case SPOOLSS_FORM_USER:
8398 case SPOOLSS_FORM_BUILTIN:
8399 case SPOOLSS_FORM_PRINTER:
8402 return WERR_INVALID_PARAM;
8405 status = winreg_printer_addform1(p->mem_ctx,
8406 get_server_info_system(),
8409 if (!W_ERROR_IS_OK(status)) {
8414 * ChangeID must always be set if this is a printer
8416 if (Printer->printer_type == SPLHND_PRINTER) {
8417 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8421 status = winreg_printer_update_changeid(p->mem_ctx,
8422 get_server_info_system(),
8424 lp_const_servicename(snum));
8425 if (!W_ERROR_IS_OK(status)) {
8433 /****************************************************************
8435 ****************************************************************/
8437 WERROR _spoolss_DeleteForm(struct pipes_struct *p,
8438 struct spoolss_DeleteForm *r)
8440 const char *form_name = r->in.form_name;
8441 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8443 WERROR status = WERR_OK;
8445 DEBUG(5,("_spoolss_DeleteForm\n"));
8448 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
8449 OUR_HANDLE(r->in.handle)));
8453 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8454 !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR) &&
8455 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8456 p->server_info->info3->base.domain.string,
8458 p->server_info->ptok,
8459 lp_printer_admin(snum))) {
8460 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
8461 return WERR_ACCESS_DENIED;
8464 status = winreg_printer_deleteform1(p->mem_ctx,
8465 get_server_info_system(),
8468 if (!W_ERROR_IS_OK(status)) {
8473 * ChangeID must always be set if this is a printer
8475 if (Printer->printer_type == SPLHND_PRINTER) {
8476 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8480 status = winreg_printer_update_changeid(p->mem_ctx,
8481 get_server_info_system(),
8483 lp_const_servicename(snum));
8484 if (!W_ERROR_IS_OK(status)) {
8492 /****************************************************************
8494 ****************************************************************/
8496 WERROR _spoolss_SetForm(struct pipes_struct *p,
8497 struct spoolss_SetForm *r)
8499 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8500 const char *form_name = r->in.form_name;
8502 WERROR status = WERR_OK;
8504 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8506 DEBUG(5,("_spoolss_SetForm\n"));
8509 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8510 OUR_HANDLE(r->in.handle)));
8514 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8515 and not a printer admin, then fail */
8517 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8518 !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR) &&
8519 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8520 p->server_info->info3->base.domain.string,
8522 p->server_info->ptok,
8523 lp_printer_admin(snum))) {
8524 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
8525 return WERR_ACCESS_DENIED;
8528 status = winreg_printer_setform1(p->mem_ctx,
8529 get_server_info_system(),
8533 if (!W_ERROR_IS_OK(status)) {
8538 * ChangeID must always be set if this is a printer
8540 if (Printer->printer_type == SPLHND_PRINTER) {
8541 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8545 status = winreg_printer_update_changeid(p->mem_ctx,
8546 get_server_info_system(),
8548 lp_const_servicename(snum));
8549 if (!W_ERROR_IS_OK(status)) {
8557 /****************************************************************************
8558 fill_print_processor1
8559 ****************************************************************************/
8561 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
8562 struct spoolss_PrintProcessorInfo1 *r,
8563 const char *print_processor_name)
8565 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
8566 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
8571 /****************************************************************************
8572 enumprintprocessors level 1.
8573 ****************************************************************************/
8575 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
8576 union spoolss_PrintProcessorInfo **info_p,
8579 union spoolss_PrintProcessorInfo *info;
8582 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcessorInfo, 1);
8583 W_ERROR_HAVE_NO_MEMORY(info);
8587 result = fill_print_processor1(info, &info[0].info1, "winprint");
8588 if (!W_ERROR_IS_OK(result)) {
8593 if (!W_ERROR_IS_OK(result)) {
8604 /****************************************************************
8605 _spoolss_EnumPrintProcessors
8606 ****************************************************************/
8608 WERROR _spoolss_EnumPrintProcessors(struct pipes_struct *p,
8609 struct spoolss_EnumPrintProcessors *r)
8613 /* that's an [in out] buffer */
8615 if (!r->in.buffer && (r->in.offered != 0)) {
8616 return WERR_INVALID_PARAM;
8619 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8622 * Enumerate the print processors ...
8624 * Just reply with "winprint", to keep NT happy
8625 * and I can use my nice printer checker.
8630 *r->out.info = NULL;
8632 if (!get_short_archi(r->in.environment)) {
8633 return WERR_INVALID_ENVIRONMENT;
8636 switch (r->in.level) {
8638 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
8642 return WERR_UNKNOWN_LEVEL;
8645 if (!W_ERROR_IS_OK(result)) {
8649 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8650 spoolss_EnumPrintProcessors,
8651 *r->out.info, r->in.level,
8653 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8654 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8656 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8659 /****************************************************************************
8660 fill_printprocdatatype1
8661 ****************************************************************************/
8663 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
8664 struct spoolss_PrintProcDataTypesInfo1 *r,
8665 const char *name_array)
8667 r->name_array = talloc_strdup(mem_ctx, name_array);
8668 W_ERROR_HAVE_NO_MEMORY(r->name_array);
8673 /****************************************************************************
8674 enumprintprocdatatypes level 1.
8675 ****************************************************************************/
8677 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
8678 union spoolss_PrintProcDataTypesInfo **info_p,
8682 union spoolss_PrintProcDataTypesInfo *info;
8684 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
8685 W_ERROR_HAVE_NO_MEMORY(info);
8689 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
8690 if (!W_ERROR_IS_OK(result)) {
8695 if (!W_ERROR_IS_OK(result)) {
8706 /****************************************************************
8707 _spoolss_EnumPrintProcDataTypes
8708 ****************************************************************/
8710 WERROR _spoolss_EnumPrintProcDataTypes(struct pipes_struct *p,
8711 struct spoolss_EnumPrintProcDataTypes *r)
8715 /* that's an [in out] buffer */
8717 if (!r->in.buffer && (r->in.offered != 0)) {
8718 return WERR_INVALID_PARAM;
8721 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
8725 *r->out.info = NULL;
8727 if (r->in.print_processor_name == NULL ||
8728 !strequal(r->in.print_processor_name, "winprint")) {
8729 return WERR_UNKNOWN_PRINTPROCESSOR;
8732 switch (r->in.level) {
8734 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
8738 return WERR_UNKNOWN_LEVEL;
8741 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8742 spoolss_EnumPrintProcDataTypes,
8743 *r->out.info, r->in.level,
8745 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8746 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8748 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8751 /****************************************************************************
8753 ****************************************************************************/
8755 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
8756 struct spoolss_MonitorInfo1 *r,
8757 const char *monitor_name)
8759 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8760 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8765 /****************************************************************************
8767 ****************************************************************************/
8769 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
8770 struct spoolss_MonitorInfo2 *r,
8771 const char *monitor_name,
8772 const char *environment,
8773 const char *dll_name)
8775 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8776 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8777 r->environment = talloc_strdup(mem_ctx, environment);
8778 W_ERROR_HAVE_NO_MEMORY(r->environment);
8779 r->dll_name = talloc_strdup(mem_ctx, dll_name);
8780 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
8785 /****************************************************************************
8786 enumprintmonitors level 1.
8787 ****************************************************************************/
8789 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
8790 union spoolss_MonitorInfo **info_p,
8793 union spoolss_MonitorInfo *info;
8794 WERROR result = WERR_OK;
8796 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8797 W_ERROR_HAVE_NO_MEMORY(info);
8801 result = fill_monitor_1(info, &info[0].info1,
8803 if (!W_ERROR_IS_OK(result)) {
8807 result = fill_monitor_1(info, &info[1].info1,
8809 if (!W_ERROR_IS_OK(result)) {
8814 if (!W_ERROR_IS_OK(result)) {
8825 /****************************************************************************
8826 enumprintmonitors level 2.
8827 ****************************************************************************/
8829 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
8830 union spoolss_MonitorInfo **info_p,
8833 union spoolss_MonitorInfo *info;
8834 WERROR result = WERR_OK;
8836 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8837 W_ERROR_HAVE_NO_MEMORY(info);
8841 result = fill_monitor_2(info, &info[0].info2,
8843 "Windows NT X86", /* FIXME */
8845 if (!W_ERROR_IS_OK(result)) {
8849 result = fill_monitor_2(info, &info[1].info2,
8851 "Windows NT X86", /* FIXME */
8853 if (!W_ERROR_IS_OK(result)) {
8858 if (!W_ERROR_IS_OK(result)) {
8869 /****************************************************************
8870 _spoolss_EnumMonitors
8871 ****************************************************************/
8873 WERROR _spoolss_EnumMonitors(struct pipes_struct *p,
8874 struct spoolss_EnumMonitors *r)
8878 /* that's an [in out] buffer */
8880 if (!r->in.buffer && (r->in.offered != 0)) {
8881 return WERR_INVALID_PARAM;
8884 DEBUG(5,("_spoolss_EnumMonitors\n"));
8887 * Enumerate the print monitors ...
8889 * Just reply with "Local Port", to keep NT happy
8890 * and I can use my nice printer checker.
8895 *r->out.info = NULL;
8897 switch (r->in.level) {
8899 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
8903 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
8907 return WERR_UNKNOWN_LEVEL;
8910 if (!W_ERROR_IS_OK(result)) {
8914 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8915 spoolss_EnumMonitors,
8916 *r->out.info, r->in.level,
8918 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8919 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8921 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8924 /****************************************************************************
8925 ****************************************************************************/
8927 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
8928 const print_queue_struct *queue,
8929 int count, int snum,
8930 struct spoolss_PrinterInfo2 *pinfo2,
8932 struct spoolss_JobInfo1 *r)
8937 for (i=0; i<count; i++) {
8938 if (queue[i].job == (int)jobid) {
8944 if (found == false) {
8945 /* NT treats not found as bad param... yet another bad choice */
8946 return WERR_INVALID_PARAM;
8949 return fill_job_info1(mem_ctx,
8957 /****************************************************************************
8958 ****************************************************************************/
8960 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
8961 const print_queue_struct *queue,
8962 int count, int snum,
8963 struct spoolss_PrinterInfo2 *pinfo2,
8965 struct spoolss_JobInfo2 *r)
8969 struct spoolss_DeviceMode *devmode;
8972 for (i=0; i<count; i++) {
8973 if (queue[i].job == (int)jobid) {
8979 if (found == false) {
8980 /* NT treats not found as bad param... yet another bad
8982 return WERR_INVALID_PARAM;
8986 * if the print job does not have a DEVMODE associated with it,
8987 * just use the one for the printer. A NULL devicemode is not
8988 * a failure condition
8991 devmode = print_job_devmode(lp_const_servicename(snum), jobid);
8993 result = spoolss_create_default_devmode(mem_ctx,
8994 pinfo2->printername,
8996 if (!W_ERROR_IS_OK(result)) {
8997 DEBUG(3, ("Can't proceed w/o a devmode!"));
9002 return fill_job_info2(mem_ctx,
9011 /****************************************************************
9013 ****************************************************************/
9015 WERROR _spoolss_GetJob(struct pipes_struct *p,
9016 struct spoolss_GetJob *r)
9018 WERROR result = WERR_OK;
9019 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
9022 print_queue_struct *queue = NULL;
9023 print_status_struct prt_status;
9025 /* that's an [in out] buffer */
9027 if (!r->in.buffer && (r->in.offered != 0)) {
9028 return WERR_INVALID_PARAM;
9031 DEBUG(5,("_spoolss_GetJob\n"));
9035 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9039 result = winreg_get_printer(p->mem_ctx,
9040 get_server_info_system(),
9042 lp_const_servicename(snum),
9044 if (!W_ERROR_IS_OK(result)) {
9048 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
9050 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
9051 count, prt_status.status, prt_status.message));
9053 switch (r->in.level) {
9055 result = getjob_level_1(p->mem_ctx,
9056 queue, count, snum, pinfo2,
9057 r->in.job_id, &r->out.info->info1);
9060 result = getjob_level_2(p->mem_ctx,
9061 queue, count, snum, pinfo2,
9062 r->in.job_id, &r->out.info->info2);
9065 result = WERR_UNKNOWN_LEVEL;
9070 TALLOC_FREE(pinfo2);
9072 if (!W_ERROR_IS_OK(result)) {
9073 TALLOC_FREE(r->out.info);
9077 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_JobInfo, r->out.info,
9079 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9081 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9084 /****************************************************************
9085 _spoolss_GetPrinterDataEx
9086 ****************************************************************/
9088 WERROR _spoolss_GetPrinterDataEx(struct pipes_struct *p,
9089 struct spoolss_GetPrinterDataEx *r)
9092 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9093 const char *printer;
9095 WERROR result = WERR_OK;
9097 enum winreg_Type val_type;
9102 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
9104 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
9105 r->in.key_name, r->in.value_name));
9107 /* in case of problem, return some default values */
9110 *r->out.type = REG_NONE;
9113 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9114 OUR_HANDLE(r->in.handle)));
9115 result = WERR_BADFID;
9119 /* Is the handle to a printer or to the server? */
9121 if (Printer->printer_type == SPLHND_SERVER) {
9123 union spoolss_PrinterData data;
9125 result = getprinterdata_printer_server(p->mem_ctx,
9129 if (!W_ERROR_IS_OK(result)) {
9133 result = push_spoolss_PrinterData(p->mem_ctx, &blob,
9134 *r->out.type, &data);
9135 if (!W_ERROR_IS_OK(result)) {
9139 *r->out.needed = blob.length;
9141 if (r->in.offered >= *r->out.needed) {
9142 memcpy(r->out.data, blob.data, blob.length);
9145 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9148 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9151 printer = lp_const_servicename(snum);
9153 /* check to see if the keyname is valid */
9154 if (!strlen(r->in.key_name)) {
9155 return WERR_INVALID_PARAM;
9158 /* XP sends this and wants the ChangeID value from PRINTER_INFO_0 */
9159 if (strequal(r->in.key_name, SPOOL_PRINTERDATA_KEY) &&
9160 strequal(r->in.value_name, "ChangeId")) {
9161 *r->out.type = REG_DWORD;
9163 if (r->in.offered >= *r->out.needed) {
9164 uint32_t changeid = 0;
9166 result = winreg_printer_get_changeid(p->mem_ctx,
9167 get_server_info_system(),
9171 if (!W_ERROR_IS_OK(result)) {
9175 SIVAL(r->out.data, 0, changeid);
9181 result = winreg_get_printer_dataex(p->mem_ctx,
9182 get_server_info_system(),
9190 if (!W_ERROR_IS_OK(result)) {
9194 *r->out.needed = val_size;
9195 *r->out.type = val_type;
9197 if (r->in.offered >= *r->out.needed) {
9198 memcpy(r->out.data, val_data, val_size);
9202 *r->out.type = SPOOLSS_BUFFER_OK(*r->out.type, REG_NONE);
9203 r->out.data = SPOOLSS_BUFFER_OK(r->out.data, r->out.data);
9205 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9208 /****************************************************************
9209 _spoolss_SetPrinterDataEx
9210 ****************************************************************/
9212 WERROR _spoolss_SetPrinterDataEx(struct pipes_struct *p,
9213 struct spoolss_SetPrinterDataEx *r)
9215 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
9217 WERROR result = WERR_OK;
9218 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9221 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
9223 /* From MSDN documentation of SetPrinterDataEx: pass request to
9224 SetPrinterData if key is "PrinterDriverData" */
9227 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9228 OUR_HANDLE(r->in.handle)));
9232 if (Printer->printer_type == SPLHND_SERVER) {
9233 DEBUG(10,("_spoolss_SetPrinterDataEx: "
9234 "Not implemented for server handles yet\n"));
9235 return WERR_INVALID_PARAM;
9238 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9243 * Access check : NT returns "access denied" if you make a
9244 * SetPrinterData call without the necessary privildge.
9245 * we were originally returning OK if nothing changed
9246 * which made Win2k issue **a lot** of SetPrinterData
9247 * when connecting to a printer --jerry
9250 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9251 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
9252 "change denied by handle access permissions\n"));
9253 return WERR_ACCESS_DENIED;
9256 result = winreg_get_printer(Printer,
9257 get_server_info_system(),
9259 lp_servicename(snum),
9261 if (!W_ERROR_IS_OK(result)) {
9265 /* check for OID in valuename */
9267 oid_string = strchr(r->in.value_name, ',');
9273 /* save the registry data */
9275 result = winreg_set_printer_dataex(p->mem_ctx,
9276 get_server_info_system(),
9285 if (W_ERROR_IS_OK(result)) {
9286 /* save the OID if one was specified */
9288 char *str = talloc_asprintf(p->mem_ctx, "%s\\%s",
9289 r->in.key_name, SPOOL_OID_KEY);
9291 result = WERR_NOMEM;
9296 * I'm not checking the status here on purpose. Don't know
9297 * if this is right, but I'm returning the status from the
9298 * previous set_printer_dataex() call. I have no idea if
9299 * this is right. --jerry
9301 winreg_set_printer_dataex(p->mem_ctx,
9302 get_server_info_system(),
9308 (uint8_t *) oid_string,
9309 strlen(oid_string) + 1);
9312 result = winreg_printer_update_changeid(p->mem_ctx,
9313 get_server_info_system(),
9315 lp_const_servicename(snum));
9320 talloc_free(pinfo2);
9324 /****************************************************************
9325 _spoolss_DeletePrinterDataEx
9326 ****************************************************************/
9328 WERROR _spoolss_DeletePrinterDataEx(struct pipes_struct *p,
9329 struct spoolss_DeletePrinterDataEx *r)
9331 const char *printer;
9333 WERROR status = WERR_OK;
9334 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9336 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
9339 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
9340 "Invalid handle (%s:%u:%u).\n",
9341 OUR_HANDLE(r->in.handle)));
9345 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9346 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
9347 "printer properties change denied by handle\n"));
9348 return WERR_ACCESS_DENIED;
9351 if (!r->in.value_name || !r->in.key_name) {
9355 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9358 printer = lp_const_servicename(snum);
9360 status = winreg_delete_printer_dataex(p->mem_ctx,
9361 get_server_info_system(),
9366 if (W_ERROR_IS_OK(status)) {
9367 status = winreg_printer_update_changeid(p->mem_ctx,
9368 get_server_info_system(),
9376 /****************************************************************
9377 _spoolss_EnumPrinterKey
9378 ****************************************************************/
9380 WERROR _spoolss_EnumPrinterKey(struct pipes_struct *p,
9381 struct spoolss_EnumPrinterKey *r)
9384 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9386 WERROR result = WERR_BADFILE;
9387 const char **array = NULL;
9390 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
9393 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
9394 OUR_HANDLE(r->in.handle)));
9398 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9402 result = winreg_enum_printer_key(p->mem_ctx,
9403 get_server_info_system(),
9405 lp_const_servicename(snum),
9409 if (!W_ERROR_IS_OK(result)) {
9413 if (!push_reg_multi_sz(p->mem_ctx, &blob, array)) {
9414 result = WERR_NOMEM;
9418 *r->out._ndr_size = r->in.offered / 2;
9419 *r->out.needed = blob.length;
9421 if (r->in.offered < *r->out.needed) {
9422 result = WERR_MORE_DATA;
9425 r->out.key_buffer->string_array = array;
9429 if (!W_ERROR_IS_OK(result)) {
9431 if (!W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
9439 /****************************************************************
9440 _spoolss_DeletePrinterKey
9441 ****************************************************************/
9443 WERROR _spoolss_DeletePrinterKey(struct pipes_struct *p,
9444 struct spoolss_DeletePrinterKey *r)
9446 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9449 const char *printer;
9451 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
9454 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
9455 OUR_HANDLE(r->in.handle)));
9459 /* if keyname == NULL, return error */
9460 if ( !r->in.key_name )
9461 return WERR_INVALID_PARAM;
9463 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9467 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9468 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9469 "printer properties change denied by handle\n"));
9470 return WERR_ACCESS_DENIED;
9473 printer = lp_const_servicename(snum);
9475 /* delete the key and all subkeys */
9476 status = winreg_delete_printer_key(p->mem_ctx,
9477 get_server_info_system(),
9481 if (W_ERROR_IS_OK(status)) {
9482 status = winreg_printer_update_changeid(p->mem_ctx,
9483 get_server_info_system(),
9491 /****************************************************************
9492 _spoolss_EnumPrinterDataEx
9493 ****************************************************************/
9495 WERROR _spoolss_EnumPrinterDataEx(struct pipes_struct *p,
9496 struct spoolss_EnumPrinterDataEx *r)
9499 struct spoolss_PrinterEnumValues *info = NULL;
9500 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9504 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
9508 *r->out.info = NULL;
9511 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
9512 OUR_HANDLE(r->in.handle)));
9517 * first check for a keyname of NULL or "". Win2k seems to send
9518 * this a lot and we should send back WERR_INVALID_PARAM
9519 * no need to spend time looking up the printer in this case.
9523 if (!strlen(r->in.key_name)) {
9524 result = WERR_INVALID_PARAM;
9528 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9532 /* now look for a match on the key name */
9533 result = winreg_enum_printer_dataex(p->mem_ctx,
9534 get_server_info_system(),
9536 lp_const_servicename(snum),
9540 if (!W_ERROR_IS_OK(result)) {
9544 #if 0 /* FIXME - gd */
9545 /* housekeeping information in the reply */
9547 /* Fix from Martin Zielinski <mz@seh.de> - ensure
9548 * the hand marshalled container size is a multiple
9549 * of 4 bytes for RPC alignment.
9553 needed += 4-(needed % 4);
9556 *r->out.count = count;
9557 *r->out.info = info;
9560 if (!W_ERROR_IS_OK(result)) {
9564 *r->out.needed = SPOOLSS_BUFFER_ARRAY(p->mem_ctx,
9565 spoolss_EnumPrinterDataEx,
9568 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9569 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, *r->out.count);
9571 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9574 /****************************************************************************
9575 ****************************************************************************/
9577 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
9578 const char *servername,
9579 const char *environment,
9580 struct spoolss_PrintProcessorDirectoryInfo1 *r)
9585 werr = compose_spoolss_server_path(mem_ctx,
9588 SPOOLSS_PRTPROCS_PATH,
9590 if (!W_ERROR_IS_OK(werr)) {
9594 DEBUG(4,("print processor directory: [%s]\n", path));
9596 r->directory_name = path;
9601 /****************************************************************
9602 _spoolss_GetPrintProcessorDirectory
9603 ****************************************************************/
9605 WERROR _spoolss_GetPrintProcessorDirectory(struct pipes_struct *p,
9606 struct spoolss_GetPrintProcessorDirectory *r)
9609 fstring prnproc_share;
9610 bool prnproc_share_exists = false;
9613 /* that's an [in out] buffer */
9615 if (!r->in.buffer && (r->in.offered != 0)) {
9616 return WERR_INVALID_PARAM;
9619 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9624 /* r->in.level is ignored */
9626 /* We always should reply with a local print processor directory so that
9627 * users are not forced to have a [prnproc$] share on the Samba spoolss
9628 * server, if users decide to do so, lets announce it though - Guenther */
9630 fstrcpy(prnproc_share, "prnproc$");
9632 snum = find_service(prnproc_share);
9634 prnproc_share_exists = true;
9637 result = getprintprocessordirectory_level_1(p->mem_ctx,
9638 prnproc_share_exists ? r->in.server : NULL,
9640 &r->out.info->info1);
9641 if (!W_ERROR_IS_OK(result)) {
9642 TALLOC_FREE(r->out.info);
9646 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo,
9647 r->out.info, r->in.level);
9648 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9650 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9653 /*******************************************************************
9654 ********************************************************************/
9656 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
9657 const char *dllname)
9659 enum ndr_err_code ndr_err;
9660 struct spoolss_MonitorUi ui;
9662 ui.dll_name = dllname;
9664 ndr_err = ndr_push_struct_blob(buf, mem_ctx, &ui,
9665 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
9666 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9667 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
9669 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9672 /*******************************************************************
9673 Streams the monitor UI DLL name in UNICODE
9674 *******************************************************************/
9676 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
9677 struct security_token *token, DATA_BLOB *in,
9678 DATA_BLOB *out, uint32_t *needed)
9680 const char *dllname = "tcpmonui.dll";
9682 *needed = (strlen(dllname)+1) * 2;
9684 if (out->length < *needed) {
9685 return WERR_INSUFFICIENT_BUFFER;
9688 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9695 /*******************************************************************
9696 ********************************************************************/
9698 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
9699 struct spoolss_PortData1 *port1,
9700 const DATA_BLOB *buf)
9702 enum ndr_err_code ndr_err;
9703 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port1,
9704 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
9705 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9706 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
9708 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9711 /*******************************************************************
9712 ********************************************************************/
9714 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
9715 struct spoolss_PortData2 *port2,
9716 const DATA_BLOB *buf)
9718 enum ndr_err_code ndr_err;
9719 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port2,
9720 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
9721 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9722 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
9724 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9727 /*******************************************************************
9728 Create a new TCP/IP port
9729 *******************************************************************/
9731 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
9732 struct security_token *token, DATA_BLOB *in,
9733 DATA_BLOB *out, uint32_t *needed)
9735 struct spoolss_PortData1 port1;
9736 struct spoolss_PortData2 port2;
9737 char *device_uri = NULL;
9740 const char *portname;
9741 const char *hostaddress;
9743 uint32_t port_number;
9746 /* peek for spoolss_PortData version */
9748 if (!in || (in->length < (128 + 4))) {
9749 return WERR_GENERAL_FAILURE;
9752 version = IVAL(in->data, 128);
9758 if (!pull_port_data_1(mem_ctx, &port1, in)) {
9762 portname = port1.portname;
9763 hostaddress = port1.hostaddress;
9764 queue = port1.queue;
9765 protocol = port1.protocol;
9766 port_number = port1.port_number;
9772 if (!pull_port_data_2(mem_ctx, &port2, in)) {
9776 portname = port2.portname;
9777 hostaddress = port2.hostaddress;
9778 queue = port2.queue;
9779 protocol = port2.protocol;
9780 port_number = port2.port_number;
9784 DEBUG(1,("xcvtcp_addport: "
9785 "unknown version of port_data: %d\n", version));
9786 return WERR_UNKNOWN_PORT;
9789 /* create the device URI and call the add_port_hook() */
9792 case PROTOCOL_RAWTCP_TYPE:
9793 device_uri = talloc_asprintf(mem_ctx,
9794 "socket://%s:%d/", hostaddress,
9798 case PROTOCOL_LPR_TYPE:
9799 device_uri = talloc_asprintf(mem_ctx,
9800 "lpr://%s/%s", hostaddress, queue );
9804 return WERR_UNKNOWN_PORT;
9811 return add_port_hook(mem_ctx, token, portname, device_uri);
9814 /*******************************************************************
9815 *******************************************************************/
9817 struct xcv_api_table xcvtcp_cmds[] = {
9818 { "MonitorUI", xcvtcp_monitorui },
9819 { "AddPort", xcvtcp_addport},
9823 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
9824 struct security_token *token, const char *command,
9831 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
9833 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
9834 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
9835 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9838 return WERR_BADFUNC;
9841 /*******************************************************************
9842 *******************************************************************/
9843 #if 0 /* don't support management using the "Local Port" monitor */
9845 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
9846 struct security_token *token, DATA_BLOB *in,
9847 DATA_BLOB *out, uint32_t *needed)
9849 const char *dllname = "localui.dll";
9851 *needed = (strlen(dllname)+1) * 2;
9853 if (out->length < *needed) {
9854 return WERR_INSUFFICIENT_BUFFER;
9857 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9864 /*******************************************************************
9865 *******************************************************************/
9867 struct xcv_api_table xcvlocal_cmds[] = {
9868 { "MonitorUI", xcvlocal_monitorui },
9872 struct xcv_api_table xcvlocal_cmds[] = {
9879 /*******************************************************************
9880 *******************************************************************/
9882 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
9883 struct security_token *token, const char *command,
9884 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
9889 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
9891 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
9892 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
9893 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9895 return WERR_BADFUNC;
9898 /****************************************************************
9900 ****************************************************************/
9902 WERROR _spoolss_XcvData(struct pipes_struct *p,
9903 struct spoolss_XcvData *r)
9905 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9906 DATA_BLOB out_data = data_blob_null;
9910 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
9911 OUR_HANDLE(r->in.handle)));
9915 /* Has to be a handle to the TCP/IP port monitor */
9917 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
9918 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
9922 /* requires administrative access to the server */
9924 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
9925 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
9926 return WERR_ACCESS_DENIED;
9929 /* Allocate the outgoing buffer */
9931 if (r->in.out_data_size) {
9932 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
9933 if (out_data.data == NULL) {
9938 switch ( Printer->printer_type ) {
9939 case SPLHND_PORTMON_TCP:
9940 werror = process_xcvtcp_command(p->mem_ctx,
9941 p->server_info->ptok,
9942 r->in.function_name,
9943 &r->in.in_data, &out_data,
9946 case SPLHND_PORTMON_LOCAL:
9947 werror = process_xcvlocal_command(p->mem_ctx,
9948 p->server_info->ptok,
9949 r->in.function_name,
9950 &r->in.in_data, &out_data,
9954 werror = WERR_INVALID_PRINT_MONITOR;
9957 if (!W_ERROR_IS_OK(werror)) {
9961 *r->out.status_code = 0;
9963 if (r->out.out_data && out_data.data && r->in.out_data_size && out_data.length) {
9964 memcpy(r->out.out_data, out_data.data,
9965 MIN(r->in.out_data_size, out_data.length));
9971 /****************************************************************
9972 _spoolss_AddPrintProcessor
9973 ****************************************************************/
9975 WERROR _spoolss_AddPrintProcessor(struct pipes_struct *p,
9976 struct spoolss_AddPrintProcessor *r)
9978 /* for now, just indicate success and ignore the add. We'll
9979 automatically set the winprint processor for printer
9980 entries later. Used to debug the LexMark Optra S 1855 PCL
9986 /****************************************************************
9988 ****************************************************************/
9990 WERROR _spoolss_AddPort(struct pipes_struct *p,
9991 struct spoolss_AddPort *r)
9993 /* do what w2k3 does */
9995 return WERR_NOT_SUPPORTED;
9998 /****************************************************************
9999 _spoolss_GetPrinterDriver
10000 ****************************************************************/
10002 WERROR _spoolss_GetPrinterDriver(struct pipes_struct *p,
10003 struct spoolss_GetPrinterDriver *r)
10005 p->rng_fault_state = true;
10006 return WERR_NOT_SUPPORTED;
10009 /****************************************************************
10010 _spoolss_ReadPrinter
10011 ****************************************************************/
10013 WERROR _spoolss_ReadPrinter(struct pipes_struct *p,
10014 struct spoolss_ReadPrinter *r)
10016 p->rng_fault_state = true;
10017 return WERR_NOT_SUPPORTED;
10020 /****************************************************************
10021 _spoolss_WaitForPrinterChange
10022 ****************************************************************/
10024 WERROR _spoolss_WaitForPrinterChange(struct pipes_struct *p,
10025 struct spoolss_WaitForPrinterChange *r)
10027 p->rng_fault_state = true;
10028 return WERR_NOT_SUPPORTED;
10031 /****************************************************************
10032 _spoolss_ConfigurePort
10033 ****************************************************************/
10035 WERROR _spoolss_ConfigurePort(struct pipes_struct *p,
10036 struct spoolss_ConfigurePort *r)
10038 p->rng_fault_state = true;
10039 return WERR_NOT_SUPPORTED;
10042 /****************************************************************
10043 _spoolss_DeletePort
10044 ****************************************************************/
10046 WERROR _spoolss_DeletePort(struct pipes_struct *p,
10047 struct spoolss_DeletePort *r)
10049 p->rng_fault_state = true;
10050 return WERR_NOT_SUPPORTED;
10053 /****************************************************************
10054 _spoolss_CreatePrinterIC
10055 ****************************************************************/
10057 WERROR _spoolss_CreatePrinterIC(struct pipes_struct *p,
10058 struct spoolss_CreatePrinterIC *r)
10060 p->rng_fault_state = true;
10061 return WERR_NOT_SUPPORTED;
10064 /****************************************************************
10065 _spoolss_PlayGDIScriptOnPrinterIC
10066 ****************************************************************/
10068 WERROR _spoolss_PlayGDIScriptOnPrinterIC(struct pipes_struct *p,
10069 struct spoolss_PlayGDIScriptOnPrinterIC *r)
10071 p->rng_fault_state = true;
10072 return WERR_NOT_SUPPORTED;
10075 /****************************************************************
10076 _spoolss_DeletePrinterIC
10077 ****************************************************************/
10079 WERROR _spoolss_DeletePrinterIC(struct pipes_struct *p,
10080 struct spoolss_DeletePrinterIC *r)
10082 p->rng_fault_state = true;
10083 return WERR_NOT_SUPPORTED;
10086 /****************************************************************
10087 _spoolss_AddPrinterConnection
10088 ****************************************************************/
10090 WERROR _spoolss_AddPrinterConnection(struct pipes_struct *p,
10091 struct spoolss_AddPrinterConnection *r)
10093 p->rng_fault_state = true;
10094 return WERR_NOT_SUPPORTED;
10097 /****************************************************************
10098 _spoolss_DeletePrinterConnection
10099 ****************************************************************/
10101 WERROR _spoolss_DeletePrinterConnection(struct pipes_struct *p,
10102 struct spoolss_DeletePrinterConnection *r)
10104 p->rng_fault_state = true;
10105 return WERR_NOT_SUPPORTED;
10108 /****************************************************************
10109 _spoolss_PrinterMessageBox
10110 ****************************************************************/
10112 WERROR _spoolss_PrinterMessageBox(struct pipes_struct *p,
10113 struct spoolss_PrinterMessageBox *r)
10115 p->rng_fault_state = true;
10116 return WERR_NOT_SUPPORTED;
10119 /****************************************************************
10120 _spoolss_AddMonitor
10121 ****************************************************************/
10123 WERROR _spoolss_AddMonitor(struct pipes_struct *p,
10124 struct spoolss_AddMonitor *r)
10126 p->rng_fault_state = true;
10127 return WERR_NOT_SUPPORTED;
10130 /****************************************************************
10131 _spoolss_DeleteMonitor
10132 ****************************************************************/
10134 WERROR _spoolss_DeleteMonitor(struct pipes_struct *p,
10135 struct spoolss_DeleteMonitor *r)
10137 p->rng_fault_state = true;
10138 return WERR_NOT_SUPPORTED;
10141 /****************************************************************
10142 _spoolss_DeletePrintProcessor
10143 ****************************************************************/
10145 WERROR _spoolss_DeletePrintProcessor(struct pipes_struct *p,
10146 struct spoolss_DeletePrintProcessor *r)
10148 p->rng_fault_state = true;
10149 return WERR_NOT_SUPPORTED;
10152 /****************************************************************
10153 _spoolss_AddPrintProvidor
10154 ****************************************************************/
10156 WERROR _spoolss_AddPrintProvidor(struct pipes_struct *p,
10157 struct spoolss_AddPrintProvidor *r)
10159 p->rng_fault_state = true;
10160 return WERR_NOT_SUPPORTED;
10163 /****************************************************************
10164 _spoolss_DeletePrintProvidor
10165 ****************************************************************/
10167 WERROR _spoolss_DeletePrintProvidor(struct pipes_struct *p,
10168 struct spoolss_DeletePrintProvidor *r)
10170 p->rng_fault_state = true;
10171 return WERR_NOT_SUPPORTED;
10174 /****************************************************************
10175 _spoolss_FindFirstPrinterChangeNotification
10176 ****************************************************************/
10178 WERROR _spoolss_FindFirstPrinterChangeNotification(struct pipes_struct *p,
10179 struct spoolss_FindFirstPrinterChangeNotification *r)
10181 p->rng_fault_state = true;
10182 return WERR_NOT_SUPPORTED;
10185 /****************************************************************
10186 _spoolss_FindNextPrinterChangeNotification
10187 ****************************************************************/
10189 WERROR _spoolss_FindNextPrinterChangeNotification(struct pipes_struct *p,
10190 struct spoolss_FindNextPrinterChangeNotification *r)
10192 p->rng_fault_state = true;
10193 return WERR_NOT_SUPPORTED;
10196 /****************************************************************
10197 _spoolss_RouterFindFirstPrinterChangeNotificationOld
10198 ****************************************************************/
10200 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(struct pipes_struct *p,
10201 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
10203 p->rng_fault_state = true;
10204 return WERR_NOT_SUPPORTED;
10207 /****************************************************************
10208 _spoolss_ReplyOpenPrinter
10209 ****************************************************************/
10211 WERROR _spoolss_ReplyOpenPrinter(struct pipes_struct *p,
10212 struct spoolss_ReplyOpenPrinter *r)
10214 p->rng_fault_state = true;
10215 return WERR_NOT_SUPPORTED;
10218 /****************************************************************
10219 _spoolss_RouterReplyPrinter
10220 ****************************************************************/
10222 WERROR _spoolss_RouterReplyPrinter(struct pipes_struct *p,
10223 struct spoolss_RouterReplyPrinter *r)
10225 p->rng_fault_state = true;
10226 return WERR_NOT_SUPPORTED;
10229 /****************************************************************
10230 _spoolss_ReplyClosePrinter
10231 ****************************************************************/
10233 WERROR _spoolss_ReplyClosePrinter(struct pipes_struct *p,
10234 struct spoolss_ReplyClosePrinter *r)
10236 p->rng_fault_state = true;
10237 return WERR_NOT_SUPPORTED;
10240 /****************************************************************
10242 ****************************************************************/
10244 WERROR _spoolss_AddPortEx(struct pipes_struct *p,
10245 struct spoolss_AddPortEx *r)
10247 p->rng_fault_state = true;
10248 return WERR_NOT_SUPPORTED;
10251 /****************************************************************
10252 _spoolss_RouterFindFirstPrinterChangeNotification
10253 ****************************************************************/
10255 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(struct pipes_struct *p,
10256 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
10258 p->rng_fault_state = true;
10259 return WERR_NOT_SUPPORTED;
10262 /****************************************************************
10263 _spoolss_SpoolerInit
10264 ****************************************************************/
10266 WERROR _spoolss_SpoolerInit(struct pipes_struct *p,
10267 struct spoolss_SpoolerInit *r)
10269 p->rng_fault_state = true;
10270 return WERR_NOT_SUPPORTED;
10273 /****************************************************************
10274 _spoolss_ResetPrinterEx
10275 ****************************************************************/
10277 WERROR _spoolss_ResetPrinterEx(struct pipes_struct *p,
10278 struct spoolss_ResetPrinterEx *r)
10280 p->rng_fault_state = true;
10281 return WERR_NOT_SUPPORTED;
10284 /****************************************************************
10285 _spoolss_RouterReplyPrinterEx
10286 ****************************************************************/
10288 WERROR _spoolss_RouterReplyPrinterEx(struct pipes_struct *p,
10289 struct spoolss_RouterReplyPrinterEx *r)
10291 p->rng_fault_state = true;
10292 return WERR_NOT_SUPPORTED;
10295 /****************************************************************
10297 ****************************************************************/
10299 WERROR _spoolss_44(struct pipes_struct *p,
10300 struct spoolss_44 *r)
10302 p->rng_fault_state = true;
10303 return WERR_NOT_SUPPORTED;
10306 /****************************************************************
10308 ****************************************************************/
10310 WERROR _spoolss_SetPort(struct pipes_struct *p,
10311 struct spoolss_SetPort *r)
10313 p->rng_fault_state = true;
10314 return WERR_NOT_SUPPORTED;
10317 /****************************************************************
10319 ****************************************************************/
10321 WERROR _spoolss_4a(struct pipes_struct *p,
10322 struct spoolss_4a *r)
10324 p->rng_fault_state = true;
10325 return WERR_NOT_SUPPORTED;
10328 /****************************************************************
10330 ****************************************************************/
10332 WERROR _spoolss_4b(struct pipes_struct *p,
10333 struct spoolss_4b *r)
10335 p->rng_fault_state = true;
10336 return WERR_NOT_SUPPORTED;
10339 /****************************************************************
10341 ****************************************************************/
10343 WERROR _spoolss_4c(struct pipes_struct *p,
10344 struct spoolss_4c *r)
10346 p->rng_fault_state = true;
10347 return WERR_NOT_SUPPORTED;
10350 /****************************************************************
10352 ****************************************************************/
10354 WERROR _spoolss_53(struct pipes_struct *p,
10355 struct spoolss_53 *r)
10357 p->rng_fault_state = true;
10358 return WERR_NOT_SUPPORTED;
10361 /****************************************************************
10363 ****************************************************************/
10365 WERROR _spoolss_55(struct pipes_struct *p,
10366 struct spoolss_55 *r)
10368 p->rng_fault_state = true;
10369 return WERR_NOT_SUPPORTED;
10372 /****************************************************************
10374 ****************************************************************/
10376 WERROR _spoolss_56(struct pipes_struct *p,
10377 struct spoolss_56 *r)
10379 p->rng_fault_state = true;
10380 return WERR_NOT_SUPPORTED;
10383 /****************************************************************
10385 ****************************************************************/
10387 WERROR _spoolss_57(struct pipes_struct *p,
10388 struct spoolss_57 *r)
10390 p->rng_fault_state = true;
10391 return WERR_NOT_SUPPORTED;
10394 /****************************************************************
10396 ****************************************************************/
10398 WERROR _spoolss_5a(struct pipes_struct *p,
10399 struct spoolss_5a *r)
10401 p->rng_fault_state = true;
10402 return WERR_NOT_SUPPORTED;
10405 /****************************************************************
10407 ****************************************************************/
10409 WERROR _spoolss_5b(struct pipes_struct *p,
10410 struct spoolss_5b *r)
10412 p->rng_fault_state = true;
10413 return WERR_NOT_SUPPORTED;
10416 /****************************************************************
10418 ****************************************************************/
10420 WERROR _spoolss_5c(struct pipes_struct *p,
10421 struct spoolss_5c *r)
10423 p->rng_fault_state = true;
10424 return WERR_NOT_SUPPORTED;
10427 /****************************************************************
10429 ****************************************************************/
10431 WERROR _spoolss_5d(struct pipes_struct *p,
10432 struct spoolss_5d *r)
10434 p->rng_fault_state = true;
10435 return WERR_NOT_SUPPORTED;
10438 /****************************************************************
10440 ****************************************************************/
10442 WERROR _spoolss_5e(struct pipes_struct *p,
10443 struct spoolss_5e *r)
10445 p->rng_fault_state = true;
10446 return WERR_NOT_SUPPORTED;
10449 /****************************************************************
10451 ****************************************************************/
10453 WERROR _spoolss_5f(struct pipes_struct *p,
10454 struct spoolss_5f *r)
10456 p->rng_fault_state = true;
10457 return WERR_NOT_SUPPORTED;
10460 /****************************************************************
10462 ****************************************************************/
10464 WERROR _spoolss_60(struct pipes_struct *p,
10465 struct spoolss_60 *r)
10467 p->rng_fault_state = true;
10468 return WERR_NOT_SUPPORTED;
10471 /****************************************************************
10473 ****************************************************************/
10475 WERROR _spoolss_61(struct pipes_struct *p,
10476 struct spoolss_61 *r)
10478 p->rng_fault_state = true;
10479 return WERR_NOT_SUPPORTED;
10482 /****************************************************************
10484 ****************************************************************/
10486 WERROR _spoolss_62(struct pipes_struct *p,
10487 struct spoolss_62 *r)
10489 p->rng_fault_state = true;
10490 return WERR_NOT_SUPPORTED;
10493 /****************************************************************
10495 ****************************************************************/
10497 WERROR _spoolss_63(struct pipes_struct *p,
10498 struct spoolss_63 *r)
10500 p->rng_fault_state = true;
10501 return WERR_NOT_SUPPORTED;
10504 /****************************************************************
10506 ****************************************************************/
10508 WERROR _spoolss_64(struct pipes_struct *p,
10509 struct spoolss_64 *r)
10511 p->rng_fault_state = true;
10512 return WERR_NOT_SUPPORTED;
10515 /****************************************************************
10517 ****************************************************************/
10519 WERROR _spoolss_65(struct pipes_struct *p,
10520 struct spoolss_65 *r)
10522 p->rng_fault_state = true;
10523 return WERR_NOT_SUPPORTED;
10526 /****************************************************************
10527 _spoolss_GetCorePrinterDrivers
10528 ****************************************************************/
10530 WERROR _spoolss_GetCorePrinterDrivers(struct pipes_struct *p,
10531 struct spoolss_GetCorePrinterDrivers *r)
10533 p->rng_fault_state = true;
10534 return WERR_NOT_SUPPORTED;
10537 /****************************************************************
10539 ****************************************************************/
10541 WERROR _spoolss_67(struct pipes_struct *p,
10542 struct spoolss_67 *r)
10544 p->rng_fault_state = true;
10545 return WERR_NOT_SUPPORTED;
10548 /****************************************************************
10549 _spoolss_GetPrinterDriverPackagePath
10550 ****************************************************************/
10552 WERROR _spoolss_GetPrinterDriverPackagePath(struct pipes_struct *p,
10553 struct spoolss_GetPrinterDriverPackagePath *r)
10555 p->rng_fault_state = true;
10556 return WERR_NOT_SUPPORTED;
10559 /****************************************************************
10561 ****************************************************************/
10563 WERROR _spoolss_69(struct pipes_struct *p,
10564 struct spoolss_69 *r)
10566 p->rng_fault_state = true;
10567 return WERR_NOT_SUPPORTED;
10570 /****************************************************************
10572 ****************************************************************/
10574 WERROR _spoolss_6a(struct pipes_struct *p,
10575 struct spoolss_6a *r)
10577 p->rng_fault_state = true;
10578 return WERR_NOT_SUPPORTED;
10581 /****************************************************************
10583 ****************************************************************/
10585 WERROR _spoolss_6b(struct pipes_struct *p,
10586 struct spoolss_6b *r)
10588 p->rng_fault_state = true;
10589 return WERR_NOT_SUPPORTED;
10592 /****************************************************************
10594 ****************************************************************/
10596 WERROR _spoolss_6c(struct pipes_struct *p,
10597 struct spoolss_6c *r)
10599 p->rng_fault_state = true;
10600 return WERR_NOT_SUPPORTED;
10603 /****************************************************************
10605 ****************************************************************/
10607 WERROR _spoolss_6d(struct pipes_struct *p,
10608 struct spoolss_6d *r)
10610 p->rng_fault_state = true;
10611 return WERR_NOT_SUPPORTED;