xref: /illumos-gate/usr/src/cmd/lp/cmd/lpsched/validate.c (revision 1333d647b6ccdbd6cd8658a0b035eb82c34ae5bb)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
545916cd2Sjpk  * Common Development and Distribution License (the "License").
645916cd2Sjpk  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*1333d647Skeerthi  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
277c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate 
3045916cd2Sjpk #pragma ident	"%Z%%M%	%I%	%E% SMI"
3145916cd2Sjpk /* SVr4.0 1.11.1.10	*/
327c478bd9Sstevel@tonic-gate /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include "lpsched.h"
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #include "validate.h"
377c478bd9Sstevel@tonic-gate 
3845916cd2Sjpk #include <syslog.h>
3945916cd2Sjpk #include <errno.h>
4045916cd2Sjpk #include <deflt.h>
4145916cd2Sjpk #include <tsol/label.h>
4245916cd2Sjpk #include <auth_list.h>
4345916cd2Sjpk 
447c478bd9Sstevel@tonic-gate #define register auto
457c478bd9Sstevel@tonic-gate 
4645916cd2Sjpk 
477c478bd9Sstevel@tonic-gate int		pickfilter ( RSTATUS * , CANDIDATE * , FSTATUS * );
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate unsigned long		chkprinter_result	= 0;
507c478bd9Sstevel@tonic-gate char *			o_cpi		= 0;
517c478bd9Sstevel@tonic-gate char *			o_lpi		= 0;
527c478bd9Sstevel@tonic-gate char *			o_width		= 0;
537c478bd9Sstevel@tonic-gate char *			o_length	= 0;
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate static int		wants_nobanner	= 0;
5645916cd2Sjpk static int		wants_nolabels	= 0;
577c478bd9Sstevel@tonic-gate static int		lp_or_root	= 0;
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate static int		_chkopts ( RSTATUS *, CANDIDATE * , FSTATUS * );
607c478bd9Sstevel@tonic-gate static void		free_candidate ( CANDIDATE * );
6145916cd2Sjpk static int		tsol_check_printer_label_range(char *, const char *);
6245916cd2Sjpk static int		tsol_lpauth(char *, char *);
6345916cd2Sjpk static int		secpolicy_chkpolicy(char *policyp);
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate /**
667c478bd9Sstevel@tonic-gate  ** _validate() - FIND A PRINTER TO HANDLE A REQUEST
677c478bd9Sstevel@tonic-gate  **/
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate short
707c478bd9Sstevel@tonic-gate _validate(RSTATUS *prs, PSTATUS *pps, PSTATUS *stop_pps, char **prefixp,
717c478bd9Sstevel@tonic-gate 	 int moving)
727c478bd9Sstevel@tonic-gate {
737c478bd9Sstevel@tonic-gate 	register CANDIDATE	*pc		= 0,
747c478bd9Sstevel@tonic-gate 				*pcend,
757c478bd9Sstevel@tonic-gate 				*best_pc	= 0;
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate 	register FSTATUS	*pfs		= 0;
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate 	register CSTATUS	*pcs		= 0;
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate 	CANDIDATE		*arena		= 0,
827c478bd9Sstevel@tonic-gate 				single;
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate 	size_t			n;
850a44ef6dSjacobs 	int i;
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate 	short			ret;
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate 	chkprinter_result = 0;
907c478bd9Sstevel@tonic-gate 	o_cpi = o_lpi = o_width = o_length = 0;
917c478bd9Sstevel@tonic-gate 	wants_nobanner = 0;
927c478bd9Sstevel@tonic-gate 	memset (&single, 0, sizeof(single));
937c478bd9Sstevel@tonic-gate 
9445916cd2Sjpk 	wants_nolabels = 0;
9545916cd2Sjpk 	/*
9645916cd2Sjpk 	 * If the system is labeled, the printing of postscript files
9745916cd2Sjpk 	 * is restricted.  All users can print postscript files if the
9845916cd2Sjpk 	 * file /etc/default/print contains "PRINT_POSTSCRIPT=1".
9945916cd2Sjpk 	 * (this is checked by secpolicy_chkpolicy).  Otherwise the
10045916cd2Sjpk 	 * user must have PRINT_POSTSCRIPT_AUTH to print postscript files.
10145916cd2Sjpk 	 */
10245916cd2Sjpk 	if ((is_system_labeled() &&
10345916cd2Sjpk 	    strcmp(prs->request->input_type, "postscript") == 0) &&
10445916cd2Sjpk 	    (secpolicy_chkpolicy("PRINT_POSTSCRIPT=") == 0)) {
10545916cd2Sjpk 		if (tsol_lpauth(PRINT_POSTSCRIPT_AUTH, prs->secure->user)
10645916cd2Sjpk 		    == 0) {
10745916cd2Sjpk 			ret = MDENYDEST;
10845916cd2Sjpk 			goto Return;
10945916cd2Sjpk 		}
11045916cd2Sjpk 	}
1117c478bd9Sstevel@tonic-gate 	lp_or_root = 0;
1127c478bd9Sstevel@tonic-gate 
1130a44ef6dSjacobs 	if (bangequ(prs->secure->user, "root") ||
1140a44ef6dSjacobs 	    bangequ(prs->secure->user, "lp"))
1157c478bd9Sstevel@tonic-gate 			lp_or_root = 1;
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate 	if (prefixp)
1187c478bd9Sstevel@tonic-gate 		*prefixp = prs->request->destination;
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate 	/*
1217c478bd9Sstevel@tonic-gate 	 * If a destination other than "any" was given,
1227c478bd9Sstevel@tonic-gate 	 * see if it exists in our internal tables.
1237c478bd9Sstevel@tonic-gate 	 */
1247c478bd9Sstevel@tonic-gate 	if (!pps && prs->request->destination &&
1257c478bd9Sstevel@tonic-gate 	    !STREQU(prs->request->destination, NAME_ANY))
1260a44ef6dSjacobs 		if (((pps = search_pstatus(prs->request->destination)) != NULL) ||
1270a44ef6dSjacobs 		    ((pcs = search_cstatus(prs->request->destination)) != NULL) &&
1287c478bd9Sstevel@tonic-gate 		    pcs->class->members)
1297c478bd9Sstevel@tonic-gate 			/*EMPTY*/;
1307c478bd9Sstevel@tonic-gate 		else {
1317c478bd9Sstevel@tonic-gate 			ret = MNODEST;
1327c478bd9Sstevel@tonic-gate 			goto Return;
1337c478bd9Sstevel@tonic-gate 		}
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate 	/*
1367c478bd9Sstevel@tonic-gate 	 * If we are trying to avoid a printer, but the request
1377c478bd9Sstevel@tonic-gate 	 * was destined for just that printer, we're out.
1387c478bd9Sstevel@tonic-gate 	 */
1397c478bd9Sstevel@tonic-gate 	if (pps && pps == stop_pps) {
1407c478bd9Sstevel@tonic-gate 		ret = MERRDEST;
1417c478bd9Sstevel@tonic-gate 		goto Return;
1427c478bd9Sstevel@tonic-gate 	}
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate 	/*
1457c478bd9Sstevel@tonic-gate 	 * If a form was given, see if it exists; if so,
1467c478bd9Sstevel@tonic-gate 	 * see if the user is allowed to use it.
1477c478bd9Sstevel@tonic-gate 	 * If a remote printer was specified, then don't use any local
1487c478bd9Sstevel@tonic-gate 	 * form knowledge.
1497c478bd9Sstevel@tonic-gate 	 */
1507c478bd9Sstevel@tonic-gate 	if (prs && prs->request && prs->request->form && (pps || pcs)) {
1510a44ef6dSjacobs 		if ((pfs = search_fstatus(prs->request->form))) {
1527c478bd9Sstevel@tonic-gate 			if (lp_or_root || allowed(prs->secure->user,
1537c478bd9Sstevel@tonic-gate 				pfs->users_allowed, pfs->users_denied))
1547c478bd9Sstevel@tonic-gate 				/*EMPTY*/;
1557c478bd9Sstevel@tonic-gate 			else {
1567c478bd9Sstevel@tonic-gate 				ret = MDENYMEDIA;
1577c478bd9Sstevel@tonic-gate 				goto Return;
1587c478bd9Sstevel@tonic-gate 			}
1597c478bd9Sstevel@tonic-gate 		} else {
1607c478bd9Sstevel@tonic-gate 			ret = MNOMEDIA;
1617c478bd9Sstevel@tonic-gate 			goto Return;
1627c478bd9Sstevel@tonic-gate 		}
1637c478bd9Sstevel@tonic-gate 	}
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate 	/*
1667c478bd9Sstevel@tonic-gate 	 * If the request includes -o options there may be pitch and
1677c478bd9Sstevel@tonic-gate 	 * size and no-banner requests that have to be checked. One
1687c478bd9Sstevel@tonic-gate 	 * could argue that this shouldn't be in the Spooler, because
1697c478bd9Sstevel@tonic-gate 	 * the Spooler's job is SPOOLING, not PRINTING. That's right,
1707c478bd9Sstevel@tonic-gate 	 * except that the Spooler will be making a choice of printers
1717c478bd9Sstevel@tonic-gate 	 * so it has to evaluate carefully: E.g. user wants ANY printer,
1727c478bd9Sstevel@tonic-gate 	 * so we should pick one that can handle what he/she wants.
1737c478bd9Sstevel@tonic-gate 	 *
1747c478bd9Sstevel@tonic-gate 	 * Parse out the important stuff here so we have it when we
1757c478bd9Sstevel@tonic-gate 	 * need it.
1767c478bd9Sstevel@tonic-gate 	 */
1777c478bd9Sstevel@tonic-gate 	{
1787c478bd9Sstevel@tonic-gate 		register char		**list,
1797c478bd9Sstevel@tonic-gate 					**pl;
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate 		if (
1827c478bd9Sstevel@tonic-gate 			prs->request->options
1837c478bd9Sstevel@tonic-gate 		     && (list = dashos(prs->request->options))
1847c478bd9Sstevel@tonic-gate 		) {
1857c478bd9Sstevel@tonic-gate 			for (pl = list ; *pl; pl++)
1867c478bd9Sstevel@tonic-gate 				if (STRNEQU(*pl, "cpi=", 4))
1877c478bd9Sstevel@tonic-gate 					o_cpi = Strdup(*pl + 4);
1887c478bd9Sstevel@tonic-gate 				else if (STRNEQU(*pl, "lpi=", 4))
1897c478bd9Sstevel@tonic-gate 					o_lpi = Strdup(*pl + 4);
1907c478bd9Sstevel@tonic-gate 				else if (STRNEQU(*pl, "width=", 6))
1917c478bd9Sstevel@tonic-gate 					o_width = Strdup(*pl + 6);
1927c478bd9Sstevel@tonic-gate 				else if (STRNEQU(*pl, "length=", 7))
1937c478bd9Sstevel@tonic-gate 					o_length = Strdup(*pl + 7);
1947c478bd9Sstevel@tonic-gate 				else if (STREQU(*pl, "nobanner"))
1957c478bd9Sstevel@tonic-gate 					wants_nobanner = 1;
19645916cd2Sjpk 				else if (STREQU(*pl, "nolabels"))
19745916cd2Sjpk 					wants_nolabels = 1;
1987c478bd9Sstevel@tonic-gate 			freelist (list);
1997c478bd9Sstevel@tonic-gate 		}
2007c478bd9Sstevel@tonic-gate 	}
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate 	/*
2037c478bd9Sstevel@tonic-gate 	 * This macro checks that a form has a mandatory print wheel
2047c478bd9Sstevel@tonic-gate 	 * (or character set).
2057c478bd9Sstevel@tonic-gate 	 */
2067c478bd9Sstevel@tonic-gate #define	CHKMAND(PFS) \
2077c478bd9Sstevel@tonic-gate 	( \
2087c478bd9Sstevel@tonic-gate 		(PFS) \
2097c478bd9Sstevel@tonic-gate 	     && (PFS)->form->chset \
2107c478bd9Sstevel@tonic-gate 	     && !STREQU((PFS)->form->chset, NAME_ANY) \
2117c478bd9Sstevel@tonic-gate 	     && (PFS)->form->mandatory \
2127c478bd9Sstevel@tonic-gate 	)
2137c478bd9Sstevel@tonic-gate 
2147c478bd9Sstevel@tonic-gate 	/*
2157c478bd9Sstevel@tonic-gate 	 * This macro checks that the user is allowed to use the
2167c478bd9Sstevel@tonic-gate 	 * printer.
2177c478bd9Sstevel@tonic-gate 	 */
2187c478bd9Sstevel@tonic-gate #define CHKU(PRS,PPS) \
2197c478bd9Sstevel@tonic-gate 	( \
2207c478bd9Sstevel@tonic-gate 		lp_or_root \
2217c478bd9Sstevel@tonic-gate 	     || allowed( \
2227c478bd9Sstevel@tonic-gate 			(PRS)->secure->user, \
2237c478bd9Sstevel@tonic-gate 			(PPS)->users_allowed, \
2247c478bd9Sstevel@tonic-gate 			(PPS)->users_denied \
2257c478bd9Sstevel@tonic-gate 		) \
2267c478bd9Sstevel@tonic-gate 	)
2277c478bd9Sstevel@tonic-gate 
2287c478bd9Sstevel@tonic-gate 	/*
2297c478bd9Sstevel@tonic-gate 	 * This macro checks that the form is allowed on the printer,
2307c478bd9Sstevel@tonic-gate 	 * or is already mounted there.
2317c478bd9Sstevel@tonic-gate 	 * Note: By doing this check we don't have to check that the
2327c478bd9Sstevel@tonic-gate 	 * characteristics of the form, such as pitch, size, or
2337c478bd9Sstevel@tonic-gate 	 * character set, against the printer's capabilities, ASSUMING,
2347c478bd9Sstevel@tonic-gate 	 * of course, that the allow list is correct. That is, the
2357c478bd9Sstevel@tonic-gate 	 * allow list lists forms that have already been checked against
2367c478bd9Sstevel@tonic-gate 	 * the printer!
2377c478bd9Sstevel@tonic-gate 	 */
2387c478bd9Sstevel@tonic-gate #define CHKF(PFS,PPS) \
2397c478bd9Sstevel@tonic-gate 	( \
2407c478bd9Sstevel@tonic-gate 		isFormMountedOnPrinter(PPS,PFS) \
2417c478bd9Sstevel@tonic-gate 	     || allowed( \
2427c478bd9Sstevel@tonic-gate 			(PFS)->form->name, \
2437c478bd9Sstevel@tonic-gate 			(PPS)->forms_allowed, \
2447c478bd9Sstevel@tonic-gate 			(PPS)->forms_denied \
2457c478bd9Sstevel@tonic-gate 		) \
2467c478bd9Sstevel@tonic-gate 	)
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate 	/*
2497c478bd9Sstevel@tonic-gate 	 * This macro checks that the print wheel is acceptable
2507c478bd9Sstevel@tonic-gate 	 * for the printer or is mounted. Note: If the printer doesn't
2517c478bd9Sstevel@tonic-gate 	 * take print wheels, the check passes. The check for printers
2527c478bd9Sstevel@tonic-gate 	 * that don't take print wheels is below.
2537c478bd9Sstevel@tonic-gate 	 */
2547c478bd9Sstevel@tonic-gate #define CHKPW(PW,PPS) \
2557c478bd9Sstevel@tonic-gate 	( \
2567c478bd9Sstevel@tonic-gate 		!(PPS)->printer->daisy \
2577c478bd9Sstevel@tonic-gate 	     || ( \
2587c478bd9Sstevel@tonic-gate 			(PPS)->pwheel_name \
2597c478bd9Sstevel@tonic-gate 		     && STREQU((PPS)->pwheel_name, (PW)) \
2607c478bd9Sstevel@tonic-gate 		) \
2617c478bd9Sstevel@tonic-gate 	     || searchlist((PW), (PPS)->printer->char_sets) \
2627c478bd9Sstevel@tonic-gate 	)
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate 	/*
2657c478bd9Sstevel@tonic-gate 	 * This macro checks the pitch, page size, and (if need be)
2667c478bd9Sstevel@tonic-gate 	 * the character set. The character set isn't checked if the
2677c478bd9Sstevel@tonic-gate 	 * printer takes print wheels, or if the character set is
2687c478bd9Sstevel@tonic-gate 	 * listed in the printer's alias list.
2697c478bd9Sstevel@tonic-gate 	 * The form has to be checked as well; while we're sure that
2707c478bd9Sstevel@tonic-gate 	 * at least one type for each printer can handle the form's
2717c478bd9Sstevel@tonic-gate 	 * cpi/lpi/etc. characteristics (lpadmin made sure), we aren't
2727c478bd9Sstevel@tonic-gate 	 * sure that ALL the types work.
2737c478bd9Sstevel@tonic-gate 	 */
2747c478bd9Sstevel@tonic-gate #define CHKOPTS(PRS,PC,PFS) _chkopts((PRS),(PC),(PFS)) /* was a macro */
2757c478bd9Sstevel@tonic-gate 
2767c478bd9Sstevel@tonic-gate 	/*
2777c478bd9Sstevel@tonic-gate 	 * This macro checks the acceptance status of a printer.
2787c478bd9Sstevel@tonic-gate 	 * If the request is already assigned to that printer,
2797c478bd9Sstevel@tonic-gate 	 * then it's okay. It's ambiguous what should happen if
2807c478bd9Sstevel@tonic-gate 	 * originally a "-d any" request was accepted, temporarily
2817c478bd9Sstevel@tonic-gate 	 * assigned one printer, then the administrator (1) rejected
2827c478bd9Sstevel@tonic-gate 	 * further requests for the printers and (2) made the
2837c478bd9Sstevel@tonic-gate 	 * temporarily assigned printer unusable for the request.
2847c478bd9Sstevel@tonic-gate 	 * What will happen, of course, is that the request will
2857c478bd9Sstevel@tonic-gate 	 * be canceled, even though the other printers would be okay
2867c478bd9Sstevel@tonic-gate 	 * if not rejecting....but if we were to say, gee it's okay,
2877c478bd9Sstevel@tonic-gate 	 * the request has already been accepted, we may be allowing
2887c478bd9Sstevel@tonic-gate 	 * it on printers that were NEVER accepting. Thus we can
2897c478bd9Sstevel@tonic-gate 	 * continue to accept it only for the printer already assigned.
2907c478bd9Sstevel@tonic-gate 	 */
2917c478bd9Sstevel@tonic-gate #define CHKACCEPT(PRS,PPS) \
2927c478bd9Sstevel@tonic-gate 	( \
2937c478bd9Sstevel@tonic-gate 		!((PPS)->status & PS_REJECTED) \
2947c478bd9Sstevel@tonic-gate 	     || (PRS)->printer == (PPS) \
2957c478bd9Sstevel@tonic-gate 	     || moving \
2967c478bd9Sstevel@tonic-gate 	)
2977c478bd9Sstevel@tonic-gate 
2987c478bd9Sstevel@tonic-gate 	/*
2997c478bd9Sstevel@tonic-gate 	 * If a print wheel or character set is given, see if it
3007c478bd9Sstevel@tonic-gate 	 * is allowed on the form.
3017c478bd9Sstevel@tonic-gate 	 */
3027c478bd9Sstevel@tonic-gate 	if (prs->request->charset)
3037c478bd9Sstevel@tonic-gate 		if (
3047c478bd9Sstevel@tonic-gate 			!CHKMAND(pfs)
3057c478bd9Sstevel@tonic-gate 		     || STREQU(prs->request->charset, pfs->form->chset)
3067c478bd9Sstevel@tonic-gate 		)
3077c478bd9Sstevel@tonic-gate 			/*EMPTY*/;
3087c478bd9Sstevel@tonic-gate 		else {
3097c478bd9Sstevel@tonic-gate 			ret = MDENYMEDIA;
3107c478bd9Sstevel@tonic-gate 			chkprinter_result |= PCK_CHARSET;
3117c478bd9Sstevel@tonic-gate 			goto Return;
3127c478bd9Sstevel@tonic-gate 		}
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate 	/*
3157c478bd9Sstevel@tonic-gate 	 * If a single printer was named, check the request against it.
3167c478bd9Sstevel@tonic-gate 	 * Do the accept/reject check late so that we give the most
3177c478bd9Sstevel@tonic-gate 	 * useful information to the user.
3187c478bd9Sstevel@tonic-gate 	 */
3197c478bd9Sstevel@tonic-gate 	if (pps) {
3207c478bd9Sstevel@tonic-gate 		(pc = &single)->pps = pps;
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate 		/* Does the printer allow the user? */
3237c478bd9Sstevel@tonic-gate 		if (!CHKU(prs, pps)) {
3247c478bd9Sstevel@tonic-gate 			ret = MDENYDEST;
3257c478bd9Sstevel@tonic-gate 			goto Return;
3267c478bd9Sstevel@tonic-gate 		}
3277c478bd9Sstevel@tonic-gate 
32845916cd2Sjpk 		/* Check printer label range */
32945916cd2Sjpk 		if (is_system_labeled() && prs->secure->slabel != NULL) {
33045916cd2Sjpk 			if (tsol_check_printer_label_range(
33145916cd2Sjpk 			    prs->secure->slabel,
33245916cd2Sjpk 			    pps->printer->name) == 0) {
33345916cd2Sjpk 				ret = MDENYDEST;
33445916cd2Sjpk 				goto Return;
33545916cd2Sjpk 			}
33645916cd2Sjpk 		}
33745916cd2Sjpk 
3387c478bd9Sstevel@tonic-gate 		/* Does the printer allow the form? */
3397c478bd9Sstevel@tonic-gate 		if (pfs && !CHKF(pfs, pps)) {
3407c478bd9Sstevel@tonic-gate 			ret = MNOMOUNT;
3417c478bd9Sstevel@tonic-gate 			goto Return;
3427c478bd9Sstevel@tonic-gate 		}
3437c478bd9Sstevel@tonic-gate 
3447c478bd9Sstevel@tonic-gate 		/* Does the printer allow the pwheel? */
3457c478bd9Sstevel@tonic-gate 		if (
3467c478bd9Sstevel@tonic-gate 			prs->request->charset
3477c478bd9Sstevel@tonic-gate 		     && !CHKPW(prs->request->charset, pps)
3487c478bd9Sstevel@tonic-gate 		) {
3497c478bd9Sstevel@tonic-gate 			ret = MNOMOUNT;
3507c478bd9Sstevel@tonic-gate 			goto Return;
3517c478bd9Sstevel@tonic-gate 		}
3527c478bd9Sstevel@tonic-gate 
3537c478bd9Sstevel@tonic-gate 		/* Can printer handle the pitch/size/charset/nobanner? */
3547c478bd9Sstevel@tonic-gate 		if (!CHKOPTS(prs, pc, pfs)) {
3557c478bd9Sstevel@tonic-gate 			ret = MDENYDEST;
3567c478bd9Sstevel@tonic-gate 			goto Return;
3577c478bd9Sstevel@tonic-gate 		}
3587c478bd9Sstevel@tonic-gate 
3597c478bd9Sstevel@tonic-gate 		/* Is the printer allowing requests? */
3607c478bd9Sstevel@tonic-gate 		if (!CHKACCEPT(prs, pps)) {
3617c478bd9Sstevel@tonic-gate 			ret = MERRDEST;
3627c478bd9Sstevel@tonic-gate 			goto Return;
3637c478bd9Sstevel@tonic-gate 		}
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate 		/* Is there a filter which will convert the input? */
3667c478bd9Sstevel@tonic-gate 		if (!pickfilter(prs, pc, pfs)) {
3677c478bd9Sstevel@tonic-gate 			ret = MNOFILTER;
3687c478bd9Sstevel@tonic-gate 			goto Return;
3697c478bd9Sstevel@tonic-gate 		}
3707c478bd9Sstevel@tonic-gate 
3717c478bd9Sstevel@tonic-gate 		best_pc = pc;
3727c478bd9Sstevel@tonic-gate 		ret = MOK;
3737c478bd9Sstevel@tonic-gate 		goto Return;
3747c478bd9Sstevel@tonic-gate 	}
3757c478bd9Sstevel@tonic-gate 
3767c478bd9Sstevel@tonic-gate 	/*
3777c478bd9Sstevel@tonic-gate 	 * Do the acceptance check on the class (if we have one)
3787c478bd9Sstevel@tonic-gate 	 * now so we can proceed with checks on individual printers
3797c478bd9Sstevel@tonic-gate 	 * in the class. Don't toss out the request if it is already
3807c478bd9Sstevel@tonic-gate 	 * assigned a printer just because the class is NOW rejecting.
3817c478bd9Sstevel@tonic-gate 	 */
3827c478bd9Sstevel@tonic-gate 	if (
3837c478bd9Sstevel@tonic-gate 		pcs
3847c478bd9Sstevel@tonic-gate 	     && (pcs->status & CS_REJECTED)
3857c478bd9Sstevel@tonic-gate 	     && !moving
3867c478bd9Sstevel@tonic-gate 	     && !prs->printer
3877c478bd9Sstevel@tonic-gate 	) {
3887c478bd9Sstevel@tonic-gate 		ret = MERRDEST;
3897c478bd9Sstevel@tonic-gate 		goto Return;
3907c478bd9Sstevel@tonic-gate 	}
3917c478bd9Sstevel@tonic-gate 
3927c478bd9Sstevel@tonic-gate 	/*
3937c478bd9Sstevel@tonic-gate 	 * Construct a list of printers based on the destination
3947c478bd9Sstevel@tonic-gate 	 * given. Cross off those that aren't accepting requests,
3957c478bd9Sstevel@tonic-gate 	 * that can't take the form, or which the user can't use.
3967c478bd9Sstevel@tonic-gate 	 * See if the list becomes empty.
3977c478bd9Sstevel@tonic-gate 	 */
3987c478bd9Sstevel@tonic-gate 
3997c478bd9Sstevel@tonic-gate 	if (pcs)
4007c478bd9Sstevel@tonic-gate 		n = lenlist(pcs->class->members);
4017c478bd9Sstevel@tonic-gate 	else {
4020a44ef6dSjacobs 		for (n = 0; PStatus != NULL && PStatus[n] != NULL; n++) ;
4037c478bd9Sstevel@tonic-gate 	}
4047c478bd9Sstevel@tonic-gate 	pcend = arena = (CANDIDATE *)Calloc(n, sizeof(CANDIDATE));
4057c478bd9Sstevel@tonic-gate 
4067c478bd9Sstevel@tonic-gate 	/*
4077c478bd9Sstevel@tonic-gate 	 * Start with a list of printers that are accepting requests.
4087c478bd9Sstevel@tonic-gate 	 * Don't skip a printer if it's rejecting but the request
4097c478bd9Sstevel@tonic-gate 	 * has already been accepted for it.
4107c478bd9Sstevel@tonic-gate 	 */
4117c478bd9Sstevel@tonic-gate 	if (pcs) {
4127c478bd9Sstevel@tonic-gate 		register char		 **pn;
4137c478bd9Sstevel@tonic-gate 
4147c478bd9Sstevel@tonic-gate 		for (pn = pcs->class->members; *pn; pn++)
4157c478bd9Sstevel@tonic-gate 			if (
4160a44ef6dSjacobs 				((pps = search_pstatus(*pn)) != NULL)
4177c478bd9Sstevel@tonic-gate 			     && pps != stop_pps
4187c478bd9Sstevel@tonic-gate 			)
4197c478bd9Sstevel@tonic-gate 				(pcend++)->pps = pps;
4207c478bd9Sstevel@tonic-gate 
4217c478bd9Sstevel@tonic-gate 
4227c478bd9Sstevel@tonic-gate 	} else
4230a44ef6dSjacobs 		for (i = 0; PStatus != NULL && PStatus[i] != NULL; i++) {
4240a44ef6dSjacobs 			pps = PStatus[i];
4250a44ef6dSjacobs 
4267c478bd9Sstevel@tonic-gate 			if (CHKACCEPT(prs, pps) && pps != stop_pps)
4277c478bd9Sstevel@tonic-gate 				(pcend++)->pps = pps;
4280a44ef6dSjacobs 		}
4297c478bd9Sstevel@tonic-gate 
4307c478bd9Sstevel@tonic-gate 	if (pcend == arena) {
4317c478bd9Sstevel@tonic-gate 		ret = MERRDEST;
4327c478bd9Sstevel@tonic-gate 		goto Return;
4337c478bd9Sstevel@tonic-gate 	}
4347c478bd9Sstevel@tonic-gate 
4357c478bd9Sstevel@tonic-gate 	/*
4367c478bd9Sstevel@tonic-gate 	 * Clean out printers that the user can't use. We piggy-back
4377c478bd9Sstevel@tonic-gate 	 * the pitch/size/banner checks here because the same error return
4387c478bd9Sstevel@tonic-gate 	 * is given (strange, eh?).
4397c478bd9Sstevel@tonic-gate 	 */
4407c478bd9Sstevel@tonic-gate 	{
4417c478bd9Sstevel@tonic-gate 		register CANDIDATE	*pcend2;
4427c478bd9Sstevel@tonic-gate 
4437c478bd9Sstevel@tonic-gate 		for (pcend2 = pc = arena; pc < pcend; pc++) {
4447c478bd9Sstevel@tonic-gate 			if (CHKU(prs, pc->pps) && CHKOPTS(prs, pc, pfs))
4457c478bd9Sstevel@tonic-gate 				*pcend2++ = *pc;
4467c478bd9Sstevel@tonic-gate 			else
4477c478bd9Sstevel@tonic-gate 				free_candidate (pc);
4487c478bd9Sstevel@tonic-gate 		}
4497c478bd9Sstevel@tonic-gate 
4507c478bd9Sstevel@tonic-gate 		if (pcend2 == arena) {
4517c478bd9Sstevel@tonic-gate 			ret = MDENYDEST;
4527c478bd9Sstevel@tonic-gate 			goto Return;
4537c478bd9Sstevel@tonic-gate 		}
4547c478bd9Sstevel@tonic-gate 		pcend = pcend2;
4557c478bd9Sstevel@tonic-gate 
4567c478bd9Sstevel@tonic-gate 	}
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate 	/*
4597c478bd9Sstevel@tonic-gate 	 * Clean out printers that can't mount the form,
4607c478bd9Sstevel@tonic-gate 	 * EXCEPT for printers that already have it mounted:
4617c478bd9Sstevel@tonic-gate 	 */
4627c478bd9Sstevel@tonic-gate 	if (pfs) {
4637c478bd9Sstevel@tonic-gate 		register CANDIDATE	*pcend2;
4647c478bd9Sstevel@tonic-gate 
4657c478bd9Sstevel@tonic-gate 		for (pcend2 = pc = arena; pc < pcend; pc++)
4667c478bd9Sstevel@tonic-gate 			if (CHKF(pfs, pc->pps))
4677c478bd9Sstevel@tonic-gate 				*pcend2++ = *pc;
4687c478bd9Sstevel@tonic-gate 			else
4697c478bd9Sstevel@tonic-gate 				free_candidate (pc);
4707c478bd9Sstevel@tonic-gate 
4717c478bd9Sstevel@tonic-gate 		if (pcend2 == arena) {
4727c478bd9Sstevel@tonic-gate 			ret = MNOMOUNT;
4737c478bd9Sstevel@tonic-gate 			goto Return;
4747c478bd9Sstevel@tonic-gate 		}
4757c478bd9Sstevel@tonic-gate 		pcend = pcend2;
4767c478bd9Sstevel@tonic-gate 
4777c478bd9Sstevel@tonic-gate 	}
4787c478bd9Sstevel@tonic-gate 
4797c478bd9Sstevel@tonic-gate 	/*
4807c478bd9Sstevel@tonic-gate 	 * Clean out printers that can't take the print wheel
4817c478bd9Sstevel@tonic-gate 	 * EXCEPT for printers that already have it mounted
4827c478bd9Sstevel@tonic-gate 	 * or printers for which it is a selectable character set:
4837c478bd9Sstevel@tonic-gate 	 */
4847c478bd9Sstevel@tonic-gate 	if (prs->request->charset) {
4857c478bd9Sstevel@tonic-gate 		register CANDIDATE	*pcend2;
4867c478bd9Sstevel@tonic-gate 
4877c478bd9Sstevel@tonic-gate 		for (pcend2 = pc = arena; pc < pcend; pc++)
4887c478bd9Sstevel@tonic-gate 			if (CHKPW(prs->request->charset, pc->pps))
4897c478bd9Sstevel@tonic-gate 				*pcend2++ = *pc;
4907c478bd9Sstevel@tonic-gate 			else
4917c478bd9Sstevel@tonic-gate 				free_candidate (pc);
4927c478bd9Sstevel@tonic-gate 
4937c478bd9Sstevel@tonic-gate 		if (pcend2 == arena) {
4947c478bd9Sstevel@tonic-gate 			ret = MNOMOUNT;
4957c478bd9Sstevel@tonic-gate 			goto Return;
4967c478bd9Sstevel@tonic-gate 		}
4977c478bd9Sstevel@tonic-gate 		pcend = pcend2;
4987c478bd9Sstevel@tonic-gate 
4997c478bd9Sstevel@tonic-gate 	}
5007c478bd9Sstevel@tonic-gate 
5017c478bd9Sstevel@tonic-gate 	/*
5027c478bd9Sstevel@tonic-gate 	 * Clean out printers that can't handle the printing
5037c478bd9Sstevel@tonic-gate 	 * and for which there's no filter to convert the input.
5047c478bd9Sstevel@tonic-gate 	 *
5057c478bd9Sstevel@tonic-gate 	 */
5067c478bd9Sstevel@tonic-gate 
5077c478bd9Sstevel@tonic-gate 	/*
5087c478bd9Sstevel@tonic-gate 	 * Is the form mounted, or is none needed?
5097c478bd9Sstevel@tonic-gate 	 */
5107c478bd9Sstevel@tonic-gate #define CHKFMNT(PFS,PPS) (isFormUsableOnPrinter(PPS,PFS))
5117c478bd9Sstevel@tonic-gate 
5127c478bd9Sstevel@tonic-gate 	/*
5137c478bd9Sstevel@tonic-gate 	 * Is the print-wheel mounted, or is none needed?
5147c478bd9Sstevel@tonic-gate 	 */
5157c478bd9Sstevel@tonic-gate #define CHKPWMNT(PRS,PPS) SAME((PPS)->pwheel_name, (PRS)->request->charset)
5167c478bd9Sstevel@tonic-gate 
5177c478bd9Sstevel@tonic-gate 	/*
5187c478bd9Sstevel@tonic-gate 	 * Do we NOT need a special character set, or can we select
5197c478bd9Sstevel@tonic-gate 	 * it on the printer? Note: Getting this far means that IF
5207c478bd9Sstevel@tonic-gate 	 * the printer has selectable character sets (!daisy) then
5217c478bd9Sstevel@tonic-gate 	 * it can select the one we want.
5227c478bd9Sstevel@tonic-gate 	 */
5237c478bd9Sstevel@tonic-gate #define CHKCHSET(PRS,PPS) \
5247c478bd9Sstevel@tonic-gate 	( \
5257c478bd9Sstevel@tonic-gate 		!(PRS)->request->charset \
5267c478bd9Sstevel@tonic-gate 	     || !(PPS)->printer->daisy \
5277c478bd9Sstevel@tonic-gate 	)
5287c478bd9Sstevel@tonic-gate 
5297c478bd9Sstevel@tonic-gate 	/*
5307c478bd9Sstevel@tonic-gate 	 * Is the printer able to print now?
5317c478bd9Sstevel@tonic-gate 	 */
5327c478bd9Sstevel@tonic-gate #define CHKENB(PPS)	 (!((PPS)->status & (PS_DISABLED|PS_FAULTED)))
5337c478bd9Sstevel@tonic-gate 
5347c478bd9Sstevel@tonic-gate 	/*
5357c478bd9Sstevel@tonic-gate 	 * Is the printer not busy printing another request, or
5367c478bd9Sstevel@tonic-gate 	 * not awaiting an auto-retry after a fault?
5377c478bd9Sstevel@tonic-gate 	 */
5387c478bd9Sstevel@tonic-gate #define CHKFREE(PPS)	 (!((PPS)->status & (PS_BUSY|PS_LATER)))
5397c478bd9Sstevel@tonic-gate 
5407c478bd9Sstevel@tonic-gate 	{
5417c478bd9Sstevel@tonic-gate 		register CANDIDATE	*pcend2;
5427c478bd9Sstevel@tonic-gate 
5437c478bd9Sstevel@tonic-gate 		for (pcend2 = pc = arena; pc < pcend; pc++)
5447c478bd9Sstevel@tonic-gate 			if (pickfilter(prs, pc, pfs)) {
5457c478bd9Sstevel@tonic-gate 
5467c478bd9Sstevel@tonic-gate 				/*
5477c478bd9Sstevel@tonic-gate 				 * Compute a ``weight'' for this printer,
5487c478bd9Sstevel@tonic-gate 				 * based on its status. We'll later pick
5497c478bd9Sstevel@tonic-gate 				 * the printer with the highest weight.
5507c478bd9Sstevel@tonic-gate 				 */
5517c478bd9Sstevel@tonic-gate 				pc->weight = 0;
5527c478bd9Sstevel@tonic-gate 				if (!pc->fast && !pc->slow)
5537c478bd9Sstevel@tonic-gate 					pc->weight += WEIGHT_NOFILTER;
5547c478bd9Sstevel@tonic-gate 				if (CHKFREE(pc->pps))
5557c478bd9Sstevel@tonic-gate 					pc->weight += WEIGHT_FREE;
5567c478bd9Sstevel@tonic-gate 				if (CHKENB(pc->pps))
5577c478bd9Sstevel@tonic-gate 					pc->weight += WEIGHT_ENABLED;
5587c478bd9Sstevel@tonic-gate 				if (CHKFMNT(pfs, pc->pps))
5597c478bd9Sstevel@tonic-gate 					pc->weight += WEIGHT_MOUNTED;
5607c478bd9Sstevel@tonic-gate 				if (CHKPWMNT(prs, pc->pps))
5617c478bd9Sstevel@tonic-gate 					pc->weight += WEIGHT_MOUNTED;
5627c478bd9Sstevel@tonic-gate 				if (CHKCHSET(prs, pc->pps))
5637c478bd9Sstevel@tonic-gate 					pc->weight += WEIGHT_SELECTS;
5647c478bd9Sstevel@tonic-gate 
5657c478bd9Sstevel@tonic-gate #if	defined(FILTER_EARLY_OUT)
5667c478bd9Sstevel@tonic-gate 				if (pc->weight == WEIGHT_MAX) {
5677c478bd9Sstevel@tonic-gate 					/*
5687c478bd9Sstevel@tonic-gate 					 * This is the one!
5697c478bd9Sstevel@tonic-gate 					 */
5707c478bd9Sstevel@tonic-gate 					best_pc = pc;
5717c478bd9Sstevel@tonic-gate 					ret = MOK;
5727c478bd9Sstevel@tonic-gate 					goto Return;
5737c478bd9Sstevel@tonic-gate 				}
5747c478bd9Sstevel@tonic-gate #endif
5757c478bd9Sstevel@tonic-gate 				/*
5767c478bd9Sstevel@tonic-gate 				 * This is a candidate!
5777c478bd9Sstevel@tonic-gate 				 */
5787c478bd9Sstevel@tonic-gate 				*pcend2++ = *pc;
5797c478bd9Sstevel@tonic-gate 
5807c478bd9Sstevel@tonic-gate 			} else
5817c478bd9Sstevel@tonic-gate 				/*
5827c478bd9Sstevel@tonic-gate 				 * No filter for this one!
5837c478bd9Sstevel@tonic-gate 				 */
5847c478bd9Sstevel@tonic-gate 				free_candidate (pc);
5857c478bd9Sstevel@tonic-gate 
5867c478bd9Sstevel@tonic-gate 		if (pcend2 == arena) {
5877c478bd9Sstevel@tonic-gate 			ret = MNOFILTER;
5887c478bd9Sstevel@tonic-gate 			goto Return;
5897c478bd9Sstevel@tonic-gate 		}
5907c478bd9Sstevel@tonic-gate 		pcend = pcend2;
5917c478bd9Sstevel@tonic-gate 
5927c478bd9Sstevel@tonic-gate 	}
5937c478bd9Sstevel@tonic-gate 
5947c478bd9Sstevel@tonic-gate 	if (pcend - arena == 1) {
5957c478bd9Sstevel@tonic-gate 		best_pc = arena;
5967c478bd9Sstevel@tonic-gate 		ret = MOK;
5977c478bd9Sstevel@tonic-gate 		goto Return;
5987c478bd9Sstevel@tonic-gate 	}
59945916cd2Sjpk 	/*
60045916cd2Sjpk 	 * Clean out local printers
60145916cd2Sjpk 	 * where the request is outside the printer label range.
60245916cd2Sjpk 	 */
60345916cd2Sjpk 	{
604*1333d647Skeerthi 		register CANDIDATE	*pcend2 = pcend;
60545916cd2Sjpk 
60645916cd2Sjpk 		if (is_system_labeled()) {
60745916cd2Sjpk 			for (pcend2 = pc = arena; pc < pcend; pc++) {
60845916cd2Sjpk 				if (tsol_check_printer_label_range(
60945916cd2Sjpk 				    prs->secure->slabel,
61045916cd2Sjpk 				    pps->printer->name) == 1)
61145916cd2Sjpk 					*pcend2++ = *pc;
61245916cd2Sjpk 				else
61345916cd2Sjpk 					free_candidate(pc);
61445916cd2Sjpk 			}
61545916cd2Sjpk 		}
61645916cd2Sjpk 
61745916cd2Sjpk 		if (pcend2 == arena) {
61845916cd2Sjpk 			ret = MDENYDEST;
61945916cd2Sjpk 			goto Return;
62045916cd2Sjpk 		}
62145916cd2Sjpk 		pcend = pcend2;
62245916cd2Sjpk 	}
6237c478bd9Sstevel@tonic-gate 
6247c478bd9Sstevel@tonic-gate #if	defined(OTHER_FACTORS)
6257c478bd9Sstevel@tonic-gate 	/*
6267c478bd9Sstevel@tonic-gate 	 * Here you might want to add code that considers
6277c478bd9Sstevel@tonic-gate 	 * other factors: the size of the file(s) to be
6287c478bd9Sstevel@tonic-gate 	 * printed ("prs->secure->size") in relation to the
6297c478bd9Sstevel@tonic-gate 	 * printer (e.g. printer A gets mostly large
6307c478bd9Sstevel@tonic-gate 	 * files, printer B gets mostly small files); the
6317c478bd9Sstevel@tonic-gate 	 * number/total-size of requests currently queued
6327c478bd9Sstevel@tonic-gate 	 * for the printer; etc.
6337c478bd9Sstevel@tonic-gate 	 *
6347c478bd9Sstevel@tonic-gate 	 * If your code includes eliminating printers drop them
6357c478bd9Sstevel@tonic-gate 	 * from the list (as done in several places above).
6367c478bd9Sstevel@tonic-gate 	 * Otherwise, your code should add weights to the weight
6377c478bd9Sstevel@tonic-gate 	 * already computed. Change the WEIGHT_MAX, increase the
6387c478bd9Sstevel@tonic-gate 	 * other WEIGHT_X values to compensate, etc., as appropriate.
6397c478bd9Sstevel@tonic-gate 	 */
6407c478bd9Sstevel@tonic-gate 	;
6417c478bd9Sstevel@tonic-gate #endif
6427c478bd9Sstevel@tonic-gate 
6437c478bd9Sstevel@tonic-gate 	/*
6447c478bd9Sstevel@tonic-gate 	 * Pick the best printer from a list of eligible candidates.
6457c478bd9Sstevel@tonic-gate 	 */
6467c478bd9Sstevel@tonic-gate 	best_pc = arena;
6477c478bd9Sstevel@tonic-gate 	for (pc = arena + 1; pc < pcend; pc++)
6487c478bd9Sstevel@tonic-gate 		if (pc->weight > best_pc->weight)
6497c478bd9Sstevel@tonic-gate 			best_pc = pc;
6507c478bd9Sstevel@tonic-gate 	ret = MOK;
6517c478bd9Sstevel@tonic-gate 
6527c478bd9Sstevel@tonic-gate 	/*
6537c478bd9Sstevel@tonic-gate 	 * Branch to here if MOK and/or if things have been allocated.
6547c478bd9Sstevel@tonic-gate 	 */
6557c478bd9Sstevel@tonic-gate Return:	if (ret == MOK) {
6567c478bd9Sstevel@tonic-gate 		register USER		*pu = Getuser(prs->secure->user);
6577c478bd9Sstevel@tonic-gate 
6587c478bd9Sstevel@tonic-gate 		register char		*pwheel_name;
6597c478bd9Sstevel@tonic-gate 
6607c478bd9Sstevel@tonic-gate 		PSTATUS			*oldpps = prs->printer;
6617c478bd9Sstevel@tonic-gate 
6627c478bd9Sstevel@tonic-gate 
6637c478bd9Sstevel@tonic-gate 		/*
6647c478bd9Sstevel@tonic-gate 		 * We are going to accept this print request, having
6657c478bd9Sstevel@tonic-gate 		 * found a printer for it. This printer will be assigned
6667c478bd9Sstevel@tonic-gate 		 * to the request, although this assignment may be
6677c478bd9Sstevel@tonic-gate 		 * temporary if other printers qualify and this printer
6687c478bd9Sstevel@tonic-gate 		 * is changed to no longer qualify. Qualification in
6697c478bd9Sstevel@tonic-gate 		 * this context includes being ready to print!
6707c478bd9Sstevel@tonic-gate 		 */
6717c478bd9Sstevel@tonic-gate 		prs->printer = best_pc->pps;
6727c478bd9Sstevel@tonic-gate 		load_str (&(prs->printer_type), best_pc->printer_type);
6737c478bd9Sstevel@tonic-gate 
6747c478bd9Sstevel@tonic-gate 		/*
6757c478bd9Sstevel@tonic-gate 		 * Assign the form (if any) to the request. Adjust
6767c478bd9Sstevel@tonic-gate 		 * the number of requests queued for old and new form
6777c478bd9Sstevel@tonic-gate 		 * accordingly.
6787c478bd9Sstevel@tonic-gate 		 */
6797c478bd9Sstevel@tonic-gate 		if (prs->form != pfs) {
6807c478bd9Sstevel@tonic-gate 			unqueue_form (prs);
6817c478bd9Sstevel@tonic-gate 			queue_form (prs, pfs);
6827c478bd9Sstevel@tonic-gate 		}
6837c478bd9Sstevel@tonic-gate 
6847c478bd9Sstevel@tonic-gate 		/*
6857c478bd9Sstevel@tonic-gate 		 * Ditto for the print wheel, except include here the
6867c478bd9Sstevel@tonic-gate 		 * print wheel needed by the form.
6877c478bd9Sstevel@tonic-gate 		 * CAUTION: When checking this request later, don't
6887c478bd9Sstevel@tonic-gate 		 * refuse to service it if the print wheel for the
6897c478bd9Sstevel@tonic-gate 		 * form isn't mounted but the form is; a mounted form
6907c478bd9Sstevel@tonic-gate 		 * overrides its other needs. Don't be confused by the
6917c478bd9Sstevel@tonic-gate 		 * name of the bit, RSS_PWMAND; a printer that prints
6927c478bd9Sstevel@tonic-gate 		 * this request MUST have the print wheel mounted
6937c478bd9Sstevel@tonic-gate 		 * (if it takes print wheels) if the user asked for
6947c478bd9Sstevel@tonic-gate 		 * a particular print wheel.
6957c478bd9Sstevel@tonic-gate 		 */
6967c478bd9Sstevel@tonic-gate 		prs->status &= ~RSS_PWMAND;
6977c478bd9Sstevel@tonic-gate 		if (CHKMAND(pfs))
6987c478bd9Sstevel@tonic-gate 			pwheel_name = pfs->form->chset;
6997c478bd9Sstevel@tonic-gate 		else
7007c478bd9Sstevel@tonic-gate 			if ((pwheel_name = prs->request->charset) != NULL)
7017c478bd9Sstevel@tonic-gate 				prs->status |= RSS_PWMAND;
7027c478bd9Sstevel@tonic-gate 
7037c478bd9Sstevel@tonic-gate 		if (!SAME(pwheel_name, prs->pwheel_name)) {
7047c478bd9Sstevel@tonic-gate 			unqueue_pwheel (prs);
7057c478bd9Sstevel@tonic-gate 			queue_pwheel (prs, pwheel_name);
7067c478bd9Sstevel@tonic-gate 		}
7077c478bd9Sstevel@tonic-gate 
7087c478bd9Sstevel@tonic-gate 		/*
7097c478bd9Sstevel@tonic-gate 		 * Adjust the priority to lie within the limits allowed
7107c478bd9Sstevel@tonic-gate 		 * for the user (this is a silent adjustment as required).
7117c478bd9Sstevel@tonic-gate 		 * CURRENTLY, ONLY NEW REQUESTS WILL GET QUEUED ACCORDING
7127c478bd9Sstevel@tonic-gate 		 * TO THIS PRIORITY. EXISTING REQUESTS BEING (RE)EVALUATED
7137c478bd9Sstevel@tonic-gate 		 * WILL NOT BE REQUEUED.
7147c478bd9Sstevel@tonic-gate 		 * A wild priority is changed to the default, or the
7157c478bd9Sstevel@tonic-gate 		 * limit, whichever is the lower priority (higher value).
7167c478bd9Sstevel@tonic-gate 		 */
7177c478bd9Sstevel@tonic-gate 		if (prs->request->priority < 0 || 39 < prs->request->priority)
7187c478bd9Sstevel@tonic-gate 			prs->request->priority = getdfltpri();
7197c478bd9Sstevel@tonic-gate 		if (pu && prs->request->priority < pu->priority_limit)
7207c478bd9Sstevel@tonic-gate 			prs->request->priority = pu->priority_limit;
7217c478bd9Sstevel@tonic-gate 
7227c478bd9Sstevel@tonic-gate 		/*
7237c478bd9Sstevel@tonic-gate 		 * If a filter is involved, change the number of
7247c478bd9Sstevel@tonic-gate 		 * copies to 1 (if the filter handles it).
7257c478bd9Sstevel@tonic-gate 		 */
7267c478bd9Sstevel@tonic-gate 		if (
7277c478bd9Sstevel@tonic-gate 			(best_pc->fast || best_pc->slow)
7287c478bd9Sstevel@tonic-gate 		     && (best_pc->flags & FPARM_COPIES)
7297c478bd9Sstevel@tonic-gate 		     && prs->request->copies > 1
7307c478bd9Sstevel@tonic-gate 		)
7317c478bd9Sstevel@tonic-gate 			prs->copies = 1;
7327c478bd9Sstevel@tonic-gate 		else
7337c478bd9Sstevel@tonic-gate 			/*
7347c478bd9Sstevel@tonic-gate 			 * We use two ".copies" because we don't
7357c478bd9Sstevel@tonic-gate 			 * want to lose track of the number requested,
7367c478bd9Sstevel@tonic-gate 			 * but do want to mark the number the interface
7377c478bd9Sstevel@tonic-gate 			 * program is to handle. Here is the best
7387c478bd9Sstevel@tonic-gate 			 * place to know this.
7397c478bd9Sstevel@tonic-gate 			 */
7407c478bd9Sstevel@tonic-gate 			prs->copies = prs->request->copies;
7417c478bd9Sstevel@tonic-gate 
7427c478bd9Sstevel@tonic-gate 		if (best_pc->slow) {
7437c478bd9Sstevel@tonic-gate 			/*
7447c478bd9Sstevel@tonic-gate 			 * If the filter has changed, the request will
7457c478bd9Sstevel@tonic-gate 			 * have to be refiltered. This may mean stopping
7467c478bd9Sstevel@tonic-gate 			 * a currently running filter or interface.
7477c478bd9Sstevel@tonic-gate 			 */
7487c478bd9Sstevel@tonic-gate 			if (!SAME(best_pc->slow, prs->slow)) {
7497c478bd9Sstevel@tonic-gate 
7507c478bd9Sstevel@tonic-gate 			    if (prs->request->outcome & RS_FILTERED)
7517c478bd9Sstevel@tonic-gate 				prs->request->outcome &= ~RS_FILTERED;
7527c478bd9Sstevel@tonic-gate 
7537c478bd9Sstevel@tonic-gate 			    if (
7547c478bd9Sstevel@tonic-gate 				prs->request->outcome & RS_FILTERING
7557c478bd9Sstevel@tonic-gate 			     && !(prs->request->outcome & RS_STOPPED)
7567c478bd9Sstevel@tonic-gate 			    ) {
7577c478bd9Sstevel@tonic-gate 				prs->request->outcome |= RS_REFILTER;
7587c478bd9Sstevel@tonic-gate 				prs->request->outcome |= RS_STOPPED;
7597c478bd9Sstevel@tonic-gate 				terminate (prs->exec);
7607c478bd9Sstevel@tonic-gate 
7617c478bd9Sstevel@tonic-gate 			    } else if (
7627c478bd9Sstevel@tonic-gate 				prs->request->outcome & RS_PRINTING
7637c478bd9Sstevel@tonic-gate 			     && !(prs->request->outcome & RS_STOPPED)
7647c478bd9Sstevel@tonic-gate 			    ) {
7657c478bd9Sstevel@tonic-gate 				prs->request->outcome |= RS_STOPPED;
7667c478bd9Sstevel@tonic-gate 				terminate (oldpps->exec);
7677c478bd9Sstevel@tonic-gate 			    }
7687c478bd9Sstevel@tonic-gate 
7697c478bd9Sstevel@tonic-gate 			}
7707c478bd9Sstevel@tonic-gate 
7717c478bd9Sstevel@tonic-gate 			load_str (&(prs->slow), best_pc->slow);
7727c478bd9Sstevel@tonic-gate 			/* Assumption: if there is a slow filter,
7737c478bd9Sstevel@tonic-gate 			 * there is an output_type
7747c478bd9Sstevel@tonic-gate 			 */
7757c478bd9Sstevel@tonic-gate 
7767c478bd9Sstevel@tonic-gate 			load_str (&(prs->output_type), best_pc->output_type);
7777c478bd9Sstevel@tonic-gate 		} else
7787c478bd9Sstevel@tonic-gate 			unload_str (&(prs->slow));
7797c478bd9Sstevel@tonic-gate 
7807c478bd9Sstevel@tonic-gate 		load_str (&(prs->fast), best_pc->fast);
7817c478bd9Sstevel@tonic-gate 
7827c478bd9Sstevel@tonic-gate 		if (prs->request->actions & ACT_FAST && prs->slow) {
7837c478bd9Sstevel@tonic-gate 			if (prs->fast) {
7847c478bd9Sstevel@tonic-gate 				prs->fast = makestr(
7857c478bd9Sstevel@tonic-gate 					prs->slow,
7867c478bd9Sstevel@tonic-gate 					"|",
7877c478bd9Sstevel@tonic-gate 					prs->fast,
7887c478bd9Sstevel@tonic-gate 					(char *)0
7897c478bd9Sstevel@tonic-gate 				);
7907c478bd9Sstevel@tonic-gate 				Free (prs->slow);
7917c478bd9Sstevel@tonic-gate 			} else
7927c478bd9Sstevel@tonic-gate 				prs->fast = prs->slow;
7937c478bd9Sstevel@tonic-gate 			prs->slow = 0;
7947c478bd9Sstevel@tonic-gate 		}
7957c478bd9Sstevel@tonic-gate 
7967c478bd9Sstevel@tonic-gate 	}
7977c478bd9Sstevel@tonic-gate 
7987c478bd9Sstevel@tonic-gate 
7997c478bd9Sstevel@tonic-gate 	/*
8007c478bd9Sstevel@tonic-gate 	 * Free the space allocated for the candidates, INCLUDING
8017c478bd9Sstevel@tonic-gate 	 * the one chosen. Any allocated space in the chosen candidate
8027c478bd9Sstevel@tonic-gate 	 * that has to be saved should have been COPIED already.
8037c478bd9Sstevel@tonic-gate 	 */
8047c478bd9Sstevel@tonic-gate 	if (arena) {
8057c478bd9Sstevel@tonic-gate 		for (pc = arena; pc < pcend; pc++)
8067c478bd9Sstevel@tonic-gate 			free_candidate (pc);
8077c478bd9Sstevel@tonic-gate 		Free ((char *)arena);
8087c478bd9Sstevel@tonic-gate 	} else if (best_pc)
8097c478bd9Sstevel@tonic-gate 		free_candidate (best_pc);
8107c478bd9Sstevel@tonic-gate 
8117c478bd9Sstevel@tonic-gate 	if (o_length)
8127c478bd9Sstevel@tonic-gate 		Free (o_length);
8137c478bd9Sstevel@tonic-gate 	if (o_width)
8147c478bd9Sstevel@tonic-gate 		Free (o_width);
8157c478bd9Sstevel@tonic-gate 	if (o_lpi)
8167c478bd9Sstevel@tonic-gate 		Free (o_lpi);
8177c478bd9Sstevel@tonic-gate 	if (o_cpi)
8187c478bd9Sstevel@tonic-gate 		Free (o_cpi);
8197c478bd9Sstevel@tonic-gate 
8207c478bd9Sstevel@tonic-gate 
8217c478bd9Sstevel@tonic-gate 	/*
8227c478bd9Sstevel@tonic-gate 	 * The following value is valid ONLY IF the request
8237c478bd9Sstevel@tonic-gate 	 * is canceled or rejected. Not all requests that
8247c478bd9Sstevel@tonic-gate 	 * we fail in this routine are tossed out!
8257c478bd9Sstevel@tonic-gate 	 */
8267c478bd9Sstevel@tonic-gate 	prs->reason = ret;
8277c478bd9Sstevel@tonic-gate 
8287c478bd9Sstevel@tonic-gate 
8297c478bd9Sstevel@tonic-gate 	return (ret);
8307c478bd9Sstevel@tonic-gate }
8317c478bd9Sstevel@tonic-gate 
8327c478bd9Sstevel@tonic-gate /**
8337c478bd9Sstevel@tonic-gate  ** _chkopts() - CHECK -o OPTIONS
8347c478bd9Sstevel@tonic-gate  **/
8357c478bd9Sstevel@tonic-gate 
8367c478bd9Sstevel@tonic-gate static int
8377c478bd9Sstevel@tonic-gate _chkopts(RSTATUS *prs, CANDIDATE *pc, FSTATUS *pfs)
8387c478bd9Sstevel@tonic-gate {
8397c478bd9Sstevel@tonic-gate 	unsigned long		ret	= 0;
8407c478bd9Sstevel@tonic-gate 	unsigned long		chk	= 0;
8417c478bd9Sstevel@tonic-gate 
8427c478bd9Sstevel@tonic-gate 	char *			charset;
8437c478bd9Sstevel@tonic-gate 	char *			cpi	= 0;
8447c478bd9Sstevel@tonic-gate 	char *			lpi	= 0;
8457c478bd9Sstevel@tonic-gate 	char *			width	= 0;
8467c478bd9Sstevel@tonic-gate 	char *			length	= 0;
8477c478bd9Sstevel@tonic-gate 	char *			paper = NULL;
8487c478bd9Sstevel@tonic-gate 
8497c478bd9Sstevel@tonic-gate 	char **			pt;
85045916cd2Sjpk 	int			nobanner_not_allowed = 0;
8517c478bd9Sstevel@tonic-gate 
8527c478bd9Sstevel@tonic-gate 
8537c478bd9Sstevel@tonic-gate 	/*
8547c478bd9Sstevel@tonic-gate 	 * If we have a form, it overrides whatever print characteristics
8557c478bd9Sstevel@tonic-gate 	 * the user gave.
8567c478bd9Sstevel@tonic-gate 	 */
8577c478bd9Sstevel@tonic-gate 	if (pfs) {
8587c478bd9Sstevel@tonic-gate 		cpi = pfs->cpi;
8597c478bd9Sstevel@tonic-gate 		lpi = pfs->lpi;
8607c478bd9Sstevel@tonic-gate 		width = pfs->pwid;
8617c478bd9Sstevel@tonic-gate 		length = pfs->plen;
8627c478bd9Sstevel@tonic-gate 		paper = pfs->form->paper;
8637c478bd9Sstevel@tonic-gate 	} else {
8647c478bd9Sstevel@tonic-gate 		cpi = o_cpi;
8657c478bd9Sstevel@tonic-gate 		lpi = o_lpi;
8667c478bd9Sstevel@tonic-gate 		width = o_width;
8677c478bd9Sstevel@tonic-gate 		length = o_length;
8687c478bd9Sstevel@tonic-gate 	}
8697c478bd9Sstevel@tonic-gate 
8707c478bd9Sstevel@tonic-gate 	/*
8717c478bd9Sstevel@tonic-gate 	 * If the printer takes print wheels, or the character set
8727c478bd9Sstevel@tonic-gate 	 * the user wants is listed in the character set map for this
8737c478bd9Sstevel@tonic-gate 	 * printer, we needn't check if the printer can handle the
8747c478bd9Sstevel@tonic-gate 	 * character set. (Note: The check for the print wheel case
8757c478bd9Sstevel@tonic-gate 	 * is done elsewhere.)
8767c478bd9Sstevel@tonic-gate 	 */
8777c478bd9Sstevel@tonic-gate 
8787c478bd9Sstevel@tonic-gate 	if (pc->pps->printer->daisy ||
8797c478bd9Sstevel@tonic-gate 	    search_cslist(prs->request->charset, pc->pps->printer->char_sets))
8807c478bd9Sstevel@tonic-gate 		charset = 0;
8817c478bd9Sstevel@tonic-gate 	else
8827c478bd9Sstevel@tonic-gate 		charset = prs->request->charset;
8837c478bd9Sstevel@tonic-gate 
8847c478bd9Sstevel@tonic-gate 	pc->printer_types = 0;
8857c478bd9Sstevel@tonic-gate 	for (pt = pc->pps->printer->printer_types; *pt; pt++) {
8867c478bd9Sstevel@tonic-gate 		unsigned long		this;
8877c478bd9Sstevel@tonic-gate 
8887c478bd9Sstevel@tonic-gate 		if (paper) {
8897c478bd9Sstevel@tonic-gate 			if (allowed(paper,pc->pps->paper_allowed,NULL)) {
8907c478bd9Sstevel@tonic-gate 				addlist (&(pc->printer_types), *pt);
8917c478bd9Sstevel@tonic-gate 			} else {
8927c478bd9Sstevel@tonic-gate 				ret |= PCK_PAPER;
8937c478bd9Sstevel@tonic-gate 			}
8947c478bd9Sstevel@tonic-gate 		} else {
8957c478bd9Sstevel@tonic-gate 			this = chkprinter(*pt, cpi, lpi, length, width,
8967c478bd9Sstevel@tonic-gate 				charset);
8977c478bd9Sstevel@tonic-gate 			if (this == 0)
8987c478bd9Sstevel@tonic-gate 				addlist(&(pc->printer_types), *pt);
8997c478bd9Sstevel@tonic-gate 			chk |= this;
9007c478bd9Sstevel@tonic-gate 		}
9017c478bd9Sstevel@tonic-gate 	}
9027c478bd9Sstevel@tonic-gate 	if (!pc->printer_types)
9037c478bd9Sstevel@tonic-gate 		ret |= chk;
9047c478bd9Sstevel@tonic-gate 
90545916cd2Sjpk 	/*
90645916cd2Sjpk 	 * If the sytem is labeled, then user who wants 'nolabels' must
90745916cd2Sjpk 	 * have PRINT_UNLABELED_AUTH authorizations to allow it.
90845916cd2Sjpk 	 */
90945916cd2Sjpk 	if (is_system_labeled() && (wants_nolabels == 1)) {
91045916cd2Sjpk 		if (!tsol_lpauth(PRINT_UNLABELED_AUTH, prs->secure->user)) {
91145916cd2Sjpk 			/* if not authorized, remove "nolabels" from options */
91245916cd2Sjpk 			register char		**list;
91345916cd2Sjpk 			if (prs->request->options &&
91445916cd2Sjpk 			    (list = dashos(prs->request->options))) {
91545916cd2Sjpk 				dellist(&list, "nolabels");
91645916cd2Sjpk 				free(prs->request->options);
91745916cd2Sjpk 				prs->request->options = sprintlist(list);
91845916cd2Sjpk 			}
91945916cd2Sjpk 		}
92045916cd2Sjpk 	}
92145916cd2Sjpk 
92245916cd2Sjpk 
9237c478bd9Sstevel@tonic-gate 	if (pc->pps->printer->banner == BAN_ALWAYS) {
92445916cd2Sjpk 		/* delete "nobanner" */
92545916cd2Sjpk 		char **list;
9267c478bd9Sstevel@tonic-gate 
92745916cd2Sjpk 		/*
92845916cd2Sjpk 		 * If the system is labeled, users must have
92945916cd2Sjpk 		 * PRINT_NOBANNER_AUTH authorization to print
93045916cd2Sjpk 		 * without a banner.
93145916cd2Sjpk 		 */
93245916cd2Sjpk 		if (is_system_labeled()) {
93345916cd2Sjpk 			if (wants_nobanner == 1) {
93445916cd2Sjpk 				if (tsol_lpauth(PRINT_NOBANNER_AUTH,
93545916cd2Sjpk 					prs->secure->user) == 0) {
93645916cd2Sjpk 					nobanner_not_allowed = 1;
93745916cd2Sjpk 				}
93845916cd2Sjpk 			}
93945916cd2Sjpk 
94045916cd2Sjpk 		}
94145916cd2Sjpk 		else if ((wants_nobanner == 1) && (lp_or_root != 1)) {
94245916cd2Sjpk 			nobanner_not_allowed = 1;
94345916cd2Sjpk 		}
94445916cd2Sjpk 		if (nobanner_not_allowed == 1) {
94545916cd2Sjpk 			/* Take out 'nobanner' from request options. */
9467c478bd9Sstevel@tonic-gate 			if (prs->request->options &&
9477c478bd9Sstevel@tonic-gate 			    (list = dashos(prs->request->options))) {
9487c478bd9Sstevel@tonic-gate 				dellist(&list, "nobanner");
9497c478bd9Sstevel@tonic-gate 				free(prs->request->options);
9507c478bd9Sstevel@tonic-gate 				prs->request->options = sprintlist(list);
9517c478bd9Sstevel@tonic-gate 			}
9527c478bd9Sstevel@tonic-gate 		}
9537c478bd9Sstevel@tonic-gate 	} else if (pc->pps->printer->banner == BAN_NEVER) {
9547c478bd9Sstevel@tonic-gate 		if (wants_nobanner == 0) {
9557c478bd9Sstevel@tonic-gate 			/* add "nobanner" */
9567c478bd9Sstevel@tonic-gate 			char **list = NULL;
9577c478bd9Sstevel@tonic-gate 
9587c478bd9Sstevel@tonic-gate 			if (prs->request->options) {
9597c478bd9Sstevel@tonic-gate 				list = dashos(prs->request->options);
9607c478bd9Sstevel@tonic-gate 				free(prs->request->options);
9617c478bd9Sstevel@tonic-gate 			}
9627c478bd9Sstevel@tonic-gate 			appendlist(&list, "nobanner");
9637c478bd9Sstevel@tonic-gate 			prs->request->options = sprintlist(list);
9647c478bd9Sstevel@tonic-gate 		}
9657c478bd9Sstevel@tonic-gate 	} else /* if (pc->pps->printer->banner == BAN_OPTIONAL) */ {
9667c478bd9Sstevel@tonic-gate 		/* it is optional, leave it alone */
9677c478bd9Sstevel@tonic-gate 	}
9687c478bd9Sstevel@tonic-gate 
9697c478bd9Sstevel@tonic-gate 	chkprinter_result |= ret;
9707c478bd9Sstevel@tonic-gate 	return (ret == 0);
9717c478bd9Sstevel@tonic-gate }
9727c478bd9Sstevel@tonic-gate 
9737c478bd9Sstevel@tonic-gate /**
9747c478bd9Sstevel@tonic-gate  ** free_candidate()
9757c478bd9Sstevel@tonic-gate  **/
9767c478bd9Sstevel@tonic-gate 
9777c478bd9Sstevel@tonic-gate static void
9787c478bd9Sstevel@tonic-gate free_candidate(CANDIDATE *pc)
9797c478bd9Sstevel@tonic-gate {
9807c478bd9Sstevel@tonic-gate 	if (pc->slow)
9817c478bd9Sstevel@tonic-gate 		unload_str (&(pc->slow));
9827c478bd9Sstevel@tonic-gate 	if (pc->fast)
9837c478bd9Sstevel@tonic-gate 		unload_str (&(pc->fast));
9847c478bd9Sstevel@tonic-gate 	if (pc->printer_types) {
9857c478bd9Sstevel@tonic-gate 		freelist (pc->printer_types);
9867c478bd9Sstevel@tonic-gate 		pc->printer_types = 0;
9877c478bd9Sstevel@tonic-gate 	}
9887c478bd9Sstevel@tonic-gate 	if (pc->printer_type)
9897c478bd9Sstevel@tonic-gate 		unload_str (&(pc->printer_type));
9907c478bd9Sstevel@tonic-gate 	if (pc->output_type)
9917c478bd9Sstevel@tonic-gate 		unload_str (&(pc->output_type));
9927c478bd9Sstevel@tonic-gate 	return;
9937c478bd9Sstevel@tonic-gate }
99445916cd2Sjpk 
99545916cd2Sjpk static int
99645916cd2Sjpk tsol_check_printer_label_range(char *slabel, const char *printer)
99745916cd2Sjpk {
99845916cd2Sjpk 	int			in_range = 0;
99945916cd2Sjpk 	int			err = 0;
100045916cd2Sjpk 	m_range_t		*range;
100145916cd2Sjpk 	m_label_t	*sl = NULL;
100245916cd2Sjpk 
100345916cd2Sjpk 	if (slabel == NULL)
100445916cd2Sjpk 		return (0);
100545916cd2Sjpk 
100645916cd2Sjpk 	if ((err =
100745916cd2Sjpk 	    (str_to_label(slabel, &sl, USER_CLEAR, L_NO_CORRECTION, &in_range)))
100845916cd2Sjpk 	    == -1) {
100945916cd2Sjpk 		/* stobsl error on printer max label */
101045916cd2Sjpk 		return (0);
101145916cd2Sjpk 	}
101245916cd2Sjpk 	if ((range = getdevicerange(printer)) == NULL) {
101345916cd2Sjpk 		m_label_free(sl);
101445916cd2Sjpk 		return (0);
101545916cd2Sjpk 	}
101645916cd2Sjpk 
101745916cd2Sjpk 	/* blinrange returns true (1) if in range, false (0) if not */
101845916cd2Sjpk 	in_range = blinrange(sl, range);
101945916cd2Sjpk 
102045916cd2Sjpk 	m_label_free(sl);
102145916cd2Sjpk 	m_label_free(range->lower_bound);
102245916cd2Sjpk 	m_label_free(range->upper_bound);
102345916cd2Sjpk 	free(range);
102445916cd2Sjpk 
102545916cd2Sjpk 	return (in_range);
102645916cd2Sjpk }
102745916cd2Sjpk 
102845916cd2Sjpk /*
102945916cd2Sjpk  * Given a character string with a "username" or "system!username"
103045916cd2Sjpk  * this function returns a pointer to "username"
103145916cd2Sjpk  */
103245916cd2Sjpk static int
103345916cd2Sjpk tsol_lpauth(char *auth, char *in_name)
103445916cd2Sjpk {
103545916cd2Sjpk 	char *cp;
103645916cd2Sjpk 	int res;
103745916cd2Sjpk 
103845916cd2Sjpk 	if ((cp = strchr(in_name, '@')) != NULL) {
103945916cd2Sjpk 		/* user@system */
104045916cd2Sjpk 		*cp = '\0';
104145916cd2Sjpk 		res = chkauthattr(auth, in_name);
104245916cd2Sjpk 		*cp = '@';
104345916cd2Sjpk 	} else if ((cp = strchr(in_name, '!')) != NULL)
104445916cd2Sjpk 		/* system!user */
104545916cd2Sjpk 		res = chkauthattr(auth, cp+1);
104645916cd2Sjpk 	else
104745916cd2Sjpk 		/* user */
104845916cd2Sjpk 		res = chkauthattr(auth, in_name);
104945916cd2Sjpk 
105045916cd2Sjpk 	return (res);
105145916cd2Sjpk }
105245916cd2Sjpk 
105345916cd2Sjpk #define	POLICY_FILE	"/etc/default/print"
105445916cd2Sjpk 
105545916cd2Sjpk int
105645916cd2Sjpk secpolicy_chkpolicy(char *policyp)
105745916cd2Sjpk {
105845916cd2Sjpk 	char *option;
105945916cd2Sjpk 	int opt_val;
106045916cd2Sjpk 
106145916cd2Sjpk 	if (policyp == NULL)
106245916cd2Sjpk 		return (0);
106345916cd2Sjpk 	opt_val = 0;
106445916cd2Sjpk 	if (defopen(POLICY_FILE) == 0) {
106545916cd2Sjpk 
106645916cd2Sjpk 		defcntl(DC_SETFLAGS, DC_STD & ~DC_CASE); /* ignore case */
106745916cd2Sjpk 
106845916cd2Sjpk 		if ((option = defread(policyp)) != NULL)
106945916cd2Sjpk 			opt_val = atoi(option);
107045916cd2Sjpk 	}
107145916cd2Sjpk 	(void) defopen((char *)NULL);
107245916cd2Sjpk 	syslog(LOG_DEBUG, "--- Policy %s, opt_val==%d",
107345916cd2Sjpk 	    policyp ? policyp : "NULL", opt_val);
107445916cd2Sjpk 	return (opt_val);
107545916cd2Sjpk }
1076