(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
This commit is contained in:
69
kadmin/ext.c
69
kadmin/ext.c
@@ -44,27 +44,68 @@ static int
|
|||||||
do_ext_keytab(krb5_principal principal, void *data)
|
do_ext_keytab(krb5_principal principal, void *data)
|
||||||
{
|
{
|
||||||
krb5_error_code ret;
|
krb5_error_code ret;
|
||||||
int i;
|
|
||||||
kadm5_principal_ent_rec princ;
|
kadm5_principal_ent_rec princ;
|
||||||
struct ext_keytab_data *e = data;
|
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,
|
ret = kadm5_get_principal(kadm_handle, principal, &princ,
|
||||||
KADM5_PRINCIPAL|KADM5_KVNO|KADM5_KEY_DATA);
|
KADM5_PRINCIPAL|KADM5_KVNO|KADM5_KEY_DATA);
|
||||||
if(ret)
|
if(ret)
|
||||||
return ret;
|
return ret;
|
||||||
for(i = 0; i < princ.n_key_data; i++){
|
|
||||||
krb5_keytab_entry key;
|
if (princ.n_key_data) {
|
||||||
krb5_key_data *k = &princ.key_data[i];
|
keys = malloc(sizeof(*keys) * princ.n_key_data);
|
||||||
key.principal = princ.principal;
|
if (keys == NULL) {
|
||||||
key.vno = k->key_data_kvno;
|
kadm5_free_principal_ent(kadm_handle, &princ);
|
||||||
key.keyblock.keytype = k->key_data_type[0];
|
krb5_clear_error_string(context);
|
||||||
key.keyblock.keyvalue.length = k->key_data_length[0];
|
return ENOMEM;
|
||||||
key.keyblock.keyvalue.data = k->key_data_contents[0];
|
}
|
||||||
key.timestamp = time(NULL);
|
for (i = 0; i < princ.n_key_data; i++) {
|
||||||
ret = krb5_kt_add_entry(context, e->keytab, &key);
|
krb5_key_data *k = &princ.key_data[i];
|
||||||
if(ret)
|
|
||||||
krb5_warn(context, ret, "krb5_kt_add_entry");
|
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);
|
kadm5_free_principal_ent(kadm_handle, &princ);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user