Bug 14522

Summary: dhclient incorrectly reads and sets hostname as a hex string
Product: Base System Reporter: simon.hewison <simon.hewison>
Component: confAssignee: David E. O'Brien <obrien>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 3.3-RELEASE   
Hardware: Any   
OS: Any   

Description simon.hewison 1999-10-25 18:40:00 UTC
When using the standard dhcp client configuration, and when the DHCP server sets the hostname, dhclient sets the hostname to a colon separated hexadecimal representation of the string which is the hostname finished off with the null termination byte.

Fix: 

don't assign a hostname by dhcp, set it in /etc/rc.conf :-(
How-To-Repeat: Get a Microsoft DHCP server to assign a hostname to a reserved lease.
Comment 1 m.seaman 1999-10-26 10:17:40 UTC
simon.hewison@demon.net wrote:
> 
> >Number:         14522
> >Category:       conf
> >Synopsis:       dhclient incorrectly reads and sets hostname as a hex string
> >Confidential:   no
> >Severity:       non-critical
> >Priority:       low
> >Responsible:    freebsd-bugs
> >State:          open
> >Quarter:
> >Keywords:
> >Date-Required:
> >Class:          sw-bug
> >Submitter-Id:   current-users
> >Arrival-Date:   Mon Oct 25 10:40:00 PDT 1999
> >Closed-Date:
> >Last-Modified:
> >Originator:     Simon Hewison
> >Release:        3.3-RELEASE
> >Organization:
> Demon Internet
> >Environment:
> FreeBSD 67:77:2d:69:6e:64:65:78:2d:32:0 3.3-RELEASE FreeBSD 3.3-RELEASE #0: Thu Sep 16 23:40:35 GMT 1999     jkh@highwing.cdrom.com:/usr/src/sys/compile/GENERIC  i386
> >Description:
> When using the standard dhcp client configuration, and when the DHCP server sets the hostname, dhclient sets the hostname to a colon separated hexadecimal representation of the string which is the hostname finished off with the null termination byte.
> >How-To-Repeat:
> Get a Microsoft DHCP server to assign a hostname to a reserved lease.
> 
> >Fix:
> don't assign a hostname by dhcp, set it in /etc/rc.conf :-(
> 
> >Release-Note:
> >Audit-Trail:
> >Unformatted:
> 
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-bugs" in the body of the message

For what it's worth, here's a /etc/dhclient-enter-hooks script I kludged
together to get round this problem.  Not pretty, not very well tested and just
one of those temporary fixes that seems to have settled in for the duration.


#!/bin/sh

# Local customizations for /sbin/dhclient-script Here we just setup
# the hostname.  This is imported into /sbin/dhclient-script via
# `. /etc/dhclient-enter-hooks'

# Check on the various DHCP variables we would like to see.  These are
# all independant of the particular interface we're managing, but as
# we only have one interface per machine, here will do as well as
# anywhere.

if [ x$new_host_name != x ]; then
    # isc-dhcpd 2.0b1p26 supplies/expects the hostname as an arbitrary
    # hex encoded binary string `xx:xx:xx' where x are hex digits..
    # isc-dhcpd 2.0b1pl4 (which we're using as the server) supplies
    # the hostname as an ascii string.  Why the change?  This kludge
    # converts to ascii if necessary.

    if echo $new_host_name | \
        grep -Ex '([[:xdigit:]]{2}:)+[[:xdigit:]]{2}' >/dev/null 2>&1;
    then
        new_host_name=`perl -e 'map { print chr hex $_; } \
            split /:/, $ARGV[0];' $new_host_name`
    fi    
    $LOGGER "New Host Name: $new_host_name"
fi

if [ x$old_host_name != x ]; then
    # Need to decode old_host_name in the same way (?)

    if echo $old_host_name | \
        grep -Ex '([[:xdigit:]]{2}:)+[[:xdigit:]]{2}' >/dev/null 2>&1;
    then
        old_host_name=`perl -e 'map { print chr hex $_; } \
            split /:/, $ARGV[0];' $old_host_name`
    fi    
fi

# Define functions to substitute DHCP data into local config files
# or to set/change various system attributes.  Nb. this relies on
# overwriting the static values set from rc.* files on boot-up.

set_host_name() {
    if [ x$new_host_name != x ] \
        && [ x$new_host_name != x$old_host_name ]
    then
        hostname $new_host_name
    fi
    $LOGGER set hostname to $new_host_name 
}

# Test $reason to discover why we were called and amend our
# configuration appropriately.

exit_status=0

case $reason in
    MEDIUM)     # Change of interface media type
        ;;
    PREINIT)    # Config. interface prior to contacting DHCP server
        ;;
    ARPSEND)    # Check offered IP not already in use via arp (how?)
        ;;
    ARPCHECK)   # Did we get a response to ARPSEND?
        ;;
    BOUND)      # Received initial config from DHCP server
        set_host_name ;
        ;;
    RENEW)      # Received change to configuration from DHCP server
        set_host_name ;
        ;;
    REBIND)     # Bound to a different DHCP server
        set_host_name ;
        ;;
    REBOOT)     # Renewed previous lease after reboot
        set_host_name ;
        ;;
    EXPIRE)     # Can't get a new/replacement lease
        ;;
    FAIL)       # Can't contact DHCP server or can't get valid lease
        ;;
    TIMEOUT)    # Can't contact DHCP server, but have saved lease to reuse
        set_host_name ;
        ;;
    *)
        $LOGGER "unknown reason \"$reason\" for calling dhclient-script"
        exit_status=1
        ;;
esac

# 
# That's All Folks!
#

	Matthew

-- 
           Certe, Toto, sentio nos in Kansate non iam adesse.

   Dr. Matthew Seaman, Inpharmatica Ltd, 60 Charlotte St, London, W1P 2AX
            Tel: +44 171 631 4644 x229  Fax: +44 171 631 4844
Comment 2 nbm freebsd_committer freebsd_triage 2000-07-14 13:55:49 UTC
Responsible Changed
From-To: freebsd-bugs->obrien

Mr. O'Brien was recently accumulating dhclient PRs.
Comment 3 David E. O'Brien freebsd_committer freebsd_triage 2000-07-14 18:17:03 UTC
State Changed
From-To: open->closed

This bug has been fixed in ISC's DHCP version 2.0.  FreeBSD-3.4 should 
this version.  If not, FreeBSD-3.5 definately does.  If the user does not 
want to upgrade to 3.{4,5}, /sbin/dhclient could be extrated from the 
release distribution and used on the 3.3 machine.