mirror of
https://github.com/PowerShell/openssh-portable.git
synced 2025-07-28 08:14:24 +02:00
upstream: sshd: switch loginmsg to sshbuf API; ok djm@
OpenBSD-Commit-ID: f3cb4e54bff15c593602d95cc43e32ee1a4bac42
This commit is contained in:
parent
89dd615b8b
commit
2808d18ca4
@ -1,4 +1,4 @@
|
|||||||
/* $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>
|
* Author: Tatu Ylonen <ylo@cs.hut.fi>
|
||||||
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
|
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
|
||||||
@ -46,16 +46,17 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#include "packet.h"
|
#include "packet.h"
|
||||||
#include "buffer.h"
|
#include "sshbuf.h"
|
||||||
|
#include "ssherr.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "servconf.h"
|
#include "servconf.h"
|
||||||
#include "key.h"
|
#include "sshkey.h"
|
||||||
#include "hostfile.h"
|
#include "hostfile.h"
|
||||||
#include "auth.h"
|
#include "auth.h"
|
||||||
#include "auth-options.h"
|
#include "auth-options.h"
|
||||||
|
|
||||||
extern Buffer loginmsg;
|
extern struct sshbuf *loginmsg;
|
||||||
extern ServerOptions options;
|
extern ServerOptions options;
|
||||||
|
|
||||||
#ifdef HAVE_LOGIN_CAP
|
#ifdef HAVE_LOGIN_CAP
|
||||||
@ -131,7 +132,7 @@ auth_password(struct ssh *ssh, const char *password)
|
|||||||
static void
|
static void
|
||||||
warn_expiry(Authctxt *authctxt, auth_session_t *as)
|
warn_expiry(Authctxt *authctxt, auth_session_t *as)
|
||||||
{
|
{
|
||||||
char buf[256];
|
int r;
|
||||||
quad_t pwtimeleft, actimeleft, daysleft, pwwarntime, acwarntime;
|
quad_t pwtimeleft, actimeleft, daysleft, pwwarntime, acwarntime;
|
||||||
|
|
||||||
pwwarntime = acwarntime = TWO_WEEKS;
|
pwwarntime = acwarntime = TWO_WEEKS;
|
||||||
@ -148,17 +149,17 @@ warn_expiry(Authctxt *authctxt, auth_session_t *as)
|
|||||||
#endif
|
#endif
|
||||||
if (pwtimeleft != 0 && pwtimeleft < pwwarntime) {
|
if (pwtimeleft != 0 && pwtimeleft < pwwarntime) {
|
||||||
daysleft = pwtimeleft / DAY + 1;
|
daysleft = pwtimeleft / DAY + 1;
|
||||||
snprintf(buf, sizeof(buf),
|
if ((r = sshbuf_putf(loginmsg,
|
||||||
"Your password will expire in %lld day%s.\n",
|
"Your password will expire in %lld day%s.\n",
|
||||||
daysleft, daysleft == 1 ? "" : "s");
|
daysleft, daysleft == 1 ? "" : "s")) != 0)
|
||||||
buffer_append(&loginmsg, buf, strlen(buf));
|
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
||||||
}
|
}
|
||||||
if (actimeleft != 0 && actimeleft < acwarntime) {
|
if (actimeleft != 0 && actimeleft < acwarntime) {
|
||||||
daysleft = actimeleft / DAY + 1;
|
daysleft = actimeleft / DAY + 1;
|
||||||
snprintf(buf, sizeof(buf),
|
if ((r = sshbuf_putf(loginmsg,
|
||||||
"Your account will expire in %lld day%s.\n",
|
"Your account will expire in %lld day%s.\n",
|
||||||
daysleft, daysleft == 1 ? "" : "s");
|
daysleft, daysleft == 1 ? "" : "s")) != 0)
|
||||||
buffer_append(&loginmsg, buf, strlen(buf));
|
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $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 Niels Provos <provos@citi.umich.edu>
|
||||||
* Copyright 2002 Markus Friedl <markus@openbsd.org>
|
* Copyright 2002 Markus Friedl <markus@openbsd.org>
|
||||||
@ -115,7 +115,7 @@ extern u_int utmp_len;
|
|||||||
extern u_char session_id[];
|
extern u_char session_id[];
|
||||||
extern Buffer auth_debug;
|
extern Buffer auth_debug;
|
||||||
extern int auth_debug_init;
|
extern int auth_debug_init;
|
||||||
extern Buffer loginmsg;
|
extern struct sshbuf *loginmsg;
|
||||||
extern struct sshauthopt *auth_opts; /* XXX move to permanent ssh->authctxt? */
|
extern struct sshauthopt *auth_opts; /* XXX move to permanent ssh->authctxt? */
|
||||||
|
|
||||||
/* State exported from the child */
|
/* State exported from the child */
|
||||||
@ -1495,8 +1495,8 @@ mm_answer_pty(int sock, Buffer *m)
|
|||||||
close(0);
|
close(0);
|
||||||
|
|
||||||
/* send messages generated by record_login */
|
/* send messages generated by record_login */
|
||||||
buffer_put_string(m, buffer_ptr(&loginmsg), buffer_len(&loginmsg));
|
buffer_put_string(m, buffer_ptr(loginmsg), buffer_len(loginmsg));
|
||||||
buffer_clear(&loginmsg);
|
buffer_clear(loginmsg);
|
||||||
|
|
||||||
mm_request_send(sock, MONITOR_ANS_PTY, m);
|
mm_request_send(sock, MONITOR_ANS_PTY, m);
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $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 Niels Provos <provos@citi.umich.edu>
|
||||||
* Copyright 2002 Markus Friedl <markus@openbsd.org>
|
* Copyright 2002 Markus Friedl <markus@openbsd.org>
|
||||||
@ -87,7 +87,7 @@
|
|||||||
extern z_stream incoming_stream;
|
extern z_stream incoming_stream;
|
||||||
extern z_stream outgoing_stream;
|
extern z_stream outgoing_stream;
|
||||||
extern struct monitor *pmonitor;
|
extern struct monitor *pmonitor;
|
||||||
extern Buffer loginmsg;
|
extern struct sshbuf *loginmsg;
|
||||||
extern ServerOptions options;
|
extern ServerOptions options;
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -506,7 +506,7 @@ mm_pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, size_t namebuflen)
|
|||||||
{
|
{
|
||||||
Buffer m;
|
Buffer m;
|
||||||
char *p, *msg;
|
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 */
|
/* Kludge: ensure there are fds free to receive the pty/tty */
|
||||||
if ((tmp1 = dup(pmonitor->m_recvfd)) == -1 ||
|
if ((tmp1 = dup(pmonitor->m_recvfd)) == -1 ||
|
||||||
@ -540,7 +540,8 @@ mm_pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, size_t namebuflen)
|
|||||||
strlcpy(namebuf, p, namebuflen); /* Possible truncation */
|
strlcpy(namebuf, p, namebuflen); /* Possible truncation */
|
||||||
free(p);
|
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);
|
free(msg);
|
||||||
|
|
||||||
if ((*ptyfd = mm_receive_fd(pmonitor->m_recvfd)) == -1 ||
|
if ((*ptyfd = mm_receive_fd(pmonitor->m_recvfd)) == -1 ||
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $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>
|
* Author: Tatu Ylonen <ylo@cs.hut.fi>
|
||||||
@ -261,8 +261,8 @@ void fill_default_server_options(ServerOptions *);
|
|||||||
int process_server_config_line(ServerOptions *, char *, const char *, int,
|
int process_server_config_line(ServerOptions *, char *, const char *, int,
|
||||||
int *, struct connection_info *);
|
int *, struct connection_info *);
|
||||||
void process_permitopen(struct ssh *ssh, ServerOptions *options);
|
void process_permitopen(struct ssh *ssh, ServerOptions *options);
|
||||||
void load_server_config(const char *, Buffer *);
|
void load_server_config(const char *, struct sshbuf *);
|
||||||
void parse_server_config(ServerOptions *, const char *, Buffer *,
|
void parse_server_config(ServerOptions *, const char *, struct sshbuf *,
|
||||||
struct connection_info *);
|
struct connection_info *);
|
||||||
void parse_server_match_config(ServerOptions *, struct connection_info *);
|
void parse_server_match_config(ServerOptions *, struct connection_info *);
|
||||||
int parse_server_match_testspec(struct connection_info *, char *);
|
int parse_server_match_testspec(struct connection_info *, char *);
|
||||||
|
22
session.c
22
session.c
@ -1,4 +1,4 @@
|
|||||||
/* $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
|
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
|
||||||
* All rights reserved
|
* All rights reserved
|
||||||
@ -69,7 +69,8 @@
|
|||||||
#include "ssh2.h"
|
#include "ssh2.h"
|
||||||
#include "sshpty.h"
|
#include "sshpty.h"
|
||||||
#include "packet.h"
|
#include "packet.h"
|
||||||
#include "buffer.h"
|
#include "sshbuf.h"
|
||||||
|
#include "ssherr.h"
|
||||||
#include "match.h"
|
#include "match.h"
|
||||||
#include "uidswap.h"
|
#include "uidswap.h"
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
@ -139,7 +140,7 @@ extern int debug_flag;
|
|||||||
extern u_int utmp_len;
|
extern u_int utmp_len;
|
||||||
extern int startup_pipe;
|
extern int startup_pipe;
|
||||||
extern void destroy_sensitive_data(void);
|
extern void destroy_sensitive_data(void);
|
||||||
extern Buffer loginmsg;
|
extern struct sshbuf *loginmsg;
|
||||||
extern struct sshauthopt *auth_opts;
|
extern struct sshauthopt *auth_opts;
|
||||||
char *tun_fwd_ifnames; /* serverloop.c */
|
char *tun_fwd_ifnames; /* serverloop.c */
|
||||||
|
|
||||||
@ -248,11 +249,14 @@ auth_input_request_forwarding(struct ssh *ssh, struct passwd * pw)
|
|||||||
static void
|
static void
|
||||||
display_loginmsg(void)
|
display_loginmsg(void)
|
||||||
{
|
{
|
||||||
if (buffer_len(&loginmsg) > 0) {
|
int r;
|
||||||
buffer_append(&loginmsg, "\0", 1);
|
|
||||||
printf("%s", (char *)buffer_ptr(&loginmsg));
|
if (sshbuf_len(loginmsg) == 0)
|
||||||
buffer_clear(&loginmsg);
|
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
|
static void
|
||||||
@ -757,7 +761,7 @@ do_exec(struct ssh *ssh, Session *s, const char *command)
|
|||||||
* it to the user, otherwise multiple sessions may accumulate
|
* it to the user, otherwise multiple sessions may accumulate
|
||||||
* multiple copies of the login messages.
|
* multiple copies of the login messages.
|
||||||
*/
|
*/
|
||||||
buffer_clear(&loginmsg);
|
sshbuf_reset(loginmsg);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
9
sshd.c
9
sshd.c
@ -1,4 +1,4 @@
|
|||||||
/* $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>
|
* Author: Tatu Ylonen <ylo@cs.hut.fi>
|
||||||
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
|
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
|
||||||
@ -240,7 +240,7 @@ struct sshauthopt *auth_opts = NULL;
|
|||||||
Buffer cfg;
|
Buffer cfg;
|
||||||
|
|
||||||
/* message to be displayed after login */
|
/* message to be displayed after login */
|
||||||
Buffer loginmsg;
|
struct sshbuf *loginmsg;
|
||||||
|
|
||||||
/* Unprivileged user */
|
/* Unprivileged user */
|
||||||
struct passwd *privsep_pw = NULL;
|
struct passwd *privsep_pw = NULL;
|
||||||
@ -649,7 +649,7 @@ privsep_postauth(Authctxt *authctxt)
|
|||||||
fatal("fork of unprivileged child failed");
|
fatal("fork of unprivileged child failed");
|
||||||
else if (pmonitor->m_pid != 0) {
|
else if (pmonitor->m_pid != 0) {
|
||||||
verbose("User child is on pid %ld", (long)pmonitor->m_pid);
|
verbose("User child is on pid %ld", (long)pmonitor->m_pid);
|
||||||
buffer_clear(&loginmsg);
|
sshbuf_reset(loginmsg);
|
||||||
monitor_clear_keystate(pmonitor);
|
monitor_clear_keystate(pmonitor);
|
||||||
monitor_child_postauth(pmonitor);
|
monitor_child_postauth(pmonitor);
|
||||||
|
|
||||||
@ -2119,7 +2119,8 @@ main(int ac, char **av)
|
|||||||
fatal("allocation failed");
|
fatal("allocation failed");
|
||||||
|
|
||||||
/* prepare buffer to collect messages to display to user after login */
|
/* 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();
|
auth_debug_reset();
|
||||||
|
|
||||||
if (use_privsep) {
|
if (use_privsep) {
|
||||||
|
22
sshlogin.c
22
sshlogin.c
@ -1,4 +1,4 @@
|
|||||||
/* $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>
|
* Author: Tatu Ylonen <ylo@cs.hut.fi>
|
||||||
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
|
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
|
||||||
@ -55,13 +55,15 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
|
#include "sshlogin.h"
|
||||||
|
#include "ssherr.h"
|
||||||
#include "loginrec.h"
|
#include "loginrec.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "buffer.h"
|
#include "sshbuf.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "servconf.h"
|
#include "servconf.h"
|
||||||
|
|
||||||
extern Buffer loginmsg;
|
extern struct sshbuf *loginmsg;
|
||||||
extern ServerOptions options;
|
extern ServerOptions options;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -88,8 +90,9 @@ static void
|
|||||||
store_lastlog_message(const char *user, uid_t uid)
|
store_lastlog_message(const char *user, uid_t uid)
|
||||||
{
|
{
|
||||||
#ifndef NO_SSH_LASTLOG
|
#ifndef NO_SSH_LASTLOG
|
||||||
char *time_string, hostname[HOST_NAME_MAX+1] = "", buf[512];
|
char *time_string, hostname[HOST_NAME_MAX+1] = "";
|
||||||
time_t last_login_time;
|
time_t last_login_time;
|
||||||
|
int r;
|
||||||
|
|
||||||
if (!options.print_lastlog)
|
if (!options.print_lastlog)
|
||||||
return;
|
return;
|
||||||
@ -97,7 +100,9 @@ store_lastlog_message(const char *user, uid_t uid)
|
|||||||
# ifdef CUSTOM_SYS_AUTH_GET_LASTLOGIN_MSG
|
# ifdef CUSTOM_SYS_AUTH_GET_LASTLOGIN_MSG
|
||||||
time_string = sys_auth_get_lastlogin_msg(user, uid);
|
time_string = sys_auth_get_lastlogin_msg(user, uid);
|
||||||
if (time_string != NULL) {
|
if (time_string != NULL) {
|
||||||
buffer_append(&loginmsg, time_string, strlen(time_string));
|
if ((r = sshbuf_put(loginmsg,
|
||||||
|
time_string, strlen(time_string))) != 0)
|
||||||
|
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
||||||
free(time_string);
|
free(time_string);
|
||||||
}
|
}
|
||||||
# else
|
# else
|
||||||
@ -108,12 +113,13 @@ store_lastlog_message(const char *user, uid_t uid)
|
|||||||
time_string = ctime(&last_login_time);
|
time_string = ctime(&last_login_time);
|
||||||
time_string[strcspn(time_string, "\n")] = '\0';
|
time_string[strcspn(time_string, "\n")] = '\0';
|
||||||
if (strcmp(hostname, "") == 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);
|
time_string);
|
||||||
else
|
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);
|
time_string, hostname);
|
||||||
buffer_append(&loginmsg, buf, strlen(buf));
|
if (r != 0)
|
||||||
|
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
||||||
}
|
}
|
||||||
# endif /* CUSTOM_SYS_AUTH_GET_LASTLOGIN_MSG */
|
# endif /* CUSTOM_SYS_AUTH_GET_LASTLOGIN_MSG */
|
||||||
#endif /* NO_SSH_LASTLOG */
|
#endif /* NO_SSH_LASTLOG */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user