]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
Return error status when duplicate hostname found instead of bombing.
authorTed Lemon <source@isc.org>
Thu, 16 Sep 1999 05:12:38 +0000 (05:12 +0000)
committerTed Lemon <source@isc.org>
Thu, 16 Sep 1999 05:12:38 +0000 (05:12 +0000)
common/memory.c
server/confpars.c
server/omapi.c

index 870d8c74b5da1abbb2209f6ba858d3e271df5ab9..08fa799be61c355cba54026630a06abba64a08b8 100644 (file)
@@ -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)
index 6625e908876a25b2a90754783b5a4f900271b04c..ce75cf37df4691c49be82acc0e1ff6d6f530f1b7 100644 (file)
@@ -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));
        }
 }
 
index 46814a004f204f2d648f493f27d54810d7c2b95b..5179ada73182acaf0ff2b890e852459e18c89436 100644 (file)
@@ -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. */