Changeset 21 in openpam


Ignore:
Timestamp:
Feb 2, 2002, 6:37:08 PM (14 years ago)
Author:
des
Message:

Move linker-related code out into a separate file so it'll be easier
to restructure it later on.

Sponsored by: DARPA, NAI Labs

Location:
trunk/lib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Makefile

    r16 r21  
    4646SRCS            += openpam_dispatch.c
    4747SRCS            += openpam_findenv.c
     48SRCS            += openpam_load.c
    4849SRCS            += openpam_log.c
    4950SRCS            += openpam_ttyconv.c
  • trunk/lib/openpam_impl.h

    r20 r21  
    111111int             openpam_dispatch(pam_handle_t *, int, int);
    112112int             openpam_findenv(pam_handle_t *, const char *, size_t);
     113int             openpam_add_module(pam_handle_t *, int, int,
     114                                   const char *, const char *);
     115void            openpam_clear_chains(pam_handle_t *);
    113116
    114117#endif
  • trunk/lib/pam_end.c

    r18 r21  
    3535 */
    3636
    37 #include <dlfcn.h>
    3837#include <stdlib.h>
    3938
     
    5352        int status)
    5453{
    55         pam_chain_t *module;
    5654        pam_data_t *dp;
    5755        int i;
     
    7573
    7674        /* clear chains */
    77         for (i = 0; i < PAM_NUM_CHAINS; ++i) {
    78                 while (pamh->chains[i] != NULL) {
    79                         module = pamh->chains[i];
    80                         pamh->chains[i] = module->next;
    81                         /* XXX free options */
    82                         dlclose(module->dlh);
    83                         free(module->modpath);
    84                         free(module);
    85                 }
    86         }
     75        openpam_clear_chains(pamh);
    8776
    8877        /* clear items */
  • trunk/lib/pam_start.c

    r19 r21  
    3535 */
    3636
    37 #include <sys/param.h>
    38 
    3937#include <ctype.h>
    40 #include <dlfcn.h>
    4138#include <errno.h>
    4239#include <stdio.h>
     
    8885        pam_end(ph, r);
    8986        return (r);
    90 }
    91 
    92 /* XXX move to a different file */
    93 const char *_pam_sm_func_name[PAM_NUM_PRIMITIVES] = {
    94         "pam_sm_acct_mgmt",
    95         "pam_sm_authenticate",
    96         "pam_sm_chauthtok",
    97         "pam_sm_close_session",
    98         "pam_sm_open_session",
    99         "pam_sm_setcred"
    100 };
    101 
    102 static int
    103 _pam_add_module(pam_handle_t *pamh,
    104         int chain,
    105         int flag,
    106         const char *modpath,
    107         const char *options /* XXX */ __unused)
    108 {
    109         pam_chain_t *module, *iterator;
    110         int i;
    111 
    112         /* fill in configuration data */
    113         if ((module = malloc(sizeof(*module))) == NULL) {
    114                 openpam_log(PAM_LOG_ERROR, "malloc(): %m");
    115                 return (PAM_BUF_ERR);
    116         }
    117         if ((module->modpath = strdup(modpath)) == NULL) {
    118                 openpam_log(PAM_LOG_ERROR, "strdup(): %m");
    119                 free(module);
    120                 return (PAM_BUF_ERR);
    121         }
    122         module->flag = flag;
    123         module->next = NULL;
    124 
    125         /* load module and resolve symbols */
    126         /*
    127          * Each module is dlopen()'d once for evey time it occurs in
    128          * any chain.  While the linker is smart enough to not load
    129          * the same module more than once, it does waste space in the
    130          * form of linker handles and pam_func structs.
    131          *
    132          * TODO: implement a central module cache and replace the
    133          * array of pam_func structs in struct pam_chain with pointers
    134          * to the appropriate entry in the module cache.
    135          *
    136          * TODO: move this code out into a separate file to hide the
    137          * details of the module cache and linker API from this file.
    138          */
    139         if ((module->dlh = dlopen(modpath, RTLD_NOW)) == NULL) {
    140                 openpam_log(PAM_LOG_ERROR, "dlopen(): %s", dlerror());
    141                 free(module->modpath);
    142                 free(module);
    143                 return (PAM_OPEN_ERR);
    144         }
    145         for (i = 0; i < PAM_NUM_PRIMITIVES; ++i)
    146                 module->primitive[i] =
    147                     dlsym(module->dlh, _pam_sm_func_name[i]);
    148 
    149         if ((iterator = pamh->chains[chain]) != NULL) {
    150                 while (iterator->next != NULL)
    151                         iterator = iterator->next;
    152                 iterator->next = module;
    153         } else {
    154                 pamh->chains[chain] = module;
    155         }
    156         return (PAM_SUCCESS);
    15787}
    15888
     
    287217                 * appropriate chain and bump the counter.
    288218                 */
    289                 if ((r = _pam_add_module(pamh, chain, flag, p, q)) !=
     219                if ((r = openpam_add_module(pamh, chain, flag, p, q)) !=
    290220                    PAM_SUCCESS)
    291221                        return (-r);
Note: See TracChangeset for help on using the changeset viewer.