From 8c2f4c74b7f1546cdd506c680e1d1635a4af6bc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Tue, 10 Jan 2012 21:26:34 +0000 Subject: [PATCH] Use fdlopen(3) if it is available. git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@516 185d5e19-27fe-0310-9dcf-9bff6b9f3609 --- lib/openpam_dynamic.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/openpam_dynamic.c b/lib/openpam_dynamic.c index 1a05565..ef44180 100644 --- a/lib/openpam_dynamic.c +++ b/lib/openpam_dynamic.c @@ -40,6 +40,7 @@ #endif #include +#include #include #include #include @@ -60,14 +61,44 @@ * Perform sanity checks and attempt to load a module */ +#ifdef HAVE_FDLOPEN static void * try_dlopen(const char *modfn) { + void *dlh; + int fd; + + if ((fd = open(modfn, O_RDONLY)) < 0) + return (NULL); + if (openpam_check_desc_owner_perms(modfn, fd) != 0) { + close(fd); + return (NULL); + } + if ((dlh = fdlopen(fd, RTLD_NOW)) == NULL) { + openpam_log(PAM_LOG_ERROR, "%s: %s", modfn, dlerror()); + close(fd); + errno = 0; + return (NULL); + } + close(fd); + return (dlh); +} +#else +static void * +try_dlopen(const char *modfn) +{ + void *dlh; if (openpam_check_path_owner_perms(modfn) != 0) return (NULL); - return (dlopen(modfn, RTLD_NOW)); + if ((dlh = dlopen(modfn, RTLD_NOW)) == NULL) { + openpam_log(PAM_LOG_ERROR, "%s: %s", modfn, dlerror()); + errno = 0; + return (NULL); + } + return (dlh); } +#endif /* * OpenPAM internal @@ -124,7 +155,8 @@ buf_err: dlclose(dlh); FREE(module); err: - openpam_log(PAM_LOG_ERROR, "%m"); + if (errno != 0) + openpam_log(PAM_LOG_ERROR, "%s: %m", path); return (NULL); }