resolvconf.in (302408) | resolvconf.in (304515) |
---|---|
1#!/bin/sh 2# Copyright (c) 2007-2016 Roy Marples 3# All rights reserved 4 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions 7# are met: 8# * Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 27RESOLVCONF="$0" | 1#!/bin/sh 2# Copyright (c) 2007-2016 Roy Marples 3# All rights reserved 4 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions 7# are met: 8# * Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 27RESOLVCONF="$0" |
28OPENRESOLV_VERSION="3.8.1" |
|
28SYSCONFDIR=@SYSCONFDIR@ 29LIBEXECDIR=@LIBEXECDIR@ 30VARDIR=@VARDIR@ | 29SYSCONFDIR=@SYSCONFDIR@ 30LIBEXECDIR=@LIBEXECDIR@ 31VARDIR=@VARDIR@ |
32RCDIR=@RCDIR@ 33RESTARTCMD=@RESTARTCMD@ |
|
31 32# Disregard dhcpcd setting 33unset interface_order state_dir 34 35# If you change this, change the test in VFLAG and libc.in as well 36local_nameservers="127.* 0.0.0.0 255.255.255.255 ::1" 37 38dynamic_order="tap[0-9]* tun[0-9]* vpn vpn[0-9]* ppp[0-9]* ippp[0-9]*" --- 27 unchanged lines hidden (view full) --- 66{ 67 echo "$*" >&2 68 exit 1 69} 70 71usage() 72{ 73 cat <<-EOF | 34 35# Disregard dhcpcd setting 36unset interface_order state_dir 37 38# If you change this, change the test in VFLAG and libc.in as well 39local_nameservers="127.* 0.0.0.0 255.255.255.255 ::1" 40 41dynamic_order="tap[0-9]* tun[0-9]* vpn vpn[0-9]* ppp[0-9]* ippp[0-9]*" --- 27 unchanged lines hidden (view full) --- 69{ 70 echo "$*" >&2 71 exit 1 72} 73 74usage() 75{ 76 cat <<-EOF |
74 Usage: ${RESOLVCONF##*/} [options] | 77 Usage: ${RESOLVCONF##*/} [options] command [argument] |
75 76 Inform the system about any DNS updates. 77 | 78 79 Inform the system about any DNS updates. 80 |
78 Options: | 81 Commands: |
79 -a \$INTERFACE Add DNS information to the specified interface 80 (DNS supplied via stdin in resolv.conf format) | 82 -a \$INTERFACE Add DNS information to the specified interface 83 (DNS supplied via stdin in resolv.conf format) |
81 -m metric Give the added DNS information a metric 82 -p Mark the interface as private 83 -x Mark the interface as exclusive | |
84 -d \$INTERFACE Delete DNS information from the specified interface | 84 -d \$INTERFACE Delete DNS information from the specified interface |
85 -f Ignore non existant interfaces 86 -I Init the state dir 87 -u Run updates from our current DNS information 88 -l [\$PATTERN] Show DNS information, optionally from interfaces 89 that match the specified pattern | 85 -h Show this help cruft |
90 -i [\$PATTERN] Show interfaces that have supplied DNS information 91 optionally from interfaces that match the specified 92 pattern | 86 -i [\$PATTERN] Show interfaces that have supplied DNS information 87 optionally from interfaces that match the specified 88 pattern |
89 -l [\$PATTERN] Show DNS information, optionally from interfaces 90 that match the specified pattern 91 92 -u Run updates from our current DNS information 93 94 Options: 95 -f Ignore non existent interfaces 96 -m metric Give the added DNS information a metric 97 -p Mark the interface as private 98 -x Mark the interface as exclusive 99 100 Subscriber and System Init Commands: 101 -I Init the state dir 102 -r \$SERVICE Restart the system service 103 (restarting a non-existent or non-running service 104 should have no output and return 0) 105 -R Show the system service restart command |
|
93 -v [\$PATTERN] echo NEWDOMAIN, NEWSEARCH and NEWNS variables to 94 the console | 106 -v [\$PATTERN] echo NEWDOMAIN, NEWSEARCH and NEWNS variables to 107 the console |
95 -h Show this help cruft | 108 -V [\$PATTERN] Same as -v, but only uses configuration in 109 $SYSCONFDIR/resolvconf.conf |
96 EOF 97 [ -z "$1" ] && exit 0 98 echo 99 error_exit "$*" 100} 101 | 110 EOF 111 [ -z "$1" ] && exit 0 112 echo 113 error_exit "$*" 114} 115 |
102echo_resolv() 103{ 104 local line= OIFS="$IFS" 105 106 [ -n "$1" -a -f "$IFACEDIR/$1" ] || return 1 107 echo "# resolv.conf from $1" 108 # Our variable maker works of the fact each resolv.conf per interface 109 # is separated by blank lines. 110 # So we remove them when echoing them. 111 while read -r line; do 112 IFS="$OIFS" 113 if [ -n "$line" ]; then 114 # We need to set IFS here to preserve any whitespace 115 IFS='' 116 printf "%s\n" "$line" 117 fi 118 done < "$IFACEDIR/$1" 119 echo 120 IFS="$OIFS" 121} 122 | |
123# Strip any trailing dot from each name as a FQDN does not belong 124# in resolv.conf(5) 125# If you think otherwise, capture a DNS trace and you'll see libc 126# will strip it regardless. 127# This also solves setting up duplicate zones in our subscribers. 128strip_trailing_dots() 129{ 130 local n= d= --- 23 unchanged lines hidden (view full) --- 154 if [ -e "$PRIVATEDIR/$iface" ]; then 155 private=true 156 else 157 # Allow expansion 158 cd "$IFACEDIR" 159 private=false 160 for p in $private_interfaces; do 161 case "$iface" in | 116# Strip any trailing dot from each name as a FQDN does not belong 117# in resolv.conf(5) 118# If you think otherwise, capture a DNS trace and you'll see libc 119# will strip it regardless. 120# This also solves setting up duplicate zones in our subscribers. 121strip_trailing_dots() 122{ 123 local n= d= --- 23 unchanged lines hidden (view full) --- 147 if [ -e "$PRIVATEDIR/$iface" ]; then 148 private=true 149 else 150 # Allow expansion 151 cd "$IFACEDIR" 152 private=false 153 for p in $private_interfaces; do 154 case "$iface" in |
162 "$p"|"$p":*) private=true; break;; | 155 "$p"|"$p":*) 156 private=true 157 break 158 ;; |
163 esac 164 done 165 fi 166 fi 167 ;; 168 "nameserver "*) 169 islocal=false 170 for l in $local_nameservers; do --- 85 unchanged lines hidden (view full) --- 256 else 257 mkdir "$d" || e=$? 258 fi 259 fi 260 done 261 return $e 262} 263 | 159 esac 160 done 161 fi 162 fi 163 ;; 164 "nameserver "*) 165 islocal=false 166 for l in $local_nameservers; do --- 85 unchanged lines hidden (view full) --- 252 else 253 mkdir "$d" || e=$? 254 fi 255 fi 256 done 257 return $e 258} 259 |
260# With the advent of alternative init systems, it's possible to have 261# more than one installed. So we need to try and guess what one we're 262# using unless overriden by configure. 263# Note that restarting a service is a last resort - the subscribers 264# should make a reasonable attempt to reconfigre the service via some 265# method, normally SIGHUP. 266detect_init() 267{ 268 [ -n "$RESTARTCMD" ] && return 0 269 270 # Detect the running init system. 271 # As systemd and OpenRC can be installed on top of legacy init 272 # systems we try to detect them first. 273 local status="@STATUSARG@" 274 : ${status:=status} 275 if [ -x /bin/systemctl -a -S /run/systemd/private ]; then 276 RESTARTCMD="if /bin/systemctl --quiet is-active \$1.service; then 277 /bin/systemctl restart \$1.service; 278fi" 279 elif [ -x /usr/bin/systemctl -a -S /run/systemd/private ]; then 280 RESTARTCMD="if /usr/bin/systemctl --quiet is-active \$1.service; then 281 /usr/bin/systemctl restart \$1.service; 282fi" 283 elif [ -x /sbin/rc-service -a \ 284 -s /libexec/rc/init.d/softlevel -o -s /run/openrc/softlevel ] 285 then 286 RESTARTCMD="/sbin/rc-service -i \$1 -- -Ds restart" 287 elif [ -x /usr/sbin/invoke-rc.d ]; then 288 RCDIR=/etc/init.d 289 RESTARTCMD="if /usr/sbin/invoke-rc.d --quiet \$1 status 1>/dev/null 2>&1; then 290 /usr/sbin/invoke-rc.d \$1 restart; 291fi" 292 elif [ -x /sbin/service ]; then 293 # Old RedHat 294 RCDIR=/etc/init.d 295 RESTARTCMD="if /sbin/service \$1; then 296 /sbin/service \$1 restart; 297fi" 298 elif [ -x /usr/sbin/service ]; then 299 # Could be FreeBSD 300 RESTARTCMD="if /usr/sbin/service \$1 $status 1>/dev/null 2>&1; then 301 /usr/sbin/service \$1 restart; 302fi" 303 elif [ -x /bin/sv ]; then 304 RESTARTCMD="/bin/sv try-restart \$1" 305 elif [ -x /usr/bin/sv ]; then 306 RESTARTCMD="/usr/bin/sv try-restart \$1" 307 elif [ -e /etc/arch-release -a -d /etc/rc.d ]; then 308 RCDIR=/etc/rc.d 309 RESTARTCMD="if [ -e /var/run/daemons/\$1 ]; then 310 /etc/rc.d/\$1 restart; 311fi" 312 elif [ -e /etc/slackware-version -a -d /etc/rc.d ]; then 313 RESTARTCMD="if /etc/rc.d/rc.\$1 status 1>/dev/null 2>&1; then 314 /etc/rc.d/rc.\$1 restart; 315fi" 316 elif [ -e /etc/rc.d/rc.subr -a -d /etc/rc.d ]; then 317 # OpenBSD 318 RESTARTCMD="if /etc/rc.d/\$1 check 1>/dev/null 2>&1; then 319 /etc/rc.d/\$1 restart; 320fi" 321 else 322 for x in /etc/init.d/rc.d /etc/rc.d /etc/init.d; do 323 [ -d $x ] || continue 324 RESTARTCMD="if $x/\$1 $status 1>/dev/null 2>&1; then 325 $x/\$1 restart; 326fi" 327 break 328 done 329 fi 330 331 if [ -z "$RESTARTCMD" ]; then 332 if [ "$NOINIT_WARNED" != true ]; then 333 warn "could not detect a useable init system" 334 _NOINIT_WARNED=true 335 fi 336 return 1 337 fi 338 _NOINIT_WARNED= 339 return 0 340} 341 342echo_resolv() 343{ 344 local line= OIFS="$IFS" 345 346 [ -n "$1" -a -f "$IFACEDIR/$1" ] || return 1 347 echo "# resolv.conf from $1" 348 # Our variable maker works of the fact each resolv.conf per interface 349 # is separated by blank lines. 350 # So we remove them when echoing them. 351 while read -r line; do 352 IFS="$OIFS" 353 if [ -n "$line" ]; then 354 # We need to set IFS here to preserve any whitespace 355 IFS='' 356 printf "%s\n" "$line" 357 fi 358 done < "$IFACEDIR/$1" 359 IFS="$OIFS" 360} 361 |
|
264list_resolv() 265{ 266 [ -d "$IFACEDIR" ] || return 0 267 268 local report=false list= retval=0 cmd="$1" excl= 269 shift 270 271 case "$IF_EXCLUSIVE" in --- 43 unchanged lines hidden (view full) --- 315 [ -f "$i" ] && list="$list ${i#* }" 316 done 317 fi 318 list="$list *" 319 fi 320 321 cd "$IFACEDIR" 322 retval=1 | 362list_resolv() 363{ 364 [ -d "$IFACEDIR" ] || return 0 365 366 local report=false list= retval=0 cmd="$1" excl= 367 shift 368 369 case "$IF_EXCLUSIVE" in --- 43 unchanged lines hidden (view full) --- 413 [ -f "$i" ] && list="$list ${i#* }" 414 done 415 fi 416 list="$list *" 417 fi 418 419 cd "$IFACEDIR" 420 retval=1 |
421 excl=true |
|
323 for i in $(uniqify $list); do 324 # Only list interfaces which we really have 325 if ! [ -f "$i" ]; then 326 if $report; then 327 echo "No resolv.conf for interface $i" >&2 328 retval=2 329 fi 330 continue 331 fi 332 333 if [ "$cmd" = i -o "$cmd" = "-i" ]; then 334 printf %s "$i " 335 else 336 echo_resolv "$i" | 422 for i in $(uniqify $list); do 423 # Only list interfaces which we really have 424 if ! [ -f "$i" ]; then 425 if $report; then 426 echo "No resolv.conf for interface $i" >&2 427 retval=2 428 fi 429 continue 430 fi 431 432 if [ "$cmd" = i -o "$cmd" = "-i" ]; then 433 printf %s "$i " 434 else 435 echo_resolv "$i" |
436 echo |
|
337 fi 338 [ $? = 0 -a "$retval" = 1 ] && retval=0 339 done 340 [ "$cmd" = i -o "$cmd" = "-i" ] && echo 341 return $retval 342} 343 344list_remove() { --- 149 unchanged lines hidden (view full) --- 494 echo "SEARCH='$SEARCH'" 495 echo "NAMESERVERS='$NAMESERVERS'" 496 echo "LOCALNAMESERVERS='$LOCALNAMESERVERS'" 497 echo "DOMAINS='$newdomains'" 498} 499 500force=false 501VFLAG= | 437 fi 438 [ $? = 0 -a "$retval" = 1 ] && retval=0 439 done 440 [ "$cmd" = i -o "$cmd" = "-i" ] && echo 441 return $retval 442} 443 444list_remove() { --- 149 unchanged lines hidden (view full) --- 594 echo "SEARCH='$SEARCH'" 595 echo "NAMESERVERS='$NAMESERVERS'" 596 echo "LOCALNAMESERVERS='$LOCALNAMESERVERS'" 597 echo "DOMAINS='$newdomains'" 598} 599 600force=false 601VFLAG= |
502while getopts a:Dd:fhIilm:puvVx OPT; do | 602while getopts a:Dd:fhIilm:pRruvVx OPT; do |
503 case "$OPT" in 504 f) force=true;; 505 h) usage;; 506 m) IF_METRIC="$OPTARG";; 507 p) IF_PRIVATE=1;; 508 V) 509 VFLAG=1 510 if [ "$local_nameservers" = \ --- 25 unchanged lines hidden (view full) --- 536fi 537 538# -l lists our resolv files, optionally for a specific interface 539if [ "$cmd" = l -o "$cmd" = i ]; then 540 list_resolv "$cmd" "$args" 541 exit $? 542fi 543 | 603 case "$OPT" in 604 f) force=true;; 605 h) usage;; 606 m) IF_METRIC="$OPTARG";; 607 p) IF_PRIVATE=1;; 608 V) 609 VFLAG=1 610 if [ "$local_nameservers" = \ --- 25 unchanged lines hidden (view full) --- 636fi 637 638# -l lists our resolv files, optionally for a specific interface 639if [ "$cmd" = l -o "$cmd" = i ]; then 640 list_resolv "$cmd" "$args" 641 exit $? 642fi 643 |
644# Restart a service or echo the command to restart a service 645if [ "$cmd" = r -o "$cmd" = R ]; then 646 detect_init || exit 1 647 if [ "$cmd" = r ]; then 648 set -- $args 649 eval $RESTARTCMD 650 else 651 echo "$RESTARTCMD" 652 fi 653 exit $? 654fi 655 |
|
544# Not normally needed, but subscribers should be able to run independently 545if [ "$cmd" = v -o -n "$VFLAG" ]; then 546 make_vars "$iface" 547 exit $? 548fi 549 550# Test that we have valid options 551if [ "$cmd" = a -o "$cmd" = d ]; then --- 208 unchanged lines hidden (view full) --- 760 ;; 761esac 762 763case "${resolvconf:-YES}" in 764[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) ;; 765*) exit 0;; 766esac 767 | 656# Not normally needed, but subscribers should be able to run independently 657if [ "$cmd" = v -o -n "$VFLAG" ]; then 658 make_vars "$iface" 659 exit $? 660fi 661 662# Test that we have valid options 663if [ "$cmd" = a -o "$cmd" = d ]; then --- 208 unchanged lines hidden (view full) --- 872 ;; 873esac 874 875case "${resolvconf:-YES}" in 876[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) ;; 877*) exit 0;; 878esac 879 |
880# Try and detect a suitable init system for our scripts 881detect_init 882export RESTARTCMD RCDIR _NOINIT_WARNED 883 |
|
768eval "$(make_vars)" 769export RESOLVCONF DOMAINS SEARCH NAMESERVERS LOCALNAMESERVERS 770: ${list_resolv:=list_resolv -l} 771retval=0 772 773# Run scripts in the same directory resolvconf is run from | 884eval "$(make_vars)" 885export RESOLVCONF DOMAINS SEARCH NAMESERVERS LOCALNAMESERVERS 886: ${list_resolv:=list_resolv -l} 887retval=0 888 889# Run scripts in the same directory resolvconf is run from |
774# in case any scripts accidently dump files in the wrong place. | 890# in case any scripts accidentally dump files in the wrong place. |
775cd "$_PWD" 776for script in "$LIBEXECDIR"/*; do 777 if [ -f "$script" ]; then 778 eval script_enabled="\$${script##*/}" 779 case "${script_enabled:-YES}" in 780 [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) ;; 781 *) continue;; 782 esac 783 if [ -x "$script" ]; then 784 "$script" "$cmd" "$iface" 785 else 786 (set -- "$cmd" "$iface"; . "$script") 787 fi 788 retval=$(($retval + $?)) 789 fi 790done 791exit $retval | 891cd "$_PWD" 892for script in "$LIBEXECDIR"/*; do 893 if [ -f "$script" ]; then 894 eval script_enabled="\$${script##*/}" 895 case "${script_enabled:-YES}" in 896 [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) ;; 897 *) continue;; 898 esac 899 if [ -x "$script" ]; then 900 "$script" "$cmd" "$iface" 901 else 902 (set -- "$cmd" "$iface"; . "$script") 903 fi 904 retval=$(($retval + $?)) 905 fi 906done 907exit $retval |