Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2002 Niels Provos <provos@citi.umich.edu> |
| 3 | * Copyright 2002 Markus Friedl <markus@openbsd.org> |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions |
| 8 | * are met: |
| 9 | * 1. Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * 2. Redistributions in binary form must reproduce the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer in the |
| 13 | * documentation and/or other materials provided with the distribution. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | */ |
| 26 | |
| 27 | #include "includes.h" |
Darren Tucker | 47eede7 | 2005-03-14 23:08:12 +1100 | [diff] [blame] | 28 | RCSID("$OpenBSD: monitor.c,v 1.63 2005/03/10 22:01:05 deraadt Exp $"); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 29 | |
| 30 | #include <openssl/dh.h> |
| 31 | |
| 32 | #ifdef SKEY |
| 33 | #include <skey.h> |
| 34 | #endif |
| 35 | |
| 36 | #include "ssh.h" |
| 37 | #include "auth.h" |
| 38 | #include "kex.h" |
| 39 | #include "dh.h" |
Ben Lindstrom | 036768e | 2004-04-08 16:12:30 +0000 | [diff] [blame] | 40 | #ifdef TARGET_OS_MAC /* XXX Broken krb5 headers on Mac */ |
| 41 | #undef TARGET_OS_MAC |
Ben Lindstrom | 1b9f2a6 | 2004-04-08 05:11:03 +0000 | [diff] [blame] | 42 | #include "zlib.h" |
Ben Lindstrom | 036768e | 2004-04-08 16:12:30 +0000 | [diff] [blame] | 43 | #define TARGET_OS_MAC 1 |
| 44 | #else |
| 45 | #include "zlib.h" |
| 46 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 47 | #include "packet.h" |
| 48 | #include "auth-options.h" |
| 49 | #include "sshpty.h" |
| 50 | #include "channels.h" |
| 51 | #include "session.h" |
| 52 | #include "sshlogin.h" |
| 53 | #include "canohost.h" |
| 54 | #include "log.h" |
| 55 | #include "servconf.h" |
| 56 | #include "monitor.h" |
| 57 | #include "monitor_mm.h" |
| 58 | #include "monitor_wrap.h" |
| 59 | #include "monitor_fdpass.h" |
| 60 | #include "xmalloc.h" |
| 61 | #include "misc.h" |
| 62 | #include "buffer.h" |
| 63 | #include "bufaux.h" |
| 64 | #include "compat.h" |
| 65 | #include "ssh2.h" |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 66 | |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 67 | #ifdef GSSAPI |
| 68 | #include "ssh-gss.h" |
| 69 | static Gssctxt *gsscontext = NULL; |
| 70 | #endif |
| 71 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 72 | /* Imports */ |
| 73 | extern ServerOptions options; |
| 74 | extern u_int utmp_len; |
| 75 | extern Newkeys *current_keys[]; |
| 76 | extern z_stream incoming_stream; |
| 77 | extern z_stream outgoing_stream; |
| 78 | extern u_char session_id[]; |
| 79 | extern Buffer input, output; |
| 80 | extern Buffer auth_debug; |
| 81 | extern int auth_debug_init; |
Darren Tucker | 0999174 | 2004-07-17 17:05:14 +1000 | [diff] [blame] | 82 | extern Buffer loginmsg; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 83 | |
| 84 | /* State exported from the child */ |
| 85 | |
| 86 | struct { |
| 87 | z_stream incoming; |
| 88 | z_stream outgoing; |
| 89 | u_char *keyin; |
| 90 | u_int keyinlen; |
| 91 | u_char *keyout; |
| 92 | u_int keyoutlen; |
| 93 | u_char *ivin; |
| 94 | u_int ivinlen; |
| 95 | u_char *ivout; |
| 96 | u_int ivoutlen; |
Ben Lindstrom | 402c6cc | 2002-06-21 00:43:42 +0000 | [diff] [blame] | 97 | u_char *ssh1key; |
| 98 | u_int ssh1keylen; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 99 | int ssh1cipher; |
| 100 | int ssh1protoflags; |
| 101 | u_char *input; |
| 102 | u_int ilen; |
| 103 | u_char *output; |
| 104 | u_int olen; |
| 105 | } child_state; |
| 106 | |
Damien Miller | 469954d | 2003-06-18 20:25:33 +1000 | [diff] [blame] | 107 | /* Functions on the monitor that answer unprivileged requests */ |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 108 | |
| 109 | int mm_answer_moduli(int, Buffer *); |
| 110 | int mm_answer_sign(int, Buffer *); |
| 111 | int mm_answer_pwnamallow(int, Buffer *); |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 112 | int mm_answer_auth2_read_banner(int, Buffer *); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 113 | int mm_answer_authserv(int, Buffer *); |
| 114 | int mm_answer_authpassword(int, Buffer *); |
| 115 | int mm_answer_bsdauthquery(int, Buffer *); |
| 116 | int mm_answer_bsdauthrespond(int, Buffer *); |
| 117 | int mm_answer_skeyquery(int, Buffer *); |
| 118 | int mm_answer_skeyrespond(int, Buffer *); |
| 119 | int mm_answer_keyallowed(int, Buffer *); |
| 120 | int mm_answer_keyverify(int, Buffer *); |
| 121 | int mm_answer_pty(int, Buffer *); |
| 122 | int mm_answer_pty_cleanup(int, Buffer *); |
| 123 | int mm_answer_term(int, Buffer *); |
| 124 | int mm_answer_rsa_keyallowed(int, Buffer *); |
| 125 | int mm_answer_rsa_challenge(int, Buffer *); |
| 126 | int mm_answer_rsa_response(int, Buffer *); |
| 127 | int mm_answer_sesskey(int, Buffer *); |
| 128 | int mm_answer_sessid(int, Buffer *); |
| 129 | |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 130 | #ifdef USE_PAM |
| 131 | int mm_answer_pam_start(int, Buffer *); |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 132 | int mm_answer_pam_account(int, Buffer *); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 133 | int mm_answer_pam_init_ctx(int, Buffer *); |
| 134 | int mm_answer_pam_query(int, Buffer *); |
| 135 | int mm_answer_pam_respond(int, Buffer *); |
| 136 | int mm_answer_pam_free_ctx(int, Buffer *); |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 137 | #endif |
| 138 | |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 139 | #ifdef GSSAPI |
| 140 | int mm_answer_gss_setup_ctx(int, Buffer *); |
| 141 | int mm_answer_gss_accept_ctx(int, Buffer *); |
| 142 | int mm_answer_gss_userok(int, Buffer *); |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 143 | int mm_answer_gss_checkmic(int, Buffer *); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 144 | #endif |
Damien Miller | 25162f2 | 2002-09-12 09:47:29 +1000 | [diff] [blame] | 145 | |
Darren Tucker | 2e0cf0d | 2005-02-08 21:52:47 +1100 | [diff] [blame] | 146 | #ifdef SSH_AUDIT_EVENTS |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 147 | int mm_answer_audit_event(int, Buffer *); |
| 148 | int mm_answer_audit_command(int, Buffer *); |
| 149 | #endif |
| 150 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 151 | static Authctxt *authctxt; |
| 152 | static BIGNUM *ssh1_challenge = NULL; /* used for ssh1 rsa auth */ |
| 153 | |
| 154 | /* local state for key verify */ |
| 155 | static u_char *key_blob = NULL; |
| 156 | static u_int key_bloblen = 0; |
| 157 | static int key_blobtype = MM_NOKEY; |
Damien Miller | a10f561 | 2002-09-12 09:49:15 +1000 | [diff] [blame] | 158 | static char *hostbased_cuser = NULL; |
| 159 | static char *hostbased_chost = NULL; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 160 | static char *auth_method = "unknown"; |
Darren Tucker | 502d384 | 2003-06-28 12:38:01 +1000 | [diff] [blame] | 161 | static u_int session_id2_len = 0; |
Ben Lindstrom | f67e077 | 2002-06-06 20:58:19 +0000 | [diff] [blame] | 162 | static u_char *session_id2 = NULL; |
Damien Miller | be64d43 | 2003-05-14 19:31:12 +1000 | [diff] [blame] | 163 | static pid_t monitor_child_pid; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 164 | |
| 165 | struct mon_table { |
| 166 | enum monitor_reqtype type; |
| 167 | int flags; |
| 168 | int (*f)(int, Buffer *); |
| 169 | }; |
| 170 | |
| 171 | #define MON_ISAUTH 0x0004 /* Required for Authentication */ |
| 172 | #define MON_AUTHDECIDE 0x0008 /* Decides Authentication */ |
| 173 | #define MON_ONCE 0x0010 /* Disable after calling */ |
| 174 | |
| 175 | #define MON_AUTH (MON_ISAUTH|MON_AUTHDECIDE) |
| 176 | |
| 177 | #define MON_PERMIT 0x1000 /* Request is permitted */ |
| 178 | |
| 179 | struct mon_table mon_dispatch_proto20[] = { |
| 180 | {MONITOR_REQ_MODULI, MON_ONCE, mm_answer_moduli}, |
| 181 | {MONITOR_REQ_SIGN, MON_ONCE, mm_answer_sign}, |
| 182 | {MONITOR_REQ_PWNAM, MON_ONCE, mm_answer_pwnamallow}, |
| 183 | {MONITOR_REQ_AUTHSERV, MON_ONCE, mm_answer_authserv}, |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 184 | {MONITOR_REQ_AUTH2_READ_BANNER, MON_ONCE, mm_answer_auth2_read_banner}, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 185 | {MONITOR_REQ_AUTHPASSWORD, MON_AUTH, mm_answer_authpassword}, |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 186 | #ifdef USE_PAM |
| 187 | {MONITOR_REQ_PAM_START, MON_ONCE, mm_answer_pam_start}, |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 188 | {MONITOR_REQ_PAM_ACCOUNT, 0, mm_answer_pam_account}, |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 189 | {MONITOR_REQ_PAM_INIT_CTX, MON_ISAUTH, mm_answer_pam_init_ctx}, |
| 190 | {MONITOR_REQ_PAM_QUERY, MON_ISAUTH, mm_answer_pam_query}, |
| 191 | {MONITOR_REQ_PAM_RESPOND, MON_ISAUTH, mm_answer_pam_respond}, |
| 192 | {MONITOR_REQ_PAM_FREE_CTX, MON_ONCE|MON_AUTHDECIDE, mm_answer_pam_free_ctx}, |
Kevin Steves | bd1901b | 2002-04-01 18:04:35 +0000 | [diff] [blame] | 193 | #endif |
Darren Tucker | 2e0cf0d | 2005-02-08 21:52:47 +1100 | [diff] [blame] | 194 | #ifdef SSH_AUDIT_EVENTS |
Darren Tucker | 3745e2b | 2005-03-06 22:31:35 +1100 | [diff] [blame] | 195 | {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event}, |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 196 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 197 | #ifdef BSD_AUTH |
| 198 | {MONITOR_REQ_BSDAUTHQUERY, MON_ISAUTH, mm_answer_bsdauthquery}, |
| 199 | {MONITOR_REQ_BSDAUTHRESPOND, MON_AUTH,mm_answer_bsdauthrespond}, |
| 200 | #endif |
| 201 | #ifdef SKEY |
| 202 | {MONITOR_REQ_SKEYQUERY, MON_ISAUTH, mm_answer_skeyquery}, |
| 203 | {MONITOR_REQ_SKEYRESPOND, MON_AUTH, mm_answer_skeyrespond}, |
| 204 | #endif |
| 205 | {MONITOR_REQ_KEYALLOWED, MON_ISAUTH, mm_answer_keyallowed}, |
| 206 | {MONITOR_REQ_KEYVERIFY, MON_AUTH, mm_answer_keyverify}, |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 207 | #ifdef GSSAPI |
| 208 | {MONITOR_REQ_GSSSETUP, MON_ISAUTH, mm_answer_gss_setup_ctx}, |
| 209 | {MONITOR_REQ_GSSSTEP, MON_ISAUTH, mm_answer_gss_accept_ctx}, |
| 210 | {MONITOR_REQ_GSSUSEROK, MON_AUTH, mm_answer_gss_userok}, |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 211 | {MONITOR_REQ_GSSCHECKMIC, MON_ISAUTH, mm_answer_gss_checkmic}, |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 212 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 213 | {0, 0, NULL} |
| 214 | }; |
| 215 | |
| 216 | struct mon_table mon_dispatch_postauth20[] = { |
| 217 | {MONITOR_REQ_MODULI, 0, mm_answer_moduli}, |
| 218 | {MONITOR_REQ_SIGN, 0, mm_answer_sign}, |
| 219 | {MONITOR_REQ_PTY, 0, mm_answer_pty}, |
| 220 | {MONITOR_REQ_PTYCLEANUP, 0, mm_answer_pty_cleanup}, |
| 221 | {MONITOR_REQ_TERM, 0, mm_answer_term}, |
Darren Tucker | 2e0cf0d | 2005-02-08 21:52:47 +1100 | [diff] [blame] | 222 | #ifdef SSH_AUDIT_EVENTS |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 223 | {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event}, |
| 224 | {MONITOR_REQ_AUDIT_COMMAND, MON_PERMIT, mm_answer_audit_command}, |
| 225 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 226 | {0, 0, NULL} |
| 227 | }; |
| 228 | |
| 229 | struct mon_table mon_dispatch_proto15[] = { |
| 230 | {MONITOR_REQ_PWNAM, MON_ONCE, mm_answer_pwnamallow}, |
| 231 | {MONITOR_REQ_SESSKEY, MON_ONCE, mm_answer_sesskey}, |
| 232 | {MONITOR_REQ_SESSID, MON_ONCE, mm_answer_sessid}, |
| 233 | {MONITOR_REQ_AUTHPASSWORD, MON_AUTH, mm_answer_authpassword}, |
| 234 | {MONITOR_REQ_RSAKEYALLOWED, MON_ISAUTH, mm_answer_rsa_keyallowed}, |
| 235 | {MONITOR_REQ_KEYALLOWED, MON_ISAUTH, mm_answer_keyallowed}, |
| 236 | {MONITOR_REQ_RSACHALLENGE, MON_ONCE, mm_answer_rsa_challenge}, |
| 237 | {MONITOR_REQ_RSARESPONSE, MON_ONCE|MON_AUTHDECIDE, mm_answer_rsa_response}, |
| 238 | #ifdef BSD_AUTH |
| 239 | {MONITOR_REQ_BSDAUTHQUERY, MON_ISAUTH, mm_answer_bsdauthquery}, |
| 240 | {MONITOR_REQ_BSDAUTHRESPOND, MON_AUTH,mm_answer_bsdauthrespond}, |
| 241 | #endif |
| 242 | #ifdef SKEY |
| 243 | {MONITOR_REQ_SKEYQUERY, MON_ISAUTH, mm_answer_skeyquery}, |
| 244 | {MONITOR_REQ_SKEYRESPOND, MON_AUTH, mm_answer_skeyrespond}, |
| 245 | #endif |
Damien Miller | a33501b | 2002-05-08 12:24:42 +1000 | [diff] [blame] | 246 | #ifdef USE_PAM |
| 247 | {MONITOR_REQ_PAM_START, MON_ONCE, mm_answer_pam_start}, |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 248 | {MONITOR_REQ_PAM_ACCOUNT, 0, mm_answer_pam_account}, |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 249 | {MONITOR_REQ_PAM_INIT_CTX, MON_ISAUTH, mm_answer_pam_init_ctx}, |
| 250 | {MONITOR_REQ_PAM_QUERY, MON_ISAUTH, mm_answer_pam_query}, |
| 251 | {MONITOR_REQ_PAM_RESPOND, MON_ISAUTH, mm_answer_pam_respond}, |
| 252 | {MONITOR_REQ_PAM_FREE_CTX, MON_ONCE|MON_AUTHDECIDE, mm_answer_pam_free_ctx}, |
Damien Miller | a33501b | 2002-05-08 12:24:42 +1000 | [diff] [blame] | 253 | #endif |
Darren Tucker | 2e0cf0d | 2005-02-08 21:52:47 +1100 | [diff] [blame] | 254 | #ifdef SSH_AUDIT_EVENTS |
Darren Tucker | 3745e2b | 2005-03-06 22:31:35 +1100 | [diff] [blame] | 255 | {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event}, |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 256 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 257 | {0, 0, NULL} |
| 258 | }; |
| 259 | |
| 260 | struct mon_table mon_dispatch_postauth15[] = { |
| 261 | {MONITOR_REQ_PTY, MON_ONCE, mm_answer_pty}, |
| 262 | {MONITOR_REQ_PTYCLEANUP, MON_ONCE, mm_answer_pty_cleanup}, |
| 263 | {MONITOR_REQ_TERM, 0, mm_answer_term}, |
Darren Tucker | 2e0cf0d | 2005-02-08 21:52:47 +1100 | [diff] [blame] | 264 | #ifdef SSH_AUDIT_EVENTS |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 265 | {MONITOR_REQ_AUDIT_EVENT, MON_PERMIT, mm_answer_audit_event}, |
Darren Tucker | 3745e2b | 2005-03-06 22:31:35 +1100 | [diff] [blame] | 266 | {MONITOR_REQ_AUDIT_COMMAND, MON_ONCE, mm_answer_audit_command}, |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 267 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 268 | {0, 0, NULL} |
| 269 | }; |
| 270 | |
| 271 | struct mon_table *mon_dispatch; |
| 272 | |
| 273 | /* Specifies if a certain message is allowed at the moment */ |
| 274 | |
| 275 | static void |
| 276 | monitor_permit(struct mon_table *ent, enum monitor_reqtype type, int permit) |
| 277 | { |
| 278 | while (ent->f != NULL) { |
| 279 | if (ent->type == type) { |
| 280 | ent->flags &= ~MON_PERMIT; |
| 281 | ent->flags |= permit ? MON_PERMIT : 0; |
| 282 | return; |
| 283 | } |
| 284 | ent++; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | static void |
| 289 | monitor_permit_authentications(int permit) |
| 290 | { |
| 291 | struct mon_table *ent = mon_dispatch; |
| 292 | |
| 293 | while (ent->f != NULL) { |
| 294 | if (ent->flags & MON_AUTH) { |
| 295 | ent->flags &= ~MON_PERMIT; |
| 296 | ent->flags |= permit ? MON_PERMIT : 0; |
| 297 | } |
| 298 | ent++; |
| 299 | } |
| 300 | } |
| 301 | |
Darren Tucker | 3e33cec | 2003-10-02 16:12:36 +1000 | [diff] [blame] | 302 | void |
| 303 | monitor_child_preauth(Authctxt *_authctxt, struct monitor *pmonitor) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 304 | { |
| 305 | struct mon_table *ent; |
| 306 | int authenticated = 0; |
| 307 | |
| 308 | debug3("preauth child monitor started"); |
| 309 | |
Darren Tucker | 3e33cec | 2003-10-02 16:12:36 +1000 | [diff] [blame] | 310 | authctxt = _authctxt; |
| 311 | memset(authctxt, 0, sizeof(*authctxt)); |
| 312 | |
Darren Tucker | de0de39 | 2005-03-31 23:52:04 +1000 | [diff] [blame] | 313 | authctxt->loginmsg = &loginmsg; |
| 314 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 315 | if (compat20) { |
| 316 | mon_dispatch = mon_dispatch_proto20; |
| 317 | |
| 318 | /* Permit requests for moduli and signatures */ |
| 319 | monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1); |
| 320 | monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1); |
| 321 | } else { |
| 322 | mon_dispatch = mon_dispatch_proto15; |
| 323 | |
| 324 | monitor_permit(mon_dispatch, MONITOR_REQ_SESSKEY, 1); |
| 325 | } |
| 326 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 327 | /* The first few requests do not require asynchronous access */ |
| 328 | while (!authenticated) { |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 329 | authenticated = monitor_read(pmonitor, mon_dispatch, &ent); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 330 | if (authenticated) { |
| 331 | if (!(ent->flags & MON_AUTHDECIDE)) |
| 332 | fatal("%s: unexpected authentication from %d", |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 333 | __func__, ent->type); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 334 | if (authctxt->pw->pw_uid == 0 && |
| 335 | !auth_root_allowed(auth_method)) |
| 336 | authenticated = 0; |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 337 | #ifdef USE_PAM |
| 338 | /* PAM needs to perform account checks after auth */ |
Damien Miller | 6aef38f | 2003-11-18 10:45:20 +1100 | [diff] [blame] | 339 | if (options.use_pam && authenticated) { |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 340 | Buffer m; |
| 341 | |
| 342 | buffer_init(&m); |
Damien Miller | a8e06ce | 2003-11-21 23:48:55 +1100 | [diff] [blame] | 343 | mm_request_receive_expect(pmonitor->m_sendfd, |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 344 | MONITOR_REQ_PAM_ACCOUNT, &m); |
| 345 | authenticated = mm_answer_pam_account(pmonitor->m_sendfd, &m); |
| 346 | buffer_free(&m); |
| 347 | } |
| 348 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | if (ent->flags & MON_AUTHDECIDE) { |
| 352 | auth_log(authctxt, authenticated, auth_method, |
| 353 | compat20 ? " ssh2" : ""); |
| 354 | if (!authenticated) |
| 355 | authctxt->failures++; |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | if (!authctxt->valid) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 360 | fatal("%s: authenticated invalid user", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 361 | |
| 362 | debug("%s: %s has been authenticated by privileged process", |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 363 | __func__, authctxt->user); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 364 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 365 | mm_get_keystate(pmonitor); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 366 | } |
| 367 | |
Damien Miller | be64d43 | 2003-05-14 19:31:12 +1000 | [diff] [blame] | 368 | static void |
| 369 | monitor_set_child_handler(pid_t pid) |
| 370 | { |
| 371 | monitor_child_pid = pid; |
| 372 | } |
| 373 | |
| 374 | static void |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 375 | monitor_child_handler(int sig) |
Damien Miller | be64d43 | 2003-05-14 19:31:12 +1000 | [diff] [blame] | 376 | { |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 377 | kill(monitor_child_pid, sig); |
Damien Miller | be64d43 | 2003-05-14 19:31:12 +1000 | [diff] [blame] | 378 | } |
| 379 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 380 | void |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 381 | monitor_child_postauth(struct monitor *pmonitor) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 382 | { |
Damien Miller | be64d43 | 2003-05-14 19:31:12 +1000 | [diff] [blame] | 383 | monitor_set_child_handler(pmonitor->m_pid); |
| 384 | signal(SIGHUP, &monitor_child_handler); |
| 385 | signal(SIGTERM, &monitor_child_handler); |
| 386 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 387 | if (compat20) { |
| 388 | mon_dispatch = mon_dispatch_postauth20; |
| 389 | |
| 390 | /* Permit requests for moduli and signatures */ |
| 391 | monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1); |
| 392 | monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1); |
| 393 | monitor_permit(mon_dispatch, MONITOR_REQ_TERM, 1); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 394 | } else { |
| 395 | mon_dispatch = mon_dispatch_postauth15; |
| 396 | monitor_permit(mon_dispatch, MONITOR_REQ_TERM, 1); |
| 397 | } |
| 398 | if (!no_pty_flag) { |
| 399 | monitor_permit(mon_dispatch, MONITOR_REQ_PTY, 1); |
| 400 | monitor_permit(mon_dispatch, MONITOR_REQ_PTYCLEANUP, 1); |
| 401 | } |
| 402 | |
| 403 | for (;;) |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 404 | monitor_read(pmonitor, mon_dispatch, NULL); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | void |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 408 | monitor_sync(struct monitor *pmonitor) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 409 | { |
Damien Miller | 2d6b833 | 2002-06-21 15:59:49 +1000 | [diff] [blame] | 410 | if (options.compression) { |
| 411 | /* The member allocation is not visible, so sync it */ |
| 412 | mm_share_sync(&pmonitor->m_zlib, &pmonitor->m_zback); |
| 413 | } |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | int |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 417 | monitor_read(struct monitor *pmonitor, struct mon_table *ent, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 418 | struct mon_table **pent) |
| 419 | { |
| 420 | Buffer m; |
| 421 | int ret; |
| 422 | u_char type; |
| 423 | |
| 424 | buffer_init(&m); |
| 425 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 426 | mm_request_receive(pmonitor->m_sendfd, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 427 | type = buffer_get_char(&m); |
| 428 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 429 | debug3("%s: checking request %d", __func__, type); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 430 | |
| 431 | while (ent->f != NULL) { |
| 432 | if (ent->type == type) |
| 433 | break; |
| 434 | ent++; |
| 435 | } |
| 436 | |
| 437 | if (ent->f != NULL) { |
| 438 | if (!(ent->flags & MON_PERMIT)) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 439 | fatal("%s: unpermitted request %d", __func__, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 440 | type); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 441 | ret = (*ent->f)(pmonitor->m_sendfd, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 442 | buffer_free(&m); |
| 443 | |
| 444 | /* The child may use this request only once, disable it */ |
| 445 | if (ent->flags & MON_ONCE) { |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 446 | debug2("%s: %d used once, disabling now", __func__, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 447 | type); |
| 448 | ent->flags &= ~MON_PERMIT; |
| 449 | } |
| 450 | |
| 451 | if (pent != NULL) |
| 452 | *pent = ent; |
| 453 | |
| 454 | return ret; |
| 455 | } |
| 456 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 457 | fatal("%s: unsupported request: %d", __func__, type); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 458 | |
| 459 | /* NOTREACHED */ |
| 460 | return (-1); |
| 461 | } |
| 462 | |
| 463 | /* allowed key state */ |
| 464 | static int |
| 465 | monitor_allowed_key(u_char *blob, u_int bloblen) |
| 466 | { |
| 467 | /* make sure key is allowed */ |
| 468 | if (key_blob == NULL || key_bloblen != bloblen || |
| 469 | memcmp(key_blob, blob, key_bloblen)) |
| 470 | return (0); |
| 471 | return (1); |
| 472 | } |
| 473 | |
| 474 | static void |
| 475 | monitor_reset_key_state(void) |
| 476 | { |
| 477 | /* reset state */ |
| 478 | if (key_blob != NULL) |
| 479 | xfree(key_blob); |
| 480 | if (hostbased_cuser != NULL) |
| 481 | xfree(hostbased_cuser); |
| 482 | if (hostbased_chost != NULL) |
| 483 | xfree(hostbased_chost); |
| 484 | key_blob = NULL; |
| 485 | key_bloblen = 0; |
| 486 | key_blobtype = MM_NOKEY; |
| 487 | hostbased_cuser = NULL; |
| 488 | hostbased_chost = NULL; |
| 489 | } |
| 490 | |
| 491 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 492 | mm_answer_moduli(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 493 | { |
| 494 | DH *dh; |
| 495 | int min, want, max; |
| 496 | |
| 497 | min = buffer_get_int(m); |
| 498 | want = buffer_get_int(m); |
| 499 | max = buffer_get_int(m); |
| 500 | |
| 501 | debug3("%s: got parameters: %d %d %d", |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 502 | __func__, min, want, max); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 503 | /* We need to check here, too, in case the child got corrupted */ |
| 504 | if (max < min || want < min || max < want) |
| 505 | fatal("%s: bad parameters: %d %d %d", |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 506 | __func__, min, want, max); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 507 | |
| 508 | buffer_clear(m); |
| 509 | |
| 510 | dh = choose_dh(min, want, max); |
| 511 | if (dh == NULL) { |
| 512 | buffer_put_char(m, 0); |
| 513 | return (0); |
| 514 | } else { |
| 515 | /* Send first bignum */ |
| 516 | buffer_put_char(m, 1); |
| 517 | buffer_put_bignum2(m, dh->p); |
| 518 | buffer_put_bignum2(m, dh->g); |
| 519 | |
| 520 | DH_free(dh); |
| 521 | } |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 522 | mm_request_send(sock, MONITOR_ANS_MODULI, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 523 | return (0); |
| 524 | } |
| 525 | |
| 526 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 527 | mm_answer_sign(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 528 | { |
| 529 | Key *key; |
| 530 | u_char *p; |
| 531 | u_char *signature; |
| 532 | u_int siglen, datlen; |
| 533 | int keyid; |
| 534 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 535 | debug3("%s", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 536 | |
| 537 | keyid = buffer_get_int(m); |
| 538 | p = buffer_get_string(m, &datlen); |
| 539 | |
| 540 | if (datlen != 20) |
Ben Lindstrom | d550218 | 2002-06-27 00:12:57 +0000 | [diff] [blame] | 541 | fatal("%s: data length incorrect: %u", __func__, datlen); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 542 | |
Ben Lindstrom | f67e077 | 2002-06-06 20:58:19 +0000 | [diff] [blame] | 543 | /* save session id, it will be passed on the first call */ |
| 544 | if (session_id2_len == 0) { |
| 545 | session_id2_len = datlen; |
| 546 | session_id2 = xmalloc(session_id2_len); |
| 547 | memcpy(session_id2, p, session_id2_len); |
| 548 | } |
| 549 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 550 | if ((key = get_hostkey_by_index(keyid)) == NULL) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 551 | fatal("%s: no hostkey from index %d", __func__, keyid); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 552 | if (key_sign(key, &signature, &siglen, p, datlen) < 0) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 553 | fatal("%s: key_sign failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 554 | |
Ben Lindstrom | d550218 | 2002-06-27 00:12:57 +0000 | [diff] [blame] | 555 | debug3("%s: signature %p(%u)", __func__, signature, siglen); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 556 | |
| 557 | buffer_clear(m); |
| 558 | buffer_put_string(m, signature, siglen); |
| 559 | |
| 560 | xfree(p); |
| 561 | xfree(signature); |
| 562 | |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 563 | mm_request_send(sock, MONITOR_ANS_SIGN, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 564 | |
| 565 | /* Turn on permissions for getpwnam */ |
| 566 | monitor_permit(mon_dispatch, MONITOR_REQ_PWNAM, 1); |
| 567 | |
| 568 | return (0); |
| 569 | } |
| 570 | |
| 571 | /* Retrieves the password entry and also checks if the user is permitted */ |
| 572 | |
| 573 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 574 | mm_answer_pwnamallow(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 575 | { |
Darren Tucker | b09b677 | 2004-06-22 15:06:46 +1000 | [diff] [blame] | 576 | char *username; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 577 | struct passwd *pwent; |
| 578 | int allowed = 0; |
| 579 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 580 | debug3("%s", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 581 | |
| 582 | if (authctxt->attempt++ != 0) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 583 | fatal("%s: multiple attempts for getpwnam", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 584 | |
Darren Tucker | b09b677 | 2004-06-22 15:06:46 +1000 | [diff] [blame] | 585 | username = buffer_get_string(m, NULL); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 586 | |
Darren Tucker | b09b677 | 2004-06-22 15:06:46 +1000 | [diff] [blame] | 587 | pwent = getpwnamallow(username); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 588 | |
Darren Tucker | b09b677 | 2004-06-22 15:06:46 +1000 | [diff] [blame] | 589 | authctxt->user = xstrdup(username); |
| 590 | setproctitle("%s [priv]", pwent ? username : "unknown"); |
| 591 | xfree(username); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 592 | |
| 593 | buffer_clear(m); |
| 594 | |
| 595 | if (pwent == NULL) { |
| 596 | buffer_put_char(m, 0); |
Damien Miller | f96d183 | 2003-11-18 22:01:48 +1100 | [diff] [blame] | 597 | authctxt->pw = fakepw(); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 598 | goto out; |
| 599 | } |
| 600 | |
| 601 | allowed = 1; |
| 602 | authctxt->pw = pwent; |
| 603 | authctxt->valid = 1; |
| 604 | |
| 605 | buffer_put_char(m, 1); |
| 606 | buffer_put_string(m, pwent, sizeof(struct passwd)); |
| 607 | buffer_put_cstring(m, pwent->pw_name); |
| 608 | buffer_put_cstring(m, "*"); |
| 609 | buffer_put_cstring(m, pwent->pw_gecos); |
Kevin Steves | 7e14760 | 2002-03-22 18:07:17 +0000 | [diff] [blame] | 610 | #ifdef HAVE_PW_CLASS_IN_PASSWD |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 611 | buffer_put_cstring(m, pwent->pw_class); |
Kevin Steves | 7e14760 | 2002-03-22 18:07:17 +0000 | [diff] [blame] | 612 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 613 | buffer_put_cstring(m, pwent->pw_dir); |
| 614 | buffer_put_cstring(m, pwent->pw_shell); |
| 615 | |
| 616 | out: |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 617 | debug3("%s: sending MONITOR_ANS_PWNAM: %d", __func__, allowed); |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 618 | mm_request_send(sock, MONITOR_ANS_PWNAM, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 619 | |
| 620 | /* For SSHv1 allow authentication now */ |
| 621 | if (!compat20) |
| 622 | monitor_permit_authentications(1); |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 623 | else { |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 624 | /* Allow service/style information on the auth context */ |
| 625 | monitor_permit(mon_dispatch, MONITOR_REQ_AUTHSERV, 1); |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 626 | monitor_permit(mon_dispatch, MONITOR_REQ_AUTH2_READ_BANNER, 1); |
| 627 | } |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 628 | |
Damien Miller | a33501b | 2002-05-08 12:24:42 +1000 | [diff] [blame] | 629 | #ifdef USE_PAM |
Damien Miller | 4e448a3 | 2003-05-14 15:11:48 +1000 | [diff] [blame] | 630 | if (options.use_pam) |
| 631 | monitor_permit(mon_dispatch, MONITOR_REQ_PAM_START, 1); |
Damien Miller | a33501b | 2002-05-08 12:24:42 +1000 | [diff] [blame] | 632 | #endif |
Darren Tucker | 2e0cf0d | 2005-02-08 21:52:47 +1100 | [diff] [blame] | 633 | #ifdef SSH_AUDIT_EVENTS |
Darren Tucker | 3745e2b | 2005-03-06 22:31:35 +1100 | [diff] [blame] | 634 | monitor_permit(mon_dispatch, MONITOR_REQ_AUDIT_COMMAND, 1); |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 635 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 636 | |
| 637 | return (0); |
| 638 | } |
| 639 | |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 640 | int mm_answer_auth2_read_banner(int sock, Buffer *m) |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 641 | { |
| 642 | char *banner; |
| 643 | |
| 644 | buffer_clear(m); |
| 645 | banner = auth2_read_banner(); |
| 646 | buffer_put_cstring(m, banner != NULL ? banner : ""); |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 647 | mm_request_send(sock, MONITOR_ANS_AUTH2_READ_BANNER, m); |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 648 | |
| 649 | if (banner != NULL) |
Ben Lindstrom | eec16fc | 2002-07-04 00:06:15 +0000 | [diff] [blame] | 650 | xfree(banner); |
Damien Miller | 5ad9fd9 | 2002-05-13 11:07:41 +1000 | [diff] [blame] | 651 | |
| 652 | return (0); |
| 653 | } |
| 654 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 655 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 656 | mm_answer_authserv(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 657 | { |
| 658 | monitor_permit_authentications(1); |
| 659 | |
| 660 | authctxt->service = buffer_get_string(m, NULL); |
| 661 | authctxt->style = buffer_get_string(m, NULL); |
| 662 | debug3("%s: service=%s, style=%s", |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 663 | __func__, authctxt->service, authctxt->style); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 664 | |
| 665 | if (strlen(authctxt->style) == 0) { |
| 666 | xfree(authctxt->style); |
| 667 | authctxt->style = NULL; |
| 668 | } |
| 669 | |
| 670 | return (0); |
| 671 | } |
| 672 | |
| 673 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 674 | mm_answer_authpassword(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 675 | { |
| 676 | static int call_count; |
| 677 | char *passwd; |
Ben Lindstrom | 7cea16b | 2002-07-23 21:13:40 +0000 | [diff] [blame] | 678 | int authenticated; |
| 679 | u_int plen; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 680 | |
| 681 | passwd = buffer_get_string(m, &plen); |
| 682 | /* Only authenticate if the context is valid */ |
Ben Lindstrom | dcf6bfb | 2002-06-06 20:57:17 +0000 | [diff] [blame] | 683 | authenticated = options.password_authentication && |
Damien Miller | 856f0be | 2003-09-03 07:32:45 +1000 | [diff] [blame] | 684 | auth_password(authctxt, passwd); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 685 | memset(passwd, 0, strlen(passwd)); |
| 686 | xfree(passwd); |
| 687 | |
| 688 | buffer_clear(m); |
| 689 | buffer_put_int(m, authenticated); |
| 690 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 691 | debug3("%s: sending result %d", __func__, authenticated); |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 692 | mm_request_send(sock, MONITOR_ANS_AUTHPASSWORD, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 693 | |
| 694 | call_count++; |
| 695 | if (plen == 0 && call_count == 1) |
| 696 | auth_method = "none"; |
| 697 | else |
| 698 | auth_method = "password"; |
| 699 | |
| 700 | /* Causes monitor loop to terminate if authenticated */ |
| 701 | return (authenticated); |
| 702 | } |
| 703 | |
| 704 | #ifdef BSD_AUTH |
| 705 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 706 | mm_answer_bsdauthquery(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 707 | { |
| 708 | char *name, *infotxt; |
| 709 | u_int numprompts; |
| 710 | u_int *echo_on; |
| 711 | char **prompts; |
Damien Miller | b7df3af | 2003-02-24 11:55:46 +1100 | [diff] [blame] | 712 | u_int success; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 713 | |
Damien Miller | b7df3af | 2003-02-24 11:55:46 +1100 | [diff] [blame] | 714 | success = bsdauth_query(authctxt, &name, &infotxt, &numprompts, |
| 715 | &prompts, &echo_on) < 0 ? 0 : 1; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 716 | |
| 717 | buffer_clear(m); |
Damien Miller | b7df3af | 2003-02-24 11:55:46 +1100 | [diff] [blame] | 718 | buffer_put_int(m, success); |
| 719 | if (success) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 720 | buffer_put_cstring(m, prompts[0]); |
| 721 | |
Damien Miller | b7df3af | 2003-02-24 11:55:46 +1100 | [diff] [blame] | 722 | debug3("%s: sending challenge success: %u", __func__, success); |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 723 | mm_request_send(sock, MONITOR_ANS_BSDAUTHQUERY, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 724 | |
Damien Miller | b7df3af | 2003-02-24 11:55:46 +1100 | [diff] [blame] | 725 | if (success) { |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 726 | xfree(name); |
| 727 | xfree(infotxt); |
| 728 | xfree(prompts); |
| 729 | xfree(echo_on); |
| 730 | } |
| 731 | |
| 732 | return (0); |
| 733 | } |
| 734 | |
| 735 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 736 | mm_answer_bsdauthrespond(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 737 | { |
| 738 | char *response; |
| 739 | int authok; |
| 740 | |
| 741 | if (authctxt->as == 0) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 742 | fatal("%s: no bsd auth session", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 743 | |
| 744 | response = buffer_get_string(m, NULL); |
Ben Lindstrom | dcf6bfb | 2002-06-06 20:57:17 +0000 | [diff] [blame] | 745 | authok = options.challenge_response_authentication && |
| 746 | auth_userresponse(authctxt->as, response, 0); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 747 | authctxt->as = NULL; |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 748 | debug3("%s: <%s> = <%d>", __func__, response, authok); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 749 | xfree(response); |
| 750 | |
| 751 | buffer_clear(m); |
| 752 | buffer_put_int(m, authok); |
| 753 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 754 | debug3("%s: sending authenticated: %d", __func__, authok); |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 755 | mm_request_send(sock, MONITOR_ANS_BSDAUTHRESPOND, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 756 | |
| 757 | auth_method = "bsdauth"; |
| 758 | |
| 759 | return (authok != 0); |
| 760 | } |
| 761 | #endif |
| 762 | |
| 763 | #ifdef SKEY |
| 764 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 765 | mm_answer_skeyquery(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 766 | { |
| 767 | struct skey skey; |
| 768 | char challenge[1024]; |
Damien Miller | b7df3af | 2003-02-24 11:55:46 +1100 | [diff] [blame] | 769 | u_int success; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 770 | |
Darren Tucker | 06a8cfe | 2004-04-14 17:24:30 +1000 | [diff] [blame] | 771 | success = _compat_skeychallenge(&skey, authctxt->user, challenge, |
| 772 | sizeof(challenge)) < 0 ? 0 : 1; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 773 | |
| 774 | buffer_clear(m); |
Damien Miller | b7df3af | 2003-02-24 11:55:46 +1100 | [diff] [blame] | 775 | buffer_put_int(m, success); |
| 776 | if (success) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 777 | buffer_put_cstring(m, challenge); |
| 778 | |
Damien Miller | b7df3af | 2003-02-24 11:55:46 +1100 | [diff] [blame] | 779 | debug3("%s: sending challenge success: %u", __func__, success); |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 780 | mm_request_send(sock, MONITOR_ANS_SKEYQUERY, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 781 | |
| 782 | return (0); |
| 783 | } |
| 784 | |
| 785 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 786 | mm_answer_skeyrespond(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 787 | { |
| 788 | char *response; |
| 789 | int authok; |
| 790 | |
| 791 | response = buffer_get_string(m, NULL); |
| 792 | |
Ben Lindstrom | dcf6bfb | 2002-06-06 20:57:17 +0000 | [diff] [blame] | 793 | authok = (options.challenge_response_authentication && |
| 794 | authctxt->valid && |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 795 | skey_haskey(authctxt->pw->pw_name) == 0 && |
| 796 | skey_passcheck(authctxt->pw->pw_name, response) != -1); |
| 797 | |
| 798 | xfree(response); |
| 799 | |
| 800 | buffer_clear(m); |
| 801 | buffer_put_int(m, authok); |
| 802 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 803 | debug3("%s: sending authenticated: %d", __func__, authok); |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 804 | mm_request_send(sock, MONITOR_ANS_SKEYRESPOND, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 805 | |
| 806 | auth_method = "skey"; |
| 807 | |
| 808 | return (authok != 0); |
| 809 | } |
| 810 | #endif |
| 811 | |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 812 | #ifdef USE_PAM |
| 813 | int |
Darren Tucker | 7eda592 | 2004-06-22 13:22:50 +1000 | [diff] [blame] | 814 | mm_answer_pam_start(int sock, Buffer *m) |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 815 | { |
Damien Miller | 4e448a3 | 2003-05-14 15:11:48 +1000 | [diff] [blame] | 816 | if (!options.use_pam) |
| 817 | fatal("UsePAM not set, but ended up in %s anyway", __func__); |
| 818 | |
Darren Tucker | dbf7a74 | 2004-03-08 23:04:06 +1100 | [diff] [blame] | 819 | start_pam(authctxt); |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 820 | |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 821 | monitor_permit(mon_dispatch, MONITOR_REQ_PAM_ACCOUNT, 1); |
| 822 | |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 823 | return (0); |
| 824 | } |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 825 | |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 826 | int |
Darren Tucker | 7eda592 | 2004-06-22 13:22:50 +1000 | [diff] [blame] | 827 | mm_answer_pam_account(int sock, Buffer *m) |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 828 | { |
| 829 | u_int ret; |
Damien Miller | 787b2ec | 2003-11-21 23:56:47 +1100 | [diff] [blame] | 830 | |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 831 | if (!options.use_pam) |
| 832 | fatal("UsePAM not set, but ended up in %s anyway", __func__); |
| 833 | |
| 834 | ret = do_pam_account(); |
| 835 | |
| 836 | buffer_put_int(m, ret); |
Darren Tucker | 77fc29e | 2004-09-11 23:07:03 +1000 | [diff] [blame] | 837 | buffer_append(&loginmsg, "\0", 1); |
| 838 | buffer_put_cstring(m, buffer_ptr(&loginmsg)); |
| 839 | buffer_clear(&loginmsg); |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 840 | |
Darren Tucker | 7eda592 | 2004-06-22 13:22:50 +1000 | [diff] [blame] | 841 | mm_request_send(sock, MONITOR_ANS_PAM_ACCOUNT, m); |
Damien Miller | 1f499fd | 2003-08-25 13:08:49 +1000 | [diff] [blame] | 842 | |
| 843 | return (ret); |
| 844 | } |
| 845 | |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 846 | static void *sshpam_ctxt, *sshpam_authok; |
| 847 | extern KbdintDevice sshpam_device; |
| 848 | |
| 849 | int |
Darren Tucker | 7eda592 | 2004-06-22 13:22:50 +1000 | [diff] [blame] | 850 | mm_answer_pam_init_ctx(int sock, Buffer *m) |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 851 | { |
| 852 | |
| 853 | debug3("%s", __func__); |
| 854 | authctxt->user = buffer_get_string(m, NULL); |
| 855 | sshpam_ctxt = (sshpam_device.init_ctx)(authctxt); |
| 856 | sshpam_authok = NULL; |
| 857 | buffer_clear(m); |
| 858 | if (sshpam_ctxt != NULL) { |
| 859 | monitor_permit(mon_dispatch, MONITOR_REQ_PAM_FREE_CTX, 1); |
| 860 | buffer_put_int(m, 1); |
| 861 | } else { |
| 862 | buffer_put_int(m, 0); |
| 863 | } |
Darren Tucker | 7eda592 | 2004-06-22 13:22:50 +1000 | [diff] [blame] | 864 | mm_request_send(sock, MONITOR_ANS_PAM_INIT_CTX, m); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 865 | return (0); |
| 866 | } |
| 867 | |
| 868 | int |
Darren Tucker | 7eda592 | 2004-06-22 13:22:50 +1000 | [diff] [blame] | 869 | mm_answer_pam_query(int sock, Buffer *m) |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 870 | { |
| 871 | char *name, *info, **prompts; |
| 872 | u_int num, *echo_on; |
| 873 | int i, ret; |
| 874 | |
| 875 | debug3("%s", __func__); |
| 876 | sshpam_authok = NULL; |
| 877 | ret = (sshpam_device.query)(sshpam_ctxt, &name, &info, &num, &prompts, &echo_on); |
| 878 | if (ret == 0 && num == 0) |
| 879 | sshpam_authok = sshpam_ctxt; |
| 880 | if (num > 1 || name == NULL || info == NULL) |
| 881 | ret = -1; |
| 882 | buffer_clear(m); |
| 883 | buffer_put_int(m, ret); |
| 884 | buffer_put_cstring(m, name); |
| 885 | xfree(name); |
| 886 | buffer_put_cstring(m, info); |
| 887 | xfree(info); |
| 888 | buffer_put_int(m, num); |
| 889 | for (i = 0; i < num; ++i) { |
| 890 | buffer_put_cstring(m, prompts[i]); |
| 891 | xfree(prompts[i]); |
| 892 | buffer_put_int(m, echo_on[i]); |
| 893 | } |
| 894 | if (prompts != NULL) |
| 895 | xfree(prompts); |
| 896 | if (echo_on != NULL) |
| 897 | xfree(echo_on); |
Darren Tucker | 7eda592 | 2004-06-22 13:22:50 +1000 | [diff] [blame] | 898 | mm_request_send(sock, MONITOR_ANS_PAM_QUERY, m); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 899 | return (0); |
| 900 | } |
| 901 | |
| 902 | int |
Darren Tucker | 7eda592 | 2004-06-22 13:22:50 +1000 | [diff] [blame] | 903 | mm_answer_pam_respond(int sock, Buffer *m) |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 904 | { |
| 905 | char **resp; |
| 906 | u_int num; |
| 907 | int i, ret; |
| 908 | |
| 909 | debug3("%s", __func__); |
| 910 | sshpam_authok = NULL; |
| 911 | num = buffer_get_int(m); |
| 912 | if (num > 0) { |
| 913 | resp = xmalloc(num * sizeof(char *)); |
| 914 | for (i = 0; i < num; ++i) |
| 915 | resp[i] = buffer_get_string(m, NULL); |
| 916 | ret = (sshpam_device.respond)(sshpam_ctxt, num, resp); |
| 917 | for (i = 0; i < num; ++i) |
| 918 | xfree(resp[i]); |
| 919 | xfree(resp); |
| 920 | } else { |
| 921 | ret = (sshpam_device.respond)(sshpam_ctxt, num, NULL); |
| 922 | } |
| 923 | buffer_clear(m); |
| 924 | buffer_put_int(m, ret); |
Darren Tucker | 7eda592 | 2004-06-22 13:22:50 +1000 | [diff] [blame] | 925 | mm_request_send(sock, MONITOR_ANS_PAM_RESPOND, m); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 926 | auth_method = "keyboard-interactive/pam"; |
| 927 | if (ret == 0) |
| 928 | sshpam_authok = sshpam_ctxt; |
| 929 | return (0); |
| 930 | } |
| 931 | |
| 932 | int |
Darren Tucker | 7eda592 | 2004-06-22 13:22:50 +1000 | [diff] [blame] | 933 | mm_answer_pam_free_ctx(int sock, Buffer *m) |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 934 | { |
| 935 | |
| 936 | debug3("%s", __func__); |
| 937 | (sshpam_device.free_ctx)(sshpam_ctxt); |
| 938 | buffer_clear(m); |
Darren Tucker | 7eda592 | 2004-06-22 13:22:50 +1000 | [diff] [blame] | 939 | mm_request_send(sock, MONITOR_ANS_PAM_FREE_CTX, m); |
Damien Miller | 4f9f42a | 2003-05-10 19:28:02 +1000 | [diff] [blame] | 940 | return (sshpam_authok == sshpam_ctxt); |
| 941 | } |
Damien Miller | 7941855 | 2002-04-23 20:28:48 +1000 | [diff] [blame] | 942 | #endif |
| 943 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 944 | static void |
| 945 | mm_append_debug(Buffer *m) |
| 946 | { |
| 947 | if (auth_debug_init && buffer_len(&auth_debug)) { |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 948 | debug3("%s: Appending debug messages for child", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 949 | buffer_append(m, buffer_ptr(&auth_debug), |
| 950 | buffer_len(&auth_debug)); |
| 951 | buffer_clear(&auth_debug); |
| 952 | } |
| 953 | } |
| 954 | |
| 955 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 956 | mm_answer_keyallowed(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 957 | { |
| 958 | Key *key; |
Damien Miller | a10f561 | 2002-09-12 09:49:15 +1000 | [diff] [blame] | 959 | char *cuser, *chost; |
| 960 | u_char *blob; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 961 | u_int bloblen; |
| 962 | enum mm_keytype type = 0; |
| 963 | int allowed = 0; |
| 964 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 965 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 966 | |
| 967 | type = buffer_get_int(m); |
| 968 | cuser = buffer_get_string(m, NULL); |
| 969 | chost = buffer_get_string(m, NULL); |
| 970 | blob = buffer_get_string(m, &bloblen); |
| 971 | |
| 972 | key = key_from_blob(blob, bloblen); |
| 973 | |
| 974 | if ((compat20 && type == MM_RSAHOSTKEY) || |
| 975 | (!compat20 && type != MM_RSAHOSTKEY)) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 976 | fatal("%s: key type and protocol mismatch", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 977 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 978 | debug3("%s: key_from_blob: %p", __func__, key); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 979 | |
Damien Miller | 3e3b514 | 2003-11-17 21:13:40 +1100 | [diff] [blame] | 980 | if (key != NULL && authctxt->valid) { |
Darren Tucker | 47eede7 | 2005-03-14 23:08:12 +1100 | [diff] [blame] | 981 | switch (type) { |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 982 | case MM_USERKEY: |
Ben Lindstrom | dcf6bfb | 2002-06-06 20:57:17 +0000 | [diff] [blame] | 983 | allowed = options.pubkey_authentication && |
| 984 | user_key_allowed(authctxt->pw, key); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 985 | break; |
| 986 | case MM_HOSTKEY: |
Ben Lindstrom | dcf6bfb | 2002-06-06 20:57:17 +0000 | [diff] [blame] | 987 | allowed = options.hostbased_authentication && |
| 988 | hostbased_key_allowed(authctxt->pw, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 989 | cuser, chost, key); |
| 990 | break; |
| 991 | case MM_RSAHOSTKEY: |
| 992 | key->type = KEY_RSA1; /* XXX */ |
Ben Lindstrom | dcf6bfb | 2002-06-06 20:57:17 +0000 | [diff] [blame] | 993 | allowed = options.rhosts_rsa_authentication && |
| 994 | auth_rhosts_rsa_key_allowed(authctxt->pw, |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 995 | cuser, chost, key); |
| 996 | break; |
| 997 | default: |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 998 | fatal("%s: unknown key type %d", __func__, type); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 999 | break; |
| 1000 | } |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1001 | } |
Damien Miller | 0011138 | 2003-03-10 11:21:17 +1100 | [diff] [blame] | 1002 | if (key != NULL) |
| 1003 | key_free(key); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1004 | |
| 1005 | /* clear temporarily storage (used by verify) */ |
| 1006 | monitor_reset_key_state(); |
| 1007 | |
| 1008 | if (allowed) { |
| 1009 | /* Save temporarily for comparison in verify */ |
| 1010 | key_blob = blob; |
| 1011 | key_bloblen = bloblen; |
| 1012 | key_blobtype = type; |
| 1013 | hostbased_cuser = cuser; |
| 1014 | hostbased_chost = chost; |
| 1015 | } |
| 1016 | |
| 1017 | debug3("%s: key %p is %s", |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1018 | __func__, key, allowed ? "allowed" : "disallowed"); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1019 | |
| 1020 | buffer_clear(m); |
| 1021 | buffer_put_int(m, allowed); |
Damien Miller | 06ebedf | 2003-02-24 12:03:38 +1100 | [diff] [blame] | 1022 | buffer_put_int(m, forced_command != NULL); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1023 | |
| 1024 | mm_append_debug(m); |
| 1025 | |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1026 | mm_request_send(sock, MONITOR_ANS_KEYALLOWED, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1027 | |
| 1028 | if (type == MM_RSAHOSTKEY) |
| 1029 | monitor_permit(mon_dispatch, MONITOR_REQ_RSACHALLENGE, allowed); |
| 1030 | |
| 1031 | return (0); |
| 1032 | } |
| 1033 | |
| 1034 | static int |
| 1035 | monitor_valid_userblob(u_char *data, u_int datalen) |
| 1036 | { |
| 1037 | Buffer b; |
Damien Miller | a10f561 | 2002-09-12 09:49:15 +1000 | [diff] [blame] | 1038 | char *p; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1039 | u_int len; |
| 1040 | int fail = 0; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1041 | |
| 1042 | buffer_init(&b); |
| 1043 | buffer_append(&b, data, datalen); |
| 1044 | |
| 1045 | if (datafellows & SSH_OLD_SESSIONID) { |
Ben Lindstrom | f67e077 | 2002-06-06 20:58:19 +0000 | [diff] [blame] | 1046 | p = buffer_ptr(&b); |
| 1047 | len = buffer_len(&b); |
| 1048 | if ((session_id2 == NULL) || |
| 1049 | (len < session_id2_len) || |
| 1050 | (memcmp(p, session_id2, session_id2_len) != 0)) |
| 1051 | fail++; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1052 | buffer_consume(&b, session_id2_len); |
| 1053 | } else { |
Ben Lindstrom | f67e077 | 2002-06-06 20:58:19 +0000 | [diff] [blame] | 1054 | p = buffer_get_string(&b, &len); |
| 1055 | if ((session_id2 == NULL) || |
| 1056 | (len != session_id2_len) || |
| 1057 | (memcmp(p, session_id2, session_id2_len) != 0)) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1058 | fail++; |
Ben Lindstrom | f67e077 | 2002-06-06 20:58:19 +0000 | [diff] [blame] | 1059 | xfree(p); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1060 | } |
| 1061 | if (buffer_get_char(&b) != SSH2_MSG_USERAUTH_REQUEST) |
| 1062 | fail++; |
| 1063 | p = buffer_get_string(&b, NULL); |
| 1064 | if (strcmp(authctxt->user, p) != 0) { |
Damien Miller | 996acd2 | 2003-04-09 20:59:48 +1000 | [diff] [blame] | 1065 | logit("wrong user name passed to monitor: expected %s != %.100s", |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1066 | authctxt->user, p); |
| 1067 | fail++; |
| 1068 | } |
| 1069 | xfree(p); |
| 1070 | buffer_skip_string(&b); |
| 1071 | if (datafellows & SSH_BUG_PKAUTH) { |
| 1072 | if (!buffer_get_char(&b)) |
| 1073 | fail++; |
| 1074 | } else { |
| 1075 | p = buffer_get_string(&b, NULL); |
| 1076 | if (strcmp("publickey", p) != 0) |
| 1077 | fail++; |
| 1078 | xfree(p); |
| 1079 | if (!buffer_get_char(&b)) |
| 1080 | fail++; |
| 1081 | buffer_skip_string(&b); |
| 1082 | } |
| 1083 | buffer_skip_string(&b); |
| 1084 | if (buffer_len(&b) != 0) |
| 1085 | fail++; |
| 1086 | buffer_free(&b); |
| 1087 | return (fail == 0); |
| 1088 | } |
| 1089 | |
| 1090 | static int |
Damien Miller | a10f561 | 2002-09-12 09:49:15 +1000 | [diff] [blame] | 1091 | monitor_valid_hostbasedblob(u_char *data, u_int datalen, char *cuser, |
| 1092 | char *chost) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1093 | { |
| 1094 | Buffer b; |
Damien Miller | a10f561 | 2002-09-12 09:49:15 +1000 | [diff] [blame] | 1095 | char *p; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1096 | u_int len; |
| 1097 | int fail = 0; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1098 | |
| 1099 | buffer_init(&b); |
| 1100 | buffer_append(&b, data, datalen); |
| 1101 | |
Ben Lindstrom | f67e077 | 2002-06-06 20:58:19 +0000 | [diff] [blame] | 1102 | p = buffer_get_string(&b, &len); |
| 1103 | if ((session_id2 == NULL) || |
| 1104 | (len != session_id2_len) || |
| 1105 | (memcmp(p, session_id2, session_id2_len) != 0)) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1106 | fail++; |
Ben Lindstrom | f67e077 | 2002-06-06 20:58:19 +0000 | [diff] [blame] | 1107 | xfree(p); |
| 1108 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1109 | if (buffer_get_char(&b) != SSH2_MSG_USERAUTH_REQUEST) |
| 1110 | fail++; |
| 1111 | p = buffer_get_string(&b, NULL); |
| 1112 | if (strcmp(authctxt->user, p) != 0) { |
Damien Miller | 996acd2 | 2003-04-09 20:59:48 +1000 | [diff] [blame] | 1113 | logit("wrong user name passed to monitor: expected %s != %.100s", |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1114 | authctxt->user, p); |
| 1115 | fail++; |
| 1116 | } |
| 1117 | xfree(p); |
| 1118 | buffer_skip_string(&b); /* service */ |
| 1119 | p = buffer_get_string(&b, NULL); |
| 1120 | if (strcmp(p, "hostbased") != 0) |
| 1121 | fail++; |
| 1122 | xfree(p); |
| 1123 | buffer_skip_string(&b); /* pkalg */ |
| 1124 | buffer_skip_string(&b); /* pkblob */ |
| 1125 | |
| 1126 | /* verify client host, strip trailing dot if necessary */ |
| 1127 | p = buffer_get_string(&b, NULL); |
| 1128 | if (((len = strlen(p)) > 0) && p[len - 1] == '.') |
| 1129 | p[len - 1] = '\0'; |
| 1130 | if (strcmp(p, chost) != 0) |
| 1131 | fail++; |
| 1132 | xfree(p); |
| 1133 | |
| 1134 | /* verify client user */ |
| 1135 | p = buffer_get_string(&b, NULL); |
| 1136 | if (strcmp(p, cuser) != 0) |
| 1137 | fail++; |
| 1138 | xfree(p); |
| 1139 | |
| 1140 | if (buffer_len(&b) != 0) |
| 1141 | fail++; |
| 1142 | buffer_free(&b); |
| 1143 | return (fail == 0); |
| 1144 | } |
| 1145 | |
| 1146 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1147 | mm_answer_keyverify(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1148 | { |
| 1149 | Key *key; |
| 1150 | u_char *signature, *data, *blob; |
| 1151 | u_int signaturelen, datalen, bloblen; |
| 1152 | int verified = 0; |
| 1153 | int valid_data = 0; |
| 1154 | |
| 1155 | blob = buffer_get_string(m, &bloblen); |
| 1156 | signature = buffer_get_string(m, &signaturelen); |
| 1157 | data = buffer_get_string(m, &datalen); |
| 1158 | |
| 1159 | if (hostbased_cuser == NULL || hostbased_chost == NULL || |
Ben Lindstrom | b57a4bf | 2002-03-27 18:00:59 +0000 | [diff] [blame] | 1160 | !monitor_allowed_key(blob, bloblen)) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1161 | fatal("%s: bad key, not previously allowed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1162 | |
| 1163 | key = key_from_blob(blob, bloblen); |
| 1164 | if (key == NULL) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1165 | fatal("%s: bad public key blob", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1166 | |
| 1167 | switch (key_blobtype) { |
| 1168 | case MM_USERKEY: |
| 1169 | valid_data = monitor_valid_userblob(data, datalen); |
| 1170 | break; |
| 1171 | case MM_HOSTKEY: |
| 1172 | valid_data = monitor_valid_hostbasedblob(data, datalen, |
| 1173 | hostbased_cuser, hostbased_chost); |
| 1174 | break; |
| 1175 | default: |
| 1176 | valid_data = 0; |
| 1177 | break; |
| 1178 | } |
| 1179 | if (!valid_data) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1180 | fatal("%s: bad signature data blob", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1181 | |
| 1182 | verified = key_verify(key, signature, signaturelen, data, datalen); |
| 1183 | debug3("%s: key %p signature %s", |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1184 | __func__, key, verified ? "verified" : "unverified"); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1185 | |
| 1186 | key_free(key); |
| 1187 | xfree(blob); |
| 1188 | xfree(signature); |
| 1189 | xfree(data); |
| 1190 | |
Ben Lindstrom | e1c0912 | 2002-06-23 00:38:24 +0000 | [diff] [blame] | 1191 | auth_method = key_blobtype == MM_USERKEY ? "publickey" : "hostbased"; |
| 1192 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1193 | monitor_reset_key_state(); |
| 1194 | |
| 1195 | buffer_clear(m); |
| 1196 | buffer_put_int(m, verified); |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1197 | mm_request_send(sock, MONITOR_ANS_KEYVERIFY, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1198 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1199 | return (verified); |
| 1200 | } |
| 1201 | |
| 1202 | static void |
| 1203 | mm_record_login(Session *s, struct passwd *pw) |
| 1204 | { |
| 1205 | socklen_t fromlen; |
| 1206 | struct sockaddr_storage from; |
| 1207 | |
| 1208 | /* |
| 1209 | * Get IP address of client. If the connection is not a socket, let |
| 1210 | * the address be 0.0.0.0. |
| 1211 | */ |
| 1212 | memset(&from, 0, sizeof(from)); |
Damien Miller | ebc2306 | 2002-09-04 16:45:09 +1000 | [diff] [blame] | 1213 | fromlen = sizeof(from); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1214 | if (packet_connection_is_on_socket()) { |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1215 | if (getpeername(packet_get_connection_in(), |
| 1216 | (struct sockaddr *) & from, &fromlen) < 0) { |
| 1217 | debug("getpeername: %.100s", strerror(errno)); |
Darren Tucker | 3e33cec | 2003-10-02 16:12:36 +1000 | [diff] [blame] | 1218 | cleanup_exit(255); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1219 | } |
| 1220 | } |
| 1221 | /* Record that there was a login on that tty from the remote host. */ |
| 1222 | record_login(s->pid, s->tty, pw->pw_name, pw->pw_uid, |
Damien Miller | 3a961dc | 2003-06-03 10:25:48 +1000 | [diff] [blame] | 1223 | get_remote_name_or_ip(utmp_len, options.use_dns), |
Damien Miller | ebc2306 | 2002-09-04 16:45:09 +1000 | [diff] [blame] | 1224 | (struct sockaddr *)&from, fromlen); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1225 | } |
| 1226 | |
| 1227 | static void |
| 1228 | mm_session_close(Session *s) |
| 1229 | { |
Damien Miller | 04bd8b0 | 2003-05-25 14:38:33 +1000 | [diff] [blame] | 1230 | debug3("%s: session %d pid %ld", __func__, s->self, (long)s->pid); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1231 | if (s->ttyfd != -1) { |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1232 | debug3("%s: tty %s ptyfd %d", __func__, s->tty, s->ptyfd); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1233 | session_pty_cleanup2(s); |
| 1234 | } |
| 1235 | s->used = 0; |
| 1236 | } |
| 1237 | |
| 1238 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1239 | mm_answer_pty(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1240 | { |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1241 | extern struct monitor *pmonitor; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1242 | Session *s; |
| 1243 | int res, fd0; |
| 1244 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1245 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1246 | |
| 1247 | buffer_clear(m); |
| 1248 | s = session_new(); |
| 1249 | if (s == NULL) |
| 1250 | goto error; |
| 1251 | s->authctxt = authctxt; |
| 1252 | s->pw = authctxt->pw; |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1253 | s->pid = pmonitor->m_pid; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1254 | res = pty_allocate(&s->ptyfd, &s->ttyfd, s->tty, sizeof(s->tty)); |
| 1255 | if (res == 0) |
| 1256 | goto error; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1257 | pty_setowner(authctxt->pw, s->tty); |
| 1258 | |
| 1259 | buffer_put_int(m, 1); |
| 1260 | buffer_put_cstring(m, s->tty); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1261 | |
| 1262 | /* We need to trick ttyslot */ |
| 1263 | if (dup2(s->ttyfd, 0) == -1) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1264 | fatal("%s: dup2", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1265 | |
| 1266 | mm_record_login(s, authctxt->pw); |
| 1267 | |
| 1268 | /* Now we can close the file descriptor again */ |
| 1269 | close(0); |
| 1270 | |
Darren Tucker | 0999174 | 2004-07-17 17:05:14 +1000 | [diff] [blame] | 1271 | /* send messages generated by record_login */ |
| 1272 | buffer_put_string(m, buffer_ptr(&loginmsg), buffer_len(&loginmsg)); |
| 1273 | buffer_clear(&loginmsg); |
| 1274 | |
| 1275 | mm_request_send(sock, MONITOR_ANS_PTY, m); |
| 1276 | |
| 1277 | mm_send_fd(sock, s->ptyfd); |
| 1278 | mm_send_fd(sock, s->ttyfd); |
| 1279 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1280 | /* make sure nothing uses fd 0 */ |
| 1281 | if ((fd0 = open(_PATH_DEVNULL, O_RDONLY)) < 0) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1282 | fatal("%s: open(/dev/null): %s", __func__, strerror(errno)); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1283 | if (fd0 != 0) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1284 | error("%s: fd0 %d != 0", __func__, fd0); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1285 | |
| 1286 | /* slave is not needed */ |
| 1287 | close(s->ttyfd); |
| 1288 | s->ttyfd = s->ptyfd; |
| 1289 | /* no need to dup() because nobody closes ptyfd */ |
| 1290 | s->ptymaster = s->ptyfd; |
| 1291 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1292 | debug3("%s: tty %s ptyfd %d", __func__, s->tty, s->ttyfd); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1293 | |
| 1294 | return (0); |
| 1295 | |
| 1296 | error: |
| 1297 | if (s != NULL) |
| 1298 | mm_session_close(s); |
| 1299 | buffer_put_int(m, 0); |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1300 | mm_request_send(sock, MONITOR_ANS_PTY, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1301 | return (0); |
| 1302 | } |
| 1303 | |
| 1304 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1305 | mm_answer_pty_cleanup(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1306 | { |
| 1307 | Session *s; |
| 1308 | char *tty; |
| 1309 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1310 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1311 | |
| 1312 | tty = buffer_get_string(m, NULL); |
| 1313 | if ((s = session_by_tty(tty)) != NULL) |
| 1314 | mm_session_close(s); |
| 1315 | buffer_clear(m); |
| 1316 | xfree(tty); |
| 1317 | return (0); |
| 1318 | } |
| 1319 | |
| 1320 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1321 | mm_answer_sesskey(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1322 | { |
| 1323 | BIGNUM *p; |
| 1324 | int rsafail; |
| 1325 | |
| 1326 | /* Turn off permissions */ |
Darren Tucker | 5b53026 | 2005-02-09 09:52:17 +1100 | [diff] [blame] | 1327 | monitor_permit(mon_dispatch, MONITOR_REQ_SESSKEY, 0); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1328 | |
| 1329 | if ((p = BN_new()) == NULL) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1330 | fatal("%s: BN_new", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1331 | |
| 1332 | buffer_get_bignum2(m, p); |
| 1333 | |
| 1334 | rsafail = ssh1_session_key(p); |
| 1335 | |
| 1336 | buffer_clear(m); |
| 1337 | buffer_put_int(m, rsafail); |
| 1338 | buffer_put_bignum2(m, p); |
| 1339 | |
| 1340 | BN_clear_free(p); |
| 1341 | |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1342 | mm_request_send(sock, MONITOR_ANS_SESSKEY, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1343 | |
| 1344 | /* Turn on permissions for sessid passing */ |
| 1345 | monitor_permit(mon_dispatch, MONITOR_REQ_SESSID, 1); |
| 1346 | |
| 1347 | return (0); |
| 1348 | } |
| 1349 | |
| 1350 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1351 | mm_answer_sessid(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1352 | { |
| 1353 | int i; |
| 1354 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1355 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1356 | |
| 1357 | if (buffer_len(m) != 16) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1358 | fatal("%s: bad ssh1 session id", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1359 | for (i = 0; i < 16; i++) |
| 1360 | session_id[i] = buffer_get_char(m); |
| 1361 | |
| 1362 | /* Turn on permissions for getpwnam */ |
| 1363 | monitor_permit(mon_dispatch, MONITOR_REQ_PWNAM, 1); |
| 1364 | |
| 1365 | return (0); |
| 1366 | } |
| 1367 | |
| 1368 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1369 | mm_answer_rsa_keyallowed(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1370 | { |
| 1371 | BIGNUM *client_n; |
| 1372 | Key *key = NULL; |
| 1373 | u_char *blob = NULL; |
| 1374 | u_int blen = 0; |
| 1375 | int allowed = 0; |
| 1376 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1377 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1378 | |
Ben Lindstrom | dcf6bfb | 2002-06-06 20:57:17 +0000 | [diff] [blame] | 1379 | if (options.rsa_authentication && authctxt->valid) { |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1380 | if ((client_n = BN_new()) == NULL) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1381 | fatal("%s: BN_new", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1382 | buffer_get_bignum2(m, client_n); |
| 1383 | allowed = auth_rsa_key_allowed(authctxt->pw, client_n, &key); |
| 1384 | BN_clear_free(client_n); |
| 1385 | } |
| 1386 | buffer_clear(m); |
| 1387 | buffer_put_int(m, allowed); |
Damien Miller | 06ebedf | 2003-02-24 12:03:38 +1100 | [diff] [blame] | 1388 | buffer_put_int(m, forced_command != NULL); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1389 | |
| 1390 | /* clear temporarily storage (used by generate challenge) */ |
| 1391 | monitor_reset_key_state(); |
| 1392 | |
| 1393 | if (allowed && key != NULL) { |
| 1394 | key->type = KEY_RSA; /* cheat for key_to_blob */ |
| 1395 | if (key_to_blob(key, &blob, &blen) == 0) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1396 | fatal("%s: key_to_blob failed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1397 | buffer_put_string(m, blob, blen); |
| 1398 | |
| 1399 | /* Save temporarily for comparison in verify */ |
| 1400 | key_blob = blob; |
| 1401 | key_bloblen = blen; |
| 1402 | key_blobtype = MM_RSAUSERKEY; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1403 | } |
Damien Miller | 0011138 | 2003-03-10 11:21:17 +1100 | [diff] [blame] | 1404 | if (key != NULL) |
| 1405 | key_free(key); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1406 | |
| 1407 | mm_append_debug(m); |
| 1408 | |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1409 | mm_request_send(sock, MONITOR_ANS_RSAKEYALLOWED, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1410 | |
| 1411 | monitor_permit(mon_dispatch, MONITOR_REQ_RSACHALLENGE, allowed); |
| 1412 | monitor_permit(mon_dispatch, MONITOR_REQ_RSARESPONSE, 0); |
| 1413 | return (0); |
| 1414 | } |
| 1415 | |
| 1416 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1417 | mm_answer_rsa_challenge(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1418 | { |
| 1419 | Key *key = NULL; |
| 1420 | u_char *blob; |
| 1421 | u_int blen; |
| 1422 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1423 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1424 | |
| 1425 | if (!authctxt->valid) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1426 | fatal("%s: authctxt not valid", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1427 | blob = buffer_get_string(m, &blen); |
| 1428 | if (!monitor_allowed_key(blob, blen)) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1429 | fatal("%s: bad key, not previously allowed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1430 | if (key_blobtype != MM_RSAUSERKEY && key_blobtype != MM_RSAHOSTKEY) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1431 | fatal("%s: key type mismatch", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1432 | if ((key = key_from_blob(blob, blen)) == NULL) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1433 | fatal("%s: received bad key", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1434 | |
| 1435 | if (ssh1_challenge) |
| 1436 | BN_clear_free(ssh1_challenge); |
| 1437 | ssh1_challenge = auth_rsa_generate_challenge(key); |
| 1438 | |
| 1439 | buffer_clear(m); |
| 1440 | buffer_put_bignum2(m, ssh1_challenge); |
| 1441 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1442 | debug3("%s sending reply", __func__); |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1443 | mm_request_send(sock, MONITOR_ANS_RSACHALLENGE, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1444 | |
| 1445 | monitor_permit(mon_dispatch, MONITOR_REQ_RSARESPONSE, 1); |
Damien Miller | 0011138 | 2003-03-10 11:21:17 +1100 | [diff] [blame] | 1446 | |
| 1447 | xfree(blob); |
| 1448 | key_free(key); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1449 | return (0); |
| 1450 | } |
| 1451 | |
| 1452 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1453 | mm_answer_rsa_response(int sock, Buffer *m) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1454 | { |
| 1455 | Key *key = NULL; |
| 1456 | u_char *blob, *response; |
| 1457 | u_int blen, len; |
| 1458 | int success; |
| 1459 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1460 | debug3("%s entering", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1461 | |
| 1462 | if (!authctxt->valid) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1463 | fatal("%s: authctxt not valid", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1464 | if (ssh1_challenge == NULL) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1465 | fatal("%s: no ssh1_challenge", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1466 | |
| 1467 | blob = buffer_get_string(m, &blen); |
| 1468 | if (!monitor_allowed_key(blob, blen)) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1469 | fatal("%s: bad key, not previously allowed", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1470 | if (key_blobtype != MM_RSAUSERKEY && key_blobtype != MM_RSAHOSTKEY) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1471 | fatal("%s: key type mismatch: %d", __func__, key_blobtype); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1472 | if ((key = key_from_blob(blob, blen)) == NULL) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1473 | fatal("%s: received bad key", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1474 | response = buffer_get_string(m, &len); |
| 1475 | if (len != 16) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1476 | fatal("%s: received bad response to challenge", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1477 | success = auth_rsa_verify_response(key, ssh1_challenge, response); |
| 1478 | |
Damien Miller | 0011138 | 2003-03-10 11:21:17 +1100 | [diff] [blame] | 1479 | xfree(blob); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1480 | key_free(key); |
| 1481 | xfree(response); |
| 1482 | |
| 1483 | auth_method = key_blobtype == MM_RSAUSERKEY ? "rsa" : "rhosts-rsa"; |
| 1484 | |
| 1485 | /* reset state */ |
| 1486 | BN_clear_free(ssh1_challenge); |
| 1487 | ssh1_challenge = NULL; |
| 1488 | monitor_reset_key_state(); |
| 1489 | |
| 1490 | buffer_clear(m); |
| 1491 | buffer_put_int(m, success); |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1492 | mm_request_send(sock, MONITOR_ANS_RSARESPONSE, m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1493 | |
| 1494 | return (success); |
| 1495 | } |
| 1496 | |
| 1497 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1498 | mm_answer_term(int sock, Buffer *req) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1499 | { |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1500 | extern struct monitor *pmonitor; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1501 | int res, status; |
| 1502 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1503 | debug3("%s: tearing down sessions", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1504 | |
| 1505 | /* The child is terminating */ |
| 1506 | session_destroy_all(&mm_session_close); |
| 1507 | |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1508 | while (waitpid(pmonitor->m_pid, &status, 0) == -1) |
Ben Lindstrom | 47fd811 | 2002-04-02 20:48:19 +0000 | [diff] [blame] | 1509 | if (errno != EINTR) |
| 1510 | exit(1); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1511 | |
| 1512 | res = WIFEXITED(status) ? WEXITSTATUS(status) : 1; |
| 1513 | |
| 1514 | /* Terminate process */ |
Darren Tucker | 1f8311c | 2004-05-13 16:39:33 +1000 | [diff] [blame] | 1515 | exit(res); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1516 | } |
| 1517 | |
Darren Tucker | 2e0cf0d | 2005-02-08 21:52:47 +1100 | [diff] [blame] | 1518 | #ifdef SSH_AUDIT_EVENTS |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 1519 | /* Report that an audit event occurred */ |
| 1520 | int |
| 1521 | mm_answer_audit_event(int socket, Buffer *m) |
| 1522 | { |
| 1523 | ssh_audit_event_t event; |
| 1524 | |
| 1525 | debug3("%s entering", __func__); |
| 1526 | |
| 1527 | event = buffer_get_int(m); |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 1528 | switch(event) { |
Darren Tucker | 2e0cf0d | 2005-02-08 21:52:47 +1100 | [diff] [blame] | 1529 | case SSH_AUTH_FAIL_PUBKEY: |
| 1530 | case SSH_AUTH_FAIL_HOSTBASED: |
| 1531 | case SSH_AUTH_FAIL_GSSAPI: |
| 1532 | case SSH_LOGIN_EXCEED_MAXTRIES: |
| 1533 | case SSH_LOGIN_ROOT_DENIED: |
| 1534 | case SSH_CONNECTION_CLOSE: |
| 1535 | case SSH_INVALID_USER: |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 1536 | audit_event(event); |
| 1537 | break; |
| 1538 | default: |
| 1539 | fatal("Audit event type %d not permitted", event); |
| 1540 | } |
| 1541 | |
| 1542 | return (0); |
| 1543 | } |
| 1544 | |
| 1545 | int |
| 1546 | mm_answer_audit_command(int socket, Buffer *m) |
| 1547 | { |
| 1548 | u_int len; |
| 1549 | char *cmd; |
| 1550 | |
| 1551 | debug3("%s entering", __func__); |
| 1552 | cmd = buffer_get_string(m, &len); |
| 1553 | /* sanity check command, if so how? */ |
| 1554 | audit_run_command(cmd); |
| 1555 | xfree(cmd); |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 1556 | return (0); |
| 1557 | } |
Darren Tucker | 2e0cf0d | 2005-02-08 21:52:47 +1100 | [diff] [blame] | 1558 | #endif /* SSH_AUDIT_EVENTS */ |
Darren Tucker | 269a1ea | 2005-02-03 00:20:53 +1100 | [diff] [blame] | 1559 | |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1560 | void |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1561 | monitor_apply_keystate(struct monitor *pmonitor) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1562 | { |
| 1563 | if (compat20) { |
| 1564 | set_newkeys(MODE_IN); |
| 1565 | set_newkeys(MODE_OUT); |
| 1566 | } else { |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1567 | packet_set_protocol_flags(child_state.ssh1protoflags); |
Ben Lindstrom | 402c6cc | 2002-06-21 00:43:42 +0000 | [diff] [blame] | 1568 | packet_set_encryption_key(child_state.ssh1key, |
| 1569 | child_state.ssh1keylen, child_state.ssh1cipher); |
| 1570 | xfree(child_state.ssh1key); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1571 | } |
| 1572 | |
Ben Lindstrom | 402c6cc | 2002-06-21 00:43:42 +0000 | [diff] [blame] | 1573 | /* for rc4 and other stateful ciphers */ |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1574 | packet_set_keycontext(MODE_OUT, child_state.keyout); |
| 1575 | xfree(child_state.keyout); |
| 1576 | packet_set_keycontext(MODE_IN, child_state.keyin); |
| 1577 | xfree(child_state.keyin); |
| 1578 | |
| 1579 | if (!compat20) { |
| 1580 | packet_set_iv(MODE_OUT, child_state.ivout); |
| 1581 | xfree(child_state.ivout); |
| 1582 | packet_set_iv(MODE_IN, child_state.ivin); |
| 1583 | xfree(child_state.ivin); |
| 1584 | } |
| 1585 | |
| 1586 | memcpy(&incoming_stream, &child_state.incoming, |
| 1587 | sizeof(incoming_stream)); |
| 1588 | memcpy(&outgoing_stream, &child_state.outgoing, |
| 1589 | sizeof(outgoing_stream)); |
| 1590 | |
| 1591 | /* Update with new address */ |
Damien Miller | 2d6b833 | 2002-06-21 15:59:49 +1000 | [diff] [blame] | 1592 | if (options.compression) |
| 1593 | mm_init_compression(pmonitor->m_zlib); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1594 | |
| 1595 | /* Network I/O buffers */ |
| 1596 | /* XXX inefficient for large buffers, need: buffer_init_from_string */ |
| 1597 | buffer_clear(&input); |
| 1598 | buffer_append(&input, child_state.input, child_state.ilen); |
| 1599 | memset(child_state.input, 0, child_state.ilen); |
| 1600 | xfree(child_state.input); |
| 1601 | |
| 1602 | buffer_clear(&output); |
| 1603 | buffer_append(&output, child_state.output, child_state.olen); |
| 1604 | memset(child_state.output, 0, child_state.olen); |
| 1605 | xfree(child_state.output); |
| 1606 | } |
| 1607 | |
| 1608 | static Kex * |
| 1609 | mm_get_kex(Buffer *m) |
| 1610 | { |
| 1611 | Kex *kex; |
| 1612 | void *blob; |
| 1613 | u_int bloblen; |
| 1614 | |
| 1615 | kex = xmalloc(sizeof(*kex)); |
| 1616 | memset(kex, 0, sizeof(*kex)); |
| 1617 | kex->session_id = buffer_get_string(m, &kex->session_id_len); |
Ben Lindstrom | f67e077 | 2002-06-06 20:58:19 +0000 | [diff] [blame] | 1618 | if ((session_id2 == NULL) || |
| 1619 | (kex->session_id_len != session_id2_len) || |
| 1620 | (memcmp(kex->session_id, session_id2, session_id2_len) != 0)) |
| 1621 | fatal("mm_get_get: internal error: bad session id"); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1622 | kex->we_need = buffer_get_int(m); |
Damien Miller | b062c29 | 2003-03-24 09:12:09 +1100 | [diff] [blame] | 1623 | kex->kex[KEX_DH_GRP1_SHA1] = kexdh_server; |
Damien Miller | f675fc4 | 2004-06-15 10:30:09 +1000 | [diff] [blame] | 1624 | kex->kex[KEX_DH_GRP14_SHA1] = kexdh_server; |
Damien Miller | b062c29 | 2003-03-24 09:12:09 +1100 | [diff] [blame] | 1625 | kex->kex[KEX_DH_GEX_SHA1] = kexgex_server; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1626 | kex->server = 1; |
| 1627 | kex->hostkey_type = buffer_get_int(m); |
| 1628 | kex->kex_type = buffer_get_int(m); |
| 1629 | blob = buffer_get_string(m, &bloblen); |
| 1630 | buffer_init(&kex->my); |
| 1631 | buffer_append(&kex->my, blob, bloblen); |
| 1632 | xfree(blob); |
| 1633 | blob = buffer_get_string(m, &bloblen); |
| 1634 | buffer_init(&kex->peer); |
| 1635 | buffer_append(&kex->peer, blob, bloblen); |
| 1636 | xfree(blob); |
| 1637 | kex->done = 1; |
| 1638 | kex->flags = buffer_get_int(m); |
| 1639 | kex->client_version_string = buffer_get_string(m, NULL); |
| 1640 | kex->server_version_string = buffer_get_string(m, NULL); |
| 1641 | kex->load_host_key=&get_hostkey_by_type; |
| 1642 | kex->host_key_index=&get_hostkey_index; |
| 1643 | |
| 1644 | return (kex); |
| 1645 | } |
| 1646 | |
| 1647 | /* This function requries careful sanity checking */ |
| 1648 | |
| 1649 | void |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1650 | mm_get_keystate(struct monitor *pmonitor) |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1651 | { |
| 1652 | Buffer m; |
| 1653 | u_char *blob, *p; |
| 1654 | u_int bloblen, plen; |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 1655 | u_int32_t seqnr, packets; |
| 1656 | u_int64_t blocks; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1657 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1658 | debug3("%s: Waiting for new keys", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1659 | |
| 1660 | buffer_init(&m); |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1661 | mm_request_receive_expect(pmonitor->m_sendfd, MONITOR_REQ_KEYEXPORT, &m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1662 | if (!compat20) { |
| 1663 | child_state.ssh1protoflags = buffer_get_int(&m); |
| 1664 | child_state.ssh1cipher = buffer_get_int(&m); |
Ben Lindstrom | 402c6cc | 2002-06-21 00:43:42 +0000 | [diff] [blame] | 1665 | child_state.ssh1key = buffer_get_string(&m, |
| 1666 | &child_state.ssh1keylen); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1667 | child_state.ivout = buffer_get_string(&m, |
| 1668 | &child_state.ivoutlen); |
| 1669 | child_state.ivin = buffer_get_string(&m, &child_state.ivinlen); |
| 1670 | goto skip; |
| 1671 | } else { |
| 1672 | /* Get the Kex for rekeying */ |
Ben Lindstrom | 7339b2a | 2002-05-15 16:25:01 +0000 | [diff] [blame] | 1673 | *pmonitor->m_pkex = mm_get_kex(&m); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1674 | } |
| 1675 | |
| 1676 | blob = buffer_get_string(&m, &bloblen); |
| 1677 | current_keys[MODE_OUT] = mm_newkeys_from_blob(blob, bloblen); |
| 1678 | xfree(blob); |
| 1679 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1680 | debug3("%s: Waiting for second key", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1681 | blob = buffer_get_string(&m, &bloblen); |
| 1682 | current_keys[MODE_IN] = mm_newkeys_from_blob(blob, bloblen); |
| 1683 | xfree(blob); |
| 1684 | |
| 1685 | /* Now get sequence numbers for the packets */ |
Damien Miller | a5539d2 | 2003-04-09 20:50:06 +1000 | [diff] [blame] | 1686 | seqnr = buffer_get_int(&m); |
| 1687 | blocks = buffer_get_int64(&m); |
| 1688 | packets = buffer_get_int(&m); |
| 1689 | packet_set_state(MODE_OUT, seqnr, blocks, packets); |
| 1690 | seqnr = buffer_get_int(&m); |
| 1691 | blocks = buffer_get_int64(&m); |
| 1692 | packets = buffer_get_int(&m); |
| 1693 | packet_set_state(MODE_IN, seqnr, blocks, packets); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1694 | |
| 1695 | skip: |
| 1696 | /* Get the key context */ |
| 1697 | child_state.keyout = buffer_get_string(&m, &child_state.keyoutlen); |
| 1698 | child_state.keyin = buffer_get_string(&m, &child_state.keyinlen); |
| 1699 | |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1700 | debug3("%s: Getting compression state", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1701 | /* Get compression state */ |
| 1702 | p = buffer_get_string(&m, &plen); |
| 1703 | if (plen != sizeof(child_state.outgoing)) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1704 | fatal("%s: bad request size", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1705 | memcpy(&child_state.outgoing, p, sizeof(child_state.outgoing)); |
| 1706 | xfree(p); |
| 1707 | |
| 1708 | p = buffer_get_string(&m, &plen); |
| 1709 | if (plen != sizeof(child_state.incoming)) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1710 | fatal("%s: bad request size", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1711 | memcpy(&child_state.incoming, p, sizeof(child_state.incoming)); |
| 1712 | xfree(p); |
| 1713 | |
| 1714 | /* Network I/O buffers */ |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1715 | debug3("%s: Getting Network I/O buffers", __func__); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1716 | child_state.input = buffer_get_string(&m, &child_state.ilen); |
| 1717 | child_state.output = buffer_get_string(&m, &child_state.olen); |
| 1718 | |
| 1719 | buffer_free(&m); |
| 1720 | } |
| 1721 | |
| 1722 | |
| 1723 | /* Allocation functions for zlib */ |
| 1724 | void * |
| 1725 | mm_zalloc(struct mm_master *mm, u_int ncount, u_int size) |
| 1726 | { |
Ben Lindstrom | 41ee2b0 | 2002-11-09 15:47:47 +0000 | [diff] [blame] | 1727 | size_t len = (size_t) size * ncount; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1728 | void *address; |
| 1729 | |
Ben Lindstrom | 0a4f754 | 2002-08-20 18:36:25 +0000 | [diff] [blame] | 1730 | if (len == 0 || ncount > SIZE_T_MAX / size) |
Damien Miller | 530a754 | 2002-06-26 23:27:11 +1000 | [diff] [blame] | 1731 | fatal("%s: mm_zalloc(%u, %u)", __func__, ncount, size); |
| 1732 | |
| 1733 | address = mm_malloc(mm, len); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1734 | |
| 1735 | return (address); |
| 1736 | } |
| 1737 | |
| 1738 | void |
| 1739 | mm_zfree(struct mm_master *mm, void *address) |
| 1740 | { |
| 1741 | mm_free(mm, address); |
| 1742 | } |
| 1743 | |
| 1744 | void |
| 1745 | mm_init_compression(struct mm_master *mm) |
| 1746 | { |
| 1747 | outgoing_stream.zalloc = (alloc_func)mm_zalloc; |
| 1748 | outgoing_stream.zfree = (free_func)mm_zfree; |
| 1749 | outgoing_stream.opaque = mm; |
| 1750 | |
| 1751 | incoming_stream.zalloc = (alloc_func)mm_zalloc; |
| 1752 | incoming_stream.zfree = (free_func)mm_zfree; |
| 1753 | incoming_stream.opaque = mm; |
| 1754 | } |
| 1755 | |
| 1756 | /* XXX */ |
| 1757 | |
| 1758 | #define FD_CLOSEONEXEC(x) do { \ |
| 1759 | if (fcntl(x, F_SETFD, 1) == -1) \ |
| 1760 | fatal("fcntl(%d, F_SETFD)", x); \ |
| 1761 | } while (0) |
| 1762 | |
| 1763 | static void |
| 1764 | monitor_socketpair(int *pair) |
| 1765 | { |
Kevin Steves | fe6ca54 | 2002-04-10 22:04:54 +0000 | [diff] [blame] | 1766 | #ifdef HAVE_SOCKETPAIR |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1767 | if (socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1) |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1768 | fatal("%s: socketpair", __func__); |
Kevin Steves | fe6ca54 | 2002-04-10 22:04:54 +0000 | [diff] [blame] | 1769 | #else |
| 1770 | fatal("%s: UsePrivilegeSeparation=yes not supported", |
Ben Lindstrom | 7d9c38f | 2002-06-06 21:40:51 +0000 | [diff] [blame] | 1771 | __func__); |
Kevin Steves | fe6ca54 | 2002-04-10 22:04:54 +0000 | [diff] [blame] | 1772 | #endif |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1773 | FD_CLOSEONEXEC(pair[0]); |
| 1774 | FD_CLOSEONEXEC(pair[1]); |
| 1775 | } |
| 1776 | |
| 1777 | #define MM_MEMSIZE 65536 |
| 1778 | |
| 1779 | struct monitor * |
| 1780 | monitor_init(void) |
| 1781 | { |
| 1782 | struct monitor *mon; |
| 1783 | int pair[2]; |
| 1784 | |
| 1785 | mon = xmalloc(sizeof(*mon)); |
| 1786 | |
Darren Tucker | a8be9e2 | 2004-02-06 16:40:27 +1100 | [diff] [blame] | 1787 | mon->m_pid = 0; |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1788 | monitor_socketpair(pair); |
| 1789 | |
| 1790 | mon->m_recvfd = pair[0]; |
| 1791 | mon->m_sendfd = pair[1]; |
| 1792 | |
| 1793 | /* Used to share zlib space across processes */ |
Damien Miller | 2d6b833 | 2002-06-21 15:59:49 +1000 | [diff] [blame] | 1794 | if (options.compression) { |
| 1795 | mon->m_zback = mm_create(NULL, MM_MEMSIZE); |
| 1796 | mon->m_zlib = mm_create(mon->m_zback, 20 * MM_MEMSIZE); |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1797 | |
Damien Miller | 2d6b833 | 2002-06-21 15:59:49 +1000 | [diff] [blame] | 1798 | /* Compression needs to share state across borders */ |
| 1799 | mm_init_compression(mon->m_zlib); |
| 1800 | } |
Ben Lindstrom | 7a2073c | 2002-03-22 02:30:41 +0000 | [diff] [blame] | 1801 | |
| 1802 | return mon; |
| 1803 | } |
| 1804 | |
| 1805 | void |
| 1806 | monitor_reinit(struct monitor *mon) |
| 1807 | { |
| 1808 | int pair[2]; |
| 1809 | |
| 1810 | monitor_socketpair(pair); |
| 1811 | |
| 1812 | mon->m_recvfd = pair[0]; |
| 1813 | mon->m_sendfd = pair[1]; |
| 1814 | } |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1815 | |
| 1816 | #ifdef GSSAPI |
| 1817 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1818 | mm_answer_gss_setup_ctx(int sock, Buffer *m) |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1819 | { |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1820 | gss_OID_desc goid; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1821 | OM_uint32 major; |
| 1822 | u_int len; |
| 1823 | |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1824 | goid.elements = buffer_get_string(m, &len); |
| 1825 | goid.length = len; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1826 | |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1827 | major = ssh_gssapi_server_ctx(&gsscontext, &goid); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1828 | |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1829 | xfree(goid.elements); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1830 | |
| 1831 | buffer_clear(m); |
| 1832 | buffer_put_int(m, major); |
| 1833 | |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1834 | mm_request_send(sock,MONITOR_ANS_GSSSETUP, m); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1835 | |
| 1836 | /* Now we have a context, enable the step */ |
| 1837 | monitor_permit(mon_dispatch, MONITOR_REQ_GSSSTEP, 1); |
| 1838 | |
| 1839 | return (0); |
| 1840 | } |
| 1841 | |
| 1842 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1843 | mm_answer_gss_accept_ctx(int sock, Buffer *m) |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1844 | { |
| 1845 | gss_buffer_desc in; |
| 1846 | gss_buffer_desc out = GSS_C_EMPTY_BUFFER; |
| 1847 | OM_uint32 major,minor; |
| 1848 | OM_uint32 flags = 0; /* GSI needs this */ |
Darren Tucker | 600ad8d | 2003-08-26 12:10:48 +1000 | [diff] [blame] | 1849 | u_int len; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1850 | |
Darren Tucker | 600ad8d | 2003-08-26 12:10:48 +1000 | [diff] [blame] | 1851 | in.value = buffer_get_string(m, &len); |
| 1852 | in.length = len; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1853 | major = ssh_gssapi_accept_ctx(gsscontext, &in, &out, &flags); |
| 1854 | xfree(in.value); |
| 1855 | |
| 1856 | buffer_clear(m); |
| 1857 | buffer_put_int(m, major); |
| 1858 | buffer_put_string(m, out.value, out.length); |
| 1859 | buffer_put_int(m, flags); |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1860 | mm_request_send(sock, MONITOR_ANS_GSSSTEP, m); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1861 | |
| 1862 | gss_release_buffer(&minor, &out); |
| 1863 | |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1864 | if (major==GSS_S_COMPLETE) { |
| 1865 | monitor_permit(mon_dispatch, MONITOR_REQ_GSSSTEP, 0); |
| 1866 | monitor_permit(mon_dispatch, MONITOR_REQ_GSSUSEROK, 1); |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 1867 | monitor_permit(mon_dispatch, MONITOR_REQ_GSSCHECKMIC, 1); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1868 | } |
| 1869 | return (0); |
| 1870 | } |
| 1871 | |
| 1872 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1873 | mm_answer_gss_checkmic(int sock, Buffer *m) |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 1874 | { |
| 1875 | gss_buffer_desc gssbuf, mic; |
| 1876 | OM_uint32 ret; |
| 1877 | u_int len; |
Damien Miller | 787b2ec | 2003-11-21 23:56:47 +1100 | [diff] [blame] | 1878 | |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 1879 | gssbuf.value = buffer_get_string(m, &len); |
| 1880 | gssbuf.length = len; |
| 1881 | mic.value = buffer_get_string(m, &len); |
| 1882 | mic.length = len; |
Damien Miller | 787b2ec | 2003-11-21 23:56:47 +1100 | [diff] [blame] | 1883 | |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 1884 | ret = ssh_gssapi_checkmic(gsscontext, &gssbuf, &mic); |
Damien Miller | 787b2ec | 2003-11-21 23:56:47 +1100 | [diff] [blame] | 1885 | |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 1886 | xfree(gssbuf.value); |
| 1887 | xfree(mic.value); |
Damien Miller | 787b2ec | 2003-11-21 23:56:47 +1100 | [diff] [blame] | 1888 | |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 1889 | buffer_clear(m); |
| 1890 | buffer_put_int(m, ret); |
Damien Miller | 787b2ec | 2003-11-21 23:56:47 +1100 | [diff] [blame] | 1891 | |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1892 | mm_request_send(sock, MONITOR_ANS_GSSCHECKMIC, m); |
Damien Miller | 787b2ec | 2003-11-21 23:56:47 +1100 | [diff] [blame] | 1893 | |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 1894 | if (!GSS_ERROR(ret)) |
| 1895 | monitor_permit(mon_dispatch, MONITOR_REQ_GSSUSEROK, 1); |
Damien Miller | 787b2ec | 2003-11-21 23:56:47 +1100 | [diff] [blame] | 1896 | |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 1897 | return (0); |
| 1898 | } |
| 1899 | |
| 1900 | int |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1901 | mm_answer_gss_userok(int sock, Buffer *m) |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1902 | { |
| 1903 | int authenticated; |
| 1904 | |
| 1905 | authenticated = authctxt->valid && ssh_gssapi_userok(authctxt->user); |
| 1906 | |
| 1907 | buffer_clear(m); |
| 1908 | buffer_put_int(m, authenticated); |
| 1909 | |
| 1910 | debug3("%s: sending result %d", __func__, authenticated); |
Darren Tucker | 3f9fdc7 | 2004-06-22 12:56:01 +1000 | [diff] [blame] | 1911 | mm_request_send(sock, MONITOR_ANS_GSSUSEROK, m); |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1912 | |
Damien Miller | 0425d40 | 2003-11-17 22:18:21 +1100 | [diff] [blame] | 1913 | auth_method="gssapi-with-mic"; |
Darren Tucker | 0efd155 | 2003-08-26 11:49:55 +1000 | [diff] [blame] | 1914 | |
| 1915 | /* Monitor loop will terminate if authenticated */ |
| 1916 | return (authenticated); |
| 1917 | } |
| 1918 | #endif /* GSSAPI */ |