summaryrefslogtreecommitdiffstats
path: root/testsuite/nsswitch/getent.exp
blob: 72bf2ea1ebec60252c6b4f72aa8cdf66956ce7f3 (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
#
# @(#) Test the getent command returns domain/local users and groups
#

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

#
#   @(#) Test getent passwd returns domain users
#

set wbinfo_output [util_start "bin/wbinfo" "-u"]
set getent_output [util_start "getent" "passwd" ""]

if { ![regexp "$domain/" $getent_output] } {
    fail "no domain users in getent passwd"
    return
}

if { [regexp "Error" $wbinfo_output] } {
    fail "wbinfo -u failed"
    return
}

#
#   @(#) Test each user in the output of wbinfo is also in the output of
#   @(#) getent.
#

# Test wbinfo user names are in getent user names

foreach { user } [split $wbinfo_output "\n"] {

    verbose "looking for $user"

    set test_desc "getent passwd does not contain $user"

    if { ![regexp "$user" $getent_output] } {
        fail $test_desc
    } else {
        pass $test_desc
    }
}

# Test getent user names are in wbinfo user names

foreach { user } [split $getent_output "\n"] {

    set user_info [split $user ":"]
    set username [lindex $user_info 0]

    if { [regexp {^[^/]+/} $username] } {

	set test_desc "wbinfo -u does not contain $username"

	if { ![regexp "$username" $wbinfo_output] } {
	    fail $test_desc
	} else {
	    pass $test_desc
	}
    } else {
	verbose "ignoring non-domain user $username"
    }
}

#
#   @(#) Test each group in the output of wbinfo is also in the output of
#   @(#) getent.
#

set wbinfo_output [util_start "bin/wbinfo" "-g"]
set getent_output [util_start "getent" "group" ""]

if { ![regexp "$domain/" $getent_output] } {
    fail "no domain groups in getent passwd"
    return
}

if { [regexp "Error" $wbinfo_output] } {
    fail "wbinfo -g failed"
    return
}

# Test wbinfo group names are in getent group names

foreach { group } [split $wbinfo_output "\n"] {

    verbose "looking for $group"

    set test_desc "getent group does not contain $group"

    if { ![regexp "$group" $getent_output] } {
        fail $test_desc
    } else {
        pass $test_desc
    }
}

# Test getent group names are in wbinfo group names

foreach { group } [split $getent_output "\n"] {

    set group_info [split $group ":"]
    set groupname [lindex $group_info 0]

    if { [regexp {^[^/]+/} $groupname] } {

	set test_desc "wbinfo -g does not contain $groupname"

	if { ![regexp "$groupname" $wbinfo_output] } {
	    fail $test_desc
	} else {
	    pass $test_desc
	}
    } else {
	verbose "ignoring non-domain group $groupname"
    }
}

#
#   @(#) Test out of order and repeat calls of pwent functions
#   @(#) Test out of order and repeat calls of grent functions
#

set getent_tests [list \
	{ "out of order pwent operations" "getent_pwent" } \
	{ "out of order grent operations" "getent_grent" } \
	]

# Compile and run each test

foreach { test } $getent_tests {
    set test_desc [lindex $test 0]
    set test_file [lindex $test 1]

    simple_compile $test_file
    set output [util_start "$srcdir/$subdir/$test_file" ]

    if { [regexp "PASS" $output] } {
        pass $test_desc
        file delete "$srcdir/$subdir/$test_file" "$srcdir/$subdir/$test_file.o"
    } else {
        fail $test_desc
        puts $output
    }

}