diff options
author | Achilles Gaikwad <agaikwad@redhat.com> | 2018-07-24 01:09:13 +0530 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2018-09-29 22:39:26 -0700 |
commit | a32a756a58fec134836f85c2c8bfd58063ebc4c4 (patch) | |
tree | 357b404839dd1cb0b9953a0ca0f89021f51221a2 /tests/id | |
parent | 7262994810deac63fcb55223e599acc7339a7526 (diff) | |
download | coreutils-a32a756a58fec134836f85c2c8bfd58063ebc4c4.tar.gz |
id: support multiple specified users
$ id root nobody
uid=0(root) gid=0(root) groups=0(root)
uid=99(nobody) gid=99(nobody) groups=99(nobody)
* src/id.c (main): Make variables opt_zero, just_group_list,
just_group, use_real, just_user global to be used in a new
function.
(print_stuff): New function that will print user and group
information for the specified USER.
When using -G option delimit each record with two NULs.
Restructure the code in the file to have global variables
followed by functions.
* tests/id/zero.sh: Add test cases to check the usage
of -z option with multiple users.
* tests/id/uid.sh: Add a test case to ensure all users
are queried in the presence of errors.
* doc/coreutils.texi: Document the interface changes.
* NEWS: Mention the new feature.
Diffstat (limited to 'tests/id')
-rwxr-xr-x | tests/id/uid.sh | 5 | ||||
-rwxr-xr-x | tests/id/zero.sh | 37 |
2 files changed, 42 insertions, 0 deletions
diff --git a/tests/id/uid.sh b/tests/id/uid.sh index 61d313778..9d856433d 100755 --- a/tests/id/uid.sh +++ b/tests/id/uid.sh @@ -24,6 +24,11 @@ user=$(id -nu) || fail=1 # Ensure the empty user spec is discarded returns_ 1 id '' || fail=1 +# Ensure we don't exit early, and process all users +id $user > user_out || fail=1 +returns_ 1 id '' $user >multi_user_out || fail=1 +compare user_out multi_user_out || fail=1 + for mode in '' '-G' '-g'; do id $mode $user > user_out || fail=1 # lookup name for comparison diff --git a/tests/id/zero.sh b/tests/id/zero.sh index f183e18f8..d0cf44c53 100755 --- a/tests/id/zero.sh +++ b/tests/id/zero.sh @@ -63,4 +63,41 @@ printf '\n' >> out || framework_failure_ tr '\0' ' ' < out > out2 || framework_failure_ compare exp out2 || fail=1 +# multiuser testing with -z +# test if the options work, these tests should pass if the above tests +# do. + +for o in g gr u ur ; do + for n in '' n ; do + id -${o}${n} $users >> tmp1 || + { test $? -ne 1 || test -z "$n" && fail=1; } + id -${o}${n}z $users > tmp2 || + { test $? -ne 1 || test -z "$n" && fail=1; } + tr '\0' '\n' < tmp2 >> tmp3 + done +done +compare tmp1 tmp3 || fail=1 + +# Separate checks when we are testing for multiple users && -G. +# This is done because we terminate the records with two NULs +# instead of a regular single NUL. + +NL=' +' + +for o in G Gr ; do + for n in '' n ; do + id -${o}${n} $users >> gtmp1 || + { test $? -ne 1 || test -z "$n" && fail=1; } + id -${o}${n}z $users > gtmp2 || + { test $? -ne 1 || test -z "$n" && fail=1; } + # we replace all NULs with spaces, the result we get is there are two + # consecutive spaces instead of two NUL's, we pass this to sed + # to replace more than 1 space with a newline. This is ideally where a new + # line should be. This should make the output similar to without -z. + tr '\0' ' ' < gtmp2 | sed "s/ /\\$NL/g" >> gtmp3 + done +done +compare gtmp1 gtmp3 || fail=1 + Exit $fail |