From: Ted Lemon Date: Thu, 6 Jul 2000 10:16:54 +0000 (+0000) Subject: Fix handling of client-hostname. X-Git-Tag: V3-BETA-2-PATCH-1~83 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d73e855da2fbb6edc1370482808cb0555d264488;p=thirdparty%2Fdhcp.git Fix handling of client-hostname. --- diff --git a/server/dhcp.c b/server/dhcp.c index 9fcf2f4ce..487ea1d19 100644 --- a/server/dhcp.c +++ b/server/dhcp.c @@ -43,7 +43,7 @@ #ifndef lint static char copyright[] = -"$Id: dhcp.c,v 1.155 2000/06/30 00:48:55 mellon Exp $ Copyright (c) 1995-2000 The Internet Software Consortium. All rights reserved.\n"; +"$Id: dhcp.c,v 1.156 2000/07/06 10:16:54 mellon Exp $ Copyright (c) 1995-2000 The Internet Software Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -1202,37 +1202,6 @@ void ack_lease (packet, lease, offer, when, msg, ms_nulltp) packet -> options, DHO_DHCP_SERVER_IDENTIFIER)) state -> got_server_identifier = 1; - /* Replace the old lease hostname with the new one, if it's changed. */ - oc = lookup_option (&dhcp_universe, packet -> options, DHO_HOST_NAME); - memset (&d1, 0, sizeof d1); - if (oc) - s1 = evaluate_option_cache (&d1, packet, (struct lease *)0, - packet -> options, - (struct option_state *)0, - &global_scope, oc, MDL); - if (oc && s1 && - lease -> client_hostname && - strlen (lease -> client_hostname) == d1.len && - !memcmp (lease -> client_hostname, d1.data, d1.len)) { - /* Hasn't changed. */ - data_string_forget (&d1, MDL); - } else if (oc && s1) { - if (lease -> client_hostname) - dfree (lease -> client_hostname, MDL); - lease -> client_hostname = - dmalloc (d1.len + 1, MDL); - if (!lease -> client_hostname) - log_error ("no memory for client hostname."); - else { - memcpy (lease -> client_hostname, d1.data, d1.len); - lease -> client_hostname [d1.len] = 0; - } - data_string_forget (&d1, MDL); - } else if (lease -> client_hostname) { - dfree (lease -> client_hostname, MDL); - lease -> client_hostname = 0; - } - /* Steal the agent options from the packet. */ if (packet -> options -> universes [agent_universe.index]) { state -> options -> universes [agent_universe.index] = @@ -1371,6 +1340,7 @@ void ack_lease (packet, lease, offer, when, msg, ms_nulltp) /* Make sure this packet satisfies the configured minimum number of seconds. */ + memset (&d1, 0, sizeof d1); if (offer == DHCPOFFER && (oc = lookup_option (&server_universe, state -> options, SV_MIN_SECS))) { @@ -1778,6 +1748,32 @@ void ack_lease (packet, lease, offer, when, msg, ms_nulltp) lt -> scope.bindings = lease -> scope.bindings; lease -> scope.bindings = (struct binding *)0; + /* Replace the old lease hostname with the new one, if it's changed. */ + oc = lookup_option (&dhcp_universe, packet -> options, DHO_HOST_NAME); + if (oc) + s1 = evaluate_option_cache (&d1, packet, (struct lease *)0, + packet -> options, + (struct option_state *)0, + &global_scope, oc, MDL); + if (oc && s1 && + lease -> client_hostname && + strlen (lease -> client_hostname) == d1.len && + !memcmp (lease -> client_hostname, d1.data, d1.len)) { + /* Hasn't changed. */ + data_string_forget (&d1, MDL); + lt -> client_hostname = lease -> client_hostname; + lease -> client_hostname = (char *)0; + } else if (oc && s1) { + lt -> client_hostname = dmalloc (d1.len + 1, MDL); + if (!lt -> client_hostname) + log_error ("no memory for client hostname."); + else { + memcpy (lt -> client_hostname, d1.data, d1.len); + lt -> client_hostname [d1.len] = 0; + } + data_string_forget (&d1, MDL); + } + /* Don't call supersede_lease on a mocked-up lease. */ if (lease -> flags & STATIC_LEASE) { /* Copy the hardware address into the static lease