1 /* pam_end.c */
2
3 /*
4 * $Id$
5 */
6
7 #include "pam_private.h"
8 #include "pam_inline.h"
9
10 #include <stdlib.h>
11
12 int pam_end(pam_handle_t *pamh, int pam_status)
13 {
14 int ret;
15
16 D(("entering pam_end()"));
17
18 IF_NO_PAMH("pam_end", pamh, PAM_SYSTEM_ERR);
19
20 if (__PAM_FROM_MODULE(pamh)) {
21 D(("called from module!?"));
22 return PAM_SYSTEM_ERR;
23 }
24
25 #ifdef HAVE_LIBAUDIT
26 _pam_audit_end(pamh, pam_status);
27 #endif
28
29 /* first liberate the modules (it is not inconcevible that the
30 modules may need to use the service_name etc. to clean up) */
31
32 _pam_free_data(pamh, pam_status);
33
34 /* now drop all modules */
35
36 if ((ret = _pam_free_handlers(pamh)) != PAM_SUCCESS) {
37 return ret; /* error occurred */
38 }
39
40 /* from this point we cannot call the modules any more. Free the remaining
41 memory used by the Linux-PAM interface */
42
43 _pam_drop_env(pamh); /* purge the environment */
44
45 pam_overwrite_string(pamh->authtok); /* blank out old token */
46 _pam_drop(pamh->authtok);
47
48 pam_overwrite_string(pamh->oldauthtok); /* blank out old token */
49 _pam_drop(pamh->oldauthtok);
50
51 pam_overwrite_string(pamh->former.prompt);
52 _pam_drop(pamh->former.prompt); /* drop saved prompt */
53
54 pam_overwrite_string(pamh->service_name);
55 _pam_drop(pamh->service_name);
56
57 pam_overwrite_string(pamh->user);
58 _pam_drop(pamh->user);
59
60 pam_overwrite_string(pamh->confdir);
61 _pam_drop(pamh->confdir);
62
63 pam_overwrite_string(pamh->prompt);
64 _pam_drop(pamh->prompt); /* prompt for pam_get_user() */
65
66 pam_overwrite_string(pamh->tty);
67 _pam_drop(pamh->tty);
68
69 pam_overwrite_string(pamh->rhost);
70 _pam_drop(pamh->rhost);
71
72 pam_overwrite_string(pamh->ruser);
73 _pam_drop(pamh->ruser);
74
75 _pam_drop(pamh->pam_conversation);
76 pamh->fail_delay.delay_fn_ptr = NULL;
77
78 _pam_drop(pamh->former.substates);
79
80 pam_overwrite_string(pamh->xdisplay);
81 _pam_drop(pamh->xdisplay);
82
83 pam_overwrite_string(pamh->xauth.name);
84 _pam_drop(pamh->xauth.name);
85 pam_overwrite_n(pamh->xauth.data, (unsigned int)pamh->xauth.datalen);
86 _pam_drop(pamh->xauth.data);
87 pam_overwrite_object(&pamh->xauth);
88
89 pam_overwrite_string(pamh->authtok_type);
90 _pam_drop(pamh->authtok_type);
91
92 /* and finally liberate the memory for the pam_handle structure */
93
94 _pam_drop(pamh);
95
96 D(("exiting pam_end() successfully"));
97
98 return PAM_SUCCESS;
99 }