blob: 2cd43a7ffe2cdba7203b8af87f21ff953ec5cf0a (
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
|
#!/bin/sh
#
# Test id mapping with various SIDs and idmap_rid
#
if [ $# -lt 1 ]; then
echo Usage: $0 DOMAIN RANGE_START
exit 1
fi
DOMAIN="$1"
RANGE_START="$2"
wbinfo="$VALGRIND $BINDIR/wbinfo"
failed=0
. $(dirname $0)/../../testprogs/blackbox/subunit.sh
DOMAIN_SID=$($wbinfo -n "$DOMAIN/" | cut -f 1 -d " ")
if [ $? -ne 0 ]; then
echo "Could not find domain SID" | subunit_fail_test "test_idmap_rid"
exit 1
fi
# Find an unused uid and SID
RID=66666
MAX_RID=77777
while true; do
id $RID
if [ $? -ne 0 ]; then
SID="$DOMAIN_SID-$RID"
$wbinfo -s $SID
if [ $? -ne 0 ]; then
break
fi
fi
RID=$(expr $RID + 1)
if [ $RID -eq $MAX_RID ]; then
echo "Could not find free SID" | subunit_fail_test "test_idmap_rid"
exit 1
fi
done
#
# Test 1: Using non-existing SID to check backend returns a mapping
#
EXPECTED_ID=$(expr $RID + $RANGE_START)
out="$($wbinfo --sids-to-unix-ids=$SID)"
echo "wbinfo returned: \"$out\", expecting \"$SID -> uid/gid $EXPECTED_ID\""
test "$out" = "$SID -> uid/gid $EXPECTED_ID"
ret=$?
testit "Unknown RID from primary domain returns a mapping" test $ret -eq 0 || failed=$(expr $failed + 1)
#
# Test 2: Using bogus SID with bad domain part to check idmap backend does not generate a mapping
#
SID=S-1-5-21-1111-2222-3333-666
out="$($wbinfo --sids-to-unix-ids=$SID)"
echo "wbinfo returned: \"$out\", expecting \"$SID -> unmapped\""
test "$out" = "$SID -> unmapped"
ret=$?
testit "Bogus SID returns unmapped" test $ret -eq 0 || failed=$(expr $failed + 1)
#
# Test 3: ID_TYPE_BOTH mappings for group
#
GROUP="$DOMAIN/Domain Users"
GROUP_SID=$($wbinfo --name-to-sid="$GROUP" | sed -e 's/ .*//')
uid=$($wbinfo --sid-to-uid=$GROUP_SID)
ret=$?
testit "ID_TYPE_BOTH group map to uid succeeds" test $ret -eq 0 ||
failed=$(expr $failed + 1)
testit "ID_TYPE_BOTH group map to uid has result" test -n $uid ||
failed=$(expr $failed + 1)
gid=$($wbinfo --sid-to-gid=$GROUP_SID)
ret=$?
testit "ID_TYPE_BOTH group map to gid succeeds" test $ret -eq 0 ||
failed=$(expr $failed + 1)
testit "ID_TYPE_BOTH group map to gid has result" test -n $gid ||
failed=$(expr $failed + 1)
testit "ID_TYPE_BOTH group uid equals gid" test $uid -eq $gid ||
failed=$(expr $failed + 1)
group_pw="$DOMAIN/domain users:*:$uid:$gid::/home/$DOMAIN/domain users:/bin/false"
out=$(getent passwd "$GROUP")
ret=$?
testit "getpwnam for ID_TYPE_BOTH group succeeds" test $ret -eq 0 ||
failed=$(expr $failed + 1)
test "$out" = "$group_pw"
ret=$?
testit "getpwnam for ID_TYPE_BOTH group output" test $ret -eq 0 ||
failed=$(expr $failed + 1)
out=$(getent passwd $uid)
ret=$?
testit "getpwuid for ID_TYPE_BOTH group succeeds" test $ret -eq 0 ||
failed=$(expr $failed + 1)
test "$out" = "$group_pw"
ret=$?
testit "getpwuid for ID_TYPE_BOTH group output" test $ret -eq 0 ||
failed=$(expr $failed + 1)
group_gr="$DOMAIN/domain users:x:$gid"
out=$(getent group "$GROUP")
ret=$?
testit "getgrnam for ID_TYPE_BOTH group succeeds" test $ret -eq 0 ||
failed=$(expr $failed + 1)
# Compare only 'groupname:x:gid' part, drop the members
normalized_out=$(echo "$out" | cut -d: -f1-3)
test "$normalized_out" = "$group_gr"
ret=$?
testit "getgrnam for ID_TYPE_BOTH group output" test $ret -eq 0 ||
failed=$(expr $failed + 1)
out=$(getent group "$gid")
ret=$?
testit "getgrgid for ID_TYPE_BOTH group succeeds" test $ret -eq 0 ||
failed=$(expr $failed + 1)
# Compare only 'groupname:x:gid' part, drop the members
normalized_out=$(echo "$out" | cut -d: -f1-3)
test "$normalized_out" = "$group_gr"
ret=$?
testit "getgrgid for ID_TYPE_BOTH group output" test $ret -eq 0 ||
failed=$(expr $failed + 1)
#
# Test 4: ID_TYPE_BOTH mappings for user
#
dom_users_gid=$gid
USER="$DOMAIN/Administrator"
USER_SID=$($wbinfo --name-to-sid="$USER" | sed -e 's/ .*//')
uid=$($wbinfo --sid-to-uid=$USER_SID)
ret=$?
testit "ID_TYPE_BOTH user map to uid succeeds" test $ret -eq 0 ||
failed=$(expr $failed + 1)
testit "ID_TYPE_BOTH user map to uid has result" test -n $uid ||
failed=$(expr $failed + 1)
gid=$($wbinfo --sid-to-gid=$USER_SID)
ret=$?
testit "ID_TYPE_BOTH user map to gid succeeds" test $ret -eq 0 ||
failed=$(expr $failed + 1)
testit "ID_TYPE_BOTH user map to gid has result" test -n $gid ||
failed=$(expr $failed + 1)
testit "ID_TYPE_BOTH user uid equals gid" test $uid -eq $gid ||
failed=$(expr $failed + 1)
user_pw="$DOMAIN/administrator:*:$uid:$dom_users_gid::/home/$DOMAIN/administrator:/bin/false"
out=$(getent passwd "$USER")
ret=$?
testit "getpwnam for ID_TYPE_BOTH user succeeds" test $ret -eq 0 ||
failed=$(expr $failed + 1)
test "$out" = "$user_pw"
ret=$?
testit "getpwnam for ID_TYPE_BOTH user output" test $ret -eq 0 ||
failed=$(expr $failed + 1)
out=$(getent passwd $uid)
ret=$?
testit "getpwuid for ID_TYPE_BOTH user succeeds" test $ret -eq 0 ||
failed=$(expr $failed + 1)
test "$out" = "$user_pw"
ret=$?
testit "getpwuid for ID_TYPE_BOTH user output" test $ret -eq 0 ||
failed=$(expr $failed + 1)
user_gr="$DOMAIN/administrator:x:$gid:$DOMAIN/administrator"
out=$(getent group "$USER")
ret=$?
testit "getgrnam for ID_TYPE_BOTH user succeeds" test $ret -eq 0 ||
failed=$(expr $failed + 1)
test "$out" = "$user_gr"
ret=$?
testit "getgrnam for ID_TYPE_BOTH user output" test $ret -eq 0 ||
failed=$(expr $failed + 1)
out=$(getent group "$gid")
ret=$?
testit "getgrgid for ID_TYPE_BOTH user succeeds" test $ret -eq 0 ||
failed=$(expr $failed + 1)
test "$out" = "$user_gr"
ret=$?
testit "getgrgid for ID_TYPE_BOTH user output" test $ret -eq 0 ||
failed=$(expr $failed + 1)
exit $failed
|