mirror of
https://gitlab.isc.org/isc-projects/dhcp
synced 2025-08-31 06:15:55 +00:00
Return error status when duplicate hostname found instead of bombing.
This commit is contained in:
@@ -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)
|
||||
|
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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. */
|
||||
|
Reference in New Issue
Block a user