4 * Copyright Alexander O. Yuriev, 1996. All rights reserved.
5 * Copyright Jan Rêkorajski, 1999. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, and the entire permission notice in its entirety,
12 * including the disclaimer of warranties.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote
17 * products derived from this software without specific prior
20 * ALTERNATIVELY, this product may be distributed under the terms of
21 * the GNU Public License, in which case the provisions of the GPL are
22 * required INSTEAD OF the above restrictions. (This clause is
23 * necessary due to a potential bad interaction between the GPL and
24 * the restrictions contained in a BSD-style copyright.)
26 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
30 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
36 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 #include <sys/types.h>
50 /* indicate the following groups are defined */
52 #define PAM_SM_SESSION
54 #include <security/_pam_macros.h>
55 #include <security/pam_modules.h>
56 #include <security/pam_ext.h>
57 #include <security/pam_modutil.h>
62 * PAM framework looks for these entry-points to pass control to the
66 PAM_EXTERN int pam_sm_open_session(pam_handle_t * pamh, int flags,
67 int argc, const char **argv)
69 char *user_name, *service;
72 const char *login_name;
76 ctrl = _set_ctrl(pamh, flags, NULL, NULL, argc, argv);
78 retval = pam_get_item(pamh, PAM_USER, (void *) &user_name);
79 if (user_name == NULL || *user_name == '\0' || retval != PAM_SUCCESS) {
80 pam_syslog(pamh, LOG_CRIT,
81 "open_session - error recovering username");
82 return PAM_SESSION_ERR; /* How did we get authenticated with
85 retval = pam_get_item(pamh, PAM_SERVICE, (void *) &service);
86 if (service == NULL || *service == '\0' || retval != PAM_SUCCESS) {
87 pam_syslog(pamh, LOG_CRIT,
88 "open_session - error recovering service");
89 return PAM_SESSION_ERR;
91 login_name = pam_modutil_getlogin(pamh);
92 if (login_name == NULL) {
95 pam_syslog(pamh, LOG_INFO, "session opened for user %s by %s(uid=%lu)",
96 user_name, login_name, (unsigned long)getuid());
101 PAM_EXTERN int pam_sm_close_session(pam_handle_t * pamh, int flags,
102 int argc, const char **argv)
104 char *user_name, *service;
110 ctrl = _set_ctrl(pamh, flags, NULL, NULL, argc, argv);
112 retval = pam_get_item(pamh, PAM_USER, (void *) &user_name);
113 if (user_name == NULL || *user_name == '\0' || retval != PAM_SUCCESS) {
114 pam_syslog(pamh, LOG_CRIT,
115 "close_session - error recovering username");
116 return PAM_SESSION_ERR; /* How did we get authenticated with
119 retval = pam_get_item(pamh, PAM_SERVICE, (void *) &service);
120 if (service == NULL || *service == '\0' || retval != PAM_SUCCESS) {
121 pam_syslog(pamh, LOG_CRIT,
122 "close_session - error recovering service");
123 return PAM_SESSION_ERR;
125 pam_syslog(pamh, LOG_INFO, "session closed for user %s",
131 /* static module data */
133 struct pam_module _pam_unix_session_modstruct = {
139 pam_sm_close_session,