1 #! /usr/bin/ksh -p
2 #
3 # CDDL HEADER START
4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22
23 #
24 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27 # uidmapping_03.ksh
28 # This file contains positive testcases for the setup that both server
29 # and client have the same domain. The testcases are divided into two
30 # groups, the first group are using chown/chgrp/ls to change user/group
31 # id and then verify it. They are:
32 #
33 # {a} - change owner to root and verify it
34 # {b} - change group to root and verify it
35 # {c} - change owner to normal user(uucp) and verify it
36 # {d} - change group to normal group(uucp) and verify it
37 # {e} - change user and group at the same time and verify them
38 # {f} - change owner to user id unknown to both client and server
39 # {g} - change group to group id unknown to both client and server
40 # {h} - change owner to user which has different ids on client and server
41 # {i} - change owner to user known only to server
42 #
43 # The second group are using setfacl/getfacl to modify acl entries and
44 # then verify it. They are:
45 #
46 # {j} - add acl entry for root user and verify it
47 # {k} - add acl entry for root group and verify it
48 # {l} - add acl entry for normal user(uucp) and verify it
49 # {m} - add acl entry for normal group(uucp) and verify it
50 # {n} - add acl entries for normal user and group at the same time
51 # and verify it
52 # {o} - add acl entry for user id unknown to both client and server
53 # {p} - add acl entry for group id unknown to both client and server
54 # {q} - add acl entry for user which has different ids on client
55 # and server
56
57 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
58
59 trap "cleanup" EXIT
60 trap "exit 1" HUP INT QUIT PIPE TERM
61
62 NAME=`basename $0`
63 UIDMAPENV="./uid_proc"
64 UNINITIATED=6
65
66 # set up script running environment
67 if [ ! -f $UIDMAPENV ]; then
68 echo "$NAME: UIDMAPENV[$UIDMAPENV] not found; test UNINITIATED."
69 exit $UNINITIATED
70 fi
71 . $UIDMAPENV
72
73 ASSERTIONS=${ASSERTIONS:-"a b c d e f g h i j k l m n o p q"}
74 DESC="client and server have the same mapid domain, "
75
76 function setup
77 {
78 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
79
80 # run test cases on shared directory
81 cd $TESTDIR
82
83 if [ "$Sdomain" != "$Cdomain" ]; then
84 # set up client domain
85 set_local_domain $Sdomain 2>$ERRLOG
86 ckreturn $? "could not set up domain $Sdomain on client" \
87 $ERRLOG "ERROR" || return 1
88 fi
89
90 # create temporary file for testing
91 touch $TESTFILE 2>$ERRLOG
92 ckreturn $? "could not create $TESTFILE" $ERRLOG "ERROR" || return 1
93 }
94
95 function cleanup
96 {
97 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
98
99 # we don't want user can interrupt cleanup procedure
100 trap '' HUP INT QUIT PIPE TERM
101
102 # remove testfile
103 rm -f $TESTFILE 2>$ERRLOG
104 ckreturn $? "could not remove $TESTFILE" $ERRLOG "WARNING"
105
106 # Change to other directory
107 cd $TESTROOT
108
109 restore_local_domain 2>$ERRLOG
110 ckreturn $? "could not restore local domain" $ERRLOG "WARNING"
111
112 # remove temporary file
113 rm -f $ERRLOG
114 ckreturn $? "could not remove $ERRLOG" /dev/null "WARNING"
115 }
116
117 #
118 # assertions using chown/chgrp
119 #
120
121 function as_a
122 {
123 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
124
125 uid=0;user="root"
126
127 exp=$user
128 desc="$DESC""owner set to $uid(chown), "
129 desc="$desc""check it on client(ls)"
130 assertion a "$desc" $exp
131
132 chown $uid $TESTFILE 2>$ERRLOG
133 ckreturn $? "could not chown $TESTFILE" $ERRLOG "UNRESOLVED" \
134 || return 1
135
136 res=$(get_val $OWN $TESTFILE)
137 ckres2 uidmapping "$res" $exp "incorrect user name"
138 }
139
140
141 function as_b
142 {
143 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
144
145 gid=0;group="root"
146
147 exp=$group
148 desc="$DESC""group set to $gid, "
149 desc="$desc""check it on client(ls)"
150 assertion b "$desc" $exp
151
152 chgrp 0 $TESTFILE 2>$ERRLOG
153 ckreturn $? "could not chgrp $TESTFILE" $ERRLOG "UNRESOLVED" \
154 || return 1
155
156 res=$(get_val $GRP $TESTFILE)
157 ckres2 uidmapping "$res" $exp "incorrect group name"
158 }
159
160
161 function as_c
162 {
163 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
164
165 uid=5;user="uucp"
166
167 exp=$user
168 desc="$DESC""known mapable user id $uid, "
169 desc="$desc""change file owner(chown), "
170 desc="$desc""check it on client(ls)"
171 assertion c "$desc" $exp
172
173 chown $uid $TESTFILE 2>$ERRLOG
174 ckreturn $? "could not chown $TESTFILE" $ERRLOG "UNRESOLVED" \
175 || return 1
176
177 res=$(get_val $OWN $TESTFILE)
178 ckres2 uidmapping "$res" $exp "incorrect user name"
179 }
180
181
182 function as_d
183 {
184 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
185
186 gid=5;group="uucp"
187
188 exp=$group
189 desc="$DESC""known mapable group id $gid, "
190 desc="$desc""change file owner_group(chgrp), "
191 desc="$desc""check it on client(ls)"
192 assertion d "$desc" $exp
193
194 chgrp $gid $TESTFILE
195 ckreturn $? "could not chgrp $TESTFILE" $ERRLOG "UNRESOLVED" \
196 || return 1
197
198 res=$(get_val $GRP $TESTFILE)
199 ckres2 uidmapping "$res" $exp "incorrect group name"
200 }
201
202
203 function as_e
204 {
205 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
206
207 user="nuucp";group="nuucp"
208
209 # Assertion e1
210 exp=$user
211 desc="$DESC""known user $user and group $group, "
212 desc="$desc""change file owner and owner_group(chown), "
213 desc="$desc""check owner on client(ls)"
214 assertion e1 "$desc" $exp
215
216 chown nuucp:nuucp $TESTFILE
217 ckreturn $? "could not chown $TESTFILE" $ERRLOG "UNRESOLVED" \
218 || return 1
219
220 res=$(get_val $OWN $TESTFILE)
221 ckres2 uidmapping "$res" $exp "incorrect user name"
222
223 # Assertion e2
224 exp=$group
225 desc="$DESC""known user $user and group $group, "
226 desc="$desc""change file owner and owner_group(chown), "
227 desc="$desc""check group on client(ls)"
228 assertion e2 "$desc" $exp
229
230 res=$(get_val $GRP $TESTFILE)
231 ckres2 uidmapping "$res" $exp "incorrect group name"
232 }
233
234
235 function as_f
236 {
237 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
238
239 uid=$(get_free_id UID)
240 ckreturn $? "could not find free uid on server and client" /dev/null \
241 "UNRESOLVED" || return 1
242
243 exp=$uid
244 desc="$DESC""user id $uid unmappable on client and server, "
245 desc="$desc""change file owner(chown), "
246 desc="$desc""check it on client(ls)"
247 assertion f "$desc" $exp
248
249 chown $uid $TESTFILE 2>$ERRLOG
250 ckreturn $? "could not chown $TESTFILE" $ERRLOG "UNRESOLVED" \
251 || return 1
252
253 res=$(get_val $OWN $TESTFILE)
254 ckres2 uidmapping "$res" $exp "incorrect user id"
255 }
256
257 function as_g
258 {
259 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
260
261 gid=$(get_free_id GID)
262 ckreturn $? "could not find free gid on server and client" /dev/null \
263 "UNRESOLVED" || return 1
264
265 exp=$gid
266 desc="$DESC""group id $gid unmappable on client and server, "
267 desc="$desc""change file owner_group(chgrp), "
268 desc="$desc""check it on client(ls)"
269 assertion g "$desc" $exp
270
271 chgrp $gid $TESTFILE 2>$ERRLOG
272 ckreturn $? "could not chgrp $TESTFILE" $ERRLOG "UNRESOLVED" \
273 || return 1
274
275 res=$(get_val $GRP $TESTFILE)
276 ckres2 uidmapping "$res" $exp "incorrect group id"
277 }
278
279
280 function as_h
281 {
282 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
283
284 uid=$TUSERCID3;user=$TUSERC3
285
286 exp=$user
287 desc="$DESC""common user $user but with different user ids, "
288 desc="$desc""change file owner(chown), "
289 desc="$desc""check it on client(ls)"
290 assertion h "$desc" $exp
291
292 chown $uid $TESTFILE 2>$ERRLOG
293 ckreturn $? "could not chown $TESTFILE" $ERRLOG "UNRESOLVED" \
294 || return 1
295
296 res=$(get_val $OWN $TESTFILE)
297 ckres2 uidmapping "$res" $exp "incorrect user name"
298 }
299
300 function as_i
301 {
302 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
303
304 uid=$TUSERSID;user="nobody"
305
306 exp=$user
307 desc="$DESC""user id only known to server: $uid, "
308 desc="$desc""change file owner(chown), "
309 desc="$desc""check it on client(ls)"
310 assertion i "$desc" $exp
311
312 chown $uid $TESTFILE 2>$ERRLOG
313 ckreturn $? "could not chown $TESTFILE" $ERRLOG "UNRESOLVED" \
314 || return 1
315
316 res=$(get_val $OWN $TESTFILE)
317 ckres2 uidmapping "$res" $exp "incorrect user name"
318 }
319
320 #
321 # assertions using acls
322 #
323
324 function as_j
325 {
326 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
327
328 uid=0;user=root
329
330 exp=$user
331 desc="$DESC""user acl for user $uid set(setfacl), "
332 desc="$desc""check user acl on client(getfacl)"
333 assertion j "$desc" $exp
334
335 setfacl -m user:$uid:rw- $TESTFILE 2>$ERRLOG
336 ckreturn $? "could not setfacl $TESTFILE" $ERRLOG "UNRESOLVED" \
337 || return 1
338
339 res=$(get_acl_val user:$user $TESTFILE)
340 ckres2 uidmapping "$res" $user "incorrect user name"
341
342 setfacl -d user:$uid:rw- $TESTFILE 2>$ERRLOG
343 ckreturn $? "could not setfacl $TESTFILE" $ERRLOG "WARNING"
344 }
345
346
347 function as_k
348 {
349 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
350
351 gid=0;group=root
352
353 exp=$group
354 desc="$DESC""group acl for group $gid set(setfacl), "
355 desc="$desc""check group acl on client(getfacl)"
356 assertion k "$desc" $exp
357
358 setfacl -m group:0:rw- $TESTFILE 2>$ERRLOG
359 ckreturn $? "could not setfacl $TESTFILE" $ERRLOG "UNRESOLVED" \
360 || return 1
361
362 res=$(get_acl_val group:$group $TESTFILE)
363 ckres2 uidmapping "$res" $exp "incorrect group name"
364
365 setfacl -d group:$gid:rw- $TESTFILE 2>$ERRLOG
366 ckreturn $? "could not setfacl $TESTFILE" $ERRLOG "WARNING"
367 }
368
369
370 function as_l
371 {
372 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
373
374 uid=5; user=uucp
375
376 exp=$user
377 desc="$DESC""known mapable user id $uid, "
378 desc="$desc""set user acl(setfacl), "
379 desc="$desc""check user acl on client(getfacl)"
380 assertion l "$desc" $exp
381
382 setfacl -m user:$uid:rw- $TESTFILE 2>$ERRLOG
383 ckreturn $? "could not setfacl $TESTFILE" $ERRLOG "UNRESOLVED" \
384 || return 1
385
386 res=$(get_acl_val user:uucp $TESTFILE)
387 ckres2 uidmapping "$res" $user "incorrect user name"
388
389 setfacl -d user:$uid:rw- $TESTFILE 2>$ERRLOG
390 ckreturn $? "could not setfacl $TESTFILE" $ERRLOG "WARNING"
391 }
392
393
394 function as_m
395 {
396 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
397
398 gid=5; group=uucp
399
400 exp=$group
401 desc="$DESC""known mapable group id $gid, "
402 desc="$desc""set group acl(setfacl), "
403 desc="$desc""check group acl on client(getfacl)"
404 assertion m "$desc" $exp
405
406 setfacl -m group:$gid:r-x $TESTFILE 2>$ERRLOG
407 ckreturn $? "could not setfacl $TESTFILE" $ERRLOG "UNRESOLVED" \
408 || return 1
409
410 res=$(get_acl_val group:$group $TESTFILE)
411 ckres2 uidmapping "$res" $exp "incorrect group name"
412
413 setfacl -d group:$gid:r-x $TESTFILE 2>$ERRLOG
414 ckreturn $? "could not setfacl $TESTFILE" $ERRLOG "WARNING"
415 }
416
417
418 function as_n
419 {
420 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
421
422 user=nuucp; group=nuucp
423
424 # assertion n1
425 exp=$user
426 desc="$DESC""known user $user and group $group, "
427 desc="$desc""set user acl and group acl(setfacl), "
428 desc="$desc""check user acl(getfacl)"
429 assertion n1 "$desc" $exp
430
431 setfacl -m user:nuucp:rw-,group:nuucp:r-x $TESTFILE 2>$ERRLOG
432 ckreturn $? "could not setfacl $TESTFILE" $ERRLOG "UNRESOLVED" \
433 || return 1
434
435 res=$(get_acl_val user:$user $TESTFILE)
436 ckres2 uidmapping "$res" $exp "incorrect user name"
437
438 # assertion n2
439 exp=$group
440 desc="$DESC""known user $user and group $group, "
441 desc="$desc""set user acl and group acl(setfacl), "
442 desc="$desc""check group acl(getfacl)"
443 assertion n2 "$desc" $exp
444
445 res=$(get_acl_val group:$group $TESTFILE)
446 ckres2 uidmapping "$res" $exp "incorrect group name"
447
448 setfacl -d user:nuucp:rw-,group:nuucp:r-x $TESTFILE 2>$ERRLOG
449 ckreturn $? "could not setfacl $TESTFILE" $ERRLOG "WARNING"
450 }
451
452
453 function as_o
454 {
455 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
456
457 uid=$(get_free_id UID)
458 ckreturn $? "could not find free uid on server and client" /dev/null \
459 "UNRESOLVED" || return 1
460
461 exp=$uid
462 desc="$DESC""user id $uid unmappable on server and client, "
463 desc="$desc""set user acl(setfacl), "
464 desc="$desc""check user acl on client(getfacl)"
465 assertion o "$desc" $exp
466
467 setfacl -m user:$uid:rw- $TESTFILE 2>$ERRLOG
468 ckreturn $? "could not setfacl $TESTFILE" $ERRLOG "UNRESOLVED" \
469 || return 1
470
471 res=$(get_acl_val user:$uid $TESTFILE)
472 ckres2 uidmapping "$res" $exp "incorrect user id"
473
474 setfacl -d user:$uid:rw- $TESTFILE 2>$ERRLOG
475 ckreturn $? "could not setfacl $TESTFILE" $ERRLOG "WARNING"
476 }
477
478 function as_p
479 {
480 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
481
482 gid=$(get_free_id GID)
483 ckreturn $? "could not find free gid on server and client" /dev/null \
484 "UNRESOLVED" || return 1
485
486 exp=$gid
487 desc="$DESC""group id $gid unmappable on server and client, "
488 desc="$desc""set group acl(setfacl), "
489 desc="$desc""check group acl on client(getfacl)"
490 assertion p "$desc" $exp
491
492 setfacl -m group:$gid:r-x $TESTFILE 2>$ERRLOG
493 ckreturn $? "could not setfacl $TESTFILE" $ERRLOG "UNRESOLVED" \
494 || return 1
495
496 res=$(get_acl_val group:$gid $TESTFILE)
497 ckres2 uidmapping "$res" $exp "incorrect group id"
498
499 setfacl -d group:$gid:r-x $TESTFILE 2>$ERRLOG
500 ckreturn $? "could not setfacl $TESTFILE" $ERRLOG "WARNING"
501 }
502
503
504 function as_q
505 {
506 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
507
508 uid=$TUSERCID3; user=$TUSERC3
509
510 exp=$user
511 desc="$DESC""common user but with different user ids: $uid, "
512 desc="$desc""set user acl(setfacl), "
513 desc="$desc""check user acl on client(getfacl)"
514 assertion q "$desc" $exp
515
516 setfacl -m user:$uid:rw- $TESTFILE 2>$ERRLOG
517 ckreturn $? "could not setfacl $TESTFILE" $ERRLOG "UNRESOLVED" \
518 || return 1
519
520 res=$(get_acl_val user:$user $TESTFILE)
521 ckres2 uidmapping "$res" $exp "incorrect user name"
522
523 setfacl -d user:$uid:rw- $TESTFILE 2>$ERRLOG
524 ckreturn $? "could not setfacl $TESTFILE" $ERRLOG "WARNING"
525 }
526
527 # set up test environment
528 setup || exit $UNINITIATED
529
530 # main loop
531 for i in $ASSERTIONS
532 do
533 as_$i || print_state
534 done