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"\
12 # Make sure id -u succeeds.
15 echo "$0: cannot run \`id -u'" 1>&2
19 # Make sure it gives valid output.
22 echo "$0: invalid output (\`$my_uid') from \`id -u'" 1>&2
30 # When running as root, always ensure that we have a valid non-root username.
31 # As non-root, don't do anything, since we won't be running setuidgid.
32 : ${NON_ROOT_USERNAME=nobody}
34 # Ensure that the supplied username is valid and with UID != 0.
35 coreutils_non_root_uid=`id -u $NON_ROOT_USERNAME`
38 echo "$0: This command failed: \`id -u $NON_ROOT_USERNAME'" 1>&2
39 echo "$0: Skipping this test. To enable it, set the envvar" 1>&2
40 echo "$0: NON_ROOT_USERNAME to a non-root user name." 1>&2
43 test "$coreutils_non_root_uid" = 0 && \
45 echo "$0: The specified NON_ROOT_USERNAME ($NON_ROOT_USERNAME)" 1>&2
46 echo "$0: is invalid because its UID is 0." 1>&2
52 case $PRIV_CHECK_ARG:$my_uid in
54 require-root:*) give_msg=yes ;;
56 # `.' must be writable by $NON_ROOT_USERNAME
57 setuidgid $NON_ROOT_USERNAME test -w . ||
59 echo "$0: `pwd`: not writable by user \`$NON_ROOT_USERNAME'" 1>&2
60 echo "$0: skipping this test" 1>&2
63 exec setuidgid $NON_ROOT_USERNAME $0
65 require-non-root:*) ;;
68 test $give_msg = yes && {
70 ***************************
72 $0: This test is being skipped, since it works only
74 ***************************