aboutsummaryrefslogtreecommitdiff
path: root/coreutils/id_test.sh
blob: 0d65f2ae31cdba01bea9828dbd8a86c8459ff9a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#!/bin/bash
# Test script for busybox id vs. coreutils id.
# Needs root privileges for some tests.

cp /usr/bin/id .
BUSYBOX=./busybox
ID=./id
LIST=`awk -F: '{ printf "%s\n", $1 }' /etc/passwd`
FLAG_USER_EXISTS="no"
TEST_USER="f583ca884c1d93458fb61ed137ff44f6"

echo "test 1: id [options] nousername"
rm -f foo bar
for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr"
do
	#echo "$OPTIONS"
	$BUSYBOX id $OPTIONS >foo 2>/dev/null
	RET1=$?
	$ID $OPTIONS >bar 2>/dev/null
	RET2=$?
	if test "$RET1" != "$RET2"; then
		echo "Return Values differ ($RET1 != $RET2): options $OPTIONS"
	fi
	diff foo bar
done

echo "test 2: id [options] username"
rm -f foo bar
for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr"
do
	#echo "$OPTIONS"
	for i in $LIST ; do
		if test "$i" = "$TEST_USER"; then
			FLAG_USER_EXISTS="yes"
		fi
		$BUSYBOX id $OPTIONS $i >foo 2>/dev/null
		RET1=$?
		$ID $OPTIONS $i >bar 2>/dev/null
		RET2=$?
		if test "$RET1" != "$RET2"; then
			echo "Return Values differ ($RET1 != $RET2): options $OPTIONS"
		fi
		diff foo bar
	done
done

if test $FLAG_USER_EXISTS = "yes"; then
	echo "test 3,4,5,6,7,8,9,10,11,12 skipped because test user $TEST_USER already exists"
	rm -f foo bar
	exit 1
fi

adduser -s /bin/true -g "" -H -D "$TEST_USER" || exit 1

chown $TEST_USER.$TEST_USER $BUSYBOX
chmod u+s $BUSYBOX 2>&1 /dev/null
chown $TEST_USER.$TEST_USER $ID
chmod u+s $ID 2>&1 /dev/null

echo "test 3 setuid, existing user: id [options] no username"
rm -f foo bar
for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr"
do
	#echo "$OPTIONS"
	$BUSYBOX id $OPTIONS >foo 2>/dev/null
	RET1=$?
	$ID $OPTIONS >bar 2>/dev/null
	RET2=$?
	if test "$RET1" != "$RET2"; then
		echo "Return Values differ ($RET1 != $RET2): options $OPTIONS"
	fi
	diff foo bar
	#done
done

echo "test 4 setuid, existing user: id [options] username"
rm -f foo bar
for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr"
do
	#echo "$OPTIONS"
	for i in $LIST ; do
		$BUSYBOX id $OPTIONS $i >foo 2>/dev/null
		RET1=$?
		$ID $OPTIONS $i >bar 2>/dev/null
		RET2=$?
		if test "$RET1" != "$RET2"; then
			echo "Return Values differ ($RET1 != $RET2): options $OPTIONS"
		fi
		diff foo bar
	done
done

chown $TEST_USER.$TEST_USER $BUSYBOX
chmod g+s $BUSYBOX 2>&1 /dev/null
chown $TEST_USER.$TEST_USER $ID
chmod g+s $ID 2>&1 /dev/null

echo "test 5 setgid, existing user: id [options] no username"
rm -f foo bar
for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr"
do
	#echo "$OPTIONS"
	$BUSYBOX id $OPTIONS >foo 2>/dev/null
	RET1=$?
	$ID $OPTIONS >bar 2>/dev/null
	RET2=$?
	if test "$RET1" != "$RET2"; then
		echo "Return Values differ ($RET1 != $RET2): options $OPTIONS"
	fi
	diff foo bar
	#done
done

echo "test 6 setgid, existing user: id [options] username"
rm -f foo bar
for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr"
do
	#echo "$OPTIONS"
	for i in $LIST ; do
		$BUSYBOX id $OPTIONS $i >foo 2>/dev/null
		RET1=$?
		$ID $OPTIONS $i >bar 2>/dev/null
		RET2=$?
		if test "$RET1" != "$RET2"; then
			echo "Return Values differ ($RET1 != $RET2): options $OPTIONS"
		fi
		diff foo bar
	done
done

chown $TEST_USER.$TEST_USER $BUSYBOX
chmod u+s,g+s $BUSYBOX 2>&1 /dev/null
chown $TEST_USER.$TEST_USER $ID
chmod u+s,g+s $ID 2>&1 /dev/null

echo "test 7 setuid, setgid, existing user: id [options] no username"
rm -f foo bar
for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr"
do
	#echo "$OPTIONS"
	$BUSYBOX id $OPTIONS >foo 2>/dev/null
	RET1=$?
	$ID $OPTIONS >bar 2>/dev/null
	RET2=$?
	if test "$RET1" != "$RET2"; then
		echo "Return Values differ ($RET1 != $RET2): options $OPTIONS"
	fi
	diff foo bar
	#done
done

echo "test 8 setuid, setgid, existing user: id [options] username"
rm -f foo bar
for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr"
do
	#echo "$OPTIONS"
	for i in $LIST ; do
		$BUSYBOX id $OPTIONS $i >foo 2>/dev/null
		RET1=$?
		$ID $OPTIONS $i >bar 2>/dev/null
		RET2=$?
		if test "$RET1" != "$RET2"; then
			echo "Return Values differ ($RET1 != $RET2): options $OPTIONS"
		fi
		diff foo bar
	done
done

deluser $TEST_USER || exit 1

echo "test 9 setuid, setgid, not existing user: id [options] no username"
rm -f foo bar
for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr"
do
	#echo "$OPTIONS"
	$BUSYBOX id $OPTIONS >foo 2>/dev/null
	RET1=$?
	$ID $OPTIONS >bar 2>/dev/null
	RET2=$?
	if test "$RET1" != "$RET2"; then
		echo "Return Values differ ($RET1 != $RET2): options $OPTIONS"
	fi
	diff foo bar
done

echo "test 10 setuid, setgid, not existing user: id [options] username"
rm -f foo bar
for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr"
do
	#echo "$OPTIONS"
	for i in $LIST ; do
		$BUSYBOX id $OPTIONS $i >foo 2>/dev/null
		RET1=$?
		$ID $OPTIONS $i >bar 2>/dev/null
		RET2=$?
		if test "$RET1" != "$RET2"; then
			echo "Return Values differ ($RET1 != $RET2): options $OPTIONS"
		fi
		diff foo bar
	done
done

chown .root $BUSYBOX 2>&1 /dev/null
chown .root $ID 2>&1 /dev/null
chmod g+s $BUSYBOX 2>&1 /dev/null
chmod g+s $ID 2>&1 /dev/null

echo "test 11 setgid, not existing group: id [options] no username"
rm -f foo bar
for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr"
do
	#echo "$OPTIONS"
	$BUSYBOX id $OPTIONS >foo 2>/dev/null
	RET1=$?
	$ID $OPTIONS >bar 2>/dev/null
	RET2=$?
	if test "$RET1" != "$RET2"; then
		echo "Return Values differ ($RET1 != $RET2): options $OPTIONS"
	fi
	diff foo bar
	#done
done

echo "test 12 setgid, not existing group: id [options] username"
rm -f foo bar
for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr"
do
	#echo "$OPTIONS"
	for i in $LIST ; do
		$BUSYBOX id $OPTIONS $i >foo 2>/dev/null
		RET1=$?
		$ID $OPTIONS $i >bar 2>/dev/null
		RET2=$?
		if test "$RET1" != "$RET2"; then
			echo "Return Values differ ($RET1 != $RET2): options $OPTIONS"
		fi
		diff foo bar
	done
done

chown root.root $BUSYBOX 2>&1 /dev/null
chown root.root $ID 2>&1 /dev/null
rm -f $ID
rm -f foo bar