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