dsdb-operational: Avoid doing the ldb_attr_cmp if bypass flag is not set
[Samba/gebeck_regimport.git] / testsuite / nsswitch / envvar.exp
blob134a8b37a85c72a149c8bcbfb81ef2fb0abc3a07
2 # @(#) Test operation of WINBINDD_DOMAIN environment variable
5 load_lib "util-defs.exp"
6 load_lib "$srcdir/lib/nsswitch-config.exp"
9 # @(#) Test that there is at least one domain user and domain group
10 # @(#) in the output of getent passwd and getent group.
13 # Get list of users and groups
15 set user_list [util_start "getent passwd"]
16 set group_list [util_start "getent group"]
18 verbose "user list is:\n$user_list"
19 verbose "group list is:\n$group_list"
21 # Check for domain users
23 set no_dom 0
25 if { ![regexp "$domain/" $user_list] } {
26 fail "no domain users in getent"
27 set no_dom 1
30 # Check for domain groups
32 if { ![regexp "$domain/" $group_list] } {
33 fail "no domain groups in getent group"
34 set no_dom 1
37 if { $no_dom } {
38 return
42 # @(#) Check for "leakage" between different domains using the
43 # @(#) WINBINDD_DOMAIN environment variable.
46 verbose "Domain is $domain"
48 set output [util_start "bin/wbinfo" "-m"]
49 verbose "Trusted domains are $output"
50 set trusted_domain_list [split $output "\n"]
52 # Test simple inclusion by setting $WINBINDD_DOMAIN to each trusted domain
53 # in turn and checking there are no users/groups from other domains in the
54 # output of getent.
56 set domain_list $trusted_domain_list
57 lappend domain_list $domain
59 foreach { the_domain } $domain_list {
61 set env(WINBINDD_DOMAIN) $the_domain
63 set user_out [util_start "getent passwd"]
64 set group_out [util_start "getent group"]
66 verbose "users in $the_domain:\n$user_out\n"
67 verbose "groups in $the_domain:\n$group_out\n"
69 # Users
71 set test_desc "users in WINBINDD_DOMAIN $the_domain"
72 set failed 0
74 foreach { user } [split $user_out "\n"] {
75 set user_name [lindex [split $user ":"] 0]
76 if { [regexp "/" $user_name] && ![regexp $the_domain $user_name]} {
77 set failed 1
81 if { $failed } {
82 fail $test_desc
83 } else {
84 pass $test_desc
87 # Groups
89 set test_desc "groups in WINBINDD_DOMAIN $the_domain"
90 set failed 0
92 foreach { group } [split $group_out "\n"] {
93 set group_name [lindex [split $group ":"] 0]
94 if { [regexp "/" $group_name] && ![regexp $the_domain $group_name]} {
95 set failed 1
99 if { $failed } {
100 fail $test_desc
101 } else {
102 pass $test_desc
107 # @(#) Test inclusion of a dummy domain doesn't generate users/groups
108 # @(#) from that domain.
111 set env(WINBINDD_DOMAIN) "asmithee"
112 set user_out [util_start "getent passwd"]
113 set group_out [util_start "getent group"]
115 # Users
117 set test_desc "users in different WINBINDD_DOMAIN"
118 if { [regexp $domain $user_out] } {
119 fail $test_desc
120 } else {
121 pass $test_desc
124 # Groups
126 set test_desc "groups in different WINBINDD_DOMAIN"
127 if { [regexp $domain $group_out] } {
128 fail $test_desc
129 } else {
130 pass $test_desc
134 # @(#) Test comma separated inclusion of dummy domain doesn't generate
135 # @(#) users/groups in the dummy domain.
138 foreach { the_domain } $domain_list {
139 set env(WINBINDD_DOMAIN) "$the_domain,asmithee"
140 set user_out [util_start "getent passwd"]
141 set group_out [util_start "getent group"]
143 verbose "users in $the_domain:\n$user_out\n"
144 verbose "groups in $the_domain:\n$group_out\n"
146 # Users
148 set test_desc "users in comma separated WINBINDD_DOMAIN $the_domain"
149 set failed 0
151 foreach { user } [split $user_out "\n"] {
152 set user_name [lindex [split $user ":"] 0]
153 if { [regexp "/" $user_name] && ![regexp $the_domain $user_name]} {
154 set failed 1
158 if { $failed } {
159 fail $test_desc
160 } else {
161 pass $test_desc
164 # Groups
166 set test_desc "groups in comma separated WINBINDD_DOMAIN $the_domain"
167 set failed 0
169 foreach { group } [split $group_out "\n"] {
170 set group_name [lindex [split $group ":"] 0]
171 if { [regexp "/" $group_name] && ![regexp $the_domain $group_name]} {
172 set failed 1
176 if { $failed } {
177 fail $test_desc
178 } else {
179 pass $test_desc
184 # @(#) Test two comma separated dummy domains do not generate any domain
185 # @(#) users or groups.
188 foreach { the_domain } $domain_list {
190 set env(WINBINDD_DOMAIN) "moose,asmithee"
191 set user_out [util_start "getent passwd"]
192 set group_out [util_start "getent group"]
194 verbose "users in $the_domain:\n$user_out\n"
195 verbose "groups in $the_domain:\n$group_out\n"
197 # Users
199 set test_desc "users in comma separated invalid WINBINDD_DOMAIN"
200 if { [regexp $the_domain $user_out] } {
201 fail $test_desc
202 } else {
203 pass $test_desc
206 # Groups
208 set test_desc "groups in comma separated invalid WINBINDD_DOMAIN"
209 if { [regexp $the_domain $group_out] } {
210 fail $test_desc
211 } else {
212 pass $test_desc
216 set env(WINBINDD_DOMAIN) ""
219 # @(#) Test _NO_WINBINDD doesn't return any domain users or groups
222 set env(_NO_WINBINDD) "1"
223 set user_out [util_start "getent passwd"]
224 set group_out [util_start "getent group"]
226 verbose "users with _NO_WINBINDD:\n$user_out\n"
227 verbose "groups with _NO_WINBINDD:\n$group_out\n"
229 foreach { the_domain } $domain_list {
231 # Users
233 set test_desc "users found with _NO_WINBINDD environment variable set"
234 if { [regexp $the_domain $user_out] } {
235 fail $test_desc
236 } else {
237 pass $test_desc
240 # Groups
242 set test_desc "groups found with _NO_WINBINDD environment variable set"
243 if { [regexp $the_domain $group_out] } {
244 fail $test_desc
245 } else {
246 pass $test_desc
250 # Unset _NO_WINBINDD and make sure everything still works
252 unset env(_NO_WINBINDD)
254 set user_out [util_start "getent passwd"]
255 set group_out [util_start "getent group"]
257 verbose "users with _NO_WINBINDD unset:\n$user_out\n"
258 verbose "groups with _NO_WINBINDD unset:\n$group_out\n"
260 # Users
262 set test_desc "no users found with _NO_WINBINDD environment variable set"
263 if { $user_out != $user_list } {
264 fail $test_desc
265 } else {
266 pass $test_desc
269 # Groups
271 set test_desc "no groups found with _NO_WINBINDD environment variable set"
272 if { $group_out != $group_list } {
273 fail $test_desc
274 } else {
275 pass $test_desc
278 # Make sure we unset the environment vars so we don't cause subsequent tests
279 # any grief.
281 catch { unset env(WINBINDD_DOMAIN) } tmp
282 catch { unset env(_NO_WINBINDD) } tmp