/*****************************************************************
**
** @(#) ncparse.c -- A very simple named.conf parser
**
** Copyright (c) Apr 2005 - Nov 2007, Holger Zuleger HZnet. All rights reserved.
**
** This software is open source.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
**
** Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
**
** Redistributions in binary form must reproduce the above copyright notice,
** this list of conditions and the following disclaimer in the documentation
**
** Neither the name of Holger Zuleger HZnet nor the names of its contributors may
** be used to endorse or promote products derived from this software without
** specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
** TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
** POSSIBILITY OF SUCH DAMAGE.
**
*****************************************************************/
# include <stdio.h>
# include <string.h>
# include <ctype.h>
# include <assert.h>
# include "debug.h"
# include "misc.h"
# include "log.h"
#define extern
# include "ncparse.h"
#undef extern
/* list of "named.conf" keywords we are interested in */
static struct KeyWords {
char *name;
int tok;
} kw[] = {
{ "STRING", TOK_STRING },
{ "include", TOK_INCLUDE },
{ "directory", TOK_DIR },
{ "file", TOK_FILE },
{ "zone", TOK_ZONE },
#if 0 /* we don't need the type keyword; master, slave etc. is sufficient */
{ "type", TOK_TYPE },
#endif
{ "master", TOK_MASTER },
{ "slave", TOK_SLAVE },
{ "stub", TOK_STUB },
{ "hint", TOK_HINT },
{ "forward", TOK_FORWARD },
{ "delegation-only", TOK_DELEGATION },
{ "view", TOK_VIEW },
{ NULL, TOK_UNKNOWN },
};
#ifdef DBG
{
int i;
i = 0;
i++;
}
#endif
{
int i;
i = 0;
i++;
}
{
int lastc;
int c;
char *p;
char *bufend;
*val = '\0';
do {
;
if ( c == '#' ) /* single line comment ? */
{
;
continue;
}
if ( c == EOF )
return EOF;
if ( c == '{' || c == '}' || c == ';' )
continue;
if ( c == '/' ) /* begin of C comment ? */
{
{
lastc = c;
}
else if ( c == '/' ) /* is it a C single line comment ? */
{
;
}
else /* no ! */
continue;
}
if ( c == '\"' )
{
p = val;
*p++ = c;
*p = '\0';
/* if string buffer is too small, eat up rest of string */
while ( c != EOF && c != '\"' )
return TOK_STRING;
}
p = buf;
do
*p++ = tolower (c);
*p = '\0';
return c;
} while ( c != EOF );
return EOF;
}
/*****************************************************************
**
** parse_namedconf (const char *filename, chroot_dir, dir, dirsize, int (*func) ())
**
** Very dumb named.conf parser.
** - In a zone declaration the _first_ keyword MUST be "type"
** - For every master zone "func (directory, zone, filename)" will be called
**
*****************************************************************/
int parse_namedconf (const char *filename, const char *chroot_dir, char *dir, size_t dirsize, int (*func) ())
{
int tok;
#if 1 /* this is potentialy too small for key data, but we don't need the keys... */
#else
#endif
view[0] = '\0';
return 0;
{
{
}
{
{
dbg_val2 ("parse_namedconf: directory found \"%s\" (dir is %s)\n",
else
/* prepend chroot directory (do it only once) */
if ( chroot_dir && *chroot_dir )
{
chroot_dir = NULL;
}
else
}
}
else if ( tok == TOK_INCLUDE )
{
{
else
return 0;
}
else
{
error ("parse_namedconf: need a filename after \"include\"!\n");
}
}
{
continue;
}
{
continue;
continue;
continue;
continue;
}
else
}
return 1;
}
#ifdef TEST_NCPARSE
{
printf ("printzone ");
printf ("file ");
putchar ('\n');
return 1;
}
char *progname;
{
directory[0] = '\0';
if ( --argc == 0 )
else
}
#endif