RUN_VERY_EXPENSIVE_TESTS=no
SHELL=/bin/sh
NON_ROOT_USERNAME=nobody
- NON_ROOT_GROUP=$(id -g $NON_ROOT_USERNAME)
+ NON_ROOT_GID=$(id -g $NON_ROOT_USERNAME)
COREUTILS_GROUPS=$(id -G)
There are hundreds of tests in the tests/ directories. You can use
{
uid_is_privileged_ || skip_ "must be run as root"
NON_ROOT_USERNAME=${NON_ROOT_USERNAME=nobody}
- NON_ROOT_GROUP=${NON_ROOT_GROUP=$(id -g $NON_ROOT_USERNAME)}
+ NON_ROOT_GID=${NON_ROOT_GID=$(id -g $NON_ROOT_USERNAME)}
# When the current test invokes chroot, call nonroot_has_perm_
# to check for a common problem.
print_ver_ id
require_root_
-u=$(id -u $NON_ROOT_USERNAME) || framework_failure_
-g=$u
-
-# Construct a different group number.
-gp1=$(expr $g + 1)
+# Construct a different group number
+gp1=$(expr $NON_ROOT_GID + 1)
echo $gp1 > exp || framework_failure_
-# With coreutils-8.16 and earlier, id -G would print both: $gp1 $g
-chroot --user=+$u:+$gp1 --groups='' / env PATH="$PATH" \
+# With coreutils-8.16 and earlier, id -G would print both:
+# $gp1 $NON_ROOT_GID
+chroot --user=$NON_ROOT_USERNAME:+$gp1 --groups='' / env PATH="$PATH" \
id -G > out || fail=1
-compare exp out || { cat out; fail=1; }
+compare exp out || fail=1
-# With coreutils-8.22 and earlier, id would erroneously print groups=$g
-chroot --user=+$u:+$gp1 --groups='' / env PATH="$PATH" \
+# With coreutils-8.22 and earlier, id would erroneously print
+# groups=$NON_ROOT_GID
+chroot --user=$NON_ROOT_USERNAME:+$gp1 --groups='' / env PATH="$PATH" \
id > out || fail=1
grep -F "groups=$gp1" out || { cat out; fail=1; }
# verify numeric IDs looked up similarly to names
NON_ROOT_UID=$(id -u $NON_ROOT_USERNAME)
-NON_ROOT_GID=$(id -g $NON_ROOT_USERNAME)
+NON_ROOT_GROUP=$NON_ROOT_GID # Used where we want name lookups to occur
# "uid:" is supported (unlike chown etc.) since we treat it like "uid"
chroot --userspec=$NON_ROOT_UID: / true || fail=1
chroot --userspec=$NON_ROOT_USERNAME:$NON_ROOT_GROUP \
--groups=$NON_ROOT_GROUP / id -G
)
-test "$id_G_after_chroot" = $NON_ROOT_GROUP || fail=1
+test "$id_G_after_chroot" = $NON_ROOT_GID || fail=1
# Verify that when specifying only the user name we get all their groups
test "$(chroot --userspec=$NON_ROOT_USERNAME / id -G)" = \
# Verify that when specifying only the user and clearing supplemental groups
# that we only get the primary group
test "$(chroot --userspec=$NON_ROOT_USERNAME --groups='' / id -G)" = \
- "$(id -g $NON_ROOT_USERNAME)" || fail=1
+ $NON_ROOT_GID || fail=1
# Verify that when specifying only the UID we get all their groups
test "$(chroot --userspec=$NON_ROOT_UID / id -G)" = \
# results in no lookups in the name database which could be useful depending
# on your chroot setup.
test "$(chroot --userspec=+$NON_ROOT_UID:+$NON_ROOT_GID --groups='' / id -G)" =\
- "$(id -g $NON_ROOT_USERNAME)" || fail=1
+ $NON_ROOT_GID || fail=1
# Verify that when specifying only a group we get the current user ID
test "$(chroot --userspec=:$NON_ROOT_GROUP / id -u)" = "$(id -u)" \
require_root_
-group_num=$(id -g $NON_ROOT_USERNAME)
-
# Create a file owned by root, and writable by $NON_ROOT_USERNAME.
echo > root-owned || framework_failure_
-chgrp +$group_num . root-owned || framework_failure_
+chgrp +$NON_ROOT_GID . root-owned || framework_failure_
chmod g+w root-owned
# Ensure that the current directory is searchable by $NON_ROOT_USERNAME.
print_ver_ touch
require_root_
-group_num=$(id -g $NON_ROOT_USERNAME)
-
# Create a file owned by root, and writable by $NON_ROOT_USERNAME.
echo > root-owned || framework_failure_
-chgrp +$group_num . root-owned || framework_failure_
+chgrp +$NON_ROOT_GID . root-owned || framework_failure_
chmod g+w root-owned
# Ensure that the current directory is searchable by $NON_ROOT_USERNAME.