WebDAV: avoid DNS SRV retry loop for aliases

Certains domains (like googleapis.com) are aliases. The lookup tools
do not fail with NXDOMAIN in this case, causing the
syncevo-webdav-lookup script to return only an unknown lookup error,
in which case the WebDAV backend will retry for a while.

We need to detect aliases resp. missing SRV information and return a
"no information error".
This commit is contained in:
Patrick Ohly 2014-07-25 11:02:31 +02:00
parent 2371f69f97
commit cab4d0a98d
1 changed files with 27 additions and 13 deletions

View File

@ -47,6 +47,9 @@ DOMAIN=$2
LOG=`mktemp`
trap "[ -s $LOG ] && ( echo $0 failed to find '$TYPE $DOMAIN':; cat $LOG >&2 ); rm -f $LOG" EXIT
# We depend on certain output strings which might be localized.
export LC_ALL=C
# find one of the supported tools for DNS queries
TOOL=
ALTERNATIVES="adnshost host /usr/lib/syncevolution/host nslookup"
@ -78,40 +81,51 @@ for type in ${TYPE}s ${TYPE}; do
case $TOOL in
adnshost)
if res=`$TOOL -Fi -tsrv _$type._tcp.$DOMAIN | tee -a $LOG | grep -e ^_$type._tcp.$DOMAIN -e nxdomain`; then
if res=`$TOOL -Fi -tsrv _$type._tcp.$DOMAIN | tee -a $LOG | grep -e ^_$type._tcp.$DOMAIN -e nxdomain -e permfail`; then
# _carddavs._tcp.yahoo.com.cn SRV 1 1 443 carddav.address.yahoo.com misconfig 101 prohibitedcname "DNS alias found where canonical name wanted" ( )
PORT=`echo $res | sed -e 's;.* SRV [^ ]* [^ ]* \([^ ]*\) \([^ ]*\).*;\1;'`
HOSTNAME=`echo $res | sed -e 's;.* SRV [^ ]* [^ ]* \([^ ]*\) \([^ ]*\).*;\2;'`
else
ret=$?
if echo "$res" | grep -q nxdomain; then
if echo "$res" | grep -q -e nxdomain -e permfail; then
ret=3
fi
exit $ret
fi
;;
nslookup)
if res=`$TOOL -type=srv _$type._tcp.$DOMAIN | tee -a $LOG | grep -e "service =" -e NXDOMAIN | head -1`; then
# _caldavs._tcp.yahoo.com service = 1 1 443 caldav.calendar.yahoo.com.
PORT=`echo $res | sed -e 's;.*service = [^ ]* [^ ]* \([^ ]*\) \([^ ]*\)\.;\1;'`
HOSTNAME=`echo $res | sed -e 's;.*service = [^ ]* [^ ]* \([^ ]*\) \([^ ]*\)\.;\2;'`
if res=`$TOOL -type=srv _$type._tcp.$DOMAIN | tee -a $LOG | grep -e "service =" -e NXDOMAIN -e 'canonical name' | head -1`; then
if echo "$res" | grep -q -e NXDOMAIN -e 'canonical name'; then
exit 3
else
# _caldavs._tcp.yahoo.com service = 1 1 443 caldav.calendar.yahoo.com.
PORT=`echo $res | sed -e 's;.*service = [^ ]* [^ ]* \([^ ]*\) \([^ ]*\)\.;\1;'`
HOSTNAME=`echo $res | sed -e 's;.*service = [^ ]* [^ ]* \([^ ]*\) \([^ ]*\)\.;\2;'`
fi
else
ret=$?
if echo "$res" | grep -q NXDOMAIN; then
if echo "$res" | grep -q -e NXDOMAIN -e 'canonical name'; then
ret=3
fi
exit $ret
fi
;;
host|*/host)
if res=`$TOOL -t srv _$type._tcp.$DOMAIN | tee -a $LOG | grep -e "\<SRV\>" -e NXDOMAIN | head -1`; then
# _caldavs._tcp.yahoo.com has SRV record 1 1 443 caldav.calendar.yahoo.com.
# _caldavs._tcp.yahoo.com SRV 1 1 443 caldav.calendar.yahoo.com
PORT=`echo $res | sed -e 's;.* \([^ ]*\) \([^. ]\+\(\.[^. ]\+\)*\)\.\?;\1;'`
HOSTNAME=`echo $res | sed -e 's;.* \([^ ]*\) \([^. ]\+\(\.[^. ]\+\)*\)\.\?;\2;'`
# "host -t srv _carddavs._tcp.googleapis.com" returns only alias information.
# If we see that instead of the service entry, then we know that the information
# is permanently not available.
if res=`$TOOL -t srv _$type._tcp.$DOMAIN | tee -a $LOG | grep -e "\<SRV\>" -e NXDOMAIN -e 'is an alias' | head -1`; then
if echo "$res" | grep -q -e NXDOMAIN -e 'is an alias'; then
exit 3
else
# _caldavs._tcp.yahoo.com has SRV record 1 1 443 caldav.calendar.yahoo.com.
# _caldavs._tcp.yahoo.com SRV 1 1 443 caldav.calendar.yahoo.com
PORT=`echo $res | sed -e 's;.* \([^ ]*\) \([^. ]\+\(\.[^. ]\+\)*\)\.\?;\1;'`
HOSTNAME=`echo $res | sed -e 's;.* \([^ ]*\) \([^. ]\+\(\.[^. ]\+\)*\)\.\?;\2;'`
fi
else
ret=$?
if echo "$res" | grep -q NXDOMAIN; then
if echo "$res" | grep -q -e NXDOMAIN -e 'is an alias'; then
ret=3
fi
exit $ret