xref: /illumos-gate/usr/src/cmd/lp/cmd/lpadmin/chkopts.c (revision 2a8bcb4e)
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
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
237c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
287c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
297c478bd9Sstevel@tonic-gate  */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include "stdio.h"
327c478bd9Sstevel@tonic-gate #include "string.h"
337c478bd9Sstevel@tonic-gate #include "pwd.h"
347c478bd9Sstevel@tonic-gate #include "sys/types.h"
357c478bd9Sstevel@tonic-gate #include "errno.h"
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #include "lp.h"
387c478bd9Sstevel@tonic-gate #include "printers.h"
397c478bd9Sstevel@tonic-gate #include "form.h"
407c478bd9Sstevel@tonic-gate #include "class.h"
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #define	WHO_AM_I	I_AM_LPADMIN
437c478bd9Sstevel@tonic-gate #include "oam.h"
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #include "lpadmin.h"
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate #define PPDZIP	".gz"
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate extern PRINTER		*printer_pointer;
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate extern PWHEEL		*pwheel_pointer;
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate extern struct passwd	*getpwnam();
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate void			chkopts2(),
577c478bd9Sstevel@tonic-gate 			chkopts3();
587c478bd9Sstevel@tonic-gate static void		chksys();
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate FORM			formbuf;
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate char			**f_allow,
637c478bd9Sstevel@tonic-gate 			**f_deny,
647c478bd9Sstevel@tonic-gate 			**u_allow,
657c478bd9Sstevel@tonic-gate 			**u_deny,
667c478bd9Sstevel@tonic-gate 			**p_add,
677c478bd9Sstevel@tonic-gate 			**p_remove;
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate PRINTER			*oldp		= 0;
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate PWHEEL			*oldS		= 0;
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate short			daisy		= 0;
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate static int		root_can_write();
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate static char		*unpack_sdn();
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate static char **		bad_list;
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate #if	defined(__STDC__)
827c478bd9Sstevel@tonic-gate static unsigned long	sum_chkprinter ( char ** , char * , char * , char * , char * , char * );
837c478bd9Sstevel@tonic-gate static int isPPD(char *ppd_file);
847c478bd9Sstevel@tonic-gate #else
857c478bd9Sstevel@tonic-gate static unsigned long	sum_chkprinter();
867c478bd9Sstevel@tonic-gate static int isPPD();
877c478bd9Sstevel@tonic-gate #endif
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate /**
907c478bd9Sstevel@tonic-gate  ** chkopts() -- CHECK LEGALITY OF COMMAND LINE OPTIONS
917c478bd9Sstevel@tonic-gate  **/
927c478bd9Sstevel@tonic-gate 
chkopts()937c478bd9Sstevel@tonic-gate void			chkopts ()
947c478bd9Sstevel@tonic-gate {
957c478bd9Sstevel@tonic-gate 	short		isfAuto = 0;
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate 	/*
987c478bd9Sstevel@tonic-gate 	 * Check -d.
997c478bd9Sstevel@tonic-gate 	 */
1007c478bd9Sstevel@tonic-gate 	if (d) {
1017c478bd9Sstevel@tonic-gate 		if (
1027c478bd9Sstevel@tonic-gate 			a || c || f || P || j || m || M || t || p || r || u || x
1037c478bd9Sstevel@tonic-gate #if	defined(DIRECT_ACCESS)
1047c478bd9Sstevel@tonic-gate 		     || C
1057c478bd9Sstevel@tonic-gate #endif
1067c478bd9Sstevel@tonic-gate #ifdef LP_USE_PAPI_ATTR
1077c478bd9Sstevel@tonic-gate 		     || n_opt
1087c478bd9Sstevel@tonic-gate #endif
1097c478bd9Sstevel@tonic-gate 		     || strlen(modifications)
1107c478bd9Sstevel@tonic-gate 		) {
1117c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_ADM_DALONE);
1127c478bd9Sstevel@tonic-gate 			done (1);
1137c478bd9Sstevel@tonic-gate 		}
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate 		if (
1167c478bd9Sstevel@tonic-gate 			*d
1177c478bd9Sstevel@tonic-gate 		     && !STREQU(d, NAME_NONE)
1187c478bd9Sstevel@tonic-gate 		     && !isprinter(d)
1197c478bd9Sstevel@tonic-gate 		     && !isclass(d)
1207c478bd9Sstevel@tonic-gate 		) {
1217c478bd9Sstevel@tonic-gate 			LP_ERRMSG1 (ERROR, E_ADM_NODEST, d);
1227c478bd9Sstevel@tonic-gate 			done (1);
1237c478bd9Sstevel@tonic-gate 		}
1247c478bd9Sstevel@tonic-gate 		return;
1257c478bd9Sstevel@tonic-gate 	}
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate 	/*
1287c478bd9Sstevel@tonic-gate 	 * Check -x.
1297c478bd9Sstevel@tonic-gate 	 */
1307c478bd9Sstevel@tonic-gate 	if (x) {
1317c478bd9Sstevel@tonic-gate 		if (	/* MR bl88-02718 */
1327c478bd9Sstevel@tonic-gate 			A || a || c || f || P || j || m || M || t || p || r || u || d
1337c478bd9Sstevel@tonic-gate #if	defined(DIRECT_ACCESS)
1347c478bd9Sstevel@tonic-gate 		     || C
1357c478bd9Sstevel@tonic-gate #endif
1367c478bd9Sstevel@tonic-gate #ifdef LP_USE_PAPI_ATTR
1377c478bd9Sstevel@tonic-gate 		     || n_opt
1387c478bd9Sstevel@tonic-gate #endif
1397c478bd9Sstevel@tonic-gate 		     || strlen(modifications)
1407c478bd9Sstevel@tonic-gate 		) {
1417c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_ADM_XALONE);
1427c478bd9Sstevel@tonic-gate 			done (1);
1437c478bd9Sstevel@tonic-gate 		}
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate 		if (
1467c478bd9Sstevel@tonic-gate 			!STREQU(NAME_ALL, x)
1477c478bd9Sstevel@tonic-gate 		     && !STREQU(NAME_ANY, x)
1487c478bd9Sstevel@tonic-gate 		     && !isprinter(x)
1497c478bd9Sstevel@tonic-gate 		     && !isclass(x)
1507c478bd9Sstevel@tonic-gate 		) {
1517c478bd9Sstevel@tonic-gate 			LP_ERRMSG1 (ERROR, E_ADM_NODEST, x);
1527c478bd9Sstevel@tonic-gate 			done (1);
1537c478bd9Sstevel@tonic-gate 		}
1547c478bd9Sstevel@tonic-gate 		return;
1557c478bd9Sstevel@tonic-gate 	}
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate 	/*
1587c478bd9Sstevel@tonic-gate 	 * Problems common to both -p and -S (-S alone).
1597c478bd9Sstevel@tonic-gate 	 */
1607c478bd9Sstevel@tonic-gate 	if (A && STREQU(A, NAME_LIST) && (W != -1 || Q != -1)) {
1617c478bd9Sstevel@tonic-gate 		LP_ERRMSG (ERROR, E_ADM_LISTWQ);
1627c478bd9Sstevel@tonic-gate 		done (1);
1637c478bd9Sstevel@tonic-gate 	}
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate 	/*
1677c478bd9Sstevel@tonic-gate 	 * Check -S.
1687c478bd9Sstevel@tonic-gate 	 */
1697c478bd9Sstevel@tonic-gate 	if (!p && S) {
1707c478bd9Sstevel@tonic-gate 		if (
1717c478bd9Sstevel@tonic-gate 			M || t || a || f || P || c || r || e || i || m || H || h
1727c478bd9Sstevel@tonic-gate 		     || l || v || I || T || D || F || u || U || j || o
1737c478bd9Sstevel@tonic-gate #ifdef LP_USE_PAPI_ATTR
1747c478bd9Sstevel@tonic-gate 		     || n_opt
1757c478bd9Sstevel@tonic-gate #endif
1767c478bd9Sstevel@tonic-gate 		) {
1777c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_ADM_SALONE);
1787c478bd9Sstevel@tonic-gate 			done (1);
1797c478bd9Sstevel@tonic-gate 		}
1807c478bd9Sstevel@tonic-gate 		if (!A && W == -1 && Q == -1) {
1817c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_ADM_NOAWQ);
1827c478bd9Sstevel@tonic-gate 			done (1);
1837c478bd9Sstevel@tonic-gate 		}
1847c478bd9Sstevel@tonic-gate 		if (S[0] && S[1])
1857c478bd9Sstevel@tonic-gate 			LP_ERRMSG (WARNING, E_ADM_ASINGLES);
186*2a8bcb4eSToomas Soome 		if (!STREQU(NAME_ALL, *S) && !STREQU(NAME_ANY, *S))
1877c478bd9Sstevel@tonic-gate 			chkopts3(1);
1887c478bd9Sstevel@tonic-gate 		return;
1897c478bd9Sstevel@tonic-gate 	}
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate 	/*
1927c478bd9Sstevel@tonic-gate 	 * At this point we must have a printer (-p option).
1937c478bd9Sstevel@tonic-gate 	 */
1947c478bd9Sstevel@tonic-gate 	if (!p) {
1957c478bd9Sstevel@tonic-gate 		LP_ERRMSG (ERROR, E_ADM_NOACT);
1967c478bd9Sstevel@tonic-gate 		done (1);
1977c478bd9Sstevel@tonic-gate 	}
1987c478bd9Sstevel@tonic-gate 	if (STREQU(NAME_NONE, p)) {
1997c478bd9Sstevel@tonic-gate 		LP_ERRMSG1 (ERROR, E_LP_NULLARG, "p");
2007c478bd9Sstevel@tonic-gate 		done (1);
2017c478bd9Sstevel@tonic-gate 	}
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate 	/*
2057c478bd9Sstevel@tonic-gate 	 * Mount but nothing to mount?
2067c478bd9Sstevel@tonic-gate 	 */
2077c478bd9Sstevel@tonic-gate 	if (M && (!f && !S)) {
2087c478bd9Sstevel@tonic-gate 		LP_ERRMSG (ERROR, E_ADM_MNTNONE);
2097c478bd9Sstevel@tonic-gate 		done (1);
2107c478bd9Sstevel@tonic-gate 	}
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate 	/*
2137c478bd9Sstevel@tonic-gate 	 * -Q isn't allowed with -p.
2147c478bd9Sstevel@tonic-gate 	 */
2157c478bd9Sstevel@tonic-gate 	if (Q != -1) {
2167c478bd9Sstevel@tonic-gate 		LP_ERRMSG (ERROR, E_ADM_PNOQ);
2177c478bd9Sstevel@tonic-gate 		done (1);
2187c478bd9Sstevel@tonic-gate 	}
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate 	/*
2217c478bd9Sstevel@tonic-gate 	 * Fault recovery.
2227c478bd9Sstevel@tonic-gate 	 */
2237c478bd9Sstevel@tonic-gate 	if (
2247c478bd9Sstevel@tonic-gate 		F
2257c478bd9Sstevel@tonic-gate 	     && !STREQU(F, NAME_WAIT)
2267c478bd9Sstevel@tonic-gate 	     && !STREQU(F, NAME_BEGINNING)
2277c478bd9Sstevel@tonic-gate 	     && (
2287c478bd9Sstevel@tonic-gate 			!STREQU(F, NAME_CONTINUE)
2297c478bd9Sstevel@tonic-gate 		     || j
2307c478bd9Sstevel@tonic-gate 		     && STREQU(F, NAME_CONTINUE)
2317c478bd9Sstevel@tonic-gate 		)
2327c478bd9Sstevel@tonic-gate 	) {
2337c478bd9Sstevel@tonic-gate #if	defined(J_OPTION)
2347c478bd9Sstevel@tonic-gate 		if (j)
2357c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_ADM_FBADJ);
2367c478bd9Sstevel@tonic-gate 		else
2377c478bd9Sstevel@tonic-gate #endif
2387c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_ADM_FBAD);
2397c478bd9Sstevel@tonic-gate 		done (1);
2407c478bd9Sstevel@tonic-gate 	}
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate #if	defined(J_OPTION)
2437c478bd9Sstevel@tonic-gate 	/*
2447c478bd9Sstevel@tonic-gate 	 * The -j option is used only with the -F option.
2457c478bd9Sstevel@tonic-gate 	 */
2467c478bd9Sstevel@tonic-gate  	if (j) {
2477c478bd9Sstevel@tonic-gate 		if (M || t || a || f || P || c || r || e || i || m || H || h ||
2487c478bd9Sstevel@tonic-gate #ifdef LP_USE_PAPI_ATTR
2497c478bd9Sstevel@tonic-gate 		    n_opt ||
2507c478bd9Sstevel@tonic-gate #endif
2517c478bd9Sstevel@tonic-gate 		    l || v || I || T || D || u || U || o) {
2527c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_ADM_JALONE);
2537c478bd9Sstevel@tonic-gate 			done (1);
2547c478bd9Sstevel@tonic-gate 		}
2557c478bd9Sstevel@tonic-gate 		if (j && !F) {
2567c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_ADM_JNOF);
2577c478bd9Sstevel@tonic-gate 			done (1);
2587c478bd9Sstevel@tonic-gate 		}
2597c478bd9Sstevel@tonic-gate 		return;
2607c478bd9Sstevel@tonic-gate 	}
2617c478bd9Sstevel@tonic-gate #endif
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate #if	defined(DIRECT_ACCESS)
2647c478bd9Sstevel@tonic-gate 	/*
2657c478bd9Sstevel@tonic-gate 	 * -C is only used to modify -u
2667c478bd9Sstevel@tonic-gate 	 */
2677c478bd9Sstevel@tonic-gate 	if (C && !u) {
2687c478bd9Sstevel@tonic-gate 		LP_ERRMSG (ERROR, E_ADM_CNOU);
2697c478bd9Sstevel@tonic-gate 		done (1);
2707c478bd9Sstevel@tonic-gate 	}
2717c478bd9Sstevel@tonic-gate #endif
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate 	/*
2747c478bd9Sstevel@tonic-gate 	 * The -a option needs the -M and -f options,
2757c478bd9Sstevel@tonic-gate 	 * Also, -ofilebreak is used only with -a.
2767c478bd9Sstevel@tonic-gate 	 */
2777c478bd9Sstevel@tonic-gate 	if (a && (!M || !f)) {
2787c478bd9Sstevel@tonic-gate 		LP_ERRMSG (ERROR, E_ADM_MALIGN);
2797c478bd9Sstevel@tonic-gate 		done (1);
2807c478bd9Sstevel@tonic-gate 	}
2817c478bd9Sstevel@tonic-gate 	if (filebreak && !a)
2827c478bd9Sstevel@tonic-gate 		LP_ERRMSG (WARNING, E_ADM_FILEBREAK);
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate 	/*
2857c478bd9Sstevel@tonic-gate 	 * The "-p all" case is restricted to certain options.
2867c478bd9Sstevel@tonic-gate 	 */
2877c478bd9Sstevel@tonic-gate 	if (
2887c478bd9Sstevel@tonic-gate 		(STREQU(NAME_ANY, p) || STREQU(NAME_ALL, p))
2897c478bd9Sstevel@tonic-gate 	     && (
2907c478bd9Sstevel@tonic-gate 			a || h || l || M || t || D || e || f || P || H || s
2917c478bd9Sstevel@tonic-gate #ifdef LP_USE_PAPI_ATTR
2927c478bd9Sstevel@tonic-gate 		      || n_opt
2937c478bd9Sstevel@tonic-gate #endif
2947c478bd9Sstevel@tonic-gate 		     || i || I || m || S || T || u || U || v || banner != -1
2957c478bd9Sstevel@tonic-gate 		     || cpi || lpi || width || length || stty_opt
2967c478bd9Sstevel@tonic-gate 		)
2977c478bd9Sstevel@tonic-gate 	) {
2987c478bd9Sstevel@tonic-gate 		LP_ERRMSG (ERROR, E_ADM_ANYALLNONE);
2997c478bd9Sstevel@tonic-gate 		done (1);
3007c478bd9Sstevel@tonic-gate 
301*2a8bcb4eSToomas Soome 	}
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate 	/*
3047c478bd9Sstevel@tonic-gate 	 * Allow giving -v or -U option as way of making
3057c478bd9Sstevel@tonic-gate 	 * remote printer into local printer.
3067c478bd9Sstevel@tonic-gate 	 * Note: "!s" here means the user has not given the -s;
3077c478bd9Sstevel@tonic-gate 	 * later it means the user gave -s local-system.
3087c478bd9Sstevel@tonic-gate 	 */
3097c478bd9Sstevel@tonic-gate 	if (!s && (v || U))
3107c478bd9Sstevel@tonic-gate 		s = Local_System;
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate 	/*
3137c478bd9Sstevel@tonic-gate 	 * Be careful about checking "s" before getting here.
3147c478bd9Sstevel@tonic-gate 	 * We want "s == 0" to mean this is a local printer; however,
3157c478bd9Sstevel@tonic-gate 	 * if the user wants to change a remote printer to a local
3167c478bd9Sstevel@tonic-gate 	 * printer, we have to have "s == Local_System" long enough
3177c478bd9Sstevel@tonic-gate 	 * to get into "chkopts2()" where a special check is made.
3187c478bd9Sstevel@tonic-gate 	 * After "chkopts2()", "s == 0" means local.
3197c478bd9Sstevel@tonic-gate 	 */
320*2a8bcb4eSToomas Soome 	if (!STREQU(NAME_ALL, p) && !STREQU(NAME_ANY, p))
3217c478bd9Sstevel@tonic-gate 		/*
3227c478bd9Sstevel@tonic-gate 		 * If old printer, make sure it exists. If new printer,
3237c478bd9Sstevel@tonic-gate 		 * check that the name is okay, and that enough is given.
3247c478bd9Sstevel@tonic-gate 		 * (This stuff has been moved to "chkopts2()".)
3257c478bd9Sstevel@tonic-gate 		 */
3267c478bd9Sstevel@tonic-gate 		chkopts2(1);
3277c478bd9Sstevel@tonic-gate 
3287c478bd9Sstevel@tonic-gate 	if (!s) {
3297c478bd9Sstevel@tonic-gate 
3307c478bd9Sstevel@tonic-gate 		/*
3317c478bd9Sstevel@tonic-gate 		 * Only one of -i, -m, -e.
3327c478bd9Sstevel@tonic-gate 		 */
3337c478bd9Sstevel@tonic-gate 		if ((i && e) || (m && e) || (i && m)) {
3347c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_ADM_INTCONF);
3357c478bd9Sstevel@tonic-gate 			done (1);
3367c478bd9Sstevel@tonic-gate 		}
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate 		/*
3397c478bd9Sstevel@tonic-gate 		 * Check -e arg.
3407c478bd9Sstevel@tonic-gate 		 */
3417c478bd9Sstevel@tonic-gate 		if (e) {
3427c478bd9Sstevel@tonic-gate 			if (!isprinter(e)) {
3437c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (ERROR, E_ADM_NOPR, e);
3447c478bd9Sstevel@tonic-gate 				done (1);
3457c478bd9Sstevel@tonic-gate 			}
3467c478bd9Sstevel@tonic-gate 			if (strcmp(e, p) == 0) {
3477c478bd9Sstevel@tonic-gate 				LP_ERRMSG (ERROR, E_ADM_SAMEPE);
3487c478bd9Sstevel@tonic-gate 				done (1);
3497c478bd9Sstevel@tonic-gate 			}
3507c478bd9Sstevel@tonic-gate 		}
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate 		/*
3537c478bd9Sstevel@tonic-gate 		 * Check -m arg.
3547c478bd9Sstevel@tonic-gate 		 */
3557c478bd9Sstevel@tonic-gate 		if (m && !ismodel(m)) {
3567c478bd9Sstevel@tonic-gate 			LP_ERRMSG1 (ERROR, E_ADM_NOMODEL, m);
3577c478bd9Sstevel@tonic-gate 			done (1);
3587c478bd9Sstevel@tonic-gate 		}
3597c478bd9Sstevel@tonic-gate 
3607c478bd9Sstevel@tonic-gate #ifdef LP_USE_PAPI_ATTR
3617c478bd9Sstevel@tonic-gate 		/*
3627c478bd9Sstevel@tonic-gate 		 * Check -n arg. The ppd file exists.
3637c478bd9Sstevel@tonic-gate 		 */
3647c478bd9Sstevel@tonic-gate 		if ((n_opt != NULL) && !isPPD(n_opt)) {
3657c478bd9Sstevel@tonic-gate 			LP_ERRMSG1 (ERROR, E_ADM_NOPPD, n_opt);
3667c478bd9Sstevel@tonic-gate 			done (1);
3677c478bd9Sstevel@tonic-gate 		}
3687c478bd9Sstevel@tonic-gate #endif
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate 		/*
3717c478bd9Sstevel@tonic-gate 		 * Need exactly one of -h or -l (but will default -h).
3727c478bd9Sstevel@tonic-gate 		 */
3737c478bd9Sstevel@tonic-gate 		if (h && l) {
3747c478bd9Sstevel@tonic-gate 			LP_ERRMSG2 (ERROR, E_ADM_CONFLICT, 'h', 'l');
3757c478bd9Sstevel@tonic-gate 			done (1);
3767c478bd9Sstevel@tonic-gate 		}
3777c478bd9Sstevel@tonic-gate 		if (!h && !l)
3787c478bd9Sstevel@tonic-gate 			h = 1;
3797c478bd9Sstevel@tonic-gate 
3807c478bd9Sstevel@tonic-gate 		/*
3817c478bd9Sstevel@tonic-gate 		 * Check -c and -r.
3827c478bd9Sstevel@tonic-gate 		 */
3837c478bd9Sstevel@tonic-gate 		if (c && r && strcmp(c, r) == 0) {
3847c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_ADM_SAMECR);
3857c478bd9Sstevel@tonic-gate 			done (1);
3867c478bd9Sstevel@tonic-gate 		}
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate 
3897c478bd9Sstevel@tonic-gate 		/*
3907c478bd9Sstevel@tonic-gate 		 * Are we creating a class with the same name as a printer?
3917c478bd9Sstevel@tonic-gate 		 */
3927c478bd9Sstevel@tonic-gate 		if (c) {
3937c478bd9Sstevel@tonic-gate 			if (STREQU(c, p)) {
3947c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (ERROR, E_ADM_CLNPR, c);
3957c478bd9Sstevel@tonic-gate 				done (1);
3967c478bd9Sstevel@tonic-gate 			}
3977c478bd9Sstevel@tonic-gate 			if (isprinter(c)) {
3987c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (ERROR, E_ADM_CLPR, c);
3997c478bd9Sstevel@tonic-gate 				done (1);
4007c478bd9Sstevel@tonic-gate 			}
4017c478bd9Sstevel@tonic-gate 		}
4027c478bd9Sstevel@tonic-gate 
4037c478bd9Sstevel@tonic-gate 		if (v && (is_printer_uri(v) < 0)) {
4047c478bd9Sstevel@tonic-gate 			/*
4057c478bd9Sstevel@tonic-gate 			 * The device must be writeable by root.
4067c478bd9Sstevel@tonic-gate 			 */
4077c478bd9Sstevel@tonic-gate 			if (v && root_can_write(v) == -1)
4087c478bd9Sstevel@tonic-gate 				done (1);
4097c478bd9Sstevel@tonic-gate 		}
4107c478bd9Sstevel@tonic-gate 
4117c478bd9Sstevel@tonic-gate 		/*
4127c478bd9Sstevel@tonic-gate 		 * Can't have both device and dial-out.
4137c478bd9Sstevel@tonic-gate 		 */
4147c478bd9Sstevel@tonic-gate 		if (v && U) {
4157c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_ADM_BOTHUV);
4167c478bd9Sstevel@tonic-gate 			done (1);
4177c478bd9Sstevel@tonic-gate 		}
4187c478bd9Sstevel@tonic-gate 
4197c478bd9Sstevel@tonic-gate 	} else
4207c478bd9Sstevel@tonic-gate 		if (
421*2a8bcb4eSToomas Soome 			A || a || e || H || h || i || l || m || ( t && !M) || ( M && !t)
4227c478bd9Sstevel@tonic-gate 		     || o || U || v || Q != -1 || W != -1
4237c478bd9Sstevel@tonic-gate #ifdef LP_USE_PAPI_ATTR
4247c478bd9Sstevel@tonic-gate 		     || n_opt
4257c478bd9Sstevel@tonic-gate #endif
4267c478bd9Sstevel@tonic-gate 		) {
4277c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_ADM_NOTLOCAL);
4287c478bd9Sstevel@tonic-gate 			done(1);
4297c478bd9Sstevel@tonic-gate 		}
4307c478bd9Sstevel@tonic-gate 
4317c478bd9Sstevel@tonic-gate 
4327c478bd9Sstevel@tonic-gate 	/*
4337c478bd9Sstevel@tonic-gate 	 * We need the printer type for some things, and the boolean
4347c478bd9Sstevel@tonic-gate 	 * "daisy" (from Terminfo) for other things.
4357c478bd9Sstevel@tonic-gate 	 */
4367c478bd9Sstevel@tonic-gate 	if (!T && oldp)
4377c478bd9Sstevel@tonic-gate 		T = oldp->printer_types;
4387c478bd9Sstevel@tonic-gate 	if (T) {
4397c478bd9Sstevel@tonic-gate 		short			a_daisy;
4407c478bd9Sstevel@tonic-gate 
4417c478bd9Sstevel@tonic-gate 		char **			pt;
4427c478bd9Sstevel@tonic-gate 
4437c478bd9Sstevel@tonic-gate 
4447c478bd9Sstevel@tonic-gate 		if (lenlist(T) > 1 && searchlist(NAME_UNKNOWN, T)) {
4457c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_ADM_MUNKNOWN);
4467c478bd9Sstevel@tonic-gate 			done (1);
4477c478bd9Sstevel@tonic-gate 		}
4487c478bd9Sstevel@tonic-gate 
4497c478bd9Sstevel@tonic-gate 		for (pt = T; *pt; pt++)
4507c478bd9Sstevel@tonic-gate 			if (tidbit(*pt, (char *)0) == -1) {
4517c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (ERROR, E_ADM_BADTYPE, *pt);
4527c478bd9Sstevel@tonic-gate 				done (1);
4537c478bd9Sstevel@tonic-gate 			}
4547c478bd9Sstevel@tonic-gate 
4557c478bd9Sstevel@tonic-gate 		/*
4567c478bd9Sstevel@tonic-gate 		 * All the printer types had better agree on whether the
4577c478bd9Sstevel@tonic-gate 		 * printer takes print wheels!
4587c478bd9Sstevel@tonic-gate 		 */
4597c478bd9Sstevel@tonic-gate 		daisy = a_daisy = -1;
4607c478bd9Sstevel@tonic-gate 		for (pt = T; *pt; pt++) {
4617c478bd9Sstevel@tonic-gate 			tidbit (*pt, "daisy", &daisy);
4627c478bd9Sstevel@tonic-gate 			if (daisy == -1)
4637c478bd9Sstevel@tonic-gate 				daisy = 0;
4647c478bd9Sstevel@tonic-gate 			if (a_daisy == -1)
4657c478bd9Sstevel@tonic-gate 				a_daisy = daisy;
4667c478bd9Sstevel@tonic-gate 			else if (a_daisy != daisy) {
4677c478bd9Sstevel@tonic-gate 				LP_ERRMSG (ERROR, E_ADM_MIXEDTYPES);
4687c478bd9Sstevel@tonic-gate 				done (1);
4697c478bd9Sstevel@tonic-gate 			}
4707c478bd9Sstevel@tonic-gate 		}
4717c478bd9Sstevel@tonic-gate 	}
4727c478bd9Sstevel@tonic-gate 	if (cpi || lpi || length || width || S || f || filebreak)
4737c478bd9Sstevel@tonic-gate 		if (!T) {
4747c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_ADM_TOPT);
4757c478bd9Sstevel@tonic-gate 			done (1);
4767c478bd9Sstevel@tonic-gate 
4777c478bd9Sstevel@tonic-gate 		}
4787c478bd9Sstevel@tonic-gate 
4797c478bd9Sstevel@tonic-gate 	/*
4807c478bd9Sstevel@tonic-gate 	 * Check -o cpi=, -o lpi=, -o length=, -o width=
4817c478bd9Sstevel@tonic-gate 	 */
4827c478bd9Sstevel@tonic-gate 	if (cpi || lpi || length || width) {
4837c478bd9Sstevel@tonic-gate 		unsigned	long	rc;
4847c478bd9Sstevel@tonic-gate 
4857c478bd9Sstevel@tonic-gate 		if ((rc = sum_chkprinter(T, cpi, lpi, length, width, NULL)) == 0) {
4867c478bd9Sstevel@tonic-gate 			if (bad_list)
4877c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (
4887c478bd9Sstevel@tonic-gate 					INFO,
4897c478bd9Sstevel@tonic-gate 					E_ADM_NBADCAPS,
4907c478bd9Sstevel@tonic-gate 					sprintlist(bad_list)
4917c478bd9Sstevel@tonic-gate 				);
4927c478bd9Sstevel@tonic-gate 
4937c478bd9Sstevel@tonic-gate 		} else {
4947c478bd9Sstevel@tonic-gate 			if ((rc & PCK_CPI) && cpi)
4957c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (ERROR, E_ADM_BADCAP, "cpi=");
4967c478bd9Sstevel@tonic-gate 
4977c478bd9Sstevel@tonic-gate 			if ((rc & PCK_LPI) && lpi)
4987c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (ERROR, E_ADM_BADCAP, "lpi=");
4997c478bd9Sstevel@tonic-gate 
5007c478bd9Sstevel@tonic-gate 			if ((rc & PCK_WIDTH) && width)
5017c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (ERROR, E_ADM_BADCAP, "width=");
5027c478bd9Sstevel@tonic-gate 
5037c478bd9Sstevel@tonic-gate 			if ((rc & PCK_LENGTH) && length)
5047c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (ERROR, E_ADM_BADCAP, "length=");
5057c478bd9Sstevel@tonic-gate 
5067c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_ADM_BADCAPS);
5077c478bd9Sstevel@tonic-gate 			done(1);
5087c478bd9Sstevel@tonic-gate 		}
5097c478bd9Sstevel@tonic-gate 	}
5107c478bd9Sstevel@tonic-gate 
5117c478bd9Sstevel@tonic-gate 	/*
5127c478bd9Sstevel@tonic-gate 	 * Check -I (old or new):
5137c478bd9Sstevel@tonic-gate 	 */
5147c478bd9Sstevel@tonic-gate 	if (T && lenlist(T) > 1) {
5157c478bd9Sstevel@tonic-gate 
5167c478bd9Sstevel@tonic-gate #define BADILIST(X) (lenlist(X) > 1 || X && *X && !STREQU(NAME_SIMPLE, *X))
5177c478bd9Sstevel@tonic-gate 		if (
5187c478bd9Sstevel@tonic-gate 			I && BADILIST(I)
5197c478bd9Sstevel@tonic-gate 		     || !I && oldp && BADILIST(oldp->input_types)
5207c478bd9Sstevel@tonic-gate 		) {
5217c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_ADM_ONLYSIMPLE);
5227c478bd9Sstevel@tonic-gate 			done (1);
5237c478bd9Sstevel@tonic-gate 		}
5247c478bd9Sstevel@tonic-gate 	}
5257c478bd9Sstevel@tonic-gate 
5267c478bd9Sstevel@tonic-gate 	/*
5277c478bd9Sstevel@tonic-gate 	 * MOUNT:
5287c478bd9Sstevel@tonic-gate 	 * Only one print wheel can be mounted at a time.
5297c478bd9Sstevel@tonic-gate 	 */
5307c478bd9Sstevel@tonic-gate 	if (M && S && S[0] && S[1])
5317c478bd9Sstevel@tonic-gate 		LP_ERRMSG (WARNING, E_ADM_MSINGLES);
5327c478bd9Sstevel@tonic-gate 
5337c478bd9Sstevel@tonic-gate 	/*
5347c478bd9Sstevel@tonic-gate 	 * NO MOUNT:
5357c478bd9Sstevel@tonic-gate 	 * If the printer takes print wheels, the -S argument
5367c478bd9Sstevel@tonic-gate 	 * should be a simple list; otherwise, it must be a
5377c478bd9Sstevel@tonic-gate 	 * mapping list. (EXCEPT: In either case, "none" alone
5387c478bd9Sstevel@tonic-gate 	 * means delete the existing list.)
5397c478bd9Sstevel@tonic-gate 	 */
5407c478bd9Sstevel@tonic-gate 	if (S && !M) {
5417c478bd9Sstevel@tonic-gate 		register char		**item,
5427c478bd9Sstevel@tonic-gate 					*cp;
5437c478bd9Sstevel@tonic-gate 
5447c478bd9Sstevel@tonic-gate 		/*
5457c478bd9Sstevel@tonic-gate 		 * For us to be here, "daisy" must have been set.
5467c478bd9Sstevel@tonic-gate 		 * (-S requires knowing printer type (T), and knowing
5477c478bd9Sstevel@tonic-gate 		 * T caused call to "tidbit()" to set "daisy").
5487c478bd9Sstevel@tonic-gate 		 */
5497c478bd9Sstevel@tonic-gate 		if (!STREQU(S[0], NAME_NONE) || S[1])
5507c478bd9Sstevel@tonic-gate 		    if (daisy) {
5517c478bd9Sstevel@tonic-gate 			for (item = S; *item; item++) {
5527c478bd9Sstevel@tonic-gate 				if (strchr(*item, '=')) {
5537c478bd9Sstevel@tonic-gate 					LP_ERRMSG (ERROR, E_ADM_PWHEELS);
5547c478bd9Sstevel@tonic-gate 					done (1);
5557c478bd9Sstevel@tonic-gate 				}
5567c478bd9Sstevel@tonic-gate 				if (!syn_name(*item)) {
5577c478bd9Sstevel@tonic-gate 					LP_ERRMSG1 (ERROR, E_LP_NOTNAME, *item);
5587c478bd9Sstevel@tonic-gate 					done (1);
5597c478bd9Sstevel@tonic-gate 				}
5607c478bd9Sstevel@tonic-gate 			}
5617c478bd9Sstevel@tonic-gate 		    } else {
5627c478bd9Sstevel@tonic-gate 			register int		die = 0;
5637c478bd9Sstevel@tonic-gate 
5647c478bd9Sstevel@tonic-gate 			for (item = S; *item; item++) {
5657c478bd9Sstevel@tonic-gate 				if (!(cp = strchr(*item, '='))) {
5667c478bd9Sstevel@tonic-gate 					LP_ERRMSG (ERROR, E_ADM_CHARSETS);
5677c478bd9Sstevel@tonic-gate 					done (1);
5687c478bd9Sstevel@tonic-gate 				}
5697c478bd9Sstevel@tonic-gate 
5707c478bd9Sstevel@tonic-gate 				*cp = 0;
5717c478bd9Sstevel@tonic-gate 				if (!syn_name(*item)) {
5727c478bd9Sstevel@tonic-gate 					LP_ERRMSG1 (ERROR, E_LP_NOTNAME, *item);
5737c478bd9Sstevel@tonic-gate 					done (1);
5747c478bd9Sstevel@tonic-gate 				}
5757c478bd9Sstevel@tonic-gate 				if (PCK_CHARSET & sum_chkprinter(T, (char *)0, (char *)0, (char *)0, (char *)0, *item)) {
5767c478bd9Sstevel@tonic-gate 					LP_ERRMSG1 (ERROR, E_ADM_BADSET, *item);
5777c478bd9Sstevel@tonic-gate 					die = 1;
5787c478bd9Sstevel@tonic-gate 				} else {
5797c478bd9Sstevel@tonic-gate 					if (bad_list)
5807c478bd9Sstevel@tonic-gate 						LP_ERRMSG2 (
5817c478bd9Sstevel@tonic-gate 							INFO,
5827c478bd9Sstevel@tonic-gate 							E_ADM_NBADSET,
5837c478bd9Sstevel@tonic-gate 							*item,
5847c478bd9Sstevel@tonic-gate 							sprintlist(bad_list)
5857c478bd9Sstevel@tonic-gate 						);
5867c478bd9Sstevel@tonic-gate 				}
5877c478bd9Sstevel@tonic-gate 				*cp++ = '=';
5887c478bd9Sstevel@tonic-gate 				if (!syn_name(cp)) {
5897c478bd9Sstevel@tonic-gate 					LP_ERRMSG1 (ERROR, E_LP_NOTNAME, cp);
5907c478bd9Sstevel@tonic-gate 					done (1);
5917c478bd9Sstevel@tonic-gate 				}
5927c478bd9Sstevel@tonic-gate 			}
5937c478bd9Sstevel@tonic-gate 			if (die) {
5947c478bd9Sstevel@tonic-gate 				LP_ERRMSG (ERROR, E_ADM_BADSETS);
5957c478bd9Sstevel@tonic-gate 				done (1);
5967c478bd9Sstevel@tonic-gate 			}
5977c478bd9Sstevel@tonic-gate 		}
5987c478bd9Sstevel@tonic-gate 	}
5997c478bd9Sstevel@tonic-gate 
6007c478bd9Sstevel@tonic-gate 	if (P) {
6017c478bd9Sstevel@tonic-gate 		int createForm = 0;
6027c478bd9Sstevel@tonic-gate 		char **plist;
6037c478bd9Sstevel@tonic-gate 
6047c478bd9Sstevel@tonic-gate 		if (getform(P, &formbuf, (FALERT *)0, (FILE **)0) != -1) {
6057c478bd9Sstevel@tonic-gate 			if ((!formbuf.paper) || (!STREQU(formbuf.paper,P)) ) {
6067c478bd9Sstevel@tonic-gate 				LP_ERRMSG (ERROR, E_ADM_ALSO_SEP_FORM);
6077c478bd9Sstevel@tonic-gate 				done (1);
6087c478bd9Sstevel@tonic-gate 			}
6097c478bd9Sstevel@tonic-gate 		} else
6107c478bd9Sstevel@tonic-gate 			createForm = 1;
6117c478bd9Sstevel@tonic-gate 
6127c478bd9Sstevel@tonic-gate 		if (*P == '~') { /* removing types of papers */
6137c478bd9Sstevel@tonic-gate 			P++;
6147c478bd9Sstevel@tonic-gate 			p_remove = getlist(P, LP_WS, LP_SEP);
6157c478bd9Sstevel@tonic-gate 			p_add = NULL;
6167c478bd9Sstevel@tonic-gate 		} else  { /* adding types of papers */
6177c478bd9Sstevel@tonic-gate 			p_add = getlist(P, LP_WS, LP_SEP);
6187c478bd9Sstevel@tonic-gate 			p_remove = NULL;
6197c478bd9Sstevel@tonic-gate 			if (createForm) {
6207c478bd9Sstevel@tonic-gate 				char cmdBuf[200];
6217c478bd9Sstevel@tonic-gate 
6227c478bd9Sstevel@tonic-gate 				for (plist = p_add; *plist; plist++) {
6237c478bd9Sstevel@tonic-gate 					snprintf(cmdBuf, sizeof (cmdBuf),
6247c478bd9Sstevel@tonic-gate 					    "lpforms -f %s -d\n", *plist);
6257c478bd9Sstevel@tonic-gate 					system(cmdBuf);
6267c478bd9Sstevel@tonic-gate 				}
6277c478bd9Sstevel@tonic-gate 			}
6287c478bd9Sstevel@tonic-gate 		}
6297c478bd9Sstevel@tonic-gate 
6307c478bd9Sstevel@tonic-gate 		if (!f && !M) {  /* make paper allowed on printer too */
6317c478bd9Sstevel@tonic-gate 			f = Malloc(strlen(P) + strlen(NAME_ALLOW) +
6327c478bd9Sstevel@tonic-gate 			    strlen(": "));
6337c478bd9Sstevel@tonic-gate 			sprintf(f, "%s:%s", NAME_ALLOW, P);
6347c478bd9Sstevel@tonic-gate 			isfAuto = 1;
6357c478bd9Sstevel@tonic-gate 		}
6367c478bd9Sstevel@tonic-gate 	}
6377c478bd9Sstevel@tonic-gate 	/*
6387c478bd9Sstevel@tonic-gate 	 * NO MOUNT:
6397c478bd9Sstevel@tonic-gate 	 * The -f option restricts the forms that can be used with
6407c478bd9Sstevel@tonic-gate 	 * the printer.
6417c478bd9Sstevel@tonic-gate 	 *	- construct the allow/deny lists
6427c478bd9Sstevel@tonic-gate 	 *	- check each allowed form to see if it'll work
6437c478bd9Sstevel@tonic-gate 	 *	  on the printer
6447c478bd9Sstevel@tonic-gate 	 */
6457c478bd9Sstevel@tonic-gate 	if (f && !M) {
6467c478bd9Sstevel@tonic-gate 		register char		*type	= strtok(f, ":"),
6477c478bd9Sstevel@tonic-gate 					*str	= strtok((char *)0, ":"),
6487c478bd9Sstevel@tonic-gate 					**pf;
6497c478bd9Sstevel@tonic-gate 
6507c478bd9Sstevel@tonic-gate 		register int		die	= 0;
6517c478bd9Sstevel@tonic-gate 
6527c478bd9Sstevel@tonic-gate 
6537c478bd9Sstevel@tonic-gate 		if (STREQU(type, NAME_ALLOW) && str) {
6547c478bd9Sstevel@tonic-gate 			if ((pf = f_allow = getlist(str, LP_WS, LP_SEP)) != NULL) {
6557c478bd9Sstevel@tonic-gate 				while (*pf) {
6567c478bd9Sstevel@tonic-gate 					if ((!isfAuto) &&
6577c478bd9Sstevel@tonic-gate 						!STREQU(*pf, NAME_NONE)
6587c478bd9Sstevel@tonic-gate 					     && verify_form(*pf) < 0
6597c478bd9Sstevel@tonic-gate 					)
6607c478bd9Sstevel@tonic-gate 						die = 1;
6617c478bd9Sstevel@tonic-gate 					pf++;
6627c478bd9Sstevel@tonic-gate 				}
6637c478bd9Sstevel@tonic-gate 				if (die) {
6647c478bd9Sstevel@tonic-gate 					LP_ERRMSG (ERROR, E_ADM_FORMCAPS);
6657c478bd9Sstevel@tonic-gate 					done (1);
6667c478bd9Sstevel@tonic-gate 				}
6677c478bd9Sstevel@tonic-gate 
6687c478bd9Sstevel@tonic-gate 			} else
6697c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (WARNING, E_ADM_MISSING, NAME_ALLOW);
6707c478bd9Sstevel@tonic-gate 
6717c478bd9Sstevel@tonic-gate 		} else if (STREQU(type, NAME_DENY) && str) {
6727c478bd9Sstevel@tonic-gate 			if ((pf = f_deny = getlist(str, LP_WS, LP_SEP)) != NULL) {
6737c478bd9Sstevel@tonic-gate 				if (!STREQU(*pf, NAME_ALL)) {
6747c478bd9Sstevel@tonic-gate 					while (*pf) {
6757c478bd9Sstevel@tonic-gate 						if ((!isfAuto) &&
6767c478bd9Sstevel@tonic-gate 						  !STREQU(*pf, NAME_NONE) &&
6777c478bd9Sstevel@tonic-gate 					     	  getform(*pf, &formbuf,
6787c478bd9Sstevel@tonic-gate 						  (FALERT *)0, (FILE **)0) < 0
6797c478bd9Sstevel@tonic-gate 						) {
6807c478bd9Sstevel@tonic-gate 						   LP_ERRMSG2(WARNING,
6817c478bd9Sstevel@tonic-gate 							E_ADM_ICKFORM, *pf, p);
6827c478bd9Sstevel@tonic-gate 						   die = 1;
6837c478bd9Sstevel@tonic-gate 						}
6847c478bd9Sstevel@tonic-gate 						pf++;
6857c478bd9Sstevel@tonic-gate 					}
6867c478bd9Sstevel@tonic-gate 				}
6877c478bd9Sstevel@tonic-gate 				if (die) {
6887c478bd9Sstevel@tonic-gate 					done (1);
6897c478bd9Sstevel@tonic-gate 				}
6907c478bd9Sstevel@tonic-gate 
6917c478bd9Sstevel@tonic-gate 			} else
6927c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (WARNING, E_ADM_MISSING, NAME_DENY);
6937c478bd9Sstevel@tonic-gate 
6947c478bd9Sstevel@tonic-gate 		} else {
6957c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_ADM_FALLOWDENY);
6967c478bd9Sstevel@tonic-gate 			done (1);
6977c478bd9Sstevel@tonic-gate 		}
6987c478bd9Sstevel@tonic-gate 	}
6997c478bd9Sstevel@tonic-gate 
7007c478bd9Sstevel@tonic-gate 	/*
7017c478bd9Sstevel@tonic-gate 	 * The -u option is setting use restrictions on printers.
7027c478bd9Sstevel@tonic-gate 	 *	- construct the allow/deny lists
7037c478bd9Sstevel@tonic-gate 	 */
7047c478bd9Sstevel@tonic-gate 	if (u) {
7057c478bd9Sstevel@tonic-gate 		register char		*type	= strtok(u, ":"),
7067c478bd9Sstevel@tonic-gate 					*str	= strtok((char *)0, ":");
7077c478bd9Sstevel@tonic-gate 
7087c478bd9Sstevel@tonic-gate 		if (STREQU(type, NAME_ALLOW) && str) {
7097c478bd9Sstevel@tonic-gate 			if (!(u_allow = getlist(str, LP_WS, LP_SEP)))
7107c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (WARNING, E_ADM_MISSING, NAME_ALLOW);
7117c478bd9Sstevel@tonic-gate 
7127c478bd9Sstevel@tonic-gate 		} else if (STREQU(type, NAME_DENY) && str) {
7137c478bd9Sstevel@tonic-gate 			if (!(u_deny = getlist(str, LP_WS, LP_SEP)))
7147c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (WARNING, E_ADM_MISSING, NAME_DENY);
7157c478bd9Sstevel@tonic-gate 
7167c478bd9Sstevel@tonic-gate 		} else {
7177c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_LP_UALLOWDENY);
7187c478bd9Sstevel@tonic-gate 			done (1);
7197c478bd9Sstevel@tonic-gate 		}
7207c478bd9Sstevel@tonic-gate 	}
7217c478bd9Sstevel@tonic-gate 
7227c478bd9Sstevel@tonic-gate 	return;
7237c478bd9Sstevel@tonic-gate }
7247c478bd9Sstevel@tonic-gate 
7257c478bd9Sstevel@tonic-gate /**
7267c478bd9Sstevel@tonic-gate  ** root_can_write() - CHECK THAT "root" CAN SENSIBLY WRITE TO PATH
7277c478bd9Sstevel@tonic-gate  **/
7287c478bd9Sstevel@tonic-gate 
root_can_write(path)7297c478bd9Sstevel@tonic-gate static int		root_can_write (path)
7307c478bd9Sstevel@tonic-gate 	char			*path;
7317c478bd9Sstevel@tonic-gate {
7327c478bd9Sstevel@tonic-gate 	static int		lp_uid		= -1;
7337c478bd9Sstevel@tonic-gate 
7347c478bd9Sstevel@tonic-gate 	struct passwd		*ppw;
7357c478bd9Sstevel@tonic-gate 
7367c478bd9Sstevel@tonic-gate 	struct stat		statbuf;
7377c478bd9Sstevel@tonic-gate 
7387c478bd9Sstevel@tonic-gate 
7397c478bd9Sstevel@tonic-gate 	if (lstat(path, &statbuf) == -1) {
7407c478bd9Sstevel@tonic-gate 		LP_ERRMSG1 (ERROR, E_ADM_NOENT, v);
7417c478bd9Sstevel@tonic-gate 		return (-1);
7427c478bd9Sstevel@tonic-gate 	}
7437c478bd9Sstevel@tonic-gate 	/*
7447c478bd9Sstevel@tonic-gate 	 * If the device is a symlink (and it is not a root owned symlink),
7457c478bd9Sstevel@tonic-gate 	 * verify that the owner matches the destination owner.
7467c478bd9Sstevel@tonic-gate 	 */
7474bc0a2efScasper 	if (S_ISLNK(statbuf.st_mode) && statbuf.st_uid != 0) {
7487c478bd9Sstevel@tonic-gate 		uid_t uid = statbuf.st_uid;
7497c478bd9Sstevel@tonic-gate 
7507c478bd9Sstevel@tonic-gate 		if (Stat(path, &statbuf) == -1) {
7517c478bd9Sstevel@tonic-gate 			LP_ERRMSG1 (ERROR, E_ADM_NOENT, v);
7527c478bd9Sstevel@tonic-gate 			return (-1);
7537c478bd9Sstevel@tonic-gate 		}
7547c478bd9Sstevel@tonic-gate 
7557c478bd9Sstevel@tonic-gate 		if (statbuf.st_uid != uid) {
7567c478bd9Sstevel@tonic-gate 			LP_ERRMSG1 (ERROR, E_ADM_ISMISMATCH, v);
7577c478bd9Sstevel@tonic-gate 			done(1);
7587c478bd9Sstevel@tonic-gate 		}
7597c478bd9Sstevel@tonic-gate 
7607c478bd9Sstevel@tonic-gate 		LP_ERRMSG1(WARNING, E_ADM_ISNOTROOTOWNED, v);
7617c478bd9Sstevel@tonic-gate 	}
7627c478bd9Sstevel@tonic-gate 
7637c478bd9Sstevel@tonic-gate 	if ((statbuf.st_mode & S_IFMT) == S_IFDIR) {
7647c478bd9Sstevel@tonic-gate 		LP_ERRMSG1 (WARNING, E_ADM_ISDIR, v);
7657c478bd9Sstevel@tonic-gate 	} else if ((statbuf.st_mode & S_IFMT) == S_IFBLK)
7667c478bd9Sstevel@tonic-gate 		LP_ERRMSG1 (WARNING, E_ADM_ISBLK, v);
7677c478bd9Sstevel@tonic-gate 
7687c478bd9Sstevel@tonic-gate 	if (lp_uid == -1) {
7697c478bd9Sstevel@tonic-gate 		if (!(ppw = getpwnam(LPUSER)))
7707c478bd9Sstevel@tonic-gate 			ppw = getpwnam(ROOTUSER);
7717c478bd9Sstevel@tonic-gate 		endpwent ();
7727c478bd9Sstevel@tonic-gate 		if (ppw)
7737c478bd9Sstevel@tonic-gate 			lp_uid = ppw->pw_uid;
7747c478bd9Sstevel@tonic-gate 		else
7757c478bd9Sstevel@tonic-gate 			lp_uid = 0;
7767c478bd9Sstevel@tonic-gate 	}
7777c478bd9Sstevel@tonic-gate 	if (!STREQU(v, "/dev/null"))
7787c478bd9Sstevel@tonic-gate 	    if ((statbuf.st_uid && statbuf.st_uid != lp_uid)
7797c478bd9Sstevel@tonic-gate 		|| (statbuf.st_mode & (S_IWGRP|S_IRGRP|S_IWOTH|S_IROTH)))
7807c478bd9Sstevel@tonic-gate 		LP_ERRMSG1 (WARNING, E_ADM_DEVACCESS, v);
7817c478bd9Sstevel@tonic-gate 
7827c478bd9Sstevel@tonic-gate 	return (0);
7837c478bd9Sstevel@tonic-gate }
7847c478bd9Sstevel@tonic-gate 
7857c478bd9Sstevel@tonic-gate /**
7867c478bd9Sstevel@tonic-gate  ** unpack_sdn() - TURN SCALED TYPE INTO char* TYPE
7877c478bd9Sstevel@tonic-gate  **/
7887c478bd9Sstevel@tonic-gate 
unpack_sdn(sdn)7897c478bd9Sstevel@tonic-gate static char		*unpack_sdn (sdn)
7907c478bd9Sstevel@tonic-gate 	SCALED			sdn;
7917c478bd9Sstevel@tonic-gate {
7927c478bd9Sstevel@tonic-gate 	register char		*cp;
7937c478bd9Sstevel@tonic-gate 	extern char		*malloc();
7947c478bd9Sstevel@tonic-gate 
7957c478bd9Sstevel@tonic-gate 	if (sdn.val <= 0 || 99999 < sdn.val)
7967c478bd9Sstevel@tonic-gate 		cp = 0;
7977c478bd9Sstevel@tonic-gate 
7987c478bd9Sstevel@tonic-gate 	else if (sdn.val == N_COMPRESSED)
7997c478bd9Sstevel@tonic-gate 		cp = strdup(NAME_COMPRESSED);
8007c478bd9Sstevel@tonic-gate 
8017c478bd9Sstevel@tonic-gate 	else if ((cp = malloc(sizeof("99999.999x"))))
8027c478bd9Sstevel@tonic-gate 		(void) sprintf(cp, "%.3f%c", sdn.val, sdn.sc);
8037c478bd9Sstevel@tonic-gate 
8047c478bd9Sstevel@tonic-gate 	return (cp);
8057c478bd9Sstevel@tonic-gate }
8067c478bd9Sstevel@tonic-gate 
8077c478bd9Sstevel@tonic-gate /**
8087c478bd9Sstevel@tonic-gate  ** verify_form() - SEE IF PRINTER CAN HANDLE FORM
8097c478bd9Sstevel@tonic-gate  **/
8107c478bd9Sstevel@tonic-gate 
verify_form(form)8117c478bd9Sstevel@tonic-gate int			verify_form (form)
8127c478bd9Sstevel@tonic-gate 	char			*form;
8137c478bd9Sstevel@tonic-gate {
8147c478bd9Sstevel@tonic-gate 	register char		*cpi_f,
8157c478bd9Sstevel@tonic-gate 				*lpi_f,
8167c478bd9Sstevel@tonic-gate 				*width_f,
8177c478bd9Sstevel@tonic-gate 				*length_f,
8187c478bd9Sstevel@tonic-gate 				*chset;
8197c478bd9Sstevel@tonic-gate 
8207c478bd9Sstevel@tonic-gate 	register int		rc	= 0;
8217c478bd9Sstevel@tonic-gate 	char			**paperAllowed = NULL;
8227c478bd9Sstevel@tonic-gate 	char			**paperDenied = NULL;
8237c478bd9Sstevel@tonic-gate 
8247c478bd9Sstevel@tonic-gate 	register unsigned long	checks;
8257c478bd9Sstevel@tonic-gate 
8267c478bd9Sstevel@tonic-gate 
8277c478bd9Sstevel@tonic-gate 	if (STREQU(form, NAME_ANY))
8287c478bd9Sstevel@tonic-gate 		form = NAME_ALL;
8297c478bd9Sstevel@tonic-gate 
8307c478bd9Sstevel@tonic-gate 	while (getform(form, &formbuf, (FALERT *)0, (FILE **)0) != -1) {
8317c478bd9Sstevel@tonic-gate 		if (formbuf.paper) {
8327c478bd9Sstevel@tonic-gate 			if (!paperAllowed) {
8337c478bd9Sstevel@tonic-gate 				load_paperprinter_access(p, &paperAllowed,
8347c478bd9Sstevel@tonic-gate 					&paperDenied);
8357c478bd9Sstevel@tonic-gate 				freelist(paperDenied);
8367c478bd9Sstevel@tonic-gate 			}
8377c478bd9Sstevel@tonic-gate 			if (!allowed(formbuf.paper,paperAllowed,NULL)) {
8387c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (INFO, E_ADM_BADCAP,
8397c478bd9Sstevel@tonic-gate 				gettext("printer doesn't support paper type"));
8407c478bd9Sstevel@tonic-gate 				rc = -1;
8417c478bd9Sstevel@tonic-gate 			}
8427c478bd9Sstevel@tonic-gate 		}
8437c478bd9Sstevel@tonic-gate 		else {
844*2a8bcb4eSToomas Soome 
8457c478bd9Sstevel@tonic-gate 		cpi_f = unpack_sdn(formbuf.cpi);
8467c478bd9Sstevel@tonic-gate 		lpi_f = unpack_sdn(formbuf.lpi);
8477c478bd9Sstevel@tonic-gate 		width_f = unpack_sdn(formbuf.pwid);
8487c478bd9Sstevel@tonic-gate 		length_f = unpack_sdn(formbuf.plen);
8497c478bd9Sstevel@tonic-gate 
8507c478bd9Sstevel@tonic-gate 		if (
8517c478bd9Sstevel@tonic-gate 			formbuf.mandatory
8527c478bd9Sstevel@tonic-gate 		     && !daisy
8537c478bd9Sstevel@tonic-gate 		     && !search_cslist(
8547c478bd9Sstevel@tonic-gate 				formbuf.chset,
8557c478bd9Sstevel@tonic-gate 				(S && !M? S : (oldp? oldp->char_sets : (char **)0))
8567c478bd9Sstevel@tonic-gate 			)
8577c478bd9Sstevel@tonic-gate 		)
8587c478bd9Sstevel@tonic-gate 			chset = formbuf.chset;
8597c478bd9Sstevel@tonic-gate 		else
8607c478bd9Sstevel@tonic-gate 			chset = 0;
8617c478bd9Sstevel@tonic-gate 
8627c478bd9Sstevel@tonic-gate 		if ((checks = sum_chkprinter(
8637c478bd9Sstevel@tonic-gate 			T,
8647c478bd9Sstevel@tonic-gate 			cpi_f,
8657c478bd9Sstevel@tonic-gate 			lpi_f,
8667c478bd9Sstevel@tonic-gate 			length_f,
8677c478bd9Sstevel@tonic-gate 			width_f,
8687c478bd9Sstevel@tonic-gate 			chset
8697c478bd9Sstevel@tonic-gate 		))) {
8707c478bd9Sstevel@tonic-gate 			rc = -1;
8717c478bd9Sstevel@tonic-gate 			if ((checks & PCK_CPI) && cpi_f)
8727c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (INFO, E_ADM_BADCAP, "cpi");
8737c478bd9Sstevel@tonic-gate 
8747c478bd9Sstevel@tonic-gate 			if ((checks & PCK_LPI) && lpi_f)
8757c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (INFO, E_ADM_BADCAP, "lpi");
8767c478bd9Sstevel@tonic-gate 
8777c478bd9Sstevel@tonic-gate 			if ((checks & PCK_WIDTH) && width_f)
8787c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (INFO, E_ADM_BADCAP, "width");
8797c478bd9Sstevel@tonic-gate 
8807c478bd9Sstevel@tonic-gate 			if ((checks & PCK_LENGTH) && length_f)
8817c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (INFO, E_ADM_BADCAP, "length");
8827c478bd9Sstevel@tonic-gate 
8837c478bd9Sstevel@tonic-gate 			if ((checks & PCK_CHARSET) && formbuf.chset) {
8847c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (INFO, E_ADM_BADSET, formbuf.chset);
8857c478bd9Sstevel@tonic-gate 				rc = -2;
8867c478bd9Sstevel@tonic-gate 			}
8877c478bd9Sstevel@tonic-gate 			LP_ERRMSG1 (INFO, E_ADM_FORMCAP, formbuf.name);
8887c478bd9Sstevel@tonic-gate 		} else {
8897c478bd9Sstevel@tonic-gate 			if (bad_list)
8907c478bd9Sstevel@tonic-gate 				LP_ERRMSG2 (
8917c478bd9Sstevel@tonic-gate 					INFO,
8927c478bd9Sstevel@tonic-gate 					E_ADM_NBADMOUNT,
8937c478bd9Sstevel@tonic-gate 					formbuf.name,
8947c478bd9Sstevel@tonic-gate 					sprintlist(bad_list)
8957c478bd9Sstevel@tonic-gate 				);
8967c478bd9Sstevel@tonic-gate 		}
8977c478bd9Sstevel@tonic-gate 		}
8987c478bd9Sstevel@tonic-gate 
8997c478bd9Sstevel@tonic-gate 		if (!STREQU(form, NAME_ALL)) {
9007c478bd9Sstevel@tonic-gate 			if (paperAllowed)
9017c478bd9Sstevel@tonic-gate 				freelist(paperAllowed);
9027c478bd9Sstevel@tonic-gate 			return (rc);
9037c478bd9Sstevel@tonic-gate 		}
9047c478bd9Sstevel@tonic-gate 
9057c478bd9Sstevel@tonic-gate 	}
9067c478bd9Sstevel@tonic-gate 	if (paperAllowed)
9077c478bd9Sstevel@tonic-gate 		freelist(paperAllowed);
9087c478bd9Sstevel@tonic-gate 
9097c478bd9Sstevel@tonic-gate 	if (!STREQU(form, NAME_ALL)) {
9107c478bd9Sstevel@tonic-gate 		LP_ERRMSG1 (ERROR, E_LP_NOFORM, form);
9117c478bd9Sstevel@tonic-gate 		done (1);
9127c478bd9Sstevel@tonic-gate 	}
9137c478bd9Sstevel@tonic-gate 
9147c478bd9Sstevel@tonic-gate 	return (rc);
9157c478bd9Sstevel@tonic-gate }
9167c478bd9Sstevel@tonic-gate 
9177c478bd9Sstevel@tonic-gate /*
9187c478bd9Sstevel@tonic-gate 	Second phase of parsing for -p option.
9197c478bd9Sstevel@tonic-gate 	In a seperate routine so we can call it from other
920*2a8bcb4eSToomas Soome 	routines. This is used when any or all are used as
9217c478bd9Sstevel@tonic-gate 	a printer name. main() loops over each printer, and
9227c478bd9Sstevel@tonic-gate 	must call this function for each printer found.
9237c478bd9Sstevel@tonic-gate */
9247c478bd9Sstevel@tonic-gate void
chkopts2(called_from_chkopts)9257c478bd9Sstevel@tonic-gate chkopts2(called_from_chkopts)
9267c478bd9Sstevel@tonic-gate int	called_from_chkopts;
9277c478bd9Sstevel@tonic-gate {
9287c478bd9Sstevel@tonic-gate 	/*
9297c478bd9Sstevel@tonic-gate 		Only do the getprinter() if we are not being called
930*2a8bcb4eSToomas Soome 		from lpadmin.c. Otherwise we mess up our arena for
9317c478bd9Sstevel@tonic-gate 		"all" processing.
9327c478bd9Sstevel@tonic-gate 	*/
9337c478bd9Sstevel@tonic-gate 	if (!called_from_chkopts)
9347c478bd9Sstevel@tonic-gate 		oldp = printer_pointer;
9357c478bd9Sstevel@tonic-gate 	else if (!(oldp = getprinter(p)) && errno != ENOENT) {
9367c478bd9Sstevel@tonic-gate 		LP_ERRMSG2 (ERROR, E_LP_GETPRINTER, p, PERROR);
9377c478bd9Sstevel@tonic-gate 		done(1);
9387c478bd9Sstevel@tonic-gate 	}
9397c478bd9Sstevel@tonic-gate 
9407c478bd9Sstevel@tonic-gate 	if (oldp) {
9417c478bd9Sstevel@tonic-gate 		if (
9427c478bd9Sstevel@tonic-gate 			!c && !d && !f && !P && !M && !t && !r && !u && !x && !A
9437c478bd9Sstevel@tonic-gate 	     		&& !strlen(modifications)
9447c478bd9Sstevel@tonic-gate 		) {
9457c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_ADM_PLONELY);
9467c478bd9Sstevel@tonic-gate 			done (1);
9477c478bd9Sstevel@tonic-gate 		}
9487c478bd9Sstevel@tonic-gate 
9497c478bd9Sstevel@tonic-gate 		/*
9507c478bd9Sstevel@tonic-gate 		 * For the case "-s local-system", we need to keep
9517c478bd9Sstevel@tonic-gate 		 * "s != 0" long enough to get here, where it keeps
9527c478bd9Sstevel@tonic-gate 		 * us from taking the old value. After this, we make
9537c478bd9Sstevel@tonic-gate 		 * "s == 0" to indicate this is a local printer.
9547c478bd9Sstevel@tonic-gate 		 */
9557c478bd9Sstevel@tonic-gate 		if (s && s != Local_System)
9567c478bd9Sstevel@tonic-gate 			chksys(s);
9577c478bd9Sstevel@tonic-gate 		if (!s && oldp->remote && *(oldp->remote))
9587c478bd9Sstevel@tonic-gate 			s = strdup(oldp->remote);
9597c478bd9Sstevel@tonic-gate 		if (s == Local_System)
9607c478bd9Sstevel@tonic-gate 			s = 0;
9617c478bd9Sstevel@tonic-gate 
9627c478bd9Sstevel@tonic-gate 		/*
9637c478bd9Sstevel@tonic-gate 		 * A remote printer converted to a local printer
9647c478bd9Sstevel@tonic-gate 		 * requires device or dial info.
9657c478bd9Sstevel@tonic-gate 		 */
9667c478bd9Sstevel@tonic-gate 		if (!s && oldp->remote && !v && !U) {
9677c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_ADM_NOUV);
9687c478bd9Sstevel@tonic-gate 			done (1);
9697c478bd9Sstevel@tonic-gate 		}
9707c478bd9Sstevel@tonic-gate 
9717c478bd9Sstevel@tonic-gate 
9727c478bd9Sstevel@tonic-gate 	} else {
9737c478bd9Sstevel@tonic-gate 		if (getclass(p)) {
9747c478bd9Sstevel@tonic-gate 			LP_ERRMSG1 (ERROR, E_ADM_PRCL, p);
9757c478bd9Sstevel@tonic-gate 			done (1);
9767c478bd9Sstevel@tonic-gate 		}
9777c478bd9Sstevel@tonic-gate 
9787c478bd9Sstevel@tonic-gate 		if (!syn_name(p)) {
9797c478bd9Sstevel@tonic-gate 			LP_ERRMSG1 (ERROR, E_LP_NOTNAME, p);
9807c478bd9Sstevel@tonic-gate 			done (1);
9817c478bd9Sstevel@tonic-gate 		}
9827c478bd9Sstevel@tonic-gate 
9837c478bd9Sstevel@tonic-gate 		if (s == Local_System)
9847c478bd9Sstevel@tonic-gate 			s = 0;
9857c478bd9Sstevel@tonic-gate 		if (s)
9867c478bd9Sstevel@tonic-gate 			chksys(s);
9877c478bd9Sstevel@tonic-gate 
9887c478bd9Sstevel@tonic-gate #ifdef LP_USE_PAPI_ATTR
9897c478bd9Sstevel@tonic-gate 		/*
9907c478bd9Sstevel@tonic-gate 		 * New printer - if no model and a PPD file is defined then
991*2a8bcb4eSToomas Soome 		 *               use 'standard_foomatic' otherwise use
9927c478bd9Sstevel@tonic-gate 		 *               the 'standard' model.
9937c478bd9Sstevel@tonic-gate 		 */
9947c478bd9Sstevel@tonic-gate 		if (!(e || i || m) && !s) {
9957c478bd9Sstevel@tonic-gate 			if (n_opt != NULL) {
9967c478bd9Sstevel@tonic-gate 				m = STANDARD_FOOMATIC;
9977c478bd9Sstevel@tonic-gate 			} else {
9987c478bd9Sstevel@tonic-gate 				m = STANDARD;
9997c478bd9Sstevel@tonic-gate 			}
10007c478bd9Sstevel@tonic-gate 		}
10017c478bd9Sstevel@tonic-gate #else
10027c478bd9Sstevel@tonic-gate 		/*
10037c478bd9Sstevel@tonic-gate 		 * New printer - if no model, use standard
10047c478bd9Sstevel@tonic-gate 		 */
10057c478bd9Sstevel@tonic-gate 		if (!(e || i || m) && !s)
10067c478bd9Sstevel@tonic-gate 			m = STANDARD;
10077c478bd9Sstevel@tonic-gate #endif
10087c478bd9Sstevel@tonic-gate 
10097c478bd9Sstevel@tonic-gate 		/*
10107c478bd9Sstevel@tonic-gate 		 * A new printer requires device or dial info.
10117c478bd9Sstevel@tonic-gate 		 */
10127c478bd9Sstevel@tonic-gate 		if (!v && !U && !s) {
10137c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_ADM_NOUV);
10147c478bd9Sstevel@tonic-gate 			done (1);
10157c478bd9Sstevel@tonic-gate 		}
10167c478bd9Sstevel@tonic-gate 
10177c478bd9Sstevel@tonic-gate 		/*
10187c478bd9Sstevel@tonic-gate 		 * Can't quiet a new printer,
10197c478bd9Sstevel@tonic-gate 		 * can't list the alerting for a new printer.
10207c478bd9Sstevel@tonic-gate 		 */
10217c478bd9Sstevel@tonic-gate 		if (
10227c478bd9Sstevel@tonic-gate 			A
10237c478bd9Sstevel@tonic-gate 		     && (STREQU(A, NAME_QUIET) || STREQU(A, NAME_LIST))
10247c478bd9Sstevel@tonic-gate 		) {
10257c478bd9Sstevel@tonic-gate 			LP_ERRMSG1 (ERROR, E_ADM_BADQUIETORLIST, p);
10267c478bd9Sstevel@tonic-gate 			done (1);
10277c478bd9Sstevel@tonic-gate 		}
10287c478bd9Sstevel@tonic-gate 
10297c478bd9Sstevel@tonic-gate 		/*
10307c478bd9Sstevel@tonic-gate 		 * New printer - if no input types given, assume "simple".
10317c478bd9Sstevel@tonic-gate 		 */
10327c478bd9Sstevel@tonic-gate 		if (!I) {
10337c478bd9Sstevel@tonic-gate 			I = getlist(NAME_SIMPLE, LP_WS, LP_SEP);
10347c478bd9Sstevel@tonic-gate 			strcat (modifications, "I");
10357c478bd9Sstevel@tonic-gate 		}
10367c478bd9Sstevel@tonic-gate 	}
10377c478bd9Sstevel@tonic-gate }
10387c478bd9Sstevel@tonic-gate 
10397c478bd9Sstevel@tonic-gate /*
10407c478bd9Sstevel@tonic-gate 	Second phase of parsing for -S option.
10417c478bd9Sstevel@tonic-gate 	In a seperate routine so we can call it from other
1042*2a8bcb4eSToomas Soome 	routines. This is used when any or all are used as
10437c478bd9Sstevel@tonic-gate 	a print wheel name. main() loops over each print wheel,
10447c478bd9Sstevel@tonic-gate 	and must call this function for each print wheel found.
10457c478bd9Sstevel@tonic-gate */
10467c478bd9Sstevel@tonic-gate void
chkopts3(called_from_chkopts)10477c478bd9Sstevel@tonic-gate chkopts3(called_from_chkopts)
10487c478bd9Sstevel@tonic-gate int	called_from_chkopts;
10497c478bd9Sstevel@tonic-gate {
10507c478bd9Sstevel@tonic-gate 	/*
10517c478bd9Sstevel@tonic-gate 		Only do the getpwheel() if we are not being called
1052*2a8bcb4eSToomas Soome 		from lpadmin.c. Otherwise we mess up our arena for
10537c478bd9Sstevel@tonic-gate 		"all" processing.
10547c478bd9Sstevel@tonic-gate 	*/
10557c478bd9Sstevel@tonic-gate 	if (!called_from_chkopts)
10567c478bd9Sstevel@tonic-gate 		oldS = pwheel_pointer;
10577c478bd9Sstevel@tonic-gate 	else
10587c478bd9Sstevel@tonic-gate 		oldS = getpwheel(*S);
10597c478bd9Sstevel@tonic-gate 
10607c478bd9Sstevel@tonic-gate 	if (!oldS) {
10617c478bd9Sstevel@tonic-gate 		if (!syn_name(*S)) {
10627c478bd9Sstevel@tonic-gate 			LP_ERRMSG1 (ERROR, E_LP_NOTNAME, *S);
10637c478bd9Sstevel@tonic-gate 			done (1);
10647c478bd9Sstevel@tonic-gate 		}
10657c478bd9Sstevel@tonic-gate 
10667c478bd9Sstevel@tonic-gate 		/*
10677c478bd9Sstevel@tonic-gate 		 * Can't quiet a new print wheel,
10687c478bd9Sstevel@tonic-gate 		 * can't list the alerting for a new print wheel.
10697c478bd9Sstevel@tonic-gate 		 */
10707c478bd9Sstevel@tonic-gate 		if (
10717c478bd9Sstevel@tonic-gate 			A
10727c478bd9Sstevel@tonic-gate 		     && (STREQU(A, NAME_QUIET) || STREQU(A, NAME_LIST))
10737c478bd9Sstevel@tonic-gate 		) {
10747c478bd9Sstevel@tonic-gate 			LP_ERRMSG1 (ERROR, E_ADM_BADQUIETORLIST, *S);
10757c478bd9Sstevel@tonic-gate 			done (1);
10767c478bd9Sstevel@tonic-gate 		}
10777c478bd9Sstevel@tonic-gate 	}
10787c478bd9Sstevel@tonic-gate }
10797c478bd9Sstevel@tonic-gate 
10807c478bd9Sstevel@tonic-gate static void
chksys(s)10817c478bd9Sstevel@tonic-gate chksys(s)
10827c478bd9Sstevel@tonic-gate char	*s;
10837c478bd9Sstevel@tonic-gate {
10847c478bd9Sstevel@tonic-gate 	char	*cp;
10857c478bd9Sstevel@tonic-gate 
10867c478bd9Sstevel@tonic-gate 	if (STREQU(s, NAME_ALL) || STREQU(s, NAME_ANY)) {
10877c478bd9Sstevel@tonic-gate 		LP_ERRMSG (ERROR, E_ADM_ANYALLSYS);
10887c478bd9Sstevel@tonic-gate 		done(1);
10897c478bd9Sstevel@tonic-gate 	}
10907c478bd9Sstevel@tonic-gate 
10917c478bd9Sstevel@tonic-gate 	if ((cp = strchr(s, '!')) != NULL)
10927c478bd9Sstevel@tonic-gate 		*cp = '\0';
10937c478bd9Sstevel@tonic-gate 
10947c478bd9Sstevel@tonic-gate 	if (cp)
10957c478bd9Sstevel@tonic-gate 		*cp = '!';
10967c478bd9Sstevel@tonic-gate 
10977c478bd9Sstevel@tonic-gate 	return;
10987c478bd9Sstevel@tonic-gate }
10997c478bd9Sstevel@tonic-gate 
11007c478bd9Sstevel@tonic-gate /**
11017c478bd9Sstevel@tonic-gate  ** sum_chkprinter() - CHECK TERMINFO STUFF FOR A LIST OF PRINTER TYPES
11027c478bd9Sstevel@tonic-gate  **/
11037c478bd9Sstevel@tonic-gate 
11047c478bd9Sstevel@tonic-gate #include "lp.set.h"
11057c478bd9Sstevel@tonic-gate 
11067c478bd9Sstevel@tonic-gate static unsigned long
11077c478bd9Sstevel@tonic-gate #if	defined(__STDC__)
sum_chkprinter(char ** types,char * cpi,char * lpi,char * len,char * wid,char * cs)11087c478bd9Sstevel@tonic-gate sum_chkprinter (
11097c478bd9Sstevel@tonic-gate 	char **			types,
11107c478bd9Sstevel@tonic-gate 	char *			cpi,
11117c478bd9Sstevel@tonic-gate 	char *			lpi,
11127c478bd9Sstevel@tonic-gate 	char *			len,
11137c478bd9Sstevel@tonic-gate 	char *			wid,
11147c478bd9Sstevel@tonic-gate 	char *			cs
11157c478bd9Sstevel@tonic-gate )
11167c478bd9Sstevel@tonic-gate #else
11177c478bd9Sstevel@tonic-gate sum_chkprinter (types, cpi, lpi, len, wid, cs)
11187c478bd9Sstevel@tonic-gate 	char **			types;
11197c478bd9Sstevel@tonic-gate 	char *			cpi;
11207c478bd9Sstevel@tonic-gate 	char *			lpi;
11217c478bd9Sstevel@tonic-gate 	char *			len;
11227c478bd9Sstevel@tonic-gate 	char *			wid;
11237c478bd9Sstevel@tonic-gate 	char *			cs;
11247c478bd9Sstevel@tonic-gate #endif
11257c478bd9Sstevel@tonic-gate {
11267c478bd9Sstevel@tonic-gate 	char **			pt;
11277c478bd9Sstevel@tonic-gate 
11287c478bd9Sstevel@tonic-gate 	unsigned long		worst	= 0;
11297c478bd9Sstevel@tonic-gate 	unsigned long		this	= 0;
11307c478bd9Sstevel@tonic-gate 
11317c478bd9Sstevel@tonic-gate 
11327c478bd9Sstevel@tonic-gate 	/*
11337c478bd9Sstevel@tonic-gate 	 * Check each printer type, to see if any won't work with
11347c478bd9Sstevel@tonic-gate 	 * the attributes requested. However, return ``success''
11357c478bd9Sstevel@tonic-gate 	 * if at least one type works. Keep a list of the failed
11367c478bd9Sstevel@tonic-gate 	 * types for the caller to report.
11377c478bd9Sstevel@tonic-gate 	 */
11387c478bd9Sstevel@tonic-gate 	bad_list = 0;
11397c478bd9Sstevel@tonic-gate 	for (pt = types; *pt; pt++) {
11407c478bd9Sstevel@tonic-gate 		this = chkprinter(*pt, cpi, lpi, len, wid, cs);
11417c478bd9Sstevel@tonic-gate 		if (this != 0)
11427c478bd9Sstevel@tonic-gate 			addlist (&bad_list, *pt);
11437c478bd9Sstevel@tonic-gate 		worst |= this;
11447c478bd9Sstevel@tonic-gate 	}
11457c478bd9Sstevel@tonic-gate 	if (lenlist(types) == lenlist(bad_list))
11467c478bd9Sstevel@tonic-gate 		return (worst);
11477c478bd9Sstevel@tonic-gate 	else
11487c478bd9Sstevel@tonic-gate 		return (0);
11497c478bd9Sstevel@tonic-gate }
11507c478bd9Sstevel@tonic-gate 
11517c478bd9Sstevel@tonic-gate /*
11527c478bd9Sstevel@tonic-gate  * Function:    isPPD()
11537c478bd9Sstevel@tonic-gate  *
11547c478bd9Sstevel@tonic-gate  * Description: Check that the given PPD file exists. The argument given can
11557c478bd9Sstevel@tonic-gate  *              either be a relative path or a full path to the file.
11567c478bd9Sstevel@tonic-gate  *
11577c478bd9Sstevel@tonic-gate  * Returns:     1 = PPD file found
11587c478bd9Sstevel@tonic-gate  *              0 = PPD file not found
11597c478bd9Sstevel@tonic-gate  */
11607c478bd9Sstevel@tonic-gate 
11617c478bd9Sstevel@tonic-gate static int
isPPD(char * ppd_file)11627c478bd9Sstevel@tonic-gate isPPD(char *ppd_file)
11637c478bd9Sstevel@tonic-gate {
11647c478bd9Sstevel@tonic-gate 	int result = 0;
11657c478bd9Sstevel@tonic-gate 	char *ppd = NULL;
11667c478bd9Sstevel@tonic-gate 
11677c478bd9Sstevel@tonic-gate 	if (ppd_file != NULL) {
11687c478bd9Sstevel@tonic-gate 		if (*ppd_file == '/') {
11697c478bd9Sstevel@tonic-gate 			ppd = strdup(ppd_file);
11707c478bd9Sstevel@tonic-gate 		} else {
11717c478bd9Sstevel@tonic-gate 			ppd = makepath(Lp_Model, "ppd", ppd_file, (char *)0);
11727c478bd9Sstevel@tonic-gate 		}
11737c478bd9Sstevel@tonic-gate 
11747c478bd9Sstevel@tonic-gate 		/*
11757c478bd9Sstevel@tonic-gate 		 * now check the file exists
11767c478bd9Sstevel@tonic-gate 		 */
11777c478bd9Sstevel@tonic-gate 		if ((ppd != NULL) && (Access(ppd, 04) != -1)) {
11787c478bd9Sstevel@tonic-gate 			result = 1;
11797c478bd9Sstevel@tonic-gate 		} else {
11807c478bd9Sstevel@tonic-gate 			/*
11817c478bd9Sstevel@tonic-gate 			 * files does not exist so append .gz and check if
11827c478bd9Sstevel@tonic-gate 			 * that exist
11837c478bd9Sstevel@tonic-gate 			 */
11847c478bd9Sstevel@tonic-gate 			ppd = Realloc(ppd, strlen(ppd)+ strlen(PPDZIP)+2);
11857c478bd9Sstevel@tonic-gate 			if (ppd != NULL) {
11867c478bd9Sstevel@tonic-gate 				ppd = strcat(ppd, PPDZIP);
11877c478bd9Sstevel@tonic-gate 				if (Access(ppd, 04) != -1) {
11887c478bd9Sstevel@tonic-gate 					result = 1;
11897c478bd9Sstevel@tonic-gate 				}
11907c478bd9Sstevel@tonic-gate 			}
11917c478bd9Sstevel@tonic-gate 		}
11927c478bd9Sstevel@tonic-gate 
11937c478bd9Sstevel@tonic-gate 		if (ppd != NULL) {
11947c478bd9Sstevel@tonic-gate 			free(ppd);
11957c478bd9Sstevel@tonic-gate 		}
11967c478bd9Sstevel@tonic-gate 	}
11977c478bd9Sstevel@tonic-gate 	return (result);
11987c478bd9Sstevel@tonic-gate } /* isPPD() */
1199