version 1.66, 2015/12/09 19:26:26 |
version 1.67, 2015/12/26 20:51:35 |
|
|
dolastlog(int quiet) |
dolastlog(int quiet) |
{ |
{ |
struct lastlog ll; |
struct lastlog ll; |
|
off_t pos; |
int fd; |
int fd; |
|
|
if ((fd = open(_PATH_LASTLOG, O_RDWR, 0)) >= 0) { |
if ((fd = open(_PATH_LASTLOG, O_RDWR, 0)) >= 0) { |
(void)lseek(fd, (off_t)pwd->pw_uid * sizeof(ll), SEEK_SET); |
pos = (off_t)pwd->pw_uid * sizeof(ll); |
if (!quiet) { |
if (!quiet) { |
if (read(fd, (char *)&ll, sizeof(ll)) == sizeof(ll) && |
if (pread(fd, &ll, sizeof(ll), pos) == sizeof(ll) && |
ll.ll_time != 0) { |
ll.ll_time != 0) { |
(void)printf("Last login: %.*s ", |
(void)printf("Last login: %.*s ", |
24-5, (char *)ctime(&ll.ll_time)); |
24-5, (char *)ctime(&ll.ll_time)); |
|
|
ll.ll_host); |
ll.ll_host); |
(void)putchar('\n'); |
(void)putchar('\n'); |
} |
} |
(void)lseek(fd, (off_t)pwd->pw_uid * sizeof(ll), |
|
SEEK_SET); |
|
} |
} |
memset((void *)&ll, 0, sizeof(ll)); |
memset(&ll, 0, sizeof(ll)); |
(void)time(&ll.ll_time); |
(void)time(&ll.ll_time); |
(void)strncpy(ll.ll_line, tty, sizeof(ll.ll_line)); |
(void)strncpy(ll.ll_line, tty, sizeof(ll.ll_line)); |
if (hostname) |
if (hostname) |
(void)strncpy(ll.ll_host, hostname, sizeof(ll.ll_host)); |
(void)strncpy(ll.ll_host, hostname, sizeof(ll.ll_host)); |
(void)write(fd, (char *)&ll, sizeof(ll)); |
(void)pwrite(fd, &ll, sizeof(ll), pos); |
(void)close(fd); |
(void)close(fd); |
} |
} |
} |
} |