3 # Blackbox tests for an exported keytab with kinit
5 # Copyright (C) 2006-2007 Jelmer Vernooij <jelmer@samba.org>
6 # Copyright (C) 2006-2008 Andrew Bartlett <abartlet@samba.org>
7 # Copyright (C) 2016 Andreas Schneider <asn@cryptomilk.org>
11 Usage: test_extract_keytab.sh SERVER USERNAME REALM DOMAIN PREFIX SMBCLIENT
25 samba_bindir
="$BINDIR"
26 samba_tool
="$samba_bindir/samba-tool"
27 samba_newuser
="$samba_tool user create"
28 samba_texpect
="$samba_bindir/texpect"
29 samba_ktutil
="$BINDIR/samba4ktutil"
32 samba_kdestroy
=kdestroy
34 SERVER_FQDN
="$SERVER.$(echo $REALM | tr '[:upper:]' '[:lower:]')"
36 source `dirname $0`/subunit.sh
44 $VALGRIND $smbclient //$SERVER/tmp
-c "$cmd" $@
46 if [ x
$status = x0
]; then
60 echo "test: $testname"
62 NKEYS
=$
($VALGRIND $samba_ktutil $keytab |
grep -i "$principal" |
egrep -c "DES|AES|ArcFour")
64 if [ x
$status != x0
]; then
65 echo "failure: $testname"
69 if [ x
$NKEYS != x
$expected_nkeys ] ; then
70 echo "failure: $testname"
73 echo "success: $testname"
78 TEST_PASSWORD
=testPaSS@
01%
80 testit
"create local user $TEST_USER" $VALGRIND $samba_newuser $TEST_USER $TEST_PASSWORD $@ || failed
=`expr $failed + 1`
82 testit
"dump keytab from domain" $VALGRIND $samba_tool domain exportkeytab
$PREFIX/tmpkeytab-all $@ || failed
=`expr $failed + 1`
83 test_keytab
"read keytab from domain" "$PREFIX/tmpkeytab-all" "$SERVER\\\$" 5
85 testit
"dump keytab from domain (2nd time)" $VALGRIND $samba_tool domain exportkeytab
$PREFIX/tmpkeytab-all $@ || failed
=`expr $failed + 1`
86 test_keytab
"read keytab from domain (2nd time)" "$PREFIX/tmpkeytab-all" "$SERVER\\\$" 5
88 testit
"dump keytab from domain for cifs service principal" $VALGRIND $samba_tool domain exportkeytab
$PREFIX/tmpkeytab-server
--principal=cifs
/$SERVER_FQDN $@ || failed
=`expr $failed + 1`
89 test_keytab
"read keytab from domain for cifs service principal" "$PREFIX/tmpkeytab-server" "cifs/$SERVER_FQDN" 5
90 testit
"dump keytab from domain for cifs service principal (2nd time)" $VALGRIND $samba_tool domain exportkeytab
$PREFIX/tmpkeytab-server
--principal=cifs
/$SERVER_FQDN $@ || failed
=`expr $failed + 1`
91 test_keytab
"read keytab from domain for cifs service principal (2nd time)" "$PREFIX/tmpkeytab-server" "cifs/$SERVER_FQDN" 5
93 testit
"dump keytab from domain for user principal" $VALGRIND $samba_tool domain exportkeytab
$PREFIX/tmpkeytab-user-princ
--principal=$TEST_USER $@ || failed
=`expr $failed + 1`
94 test_keytab
"dump keytab from domain for user principal" "$PREFIX/tmpkeytab-user-princ" "$TEST_USER@$REALM" 5
95 testit
"dump keytab from domain for user principal (2nd time)" $VALGRIND $samba_tool domain exportkeytab
$PREFIX/tmpkeytab-user-princ
--principal=$TEST_USER@
$REALM $@ || failed
=`expr $failed + 1`
96 test_keytab
"dump keytab from domain for user principal (2nd time)" "$PREFIX/tmpkeytab-user-princ" "$TEST_USER@$REALM" 5
98 KRB5CCNAME
="$PREFIX/tmpuserccache"
101 testit
"kinit with keytab as user" $VALGRIND $samba_kinit -k -t $PREFIX/tmpkeytab-all
$TEST_USER@
$REALM || failed
=`expr $failed + 1`
102 test_smbclient
"Test login with user kerberos ccache" 'ls' -k yes || failed
=`expr $failed + 1`
105 testit
"kinit with keytab as user (one princ)" $VALGRIND $samba_kinit -k -t $PREFIX/tmpkeytab-user-princ
$TEST_USER@
$REALM || failed
=`expr $failed + 1`
106 test_smbclient
"Test login with user kerberos ccache (one princ)" 'ls' -k yes || failed
=`expr $failed + 1`
109 KRB5CCNAME
="$PREFIX/tmpadminccache"
112 testit
"kinit with keytab as $USERNAME" $VALGRIND $samba_kinit -k -t $PREFIX/tmpkeytab-all
$USERNAME@
$REALM || failed
=`expr $failed + 1`
114 KRB5CCNAME
="$PREFIX/tmpserverccache"
116 echo "$samba_kinit -k -t $PREFIX/tmpkeytab-server cifs/$SERVER_FQDN"
117 testit
"kinit with SPN from keytab" $VALGRIND $samba_kinit -k -t $PREFIX/tmpkeytab-server cifs
/$SERVER_FQDN || failed
=`expr $failed + 1`
122 testit
"delete user $TEST_USER" $VALGRIND $samba_tool user delete nettestuser
-k yes $@ || failed
=`expr $failed + 1`
125 rm -f $PREFIX/tmpadminccache
$PREFIX/tmpuserccache
$PREFIX/tmpkeytab
$PREFIX/tmpkeytab-2
$PREFIX/tmpkeytab-server