From 4f552174b48efdde7d47e090ebc6203657adc19b Mon Sep 17 00:00:00 2001 From: Thorsten Kukuk Date: Thu, 24 Aug 2006 18:01:22 +0000 Subject: Relevant BUGIDs: Purpose of commit: bugfix Commit summary: --------------- 2006-08-24 Thorsten Kukuk * release version 0.99.6.2 * modules/pam_lastlog/pam_lastlog.c (last_login_date): Create lastlog file if it does not exist. --- modules/pam_lastlog/pam_lastlog.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'modules/pam_lastlog/pam_lastlog.c') diff --git a/modules/pam_lastlog/pam_lastlog.c b/modules/pam_lastlog/pam_lastlog.c index f470166f..a26b7c2e 100644 --- a/modules/pam_lastlog/pam_lastlog.c +++ b/modules/pam_lastlog/pam_lastlog.c @@ -12,6 +12,7 @@ #include #include +#include #ifdef HAVE_UTMP_H # include #else @@ -327,9 +328,23 @@ last_login_date(pam_handle_t *pamh, int announce, uid_t uid, const char *user) /* obtain the last login date and all the relevant info */ last_fd = open(_PATH_LASTLOG, O_RDWR); if (last_fd < 0) { - pam_syslog(pamh, LOG_ERR, "unable to open %s: %m", _PATH_LASTLOG); - D(("unable to open %s file", _PATH_LASTLOG)); - return PAM_SERVICE_ERR; + if (errno == ENOENT) { + last_fd = open(_PATH_LASTLOG, O_RDWR|O_CREAT, + S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); + if (last_fd < 0) { + pam_syslog(pamh, LOG_ERR, + "unable to create %s: %m", _PATH_LASTLOG); + D(("unable to create %s file", _PATH_LASTLOG)); + return PAM_SERVICE_ERR; + } + pam_syslog(pamh, LOG_WARN, + "file %s created", _PATH_LASTLOG); + D(("file %s created", _PATH_LASTLOG)); + } else { + pam_syslog(pamh, LOG_ERR, "unable to open %s: %m", _PATH_LASTLOG); + D(("unable to open %s file", _PATH_LASTLOG)); + return PAM_SERVICE_ERR; + } } if (lseek(last_fd, sizeof(struct lastlog) * (off_t) uid, SEEK_SET) < 0) { -- cgit v1.2.3