summaryrefslogtreecommitdiffstats
path: root/testsuite/nsswitch/envvar.exp
blob: 134a8b37a85c72a149c8bcbfb81ef2fb0abc3a07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#
# @(#) Test operation of WINBINDD_DOMAIN environment variable
#

load_lib "util-defs.exp"
load_lib "$srcdir/lib/nsswitch-config.exp"

#
#   @(#) Test that there is at least one domain user and domain group
#   @(#) in the output of getent passwd and getent group.
#

# Get list of users and groups

set user_list [util_start "getent passwd"]
set group_list [util_start "getent group"]

verbose "user list is:\n$user_list"
verbose "group list is:\n$group_list"

# Check for domain users

set no_dom 0

if { ![regexp "$domain/" $user_list] } {
    fail "no domain users in getent"
    set no_dom 1
}

# Check for domain groups

if { ![regexp "$domain/" $group_list] } {
    fail "no domain groups in getent group"
    set no_dom 1
}

if { $no_dom } {
    return
}

#
#   @(#) Check for "leakage" between different domains using the
#   @(#) WINBINDD_DOMAIN environment variable.
#

verbose "Domain is $domain"

set output [util_start "bin/wbinfo" "-m"]
verbose "Trusted domains are $output"
set trusted_domain_list [split $output "\n"]

# Test simple inclusion by setting $WINBINDD_DOMAIN to each trusted domain
# in turn and checking there are no users/groups from other domains in the
# output of getent.

set domain_list $trusted_domain_list
lappend domain_list $domain

foreach { the_domain } $domain_list {

    set env(WINBINDD_DOMAIN) $the_domain

    set user_out [util_start "getent passwd"]
    set group_out [util_start "getent group"]

    verbose "users in $the_domain:\n$user_out\n"
    verbose "groups in $the_domain:\n$group_out\n"

    # Users

    set test_desc "users in WINBINDD_DOMAIN $the_domain"
    set failed 0

    foreach { user } [split $user_out "\n"] {
	set user_name [lindex [split $user ":"] 0]
	if { [regexp "/" $user_name] && ![regexp $the_domain $user_name]} {
	    set failed 1
	}
    }
    
    if { $failed } {
	fail $test_desc
    } else {
	pass $test_desc
    }

    # Groups

    set test_desc "groups in WINBINDD_DOMAIN $the_domain"
    set failed 0
    
    foreach { group } [split $group_out "\n"] {
	set group_name [lindex [split $group ":"] 0]
	if { [regexp "/" $group_name] && ![regexp $the_domain $group_name]} {
	    set failed 1
	}
    }

    if { $failed } {
	fail $test_desc
    } else {
	pass $test_desc
    }
}

#
#   @(#) Test inclusion of a dummy domain doesn't generate users/groups
#   @(#) from that domain.
#

set env(WINBINDD_DOMAIN) "asmithee"
set user_out [util_start "getent passwd"]
set group_out [util_start "getent group"]

# Users

set test_desc "users in different WINBINDD_DOMAIN"
if { [regexp $domain $user_out] } {
    fail $test_desc
} else {
    pass $test_desc
}

# Groups

set test_desc "groups in different WINBINDD_DOMAIN"
if { [regexp $domain $group_out] } {
    fail $test_desc
} else {
    pass $test_desc
}

#
#   @(#) Test comma separated inclusion of dummy domain doesn't generate
#   @(#) users/groups in the dummy domain.
#

foreach { the_domain } $domain_list {
    set env(WINBINDD_DOMAIN) "$the_domain,asmithee"
    set user_out [util_start "getent passwd"]
    set group_out [util_start "getent group"]

    verbose "users in $the_domain:\n$user_out\n"
    verbose "groups in $the_domain:\n$group_out\n"

    # Users

    set test_desc "users in comma separated WINBINDD_DOMAIN $the_domain"
    set failed 0

    foreach { user } [split $user_out "\n"] {
	set user_name [lindex [split $user ":"] 0]
	if { [regexp "/" $user_name] && ![regexp $the_domain $user_name]} {
	    set failed 1
	}
    }

    if { $failed } {
	fail $test_desc
    } else {
	pass $test_desc
    }

    # Groups

    set test_desc "groups in comma separated WINBINDD_DOMAIN $the_domain"
    set failed 0
    
    foreach { group } [split $group_out "\n"] {
	set group_name [lindex [split $group ":"] 0]
	if { [regexp "/" $group_name] && ![regexp $the_domain $group_name]} {
	    set failed 1
	}
    }
    
    if { $failed } {
	fail $test_desc
    } else {
	pass $test_desc
    }
}

#
#   @(#) Test two comma separated dummy domains do not generate any domain
#   @(#) users or groups.
#

foreach { the_domain } $domain_list {

    set env(WINBINDD_DOMAIN) "moose,asmithee"
    set user_out [util_start "getent passwd"]
    set group_out [util_start "getent group"]

    verbose "users in $the_domain:\n$user_out\n"
    verbose "groups in $the_domain:\n$group_out\n"

    # Users

    set test_desc "users in comma separated invalid WINBINDD_DOMAIN"
    if { [regexp $the_domain $user_out] } {
	fail $test_desc
    } else {
	pass $test_desc
    }

    # Groups
    
    set test_desc "groups in comma separated invalid WINBINDD_DOMAIN"
    if { [regexp $the_domain $group_out] } {
	fail $test_desc
    } else {
	pass $test_desc
    }
}

set env(WINBINDD_DOMAIN) ""

#
#   @(#) Test _NO_WINBINDD doesn't return any domain users or groups
#

set env(_NO_WINBINDD) "1"
set user_out [util_start "getent passwd"]
set group_out [util_start "getent group"]

verbose "users with _NO_WINBINDD:\n$user_out\n"
verbose "groups with _NO_WINBINDD:\n$group_out\n"

foreach { the_domain } $domain_list {

    # Users

    set test_desc "users found with _NO_WINBINDD environment variable set"
    if { [regexp $the_domain $user_out] } {
	fail $test_desc
    } else {
	pass $test_desc
    }

    # Groups
    
    set test_desc "groups found with _NO_WINBINDD environment variable set"
    if { [regexp $the_domain $group_out] } {
	fail $test_desc
    } else {
	pass $test_desc
    }
}

# Unset _NO_WINBINDD and make sure everything still works

unset env(_NO_WINBINDD)

set user_out [util_start "getent passwd"]
set group_out [util_start "getent group"]

verbose "users with _NO_WINBINDD unset:\n$user_out\n"
verbose "groups with _NO_WINBINDD unset:\n$group_out\n"

# Users

set test_desc "no users found with _NO_WINBINDD environment variable set"
if { $user_out != $user_list } {
    fail $test_desc
} else {
    pass $test_desc
}

# Groups

set test_desc "no groups found with _NO_WINBINDD environment variable set"
if { $group_out != $group_list } {
    fail $test_desc
} else {
    pass $test_desc
}

# Make sure we unset the environment vars so we don't cause subsequent tests
# any grief.

catch { unset env(WINBINDD_DOMAIN) } tmp
catch { unset env(_NO_WINBINDD) } tmp