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