165532Snectar%{ 265532Snectar/* $NetBSD: nsparser.y,v 1.3 1999/01/25 00:16:18 lukem Exp $ */ 365532Snectar 465532Snectar/*- 565532Snectar * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. 665532Snectar * All rights reserved. 765532Snectar * 865532Snectar * This code is derived from software contributed to The NetBSD Foundation 965532Snectar * by Luke Mewburn. 1065532Snectar * 1165532Snectar * Redistribution and use in source and binary forms, with or without 1265532Snectar * modification, are permitted provided that the following conditions 1365532Snectar * are met: 1465532Snectar * 1. Redistributions of source code must retain the above copyright 1565532Snectar * notice, this list of conditions and the following disclaimer. 1665532Snectar * 2. Redistributions in binary form must reproduce the above copyright 1765532Snectar * notice, this list of conditions and the following disclaimer in the 1865532Snectar * documentation and/or other materials provided with the distribution. 1965532Snectar * 2065532Snectar * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 2165532Snectar * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2265532Snectar * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2365532Snectar * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 2465532Snectar * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2565532Snectar * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2665532Snectar * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2765532Snectar * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2865532Snectar * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2965532Snectar * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3065532Snectar * POSSIBILITY OF SUCH DAMAGE. 3165532Snectar */ 3265532Snectar 3365532Snectar#include <sys/cdefs.h> 34113595Snectar__FBSDID("$FreeBSD$"); 3565532Snectar 36113595Snectar#include "namespace.h" 3765532Snectar#define _NS_PRIVATE 3865532Snectar#include <nsswitch.h> 3965532Snectar#include <stdio.h> 40235767Skevlo#include <stdlib.h> 4165532Snectar#include <string.h> 42113595Snectar#include <syslog.h> 43113595Snectar#include "un-namespace.h" 4465532Snectar 4592905Sobrienstatic void _nsaddsrctomap(const char *); 4665532Snectar 4765532Snectarstatic ns_dbt curdbt; 4865532Snectarstatic ns_src cursrc; 4965532Snectar%} 5065532Snectar 5165532Snectar%union { 5265532Snectar char *str; 5365532Snectar int mapval; 5465532Snectar} 5565532Snectar 5665532Snectar%token NL 5765532Snectar%token SUCCESS UNAVAIL NOTFOUND TRYAGAIN 5865532Snectar%token RETURN CONTINUE 59113595Snectar%token ERRORTOKEN 6065532Snectar%token <str> STRING 6165532Snectar 6265532Snectar%type <mapval> Status Action 6365532Snectar 6465532Snectar%% 6565532Snectar 6665532SnectarFile 6765532Snectar : /* empty */ 6865532Snectar | Lines 6965532Snectar ; 7065532Snectar 7165532SnectarLines 7265532Snectar : Entry 7365532Snectar | Lines Entry 7465532Snectar ; 7565532Snectar 7665532SnectarEntry 7765532Snectar : NL 7865532Snectar | Database ':' NL 79169644Sjon { 80169644Sjon free((char*)curdbt.name); 81169644Sjon } 8265532Snectar | Database ':' Srclist NL 8365532Snectar { 8465532Snectar _nsdbtput(&curdbt); 8565532Snectar } 8686162Sfenner | error NL 8786162Sfenner { 8886162Sfenner yyerrok; 8986162Sfenner } 9065532Snectar ; 9165532Snectar 9265532SnectarDatabase 9365532Snectar : STRING 9465532Snectar { 9565532Snectar curdbt.name = yylval.str; 9665532Snectar curdbt.srclist = NULL; 9765532Snectar curdbt.srclistsize = 0; 9865532Snectar } 9965532Snectar ; 10065532Snectar 10165532SnectarSrclist 10265532Snectar : Item 10365532Snectar | Srclist Item 10465532Snectar ; 10565532Snectar 10665532SnectarItem 10765532Snectar : STRING 10865532Snectar { 109113595Snectar cursrc.flags = NS_TERMINATE; 11065532Snectar _nsaddsrctomap($1); 11165532Snectar } 11265532Snectar | STRING '[' { cursrc.flags = NS_SUCCESS; } Criteria ']' 11365532Snectar { 11465532Snectar _nsaddsrctomap($1); 11565532Snectar } 11665532Snectar ; 11765532Snectar 11865532SnectarCriteria 11965532Snectar : Criterion 12065532Snectar | Criteria Criterion 12165532Snectar ; 12265532Snectar 12365532SnectarCriterion 12465532Snectar : Status '=' Action 12565532Snectar { 126113595Snectar if ($3) /* if action == RETURN set RETURN bit */ 12765532Snectar cursrc.flags |= $1; 128113595Snectar else /* else unset it */ 12965532Snectar cursrc.flags &= ~$1; 13065532Snectar } 13165532Snectar ; 13265532Snectar 13365532SnectarStatus 13465532Snectar : SUCCESS { $$ = NS_SUCCESS; } 13565532Snectar | UNAVAIL { $$ = NS_UNAVAIL; } 13665532Snectar | NOTFOUND { $$ = NS_NOTFOUND; } 13765532Snectar | TRYAGAIN { $$ = NS_TRYAGAIN; } 13865532Snectar ; 13965532Snectar 14065532SnectarAction 141113595Snectar : RETURN { $$ = NS_ACTION_RETURN; } 142113595Snectar | CONTINUE { $$ = NS_ACTION_CONTINUE; } 14365532Snectar ; 14465532Snectar 14565532Snectar%% 14665532Snectar 14765532Snectarstatic void 14865532Snectar_nsaddsrctomap(elem) 14965532Snectar const char *elem; 15065532Snectar{ 15165532Snectar int i, lineno; 15265532Snectar extern int _nsyylineno; 15365532Snectar extern char * _nsyytext; 15465532Snectar 15565532Snectar lineno = _nsyylineno - (*_nsyytext == '\n' ? 1 : 0); 15665532Snectar if (curdbt.srclistsize > 0) { 157158190Sume if (((strcasecmp(elem, NSSRC_COMPAT) == 0) && 158158190Sume (strcasecmp(curdbt.srclist[0].name, NSSRC_CACHE) != 0)) || 15965532Snectar (strcasecmp(curdbt.srclist[0].name, NSSRC_COMPAT) == 0)) { 160113595Snectar syslog(LOG_ERR, 161158190Sume "NSSWITCH(nsparser): %s line %d: 'compat' used with sources, other than 'cache'", 16265532Snectar _PATH_NS_CONF, lineno); 163169644Sjon free((void*)elem); 16465532Snectar return; 16565532Snectar } 16665532Snectar } 16765532Snectar for (i = 0; i < curdbt.srclistsize; i++) { 16865532Snectar if (strcasecmp(curdbt.srclist[i].name, elem) == 0) { 169113595Snectar syslog(LOG_ERR, 170113595Snectar "NSSWITCH(nsparser): %s line %d: duplicate source '%s'", 17165532Snectar _PATH_NS_CONF, lineno, elem); 172169644Sjon free((void*)elem); 17365532Snectar return; 17465532Snectar } 17565532Snectar } 17665532Snectar cursrc.name = elem; 17765532Snectar _nsdbtaddsrc(&curdbt, &cursrc); 17865532Snectar} 179