2018-01-08 15:14:44 +00:00
|
|
|
/* $OpenBSD: monitor_wrap.c,v 1.98 2018/01/08 15:14:44 markus Exp $ */
|
2002-03-22 02:30:41 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
|
|
|
|
* Copyright 2002 Markus Friedl <markus@openbsd.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "includes.h"
|
|
|
|
|
2006-07-10 10:53:08 +00:00
|
|
|
#include <sys/types.h>
|
2006-08-05 08:46:47 +00:00
|
|
|
#include <sys/uio.h>
|
2006-07-10 10:53:08 +00:00
|
|
|
|
2006-07-12 12:22:46 +00:00
|
|
|
#include <errno.h>
|
2006-07-10 10:53:08 +00:00
|
|
|
#include <pwd.h>
|
2006-08-05 02:39:39 +00:00
|
|
|
#include <signal.h>
|
2006-09-01 05:38:36 +00:00
|
|
|
#include <stdarg.h>
|
2006-08-05 01:37:59 +00:00
|
|
|
#include <stdio.h>
|
2006-07-24 04:13:33 +00:00
|
|
|
#include <string.h>
|
2006-08-05 08:46:47 +00:00
|
|
|
#include <unistd.h>
|
2006-07-10 10:53:08 +00:00
|
|
|
|
2014-05-15 04:24:09 +00:00
|
|
|
#ifdef WITH_OPENSSL
|
2006-08-05 02:39:39 +00:00
|
|
|
#include <openssl/bn.h>
|
|
|
|
#include <openssl/dh.h>
|
2008-11-05 05:20:46 +00:00
|
|
|
#include <openssl/evp.h>
|
2014-05-15 04:24:09 +00:00
|
|
|
#endif
|
2006-08-05 02:39:39 +00:00
|
|
|
|
2008-05-19 05:05:07 +00:00
|
|
|
#include "openbsd-compat/sys-queue.h"
|
2006-08-05 02:39:39 +00:00
|
|
|
#include "xmalloc.h"
|
2002-03-22 02:30:41 +00:00
|
|
|
#include "ssh.h"
|
2014-05-15 04:24:09 +00:00
|
|
|
#ifdef WITH_OPENSSL
|
2002-03-22 02:30:41 +00:00
|
|
|
#include "dh.h"
|
2014-05-15 04:24:09 +00:00
|
|
|
#endif
|
2006-08-05 02:39:39 +00:00
|
|
|
#include "buffer.h"
|
|
|
|
#include "key.h"
|
|
|
|
#include "cipher.h"
|
2002-03-22 02:30:41 +00:00
|
|
|
#include "kex.h"
|
2006-08-05 02:39:39 +00:00
|
|
|
#include "hostfile.h"
|
2002-03-22 02:30:41 +00:00
|
|
|
#include "auth.h"
|
2003-02-24 01:03:38 +00:00
|
|
|
#include "auth-options.h"
|
2002-03-22 02:30:41 +00:00
|
|
|
#include "packet.h"
|
|
|
|
#include "mac.h"
|
|
|
|
#include "log.h"
|
2016-07-17 23:33:25 +00:00
|
|
|
#include "auth-pam.h"
|
2004-04-08 16:12:30 +00:00
|
|
|
#ifdef TARGET_OS_MAC /* XXX Broken krb5 headers on Mac */
|
|
|
|
#undef TARGET_OS_MAC
|
2004-04-08 05:11:03 +00:00
|
|
|
#include "zlib.h"
|
2004-04-08 16:12:30 +00:00
|
|
|
#define TARGET_OS_MAC 1
|
|
|
|
#else
|
|
|
|
#include "zlib.h"
|
|
|
|
#endif
|
2002-03-22 02:30:41 +00:00
|
|
|
#include "monitor.h"
|
2006-08-05 02:39:39 +00:00
|
|
|
#ifdef GSSAPI
|
|
|
|
#include "ssh-gss.h"
|
|
|
|
#endif
|
2002-03-22 02:30:41 +00:00
|
|
|
#include "monitor_wrap.h"
|
|
|
|
#include "atomicio.h"
|
|
|
|
#include "monitor_fdpass.h"
|
2006-03-31 12:13:02 +00:00
|
|
|
#include "misc.h"
|
2002-03-22 02:30:41 +00:00
|
|
|
|
|
|
|
#include "channels.h"
|
|
|
|
#include "session.h"
|
2007-02-19 11:25:37 +00:00
|
|
|
#include "servconf.h"
|
2002-03-22 02:30:41 +00:00
|
|
|
|
2015-01-19 19:52:16 +00:00
|
|
|
#include "ssherr.h"
|
|
|
|
|
2002-03-22 02:30:41 +00:00
|
|
|
/* Imports */
|
|
|
|
extern z_stream incoming_stream;
|
|
|
|
extern z_stream outgoing_stream;
|
2002-05-15 16:25:01 +00:00
|
|
|
extern struct monitor *pmonitor;
|
2004-07-17 07:05:14 +00:00
|
|
|
extern Buffer loginmsg;
|
2003-05-14 05:11:48 +00:00
|
|
|
extern ServerOptions options;
|
2002-03-22 02:30:41 +00:00
|
|
|
|
2011-06-20 04:42:23 +00:00
|
|
|
void
|
|
|
|
mm_log_handler(LogLevel level, const char *msg, void *ctx)
|
|
|
|
{
|
|
|
|
Buffer log_msg;
|
|
|
|
struct monitor *mon = (struct monitor *)ctx;
|
|
|
|
|
|
|
|
if (mon->m_log_sendfd == -1)
|
|
|
|
fatal("%s: no log channel", __func__);
|
|
|
|
|
|
|
|
buffer_init(&log_msg);
|
|
|
|
/*
|
|
|
|
* Placeholder for packet length. Will be filled in with the actual
|
|
|
|
* packet length once the packet has been constucted. This saves
|
|
|
|
* fragile math.
|
|
|
|
*/
|
|
|
|
buffer_put_int(&log_msg, 0);
|
|
|
|
|
|
|
|
buffer_put_int(&log_msg, level);
|
|
|
|
buffer_put_cstring(&log_msg, msg);
|
|
|
|
put_u32(buffer_ptr(&log_msg), buffer_len(&log_msg) - 4);
|
|
|
|
if (atomicio(vwrite, mon->m_log_sendfd, buffer_ptr(&log_msg),
|
|
|
|
buffer_len(&log_msg)) != buffer_len(&log_msg))
|
|
|
|
fatal("%s: write: %s", __func__, strerror(errno));
|
|
|
|
buffer_free(&log_msg);
|
|
|
|
}
|
|
|
|
|
2003-10-02 06:12:36 +00:00
|
|
|
int
|
|
|
|
mm_is_monitor(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* m_pid is only set in the privileged part, and
|
|
|
|
* points to the unprivileged child.
|
|
|
|
*/
|
2003-11-03 09:03:25 +00:00
|
|
|
return (pmonitor && pmonitor->m_pid > 0);
|
2003-10-02 06:12:36 +00:00
|
|
|
}
|
|
|
|
|
2002-03-22 02:30:41 +00:00
|
|
|
void
|
2004-06-22 02:56:01 +00:00
|
|
|
mm_request_send(int sock, enum monitor_reqtype type, Buffer *m)
|
2002-03-22 02:30:41 +00:00
|
|
|
{
|
|
|
|
u_int mlen = buffer_len(m);
|
2002-07-04 00:09:26 +00:00
|
|
|
u_char buf[5];
|
2002-03-22 02:30:41 +00:00
|
|
|
|
2002-06-06 21:40:51 +00:00
|
|
|
debug3("%s entering: type %d", __func__, type);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
2006-03-31 12:13:02 +00:00
|
|
|
put_u32(buf, mlen + 1);
|
2002-06-21 00:41:51 +00:00
|
|
|
buf[4] = (u_char) type; /* 1st byte of payload is mesg-type */
|
2004-06-22 02:56:01 +00:00
|
|
|
if (atomicio(vwrite, sock, buf, sizeof(buf)) != sizeof(buf))
|
2005-05-26 02:23:44 +00:00
|
|
|
fatal("%s: write: %s", __func__, strerror(errno));
|
2004-06-22 02:56:01 +00:00
|
|
|
if (atomicio(vwrite, sock, buffer_ptr(m), mlen) != mlen)
|
2005-05-26 02:23:44 +00:00
|
|
|
fatal("%s: write: %s", __func__, strerror(errno));
|
2002-03-22 02:30:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-06-22 02:56:01 +00:00
|
|
|
mm_request_receive(int sock, Buffer *m)
|
2002-03-22 02:30:41 +00:00
|
|
|
{
|
|
|
|
u_char buf[4];
|
|
|
|
u_int msg_len;
|
|
|
|
|
2002-06-06 21:40:51 +00:00
|
|
|
debug3("%s entering", __func__);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
2005-05-26 02:23:44 +00:00
|
|
|
if (atomicio(read, sock, buf, sizeof(buf)) != sizeof(buf)) {
|
2015-03-19 22:11:59 +00:00
|
|
|
if (errno == EPIPE)
|
2003-10-02 06:12:36 +00:00
|
|
|
cleanup_exit(255);
|
2005-05-26 02:23:44 +00:00
|
|
|
fatal("%s: read: %s", __func__, strerror(errno));
|
2002-03-22 02:30:41 +00:00
|
|
|
}
|
2006-03-31 12:13:02 +00:00
|
|
|
msg_len = get_u32(buf);
|
2002-03-22 02:30:41 +00:00
|
|
|
if (msg_len > 256 * 1024)
|
2002-06-06 21:40:51 +00:00
|
|
|
fatal("%s: read: bad msg_len %d", __func__, msg_len);
|
2002-03-22 02:30:41 +00:00
|
|
|
buffer_clear(m);
|
|
|
|
buffer_append_space(m, msg_len);
|
2005-05-26 02:23:44 +00:00
|
|
|
if (atomicio(read, sock, buffer_ptr(m), msg_len) != msg_len)
|
|
|
|
fatal("%s: read: %s", __func__, strerror(errno));
|
2002-03-22 02:30:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-06-22 02:56:01 +00:00
|
|
|
mm_request_receive_expect(int sock, enum monitor_reqtype type, Buffer *m)
|
2002-03-22 02:30:41 +00:00
|
|
|
{
|
|
|
|
u_char rtype;
|
|
|
|
|
2002-06-06 21:40:51 +00:00
|
|
|
debug3("%s entering: type %d", __func__, type);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
2004-06-22 02:56:01 +00:00
|
|
|
mm_request_receive(sock, m);
|
2002-03-22 02:30:41 +00:00
|
|
|
rtype = buffer_get_char(m);
|
|
|
|
if (rtype != type)
|
2002-06-06 21:40:51 +00:00
|
|
|
fatal("%s: read: rtype %d != type %d", __func__,
|
2002-03-22 02:30:41 +00:00
|
|
|
rtype, type);
|
|
|
|
}
|
|
|
|
|
2014-05-15 04:24:09 +00:00
|
|
|
#ifdef WITH_OPENSSL
|
2002-03-22 02:30:41 +00:00
|
|
|
DH *
|
|
|
|
mm_choose_dh(int min, int nbits, int max)
|
|
|
|
{
|
|
|
|
BIGNUM *p, *g;
|
|
|
|
int success = 0;
|
|
|
|
Buffer m;
|
|
|
|
|
|
|
|
buffer_init(&m);
|
|
|
|
buffer_put_int(&m, min);
|
|
|
|
buffer_put_int(&m, nbits);
|
|
|
|
buffer_put_int(&m, max);
|
|
|
|
|
2002-05-15 16:25:01 +00:00
|
|
|
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_MODULI, &m);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
2002-06-06 21:40:51 +00:00
|
|
|
debug3("%s: waiting for MONITOR_ANS_MODULI", __func__);
|
2002-05-15 16:25:01 +00:00
|
|
|
mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_MODULI, &m);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
|
|
|
success = buffer_get_char(&m);
|
|
|
|
if (success == 0)
|
2002-06-06 21:40:51 +00:00
|
|
|
fatal("%s: MONITOR_ANS_MODULI failed", __func__);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
|
|
|
if ((p = BN_new()) == NULL)
|
2002-06-06 21:40:51 +00:00
|
|
|
fatal("%s: BN_new failed", __func__);
|
2002-03-22 02:30:41 +00:00
|
|
|
if ((g = BN_new()) == NULL)
|
2002-06-06 21:40:51 +00:00
|
|
|
fatal("%s: BN_new failed", __func__);
|
2002-03-22 02:30:41 +00:00
|
|
|
buffer_get_bignum2(&m, p);
|
|
|
|
buffer_get_bignum2(&m, g);
|
|
|
|
|
2002-06-06 21:40:51 +00:00
|
|
|
debug3("%s: remaining %d", __func__, buffer_len(&m));
|
2002-03-22 02:30:41 +00:00
|
|
|
buffer_free(&m);
|
|
|
|
|
|
|
|
return (dh_new_group(g, p));
|
|
|
|
}
|
2014-05-15 04:24:09 +00:00
|
|
|
#endif
|
2002-03-22 02:30:41 +00:00
|
|
|
|
|
|
|
int
|
2017-05-30 08:52:19 +00:00
|
|
|
mm_key_sign(struct sshkey *key, u_char **sigp, u_int *lenp,
|
2015-12-04 16:41:28 +00:00
|
|
|
const u_char *data, u_int datalen, const char *hostkey_alg)
|
2002-03-22 02:30:41 +00:00
|
|
|
{
|
2015-01-19 20:16:15 +00:00
|
|
|
struct kex *kex = *pmonitor->m_pkex;
|
2002-03-22 02:30:41 +00:00
|
|
|
Buffer m;
|
|
|
|
|
2002-06-06 21:40:51 +00:00
|
|
|
debug3("%s entering", __func__);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
|
|
|
buffer_init(&m);
|
2015-02-16 22:13:32 +00:00
|
|
|
buffer_put_int(&m, kex->host_key_index(key, 0, active_state));
|
2002-03-22 02:30:41 +00:00
|
|
|
buffer_put_string(&m, data, datalen);
|
2015-12-04 16:41:28 +00:00
|
|
|
buffer_put_cstring(&m, hostkey_alg);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
2002-05-15 16:25:01 +00:00
|
|
|
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_SIGN, &m);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
2002-06-06 21:40:51 +00:00
|
|
|
debug3("%s: waiting for MONITOR_ANS_SIGN", __func__);
|
2002-05-15 16:25:01 +00:00
|
|
|
mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_SIGN, &m);
|
2002-03-22 02:30:41 +00:00
|
|
|
*sigp = buffer_get_string(&m, lenp);
|
|
|
|
buffer_free(&m);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct passwd *
|
2004-06-22 05:06:46 +00:00
|
|
|
mm_getpwnamallow(const char *username)
|
2002-03-22 02:30:41 +00:00
|
|
|
{
|
2017-09-12 06:32:07 +00:00
|
|
|
struct ssh *ssh = active_state; /* XXX */
|
2002-03-22 02:30:41 +00:00
|
|
|
Buffer m;
|
|
|
|
struct passwd *pw;
|
2011-05-29 11:39:36 +00:00
|
|
|
u_int len, i;
|
2007-02-19 11:25:37 +00:00
|
|
|
ServerOptions *newopts;
|
2002-03-22 02:30:41 +00:00
|
|
|
|
2002-06-06 21:40:51 +00:00
|
|
|
debug3("%s entering", __func__);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
|
|
|
buffer_init(&m);
|
2004-06-22 05:06:46 +00:00
|
|
|
buffer_put_cstring(&m, username);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
2002-05-15 16:25:01 +00:00
|
|
|
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PWNAM, &m);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
2002-06-06 21:40:51 +00:00
|
|
|
debug3("%s: waiting for MONITOR_ANS_PWNAM", __func__);
|
2002-05-15 16:25:01 +00:00
|
|
|
mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PWNAM, &m);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
|
|
|
if (buffer_get_char(&m) == 0) {
|
2007-12-02 12:02:15 +00:00
|
|
|
pw = NULL;
|
|
|
|
goto out;
|
2002-03-22 02:30:41 +00:00
|
|
|
}
|
2007-02-19 11:25:37 +00:00
|
|
|
pw = buffer_get_string(&m, &len);
|
|
|
|
if (len != sizeof(struct passwd))
|
2002-06-06 21:40:51 +00:00
|
|
|
fatal("%s: struct passwd size mismatch", __func__);
|
2002-03-22 02:30:41 +00:00
|
|
|
pw->pw_name = buffer_get_string(&m, NULL);
|
|
|
|
pw->pw_passwd = buffer_get_string(&m, NULL);
|
2013-04-23 04:25:52 +00:00
|
|
|
#ifdef HAVE_STRUCT_PASSWD_PW_GECOS
|
2002-03-22 02:30:41 +00:00
|
|
|
pw->pw_gecos = buffer_get_string(&m, NULL);
|
2013-04-23 04:25:52 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRUCT_PASSWD_PW_CLASS
|
2002-03-22 02:30:41 +00:00
|
|
|
pw->pw_class = buffer_get_string(&m, NULL);
|
2002-03-22 18:07:17 +00:00
|
|
|
#endif
|
2002-03-22 02:30:41 +00:00
|
|
|
pw->pw_dir = buffer_get_string(&m, NULL);
|
|
|
|
pw->pw_shell = buffer_get_string(&m, NULL);
|
2007-02-19 11:25:37 +00:00
|
|
|
|
2007-12-02 12:02:15 +00:00
|
|
|
out:
|
2007-02-19 11:25:37 +00:00
|
|
|
/* copy options block as a Match directive may have changed some */
|
|
|
|
newopts = buffer_get_string(&m, &len);
|
|
|
|
if (len != sizeof(*newopts))
|
|
|
|
fatal("%s: option block size mismatch", __func__);
|
2011-05-20 09:04:14 +00:00
|
|
|
|
|
|
|
#define M_CP_STROPT(x) do { \
|
|
|
|
if (newopts->x != NULL) \
|
|
|
|
newopts->x = buffer_get_string(&m, NULL); \
|
|
|
|
} while (0)
|
2011-05-29 11:39:36 +00:00
|
|
|
#define M_CP_STRARRAYOPT(x, nx) do { \
|
2017-10-02 19:33:20 +00:00
|
|
|
newopts->x = newopts->nx == 0 ? \
|
|
|
|
NULL : xcalloc(newopts->nx, sizeof(*newopts->x)); \
|
2017-10-05 15:52:03 +00:00
|
|
|
for (i = 0; i < newopts->nx; i++) \
|
|
|
|
newopts->x[i] = buffer_get_string(&m, NULL); \
|
2017-10-02 19:33:20 +00:00
|
|
|
} while (0)
|
2011-05-20 09:04:14 +00:00
|
|
|
/* See comment in servconf.h */
|
|
|
|
COPY_MATCH_STRING_OPTS();
|
|
|
|
#undef M_CP_STROPT
|
2011-05-29 11:39:36 +00:00
|
|
|
#undef M_CP_STRARRAYOPT
|
2011-05-20 09:04:14 +00:00
|
|
|
|
2007-02-19 11:25:37 +00:00
|
|
|
copy_set_server_options(&options, newopts, 1);
|
2017-05-17 01:24:17 +00:00
|
|
|
log_change_level(options.log_level);
|
2017-09-12 06:32:07 +00:00
|
|
|
process_permitopen(ssh, &options);
|
2013-06-01 21:31:17 +00:00
|
|
|
free(newopts);
|
2007-02-19 11:25:37 +00:00
|
|
|
|
2002-03-22 02:30:41 +00:00
|
|
|
buffer_free(&m);
|
|
|
|
|
|
|
|
return (pw);
|
|
|
|
}
|
|
|
|
|
2003-10-15 05:56:58 +00:00
|
|
|
char *
|
|
|
|
mm_auth2_read_banner(void)
|
2002-05-13 01:07:41 +00:00
|
|
|
{
|
|
|
|
Buffer m;
|
|
|
|
char *banner;
|
|
|
|
|
2002-06-06 21:40:51 +00:00
|
|
|
debug3("%s entering", __func__);
|
2002-05-13 01:07:41 +00:00
|
|
|
|
|
|
|
buffer_init(&m);
|
2002-05-15 16:25:01 +00:00
|
|
|
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTH2_READ_BANNER, &m);
|
2002-05-13 01:07:41 +00:00
|
|
|
buffer_clear(&m);
|
|
|
|
|
2003-10-15 05:56:58 +00:00
|
|
|
mm_request_receive_expect(pmonitor->m_recvfd,
|
|
|
|
MONITOR_ANS_AUTH2_READ_BANNER, &m);
|
2002-05-13 01:07:41 +00:00
|
|
|
banner = buffer_get_string(&m, NULL);
|
|
|
|
buffer_free(&m);
|
2002-06-21 00:41:51 +00:00
|
|
|
|
2003-10-15 05:56:58 +00:00
|
|
|
/* treat empty banner as missing banner */
|
|
|
|
if (strlen(banner) == 0) {
|
2013-06-01 21:31:17 +00:00
|
|
|
free(banner);
|
2003-10-15 05:56:58 +00:00
|
|
|
banner = NULL;
|
|
|
|
}
|
2002-05-13 01:07:41 +00:00
|
|
|
return (banner);
|
|
|
|
}
|
|
|
|
|
2002-03-22 02:30:41 +00:00
|
|
|
/* Inform the privileged process about service and style */
|
|
|
|
|
|
|
|
void
|
|
|
|
mm_inform_authserv(char *service, char *style)
|
|
|
|
{
|
|
|
|
Buffer m;
|
|
|
|
|
2002-06-06 21:40:51 +00:00
|
|
|
debug3("%s entering", __func__);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
|
|
|
buffer_init(&m);
|
|
|
|
buffer_put_cstring(&m, service);
|
|
|
|
buffer_put_cstring(&m, style ? style : "");
|
|
|
|
|
2002-05-15 16:25:01 +00:00
|
|
|
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHSERV, &m);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
|
|
|
buffer_free(&m);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do the password authentication */
|
|
|
|
int
|
|
|
|
mm_auth_password(Authctxt *authctxt, char *password)
|
|
|
|
{
|
|
|
|
Buffer m;
|
|
|
|
int authenticated = 0;
|
|
|
|
|
2002-06-06 21:40:51 +00:00
|
|
|
debug3("%s entering", __func__);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
|
|
|
buffer_init(&m);
|
|
|
|
buffer_put_cstring(&m, password);
|
2002-05-15 16:25:01 +00:00
|
|
|
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHPASSWORD, &m);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
2002-06-06 21:40:51 +00:00
|
|
|
debug3("%s: waiting for MONITOR_ANS_AUTHPASSWORD", __func__);
|
2002-05-15 16:25:01 +00:00
|
|
|
mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_AUTHPASSWORD, &m);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
|
|
|
authenticated = buffer_get_int(&m);
|
2016-07-17 23:33:25 +00:00
|
|
|
#ifdef USE_PAM
|
|
|
|
sshpam_set_maxtries_reached(buffer_get_int(&m));
|
|
|
|
#endif
|
2002-03-22 02:30:41 +00:00
|
|
|
|
|
|
|
buffer_free(&m);
|
|
|
|
|
|
|
|
debug3("%s: user %sauthenticated",
|
2002-06-06 21:40:51 +00:00
|
|
|
__func__, authenticated ? "" : "not ");
|
2002-03-22 02:30:41 +00:00
|
|
|
return (authenticated);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2017-05-30 08:52:19 +00:00
|
|
|
mm_user_key_allowed(struct passwd *pw, struct sshkey *key,
|
|
|
|
int pubkey_auth_attempt)
|
2002-03-22 02:30:41 +00:00
|
|
|
{
|
2015-05-01 03:23:51 +00:00
|
|
|
return (mm_key_allowed(MM_USERKEY, NULL, NULL, key,
|
|
|
|
pubkey_auth_attempt));
|
2002-03-22 02:30:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-03-07 19:02:43 +00:00
|
|
|
mm_hostbased_key_allowed(struct passwd *pw, const char *user, const char *host,
|
2017-05-30 08:52:19 +00:00
|
|
|
struct sshkey *key)
|
2002-03-22 02:30:41 +00:00
|
|
|
{
|
2015-05-01 03:23:51 +00:00
|
|
|
return (mm_key_allowed(MM_HOSTKEY, user, host, key, 0));
|
2002-03-22 02:30:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-03-07 19:02:43 +00:00
|
|
|
mm_key_allowed(enum mm_keytype type, const char *user, const char *host,
|
2017-05-30 08:52:19 +00:00
|
|
|
struct sshkey *key, int pubkey_auth_attempt)
|
2002-03-22 02:30:41 +00:00
|
|
|
{
|
|
|
|
Buffer m;
|
|
|
|
u_char *blob;
|
|
|
|
u_int len;
|
2003-02-24 01:03:38 +00:00
|
|
|
int allowed = 0, have_forced = 0;
|
2002-03-22 02:30:41 +00:00
|
|
|
|
2002-06-06 21:40:51 +00:00
|
|
|
debug3("%s entering", __func__);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
|
|
|
/* Convert the key to a blob and the pass it over */
|
|
|
|
if (!key_to_blob(key, &blob, &len))
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
buffer_init(&m);
|
|
|
|
buffer_put_int(&m, type);
|
|
|
|
buffer_put_cstring(&m, user ? user : "");
|
|
|
|
buffer_put_cstring(&m, host ? host : "");
|
|
|
|
buffer_put_string(&m, blob, len);
|
2015-05-01 03:23:51 +00:00
|
|
|
buffer_put_int(&m, pubkey_auth_attempt);
|
2013-06-01 21:31:17 +00:00
|
|
|
free(blob);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
2002-05-15 16:25:01 +00:00
|
|
|
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_KEYALLOWED, &m);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
2002-06-06 21:40:51 +00:00
|
|
|
debug3("%s: waiting for MONITOR_ANS_KEYALLOWED", __func__);
|
2002-05-15 16:25:01 +00:00
|
|
|
mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_KEYALLOWED, &m);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
|
|
|
allowed = buffer_get_int(&m);
|
|
|
|
|
2003-02-24 01:03:38 +00:00
|
|
|
/* fake forced command */
|
|
|
|
auth_clear_options();
|
|
|
|
have_forced = buffer_get_int(&m);
|
|
|
|
forced_command = have_forced ? xstrdup("true") : NULL;
|
|
|
|
|
2002-03-22 02:30:41 +00:00
|
|
|
buffer_free(&m);
|
|
|
|
|
|
|
|
return (allowed);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This key verify needs to send the key type along, because the
|
|
|
|
* privileged parent makes the decision if the key is allowed
|
|
|
|
* for authentication.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2017-05-30 14:10:53 +00:00
|
|
|
mm_sshkey_verify(const struct sshkey *key, const u_char *sig, size_t siglen,
|
2017-12-18 02:25:15 +00:00
|
|
|
const u_char *data, size_t datalen, const char *sigalg, u_int compat)
|
2002-03-22 02:30:41 +00:00
|
|
|
{
|
|
|
|
Buffer m;
|
|
|
|
u_char *blob;
|
|
|
|
u_int len;
|
2017-05-30 14:10:53 +00:00
|
|
|
u_int encoded_ret = 0;
|
2002-03-22 02:30:41 +00:00
|
|
|
|
2002-06-06 21:40:51 +00:00
|
|
|
debug3("%s entering", __func__);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
|
|
|
/* Convert the key to a blob and the pass it over */
|
|
|
|
if (!key_to_blob(key, &blob, &len))
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
buffer_init(&m);
|
|
|
|
buffer_put_string(&m, blob, len);
|
|
|
|
buffer_put_string(&m, sig, siglen);
|
|
|
|
buffer_put_string(&m, data, datalen);
|
2017-12-21 00:00:28 +00:00
|
|
|
buffer_put_cstring(&m, sigalg == NULL ? "" : sigalg);
|
2013-06-01 21:31:17 +00:00
|
|
|
free(blob);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
2002-05-15 16:25:01 +00:00
|
|
|
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_KEYVERIFY, &m);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
2002-06-06 21:40:51 +00:00
|
|
|
debug3("%s: waiting for MONITOR_ANS_KEYVERIFY", __func__);
|
2002-05-15 16:25:01 +00:00
|
|
|
mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_KEYVERIFY, &m);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
2017-05-30 14:10:53 +00:00
|
|
|
encoded_ret = buffer_get_int(&m);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
|
|
|
buffer_free(&m);
|
|
|
|
|
2017-05-30 14:10:53 +00:00
|
|
|
if (encoded_ret != 0)
|
|
|
|
return SSH_ERR_SIGNATURE_INVALID;
|
|
|
|
return 0;
|
2002-03-22 02:30:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-06-22 02:56:01 +00:00
|
|
|
mm_send_keystate(struct monitor *monitor)
|
2002-03-22 02:30:41 +00:00
|
|
|
{
|
2015-01-19 19:52:16 +00:00
|
|
|
struct ssh *ssh = active_state; /* XXX */
|
|
|
|
struct sshbuf *m;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
if ((m = sshbuf_new()) == NULL)
|
|
|
|
fatal("%s: sshbuf_new failed", __func__);
|
|
|
|
if ((r = ssh_packet_get_state(ssh, m)) != 0)
|
|
|
|
fatal("%s: get_state failed: %s",
|
|
|
|
__func__, ssh_err(r));
|
|
|
|
mm_request_send(monitor->m_recvfd, MONITOR_REQ_KEYEXPORT, m);
|
2002-06-06 21:40:51 +00:00
|
|
|
debug3("%s: Finished sending state", __func__);
|
2015-01-19 19:52:16 +00:00
|
|
|
sshbuf_free(m);
|
2002-03-22 02:30:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2006-03-26 03:04:36 +00:00
|
|
|
mm_pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, size_t namebuflen)
|
2002-03-22 02:30:41 +00:00
|
|
|
{
|
|
|
|
Buffer m;
|
2004-07-17 07:05:14 +00:00
|
|
|
char *p, *msg;
|
2008-05-19 05:34:50 +00:00
|
|
|
int success = 0, tmp1 = -1, tmp2 = -1;
|
|
|
|
|
|
|
|
/* Kludge: ensure there are fds free to receive the pty/tty */
|
|
|
|
if ((tmp1 = dup(pmonitor->m_recvfd)) == -1 ||
|
|
|
|
(tmp2 = dup(pmonitor->m_recvfd)) == -1) {
|
|
|
|
error("%s: cannot allocate fds for pty", __func__);
|
|
|
|
if (tmp1 > 0)
|
|
|
|
close(tmp1);
|
|
|
|
if (tmp2 > 0)
|
|
|
|
close(tmp2);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
close(tmp1);
|
|
|
|
close(tmp2);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
|
|
|
buffer_init(&m);
|
2002-05-15 16:25:01 +00:00
|
|
|
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PTY, &m);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
2002-06-06 21:40:51 +00:00
|
|
|
debug3("%s: waiting for MONITOR_ANS_PTY", __func__);
|
2002-05-15 16:25:01 +00:00
|
|
|
mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PTY, &m);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
|
|
|
success = buffer_get_int(&m);
|
|
|
|
if (success == 0) {
|
2002-06-06 21:40:51 +00:00
|
|
|
debug3("%s: pty alloc failed", __func__);
|
2002-03-22 02:30:41 +00:00
|
|
|
buffer_free(&m);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
p = buffer_get_string(&m, NULL);
|
2004-07-17 07:05:14 +00:00
|
|
|
msg = buffer_get_string(&m, NULL);
|
2002-03-22 02:30:41 +00:00
|
|
|
buffer_free(&m);
|
|
|
|
|
|
|
|
strlcpy(namebuf, p, namebuflen); /* Possible truncation */
|
2013-06-01 21:31:17 +00:00
|
|
|
free(p);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
2004-07-17 07:05:14 +00:00
|
|
|
buffer_append(&loginmsg, msg, strlen(msg));
|
2013-06-01 21:31:17 +00:00
|
|
|
free(msg);
|
2004-07-17 07:05:14 +00:00
|
|
|
|
2007-09-17 02:04:08 +00:00
|
|
|
if ((*ptyfd = mm_receive_fd(pmonitor->m_recvfd)) == -1 ||
|
|
|
|
(*ttyfd = mm_receive_fd(pmonitor->m_recvfd)) == -1)
|
|
|
|
fatal("%s: receive fds failed", __func__);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
|
|
|
/* Success */
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-10-02 06:12:36 +00:00
|
|
|
mm_session_pty_cleanup2(Session *s)
|
2002-03-22 02:30:41 +00:00
|
|
|
{
|
|
|
|
Buffer m;
|
|
|
|
|
|
|
|
if (s->ttyfd == -1)
|
|
|
|
return;
|
|
|
|
buffer_init(&m);
|
|
|
|
buffer_put_cstring(&m, s->tty);
|
2002-05-15 16:25:01 +00:00
|
|
|
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PTYCLEANUP, &m);
|
2002-03-22 02:30:41 +00:00
|
|
|
buffer_free(&m);
|
|
|
|
|
|
|
|
/* closed dup'ed master */
|
2008-05-19 05:34:50 +00:00
|
|
|
if (s->ptymaster != -1 && close(s->ptymaster) < 0)
|
|
|
|
error("close(s->ptymaster/%d): %s",
|
|
|
|
s->ptymaster, strerror(errno));
|
2002-03-22 02:30:41 +00:00
|
|
|
|
|
|
|
/* unlink pty from session */
|
|
|
|
s->ttyfd = -1;
|
|
|
|
}
|
|
|
|
|
2002-04-23 10:28:48 +00:00
|
|
|
#ifdef USE_PAM
|
|
|
|
void
|
2004-03-08 12:04:06 +00:00
|
|
|
mm_start_pam(Authctxt *authctxt)
|
2002-04-23 10:28:48 +00:00
|
|
|
{
|
|
|
|
Buffer m;
|
|
|
|
|
2002-06-06 21:40:51 +00:00
|
|
|
debug3("%s entering", __func__);
|
2003-05-14 05:11:48 +00:00
|
|
|
if (!options.use_pam)
|
|
|
|
fatal("UsePAM=no, but ended up in %s anyway", __func__);
|
2002-04-23 10:28:48 +00:00
|
|
|
|
|
|
|
buffer_init(&m);
|
2002-05-15 16:25:01 +00:00
|
|
|
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_START, &m);
|
2002-04-23 10:28:48 +00:00
|
|
|
|
|
|
|
buffer_free(&m);
|
|
|
|
}
|
2003-05-10 09:28:02 +00:00
|
|
|
|
2003-08-25 03:08:49 +00:00
|
|
|
u_int
|
|
|
|
mm_do_pam_account(void)
|
|
|
|
{
|
|
|
|
Buffer m;
|
|
|
|
u_int ret;
|
2004-09-11 13:07:03 +00:00
|
|
|
char *msg;
|
2003-08-25 03:08:49 +00:00
|
|
|
|
|
|
|
debug3("%s entering", __func__);
|
|
|
|
if (!options.use_pam)
|
|
|
|
fatal("UsePAM=no, but ended up in %s anyway", __func__);
|
|
|
|
|
|
|
|
buffer_init(&m);
|
|
|
|
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_ACCOUNT, &m);
|
|
|
|
|
2003-11-21 12:48:55 +00:00
|
|
|
mm_request_receive_expect(pmonitor->m_recvfd,
|
2003-08-25 03:08:49 +00:00
|
|
|
MONITOR_ANS_PAM_ACCOUNT, &m);
|
|
|
|
ret = buffer_get_int(&m);
|
2004-09-11 13:07:03 +00:00
|
|
|
msg = buffer_get_string(&m, NULL);
|
|
|
|
buffer_append(&loginmsg, msg, strlen(msg));
|
2013-06-01 22:07:31 +00:00
|
|
|
free(msg);
|
2003-08-25 03:08:49 +00:00
|
|
|
|
|
|
|
buffer_free(&m);
|
2003-11-21 12:56:47 +00:00
|
|
|
|
2003-08-25 03:08:49 +00:00
|
|
|
debug3("%s returning %d", __func__, ret);
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2003-05-10 09:28:02 +00:00
|
|
|
void *
|
|
|
|
mm_sshpam_init_ctx(Authctxt *authctxt)
|
|
|
|
{
|
|
|
|
Buffer m;
|
|
|
|
int success;
|
|
|
|
|
|
|
|
debug3("%s", __func__);
|
|
|
|
buffer_init(&m);
|
|
|
|
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_INIT_CTX, &m);
|
|
|
|
debug3("%s: waiting for MONITOR_ANS_PAM_INIT_CTX", __func__);
|
|
|
|
mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PAM_INIT_CTX, &m);
|
|
|
|
success = buffer_get_int(&m);
|
|
|
|
if (success == 0) {
|
|
|
|
debug3("%s: pam_init_ctx failed", __func__);
|
|
|
|
buffer_free(&m);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
buffer_free(&m);
|
|
|
|
return (authctxt);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
mm_sshpam_query(void *ctx, char **name, char **info,
|
|
|
|
u_int *num, char ***prompts, u_int **echo_on)
|
|
|
|
{
|
|
|
|
Buffer m;
|
2005-07-17 07:53:31 +00:00
|
|
|
u_int i;
|
|
|
|
int ret;
|
2003-05-10 09:28:02 +00:00
|
|
|
|
|
|
|
debug3("%s", __func__);
|
|
|
|
buffer_init(&m);
|
|
|
|
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_QUERY, &m);
|
|
|
|
debug3("%s: waiting for MONITOR_ANS_PAM_QUERY", __func__);
|
|
|
|
mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PAM_QUERY, &m);
|
|
|
|
ret = buffer_get_int(&m);
|
|
|
|
debug3("%s: pam_query returned %d", __func__, ret);
|
|
|
|
*name = buffer_get_string(&m, NULL);
|
|
|
|
*info = buffer_get_string(&m, NULL);
|
2016-07-17 23:33:25 +00:00
|
|
|
sshpam_set_maxtries_reached(buffer_get_int(&m));
|
2003-05-10 09:28:02 +00:00
|
|
|
*num = buffer_get_int(&m);
|
2006-05-04 06:24:34 +00:00
|
|
|
if (*num > PAM_MAX_NUM_MSG)
|
|
|
|
fatal("%s: recieved %u PAM messages, expected <= %u",
|
|
|
|
__func__, *num, PAM_MAX_NUM_MSG);
|
|
|
|
*prompts = xcalloc((*num + 1), sizeof(char *));
|
|
|
|
*echo_on = xcalloc((*num + 1), sizeof(u_int));
|
2003-05-10 09:28:02 +00:00
|
|
|
for (i = 0; i < *num; ++i) {
|
|
|
|
(*prompts)[i] = buffer_get_string(&m, NULL);
|
|
|
|
(*echo_on)[i] = buffer_get_int(&m);
|
|
|
|
}
|
|
|
|
buffer_free(&m);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
mm_sshpam_respond(void *ctx, u_int num, char **resp)
|
|
|
|
{
|
|
|
|
Buffer m;
|
2005-07-17 07:53:31 +00:00
|
|
|
u_int i;
|
|
|
|
int ret;
|
2003-05-10 09:28:02 +00:00
|
|
|
|
|
|
|
debug3("%s", __func__);
|
|
|
|
buffer_init(&m);
|
|
|
|
buffer_put_int(&m, num);
|
|
|
|
for (i = 0; i < num; ++i)
|
|
|
|
buffer_put_cstring(&m, resp[i]);
|
|
|
|
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_RESPOND, &m);
|
|
|
|
debug3("%s: waiting for MONITOR_ANS_PAM_RESPOND", __func__);
|
|
|
|
mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PAM_RESPOND, &m);
|
|
|
|
ret = buffer_get_int(&m);
|
|
|
|
debug3("%s: pam_respond returned %d", __func__, ret);
|
|
|
|
buffer_free(&m);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mm_sshpam_free_ctx(void *ctxtp)
|
|
|
|
{
|
|
|
|
Buffer m;
|
|
|
|
|
|
|
|
debug3("%s", __func__);
|
|
|
|
buffer_init(&m);
|
|
|
|
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_FREE_CTX, &m);
|
|
|
|
debug3("%s: waiting for MONITOR_ANS_PAM_FREE_CTX", __func__);
|
|
|
|
mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PAM_FREE_CTX, &m);
|
|
|
|
buffer_free(&m);
|
|
|
|
}
|
2002-04-23 10:28:48 +00:00
|
|
|
#endif /* USE_PAM */
|
|
|
|
|
2002-03-22 02:30:41 +00:00
|
|
|
/* Request process termination */
|
|
|
|
|
|
|
|
void
|
|
|
|
mm_terminate(void)
|
|
|
|
{
|
|
|
|
Buffer m;
|
|
|
|
|
|
|
|
buffer_init(&m);
|
2002-05-15 16:25:01 +00:00
|
|
|
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_TERM, &m);
|
2002-03-22 02:30:41 +00:00
|
|
|
buffer_free(&m);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mm_chall_setup(char **name, char **infotxt, u_int *numprompts,
|
|
|
|
char ***prompts, u_int **echo_on)
|
|
|
|
{
|
2002-06-21 00:41:51 +00:00
|
|
|
*name = xstrdup("");
|
|
|
|
*infotxt = xstrdup("");
|
2002-03-22 02:30:41 +00:00
|
|
|
*numprompts = 1;
|
2006-03-26 03:19:21 +00:00
|
|
|
*prompts = xcalloc(*numprompts, sizeof(char *));
|
|
|
|
*echo_on = xcalloc(*numprompts, sizeof(u_int));
|
2002-03-22 02:30:41 +00:00
|
|
|
(*echo_on)[0] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
mm_bsdauth_query(void *ctx, char **name, char **infotxt,
|
|
|
|
u_int *numprompts, char ***prompts, u_int **echo_on)
|
|
|
|
{
|
|
|
|
Buffer m;
|
2003-02-24 00:55:46 +00:00
|
|
|
u_int success;
|
2002-03-22 02:30:41 +00:00
|
|
|
char *challenge;
|
|
|
|
|
2002-06-06 21:40:51 +00:00
|
|
|
debug3("%s: entering", __func__);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
|
|
|
buffer_init(&m);
|
2002-05-15 16:25:01 +00:00
|
|
|
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_BSDAUTHQUERY, &m);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
2002-05-15 16:25:01 +00:00
|
|
|
mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_BSDAUTHQUERY,
|
2002-03-22 02:30:41 +00:00
|
|
|
&m);
|
2003-02-24 00:55:46 +00:00
|
|
|
success = buffer_get_int(&m);
|
|
|
|
if (success == 0) {
|
2002-06-06 21:40:51 +00:00
|
|
|
debug3("%s: no challenge", __func__);
|
2002-03-22 02:30:41 +00:00
|
|
|
buffer_free(&m);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the challenge, and format the response */
|
|
|
|
challenge = buffer_get_string(&m, NULL);
|
|
|
|
buffer_free(&m);
|
|
|
|
|
|
|
|
mm_chall_setup(name, infotxt, numprompts, prompts, echo_on);
|
|
|
|
(*prompts)[0] = challenge;
|
|
|
|
|
2002-06-06 21:40:51 +00:00
|
|
|
debug3("%s: received challenge: %s", __func__, challenge);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
mm_bsdauth_respond(void *ctx, u_int numresponses, char **responses)
|
|
|
|
{
|
|
|
|
Buffer m;
|
|
|
|
int authok;
|
|
|
|
|
2002-06-06 21:40:51 +00:00
|
|
|
debug3("%s: entering", __func__);
|
2002-03-22 02:30:41 +00:00
|
|
|
if (numresponses != 1)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
buffer_init(&m);
|
|
|
|
buffer_put_cstring(&m, responses[0]);
|
2002-05-15 16:25:01 +00:00
|
|
|
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_BSDAUTHRESPOND, &m);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
2002-05-15 16:25:01 +00:00
|
|
|
mm_request_receive_expect(pmonitor->m_recvfd,
|
2002-03-22 02:30:41 +00:00
|
|
|
MONITOR_ANS_BSDAUTHRESPOND, &m);
|
|
|
|
|
|
|
|
authok = buffer_get_int(&m);
|
|
|
|
buffer_free(&m);
|
|
|
|
|
|
|
|
return ((authok == 0) ? -1 : 0);
|
|
|
|
}
|
|
|
|
|
2004-07-08 13:09:42 +00:00
|
|
|
#ifdef SKEY
|
2002-03-22 02:30:41 +00:00
|
|
|
int
|
|
|
|
mm_skey_query(void *ctx, char **name, char **infotxt,
|
|
|
|
u_int *numprompts, char ***prompts, u_int **echo_on)
|
|
|
|
{
|
|
|
|
Buffer m;
|
2003-02-24 00:55:46 +00:00
|
|
|
u_int success;
|
2006-08-05 08:50:35 +00:00
|
|
|
char *challenge;
|
2002-03-22 02:30:41 +00:00
|
|
|
|
2002-06-06 21:40:51 +00:00
|
|
|
debug3("%s: entering", __func__);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
|
|
|
buffer_init(&m);
|
2002-05-15 16:25:01 +00:00
|
|
|
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_SKEYQUERY, &m);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
2002-05-15 16:25:01 +00:00
|
|
|
mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_SKEYQUERY,
|
2002-03-22 02:30:41 +00:00
|
|
|
&m);
|
2003-02-24 00:55:46 +00:00
|
|
|
success = buffer_get_int(&m);
|
|
|
|
if (success == 0) {
|
2002-06-06 21:40:51 +00:00
|
|
|
debug3("%s: no challenge", __func__);
|
2002-03-22 02:30:41 +00:00
|
|
|
buffer_free(&m);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the challenge, and format the response */
|
|
|
|
challenge = buffer_get_string(&m, NULL);
|
|
|
|
buffer_free(&m);
|
|
|
|
|
2002-06-06 21:40:51 +00:00
|
|
|
debug3("%s: received challenge: %s", __func__, challenge);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
|
|
|
mm_chall_setup(name, infotxt, numprompts, prompts, echo_on);
|
|
|
|
|
2006-03-26 03:19:21 +00:00
|
|
|
xasprintf(*prompts, "%s%s", challenge, SKEY_PROMPT);
|
2013-06-01 22:07:31 +00:00
|
|
|
free(challenge);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
mm_skey_respond(void *ctx, u_int numresponses, char **responses)
|
|
|
|
{
|
|
|
|
Buffer m;
|
|
|
|
int authok;
|
|
|
|
|
2002-06-06 21:40:51 +00:00
|
|
|
debug3("%s: entering", __func__);
|
2002-03-22 02:30:41 +00:00
|
|
|
if (numresponses != 1)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
buffer_init(&m);
|
|
|
|
buffer_put_cstring(&m, responses[0]);
|
2002-05-15 16:25:01 +00:00
|
|
|
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_SKEYRESPOND, &m);
|
2002-03-22 02:30:41 +00:00
|
|
|
|
2002-05-15 16:25:01 +00:00
|
|
|
mm_request_receive_expect(pmonitor->m_recvfd,
|
2002-03-22 02:30:41 +00:00
|
|
|
MONITOR_ANS_SKEYRESPOND, &m);
|
|
|
|
|
|
|
|
authok = buffer_get_int(&m);
|
|
|
|
buffer_free(&m);
|
|
|
|
|
|
|
|
return ((authok == 0) ? -1 : 0);
|
|
|
|
}
|
2004-07-08 13:09:42 +00:00
|
|
|
#endif /* SKEY */
|
2002-03-22 02:30:41 +00:00
|
|
|
|
2005-02-08 10:52:47 +00:00
|
|
|
#ifdef SSH_AUDIT_EVENTS
|
2005-02-02 13:20:53 +00:00
|
|
|
void
|
|
|
|
mm_audit_event(ssh_audit_event_t event)
|
|
|
|
{
|
|
|
|
Buffer m;
|
|
|
|
|
|
|
|
debug3("%s entering", __func__);
|
|
|
|
|
|
|
|
buffer_init(&m);
|
|
|
|
buffer_put_int(&m, event);
|
|
|
|
|
|
|
|
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_EVENT, &m);
|
|
|
|
buffer_free(&m);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mm_audit_run_command(const char *command)
|
|
|
|
{
|
|
|
|
Buffer m;
|
|
|
|
|
|
|
|
debug3("%s entering command %s", __func__, command);
|
|
|
|
|
|
|
|
buffer_init(&m);
|
|
|
|
buffer_put_cstring(&m, command);
|
|
|
|
|
|
|
|
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_COMMAND, &m);
|
|
|
|
buffer_free(&m);
|
|
|
|
}
|
2005-02-08 10:52:47 +00:00
|
|
|
#endif /* SSH_AUDIT_EVENTS */
|
2005-02-02 13:20:53 +00:00
|
|
|
|
2003-08-26 01:49:55 +00:00
|
|
|
#ifdef GSSAPI
|
|
|
|
OM_uint32
|
2004-06-22 02:56:01 +00:00
|
|
|
mm_ssh_gssapi_server_ctx(Gssctxt **ctx, gss_OID goid)
|
2003-08-26 01:49:55 +00:00
|
|
|
{
|
|
|
|
Buffer m;
|
|
|
|
OM_uint32 major;
|
|
|
|
|
|
|
|
/* Client doesn't get to see the context */
|
|
|
|
*ctx = NULL;
|
|
|
|
|
|
|
|
buffer_init(&m);
|
2004-06-22 02:56:01 +00:00
|
|
|
buffer_put_string(&m, goid->elements, goid->length);
|
2003-08-26 01:49:55 +00:00
|
|
|
|
|
|
|
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSSETUP, &m);
|
|
|
|
mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSSETUP, &m);
|
|
|
|
|
|
|
|
major = buffer_get_int(&m);
|
|
|
|
|
|
|
|
buffer_free(&m);
|
|
|
|
return (major);
|
|
|
|
}
|
|
|
|
|
|
|
|
OM_uint32
|
|
|
|
mm_ssh_gssapi_accept_ctx(Gssctxt *ctx, gss_buffer_desc *in,
|
|
|
|
gss_buffer_desc *out, OM_uint32 *flags)
|
|
|
|
{
|
|
|
|
Buffer m;
|
|
|
|
OM_uint32 major;
|
2003-08-26 02:10:48 +00:00
|
|
|
u_int len;
|
2003-08-26 01:49:55 +00:00
|
|
|
|
|
|
|
buffer_init(&m);
|
|
|
|
buffer_put_string(&m, in->value, in->length);
|
|
|
|
|
|
|
|
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSSTEP, &m);
|
|
|
|
mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSSTEP, &m);
|
|
|
|
|
|
|
|
major = buffer_get_int(&m);
|
2003-08-26 02:10:48 +00:00
|
|
|
out->value = buffer_get_string(&m, &len);
|
|
|
|
out->length = len;
|
2003-08-26 01:49:55 +00:00
|
|
|
if (flags)
|
|
|
|
*flags = buffer_get_int(&m);
|
|
|
|
|
|
|
|
buffer_free(&m);
|
|
|
|
|
|
|
|
return (major);
|
|
|
|
}
|
|
|
|
|
2003-11-17 11:18:21 +00:00
|
|
|
OM_uint32
|
|
|
|
mm_ssh_gssapi_checkmic(Gssctxt *ctx, gss_buffer_t gssbuf, gss_buffer_t gssmic)
|
|
|
|
{
|
|
|
|
Buffer m;
|
|
|
|
OM_uint32 major;
|
|
|
|
|
|
|
|
buffer_init(&m);
|
|
|
|
buffer_put_string(&m, gssbuf->value, gssbuf->length);
|
|
|
|
buffer_put_string(&m, gssmic->value, gssmic->length);
|
|
|
|
|
|
|
|
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSCHECKMIC, &m);
|
|
|
|
mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSCHECKMIC,
|
|
|
|
&m);
|
|
|
|
|
|
|
|
major = buffer_get_int(&m);
|
|
|
|
buffer_free(&m);
|
|
|
|
return(major);
|
|
|
|
}
|
|
|
|
|
2003-08-26 01:49:55 +00:00
|
|
|
int
|
|
|
|
mm_ssh_gssapi_userok(char *user)
|
|
|
|
{
|
|
|
|
Buffer m;
|
|
|
|
int authenticated = 0;
|
|
|
|
|
|
|
|
buffer_init(&m);
|
|
|
|
|
|
|
|
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSUSEROK, &m);
|
|
|
|
mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSUSEROK,
|
|
|
|
&m);
|
|
|
|
|
|
|
|
authenticated = buffer_get_int(&m);
|
|
|
|
|
|
|
|
buffer_free(&m);
|
|
|
|
debug3("%s: user %sauthenticated",__func__, authenticated ? "" : "not ");
|
|
|
|
return (authenticated);
|
|
|
|
}
|
|
|
|
#endif /* GSSAPI */
|
2008-11-05 05:20:46 +00:00
|
|
|
|