aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/libpam/modules/pam_lastlog/pam_lastlog.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/lib/libpam/modules/pam_lastlog/pam_lastlog.c b/lib/libpam/modules/pam_lastlog/pam_lastlog.c
index 519d4520b812..817d1f3ba793 100644
--- a/lib/libpam/modules/pam_lastlog/pam_lastlog.c
+++ b/lib/libpam/modules/pam_lastlog/pam_lastlog.c
@@ -87,12 +87,17 @@ pam_sm_open_session(pam_handle_t *pamh, int flags,
PAM_LOG("Got user: %s", user);
pam_err = pam_get_item(pamh, PAM_RHOST, &rhost);
- if (pam_err != PAM_SUCCESS)
+ if (pam_err != PAM_SUCCESS) {
+ PAM_LOG("No PAM_RHOST");
goto err;
+ }
pam_err = pam_get_item(pamh, PAM_TTY, &tty);
- if (pam_err != PAM_SUCCESS)
+ if (pam_err != PAM_SUCCESS) {
+ PAM_LOG("No PAM_TTY");
goto err;
+ }
if (tty == NULL) {
+ PAM_LOG("No PAM_TTY");
pam_err = PAM_SERVICE_ERR;
goto err;
}
@@ -102,8 +107,10 @@ pam_sm_open_session(pam_handle_t *pamh, int flags,
return (PAM_SERVICE_ERR);
fd = open(_PATH_LASTLOG, O_RDWR|O_CREAT, 0644);
- if (fd == -1)
+ if (fd == -1) {
+ PAM_LOG("Failed to open %s", _PATH_LASTLOG);
goto file_err;
+ }
/*
* Record session in lastlog(5).
@@ -170,18 +177,26 @@ PAM_EXTERN int
pam_sm_close_session(pam_handle_t *pamh __unused, int flags __unused,
int argc __unused, const char *argv[] __unused)
{
- const void *tty;
+ const void *tty;
+ int pam_err;
- pam_get_item(pamh, PAM_TTY, (const void **)&tty);
+ pam_err = pam_get_item(pamh, PAM_TTY, (const void **)&tty);
+ if (pam_err != PAM_SUCCESS)
+ goto err;
if (strncmp(tty, _PATH_DEV, strlen(_PATH_DEV)) == 0)
tty = (const char *)tty + strlen(_PATH_DEV);
if (*(const char *)tty == '\0')
return (PAM_SERVICE_ERR);
- if (logout(tty) != 1)
- syslog(LOG_ERR, "%s(): no utmp record for %s",
+ if (logout(tty) != 1)
+ syslog(LOG_ERR, "%s(): no utmp record for %s",
__func__, (const char *)tty);
- logwtmp(tty, "", "");
- return (PAM_SUCCESS);
+ logwtmp(tty, "", "");
+ return (PAM_SUCCESS);
+
+ err:
+ if (openpam_get_option(pamh, "no_fail"))
+ return (PAM_SUCCESS);
+ return (pam_err);
}
PAM_MODULE_ENTRY("pam_lastlog");