Changeset 433

Show
Ignore:
Timestamp:
03/10/10 11:34:36 (5 months ago)
Author:
des
Message:

Add support for dynamic modules that contain a struct pam_module.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/openpam_dynamic.c

    r423 r433  
    6262openpam_dynamic(const char *path) 
    6363{ 
     64        const pam_module_t *dlmodule; 
    6465        pam_module_t *module; 
    6566        const char *prefix; 
     
    6970 
    7071        dlh = NULL; 
    71         if ((module = calloc(1, sizeof *module)) == NULL) 
    72                 goto buf_err; 
    7372 
    7473        /* Prepend the standard prefix if not an absolute pathname. */ 
     
    8079        /* try versioned module first, then unversioned module */ 
    8180        if (asprintf(&vpath, "%s%s.%d", prefix, path, LIB_MAJ) < 0) 
    82                 goto buf_err; 
     81                goto err; 
    8382        if ((dlh = dlopen(vpath, RTLD_NOW)) == NULL) { 
    8483                openpam_log(PAM_LOG_DEBUG, "%s: %s", vpath, dlerror()); 
     
    8786                        openpam_log(PAM_LOG_DEBUG, "%s: %s", vpath, dlerror()); 
    8887                        FREE(vpath); 
    89                         FREE(module); 
    9088                        return (NULL); 
    9189                } 
    9290        } 
    9391        FREE(vpath); 
     92        if ((module = calloc(1, sizeof *module)) == NULL) 
     93                goto buf_err; 
    9494        if ((module->path = strdup(path)) == NULL) 
    9595                goto buf_err; 
    9696        module->dlh = dlh; 
     97        dlmodule = dlsym(dlh, "_pam_module"); 
    9798        for (i = 0; i < PAM_NUM_PRIMITIVES; ++i) { 
    98                 module->func[i] = (pam_func_t)dlsym(dlh, _pam_sm_func_name[i]); 
     99                module->func[i] = dlmodule ? dlmodule->func[i] : 
     100                    (pam_func_t)dlsym(dlh, _pam_sm_func_name[i]); 
    99101                if (module->func[i] == NULL) 
    100102                        openpam_log(PAM_LOG_DEBUG, "%s: %s(): %s", 
     
    103105        return (module); 
    104106buf_err: 
    105         openpam_log(PAM_LOG_ERROR, "%m"); 
    106107        if (dlh != NULL) 
    107108                dlclose(dlh); 
    108109        FREE(module); 
     110err: 
     111        openpam_log(PAM_LOG_ERROR, "%m"); 
    109112        return (NULL); 
    110113}