From 385eb53d63d859dbcd684348d4c404e2a1ec2eef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Wed, 10 Mar 2010 11:34:36 +0000 Subject: [PATCH] Add support for dynamic modules that contain a struct pam_module. git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@433 185d5e19-27fe-0310-9dcf-9bff6b9f3609 --- lib/openpam_dynamic.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/openpam_dynamic.c b/lib/openpam_dynamic.c index 33f99b2..b1ef6ba 100644 --- a/lib/openpam_dynamic.c +++ b/lib/openpam_dynamic.c @@ -61,6 +61,7 @@ pam_module_t * openpam_dynamic(const char *path) { + const pam_module_t *dlmodule; pam_module_t *module; const char *prefix; char *vpath; @@ -68,8 +69,6 @@ openpam_dynamic(const char *path) int i; dlh = NULL; - if ((module = calloc(1, sizeof *module)) == NULL) - goto buf_err; /* Prepend the standard prefix if not an absolute pathname. */ if (path[0] != '/') @@ -79,33 +78,37 @@ openpam_dynamic(const char *path) /* try versioned module first, then unversioned module */ if (asprintf(&vpath, "%s%s.%d", prefix, path, LIB_MAJ) < 0) - goto buf_err; + goto err; if ((dlh = dlopen(vpath, RTLD_NOW)) == NULL) { openpam_log(PAM_LOG_DEBUG, "%s: %s", vpath, dlerror()); *strrchr(vpath, '.') = '\0'; if ((dlh = dlopen(vpath, RTLD_NOW)) == NULL) { openpam_log(PAM_LOG_DEBUG, "%s: %s", vpath, dlerror()); FREE(vpath); - FREE(module); return (NULL); } } FREE(vpath); + if ((module = calloc(1, sizeof *module)) == NULL) + goto buf_err; if ((module->path = strdup(path)) == NULL) goto buf_err; module->dlh = dlh; + dlmodule = dlsym(dlh, "_pam_module"); for (i = 0; i < PAM_NUM_PRIMITIVES; ++i) { - module->func[i] = (pam_func_t)dlsym(dlh, _pam_sm_func_name[i]); + module->func[i] = dlmodule ? dlmodule->func[i] : + (pam_func_t)dlsym(dlh, _pam_sm_func_name[i]); if (module->func[i] == NULL) openpam_log(PAM_LOG_DEBUG, "%s: %s(): %s", path, _pam_sm_func_name[i], dlerror()); } return (module); buf_err: - openpam_log(PAM_LOG_ERROR, "%m"); if (dlh != NULL) dlclose(dlh); FREE(module); +err: + openpam_log(PAM_LOG_ERROR, "%m"); return (NULL); }