|
Lines 42-47
Link Here
|
| 42 |
RCSID("$OpenBSD: sshlogin.c,v 1.8 2004/06/21 17:36:31 avsm Exp $"); |
42 |
RCSID("$OpenBSD: sshlogin.c,v 1.8 2004/06/21 17:36:31 avsm Exp $"); |
| 43 |
|
43 |
|
| 44 |
#include "loginrec.h" |
44 |
#include "loginrec.h" |
|
|
45 |
#include "log.h" |
| 46 |
#include "buffer.h" |
| 47 |
#include "servconf.h" |
| 48 |
|
| 49 |
extern Buffer loginmsg; |
| 50 |
extern ServerOptions options; |
| 45 |
|
51 |
|
| 46 |
/* |
52 |
/* |
| 47 |
* Returns the time when the user last logged in. Returns 0 if the |
53 |
* Returns the time when the user last logged in. Returns 0 if the |
|
Lines 60-65
get_last_login_time(uid_t uid, const cha
Link Here
|
| 60 |
} |
66 |
} |
| 61 |
|
67 |
|
| 62 |
/* |
68 |
/* |
|
|
69 |
* Generate and store last login message. This must be done before |
| 70 |
* login_login() is called and lastlog is updated. |
| 71 |
*/ |
| 72 |
void |
| 73 |
store_lastlog_message(const char *user, uid_t uid) |
| 74 |
{ |
| 75 |
char *time_string, hostname[MAXHOSTNAMELEN] = "", buf[512]; |
| 76 |
time_t last_login_time; |
| 77 |
|
| 78 |
#ifndef NO_SSH_LASTLOG |
| 79 |
if (!options.print_lastlog) |
| 80 |
return; |
| 81 |
|
| 82 |
last_login_time = get_last_login_time(uid, user, hostname, |
| 83 |
sizeof(hostname)); |
| 84 |
|
| 85 |
if (last_login_time != 0) { |
| 86 |
time_string = ctime(&last_login_time); |
| 87 |
if (strchr(time_string, '\n')) |
| 88 |
*strchr(time_string, '\n') = 0; |
| 89 |
if (strcmp(hostname, "") == 0) |
| 90 |
snprintf(buf, sizeof(buf), "Last login: %s\r\n", |
| 91 |
time_string); |
| 92 |
else |
| 93 |
snprintf(buf, sizeof(buf), "Last login: %s from %s\r\n", |
| 94 |
time_string, hostname); |
| 95 |
buffer_append(&loginmsg, buf, strlen(buf)); |
| 96 |
} |
| 97 |
#endif /* NO_SSH_LASTLOG */ |
| 98 |
} |
| 99 |
|
| 100 |
/* |
| 63 |
* Records that the user has logged in. I wish these parts of operating |
101 |
* Records that the user has logged in. I wish these parts of operating |
| 64 |
* systems were more standardized. |
102 |
* systems were more standardized. |
| 65 |
*/ |
103 |
*/ |
|
Lines 68-73
record_login(pid_t pid, const char *tty,
Link Here
|
| 68 |
const char *host, struct sockaddr * addr, socklen_t addrlen) |
106 |
const char *host, struct sockaddr * addr, socklen_t addrlen) |
| 69 |
{ |
107 |
{ |
| 70 |
struct logininfo *li; |
108 |
struct logininfo *li; |
|
|
109 |
|
| 110 |
/* save previous login details before writing new */ |
| 111 |
store_lastlog_message(user, uid); |
| 71 |
|
112 |
|
| 72 |
li = login_alloc_entry(pid, user, host, tty); |
113 |
li = login_alloc_entry(pid, user, host, tty); |
| 73 |
login_set_addr(li, addr, addrlen); |
114 |
login_set_addr(li, addr, addrlen); |