selftest/samba4.blackbox.export.keytab: check exported keytabs
authorRalph Boehme <slow@samba.org>
Fri, 22 Apr 2016 21:59:12 +0000 (23:59 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Mon, 25 Apr 2016 08:35:14 +0000 (10:35 +0200)
Now that we have a usable ktutil, actually verify that the exported
keytabs contains the keys we expect.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
testprogs/blackbox/test_export_keytab_heimdal.sh

index 3bfd61ca62ed379ea9c6386c46a1c93f5e6be09f..8ee9e9e3638084aea9a096582cd0043d53f96038 100755 (executable)
@@ -21,6 +21,7 @@ failed=0
 
 samba4bindir="$BINDIR"
 samba_tool="$samba4bindir/samba-tool"
+samba4ktutil="$BINDIR/samba4ktutil"
 newuser="$samba_tool user create"
 
 SERVER_FQDN="$SERVER.$(echo $REALM | tr '[:upper:]' '[:lower:]')"
@@ -48,18 +49,47 @@ test_smbclient() {
        return $status
 }
 
+test_keytab() {
+       testname="$1"
+       keytab="$2"
+       principal="$3"
+       expected_nkeys="$4"
+
+       echo "test: $testname"
+
+       NKEYS=$($VALGRIND $samba4ktutil $keytab | grep -i "$principal" | egrep -c "des|aes|arcfour")
+       status=$?
+       if [ x$status != x0 ]; then
+               echo "failure: $testname"
+               return $status
+       fi
+
+       if [ x$NKEYS != x$expected_nkeys ] ; then
+               echo "failure: $testname"
+               return 1
+       fi
+       echo "success: $testname"
+       return 0
+}
+
 USERPASS=testPaSS@01%
 
 testit "create user locally" $VALGRIND $newuser nettestuser $USERPASS $@ || failed=`expr $failed + 1`
 
 testit "dump keytab from domain" $VALGRIND $samba_tool domain exportkeytab $PREFIX/tmpkeytab $@ || failed=`expr $failed + 1`
+test_keytab "read keytab from domain" "$PREFIX/tmpkeytab" "$SERVER\\\$" 5
 testit "dump keytab from domain (2nd time)" $VALGRIND $samba_tool domain exportkeytab $PREFIX/tmpkeytab $@ || failed=`expr $failed + 1`
+test_keytab "read keytab from domain (2nd time)" "$PREFIX/tmpkeytab" "$SERVER\\\$" 5
 
 testit "dump keytab from domain for cifs principal" $VALGRIND $samba_tool domain exportkeytab $PREFIX/tmpkeytab-server --principal=cifs/$SERVER_FQDN $@ || failed=`expr $failed + 1`
+test_keytab "read keytab from domain for cifs principal" "$PREFIX/tmpkeytab-server" "cifs/$SERVER_FQDN" 5
 testit "dump keytab from domain for cifs principal (2nd time)" $VALGRIND $samba_tool domain exportkeytab $PREFIX/tmpkeytab-server --principal=cifs/$SERVER_FQDN $@ || failed=`expr $failed + 1`
+test_keytab "read keytab from domain for cifs principal (2nd time)" "$PREFIX/tmpkeytab-server" "cifs/$SERVER_FQDN" 5
 
 testit "dump keytab from domain for user principal" $VALGRIND $samba_tool domain exportkeytab $PREFIX/tmpkeytab-2 --principal=nettestuser $@ || failed=`expr $failed + 1`
+test_keytab "dump keytab from domain for user principal" "$PREFIX/tmpkeytab-2" "nettestuser@$REALM" 5
 testit "dump keytab from domain for user principal (2nd time)" $VALGRIND $samba_tool domain exportkeytab $PREFIX/tmpkeytab-2 --principal=nettestuser@$REALM $@ || failed=`expr $failed + 1`
+test_keytab "dump keytab from domain for user principal (2nd time)" "$PREFIX/tmpkeytab-2" "nettestuser@$REALM" 5
 
 KRB5CCNAME="$PREFIX/tmpuserccache"
 export KRB5CCNAME