2 * Copyright 2002 Niels Provos <provos@citi.umich.edu>
3 * Copyright 2002 Markus Friedl <markus@openbsd.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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.
28 RCSID("$OpenBSD: monitor.c,v 1.53 2003/11/18 10:53:07 djm Exp $");
30 #include <openssl/dh.h>
42 #include "auth-options.h"
51 #include "monitor_mm.h"
52 #include "monitor_wrap.h"
53 #include "monitor_fdpass.h"
64 static Gssctxt *gsscontext = NULL;
68 extern ServerOptions options;
69 extern u_int utmp_len;
70 extern Newkeys *current_keys[];
71 extern z_stream incoming_stream;
72 extern z_stream outgoing_stream;
73 extern u_char session_id[];
74 extern Buffer input, output;
75 extern Buffer auth_debug;
76 extern int auth_debug_init;
78 /* State exported from the child */
101 /* Functions on the monitor that answer unprivileged requests */
103 int mm_answer_moduli(int, Buffer *);
104 int mm_answer_sign(int, Buffer *);
105 int mm_answer_pwnamallow(int, Buffer *);
106 int mm_answer_auth2_read_banner(int, Buffer *);
107 int mm_answer_authserv(int, Buffer *);
108 int mm_answer_authpassword(int, Buffer *);
109 int mm_answer_bsdauthquery(int, Buffer *);
110 int mm_answer_bsdauthrespond(int, Buffer *);
111 int mm_answer_skeyquery(int, Buffer *);
112 int mm_answer_skeyrespond(int, Buffer *);
113 int mm_answer_keyallowed(int, Buffer *);
114 int mm_answer_keyverify(int, Buffer *);
115 int mm_answer_pty(int, Buffer *);
116 int mm_answer_pty_cleanup(int, Buffer *);
117 int mm_answer_term(int, Buffer *);
118 int mm_answer_rsa_keyallowed(int, Buffer *);
119 int mm_answer_rsa_challenge(int, Buffer *);
120 int mm_answer_rsa_response(int, Buffer *);
121 int mm_answer_sesskey(int, Buffer *);
122 int mm_answer_sessid(int, Buffer *);
125 int mm_answer_pam_start(int, Buffer *);
126 int mm_answer_pam_account(int, Buffer *);
127 int mm_answer_pam_init_ctx(int, Buffer *);
128 int mm_answer_pam_query(int, Buffer *);
129 int mm_answer_pam_respond(int, Buffer *);
130 int mm_answer_pam_free_ctx(int, Buffer *);
134 int mm_answer_gss_setup_ctx(int, Buffer *);
135 int mm_answer_gss_accept_ctx(int, Buffer *);
136 int mm_answer_gss_userok(int, Buffer *);
137 int mm_answer_gss_checkmic(int, Buffer *);
140 static Authctxt *authctxt;
141 static BIGNUM *ssh1_challenge = NULL; /* used for ssh1 rsa auth */
143 /* local state for key verify */
144 static u_char *key_blob = NULL;
145 static u_int key_bloblen = 0;
146 static int key_blobtype = MM_NOKEY;
147 static char *hostbased_cuser = NULL;
148 static char *hostbased_chost = NULL;
149 static char *auth_method = "unknown";
150 static u_int session_id2_len = 0;
151 static u_char *session_id2 = NULL;
152 static pid_t monitor_child_pid;
155 enum monitor_reqtype type;
157 int (*f)(int, Buffer *);
160 #define MON_ISAUTH 0x0004 /* Required for Authentication */
161 #define MON_AUTHDECIDE 0x0008 /* Decides Authentication */
162 #define MON_ONCE 0x0010 /* Disable after calling */
164 #define MON_AUTH (MON_ISAUTH|MON_AUTHDECIDE)
166 #define MON_PERMIT 0x1000 /* Request is permitted */
168 struct mon_table mon_dispatch_proto20[] = {
169 {MONITOR_REQ_MODULI, MON_ONCE, mm_answer_moduli},
170 {MONITOR_REQ_SIGN, MON_ONCE, mm_answer_sign},
171 {MONITOR_REQ_PWNAM, MON_ONCE, mm_answer_pwnamallow},
172 {MONITOR_REQ_AUTHSERV, MON_ONCE, mm_answer_authserv},
173 {MONITOR_REQ_AUTH2_READ_BANNER, MON_ONCE, mm_answer_auth2_read_banner},
174 {MONITOR_REQ_AUTHPASSWORD, MON_AUTH, mm_answer_authpassword},
176 {MONITOR_REQ_PAM_START, MON_ONCE, mm_answer_pam_start},
177 {MONITOR_REQ_PAM_ACCOUNT, 0, mm_answer_pam_account},
178 {MONITOR_REQ_PAM_INIT_CTX, MON_ISAUTH, mm_answer_pam_init_ctx},
179 {MONITOR_REQ_PAM_QUERY, MON_ISAUTH, mm_answer_pam_query},
180 {MONITOR_REQ_PAM_RESPOND, MON_ISAUTH, mm_answer_pam_respond},
181 {MONITOR_REQ_PAM_FREE_CTX, MON_ONCE|MON_AUTHDECIDE, mm_answer_pam_free_ctx},
184 {MONITOR_REQ_BSDAUTHQUERY, MON_ISAUTH, mm_answer_bsdauthquery},
185 {MONITOR_REQ_BSDAUTHRESPOND, MON_AUTH,mm_answer_bsdauthrespond},
188 {MONITOR_REQ_SKEYQUERY, MON_ISAUTH, mm_answer_skeyquery},
189 {MONITOR_REQ_SKEYRESPOND, MON_AUTH, mm_answer_skeyrespond},
191 {MONITOR_REQ_KEYALLOWED, MON_ISAUTH, mm_answer_keyallowed},
192 {MONITOR_REQ_KEYVERIFY, MON_AUTH, mm_answer_keyverify},
194 {MONITOR_REQ_GSSSETUP, MON_ISAUTH, mm_answer_gss_setup_ctx},
195 {MONITOR_REQ_GSSSTEP, MON_ISAUTH, mm_answer_gss_accept_ctx},
196 {MONITOR_REQ_GSSUSEROK, MON_AUTH, mm_answer_gss_userok},
197 {MONITOR_REQ_GSSCHECKMIC, MON_ISAUTH, mm_answer_gss_checkmic},
202 struct mon_table mon_dispatch_postauth20[] = {
203 {MONITOR_REQ_MODULI, 0, mm_answer_moduli},
204 {MONITOR_REQ_SIGN, 0, mm_answer_sign},
205 {MONITOR_REQ_PTY, 0, mm_answer_pty},
206 {MONITOR_REQ_PTYCLEANUP, 0, mm_answer_pty_cleanup},
207 {MONITOR_REQ_TERM, 0, mm_answer_term},
211 struct mon_table mon_dispatch_proto15[] = {
212 {MONITOR_REQ_PWNAM, MON_ONCE, mm_answer_pwnamallow},
213 {MONITOR_REQ_SESSKEY, MON_ONCE, mm_answer_sesskey},
214 {MONITOR_REQ_SESSID, MON_ONCE, mm_answer_sessid},
215 {MONITOR_REQ_AUTHPASSWORD, MON_AUTH, mm_answer_authpassword},
216 {MONITOR_REQ_RSAKEYALLOWED, MON_ISAUTH, mm_answer_rsa_keyallowed},
217 {MONITOR_REQ_KEYALLOWED, MON_ISAUTH, mm_answer_keyallowed},
218 {MONITOR_REQ_RSACHALLENGE, MON_ONCE, mm_answer_rsa_challenge},
219 {MONITOR_REQ_RSARESPONSE, MON_ONCE|MON_AUTHDECIDE, mm_answer_rsa_response},
221 {MONITOR_REQ_BSDAUTHQUERY, MON_ISAUTH, mm_answer_bsdauthquery},
222 {MONITOR_REQ_BSDAUTHRESPOND, MON_AUTH,mm_answer_bsdauthrespond},
225 {MONITOR_REQ_SKEYQUERY, MON_ISAUTH, mm_answer_skeyquery},
226 {MONITOR_REQ_SKEYRESPOND, MON_AUTH, mm_answer_skeyrespond},
229 {MONITOR_REQ_PAM_START, MON_ONCE, mm_answer_pam_start},
230 {MONITOR_REQ_PAM_ACCOUNT, 0, mm_answer_pam_account},
231 {MONITOR_REQ_PAM_INIT_CTX, MON_ISAUTH, mm_answer_pam_init_ctx},
232 {MONITOR_REQ_PAM_QUERY, MON_ISAUTH, mm_answer_pam_query},
233 {MONITOR_REQ_PAM_RESPOND, MON_ISAUTH, mm_answer_pam_respond},
234 {MONITOR_REQ_PAM_FREE_CTX, MON_ONCE|MON_AUTHDECIDE, mm_answer_pam_free_ctx},
239 struct mon_table mon_dispatch_postauth15[] = {
240 {MONITOR_REQ_PTY, MON_ONCE, mm_answer_pty},
241 {MONITOR_REQ_PTYCLEANUP, MON_ONCE, mm_answer_pty_cleanup},
242 {MONITOR_REQ_TERM, 0, mm_answer_term},
246 struct mon_table *mon_dispatch;
248 /* Specifies if a certain message is allowed at the moment */
251 monitor_permit(struct mon_table *ent, enum monitor_reqtype type, int permit)
253 while (ent->f != NULL) {
254 if (ent->type == type) {
255 ent->flags &= ~MON_PERMIT;
256 ent->flags |= permit ? MON_PERMIT : 0;
264 monitor_permit_authentications(int permit)
266 struct mon_table *ent = mon_dispatch;
268 while (ent->f != NULL) {
269 if (ent->flags & MON_AUTH) {
270 ent->flags &= ~MON_PERMIT;
271 ent->flags |= permit ? MON_PERMIT : 0;
278 monitor_child_preauth(Authctxt *_authctxt, struct monitor *pmonitor)
280 struct mon_table *ent;
281 int authenticated = 0;
283 debug3("preauth child monitor started");
285 authctxt = _authctxt;
286 memset(authctxt, 0, sizeof(*authctxt));
289 mon_dispatch = mon_dispatch_proto20;
291 /* Permit requests for moduli and signatures */
292 monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1);
293 monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1);
295 mon_dispatch = mon_dispatch_proto15;
297 monitor_permit(mon_dispatch, MONITOR_REQ_SESSKEY, 1);
300 /* The first few requests do not require asynchronous access */
301 while (!authenticated) {
302 authenticated = monitor_read(pmonitor, mon_dispatch, &ent);
304 if (!(ent->flags & MON_AUTHDECIDE))
305 fatal("%s: unexpected authentication from %d",
306 __func__, ent->type);
307 if (authctxt->pw->pw_uid == 0 &&
308 !auth_root_allowed(auth_method))
311 /* PAM needs to perform account checks after auth */
312 if (options.use_pam && authenticated) {
316 mm_request_receive_expect(pmonitor->m_sendfd,
317 MONITOR_REQ_PAM_ACCOUNT, &m);
318 authenticated = mm_answer_pam_account(pmonitor->m_sendfd, &m);
324 if (ent->flags & MON_AUTHDECIDE) {
325 auth_log(authctxt, authenticated, auth_method,
326 compat20 ? " ssh2" : "");
328 authctxt->failures++;
332 if (!authctxt->valid)
333 fatal("%s: authenticated invalid user", __func__);
335 debug("%s: %s has been authenticated by privileged process",
336 __func__, authctxt->user);
338 mm_get_keystate(pmonitor);
342 monitor_set_child_handler(pid_t pid)
344 monitor_child_pid = pid;
348 monitor_child_handler(int signal)
350 kill(monitor_child_pid, signal);
354 monitor_child_postauth(struct monitor *pmonitor)
356 monitor_set_child_handler(pmonitor->m_pid);
357 signal(SIGHUP, &monitor_child_handler);
358 signal(SIGTERM, &monitor_child_handler);
361 mon_dispatch = mon_dispatch_postauth20;
363 /* Permit requests for moduli and signatures */
364 monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1);
365 monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1);
366 monitor_permit(mon_dispatch, MONITOR_REQ_TERM, 1);
368 mon_dispatch = mon_dispatch_postauth15;
369 monitor_permit(mon_dispatch, MONITOR_REQ_TERM, 1);
372 monitor_permit(mon_dispatch, MONITOR_REQ_PTY, 1);
373 monitor_permit(mon_dispatch, MONITOR_REQ_PTYCLEANUP, 1);
377 monitor_read(pmonitor, mon_dispatch, NULL);
381 monitor_sync(struct monitor *pmonitor)
383 if (options.compression) {
384 /* The member allocation is not visible, so sync it */
385 mm_share_sync(&pmonitor->m_zlib, &pmonitor->m_zback);
390 monitor_read(struct monitor *pmonitor, struct mon_table *ent,
391 struct mon_table **pent)
399 mm_request_receive(pmonitor->m_sendfd, &m);
400 type = buffer_get_char(&m);
402 debug3("%s: checking request %d", __func__, type);
404 while (ent->f != NULL) {
405 if (ent->type == type)
410 if (ent->f != NULL) {
411 if (!(ent->flags & MON_PERMIT))
412 fatal("%s: unpermitted request %d", __func__,
414 ret = (*ent->f)(pmonitor->m_sendfd, &m);
417 /* The child may use this request only once, disable it */
418 if (ent->flags & MON_ONCE) {
419 debug2("%s: %d used once, disabling now", __func__,
421 ent->flags &= ~MON_PERMIT;
430 fatal("%s: unsupported request: %d", __func__, type);
436 /* allowed key state */
438 monitor_allowed_key(u_char *blob, u_int bloblen)
440 /* make sure key is allowed */
441 if (key_blob == NULL || key_bloblen != bloblen ||
442 memcmp(key_blob, blob, key_bloblen))
448 monitor_reset_key_state(void)
451 if (key_blob != NULL)
453 if (hostbased_cuser != NULL)
454 xfree(hostbased_cuser);
455 if (hostbased_chost != NULL)
456 xfree(hostbased_chost);
459 key_blobtype = MM_NOKEY;
460 hostbased_cuser = NULL;
461 hostbased_chost = NULL;
465 mm_answer_moduli(int socket, Buffer *m)
470 min = buffer_get_int(m);
471 want = buffer_get_int(m);
472 max = buffer_get_int(m);
474 debug3("%s: got parameters: %d %d %d",
475 __func__, min, want, max);
476 /* We need to check here, too, in case the child got corrupted */
477 if (max < min || want < min || max < want)
478 fatal("%s: bad parameters: %d %d %d",
479 __func__, min, want, max);
483 dh = choose_dh(min, want, max);
485 buffer_put_char(m, 0);
488 /* Send first bignum */
489 buffer_put_char(m, 1);
490 buffer_put_bignum2(m, dh->p);
491 buffer_put_bignum2(m, dh->g);
495 mm_request_send(socket, MONITOR_ANS_MODULI, m);
500 mm_answer_sign(int socket, Buffer *m)
505 u_int siglen, datlen;
508 debug3("%s", __func__);
510 keyid = buffer_get_int(m);
511 p = buffer_get_string(m, &datlen);
514 fatal("%s: data length incorrect: %u", __func__, datlen);
516 /* save session id, it will be passed on the first call */
517 if (session_id2_len == 0) {
518 session_id2_len = datlen;
519 session_id2 = xmalloc(session_id2_len);
520 memcpy(session_id2, p, session_id2_len);
523 if ((key = get_hostkey_by_index(keyid)) == NULL)
524 fatal("%s: no hostkey from index %d", __func__, keyid);
525 if (key_sign(key, &signature, &siglen, p, datlen) < 0)
526 fatal("%s: key_sign failed", __func__);
528 debug3("%s: signature %p(%u)", __func__, signature, siglen);
531 buffer_put_string(m, signature, siglen);
536 mm_request_send(socket, MONITOR_ANS_SIGN, m);
538 /* Turn on permissions for getpwnam */
539 monitor_permit(mon_dispatch, MONITOR_REQ_PWNAM, 1);
544 /* Retrieves the password entry and also checks if the user is permitted */
547 mm_answer_pwnamallow(int socket, Buffer *m)
550 struct passwd *pwent;
553 debug3("%s", __func__);
555 if (authctxt->attempt++ != 0)
556 fatal("%s: multiple attempts for getpwnam", __func__);
558 login = buffer_get_string(m, NULL);
560 pwent = getpwnamallow(login);
562 authctxt->user = xstrdup(login);
563 setproctitle("%s [priv]", pwent ? login : "unknown");
569 buffer_put_char(m, 0);
570 authctxt->pw = fakepw();
575 authctxt->pw = pwent;
578 buffer_put_char(m, 1);
579 buffer_put_string(m, pwent, sizeof(struct passwd));
580 buffer_put_cstring(m, pwent->pw_name);
581 buffer_put_cstring(m, "*");
582 buffer_put_cstring(m, pwent->pw_gecos);
583 #ifdef HAVE_PW_CLASS_IN_PASSWD
584 buffer_put_cstring(m, pwent->pw_class);
586 buffer_put_cstring(m, pwent->pw_dir);
587 buffer_put_cstring(m, pwent->pw_shell);
590 debug3("%s: sending MONITOR_ANS_PWNAM: %d", __func__, allowed);
591 mm_request_send(socket, MONITOR_ANS_PWNAM, m);
593 /* For SSHv1 allow authentication now */
595 monitor_permit_authentications(1);
597 /* Allow service/style information on the auth context */
598 monitor_permit(mon_dispatch, MONITOR_REQ_AUTHSERV, 1);
599 monitor_permit(mon_dispatch, MONITOR_REQ_AUTH2_READ_BANNER, 1);
604 monitor_permit(mon_dispatch, MONITOR_REQ_PAM_START, 1);
610 int mm_answer_auth2_read_banner(int socket, Buffer *m)
615 banner = auth2_read_banner();
616 buffer_put_cstring(m, banner != NULL ? banner : "");
617 mm_request_send(socket, MONITOR_ANS_AUTH2_READ_BANNER, m);
626 mm_answer_authserv(int socket, Buffer *m)
628 monitor_permit_authentications(1);
630 authctxt->service = buffer_get_string(m, NULL);
631 authctxt->style = buffer_get_string(m, NULL);
632 debug3("%s: service=%s, style=%s",
633 __func__, authctxt->service, authctxt->style);
635 if (strlen(authctxt->style) == 0) {
636 xfree(authctxt->style);
637 authctxt->style = NULL;
644 mm_answer_authpassword(int socket, Buffer *m)
646 static int call_count;
651 passwd = buffer_get_string(m, &plen);
652 /* Only authenticate if the context is valid */
653 authenticated = options.password_authentication &&
654 auth_password(authctxt, passwd);
655 memset(passwd, 0, strlen(passwd));
659 buffer_put_int(m, authenticated);
661 debug3("%s: sending result %d", __func__, authenticated);
662 mm_request_send(socket, MONITOR_ANS_AUTHPASSWORD, m);
665 if (plen == 0 && call_count == 1)
666 auth_method = "none";
668 auth_method = "password";
670 /* Causes monitor loop to terminate if authenticated */
671 return (authenticated);
676 mm_answer_bsdauthquery(int socket, Buffer *m)
678 char *name, *infotxt;
684 success = bsdauth_query(authctxt, &name, &infotxt, &numprompts,
685 &prompts, &echo_on) < 0 ? 0 : 1;
688 buffer_put_int(m, success);
690 buffer_put_cstring(m, prompts[0]);
692 debug3("%s: sending challenge success: %u", __func__, success);
693 mm_request_send(socket, MONITOR_ANS_BSDAUTHQUERY, m);
706 mm_answer_bsdauthrespond(int socket, Buffer *m)
711 if (authctxt->as == 0)
712 fatal("%s: no bsd auth session", __func__);
714 response = buffer_get_string(m, NULL);
715 authok = options.challenge_response_authentication &&
716 auth_userresponse(authctxt->as, response, 0);
718 debug3("%s: <%s> = <%d>", __func__, response, authok);
722 buffer_put_int(m, authok);
724 debug3("%s: sending authenticated: %d", __func__, authok);
725 mm_request_send(socket, MONITOR_ANS_BSDAUTHRESPOND, m);
727 auth_method = "bsdauth";
729 return (authok != 0);
735 mm_answer_skeyquery(int socket, Buffer *m)
738 char challenge[1024];
741 success = skeychallenge(&skey, authctxt->user, challenge) < 0 ? 0 : 1;
744 buffer_put_int(m, success);
746 buffer_put_cstring(m, challenge);
748 debug3("%s: sending challenge success: %u", __func__, success);
749 mm_request_send(socket, MONITOR_ANS_SKEYQUERY, m);
755 mm_answer_skeyrespond(int socket, Buffer *m)
760 response = buffer_get_string(m, NULL);
762 authok = (options.challenge_response_authentication &&
764 skey_haskey(authctxt->pw->pw_name) == 0 &&
765 skey_passcheck(authctxt->pw->pw_name, response) != -1);
770 buffer_put_int(m, authok);
772 debug3("%s: sending authenticated: %d", __func__, authok);
773 mm_request_send(socket, MONITOR_ANS_SKEYRESPOND, m);
775 auth_method = "skey";
777 return (authok != 0);
783 mm_answer_pam_start(int socket, Buffer *m)
787 if (!options.use_pam)
788 fatal("UsePAM not set, but ended up in %s anyway", __func__);
790 user = buffer_get_string(m, NULL);
796 monitor_permit(mon_dispatch, MONITOR_REQ_PAM_ACCOUNT, 1);
802 mm_answer_pam_account(int socket, Buffer *m)
806 if (!options.use_pam)
807 fatal("UsePAM not set, but ended up in %s anyway", __func__);
809 ret = do_pam_account();
811 buffer_put_int(m, ret);
813 mm_request_send(socket, MONITOR_ANS_PAM_ACCOUNT, m);
818 static void *sshpam_ctxt, *sshpam_authok;
819 extern KbdintDevice sshpam_device;
822 mm_answer_pam_init_ctx(int socket, Buffer *m)
825 debug3("%s", __func__);
826 authctxt->user = buffer_get_string(m, NULL);
827 sshpam_ctxt = (sshpam_device.init_ctx)(authctxt);
828 sshpam_authok = NULL;
830 if (sshpam_ctxt != NULL) {
831 monitor_permit(mon_dispatch, MONITOR_REQ_PAM_FREE_CTX, 1);
832 buffer_put_int(m, 1);
834 buffer_put_int(m, 0);
836 mm_request_send(socket, MONITOR_ANS_PAM_INIT_CTX, m);
841 mm_answer_pam_query(int socket, Buffer *m)
843 char *name, *info, **prompts;
847 debug3("%s", __func__);
848 sshpam_authok = NULL;
849 ret = (sshpam_device.query)(sshpam_ctxt, &name, &info, &num, &prompts, &echo_on);
850 if (ret == 0 && num == 0)
851 sshpam_authok = sshpam_ctxt;
852 if (num > 1 || name == NULL || info == NULL)
855 buffer_put_int(m, ret);
856 buffer_put_cstring(m, name);
858 buffer_put_cstring(m, info);
860 buffer_put_int(m, num);
861 for (i = 0; i < num; ++i) {
862 buffer_put_cstring(m, prompts[i]);
864 buffer_put_int(m, echo_on[i]);
870 mm_request_send(socket, MONITOR_ANS_PAM_QUERY, m);
875 mm_answer_pam_respond(int socket, Buffer *m)
881 debug3("%s", __func__);
882 sshpam_authok = NULL;
883 num = buffer_get_int(m);
885 resp = xmalloc(num * sizeof(char *));
886 for (i = 0; i < num; ++i)
887 resp[i] = buffer_get_string(m, NULL);
888 ret = (sshpam_device.respond)(sshpam_ctxt, num, resp);
889 for (i = 0; i < num; ++i)
893 ret = (sshpam_device.respond)(sshpam_ctxt, num, NULL);
896 buffer_put_int(m, ret);
897 mm_request_send(socket, MONITOR_ANS_PAM_RESPOND, m);
898 auth_method = "keyboard-interactive/pam";
900 sshpam_authok = sshpam_ctxt;
905 mm_answer_pam_free_ctx(int socket, Buffer *m)
908 debug3("%s", __func__);
909 (sshpam_device.free_ctx)(sshpam_ctxt);
911 mm_request_send(socket, MONITOR_ANS_PAM_FREE_CTX, m);
912 return (sshpam_authok == sshpam_ctxt);
917 mm_append_debug(Buffer *m)
919 if (auth_debug_init && buffer_len(&auth_debug)) {
920 debug3("%s: Appending debug messages for child", __func__);
921 buffer_append(m, buffer_ptr(&auth_debug),
922 buffer_len(&auth_debug));
923 buffer_clear(&auth_debug);
928 mm_answer_keyallowed(int socket, Buffer *m)
934 enum mm_keytype type = 0;
937 debug3("%s entering", __func__);
939 type = buffer_get_int(m);
940 cuser = buffer_get_string(m, NULL);
941 chost = buffer_get_string(m, NULL);
942 blob = buffer_get_string(m, &bloblen);
944 key = key_from_blob(blob, bloblen);
946 if ((compat20 && type == MM_RSAHOSTKEY) ||
947 (!compat20 && type != MM_RSAHOSTKEY))
948 fatal("%s: key type and protocol mismatch", __func__);
950 debug3("%s: key_from_blob: %p", __func__, key);
952 if (key != NULL && authctxt->valid) {
955 allowed = options.pubkey_authentication &&
956 user_key_allowed(authctxt->pw, key);
959 allowed = options.hostbased_authentication &&
960 hostbased_key_allowed(authctxt->pw,
964 key->type = KEY_RSA1; /* XXX */
965 allowed = options.rhosts_rsa_authentication &&
966 auth_rhosts_rsa_key_allowed(authctxt->pw,
970 fatal("%s: unknown key type %d", __func__, type);
977 /* clear temporarily storage (used by verify) */
978 monitor_reset_key_state();
981 /* Save temporarily for comparison in verify */
983 key_bloblen = bloblen;
985 hostbased_cuser = cuser;
986 hostbased_chost = chost;
989 debug3("%s: key %p is %s",
990 __func__, key, allowed ? "allowed" : "disallowed");
993 buffer_put_int(m, allowed);
994 buffer_put_int(m, forced_command != NULL);
998 mm_request_send(socket, MONITOR_ANS_KEYALLOWED, m);
1000 if (type == MM_RSAHOSTKEY)
1001 monitor_permit(mon_dispatch, MONITOR_REQ_RSACHALLENGE, allowed);
1007 monitor_valid_userblob(u_char *data, u_int datalen)
1015 buffer_append(&b, data, datalen);
1017 if (datafellows & SSH_OLD_SESSIONID) {
1019 len = buffer_len(&b);
1020 if ((session_id2 == NULL) ||
1021 (len < session_id2_len) ||
1022 (memcmp(p, session_id2, session_id2_len) != 0))
1024 buffer_consume(&b, session_id2_len);
1026 p = buffer_get_string(&b, &len);
1027 if ((session_id2 == NULL) ||
1028 (len != session_id2_len) ||
1029 (memcmp(p, session_id2, session_id2_len) != 0))
1033 if (buffer_get_char(&b) != SSH2_MSG_USERAUTH_REQUEST)
1035 p = buffer_get_string(&b, NULL);
1036 if (strcmp(authctxt->user, p) != 0) {
1037 logit("wrong user name passed to monitor: expected %s != %.100s",
1042 buffer_skip_string(&b);
1043 if (datafellows & SSH_BUG_PKAUTH) {
1044 if (!buffer_get_char(&b))
1047 p = buffer_get_string(&b, NULL);
1048 if (strcmp("publickey", p) != 0)
1051 if (!buffer_get_char(&b))
1053 buffer_skip_string(&b);
1055 buffer_skip_string(&b);
1056 if (buffer_len(&b) != 0)
1063 monitor_valid_hostbasedblob(u_char *data, u_int datalen, char *cuser,
1072 buffer_append(&b, data, datalen);
1074 p = buffer_get_string(&b, &len);
1075 if ((session_id2 == NULL) ||
1076 (len != session_id2_len) ||
1077 (memcmp(p, session_id2, session_id2_len) != 0))
1081 if (buffer_get_char(&b) != SSH2_MSG_USERAUTH_REQUEST)
1083 p = buffer_get_string(&b, NULL);
1084 if (strcmp(authctxt->user, p) != 0) {
1085 logit("wrong user name passed to monitor: expected %s != %.100s",
1090 buffer_skip_string(&b); /* service */
1091 p = buffer_get_string(&b, NULL);
1092 if (strcmp(p, "hostbased") != 0)
1095 buffer_skip_string(&b); /* pkalg */
1096 buffer_skip_string(&b); /* pkblob */
1098 /* verify client host, strip trailing dot if necessary */
1099 p = buffer_get_string(&b, NULL);
1100 if (((len = strlen(p)) > 0) && p[len - 1] == '.')
1102 if (strcmp(p, chost) != 0)
1106 /* verify client user */
1107 p = buffer_get_string(&b, NULL);
1108 if (strcmp(p, cuser) != 0)
1112 if (buffer_len(&b) != 0)
1119 mm_answer_keyverify(int socket, Buffer *m)
1122 u_char *signature, *data, *blob;
1123 u_int signaturelen, datalen, bloblen;
1127 blob = buffer_get_string(m, &bloblen);
1128 signature = buffer_get_string(m, &signaturelen);
1129 data = buffer_get_string(m, &datalen);
1131 if (hostbased_cuser == NULL || hostbased_chost == NULL ||
1132 !monitor_allowed_key(blob, bloblen))
1133 fatal("%s: bad key, not previously allowed", __func__);
1135 key = key_from_blob(blob, bloblen);
1137 fatal("%s: bad public key blob", __func__);
1139 switch (key_blobtype) {
1141 valid_data = monitor_valid_userblob(data, datalen);
1144 valid_data = monitor_valid_hostbasedblob(data, datalen,
1145 hostbased_cuser, hostbased_chost);
1152 fatal("%s: bad signature data blob", __func__);
1154 verified = key_verify(key, signature, signaturelen, data, datalen);
1155 debug3("%s: key %p signature %s",
1156 __func__, key, verified ? "verified" : "unverified");
1163 auth_method = key_blobtype == MM_USERKEY ? "publickey" : "hostbased";
1165 monitor_reset_key_state();
1168 buffer_put_int(m, verified);
1169 mm_request_send(socket, MONITOR_ANS_KEYVERIFY, m);
1175 mm_record_login(Session *s, struct passwd *pw)
1178 struct sockaddr_storage from;
1181 * Get IP address of client. If the connection is not a socket, let
1182 * the address be 0.0.0.0.
1184 memset(&from, 0, sizeof(from));
1185 fromlen = sizeof(from);
1186 if (packet_connection_is_on_socket()) {
1187 if (getpeername(packet_get_connection_in(),
1188 (struct sockaddr *) & from, &fromlen) < 0) {
1189 debug("getpeername: %.100s", strerror(errno));
1193 /* Record that there was a login on that tty from the remote host. */
1194 record_login(s->pid, s->tty, pw->pw_name, pw->pw_uid,
1195 get_remote_name_or_ip(utmp_len, options.use_dns),
1196 (struct sockaddr *)&from, fromlen);
1200 mm_session_close(Session *s)
1202 debug3("%s: session %d pid %ld", __func__, s->self, (long)s->pid);
1203 if (s->ttyfd != -1) {
1204 debug3("%s: tty %s ptyfd %d", __func__, s->tty, s->ptyfd);
1205 session_pty_cleanup2(s);
1211 mm_answer_pty(int socket, Buffer *m)
1213 extern struct monitor *pmonitor;
1217 debug3("%s entering", __func__);
1223 s->authctxt = authctxt;
1224 s->pw = authctxt->pw;
1225 s->pid = pmonitor->m_pid;
1226 res = pty_allocate(&s->ptyfd, &s->ttyfd, s->tty, sizeof(s->tty));
1229 pty_setowner(authctxt->pw, s->tty);
1231 buffer_put_int(m, 1);
1232 buffer_put_cstring(m, s->tty);
1233 mm_request_send(socket, MONITOR_ANS_PTY, m);
1235 mm_send_fd(socket, s->ptyfd);
1236 mm_send_fd(socket, s->ttyfd);
1238 /* We need to trick ttyslot */
1239 if (dup2(s->ttyfd, 0) == -1)
1240 fatal("%s: dup2", __func__);
1242 mm_record_login(s, authctxt->pw);
1244 /* Now we can close the file descriptor again */
1247 /* make sure nothing uses fd 0 */
1248 if ((fd0 = open(_PATH_DEVNULL, O_RDONLY)) < 0)
1249 fatal("%s: open(/dev/null): %s", __func__, strerror(errno));
1251 error("%s: fd0 %d != 0", __func__, fd0);
1253 /* slave is not needed */
1255 s->ttyfd = s->ptyfd;
1256 /* no need to dup() because nobody closes ptyfd */
1257 s->ptymaster = s->ptyfd;
1259 debug3("%s: tty %s ptyfd %d", __func__, s->tty, s->ttyfd);
1265 mm_session_close(s);
1266 buffer_put_int(m, 0);
1267 mm_request_send(socket, MONITOR_ANS_PTY, m);
1272 mm_answer_pty_cleanup(int socket, Buffer *m)
1277 debug3("%s entering", __func__);
1279 tty = buffer_get_string(m, NULL);
1280 if ((s = session_by_tty(tty)) != NULL)
1281 mm_session_close(s);
1288 mm_answer_sesskey(int socket, Buffer *m)
1293 /* Turn off permissions */
1294 monitor_permit(mon_dispatch, MONITOR_REQ_SESSKEY, 1);
1296 if ((p = BN_new()) == NULL)
1297 fatal("%s: BN_new", __func__);
1299 buffer_get_bignum2(m, p);
1301 rsafail = ssh1_session_key(p);
1304 buffer_put_int(m, rsafail);
1305 buffer_put_bignum2(m, p);
1309 mm_request_send(socket, MONITOR_ANS_SESSKEY, m);
1311 /* Turn on permissions for sessid passing */
1312 monitor_permit(mon_dispatch, MONITOR_REQ_SESSID, 1);
1318 mm_answer_sessid(int socket, Buffer *m)
1322 debug3("%s entering", __func__);
1324 if (buffer_len(m) != 16)
1325 fatal("%s: bad ssh1 session id", __func__);
1326 for (i = 0; i < 16; i++)
1327 session_id[i] = buffer_get_char(m);
1329 /* Turn on permissions for getpwnam */
1330 monitor_permit(mon_dispatch, MONITOR_REQ_PWNAM, 1);
1336 mm_answer_rsa_keyallowed(int socket, Buffer *m)
1340 u_char *blob = NULL;
1344 debug3("%s entering", __func__);
1346 if (options.rsa_authentication && authctxt->valid) {
1347 if ((client_n = BN_new()) == NULL)
1348 fatal("%s: BN_new", __func__);
1349 buffer_get_bignum2(m, client_n);
1350 allowed = auth_rsa_key_allowed(authctxt->pw, client_n, &key);
1351 BN_clear_free(client_n);
1354 buffer_put_int(m, allowed);
1355 buffer_put_int(m, forced_command != NULL);
1357 /* clear temporarily storage (used by generate challenge) */
1358 monitor_reset_key_state();
1360 if (allowed && key != NULL) {
1361 key->type = KEY_RSA; /* cheat for key_to_blob */
1362 if (key_to_blob(key, &blob, &blen) == 0)
1363 fatal("%s: key_to_blob failed", __func__);
1364 buffer_put_string(m, blob, blen);
1366 /* Save temporarily for comparison in verify */
1369 key_blobtype = MM_RSAUSERKEY;
1376 mm_request_send(socket, MONITOR_ANS_RSAKEYALLOWED, m);
1378 monitor_permit(mon_dispatch, MONITOR_REQ_RSACHALLENGE, allowed);
1379 monitor_permit(mon_dispatch, MONITOR_REQ_RSARESPONSE, 0);
1384 mm_answer_rsa_challenge(int socket, Buffer *m)
1390 debug3("%s entering", __func__);
1392 if (!authctxt->valid)
1393 fatal("%s: authctxt not valid", __func__);
1394 blob = buffer_get_string(m, &blen);
1395 if (!monitor_allowed_key(blob, blen))
1396 fatal("%s: bad key, not previously allowed", __func__);
1397 if (key_blobtype != MM_RSAUSERKEY && key_blobtype != MM_RSAHOSTKEY)
1398 fatal("%s: key type mismatch", __func__);
1399 if ((key = key_from_blob(blob, blen)) == NULL)
1400 fatal("%s: received bad key", __func__);
1403 BN_clear_free(ssh1_challenge);
1404 ssh1_challenge = auth_rsa_generate_challenge(key);
1407 buffer_put_bignum2(m, ssh1_challenge);
1409 debug3("%s sending reply", __func__);
1410 mm_request_send(socket, MONITOR_ANS_RSACHALLENGE, m);
1412 monitor_permit(mon_dispatch, MONITOR_REQ_RSARESPONSE, 1);
1420 mm_answer_rsa_response(int socket, Buffer *m)
1423 u_char *blob, *response;
1427 debug3("%s entering", __func__);
1429 if (!authctxt->valid)
1430 fatal("%s: authctxt not valid", __func__);
1431 if (ssh1_challenge == NULL)
1432 fatal("%s: no ssh1_challenge", __func__);
1434 blob = buffer_get_string(m, &blen);
1435 if (!monitor_allowed_key(blob, blen))
1436 fatal("%s: bad key, not previously allowed", __func__);
1437 if (key_blobtype != MM_RSAUSERKEY && key_blobtype != MM_RSAHOSTKEY)
1438 fatal("%s: key type mismatch: %d", __func__, key_blobtype);
1439 if ((key = key_from_blob(blob, blen)) == NULL)
1440 fatal("%s: received bad key", __func__);
1441 response = buffer_get_string(m, &len);
1443 fatal("%s: received bad response to challenge", __func__);
1444 success = auth_rsa_verify_response(key, ssh1_challenge, response);
1450 auth_method = key_blobtype == MM_RSAUSERKEY ? "rsa" : "rhosts-rsa";
1453 BN_clear_free(ssh1_challenge);
1454 ssh1_challenge = NULL;
1455 monitor_reset_key_state();
1458 buffer_put_int(m, success);
1459 mm_request_send(socket, MONITOR_ANS_RSARESPONSE, m);
1465 mm_answer_term(int socket, Buffer *req)
1467 extern struct monitor *pmonitor;
1470 debug3("%s: tearing down sessions", __func__);
1472 /* The child is terminating */
1473 session_destroy_all(&mm_session_close);
1475 while (waitpid(pmonitor->m_pid, &status, 0) == -1)
1479 res = WIFEXITED(status) ? WEXITSTATUS(status) : 1;
1481 /* Terminate process */
1486 monitor_apply_keystate(struct monitor *pmonitor)
1489 set_newkeys(MODE_IN);
1490 set_newkeys(MODE_OUT);
1492 packet_set_protocol_flags(child_state.ssh1protoflags);
1493 packet_set_encryption_key(child_state.ssh1key,
1494 child_state.ssh1keylen, child_state.ssh1cipher);
1495 xfree(child_state.ssh1key);
1498 /* for rc4 and other stateful ciphers */
1499 packet_set_keycontext(MODE_OUT, child_state.keyout);
1500 xfree(child_state.keyout);
1501 packet_set_keycontext(MODE_IN, child_state.keyin);
1502 xfree(child_state.keyin);
1505 packet_set_iv(MODE_OUT, child_state.ivout);
1506 xfree(child_state.ivout);
1507 packet_set_iv(MODE_IN, child_state.ivin);
1508 xfree(child_state.ivin);
1511 memcpy(&incoming_stream, &child_state.incoming,
1512 sizeof(incoming_stream));
1513 memcpy(&outgoing_stream, &child_state.outgoing,
1514 sizeof(outgoing_stream));
1516 /* Update with new address */
1517 if (options.compression)
1518 mm_init_compression(pmonitor->m_zlib);
1520 /* Network I/O buffers */
1521 /* XXX inefficient for large buffers, need: buffer_init_from_string */
1522 buffer_clear(&input);
1523 buffer_append(&input, child_state.input, child_state.ilen);
1524 memset(child_state.input, 0, child_state.ilen);
1525 xfree(child_state.input);
1527 buffer_clear(&output);
1528 buffer_append(&output, child_state.output, child_state.olen);
1529 memset(child_state.output, 0, child_state.olen);
1530 xfree(child_state.output);
1534 mm_get_kex(Buffer *m)
1540 kex = xmalloc(sizeof(*kex));
1541 memset(kex, 0, sizeof(*kex));
1542 kex->session_id = buffer_get_string(m, &kex->session_id_len);
1543 if ((session_id2 == NULL) ||
1544 (kex->session_id_len != session_id2_len) ||
1545 (memcmp(kex->session_id, session_id2, session_id2_len) != 0))
1546 fatal("mm_get_get: internal error: bad session id");
1547 kex->we_need = buffer_get_int(m);
1548 kex->kex[KEX_DH_GRP1_SHA1] = kexdh_server;
1549 kex->kex[KEX_DH_GEX_SHA1] = kexgex_server;
1551 kex->hostkey_type = buffer_get_int(m);
1552 kex->kex_type = buffer_get_int(m);
1553 blob = buffer_get_string(m, &bloblen);
1554 buffer_init(&kex->my);
1555 buffer_append(&kex->my, blob, bloblen);
1557 blob = buffer_get_string(m, &bloblen);
1558 buffer_init(&kex->peer);
1559 buffer_append(&kex->peer, blob, bloblen);
1562 kex->flags = buffer_get_int(m);
1563 kex->client_version_string = buffer_get_string(m, NULL);
1564 kex->server_version_string = buffer_get_string(m, NULL);
1565 kex->load_host_key=&get_hostkey_by_type;
1566 kex->host_key_index=&get_hostkey_index;
1571 /* This function requries careful sanity checking */
1574 mm_get_keystate(struct monitor *pmonitor)
1578 u_int bloblen, plen;
1579 u_int32_t seqnr, packets;
1582 debug3("%s: Waiting for new keys", __func__);
1585 mm_request_receive_expect(pmonitor->m_sendfd, MONITOR_REQ_KEYEXPORT, &m);
1587 child_state.ssh1protoflags = buffer_get_int(&m);
1588 child_state.ssh1cipher = buffer_get_int(&m);
1589 child_state.ssh1key = buffer_get_string(&m,
1590 &child_state.ssh1keylen);
1591 child_state.ivout = buffer_get_string(&m,
1592 &child_state.ivoutlen);
1593 child_state.ivin = buffer_get_string(&m, &child_state.ivinlen);
1596 /* Get the Kex for rekeying */
1597 *pmonitor->m_pkex = mm_get_kex(&m);
1600 blob = buffer_get_string(&m, &bloblen);
1601 current_keys[MODE_OUT] = mm_newkeys_from_blob(blob, bloblen);
1604 debug3("%s: Waiting for second key", __func__);
1605 blob = buffer_get_string(&m, &bloblen);
1606 current_keys[MODE_IN] = mm_newkeys_from_blob(blob, bloblen);
1609 /* Now get sequence numbers for the packets */
1610 seqnr = buffer_get_int(&m);
1611 blocks = buffer_get_int64(&m);
1612 packets = buffer_get_int(&m);
1613 packet_set_state(MODE_OUT, seqnr, blocks, packets);
1614 seqnr = buffer_get_int(&m);
1615 blocks = buffer_get_int64(&m);
1616 packets = buffer_get_int(&m);
1617 packet_set_state(MODE_IN, seqnr, blocks, packets);
1620 /* Get the key context */
1621 child_state.keyout = buffer_get_string(&m, &child_state.keyoutlen);
1622 child_state.keyin = buffer_get_string(&m, &child_state.keyinlen);
1624 debug3("%s: Getting compression state", __func__);
1625 /* Get compression state */
1626 p = buffer_get_string(&m, &plen);
1627 if (plen != sizeof(child_state.outgoing))
1628 fatal("%s: bad request size", __func__);
1629 memcpy(&child_state.outgoing, p, sizeof(child_state.outgoing));
1632 p = buffer_get_string(&m, &plen);
1633 if (plen != sizeof(child_state.incoming))
1634 fatal("%s: bad request size", __func__);
1635 memcpy(&child_state.incoming, p, sizeof(child_state.incoming));
1638 /* Network I/O buffers */
1639 debug3("%s: Getting Network I/O buffers", __func__);
1640 child_state.input = buffer_get_string(&m, &child_state.ilen);
1641 child_state.output = buffer_get_string(&m, &child_state.olen);
1647 /* Allocation functions for zlib */
1649 mm_zalloc(struct mm_master *mm, u_int ncount, u_int size)
1651 size_t len = (size_t) size * ncount;
1654 if (len == 0 || ncount > SIZE_T_MAX / size)
1655 fatal("%s: mm_zalloc(%u, %u)", __func__, ncount, size);
1657 address = mm_malloc(mm, len);
1663 mm_zfree(struct mm_master *mm, void *address)
1665 mm_free(mm, address);
1669 mm_init_compression(struct mm_master *mm)
1671 outgoing_stream.zalloc = (alloc_func)mm_zalloc;
1672 outgoing_stream.zfree = (free_func)mm_zfree;
1673 outgoing_stream.opaque = mm;
1675 incoming_stream.zalloc = (alloc_func)mm_zalloc;
1676 incoming_stream.zfree = (free_func)mm_zfree;
1677 incoming_stream.opaque = mm;
1682 #define FD_CLOSEONEXEC(x) do { \
1683 if (fcntl(x, F_SETFD, 1) == -1) \
1684 fatal("fcntl(%d, F_SETFD)", x); \
1688 monitor_socketpair(int *pair)
1690 #ifdef HAVE_SOCKETPAIR
1691 if (socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1)
1692 fatal("%s: socketpair", __func__);
1694 fatal("%s: UsePrivilegeSeparation=yes not supported",
1697 FD_CLOSEONEXEC(pair[0]);
1698 FD_CLOSEONEXEC(pair[1]);
1701 #define MM_MEMSIZE 65536
1706 struct monitor *mon;
1709 mon = xmalloc(sizeof(*mon));
1711 monitor_socketpair(pair);
1713 mon->m_recvfd = pair[0];
1714 mon->m_sendfd = pair[1];
1716 /* Used to share zlib space across processes */
1717 if (options.compression) {
1718 mon->m_zback = mm_create(NULL, MM_MEMSIZE);
1719 mon->m_zlib = mm_create(mon->m_zback, 20 * MM_MEMSIZE);
1721 /* Compression needs to share state across borders */
1722 mm_init_compression(mon->m_zlib);
1729 monitor_reinit(struct monitor *mon)
1733 monitor_socketpair(pair);
1735 mon->m_recvfd = pair[0];
1736 mon->m_sendfd = pair[1];
1741 mm_answer_gss_setup_ctx(int socket, Buffer *m)
1747 oid.elements = buffer_get_string(m, &len);
1750 major = ssh_gssapi_server_ctx(&gsscontext, &oid);
1752 xfree(oid.elements);
1755 buffer_put_int(m, major);
1757 mm_request_send(socket,MONITOR_ANS_GSSSETUP, m);
1759 /* Now we have a context, enable the step */
1760 monitor_permit(mon_dispatch, MONITOR_REQ_GSSSTEP, 1);
1766 mm_answer_gss_accept_ctx(int socket, Buffer *m)
1769 gss_buffer_desc out = GSS_C_EMPTY_BUFFER;
1770 OM_uint32 major,minor;
1771 OM_uint32 flags = 0; /* GSI needs this */
1774 in.value = buffer_get_string(m, &len);
1776 major = ssh_gssapi_accept_ctx(gsscontext, &in, &out, &flags);
1780 buffer_put_int(m, major);
1781 buffer_put_string(m, out.value, out.length);
1782 buffer_put_int(m, flags);
1783 mm_request_send(socket, MONITOR_ANS_GSSSTEP, m);
1785 gss_release_buffer(&minor, &out);
1787 if (major==GSS_S_COMPLETE) {
1788 monitor_permit(mon_dispatch, MONITOR_REQ_GSSSTEP, 0);
1789 monitor_permit(mon_dispatch, MONITOR_REQ_GSSUSEROK, 1);
1790 monitor_permit(mon_dispatch, MONITOR_REQ_GSSCHECKMIC, 1);
1796 mm_answer_gss_checkmic(int socket, Buffer *m)
1798 gss_buffer_desc gssbuf, mic;
1802 gssbuf.value = buffer_get_string(m, &len);
1803 gssbuf.length = len;
1804 mic.value = buffer_get_string(m, &len);
1807 ret = ssh_gssapi_checkmic(gsscontext, &gssbuf, &mic);
1809 xfree(gssbuf.value);
1813 buffer_put_int(m, ret);
1815 mm_request_send(socket, MONITOR_ANS_GSSCHECKMIC, m);
1817 if (!GSS_ERROR(ret))
1818 monitor_permit(mon_dispatch, MONITOR_REQ_GSSUSEROK, 1);
1824 mm_answer_gss_userok(int socket, Buffer *m)
1828 authenticated = authctxt->valid && ssh_gssapi_userok(authctxt->user);
1831 buffer_put_int(m, authenticated);
1833 debug3("%s: sending result %d", __func__, authenticated);
1834 mm_request_send(socket, MONITOR_ANS_GSSUSEROK, m);
1836 auth_method="gssapi-with-mic";
1838 /* Monitor loop will terminate if authenticated */
1839 return (authenticated);