-/* $OpenBSD: auth-passwd.c,v 1.46 2018/03/03 03:15:51 djm Exp $ */
+/* $OpenBSD: auth-passwd.c,v 1.47 2018/07/09 21:26:02 markus Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
#include <stdarg.h>
#include "packet.h"
-#include "buffer.h"
+#include "sshbuf.h"
+#include "ssherr.h"
#include "log.h"
#include "misc.h"
#include "servconf.h"
-#include "key.h"
+#include "sshkey.h"
#include "hostfile.h"
#include "auth.h"
#include "auth-options.h"
-extern Buffer loginmsg;
+extern struct sshbuf *loginmsg;
extern ServerOptions options;
int sys_auth_passwd(struct ssh *, const char *);
static void
warn_expiry(Authctxt *authctxt, auth_session_t *as)
{
- char buf[256];
+ int r;
quad_t pwtimeleft, actimeleft, daysleft, pwwarntime, acwarntime;
pwwarntime = acwarntime = TWO_WEEKS;
}
if (pwtimeleft != 0 && pwtimeleft < pwwarntime) {
daysleft = pwtimeleft / DAY + 1;
- snprintf(buf, sizeof(buf),
+ if ((r = sshbuf_putf(loginmsg,
"Your password will expire in %lld day%s.\n",
- daysleft, daysleft == 1 ? "" : "s");
- buffer_append(&loginmsg, buf, strlen(buf));
+ daysleft, daysleft == 1 ? "" : "s")) != 0)
+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
}
if (actimeleft != 0 && actimeleft < acwarntime) {
daysleft = actimeleft / DAY + 1;
- snprintf(buf, sizeof(buf),
+ if ((r = sshbuf_putf(loginmsg,
"Your account will expire in %lld day%s.\n",
- daysleft, daysleft == 1 ? "" : "s");
- buffer_append(&loginmsg, buf, strlen(buf));
+ daysleft, daysleft == 1 ? "" : "s")) != 0)
+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
}
}
-/* $OpenBSD: monitor.c,v 1.180 2018/03/03 03:15:51 djm Exp $ */
+/* $OpenBSD: monitor.c,v 1.181 2018/07/09 21:26:02 markus Exp $ */
/*
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
* Copyright 2002 Markus Friedl <markus@openbsd.org>
extern u_char session_id[];
extern Buffer auth_debug;
extern int auth_debug_init;
-extern Buffer loginmsg;
+extern struct sshbuf *loginmsg;
extern struct sshauthopt *auth_opts; /* XXX move to permanent ssh->authctxt? */
/* State exported from the child */
close(0);
/* send messages generated by record_login */
- buffer_put_string(m, buffer_ptr(&loginmsg), buffer_len(&loginmsg));
- buffer_clear(&loginmsg);
+ buffer_put_string(m, buffer_ptr(loginmsg), buffer_len(loginmsg));
+ buffer_clear(loginmsg);
mm_request_send(sock, MONITOR_ANS_PTY, m);
-/* $OpenBSD: monitor_wrap.c,v 1.101 2018/07/09 13:37:10 sf Exp $ */
+/* $OpenBSD: monitor_wrap.c,v 1.102 2018/07/09 21:26:02 markus Exp $ */
/*
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
* Copyright 2002 Markus Friedl <markus@openbsd.org>
extern z_stream incoming_stream;
extern z_stream outgoing_stream;
extern struct monitor *pmonitor;
-extern Buffer loginmsg;
+extern struct sshbuf *loginmsg;
extern ServerOptions options;
void
{
Buffer m;
char *p, *msg;
- int success = 0, tmp1 = -1, tmp2 = -1;
+ int success = 0, tmp1 = -1, tmp2 = -1, r;
/* Kludge: ensure there are fds free to receive the pty/tty */
if ((tmp1 = dup(pmonitor->m_recvfd)) == -1 ||
strlcpy(namebuf, p, namebuflen); /* Possible truncation */
free(p);
- buffer_append(&loginmsg, msg, strlen(msg));
+ if ((r = sshbuf_put(loginmsg, msg, strlen(msg))) != 0)
+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
free(msg);
if ((*ptyfd = mm_receive_fd(pmonitor->m_recvfd)) == -1 ||
-/* $OpenBSD: servconf.h,v 1.135 2018/07/03 10:59:35 djm Exp $ */
+/* $OpenBSD: servconf.h,v 1.136 2018/07/09 21:26:02 markus Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
int process_server_config_line(ServerOptions *, char *, const char *, int,
int *, struct connection_info *);
void process_permitopen(struct ssh *ssh, ServerOptions *options);
-void load_server_config(const char *, Buffer *);
-void parse_server_config(ServerOptions *, const char *, Buffer *,
+void load_server_config(const char *, struct sshbuf *);
+void parse_server_config(ServerOptions *, const char *, struct sshbuf *,
struct connection_info *);
void parse_server_match_config(ServerOptions *, struct connection_info *);
int parse_server_match_testspec(struct connection_info *, char *);
-/* $OpenBSD: session.c,v 1.302 2018/07/09 21:20:26 markus Exp $ */
+/* $OpenBSD: session.c,v 1.303 2018/07/09 21:26:02 markus Exp $ */
/*
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
* All rights reserved
#include "ssh2.h"
#include "sshpty.h"
#include "packet.h"
-#include "buffer.h"
+#include "sshbuf.h"
+#include "ssherr.h"
#include "match.h"
#include "uidswap.h"
#include "compat.h"
extern u_int utmp_len;
extern int startup_pipe;
extern void destroy_sensitive_data(void);
-extern Buffer loginmsg;
+extern struct sshbuf *loginmsg;
extern struct sshauthopt *auth_opts;
char *tun_fwd_ifnames; /* serverloop.c */
static void
display_loginmsg(void)
{
- if (buffer_len(&loginmsg) > 0) {
- buffer_append(&loginmsg, "\0", 1);
- printf("%s", (char *)buffer_ptr(&loginmsg));
- buffer_clear(&loginmsg);
- }
+ int r;
+
+ if (sshbuf_len(loginmsg) == 0)
+ return;
+ if ((r = sshbuf_put_u8(loginmsg, 0)) != 0)
+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
+ printf("%s", (char *)sshbuf_ptr(loginmsg));
+ sshbuf_reset(loginmsg);
}
static void
* it to the user, otherwise multiple sessions may accumulate
* multiple copies of the login messages.
*/
- buffer_clear(&loginmsg);
+ sshbuf_reset(loginmsg);
return ret;
}
-/* $OpenBSD: sshd.c,v 1.509 2018/07/03 11:39:54 djm Exp $ */
+/* $OpenBSD: sshd.c,v 1.510 2018/07/09 21:26:02 markus Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
Buffer cfg;
/* message to be displayed after login */
-Buffer loginmsg;
+struct sshbuf *loginmsg;
/* Prototypes for various functions defined later in this file. */
void destroy_sensitive_data(void);
fatal("fork of unprivileged child failed");
else if (pmonitor->m_pid != 0) {
verbose("User child is on pid %ld", (long)pmonitor->m_pid);
- buffer_clear(&loginmsg);
+ sshbuf_reset(loginmsg);
monitor_clear_keystate(pmonitor);
monitor_child_postauth(pmonitor);
fatal("allocation failed");
/* prepare buffer to collect messages to display to user after login */
- buffer_init(&loginmsg);
+ if ((loginmsg = sshbuf_new()) == NULL)
+ fatal("%s: sshbuf_new failed", __func__);
auth_debug_reset();
if (use_privsep) {
-/* $OpenBSD: sshlogin.c,v 1.32 2015/12/26 20:51:35 guenther Exp $ */
+/* $OpenBSD: sshlogin.c,v 1.33 2018/07/09 21:26:02 markus Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
#include <limits.h>
#include "sshlogin.h"
+#include "ssherr.h"
#include "log.h"
-#include "buffer.h"
+#include "sshbuf.h"
#include "misc.h"
#include "servconf.h"
-extern Buffer loginmsg;
+extern struct sshbuf *loginmsg;
extern ServerOptions options;
/*
static void
store_lastlog_message(const char *user, uid_t uid)
{
- char *time_string, hostname[HOST_NAME_MAX+1] = "", buf[512];
+ char *time_string, hostname[HOST_NAME_MAX+1] = "";
time_t last_login_time;
+ int r;
if (!options.print_lastlog)
return;
time_string = ctime(&last_login_time);
time_string[strcspn(time_string, "\n")] = '\0';
if (strcmp(hostname, "") == 0)
- snprintf(buf, sizeof(buf), "Last login: %s\r\n",
+ r = sshbuf_putf(loginmsg, "Last login: %s\r\n",
time_string);
else
- snprintf(buf, sizeof(buf), "Last login: %s from %s\r\n",
+ r = sshbuf_putf(loginmsg, "Last login: %s from %s\r\n",
time_string, hostname);
- buffer_append(&loginmsg, buf, strlen(buf));
+ if (r != 0)
+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
}
}