16 #include <security/pam_appl.h>
20 static void *libpam_h = NULL;
22 #define RESOLVE_PAM_FUNCTION(x, y, z, err) \
24 union { const void *tpointer; y(*fn) z; } fptr; \
25 fptr.tpointer = dlsym(libpam_h, #x); real_ ## x = fptr.fn; \
26 if (real_ ## x == NULL) { \
27 fprintf(stderr, "PAMDL: unable to resolve '%s': %s\n", #x, dlerror()); \
33 dlopen_pam(
const char *so)
37 libpam_h = dlopen(so, RTLD_GLOBAL|RTLD_NOW);
39 return libpam_h != NULL;
53 pam_start(
const char *service_name,
const char *user,
54 const struct pam_conv *pam_conversation,
57 int (*real_pam_start)(
const char *,
const char *,
58 const struct pam_conv *,
60 RESOLVE_PAM_FUNCTION(pam_start,
int, (
const char *,
const char *,
61 const struct pam_conv *,
62 pam_handle_t **), PAM_ABORT);
63 return real_pam_start(service_name, user, pam_conversation, pamh);
67 pam_end(pam_handle_t *pamh,
int pam_status)
69 int (*real_pam_end)(pam_handle_t *, int);
70 RESOLVE_PAM_FUNCTION(pam_end,
int, (pam_handle_t *,
int), PAM_ABORT);
71 return real_pam_end(pamh, pam_status);
75 pam_set_item(pam_handle_t *pamh,
int item_type,
const void *item)
77 int (*real_pam_set_item)(pam_handle_t *, int,
const void *);
78 RESOLVE_PAM_FUNCTION(pam_set_item,
int,
79 (pam_handle_t *,
int,
const void *), PAM_ABORT);
80 return real_pam_set_item(pamh, item_type, item);
84 pam_get_item(
const pam_handle_t *pamh,
int item_type,
const void **item)
86 int (*real_pam_get_item)(
const pam_handle_t *, int,
const void **);
87 RESOLVE_PAM_FUNCTION(pam_get_item,
int,
88 (
const pam_handle_t *,
int,
const void **),
90 return real_pam_get_item(pamh, item_type, item);
94 pam_fail_delay(pam_handle_t *pamh,
unsigned int musec_delay)
96 int (*real_pam_fail_delay)(pam_handle_t *,
unsigned int);
97 RESOLVE_PAM_FUNCTION(pam_fail_delay,
int, (pam_handle_t *,
unsigned int),
99 return real_pam_fail_delay(pamh, musec_delay);
102 typedef const char *const_char_pointer;
105 pam_strerror(pam_handle_t *pamh,
int errnum)
107 const_char_pointer (*real_pam_strerror)(pam_handle_t *, int);
108 RESOLVE_PAM_FUNCTION(pam_strerror, const_char_pointer,
109 (pam_handle_t *,
int), NULL);
110 return real_pam_strerror(pamh, errnum);
114 pam_putenv(pam_handle_t *pamh,
const char *
name_value)
116 int (*real_pam_putenv)(pam_handle_t *,
const char *);
117 RESOLVE_PAM_FUNCTION(pam_putenv,
int, (pam_handle_t *,
const char *),
123 pam_getenv(pam_handle_t *pamh,
const char *name)
125 const_char_pointer (*real_pam_getenv)(pam_handle_t *,
const char *);
126 RESOLVE_PAM_FUNCTION(pam_getenv, const_char_pointer,
127 (pam_handle_t *,
const char *), NULL);
128 return real_pam_getenv(pamh, name);
131 typedef char **char_ppointer;
133 pam_getenvlist(pam_handle_t *pamh)
135 char_ppointer (*real_pam_getenvlist)(pam_handle_t *);
136 RESOLVE_PAM_FUNCTION(pam_getenvlist, char_ppointer, (pam_handle_t *),
138 return real_pam_getenvlist(pamh);
144 pam_authenticate(pam_handle_t *pamh,
int flags)
146 int (*real_pam_authenticate)(pam_handle_t *, int);
147 RESOLVE_PAM_FUNCTION(pam_authenticate,
int, (pam_handle_t *,
int),
149 return real_pam_authenticate(pamh, flags);
153 pam_setcred(pam_handle_t *pamh,
int flags)
155 int (*real_pam_setcred)(pam_handle_t *, int);
156 RESOLVE_PAM_FUNCTION(pam_setcred,
int, (pam_handle_t *,
int), PAM_ABORT);
157 return real_pam_setcred(pamh, flags);
163 pam_acct_mgmt(pam_handle_t *pamh,
int flags)
165 int (*real_pam_acct_mgmt)(pam_handle_t *, int);
166 RESOLVE_PAM_FUNCTION(pam_acct_mgmt,
int, (pam_handle_t *,
int), PAM_ABORT);
167 return real_pam_acct_mgmt(pamh, flags);
173 pam_open_session(pam_handle_t *pamh,
int flags)
175 int (*real_pam_open_session)(pam_handle_t *, int);
176 RESOLVE_PAM_FUNCTION(pam_open_session,
int, (pam_handle_t *,
int),
178 return real_pam_open_session(pamh, flags);
182 pam_close_session(pam_handle_t *pamh,
int flags)
184 int (*real_pam_close_session)(pam_handle_t *, int);
185 RESOLVE_PAM_FUNCTION(pam_close_session,
int, (pam_handle_t *,
int),
187 return real_pam_close_session(pamh, flags);
193 pam_chauthtok(pam_handle_t *pamh,
int flags)
195 int (*real_pam_chauthtok)(pam_handle_t *, int);
196 RESOLVE_PAM_FUNCTION(pam_chauthtok,
int, (pam_handle_t *,
int), PAM_ABORT);
197 return real_pam_chauthtok(pamh, flags);