selftest: Remove duplication between BUILDIR and BINDIR
[kai/samba.git] / testprogs / blackbox / test_kinit.sh
1 #!/bin/sh
2 # Blackbox tests for kinit and kerberos integration with smbclient etc
3 # Copyright (C) 2006-2007 Jelmer Vernooij <jelmer@samba.org>
4 # Copyright (C) 2006-2008 Andrew Bartlett <abartlet@samba.org>
5
6 if [ $# -lt 5 ]; then
7 cat <<EOF
8 Usage: test_kinit.sh SERVER USERNAME PASSWORD REALM DOMAIN PREFIX
9 EOF
10 exit 1;
11 fi
12
13 SERVER=$1
14 USERNAME=$2
15 PASSWORD=$3
16 REALM=$4
17 DOMAIN=$5
18 PREFIX=$6
19 ENCTYPE=$7
20 shift 7
21 failed=0
22
23 samba4bindir="$BINDIR"
24 samba4srcdir="$SRCDIR/source4"
25 smbclient="$samba4bindir/smbclient$EXEEXT"
26 samba4kinit="$samba4bindir/samba4kinit$EXEEXT"
27 samba_tool="$samba4bindir/samba-tool$EXEEXT"
28 ldbmodify="$samba4bindir/ldbmodify$EXEEXT"
29 ldbsearch="$samba4bindir/ldbsearch$EXEEXT"
30 rkpty="$samba4bindir/rkpty$EXEEXT"
31 samba4kpasswd="$samba4bindir/samba4kpasswd$EXEEXT"
32 enableaccount="$samba_tool enableaccount"
33 machineaccountccache="$samba4srcdir/scripting/bin/machineaccountccache"
34
35 . `dirname $0`/subunit.sh
36
37 test_smbclient() {
38         name="$1"
39         cmd="$2"
40         shift
41         shift
42         echo "test: $name"
43         $VALGRIND $smbclient $CONFIGURATION //$SERVER/tmp -c "$cmd" -W "$DOMAIN" $@
44         status=$?
45         if [ x$status = x0 ]; then
46                 echo "success: $name"
47         else
48                 echo "failure: $name"
49         fi
50         return $status
51 }
52
53 enctype="-e $ENCTYPE"
54
55 PWSETCONFIG="-H ldap://$SERVER -U$USERNAME%$PASSWORD"
56 export PWSETCONFIG
57
58 KRB5CCNAME="$PREFIX/tmpccache"
59 export KRB5CCNAME
60
61 testit "reset password policies beside of minimum password age of 0 days" $VALGRIND $samba_tool pwsettings $PWSETCONFIG set --complexity=default --history-length=default --min-pwd-length=default --min-pwd-age=0 --max-pwd-age=default || failed=`expr $failed + 1`
62
63 echo $PASSWORD > $PREFIX/tmppassfile
64 #testit "kinit with keytab" $samba4kinit $enctype --keytab=$PREFIX/dc/private/secrets.keytab $SERVER\$@$REALM   || failed=`expr $failed + 1`
65 testit "kinit with password" $samba4kinit $enctype --password-file=$PREFIX/tmppassfile --request-pac $USERNAME@$REALM   || failed=`expr $failed + 1`
66 testit "kinit with password (enterprise style)" $samba4kinit $enctype --enterprise --password-file=$PREFIX/tmppassfile --request-pac $USERNAME@$REALM   || failed=`expr $failed + 1`
67 testit "kinit with password (windows style)" $samba4kinit $enctype  --renewable --windows --password-file=$PREFIX/tmppassfile --request-pac $USERNAME@$REALM   || failed=`expr $failed + 1`
68 testit "kinit renew ticket" $samba4kinit $enctype --request-pac -R
69
70 test_smbclient "Test login with kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
71
72 testit "check time with kerberos ccache" $VALGRIND $samba_tool $CONFIGURATION -k yes $@ time $SERVER || failed=`expr $failed + 1`
73
74 USERPASS=testPass@12%
75 echo $USERPASS > $PREFIX/tmpuserpassfile
76 testit "add user with kerberos ccache" $VALGRIND $samba_tool user add nettestuser $USERPASS $CONFIGURATION  -k yes $@ || failed=`expr $failed + 1`
77
78 echo "Getting defaultNamingContext"
79 BASEDN=`$ldbsearch $options --basedn='' -H ldap://$SERVER -s base DUMMY=x defaultNamingContext | grep defaultNamingContext | awk '{print $2}'`
80
81 cat > $PREFIX/tmpldbmodify <<EOF
82 dn: cn=nettestuser,cn=users,$BASEDN
83 changetype: modify
84 add: servicePrincipalName
85 servicePrincipalName: host/nettestuser
86 EOF
87
88 testit "modify servicePrincipalName" $VALGRIND $ldbmodify -H ldap://$SERVER $PREFIX/tmpldbmodify -k yes $@ || failed=`expr $failed + 1`
89
90 testit "set user password with kerberos ccache" $VALGRIND $samba_tool password set $DOMAIN\\nettestuser $USERPASS $CONFIGURATION  -k yes $@ || failed=`expr $failed + 1`
91
92 testit "enable user with kerberos cache" $VALGRIND $enableaccount nettestuser -H ldap://$SERVER -k yes $@ || failed=`expr $failed + 1`
93
94 KRB5CCNAME="$PREFIX/tmpuserccache"
95 export KRB5CCNAME
96
97 testit "kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM   || failed=`expr $failed + 1`
98
99 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
100
101 NEWUSERPASS=testPaSS@34%
102 testit "change user password with 'samba-tool password change' (rpc)" $VALGRIND $samba_tool password change -W$DOMAIN -U$DOMAIN\\nettestuser%$USERPASS $CONFIGURATION  -k no $NEWUSERPASS $@ || failed=`expr $failed + 1`
103
104 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
105 testit "kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM   || failed=`expr $failed + 1`
106
107 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
108
109
110 USERPASS=$NEWUSERPASS
111 NEWUSERPASS=testPaSS@56%
112 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
113
114 cat > $PREFIX/tmpkpasswdscript <<EOF
115 expect Password
116 password ${USERPASS}\n
117 expect New password
118 send ${NEWUSERPASS}\n
119 expect Verify password
120 send ${NEWUSERPASS}\n
121 expect Success
122 EOF
123
124 testit "change user password with kpasswd" $rkpty $PREFIX/tmpkpasswdscript $samba4kpasswd nettestuser@$REALM || failed=`expr $failed + 1`
125
126 testit "kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM   || failed=`expr $failed + 1`
127
128 NEWUSERPASS=testPaSS@78%
129 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
130
131 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
132
133 cat > $PREFIX/tmpkpasswdscript <<EOF
134 expect New password
135 send ${NEWUSERPASS}\n
136 expect Verify password
137 send ${NEWUSERPASS}\n
138 expect Success
139 EOF
140
141 testit "set user password with kpasswd" $rkpty $PREFIX/tmpkpasswdscript $samba4kpasswd --cache=$PREFIX/tmpccache nettestuser@$REALM || failed=`expr $failed + 1`
142
143 testit "kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM   || failed=`expr $failed + 1`
144
145 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
146
147 NEWUSERPASS=testPaSS@910%
148 echo $NEWUSERPASS > $PREFIX/tmpuserpassfile
149
150 cat > $PREFIX/tmpkpasswdscript <<EOF
151 expect New password
152 send ${NEWUSERPASS}\n
153 expect Verify password
154 send ${NEWUSERPASS}\n
155 expect Success
156 EOF
157
158 testit "set user password with kpasswd and servicePrincipalName" $rkpty $PREFIX/tmpkpasswdscript $samba4kpasswd --cache=$PREFIX/tmpccache host/nettestuser@$REALM || failed=`expr $failed + 1`
159
160 testit "kinit with user password" $samba4kinit $enctype --password-file=$PREFIX/tmpuserpassfile --request-pac nettestuser@$REALM   || failed=`expr $failed + 1`
161
162 test_smbclient "Test login with user kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
163
164 KRB5CCNAME="$PREFIX/tmpccache"
165 export KRB5CCNAME
166
167 lowerrealm=$(echo $REALM | tr '[A-Z]' '[a-z]')
168 test_smbclient "Test login with user kerberos lowercase realm" 'ls' -k yes -Unettestuser@$lowerrealm%$NEWUSERPASS || failed=`expr $failed + 1`
169 test_smbclient "Test login with user kerberos lowercase realm 2" 'ls' -k yes -Unettestuser@$REALM%$NEWUSERPASS --realm=$lowerrealm || failed=`expr $failed + 1`
170
171 testit "del user with kerberos ccache" $VALGRIND $samba_tool user delete nettestuser $CONFIGURATION -k yes $@ || failed=`expr $failed + 1`
172
173 rm -f $KRB5CCNAME
174 testit "kinit with machineaccountccache script" $machineaccountccache $CONFIGURATION $KRB5CCNAME || failed=`expr $failed + 1`
175 test_smbclient "Test machine account login with kerberos ccache" 'ls' -k yes || failed=`expr $failed + 1`
176
177 testit "reset password policies" $VALGRIND $samba_tool pwsettings $PWSETCONFIG set --complexity=default --history-length=default --min-pwd-length=default --min-pwd-age=default --max-pwd-age=default || failed=`expr $failed + 1`
178
179 rm -f $PREFIX/tmpccache tmpccfile tmppassfile tmpuserpassfile tmpuserccache tmpkpasswdscript
180 exit $failed