From f8de12c234f6dba880f3549fdc8f85880a2db4ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Tue, 6 Jul 2004 04:21:26 +0000 Subject: [PATCH] (do_ext_keytab): if there isn't any keydata, try using kadm5_randkey_principal git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@14029 ec53bebd-3082-4978-b11e-865c3cabbd6b --- kadmin/ext.c | 69 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 14 deletions(-) diff --git a/kadmin/ext.c b/kadmin/ext.c index 6dd47afea..abe367f35 100644 --- a/kadmin/ext.c +++ b/kadmin/ext.c @@ -44,27 +44,68 @@ static int do_ext_keytab(krb5_principal principal, void *data) { krb5_error_code ret; - int i; kadm5_principal_ent_rec princ; struct ext_keytab_data *e = data; - + krb5_keytab_entry *keys = NULL; + krb5_keyblock *k = NULL; + int i, n_k; + ret = kadm5_get_principal(kadm_handle, principal, &princ, KADM5_PRINCIPAL|KADM5_KVNO|KADM5_KEY_DATA); if(ret) return ret; - for(i = 0; i < princ.n_key_data; i++){ - krb5_keytab_entry key; - krb5_key_data *k = &princ.key_data[i]; - key.principal = princ.principal; - key.vno = k->key_data_kvno; - key.keyblock.keytype = k->key_data_type[0]; - key.keyblock.keyvalue.length = k->key_data_length[0]; - key.keyblock.keyvalue.data = k->key_data_contents[0]; - key.timestamp = time(NULL); - ret = krb5_kt_add_entry(context, e->keytab, &key); - if(ret) - krb5_warn(context, ret, "krb5_kt_add_entry"); + + if (princ.n_key_data) { + keys = malloc(sizeof(*keys) * princ.n_key_data); + if (keys == NULL) { + kadm5_free_principal_ent(kadm_handle, &princ); + krb5_clear_error_string(context); + return ENOMEM; + } + for (i = 0; i < princ.n_key_data; i++) { + krb5_key_data *k = &princ.key_data[i]; + + keys[i].principal = princ.principal; + keys[i].vno = k->key_data_kvno; + keys[i].keyblock.keytype = k->key_data_type[0]; + keys[i].keyblock.keyvalue.length = k->key_data_length[0]; + keys[i].keyblock.keyvalue.data = k->key_data_contents[0]; + keys[i].timestamp = time(NULL); + } + + n_k = princ.n_key_data; + } else { + ret = kadm5_randkey_principal(kadm_handle, principal, &k, &n_k); + if (ret) { + kadm5_free_principal_ent(kadm_handle, &princ); + return ret; + } + keys = malloc(sizeof(*keys) * n_k); + if (keys == NULL) { + kadm5_free_principal_ent(kadm_handle, &princ); + krb5_clear_error_string(context); + return ENOMEM; + } + for (i = 0; i < n_k; i++) { + keys[i].principal = principal; + keys[i].vno = princ.kvno + 1; /* XXX get entry again */ + keys[i].keyblock = k[i]; + keys[i].timestamp = time(NULL); + } } + + for(i = 0; i < n_k; i++) { + ret = krb5_kt_add_entry(context, e->keytab, &keys[i]); + if(ret) + krb5_warn(context, ret, "krb5_kt_add_entry(%d)", i); + } + + if (k) { + memset(k, 0, n_k * sizeof(*k)); + free(k); + } + if (keys) + free(keys); kadm5_free_principal_ent(kadm_handle, &princ); return 0; }