smbd: Alternative fix for smb2.stream.attributes2 test
[Samba.git] / nsswitch / tests / test_wbinfo.sh
blobb36e4c63bc144e1497257a9552855190a08c628a
1 #!/bin/sh
2 # Blackbox test for wbinfo
3 if [ $# -lt 4 ]; then
4 cat <<EOF
5 Usage: test_wbinfo.sh DOMAIN USERNAME PASSWORD TARGET
6 EOF
7 exit 1
8 fi
10 DOMAIN=$1
11 USERNAME=$2
12 PASSWORD=$3
13 TARGET=$4
14 shift 4
16 failed=0
17 samba4bindir="$BINDIR"
18 wbinfo="$VALGRIND $samba4bindir/wbinfo"
20 . $(dirname $0)/../../testprogs/blackbox/subunit.sh
22 testfail()
24 name="$1"
25 shift
26 cmdline="$*"
27 echo "test: $name"
28 $cmdline
29 status=$?
30 if [ x$status = x0 ]; then
31 echo "failure: $name"
32 return 1
33 else
34 echo "success: $name"
35 return 0
39 knownfail()
41 name="$1"
42 shift
43 cmdline="$*"
44 echo "test: $name"
45 $cmdline
46 status=$?
47 if [ x$status = x0 ]; then
48 echo "failure: $name [unexpected success]"
49 status=1
50 else
51 echo "knownfail: $name"
52 status=0
54 return $status
57 KRB5CCNAME_PATH="$PREFIX/test_wbinfo_krb5ccache"
58 rm -f $KRB5CCNAME_PATH
60 KRB5CCNAME="FILE:$KRB5CCNAME_PATH"
61 export KRB5CCNAME
63 # List users
64 testit "wbinfo -u against $TARGET" $wbinfo -u || failed=$(expr $failed + 1)
65 # List groups
66 testit "wbinfo -g against $TARGET" $wbinfo -g || failed=$(expr $failed + 1)
67 # Convert netbios name to IP
68 # Does not work yet
69 testit "wbinfo -N against $TARGET" $wbinfo -N $NETBIOSNAME || failed=$(expr $failed + 1)
70 # Convert IP to netbios name
71 # Does not work yet
72 testit "wbinfo -I against $TARGET" $wbinfo -I $SERVER_IP || failed=$(expr $failed + 1)
74 # Convert name to SID
75 testit "wbinfo -n against $TARGET" $wbinfo -n "$DOMAIN/$USERNAME" || failed=$(expr $failed + 1)
76 admin_sid=$($wbinfo -n "$DOMAIN/$USERNAME" | cut -d " " -f1)
77 echo "$DOMAIN/$USERNAME resolved to $admin_sid"
79 testit "wbinfo -s $admin_sid against $TARGET" $wbinfo -s $admin_sid || failed=$(expr $failed + 1)
80 admin_name=$($wbinfo -s $admin_sid | cut -d " " -f1 | tr a-z A-Z)
81 echo "$admin_sid resolved to $admin_name"
83 tested_name=$(echo $DOMAIN/$USERNAME | tr a-z A-Z)
85 echo "test: wbinfo -s check for sane mapping"
86 if test x$admin_name != x$tested_name; then
87 echo "$admin_name does not match $tested_name"
88 echo "failure: wbinfo -s check for sane mapping"
89 failed=$(expr $failed + 1)
90 else
91 echo "success: wbinfo -s check for sane mapping"
94 while read SID; do
95 read NAME
97 testit "wbinfo -s $SID against $TARGET" $wbinfo -s $SID || failed=$(expr $failed + 1)
99 RESOLVED_NAME=$($wbinfo -s $SID | tr a-z A-Z)
100 echo "$SID resolved to $RESOLVED_NAME"
102 echo "test: wbinfo -s $SID against $TARGET"
103 if test x"$RESOLVED_NAME" != x"$NAME"; then
104 echo "$RESOLVED_NAME does not match $NAME"
105 echo "failure: wbinfo -s $SID against $TARGET"
106 failed=$(expr $failed + 1)
107 else
108 echo "success: wbinfo -s $SID against $TARGET"
110 done <<EOF
111 S-1-1-0
112 /EVERYONE 5
113 S-1-3-1
114 /CREATOR GROUP 5
115 S-1-5-1
116 NT AUTHORITY/DIALUP 5
119 testit "wbinfo -n on the returned name against $TARGET" $wbinfo -n $admin_name || failed=$(expr $failed + 1)
120 test_sid=$($wbinfo -n $tested_name | cut -d " " -f1)
122 echo "test: wbinfo -n check for sane mapping"
123 if test x$admin_sid != x$test_sid; then
124 echo "$admin_sid does not match $test_sid"
125 echo "failure: wbinfo -n check for sane mapping"
126 failed=$(expr $failed + 1)
127 else
128 echo "success: wbinfo -n check for sane mapping"
131 echo "test: wbinfo -n NT Authority/Authenticated Users"
132 $wbinfo -n "NT Authority/Authenticated Users"
133 if [ $? -ne 0 ]; then
134 echo "failure: wbinfo -n NT Authority/Authenticated Users"
135 failed=$(expr $failed + 1)
136 else
137 echo "success: wbinfo -n NT Authority/Authenticated Users"
140 echo "test: wbinfo --group-info NT Authority/Authenticated Users"
141 $wbinfo --group-info "NT Authority/Authenticated Users"
142 if [ $? -ne 0 ]; then
143 echo "failure: wbinfo --group-info NT Authority/Authenticated Users"
144 failed=$(expr $failed + 1)
145 else
146 echo "success: wbinfo --group-info NT Authority/Authenticated Users"
149 testit "wbinfo -U against $TARGET" $wbinfo -U 30000 || failed=$(expr $failed + 1)
151 echo "test: wbinfo -U check for sane mapping"
152 sid_for_30000=$($wbinfo -U 30000)
153 if test x$sid_for_30000 != "xS-1-22-1-30000"; then
154 echo "uid 30000 mapped to $sid_for_30000, not S-1-22-1-30000"
155 echo "failure: wbinfo -U check for sane mapping"
156 failed=$(expr $failed + 1)
157 else
158 echo "success: wbinfo -U check for sane mapping"
161 admin_uid=$($wbinfo -S $admin_sid)
163 testit "wbinfo -G against $TARGET" $wbinfo -G 30000 || failed=$(expr $failed + 1)
165 echo "test: wbinfo -G check for sane mapping"
166 sid_for_30000=$($wbinfo -G 30000)
167 if test x$sid_for_30000 != "xS-1-22-2-30000"; then
168 echo "gid 30000 mapped to $sid_for_30000, not S-1-22-2-30000"
169 echo "failure: wbinfo -G check for sane mapping"
170 failed=$(expr $failed + 1)
171 else
172 echo "success: wbinfo -G check for sane mapping"
175 testit "wbinfo -S against $TARGET" $wbinfo -S "S-1-22-1-30000" || failed=$(expr $failed + 1)
177 echo "test: wbinfo -S check for sane mapping"
178 uid_for_sid=$($wbinfo -S S-1-22-1-30000)
179 if test 0$uid_for_sid -ne 30000; then
180 echo "S-1-22-1-30000 mapped to $uid_for_sid, not 30000"
181 echo "failure: wbinfo -S check for sane mapping"
182 failed=$(expr $failed + 1)
183 else
184 echo "success: wbinfo -S check for sane mapping"
187 testfail "wbinfo -S against $TARGET using invalid SID" $wbinfo -S "S-1-22-2-30000" || failed=$(expr $failed + 1)
189 testit "wbinfo -Y against $TARGET" $wbinfo -Y "S-1-22-2-30000" || failed=$(expr $failed + 1)
191 echo "test: wbinfo -Y check for sane mapping"
192 gid_for_sid=$($wbinfo -Y S-1-22-2-30000)
193 if test 0$gid_for_sid -ne 30000; then
194 echo "S-1-22-2-30000 mapped to $gid_for_sid, not 30000"
195 echo "failure: wbinfo -Y check for sane mapping"
196 failed=$(expr $failed + 1)
197 else
198 echo "success: wbinfo -Y check for sane mapping"
201 testfail "wbinfo -Y against $TARGET using invalid SID" $wbinfo -Y "S-1-22-1-30000" || failed=$(expr $failed + 1)
203 testit "wbinfo -t against $TARGET" $wbinfo -t || failed=$(expr $failed + 1)
205 #didn't really work anyway
206 testit "wbinfo --trusted-domains against $TARGET" $wbinfo --trusted-domains || failed=$(expr $failed + 1)
207 testit "wbinfo --all-domains against $TARGET" $wbinfo --all-domains || failed=$(expr $failed + 1)
209 testit "wbinfo --own-domain against $TARGET" $wbinfo --own-domain || failed=$(expr $failed + 1)
211 echo "test: wbinfo --own-domain against $TARGET check output"
212 own_domain=$($wbinfo --own-domain)
213 if test x$own_domain = x$DOMAIN; then
214 echo "success: wbinfo --own-domain against $TARGET check output"
215 else
216 echo "Own domain reported as $own_domain instead of $DOMAIN"
217 echo "failure: wbinfo --own-domain against $TARGET check output"
218 failed=$(expr $failed + 1)
221 # this does not work
222 knownfail "wbinfo --sequence against $TARGET" $wbinfo --sequence
224 # this is stubbed out now
225 testit "wbinfo -D against $TARGET" $wbinfo -D $DOMAIN || failed=$(expr $failed + 1)
227 testit "wbinfo -i against $TARGET" $wbinfo -i "$DOMAIN/$USERNAME" || failed=$(expr $failed + 1)
229 echo "test: wbinfo --group-info against $TARGET"
230 gid=$($wbinfo --group-info "$DOMAIN/Domain users" | cut -d: -f3)
231 if test x$? = x0; then
232 echo "success: wbinfo --group-info against $TARGET"
233 else
234 echo "failure: wbinfo --group-info against $TARGET"
235 failed=$(expr $failed + 1)
238 test_name="wbinfo -i against $TARGET"
239 subunit_start_test "$test_name"
240 passwd_line=$($wbinfo -i "$DOMAIN/$USERNAME")
241 if test x$? = x0; then
242 subunit_pass_test "$test_name"
243 else
244 subunit_fail_test "$test_name"
245 failed=$(expr $failed + 1)
248 test_name="confirm output of wbinfo -i against $TARGET"
249 subunit_start_test "$test_name"
251 # The full name (GECOS) is based on name (the RDN, in this case CN)
252 # and displayName in winbindd_ads, and is based only on displayName in
253 # winbindd_msrpc and winbindd_rpc. Allow both versions.
254 if test "$TARGET" = "ad_member"; then
255 expected1_line="$DOMAIN/administrator:*:$admin_uid:$gid:Administrator:/home/$DOMAIN/Domain Users/administrator:/bin/false"
256 expected2_line="$DOMAIN/administrator:*:$admin_uid:$gid::/home/$DOMAIN/Domain Users/administrator:/bin/false"
257 else
258 expected1_line="$DOMAIN/administrator:*:$admin_uid:$gid:Administrator:/home/$DOMAIN/administrator:/bin/false"
259 expected2_line="$DOMAIN/administrator:*:$admin_uid:$gid::/home/$DOMAIN/administrator:/bin/false"
262 if test "x$passwd_line" = "x$expected1_line" -o "x$passwd_line" = "x$expected2_line"; then
263 subunit_pass_test "$test_name"
264 else
265 echo "expected '$expected1_line' or '$expected2_line' got '$passwd_line'" | subunit_fail_test "$test_name"
266 failed=$(expr $failed + 1)
269 test_name="wbinfo --uid-info against $TARGET"
270 subunit_start_test "$test_name"
271 passwd_line=$($wbinfo --uid-info=$admin_uid)
272 if test x$? = x0; then
273 subunit_pass_test "$test_name"
274 else
275 subunit_fail_test "$test_name"
276 failed=$(expr $failed + 1)
279 test_name="confirm output of wbinfo --uid-info against $TARGET"
280 subunit_start_test "$test_name"
281 if test "x$passwd_line" = "x$expected1_line" -o "x$passwd_line" = "x$expected2_line"; then
282 subunit_pass_test "$test_name"
283 else
284 echo "expected '$expected1_line' or '$expected2_line' got '$passwd_line'" | subunit_fail_test "$test_name"
285 failed=$(expr $failed + 1)
288 testfail "wbinfo --group-info against $TARGET with $USERNAME" $wbinfo --group-info $USERNAME || failed=$(expr $failed + 1)
290 testit "wbinfo --gid-info against $TARGET" $wbinfo --gid-info $gid || failed=$(expr $failed + 1)
292 testit "wbinfo -r against $TARGET" $wbinfo -r "$DOMAIN/$USERNAME" || failed=$(expr $failed + 1)
294 testit "wbinfo --user-domgroups against $TARGET" $wbinfo --user-domgroups $admin_sid || failed=$(expr $failed + 1)
296 testit "wbinfo --user-sids against $TARGET" $wbinfo --user-sids $admin_sid || failed=$(expr $failed + 1)
298 testit "wbinfo -a against $TARGET with domain creds" $wbinfo -a "$DOMAIN/$USERNAME"%"$PASSWORD" || failed=$(expr $failed + 1)
300 testit "wbinfo -a against $TARGET with domain upn creds" $wbinfo -a "$USERNAME@$DOMAIN"%"$PASSWORD" || failed=$(expr $failed + 1)
302 testit "wbinfo --getdcname against $TARGET" $wbinfo --getdcname=$DOMAIN
304 testit "wbinfo -p against $TARGET" $wbinfo -p || failed=$(expr $failed + 1)
306 testit "wbinfo -K against $TARGET with domain creds" $wbinfo --krb5ccname=$KRB5CCNAME --krb5auth="$DOMAIN/$USERNAME"%"$PASSWORD" || failed=$(expr $failed + 1)
308 testit "wbinfo --separator against $TARGET" $wbinfo --separator || failed=$(expr $failed + 1)
310 if test "$TARGET" = "ad_member"; then
311 testit "wbinfo --domain-info=$DOMAIN" $wbinfo --domain-info=$DOMAIN || failed=$(expr $failed + 1)
313 testit "wbinfo --dc-info=$DOMAIN" $wbinfo --dc-info=$DOMAIN || failed=$(expr $failed + 1)
316 testit_expect_failure "wbinfo -a against $TARGET with invalid password" $wbinfo -a "$DOMAIN/$USERNAME%InvalidPassword" || failed=$(expr $failed + 1)
318 testit_expect_failure "wbinfo -K against $TARGET with invalid password" $wbinfo -K "$DOMAIN/$USERNAME%InvalidPassword" || failed=$(expr $failed + 1)
320 rm -f $KRB5CCNAME_PATH
322 exit $failed