From rbw@myplace.org  Wed Jan 30 09:12:10 2002
Return-Path: <rbw@myplace.org>
Received: from malkavian.org (malkavian.org [206.136.132.23])
	by hub.freebsd.org (Postfix) with ESMTP id 029EE37B405
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 30 Jan 2002 09:12:10 -0800 (PST)
Received: (from rbw@localhost)
	by malkavian.org (8.11.6/8.11.1) id g0UHC4800881;
	Wed, 30 Jan 2002 12:12:04 -0500 (EST)
	(envelope-from rbw@myplace.org)
Message-Id: <20020130101203.A551@malkavian.org>
Date: Wed, 30 Jan 2002 10:12:04 -0700
From: "brian j. peterson" <rbw@myplace.org>
Reply-To: "brian j. peterson" <rbw@myplace.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc: "brian j. peterson" <rbw@myplace.org>
Subject: [PATCH] /sbin/dhclient-script overwrites /etc/resolv.conf without any relevant information

>Number:         34455
>Category:       misc
>Synopsis:       [PATCH] /sbin/dhclient-script overwrites /etc/resolv.conf without any relevant information
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    obrien
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jan 30 09:20:00 PST 2002
>Closed-Date:    Thu Jan 31 07:02:34 PST 2002
>Last-Modified:  Thu Jan 31 11:20:01 PST 2002
>Originator:     "brian j. peterson" <rbw@myplace.org>
>Release:        FreeBSD 4.5-PRERELEASE alpha
>Organization:
>Environment:
System: FreeBSD nikita 4.5-PRERELEASE FreeBSD 4.5-PRERELEASE #7: Sun Jan 6 17:14:40 MST 2002 root@nikita:/usr/obj/usr/src/sys/HARLOT alpha


>Description:
With the following /etc/dhclient.conf, I am not requesting a domain-name
or domain-name-servers, but '/sbin/dhclient de0' still overwrites my
/etc/resolv.conf.

root@nikita% cat /etc/dhclient.conf 
interface "de0" {
        send host-name "nikita";
        request subnet-mask,
                broadcast-address,
                routers;
}
root@nikita% cat /etc/resolv.conf
search 
root@nikita% 

Basically, the make_resolv_conf() portion of /sbin/dhclient-conf is
overwriting /etc/resolv.conf despite the fact that it has no useful
information to write to it.


>How-To-Repeat:
1) define a custom /etc/resolv.conf
2) start /sbin/dhclient on an interface configured without any
   'domain-name' or 'domain-name-servers' options defined in any
   'require' or 'request' statements.
3) observe that /etc/resolv.conf has been overwritten


>Fix:

Modify the make_resolv_conf() portion of /sbin/dhclient like so:

root@nikita% diff -u /sbin/dhclient-script_1.9.2.4 /sbin/dhclient-script_new
--- /sbin/dhclient-script_1.9.2.4       Mon Jan  7 17:29:01 2002
+++ /sbin/dhclient-script_new   Tue Jan 29 18:54:04 2002
@@ -9,10 +9,12 @@
 fi
 
 make_resolv_conf() {
-  echo search $new_domain_name >/etc/resolv.conf
-  for nameserver in $new_domain_name_servers; do
-    echo nameserver $nameserver >>/etc/resolv.conf
-  done
+  if [ x$new_domain_name != x ]; then
+    echo search $new_domain_name >/etc/resolv.conf
+    for nameserver in $new_domain_name_servers; do
+      echo nameserver $nameserver >>/etc/resolv.conf
+    done
+  fi
 }
 
 # Must be used on exit.   Invokes the local dhcp client exit hooks, if any.

The above diff is based on
$FreeBSD: src/contrib/isc-dhcp/client/scripts/freebsd,v 1.9.2.4 2001/03/05 10:09:32 obrien Exp $
but can easily be applied to -CURRENT (v 1.19) and then MFC'd at a later date.
>Release-Note:
>Audit-Trail:

From: Ceri <setantae@submonkey.net>
To: "brian j. peterson" <rbw@myplace.org>
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: misc/34455: [PATCH] /sbin/dhclient-script overwrites /etc/resolv.conf without any relevant information
Date: Wed, 30 Jan 2002 18:28:07 +0000

 On Wed, Jan 30, 2002 at 10:12:04AM -0700, brian j. peterson wrote:
 > 
 > >How-To-Repeat:
 > 1) define a custom /etc/resolv.conf
 > 2) start /sbin/dhclient on an interface configured without any
 >    'domain-name' or 'domain-name-servers' options defined in any
 >    'require' or 'request' statements.
 > 3) observe that /etc/resolv.conf has been overwritten
 
 Strikes me as pilot error to be honest.
 If the DCHP server doesn't provide nameservers, and you're not overriding them,
 then you'll end up with nothing there.
 
 If you wish to insert some information into /etc/resolv.conf,
 that's what the supersede statement in dhclient.conf is for, viz.
 
 # cat /etc/dhclient.conf
 interface "ed0" {
 	supersede domain-name "private.submonkey.net";
 	prepend domain-name-servers 192.168.10.1;
 }
 
 -- 
 Ceri

From: "brian j. peterson" <rbw@myplace.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc: Ceri <setantae@submonkey.net>
Subject: Re: misc/34455: [PATCH] /sbin/dhclient-script overwrites /etc/resolv.conf without any relevant information
Date: Wed, 30 Jan 2002 14:04:31 -0700

 On Wed, Jan 30, 2002 at 06:28:07PM +0000, Ceri wrote:
 > Strikes me as pilot error to be honest.
 > If the DCHP server doesn't provide nameservers, and you're not overriding them,
 > then you'll end up with nothing there.
 > 
 > If you wish to insert some information into /etc/resolv.conf,
 > that's what the supersede statement in dhclient.conf is for, viz.
 > 
 > # cat /etc/dhclient.conf
 > interface "ed0" {
 > 	supersede domain-name "private.submonkey.net";
 > 	prepend domain-name-servers 192.168.10.1;
 > }
 
 admittedly, there are ways around this problem, but the fact is that
 dhclient-script is overwriting /etc/resolv.conf regardless of whether
 or not it has useful data to write to it.  my trivial patch solves this
 problem by not writing to /etc/resolv.conf if there's no reason to.
 (the script simply checks to see if a certain variable has a value or
 not, and writes to /etc/resolv.conf only if the variable has a value.)
 
 i prefer, at this point, to create my own /etc/resolv.conf, and since i'm
 not requesting any domain-name or domaina-name-servers information, i
 don't think dhclient-script has any business overwriting /etc/resolv.conf
 with "search \n".
 
 am i wrong to expect this script to not clobber important files with
 useless information?
 
 -brian

From: "brian j. peterson" <rbw@myplace.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc: Ceri <setantae@submonkey.net>
Subject: Re: misc/34455: [PATCH] /sbin/dhclient-script overwrites /etc/resolv.conf without any relevant information
Date: Wed, 30 Jan 2002 15:50:02 -0700

 On Wed, Jan 30, 2002 at 10:06:04PM +0000, Ceri wrote:
 > On Wed, Jan 30, 2002 at 01:10:02PM -0800, brian j. peterson wrote:
 > >  am i wrong to expect this script to not clobber important files with
 > >  useless information?
 > 
 > I don't know.
 > I think a modification like this should really be done locally in
 > /etc/dhclient-enter-hooks, as per dhclient-script.5 :
 > 
 >        When  it  starts,  the client script first defines a shell
 >        function, make_resolv_conf , which is later used to create
 >        the  /etc/resolv.conf  file.    To  override  the  default
 >        behaviour,  redefine  this  function  in  the  enter  hook
 >        script.
 > 
 > This opinion is mainly formed due to the difference in our perceptions of
 > what the patch actually does.  It suits your position, but it's not friendly
 > to anyone who might want to roll out empty /etc/resolv.conf's for whatever
 > reason.
 
 
 i consider the default behavior of /etc/dhclient-script to be bordering on
 destructive in this case.  imho, default behavior shouldn't be destructive.
 if someone wants to do something specific like roll out empty copies of
 /etc/resolv.conf, shouldn't THEY be using /etc/dhclient-enter-hooks as a
 means to achieve this?
 
 i realize i am asking for a modification of long-standing default behavior
 here, but i wouldn't be making the request if i didn't think it was
 warranted.  is it by design that the default make_resolv_conf() in
 dhclient-script overwrites /etc/resolv.conf every single time, no matter
 what the circumstances?  if so, can someone enlighten me as to the
 motivation behind that design decision?
 
 -brian
Responsible-Changed-From-To: freebsd-bugs->obrien 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Thu Jan 31 01:44:07 PST 2002 
Responsible-Changed-Why:  
Over to maintainer. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=34455 
State-Changed-From-To: open->closed 
State-Changed-By: obrien 
State-Changed-When: Thu Jan 31 07:02:34 PST 2002 
State-Changed-Why:  
That is how dhcp works WRT /etc/resolv.conf. 
The server is allowed to give you more information that you requested. 

If you want specific content in your /etc/resolv.conf reguardless to what 
the dhcp server provides, you need things like this in your /etc/dhclient.conf 

supersede domain-name "nuxi.com freebsd.org"; 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=34455 

From: "brian j. peterson" <rbw@myplace.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc: obrien@freebsd.org
Subject: Re: misc/34455: [PATCH] /sbin/dhclient-script overwrites /etc/resolv.conf without any relevant information
Date: Thu, 31 Jan 2002 10:32:23 -0700

 On Thu, Jan 31, 2002 at 07:06:02AM -0800, obrien@FreeBSD.org wrote:
 > Synopsis: [PATCH] /sbin/dhclient-script overwrites /etc/resolv.conf without any relevant information
 > 
 > State-Changed-From-To: open->closed
 > State-Changed-By: obrien
 > State-Changed-When: Thu Jan 31 07:02:34 PST 2002
 > State-Changed-Why: 
 > That is how dhcp works WRT /etc/resolv.conf.
 > The server is allowed to give you more information that you requested.
 
 The server isn't giving me any more information than was requested.  The
 problem is that dhclient-script is writing "search\n" to /etc/resolv.conf
 when the server hasn't provided ANY domain-name or domain-name-servers
 information.
 
 
 > If you want specific content in your /etc/resolv.conf reguardless to what
 > the dhcp server provides, you need things like this in your /etc/dhclient.conf
 > 
 > 	supersede domain-name "nuxi.com freebsd.org";
 
 I don't want dhclient-script even touching my /etc/resolv.conf unless it has
 useful information to write to it.
 
 I guess I've just been told "this is by design", but I want it to be under-
 stood that this is _NOT_ a situation where my manually configured
 /etc/resolv.conf has been overwritten with domain-name and domain-name-servers
 information from my DHCP server.  If that was the case, my system would still
 have useful settings in /etc/resolv.conf.  As it is, I essentially end up with
 a null /etc/resolv.conf .  Observe:
 
 # cat /etc/resolv.conf
 search ph.cox.net
 nameserver 68.6.19.237
 nameserver 68.1.17.237
 # /sbin/dhclient de0
 dhclient: New IP Address(de0): 68.xxx.xxx.xxx
 dhclient: New Subnet Mask (de0): 255.255.254.0
 dhclient: New Broadcast Address(de0): 68.xxx.xxx.255
 dhclient: New Routers: 68.xxx.xxx.1
 # cat /etc/resolv.conf
 search
 # cat /etc/dhclient.conf
 interface "de0" {
 	send host-name "nikita";
 	request subnet-mask,
 		broadcast-address,
 		routers;
 }
 # 
 
 I have a hard time believing this to be desired behavior, but I guess that's
 what you are telling me.
 
 Thanks for your time,
 Brian

From: "brian j. peterson" <rbw@myplace.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc: obrien@freebsd.org
Subject: Re: misc/34455: [PATCH] /sbin/dhclient-script overwrites /etc/resolv.conf without any relevant information
Date: Thu, 31 Jan 2002 11:08:20 -0700

 By the way, the ISC has already implemented a patch similar to my own
 in their DHCP Version 3.0.1rc6.  Observe:
 
 --- FreeBSD's src/contrib/isc-dhcp/client/scripts/freebsd,v 1.9.2.4
     before my patch:
 # grep -A 5 -e "make_resolv_conf() {" /sbin/dhclient-script_1.9.2.4
 make_resolv_conf() {
   echo search $new_domain_name >/etc/resolv.conf
   for nameserver in $new_domain_name_servers; do
     echo nameserver $nameserver >>/etc/resolv.conf
   done
 }
 # 
 
 --- FreeBSD's src/contrib/isc-dhcp/client/scripts/freebsd,v 1.9.2.4
     after my patch:
 # grep -A 7 -e "make_resolv_conf() {" /sbin/dhclient-script_new
 make_resolv_conf() {
   if [ x$new_domain_name != x ]; then
     echo search $new_domain_name >/etc/resolv.conf
     for nameserver in $new_domain_name_servers; do
       echo nameserver $nameserver >>/etc/resolv.conf
     done
   fi
 }
 # 
 
 --- ISC's dhcp-3.0.1rc6/client/scripts/freebsd
     from ftp://ftp.isc.org/isc/dhcp/dhcp-3.0.1rc6.tar.gz:
 # grep -A 7 -e "make_resolv_conf() {" dhcp-3.0.1rc6/client/scripts/freebsd 
 make_resolv_conf() {
   if [ "x$new_domain_name" != x ] && [ x"$new_domain_name_servers" != x ]; then
     echo search $new_domain_name >/etc/resolv.conf
     for nameserver in $new_domain_name_servers; do
       echo nameserver $nameserver >>/etc/resolv.conf
     done
   fi
 }
 # 
 
 Their patch is more robust than mine (it ensures that the DHCP server is
 providing BOTH a domain-name and domain-name-servers before writing to
 /etc/resolv.conf), so perhaps you will prefer to use their code.
 
 Thanks again for your time,
 Brian

From: "David O'Brien" <obrien@freebsd.org>
To: "brian j. peterson" <rbw@myplace.org>
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: misc/34455: [PATCH] /sbin/dhclient-script overwrites /etc/resolv.conf without any relevant information
Date: Thu, 31 Jan 2002 11:10:59 -0800

 On Thu, Jan 31, 2002 at 10:32:23AM -0700, brian j. peterson wrote:
 > I have a hard time believing this to be desired behavior, but I guess that's
 > what you are telling me.
 
 Take it up with the ISC people.
  
 -- 
 -- David  (obrien@FreeBSD.org)
>Unformatted:
