lib/popt: Fix typo in README.
[Samba/gbeck.git] / testsuite / nsswitch / wbinfo.exp
blob8be25b2a0f17e1345ff88c7fdbd62692cb5c352d
2 # @(#) Test wbinfo client access to winbind daemon
5 load_lib "util-defs.exp"
6 load_lib "$srcdir/lib/nsswitch-config.exp"
7 load_lib "$srcdir/lib/default-nt-names.exp"
9 # Name types
11 set SID_NAME_USER 1
12 set SID_NAME_DOM_GRP 2
13 set SID_NAME_DOMAIN 3
14 set SID_NAME_ALIAS 4
15 set SID_NAME_UNKNOWN 8
17 # Get list of users and groups
19 set user_list [util_start "bin/wbinfo" "-u"]
20 set group_list [util_start "bin/wbinfo" "-g"]
22 verbose "user list is:\n$user_list"
23 verbose "group list is:\n$group_list"
25 set user_list [split $user_list "\n"]
26 set group_list [split $group_list "\n"]
29 # @(#) Check list of users and groups contain default NT user and group
30 # @(#) names
33 # Users
35 foreach { user } $domain_users {
36 set test_desc "user $user in wbinfo domain users"
37 if {![regexp $user $user_list]} {
38 fail $test_desc
39 } else {
40 pass $test_desc
44 # Groups
46 foreach { group } $domain_groups {
47 set test_desc "group $group in wbinfo domain groups"
48 if {![regexp $group $group_list]} {
49 fail $test_desc
50 } else {
51 pass $test_desc
56 # @(#) Lookup sids for all user and group names returned by wbinfo
59 # Users
61 foreach { user } $user_list {
62 set test_desc "get sid for user $user"
63 set output [util_start "bin/wbinfo" "-n \"$user\""]
65 verbose $output
67 # Split output into name and name_type
69 set list [split $output " "]
70 set sid_type [lindex $list [expr [llength $list] - 1]]
71 set sid [join [lrange $list 0 [expr [llength $list] - 2]] " "]
73 if { ![regexp "S-" $sid] } {
74 fail $test_desc
75 } else {
76 pass $test_desc
79 set test_desc "sid type for user $user"
80 if { $sid_type != $SID_NAME_USER } {
81 fail $test_desc
82 } else {
83 pass $test_desc
86 lappend user_sid_list $sid
89 # Groups
91 foreach { group } $group_list {
92 set test_desc "get sid for group $group"
93 set output [util_start "bin/wbinfo" "-n \"$group\""]
95 verbose $output
97 # Split output into sid and sid type
99 set list [split $output " "]
100 set sid_type [lindex $list [expr [llength $list] - 1]]
101 set sid [join [lrange $list 0 [expr [llength $list] - 2]] " "]
103 if { ![regexp "S-" $sid] } {
104 fail $test_desc
105 } else {
106 pass $test_desc
109 set test_desc "sid type for group group"
110 if { $sid_type != $SID_NAME_DOM_GRP } {
111 fail $test_desc
112 } else {
113 pass $test_desc
116 lappend group_sid_list $sid
120 # @(#) Check reverse lookup of sids to names
123 # Users
125 set count 0
127 foreach { sid } $user_sid_list {
128 set test_desc "reverse user name lookup for sid $sid"
129 set output [util_start "bin/wbinfo" "-s $sid"]
131 verbose $output
133 # Split output into name and name_type
135 set list [split $output " "]
136 set name_type [lindex $list [expr [llength $list] - 1]]
137 set name [join [lrange $list 0 [expr [llength $list] - 2]] " "]
139 if { $name != [lindex $user_list $count] } {
140 fail $test_desc
141 } else {
142 pass $test_desc
145 set test_desc "reverse user name type lookup for sid $sid"
147 if { $name_type != 1 } {
148 fail $test_desc
149 } else {
150 pass $test_desc
153 incr count
156 # Groups
158 set count 0
160 foreach { sid } $group_sid_list {
161 set test_desc "reverse group name lookup for sid $sid"
162 set output [util_start "bin/wbinfo" "-s $sid"]
164 verbose $output
166 # Split output into name and name_type
168 set list [split $output " "]
169 set name_type [lindex $list [expr [llength $list] - 1]]
170 set name [join [lrange $list 0 [expr [llength $list] - 2]] " "]
172 if { $name != [lindex $group_list $count] } {
173 fail $test_desc
174 } else {
175 pass $test_desc
178 set test_desc "reverse group name type lookup for sid $sid"
180 if { $name_type != 2 } {
181 fail $test_desc
182 } else {
183 pass $test_desc
186 incr count
190 # @(#) Cross-check the output of wbinfo -n, getent passwd/group and
191 # @(#) wbinfo -S
194 # Get mapped list of uids from winbindd
196 set output [util_start "getent" "passwd"]
197 set user_list [split $output "\n"]
199 foreach { user_entry } $user_list {
200 if { [regexp $domain $user_entry] } {
201 set field_list [split $user_entry ":"]
202 set name_output [util_start "bin/wbinfo" \
203 "-n \"[lindex $field_list 0]\""]
204 set list [split $name_output " "]
205 set name_type [lindex $list [expr [llength $list] - 1]]
206 set name [join [lrange $list 0 [expr [llength $list] - 2]] " "]
207 set username_uid_sid [lappend username_uid_sid [list \
208 [lindex $field_list 0] \
209 [lindex $field_list 2] \
210 $name]]
214 # Get mapped list of gids from winbindd
216 set output [util_start "getent" "group"]
217 set group_list [split $output "\n"]
219 foreach { group_entry } $group_list {
220 if { [regexp $domain $group_entry] } {
221 set field_list [split $group_entry ":"]
222 set groupname_gid_sid [lappend groupname_gid_sid [list \
223 [lindex $field_list 0] \
224 [lindex $field_list 2] \
225 [util_start "bin/wbinfo" "-n \"[lindex $field_list 0]\""]]]
229 # OK, now we have enough info to cross-check the uid/gid -> sid and
230 # sid -> uid/gid functions
232 foreach { user } $username_uid_sid {
233 set sid [util_start "bin/wbinfo" "-U [lindex $user 1]"]
234 set uid [util_start "bin/wbinfo" "-S [lindex $user 2]"]
236 set test_desc "lookup sid by uid [lindex $user 1]"
238 if { $sid != [lindex $user 2] } {
239 fail $test_desc
240 } else {
241 pass $test_desc
244 set test_desc "lookup uid by sid [lindex $user 2]"
246 if { $uid != [lindex $user 1] } {
247 fail $test_desc
248 } else {
249 pass $test_desc
253 foreach { group } $groupname_gid_sid {
254 set sid [util_start "bin/wbinfo" "-G [lindex $group 1]"]
255 set gid [util_start "bin/wbinfo" "-Y [lindex $group 2]"]
257 set test_desc "lookup sid by gid [lindex $group 1]"
259 if { $sid != [lindex [split [lindex $group 2] " "] 0] ||
260 [lindex [split [lindex $group 2] " " ] 1] != 2 } {
261 fail $test_desc
262 } else {
263 pass $test_desc
266 set test_desc "lookup gid by sid [lindex $group 2]"
268 if { $gid != [lindex $group 1] } {
269 fail $test_desc
270 } else {
271 pass $test_desc
275 # Check exit codes
277 proc check_errcode { args } {
278 global errorCode
279 set test_desc [lindex $args 0]
280 set cmd [lindex $args 1]
281 set result [lindex $args 2]
283 set errorCode ""
284 verbose "Spawning $cmd"
285 catch "exec $cmd" output
286 set exit_code [lindex $errorCode 2]
287 if { $exit_code == "" } { set exit_code 0 }
289 if { $exit_code == $result } {
290 verbose "process returned correct exit code $exit_code"
291 pass $test_desc
292 } else {
293 verbose "process returned bad exit code $exit_code instead of $result"
294 fail $test_desc
298 set gooduser_name [lindex [split [lindex $user_list 0] ":"] 0]
299 set gooduser_sid [util_start "bin/wbinfo" "-n $gooduser_name"]
301 set goodgroup_name [lindex [split [lindex $group_list 0] ":"] 0]
302 set goodgroup_sid [util_start "bin/wbinfo" "-n $goodgroup_name"]
304 # Some conditions not tested:
305 # - bad list users/groups
306 # - good uid/gid to sid
308 set errcode_tests [list \
309 { "exit code, no arg" "bin/wbinfo" 1 } \
310 { "exit code, invalid arg" "bin/wbinfo -@" 1 } \
311 { "exit code, list users" "bin/wbinfo -u" 0 } \
312 { "exit code, list groups" "bin/wbinfo -g" 0 } \
313 { "exit code, good name to sid" "bin/wbinfo -n $gooduser_name" 0 } \
314 { "exit code, bad name to sid" "bin/wbinfo -n asmithee" 1 } \
315 { "exit code, good sid to name" "bin/wbinfo -s $gooduser_sid" 0 } \
316 { "exit code, bad sid to name" "bin/wbinfo -s S-1234" 1 } \
317 { "exit code, bad uid to sid" "bin/wbinfo -U 0" 1 } \
318 { "exit code, bad gid to sid" "bin/wbinfo -G 0" 1} \
319 { "exit code, good sid to uid" "bin/wbinfo -S $gooduser_sid" 0 } \
320 { "exit code, bad sid to uid" "bin/wbinfo -S S-1234" 1 } \
321 { "exit code, good sid to gid" "bin/wbinfo -Y $goodgroup_sid" 0 } \
322 { "exit code, bad sid to gid" "bin/wbinfo -Y S-1234" 1 } \
325 foreach { test } $errcode_tests {
326 check_errcode [lindex $test 0] [lindex $test 1] [lindex $test 2]
329 # Test enumerate trusted domains
331 set test_desc "enumerate trusted domains"
332 set output [util_start "bin/wbinfo" "-m"]
334 verbose $output
336 foreach { the_domain } $output {
337 if { $the_domain == $domain} {
338 fail "own domain appears in trusted list"
342 if {[regexp "Usage" $output] || [regexp "Could not" $output]} {
343 fail $test_desc
344 } else {
345 pass $test_desc
348 # Test check machine account
350 set test_desc "check machine account"
351 set output [util_start "bin/wbinfo" "-t"]
353 verbose $output
355 if {[regexp "Usage" $output] || [regexp "Could not" $output] || \
356 ![regexp "(good|bad)" $output]} {
357 fail $test_desc
358 } else {
359 pass $test_desc