2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
15 #include <security/pam_appl.h>
16 #include <security/pam_modules.h>
19 #include "afs_message.h"
23 pam_sm_open_session(pam_handle_t
* pamh
, int flags
, int argc
,
30 #define REMAINLIFETIME 300
33 pam_sm_close_session(pam_handle_t
* pamh
, int flags
, int argc
,
37 int logmask
= LOG_UPTO(LOG_INFO
);
39 int remainlifetime
= REMAINLIFETIME
;
42 openlog(pam_afs_ident
, LOG_CONS
| LOG_PID
, LOG_AUTH
);
46 * Parse the user options. Log an error for any unknown options.
48 for (i
= 0; i
< argc
; i
++) {
49 if (strcasecmp(argv
[i
], "debug") == 0) {
50 logmask
|= LOG_MASK(LOG_DEBUG
);
51 (void)setlogmask(logmask
);
52 } else if (strcasecmp(argv
[i
], "remain") == 0) {
54 } else if (strcasecmp(argv
[i
], "remainlifetime") == 0) {
57 remainlifetime
= (int)strtol(argv
[i
], NULL
, 10);
58 if (remainlifetime
== 0) {
59 if ((errno
== EINVAL
) || (errno
== ERANGE
)) {
60 remainlifetime
= REMAINLIFETIME
;
61 pam_afs_syslog(LOG_ERR
, PAMAFS_REMAINLIFETIME
, argv
[i
],
68 } else if (strcmp(argv
[i
], "no_unlog") == 0) {
71 pam_afs_syslog(LOG_ERR
, PAMAFS_UNKNOWNOPT
, argv
[i
]);
75 if (logmask
& LOG_MASK(LOG_DEBUG
))
77 "pam_afs_session_close: remain: %d, remainlifetime: %d, no_unlog: %d",
78 remain
, remainlifetime
, no_unlog
);
79 if (remain
&& !no_unlog
) {
82 return (PAM_SESSION_ERR
);
84 #ifdef AFS_LINUX20_ENV
88 for (i
= 0; i
< 64; i
++)
90 sleep(remainlifetime
);
91 ktc_ForgetAllTokens();
92 pam_afs_syslog(LOG_INFO
, PAMAFS_SESSIONCLOSED2
);
95 pam_afs_syslog(LOG_INFO
, PAMAFS_SESSIONCLOSED1
);
99 if (!no_unlog
&& ktc_ForgetAllTokens())
100 return PAM_SESSION_ERR
;
101 if (logmask
& LOG_MASK(LOG_DEBUG
))
102 syslog(LOG_DEBUG
, "pam_afs_session_close: Session closed");