djm@openbsd.org | 0fa174e | 2019-01-19 21:31:32 +0000 | [diff] [blame] | 1 | /* $OpenBSD: monitor_wrap.c,v 1.108 2019/01/19 21:31:32 djm Exp $ */ |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2002 Niels Provos <provos@citi.umich.edu> |
| 4 | * Copyright 2002 Markus Friedl <markus@openbsd.org> |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 10 | * 1. Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in the |
| 14 | * documentation and/or other materials provided with the distribution. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #include "includes.h" |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 29 | |
Damien Miller | 9f2abc4 | 2006-07-10 20:53:08 +1000 | [diff] [blame] | 30 | #include <sys/types.h> |
Darren Tucker | 1a3d6e7 | 2006-08-05 18:46:47 +1000 | [diff] [blame] | 31 | #include <sys/uio.h> |
Damien Miller | 9f2abc4 | 2006-07-10 20:53:08 +1000 | [diff] [blame] | 32 | |
Darren Tucker | 3997249 | 2006-07-12 22:22:46 +1000 | [diff] [blame] | 33 | #include <errno.h> |
Damien Miller | 9f2abc4 | 2006-07-10 20:53:08 +1000 | [diff] [blame] | 34 | #include <pwd.h> |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 35 | #include <signal.h> |
Damien Miller | ded319c | 2006-09-01 15:38:36 +1000 | [diff] [blame] | 36 | #include <stdarg.h> |
Damien Miller | a7a73ee | 2006-08-05 11:37:59 +1000 | [diff] [blame] | 37 | #include <stdio.h> |
Damien Miller | e3476ed | 2006-07-24 14:13:33 +1000 | [diff] [blame] | 38 | #include <string.h> |
Darren Tucker | 1a3d6e7 | 2006-08-05 18:46:47 +1000 | [diff] [blame] | 39 | #include <unistd.h> |
Damien Miller | 9f2abc4 | 2006-07-10 20:53:08 +1000 | [diff] [blame] | 40 | |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 41 | #ifdef WITH_OPENSSL |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 42 | #include <openssl/bn.h> |
| 43 | #include <openssl/dh.h> |
Damien Miller | 01ed227 | 2008-11-05 16:20:46 +1100 | [diff] [blame] | 44 | #include <openssl/evp.h> |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 45 | #endif |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 46 | |
Damien Miller | b84886b | 2008-05-19 15:05:07 +1000 | [diff] [blame] | 47 | #include "openbsd-compat/sys-queue.h" |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 48 | #include "xmalloc.h" |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 49 | #include "ssh.h" |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 50 | #ifdef WITH_OPENSSL |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 51 | #include "dh.h" |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 52 | #endif |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 53 | #include "sshbuf.h" |
markus@openbsd.org | 5467fbc | 2018-07-11 18:53:29 +0000 | [diff] [blame] | 54 | #include "sshkey.h" |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 55 | #include "cipher.h" |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 56 | #include "kex.h" |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 57 | #include "hostfile.h" |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 58 | #include "auth.h" |
Damien Miller | 06ebedf | 2003-02-24 12:03:38 +1100 | [diff] [blame] | 59 | #include "auth-options.h" |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 60 | #include "packet.h" |
| 61 | #include "mac.h" |
| 62 | #include "log.h" |
Darren Tucker | 01558b7 | 2016-07-18 09:33:25 +1000 | [diff] [blame] | 63 | #include "auth-pam.h" |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 64 | #include "monitor.h" |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 65 | #ifdef GSSAPI |
| 66 | #include "ssh-gss.h" |
| 67 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 68 | #include "monitor_wrap.h" |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 69 | #include "atomicio.h" |
| 70 | #include "monitor_fdpass.h" |
Damien Miller | 3f94188 | 2006-03-31 23:13:02 +1100 | [diff] [blame] | 71 | #include "misc.h" |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 72 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 73 | #include "channels.h" |
| 74 | #include "session.h" |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 75 | #include "servconf.h" |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 76 | |
markus@openbsd.org | 091c302 | 2015-01-19 19:52:16 +0000 | [diff] [blame] | 77 | #include "ssherr.h" |
| 78 | |
djm@openbsd.org | 0fa174e | 2019-01-19 21:31:32 +0000 | [diff] [blame] | 79 | #include "opacket.h" /* XXX */ |
| 80 | extern struct ssh *active_state; /* XXX */ |
| 81 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 82 | /* Imports */ |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 83 | extern struct monitor *pmonitor; |
markus@openbsd.org | 2808d18 | 2018-07-09 21:26:02 +0000 | [diff] [blame] | 84 | extern struct sshbuf *loginmsg; |
Damien Miller | 4e448a3 | 2003-05-14 15:11:48 +1000 | [diff] [blame] | 85 | extern ServerOptions options; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 86 | |
Damien Miller | 8f0bf23 | 2011-06-20 14:42:23 +1000 | [diff] [blame] | 87 | void |
| 88 | mm_log_handler(LogLevel level, const char *msg, void *ctx) |
| 89 | { |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 90 | struct sshbuf *log_msg; |
Damien Miller | 8f0bf23 | 2011-06-20 14:42:23 +1000 | [diff] [blame] | 91 | struct monitor *mon = (struct monitor *)ctx; |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 92 | int r; |
| 93 | size_t len; |
Damien Miller | 8f0bf23 | 2011-06-20 14:42:23 +1000 | [diff] [blame] | 94 | |
| 95 | if (mon->m_log_sendfd == -1) |
| 96 | fatal("%s: no log channel", __func__); |
| 97 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 98 | if ((log_msg = sshbuf_new()) == NULL) |
| 99 | fatal("%s: sshbuf_new failed", __func__); |
Damien Miller | 8f0bf23 | 2011-06-20 14:42:23 +1000 | [diff] [blame] | 100 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 101 | if ((r = sshbuf_put_u32(log_msg, 0)) != 0 || /* length; filled below */ |
| 102 | (r = sshbuf_put_u32(log_msg, level)) != 0 || |
| 103 | (r = sshbuf_put_cstring(log_msg, msg)) != 0) |
| 104 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
| 105 | if ((len = sshbuf_len(log_msg)) < 4 || len > 0xffffffff) |
| 106 | fatal("%s: bad length %zu", __func__, len); |
| 107 | POKE_U32(sshbuf_mutable_ptr(log_msg), len - 4); |
| 108 | if (atomicio(vwrite, mon->m_log_sendfd, |
| 109 | sshbuf_mutable_ptr(log_msg), len) != len) |
Damien Miller | 8f0bf23 | 2011-06-20 14:42:23 +1000 | [diff] [blame] | 110 | fatal("%s: write: %s", __func__, strerror(errno)); |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 111 | sshbuf_free(log_msg); |
Damien Miller | 8f0bf23 | 2011-06-20 14:42:23 +1000 | [diff] [blame] | 112 | } |
| 113 | |
Darren Tucker | 3e33cec | 2003-10-02 16:12:36 +1000 | [diff] [blame] | 114 | int |
| 115 | mm_is_monitor(void) |
| 116 | { |
| 117 | /* |
| 118 | * m_pid is only set in the privileged part, and |
| 119 | * points to the unprivileged child. |
| 120 | */ |
Darren Tucker | a47c9bc | 2003-11-03 20:03:25 +1100 | [diff] [blame] | 121 | return (pmonitor && pmonitor->m_pid > 0); |
Darren Tucker | 3e33cec | 2003-10-02 16:12:36 +1000 | [diff] [blame] | 122 | } |
| 123 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 124 | void |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 125 | mm_request_send(int sock, enum monitor_reqtype type, struct sshbuf *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 126 | { |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 127 | size_t mlen = sshbuf_len(m); |
Ben Lindstrom | b1bdc5a | 2002-07-04 00:09:26 +0000 | [diff] [blame] | 128 | u_char buf[5]; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 129 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 130 | debug3("%s entering: type %d", __func__, type); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 131 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 132 | if (mlen >= 0xffffffff) |
| 133 | fatal("%s: bad length %zu", __func__, mlen); |
| 134 | POKE_U32(buf, mlen + 1); |
Ben Lindstrom | cb72e4f | 2002-06-21 00:41:51 +0000 | [diff] [blame] | 135 | buf[4] = (u_char) type; /* 1st byte of payload is mesg-type */ |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 136 | if (atomicio(vwrite, sock, buf, sizeof(buf)) != sizeof(buf)) |
Damien Miller | b253cc4 | 2005-05-26 12:23:44 +1000 | [diff] [blame] | 137 | fatal("%s: write: %s", __func__, strerror(errno)); |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 138 | if (atomicio(vwrite, sock, sshbuf_mutable_ptr(m), mlen) != mlen) |
Damien Miller | b253cc4 | 2005-05-26 12:23:44 +1000 | [diff] [blame] | 139 | fatal("%s: write: %s", __func__, strerror(errno)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | void |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 143 | mm_request_receive(int sock, struct sshbuf *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 144 | { |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 145 | u_char buf[4], *p = NULL; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 146 | u_int msg_len; |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 147 | int r; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 148 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 149 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 150 | |
Damien Miller | b253cc4 | 2005-05-26 12:23:44 +1000 | [diff] [blame] | 151 | if (atomicio(read, sock, buf, sizeof(buf)) != sizeof(buf)) { |
Damien Miller | 4d24b3b | 2015-03-20 09:11:59 +1100 | [diff] [blame] | 152 | if (errno == EPIPE) |
Darren Tucker | 3e33cec | 2003-10-02 16:12:36 +1000 | [diff] [blame] | 153 | cleanup_exit(255); |
Damien Miller | b253cc4 | 2005-05-26 12:23:44 +1000 | [diff] [blame] | 154 | fatal("%s: read: %s", __func__, strerror(errno)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 155 | } |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 156 | msg_len = PEEK_U32(buf); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 157 | if (msg_len > 256 * 1024) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 158 | fatal("%s: read: bad msg_len %d", __func__, msg_len); |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 159 | sshbuf_reset(m); |
| 160 | if ((r = sshbuf_reserve(m, msg_len, &p)) != 0) |
| 161 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
| 162 | if (atomicio(read, sock, p, msg_len) != msg_len) |
Damien Miller | b253cc4 | 2005-05-26 12:23:44 +1000 | [diff] [blame] | 163 | fatal("%s: read: %s", __func__, strerror(errno)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | void |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 167 | mm_request_receive_expect(int sock, enum monitor_reqtype type, struct sshbuf *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 168 | { |
| 169 | u_char rtype; |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 170 | int r; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 171 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 172 | debug3("%s entering: type %d", __func__, type); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 173 | |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 174 | mm_request_receive(sock, m); |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 175 | if ((r = sshbuf_get_u8(m, &rtype)) != 0) |
| 176 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 177 | if (rtype != type) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 178 | fatal("%s: read: rtype %d != type %d", __func__, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 179 | rtype, type); |
| 180 | } |
| 181 | |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 182 | #ifdef WITH_OPENSSL |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 183 | DH * |
| 184 | mm_choose_dh(int min, int nbits, int max) |
| 185 | { |
| 186 | BIGNUM *p, *g; |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 187 | int r; |
| 188 | u_char success = 0; |
| 189 | struct sshbuf *m; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 190 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 191 | if ((m = sshbuf_new()) == NULL) |
| 192 | fatal("%s: sshbuf_new failed", __func__); |
| 193 | if ((r = sshbuf_put_u32(m, min)) != 0 || |
| 194 | (r = sshbuf_put_u32(m, nbits)) != 0 || |
| 195 | (r = sshbuf_put_u32(m, max)) != 0) |
| 196 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 197 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 198 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_MODULI, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 199 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 200 | debug3("%s: waiting for MONITOR_ANS_MODULI", __func__); |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 201 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_MODULI, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 202 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 203 | if ((r = sshbuf_get_u8(m, &success)) != 0) |
| 204 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 205 | if (success == 0) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 206 | fatal("%s: MONITOR_ANS_MODULI failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 207 | |
| 208 | if ((p = BN_new()) == NULL) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 209 | fatal("%s: BN_new failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 210 | if ((g = BN_new()) == NULL) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 211 | fatal("%s: BN_new failed", __func__); |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 212 | if ((r = sshbuf_get_bignum2(m, p)) != 0 || |
| 213 | (r = sshbuf_get_bignum2(m, g)) != 0) |
| 214 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 215 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 216 | debug3("%s: remaining %zu", __func__, sshbuf_len(m)); |
| 217 | sshbuf_free(m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 218 | |
| 219 | return (dh_new_group(g, p)); |
| 220 | } |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 221 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 222 | |
| 223 | int |
markus@openbsd.org | 5467fbc | 2018-07-11 18:53:29 +0000 | [diff] [blame] | 224 | mm_sshkey_sign(struct sshkey *key, u_char **sigp, size_t *lenp, |
| 225 | const u_char *data, size_t datalen, const char *hostkey_alg, u_int compat) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 226 | { |
markus@openbsd.org | 57d10cb | 2015-01-19 20:16:15 +0000 | [diff] [blame] | 227 | struct kex *kex = *pmonitor->m_pkex; |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 228 | struct sshbuf *m; |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 229 | u_int ndx = kex->host_key_index(key, 0, active_state); |
| 230 | int r; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 231 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 232 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 233 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 234 | if ((m = sshbuf_new()) == NULL) |
| 235 | fatal("%s: sshbuf_new failed", __func__); |
| 236 | if ((r = sshbuf_put_u32(m, ndx)) != 0 || |
| 237 | (r = sshbuf_put_string(m, data, datalen)) != 0 || |
markus@openbsd.org | 5467fbc | 2018-07-11 18:53:29 +0000 | [diff] [blame] | 238 | (r = sshbuf_put_cstring(m, hostkey_alg)) != 0 || |
| 239 | (r = sshbuf_put_u32(m, compat)) != 0) |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 240 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 241 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 242 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_SIGN, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 243 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 244 | debug3("%s: waiting for MONITOR_ANS_SIGN", __func__); |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 245 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_SIGN, m); |
markus@openbsd.org | 5467fbc | 2018-07-11 18:53:29 +0000 | [diff] [blame] | 246 | if ((r = sshbuf_get_string(m, sigp, lenp)) != 0) |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 247 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 248 | sshbuf_free(m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 249 | |
| 250 | return (0); |
| 251 | } |
| 252 | |
| 253 | struct passwd * |
Darren Tucker | b09b677 | 2004-06-22 15:06:46 +1000 | [diff] [blame] | 254 | mm_getpwnamallow(const char *username) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 255 | { |
djm@openbsd.org | dbee411 | 2017-09-12 06:32:07 +0000 | [diff] [blame] | 256 | struct ssh *ssh = active_state; /* XXX */ |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 257 | struct sshbuf *m; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 258 | struct passwd *pw; |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 259 | size_t len; |
| 260 | u_int i; |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 261 | ServerOptions *newopts; |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 262 | int r; |
| 263 | u_char ok; |
| 264 | const u_char *p; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 265 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 266 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 267 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 268 | if ((m = sshbuf_new()) == NULL) |
| 269 | fatal("%s: sshbuf_new failed", __func__); |
| 270 | if ((r = sshbuf_put_cstring(m, username)) != 0) |
| 271 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 272 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 273 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PWNAM, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 274 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 275 | debug3("%s: waiting for MONITOR_ANS_PWNAM", __func__); |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 276 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PWNAM, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 277 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 278 | if ((r = sshbuf_get_u8(m, &ok)) != 0) |
| 279 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
| 280 | if (ok == 0) { |
Darren Tucker | 2f8b3d9 | 2007-12-02 23:02:15 +1100 | [diff] [blame] | 281 | pw = NULL; |
| 282 | goto out; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 283 | } |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 284 | |
| 285 | /* XXX don't like passing struct passwd like this */ |
| 286 | pw = xcalloc(sizeof(*pw), 1); |
| 287 | if ((r = sshbuf_get_string_direct(m, &p, &len)) != 0) |
| 288 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
| 289 | if (len != sizeof(*pw)) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 290 | fatal("%s: struct passwd size mismatch", __func__); |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 291 | memcpy(pw, p, sizeof(*pw)); |
| 292 | |
| 293 | if ((r = sshbuf_get_cstring(m, &pw->pw_name, NULL)) != 0 || |
| 294 | (r = sshbuf_get_cstring(m, &pw->pw_passwd, NULL)) != 0 || |
Damien Miller | 6332da2 | 2013-04-23 14:25:52 +1000 | [diff] [blame] | 295 | #ifdef HAVE_STRUCT_PASSWD_PW_GECOS |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 296 | (r = sshbuf_get_cstring(m, &pw->pw_gecos, NULL)) != 0 || |
Damien Miller | 6332da2 | 2013-04-23 14:25:52 +1000 | [diff] [blame] | 297 | #endif |
| 298 | #ifdef HAVE_STRUCT_PASSWD_PW_CLASS |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 299 | (r = sshbuf_get_cstring(m, &pw->pw_class, NULL)) != 0 || |
Kevin Steves | 7e14760 | 2002-03-22 18:07:17 +0000 | [diff] [blame] | 300 | #endif |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 301 | (r = sshbuf_get_cstring(m, &pw->pw_dir, NULL)) != 0 || |
| 302 | (r = sshbuf_get_cstring(m, &pw->pw_shell, NULL)) != 0) |
| 303 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 304 | |
Darren Tucker | 2f8b3d9 | 2007-12-02 23:02:15 +1100 | [diff] [blame] | 305 | out: |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 306 | /* copy options block as a Match directive may have changed some */ |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 307 | if ((r = sshbuf_get_string_direct(m, &p, &len)) != 0) |
| 308 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 309 | if (len != sizeof(*newopts)) |
| 310 | fatal("%s: option block size mismatch", __func__); |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 311 | newopts = xcalloc(sizeof(*newopts), 1); |
| 312 | memcpy(newopts, p, sizeof(*newopts)); |
Damien Miller | f2e407e | 2011-05-20 19:04:14 +1000 | [diff] [blame] | 313 | |
| 314 | #define M_CP_STROPT(x) do { \ |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 315 | if (newopts->x != NULL) { \ |
| 316 | if ((r = sshbuf_get_cstring(m, \ |
| 317 | &newopts->x, NULL)) != 0) \ |
| 318 | fatal("%s: buffer error: %s", \ |
| 319 | __func__, ssh_err(r)); \ |
| 320 | } \ |
Damien Miller | f2e407e | 2011-05-20 19:04:14 +1000 | [diff] [blame] | 321 | } while (0) |
Damien Miller | d8478b6 | 2011-05-29 21:39:36 +1000 | [diff] [blame] | 322 | #define M_CP_STRARRAYOPT(x, nx) do { \ |
djm@openbsd.org | 66bf74a | 2017-10-02 19:33:20 +0000 | [diff] [blame] | 323 | newopts->x = newopts->nx == 0 ? \ |
| 324 | NULL : xcalloc(newopts->nx, sizeof(*newopts->x)); \ |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 325 | for (i = 0; i < newopts->nx; i++) { \ |
| 326 | if ((r = sshbuf_get_cstring(m, \ |
| 327 | &newopts->x[i], NULL)) != 0) \ |
| 328 | fatal("%s: buffer error: %s", \ |
| 329 | __func__, ssh_err(r)); \ |
| 330 | } \ |
djm@openbsd.org | 66bf74a | 2017-10-02 19:33:20 +0000 | [diff] [blame] | 331 | } while (0) |
Damien Miller | f2e407e | 2011-05-20 19:04:14 +1000 | [diff] [blame] | 332 | /* See comment in servconf.h */ |
| 333 | COPY_MATCH_STRING_OPTS(); |
| 334 | #undef M_CP_STROPT |
Damien Miller | d8478b6 | 2011-05-29 21:39:36 +1000 | [diff] [blame] | 335 | #undef M_CP_STRARRAYOPT |
Damien Miller | f2e407e | 2011-05-20 19:04:14 +1000 | [diff] [blame] | 336 | |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 337 | copy_set_server_options(&options, newopts, 1); |
djm@openbsd.org | 54cd41a | 2017-05-17 01:24:17 +0000 | [diff] [blame] | 338 | log_change_level(options.log_level); |
djm@openbsd.org | dbee411 | 2017-09-12 06:32:07 +0000 | [diff] [blame] | 339 | process_permitopen(ssh, &options); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 340 | free(newopts); |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 341 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 342 | sshbuf_free(m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 343 | |
| 344 | return (pw); |
| 345 | } |
| 346 | |
Darren Tucker | 7eb3de0 | 2003-10-15 15:56:58 +1000 | [diff] [blame] | 347 | char * |
| 348 | mm_auth2_read_banner(void) |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 349 | { |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 350 | struct sshbuf *m; |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 351 | char *banner; |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 352 | int r; |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 353 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 354 | debug3("%s entering", __func__); |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 355 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 356 | if ((m = sshbuf_new()) == NULL) |
| 357 | fatal("%s: sshbuf_new failed", __func__); |
| 358 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTH2_READ_BANNER, m); |
| 359 | sshbuf_reset(m); |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 360 | |
Darren Tucker | 7eb3de0 | 2003-10-15 15:56:58 +1000 | [diff] [blame] | 361 | mm_request_receive_expect(pmonitor->m_recvfd, |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 362 | MONITOR_ANS_AUTH2_READ_BANNER, m); |
| 363 | if ((r = sshbuf_get_cstring(m, &banner, NULL)) != 0) |
| 364 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
| 365 | sshbuf_free(m); |
Ben Lindstrom | cb72e4f | 2002-06-21 00:41:51 +0000 | [diff] [blame] | 366 | |
Darren Tucker | 7eb3de0 | 2003-10-15 15:56:58 +1000 | [diff] [blame] | 367 | /* treat empty banner as missing banner */ |
| 368 | if (strlen(banner) == 0) { |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 369 | free(banner); |
Darren Tucker | 7eb3de0 | 2003-10-15 15:56:58 +1000 | [diff] [blame] | 370 | banner = NULL; |
| 371 | } |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 372 | return (banner); |
| 373 | } |
| 374 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 375 | /* Inform the privileged process about service and style */ |
| 376 | |
| 377 | void |
| 378 | mm_inform_authserv(char *service, char *style) |
| 379 | { |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 380 | struct sshbuf *m; |
| 381 | int r; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 382 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 383 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 384 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 385 | if ((m = sshbuf_new()) == NULL) |
| 386 | fatal("%s: sshbuf_new failed", __func__); |
| 387 | if ((r = sshbuf_put_cstring(m, service)) != 0 || |
| 388 | (r = sshbuf_put_cstring(m, style ? style : "")) != 0) |
| 389 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 390 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 391 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHSERV, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 392 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 393 | sshbuf_free(m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | /* Do the password authentication */ |
| 397 | int |
djm@openbsd.org | 7c85685 | 2018-03-03 03:15:51 +0000 | [diff] [blame] | 398 | mm_auth_password(struct ssh *ssh, char *password) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 399 | { |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 400 | struct sshbuf *m; |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 401 | int r, authenticated = 0; |
| 402 | #ifdef USE_PAM |
| 403 | u_int maxtries = 0; |
| 404 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 405 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 406 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 407 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 408 | if ((m = sshbuf_new()) == NULL) |
| 409 | fatal("%s: sshbuf_new failed", __func__); |
| 410 | if ((r = sshbuf_put_cstring(m, password)) != 0) |
| 411 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
| 412 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHPASSWORD, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 413 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 414 | debug3("%s: waiting for MONITOR_ANS_AUTHPASSWORD", __func__); |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 415 | mm_request_receive_expect(pmonitor->m_recvfd, |
| 416 | MONITOR_ANS_AUTHPASSWORD, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 417 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 418 | if ((r = sshbuf_get_u32(m, &authenticated)) != 0) |
| 419 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
Darren Tucker | 01558b7 | 2016-07-18 09:33:25 +1000 | [diff] [blame] | 420 | #ifdef USE_PAM |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 421 | if ((r = sshbuf_get_u32(m, &maxtries)) != 0) |
| 422 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 423 | if (maxtries > INT_MAX) |
| 424 | fatal("%s: bad maxtries %u", __func__, maxtries); |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 425 | sshpam_set_maxtries_reached(maxtries); |
Darren Tucker | 01558b7 | 2016-07-18 09:33:25 +1000 | [diff] [blame] | 426 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 427 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 428 | sshbuf_free(m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 429 | |
| 430 | debug3("%s: user %sauthenticated", |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 431 | __func__, authenticated ? "" : "not "); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 432 | return (authenticated); |
| 433 | } |
| 434 | |
| 435 | int |
djm@openbsd.org | 7c85685 | 2018-03-03 03:15:51 +0000 | [diff] [blame] | 436 | mm_user_key_allowed(struct ssh *ssh, struct passwd *pw, struct sshkey *key, |
| 437 | int pubkey_auth_attempt, struct sshauthopt **authoptp) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 438 | { |
djm@openbsd.org | 179be0f | 2015-05-01 03:23:51 +0000 | [diff] [blame] | 439 | return (mm_key_allowed(MM_USERKEY, NULL, NULL, key, |
djm@openbsd.org | 7c85685 | 2018-03-03 03:15:51 +0000 | [diff] [blame] | 440 | pubkey_auth_attempt, authoptp)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | int |
djm@openbsd.org | 9576726 | 2016-03-07 19:02:43 +0000 | [diff] [blame] | 444 | mm_hostbased_key_allowed(struct passwd *pw, const char *user, const char *host, |
markus@openbsd.org | 54d90ac | 2017-05-30 08:52:19 +0000 | [diff] [blame] | 445 | struct sshkey *key) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 446 | { |
djm@openbsd.org | 7c85685 | 2018-03-03 03:15:51 +0000 | [diff] [blame] | 447 | return (mm_key_allowed(MM_HOSTKEY, user, host, key, 0, NULL)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | int |
djm@openbsd.org | 9576726 | 2016-03-07 19:02:43 +0000 | [diff] [blame] | 451 | mm_key_allowed(enum mm_keytype type, const char *user, const char *host, |
djm@openbsd.org | 7c85685 | 2018-03-03 03:15:51 +0000 | [diff] [blame] | 452 | struct sshkey *key, int pubkey_auth_attempt, struct sshauthopt **authoptp) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 453 | { |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 454 | struct sshbuf *m; |
djm@openbsd.org | 7c85685 | 2018-03-03 03:15:51 +0000 | [diff] [blame] | 455 | int r, allowed = 0; |
| 456 | struct sshauthopt *opts = NULL; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 457 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 458 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 459 | |
djm@openbsd.org | 7c85685 | 2018-03-03 03:15:51 +0000 | [diff] [blame] | 460 | if (authoptp != NULL) |
| 461 | *authoptp = NULL; |
| 462 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 463 | if ((m = sshbuf_new()) == NULL) |
| 464 | fatal("%s: sshbuf_new failed", __func__); |
| 465 | if ((r = sshbuf_put_u32(m, type)) != 0 || |
| 466 | (r = sshbuf_put_cstring(m, user ? user : "")) != 0 || |
| 467 | (r = sshbuf_put_cstring(m, host ? host : "")) != 0 || |
| 468 | (r = sshkey_puts(key, m)) != 0 || |
| 469 | (r = sshbuf_put_u32(m, pubkey_auth_attempt)) != 0) |
| 470 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 471 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 472 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_KEYALLOWED, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 473 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 474 | debug3("%s: waiting for MONITOR_ANS_KEYALLOWED", __func__); |
djm@openbsd.org | 7c85685 | 2018-03-03 03:15:51 +0000 | [diff] [blame] | 475 | mm_request_receive_expect(pmonitor->m_recvfd, |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 476 | MONITOR_ANS_KEYALLOWED, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 477 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 478 | if ((r = sshbuf_get_u32(m, &allowed)) != 0) |
| 479 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
djm@openbsd.org | 7c85685 | 2018-03-03 03:15:51 +0000 | [diff] [blame] | 480 | if (allowed && type == MM_USERKEY) { |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 481 | if ((r = sshauthopt_deserialise(m, &opts)) != 0) |
djm@openbsd.org | 7c85685 | 2018-03-03 03:15:51 +0000 | [diff] [blame] | 482 | fatal("%s: sshauthopt_deserialise: %s", |
| 483 | __func__, ssh_err(r)); |
| 484 | } |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 485 | sshbuf_free(m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 486 | |
djm@openbsd.org | 7c85685 | 2018-03-03 03:15:51 +0000 | [diff] [blame] | 487 | if (authoptp != NULL) { |
| 488 | *authoptp = opts; |
| 489 | opts = NULL; |
| 490 | } |
| 491 | sshauthopt_free(opts); |
| 492 | |
| 493 | return allowed; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | /* |
| 497 | * This key verify needs to send the key type along, because the |
| 498 | * privileged parent makes the decision if the key is allowed |
| 499 | * for authentication. |
| 500 | */ |
| 501 | |
| 502 | int |
markus@openbsd.org | 00ed75c | 2017-05-30 14:10:53 +0000 | [diff] [blame] | 503 | mm_sshkey_verify(const struct sshkey *key, const u_char *sig, size_t siglen, |
djm@openbsd.org | 04c7e28 | 2017-12-18 02:25:15 +0000 | [diff] [blame] | 504 | const u_char *data, size_t datalen, const char *sigalg, u_int compat) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 505 | { |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 506 | struct sshbuf *m; |
markus@openbsd.org | 00ed75c | 2017-05-30 14:10:53 +0000 | [diff] [blame] | 507 | u_int encoded_ret = 0; |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 508 | int r; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 509 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 510 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 511 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 512 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 513 | if ((m = sshbuf_new()) == NULL) |
| 514 | fatal("%s: sshbuf_new failed", __func__); |
| 515 | if ((r = sshkey_puts(key, m)) != 0 || |
| 516 | (r = sshbuf_put_string(m, sig, siglen)) != 0 || |
| 517 | (r = sshbuf_put_string(m, data, datalen)) != 0 || |
| 518 | (r = sshbuf_put_cstring(m, sigalg == NULL ? "" : sigalg)) != 0) |
| 519 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 520 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 521 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_KEYVERIFY, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 522 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 523 | debug3("%s: waiting for MONITOR_ANS_KEYVERIFY", __func__); |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 524 | mm_request_receive_expect(pmonitor->m_recvfd, |
| 525 | MONITOR_ANS_KEYVERIFY, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 526 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 527 | if ((r = sshbuf_get_u32(m, &encoded_ret)) != 0) |
| 528 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 529 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 530 | sshbuf_free(m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 531 | |
markus@openbsd.org | 00ed75c | 2017-05-30 14:10:53 +0000 | [diff] [blame] | 532 | if (encoded_ret != 0) |
| 533 | return SSH_ERR_SIGNATURE_INVALID; |
| 534 | return 0; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 535 | } |
| 536 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 537 | void |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 538 | mm_send_keystate(struct monitor *monitor) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 539 | { |
markus@openbsd.org | 091c302 | 2015-01-19 19:52:16 +0000 | [diff] [blame] | 540 | struct ssh *ssh = active_state; /* XXX */ |
| 541 | struct sshbuf *m; |
| 542 | int r; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 543 | |
markus@openbsd.org | 091c302 | 2015-01-19 19:52:16 +0000 | [diff] [blame] | 544 | if ((m = sshbuf_new()) == NULL) |
| 545 | fatal("%s: sshbuf_new failed", __func__); |
| 546 | if ((r = ssh_packet_get_state(ssh, m)) != 0) |
| 547 | fatal("%s: get_state failed: %s", |
| 548 | __func__, ssh_err(r)); |
| 549 | mm_request_send(monitor->m_recvfd, MONITOR_REQ_KEYEXPORT, m); |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 550 | debug3("%s: Finished sending state", __func__); |
markus@openbsd.org | 091c302 | 2015-01-19 19:52:16 +0000 | [diff] [blame] | 551 | sshbuf_free(m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | int |
Damien Miller | 71a7367 | 2006-03-26 14:04:36 +1100 | [diff] [blame] | 555 | mm_pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, size_t namebuflen) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 556 | { |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 557 | struct sshbuf *m; |
Darren Tucker | 0999174 | 2004-07-17 17:05:14 +1000 | [diff] [blame] | 558 | char *p, *msg; |
markus@openbsd.org | 2808d18 | 2018-07-09 21:26:02 +0000 | [diff] [blame] | 559 | int success = 0, tmp1 = -1, tmp2 = -1, r; |
Damien Miller | 7207f64 | 2008-05-19 15:34:50 +1000 | [diff] [blame] | 560 | |
| 561 | /* Kludge: ensure there are fds free to receive the pty/tty */ |
| 562 | if ((tmp1 = dup(pmonitor->m_recvfd)) == -1 || |
| 563 | (tmp2 = dup(pmonitor->m_recvfd)) == -1) { |
| 564 | error("%s: cannot allocate fds for pty", __func__); |
| 565 | if (tmp1 > 0) |
| 566 | close(tmp1); |
| 567 | if (tmp2 > 0) |
| 568 | close(tmp2); |
| 569 | return 0; |
| 570 | } |
| 571 | close(tmp1); |
| 572 | close(tmp2); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 573 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 574 | if ((m = sshbuf_new()) == NULL) |
| 575 | fatal("%s: sshbuf_new failed", __func__); |
| 576 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PTY, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 577 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 578 | debug3("%s: waiting for MONITOR_ANS_PTY", __func__); |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 579 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PTY, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 580 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 581 | if ((r = sshbuf_get_u32(m, &success)) != 0) |
| 582 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 583 | if (success == 0) { |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 584 | debug3("%s: pty alloc failed", __func__); |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 585 | sshbuf_free(m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 586 | return (0); |
| 587 | } |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 588 | if ((r = sshbuf_get_cstring(m, &p, NULL)) != 0 || |
| 589 | (r = sshbuf_get_cstring(m, &msg, NULL)) != 0) |
| 590 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
| 591 | sshbuf_free(m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 592 | |
| 593 | strlcpy(namebuf, p, namebuflen); /* Possible truncation */ |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 594 | free(p); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 595 | |
markus@openbsd.org | 2808d18 | 2018-07-09 21:26:02 +0000 | [diff] [blame] | 596 | if ((r = sshbuf_put(loginmsg, msg, strlen(msg))) != 0) |
| 597 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 598 | free(msg); |
Darren Tucker | 0999174 | 2004-07-17 17:05:14 +1000 | [diff] [blame] | 599 | |
Damien Miller | 54fd7cf | 2007-09-17 12:04:08 +1000 | [diff] [blame] | 600 | if ((*ptyfd = mm_receive_fd(pmonitor->m_recvfd)) == -1 || |
| 601 | (*ttyfd = mm_receive_fd(pmonitor->m_recvfd)) == -1) |
| 602 | fatal("%s: receive fds failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 603 | |
| 604 | /* Success */ |
| 605 | return (1); |
| 606 | } |
| 607 | |
| 608 | void |
Darren Tucker | 3e33cec | 2003-10-02 16:12:36 +1000 | [diff] [blame] | 609 | mm_session_pty_cleanup2(Session *s) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 610 | { |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 611 | struct sshbuf *m; |
| 612 | int r; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 613 | |
| 614 | if (s->ttyfd == -1) |
| 615 | return; |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 616 | if ((m = sshbuf_new()) == NULL) |
| 617 | fatal("%s: sshbuf_new failed", __func__); |
| 618 | if ((r = sshbuf_put_cstring(m, s->tty)) != 0) |
| 619 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
| 620 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PTYCLEANUP, m); |
| 621 | sshbuf_free(m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 622 | |
| 623 | /* closed dup'ed master */ |
Damien Miller | 7207f64 | 2008-05-19 15:34:50 +1000 | [diff] [blame] | 624 | if (s->ptymaster != -1 && close(s->ptymaster) < 0) |
| 625 | error("close(s->ptymaster/%d): %s", |
| 626 | s->ptymaster, strerror(errno)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 627 | |
| 628 | /* unlink pty from session */ |
| 629 | s->ttyfd = -1; |
| 630 | } |
| 631 | |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 632 | #ifdef USE_PAM |
| 633 | void |
Darren Tucker | dbf7a74 | 2004-03-08 23:04:06 +1100 | [diff] [blame] | 634 | mm_start_pam(Authctxt *authctxt) |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 635 | { |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 636 | struct sshbuf *m; |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 637 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 638 | debug3("%s entering", __func__); |
Damien Miller | 4e448a3 | 2003-05-14 15:11:48 +1000 | [diff] [blame] | 639 | if (!options.use_pam) |
| 640 | fatal("UsePAM=no, but ended up in %s anyway", __func__); |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 641 | if ((m = sshbuf_new()) == NULL) |
| 642 | fatal("%s: sshbuf_new failed", __func__); |
| 643 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_START, m); |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 644 | |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 645 | sshbuf_free(m); |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 646 | } |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 647 | |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 648 | u_int |
| 649 | mm_do_pam_account(void) |
| 650 | { |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 651 | struct sshbuf *m; |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 652 | u_int ret; |
Darren Tucker | 77fc29e | 2004-09-11 23:07:03 +1000 | [diff] [blame] | 653 | char *msg; |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 654 | size_t msglen; |
| 655 | int r; |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 656 | |
| 657 | debug3("%s entering", __func__); |
| 658 | if (!options.use_pam) |
| 659 | fatal("UsePAM=no, but ended up in %s anyway", __func__); |
| 660 | |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 661 | if ((m = sshbuf_new()) == NULL) |
| 662 | fatal("%s: sshbuf_new failed", __func__); |
| 663 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_ACCOUNT, m); |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 664 | |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 665 | mm_request_receive_expect(pmonitor->m_recvfd, |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 666 | MONITOR_ANS_PAM_ACCOUNT, m); |
| 667 | if ((r = sshbuf_get_u32(m, &ret)) != 0 || |
| 668 | (r = sshbuf_get_cstring(m, &msg, &msglen)) != 0 || |
| 669 | (r = sshbuf_put(loginmsg, msg, msglen)) != 0) |
| 670 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 671 | |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 672 | free(msg); |
| 673 | sshbuf_free(m); |
Damien Miller | 787b2ec | 2003-11-21 23:56:47 +1100 | [diff] [blame] | 674 | |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 675 | debug3("%s returning %d", __func__, ret); |
| 676 | |
| 677 | return (ret); |
| 678 | } |
| 679 | |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 680 | void * |
| 681 | mm_sshpam_init_ctx(Authctxt *authctxt) |
| 682 | { |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 683 | struct sshbuf *m; |
| 684 | int r, success; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 685 | |
| 686 | debug3("%s", __func__); |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 687 | if ((m = sshbuf_new()) == NULL) |
| 688 | fatal("%s: sshbuf_new failed", __func__); |
| 689 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_INIT_CTX, m); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 690 | debug3("%s: waiting for MONITOR_ANS_PAM_INIT_CTX", __func__); |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 691 | mm_request_receive_expect(pmonitor->m_recvfd, |
| 692 | MONITOR_ANS_PAM_INIT_CTX, m); |
| 693 | if ((r = sshbuf_get_u32(m, &success)) != 0) |
| 694 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 695 | if (success == 0) { |
| 696 | debug3("%s: pam_init_ctx failed", __func__); |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 697 | sshbuf_free(m); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 698 | return (NULL); |
| 699 | } |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 700 | sshbuf_free(m); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 701 | return (authctxt); |
| 702 | } |
| 703 | |
| 704 | int |
| 705 | mm_sshpam_query(void *ctx, char **name, char **info, |
| 706 | u_int *num, char ***prompts, u_int **echo_on) |
| 707 | { |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 708 | struct sshbuf *m; |
| 709 | u_int i, n; |
| 710 | int r, ret; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 711 | |
| 712 | debug3("%s", __func__); |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 713 | if ((m = sshbuf_new()) == NULL) |
| 714 | fatal("%s: sshbuf_new failed", __func__); |
| 715 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_QUERY, m); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 716 | debug3("%s: waiting for MONITOR_ANS_PAM_QUERY", __func__); |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 717 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PAM_QUERY, m); |
| 718 | if ((r = sshbuf_get_u32(m, &ret)) != 0 || |
| 719 | (r = sshbuf_get_cstring(m, name, NULL)) != 0 || |
| 720 | (r = sshbuf_get_cstring(m, info, NULL)) != 0 || |
| 721 | (r = sshbuf_get_u32(m, &n)) != 0 || |
| 722 | (r = sshbuf_get_u32(m, num)) != 0) |
| 723 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 724 | debug3("%s: pam_query returned %d", __func__, ret); |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 725 | sshpam_set_maxtries_reached(n); |
Darren Tucker | d8093e4 | 2006-05-04 16:24:34 +1000 | [diff] [blame] | 726 | if (*num > PAM_MAX_NUM_MSG) |
Damien Miller | 10479cc | 2018-04-10 10:19:02 +1000 | [diff] [blame] | 727 | fatal("%s: received %u PAM messages, expected <= %u", |
Darren Tucker | d8093e4 | 2006-05-04 16:24:34 +1000 | [diff] [blame] | 728 | __func__, *num, PAM_MAX_NUM_MSG); |
| 729 | *prompts = xcalloc((*num + 1), sizeof(char *)); |
| 730 | *echo_on = xcalloc((*num + 1), sizeof(u_int)); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 731 | for (i = 0; i < *num; ++i) { |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 732 | if ((r = sshbuf_get_cstring(m, &((*prompts)[i]), NULL)) != 0 || |
| 733 | (r = sshbuf_get_u32(m, &((*echo_on)[i]))) != 0) |
| 734 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 735 | } |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 736 | sshbuf_free(m); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 737 | return (ret); |
| 738 | } |
| 739 | |
| 740 | int |
| 741 | mm_sshpam_respond(void *ctx, u_int num, char **resp) |
| 742 | { |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 743 | struct sshbuf *m; |
| 744 | u_int n, i; |
| 745 | int r, ret; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 746 | |
| 747 | debug3("%s", __func__); |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 748 | if ((m = sshbuf_new()) == NULL) |
| 749 | fatal("%s: sshbuf_new failed", __func__); |
| 750 | if ((r = sshbuf_put_u32(m, num)) != 0) |
| 751 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
| 752 | for (i = 0; i < num; ++i) { |
| 753 | if ((r = sshbuf_put_cstring(m, resp[i])) != 0) |
| 754 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
| 755 | } |
| 756 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_RESPOND, m); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 757 | debug3("%s: waiting for MONITOR_ANS_PAM_RESPOND", __func__); |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 758 | mm_request_receive_expect(pmonitor->m_recvfd, |
| 759 | MONITOR_ANS_PAM_RESPOND, m); |
| 760 | if ((r = sshbuf_get_u32(m, &n)) != 0) |
| 761 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
| 762 | ret = (int)n; /* XXX */ |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 763 | debug3("%s: pam_respond returned %d", __func__, ret); |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 764 | sshbuf_free(m); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 765 | return (ret); |
| 766 | } |
| 767 | |
| 768 | void |
| 769 | mm_sshpam_free_ctx(void *ctxtp) |
| 770 | { |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 771 | struct sshbuf *m; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 772 | |
| 773 | debug3("%s", __func__); |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 774 | if ((m = sshbuf_new()) == NULL) |
| 775 | fatal("%s: sshbuf_new failed", __func__); |
| 776 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_FREE_CTX, m); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 777 | debug3("%s: waiting for MONITOR_ANS_PAM_FREE_CTX", __func__); |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 778 | mm_request_receive_expect(pmonitor->m_recvfd, |
| 779 | MONITOR_ANS_PAM_FREE_CTX, m); |
| 780 | sshbuf_free(m); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 781 | } |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 782 | #endif /* USE_PAM */ |
| 783 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 784 | /* Request process termination */ |
| 785 | |
| 786 | void |
| 787 | mm_terminate(void) |
| 788 | { |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 789 | struct sshbuf *m; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 790 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 791 | if ((m = sshbuf_new()) == NULL) |
| 792 | fatal("%s: sshbuf_new failed", __func__); |
| 793 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_TERM, m); |
| 794 | sshbuf_free(m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 795 | } |
| 796 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 797 | static void |
| 798 | mm_chall_setup(char **name, char **infotxt, u_int *numprompts, |
| 799 | char ***prompts, u_int **echo_on) |
| 800 | { |
Ben Lindstrom | cb72e4f | 2002-06-21 00:41:51 +0000 | [diff] [blame] | 801 | *name = xstrdup(""); |
| 802 | *infotxt = xstrdup(""); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 803 | *numprompts = 1; |
Damien Miller | 07d86be | 2006-03-26 14:19:21 +1100 | [diff] [blame] | 804 | *prompts = xcalloc(*numprompts, sizeof(char *)); |
| 805 | *echo_on = xcalloc(*numprompts, sizeof(u_int)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 806 | (*echo_on)[0] = 0; |
| 807 | } |
| 808 | |
| 809 | int |
| 810 | mm_bsdauth_query(void *ctx, char **name, char **infotxt, |
| 811 | u_int *numprompts, char ***prompts, u_int **echo_on) |
| 812 | { |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 813 | struct sshbuf *m; |
Damien Miller | b7df3af | 2003-02-24 11:55:46 +1100 | [diff] [blame] | 814 | u_int success; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 815 | char *challenge; |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 816 | int r; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 817 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 818 | debug3("%s: entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 819 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 820 | if ((m = sshbuf_new()) == NULL) |
| 821 | fatal("%s: sshbuf_new failed", __func__); |
| 822 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_BSDAUTHQUERY, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 823 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 824 | mm_request_receive_expect(pmonitor->m_recvfd, |
| 825 | MONITOR_ANS_BSDAUTHQUERY, m); |
| 826 | if ((r = sshbuf_get_u32(m, &success)) != 0) |
| 827 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
Damien Miller | b7df3af | 2003-02-24 11:55:46 +1100 | [diff] [blame] | 828 | if (success == 0) { |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 829 | debug3("%s: no challenge", __func__); |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 830 | sshbuf_free(m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 831 | return (-1); |
| 832 | } |
| 833 | |
| 834 | /* Get the challenge, and format the response */ |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 835 | if ((r = sshbuf_get_cstring(m, &challenge, NULL)) != 0) |
| 836 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
| 837 | sshbuf_free(m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 838 | |
| 839 | mm_chall_setup(name, infotxt, numprompts, prompts, echo_on); |
| 840 | (*prompts)[0] = challenge; |
| 841 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 842 | debug3("%s: received challenge: %s", __func__, challenge); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 843 | |
| 844 | return (0); |
| 845 | } |
| 846 | |
| 847 | int |
| 848 | mm_bsdauth_respond(void *ctx, u_int numresponses, char **responses) |
| 849 | { |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 850 | struct sshbuf *m; |
| 851 | int r, authok; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 852 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 853 | debug3("%s: entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 854 | if (numresponses != 1) |
| 855 | return (-1); |
| 856 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 857 | if ((m = sshbuf_new()) == NULL) |
| 858 | fatal("%s: sshbuf_new failed", __func__); |
| 859 | if ((r = sshbuf_put_cstring(m, responses[0])) != 0) |
| 860 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
| 861 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_BSDAUTHRESPOND, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 862 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 863 | mm_request_receive_expect(pmonitor->m_recvfd, |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 864 | MONITOR_ANS_BSDAUTHRESPOND, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 865 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 866 | if ((r = sshbuf_get_u32(m, &authok)) != 0) |
| 867 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
| 868 | sshbuf_free(m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 869 | |
| 870 | return ((authok == 0) ? -1 : 0); |
| 871 | } |
| 872 | |
Darren Tucker | 2e0cf0d | 2005-02-08 21:52:47 +1100 | [diff] [blame] | 873 | #ifdef SSH_AUDIT_EVENTS |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 874 | void |
| 875 | mm_audit_event(ssh_audit_event_t event) |
| 876 | { |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 877 | struct sshbuf *m; |
Darren Tucker | 1dd32c2 | 2018-07-13 13:38:10 +1000 | [diff] [blame] | 878 | int r; |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 879 | |
| 880 | debug3("%s entering", __func__); |
| 881 | |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 882 | if ((m = sshbuf_new()) == NULL) |
Darren Tucker | 1dd32c2 | 2018-07-13 13:38:10 +1000 | [diff] [blame] | 883 | fatal("%s: sshbuf_new failed", __func__); |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 884 | if ((r = sshbuf_put_u32(m, event)) != 0) |
| 885 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 886 | |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 887 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_EVENT, m); |
| 888 | sshbuf_free(m); |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | void |
| 892 | mm_audit_run_command(const char *command) |
| 893 | { |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 894 | struct sshbuf *m; |
Darren Tucker | 1dd32c2 | 2018-07-13 13:38:10 +1000 | [diff] [blame] | 895 | int r; |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 896 | |
| 897 | debug3("%s entering command %s", __func__, command); |
| 898 | |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 899 | if ((m = sshbuf_new()) == NULL) |
Darren Tucker | 1dd32c2 | 2018-07-13 13:38:10 +1000 | [diff] [blame] | 900 | fatal("%s: sshbuf_new failed", __func__); |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 901 | if ((r = sshbuf_put_cstring(m, command)) != 0) |
| 902 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 903 | |
Damien Miller | 120a1ec | 2018-07-10 19:39:52 +1000 | [diff] [blame] | 904 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_COMMAND, m); |
| 905 | sshbuf_free(m); |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 906 | } |
Darren Tucker | 2e0cf0d | 2005-02-08 21:52:47 +1100 | [diff] [blame] | 907 | #endif /* SSH_AUDIT_EVENTS */ |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 908 | |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 909 | #ifdef GSSAPI |
| 910 | OM_uint32 |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 911 | mm_ssh_gssapi_server_ctx(Gssctxt **ctx, gss_OID goid) |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 912 | { |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 913 | struct sshbuf *m; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 914 | OM_uint32 major; |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 915 | int r; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 916 | |
| 917 | /* Client doesn't get to see the context */ |
| 918 | *ctx = NULL; |
| 919 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 920 | if ((m = sshbuf_new()) == NULL) |
| 921 | fatal("%s: sshbuf_new failed", __func__); |
| 922 | if ((r = sshbuf_put_string(m, goid->elements, goid->length)) != 0) |
| 923 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 924 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 925 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSSETUP, m); |
| 926 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSSETUP, m); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 927 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 928 | if ((r = sshbuf_get_u32(m, &major)) != 0) |
| 929 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 930 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 931 | sshbuf_free(m); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 932 | return (major); |
| 933 | } |
| 934 | |
| 935 | OM_uint32 |
| 936 | mm_ssh_gssapi_accept_ctx(Gssctxt *ctx, gss_buffer_desc *in, |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 937 | gss_buffer_desc *out, OM_uint32 *flagsp) |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 938 | { |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 939 | struct sshbuf *m; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 940 | OM_uint32 major; |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 941 | u_int flags; |
| 942 | int r; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 943 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 944 | if ((m = sshbuf_new()) == NULL) |
| 945 | fatal("%s: sshbuf_new failed", __func__); |
| 946 | if ((r = sshbuf_put_string(m, in->value, in->length)) != 0) |
| 947 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 948 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 949 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSSTEP, m); |
| 950 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSSTEP, m); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 951 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 952 | if ((r = sshbuf_get_u32(m, &major)) != 0 || |
djm@openbsd.org | 0f3958c | 2018-07-10 09:13:30 +0000 | [diff] [blame] | 953 | (r = ssh_gssapi_get_buffer_desc(m, out)) != 0) |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 954 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
| 955 | if (flagsp != NULL) { |
| 956 | if ((r = sshbuf_get_u32(m, &flags)) != 0) |
| 957 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
| 958 | *flagsp = flags; |
| 959 | } |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 960 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 961 | sshbuf_free(m); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 962 | |
| 963 | return (major); |
| 964 | } |
| 965 | |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 966 | OM_uint32 |
| 967 | mm_ssh_gssapi_checkmic(Gssctxt *ctx, gss_buffer_t gssbuf, gss_buffer_t gssmic) |
| 968 | { |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 969 | struct sshbuf *m; |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 970 | OM_uint32 major; |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 971 | int r; |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 972 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 973 | if ((m = sshbuf_new()) == NULL) |
| 974 | fatal("%s: sshbuf_new failed", __func__); |
| 975 | if ((r = sshbuf_put_string(m, gssbuf->value, gssbuf->length)) != 0 || |
| 976 | (r = sshbuf_put_string(m, gssmic->value, gssmic->length)) != 0) |
| 977 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 978 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 979 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSCHECKMIC, m); |
| 980 | mm_request_receive_expect(pmonitor->m_recvfd, |
| 981 | MONITOR_ANS_GSSCHECKMIC, m); |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 982 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 983 | if ((r = sshbuf_get_u32(m, &major)) != 0) |
| 984 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
| 985 | sshbuf_free(m); |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 986 | return(major); |
| 987 | } |
| 988 | |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 989 | int |
| 990 | mm_ssh_gssapi_userok(char *user) |
| 991 | { |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 992 | struct sshbuf *m; |
| 993 | int r, authenticated = 0; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 994 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 995 | if ((m = sshbuf_new()) == NULL) |
| 996 | fatal("%s: sshbuf_new failed", __func__); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 997 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 998 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSUSEROK, m); |
| 999 | mm_request_receive_expect(pmonitor->m_recvfd, |
| 1000 | MONITOR_ANS_GSSUSEROK, m); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1001 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 1002 | if ((r = sshbuf_get_u32(m, &authenticated)) != 0) |
| 1003 | fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1004 | |
markus@openbsd.org | 235c7c4 | 2018-07-09 21:53:45 +0000 | [diff] [blame] | 1005 | sshbuf_free(m); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1006 | debug3("%s: user %sauthenticated",__func__, authenticated ? "" : "not "); |
| 1007 | return (authenticated); |
| 1008 | } |
| 1009 | #endif /* GSSAPI */ |