From 1eb4e2516e0e075f962ae95eb036cfe6bac3ecd3 Mon Sep 17 00:00:00 2001 From: Love Hornquist Astrand Date: Mon, 4 Mar 2013 10:18:16 -0800 Subject: [PATCH] unify hdb_so_method and hdb_method --- lib/hdb/hdb-ldap.c | 18 ++++++- lib/hdb/hdb.c | 116 +++++---------------------------------------- lib/hdb/hdb.h | 11 +---- 3 files changed, 30 insertions(+), 115 deletions(-) diff --git a/lib/hdb/hdb-ldap.c b/lib/hdb/hdb-ldap.c index 8ada46d8f..9191710c7 100644 --- a/lib/hdb/hdb-ldap.c +++ b/lib/hdb/hdb-ldap.c @@ -1932,14 +1932,30 @@ hdb_ldapi_create(krb5_context context, HDB ** db, const char *arg) #ifdef OPENLDAP_MODULE -struct hdb_so_method hdb_ldap_interface = { + +krb5_error_code KRB5_LIB_CALL * +init(krb5_context context, void **ctx) +{ + *ctx = NULL; +} + +void KRB5_LIB_CALL * +fini(void *ctx) +{ +} + +struct hdb_method hdb_ldap_interface = { HDB_INTERFACE_VERSION, + init, + fini, "ldap", hdb_ldap_create }; struct hdb_so_method hdb_ldapi_interface = { HDB_INTERFACE_VERSION, + init, + fini, "ldapi", hdb_ldapi_create }; diff --git a/lib/hdb/hdb.c b/lib/hdb/hdb.c index c129aa47c..443ea5ba0 100644 --- a/lib/hdb/hdb.c +++ b/lib/hdb/hdb.c @@ -65,34 +65,34 @@ const int hdb_interface_version = HDB_INTERFACE_VERSION; static struct hdb_method methods[] = { #if HAVE_DB1 || HAVE_DB3 - { HDB_INTERFACE_VERSION, "db:", hdb_db_create}, + { HDB_INTERFACE_VERSION, NULL, NULL, "db:", hdb_db_create}, #endif #if HAVE_DB1 - { HDB_INTERFACE_VERSION, "mit-db:", hdb_mitdb_create}, + { HDB_INTERFACE_VERSION, NULL, NULL, "mit-db:", hdb_mitdb_create}, #endif #if HAVE_MDB - { HDB_INTERFACE_VERSION, "mdb:", hdb_mdb_create}, + { HDB_INTERFACE_VERSION, NULL, NULL, "mdb:", hdb_mdb_create}, #endif #if HAVE_NDBM - { HDB_INTERFACE_VERSION, "ndbm:", hdb_ndbm_create}, + { HDB_INTERFACE_VERSION, NULL, NULL, "ndbm:", hdb_ndbm_create}, #endif - { HDB_INTERFACE_VERSION, "keytab:", hdb_keytab_create}, + { HDB_INTERFACE_VERSION, NULL, NULL, "keytab:", hdb_keytab_create}, #if defined(OPENLDAP) && !defined(OPENLDAP_MODULE) - { HDB_INTERFACE_VERSION, "ldap:", hdb_ldap_create}, - { HDB_INTERFACE_VERSION, "ldapi:", hdb_ldapi_create}, + { HDB_INTERFACE_VERSION, NULL, NULL, "ldap:", hdb_ldap_create}, + { HDB_INTERFACE_VERSION, NULL, NULL, "ldapi:", hdb_ldapi_create}, #endif #ifdef HAVE_SQLITE3 - { HDB_INTERFACE_VERSION, "sqlite:", hdb_sqlite_create}, + { HDB_INTERFACE_VERSION, NULL, NULL, "sqlite:", hdb_sqlite_create}, #endif - {0, NULL, NULL} + { 0, NULL, NULL, NULL, NULL} }; #if HAVE_DB1 || HAVE_DB3 static struct hdb_method dbmetod = - { HDB_INTERFACE_VERSION, "", hdb_db_create }; + { HDB_INTERFACE_VERSION, NULL, NULL, "", hdb_db_create }; #elif defined(HAVE_NDBM) static struct hdb_method dbmetod = - { HDB_INTERFACE_VERSION, "", hdb_ndbm_create }; + { HDB_INTERFACE_VERSION, NULL, NULL, "", hdb_ndbm_create }; #endif const Keys * @@ -293,100 +293,6 @@ hdb_init_db(krb5_context context, HDB *db) return ret2; } -#ifdef HAVE_DLOPEN - - /* - * Load a dynamic backend from /usr/heimdal/lib/hdb_NAME.so, - * looking for the hdb_NAME_create symbol. - */ - -static const struct hdb_method * -find_dynamic_method (krb5_context context, - const char *filename, - const char **rest) -{ - static struct hdb_method method; - struct hdb_so_method *mso; - char *prefix, *path, *symbol; - const char *p; - void *dl; - size_t len; - - p = strchr(filename, ':'); - - /* if no prefix, don't know what module to load, just ignore it */ - if (p == NULL) - return NULL; - - len = p - filename; - *rest = filename + len + 1; - - prefix = malloc(len + 1); - if (prefix == NULL) - krb5_errx(context, 1, "out of memory"); - strlcpy(prefix, filename, len + 1); - - if (asprintf(&path, LIBDIR "/hdb_%s.so", prefix) == -1) - krb5_errx(context, 1, "out of memory"); - -#ifndef RTLD_NOW -#define RTLD_NOW 0 -#endif -#ifndef RTLD_GLOBAL -#define RTLD_GLOBAL 0 -#endif - - dl = dlopen(path, RTLD_NOW | RTLD_GLOBAL); - if (dl == NULL) { - krb5_warnx(context, "error trying to load dynamic module %s: %s\n", - path, dlerror()); - free(prefix); - free(path); - return NULL; - } - - if (asprintf(&symbol, "hdb_%s_interface", prefix) == -1) - krb5_errx(context, 1, "out of memory"); - - mso = (struct hdb_so_method *) dlsym(dl, symbol); - if (mso == NULL) { - krb5_warnx(context, "error finding symbol %s in %s: %s\n", - symbol, path, dlerror()); - dlclose(dl); - free(symbol); - free(prefix); - free(path); - return NULL; - } - free(path); - free(symbol); - - if (mso->version != HDB_INTERFACE_VERSION) { - krb5_warnx(context, - "error wrong version in shared module %s " - "version: %d should have been %d\n", - prefix, mso->version, HDB_INTERFACE_VERSION); - dlclose(dl); - free(prefix); - return NULL; - } - - if (mso->create == NULL) { - krb5_errx(context, 1, - "no entry point function in shared mod %s ", - prefix); - dlclose(dl); - free(prefix); - return NULL; - } - - method.create = mso->create; - method.prefix = prefix; - - return &method; -} -#endif /* HAVE_DLOPEN */ - /* * find the relevant method for `filename', returning a pointer to the * rest in `rest'. diff --git a/lib/hdb/hdb.h b/lib/hdb/hdb.h index fddd360eb..a81771ec2 100644 --- a/lib/hdb/hdb.h +++ b/lib/hdb/hdb.h @@ -265,11 +265,10 @@ typedef struct HDB { #define HDB_INTERFACE_VERSION 8 -struct hdb_so_method { - int minor_version; +struct hdb_method { + int version; krb5_error_code (KRB5_LIB_CALL *init)(krb5_context, void **); void (KRB5_LIB_CALL *fini)(void *); - int version; const char *prefix; krb5_error_code (*create)(krb5_context, HDB **, const char *filename); }; @@ -289,12 +288,6 @@ typedef krb5_error_code (*hdb_foreach_func_t)(krb5_context, HDB*, hdb_entry_ex*, void*); extern krb5_kt_ops hdb_kt_ops; -struct hdb_method { - int interface_version; - const char *prefix; - krb5_error_code (*create)(krb5_context, HDB **, const char *filename); -}; - extern const int hdb_interface_version; #include