From 3ffb12045467cb49dc4ad80f9d99f6c1d078e235 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Thu, 24 Aug 2006 08:40:56 +0000 Subject: [PATCH] (_kdc_get_preferred_key): new function, Use the order list of preferred encryption types and sort the available keys and return the most preferred key. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@17907 ec53bebd-3082-4978-b11e-865c3cabbd6b --- kdc/misc.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/kdc/misc.c b/kdc/misc.c index 47b9ddf60..494276a36 100644 --- a/kdc/misc.c +++ b/kdc/misc.c @@ -84,3 +84,39 @@ _kdc_free_ent(krb5_context context, hdb_entry_ex *ent) free (ent); } +/* + * Use the order list of preferred encryption types and sort the + * available keys and return the most preferred key. + */ + +krb5_error_code +_kdc_get_preferred_key(krb5_context context, + krb5_kdc_configuration *config, + hdb_entry_ex *h, + const char *name, + krb5_enctype *enctype, + Key **key) +{ + const krb5_enctype *p; + krb5_error_code ret; + int i; + + p = krb5_kerberos_enctypes(context); + + for (i = 0; p[i] != ETYPE_NULL; i++) { + if (krb5_enctype_valid(context, p[i]) != 0) + continue; + ret = hdb_enctype2key(context, + &h->entry, + p[i], + key); + if (ret == 0) { + *enctype = p[i]; + return 0; + } + } + + krb5_set_error_string(context, "No valid kerberos key found for %s", name); + return EINVAL; +} +