nsparser.y revision 1.2
1%{ 2/* $NetBSD: nsparser.y,v 1.2 1999/01/15 12:53:25 lukem Exp $ */ 3 4/*- 5 * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to The NetBSD Foundation 9 * by Luke Mewburn. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. All advertising materials mentioning features or use of this software 20 * must display the following acknowledgement: 21 * This product includes software developed by the NetBSD 22 * Foundation, Inc. and its contributors. 23 * 4. Neither the name of The NetBSD Foundation nor the names of its 24 * contributors may be used to endorse or promote products derived 25 * from this software without specific prior written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 * POSSIBILITY OF SUCH DAMAGE. 38 */ 39 40#define _NS_PRIVATE 41#include <err.h> 42#include <nsswitch.h> 43#include <stdio.h> 44#include <string.h> 45 46 47static void _nsaddsrctomap __P((const char *)); 48 49static ns_dbt curdbt; 50static ns_src cursrc; 51%} 52 53%union { 54 char *str; 55 int mapval; 56} 57 58%token NL 59%token SUCCESS UNAVAIL NOTFOUND TRYAGAIN 60%token RETURN CONTINUE 61%token <str> STRING 62 63%type <mapval> Status Action 64 65%% 66 67File 68 : /* empty */ 69 | Lines 70 ; 71 72Lines 73 : Entry 74 | Lines Entry 75 ; 76 77Entry 78 : NL 79 | Database ':' NL 80 | Database ':' Srclist NL 81 { 82 _nsdbtput(&curdbt); 83 } 84 ; 85 86Database 87 : STRING 88 { 89 curdbt.name = yylval.str; 90 curdbt.srclist = NULL; 91 curdbt.srclistsize = 0; 92 } 93 ; 94 95Srclist 96 : Item 97 | Srclist Item 98 ; 99 100Item 101 : STRING 102 { 103 cursrc.flags = NS_SUCCESS; 104 _nsaddsrctomap($1); 105 } 106 | STRING '[' { cursrc.flags = NS_SUCCESS; } Criteria ']' 107 { 108 _nsaddsrctomap($1); 109 } 110 ; 111 112Criteria 113 : Criterion 114 | Criteria Criterion 115 ; 116 117Criterion 118 : Status '=' Action 119 { 120 if ($3) /* if action == RETURN set RETURN bit */ 121 cursrc.flags |= $1; 122 else /* else unset it */ 123 cursrc.flags &= ~$1; 124 } 125 ; 126 127Status 128 : SUCCESS { $$ = NS_SUCCESS; } 129 | UNAVAIL { $$ = NS_UNAVAIL; } 130 | NOTFOUND { $$ = NS_NOTFOUND; } 131 | TRYAGAIN { $$ = NS_TRYAGAIN; } 132 ; 133 134Action 135 : RETURN { $$ = 1L; } 136 | CONTINUE { $$ = 0L; } 137 ; 138 139%% 140 141static void 142_nsaddsrctomap(elem) 143 const char *elem; 144{ 145 int i, lineno; 146 extern int _nsyylineno; 147 extern char * _nsyytext; 148 149 lineno = _nsyylineno - (*_nsyytext == '\n' ? 1 : 0); 150 if (curdbt.srclistsize > 0) { 151 if ((strcasecmp(elem, NSSRC_COMPAT) == 0) || 152 (strcasecmp(curdbt.srclist[0].name, NSSRC_COMPAT) == 0)) { 153 /* XXX: syslog the following */ 154 warnx("%s line %d: 'compat' used with other sources", 155 _PATH_NS_CONF, lineno); 156 return; 157 } 158 } 159 for (i = 0; i < curdbt.srclistsize; i++) { 160 if (strcasecmp(curdbt.srclist[i].name, elem) == 0) { 161 /* XXX: syslog the following */ 162 warnx("%s line %d: duplicate source '%s'", 163 _PATH_NS_CONF, lineno, elem); 164 return; 165 } 166 } 167 cursrc.name = elem; 168 _nsdbtaddsrc(&curdbt, &cursrc); 169} 170