/sbin/resolvconf is in resolvconf 1.79.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | #!/bin/sh
#
# This file is part of the resolvconf package.
#
set -e
echo_usage() { echo "Usage: resolvconf (-d IFACE|-a IFACE|-u|--enable-updates|--disable-updates|--updates-are-enabled)" ; }
PATH=/sbin:/bin
MYNAME="${0##*/}"
# Note that /etc/resolvconf/run may be (and generally is) a symlink
RUN_DIR=/etc/resolvconf/run
ENABLE_UPDATES_FLAGFILE="${RUN_DIR}/enable-updates"
POSTPONED_UPDATE_FLAGFILE="${RUN_DIR}/postponed-update"
report_err() { echo "${MYNAME}: Error: $*" >&2 ; }
# Check arguments
CMD="$1"
case "$CMD" in
-a|-d)
IFACE="$2"
if [ ! "$IFACE" ] ; then
report_err "No interface name specified"
echo_usage >&2
exit 1
fi
report_iface_err() {
report_err "$* not allowed in interface record name"
}
case "$IFACE" in
*/*) report_iface_err "Slash" ; exit 1 ;;
*" "*) report_iface_err "Space" ; exit 1 ;;
.*) report_iface_err "Initial dot" ; exit 1 ;;
-*) report_iface_err "Initial hyphen" ; exit 1 ;;
~*) report_iface_err "Initial tilde" ; exit 1 ;;
esac
;;
-u|--enable-updates|--disable-updates|--updates-are-enabled)
if [ "$2" ] ; then
report_err "The $CMD option does not take an argument"
echo_usage >&2
exit 1
fi
;;
*)
report_err "Command not recognized"
echo_usage >&2
exit 99
;;
esac
[ -d "${RUN_DIR}/interface" ] || { mkdir -p "${RUN_DIR}/interface" ; }
[ -d "${RUN_DIR}/interface" ] || { report_err "${RUN_DIR}/interface either does not exist or is not a directory" ; exit 1 ; }
cd "${RUN_DIR}/interface"
update_and_exit()
{
rm -f "$POSTPONED_UPDATE_FLAGFILE"
exec run-parts ${1:+--arg="$1"} ${2:+--arg="$2"} /etc/resolvconf/update.d
}
# Handle commands that don't require normalized_stdin()
case "$CMD" in
-d)
if [ ! -e "$IFACE" ] ; then
exit 0
fi
if [ ! -s "$IFACE" ] ; then
rm -f "$IFACE"
exit 0
fi
rm -f "$IFACE"
if [ -e "$ENABLE_UPDATES_FLAGFILE" ] ; then
update_and_exit -d "$IFACE"
else
: >| "$POSTPONED_UPDATE_FLAGFILE"
exit 0
fi
;;
-u)
if [ -e "$ENABLE_UPDATES_FLAGFILE" ] ; then
update_and_exit -u
else
: >| "$POSTPONED_UPDATE_FLAGFILE"
exit 0
fi
;;
--enable-updates)
: >| "$ENABLE_UPDATES_FLAGFILE" || exit 1
if [ -e "$POSTPONED_UPDATE_FLAGFILE" ] ; then
(update_and_exit -u) || :
fi
exit 0
;;
--disable-updates)
rm -f "$POSTPONED_UPDATE_FLAGFILE" || :
rm -f "$ENABLE_UPDATES_FLAGFILE" || exit 1
exit 0
;;
--updates-are-enabled)
if [ -e "$ENABLE_UPDATES_FLAGFILE" ] ; then
exit 0
else
exit 1
fi
;;
esac
#
# The following function must EXACTLY the same in the resolvconf
# and test-normalization scripts. And the test must pass!
#
### BEGIN FUNCTION TO COPY TO THE test-normalization SCRIPT ###
#
# Echo stdin with:
# comments removed;
# initial and terminal whitespace removed;
# whitespace strings replaced by single blanks;
# leading zeroes removed from nameserver address fields;
# first set of zero fields in an IPv6 address collapsed to '::';
# empty lines removed.
normalized_stdin() {
sed \
-e 's/#.*$//' \
-e 's/[[:blank:]]\+$//' \
-e 's/^[[:blank:]]\+//' \
-e 's/[[:blank:]]\+/ /g' \
-e '/^nameserver/!b ENDOFCYCLE' \
-e 's/$/ /' \
-e 's/\([:. ]\)0\+/\10/g' \
-e 's/\([:. ]\)0\([123456789abcdefABCDEF][[:xdigit:]]*\)/\1\2/g' \
-e '/::/b ENDOFCYCLE; s/ \(0[: ]\)\+/ ::/' \
-e '/::/b ENDOFCYCLE; s/:\(0[: ]\)\+/::/' \
-e ': ENDOFCYCLE' \
- | \
sed \
-e 's/[[:blank:]]\+$//' \
-e '/^$/d'
}
### END FUNCTION TO COPY TO THE test-normalization SCRIPT ###
case "$CMD" in
-a)
OLD_CONTENT=""
[ -f "$IFACE" ] && OLD_CONTENT="$(cat "$IFACE")"
NEW_CONTENT="$(normalized_stdin)"
# Proceed only if content has changed. The test here can't
# eliminate 100% of redundant invocations of update scripts
# because we don't do any locking; however it certainly does
# eliminate most of them.
if [ "$NEW_CONTENT" = "$OLD_CONTENT" ] ; then
exit 0
fi
IFACE_TMPFILE="${IFACE}_new.$$"
cleanup() { rm -f "$IFACE_TMPFILE" ; }
trap cleanup EXIT
echo "$NEW_CONTENT" > "$IFACE_TMPFILE"
mv -f "$IFACE_TMPFILE" "$IFACE"
if [ -e "$ENABLE_UPDATES_FLAGFILE" ] ; then
update_and_exit -a "$IFACE"
else
: >| "$POSTPONED_UPDATE_FLAGFILE"
exit 0
fi
;;
esac
# Don't reach here
exit 99
|