xref: /openbsd-src/usr.bin/ssh/monitor_wrap.c (revision ae3cb403620ab940fbaabb3055fac045a63d56b7)
1 /* $OpenBSD: monitor_wrap.c,v 1.98 2018/01/08 15:14:44 markus Exp $ */
2 /*
3  * Copyright 2002 Niels Provos <provos@citi.umich.edu>
4  * Copyright 2002 Markus Friedl <markus@openbsd.org>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include <sys/types.h>
29 #include <sys/uio.h>
30 #include <sys/queue.h>
31 
32 #include <errno.h>
33 #include <pwd.h>
34 #include <signal.h>
35 #include <stdio.h>
36 #include <string.h>
37 #include <unistd.h>
38 
39 #ifdef WITH_OPENSSL
40 #include <openssl/bn.h>
41 #include <openssl/dh.h>
42 #endif
43 
44 #include "xmalloc.h"
45 #include "ssh.h"
46 #ifdef WITH_OPENSSL
47 #include "dh.h"
48 #endif
49 #include "buffer.h"
50 #include "key.h"
51 #include "cipher.h"
52 #include "kex.h"
53 #include "hostfile.h"
54 #include "auth.h"
55 #include "auth-options.h"
56 #include "packet.h"
57 #include "mac.h"
58 #include "log.h"
59 #include <zlib.h>
60 #include "monitor.h"
61 #ifdef GSSAPI
62 #include "ssh-gss.h"
63 #endif
64 #include "monitor_wrap.h"
65 #include "atomicio.h"
66 #include "monitor_fdpass.h"
67 #include "misc.h"
68 
69 #include "channels.h"
70 #include "session.h"
71 #include "servconf.h"
72 
73 #include "ssherr.h"
74 
75 /* Imports */
76 extern z_stream incoming_stream;
77 extern z_stream outgoing_stream;
78 extern struct monitor *pmonitor;
79 extern Buffer loginmsg;
80 extern ServerOptions options;
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 }
107 
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 	 */
115 	return (pmonitor && pmonitor->m_pid > 0);
116 }
117 
118 void
119 mm_request_send(int sock, enum monitor_reqtype type, Buffer *m)
120 {
121 	u_int mlen = buffer_len(m);
122 	u_char buf[5];
123 
124 	debug3("%s entering: type %d", __func__, type);
125 
126 	put_u32(buf, mlen + 1);
127 	buf[4] = (u_char) type;		/* 1st byte of payload is mesg-type */
128 	if (atomicio(vwrite, sock, buf, sizeof(buf)) != sizeof(buf))
129 		fatal("%s: write: %s", __func__, strerror(errno));
130 	if (atomicio(vwrite, sock, buffer_ptr(m), mlen) != mlen)
131 		fatal("%s: write: %s", __func__, strerror(errno));
132 }
133 
134 void
135 mm_request_receive(int sock, Buffer *m)
136 {
137 	u_char buf[4];
138 	u_int msg_len;
139 
140 	debug3("%s entering", __func__);
141 
142 	if (atomicio(read, sock, buf, sizeof(buf)) != sizeof(buf)) {
143 		if (errno == EPIPE)
144 			cleanup_exit(255);
145 		fatal("%s: read: %s", __func__, strerror(errno));
146 	}
147 	msg_len = get_u32(buf);
148 	if (msg_len > 256 * 1024)
149 		fatal("%s: read: bad msg_len %d", __func__, msg_len);
150 	buffer_clear(m);
151 	buffer_append_space(m, msg_len);
152 	if (atomicio(read, sock, buffer_ptr(m), msg_len) != msg_len)
153 		fatal("%s: read: %s", __func__, strerror(errno));
154 }
155 
156 void
157 mm_request_receive_expect(int sock, enum monitor_reqtype type, Buffer *m)
158 {
159 	u_char rtype;
160 
161 	debug3("%s entering: type %d", __func__, type);
162 
163 	mm_request_receive(sock, m);
164 	rtype = buffer_get_char(m);
165 	if (rtype != type)
166 		fatal("%s: read: rtype %d != type %d", __func__,
167 		    rtype, type);
168 }
169 
170 #ifdef WITH_OPENSSL
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 
183 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_MODULI, &m);
184 
185 	debug3("%s: waiting for MONITOR_ANS_MODULI", __func__);
186 	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_MODULI, &m);
187 
188 	success = buffer_get_char(&m);
189 	if (success == 0)
190 		fatal("%s: MONITOR_ANS_MODULI failed", __func__);
191 
192 	if ((p = BN_new()) == NULL)
193 		fatal("%s: BN_new failed", __func__);
194 	if ((g = BN_new()) == NULL)
195 		fatal("%s: BN_new failed", __func__);
196 	buffer_get_bignum2(&m, p);
197 	buffer_get_bignum2(&m, g);
198 
199 	debug3("%s: remaining %d", __func__, buffer_len(&m));
200 	buffer_free(&m);
201 
202 	return (dh_new_group(g, p));
203 }
204 #endif
205 
206 int
207 mm_key_sign(struct sshkey *key, u_char **sigp, u_int *lenp,
208     const u_char *data, u_int datalen, const char *hostkey_alg)
209 {
210 	struct kex *kex = *pmonitor->m_pkex;
211 	Buffer m;
212 
213 	debug3("%s entering", __func__);
214 
215 	buffer_init(&m);
216 	buffer_put_int(&m, kex->host_key_index(key, 0, active_state));
217 	buffer_put_string(&m, data, datalen);
218 	buffer_put_cstring(&m, hostkey_alg);
219 
220 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_SIGN, &m);
221 
222 	debug3("%s: waiting for MONITOR_ANS_SIGN", __func__);
223 	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_SIGN, &m);
224 	*sigp  = buffer_get_string(&m, lenp);
225 	buffer_free(&m);
226 
227 	return (0);
228 }
229 
230 struct passwd *
231 mm_getpwnamallow(const char *username)
232 {
233 	struct ssh *ssh = active_state;		/* XXX */
234 	Buffer m;
235 	struct passwd *pw;
236 	u_int len, i;
237 	ServerOptions *newopts;
238 
239 	debug3("%s entering", __func__);
240 
241 	buffer_init(&m);
242 	buffer_put_cstring(&m, username);
243 
244 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PWNAM, &m);
245 
246 	debug3("%s: waiting for MONITOR_ANS_PWNAM", __func__);
247 	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PWNAM, &m);
248 
249 	if (buffer_get_char(&m) == 0) {
250 		pw = NULL;
251 		goto out;
252 	}
253 	pw = buffer_get_string(&m, &len);
254 	if (len != sizeof(struct passwd))
255 		fatal("%s: struct passwd size mismatch", __func__);
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);
262 
263 out:
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__);
268 
269 #define M_CP_STROPT(x) do { \
270 		if (newopts->x != NULL) \
271 			newopts->x = buffer_get_string(&m, NULL); \
272 	} while (0)
273 #define M_CP_STRARRAYOPT(x, nx) do { \
274 		newopts->x = newopts->nx == 0 ? \
275 		    NULL : xcalloc(newopts->nx, sizeof(*newopts->x)); \
276 		for (i = 0; i < newopts->nx; i++) \
277 			newopts->x[i] = buffer_get_string(&m, NULL); \
278 	} while (0)
279 	/* See comment in servconf.h */
280 	COPY_MATCH_STRING_OPTS();
281 #undef M_CP_STROPT
282 #undef M_CP_STRARRAYOPT
283 
284 	copy_set_server_options(&options, newopts, 1);
285 	log_change_level(options.log_level);
286 	process_permitopen(ssh, &options);
287 	free(newopts);
288 
289 	buffer_free(&m);
290 
291 	return (pw);
292 }
293 
294 char *
295 mm_auth2_read_banner(void)
296 {
297 	Buffer m;
298 	char *banner;
299 
300 	debug3("%s entering", __func__);
301 
302 	buffer_init(&m);
303 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTH2_READ_BANNER, &m);
304 	buffer_clear(&m);
305 
306 	mm_request_receive_expect(pmonitor->m_recvfd,
307 	    MONITOR_ANS_AUTH2_READ_BANNER, &m);
308 	banner = buffer_get_string(&m, NULL);
309 	buffer_free(&m);
310 
311 	/* treat empty banner as missing banner */
312 	if (strlen(banner) == 0) {
313 		free(banner);
314 		banner = NULL;
315 	}
316 	return (banner);
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 
326 	debug3("%s entering", __func__);
327 
328 	buffer_init(&m);
329 	buffer_put_cstring(&m, service);
330 	buffer_put_cstring(&m, style ? style : "");
331 
332 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHSERV, &m);
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 
344 	debug3("%s entering", __func__);
345 
346 	buffer_init(&m);
347 	buffer_put_cstring(&m, password);
348 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHPASSWORD, &m);
349 
350 	debug3("%s: waiting for MONITOR_ANS_AUTHPASSWORD", __func__);
351 	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_AUTHPASSWORD, &m);
352 
353 	authenticated = buffer_get_int(&m);
354 
355 	buffer_free(&m);
356 
357 	debug3("%s: user %sauthenticated",
358 	    __func__, authenticated ? "" : "not ");
359 	return (authenticated);
360 }
361 
362 int
363 mm_user_key_allowed(struct passwd *pw, struct sshkey *key,
364     int pubkey_auth_attempt)
365 {
366 	return (mm_key_allowed(MM_USERKEY, NULL, NULL, key,
367 	    pubkey_auth_attempt));
368 }
369 
370 int
371 mm_hostbased_key_allowed(struct passwd *pw, const char *user, const char *host,
372     struct sshkey *key)
373 {
374 	return (mm_key_allowed(MM_HOSTKEY, user, host, key, 0));
375 }
376 
377 int
378 mm_key_allowed(enum mm_keytype type, const char *user, const char *host,
379     struct sshkey *key, int pubkey_auth_attempt)
380 {
381 	Buffer m;
382 	u_char *blob;
383 	u_int len;
384 	int allowed = 0, have_forced = 0;
385 
386 	debug3("%s entering", __func__);
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);
397 	buffer_put_int(&m, pubkey_auth_attempt);
398 	free(blob);
399 
400 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_KEYALLOWED, &m);
401 
402 	debug3("%s: waiting for MONITOR_ANS_KEYALLOWED", __func__);
403 	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_KEYALLOWED, &m);
404 
405 	allowed = buffer_get_int(&m);
406 
407 	/* fake forced command */
408 	auth_clear_options();
409 	have_forced = buffer_get_int(&m);
410 	forced_command = have_forced ? xstrdup("true") : NULL;
411 
412 	buffer_free(&m);
413 
414 	return (allowed);
415 }
416 
417 /*
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
424 mm_sshkey_verify(const struct sshkey *key, const u_char *sig, size_t siglen,
425     const u_char *data, size_t datalen, const char *sigalg, u_int compat)
426 {
427 	Buffer m;
428 	u_char *blob;
429 	u_int len;
430 	u_int encoded_ret = 0;
431 
432 	debug3("%s entering", __func__);
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);
442 	buffer_put_cstring(&m, sigalg == NULL ? "" : sigalg);
443 	free(blob);
444 
445 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_KEYVERIFY, &m);
446 
447 	debug3("%s: waiting for MONITOR_ANS_KEYVERIFY", __func__);
448 	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_KEYVERIFY, &m);
449 
450 	encoded_ret = buffer_get_int(&m);
451 
452 	buffer_free(&m);
453 
454 	if (encoded_ret != 0)
455 		return SSH_ERR_SIGNATURE_INVALID;
456 	return 0;
457 }
458 
459 void
460 mm_send_keystate(struct monitor *monitor)
461 {
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);
472 	debug3("%s: Finished sending state", __func__);
473 	sshbuf_free(m);
474 }
475 
476 int
477 mm_pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, size_t namebuflen)
478 {
479 	Buffer m;
480 	char *p, *msg;
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);
495 
496 	buffer_init(&m);
497 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PTY, &m);
498 
499 	debug3("%s: waiting for MONITOR_ANS_PTY", __func__);
500 	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PTY, &m);
501 
502 	success = buffer_get_int(&m);
503 	if (success == 0) {
504 		debug3("%s: pty alloc failed", __func__);
505 		buffer_free(&m);
506 		return (0);
507 	}
508 	p = buffer_get_string(&m, NULL);
509 	msg = buffer_get_string(&m, NULL);
510 	buffer_free(&m);
511 
512 	strlcpy(namebuf, p, namebuflen); /* Possible truncation */
513 	free(p);
514 
515 	buffer_append(&loginmsg, msg, strlen(msg));
516 	free(msg);
517 
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__);
521 
522 	/* Success */
523 	return (1);
524 }
525 
526 void
527 mm_session_pty_cleanup2(Session *s)
528 {
529 	Buffer m;
530 
531 	if (s->ttyfd == -1)
532 		return;
533 	buffer_init(&m);
534 	buffer_put_cstring(&m, s->tty);
535 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PTYCLEANUP, &m);
536 	buffer_free(&m);
537 
538 	/* closed dup'ed master */
539 	if (s->ptymaster != -1 && close(s->ptymaster) < 0)
540 		error("close(s->ptymaster/%d): %s",
541 		    s->ptymaster, strerror(errno));
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);
555 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_TERM, &m);
556 	buffer_free(&m);
557 }
558 
559 static void
560 mm_chall_setup(char **name, char **infotxt, u_int *numprompts,
561     char ***prompts, u_int **echo_on)
562 {
563 	*name = xstrdup("");
564 	*infotxt = xstrdup("");
565 	*numprompts = 1;
566 	*prompts = xcalloc(*numprompts, sizeof(char *));
567 	*echo_on = xcalloc(*numprompts, sizeof(u_int));
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;
576 	u_int success;
577 	char *challenge;
578 
579 	debug3("%s: entering", __func__);
580 
581 	buffer_init(&m);
582 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_BSDAUTHQUERY, &m);
583 
584 	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_BSDAUTHQUERY,
585 	    &m);
586 	success = buffer_get_int(&m);
587 	if (success == 0) {
588 		debug3("%s: no challenge", __func__);
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 
600 	debug3("%s: received challenge: %s", __func__, challenge);
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 
611 	debug3("%s: entering", __func__);
612 	if (numresponses != 1)
613 		return (-1);
614 
615 	buffer_init(&m);
616 	buffer_put_cstring(&m, responses[0]);
617 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_BSDAUTHRESPOND, &m);
618 
619 	mm_request_receive_expect(pmonitor->m_recvfd,
620 	    MONITOR_ANS_BSDAUTHRESPOND, &m);
621 
622 	authok = buffer_get_int(&m);
623 	buffer_free(&m);
624 
625 	return ((authok == 0) ? -1 : 0);
626 }
627 
628 #ifdef GSSAPI
629 OM_uint32
630 mm_ssh_gssapi_server_ctx(Gssctxt **ctx, gss_OID goid)
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);
639 	buffer_put_string(&m, goid->elements, goid->length);
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;
656 	u_int len;
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);
665 	out->value = buffer_get_string(&m, &len);
666 	out->length = len;
667 	if (flags)
668 		*flags = buffer_get_int(&m);
669 
670 	buffer_free(&m);
671 
672 	return (major);
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);
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 */
713 
714