xref: /illumos-gate/usr/src/cmd/lp/cmd/lpfilter.c (revision 55fea89d)
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 /*
23ace1a5f1Sdp  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
287c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
297c478bd9Sstevel@tonic-gate 
30ace1a5f1Sdp #include <stdio.h>
31ace1a5f1Sdp #include <errno.h>
32ace1a5f1Sdp #include <string.h>
337c478bd9Sstevel@tonic-gate #include <locale.h>
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #include "lp.h"
367c478bd9Sstevel@tonic-gate #include "access.h"
377c478bd9Sstevel@tonic-gate #include "filters.h"
387c478bd9Sstevel@tonic-gate #include "msgs.h"
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #define	WHO_AM_I	I_AM_LPFILTER
417c478bd9Sstevel@tonic-gate #include "oam.h"
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #define	OPT_LIST	"f:F:ixl"
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate int			add_filter(),
467c478bd9Sstevel@tonic-gate 			reload_filter(),
477c478bd9Sstevel@tonic-gate 			delete_filter(),
487c478bd9Sstevel@tonic-gate 			list_filter();
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate static void		alert_spooler(),
517c478bd9Sstevel@tonic-gate 			same_complaints();
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate static char		*opt();
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate /*
567c478bd9Sstevel@tonic-gate  * Unfortunately, the LP requirements show the listing of a filter
577c478bd9Sstevel@tonic-gate  * to be in a different order than the stored filter table. We can't
587c478bd9Sstevel@tonic-gate  * change the stored version because it's the same as UNISON uses.
597c478bd9Sstevel@tonic-gate  * So, we can't reuse the "FL_..." #defines found in "filters.h".
607c478bd9Sstevel@tonic-gate  * But the following have similar use.
617c478bd9Sstevel@tonic-gate  */
627c478bd9Sstevel@tonic-gate #define FL_MAX_P	FL_MAX
637c478bd9Sstevel@tonic-gate # define FL_IGN_P	8
647c478bd9Sstevel@tonic-gate # define FL_PTYPS_P	2
657c478bd9Sstevel@tonic-gate # define FL_PRTRS_P	3
667c478bd9Sstevel@tonic-gate # define FL_ITYPS_P	0
677c478bd9Sstevel@tonic-gate # define FL_NAME_P	7
687c478bd9Sstevel@tonic-gate # define FL_OTYPS_P	1
697c478bd9Sstevel@tonic-gate # define FL_TYPE_P	4
707c478bd9Sstevel@tonic-gate # define FL_CMD_P	5
717c478bd9Sstevel@tonic-gate # define FL_TMPS_P	6
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate #define	TABLE		0
747c478bd9Sstevel@tonic-gate #define	TABLE_I		1
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate static struct headings {
777c478bd9Sstevel@tonic-gate 	char			*v;
787c478bd9Sstevel@tonic-gate 	short			len;
797c478bd9Sstevel@tonic-gate }		headings[FL_MAX_P] = {
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate #define	ENTRY(X)	X, sizeof(X)-1
827c478bd9Sstevel@tonic-gate 	ENTRY("Input types:"),
837c478bd9Sstevel@tonic-gate 	ENTRY("Output types:"),
847c478bd9Sstevel@tonic-gate 	ENTRY("Printer types:"),
857c478bd9Sstevel@tonic-gate 	ENTRY("Printers:"),
867c478bd9Sstevel@tonic-gate 	ENTRY("Filter type:"),
877c478bd9Sstevel@tonic-gate 	ENTRY("Command:"),
887c478bd9Sstevel@tonic-gate 	ENTRY("Options:"),
897c478bd9Sstevel@tonic-gate 	ENTRY(""),
907c478bd9Sstevel@tonic-gate 	ENTRY("")
917c478bd9Sstevel@tonic-gate #undef	ENTRY
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate };
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate /**
967c478bd9Sstevel@tonic-gate  ** usage()
977c478bd9Sstevel@tonic-gate  **/
987c478bd9Sstevel@tonic-gate 
usage()997c478bd9Sstevel@tonic-gate void			usage ()
1007c478bd9Sstevel@tonic-gate {
1017c478bd9Sstevel@tonic-gate 	(void) printf (gettext(
1027c478bd9Sstevel@tonic-gate "usage:\n"
1037c478bd9Sstevel@tonic-gate "\n"
1047c478bd9Sstevel@tonic-gate "  (add or change filter)\n"
1057c478bd9Sstevel@tonic-gate "    lpfilter -f filter-name {-F path-name | -}\n"
1067c478bd9Sstevel@tonic-gate "\n"
1077c478bd9Sstevel@tonic-gate "  (restore delivered filter)\n"
1087c478bd9Sstevel@tonic-gate "    lpfilter -f filter-name -i\n"
1097c478bd9Sstevel@tonic-gate "\n"
1107c478bd9Sstevel@tonic-gate "  (list a filter)\n"
1117c478bd9Sstevel@tonic-gate "    lpfilter -f filter-name -l\n"
1127c478bd9Sstevel@tonic-gate "\n"
1137c478bd9Sstevel@tonic-gate "  (list all filters)\n"
1147c478bd9Sstevel@tonic-gate "    lpfilter -f \"all\" -l\n"
1157c478bd9Sstevel@tonic-gate "\n"
1167c478bd9Sstevel@tonic-gate "  (delete filter)\n"
1177c478bd9Sstevel@tonic-gate "    lpfilter -f filter-name -x\n"));
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate 	return;
1207c478bd9Sstevel@tonic-gate }
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate /**
1237c478bd9Sstevel@tonic-gate  ** main()
1247c478bd9Sstevel@tonic-gate  **/
1257c478bd9Sstevel@tonic-gate 
main(argc,argv)1267c478bd9Sstevel@tonic-gate int			main (argc, argv)
1277c478bd9Sstevel@tonic-gate 	int			argc;
1287c478bd9Sstevel@tonic-gate 	char			*argv[];
1297c478bd9Sstevel@tonic-gate {
1307c478bd9Sstevel@tonic-gate 	extern int		optind,
1317c478bd9Sstevel@tonic-gate 				opterr,
1327c478bd9Sstevel@tonic-gate 				optopt,
1337c478bd9Sstevel@tonic-gate 				getopt();
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate 	extern char		*optarg;
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate 	int			c,
1387c478bd9Sstevel@tonic-gate 				(*action)(),
1397c478bd9Sstevel@tonic-gate 				(*newaction)();
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate 	FILE			*input;
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate 	char			*filter,
1447c478bd9Sstevel@tonic-gate 				*p;
145268ffd3aSRichard Lowe 	char			stroptsw[] = "-X";
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate 	(void) setlocale (LC_ALL, "");
1497c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
1507c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST"
1517c478bd9Sstevel@tonic-gate #endif
1527c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate 	if (!is_user_admin()) {
1557c478bd9Sstevel@tonic-gate 		LP_ERRMSG (ERROR, E_LP_NOTADM);
1567c478bd9Sstevel@tonic-gate 		exit (1);
1577c478bd9Sstevel@tonic-gate 	}
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate 	action = 0;
1607c478bd9Sstevel@tonic-gate 	input = 0;
1617c478bd9Sstevel@tonic-gate 	filter = 0;
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate 	opterr = 0;
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate 	while ((c = getopt(argc, argv, OPT_LIST)) != -1) switch (c) {
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate 	case 'f':
1687c478bd9Sstevel@tonic-gate 		if (filter)
1697c478bd9Sstevel@tonic-gate 			LP_ERRMSG1 (WARNING, E_LP_2MANY, 'f');
1707c478bd9Sstevel@tonic-gate 		filter = optarg;
1717c478bd9Sstevel@tonic-gate 		if (
1727c478bd9Sstevel@tonic-gate 			STREQU(NAME_ANY, filter)
1737c478bd9Sstevel@tonic-gate 		     || STREQU(NAME_NONE, filter)
1747c478bd9Sstevel@tonic-gate 		) {
1757c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_LP_ANYNONE);
1767c478bd9Sstevel@tonic-gate 			exit (1);
1777c478bd9Sstevel@tonic-gate 		} else if (!syn_name(filter)) {
1787c478bd9Sstevel@tonic-gate 			LP_ERRMSG1 (ERROR, E_LP_NOTNAME, filter);
1797c478bd9Sstevel@tonic-gate 			exit (1);
1807c478bd9Sstevel@tonic-gate 		} else if (!*filter)
1817c478bd9Sstevel@tonic-gate 			filter = NAME_ALL;
1827c478bd9Sstevel@tonic-gate 		break;
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate 	case 'F':
1857c478bd9Sstevel@tonic-gate 		if (input)
1867c478bd9Sstevel@tonic-gate 			LP_ERRMSG1 (WARNING, E_LP_2MANY, 'F');
1877c478bd9Sstevel@tonic-gate 		if (!(input = fopen(optarg, "r"))) {
1887c478bd9Sstevel@tonic-gate 			LP_ERRMSG1 (ERROR, E_FL_OPEN, optarg);
1897c478bd9Sstevel@tonic-gate 			exit (1);
1907c478bd9Sstevel@tonic-gate 		}
1917c478bd9Sstevel@tonic-gate 		newaction = add_filter;
1927c478bd9Sstevel@tonic-gate 		goto Check;
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate 	case 'i':
1957c478bd9Sstevel@tonic-gate 		newaction = reload_filter;
1967c478bd9Sstevel@tonic-gate 		goto Check;
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate 	case 'x':
1997c478bd9Sstevel@tonic-gate 		newaction = delete_filter;
2007c478bd9Sstevel@tonic-gate 		goto Check;
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate 	case 'l':
2037c478bd9Sstevel@tonic-gate 		newaction = list_filter;
2047c478bd9Sstevel@tonic-gate Check:		if (action && newaction != action) {
2057c478bd9Sstevel@tonic-gate 			LP_ERRMSG2 (
2067c478bd9Sstevel@tonic-gate 				ERROR,
2077c478bd9Sstevel@tonic-gate 				E_LP_AMBIG,
2087c478bd9Sstevel@tonic-gate 				opt(action),
2097c478bd9Sstevel@tonic-gate 				opt(newaction)
2107c478bd9Sstevel@tonic-gate 			);
2117c478bd9Sstevel@tonic-gate 			exit (1);
2127c478bd9Sstevel@tonic-gate 		}
2137c478bd9Sstevel@tonic-gate 		action = newaction;
2147c478bd9Sstevel@tonic-gate 		break;
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate 	default:
2177c478bd9Sstevel@tonic-gate 		if (optopt == '?') {
2187c478bd9Sstevel@tonic-gate 			usage ();
2197c478bd9Sstevel@tonic-gate 			exit (0);
2207c478bd9Sstevel@tonic-gate 		}
221268ffd3aSRichard Lowe 		stroptsw[1] = optopt;
2227c478bd9Sstevel@tonic-gate 		if (strchr(OPT_LIST, optopt))
223268ffd3aSRichard Lowe 			LP_ERRMSG1 (ERROR, E_LP_OPTARG, stroptsw);
2247c478bd9Sstevel@tonic-gate 		else
225268ffd3aSRichard Lowe 			LP_ERRMSG1 (ERROR, E_LP_OPTION, stroptsw);
2267c478bd9Sstevel@tonic-gate 		exit (1);
2277c478bd9Sstevel@tonic-gate 
2287c478bd9Sstevel@tonic-gate 	}
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate 	if (optind < argc && STREQU(argv[optind], "-"))
2317c478bd9Sstevel@tonic-gate 		if (action) {
2327c478bd9Sstevel@tonic-gate 	 		LP_ERRMSG2 (ERROR, E_LP_AMBIG, opt(action), "-");
2337c478bd9Sstevel@tonic-gate 			exit (1);
2347c478bd9Sstevel@tonic-gate 		} else {
2357c478bd9Sstevel@tonic-gate 			action = add_filter;
2367c478bd9Sstevel@tonic-gate 			optind++;
2377c478bd9Sstevel@tonic-gate 		}
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate 	if (!filter) {
2407c478bd9Sstevel@tonic-gate 		LP_ERRMSG (ERROR, E_FL_NOFILT);
2417c478bd9Sstevel@tonic-gate 		exit (1);
2427c478bd9Sstevel@tonic-gate 	}
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate 	if (!action) {
2457c478bd9Sstevel@tonic-gate 		LP_ERRMSG (ERROR, E_FL_NOACT);
2467c478bd9Sstevel@tonic-gate 		exit (1);
2477c478bd9Sstevel@tonic-gate 	}
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate 	if (optind < argc)
2507c478bd9Sstevel@tonic-gate 		LP_ERRMSG1 (WARNING, E_FL_IGNORE, argv[optind]);
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate 	return ((*action)(filter, input));
2537c478bd9Sstevel@tonic-gate }
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate /**
2567c478bd9Sstevel@tonic-gate  ** add_filter()
2577c478bd9Sstevel@tonic-gate  **/
2587c478bd9Sstevel@tonic-gate 
add_filter(filter,input)2597c478bd9Sstevel@tonic-gate int			add_filter (filter, input)
2607c478bd9Sstevel@tonic-gate 	char			*filter;
2617c478bd9Sstevel@tonic-gate 	FILE			*input;
2627c478bd9Sstevel@tonic-gate {
2637c478bd9Sstevel@tonic-gate 	register FILTER		*pf,
2647c478bd9Sstevel@tonic-gate 				*store,
2657c478bd9Sstevel@tonic-gate 				*ps;
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate 	register int		fld;
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate 	register char		*p;
2707c478bd9Sstevel@tonic-gate 
2717c478bd9Sstevel@tonic-gate 	char			buf[3 * BUFSIZ],
2727c478bd9Sstevel@tonic-gate 				*file;
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate 	int			line,
2757c478bd9Sstevel@tonic-gate 				bad_headings,
2767c478bd9Sstevel@tonic-gate 				real_fields[FL_MAX],
2777c478bd9Sstevel@tonic-gate 				at_least_one,
2787c478bd9Sstevel@tonic-gate 				ret;
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate 	FILTER			flbuf;
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate 	/*
2847c478bd9Sstevel@tonic-gate 	 * First we read in the input and parse it into a filter,
2857c478bd9Sstevel@tonic-gate 	 * storing it in the filter buffer "flbuf". Keep track of
2867c478bd9Sstevel@tonic-gate 	 * which fields have been given, to avoid overwriting unchanged
2877c478bd9Sstevel@tonic-gate 	 * fields later.
2887c478bd9Sstevel@tonic-gate 	 */
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate 	if (!input)
2917c478bd9Sstevel@tonic-gate 		input = stdin;
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate 	for (fld = 0; fld < FL_MAX; fld++)
2947c478bd9Sstevel@tonic-gate 		real_fields[fld] = 0;
2957c478bd9Sstevel@tonic-gate 	flbuf.templates = 0;
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate 	line = bad_headings = 0;
2987c478bd9Sstevel@tonic-gate 	while (fgets(buf, sizeof(buf), input) != NULL) {
2997c478bd9Sstevel@tonic-gate 
3007c478bd9Sstevel@tonic-gate 		buf[strlen(buf) - 1] = 0;
3017c478bd9Sstevel@tonic-gate 
3027c478bd9Sstevel@tonic-gate 		line++;
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate 		p = buf + strspn(buf, " \t");
3057c478bd9Sstevel@tonic-gate 		if (!*p || *p == '#')
3067c478bd9Sstevel@tonic-gate 			continue;
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate 		for (fld = 0; fld < FL_MAX; fld++)
3097c478bd9Sstevel@tonic-gate 			if (
3107c478bd9Sstevel@tonic-gate 				headings[fld].v
3117c478bd9Sstevel@tonic-gate 			     && headings[fld].len
3127c478bd9Sstevel@tonic-gate 			     && CS_STRNEQU(
3137c478bd9Sstevel@tonic-gate 					p,
3147c478bd9Sstevel@tonic-gate 					headings[fld].v,
3157c478bd9Sstevel@tonic-gate 					headings[fld].len
3167c478bd9Sstevel@tonic-gate 				)
3177c478bd9Sstevel@tonic-gate 			) {
3187c478bd9Sstevel@tonic-gate 				real_fields[fld] = 1;
3197c478bd9Sstevel@tonic-gate 				p += headings[fld].len + 1;
3207c478bd9Sstevel@tonic-gate 				break;
3217c478bd9Sstevel@tonic-gate 			}
3227c478bd9Sstevel@tonic-gate 
3237c478bd9Sstevel@tonic-gate 		if (fld >= FL_MAX) {
3247c478bd9Sstevel@tonic-gate 
3257c478bd9Sstevel@tonic-gate 			if (bad_headings++ >= 5) {
3267c478bd9Sstevel@tonic-gate 				LP_ERRMSG (ERROR, E_FL_GARBAGE);
3277c478bd9Sstevel@tonic-gate 				return (1);
3287c478bd9Sstevel@tonic-gate 			}
3297c478bd9Sstevel@tonic-gate 			LP_ERRMSG1 (WARNING, E_FL_HEADING, line);
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate 		} else switch (fld) {
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate 			case FL_IGN_P:
3347c478bd9Sstevel@tonic-gate 			case FL_NAME_P:
3357c478bd9Sstevel@tonic-gate 				break;
3367c478bd9Sstevel@tonic-gate 			case FL_CMD_P:
3377c478bd9Sstevel@tonic-gate 				flbuf.command = strdup(strip(p));
3387c478bd9Sstevel@tonic-gate 				break;
3397c478bd9Sstevel@tonic-gate 			case FL_TYPE_P:
3407c478bd9Sstevel@tonic-gate 				flbuf.type = s_to_filtertype(strip(p));
3417c478bd9Sstevel@tonic-gate 				break;
3427c478bd9Sstevel@tonic-gate 			case FL_PTYPS_P:
3437c478bd9Sstevel@tonic-gate 				flbuf.printer_types = getlist(p, LP_WS, LP_SEP);
3447c478bd9Sstevel@tonic-gate 				break;
3457c478bd9Sstevel@tonic-gate 			case FL_ITYPS_P:
3467c478bd9Sstevel@tonic-gate 				flbuf.input_types = getlist(p, LP_WS, LP_SEP);
3477c478bd9Sstevel@tonic-gate 				break;
3487c478bd9Sstevel@tonic-gate 			case FL_OTYPS_P:
3497c478bd9Sstevel@tonic-gate 				flbuf.output_types = getlist(p, LP_WS, LP_SEP);
3507c478bd9Sstevel@tonic-gate 				break;
3517c478bd9Sstevel@tonic-gate 			case FL_PRTRS_P:
3527c478bd9Sstevel@tonic-gate 				flbuf.printers = getlist(p, LP_WS, LP_SEP);
3537c478bd9Sstevel@tonic-gate 				break;
3547c478bd9Sstevel@tonic-gate 			case FL_TMPS_P:
3557c478bd9Sstevel@tonic-gate 				if (flbuf.templates) {
3567c478bd9Sstevel@tonic-gate 					char			**temp;
3577c478bd9Sstevel@tonic-gate 
3587c478bd9Sstevel@tonic-gate 					temp = getlist(p, "", LP_SEP);
3597c478bd9Sstevel@tonic-gate 					mergelist (&(flbuf.templates), temp);
3607c478bd9Sstevel@tonic-gate 					freelist (temp);
3617c478bd9Sstevel@tonic-gate 				} else
3627c478bd9Sstevel@tonic-gate 					flbuf.templates = getlist(p, "", LP_SEP);
3637c478bd9Sstevel@tonic-gate 				break;
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate 		}
3667c478bd9Sstevel@tonic-gate 
3677c478bd9Sstevel@tonic-gate 	}
3687c478bd9Sstevel@tonic-gate 	if (ferror(input)) {
3697c478bd9Sstevel@tonic-gate 		LP_ERRMSG (ERROR, E_FL_READ);
3707c478bd9Sstevel@tonic-gate 		return (1);
3717c478bd9Sstevel@tonic-gate 	}
3727c478bd9Sstevel@tonic-gate 
3737c478bd9Sstevel@tonic-gate 	/*
3747c478bd9Sstevel@tonic-gate 	 * We have the input stored, now get the current copy of the
3757c478bd9Sstevel@tonic-gate 	 * filter(s). If no filter exists, we create it.
3767c478bd9Sstevel@tonic-gate 	 */
3777c478bd9Sstevel@tonic-gate 
3787c478bd9Sstevel@tonic-gate 	if (STREQU(NAME_ALL, filter)) {
3797c478bd9Sstevel@tonic-gate 
3807c478bd9Sstevel@tonic-gate 		/*
3817c478bd9Sstevel@tonic-gate 		 * Adding ``all'' means changing all filters to reflect
3827c478bd9Sstevel@tonic-gate 		 * the information in the input. We'll preload the
3837c478bd9Sstevel@tonic-gate 		 * filters so that we know how many there are.
3847c478bd9Sstevel@tonic-gate 		 */
3857c478bd9Sstevel@tonic-gate 		if (
3867c478bd9Sstevel@tonic-gate 			!(file = getfilterfile(FILTERTABLE))
3877c478bd9Sstevel@tonic-gate 		     || loadfilters(file) == -1
3887c478bd9Sstevel@tonic-gate 		) {
3897c478bd9Sstevel@tonic-gate 			switch (errno) {
3907c478bd9Sstevel@tonic-gate 			case ENOENT:
3917c478bd9Sstevel@tonic-gate 				LP_ERRMSG (ERROR, E_FL_NOTALL);
3927c478bd9Sstevel@tonic-gate 				break;
3937c478bd9Sstevel@tonic-gate 			default:
3947c478bd9Sstevel@tonic-gate 				same_complaints (FILTERTABLE, TABLE);
3957c478bd9Sstevel@tonic-gate 				break;
3967c478bd9Sstevel@tonic-gate 			}
3977c478bd9Sstevel@tonic-gate 			return (1);
3987c478bd9Sstevel@tonic-gate 		}
3997c478bd9Sstevel@tonic-gate 
4007c478bd9Sstevel@tonic-gate 		store = (FILTER *)malloc((nfilters + 1) * sizeof(FILTER));
4017c478bd9Sstevel@tonic-gate 		if (!store) {
4027c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_LP_MALLOC);
4037c478bd9Sstevel@tonic-gate 			return (1);
4047c478bd9Sstevel@tonic-gate 		}
405*55fea89dSDan Cross 
4067c478bd9Sstevel@tonic-gate 		for (ps = store; (pf = getfilter(filter)); )
4077c478bd9Sstevel@tonic-gate 			*ps++ = *pf;
4087c478bd9Sstevel@tonic-gate 		ps->name = 0;
4097c478bd9Sstevel@tonic-gate 
4107c478bd9Sstevel@tonic-gate 		switch (errno) {
4117c478bd9Sstevel@tonic-gate 		case ENOENT:
4127c478bd9Sstevel@tonic-gate 			if (ps - store != nfilters) {
4137c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (
4147c478bd9Sstevel@tonic-gate 					ERROR,
4157c478bd9Sstevel@tonic-gate 					E_FL_STRANGE,
4167c478bd9Sstevel@tonic-gate 					getfilterfile(FILTERTABLE)
4177c478bd9Sstevel@tonic-gate 				);
4187c478bd9Sstevel@tonic-gate 				return (1);
4197c478bd9Sstevel@tonic-gate 			}
4207c478bd9Sstevel@tonic-gate 			break;
4217c478bd9Sstevel@tonic-gate 		default:
4227c478bd9Sstevel@tonic-gate 			same_complaints (FILTERTABLE, TABLE);
4237c478bd9Sstevel@tonic-gate 			return (1);
4247c478bd9Sstevel@tonic-gate 		}
4257c478bd9Sstevel@tonic-gate 
4267c478bd9Sstevel@tonic-gate 	} else {
4277c478bd9Sstevel@tonic-gate 
4287c478bd9Sstevel@tonic-gate 		store = (FILTER *)malloc(2 * sizeof(FILTER));
4297c478bd9Sstevel@tonic-gate 		if (!store) {
4307c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_LP_MALLOC);
4317c478bd9Sstevel@tonic-gate 			return (1);
4327c478bd9Sstevel@tonic-gate 		}
433*55fea89dSDan Cross 
4347c478bd9Sstevel@tonic-gate 		if ((pf = getfilter(filter))) {
4357c478bd9Sstevel@tonic-gate 			store[0] = *pf;
4367c478bd9Sstevel@tonic-gate 		} else
4377c478bd9Sstevel@tonic-gate 			switch (errno) {
4387c478bd9Sstevel@tonic-gate 			case ENOENT:
4397c478bd9Sstevel@tonic-gate 				/*
4407c478bd9Sstevel@tonic-gate 				 * We must be adding a new filter, so
4417c478bd9Sstevel@tonic-gate 				 * set up default values. Check that
4427c478bd9Sstevel@tonic-gate 				 * we'll have something reasonable to add.
4437c478bd9Sstevel@tonic-gate 				 */
4447c478bd9Sstevel@tonic-gate 				pf = store;
4457c478bd9Sstevel@tonic-gate 				pf->name = strdup(filter);
4467c478bd9Sstevel@tonic-gate 				pf->command = 0;
4477c478bd9Sstevel@tonic-gate 				pf->type = fl_slow;
4487c478bd9Sstevel@tonic-gate 				pf->printer_types = 0;
4497c478bd9Sstevel@tonic-gate 				pf->printers = 0;
4507c478bd9Sstevel@tonic-gate 				pf->input_types = 0;
4517c478bd9Sstevel@tonic-gate 				pf->output_types = 0;
4527c478bd9Sstevel@tonic-gate 				pf->templates = 0;
4537c478bd9Sstevel@tonic-gate 				if (!flbuf.command) {
4547c478bd9Sstevel@tonic-gate 					LP_ERRMSG (ERROR, E_FL_NOCMD);
4557c478bd9Sstevel@tonic-gate 					return (1);
4567c478bd9Sstevel@tonic-gate 				}
4577c478bd9Sstevel@tonic-gate 				break;
4587c478bd9Sstevel@tonic-gate 			default:
4597c478bd9Sstevel@tonic-gate 				same_complaints (FILTERTABLE, TABLE);
4607c478bd9Sstevel@tonic-gate 				return (1);
4617c478bd9Sstevel@tonic-gate 			}
4627c478bd9Sstevel@tonic-gate 
4637c478bd9Sstevel@tonic-gate 		store[1].name = 0;
464*55fea89dSDan Cross 
4657c478bd9Sstevel@tonic-gate 	}
4667c478bd9Sstevel@tonic-gate 
4677c478bd9Sstevel@tonic-gate 	at_least_one = ret = 0;
4687c478bd9Sstevel@tonic-gate 	for (ps = store; ps->name; ps++) {
4697c478bd9Sstevel@tonic-gate 
4707c478bd9Sstevel@tonic-gate 		for (fld = 0; fld < FL_MAX; fld++)
4717c478bd9Sstevel@tonic-gate 			if (real_fields[fld]) switch(fld) {
4727c478bd9Sstevel@tonic-gate 			case FL_IGN_P:
4737c478bd9Sstevel@tonic-gate 			case FL_NAME_P:
4747c478bd9Sstevel@tonic-gate 				break;
4757c478bd9Sstevel@tonic-gate 			case FL_CMD_P:
4767c478bd9Sstevel@tonic-gate 				ps->command = flbuf.command;
4777c478bd9Sstevel@tonic-gate 				break;
4787c478bd9Sstevel@tonic-gate 			case FL_TYPE_P:
4797c478bd9Sstevel@tonic-gate 				ps->type = flbuf.type;
4807c478bd9Sstevel@tonic-gate 				break;
4817c478bd9Sstevel@tonic-gate 			case FL_PTYPS_P:
4827c478bd9Sstevel@tonic-gate 				ps->printer_types = flbuf.printer_types;
4837c478bd9Sstevel@tonic-gate 				break;
4847c478bd9Sstevel@tonic-gate 			case FL_ITYPS_P:
4857c478bd9Sstevel@tonic-gate 				ps->input_types = flbuf.input_types;
4867c478bd9Sstevel@tonic-gate 				break;
4877c478bd9Sstevel@tonic-gate 			case FL_OTYPS_P:
4887c478bd9Sstevel@tonic-gate 				ps->output_types = flbuf.output_types;
4897c478bd9Sstevel@tonic-gate 				break;
4907c478bd9Sstevel@tonic-gate 			case FL_PRTRS_P:
4917c478bd9Sstevel@tonic-gate 				ps->printers = flbuf.printers;
4927c478bd9Sstevel@tonic-gate 				break;
4937c478bd9Sstevel@tonic-gate 			case FL_TMPS_P:
4947c478bd9Sstevel@tonic-gate 				ps->templates = flbuf.templates;
4957c478bd9Sstevel@tonic-gate 				break;
4967c478bd9Sstevel@tonic-gate 			}
4977c478bd9Sstevel@tonic-gate 
4987c478bd9Sstevel@tonic-gate 		if (putfilter(ps->name, ps) == -1) {
4997c478bd9Sstevel@tonic-gate 			if (errno == EBADF)  switch (lp_errno) {
5007c478bd9Sstevel@tonic-gate 			case LP_ETEMPLATE:
5017c478bd9Sstevel@tonic-gate 				LP_ERRMSG (ERROR, E_FL_BADTEMPLATE);
5027c478bd9Sstevel@tonic-gate 				break;
5037c478bd9Sstevel@tonic-gate 			case LP_EKEYWORD:
5047c478bd9Sstevel@tonic-gate 				LP_ERRMSG (ERROR, E_FL_BADKEY);
5057c478bd9Sstevel@tonic-gate 				break;
5067c478bd9Sstevel@tonic-gate 			case LP_EPATTERN:
5077c478bd9Sstevel@tonic-gate 				LP_ERRMSG (ERROR, E_FL_BADPATT);
5087c478bd9Sstevel@tonic-gate 				break;
5097c478bd9Sstevel@tonic-gate 			case LP_EREGEX:
5107c478bd9Sstevel@tonic-gate 			{
5117c478bd9Sstevel@tonic-gate 				char *			why;
5127c478bd9Sstevel@tonic-gate 
5137c478bd9Sstevel@tonic-gate 				extern int		regerrno;
5147c478bd9Sstevel@tonic-gate 
5157c478bd9Sstevel@tonic-gate 
5167c478bd9Sstevel@tonic-gate 				switch (regerrno) {
5177c478bd9Sstevel@tonic-gate 				case 11:
5187c478bd9Sstevel@tonic-gate 					why = "range endpoint too large";
5197c478bd9Sstevel@tonic-gate 					break;
5207c478bd9Sstevel@tonic-gate 				case 16:
5217c478bd9Sstevel@tonic-gate 					why = "bad number";
5227c478bd9Sstevel@tonic-gate 					break;
5237c478bd9Sstevel@tonic-gate 				case 25:
5247c478bd9Sstevel@tonic-gate 					why = "\"\\digit\" out of range";
5257c478bd9Sstevel@tonic-gate 					break;
5267c478bd9Sstevel@tonic-gate 				case 36:
5277c478bd9Sstevel@tonic-gate 					why = "illegal or missing delimiter";
5287c478bd9Sstevel@tonic-gate 					break;
5297c478bd9Sstevel@tonic-gate 				case 41:
5307c478bd9Sstevel@tonic-gate 					why = "no remembered search string";
5317c478bd9Sstevel@tonic-gate 					break;
5327c478bd9Sstevel@tonic-gate 				case 42:
5337c478bd9Sstevel@tonic-gate 					why = "\\(...\\) imbalance";
5347c478bd9Sstevel@tonic-gate 					break;
5357c478bd9Sstevel@tonic-gate 				case 43:
5367c478bd9Sstevel@tonic-gate 					why = "too many \\(";
5377c478bd9Sstevel@tonic-gate 					break;
5387c478bd9Sstevel@tonic-gate 				case 44:
5397c478bd9Sstevel@tonic-gate 					why = "more than 2 numbers given in \\{...\\}";
5407c478bd9Sstevel@tonic-gate 					break;
5417c478bd9Sstevel@tonic-gate 				case 45:
5427c478bd9Sstevel@tonic-gate 					why = "} expected after \\";
5437c478bd9Sstevel@tonic-gate 					break;
5447c478bd9Sstevel@tonic-gate 				case 46:
5457c478bd9Sstevel@tonic-gate 					why = "first number exceeds second in \\{...\\}";
5467c478bd9Sstevel@tonic-gate 					break;
5477c478bd9Sstevel@tonic-gate 				case 49:
5487c478bd9Sstevel@tonic-gate 					why = "[...] imbalance";
5497c478bd9Sstevel@tonic-gate 					break;
5507c478bd9Sstevel@tonic-gate 				case 50:
5517c478bd9Sstevel@tonic-gate 					why = "regular expression overflow";
5527c478bd9Sstevel@tonic-gate 					break;
5537c478bd9Sstevel@tonic-gate 				}
5547c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (ERROR, E_FL_BADREGEX, why);
5557c478bd9Sstevel@tonic-gate 				break;
5567c478bd9Sstevel@tonic-gate 			}
5577c478bd9Sstevel@tonic-gate 			case LP_ERESULT:
5587c478bd9Sstevel@tonic-gate 				LP_ERRMSG (ERROR, E_FL_BADRESULT);
5597c478bd9Sstevel@tonic-gate 				break;
5607c478bd9Sstevel@tonic-gate 			case LP_ENOMEM:
5617c478bd9Sstevel@tonic-gate 				errno = ENOMEM;
5627c478bd9Sstevel@tonic-gate 				same_complaints (FILTERTABLE, TABLE);
5637c478bd9Sstevel@tonic-gate 				break;
5647c478bd9Sstevel@tonic-gate 			} else
5657c478bd9Sstevel@tonic-gate 				same_complaints (FILTERTABLE, TABLE);
5667c478bd9Sstevel@tonic-gate 			ret = 1;
5677c478bd9Sstevel@tonic-gate 			break;
5687c478bd9Sstevel@tonic-gate 		} else
5697c478bd9Sstevel@tonic-gate 			at_least_one = 1;
5707c478bd9Sstevel@tonic-gate 
5717c478bd9Sstevel@tonic-gate 	}
5727c478bd9Sstevel@tonic-gate 
5737c478bd9Sstevel@tonic-gate 	if (at_least_one)
5747c478bd9Sstevel@tonic-gate 		(void)alert_spooler ();
5757c478bd9Sstevel@tonic-gate 
5767c478bd9Sstevel@tonic-gate 	return (ret);
5777c478bd9Sstevel@tonic-gate }
5787c478bd9Sstevel@tonic-gate 
5797c478bd9Sstevel@tonic-gate /**
5807c478bd9Sstevel@tonic-gate  ** reload_filter()
5817c478bd9Sstevel@tonic-gate  **/
5827c478bd9Sstevel@tonic-gate 
reload_filter(filter)5837c478bd9Sstevel@tonic-gate int			reload_filter (filter)
5847c478bd9Sstevel@tonic-gate 	char			*filter;
5857c478bd9Sstevel@tonic-gate {
5867c478bd9Sstevel@tonic-gate 	register FILTER		*pf,
5877c478bd9Sstevel@tonic-gate 				*store,
5887c478bd9Sstevel@tonic-gate 				*ps;
5897c478bd9Sstevel@tonic-gate 
5907c478bd9Sstevel@tonic-gate 	char			*factory_file;
5917c478bd9Sstevel@tonic-gate 
5927c478bd9Sstevel@tonic-gate 	int			ret,
5937c478bd9Sstevel@tonic-gate 				at_least_one;
5947c478bd9Sstevel@tonic-gate 
5957c478bd9Sstevel@tonic-gate 	/*
5967c478bd9Sstevel@tonic-gate 	 * ``Manually'' load the archived filters, so that a call
5977c478bd9Sstevel@tonic-gate 	 * to "getfilter()" will read from them instead of the regular
5987c478bd9Sstevel@tonic-gate 	 * table.
5997c478bd9Sstevel@tonic-gate 	 */
6007c478bd9Sstevel@tonic-gate 	if (
6017c478bd9Sstevel@tonic-gate 		!(factory_file = getfilterfile(FILTERTABLE_I))
6027c478bd9Sstevel@tonic-gate 	     || loadfilters(factory_file) == -1
6037c478bd9Sstevel@tonic-gate 	) {
6047c478bd9Sstevel@tonic-gate 		switch (errno) {
6057c478bd9Sstevel@tonic-gate 		case ENOENT:
6067c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_FL_NOFACTY);
6077c478bd9Sstevel@tonic-gate 			break;
6087c478bd9Sstevel@tonic-gate 		default:
6097c478bd9Sstevel@tonic-gate 			same_complaints (FILTERTABLE_I, TABLE_I);
6107c478bd9Sstevel@tonic-gate 			break;
6117c478bd9Sstevel@tonic-gate 		}
6127c478bd9Sstevel@tonic-gate 		return (1);
6137c478bd9Sstevel@tonic-gate 	}
6147c478bd9Sstevel@tonic-gate 
6157c478bd9Sstevel@tonic-gate 	if (STREQU(NAME_ALL, filter)) {
6167c478bd9Sstevel@tonic-gate 
6177c478bd9Sstevel@tonic-gate 		store = (FILTER *)malloc((nfilters + 1) * sizeof(FILTER));
6187c478bd9Sstevel@tonic-gate 		if (!store) {
6197c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_LP_MALLOC);
6207c478bd9Sstevel@tonic-gate 			return (1);
6217c478bd9Sstevel@tonic-gate 		}
622*55fea89dSDan Cross 
6237c478bd9Sstevel@tonic-gate 		for (ps = store; (pf = getfilter(filter)); )
6247c478bd9Sstevel@tonic-gate 			*ps++ = *pf;
6257c478bd9Sstevel@tonic-gate 		ps->name = 0;
6267c478bd9Sstevel@tonic-gate 
6277c478bd9Sstevel@tonic-gate 		switch (errno) {
6287c478bd9Sstevel@tonic-gate 		case ENOENT:
6297c478bd9Sstevel@tonic-gate 			if (ps - store != nfilters) {
6307c478bd9Sstevel@tonic-gate 				LP_ERRMSG1 (
6317c478bd9Sstevel@tonic-gate 					ERROR,
6327c478bd9Sstevel@tonic-gate 					E_FL_STRANGE,
6337c478bd9Sstevel@tonic-gate 					getfilterfile(FILTERTABLE_I)
6347c478bd9Sstevel@tonic-gate 				);
6357c478bd9Sstevel@tonic-gate 				return (1);
6367c478bd9Sstevel@tonic-gate 			}
6377c478bd9Sstevel@tonic-gate 			break;
6387c478bd9Sstevel@tonic-gate 		default:
6397c478bd9Sstevel@tonic-gate 			same_complaints (FILTERTABLE_I, TABLE_I);
6407c478bd9Sstevel@tonic-gate 			return (1);
6417c478bd9Sstevel@tonic-gate 		}
6427c478bd9Sstevel@tonic-gate 
6437c478bd9Sstevel@tonic-gate 	} else {
6447c478bd9Sstevel@tonic-gate 
6457c478bd9Sstevel@tonic-gate 		store = (FILTER *)malloc(2 * sizeof(FILTER));
6467c478bd9Sstevel@tonic-gate 		if (!store) {
6477c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_LP_MALLOC);
6487c478bd9Sstevel@tonic-gate 			return (1);
6497c478bd9Sstevel@tonic-gate 		}
650*55fea89dSDan Cross 
6517c478bd9Sstevel@tonic-gate 		if (!(pf = getfilter(filter))) switch (errno) {
6527c478bd9Sstevel@tonic-gate 		case ENOENT:
6537c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_FL_FACTYNM);
6547c478bd9Sstevel@tonic-gate 			return (1);
6557c478bd9Sstevel@tonic-gate 		default:
6567c478bd9Sstevel@tonic-gate 			same_complaints (FILTERTABLE_I, TABLE_I);
6577c478bd9Sstevel@tonic-gate 			return (1);
6587c478bd9Sstevel@tonic-gate 		}
6597c478bd9Sstevel@tonic-gate 
6607c478bd9Sstevel@tonic-gate 		store[0] = *pf;
6617c478bd9Sstevel@tonic-gate 		store[1].name = 0;
662*55fea89dSDan Cross 
6637c478bd9Sstevel@tonic-gate 	}
6647c478bd9Sstevel@tonic-gate 
6657c478bd9Sstevel@tonic-gate 	/*
6667c478bd9Sstevel@tonic-gate 	 * Having stored the archived filter(s) in our own area, clear
6677c478bd9Sstevel@tonic-gate 	 * the currently loaded table so that the subsequent calls to
6687c478bd9Sstevel@tonic-gate 	 * "putfilter()" will read in the regular table.
6697c478bd9Sstevel@tonic-gate 	 */
6707c478bd9Sstevel@tonic-gate 	trash_filters ();
6717c478bd9Sstevel@tonic-gate 
6727c478bd9Sstevel@tonic-gate 	at_least_one = ret = 0;
6737c478bd9Sstevel@tonic-gate 	for (ps = store; ps->name; ps++)
6747c478bd9Sstevel@tonic-gate 		if (putfilter(ps->name, ps) == -1) {
6757c478bd9Sstevel@tonic-gate 			same_complaints (FILTERTABLE, TABLE);
6767c478bd9Sstevel@tonic-gate 			ret = 1;
6777c478bd9Sstevel@tonic-gate 			break;
6787c478bd9Sstevel@tonic-gate 		} else
6797c478bd9Sstevel@tonic-gate 			at_least_one = 1;
6807c478bd9Sstevel@tonic-gate 
6817c478bd9Sstevel@tonic-gate 	if (at_least_one)
6827c478bd9Sstevel@tonic-gate 		(void)alert_spooler ();
6837c478bd9Sstevel@tonic-gate 
6847c478bd9Sstevel@tonic-gate 	return (ret);
6857c478bd9Sstevel@tonic-gate }
6867c478bd9Sstevel@tonic-gate 
6877c478bd9Sstevel@tonic-gate /**
6887c478bd9Sstevel@tonic-gate  ** delete_filter()
6897c478bd9Sstevel@tonic-gate  **/
6907c478bd9Sstevel@tonic-gate 
delete_filter(filter)6917c478bd9Sstevel@tonic-gate int			delete_filter (filter)
6927c478bd9Sstevel@tonic-gate 	char			*filter;
6937c478bd9Sstevel@tonic-gate {
6947c478bd9Sstevel@tonic-gate 	if (delfilter(filter) == -1) switch (errno) {
6957c478bd9Sstevel@tonic-gate 	case ENOENT:
6967c478bd9Sstevel@tonic-gate 		LP_ERRMSG1 (ERROR, E_FL_UNKFILT, filter);
6977c478bd9Sstevel@tonic-gate 		return (1);
6987c478bd9Sstevel@tonic-gate 	default:
6997c478bd9Sstevel@tonic-gate 		same_complaints (FILTERTABLE, TABLE);
7007c478bd9Sstevel@tonic-gate 		return (1);
7017c478bd9Sstevel@tonic-gate 	}
7027c478bd9Sstevel@tonic-gate 
7037c478bd9Sstevel@tonic-gate 	(void)alert_spooler ();
7047c478bd9Sstevel@tonic-gate 
7057c478bd9Sstevel@tonic-gate 	return (0);
7067c478bd9Sstevel@tonic-gate }
7077c478bd9Sstevel@tonic-gate 
7087c478bd9Sstevel@tonic-gate /**
7097c478bd9Sstevel@tonic-gate  ** list_filter()
7107c478bd9Sstevel@tonic-gate  **/
7117c478bd9Sstevel@tonic-gate 
7127c478bd9Sstevel@tonic-gate static void		_list_filter();
7137c478bd9Sstevel@tonic-gate 
list_filter(filter)7147c478bd9Sstevel@tonic-gate int			list_filter (filter)
7157c478bd9Sstevel@tonic-gate 	char			*filter;
7167c478bd9Sstevel@tonic-gate {
7177c478bd9Sstevel@tonic-gate 	register FILTER		*pf;
7187c478bd9Sstevel@tonic-gate 
7197c478bd9Sstevel@tonic-gate 	char			*nl;
7207c478bd9Sstevel@tonic-gate 
7217c478bd9Sstevel@tonic-gate 	if (STREQU(NAME_ALL, filter)) {
7227c478bd9Sstevel@tonic-gate 
7237c478bd9Sstevel@tonic-gate 		nl = "";
7247c478bd9Sstevel@tonic-gate 		while ((pf = getfilter(filter))) {
7257c478bd9Sstevel@tonic-gate 			printf (gettext("%s(Filter \"%s\")\n"), nl, pf->name);
7267c478bd9Sstevel@tonic-gate 			_list_filter (pf);
7277c478bd9Sstevel@tonic-gate 			nl = "\n";
7287c478bd9Sstevel@tonic-gate 		}
7297c478bd9Sstevel@tonic-gate 
7307c478bd9Sstevel@tonic-gate 		switch (errno) {
7317c478bd9Sstevel@tonic-gate 		case ENOENT:
7327c478bd9Sstevel@tonic-gate 			return (0);
7337c478bd9Sstevel@tonic-gate 		default:
7347c478bd9Sstevel@tonic-gate 			same_complaints (FILTERTABLE, TABLE);
7357c478bd9Sstevel@tonic-gate 			return (1);
7367c478bd9Sstevel@tonic-gate 		}
7377c478bd9Sstevel@tonic-gate 
7387c478bd9Sstevel@tonic-gate 	} else {
7397c478bd9Sstevel@tonic-gate 
7407c478bd9Sstevel@tonic-gate 		if ((pf = getfilter(filter))) {
7417c478bd9Sstevel@tonic-gate 			_list_filter (pf);
7427c478bd9Sstevel@tonic-gate 			return (0);
7437c478bd9Sstevel@tonic-gate 		}
7447c478bd9Sstevel@tonic-gate 
7457c478bd9Sstevel@tonic-gate 		switch (errno) {
7467c478bd9Sstevel@tonic-gate 		case ENOENT:
7477c478bd9Sstevel@tonic-gate 			LP_ERRMSG1 (ERROR, E_FL_UNKFILT, filter);
7487c478bd9Sstevel@tonic-gate 			return (1);
7497c478bd9Sstevel@tonic-gate 		default:
7507c478bd9Sstevel@tonic-gate 			same_complaints (FILTERTABLE, TABLE);
7517c478bd9Sstevel@tonic-gate 			return (1);
7527c478bd9Sstevel@tonic-gate 		}
7537c478bd9Sstevel@tonic-gate 
7547c478bd9Sstevel@tonic-gate 	}
7557c478bd9Sstevel@tonic-gate }
7567c478bd9Sstevel@tonic-gate 
_list_filter(pf)7577c478bd9Sstevel@tonic-gate static void		_list_filter (pf)
7587c478bd9Sstevel@tonic-gate 	register FILTER		*pf;
7597c478bd9Sstevel@tonic-gate {
7607c478bd9Sstevel@tonic-gate 	register char		**pp,
7617c478bd9Sstevel@tonic-gate 				*sep;
7627c478bd9Sstevel@tonic-gate 
7637c478bd9Sstevel@tonic-gate 	register int		fld;
7647c478bd9Sstevel@tonic-gate 
7657c478bd9Sstevel@tonic-gate 	char *			head;
7667c478bd9Sstevel@tonic-gate 
7677c478bd9Sstevel@tonic-gate 
7687c478bd9Sstevel@tonic-gate 	for (fld = 0; fld < FL_MAX_P; fld++) switch (fld) {
7697c478bd9Sstevel@tonic-gate 	case FL_IGN_P:
7707c478bd9Sstevel@tonic-gate 	case FL_NAME_P:
7717c478bd9Sstevel@tonic-gate 		break;
7727c478bd9Sstevel@tonic-gate 	case FL_CMD_P:
7737c478bd9Sstevel@tonic-gate 		printf (
7747c478bd9Sstevel@tonic-gate 			"%s %s\n",
7757c478bd9Sstevel@tonic-gate 			headings[fld].v,
7767c478bd9Sstevel@tonic-gate 			(pf->command? pf->command : "")
7777c478bd9Sstevel@tonic-gate 		);
7787c478bd9Sstevel@tonic-gate 		break;
7797c478bd9Sstevel@tonic-gate 	case FL_TYPE_P:
7807c478bd9Sstevel@tonic-gate 		printf (
7817c478bd9Sstevel@tonic-gate 			"%s %s\n",
7827c478bd9Sstevel@tonic-gate 			headings[fld].v,
7837c478bd9Sstevel@tonic-gate 			(pf->type == fl_fast? FL_FAST : FL_SLOW)
7847c478bd9Sstevel@tonic-gate 		);
7857c478bd9Sstevel@tonic-gate 		break;
7867c478bd9Sstevel@tonic-gate 	case FL_PTYPS_P:
7877c478bd9Sstevel@tonic-gate 		pp = pf->printer_types;
7887c478bd9Sstevel@tonic-gate 		goto Lists;
7897c478bd9Sstevel@tonic-gate 	case FL_ITYPS_P:
7907c478bd9Sstevel@tonic-gate 		pp = pf->input_types;
7917c478bd9Sstevel@tonic-gate 		goto Lists;
7927c478bd9Sstevel@tonic-gate 	case FL_OTYPS_P:
7937c478bd9Sstevel@tonic-gate 		pp = pf->output_types;
7947c478bd9Sstevel@tonic-gate 		goto Lists;
7957c478bd9Sstevel@tonic-gate 	case FL_PRTRS_P:
7967c478bd9Sstevel@tonic-gate 		pp = pf->printers;
7977c478bd9Sstevel@tonic-gate Lists:		printlist_qsep = 1;
7987c478bd9Sstevel@tonic-gate 		printlist_setup ("", "", LP_SEP, "");
7997c478bd9Sstevel@tonic-gate 		printf ("%s ", headings[fld].v);
8007c478bd9Sstevel@tonic-gate 		printlist (stdout, pp);
8017c478bd9Sstevel@tonic-gate 		printf ("\n");
8027c478bd9Sstevel@tonic-gate 		break;
8037c478bd9Sstevel@tonic-gate 	case FL_TMPS_P:
8047c478bd9Sstevel@tonic-gate 		head = makestr(headings[fld].v, " ", (char *)0);
8057c478bd9Sstevel@tonic-gate 		printlist_qsep = 1;
8067c478bd9Sstevel@tonic-gate 		printlist_setup (head, "", "\n", "\n");
8077c478bd9Sstevel@tonic-gate 		printlist (stdout, pf->templates);
8087c478bd9Sstevel@tonic-gate 		break;
8097c478bd9Sstevel@tonic-gate 	}
8107c478bd9Sstevel@tonic-gate 
8117c478bd9Sstevel@tonic-gate 	return;
8127c478bd9Sstevel@tonic-gate }
8137c478bd9Sstevel@tonic-gate 
8147c478bd9Sstevel@tonic-gate /**
8157c478bd9Sstevel@tonic-gate  ** opt() - GENERATE OPTION FROM FUNCTION NAME
8167c478bd9Sstevel@tonic-gate  **/
8177c478bd9Sstevel@tonic-gate 
8187c478bd9Sstevel@tonic-gate static char		*opt (fnc)
8197c478bd9Sstevel@tonic-gate 	int			(*fnc)();
8207c478bd9Sstevel@tonic-gate {
8217c478bd9Sstevel@tonic-gate 	if (fnc == add_filter)
8227c478bd9Sstevel@tonic-gate 		return ("-F");
8237c478bd9Sstevel@tonic-gate 	else if (fnc == reload_filter)
8247c478bd9Sstevel@tonic-gate 		return ("-i");
8257c478bd9Sstevel@tonic-gate 	else if (fnc == list_filter)
8267c478bd9Sstevel@tonic-gate 		return ("-l");
8277c478bd9Sstevel@tonic-gate 	else if (fnc == delete_filter)
8287c478bd9Sstevel@tonic-gate 		return ("-x");
8297c478bd9Sstevel@tonic-gate 	else
8307c478bd9Sstevel@tonic-gate 		return ("-?");
8317c478bd9Sstevel@tonic-gate }
8327c478bd9Sstevel@tonic-gate 
8337c478bd9Sstevel@tonic-gate /**
8347c478bd9Sstevel@tonic-gate  ** alert_spooler() - TELL SPOOLER TO LOAD FILTER TABLE
8357c478bd9Sstevel@tonic-gate  **/
8367c478bd9Sstevel@tonic-gate 
alert_spooler()8377c478bd9Sstevel@tonic-gate static void		alert_spooler ()
8387c478bd9Sstevel@tonic-gate {
8397c478bd9Sstevel@tonic-gate 	char			msgbuf[MSGMAX];
8407c478bd9Sstevel@tonic-gate 
8417c478bd9Sstevel@tonic-gate 	int			mtype;
8427c478bd9Sstevel@tonic-gate 
8437c478bd9Sstevel@tonic-gate 	short			status;
8447c478bd9Sstevel@tonic-gate 
8457c478bd9Sstevel@tonic-gate 	/*
8467c478bd9Sstevel@tonic-gate 	 * If the attempt to open a message queue to the
8477c478bd9Sstevel@tonic-gate 	 * Spooler fails, assume it isn't running and just
8487c478bd9Sstevel@tonic-gate 	 * return--don't say anything, `cause the user may
8497c478bd9Sstevel@tonic-gate 	 * know. Any other failure deserves an error message.
8507c478bd9Sstevel@tonic-gate 	 */
8517c478bd9Sstevel@tonic-gate 
8527c478bd9Sstevel@tonic-gate 	if (mopen() == -1)
8537c478bd9Sstevel@tonic-gate 		return;
8547c478bd9Sstevel@tonic-gate 
8557c478bd9Sstevel@tonic-gate 	(void)putmessage (msgbuf, S_LOAD_FILTER_TABLE);
8567c478bd9Sstevel@tonic-gate 
8577c478bd9Sstevel@tonic-gate 	if (msend(msgbuf) == -1)
8587c478bd9Sstevel@tonic-gate 		goto Error;
8597c478bd9Sstevel@tonic-gate 	if (mrecv(msgbuf, MSGMAX) == -1)
8607c478bd9Sstevel@tonic-gate 		goto Error;
8617c478bd9Sstevel@tonic-gate 
8627c478bd9Sstevel@tonic-gate 	mtype = getmessage(msgbuf, R_LOAD_FILTER_TABLE, &status);
8637c478bd9Sstevel@tonic-gate 	if (mtype != R_LOAD_FILTER_TABLE) {
8647c478bd9Sstevel@tonic-gate 		LP_ERRMSG1 (ERROR, E_LP_BADREPLY, mtype);
8657c478bd9Sstevel@tonic-gate 		(void)mclose ();
8667c478bd9Sstevel@tonic-gate 		exit (1);
8677c478bd9Sstevel@tonic-gate 	}
8687c478bd9Sstevel@tonic-gate 
8697c478bd9Sstevel@tonic-gate 	if (status == MOK)
8707c478bd9Sstevel@tonic-gate 		goto NoError;
8717c478bd9Sstevel@tonic-gate 
8727c478bd9Sstevel@tonic-gate Error:	LP_ERRMSG (ERROR, E_FL_NOSPLOAD);
8737c478bd9Sstevel@tonic-gate 
8747c478bd9Sstevel@tonic-gate NoError:(void)mclose ();
8757c478bd9Sstevel@tonic-gate 	return;
8767c478bd9Sstevel@tonic-gate 
8777c478bd9Sstevel@tonic-gate }
8787c478bd9Sstevel@tonic-gate 
8797c478bd9Sstevel@tonic-gate /**
8807c478bd9Sstevel@tonic-gate  ** same_complaints() - PRINT COMMON ERROR MESSAGES
8817c478bd9Sstevel@tonic-gate  **/
8827c478bd9Sstevel@tonic-gate 
same_complaints(table,type)8837c478bd9Sstevel@tonic-gate static void		same_complaints (table, type)
8847c478bd9Sstevel@tonic-gate 	char			*table;
8857c478bd9Sstevel@tonic-gate 	int			type;
8867c478bd9Sstevel@tonic-gate {
8877c478bd9Sstevel@tonic-gate 	switch (errno) {
8887c478bd9Sstevel@tonic-gate 	case EACCES:
8897c478bd9Sstevel@tonic-gate 		if (type == TABLE)
8907c478bd9Sstevel@tonic-gate 			LP_ERRMSG1 (
8917c478bd9Sstevel@tonic-gate 				ERROR,
8927c478bd9Sstevel@tonic-gate 				E_FL_ACCESS,
8937c478bd9Sstevel@tonic-gate 				getfilterfile(table)
8947c478bd9Sstevel@tonic-gate 			);
8957c478bd9Sstevel@tonic-gate 		else
8967c478bd9Sstevel@tonic-gate 			LP_ERRMSG1 (
8977c478bd9Sstevel@tonic-gate 				ERROR,
8987c478bd9Sstevel@tonic-gate 				E_FL_ACCESSI,
8997c478bd9Sstevel@tonic-gate 				getfilterfile(table)
9007c478bd9Sstevel@tonic-gate 			);
9017c478bd9Sstevel@tonic-gate 		break;
9027c478bd9Sstevel@tonic-gate 	case EAGAIN:
9037c478bd9Sstevel@tonic-gate 	case EDEADLK:
9047c478bd9Sstevel@tonic-gate 		LP_ERRMSG1 (ERROR, E_LP_AGAIN, getfilterfile(table));
9057c478bd9Sstevel@tonic-gate 		break;
9067c478bd9Sstevel@tonic-gate 	default:
9077c478bd9Sstevel@tonic-gate 		LP_ERRMSG2 (
9087c478bd9Sstevel@tonic-gate 			ERROR,
9097c478bd9Sstevel@tonic-gate 			E_FL_UNKNOWN,
9107c478bd9Sstevel@tonic-gate 			getfilterfile(table),
911ace1a5f1Sdp 			strerror(errno)
9127c478bd9Sstevel@tonic-gate 		);
9137c478bd9Sstevel@tonic-gate 		break;
9147c478bd9Sstevel@tonic-gate 	}
9157c478bd9Sstevel@tonic-gate 	return;
9167c478bd9Sstevel@tonic-gate }
917