nsparser.y revision 1.8
11.2Slukem%{
21.8Slukem/*	$NetBSD: nsparser.y,v 1.8 2002/03/19 00:04:09 lukem Exp $	*/
31.2Slukem
41.2Slukem/*-
51.2Slukem * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc.
61.2Slukem * All rights reserved.
71.2Slukem *
81.2Slukem * This code is derived from software contributed to The NetBSD Foundation
91.2Slukem * by Luke Mewburn.
101.2Slukem *
111.2Slukem * Redistribution and use in source and binary forms, with or without
121.2Slukem * modification, are permitted provided that the following conditions
131.2Slukem * are met:
141.2Slukem * 1. Redistributions of source code must retain the above copyright
151.2Slukem *    notice, this list of conditions and the following disclaimer.
161.2Slukem * 2. Redistributions in binary form must reproduce the above copyright
171.2Slukem *    notice, this list of conditions and the following disclaimer in the
181.2Slukem *    documentation and/or other materials provided with the distribution.
191.2Slukem * 3. All advertising materials mentioning features or use of this software
201.2Slukem *    must display the following acknowledgement:
211.2Slukem *        This product includes software developed by the NetBSD
221.2Slukem *        Foundation, Inc. and its contributors.
231.2Slukem * 4. Neither the name of The NetBSD Foundation nor the names of its
241.2Slukem *    contributors may be used to endorse or promote products derived
251.2Slukem *    from this software without specific prior written permission.
261.2Slukem *
271.2Slukem * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
281.2Slukem * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
291.2Slukem * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
301.2Slukem * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
311.2Slukem * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
321.2Slukem * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
331.2Slukem * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
341.2Slukem * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
351.2Slukem * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
361.2Slukem * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
371.2Slukem * POSSIBILITY OF SUCH DAMAGE.
381.2Slukem */
391.2Slukem
401.3Slukem#include <sys/cdefs.h>
411.3Slukem#if defined(LIBC_SCCS) && !defined(lint)
421.8Slukem__RCSID("$NetBSD: nsparser.y,v 1.8 2002/03/19 00:04:09 lukem Exp $");
431.3Slukem#endif /* LIBC_SCCS and not lint */
441.3Slukem
451.4Skleink#include "namespace.h"
461.5Slukem
471.5Slukem#include <assert.h>
481.3Slukem#include <err.h>
491.2Slukem#define _NS_PRIVATE
501.2Slukem#include <nsswitch.h>
511.2Slukem#include <stdio.h>
521.2Slukem#include <string.h>
531.2Slukem
541.2Slukem
551.2Slukemstatic	void	_nsaddsrctomap __P((const char *));
561.2Slukem
571.2Slukemstatic	ns_dbt		curdbt;
581.2Slukemstatic	ns_src		cursrc;
591.6Slukem
601.6Slukemextern char *	_nsyytext;
611.7Schristosextern int _nsyylineno;
621.2Slukem%}
631.2Slukem
641.2Slukem%union {
651.2Slukem	char *str;
661.2Slukem	int   mapval;
671.2Slukem}
681.2Slukem
691.2Slukem%token	NL
701.2Slukem%token	SUCCESS UNAVAIL NOTFOUND TRYAGAIN
711.2Slukem%token	RETURN CONTINUE
721.2Slukem%token	<str> STRING
731.2Slukem
741.2Slukem%type	<mapval> Status Action
751.2Slukem
761.2Slukem%%
771.2Slukem
781.2SlukemFile
791.2Slukem	:	/* empty */
801.2Slukem	| Lines
811.2Slukem	;
821.2Slukem
831.2SlukemLines
841.2Slukem	: Entry
851.2Slukem	| Lines Entry
861.2Slukem	;
871.2Slukem
881.2SlukemEntry
891.2Slukem	: NL
901.2Slukem	| Database ':' NL
911.2Slukem	| Database ':' Srclist NL
921.2Slukem		{
931.6Slukem			int lineno;
941.6Slukem
951.6Slukem			lineno = _nsyylineno - (*_nsyytext == '\n' ? 1 : 0);
961.6Slukem			if (_nsdbtput(&curdbt) == -1)
971.6Slukem					/* XXX: syslog the following */
981.6Slukem				warn("%s line %d: error adding entry",
991.6Slukem				    _PATH_NS_CONF, lineno);
1001.8Slukem		}
1011.8Slukem	| error NL
1021.8Slukem		{
1031.8Slukem			yyerrok;
1041.2Slukem		}
1051.2Slukem	;
1061.2Slukem
1071.2SlukemDatabase
1081.2Slukem	: STRING
1091.2Slukem		{
1101.2Slukem			curdbt.name = yylval.str;
1111.2Slukem			curdbt.srclist = NULL;
1121.2Slukem			curdbt.srclistsize = 0;
1131.2Slukem		}
1141.2Slukem	;
1151.2Slukem
1161.2SlukemSrclist
1171.2Slukem	: Item
1181.2Slukem	| Srclist Item
1191.2Slukem	;
1201.2Slukem
1211.2SlukemItem
1221.2Slukem	: STRING
1231.2Slukem		{
1241.2Slukem			cursrc.flags = NS_SUCCESS;
1251.2Slukem			_nsaddsrctomap($1);
1261.2Slukem		}
1271.2Slukem	| STRING '[' { cursrc.flags = NS_SUCCESS; } Criteria ']'
1281.2Slukem		{
1291.2Slukem			_nsaddsrctomap($1);
1301.2Slukem		}
1311.2Slukem	;
1321.2Slukem
1331.2SlukemCriteria
1341.2Slukem	: Criterion
1351.2Slukem	| Criteria Criterion
1361.2Slukem	;
1371.2Slukem
1381.2SlukemCriterion
1391.2Slukem	: Status '=' Action
1401.2Slukem		{
1411.2Slukem			if ($3)		/* if action == RETURN set RETURN bit */
1421.2Slukem				cursrc.flags |= $1;
1431.2Slukem			else		/* else unset it */
1441.2Slukem				cursrc.flags &= ~$1;
1451.2Slukem		}
1461.2Slukem	;
1471.2Slukem
1481.2SlukemStatus
1491.2Slukem	: SUCCESS	{ $$ = NS_SUCCESS; }
1501.2Slukem	| UNAVAIL	{ $$ = NS_UNAVAIL; }
1511.2Slukem	| NOTFOUND	{ $$ = NS_NOTFOUND; }
1521.2Slukem	| TRYAGAIN	{ $$ = NS_TRYAGAIN; }
1531.2Slukem	;
1541.2Slukem
1551.2SlukemAction
1561.2Slukem	: RETURN	{ $$ = 1L; }
1571.2Slukem	| CONTINUE	{ $$ = 0L; }
1581.2Slukem	;
1591.2Slukem
1601.2Slukem%%
1611.2Slukem
1621.2Slukemstatic void
1631.2Slukem_nsaddsrctomap(elem)
1641.2Slukem	const char *elem;
1651.2Slukem{
1661.2Slukem	int		i, lineno;
1671.5Slukem
1681.5Slukem	_DIAGASSERT(elem != NULL);
1691.2Slukem
1701.2Slukem	lineno = _nsyylineno - (*_nsyytext == '\n' ? 1 : 0);
1711.2Slukem	if (curdbt.srclistsize > 0) {
1721.2Slukem		if ((strcasecmp(elem, NSSRC_COMPAT) == 0) ||
1731.2Slukem		    (strcasecmp(curdbt.srclist[0].name, NSSRC_COMPAT) == 0)) {
1741.2Slukem				/* XXX: syslog the following */
1751.2Slukem			warnx("%s line %d: 'compat' used with other sources",
1761.2Slukem			    _PATH_NS_CONF, lineno);
1771.2Slukem			return;
1781.2Slukem		}
1791.2Slukem	}
1801.2Slukem	for (i = 0; i < curdbt.srclistsize; i++) {
1811.2Slukem		if (strcasecmp(curdbt.srclist[i].name, elem) == 0) {
1821.2Slukem				/* XXX: syslog the following */
1831.2Slukem			warnx("%s line %d: duplicate source '%s'",
1841.2Slukem			    _PATH_NS_CONF, lineno, elem);
1851.2Slukem			return;
1861.2Slukem		}
1871.2Slukem	}
1881.2Slukem	cursrc.name = elem;
1891.6Slukem	if (_nsdbtaddsrc(&curdbt, &cursrc) == -1) {
1901.6Slukem			/* XXX: syslog the following */
1911.6Slukem		warn("%s line %d: error adding '%s'",
1921.6Slukem		    _PATH_NS_CONF, lineno, elem);
1931.6Slukem	}
1941.2Slukem}
195