11#! /bin/sh
2- # Copyright (c) 2007-2023 Roy Marples
2+ # Copyright (c) 2007-2025 Roy Marples
33# All rights reserved
44
55# Redistribution and use in source and binary forms, with or without
2525# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626
2727RESOLVCONF=" $0 "
28- OPENRESOLV_VERSION=" 3.13.2 "
28+ OPENRESOLV_VERSION=" 3.14.0 "
2929SYSCONFDIR=@SYSCONFDIR@
3030LIBEXECDIR=@LIBEXECDIR@
3131VARDIR=@VARDIR@
@@ -34,7 +34,7 @@ RESTARTCMD=@RESTARTCMD@
3434
3535if [ " $1 " = " --version" ]; then
3636 echo " openresolv $OPENRESOLV_VERSION "
37- echo " Copyright (c) 2007-2020 Roy Marples"
37+ echo " Copyright (c) 2007-2025 Roy Marples"
3838 exit 0
3939fi
4040
@@ -48,6 +48,27 @@ dynamic_order="tap[0-9]* tun[0-9]* vpn vpn[0-9]* wg[0-9]* ppp[0-9]* ippp[0-9]*"
4848interface_order=" lo lo[0-9]*"
4949name_server_blacklist=" 0.0.0.0"
5050
51+ # Poor mans cat
52+ # /usr might not be available
53+ cat ()
54+ {
55+ OIFS=" $IFS "
56+ IFS=' '
57+ if [ -n " $1 " ]; then
58+ while read -r line; do
59+ printf " %s\n" " $line "
60+ done < " $1 "
61+ else
62+ while read -r line; do
63+ printf " %s\n" " $line "
64+ done
65+ fi
66+ retval=$?
67+ IFS=" $OIFS "
68+ return $retval
69+ }
70+
71+
5172# Support original resolvconf configuration layout
5273# as well as the openresolv config file
5374if [ -f " $SYSCONFDIR " /resolvconf.conf ]; then
@@ -98,6 +119,7 @@ usage()
98119 pattern
99120 -l [\$ PATTERN] Show DNS information, optionally from interfaces
100121 that match the specified pattern
122+ -L [\$ PATTERN] Same as -l, but adjusted by our config
101123
102124 -u Run updates from our current DNS information
103125 --version Echo the ${RESOLVCONF##*/ } version
@@ -434,12 +456,68 @@ deprecated_interface()
434456 return 1
435457}
436458
459+ match ()
460+ {
461+ match=" $1 "
462+ file=" $2 "
463+ retval=1
464+ count=0
465+
466+ while read -r keyword value; do
467+ new_match=
468+ for om in $match ; do
469+ m=" $om "
470+ keep=
471+ while [ -n " $m " ]; do
472+ k=" ${m%%/* } "
473+ r=" ${m#*/ } "
474+ f=" ${r%%/* } "
475+ r=" ${r#*/ } "
476+ # If the length of m is the same as k/f then
477+ # we know that we are done
478+ if [ ${# m} = $(( ${# k} + 1 + ${# f} )) ]; then
479+ r=
480+ fi
481+ m=" $r "
482+ matched=false
483+ case " $keyword " in
484+ $k )
485+ case " $value " in
486+ $f )
487+ matched=true
488+ ;;
489+ esac
490+ ;;
491+ esac
492+ if ! $matched ; then
493+ keep=" $keep ${keep: +/ } $k /$f "
494+ fi
495+ done
496+ if [ -n " $om " ] && [ -z " $keep " ]; then
497+ retval=0
498+ break 2
499+ fi
500+ new_match=" ${new_match}${new_match: + }${keep} "
501+ done
502+ match=" ${new_match} "
503+ done < " $file "
504+ return $retval
505+ }
506+
437507list_resolv ()
438508{
439509 [ -d " $IFACEDIR " ] || return 0
440510
441- cmd=" $1 "
442- shift
511+ OPTIND=
512+ list_cmd=
513+ while getopts iLl OPT; do
514+ case " $OPT " in
515+ ' ?' ) exit 1;;
516+ * ) list_cmd=" $OPT " ;;
517+ esac
518+ done
519+ shift $(( $OPTIND - 1 ))
520+
443521 pattern_specified=" $1 "
444522
445523 excl=false
@@ -540,7 +618,7 @@ list_resolv()
540618 continue
541619 fi
542620
543- if ! $ALLIFACES ; then
621+ if [ " $list_cmd " = L ] ; then
544622 if [ -n " $allow_interfaces " ]; then
545623 x=false
546624 for j in $allow_interfaces ; do
@@ -555,16 +633,20 @@ list_resolv()
555633 continue 2
556634 fi
557635 done
636+
637+ if [ -n " $exclude " ] && match " $exclude " " $i " ; then
638+ continue
639+ fi
558640 fi
559641
560- if [ " $cmd " = i ] || [ " $cmd " = " -i " ]; then
642+ if [ " $list_cmd " = i ]; then
561643 printf %s " $i "
562644 else
563645 echo_resolv " $i " && echo
564646 fi
565647 [ $? = 0 ] && [ " $retval " = 1 ] && retval=0
566648 done
567- [ " $cmd " = i ] || [ " $cmd " = " -i " ] && echo
649+ [ " $list_cmd " = i ] && echo
568650 return $retval
569651}
570652
@@ -674,7 +756,7 @@ make_vars()
674756 if [ -z " $VFLAG " ]; then
675757 IF_EXCLUSIVE=1
676758 list_resolv -i " $@ " > /dev/null || IF_EXCLUSIVE=0
677- eval " $( list_resolv -l " $@ " | replace | parse_resolv) "
759+ eval " $( list_resolv -L " $@ " | replace | parse_resolv) "
678760 fi
679761 if [ -n " ${name_servers_append}${search_domains_append} " ]; then
680762 eval " $( echo_append | parse_resolv) "
@@ -724,7 +806,7 @@ make_vars()
724806
725807force=false
726808VFLAG=
727- while getopts a:C:c:Dd:fhIilm :pRruvVx OPT; do
809+ while getopts a:C:c:Dd:fhIiLlm :pRruvVx OPT; do
728810 case " $OPT " in
729811 f) force=true;;
730812 h) usage;;
762844
763845# -l lists our resolv files, optionally for a specific interface
764846if [ " $cmd " = l ] || [ " $cmd " = i ]; then
765- ALLIFACES=true
766- list_resolv " $cmd " " $args "
847+ list_resolv " -$cmd " " $args "
767848 exit $?
768849fi
769- ALLIFACES=false
850+ # -L is the same as -l, but post-processed from our config
851+ if [ " $cmd " = L ]; then
852+ list_resolv " -$cmd " " $args " | replace
853+ exit $? 2
854+ fi
770855
771856# Restart a service or echo the command to restart a service
772857if [ " $cmd " = r ] || [ " $cmd " = R ]; then
@@ -1077,7 +1162,7 @@ export RESTARTCMD RCDIR _NOINIT_WARNED
10771162
10781163eval " $( make_vars) "
10791164export RESOLVCONF DOMAINS SEARCH NAMESERVERS LOCALNAMESERVERS
1080- : ${list_resolv:= list_resolv -l }
1165+ : ${list_resolv:= list_resolv -L }
10811166retval=0
10821167
10831168# Run scripts in the same directory resolvconf is run from
0 commit comments