2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-2000,
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
6 * Copyright (C) Jean François Micouleau 1998-2000,
7 * Copyright (C) Jeremy Allison 2001-2002,
8 * Copyright (C) Gerald Carter 2000-2004,
9 * Copyright (C) Tim Potter 2001-2002.
10 * Copyright (C) Guenther Deschner 2009-2010.
11 * Copyright (C) Andreas Schneider 2010.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 /* Since the SPOOLSS rpc routines are basically DOS 16-bit calls wrapped
28 up, all the errors returned are DOS errors, not NT status codes. */
31 #include "nt_printing.h"
32 #include "srv_spoolss_util.h"
33 #include "../librpc/gen_ndr/srv_spoolss.h"
34 #include "../librpc/gen_ndr/cli_spoolss.h"
35 #include "rpc_client/init_spoolss.h"
36 #include "librpc/gen_ndr/messaging.h"
37 #include "../libcli/security/security.h"
38 #include "librpc/gen_ndr/ndr_security.h"
40 #include "registry/reg_objects.h"
41 #include "include/printing.h"
43 #include "../librpc/gen_ndr/netlogon.h"
46 /* macros stolen from s4 spoolss server */
47 #define SPOOLSS_BUFFER_UNION(fn,info,level) \
48 ((info)?ndr_size_##fn(info, level, 0):0)
50 #define SPOOLSS_BUFFER_UNION_ARRAY(mem_ctx,fn,info,level,count) \
51 ((info)?ndr_size_##fn##_info(mem_ctx, level, count, info):0)
53 #define SPOOLSS_BUFFER_ARRAY(mem_ctx,fn,info,count) \
54 ((info)?ndr_size_##fn##_info(mem_ctx, count, info):0)
56 #define SPOOLSS_BUFFER_OK(val_true,val_false) ((r->in.offered >= *r->out.needed)?val_true:val_false)
59 #define DBGC_CLASS DBGC_RPC_SRV
61 #ifndef MAX_OPEN_PRINTER_EXS
62 #define MAX_OPEN_PRINTER_EXS 50
65 struct notify_back_channel;
67 /* structure to store the printer handles */
68 /* and a reference to what it's pointing to */
69 /* and the notify info asked about */
70 /* that's the central struct */
71 struct printer_handle {
72 struct printer_handle *prev, *next;
73 bool document_started;
75 uint32 jobid; /* jobid in printing backend */
77 const char *servername;
80 uint32 access_granted;
86 struct spoolss_NotifyOption *option;
87 struct policy_handle cli_hnd;
88 struct notify_back_channel *cli_chan;
90 /* are we in a FindNextPrinterChangeNotify() call? */
92 struct messaging_context *msg_ctx;
99 /* devmode sent in the OpenPrinter() call */
100 struct spoolss_DeviceMode *devmode;
102 /* TODO cache the printer info2 structure */
103 struct spoolss_PrinterInfo2 *info2;
107 static struct printer_handle *printers_list;
109 struct printer_session_counter {
110 struct printer_session_counter *next;
111 struct printer_session_counter *prev;
117 static struct printer_session_counter *counter_list;
119 struct notify_back_channel {
120 struct notify_back_channel *prev, *next;
122 /* associated client */
123 struct sockaddr_storage client_address;
125 /* print notify back-channel pipe handle*/
126 struct rpc_pipe_client *cli_pipe;
127 uint32_t active_connections;
130 static struct notify_back_channel *back_channels;
132 /* Map generic permissions to printer object specific permissions */
134 const struct standard_mapping printer_std_mapping = {
141 /* Map generic permissions to print server object specific permissions */
143 const struct standard_mapping printserver_std_mapping = {
150 /* API table for Xcv Monitor functions */
152 struct xcv_api_table {
154 WERROR(*fn) (TALLOC_CTX *mem_ctx, struct security_token *token, DATA_BLOB *in, DATA_BLOB *out, uint32_t *needed);
157 static void prune_printername_cache(void);
159 /********************************************************************
160 * Canonicalize servername.
161 ********************************************************************/
163 static const char *canon_servername(const char *servername)
165 const char *pservername = servername;
166 while (*pservername == '\\') {
172 /* translate between internal status numbers and NT status numbers */
173 static int nt_printj_status(int v)
179 return JOB_STATUS_PAUSED;
181 return JOB_STATUS_SPOOLING;
183 return JOB_STATUS_PRINTING;
185 return JOB_STATUS_ERROR;
187 return JOB_STATUS_DELETING;
189 return JOB_STATUS_OFFLINE;
191 return JOB_STATUS_PAPEROUT;
193 return JOB_STATUS_PRINTED;
195 return JOB_STATUS_DELETED;
197 return JOB_STATUS_BLOCKED_DEVQ;
198 case LPQ_USER_INTERVENTION:
199 return JOB_STATUS_USER_INTERVENTION;
204 static int nt_printq_status(int v)
208 return PRINTER_STATUS_PAUSED;
217 /***************************************************************************
218 Disconnect from the client
219 ****************************************************************************/
221 static void srv_spoolss_replycloseprinter(int snum,
222 struct printer_handle *prn_hnd)
228 * Tell the specific printing tdb we no longer want messages for this printer
229 * by deregistering our PID.
232 if (!print_notify_deregister_pid(snum)) {
233 DEBUG(0, ("Failed to register our pid for printer %s\n",
234 lp_const_servicename(snum)));
237 /* weird if the test succeeds !!! */
238 if (prn_hnd->notify.cli_chan == NULL ||
239 prn_hnd->notify.cli_chan->active_connections == 0) {
240 DEBUG(0, ("Trying to close unexisting backchannel!\n"));
241 DLIST_REMOVE(back_channels, prn_hnd->notify.cli_chan);
242 TALLOC_FREE(prn_hnd->notify.cli_chan);
246 status = rpccli_spoolss_ReplyClosePrinter(
247 prn_hnd->notify.cli_chan->cli_pipe,
249 &prn_hnd->notify.cli_hnd,
251 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
252 DEBUG(0, ("reply_close_printer failed [%s].\n",
253 win_errstr(result)));
256 /* if it's the last connection, deconnect the IPC$ share */
257 if (prn_hnd->notify.cli_chan->active_connections == 1) {
259 cli_shutdown(rpc_pipe_np_smb_conn(prn_hnd->notify.cli_chan->cli_pipe));
260 DLIST_REMOVE(back_channels, prn_hnd->notify.cli_chan);
261 TALLOC_FREE(prn_hnd->notify.cli_chan);
263 if (prn_hnd->notify.msg_ctx != NULL) {
264 messaging_deregister(prn_hnd->notify.msg_ctx,
265 MSG_PRINTER_NOTIFY2, NULL);
268 * Tell the serverid.tdb we're no longer
269 * interested in printer notify messages.
272 serverid_register_msg_flags(
273 messaging_server_id(prn_hnd->notify.msg_ctx),
274 false, FLAG_MSG_PRINT_NOTIFY);
278 if (prn_hnd->notify.cli_chan) {
279 prn_hnd->notify.cli_chan->active_connections--;
283 /****************************************************************************
284 Functions to free a printer entry datastruct.
285 ****************************************************************************/
287 static int printer_entry_destructor(struct printer_handle *Printer)
289 if (Printer->notify.cli_chan != NULL &&
290 Printer->notify.cli_chan->active_connections > 0) {
293 switch(Printer->printer_type) {
295 srv_spoolss_replycloseprinter(snum, Printer);
299 snum = print_queue_snum(Printer->sharename);
301 srv_spoolss_replycloseprinter(snum, Printer);
309 Printer->notify.flags=0;
310 Printer->notify.options=0;
311 Printer->notify.localmachine[0]='\0';
312 Printer->notify.printerlocal=0;
313 TALLOC_FREE(Printer->notify.option);
314 TALLOC_FREE(Printer->devmode);
316 /* Remove from the internal list. */
317 DLIST_REMOVE(printers_list, Printer);
321 /****************************************************************************
322 find printer index by handle
323 ****************************************************************************/
325 static struct printer_handle *find_printer_index_by_hnd(struct pipes_struct *p,
326 struct policy_handle *hnd)
328 struct printer_handle *find_printer = NULL;
330 if(!find_policy_by_hnd(p,hnd,(void **)(void *)&find_printer)) {
331 DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: "));
338 /****************************************************************************
339 Close printer index by handle.
340 ****************************************************************************/
342 static bool close_printer_handle(struct pipes_struct *p, struct policy_handle *hnd)
344 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
347 DEBUG(2,("close_printer_handle: Invalid handle (%s:%u:%u)\n",
352 close_policy_hnd(p, hnd);
357 /****************************************************************************
358 Delete a printer given a handle.
359 ****************************************************************************/
361 static WERROR delete_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
362 const char *sharename,
363 struct messaging_context *msg_ctx)
365 char *cmd = lp_deleteprinter_cmd();
366 char *command = NULL;
368 bool is_print_op = false;
370 /* can't fail if we don't try */
375 command = talloc_asprintf(ctx,
382 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
384 DEBUG(10,("Running [%s]\n", command));
386 /********** BEGIN SePrintOperatorPrivlege BLOCK **********/
391 if ( (ret = smbrun(command, NULL)) == 0 ) {
392 /* Tell everyone we updated smb.conf. */
393 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
399 /********** END SePrintOperatorPrivlege BLOCK **********/
401 DEBUGADD(10,("returned [%d]\n", ret));
403 TALLOC_FREE(command);
406 return WERR_BADFID; /* What to return here? */
408 /* go ahead and re-read the services immediately */
410 reload_services(msg_ctx, -1, false);
413 if ( lp_servicenumber( sharename ) >= 0 )
414 return WERR_ACCESS_DENIED;
419 /****************************************************************************
420 Delete a printer given a handle.
421 ****************************************************************************/
423 static WERROR delete_printer_handle(struct pipes_struct *p, struct policy_handle *hnd)
425 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
429 DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n",
435 * It turns out that Windows allows delete printer on a handle
436 * opened by an admin user, then used on a pipe handle created
437 * by an anonymous user..... but they're working on security.... riiight !
441 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
442 DEBUG(3, ("delete_printer_handle: denied by handle\n"));
443 return WERR_ACCESS_DENIED;
446 /* this does not need a become root since the access check has been
447 done on the handle already */
449 result = winreg_delete_printer_key(p->mem_ctx,
450 get_server_info_system(),
454 if (!W_ERROR_IS_OK(result)) {
455 DEBUG(3,("Error deleting printer %s\n", Printer->sharename));
459 result = delete_printer_hook(p->mem_ctx, p->server_info->ptok,
460 Printer->sharename, p->msg_ctx);
461 if (!W_ERROR_IS_OK(result)) {
464 prune_printername_cache();
468 /****************************************************************************
469 Return the snum of a printer corresponding to an handle.
470 ****************************************************************************/
472 static bool get_printer_snum(struct pipes_struct *p, struct policy_handle *hnd,
473 int *number, struct share_params **params)
475 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
478 DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n",
483 switch (Printer->printer_type) {
485 DEBUG(4,("short name:%s\n", Printer->sharename));
486 *number = print_queue_snum(Printer->sharename);
487 return (*number != -1);
495 /****************************************************************************
496 Set printer handle type.
497 Check if it's \\server or \\server\printer
498 ****************************************************************************/
500 static bool set_printer_hnd_printertype(struct printer_handle *Printer, const char *handlename)
502 DEBUG(3,("Setting printer type=%s\n", handlename));
504 /* it's a print server */
505 if (handlename && *handlename=='\\' && *(handlename+1)=='\\' && !strchr_m(handlename+2, '\\')) {
506 DEBUGADD(4,("Printer is a print server\n"));
507 Printer->printer_type = SPLHND_SERVER;
509 /* it's a printer (set_printer_hnd_name() will handle port monitors */
511 DEBUGADD(4,("Printer is a printer\n"));
512 Printer->printer_type = SPLHND_PRINTER;
518 static void prune_printername_cache_fn(const char *key, const char *value,
519 time_t timeout, void *private_data)
524 static void prune_printername_cache(void)
526 gencache_iterate(prune_printername_cache_fn, NULL, "PRINTERNAME/*");
529 /****************************************************************************
530 Set printer handle name.. Accept names like \\server, \\server\printer,
531 \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
532 the MSDN docs regarding OpenPrinter() for details on the XcvData() and
533 XcvDataPort() interface.
534 ****************************************************************************/
536 static WERROR set_printer_hnd_name(TALLOC_CTX *mem_ctx,
537 const struct auth_serversupplied_info *server_info,
538 struct messaging_context *msg_ctx,
539 struct printer_handle *Printer,
540 const char *handlename)
543 int n_services=lp_numservices();
545 const char *printername;
546 const char *servername = NULL;
549 struct spoolss_PrinterInfo2 *info2 = NULL;
554 * Hopefully nobody names his printers like this. Maybe \ or ,
555 * are illegal in printer names even?
557 const char printer_not_found[] = "Printer \\, !@#$%^&*( not found";
561 DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename,
562 (unsigned long)strlen(handlename)));
564 aprinter = CONST_DISCARD(char *, handlename);
565 if ( *handlename == '\\' ) {
566 servername = canon_servername(handlename);
567 if ( (aprinter = strchr_m( servername, '\\' )) != NULL ) {
571 if (!is_myname_or_ipaddr(servername)) {
572 return WERR_INVALID_PRINTER_NAME;
574 Printer->servername = talloc_asprintf(Printer, "\\\\%s", servername);
575 if (Printer->servername == NULL) {
580 if (Printer->printer_type == SPLHND_SERVER) {
584 if (Printer->printer_type != SPLHND_PRINTER) {
585 return WERR_INVALID_HANDLE;
588 DEBUGADD(5, ("searching for [%s]\n", aprinter));
590 p = strchr(aprinter, ',');
597 if (strncmp(p, "DrvConvert", strlen("DrvConvert")) == 0) {
599 } else if (strncmp(p, "LocalOnly", strlen("LocalOnly")) == 0) {
605 DEBUGADD(5, ("stripped handlename: [%s]\n", aprinter));
608 /* check for the Port Monitor Interface */
609 if ( strequal( aprinter, SPL_XCV_MONITOR_TCPMON ) ) {
610 Printer->printer_type = SPLHND_PORTMON_TCP;
611 fstrcpy(sname, SPL_XCV_MONITOR_TCPMON);
614 else if ( strequal( aprinter, SPL_XCV_MONITOR_LOCALMON ) ) {
615 Printer->printer_type = SPLHND_PORTMON_LOCAL;
616 fstrcpy(sname, SPL_XCV_MONITOR_LOCALMON);
621 * With hundreds of printers, the "for" loop iterating all
622 * shares can be quite expensive, as it is done on every
623 * OpenPrinter. The loop maps "aprinter" to "sname", the
624 * result of which we cache in gencache.
627 cache_key = talloc_asprintf(talloc_tos(), "PRINTERNAME/%s",
629 if ((cache_key != NULL) && gencache_get(cache_key, &tmp, NULL)) {
631 found = (strcmp(tmp, printer_not_found) != 0);
633 DEBUG(4, ("Printer %s not found\n", aprinter));
635 return WERR_INVALID_PRINTER_NAME;
641 /* Search all sharenames first as this is easier than pulling
642 the printer_info_2 off of disk. Don't use find_service() since
643 that calls out to map_username() */
645 /* do another loop to look for printernames */
646 for (snum = 0; !found && snum < n_services; snum++) {
647 const char *printer = lp_const_servicename(snum);
649 /* no point going on if this is not a printer */
650 if (!(lp_snum_ok(snum) && lp_print_ok(snum))) {
654 /* ignore [printers] share */
655 if (strequal(printer, "printers")) {
659 fstrcpy(sname, printer);
660 if (strequal(aprinter, printer)) {
665 /* no point looking up the printer object if
666 we aren't allowing printername != sharename */
667 if (lp_force_printername(snum)) {
671 result = winreg_get_printer(mem_ctx,
676 if ( !W_ERROR_IS_OK(result) ) {
677 DEBUG(2,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
678 sname, win_errstr(result)));
682 printername = strrchr(info2->printername, '\\');
683 if (printername == NULL) {
684 printername = info2->printername;
689 if (strequal(printername, aprinter)) {
694 DEBUGADD(10, ("printername: %s\n", printername));
700 if (cache_key != NULL) {
701 gencache_set(cache_key, printer_not_found,
703 TALLOC_FREE(cache_key);
705 DEBUGADD(4,("Printer not found\n"));
706 return WERR_INVALID_PRINTER_NAME;
709 if (cache_key != NULL) {
710 gencache_set(cache_key, sname, time(NULL)+300);
711 TALLOC_FREE(cache_key);
714 DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter, sname));
716 fstrcpy(Printer->sharename, sname);
721 /****************************************************************************
722 Find first available printer slot. creates a printer handle for you.
723 ****************************************************************************/
725 static WERROR open_printer_hnd(struct pipes_struct *p,
726 struct policy_handle *hnd,
728 uint32_t access_granted)
730 struct printer_handle *new_printer;
733 DEBUG(10,("open_printer_hnd: name [%s]\n", name));
735 new_printer = talloc_zero(p->mem_ctx, struct printer_handle);
736 if (new_printer == NULL) {
739 talloc_set_destructor(new_printer, printer_entry_destructor);
741 /* This also steals the printer_handle on the policy_handle */
742 if (!create_policy_hnd(p, hnd, new_printer)) {
743 TALLOC_FREE(new_printer);
744 return WERR_INVALID_HANDLE;
747 /* Add to the internal list. */
748 DLIST_ADD(printers_list, new_printer);
750 new_printer->notify.option=NULL;
752 if (!set_printer_hnd_printertype(new_printer, name)) {
753 close_printer_handle(p, hnd);
754 return WERR_INVALID_HANDLE;
757 result = set_printer_hnd_name(p->mem_ctx,
758 get_server_info_system(),
761 if (!W_ERROR_IS_OK(result)) {
762 close_printer_handle(p, hnd);
766 new_printer->access_granted = access_granted;
768 DEBUG(5, ("%d printer handles active\n",
769 (int)num_pipe_handles(p)));
774 /***************************************************************************
775 check to see if the client motify handle is monitoring the notification
776 given by (notify_type, notify_field).
777 **************************************************************************/
779 static bool is_monitoring_event_flags(uint32_t flags, uint16_t notify_type,
780 uint16_t notify_field)
785 static bool is_monitoring_event(struct printer_handle *p, uint16_t notify_type,
786 uint16_t notify_field)
788 struct spoolss_NotifyOption *option = p->notify.option;
792 * Flags should always be zero when the change notify
793 * is registered by the client's spooler. A user Win32 app
794 * might use the flags though instead of the NOTIFY_OPTION_INFO
803 return is_monitoring_event_flags(
804 p->notify.flags, notify_type, notify_field);
806 for (i = 0; i < option->count; i++) {
808 /* Check match for notify_type */
810 if (option->types[i].type != notify_type)
813 /* Check match for field */
815 for (j = 0; j < option->types[i].count; j++) {
816 if (option->types[i].fields[j].field == notify_field) {
822 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
823 p->servername, p->sharename, notify_type, notify_field));
828 #define SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(_data, _integer) \
829 _data->data.integer[0] = _integer; \
830 _data->data.integer[1] = 0;
833 #define SETUP_SPOOLSS_NOTIFY_DATA_STRING(_data, _p) \
834 _data->data.string.string = talloc_strdup(mem_ctx, _p); \
835 if (!_data->data.string.string) {\
836 _data->data.string.size = 0; \
838 _data->data.string.size = strlen_m_term(_p) * 2;
840 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
841 _data->data.devmode.devmode = _devmode;
843 #define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _sd) \
844 _data->data.sd.sd = dup_sec_desc(mem_ctx, _sd); \
845 if (!_data->data.sd.sd) { \
846 _data->data.sd.sd_size = 0; \
848 _data->data.sd.sd_size = \
849 ndr_size_security_descriptor(_data->data.sd.sd, 0);
851 static void init_systemtime_buffer(TALLOC_CTX *mem_ctx,
856 struct spoolss_Time st;
860 if (!init_systemtime(&st, t)) {
864 p = talloc_array(mem_ctx, char, len);
870 * Systemtime must be linearized as a set of UINT16's.
871 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
874 SSVAL(p, 0, st.year);
875 SSVAL(p, 2, st.month);
876 SSVAL(p, 4, st.day_of_week);
878 SSVAL(p, 8, st.hour);
879 SSVAL(p, 10, st.minute);
880 SSVAL(p, 12, st.second);
881 SSVAL(p, 14, st.millisecond);
887 /* Convert a notification message to a struct spoolss_Notify */
889 static void notify_one_value(struct spoolss_notify_msg *msg,
890 struct spoolss_Notify *data,
893 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, msg->notify.value[0]);
896 static void notify_string(struct spoolss_notify_msg *msg,
897 struct spoolss_Notify *data,
900 /* The length of the message includes the trailing \0 */
902 data->data.string.size = msg->len * 2;
903 data->data.string.string = talloc_strdup(mem_ctx, msg->notify.data);
904 if (!data->data.string.string) {
905 data->data.string.size = 0;
910 static void notify_system_time(struct spoolss_notify_msg *msg,
911 struct spoolss_Notify *data,
914 data->data.string.string = NULL;
915 data->data.string.size = 0;
917 if (msg->len != sizeof(time_t)) {
918 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
923 init_systemtime_buffer(mem_ctx, gmtime((time_t *)msg->notify.data),
924 &data->data.string.string,
925 &data->data.string.size);
928 struct notify2_message_table {
930 void (*fn)(struct spoolss_notify_msg *msg,
931 struct spoolss_Notify *data, TALLOC_CTX *mem_ctx);
934 static struct notify2_message_table printer_notify_table[] = {
935 /* 0x00 */ { "PRINTER_NOTIFY_FIELD_SERVER_NAME", notify_string },
936 /* 0x01 */ { "PRINTER_NOTIFY_FIELD_PRINTER_NAME", notify_string },
937 /* 0x02 */ { "PRINTER_NOTIFY_FIELD_SHARE_NAME", notify_string },
938 /* 0x03 */ { "PRINTER_NOTIFY_FIELD_PORT_NAME", notify_string },
939 /* 0x04 */ { "PRINTER_NOTIFY_FIELD_DRIVER_NAME", notify_string },
940 /* 0x05 */ { "PRINTER_NOTIFY_FIELD_COMMENT", notify_string },
941 /* 0x06 */ { "PRINTER_NOTIFY_FIELD_LOCATION", notify_string },
942 /* 0x07 */ { "PRINTER_NOTIFY_FIELD_DEVMODE", NULL },
943 /* 0x08 */ { "PRINTER_NOTIFY_FIELD_SEPFILE", notify_string },
944 /* 0x09 */ { "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", notify_string },
945 /* 0x0a */ { "PRINTER_NOTIFY_FIELD_PARAMETERS", NULL },
946 /* 0x0b */ { "PRINTER_NOTIFY_FIELD_DATATYPE", notify_string },
947 /* 0x0c */ { "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
948 /* 0x0d */ { "PRINTER_NOTIFY_FIELD_ATTRIBUTES", notify_one_value },
949 /* 0x0e */ { "PRINTER_NOTIFY_FIELD_PRIORITY", notify_one_value },
950 /* 0x0f */ { "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NULL },
951 /* 0x10 */ { "PRINTER_NOTIFY_FIELD_START_TIME", NULL },
952 /* 0x11 */ { "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NULL },
953 /* 0x12 */ { "PRINTER_NOTIFY_FIELD_STATUS", notify_one_value },
956 static struct notify2_message_table job_notify_table[] = {
957 /* 0x00 */ { "JOB_NOTIFY_FIELD_PRINTER_NAME", NULL },
958 /* 0x01 */ { "JOB_NOTIFY_FIELD_MACHINE_NAME", NULL },
959 /* 0x02 */ { "JOB_NOTIFY_FIELD_PORT_NAME", NULL },
960 /* 0x03 */ { "JOB_NOTIFY_FIELD_USER_NAME", notify_string },
961 /* 0x04 */ { "JOB_NOTIFY_FIELD_NOTIFY_NAME", NULL },
962 /* 0x05 */ { "JOB_NOTIFY_FIELD_DATATYPE", NULL },
963 /* 0x06 */ { "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NULL },
964 /* 0x07 */ { "JOB_NOTIFY_FIELD_PARAMETERS", NULL },
965 /* 0x08 */ { "JOB_NOTIFY_FIELD_DRIVER_NAME", NULL },
966 /* 0x09 */ { "JOB_NOTIFY_FIELD_DEVMODE", NULL },
967 /* 0x0a */ { "JOB_NOTIFY_FIELD_STATUS", notify_one_value },
968 /* 0x0b */ { "JOB_NOTIFY_FIELD_STATUS_STRING", NULL },
969 /* 0x0c */ { "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NULL },
970 /* 0x0d */ { "JOB_NOTIFY_FIELD_DOCUMENT", notify_string },
971 /* 0x0e */ { "JOB_NOTIFY_FIELD_PRIORITY", NULL },
972 /* 0x0f */ { "JOB_NOTIFY_FIELD_POSITION", NULL },
973 /* 0x10 */ { "JOB_NOTIFY_FIELD_SUBMITTED", notify_system_time },
974 /* 0x11 */ { "JOB_NOTIFY_FIELD_START_TIME", NULL },
975 /* 0x12 */ { "JOB_NOTIFY_FIELD_UNTIL_TIME", NULL },
976 /* 0x13 */ { "JOB_NOTIFY_FIELD_TIME", NULL },
977 /* 0x14 */ { "JOB_NOTIFY_FIELD_TOTAL_PAGES", notify_one_value },
978 /* 0x15 */ { "JOB_NOTIFY_FIELD_PAGES_PRINTED", NULL },
979 /* 0x16 */ { "JOB_NOTIFY_FIELD_TOTAL_BYTES", notify_one_value },
980 /* 0x17 */ { "JOB_NOTIFY_FIELD_BYTES_PRINTED", NULL },
984 /***********************************************************************
985 Allocate talloc context for container object
986 **********************************************************************/
988 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR *ctr )
993 ctr->ctx = talloc_init("notify_msg_ctr_init %p", ctr);
998 /***********************************************************************
999 release all allocated memory and zero out structure
1000 **********************************************************************/
1002 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1008 talloc_destroy(ctr->ctx);
1015 /***********************************************************************
1016 **********************************************************************/
1018 static TALLOC_CTX* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1026 /***********************************************************************
1027 **********************************************************************/
1029 static SPOOLSS_NOTIFY_MSG_GROUP* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
1031 if ( !ctr || !ctr->msg_groups )
1034 if ( idx >= ctr->num_groups )
1037 return &ctr->msg_groups[idx];
1041 /***********************************************************************
1042 How many groups of change messages do we have ?
1043 **********************************************************************/
1045 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR *ctr )
1050 return ctr->num_groups;
1053 /***********************************************************************
1054 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
1055 **********************************************************************/
1057 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MSG *msg )
1059 SPOOLSS_NOTIFY_MSG_GROUP *groups = NULL;
1060 SPOOLSS_NOTIFY_MSG_GROUP *msg_grp = NULL;
1061 SPOOLSS_NOTIFY_MSG *msg_list = NULL;
1067 /* loop over all groups looking for a matching printer name */
1069 for ( i=0; i<ctr->num_groups; i++ ) {
1070 if ( strcmp(ctr->msg_groups[i].printername, msg->printer) == 0 )
1074 /* add a new group? */
1076 if ( i == ctr->num_groups ) {
1079 if ( !(groups = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->msg_groups, SPOOLSS_NOTIFY_MSG_GROUP, ctr->num_groups)) ) {
1080 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
1083 ctr->msg_groups = groups;
1085 /* clear the new entry and set the printer name */
1087 ZERO_STRUCT( ctr->msg_groups[ctr->num_groups-1] );
1088 fstrcpy( ctr->msg_groups[ctr->num_groups-1].printername, msg->printer );
1091 /* add the change messages; 'i' is the correct index now regardless */
1093 msg_grp = &ctr->msg_groups[i];
1095 msg_grp->num_msgs++;
1097 if ( !(msg_list = TALLOC_REALLOC_ARRAY( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) {
1098 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs));
1101 msg_grp->msgs = msg_list;
1103 new_slot = msg_grp->num_msgs-1;
1104 memcpy( &msg_grp->msgs[new_slot], msg, sizeof(SPOOLSS_NOTIFY_MSG) );
1106 /* need to allocate own copy of data */
1108 if ( msg->len != 0 )
1109 msg_grp->msgs[new_slot].notify.data = (char *)
1110 TALLOC_MEMDUP( ctr->ctx, msg->notify.data, msg->len );
1112 return ctr->num_groups;
1115 static void construct_info_data(struct spoolss_Notify *info_data,
1116 enum spoolss_NotifyType type,
1117 uint16_t field, int id);
1119 /***********************************************************************
1120 Send a change notication message on all handles which have a call
1122 **********************************************************************/
1124 static int build_notify2_messages(TALLOC_CTX *mem_ctx,
1125 struct printer_handle *prn_hnd,
1126 SPOOLSS_NOTIFY_MSG *messages,
1128 struct spoolss_Notify **_notifies,
1131 struct spoolss_Notify *notifies;
1132 SPOOLSS_NOTIFY_MSG *msg;
1137 notifies = talloc_zero_array(mem_ctx,
1138 struct spoolss_Notify, num_msgs);
1143 for (i = 0; i < num_msgs; i++) {
1147 /* Are we monitoring this event? */
1149 if (!is_monitoring_event(prn_hnd, msg->type, msg->field)) {
1153 DEBUG(10, ("Sending message type [0x%x] field [0x%2x] "
1154 "for printer [%s]\n",
1155 msg->type, msg->field, prn_hnd->sharename));
1158 * if the is a printer notification handle and not a job
1159 * notification type, then set the id to 0.
1160 * Otherwise just use what was specified in the message.
1162 * When registering change notification on a print server
1163 * handle we always need to send back the id (snum) matching
1164 * the printer for which the change took place.
1165 * For change notify registered on a printer handle,
1166 * this does not matter and the id should be 0.
1171 if ((msg->type == PRINTER_NOTIFY_TYPE) &&
1172 (prn_hnd->printer_type == SPLHND_PRINTER)) {
1178 /* Convert unix jobid to smb jobid */
1180 if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) {
1181 id = sysjob_to_jobid(msg->id);
1184 DEBUG(3, ("no such unix jobid %d\n",
1190 construct_info_data(¬ifies[count],
1191 msg->type, msg->field, id);
1194 case PRINTER_NOTIFY_TYPE:
1195 if (printer_notify_table[msg->field].fn) {
1196 printer_notify_table[msg->field].fn(msg,
1197 ¬ifies[count], mem_ctx);
1201 case JOB_NOTIFY_TYPE:
1202 if (job_notify_table[msg->field].fn) {
1203 job_notify_table[msg->field].fn(msg,
1204 ¬ifies[count], mem_ctx);
1209 DEBUG(5, ("Unknown notification type %d\n",
1217 *_notifies = notifies;
1223 static int send_notify2_printer(TALLOC_CTX *mem_ctx,
1224 struct printer_handle *prn_hnd,
1225 SPOOLSS_NOTIFY_MSG_GROUP *msg_group)
1227 struct spoolss_Notify *notifies;
1229 union spoolss_ReplyPrinterInfo info;
1230 struct spoolss_NotifyInfo info0;
1231 uint32_t reply_result;
1236 /* Is there notification on this handle? */
1237 if (prn_hnd->notify.cli_chan == NULL ||
1238 prn_hnd->notify.cli_chan->active_connections == 0) {
1242 DEBUG(10, ("Client connected! [\\\\%s\\%s]\n",
1243 prn_hnd->servername, prn_hnd->sharename));
1245 /* For this printer? Print servers always receive notifications. */
1246 if ((prn_hnd->printer_type == SPLHND_PRINTER) &&
1247 (!strequal(msg_group->printername, prn_hnd->sharename))) {
1251 DEBUG(10,("Our printer\n"));
1253 /* build the array of change notifications */
1254 ret = build_notify2_messages(mem_ctx, prn_hnd,
1256 msg_group->num_msgs,
1262 info0.version = 0x2;
1263 info0.flags = count ? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED;
1264 info0.count = count;
1265 info0.notifies = notifies;
1267 info.info0 = &info0;
1269 status = rpccli_spoolss_RouterReplyPrinterEx(
1270 prn_hnd->notify.cli_chan->cli_pipe,
1272 &prn_hnd->notify.cli_hnd,
1273 prn_hnd->notify.change, /* color */
1274 prn_hnd->notify.flags,
1276 0, /* reply_type, must be 0 */
1278 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(werr)) {
1279 DEBUG(1, ("RouterReplyPrinterEx to client: %s "
1281 prn_hnd->notify.cli_chan->cli_pipe->srv_name_slash,
1284 switch (reply_result) {
1287 case PRINTER_NOTIFY_INFO_DISCARDED:
1288 case PRINTER_NOTIFY_INFO_DISCARDNOTED:
1289 case PRINTER_NOTIFY_INFO_COLOR_MISMATCH:
1298 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
1300 struct printer_handle *p;
1301 TALLOC_CTX *mem_ctx = notify_ctr_getctx( ctr );
1302 SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx );
1306 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
1310 if (!msg_group->msgs) {
1311 DEBUG(5, ("send_notify2_changes() called with no messages!\n"));
1315 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername));
1317 /* loop over all printers */
1319 for (p = printers_list; p; p = p->next) {
1320 ret = send_notify2_printer(mem_ctx, p, msg_group);
1327 DEBUG(8,("send_notify2_changes: Exit...\n"));
1331 /***********************************************************************
1332 **********************************************************************/
1334 static bool notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, void *buf, size_t len )
1337 uint32_t tv_sec, tv_usec;
1340 /* Unpack message */
1342 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "f",
1345 offset += tdb_unpack((uint8_t *)buf + offset, len - offset, "ddddddd",
1347 &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags);
1350 tdb_unpack((uint8_t *)buf + offset, len - offset, "dd",
1351 &msg->notify.value[0], &msg->notify.value[1]);
1353 tdb_unpack((uint8_t *)buf + offset, len - offset, "B",
1354 &msg->len, &msg->notify.data);
1356 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1357 msg->printer, (unsigned int)msg->id, msg->type, msg->field, msg->flags));
1359 tv->tv_sec = tv_sec;
1360 tv->tv_usec = tv_usec;
1363 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg->notify.value[0],
1364 msg->notify.value[1]));
1366 dump_data(3, (uint8_t *)msg->notify.data, msg->len);
1371 /********************************************************************
1372 Receive a notify2 message list
1373 ********************************************************************/
1375 static void receive_notify2_message_list(struct messaging_context *msg,
1378 struct server_id server_id,
1381 size_t msg_count, i;
1382 char *buf = (char *)data->data;
1385 SPOOLSS_NOTIFY_MSG notify;
1386 SPOOLSS_NOTIFY_MSG_CTR messages;
1389 if (data->length < 4) {
1390 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1394 msg_count = IVAL(buf, 0);
1397 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count));
1399 if (msg_count == 0) {
1400 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1404 /* initialize the container */
1406 ZERO_STRUCT( messages );
1407 notify_msg_ctr_init( &messages );
1410 * build message groups for each printer identified
1411 * in a change_notify msg. Remember that a PCN message
1412 * includes the handle returned for the srv_spoolss_replyopenprinter()
1413 * call. Therefore messages are grouped according to printer handle.
1416 for ( i=0; i<msg_count; i++ ) {
1417 struct timeval msg_tv;
1419 if (msg_ptr + 4 - buf > data->length) {
1420 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1424 msg_len = IVAL(msg_ptr,0);
1427 if (msg_ptr + msg_len - buf > data->length) {
1428 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1432 /* unpack messages */
1434 ZERO_STRUCT( notify );
1435 notify2_unpack_msg( ¬ify, &msg_tv, msg_ptr, msg_len );
1438 /* add to correct list in container */
1440 notify_msg_ctr_addmsg( &messages, ¬ify );
1442 /* free memory that might have been allocated by notify2_unpack_msg() */
1444 if ( notify.len != 0 )
1445 SAFE_FREE( notify.notify.data );
1448 /* process each group of messages */
1450 num_groups = notify_msg_ctr_numgroups( &messages );
1451 for ( i=0; i<num_groups; i++ )
1452 send_notify2_changes( &messages, i );
1457 DEBUG(10,("receive_notify2_message_list: processed %u messages\n",
1458 (uint32_t)msg_count ));
1460 notify_msg_ctr_destroy( &messages );
1465 /********************************************************************
1466 Send a message to ourself about new driver being installed
1467 so we can upgrade the information for each printer bound to this
1469 ********************************************************************/
1471 static bool srv_spoolss_drv_upgrade_printer(const char *drivername,
1472 struct messaging_context *msg_ctx)
1474 int len = strlen(drivername);
1479 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1482 messaging_send_buf(msg_ctx, messaging_server_id(msg_ctx),
1483 MSG_PRINTER_DRVUPGRADE,
1484 (uint8_t *)drivername, len+1);
1489 void srv_spoolss_cleanup(void)
1491 struct printer_session_counter *session_counter;
1493 for (session_counter = counter_list;
1494 session_counter != NULL;
1495 session_counter = counter_list) {
1496 DLIST_REMOVE(counter_list, session_counter);
1497 TALLOC_FREE(session_counter);
1501 /**********************************************************************
1502 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1503 over all printers, upgrading ones as necessary
1504 **********************************************************************/
1506 void do_drv_upgrade_printer(struct messaging_context *msg,
1509 struct server_id server_id,
1512 TALLOC_CTX *tmp_ctx;
1513 struct auth_serversupplied_info *server_info = NULL;
1514 struct spoolss_PrinterInfo2 *pinfo2;
1517 const char *drivername;
1519 int n_services = lp_numservices();
1521 tmp_ctx = talloc_new(NULL);
1522 if (!tmp_ctx) return;
1524 status = make_server_info_system(tmp_ctx, &server_info);
1525 if (!NT_STATUS_IS_OK(status)) {
1526 DEBUG(0, ("do_drv_upgrade_printer: "
1527 "Could not create system server_info\n"));
1531 drivername = talloc_strndup(tmp_ctx, (const char *)data->data, data->length);
1533 DEBUG(0, ("do_drv_upgrade_printer: Out of memoery ?!\n"));
1537 DEBUG(10, ("do_drv_upgrade_printer: "
1538 "Got message for new driver [%s]\n", drivername));
1540 /* Iterate the printer list */
1542 for (snum = 0; snum < n_services; snum++) {
1543 if (!lp_snum_ok(snum) || !lp_print_ok(snum)) {
1547 /* ignore [printers] share */
1548 if (strequal(lp_const_servicename(snum), "printers")) {
1552 result = winreg_get_printer(tmp_ctx, server_info, msg,
1553 lp_const_servicename(snum),
1556 if (!W_ERROR_IS_OK(result)) {
1560 if (!pinfo2->drivername) {
1564 if (strcmp(drivername, pinfo2->drivername) != 0) {
1568 DEBUG(6,("Updating printer [%s]\n", pinfo2->printername));
1570 /* all we care about currently is the change_id */
1571 result = winreg_printer_update_changeid(tmp_ctx,
1574 pinfo2->printername);
1576 if (!W_ERROR_IS_OK(result)) {
1577 DEBUG(3, ("do_drv_upgrade_printer: "
1578 "Failed to update changeid [%s]\n",
1579 win_errstr(result)));
1585 talloc_free(tmp_ctx);
1588 /********************************************************************
1589 Update the cache for all printq's with a registered client
1591 ********************************************************************/
1593 void update_monitored_printq_cache(struct messaging_context *msg_ctx)
1595 struct printer_handle *printer = printers_list;
1598 /* loop through all printers and update the cache where
1599 a client is connected */
1601 if ((printer->printer_type == SPLHND_PRINTER) &&
1602 ((printer->notify.cli_chan != NULL) &&
1603 (printer->notify.cli_chan->active_connections > 0))) {
1604 snum = print_queue_snum(printer->sharename);
1605 print_queue_status(msg_ctx, snum, NULL, NULL);
1608 printer = printer->next;
1614 /****************************************************************
1615 _spoolss_OpenPrinter
1616 ****************************************************************/
1618 WERROR _spoolss_OpenPrinter(struct pipes_struct *p,
1619 struct spoolss_OpenPrinter *r)
1621 struct spoolss_OpenPrinterEx e;
1624 ZERO_STRUCT(e.in.userlevel);
1626 e.in.printername = r->in.printername;
1627 e.in.datatype = r->in.datatype;
1628 e.in.devmode_ctr = r->in.devmode_ctr;
1629 e.in.access_mask = r->in.access_mask;
1632 e.out.handle = r->out.handle;
1634 werr = _spoolss_OpenPrinterEx(p, &e);
1636 if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
1637 /* OpenPrinterEx returns this for a bad
1638 * printer name. We must return WERR_INVALID_PRINTER_NAME
1641 werr = WERR_INVALID_PRINTER_NAME;
1647 static WERROR copy_devicemode(TALLOC_CTX *mem_ctx,
1648 struct spoolss_DeviceMode *orig,
1649 struct spoolss_DeviceMode **dest)
1651 struct spoolss_DeviceMode *dm;
1653 dm = talloc(mem_ctx, struct spoolss_DeviceMode);
1658 /* copy all values, then duplicate strings and structs */
1661 dm->devicename = talloc_strdup(dm, orig->devicename);
1662 if (!dm->devicename) {
1665 dm->formname = talloc_strdup(dm, orig->formname);
1666 if (!dm->formname) {
1669 if (orig->driverextra_data.data) {
1670 dm->driverextra_data.data =
1671 (uint8_t *) talloc_memdup(dm, orig->driverextra_data.data,
1672 orig->driverextra_data.length);
1673 if (!dm->driverextra_data.data) {
1682 /****************************************************************
1683 _spoolss_OpenPrinterEx
1684 ****************************************************************/
1686 WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
1687 struct spoolss_OpenPrinterEx *r)
1690 struct printer_handle *Printer=NULL;
1693 if (!r->in.printername) {
1694 return WERR_INVALID_PARAM;
1697 if (r->in.level < 0 || r->in.level > 3) {
1698 return WERR_INVALID_PARAM;
1700 if ((r->in.level == 1 && !r->in.userlevel.level1) ||
1701 (r->in.level == 2 && !r->in.userlevel.level2) ||
1702 (r->in.level == 3 && !r->in.userlevel.level3)) {
1703 return WERR_INVALID_PARAM;
1706 /* some sanity check because you can open a printer or a print server */
1707 /* aka: \\server\printer or \\server */
1709 DEBUGADD(3,("checking name: %s\n", r->in.printername));
1711 result = open_printer_hnd(p, r->out.handle, r->in.printername, 0);
1712 if (!W_ERROR_IS_OK(result)) {
1713 DEBUG(0,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
1714 "for printer %s\n", r->in.printername));
1715 ZERO_STRUCTP(r->out.handle);
1719 Printer = find_printer_index_by_hnd(p, r->out.handle);
1721 DEBUG(0,("_spoolss_OpenPrinterEx: logic error. Can't find printer "
1722 "handle we created for printer %s\n", r->in.printername));
1723 close_printer_handle(p, r->out.handle);
1724 ZERO_STRUCTP(r->out.handle);
1725 return WERR_INVALID_PARAM;
1729 * First case: the user is opening the print server:
1731 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1732 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1734 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1735 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1736 * or if the user is listed in the smb.conf printer admin parameter.
1738 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1739 * client view printer folder, but does not show the MSAPW.
1741 * Note: this test needs code to check access rights here too. Jeremy
1742 * could you look at this?
1744 * Second case: the user is opening a printer:
1745 * NT doesn't let us connect to a printer if the connecting user
1746 * doesn't have print permission.
1748 * Third case: user is opening a Port Monitor
1749 * access checks same as opening a handle to the print server.
1752 switch (Printer->printer_type )
1755 case SPLHND_PORTMON_TCP:
1756 case SPLHND_PORTMON_LOCAL:
1757 /* Printserver handles use global struct... */
1761 /* Map standard access rights to object specific access rights */
1763 se_map_standard(&r->in.access_mask,
1764 &printserver_std_mapping);
1766 /* Deny any object specific bits that don't apply to print
1767 servers (i.e printer and job specific bits) */
1769 r->in.access_mask &= SEC_MASK_SPECIFIC;
1771 if (r->in.access_mask &
1772 ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) {
1773 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1774 close_printer_handle(p, r->out.handle);
1775 ZERO_STRUCTP(r->out.handle);
1776 return WERR_ACCESS_DENIED;
1779 /* Allow admin access */
1781 if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
1783 if (!lp_ms_add_printer_wizard()) {
1784 close_printer_handle(p, r->out.handle);
1785 ZERO_STRUCTP(r->out.handle);
1786 return WERR_ACCESS_DENIED;
1789 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1790 and not a printer admin, then fail */
1792 if ((p->server_info->utok.uid != sec_initial_uid()) &&
1793 !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR) &&
1794 !token_contains_name_in_list(
1795 uidtoname(p->server_info->utok.uid),
1796 p->server_info->info3->base.domain.string,
1798 p->server_info->ptok,
1799 lp_printer_admin(snum))) {
1800 close_printer_handle(p, r->out.handle);
1801 ZERO_STRUCTP(r->out.handle);
1802 return WERR_ACCESS_DENIED;
1805 r->in.access_mask = SERVER_ACCESS_ADMINISTER;
1809 r->in.access_mask = SERVER_ACCESS_ENUMERATE;
1812 DEBUG(4,("Setting print server access = %s\n", (r->in.access_mask == SERVER_ACCESS_ADMINISTER)
1813 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1815 /* We fall through to return WERR_OK */
1818 case SPLHND_PRINTER:
1819 /* NT doesn't let us connect to a printer if the connecting user
1820 doesn't have print permission. */
1822 if (!get_printer_snum(p, r->out.handle, &snum, NULL)) {
1823 close_printer_handle(p, r->out.handle);
1824 ZERO_STRUCTP(r->out.handle);
1828 if (r->in.access_mask == SEC_FLAG_MAXIMUM_ALLOWED) {
1829 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1832 se_map_standard(&r->in.access_mask, &printer_std_mapping);
1834 /* map an empty access mask to the minimum access mask */
1835 if (r->in.access_mask == 0x0)
1836 r->in.access_mask = PRINTER_ACCESS_USE;
1839 * If we are not serving the printer driver for this printer,
1840 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1841 * will keep NT clients happy --jerry
1844 if (lp_use_client_driver(snum)
1845 && (r->in.access_mask & PRINTER_ACCESS_ADMINISTER))
1847 r->in.access_mask = PRINTER_ACCESS_USE;
1850 /* check smb.conf parameters and the the sec_desc */
1852 if (!allow_access(lp_hostsdeny(snum), lp_hostsallow(snum),
1853 p->client_id->name, p->client_id->addr)) {
1854 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1855 ZERO_STRUCTP(r->out.handle);
1856 return WERR_ACCESS_DENIED;
1859 if (!user_ok_token(uidtoname(p->server_info->utok.uid), NULL,
1860 p->server_info->ptok, snum) ||
1861 !print_access_check(p->server_info,
1864 r->in.access_mask)) {
1865 DEBUG(3, ("access DENIED for printer open\n"));
1866 close_printer_handle(p, r->out.handle);
1867 ZERO_STRUCTP(r->out.handle);
1868 return WERR_ACCESS_DENIED;
1871 if ((r->in.access_mask & SEC_MASK_SPECIFIC)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) {
1872 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1873 close_printer_handle(p, r->out.handle);
1874 ZERO_STRUCTP(r->out.handle);
1875 return WERR_ACCESS_DENIED;
1878 if (r->in.access_mask & PRINTER_ACCESS_ADMINISTER)
1879 r->in.access_mask = PRINTER_ACCESS_ADMINISTER;
1881 r->in.access_mask = PRINTER_ACCESS_USE;
1883 DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1884 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1886 winreg_create_printer(p->mem_ctx,
1887 get_server_info_system(),
1889 lp_const_servicename(snum));
1894 /* sanity check to prevent programmer error */
1895 ZERO_STRUCTP(r->out.handle);
1899 Printer->access_granted = r->in.access_mask;
1902 * If the client sent a devmode in the OpenPrinter() call, then
1903 * save it here in case we get a job submission on this handle
1906 if ((Printer->printer_type != SPLHND_SERVER) &&
1907 r->in.devmode_ctr.devmode) {
1908 copy_devicemode(NULL, r->in.devmode_ctr.devmode,
1912 #if 0 /* JERRY -- I'm doubtful this is really effective */
1913 /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
1914 optimization in Windows 2000 clients --jerry */
1916 if ( (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
1917 && (RA_WIN2K == get_remote_arch()) )
1919 DEBUG(10,("_spoolss_OpenPrinterEx: Enabling LAN/WAN hack for Win2k clients.\n"));
1920 sys_usleep( 500000 );
1927 /****************************************************************
1928 _spoolss_ClosePrinter
1929 ****************************************************************/
1931 WERROR _spoolss_ClosePrinter(struct pipes_struct *p,
1932 struct spoolss_ClosePrinter *r)
1934 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
1936 if (Printer && Printer->document_started) {
1937 struct spoolss_EndDocPrinter e;
1939 e.in.handle = r->in.handle;
1941 _spoolss_EndDocPrinter(p, &e);
1944 if (!close_printer_handle(p, r->in.handle))
1947 /* clear the returned printer handle. Observed behavior
1948 from Win2k server. Don't think this really matters.
1949 Previous code just copied the value of the closed
1952 ZERO_STRUCTP(r->out.handle);
1957 /****************************************************************
1958 _spoolss_DeletePrinter
1959 ****************************************************************/
1961 WERROR _spoolss_DeletePrinter(struct pipes_struct *p,
1962 struct spoolss_DeletePrinter *r)
1964 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
1968 if (Printer && Printer->document_started) {
1969 struct spoolss_EndDocPrinter e;
1971 e.in.handle = r->in.handle;
1973 _spoolss_EndDocPrinter(p, &e);
1976 if (get_printer_snum(p, r->in.handle, &snum, NULL)) {
1977 winreg_delete_printer_key(p->mem_ctx,
1978 get_server_info_system(),
1980 lp_const_servicename(snum),
1984 result = delete_printer_handle(p, r->in.handle);
1989 /*******************************************************************
1990 * static function to lookup the version id corresponding to an
1991 * long architecture string
1992 ******************************************************************/
1994 static const struct print_architecture_table_node archi_table[]= {
1996 {"Windows 4.0", SPL_ARCH_WIN40, 0 },
1997 {"Windows NT x86", SPL_ARCH_W32X86, 2 },
1998 {"Windows NT R4000", SPL_ARCH_W32MIPS, 2 },
1999 {"Windows NT Alpha_AXP", SPL_ARCH_W32ALPHA, 2 },
2000 {"Windows NT PowerPC", SPL_ARCH_W32PPC, 2 },
2001 {"Windows IA64", SPL_ARCH_IA64, 3 },
2002 {"Windows x64", SPL_ARCH_X64, 3 },
2006 static int get_version_id(const char *arch)
2010 for (i=0; archi_table[i].long_archi != NULL; i++)
2012 if (strcmp(arch, archi_table[i].long_archi) == 0)
2013 return (archi_table[i].version);
2019 /****************************************************************
2020 _spoolss_DeletePrinterDriver
2021 ****************************************************************/
2023 WERROR _spoolss_DeletePrinterDriver(struct pipes_struct *p,
2024 struct spoolss_DeletePrinterDriver *r)
2027 struct spoolss_DriverInfo8 *info = NULL;
2028 struct spoolss_DriverInfo8 *info_win2k = NULL;
2032 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2033 and not a printer admin, then fail */
2035 if ( (p->server_info->utok.uid != sec_initial_uid())
2036 && !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR)
2037 && !token_contains_name_in_list(
2038 uidtoname(p->server_info->utok.uid),
2039 p->server_info->info3->base.domain.string,
2041 p->server_info->ptok,
2042 lp_printer_admin(-1)) )
2044 return WERR_ACCESS_DENIED;
2047 /* check that we have a valid driver name first */
2049 if ((version = get_version_id(r->in.architecture)) == -1)
2050 return WERR_INVALID_ENVIRONMENT;
2052 status = winreg_get_driver(p->mem_ctx,
2053 get_server_info_system(),
2055 r->in.architecture, r->in.driver,
2057 if (!W_ERROR_IS_OK(status)) {
2058 /* try for Win2k driver if "Windows NT x86" */
2060 if ( version == 2 ) {
2063 status = winreg_get_driver(p->mem_ctx,
2064 get_server_info_system(),
2069 if (!W_ERROR_IS_OK(status)) {
2070 status = WERR_UNKNOWN_PRINTER_DRIVER;
2074 /* otherwise it was a failure */
2076 status = WERR_UNKNOWN_PRINTER_DRIVER;
2082 if (printer_driver_in_use(p->mem_ctx,
2083 get_server_info_system(),
2086 status = WERR_PRINTER_DRIVER_IN_USE;
2091 status = winreg_get_driver(p->mem_ctx,
2092 get_server_info_system(),
2095 r->in.driver, 3, &info_win2k);
2096 if (W_ERROR_IS_OK(status)) {
2097 /* if we get to here, we now have 2 driver info structures to remove */
2098 /* remove the Win2k driver first*/
2100 status = winreg_del_driver(p->mem_ctx,
2101 get_server_info_system(),
2104 talloc_free(info_win2k);
2106 /* this should not have failed---if it did, report to client */
2107 if (!W_ERROR_IS_OK(status)) {
2113 status = winreg_del_driver(p->mem_ctx,
2114 get_server_info_system(),
2124 /****************************************************************
2125 _spoolss_DeletePrinterDriverEx
2126 ****************************************************************/
2128 WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
2129 struct spoolss_DeletePrinterDriverEx *r)
2131 struct spoolss_DriverInfo8 *info = NULL;
2132 struct spoolss_DriverInfo8 *info_win2k = NULL;
2137 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2138 and not a printer admin, then fail */
2140 if ( (p->server_info->utok.uid != sec_initial_uid())
2141 && !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR)
2142 && !token_contains_name_in_list(
2143 uidtoname(p->server_info->utok.uid),
2144 p->server_info->info3->base.domain.string,
2146 p->server_info->ptok, lp_printer_admin(-1)) )
2148 return WERR_ACCESS_DENIED;
2151 /* check that we have a valid driver name first */
2152 if ((version = get_version_id(r->in.architecture)) == -1) {
2153 /* this is what NT returns */
2154 return WERR_INVALID_ENVIRONMENT;
2157 if (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION)
2158 version = r->in.version;
2160 status = winreg_get_driver(p->mem_ctx,
2161 get_server_info_system(),
2167 if (!W_ERROR_IS_OK(status)) {
2168 status = WERR_UNKNOWN_PRINTER_DRIVER;
2171 * if the client asked for a specific version,
2172 * or this is something other than Windows NT x86,
2176 if ( (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) || (version !=2) )
2179 /* try for Win2k driver if "Windows NT x86" */
2182 status = winreg_get_driver(info,
2183 get_server_info_system(),
2188 if (!W_ERROR_IS_OK(status)) {
2189 status = WERR_UNKNOWN_PRINTER_DRIVER;
2194 if (printer_driver_in_use(info,
2195 get_server_info_system(),
2198 status = WERR_PRINTER_DRIVER_IN_USE;
2203 * we have a couple of cases to consider.
2204 * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set,
2205 * then the delete should fail if **any** files overlap with
2207 * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
2208 * non-overlapping files
2209 * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
2210 * is set, the do not delete any files
2211 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
2214 delete_files = r->in.delete_flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES);
2216 /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
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 status = WERR_ACCESS_DENIED;
2230 /* also check for W32X86/3 if necessary; maybe we already have? */
2232 if ( (version == 2) && ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION) ) {
2233 status = winreg_get_driver(info,
2234 get_server_info_system(),
2237 r->in.driver, 3, &info_win2k);
2238 if (W_ERROR_IS_OK(status)) {
2241 (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
2242 printer_driver_files_in_use(info,
2243 get_server_info_system(),
2246 /* no idea of the correct error here */
2247 talloc_free(info_win2k);
2248 status = WERR_ACCESS_DENIED;
2252 /* if we get to here, we now have 2 driver info structures to remove */
2253 /* remove the Win2k driver first*/
2255 status = winreg_del_driver(info,
2256 get_server_info_system(),
2261 /* this should not have failed---if it did, report to client */
2263 if (!W_ERROR_IS_OK(status)) {
2268 * now delete any associated files if delete_files is
2269 * true. Even if this part failes, we return succes
2270 * because the driver doesn not exist any more
2273 delete_driver_files(get_server_info_system(),
2279 status = winreg_del_driver(info,
2280 get_server_info_system(),
2284 if (!W_ERROR_IS_OK(status)) {
2289 * now delete any associated files if delete_files is
2290 * true. Even if this part failes, we return succes
2291 * because the driver doesn not exist any more
2294 delete_driver_files(get_server_info_system(), info);
2303 /********************************************************************
2304 GetPrinterData on a printer server Handle.
2305 ********************************************************************/
2307 static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
2309 enum winreg_Type *type,
2310 union spoolss_PrinterData *data)
2312 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2314 if (!StrCaseCmp(value, "W3SvcInstalled")) {
2320 if (!StrCaseCmp(value, "BeepEnabled")) {
2326 if (!StrCaseCmp(value, "EventLog")) {
2328 /* formally was 0x1b */
2333 if (!StrCaseCmp(value, "NetPopup")) {
2339 if (!StrCaseCmp(value, "MajorVersion")) {
2342 /* Windows NT 4.0 seems to not allow uploading of drivers
2343 to a server that reports 0x3 as the MajorVersion.
2344 need to investigate more how Win2k gets around this .
2347 if (RA_WINNT == get_remote_arch()) {
2356 if (!StrCaseCmp(value, "MinorVersion")) {
2363 * uint32_t size = 0x114
2364 * uint32_t major = 5
2365 * uint32_t minor = [0|1]
2366 * uint32_t build = [2195|2600]
2367 * extra unicode string = e.g. "Service Pack 3"
2369 if (!StrCaseCmp(value, "OSVersion")) {
2371 enum ndr_err_code ndr_err;
2372 struct spoolss_OSVersion os;
2374 os.major = 5; /* Windows 2000 == 5.0 */
2376 os.build = 2195; /* build */
2377 os.extra_string = ""; /* leave extra string empty */
2379 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &os,
2380 (ndr_push_flags_fn_t)ndr_push_spoolss_OSVersion);
2381 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2382 return WERR_GENERAL_FAILURE;
2386 data->binary = blob;
2392 if (!StrCaseCmp(value, "DefaultSpoolDirectory")) {
2395 data->string = talloc_strdup(mem_ctx, "C:\\PRINTERS");
2396 W_ERROR_HAVE_NO_MEMORY(data->string);
2401 if (!StrCaseCmp(value, "Architecture")) {
2403 data->string = talloc_strdup(mem_ctx,
2404 lp_parm_const_string(GLOBAL_SECTION_SNUM, "spoolss", "architecture", SPOOLSS_ARCHITECTURE_NT_X86));
2405 W_ERROR_HAVE_NO_MEMORY(data->string);
2410 if (!StrCaseCmp(value, "DsPresent")) {
2413 /* only show the publish check box if we are a
2414 member of a AD domain */
2416 if (lp_security() == SEC_ADS) {
2424 if (!StrCaseCmp(value, "DNSMachineName")) {
2425 const char *hostname = get_mydnsfullname();
2428 return WERR_BADFILE;
2432 data->string = talloc_strdup(mem_ctx, hostname);
2433 W_ERROR_HAVE_NO_MEMORY(data->string);
2440 return WERR_INVALID_PARAM;
2443 /****************************************************************
2444 _spoolss_GetPrinterData
2445 ****************************************************************/
2447 WERROR _spoolss_GetPrinterData(struct pipes_struct *p,
2448 struct spoolss_GetPrinterData *r)
2450 struct spoolss_GetPrinterDataEx r2;
2452 r2.in.handle = r->in.handle;
2453 r2.in.key_name = "PrinterDriverData";
2454 r2.in.value_name = r->in.value_name;
2455 r2.in.offered = r->in.offered;
2456 r2.out.type = r->out.type;
2457 r2.out.data = r->out.data;
2458 r2.out.needed = r->out.needed;
2460 return _spoolss_GetPrinterDataEx(p, &r2);
2463 /*********************************************************
2464 Connect to the client machine.
2465 **********************************************************/
2467 static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
2468 struct sockaddr_storage *client_ss, const char *remote_machine)
2471 struct cli_state *the_cli;
2472 struct sockaddr_storage rm_addr;
2473 char addr[INET6_ADDRSTRLEN];
2475 if ( is_zero_addr((struct sockaddr *)client_ss) ) {
2476 DEBUG(2,("spoolss_connect_to_client: resolving %s\n",
2478 if ( !resolve_name( remote_machine, &rm_addr, 0x20, false) ) {
2479 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2482 print_sockaddr(addr, sizeof(addr), &rm_addr);
2484 rm_addr = *client_ss;
2485 print_sockaddr(addr, sizeof(addr), &rm_addr);
2486 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2490 if (ismyaddr((struct sockaddr *)(void *)&rm_addr)) {
2491 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
2496 /* setup the connection */
2497 ret = cli_full_connection( &the_cli, global_myname(), remote_machine,
2498 &rm_addr, 0, "IPC$", "IPC",
2502 0, lp_client_signing(), NULL );
2504 if ( !NT_STATUS_IS_OK( ret ) ) {
2505 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2510 if ( the_cli->protocol != PROTOCOL_NT1 ) {
2511 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2512 cli_shutdown(the_cli);
2517 * Ok - we have an anonymous connection to the IPC$ share.
2518 * Now start the NT Domain stuff :-).
2521 ret = cli_rpc_pipe_open_noauth(the_cli, &ndr_table_spoolss.syntax_id, pp_pipe);
2522 if (!NT_STATUS_IS_OK(ret)) {
2523 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2524 remote_machine, nt_errstr(ret)));
2525 cli_shutdown(the_cli);
2532 /***************************************************************************
2533 Connect to the client.
2534 ****************************************************************************/
2536 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
2537 uint32_t localprinter,
2538 enum winreg_Type type,
2539 struct policy_handle *handle,
2540 struct notify_back_channel **_chan,
2541 struct sockaddr_storage *client_ss,
2542 struct messaging_context *msg_ctx)
2546 struct notify_back_channel *chan;
2548 for (chan = back_channels; chan; chan = chan->next) {
2549 if (memcmp(&chan->client_address, client_ss,
2550 sizeof(struct sockaddr_storage)) == 0) {
2556 * If it's the first connection, contact the client
2557 * and connect to the IPC$ share anonymously
2560 fstring unix_printer;
2562 /* the +2 is to strip the leading 2 backslashs */
2563 fstrcpy(unix_printer, printer + 2);
2565 chan = talloc_zero(back_channels, struct notify_back_channel);
2569 chan->client_address = *client_ss;
2571 if (!spoolss_connect_to_client(&chan->cli_pipe, client_ss, unix_printer)) {
2576 DLIST_ADD(back_channels, chan);
2578 messaging_register(msg_ctx, NULL, MSG_PRINTER_NOTIFY2,
2579 receive_notify2_message_list);
2580 /* Tell the connections db we're now interested in printer
2581 * notify messages. */
2582 serverid_register_msg_flags(messaging_server_id(msg_ctx),
2583 true, FLAG_MSG_PRINT_NOTIFY);
2587 * Tell the specific printing tdb we want messages for this printer
2588 * by registering our PID.
2591 if (!print_notify_register_pid(snum)) {
2592 DEBUG(0, ("Failed to register our pid for printer %s\n",
2596 status = rpccli_spoolss_ReplyOpenPrinter(chan->cli_pipe, talloc_tos(),
2604 if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
2605 DEBUG(5, ("Client RPC returned [%s]\n", win_errstr(result)));
2608 chan->active_connections++;
2611 return (W_ERROR_IS_OK(result));
2614 /****************************************************************
2615 ****************************************************************/
2617 static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx,
2618 const struct spoolss_NotifyOption *r)
2620 struct spoolss_NotifyOption *option;
2627 option = talloc_zero(mem_ctx, struct spoolss_NotifyOption);
2634 if (!option->count) {
2638 option->types = talloc_zero_array(option,
2639 struct spoolss_NotifyOptionType, option->count);
2640 if (!option->types) {
2641 talloc_free(option);
2645 for (i=0; i < option->count; i++) {
2646 option->types[i] = r->types[i];
2648 if (option->types[i].count) {
2649 option->types[i].fields = talloc_zero_array(option,
2650 union spoolss_Field, option->types[i].count);
2651 if (!option->types[i].fields) {
2652 talloc_free(option);
2655 for (k=0; k<option->types[i].count; k++) {
2656 option->types[i].fields[k] =
2657 r->types[i].fields[k];
2665 /****************************************************************
2666 * _spoolss_RemoteFindFirstPrinterChangeNotifyEx
2668 * before replying OK: status=0 a rpc call is made to the workstation
2669 * asking ReplyOpenPrinter
2671 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2672 * called from api_spoolss_rffpcnex
2673 ****************************************************************/
2675 WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct *p,
2676 struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
2679 struct spoolss_NotifyOption *option = r->in.notify_options;
2680 struct sockaddr_storage client_ss;
2682 /* store the notify value in the printer struct */
2684 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
2687 DEBUG(2,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2688 "Invalid handle (%s:%u:%u).\n",
2689 OUR_HANDLE(r->in.handle)));
2693 Printer->notify.flags = r->in.flags;
2694 Printer->notify.options = r->in.options;
2695 Printer->notify.printerlocal = r->in.printer_local;
2696 Printer->notify.msg_ctx = p->msg_ctx;
2698 TALLOC_FREE(Printer->notify.option);
2699 Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
2701 fstrcpy(Printer->notify.localmachine, r->in.local_machine);
2703 /* Connect to the client machine and send a ReplyOpenPrinter */
2705 if ( Printer->printer_type == SPLHND_SERVER)
2707 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2708 !get_printer_snum(p, r->in.handle, &snum, NULL) )
2711 DEBUG(10,("_spoolss_RemoteFindFirstPrinterChangeNotifyEx: "
2712 "client_address is %s\n", p->client_id->addr));
2714 if (!interpret_string_addr(&client_ss, p->client_id->addr,
2716 return WERR_SERVER_UNAVAILABLE;
2719 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2720 Printer->notify.printerlocal, REG_SZ,
2721 &Printer->notify.cli_hnd,
2722 &Printer->notify.cli_chan,
2723 &client_ss, p->msg_ctx)) {
2724 return WERR_SERVER_UNAVAILABLE;
2730 /*******************************************************************
2731 * fill a notify_info_data with the servername
2732 ********************************************************************/
2734 static void spoolss_notify_server_name(struct messaging_context *msg_ctx,
2736 struct spoolss_Notify *data,
2737 print_queue_struct *queue,
2738 struct spoolss_PrinterInfo2 *pinfo2,
2739 TALLOC_CTX *mem_ctx)
2741 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->servername);
2744 /*******************************************************************
2745 * fill a notify_info_data with the printername (not including the servername).
2746 ********************************************************************/
2748 static void spoolss_notify_printer_name(struct messaging_context *msg_ctx,
2750 struct spoolss_Notify *data,
2751 print_queue_struct *queue,
2752 struct spoolss_PrinterInfo2 *pinfo2,
2753 TALLOC_CTX *mem_ctx)
2755 /* the notify name should not contain the \\server\ part */
2756 const char *p = strrchr(pinfo2->printername, '\\');
2759 p = pinfo2->printername;
2764 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2767 /*******************************************************************
2768 * fill a notify_info_data with the servicename
2769 ********************************************************************/
2771 static void spoolss_notify_share_name(struct messaging_context *msg_ctx,
2773 struct spoolss_Notify *data,
2774 print_queue_struct *queue,
2775 struct spoolss_PrinterInfo2 *pinfo2,
2776 TALLOC_CTX *mem_ctx)
2778 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(snum));
2781 /*******************************************************************
2782 * fill a notify_info_data with the port name
2783 ********************************************************************/
2785 static void spoolss_notify_port_name(struct messaging_context *msg_ctx,
2787 struct spoolss_Notify *data,
2788 print_queue_struct *queue,
2789 struct spoolss_PrinterInfo2 *pinfo2,
2790 TALLOC_CTX *mem_ctx)
2792 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->portname);
2795 /*******************************************************************
2796 * fill a notify_info_data with the printername
2797 * but it doesn't exist, have to see what to do
2798 ********************************************************************/
2800 static void spoolss_notify_driver_name(struct messaging_context *msg_ctx,
2802 struct spoolss_Notify *data,
2803 print_queue_struct *queue,
2804 struct spoolss_PrinterInfo2 *pinfo2,
2805 TALLOC_CTX *mem_ctx)
2807 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->drivername);
2810 /*******************************************************************
2811 * fill a notify_info_data with the comment
2812 ********************************************************************/
2814 static void spoolss_notify_comment(struct messaging_context *msg_ctx,
2816 struct spoolss_Notify *data,
2817 print_queue_struct *queue,
2818 struct spoolss_PrinterInfo2 *pinfo2,
2819 TALLOC_CTX *mem_ctx)
2823 if (*pinfo2->comment == '\0') {
2824 p = lp_comment(snum);
2826 p = pinfo2->comment;
2829 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
2832 /*******************************************************************
2833 * fill a notify_info_data with the comment
2834 * location = "Room 1, floor 2, building 3"
2835 ********************************************************************/
2837 static void spoolss_notify_location(struct messaging_context *msg_ctx,
2839 struct spoolss_Notify *data,
2840 print_queue_struct *queue,
2841 struct spoolss_PrinterInfo2 *pinfo2,
2842 TALLOC_CTX *mem_ctx)
2844 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->location);
2847 /*******************************************************************
2848 * fill a notify_info_data with the device mode
2849 * jfm:xxxx don't to it for know but that's a real problem !!!
2850 ********************************************************************/
2852 static void spoolss_notify_devmode(struct messaging_context *msg_ctx,
2854 struct spoolss_Notify *data,
2855 print_queue_struct *queue,
2856 struct spoolss_PrinterInfo2 *pinfo2,
2857 TALLOC_CTX *mem_ctx)
2859 /* for a dummy implementation we have to zero the fields */
2860 SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(data, NULL);
2863 /*******************************************************************
2864 * fill a notify_info_data with the separator file name
2865 ********************************************************************/
2867 static void spoolss_notify_sepfile(struct messaging_context *msg_ctx,
2869 struct spoolss_Notify *data,
2870 print_queue_struct *queue,
2871 struct spoolss_PrinterInfo2 *pinfo2,
2872 TALLOC_CTX *mem_ctx)
2874 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->sepfile);
2877 /*******************************************************************
2878 * fill a notify_info_data with the print processor
2879 * jfm:xxxx return always winprint to indicate we don't do anything to it
2880 ********************************************************************/
2882 static void spoolss_notify_print_processor(struct messaging_context *msg_ctx,
2884 struct spoolss_Notify *data,
2885 print_queue_struct *queue,
2886 struct spoolss_PrinterInfo2 *pinfo2,
2887 TALLOC_CTX *mem_ctx)
2889 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->printprocessor);
2892 /*******************************************************************
2893 * fill a notify_info_data with the print processor options
2894 * jfm:xxxx send an empty string
2895 ********************************************************************/
2897 static void spoolss_notify_parameters(struct messaging_context *msg_ctx,
2899 struct spoolss_Notify *data,
2900 print_queue_struct *queue,
2901 struct spoolss_PrinterInfo2 *pinfo2,
2902 TALLOC_CTX *mem_ctx)
2904 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->parameters);
2907 /*******************************************************************
2908 * fill a notify_info_data with the data type
2909 * jfm:xxxx always send RAW as data type
2910 ********************************************************************/
2912 static void spoolss_notify_datatype(struct messaging_context *msg_ctx,
2914 struct spoolss_Notify *data,
2915 print_queue_struct *queue,
2916 struct spoolss_PrinterInfo2 *pinfo2,
2917 TALLOC_CTX *mem_ctx)
2919 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->datatype);
2922 /*******************************************************************
2923 * fill a notify_info_data with the security descriptor
2924 * jfm:xxxx send an null pointer to say no security desc
2925 * have to implement security before !
2926 ********************************************************************/
2928 static void spoolss_notify_security_desc(struct messaging_context *msg_ctx,
2930 struct spoolss_Notify *data,
2931 print_queue_struct *queue,
2932 struct spoolss_PrinterInfo2 *pinfo2,
2933 TALLOC_CTX *mem_ctx)
2935 SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data, pinfo2->secdesc);
2938 /*******************************************************************
2939 * fill a notify_info_data with the attributes
2940 * jfm:xxxx a samba printer is always shared
2941 ********************************************************************/
2943 static void spoolss_notify_attributes(struct messaging_context *msg_ctx,
2945 struct spoolss_Notify *data,
2946 print_queue_struct *queue,
2947 struct spoolss_PrinterInfo2 *pinfo2,
2948 TALLOC_CTX *mem_ctx)
2950 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->attributes);
2953 /*******************************************************************
2954 * fill a notify_info_data with the priority
2955 ********************************************************************/
2957 static void spoolss_notify_priority(struct messaging_context *msg_ctx,
2959 struct spoolss_Notify *data,
2960 print_queue_struct *queue,
2961 struct spoolss_PrinterInfo2 *pinfo2,
2962 TALLOC_CTX *mem_ctx)
2964 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->priority);
2967 /*******************************************************************
2968 * fill a notify_info_data with the default priority
2969 ********************************************************************/
2971 static void spoolss_notify_default_priority(struct messaging_context *msg_ctx,
2973 struct spoolss_Notify *data,
2974 print_queue_struct *queue,
2975 struct spoolss_PrinterInfo2 *pinfo2,
2976 TALLOC_CTX *mem_ctx)
2978 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->defaultpriority);
2981 /*******************************************************************
2982 * fill a notify_info_data with the start time
2983 ********************************************************************/
2985 static void spoolss_notify_start_time(struct messaging_context *msg_ctx,
2987 struct spoolss_Notify *data,
2988 print_queue_struct *queue,
2989 struct spoolss_PrinterInfo2 *pinfo2,
2990 TALLOC_CTX *mem_ctx)
2992 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->starttime);
2995 /*******************************************************************
2996 * fill a notify_info_data with the until time
2997 ********************************************************************/
2999 static void spoolss_notify_until_time(struct messaging_context *msg_ctx,
3001 struct spoolss_Notify *data,
3002 print_queue_struct *queue,
3003 struct spoolss_PrinterInfo2 *pinfo2,
3004 TALLOC_CTX *mem_ctx)
3006 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->untiltime);
3009 /*******************************************************************
3010 * fill a notify_info_data with the status
3011 ********************************************************************/
3013 static void spoolss_notify_status(struct messaging_context *msg_ctx,
3015 struct spoolss_Notify *data,
3016 print_queue_struct *queue,
3017 struct spoolss_PrinterInfo2 *pinfo2,
3018 TALLOC_CTX *mem_ctx)
3020 print_status_struct status;
3022 print_queue_length(msg_ctx, snum, &status);
3023 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
3026 /*******************************************************************
3027 * fill a notify_info_data with the number of jobs queued
3028 ********************************************************************/
3030 static void spoolss_notify_cjobs(struct messaging_context *msg_ctx,
3032 struct spoolss_Notify *data,
3033 print_queue_struct *queue,
3034 struct spoolss_PrinterInfo2 *pinfo2,
3035 TALLOC_CTX *mem_ctx)
3037 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(
3038 data, print_queue_length(msg_ctx, snum, NULL));
3041 /*******************************************************************
3042 * fill a notify_info_data with the average ppm
3043 ********************************************************************/
3045 static void spoolss_notify_average_ppm(struct messaging_context *msg_ctx,
3047 struct spoolss_Notify *data,
3048 print_queue_struct *queue,
3049 struct spoolss_PrinterInfo2 *pinfo2,
3050 TALLOC_CTX *mem_ctx)
3052 /* always respond 8 pages per minutes */
3053 /* a little hard ! */
3054 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->averageppm);
3057 /*******************************************************************
3058 * fill a notify_info_data with username
3059 ********************************************************************/
3061 static void spoolss_notify_username(struct messaging_context *msg_ctx,
3063 struct spoolss_Notify *data,
3064 print_queue_struct *queue,
3065 struct spoolss_PrinterInfo2 *pinfo2,
3066 TALLOC_CTX *mem_ctx)
3068 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
3071 /*******************************************************************
3072 * fill a notify_info_data with job status
3073 ********************************************************************/
3075 static void spoolss_notify_job_status(struct messaging_context *msg_ctx,
3077 struct spoolss_Notify *data,
3078 print_queue_struct *queue,
3079 struct spoolss_PrinterInfo2 *pinfo2,
3080 TALLOC_CTX *mem_ctx)
3082 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
3085 /*******************************************************************
3086 * fill a notify_info_data with job name
3087 ********************************************************************/
3089 static void spoolss_notify_job_name(struct messaging_context *msg_ctx,
3091 struct spoolss_Notify *data,
3092 print_queue_struct *queue,
3093 struct spoolss_PrinterInfo2 *pinfo2,
3094 TALLOC_CTX *mem_ctx)
3096 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
3099 /*******************************************************************
3100 * fill a notify_info_data with job status
3101 ********************************************************************/
3103 static void spoolss_notify_job_status_string(struct messaging_context *msg_ctx,
3105 struct spoolss_Notify *data,
3106 print_queue_struct *queue,
3107 struct spoolss_PrinterInfo2 *pinfo2,
3108 TALLOC_CTX *mem_ctx)
3111 * Now we're returning job status codes we just return a "" here. JRA.
3116 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
3119 switch (queue->status) {
3124 p = ""; /* NT provides the paused string */
3133 #endif /* NO LONGER NEEDED. */
3135 SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
3138 /*******************************************************************
3139 * fill a notify_info_data with job time
3140 ********************************************************************/
3142 static void spoolss_notify_job_time(struct messaging_context *msg_ctx,
3144 struct spoolss_Notify *data,
3145 print_queue_struct *queue,
3146 struct spoolss_PrinterInfo2 *pinfo2,
3147 TALLOC_CTX *mem_ctx)
3149 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3152 /*******************************************************************
3153 * fill a notify_info_data with job size
3154 ********************************************************************/
3156 static void spoolss_notify_job_size(struct messaging_context *msg_ctx,
3158 struct spoolss_Notify *data,
3159 print_queue_struct *queue,
3160 struct spoolss_PrinterInfo2 *pinfo2,
3161 TALLOC_CTX *mem_ctx)
3163 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
3166 /*******************************************************************
3167 * fill a notify_info_data with page info
3168 ********************************************************************/
3169 static void spoolss_notify_total_pages(struct messaging_context *msg_ctx,
3171 struct spoolss_Notify *data,
3172 print_queue_struct *queue,
3173 struct spoolss_PrinterInfo2 *pinfo2,
3174 TALLOC_CTX *mem_ctx)
3176 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
3179 /*******************************************************************
3180 * fill a notify_info_data with pages printed info.
3181 ********************************************************************/
3182 static void spoolss_notify_pages_printed(struct messaging_context *msg_ctx,
3184 struct spoolss_Notify *data,
3185 print_queue_struct *queue,
3186 struct spoolss_PrinterInfo2 *pinfo2,
3187 TALLOC_CTX *mem_ctx)
3189 /* Add code when back-end tracks this */
3190 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
3193 /*******************************************************************
3194 Fill a notify_info_data with job position.
3195 ********************************************************************/
3197 static void spoolss_notify_job_position(struct messaging_context *msg_ctx,
3199 struct spoolss_Notify *data,
3200 print_queue_struct *queue,
3201 struct spoolss_PrinterInfo2 *pinfo2,
3202 TALLOC_CTX *mem_ctx)
3204 SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->job);
3207 /*******************************************************************
3208 Fill a notify_info_data with submitted time.
3209 ********************************************************************/
3211 static void spoolss_notify_submitted_time(struct messaging_context *msg_ctx,
3213 struct spoolss_Notify *data,
3214 print_queue_struct *queue,
3215 struct spoolss_PrinterInfo2 *pinfo2,
3216 TALLOC_CTX *mem_ctx)
3218 data->data.string.string = NULL;
3219 data->data.string.size = 0;
3221 init_systemtime_buffer(mem_ctx, gmtime(&queue->time),
3222 &data->data.string.string,
3223 &data->data.string.size);
3227 struct s_notify_info_data_table
3229 enum spoolss_NotifyType type;
3232 enum spoolss_NotifyTable variable_type;
3233 void (*fn) (struct messaging_context *msg_ctx,
3234 int snum, struct spoolss_Notify *data,
3235 print_queue_struct *queue,
3236 struct spoolss_PrinterInfo2 *pinfo2,
3237 TALLOC_CTX *mem_ctx);
3240 /* A table describing the various print notification constants and
3241 whether the notification data is a pointer to a variable sized
3242 buffer, a one value uint32_t or a two value uint32_t. */
3244 static const struct s_notify_info_data_table notify_info_data_table[] =
3246 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SERVER_NAME, "PRINTER_NOTIFY_FIELD_SERVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3247 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINTER_NAME, "PRINTER_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3248 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SHARE_NAME, "PRINTER_NOTIFY_FIELD_SHARE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_share_name },
3249 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PORT_NAME, "PRINTER_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3250 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DRIVER_NAME, "PRINTER_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3251 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_COMMENT, "PRINTER_NOTIFY_FIELD_COMMENT", NOTIFY_TABLE_STRING, spoolss_notify_comment },
3252 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_LOCATION, "PRINTER_NOTIFY_FIELD_LOCATION", NOTIFY_TABLE_STRING, spoolss_notify_location },
3253 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEVMODE, "PRINTER_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3254 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SEPFILE, "PRINTER_NOTIFY_FIELD_SEPFILE", NOTIFY_TABLE_STRING, spoolss_notify_sepfile },
3255 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR, "PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3256 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PARAMETERS, "PRINTER_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3257 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DATATYPE, "PRINTER_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3258 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, spoolss_notify_security_desc },
3259 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_ATTRIBUTES, "PRINTER_NOTIFY_FIELD_ATTRIBUTES", NOTIFY_TABLE_DWORD, spoolss_notify_attributes },
3260 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRIORITY, "PRINTER_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3261 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY, "PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_default_priority },
3262 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_START_TIME, "PRINTER_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3263 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_UNTIL_TIME, "PRINTER_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3264 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS, "PRINTER_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_status },
3265 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_STATUS_STRING, "PRINTER_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, NULL },
3266 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_CJOBS, "PRINTER_NOTIFY_FIELD_CJOBS", NOTIFY_TABLE_DWORD, spoolss_notify_cjobs },
3267 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_AVERAGE_PPM, "PRINTER_NOTIFY_FIELD_AVERAGE_PPM", NOTIFY_TABLE_DWORD, spoolss_notify_average_ppm },
3268 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_PAGES, "PRINTER_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, NULL },
3269 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PAGES_PRINTED, "PRINTER_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3270 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_TOTAL_BYTES, "PRINTER_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, NULL },
3271 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_BYTES_PRINTED, "PRINTER_NOTIFY_FIELD_BYTES_PRINTED", NOTIFY_TABLE_DWORD, NULL },
3272 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINTER_NAME, "JOB_NOTIFY_FIELD_PRINTER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_printer_name },
3273 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_MACHINE_NAME, "JOB_NOTIFY_FIELD_MACHINE_NAME", NOTIFY_TABLE_STRING, spoolss_notify_server_name },
3274 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PORT_NAME, "JOB_NOTIFY_FIELD_PORT_NAME", NOTIFY_TABLE_STRING, spoolss_notify_port_name },
3275 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_USER_NAME, "JOB_NOTIFY_FIELD_USER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3276 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_NOTIFY_NAME, "JOB_NOTIFY_FIELD_NOTIFY_NAME", NOTIFY_TABLE_STRING, spoolss_notify_username },
3277 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DATATYPE, "JOB_NOTIFY_FIELD_DATATYPE", NOTIFY_TABLE_STRING, spoolss_notify_datatype },
3278 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRINT_PROCESSOR, "JOB_NOTIFY_FIELD_PRINT_PROCESSOR", NOTIFY_TABLE_STRING, spoolss_notify_print_processor },
3279 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PARAMETERS, "JOB_NOTIFY_FIELD_PARAMETERS", NOTIFY_TABLE_STRING, spoolss_notify_parameters },
3280 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DRIVER_NAME, "JOB_NOTIFY_FIELD_DRIVER_NAME", NOTIFY_TABLE_STRING, spoolss_notify_driver_name },
3281 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DEVMODE, "JOB_NOTIFY_FIELD_DEVMODE", NOTIFY_TABLE_DEVMODE, spoolss_notify_devmode },
3282 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS, "JOB_NOTIFY_FIELD_STATUS", NOTIFY_TABLE_DWORD, spoolss_notify_job_status },
3283 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_STATUS_STRING, "JOB_NOTIFY_FIELD_STATUS_STRING", NOTIFY_TABLE_STRING, spoolss_notify_job_status_string },
3284 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR, "JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR", NOTIFY_TABLE_SECURITYDESCRIPTOR, NULL },
3285 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_DOCUMENT, "JOB_NOTIFY_FIELD_DOCUMENT", NOTIFY_TABLE_STRING, spoolss_notify_job_name },
3286 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PRIORITY, "JOB_NOTIFY_FIELD_PRIORITY", NOTIFY_TABLE_DWORD, spoolss_notify_priority },
3287 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_POSITION, "JOB_NOTIFY_FIELD_POSITION", NOTIFY_TABLE_DWORD, spoolss_notify_job_position },
3288 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_SUBMITTED, "JOB_NOTIFY_FIELD_SUBMITTED", NOTIFY_TABLE_TIME, spoolss_notify_submitted_time },
3289 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_START_TIME, "JOB_NOTIFY_FIELD_START_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_start_time },
3290 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_UNTIL_TIME, "JOB_NOTIFY_FIELD_UNTIL_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_until_time },
3291 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TIME, "JOB_NOTIFY_FIELD_TIME", NOTIFY_TABLE_DWORD, spoolss_notify_job_time },
3292 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_PAGES, "JOB_NOTIFY_FIELD_TOTAL_PAGES", NOTIFY_TABLE_DWORD, spoolss_notify_total_pages },
3293 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_PAGES_PRINTED, "JOB_NOTIFY_FIELD_PAGES_PRINTED", NOTIFY_TABLE_DWORD, spoolss_notify_pages_printed },
3294 { JOB_NOTIFY_TYPE, JOB_NOTIFY_FIELD_TOTAL_BYTES, "JOB_NOTIFY_FIELD_TOTAL_BYTES", NOTIFY_TABLE_DWORD, spoolss_notify_job_size },
3297 /*******************************************************************
3298 Return the variable_type of info_data structure.
3299 ********************************************************************/
3301 static enum spoolss_NotifyTable variable_type_of_notify_info_data(enum spoolss_NotifyType type,
3306 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3307 if ( (notify_info_data_table[i].type == type) &&
3308 (notify_info_data_table[i].field == field) ) {
3309 return notify_info_data_table[i].variable_type;
3313 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
3315 return (enum spoolss_NotifyTable) 0;
3318 /****************************************************************************
3319 ****************************************************************************/
3321 static bool search_notify(enum spoolss_NotifyType type,
3327 for (i = 0; i < ARRAY_SIZE(notify_info_data_table); i++) {
3328 if (notify_info_data_table[i].type == type &&
3329 notify_info_data_table[i].field == field &&
3330 notify_info_data_table[i].fn != NULL) {
3339 /****************************************************************************
3340 ****************************************************************************/
3342 static void construct_info_data(struct spoolss_Notify *info_data,
3343 enum spoolss_NotifyType type,
3344 uint16_t field, int id)
3346 info_data->type = type;
3347 info_data->field.field = field;
3348 info_data->variable_type = variable_type_of_notify_info_data(type, field);
3349 info_data->job_id = id;
3352 /*******************************************************************
3354 * fill a notify_info struct with info asked
3356 ********************************************************************/
3358 static bool construct_notify_printer_info(struct messaging_context *msg_ctx,
3359 struct printer_handle *print_hnd,
3360 struct spoolss_NotifyInfo *info,
3361 struct spoolss_PrinterInfo2 *pinfo2,
3363 const struct spoolss_NotifyOptionType *option_type,
3365 TALLOC_CTX *mem_ctx)
3368 enum spoolss_NotifyType type;
3371 struct spoolss_Notify *current_data;
3372 print_queue_struct *queue=NULL;
3374 type = option_type->type;
3376 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3377 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3378 option_type->count, lp_servicename(snum)));
3380 for(field_num=0; field_num < option_type->count; field_num++) {
3381 field = option_type->fields[field_num].field;
3383 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3385 if (!search_notify(type, field, &j) )
3388 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3389 struct spoolss_Notify,
3391 if (info->notifies == NULL) {
3392 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3396 current_data = &info->notifies[info->count];
3398 construct_info_data(current_data, type, field, id);
3400 DEBUG(10, ("construct_notify_printer_info: "
3401 "calling [%s] snum=%d printername=[%s])\n",
3402 notify_info_data_table[j].name, snum,
3403 pinfo2->printername));
3405 notify_info_data_table[j].fn(msg_ctx, snum, current_data,
3406 queue, pinfo2, mem_ctx);
3414 /*******************************************************************
3416 * fill a notify_info struct with info asked
3418 ********************************************************************/
3420 static bool construct_notify_jobs_info(struct messaging_context *msg_ctx,
3421 print_queue_struct *queue,
3422 struct spoolss_NotifyInfo *info,
3423 struct spoolss_PrinterInfo2 *pinfo2,
3425 const struct spoolss_NotifyOptionType *option_type,
3427 TALLOC_CTX *mem_ctx)
3430 enum spoolss_NotifyType type;
3432 struct spoolss_Notify *current_data;
3434 DEBUG(4,("construct_notify_jobs_info\n"));
3436 type = option_type->type;
3438 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3439 (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
3440 option_type->count));
3442 for(field_num=0; field_num<option_type->count; field_num++) {
3443 field = option_type->fields[field_num].field;
3445 if (!search_notify(type, field, &j) )
3448 info->notifies = TALLOC_REALLOC_ARRAY(info, info->notifies,
3449 struct spoolss_Notify,
3451 if (info->notifies == NULL) {
3452 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3456 current_data=&(info->notifies[info->count]);
3458 construct_info_data(current_data, type, field, id);
3459 notify_info_data_table[j].fn(msg_ctx, snum, current_data,
3460 queue, pinfo2, mem_ctx);
3468 * JFM: The enumeration is not that simple, it's even non obvious.
3470 * let's take an example: I want to monitor the PRINTER SERVER for
3471 * the printer's name and the number of jobs currently queued.
3472 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3473 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3475 * I have 3 printers on the back of my server.
3477 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3480 * 1 printer 1 name 1
3481 * 2 printer 1 cjob 1
3482 * 3 printer 2 name 2
3483 * 4 printer 2 cjob 2
3484 * 5 printer 3 name 3
3485 * 6 printer 3 name 3
3487 * that's the print server case, the printer case is even worse.
3490 /*******************************************************************
3492 * enumerate all printers on the printserver
3493 * fill a notify_info struct with info asked
3495 ********************************************************************/
3497 static WERROR printserver_notify_info(struct pipes_struct *p,
3498 struct policy_handle *hnd,
3499 struct spoolss_NotifyInfo *info,
3500 TALLOC_CTX *mem_ctx)
3503 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
3504 int n_services=lp_numservices();
3506 struct spoolss_NotifyOption *option;
3507 struct spoolss_NotifyOptionType option_type;
3508 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3511 DEBUG(4,("printserver_notify_info\n"));
3516 option = Printer->notify.option;
3519 info->notifies = NULL;
3522 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3523 sending a ffpcn() request first */
3528 for (i=0; i<option->count; i++) {
3529 option_type = option->types[i];
3531 if (option_type.type != PRINTER_NOTIFY_TYPE)
3534 for (snum = 0; snum < n_services; snum++) {
3535 if (!lp_browseable(snum) ||
3536 !lp_snum_ok(snum) ||
3537 !lp_print_ok(snum)) {
3538 continue; /* skip */
3541 /* Maybe we should use the SYSTEM server_info here... */
3542 result = winreg_get_printer(mem_ctx,
3543 get_server_info_system(),
3545 lp_servicename(snum),
3547 if (!W_ERROR_IS_OK(result)) {
3548 DEBUG(4, ("printserver_notify_info: "
3549 "Failed to get printer [%s]\n",
3550 lp_servicename(snum)));
3555 construct_notify_printer_info(p->msg_ctx,
3561 TALLOC_FREE(pinfo2);
3567 * Debugging information, don't delete.
3570 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3571 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3572 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3574 for (i=0; i<info->count; i++) {
3575 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3576 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3577 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3584 /*******************************************************************
3586 * fill a notify_info struct with info asked
3588 ********************************************************************/
3590 static WERROR printer_notify_info(struct pipes_struct *p,
3591 struct policy_handle *hnd,
3592 struct spoolss_NotifyInfo *info,
3593 TALLOC_CTX *mem_ctx)
3596 struct printer_handle *Printer = find_printer_index_by_hnd(p, hnd);
3599 struct spoolss_NotifyOption *option;
3600 struct spoolss_NotifyOptionType option_type;
3602 print_queue_struct *queue=NULL;
3603 print_status_struct status;
3604 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
3607 DEBUG(4,("printer_notify_info\n"));
3612 option = Printer->notify.option;
3616 info->notifies = NULL;
3619 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3620 sending a ffpcn() request first */
3625 get_printer_snum(p, hnd, &snum, NULL);
3627 /* Maybe we should use the SYSTEM server_info here... */
3628 result = winreg_get_printer(mem_ctx,
3629 get_server_info_system(),
3631 lp_servicename(snum), &pinfo2);
3632 if (!W_ERROR_IS_OK(result)) {
3636 for (i=0; i<option->count; i++) {
3637 option_type = option->types[i];
3639 switch (option_type.type) {
3640 case PRINTER_NOTIFY_TYPE:
3641 if (construct_notify_printer_info(p->msg_ctx,
3650 case JOB_NOTIFY_TYPE:
3652 count = print_queue_status(p->msg_ctx, snum, &queue,
3655 for (j=0; j<count; j++) {
3656 construct_notify_jobs_info(p->msg_ctx,
3670 * Debugging information, don't delete.
3673 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3674 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3675 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3677 for (i=0; i<info->count; i++) {
3678 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3679 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3680 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3684 talloc_free(pinfo2);
3688 /****************************************************************
3689 _spoolss_RouterRefreshPrinterChangeNotify
3690 ****************************************************************/
3692 WERROR _spoolss_RouterRefreshPrinterChangeNotify(struct pipes_struct *p,
3693 struct spoolss_RouterRefreshPrinterChangeNotify *r)
3695 struct spoolss_NotifyInfo *info;
3697 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
3698 WERROR result = WERR_BADFID;
3700 /* we always have a spoolss_NotifyInfo struct */
3701 info = talloc_zero(p->mem_ctx, struct spoolss_NotifyInfo);
3703 result = WERR_NOMEM;
3707 *r->out.info = info;
3710 DEBUG(2,("_spoolss_RouterRefreshPrinterChangeNotify: "
3711 "Invalid handle (%s:%u:%u).\n",
3712 OUR_HANDLE(r->in.handle)));
3716 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3719 * We are now using the change value, and
3720 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3721 * I don't have a global notification system, I'm sending back all the
3722 * informations even when _NOTHING_ has changed.
3725 /* We need to keep track of the change value to send back in
3726 RRPCN replies otherwise our updates are ignored. */
3728 Printer->notify.fnpcn = true;
3730 if (Printer->notify.cli_chan != NULL &&
3731 Printer->notify.cli_chan->active_connections > 0) {
3732 DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
3733 "Saving change value in request [%x]\n",
3735 Printer->notify.change = r->in.change_low;
3738 /* just ignore the spoolss_NotifyOption */
3740 switch (Printer->printer_type) {
3742 result = printserver_notify_info(p, r->in.handle,
3746 case SPLHND_PRINTER:
3747 result = printer_notify_info(p, r->in.handle,
3752 Printer->notify.fnpcn = false;
3758 /********************************************************************
3759 ********************************************************************/
3761 static WERROR create_printername(TALLOC_CTX *mem_ctx,
3762 const char *servername,
3763 const char *printername,
3764 const char **printername_p)
3766 /* FIXME: add lp_force_printername() */
3768 if (servername == NULL) {
3769 *printername_p = talloc_strdup(mem_ctx, printername);
3770 W_ERROR_HAVE_NO_MEMORY(*printername_p);
3774 if (servername[0] == '\\' && servername[1] == '\\') {
3778 *printername_p = talloc_asprintf(mem_ctx, "\\\\%s\\%s", servername, printername);
3779 W_ERROR_HAVE_NO_MEMORY(*printername_p);
3784 /********************************************************************
3785 ********************************************************************/
3787 static void compose_devicemode_devicename(struct spoolss_DeviceMode *dm,
3788 const char *printername)
3794 dm->devicename = talloc_strndup(dm, printername,
3795 MIN(strlen(printername), 31));
3798 /********************************************************************
3799 * construct_printer_info_0
3800 * fill a printer_info_0 struct
3801 ********************************************************************/
3803 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
3804 const struct auth_serversupplied_info *server_info,
3805 struct messaging_context *msg_ctx,
3806 struct spoolss_PrinterInfo2 *info2,
3807 const char *servername,
3808 struct spoolss_PrinterInfo0 *r,
3812 struct printer_session_counter *session_counter;
3813 struct timeval setuptime;
3814 print_status_struct status;
3817 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
3818 if (!W_ERROR_IS_OK(result)) {
3823 r->servername = talloc_strdup(mem_ctx, servername);
3824 W_ERROR_HAVE_NO_MEMORY(r->servername);
3826 r->servername = NULL;
3829 count = print_queue_length(msg_ctx, snum, &status);
3831 /* check if we already have a counter for this printer */
3832 for (session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3833 if (session_counter->snum == snum)
3837 /* it's the first time, add it to the list */
3838 if (session_counter == NULL) {
3839 session_counter = talloc_zero(counter_list, struct printer_session_counter);
3840 W_ERROR_HAVE_NO_MEMORY(session_counter);
3841 session_counter->snum = snum;
3842 session_counter->counter = 0;
3843 DLIST_ADD(counter_list, session_counter);
3847 session_counter->counter++;
3853 get_startup_time(&setuptime);
3854 init_systemtime(&r->time, gmtime(&setuptime.tv_sec));
3857 * the global_counter should be stored in a TDB as it's common to all the clients
3858 * and should be zeroed on samba startup
3860 r->global_counter = session_counter->counter;
3862 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
3863 SSVAL(&r->version, 0, 0x0005); /* NT 5 */
3864 SSVAL(&r->version, 2, 0x0893); /* build 2195 */
3865 r->free_build = SPOOLSS_RELEASE_BUILD;
3867 r->max_spooling = 0;
3868 r->session_counter = session_counter->counter;
3869 r->num_error_out_of_paper = 0x0;
3870 r->num_error_not_ready = 0x0; /* number of print failure */
3872 r->number_of_processors = 0x1;
3873 r->processor_type = PROCESSOR_INTEL_PENTIUM; /* 586 Pentium ? */
3874 r->high_part_total_bytes = 0x0;
3876 /* ChangeID in milliseconds*/
3877 winreg_printer_get_changeid(mem_ctx, server_info, msg_ctx,
3878 info2->sharename, &r->change_id);
3880 r->last_error = WERR_OK;
3881 r->status = nt_printq_status(status.status);
3882 r->enumerate_network_printers = 0x0;
3883 r->c_setprinter = 0x0;
3884 r->processor_architecture = PROCESSOR_ARCHITECTURE_INTEL;
3885 r->processor_level = 0x6; /* 6 ???*/
3894 /********************************************************************
3895 * construct_printer_info1
3896 * fill a spoolss_PrinterInfo1 struct
3897 ********************************************************************/
3899 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
3900 const struct spoolss_PrinterInfo2 *info2,
3902 const char *servername,
3903 struct spoolss_PrinterInfo1 *r,
3910 if (info2->comment == NULL || info2->comment[0] == '\0') {
3911 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3913 r->comment = talloc_strdup(mem_ctx, info2->comment); /* saved comment */
3915 W_ERROR_HAVE_NO_MEMORY(r->comment);
3917 result = create_printername(mem_ctx, servername, info2->printername, &r->name);
3918 if (!W_ERROR_IS_OK(result)) {
3922 r->description = talloc_asprintf(mem_ctx, "%s,%s,%s",
3926 W_ERROR_HAVE_NO_MEMORY(r->description);
3931 /********************************************************************
3932 * construct_printer_info2
3933 * fill a spoolss_PrinterInfo2 struct
3934 ********************************************************************/
3936 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
3937 struct messaging_context *msg_ctx,
3938 const struct spoolss_PrinterInfo2 *info2,
3939 const char *servername,
3940 struct spoolss_PrinterInfo2 *r,
3944 print_status_struct status;
3947 count = print_queue_length(msg_ctx, snum, &status);
3950 r->servername = talloc_strdup(mem_ctx, servername);
3951 W_ERROR_HAVE_NO_MEMORY(r->servername);
3953 r->servername = NULL;
3956 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
3957 if (!W_ERROR_IS_OK(result)) {
3961 r->sharename = talloc_strdup(mem_ctx, lp_servicename(snum));
3962 W_ERROR_HAVE_NO_MEMORY(r->sharename);
3963 r->portname = talloc_strdup(mem_ctx, info2->portname);
3964 W_ERROR_HAVE_NO_MEMORY(r->portname);
3965 r->drivername = talloc_strdup(mem_ctx, info2->drivername);
3966 W_ERROR_HAVE_NO_MEMORY(r->drivername);
3968 if (info2->comment[0] == '\0') {
3969 r->comment = talloc_strdup(mem_ctx, lp_comment(snum));
3971 r->comment = talloc_strdup(mem_ctx, info2->comment);
3973 W_ERROR_HAVE_NO_MEMORY(r->comment);
3975 r->location = talloc_strdup(mem_ctx, info2->location);
3976 W_ERROR_HAVE_NO_MEMORY(r->location);
3977 r->sepfile = talloc_strdup(mem_ctx, info2->sepfile);
3978 W_ERROR_HAVE_NO_MEMORY(r->sepfile);
3979 r->printprocessor = talloc_strdup(mem_ctx, info2->printprocessor);
3980 W_ERROR_HAVE_NO_MEMORY(r->printprocessor);
3981 r->datatype = talloc_strdup(mem_ctx, info2->datatype);
3982 W_ERROR_HAVE_NO_MEMORY(r->datatype);
3983 r->parameters = talloc_strdup(mem_ctx, info2->parameters);
3984 W_ERROR_HAVE_NO_MEMORY(r->parameters);
3986 r->attributes = info2->attributes;
3988 r->priority = info2->priority;
3989 r->defaultpriority = info2->defaultpriority;
3990 r->starttime = info2->starttime;
3991 r->untiltime = info2->untiltime;
3992 r->status = nt_printq_status(status.status);
3994 r->averageppm = info2->averageppm;
3996 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
3998 DEBUG(8,("Returning NULL Devicemode!\n"));
4001 compose_devicemode_devicename(r->devmode, r->printername);
4005 if (info2->secdesc != NULL) {
4006 /* don't use talloc_steal() here unless you do a deep steal of all
4007 the SEC_DESC members */
4009 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
4015 /********************************************************************
4016 * construct_printer_info3
4017 * fill a spoolss_PrinterInfo3 struct
4018 ********************************************************************/
4020 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
4021 const struct spoolss_PrinterInfo2 *info2,
4022 const char *servername,
4023 struct spoolss_PrinterInfo3 *r,
4026 /* These are the components of the SD we are returning. */
4028 if (info2->secdesc != NULL) {
4029 /* don't use talloc_steal() here unless you do a deep steal of all
4030 the SEC_DESC members */
4032 r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
4033 W_ERROR_HAVE_NO_MEMORY(r->secdesc);
4039 /********************************************************************
4040 * construct_printer_info4
4041 * fill a spoolss_PrinterInfo4 struct
4042 ********************************************************************/
4044 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
4045 const struct spoolss_PrinterInfo2 *info2,
4046 const char *servername,
4047 struct spoolss_PrinterInfo4 *r,
4052 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
4053 if (!W_ERROR_IS_OK(result)) {
4058 r->servername = talloc_strdup(mem_ctx, servername);
4059 W_ERROR_HAVE_NO_MEMORY(r->servername);
4061 r->servername = NULL;
4064 r->attributes = info2->attributes;
4069 /********************************************************************
4070 * construct_printer_info5
4071 * fill a spoolss_PrinterInfo5 struct
4072 ********************************************************************/
4074 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
4075 const struct spoolss_PrinterInfo2 *info2,
4076 const char *servername,
4077 struct spoolss_PrinterInfo5 *r,
4082 result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
4083 if (!W_ERROR_IS_OK(result)) {
4087 r->portname = talloc_strdup(mem_ctx, info2->portname);
4088 W_ERROR_HAVE_NO_MEMORY(r->portname);
4090 r->attributes = info2->attributes;
4092 /* these two are not used by NT+ according to MSDN */
4093 r->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
4094 r->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
4099 /********************************************************************
4100 * construct_printer_info_6
4101 * fill a spoolss_PrinterInfo6 struct
4102 ********************************************************************/
4104 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
4105 struct messaging_context *msg_ctx,
4106 const struct spoolss_PrinterInfo2 *info2,
4107 const char *servername,
4108 struct spoolss_PrinterInfo6 *r,
4112 print_status_struct status;
4114 count = print_queue_length(msg_ctx, snum, &status);
4116 r->status = nt_printq_status(status.status);
4121 /********************************************************************
4122 * construct_printer_info7
4123 * fill a spoolss_PrinterInfo7 struct
4124 ********************************************************************/
4126 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
4127 struct messaging_context *msg_ctx,
4128 const char *servername,
4129 struct spoolss_PrinterInfo7 *r,
4132 struct auth_serversupplied_info *server_info;
4136 status = make_server_info_system(mem_ctx, &server_info);
4137 if (!NT_STATUS_IS_OK(status)) {
4138 DEBUG(0, ("construct_printer_info7: "
4139 "Could not create system server_info\n"));
4143 if (is_printer_published(mem_ctx, server_info, msg_ctx,
4145 lp_servicename(snum), &guid, NULL)) {
4146 r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
4147 r->action = DSPRINT_PUBLISH;
4149 r->guid = talloc_strdup(mem_ctx, "");
4150 r->action = DSPRINT_UNPUBLISH;
4152 W_ERROR_HAVE_NO_MEMORY(r->guid);
4154 TALLOC_FREE(server_info);
4158 /********************************************************************
4159 * construct_printer_info8
4160 * fill a spoolss_PrinterInfo8 struct
4161 ********************************************************************/
4163 static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
4164 const struct spoolss_PrinterInfo2 *info2,
4165 const char *servername,
4166 struct spoolss_DeviceModeInfo *r,
4170 const char *printername;
4172 result = create_printername(mem_ctx, servername, info2->printername, &printername);
4173 if (!W_ERROR_IS_OK(result)) {
4177 copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
4179 DEBUG(8,("Returning NULL Devicemode!\n"));
4182 compose_devicemode_devicename(r->devmode, printername);
4188 /********************************************************************
4189 ********************************************************************/
4191 static bool snum_is_shared_printer(int snum)
4193 return (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum));
4196 /********************************************************************
4197 Spoolss_enumprinters.
4198 ********************************************************************/
4200 static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
4201 const struct auth_serversupplied_info *server_info,
4202 struct messaging_context *msg_ctx,
4203 const char *servername,
4206 union spoolss_PrinterInfo **info_p,
4210 int n_services = lp_numservices();
4211 union spoolss_PrinterInfo *info = NULL;
4213 WERROR result = WERR_OK;
4218 for (snum = 0; snum < n_services; snum++) {
4220 const char *printer;
4221 struct spoolss_PrinterInfo2 *info2;
4223 if (!snum_is_shared_printer(snum)) {
4227 printer = lp_const_servicename(snum);
4229 DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
4232 result = winreg_create_printer(mem_ctx,
4236 if (!W_ERROR_IS_OK(result)) {
4240 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
4241 union spoolss_PrinterInfo,
4244 result = WERR_NOMEM;
4248 result = winreg_get_printer(mem_ctx, server_info, msg_ctx,
4250 if (!W_ERROR_IS_OK(result)) {
4256 result = construct_printer_info0(info, server_info,
4259 &info[count].info0, snum);
4262 result = construct_printer_info1(info, info2, flags,
4264 &info[count].info1, snum);
4267 result = construct_printer_info2(info, msg_ctx, info2,
4269 &info[count].info2, snum);
4272 result = construct_printer_info4(info, info2,
4274 &info[count].info4, snum);
4277 result = construct_printer_info5(info, info2,
4279 &info[count].info5, snum);
4283 result = WERR_UNKNOWN_LEVEL;
4287 if (!W_ERROR_IS_OK(result)) {
4298 if (!W_ERROR_IS_OK(result)) {
4308 /********************************************************************
4309 * handle enumeration of printers at level 0
4310 ********************************************************************/
4312 static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
4313 const struct auth_serversupplied_info *server_info,
4314 struct messaging_context *msg_ctx,
4316 const char *servername,
4317 union spoolss_PrinterInfo **info,
4320 DEBUG(4,("enum_all_printers_info_0\n"));
4322 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4323 servername, 0, flags, info, count);
4327 /********************************************************************
4328 ********************************************************************/
4330 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
4331 const struct auth_serversupplied_info *server_info,
4332 struct messaging_context *msg_ctx,
4333 const char *servername,
4335 union spoolss_PrinterInfo **info,
4338 DEBUG(4,("enum_all_printers_info_1\n"));
4340 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4341 servername, 1, flags, info, count);
4344 /********************************************************************
4345 enum_all_printers_info_1_local.
4346 *********************************************************************/
4348 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
4349 const struct auth_serversupplied_info *server_info,
4350 struct messaging_context *msg_ctx,
4351 const char *servername,
4352 union spoolss_PrinterInfo **info,
4355 DEBUG(4,("enum_all_printers_info_1_local\n"));
4357 return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
4358 servername, PRINTER_ENUM_ICON8, info, count);
4361 /********************************************************************
4362 enum_all_printers_info_1_name.
4363 *********************************************************************/
4365 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
4366 const struct auth_serversupplied_info *server_info,
4367 struct messaging_context *msg_ctx,
4368 const char *servername,
4369 union spoolss_PrinterInfo **info,
4372 const char *s = servername;
4374 DEBUG(4,("enum_all_printers_info_1_name\n"));
4376 if ((servername[0] == '\\') && (servername[1] == '\\')) {
4380 if (!is_myname_or_ipaddr(s)) {
4381 return WERR_INVALID_NAME;
4384 return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
4385 servername, PRINTER_ENUM_ICON8, info, count);
4388 /********************************************************************
4389 enum_all_printers_info_1_network.
4390 *********************************************************************/
4392 static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
4393 const struct auth_serversupplied_info *server_info,
4394 struct messaging_context *msg_ctx,
4395 const char *servername,
4396 union spoolss_PrinterInfo **info,
4399 const char *s = servername;
4401 DEBUG(4,("enum_all_printers_info_1_network\n"));
4403 /* If we respond to a enum_printers level 1 on our name with flags
4404 set to PRINTER_ENUM_REMOTE with a list of printers then these
4405 printers incorrectly appear in the APW browse list.
4406 Specifically the printers for the server appear at the workgroup
4407 level where all the other servers in the domain are
4408 listed. Windows responds to this call with a
4409 WERR_CAN_NOT_COMPLETE so we should do the same. */
4411 if (servername[0] == '\\' && servername[1] == '\\') {
4415 if (is_myname_or_ipaddr(s)) {
4416 return WERR_CAN_NOT_COMPLETE;
4419 return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
4420 servername, PRINTER_ENUM_NAME, info, count);
4423 /********************************************************************
4424 * api_spoolss_enumprinters
4426 * called from api_spoolss_enumprinters (see this to understand)
4427 ********************************************************************/
4429 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
4430 const struct auth_serversupplied_info *server_info,
4431 struct messaging_context *msg_ctx,
4432 const char *servername,
4433 union spoolss_PrinterInfo **info,
4436 DEBUG(4,("enum_all_printers_info_2\n"));
4438 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4439 servername, 2, 0, info, count);
4442 /********************************************************************
4443 * handle enumeration of printers at level 1
4444 ********************************************************************/
4446 static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
4447 const struct auth_serversupplied_info *server_info,
4448 struct messaging_context *msg_ctx,
4450 const char *servername,
4451 union spoolss_PrinterInfo **info,
4454 /* Not all the flags are equals */
4456 if (flags & PRINTER_ENUM_LOCAL) {
4457 return enum_all_printers_info_1_local(mem_ctx, server_info,
4458 msg_ctx, servername, info, count);
4461 if (flags & PRINTER_ENUM_NAME) {
4462 return enum_all_printers_info_1_name(mem_ctx, server_info,
4463 msg_ctx, servername, info,
4467 if (flags & PRINTER_ENUM_NETWORK) {
4468 return enum_all_printers_info_1_network(mem_ctx, server_info,
4469 msg_ctx, servername, info,
4473 return WERR_OK; /* NT4sp5 does that */
4476 /********************************************************************
4477 * handle enumeration of printers at level 2
4478 ********************************************************************/
4480 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
4481 const struct auth_serversupplied_info *server_info,
4482 struct messaging_context *msg_ctx,
4484 const char *servername,
4485 union spoolss_PrinterInfo **info,
4488 if (flags & PRINTER_ENUM_LOCAL) {
4490 return enum_all_printers_info_2(mem_ctx, server_info, msg_ctx,
4495 if (flags & PRINTER_ENUM_NAME) {
4496 if (servername && !is_myname_or_ipaddr(canon_servername(servername))) {
4497 return WERR_INVALID_NAME;
4500 return enum_all_printers_info_2(mem_ctx, server_info, msg_ctx,
4505 if (flags & PRINTER_ENUM_REMOTE) {
4506 return WERR_UNKNOWN_LEVEL;
4512 /********************************************************************
4513 * handle enumeration of printers at level 4
4514 ********************************************************************/
4516 static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
4517 const struct auth_serversupplied_info *server_info,
4518 struct messaging_context *msg_ctx,
4520 const char *servername,
4521 union spoolss_PrinterInfo **info,
4524 DEBUG(4,("enum_all_printers_info_4\n"));
4526 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4527 servername, 4, flags, info, count);
4531 /********************************************************************
4532 * handle enumeration of printers at level 5
4533 ********************************************************************/
4535 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
4536 const struct auth_serversupplied_info *server_info,
4537 struct messaging_context *msg_ctx,
4539 const char *servername,
4540 union spoolss_PrinterInfo **info,
4543 DEBUG(4,("enum_all_printers_info_5\n"));
4545 return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
4546 servername, 5, flags, info, count);
4549 /****************************************************************
4550 _spoolss_EnumPrinters
4551 ****************************************************************/
4553 WERROR _spoolss_EnumPrinters(struct pipes_struct *p,
4554 struct spoolss_EnumPrinters *r)
4556 const struct auth_serversupplied_info *server_info = get_server_info_system();
4559 /* that's an [in out] buffer */
4561 if (!r->in.buffer && (r->in.offered != 0)) {
4562 return WERR_INVALID_PARAM;
4565 DEBUG(4,("_spoolss_EnumPrinters\n"));
4569 *r->out.info = NULL;
4573 * flags==PRINTER_ENUM_NAME
4574 * if name=="" then enumerates all printers
4575 * if name!="" then enumerate the printer
4576 * flags==PRINTER_ENUM_REMOTE
4577 * name is NULL, enumerate printers
4578 * Level 2: name!="" enumerates printers, name can't be NULL
4579 * Level 3: doesn't exist
4580 * Level 4: does a local registry lookup
4581 * Level 5: same as Level 2
4584 if (r->in.server && r->in.server[0] == '\0') {
4585 r->in.server = NULL;
4588 switch (r->in.level) {
4590 result = enumprinters_level0(p->mem_ctx, server_info,
4591 p->msg_ctx, r->in.flags,
4593 r->out.info, r->out.count);
4596 result = enumprinters_level1(p->mem_ctx, server_info,
4597 p->msg_ctx, r->in.flags,
4599 r->out.info, r->out.count);
4602 result = enumprinters_level2(p->mem_ctx, server_info,
4603 p->msg_ctx, r->in.flags,
4605 r->out.info, r->out.count);
4608 result = enumprinters_level4(p->mem_ctx, server_info,
4609 p->msg_ctx, r->in.flags,
4611 r->out.info, r->out.count);
4614 result = enumprinters_level5(p->mem_ctx, server_info,
4615 p->msg_ctx, r->in.flags,
4617 r->out.info, r->out.count);
4620 return WERR_UNKNOWN_LEVEL;
4623 if (!W_ERROR_IS_OK(result)) {
4627 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
4628 spoolss_EnumPrinters,
4629 *r->out.info, r->in.level,
4631 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
4632 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
4634 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4637 /****************************************************************
4639 ****************************************************************/
4641 WERROR _spoolss_GetPrinter(struct pipes_struct *p,
4642 struct spoolss_GetPrinter *r)
4644 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
4645 struct spoolss_PrinterInfo2 *info2 = NULL;
4646 WERROR result = WERR_OK;
4649 /* that's an [in out] buffer */
4651 if (!r->in.buffer && (r->in.offered != 0)) {
4652 return WERR_INVALID_PARAM;
4657 if (Printer == NULL) {
4661 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
4665 result = winreg_get_printer(p->mem_ctx,
4666 get_server_info_system(),
4668 lp_const_servicename(snum),
4670 if (!W_ERROR_IS_OK(result)) {
4674 switch (r->in.level) {
4676 result = construct_printer_info0(p->mem_ctx,
4677 get_server_info_system(),
4680 Printer->servername,
4681 &r->out.info->info0,
4685 result = construct_printer_info1(p->mem_ctx, info2,
4687 Printer->servername,
4688 &r->out.info->info1, snum);
4691 result = construct_printer_info2(p->mem_ctx, p->msg_ctx, info2,
4692 Printer->servername,
4693 &r->out.info->info2, snum);
4696 result = construct_printer_info3(p->mem_ctx, info2,
4697 Printer->servername,
4698 &r->out.info->info3, snum);
4701 result = construct_printer_info4(p->mem_ctx, info2,
4702 Printer->servername,
4703 &r->out.info->info4, snum);
4706 result = construct_printer_info5(p->mem_ctx, info2,
4707 Printer->servername,
4708 &r->out.info->info5, snum);
4711 result = construct_printer_info6(p->mem_ctx, p->msg_ctx, info2,
4712 Printer->servername,
4713 &r->out.info->info6, snum);
4716 result = construct_printer_info7(p->mem_ctx, p->msg_ctx,
4717 Printer->servername,
4718 &r->out.info->info7, snum);
4721 result = construct_printer_info8(p->mem_ctx, info2,
4722 Printer->servername,
4723 &r->out.info->info8, snum);
4726 result = WERR_UNKNOWN_LEVEL;
4731 if (!W_ERROR_IS_OK(result)) {
4732 DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
4733 r->in.level, win_errstr(result)));
4734 TALLOC_FREE(r->out.info);
4738 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrinterInfo,
4739 r->out.info, r->in.level);
4740 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
4742 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
4745 /********************************************************************
4746 ********************************************************************/
4748 #define FILL_DRIVER_STRING(mem_ctx, in, out) \
4750 if (in && strlen(in)) { \
4751 out = talloc_strdup(mem_ctx, in); \
4753 out = talloc_strdup(mem_ctx, ""); \
4755 W_ERROR_HAVE_NO_MEMORY(out); \
4758 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, arch, ver, in, out) \
4760 if (in && strlen(in)) { \
4761 out = talloc_asprintf(mem_ctx, "\\\\%s\\print$\\%s\\%d\\%s", server, get_short_archi(arch), ver, in); \
4763 out = talloc_strdup(mem_ctx, ""); \
4765 W_ERROR_HAVE_NO_MEMORY(out); \
4768 static WERROR string_array_from_driver_info(TALLOC_CTX *mem_ctx,
4769 const char **string_array,
4770 const char ***presult,
4771 const char *cservername,
4775 int i, num_strings = 0;
4776 const char **array = NULL;
4778 if (string_array == NULL) {
4779 return WERR_INVALID_PARAMETER;;
4782 for (i=0; string_array[i] && string_array[i][0] != '\0'; i++) {
4783 const char *str = NULL;
4785 if (cservername == NULL || arch == NULL) {
4786 FILL_DRIVER_STRING(mem_ctx, string_array[i], str);
4788 FILL_DRIVER_UNC_STRING(mem_ctx, cservername, arch, version, string_array[i], str);
4791 if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
4798 ADD_TO_ARRAY(mem_ctx, const char *, NULL,
4799 &array, &num_strings);
4809 /********************************************************************
4810 * fill a spoolss_DriverInfo1 struct
4811 ********************************************************************/
4813 static WERROR fill_printer_driver_info1(TALLOC_CTX *mem_ctx,
4814 struct spoolss_DriverInfo1 *r,
4815 const struct spoolss_DriverInfo8 *driver,
4816 const char *servername)
4818 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4819 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4824 /********************************************************************
4825 * fill a spoolss_DriverInfo2 struct
4826 ********************************************************************/
4828 static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
4829 struct spoolss_DriverInfo2 *r,
4830 const struct spoolss_DriverInfo8 *driver,
4831 const char *servername)
4834 const char *cservername = canon_servername(servername);
4836 r->version = driver->version;
4838 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4839 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4840 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4841 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4843 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4844 driver->architecture,
4846 driver->driver_path,
4849 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4850 driver->architecture,
4855 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4856 driver->architecture,
4858 driver->config_file,
4864 /********************************************************************
4865 * fill a spoolss_DriverInfo3 struct
4866 ********************************************************************/
4868 static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
4869 struct spoolss_DriverInfo3 *r,
4870 const struct spoolss_DriverInfo8 *driver,
4871 const char *servername)
4873 const char *cservername = canon_servername(servername);
4875 r->version = driver->version;
4877 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4878 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4879 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4880 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4882 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4883 driver->architecture,
4885 driver->driver_path,
4888 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4889 driver->architecture,
4894 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4895 driver->architecture,
4897 driver->config_file,
4900 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4901 driver->architecture,
4906 FILL_DRIVER_STRING(mem_ctx,
4907 driver->monitor_name,
4910 FILL_DRIVER_STRING(mem_ctx,
4911 driver->default_datatype,
4912 r->default_datatype);
4914 return string_array_from_driver_info(mem_ctx,
4915 driver->dependent_files,
4916 &r->dependent_files,
4918 driver->architecture,
4922 /********************************************************************
4923 * fill a spoolss_DriverInfo4 struct
4924 ********************************************************************/
4926 static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
4927 struct spoolss_DriverInfo4 *r,
4928 const struct spoolss_DriverInfo8 *driver,
4929 const char *servername)
4931 const char *cservername = canon_servername(servername);
4934 r->version = driver->version;
4936 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
4937 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
4938 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
4939 W_ERROR_HAVE_NO_MEMORY(r->architecture);
4941 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4942 driver->architecture,
4944 driver->driver_path,
4947 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4948 driver->architecture,
4953 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4954 driver->architecture,
4956 driver->config_file,
4959 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
4960 driver->architecture,
4965 result = string_array_from_driver_info(mem_ctx,
4966 driver->dependent_files,
4967 &r->dependent_files,
4969 driver->architecture,
4971 if (!W_ERROR_IS_OK(result)) {
4975 FILL_DRIVER_STRING(mem_ctx,
4976 driver->monitor_name,
4979 FILL_DRIVER_STRING(mem_ctx,
4980 driver->default_datatype,
4981 r->default_datatype);
4984 result = string_array_from_driver_info(mem_ctx,
4985 driver->previous_names,
4992 /********************************************************************
4993 * fill a spoolss_DriverInfo5 struct
4994 ********************************************************************/
4996 static WERROR fill_printer_driver_info5(TALLOC_CTX *mem_ctx,
4997 struct spoolss_DriverInfo5 *r,
4998 const struct spoolss_DriverInfo8 *driver,
4999 const char *servername)
5001 const char *cservername = canon_servername(servername);
5003 r->version = driver->version;
5005 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5006 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5007 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5008 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5010 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5011 driver->architecture,
5013 driver->driver_path,
5016 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5017 driver->architecture,
5022 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5023 driver->architecture,
5025 driver->config_file,
5028 r->driver_attributes = 0;
5029 r->config_version = 0;
5030 r->driver_version = 0;
5034 /********************************************************************
5035 * fill a spoolss_DriverInfo6 struct
5036 ********************************************************************/
5038 static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
5039 struct spoolss_DriverInfo6 *r,
5040 const struct spoolss_DriverInfo8 *driver,
5041 const char *servername)
5043 const char *cservername = canon_servername(servername);
5046 r->version = driver->version;
5048 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5049 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5050 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5051 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5053 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5054 driver->architecture,
5056 driver->driver_path,
5059 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5060 driver->architecture,
5065 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5066 driver->architecture,
5068 driver->config_file,
5071 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5072 driver->architecture,
5077 FILL_DRIVER_STRING(mem_ctx,
5078 driver->monitor_name,
5081 FILL_DRIVER_STRING(mem_ctx,
5082 driver->default_datatype,
5083 r->default_datatype);
5085 result = string_array_from_driver_info(mem_ctx,
5086 driver->dependent_files,
5087 &r->dependent_files,
5089 driver->architecture,
5091 if (!W_ERROR_IS_OK(result)) {
5095 result = string_array_from_driver_info(mem_ctx,
5096 driver->previous_names,
5099 if (!W_ERROR_IS_OK(result)) {
5103 r->driver_date = driver->driver_date;
5104 r->driver_version = driver->driver_version;
5106 FILL_DRIVER_STRING(mem_ctx,
5107 driver->manufacturer_name,
5108 r->manufacturer_name);
5109 FILL_DRIVER_STRING(mem_ctx,
5110 driver->manufacturer_url,
5111 r->manufacturer_url);
5112 FILL_DRIVER_STRING(mem_ctx,
5113 driver->hardware_id,
5115 FILL_DRIVER_STRING(mem_ctx,
5122 /********************************************************************
5123 * fill a spoolss_DriverInfo8 struct
5124 ********************************************************************/
5126 static WERROR fill_printer_driver_info8(TALLOC_CTX *mem_ctx,
5127 struct spoolss_DriverInfo8 *r,
5128 const struct spoolss_DriverInfo8 *driver,
5129 const char *servername)
5131 const char *cservername = canon_servername(servername);
5134 r->version = driver->version;
5136 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5137 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5138 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5139 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5141 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5142 driver->architecture,
5144 driver->driver_path,
5147 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5148 driver->architecture,
5153 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5154 driver->architecture,
5156 driver->config_file,
5159 FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
5160 driver->architecture,
5165 FILL_DRIVER_STRING(mem_ctx,
5166 driver->monitor_name,
5169 FILL_DRIVER_STRING(mem_ctx,
5170 driver->default_datatype,
5171 r->default_datatype);
5173 result = string_array_from_driver_info(mem_ctx,
5174 driver->dependent_files,
5175 &r->dependent_files,
5177 driver->architecture,
5179 if (!W_ERROR_IS_OK(result)) {
5183 result = string_array_from_driver_info(mem_ctx,
5184 driver->previous_names,
5187 if (!W_ERROR_IS_OK(result)) {
5191 r->driver_date = driver->driver_date;
5192 r->driver_version = driver->driver_version;
5194 FILL_DRIVER_STRING(mem_ctx,
5195 driver->manufacturer_name,
5196 r->manufacturer_name);
5197 FILL_DRIVER_STRING(mem_ctx,
5198 driver->manufacturer_url,
5199 r->manufacturer_url);
5200 FILL_DRIVER_STRING(mem_ctx,
5201 driver->hardware_id,
5203 FILL_DRIVER_STRING(mem_ctx,
5207 FILL_DRIVER_STRING(mem_ctx,
5208 driver->print_processor,
5209 r->print_processor);
5210 FILL_DRIVER_STRING(mem_ctx,
5211 driver->vendor_setup,
5214 result = string_array_from_driver_info(mem_ctx,
5215 driver->color_profiles,
5218 if (!W_ERROR_IS_OK(result)) {
5222 FILL_DRIVER_STRING(mem_ctx,
5226 r->printer_driver_attributes = driver->printer_driver_attributes;
5228 result = string_array_from_driver_info(mem_ctx,
5229 driver->core_driver_dependencies,
5230 &r->core_driver_dependencies,
5232 if (!W_ERROR_IS_OK(result)) {
5236 r->min_inbox_driver_ver_date = driver->min_inbox_driver_ver_date;
5237 r->min_inbox_driver_ver_version = driver->min_inbox_driver_ver_version;
5242 #if 0 /* disabled until marshalling issues are resolved - gd */
5243 /********************************************************************
5244 ********************************************************************/
5246 static WERROR fill_spoolss_DriverFileInfo(TALLOC_CTX *mem_ctx,
5247 struct spoolss_DriverFileInfo *r,
5248 const char *cservername,
5249 const char *file_name,
5250 enum spoolss_DriverFileType file_type,
5251 uint32_t file_version)
5253 r->file_name = talloc_asprintf(mem_ctx, "\\\\%s%s",
5254 cservername, file_name);
5255 W_ERROR_HAVE_NO_MEMORY(r->file_name);
5256 r->file_type = file_type;
5257 r->file_version = file_version;
5262 /********************************************************************
5263 ********************************************************************/
5265 static WERROR spoolss_DriverFileInfo_from_driver(TALLOC_CTX *mem_ctx,
5266 const struct spoolss_DriverInfo8 *driver,
5267 const char *cservername,
5268 struct spoolss_DriverFileInfo **info_p,
5271 struct spoolss_DriverFileInfo *info = NULL;
5279 if (strlen(driver->driver_path)) {
5280 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5281 struct spoolss_DriverFileInfo,
5283 W_ERROR_HAVE_NO_MEMORY(info);
5284 result = fill_spoolss_DriverFileInfo(info,
5287 driver->driver_path,
5288 SPOOLSS_DRIVER_FILE_TYPE_RENDERING,
5290 W_ERROR_NOT_OK_RETURN(result);
5294 if (strlen(driver->config_file)) {
5295 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5296 struct spoolss_DriverFileInfo,
5298 W_ERROR_HAVE_NO_MEMORY(info);
5299 result = fill_spoolss_DriverFileInfo(info,
5302 driver->config_file,
5303 SPOOLSS_DRIVER_FILE_TYPE_CONFIGURATION,
5305 W_ERROR_NOT_OK_RETURN(result);
5309 if (strlen(driver->data_file)) {
5310 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5311 struct spoolss_DriverFileInfo,
5313 W_ERROR_HAVE_NO_MEMORY(info);
5314 result = fill_spoolss_DriverFileInfo(info,
5318 SPOOLSS_DRIVER_FILE_TYPE_DATA,
5320 W_ERROR_NOT_OK_RETURN(result);
5324 if (strlen(driver->help_file)) {
5325 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5326 struct spoolss_DriverFileInfo,
5328 W_ERROR_HAVE_NO_MEMORY(info);
5329 result = fill_spoolss_DriverFileInfo(info,
5333 SPOOLSS_DRIVER_FILE_TYPE_HELP,
5335 W_ERROR_NOT_OK_RETURN(result);
5339 for (i=0; driver->dependent_files[i] && driver->dependent_files[i][0] != '\0'; i++) {
5340 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
5341 struct spoolss_DriverFileInfo,
5343 W_ERROR_HAVE_NO_MEMORY(info);
5344 result = fill_spoolss_DriverFileInfo(info,
5347 driver->dependent_files[i],
5348 SPOOLSS_DRIVER_FILE_TYPE_OTHER,
5350 W_ERROR_NOT_OK_RETURN(result);
5360 /********************************************************************
5361 * fill a spoolss_DriverInfo101 struct
5362 ********************************************************************/
5364 static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
5365 struct spoolss_DriverInfo101 *r,
5366 const struct spoolss_DriverInfo8 *driver,
5367 const char *servername)
5369 const char *cservername = canon_servername(servername);
5372 r->version = driver->version;
5374 r->driver_name = talloc_strdup(mem_ctx, driver->driver_name);
5375 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
5376 r->architecture = talloc_strdup(mem_ctx, driver->architecture);
5377 W_ERROR_HAVE_NO_MEMORY(r->architecture);
5379 result = spoolss_DriverFileInfo_from_driver(mem_ctx, driver,
5383 if (!W_ERROR_IS_OK(result)) {
5387 FILL_DRIVER_STRING(mem_ctx,
5388 driver->monitor_name,
5391 FILL_DRIVER_STRING(mem_ctx,
5392 driver->default_datatype,
5393 r->default_datatype);
5395 result = string_array_from_driver_info(mem_ctx,
5396 driver->previous_names,
5399 if (!W_ERROR_IS_OK(result)) {
5403 r->driver_date = driver->driver_date;
5404 r->driver_version = driver->driver_version;
5406 FILL_DRIVER_STRING(mem_ctx,
5407 driver->manufacturer_name,
5408 r->manufacturer_name);
5409 FILL_DRIVER_STRING(mem_ctx,
5410 driver->manufacturer_url,
5411 r->manufacturer_url);
5412 FILL_DRIVER_STRING(mem_ctx,
5413 driver->hardware_id,
5415 FILL_DRIVER_STRING(mem_ctx,
5422 /********************************************************************
5423 ********************************************************************/
5425 static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
5426 const struct auth_serversupplied_info *server_info,
5427 struct messaging_context *msg_ctx,
5429 union spoolss_DriverInfo *r,
5431 const char *servername,
5432 const char *architecture,
5435 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
5436 struct spoolss_DriverInfo8 *driver;
5440 return WERR_UNKNOWN_LEVEL;
5443 result = winreg_get_printer(mem_ctx,
5446 lp_const_servicename(snum),
5449 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5450 win_errstr(result)));
5452 if (!W_ERROR_IS_OK(result)) {
5453 return WERR_INVALID_PRINTER_NAME;
5456 result = winreg_get_driver(mem_ctx, server_info, msg_ctx,
5458 pinfo2->drivername, version, &driver);
5460 DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
5461 win_errstr(result)));
5463 if (!W_ERROR_IS_OK(result)) {
5465 * Is this a W2k client ?
5469 talloc_free(pinfo2);
5470 return WERR_UNKNOWN_PRINTER_DRIVER;
5473 /* Yes - try again with a WinNT driver. */
5475 result = winreg_get_driver(mem_ctx, server_info, msg_ctx,
5479 DEBUG(8,("construct_printer_driver_level: status: %s\n",
5480 win_errstr(result)));
5481 if (!W_ERROR_IS_OK(result)) {
5482 talloc_free(pinfo2);
5483 return WERR_UNKNOWN_PRINTER_DRIVER;
5489 result = fill_printer_driver_info1(mem_ctx, &r->info1, driver, servername);
5492 result = fill_printer_driver_info2(mem_ctx, &r->info2, driver, servername);
5495 result = fill_printer_driver_info3(mem_ctx, &r->info3, driver, servername);
5498 result = fill_printer_driver_info4(mem_ctx, &r->info4, driver, servername);
5501 result = fill_printer_driver_info5(mem_ctx, &r->info5, driver, servername);
5504 result = fill_printer_driver_info6(mem_ctx, &r->info6, driver, servername);
5507 result = fill_printer_driver_info8(mem_ctx, &r->info8, driver, servername);
5509 #if 0 /* disabled until marshalling issues are resolved - gd */
5511 result = fill_printer_driver_info101(mem_ctx, &r->info101, driver, servername);
5515 result = WERR_UNKNOWN_LEVEL;
5519 talloc_free(pinfo2);
5520 talloc_free(driver);
5525 /****************************************************************
5526 _spoolss_GetPrinterDriver2
5527 ****************************************************************/
5529 WERROR _spoolss_GetPrinterDriver2(struct pipes_struct *p,
5530 struct spoolss_GetPrinterDriver2 *r)
5532 struct printer_handle *printer;
5537 /* that's an [in out] buffer */
5539 if (!r->in.buffer && (r->in.offered != 0)) {
5540 return WERR_INVALID_PARAM;
5543 DEBUG(4,("_spoolss_GetPrinterDriver2\n"));
5545 if (!(printer = find_printer_index_by_hnd(p, r->in.handle))) {
5546 DEBUG(0,("_spoolss_GetPrinterDriver2: invalid printer handle!\n"));
5547 return WERR_INVALID_PRINTER_NAME;
5551 *r->out.server_major_version = 0;
5552 *r->out.server_minor_version = 0;
5554 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5558 result = construct_printer_driver_info_level(p->mem_ctx,
5559 get_server_info_system(),
5561 r->in.level, r->out.info,
5562 snum, printer->servername,
5564 r->in.client_major_version);
5565 if (!W_ERROR_IS_OK(result)) {
5566 TALLOC_FREE(r->out.info);
5570 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverInfo,
5571 r->out.info, r->in.level);
5572 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
5574 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
5578 /****************************************************************
5579 _spoolss_StartPagePrinter
5580 ****************************************************************/
5582 WERROR _spoolss_StartPagePrinter(struct pipes_struct *p,
5583 struct spoolss_StartPagePrinter *r)
5585 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5588 DEBUG(3,("_spoolss_StartPagePrinter: "
5589 "Error in startpageprinter printer handle\n"));
5593 Printer->page_started = true;
5597 /****************************************************************
5598 _spoolss_EndPagePrinter
5599 ****************************************************************/
5601 WERROR _spoolss_EndPagePrinter(struct pipes_struct *p,
5602 struct spoolss_EndPagePrinter *r)
5606 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5609 DEBUG(2,("_spoolss_EndPagePrinter: Invalid handle (%s:%u:%u).\n",
5610 OUR_HANDLE(r->in.handle)));
5614 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5617 Printer->page_started = false;
5618 print_job_endpage(p->msg_ctx, snum, Printer->jobid);
5623 /****************************************************************
5624 _spoolss_StartDocPrinter
5625 ****************************************************************/
5627 WERROR _spoolss_StartDocPrinter(struct pipes_struct *p,
5628 struct spoolss_StartDocPrinter *r)
5630 struct spoolss_DocumentInfo1 *info_1;
5632 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5636 DEBUG(2,("_spoolss_StartDocPrinter: "
5637 "Invalid handle (%s:%u:%u)\n",
5638 OUR_HANDLE(r->in.handle)));
5642 if (Printer->jobid) {
5643 DEBUG(2, ("_spoolss_StartDocPrinter: "
5644 "StartDocPrinter called twice! "
5645 "(existing jobid = %d)\n", Printer->jobid));
5646 return WERR_INVALID_HANDLE;
5649 if (r->in.level != 1) {
5650 return WERR_UNKNOWN_LEVEL;
5653 info_1 = r->in.info.info1;
5656 * a nice thing with NT is it doesn't listen to what you tell it.
5657 * when asked to send _only_ RAW datas, it tries to send datas
5660 * So I add checks like in NT Server ...
5663 if (info_1->datatype) {
5664 if (strcmp(info_1->datatype, "RAW") != 0) {
5666 return WERR_INVALID_DATATYPE;
5670 /* get the share number of the printer */
5671 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5675 werr = print_job_start(p->server_info,
5679 info_1->document_name,
5680 info_1->output_file,
5684 /* An error occured in print_job_start() so return an appropriate
5687 if (!W_ERROR_IS_OK(werr)) {
5691 Printer->document_started = true;
5692 *r->out.job_id = Printer->jobid;
5697 /****************************************************************
5698 _spoolss_EndDocPrinter
5699 ****************************************************************/
5701 WERROR _spoolss_EndDocPrinter(struct pipes_struct *p,
5702 struct spoolss_EndDocPrinter *r)
5704 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5709 DEBUG(2,("_spoolss_EndDocPrinter: Invalid handle (%s:%u:%u)\n",
5710 OUR_HANDLE(r->in.handle)));
5714 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
5718 Printer->document_started = false;
5719 status = print_job_end(p->msg_ctx, snum, Printer->jobid, NORMAL_CLOSE);
5720 if (!NT_STATUS_IS_OK(status)) {
5721 DEBUG(2, ("_spoolss_EndDocPrinter: "
5722 "print_job_end failed [%s]\n",
5723 nt_errstr(status)));
5727 return ntstatus_to_werror(status);
5730 /****************************************************************
5731 _spoolss_WritePrinter
5732 ****************************************************************/
5734 WERROR _spoolss_WritePrinter(struct pipes_struct *p,
5735 struct spoolss_WritePrinter *r)
5737 ssize_t buffer_written;
5739 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5742 DEBUG(2,("_spoolss_WritePrinter: Invalid handle (%s:%u:%u)\n",
5743 OUR_HANDLE(r->in.handle)));
5744 *r->out.num_written = r->in._data_size;
5748 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5751 /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
5752 buffer_written = print_job_write(server_event_context(),p->msg_ctx,
5753 snum, Printer->jobid,
5754 (const char *)r->in.data.data,
5755 (size_t)r->in._data_size);
5756 if (buffer_written == (ssize_t)-1) {
5757 *r->out.num_written = 0;
5758 if (errno == ENOSPC)
5759 return WERR_NO_SPOOL_SPACE;
5761 return WERR_ACCESS_DENIED;
5764 *r->out.num_written = r->in._data_size;
5769 /********************************************************************
5770 * api_spoolss_getprinter
5771 * called from the spoolss dispatcher
5773 ********************************************************************/
5775 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
5776 struct pipes_struct *p)
5778 const struct auth_serversupplied_info *server_info = p->server_info;
5780 WERROR errcode = WERR_BADFUNC;
5781 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
5784 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n",
5785 OUR_HANDLE(handle)));
5789 if (!get_printer_snum(p, handle, &snum, NULL))
5793 case SPOOLSS_PRINTER_CONTROL_PAUSE:
5794 errcode = print_queue_pause(server_info, p->msg_ctx, snum);
5796 case SPOOLSS_PRINTER_CONTROL_RESUME:
5797 case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
5798 errcode = print_queue_resume(server_info, p->msg_ctx, snum);
5800 case SPOOLSS_PRINTER_CONTROL_PURGE:
5801 errcode = print_queue_purge(server_info, p->msg_ctx, snum);
5804 return WERR_UNKNOWN_LEVEL;
5811 /****************************************************************
5812 _spoolss_AbortPrinter
5813 * From MSDN: "Deletes printer's spool file if printer is configured
5815 ****************************************************************/
5817 WERROR _spoolss_AbortPrinter(struct pipes_struct *p,
5818 struct spoolss_AbortPrinter *r)
5820 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
5822 WERROR errcode = WERR_OK;
5825 DEBUG(2,("_spoolss_AbortPrinter: Invalid handle (%s:%u:%u)\n",
5826 OUR_HANDLE(r->in.handle)));
5830 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
5833 if (!Printer->document_started) {
5834 return WERR_SPL_NO_STARTDOC;
5837 errcode = print_job_delete(p->server_info,
5845 /********************************************************************
5846 * called by spoolss_api_setprinter
5847 * when updating a printer description
5848 ********************************************************************/
5850 static WERROR update_printer_sec(struct policy_handle *handle,
5851 struct pipes_struct *p,
5852 struct sec_desc_buf *secdesc_ctr)
5854 struct spoolss_security_descriptor *new_secdesc = NULL;
5855 struct spoolss_security_descriptor *old_secdesc = NULL;
5856 const char *printer;
5860 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
5862 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
5863 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
5864 OUR_HANDLE(handle)));
5866 result = WERR_BADFID;
5870 if (secdesc_ctr == NULL) {
5871 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
5872 result = WERR_INVALID_PARAM;
5875 printer = lp_const_servicename(snum);
5877 /* Check the user has permissions to change the security
5878 descriptor. By experimentation with two NT machines, the user
5879 requires Full Access to the printer to change security
5882 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
5883 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
5884 result = WERR_ACCESS_DENIED;
5888 /* NT seems to like setting the security descriptor even though
5889 nothing may have actually changed. */
5890 result = winreg_get_printer_secdesc(p->mem_ctx,
5891 get_server_info_system(),
5895 if (!W_ERROR_IS_OK(result)) {
5896 DEBUG(2,("update_printer_sec: winreg_get_printer_secdesc() failed\n"));
5897 result = WERR_BADFID;
5901 if (DEBUGLEVEL >= 10) {
5902 struct security_acl *the_acl;
5905 the_acl = old_secdesc->dacl;
5906 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
5907 printer, the_acl->num_aces));
5909 for (i = 0; i < the_acl->num_aces; i++) {
5910 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5911 &the_acl->aces[i].trustee),
5912 the_acl->aces[i].access_mask));
5915 the_acl = secdesc_ctr->sd->dacl;
5918 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
5919 printer, the_acl->num_aces));
5921 for (i = 0; i < the_acl->num_aces; i++) {
5922 DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
5923 &the_acl->aces[i].trustee),
5924 the_acl->aces[i].access_mask));
5927 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
5931 new_secdesc = sec_desc_merge(p->mem_ctx, secdesc_ctr->sd, old_secdesc);
5932 if (new_secdesc == NULL) {
5933 result = WERR_NOMEM;
5937 if (security_descriptor_equal(new_secdesc, old_secdesc)) {
5942 result = winreg_set_printer_secdesc(p->mem_ctx,
5943 get_server_info_system(),
5952 /********************************************************************
5953 Canonicalize printer info from a client
5954 ********************************************************************/
5956 static bool check_printer_ok(TALLOC_CTX *mem_ctx,
5957 struct spoolss_SetPrinterInfo2 *info2,
5960 fstring printername;
5963 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
5964 "portname=%s drivername=%s comment=%s location=%s\n",
5965 info2->servername, info2->printername, info2->sharename,
5966 info2->portname, info2->drivername, info2->comment,
5969 /* we force some elements to "correct" values */
5970 info2->servername = talloc_asprintf(mem_ctx, "\\\\%s", global_myname());
5971 if (info2->servername == NULL) {
5974 info2->sharename = talloc_strdup(mem_ctx, lp_const_servicename(snum));
5975 if (info2->sharename == NULL) {
5979 /* check to see if we allow printername != sharename */
5980 if (lp_force_printername(snum)) {
5981 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5982 global_myname(), info2->sharename);
5984 /* make sure printername is in \\server\printername format */
5985 fstrcpy(printername, info2->printername);
5987 if ( printername[0] == '\\' && printername[1] == '\\' ) {
5988 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
5992 info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
5993 global_myname(), p);
5995 if (info2->printername == NULL) {
5999 info2->attributes |= PRINTER_ATTRIBUTE_SAMBA;
6000 info2->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
6005 /****************************************************************************
6006 ****************************************************************************/
6008 static WERROR add_port_hook(TALLOC_CTX *ctx, struct security_token *token, const char *portname, const char *uri)
6010 char *cmd = lp_addport_cmd();
6011 char *command = NULL;
6013 bool is_print_op = false;
6016 return WERR_ACCESS_DENIED;
6019 command = talloc_asprintf(ctx,
6020 "%s \"%s\" \"%s\"", cmd, portname, uri );
6026 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
6028 DEBUG(10,("Running [%s]\n", command));
6030 /********* BEGIN SePrintOperatorPrivilege **********/
6035 ret = smbrun(command, NULL);
6040 /********* END SePrintOperatorPrivilege **********/
6042 DEBUGADD(10,("returned [%d]\n", ret));
6044 TALLOC_FREE(command);
6047 return WERR_ACCESS_DENIED;
6053 /****************************************************************************
6054 ****************************************************************************/
6056 static bool add_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
6057 struct spoolss_SetPrinterInfo2 *info2,
6058 const char *remote_machine,
6059 struct messaging_context *msg_ctx)
6061 char *cmd = lp_addprinter_cmd();
6063 char *command = NULL;
6067 bool is_print_op = false;
6069 if (!remote_machine) {
6073 command = talloc_asprintf(ctx,
6074 "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
6075 cmd, info2->printername, info2->sharename,
6076 info2->portname, info2->drivername,
6077 info2->location, info2->comment, remote_machine);
6083 is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
6085 DEBUG(10,("Running [%s]\n", command));
6087 /********* BEGIN SePrintOperatorPrivilege **********/
6092 if ( (ret = smbrun(command, &fd)) == 0 ) {
6093 /* Tell everyone we updated smb.conf. */
6094 message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
6100 /********* END SePrintOperatorPrivilege **********/
6102 DEBUGADD(10,("returned [%d]\n", ret));
6104 TALLOC_FREE(command);
6112 /* reload our services immediately */
6114 reload_services(msg_ctx, -1, false);
6118 /* Get lines and convert them back to dos-codepage */
6119 qlines = fd_lines_load(fd, &numlines, 0, NULL);
6120 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
6123 /* Set the portname to what the script says the portname should be. */
6124 /* but don't require anything to be return from the script exit a good error code */
6127 /* Set the portname to what the script says the portname should be. */
6128 info2->portname = talloc_strdup(ctx, qlines[0]);
6129 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
6132 TALLOC_FREE(qlines);
6136 static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
6137 const struct auth_serversupplied_info *server_info,
6138 struct messaging_context *msg_ctx,
6140 struct spoolss_SetPrinterInfo2 *printer,
6141 struct spoolss_PrinterInfo2 *old_printer)
6143 bool force_update = (old_printer == NULL);
6144 const char *dnsdomname;
6145 const char *longname;
6146 const char *uncname;
6147 const char *spooling;
6149 WERROR result = WERR_OK;
6151 if (force_update || !strequal(printer->drivername, old_printer->drivername)) {
6152 push_reg_sz(mem_ctx, &buffer, printer->drivername);
6153 winreg_set_printer_dataex(mem_ctx,
6157 SPOOL_DSSPOOLER_KEY,
6158 SPOOL_REG_DRIVERNAME,
6163 if (!force_update) {
6164 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
6165 printer->drivername));
6167 notify_printer_driver(server_event_context(), msg_ctx,
6168 snum, printer->drivername ?
6169 printer->drivername : "");
6173 if (force_update || !strequal(printer->comment, old_printer->comment)) {
6174 push_reg_sz(mem_ctx, &buffer, printer->comment);
6175 winreg_set_printer_dataex(mem_ctx,
6179 SPOOL_DSSPOOLER_KEY,
6180 SPOOL_REG_DESCRIPTION,
6185 if (!force_update) {
6186 notify_printer_comment(server_event_context(), msg_ctx,
6187 snum, printer->comment ?
6188 printer->comment : "");
6192 if (force_update || !strequal(printer->sharename, old_printer->sharename)) {
6193 push_reg_sz(mem_ctx, &buffer, printer->sharename);
6194 winreg_set_printer_dataex(mem_ctx,
6198 SPOOL_DSSPOOLER_KEY,
6199 SPOOL_REG_PRINTSHARENAME,
6204 if (!force_update) {
6205 notify_printer_sharename(server_event_context(),
6207 snum, printer->sharename ?
6208 printer->sharename : "");
6212 if (force_update || !strequal(printer->printername, old_printer->printername)) {
6215 p = strrchr(printer->printername, '\\' );
6219 p = printer->printername;
6222 push_reg_sz(mem_ctx, &buffer, p);
6223 winreg_set_printer_dataex(mem_ctx,
6227 SPOOL_DSSPOOLER_KEY,
6228 SPOOL_REG_PRINTERNAME,
6233 if (!force_update) {
6234 notify_printer_printername(server_event_context(),
6235 msg_ctx, snum, p ? p : "");
6239 if (force_update || !strequal(printer->portname, old_printer->portname)) {
6240 push_reg_sz(mem_ctx, &buffer, printer->portname);
6241 winreg_set_printer_dataex(mem_ctx,
6245 SPOOL_DSSPOOLER_KEY,
6251 if (!force_update) {
6252 notify_printer_port(server_event_context(),
6253 msg_ctx, snum, printer->portname ?
6254 printer->portname : "");
6258 if (force_update || !strequal(printer->location, old_printer->location)) {
6259 push_reg_sz(mem_ctx, &buffer, printer->location);
6260 winreg_set_printer_dataex(mem_ctx,
6264 SPOOL_DSSPOOLER_KEY,
6270 if (!force_update) {
6271 notify_printer_location(server_event_context(),
6274 printer->location : "");
6278 if (force_update || !strequal(printer->sepfile, old_printer->sepfile)) {
6279 push_reg_sz(mem_ctx, &buffer, printer->sepfile);
6280 winreg_set_printer_dataex(mem_ctx,
6284 SPOOL_DSSPOOLER_KEY,
6285 SPOOL_REG_PRINTSEPARATORFILE,
6290 if (!force_update) {
6291 notify_printer_sepfile(server_event_context(),
6294 printer->sepfile : "");
6298 if (force_update || printer->starttime != old_printer->starttime) {
6299 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6300 SIVAL(buffer.data, 0, printer->starttime);
6301 winreg_set_printer_dataex(mem_ctx,
6305 SPOOL_DSSPOOLER_KEY,
6306 SPOOL_REG_PRINTSTARTTIME,
6312 if (force_update || printer->untiltime != old_printer->untiltime) {
6313 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6314 SIVAL(buffer.data, 0, printer->untiltime);
6315 winreg_set_printer_dataex(mem_ctx,
6319 SPOOL_DSSPOOLER_KEY,
6320 SPOOL_REG_PRINTENDTIME,
6326 if (force_update || printer->priority != old_printer->priority) {
6327 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6328 SIVAL(buffer.data, 0, printer->priority);
6329 winreg_set_printer_dataex(mem_ctx,
6333 SPOOL_DSSPOOLER_KEY,
6340 if (force_update || printer->attributes != old_printer->attributes) {
6341 buffer = data_blob_talloc(mem_ctx, NULL, 4);
6342 SIVAL(buffer.data, 0, (printer->attributes &
6343 PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS));
6344 winreg_set_printer_dataex(mem_ctx,
6348 SPOOL_DSSPOOLER_KEY,
6349 SPOOL_REG_PRINTKEEPPRINTEDJOBS,
6354 switch (printer->attributes & 0x3) {
6356 spooling = SPOOL_REGVAL_PRINTWHILESPOOLING;
6359 spooling = SPOOL_REGVAL_PRINTAFTERSPOOLED;
6362 spooling = SPOOL_REGVAL_PRINTDIRECT;
6365 spooling = "unknown";
6367 push_reg_sz(mem_ctx, &buffer, spooling);
6368 winreg_set_printer_dataex(mem_ctx,
6372 SPOOL_DSSPOOLER_KEY,
6373 SPOOL_REG_PRINTSPOOLING,
6379 push_reg_sz(mem_ctx, &buffer, global_myname());
6380 winreg_set_printer_dataex(mem_ctx,
6384 SPOOL_DSSPOOLER_KEY,
6385 SPOOL_REG_SHORTSERVERNAME,
6390 dnsdomname = get_mydnsfullname();
6391 if (dnsdomname != NULL && dnsdomname[0] != '\0') {
6392 longname = talloc_strdup(mem_ctx, dnsdomname);
6394 longname = talloc_strdup(mem_ctx, global_myname());
6396 if (longname == NULL) {
6397 result = WERR_NOMEM;
6401 push_reg_sz(mem_ctx, &buffer, longname);
6402 winreg_set_printer_dataex(mem_ctx,
6406 SPOOL_DSSPOOLER_KEY,
6407 SPOOL_REG_SERVERNAME,
6412 uncname = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
6413 global_myname(), printer->sharename);
6414 push_reg_sz(mem_ctx, &buffer, uncname);
6415 winreg_set_printer_dataex(mem_ctx,
6419 SPOOL_DSSPOOLER_KEY,
6429 /********************************************************************
6430 * Called by spoolss_api_setprinter
6431 * when updating a printer description.
6432 ********************************************************************/
6434 static WERROR update_printer(struct pipes_struct *p,
6435 struct policy_handle *handle,
6436 struct spoolss_SetPrinterInfoCtr *info_ctr,
6437 struct spoolss_DeviceMode *devmode)
6439 uint32_t printer_mask = SPOOLSS_PRINTER_INFO_ALL;
6440 struct spoolss_SetPrinterInfo2 *printer = info_ctr->info.info2;
6441 struct spoolss_PrinterInfo2 *old_printer;
6442 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6444 WERROR result = WERR_OK;
6445 TALLOC_CTX *tmp_ctx;
6447 DEBUG(8,("update_printer\n"));
6449 tmp_ctx = talloc_new(p->mem_ctx);
6450 if (tmp_ctx == NULL) {
6455 result = WERR_BADFID;
6459 if (!get_printer_snum(p, handle, &snum, NULL)) {
6460 result = WERR_BADFID;
6464 result = winreg_get_printer(tmp_ctx,
6465 get_server_info_system(),
6467 lp_const_servicename(snum),
6469 if (!W_ERROR_IS_OK(result)) {
6470 result = WERR_BADFID;
6474 /* Do sanity check on the requested changes for Samba */
6475 if (!check_printer_ok(tmp_ctx, printer, snum)) {
6476 result = WERR_INVALID_PARAM;
6480 /* FIXME!!! If the driver has changed we really should verify that
6481 it is installed before doing much else --jerry */
6483 /* Check calling user has permission to update printer description */
6484 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6485 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6486 result = WERR_ACCESS_DENIED;
6490 /* Call addprinter hook */
6491 /* Check changes to see if this is really needed */
6493 if (*lp_addprinter_cmd() &&
6494 (!strequal(printer->drivername, old_printer->drivername) ||
6495 !strequal(printer->comment, old_printer->comment) ||
6496 !strequal(printer->portname, old_printer->portname) ||
6497 !strequal(printer->location, old_printer->location)) )
6499 /* add_printer_hook() will call reload_services() */
6500 if (!add_printer_hook(tmp_ctx, p->server_info->ptok,
6501 printer, p->client_id->addr,
6503 result = WERR_ACCESS_DENIED;
6508 update_dsspooler(tmp_ctx,
6509 get_server_info_system(),
6515 printer_mask &= ~SPOOLSS_PRINTER_INFO_SECDESC;
6517 if (devmode == NULL) {
6518 printer_mask &= ~SPOOLSS_PRINTER_INFO_DEVMODE;
6520 result = winreg_update_printer(tmp_ctx,
6521 get_server_info_system(),
6530 talloc_free(tmp_ctx);
6535 /****************************************************************************
6536 ****************************************************************************/
6537 static WERROR publish_or_unpublish_printer(struct pipes_struct *p,
6538 struct policy_handle *handle,
6539 struct spoolss_SetPrinterInfo7 *info7)
6542 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
6545 struct printer_handle *Printer;
6547 if ( lp_security() != SEC_ADS ) {
6548 return WERR_UNKNOWN_LEVEL;
6551 Printer = find_printer_index_by_hnd(p, handle);
6553 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
6558 if (!get_printer_snum(p, handle, &snum, NULL))
6561 result = winreg_get_printer(p->mem_ctx,
6562 get_server_info_system(),
6564 lp_servicename(snum),
6566 if (!W_ERROR_IS_OK(result)) {
6570 nt_printer_publish(pinfo2,
6571 get_server_info_system(),
6576 TALLOC_FREE(pinfo2);
6579 return WERR_UNKNOWN_LEVEL;
6583 /********************************************************************
6584 ********************************************************************/
6586 static WERROR update_printer_devmode(struct pipes_struct *p,
6587 struct policy_handle *handle,
6588 struct spoolss_DeviceMode *devmode)
6591 struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
6592 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_DEVMODE;
6594 DEBUG(8,("update_printer_devmode\n"));
6600 if (!get_printer_snum(p, handle, &snum, NULL)) {
6604 /* Check calling user has permission to update printer description */
6605 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6606 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6607 return WERR_ACCESS_DENIED;
6610 return winreg_update_printer(p->mem_ctx,
6611 get_server_info_system(),
6613 lp_const_servicename(snum),
6621 /****************************************************************
6623 ****************************************************************/
6625 WERROR _spoolss_SetPrinter(struct pipes_struct *p,
6626 struct spoolss_SetPrinter *r)
6630 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
6633 DEBUG(2,("_spoolss_SetPrinter: Invalid handle (%s:%u:%u)\n",
6634 OUR_HANDLE(r->in.handle)));
6638 /* check the level */
6639 switch (r->in.info_ctr->level) {
6641 return control_printer(r->in.handle, r->in.command, p);
6643 result = update_printer(p, r->in.handle,
6645 r->in.devmode_ctr->devmode);
6646 if (!W_ERROR_IS_OK(result))
6648 if (r->in.secdesc_ctr->sd)
6649 result = update_printer_sec(r->in.handle, p,
6653 return update_printer_sec(r->in.handle, p,
6656 return publish_or_unpublish_printer(p, r->in.handle,
6657 r->in.info_ctr->info.info7);
6659 return update_printer_devmode(p, r->in.handle,
6660 r->in.devmode_ctr->devmode);
6662 return WERR_UNKNOWN_LEVEL;
6666 /****************************************************************
6667 _spoolss_FindClosePrinterNotify
6668 ****************************************************************/
6670 WERROR _spoolss_FindClosePrinterNotify(struct pipes_struct *p,
6671 struct spoolss_FindClosePrinterNotify *r)
6673 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
6676 DEBUG(2,("_spoolss_FindClosePrinterNotify: "
6677 "Invalid handle (%s:%u:%u)\n", OUR_HANDLE(r->in.handle)));
6681 if (Printer->notify.cli_chan != NULL &&
6682 Printer->notify.cli_chan->active_connections > 0) {
6685 if (Printer->printer_type == SPLHND_PRINTER) {
6686 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
6691 srv_spoolss_replycloseprinter(snum, Printer);
6694 Printer->notify.flags=0;
6695 Printer->notify.options=0;
6696 Printer->notify.localmachine[0]='\0';
6697 Printer->notify.printerlocal=0;
6698 TALLOC_FREE(Printer->notify.option);
6703 /****************************************************************
6705 ****************************************************************/
6707 WERROR _spoolss_AddJob(struct pipes_struct *p,
6708 struct spoolss_AddJob *r)
6710 if (!r->in.buffer && (r->in.offered != 0)) {
6711 return WERR_INVALID_PARAM;
6714 /* this is what a NT server returns for AddJob. AddJob must fail on
6715 * non-local printers */
6717 if (r->in.level != 1) {
6718 return WERR_UNKNOWN_LEVEL;
6721 return WERR_INVALID_PARAM;
6724 /****************************************************************************
6726 ****************************************************************************/
6728 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
6729 struct spoolss_JobInfo1 *r,
6730 const print_queue_struct *queue,
6731 int position, int snum,
6732 struct spoolss_PrinterInfo2 *pinfo2)
6736 t = gmtime(&queue->time);
6738 r->job_id = queue->job;
6740 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6741 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6742 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6743 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6744 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6745 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6746 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6747 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6748 r->data_type = talloc_strdup(mem_ctx, "RAW");
6749 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6750 r->text_status = talloc_strdup(mem_ctx, "");
6751 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6753 r->status = nt_printj_status(queue->status);
6754 r->priority = queue->priority;
6755 r->position = position;
6756 r->total_pages = queue->page_count;
6757 r->pages_printed = 0; /* ??? */
6759 init_systemtime(&r->submitted, t);
6764 /****************************************************************************
6766 ****************************************************************************/
6768 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
6769 struct spoolss_JobInfo2 *r,
6770 const print_queue_struct *queue,
6771 int position, int snum,
6772 struct spoolss_PrinterInfo2 *pinfo2,
6773 struct spoolss_DeviceMode *devmode)
6777 t = gmtime(&queue->time);
6779 r->job_id = queue->job;
6781 r->printer_name = talloc_strdup(mem_ctx, lp_servicename(snum));
6782 W_ERROR_HAVE_NO_MEMORY(r->printer_name);
6783 r->server_name = talloc_strdup(mem_ctx, pinfo2->servername);
6784 W_ERROR_HAVE_NO_MEMORY(r->server_name);
6785 r->user_name = talloc_strdup(mem_ctx, queue->fs_user);
6786 W_ERROR_HAVE_NO_MEMORY(r->user_name);
6787 r->document_name = talloc_strdup(mem_ctx, queue->fs_file);
6788 W_ERROR_HAVE_NO_MEMORY(r->document_name);
6789 r->notify_name = talloc_strdup(mem_ctx, queue->fs_user);
6790 W_ERROR_HAVE_NO_MEMORY(r->notify_name);
6791 r->data_type = talloc_strdup(mem_ctx, "RAW");
6792 W_ERROR_HAVE_NO_MEMORY(r->data_type);
6793 r->print_processor = talloc_strdup(mem_ctx, "winprint");
6794 W_ERROR_HAVE_NO_MEMORY(r->print_processor);
6795 r->parameters = talloc_strdup(mem_ctx, "");
6796 W_ERROR_HAVE_NO_MEMORY(r->parameters);
6797 r->driver_name = talloc_strdup(mem_ctx, pinfo2->drivername);
6798 W_ERROR_HAVE_NO_MEMORY(r->driver_name);
6800 r->devmode = devmode;
6802 r->text_status = talloc_strdup(mem_ctx, "");
6803 W_ERROR_HAVE_NO_MEMORY(r->text_status);
6807 r->status = nt_printj_status(queue->status);
6808 r->priority = queue->priority;
6809 r->position = position;
6812 r->total_pages = queue->page_count;
6813 r->size = queue->size;
6814 init_systemtime(&r->submitted, t);
6816 r->pages_printed = 0; /* ??? */
6821 /****************************************************************************
6823 ****************************************************************************/
6825 static WERROR fill_job_info3(TALLOC_CTX *mem_ctx,
6826 struct spoolss_JobInfo3 *r,
6827 const print_queue_struct *queue,
6828 const print_queue_struct *next_queue,
6829 int position, int snum,
6830 struct spoolss_PrinterInfo2 *pinfo2)
6832 r->job_id = queue->job;
6835 r->next_job_id = next_queue->job;
6842 /****************************************************************************
6843 Enumjobs at level 1.
6844 ****************************************************************************/
6846 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
6847 const print_queue_struct *queue,
6848 uint32_t num_queues, int snum,
6849 struct spoolss_PrinterInfo2 *pinfo2,
6850 union spoolss_JobInfo **info_p,
6853 union spoolss_JobInfo *info;
6855 WERROR result = WERR_OK;
6857 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6858 W_ERROR_HAVE_NO_MEMORY(info);
6860 *count = num_queues;
6862 for (i=0; i<*count; i++) {
6863 result = fill_job_info1(info,
6869 if (!W_ERROR_IS_OK(result)) {
6875 if (!W_ERROR_IS_OK(result)) {
6886 /****************************************************************************
6887 Enumjobs at level 2.
6888 ****************************************************************************/
6890 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
6891 const print_queue_struct *queue,
6892 uint32_t num_queues, int snum,
6893 struct spoolss_PrinterInfo2 *pinfo2,
6894 union spoolss_JobInfo **info_p,
6897 union spoolss_JobInfo *info;
6899 WERROR result = WERR_OK;
6901 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6902 W_ERROR_HAVE_NO_MEMORY(info);
6904 *count = num_queues;
6906 for (i=0; i<*count; i++) {
6907 struct spoolss_DeviceMode *devmode;
6909 result = spoolss_create_default_devmode(info,
6910 pinfo2->printername,
6912 if (!W_ERROR_IS_OK(result)) {
6913 DEBUG(3, ("Can't proceed w/o a devmode!"));
6917 result = fill_job_info2(info,
6924 if (!W_ERROR_IS_OK(result)) {
6930 if (!W_ERROR_IS_OK(result)) {
6941 /****************************************************************************
6942 Enumjobs at level 3.
6943 ****************************************************************************/
6945 static WERROR enumjobs_level3(TALLOC_CTX *mem_ctx,
6946 const print_queue_struct *queue,
6947 uint32_t num_queues, int snum,
6948 struct spoolss_PrinterInfo2 *pinfo2,
6949 union spoolss_JobInfo **info_p,
6952 union spoolss_JobInfo *info;
6954 WERROR result = WERR_OK;
6956 info = TALLOC_ARRAY(mem_ctx, union spoolss_JobInfo, num_queues);
6957 W_ERROR_HAVE_NO_MEMORY(info);
6959 *count = num_queues;
6961 for (i=0; i<*count; i++) {
6962 const print_queue_struct *next_queue = NULL;
6965 next_queue = &queue[i+1];
6968 result = fill_job_info3(info,
6975 if (!W_ERROR_IS_OK(result)) {
6981 if (!W_ERROR_IS_OK(result)) {
6992 /****************************************************************
6994 ****************************************************************/
6996 WERROR _spoolss_EnumJobs(struct pipes_struct *p,
6997 struct spoolss_EnumJobs *r)
7000 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
7002 print_status_struct prt_status;
7003 print_queue_struct *queue = NULL;
7006 /* that's an [in out] buffer */
7008 if (!r->in.buffer && (r->in.offered != 0)) {
7009 return WERR_INVALID_PARAM;
7012 DEBUG(4,("_spoolss_EnumJobs\n"));
7016 *r->out.info = NULL;
7018 /* lookup the printer snum and tdb entry */
7020 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7024 result = winreg_get_printer(p->mem_ctx,
7025 get_server_info_system(),
7027 lp_const_servicename(snum),
7029 if (!W_ERROR_IS_OK(result)) {
7033 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
7034 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
7035 count, prt_status.status, prt_status.message));
7039 TALLOC_FREE(pinfo2);
7043 switch (r->in.level) {
7045 result = enumjobs_level1(p->mem_ctx, queue, count, snum,
7046 pinfo2, r->out.info, r->out.count);
7049 result = enumjobs_level2(p->mem_ctx, queue, count, snum,
7050 pinfo2, r->out.info, r->out.count);
7053 result = enumjobs_level3(p->mem_ctx, queue, count, snum,
7054 pinfo2, r->out.info, r->out.count);
7057 result = WERR_UNKNOWN_LEVEL;
7062 TALLOC_FREE(pinfo2);
7064 if (!W_ERROR_IS_OK(result)) {
7068 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7070 *r->out.info, r->in.level,
7072 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7073 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7075 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7078 /****************************************************************
7079 _spoolss_ScheduleJob
7080 ****************************************************************/
7082 WERROR _spoolss_ScheduleJob(struct pipes_struct *p,
7083 struct spoolss_ScheduleJob *r)
7088 /****************************************************************
7089 ****************************************************************/
7091 static WERROR spoolss_setjob_1(TALLOC_CTX *mem_ctx,
7092 struct messaging_context *msg_ctx,
7093 const char *printer_name,
7095 struct spoolss_SetJobInfo1 *r)
7099 if (!print_job_get_name(mem_ctx, printer_name, job_id, &old_doc_name)) {
7103 if (strequal(old_doc_name, r->document_name)) {
7107 if (!print_job_set_name(server_event_context(), msg_ctx,
7108 printer_name, job_id, r->document_name)) {
7115 /****************************************************************
7117 ****************************************************************/
7119 WERROR _spoolss_SetJob(struct pipes_struct *p,
7120 struct spoolss_SetJob *r)
7122 const struct auth_serversupplied_info *server_info = p->server_info;
7124 WERROR errcode = WERR_BADFUNC;
7126 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
7130 if (!print_job_exists(lp_const_servicename(snum), r->in.job_id)) {
7131 return WERR_INVALID_PRINTER_NAME;
7134 switch (r->in.command) {
7135 case SPOOLSS_JOB_CONTROL_CANCEL:
7136 case SPOOLSS_JOB_CONTROL_DELETE:
7137 errcode = print_job_delete(server_info, p->msg_ctx,
7138 snum, r->in.job_id);
7139 if (W_ERROR_EQUAL(errcode, WERR_PRINTER_HAS_JOBS_QUEUED)) {
7143 case SPOOLSS_JOB_CONTROL_PAUSE:
7144 if (print_job_pause(server_info, p->msg_ctx,
7145 snum, r->in.job_id, &errcode)) {
7149 case SPOOLSS_JOB_CONTROL_RESTART:
7150 case SPOOLSS_JOB_CONTROL_RESUME:
7151 if (print_job_resume(server_info, p->msg_ctx,
7152 snum, r->in.job_id, &errcode)) {
7160 return WERR_UNKNOWN_LEVEL;
7163 if (!W_ERROR_IS_OK(errcode)) {
7167 if (r->in.ctr == NULL) {
7171 switch (r->in.ctr->level) {
7173 errcode = spoolss_setjob_1(p->mem_ctx, p->msg_ctx,
7174 lp_const_servicename(snum),
7176 r->in.ctr->info.info1);
7182 return WERR_UNKNOWN_LEVEL;
7188 /****************************************************************************
7189 Enumerates all printer drivers by level and architecture.
7190 ****************************************************************************/
7192 static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
7193 const struct auth_serversupplied_info *server_info,
7194 struct messaging_context *msg_ctx,
7195 const char *servername,
7196 const char *architecture,
7198 union spoolss_DriverInfo **info_p,
7203 struct spoolss_DriverInfo8 *driver;
7204 union spoolss_DriverInfo *info = NULL;
7206 WERROR result = WERR_OK;
7207 uint32_t num_drivers;
7208 const char **drivers;
7213 for (version=0; version<DRIVER_MAX_VERSION; version++) {
7214 result = winreg_get_driver_list(mem_ctx, server_info, msg_ctx,
7215 architecture, version,
7216 &num_drivers, &drivers);
7217 if (!W_ERROR_IS_OK(result)) {
7220 DEBUG(4, ("we have:[%d] drivers in environment"
7221 " [%s] and version [%d]\n",
7222 num_drivers, architecture, version));
7224 if (num_drivers != 0) {
7225 info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
7226 union spoolss_DriverInfo,
7227 count + num_drivers);
7229 DEBUG(0,("enumprinterdrivers_level_by_architecture: "
7230 "failed to enlarge driver info buffer!\n"));
7231 result = WERR_NOMEM;
7236 for (i = 0; i < num_drivers; i++) {
7237 DEBUG(5, ("\tdriver: [%s]\n", drivers[i]));
7239 result = winreg_get_driver(mem_ctx, server_info,
7241 architecture, drivers[i],
7243 if (!W_ERROR_IS_OK(result)) {
7249 result = fill_printer_driver_info1(info, &info[count+i].info1,
7250 driver, servername);
7253 result = fill_printer_driver_info2(info, &info[count+i].info2,
7254 driver, servername);
7257 result = fill_printer_driver_info3(info, &info[count+i].info3,
7258 driver, servername);
7261 result = fill_printer_driver_info4(info, &info[count+i].info4,
7262 driver, servername);
7265 result = fill_printer_driver_info5(info, &info[count+i].info5,
7266 driver, servername);
7269 result = fill_printer_driver_info6(info, &info[count+i].info6,
7270 driver, servername);
7273 result = fill_printer_driver_info8(info, &info[count+i].info8,
7274 driver, servername);
7277 result = WERR_UNKNOWN_LEVEL;
7281 TALLOC_FREE(driver);
7283 if (!W_ERROR_IS_OK(result)) {
7288 count += num_drivers;
7289 TALLOC_FREE(drivers);
7293 TALLOC_FREE(drivers);
7295 if (!W_ERROR_IS_OK(result)) {
7306 /****************************************************************************
7307 Enumerates all printer drivers by level.
7308 ****************************************************************************/
7310 static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
7311 const struct auth_serversupplied_info *server_info,
7312 struct messaging_context *msg_ctx,
7313 const char *servername,
7314 const char *architecture,
7316 union spoolss_DriverInfo **info_p,
7320 WERROR result = WERR_OK;
7322 if (strequal(architecture, SPOOLSS_ARCHITECTURE_ALL)) {
7324 for (a=0; archi_table[a].long_archi != NULL; a++) {
7326 union spoolss_DriverInfo *info = NULL;
7329 result = enumprinterdrivers_level_by_architecture(mem_ctx,
7333 archi_table[a].long_archi,
7337 if (!W_ERROR_IS_OK(result)) {
7341 for (i=0; i < count; i++) {
7342 ADD_TO_ARRAY(mem_ctx, union spoolss_DriverInfo,
7343 info[i], info_p, count_p);
7350 return enumprinterdrivers_level_by_architecture(mem_ctx,
7360 /****************************************************************
7361 _spoolss_EnumPrinterDrivers
7362 ****************************************************************/
7364 WERROR _spoolss_EnumPrinterDrivers(struct pipes_struct *p,
7365 struct spoolss_EnumPrinterDrivers *r)
7367 const char *cservername;
7370 /* that's an [in out] buffer */
7372 if (!r->in.buffer && (r->in.offered != 0)) {
7373 return WERR_INVALID_PARAM;
7376 DEBUG(4,("_spoolss_EnumPrinterDrivers\n"));
7380 *r->out.info = NULL;
7382 cservername = canon_servername(r->in.server);
7384 if (!is_myname_or_ipaddr(cservername)) {
7385 return WERR_UNKNOWN_PRINTER_DRIVER;
7388 result = enumprinterdrivers_level(p->mem_ctx,
7389 get_server_info_system(),
7396 if (!W_ERROR_IS_OK(result)) {
7400 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7401 spoolss_EnumPrinterDrivers,
7402 *r->out.info, r->in.level,
7404 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7405 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7407 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7410 /****************************************************************
7412 ****************************************************************/
7414 WERROR _spoolss_EnumForms(struct pipes_struct *p,
7415 struct spoolss_EnumForms *r)
7421 *r->out.info = NULL;
7423 /* that's an [in out] buffer */
7425 if (!r->in.buffer && (r->in.offered != 0) ) {
7426 return WERR_INVALID_PARAM;
7429 DEBUG(4,("_spoolss_EnumForms\n"));
7430 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7431 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7433 switch (r->in.level) {
7435 result = winreg_printer_enumforms1(p->mem_ctx,
7436 get_server_info_system(),
7442 result = WERR_UNKNOWN_LEVEL;
7446 if (!W_ERROR_IS_OK(result)) {
7450 if (*r->out.count == 0) {
7451 return WERR_NO_MORE_ITEMS;
7454 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7456 *r->out.info, r->in.level,
7458 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7459 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7461 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7464 /****************************************************************
7466 ****************************************************************/
7468 WERROR _spoolss_GetForm(struct pipes_struct *p,
7469 struct spoolss_GetForm *r)
7473 /* that's an [in out] buffer */
7475 if (!r->in.buffer && (r->in.offered != 0)) {
7476 return WERR_INVALID_PARAM;
7479 DEBUG(4,("_spoolss_GetForm\n"));
7480 DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
7481 DEBUGADD(5,("Info level [%d]\n", r->in.level));
7483 switch (r->in.level) {
7485 result = winreg_printer_getform1(p->mem_ctx,
7486 get_server_info_system(),
7489 &r->out.info->info1);
7492 result = WERR_UNKNOWN_LEVEL;
7496 if (!W_ERROR_IS_OK(result)) {
7497 TALLOC_FREE(r->out.info);
7501 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo,
7502 r->out.info, r->in.level);
7503 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
7505 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7508 /****************************************************************************
7509 ****************************************************************************/
7511 static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
7512 struct spoolss_PortInfo1 *r,
7515 r->port_name = talloc_strdup(mem_ctx, name);
7516 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7521 /****************************************************************************
7522 TODO: This probably needs distinguish between TCP/IP and Local ports
7524 ****************************************************************************/
7526 static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
7527 struct spoolss_PortInfo2 *r,
7530 r->port_name = talloc_strdup(mem_ctx, name);
7531 W_ERROR_HAVE_NO_MEMORY(r->port_name);
7533 r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
7534 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
7536 r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT);
7537 W_ERROR_HAVE_NO_MEMORY(r->description);
7539 r->port_type = SPOOLSS_PORT_TYPE_WRITE;
7546 /****************************************************************************
7547 wrapper around the enumer ports command
7548 ****************************************************************************/
7550 static WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines)
7552 char *cmd = lp_enumports_cmd();
7553 char **qlines = NULL;
7554 char *command = NULL;
7562 /* if no hook then just fill in the default port */
7565 if (!(qlines = TALLOC_ARRAY( NULL, char*, 2 ))) {
7568 if (!(qlines[0] = talloc_strdup(qlines, SAMBA_PRINTER_PORT_NAME ))) {
7569 TALLOC_FREE(qlines);
7576 /* we have a valid enumport command */
7578 command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
7583 DEBUG(10,("Running [%s]\n", command));
7584 ret = smbrun(command, &fd);
7585 DEBUG(10,("Returned [%d]\n", ret));
7586 TALLOC_FREE(command);
7591 return WERR_ACCESS_DENIED;
7595 qlines = fd_lines_load(fd, &numlines, 0, NULL);
7596 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
7606 /****************************************************************************
7608 ****************************************************************************/
7610 static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
7611 union spoolss_PortInfo **info_p,
7614 union spoolss_PortInfo *info = NULL;
7616 WERROR result = WERR_OK;
7617 char **qlines = NULL;
7620 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7621 if (!W_ERROR_IS_OK(result)) {
7626 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7628 DEBUG(10,("Returning WERR_NOMEM\n"));
7629 result = WERR_NOMEM;
7633 for (i=0; i<numlines; i++) {
7634 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7635 result = fill_port_1(info, &info[i].info1, qlines[i]);
7636 if (!W_ERROR_IS_OK(result)) {
7641 TALLOC_FREE(qlines);
7644 if (!W_ERROR_IS_OK(result)) {
7646 TALLOC_FREE(qlines);
7658 /****************************************************************************
7660 ****************************************************************************/
7662 static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
7663 union spoolss_PortInfo **info_p,
7666 union spoolss_PortInfo *info = NULL;
7668 WERROR result = WERR_OK;
7669 char **qlines = NULL;
7672 result = enumports_hook(talloc_tos(), &numlines, &qlines );
7673 if (!W_ERROR_IS_OK(result)) {
7678 info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
7680 DEBUG(10,("Returning WERR_NOMEM\n"));
7681 result = WERR_NOMEM;
7685 for (i=0; i<numlines; i++) {
7686 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7687 result = fill_port_2(info, &info[i].info2, qlines[i]);
7688 if (!W_ERROR_IS_OK(result)) {
7693 TALLOC_FREE(qlines);
7696 if (!W_ERROR_IS_OK(result)) {
7698 TALLOC_FREE(qlines);
7710 /****************************************************************
7712 ****************************************************************/
7714 WERROR _spoolss_EnumPorts(struct pipes_struct *p,
7715 struct spoolss_EnumPorts *r)
7719 /* that's an [in out] buffer */
7721 if (!r->in.buffer && (r->in.offered != 0)) {
7722 return WERR_INVALID_PARAM;
7725 DEBUG(4,("_spoolss_EnumPorts\n"));
7729 *r->out.info = NULL;
7731 switch (r->in.level) {
7733 result = enumports_level_1(p->mem_ctx, r->out.info,
7737 result = enumports_level_2(p->mem_ctx, r->out.info,
7741 return WERR_UNKNOWN_LEVEL;
7744 if (!W_ERROR_IS_OK(result)) {
7748 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
7750 *r->out.info, r->in.level,
7752 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
7753 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
7755 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
7758 /****************************************************************************
7759 ****************************************************************************/
7761 static WERROR spoolss_addprinterex_level_2(struct pipes_struct *p,
7763 struct spoolss_SetPrinterInfoCtr *info_ctr,
7764 struct spoolss_DeviceMode *devmode,
7765 struct security_descriptor *secdesc,
7766 struct spoolss_UserLevelCtr *user_ctr,
7767 struct policy_handle *handle)
7769 struct spoolss_SetPrinterInfo2 *info2 = info_ctr->info.info2;
7770 uint32_t info2_mask = SPOOLSS_PRINTER_INFO_ALL;
7772 WERROR err = WERR_OK;
7774 /* samba does not have a concept of local, non-shared printers yet, so
7775 * make sure we always setup sharename - gd */
7776 if ((info2->sharename == NULL || info2->sharename[0] == '\0') &&
7777 (info2->printername != NULL && info2->printername[0] != '\0')) {
7778 DEBUG(5, ("spoolss_addprinterex_level_2: "
7779 "no sharename has been set, setting printername %s as sharename\n",
7780 info2->printername));
7781 info2->sharename = info2->printername;
7784 /* check to see if the printer already exists */
7785 if ((snum = print_queue_snum(info2->sharename)) != -1) {
7786 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7788 return WERR_PRINTER_ALREADY_EXISTS;
7791 if (!lp_force_printername(GLOBAL_SECTION_SNUM)) {
7792 if ((snum = print_queue_snum(info2->printername)) != -1) {
7793 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7794 info2->printername));
7795 return WERR_PRINTER_ALREADY_EXISTS;
7799 /* validate printer info struct */
7800 if (!info2->printername || strlen(info2->printername) == 0) {
7801 return WERR_INVALID_PRINTER_NAME;
7803 if (!info2->portname || strlen(info2->portname) == 0) {
7804 return WERR_UNKNOWN_PORT;
7806 if (!info2->drivername || strlen(info2->drivername) == 0) {
7807 return WERR_UNKNOWN_PRINTER_DRIVER;
7809 if (!info2->printprocessor || strlen(info2->printprocessor) == 0) {
7810 return WERR_UNKNOWN_PRINTPROCESSOR;
7813 /* FIXME!!! smbd should check to see if the driver is installed before
7814 trying to add a printer like this --jerry */
7816 if (*lp_addprinter_cmd() ) {
7817 if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
7818 info2, p->client_id->addr,
7820 return WERR_ACCESS_DENIED;
7823 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no"
7824 "smb.conf parameter \"addprinter command\" is defined. This"
7825 "parameter must exist for this call to succeed\n",
7826 info2->sharename ));
7829 if ((snum = print_queue_snum(info2->sharename)) == -1) {
7830 return WERR_ACCESS_DENIED;
7833 /* you must be a printer admin to add a new printer */
7834 if (!print_access_check(p->server_info,
7837 PRINTER_ACCESS_ADMINISTER)) {
7838 return WERR_ACCESS_DENIED;
7842 * Do sanity check on the requested changes for Samba.
7845 if (!check_printer_ok(p->mem_ctx, info2, snum)) {
7846 return WERR_INVALID_PARAM;
7849 if (devmode == NULL) {
7850 info2_mask = ~SPOOLSS_PRINTER_INFO_DEVMODE;
7853 update_dsspooler(p->mem_ctx,
7854 get_server_info_system(),
7860 err = winreg_update_printer(p->mem_ctx,
7861 get_server_info_system(),
7868 if (!W_ERROR_IS_OK(err)) {
7872 err = open_printer_hnd(p, handle, info2->printername, PRINTER_ACCESS_ADMINISTER);
7873 if (!W_ERROR_IS_OK(err)) {
7874 /* Handle open failed - remove addition. */
7875 ZERO_STRUCTP(handle);
7882 /****************************************************************
7883 _spoolss_AddPrinterEx
7884 ****************************************************************/
7886 WERROR _spoolss_AddPrinterEx(struct pipes_struct *p,
7887 struct spoolss_AddPrinterEx *r)
7889 switch (r->in.info_ctr->level) {
7891 /* we don't handle yet */
7892 /* but I know what to do ... */
7893 return WERR_UNKNOWN_LEVEL;
7895 return spoolss_addprinterex_level_2(p, r->in.server,
7897 r->in.devmode_ctr->devmode,
7898 r->in.secdesc_ctr->sd,
7899 r->in.userlevel_ctr,
7902 return WERR_UNKNOWN_LEVEL;
7906 /****************************************************************
7908 ****************************************************************/
7910 WERROR _spoolss_AddPrinter(struct pipes_struct *p,
7911 struct spoolss_AddPrinter *r)
7913 struct spoolss_AddPrinterEx a;
7914 struct spoolss_UserLevelCtr userlevel_ctr;
7916 ZERO_STRUCT(userlevel_ctr);
7918 userlevel_ctr.level = 1;
7920 a.in.server = r->in.server;
7921 a.in.info_ctr = r->in.info_ctr;
7922 a.in.devmode_ctr = r->in.devmode_ctr;
7923 a.in.secdesc_ctr = r->in.secdesc_ctr;
7924 a.in.userlevel_ctr = &userlevel_ctr;
7925 a.out.handle = r->out.handle;
7927 return _spoolss_AddPrinterEx(p, &a);
7930 /****************************************************************
7931 _spoolss_AddPrinterDriverEx
7932 ****************************************************************/
7934 WERROR _spoolss_AddPrinterDriverEx(struct pipes_struct *p,
7935 struct spoolss_AddPrinterDriverEx *r)
7937 WERROR err = WERR_OK;
7938 const char *driver_name = NULL;
7943 case NDR_SPOOLSS_ADDPRINTERDRIVER:
7944 fn = "_spoolss_AddPrinterDriver";
7946 case NDR_SPOOLSS_ADDPRINTERDRIVEREX:
7947 fn = "_spoolss_AddPrinterDriverEx";
7950 return WERR_INVALID_PARAM;
7954 * we only support the semantics of AddPrinterDriver()
7955 * i.e. only copy files that are newer than existing ones
7958 if (r->in.flags == 0) {
7959 return WERR_INVALID_PARAM;
7962 if (r->in.flags != APD_COPY_NEW_FILES) {
7963 return WERR_ACCESS_DENIED;
7967 if (r->in.info_ctr->level != 3 && r->in.info_ctr->level != 6) {
7968 /* Clever hack from Martin Zielinski <mz@seh.de>
7969 * to allow downgrade from level 8 (Vista).
7971 DEBUG(0,("%s: level %d not yet implemented\n", fn,
7972 r->in.info_ctr->level));
7973 return WERR_UNKNOWN_LEVEL;
7976 DEBUG(5,("Cleaning driver's information\n"));
7977 err = clean_up_driver_struct(p->mem_ctx, p, r->in.info_ctr);
7978 if (!W_ERROR_IS_OK(err))
7981 DEBUG(5,("Moving driver to final destination\n"));
7982 if( !W_ERROR_IS_OK(err = move_driver_to_download_area(p, r->in.info_ctr,
7987 err = winreg_add_driver(p->mem_ctx,
7988 get_server_info_system(),
7993 if (!W_ERROR_IS_OK(err)) {
7998 * I think this is where he DrvUpgradePrinter() hook would be
7999 * be called in a driver's interface DLL on a Windows NT 4.0/2k
8000 * server. Right now, we just need to send ourselves a message
8001 * to update each printer bound to this driver. --jerry
8004 if (!srv_spoolss_drv_upgrade_printer(driver_name, p->msg_ctx)) {
8005 DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
8013 /****************************************************************
8014 _spoolss_AddPrinterDriver
8015 ****************************************************************/
8017 WERROR _spoolss_AddPrinterDriver(struct pipes_struct *p,
8018 struct spoolss_AddPrinterDriver *r)
8020 struct spoolss_AddPrinterDriverEx a;
8022 switch (r->in.info_ctr->level) {
8029 return WERR_UNKNOWN_LEVEL;
8032 a.in.servername = r->in.servername;
8033 a.in.info_ctr = r->in.info_ctr;
8034 a.in.flags = APD_COPY_NEW_FILES;
8036 return _spoolss_AddPrinterDriverEx(p, &a);
8039 /****************************************************************************
8040 ****************************************************************************/
8042 struct _spoolss_paths {
8048 enum { SPOOLSS_DRIVER_PATH, SPOOLSS_PRTPROCS_PATH };
8050 static const struct _spoolss_paths spoolss_paths[]= {
8051 { SPOOLSS_DRIVER_PATH, "print$", "DRIVERS" },
8052 { SPOOLSS_PRTPROCS_PATH, "prnproc$", "PRTPROCS" }
8055 static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
8056 const char *servername,
8057 const char *environment,
8061 const char *pservername = NULL;
8062 const char *long_archi = SPOOLSS_ARCHITECTURE_NT_X86;
8063 const char *short_archi;
8067 /* environment may be empty */
8068 if (environment && strlen(environment)) {
8069 long_archi = environment;
8072 /* servername may be empty */
8073 if (servername && strlen(servername)) {
8074 pservername = canon_servername(servername);
8076 if (!is_myname_or_ipaddr(pservername)) {
8077 return WERR_INVALID_PARAM;
8081 if (!(short_archi = get_short_archi(long_archi))) {
8082 return WERR_INVALID_ENVIRONMENT;
8085 switch (component) {
8086 case SPOOLSS_PRTPROCS_PATH:
8087 case SPOOLSS_DRIVER_PATH:
8089 *path = talloc_asprintf(mem_ctx,
8092 spoolss_paths[component].share,
8095 *path = talloc_asprintf(mem_ctx, "%s\\%s\\%s",
8096 SPOOLSS_DEFAULT_SERVER_PATH,
8097 spoolss_paths[component].dir,
8102 return WERR_INVALID_PARAM;
8112 /****************************************************************************
8113 ****************************************************************************/
8115 static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
8116 const char *servername,
8117 const char *environment,
8118 struct spoolss_DriverDirectoryInfo1 *r)
8123 werr = compose_spoolss_server_path(mem_ctx,
8126 SPOOLSS_DRIVER_PATH,
8128 if (!W_ERROR_IS_OK(werr)) {
8132 DEBUG(4,("printer driver directory: [%s]\n", path));
8134 r->directory_name = path;
8139 /****************************************************************
8140 _spoolss_GetPrinterDriverDirectory
8141 ****************************************************************/
8143 WERROR _spoolss_GetPrinterDriverDirectory(struct pipes_struct *p,
8144 struct spoolss_GetPrinterDriverDirectory *r)
8148 /* that's an [in out] buffer */
8150 if (!r->in.buffer && (r->in.offered != 0)) {
8151 return WERR_INVALID_PARAM;
8154 DEBUG(5,("_spoolss_GetPrinterDriverDirectory: level %d\n",
8159 /* r->in.level is ignored */
8161 werror = getprinterdriverdir_level_1(p->mem_ctx,
8164 &r->out.info->info1);
8165 if (!W_ERROR_IS_OK(werror)) {
8166 TALLOC_FREE(r->out.info);
8170 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_DriverDirectoryInfo,
8171 r->out.info, r->in.level);
8172 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
8174 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8177 /****************************************************************
8178 _spoolss_EnumPrinterData
8179 ****************************************************************/
8181 WERROR _spoolss_EnumPrinterData(struct pipes_struct *p,
8182 struct spoolss_EnumPrinterData *r)
8185 struct spoolss_EnumPrinterDataEx r2;
8187 struct spoolss_PrinterEnumValues *info, *val = NULL;
8190 r2.in.handle = r->in.handle;
8191 r2.in.key_name = "PrinterDriverData";
8193 r2.out.count = &count;
8194 r2.out.info = &info;
8195 r2.out.needed = &needed;
8197 result = _spoolss_EnumPrinterDataEx(p, &r2);
8198 if (W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
8199 r2.in.offered = needed;
8200 result = _spoolss_EnumPrinterDataEx(p, &r2);
8202 if (!W_ERROR_IS_OK(result)) {
8207 * The NT machine wants to know the biggest size of value and data
8209 * cf: MSDN EnumPrinterData remark section
8212 if (!r->in.value_offered && !r->in.data_offered) {
8213 uint32_t biggest_valuesize = 0;
8214 uint32_t biggest_datasize = 0;
8217 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
8219 for (i=0; i<count; i++) {
8221 name_length = strlen(info[i].value_name);
8222 if (strlen(info[i].value_name) > biggest_valuesize) {
8223 biggest_valuesize = name_length;
8226 if (info[i].data_length > biggest_datasize) {
8227 biggest_datasize = info[i].data_length;
8230 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
8234 /* the value is an UNICODE string but real_value_size is the length
8235 in bytes including the trailing 0 */
8237 *r->out.value_needed = 2 * (1 + biggest_valuesize);
8238 *r->out.data_needed = biggest_datasize;
8240 DEBUG(6,("final values: [%d], [%d]\n",
8241 *r->out.value_needed, *r->out.data_needed));
8246 if (r->in.enum_index < count) {
8247 val = &info[r->in.enum_index];
8251 /* out_value should default to "" or else NT4 has
8252 problems unmarshalling the response */
8254 if (r->in.value_offered) {
8255 *r->out.value_needed = 1;
8256 r->out.value_name = talloc_strdup(r, "");
8257 if (!r->out.value_name) {
8261 r->out.value_name = NULL;
8262 *r->out.value_needed = 0;
8265 /* the data is counted in bytes */
8267 *r->out.data_needed = r->in.data_offered;
8269 result = WERR_NO_MORE_ITEMS;
8273 * - counted in bytes in the request
8274 * - counted in UNICODE chars in the max reply
8275 * - counted in bytes in the real size
8277 * take a pause *before* coding not *during* coding
8281 if (r->in.value_offered) {
8282 r->out.value_name = talloc_strdup(r, val->value_name);
8283 if (!r->out.value_name) {
8286 *r->out.value_needed = val->value_name_len;
8288 r->out.value_name = NULL;
8289 *r->out.value_needed = 0;
8294 *r->out.type = val->type;
8296 /* data - counted in bytes */
8299 * See the section "Dynamically Typed Query Parameters"
8303 if (r->out.data && val->data && val->data->data &&
8304 val->data_length && r->in.data_offered) {
8305 memcpy(r->out.data, val->data->data,
8306 MIN(val->data_length,r->in.data_offered));
8309 *r->out.data_needed = val->data_length;
8317 /****************************************************************
8318 _spoolss_SetPrinterData
8319 ****************************************************************/
8321 WERROR _spoolss_SetPrinterData(struct pipes_struct *p,
8322 struct spoolss_SetPrinterData *r)
8324 struct spoolss_SetPrinterDataEx r2;
8326 r2.in.handle = r->in.handle;
8327 r2.in.key_name = "PrinterDriverData";
8328 r2.in.value_name = r->in.value_name;
8329 r2.in.type = r->in.type;
8330 r2.in.data = r->in.data;
8331 r2.in.offered = r->in.offered;
8333 return _spoolss_SetPrinterDataEx(p, &r2);
8336 /****************************************************************
8337 _spoolss_ResetPrinter
8338 ****************************************************************/
8340 WERROR _spoolss_ResetPrinter(struct pipes_struct *p,
8341 struct spoolss_ResetPrinter *r)
8343 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8346 DEBUG(5,("_spoolss_ResetPrinter\n"));
8349 * All we do is to check to see if the handle and queue is valid.
8350 * This call really doesn't mean anything to us because we only
8351 * support RAW printing. --jerry
8355 DEBUG(2,("_spoolss_ResetPrinter: Invalid handle (%s:%u:%u).\n",
8356 OUR_HANDLE(r->in.handle)));
8360 if (!get_printer_snum(p, r->in.handle, &snum, NULL))
8364 /* blindly return success */
8368 /****************************************************************
8369 _spoolss_DeletePrinterData
8370 ****************************************************************/
8372 WERROR _spoolss_DeletePrinterData(struct pipes_struct *p,
8373 struct spoolss_DeletePrinterData *r)
8375 struct spoolss_DeletePrinterDataEx r2;
8377 r2.in.handle = r->in.handle;
8378 r2.in.key_name = "PrinterDriverData";
8379 r2.in.value_name = r->in.value_name;
8381 return _spoolss_DeletePrinterDataEx(p, &r2);
8384 /****************************************************************
8386 ****************************************************************/
8388 WERROR _spoolss_AddForm(struct pipes_struct *p,
8389 struct spoolss_AddForm *r)
8391 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8393 WERROR status = WERR_OK;
8395 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8397 DEBUG(5,("_spoolss_AddForm\n"));
8400 DEBUG(2,("_spoolss_AddForm: Invalid handle (%s:%u:%u).\n",
8401 OUR_HANDLE(r->in.handle)));
8405 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8406 and not a printer admin, then fail */
8408 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8409 !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR) &&
8410 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8411 p->server_info->info3->base.domain.string,
8413 p->server_info->ptok,
8414 lp_printer_admin(snum))) {
8415 DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
8416 return WERR_ACCESS_DENIED;
8419 switch (form->flags) {
8420 case SPOOLSS_FORM_USER:
8421 case SPOOLSS_FORM_BUILTIN:
8422 case SPOOLSS_FORM_PRINTER:
8425 return WERR_INVALID_PARAM;
8428 status = winreg_printer_addform1(p->mem_ctx,
8429 get_server_info_system(),
8432 if (!W_ERROR_IS_OK(status)) {
8437 * ChangeID must always be set if this is a printer
8439 if (Printer->printer_type == SPLHND_PRINTER) {
8440 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8444 status = winreg_printer_update_changeid(p->mem_ctx,
8445 get_server_info_system(),
8447 lp_const_servicename(snum));
8448 if (!W_ERROR_IS_OK(status)) {
8456 /****************************************************************
8458 ****************************************************************/
8460 WERROR _spoolss_DeleteForm(struct pipes_struct *p,
8461 struct spoolss_DeleteForm *r)
8463 const char *form_name = r->in.form_name;
8464 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8466 WERROR status = WERR_OK;
8468 DEBUG(5,("_spoolss_DeleteForm\n"));
8471 DEBUG(2,("_spoolss_DeleteForm: Invalid handle (%s:%u:%u).\n",
8472 OUR_HANDLE(r->in.handle)));
8476 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8477 !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR) &&
8478 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8479 p->server_info->info3->base.domain.string,
8481 p->server_info->ptok,
8482 lp_printer_admin(snum))) {
8483 DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
8484 return WERR_ACCESS_DENIED;
8487 status = winreg_printer_deleteform1(p->mem_ctx,
8488 get_server_info_system(),
8491 if (!W_ERROR_IS_OK(status)) {
8496 * ChangeID must always be set if this is a printer
8498 if (Printer->printer_type == SPLHND_PRINTER) {
8499 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8503 status = winreg_printer_update_changeid(p->mem_ctx,
8504 get_server_info_system(),
8506 lp_const_servicename(snum));
8507 if (!W_ERROR_IS_OK(status)) {
8515 /****************************************************************
8517 ****************************************************************/
8519 WERROR _spoolss_SetForm(struct pipes_struct *p,
8520 struct spoolss_SetForm *r)
8522 struct spoolss_AddFormInfo1 *form = r->in.info.info1;
8523 const char *form_name = r->in.form_name;
8525 WERROR status = WERR_OK;
8527 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
8529 DEBUG(5,("_spoolss_SetForm\n"));
8532 DEBUG(2,("_spoolss_SetForm: Invalid handle (%s:%u:%u).\n",
8533 OUR_HANDLE(r->in.handle)));
8537 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
8538 and not a printer admin, then fail */
8540 if ((p->server_info->utok.uid != sec_initial_uid()) &&
8541 !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR) &&
8542 !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
8543 p->server_info->info3->base.domain.string,
8545 p->server_info->ptok,
8546 lp_printer_admin(snum))) {
8547 DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
8548 return WERR_ACCESS_DENIED;
8551 status = winreg_printer_setform1(p->mem_ctx,
8552 get_server_info_system(),
8556 if (!W_ERROR_IS_OK(status)) {
8561 * ChangeID must always be set if this is a printer
8563 if (Printer->printer_type == SPLHND_PRINTER) {
8564 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
8568 status = winreg_printer_update_changeid(p->mem_ctx,
8569 get_server_info_system(),
8571 lp_const_servicename(snum));
8572 if (!W_ERROR_IS_OK(status)) {
8580 /****************************************************************************
8581 fill_print_processor1
8582 ****************************************************************************/
8584 static WERROR fill_print_processor1(TALLOC_CTX *mem_ctx,
8585 struct spoolss_PrintProcessorInfo1 *r,
8586 const char *print_processor_name)
8588 r->print_processor_name = talloc_strdup(mem_ctx, print_processor_name);
8589 W_ERROR_HAVE_NO_MEMORY(r->print_processor_name);
8594 /****************************************************************************
8595 enumprintprocessors level 1.
8596 ****************************************************************************/
8598 static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
8599 union spoolss_PrintProcessorInfo **info_p,
8602 union spoolss_PrintProcessorInfo *info;
8605 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcessorInfo, 1);
8606 W_ERROR_HAVE_NO_MEMORY(info);
8610 result = fill_print_processor1(info, &info[0].info1, "winprint");
8611 if (!W_ERROR_IS_OK(result)) {
8616 if (!W_ERROR_IS_OK(result)) {
8627 /****************************************************************
8628 _spoolss_EnumPrintProcessors
8629 ****************************************************************/
8631 WERROR _spoolss_EnumPrintProcessors(struct pipes_struct *p,
8632 struct spoolss_EnumPrintProcessors *r)
8636 /* that's an [in out] buffer */
8638 if (!r->in.buffer && (r->in.offered != 0)) {
8639 return WERR_INVALID_PARAM;
8642 DEBUG(5,("_spoolss_EnumPrintProcessors\n"));
8645 * Enumerate the print processors ...
8647 * Just reply with "winprint", to keep NT happy
8648 * and I can use my nice printer checker.
8653 *r->out.info = NULL;
8655 if (!get_short_archi(r->in.environment)) {
8656 return WERR_INVALID_ENVIRONMENT;
8659 switch (r->in.level) {
8661 result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
8665 return WERR_UNKNOWN_LEVEL;
8668 if (!W_ERROR_IS_OK(result)) {
8672 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8673 spoolss_EnumPrintProcessors,
8674 *r->out.info, r->in.level,
8676 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8677 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8679 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8682 /****************************************************************************
8683 fill_printprocdatatype1
8684 ****************************************************************************/
8686 static WERROR fill_printprocdatatype1(TALLOC_CTX *mem_ctx,
8687 struct spoolss_PrintProcDataTypesInfo1 *r,
8688 const char *name_array)
8690 r->name_array = talloc_strdup(mem_ctx, name_array);
8691 W_ERROR_HAVE_NO_MEMORY(r->name_array);
8696 /****************************************************************************
8697 enumprintprocdatatypes level 1.
8698 ****************************************************************************/
8700 static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
8701 union spoolss_PrintProcDataTypesInfo **info_p,
8705 union spoolss_PrintProcDataTypesInfo *info;
8707 info = TALLOC_ARRAY(mem_ctx, union spoolss_PrintProcDataTypesInfo, 1);
8708 W_ERROR_HAVE_NO_MEMORY(info);
8712 result = fill_printprocdatatype1(info, &info[0].info1, "RAW");
8713 if (!W_ERROR_IS_OK(result)) {
8718 if (!W_ERROR_IS_OK(result)) {
8729 /****************************************************************
8730 _spoolss_EnumPrintProcDataTypes
8731 ****************************************************************/
8733 WERROR _spoolss_EnumPrintProcDataTypes(struct pipes_struct *p,
8734 struct spoolss_EnumPrintProcDataTypes *r)
8738 /* that's an [in out] buffer */
8740 if (!r->in.buffer && (r->in.offered != 0)) {
8741 return WERR_INVALID_PARAM;
8744 DEBUG(5,("_spoolss_EnumPrintProcDataTypes\n"));
8748 *r->out.info = NULL;
8750 if (r->in.print_processor_name == NULL ||
8751 !strequal(r->in.print_processor_name, "winprint")) {
8752 return WERR_UNKNOWN_PRINTPROCESSOR;
8755 switch (r->in.level) {
8757 result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
8761 return WERR_UNKNOWN_LEVEL;
8764 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8765 spoolss_EnumPrintProcDataTypes,
8766 *r->out.info, r->in.level,
8768 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8769 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8771 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8774 /****************************************************************************
8776 ****************************************************************************/
8778 static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx,
8779 struct spoolss_MonitorInfo1 *r,
8780 const char *monitor_name)
8782 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8783 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8788 /****************************************************************************
8790 ****************************************************************************/
8792 static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx,
8793 struct spoolss_MonitorInfo2 *r,
8794 const char *monitor_name,
8795 const char *environment,
8796 const char *dll_name)
8798 r->monitor_name = talloc_strdup(mem_ctx, monitor_name);
8799 W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
8800 r->environment = talloc_strdup(mem_ctx, environment);
8801 W_ERROR_HAVE_NO_MEMORY(r->environment);
8802 r->dll_name = talloc_strdup(mem_ctx, dll_name);
8803 W_ERROR_HAVE_NO_MEMORY(r->dll_name);
8808 /****************************************************************************
8809 enumprintmonitors level 1.
8810 ****************************************************************************/
8812 static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx,
8813 union spoolss_MonitorInfo **info_p,
8816 union spoolss_MonitorInfo *info;
8817 WERROR result = WERR_OK;
8819 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8820 W_ERROR_HAVE_NO_MEMORY(info);
8824 result = fill_monitor_1(info, &info[0].info1,
8826 if (!W_ERROR_IS_OK(result)) {
8830 result = fill_monitor_1(info, &info[1].info1,
8832 if (!W_ERROR_IS_OK(result)) {
8837 if (!W_ERROR_IS_OK(result)) {
8848 /****************************************************************************
8849 enumprintmonitors level 2.
8850 ****************************************************************************/
8852 static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx,
8853 union spoolss_MonitorInfo **info_p,
8856 union spoolss_MonitorInfo *info;
8857 WERROR result = WERR_OK;
8859 info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2);
8860 W_ERROR_HAVE_NO_MEMORY(info);
8864 result = fill_monitor_2(info, &info[0].info2,
8866 "Windows NT X86", /* FIXME */
8868 if (!W_ERROR_IS_OK(result)) {
8872 result = fill_monitor_2(info, &info[1].info2,
8874 "Windows NT X86", /* FIXME */
8876 if (!W_ERROR_IS_OK(result)) {
8881 if (!W_ERROR_IS_OK(result)) {
8892 /****************************************************************
8893 _spoolss_EnumMonitors
8894 ****************************************************************/
8896 WERROR _spoolss_EnumMonitors(struct pipes_struct *p,
8897 struct spoolss_EnumMonitors *r)
8901 /* that's an [in out] buffer */
8903 if (!r->in.buffer && (r->in.offered != 0)) {
8904 return WERR_INVALID_PARAM;
8907 DEBUG(5,("_spoolss_EnumMonitors\n"));
8910 * Enumerate the print monitors ...
8912 * Just reply with "Local Port", to keep NT happy
8913 * and I can use my nice printer checker.
8918 *r->out.info = NULL;
8920 switch (r->in.level) {
8922 result = enumprintmonitors_level_1(p->mem_ctx, r->out.info,
8926 result = enumprintmonitors_level_2(p->mem_ctx, r->out.info,
8930 return WERR_UNKNOWN_LEVEL;
8933 if (!W_ERROR_IS_OK(result)) {
8937 *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
8938 spoolss_EnumMonitors,
8939 *r->out.info, r->in.level,
8941 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
8942 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
8944 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
8947 /****************************************************************************
8948 ****************************************************************************/
8950 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
8951 const print_queue_struct *queue,
8952 int count, int snum,
8953 struct spoolss_PrinterInfo2 *pinfo2,
8955 struct spoolss_JobInfo1 *r)
8960 for (i=0; i<count; i++) {
8961 if (queue[i].job == (int)jobid) {
8967 if (found == false) {
8968 /* NT treats not found as bad param... yet another bad choice */
8969 return WERR_INVALID_PARAM;
8972 return fill_job_info1(mem_ctx,
8980 /****************************************************************************
8981 ****************************************************************************/
8983 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
8984 const print_queue_struct *queue,
8985 int count, int snum,
8986 struct spoolss_PrinterInfo2 *pinfo2,
8988 struct spoolss_JobInfo2 *r)
8992 struct spoolss_DeviceMode *devmode;
8995 for (i=0; i<count; i++) {
8996 if (queue[i].job == (int)jobid) {
9002 if (found == false) {
9003 /* NT treats not found as bad param... yet another bad
9005 return WERR_INVALID_PARAM;
9009 * if the print job does not have a DEVMODE associated with it,
9010 * just use the one for the printer. A NULL devicemode is not
9011 * a failure condition
9014 devmode = print_job_devmode(lp_const_servicename(snum), jobid);
9016 result = spoolss_create_default_devmode(mem_ctx,
9017 pinfo2->printername,
9019 if (!W_ERROR_IS_OK(result)) {
9020 DEBUG(3, ("Can't proceed w/o a devmode!"));
9025 return fill_job_info2(mem_ctx,
9034 /****************************************************************
9036 ****************************************************************/
9038 WERROR _spoolss_GetJob(struct pipes_struct *p,
9039 struct spoolss_GetJob *r)
9041 WERROR result = WERR_OK;
9042 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
9045 print_queue_struct *queue = NULL;
9046 print_status_struct prt_status;
9048 /* that's an [in out] buffer */
9050 if (!r->in.buffer && (r->in.offered != 0)) {
9051 return WERR_INVALID_PARAM;
9054 DEBUG(5,("_spoolss_GetJob\n"));
9058 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9062 result = winreg_get_printer(p->mem_ctx,
9063 get_server_info_system(),
9065 lp_const_servicename(snum),
9067 if (!W_ERROR_IS_OK(result)) {
9071 count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
9073 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
9074 count, prt_status.status, prt_status.message));
9076 switch (r->in.level) {
9078 result = getjob_level_1(p->mem_ctx,
9079 queue, count, snum, pinfo2,
9080 r->in.job_id, &r->out.info->info1);
9083 result = getjob_level_2(p->mem_ctx,
9084 queue, count, snum, pinfo2,
9085 r->in.job_id, &r->out.info->info2);
9088 result = WERR_UNKNOWN_LEVEL;
9093 TALLOC_FREE(pinfo2);
9095 if (!W_ERROR_IS_OK(result)) {
9096 TALLOC_FREE(r->out.info);
9100 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_JobInfo, r->out.info,
9102 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9104 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9107 /****************************************************************
9108 _spoolss_GetPrinterDataEx
9109 ****************************************************************/
9111 WERROR _spoolss_GetPrinterDataEx(struct pipes_struct *p,
9112 struct spoolss_GetPrinterDataEx *r)
9115 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9116 const char *printer;
9118 WERROR result = WERR_OK;
9120 enum winreg_Type val_type;
9125 DEBUG(4,("_spoolss_GetPrinterDataEx\n"));
9127 DEBUG(10, ("_spoolss_GetPrinterDataEx: key => [%s], value => [%s]\n",
9128 r->in.key_name, r->in.value_name));
9130 /* in case of problem, return some default values */
9133 *r->out.type = REG_NONE;
9136 DEBUG(2,("_spoolss_GetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9137 OUR_HANDLE(r->in.handle)));
9138 result = WERR_BADFID;
9142 /* Is the handle to a printer or to the server? */
9144 if (Printer->printer_type == SPLHND_SERVER) {
9146 union spoolss_PrinterData data;
9148 result = getprinterdata_printer_server(p->mem_ctx,
9152 if (!W_ERROR_IS_OK(result)) {
9156 result = push_spoolss_PrinterData(p->mem_ctx, &blob,
9157 *r->out.type, &data);
9158 if (!W_ERROR_IS_OK(result)) {
9162 *r->out.needed = blob.length;
9164 if (r->in.offered >= *r->out.needed) {
9165 memcpy(r->out.data, blob.data, blob.length);
9168 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9171 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9174 printer = lp_const_servicename(snum);
9176 /* check to see if the keyname is valid */
9177 if (!strlen(r->in.key_name)) {
9178 return WERR_INVALID_PARAM;
9181 /* XP sends this and wants the ChangeID value from PRINTER_INFO_0 */
9182 if (strequal(r->in.key_name, SPOOL_PRINTERDATA_KEY) &&
9183 strequal(r->in.value_name, "ChangeId")) {
9184 *r->out.type = REG_DWORD;
9186 if (r->in.offered >= *r->out.needed) {
9187 uint32_t changeid = 0;
9189 result = winreg_printer_get_changeid(p->mem_ctx,
9190 get_server_info_system(),
9194 if (!W_ERROR_IS_OK(result)) {
9198 SIVAL(r->out.data, 0, changeid);
9204 result = winreg_get_printer_dataex(p->mem_ctx,
9205 get_server_info_system(),
9213 if (!W_ERROR_IS_OK(result)) {
9217 *r->out.needed = val_size;
9218 *r->out.type = val_type;
9220 if (r->in.offered >= *r->out.needed) {
9221 memcpy(r->out.data, val_data, val_size);
9225 /* retain type when returning WERR_MORE_DATA */
9226 r->out.data = SPOOLSS_BUFFER_OK(r->out.data, r->out.data);
9228 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9231 /****************************************************************
9232 _spoolss_SetPrinterDataEx
9233 ****************************************************************/
9235 WERROR _spoolss_SetPrinterDataEx(struct pipes_struct *p,
9236 struct spoolss_SetPrinterDataEx *r)
9238 struct spoolss_PrinterInfo2 *pinfo2 = NULL;
9240 WERROR result = WERR_OK;
9241 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9244 DEBUG(4,("_spoolss_SetPrinterDataEx\n"));
9246 /* From MSDN documentation of SetPrinterDataEx: pass request to
9247 SetPrinterData if key is "PrinterDriverData" */
9250 DEBUG(2,("_spoolss_SetPrinterDataEx: Invalid handle (%s:%u:%u).\n",
9251 OUR_HANDLE(r->in.handle)));
9255 if (Printer->printer_type == SPLHND_SERVER) {
9256 DEBUG(10,("_spoolss_SetPrinterDataEx: "
9257 "Not implemented for server handles yet\n"));
9258 return WERR_INVALID_PARAM;
9261 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9266 * Access check : NT returns "access denied" if you make a
9267 * SetPrinterData call without the necessary privildge.
9268 * we were originally returning OK if nothing changed
9269 * which made Win2k issue **a lot** of SetPrinterData
9270 * when connecting to a printer --jerry
9273 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9274 DEBUG(3, ("_spoolss_SetPrinterDataEx: "
9275 "change denied by handle access permissions\n"));
9276 return WERR_ACCESS_DENIED;
9279 result = winreg_get_printer(Printer,
9280 get_server_info_system(),
9282 lp_servicename(snum),
9284 if (!W_ERROR_IS_OK(result)) {
9288 /* check for OID in valuename */
9290 oid_string = strchr(r->in.value_name, ',');
9296 /* save the registry data */
9298 result = winreg_set_printer_dataex(p->mem_ctx,
9299 get_server_info_system(),
9308 if (W_ERROR_IS_OK(result)) {
9309 /* save the OID if one was specified */
9311 char *str = talloc_asprintf(p->mem_ctx, "%s\\%s",
9312 r->in.key_name, SPOOL_OID_KEY);
9314 result = WERR_NOMEM;
9319 * I'm not checking the status here on purpose. Don't know
9320 * if this is right, but I'm returning the status from the
9321 * previous set_printer_dataex() call. I have no idea if
9322 * this is right. --jerry
9324 winreg_set_printer_dataex(p->mem_ctx,
9325 get_server_info_system(),
9331 (uint8_t *) oid_string,
9332 strlen(oid_string) + 1);
9335 result = winreg_printer_update_changeid(p->mem_ctx,
9336 get_server_info_system(),
9338 lp_const_servicename(snum));
9343 talloc_free(pinfo2);
9347 /****************************************************************
9348 _spoolss_DeletePrinterDataEx
9349 ****************************************************************/
9351 WERROR _spoolss_DeletePrinterDataEx(struct pipes_struct *p,
9352 struct spoolss_DeletePrinterDataEx *r)
9354 const char *printer;
9356 WERROR status = WERR_OK;
9357 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9359 DEBUG(5,("_spoolss_DeletePrinterDataEx\n"));
9362 DEBUG(2,("_spoolss_DeletePrinterDataEx: "
9363 "Invalid handle (%s:%u:%u).\n",
9364 OUR_HANDLE(r->in.handle)));
9368 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9369 DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
9370 "printer properties change denied by handle\n"));
9371 return WERR_ACCESS_DENIED;
9374 if (!r->in.value_name || !r->in.key_name) {
9378 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9381 printer = lp_const_servicename(snum);
9383 status = winreg_delete_printer_dataex(p->mem_ctx,
9384 get_server_info_system(),
9389 if (W_ERROR_IS_OK(status)) {
9390 status = winreg_printer_update_changeid(p->mem_ctx,
9391 get_server_info_system(),
9399 /****************************************************************
9400 _spoolss_EnumPrinterKey
9401 ****************************************************************/
9403 WERROR _spoolss_EnumPrinterKey(struct pipes_struct *p,
9404 struct spoolss_EnumPrinterKey *r)
9407 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9409 WERROR result = WERR_BADFILE;
9410 const char **array = NULL;
9413 DEBUG(4,("_spoolss_EnumPrinterKey\n"));
9416 DEBUG(2,("_spoolss_EnumPrinterKey: Invalid handle (%s:%u:%u).\n",
9417 OUR_HANDLE(r->in.handle)));
9421 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9425 result = winreg_enum_printer_key(p->mem_ctx,
9426 get_server_info_system(),
9428 lp_const_servicename(snum),
9432 if (!W_ERROR_IS_OK(result)) {
9436 if (!push_reg_multi_sz(p->mem_ctx, &blob, array)) {
9437 result = WERR_NOMEM;
9441 *r->out._ndr_size = r->in.offered / 2;
9442 *r->out.needed = blob.length;
9444 if (r->in.offered < *r->out.needed) {
9445 result = WERR_MORE_DATA;
9448 r->out.key_buffer->string_array = array;
9452 if (!W_ERROR_IS_OK(result)) {
9454 if (!W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
9462 /****************************************************************
9463 _spoolss_DeletePrinterKey
9464 ****************************************************************/
9466 WERROR _spoolss_DeletePrinterKey(struct pipes_struct *p,
9467 struct spoolss_DeletePrinterKey *r)
9469 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9472 const char *printer;
9474 DEBUG(5,("_spoolss_DeletePrinterKey\n"));
9477 DEBUG(2,("_spoolss_DeletePrinterKey: Invalid handle (%s:%u:%u).\n",
9478 OUR_HANDLE(r->in.handle)));
9482 /* if keyname == NULL, return error */
9483 if ( !r->in.key_name )
9484 return WERR_INVALID_PARAM;
9486 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9490 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9491 DEBUG(3, ("_spoolss_DeletePrinterKey: "
9492 "printer properties change denied by handle\n"));
9493 return WERR_ACCESS_DENIED;
9496 printer = lp_const_servicename(snum);
9498 /* delete the key and all subkeys */
9499 status = winreg_delete_printer_key(p->mem_ctx,
9500 get_server_info_system(),
9504 if (W_ERROR_IS_OK(status)) {
9505 status = winreg_printer_update_changeid(p->mem_ctx,
9506 get_server_info_system(),
9514 /****************************************************************
9515 _spoolss_EnumPrinterDataEx
9516 ****************************************************************/
9518 WERROR _spoolss_EnumPrinterDataEx(struct pipes_struct *p,
9519 struct spoolss_EnumPrinterDataEx *r)
9522 struct spoolss_PrinterEnumValues *info = NULL;
9523 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9527 DEBUG(4,("_spoolss_EnumPrinterDataEx\n"));
9531 *r->out.info = NULL;
9534 DEBUG(2,("_spoolss_EnumPrinterDataEx: Invalid handle (%s:%u:%u1<).\n",
9535 OUR_HANDLE(r->in.handle)));
9540 * first check for a keyname of NULL or "". Win2k seems to send
9541 * this a lot and we should send back WERR_INVALID_PARAM
9542 * no need to spend time looking up the printer in this case.
9546 if (!strlen(r->in.key_name)) {
9547 result = WERR_INVALID_PARAM;
9551 if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
9555 /* now look for a match on the key name */
9556 result = winreg_enum_printer_dataex(p->mem_ctx,
9557 get_server_info_system(),
9559 lp_const_servicename(snum),
9563 if (!W_ERROR_IS_OK(result)) {
9567 #if 0 /* FIXME - gd */
9568 /* housekeeping information in the reply */
9570 /* Fix from Martin Zielinski <mz@seh.de> - ensure
9571 * the hand marshalled container size is a multiple
9572 * of 4 bytes for RPC alignment.
9576 needed += 4-(needed % 4);
9579 *r->out.count = count;
9580 *r->out.info = info;
9583 if (!W_ERROR_IS_OK(result)) {
9587 *r->out.needed = SPOOLSS_BUFFER_ARRAY(p->mem_ctx,
9588 spoolss_EnumPrinterDataEx,
9591 *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
9592 *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, *r->out.count);
9594 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_MORE_DATA);
9597 /****************************************************************************
9598 ****************************************************************************/
9600 static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
9601 const char *servername,
9602 const char *environment,
9603 struct spoolss_PrintProcessorDirectoryInfo1 *r)
9608 werr = compose_spoolss_server_path(mem_ctx,
9611 SPOOLSS_PRTPROCS_PATH,
9613 if (!W_ERROR_IS_OK(werr)) {
9617 DEBUG(4,("print processor directory: [%s]\n", path));
9619 r->directory_name = path;
9624 /****************************************************************
9625 _spoolss_GetPrintProcessorDirectory
9626 ****************************************************************/
9628 WERROR _spoolss_GetPrintProcessorDirectory(struct pipes_struct *p,
9629 struct spoolss_GetPrintProcessorDirectory *r)
9632 char *prnproc_share = NULL;
9633 bool prnproc_share_exists = false;
9636 /* that's an [in out] buffer */
9638 if (!r->in.buffer && (r->in.offered != 0)) {
9639 return WERR_INVALID_PARAM;
9642 DEBUG(5,("_spoolss_GetPrintProcessorDirectory: level %d\n",
9647 /* r->in.level is ignored */
9649 /* We always should reply with a local print processor directory so that
9650 * users are not forced to have a [prnproc$] share on the Samba spoolss
9651 * server, if users decide to do so, lets announce it though - Guenther */
9653 snum = find_service(talloc_tos(), "prnproc$", &prnproc_share);
9654 if (!prnproc_share) {
9658 prnproc_share_exists = true;
9661 result = getprintprocessordirectory_level_1(p->mem_ctx,
9662 prnproc_share_exists ? r->in.server : NULL,
9664 &r->out.info->info1);
9665 if (!W_ERROR_IS_OK(result)) {
9666 TALLOC_FREE(r->out.info);
9670 *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_PrintProcessorDirectoryInfo,
9671 r->out.info, r->in.level);
9672 r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL);
9674 return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
9677 /*******************************************************************
9678 ********************************************************************/
9680 static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
9681 const char *dllname)
9683 enum ndr_err_code ndr_err;
9684 struct spoolss_MonitorUi ui;
9686 ui.dll_name = dllname;
9688 ndr_err = ndr_push_struct_blob(buf, mem_ctx, &ui,
9689 (ndr_push_flags_fn_t)ndr_push_spoolss_MonitorUi);
9690 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9691 NDR_PRINT_DEBUG(spoolss_MonitorUi, &ui);
9693 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9696 /*******************************************************************
9697 Streams the monitor UI DLL name in UNICODE
9698 *******************************************************************/
9700 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
9701 struct security_token *token, DATA_BLOB *in,
9702 DATA_BLOB *out, uint32_t *needed)
9704 const char *dllname = "tcpmonui.dll";
9706 *needed = (strlen(dllname)+1) * 2;
9708 if (out->length < *needed) {
9709 return WERR_INSUFFICIENT_BUFFER;
9712 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9719 /*******************************************************************
9720 ********************************************************************/
9722 static bool pull_port_data_1(TALLOC_CTX *mem_ctx,
9723 struct spoolss_PortData1 *port1,
9724 const DATA_BLOB *buf)
9726 enum ndr_err_code ndr_err;
9727 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port1,
9728 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData1);
9729 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9730 NDR_PRINT_DEBUG(spoolss_PortData1, port1);
9732 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9735 /*******************************************************************
9736 ********************************************************************/
9738 static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
9739 struct spoolss_PortData2 *port2,
9740 const DATA_BLOB *buf)
9742 enum ndr_err_code ndr_err;
9743 ndr_err = ndr_pull_struct_blob(buf, mem_ctx, port2,
9744 (ndr_pull_flags_fn_t)ndr_pull_spoolss_PortData2);
9745 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLEVEL >= 10)) {
9746 NDR_PRINT_DEBUG(spoolss_PortData2, port2);
9748 return NDR_ERR_CODE_IS_SUCCESS(ndr_err);
9751 /*******************************************************************
9752 Create a new TCP/IP port
9753 *******************************************************************/
9755 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
9756 struct security_token *token, DATA_BLOB *in,
9757 DATA_BLOB *out, uint32_t *needed)
9759 struct spoolss_PortData1 port1;
9760 struct spoolss_PortData2 port2;
9761 char *device_uri = NULL;
9764 const char *portname;
9765 const char *hostaddress;
9767 uint32_t port_number;
9770 /* peek for spoolss_PortData version */
9772 if (!in || (in->length < (128 + 4))) {
9773 return WERR_GENERAL_FAILURE;
9776 version = IVAL(in->data, 128);
9782 if (!pull_port_data_1(mem_ctx, &port1, in)) {
9786 portname = port1.portname;
9787 hostaddress = port1.hostaddress;
9788 queue = port1.queue;
9789 protocol = port1.protocol;
9790 port_number = port1.port_number;
9796 if (!pull_port_data_2(mem_ctx, &port2, in)) {
9800 portname = port2.portname;
9801 hostaddress = port2.hostaddress;
9802 queue = port2.queue;
9803 protocol = port2.protocol;
9804 port_number = port2.port_number;
9808 DEBUG(1,("xcvtcp_addport: "
9809 "unknown version of port_data: %d\n", version));
9810 return WERR_UNKNOWN_PORT;
9813 /* create the device URI and call the add_port_hook() */
9816 case PROTOCOL_RAWTCP_TYPE:
9817 device_uri = talloc_asprintf(mem_ctx,
9818 "socket://%s:%d/", hostaddress,
9822 case PROTOCOL_LPR_TYPE:
9823 device_uri = talloc_asprintf(mem_ctx,
9824 "lpr://%s/%s", hostaddress, queue );
9828 return WERR_UNKNOWN_PORT;
9835 return add_port_hook(mem_ctx, token, portname, device_uri);
9838 /*******************************************************************
9839 *******************************************************************/
9841 struct xcv_api_table xcvtcp_cmds[] = {
9842 { "MonitorUI", xcvtcp_monitorui },
9843 { "AddPort", xcvtcp_addport},
9847 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
9848 struct security_token *token, const char *command,
9855 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
9857 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
9858 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
9859 return xcvtcp_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9862 return WERR_BADFUNC;
9865 /*******************************************************************
9866 *******************************************************************/
9867 #if 0 /* don't support management using the "Local Port" monitor */
9869 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
9870 struct security_token *token, DATA_BLOB *in,
9871 DATA_BLOB *out, uint32_t *needed)
9873 const char *dllname = "localui.dll";
9875 *needed = (strlen(dllname)+1) * 2;
9877 if (out->length < *needed) {
9878 return WERR_INSUFFICIENT_BUFFER;
9881 if (!push_monitorui_buf(mem_ctx, out, dllname)) {
9888 /*******************************************************************
9889 *******************************************************************/
9891 struct xcv_api_table xcvlocal_cmds[] = {
9892 { "MonitorUI", xcvlocal_monitorui },
9896 struct xcv_api_table xcvlocal_cmds[] = {
9903 /*******************************************************************
9904 *******************************************************************/
9906 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
9907 struct security_token *token, const char *command,
9908 DATA_BLOB *inbuf, DATA_BLOB *outbuf,
9913 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
9915 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
9916 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
9917 return xcvlocal_cmds[i].fn(mem_ctx, token, inbuf, outbuf, needed);
9919 return WERR_BADFUNC;
9922 /****************************************************************
9924 ****************************************************************/
9926 WERROR _spoolss_XcvData(struct pipes_struct *p,
9927 struct spoolss_XcvData *r)
9929 struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
9930 DATA_BLOB out_data = data_blob_null;
9934 DEBUG(2,("_spoolss_XcvData: Invalid handle (%s:%u:%u).\n",
9935 OUR_HANDLE(r->in.handle)));
9939 /* Has to be a handle to the TCP/IP port monitor */
9941 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
9942 DEBUG(2,("_spoolss_XcvData: Call only valid for Port Monitors\n"));
9946 /* requires administrative access to the server */
9948 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
9949 DEBUG(2,("_spoolss_XcvData: denied by handle permissions.\n"));
9950 return WERR_ACCESS_DENIED;
9953 /* Allocate the outgoing buffer */
9955 if (r->in.out_data_size) {
9956 out_data = data_blob_talloc_zero(p->mem_ctx, r->in.out_data_size);
9957 if (out_data.data == NULL) {
9962 switch ( Printer->printer_type ) {
9963 case SPLHND_PORTMON_TCP:
9964 werror = process_xcvtcp_command(p->mem_ctx,
9965 p->server_info->ptok,
9966 r->in.function_name,
9967 &r->in.in_data, &out_data,
9970 case SPLHND_PORTMON_LOCAL:
9971 werror = process_xcvlocal_command(p->mem_ctx,
9972 p->server_info->ptok,
9973 r->in.function_name,
9974 &r->in.in_data, &out_data,
9978 werror = WERR_INVALID_PRINT_MONITOR;
9981 if (!W_ERROR_IS_OK(werror)) {
9985 *r->out.status_code = 0;
9987 if (r->out.out_data && out_data.data && r->in.out_data_size && out_data.length) {
9988 memcpy(r->out.out_data, out_data.data,
9989 MIN(r->in.out_data_size, out_data.length));
9995 /****************************************************************
9996 _spoolss_AddPrintProcessor
9997 ****************************************************************/
9999 WERROR _spoolss_AddPrintProcessor(struct pipes_struct *p,
10000 struct spoolss_AddPrintProcessor *r)
10002 /* for now, just indicate success and ignore the add. We'll
10003 automatically set the winprint processor for printer
10004 entries later. Used to debug the LexMark Optra S 1855 PCL
10010 /****************************************************************
10012 ****************************************************************/
10014 WERROR _spoolss_AddPort(struct pipes_struct *p,
10015 struct spoolss_AddPort *r)
10017 /* do what w2k3 does */
10019 return WERR_NOT_SUPPORTED;
10022 /****************************************************************
10023 _spoolss_GetPrinterDriver
10024 ****************************************************************/
10026 WERROR _spoolss_GetPrinterDriver(struct pipes_struct *p,
10027 struct spoolss_GetPrinterDriver *r)
10029 p->rng_fault_state = true;
10030 return WERR_NOT_SUPPORTED;
10033 /****************************************************************
10034 _spoolss_ReadPrinter
10035 ****************************************************************/
10037 WERROR _spoolss_ReadPrinter(struct pipes_struct *p,
10038 struct spoolss_ReadPrinter *r)
10040 p->rng_fault_state = true;
10041 return WERR_NOT_SUPPORTED;
10044 /****************************************************************
10045 _spoolss_WaitForPrinterChange
10046 ****************************************************************/
10048 WERROR _spoolss_WaitForPrinterChange(struct pipes_struct *p,
10049 struct spoolss_WaitForPrinterChange *r)
10051 p->rng_fault_state = true;
10052 return WERR_NOT_SUPPORTED;
10055 /****************************************************************
10056 _spoolss_ConfigurePort
10057 ****************************************************************/
10059 WERROR _spoolss_ConfigurePort(struct pipes_struct *p,
10060 struct spoolss_ConfigurePort *r)
10062 p->rng_fault_state = true;
10063 return WERR_NOT_SUPPORTED;
10066 /****************************************************************
10067 _spoolss_DeletePort
10068 ****************************************************************/
10070 WERROR _spoolss_DeletePort(struct pipes_struct *p,
10071 struct spoolss_DeletePort *r)
10073 p->rng_fault_state = true;
10074 return WERR_NOT_SUPPORTED;
10077 /****************************************************************
10078 _spoolss_CreatePrinterIC
10079 ****************************************************************/
10081 WERROR _spoolss_CreatePrinterIC(struct pipes_struct *p,
10082 struct spoolss_CreatePrinterIC *r)
10084 p->rng_fault_state = true;
10085 return WERR_NOT_SUPPORTED;
10088 /****************************************************************
10089 _spoolss_PlayGDIScriptOnPrinterIC
10090 ****************************************************************/
10092 WERROR _spoolss_PlayGDIScriptOnPrinterIC(struct pipes_struct *p,
10093 struct spoolss_PlayGDIScriptOnPrinterIC *r)
10095 p->rng_fault_state = true;
10096 return WERR_NOT_SUPPORTED;
10099 /****************************************************************
10100 _spoolss_DeletePrinterIC
10101 ****************************************************************/
10103 WERROR _spoolss_DeletePrinterIC(struct pipes_struct *p,
10104 struct spoolss_DeletePrinterIC *r)
10106 p->rng_fault_state = true;
10107 return WERR_NOT_SUPPORTED;
10110 /****************************************************************
10111 _spoolss_AddPrinterConnection
10112 ****************************************************************/
10114 WERROR _spoolss_AddPrinterConnection(struct pipes_struct *p,
10115 struct spoolss_AddPrinterConnection *r)
10117 p->rng_fault_state = true;
10118 return WERR_NOT_SUPPORTED;
10121 /****************************************************************
10122 _spoolss_DeletePrinterConnection
10123 ****************************************************************/
10125 WERROR _spoolss_DeletePrinterConnection(struct pipes_struct *p,
10126 struct spoolss_DeletePrinterConnection *r)
10128 p->rng_fault_state = true;
10129 return WERR_NOT_SUPPORTED;
10132 /****************************************************************
10133 _spoolss_PrinterMessageBox
10134 ****************************************************************/
10136 WERROR _spoolss_PrinterMessageBox(struct pipes_struct *p,
10137 struct spoolss_PrinterMessageBox *r)
10139 p->rng_fault_state = true;
10140 return WERR_NOT_SUPPORTED;
10143 /****************************************************************
10144 _spoolss_AddMonitor
10145 ****************************************************************/
10147 WERROR _spoolss_AddMonitor(struct pipes_struct *p,
10148 struct spoolss_AddMonitor *r)
10150 p->rng_fault_state = true;
10151 return WERR_NOT_SUPPORTED;
10154 /****************************************************************
10155 _spoolss_DeleteMonitor
10156 ****************************************************************/
10158 WERROR _spoolss_DeleteMonitor(struct pipes_struct *p,
10159 struct spoolss_DeleteMonitor *r)
10161 p->rng_fault_state = true;
10162 return WERR_NOT_SUPPORTED;
10165 /****************************************************************
10166 _spoolss_DeletePrintProcessor
10167 ****************************************************************/
10169 WERROR _spoolss_DeletePrintProcessor(struct pipes_struct *p,
10170 struct spoolss_DeletePrintProcessor *r)
10172 p->rng_fault_state = true;
10173 return WERR_NOT_SUPPORTED;
10176 /****************************************************************
10177 _spoolss_AddPrintProvidor
10178 ****************************************************************/
10180 WERROR _spoolss_AddPrintProvidor(struct pipes_struct *p,
10181 struct spoolss_AddPrintProvidor *r)
10183 p->rng_fault_state = true;
10184 return WERR_NOT_SUPPORTED;
10187 /****************************************************************
10188 _spoolss_DeletePrintProvidor
10189 ****************************************************************/
10191 WERROR _spoolss_DeletePrintProvidor(struct pipes_struct *p,
10192 struct spoolss_DeletePrintProvidor *r)
10194 p->rng_fault_state = true;
10195 return WERR_NOT_SUPPORTED;
10198 /****************************************************************
10199 _spoolss_FindFirstPrinterChangeNotification
10200 ****************************************************************/
10202 WERROR _spoolss_FindFirstPrinterChangeNotification(struct pipes_struct *p,
10203 struct spoolss_FindFirstPrinterChangeNotification *r)
10205 p->rng_fault_state = true;
10206 return WERR_NOT_SUPPORTED;
10209 /****************************************************************
10210 _spoolss_FindNextPrinterChangeNotification
10211 ****************************************************************/
10213 WERROR _spoolss_FindNextPrinterChangeNotification(struct pipes_struct *p,
10214 struct spoolss_FindNextPrinterChangeNotification *r)
10216 p->rng_fault_state = true;
10217 return WERR_NOT_SUPPORTED;
10220 /****************************************************************
10221 _spoolss_RouterFindFirstPrinterChangeNotificationOld
10222 ****************************************************************/
10224 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(struct pipes_struct *p,
10225 struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
10227 p->rng_fault_state = true;
10228 return WERR_NOT_SUPPORTED;
10231 /****************************************************************
10232 _spoolss_ReplyOpenPrinter
10233 ****************************************************************/
10235 WERROR _spoolss_ReplyOpenPrinter(struct pipes_struct *p,
10236 struct spoolss_ReplyOpenPrinter *r)
10238 p->rng_fault_state = true;
10239 return WERR_NOT_SUPPORTED;
10242 /****************************************************************
10243 _spoolss_RouterReplyPrinter
10244 ****************************************************************/
10246 WERROR _spoolss_RouterReplyPrinter(struct pipes_struct *p,
10247 struct spoolss_RouterReplyPrinter *r)
10249 p->rng_fault_state = true;
10250 return WERR_NOT_SUPPORTED;
10253 /****************************************************************
10254 _spoolss_ReplyClosePrinter
10255 ****************************************************************/
10257 WERROR _spoolss_ReplyClosePrinter(struct pipes_struct *p,
10258 struct spoolss_ReplyClosePrinter *r)
10260 p->rng_fault_state = true;
10261 return WERR_NOT_SUPPORTED;
10264 /****************************************************************
10266 ****************************************************************/
10268 WERROR _spoolss_AddPortEx(struct pipes_struct *p,
10269 struct spoolss_AddPortEx *r)
10271 p->rng_fault_state = true;
10272 return WERR_NOT_SUPPORTED;
10275 /****************************************************************
10276 _spoolss_RouterFindFirstPrinterChangeNotification
10277 ****************************************************************/
10279 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(struct pipes_struct *p,
10280 struct spoolss_RouterFindFirstPrinterChangeNotification *r)
10282 p->rng_fault_state = true;
10283 return WERR_NOT_SUPPORTED;
10286 /****************************************************************
10287 _spoolss_SpoolerInit
10288 ****************************************************************/
10290 WERROR _spoolss_SpoolerInit(struct pipes_struct *p,
10291 struct spoolss_SpoolerInit *r)
10293 p->rng_fault_state = true;
10294 return WERR_NOT_SUPPORTED;
10297 /****************************************************************
10298 _spoolss_ResetPrinterEx
10299 ****************************************************************/
10301 WERROR _spoolss_ResetPrinterEx(struct pipes_struct *p,
10302 struct spoolss_ResetPrinterEx *r)
10304 p->rng_fault_state = true;
10305 return WERR_NOT_SUPPORTED;
10308 /****************************************************************
10309 _spoolss_RouterReplyPrinterEx
10310 ****************************************************************/
10312 WERROR _spoolss_RouterReplyPrinterEx(struct pipes_struct *p,
10313 struct spoolss_RouterReplyPrinterEx *r)
10315 p->rng_fault_state = true;
10316 return WERR_NOT_SUPPORTED;
10319 /****************************************************************
10321 ****************************************************************/
10323 WERROR _spoolss_44(struct pipes_struct *p,
10324 struct spoolss_44 *r)
10326 p->rng_fault_state = true;
10327 return WERR_NOT_SUPPORTED;
10330 /****************************************************************
10332 ****************************************************************/
10334 WERROR _spoolss_SetPort(struct pipes_struct *p,
10335 struct spoolss_SetPort *r)
10337 p->rng_fault_state = true;
10338 return WERR_NOT_SUPPORTED;
10341 /****************************************************************
10343 ****************************************************************/
10345 WERROR _spoolss_4a(struct pipes_struct *p,
10346 struct spoolss_4a *r)
10348 p->rng_fault_state = true;
10349 return WERR_NOT_SUPPORTED;
10352 /****************************************************************
10354 ****************************************************************/
10356 WERROR _spoolss_4b(struct pipes_struct *p,
10357 struct spoolss_4b *r)
10359 p->rng_fault_state = true;
10360 return WERR_NOT_SUPPORTED;
10363 /****************************************************************
10365 ****************************************************************/
10367 WERROR _spoolss_4c(struct pipes_struct *p,
10368 struct spoolss_4c *r)
10370 p->rng_fault_state = true;
10371 return WERR_NOT_SUPPORTED;
10374 /****************************************************************
10376 ****************************************************************/
10378 WERROR _spoolss_53(struct pipes_struct *p,
10379 struct spoolss_53 *r)
10381 p->rng_fault_state = true;
10382 return WERR_NOT_SUPPORTED;
10385 /****************************************************************
10387 ****************************************************************/
10389 WERROR _spoolss_55(struct pipes_struct *p,
10390 struct spoolss_55 *r)
10392 p->rng_fault_state = true;
10393 return WERR_NOT_SUPPORTED;
10396 /****************************************************************
10398 ****************************************************************/
10400 WERROR _spoolss_56(struct pipes_struct *p,
10401 struct spoolss_56 *r)
10403 p->rng_fault_state = true;
10404 return WERR_NOT_SUPPORTED;
10407 /****************************************************************
10409 ****************************************************************/
10411 WERROR _spoolss_57(struct pipes_struct *p,
10412 struct spoolss_57 *r)
10414 p->rng_fault_state = true;
10415 return WERR_NOT_SUPPORTED;
10418 /****************************************************************
10420 ****************************************************************/
10422 WERROR _spoolss_5a(struct pipes_struct *p,
10423 struct spoolss_5a *r)
10425 p->rng_fault_state = true;
10426 return WERR_NOT_SUPPORTED;
10429 /****************************************************************
10431 ****************************************************************/
10433 WERROR _spoolss_5b(struct pipes_struct *p,
10434 struct spoolss_5b *r)
10436 p->rng_fault_state = true;
10437 return WERR_NOT_SUPPORTED;
10440 /****************************************************************
10442 ****************************************************************/
10444 WERROR _spoolss_5c(struct pipes_struct *p,
10445 struct spoolss_5c *r)
10447 p->rng_fault_state = true;
10448 return WERR_NOT_SUPPORTED;
10451 /****************************************************************
10453 ****************************************************************/
10455 WERROR _spoolss_5d(struct pipes_struct *p,
10456 struct spoolss_5d *r)
10458 p->rng_fault_state = true;
10459 return WERR_NOT_SUPPORTED;
10462 /****************************************************************
10464 ****************************************************************/
10466 WERROR _spoolss_5e(struct pipes_struct *p,
10467 struct spoolss_5e *r)
10469 p->rng_fault_state = true;
10470 return WERR_NOT_SUPPORTED;
10473 /****************************************************************
10475 ****************************************************************/
10477 WERROR _spoolss_5f(struct pipes_struct *p,
10478 struct spoolss_5f *r)
10480 p->rng_fault_state = true;
10481 return WERR_NOT_SUPPORTED;
10484 /****************************************************************
10486 ****************************************************************/
10488 WERROR _spoolss_60(struct pipes_struct *p,
10489 struct spoolss_60 *r)
10491 p->rng_fault_state = true;
10492 return WERR_NOT_SUPPORTED;
10495 /****************************************************************
10497 ****************************************************************/
10499 WERROR _spoolss_61(struct pipes_struct *p,
10500 struct spoolss_61 *r)
10502 p->rng_fault_state = true;
10503 return WERR_NOT_SUPPORTED;
10506 /****************************************************************
10508 ****************************************************************/
10510 WERROR _spoolss_62(struct pipes_struct *p,
10511 struct spoolss_62 *r)
10513 p->rng_fault_state = true;
10514 return WERR_NOT_SUPPORTED;
10517 /****************************************************************
10519 ****************************************************************/
10521 WERROR _spoolss_63(struct pipes_struct *p,
10522 struct spoolss_63 *r)
10524 p->rng_fault_state = true;
10525 return WERR_NOT_SUPPORTED;
10528 /****************************************************************
10530 ****************************************************************/
10532 WERROR _spoolss_64(struct pipes_struct *p,
10533 struct spoolss_64 *r)
10535 p->rng_fault_state = true;
10536 return WERR_NOT_SUPPORTED;
10539 /****************************************************************
10541 ****************************************************************/
10543 WERROR _spoolss_65(struct pipes_struct *p,
10544 struct spoolss_65 *r)
10546 p->rng_fault_state = true;
10547 return WERR_NOT_SUPPORTED;
10550 /****************************************************************
10551 _spoolss_GetCorePrinterDrivers
10552 ****************************************************************/
10554 WERROR _spoolss_GetCorePrinterDrivers(struct pipes_struct *p,
10555 struct spoolss_GetCorePrinterDrivers *r)
10557 p->rng_fault_state = true;
10558 return WERR_NOT_SUPPORTED;
10561 /****************************************************************
10563 ****************************************************************/
10565 WERROR _spoolss_67(struct pipes_struct *p,
10566 struct spoolss_67 *r)
10568 p->rng_fault_state = true;
10569 return WERR_NOT_SUPPORTED;
10572 /****************************************************************
10573 _spoolss_GetPrinterDriverPackagePath
10574 ****************************************************************/
10576 WERROR _spoolss_GetPrinterDriverPackagePath(struct pipes_struct *p,
10577 struct spoolss_GetPrinterDriverPackagePath *r)
10579 p->rng_fault_state = true;
10580 return WERR_NOT_SUPPORTED;
10583 /****************************************************************
10585 ****************************************************************/
10587 WERROR _spoolss_69(struct pipes_struct *p,
10588 struct spoolss_69 *r)
10590 p->rng_fault_state = true;
10591 return WERR_NOT_SUPPORTED;
10594 /****************************************************************
10596 ****************************************************************/
10598 WERROR _spoolss_6a(struct pipes_struct *p,
10599 struct spoolss_6a *r)
10601 p->rng_fault_state = true;
10602 return WERR_NOT_SUPPORTED;
10605 /****************************************************************
10607 ****************************************************************/
10609 WERROR _spoolss_6b(struct pipes_struct *p,
10610 struct spoolss_6b *r)
10612 p->rng_fault_state = true;
10613 return WERR_NOT_SUPPORTED;
10616 /****************************************************************
10618 ****************************************************************/
10620 WERROR _spoolss_6c(struct pipes_struct *p,
10621 struct spoolss_6c *r)
10623 p->rng_fault_state = true;
10624 return WERR_NOT_SUPPORTED;
10627 /****************************************************************
10629 ****************************************************************/
10631 WERROR _spoolss_6d(struct pipes_struct *p,
10632 struct spoolss_6d *r)
10634 p->rng_fault_state = true;
10635 return WERR_NOT_SUPPORTED;