kadmin: Use kadm5_iter_principals() to list princs

Now that we have a properly working API for listing principals in an
online way, and a server-side implementation of it, use it.

This should work with old and new servers, but it will only be online
and fast when talking to new servers.

(Old servers have a bug though that prevents LIST from working.)
This commit is contained in:
Nicolas Williams
2022-03-18 00:28:23 -05:00
parent b92a02edda
commit 1dbfd4e835
4 changed files with 124 additions and 45 deletions

View File

@@ -84,6 +84,7 @@ struct get_entry_data {
struct field_info *chead, **ctail;
const char *krb5_config_fname;
uint32_t n;
int upto;
};
static int
@@ -478,6 +479,11 @@ do_get_entry(krb5_principal principal, void *data)
krb5_error_code ret;
struct get_entry_data *e = data;
if (e->upto == 0)
return EINTR;
if (e->upto > 0)
e->upto--;
memset(&princ, 0, sizeof(princ));
ret = kadm5_get_principal(kadm_handle, principal,
&princ,
@@ -534,8 +540,14 @@ static int
do_list_entry(krb5_principal principal, void *data)
{
char buf[1024];
int *upto = data;
krb5_error_code ret;
if (*upto == 0)
return EINTR;
if (*upto > 0)
(*upto)--;
ret = krb5_unparse_name_fixed_short(context, principal, buf, sizeof(buf));
if (ret != 0)
return ret;
@@ -544,13 +556,13 @@ do_list_entry(krb5_principal principal, void *data)
}
static int
listit(const char *funcname, int argc, char **argv)
listit(const char *funcname, int upto, int argc, char **argv)
{
int i;
krb5_error_code ret, saved_ret = 0;
for (i = 0; i < argc; i++) {
ret = foreach_principal(argv[i], do_list_entry, funcname, NULL);
ret = foreach_principal(argv[i], do_list_entry, funcname, &upto);
if (saved_ret == 0 && ret != 0)
saved_ret = ret;
}
@@ -577,7 +589,7 @@ getit(struct get_options *opt, const char *name, int argc, char **argv)
opt->short_flag = 1;
if (opt->terse_flag)
return listit(name, argc, argv);
return listit(name, opt->upto_integer, argc, argv);
data.table = NULL;
data.chead = NULL;
@@ -585,6 +597,7 @@ getit(struct get_options *opt, const char *name, int argc, char **argv)
data.mask = 0;
data.extra_mask = 0;
data.krb5_config_fname = opt->krb5_config_file_string;
data.upto = opt->upto_integer;
data.n = 0;
if(opt->short_flag) {
@@ -638,5 +651,6 @@ list_princs(struct list_options *opt, int argc, char **argv)
get_opt.short_flag = opt->short_flag;
get_opt.terse_flag = opt->terse_flag;
get_opt.column_info_string = opt->column_info_string;
get_opt.upto_integer = opt->upto_integer;
return getit(&get_opt, "list", argc, argv);
}