diff options
Diffstat (limited to '')
-rw-r--r-- | lib/log.c (renamed from libmisc/log.c) | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/libmisc/log.c b/lib/log.c index a220be0..9f54d45 100644 --- a/libmisc/log.c +++ b/lib/log.c @@ -17,14 +17,18 @@ #include <time.h> #include "defines.h" #include <lastlog.h> +#include "memzero.h" #include "prototypes.h" +#include "string/strncpy.h" +#include "string/strtcpy.h" + /* * dolastlog - create lastlog entry * * A "last login" entry is created for the user being logged in. The * UID is extracted from the global (struct passwd) entry and the - * TTY information is gotten from the (struct utmp). + * TTY information is gotten from the (struct utmpx). */ void dolastlog ( struct lastlog *ll, @@ -67,7 +71,7 @@ void dolastlog ( * the way we read the old one in. */ - if (read (fd, (void *) &newlog, sizeof newlog) != (ssize_t) sizeof newlog) { + if (read (fd, &newlog, sizeof newlog) != (ssize_t) sizeof newlog) { memzero (&newlog, sizeof newlog); } if (NULL != ll) { @@ -77,17 +81,29 @@ void dolastlog ( ll_time = newlog.ll_time; (void) time (&ll_time); newlog.ll_time = ll_time; - strncpy (newlog.ll_line, line, sizeof (newlog.ll_line) - 1); + STRTCPY(newlog.ll_line, line); #if HAVE_LL_HOST - strncpy (newlog.ll_host, host, sizeof (newlog.ll_host) - 1); + STRNCPY(newlog.ll_host, host); #endif if ( (lseek (fd, offset, SEEK_SET) != offset) - || (write (fd, (const void *) &newlog, sizeof newlog) != (ssize_t) sizeof newlog) - || (close (fd) != 0)) { - SYSLOG ((LOG_WARN, - "Can't write lastlog entry for UID %lu in %s.", - (unsigned long) pw->pw_uid, LASTLOG_FILE)); + || (write_full(fd, &newlog, sizeof newlog) == -1)) { + goto err_write; + } + + if (close (fd) != 0 && errno != EINTR) { + goto err_close; + } + + return; + +err_write: + { + int saved_errno = errno; (void) close (fd); + errno = saved_errno; } +err_close: + SYSLOG ((LOG_WARN, + "Can't write lastlog entry for UID %lu in %s: %m", + (unsigned long) pw->pw_uid, LASTLOG_FILE)); } - |