xref: /openbsd-src/usr.bin/ssh/monitor_wrap.c (revision c7e8ea31cd41a963f06f0a8ba93948b06aa6b4a4)
1 /* $OpenBSD: monitor_wrap.c,v 1.92 2017/05/30 14:10:53 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 #include "uuencode.h"
69 
70 #include "channels.h"
71 #include "session.h"
72 #include "servconf.h"
73 
74 #include "ssherr.h"
75 
76 /* Imports */
77 extern z_stream incoming_stream;
78 extern z_stream outgoing_stream;
79 extern struct monitor *pmonitor;
80 extern Buffer loginmsg;
81 extern ServerOptions options;
82 
83 void
84 mm_log_handler(LogLevel level, const char *msg, void *ctx)
85 {
86 	Buffer log_msg;
87 	struct monitor *mon = (struct monitor *)ctx;
88 
89 	if (mon->m_log_sendfd == -1)
90 		fatal("%s: no log channel", __func__);
91 
92 	buffer_init(&log_msg);
93 	/*
94 	 * Placeholder for packet length. Will be filled in with the actual
95 	 * packet length once the packet has been constucted. This saves
96 	 * fragile math.
97 	 */
98 	buffer_put_int(&log_msg, 0);
99 
100 	buffer_put_int(&log_msg, level);
101 	buffer_put_cstring(&log_msg, msg);
102 	put_u32(buffer_ptr(&log_msg), buffer_len(&log_msg) - 4);
103 	if (atomicio(vwrite, mon->m_log_sendfd, buffer_ptr(&log_msg),
104 	    buffer_len(&log_msg)) != buffer_len(&log_msg))
105 		fatal("%s: write: %s", __func__, strerror(errno));
106 	buffer_free(&log_msg);
107 }
108 
109 int
110 mm_is_monitor(void)
111 {
112 	/*
113 	 * m_pid is only set in the privileged part, and
114 	 * points to the unprivileged child.
115 	 */
116 	return (pmonitor && pmonitor->m_pid > 0);
117 }
118 
119 void
120 mm_request_send(int sock, enum monitor_reqtype type, Buffer *m)
121 {
122 	u_int mlen = buffer_len(m);
123 	u_char buf[5];
124 
125 	debug3("%s entering: type %d", __func__, type);
126 
127 	put_u32(buf, mlen + 1);
128 	buf[4] = (u_char) type;		/* 1st byte of payload is mesg-type */
129 	if (atomicio(vwrite, sock, buf, sizeof(buf)) != sizeof(buf))
130 		fatal("%s: write: %s", __func__, strerror(errno));
131 	if (atomicio(vwrite, sock, buffer_ptr(m), mlen) != mlen)
132 		fatal("%s: write: %s", __func__, strerror(errno));
133 }
134 
135 void
136 mm_request_receive(int sock, Buffer *m)
137 {
138 	u_char buf[4];
139 	u_int msg_len;
140 
141 	debug3("%s entering", __func__);
142 
143 	if (atomicio(read, sock, buf, sizeof(buf)) != sizeof(buf)) {
144 		if (errno == EPIPE)
145 			cleanup_exit(255);
146 		fatal("%s: read: %s", __func__, strerror(errno));
147 	}
148 	msg_len = get_u32(buf);
149 	if (msg_len > 256 * 1024)
150 		fatal("%s: read: bad msg_len %d", __func__, msg_len);
151 	buffer_clear(m);
152 	buffer_append_space(m, msg_len);
153 	if (atomicio(read, sock, buffer_ptr(m), msg_len) != msg_len)
154 		fatal("%s: read: %s", __func__, strerror(errno));
155 }
156 
157 void
158 mm_request_receive_expect(int sock, enum monitor_reqtype type, Buffer *m)
159 {
160 	u_char rtype;
161 
162 	debug3("%s entering: type %d", __func__, type);
163 
164 	mm_request_receive(sock, m);
165 	rtype = buffer_get_char(m);
166 	if (rtype != type)
167 		fatal("%s: read: rtype %d != type %d", __func__,
168 		    rtype, type);
169 }
170 
171 #ifdef WITH_OPENSSL
172 DH *
173 mm_choose_dh(int min, int nbits, int max)
174 {
175 	BIGNUM *p, *g;
176 	int success = 0;
177 	Buffer m;
178 
179 	buffer_init(&m);
180 	buffer_put_int(&m, min);
181 	buffer_put_int(&m, nbits);
182 	buffer_put_int(&m, max);
183 
184 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_MODULI, &m);
185 
186 	debug3("%s: waiting for MONITOR_ANS_MODULI", __func__);
187 	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_MODULI, &m);
188 
189 	success = buffer_get_char(&m);
190 	if (success == 0)
191 		fatal("%s: MONITOR_ANS_MODULI failed", __func__);
192 
193 	if ((p = BN_new()) == NULL)
194 		fatal("%s: BN_new failed", __func__);
195 	if ((g = BN_new()) == NULL)
196 		fatal("%s: BN_new failed", __func__);
197 	buffer_get_bignum2(&m, p);
198 	buffer_get_bignum2(&m, g);
199 
200 	debug3("%s: remaining %d", __func__, buffer_len(&m));
201 	buffer_free(&m);
202 
203 	return (dh_new_group(g, p));
204 }
205 #endif
206 
207 int
208 mm_key_sign(struct sshkey *key, u_char **sigp, u_int *lenp,
209     const u_char *data, u_int datalen, const char *hostkey_alg)
210 {
211 	struct kex *kex = *pmonitor->m_pkex;
212 	Buffer m;
213 
214 	debug3("%s entering", __func__);
215 
216 	buffer_init(&m);
217 	buffer_put_int(&m, kex->host_key_index(key, 0, active_state));
218 	buffer_put_string(&m, data, datalen);
219 	buffer_put_cstring(&m, hostkey_alg);
220 
221 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_SIGN, &m);
222 
223 	debug3("%s: waiting for MONITOR_ANS_SIGN", __func__);
224 	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_SIGN, &m);
225 	*sigp  = buffer_get_string(&m, lenp);
226 	buffer_free(&m);
227 
228 	return (0);
229 }
230 
231 struct passwd *
232 mm_getpwnamallow(const char *username)
233 {
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 		for (i = 0; i < newopts->nx; i++) \
275 			newopts->x[i] = buffer_get_string(&m, NULL); \
276 	} while (0)
277 	/* See comment in servconf.h */
278 	COPY_MATCH_STRING_OPTS();
279 #undef M_CP_STROPT
280 #undef M_CP_STRARRAYOPT
281 
282 	copy_set_server_options(&options, newopts, 1);
283 	log_change_level(options.log_level);
284 	free(newopts);
285 
286 	buffer_free(&m);
287 
288 	return (pw);
289 }
290 
291 char *
292 mm_auth2_read_banner(void)
293 {
294 	Buffer m;
295 	char *banner;
296 
297 	debug3("%s entering", __func__);
298 
299 	buffer_init(&m);
300 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTH2_READ_BANNER, &m);
301 	buffer_clear(&m);
302 
303 	mm_request_receive_expect(pmonitor->m_recvfd,
304 	    MONITOR_ANS_AUTH2_READ_BANNER, &m);
305 	banner = buffer_get_string(&m, NULL);
306 	buffer_free(&m);
307 
308 	/* treat empty banner as missing banner */
309 	if (strlen(banner) == 0) {
310 		free(banner);
311 		banner = NULL;
312 	}
313 	return (banner);
314 }
315 
316 /* Inform the privileged process about service and style */
317 
318 void
319 mm_inform_authserv(char *service, char *style)
320 {
321 	Buffer m;
322 
323 	debug3("%s entering", __func__);
324 
325 	buffer_init(&m);
326 	buffer_put_cstring(&m, service);
327 	buffer_put_cstring(&m, style ? style : "");
328 
329 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHSERV, &m);
330 
331 	buffer_free(&m);
332 }
333 
334 /* Do the password authentication */
335 int
336 mm_auth_password(Authctxt *authctxt, char *password)
337 {
338 	Buffer m;
339 	int authenticated = 0;
340 
341 	debug3("%s entering", __func__);
342 
343 	buffer_init(&m);
344 	buffer_put_cstring(&m, password);
345 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHPASSWORD, &m);
346 
347 	debug3("%s: waiting for MONITOR_ANS_AUTHPASSWORD", __func__);
348 	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_AUTHPASSWORD, &m);
349 
350 	authenticated = buffer_get_int(&m);
351 
352 	buffer_free(&m);
353 
354 	debug3("%s: user %sauthenticated",
355 	    __func__, authenticated ? "" : "not ");
356 	return (authenticated);
357 }
358 
359 int
360 mm_user_key_allowed(struct passwd *pw, struct sshkey *key,
361     int pubkey_auth_attempt)
362 {
363 	return (mm_key_allowed(MM_USERKEY, NULL, NULL, key,
364 	    pubkey_auth_attempt));
365 }
366 
367 int
368 mm_hostbased_key_allowed(struct passwd *pw, const char *user, const char *host,
369     struct sshkey *key)
370 {
371 	return (mm_key_allowed(MM_HOSTKEY, user, host, key, 0));
372 }
373 
374 int
375 mm_key_allowed(enum mm_keytype type, const char *user, const char *host,
376     struct sshkey *key, int pubkey_auth_attempt)
377 {
378 	Buffer m;
379 	u_char *blob;
380 	u_int len;
381 	int allowed = 0, have_forced = 0;
382 
383 	debug3("%s entering", __func__);
384 
385 	/* Convert the key to a blob and the pass it over */
386 	if (!key_to_blob(key, &blob, &len))
387 		return (0);
388 
389 	buffer_init(&m);
390 	buffer_put_int(&m, type);
391 	buffer_put_cstring(&m, user ? user : "");
392 	buffer_put_cstring(&m, host ? host : "");
393 	buffer_put_string(&m, blob, len);
394 	buffer_put_int(&m, pubkey_auth_attempt);
395 	free(blob);
396 
397 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_KEYALLOWED, &m);
398 
399 	debug3("%s: waiting for MONITOR_ANS_KEYALLOWED", __func__);
400 	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_KEYALLOWED, &m);
401 
402 	allowed = buffer_get_int(&m);
403 
404 	/* fake forced command */
405 	auth_clear_options();
406 	have_forced = buffer_get_int(&m);
407 	forced_command = have_forced ? xstrdup("true") : NULL;
408 
409 	buffer_free(&m);
410 
411 	return (allowed);
412 }
413 
414 /*
415  * This key verify needs to send the key type along, because the
416  * privileged parent makes the decision if the key is allowed
417  * for authentication.
418  */
419 
420 int
421 mm_sshkey_verify(const struct sshkey *key, const u_char *sig, size_t siglen,
422     const u_char *data, size_t datalen, u_int compat)
423 {
424 	Buffer m;
425 	u_char *blob;
426 	u_int len;
427 	u_int encoded_ret = 0;
428 
429 	debug3("%s entering", __func__);
430 
431 	/* Convert the key to a blob and the pass it over */
432 	if (!key_to_blob(key, &blob, &len))
433 		return (0);
434 
435 	buffer_init(&m);
436 	buffer_put_string(&m, blob, len);
437 	buffer_put_string(&m, sig, siglen);
438 	buffer_put_string(&m, data, datalen);
439 	free(blob);
440 
441 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_KEYVERIFY, &m);
442 
443 	debug3("%s: waiting for MONITOR_ANS_KEYVERIFY", __func__);
444 	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_KEYVERIFY, &m);
445 
446 	encoded_ret = buffer_get_int(&m);
447 
448 	buffer_free(&m);
449 
450 	if (encoded_ret != 0)
451 		return SSH_ERR_SIGNATURE_INVALID;
452 	return 0;
453 }
454 
455 void
456 mm_send_keystate(struct monitor *monitor)
457 {
458 	struct ssh *ssh = active_state;		/* XXX */
459 	struct sshbuf *m;
460 	int r;
461 
462 	if ((m = sshbuf_new()) == NULL)
463 		fatal("%s: sshbuf_new failed", __func__);
464 	if ((r = ssh_packet_get_state(ssh, m)) != 0)
465 		fatal("%s: get_state failed: %s",
466 		    __func__, ssh_err(r));
467 	mm_request_send(monitor->m_recvfd, MONITOR_REQ_KEYEXPORT, m);
468 	debug3("%s: Finished sending state", __func__);
469 	sshbuf_free(m);
470 }
471 
472 int
473 mm_pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, size_t namebuflen)
474 {
475 	Buffer m;
476 	char *p, *msg;
477 	int success = 0, tmp1 = -1, tmp2 = -1;
478 
479 	/* Kludge: ensure there are fds free to receive the pty/tty */
480 	if ((tmp1 = dup(pmonitor->m_recvfd)) == -1 ||
481 	    (tmp2 = dup(pmonitor->m_recvfd)) == -1) {
482 		error("%s: cannot allocate fds for pty", __func__);
483 		if (tmp1 > 0)
484 			close(tmp1);
485 		if (tmp2 > 0)
486 			close(tmp2);
487 		return 0;
488 	}
489 	close(tmp1);
490 	close(tmp2);
491 
492 	buffer_init(&m);
493 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PTY, &m);
494 
495 	debug3("%s: waiting for MONITOR_ANS_PTY", __func__);
496 	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PTY, &m);
497 
498 	success = buffer_get_int(&m);
499 	if (success == 0) {
500 		debug3("%s: pty alloc failed", __func__);
501 		buffer_free(&m);
502 		return (0);
503 	}
504 	p = buffer_get_string(&m, NULL);
505 	msg = buffer_get_string(&m, NULL);
506 	buffer_free(&m);
507 
508 	strlcpy(namebuf, p, namebuflen); /* Possible truncation */
509 	free(p);
510 
511 	buffer_append(&loginmsg, msg, strlen(msg));
512 	free(msg);
513 
514 	if ((*ptyfd = mm_receive_fd(pmonitor->m_recvfd)) == -1 ||
515 	    (*ttyfd = mm_receive_fd(pmonitor->m_recvfd)) == -1)
516 		fatal("%s: receive fds failed", __func__);
517 
518 	/* Success */
519 	return (1);
520 }
521 
522 void
523 mm_session_pty_cleanup2(Session *s)
524 {
525 	Buffer m;
526 
527 	if (s->ttyfd == -1)
528 		return;
529 	buffer_init(&m);
530 	buffer_put_cstring(&m, s->tty);
531 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PTYCLEANUP, &m);
532 	buffer_free(&m);
533 
534 	/* closed dup'ed master */
535 	if (s->ptymaster != -1 && close(s->ptymaster) < 0)
536 		error("close(s->ptymaster/%d): %s",
537 		    s->ptymaster, strerror(errno));
538 
539 	/* unlink pty from session */
540 	s->ttyfd = -1;
541 }
542 
543 /* Request process termination */
544 
545 void
546 mm_terminate(void)
547 {
548 	Buffer m;
549 
550 	buffer_init(&m);
551 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_TERM, &m);
552 	buffer_free(&m);
553 }
554 
555 static void
556 mm_chall_setup(char **name, char **infotxt, u_int *numprompts,
557     char ***prompts, u_int **echo_on)
558 {
559 	*name = xstrdup("");
560 	*infotxt = xstrdup("");
561 	*numprompts = 1;
562 	*prompts = xcalloc(*numprompts, sizeof(char *));
563 	*echo_on = xcalloc(*numprompts, sizeof(u_int));
564 	(*echo_on)[0] = 0;
565 }
566 
567 int
568 mm_bsdauth_query(void *ctx, char **name, char **infotxt,
569    u_int *numprompts, char ***prompts, u_int **echo_on)
570 {
571 	Buffer m;
572 	u_int success;
573 	char *challenge;
574 
575 	debug3("%s: entering", __func__);
576 
577 	buffer_init(&m);
578 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_BSDAUTHQUERY, &m);
579 
580 	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_BSDAUTHQUERY,
581 	    &m);
582 	success = buffer_get_int(&m);
583 	if (success == 0) {
584 		debug3("%s: no challenge", __func__);
585 		buffer_free(&m);
586 		return (-1);
587 	}
588 
589 	/* Get the challenge, and format the response */
590 	challenge  = buffer_get_string(&m, NULL);
591 	buffer_free(&m);
592 
593 	mm_chall_setup(name, infotxt, numprompts, prompts, echo_on);
594 	(*prompts)[0] = challenge;
595 
596 	debug3("%s: received challenge: %s", __func__, challenge);
597 
598 	return (0);
599 }
600 
601 int
602 mm_bsdauth_respond(void *ctx, u_int numresponses, char **responses)
603 {
604 	Buffer m;
605 	int authok;
606 
607 	debug3("%s: entering", __func__);
608 	if (numresponses != 1)
609 		return (-1);
610 
611 	buffer_init(&m);
612 	buffer_put_cstring(&m, responses[0]);
613 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_BSDAUTHRESPOND, &m);
614 
615 	mm_request_receive_expect(pmonitor->m_recvfd,
616 	    MONITOR_ANS_BSDAUTHRESPOND, &m);
617 
618 	authok = buffer_get_int(&m);
619 	buffer_free(&m);
620 
621 	return ((authok == 0) ? -1 : 0);
622 }
623 
624 #ifdef GSSAPI
625 OM_uint32
626 mm_ssh_gssapi_server_ctx(Gssctxt **ctx, gss_OID goid)
627 {
628 	Buffer m;
629 	OM_uint32 major;
630 
631 	/* Client doesn't get to see the context */
632 	*ctx = NULL;
633 
634 	buffer_init(&m);
635 	buffer_put_string(&m, goid->elements, goid->length);
636 
637 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSSETUP, &m);
638 	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSSETUP, &m);
639 
640 	major = buffer_get_int(&m);
641 
642 	buffer_free(&m);
643 	return (major);
644 }
645 
646 OM_uint32
647 mm_ssh_gssapi_accept_ctx(Gssctxt *ctx, gss_buffer_desc *in,
648     gss_buffer_desc *out, OM_uint32 *flags)
649 {
650 	Buffer m;
651 	OM_uint32 major;
652 	u_int len;
653 
654 	buffer_init(&m);
655 	buffer_put_string(&m, in->value, in->length);
656 
657 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSSTEP, &m);
658 	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSSTEP, &m);
659 
660 	major = buffer_get_int(&m);
661 	out->value = buffer_get_string(&m, &len);
662 	out->length = len;
663 	if (flags)
664 		*flags = buffer_get_int(&m);
665 
666 	buffer_free(&m);
667 
668 	return (major);
669 }
670 
671 OM_uint32
672 mm_ssh_gssapi_checkmic(Gssctxt *ctx, gss_buffer_t gssbuf, gss_buffer_t gssmic)
673 {
674 	Buffer m;
675 	OM_uint32 major;
676 
677 	buffer_init(&m);
678 	buffer_put_string(&m, gssbuf->value, gssbuf->length);
679 	buffer_put_string(&m, gssmic->value, gssmic->length);
680 
681 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSCHECKMIC, &m);
682 	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSCHECKMIC,
683 	    &m);
684 
685 	major = buffer_get_int(&m);
686 	buffer_free(&m);
687 	return(major);
688 }
689 
690 int
691 mm_ssh_gssapi_userok(char *user)
692 {
693 	Buffer m;
694 	int authenticated = 0;
695 
696 	buffer_init(&m);
697 
698 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSUSEROK, &m);
699 	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSUSEROK,
700 				  &m);
701 
702 	authenticated = buffer_get_int(&m);
703 
704 	buffer_free(&m);
705 	debug3("%s: user %sauthenticated",__func__, authenticated ? "" : "not ");
706 	return (authenticated);
707 }
708 #endif /* GSSAPI */
709 
710