| 1 | # | 
|---|
| 2 | # @(#) Test the getent command returns domain/local users and groups | 
|---|
| 3 | # | 
|---|
| 4 |  | 
|---|
| 5 | load_lib util-defs.exp | 
|---|
| 6 | load_lib compile.exp | 
|---|
| 7 | load_lib $srcdir/lib/nsswitch-config.exp | 
|---|
| 8 |  | 
|---|
| 9 | # | 
|---|
| 10 | #   @(#) Test getent passwd returns domain users | 
|---|
| 11 | # | 
|---|
| 12 |  | 
|---|
| 13 | set wbinfo_output [util_start "bin/wbinfo" "-u"] | 
|---|
| 14 | set getent_output [util_start "getent" "passwd" ""] | 
|---|
| 15 |  | 
|---|
| 16 | if { ![regexp "$domain/" $getent_output] } { | 
|---|
| 17 | fail "no domain users in getent passwd" | 
|---|
| 18 | return | 
|---|
| 19 | } | 
|---|
| 20 |  | 
|---|
| 21 | if { [regexp "Error" $wbinfo_output] } { | 
|---|
| 22 | fail "wbinfo -u failed" | 
|---|
| 23 | return | 
|---|
| 24 | } | 
|---|
| 25 |  | 
|---|
| 26 | # | 
|---|
| 27 | #   @(#) Test each user in the output of wbinfo is also in the output of | 
|---|
| 28 | #   @(#) getent. | 
|---|
| 29 | # | 
|---|
| 30 |  | 
|---|
| 31 | # Test wbinfo user names are in getent user names | 
|---|
| 32 |  | 
|---|
| 33 | foreach { user } [split $wbinfo_output "\n"] { | 
|---|
| 34 |  | 
|---|
| 35 | verbose "looking for $user" | 
|---|
| 36 |  | 
|---|
| 37 | set test_desc "getent passwd does not contain $user" | 
|---|
| 38 |  | 
|---|
| 39 | if { ![regexp "$user" $getent_output] } { | 
|---|
| 40 | fail $test_desc | 
|---|
| 41 | } else { | 
|---|
| 42 | pass $test_desc | 
|---|
| 43 | } | 
|---|
| 44 | } | 
|---|
| 45 |  | 
|---|
| 46 | # Test getent user names are in wbinfo user names | 
|---|
| 47 |  | 
|---|
| 48 | foreach { user } [split $getent_output "\n"] { | 
|---|
| 49 |  | 
|---|
| 50 | set user_info [split $user ":"] | 
|---|
| 51 | set username [lindex $user_info 0] | 
|---|
| 52 |  | 
|---|
| 53 | if { [regexp {^[^/]+/} $username] } { | 
|---|
| 54 |  | 
|---|
| 55 | set test_desc "wbinfo -u does not contain $username" | 
|---|
| 56 |  | 
|---|
| 57 | if { ![regexp "$username" $wbinfo_output] } { | 
|---|
| 58 | fail $test_desc | 
|---|
| 59 | } else { | 
|---|
| 60 | pass $test_desc | 
|---|
| 61 | } | 
|---|
| 62 | } else { | 
|---|
| 63 | verbose "ignoring non-domain user $username" | 
|---|
| 64 | } | 
|---|
| 65 | } | 
|---|
| 66 |  | 
|---|
| 67 | # | 
|---|
| 68 | #   @(#) Test each group in the output of wbinfo is also in the output of | 
|---|
| 69 | #   @(#) getent. | 
|---|
| 70 | # | 
|---|
| 71 |  | 
|---|
| 72 | set wbinfo_output [util_start "bin/wbinfo" "-g"] | 
|---|
| 73 | set getent_output [util_start "getent" "group" ""] | 
|---|
| 74 |  | 
|---|
| 75 | if { ![regexp "$domain/" $getent_output] } { | 
|---|
| 76 | fail "no domain groups in getent passwd" | 
|---|
| 77 | return | 
|---|
| 78 | } | 
|---|
| 79 |  | 
|---|
| 80 | if { [regexp "Error" $wbinfo_output] } { | 
|---|
| 81 | fail "wbinfo -g failed" | 
|---|
| 82 | return | 
|---|
| 83 | } | 
|---|
| 84 |  | 
|---|
| 85 | # Test wbinfo group names are in getent group names | 
|---|
| 86 |  | 
|---|
| 87 | foreach { group } [split $wbinfo_output "\n"] { | 
|---|
| 88 |  | 
|---|
| 89 | verbose "looking for $group" | 
|---|
| 90 |  | 
|---|
| 91 | set test_desc "getent group does not contain $group" | 
|---|
| 92 |  | 
|---|
| 93 | if { ![regexp "$group" $getent_output] } { | 
|---|
| 94 | fail $test_desc | 
|---|
| 95 | } else { | 
|---|
| 96 | pass $test_desc | 
|---|
| 97 | } | 
|---|
| 98 | } | 
|---|
| 99 |  | 
|---|
| 100 | # Test getent group names are in wbinfo group names | 
|---|
| 101 |  | 
|---|
| 102 | foreach { group } [split $getent_output "\n"] { | 
|---|
| 103 |  | 
|---|
| 104 | set group_info [split $group ":"] | 
|---|
| 105 | set groupname [lindex $group_info 0] | 
|---|
| 106 |  | 
|---|
| 107 | if { [regexp {^[^/]+/} $groupname] } { | 
|---|
| 108 |  | 
|---|
| 109 | set test_desc "wbinfo -g does not contain $groupname" | 
|---|
| 110 |  | 
|---|
| 111 | if { ![regexp "$groupname" $wbinfo_output] } { | 
|---|
| 112 | fail $test_desc | 
|---|
| 113 | } else { | 
|---|
| 114 | pass $test_desc | 
|---|
| 115 | } | 
|---|
| 116 | } else { | 
|---|
| 117 | verbose "ignoring non-domain group $groupname" | 
|---|
| 118 | } | 
|---|
| 119 | } | 
|---|
| 120 |  | 
|---|
| 121 | # | 
|---|
| 122 | #   @(#) Test out of order and repeat calls of pwent functions | 
|---|
| 123 | #   @(#) Test out of order and repeat calls of grent functions | 
|---|
| 124 | # | 
|---|
| 125 |  | 
|---|
| 126 | set getent_tests [list \ | 
|---|
| 127 | { "out of order pwent operations" "getent_pwent" } \ | 
|---|
| 128 | { "out of order grent operations" "getent_grent" } \ | 
|---|
| 129 | ] | 
|---|
| 130 |  | 
|---|
| 131 | # Compile and run each test | 
|---|
| 132 |  | 
|---|
| 133 | foreach { test } $getent_tests { | 
|---|
| 134 | set test_desc [lindex $test 0] | 
|---|
| 135 | set test_file [lindex $test 1] | 
|---|
| 136 |  | 
|---|
| 137 | simple_compile $test_file | 
|---|
| 138 | set output [util_start "$srcdir/$subdir/$test_file" ] | 
|---|
| 139 |  | 
|---|
| 140 | if { [regexp "PASS" $output] } { | 
|---|
| 141 | pass $test_desc | 
|---|
| 142 | file delete "$srcdir/$subdir/$test_file" "$srcdir/$subdir/$test_file.o" | 
|---|
| 143 | } else { | 
|---|
| 144 | fail $test_desc | 
|---|
| 145 | puts $output | 
|---|
| 146 | } | 
|---|
| 147 |  | 
|---|
| 148 | } | 
|---|