summaryrefslogtreecommitdiff
path: root/tests/priv-check
blob: 4b95f860fffcf6c20389611484a5805267893911 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# -*- sh -*-
# Source this file at the beginning of a test that works
# only when run as root or as non-root.

case $1 in
  require-root) who='as root';;
  require-non-root) who='by an unprivileged user';;
  *) echo "Usage: $0 require-root|require-non-root" 1>&2; exit 1;;
esac

priv_check_temp=priv-check.$$
touch $priv_check_temp || framework_failure=1
chmod a-w $priv_check_temp || framework_failure=1

(echo foo >> $priv_check_temp) >/dev/null 2>&1
overwrite_status=$?
give_msg=no
case $1:$overwrite_status in
  require-root:0) ;;
  require-root:*) give_msg=yes ;;
  require-non-root:0) give_msg=yes ;;
  require-non-root:*) ;;
esac

test $give_msg = yes && {
  cat <<EOF
***************************
NOTICE:
$0: This test is being skipped, since it works only
when run $who.
***************************
EOF
  rm -f $priv_check_temp
  (exit 77); exit
}

rm -f $priv_check_temp