python:tests: Store keys as bytes rather than as lists of ints
[samba.git] / testprogs / blackbox / test_kinit_trusts_mit.sh
1 #!/bin/sh
2 # Blackbox tests for kinit and trust validation
3 # Copyright (c) 2015 Stefan Metzmacher <metze@samba.org>
4 # Copyright (c) 2016 Andreas Schneider <asn@samba.org>
5
6 if [ $# -lt 5 ]; then
7 cat <<EOF
8 Usage: test_kinit_trusts.sh SERVER USERNAME PASSWORD REALM DOMAIN TRUST_USERNAME TRUST_PASSWORD TRUST_REALM TRUST_DOMAIN PREFIX TYPE
9 EOF
10 exit 1;
11 fi
12
13 SERVER=$1
14 USERNAME=$2
15 PASSWORD=$3
16 REALM=$4
17 DOMAIN=$5
18 shift 5
19 TRUST_SERVER=$1
20 TRUST_USERNAME=$2
21 TRUST_PASSWORD=$3
22 TRUST_REALM=$4
23 TRUST_DOMAIN=$5
24 shift 5
25 PREFIX=$1
26 TYPE=$2
27 shift 2
28
29 failed=0
30
31 samba_bindir="$BINDIR"
32 samba_srcdir="$SRCDIR/source4"
33 samba_kinit=kinit
34 samba_kdestroy=kdestroy
35 samba_kpasswd=kpasswd
36
37 samba_tool="$samba_bindir/samba-tool"
38 samba_texpect="$samba_bindir/texpect"
39
40 smbclient="$samba_bindir/smbclient"
41 wbinfo="$samba_bindir/wbinfo"
42 rpcclient="$samba_bindir/rpcclient"
43
44 SMBCLIENT_UNC="//$SERVER.$REALM/tmp"
45
46 . `dirname $0`/subunit.sh
47
48 test_smbclient() {
49         name="$1"
50         cmd="$2"
51         shift
52         shift
53         echo "test: $name"
54         $VALGRIND $smbclient $CONFIGURATION $SMBCLIENT_UNC -c "$cmd" $@
55         status=$?
56         if [ x$status = x0 ]; then
57                 echo "success: $name"
58         else
59                 echo "failure: $name"
60         fi
61         return $status
62 }
63
64 KRB5CCNAME_PATH="$PREFIX/test_kinit_trusts_ccache"
65 KRB5CCNAME="FILE:$KRB5CCNAME_PATH"
66 export KRB5CCNAME
67 rm -rf $KRB5CCNAME_PATH
68
69 cat > $PREFIX/tmpkinitscript <<EOF
70 expect Password for
71 send ${TRUST_PASSWORD}\n
72 EOF
73
74 ###########################################################
75 ### Test incoming trust direction
76 ###########################################################
77
78 testit "kinit with password" $samba_texpect $PREFIX/tmpkinitscript $samba_kinit $TRUST_USERNAME@$TRUST_REALM || failed=`expr $failed + 1`
79 test_smbclient "Test login with kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
80 $samba_kdestroy
81
82 smbclient="$samba_bindir/smbclient4"
83
84 testit "kinit with password" $samba_texpect $PREFIX/tmpkinitscript $samba_kinit $TRUST_USERNAME@$TRUST_REALM || failed=`expr $failed + 1`
85 test_smbclient "Test login with kerberos ccache (smbclient4)" 'ls' -k yes || failed=`expr $failed + 1`
86 $samba_kdestroy
87
88 smbclient="$samba_bindir/smbclient"
89
90 testit "kinit with password (enterprise)" $samba_texpect $PREFIX/tmpkinitscript $samba_kinit -E $TRUST_USERNAME@$TRUST_REALM || failed=`expr $failed + 1`
91 test_smbclient "Test login with kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
92
93 $samba_kdestroy
94
95 if test x"${TYPE}" = x"forest" ;then
96     testit "kinit with password (enterprise UPN)" $samba_texpect $PREFIX/tmpkinitscript $samba_kinit -E testdenied_upn@${TRUST_REALM}.upn || failed=`expr $failed + 1`
97     test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
98 fi
99
100 $samba_kdestroy
101
102 testit "kinit with password (enterprise)" $samba_texpect $PREFIX/tmpkinitscript $samba_kinit -E $TRUST_USERNAME@$TRUST_REALM || failed=`expr $failed + 1`
103 test_smbclient "Test login with kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
104
105 testit "kinit renew ticket" $samba_kinit -R
106 test_smbclient "Test login with kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
107
108 testit "check time with kerberos ccache" $VALGRIND $samba_tool time $SERVER.$REALM $CONFIGURATION -k yes $@ || failed=`expr $failed + 1`
109
110 $samba_kdestroy
111
112 lowerrealm=$(echo $TRUST_REALM | tr '[A-Z]' '[a-z]')
113 test_smbclient "Test login with user kerberos lowercase realm" 'ls' -k yes -d5 -U$TRUST_USERNAME@$lowerrealm%$TRUST_PASSWORD || failed=`expr $failed + 1`
114 test_smbclient "Test login with user kerberos lowercase realm 2" 'ls' -k yes -U$TRUST_USERNAME@$TRUST_REALM%$TRUST_PASSWORD --realm=$lowerrealm || failed=`expr $failed + 1`
115
116 ###########################################################
117 ### Test outgoing trust direction
118 ###########################################################
119
120 SMBCLIENT_UNC="//$TRUST_SERVER.$TRUST_REALM/tmp"
121 test_smbclient "Test user login with the first outgoing secret" 'ls' -k yes -U$USERNAME@$REALM%$PASSWORD || failed=`expr $failed + 1`
122
123 testit_expect_failure "setpassword should not work" $VALGRIND $samba_tool user setpassword "${TRUST_DOMAIN}\$" --random-password || failed=`expr $failed + 1`
124
125 testit "wbinfo ping dc" $VALGRIND $wbinfo --ping-dc --domain=$TRUST_DOMAIN || failed=`expr $failed + 1`
126 testit "wbinfo change outgoing trust pw" $VALGRIND $wbinfo --change-secret --domain=$TRUST_DOMAIN || failed=`expr $failed + 1`
127 testit "wbinfo check outgoing trust pw" $VALGRIND $wbinfo --check-secret --domain=$TRUST_DOMAIN || failed=`expr $failed + 1`
128
129 test_smbclient "Test user login with the changed outgoing secret" 'ls' -k yes -U$USERNAME@$REALM%$PASSWORD || failed=`expr $failed + 1`
130
131 ### Cleanup
132
133 $samba_kdestroy
134
135 rm -f $KRB5CCNAME_PATH
136 rm -f $PREFIX/tmpkinituserpassscript
137 rm -f $PREFIX/tmpkinitscript
138
139 exit $failed