Commit 00ecef76 authored by Sevan Janiyan's avatar Sevan Janiyan Committed by GitHub
Browse files

Use the md5 utility in scripts for checksums (#327)

* md5sum is only present on systems with gnu coreutils.
The BSDs & OS X include the md5 utility.
Add the relevant tests to use md5sum when that's found and md5 otherwise.
Test for the paths of md5 covers NetBSD, FreeBSD (& DragonFly by proxy), OpenBSD & OS X.

* Check for the presence of the md5 utility and use that for comparison if present.
For the benefit of the BSDs & OS X.

* Though coreutils has the route & netstat command, their syntax is different
to their *BSD counterparts.
Add the necessary parts to populate $HS_WANIF & $HS_DHCPRELAYAGENT correctly.
parent 4876272e
......@@ -54,7 +54,11 @@ HS_WISPRLOGIN=${HS_WISPRLOGIN:-$HS_UAMSERVICE}
HS_PAP_OK=${HS_PAP_OK:-on}
HS_DNS1=${HS_DNS1:-$HS_DNS}
HS_DNS1=${HS_DNS1:-$(grep '^nameserver' /etc/resolv.conf | head -n1 | awk '{print $2}')}
if [ $(uname) = "Linux" ]; then
HS_WANIF=${HS_WANIF:-$(route -n|grep '^0.0.0.0'|head -n1|awk '{print $8}')}
else
HS_WANIF=${HS_WANIF:-$(route get default | grep interface | awk '{print $2}')}
fi
bailout() { echo $1; exit; }
......@@ -125,7 +129,13 @@ writeconfig() {
addconfig1 ${HS_GID:+"gid \"$HS_GID\""}
[ -n "$HS_DHCPGATEWAY" ] && {
HS_DHCPRELAYAGENT=${HS_DHCPRELAYAGENT:-$(ifconfig $(route -n|grep '^0.0.0.0'|awk '{ print $8 }')|grep 'inet addr:'|cut -d: -f 2|cut -d' ' -f1)}
if [ $(uname) = "Linux" ]; then
HS_DHCPRELAYAGENT=${HS_DHCPRELAYAGENT:-$(ifconfig $(route -n|grep '^0.0.0.0'| \
awk '{ print $8 }')|grep 'inet addr:'|cut -d: -f 2|cut -d' ' -f1)}
else
HS_DHCPRELAYAGENT=${HS_DHCPRELAYAGENT:-$(ifconfig $(netstat -rn | grep 'default' | \
head -n1 | awk '{print$7}') | grep 'inet ' | cut -d/ -f 1 | cut -d' ' -f2)}
fi
addconfig1 "dhcpgateway \"$HS_DHCPGATEWAY\""
addconfig1 "dhcprelayagent \"$HS_DHCPRELAYAGENT\""
}
......@@ -317,6 +327,10 @@ files_equal() { # returns 0 for equal, 1 for not-equal
[ "$(md5sum $1 | cut -f1 -d' ')" = "$(md5sum $2 | cut -f1 -d' ')" ] && return 0;
return 1;
}
[ -x /usr/bin/md5 ] || [ -x /sbin/md5 ] || [ -x /bin/md5 ] && {
[ "$(md5 $1)" = "$(md5 $2)" ] && return 0;
return 1;
}
return 0;
}
......
......@@ -130,7 +130,12 @@ local_login_url() {
if [ "$HS_USELOCALUSERS" = "on" ]; then
line=$(head -1 $USERS)
if [ "$line" = "" ]; then
if [ -x /usr/bin/md5sum ] || [ -x /bin/md5sum ]; then
echo "tos:$(echo '$$$(date)'|md5sum|cut -f1)" >> $USERS
fi
if [ -x /usr/bin/md5 ] || [ -x /sbin/md5 ] || [ -x /bin/md5 ]; then
echo "tos:$(echo '$$$(date)'|md5)" >> $USERS
fi
line=$(head -1 $USERS)
fi
if [ "$line" != "" ]; then
......@@ -237,7 +242,12 @@ then
[ "$HTTPS" = "on" ] && HTTP="https"
URL="$HTTP://$SERVER_NAME/$REQUEST_URI?$QS"
CHECK="$URL$HS_UAMSECRET"
if [ -x /usr/bin/md5sum ] || [ -x /bin/md5sum ]; then
CHECK_MD5=$(echo -n "$CHECK" |md5sum|cut -d' ' -f1|tr 'a-z' 'A-Z');
fi
if [ -x /usr/bin/md5 ] || [ -x /sbin/md5 ] || [ -x /bin/md5 ]; then
CHECK_MD5=$(echo -n "$CHECK" |md5 |tr 'a-z' 'A-Z');
fi
if [ "$CHECK_MD5" = "$FORM_md" ]; then
COOVA_USERURL=$FORM_userurl
else
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment