/****************************************************************
**
** @(#) zconf.c -- configuration file parser for dnssec.conf
**
** Most of the code is from the SixXS Heartbeat Client
** written by Jeroen Massar <jeroen@sixxs.net>
**
** New config types and many code changes by Holger Zuleger
**
** Copyright (c) Aug 2005, Jeroen Massar.
** Copyright (c) Aug 2005 - Apr 2010, Holger Zuleger.
** 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 Jeroen Masar or Holger Zuleger 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 <errno.h>
# include <unistd.h>
# include <stdlib.h>
# include <stdarg.h>
# include <string.h>
# include <strings.h>
# include <assert.h>
# include <ctype.h>
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
# include "config_zkt.h"
# include "debug.h"
# include "misc.h"
#define extern
# include "zconf.h"
#undef extern
# include "dki.h"
# define cmdln (0)
typedef enum {
CONF_END = 0,
} ctype_t;
/*****************************************************************
** private (static) variables
*****************************************************************/
static int compversion;
NULL, /* viewname cmdline parameter */
0, /* noexec cmdline parameter */
DIST_CMD, /* defaults to NULL which means to run "rndc reload" */
};
typedef struct {
/* this is a ugly hack needed by cmpconfig () */
} zconf_para_t;
#if defined (DEF_TTL)
#endif
{ "Key_Algo", 99, 100, CONF_ALGO, &def.k_algo }, /* now used as general KEY algoritjm (KSK & ZSK) */
{ "KeyAlgo", 101, last, CONF_ALGO, &def.k_algo }, /* now used as general KEY algoritjm (KSK & ZSK) */
/* { "ZSK_algo", 1, CONF_ALGO, &def.z_algo }, ZSK algo removed (set to same as ksk) */
{ "ZSK_algo", first, 98, CONF_ALGO, &def.k2_algo }, /* if someone using it already, map the algo to the additional key algorithm */
};
/*****************************************************************
** private (static) function deklaration and definition
*****************************************************************/
{
}
{
zconf_para_t *c;
{
return 1;
}
return 0;
}
{
#if defined (DEF_TTL)
#endif
// set_varptr ("zsk_algo", &cp->z_algo, cp2 ? &cp2->z_algo: NULL);
}
{
char *tag;
zconf_para_t *c;
*p-- = '\0';
;
/* Ignore comments and emtpy lines */
if ( *p == '\0' || ISCOMMENT (p) )
return;
tag = p;
/* Get the end of the first argument */
p++;
*p++ = '\0'; /* Terminate this argument */
p++;
val = p; /* Start of the value */
/* If starting with quote, skip until next quote */
if ( *p == '"' || *p == '\'' )
{
p++; /* Find next quote */
p++;
*p = '\0';
val++; /* Skip the first quote */
}
else /* Otherwise check if there is any comment char at the end */
{
p++;
if ( ISCOMMENT (p) )
{
do /* Chop off white space before comment */
*p-- = '\0';
}
}
/* Otherwise it is already terminated above */
found = 0;
c = confpara;
{
{
char **str;
char quantity;
long lval;
found = 1;
switch ( c->type )
{
case CONF_VERSION:
break;
case CONF_LEVEL:
case CONF_FACILITY:
case CONF_STRING:
break;
case CONF_INT:
break;
case CONF_TIMEINT:
quantity = 'd';
lval = 0L;
else
if ( quantity == 'm' )
else if ( quantity == 'h' )
else if ( quantity == 'd' )
else if ( quantity == 'w' )
else if ( quantity == 'y' )
break;
case CONF_ALGO:
*((int *)c->var) = DK_ALGO_RSA;
*((int *)c->var) = DK_ALGO_DSA;
*((int *)c->var) = DK_ALGO_RSASHA1;
*((int *)c->var) = DK_ALGO_NSEC3DSA;
*((int *)c->var) = DK_ALGO_NSEC3RSASHA1;
*((int *)c->var) = DK_ALGO_RSASHA256;
*((int *)c->var) = DK_ALGO_RSASHA512;
#endif
else
error ("Illegal algorithm \"%s\" "
break;
case CONF_SERIAL:
else
error ("Illegal serial no format \"%s\" "
break;
case CONF_NSEC3:
else
error ("Illegal NSEC3 format \"%s\" "
break;
case CONF_BOOL:
break;
default:
}
}
c++;
}
if ( !found )
return;
}
{
int i;
long lval;
{
case CONF_VERSION:
break;
case CONF_COMMENT:
else
break;
case CONF_LEVEL:
case CONF_FACILITY:
{
{
char *p;
}
else
}
break;
case CONF_STRING:
break;
case CONF_BOOL:
break;
case CONF_TIMEINT:
if ( lval )
break;
case CONF_ALGO:
if ( i )
{
}
break;
case CONF_SERIAL:
else
break;
case CONF_NSEC3:
break;
case CONF_INT:
break;
case CONF_END:
/* NOTREACHED */
break;
}
}
/*****************************************************************
** public function definition
*****************************************************************/
{
}
{
if ( val == 0 )
else
return str;
}
/*****************************************************************
** loadconfig (file, conf)
** Loads a config file into the "conf" structure pointed to by "z".
** If "z" is NULL then a new conf struct will be dynamically
** allocated.
** If no filename is given the conf struct will be initialized
** with the builtin default config
*****************************************************************/
{
unsigned int line;
if ( z == NULL ) /* allocate new memory for zconf_t */
{
return NULL;
}
{
dbg_val0("loadconfig (NULL)\n");
return z;
}
set_all_varptr (z, NULL);
line = 0;
return z;
}
{
char *buf;
unsigned int line;
if ( z == NULL )
{
return NULL;
}
{
dbg_val0("loadconfig_fromstr (NULL)\n");
return z;
}
set_all_varptr (z, NULL);
/* str is const, so we have to copy it into a new buffer */
fatal ("loadconfig_fromstr: Out of memory");
line = 0;
while ( tok )
{
line++;
}
return z;
}
/*****************************************************************
** dupconfig (config)
** duplicate config struct and return a ptr to the new struct
*****************************************************************/
{
zconf_t *z;
return NULL;
return z;
}
/*****************************************************************
** freeconfig (config)
** free memory for config struct and return a NULL ptr
*****************************************************************/
{
}
/*****************************************************************
** setconfigpar (entry, pval)
*****************************************************************/
{
char *str;
zconf_para_t *c;
{
switch ( c->type )
{
case CONF_VERSION:
break;
case CONF_LEVEL:
case CONF_FACILITY:
case CONF_STRING:
if ( pval )
{
}
else
break;
case CONF_BOOL:
/* fall through */
case CONF_ALGO:
/* fall through */
case CONF_INT:
break;
case CONF_TIMEINT:
break;
case CONF_NSEC3:
break;
case CONF_SERIAL:
break;
case CONF_COMMENT:
case CONF_END:
/* NOTREACHED */
break;
}
return 1;
}
return 0;
}
/*****************************************************************
** printconfig (fname, config)
*****************************************************************/
{
if ( z == NULL )
return 0;
{
{
return -1;
}
}
return 1;
}
/*****************************************************************
** printconfigdiff (fname, conf_a, conf_b)
*****************************************************************/
{
int eq;
return 0;
{
{
return -1;
}
}
{
eq = 0;
continue;
{
case CONF_VERSION:
case CONF_END:
case CONF_COMMENT:
continue;
case CONF_NSEC3:
break;
case CONF_SERIAL:
break;
case CONF_BOOL:
case CONF_ALGO:
case CONF_INT:
break;
case CONF_TIMEINT:
break;
case CONF_LEVEL:
case CONF_FACILITY:
case CONF_STRING:
eq = 0;
else
eq = 1;
}
if ( !eq )
}
return 1;
}
/*****************************************************************
** checkconfig (config)
*****************************************************************/
{
int ret;
long max_ttl;
if ( z == NULL )
return 1;
if ( max_ttl <= 0 )
max_ttl = z->sigvalidity;
ret = 0;
if ( z->saltbits < 4 )
if ( z->saltbits > 128 )
{
fprintf (stderr, "While the maximum is 520 bits of salt, it's not recommended to use more than 128 bits.\n");
}
{
fprintf (stderr, "Signature should be valid for at least 1 day and no longer than 3 month (12 weeks)\n");
}
if ( z->max_ttl <= 0 )
{
fprintf (stderr, "Please set max_ttl to the maximum ttl used in the zone (run zkt-conf -w zone.db)\n");
}
else
max_ttl, z->sigvalidity);
// if ( z->resign > (z->sigvalidity*5/6) - (max_ttl + z->proptime) )
{
}
{
ret = fprintf (stderr, "signature lifetime (%ld) (%s)\n", z->sigvalidity, timeint2str(z->sigvalidity - max_ttl));
}
{
}
{
}
{
}
return !ret;
}
#ifdef CONF_TEST
const char *progname;
{
char *optstr;
int val;
while ( --argc >= 1 )
{
}
val = 1;
val = 2;
val = 1;
val = 1200;
}
#endif