]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
Fixed OMAPI lookups based on hardware-address. The hardware type
authorDamien Neil <source@isc.org>
Fri, 20 Oct 2000 01:01:41 +0000 (01:01 +0000)
committerDamien Neil <source@isc.org>
Fri, 20 Oct 2000 01:01:41 +0000 (01:01 +0000)
is now specified via the hardware-type field.

server/omapi.c

index 497c08af5564e96caaf2f65536dabf3c25119c0b..557f97ad8a847ed1968661be9c3cbc8e7aeb2ef2 100644 (file)
@@ -50,7 +50,7 @@
 
 #ifndef lint
 static char copyright[] =
-"$Id: omapi.c,v 1.39 2000/10/10 19:14:37 mellon Exp $ Copyright (c) 1999-2000 The Internet Software Consortium.  All rights reserved.\n";
+"$Id: omapi.c,v 1.40 2000/10/20 01:01:41 neild Exp $ Copyright (c) 1999-2000 The Internet Software Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -1204,11 +1204,53 @@ isc_result_t dhcp_host_lookup (omapi_object_t **lp,
        /* Now look for a hardware address. */
        status = omapi_get_value_str (ref, id, "hardware-address", &tv);
        if (status == ISC_R_SUCCESS) {
-               host = (struct host_decl *)0;
-               host_hash_lookup (&host, host_hw_addr_hash,
-                                 tv -> value -> u.buffer.value,
-                                 tv -> value -> u.buffer.len, MDL);
+               unsigned char *haddr;
+               unsigned int len;
+
+               len = tv -> value -> u.buffer.len + 1;
+               haddr = dmalloc (len, MDL);
+               if (!haddr) {
+                       omapi_value_dereference (&tv, MDL);
+                       return ISC_R_NOMEMORY;
+               }
+
+               memcpy (haddr + 1, tv -> value -> u.buffer.value, len - 1);
                omapi_value_dereference (&tv, MDL);
+
+               status = omapi_get_value_str (ref, id, "hardware-type", &tv);
+               if (status == ISC_R_SUCCESS) {
+                       if (tv -> value -> type == omapi_datatype_data) {
+                               if ((tv -> value -> u.buffer.len != 4) ||
+                                   (tv -> value -> u.buffer.value[0] != 0) ||
+                                   (tv -> value -> u.buffer.value[1] != 0) ||
+                                   (tv -> value -> u.buffer.value[2] != 0)) {
+                                       omapi_value_dereference (&tv, MDL);
+                                       dfree (haddr, MDL);
+                                       return ISC_R_INVALIDARG;
+                               }
+
+                               haddr[0] = tv -> value -> u.buffer.value[3];
+                       } else if (tv -> value -> type == omapi_datatype_int) {
+                               haddr[0] = (unsigned char)
+                                       tv -> value -> u.integer;
+                       } else {
+                               omapi_value_dereference (&tv, MDL);
+                               dfree (haddr, MDL);
+                               return ISC_R_INVALIDARG;
+                       }
+
+                       omapi_value_dereference (&tv, MDL);
+               } else {
+                       /* If no hardware-type is specified, default to
+                          ethernet.  This may or may not be a good idea,
+                          but Telus is currently relying on this behavior.
+                          - DPN */
+                       haddr[0] = HTYPE_ETHER;
+               }
+
+               host = (struct host_decl *)0;
+               host_hash_lookup (&host, host_hw_addr_hash, haddr, len, MDL);
+               dfree (haddr, MDL);
                        
                if (*lp && *lp != (omapi_object_t *)host) {
                        omapi_object_dereference (lp, MDL);