krb5_wrap: fix keep_old_entries logic in smb_krb5_kt_seek_and_delete_old_entries()
authorRalph Boehme <slow@samba.org>
Thu, 21 Apr 2016 18:55:36 +0000 (20:55 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Mon, 25 Apr 2016 08:35:14 +0000 (10:35 +0200)
commit35b2fb4ff3252a8fc340c8d7278314c7a0f6f894
treefc06d3c8fd9b830ce6125d97b220ff9529d968ad
parentb26ae7fbf66b4d79efc7a49164f93011d963333b
krb5_wrap: fix keep_old_entries logic in smb_krb5_kt_seek_and_delete_old_entries()

This fixes an regression introduced in 5c5d586d3ebd40 at a higher level
in the caller smb_krb5_kt_add_entry(): calling smb_krb5_kt_add_entry
with keep_old_entries=false resulted in only one enctype per principal
remaining in the exported keytab.

The function smb_krb5_kt_seek_and_delete_old_entries() is called from
smb_krb5_kt_add_entry() when adding keys to a keytab. When the keytab
contains keys with the same kvno as the key to be added and
keep_old_entries is false, the key is deleted without checking the
encryption type of the key. This means that when adding keys for a
principal only the last enctype will be in the exported keytab.

Fix this by checking the encryption type and only treat a key as "old"
if keytab_key_kvno <= new_key_kvno and keytab_key_enctype ==
new_key_enctype.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
lib/krb5_wrap/krb5_samba.c