diff --git a/lib/krb5/context.c b/lib/krb5/context.c index 1e0cb6a5c..f150930f0 100644 --- a/lib/krb5/context.c +++ b/lib/krb5/context.c @@ -355,8 +355,17 @@ static void init_context_once(void *ctx) { krb5_context context = ctx; + char **dirs; - _krb5_load_plugins(context, "krb5", sysplugin_dirs); + dirs = krb5_config_get_strings(context, NULL, "libdefaults", + "plugin_dir", NULL); + if (dirs == NULL) + dirs = rk_UNCONST(sysplugin_dirs); + + _krb5_load_plugins(context, "krb5", (const char **)dirs); + + if (dirs != rk_UNCONST(sysplugin_dirs)) + krb5_config_free_strings(dirs); bindtextdomain(HEIMDAL_TEXTDOMAIN, HEIMDAL_LOCALEDIR); } diff --git a/lib/krb5/plugin.c b/lib/krb5/plugin.c index 3de03a895..ed6cea3a9 100644 --- a/lib/krb5/plugin.c +++ b/lib/krb5/plugin.c @@ -61,68 +61,6 @@ struct plugin { static HEIMDAL_MUTEX plugin_mutex = HEIMDAL_MUTEX_INITIALIZER; static struct plugin *registered = NULL; -static int plugins_needs_scan = 1; - -static const char *sysplugin_dirs[] = { - LIBDIR "/plugin/krb5", -#ifdef __APPLE__ - "/Library/KerberosPlugins/KerberosFrameworkPlugins", - "/System/Library/KerberosPlugins/KerberosFrameworkPlugins", -#endif - NULL -}; - -/* - * - */ - -void * -_krb5_plugin_get_symbol(struct krb5_plugin *p) -{ - return p->symbol; -} - -struct krb5_plugin * -_krb5_plugin_get_next(struct krb5_plugin *p) -{ - return p->next; -} - -/* - * - */ - -#ifdef HAVE_DLOPEN - -static krb5_error_code -loadlib(krb5_context context, char *path) -{ - struct plugin *e; - - e = calloc(1, sizeof(*e)); - if (e == NULL) { - krb5_set_error_message(context, ENOMEM, "malloc: out of memory"); - free(path); - return ENOMEM; - } - -#ifndef RTLD_LAZY -#define RTLD_LAZY 0 -#endif -#ifndef RTLD_LOCAL -#define RTLD_LOCAL 0 -#endif - e->type = DSO; - /* ignore error from dlopen, and just keep it as negative cache entry */ - e->u.dso.dsohandle = dlopen(path, RTLD_LOCAL|RTLD_LAZY); - e->u.dso.path = path; - - e->next = registered; - registered = e; - - return 0; -} -#endif /* HAVE_DLOPEN */ /** * Register a plugin symbol name of specific type. @@ -180,128 +118,6 @@ krb5_plugin_register(krb5_context context, return 0; } -static int -is_valid_plugin_filename(const char * n) -{ - if (n[0] == '.' && (n[1] == '\0' || (n[1] == '.' && n[2] == '\0'))) - return 0; - -#ifdef _WIN32 - /* On Windows, we only attempt to load .dll files as plug-ins. */ - { - const char * ext; - - ext = strrchr(n, '.'); - if (ext == NULL) - return 0; - - return !stricmp(ext, ".dll"); - } -#else - return 1; -#endif -} - -static void -trim_trailing_slash(char * path) -{ - size_t l; - - l = strlen(path); - while (l > 0 && (path[l - 1] == '/' -#ifdef BACKSLASH_PATH_DELIM - || path[l - 1] == '\\' -#endif - )) { - path[--l] = '\0'; - } -} - -static krb5_error_code -load_plugins(krb5_context context) -{ - struct plugin *e; - krb5_error_code ret; - char **dirs = NULL, **di; - struct dirent *entry; - char *path; - DIR *d = NULL; - - if (!plugins_needs_scan) - return 0; - plugins_needs_scan = 0; - -#ifdef HAVE_DLOPEN - - dirs = krb5_config_get_strings(context, NULL, "libdefaults", - "plugin_dir", NULL); - if (dirs == NULL) - dirs = rk_UNCONST(sysplugin_dirs); - - for (di = dirs; *di != NULL; di++) { - char * dir = *di; - -#ifdef KRB5_USE_PATH_TOKENS - if (_krb5_expand_path_tokens(context, *di, &dir)) - goto next_dir; -#endif - - trim_trailing_slash(dir); - - d = opendir(dir); - - if (d == NULL) - goto next_dir; - - rk_cloexec_dir(d); - - while ((entry = readdir(d)) != NULL) { - char *n = entry->d_name; - - /* skip . and .. */ - if (!is_valid_plugin_filename(n)) - continue; - - path = NULL; - ret = 0; -#ifdef __APPLE__ - { /* support loading bundles on MacOS */ - size_t len = strlen(n); - if (len > 7 && strcmp(&n[len - 7], ".bundle") == 0) - ret = asprintf(&path, "%s/%s/Contents/MacOS/%.*s", dir, n, (int)(len - 7), n); - } -#endif - if (ret < 0 || path == NULL) - ret = asprintf(&path, "%s/%s", dir, n); - - if (ret < 0 || path == NULL) { - ret = ENOMEM; - krb5_set_error_message(context, ret, "malloc: out of memory"); - return ret; - } - - /* check if already tried */ - for (e = registered; e != NULL; e = e->next) - if (e->type == DSO && strcmp(e->u.dso.path, path) == 0) - break; - if (e) { - free(path); - } else { - loadlib(context, path); /* store or frees path */ - } - } - closedir(d); - - next_dir: - if (dir != *di) - free(dir); - } - if (dirs != rk_UNCONST(sysplugin_dirs)) - krb5_config_free_strings(dirs); -#endif /* HAVE_DLOPEN */ - return 0; -} - static krb5_error_code add_symbol(krb5_context context, struct krb5_plugin **list, void *symbol) { @@ -331,8 +147,6 @@ _krb5_plugin_find(krb5_context context, HEIMDAL_MUTEX_lock(&plugin_mutex); - load_plugins(context); - for (ret = 0, e = registered; e != NULL; e = e->next) { switch(e->type) { case DSO: { diff --git a/lib/krb5/version-script.map b/lib/krb5/version-script.map index 3cb6852f4..f01fc6d32 100644 --- a/lib/krb5/version-script.map +++ b/lib/krb5/version-script.map @@ -745,8 +745,6 @@ HEIMDAL_KRB5_2.0 { _krb5_pk_octetstring2key; _krb5_plugin_find; _krb5_plugin_free; - _krb5_plugin_get_next; - _krb5_plugin_get_symbol; _krb5_plugin_run_f; _krb5_principal2principalname; _krb5_principalname2krb5_principal;