]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
Fix assorted code which assumes that leases will always have an
authorDamien Neil <source@isc.org>
Mon, 14 Aug 2000 21:58:04 +0000 (21:58 +0000)
committerDamien Neil <source@isc.org>
Mon, 14 Aug 2000 21:58:04 +0000 (21:58 +0000)
associated hardware address.

server/omapi.c

index 9711bdc73ac28cbb3150935e46a0502477b21729..faf3b3567cc886af72a549ac7a17346616046b35 100644 (file)
@@ -50,7 +50,7 @@
 
 #ifndef lint
 static char copyright[] =
-"$Id: omapi.c,v 1.33 2000/07/06 22:37:53 mellon Exp $ Copyright (c) 1999-2000 The Internet Software Consortium.  All rights reserved.\n";
+"$Id: omapi.c,v 1.34 2000/08/14 21:58:04 neild Exp $ Copyright (c) 1999-2000 The Internet Software Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -284,14 +284,20 @@ isc_result_t dhcp_lease_get_value (omapi_object_t *h, omapi_object_t *id,
                                 ((omapi_object_t *)lease -> billing_class),
                                 MDL);
                return ISC_R_NOTFOUND;
-       } else if (!omapi_ds_strcmp (name, "hardware-address"))
-               return omapi_make_const_value
-                       (value, name, &lease -> hardware_addr.hbuf [1],
-                        (unsigned)(lease -> hardware_addr.hlen - 1), MDL);
-       else if (!omapi_ds_strcmp (name, "hardware-type"))
-               return omapi_make_int_value (value, name,
-                                            lease -> hardware_addr.hbuf [0],
-                                            MDL);
+       } else if (!omapi_ds_strcmp (name, "hardware-address")) {
+               if (lease -> hardware_addr.hlen)
+                       return omapi_make_const_value
+                               (value, name, &lease -> hardware_addr.hbuf [1],
+                                (unsigned)(lease -> hardware_addr.hlen - 1),
+                                MDL);
+               return ISC_R_NOTFOUND;
+       } else if (!omapi_ds_strcmp (name, "hardware-type")) {
+               if (lease -> hardware_addr.hlen)
+                       return omapi_make_int_value
+                               (value, name, lease -> hardware_addr.hbuf [0],
+                                MDL);
+               return ISC_R_NOTFOUND;
+       }
 
        /* Try to find some inner object that can take the value. */
        if (h -> inner && h -> inner -> type -> get_value) {
@@ -485,30 +491,33 @@ isc_result_t dhcp_lease_stuff_values (omapi_object_t *c,
        if (status != ISC_R_SUCCESS)
                return status;
 
-       status = omapi_connection_put_name (c, "hardware-address");
-       if (status != ISC_R_SUCCESS)
-               return status;
-       status = (omapi_connection_put_uint32
-                 (c, (unsigned long)(lease -> hardware_addr.hlen - 1)));
-       if (status != ISC_R_SUCCESS)
-               return status;
-       status = (omapi_connection_copyin
-                 (c, &lease -> hardware_addr.hbuf [1],
-                  (unsigned long)(lease -> hardware_addr.hlen - 1)));
-       
-       if (status != ISC_R_SUCCESS)
-               return status;
+       if (lease -> hardware_addr.hlen) {
+               status = omapi_connection_put_name (c, "hardware-address");
+               if (status != ISC_R_SUCCESS)
+                       return status;
+               status = (omapi_connection_put_uint32
+                         (c,
+                          (unsigned long)(lease -> hardware_addr.hlen - 1)));
+               if (status != ISC_R_SUCCESS)
+                       return status;
+               status = (omapi_connection_copyin
+                         (c, &lease -> hardware_addr.hbuf [1],
+                          (unsigned long)(lease -> hardware_addr.hlen - 1)));
 
-       status = omapi_connection_put_name (c, "hardware-type");
-       if (status != ISC_R_SUCCESS)
-               return status;
-       status = omapi_connection_put_uint32 (c, sizeof (int));
-       if (status != ISC_R_SUCCESS)
-               return status;
-       status = omapi_connection_put_uint32 (c,
-                                             lease -> hardware_addr.hbuf [0]);
-       if (status != ISC_R_SUCCESS)
-               return status;
+               if (status != ISC_R_SUCCESS)
+                       return status;
+
+               status = omapi_connection_put_name (c, "hardware-type");
+               if (status != ISC_R_SUCCESS)
+                       return status;
+               status = omapi_connection_put_uint32 (c, sizeof (int));
+               if (status != ISC_R_SUCCESS)
+                       return status;
+               status = omapi_connection_put_uint32
+                       (c, lease -> hardware_addr.hbuf [0]);
+               if (status != ISC_R_SUCCESS)
+                       return status;
+       }
 
 
        status = omapi_connection_put_name (c, "ends");