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