2 # Exercise "id --zero".
4 # Copyright (C) 2013-2024 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 .
"${srcdir=.}/tests/init.sh"; path_prepend_ .
/src
26 # id(1) should refuse --zero in default format.
27 echo 'id: option --zero not permitted in default format' > err-exp \
29 id
--zero > out
2>err
&& fail
=1
30 compare
/dev
/null out || fail
=1
31 compare err-exp err || fail
=1
33 # Create a nice list of users.
34 # Add $USER to ensure we have at least one explicit entry.
36 # Add a few typical users to test single group and multiple groups.
37 for u
in root man postfix sshd nobody
; do
38 id
$u >/dev
/null
2>&1 && users
="$users $u"
40 # Add $users and '' (implicit $USER) to list to process.
41 printf '%s\n' $users '' >> users || framework_failure_
43 # Exercise "id -z" with various options.
44 printf '\n' > exp || framework_failure_
45 > out || framework_failure_
48 for o
in g gr G Gr u ur
; do
50 printf '%s: ' "id -${o}${n}[z] $u" >> exp || framework_failure_
51 printf '\n%s: ' "id -${o}${n}[z] $u" >> out || framework_failure_
52 # There may be no name corresponding to an id, so don't check
53 # exit status when in name lookup mode
54 id
-${o}${n} $u >> exp ||
55 { test $?
-ne 1 ||
test -z "$n" && fail
=1; }
56 id
-${o}${n}z
$u > tmp ||
57 { test $?
-ne 1 ||
test -z "$n" && fail
=1; }
58 head -c-1 < tmp
>> out || framework_failure_
62 printf '\n' >> out || framework_failure_
63 tr '\0' ' ' < out
> out2 || framework_failure_
64 compare exp out2 || fail
=1
66 # multiuser testing with -z
67 # test if the options work, these tests should pass if the above tests
70 for o
in g gr u ur
; do
72 id
-${o}${n} $users >> tmp1 ||
73 { test $?
-ne 1 ||
test -z "$n" && fail
=1; }
74 id
-${o}${n}z
$users > tmp2 ||
75 { test $?
-ne 1 ||
test -z "$n" && fail
=1; }
76 tr '\0' '\n' < tmp2
>> tmp3
79 compare tmp1 tmp3 || fail
=1
81 # Separate checks when we are testing for multiple users && -G.
82 # This is done because we terminate the records with two NULs
83 # instead of a regular single NUL.
90 id
-${o}${n} $users >> gtmp1 ||
91 { test $?
-ne 1 ||
test -z "$n" && fail
=1; }
92 echo >> gtmp1 || framework_failure_
94 id
-${o}${n}z
$users > gtmp2 ||
95 { test $?
-ne 1 ||
test -z "$n" && fail
=1; }
96 # we replace all NULs with spaces, the result we get is there are two
97 # consecutive spaces instead of two NUL's, we pass this to sed
98 # to replace more than 1 space with a newline. This is ideally where a new
99 # line should be. This should make the output similar to without -z.
100 { tr '\0' ' ' < gtmp2
; echo; } |
sed "s/ /\\$NL/g" >> gtmp3
103 compare gtmp1 gtmp3 || fail
=1