Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 1 | /* $OpenBSD: monitor_wrap.c,v 1.80 2014/04/29 18:01:49 markus 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 |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 53 | #include "buffer.h" |
| 54 | #include "key.h" |
| 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" |
Ben Lindstrom | 036768e | 2004-04-08 16:12:30 +0000 | [diff] [blame] | 63 | #ifdef TARGET_OS_MAC /* XXX Broken krb5 headers on Mac */ |
| 64 | #undef TARGET_OS_MAC |
Ben Lindstrom | 1b9f2a6 | 2004-04-08 05:11:03 +0000 | [diff] [blame] | 65 | #include "zlib.h" |
Ben Lindstrom | 036768e | 2004-04-08 16:12:30 +0000 | [diff] [blame] | 66 | #define TARGET_OS_MAC 1 |
| 67 | #else |
| 68 | #include "zlib.h" |
| 69 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 70 | #include "monitor.h" |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 71 | #ifdef GSSAPI |
| 72 | #include "ssh-gss.h" |
| 73 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 74 | #include "monitor_wrap.h" |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 75 | #include "atomicio.h" |
| 76 | #include "monitor_fdpass.h" |
Damien Miller | 3f94188 | 2006-03-31 23:13:02 +1100 | [diff] [blame] | 77 | #include "misc.h" |
Damien Miller | eb8b60e | 2010-08-31 22:41:14 +1000 | [diff] [blame] | 78 | #include "uuencode.h" |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 79 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 80 | #include "channels.h" |
| 81 | #include "session.h" |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 82 | #include "servconf.h" |
Darren Tucker | c5564e1 | 2009-06-21 18:53:53 +1000 | [diff] [blame] | 83 | #include "roaming.h" |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 84 | |
| 85 | /* Imports */ |
| 86 | extern int compat20; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 87 | extern z_stream incoming_stream; |
| 88 | extern z_stream outgoing_stream; |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 89 | extern struct monitor *pmonitor; |
Darren Tucker | 0999174 | 2004-07-17 17:05:14 +1000 | [diff] [blame] | 90 | extern Buffer loginmsg; |
Damien Miller | 4e448a3 | 2003-05-14 15:11:48 +1000 | [diff] [blame] | 91 | extern ServerOptions options; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 92 | |
Damien Miller | 8f0bf23 | 2011-06-20 14:42:23 +1000 | [diff] [blame] | 93 | void |
| 94 | mm_log_handler(LogLevel level, const char *msg, void *ctx) |
| 95 | { |
| 96 | Buffer log_msg; |
| 97 | struct monitor *mon = (struct monitor *)ctx; |
| 98 | |
| 99 | if (mon->m_log_sendfd == -1) |
| 100 | fatal("%s: no log channel", __func__); |
| 101 | |
| 102 | buffer_init(&log_msg); |
| 103 | /* |
| 104 | * Placeholder for packet length. Will be filled in with the actual |
| 105 | * packet length once the packet has been constucted. This saves |
| 106 | * fragile math. |
| 107 | */ |
| 108 | buffer_put_int(&log_msg, 0); |
| 109 | |
| 110 | buffer_put_int(&log_msg, level); |
| 111 | buffer_put_cstring(&log_msg, msg); |
| 112 | put_u32(buffer_ptr(&log_msg), buffer_len(&log_msg) - 4); |
| 113 | if (atomicio(vwrite, mon->m_log_sendfd, buffer_ptr(&log_msg), |
| 114 | buffer_len(&log_msg)) != buffer_len(&log_msg)) |
| 115 | fatal("%s: write: %s", __func__, strerror(errno)); |
| 116 | buffer_free(&log_msg); |
| 117 | } |
| 118 | |
Darren Tucker | 3e33cec | 2003-10-02 16:12:36 +1000 | [diff] [blame] | 119 | int |
| 120 | mm_is_monitor(void) |
| 121 | { |
| 122 | /* |
| 123 | * m_pid is only set in the privileged part, and |
| 124 | * points to the unprivileged child. |
| 125 | */ |
Darren Tucker | a47c9bc | 2003-11-03 20:03:25 +1100 | [diff] [blame] | 126 | return (pmonitor && pmonitor->m_pid > 0); |
Darren Tucker | 3e33cec | 2003-10-02 16:12:36 +1000 | [diff] [blame] | 127 | } |
| 128 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 129 | void |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 130 | mm_request_send(int sock, enum monitor_reqtype type, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 131 | { |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 132 | u_int mlen = buffer_len(m); |
Ben Lindstrom | b1bdc5a | 2002-07-04 00:09:26 +0000 | [diff] [blame] | 133 | u_char buf[5]; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 134 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 135 | debug3("%s entering: type %d", __func__, type); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 136 | |
Damien Miller | 3f94188 | 2006-03-31 23:13:02 +1100 | [diff] [blame] | 137 | put_u32(buf, mlen + 1); |
Ben Lindstrom | cb72e4f | 2002-06-21 00:41:51 +0000 | [diff] [blame] | 138 | buf[4] = (u_char) type; /* 1st byte of payload is mesg-type */ |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 139 | if (atomicio(vwrite, sock, buf, sizeof(buf)) != sizeof(buf)) |
Damien Miller | b253cc4 | 2005-05-26 12:23:44 +1000 | [diff] [blame] | 140 | fatal("%s: write: %s", __func__, strerror(errno)); |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 141 | if (atomicio(vwrite, sock, buffer_ptr(m), mlen) != mlen) |
Damien Miller | b253cc4 | 2005-05-26 12:23:44 +1000 | [diff] [blame] | 142 | fatal("%s: write: %s", __func__, strerror(errno)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | void |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 146 | mm_request_receive(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 147 | { |
| 148 | u_char buf[4]; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 149 | u_int msg_len; |
| 150 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 151 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 152 | |
Damien Miller | b253cc4 | 2005-05-26 12:23:44 +1000 | [diff] [blame] | 153 | if (atomicio(read, sock, buf, sizeof(buf)) != sizeof(buf)) { |
| 154 | if (errno == EPIPE) |
Darren Tucker | 3e33cec | 2003-10-02 16:12:36 +1000 | [diff] [blame] | 155 | cleanup_exit(255); |
Damien Miller | b253cc4 | 2005-05-26 12:23:44 +1000 | [diff] [blame] | 156 | fatal("%s: read: %s", __func__, strerror(errno)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 157 | } |
Damien Miller | 3f94188 | 2006-03-31 23:13:02 +1100 | [diff] [blame] | 158 | msg_len = get_u32(buf); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 159 | if (msg_len > 256 * 1024) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 160 | fatal("%s: read: bad msg_len %d", __func__, msg_len); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 161 | buffer_clear(m); |
| 162 | buffer_append_space(m, msg_len); |
Damien Miller | b253cc4 | 2005-05-26 12:23:44 +1000 | [diff] [blame] | 163 | if (atomicio(read, sock, buffer_ptr(m), msg_len) != msg_len) |
| 164 | fatal("%s: read: %s", __func__, strerror(errno)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | void |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 168 | mm_request_receive_expect(int sock, enum monitor_reqtype type, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 169 | { |
| 170 | u_char rtype; |
| 171 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 172 | debug3("%s entering: type %d", __func__, type); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 173 | |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 174 | mm_request_receive(sock, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 175 | rtype = buffer_get_char(m); |
| 176 | if (rtype != type) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 177 | fatal("%s: read: rtype %d != type %d", __func__, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 178 | rtype, type); |
| 179 | } |
| 180 | |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 181 | #ifdef WITH_OPENSSL |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 182 | DH * |
| 183 | mm_choose_dh(int min, int nbits, int max) |
| 184 | { |
| 185 | BIGNUM *p, *g; |
| 186 | int success = 0; |
| 187 | Buffer m; |
| 188 | |
| 189 | buffer_init(&m); |
| 190 | buffer_put_int(&m, min); |
| 191 | buffer_put_int(&m, nbits); |
| 192 | buffer_put_int(&m, max); |
| 193 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 194 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_MODULI, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 195 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 196 | debug3("%s: waiting for MONITOR_ANS_MODULI", __func__); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 197 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_MODULI, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 198 | |
| 199 | success = buffer_get_char(&m); |
| 200 | if (success == 0) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 201 | fatal("%s: MONITOR_ANS_MODULI failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 202 | |
| 203 | if ((p = BN_new()) == NULL) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 204 | fatal("%s: BN_new failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 205 | if ((g = 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 | buffer_get_bignum2(&m, p); |
| 208 | buffer_get_bignum2(&m, g); |
| 209 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 210 | debug3("%s: remaining %d", __func__, buffer_len(&m)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 211 | buffer_free(&m); |
| 212 | |
| 213 | return (dh_new_group(g, p)); |
| 214 | } |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 215 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 216 | |
| 217 | int |
| 218 | mm_key_sign(Key *key, u_char **sigp, u_int *lenp, u_char *data, u_int datalen) |
| 219 | { |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 220 | Kex *kex = *pmonitor->m_pkex; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 221 | Buffer m; |
| 222 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 223 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 224 | |
| 225 | buffer_init(&m); |
| 226 | buffer_put_int(&m, kex->host_key_index(key)); |
| 227 | buffer_put_string(&m, data, datalen); |
| 228 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 229 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_SIGN, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 230 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 231 | debug3("%s: waiting for MONITOR_ANS_SIGN", __func__); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 232 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_SIGN, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 233 | *sigp = buffer_get_string(&m, lenp); |
| 234 | buffer_free(&m); |
| 235 | |
| 236 | return (0); |
| 237 | } |
| 238 | |
| 239 | struct passwd * |
Darren Tucker | b09b677 | 2004-06-22 15:06:46 +1000 | [diff] [blame] | 240 | mm_getpwnamallow(const char *username) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 241 | { |
| 242 | Buffer m; |
| 243 | struct passwd *pw; |
Damien Miller | d8478b6 | 2011-05-29 21:39:36 +1000 | [diff] [blame] | 244 | u_int len, i; |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 245 | ServerOptions *newopts; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 246 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 247 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 248 | |
| 249 | buffer_init(&m); |
Darren Tucker | b09b677 | 2004-06-22 15:06:46 +1000 | [diff] [blame] | 250 | buffer_put_cstring(&m, username); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 251 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 252 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PWNAM, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 253 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 254 | debug3("%s: waiting for MONITOR_ANS_PWNAM", __func__); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 255 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PWNAM, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 256 | |
| 257 | if (buffer_get_char(&m) == 0) { |
Darren Tucker | 2f8b3d9 | 2007-12-02 23:02:15 +1100 | [diff] [blame] | 258 | pw = NULL; |
| 259 | goto out; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 260 | } |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 261 | pw = buffer_get_string(&m, &len); |
| 262 | if (len != sizeof(struct passwd)) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 263 | fatal("%s: struct passwd size mismatch", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 264 | pw->pw_name = buffer_get_string(&m, NULL); |
| 265 | pw->pw_passwd = buffer_get_string(&m, NULL); |
Damien Miller | 6332da2 | 2013-04-23 14:25:52 +1000 | [diff] [blame] | 266 | #ifdef HAVE_STRUCT_PASSWD_PW_GECOS |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 267 | pw->pw_gecos = buffer_get_string(&m, NULL); |
Damien Miller | 6332da2 | 2013-04-23 14:25:52 +1000 | [diff] [blame] | 268 | #endif |
| 269 | #ifdef HAVE_STRUCT_PASSWD_PW_CLASS |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 270 | pw->pw_class = buffer_get_string(&m, NULL); |
Kevin Steves | 7e14760 | 2002-03-22 18:07:17 +0000 | [diff] [blame] | 271 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 272 | pw->pw_dir = buffer_get_string(&m, NULL); |
| 273 | pw->pw_shell = buffer_get_string(&m, NULL); |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 274 | |
Darren Tucker | 2f8b3d9 | 2007-12-02 23:02:15 +1100 | [diff] [blame] | 275 | out: |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 276 | /* copy options block as a Match directive may have changed some */ |
| 277 | newopts = buffer_get_string(&m, &len); |
| 278 | if (len != sizeof(*newopts)) |
| 279 | fatal("%s: option block size mismatch", __func__); |
Damien Miller | f2e407e | 2011-05-20 19:04:14 +1000 | [diff] [blame] | 280 | |
| 281 | #define M_CP_STROPT(x) do { \ |
| 282 | if (newopts->x != NULL) \ |
| 283 | newopts->x = buffer_get_string(&m, NULL); \ |
| 284 | } while (0) |
Damien Miller | d8478b6 | 2011-05-29 21:39:36 +1000 | [diff] [blame] | 285 | #define M_CP_STRARRAYOPT(x, nx) do { \ |
| 286 | for (i = 0; i < newopts->nx; i++) \ |
| 287 | newopts->x[i] = buffer_get_string(&m, NULL); \ |
| 288 | } while (0) |
Damien Miller | f2e407e | 2011-05-20 19:04:14 +1000 | [diff] [blame] | 289 | /* See comment in servconf.h */ |
| 290 | COPY_MATCH_STRING_OPTS(); |
| 291 | #undef M_CP_STROPT |
Damien Miller | d8478b6 | 2011-05-29 21:39:36 +1000 | [diff] [blame] | 292 | #undef M_CP_STRARRAYOPT |
Damien Miller | f2e407e | 2011-05-20 19:04:14 +1000 | [diff] [blame] | 293 | |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 294 | copy_set_server_options(&options, newopts, 1); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 295 | free(newopts); |
Darren Tucker | 1629c07 | 2007-02-19 22:25:37 +1100 | [diff] [blame] | 296 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 297 | buffer_free(&m); |
| 298 | |
| 299 | return (pw); |
| 300 | } |
| 301 | |
Darren Tucker | 7eb3de0 | 2003-10-15 15:56:58 +1000 | [diff] [blame] | 302 | char * |
| 303 | mm_auth2_read_banner(void) |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 304 | { |
| 305 | Buffer m; |
| 306 | char *banner; |
| 307 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 308 | debug3("%s entering", __func__); |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 309 | |
| 310 | buffer_init(&m); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 311 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTH2_READ_BANNER, &m); |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 312 | buffer_clear(&m); |
| 313 | |
Darren Tucker | 7eb3de0 | 2003-10-15 15:56:58 +1000 | [diff] [blame] | 314 | mm_request_receive_expect(pmonitor->m_recvfd, |
| 315 | MONITOR_ANS_AUTH2_READ_BANNER, &m); |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 316 | banner = buffer_get_string(&m, NULL); |
| 317 | buffer_free(&m); |
Ben Lindstrom | cb72e4f | 2002-06-21 00:41:51 +0000 | [diff] [blame] | 318 | |
Darren Tucker | 7eb3de0 | 2003-10-15 15:56:58 +1000 | [diff] [blame] | 319 | /* treat empty banner as missing banner */ |
| 320 | if (strlen(banner) == 0) { |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 321 | free(banner); |
Darren Tucker | 7eb3de0 | 2003-10-15 15:56:58 +1000 | [diff] [blame] | 322 | banner = NULL; |
| 323 | } |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 324 | return (banner); |
| 325 | } |
| 326 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 327 | /* Inform the privileged process about service and style */ |
| 328 | |
| 329 | void |
| 330 | mm_inform_authserv(char *service, char *style) |
| 331 | { |
| 332 | Buffer m; |
| 333 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 334 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 335 | |
| 336 | buffer_init(&m); |
| 337 | buffer_put_cstring(&m, service); |
| 338 | buffer_put_cstring(&m, style ? style : ""); |
| 339 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 340 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHSERV, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 341 | |
| 342 | buffer_free(&m); |
| 343 | } |
| 344 | |
| 345 | /* Do the password authentication */ |
| 346 | int |
| 347 | mm_auth_password(Authctxt *authctxt, char *password) |
| 348 | { |
| 349 | Buffer m; |
| 350 | int authenticated = 0; |
| 351 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 352 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 353 | |
| 354 | buffer_init(&m); |
| 355 | buffer_put_cstring(&m, password); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 356 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHPASSWORD, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 357 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 358 | debug3("%s: waiting for MONITOR_ANS_AUTHPASSWORD", __func__); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 359 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_AUTHPASSWORD, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 360 | |
| 361 | authenticated = buffer_get_int(&m); |
| 362 | |
| 363 | buffer_free(&m); |
| 364 | |
| 365 | debug3("%s: user %sauthenticated", |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 366 | __func__, authenticated ? "" : "not "); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 367 | return (authenticated); |
| 368 | } |
| 369 | |
| 370 | int |
| 371 | mm_user_key_allowed(struct passwd *pw, Key *key) |
| 372 | { |
| 373 | return (mm_key_allowed(MM_USERKEY, NULL, NULL, key)); |
| 374 | } |
| 375 | |
| 376 | int |
| 377 | mm_hostbased_key_allowed(struct passwd *pw, char *user, char *host, |
| 378 | Key *key) |
| 379 | { |
| 380 | return (mm_key_allowed(MM_HOSTKEY, user, host, key)); |
| 381 | } |
| 382 | |
| 383 | int |
| 384 | mm_auth_rhosts_rsa_key_allowed(struct passwd *pw, char *user, |
| 385 | char *host, Key *key) |
| 386 | { |
| 387 | int ret; |
| 388 | |
| 389 | key->type = KEY_RSA; /* XXX hack for key_to_blob */ |
| 390 | ret = mm_key_allowed(MM_RSAHOSTKEY, user, host, key); |
| 391 | key->type = KEY_RSA1; |
| 392 | return (ret); |
| 393 | } |
| 394 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 395 | int |
| 396 | mm_key_allowed(enum mm_keytype type, char *user, char *host, Key *key) |
| 397 | { |
| 398 | Buffer m; |
| 399 | u_char *blob; |
| 400 | u_int len; |
Damien Miller | 06ebedf | 2003-02-24 12:03:38 +1100 | [diff] [blame] | 401 | int allowed = 0, have_forced = 0; |
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 | |
| 405 | /* Convert the key to a blob and the pass it over */ |
| 406 | if (!key_to_blob(key, &blob, &len)) |
| 407 | return (0); |
| 408 | |
| 409 | buffer_init(&m); |
| 410 | buffer_put_int(&m, type); |
| 411 | buffer_put_cstring(&m, user ? user : ""); |
| 412 | buffer_put_cstring(&m, host ? host : ""); |
| 413 | buffer_put_string(&m, blob, len); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 414 | free(blob); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 415 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 416 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_KEYALLOWED, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 417 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 418 | debug3("%s: waiting for MONITOR_ANS_KEYALLOWED", __func__); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 419 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_KEYALLOWED, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 420 | |
| 421 | allowed = buffer_get_int(&m); |
| 422 | |
Damien Miller | 06ebedf | 2003-02-24 12:03:38 +1100 | [diff] [blame] | 423 | /* fake forced command */ |
| 424 | auth_clear_options(); |
| 425 | have_forced = buffer_get_int(&m); |
| 426 | forced_command = have_forced ? xstrdup("true") : NULL; |
| 427 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 428 | buffer_free(&m); |
| 429 | |
| 430 | return (allowed); |
| 431 | } |
| 432 | |
| 433 | /* |
| 434 | * This key verify needs to send the key type along, because the |
| 435 | * privileged parent makes the decision if the key is allowed |
| 436 | * for authentication. |
| 437 | */ |
| 438 | |
| 439 | int |
| 440 | mm_key_verify(Key *key, u_char *sig, u_int siglen, u_char *data, u_int datalen) |
| 441 | { |
| 442 | Buffer m; |
| 443 | u_char *blob; |
| 444 | u_int len; |
| 445 | int verified = 0; |
| 446 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 447 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 448 | |
| 449 | /* Convert the key to a blob and the pass it over */ |
| 450 | if (!key_to_blob(key, &blob, &len)) |
| 451 | return (0); |
| 452 | |
| 453 | buffer_init(&m); |
| 454 | buffer_put_string(&m, blob, len); |
| 455 | buffer_put_string(&m, sig, siglen); |
| 456 | buffer_put_string(&m, data, datalen); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 457 | free(blob); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 458 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 459 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_KEYVERIFY, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 460 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 461 | debug3("%s: waiting for MONITOR_ANS_KEYVERIFY", __func__); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 462 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_KEYVERIFY, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 463 | |
| 464 | verified = buffer_get_int(&m); |
| 465 | |
| 466 | buffer_free(&m); |
| 467 | |
| 468 | return (verified); |
| 469 | } |
| 470 | |
| 471 | /* Export key state after authentication */ |
| 472 | Newkeys * |
| 473 | mm_newkeys_from_blob(u_char *blob, int blen) |
| 474 | { |
| 475 | Buffer b; |
| 476 | u_int len; |
| 477 | Newkeys *newkey = NULL; |
| 478 | Enc *enc; |
| 479 | Mac *mac; |
| 480 | Comp *comp; |
| 481 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 482 | debug3("%s: %p(%d)", __func__, blob, blen); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 483 | #ifdef DEBUG_PK |
| 484 | dump_base64(stderr, blob, blen); |
| 485 | #endif |
| 486 | buffer_init(&b); |
| 487 | buffer_append(&b, blob, blen); |
| 488 | |
Damien Miller | 49c145c | 2013-11-07 13:35:39 +1100 | [diff] [blame] | 489 | newkey = xcalloc(1, sizeof(*newkey)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 490 | enc = &newkey->enc; |
| 491 | mac = &newkey->mac; |
| 492 | comp = &newkey->comp; |
| 493 | |
| 494 | /* Enc structure */ |
| 495 | enc->name = buffer_get_string(&b, NULL); |
| 496 | buffer_get(&b, &enc->cipher, sizeof(enc->cipher)); |
| 497 | enc->enabled = buffer_get_int(&b); |
| 498 | enc->block_size = buffer_get_int(&b); |
| 499 | enc->key = buffer_get_string(&b, &enc->key_len); |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 500 | enc->iv = buffer_get_string(&b, &enc->iv_len); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 501 | |
| 502 | if (enc->name == NULL || cipher_by_name(enc->name) != enc->cipher) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 503 | fatal("%s: bad cipher name %s or pointer %p", __func__, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 504 | enc->name, enc->cipher); |
| 505 | |
| 506 | /* Mac structure */ |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 507 | if (cipher_authlen(enc->cipher) == 0) { |
| 508 | mac->name = buffer_get_string(&b, NULL); |
| 509 | if (mac->name == NULL || mac_setup(mac, mac->name) == -1) |
| 510 | fatal("%s: can not setup mac %s", __func__, mac->name); |
| 511 | mac->enabled = buffer_get_int(&b); |
| 512 | mac->key = buffer_get_string(&b, &len); |
| 513 | if (len > mac->key_len) |
| 514 | fatal("%s: bad mac key length: %u > %d", __func__, len, |
| 515 | mac->key_len); |
| 516 | mac->key_len = len; |
| 517 | } |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 518 | |
| 519 | /* Comp structure */ |
| 520 | comp->type = buffer_get_int(&b); |
| 521 | comp->enabled = buffer_get_int(&b); |
| 522 | comp->name = buffer_get_string(&b, NULL); |
| 523 | |
| 524 | len = buffer_len(&b); |
| 525 | if (len != 0) |
Ben Lindstrom | 0851249 | 2002-06-27 00:23:02 +0000 | [diff] [blame] | 526 | error("newkeys_from_blob: remaining bytes in blob %u", len); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 527 | buffer_free(&b); |
| 528 | return (newkey); |
| 529 | } |
| 530 | |
| 531 | int |
| 532 | mm_newkeys_to_blob(int mode, u_char **blobp, u_int *lenp) |
| 533 | { |
| 534 | Buffer b; |
| 535 | int len; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 536 | Enc *enc; |
| 537 | Mac *mac; |
| 538 | Comp *comp; |
Darren Tucker | f7288d7 | 2009-06-21 18:12:20 +1000 | [diff] [blame] | 539 | Newkeys *newkey = (Newkeys *)packet_get_newkeys(mode); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 540 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 541 | debug3("%s: converting %p", __func__, newkey); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 542 | |
| 543 | if (newkey == NULL) { |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 544 | error("%s: newkey == NULL", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 545 | return 0; |
| 546 | } |
| 547 | enc = &newkey->enc; |
| 548 | mac = &newkey->mac; |
| 549 | comp = &newkey->comp; |
| 550 | |
| 551 | buffer_init(&b); |
| 552 | /* Enc structure */ |
| 553 | buffer_put_cstring(&b, enc->name); |
| 554 | /* The cipher struct is constant and shared, you export pointer */ |
| 555 | buffer_append(&b, &enc->cipher, sizeof(enc->cipher)); |
| 556 | buffer_put_int(&b, enc->enabled); |
| 557 | buffer_put_int(&b, enc->block_size); |
| 558 | buffer_put_string(&b, enc->key, enc->key_len); |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 559 | packet_get_keyiv(mode, enc->iv, enc->iv_len); |
| 560 | buffer_put_string(&b, enc->iv, enc->iv_len); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 561 | |
| 562 | /* Mac structure */ |
Damien Miller | 1d75abf | 2013-01-09 16:12:19 +1100 | [diff] [blame] | 563 | if (cipher_authlen(enc->cipher) == 0) { |
| 564 | buffer_put_cstring(&b, mac->name); |
| 565 | buffer_put_int(&b, mac->enabled); |
| 566 | buffer_put_string(&b, mac->key, mac->key_len); |
| 567 | } |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 568 | |
| 569 | /* Comp structure */ |
| 570 | buffer_put_int(&b, comp->type); |
| 571 | buffer_put_int(&b, comp->enabled); |
| 572 | buffer_put_cstring(&b, comp->name); |
| 573 | |
| 574 | len = buffer_len(&b); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 575 | if (lenp != NULL) |
| 576 | *lenp = len; |
Ben Lindstrom | 2bf759c | 2002-07-07 22:13:31 +0000 | [diff] [blame] | 577 | if (blobp != NULL) { |
| 578 | *blobp = xmalloc(len); |
| 579 | memcpy(*blobp, buffer_ptr(&b), len); |
| 580 | } |
Damien Miller | a5103f4 | 2014-02-04 11:20:14 +1100 | [diff] [blame] | 581 | explicit_bzero(buffer_ptr(&b), len); |
Ben Lindstrom | 2bf759c | 2002-07-07 22:13:31 +0000 | [diff] [blame] | 582 | buffer_free(&b); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 583 | return len; |
| 584 | } |
| 585 | |
| 586 | static void |
| 587 | mm_send_kex(Buffer *m, Kex *kex) |
| 588 | { |
| 589 | buffer_put_string(m, kex->session_id, kex->session_id_len); |
| 590 | buffer_put_int(m, kex->we_need); |
| 591 | buffer_put_int(m, kex->hostkey_type); |
| 592 | buffer_put_int(m, kex->kex_type); |
| 593 | buffer_put_string(m, buffer_ptr(&kex->my), buffer_len(&kex->my)); |
| 594 | buffer_put_string(m, buffer_ptr(&kex->peer), buffer_len(&kex->peer)); |
| 595 | buffer_put_int(m, kex->flags); |
| 596 | buffer_put_cstring(m, kex->client_version_string); |
| 597 | buffer_put_cstring(m, kex->server_version_string); |
| 598 | } |
| 599 | |
| 600 | void |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 601 | mm_send_keystate(struct monitor *monitor) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 602 | { |
Darren Tucker | f7288d7 | 2009-06-21 18:12:20 +1000 | [diff] [blame] | 603 | Buffer m, *input, *output; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 604 | u_char *blob, *p; |
| 605 | u_int bloblen, plen; |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 606 | u_int32_t seqnr, packets; |
Damien Miller | b61f3fc | 2008-07-11 17:36:48 +1000 | [diff] [blame] | 607 | u_int64_t blocks, bytes; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 608 | |
| 609 | buffer_init(&m); |
| 610 | |
| 611 | if (!compat20) { |
| 612 | u_char iv[24]; |
Ben Lindstrom | 402c6cc | 2002-06-21 00:43:42 +0000 | [diff] [blame] | 613 | u_char *key; |
| 614 | u_int ivlen, keylen; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 615 | |
| 616 | buffer_put_int(&m, packet_get_protocol_flags()); |
| 617 | |
| 618 | buffer_put_int(&m, packet_get_ssh1_cipher()); |
| 619 | |
Ben Lindstrom | 402c6cc | 2002-06-21 00:43:42 +0000 | [diff] [blame] | 620 | debug3("%s: Sending ssh1 KEY+IV", __func__); |
| 621 | keylen = packet_get_encryption_key(NULL); |
| 622 | key = xmalloc(keylen+1); /* add 1 if keylen == 0 */ |
| 623 | keylen = packet_get_encryption_key(key); |
| 624 | buffer_put_string(&m, key, keylen); |
Damien Miller | a5103f4 | 2014-02-04 11:20:14 +1100 | [diff] [blame] | 625 | explicit_bzero(key, keylen); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 626 | free(key); |
Ben Lindstrom | 402c6cc | 2002-06-21 00:43:42 +0000 | [diff] [blame] | 627 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 628 | ivlen = packet_get_keyiv_len(MODE_OUT); |
| 629 | packet_get_keyiv(MODE_OUT, iv, ivlen); |
| 630 | buffer_put_string(&m, iv, ivlen); |
Darren Tucker | 3a7c041 | 2012-10-05 10:51:59 +1000 | [diff] [blame] | 631 | ivlen = packet_get_keyiv_len(MODE_IN); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 632 | packet_get_keyiv(MODE_IN, iv, ivlen); |
| 633 | buffer_put_string(&m, iv, ivlen); |
| 634 | goto skip; |
| 635 | } else { |
| 636 | /* Kex for rekeying */ |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 637 | mm_send_kex(&m, *monitor->m_pkex); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | debug3("%s: Sending new keys: %p %p", |
Darren Tucker | f7288d7 | 2009-06-21 18:12:20 +1000 | [diff] [blame] | 641 | __func__, packet_get_newkeys(MODE_OUT), |
| 642 | packet_get_newkeys(MODE_IN)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 643 | |
| 644 | /* Keys from Kex */ |
| 645 | if (!mm_newkeys_to_blob(MODE_OUT, &blob, &bloblen)) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 646 | fatal("%s: conversion of newkeys failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 647 | |
| 648 | buffer_put_string(&m, blob, bloblen); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 649 | free(blob); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 650 | |
| 651 | if (!mm_newkeys_to_blob(MODE_IN, &blob, &bloblen)) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 652 | fatal("%s: conversion of newkeys failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 653 | |
| 654 | buffer_put_string(&m, blob, bloblen); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 655 | free(blob); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 656 | |
Damien Miller | b61f3fc | 2008-07-11 17:36:48 +1000 | [diff] [blame] | 657 | packet_get_state(MODE_OUT, &seqnr, &blocks, &packets, &bytes); |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 658 | buffer_put_int(&m, seqnr); |
| 659 | buffer_put_int64(&m, blocks); |
| 660 | buffer_put_int(&m, packets); |
Damien Miller | b61f3fc | 2008-07-11 17:36:48 +1000 | [diff] [blame] | 661 | buffer_put_int64(&m, bytes); |
| 662 | packet_get_state(MODE_IN, &seqnr, &blocks, &packets, &bytes); |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 663 | buffer_put_int(&m, seqnr); |
| 664 | buffer_put_int64(&m, blocks); |
| 665 | buffer_put_int(&m, packets); |
Damien Miller | b61f3fc | 2008-07-11 17:36:48 +1000 | [diff] [blame] | 666 | buffer_put_int64(&m, bytes); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 667 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 668 | debug3("%s: New keys have been sent", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 669 | skip: |
| 670 | /* More key context */ |
| 671 | plen = packet_get_keycontext(MODE_OUT, NULL); |
| 672 | p = xmalloc(plen+1); |
| 673 | packet_get_keycontext(MODE_OUT, p); |
| 674 | buffer_put_string(&m, p, plen); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 675 | free(p); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 676 | |
| 677 | plen = packet_get_keycontext(MODE_IN, NULL); |
| 678 | p = xmalloc(plen+1); |
| 679 | packet_get_keycontext(MODE_IN, p); |
| 680 | buffer_put_string(&m, p, plen); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 681 | free(p); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 682 | |
| 683 | /* Compression state */ |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 684 | debug3("%s: Sending compression state", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 685 | buffer_put_string(&m, &outgoing_stream, sizeof(outgoing_stream)); |
| 686 | buffer_put_string(&m, &incoming_stream, sizeof(incoming_stream)); |
| 687 | |
| 688 | /* Network I/O buffers */ |
Darren Tucker | f7288d7 | 2009-06-21 18:12:20 +1000 | [diff] [blame] | 689 | input = (Buffer *)packet_get_input(); |
| 690 | output = (Buffer *)packet_get_output(); |
| 691 | buffer_put_string(&m, buffer_ptr(input), buffer_len(input)); |
| 692 | buffer_put_string(&m, buffer_ptr(output), buffer_len(output)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 693 | |
Darren Tucker | c5564e1 | 2009-06-21 18:53:53 +1000 | [diff] [blame] | 694 | /* Roaming */ |
| 695 | if (compat20) { |
| 696 | buffer_put_int64(&m, get_sent_bytes()); |
| 697 | buffer_put_int64(&m, get_recv_bytes()); |
| 698 | } |
| 699 | |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 700 | mm_request_send(monitor->m_recvfd, MONITOR_REQ_KEYEXPORT, &m); |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 701 | debug3("%s: Finished sending state", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 702 | |
| 703 | buffer_free(&m); |
| 704 | } |
| 705 | |
| 706 | int |
Damien Miller | 71a7367 | 2006-03-26 14:04:36 +1100 | [diff] [blame] | 707 | mm_pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, size_t namebuflen) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 708 | { |
| 709 | Buffer m; |
Darren Tucker | 0999174 | 2004-07-17 17:05:14 +1000 | [diff] [blame] | 710 | char *p, *msg; |
Damien Miller | 7207f64 | 2008-05-19 15:34:50 +1000 | [diff] [blame] | 711 | int success = 0, tmp1 = -1, tmp2 = -1; |
| 712 | |
| 713 | /* Kludge: ensure there are fds free to receive the pty/tty */ |
| 714 | if ((tmp1 = dup(pmonitor->m_recvfd)) == -1 || |
| 715 | (tmp2 = dup(pmonitor->m_recvfd)) == -1) { |
| 716 | error("%s: cannot allocate fds for pty", __func__); |
| 717 | if (tmp1 > 0) |
| 718 | close(tmp1); |
| 719 | if (tmp2 > 0) |
| 720 | close(tmp2); |
| 721 | return 0; |
| 722 | } |
| 723 | close(tmp1); |
| 724 | close(tmp2); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 725 | |
| 726 | buffer_init(&m); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 727 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PTY, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 728 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 729 | debug3("%s: waiting for MONITOR_ANS_PTY", __func__); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 730 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PTY, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 731 | |
| 732 | success = buffer_get_int(&m); |
| 733 | if (success == 0) { |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 734 | debug3("%s: pty alloc failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 735 | buffer_free(&m); |
| 736 | return (0); |
| 737 | } |
| 738 | p = buffer_get_string(&m, NULL); |
Darren Tucker | 0999174 | 2004-07-17 17:05:14 +1000 | [diff] [blame] | 739 | msg = buffer_get_string(&m, NULL); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 740 | buffer_free(&m); |
| 741 | |
| 742 | strlcpy(namebuf, p, namebuflen); /* Possible truncation */ |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 743 | free(p); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 744 | |
Darren Tucker | 0999174 | 2004-07-17 17:05:14 +1000 | [diff] [blame] | 745 | buffer_append(&loginmsg, msg, strlen(msg)); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 746 | free(msg); |
Darren Tucker | 0999174 | 2004-07-17 17:05:14 +1000 | [diff] [blame] | 747 | |
Damien Miller | 54fd7cf | 2007-09-17 12:04:08 +1000 | [diff] [blame] | 748 | if ((*ptyfd = mm_receive_fd(pmonitor->m_recvfd)) == -1 || |
| 749 | (*ttyfd = mm_receive_fd(pmonitor->m_recvfd)) == -1) |
| 750 | fatal("%s: receive fds failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 751 | |
| 752 | /* Success */ |
| 753 | return (1); |
| 754 | } |
| 755 | |
| 756 | void |
Darren Tucker | 3e33cec | 2003-10-02 16:12:36 +1000 | [diff] [blame] | 757 | mm_session_pty_cleanup2(Session *s) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 758 | { |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 759 | Buffer m; |
| 760 | |
| 761 | if (s->ttyfd == -1) |
| 762 | return; |
| 763 | buffer_init(&m); |
| 764 | buffer_put_cstring(&m, s->tty); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 765 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PTYCLEANUP, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 766 | buffer_free(&m); |
| 767 | |
| 768 | /* closed dup'ed master */ |
Damien Miller | 7207f64 | 2008-05-19 15:34:50 +1000 | [diff] [blame] | 769 | if (s->ptymaster != -1 && close(s->ptymaster) < 0) |
| 770 | error("close(s->ptymaster/%d): %s", |
| 771 | s->ptymaster, strerror(errno)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 772 | |
| 773 | /* unlink pty from session */ |
| 774 | s->ttyfd = -1; |
| 775 | } |
| 776 | |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 777 | #ifdef USE_PAM |
| 778 | void |
Darren Tucker | dbf7a74 | 2004-03-08 23:04:06 +1100 | [diff] [blame] | 779 | mm_start_pam(Authctxt *authctxt) |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 780 | { |
| 781 | Buffer m; |
| 782 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 783 | debug3("%s entering", __func__); |
Damien Miller | 4e448a3 | 2003-05-14 15:11:48 +1000 | [diff] [blame] | 784 | if (!options.use_pam) |
| 785 | fatal("UsePAM=no, but ended up in %s anyway", __func__); |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 786 | |
| 787 | buffer_init(&m); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 788 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_START, &m); |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 789 | |
| 790 | buffer_free(&m); |
| 791 | } |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 792 | |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 793 | u_int |
| 794 | mm_do_pam_account(void) |
| 795 | { |
| 796 | Buffer m; |
| 797 | u_int ret; |
Darren Tucker | 77fc29e | 2004-09-11 23:07:03 +1000 | [diff] [blame] | 798 | char *msg; |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 799 | |
| 800 | debug3("%s entering", __func__); |
| 801 | if (!options.use_pam) |
| 802 | fatal("UsePAM=no, but ended up in %s anyway", __func__); |
| 803 | |
| 804 | buffer_init(&m); |
| 805 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_ACCOUNT, &m); |
| 806 | |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 807 | mm_request_receive_expect(pmonitor->m_recvfd, |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 808 | MONITOR_ANS_PAM_ACCOUNT, &m); |
| 809 | ret = buffer_get_int(&m); |
Darren Tucker | 77fc29e | 2004-09-11 23:07:03 +1000 | [diff] [blame] | 810 | msg = buffer_get_string(&m, NULL); |
| 811 | buffer_append(&loginmsg, msg, strlen(msg)); |
Darren Tucker | f60845f | 2013-06-02 08:07:31 +1000 | [diff] [blame] | 812 | free(msg); |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 813 | |
| 814 | buffer_free(&m); |
Damien Miller | 787b2ec | 2003-11-21 23:56:47 +1100 | [diff] [blame] | 815 | |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 816 | debug3("%s returning %d", __func__, ret); |
| 817 | |
| 818 | return (ret); |
| 819 | } |
| 820 | |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 821 | void * |
| 822 | mm_sshpam_init_ctx(Authctxt *authctxt) |
| 823 | { |
| 824 | Buffer m; |
| 825 | int success; |
| 826 | |
| 827 | debug3("%s", __func__); |
| 828 | buffer_init(&m); |
| 829 | buffer_put_cstring(&m, authctxt->user); |
| 830 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_INIT_CTX, &m); |
| 831 | debug3("%s: waiting for MONITOR_ANS_PAM_INIT_CTX", __func__); |
| 832 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PAM_INIT_CTX, &m); |
| 833 | success = buffer_get_int(&m); |
| 834 | if (success == 0) { |
| 835 | debug3("%s: pam_init_ctx failed", __func__); |
| 836 | buffer_free(&m); |
| 837 | return (NULL); |
| 838 | } |
| 839 | buffer_free(&m); |
| 840 | return (authctxt); |
| 841 | } |
| 842 | |
| 843 | int |
| 844 | mm_sshpam_query(void *ctx, char **name, char **info, |
| 845 | u_int *num, char ***prompts, u_int **echo_on) |
| 846 | { |
| 847 | Buffer m; |
Damien Miller | 04b6533 | 2005-07-17 17:53:31 +1000 | [diff] [blame] | 848 | u_int i; |
| 849 | int ret; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 850 | |
| 851 | debug3("%s", __func__); |
| 852 | buffer_init(&m); |
| 853 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_QUERY, &m); |
| 854 | debug3("%s: waiting for MONITOR_ANS_PAM_QUERY", __func__); |
| 855 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PAM_QUERY, &m); |
| 856 | ret = buffer_get_int(&m); |
| 857 | debug3("%s: pam_query returned %d", __func__, ret); |
| 858 | *name = buffer_get_string(&m, NULL); |
| 859 | *info = buffer_get_string(&m, NULL); |
| 860 | *num = buffer_get_int(&m); |
Darren Tucker | d8093e4 | 2006-05-04 16:24:34 +1000 | [diff] [blame] | 861 | if (*num > PAM_MAX_NUM_MSG) |
| 862 | fatal("%s: recieved %u PAM messages, expected <= %u", |
| 863 | __func__, *num, PAM_MAX_NUM_MSG); |
| 864 | *prompts = xcalloc((*num + 1), sizeof(char *)); |
| 865 | *echo_on = xcalloc((*num + 1), sizeof(u_int)); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 866 | for (i = 0; i < *num; ++i) { |
| 867 | (*prompts)[i] = buffer_get_string(&m, NULL); |
| 868 | (*echo_on)[i] = buffer_get_int(&m); |
| 869 | } |
| 870 | buffer_free(&m); |
| 871 | return (ret); |
| 872 | } |
| 873 | |
| 874 | int |
| 875 | mm_sshpam_respond(void *ctx, u_int num, char **resp) |
| 876 | { |
| 877 | Buffer m; |
Damien Miller | 04b6533 | 2005-07-17 17:53:31 +1000 | [diff] [blame] | 878 | u_int i; |
| 879 | int ret; |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 880 | |
| 881 | debug3("%s", __func__); |
| 882 | buffer_init(&m); |
| 883 | buffer_put_int(&m, num); |
| 884 | for (i = 0; i < num; ++i) |
| 885 | buffer_put_cstring(&m, resp[i]); |
| 886 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_RESPOND, &m); |
| 887 | debug3("%s: waiting for MONITOR_ANS_PAM_RESPOND", __func__); |
| 888 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PAM_RESPOND, &m); |
| 889 | ret = buffer_get_int(&m); |
| 890 | debug3("%s: pam_respond returned %d", __func__, ret); |
| 891 | buffer_free(&m); |
| 892 | return (ret); |
| 893 | } |
| 894 | |
| 895 | void |
| 896 | mm_sshpam_free_ctx(void *ctxtp) |
| 897 | { |
| 898 | Buffer m; |
| 899 | |
| 900 | debug3("%s", __func__); |
| 901 | buffer_init(&m); |
| 902 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PAM_FREE_CTX, &m); |
| 903 | debug3("%s: waiting for MONITOR_ANS_PAM_FREE_CTX", __func__); |
| 904 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PAM_FREE_CTX, &m); |
| 905 | buffer_free(&m); |
| 906 | } |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 907 | #endif /* USE_PAM */ |
| 908 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 909 | /* Request process termination */ |
| 910 | |
| 911 | void |
| 912 | mm_terminate(void) |
| 913 | { |
| 914 | Buffer m; |
| 915 | |
| 916 | buffer_init(&m); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 917 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_TERM, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 918 | buffer_free(&m); |
| 919 | } |
| 920 | |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 921 | #ifdef WITH_SSH1 |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 922 | int |
| 923 | mm_ssh1_session_key(BIGNUM *num) |
| 924 | { |
| 925 | int rsafail; |
| 926 | Buffer m; |
| 927 | |
| 928 | buffer_init(&m); |
| 929 | buffer_put_bignum2(&m, num); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 930 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_SESSKEY, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 931 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 932 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_SESSKEY, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 933 | |
| 934 | rsafail = buffer_get_int(&m); |
| 935 | buffer_get_bignum2(&m, num); |
| 936 | |
| 937 | buffer_free(&m); |
| 938 | |
| 939 | return (rsafail); |
| 940 | } |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 941 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 942 | |
| 943 | static void |
| 944 | mm_chall_setup(char **name, char **infotxt, u_int *numprompts, |
| 945 | char ***prompts, u_int **echo_on) |
| 946 | { |
Ben Lindstrom | cb72e4f | 2002-06-21 00:41:51 +0000 | [diff] [blame] | 947 | *name = xstrdup(""); |
| 948 | *infotxt = xstrdup(""); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 949 | *numprompts = 1; |
Damien Miller | 07d86be | 2006-03-26 14:19:21 +1100 | [diff] [blame] | 950 | *prompts = xcalloc(*numprompts, sizeof(char *)); |
| 951 | *echo_on = xcalloc(*numprompts, sizeof(u_int)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 952 | (*echo_on)[0] = 0; |
| 953 | } |
| 954 | |
| 955 | int |
| 956 | mm_bsdauth_query(void *ctx, char **name, char **infotxt, |
| 957 | u_int *numprompts, char ***prompts, u_int **echo_on) |
| 958 | { |
| 959 | Buffer m; |
Damien Miller | b7df3af | 2003-02-24 11:55:46 +1100 | [diff] [blame] | 960 | u_int success; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 961 | char *challenge; |
| 962 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 963 | debug3("%s: entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 964 | |
| 965 | buffer_init(&m); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 966 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_BSDAUTHQUERY, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 967 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 968 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_BSDAUTHQUERY, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 969 | &m); |
Damien Miller | b7df3af | 2003-02-24 11:55:46 +1100 | [diff] [blame] | 970 | success = buffer_get_int(&m); |
| 971 | if (success == 0) { |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 972 | debug3("%s: no challenge", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 973 | buffer_free(&m); |
| 974 | return (-1); |
| 975 | } |
| 976 | |
| 977 | /* Get the challenge, and format the response */ |
| 978 | challenge = buffer_get_string(&m, NULL); |
| 979 | buffer_free(&m); |
| 980 | |
| 981 | mm_chall_setup(name, infotxt, numprompts, prompts, echo_on); |
| 982 | (*prompts)[0] = challenge; |
| 983 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 984 | debug3("%s: received challenge: %s", __func__, challenge); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 985 | |
| 986 | return (0); |
| 987 | } |
| 988 | |
| 989 | int |
| 990 | mm_bsdauth_respond(void *ctx, u_int numresponses, char **responses) |
| 991 | { |
| 992 | Buffer m; |
| 993 | int authok; |
| 994 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 995 | debug3("%s: entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 996 | if (numresponses != 1) |
| 997 | return (-1); |
| 998 | |
| 999 | buffer_init(&m); |
| 1000 | buffer_put_cstring(&m, responses[0]); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1001 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_BSDAUTHRESPOND, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1002 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1003 | mm_request_receive_expect(pmonitor->m_recvfd, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1004 | MONITOR_ANS_BSDAUTHRESPOND, &m); |
| 1005 | |
| 1006 | authok = buffer_get_int(&m); |
| 1007 | buffer_free(&m); |
| 1008 | |
| 1009 | return ((authok == 0) ? -1 : 0); |
| 1010 | } |
| 1011 | |
Darren Tucker | 042e2e8 | 2004-07-08 23:09:42 +1000 | [diff] [blame] | 1012 | #ifdef SKEY |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1013 | int |
| 1014 | mm_skey_query(void *ctx, char **name, char **infotxt, |
| 1015 | u_int *numprompts, char ***prompts, u_int **echo_on) |
| 1016 | { |
| 1017 | Buffer m; |
Damien Miller | b7df3af | 2003-02-24 11:55:46 +1100 | [diff] [blame] | 1018 | u_int success; |
Darren Tucker | d6a23f2 | 2006-08-05 18:50:35 +1000 | [diff] [blame] | 1019 | char *challenge; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1020 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1021 | debug3("%s: entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1022 | |
| 1023 | buffer_init(&m); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1024 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_SKEYQUERY, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1025 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1026 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_SKEYQUERY, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1027 | &m); |
Damien Miller | b7df3af | 2003-02-24 11:55:46 +1100 | [diff] [blame] | 1028 | success = buffer_get_int(&m); |
| 1029 | if (success == 0) { |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1030 | debug3("%s: no challenge", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1031 | buffer_free(&m); |
| 1032 | return (-1); |
| 1033 | } |
| 1034 | |
| 1035 | /* Get the challenge, and format the response */ |
| 1036 | challenge = buffer_get_string(&m, NULL); |
| 1037 | buffer_free(&m); |
| 1038 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1039 | debug3("%s: received challenge: %s", __func__, challenge); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1040 | |
| 1041 | mm_chall_setup(name, infotxt, numprompts, prompts, echo_on); |
| 1042 | |
Damien Miller | 07d86be | 2006-03-26 14:19:21 +1100 | [diff] [blame] | 1043 | xasprintf(*prompts, "%s%s", challenge, SKEY_PROMPT); |
Darren Tucker | f60845f | 2013-06-02 08:07:31 +1000 | [diff] [blame] | 1044 | free(challenge); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1045 | |
| 1046 | return (0); |
| 1047 | } |
| 1048 | |
| 1049 | int |
| 1050 | mm_skey_respond(void *ctx, u_int numresponses, char **responses) |
| 1051 | { |
| 1052 | Buffer m; |
| 1053 | int authok; |
| 1054 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1055 | debug3("%s: entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1056 | if (numresponses != 1) |
| 1057 | return (-1); |
| 1058 | |
| 1059 | buffer_init(&m); |
| 1060 | buffer_put_cstring(&m, responses[0]); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1061 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_SKEYRESPOND, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1062 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1063 | mm_request_receive_expect(pmonitor->m_recvfd, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1064 | MONITOR_ANS_SKEYRESPOND, &m); |
| 1065 | |
| 1066 | authok = buffer_get_int(&m); |
| 1067 | buffer_free(&m); |
| 1068 | |
| 1069 | return ((authok == 0) ? -1 : 0); |
| 1070 | } |
Darren Tucker | 042e2e8 | 2004-07-08 23:09:42 +1000 | [diff] [blame] | 1071 | #endif /* SKEY */ |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1072 | |
| 1073 | void |
| 1074 | mm_ssh1_session_id(u_char session_id[16]) |
| 1075 | { |
| 1076 | Buffer m; |
| 1077 | int i; |
| 1078 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1079 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1080 | |
| 1081 | buffer_init(&m); |
| 1082 | for (i = 0; i < 16; i++) |
| 1083 | buffer_put_char(&m, session_id[i]); |
| 1084 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1085 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_SESSID, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1086 | buffer_free(&m); |
| 1087 | } |
| 1088 | |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 1089 | #ifdef WITH_SSH1 |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1090 | int |
| 1091 | mm_auth_rsa_key_allowed(struct passwd *pw, BIGNUM *client_n, Key **rkey) |
| 1092 | { |
| 1093 | Buffer m; |
| 1094 | Key *key; |
| 1095 | u_char *blob; |
| 1096 | u_int blen; |
Damien Miller | 06ebedf | 2003-02-24 12:03:38 +1100 | [diff] [blame] | 1097 | int allowed = 0, have_forced = 0; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1098 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1099 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1100 | |
| 1101 | buffer_init(&m); |
| 1102 | buffer_put_bignum2(&m, client_n); |
| 1103 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1104 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_RSAKEYALLOWED, &m); |
| 1105 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_RSAKEYALLOWED, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1106 | |
| 1107 | allowed = buffer_get_int(&m); |
| 1108 | |
Damien Miller | 06ebedf | 2003-02-24 12:03:38 +1100 | [diff] [blame] | 1109 | /* fake forced command */ |
| 1110 | auth_clear_options(); |
| 1111 | have_forced = buffer_get_int(&m); |
| 1112 | forced_command = have_forced ? xstrdup("true") : NULL; |
| 1113 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1114 | if (allowed && rkey != NULL) { |
| 1115 | blob = buffer_get_string(&m, &blen); |
| 1116 | if ((key = key_from_blob(blob, blen)) == NULL) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1117 | fatal("%s: key_from_blob failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1118 | *rkey = key; |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 1119 | free(blob); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1120 | } |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1121 | buffer_free(&m); |
| 1122 | |
| 1123 | return (allowed); |
| 1124 | } |
| 1125 | |
| 1126 | BIGNUM * |
| 1127 | mm_auth_rsa_generate_challenge(Key *key) |
| 1128 | { |
| 1129 | Buffer m; |
| 1130 | BIGNUM *challenge; |
| 1131 | u_char *blob; |
| 1132 | u_int blen; |
| 1133 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1134 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1135 | |
| 1136 | if ((challenge = BN_new()) == NULL) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1137 | fatal("%s: BN_new failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1138 | |
| 1139 | key->type = KEY_RSA; /* XXX cheat for key_to_blob */ |
| 1140 | if (key_to_blob(key, &blob, &blen) == 0) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1141 | fatal("%s: key_to_blob failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1142 | key->type = KEY_RSA1; |
| 1143 | |
| 1144 | buffer_init(&m); |
| 1145 | buffer_put_string(&m, blob, blen); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 1146 | free(blob); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1147 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1148 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_RSACHALLENGE, &m); |
| 1149 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_RSACHALLENGE, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1150 | |
| 1151 | buffer_get_bignum2(&m, challenge); |
| 1152 | buffer_free(&m); |
| 1153 | |
| 1154 | return (challenge); |
| 1155 | } |
| 1156 | |
| 1157 | int |
| 1158 | mm_auth_rsa_verify_response(Key *key, BIGNUM *p, u_char response[16]) |
| 1159 | { |
| 1160 | Buffer m; |
| 1161 | u_char *blob; |
| 1162 | u_int blen; |
| 1163 | int success = 0; |
| 1164 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1165 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1166 | |
| 1167 | key->type = KEY_RSA; /* XXX cheat for key_to_blob */ |
| 1168 | if (key_to_blob(key, &blob, &blen) == 0) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1169 | fatal("%s: key_to_blob failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1170 | key->type = KEY_RSA1; |
| 1171 | |
| 1172 | buffer_init(&m); |
| 1173 | buffer_put_string(&m, blob, blen); |
| 1174 | buffer_put_string(&m, response, 16); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 1175 | free(blob); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1176 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1177 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_RSARESPONSE, &m); |
| 1178 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_RSARESPONSE, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1179 | |
| 1180 | success = buffer_get_int(&m); |
| 1181 | buffer_free(&m); |
| 1182 | |
| 1183 | return (success); |
| 1184 | } |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 1185 | #endif |
Damien Miller | 25162f2 | 2002-09-12 09:47:29 +1000 | [diff] [blame] | 1186 | |
Darren Tucker | 2e0cf0d | 2005-02-08 21:52:47 +1100 | [diff] [blame] | 1187 | #ifdef SSH_AUDIT_EVENTS |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 1188 | void |
| 1189 | mm_audit_event(ssh_audit_event_t event) |
| 1190 | { |
| 1191 | Buffer m; |
| 1192 | |
| 1193 | debug3("%s entering", __func__); |
| 1194 | |
| 1195 | buffer_init(&m); |
| 1196 | buffer_put_int(&m, event); |
| 1197 | |
| 1198 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_EVENT, &m); |
| 1199 | buffer_free(&m); |
| 1200 | } |
| 1201 | |
| 1202 | void |
| 1203 | mm_audit_run_command(const char *command) |
| 1204 | { |
| 1205 | Buffer m; |
| 1206 | |
| 1207 | debug3("%s entering command %s", __func__, command); |
| 1208 | |
| 1209 | buffer_init(&m); |
| 1210 | buffer_put_cstring(&m, command); |
| 1211 | |
| 1212 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_COMMAND, &m); |
| 1213 | buffer_free(&m); |
| 1214 | } |
Darren Tucker | 2e0cf0d | 2005-02-08 21:52:47 +1100 | [diff] [blame] | 1215 | #endif /* SSH_AUDIT_EVENTS */ |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 1216 | |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1217 | #ifdef GSSAPI |
| 1218 | OM_uint32 |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1219 | mm_ssh_gssapi_server_ctx(Gssctxt **ctx, gss_OID goid) |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1220 | { |
| 1221 | Buffer m; |
| 1222 | OM_uint32 major; |
| 1223 | |
| 1224 | /* Client doesn't get to see the context */ |
| 1225 | *ctx = NULL; |
| 1226 | |
| 1227 | buffer_init(&m); |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1228 | buffer_put_string(&m, goid->elements, goid->length); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1229 | |
| 1230 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSSETUP, &m); |
| 1231 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSSETUP, &m); |
| 1232 | |
| 1233 | major = buffer_get_int(&m); |
| 1234 | |
| 1235 | buffer_free(&m); |
| 1236 | return (major); |
| 1237 | } |
| 1238 | |
| 1239 | OM_uint32 |
| 1240 | mm_ssh_gssapi_accept_ctx(Gssctxt *ctx, gss_buffer_desc *in, |
| 1241 | gss_buffer_desc *out, OM_uint32 *flags) |
| 1242 | { |
| 1243 | Buffer m; |
| 1244 | OM_uint32 major; |
Darren Tucker | 600ad8d | 2003-08-26 12:10:48 +1000 | [diff] [blame] | 1245 | u_int len; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1246 | |
| 1247 | buffer_init(&m); |
| 1248 | buffer_put_string(&m, in->value, in->length); |
| 1249 | |
| 1250 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSSTEP, &m); |
| 1251 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSSTEP, &m); |
| 1252 | |
| 1253 | major = buffer_get_int(&m); |
Darren Tucker | 600ad8d | 2003-08-26 12:10:48 +1000 | [diff] [blame] | 1254 | out->value = buffer_get_string(&m, &len); |
| 1255 | out->length = len; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1256 | if (flags) |
| 1257 | *flags = buffer_get_int(&m); |
| 1258 | |
| 1259 | buffer_free(&m); |
| 1260 | |
| 1261 | return (major); |
| 1262 | } |
| 1263 | |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 1264 | OM_uint32 |
| 1265 | mm_ssh_gssapi_checkmic(Gssctxt *ctx, gss_buffer_t gssbuf, gss_buffer_t gssmic) |
| 1266 | { |
| 1267 | Buffer m; |
| 1268 | OM_uint32 major; |
| 1269 | |
| 1270 | buffer_init(&m); |
| 1271 | buffer_put_string(&m, gssbuf->value, gssbuf->length); |
| 1272 | buffer_put_string(&m, gssmic->value, gssmic->length); |
| 1273 | |
| 1274 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSCHECKMIC, &m); |
| 1275 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSCHECKMIC, |
| 1276 | &m); |
| 1277 | |
| 1278 | major = buffer_get_int(&m); |
| 1279 | buffer_free(&m); |
| 1280 | return(major); |
| 1281 | } |
| 1282 | |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1283 | int |
| 1284 | mm_ssh_gssapi_userok(char *user) |
| 1285 | { |
| 1286 | Buffer m; |
| 1287 | int authenticated = 0; |
| 1288 | |
| 1289 | buffer_init(&m); |
| 1290 | |
| 1291 | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSUSEROK, &m); |
| 1292 | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSUSEROK, |
| 1293 | &m); |
| 1294 | |
| 1295 | authenticated = buffer_get_int(&m); |
| 1296 | |
| 1297 | buffer_free(&m); |
| 1298 | debug3("%s: user %sauthenticated",__func__, authenticated ? "" : "not "); |
| 1299 | return (authenticated); |
| 1300 | } |
| 1301 | #endif /* GSSAPI */ |
Damien Miller | 01ed227 | 2008-11-05 16:20:46 +1100 | [diff] [blame] | 1302 | |