#include #include #include #include #include "time_defs.h" #include "utmp_defs.h" #include "prot_defs.h" #ifndef LASTLOG_FILE #define LASTLOG_FILE "/var/log/lastlog" #endif #define SC(A,B) str_copynz(A, B, sizeof(A)) void lastlog_do(char *buf, unsigned int uid, char *line) /*EXTRACT_INCL*/{ int fd = open(LASTLOG_FILE, O_RDWR); struct lastlog ll; off_t offset = uid * sizeof ll; char *p=buf; p[0] = 0; if (fd<0 || lseek(fd, offset, SEEK_SET) != offset) goto do_close; if (read(fd, &ll, sizeof ll) == sizeof ll && ll.ll_time) { p += str_copy(p, "Last login: "); p += nv_ctime(p, ll.ll_time, 24); p += str_copy(p, " on "); p += str_add(p, ll.ll_line, sizeof ll.ll_line); if (ll.ll_host[0]) { p += str_copy(p, " from "); p += str_add(p, ll.ll_host, 40); } *p++ = '\n'; *p = 0; } if (lseek(fd, offset, SEEK_SET) != offset) goto do_close; byte_zero(&ll, sizeof ll); ll.ll_time=time(0); SC(ll.ll_line, line); SAFE_IO(write, fd, &ll, sizeof ll); do_close: close(fd); }