1248aee62SJacques Vidrine %{ 2248aee62SJacques Vidrine /* $NetBSD: nsparser.y,v 1.3 1999/01/25 00:16:18 lukem Exp $ */ 3248aee62SJacques Vidrine 4248aee62SJacques Vidrine /*- 5*b61a5730SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 6d915a14eSPedro F. Giffuni * 7248aee62SJacques Vidrine * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. 8248aee62SJacques Vidrine * All rights reserved. 9248aee62SJacques Vidrine * 10248aee62SJacques Vidrine * This code is derived from software contributed to The NetBSD Foundation 11248aee62SJacques Vidrine * by Luke Mewburn. 12248aee62SJacques Vidrine * 13248aee62SJacques Vidrine * Redistribution and use in source and binary forms, with or without 14248aee62SJacques Vidrine * modification, are permitted provided that the following conditions 15248aee62SJacques Vidrine * are met: 16248aee62SJacques Vidrine * 1. Redistributions of source code must retain the above copyright 17248aee62SJacques Vidrine * notice, this list of conditions and the following disclaimer. 18248aee62SJacques Vidrine * 2. Redistributions in binary form must reproduce the above copyright 19248aee62SJacques Vidrine * notice, this list of conditions and the following disclaimer in the 20248aee62SJacques Vidrine * documentation and/or other materials provided with the distribution. 21248aee62SJacques Vidrine * 22248aee62SJacques Vidrine * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 23248aee62SJacques Vidrine * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 24248aee62SJacques Vidrine * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25248aee62SJacques Vidrine * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 26248aee62SJacques Vidrine * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27248aee62SJacques Vidrine * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28248aee62SJacques Vidrine * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29248aee62SJacques Vidrine * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30248aee62SJacques Vidrine * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31248aee62SJacques Vidrine * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32248aee62SJacques Vidrine * POSSIBILITY OF SUCH DAMAGE. 33248aee62SJacques Vidrine */ 34248aee62SJacques Vidrine 3546d93063SJacques Vidrine #include "namespace.h" 36248aee62SJacques Vidrine #define _NS_PRIVATE 37248aee62SJacques Vidrine #include <nsswitch.h> 38248aee62SJacques Vidrine #include <stdio.h> 39d52995b6SKevin Lo #include <stdlib.h> 40248aee62SJacques Vidrine #include <string.h> 4146d93063SJacques Vidrine #include <syslog.h> 4246d93063SJacques Vidrine #include "un-namespace.h" 43248aee62SJacques Vidrine 44c05ac53bSDavid E. O'Brien static void _nsaddsrctomap(const char *); 45248aee62SJacques Vidrine 46248aee62SJacques Vidrine static ns_dbt curdbt; 47248aee62SJacques Vidrine static ns_src cursrc; 48248aee62SJacques Vidrine %} 49248aee62SJacques Vidrine 50248aee62SJacques Vidrine %union { 51248aee62SJacques Vidrine char *str; 52248aee62SJacques Vidrine int mapval; 53248aee62SJacques Vidrine } 54248aee62SJacques Vidrine 55248aee62SJacques Vidrine %token NL 56248aee62SJacques Vidrine %token SUCCESS UNAVAIL NOTFOUND TRYAGAIN 57248aee62SJacques Vidrine %token RETURN CONTINUE 5846d93063SJacques Vidrine %token ERRORTOKEN 59248aee62SJacques Vidrine %token <str> STRING 60248aee62SJacques Vidrine 61248aee62SJacques Vidrine %type <mapval> Status Action 62248aee62SJacques Vidrine 63248aee62SJacques Vidrine %% 64248aee62SJacques Vidrine 65248aee62SJacques Vidrine File 66248aee62SJacques Vidrine : /* empty */ 67248aee62SJacques Vidrine | Lines 68248aee62SJacques Vidrine ; 69248aee62SJacques Vidrine 70248aee62SJacques Vidrine Lines 71248aee62SJacques Vidrine : Entry 72248aee62SJacques Vidrine | Lines Entry 73248aee62SJacques Vidrine ; 74248aee62SJacques Vidrine 75248aee62SJacques Vidrine Entry 76248aee62SJacques Vidrine : NL 77248aee62SJacques Vidrine | Database ':' NL 787a800a56SJonathan Chen { 797a800a56SJonathan Chen free((char*)curdbt.name); 807a800a56SJonathan Chen } 81248aee62SJacques Vidrine | Database ':' Srclist NL 82248aee62SJacques Vidrine { 83248aee62SJacques Vidrine _nsdbtput(&curdbt); 84248aee62SJacques Vidrine } 8570982dcaSBill Fenner | error NL 8670982dcaSBill Fenner { 8770982dcaSBill Fenner yyerrok; 8870982dcaSBill Fenner } 89248aee62SJacques Vidrine ; 90248aee62SJacques Vidrine 91248aee62SJacques Vidrine Database 92248aee62SJacques Vidrine : STRING 93248aee62SJacques Vidrine { 94248aee62SJacques Vidrine curdbt.name = yylval.str; 95248aee62SJacques Vidrine curdbt.srclist = NULL; 96248aee62SJacques Vidrine curdbt.srclistsize = 0; 97248aee62SJacques Vidrine } 98248aee62SJacques Vidrine ; 99248aee62SJacques Vidrine 100248aee62SJacques Vidrine Srclist 101248aee62SJacques Vidrine : Item 102248aee62SJacques Vidrine | Srclist Item 103248aee62SJacques Vidrine ; 104248aee62SJacques Vidrine 105248aee62SJacques Vidrine Item 106248aee62SJacques Vidrine : STRING 107248aee62SJacques Vidrine { 10846d93063SJacques Vidrine cursrc.flags = NS_TERMINATE; 109248aee62SJacques Vidrine _nsaddsrctomap($1); 110248aee62SJacques Vidrine } 111248aee62SJacques Vidrine | STRING '[' { cursrc.flags = NS_SUCCESS; } Criteria ']' 112248aee62SJacques Vidrine { 113248aee62SJacques Vidrine _nsaddsrctomap($1); 114248aee62SJacques Vidrine } 115248aee62SJacques Vidrine ; 116248aee62SJacques Vidrine 117248aee62SJacques Vidrine Criteria 118248aee62SJacques Vidrine : Criterion 119248aee62SJacques Vidrine | Criteria Criterion 120248aee62SJacques Vidrine ; 121248aee62SJacques Vidrine 122248aee62SJacques Vidrine Criterion 123248aee62SJacques Vidrine : Status '=' Action 124248aee62SJacques Vidrine { 125248aee62SJacques Vidrine if ($3) /* if action == RETURN set RETURN bit */ 126248aee62SJacques Vidrine cursrc.flags |= $1; 127248aee62SJacques Vidrine else /* else unset it */ 128248aee62SJacques Vidrine cursrc.flags &= ~$1; 129248aee62SJacques Vidrine } 130248aee62SJacques Vidrine ; 131248aee62SJacques Vidrine 132248aee62SJacques Vidrine Status 133248aee62SJacques Vidrine : SUCCESS { $$ = NS_SUCCESS; } 134248aee62SJacques Vidrine | UNAVAIL { $$ = NS_UNAVAIL; } 135248aee62SJacques Vidrine | NOTFOUND { $$ = NS_NOTFOUND; } 136248aee62SJacques Vidrine | TRYAGAIN { $$ = NS_TRYAGAIN; } 137248aee62SJacques Vidrine ; 138248aee62SJacques Vidrine 139248aee62SJacques Vidrine Action 14046d93063SJacques Vidrine : RETURN { $$ = NS_ACTION_RETURN; } 14146d93063SJacques Vidrine | CONTINUE { $$ = NS_ACTION_CONTINUE; } 142248aee62SJacques Vidrine ; 143248aee62SJacques Vidrine 144248aee62SJacques Vidrine %% 145248aee62SJacques Vidrine 146248aee62SJacques Vidrine static void 147626c9d74SCraig Rodrigues _nsaddsrctomap(const char *elem) 148248aee62SJacques Vidrine { 149248aee62SJacques Vidrine int i, lineno; 150248aee62SJacques Vidrine extern int _nsyylineno; 151248aee62SJacques Vidrine extern char * _nsyytext; 152248aee62SJacques Vidrine 153248aee62SJacques Vidrine lineno = _nsyylineno - (*_nsyytext == '\n' ? 1 : 0); 154248aee62SJacques Vidrine if (curdbt.srclistsize > 0) { 155eb59e992SHajimu UMEMOTO if (((strcasecmp(elem, NSSRC_COMPAT) == 0) && 156eb59e992SHajimu UMEMOTO (strcasecmp(curdbt.srclist[0].name, NSSRC_CACHE) != 0)) || 157248aee62SJacques Vidrine (strcasecmp(curdbt.srclist[0].name, NSSRC_COMPAT) == 0)) { 15846d93063SJacques Vidrine syslog(LOG_ERR, 159eb59e992SHajimu UMEMOTO "NSSWITCH(nsparser): %s line %d: 'compat' used with sources, other than 'cache'", 160248aee62SJacques Vidrine _PATH_NS_CONF, lineno); 1617a800a56SJonathan Chen free((void*)elem); 162248aee62SJacques Vidrine return; 163248aee62SJacques Vidrine } 164248aee62SJacques Vidrine } 165248aee62SJacques Vidrine for (i = 0; i < curdbt.srclistsize; i++) { 166248aee62SJacques Vidrine if (strcasecmp(curdbt.srclist[i].name, elem) == 0) { 16746d93063SJacques Vidrine syslog(LOG_ERR, 16846d93063SJacques Vidrine "NSSWITCH(nsparser): %s line %d: duplicate source '%s'", 169248aee62SJacques Vidrine _PATH_NS_CONF, lineno, elem); 1707a800a56SJonathan Chen free((void*)elem); 171248aee62SJacques Vidrine return; 172248aee62SJacques Vidrine } 173248aee62SJacques Vidrine } 174248aee62SJacques Vidrine cursrc.name = elem; 175248aee62SJacques Vidrine _nsdbtaddsrc(&curdbt, &cursrc); 176248aee62SJacques Vidrine } 177