xref: /openbsd/usr.bin/ssh/monitor_wrap.c (revision 998de4a5)
1 /* $OpenBSD: monitor_wrap.c,v 1.89 2016/08/13 17:47:41 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(Key *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 	free(newopts);
284 
285 	buffer_free(&m);
286 
287 	return (pw);
288 }
289 
290 char *
291 mm_auth2_read_banner(void)
292 {
293 	Buffer m;
294 	char *banner;
295 
296 	debug3("%s entering", __func__);
297 
298 	buffer_init(&m);
299 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTH2_READ_BANNER, &m);
300 	buffer_clear(&m);
301 
302 	mm_request_receive_expect(pmonitor->m_recvfd,
303 	    MONITOR_ANS_AUTH2_READ_BANNER, &m);
304 	banner = buffer_get_string(&m, NULL);
305 	buffer_free(&m);
306 
307 	/* treat empty banner as missing banner */
308 	if (strlen(banner) == 0) {
309 		free(banner);
310 		banner = NULL;
311 	}
312 	return (banner);
313 }
314 
315 /* Inform the privileged process about service and style */
316 
317 void
318 mm_inform_authserv(char *service, char *style)
319 {
320 	Buffer m;
321 
322 	debug3("%s entering", __func__);
323 
324 	buffer_init(&m);
325 	buffer_put_cstring(&m, service);
326 	buffer_put_cstring(&m, style ? style : "");
327 
328 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHSERV, &m);
329 
330 	buffer_free(&m);
331 }
332 
333 /* Do the password authentication */
334 int
335 mm_auth_password(Authctxt *authctxt, char *password)
336 {
337 	Buffer m;
338 	int authenticated = 0;
339 
340 	debug3("%s entering", __func__);
341 
342 	buffer_init(&m);
343 	buffer_put_cstring(&m, password);
344 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUTHPASSWORD, &m);
345 
346 	debug3("%s: waiting for MONITOR_ANS_AUTHPASSWORD", __func__);
347 	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_AUTHPASSWORD, &m);
348 
349 	authenticated = buffer_get_int(&m);
350 
351 	buffer_free(&m);
352 
353 	debug3("%s: user %sauthenticated",
354 	    __func__, authenticated ? "" : "not ");
355 	return (authenticated);
356 }
357 
358 int
359 mm_user_key_allowed(struct passwd *pw, Key *key, int pubkey_auth_attempt)
360 {
361 	return (mm_key_allowed(MM_USERKEY, NULL, NULL, key,
362 	    pubkey_auth_attempt));
363 }
364 
365 int
366 mm_hostbased_key_allowed(struct passwd *pw, const char *user, const char *host,
367     Key *key)
368 {
369 	return (mm_key_allowed(MM_HOSTKEY, user, host, key, 0));
370 }
371 
372 int
373 mm_key_allowed(enum mm_keytype type, const char *user, const char *host,
374     Key *key, int pubkey_auth_attempt)
375 {
376 	Buffer m;
377 	u_char *blob;
378 	u_int len;
379 	int allowed = 0, have_forced = 0;
380 
381 	debug3("%s entering", __func__);
382 
383 	/* Convert the key to a blob and the pass it over */
384 	if (!key_to_blob(key, &blob, &len))
385 		return (0);
386 
387 	buffer_init(&m);
388 	buffer_put_int(&m, type);
389 	buffer_put_cstring(&m, user ? user : "");
390 	buffer_put_cstring(&m, host ? host : "");
391 	buffer_put_string(&m, blob, len);
392 	buffer_put_int(&m, pubkey_auth_attempt);
393 	free(blob);
394 
395 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_KEYALLOWED, &m);
396 
397 	debug3("%s: waiting for MONITOR_ANS_KEYALLOWED", __func__);
398 	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_KEYALLOWED, &m);
399 
400 	allowed = buffer_get_int(&m);
401 
402 	/* fake forced command */
403 	auth_clear_options();
404 	have_forced = buffer_get_int(&m);
405 	forced_command = have_forced ? xstrdup("true") : NULL;
406 
407 	buffer_free(&m);
408 
409 	return (allowed);
410 }
411 
412 /*
413  * This key verify needs to send the key type along, because the
414  * privileged parent makes the decision if the key is allowed
415  * for authentication.
416  */
417 
418 int
419 mm_key_verify(Key *key, u_char *sig, u_int siglen, u_char *data, u_int datalen)
420 {
421 	Buffer m;
422 	u_char *blob;
423 	u_int len;
424 	int verified = 0;
425 
426 	debug3("%s entering", __func__);
427 
428 	/* Convert the key to a blob and the pass it over */
429 	if (!key_to_blob(key, &blob, &len))
430 		return (0);
431 
432 	buffer_init(&m);
433 	buffer_put_string(&m, blob, len);
434 	buffer_put_string(&m, sig, siglen);
435 	buffer_put_string(&m, data, datalen);
436 	free(blob);
437 
438 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_KEYVERIFY, &m);
439 
440 	debug3("%s: waiting for MONITOR_ANS_KEYVERIFY", __func__);
441 	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_KEYVERIFY, &m);
442 
443 	verified = buffer_get_int(&m);
444 
445 	buffer_free(&m);
446 
447 	return (verified);
448 }
449 
450 void
451 mm_send_keystate(struct monitor *monitor)
452 {
453 	struct ssh *ssh = active_state;		/* XXX */
454 	struct sshbuf *m;
455 	int r;
456 
457 	if ((m = sshbuf_new()) == NULL)
458 		fatal("%s: sshbuf_new failed", __func__);
459 	if ((r = ssh_packet_get_state(ssh, m)) != 0)
460 		fatal("%s: get_state failed: %s",
461 		    __func__, ssh_err(r));
462 	mm_request_send(monitor->m_recvfd, MONITOR_REQ_KEYEXPORT, m);
463 	debug3("%s: Finished sending state", __func__);
464 	sshbuf_free(m);
465 }
466 
467 int
468 mm_pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, size_t namebuflen)
469 {
470 	Buffer m;
471 	char *p, *msg;
472 	int success = 0, tmp1 = -1, tmp2 = -1;
473 
474 	/* Kludge: ensure there are fds free to receive the pty/tty */
475 	if ((tmp1 = dup(pmonitor->m_recvfd)) == -1 ||
476 	    (tmp2 = dup(pmonitor->m_recvfd)) == -1) {
477 		error("%s: cannot allocate fds for pty", __func__);
478 		if (tmp1 > 0)
479 			close(tmp1);
480 		if (tmp2 > 0)
481 			close(tmp2);
482 		return 0;
483 	}
484 	close(tmp1);
485 	close(tmp2);
486 
487 	buffer_init(&m);
488 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PTY, &m);
489 
490 	debug3("%s: waiting for MONITOR_ANS_PTY", __func__);
491 	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PTY, &m);
492 
493 	success = buffer_get_int(&m);
494 	if (success == 0) {
495 		debug3("%s: pty alloc failed", __func__);
496 		buffer_free(&m);
497 		return (0);
498 	}
499 	p = buffer_get_string(&m, NULL);
500 	msg = buffer_get_string(&m, NULL);
501 	buffer_free(&m);
502 
503 	strlcpy(namebuf, p, namebuflen); /* Possible truncation */
504 	free(p);
505 
506 	buffer_append(&loginmsg, msg, strlen(msg));
507 	free(msg);
508 
509 	if ((*ptyfd = mm_receive_fd(pmonitor->m_recvfd)) == -1 ||
510 	    (*ttyfd = mm_receive_fd(pmonitor->m_recvfd)) == -1)
511 		fatal("%s: receive fds failed", __func__);
512 
513 	/* Success */
514 	return (1);
515 }
516 
517 void
518 mm_session_pty_cleanup2(Session *s)
519 {
520 	Buffer m;
521 
522 	if (s->ttyfd == -1)
523 		return;
524 	buffer_init(&m);
525 	buffer_put_cstring(&m, s->tty);
526 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PTYCLEANUP, &m);
527 	buffer_free(&m);
528 
529 	/* closed dup'ed master */
530 	if (s->ptymaster != -1 && close(s->ptymaster) < 0)
531 		error("close(s->ptymaster/%d): %s",
532 		    s->ptymaster, strerror(errno));
533 
534 	/* unlink pty from session */
535 	s->ttyfd = -1;
536 }
537 
538 /* Request process termination */
539 
540 void
541 mm_terminate(void)
542 {
543 	Buffer m;
544 
545 	buffer_init(&m);
546 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_TERM, &m);
547 	buffer_free(&m);
548 }
549 
550 static void
551 mm_chall_setup(char **name, char **infotxt, u_int *numprompts,
552     char ***prompts, u_int **echo_on)
553 {
554 	*name = xstrdup("");
555 	*infotxt = xstrdup("");
556 	*numprompts = 1;
557 	*prompts = xcalloc(*numprompts, sizeof(char *));
558 	*echo_on = xcalloc(*numprompts, sizeof(u_int));
559 	(*echo_on)[0] = 0;
560 }
561 
562 int
563 mm_bsdauth_query(void *ctx, char **name, char **infotxt,
564    u_int *numprompts, char ***prompts, u_int **echo_on)
565 {
566 	Buffer m;
567 	u_int success;
568 	char *challenge;
569 
570 	debug3("%s: entering", __func__);
571 
572 	buffer_init(&m);
573 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_BSDAUTHQUERY, &m);
574 
575 	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_BSDAUTHQUERY,
576 	    &m);
577 	success = buffer_get_int(&m);
578 	if (success == 0) {
579 		debug3("%s: no challenge", __func__);
580 		buffer_free(&m);
581 		return (-1);
582 	}
583 
584 	/* Get the challenge, and format the response */
585 	challenge  = buffer_get_string(&m, NULL);
586 	buffer_free(&m);
587 
588 	mm_chall_setup(name, infotxt, numprompts, prompts, echo_on);
589 	(*prompts)[0] = challenge;
590 
591 	debug3("%s: received challenge: %s", __func__, challenge);
592 
593 	return (0);
594 }
595 
596 int
597 mm_bsdauth_respond(void *ctx, u_int numresponses, char **responses)
598 {
599 	Buffer m;
600 	int authok;
601 
602 	debug3("%s: entering", __func__);
603 	if (numresponses != 1)
604 		return (-1);
605 
606 	buffer_init(&m);
607 	buffer_put_cstring(&m, responses[0]);
608 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_BSDAUTHRESPOND, &m);
609 
610 	mm_request_receive_expect(pmonitor->m_recvfd,
611 	    MONITOR_ANS_BSDAUTHRESPOND, &m);
612 
613 	authok = buffer_get_int(&m);
614 	buffer_free(&m);
615 
616 	return ((authok == 0) ? -1 : 0);
617 }
618 
619 #ifdef GSSAPI
620 OM_uint32
621 mm_ssh_gssapi_server_ctx(Gssctxt **ctx, gss_OID goid)
622 {
623 	Buffer m;
624 	OM_uint32 major;
625 
626 	/* Client doesn't get to see the context */
627 	*ctx = NULL;
628 
629 	buffer_init(&m);
630 	buffer_put_string(&m, goid->elements, goid->length);
631 
632 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSSETUP, &m);
633 	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSSETUP, &m);
634 
635 	major = buffer_get_int(&m);
636 
637 	buffer_free(&m);
638 	return (major);
639 }
640 
641 OM_uint32
642 mm_ssh_gssapi_accept_ctx(Gssctxt *ctx, gss_buffer_desc *in,
643     gss_buffer_desc *out, OM_uint32 *flags)
644 {
645 	Buffer m;
646 	OM_uint32 major;
647 	u_int len;
648 
649 	buffer_init(&m);
650 	buffer_put_string(&m, in->value, in->length);
651 
652 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSSTEP, &m);
653 	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSSTEP, &m);
654 
655 	major = buffer_get_int(&m);
656 	out->value = buffer_get_string(&m, &len);
657 	out->length = len;
658 	if (flags)
659 		*flags = buffer_get_int(&m);
660 
661 	buffer_free(&m);
662 
663 	return (major);
664 }
665 
666 OM_uint32
667 mm_ssh_gssapi_checkmic(Gssctxt *ctx, gss_buffer_t gssbuf, gss_buffer_t gssmic)
668 {
669 	Buffer m;
670 	OM_uint32 major;
671 
672 	buffer_init(&m);
673 	buffer_put_string(&m, gssbuf->value, gssbuf->length);
674 	buffer_put_string(&m, gssmic->value, gssmic->length);
675 
676 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSCHECKMIC, &m);
677 	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSCHECKMIC,
678 	    &m);
679 
680 	major = buffer_get_int(&m);
681 	buffer_free(&m);
682 	return(major);
683 }
684 
685 int
686 mm_ssh_gssapi_userok(char *user)
687 {
688 	Buffer m;
689 	int authenticated = 0;
690 
691 	buffer_init(&m);
692 
693 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSUSEROK, &m);
694 	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSUSEROK,
695 				  &m);
696 
697 	authenticated = buffer_get_int(&m);
698 
699 	buffer_free(&m);
700 	debug3("%s: user %sauthenticated",__func__, authenticated ? "" : "not ");
701 	return (authenticated);
702 }
703 #endif /* GSSAPI */
704 
705