/*****************************************************************
**
** @(#) zfparse.c -- A zone file parser
**
** Copyright (c) Jan 2010 - Jan 2010, 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 <stdlib.h>
# include <unistd.h> /* for link(), unlink() */
# include <ctype.h>
# include <assert.h>
#if 0
# include <time.h>
# include <utime.h>
# include <errno.h>
# include <fcntl.h>
#endif
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
# include "config_zkt.h"
# include "zconf.h"
# include "log.h"
# include "debug.h"
#define extern
# include "zfparse.h"
#undef extern
extern const char *progname;
/*****************************************************************
** is_multiline_rr (const char *s)
*****************************************************************/
{
while ( *p && *p != ';' )
{
if ( *p == '\"' )
do
p++;
while ( *p && *p != '\"' );
if ( *p == '(' )
*multi_line_rr = 1;
if ( *p == ')' )
*multi_line_rr = 0;
p++;
}
return p;
}
/*****************************************************************
** skipws (const char *s)
*****************************************************************/
static const char *skipws (const char *s)
{
while ( *s && (*s == ' ' || *s == '\t' || *s == '\n') )
s++;
return s;
}
/*****************************************************************
** skiplabel (const char *s)
*****************************************************************/
static const char *skiplabel (const char *s)
{
while ( *s && *s != ';' && *s != ' ' && *s != '\t' && *s != '\n' )
s++;
return s;
}
/*****************************************************************
** setminmax ()
*****************************************************************/
{
}
/*****************************************************************
** get_ttl ()
*****************************************************************/
static long get_ttl (const char *s)
{
char quantity;
long lval;
quantity = 'd';
if ( quantity == 'm' )
else if ( quantity == 'h' )
else if ( quantity == 'd' )
else if ( quantity == 'w' )
else if ( quantity == 'y' )
return lval;
}
/*****************************************************************
** addkeydb ()
*****************************************************************/
{
return -1;
return 0;
}
/*****************************************************************
** parsezonefile ()
** parse the BIND zone file 'file' and store the minimum and
** maximum ttl value in the corresponding parameter.
** if keydbfile is set, check if this file is already include.
** return 0 if keydbfile is not included
** return 1 if keydbfile is included
** return -1 on error
*****************************************************************/
{
int len;
int lnr;
long ttl;
int multi_line_rr;
int keydbfilefound;
const char *p;
return -1;
lnr = 0;
keydbfilefound = 0;
multi_line_rr = 0;
{
lnr++;
p = buf;
if ( multi_line_rr ) /* skip line if it's part of a multiline rr */
{
is_multiline_rr (&multi_line_rr, p);
continue;
}
if ( *p == '$' ) /* special directive ? */
{
{
}
{
keydbfilefound = 1;
else
}
}
else if ( !isspace (*p) ) /* label ? */
p = skiplabel (p);
p = skipws (p);
if ( *p == ';' ) /* skip line if it's a comment line */
continue;
/* skip class (hesiod is not supported now) */
p += 2;
p = skipws (p);
if ( isdigit (*p) ) /* ttl ? */
{
}
/* check the rest of the line if it's the beginning of a multi_line_rr */
is_multiline_rr (&multi_line_rr, p);
}
if ( file )
dbg_val5 ("parsezonefile (\"%s\", %ld, %ld, \"%s\") ==> %d\n",
return keydbfilefound;
}
#ifdef TEST
const char *progname;
{
long minttl;
long maxttl;
int keydbfound;
char *dnskeydb;
dnskeydb = "dnskey.db";
minttl = 0x7FFFFFFF;
maxttl = 0;
if ( keydbfound < 0 )
if ( dnskeydb && !keydbfound )
{
}
return 0;
}
#endif