48e7dcb2be751bdc3ec0f7f2901318d983fbf76e
[tprouty/samba.git] / testsuite / nsswitch / getpwuid.exp
1 #
2 # @(#) Test reverse lookup of user ids from getent match getpwuid() output
3 #
4
5 load_lib util-defs.exp
6 load_lib "$srcdir/config/env.exp"
7 load_lib "$srcdir/config/default-nt-names.exp"
8
9 # Compile getpwuid.c
10
11 set output [target_compile "$srcdir/$subdir/getpwuid.c" \
12         "$srcdir/$subdir/getpwuid" executable {additional_flags="-g"}]
13
14 if {$output != ""} {
15     perror "compile getpwuid"
16     puts $output
17     return
18 }
19
20 # Get list of uids using getent
21
22 set output [util_start "getent" "passwd" ""]
23 set got_entries 0
24
25 foreach {line} [split $output "\n"] {
26
27     # Process user
28
29     set pwd_entry [split $line ":"]
30     set user [lindex $pwd_entry 0]
31
32     if {[regexp "^($domain)/" $user]} {
33
34         set got_entries 1
35
36         # Only lookup winbindd users
37
38         set uid [lindex $pwd_entry 2]
39         set gid [lindex $pwd_entry 3]
40
41         # Test lookup of uid succeeds
42
43         set output [util_start "$srcdir/$subdir/getpwuid" "$uid" ""]
44         if {[regexp "PASS:" $output]} {
45             pass "getpwuid $uid ($user)"
46         } else {
47             fail "getpwuid $uid ($user)"
48         }            
49     }
50 }
51
52 if {!$got_entries} {
53     perror "No domain users returned from getent"
54 }