#!/bin/sh
#
# "suidfix" - fix permissions and sticky bits for the binaries
# installed by GNUnet.
# Takes GNUNET_PREFIX from the environment.
#
# Taken from dangole's LEDE/OpenWRT config.. thx!

suid_root_helpers="exit nat-server nat-client transport-bluetooth transport-wlan vpn"
libexec="${GNUNET_PREFIX}/lib/gnunet/libexec"

chmodown_execbin() {
        if [ -x $1 ]; then
                if [ "$3" ]; then
                        chown $3 $1 2>/dev/null && chmod $2 $1
                else
                        chmod $2 $1
                fi
		ls -l $1
	else
		echo "Missing: $1"
        fi
}

for helper in $suid_root_helpers; do
	chmodown_execbin ${libexec}/gnunet-helper-$helper u+s
done
chmodown_execbin ${libexec}/gnunet-helper-dns 4750 root:gnunetdns
chmodown_execbin ${libexec}/gnunet-service-dns 2750 gnunet:gnunetdns

