summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Lemon <source@isc.org>1999-09-16 05:12:38 +0000
committerTed Lemon <source@isc.org>1999-09-16 05:12:38 +0000
commit92ce3f81d15f118623df8b0a5e84bfc7cd60293d (patch)
treec7dc7911a3cb9dc5faa33b5caa49031711c4503f
parent696337081a9fb10ca1ab105e54ef09e8441d12fd (diff)
downloadisc-dhcp-92ce3f81d15f118623df8b0a5e84bfc7cd60293d.tar.gz
Return error status when duplicate hostname found instead of bombing.
-rw-r--r--common/memory.c52
-rw-r--r--server/confpars.c7
-rw-r--r--server/omapi.c16
3 files changed, 47 insertions, 28 deletions
diff --git a/common/memory.c b/common/memory.c
index 870d8c74..08fa799b 100644
--- a/common/memory.c
+++ b/common/memory.c
@@ -22,7 +22,7 @@
#ifndef lint
static char copyright[] =
-"$Id: memory.c,v 1.58 1999/09/16 01:19:52 mellon Exp $ Copyright (c) 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
+"$Id: memory.c,v 1.59 1999/09/16 05:12:33 mellon Exp $ Copyright (c) 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
@@ -40,7 +40,7 @@ static struct host_decl *dynamic_hosts;
omapi_object_type_t *dhcp_type_host;
-void enter_host (hd, dynamicp, commit)
+isc_result_t enter_host (hd, dynamicp, commit)
struct host_decl *hd;
int dynamicp;
int commit;
@@ -49,6 +49,30 @@ void enter_host (hd, dynamicp, commit)
struct host_decl *np = (struct host_decl *)0;
struct executable_statement *esp;
+ if (!host_name_hash) {
+ host_name_hash = new_hash ();
+ if (!host_name_hash)
+ log_fatal ("Can't allocate host name hash");
+ } else {
+ hp = (struct host_decl *)
+ hash_lookup (host_name_hash,
+ (unsigned char *)hd -> name,
+ strlen (hd -> name));
+
+ /* If there isn't already a host decl matching this
+ address, add it to the hash table. */
+ if (!hp) {
+ add_hash (host_name_hash,
+ (unsigned char *)hd -> name,
+ strlen (hd -> name),
+ (unsigned char *)hd);
+ hd -> refcnt++; /* XXX */
+ } else
+ /* XXX actually, we have to delete the old one
+ XXX carefully and replace it. Not done yet. */
+ return ISC_R_EXISTS;
+ }
+
if (dynamicp) {
hd -> flags |= HOST_DECL_DYNAMIC;
hd -> n_dynamic = dynamic_hosts;
@@ -148,32 +172,12 @@ void enter_host (hd, dynamicp, commit)
}
}
- if (!host_name_hash) {
- host_name_hash = new_hash ();
- if (!host_name_hash)
- log_fatal ("Can't allocate host/hw hash");
- } else {
- hp = (struct host_decl *)
- hash_lookup (host_name_hash,
- (unsigned char *)hd -> name,
- strlen (hd -> name));
-
- /* If there isn't already a host decl matching this
- address, add it to the hash table. */
- if (!hp) {
- add_hash (host_name_hash,
- (unsigned char *)hd -> name, strlen (hd -> name),
- (unsigned char *)hd);
- hd -> refcnt++; /* XXX */
- } else
- /* XXX actually, we have to delete the old one
- XXX carefully and replace it. Not done yet. */
- log_fatal ("duplicate hostname: %s!", hd -> name);
- }
if (dynamicp && commit) {
write_host (hd);
commit_leases ();
}
+
+ return ISC_R_SUCCESS;
}
void delete_host (hd, commit)
diff --git a/server/confpars.c b/server/confpars.c
index 6625e908..ce75cf37 100644
--- a/server/confpars.c
+++ b/server/confpars.c
@@ -22,7 +22,7 @@
#ifndef lint
static char copyright[] =
-"$Id: confpars.c,v 1.81 1999/09/16 00:52:50 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n";
+"$Id: confpars.c,v 1.82 1999/09/16 05:12:38 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
@@ -901,6 +901,7 @@ void parse_host_declaration (cfile, group)
int declaration = 0;
int dynamicp = 0;
int deleted = 0;
+ isc_result_t status;
token = peek_token (&val, cfile);
if (token != LBRACE) {
@@ -968,7 +969,9 @@ void parse_host_declaration (cfile, group)
free_group (host -> group, "parse_host_declaration");
dfree (host, "parse_host_declaration");
} else {
- enter_host (host, dynamicp, 0);
+ status = enter_host (host, dynamicp, 0);
+ if (status != ISC_R_SUCCESS)
+ parse_warn ("host %s: %s", isc_result_totext (status));
}
}
diff --git a/server/omapi.c b/server/omapi.c
index 46814a00..5179ada7 100644
--- a/server/omapi.c
+++ b/server/omapi.c
@@ -29,7 +29,7 @@
#ifndef lint
static char copyright[] =
-"$Id: omapi.c,v 1.6 1999/09/16 04:53:38 mellon Exp $ Copyright (c) 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
+"$Id: omapi.c,v 1.7 1999/09/16 05:12:38 mellon Exp $ Copyright (c) 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
@@ -298,6 +298,10 @@ isc_result_t dhcp_lease_signal_handler (omapi_object_t *h,
lease = (struct lease *)h;
if (!strcmp (name, "updated")) {
+ if (lease -> hardware_addr.hlen == 0 ||
+ lease -> hardware_addr.htype == 0 ||
+ lease -> hardware_addr.hlen > 16)
+ return ISC_R_INVALIDARG;
if (!write_lease (lease))
return ISC_R_IOERROR;
}
@@ -828,6 +832,11 @@ isc_result_t dhcp_host_signal_handler (omapi_object_t *h,
host = (struct host_decl *)h;
if (!strcmp (name, "updated")) {
+ if (host -> interface.hlen == 0 ||
+ host -> interface.htype == 0 ||
+ host -> interface.hlen > 16)
+ return ISC_R_INVALIDARG;
+
if (!host -> name) {
char hnbuf [64];
sprintf (hnbuf, "nh%08lx%08lx",
@@ -837,7 +846,10 @@ isc_result_t dhcp_host_signal_handler (omapi_object_t *h,
return ISC_R_NOMEMORY;
strcpy (host -> name, hnbuf);
}
- enter_host (host, 1, 1);
+
+ status = enter_host (host, 1, 1);
+ if (status != ISC_R_SUCCESS)
+ return status;
}
/* Try to find some inner object that can take the value. */