Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 26 Oct 1999 09:17:40 +0000
From:      Matthew Seaman <m.seaman@inpharmatica.co.uk>
To:        simon.hewison@demon.net
Cc:        freebsd-gnats-submit@FreeBSD.ORG, freebsd-bugs@FreeBSD.ORG
Subject:   Re: conf/14522: dhclient incorrectly reads and sets hostname as a hex  string
Message-ID:  <381571B4.7C8E2B60@inpharmatica.co.uk>
References:  <19991025173454.F0C4B15194@hub.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?381571B4.7C8E2B60>