krb5, kadm5: refactor plugin API

Refactor plugin framework to use a single list of loaded plugins; add a new
plugin API where DSOs export a load function that can declare dependencies and
export multiple plugins; refactor kadm5 hook API to use krb5 plugin framework.

More information in krb5-plugin(7).
This commit is contained in:
Luke Howard
2019-01-01 21:55:36 +11:00
committed by Nico Williams
parent e9b3b2326d
commit 803efebca5
37 changed files with 1293 additions and 639 deletions

View File

@@ -35,6 +35,37 @@
RCSID("$Id$");
struct rename_principal_hook_ctx {
kadm5_server_context *context;
enum kadm5_hook_stage stage;
krb5_error_code code;
krb5_const_principal source, target;
};
static krb5_error_code
rename_principal_hook_cb(krb5_context context,
const void *hook,
void *hookctx,
void *userctx)
{
krb5_error_code ret;
const struct kadm5_hook_ftable *ftable = hook;
struct rename_principal_hook_ctx *ctx = userctx;
ret = ftable->rename(context, hookctx,
ctx->stage, ctx->code,
ctx->source, ctx->target);
if (ret != 0 && ret != KRB5_PLUGIN_NO_HANDLE)
_kadm5_s_set_hook_error_message(ctx->context, ret, "rename",
hook, ctx->stage);
/* only pre-commit plugins can abort */
if (ret == 0 || ctx->stage == KADM5_HOOK_STAGE_POSTCOMMIT)
ret = KRB5_PLUGIN_NO_HANDLE;
return ret;
}
static kadm5_ret_t
rename_principal_hook(kadm5_server_context *context,
enum kadm5_hook_stage stage,
@@ -42,23 +73,19 @@ rename_principal_hook(kadm5_server_context *context,
krb5_const_principal source,
krb5_const_principal target)
{
krb5_error_code ret = 0;
size_t i;
krb5_error_code ret;
struct rename_principal_hook_ctx ctx;
for (i = 0; i < context->num_hooks; i++) {
kadm5_hook_context *hook = context->hooks[i];
ctx.context = context;
ctx.stage = stage;
ctx.code = code;
ctx.source = source;
ctx.target = target;
if (hook->hook->rename != NULL) {
ret = hook->hook->rename(context->context, hook->data,
stage, code, source, target);
if (ret != 0) {
_kadm5_s_set_hook_error_message(context, ret, "rename",
hook->hook, stage);
if (stage == KADM5_HOOK_STAGE_PRECOMMIT)
break;
}
}
}
ret = _krb5_plugin_run_f(context->context, &kadm5_hook_plugin_data,
0, &ctx, rename_principal_hook_cb);
if (ret == KRB5_PLUGIN_NO_HANDLE)
ret = 0;
return ret;
}