kadmin: add ext_keytab --random-key switch
Add a --random-key switch to kadmin's ext_keytab to force the generation of a new keyset consisting of random keys and a new key version number.
This commit is contained in:

committed by
Nicolas Williams

parent
34bf7ae162
commit
15e69fbb58
35
kadmin/ext.c
35
kadmin/ext.c
@@ -36,6 +36,7 @@
|
|||||||
|
|
||||||
struct ext_keytab_data {
|
struct ext_keytab_data {
|
||||||
krb5_keytab keytab;
|
krb5_keytab keytab;
|
||||||
|
int random_key_flag;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@@ -48,10 +49,14 @@ do_ext_keytab(krb5_principal principal, void *data)
|
|||||||
krb5_keyblock *k = NULL;
|
krb5_keyblock *k = NULL;
|
||||||
size_t i;
|
size_t i;
|
||||||
int n_k = 0;
|
int n_k = 0;
|
||||||
|
uint32_t mask;
|
||||||
char *unparsed = NULL;
|
char *unparsed = NULL;
|
||||||
|
|
||||||
ret = kadm5_get_principal(kadm_handle, principal, &princ,
|
mask = KADM5_PRINCIPAL;
|
||||||
KADM5_PRINCIPAL|KADM5_KVNO|KADM5_KEY_DATA);
|
if (!e->random_key_flag)
|
||||||
|
mask |= KADM5_KVNO | KADM5_KEY_DATA;
|
||||||
|
|
||||||
|
ret = kadm5_get_principal(kadm_handle, principal, &princ, mask);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
@@ -59,7 +64,12 @@ do_ext_keytab(krb5_principal principal, void *data)
|
|||||||
if (ret)
|
if (ret)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (princ.n_key_data) {
|
if (!e->random_key_flag) {
|
||||||
|
if (princ.n_key_data == 0) {
|
||||||
|
krb5_warnx(context, "principal has no keys, or user lacks "
|
||||||
|
"get-keys privilege for %s", unparsed);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
keys = calloc(sizeof(*keys), princ.n_key_data);
|
keys = calloc(sizeof(*keys), princ.n_key_data);
|
||||||
if (keys == NULL) {
|
if (keys == NULL) {
|
||||||
ret = krb5_enomem(context);
|
ret = krb5_enomem(context);
|
||||||
@@ -71,11 +81,10 @@ do_ext_keytab(krb5_principal principal, void *data)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* If the kadm5 client princ lacks get-keys then it may get
|
* If the kadm5 client princ lacks get-keys then it may get
|
||||||
* bogus keys four bytes long.
|
* bogus keys. This should only happen with kadmind servers
|
||||||
|
* running master code from somewhere between 1.5 and 1.6.
|
||||||
*/
|
*/
|
||||||
if ((kd->key_data_length[0] == sizeof (KADM5_BOGUS_KEY_DATA) - 1)
|
if (kadm5_some_keys_are_bogus(1, kd)) {
|
||||||
&& (ct_memcmp(kd->key_data_contents[0], KADM5_BOGUS_KEY_DATA,
|
|
||||||
kd->key_data_length[0]) == 0)) {
|
|
||||||
if (!warned) {
|
if (!warned) {
|
||||||
krb5_warnx(context, "user lacks get-keys privilege for %s",
|
krb5_warnx(context, "user lacks get-keys privilege for %s",
|
||||||
unparsed);
|
unparsed);
|
||||||
@@ -92,9 +101,7 @@ do_ext_keytab(krb5_principal principal, void *data)
|
|||||||
keys[i].timestamp = time(NULL);
|
keys[i].timestamp = time(NULL);
|
||||||
n_k++;
|
n_k++;
|
||||||
}
|
}
|
||||||
}
|
} else if (e->random_key_flag) {
|
||||||
|
|
||||||
if (n_k == 0) {
|
|
||||||
/* Probably lack get-keys privilege, but we may be able to set keys */
|
/* Probably lack get-keys privilege, but we may be able to set keys */
|
||||||
ret = kadm5_randkey_principal(kadm_handle, principal, &k, &n_k);
|
ret = kadm5_randkey_principal(kadm_handle, principal, &k, &n_k);
|
||||||
if (ret)
|
if (ret)
|
||||||
@@ -113,6 +120,9 @@ do_ext_keytab(krb5_principal principal, void *data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (n_k == 0)
|
||||||
|
krb5_warn(context, ret, "no keys written to keytab for %s", unparsed);
|
||||||
|
|
||||||
for (i = 0; i < n_k; i++) {
|
for (i = 0; i < n_k; i++) {
|
||||||
ret = krb5_kt_add_entry(context, e->keytab, &keys[i]);
|
ret = krb5_kt_add_entry(context, e->keytab, &keys[i]);
|
||||||
if (ret)
|
if (ret)
|
||||||
@@ -122,7 +132,8 @@ do_ext_keytab(krb5_principal principal, void *data)
|
|||||||
out:
|
out:
|
||||||
kadm5_free_principal_ent(kadm_handle, &princ);
|
kadm5_free_principal_ent(kadm_handle, &princ);
|
||||||
if (k) {
|
if (k) {
|
||||||
memset(k, 0, n_k * sizeof(*k));
|
for (i = 0; i < n_k; i++)
|
||||||
|
memset(k[i].keyvalue.data, 0, k[i].keyvalue.length);
|
||||||
free(k);
|
free(k);
|
||||||
}
|
}
|
||||||
free(unparsed);
|
free(unparsed);
|
||||||
@@ -147,6 +158,8 @@ ext_keytab(struct ext_keytab_options *opt, int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.random_key_flag = opt->random_key_flag;
|
||||||
|
|
||||||
for(i = 0; i < argc; i++) {
|
for(i = 0; i < argc; i++) {
|
||||||
ret = foreach_principal(argv[i], do_ext_keytab, "ext", &data);
|
ret = foreach_principal(argv[i], do_ext_keytab, "ext", &data);
|
||||||
if (ret)
|
if (ret)
|
||||||
|
@@ -280,6 +280,12 @@ command = {
|
|||||||
type = "string"
|
type = "string"
|
||||||
help = "keytab to use"
|
help = "keytab to use"
|
||||||
}
|
}
|
||||||
|
option = {
|
||||||
|
long = "random-key"
|
||||||
|
short = "r"
|
||||||
|
type = "flag"
|
||||||
|
help = "set random key"
|
||||||
|
}
|
||||||
argument = "principal..."
|
argument = "principal..."
|
||||||
min_args = "1"
|
min_args = "1"
|
||||||
help = "Extracts the keys of all principals matching the expressions, and stores them in a keytab."
|
help = "Extracts the keys of all principals matching the expressions, and stores them in a keytab."
|
||||||
|
Reference in New Issue
Block a user