1 /* pam_handlers.c -- pam config file parsing and module loading */
4 * created by Marc Ewing.
5 * Currently maintained by Andrew G. Morgan <morgan@linux.kernel.org>
7 * $Id: pam_handlers.c,v 1.17 1997/04/05 06:55:24 morgan Exp morgan $
8 * $FreeBSD: src/contrib/libpam/libpam/pam_handlers.c,v 1.1.1.1.6.2 2001/06/11 15:28:12 markm Exp $
15 #include <sys/types.h>
25 #include "pam_private.h"
27 /* FreeBSD doesn't define this */
32 /* If not required, define as nothing - FreeBSD needs it to be "_"... */
33 #ifndef SHLIB_SYM_PREFIX
34 # define SHLIB_SYM_PREFIX ""
38 #define MODULE_CHUNK 4
40 static int _pam_assemble_line(FILE *f, char *buf, int buf_len);
42 static void _pam_free_handlers_aux(struct handler **hp);
44 static int _pam_add_handler(pam_handle_t *pamh
45 , int must_fail, int other, int type
46 , int *actions, const char *mod_path
47 , int argc, char **argv, int argvlen);
49 /* Values for module type */
56 static int _pam_parse_conf_file(pam_handle_t *pamh, FILE *f
57 , const char *known_service /* specific file */
58 #ifdef PAM_READ_BOTH_CONFS
60 #endif /* PAM_READ_BOTH_CONFS */
64 int x; /* read a line from the FILE *f ? */
66 * read a line from the configuration (FILE *) f
68 while ((x = _pam_assemble_line(f, buf, BUF_SIZE)) > 0) {
69 char *tok, *nexttok=NULL;
70 const char *this_service;
72 int module_type, actions[_PAM_RETURN_VALUES];
73 int other; /* set if module is for PAM_DEFAULT_SERVICE */
74 int res; /* module added successfully? */
75 int must_fail=0; /* a badly formatted line must fail when used */
80 D(("_pam_init_handler: LINE: %s", buf));
81 if (known_service != NULL) {
83 /* No service field: all lines are for the known service. */
84 this_service = known_service;
86 this_service = tok = _pam_StrTok(buf, " \n\t", &nexttok);
89 #ifdef PAM_READ_BOTH_CONFS
93 #endif /* PAM_READ_BOTH_CONFS */
94 other = !_pam_strCMP(this_service, PAM_DEFAULT_SERVICE);
96 /* accept "service name" or PAM_DEFAULT_SERVICE modules */
97 if (!_pam_strCMP(this_service, pamh->service_name) || other) {
98 /* This is a service we are looking for */
99 D(("_pam_init_handlers: Found PAM config entry for: %s"
102 tok = _pam_StrTok(NULL, " \n\t", &nexttok);
103 if (!_pam_strCMP("auth", tok)) {
104 module_type = PAM_T_AUTH;
105 } else if (!_pam_strCMP("session", tok)) {
106 module_type = PAM_T_SESS;
107 } else if (!_pam_strCMP("account", tok)) {
108 module_type = PAM_T_ACCT;
109 } else if (!_pam_strCMP("password", tok)) {
110 module_type = PAM_T_PASS;
112 /* Illegal module type */
113 D(("_pam_init_handlers: bad module type: %s", tok));
114 pam_system_log(pamh, NULL, LOG_ERR,
115 "(%s) illegal module type: %s"
116 , this_service, tok);
117 module_type = PAM_T_AUTH; /* most sensitive */
118 must_fail = 1; /* install as normal but fail when dispatched */
120 D(("Using %s config entry: %s", must_fail?"BAD ":"", tok));
122 /* reset the actions to .._UNDEF's -- this is so that
123 we can work out which entries are not yet set (for default). */
126 for (i=0; i<_PAM_RETURN_VALUES;
127 actions[i++] = _PAM_ACTION_UNDEF);
129 tok = _pam_StrTok(NULL, " \n\t", &nexttok);
130 if (!_pam_strCMP("required", tok)) {
131 D(("*PAM_F_REQUIRED*"));
132 actions[PAM_SUCCESS] = _PAM_ACTION_OK;
133 actions[PAM_NEW_AUTHTOK_REQD] = _PAM_ACTION_OK;
134 actions[PAM_IGNORE] = _PAM_ACTION_IGNORE;
135 _pam_set_default_control(actions, _PAM_ACTION_BAD);
136 } else if (!_pam_strCMP("requisite", tok)) {
137 D(("*PAM_F_REQUISITE*"));
138 actions[PAM_SUCCESS] = _PAM_ACTION_OK;
139 actions[PAM_NEW_AUTHTOK_REQD] = _PAM_ACTION_OK;
140 actions[PAM_IGNORE] = _PAM_ACTION_IGNORE;
141 _pam_set_default_control(actions, _PAM_ACTION_DIE);
142 } else if (!_pam_strCMP("optional", tok)) {
143 D(("*PAM_F_OPTIONAL*"));
144 actions[PAM_SUCCESS] = _PAM_ACTION_OK;
145 actions[PAM_NEW_AUTHTOK_REQD] = _PAM_ACTION_OK;
146 _pam_set_default_control(actions, _PAM_ACTION_IGNORE);
147 } else if (!_pam_strCMP("sufficient", tok)) {
148 D(("*PAM_F_SUFFICIENT*"));
149 actions[PAM_SUCCESS] = _PAM_ACTION_DONE;
150 actions[PAM_NEW_AUTHTOK_REQD] = _PAM_ACTION_DONE;
151 _pam_set_default_control(actions, _PAM_ACTION_IGNORE);
153 D(("will need to parse %s", tok));
154 _pam_parse_control(actions, tok);
155 /* by default the default is to treat as failure */
156 _pam_set_default_control(actions, _PAM_ACTION_BAD);
159 tok = _pam_StrTok(NULL, " \n\t", &nexttok);
162 D(("mod_path = %s",mod_path));
164 /* no module name given */
165 D(("_pam_init_handlers: no module name supplied"));
166 pam_system_log(pamh, NULL, LOG_ERR,
167 "(%s) no module name supplied", this_service);
172 /* nexttok points to remaining arguments... */
174 if (nexttok != NULL) {
175 D(("list: %s",nexttok));
176 argvlen = _pam_mkargv(nexttok, &argv, &argc);
177 D(("argvlen = %d",argvlen));
178 } else { /* there are no arguments so fix by hand */
179 D(("_pam_init_handlers: empty argument list"));
188 D(("CONF%s: %s%s %d %s %d"
189 , must_fail?"<*will fail*>":""
190 , this_service, other ? "(backup)":""
193 for (y = 0; y < argc; y++) {
194 D(("CONF: %s", argv[y]));
196 for (y = 0; y<_PAM_RETURN_VALUES; ++y) {
197 D(("RETURN %s(%d) -> %d %s",
198 _pam_token_returns[y], y, actions[y],
199 actions[y]>0 ? "jump":
200 _pam_token_actions[-actions[y]]));
202 fprintf(stderr, "pause to look at debugging: ");
207 res = _pam_add_handler(pamh, must_fail, other
208 , module_type, actions, mod_path
209 , argc, argv, argvlen);
210 if (res != PAM_SUCCESS) {
211 pam_system_log(pamh, NULL, LOG_ERR,
212 "error loading %s", mod_path);
213 D(("failed to load module - aborting"));
219 return ( (x < 0) ? PAM_ABORT:PAM_SUCCESS );
222 /* Parse config file, allocate handler structures, dlopen() */
223 int _pam_init_handlers(pam_handle_t *pamh)
228 D(("_pam_init_handlers called"));
229 IF_NO_PAMH("_pam_init_handlers",pamh,PAM_SYSTEM_ERR);
231 /* Return immediately if everything is already loaded */
232 if (pamh->handlers.handlers_loaded) {
236 D(("_pam_init_handlers: initializing"));
238 /* First clean the service structure */
240 _pam_free_handlers(pamh);
241 if (! pamh->handlers.module) {
242 if ((pamh->handlers.module =
243 malloc(MODULE_CHUNK * sizeof(struct loaded_module))) == NULL) {
244 pam_system_log(pamh, NULL, LOG_CRIT,
245 "_pam_init_handlers: no memory loading module");
248 pamh->handlers.modules_allocated = MODULE_CHUNK;
249 pamh->handlers.modules_used = 0;
252 if (pamh->service_name == NULL) {
253 return PAM_BAD_ITEM; /* XXX - better error? */
257 /* Is the PAM subsystem locked? */
261 if ((fd_tmp = open( PAM_LOCK_FILE, O_RDONLY )) != -1) {
262 pam_system_log(pamh, NULL, LOG_ERR,
263 "_pam_init_handlers: PAM lockfile ("
264 PAM_LOCK_FILE ") exists - aborting");
265 (void) close(fd_tmp);
267 * to avoid swamping the system with requests
269 _pam_start_timer(pamh);
270 pam_fail_delay(pamh, 5000000);
271 _pam_await_timer(pamh, PAM_ABORT);
276 #endif /* PAM_LOCKING */
279 * Now parse the config file(s) and add handlers
284 /* Is there a PAM_CONFIG_D directory? */
285 if ( stat(PAM_CONFIG_D, &test_d) == 0 && S_ISDIR(test_d.st_mode) ) {
287 int read_something=0;
289 D(("searching " PAM_CONFIG_D " for config files"));
290 filename = malloc(sizeof(PAM_CONFIG_DF)
291 +strlen(pamh->service_name));
292 if (filename == NULL) {
293 pam_system_log(pamh, NULL, LOG_ERR,
294 "_pam_init_handlers: no memory; service %s",
298 sprintf(filename, PAM_CONFIG_DF, pamh->service_name);
299 D(("opening %s", filename));
300 f = fopen(filename, "r");
302 /* would test magic here? */
303 retval = _pam_parse_conf_file(pamh, f, pamh->service_name
304 #ifdef PAM_READ_BOTH_CONFS
306 #endif /* PAM_READ_BOTH_CONFS */
309 if (retval != PAM_SUCCESS) {
310 pam_system_log(pamh, NULL, LOG_ERR,
311 "_pam_init_handlers: error reading %s",
313 pam_system_log(pamh, NULL, LOG_ERR,
314 "_pam_init_handlers: [%s]",
315 pam_strerror(pamh, retval));
320 D(("unable to open %s", filename));
321 #ifdef PAM_READ_BOTH_CONFS
322 D(("checking %s", PAM_CONFIG));
324 if ((f = fopen(PAM_CONFIG,"r")) != NULL) {
325 retval = _pam_parse_conf_file(pamh, f, NULL, 1);
328 #endif /* PAM_READ_BOTH_CONFS */
329 retval = PAM_SUCCESS;
331 * XXX - should we log an error? Some people want to always
337 if (retval == PAM_SUCCESS) {
338 /* now parse the PAM_DEFAULT_SERVICE_FILE */
340 D(("opening %s", PAM_DEFAULT_SERVICE_FILE));
341 f = fopen(PAM_DEFAULT_SERVICE_FILE, "r");
343 /* would test magic here? */
344 retval = _pam_parse_conf_file(pamh, f
345 , PAM_DEFAULT_SERVICE
346 #ifdef PAM_READ_BOTH_CONFS
348 #endif /* PAM_READ_BOTH_CONFS */
351 if (retval != PAM_SUCCESS) {
352 pam_system_log(pamh, NULL, LOG_ERR,
353 "_pam_init_handlers: error reading %s",
354 PAM_DEFAULT_SERVICE_FILE);
355 pam_system_log(pamh, NULL, LOG_ERR,
356 "_pam_init_handlers: [%s]",
357 pam_strerror(pamh, retval));
362 D(("unable to open %s", PAM_DEFAULT_SERVICE_FILE));
363 pam_system_log(pamh, NULL, LOG_ERR,
364 "_pam_init_handlers: no default config %s",
365 PAM_DEFAULT_SERVICE_FILE);
367 if (!read_something) { /* nothing read successfully */
372 if ((f = fopen(PAM_CONFIG, "r")) == NULL) {
373 pam_system_log(pamh, NULL, LOG_ERR,
374 "_pam_init_handlers: could not open "
379 retval = _pam_parse_conf_file(pamh, f, NULL
380 #ifdef PAM_READ_BOTH_CONFS
382 #endif /* PAM_READ_BOTH_CONFS */
385 D(("closing configuration file"));
390 if (retval != PAM_SUCCESS) {
392 pam_system_log(pamh, NULL, LOG_ERR,
393 "error reading PAM configuration file");
397 pamh->handlers.handlers_loaded = 1;
399 D(("_pam_init_handlers exiting"));
404 * This is where we read a line of the PAM config file. The line may be
405 * preceeded by lines of comments and also extended with "\\\n"
408 int _pam_assemble_line(FILE *f, char *buffer, int buf_len)
414 /* loop broken with a 'break' when a non-'\\n' ended line is read */
418 if (used >= buf_len) {
420 D(("_pam_assemble_line: overflow"));
423 if (fgets(p, buf_len - used, f) == NULL) {
425 /* Incomplete read */
433 /* skip leading spaces --- line may be blank */
435 s = p + strspn(p, " \n\t");
436 if (*s && (*s != '#')) {
440 * we are only interested in characters before the first '#'
444 while (*s && *s != '#')
449 break; /* the line has been read */
455 * Check for backslash by scanning back from the end of
456 * the entered line, the '\n' has been included since
457 * normally a line is terminated with this
458 * character. fgets() should only return one though!
462 while (s > os && ((*--s == ' ') || (*s == '\t')
465 /* check if it ends with a backslash */
467 *s++ = ' '; /* replace backslash with ' ' */
468 *s = '\0'; /* truncate the line here */
470 p = s; /* there is more ... */
472 /* End of the line! */
474 break; /* this is the complete line */
478 /* Nothing in this line */
486 typedef int (*servicefn)(pam_handle_t *, int, int, char **);
488 int _pam_add_handler(pam_handle_t *pamh
489 , int must_fail, int other, int type
490 , int *actions, const char *mod_path
491 , int argc, char **argv, int argvlen)
493 struct loaded_module *mod;
495 struct handler **handler_p;
496 struct handler **handler_p2;
497 struct handlers *the_handlers;
498 const char *sym, *sym2;
500 const char *_sym, *_sym2;
502 char *mod_full_path=NULL;
503 servicefn func, func2;
507 IF_NO_PAMH("_pam_add_handler",pamh,PAM_SYSTEM_ERR);
509 /* if NULL set to something that can be searched for */
510 if (mod_path == NULL) {
511 mod_path = "<*unknown module path*>";
512 } else if (mod_path[0] != '/') {
513 mod_full_path = malloc(sizeof(DEFAULT_MODULE_PATH)+strlen(mod_path));
514 sprintf(mod_full_path, DEFAULT_MODULE_PATH "%s", mod_path);
515 mod_path = mod_full_path;
518 D(("_pam_add_handler: adding type %d, module `%s'",type,mod_path));
519 mod = pamh->handlers.module;
521 /* First, ensure the module is loaded */
522 while (x < pamh->handlers.modules_used) {
523 if (!strcmp(mod[x].name, mod_path)) { /* case sensitive ! */
528 if (x == pamh->handlers.modules_used) {
530 if (pamh->handlers.modules_allocated == pamh->handlers.modules_used) {
531 /* will need more memory */
532 void *tmp = realloc(pamh->handlers.module,
533 (pamh->handlers.modules_allocated+MODULE_CHUNK)
534 *sizeof(struct loaded_module));
536 D(("cannot enlarge module pointer memory"));
537 pam_system_log(pamh, NULL, LOG_ERR,
538 "realloc returned NULL in _pam_add_handler");
539 _pam_drop(mod_full_path);
542 pamh->handlers.module = tmp;
543 pamh->handlers.modules_allocated += MODULE_CHUNK;
545 mod = &(pamh->handlers.module[x]);
546 /* Be pessimistic... */
550 D(("_pam_add_handler: dlopen(%s) -> %lx", mod_path, &mod->dl_handle));
553 shl_load(mod_path, BIND_IMMEDIATE, 0L);
555 dlopen(mod_path, RTLD_NOW);
556 # endif /* PAM_SHL */
557 D(("_pam_add_handler: dlopen'ed"));
558 if (mod->dl_handle == NULL) {
559 D(("_pam_add_handler: dlopen(%s) failed", mod_path));
560 pam_system_log(pamh, NULL, LOG_ERR, "unable to dlopen(%s)",
563 pam_system_log(pamh, NULL, LOG_ERR, "[dlerror: %s]", dlerror());
564 # endif /* PAM_SHL */
565 /* Don't abort yet; static code may be able to find function.
566 * But defaults to abort if nothing found below... */
568 D(("module added successfully"));
569 success = PAM_SUCCESS;
570 mod->type = PAM_MT_DYNAMIC_MOD;
571 pamh->handlers.modules_used++;
575 /* Only load static function if function was not found dynamically.
576 * This code should work even if no dynamic loading is available. */
577 if (success != PAM_SUCCESS) {
578 D(("_pam_add_handler: open static handler %s", mod_path));
579 mod->dl_handle = _pam_open_static_handler(mod_path);
580 if (mod->dl_handle == NULL) {
581 D(("_pam_add_handler: unable to find static handler %s",
583 pam_system_log(pamh, NULL, LOG_ERR,
584 "unable to open static handler %s", mod_path);
585 /* Didn't find module in dynamic or static..will mark bad */
587 D(("static module added successfully"));
588 success = PAM_SUCCESS;
589 mod->type = PAM_MT_STATIC_MOD;
590 pamh->handlers.modules_used++;
595 if (success != PAM_SUCCESS) { /* add a malformed module */
596 mod->dl_handle = NULL;
597 mod->type = PAM_MT_FAULTY_MOD;
598 pamh->handlers.modules_used++;
599 pam_system_log(pamh, NULL, LOG_ERR,
600 "adding faulty module: %s", mod_path);
601 success = PAM_SUCCESS; /* We have successfully added a module */
604 /* indicate its name - later we will search for it by this */
605 if ((mod->name = _pam_strdup(mod_path)) == NULL) {
606 D(("_pam_handler: couldn't get memory for mod_path"));
607 pam_system_log(pamh, NULL, LOG_ERR,
608 "no memory for module path", mod_path);
612 } else { /* x != pamh->handlers.modules_used */
613 mod += x; /* the located module */
614 success = PAM_SUCCESS;
617 _pam_drop(mod_full_path);
618 mod_path = NULL; /* no longer needed or trusted */
620 /* Now return error if necessary after trying all possible ways... */
621 if (success != PAM_SUCCESS)
625 * At this point 'mod' points to the stored/loaded module. If its
626 * dl_handle is unknown, then we must be able to indicate dispatch
627 * failure with 'must_fail'
630 /* Now define the handler(s) based on mod->dlhandle and type */
632 /* decide which list of handlers to use */
633 the_handlers = (other) ? &pamh->handlers.other : &pamh->handlers.conf;
635 handler_p = handler_p2 = NULL;
642 /* point handler_p's at the root addresses of the function stacks */
645 handler_p = &the_handlers->authenticate;
646 sym = SHLIB_SYM_PREFIX "pam_sm_authenticate";
647 handler_p2 = &the_handlers->setcred;
648 sym2 = SHLIB_SYM_PREFIX "pam_sm_setcred";
650 _sym = "_pam_sm_authenticate";
651 _sym2 = "_pam_sm_setcred";
655 handler_p = &the_handlers->open_session;
656 sym = SHLIB_SYM_PREFIX "pam_sm_open_session";
657 handler_p2 = &the_handlers->close_session;
658 sym2 = SHLIB_SYM_PREFIX "pam_sm_close_session";
660 _sym = "_pam_sm_open_session";
661 _sym2 = "_pam_sm_close_session";
665 handler_p = &the_handlers->acct_mgmt;
666 sym = SHLIB_SYM_PREFIX "pam_sm_acct_mgmt";
668 _sym = "_pam_sm_acct_mgmt";
672 handler_p = &the_handlers->chauthtok;
673 sym = SHLIB_SYM_PREFIX "pam_sm_chauthtok";
675 _sym = "_pam_sm_chauthtok";
679 /* Illegal module type */
680 D(("_pam_add_handler: illegal module type %d", type));
684 /* are the modules reliable? */
687 mod->type != PAM_MT_DYNAMIC_MOD
689 #endif /* PAM_DYNAMIC */
691 mod->type != PAM_MT_STATIC_MOD
693 #endif /* PAM_STATIC */
694 mod->type != PAM_MT_FAULTY_MOD
696 D(("_pam_add_handlers: illegal module library type; %d", mod->type));
697 pam_system_log(pamh, NULL, LOG_ERR,
698 "internal error: module library type not known: %s;%d",
703 /* now identify this module's functions - for non-faulty modules */
706 if ((mod->type == PAM_MT_DYNAMIC_MOD) &&
708 (shl_findsym(&mod->dl_handle, sym, (short) TYPE_PROCEDURE, &func) &&
709 shl_findsym(&mod->dl_handle, _sym, (short) TYPE_PROCEDURE, &func))
711 (func = (servicefn) dlsym(mod->dl_handle, sym)) == NULL
712 # endif /* PAM_SHL */
714 pam_system_log(pamh, NULL, LOG_ERR, "unable to resolve symbol: %s",
719 if ((mod->type == PAM_MT_STATIC_MOD) &&
720 (func = (servicefn)_pam_get_static_sym(mod->dl_handle, sym)) == NULL) {
721 pam_system_log(pamh, NULL, LOG_ERR,
722 "unable to resolve static symbol: %s", sym);
727 if ((mod->type == PAM_MT_DYNAMIC_MOD) &&
729 (shl_findsym(&mod->dl_handle,sym2,(short)TYPE_PROCEDURE, &func2)&&
730 shl_findsym(&mod->dl_handle,_sym2,(short)TYPE_PROCEDURE, &func2))
732 (func2 = (servicefn) dlsym(mod->dl_handle, sym2)) == NULL
733 # endif /* PAM_SHL */
735 pam_system_log(pamh, NULL, LOG_ERR, "unable to resolve symbol: %s",
740 if ((mod->type == PAM_MT_STATIC_MOD) &&
741 (func2 = (servicefn)_pam_get_static_sym(mod->dl_handle, sym2))
743 pam_system_log(pamh, NULL, LOG_ERR, "unable to resolve symbol: %s",
749 /* here func (and perhaps func2) point to the appropriate functions */
751 /* add new handler to end of existing list */
752 while (*handler_p != NULL) {
753 handler_p = &((*handler_p)->next);
756 if ((*handler_p = malloc(sizeof(struct handler))) == NULL) {
757 pam_system_log(pamh, NULL, LOG_CRIT,
758 "cannot malloc struct handler #1");
762 (*handler_p)->must_fail = must_fail; /* failure forced? */
763 (*handler_p)->func = func;
764 memcpy((*handler_p)->actions,actions,sizeof((*handler_p)->actions));
765 (*handler_p)->argc = argc;
766 (*handler_p)->argv = argv; /* not a copy */
767 (*handler_p)->next = NULL;
769 /* some of the modules have a second calling function */
771 /* add new handler to end of existing list */
772 while (*handler_p2) {
773 handler_p2 = &((*handler_p2)->next);
776 if ((*handler_p2 = malloc(sizeof(struct handler))) == NULL) {
777 pam_system_log(pamh, NULL, LOG_CRIT,
778 "cannot malloc struct handler #2");
782 (*handler_p2)->must_fail = must_fail; /* failure forced? */
783 (*handler_p2)->func = func2;
784 memcpy((*handler_p2)->actions,actions,sizeof((*handler_p2)->actions));
785 (*handler_p2)->argc = argc;
787 if (((*handler_p2)->argv = malloc(argvlen)) == NULL) {
788 pam_system_log(pamh, NULL, LOG_CRIT,
789 "cannot malloc argv for handler #2");
792 memcpy((*handler_p2)->argv, argv, argvlen);
794 (*handler_p2)->argv = NULL; /* no arguments */
796 (*handler_p2)->next = NULL;
799 D(("_pam_add_handler: returning successfully"));
804 /* Free various allocated structures and dlclose() the libs */
805 int _pam_free_handlers(pam_handle_t *pamh)
807 struct loaded_module *mod;
810 IF_NO_PAMH("_pam_free_handlers",pamh,PAM_SYSTEM_ERR);
812 mod = pamh->handlers.module;
814 /* Close all loaded modules */
816 while (pamh->handlers.modules_used) {
817 D(("_pam_free_handlers: dlclose(%s)", mod->name));
821 if (mod->type == PAM_MT_DYNAMIC_MOD) shl_unload(mod->dl_handle);
823 if (mod->type == PAM_MT_DYNAMIC_MOD) dlclose(mod->dl_handle);
827 pamh->handlers.modules_used--;
830 /* Free all the handlers */
832 _pam_free_handlers_aux(&(pamh->handlers.conf.authenticate));
833 _pam_free_handlers_aux(&(pamh->handlers.conf.setcred));
834 _pam_free_handlers_aux(&(pamh->handlers.conf.acct_mgmt));
835 _pam_free_handlers_aux(&(pamh->handlers.conf.open_session));
836 _pam_free_handlers_aux(&(pamh->handlers.conf.close_session));
837 _pam_free_handlers_aux(&(pamh->handlers.conf.chauthtok));
839 _pam_free_handlers_aux(&(pamh->handlers.other.authenticate));
840 _pam_free_handlers_aux(&(pamh->handlers.other.setcred));
841 _pam_free_handlers_aux(&(pamh->handlers.other.acct_mgmt));
842 _pam_free_handlers_aux(&(pamh->handlers.other.open_session));
843 _pam_free_handlers_aux(&(pamh->handlers.other.close_session));
844 _pam_free_handlers_aux(&(pamh->handlers.other.chauthtok));
846 /* no more loaded modules */
848 _pam_drop(pamh->handlers.module);
850 /* Indicate that handlers are not initialized for this pamh */
852 pamh->handlers.handlers_loaded = 0;
857 void _pam_start_handlers(pam_handle_t *pamh)
860 /* NB. There is no check for a NULL pamh here, since no return
861 * value to communicate the fact! */
863 /* Indicate that handlers are not initialized for this pamh */
864 pamh->handlers.handlers_loaded = 0;
866 pamh->handlers.modules_allocated = 0;
867 pamh->handlers.modules_used = 0;
868 pamh->handlers.module = NULL;
870 /* initialize the .conf and .other entries */
872 pamh->handlers.conf.authenticate = NULL;
873 pamh->handlers.conf.setcred = NULL;
874 pamh->handlers.conf.acct_mgmt = NULL;
875 pamh->handlers.conf.open_session = NULL;
876 pamh->handlers.conf.close_session = NULL;
877 pamh->handlers.conf.chauthtok = NULL;
879 pamh->handlers.other.authenticate = NULL;
880 pamh->handlers.other.setcred = NULL;
881 pamh->handlers.other.acct_mgmt = NULL;
882 pamh->handlers.other.open_session = NULL;
883 pamh->handlers.other.close_session = NULL;
884 pamh->handlers.other.chauthtok = NULL;
887 void _pam_free_handlers_aux(struct handler **hp)
889 struct handler *h = *hp;
890 struct handler *last;
895 _pam_drop(h->argv); /* This is all alocated in a single chunk */
897 memset(last, 0, sizeof(*last));