1 #
2 # CDDL HEADER START
3 #
4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
7 #
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
12 #
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
18 #
19 # CDDL HEADER END
20 #
21
22 #
23 # Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
25 #
26 # UID Mapping testing.
27
28 # TESTROOT directory; must be set in the environment already
29 set TESTROOT $env(TESTROOT)
30
31 # ROOTDIR directory; must be set in the environment already
32 set ROOTDIR $env(ROOTDIR)
33
34 source [file join ${TESTROOT} tcl.init]
35 source [file join ${TESTROOT} testproc]
36 source [file join ${TESTROOT} lcltools]
37
38 # setting local variables
39 set TNAME $argv0
40
41 if {[info exists env(DNS_SERVER)] == 1} {
42 set domain [get_domain $env(SERVER) $env(DNS_SERVER)]
43 } else {
44 set domain [get_domain $env(SERVER)]
45 }
46 if {$domain == $NULL} {
47 putmsg stderr 0 "\t$TNAME: unable to determine the domain."
48 putmsg stderr 0 "\tAssertions won't be executed."
49 exit $UNINITIATED
50 }
51
52 # connect to the test server
53 Connect
54
55 set attrs {owner owner_group}
56
57 # get file file handle, ROOTDIR is mounted with option root=<this host>
58 set tag $TNAME.setup
59 set TESTFILE [file join $ROOTDIR "$TNAME"]
60 set clientid ""
61 set stateid ""
62 set seqid ""
63 set fh [openv4 $TESTFILE clientid stateid seqid]
64 if { $fh == $NULL } {
65 putmsg stderr 0 "$TNAME{all}:"
66 putmsg stderr 0 "\tTest UNINITIATED: unable to create temp file."
67 exit $UNINITIATED
68 }
69
70 set orig_attr [getfileowner $fh]
71 if { $orig_attr == $NULL } {
72 putmsg stderr 0 "$TNAME{all}:"
73 putmsg stderr 0 "\tTest UNINITIATED: unable to get $TESTFILE attributes"
74 exit $UNINITIATED
75 }
76
77 set Oown [lindex $orig_attr 0]
78 set Ogrp [lindex $orig_attr 1]
79
80 # Start testing
81 # --------------------------------------------------------------
82
83 # a: invalid chars in owner
84 set tag $TNAME{a}
85 set expct "BADOWNER"
86 set ASSERTION "invalid chars in owner, expect $expct"
87 putmsg stdout 0 "$tag: $ASSERTION"
88 set owner "owner :+\t\n\r@$domain"
89 set group ""
90 set st [uid_map $fh $stateid owner group res $Oown $Ogrp]
91 ckres "uid_mapping" $st $expct $res $PASS
92
93
94 # b: invalid chars in group
95 set tag $TNAME{b}
96 set expct "BADOWNER"
97 set ASSERTION "invalid chars in group, expect $expct"
98 putmsg stdout 0 "$tag: $ASSERTION"
99 set owner ""
100 set group "group :\t\n\r@$domain"
101 set st [uid_map $fh $stateid owner group res $Oown $Ogrp]
102 ckres "uid_mapping" $st $expct $res $PASS
103
104
105 # c: negative owner id
106 set tag $TNAME{c}
107 set expct "BADOWNER"
108 set ASSERTION "negative owner id, expect $expct"
109 putmsg stdout 0 "$tag: $ASSERTION"
110 set owner -1
111 set group ""
112 set st [uid_map $fh $stateid owner group res $Oown $Ogrp]
113 ckres "uid_mapping" $st $expct $res $PASS
114
115
116 # d: negative group id
117 set tag $TNAME{d}
118 set expct "BADOWNER"
119 set ASSERTION "negative group id, expect $expct"
120 putmsg stdout 0 "$tag: $ASSERTION"
121 set owner ""
122 set group -1
123 set st [uid_map $fh $stateid owner group res $Oown $Ogrp]
124 ckres "uid_mapping" $st $expct $res $PASS
125
126
127 # e: overflowed owner id
128 set tag $TNAME{e}
129 set expct "BADOWNER"
130 set ASSERTION "overflowed owner id, expect $expct"
131 putmsg stdout 0 "$tag: $ASSERTION"
132 set owner [string repeat "9" 20]
133 set group ""
134 set st [uid_map $fh $stateid owner group res $Oown $Ogrp]
135 ckres "uid_mapping" $st $expct $res $PASS
136
137
138 # f: overflowed group id
139 set tag $TNAME{f}
140 set expct "BADOWNER"
141 set ASSERTION "overflowed group id, expect $expct"
142 putmsg stdout 0 "$tag: $ASSERTION"
143 set owner ""
144 set group [string repeat "9" 20]
145 set st [uid_map $fh $stateid owner group res $Oown $Ogrp]
146 ckres "uid_mapping" $st $expct $res $PASS
147
148
149 # g: invalid chars in domain
150 set tag $TNAME{g}
151 set expct "BADOWNER"
152 set ASSERTION "invalid chars in domain, expect $expct"
153 putmsg stdout 0 "$tag: $ASSERTION"
154 set owner "uucp@eng+ :sun\t\n\rcom"
155 set group ""
156 set st [uid_map $fh $stateid owner group res $Oown $Ogrp]
157 ckres "uid_mapping" $st $expct $res $PASS
158
159
160 # g1: invalid extra @ char in domain
161 set tag $TNAME{g1}
162 set expct "BADOWNER"
163 set ASSERTION "invalid extra @ char in domain, expect $expct"
164 putmsg stdout 0 "$tag: $ASSERTION"
165 set owner "uucp@@$domain"
166 set group ""
167 set st [uid_map $fh $stateid owner group res $Oown $Ogrp]
168 ckres "uid_mapping" $st $expct $res $PASS
169
170
171 # h: invalid UTF8 in owner
172 # 4748963 uid mapping is not checking for invalid chars
173 set tag $TNAME{h}
174 set expct "OK"
175 set ASSERTION "valid UTF8 in owner, expect $expct"
176 putmsg stdout 0 "$tag: $ASSERTION"
177 putmsg stdout 0 "\tTest UNTESTED: nfsmapid is not enforcing valid UTF8 codes"
178 # values in hex:
179 # df ff ef ff ff f7 ff ff ff fb ff ff ff ff fd ff ff ff ff ff 00 00
180 #set enc [encoding system]
181 #set res [encoding system identity]
182 #set owner [exec echo $::env(BAD_UTF8)]
183 #append owner "@$domain"
184 #set group ""
185 #set res [encoding system $enc]
186 #set st [uid_map $fh $stateid owner group res $Oown $Ogrp]
187 #ckres "uid_mapping" $st $expct $res $PASS
188
189
190 # i: invalid UTF8 in group
191 # 4748963 uid mapping is not checking for invalid chars
192 set tag $TNAME{i}
193 set expct "OK"
194 set ASSERTION "invalid UTF8 in group, expect $expct"
195 putmsg stdout 0 "$tag: $ASSERTION"
196 putmsg stdout 0 "\tTest UNTESTED: nfsmapid is not enforcing valid UTF8 codes"
197 # values in hex:
198 # df ff ef ff ff f7 ff ff ff fb ff ff ff ff fd ff ff ff ff ff 00 00
199 #set enc [encoding system]
200 #set res [encoding system identity]
201 #set owner ""
202 #set group [exec echo $::env(BAD_UTF8)]
203 #append group "@$domain"
204 #set res [encoding system $enc]
205 #set st [uid_map $fh $stateid owner group res $Oown $Ogrp]
206 #ckres "uid_mapping" $st $expct $res $PASS
207
208
209 # j: unknown owner
210 set tag $TNAME{j}
211 set expct "BADOWNER"
212 set ASSERTION "unknown owner, expect $expct"
213 putmsg stdout 0 "$tag: $ASSERTION"
214 set owner "[ownid j]@$domain"
215 set group ""
216 set st [uid_map $fh $stateid owner group res $Oown $Ogrp]
217 ckres "uid_mapping" $st $expct $res $PASS
218
219
220 # k: unknown group
221 set tag $TNAME{k}
222 set expct "BADOWNER"
223 set ASSERTION "unknown group, expect $expct"
224 putmsg stdout 0 "$tag: $ASSERTION"
225 set owner ""
226 set group "[grpid k]@$domain"
227 set st [uid_map $fh $stateid owner group res $Oown $Ogrp]
228 ckres "uid_mapping" $st $expct $res $PASS
229
230
231 # l: unknown owner and group
232 set tag $TNAME{l}
233 set expct "BADOWNER"
234 set ASSERTION "unknown owner and group, expect $expct"
235 putmsg stdout 0 "$tag: $ASSERTION"
236 set owner "[ownid l]@$domain"
237 set group "[grpid l]@$domain"
238 set st [uid_map $fh $stateid owner group res $Oown $Ogrp]
239 ckres "uid_mapping" $st $expct $res $PASS
240
241
242 # m: known user, known group, no domain sent
243 set tag $TNAME{m}
244 set expct "BADOWNER|OK"
245 set ASSERTION "known user, known group, no domain sent, expect $expct"
246 putmsg stdout 0 "$tag: $ASSERTION"
247 set owner "nuucp"
248 set group "nuucp"
249 set st [uid_map $fh $stateid owner group res $Oown $Ogrp]
250 ckres "uid_mapping" $st $expct $res $PASS
251
252
253 # o: known owner, unknown domain
254 set tag $TNAME{o}
255 set expct "BADOWNER"
256 set ASSERTION "known owner, unknown domain, expect $expct"
257 putmsg stdout 0 "$tag: $ASSERTION"
258 set owner "uucp@noexist.sun.com"
259 set group ""
260 set st [uid_map $fh $stateid owner group res $Oown $Ogrp]
261 ckres "uid_mapping" $st $expct $res $PASS
262
263
264 # p: known group, unknown domain
265 set tag $TNAME{p}
266 set expct "BADOWNER"
267 set ASSERTION "known group, unknown domain, expect $expct"
268 putmsg stdout 0 "$tag: $ASSERTION"
269 set owner ""
270 set group "staff@noexist.sun.com"
271 set st [uid_map $fh $stateid owner group res $Oown $Ogrp]
272 ckres "uid_mapping" $st $expct $res $PASS
273
274
275 # u: user known only to client
276 set tag $TNAME{u}
277 set expct "BADOWNER"
278 set ASSERTION "user known only to client, expect $expct"
279 putmsg stdout 0 "$tag: $ASSERTION"
280 set owner "$::env(TUSERC)@$domain"
281 set group ""
282 set st [uid_map $fh $stateid owner group res $Oown $Ogrp]
283 ckres "uid_mapping" $st $expct $res $PASS
284
285
286 # w: user known only to client with common user id
287 set tag $TNAME{w}
288 set expct "BADOWNER"
289 set ASSERTION "user known only to client with common user id, expect $expct"
290 putmsg stdout 0 "$tag: $ASSERTION"
291 set owner "$::env(TUSERC2)@$domain"
292 set group ""
293 set st [uid_map $fh $stateid owner group res $Oown $Ogrp]
294 ckres "uid_mapping" $st $expct $res $PASS
295
296
297 # close file
298 set tag $TNAME.cleanup
299 set fh [closev4 $TESTFILE $fh $stateid $seqid]
300 if { $fh == $NULL } {
301 putmsg stderr 0 "\tWARNING: unable to close or delete temp file."
302 }
303
304
305 # --------------------------------------------------------------
306 # disconnect and exit
307
308 Disconnect
309 exit $PASS
310