libads: Make ads_cldap_netlogon() static
[samba4-gss.git] / nsswitch / tests / test_idmap_rid.sh
blob2cd43a7ffe2cdba7203b8af87f21ff953ec5cf0a
1 #!/bin/sh
3 # Test id mapping with various SIDs and idmap_rid
6 if [ $# -lt 1 ]; then
7 echo Usage: $0 DOMAIN RANGE_START
8 exit 1
9 fi
11 DOMAIN="$1"
12 RANGE_START="$2"
14 wbinfo="$VALGRIND $BINDIR/wbinfo"
15 failed=0
17 . $(dirname $0)/../../testprogs/blackbox/subunit.sh
19 DOMAIN_SID=$($wbinfo -n "$DOMAIN/" | cut -f 1 -d " ")
20 if [ $? -ne 0 ]; then
21 echo "Could not find domain SID" | subunit_fail_test "test_idmap_rid"
22 exit 1
25 # Find an unused uid and SID
26 RID=66666
27 MAX_RID=77777
28 while true; do
29 id $RID
30 if [ $? -ne 0 ]; then
31 SID="$DOMAIN_SID-$RID"
32 $wbinfo -s $SID
33 if [ $? -ne 0 ]; then
34 break
37 RID=$(expr $RID + 1)
38 if [ $RID -eq $MAX_RID ]; then
39 echo "Could not find free SID" | subunit_fail_test "test_idmap_rid"
40 exit 1
42 done
45 # Test 1: Using non-existing SID to check backend returns a mapping
48 EXPECTED_ID=$(expr $RID + $RANGE_START)
49 out="$($wbinfo --sids-to-unix-ids=$SID)"
50 echo "wbinfo returned: \"$out\", expecting \"$SID -> uid/gid $EXPECTED_ID\""
51 test "$out" = "$SID -> uid/gid $EXPECTED_ID"
52 ret=$?
53 testit "Unknown RID from primary domain returns a mapping" test $ret -eq 0 || failed=$(expr $failed + 1)
56 # Test 2: Using bogus SID with bad domain part to check idmap backend does not generate a mapping
59 SID=S-1-5-21-1111-2222-3333-666
60 out="$($wbinfo --sids-to-unix-ids=$SID)"
61 echo "wbinfo returned: \"$out\", expecting \"$SID -> unmapped\""
62 test "$out" = "$SID -> unmapped"
63 ret=$?
64 testit "Bogus SID returns unmapped" test $ret -eq 0 || failed=$(expr $failed + 1)
67 # Test 3: ID_TYPE_BOTH mappings for group
70 GROUP="$DOMAIN/Domain Users"
71 GROUP_SID=$($wbinfo --name-to-sid="$GROUP" | sed -e 's/ .*//')
73 uid=$($wbinfo --sid-to-uid=$GROUP_SID)
74 ret=$?
75 testit "ID_TYPE_BOTH group map to uid succeeds" test $ret -eq 0 ||
76 failed=$(expr $failed + 1)
77 testit "ID_TYPE_BOTH group map to uid has result" test -n $uid ||
78 failed=$(expr $failed + 1)
80 gid=$($wbinfo --sid-to-gid=$GROUP_SID)
81 ret=$?
82 testit "ID_TYPE_BOTH group map to gid succeeds" test $ret -eq 0 ||
83 failed=$(expr $failed + 1)
84 testit "ID_TYPE_BOTH group map to gid has result" test -n $gid ||
85 failed=$(expr $failed + 1)
87 testit "ID_TYPE_BOTH group uid equals gid" test $uid -eq $gid ||
88 failed=$(expr $failed + 1)
90 group_pw="$DOMAIN/domain users:*:$uid:$gid::/home/$DOMAIN/domain users:/bin/false"
92 out=$(getent passwd "$GROUP")
93 ret=$?
94 testit "getpwnam for ID_TYPE_BOTH group succeeds" test $ret -eq 0 ||
95 failed=$(expr $failed + 1)
97 test "$out" = "$group_pw"
98 ret=$?
99 testit "getpwnam for ID_TYPE_BOTH group output" test $ret -eq 0 ||
100 failed=$(expr $failed + 1)
102 out=$(getent passwd $uid)
103 ret=$?
104 testit "getpwuid for ID_TYPE_BOTH group succeeds" test $ret -eq 0 ||
105 failed=$(expr $failed + 1)
106 test "$out" = "$group_pw"
107 ret=$?
108 testit "getpwuid for ID_TYPE_BOTH group output" test $ret -eq 0 ||
109 failed=$(expr $failed + 1)
111 group_gr="$DOMAIN/domain users:x:$gid"
113 out=$(getent group "$GROUP")
114 ret=$?
115 testit "getgrnam for ID_TYPE_BOTH group succeeds" test $ret -eq 0 ||
116 failed=$(expr $failed + 1)
117 # Compare only 'groupname:x:gid' part, drop the members
118 normalized_out=$(echo "$out" | cut -d: -f1-3)
119 test "$normalized_out" = "$group_gr"
120 ret=$?
121 testit "getgrnam for ID_TYPE_BOTH group output" test $ret -eq 0 ||
122 failed=$(expr $failed + 1)
124 out=$(getent group "$gid")
125 ret=$?
126 testit "getgrgid for ID_TYPE_BOTH group succeeds" test $ret -eq 0 ||
127 failed=$(expr $failed + 1)
128 # Compare only 'groupname:x:gid' part, drop the members
129 normalized_out=$(echo "$out" | cut -d: -f1-3)
130 test "$normalized_out" = "$group_gr"
131 ret=$?
132 testit "getgrgid for ID_TYPE_BOTH group output" test $ret -eq 0 ||
133 failed=$(expr $failed + 1)
136 # Test 4: ID_TYPE_BOTH mappings for user
139 dom_users_gid=$gid
141 USER="$DOMAIN/Administrator"
142 USER_SID=$($wbinfo --name-to-sid="$USER" | sed -e 's/ .*//')
144 uid=$($wbinfo --sid-to-uid=$USER_SID)
145 ret=$?
146 testit "ID_TYPE_BOTH user map to uid succeeds" test $ret -eq 0 ||
147 failed=$(expr $failed + 1)
148 testit "ID_TYPE_BOTH user map to uid has result" test -n $uid ||
149 failed=$(expr $failed + 1)
151 gid=$($wbinfo --sid-to-gid=$USER_SID)
152 ret=$?
153 testit "ID_TYPE_BOTH user map to gid succeeds" test $ret -eq 0 ||
154 failed=$(expr $failed + 1)
155 testit "ID_TYPE_BOTH user map to gid has result" test -n $gid ||
156 failed=$(expr $failed + 1)
158 testit "ID_TYPE_BOTH user uid equals gid" test $uid -eq $gid ||
159 failed=$(expr $failed + 1)
161 user_pw="$DOMAIN/administrator:*:$uid:$dom_users_gid::/home/$DOMAIN/administrator:/bin/false"
163 out=$(getent passwd "$USER")
164 ret=$?
165 testit "getpwnam for ID_TYPE_BOTH user succeeds" test $ret -eq 0 ||
166 failed=$(expr $failed + 1)
168 test "$out" = "$user_pw"
169 ret=$?
170 testit "getpwnam for ID_TYPE_BOTH user output" test $ret -eq 0 ||
171 failed=$(expr $failed + 1)
173 out=$(getent passwd $uid)
174 ret=$?
175 testit "getpwuid for ID_TYPE_BOTH user succeeds" test $ret -eq 0 ||
176 failed=$(expr $failed + 1)
177 test "$out" = "$user_pw"
178 ret=$?
179 testit "getpwuid for ID_TYPE_BOTH user output" test $ret -eq 0 ||
180 failed=$(expr $failed + 1)
182 user_gr="$DOMAIN/administrator:x:$gid:$DOMAIN/administrator"
184 out=$(getent group "$USER")
185 ret=$?
186 testit "getgrnam for ID_TYPE_BOTH user succeeds" test $ret -eq 0 ||
187 failed=$(expr $failed + 1)
188 test "$out" = "$user_gr"
189 ret=$?
190 testit "getgrnam for ID_TYPE_BOTH user output" test $ret -eq 0 ||
191 failed=$(expr $failed + 1)
193 out=$(getent group "$gid")
194 ret=$?
195 testit "getgrgid for ID_TYPE_BOTH user succeeds" test $ret -eq 0 ||
196 failed=$(expr $failed + 1)
197 test "$out" = "$user_gr"
198 ret=$?
199 testit "getgrgid for ID_TYPE_BOTH user output" test $ret -eq 0 ||
200 failed=$(expr $failed + 1)
202 exit $failed