Fix a number of bugs in the module cache:

- Don't log dlopen() failures, since they're rarely interesting;
   instead, log a failure if no module was found at all.

 - When loading  a versioned module, store its logical name in the
   module structure rather than its physical name, since it will be
   looked up by its logical name if it's needed again.

 - Initialize module->next->prev when adding a module to the cache.

 - Set modules to NULL when releasing the last module in the cache.

Sponsored by:	DARPA, NAI Labs


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@94 185d5e19-27fe-0310-9dcf-9bff6b9f3609
This commit is contained in:
Dag-Erling Smørgrav 2002-03-07 20:22:38 +00:00
parent 8c639c01ef
commit 70efc25d1c
2 changed files with 14 additions and 6 deletions

View File

@ -31,7 +31,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $P4: //depot/projects/openpam/lib/openpam_dynamic.c#2 $
* $P4: //depot/projects/openpam/lib/openpam_dynamic.c#3 $
*/
#include <dlfcn.h>
@ -64,15 +64,15 @@ openpam_dynamic(const char *path)
if (asprintf(&vpath, "%s.%d", path, LIB_MAJ) == -1)
goto buf_err;
if ((dlh = dlopen(vpath, RTLD_NOW)) == NULL) {
openpam_log(PAM_LOG_ERROR, "dlopen(): %s", dlerror());
*strrchr(vpath, '.') = '\0';
if ((dlh = dlopen(vpath, RTLD_NOW)) == NULL) {
openpam_log(PAM_LOG_ERROR, "dlopen(): %s", dlerror());
free(module);
return (NULL);
}
}
module->path = vpath;
free(vpath);
if ((module->path = strdup(path)) == NULL)
goto buf_err;
module->dlh = dlh;
for (i = 0; i < PAM_NUM_PRIMITIVES; ++i)
module->func[i] = dlsym(dlh, _pam_sm_func_name[i]);

View File

@ -31,7 +31,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $P4: //depot/projects/openpam/lib/openpam_load.c#11 $
* $P4: //depot/projects/openpam/lib/openpam_load.c#12 $
*/
#include <dlfcn.h>
@ -81,9 +81,14 @@ openpam_load_module(const char *path)
(module == NULL) ? "no" : "using", path);
}
#endif
if (module == NULL)
if (module == NULL) {
openpam_log(PAM_LOG_ERROR, "no %s found", path);
return (NULL);
}
openpam_log(PAM_LOG_DEBUG, "adding %s to cache", module->path);
module->next = modules;
if (module->next != NULL)
module->next->prev = module;
module->prev = NULL;
modules = module;
found:
@ -119,6 +124,9 @@ openpam_release_module(pam_module_t *module)
module->prev->next = module->next;
if (module->next != NULL)
module->next->prev = module->prev;
if (module == modules)
modules = module->next;
openpam_log(PAM_LOG_DEBUG, "releasing %s", module->path);
free(module->path);
free(module);
}