/*****************************************************************
**
** @(#) zkt-soaserial.c (c) Oct 2007 Holger Zuleger hznet.de
**
** A small utility to print out the (unixtime) soa serial
** number in a human readable form
**
** Copyright (c) Oct 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 <time.h>
# include <utime.h>
# include <assert.h>
# include <stdlib.h>
# include <ctype.h>
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
# include "config_zkt.h"
static const char *progname;
/*****************************************************************
** timestr (sec)
*****************************************************************/
{
struct tm *t;
#if defined(HAVE_STRFTIME) && HAVE_STRFTIME
#else
static char *mstr[] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
int h, s;
h = t->tm_gmtoff / 3600;
s = t->tm_gmtoff % 3600;
h, s);
#endif
return timestr;
}
/****************************************************************
**
** int read_serial_fromfile (filename)
**
** This function depends on a special syntax formating the
** SOA record in the zone file!!
**
** To match the SOA record, the SOA RR must be formatted
** like this:
** @ IN SOA <master.fq.dn.> <hostmaster.fq.dn.> (
** <SPACEes or TABs> 1234567890; serial number
** <SPACEes or TABs> 86400 ; other values
** ...
**
****************************************************************/
{
int c;
int soafound;
return -1; /* file not found */
/* read until the line matches the beginning of a soa record ... */
soafound = 0;
{
soafound = 1;
soafound = 1;
}
if ( !soafound )
{
return -2; /* no zone file (soa not found) */
}
/* move forward until any non ws is reached */
;
*serial = 0L; /* read in the current serial number */
{
return -3; /* no serial number found */
}
return 0; /* ok! */
}
/*****************************************************************
** printserial()
*****************************************************************/
{
/* try to guess the soa serial format */
;
{
int y, m, d, v;
v = serial % 100;
serial /= 100;
d = serial % 100;
serial /= 100;
m = serial % 100;
serial /= 100;
y = serial;
printf ("\t%d-%02d-%02d Version %02d", y, m, d, v);
}
else /* unixtime */
printf ("\n");
}
/*****************************************************************
** usage (msg)
*****************************************************************/
{
exit (1);
}
/*****************************************************************
** main()
*****************************************************************/
{
unsigned long serial;
if ( --argc == 0 )
usage ("");
{
usage ("illegal option");
if ( argc != 2 )
usage ("Option -s requires an argument");
}
else
while ( argc-- > 0 )
else
return 0;
}