From b1d9b2322daa439194aaa53037fe27a0ccc0596b Mon Sep 17 00:00:00 2001 From: Thorsten Kukuk Date: Tue, 20 Dec 2005 21:28:06 +0000 Subject: Relevant BUGIDs: Purpose of commit: new feature Commit summary: --------------- 2005-12-20 Thorsten Kukuk * modules/pam_lastlog/pam_lastlog.c (last_login_read): Use strftime instead of ctime. --- modules/pam_lastlog/pam_lastlog.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 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 947d3c2d..24a13ef6 100644 --- a/modules/pam_lastlog/pam_lastlog.c +++ b/modules/pam_lastlog/pam_lastlog.c @@ -139,6 +139,7 @@ last_login_read(pam_handle_t *pamh, int announce, int last_fd, uid_t uid) struct flock last_lock; struct lastlog last_login; int retval = PAM_SUCCESS; + char the_time[256]; char *date = NULL; char *host = NULL; char *line = NULL; @@ -176,18 +177,15 @@ last_login_read(pam_handle_t *pamh, int announce, int last_fd, uid_t uid) /* we want the date? */ if (announce & LASTLOG_DATE) { + struct tm *tm, tm_buf; time_t ll_time; - char *the_time; ll_time = last_login.ll_time; - the_time = ctime(&ll_time); - the_time[strlen(the_time)-1] = '\0'; /* strip trailing '\n' */ + tm = localtime_r (&ll_time, &tm_buf); + strftime (the_time, sizeof (the_time), + " %a %b %e %H:%M:%S %Z %Y", tm); - if (asprintf(&date, " %s", the_time) < 0) { - pam_syslog(pamh, LOG_ERR, "out of memory"); - retval = PAM_BUF_ERR; - goto cleanup; - } + date = the_time; } /* we want & have the host? */ @@ -229,7 +227,6 @@ last_login_read(pam_handle_t *pamh, int announce, int last_fd, uid_t uid) cleanup: memset(&last_login, 0, sizeof(last_login)); _pam_overwrite(date); - _pam_drop(date); _pam_overwrite(host); _pam_drop(host); _pam_overwrite(line); -- cgit v1.2.3