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