s3:pylibsmb: make use of protocol independent cli_write_send/recv in py_cli_write()
[garming/samba-autobuild/.git] / nsswitch / tests / test_wbinfo.sh
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
9
10 DOMAIN=$1
11 USERNAME=$2
12 PASSWORD=$3
13 TARGET=$4
14 shift 4
15
16 failed=0
17 samba4bindir="$BINDIR"
18 wbinfo="$VALGRIND $samba4bindir/wbinfo"
19
20 . `dirname $0`/../../testprogs/blackbox/subunit.sh
21
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"
33         fi
34         return $status
35 }
36
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
50         fi
51         return $status
52 }
53
54 KRB5CCNAME_PATH="$PREFIX/test_wbinfo_krb5ccache"
55 rm -f $KRB5CCNAME_PATH
56
57 KRB5CCNAME="FILE:$KRB5CCNAME_PATH"
58 export KRB5CCNAME
59
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`
70
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"
75
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"
79
80 tested_name=`echo $DOMAIN/$USERNAME | tr a-z A-Z`
81
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"
89 fi
90
91 while read SID ; do
92     read NAME
93
94     testit "wbinfo -s $SID against $TARGET" $wbinfo -s $SID || failed=`expr $failed + 1`
95
96     RESOLVED_NAME=`$wbinfo -s $SID | tr a-z A-Z`
97     echo "$SID resolved to $RESOLVED_NAME"
98
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"
106     fi
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
114 EOF
115
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`
118
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"
126 fi
127
128 echo "test: wbinfo -n NT Authority/Authenticated Users"
129 $wbinfo -n "NT Authority/Authenticated Users"
130 if [ $? -ne 0 ] ; then
131     echo "failure: wbinfo -n NT Authority/Authenticated Users"
132     failed=`expr $failed + 1`
133 else
134     echo "success: wbinfo -n NT Authority/Authenticated Users"
135 fi
136
137 echo "test: wbinfo --group-info NT Authority/Authenticated Users"
138 $wbinfo --group-info "NT Authority/Authenticated Users"
139 if [ $? -ne 0 ] ; then
140     echo "failure: wbinfo --group-info NT Authority/Authenticated Users"
141     failed=`expr $failed + 1`
142 else
143     echo "success: wbinfo --group-info NT Authority/Authenticated Users"
144 fi
145
146 testit "wbinfo -U against $TARGET" $wbinfo -U 30000 || failed=`expr $failed + 1`
147
148 echo "test: wbinfo -U check for sane mapping"
149 sid_for_30000=`$wbinfo -U 30000`
150 if test x$sid_for_30000 != "xS-1-22-1-30000"; then
151         echo "uid 30000 mapped to $sid_for_30000, not S-1-22-1-30000"
152         echo "failure: wbinfo -U check for sane mapping"
153         failed=`expr $failed + 1`
154 else
155         echo "success: wbinfo -U check for sane mapping"
156 fi
157
158 admin_uid=`$wbinfo -S $admin_sid`
159
160 testit "wbinfo -G against $TARGET" $wbinfo -G 30000 || failed=`expr $failed + 1`
161
162 echo "test: wbinfo -G check for sane mapping"
163 sid_for_30000=`$wbinfo -G 30000`
164 if test x$sid_for_30000 != "xS-1-22-2-30000"; then
165         echo "gid 30000 mapped to $sid_for_30000, not S-1-22-2-30000"
166         echo "failure: wbinfo -G check for sane mapping"
167         failed=`expr $failed + 1`
168 else
169         echo "success: wbinfo -G check for sane mapping"
170 fi
171
172 testit "wbinfo -S against $TARGET" $wbinfo -S "S-1-22-1-30000" || failed=`expr $failed + 1`
173
174 echo "test: wbinfo -S check for sane mapping"
175 uid_for_sid=`$wbinfo -S S-1-22-1-30000`
176 if test 0$uid_for_sid -ne 30000; then
177         echo "S-1-22-1-30000 mapped to $uid_for_sid, not 30000"
178         echo "failure: wbinfo -S check for sane mapping"
179         failed=`expr $failed + 1`
180 else
181         echo "success: wbinfo -S check for sane mapping"
182 fi
183
184 testfail "wbinfo -S against $TARGET using invalid SID" $wbinfo -S "S-1-22-2-30000" && failed=`expr $failed + 1`
185
186 testit "wbinfo -Y against $TARGET" $wbinfo -Y "S-1-22-2-30000" || failed=`expr $failed + 1`
187
188 echo "test: wbinfo -Y check for sane mapping"
189 gid_for_sid=`$wbinfo -Y S-1-22-2-30000`
190 if test 0$gid_for_sid -ne 30000; then
191         echo "S-1-22-2-30000 mapped to $gid_for_sid, not 30000"
192         echo "failure: wbinfo -Y check for sane mapping"
193         failed=`expr $failed + 1`
194 else
195         echo "success: wbinfo -Y check for sane mapping"
196 fi
197
198 testfail "wbinfo -Y against $TARGET using invalid SID" $wbinfo -Y "S-1-22-1-30000" && failed=`expr $failed + 1`
199
200 testit "wbinfo -t against $TARGET" $wbinfo -t || failed=`expr $failed + 1`
201
202 #didn't really work anyway
203 testit "wbinfo  --trusted-domains against $TARGET" $wbinfo --trusted-domains || failed=`expr $failed + 1`
204 testit "wbinfo --all-domains against $TARGET" $wbinfo --all-domains || failed=`expr $failed + 1`
205
206 testit "wbinfo --own-domain against $TARGET" $wbinfo --own-domain || failed=`expr $failed + 1`
207
208 echo "test: wbinfo --own-domain against $TARGET check output"
209 own_domain=`$wbinfo --own-domain`
210 if test x$own_domain = x$DOMAIN; then
211         echo "success: wbinfo --own-domain against $TARGET check output"
212 else
213         echo "Own domain reported as $own_domain instead of $DOMAIN"
214         echo "failure: wbinfo --own-domain against $TARGET check output"
215         failed=`expr $failed + 1`
216 fi
217
218 # this does not work
219 knownfail "wbinfo --sequence against $TARGET" $wbinfo --sequence
220
221 # this is stubbed out now
222 testit "wbinfo -D against $TARGET" $wbinfo -D $DOMAIN || failed=`expr $failed + 1`
223
224 testit "wbinfo -i against $TARGET" $wbinfo -i "$DOMAIN/$USERNAME" || failed=`expr $failed + 1`
225
226 echo "test: wbinfo --group-info against $TARGET"
227 gid=`$wbinfo --group-info "$DOMAIN/Domain users" | cut -d: -f3`
228 if test x$? = x0; then
229         echo "success: wbinfo --group-info against $TARGET"
230 else
231         echo "failure: wbinfo --group-info against $TARGET"
232         failed=`expr $failed + 1`
233 fi
234
235 test_name="wbinfo -i against $TARGET"
236 subunit_start_test "$test_name"
237 passwd_line=`$wbinfo -i "$DOMAIN/$USERNAME"`
238 if test x$? = x0; then
239         subunit_pass_test "$test_name"
240 else
241         subunit_fail_test "$test_name"
242         failed=`expr $failed + 1`
243 fi
244
245 test_name="confirm output of wbinfo -i against $TARGET"
246 subunit_start_test "$test_name"
247
248 # The full name (GECOS) is based on name (the RDN, in this case CN)
249 # and displayName in winbindd_ads, and is based only on displayName in
250 # winbindd_msrpc and winbindd_rpc.  Allow both versions.
251 if test "$TARGET" = "ad_member"; then
252         expected1_line="$DOMAIN/administrator:*:$admin_uid:$gid:Administrator:/home/$DOMAIN/Domain Users/administrator:/bin/false"
253         expected2_line="$DOMAIN/administrator:*:$admin_uid:$gid::/home/$DOMAIN/Domain Users/administrator:/bin/false"
254 else
255         expected1_line="$DOMAIN/administrator:*:$admin_uid:$gid:Administrator:/home/$DOMAIN/administrator:/bin/false"
256         expected2_line="$DOMAIN/administrator:*:$admin_uid:$gid::/home/$DOMAIN/administrator:/bin/false"
257 fi
258
259 if test "x$passwd_line" = "x$expected1_line" -o "x$passwd_line" = "x$expected2_line"; then
260         subunit_pass_test "$test_name"
261 else
262         echo "expected '$expected1_line' or '$expected2_line' got '$passwd_line'" | subunit_fail_test "$test_name"
263         failed=`expr $failed + 1`
264 fi
265
266 test_name="wbinfo --uid-info against $TARGET"
267 subunit_start_test "$test_name"
268 passwd_line=`$wbinfo --uid-info=$admin_uid`
269 if test x$? = x0; then
270         subunit_pass_test "$test_name"
271 else
272         subunit_fail_test "$test_name"
273         failed=`expr $failed + 1`
274 fi
275
276 test_name="confirm output of wbinfo --uid-info against $TARGET"
277 subunit_start_test "$test_name"
278 if test "x$passwd_line" = "x$expected1_line" -o "x$passwd_line" = "x$expected2_line"; then
279         subunit_pass_test "$test_name"
280 else
281         echo "expected '$expected1_line' or '$expected2_line' got '$passwd_line'" | subunit_fail_test "$test_name"
282         failed=`expr $failed + 1`
283 fi
284
285 testfail "wbinfo --group-info against $TARGET with $USERNAME" $wbinfo --group-info $USERNAME && failed=`expr $failed + 1`
286
287 testit "wbinfo --gid-info against $TARGET" $wbinfo --gid-info $gid || failed=`expr $failed + 1`
288
289 testit "wbinfo -r against $TARGET" $wbinfo -r "$DOMAIN/$USERNAME" || failed=`expr $failed + 1`
290
291 testit "wbinfo --user-domgroups against $TARGET" $wbinfo --user-domgroups $admin_sid || failed=`expr $failed + 1`
292
293 testit "wbinfo --user-sids against $TARGET" $wbinfo --user-sids $admin_sid || failed=`expr $failed + 1`
294
295 testit "wbinfo -a against $TARGET with domain creds" $wbinfo -a "$DOMAIN/$USERNAME"%"$PASSWORD" || failed=`expr $failed + 1`
296
297 testit "wbinfo --getdcname against $TARGET" $wbinfo --getdcname=$DOMAIN
298
299 testit "wbinfo -p against $TARGET" $wbinfo -p || failed=`expr $failed + 1`
300
301 testit "wbinfo -K against $TARGET with domain creds" $wbinfo --krb5ccname=$KRB5CCNAME --krb5auth="$DOMAIN/$USERNAME"%"$PASSWORD" || failed=`expr $failed + 1`
302
303 testit "wbinfo --separator against $TARGET" $wbinfo --separator || failed=`expr $failed + 1`
304
305 if test "$TARGET" = "ad_member"; then
306         testit "wbinfo --domain-info=$DOMAIN" $wbinfo --domain-info=$DOMAIN || failed=`expr $failed + 1`
307
308         testit "wbinfo --dc-info=$DOMAIN" $wbinfo --dc-info=$DOMAIN || failed=`expr $failed + 1`
309 fi
310
311 testit_expect_failure "wbinfo -a against $TARGET with invalid password" $wbinfo -a "$DOMAIN/$USERNAME%InvalidPassword" && failed=`expr $failed + 1`
312
313 testit_expect_failure "wbinfo -K against $TARGET with invalid password" $wbinfo -K "$DOMAIN/$USERNAME%InvalidPassword" && failed=`expr $failed + 1`
314
315 rm -f $KRB5CCNAME_PATH
316
317 exit $failed