diff options
author | markus@openbsd.org <markus@openbsd.org> | 2018-07-09 21:26:02 +0000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2018-07-10 15:21:58 +1000 |
commit | 2808d18ca47ad3d251836c555f0e22aaca03d15c (patch) | |
tree | 06bc9605dd843d77ee25187637e348369e59cb1d /sshlogin.c | |
parent | 89dd615b8b531979be63f05f9d5624367c9b28e6 (diff) |
upstream: sshd: switch loginmsg to sshbuf API; ok djm@
OpenBSD-Commit-ID: f3cb4e54bff15c593602d95cc43e32ee1a4bac42
Diffstat (limited to 'sshlogin.c')
-rw-r--r-- | sshlogin.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/sshlogin.c b/sshlogin.c index cea3e7697..1b2ee5f85 100644 --- a/sshlogin.c +++ b/sshlogin.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: sshlogin.c,v 1.32 2015/12/26 20:51:35 guenther Exp $ */ | 1 | /* $OpenBSD: sshlogin.c,v 1.33 2018/07/09 21:26:02 markus Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -55,13 +55,15 @@ | |||
55 | #include <unistd.h> | 55 | #include <unistd.h> |
56 | #include <limits.h> | 56 | #include <limits.h> |
57 | 57 | ||
58 | #include "sshlogin.h" | ||
59 | #include "ssherr.h" | ||
58 | #include "loginrec.h" | 60 | #include "loginrec.h" |
59 | #include "log.h" | 61 | #include "log.h" |
60 | #include "buffer.h" | 62 | #include "sshbuf.h" |
61 | #include "misc.h" | 63 | #include "misc.h" |
62 | #include "servconf.h" | 64 | #include "servconf.h" |
63 | 65 | ||
64 | extern Buffer loginmsg; | 66 | extern struct sshbuf *loginmsg; |
65 | extern ServerOptions options; | 67 | extern ServerOptions options; |
66 | 68 | ||
67 | /* | 69 | /* |
@@ -88,8 +90,9 @@ static void | |||
88 | store_lastlog_message(const char *user, uid_t uid) | 90 | store_lastlog_message(const char *user, uid_t uid) |
89 | { | 91 | { |
90 | #ifndef NO_SSH_LASTLOG | 92 | #ifndef NO_SSH_LASTLOG |
91 | char *time_string, hostname[HOST_NAME_MAX+1] = "", buf[512]; | 93 | char *time_string, hostname[HOST_NAME_MAX+1] = ""; |
92 | time_t last_login_time; | 94 | time_t last_login_time; |
95 | int r; | ||
93 | 96 | ||
94 | if (!options.print_lastlog) | 97 | if (!options.print_lastlog) |
95 | return; | 98 | return; |
@@ -97,7 +100,9 @@ store_lastlog_message(const char *user, uid_t uid) | |||
97 | # ifdef CUSTOM_SYS_AUTH_GET_LASTLOGIN_MSG | 100 | # ifdef CUSTOM_SYS_AUTH_GET_LASTLOGIN_MSG |
98 | time_string = sys_auth_get_lastlogin_msg(user, uid); | 101 | time_string = sys_auth_get_lastlogin_msg(user, uid); |
99 | if (time_string != NULL) { | 102 | if (time_string != NULL) { |
100 | buffer_append(&loginmsg, time_string, strlen(time_string)); | 103 | if ((r = sshbuf_put(loginmsg, |
104 | time_string, strlen(time_string))) != 0) | ||
105 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); | ||
101 | free(time_string); | 106 | free(time_string); |
102 | } | 107 | } |
103 | # else | 108 | # else |
@@ -108,12 +113,13 @@ store_lastlog_message(const char *user, uid_t uid) | |||
108 | time_string = ctime(&last_login_time); | 113 | time_string = ctime(&last_login_time); |
109 | time_string[strcspn(time_string, "\n")] = '\0'; | 114 | time_string[strcspn(time_string, "\n")] = '\0'; |
110 | if (strcmp(hostname, "") == 0) | 115 | if (strcmp(hostname, "") == 0) |
111 | snprintf(buf, sizeof(buf), "Last login: %s\r\n", | 116 | r = sshbuf_putf(loginmsg, "Last login: %s\r\n", |
112 | time_string); | 117 | time_string); |
113 | else | 118 | else |
114 | snprintf(buf, sizeof(buf), "Last login: %s from %s\r\n", | 119 | r = sshbuf_putf(loginmsg, "Last login: %s from %s\r\n", |
115 | time_string, hostname); | 120 | time_string, hostname); |
116 | buffer_append(&loginmsg, buf, strlen(buf)); | 121 | if (r != 0) |
122 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); | ||
117 | } | 123 | } |
118 | # endif /* CUSTOM_SYS_AUTH_GET_LASTLOGIN_MSG */ | 124 | # endif /* CUSTOM_SYS_AUTH_GET_LASTLOGIN_MSG */ |
119 | #endif /* NO_SSH_LASTLOG */ | 125 | #endif /* NO_SSH_LASTLOG */ |