from libc
[coreutils.git] / tests / priv-check
blobb37f996328d839907c9755f3e01eef4e37b01962
1 # -*- sh -*-
2 # Source this file at the beginning of a test that works
3 # only when run as root or as non-root.
5 case "$PRIV_CHECK_ARG" in
6   require-root) who='as root';;
7   require-non-root) who='by an unprivileged user';;
8   *) echo "Usage: PRIV_CHECK_ARG={require-root|require-non-root} . priv-check"\
9      1>&2; exit 1;;
10 esac
12 priv_check_temp=priv-check.$$
13 touch $priv_check_temp || framework_failure=1
14 chmod a-w $priv_check_temp || framework_failure=1
16 (echo foo >> $priv_check_temp) >/dev/null 2>&1
17 overwrite_status=$?
18 give_msg=no
19 case $PRIV_CHECK_ARG:$overwrite_status in
20   require-root:0) ;;
21   require-root:*) give_msg=yes ;;
22   require-non-root:0) give_msg=yes ;;
23   require-non-root:*) ;;
24 esac
26 test $give_msg = yes && {
27   cat <<EOF
28 ***************************
29 NOTICE:
30 $0: This test is being skipped, since it works only
31 when run $who.
32 ***************************
33 EOF
34   rm -f $priv_check_temp
35   (exit 77); exit
38 rm -f $priv_check_temp