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