summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorDavid Hankins <dhankins@isc.org>2006-06-06 16:35:18 +0000
committerDavid Hankins <dhankins@isc.org>2006-06-06 16:35:18 +0000
commit5e864416367e93c148a709b34ae386f1539c4000 (patch)
tree701a76b3d394bac7bc7d4f0233869fd9875f3109 /common
parentd19e2cf7de53b5652d81164ca4559789e3dea511 (diff)
downloadisc-dhcp-5e864416367e93c148a709b34ae386f1539c4000.tar.gz
- A new common (server or client) option, 'db-time-format local;', has
been added which prints the local time in /var/db/dhcpd.leases rather than UTC. Thanks to a patch from Ken Lalonde. [ISC-Bugs #2678]
Diffstat (limited to 'common')
-rw-r--r--common/conflex.c8
-rw-r--r--common/parse.c49
-rw-r--r--common/print.c49
3 files changed, 102 insertions, 4 deletions
diff --git a/common/conflex.c b/common/conflex.c
index 5f744998..db3de045 100644
--- a/common/conflex.c
+++ b/common/conflex.c
@@ -34,7 +34,7 @@
#ifndef lint
static char copyright[] =
-"$Id: conflex.c,v 1.98 2006/06/01 20:23:17 dhankins Exp $ Copyright (c) 2004-2006 Internet Systems Consortium. All rights reserved.\n";
+"$Id: conflex.c,v 1.99 2006/06/06 16:35:18 dhankins Exp $ Copyright (c) 2004-2006 Internet Systems Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
@@ -647,6 +647,8 @@ static enum dhcp_token intern (atom, dfv)
return CLTT;
break;
case 'd':
+ if (!strcasecmp(atom + 1, "b-time-format"))
+ return DB_TIME_FORMAT;
if (!strcasecmp (atom + 1, "ns-update"))
return DNS_UPDATE;
if (!strcasecmp (atom + 1, "ns-delete"))
@@ -711,6 +713,8 @@ static enum dhcp_token intern (atom, dfv)
}
if (!strcasecmp (atom + 1, "ncode-int"))
return ENCODE_INT;
+ if (!strcasecmp(atom + 1, "poch"))
+ return EPOCH;
if (!strcasecmp (atom + 1, "thernet"))
return ETHERNET;
if (!strcasecmp (atom + 1, "nds"))
@@ -823,6 +827,8 @@ static enum dhcp_token intern (atom, dfv)
return LET;
if (!strcasecmp (atom + 1, "oad"))
return LOAD;
+ if (!strcasecmp(atom + 1, "ocal"))
+ return LOCAL;
if (!strcasecmp (atom + 1, "og"))
return LOG;
break;
diff --git a/common/parse.c b/common/parse.c
index 33529a5b..e1b6b772 100644
--- a/common/parse.c
+++ b/common/parse.c
@@ -34,7 +34,7 @@
#ifndef lint
static char copyright[] =
-"$Id: parse.c,v 1.111 2006/06/05 16:42:58 dhankins Exp $ Copyright (c) 2004-2006 Internet Systems Consortium. All rights reserved.\n";
+"$Id: parse.c,v 1.112 2006/06/06 16:35:18 dhankins Exp $ Copyright (c) 2004-2006 Internet Systems Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
@@ -758,6 +758,25 @@ TIME parse_date (cfile)
return MAX_TIME;
}
+ /* This indicates 'local' time format. */
+ if (token == EPOCH) {
+ token = next_token(&val, NULL, cfile);
+
+ if (token != NUMBER) {
+ parse_warn(cfile, "Seconds since epoch expected.");
+ if (token != SEMI)
+ skip_to_semi(cfile);
+ return (TIME)0;
+ }
+
+ guess = atoi(val);
+
+ if (!parse_semi(cfile))
+ return (TIME)0;
+
+ return guess;
+ }
+
if (token != NUMBER) {
parse_warn (cfile, "numeric day of week expected.");
if (token != SEMI)
@@ -1754,6 +1773,32 @@ int parse_executable_statement (result, cfile, lose, case_context)
token = peek_token (&val, (unsigned *)0, cfile);
switch (token) {
+ case DB_TIME_FORMAT:
+ next_token(&val, NULL, cfile);
+
+ token = next_token(&val, NULL, cfile);
+ if (token == DEFAULT) {
+ db_time_format = DEFAULT_TIME_FORMAT;
+ } else if (token == LOCAL) {
+ db_time_format = LOCAL_TIME_FORMAT;
+ } else {
+ parse_warn(cfile, "Expecting 'local' or 'default'.");
+ if (token != SEMI)
+ skip_to_semi(cfile);
+ *lose = 1;
+ return 0;
+ }
+
+ token = next_token(&val, NULL, cfile);
+ if (token != SEMI) {
+ parse_warn(cfile, "Expecting a semicolon.");
+ *lose = 1;
+ return 0;
+ }
+
+ /* We're done here. */
+ return 1;
+
case IF:
next_token (&val, (unsigned *)0, cfile);
return parse_if_statement (result, cfile, lose);
@@ -2188,7 +2233,7 @@ int parse_executable_statement (result, cfile, lose, case_context)
return 0;
}
break;
-
+
/* Not really a statement, but we parse it here anyway
because it's appropriate for all DHCP agents with
parsers. */
diff --git a/common/print.c b/common/print.c
index 67f22837..a1c748ad 100644
--- a/common/print.c
+++ b/common/print.c
@@ -34,11 +34,13 @@
#ifndef lint
static char copyright[] =
-"$Id: print.c,v 1.59 2006/05/11 16:31:29 dhankins Exp $ Copyright (c) 2004-2006 Internet Systems Consortium. All rights reserved.\n";
+"$Id: print.c,v 1.60 2006/06/06 16:35:18 dhankins Exp $ Copyright (c) 2004-2006 Internet Systems Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
+int db_time_format = DEFAULT_TIME_FORMAT;
+
char *quotify_string (const char *s, const char *file, int line)
{
unsigned len = 0;
@@ -1427,3 +1429,48 @@ void print_dns_status (int status, ns_updque *uq)
log_info ("%s", obuf);
}
#endif /* NSUPDATE */
+
+/* Format the given time as "A; # B", where A is the format
+ * used by the parser, and B is the local time, for humans.
+ */
+const char *
+print_time(TIME t)
+{
+ static char buf[sizeof("epoch 9223372036854775807; "
+ "# Wed Jun 30 21:49:08 2147483647")];
+ /* The string: "6 2147483647/12/31 23:59:60;"
+ * is smaller than the other, used to declare the buffer size, so
+ * we can use one buffer for both.
+ */
+
+ if (t == MAX_TIME)
+ return "never;";
+
+ if (t < 0)
+ return NULL;
+
+ /* For those lucky enough to have a 128-bit time_t, ensure that
+ * whatever (corrupt) value we're given doesn't exceed the static
+ * buffer.
+ */
+#if (MAX_TIME > 0x7fffffffffffffff)
+ if (t > 0x7fffffffffffffff)
+ return NULL;
+#endif
+
+ if (db_time_format == LOCAL_TIME_FORMAT) {
+ if (strftime(buf, sizeof(buf),
+ "epoch %s; # %a %b %d %H:%M:%S %Y",
+ localtime(&t)) == 0)
+ return NULL;
+ } else {
+ /* No bounds check for the year is necessary - in this case,
+ * strftime() will run out of space and assert an error.
+ */
+ if (strftime(buf, sizeof(buf), "%w %Y/%m/%d %H:%M:%S;",
+ gmtime(&t)) == 0)
+ return NULL;
+ }
+
+ return buf;
+}