1248aee62SJacques Vidrine %{ 2248aee62SJacques Vidrine /* $NetBSD: nsparser.y,v 1.3 1999/01/25 00:16:18 lukem Exp $ */ 3248aee62SJacques Vidrine 4248aee62SJacques Vidrine /*- 5248aee62SJacques Vidrine * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. 6248aee62SJacques Vidrine * All rights reserved. 7248aee62SJacques Vidrine * 8248aee62SJacques Vidrine * This code is derived from software contributed to The NetBSD Foundation 9248aee62SJacques Vidrine * by Luke Mewburn. 10248aee62SJacques Vidrine * 11248aee62SJacques Vidrine * Redistribution and use in source and binary forms, with or without 12248aee62SJacques Vidrine * modification, are permitted provided that the following conditions 13248aee62SJacques Vidrine * are met: 14248aee62SJacques Vidrine * 1. Redistributions of source code must retain the above copyright 15248aee62SJacques Vidrine * notice, this list of conditions and the following disclaimer. 16248aee62SJacques Vidrine * 2. Redistributions in binary form must reproduce the above copyright 17248aee62SJacques Vidrine * notice, this list of conditions and the following disclaimer in the 18248aee62SJacques Vidrine * documentation and/or other materials provided with the distribution. 19248aee62SJacques Vidrine * 3. All advertising materials mentioning features or use of this software 20248aee62SJacques Vidrine * must display the following acknowledgement: 21248aee62SJacques Vidrine * This product includes software developed by the NetBSD 22248aee62SJacques Vidrine * Foundation, Inc. and its contributors. 23248aee62SJacques Vidrine * 4. Neither the name of The NetBSD Foundation nor the names of its 24248aee62SJacques Vidrine * contributors may be used to endorse or promote products derived 25248aee62SJacques Vidrine * from this software without specific prior written permission. 26248aee62SJacques Vidrine * 27248aee62SJacques Vidrine * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 28248aee62SJacques Vidrine * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 29248aee62SJacques Vidrine * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30248aee62SJacques Vidrine * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 31248aee62SJacques Vidrine * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 32248aee62SJacques Vidrine * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 33248aee62SJacques Vidrine * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34248aee62SJacques Vidrine * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 35248aee62SJacques Vidrine * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 36248aee62SJacques Vidrine * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37248aee62SJacques Vidrine * POSSIBILITY OF SUCH DAMAGE. 38248aee62SJacques Vidrine */ 39248aee62SJacques Vidrine 40248aee62SJacques Vidrine #include <sys/cdefs.h> 41248aee62SJacques Vidrine #if defined(LIBC_SCCS) && !defined(lint) 42248aee62SJacques Vidrine static char *rcsid = 43248aee62SJacques Vidrine "$FreeBSD$"; 44248aee62SJacques Vidrine #endif /* LIBC_SCCS and not lint */ 45248aee62SJacques Vidrine 46248aee62SJacques Vidrine #include <err.h> 47248aee62SJacques Vidrine #define _NS_PRIVATE 48248aee62SJacques Vidrine #include <nsswitch.h> 49248aee62SJacques Vidrine #include <stdio.h> 50248aee62SJacques Vidrine #include <string.h> 51248aee62SJacques Vidrine 52248aee62SJacques Vidrine 53248aee62SJacques Vidrine static void _nsaddsrctomap __P((const char *)); 54248aee62SJacques Vidrine 55248aee62SJacques Vidrine static ns_dbt curdbt; 56248aee62SJacques Vidrine static ns_src cursrc; 57248aee62SJacques Vidrine %} 58248aee62SJacques Vidrine 59248aee62SJacques Vidrine %union { 60248aee62SJacques Vidrine char *str; 61248aee62SJacques Vidrine int mapval; 62248aee62SJacques Vidrine } 63248aee62SJacques Vidrine 64248aee62SJacques Vidrine %token NL 65248aee62SJacques Vidrine %token SUCCESS UNAVAIL NOTFOUND TRYAGAIN 66248aee62SJacques Vidrine %token RETURN CONTINUE 67248aee62SJacques Vidrine %token <str> STRING 68248aee62SJacques Vidrine 69248aee62SJacques Vidrine %type <mapval> Status Action 70248aee62SJacques Vidrine 71248aee62SJacques Vidrine %% 72248aee62SJacques Vidrine 73248aee62SJacques Vidrine File 74248aee62SJacques Vidrine : /* empty */ 75248aee62SJacques Vidrine | Lines 76248aee62SJacques Vidrine ; 77248aee62SJacques Vidrine 78248aee62SJacques Vidrine Lines 79248aee62SJacques Vidrine : Entry 80248aee62SJacques Vidrine | Lines Entry 81248aee62SJacques Vidrine ; 82248aee62SJacques Vidrine 83248aee62SJacques Vidrine Entry 84248aee62SJacques Vidrine : NL 85248aee62SJacques Vidrine | Database ':' NL 86248aee62SJacques Vidrine | Database ':' Srclist NL 87248aee62SJacques Vidrine { 88248aee62SJacques Vidrine _nsdbtput(&curdbt); 89248aee62SJacques Vidrine } 9070982dcaSBill Fenner | error NL 9170982dcaSBill Fenner { 9270982dcaSBill Fenner yyerrok; 9370982dcaSBill Fenner } 94248aee62SJacques Vidrine ; 95248aee62SJacques Vidrine 96248aee62SJacques Vidrine Database 97248aee62SJacques Vidrine : STRING 98248aee62SJacques Vidrine { 99248aee62SJacques Vidrine curdbt.name = yylval.str; 100248aee62SJacques Vidrine curdbt.srclist = NULL; 101248aee62SJacques Vidrine curdbt.srclistsize = 0; 102248aee62SJacques Vidrine } 103248aee62SJacques Vidrine ; 104248aee62SJacques Vidrine 105248aee62SJacques Vidrine Srclist 106248aee62SJacques Vidrine : Item 107248aee62SJacques Vidrine | Srclist Item 108248aee62SJacques Vidrine ; 109248aee62SJacques Vidrine 110248aee62SJacques Vidrine Item 111248aee62SJacques Vidrine : STRING 112248aee62SJacques Vidrine { 113248aee62SJacques Vidrine cursrc.flags = NS_SUCCESS; 114248aee62SJacques Vidrine _nsaddsrctomap($1); 115248aee62SJacques Vidrine } 116248aee62SJacques Vidrine | STRING '[' { cursrc.flags = NS_SUCCESS; } Criteria ']' 117248aee62SJacques Vidrine { 118248aee62SJacques Vidrine _nsaddsrctomap($1); 119248aee62SJacques Vidrine } 120248aee62SJacques Vidrine ; 121248aee62SJacques Vidrine 122248aee62SJacques Vidrine Criteria 123248aee62SJacques Vidrine : Criterion 124248aee62SJacques Vidrine | Criteria Criterion 125248aee62SJacques Vidrine ; 126248aee62SJacques Vidrine 127248aee62SJacques Vidrine Criterion 128248aee62SJacques Vidrine : Status '=' Action 129248aee62SJacques Vidrine { 130248aee62SJacques Vidrine if ($3) /* if action == RETURN set RETURN bit */ 131248aee62SJacques Vidrine cursrc.flags |= $1; 132248aee62SJacques Vidrine else /* else unset it */ 133248aee62SJacques Vidrine cursrc.flags &= ~$1; 134248aee62SJacques Vidrine } 135248aee62SJacques Vidrine ; 136248aee62SJacques Vidrine 137248aee62SJacques Vidrine Status 138248aee62SJacques Vidrine : SUCCESS { $$ = NS_SUCCESS; } 139248aee62SJacques Vidrine | UNAVAIL { $$ = NS_UNAVAIL; } 140248aee62SJacques Vidrine | NOTFOUND { $$ = NS_NOTFOUND; } 141248aee62SJacques Vidrine | TRYAGAIN { $$ = NS_TRYAGAIN; } 142248aee62SJacques Vidrine ; 143248aee62SJacques Vidrine 144248aee62SJacques Vidrine Action 145248aee62SJacques Vidrine : RETURN { $$ = 1L; } 146248aee62SJacques Vidrine | CONTINUE { $$ = 0L; } 147248aee62SJacques Vidrine ; 148248aee62SJacques Vidrine 149248aee62SJacques Vidrine %% 150248aee62SJacques Vidrine 151248aee62SJacques Vidrine static void 152248aee62SJacques Vidrine _nsaddsrctomap(elem) 153248aee62SJacques Vidrine const char *elem; 154248aee62SJacques Vidrine { 155248aee62SJacques Vidrine int i, lineno; 156248aee62SJacques Vidrine extern int _nsyylineno; 157248aee62SJacques Vidrine extern char * _nsyytext; 158248aee62SJacques Vidrine 159248aee62SJacques Vidrine lineno = _nsyylineno - (*_nsyytext == '\n' ? 1 : 0); 160248aee62SJacques Vidrine if (curdbt.srclistsize > 0) { 161248aee62SJacques Vidrine if ((strcasecmp(elem, NSSRC_COMPAT) == 0) || 162248aee62SJacques Vidrine (strcasecmp(curdbt.srclist[0].name, NSSRC_COMPAT) == 0)) { 163248aee62SJacques Vidrine /* XXX: syslog the following */ 164248aee62SJacques Vidrine warnx("%s line %d: 'compat' used with other sources", 165248aee62SJacques Vidrine _PATH_NS_CONF, lineno); 166248aee62SJacques Vidrine return; 167248aee62SJacques Vidrine } 168248aee62SJacques Vidrine } 169248aee62SJacques Vidrine for (i = 0; i < curdbt.srclistsize; i++) { 170248aee62SJacques Vidrine if (strcasecmp(curdbt.srclist[i].name, elem) == 0) { 171248aee62SJacques Vidrine /* XXX: syslog the following */ 172248aee62SJacques Vidrine warnx("%s line %d: duplicate source '%s'", 173248aee62SJacques Vidrine _PATH_NS_CONF, lineno, elem); 174248aee62SJacques Vidrine return; 175248aee62SJacques Vidrine } 176248aee62SJacques Vidrine } 177248aee62SJacques Vidrine cursrc.name = elem; 178248aee62SJacques Vidrine _nsdbtaddsrc(&curdbt, &cursrc); 179248aee62SJacques Vidrine } 180