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

@@ -390,6 +390,8 @@ make_sym(const char *prefix)
return sym;
}
static const char *hdb_plugin_deps[] = { "hdb", "krb5", NULL };
krb5_error_code
hdb_list_builtin(krb5_context context, char **list)
{
@@ -414,12 +416,17 @@ hdb_list_builtin(krb5_context context, char **list)
if (h->create == NULL) {
struct cb_s cb_ctx;
char *f;
char *sym;
struct krb5_plugin_data hdb_plugin_data;
hdb_plugin_data.module = "krb5";
hdb_plugin_data.min_version = HDB_INTERFACE_VERSION;
hdb_plugin_data.deps = hdb_plugin_deps;
hdb_plugin_data.get_instance = hdb_get_instance;
/* Try loading the plugin */
if (asprintf(&f, "%sfoo", h->prefix) == -1)
f = NULL;
if ((sym = make_sym(h->prefix)) == NULL) {
if ((hdb_plugin_data.name = make_sym(h->prefix)) == NULL) {
free(buf);
free(f);
return krb5_enomem(context);
@@ -427,11 +434,10 @@ hdb_list_builtin(krb5_context context, char **list)
cb_ctx.filename = f;
cb_ctx.residual = NULL;
cb_ctx.h = NULL;
(void)_krb5_plugin_run_f(context, "krb5", sym,
HDB_INTERFACE_VERSION, 0, &cb_ctx,
callback);
(void)_krb5_plugin_run_f(context, &hdb_plugin_data, 0,
&cb_ctx, callback);
free(f);
free(sym);
free(rk_UNCONST(hdb_plugin_data.name));
if (cb_ctx.h == NULL || cb_ctx.h->create == NULL)
continue;
}
@@ -483,17 +489,35 @@ hdb_create(krb5_context context, HDB **db, const char *filename)
cb_ctx.filename = filename;
if (cb_ctx.h == NULL || cb_ctx.h->create == NULL) {
char *sym;
struct krb5_plugin_data hdb_plugin_data;
if ((sym = make_sym(filename)) == NULL)
hdb_plugin_data.module = "krb5";
hdb_plugin_data.min_version = HDB_INTERFACE_VERSION;
hdb_plugin_data.deps = hdb_plugin_deps;
hdb_plugin_data.get_instance = hdb_get_instance;
if ((hdb_plugin_data.name = make_sym(filename)) == NULL)
return krb5_enomem(context);
(void)_krb5_plugin_run_f(context, "krb5", sym, HDB_INTERFACE_VERSION,
(void)_krb5_plugin_run_f(context, &hdb_plugin_data,
0, &cb_ctx, callback);
free(sym);
free(rk_UNCONST(hdb_plugin_data.name));
}
if (cb_ctx.h == NULL)
krb5_errx(context, 1, "No database support for %s", cb_ctx.filename);
return (*cb_ctx.h->create)(context, db, cb_ctx.residual);
}
uintptr_t
hdb_get_instance(const char *libname)
{
static const char *instance = "libhdb";
if (strcmp(libname, "hdb") == 0)
return (uintptr_t)instance;
else if (strcmp(libname, "krb5") == 0)
return krb5_get_instance(libname);
return 0;
}

View File

@@ -31,6 +31,7 @@
* SUCH DAMAGE.
*/
#include "krb5_locl.h"
#include "hdb_locl.h"
struct hx509_certs_data;
@@ -45,7 +46,6 @@ struct _krb5_key_data;
struct _krb5_encryption_type;
struct _krb5_key_type;
#include <pkinit_asn1.h>
#include <krb5-private.h>
#include <base64.h>
/*

View File

@@ -43,6 +43,7 @@ EXPORTS
hdb_generate_key_set_password
hdb_generate_key_set_password_with_ks_tuple
hdb_get_dbinfo
hdb_get_instance
hdb_init_db
hdb_interface_version DATA
hdb_key2principal

View File

@@ -46,6 +46,7 @@ HEIMDAL_HDB_1.0 {
hdb_generate_key_set_password;
hdb_generate_key_set_password_with_ks_tuple;
hdb_get_dbinfo;
hdb_get_instance;
hdb_init_db;
hdb_key2principal;
hdb_kvno2keys;