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.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 /* Since the SPOOLSS rpc routines are basically DOS 16-bit calls wrapped
27 up, all the errors returned are DOS errors, not NT status codes. */
31 extern userdom_struct current_user_info;
34 #define DBGC_CLASS DBGC_RPC_SRV
36 #ifndef MAX_OPEN_PRINTER_EXS
37 #define MAX_OPEN_PRINTER_EXS 50
40 #define MAGIC_DISPLAY_FREQUENCY 0xfade2bad
41 #define PHANTOM_DEVMODE_KEY "_p_f_a_n_t_0_m_"
44 const char *long_archi;
45 const char *short_archi;
49 static Printer_entry *printers_list;
51 typedef struct _counter_printer_0 {
52 struct _counter_printer_0 *next;
53 struct _counter_printer_0 *prev;
59 static counter_printer_0 *counter_list;
61 static struct rpc_pipe_client *notify_cli_pipe; /* print notify back-channel pipe handle*/
62 static uint32 smb_connections=0;
65 /* in printing/nt_printing.c */
67 extern STANDARD_MAPPING printer_std_mapping, printserver_std_mapping;
69 /* API table for Xcv Monitor functions */
71 struct xcv_api_table {
73 WERROR(*fn) (NT_USER_TOKEN *token, RPC_BUFFER *in, RPC_BUFFER *out, uint32 *needed);
77 /* translate between internal status numbers and NT status numbers */
78 static int nt_printj_status(int v)
84 return JOB_STATUS_PAUSED;
86 return JOB_STATUS_SPOOLING;
88 return JOB_STATUS_PRINTING;
90 return JOB_STATUS_ERROR;
92 return JOB_STATUS_DELETING;
94 return JOB_STATUS_OFFLINE;
96 return JOB_STATUS_PAPEROUT;
98 return JOB_STATUS_PRINTED;
100 return JOB_STATUS_DELETED;
102 return JOB_STATUS_BLOCKED;
103 case LPQ_USER_INTERVENTION:
104 return JOB_STATUS_USER_INTERVENTION;
109 static int nt_printq_status(int v)
113 return PRINTER_STATUS_PAUSED;
122 /****************************************************************************
123 Functions to handle SPOOL_NOTIFY_OPTION struct stored in Printer_entry.
124 ****************************************************************************/
126 static void free_spool_notify_option(SPOOL_NOTIFY_OPTION **pp)
131 SAFE_FREE((*pp)->ctr.type);
135 /***************************************************************************
136 Disconnect from the client
137 ****************************************************************************/
139 static void srv_spoolss_replycloseprinter(int snum, POLICY_HND *handle)
144 * Tell the specific printing tdb we no longer want messages for this printer
145 * by deregistering our PID.
148 if (!print_notify_deregister_pid(snum))
149 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", lp_const_servicename(snum) ));
151 /* weird if the test succeds !!! */
152 if (smb_connections==0) {
153 DEBUG(0,("srv_spoolss_replycloseprinter:Trying to close non-existant notify backchannel !\n"));
157 result = rpccli_spoolss_reply_close_printer(notify_cli_pipe, notify_cli_pipe->cli->mem_ctx, handle);
159 if (!W_ERROR_IS_OK(result))
160 DEBUG(0,("srv_spoolss_replycloseprinter: reply_close_printer failed [%s].\n",
161 dos_errstr(result)));
163 /* if it's the last connection, deconnect the IPC$ share */
164 if (smb_connections==1) {
166 cli_shutdown( notify_cli_pipe->cli );
167 notify_cli_pipe = NULL; /* The above call shuts downn the pipe also. */
169 messaging_deregister(smbd_messaging_context(),
170 MSG_PRINTER_NOTIFY2, NULL);
172 /* Tell the connections db we're no longer interested in
173 * printer notify messages. */
175 register_message_flags( False, FLAG_MSG_PRINT_NOTIFY );
181 /****************************************************************************
182 Functions to free a printer entry datastruct.
183 ****************************************************************************/
185 static void free_printer_entry(void *ptr)
187 Printer_entry *Printer = (Printer_entry *)ptr;
189 if (Printer->notify.client_connected==True) {
192 if ( Printer->printer_type == SPLHND_SERVER) {
194 srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd);
195 } else if (Printer->printer_type == SPLHND_PRINTER) {
196 snum = print_queue_snum(Printer->sharename);
198 srv_spoolss_replycloseprinter(snum,
199 &Printer->notify.client_hnd);
203 Printer->notify.flags=0;
204 Printer->notify.options=0;
205 Printer->notify.localmachine[0]='\0';
206 Printer->notify.printerlocal=0;
207 free_spool_notify_option(&Printer->notify.option);
208 Printer->notify.option=NULL;
209 Printer->notify.client_connected=False;
211 free_nt_devicemode( &Printer->nt_devmode );
212 free_a_printer( &Printer->printer_info, 2 );
214 talloc_destroy( Printer->ctx );
216 /* Remove from the internal list. */
217 DLIST_REMOVE(printers_list, Printer);
222 /****************************************************************************
223 Functions to duplicate a SPOOL_NOTIFY_OPTION struct stored in Printer_entry.
224 ****************************************************************************/
226 static SPOOL_NOTIFY_OPTION *dup_spool_notify_option(SPOOL_NOTIFY_OPTION *sp)
228 SPOOL_NOTIFY_OPTION *new_sp = NULL;
233 new_sp = SMB_MALLOC_P(SPOOL_NOTIFY_OPTION);
240 new_sp->ctr.type = (SPOOL_NOTIFY_OPTION_TYPE *)memdup(sp->ctr.type, sizeof(SPOOL_NOTIFY_OPTION_TYPE) * sp->ctr.count);
242 if (!new_sp->ctr.type) {
251 /****************************************************************************
252 find printer index by handle
253 ****************************************************************************/
255 static Printer_entry *find_printer_index_by_hnd(pipes_struct *p, POLICY_HND *hnd)
257 Printer_entry *find_printer = NULL;
259 if(!find_policy_by_hnd(p,hnd,(void **)(void *)&find_printer)) {
260 DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: "));
267 /****************************************************************************
268 Close printer index by handle.
269 ****************************************************************************/
271 static BOOL close_printer_handle(pipes_struct *p, POLICY_HND *hnd)
273 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
276 DEBUG(2,("close_printer_handle: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(hnd)));
280 close_policy_hnd(p, hnd);
285 /****************************************************************************
286 Delete a printer given a handle.
287 ****************************************************************************/
288 WERROR delete_printer_hook( NT_USER_TOKEN *token, const char *sharename )
290 char *cmd = lp_deleteprinter_cmd();
293 SE_PRIV se_printop = SE_PRINT_OPERATOR;
294 BOOL is_print_op = False;
296 /* can't fail if we don't try */
301 pstr_sprintf(command, "%s \"%s\"", cmd, sharename);
304 is_print_op = user_has_privileges( token, &se_printop );
306 DEBUG(10,("Running [%s]\n", command));
308 /********** BEGIN SePrintOperatorPrivlege BLOCK **********/
313 if ( (ret = smbrun(command, NULL)) == 0 ) {
314 /* Tell everyone we updated smb.conf. */
315 message_send_all(smbd_messaging_context(),
316 MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
322 /********** END SePrintOperatorPrivlege BLOCK **********/
324 DEBUGADD(10,("returned [%d]\n", ret));
327 return WERR_BADFID; /* What to return here? */
329 /* go ahead and re-read the services immediately */
330 reload_services( False );
332 if ( share_defined( sharename ) )
333 return WERR_ACCESS_DENIED;
338 /****************************************************************************
339 Delete a printer given a handle.
340 ****************************************************************************/
342 static WERROR delete_printer_handle(pipes_struct *p, POLICY_HND *hnd)
344 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
347 DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(hnd)));
352 * It turns out that Windows allows delete printer on a handle
353 * opened by an admin user, then used on a pipe handle created
354 * by an anonymous user..... but they're working on security.... riiight !
358 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
359 DEBUG(3, ("delete_printer_handle: denied by handle\n"));
360 return WERR_ACCESS_DENIED;
363 /* this does not need a become root since the access check has been
364 done on the handle already */
366 if (del_a_printer( Printer->sharename ) != 0) {
367 DEBUG(3,("Error deleting printer %s\n", Printer->sharename));
371 return delete_printer_hook( p->pipe_user.nt_user_token, Printer->sharename );
374 /****************************************************************************
375 Return the snum of a printer corresponding to an handle.
376 ****************************************************************************/
378 static BOOL get_printer_snum(pipes_struct *p, POLICY_HND *hnd, int *number,
379 struct share_params **params)
381 Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
384 DEBUG(2,("get_printer_snum: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(hnd)));
388 switch (Printer->printer_type) {
390 DEBUG(4,("short name:%s\n", Printer->sharename));
391 *number = print_queue_snum(Printer->sharename);
392 if ((*number != -1) && (params != NULL)) {
393 *params = get_share_params(tmp_talloc_ctx(),
395 if (*params == NULL) {
399 return (*number != -1);
407 /****************************************************************************
408 Set printer handle type.
409 Check if it's \\server or \\server\printer
410 ****************************************************************************/
412 static BOOL set_printer_hnd_printertype(Printer_entry *Printer, char *handlename)
414 DEBUG(3,("Setting printer type=%s\n", handlename));
416 if ( strlen(handlename) < 3 ) {
417 DEBUGADD(4,("A print server must have at least 1 char ! %s\n", handlename));
421 /* it's a print server */
422 if (*handlename=='\\' && *(handlename+1)=='\\' && !strchr_m(handlename+2, '\\')) {
423 DEBUGADD(4,("Printer is a print server\n"));
424 Printer->printer_type = SPLHND_SERVER;
426 /* it's a printer (set_printer_hnd_name() will handle port monitors */
428 DEBUGADD(4,("Printer is a printer\n"));
429 Printer->printer_type = SPLHND_PRINTER;
435 /****************************************************************************
436 Set printer handle name.. Accept names like \\server, \\server\printer,
437 \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
438 the MSDN docs regarding OpenPrinter() for details on the XcvData() and
439 XcvDataPort() interface.
440 ****************************************************************************/
442 static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename)
445 int n_services=lp_numservices();
446 char *aprinter, *printername;
447 const char *servername;
450 NT_PRINTER_INFO_LEVEL *printer = NULL;
453 DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename, (unsigned long)strlen(handlename)));
455 aprinter = handlename;
456 if ( *handlename == '\\' ) {
457 servername = handlename + 2;
458 if ( (aprinter = strchr_m( handlename+2, '\\' )) != NULL ) {
467 /* save the servername to fill in replies on this handle */
469 if ( !is_myname_or_ipaddr( servername ) )
472 fstrcpy( Printer->servername, servername );
474 if ( Printer->printer_type == SPLHND_SERVER )
477 if ( Printer->printer_type != SPLHND_PRINTER )
480 DEBUGADD(5, ("searching for [%s]\n", aprinter ));
482 /* check for the Port Monitor Interface */
484 if ( strequal( aprinter, SPL_XCV_MONITOR_TCPMON ) ) {
485 Printer->printer_type = SPLHND_PORTMON_TCP;
486 fstrcpy(sname, SPL_XCV_MONITOR_TCPMON);
489 else if ( strequal( aprinter, SPL_XCV_MONITOR_LOCALMON ) ) {
490 Printer->printer_type = SPLHND_PORTMON_LOCAL;
491 fstrcpy(sname, SPL_XCV_MONITOR_LOCALMON);
495 /* Search all sharenames first as this is easier than pulling
496 the printer_info_2 off of disk. Don't use find_service() since
497 that calls out to map_username() */
499 /* do another loop to look for printernames */
501 for (snum=0; !found && snum<n_services; snum++) {
503 /* no point going on if this is not a printer */
505 if ( !(lp_snum_ok(snum) && lp_print_ok(snum)) )
508 fstrcpy(sname, lp_servicename(snum));
509 if ( strequal( aprinter, sname ) ) {
514 /* no point looking up the printer object if
515 we aren't allowing printername != sharename */
517 if ( lp_force_printername(snum) )
520 fstrcpy(sname, lp_servicename(snum));
523 result = get_a_printer( NULL, &printer, 2, sname );
524 if ( !W_ERROR_IS_OK(result) ) {
525 DEBUG(0,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
526 sname, dos_errstr(result)));
530 /* printername is always returned as \\server\printername */
531 if ( !(printername = strchr_m(&printer->info_2->printername[2], '\\')) ) {
532 DEBUG(0,("set_printer_hnd_name: info2->printername in wrong format! [%s]\n",
533 printer->info_2->printername));
534 free_a_printer( &printer, 2);
540 if ( strequal(printername, aprinter) ) {
541 free_a_printer( &printer, 2);
546 DEBUGADD(10, ("printername: %s\n", printername));
548 free_a_printer( &printer, 2);
551 free_a_printer( &printer, 2);
554 DEBUGADD(4,("Printer not found\n"));
558 DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter, sname));
560 fstrcpy(Printer->sharename, sname);
565 /****************************************************************************
566 Find first available printer slot. creates a printer handle for you.
567 ****************************************************************************/
569 static BOOL open_printer_hnd(pipes_struct *p, POLICY_HND *hnd, char *name, uint32 access_granted)
571 Printer_entry *new_printer;
573 DEBUG(10,("open_printer_hnd: name [%s]\n", name));
575 if((new_printer=SMB_MALLOC_P(Printer_entry)) == NULL)
578 ZERO_STRUCTP(new_printer);
580 if (!create_policy_hnd(p, hnd, free_printer_entry, new_printer)) {
581 SAFE_FREE(new_printer);
585 /* Add to the internal list. */
586 DLIST_ADD(printers_list, new_printer);
588 new_printer->notify.option=NULL;
590 if ( !(new_printer->ctx = talloc_init("Printer Entry [%p]", hnd)) ) {
591 DEBUG(0,("open_printer_hnd: talloc_init() failed!\n"));
592 close_printer_handle(p, hnd);
596 if (!set_printer_hnd_printertype(new_printer, name)) {
597 close_printer_handle(p, hnd);
601 if (!set_printer_hnd_name(new_printer, name)) {
602 close_printer_handle(p, hnd);
606 new_printer->access_granted = access_granted;
608 DEBUG(5, ("%d printer handles active\n", (int)p->pipe_handles->count ));
613 /***************************************************************************
614 check to see if the client motify handle is monitoring the notification
615 given by (notify_type, notify_field).
616 **************************************************************************/
618 static BOOL is_monitoring_event_flags(uint32 flags, uint16 notify_type,
624 static BOOL is_monitoring_event(Printer_entry *p, uint16 notify_type,
627 SPOOL_NOTIFY_OPTION *option = p->notify.option;
631 * Flags should always be zero when the change notify
632 * is registered by the client's spooler. A user Win32 app
633 * might use the flags though instead of the NOTIFY_OPTION_INFO
642 return is_monitoring_event_flags(
643 p->notify.flags, notify_type, notify_field);
645 for (i = 0; i < option->count; i++) {
647 /* Check match for notify_type */
649 if (option->ctr.type[i].type != notify_type)
652 /* Check match for field */
654 for (j = 0; j < option->ctr.type[i].count; j++) {
655 if (option->ctr.type[i].fields[j] == notify_field) {
661 DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n",
662 p->servername, p->sharename, notify_type, notify_field));
667 /* Convert a notification message to a SPOOL_NOTIFY_INFO_DATA struct */
669 static void notify_one_value(struct spoolss_notify_msg *msg,
670 SPOOL_NOTIFY_INFO_DATA *data,
673 data->notify_data.value[0] = msg->notify.value[0];
674 data->notify_data.value[1] = 0;
677 static void notify_string(struct spoolss_notify_msg *msg,
678 SPOOL_NOTIFY_INFO_DATA *data,
683 /* The length of the message includes the trailing \0 */
685 init_unistr2(&unistr, msg->notify.data, UNI_STR_TERMINATE);
687 data->notify_data.data.length = msg->len * 2;
688 data->notify_data.data.string = TALLOC_ARRAY(mem_ctx, uint16, msg->len);
690 if (!data->notify_data.data.string) {
691 data->notify_data.data.length = 0;
695 memcpy(data->notify_data.data.string, unistr.buffer, msg->len * 2);
698 static void notify_system_time(struct spoolss_notify_msg *msg,
699 SPOOL_NOTIFY_INFO_DATA *data,
705 if (msg->len != sizeof(time_t)) {
706 DEBUG(5, ("notify_system_time: received wrong sized message (%d)\n",
711 if (!prs_init(&ps, RPC_MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL)) {
712 DEBUG(5, ("notify_system_time: prs_init() failed\n"));
716 if (!make_systemtime(&systime, gmtime((time_t *)msg->notify.data))) {
717 DEBUG(5, ("notify_system_time: unable to make systemtime\n"));
722 if (!spoolss_io_system_time("", &ps, 0, &systime)) {
727 data->notify_data.data.length = prs_offset(&ps);
728 if (prs_offset(&ps)) {
729 data->notify_data.data.string = (uint16 *)
730 TALLOC(mem_ctx, prs_offset(&ps));
731 if (!data->notify_data.data.string) {
735 prs_copy_all_data_out((char *)data->notify_data.data.string, &ps);
737 data->notify_data.data.string = NULL;
743 struct notify2_message_table {
745 void (*fn)(struct spoolss_notify_msg *msg,
746 SPOOL_NOTIFY_INFO_DATA *data, TALLOC_CTX *mem_ctx);
749 static struct notify2_message_table printer_notify_table[] = {
750 /* 0x00 */ { "PRINTER_NOTIFY_SERVER_NAME", notify_string },
751 /* 0x01 */ { "PRINTER_NOTIFY_PRINTER_NAME", notify_string },
752 /* 0x02 */ { "PRINTER_NOTIFY_SHARE_NAME", notify_string },
753 /* 0x03 */ { "PRINTER_NOTIFY_PORT_NAME", notify_string },
754 /* 0x04 */ { "PRINTER_NOTIFY_DRIVER_NAME", notify_string },
755 /* 0x05 */ { "PRINTER_NOTIFY_COMMENT", notify_string },
756 /* 0x06 */ { "PRINTER_NOTIFY_LOCATION", notify_string },
757 /* 0x07 */ { "PRINTER_NOTIFY_DEVMODE", NULL },
758 /* 0x08 */ { "PRINTER_NOTIFY_SEPFILE", notify_string },
759 /* 0x09 */ { "PRINTER_NOTIFY_PRINT_PROCESSOR", notify_string },
760 /* 0x0a */ { "PRINTER_NOTIFY_PARAMETERS", NULL },
761 /* 0x0b */ { "PRINTER_NOTIFY_DATATYPE", notify_string },
762 /* 0x0c */ { "PRINTER_NOTIFY_SECURITY_DESCRIPTOR", NULL },
763 /* 0x0d */ { "PRINTER_NOTIFY_ATTRIBUTES", notify_one_value },
764 /* 0x0e */ { "PRINTER_NOTIFY_PRIORITY", notify_one_value },
765 /* 0x0f */ { "PRINTER_NOTIFY_DEFAULT_PRIORITY", NULL },
766 /* 0x10 */ { "PRINTER_NOTIFY_START_TIME", NULL },
767 /* 0x11 */ { "PRINTER_NOTIFY_UNTIL_TIME", NULL },
768 /* 0x12 */ { "PRINTER_NOTIFY_STATUS", notify_one_value },
771 static struct notify2_message_table job_notify_table[] = {
772 /* 0x00 */ { "JOB_NOTIFY_PRINTER_NAME", NULL },
773 /* 0x01 */ { "JOB_NOTIFY_MACHINE_NAME", NULL },
774 /* 0x02 */ { "JOB_NOTIFY_PORT_NAME", NULL },
775 /* 0x03 */ { "JOB_NOTIFY_USER_NAME", notify_string },
776 /* 0x04 */ { "JOB_NOTIFY_NOTIFY_NAME", NULL },
777 /* 0x05 */ { "JOB_NOTIFY_DATATYPE", NULL },
778 /* 0x06 */ { "JOB_NOTIFY_PRINT_PROCESSOR", NULL },
779 /* 0x07 */ { "JOB_NOTIFY_PARAMETERS", NULL },
780 /* 0x08 */ { "JOB_NOTIFY_DRIVER_NAME", NULL },
781 /* 0x09 */ { "JOB_NOTIFY_DEVMODE", NULL },
782 /* 0x0a */ { "JOB_NOTIFY_STATUS", notify_one_value },
783 /* 0x0b */ { "JOB_NOTIFY_STATUS_STRING", NULL },
784 /* 0x0c */ { "JOB_NOTIFY_SECURITY_DESCRIPTOR", NULL },
785 /* 0x0d */ { "JOB_NOTIFY_DOCUMENT", notify_string },
786 /* 0x0e */ { "JOB_NOTIFY_PRIORITY", NULL },
787 /* 0x0f */ { "JOB_NOTIFY_POSITION", NULL },
788 /* 0x10 */ { "JOB_NOTIFY_SUBMITTED", notify_system_time },
789 /* 0x11 */ { "JOB_NOTIFY_START_TIME", NULL },
790 /* 0x12 */ { "JOB_NOTIFY_UNTIL_TIME", NULL },
791 /* 0x13 */ { "JOB_NOTIFY_TIME", NULL },
792 /* 0x14 */ { "JOB_NOTIFY_TOTAL_PAGES", notify_one_value },
793 /* 0x15 */ { "JOB_NOTIFY_PAGES_PRINTED", NULL },
794 /* 0x16 */ { "JOB_NOTIFY_TOTAL_BYTES", notify_one_value },
795 /* 0x17 */ { "JOB_NOTIFY_BYTES_PRINTED", NULL },
799 /***********************************************************************
800 Allocate talloc context for container object
801 **********************************************************************/
803 static void notify_msg_ctr_init( SPOOLSS_NOTIFY_MSG_CTR *ctr )
808 ctr->ctx = talloc_init("notify_msg_ctr_init %p", ctr);
813 /***********************************************************************
814 release all allocated memory and zero out structure
815 **********************************************************************/
817 static void notify_msg_ctr_destroy( SPOOLSS_NOTIFY_MSG_CTR *ctr )
823 talloc_destroy(ctr->ctx);
830 /***********************************************************************
831 **********************************************************************/
833 static TALLOC_CTX* notify_ctr_getctx( SPOOLSS_NOTIFY_MSG_CTR *ctr )
841 /***********************************************************************
842 **********************************************************************/
844 static SPOOLSS_NOTIFY_MSG_GROUP* notify_ctr_getgroup( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx )
846 if ( !ctr || !ctr->msg_groups )
849 if ( idx >= ctr->num_groups )
852 return &ctr->msg_groups[idx];
856 /***********************************************************************
857 How many groups of change messages do we have ?
858 **********************************************************************/
860 static int notify_msg_ctr_numgroups( SPOOLSS_NOTIFY_MSG_CTR *ctr )
865 return ctr->num_groups;
868 /***********************************************************************
869 Add a SPOOLSS_NOTIFY_MSG_CTR to the correct group
870 **********************************************************************/
872 static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MSG *msg )
874 SPOOLSS_NOTIFY_MSG_GROUP *groups = NULL;
875 SPOOLSS_NOTIFY_MSG_GROUP *msg_grp = NULL;
876 SPOOLSS_NOTIFY_MSG *msg_list = NULL;
882 /* loop over all groups looking for a matching printer name */
884 for ( i=0; i<ctr->num_groups; i++ ) {
885 if ( strcmp(ctr->msg_groups[i].printername, msg->printer) == 0 )
889 /* add a new group? */
891 if ( i == ctr->num_groups ) {
894 if ( !(groups = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->msg_groups, SPOOLSS_NOTIFY_MSG_GROUP, ctr->num_groups)) ) {
895 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
898 ctr->msg_groups = groups;
900 /* clear the new entry and set the printer name */
902 ZERO_STRUCT( ctr->msg_groups[ctr->num_groups-1] );
903 fstrcpy( ctr->msg_groups[ctr->num_groups-1].printername, msg->printer );
906 /* add the change messages; 'i' is the correct index now regardless */
908 msg_grp = &ctr->msg_groups[i];
912 if ( !(msg_list = TALLOC_REALLOC_ARRAY( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) {
913 DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs));
916 msg_grp->msgs = msg_list;
918 new_slot = msg_grp->num_msgs-1;
919 memcpy( &msg_grp->msgs[new_slot], msg, sizeof(SPOOLSS_NOTIFY_MSG) );
921 /* need to allocate own copy of data */
924 msg_grp->msgs[new_slot].notify.data = (char *)
925 TALLOC_MEMDUP( ctr->ctx, msg->notify.data, msg->len );
927 return ctr->num_groups;
930 /***********************************************************************
931 Send a change notication message on all handles which have a call
933 **********************************************************************/
935 static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx )
938 TALLOC_CTX *mem_ctx = notify_ctr_getctx( ctr );
939 SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx );
940 SPOOLSS_NOTIFY_MSG *messages;
941 int sending_msg_count;
944 DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
948 messages = msg_group->msgs;
951 DEBUG(5,("send_notify2_changes() called with no messages!\n"));
955 DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername));
957 /* loop over all printers */
959 for (p = printers_list; p; p = p->next) {
960 SPOOL_NOTIFY_INFO_DATA *data;
965 /* Is there notification on this handle? */
967 if ( !p->notify.client_connected )
970 DEBUG(10,("Client connected! [\\\\%s\\%s]\n", p->servername, p->sharename));
972 /* For this printer? Print servers always receive
975 if ( ( p->printer_type == SPLHND_PRINTER ) &&
976 ( !strequal(msg_group->printername, p->sharename) ) )
979 DEBUG(10,("Our printer\n"));
981 /* allocate the max entries possible */
983 data = TALLOC_ARRAY( mem_ctx, SPOOL_NOTIFY_INFO_DATA, msg_group->num_msgs);
990 /* build the array of change notifications */
992 sending_msg_count = 0;
994 for ( i=0; i<msg_group->num_msgs; i++ ) {
995 SPOOLSS_NOTIFY_MSG *msg = &messages[i];
997 /* Are we monitoring this event? */
999 if (!is_monitoring_event(p, msg->type, msg->field))
1002 sending_msg_count++;
1005 DEBUG(10,("process_notify2_message: Sending message type [0x%x] field [0x%2x] for printer [%s]\n",
1006 msg->type, msg->field, p->sharename));
1009 * if the is a printer notification handle and not a job notification
1010 * type, then set the id to 0. Other wise just use what was specified
1013 * When registering change notification on a print server handle
1014 * we always need to send back the id (snum) matching the printer
1015 * for which the change took place. For change notify registered
1016 * on a printer handle, this does not matter and the id should be 0.
1021 if ( ( p->printer_type == SPLHND_PRINTER ) && ( msg->type == PRINTER_NOTIFY_TYPE ) )
1027 /* Convert unix jobid to smb jobid */
1029 if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) {
1030 id = sysjob_to_jobid(msg->id);
1033 DEBUG(3, ("no such unix jobid %d\n", msg->id));
1038 construct_info_data( &data[data_len], msg->type, msg->field, id );
1041 case PRINTER_NOTIFY_TYPE:
1042 if ( printer_notify_table[msg->field].fn )
1043 printer_notify_table[msg->field].fn(msg, &data[data_len], mem_ctx);
1046 case JOB_NOTIFY_TYPE:
1047 if ( job_notify_table[msg->field].fn )
1048 job_notify_table[msg->field].fn(msg, &data[data_len], mem_ctx);
1052 DEBUG(5, ("Unknown notification type %d\n", msg->type));
1059 if ( sending_msg_count ) {
1060 rpccli_spoolss_rrpcn( notify_cli_pipe, mem_ctx, &p->notify.client_hnd,
1061 data_len, data, p->notify.change, 0 );
1066 DEBUG(8,("send_notify2_changes: Exit...\n"));
1070 /***********************************************************************
1071 **********************************************************************/
1073 static BOOL notify2_unpack_msg( SPOOLSS_NOTIFY_MSG *msg, struct timeval *tv, void *buf, size_t len )
1076 uint32 tv_sec, tv_usec;
1079 /* Unpack message */
1081 offset += tdb_unpack((uint8 *)buf + offset, len - offset, "f",
1084 offset += tdb_unpack((uint8 *)buf + offset, len - offset, "ddddddd",
1086 &msg->type, &msg->field, &msg->id, &msg->len, &msg->flags);
1089 tdb_unpack((uint8 *)buf + offset, len - offset, "dd",
1090 &msg->notify.value[0], &msg->notify.value[1]);
1092 tdb_unpack((uint8 *)buf + offset, len - offset, "B",
1093 &msg->len, &msg->notify.data);
1095 DEBUG(3, ("notify2_unpack_msg: got NOTIFY2 message for printer %s, jobid %u type %d, field 0x%02x, flags 0x%04x\n",
1096 msg->printer, (unsigned int)msg->id, msg->type, msg->field, msg->flags));
1098 tv->tv_sec = tv_sec;
1099 tv->tv_usec = tv_usec;
1102 DEBUG(3, ("notify2_unpack_msg: value1 = %d, value2 = %d\n", msg->notify.value[0],
1103 msg->notify.value[1]));
1105 dump_data(3, (uint8 *)msg->notify.data, msg->len);
1110 /********************************************************************
1111 Receive a notify2 message list
1112 ********************************************************************/
1114 static void receive_notify2_message_list(struct messaging_context *msg,
1117 struct server_id server_id,
1120 size_t msg_count, i;
1121 char *buf = (char *)data->data;
1124 SPOOLSS_NOTIFY_MSG notify;
1125 SPOOLSS_NOTIFY_MSG_CTR messages;
1128 if (data->length < 4) {
1129 DEBUG(0,("receive_notify2_message_list: bad message format (len < 4)!\n"));
1133 msg_count = IVAL(buf, 0);
1136 DEBUG(5, ("receive_notify2_message_list: got %lu messages in list\n", (unsigned long)msg_count));
1138 if (msg_count == 0) {
1139 DEBUG(0,("receive_notify2_message_list: bad message format (msg_count == 0) !\n"));
1143 /* initialize the container */
1145 ZERO_STRUCT( messages );
1146 notify_msg_ctr_init( &messages );
1149 * build message groups for each printer identified
1150 * in a change_notify msg. Remember that a PCN message
1151 * includes the handle returned for the srv_spoolss_replyopenprinter()
1152 * call. Therefore messages are grouped according to printer handle.
1155 for ( i=0; i<msg_count; i++ ) {
1156 struct timeval msg_tv;
1158 if (msg_ptr + 4 - buf > data->length) {
1159 DEBUG(0,("receive_notify2_message_list: bad message format (len > buf_size) !\n"));
1163 msg_len = IVAL(msg_ptr,0);
1166 if (msg_ptr + msg_len - buf > data->length) {
1167 DEBUG(0,("receive_notify2_message_list: bad message format (bad len) !\n"));
1171 /* unpack messages */
1173 ZERO_STRUCT( notify );
1174 notify2_unpack_msg( ¬ify, &msg_tv, msg_ptr, msg_len );
1177 /* add to correct list in container */
1179 notify_msg_ctr_addmsg( &messages, ¬ify );
1181 /* free memory that might have been allocated by notify2_unpack_msg() */
1183 if ( notify.len != 0 )
1184 SAFE_FREE( notify.notify.data );
1187 /* process each group of messages */
1189 num_groups = notify_msg_ctr_numgroups( &messages );
1190 for ( i=0; i<num_groups; i++ )
1191 send_notify2_changes( &messages, i );
1196 DEBUG(10,("receive_notify2_message_list: processed %u messages\n", (uint32)msg_count ));
1198 notify_msg_ctr_destroy( &messages );
1203 /********************************************************************
1204 Send a message to ourself about new driver being installed
1205 so we can upgrade the information for each printer bound to this
1207 ********************************************************************/
1209 static BOOL srv_spoolss_drv_upgrade_printer(char* drivername)
1211 int len = strlen(drivername);
1216 DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
1219 messaging_send_buf(smbd_messaging_context(), procid_self(),
1220 MSG_PRINTER_DRVUPGRADE,
1221 (uint8 *)drivername, len+1);
1226 /**********************************************************************
1227 callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
1228 over all printers, upgrading ones as necessary
1229 **********************************************************************/
1231 void do_drv_upgrade_printer(struct messaging_context *msg,
1234 struct server_id server_id,
1239 int n_services = lp_numservices();
1242 len = MIN(data->length,sizeof(drivername)-1);
1243 strncpy(drivername, (const char *)data->data, len);
1245 DEBUG(10,("do_drv_upgrade_printer: Got message for new driver [%s]\n", drivername ));
1247 /* Iterate the printer list */
1249 for (snum=0; snum<n_services; snum++)
1251 if (lp_snum_ok(snum) && lp_print_ok(snum) )
1254 NT_PRINTER_INFO_LEVEL *printer = NULL;
1256 result = get_a_printer(NULL, &printer, 2, lp_const_servicename(snum));
1257 if (!W_ERROR_IS_OK(result))
1260 if (printer && printer->info_2 && !strcmp(drivername, printer->info_2->drivername))
1262 DEBUG(6,("Updating printer [%s]\n", printer->info_2->printername));
1264 /* all we care about currently is the change_id */
1266 result = mod_a_printer(printer, 2);
1267 if (!W_ERROR_IS_OK(result)) {
1268 DEBUG(3,("do_drv_upgrade_printer: mod_a_printer() failed with status [%s]\n",
1269 dos_errstr(result)));
1273 free_a_printer(&printer, 2);
1280 /********************************************************************
1281 Update the cache for all printq's with a registered client
1283 ********************************************************************/
1285 void update_monitored_printq_cache( void )
1287 Printer_entry *printer = printers_list;
1290 /* loop through all printers and update the cache where
1291 client_connected == True */
1294 if ( (printer->printer_type == SPLHND_PRINTER)
1295 && printer->notify.client_connected )
1297 snum = print_queue_snum(printer->sharename);
1298 print_queue_status( snum, NULL, NULL );
1301 printer = printer->next;
1306 /********************************************************************
1307 Send a message to ourself about new driver being installed
1308 so we can upgrade the information for each printer bound to this
1310 ********************************************************************/
1312 static BOOL srv_spoolss_reset_printerdata(char* drivername)
1314 int len = strlen(drivername);
1319 DEBUG(10,("srv_spoolss_reset_printerdata: Sending message about resetting printerdata [%s]\n",
1322 messaging_send_buf(smbd_messaging_context(), procid_self(),
1323 MSG_PRINTERDATA_INIT_RESET,
1324 (uint8 *)drivername, len+1);
1329 /**********************************************************************
1330 callback to receive a MSG_PRINTERDATA_INIT_RESET message and interate
1331 over all printers, resetting printer data as neessary
1332 **********************************************************************/
1334 void reset_all_printerdata(struct messaging_context *msg,
1337 struct server_id server_id,
1342 int n_services = lp_numservices();
1345 len = MIN( data->length, sizeof(drivername)-1 );
1346 strncpy( drivername, (const char *)data->data, len );
1348 DEBUG(10,("reset_all_printerdata: Got message for new driver [%s]\n", drivername ));
1350 /* Iterate the printer list */
1352 for ( snum=0; snum<n_services; snum++ )
1354 if ( lp_snum_ok(snum) && lp_print_ok(snum) )
1357 NT_PRINTER_INFO_LEVEL *printer = NULL;
1359 result = get_a_printer( NULL, &printer, 2, lp_const_servicename(snum) );
1360 if ( !W_ERROR_IS_OK(result) )
1364 * if the printer is bound to the driver,
1365 * then reset to the new driver initdata
1368 if ( printer && printer->info_2 && !strcmp(drivername, printer->info_2->drivername) )
1370 DEBUG(6,("reset_all_printerdata: Updating printer [%s]\n", printer->info_2->printername));
1372 if ( !set_driver_init(printer, 2) ) {
1373 DEBUG(5,("reset_all_printerdata: Error resetting printer data for printer [%s], driver [%s]!\n",
1374 printer->info_2->printername, printer->info_2->drivername));
1377 result = mod_a_printer( printer, 2 );
1378 if ( !W_ERROR_IS_OK(result) ) {
1379 DEBUG(3,("reset_all_printerdata: mod_a_printer() failed! (%s)\n",
1380 get_dos_error_msg(result)));
1384 free_a_printer( &printer, 2 );
1393 /********************************************************************
1394 Copy routines used by convert_to_openprinterex()
1395 *******************************************************************/
1397 static DEVICEMODE* dup_devicemode(TALLOC_CTX *ctx, DEVICEMODE *devmode)
1405 DEBUG (8,("dup_devmode\n"));
1407 /* bulk copy first */
1409 d = (DEVICEMODE *)TALLOC_MEMDUP(ctx, devmode, sizeof(DEVICEMODE));
1413 /* dup the pointer members separately */
1415 len = unistrlen(devmode->devicename.buffer);
1417 d->devicename.buffer = TALLOC_ARRAY(ctx, uint16, len);
1418 if (!d->devicename.buffer) {
1421 if (unistrcpy(d->devicename.buffer, devmode->devicename.buffer) != len)
1426 len = unistrlen(devmode->formname.buffer);
1428 d->devicename.buffer = TALLOC_ARRAY(ctx, uint16, len);
1429 if (!d->devicename.buffer) {
1432 if (unistrcpy(d->formname.buffer, devmode->formname.buffer) != len)
1436 if (devmode->driverextra) {
1437 d->dev_private = (uint8 *)TALLOC_MEMDUP(ctx, devmode->dev_private,
1438 devmode->driverextra);
1439 if (!d->dev_private) {
1443 d->dev_private = NULL;
1448 static void copy_devmode_ctr(TALLOC_CTX *ctx, DEVMODE_CTR *new_ctr, DEVMODE_CTR *ctr)
1450 if (!new_ctr || !ctr)
1453 DEBUG(8,("copy_devmode_ctr\n"));
1455 new_ctr->size = ctr->size;
1456 new_ctr->devmode_ptr = ctr->devmode_ptr;
1458 if(ctr->devmode_ptr)
1459 new_ctr->devmode = dup_devicemode(ctx, ctr->devmode);
1462 static void copy_printer_default(TALLOC_CTX *ctx, PRINTER_DEFAULT *new_def, PRINTER_DEFAULT *def)
1464 if (!new_def || !def)
1467 DEBUG(8,("copy_printer_defaults\n"));
1469 new_def->datatype_ptr = def->datatype_ptr;
1471 if (def->datatype_ptr)
1472 copy_unistr2(&new_def->datatype, &def->datatype);
1474 copy_devmode_ctr(ctx, &new_def->devmode_cont, &def->devmode_cont);
1476 new_def->access_required = def->access_required;
1479 /********************************************************************
1480 * Convert a SPOOL_Q_OPEN_PRINTER structure to a
1481 * SPOOL_Q_OPEN_PRINTER_EX structure
1482 ********************************************************************/
1484 static WERROR convert_to_openprinterex(TALLOC_CTX *ctx, SPOOL_Q_OPEN_PRINTER_EX *q_u_ex, SPOOL_Q_OPEN_PRINTER *q_u)
1486 if (!q_u_ex || !q_u)
1489 DEBUG(8,("convert_to_openprinterex\n"));
1491 if ( q_u->printername ) {
1492 q_u_ex->printername = TALLOC_ZERO_P( ctx, UNISTR2 );
1493 if (q_u_ex->printername == NULL)
1495 copy_unistr2(q_u_ex->printername, q_u->printername);
1498 copy_printer_default(ctx, &q_u_ex->printer_default, &q_u->printer_default);
1503 /********************************************************************
1504 * spoolss_open_printer
1506 * called from the spoolss dispatcher
1507 ********************************************************************/
1509 WERROR _spoolss_open_printer(pipes_struct *p, SPOOL_Q_OPEN_PRINTER *q_u, SPOOL_R_OPEN_PRINTER *r_u)
1511 SPOOL_Q_OPEN_PRINTER_EX q_u_ex;
1512 SPOOL_R_OPEN_PRINTER_EX r_u_ex;
1517 ZERO_STRUCT(q_u_ex);
1518 ZERO_STRUCT(r_u_ex);
1520 /* convert the OpenPrinter() call to OpenPrinterEx() */
1522 r_u_ex.status = convert_to_openprinterex(p->mem_ctx, &q_u_ex, q_u);
1523 if (!W_ERROR_IS_OK(r_u_ex.status))
1524 return r_u_ex.status;
1526 r_u_ex.status = _spoolss_open_printer_ex(p, &q_u_ex, &r_u_ex);
1528 /* convert back to OpenPrinter() */
1530 memcpy(r_u, &r_u_ex, sizeof(*r_u));
1535 /********************************************************************
1536 ********************************************************************/
1538 WERROR _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, SPOOL_R_OPEN_PRINTER_EX *r_u)
1540 PRINTER_DEFAULT *printer_default = &q_u->printer_default;
1541 POLICY_HND *handle = &r_u->handle;
1545 Printer_entry *Printer=NULL;
1547 if ( !q_u->printername )
1548 return WERR_INVALID_PRINTER_NAME;
1550 /* some sanity check because you can open a printer or a print server */
1551 /* aka: \\server\printer or \\server */
1553 unistr2_to_ascii(name, q_u->printername, sizeof(name)-1);
1555 DEBUGADD(3,("checking name: %s\n",name));
1557 if (!open_printer_hnd(p, handle, name, 0))
1558 return WERR_INVALID_PRINTER_NAME;
1560 Printer=find_printer_index_by_hnd(p, handle);
1562 DEBUG(0,(" _spoolss_open_printer_ex: logic error. Can't find printer "
1563 "handle we created for printer %s\n", name ));
1564 close_printer_handle(p,handle);
1565 return WERR_INVALID_PRINTER_NAME;
1569 * First case: the user is opening the print server:
1571 * Disallow MS AddPrinterWizard if parameter disables it. A Win2k
1572 * client 1st tries an OpenPrinterEx with access==0, MUST be allowed.
1574 * Then both Win2k and WinNT clients try an OpenPrinterEx with
1575 * SERVER_ALL_ACCESS, which we allow only if the user is root (uid=0)
1576 * or if the user is listed in the smb.conf printer admin parameter.
1578 * Then they try OpenPrinterEx with SERVER_READ which we allow. This lets the
1579 * client view printer folder, but does not show the MSAPW.
1581 * Note: this test needs code to check access rights here too. Jeremy
1582 * could you look at this?
1584 * Second case: the user is opening a printer:
1585 * NT doesn't let us connect to a printer if the connecting user
1586 * doesn't have print permission.
1588 * Third case: user is opening a Port Monitor
1589 * access checks same as opening a handle to the print server.
1592 switch (Printer->printer_type )
1595 case SPLHND_PORTMON_TCP:
1596 case SPLHND_PORTMON_LOCAL:
1597 /* Printserver handles use global struct... */
1601 /* Map standard access rights to object specific access rights */
1603 se_map_standard(&printer_default->access_required,
1604 &printserver_std_mapping);
1606 /* Deny any object specific bits that don't apply to print
1607 servers (i.e printer and job specific bits) */
1609 printer_default->access_required &= SPECIFIC_RIGHTS_MASK;
1611 if (printer_default->access_required &
1612 ~(SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE)) {
1613 DEBUG(3, ("access DENIED for non-printserver bits\n"));
1614 close_printer_handle(p, handle);
1615 return WERR_ACCESS_DENIED;
1618 /* Allow admin access */
1620 if ( printer_default->access_required & SERVER_ACCESS_ADMINISTER )
1622 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1624 if (!lp_ms_add_printer_wizard()) {
1625 close_printer_handle(p, handle);
1626 return WERR_ACCESS_DENIED;
1629 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1630 and not a printer admin, then fail */
1632 if ((p->pipe_user.ut.uid != 0) &&
1633 !user_has_privileges(p->pipe_user.nt_user_token,
1635 !token_contains_name_in_list(
1636 uidtoname(p->pipe_user.ut.uid), NULL,
1637 p->pipe_user.nt_user_token,
1638 lp_printer_admin(snum))) {
1639 close_printer_handle(p, handle);
1640 return WERR_ACCESS_DENIED;
1643 printer_default->access_required = SERVER_ACCESS_ADMINISTER;
1647 printer_default->access_required = SERVER_ACCESS_ENUMERATE;
1650 DEBUG(4,("Setting print server access = %s\n", (printer_default->access_required == SERVER_ACCESS_ADMINISTER)
1651 ? "SERVER_ACCESS_ADMINISTER" : "SERVER_ACCESS_ENUMERATE" ));
1653 /* We fall through to return WERR_OK */
1656 case SPLHND_PRINTER:
1657 /* NT doesn't let us connect to a printer if the connecting user
1658 doesn't have print permission. */
1660 if (!get_printer_snum(p, handle, &snum, NULL)) {
1661 close_printer_handle(p, handle);
1665 se_map_standard(&printer_default->access_required, &printer_std_mapping);
1667 /* map an empty access mask to the minimum access mask */
1668 if (printer_default->access_required == 0x0)
1669 printer_default->access_required = PRINTER_ACCESS_USE;
1672 * If we are not serving the printer driver for this printer,
1673 * map PRINTER_ACCESS_ADMINISTER to PRINTER_ACCESS_USE. This
1674 * will keep NT clients happy --jerry
1677 if (lp_use_client_driver(snum)
1678 && (printer_default->access_required & PRINTER_ACCESS_ADMINISTER))
1680 printer_default->access_required = PRINTER_ACCESS_USE;
1683 /* check smb.conf parameters and the the sec_desc */
1685 if ( !check_access(smbd_server_fd(), lp_hostsallow(snum), lp_hostsdeny(snum)) ) {
1686 DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
1687 return WERR_ACCESS_DENIED;
1690 if (!user_ok_token(uidtoname(p->pipe_user.ut.uid),
1691 p->pipe_user.nt_user_token, snum) ||
1692 !print_access_check(&p->pipe_user, snum,
1693 printer_default->access_required)) {
1694 DEBUG(3, ("access DENIED for printer open\n"));
1695 close_printer_handle(p, handle);
1696 return WERR_ACCESS_DENIED;
1699 if ((printer_default->access_required & SPECIFIC_RIGHTS_MASK)& ~(PRINTER_ACCESS_ADMINISTER|PRINTER_ACCESS_USE)) {
1700 DEBUG(3, ("access DENIED for printer open - unknown bits\n"));
1701 close_printer_handle(p, handle);
1702 return WERR_ACCESS_DENIED;
1705 if (printer_default->access_required & PRINTER_ACCESS_ADMINISTER)
1706 printer_default->access_required = PRINTER_ACCESS_ADMINISTER;
1708 printer_default->access_required = PRINTER_ACCESS_USE;
1710 DEBUG(4,("Setting printer access = %s\n", (printer_default->access_required == PRINTER_ACCESS_ADMINISTER)
1711 ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
1716 /* sanity check to prevent programmer error */
1720 Printer->access_granted = printer_default->access_required;
1723 * If the client sent a devmode in the OpenPrinter() call, then
1724 * save it here in case we get a job submission on this handle
1727 if ( (Printer->printer_type != SPLHND_SERVER)
1728 && q_u->printer_default.devmode_cont.devmode_ptr )
1730 convert_devicemode( Printer->sharename, q_u->printer_default.devmode_cont.devmode,
1731 &Printer->nt_devmode );
1734 #if 0 /* JERRY -- I'm doubtful this is really effective */
1735 /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
1736 optimization in Windows 2000 clients --jerry */
1738 if ( (printer_default->access_required == PRINTER_ACCESS_ADMINISTER)
1739 && (RA_WIN2K == get_remote_arch()) )
1741 DEBUG(10,("_spoolss_open_printer_ex: Enabling LAN/WAN hack for Win2k clients.\n"));
1742 sys_usleep( 500000 );
1749 /****************************************************************************
1750 ****************************************************************************/
1752 static BOOL convert_printer_info(const SPOOL_PRINTER_INFO_LEVEL *uni,
1753 NT_PRINTER_INFO_LEVEL *printer, uint32 level)
1759 /* allocate memory if needed. Messy because
1760 convert_printer_info is used to update an existing
1761 printer or build a new one */
1763 if ( !printer->info_2 ) {
1764 printer->info_2 = TALLOC_ZERO_P( printer, NT_PRINTER_INFO_LEVEL_2 );
1765 if ( !printer->info_2 ) {
1766 DEBUG(0,("convert_printer_info: talloc() failed!\n"));
1771 ret = uni_2_asc_printer_info_2(uni->info_2, printer->info_2);
1772 printer->info_2->setuptime = time(NULL);
1780 static BOOL convert_printer_driver_info(const SPOOL_PRINTER_DRIVER_INFO_LEVEL *uni,
1781 NT_PRINTER_DRIVER_INFO_LEVEL *printer, uint32 level)
1787 printer->info_3=NULL;
1788 if (!uni_2_asc_printer_driver_3(uni->info_3, &printer->info_3))
1792 printer->info_6=NULL;
1793 if (!uni_2_asc_printer_driver_6(uni->info_6, &printer->info_6))
1803 BOOL convert_devicemode(const char *printername, const DEVICEMODE *devmode,
1804 NT_DEVICEMODE **pp_nt_devmode)
1806 NT_DEVICEMODE *nt_devmode = *pp_nt_devmode;
1809 * Ensure nt_devmode is a valid pointer
1810 * as we will be overwriting it.
1813 if (nt_devmode == NULL) {
1814 DEBUG(5, ("convert_devicemode: allocating a generic devmode\n"));
1815 if ((nt_devmode = construct_nt_devicemode(printername)) == NULL)
1819 rpcstr_pull(nt_devmode->devicename,devmode->devicename.buffer, 31, -1, 0);
1820 rpcstr_pull(nt_devmode->formname,devmode->formname.buffer, 31, -1, 0);
1822 nt_devmode->specversion=devmode->specversion;
1823 nt_devmode->driverversion=devmode->driverversion;
1824 nt_devmode->size=devmode->size;
1825 nt_devmode->fields=devmode->fields;
1826 nt_devmode->orientation=devmode->orientation;
1827 nt_devmode->papersize=devmode->papersize;
1828 nt_devmode->paperlength=devmode->paperlength;
1829 nt_devmode->paperwidth=devmode->paperwidth;
1830 nt_devmode->scale=devmode->scale;
1831 nt_devmode->copies=devmode->copies;
1832 nt_devmode->defaultsource=devmode->defaultsource;
1833 nt_devmode->printquality=devmode->printquality;
1834 nt_devmode->color=devmode->color;
1835 nt_devmode->duplex=devmode->duplex;
1836 nt_devmode->yresolution=devmode->yresolution;
1837 nt_devmode->ttoption=devmode->ttoption;
1838 nt_devmode->collate=devmode->collate;
1840 nt_devmode->logpixels=devmode->logpixels;
1841 nt_devmode->bitsperpel=devmode->bitsperpel;
1842 nt_devmode->pelswidth=devmode->pelswidth;
1843 nt_devmode->pelsheight=devmode->pelsheight;
1844 nt_devmode->displayflags=devmode->displayflags;
1845 nt_devmode->displayfrequency=devmode->displayfrequency;
1846 nt_devmode->icmmethod=devmode->icmmethod;
1847 nt_devmode->icmintent=devmode->icmintent;
1848 nt_devmode->mediatype=devmode->mediatype;
1849 nt_devmode->dithertype=devmode->dithertype;
1850 nt_devmode->reserved1=devmode->reserved1;
1851 nt_devmode->reserved2=devmode->reserved2;
1852 nt_devmode->panningwidth=devmode->panningwidth;
1853 nt_devmode->panningheight=devmode->panningheight;
1856 * Only change private and driverextra if the incoming devmode
1857 * has a new one. JRA.
1860 if ((devmode->driverextra != 0) && (devmode->dev_private != NULL)) {
1861 SAFE_FREE(nt_devmode->nt_dev_private);
1862 nt_devmode->driverextra=devmode->driverextra;
1863 if((nt_devmode->nt_dev_private=SMB_MALLOC_ARRAY(uint8, nt_devmode->driverextra)) == NULL)
1865 memcpy(nt_devmode->nt_dev_private, devmode->dev_private, nt_devmode->driverextra);
1868 *pp_nt_devmode = nt_devmode;
1873 /********************************************************************
1874 * _spoolss_enddocprinter_internal.
1875 ********************************************************************/
1877 static WERROR _spoolss_enddocprinter_internal(pipes_struct *p, POLICY_HND *handle)
1879 Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
1883 DEBUG(2,("_spoolss_enddocprinter_internal: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(handle)));
1887 if (!get_printer_snum(p, handle, &snum, NULL))
1890 Printer->document_started=False;
1891 print_job_end(snum, Printer->jobid,NORMAL_CLOSE);
1892 /* error codes unhandled so far ... */
1897 /********************************************************************
1898 * api_spoolss_closeprinter
1899 ********************************************************************/
1901 WERROR _spoolss_closeprinter(pipes_struct *p, SPOOL_Q_CLOSEPRINTER *q_u, SPOOL_R_CLOSEPRINTER *r_u)
1903 POLICY_HND *handle = &q_u->handle;
1905 Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
1907 if (Printer && Printer->document_started)
1908 _spoolss_enddocprinter_internal(p, handle); /* print job was not closed */
1910 if (!close_printer_handle(p, handle))
1913 /* clear the returned printer handle. Observed behavior
1914 from Win2k server. Don't think this really matters.
1915 Previous code just copied the value of the closed
1918 memset(&r_u->handle, '\0', sizeof(r_u->handle));
1923 /********************************************************************
1924 * api_spoolss_deleteprinter
1926 ********************************************************************/
1928 WERROR _spoolss_deleteprinter(pipes_struct *p, SPOOL_Q_DELETEPRINTER *q_u, SPOOL_R_DELETEPRINTER *r_u)
1930 POLICY_HND *handle = &q_u->handle;
1931 Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
1934 if (Printer && Printer->document_started)
1935 _spoolss_enddocprinter_internal(p, handle); /* print job was not closed */
1937 memcpy(&r_u->handle, &q_u->handle, sizeof(r_u->handle));
1939 result = delete_printer_handle(p, handle);
1941 update_c_setprinter(False);
1946 /*******************************************************************
1947 * static function to lookup the version id corresponding to an
1948 * long architecture string
1949 ******************************************************************/
1951 static int get_version_id (char * arch)
1954 struct table_node archi_table[]= {
1956 {"Windows 4.0", "WIN40", 0 },
1957 {"Windows NT x86", "W32X86", 2 },
1958 {"Windows NT R4000", "W32MIPS", 2 },
1959 {"Windows NT Alpha_AXP", "W32ALPHA", 2 },
1960 {"Windows NT PowerPC", "W32PPC", 2 },
1961 {"Windows IA64", "IA64", 3 },
1962 {"Windows x64", "x64", 3 },
1966 for (i=0; archi_table[i].long_archi != NULL; i++)
1968 if (strcmp(arch, archi_table[i].long_archi) == 0)
1969 return (archi_table[i].version);
1975 /********************************************************************
1976 * _spoolss_deleteprinterdriver
1977 ********************************************************************/
1979 WERROR _spoolss_deleteprinterdriver(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIVER *q_u, SPOOL_R_DELETEPRINTERDRIVER *r_u)
1983 NT_PRINTER_DRIVER_INFO_LEVEL info;
1984 NT_PRINTER_DRIVER_INFO_LEVEL info_win2k;
1987 WERROR status_win2k = WERR_ACCESS_DENIED;
1988 SE_PRIV se_printop = SE_PRINT_OPERATOR;
1990 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
1991 and not a printer admin, then fail */
1993 if ( (p->pipe_user.ut.uid != 0)
1994 && !user_has_privileges(p->pipe_user.nt_user_token, &se_printop )
1995 && !token_contains_name_in_list( uidtoname(p->pipe_user.ut.uid),
1996 NULL, p->pipe_user.nt_user_token, lp_printer_admin(-1)) )
1998 return WERR_ACCESS_DENIED;
2001 unistr2_to_ascii(driver, &q_u->driver, sizeof(driver)-1 );
2002 unistr2_to_ascii(arch, &q_u->arch, sizeof(arch)-1 );
2004 /* check that we have a valid driver name first */
2006 if ((version=get_version_id(arch)) == -1)
2007 return WERR_INVALID_ENVIRONMENT;
2010 ZERO_STRUCT(info_win2k);
2012 if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3, driver, arch, version)))
2014 /* try for Win2k driver if "Windows NT x86" */
2016 if ( version == 2 ) {
2018 if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3, driver, arch, version))) {
2019 status = WERR_UNKNOWN_PRINTER_DRIVER;
2023 /* otherwise it was a failure */
2025 status = WERR_UNKNOWN_PRINTER_DRIVER;
2031 if (printer_driver_in_use(info.info_3)) {
2032 status = WERR_PRINTER_DRIVER_IN_USE;
2038 if (W_ERROR_IS_OK(get_a_printer_driver(&info_win2k, 3, driver, arch, 3)))
2040 /* if we get to here, we now have 2 driver info structures to remove */
2041 /* remove the Win2k driver first*/
2043 status_win2k = delete_printer_driver(info_win2k.info_3, &p->pipe_user, 3, False );
2044 free_a_printer_driver( info_win2k, 3 );
2046 /* this should not have failed---if it did, report to client */
2047 if ( !W_ERROR_IS_OK(status_win2k) )
2049 status = status_win2k;
2055 status = delete_printer_driver(info.info_3, &p->pipe_user, version, False);
2057 /* if at least one of the deletes succeeded return OK */
2059 if ( W_ERROR_IS_OK(status) || W_ERROR_IS_OK(status_win2k) )
2063 free_a_printer_driver( info, 3 );
2068 /********************************************************************
2069 * spoolss_deleteprinterdriverex
2070 ********************************************************************/
2072 WERROR _spoolss_deleteprinterdriverex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDRIVEREX *q_u, SPOOL_R_DELETEPRINTERDRIVEREX *r_u)
2076 NT_PRINTER_DRIVER_INFO_LEVEL info;
2077 NT_PRINTER_DRIVER_INFO_LEVEL info_win2k;
2079 uint32 flags = q_u->delete_flags;
2082 WERROR status_win2k = WERR_ACCESS_DENIED;
2083 SE_PRIV se_printop = SE_PRINT_OPERATOR;
2085 /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
2086 and not a printer admin, then fail */
2088 if ( (p->pipe_user.ut.uid != 0)
2089 && !user_has_privileges(p->pipe_user.nt_user_token, &se_printop )
2090 && !token_contains_name_in_list( uidtoname(p->pipe_user.ut.uid),
2091 NULL, p->pipe_user.nt_user_token, lp_printer_admin(-1)) )
2093 return WERR_ACCESS_DENIED;
2096 unistr2_to_ascii(driver, &q_u->driver, sizeof(driver)-1 );
2097 unistr2_to_ascii(arch, &q_u->arch, sizeof(arch)-1 );
2099 /* check that we have a valid driver name first */
2100 if ((version=get_version_id(arch)) == -1) {
2101 /* this is what NT returns */
2102 return WERR_INVALID_ENVIRONMENT;
2105 if ( flags & DPD_DELETE_SPECIFIC_VERSION )
2106 version = q_u->version;
2109 ZERO_STRUCT(info_win2k);
2111 status = get_a_printer_driver(&info, 3, driver, arch, version);
2113 if ( !W_ERROR_IS_OK(status) )
2116 * if the client asked for a specific version,
2117 * or this is something other than Windows NT x86,
2121 if ( (flags&DPD_DELETE_SPECIFIC_VERSION) || (version !=2) )
2124 /* try for Win2k driver if "Windows NT x86" */
2127 if (!W_ERROR_IS_OK(get_a_printer_driver(&info, 3, driver, arch, version))) {
2128 status = WERR_UNKNOWN_PRINTER_DRIVER;
2133 if ( printer_driver_in_use(info.info_3) ) {
2134 status = WERR_PRINTER_DRIVER_IN_USE;
2139 * we have a couple of cases to consider.
2140 * (1) Are any files in use? If so and DPD_DELTE_ALL_FILE is set,
2141 * then the delete should fail if **any** files overlap with
2143 * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
2144 * non-overlapping files
2145 * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
2146 * is set, the do not delete any files
2147 * Refer to MSDN docs on DeletePrinterDriverEx() for details.
2150 delete_files = flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES);
2152 /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
2154 if ( delete_files && printer_driver_files_in_use(info.info_3) & (flags&DPD_DELETE_ALL_FILES) ) {
2155 /* no idea of the correct error here */
2156 status = WERR_ACCESS_DENIED;
2161 /* also check for W32X86/3 if necessary; maybe we already have? */
2163 if ( (version == 2) && ((flags&DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION) ) {
2164 if (W_ERROR_IS_OK(get_a_printer_driver(&info_win2k, 3, driver, arch, 3)))
2167 if ( delete_files && printer_driver_files_in_use(info_win2k.info_3) & (flags&DPD_DELETE_ALL_FILES) ) {
2168 /* no idea of the correct error here */
2169 free_a_printer_driver( info_win2k, 3 );
2170 status = WERR_ACCESS_DENIED;
2174 /* if we get to here, we now have 2 driver info structures to remove */
2175 /* remove the Win2k driver first*/
2177 status_win2k = delete_printer_driver(info_win2k.info_3, &p->pipe_user, 3, delete_files);
2178 free_a_printer_driver( info_win2k, 3 );
2180 /* this should not have failed---if it did, report to client */
2182 if ( !W_ERROR_IS_OK(status_win2k) )
2187 status = delete_printer_driver(info.info_3, &p->pipe_user, version, delete_files);
2189 if ( W_ERROR_IS_OK(status) || W_ERROR_IS_OK(status_win2k) )
2192 free_a_printer_driver( info, 3 );
2198 /****************************************************************************
2199 Internal routine for retreiving printerdata
2200 ***************************************************************************/
2202 static WERROR get_printer_dataex( TALLOC_CTX *ctx, NT_PRINTER_INFO_LEVEL *printer,
2203 const char *key, const char *value, uint32 *type, uint8 **data,
2204 uint32 *needed, uint32 in_size )
2206 REGISTRY_VALUE *val;
2210 if ( !(val = get_printer_data( printer->info_2, key, value)) )
2211 return WERR_BADFILE;
2213 *type = regval_type( val );
2215 DEBUG(5,("get_printer_dataex: allocating %d\n", in_size));
2217 size = regval_size( val );
2219 /* copy the min(in_size, len) */
2222 data_len = (size > in_size) ? in_size : size*sizeof(uint8);
2224 /* special case for 0 length values */
2226 if ( (*data = (uint8 *)TALLOC_MEMDUP(ctx, regval_data_p(val), data_len)) == NULL )
2230 if ( (*data = (uint8 *)TALLOC_ZERO(ctx, in_size)) == NULL )
2239 DEBUG(5,("get_printer_dataex: copy done\n"));
2244 /****************************************************************************
2245 Internal routine for removing printerdata
2246 ***************************************************************************/
2248 static WERROR delete_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, const char *key, const char *value )
2250 return delete_printer_data( printer->info_2, key, value );
2253 /****************************************************************************
2254 Internal routine for storing printerdata
2255 ***************************************************************************/
2257 WERROR set_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, const char *key, const char *value,
2258 uint32 type, uint8 *data, int real_len )
2260 /* the registry objects enforce uniqueness based on value name */
2262 return add_printer_data( printer->info_2, key, value, type, data, real_len );
2265 /********************************************************************
2266 GetPrinterData on a printer server Handle.
2267 ********************************************************************/
2269 static WERROR getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint32 *type, uint8 **data, uint32 *needed, uint32 in_size)
2273 DEBUG(8,("getprinterdata_printer_server:%s\n", value));
2275 if (!StrCaseCmp(value, "W3SvcInstalled")) {
2277 if ( !(*data = TALLOC_ARRAY(ctx, uint8, sizeof(uint32) )) )
2283 if (!StrCaseCmp(value, "BeepEnabled")) {
2285 if ( !(*data = TALLOC_ARRAY(ctx, uint8, sizeof(uint32) )) )
2287 SIVAL(*data, 0, 0x00);
2292 if (!StrCaseCmp(value, "EventLog")) {
2294 if ( !(*data = TALLOC_ARRAY(ctx, uint8, sizeof(uint32) )) )
2296 /* formally was 0x1b */
2297 SIVAL(*data, 0, 0x0);
2302 if (!StrCaseCmp(value, "NetPopup")) {
2304 if ( !(*data = TALLOC_ARRAY(ctx, uint8, sizeof(uint32) )) )
2306 SIVAL(*data, 0, 0x00);
2311 if (!StrCaseCmp(value, "MajorVersion")) {
2313 if ( !(*data = TALLOC_ARRAY(ctx, uint8, sizeof(uint32) )) )
2316 /* Windows NT 4.0 seems to not allow uploading of drivers
2317 to a server that reports 0x3 as the MajorVersion.
2318 need to investigate more how Win2k gets around this .
2321 if ( RA_WINNT == get_remote_arch() )
2330 if (!StrCaseCmp(value, "MinorVersion")) {
2332 if ( !(*data = TALLOC_ARRAY(ctx, uint8, sizeof(uint32) )) )
2340 * uint32 size = 0x114
2342 * uint32 minor = [0|1]
2343 * uint32 build = [2195|2600]
2344 * extra unicode string = e.g. "Service Pack 3"
2346 if (!StrCaseCmp(value, "OSVersion")) {
2350 if ( !(*data = TALLOC_ZERO_ARRAY(ctx, uint8, (*needed > in_size) ? *needed:in_size )) )
2353 SIVAL(*data, 0, *needed); /* size */
2354 SIVAL(*data, 4, 5); /* Windows 2000 == 5.0 */
2356 SIVAL(*data, 12, 2195); /* build */
2358 /* leave extra string empty */
2364 if (!StrCaseCmp(value, "DefaultSpoolDirectory")) {
2365 const char *string="C:\\PRINTERS";
2367 *needed = 2*(strlen(string)+1);
2368 if((*data = (uint8 *)TALLOC(ctx, (*needed > in_size) ? *needed:in_size )) == NULL)
2370 memset(*data, 0, (*needed > in_size) ? *needed:in_size);
2372 /* it's done by hand ready to go on the wire */
2373 for (i=0; i<strlen(string); i++) {
2374 (*data)[2*i]=string[i];
2375 (*data)[2*i+1]='\0';
2380 if (!StrCaseCmp(value, "Architecture")) {
2381 const char *string="Windows NT x86";
2383 *needed = 2*(strlen(string)+1);
2384 if((*data = (uint8 *)TALLOC(ctx, (*needed > in_size) ? *needed:in_size )) == NULL)
2386 memset(*data, 0, (*needed > in_size) ? *needed:in_size);
2387 for (i=0; i<strlen(string); i++) {
2388 (*data)[2*i]=string[i];
2389 (*data)[2*i+1]='\0';
2394 if (!StrCaseCmp(value, "DsPresent")) {
2396 if ( !(*data = TALLOC_ARRAY(ctx, uint8, sizeof(uint32) )) )
2399 /* only show the publish check box if we are a
2400 memeber of a AD domain */
2402 if ( lp_security() == SEC_ADS )
2403 SIVAL(*data, 0, 0x01);
2405 SIVAL(*data, 0, 0x00);
2411 if (!StrCaseCmp(value, "DNSMachineName")) {
2414 if (!get_mydnsfullname(hostname))
2415 return WERR_BADFILE;
2417 *needed = 2*(strlen(hostname)+1);
2418 if((*data = (uint8 *)TALLOC(ctx, (*needed > in_size) ? *needed:in_size )) == NULL)
2420 memset(*data, 0, (*needed > in_size) ? *needed:in_size);
2421 for (i=0; i<strlen(hostname); i++) {
2422 (*data)[2*i]=hostname[i];
2423 (*data)[2*i+1]='\0';
2429 return WERR_BADFILE;
2432 /********************************************************************
2433 * spoolss_getprinterdata
2434 ********************************************************************/
2436 WERROR _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPOOL_R_GETPRINTERDATA *r_u)
2438 POLICY_HND *handle = &q_u->handle;
2439 UNISTR2 *valuename = &q_u->valuename;
2440 uint32 in_size = q_u->size;
2441 uint32 *type = &r_u->type;
2442 uint32 *out_size = &r_u->size;
2443 uint8 **data = &r_u->data;
2444 uint32 *needed = &r_u->needed;
2447 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
2448 NT_PRINTER_INFO_LEVEL *printer = NULL;
2452 * Reminder: when it's a string, the length is in BYTES
2453 * even if UNICODE is negociated.
2458 *out_size = in_size;
2460 /* in case of problem, return some default values */
2465 DEBUG(4,("_spoolss_getprinterdata\n"));
2468 DEBUG(2,("_spoolss_getprinterdata: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
2469 status = WERR_BADFID;
2473 unistr2_to_ascii(value, valuename, sizeof(value)-1);
2475 if ( Printer->printer_type == SPLHND_SERVER )
2476 status = getprinterdata_printer_server( p->mem_ctx, value, type, data, needed, *out_size );
2479 if ( !get_printer_snum(p,handle, &snum, NULL) ) {
2480 status = WERR_BADFID;
2484 status = get_a_printer(Printer, &printer, 2, lp_servicename(snum));
2485 if ( !W_ERROR_IS_OK(status) )
2488 /* XP sends this and wants to change id value from the PRINTER_INFO_0 */
2490 if ( strequal(value, "ChangeId") ) {
2492 *needed = sizeof(uint32);
2493 if ( (*data = (uint8*)TALLOC(p->mem_ctx, sizeof(uint32))) == NULL) {
2494 status = WERR_NOMEM;
2497 SIVAL( *data, 0, printer->info_2->changeid );
2501 status = get_printer_dataex( p->mem_ctx, printer, SPOOL_PRINTERDATA_KEY, value, type, data, needed, *out_size );
2504 if (*needed > *out_size)
2505 status = WERR_MORE_DATA;
2508 if ( !W_ERROR_IS_OK(status) )
2510 DEBUG(5, ("error %d: allocating %d\n", W_ERROR_V(status),*out_size));
2512 /* reply this param doesn't exist */
2515 if((*data=(uint8 *)TALLOC_ZERO_ARRAY(p->mem_ctx, uint8, *out_size)) == NULL) {
2517 free_a_printer( &printer, 2 );
2525 /* cleanup & exit */
2528 free_a_printer( &printer, 2 );
2533 /*********************************************************
2534 Connect to the client machine.
2535 **********************************************************/
2537 static BOOL spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
2538 struct in_addr *client_ip, const char *remote_machine)
2541 struct cli_state *the_cli;
2542 struct in_addr rm_addr;
2544 if ( is_zero_ip(*client_ip) ) {
2545 if ( !resolve_name( remote_machine, &rm_addr, 0x20) ) {
2546 DEBUG(2,("spoolss_connect_to_client: Can't resolve address for %s\n", remote_machine));
2550 if ( ismyip( rm_addr )) {
2551 DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n", remote_machine));
2555 rm_addr.s_addr = client_ip->s_addr;
2556 DEBUG(5,("spoolss_connect_to_client: Using address %s (no name resolution necessary)\n",
2557 inet_ntoa(*client_ip) ));
2560 /* setup the connection */
2562 ret = cli_full_connection( &the_cli, global_myname(), remote_machine,
2563 &rm_addr, 0, "IPC$", "IPC",
2567 0, lp_client_signing(), NULL );
2569 if ( !NT_STATUS_IS_OK( ret ) ) {
2570 DEBUG(2,("spoolss_connect_to_client: connection to [%s] failed!\n",
2575 if ( the_cli->protocol != PROTOCOL_NT1 ) {
2576 DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
2577 cli_shutdown(the_cli);
2582 * Ok - we have an anonymous connection to the IPC$ share.
2583 * Now start the NT Domain stuff :-).
2586 if ( !(*pp_pipe = cli_rpc_pipe_open_noauth(the_cli, PI_SPOOLSS, &ret)) ) {
2587 DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
2588 remote_machine, nt_errstr(ret)));
2589 cli_shutdown(the_cli);
2593 /* make sure to save the cli_state pointer. Keep its own talloc_ctx */
2595 (*pp_pipe)->cli = the_cli;
2600 /***************************************************************************
2601 Connect to the client.
2602 ****************************************************************************/
2604 static BOOL srv_spoolss_replyopenprinter(int snum, const char *printer,
2605 uint32 localprinter, uint32 type,
2606 POLICY_HND *handle, struct in_addr *client_ip)
2611 * If it's the first connection, contact the client
2612 * and connect to the IPC$ share anonymously
2614 if (smb_connections==0) {
2615 fstring unix_printer;
2617 fstrcpy(unix_printer, printer+2); /* the +2 is to strip the leading 2 backslashs */
2619 if ( !spoolss_connect_to_client( ¬ify_cli_pipe, client_ip, unix_printer ))
2622 messaging_register(smbd_messaging_context(), NULL,
2623 MSG_PRINTER_NOTIFY2,
2624 receive_notify2_message_list);
2625 /* Tell the connections db we're now interested in printer
2626 * notify messages. */
2627 register_message_flags( True, FLAG_MSG_PRINT_NOTIFY );
2631 * Tell the specific printing tdb we want messages for this printer
2632 * by registering our PID.
2635 if (!print_notify_register_pid(snum))
2636 DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", printer ));
2640 result = rpccli_spoolss_reply_open_printer(notify_cli_pipe, notify_cli_pipe->cli->mem_ctx, printer, localprinter,
2643 if (!W_ERROR_IS_OK(result))
2644 DEBUG(5,("srv_spoolss_reply_open_printer: Client RPC returned [%s]\n",
2645 dos_errstr(result)));
2647 return (W_ERROR_IS_OK(result));
2650 /********************************************************************
2652 * ReplyFindFirstPrinterChangeNotifyEx
2654 * before replying OK: status=0 a rpc call is made to the workstation
2655 * asking ReplyOpenPrinter
2657 * in fact ReplyOpenPrinter is the changenotify equivalent on the spoolss pipe
2658 * called from api_spoolss_rffpcnex
2659 ********************************************************************/
2661 WERROR _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNEX *r_u)
2663 POLICY_HND *handle = &q_u->handle;
2664 uint32 flags = q_u->flags;
2665 uint32 options = q_u->options;
2666 UNISTR2 *localmachine = &q_u->localmachine;
2667 uint32 printerlocal = q_u->printerlocal;
2669 SPOOL_NOTIFY_OPTION *option = q_u->option;
2670 struct in_addr client_ip;
2672 /* store the notify value in the printer struct */
2674 Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
2677 DEBUG(2,("_spoolss_rffpcnex: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
2681 Printer->notify.flags=flags;
2682 Printer->notify.options=options;
2683 Printer->notify.printerlocal=printerlocal;
2685 if (Printer->notify.option)
2686 free_spool_notify_option(&Printer->notify.option);
2688 Printer->notify.option=dup_spool_notify_option(option);
2690 unistr2_to_ascii(Printer->notify.localmachine, localmachine,
2691 sizeof(Printer->notify.localmachine)-1);
2693 /* Connect to the client machine and send a ReplyOpenPrinter */
2695 if ( Printer->printer_type == SPLHND_SERVER)
2697 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
2698 !get_printer_snum(p, handle, &snum, NULL) )
2701 client_ip.s_addr = inet_addr(p->conn->client_address);
2703 if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
2704 Printer->notify.printerlocal, 1,
2705 &Printer->notify.client_hnd, &client_ip))
2706 return WERR_SERVER_UNAVAILABLE;
2708 Printer->notify.client_connected=True;
2713 /*******************************************************************
2714 * fill a notify_info_data with the servername
2715 ********************************************************************/
2717 void spoolss_notify_server_name(int snum,
2718 SPOOL_NOTIFY_INFO_DATA *data,
2719 print_queue_struct *queue,
2720 NT_PRINTER_INFO_LEVEL *printer,
2721 TALLOC_CTX *mem_ctx)
2726 len = rpcstr_push(temp, printer->info_2->servername, sizeof(temp)-2, STR_TERMINATE);
2728 data->notify_data.data.length = len;
2730 data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
2731 if (!data->notify_data.data.string) {
2732 data->notify_data.data.length = 0;
2736 memcpy(data->notify_data.data.string, temp, len);
2738 data->notify_data.data.string = NULL;
2742 /*******************************************************************
2743 * fill a notify_info_data with the printername (not including the servername).
2744 ********************************************************************/
2746 void spoolss_notify_printer_name(int snum,
2747 SPOOL_NOTIFY_INFO_DATA *data,
2748 print_queue_struct *queue,
2749 NT_PRINTER_INFO_LEVEL *printer,
2750 TALLOC_CTX *mem_ctx)
2755 /* the notify name should not contain the \\server\ part */
2756 char *p = strrchr(printer->info_2->printername, '\\');
2759 p = printer->info_2->printername;
2764 len = rpcstr_push(temp, p, sizeof(temp)-2, STR_TERMINATE);
2766 data->notify_data.data.length = len;
2768 data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
2769 if (!data->notify_data.data.string) {
2770 data->notify_data.data.length = 0;
2773 memcpy(data->notify_data.data.string, temp, len);
2775 data->notify_data.data.string = NULL;
2779 /*******************************************************************
2780 * fill a notify_info_data with the servicename
2781 ********************************************************************/
2783 void spoolss_notify_share_name(int snum,
2784 SPOOL_NOTIFY_INFO_DATA *data,
2785 print_queue_struct *queue,
2786 NT_PRINTER_INFO_LEVEL *printer,
2787 TALLOC_CTX *mem_ctx)
2792 len = rpcstr_push(temp, lp_servicename(snum), sizeof(temp)-2, STR_TERMINATE);
2794 data->notify_data.data.length = len;
2796 data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
2797 if (!data->notify_data.data.string) {
2798 data->notify_data.data.length = 0;
2801 memcpy(data->notify_data.data.string, temp, len);
2803 data->notify_data.data.string = NULL;
2808 /*******************************************************************
2809 * fill a notify_info_data with the port name
2810 ********************************************************************/
2812 void spoolss_notify_port_name(int snum,
2813 SPOOL_NOTIFY_INFO_DATA *data,
2814 print_queue_struct *queue,
2815 NT_PRINTER_INFO_LEVEL *printer,
2816 TALLOC_CTX *mem_ctx)
2821 /* even if it's strange, that's consistant in all the code */
2823 len = rpcstr_push(temp, printer->info_2->portname, sizeof(temp)-2, STR_TERMINATE);
2825 data->notify_data.data.length = len;
2827 data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
2829 if (!data->notify_data.data.string) {
2830 data->notify_data.data.length = 0;
2834 memcpy(data->notify_data.data.string, temp, len);
2836 data->notify_data.data.string = NULL;
2840 /*******************************************************************
2841 * fill a notify_info_data with the printername
2842 * but it doesn't exist, have to see what to do
2843 ********************************************************************/
2845 void spoolss_notify_driver_name(int snum,
2846 SPOOL_NOTIFY_INFO_DATA *data,
2847 print_queue_struct *queue,
2848 NT_PRINTER_INFO_LEVEL *printer,
2849 TALLOC_CTX *mem_ctx)
2854 len = rpcstr_push(temp, printer->info_2->drivername, sizeof(temp)-2, STR_TERMINATE);
2856 data->notify_data.data.length = len;
2858 data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
2860 if (!data->notify_data.data.string) {
2861 data->notify_data.data.length = 0;
2865 memcpy(data->notify_data.data.string, temp, len);
2867 data->notify_data.data.string = NULL;
2871 /*******************************************************************
2872 * fill a notify_info_data with the comment
2873 ********************************************************************/
2875 void spoolss_notify_comment(int snum,
2876 SPOOL_NOTIFY_INFO_DATA *data,
2877 print_queue_struct *queue,
2878 NT_PRINTER_INFO_LEVEL *printer,
2879 TALLOC_CTX *mem_ctx)
2884 if (*printer->info_2->comment == '\0')
2885 len = rpcstr_push(temp, lp_comment(snum), sizeof(temp)-2, STR_TERMINATE);
2887 len = rpcstr_push(temp, printer->info_2->comment, sizeof(temp)-2, STR_TERMINATE);
2889 data->notify_data.data.length = len;
2891 data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
2893 if (!data->notify_data.data.string) {
2894 data->notify_data.data.length = 0;
2898 memcpy(data->notify_data.data.string, temp, len);
2900 data->notify_data.data.string = NULL;
2904 /*******************************************************************
2905 * fill a notify_info_data with the comment
2906 * location = "Room 1, floor 2, building 3"
2907 ********************************************************************/
2909 void spoolss_notify_location(int snum,
2910 SPOOL_NOTIFY_INFO_DATA *data,
2911 print_queue_struct *queue,
2912 NT_PRINTER_INFO_LEVEL *printer,
2913 TALLOC_CTX *mem_ctx)
2918 len = rpcstr_push(temp, printer->info_2->location,sizeof(temp)-2, STR_TERMINATE);
2920 data->notify_data.data.length = len;
2922 data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
2924 if (!data->notify_data.data.string) {
2925 data->notify_data.data.length = 0;
2929 memcpy(data->notify_data.data.string, temp, len);
2931 data->notify_data.data.string = NULL;
2935 /*******************************************************************
2936 * fill a notify_info_data with the device mode
2937 * jfm:xxxx don't to it for know but that's a real problem !!!
2938 ********************************************************************/
2940 static void spoolss_notify_devmode(int snum,
2941 SPOOL_NOTIFY_INFO_DATA *data,
2942 print_queue_struct *queue,
2943 NT_PRINTER_INFO_LEVEL *printer,
2944 TALLOC_CTX *mem_ctx)
2946 /* for a dummy implementation we have to zero the fields */
2947 data->notify_data.data.length = 0;
2948 data->notify_data.data.string = NULL;
2951 /*******************************************************************
2952 * fill a notify_info_data with the separator file name
2953 ********************************************************************/
2955 void spoolss_notify_sepfile(int snum,
2956 SPOOL_NOTIFY_INFO_DATA *data,
2957 print_queue_struct *queue,
2958 NT_PRINTER_INFO_LEVEL *printer,
2959 TALLOC_CTX *mem_ctx)
2964 len = rpcstr_push(temp, printer->info_2->sepfile, sizeof(temp)-2, STR_TERMINATE);
2966 data->notify_data.data.length = len;
2968 data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
2970 if (!data->notify_data.data.string) {
2971 data->notify_data.data.length = 0;
2975 memcpy(data->notify_data.data.string, temp, len);
2977 data->notify_data.data.string = NULL;
2981 /*******************************************************************
2982 * fill a notify_info_data with the print processor
2983 * jfm:xxxx return always winprint to indicate we don't do anything to it
2984 ********************************************************************/
2986 void spoolss_notify_print_processor(int snum,
2987 SPOOL_NOTIFY_INFO_DATA *data,
2988 print_queue_struct *queue,
2989 NT_PRINTER_INFO_LEVEL *printer,
2990 TALLOC_CTX *mem_ctx)
2995 len = rpcstr_push(temp, printer->info_2->printprocessor, sizeof(temp)-2, STR_TERMINATE);
2997 data->notify_data.data.length = len;
2999 data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
3001 if (!data->notify_data.data.string) {
3002 data->notify_data.data.length = 0;
3006 memcpy(data->notify_data.data.string, temp, len);
3008 data->notify_data.data.string = NULL;
3012 /*******************************************************************
3013 * fill a notify_info_data with the print processor options
3014 * jfm:xxxx send an empty string
3015 ********************************************************************/
3017 void spoolss_notify_parameters(int snum,
3018 SPOOL_NOTIFY_INFO_DATA *data,
3019 print_queue_struct *queue,
3020 NT_PRINTER_INFO_LEVEL *printer,
3021 TALLOC_CTX *mem_ctx)
3026 len = rpcstr_push(temp, printer->info_2->parameters, sizeof(temp)-2, STR_TERMINATE);
3028 data->notify_data.data.length = len;
3030 data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
3032 if (!data->notify_data.data.string) {
3033 data->notify_data.data.length = 0;
3037 memcpy(data->notify_data.data.string, temp, len);
3039 data->notify_data.data.string = NULL;
3043 /*******************************************************************
3044 * fill a notify_info_data with the data type
3045 * jfm:xxxx always send RAW as data type
3046 ********************************************************************/
3048 void spoolss_notify_datatype(int snum,
3049 SPOOL_NOTIFY_INFO_DATA *data,
3050 print_queue_struct *queue,
3051 NT_PRINTER_INFO_LEVEL *printer,
3052 TALLOC_CTX *mem_ctx)
3057 len = rpcstr_push(temp, printer->info_2->datatype, sizeof(pstring)-2, STR_TERMINATE);
3059 data->notify_data.data.length = len;
3061 data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
3063 if (!data->notify_data.data.string) {
3064 data->notify_data.data.length = 0;
3068 memcpy(data->notify_data.data.string, temp, len);
3070 data->notify_data.data.string = NULL;
3074 /*******************************************************************
3075 * fill a notify_info_data with the security descriptor
3076 * jfm:xxxx send an null pointer to say no security desc
3077 * have to implement security before !
3078 ********************************************************************/
3080 static void spoolss_notify_security_desc(int snum,
3081 SPOOL_NOTIFY_INFO_DATA *data,
3082 print_queue_struct *queue,
3083 NT_PRINTER_INFO_LEVEL *printer,
3084 TALLOC_CTX *mem_ctx)
3086 data->notify_data.sd.size = printer->info_2->secdesc_buf->sd_size;
3087 data->notify_data.sd.desc = dup_sec_desc( mem_ctx, printer->info_2->secdesc_buf->sd ) ;
3090 /*******************************************************************
3091 * fill a notify_info_data with the attributes
3092 * jfm:xxxx a samba printer is always shared
3093 ********************************************************************/
3095 void spoolss_notify_attributes(int snum,
3096 SPOOL_NOTIFY_INFO_DATA *data,
3097 print_queue_struct *queue,
3098 NT_PRINTER_INFO_LEVEL *printer,
3099 TALLOC_CTX *mem_ctx)
3101 data->notify_data.value[0] = printer->info_2->attributes;
3102 data->notify_data.value[1] = 0;
3105 /*******************************************************************
3106 * fill a notify_info_data with the priority
3107 ********************************************************************/
3109 static void spoolss_notify_priority(int snum,
3110 SPOOL_NOTIFY_INFO_DATA *data,
3111 print_queue_struct *queue,
3112 NT_PRINTER_INFO_LEVEL *printer,
3113 TALLOC_CTX *mem_ctx)
3115 data->notify_data.value[0] = printer->info_2->priority;
3116 data->notify_data.value[1] = 0;
3119 /*******************************************************************
3120 * fill a notify_info_data with the default priority
3121 ********************************************************************/
3123 static void spoolss_notify_default_priority(int snum,
3124 SPOOL_NOTIFY_INFO_DATA *data,
3125 print_queue_struct *queue,
3126 NT_PRINTER_INFO_LEVEL *printer,
3127 TALLOC_CTX *mem_ctx)
3129 data->notify_data.value[0] = printer->info_2->default_priority;
3130 data->notify_data.value[1] = 0;
3133 /*******************************************************************
3134 * fill a notify_info_data with the start time
3135 ********************************************************************/
3137 static void spoolss_notify_start_time(int snum,
3138 SPOOL_NOTIFY_INFO_DATA *data,
3139 print_queue_struct *queue,
3140 NT_PRINTER_INFO_LEVEL *printer,
3141 TALLOC_CTX *mem_ctx)
3143 data->notify_data.value[0] = printer->info_2->starttime;
3144 data->notify_data.value[1] = 0;
3147 /*******************************************************************
3148 * fill a notify_info_data with the until time
3149 ********************************************************************/
3151 static void spoolss_notify_until_time(int snum,
3152 SPOOL_NOTIFY_INFO_DATA *data,
3153 print_queue_struct *queue,
3154 NT_PRINTER_INFO_LEVEL *printer,
3155 TALLOC_CTX *mem_ctx)
3157 data->notify_data.value[0] = printer->info_2->untiltime;
3158 data->notify_data.value[1] = 0;
3161 /*******************************************************************
3162 * fill a notify_info_data with the status
3163 ********************************************************************/
3165 static void spoolss_notify_status(int snum,
3166 SPOOL_NOTIFY_INFO_DATA *data,
3167 print_queue_struct *queue,
3168 NT_PRINTER_INFO_LEVEL *printer,
3169 TALLOC_CTX *mem_ctx)
3171 print_status_struct status;
3173 print_queue_length(snum, &status);
3174 data->notify_data.value[0]=(uint32) status.status;
3175 data->notify_data.value[1] = 0;
3178 /*******************************************************************
3179 * fill a notify_info_data with the number of jobs queued
3180 ********************************************************************/
3182 void spoolss_notify_cjobs(int snum,
3183 SPOOL_NOTIFY_INFO_DATA *data,
3184 print_queue_struct *queue,
3185 NT_PRINTER_INFO_LEVEL *printer,
3186 TALLOC_CTX *mem_ctx)
3188 data->notify_data.value[0] = print_queue_length(snum, NULL);
3189 data->notify_data.value[1] = 0;
3192 /*******************************************************************
3193 * fill a notify_info_data with the average ppm
3194 ********************************************************************/
3196 static void spoolss_notify_average_ppm(int snum,
3197 SPOOL_NOTIFY_INFO_DATA *data,
3198 print_queue_struct *queue,
3199 NT_PRINTER_INFO_LEVEL *printer,
3200 TALLOC_CTX *mem_ctx)
3202 /* always respond 8 pages per minutes */
3203 /* a little hard ! */
3204 data->notify_data.value[0] = printer->info_2->averageppm;
3205 data->notify_data.value[1] = 0;
3208 /*******************************************************************
3209 * fill a notify_info_data with username
3210 ********************************************************************/
3212 static void spoolss_notify_username(int snum,
3213 SPOOL_NOTIFY_INFO_DATA *data,
3214 print_queue_struct *queue,
3215 NT_PRINTER_INFO_LEVEL *printer,
3216 TALLOC_CTX *mem_ctx)
3221 len = rpcstr_push(temp, queue->fs_user, sizeof(temp)-2, STR_TERMINATE);
3223 data->notify_data.data.length = len;
3225 data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
3227 if (!data->notify_data.data.string) {
3228 data->notify_data.data.length = 0;
3232 memcpy(data->notify_data.data.string, temp, len);
3234 data->notify_data.data.string = NULL;
3238 /*******************************************************************
3239 * fill a notify_info_data with job status
3240 ********************************************************************/
3242 static void spoolss_notify_job_status(int snum,
3243 SPOOL_NOTIFY_INFO_DATA *data,
3244 print_queue_struct *queue,
3245 NT_PRINTER_INFO_LEVEL *printer,
3246 TALLOC_CTX *mem_ctx)
3248 data->notify_data.value[0]=nt_printj_status(queue->status);
3249 data->notify_data.value[1] = 0;
3252 /*******************************************************************
3253 * fill a notify_info_data with job name
3254 ********************************************************************/
3256 static void spoolss_notify_job_name(int snum,
3257 SPOOL_NOTIFY_INFO_DATA *data,
3258 print_queue_struct *queue,
3259 NT_PRINTER_INFO_LEVEL *printer,
3260 TALLOC_CTX *mem_ctx)
3265 len = rpcstr_push(temp, queue->fs_file, sizeof(temp)-2, STR_TERMINATE);
3267 data->notify_data.data.length = len;
3269 data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
3271 if (!data->notify_data.data.string) {
3272 data->notify_data.data.length = 0;
3276 memcpy(data->notify_data.data.string, temp, len);
3278 data->notify_data.data.string = NULL;
3282 /*******************************************************************
3283 * fill a notify_info_data with job status
3284 ********************************************************************/
3286 static void spoolss_notify_job_status_string(int snum,
3287 SPOOL_NOTIFY_INFO_DATA *data,
3288 print_queue_struct *queue,
3289 NT_PRINTER_INFO_LEVEL *printer,
3290 TALLOC_CTX *mem_ctx)
3293 * Now we're returning job status codes we just return a "" here. JRA.
3300 #if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
3303 switch (queue->status) {
3308 p = ""; /* NT provides the paused string */
3317 #endif /* NO LONGER NEEDED. */
3319 len = rpcstr_push(temp, p, sizeof(temp) - 2, STR_TERMINATE);
3321 data->notify_data.data.length = len;
3323 data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
3325 if (!data->notify_data.data.string) {
3326 data->notify_data.data.length = 0;
3330 memcpy(data->notify_data.data.string, temp, len);
3332 data->notify_data.data.string = NULL;
3336 /*******************************************************************
3337 * fill a notify_info_data with job time
3338 ********************************************************************/
3340 static void spoolss_notify_job_time(int snum,
3341 SPOOL_NOTIFY_INFO_DATA *data,
3342 print_queue_struct *queue,
3343 NT_PRINTER_INFO_LEVEL *printer,
3344 TALLOC_CTX *mem_ctx)
3346 data->notify_data.value[0]=0x0;
3347 data->notify_data.value[1]=0;
3350 /*******************************************************************
3351 * fill a notify_info_data with job size
3352 ********************************************************************/
3354 static void spoolss_notify_job_size(int snum,
3355 SPOOL_NOTIFY_INFO_DATA *data,
3356 print_queue_struct *queue,
3357 NT_PRINTER_INFO_LEVEL *printer,
3358 TALLOC_CTX *mem_ctx)
3360 data->notify_data.value[0]=queue->size;
3361 data->notify_data.value[1]=0;
3364 /*******************************************************************
3365 * fill a notify_info_data with page info
3366 ********************************************************************/
3367 static void spoolss_notify_total_pages(int snum,
3368 SPOOL_NOTIFY_INFO_DATA *data,
3369 print_queue_struct *queue,
3370 NT_PRINTER_INFO_LEVEL *printer,
3371 TALLOC_CTX *mem_ctx)
3373 data->notify_data.value[0]=queue->page_count;
3374 data->notify_data.value[1]=0;
3377 /*******************************************************************
3378 * fill a notify_info_data with pages printed info.
3379 ********************************************************************/
3380 static void spoolss_notify_pages_printed(int snum,
3381 SPOOL_NOTIFY_INFO_DATA *data,
3382 print_queue_struct *queue,
3383 NT_PRINTER_INFO_LEVEL *printer,
3384 TALLOC_CTX *mem_ctx)
3386 data->notify_data.value[0]=0; /* Add code when back-end tracks this */
3387 data->notify_data.value[1]=0;
3390 /*******************************************************************
3391 Fill a notify_info_data with job position.
3392 ********************************************************************/
3394 static void spoolss_notify_job_position(int snum,
3395 SPOOL_NOTIFY_INFO_DATA *data,
3396 print_queue_struct *queue,
3397 NT_PRINTER_INFO_LEVEL *printer,
3398 TALLOC_CTX *mem_ctx)
3400 data->notify_data.value[0]=queue->job;
3401 data->notify_data.value[1]=0;
3404 /*******************************************************************
3405 Fill a notify_info_data with submitted time.
3406 ********************************************************************/
3408 static void spoolss_notify_submitted_time(int snum,
3409 SPOOL_NOTIFY_INFO_DATA *data,
3410 print_queue_struct *queue,
3411 NT_PRINTER_INFO_LEVEL *printer,
3412 TALLOC_CTX *mem_ctx)
3419 t=gmtime(&queue->time);
3421 len = sizeof(SYSTEMTIME);
3423 data->notify_data.data.length = len;
3424 data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
3426 if (!data->notify_data.data.string) {
3427 data->notify_data.data.length = 0;
3431 make_systemtime(&st, t);
3434 * Systemtime must be linearized as a set of UINT16's.
3435 * Fix from Benjamin (Bj) Kuit bj@it.uts.edu.au
3438 p = (char *)data->notify_data.data.string;
3439 SSVAL(p, 0, st.year);
3440 SSVAL(p, 2, st.month);
3441 SSVAL(p, 4, st.dayofweek);
3442 SSVAL(p, 6, st.day);
3443 SSVAL(p, 8, st.hour);
3444 SSVAL(p, 10, st.minute);
3445 SSVAL(p, 12, st.second);
3446 SSVAL(p, 14, st.milliseconds);
3449 struct s_notify_info_data_table
3455 void (*fn) (int snum, SPOOL_NOTIFY_INFO_DATA *data,
3456 print_queue_struct *queue,
3457 NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx);
3460 /* A table describing the various print notification constants and
3461 whether the notification data is a pointer to a variable sized
3462 buffer, a one value uint32 or a two value uint32. */
3464 static const struct s_notify_info_data_table notify_info_data_table[] =
3466 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SERVER_NAME, "PRINTER_NOTIFY_SERVER_NAME", NOTIFY_STRING, spoolss_notify_server_name },
3467 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRINTER_NAME, "PRINTER_NOTIFY_PRINTER_NAME", NOTIFY_STRING, spoolss_notify_printer_name },
3468 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SHARE_NAME, "PRINTER_NOTIFY_SHARE_NAME", NOTIFY_STRING, spoolss_notify_share_name },
3469 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PORT_NAME, "PRINTER_NOTIFY_PORT_NAME", NOTIFY_STRING, spoolss_notify_port_name },
3470 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DRIVER_NAME, "PRINTER_NOTIFY_DRIVER_NAME", NOTIFY_STRING, spoolss_notify_driver_name },
3471 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_COMMENT, "PRINTER_NOTIFY_COMMENT", NOTIFY_STRING, spoolss_notify_comment },
3472 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_LOCATION, "PRINTER_NOTIFY_LOCATION", NOTIFY_STRING, spoolss_notify_location },
3473 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DEVMODE, "PRINTER_NOTIFY_DEVMODE", NOTIFY_POINTER, spoolss_notify_devmode },
3474 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SEPFILE, "PRINTER_NOTIFY_SEPFILE", NOTIFY_STRING, spoolss_notify_sepfile },
3475 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRINT_PROCESSOR, "PRINTER_NOTIFY_PRINT_PROCESSOR", NOTIFY_STRING, spoolss_notify_print_processor },
3476 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PARAMETERS, "PRINTER_NOTIFY_PARAMETERS", NOTIFY_STRING, spoolss_notify_parameters },
3477 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DATATYPE, "PRINTER_NOTIFY_DATATYPE", NOTIFY_STRING, spoolss_notify_datatype },
3478 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SECURITY_DESCRIPTOR, "PRINTER_NOTIFY_SECURITY_DESCRIPTOR", NOTIFY_SECDESC, spoolss_notify_security_desc },
3479 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_ATTRIBUTES, "PRINTER_NOTIFY_ATTRIBUTES", NOTIFY_ONE_VALUE, spoolss_notify_attributes },
3480 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRIORITY, "PRINTER_NOTIFY_PRIORITY", NOTIFY_ONE_VALUE, spoolss_notify_priority },
3481 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_DEFAULT_PRIORITY, "PRINTER_NOTIFY_DEFAULT_PRIORITY", NOTIFY_ONE_VALUE, spoolss_notify_default_priority },
3482 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_START_TIME, "PRINTER_NOTIFY_START_TIME", NOTIFY_ONE_VALUE, spoolss_notify_start_time },
3483 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_UNTIL_TIME, "PRINTER_NOTIFY_UNTIL_TIME", NOTIFY_ONE_VALUE, spoolss_notify_until_time },
3484 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_STATUS, "PRINTER_NOTIFY_STATUS", NOTIFY_ONE_VALUE, spoolss_notify_status },
3485 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_STATUS_STRING, "PRINTER_NOTIFY_STATUS_STRING", NOTIFY_POINTER, NULL },
3486 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_CJOBS, "PRINTER_NOTIFY_CJOBS", NOTIFY_ONE_VALUE, spoolss_notify_cjobs },
3487 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_AVERAGE_PPM, "PRINTER_NOTIFY_AVERAGE_PPM", NOTIFY_ONE_VALUE, spoolss_notify_average_ppm },
3488 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_TOTAL_PAGES, "PRINTER_NOTIFY_TOTAL_PAGES", NOTIFY_POINTER, NULL },
3489 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PAGES_PRINTED, "PRINTER_NOTIFY_PAGES_PRINTED", NOTIFY_POINTER, NULL },
3490 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_TOTAL_BYTES, "PRINTER_NOTIFY_TOTAL_BYTES", NOTIFY_POINTER, NULL },
3491 { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_BYTES_PRINTED, "PRINTER_NOTIFY_BYTES_PRINTED", NOTIFY_POINTER, NULL },
3492 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRINTER_NAME, "JOB_NOTIFY_PRINTER_NAME", NOTIFY_STRING, spoolss_notify_printer_name },
3493 { JOB_NOTIFY_TYPE, JOB_NOTIFY_MACHINE_NAME, "JOB_NOTIFY_MACHINE_NAME", NOTIFY_STRING, spoolss_notify_server_name },
3494 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PORT_NAME, "JOB_NOTIFY_PORT_NAME", NOTIFY_STRING, spoolss_notify_port_name },
3495 { JOB_NOTIFY_TYPE, JOB_NOTIFY_USER_NAME, "JOB_NOTIFY_USER_NAME", NOTIFY_STRING, spoolss_notify_username },
3496 { JOB_NOTIFY_TYPE, JOB_NOTIFY_NOTIFY_NAME, "JOB_NOTIFY_NOTIFY_NAME", NOTIFY_STRING, spoolss_notify_username },
3497 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DATATYPE, "JOB_NOTIFY_DATATYPE", NOTIFY_STRING, spoolss_notify_datatype },
3498 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRINT_PROCESSOR, "JOB_NOTIFY_PRINT_PROCESSOR", NOTIFY_STRING, spoolss_notify_print_processor },
3499 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PARAMETERS, "JOB_NOTIFY_PARAMETERS", NOTIFY_STRING, spoolss_notify_parameters },
3500 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DRIVER_NAME, "JOB_NOTIFY_DRIVER_NAME", NOTIFY_STRING, spoolss_notify_driver_name },
3501 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DEVMODE, "JOB_NOTIFY_DEVMODE", NOTIFY_POINTER, spoolss_notify_devmode },
3502 { JOB_NOTIFY_TYPE, JOB_NOTIFY_STATUS, "JOB_NOTIFY_STATUS", NOTIFY_ONE_VALUE, spoolss_notify_job_status },
3503 { JOB_NOTIFY_TYPE, JOB_NOTIFY_STATUS_STRING, "JOB_NOTIFY_STATUS_STRING", NOTIFY_STRING, spoolss_notify_job_status_string },
3504 { JOB_NOTIFY_TYPE, JOB_NOTIFY_SECURITY_DESCRIPTOR, "JOB_NOTIFY_SECURITY_DESCRIPTOR", NOTIFY_POINTER, NULL },
3505 { JOB_NOTIFY_TYPE, JOB_NOTIFY_DOCUMENT, "JOB_NOTIFY_DOCUMENT", NOTIFY_STRING, spoolss_notify_job_name },
3506 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRIORITY, "JOB_NOTIFY_PRIORITY", NOTIFY_ONE_VALUE, spoolss_notify_priority },
3507 { JOB_NOTIFY_TYPE, JOB_NOTIFY_POSITION, "JOB_NOTIFY_POSITION", NOTIFY_ONE_VALUE, spoolss_notify_job_position },
3508 { JOB_NOTIFY_TYPE, JOB_NOTIFY_SUBMITTED, "JOB_NOTIFY_SUBMITTED", NOTIFY_POINTER, spoolss_notify_submitted_time },
3509 { JOB_NOTIFY_TYPE, JOB_NOTIFY_START_TIME, "JOB_NOTIFY_START_TIME", NOTIFY_ONE_VALUE, spoolss_notify_start_time },
3510 { JOB_NOTIFY_TYPE, JOB_NOTIFY_UNTIL_TIME, "JOB_NOTIFY_UNTIL_TIME", NOTIFY_ONE_VALUE, spoolss_notify_until_time },
3511 { JOB_NOTIFY_TYPE, JOB_NOTIFY_TIME, "JOB_NOTIFY_TIME", NOTIFY_ONE_VALUE, spoolss_notify_job_time },
3512 { JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_PAGES, "JOB_NOTIFY_TOTAL_PAGES", NOTIFY_ONE_VALUE, spoolss_notify_total_pages },
3513 { JOB_NOTIFY_TYPE, JOB_NOTIFY_PAGES_PRINTED, "JOB_NOTIFY_PAGES_PRINTED", NOTIFY_ONE_VALUE, spoolss_notify_pages_printed },
3514 { JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_BYTES, "JOB_NOTIFY_TOTAL_BYTES", NOTIFY_ONE_VALUE, spoolss_notify_job_size },
3515 { PRINT_TABLE_END, 0x0, NULL, 0x0, NULL },
3518 /*******************************************************************
3519 Return the size of info_data structure.
3520 ********************************************************************/
3522 static uint32 size_of_notify_info_data(uint16 type, uint16 field)
3526 for (i = 0; i < (sizeof(notify_info_data_table)/sizeof(struct s_notify_info_data_table)); i++) {
3527 if ( (notify_info_data_table[i].type == type)
3528 && (notify_info_data_table[i].field == field) ) {
3529 switch(notify_info_data_table[i].size) {
3530 case NOTIFY_ONE_VALUE:
3531 case NOTIFY_TWO_VALUE:
3536 /* The only pointer notify data I have seen on
3537 the wire is the submitted time and this has
3538 the notify size set to 4. -tpot */
3540 case NOTIFY_POINTER:
3543 case NOTIFY_SECDESC:
3549 DEBUG(5, ("invalid notify data type %d/%d\n", type, field));
3554 /*******************************************************************
3555 Return the type of notify_info_data.
3556 ********************************************************************/
3558 static uint32 type_of_notify_info_data(uint16 type, uint16 field)
3562 for (i = 0; i < (sizeof(notify_info_data_table)/sizeof(struct s_notify_info_data_table)); i++) {
3563 if (notify_info_data_table[i].type == type &&
3564 notify_info_data_table[i].field == field)
3565 return notify_info_data_table[i].size;
3571 /****************************************************************************
3572 ****************************************************************************/
3574 static BOOL search_notify(uint16 type, uint16 field, int *value)
3578 for (i = 0; notify_info_data_table[i].type != PRINT_TABLE_END; i++) {
3579 if (notify_info_data_table[i].type == type &&
3580 notify_info_data_table[i].field == field &&
3581 notify_info_data_table[i].fn != NULL) {
3590 /****************************************************************************
3591 ****************************************************************************/
3593 void construct_info_data(SPOOL_NOTIFY_INFO_DATA *info_data, uint16 type, uint16 field, int id)
3595 info_data->type = type;
3596 info_data->field = field;
3597 info_data->reserved = 0;
3599 info_data->size = size_of_notify_info_data(type, field);
3600 info_data->enc_type = type_of_notify_info_data(type, field);
3605 /*******************************************************************
3607 * fill a notify_info struct with info asked
3609 ********************************************************************/
3611 static BOOL construct_notify_printer_info(Printer_entry *print_hnd, SPOOL_NOTIFY_INFO *info, int
3612 snum, SPOOL_NOTIFY_OPTION_TYPE
3613 *option_type, uint32 id,
3614 TALLOC_CTX *mem_ctx)
3620 SPOOL_NOTIFY_INFO_DATA *current_data;
3621 NT_PRINTER_INFO_LEVEL *printer = NULL;
3622 print_queue_struct *queue=NULL;
3624 type=option_type->type;
3626 DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
3627 (option_type->type==PRINTER_NOTIFY_TYPE?"PRINTER_NOTIFY_TYPE":"JOB_NOTIFY_TYPE"),
3628 option_type->count, lp_servicename(snum)));
3630 if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &printer, 2, lp_const_servicename(snum))))
3633 for(field_num=0; field_num<option_type->count; field_num++) {
3634 field = option_type->fields[field_num];
3636 DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field));
3638 if (!search_notify(type, field, &j) )
3641 if((info->data=SMB_REALLOC_ARRAY(info->data, SPOOL_NOTIFY_INFO_DATA, info->count+1)) == NULL) {
3642 DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
3643 free_a_printer(&printer, 2);
3647 current_data = &info->data[info->count];
3649 construct_info_data(current_data, type, field, id);
3651 DEBUG(10,("construct_notify_printer_info: calling [%s] snum=%d printername=[%s])\n",
3652 notify_info_data_table[j].name, snum, printer->info_2->printername ));
3654 notify_info_data_table[j].fn(snum, current_data, queue,
3660 free_a_printer(&printer, 2);
3664 /*******************************************************************
3666 * fill a notify_info struct with info asked
3668 ********************************************************************/
3670 static BOOL construct_notify_jobs_info(print_queue_struct *queue,
3671 SPOOL_NOTIFY_INFO *info,
3672 NT_PRINTER_INFO_LEVEL *printer,
3673 int snum, SPOOL_NOTIFY_OPTION_TYPE
3674 *option_type, uint32 id,
3675 TALLOC_CTX *mem_ctx)
3681 SPOOL_NOTIFY_INFO_DATA *current_data;
3683 DEBUG(4,("construct_notify_jobs_info\n"));
3685 type = option_type->type;
3687 DEBUGADD(4,("Notify type: [%s], number of notify info: [%d]\n",
3688 (option_type->type==PRINTER_NOTIFY_TYPE?"PRINTER_NOTIFY_TYPE":"JOB_NOTIFY_TYPE"),
3689 option_type->count));
3691 for(field_num=0; field_num<option_type->count; field_num++) {
3692 field = option_type->fields[field_num];
3694 if (!search_notify(type, field, &j) )
3697 if((info->data=SMB_REALLOC_ARRAY(info->data, SPOOL_NOTIFY_INFO_DATA, info->count+1)) == NULL) {
3698 DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
3702 current_data=&(info->data[info->count]);
3704 construct_info_data(current_data, type, field, id);
3705 notify_info_data_table[j].fn(snum, current_data, queue,
3714 * JFM: The enumeration is not that simple, it's even non obvious.
3716 * let's take an example: I want to monitor the PRINTER SERVER for
3717 * the printer's name and the number of jobs currently queued.
3718 * So in the NOTIFY_OPTION, I have one NOTIFY_OPTION_TYPE structure.
3719 * Its type is PRINTER_NOTIFY_TYPE and it has 2 fields NAME and CJOBS.
3721 * I have 3 printers on the back of my server.
3723 * Now the response is a NOTIFY_INFO structure, with 6 NOTIFY_INFO_DATA
3726 * 1 printer 1 name 1
3727 * 2 printer 1 cjob 1
3728 * 3 printer 2 name 2
3729 * 4 printer 2 cjob 2
3730 * 5 printer 3 name 3
3731 * 6 printer 3 name 3
3733 * that's the print server case, the printer case is even worse.
3736 /*******************************************************************
3738 * enumerate all printers on the printserver
3739 * fill a notify_info struct with info asked
3741 ********************************************************************/
3743 static WERROR printserver_notify_info(pipes_struct *p, POLICY_HND *hnd,
3744 SPOOL_NOTIFY_INFO *info,
3745 TALLOC_CTX *mem_ctx)
3748 Printer_entry *Printer=find_printer_index_by_hnd(p, hnd);
3749 int n_services=lp_numservices();
3751 SPOOL_NOTIFY_OPTION *option;
3752 SPOOL_NOTIFY_OPTION_TYPE *option_type;
3754 DEBUG(4,("printserver_notify_info\n"));
3759 option=Printer->notify.option;
3764 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3765 sending a ffpcn() request first */
3770 for (i=0; i<option->count; i++) {
3771 option_type=&(option->ctr.type[i]);
3773 if (option_type->type!=PRINTER_NOTIFY_TYPE)
3776 for (snum=0; snum<n_services; snum++)
3778 if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) )
3779 construct_notify_printer_info ( Printer, info, snum, option_type, snum, mem_ctx );
3785 * Debugging information, don't delete.
3788 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3789 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3790 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3792 for (i=0; i<info->count; i++) {
3793 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3794 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3795 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3802 /*******************************************************************
3804 * fill a notify_info struct with info asked
3806 ********************************************************************/
3808 static WERROR printer_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info,
3809 TALLOC_CTX *mem_ctx)
3812 Printer_entry *Printer=find_printer_index_by_hnd(p, hnd);
3815 SPOOL_NOTIFY_OPTION *option;
3816 SPOOL_NOTIFY_OPTION_TYPE *option_type;
3818 print_queue_struct *queue=NULL;
3819 print_status_struct status;
3821 DEBUG(4,("printer_notify_info\n"));
3826 option=Printer->notify.option;
3832 /* a bug in xp sp2 rc2 causes it to send a fnpcn request without
3833 sending a ffpcn() request first */
3838 get_printer_snum(p, hnd, &snum, NULL);
3840 for (i=0; i<option->count; i++) {
3841 option_type=&option->ctr.type[i];
3843 switch ( option_type->type ) {
3844 case PRINTER_NOTIFY_TYPE:
3845 if(construct_notify_printer_info(Printer, info, snum,
3851 case JOB_NOTIFY_TYPE: {
3852 NT_PRINTER_INFO_LEVEL *printer = NULL;
3854 count = print_queue_status(snum, &queue, &status);
3856 if (!W_ERROR_IS_OK(get_a_printer(Printer, &printer, 2, lp_const_servicename(snum))))
3859 for (j=0; j<count; j++) {
3860 construct_notify_jobs_info(&queue[j], info,
3867 free_a_printer(&printer, 2);
3877 * Debugging information, don't delete.
3880 DEBUG(1,("dumping the NOTIFY_INFO\n"));
3881 DEBUGADD(1,("info->version:[%d], info->flags:[%d], info->count:[%d]\n", info->version, info->flags, info->count));
3882 DEBUGADD(1,("num\ttype\tfield\tres\tid\tsize\tenc_type\n"));
3884 for (i=0; i<info->count; i++) {
3885 DEBUGADD(1,("[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\t[%d]\n",
3886 i, info->data[i].type, info->data[i].field, info->data[i].reserved,
3887 info->data[i].id, info->data[i].size, info->data[i].enc_type));
3893 /********************************************************************
3895 ********************************************************************/
3897 WERROR _spoolss_rfnpcnex( pipes_struct *p, SPOOL_Q_RFNPCNEX *q_u, SPOOL_R_RFNPCNEX *r_u)
3899 POLICY_HND *handle = &q_u->handle;
3900 SPOOL_NOTIFY_INFO *info = &r_u->info;
3902 Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
3903 WERROR result = WERR_BADFID;
3905 /* we always have a NOTIFY_INFO struct */
3909 DEBUG(2,("_spoolss_rfnpcnex: Invalid handle (%s:%u:%u).\n",
3910 OUR_HANDLE(handle)));
3914 DEBUG(4,("Printer type %x\n",Printer->printer_type));
3917 * We are now using the change value, and
3918 * I should check for PRINTER_NOTIFY_OPTIONS_REFRESH but as
3919 * I don't have a global notification system, I'm sending back all the
3920 * informations even when _NOTHING_ has changed.
3923 /* We need to keep track of the change value to send back in
3924 RRPCN replies otherwise our updates are ignored. */
3926 Printer->notify.fnpcn = True;
3928 if (Printer->notify.client_connected) {
3929 DEBUG(10,("_spoolss_rfnpcnex: Saving change value in request [%x]\n", q_u->change));
3930 Printer->notify.change = q_u->change;
3933 /* just ignore the SPOOL_NOTIFY_OPTION */
3935 switch (Printer->printer_type) {
3937 result = printserver_notify_info(p, handle, info, p->mem_ctx);
3940 case SPLHND_PRINTER:
3941 result = printer_notify_info(p, handle, info, p->mem_ctx);
3945 Printer->notify.fnpcn = False;
3951 /********************************************************************
3952 * construct_printer_info_0
3953 * fill a printer_info_0 struct
3954 ********************************************************************/
3956 static BOOL construct_printer_info_0(Printer_entry *print_hnd,
3957 PRINTER_INFO_0 *printer,
3958 const struct share_params *params)
3962 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
3963 counter_printer_0 *session_counter;
3964 uint32 global_counter;
3967 print_status_struct status;
3969 if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2,
3970 lp_const_servicename(params->service))))
3973 count = print_queue_length(params->service, &status);
3975 /* check if we already have a counter for this printer */
3976 for(session_counter = counter_list; session_counter; session_counter = session_counter->next) {
3977 if (session_counter->snum == params->service)
3981 /* it's the first time, add it to the list */
3982 if (session_counter==NULL) {
3983 if((session_counter=SMB_MALLOC_P(counter_printer_0)) == NULL) {
3984 free_a_printer(&ntprinter, 2);
3987 ZERO_STRUCTP(session_counter);
3988 session_counter->snum=params->service;
3989 session_counter->counter=0;
3990 DLIST_ADD(counter_list, session_counter);
3994 session_counter->counter++;
3997 * the global_counter should be stored in a TDB as it's common to all the clients
3998 * and should be zeroed on samba startup
4000 global_counter=session_counter->counter;
4002 pstrcpy(chaine,ntprinter->info_2->printername);
4004 init_unistr(&printer->printername, chaine);
4006 slprintf(chaine,sizeof(chaine)-1,"\\\\%s", get_server_name(print_hnd));
4007 init_unistr(&printer->servername, chaine);
4009 printer->cjobs = count;
4010 printer->total_jobs = 0;
4011 printer->total_bytes = 0;
4013 setuptime = (time_t)ntprinter->info_2->setuptime;
4014 t=gmtime(&setuptime);
4016 printer->year = t->tm_year+1900;
4017 printer->month = t->tm_mon+1;
4018 printer->dayofweek = t->tm_wday;
4019 printer->day = t->tm_mday;
4020 printer->hour = t->tm_hour;
4021 printer->minute = t->tm_min;
4022 printer->second = t->tm_sec;
4023 printer->milliseconds = 0;
4025 printer->global_counter = global_counter;
4026 printer->total_pages = 0;
4028 /* in 2.2 we reported ourselves as 0x0004 and 0x0565 */
4029 printer->major_version = 0x0005; /* NT 5 */
4030 printer->build_version = 0x0893; /* build 2195 */
4032 printer->unknown7 = 0x1;
4033 printer->unknown8 = 0x0;
4034 printer->unknown9 = 0x0;
4035 printer->session_counter = session_counter->counter;
4036 printer->unknown11 = 0x0;
4037 printer->printer_errors = 0x0; /* number of print failure */
4038 printer->unknown13 = 0x0;
4039 printer->unknown14 = 0x1;
4040 printer->unknown15 = 0x024a; /* 586 Pentium ? */
4041 printer->unknown16 = 0x0;
4042 printer->change_id = ntprinter->info_2->changeid; /* ChangeID in milliseconds*/
4043 printer->unknown18 = 0x0;
4044 printer->status = nt_printq_status(status.status);
4045 printer->unknown20 = 0x0;
4046 printer->c_setprinter = get_c_setprinter(); /* monotonically increasing sum of delta printer counts */
4047 printer->unknown22 = 0x0;
4048 printer->unknown23 = 0x6; /* 6 ???*/
4049 printer->unknown24 = 0; /* unknown 24 to 26 are always 0 */
4050 printer->unknown25 = 0;
4051 printer->unknown26 = 0;
4052 printer->unknown27 = 0;
4053 printer->unknown28 = 0;
4054 printer->unknown29 = 0;
4056 free_a_printer(&ntprinter,2);
4060 /********************************************************************
4061 * construct_printer_info_1
4062 * fill a printer_info_1 struct
4063 ********************************************************************/
4064 static BOOL construct_printer_info_1(Printer_entry *print_hnd, uint32 flags,
4065 PRINTER_INFO_1 *printer,
4066 const struct share_params *params)
4070 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
4072 if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2,
4073 lp_const_servicename(params->service))))
4076 printer->flags=flags;
4078 if (*ntprinter->info_2->comment == '\0') {
4079 init_unistr(&printer->comment, lp_comment(params->service));
4080 slprintf(chaine,sizeof(chaine)-1,"%s,%s,%s", ntprinter->info_2->printername,
4081 ntprinter->info_2->drivername,
4082 lp_comment(params->service));
4085 init_unistr(&printer->comment, ntprinter->info_2->comment); /* saved comment. */
4086 slprintf(chaine,sizeof(chaine)-1,"%s,%s,%s", ntprinter->info_2->printername,
4087 ntprinter->info_2->drivername, ntprinter->info_2->comment);
4090 slprintf(chaine2,sizeof(chaine)-1,"%s", ntprinter->info_2->printername);
4092 init_unistr(&printer->description, chaine);
4093 init_unistr(&printer->name, chaine2);
4095 free_a_printer(&ntprinter,2);
4100 /****************************************************************************
4101 Free a DEVMODE struct.
4102 ****************************************************************************/
4104 static void free_dev_mode(DEVICEMODE *dev)
4109 SAFE_FREE(dev->dev_private);
4114 /****************************************************************************
4115 Convert an NT_DEVICEMODE to a DEVICEMODE structure. Both pointers
4116 should be valid upon entry
4117 ****************************************************************************/
4119 static BOOL convert_nt_devicemode( DEVICEMODE *devmode, NT_DEVICEMODE *ntdevmode )
4121 if ( !devmode || !ntdevmode )
4124 init_unistr(&devmode->devicename, ntdevmode->devicename);
4126 init_unistr(&devmode->formname, ntdevmode->formname);
4128 devmode->specversion = ntdevmode->specversion;
4129 devmode->driverversion = ntdevmode->driverversion;
4130 devmode->size = ntdevmode->size;
4131 devmode->driverextra = ntdevmode->driverextra;
4132 devmode->fields = ntdevmode->fields;
4134 devmode->orientation = ntdevmode->orientation;
4135 devmode->papersize = ntdevmode->papersize;
4136 devmode->paperlength = ntdevmode->paperlength;
4137 devmode->paperwidth = ntdevmode->paperwidth;
4138 devmode->scale = ntdevmode->scale;
4139 devmode->copies = ntdevmode->copies;
4140 devmode->defaultsource = ntdevmode->defaultsource;
4141 devmode->printquality = ntdevmode->printquality;
4142 devmode->color = ntdevmode->color;
4143 devmode->duplex = ntdevmode->duplex;
4144 devmode->yresolution = ntdevmode->yresolution;
4145 devmode->ttoption = ntdevmode->ttoption;
4146 devmode->collate = ntdevmode->collate;
4147 devmode->icmmethod = ntdevmode->icmmethod;
4148 devmode->icmintent = ntdevmode->icmintent;
4149 devmode->mediatype = ntdevmode->mediatype;
4150 devmode->dithertype = ntdevmode->dithertype;
4152 if (ntdevmode->nt_dev_private != NULL) {
4153 if ((devmode->dev_private=(uint8 *)memdup(ntdevmode->nt_dev_private, ntdevmode->driverextra)) == NULL)
4160 /****************************************************************************
4161 Create a DEVMODE struct. Returns malloced memory.
4162 ****************************************************************************/
4164 DEVICEMODE *construct_dev_mode(const char *servicename)
4166 NT_PRINTER_INFO_LEVEL *printer = NULL;
4167 DEVICEMODE *devmode = NULL;
4169 DEBUG(7,("construct_dev_mode\n"));
4171 DEBUGADD(8,("getting printer characteristics\n"));
4173 if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, servicename)))
4176 if ( !printer->info_2->devmode ) {
4177 DEBUG(5, ("BONG! There was no device mode!\n"));
4181 if ((devmode = SMB_MALLOC_P(DEVICEMODE)) == NULL) {
4182 DEBUG(2,("construct_dev_mode: malloc fail.\n"));
4186 ZERO_STRUCTP(devmode);
4188 DEBUGADD(8,("loading DEVICEMODE\n"));
4190 if ( !convert_nt_devicemode( devmode, printer->info_2->devmode ) ) {
4191 free_dev_mode( devmode );
4196 free_a_printer(&printer,2);
4201 /********************************************************************
4202 * construct_printer_info_2
4203 * fill a printer_info_2 struct
4204 ********************************************************************/
4206 static BOOL construct_printer_info_2(Printer_entry *print_hnd,
4207 PRINTER_INFO_2 *printer,
4208 const struct share_params *params)
4211 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
4213 print_status_struct status;
4215 if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2,
4216 lp_const_servicename(params->service))))
4219 count = print_queue_length(params->service, &status);
4221 init_unistr(&printer->servername, ntprinter->info_2->servername); /* servername*/
4222 init_unistr(&printer->printername, ntprinter->info_2->printername); /* printername*/
4223 init_unistr(&printer->sharename, lp_servicename(params->service)); /* sharename */
4224 init_unistr(&printer->portname, ntprinter->info_2->portname); /* port */
4225 init_unistr(&printer->drivername, ntprinter->info_2->drivername); /* drivername */
4227 if (*ntprinter->info_2->comment == '\0')
4228 init_unistr(&printer->comment, lp_comment(params->service)); /* comment */
4230 init_unistr(&printer->comment, ntprinter->info_2->comment); /* saved comment. */
4232 init_unistr(&printer->location, ntprinter->info_2->location); /* location */
4233 init_unistr(&printer->sepfile, ntprinter->info_2->sepfile); /* separator file */
4234 init_unistr(&printer->printprocessor, ntprinter->info_2->printprocessor);/* print processor */
4235 init_unistr(&printer->datatype, ntprinter->info_2->datatype); /* datatype */
4236 init_unistr(&printer->parameters, ntprinter->info_2->parameters); /* parameters (of print processor) */
4238 printer->attributes = ntprinter->info_2->attributes;
4240 printer->priority = ntprinter->info_2->priority; /* priority */
4241 printer->defaultpriority = ntprinter->info_2->default_priority; /* default priority */
4242 printer->starttime = ntprinter->info_2->starttime; /* starttime */
4243 printer->untiltime = ntprinter->info_2->untiltime; /* untiltime */
4244 printer->status = nt_printq_status(status.status); /* status */
4245 printer->cjobs = count; /* jobs */
4246 printer->averageppm = ntprinter->info_2->averageppm; /* average pages per minute */
4248 if ( !(printer->devmode = construct_dev_mode(
4249 lp_const_servicename(params->service))) )
4250 DEBUG(8, ("Returning NULL Devicemode!\n"));
4252 printer->secdesc = NULL;
4254 if ( ntprinter->info_2->secdesc_buf
4255 && ntprinter->info_2->secdesc_buf->sd_size != 0 )
4257 /* don't use talloc_steal() here unless you do a deep steal of all
4258 the SEC_DESC members */
4260 printer->secdesc = dup_sec_desc( get_talloc_ctx(),
4261 ntprinter->info_2->secdesc_buf->sd );
4264 free_a_printer(&ntprinter, 2);
4269 /********************************************************************
4270 * construct_printer_info_3
4271 * fill a printer_info_3 struct
4272 ********************************************************************/
4274 static BOOL construct_printer_info_3(Printer_entry *print_hnd,
4275 PRINTER_INFO_3 **pp_printer,
4276 const struct share_params *params)
4278 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
4279 PRINTER_INFO_3 *printer = NULL;
4281 if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2,
4282 lp_const_servicename(params->service))))
4286 if ((printer = SMB_MALLOC_P(PRINTER_INFO_3)) == NULL) {
4287 DEBUG(2,("construct_printer_info_3: malloc fail.\n"));
4288 free_a_printer(&ntprinter, 2);
4292 ZERO_STRUCTP(printer);
4294 /* These are the components of the SD we are returning. */
4296 if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->sd_size != 0) {
4297 /* don't use talloc_steal() here unless you do a deep steal of all
4298 the SEC_DESC members */
4300 printer->secdesc = dup_sec_desc( get_talloc_ctx(),
4301 ntprinter->info_2->secdesc_buf->sd );
4304 free_a_printer(&ntprinter, 2);
4306 *pp_printer = printer;
4310 /********************************************************************
4311 * construct_printer_info_4
4312 * fill a printer_info_4 struct
4313 ********************************************************************/
4315 static BOOL construct_printer_info_4(Printer_entry *print_hnd,
4316 PRINTER_INFO_4 *printer,
4317 const struct share_params *params)
4319 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
4321 if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2,
4322 lp_const_servicename(params->service))))
4325 init_unistr(&printer->printername, ntprinter->info_2->printername); /* printername*/
4326 init_unistr(&printer->servername, ntprinter->info_2->servername); /* servername*/
4327 printer->attributes = ntprinter->info_2->attributes;
4329 free_a_printer(&ntprinter, 2);
4333 /********************************************************************
4334 * construct_printer_info_5
4335 * fill a printer_info_5 struct
4336 ********************************************************************/
4338 static BOOL construct_printer_info_5(Printer_entry *print_hnd,
4339 PRINTER_INFO_5 *printer,
4340 const struct share_params *params)
4342 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
4344 if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2,
4345 lp_const_servicename(params->service))))
4348 init_unistr(&printer->printername, ntprinter->info_2->printername);
4349 init_unistr(&printer->portname, ntprinter->info_2->portname);
4350 printer->attributes = ntprinter->info_2->attributes;
4352 /* these two are not used by NT+ according to MSDN */
4354 printer->device_not_selected_timeout = 0x0; /* have seen 0x3a98 */
4355 printer->transmission_retry_timeout = 0x0; /* have seen 0xafc8 */
4357 free_a_printer(&ntprinter, 2);
4362 /********************************************************************
4363 * construct_printer_info_6
4364 * fill a printer_info_6 struct
4365 ********************************************************************/
4367 static BOOL construct_printer_info_6(Printer_entry *print_hnd,
4368 PRINTER_INFO_6 *printer,
4369 const struct share_params *params)
4371 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
4373 print_status_struct status;
4375 if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2,
4376 lp_const_servicename(params->service))))
4379 count = print_queue_length(params->service, &status);
4381 printer->status = nt_printq_status(status.status);
4383 free_a_printer(&ntprinter, 2);
4388 /********************************************************************
4389 * construct_printer_info_7
4390 * fill a printer_info_7 struct
4391 ********************************************************************/
4393 static BOOL construct_printer_info_7(Printer_entry *print_hnd,
4394 PRINTER_INFO_7 *printer,
4395 const struct share_params *params)
4397 char *guid_str = NULL;
4400 if (is_printer_published(print_hnd, params->service, &guid)) {
4401 asprintf(&guid_str, "{%s}", smb_uuid_string_static(guid));
4402 strupper_m(guid_str);
4403 init_unistr(&printer->guid, guid_str);
4404 printer->action = SPOOL_DS_PUBLISH;
4406 init_unistr(&printer->guid, "");
4407 printer->action = SPOOL_DS_UNPUBLISH;
4413 /********************************************************************
4414 Spoolss_enumprinters.
4415 ********************************************************************/
4417 static WERROR enum_all_printers_info_1(uint32 flags, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
4420 struct share_iterator *shares;
4421 struct share_params *printer;
4422 PRINTER_INFO_1 *printers=NULL;
4423 WERROR result = WERR_OK;
4425 DEBUG(4,("enum_all_printers_info_1\n"));
4427 if (!(shares = share_list_all(NULL))) {
4428 DEBUG(5, ("Could not list printers\n"));
4429 return WERR_ACCESS_DENIED;
4432 while ((printer = next_printer(shares)) != NULL) {
4433 PRINTER_INFO_1 current_prt;
4435 DEBUG(4,("Found a printer in smb.conf: %s\n",
4436 lp_servicename(printer->service)));
4438 if (!construct_printer_info_1(NULL, flags, ¤t_prt,
4443 if((printers=SMB_REALLOC_ARRAY(printers, PRINTER_INFO_1,
4444 *returned +1)) == NULL) {
4445 DEBUG(2,("enum_all_printers_info_1: failed to enlarge "
4446 "printers buffer!\n"));
4448 TALLOC_FREE(shares);
4451 DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_1\n",
4454 memcpy(&printers[*returned], ¤t_prt,
4455 sizeof(PRINTER_INFO_1));
4457 TALLOC_FREE(printer);
4460 /* check the required size. */
4461 for (i=0; i<*returned; i++)
4462 (*needed) += spoolss_size_printer_info_1(&printers[i]);
4464 if (*needed > offered) {
4465 result = WERR_INSUFFICIENT_BUFFER;
4469 if (!rpcbuf_alloc_size(buffer, *needed)) {
4470 result = WERR_NOMEM;
4474 /* fill the buffer with the structures */
4475 for (i=0; i<*returned; i++)
4476 smb_io_printer_info_1("", buffer, &printers[i], 0);
4481 SAFE_FREE(printers);
4482 TALLOC_FREE(shares);
4484 if ( !W_ERROR_IS_OK(result) )
4490 /********************************************************************
4491 enum_all_printers_info_1_local.
4492 *********************************************************************/
4494 static WERROR enum_all_printers_info_1_local(RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
4496 DEBUG(4,("enum_all_printers_info_1_local\n"));
4498 return enum_all_printers_info_1(PRINTER_ENUM_ICON8, buffer, offered, needed, returned);
4501 /********************************************************************
4502 enum_all_printers_info_1_name.
4503 *********************************************************************/
4505 static WERROR enum_all_printers_info_1_name(fstring name, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
4509 DEBUG(4,("enum_all_printers_info_1_name\n"));
4511 if ((name[0] == '\\') && (name[1] == '\\'))
4514 if (is_myname_or_ipaddr(s)) {
4515 return enum_all_printers_info_1(PRINTER_ENUM_ICON8, buffer, offered, needed, returned);
4518 return WERR_INVALID_NAME;
4521 #if 0 /* JERRY -- disabled for now. Don't think this is used, tested, or correct */
4522 /********************************************************************
4523 enum_all_printers_info_1_remote.
4524 *********************************************************************/
4526 static WERROR enum_all_printers_info_1_remote(fstring name, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
4528 PRINTER_INFO_1 *printer;
4529 fstring printername;
4532 DEBUG(4,("enum_all_printers_info_1_remote\n"));
4533 WERROR result = WERR_OK;
4535 /* JFM: currently it's more a place holder than anything else.
4536 * In the spooler world there is a notion of server registration.
4537 * the print servers are registered on the PDC (in the same domain)
4539 * We should have a TDB here. The registration is done thru an
4540 * undocumented RPC call.
4543 if((printer=SMB_MALLOC_P(PRINTER_INFO_1)) == NULL)
4548 slprintf(printername, sizeof(printername)-1,"Windows NT Remote Printers!!\\\\%s", name);
4549 slprintf(desc, sizeof(desc)-1,"%s", name);
4550 slprintf(comment, sizeof(comment)-1, "Logged on Domain");
4552 init_unistr(&printer->description, desc);
4553 init_unistr(&printer->name, printername);
4554 init_unistr(&printer->comment, comment);
4555 printer->flags=PRINTER_ENUM_ICON3|PRINTER_ENUM_CONTAINER;
4557 /* check the required size. */
4558 *needed += spoolss_size_printer_info_1(printer);
4560 if (*needed > offered) {
4561 result = WERR_INSUFFICIENT_BUFFER;
4565 if (!rpcbuf_alloc_size(buffer, *needed)) {
4566 result = WERR_NOMEM;
4570 /* fill the buffer with the structures */
4571 smb_io_printer_info_1("", buffer, printer, 0);
4577 if ( !W_ERROR_IS_OK(result) )
4585 /********************************************************************
4586 enum_all_printers_info_1_network.
4587 *********************************************************************/
4589 static WERROR enum_all_printers_info_1_network(fstring name, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
4593 DEBUG(4,("enum_all_printers_info_1_network\n"));
4595 /* If we respond to a enum_printers level 1 on our name with flags
4596 set to PRINTER_ENUM_REMOTE with a list of printers then these
4597 printers incorrectly appear in the APW browse list.
4598 Specifically the printers for the server appear at the workgroup
4599 level where all the other servers in the domain are
4600 listed. Windows responds to this call with a
4601 WERR_CAN_NOT_COMPLETE so we should do the same. */
4603 if (name[0] == '\\' && name[1] == '\\')
4606 if (is_myname_or_ipaddr(s))
4607 return WERR_CAN_NOT_COMPLETE;
4609 return enum_all_printers_info_1(PRINTER_ENUM_UNKNOWN_8, buffer, offered, needed, returned);
4612 /********************************************************************
4613 * api_spoolss_enumprinters
4615 * called from api_spoolss_enumprinters (see this to understand)
4616 ********************************************************************/
4618 static WERROR enum_all_printers_info_2(RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
4621 struct share_iterator *shares;
4622 struct share_params *printer;
4623 PRINTER_INFO_2 *printers=NULL;
4624 WERROR result = WERR_OK;
4628 if (!(shares = share_list_all(NULL))) {
4629 DEBUG(5, ("Could not list printers\n"));
4630 return WERR_ACCESS_DENIED;
4633 while ((printer = next_printer(shares)) != NULL) {
4634 PRINTER_INFO_2 current_prt;
4636 DEBUG(4,("Found a printer in smb.conf: %s\n",
4637 lp_servicename(printer->service)));
4639 if (!construct_printer_info_2(NULL, ¤t_prt,
4643 if ( !(printers=SMB_REALLOC_ARRAY(printers, PRINTER_INFO_2,
4645 DEBUG(2,("enum_all_printers_info_2: failed to enlarge "
4646 "printers buffer!\n"));
4648 TALLOC_FREE(shares);
4652 DEBUG(4,("ReAlloced memory for [%d] PRINTER_INFO_2\n",
4655 memcpy(&printers[*returned], ¤t_prt,
4656 sizeof(PRINTER_INFO_2));
4658 TALLOC_FREE(printer);
4661 /* check the required size. */
4662 for (i=0; i<*returned; i++)
4663 (*needed) += spoolss_size_printer_info_2(&printers[i]);
4665 if (*needed > offered) {
4666 result = WERR_INSUFFICIENT_BUFFER;
4670 if (!rpcbuf_alloc_size(buffer, *needed)) {
4671 result = WERR_NOMEM;
4675 /* fill the buffer with the structures */
4676 for (i=0; i<*returned; i++)
4677 smb_io_printer_info_2("", buffer, &(printers[i]), 0);
4682 for (i=0; i<*returned; i++)
4683 free_devmode(printers[i].devmode);
4685 SAFE_FREE(printers);
4686 TALLOC_FREE(shares);
4688 if ( !W_ERROR_IS_OK(result) )
4694 /********************************************************************
4695 * handle enumeration of printers at level 1
4696 ********************************************************************/
4698 static WERROR enumprinters_level1( uint32 flags, fstring name,
4699 RPC_BUFFER *buffer, uint32 offered,
4700 uint32 *needed, uint32 *returned)
4702 /* Not all the flags are equals */
4704 if (flags & PRINTER_ENUM_LOCAL)
4705 return enum_all_printers_info_1_local(buffer, offered, needed, returned);
4707 if (flags & PRINTER_ENUM_NAME)
4708 return enum_all_printers_info_1_name(name, buffer, offered, needed, returned);
4710 #if 0 /* JERRY - disabled for now */
4711 if (flags & PRINTER_ENUM_REMOTE)
4712 return enum_all_printers_info_1_remote(name, buffer, offered, needed, returned);
4715 if (flags & PRINTER_ENUM_NETWORK)
4716 return enum_all_printers_info_1_network(name, buffer, offered, needed, returned);
4718 return WERR_OK; /* NT4sp5 does that */
4721 /********************************************************************
4722 * handle enumeration of printers at level 2
4723 ********************************************************************/
4725 static WERROR enumprinters_level2( uint32 flags, fstring servername,
4726 RPC_BUFFER *buffer, uint32 offered,
4727 uint32 *needed, uint32 *returned)
4729 char *s = servername;
4731 if (flags & PRINTER_ENUM_LOCAL) {
4732 return enum_all_printers_info_2(buffer, offered, needed, returned);
4735 if (flags & PRINTER_ENUM_NAME) {
4736 if ((servername[0] == '\\') && (servername[1] == '\\'))
4738 if (is_myname_or_ipaddr(s))
4739 return enum_all_printers_info_2(buffer, offered, needed, returned);
4741 return WERR_INVALID_NAME;
4744 if (flags & PRINTER_ENUM_REMOTE)
4745 return WERR_UNKNOWN_LEVEL;
4750 /********************************************************************
4751 * handle enumeration of printers at level 5
4752 ********************************************************************/
4754 static WERROR enumprinters_level5( uint32 flags, fstring servername,
4755 RPC_BUFFER *buffer, uint32 offered,
4756 uint32 *needed, uint32 *returned)
4758 /* return enum_all_printers_info_5(buffer, offered, needed, returned);*/
4762 /********************************************************************
4763 * api_spoolss_enumprinters
4765 * called from api_spoolss_enumprinters (see this to understand)
4766 ********************************************************************/
4768 WERROR _spoolss_enumprinters( pipes_struct *p, SPOOL_Q_ENUMPRINTERS *q_u, SPOOL_R_ENUMPRINTERS *r_u)
4770 uint32 flags = q_u->flags;
4771 UNISTR2 *servername = &q_u->servername;
4772 uint32 level = q_u->level;
4773 RPC_BUFFER *buffer = NULL;
4774 uint32 offered = q_u->offered;
4775 uint32 *needed = &r_u->needed;
4776 uint32 *returned = &r_u->returned;
4780 /* that's an [in out] buffer */
4782 if (!q_u->buffer && (offered!=0)) {
4783 return WERR_INVALID_PARAM;
4786 rpcbuf_move(q_u->buffer, &r_u->buffer);
4787 buffer = r_u->buffer;
4789 DEBUG(4,("_spoolss_enumprinters\n"));
4796 * flags==PRINTER_ENUM_NAME
4797 * if name=="" then enumerates all printers
4798 * if name!="" then enumerate the printer
4799 * flags==PRINTER_ENUM_REMOTE
4800 * name is NULL, enumerate printers
4801 * Level 2: name!="" enumerates printers, name can't be NULL
4802 * Level 3: doesn't exist
4803 * Level 4: does a local registry lookup
4804 * Level 5: same as Level 2
4807 unistr2_to_ascii(name, servername, sizeof(name)-1);
4812 return enumprinters_level1(flags, name, buffer, offered, needed, returned);
4814 return enumprinters_level2(flags, name, buffer, offered, needed, returned);
4816 return enumprinters_level5(flags, name, buffer, offered, needed, returned);
4821 return WERR_UNKNOWN_LEVEL;
4824 /****************************************************************************
4825 ****************************************************************************/
4827 static WERROR getprinter_level_0(Printer_entry *print_hnd,
4828 const struct share_params *params,
4829 RPC_BUFFER *buffer, uint32 offered,
4832 PRINTER_INFO_0 *printer=NULL;
4833 WERROR result = WERR_OK;
4835 if((printer=SMB_MALLOC_P(PRINTER_INFO_0)) == NULL)
4838 construct_printer_info_0(print_hnd, printer, params);
4840 /* check the required size. */
4841 *needed += spoolss_size_printer_info_0(printer);
4843 if (*needed > offered) {
4844 result = WERR_INSUFFICIENT_BUFFER;
4848 if (!rpcbuf_alloc_size(buffer, *needed)) {
4849 result = WERR_NOMEM;
4853 /* fill the buffer with the structures */
4854 smb_io_printer_info_0("", buffer, printer, 0);
4864 /****************************************************************************
4865 ****************************************************************************/
4867 static WERROR getprinter_level_1(Printer_entry *print_hnd,
4868 const struct share_params *params,
4869 RPC_BUFFER *buffer, uint32 offered,
4872 PRINTER_INFO_1 *printer=NULL;
4873 WERROR result = WERR_OK;
4875 if((printer=SMB_MALLOC_P(PRINTER_INFO_1)) == NULL)
4878 construct_printer_info_1(print_hnd, PRINTER_ENUM_ICON8, printer,
4881 /* check the required size. */
4882 *needed += spoolss_size_printer_info_1(printer);
4884 if (*needed > offered) {
4885 result = WERR_INSUFFICIENT_BUFFER;
4889 if (!rpcbuf_alloc_size(buffer, *needed)) {
4890 result = WERR_NOMEM;
4894 /* fill the buffer with the structures */
4895 smb_io_printer_info_1("", buffer, printer, 0);
4904 /****************************************************************************
4905 ****************************************************************************/
4907 static WERROR getprinter_level_2(Printer_entry *print_hnd,
4908 const struct share_params *params,
4909 RPC_BUFFER *buffer, uint32 offered,
4912 PRINTER_INFO_2 *printer=NULL;
4913 WERROR result = WERR_OK;
4915 if((printer=SMB_MALLOC_P(PRINTER_INFO_2))==NULL)
4918 construct_printer_info_2(print_hnd, printer, params);
4920 /* check the required size. */
4921 *needed += spoolss_size_printer_info_2(printer);
4923 if (*needed > offered) {
4924 result = WERR_INSUFFICIENT_BUFFER;
4928 if (!rpcbuf_alloc_size(buffer, *needed)) {
4929 result = WERR_NOMEM;
4933 /* fill the buffer with the structures */
4934 if (!smb_io_printer_info_2("", buffer, printer, 0))
4935 result = WERR_NOMEM;
4939 free_printer_info_2(printer);
4944 /****************************************************************************
4945 ****************************************************************************/
4947 static WERROR getprinter_level_3(Printer_entry *print_hnd,
4948 const struct share_params *params,
4949 RPC_BUFFER *buffer, uint32 offered,
4952 PRINTER_INFO_3 *printer=NULL;
4953 WERROR result = WERR_OK;
4955 if (!construct_printer_info_3(print_hnd, &printer, params))
4958 /* check the required size. */
4959 *needed += spoolss_size_printer_info_3(printer);
4961 if (*needed > offered) {
4962 result = WERR_INSUFFICIENT_BUFFER;
4966 if (!rpcbuf_alloc_size(buffer, *needed)) {
4967 result = WERR_NOMEM;
4971 /* fill the buffer with the structures */
4972 smb_io_printer_info_3("", buffer, printer, 0);
4976 free_printer_info_3(printer);
4981 /****************************************************************************
4982 ****************************************************************************/
4984 static WERROR getprinter_level_4(Printer_entry *print_hnd,
4985 const struct share_params *params,
4986 RPC_BUFFER *buffer, uint32 offered,
4989 PRINTER_INFO_4 *printer=NULL;
4990 WERROR result = WERR_OK;
4992 if((printer=SMB_MALLOC_P(PRINTER_INFO_4))==NULL)
4995 if (!construct_printer_info_4(print_hnd, printer, params)) {
5000 /* check the required size. */
5001 *needed += spoolss_size_printer_info_4(printer);
5003 if (*needed > offered) {
5004 result = WERR_INSUFFICIENT_BUFFER;
5008 if (!rpcbuf_alloc_size(buffer, *needed)) {
5009 result = WERR_NOMEM;
5013 /* fill the buffer with the structures */
5014 smb_io_printer_info_4("", buffer, printer, 0);
5018 free_printer_info_4(printer);
5023 /****************************************************************************
5024 ****************************************************************************/
5026 static WERROR getprinter_level_5(Printer_entry *print_hnd,
5027 const struct share_params *params,
5028 RPC_BUFFER *buffer, uint32 offered,
5031 PRINTER_INFO_5 *printer=NULL;
5032 WERROR result = WERR_OK;
5034 if((printer=SMB_MALLOC_P(PRINTER_INFO_5))==NULL)
5037 if (!construct_printer_info_5(print_hnd, printer, params)) {
5038 free_printer_info_5(printer);
5042 /* check the required size. */
5043 *needed += spoolss_size_printer_info_5(printer);
5045 if (*needed > offered) {
5046 result = WERR_INSUFFICIENT_BUFFER;
5050 if (!rpcbuf_alloc_size(buffer, *needed)) {
5051 result = WERR_NOMEM;
5055 /* fill the buffer with the structures */
5056 smb_io_printer_info_5("", buffer, printer, 0);
5060 free_printer_info_5(printer);
5065 static WERROR getprinter_level_6(Printer_entry *print_hnd,
5066 const struct share_params *params,
5067 RPC_BUFFER *buffer, uint32 offered,
5070 PRINTER_INFO_6 *printer;
5071 WERROR result = WERR_OK;
5073 if ((printer = SMB_MALLOC_P(PRINTER_INFO_6)) == NULL) {
5077 if (!construct_printer_info_6(print_hnd, printer, params)) {
5078 free_printer_info_6(printer);
5082 /* check the required size. */
5083 *needed += spoolss_size_printer_info_6(printer);
5085 if (*needed > offered) {
5086 result = WERR_INSUFFICIENT_BUFFER;
5090 if (!rpcbuf_alloc_size(buffer, *needed)) {
5091 result = WERR_NOMEM;
5095 /* fill the buffer with the structures */
5096 smb_io_printer_info_6("", buffer, printer, 0);
5100 free_printer_info_6(printer);
5105 static WERROR getprinter_level_7(Printer_entry *print_hnd,
5106 const struct share_params *params,
5107 RPC_BUFFER *buffer, uint32 offered,
5110 PRINTER_INFO_7 *printer=NULL;
5111 WERROR result = WERR_OK;
5113 if((printer=SMB_MALLOC_P(PRINTER_INFO_7))==NULL)
5116 if (!construct_printer_info_7(print_hnd, printer, params))
5119 /* check the required size. */
5120 *needed += spoolss_size_printer_info_7(printer);
5122 if (*needed > offered) {
5123 result = WERR_INSUFFICIENT_BUFFER;
5127 if (!rpcbuf_alloc_size(buffer, *needed)) {
5128 result = WERR_NOMEM;
5133 /* fill the buffer with the structures */
5134 smb_io_printer_info_7("", buffer, printer, 0);
5138 free_printer_info_7(printer);
5143 /****************************************************************************
5144 ****************************************************************************/
5146 WERROR _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GETPRINTER *r_u)
5148 POLICY_HND *handle = &q_u->handle;
5149 uint32 level = q_u->level;
5150 RPC_BUFFER *buffer = NULL;
5151 uint32 offered = q_u->offered;
5152 uint32 *needed = &r_u->needed;
5153 Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
5154 struct share_params *params;
5158 /* that's an [in out] buffer */
5160 if (!q_u->buffer && (offered!=0)) {
5161 return WERR_INVALID_PARAM;
5164 rpcbuf_move(q_u->buffer, &r_u->buffer);
5165 buffer = r_u->buffer;
5169 if (!get_printer_snum(p, handle, &snum, ¶ms))
5174 return getprinter_level_0(Printer, params, buffer, offered,
5177 return getprinter_level_1(Printer, params, buffer, offered,
5180 return getprinter_level_2(Printer, params, buffer, offered,
5183 return getprinter_level_3(Printer, params, buffer, offered,
5186 return getprinter_level_4(Printer, params, buffer, offered,
5189 return getprinter_level_5(Printer, params, buffer, offered,
5192 return getprinter_level_6(Printer, params, buffer, offered,
5195 return getprinter_level_7(Printer, params, buffer, offered,
5198 return WERR_UNKNOWN_LEVEL;
5201 /********************************************************************
5202 * fill a DRIVER_INFO_1 struct
5203 ********************************************************************/
5205 static void fill_printer_driver_info_1(DRIVER_INFO_1 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, fstring servername, fstring architecture)
5207 init_unistr( &info->name, driver.info_3->name);
5210 /********************************************************************
5211 * construct_printer_driver_info_1
5212 ********************************************************************/
5214 static WERROR construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, fstring servername, fstring architecture, uint32 version)
5216 NT_PRINTER_INFO_LEVEL *printer = NULL;
5217 NT_PRINTER_DRIVER_INFO_LEVEL driver;
5219 ZERO_STRUCT(driver);
5221 if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, lp_const_servicename(snum))))
5222 return WERR_INVALID_PRINTER_NAME;
5224 if (!W_ERROR_IS_OK(get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version))) {
5225 free_a_printer(&printer, 2);
5226 return WERR_UNKNOWN_PRINTER_DRIVER;
5229 fill_printer_driver_info_1(info, driver, servername, architecture);
5231 free_a_printer(&printer,2);
5236 /********************************************************************
5237 * construct_printer_driver_info_2
5238 * fill a printer_info_2 struct
5239 ********************************************************************/
5241 static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, fstring servername)
5245 info->version=driver.info_3->cversion;
5247 init_unistr( &info->name, driver.info_3->name );
5248 init_unistr( &info->architecture, driver.info_3->environment );
5251 if (strlen(driver.info_3->driverpath)) {
5252 slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->driverpath);
5253 init_unistr( &info->driverpath, temp );
5255 init_unistr( &info->driverpath, "" );
5257 if (strlen(driver.info_3->datafile)) {
5258 slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->datafile);
5259 init_unistr( &info->datafile, temp );
5261 init_unistr( &info->datafile, "" );
5263 if (strlen(driver.info_3->configfile)) {
5264 slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->configfile);
5265 init_unistr( &info->configfile, temp );
5267 init_unistr( &info->configfile, "" );
5270 /********************************************************************
5271 * construct_printer_driver_info_2
5272 * fill a printer_info_2 struct
5273 ********************************************************************/
5275 static WERROR construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, fstring servername, fstring architecture, uint32 version)
5277 NT_PRINTER_INFO_LEVEL *printer = NULL;
5278 NT_PRINTER_DRIVER_INFO_LEVEL driver;
5280 ZERO_STRUCT(printer);
5281 ZERO_STRUCT(driver);
5283 if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, lp_const_servicename(snum))))
5284 return WERR_INVALID_PRINTER_NAME;
5286 if (!W_ERROR_IS_OK(get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version))) {
5287 free_a_printer(&printer, 2);
5288 return WERR_UNKNOWN_PRINTER_DRIVER;
5291 fill_printer_driver_info_2(info, driver, servername);
5293 free_a_printer(&printer,2);
5298 /********************************************************************
5299 * copy a strings array and convert to UNICODE
5301 * convert an array of ascii string to a UNICODE string
5302 ********************************************************************/
5304 static uint32 init_unistr_array(uint16 **uni_array, fstring *char_array, const char *servername)
5311 DEBUG(6,("init_unistr_array\n"));
5322 v = ""; /* hack to handle null lists */
5325 /* hack to allow this to be used in places other than when generating
5326 the list of dependent files */
5329 slprintf( line, sizeof(line)-1, "\\\\%s%s", servername, v );
5333 DEBUGADD(6,("%d:%s:%lu\n", i, line, (unsigned long)strlen(line)));
5335 /* add one extra unit16 for the second terminating NULL */
5337 if ( (*uni_array=SMB_REALLOC_ARRAY(*uni_array, uint16, j+1+strlen(line)+2)) == NULL ) {
5338 DEBUG(2,("init_unistr_array: Realloc error\n" ));
5345 j += (rpcstr_push((*uni_array+j), line, sizeof(uint16)*strlen(line)+2, STR_TERMINATE) / sizeof(uint16));
5350 /* special case for ""; we need to add both NULL's here */
5352 (*uni_array)[j++]=0x0000;
5353 (*uni_array)[j]=0x0000;
5356 DEBUGADD(6,("last one:done\n"));
5358 /* return size of array in uint16's */
5363 /********************************************************************
5364 * construct_printer_info_3
5365 * fill a printer_info_3 struct
5366 ********************************************************************/
5368 static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, fstring servername)
5374 info->version=driver.info_3->cversion;
5376 init_unistr( &info->name, driver.info_3->name );
5377 init_unistr( &info->architecture, driver.info_3->environment );
5379 if (strlen(driver.info_3->driverpath)) {
5380 slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->driverpath);
5381 init_unistr( &info->driverpath, temp );
5383 init_unistr( &info->driverpath, "" );
5385 if (strlen(driver.info_3->datafile)) {
5386 slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->datafile);
5387 init_unistr( &info->datafile, temp );
5389 init_unistr( &info->datafile, "" );
5391 if (strlen(driver.info_3->configfile)) {
5392 slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->configfile);
5393 init_unistr( &info->configfile, temp );
5395 init_unistr( &info->configfile, "" );
5397 if (strlen(driver.info_3->helpfile)) {
5398 slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->helpfile);
5399 init_unistr( &info->helpfile, temp );
5401 init_unistr( &info->helpfile, "" );
5403 init_unistr( &info->monitorname, driver.info_3->monitorname );
5404 init_unistr( &info->defaultdatatype, driver.info_3->defaultdatatype );
5406 info->dependentfiles=NULL;
5407 init_unistr_array(&info->dependentfiles, driver.info_3->dependentfiles, servername);
5410 /********************************************************************
5411 * construct_printer_info_3
5412 * fill a printer_info_3 struct
5413 ********************************************************************/
5415 static WERROR construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, fstring servername, fstring architecture, uint32 version)
5417 NT_PRINTER_INFO_LEVEL *printer = NULL;
5418 NT_PRINTER_DRIVER_INFO_LEVEL driver;
5420 ZERO_STRUCT(driver);
5422 status=get_a_printer(NULL, &printer, 2, lp_const_servicename(snum) );
5423 DEBUG(8,("construct_printer_driver_info_3: status: %s\n", dos_errstr(status)));
5424 if (!W_ERROR_IS_OK(status))
5425 return WERR_INVALID_PRINTER_NAME;
5427 status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version);
5428 DEBUG(8,("construct_printer_driver_info_3: status: %s\n", dos_errstr(status)));
5433 * I put this code in during testing. Helpful when commenting out the
5434 * support for DRIVER_INFO_6 in regards to win2k. Not needed in general
5435 * as win2k always queries the driver using an infor level of 6.
5436 * I've left it in (but ifdef'd out) because I'll probably
5437 * use it in experimentation again in the future. --jerry 22/01/2002
5440 if (!W_ERROR_IS_OK(status)) {
5442 * Is this a W2k client ?
5445 /* Yes - try again with a WinNT driver. */
5447 status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version);
5448 DEBUG(8,("construct_printer_driver_info_3: status: %s\n", dos_errstr(status)));
5452 if (!W_ERROR_IS_OK(status)) {
5453 free_a_printer(&printer,2);
5454 return WERR_UNKNOWN_PRINTER_DRIVER;
5462 fill_printer_driver_info_3(info, driver, servername);
5464 free_a_printer(&printer,2);
5469 /********************************************************************
5470 * construct_printer_info_6
5471 * fill a printer_info_6 struct - we know that driver is really level 3. This sucks. JRA.
5472 ********************************************************************/
5474 static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, fstring servername)
5480 memset(&nullstr, '\0', sizeof(fstring));
5482 info->version=driver.info_3->cversion;
5484 init_unistr( &info->name, driver.info_3->name );
5485 init_unistr( &info->architecture, driver.info_3->environment );
5487 if (strlen(driver.info_3->driverpath)) {
5488 slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->driverpath);
5489 init_unistr( &info->driverpath, temp );
5491 init_unistr( &info->driverpath, "" );
5493 if (strlen(driver.info_3->datafile)) {
5494 slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->datafile);
5495 init_unistr( &info->datafile, temp );
5497 init_unistr( &info->datafile, "" );
5499 if (strlen(driver.info_3->configfile)) {
5500 slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->configfile);
5501 init_unistr( &info->configfile, temp );
5503 init_unistr( &info->configfile, "" );
5505 if (strlen(driver.info_3->helpfile)) {
5506 slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->helpfile);
5507 init_unistr( &info->helpfile, temp );
5509 init_unistr( &info->helpfile, "" );
5511 init_unistr( &info->monitorname, driver.info_3->monitorname );
5512 init_unistr( &info->defaultdatatype, driver.info_3->defaultdatatype );
5514 info->dependentfiles = NULL;
5515 init_unistr_array( &info->dependentfiles, driver.info_3->dependentfiles, servername );
5517 info->previousdrivernames=NULL;
5518 init_unistr_array(&info->previousdrivernames, &nullstr, servername);
5520 info->driver_date=0;
5523 info->driver_version_low=0;
5524 info->driver_version_high=0;
5526 init_unistr( &info->mfgname, "");
5527 init_unistr( &info->oem_url, "");
5528 init_unistr( &info->hardware_id, "");
5529 init_unistr( &info->provider, "");
5532 /********************************************************************
5533 * construct_printer_info_6
5534 * fill a printer_info_6 struct
5535 ********************************************************************/
5537 static WERROR construct_printer_driver_info_6(DRIVER_INFO_6 *info, int snum,
5538 fstring servername, fstring architecture, uint32 version)
5540 NT_PRINTER_INFO_LEVEL *printer = NULL;
5541 NT_PRINTER_DRIVER_INFO_LEVEL driver;
5544 ZERO_STRUCT(driver);
5546 status=get_a_printer(NULL, &printer, 2, lp_const_servicename(snum) );
5548 DEBUG(8,("construct_printer_driver_info_6: status: %s\n", dos_errstr(status)));
5550 if (!W_ERROR_IS_OK(status))
5551 return WERR_INVALID_PRINTER_NAME;
5553 status = get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version);
5555 DEBUG(8,("construct_printer_driver_info_6: status: %s\n", dos_errstr(status)));
5557 if (!W_ERROR_IS_OK(status))
5560 * Is this a W2k client ?
5564 free_a_printer(&printer,2);
5565 return WERR_UNKNOWN_PRINTER_DRIVER;
5568 /* Yes - try again with a WinNT driver. */
5570 status=get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version);
5571 DEBUG(8,("construct_printer_driver_info_6: status: %s\n", dos_errstr(status)));
5572 if (!W_ERROR_IS_OK(status)) {
5573 free_a_printer(&printer,2);
5574 return WERR_UNKNOWN_PRINTER_DRIVER;
5578 fill_printer_driver_info_6(info, driver, servername);
5580 free_a_printer(&printer,2);
5581 free_a_printer_driver(driver, 3);
5586 /****************************************************************************
5587 ****************************************************************************/
5589 static void free_printer_driver_info_3(DRIVER_INFO_3 *info)
5591 SAFE_FREE(info->dependentfiles);
5594 /****************************************************************************
5595 ****************************************************************************/
5597 static void free_printer_driver_info_6(DRIVER_INFO_6 *info)
5599 SAFE_FREE(info->dependentfiles);
5602 /****************************************************************************
5603 ****************************************************************************/
5605 static WERROR getprinterdriver2_level1(fstring servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed)
5607 DRIVER_INFO_1 *info=NULL;
5610 if((info=SMB_MALLOC_P(DRIVER_INFO_1)) == NULL)
5613 result = construct_printer_driver_info_1(info, snum, servername, architecture, version);
5614 if (!W_ERROR_IS_OK(result))
5617 /* check the required size. */
5618 *needed += spoolss_size_printer_driver_info_1(info);
5620 if (*needed > offered) {
5621 result = WERR_INSUFFICIENT_BUFFER;
5625 if (!rpcbuf_alloc_size(buffer, *needed)) {
5626 result = WERR_NOMEM;
5630 /* fill the buffer with the structures */
5631 smb_io_printer_driver_info_1("", buffer, info, 0);
5640 /****************************************************************************
5641 ****************************************************************************/
5643 static WERROR getprinterdriver2_level2(fstring servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed)
5645 DRIVER_INFO_2 *info=NULL;
5648 if((info=SMB_MALLOC_P(DRIVER_INFO_2)) == NULL)
5651 result = construct_printer_driver_info_2(info, snum, servername, architecture, version);
5652 if (!W_ERROR_IS_OK(result))
5655 /* check the required size. */
5656 *needed += spoolss_size_printer_driver_info_2(info);
5658 if (*needed > offered) {
5659 result = WERR_INSUFFICIENT_BUFFER;
5663 if (!rpcbuf_alloc_size(buffer, *needed)) {
5664 result = WERR_NOMEM;
5668 /* fill the buffer with the structures */
5669 smb_io_printer_driver_info_2("", buffer, info, 0);
5678 /****************************************************************************
5679 ****************************************************************************/
5681 static WERROR getprinterdriver2_level3(fstring servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed)
5688 result = construct_printer_driver_info_3(&info, snum, servername, architecture, version);
5689 if (!W_ERROR_IS_OK(result))
5692 /* check the required size. */
5693 *needed += spoolss_size_printer_driver_info_3(&info);
5695 if (*needed > offered) {
5696 result = WERR_INSUFFICIENT_BUFFER;
5700 if (!rpcbuf_alloc_size(buffer, *needed)) {
5701 result = WERR_NOMEM;
5705 /* fill the buffer with the structures */
5706 smb_io_printer_driver_info_3("", buffer, &info, 0);
5709 free_printer_driver_info_3(&info);
5714 /****************************************************************************
5715 ****************************************************************************/
5717 static WERROR getprinterdriver2_level6(fstring servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed)
5724 result = construct_printer_driver_info_6(&info, snum, servername, architecture, version);
5725 if (!W_ERROR_IS_OK(result))
5728 /* check the required size. */
5729 *needed += spoolss_size_printer_driver_info_6(&info);
5731 if (*needed > offered) {
5732 result = WERR_INSUFFICIENT_BUFFER;
5736 if (!rpcbuf_alloc_size(buffer, *needed)) {
5737 result = WERR_NOMEM;
5741 /* fill the buffer with the structures */
5742 smb_io_printer_driver_info_6("", buffer, &info, 0);
5745 free_printer_driver_info_6(&info);
5750 /****************************************************************************
5751 ****************************************************************************/
5753 WERROR _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 *q_u, SPOOL_R_GETPRINTERDRIVER2 *r_u)
5755 POLICY_HND *handle = &q_u->handle;
5756 UNISTR2 *uni_arch = &q_u->architecture;
5757 uint32 level = q_u->level;
5758 uint32 clientmajorversion = q_u->clientmajorversion;
5759 RPC_BUFFER *buffer = NULL;
5760 uint32 offered = q_u->offered;
5761 uint32 *needed = &r_u->needed;
5762 uint32 *servermajorversion = &r_u->servermajorversion;
5763 uint32 *serverminorversion = &r_u->serverminorversion;
5764 Printer_entry *printer;
5767 fstring architecture;
5770 /* that's an [in out] buffer */
5772 if (!q_u->buffer && (offered!=0)) {
5773 return WERR_INVALID_PARAM;
5776 rpcbuf_move(q_u->buffer, &r_u->buffer);
5777 buffer = r_u->buffer;
5779 DEBUG(4,("_spoolss_getprinterdriver2\n"));
5781 if ( !(printer = find_printer_index_by_hnd( p, handle )) ) {
5782 DEBUG(0,("_spoolss_getprinterdriver2: invalid printer handle!\n"));
5783 return WERR_INVALID_PRINTER_NAME;
5787 *servermajorversion = 0;
5788 *serverminorversion = 0;
5790 fstrcpy(servername, get_server_name( printer ));
5791 unistr2_to_ascii(architecture, uni_arch, sizeof(architecture)-1);
5793 if (!get_printer_snum(p, handle, &snum, NULL))
5798 return getprinterdriver2_level1(servername, architecture, clientmajorversion, snum, buffer, offered, needed);
5800 return getprinterdriver2_level2(servername, architecture, clientmajorversion, snum, buffer, offered, needed);
5802 return getprinterdriver2_level3(servername, architecture, clientmajorversion, snum, buffer, offered, needed);
5804 return getprinterdriver2_level6(servername, architecture, clientmajorversion, snum, buffer, offered, needed);
5807 /* apparently this call is the equivalent of
5808 EnumPrinterDataEx() for the DsDriver key */
5813 return WERR_UNKNOWN_LEVEL;
5816 /****************************************************************************
5817 ****************************************************************************/
5819 WERROR _spoolss_startpageprinter(pipes_struct *p, SPOOL_Q_STARTPAGEPRINTER *q_u, SPOOL_R_STARTPAGEPRINTER *r_u)
5821 POLICY_HND *handle = &q_u->handle;
5823 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5826 DEBUG(3,("Error in startpageprinter printer handle\n"));
5830 Printer->page_started=True;
5834 /****************************************************************************
5835 ****************************************************************************/
5837 WERROR _spoolss_endpageprinter(pipes_struct *p, SPOOL_Q_ENDPAGEPRINTER *q_u, SPOOL_R_ENDPAGEPRINTER *r_u)
5839 POLICY_HND *handle = &q_u->handle;
5842 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5845 DEBUG(2,("_spoolss_endpageprinter: Invalid handle (%s:%u:%u).\n",OUR_HANDLE(handle)));
5849 if (!get_printer_snum(p, handle, &snum, NULL))
5852 Printer->page_started=False;
5853 print_job_endpage(snum, Printer->jobid);
5858 /********************************************************************
5859 * api_spoolss_getprinter
5860 * called from the spoolss dispatcher
5862 ********************************************************************/
5864 WERROR _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, SPOOL_R_STARTDOCPRINTER *r_u)
5866 POLICY_HND *handle = &q_u->handle;
5867 DOC_INFO *docinfo = &q_u->doc_info_container.docinfo;
5868 uint32 *jobid = &r_u->jobid;
5870 DOC_INFO_1 *info_1 = &docinfo->doc_info_1;
5874 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5877 DEBUG(2,("_spoolss_startdocprinter: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(handle)));
5882 * a nice thing with NT is it doesn't listen to what you tell it.
5883 * when asked to send _only_ RAW datas, it tries to send datas
5886 * So I add checks like in NT Server ...
5889 if (info_1->p_datatype != 0) {
5890 unistr2_to_ascii(datatype, &info_1->datatype, sizeof(datatype));
5891 if (strcmp(datatype, "RAW") != 0) {
5893 return WERR_INVALID_DATATYPE;
5897 /* get the share number of the printer */
5898 if (!get_printer_snum(p, handle, &snum, NULL)) {
5902 unistr2_to_ascii(jobname, &info_1->docname, sizeof(jobname));
5904 Printer->jobid = print_job_start(&p->pipe_user, snum, jobname, Printer->nt_devmode);
5906 /* An error occured in print_job_start() so return an appropriate
5909 if (Printer->jobid == -1) {
5910 return map_werror_from_unix(errno);
5913 Printer->document_started=True;
5914 (*jobid) = Printer->jobid;
5919 /********************************************************************
5920 * api_spoolss_getprinter
5921 * called from the spoolss dispatcher
5923 ********************************************************************/
5925 WERROR _spoolss_enddocprinter(pipes_struct *p, SPOOL_Q_ENDDOCPRINTER *q_u, SPOOL_R_ENDDOCPRINTER *r_u)
5927 POLICY_HND *handle = &q_u->handle;
5929 return _spoolss_enddocprinter_internal(p, handle);
5932 /****************************************************************************
5933 ****************************************************************************/
5935 WERROR _spoolss_writeprinter(pipes_struct *p, SPOOL_Q_WRITEPRINTER *q_u, SPOOL_R_WRITEPRINTER *r_u)
5937 POLICY_HND *handle = &q_u->handle;
5938 uint32 buffer_size = q_u->buffer_size;
5939 uint8 *buffer = q_u->buffer;
5940 uint32 *buffer_written = &q_u->buffer_size2;
5942 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5945 DEBUG(2,("_spoolss_writeprinter: Invalid handle (%s:%u:%u)\n",OUR_HANDLE(handle)));
5946 r_u->buffer_written = q_u->buffer_size2;
5950 if (!get_printer_snum(p, handle, &snum, NULL))
5953 (*buffer_written) = (uint32)print_job_write(snum, Printer->jobid, (const char *)buffer,
5954 (SMB_OFF_T)-1, (size_t)buffer_size);
5955 if (*buffer_written == (uint32)-1) {
5956 r_u->buffer_written = 0;
5957 if (errno == ENOSPC)
5958 return WERR_NO_SPOOL_SPACE;
5960 return WERR_ACCESS_DENIED;
5963 r_u->buffer_written = q_u->buffer_size2;
5968 /********************************************************************
5969 * api_spoolss_getprinter
5970 * called from the spoolss dispatcher
5972 ********************************************************************/
5974 static WERROR control_printer(POLICY_HND *handle, uint32 command,
5978 WERROR errcode = WERR_BADFUNC;
5979 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
5982 DEBUG(2,("control_printer: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(handle)));
5986 if (!get_printer_snum(p, handle, &snum, NULL))
5990 case PRINTER_CONTROL_PAUSE:
5991 if (print_queue_pause(&p->pipe_user, snum, &errcode)) {
5995 case PRINTER_CONTROL_RESUME:
5996 case PRINTER_CONTROL_UNPAUSE:
5997 if (print_queue_resume(&p->pipe_user, snum, &errcode)) {
6001 case PRINTER_CONTROL_PURGE:
6002 if (print_queue_purge(&p->pipe_user, snum, &errcode)) {
6007 return WERR_UNKNOWN_LEVEL;
6013 /********************************************************************
6014 * api_spoolss_abortprinter
6015 * From MSDN: "Deletes printer's spool file if printer is configured
6017 ********************************************************************/
6019 WERROR _spoolss_abortprinter(pipes_struct *p, SPOOL_Q_ABORTPRINTER *q_u, SPOOL_R_ABORTPRINTER *r_u)
6021 POLICY_HND *handle = &q_u->handle;
6022 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
6024 WERROR errcode = WERR_OK;
6027 DEBUG(2,("_spoolss_abortprinter: Invalid handle (%s:%u:%u)\n",OUR_HANDLE(handle)));
6031 if (!get_printer_snum(p, handle, &snum, NULL))
6034 print_job_delete( &p->pipe_user, snum, Printer->jobid, &errcode );
6039 /********************************************************************
6040 * called by spoolss_api_setprinter
6041 * when updating a printer description
6042 ********************************************************************/
6044 static WERROR update_printer_sec(POLICY_HND *handle, uint32 level,
6045 const SPOOL_PRINTER_INFO_LEVEL *info,
6046 pipes_struct *p, SEC_DESC_BUF *secdesc_ctr)
6048 SEC_DESC_BUF *new_secdesc_ctr = NULL, *old_secdesc_ctr = NULL;
6052 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
6054 if (!Printer || !get_printer_snum(p, handle, &snum, NULL)) {
6055 DEBUG(2,("update_printer_sec: Invalid handle (%s:%u:%u)\n",
6056 OUR_HANDLE(handle)));
6058 result = WERR_BADFID;
6063 DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
6064 result = WERR_INVALID_PARAM;
6068 /* Check the user has permissions to change the security
6069 descriptor. By experimentation with two NT machines, the user
6070 requires Full Access to the printer to change security
6073 if ( Printer->access_granted != PRINTER_ACCESS_ADMINISTER ) {
6074 DEBUG(4,("update_printer_sec: updated denied by printer permissions\n"));
6075 result = WERR_ACCESS_DENIED;
6079 /* NT seems to like setting the security descriptor even though
6080 nothing may have actually changed. */
6082 nt_printing_getsec(p->mem_ctx, Printer->sharename, &old_secdesc_ctr);
6084 if (DEBUGLEVEL >= 10) {
6088 the_acl = old_secdesc_ctr->sd->dacl;
6089 DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
6090 PRINTERNAME(snum), the_acl->num_aces));
6092 for (i = 0; i < the_acl->num_aces; i++) {
6095 sid_to_string(sid_str, &the_acl->aces[i].trustee);
6097 DEBUG(10, ("%s 0x%08x\n", sid_str,
6098 the_acl->aces[i].access_mask));
6101 the_acl = secdesc_ctr->sd->dacl;
6104 DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
6105 PRINTERNAME(snum), the_acl->num_aces));
6107 for (i = 0; i < the_acl->num_aces; i++) {
6110 sid_to_string(sid_str, &the_acl->aces[i].trustee);
6112 DEBUG(10, ("%s 0x%08x\n", sid_str,
6113 the_acl->aces[i].access_mask));
6116 DEBUG(10, ("dacl for secdesc_ctr is NULL\n"));
6120 new_secdesc_ctr = sec_desc_merge(p->mem_ctx, secdesc_ctr, old_secdesc_ctr);
6121 if (!new_secdesc_ctr) {
6122 result = WERR_NOMEM;
6126 if (sec_desc_equal(new_secdesc_ctr->sd, old_secdesc_ctr->sd)) {
6131 result = nt_printing_setsec(Printer->sharename, new_secdesc_ctr);
6138 /********************************************************************
6139 Canonicalize printer info from a client
6141 ATTN: It does not matter what we set the servername to hear
6142 since we do the necessary work in get_a_printer() to set it to
6143 the correct value based on what the client sent in the
6144 _spoolss_open_printer_ex().
6145 ********************************************************************/
6147 static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum)
6149 fstring printername;
6152 DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
6153 "portname=%s drivername=%s comment=%s location=%s\n",
6154 info->servername, info->printername, info->sharename,
6155 info->portname, info->drivername, info->comment, info->location));
6157 /* we force some elements to "correct" values */
6158 slprintf(info->servername, sizeof(info->servername)-1, "\\\\%s", global_myname());
6159 fstrcpy(info->sharename, lp_servicename(snum));
6161 /* check to see if we allow printername != sharename */
6163 if ( lp_force_printername(snum) ) {
6164 slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s",
6165 global_myname(), info->sharename );
6168 /* make sure printername is in \\server\printername format */
6170 fstrcpy( printername, info->printername );
6172 if ( printername[0] == '\\' && printername[1] == '\\' ) {
6173 if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
6177 slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s",
6178 global_myname(), p );
6181 info->attributes |= PRINTER_ATTRIBUTE_SAMBA;
6182 info->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
6189 /****************************************************************************
6190 ****************************************************************************/
6192 WERROR add_port_hook(NT_USER_TOKEN *token, const char *portname, const char *uri )
6194 char *cmd = lp_addport_cmd();
6198 SE_PRIV se_printop = SE_PRINT_OPERATOR;
6199 BOOL is_print_op = False;
6202 return WERR_ACCESS_DENIED;
6205 slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\"", cmd, portname, uri );
6208 is_print_op = user_has_privileges( token, &se_printop );
6210 DEBUG(10,("Running [%s]\n", command));
6212 /********* BEGIN SePrintOperatorPrivilege **********/
6217 ret = smbrun(command, &fd);
6222 /********* END SePrintOperatorPrivilege **********/
6224 DEBUGADD(10,("returned [%d]\n", ret));
6229 return WERR_ACCESS_DENIED;
6235 /****************************************************************************
6236 ****************************************************************************/
6238 BOOL add_printer_hook(NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer)
6240 char *cmd = lp_addprinter_cmd();
6246 fstring remote_machine = "%m";
6247 SE_PRIV se_printop = SE_PRINT_OPERATOR;
6248 BOOL is_print_op = False;
6250 standard_sub_basic(current_user_info.smb_name,
6251 current_user_info.domain,
6252 remote_machine,sizeof(remote_machine));
6254 slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
6255 cmd, printer->info_2->printername, printer->info_2->sharename,
6256 printer->info_2->portname, printer->info_2->drivername,
6257 printer->info_2->location, printer->info_2->comment, remote_machine);
6260 is_print_op = user_has_privileges( token, &se_printop );
6262 DEBUG(10,("Running [%s]\n", command));
6264 /********* BEGIN SePrintOperatorPrivilege **********/
6269 if ( (ret = smbrun(command, &fd)) == 0 ) {
6270 /* Tell everyone we updated smb.conf. */
6271 message_send_all(smbd_messaging_context(),
6272 MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
6278 /********* END SePrintOperatorPrivilege **********/
6280 DEBUGADD(10,("returned [%d]\n", ret));
6288 /* reload our services immediately */
6289 reload_services( False );
6292 /* Get lines and convert them back to dos-codepage */
6293 qlines = fd_lines_load(fd, &numlines, 0);
6294 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
6297 /* Set the portname to what the script says the portname should be. */
6298 /* but don't require anything to be return from the script exit a good error code */
6301 /* Set the portname to what the script says the portname should be. */
6302 strncpy(printer->info_2->portname, qlines[0], sizeof(printer->info_2->portname));
6303 DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
6306 file_lines_free(qlines);
6311 /********************************************************************
6312 * Called by spoolss_api_setprinter
6313 * when updating a printer description.
6314 ********************************************************************/
6316 static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level,
6317 const SPOOL_PRINTER_INFO_LEVEL *info,
6318 DEVICEMODE *devmode)
6321 NT_PRINTER_INFO_LEVEL *printer = NULL, *old_printer = NULL;
6322 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
6327 DEBUG(8,("update_printer\n"));
6332 result = WERR_BADFID;
6336 if (!get_printer_snum(p, handle, &snum, NULL)) {
6337 result = WERR_BADFID;
6341 if (!W_ERROR_IS_OK(get_a_printer(Printer, &printer, 2, lp_const_servicename(snum))) ||
6342 (!W_ERROR_IS_OK(get_a_printer(Printer, &old_printer, 2, lp_const_servicename(snum))))) {
6343 result = WERR_BADFID;
6347 DEBUGADD(8,("Converting info_2 struct\n"));
6350 * convert_printer_info converts the incoming
6351 * info from the client and overwrites the info
6352 * just read from the tdb in the pointer 'printer'.
6355 if (!convert_printer_info(info, printer, level)) {
6356 result = WERR_NOMEM;
6361 /* we have a valid devmode
6362 convert it and link it*/
6364 DEBUGADD(8,("update_printer: Converting the devicemode struct\n"));
6365 if (!convert_devicemode(printer->info_2->printername, devmode,
6366 &printer->info_2->devmode)) {
6367 result = WERR_NOMEM;
6372 /* Do sanity check on the requested changes for Samba */
6374 if (!check_printer_ok(printer->info_2, snum)) {
6375 result = WERR_INVALID_PARAM;
6379 /* FIXME!!! If the driver has changed we really should verify that
6380 it is installed before doing much else --jerry */
6382 /* Check calling user has permission to update printer description */
6384 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
6385 DEBUG(3, ("update_printer: printer property change denied by handle\n"));
6386 result = WERR_ACCESS_DENIED;
6390 /* Call addprinter hook */
6391 /* Check changes to see if this is really needed */
6393 if ( *lp_addprinter_cmd()
6394 && (!strequal(printer->info_2->drivername, old_printer->info_2->drivername)
6395 || !strequal(printer->info_2->comment, old_printer->info_2->comment)
6396 || !strequal(printer->info_2->portname, old_printer->info_2->portname)
6397 || !strequal(printer->info_2->location, old_printer->info_2->location)) )
6399 /* add_printer_hook() will call reload_services() */
6401 if ( !add_printer_hook(p->pipe_user.nt_user_token, printer) ) {
6402 result = WERR_ACCESS_DENIED;
6408 * When a *new* driver is bound to a printer, the drivername is used to
6409 * lookup previously saved driver initialization info, which is then
6410 * bound to the printer, simulating what happens in the Windows arch.
6412 if (!strequal(printer->info_2->drivername, old_printer->info_2->drivername))
6414 if (!set_driver_init(printer, 2))
6416 DEBUG(5,("update_printer: Error restoring driver initialization data for driver [%s]!\n",
6417 printer->info_2->drivername));
6420 DEBUG(10,("update_printer: changing driver [%s]! Sending event!\n",
6421 printer->info_2->drivername));
6423 notify_printer_driver(snum, printer->info_2->drivername);
6427 * flag which changes actually occured. This is a small subset of
6428 * all the possible changes. We also have to update things in the
6432 if (!strequal(printer->info_2->comment, old_printer->info_2->comment)) {
6433 init_unistr2( &buffer, printer->info_2->comment, UNI_STR_TERMINATE);
6434 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "description",
6435 REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 );
6437 notify_printer_comment(snum, printer->info_2->comment);
6440 if (!strequal(printer->info_2->sharename, old_printer->info_2->sharename)) {
6441 init_unistr2( &buffer, printer->info_2->sharename, UNI_STR_TERMINATE);
6442 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "shareName",
6443 REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 );
6445 notify_printer_sharename(snum, printer->info_2->sharename);
6448 if (!strequal(printer->info_2->printername, old_printer->info_2->printername)) {
6451 if ( (pname = strchr_m( printer->info_2->printername+2, '\\' )) != NULL )
6454 pname = printer->info_2->printername;
6457 init_unistr2( &buffer, pname, UNI_STR_TERMINATE);
6458 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "printerName",
6459 REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 );
6461 notify_printer_printername( snum, pname );
6464 if (!strequal(printer->info_2->portname, old_printer->info_2->portname)) {
6465 init_unistr2( &buffer, printer->info_2->portname, UNI_STR_TERMINATE);
6466 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "portName",
6467 REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 );
6469 notify_printer_port(snum, printer->info_2->portname);
6472 if (!strequal(printer->info_2->location, old_printer->info_2->location)) {
6473 init_unistr2( &buffer, printer->info_2->location, UNI_STR_TERMINATE);
6474 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "location",
6475 REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 );
6477 notify_printer_location(snum, printer->info_2->location);
6480 /* here we need to update some more DsSpooler keys */
6481 /* uNCName, serverName, shortServerName */
6483 init_unistr2( &buffer, global_myname(), UNI_STR_TERMINATE);
6484 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "serverName",
6485 REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 );
6486 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "shortServerName",
6487 REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 );
6489 slprintf( asc_buffer, sizeof(asc_buffer)-1, "\\\\%s\\%s",
6490 global_myname(), printer->info_2->sharename );
6491 init_unistr2( &buffer, asc_buffer, UNI_STR_TERMINATE);
6492 set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "uNCName",
6493 REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 );
6495 /* Update printer info */
6496 result = mod_a_printer(printer, 2);
6499 free_a_printer(&printer, 2);
6500 free_a_printer(&old_printer, 2);
6506 /****************************************************************************
6507 ****************************************************************************/
6508 static WERROR publish_or_unpublish_printer(pipes_struct *p, POLICY_HND *handle,
6509 const SPOOL_PRINTER_INFO_LEVEL *info)
6512 SPOOL_PRINTER_INFO_LEVEL_7 *info7 = info->info_7;
6514 Printer_entry *Printer;
6516 if ( lp_security() != SEC_ADS ) {
6517 return WERR_UNKNOWN_LEVEL;
6520 Printer = find_printer_index_by_hnd(p, handle);
6522 DEBUG(5,("publish_or_unpublish_printer, action = %d\n",info7->action));
6527 if (!get_printer_snum(p, handle, &snum, NULL))
6530 nt_printer_publish(Printer, snum, info7->action);
6534 return WERR_UNKNOWN_LEVEL;
6537 /****************************************************************************
6538 ****************************************************************************/
6540 WERROR _spoolss_setprinter(pipes_struct *p, SPOOL_Q_SETPRINTER *q_u, SPOOL_R_SETPRINTER *r_u)
6542 POLICY_HND *handle = &q_u->handle;
6543 uint32 level = q_u->level;
6544 SPOOL_PRINTER_INFO_LEVEL *info = &q_u->info;
6545 DEVMODE_CTR devmode_ctr = q_u->devmode_ctr;
6546 SEC_DESC_BUF *secdesc_ctr = q_u->secdesc_ctr;
6547 uint32 command = q_u->command;
6550 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
6553 DEBUG(2,("_spoolss_setprinter: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(handle)));
6557 /* check the level */
6560 return control_printer(handle, command, p);
6562 result = update_printer(p, handle, level, info, devmode_ctr.devmode);
6563 if (!W_ERROR_IS_OK(result))
6566 result = update_printer_sec(handle, level, info, p, secdesc_ctr);
6569 return update_printer_sec(handle, level, info, p,
6572 return publish_or_unpublish_printer(p, handle, info);
6574 return WERR_UNKNOWN_LEVEL;
6578 /****************************************************************************
6579 ****************************************************************************/
6581 WERROR _spoolss_fcpn(pipes_struct *p, SPOOL_Q_FCPN *q_u, SPOOL_R_FCPN *r_u)
6583 POLICY_HND *handle = &q_u->handle;
6584 Printer_entry *Printer= find_printer_index_by_hnd(p, handle);
6587 DEBUG(2,("_spoolss_fcpn: Invalid handle (%s:%u:%u)\n", OUR_HANDLE(handle)));
6591 if (Printer->notify.client_connected==True) {
6594 if ( Printer->printer_type == SPLHND_SERVER)
6596 else if ( (Printer->printer_type == SPLHND_PRINTER) &&
6597 !get_printer_snum(p, handle, &snum, NULL) )
6600 srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd);
6603 Printer->notify.flags=0;
6604 Printer->notify.options=0;
6605 Printer->notify.localmachine[0]='\0';
6606 Printer->notify.printerlocal=0;
6607 if (Printer->notify.option)
6608 free_spool_notify_option(&Printer->notify.option);
6609 Printer->notify.client_connected=False;
6614 /****************************************************************************
6615 ****************************************************************************/
6617 WERROR _spoolss_addjob(pipes_struct *p, SPOOL_Q_ADDJOB *q_u, SPOOL_R_ADDJOB *r_u)
6619 /* that's an [in out] buffer */
6621 if (!q_u->buffer && (q_u->offered!=0)) {
6622 return WERR_INVALID_PARAM;
6625 rpcbuf_move(q_u->buffer, &r_u->buffer);
6628 return WERR_INVALID_PARAM; /* this is what a NT server
6629 returns for AddJob. AddJob
6630 must fail on non-local
6634 /****************************************************************************
6635 ****************************************************************************/
6637 static void fill_job_info_1(JOB_INFO_1 *job_info, const print_queue_struct *queue,
6638 int position, int snum,
6639 const NT_PRINTER_INFO_LEVEL *ntprinter)
6643 t=gmtime(&queue->time);
6645 job_info->jobid=queue->job;
6646 init_unistr(&job_info->printername, lp_servicename(snum));
6647 init_unistr(&job_info->machinename, ntprinter->info_2->servername);
6648 init_unistr(&job_info->username, queue->fs_user);
6649 init_unistr(&job_info->document, queue->fs_file);
6650 init_unistr(&job_info->datatype, "RAW");
6651 init_unistr(&job_info->text_status, "");
6652 job_info->status=nt_printj_status(queue->status);
6653 job_info->priority=queue->priority;
6654 job_info->position=position;
6655 job_info->totalpages=queue->page_count;
6656 job_info->pagesprinted=0;
6658 make_systemtime(&job_info->submitted, t);
6661 /****************************************************************************
6662 ****************************************************************************/
6664 static BOOL fill_job_info_2(JOB_INFO_2 *job_info, const print_queue_struct *queue,
6665 int position, int snum,
6666 const NT_PRINTER_INFO_LEVEL *ntprinter,
6667 DEVICEMODE *devmode)
6671 t=gmtime(&queue->time);
6673 job_info->jobid=queue->job;
6675 init_unistr(&job_info->printername, ntprinter->info_2->printername);
6677 init_unistr(&job_info->machinename, ntprinter->info_2->servername);
6678 init_unistr(&job_info->username, queue->fs_user);
6679 init_unistr(&job_info->document, queue->fs_file);
6680 init_unistr(&job_info->notifyname, queue->fs_user);
6681 init_unistr(&job_info->datatype, "RAW");
6682 init_unistr(&job_info->printprocessor, "winprint");
6683 init_unistr(&job_info->parameters, "");
6684 init_unistr(&job_info->drivername, ntprinter->info_2->drivername);
6685 init_unistr(&job_info->text_status, "");
6687 /* and here the security descriptor */
6689 job_info->status=nt_printj_status(queue->status);
6690 job_info->priority=queue->priority;
6691 job_info->position=position;
6692 job_info->starttime=0;
6693 job_info->untiltime=0;
6694 job_info->totalpages=queue->page_count;
6695 job_info->size=queue->size;
6696 make_systemtime(&(job_info->submitted), t);
6697 job_info->timeelapsed=0;
6698 job_info->pagesprinted=0;
6700 job_info->devmode = devmode;
6705 /****************************************************************************
6706 Enumjobs at level 1.
6707 ****************************************************************************/
6709 static WERROR enumjobs_level1(const print_queue_struct *queue, int snum,
6710 const NT_PRINTER_INFO_LEVEL *ntprinter,
6711 RPC_BUFFER *buffer, uint32 offered,
6712 uint32 *needed, uint32 *returned)
6716 WERROR result = WERR_OK;
6718 info=SMB_MALLOC_ARRAY(JOB_INFO_1,*returned);
6724 for (i=0; i<*returned; i++)
6725 fill_job_info_1( &info[i], &queue[i], i, snum, ntprinter );
6727 /* check the required size. */
6728 for (i=0; i<*returned; i++)
6729 (*needed) += spoolss_size_job_info_1(&info[i]);
6731 if (*needed > offered) {
6732 result = WERR_INSUFFICIENT_BUFFER;
6736 if (!rpcbuf_alloc_size(buffer, *needed)) {
6737 result = WERR_NOMEM;
6741 /* fill the buffer with the structures */
6742 for (i=0; i<*returned; i++)
6743 smb_io_job_info_1("", buffer, &info[i], 0);
6749 if ( !W_ERROR_IS_OK(result) )
6755 /****************************************************************************
6756 Enumjobs at level 2.
6757 ****************************************************************************/
6759 static WERROR enumjobs_level2(const print_queue_struct *queue, int snum,
6760 const NT_PRINTER_INFO_LEVEL *ntprinter,
6761 RPC_BUFFER *buffer, uint32 offered,
6762 uint32 *needed, uint32 *returned)
6764 JOB_INFO_2 *info = NULL;
6766 WERROR result = WERR_OK;
6767 DEVICEMODE *devmode = NULL;
6769 if ( !(info = SMB_MALLOC_ARRAY(JOB_INFO_2,*returned)) ) {
6774 /* this should not be a failure condition if the devmode is NULL */
6776 devmode = construct_dev_mode(lp_const_servicename(snum));
6778 for (i=0; i<*returned; i++)
6779 fill_job_info_2(&(info[i]), &queue[i], i, snum, ntprinter, devmode);
6781 /* check the required size. */
6782 for (i=0; i<*returned; i++)
6783 (*needed) += spoolss_size_job_info_2(&info[i]);
6785 if (*needed > offered) {
6786 result = WERR_INSUFFICIENT_BUFFER;
6790 if (!rpcbuf_alloc_size(buffer, *needed)) {
6791 result = WERR_NOMEM;
6795 /* fill the buffer with the structures */
6796 for (i=0; i<*returned; i++)
6797 smb_io_job_info_2("", buffer, &info[i], 0);
6800 free_devmode(devmode);
6803 if ( !W_ERROR_IS_OK(result) )
6810 /****************************************************************************
6812 ****************************************************************************/
6814 WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJOBS *r_u)
6816 POLICY_HND *handle = &q_u->handle;
6817 uint32 level = q_u->level;
6818 RPC_BUFFER *buffer = NULL;
6819 uint32 offered = q_u->offered;
6820 uint32 *needed = &r_u->needed;
6821 uint32 *returned = &r_u->returned;
6823 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
6825 print_status_struct prt_status;
6826 print_queue_struct *queue=NULL;
6828 /* that's an [in out] buffer */
6830 if (!q_u->buffer && (offered!=0)) {
6831 return WERR_INVALID_PARAM;
6834 rpcbuf_move(q_u->buffer, &r_u->buffer);
6835 buffer = r_u->buffer;
6837 DEBUG(4,("_spoolss_enumjobs\n"));
6842 /* lookup the printer snum and tdb entry */
6844 if (!get_printer_snum(p, handle, &snum, NULL))
6847 wret = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum));
6848 if ( !W_ERROR_IS_OK(wret) )
6851 *returned = print_queue_status(snum, &queue, &prt_status);
6852 DEBUGADD(4,("count:[%d], status:[%d], [%s]\n", *returned, prt_status.status, prt_status.message));
6854 if (*returned == 0) {
6856 free_a_printer(&ntprinter, 2);
6862 wret = enumjobs_level1(queue, snum, ntprinter, buffer, offered, needed, returned);
6865 wret = enumjobs_level2(queue, snum, ntprinter, buffer, offered, needed, returned);
6869 wret = WERR_UNKNOWN_LEVEL;
6874 free_a_printer( &ntprinter, 2 );
6878 /****************************************************************************
6879 ****************************************************************************/
6881 WERROR _spoolss_schedulejob( pipes_struct *p, SPOOL_Q_SCHEDULEJOB *q_u, SPOOL_R_SCHEDULEJOB *r_u)
6886 /****************************************************************************
6887 ****************************************************************************/
6889 WERROR _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r_u)
6891 POLICY_HND *handle = &q_u->handle;
6892 uint32 jobid = q_u->jobid;
6893 uint32 command = q_u->command;
6896 WERROR errcode = WERR_BADFUNC;
6898 if (!get_printer_snum(p, handle, &snum, NULL)) {
6902 if (!print_job_exists(lp_const_servicename(snum), jobid)) {
6903 return WERR_INVALID_PRINTER_NAME;
6907 case JOB_CONTROL_CANCEL:
6908 case JOB_CONTROL_DELETE:
6909 if (print_job_delete(&p->pipe_user, snum, jobid, &errcode)) {
6913 case JOB_CONTROL_PAUSE:
6914 if (print_job_pause(&p->pipe_user, snum, jobid, &errcode)) {
6918 case JOB_CONTROL_RESTART:
6919 case JOB_CONTROL_RESUME:
6920 if (print_job_resume(&p->pipe_user, snum, jobid, &errcode)) {
6925 return WERR_UNKNOWN_LEVEL;
6931 /****************************************************************************
6932 Enumerates all printer drivers at level 1.
6933 ****************************************************************************/
6935 static WERROR enumprinterdrivers_level1(fstring servername, fstring architecture, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
6940 fstring *list = NULL;
6941 NT_PRINTER_DRIVER_INFO_LEVEL driver;
6942 DRIVER_INFO_1 *driver_info_1=NULL;
6943 WERROR result = WERR_OK;
6947 for (version=0; version<DRIVER_MAX_VERSION; version++) {
6949 ndrivers=get_ntdrivers(&list, architecture, version);
6950 DEBUGADD(4,("we have:[%d] drivers in environment [%s] and version [%d]\n", ndrivers, architecture, version));
6952 if(ndrivers == -1) {
6953 SAFE_FREE(driver_info_1);
6958 if((driver_info_1=SMB_REALLOC_ARRAY(driver_info_1, DRIVER_INFO_1, *returned+ndrivers )) == NULL) {
6959 DEBUG(0,("enumprinterdrivers_level1: failed to enlarge driver info buffer!\n"));
6965 for (i=0; i<ndrivers; i++) {
6967 DEBUGADD(5,("\tdriver: [%s]\n", list[i]));
6968 ZERO_STRUCT(driver);
6969 status = get_a_printer_driver(&driver, 3, list[i],
6970 architecture, version);
6971 if (!W_ERROR_IS_OK(status)) {
6973 SAFE_FREE(driver_info_1);
6976 fill_printer_driver_info_1(&driver_info_1[*returned+i], driver, servername, architecture );
6977 free_a_printer_driver(driver, 3);
6980 *returned+=ndrivers;
6984 /* check the required size. */
6985 for (i=0; i<*returned; i++) {
6986 DEBUGADD(6,("adding driver [%d]'s size\n",i));
6987 *needed += spoolss_size_printer_driver_info_1(&driver_info_1[i]);
6990 if (*needed > offered) {
6991 result = WERR_INSUFFICIENT_BUFFER;
6995 if (!rpcbuf_alloc_size(buffer, *needed)) {
6996 result = WERR_NOMEM;
7000 /* fill the buffer with the driver structures */
7001 for (i=0; i<*returned; i++) {
7002 DEBUGADD(6,("adding driver [%d] to buffer\n",i));
7003 smb_io_printer_driver_info_1("", buffer, &driver_info_1[i], 0);
7007 SAFE_FREE(driver_info_1);
7009 if ( !W_ERROR_IS_OK(result) )
7015 /****************************************************************************
7016 Enumerates all printer drivers at level 2.
7017 ****************************************************************************/
7019 static WERROR enumprinterdrivers_level2(fstring servername, fstring architecture, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
7024 fstring *list = NULL;
7025 NT_PRINTER_DRIVER_INFO_LEVEL driver;
7026 DRIVER_INFO_2 *driver_info_2=NULL;
7027 WERROR result = WERR_OK;
7031 for (version=0; version<DRIVER_MAX_VERSION; version++) {
7033 ndrivers=get_ntdrivers(&list, architecture, version);
7034 DEBUGADD(4,("we have:[%d] drivers in environment [%s] and version [%d]\n", ndrivers, architecture, version));
7036 if(ndrivers == -1) {
7037 SAFE_FREE(driver_info_2);
7042 if((driver_info_2=SMB_REALLOC_ARRAY(driver_info_2, DRIVER_INFO_2, *returned+ndrivers )) == NULL) {
7043 DEBUG(0,("enumprinterdrivers_level2: failed to enlarge driver info buffer!\n"));
7049 for (i=0; i<ndrivers; i++) {
7052 DEBUGADD(5,("\tdriver: [%s]\n", list[i]));
7053 ZERO_STRUCT(driver);
7054 status = get_a_printer_driver(&driver, 3, list[i],
7055 architecture, version);
7056 if (!W_ERROR_IS_OK(status)) {
7058 SAFE_FREE(driver_info_2);
7061 fill_printer_driver_info_2(&driver_info_2[*returned+i], driver, servername);
7062 free_a_printer_driver(driver, 3);
7065 *returned+=ndrivers;
7069 /* check the required size. */
7070 for (i=0; i<*returned; i++) {
7071 DEBUGADD(6,("adding driver [%d]'s size\n",i));
7072 *needed += spoolss_size_printer_driver_info_2(&(driver_info_2[i]));
7075 if (*needed > offered) {
7076 result = WERR_INSUFFICIENT_BUFFER;
7080 if (!rpcbuf_alloc_size(buffer, *needed)) {
7081 result = WERR_NOMEM;
7085 /* fill the buffer with the form structures */
7086 for (i=0; i<*returned; i++) {
7087 DEBUGADD(6,("adding driver [%d] to buffer\n",i));
7088 smb_io_printer_driver_info_2("", buffer, &(driver_info_2[i]), 0);
7092 SAFE_FREE(driver_info_2);
7094 if ( !W_ERROR_IS_OK(result) )
7100 /****************************************************************************
7101 Enumerates all printer drivers at level 3.
7102 ****************************************************************************/
7104 static WERROR enumprinterdrivers_level3(fstring servername, fstring architecture, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
7109 fstring *list = NULL;
7110 DRIVER_INFO_3 *driver_info_3=NULL;
7111 NT_PRINTER_DRIVER_INFO_LEVEL driver;
7112 WERROR result = WERR_OK;
7116 for (version=0; version<DRIVER_MAX_VERSION; version++) {
7118 ndrivers=get_ntdrivers(&list, architecture, version);
7119 DEBUGADD(4,("we have:[%d] drivers in environment [%s] and version [%d]\n", ndrivers, architecture, version));
7121 if(ndrivers == -1) {
7122 SAFE_FREE(driver_info_3);
7127 if((driver_info_3=SMB_REALLOC_ARRAY(driver_info_3, DRIVER_INFO_3, *returned+ndrivers )) == NULL) {
7128 DEBUG(0,("enumprinterdrivers_level3: failed to enlarge driver info buffer!\n"));
7134 for (i=0; i<ndrivers; i++) {
7137 DEBUGADD(5,("\tdriver: [%s]\n", list[i]));
7138 ZERO_STRUCT(driver);
7139 status = get_a_printer_driver(&driver, 3, list[i],
7140 architecture, version);
7141 if (!W_ERROR_IS_OK(status)) {
7143 SAFE_FREE(driver_info_3);
7146 fill_printer_driver_info_3(&driver_info_3[*returned+i], driver, servername);
7147 free_a_printer_driver(driver, 3);
7150 *returned+=ndrivers;
7154 /* check the required size. */
7155 for (i=0; i<*returned; i++) {
7156 DEBUGADD(6,("adding driver [%d]'s size\n",i));
7157 *needed += spoolss_size_printer_driver_info_3(&driver_info_3[i]);
7160 if (*needed > offered) {
7161 result = WERR_INSUFFICIENT_BUFFER;
7165 if (!rpcbuf_alloc_size(buffer, *needed)) {
7166 result = WERR_NOMEM;
7170 /* fill the buffer with the driver structures */
7171 for (i=0; i<*returned; i++) {
7172 DEBUGADD(6,("adding driver [%d] to buffer\n",i));
7173 smb_io_printer_driver_info_3("", buffer, &driver_info_3[i], 0);
7177 for (i=0; i<*returned; i++) {
7178 SAFE_FREE(driver_info_3[i].dependentfiles);
7181 SAFE_FREE(driver_info_3);
7183 if ( !W_ERROR_IS_OK(result) )
7189 /****************************************************************************
7190 Enumerates all printer drivers.
7191 ****************************************************************************/
7193 WERROR _spoolss_enumprinterdrivers( pipes_struct *p, SPOOL_Q_ENUMPRINTERDRIVERS *q_u, SPOOL_R_ENUMPRINTERDRIVERS *r_u)
7195 uint32 level = q_u->level;
7196 RPC_BUFFER *buffer = NULL;
7197 uint32 offered = q_u->offered;
7198 uint32 *needed = &r_u->needed;
7199 uint32 *returned = &r_u->returned;
7202 fstring architecture;
7204 /* that's an [in out] buffer */
7206 if (!q_u->buffer && (offered!=0)) {
7207 return WERR_INVALID_PARAM;
7210 rpcbuf_move(q_u->buffer, &r_u->buffer);
7211 buffer = r_u->buffer;
7213 DEBUG(4,("_spoolss_enumprinterdrivers\n"));
7218 unistr2_to_ascii(architecture, &q_u->environment, sizeof(architecture)-1);
7219 unistr2_to_ascii(servername, &q_u->name, sizeof(servername)-1);
7221 if ( !is_myname_or_ipaddr( servername ) )
7222 return WERR_UNKNOWN_PRINTER_DRIVER;
7226 return enumprinterdrivers_level1(servername, architecture, buffer, offered, needed, returned);
7228 return enumprinterdrivers_level2(servername, architecture, buffer, offered, needed, returned);
7230 return enumprinterdrivers_level3(servername, architecture, buffer, offered, needed, returned);
7232 return WERR_UNKNOWN_LEVEL;
7236 /****************************************************************************
7237 ****************************************************************************/
7239 static void fill_form_1(FORM_1 *form, nt_forms_struct *list)
7241 form->flag=list->flag;
7242 init_unistr(&form->name, list->name);
7243 form->width=list->width;
7244 form->length=list->length;
7245 form->left=list->left;
7246 form->top=list->top;
7247 form->right=list->right;
7248 form->bottom=list->bottom;
7251 /****************************************************************************
7252 ****************************************************************************/
7254 WERROR _spoolss_enumforms(pipes_struct *p, SPOOL_Q_ENUMFORMS *q_u, SPOOL_R_ENUMFORMS *r_u)
7256 uint32 level = q_u->level;
7257 RPC_BUFFER *buffer = NULL;
7258 uint32 offered = q_u->offered;
7259 uint32 *needed = &r_u->needed;
7260 uint32 *numofforms = &r_u->numofforms;
7261 uint32 numbuiltinforms;
7263 nt_forms_struct *list=NULL;
7264 nt_forms_struct *builtinlist=NULL;
7269 /* that's an [in out] buffer */
7271 if (!q_u->buffer && (offered!=0) ) {
7272 return WERR_INVALID_PARAM;
7275 rpcbuf_move(q_u->buffer, &r_u->buffer);
7276 buffer = r_u->buffer;
7278 DEBUG(4,("_spoolss_enumforms\n"));
7279 DEBUGADD(5,("Offered buffer size [%d]\n", offered));
7280 DEBUGADD(5,("Info level [%d]\n", level));
7282 numbuiltinforms = get_builtin_ntforms(&builtinlist);
7283 DEBUGADD(5,("Number of builtin forms [%d]\n", numbuiltinforms));
7284 *numofforms = get_ntforms(&list);
7285 DEBUGADD(5,("Number of user forms [%d]\n", *numofforms));
7286 *numofforms += numbuiltinforms;
7288 if (*numofforms == 0) {
7289 SAFE_FREE(builtinlist);
7291 return WERR_NO_MORE_ITEMS;
7296 if ((forms_1=SMB_MALLOC_ARRAY(FORM_1, *numofforms)) == NULL) {
7297 SAFE_FREE(builtinlist);
7303 /* construct the list of form structures */
7304 for (i=0; i<numbuiltinforms; i++) {
7305 DEBUGADD(6,("Filling form number [%d]\n",i));
7306 fill_form_1(&forms_1[i], &builtinlist[i]);
7309 SAFE_FREE(builtinlist);
7311 for (; i<*numofforms; i++) {
7312 DEBUGADD(6,("Filling form number [%d]\n",i));
7313 fill_form_1(&forms_1[i], &list[i-numbuiltinforms]);
7318 /* check the required size. */
7319 for (i=0; i<numbuiltinforms; i++) {
7320 DEBUGADD(6,("adding form [%d]'s size\n",i));
7321 buffer_size += spoolss_size_form_1(&forms_1[i]);
7323 for (; i<*numofforms; i++) {
7324 DEBUGADD(6,("adding form [%d]'s size\n",i));
7325 buffer_size += spoolss_size_form_1(&forms_1[i]);
7328 *needed=buffer_size;
7330 if (*needed > offered) {
7333 return WERR_INSUFFICIENT_BUFFER;
7336 if (!rpcbuf_alloc_size(buffer, buffer_size)){
7342 /* fill the buffer with the form structures */
7343 for (i=0; i<numbuiltinforms; i++) {
7344 DEBUGADD(6,("adding form [%d] to buffer\n",i));
7345 smb_io_form_1("", buffer, &forms_1[i], 0);
7347 for (; i<*numofforms; i++) {
7348 DEBUGADD(6,("adding form [%d] to buffer\n",i));
7349 smb_io_form_1("", buffer, &forms_1[i], 0);
7358 SAFE_FREE(builtinlist);
7359 return WERR_UNKNOWN_LEVEL;
7363 /****************************************************************************
7364 ****************************************************************************/
7366 WERROR _spoolss_getform(pipes_struct *p, SPOOL_Q_GETFORM *q_u, SPOOL_R_GETFORM *r_u)
7368 uint32 level = q_u->level;
7369 UNISTR2 *uni_formname = &q_u->formname;
7370 RPC_BUFFER *buffer = NULL;
7371 uint32 offered = q_u->offered;
7372 uint32 *needed = &r_u->needed;
7374 nt_forms_struct *list=NULL;
7375 nt_forms_struct builtin_form;
7380 int numofforms=0, i=0;
7382 /* that's an [in out] buffer */
7384 if (!q_u->buffer && (offered!=0)) {
7385 return WERR_INVALID_PARAM;
7388 rpcbuf_move(q_u->buffer, &r_u->buffer);
7389 buffer = r_u->buffer;
7391 unistr2_to_ascii(form_name, uni_formname, sizeof(form_name)-1);
7393 DEBUG(4,("_spoolss_getform\n"));
7394 DEBUGADD(5,("Offered buffer size [%d]\n", offered));
7395 DEBUGADD(5,("Info level [%d]\n", level));
7397 foundBuiltin = get_a_builtin_ntform(uni_formname,&builtin_form);
7398 if (!foundBuiltin) {
7399 numofforms = get_ntforms(&list);
7400 DEBUGADD(5,("Number of forms [%d]\n", numofforms));
7402 if (numofforms == 0)
7409 fill_form_1(&form_1, &builtin_form);
7412 /* Check if the requested name is in the list of form structures */
7413 for (i=0; i<numofforms; i++) {
7415 DEBUG(4,("_spoolss_getform: checking form %s (want %s)\n", list[i].name, form_name));
7417 if (strequal(form_name, list[i].name)) {
7418 DEBUGADD(6,("Found form %s number [%d]\n", form_name, i));
7419 fill_form_1(&form_1, &list[i]);
7425 if (i == numofforms) {
7429 /* check the required size. */
7431 *needed=spoolss_size_form_1(&form_1);
7433 if (*needed > offered)
7434 return WERR_INSUFFICIENT_BUFFER;
7436 if (!rpcbuf_alloc_size(buffer, buffer_size))
7439 /* fill the buffer with the form structures */
7440 DEBUGADD(6,("adding form %s [%d] to buffer\n", form_name, i));
7441 smb_io_form_1("", buffer, &form_1, 0);
7447 return WERR_UNKNOWN_LEVEL;
7451 /****************************************************************************
7452 ****************************************************************************/
7454 static void fill_port_1(PORT_INFO_1 *port, const char *name)
7456 init_unistr(&port->port_name, name);
7459 /****************************************************************************
7460 TODO: This probably needs distinguish between TCP/IP and Local ports
7462 ****************************************************************************/
7464 static void fill_port_2(PORT_INFO_2 *port, const char *name)
7466 init_unistr(&port->port_name, name);
7467 init_unistr(&port->monitor_name, "Local Monitor");
7468 init_unistr(&port->description, SPL_LOCAL_PORT );
7469 port->port_type=PORT_TYPE_WRITE;
7474 /****************************************************************************
7475 wrapper around the enumer ports command
7476 ****************************************************************************/
7478 WERROR enumports_hook( int *count, char ***lines )
7480 char *cmd = lp_enumports_cmd();
7490 /* if no hook then just fill in the default port */
7493 if (!(qlines = SMB_MALLOC_ARRAY( char*, 2 ))) {
7496 if (!(qlines[0] = SMB_STRDUP( SAMBA_PRINTER_PORT_NAME ))) {
7504 /* we have a valid enumport command */
7506 slprintf(command, sizeof(command)-1, "%s \"%d\"", cmd, 1);
7508 DEBUG(10,("Running [%s]\n", command));
7509 ret = smbrun(command, &fd);
7510 DEBUG(10,("Returned [%d]\n", ret));
7515 return WERR_ACCESS_DENIED;
7519 qlines = fd_lines_load(fd, &numlines, 0);
7520 DEBUGADD(10,("Lines returned = [%d]\n", numlines));
7530 /****************************************************************************
7532 ****************************************************************************/
7534 static WERROR enumports_level_1(RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
7536 PORT_INFO_1 *ports=NULL;
7538 WERROR result = WERR_OK;
7539 char **qlines = NULL;
7542 result = enumports_hook( &numlines, &qlines );
7543 if (!W_ERROR_IS_OK(result)) {
7544 file_lines_free(qlines);
7549 if((ports=SMB_MALLOC_ARRAY( PORT_INFO_1, numlines )) == NULL) {
7550 DEBUG(10,("Returning WERR_NOMEM [%s]\n",
7551 dos_errstr(WERR_NOMEM)));
7552 file_lines_free(qlines);
7556 for (i=0; i<numlines; i++) {
7557 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7558 fill_port_1(&ports[i], qlines[i]);
7561 file_lines_free(qlines);
7563 *returned = numlines;
7565 /* check the required size. */
7566 for (i=0; i<*returned; i++) {
7567 DEBUGADD(6,("adding port [%d]'s size\n", i));
7568 *needed += spoolss_size_port_info_1(&ports[i]);
7571 if (*needed > offered) {
7572 result = WERR_INSUFFICIENT_BUFFER;
7576 if (!rpcbuf_alloc_size(buffer, *needed)) {
7577 result = WERR_NOMEM;
7581 /* fill the buffer with the ports structures */
7582 for (i=0; i<*returned; i++) {
7583 DEBUGADD(6,("adding port [%d] to buffer\n", i));
7584 smb_io_port_1("", buffer, &ports[i], 0);
7590 if ( !W_ERROR_IS_OK(result) )
7596 /****************************************************************************
7598 ****************************************************************************/
7600 static WERROR enumports_level_2(RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
7602 PORT_INFO_2 *ports=NULL;
7604 WERROR result = WERR_OK;
7605 char **qlines = NULL;
7608 result = enumports_hook( &numlines, &qlines );
7609 if ( !W_ERROR_IS_OK(result)) {
7610 file_lines_free(qlines);
7615 if((ports=SMB_MALLOC_ARRAY( PORT_INFO_2, numlines)) == NULL) {
7616 file_lines_free(qlines);
7620 for (i=0; i<numlines; i++) {
7621 DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
7622 fill_port_2(&(ports[i]), qlines[i]);
7626 file_lines_free(qlines);
7628 *returned = numlines;
7630 /* check the required size. */
7631 for (i=0; i<*returned; i++) {
7632 DEBUGADD(6,("adding port [%d]'s size\n", i));
7633 *needed += spoolss_size_port_info_2(&ports[i]);
7636 if (*needed > offered) {
7637 result = WERR_INSUFFICIENT_BUFFER;
7641 if (!rpcbuf_alloc_size(buffer, *needed)) {
7642 result = WERR_NOMEM;
7646 /* fill the buffer with the ports structures */
7647 for (i=0; i<*returned; i++) {
7648 DEBUGADD(6,("adding port [%d] to buffer\n", i));
7649 smb_io_port_2("", buffer, &ports[i], 0);
7655 if ( !W_ERROR_IS_OK(result) )
7661 /****************************************************************************
7663 ****************************************************************************/
7665 WERROR _spoolss_enumports( pipes_struct *p, SPOOL_Q_ENUMPORTS *q_u, SPOOL_R_ENUMPORTS *r_u)
7667 uint32 level = q_u->level;
7668 RPC_BUFFER *buffer = NULL;
7669 uint32 offered = q_u->offered;
7670 uint32 *needed = &r_u->needed;
7671 uint32 *returned = &r_u->returned;
7673 /* that's an [in out] buffer */
7675 if (!q_u->buffer && (offered!=0)) {
7676 return WERR_INVALID_PARAM;
7679 rpcbuf_move(q_u->buffer, &r_u->buffer);
7680 buffer = r_u->buffer;
7682 DEBUG(4,("_spoolss_enumports\n"));
7689 return enumports_level_1(buffer, offered, needed, returned);
7691 return enumports_level_2(buffer, offered, needed, returned);
7693 return WERR_UNKNOWN_LEVEL;
7697 /****************************************************************************
7698 ****************************************************************************/
7700 static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_srv_name,
7701 const SPOOL_PRINTER_INFO_LEVEL *info,
7702 DEVICEMODE *devmode, SEC_DESC_BUF *sec_desc_buf,
7703 uint32 user_switch, const SPOOL_USER_CTR *user,
7706 NT_PRINTER_INFO_LEVEL *printer = NULL;
7709 WERROR err = WERR_OK;
7711 if ( !(printer = TALLOC_ZERO_P(NULL, NT_PRINTER_INFO_LEVEL)) ) {
7712 DEBUG(0,("spoolss_addprinterex_level_2: malloc fail.\n"));
7716 /* convert from UNICODE to ASCII - this allocates the info_2 struct inside *printer.*/
7717 if (!convert_printer_info(info, printer, 2)) {
7718 free_a_printer(&printer, 2);
7722 /* check to see if the printer already exists */
7724 if ((snum = print_queue_snum(printer->info_2->sharename)) != -1) {
7725 DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
7726 printer->info_2->sharename));
7727 free_a_printer(&printer, 2);
7728 return WERR_PRINTER_ALREADY_EXISTS;
7731 /* FIXME!!! smbd should check to see if the driver is installed before
7732 trying to add a printer like this --jerry */
7734 if (*lp_addprinter_cmd() ) {
7735 if ( !add_printer_hook(p->pipe_user.nt_user_token, printer) ) {
7736 free_a_printer(&printer,2);
7737 return WERR_ACCESS_DENIED;
7740 DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no"
7741 "smb.conf parameter \"addprinter command\" is defined. This"
7742 "parameter must exist for this call to succeed\n",
7743 printer->info_2->sharename ));
7746 /* use our primary netbios name since get_a_printer() will convert
7747 it to what the client expects on a case by case basis */
7749 slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname(),
7750 printer->info_2->sharename);
7753 if ((snum = print_queue_snum(printer->info_2->sharename)) == -1) {
7754 free_a_printer(&printer,2);
7755 return WERR_ACCESS_DENIED;
7758 /* you must be a printer admin to add a new printer */
7759 if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) {
7760 free_a_printer(&printer,2);
7761 return WERR_ACCESS_DENIED;
7765 * Do sanity check on the requested changes for Samba.
7768 if (!check_printer_ok(printer->info_2, snum)) {
7769 free_a_printer(&printer,2);
7770 return WERR_INVALID_PARAM;
7774 * When a printer is created, the drivername bound to the printer is used
7775 * to lookup previously saved driver initialization info, which is then
7776 * bound to the new printer, simulating what happens in the Windows arch.
7781 set_driver_init(printer, 2);
7785 /* A valid devmode was included, convert and link it
7787 DEBUGADD(10, ("spoolss_addprinterex_level_2: devmode included, converting\n"));
7789 if (!convert_devicemode(printer->info_2->printername, devmode,
7790 &printer->info_2->devmode))
7794 /* write the ASCII on disk */
7795 err = mod_a_printer(printer, 2);
7796 if (!W_ERROR_IS_OK(err)) {
7797 free_a_printer(&printer,2);
7801 if (!open_printer_hnd(p, handle, name, PRINTER_ACCESS_ADMINISTER)) {
7802 /* Handle open failed - remove addition. */
7803 del_a_printer(printer->info_2->sharename);
7804 free_a_printer(&printer,2);
7805 return WERR_ACCESS_DENIED;
7808 update_c_setprinter(False);
7809 free_a_printer(&printer,2);
7814 /****************************************************************************
7815 ****************************************************************************/
7817 WERROR _spoolss_addprinterex( pipes_struct *p, SPOOL_Q_ADDPRINTEREX *q_u, SPOOL_R_ADDPRINTEREX *r_u)
7819 UNISTR2 *uni_srv_name = q_u->server_name;
7820 uint32 level = q_u->level;
7821 SPOOL_PRINTER_INFO_LEVEL *info = &q_u->info;
7822 DEVICEMODE *devmode = q_u->devmode_ctr.devmode;
7823 SEC_DESC_BUF *sdb = q_u->secdesc_ctr;
7824 uint32 user_switch = q_u->user_switch;
7825 SPOOL_USER_CTR *user = &q_u->user_ctr;
7826 POLICY_HND *handle = &r_u->handle;
7830 /* we don't handle yet */
7831 /* but I know what to do ... */
7832 return WERR_UNKNOWN_LEVEL;
7834 return spoolss_addprinterex_level_2(p, uni_srv_name, info,
7836 user_switch, user, handle);
7838 return WERR_UNKNOWN_LEVEL;
7842 /****************************************************************************
7843 ****************************************************************************/
7845 WERROR _spoolss_addprinterdriver(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVER *q_u, SPOOL_R_ADDPRINTERDRIVER *r_u)
7847 uint32 level = q_u->level;
7848 SPOOL_PRINTER_DRIVER_INFO_LEVEL *info = &q_u->info;
7849 WERROR err = WERR_OK;
7850 NT_PRINTER_DRIVER_INFO_LEVEL driver;
7851 fstring driver_name;
7854 ZERO_STRUCT(driver);
7856 if (!convert_printer_driver_info(info, &driver, level)) {
7861 DEBUG(5,("Cleaning driver's information\n"));
7862 err = clean_up_driver_struct(driver, level, &p->pipe_user);
7863 if (!W_ERROR_IS_OK(err))
7866 DEBUG(5,("Moving driver to final destination\n"));
7867 if( !W_ERROR_IS_OK(err = move_driver_to_download_area(driver, level, &p->pipe_user, &err)) ) {
7871 if (add_a_printer_driver(driver, level)!=0) {
7872 err = WERR_ACCESS_DENIED;
7877 * I think this is where he DrvUpgradePrinter() hook would be
7878 * be called in a driver's interface DLL on a Windows NT 4.0/2k
7879 * server. Right now, we just need to send ourselves a message
7880 * to update each printer bound to this driver. --jerry
7883 if (!srv_spoolss_drv_upgrade_printer(driver_name)) {
7884 DEBUG(0,("_spoolss_addprinterdriver: Failed to send message about upgrading driver [%s]!\n",
7889 * Based on the version (e.g. driver destination dir: 0=9x,2=Nt/2k,3=2k/Xp),
7890 * decide if the driver init data should be deleted. The rules are:
7891 * 1) never delete init data if it is a 9x driver, they don't use it anyway
7892 * 2) delete init data only if there is no 2k/Xp driver
7893 * 3) always delete init data
7894 * The generalized rule is always use init data from the highest order driver.
7895 * It is necessary to follow the driver install by an initialization step to
7896 * finish off this process.
7899 version = driver.info_3->cversion;
7900 else if (level == 6)
7901 version = driver.info_6->version;
7906 * 9x printer driver - never delete init data
7909 DEBUG(10,("_spoolss_addprinterdriver: init data not deleted for 9x driver [%s]\n",
7914 * Nt or 2k (compatiblity mode) printer driver - only delete init data if
7915 * there is no 2k/Xp driver init data for this driver name.
7919 NT_PRINTER_DRIVER_INFO_LEVEL driver1;
7921 if (!W_ERROR_IS_OK(get_a_printer_driver(&driver1, 3, driver_name, "Windows NT x86", 3))) {
7923 * No 2k/Xp driver found, delete init data (if any) for the new Nt driver.
7925 if (!del_driver_init(driver_name))
7926 DEBUG(6,("_spoolss_addprinterdriver: del_driver_init(%s) Nt failed!\n", driver_name));
7929 * a 2k/Xp driver was found, don't delete init data because Nt driver will use it.
7931 free_a_printer_driver(driver1,3);
7932 DEBUG(10,("_spoolss_addprinterdriver: init data not deleted for Nt driver [%s]\n",
7939 * 2k or Xp printer driver - always delete init data
7942 if (!del_driver_init(driver_name))
7943 DEBUG(6,("_spoolss_addprinterdriver: del_driver_init(%s) 2k/Xp failed!\n", driver_name));
7947 DEBUG(0,("_spoolss_addprinterdriver: invalid level=%d\n", level));
7953 free_a_printer_driver(driver, level);
7957 /********************************************************************
7958 * spoolss_addprinterdriverex
7959 ********************************************************************/
7961 WERROR _spoolss_addprinterdriverex(pipes_struct *p, SPOOL_Q_ADDPRINTERDRIVEREX *q_u, SPOOL_R_ADDPRINTERDRIVEREX *r_u)
7963 SPOOL_Q_ADDPRINTERDRIVER q_u_local;
7964 SPOOL_R_ADDPRINTERDRIVER r_u_local;
7967 * we only support the semantics of AddPrinterDriver()
7968 * i.e. only copy files that are newer than existing ones
7971 if ( q_u->copy_flags != APD_COPY_NEW_FILES )
7972 return WERR_ACCESS_DENIED;
7974 ZERO_STRUCT(q_u_local);
7975 ZERO_STRUCT(r_u_local);
7977 /* just pass the information off to _spoolss_addprinterdriver() */
7978 q_u_local.server_name_ptr = q_u->server_name_ptr;
7979 copy_unistr2(&q_u_local.server_name, &q_u->server_name);
7980 q_u_local.level = q_u->level;
7981 memcpy( &q_u_local.info, &q_u->info, sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL) );
7983 return _spoolss_addprinterdriver( p, &q_u_local, &r_u_local );
7986 /****************************************************************************
7987 ****************************************************************************/
7989 static void fill_driverdir_1(DRIVER_DIRECTORY_1 *info, char *name)
7991 init_unistr(&info->name, name);
7994 /****************************************************************************
7995 ****************************************************************************/
7997 static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environment, RPC_BUFFER *buffer, uint32 offered, uint32 *needed)
8003 const char *short_archi;
8004 DRIVER_DIRECTORY_1 *info=NULL;
8005 WERROR result = WERR_OK;
8007 unistr2_to_ascii(servername, name, sizeof(servername)-1);
8008 unistr2_to_ascii(long_archi, uni_environment, sizeof(long_archi)-1);
8010 /* check for beginning double '\'s and that the server
8013 pservername = servername;
8014 if ( *pservername == '\\' && strlen(servername)>2 ) {
8018 if ( !is_myname_or_ipaddr( pservername ) )
8019 return WERR_INVALID_PARAM;
8021 if (!(short_archi = get_short_archi(long_archi)))
8022 return WERR_INVALID_ENVIRONMENT;
8024 if((info=SMB_MALLOC_P(DRIVER_DIRECTORY_1)) == NULL)
8027 slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s", pservername, short_archi);
8029 DEBUG(4,("printer driver directory: [%s]\n", path));
8031 fill_driverdir_1(info, path);
8033 *needed += spoolss_size_driverdir_info_1(info);
8035 if (*needed > offered) {
8036 result = WERR_INSUFFICIENT_BUFFER;
8040 if (!rpcbuf_alloc_size(buffer, *needed)) {
8041 result = WERR_NOMEM;
8045 smb_io_driverdir_1("", buffer, info, 0);
8053 /****************************************************************************
8054 ****************************************************************************/
8056 WERROR _spoolss_getprinterdriverdirectory(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVERDIR *q_u, SPOOL_R_GETPRINTERDRIVERDIR *r_u)
8058 UNISTR2 *name = &q_u->name;
8059 UNISTR2 *uni_environment = &q_u->environment;
8060 uint32 level = q_u->level;
8061 RPC_BUFFER *buffer = NULL;
8062 uint32 offered = q_u->offered;
8063 uint32 *needed = &r_u->needed;
8065 /* that's an [in out] buffer */
8067 if (!q_u->buffer && (offered!=0)) {
8068 return WERR_INVALID_PARAM;
8071 rpcbuf_move(q_u->buffer, &r_u->buffer);
8072 buffer = r_u->buffer;
8074 DEBUG(4,("_spoolss_getprinterdriverdirectory\n"));
8080 return getprinterdriverdir_level_1(name, uni_environment, buffer, offered, needed);
8082 return WERR_UNKNOWN_LEVEL;
8086 /****************************************************************************
8087 ****************************************************************************/
8089 WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, SPOOL_R_ENUMPRINTERDATA *r_u)
8091 POLICY_HND *handle = &q_u->handle;
8092 uint32 idx = q_u->index;
8093 uint32 in_value_len = q_u->valuesize;
8094 uint32 in_data_len = q_u->datasize;
8095 uint32 *out_max_value_len = &r_u->valuesize;
8096 uint16 **out_value = &r_u->value;
8097 uint32 *out_value_len = &r_u->realvaluesize;
8098 uint32 *out_type = &r_u->type;
8099 uint32 *out_max_data_len = &r_u->datasize;
8100 uint8 **data_out = &r_u->data;
8101 uint32 *out_data_len = &r_u->realdatasize;
8103 NT_PRINTER_INFO_LEVEL *printer = NULL;
8105 uint32 biggest_valuesize;
8106 uint32 biggest_datasize;
8108 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
8111 REGISTRY_VALUE *val = NULL;
8112 NT_PRINTER_DATA *p_data;
8113 int i, key_index, num_values;
8118 *out_max_data_len = 0;
8122 DEBUG(5,("spoolss_enumprinterdata\n"));
8125 DEBUG(2,("_spoolss_enumprinterdata: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
8129 if (!get_printer_snum(p,handle, &snum, NULL))
8132 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8133 if (!W_ERROR_IS_OK(result))
8136 p_data = printer->info_2->data;
8137 key_index = lookup_printerkey( p_data, SPOOL_PRINTERDATA_KEY );
8142 * The NT machine wants to know the biggest size of value and data
8144 * cf: MSDN EnumPrinterData remark section
8147 if ( !in_value_len && !in_data_len && (key_index != -1) )
8149 DEBUGADD(6,("Activating NT mega-hack to find sizes\n"));
8151 biggest_valuesize = 0;
8152 biggest_datasize = 0;
8154 num_values = regval_ctr_numvals( p_data->keys[key_index].values );
8156 for ( i=0; i<num_values; i++ )
8158 val = regval_ctr_specific_value( p_data->keys[key_index].values, i );
8160 name_length = strlen(val->valuename);
8161 if ( strlen(val->valuename) > biggest_valuesize )
8162 biggest_valuesize = name_length;
8164 if ( val->size > biggest_datasize )
8165 biggest_datasize = val->size;
8167 DEBUG(6,("current values: [%d], [%d]\n", biggest_valuesize,
8171 /* the value is an UNICODE string but real_value_size is the length
8172 in bytes including the trailing 0 */
8174 *out_value_len = 2 * (1+biggest_valuesize);
8175 *out_data_len = biggest_datasize;
8177 DEBUG(6,("final values: [%d], [%d]\n", *out_value_len, *out_data_len));
8183 * the value len is wrong in NT sp3
8184 * that's the number of bytes not the number of unicode chars
8187 if ( key_index != -1 )
8188 val = regval_ctr_specific_value( p_data->keys[key_index].values, idx );
8193 /* out_value should default to "" or else NT4 has
8194 problems unmarshalling the response */
8196 *out_max_value_len=(in_value_len/sizeof(uint16));
8199 if((*out_value=(uint16 *)TALLOC_ZERO(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL)
8201 result = WERR_NOMEM;
8204 *out_value_len = (uint32)rpcstr_push((char *)*out_value, "", in_value_len, 0);
8210 /* the data is counted in bytes */
8212 *out_max_data_len = in_data_len;
8213 *out_data_len = in_data_len;
8215 /* only allocate when given a non-zero data_len */
8217 if ( in_data_len && ((*data_out=(uint8 *)TALLOC_ZERO(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL) )
8219 result = WERR_NOMEM;
8223 result = WERR_NO_MORE_ITEMS;
8229 * - counted in bytes in the request
8230 * - counted in UNICODE chars in the max reply
8231 * - counted in bytes in the real size
8233 * take a pause *before* coding not *during* coding
8237 *out_max_value_len=(in_value_len/sizeof(uint16));
8239 if ( (*out_value = (uint16 *)TALLOC_ZERO(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL )
8241 result = WERR_NOMEM;
8245 *out_value_len = (uint32)rpcstr_push((char *)*out_value, regval_name(val), (size_t)in_value_len, 0);
8253 *out_type = regval_type( val );
8255 /* data - counted in bytes */
8257 *out_max_data_len = in_data_len;
8258 if ( in_data_len && (*data_out = (uint8 *)TALLOC_ZERO(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL)
8260 result = WERR_NOMEM;
8263 data_len = regval_size(val);
8264 if ( *data_out && data_len )
8265 memcpy( *data_out, regval_data_p(val), data_len );
8266 *out_data_len = data_len;
8270 free_a_printer(&printer, 2);
8274 /****************************************************************************
8275 ****************************************************************************/
8277 WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SPOOL_R_SETPRINTERDATA *r_u)
8279 POLICY_HND *handle = &q_u->handle;
8280 UNISTR2 *value = &q_u->value;
8281 uint32 type = q_u->type;
8282 uint8 *data = q_u->data;
8283 uint32 real_len = q_u->real_len;
8285 NT_PRINTER_INFO_LEVEL *printer = NULL;
8287 WERROR status = WERR_OK;
8288 Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
8291 DEBUG(5,("spoolss_setprinterdata\n"));
8294 DEBUG(2,("_spoolss_setprinterdata: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
8298 if ( Printer->printer_type == SPLHND_SERVER ) {
8299 DEBUG(10,("_spoolss_setprinterdata: Not implemented for server handles yet\n"));
8300 return WERR_INVALID_PARAM;
8303 if (!get_printer_snum(p,handle, &snum, NULL))
8307 * Access check : NT returns "access denied" if you make a
8308 * SetPrinterData call without the necessary privildge.
8309 * we were originally returning OK if nothing changed
8310 * which made Win2k issue **a lot** of SetPrinterData
8311 * when connecting to a printer --jerry
8314 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER)
8316 DEBUG(3, ("_spoolss_setprinterdata: change denied by handle access permissions\n"));
8317 status = WERR_ACCESS_DENIED;
8321 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8322 if (!W_ERROR_IS_OK(status))
8325 unistr2_to_ascii( valuename, value, sizeof(valuename)-1 );
8328 * When client side code sets a magic printer data key, detect it and save
8329 * the current printer data and the magic key's data (its the DEVMODE) for
8330 * future printer/driver initializations.
8332 if ( (type == REG_BINARY) && strequal( valuename, PHANTOM_DEVMODE_KEY))
8334 /* Set devmode and printer initialization info */
8335 status = save_driver_init( printer, 2, data, real_len );
8337 srv_spoolss_reset_printerdata( printer->info_2->drivername );
8341 status = set_printer_dataex( printer, SPOOL_PRINTERDATA_KEY, valuename,
8342 type, data, real_len );
8343 if ( W_ERROR_IS_OK(status) )
8344 status = mod_a_printer(printer, 2);
8348 free_a_printer(&printer, 2);
8353 /****************************************************************************
8354 ****************************************************************************/
8356 WERROR _spoolss_resetprinter(pipes_struct *p, SPOOL_Q_RESETPRINTER *q_u, SPOOL_R_RESETPRINTER *r_u)
8358 POLICY_HND *handle = &q_u->handle;
8359 Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
8362 DEBUG(5,("_spoolss_resetprinter\n"));
8365 * All we do is to check to see if the handle and queue is valid.
8366 * This call really doesn't mean anything to us because we only
8367 * support RAW printing. --jerry
8371 DEBUG(2,("_spoolss_resetprinter: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
8375 if (!get_printer_snum(p,handle, &snum, NULL))
8379 /* blindly return success */
8384 /****************************************************************************
8385 ****************************************************************************/
8387 WERROR _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_u, SPOOL_R_DELETEPRINTERDATA *r_u)
8389 POLICY_HND *handle = &q_u->handle;
8390 UNISTR2 *value = &q_u->valuename;
8392 NT_PRINTER_INFO_LEVEL *printer = NULL;
8394 WERROR status = WERR_OK;
8395 Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
8398 DEBUG(5,("spoolss_deleteprinterdata\n"));
8401 DEBUG(2,("_spoolss_deleteprinterdata: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
8405 if (!get_printer_snum(p, handle, &snum, NULL))
8408 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
8409 DEBUG(3, ("_spoolss_deleteprinterdata: printer properties change denied by handle\n"));
8410 return WERR_ACCESS_DENIED;
8413 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8414 if (!W_ERROR_IS_OK(status))
8417 unistr2_to_ascii( valuename, value, sizeof(valuename)-1 );
8419 status = delete_printer_dataex( printer, SPOOL_PRINTERDATA_KEY, valuename );
8421 if ( W_ERROR_IS_OK(status) )
8422 mod_a_printer( printer, 2 );
8424 free_a_printer(&printer, 2);
8429 /****************************************************************************
8430 ****************************************************************************/
8432 WERROR _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM *r_u)
8434 POLICY_HND *handle = &q_u->handle;
8435 FORM *form = &q_u->form;
8436 nt_forms_struct tmpForm;
8438 WERROR status = WERR_OK;
8439 NT_PRINTER_INFO_LEVEL *printer = NULL;
8442 nt_forms_struct *list=NULL;
8443 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
8445 DEBUG(5,("spoolss_addform\n"));
8448 DEBUG(2,("_spoolss_addform: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
8453 /* forms can be added on printer of on the print server handle */
8455 if ( Printer->printer_type == SPLHND_PRINTER )
8457 if (!get_printer_snum(p,handle, &snum, NULL))
8460 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8461 if (!W_ERROR_IS_OK(status))
8465 if ( !(Printer->access_granted & (PRINTER_ACCESS_ADMINISTER|SERVER_ACCESS_ADMINISTER)) ) {
8466 DEBUG(2,("_spoolss_addform: denied by handle permissions.\n"));
8467 status = WERR_ACCESS_DENIED;
8471 /* can't add if builtin */
8473 if (get_a_builtin_ntform(&form->name,&tmpForm)) {
8474 status = WERR_ALREADY_EXISTS;
8478 count = get_ntforms(&list);
8480 if(!add_a_form(&list, form, &count)) {
8481 status = WERR_NOMEM;
8485 write_ntforms(&list, count);
8488 * ChangeID must always be set if this is a printer
8491 if ( Printer->printer_type == SPLHND_PRINTER )
8492 status = mod_a_printer(printer, 2);
8496 free_a_printer(&printer, 2);
8502 /****************************************************************************
8503 ****************************************************************************/
8505 WERROR _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DELETEFORM *r_u)
8507 POLICY_HND *handle = &q_u->handle;
8508 UNISTR2 *form_name = &q_u->name;
8509 nt_forms_struct tmpForm;
8511 nt_forms_struct *list=NULL;
8512 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
8514 WERROR status = WERR_OK;
8515 NT_PRINTER_INFO_LEVEL *printer = NULL;
8517 DEBUG(5,("spoolss_deleteform\n"));
8520 DEBUG(2,("_spoolss_deleteform: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
8524 /* forms can be deleted on printer of on the print server handle */
8526 if ( Printer->printer_type == SPLHND_PRINTER )
8528 if (!get_printer_snum(p,handle, &snum, NULL))
8531 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8532 if (!W_ERROR_IS_OK(status))
8536 if ( !(Printer->access_granted & (PRINTER_ACCESS_ADMINISTER|SERVER_ACCESS_ADMINISTER)) ) {
8537 DEBUG(2,("_spoolss_deleteform: denied by handle permissions.\n"));
8538 status = WERR_ACCESS_DENIED;
8542 /* can't delete if builtin */
8544 if (get_a_builtin_ntform(form_name,&tmpForm)) {
8545 status = WERR_INVALID_PARAM;
8549 count = get_ntforms(&list);
8551 if ( !delete_a_form(&list, form_name, &count, &status ))
8555 * ChangeID must always be set if this is a printer
8558 if ( Printer->printer_type == SPLHND_PRINTER )
8559 status = mod_a_printer(printer, 2);
8563 free_a_printer(&printer, 2);
8569 /****************************************************************************
8570 ****************************************************************************/
8572 WERROR _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM *r_u)
8574 POLICY_HND *handle = &q_u->handle;
8575 FORM *form = &q_u->form;
8576 nt_forms_struct tmpForm;
8578 WERROR status = WERR_OK;
8579 NT_PRINTER_INFO_LEVEL *printer = NULL;
8582 nt_forms_struct *list=NULL;
8583 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
8585 DEBUG(5,("spoolss_setform\n"));
8588 DEBUG(2,("_spoolss_setform: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
8592 /* forms can be modified on printer of on the print server handle */
8594 if ( Printer->printer_type == SPLHND_PRINTER )
8596 if (!get_printer_snum(p,handle, &snum, NULL))
8599 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
8600 if (!W_ERROR_IS_OK(status))
8604 if ( !(Printer->access_granted & (PRINTER_ACCESS_ADMINISTER|SERVER_ACCESS_ADMINISTER)) ) {
8605 DEBUG(2,("_spoolss_setform: denied by handle permissions\n"));
8606 status = WERR_ACCESS_DENIED;
8610 /* can't set if builtin */
8611 if (get_a_builtin_ntform(&form->name,&tmpForm)) {
8612 status = WERR_INVALID_PARAM;
8616 count = get_ntforms(&list);
8617 update_a_form(&list, form, count);
8618 write_ntforms(&list, count);
8621 * ChangeID must always be set if this is a printer
8624 if ( Printer->printer_type == SPLHND_PRINTER )
8625 status = mod_a_printer(printer, 2);
8630 free_a_printer(&printer, 2);
8636 /****************************************************************************
8637 enumprintprocessors level 1.
8638 ****************************************************************************/
8640 static WERROR enumprintprocessors_level_1(RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
8642 PRINTPROCESSOR_1 *info_1=NULL;
8643 WERROR result = WERR_OK;
8645 if((info_1 = SMB_MALLOC_P(PRINTPROCESSOR_1)) == NULL)
8650 init_unistr(&info_1->name, "winprint");
8652 *needed += spoolss_size_printprocessor_info_1(info_1);
8654 if (*needed > offered) {
8655 result = WERR_INSUFFICIENT_BUFFER;
8659 if (!rpcbuf_alloc_size(buffer, *needed)) {
8660 result = WERR_NOMEM;
8664 smb_io_printprocessor_info_1("", buffer, info_1, 0);
8669 if ( !W_ERROR_IS_OK(result) )
8675 /****************************************************************************
8676 ****************************************************************************/
8678 WERROR _spoolss_enumprintprocessors(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCESSORS *q_u, SPOOL_R_ENUMPRINTPROCESSORS *r_u)
8680 uint32 level = q_u->level;
8681 RPC_BUFFER *buffer = NULL;
8682 uint32 offered = q_u->offered;
8683 uint32 *needed = &r_u->needed;
8684 uint32 *returned = &r_u->returned;
8686 /* that's an [in out] buffer */
8688 if (!q_u->buffer && (offered!=0)) {
8689 return WERR_INVALID_PARAM;
8692 rpcbuf_move(q_u->buffer, &r_u->buffer);
8693 buffer = r_u->buffer;
8695 DEBUG(5,("spoolss_enumprintprocessors\n"));
8698 * Enumerate the print processors ...
8700 * Just reply with "winprint", to keep NT happy
8701 * and I can use my nice printer checker.
8709 return enumprintprocessors_level_1(buffer, offered, needed, returned);
8711 return WERR_UNKNOWN_LEVEL;
8715 /****************************************************************************
8716 enumprintprocdatatypes level 1.
8717 ****************************************************************************/
8719 static WERROR enumprintprocdatatypes_level_1(RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
8721 PRINTPROCDATATYPE_1 *info_1=NULL;
8722 WERROR result = WERR_OK;
8724 if((info_1 = SMB_MALLOC_P(PRINTPROCDATATYPE_1)) == NULL)
8729 init_unistr(&info_1->name, "RAW");
8731 *needed += spoolss_size_printprocdatatype_info_1(info_1);
8733 if (*needed > offered) {
8734 result = WERR_INSUFFICIENT_BUFFER;
8738 if (!rpcbuf_alloc_size(buffer, *needed)) {
8739 result = WERR_NOMEM;
8743 smb_io_printprocdatatype_info_1("", buffer, info_1, 0);
8748 if ( !W_ERROR_IS_OK(result) )
8754 /****************************************************************************
8755 ****************************************************************************/
8757 WERROR _spoolss_enumprintprocdatatypes(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCDATATYPES *q_u, SPOOL_R_ENUMPRINTPROCDATATYPES *r_u)
8759 uint32 level = q_u->level;
8760 RPC_BUFFER *buffer = NULL;
8761 uint32 offered = q_u->offered;
8762 uint32 *needed = &r_u->needed;
8763 uint32 *returned = &r_u->returned;
8765 /* that's an [in out] buffer */
8767 if (!q_u->buffer && (offered!=0)) {
8768 return WERR_INVALID_PARAM;
8771 rpcbuf_move(q_u->buffer, &r_u->buffer);
8772 buffer = r_u->buffer;
8774 DEBUG(5,("_spoolss_enumprintprocdatatypes\n"));
8781 return enumprintprocdatatypes_level_1(buffer, offered, needed, returned);
8783 return WERR_UNKNOWN_LEVEL;
8787 /****************************************************************************
8788 enumprintmonitors level 1.
8789 ****************************************************************************/
8791 static WERROR enumprintmonitors_level_1(RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
8793 PRINTMONITOR_1 *info_1;
8794 WERROR result = WERR_OK;
8797 if((info_1 = SMB_MALLOC_ARRAY(PRINTMONITOR_1, 2)) == NULL)
8802 init_unistr(&(info_1[0].name), SPL_LOCAL_PORT );
8803 init_unistr(&(info_1[1].name), SPL_TCPIP_PORT );
8805 for ( i=0; i<*returned; i++ ) {
8806 *needed += spoolss_size_printmonitor_info_1(&info_1[i]);
8809 if (*needed > offered) {
8810 result = WERR_INSUFFICIENT_BUFFER;
8814 if (!rpcbuf_alloc_size(buffer, *needed)) {
8815 result = WERR_NOMEM;
8819 for ( i=0; i<*returned; i++ ) {
8820 smb_io_printmonitor_info_1("", buffer, &info_1[i], 0);
8826 if ( !W_ERROR_IS_OK(result) )
8832 /****************************************************************************
8833 enumprintmonitors level 2.
8834 ****************************************************************************/
8836 static WERROR enumprintmonitors_level_2(RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
8838 PRINTMONITOR_2 *info_2;
8839 WERROR result = WERR_OK;
8842 if((info_2 = SMB_MALLOC_ARRAY(PRINTMONITOR_2, 2)) == NULL)
8847 init_unistr( &(info_2[0].name), SPL_LOCAL_PORT );
8848 init_unistr( &(info_2[0].environment), "Windows NT X86" );
8849 init_unistr( &(info_2[0].dll_name), "localmon.dll" );
8851 init_unistr( &(info_2[1].name), SPL_TCPIP_PORT );
8852 init_unistr( &(info_2[1].environment), "Windows NT X86" );
8853 init_unistr( &(info_2[1].dll_name), "tcpmon.dll" );
8855 for ( i=0; i<*returned; i++ ) {
8856 *needed += spoolss_size_printmonitor_info_2(&info_2[i]);
8859 if (*needed > offered) {
8860 result = WERR_INSUFFICIENT_BUFFER;
8864 if (!rpcbuf_alloc_size(buffer, *needed)) {
8865 result = WERR_NOMEM;
8869 for ( i=0; i<*returned; i++ ) {
8870 smb_io_printmonitor_info_2("", buffer, &info_2[i], 0);
8876 if ( !W_ERROR_IS_OK(result) )
8882 /****************************************************************************
8883 ****************************************************************************/
8885 WERROR _spoolss_enumprintmonitors(pipes_struct *p, SPOOL_Q_ENUMPRINTMONITORS *q_u, SPOOL_R_ENUMPRINTMONITORS *r_u)
8887 uint32 level = q_u->level;
8888 RPC_BUFFER *buffer = NULL;
8889 uint32 offered = q_u->offered;
8890 uint32 *needed = &r_u->needed;
8891 uint32 *returned = &r_u->returned;
8893 /* that's an [in out] buffer */
8895 if (!q_u->buffer && (offered!=0)) {
8896 return WERR_INVALID_PARAM;
8899 rpcbuf_move(q_u->buffer, &r_u->buffer);
8900 buffer = r_u->buffer;
8902 DEBUG(5,("spoolss_enumprintmonitors\n"));
8905 * Enumerate the print monitors ...
8907 * Just reply with "Local Port", to keep NT happy
8908 * and I can use my nice printer checker.
8916 return enumprintmonitors_level_1(buffer, offered, needed, returned);
8918 return enumprintmonitors_level_2(buffer, offered, needed, returned);
8920 return WERR_UNKNOWN_LEVEL;
8924 /****************************************************************************
8925 ****************************************************************************/
8927 static WERROR getjob_level_1(print_queue_struct **queue, int count, int snum,
8928 NT_PRINTER_INFO_LEVEL *ntprinter,
8929 uint32 jobid, RPC_BUFFER *buffer, uint32 offered,
8934 JOB_INFO_1 *info_1=NULL;
8935 WERROR result = WERR_OK;
8937 info_1=SMB_MALLOC_P(JOB_INFO_1);
8939 if (info_1 == NULL) {
8943 for (i=0; i<count && found==False; i++) {
8944 if ((*queue)[i].job==(int)jobid)
8950 /* NT treats not found as bad param... yet another bad choice */
8951 return WERR_INVALID_PARAM;
8954 fill_job_info_1( info_1, &((*queue)[i-1]), i, snum, ntprinter );
8956 *needed += spoolss_size_job_info_1(info_1);
8958 if (*needed > offered) {
8959 result = WERR_INSUFFICIENT_BUFFER;
8963 if (!rpcbuf_alloc_size(buffer, *needed)) {
8964 result = WERR_NOMEM;
8968 smb_io_job_info_1("", buffer, info_1, 0);
8976 /****************************************************************************
8977 ****************************************************************************/
8979 static WERROR getjob_level_2(print_queue_struct **queue, int count, int snum,
8980 NT_PRINTER_INFO_LEVEL *ntprinter,
8981 uint32 jobid, RPC_BUFFER *buffer, uint32 offered,
8988 DEVICEMODE *devmode = NULL;
8989 NT_DEVICEMODE *nt_devmode = NULL;
8991 if ( !(info_2=SMB_MALLOC_P(JOB_INFO_2)) )
8994 ZERO_STRUCTP(info_2);
8996 for ( i=0; i<count && found==False; i++ )
8998 if ((*queue)[i].job == (int)jobid)
9003 /* NT treats not found as bad param... yet another bad
9005 result = WERR_INVALID_PARAM;
9010 * if the print job does not have a DEVMODE associated with it,
9011 * just use the one for the printer. A NULL devicemode is not
9012 * a failure condition
9015 if ( !(nt_devmode=print_job_devmode( lp_const_servicename(snum), jobid )) )
9016 devmode = construct_dev_mode(lp_const_servicename(snum));
9018 if ((devmode = SMB_MALLOC_P(DEVICEMODE)) != NULL) {
9019 ZERO_STRUCTP( devmode );
9020 convert_nt_devicemode( devmode, nt_devmode );
9024 fill_job_info_2(info_2, &((*queue)[i-1]), i, snum, ntprinter, devmode);
9026 *needed += spoolss_size_job_info_2(info_2);
9028 if (*needed > offered) {
9029 result = WERR_INSUFFICIENT_BUFFER;
9033 if (!rpcbuf_alloc_size(buffer, *needed)) {
9034 result = WERR_NOMEM;
9038 smb_io_job_info_2("", buffer, info_2, 0);
9043 /* Cleanup allocated memory */
9045 free_job_info_2(info_2); /* Also frees devmode */
9051 /****************************************************************************
9052 ****************************************************************************/
9054 WERROR _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_u)
9056 POLICY_HND *handle = &q_u->handle;
9057 uint32 jobid = q_u->jobid;
9058 uint32 level = q_u->level;
9059 RPC_BUFFER *buffer = NULL;
9060 uint32 offered = q_u->offered;
9061 uint32 *needed = &r_u->needed;
9062 WERROR wstatus = WERR_OK;
9063 NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
9066 print_queue_struct *queue = NULL;
9067 print_status_struct prt_status;
9069 /* that's an [in out] buffer */
9071 if (!q_u->buffer && (offered!=0)) {
9072 return WERR_INVALID_PARAM;
9075 rpcbuf_move(q_u->buffer, &r_u->buffer);
9076 buffer = r_u->buffer;
9078 DEBUG(5,("spoolss_getjob\n"));
9082 if (!get_printer_snum(p, handle, &snum, NULL))
9085 wstatus = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum));
9086 if ( !W_ERROR_IS_OK(wstatus) )
9089 count = print_queue_status(snum, &queue, &prt_status);
9091 DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
9092 count, prt_status.status, prt_status.message));
9096 wstatus = getjob_level_1(&queue, count, snum, ntprinter, jobid,
9097 buffer, offered, needed);
9100 wstatus = getjob_level_2(&queue, count, snum, ntprinter, jobid,
9101 buffer, offered, needed);
9104 wstatus = WERR_UNKNOWN_LEVEL;
9109 free_a_printer( &ntprinter, 2 );
9114 /********************************************************************
9115 spoolss_getprinterdataex
9117 From MSDN documentation of GetPrinterDataEx: pass request
9118 to GetPrinterData if key is "PrinterDriverData".
9119 ********************************************************************/
9121 WERROR _spoolss_getprinterdataex(pipes_struct *p, SPOOL_Q_GETPRINTERDATAEX *q_u, SPOOL_R_GETPRINTERDATAEX *r_u)
9123 POLICY_HND *handle = &q_u->handle;
9124 uint32 in_size = q_u->size;
9125 uint32 *type = &r_u->type;
9126 uint32 *out_size = &r_u->size;
9127 uint8 **data = &r_u->data;
9128 uint32 *needed = &r_u->needed;
9129 fstring keyname, valuename;
9131 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
9133 NT_PRINTER_INFO_LEVEL *printer = NULL;
9135 WERROR status = WERR_OK;
9137 DEBUG(4,("_spoolss_getprinterdataex\n"));
9139 unistr2_to_ascii(keyname, &q_u->keyname, sizeof(keyname) - 1);
9140 unistr2_to_ascii(valuename, &q_u->valuename, sizeof(valuename) - 1);
9142 DEBUG(10, ("_spoolss_getprinterdataex: key => [%s], value => [%s]\n",
9143 keyname, valuename));
9145 /* in case of problem, return some default values */
9149 *out_size = in_size;
9152 DEBUG(2,("_spoolss_getprinterdataex: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
9153 status = WERR_BADFID;
9157 /* Is the handle to a printer or to the server? */
9159 if (Printer->printer_type == SPLHND_SERVER) {
9160 DEBUG(10,("_spoolss_getprinterdataex: Not implemented for server handles yet\n"));
9161 status = WERR_INVALID_PARAM;
9165 if ( !get_printer_snum(p,handle, &snum, NULL) )
9168 status = get_a_printer(Printer, &printer, 2, lp_servicename(snum));
9169 if ( !W_ERROR_IS_OK(status) )
9172 /* check to see if the keyname is valid */
9173 if ( !strlen(keyname) ) {
9174 status = WERR_INVALID_PARAM;
9178 if ( lookup_printerkey( printer->info_2->data, keyname ) == -1 ) {
9179 DEBUG(4,("_spoolss_getprinterdataex: Invalid keyname [%s]\n", keyname ));
9180 free_a_printer( &printer, 2 );
9181 status = WERR_BADFILE;
9185 /* When given a new keyname, we should just create it */
9187 status = get_printer_dataex( p->mem_ctx, printer, keyname, valuename, type, data, needed, in_size );
9189 if (*needed > *out_size)
9190 status = WERR_MORE_DATA;
9193 if ( !W_ERROR_IS_OK(status) )
9195 DEBUG(5, ("error: allocating %d\n", *out_size));
9197 /* reply this param doesn't exist */
9201 if( (*data=(uint8 *)TALLOC_ZERO(p->mem_ctx, *out_size*sizeof(uint8))) == NULL ) {
9202 status = WERR_NOMEM;
9211 free_a_printer( &printer, 2 );
9216 /********************************************************************
9217 * spoolss_setprinterdataex
9218 ********************************************************************/
9220 WERROR _spoolss_setprinterdataex(pipes_struct *p, SPOOL_Q_SETPRINTERDATAEX *q_u, SPOOL_R_SETPRINTERDATAEX *r_u)
9222 POLICY_HND *handle = &q_u->handle;
9223 uint32 type = q_u->type;
9224 uint8 *data = q_u->data;
9225 uint32 real_len = q_u->real_len;
9227 NT_PRINTER_INFO_LEVEL *printer = NULL;
9229 WERROR status = WERR_OK;
9230 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
9235 DEBUG(4,("_spoolss_setprinterdataex\n"));
9237 /* From MSDN documentation of SetPrinterDataEx: pass request to
9238 SetPrinterData if key is "PrinterDriverData" */
9241 DEBUG(2,("_spoolss_setprinterdataex: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
9245 if ( Printer->printer_type == SPLHND_SERVER ) {
9246 DEBUG(10,("_spoolss_setprinterdataex: Not implemented for server handles yet\n"));
9247 return WERR_INVALID_PARAM;
9250 if ( !get_printer_snum(p,handle, &snum, NULL) )
9254 * Access check : NT returns "access denied" if you make a
9255 * SetPrinterData call without the necessary privildge.
9256 * we were originally returning OK if nothing changed
9257 * which made Win2k issue **a lot** of SetPrinterData
9258 * when connecting to a printer --jerry
9261 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER)
9263 DEBUG(3, ("_spoolss_setprinterdataex: change denied by handle access permissions\n"));
9264 return WERR_ACCESS_DENIED;
9267 status = get_a_printer(Printer, &printer, 2, lp_servicename(snum));
9268 if (!W_ERROR_IS_OK(status))
9271 unistr2_to_ascii( valuename, &q_u->value, sizeof(valuename) - 1);
9272 unistr2_to_ascii( keyname, &q_u->key, sizeof(keyname) - 1);
9274 /* check for OID in valuename */
9276 if ( (oid_string = strchr( valuename, ',' )) != NULL )
9282 /* save the registry data */
9284 status = set_printer_dataex( printer, keyname, valuename, type, data, real_len );
9286 if ( W_ERROR_IS_OK(status) )
9288 /* save the OID if one was specified */
9290 fstrcat( keyname, "\\" );
9291 fstrcat( keyname, SPOOL_OID_KEY );
9294 * I'm not checking the status here on purpose. Don't know
9295 * if this is right, but I'm returning the status from the
9296 * previous set_printer_dataex() call. I have no idea if
9297 * this is right. --jerry
9300 set_printer_dataex( printer, keyname, valuename,
9301 REG_SZ, (uint8 *)oid_string,
9302 strlen(oid_string)+1 );
9305 status = mod_a_printer(printer, 2);
9308 free_a_printer(&printer, 2);
9314 /********************************************************************
9315 * spoolss_deleteprinterdataex
9316 ********************************************************************/
9318 WERROR _spoolss_deleteprinterdataex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATAEX *q_u, SPOOL_R_DELETEPRINTERDATAEX *r_u)
9320 POLICY_HND *handle = &q_u->handle;
9321 UNISTR2 *value = &q_u->valuename;
9322 UNISTR2 *key = &q_u->keyname;
9324 NT_PRINTER_INFO_LEVEL *printer = NULL;
9326 WERROR status = WERR_OK;
9327 Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
9328 pstring valuename, keyname;
9330 DEBUG(5,("spoolss_deleteprinterdataex\n"));
9333 DEBUG(2,("_spoolss_deleteprinterdata: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
9337 if (!get_printer_snum(p, handle, &snum, NULL))
9340 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9341 DEBUG(3, ("_spoolss_deleteprinterdataex: printer properties change denied by handle\n"));
9342 return WERR_ACCESS_DENIED;
9345 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9346 if (!W_ERROR_IS_OK(status))
9349 unistr2_to_ascii( valuename, value, sizeof(valuename)-1 );
9350 unistr2_to_ascii( keyname, key, sizeof(keyname)-1 );
9352 status = delete_printer_dataex( printer, keyname, valuename );
9354 if ( W_ERROR_IS_OK(status) )
9355 mod_a_printer( printer, 2 );
9357 free_a_printer(&printer, 2);
9362 /********************************************************************
9363 * spoolss_enumprinterkey
9364 ********************************************************************/
9367 WERROR _spoolss_enumprinterkey(pipes_struct *p, SPOOL_Q_ENUMPRINTERKEY *q_u, SPOOL_R_ENUMPRINTERKEY *r_u)
9370 fstring *keynames = NULL;
9371 uint16 *enumkeys = NULL;
9374 POLICY_HND *handle = &q_u->handle;
9375 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
9376 NT_PRINTER_DATA *data;
9377 NT_PRINTER_INFO_LEVEL *printer = NULL;
9379 WERROR status = WERR_BADFILE;
9382 DEBUG(4,("_spoolss_enumprinterkey\n"));
9385 DEBUG(2,("_spoolss_enumprinterkey: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
9389 if ( !get_printer_snum(p,handle, &snum, NULL) )
9392 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9393 if (!W_ERROR_IS_OK(status))
9396 /* get the list of subkey names */
9398 unistr2_to_ascii( key, &q_u->key, sizeof(key)-1 );
9399 data = printer->info_2->data;
9401 num_keys = get_printer_subkeys( data, key, &keynames );
9403 if ( num_keys == -1 ) {
9404 status = WERR_BADFILE;
9408 printerkey_len = init_unistr_array( &enumkeys, keynames, NULL );
9410 r_u->needed = printerkey_len*2;
9412 if ( q_u->size < r_u->needed ) {
9413 status = WERR_MORE_DATA;
9417 if (!make_spoolss_buffer5(p->mem_ctx, &r_u->keys, printerkey_len, enumkeys)) {
9418 status = WERR_NOMEM;
9424 if ( q_u->size < r_u->needed )
9425 status = WERR_MORE_DATA;
9428 free_a_printer( &printer, 2 );
9429 SAFE_FREE( keynames );
9434 /********************************************************************
9435 * spoolss_deleteprinterkey
9436 ********************************************************************/
9438 WERROR _spoolss_deleteprinterkey(pipes_struct *p, SPOOL_Q_DELETEPRINTERKEY *q_u, SPOOL_R_DELETEPRINTERKEY *r_u)
9440 POLICY_HND *handle = &q_u->handle;
9441 Printer_entry *Printer = find_printer_index_by_hnd(p, &q_u->handle);
9443 NT_PRINTER_INFO_LEVEL *printer = NULL;
9447 DEBUG(5,("spoolss_deleteprinterkey\n"));
9450 DEBUG(2,("_spoolss_deleteprinterkey: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(handle)));
9454 /* if keyname == NULL, return error */
9456 if ( !q_u->keyname.buffer )
9457 return WERR_INVALID_PARAM;
9459 if (!get_printer_snum(p, handle, &snum, NULL))
9462 if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
9463 DEBUG(3, ("_spoolss_deleteprinterkey: printer properties change denied by handle\n"));
9464 return WERR_ACCESS_DENIED;
9467 status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9468 if (!W_ERROR_IS_OK(status))
9471 /* delete the key and all subneys */
9473 unistr2_to_ascii(key, &q_u->keyname, sizeof(key) - 1);
9475 status = delete_all_printer_data( printer->info_2, key );
9477 if ( W_ERROR_IS_OK(status) )
9478 status = mod_a_printer(printer, 2);
9480 free_a_printer( &printer, 2 );
9486 /********************************************************************
9487 * spoolss_enumprinterdataex
9488 ********************************************************************/
9490 WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_u, SPOOL_R_ENUMPRINTERDATAEX *r_u)
9492 POLICY_HND *handle = &q_u->handle;
9493 uint32 in_size = q_u->size;
9496 NT_PRINTER_INFO_LEVEL *printer = NULL;
9497 PRINTER_ENUM_VALUES *enum_values = NULL;
9498 NT_PRINTER_DATA *p_data;
9500 Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
9505 REGISTRY_VALUE *val;
9510 DEBUG(4,("_spoolss_enumprinterdataex\n"));
9513 DEBUG(2,("_spoolss_enumprinterdataex: Invalid handle (%s:%u:%u1<).\n", OUR_HANDLE(handle)));
9518 * first check for a keyname of NULL or "". Win2k seems to send
9519 * this a lot and we should send back WERR_INVALID_PARAM
9520 * no need to spend time looking up the printer in this case.
9524 unistr2_to_ascii(key, &q_u->key, sizeof(key) - 1);
9525 if ( !strlen(key) ) {
9526 result = WERR_INVALID_PARAM;
9530 /* get the printer off of disk */
9532 if (!get_printer_snum(p,handle, &snum, NULL))
9535 ZERO_STRUCT(printer);
9536 result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
9537 if (!W_ERROR_IS_OK(result))
9540 /* now look for a match on the key name */
9542 p_data = printer->info_2->data;
9544 unistr2_to_ascii(key, &q_u->key, sizeof(key) - 1);
9545 if ( (key_index = lookup_printerkey( p_data, key)) == -1 )
9547 DEBUG(10,("_spoolss_enumprinterdataex: Unknown keyname [%s]\n", key));
9548 result = WERR_INVALID_PARAM;
9555 /* allocate the memory for the array of pointers -- if necessary */
9557 num_entries = regval_ctr_numvals( p_data->keys[key_index].values );
9560 if ( (enum_values=TALLOC_ARRAY(p->mem_ctx, PRINTER_ENUM_VALUES, num_entries)) == NULL )
9562 DEBUG(0,("_spoolss_enumprinterdataex: talloc() failed to allocate memory for [%lu] bytes!\n",
9563 (unsigned long)num_entries*sizeof(PRINTER_ENUM_VALUES)));
9564 result = WERR_NOMEM;
9568 memset( enum_values, 0x0, num_entries*sizeof(PRINTER_ENUM_VALUES) );
9572 * loop through all params and build the array to pass
9573 * back to the client
9576 for ( i=0; i<num_entries; i++ )
9578 /* lookup the registry value */
9580 val = regval_ctr_specific_value( p_data->keys[key_index].values, i );
9581 DEBUG(10,("retrieved value number [%d] [%s]\n", i, regval_name(val) ));
9585 value_name = regval_name( val );
9586 init_unistr( &enum_values[i].valuename, value_name );
9587 enum_values[i].value_len = (strlen(value_name)+1) * 2;
9588 enum_values[i].type = regval_type( val );
9590 data_len = regval_size( val );
9592 if ( !(enum_values[i].data = (uint8 *)TALLOC_MEMDUP(p->mem_ctx, regval_data_p(val), data_len)) )
9594 DEBUG(0,("TALLOC_MEMDUP failed to allocate memory [data_len=%d] for data!\n",
9596 result = WERR_NOMEM;
9600 enum_values[i].data_len = data_len;
9602 /* keep track of the size of the array in bytes */
9604 needed += spoolss_size_printer_enum_values(&enum_values[i]);
9607 /* housekeeping information in the reply */
9609 /* Fix from Martin Zielinski <mz@seh.de> - ensure
9610 * the hand marshalled container size is a multiple
9611 * of 4 bytes for RPC alignment.
9615 needed += 4-(needed % 4);
9618 r_u->needed = needed;
9619 r_u->returned = num_entries;
9621 if (needed > in_size) {
9622 result = WERR_MORE_DATA;
9626 /* copy data into the reply */
9628 r_u->ctr.size = r_u->needed;
9630 r_u->ctr.size_of_array = r_u->returned;
9631 r_u->ctr.values = enum_values;
9637 free_a_printer(&printer, 2);
9642 /****************************************************************************
9643 ****************************************************************************/
9645 static void fill_printprocessordirectory_1(PRINTPROCESSOR_DIRECTORY_1 *info, char *name)
9647 init_unistr(&info->name, name);
9650 static WERROR getprintprocessordirectory_level_1(UNISTR2 *name,
9651 UNISTR2 *environment,
9658 PRINTPROCESSOR_DIRECTORY_1 *info=NULL;
9659 WERROR result = WERR_OK;
9661 unistr2_to_ascii(long_archi, environment, sizeof(long_archi)-1);
9663 if (!get_short_archi(long_archi))
9664 return WERR_INVALID_ENVIRONMENT;
9666 if((info=SMB_MALLOC_P(PRINTPROCESSOR_DIRECTORY_1)) == NULL)
9669 pstrcpy(path, "C:\\WINNT\\System32\\spool\\PRTPROCS\\W32X86");
9671 fill_printprocessordirectory_1(info, path);
9673 *needed += spoolss_size_printprocessordirectory_info_1(info);
9675 if (*needed > offered) {
9676 result = WERR_INSUFFICIENT_BUFFER;
9680 if (!rpcbuf_alloc_size(buffer, *needed)) {
9681 result = WERR_INSUFFICIENT_BUFFER;
9685 smb_io_printprocessordirectory_1("", buffer, info, 0);
9693 WERROR _spoolss_getprintprocessordirectory(pipes_struct *p, SPOOL_Q_GETPRINTPROCESSORDIRECTORY *q_u, SPOOL_R_GETPRINTPROCESSORDIRECTORY *r_u)
9695 uint32 level = q_u->level;
9696 RPC_BUFFER *buffer = NULL;
9697 uint32 offered = q_u->offered;
9698 uint32 *needed = &r_u->needed;
9701 /* that's an [in out] buffer */
9703 if (!q_u->buffer && (offered!=0)) {
9704 return WERR_INVALID_PARAM;
9707 rpcbuf_move(q_u->buffer, &r_u->buffer);
9708 buffer = r_u->buffer;
9710 DEBUG(5,("_spoolss_getprintprocessordirectory\n"));
9716 result = getprintprocessordirectory_level_1
9717 (&q_u->name, &q_u->environment, buffer, offered, needed);
9720 result = WERR_UNKNOWN_LEVEL;
9726 /*******************************************************************
9727 Streams the monitor UI DLL name in UNICODE
9728 *******************************************************************/
9730 static WERROR xcvtcp_monitorui( NT_USER_TOKEN *token, RPC_BUFFER *in,
9731 RPC_BUFFER *out, uint32 *needed )
9733 const char *dllname = "tcpmonui.dll";
9735 *needed = (strlen(dllname)+1) * 2;
9737 if ( rpcbuf_get_size(out) < *needed ) {
9738 return WERR_INSUFFICIENT_BUFFER;
9741 if ( !make_monitorui_buf( out, dllname ) ) {
9748 /*******************************************************************
9749 Create a new TCP/IP port
9750 *******************************************************************/
9752 static WERROR xcvtcp_addport( NT_USER_TOKEN *token, RPC_BUFFER *in,
9753 RPC_BUFFER *out, uint32 *needed )
9755 NT_PORT_DATA_1 port1;
9758 ZERO_STRUCT( port1 );
9760 /* convert to our internal port data structure */
9762 if ( !convert_port_data_1( &port1, in ) ) {
9766 /* create the device URI and call the add_port_hook() */
9768 switch ( port1.protocol ) {
9769 case PORT_PROTOCOL_DIRECT:
9770 pstr_sprintf( device_uri, "socket://%s:%d/", port1.hostaddr, port1.port );
9773 case PORT_PROTOCOL_LPR:
9774 pstr_sprintf( device_uri, "lpr://%s/%s", port1.hostaddr, port1.queue );
9778 return WERR_UNKNOWN_PORT;
9781 return add_port_hook( token, port1.name, device_uri );
9784 /*******************************************************************
9785 *******************************************************************/
9787 struct xcv_api_table xcvtcp_cmds[] = {
9788 { "MonitorUI", xcvtcp_monitorui },
9789 { "AddPort", xcvtcp_addport},
9793 static WERROR process_xcvtcp_command( NT_USER_TOKEN *token, const char *command,
9794 RPC_BUFFER *inbuf, RPC_BUFFER *outbuf,
9799 DEBUG(10,("process_xcvtcp_command: Received command \"%s\"\n", command));
9801 for ( i=0; xcvtcp_cmds[i].name; i++ ) {
9802 if ( strcmp( command, xcvtcp_cmds[i].name ) == 0 )
9803 return xcvtcp_cmds[i].fn( token, inbuf, outbuf, needed );
9806 return WERR_BADFUNC;
9809 /*******************************************************************
9810 *******************************************************************/
9811 #if 0 /* don't support management using the "Local Port" monitor */
9813 static WERROR xcvlocal_monitorui( NT_USER_TOKEN *token, RPC_BUFFER *in,
9814 RPC_BUFFER *out, uint32 *needed )
9816 const char *dllname = "localui.dll";
9818 *needed = (strlen(dllname)+1) * 2;
9820 if ( rpcbuf_get_size(out) < *needed ) {
9821 return WERR_INSUFFICIENT_BUFFER;
9824 if ( !make_monitorui_buf( out, dllname )) {
9831 /*******************************************************************
9832 *******************************************************************/
9834 struct xcv_api_table xcvlocal_cmds[] = {
9835 { "MonitorUI", xcvlocal_monitorui },
9839 struct xcv_api_table xcvlocal_cmds[] = {
9846 /*******************************************************************
9847 *******************************************************************/
9849 static WERROR process_xcvlocal_command( NT_USER_TOKEN *token, const char *command,
9850 RPC_BUFFER *inbuf, RPC_BUFFER *outbuf,
9855 DEBUG(10,("process_xcvlocal_command: Received command \"%s\"\n", command));
9857 for ( i=0; xcvlocal_cmds[i].name; i++ ) {
9858 if ( strcmp( command, xcvlocal_cmds[i].name ) == 0 )
9859 return xcvlocal_cmds[i].fn( token, inbuf, outbuf , needed );
9861 return WERR_BADFUNC;
9864 /*******************************************************************
9865 *******************************************************************/
9867 WERROR _spoolss_xcvdataport(pipes_struct *p, SPOOL_Q_XCVDATAPORT *q_u, SPOOL_R_XCVDATAPORT *r_u)
9869 Printer_entry *Printer = find_printer_index_by_hnd(p, &q_u->handle);
9873 DEBUG(2,("_spoolss_xcvdataport: Invalid handle (%s:%u:%u).\n", OUR_HANDLE(&q_u->handle)));
9877 /* Has to be a handle to the TCP/IP port monitor */
9879 if ( !(Printer->printer_type & (SPLHND_PORTMON_LOCAL|SPLHND_PORTMON_TCP)) ) {
9880 DEBUG(2,("_spoolss_xcvdataport: Call only valid for Port Monitors\n"));
9884 /* requires administrative access to the server */
9886 if ( !(Printer->access_granted & SERVER_ACCESS_ADMINISTER) ) {
9887 DEBUG(2,("_spoolss_xcvdataport: denied by handle permissions.\n"));
9888 return WERR_ACCESS_DENIED;
9891 /* Get the command name. There's numerous commands supported by the
9892 TCPMON interface. */
9894 rpcstr_pull(command, q_u->dataname.buffer, sizeof(command),
9895 q_u->dataname.uni_str_len*2, 0);
9897 /* Allocate the outgoing buffer */
9899 rpcbuf_init( &r_u->outdata, q_u->offered, p->mem_ctx );
9901 switch ( Printer->printer_type ) {
9902 case SPLHND_PORTMON_TCP:
9903 return process_xcvtcp_command( p->pipe_user.nt_user_token, command,
9904 &q_u->indata, &r_u->outdata, &r_u->needed );
9905 case SPLHND_PORTMON_LOCAL:
9906 return process_xcvlocal_command( p->pipe_user.nt_user_token, command,
9907 &q_u->indata, &r_u->outdata, &r_u->needed );
9910 return WERR_INVALID_PRINT_MONITOR;