replmd: RMD_VERSION incorrectly incremented for link conflicts
[Samba.git] / nsswitch / tests / test_wbinfo.sh
blob67660e50fc8eda4a51645b2313cc208c2e85dbc1
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() {
23 name="$1"
24 shift
25 cmdline="$*"
26 echo "test: $name"
27 $cmdline
28 status=$?
29 if [ x$status = x0 ]; then
30 echo "failure: $name"
31 else
32 echo "success: $name"
34 return $status
37 knownfail() {
38 name="$1"
39 shift
40 cmdline="$*"
41 echo "test: $name"
42 $cmdline
43 status=$?
44 if [ x$status = x0 ]; then
45 echo "failure: $name [unexpected success]"
46 status=1
47 else
48 echo "knownfail: $name"
49 status=0
51 return $status
54 KRB5CCNAME_PATH="$PREFIX/test_wbinfo_krb5ccache"
55 rm -f $KRB5CCNAME_PATH
57 KRB5CCNAME="FILE:$KRB5CCNAME_PATH"
58 export KRB5CCNAME
60 # List users
61 testit "wbinfo -u against $TARGET" $wbinfo -u || failed=`expr $failed + 1`
62 # List groups
63 testit "wbinfo -g against $TARGET" $wbinfo -g || failed=`expr $failed + 1`
64 # Convert netbios name to IP
65 # Does not work yet
66 testit "wbinfo -N against $TARGET" $wbinfo -N $NETBIOSNAME || failed=`expr $failed + 1`
67 # Convert IP to netbios name
68 # Does not work yet
69 testit "wbinfo -I against $TARGET" $wbinfo -I $SERVER_IP || failed=`expr $failed + 1`
71 # Convert name to SID
72 testit "wbinfo -n against $TARGET" $wbinfo -n "$DOMAIN/$USERNAME" || failed=`expr $failed + 1`
73 admin_sid=`$wbinfo -n "$DOMAIN/$USERNAME" | cut -d " " -f1`
74 echo "$DOMAIN/$USERNAME resolved to $admin_sid"
76 testit "wbinfo -s $admin_sid against $TARGET" $wbinfo -s $admin_sid || failed=`expr $failed + 1`
77 admin_name=`$wbinfo -s $admin_sid | cut -d " " -f1| tr a-z A-Z`
78 echo "$admin_sid resolved to $admin_name"
80 tested_name=`echo $DOMAIN/$USERNAME | tr a-z A-Z`
82 echo "test: wbinfo -s check for sane mapping"
83 if test x$admin_name != x$tested_name; then
84 echo "$admin_name does not match $tested_name"
85 echo "failure: wbinfo -s check for sane mapping"
86 failed=`expr $failed + 1`
87 else
88 echo "success: wbinfo -s check for sane mapping"
91 while read SID ; do
92 read NAME
94 testit "wbinfo -s $SID against $TARGET" $wbinfo -s $SID || failed=`expr $failed + 1`
96 RESOLVED_NAME=`$wbinfo -s $SID | tr a-z A-Z`
97 echo "$SID resolved to $RESOLVED_NAME"
99 echo "test: wbinfo -s $SID against $TARGET"
100 if test x"$RESOLVED_NAME" != x"$NAME" ; then
101 echo "$RESOLVED_NAME does not match $NAME"
102 echo "failure: wbinfo -s $SID against $TARGET"
103 failed=`expr $failed + 1`
104 else
105 echo "success: wbinfo -s $SID against $TARGET"
107 done <<EOF
108 S-1-1-0
109 /EVERYONE 5
110 S-1-3-1
111 /CREATOR GROUP 5
112 S-1-5-1
113 NT AUTHORITY/DIALUP 5
116 testit "wbinfo -n on the returned name against $TARGET" $wbinfo -n $admin_name || failed=`expr $failed + 1`
117 test_sid=`$wbinfo -n $tested_name | cut -d " " -f1`
119 echo "test: wbinfo -n check for sane mapping"
120 if test x$admin_sid != x$test_sid; then
121 echo "$admin_sid does not match $test_sid"
122 echo "failure: wbinfo -n check for sane mapping"
123 failed=`expr $failed + 1`
124 else
125 echo "success: wbinfo -n check for sane mapping"
128 testit "wbinfo -U against $TARGET" $wbinfo -U 30000 || failed=`expr $failed + 1`
130 echo "test: wbinfo -U check for sane mapping"
131 sid_for_30000=`$wbinfo -U 30000`
132 if test x$sid_for_30000 != "xS-1-22-1-30000"; then
133 echo "uid 30000 mapped to $sid_for_30000, not S-1-22-1-30000"
134 echo "failure: wbinfo -U check for sane mapping"
135 failed=`expr $failed + 1`
136 else
137 echo "success: wbinfo -U check for sane mapping"
140 admin_uid=`$wbinfo -S $admin_sid`
142 testit "wbinfo -G against $TARGET" $wbinfo -G 30000 || failed=`expr $failed + 1`
144 echo "test: wbinfo -G check for sane mapping"
145 sid_for_30000=`$wbinfo -G 30000`
146 if test x$sid_for_30000 != "xS-1-22-2-30000"; then
147 echo "gid 30000 mapped to $sid_for_30000, not S-1-22-2-30000"
148 echo "failure: wbinfo -G check for sane mapping"
149 failed=`expr $failed + 1`
150 else
151 echo "success: wbinfo -G check for sane mapping"
154 testit "wbinfo -S against $TARGET" $wbinfo -S "S-1-22-1-30000" || failed=`expr $failed + 1`
156 echo "test: wbinfo -S check for sane mapping"
157 uid_for_sid=`$wbinfo -S S-1-22-1-30000`
158 if test 0$uid_for_sid -ne 30000; then
159 echo "S-1-22-1-30000 mapped to $uid_for_sid, not 30000"
160 echo "failure: wbinfo -S check for sane mapping"
161 failed=`expr $failed + 1`
162 else
163 echo "success: wbinfo -S check for sane mapping"
166 testfail "wbinfo -S against $TARGET using invalid SID" $wbinfo -S "S-1-22-2-30000" && failed=`expr $failed + 1`
168 testit "wbinfo -Y against $TARGET" $wbinfo -Y "S-1-22-2-30000" || failed=`expr $failed + 1`
170 echo "test: wbinfo -Y check for sane mapping"
171 gid_for_sid=`$wbinfo -Y S-1-22-2-30000`
172 if test 0$gid_for_sid -ne 30000; then
173 echo "S-1-22-2-30000 mapped to $gid_for_sid, not 30000"
174 echo "failure: wbinfo -Y check for sane mapping"
175 failed=`expr $failed + 1`
176 else
177 echo "success: wbinfo -Y check for sane mapping"
180 testfail "wbinfo -Y against $TARGET using invalid SID" $wbinfo -Y "S-1-22-1-30000" && failed=`expr $failed + 1`
182 testit "wbinfo -t against $TARGET" $wbinfo -t || failed=`expr $failed + 1`
184 #didn't really work anyway
185 testit "wbinfo --trusted-domains against $TARGET" $wbinfo --trusted-domains || failed=`expr $failed + 1`
186 testit "wbinfo --all-domains against $TARGET" $wbinfo --all-domains || failed=`expr $failed + 1`
188 testit "wbinfo --own-domain against $TARGET" $wbinfo --own-domain || failed=`expr $failed + 1`
190 echo "test: wbinfo --own-domain against $TARGET check output"
191 own_domain=`$wbinfo --own-domain`
192 if test x$own_domain = x$DOMAIN; then
193 echo "success: wbinfo --own-domain against $TARGET check output"
194 else
195 echo "Own domain reported as $own_domain instead of $DOMAIN"
196 echo "failure: wbinfo --own-domain against $TARGET check output"
197 failed=`expr $failed + 1`
200 # this does not work
201 knownfail "wbinfo --sequence against $TARGET" $wbinfo --sequence
203 # this is stubbed out now
204 testit "wbinfo -D against $TARGET" $wbinfo -D $DOMAIN || failed=`expr $failed + 1`
206 testit "wbinfo -i against $TARGET" $wbinfo -i "$DOMAIN/$USERNAME" || failed=`expr $failed + 1`
208 echo "test: wbinfo --group-info against $TARGET"
209 gid=`$wbinfo --group-info "$DOMAIN/Domain users" | cut -d: -f3`
210 if test x$? = x0; then
211 echo "success: wbinfo --group-info against $TARGET"
212 else
213 echo "failure: wbinfo --group-info against $TARGET"
214 failed=`expr $failed + 1`
217 test_name="wbinfo -i against $TARGET"
218 subunit_start_test "$test_name"
219 passwd_line=`$wbinfo -i "$DOMAIN/$USERNAME"`
220 if test x$? = x0; then
221 subunit_pass_test "$test_name"
222 else
223 subunit_fail_test "$test_name"
224 failed=`expr $failed + 1`
227 test_name="confirm output of wbinfo -i against $TARGET"
228 subunit_start_test "$test_name"
230 # The full name (GECOS) is based on name (the RDN, in this case CN)
231 # and displayName in winbindd_ads, and is based only on displayName in
232 # winbindd_msrpc and winbindd_rpc. Allow both versions.
233 if test "$TARGET" = "ad_member"; then
234 expected1_line="$DOMAIN/administrator:*:$admin_uid:$gid:Administrator:/home/$DOMAIN/Domain Users/administrator:/bin/false"
235 expected2_line="$DOMAIN/administrator:*:$admin_uid:$gid::/home/$DOMAIN/Domain Users/administrator:/bin/false"
236 else
237 expected1_line="$DOMAIN/administrator:*:$admin_uid:$gid:Administrator:/home/$DOMAIN/administrator:/bin/false"
238 expected2_line="$DOMAIN/administrator:*:$admin_uid:$gid::/home/$DOMAIN/administrator:/bin/false"
241 if test "x$passwd_line" = "x$expected1_line" -o "x$passwd_line" = "x$expected2_line"; then
242 subunit_pass_test "$test_name"
243 else
244 echo "expected '$expected1_line' or '$expected2_line' got '$passwd_line'" | subunit_fail_test "$test_name"
245 failed=`expr $failed + 1`
248 test_name="wbinfo --uid-info against $TARGET"
249 subunit_start_test "$test_name"
250 passwd_line=`$wbinfo --uid-info=$admin_uid`
251 if test x$? = x0; then
252 subunit_pass_test "$test_name"
253 else
254 subunit_fail_test "$test_name"
255 failed=`expr $failed + 1`
258 test_name="confirm output of wbinfo --uid-info against $TARGET"
259 subunit_start_test "$test_name"
260 if test "x$passwd_line" = "x$expected1_line" -o "x$passwd_line" = "x$expected2_line"; then
261 subunit_pass_test "$test_name"
262 else
263 echo "expected '$expected1_line' or '$expected2_line' got '$passwd_line'" | subunit_fail_test "$test_name"
264 failed=`expr $failed + 1`
267 testfail "wbinfo --group-info against $TARGET with $USERNAME" $wbinfo --group-info $USERNAME && failed=`expr $failed + 1`
269 testit "wbinfo --gid-info against $TARGET" $wbinfo --gid-info $gid || failed=`expr $failed + 1`
271 testit "wbinfo -r against $TARGET" $wbinfo -r "$DOMAIN/$USERNAME" || failed=`expr $failed + 1`
273 testit "wbinfo --user-domgroups against $TARGET" $wbinfo --user-domgroups $admin_sid || failed=`expr $failed + 1`
275 testit "wbinfo --user-sids against $TARGET" $wbinfo --user-sids $admin_sid || failed=`expr $failed + 1`
277 testit "wbinfo -a against $TARGET with domain creds" $wbinfo -a "$DOMAIN/$USERNAME"%"$PASSWORD" || failed=`expr $failed + 1`
279 testit "wbinfo --getdcname against $TARGET" $wbinfo --getdcname=$DOMAIN
281 testit "wbinfo -p against $TARGET" $wbinfo -p || failed=`expr $failed + 1`
283 testit "wbinfo -K against $TARGET with domain creds" $wbinfo --krb5ccname=$KRB5CCNAME --krb5auth="$DOMAIN/$USERNAME"%"$PASSWORD" || failed=`expr $failed + 1`
285 testit "wbinfo --separator against $TARGET" $wbinfo --separator || failed=`expr $failed + 1`
287 if test "$TARGET" = "ad_member"; then
288 testit "wbinfo --domain-info=$DOMAIN" $wbinfo --domain-info=$DOMAIN || failed=`expr $failed + 1`
290 testit "wbinfo --dc-info=$DOMAIN" $wbinfo --dc-info=$DOMAIN || failed=`expr $failed + 1`
293 testit_expect_failure "wbinfo -a against $TARGET with invalid password" $wbinfo -a "$DOMAIN/$USERNAME%InvalidPassword" && failed=`expr $failed + 1`
295 testit_expect_failure "wbinfo -K against $TARGET with invalid password" $wbinfo -K "$DOMAIN/$USERNAME%InvalidPassword" && failed=`expr $failed + 1`
297 rm -f $KRB5CCNAME_PATH
299 exit $failed