SHA256
1
0
forked from pool/dhcp
dhcp/dhcp-3.0b2pl24.resolv.conf.dif

162 lines
5.4 KiB
Plaintext

--- dhcp-3.0.1rc9/client/scripts/linux.orig Fri Apr 26 22:30:46 2002
+++ dhcp-3.0.1rc9/client/scripts/linux Tue May 21 18:37:25 2002
@@ -22,14 +22,101 @@
# 4. TIMEOUT not tested. ping has a flag I don't know, and I'm suspicious
# of the $1 in its args.
+
+# Debugging:
+#
+# logs entire run of dhclient-script to /var/log/dhclient-script,
+# if DHCLIENT_DEBUG is set in sysconfig/network/dhcp
+#
+eval `grep "^DHCLIENT_DEBUG=" /etc/sysconfig/network/dhcp`
+if [ "$DHCLIENT_DEBUG" = yes ]; then
+ set -a # allexport
+ (
+ echo '****************'
+ echo "$0 $*"
+ date
+ echo '----------------'
+ set
+ echo '----------------'
+ ) >> /var/log/dhclient-script
+ exec 2>> /var/log/dhclient-script
+ set +a
+ set -x
+fi
+
make_resolv_conf() {
- if [ "x$new_domain_name" != x ] && [ x"$new_domain_name_servers" != x ]; then
- echo search $new_domain_name >/etc/resolv.conf
- chmod 644 /etc/resolv.conf
- for nameserver in $new_domain_name_servers; do
- echo nameserver $nameserver >>/etc/resolv.conf
- done
+ # first, look if we are allowed to modify resolv.conf:
+ eval `grep "^MODIFY_RESOLV_CONF_DYNAMICALLY=" /etc/sysconfig/network/config`
+ eval `grep "^DHCLIENT_MODIFY_RESOLV_CONF=" /etc/sysconfig/network/dhcp`
+
+ test "$MODIFY_RESOLV_CONF_DYNAMICALLY" = no \
+ -o "$DHCLIENT_MODIFY_RESOLV_CONF" = no \
+ && return
+
+ # It might be useful to have more than one domain in the searchlist. To
+ # achieve this set DHCLIENT_KEEP_SEARCHLIST in /etc/sysconfig/network/dhcp to "yes"
+ # and put the additional domains in the searchlist of the *unmodified*
+ # /etc/resolv.conf. When the client is configured via DHCP the old
+ # searchlist will be appended to the new one.
+ oldsearchlist=""
+ eval `grep "^DHCLIENT_KEEP_SEARCHLIST=" /etc/sysconfig/network/dhcp`
+ if test "$DHCLIENT_KEEP_SEARCHLIST" = yes ; then
+ oldsearchlist=`while read line; do
+ case $line in search*) oldsearchlist=${line/search /};; esac;
+ done< /etc/resolv.conf;
+ echo -n $oldsearchlist`
fi
+
+
+
+ # now, backup the existing resolv.conf first. BUT:
+ # an old backup copy should not be there, because the init script deletes them; if there
+ # is one, it must be current and we don't want to overwrite it
+ # (since this script is called by dhclient more than once)
+ if ! test -f /etc/resolv.conf.saved.by.dhclient ; then
+ mv /etc/resolv.conf /etc/resolv.conf.saved.by.dhclient &> /dev/null
+ fi
+
+ # put a comment into the new file
+ # FIXME: in theory we should use /sbin/modify_resolvconf for the modifications
+ # instead of fiddling around with it ourselves.
+ write_informational_resolv_conf_header
+
+ echo search $new_domain_name $oldsearchlist >>/etc/resolv.conf
+ chmod 644 /etc/resolv.conf
+ for nameserver in $new_domain_name_servers; do
+ echo nameserver $nameserver >>/etc/resolv.conf
+ done
+}
+
+function write_informational_resolv_conf_header() {
+ cat > /etc/resolv.conf << EOF
+### BEGIN INFO
+#
+# Modified_by: dhclient
+# Backup: /etc/resolv.conf.saved.by.dhclient
+# Process: /sbin/dhclient
+# Process_id: $(pidof dhclient)
+# Script: /sbin/dhclient-script
+#
+# Info: This is a temporary resolv.conf created by dhclient.
+# A previous resolv.conf has been saved as
+# /etc/resolv.conf.saved.by.dhclient and will be
+# restored when dhclient is stopped.
+#
+# If you don't like dhclient to change your nameserver
+# settings, set DHCLIENT_MODIFY_RESOLV_CONF in
+# /etc/sysconfig/network/dhcp to "no", or set
+# MODIFY_RESOLV_CONF_DYNAMICALLY in /etc/sysconfig/network/config
+# to "no".
+# You can also customize /etc/dhclient.conf (man 5 dhclient.conf)
+# using the supersede and/or prepend option.
+### END INFO
+
+EOF
+
+# Make sure that the file is world readable even if umask is set to e.g. 077
+
}
# Must be used on exit. Invokes the local dhcp client exit hooks, if any.
@@ -106,15 +193,6 @@
if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
[ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
- current_hostname=`hostname`
- if [ x$current_hostname = x ] || \
- [ x$current_hostname = x$old_host_name ]; then
- if [ x$current_hostname = x ] || \
- [ x$new_host_name != x$old_host_name ]; then
- hostname $new_host_name
- fi
- fi
-
if [ x$old_ip_address != x ] && [ x$alias_ip_address != x ] && \
[ x$alias_ip_address != x$old_ip_address ]; then
# Possible new alias. Remove old alias.
@@ -147,6 +225,24 @@
route add -host $alias_ip_address $interface:0
fi
make_resolv_conf
+ eval `grep --no-filename "^DHCLIENT_SET_HOSTNAME=" /etc/sysconfig/network/dhcp`
+ if [ "$DHCLIENT_SET_HOSTNAME" = yes ] ; then
+
+ current_hostname=`hostname`
+ if [ x$current_hostname = x ] || \
+ [ x$current_hostname != x$new_host_name ]; then
+
+ if [ x$new_host_name != x ]; then
+ hostname $new_host_name
+ else
+ if [ -x /usr/bin/host ] ; then
+ hostname `host "$new_ip_address" | sed 's:^.* ::; s:\..*::'`
+ fi
+ fi
+
+ fi
+
+ fi
exit_with_hooks 0
fi
@@ -195,4 +291,9 @@
exit_with_hooks 1
fi
+# restore backup copy of resolv.conf
+if test -f /etc/resolv.conf.saved.by.dhclient ; then
+ mv /etc/resolv.conf.saved.by.dhclient /etc/resolv.conf
+fi
+
exit_with_hooks 0