Annotation of src/usr.bin/ssh/monitor_wrap.c, Revision 1.98
1.98 ! markus 1: /* $OpenBSD: monitor_wrap.c,v 1.97 2017/12/21 00:00:28 djm Exp $ */
1.1 provos 2: /*
3: * Copyright 2002 Niels Provos <provos@citi.umich.edu>
4: * Copyright 2002 Markus Friedl <markus@openbsd.org>
5: * All rights reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: *
16: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26: */
27:
1.46 stevesk 28: #include <sys/types.h>
1.51 dtucker 29: #include <sys/uio.h>
1.61 djm 30: #include <sys/queue.h>
1.46 stevesk 31:
1.47 stevesk 32: #include <errno.h>
1.46 stevesk 33: #include <pwd.h>
1.50 deraadt 34: #include <signal.h>
1.49 stevesk 35: #include <stdio.h>
1.48 stevesk 36: #include <string.h>
1.51 dtucker 37: #include <unistd.h>
1.68 dtucker 38:
1.80 markus 39: #ifdef WITH_OPENSSL
1.68 dtucker 40: #include <openssl/bn.h>
41: #include <openssl/dh.h>
1.80 markus 42: #endif
1.1 provos 43:
1.50 deraadt 44: #include "xmalloc.h"
1.1 provos 45: #include "ssh.h"
1.80 markus 46: #ifdef WITH_OPENSSL
1.1 provos 47: #include "dh.h"
1.80 markus 48: #endif
1.50 deraadt 49: #include "buffer.h"
50: #include "key.h"
51: #include "cipher.h"
1.1 provos 52: #include "kex.h"
1.50 deraadt 53: #include "hostfile.h"
1.1 provos 54: #include "auth.h"
1.22 markus 55: #include "auth-options.h"
1.1 provos 56: #include "packet.h"
57: #include "mac.h"
58: #include "log.h"
1.54 miod 59: #include <zlib.h>
1.1 provos 60: #include "monitor.h"
1.50 deraadt 61: #ifdef GSSAPI
62: #include "ssh-gss.h"
63: #endif
1.1 provos 64: #include "monitor_wrap.h"
65: #include "atomicio.h"
66: #include "monitor_fdpass.h"
1.45 djm 67: #include "misc.h"
1.1 provos 68:
69: #include "channels.h"
70: #include "session.h"
1.55 dtucker 71: #include "servconf.h"
1.29 markus 72:
1.82 markus 73: #include "ssherr.h"
74:
1.1 provos 75: /* Imports */
76: extern z_stream incoming_stream;
77: extern z_stream outgoing_stream;
1.7 mouring 78: extern struct monitor *pmonitor;
1.39 dtucker 79: extern Buffer loginmsg;
1.55 dtucker 80: extern ServerOptions options;
1.73 djm 81:
82: void
83: mm_log_handler(LogLevel level, const char *msg, void *ctx)
84: {
85: Buffer log_msg;
86: struct monitor *mon = (struct monitor *)ctx;
87:
88: if (mon->m_log_sendfd == -1)
89: fatal("%s: no log channel", __func__);
90:
91: buffer_init(&log_msg);
92: /*
93: * Placeholder for packet length. Will be filled in with the actual
94: * packet length once the packet has been constucted. This saves
95: * fragile math.
96: */
97: buffer_put_int(&log_msg, 0);
98:
99: buffer_put_int(&log_msg, level);
100: buffer_put_cstring(&log_msg, msg);
101: put_u32(buffer_ptr(&log_msg), buffer_len(&log_msg) - 4);
102: if (atomicio(vwrite, mon->m_log_sendfd, buffer_ptr(&log_msg),
103: buffer_len(&log_msg)) != buffer_len(&log_msg))
104: fatal("%s: write: %s", __func__, strerror(errno));
105: buffer_free(&log_msg);
106: }
1.1 provos 107:
1.32 markus 108: int
109: mm_is_monitor(void)
110: {
111: /*
112: * m_pid is only set in the privileged part, and
113: * points to the unprivileged child.
114: */
1.34 markus 115: return (pmonitor && pmonitor->m_pid > 0);
1.32 markus 116: }
117:
1.1 provos 118: void
1.36 avsm 119: mm_request_send(int sock, enum monitor_reqtype type, Buffer *m)
1.1 provos 120: {
1.13 deraadt 121: u_int mlen = buffer_len(m);
1.1 provos 122: u_char buf[5];
123:
1.8 markus 124: debug3("%s entering: type %d", __func__, type);
1.1 provos 125:
1.45 djm 126: put_u32(buf, mlen + 1);
1.10 deraadt 127: buf[4] = (u_char) type; /* 1st byte of payload is mesg-type */
1.36 avsm 128: if (atomicio(vwrite, sock, buf, sizeof(buf)) != sizeof(buf))
1.40 avsm 129: fatal("%s: write: %s", __func__, strerror(errno));
1.36 avsm 130: if (atomicio(vwrite, sock, buffer_ptr(m), mlen) != mlen)
1.40 avsm 131: fatal("%s: write: %s", __func__, strerror(errno));
1.1 provos 132: }
133:
134: void
1.36 avsm 135: mm_request_receive(int sock, Buffer *m)
1.1 provos 136: {
137: u_char buf[4];
1.13 deraadt 138: u_int msg_len;
1.1 provos 139:
1.8 markus 140: debug3("%s entering", __func__);
1.1 provos 141:
1.40 avsm 142: if (atomicio(read, sock, buf, sizeof(buf)) != sizeof(buf)) {
143: if (errno == EPIPE)
1.32 markus 144: cleanup_exit(255);
1.40 avsm 145: fatal("%s: read: %s", __func__, strerror(errno));
1.1 provos 146: }
1.45 djm 147: msg_len = get_u32(buf);
1.1 provos 148: if (msg_len > 256 * 1024)
1.8 markus 149: fatal("%s: read: bad msg_len %d", __func__, msg_len);
1.1 provos 150: buffer_clear(m);
151: buffer_append_space(m, msg_len);
1.40 avsm 152: if (atomicio(read, sock, buffer_ptr(m), msg_len) != msg_len)
153: fatal("%s: read: %s", __func__, strerror(errno));
1.1 provos 154: }
155:
156: void
1.36 avsm 157: mm_request_receive_expect(int sock, enum monitor_reqtype type, Buffer *m)
1.1 provos 158: {
159: u_char rtype;
160:
1.8 markus 161: debug3("%s entering: type %d", __func__, type);
1.1 provos 162:
1.36 avsm 163: mm_request_receive(sock, m);
1.1 provos 164: rtype = buffer_get_char(m);
165: if (rtype != type)
1.8 markus 166: fatal("%s: read: rtype %d != type %d", __func__,
1.1 provos 167: rtype, type);
168: }
169:
1.80 markus 170: #ifdef WITH_OPENSSL
1.1 provos 171: DH *
172: mm_choose_dh(int min, int nbits, int max)
173: {
174: BIGNUM *p, *g;
175: int success = 0;
176: Buffer m;
177:
178: buffer_init(&m);
179: buffer_put_int(&m, min);
180: buffer_put_int(&m, nbits);
181: buffer_put_int(&m, max);
182:
1.7 mouring 183: mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_MODULI, &m);
1.1 provos 184:
1.8 markus 185: debug3("%s: waiting for MONITOR_ANS_MODULI", __func__);
1.7 mouring 186: mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_MODULI, &m);
1.1 provos 187:
188: success = buffer_get_char(&m);
189: if (success == 0)
1.8 markus 190: fatal("%s: MONITOR_ANS_MODULI failed", __func__);
1.1 provos 191:
192: if ((p = BN_new()) == NULL)
1.8 markus 193: fatal("%s: BN_new failed", __func__);
1.3 markus 194: if ((g = BN_new()) == NULL)
1.8 markus 195: fatal("%s: BN_new failed", __func__);
1.1 provos 196: buffer_get_bignum2(&m, p);
197: buffer_get_bignum2(&m, g);
198:
1.8 markus 199: debug3("%s: remaining %d", __func__, buffer_len(&m));
1.1 provos 200: buffer_free(&m);
201:
202: return (dh_new_group(g, p));
203: }
1.80 markus 204: #endif
1.1 provos 205:
206: int
1.91 markus 207: mm_key_sign(struct sshkey *key, u_char **sigp, u_int *lenp,
1.86 markus 208: const u_char *data, u_int datalen, const char *hostkey_alg)
1.1 provos 209: {
1.83 markus 210: struct kex *kex = *pmonitor->m_pkex;
1.1 provos 211: Buffer m;
212:
1.8 markus 213: debug3("%s entering", __func__);
1.1 provos 214:
215: buffer_init(&m);
1.84 djm 216: buffer_put_int(&m, kex->host_key_index(key, 0, active_state));
1.1 provos 217: buffer_put_string(&m, data, datalen);
1.86 markus 218: buffer_put_cstring(&m, hostkey_alg);
1.1 provos 219:
1.7 mouring 220: mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_SIGN, &m);
1.1 provos 221:
1.8 markus 222: debug3("%s: waiting for MONITOR_ANS_SIGN", __func__);
1.7 mouring 223: mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_SIGN, &m);
1.1 provos 224: *sigp = buffer_get_string(&m, lenp);
225: buffer_free(&m);
226:
227: return (0);
228: }
229:
230: struct passwd *
1.37 dtucker 231: mm_getpwnamallow(const char *username)
1.1 provos 232: {
1.93 djm 233: struct ssh *ssh = active_state; /* XXX */
1.1 provos 234: Buffer m;
235: struct passwd *pw;
1.72 djm 236: u_int len, i;
1.55 dtucker 237: ServerOptions *newopts;
1.1 provos 238:
1.8 markus 239: debug3("%s entering", __func__);
1.1 provos 240:
241: buffer_init(&m);
1.37 dtucker 242: buffer_put_cstring(&m, username);
1.1 provos 243:
1.7 mouring 244: mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PWNAM, &m);
1.1 provos 245:
1.8 markus 246: debug3("%s: waiting for MONITOR_ANS_PWNAM", __func__);
1.7 mouring 247: mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PWNAM, &m);
1.1 provos 248:
249: if (buffer_get_char(&m) == 0) {
1.60 dtucker 250: pw = NULL;
251: goto out;
1.1 provos 252: }
1.55 dtucker 253: pw = buffer_get_string(&m, &len);
254: if (len != sizeof(struct passwd))
1.8 markus 255: fatal("%s: struct passwd size mismatch", __func__);
1.1 provos 256: pw->pw_name = buffer_get_string(&m, NULL);
257: pw->pw_passwd = buffer_get_string(&m, NULL);
258: pw->pw_gecos = buffer_get_string(&m, NULL);
259: pw->pw_class = buffer_get_string(&m, NULL);
260: pw->pw_dir = buffer_get_string(&m, NULL);
261: pw->pw_shell = buffer_get_string(&m, NULL);
1.55 dtucker 262:
1.60 dtucker 263: out:
1.55 dtucker 264: /* copy options block as a Match directive may have changed some */
265: newopts = buffer_get_string(&m, &len);
266: if (len != sizeof(*newopts))
267: fatal("%s: option block size mismatch", __func__);
1.71 djm 268:
269: #define M_CP_STROPT(x) do { \
270: if (newopts->x != NULL) \
271: newopts->x = buffer_get_string(&m, NULL); \
272: } while (0)
1.72 djm 273: #define M_CP_STRARRAYOPT(x, nx) do { \
1.95 djm 274: newopts->x = newopts->nx == 0 ? \
275: NULL : xcalloc(newopts->nx, sizeof(*newopts->x)); \
1.72 djm 276: for (i = 0; i < newopts->nx; i++) \
277: newopts->x[i] = buffer_get_string(&m, NULL); \
278: } while (0)
1.71 djm 279: /* See comment in servconf.h */
280: COPY_MATCH_STRING_OPTS();
281: #undef M_CP_STROPT
1.72 djm 282: #undef M_CP_STRARRAYOPT
1.71 djm 283:
1.55 dtucker 284: copy_set_server_options(&options, newopts, 1);
1.90 djm 285: log_change_level(options.log_level);
1.93 djm 286: process_permitopen(ssh, &options);
1.76 djm 287: free(newopts);
1.55 dtucker 288:
1.1 provos 289: buffer_free(&m);
290:
291: return (pw);
1.6 djm 292: }
293:
1.33 markus 294: char *
295: mm_auth2_read_banner(void)
1.6 djm 296: {
297: Buffer m;
298: char *banner;
299:
1.8 markus 300: debug3("%s entering", __func__);
1.6 djm 301:
302: buffer_init(&m);
1.7 mouring 303: mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTH2_READ_BANNER, &m);
1.6 djm 304: buffer_clear(&m);
305:
1.33 markus 306: mm_request_receive_expect(pmonitor->m_recvfd,
307: MONITOR_ANS_AUTH2_READ_BANNER, &m);
1.6 djm 308: banner = buffer_get_string(&m, NULL);
309: buffer_free(&m);
1.10 deraadt 310:
1.33 markus 311: /* treat empty banner as missing banner */
312: if (strlen(banner) == 0) {
1.76 djm 313: free(banner);
1.33 markus 314: banner = NULL;
315: }
1.6 djm 316: return (banner);
1.1 provos 317: }
318:
319: /* Inform the privileged process about service and style */
320:
321: void
322: mm_inform_authserv(char *service, char *style)
323: {
324: Buffer m;
325:
1.8 markus 326: debug3("%s entering", __func__);
1.1 provos 327:
328: buffer_init(&m);
329: buffer_put_cstring(&m, service);
330: buffer_put_cstring(&m, style ? style : "");
331:
1.7 mouring 332: mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHSERV, &m);
1.1 provos 333:
334: buffer_free(&m);
335: }
336:
337: /* Do the password authentication */
338: int
339: mm_auth_password(Authctxt *authctxt, char *password)
340: {
341: Buffer m;
342: int authenticated = 0;
343:
1.8 markus 344: debug3("%s entering", __func__);
1.1 provos 345:
346: buffer_init(&m);
347: buffer_put_cstring(&m, password);
1.7 mouring 348: mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHPASSWORD, &m);
1.1 provos 349:
1.8 markus 350: debug3("%s: waiting for MONITOR_ANS_AUTHPASSWORD", __func__);
1.7 mouring 351: mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_AUTHPASSWORD, &m);
1.1 provos 352:
353: authenticated = buffer_get_int(&m);
354:
355: buffer_free(&m);
356:
1.3 markus 357: debug3("%s: user %sauthenticated",
1.8 markus 358: __func__, authenticated ? "" : "not ");
1.1 provos 359: return (authenticated);
360: }
361:
362: int
1.91 markus 363: mm_user_key_allowed(struct passwd *pw, struct sshkey *key,
364: int pubkey_auth_attempt)
1.1 provos 365: {
1.85 djm 366: return (mm_key_allowed(MM_USERKEY, NULL, NULL, key,
367: pubkey_auth_attempt));
1.1 provos 368: }
369:
370: int
1.88 djm 371: mm_hostbased_key_allowed(struct passwd *pw, const char *user, const char *host,
1.91 markus 372: struct sshkey *key)
1.1 provos 373: {
1.85 djm 374: return (mm_key_allowed(MM_HOSTKEY, user, host, key, 0));
1.1 provos 375: }
376:
377: int
1.88 djm 378: mm_key_allowed(enum mm_keytype type, const char *user, const char *host,
1.91 markus 379: struct sshkey *key, int pubkey_auth_attempt)
1.1 provos 380: {
381: Buffer m;
382: u_char *blob;
383: u_int len;
1.22 markus 384: int allowed = 0, have_forced = 0;
1.1 provos 385:
1.8 markus 386: debug3("%s entering", __func__);
1.1 provos 387:
388: /* Convert the key to a blob and the pass it over */
389: if (!key_to_blob(key, &blob, &len))
390: return (0);
391:
392: buffer_init(&m);
393: buffer_put_int(&m, type);
394: buffer_put_cstring(&m, user ? user : "");
395: buffer_put_cstring(&m, host ? host : "");
396: buffer_put_string(&m, blob, len);
1.85 djm 397: buffer_put_int(&m, pubkey_auth_attempt);
1.76 djm 398: free(blob);
1.1 provos 399:
1.7 mouring 400: mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_KEYALLOWED, &m);
1.1 provos 401:
1.8 markus 402: debug3("%s: waiting for MONITOR_ANS_KEYALLOWED", __func__);
1.7 mouring 403: mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_KEYALLOWED, &m);
1.1 provos 404:
405: allowed = buffer_get_int(&m);
406:
1.22 markus 407: /* fake forced command */
408: auth_clear_options();
409: have_forced = buffer_get_int(&m);
410: forced_command = have_forced ? xstrdup("true") : NULL;
411:
1.1 provos 412: buffer_free(&m);
413:
414: return (allowed);
415: }
416:
1.3 markus 417: /*
1.1 provos 418: * This key verify needs to send the key type along, because the
419: * privileged parent makes the decision if the key is allowed
420: * for authentication.
421: */
422:
423: int
1.92 markus 424: mm_sshkey_verify(const struct sshkey *key, const u_char *sig, size_t siglen,
1.96 djm 425: const u_char *data, size_t datalen, const char *sigalg, u_int compat)
1.1 provos 426: {
427: Buffer m;
428: u_char *blob;
429: u_int len;
1.92 markus 430: u_int encoded_ret = 0;
1.1 provos 431:
1.8 markus 432: debug3("%s entering", __func__);
1.1 provos 433:
434: /* Convert the key to a blob and the pass it over */
435: if (!key_to_blob(key, &blob, &len))
436: return (0);
437:
438: buffer_init(&m);
439: buffer_put_string(&m, blob, len);
440: buffer_put_string(&m, sig, siglen);
441: buffer_put_string(&m, data, datalen);
1.97 djm 442: buffer_put_cstring(&m, sigalg == NULL ? "" : sigalg);
1.76 djm 443: free(blob);
1.1 provos 444:
1.7 mouring 445: mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_KEYVERIFY, &m);
1.1 provos 446:
1.8 markus 447: debug3("%s: waiting for MONITOR_ANS_KEYVERIFY", __func__);
1.7 mouring 448: mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_KEYVERIFY, &m);
1.1 provos 449:
1.92 markus 450: encoded_ret = buffer_get_int(&m);
1.1 provos 451:
452: buffer_free(&m);
453:
1.92 markus 454: if (encoded_ret != 0)
455: return SSH_ERR_SIGNATURE_INVALID;
456: return 0;
1.1 provos 457: }
458:
459: void
1.36 avsm 460: mm_send_keystate(struct monitor *monitor)
1.1 provos 461: {
1.82 markus 462: struct ssh *ssh = active_state; /* XXX */
463: struct sshbuf *m;
464: int r;
465:
466: if ((m = sshbuf_new()) == NULL)
467: fatal("%s: sshbuf_new failed", __func__);
468: if ((r = ssh_packet_get_state(ssh, m)) != 0)
469: fatal("%s: get_state failed: %s",
470: __func__, ssh_err(r));
471: mm_request_send(monitor->m_recvfd, MONITOR_REQ_KEYEXPORT, m);
1.8 markus 472: debug3("%s: Finished sending state", __func__);
1.82 markus 473: sshbuf_free(m);
1.1 provos 474: }
475:
476: int
1.42 deraadt 477: mm_pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, size_t namebuflen)
1.1 provos 478: {
479: Buffer m;
1.39 dtucker 480: char *p, *msg;
1.62 djm 481: int success = 0, tmp1 = -1, tmp2 = -1;
482:
483: /* Kludge: ensure there are fds free to receive the pty/tty */
484: if ((tmp1 = dup(pmonitor->m_recvfd)) == -1 ||
485: (tmp2 = dup(pmonitor->m_recvfd)) == -1) {
486: error("%s: cannot allocate fds for pty", __func__);
487: if (tmp1 > 0)
488: close(tmp1);
489: if (tmp2 > 0)
490: close(tmp2);
491: return 0;
492: }
493: close(tmp1);
494: close(tmp2);
1.1 provos 495:
496: buffer_init(&m);
1.7 mouring 497: mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PTY, &m);
1.1 provos 498:
1.8 markus 499: debug3("%s: waiting for MONITOR_ANS_PTY", __func__);
1.7 mouring 500: mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PTY, &m);
1.1 provos 501:
502: success = buffer_get_int(&m);
503: if (success == 0) {
1.8 markus 504: debug3("%s: pty alloc failed", __func__);
1.1 provos 505: buffer_free(&m);
506: return (0);
507: }
508: p = buffer_get_string(&m, NULL);
1.39 dtucker 509: msg = buffer_get_string(&m, NULL);
1.1 provos 510: buffer_free(&m);
511:
512: strlcpy(namebuf, p, namebuflen); /* Possible truncation */
1.76 djm 513: free(p);
1.39 dtucker 514:
515: buffer_append(&loginmsg, msg, strlen(msg));
1.76 djm 516: free(msg);
1.1 provos 517:
1.58 djm 518: if ((*ptyfd = mm_receive_fd(pmonitor->m_recvfd)) == -1 ||
519: (*ttyfd = mm_receive_fd(pmonitor->m_recvfd)) == -1)
520: fatal("%s: receive fds failed", __func__);
1.1 provos 521:
522: /* Success */
523: return (1);
524: }
525:
526: void
1.32 markus 527: mm_session_pty_cleanup2(Session *s)
1.1 provos 528: {
529: Buffer m;
530:
531: if (s->ttyfd == -1)
532: return;
533: buffer_init(&m);
534: buffer_put_cstring(&m, s->tty);
1.7 mouring 535: mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PTYCLEANUP, &m);
1.1 provos 536: buffer_free(&m);
1.3 markus 537:
1.1 provos 538: /* closed dup'ed master */
1.62 djm 539: if (s->ptymaster != -1 && close(s->ptymaster) < 0)
540: error("close(s->ptymaster/%d): %s",
541: s->ptymaster, strerror(errno));
1.1 provos 542:
543: /* unlink pty from session */
544: s->ttyfd = -1;
545: }
546:
547: /* Request process termination */
548:
549: void
550: mm_terminate(void)
551: {
552: Buffer m;
553:
554: buffer_init(&m);
1.7 mouring 555: mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_TERM, &m);
1.1 provos 556: buffer_free(&m);
557: }
558:
1.2 markus 559: static void
1.1 provos 560: mm_chall_setup(char **name, char **infotxt, u_int *numprompts,
561: char ***prompts, u_int **echo_on)
562: {
1.10 deraadt 563: *name = xstrdup("");
564: *infotxt = xstrdup("");
1.1 provos 565: *numprompts = 1;
1.43 djm 566: *prompts = xcalloc(*numprompts, sizeof(char *));
567: *echo_on = xcalloc(*numprompts, sizeof(u_int));
1.1 provos 568: (*echo_on)[0] = 0;
569: }
570:
571: int
572: mm_bsdauth_query(void *ctx, char **name, char **infotxt,
573: u_int *numprompts, char ***prompts, u_int **echo_on)
574: {
575: Buffer m;
1.21 markus 576: u_int success;
1.1 provos 577: char *challenge;
578:
1.8 markus 579: debug3("%s: entering", __func__);
1.1 provos 580:
581: buffer_init(&m);
1.7 mouring 582: mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_BSDAUTHQUERY, &m);
1.1 provos 583:
1.7 mouring 584: mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_BSDAUTHQUERY,
1.1 provos 585: &m);
1.21 markus 586: success = buffer_get_int(&m);
587: if (success == 0) {
1.8 markus 588: debug3("%s: no challenge", __func__);
1.1 provos 589: buffer_free(&m);
590: return (-1);
591: }
592:
593: /* Get the challenge, and format the response */
594: challenge = buffer_get_string(&m, NULL);
595: buffer_free(&m);
596:
597: mm_chall_setup(name, infotxt, numprompts, prompts, echo_on);
598: (*prompts)[0] = challenge;
599:
1.8 markus 600: debug3("%s: received challenge: %s", __func__, challenge);
1.1 provos 601:
602: return (0);
603: }
604:
605: int
606: mm_bsdauth_respond(void *ctx, u_int numresponses, char **responses)
607: {
608: Buffer m;
609: int authok;
610:
1.8 markus 611: debug3("%s: entering", __func__);
1.1 provos 612: if (numresponses != 1)
613: return (-1);
614:
615: buffer_init(&m);
616: buffer_put_cstring(&m, responses[0]);
1.7 mouring 617: mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_BSDAUTHRESPOND, &m);
1.1 provos 618:
1.7 mouring 619: mm_request_receive_expect(pmonitor->m_recvfd,
1.1 provos 620: MONITOR_ANS_BSDAUTHRESPOND, &m);
621:
622: authok = buffer_get_int(&m);
623: buffer_free(&m);
624:
625: return ((authok == 0) ? -1 : 0);
626: }
1.29 markus 627:
628: #ifdef GSSAPI
629: OM_uint32
1.36 avsm 630: mm_ssh_gssapi_server_ctx(Gssctxt **ctx, gss_OID goid)
1.29 markus 631: {
632: Buffer m;
633: OM_uint32 major;
634:
635: /* Client doesn't get to see the context */
636: *ctx = NULL;
637:
638: buffer_init(&m);
1.36 avsm 639: buffer_put_string(&m, goid->elements, goid->length);
1.29 markus 640:
641: mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSSETUP, &m);
642: mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSSETUP, &m);
643:
644: major = buffer_get_int(&m);
645:
646: buffer_free(&m);
647: return (major);
648: }
649:
650: OM_uint32
651: mm_ssh_gssapi_accept_ctx(Gssctxt *ctx, gss_buffer_desc *in,
652: gss_buffer_desc *out, OM_uint32 *flags)
653: {
654: Buffer m;
655: OM_uint32 major;
1.30 deraadt 656: u_int len;
1.29 markus 657:
658: buffer_init(&m);
659: buffer_put_string(&m, in->value, in->length);
660:
661: mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSSTEP, &m);
662: mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSSTEP, &m);
663:
664: major = buffer_get_int(&m);
1.30 deraadt 665: out->value = buffer_get_string(&m, &len);
666: out->length = len;
1.29 markus 667: if (flags)
668: *flags = buffer_get_int(&m);
669:
670: buffer_free(&m);
671:
672: return (major);
1.35 markus 673: }
674:
675: OM_uint32
676: mm_ssh_gssapi_checkmic(Gssctxt *ctx, gss_buffer_t gssbuf, gss_buffer_t gssmic)
677: {
678: Buffer m;
679: OM_uint32 major;
680:
681: buffer_init(&m);
682: buffer_put_string(&m, gssbuf->value, gssbuf->length);
683: buffer_put_string(&m, gssmic->value, gssmic->length);
684:
685: mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSCHECKMIC, &m);
686: mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSCHECKMIC,
687: &m);
688:
689: major = buffer_get_int(&m);
690: buffer_free(&m);
691: return(major);
1.29 markus 692: }
693:
694: int
695: mm_ssh_gssapi_userok(char *user)
696: {
697: Buffer m;
698: int authenticated = 0;
699:
700: buffer_init(&m);
701:
702: mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSUSEROK, &m);
703: mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSUSEROK,
704: &m);
705:
706: authenticated = buffer_get_int(&m);
707:
708: buffer_free(&m);
709: debug3("%s: user %sauthenticated",__func__, authenticated ? "" : "not ");
710: return (authenticated);
711: }
712: #endif /* GSSAPI */
1.64 djm 713: