From: Karel Zak Date: Fri, 15 Jun 2007 13:55:10 +0000 (+0200) Subject: tests: add support for suid programs X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1b5417aca1978450312303fa144d327ad1ca5aa7;p=util-linux tests: add support for suid programs Signed-off-by: Karel Zak --- diff --git a/tests/functions.sh b/tests/functions.sh index 4a59ff32..11a1ae5d 100644 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -58,6 +58,10 @@ function ts_init { mkdir -p $TS_DIFFDIR fi + declare -a TS_SUID_PROGS + declare -a TS_SUID_USER + declare -a TS_SUID_GROUP + TS_VERBOSE=$( ts_has_option "verbose" "$*") TS_OUTPUT="$TS_OUTDIR/$TS_NAME" TS_DIFF="$TS_DIFFDIR/$TS_NAME" @@ -85,9 +89,28 @@ function ts_init { printf "%15s: %-25s ..." "$TS_COMPONENT" "$TS_DESC" } +function ts_init_suid { + PROG="$1" + ct=${#TS_SUID_PROGS[*]} + + # Save info about original setting + TS_SUID_PROGS[$ct]=$PROG + TS_SUID_USER[$ct]=$(stat --printf="%U" $PROG) + TS_SUID_GROUP[$ct]=$(stat --printf="%G" $PROG) + + chown root.root $PROG &> /dev/null + chmod u+s $PROG &> /dev/null +} + function ts_finalize { local res=0 + for idx in $(seq 0 $((${#TS_SUID_PROGS[*]} - 1))); do + PROG=${TS_SUID_PROGS[$idx]} + chmod a-s $PROG &> /dev/null + chown ${TS_SUID_USER[$idx]}.${TS_SUID_GROUP[$idx]} $PROG &> /dev/null + done + if [ -s $TS_EXPECTED ]; then if [ -s $TS_OUTPUT ]; then diff -u $TS_EXPECTED $TS_OUTPUT > $TS_DIFF