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.50 2003/09/23 20:17:11 markus 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 *);
139 static Authctxt *authctxt;
140 static BIGNUM *ssh1_challenge = NULL; /* used for ssh1 rsa auth */
142 /* local state for key verify */
143 static u_char *key_blob = NULL;
144 static u_int key_bloblen = 0;
145 static int key_blobtype = MM_NOKEY;
146 static char *hostbased_cuser = NULL;
147 static char *hostbased_chost = NULL;
148 static char *auth_method = "unknown";
149 static u_int session_id2_len = 0;
150 static u_char *session_id2 = NULL;
151 static pid_t monitor_child_pid;
154 enum monitor_reqtype type;
156 int (*f)(int, Buffer *);
159 #define MON_ISAUTH 0x0004 /* Required for Authentication */
160 #define MON_AUTHDECIDE 0x0008 /* Decides Authentication */
161 #define MON_ONCE 0x0010 /* Disable after calling */
163 #define MON_AUTH (MON_ISAUTH|MON_AUTHDECIDE)
165 #define MON_PERMIT 0x1000 /* Request is permitted */
167 struct mon_table mon_dispatch_proto20[] = {
168 {MONITOR_REQ_MODULI, MON_ONCE, mm_answer_moduli},
169 {MONITOR_REQ_SIGN, MON_ONCE, mm_answer_sign},
170 {MONITOR_REQ_PWNAM, MON_ONCE, mm_answer_pwnamallow},
171 {MONITOR_REQ_AUTHSERV, MON_ONCE, mm_answer_authserv},
172 {MONITOR_REQ_AUTH2_READ_BANNER, MON_ONCE, mm_answer_auth2_read_banner},
173 {MONITOR_REQ_AUTHPASSWORD, MON_AUTH, mm_answer_authpassword},
175 {MONITOR_REQ_PAM_START, MON_ONCE, mm_answer_pam_start},
176 {MONITOR_REQ_PAM_ACCOUNT, 0, mm_answer_pam_account},
177 {MONITOR_REQ_PAM_INIT_CTX, MON_ISAUTH, mm_answer_pam_init_ctx},
178 {MONITOR_REQ_PAM_QUERY, MON_ISAUTH, mm_answer_pam_query},
179 {MONITOR_REQ_PAM_RESPOND, MON_ISAUTH, mm_answer_pam_respond},
180 {MONITOR_REQ_PAM_FREE_CTX, MON_ONCE|MON_AUTHDECIDE, mm_answer_pam_free_ctx},
183 {MONITOR_REQ_BSDAUTHQUERY, MON_ISAUTH, mm_answer_bsdauthquery},
184 {MONITOR_REQ_BSDAUTHRESPOND, MON_AUTH,mm_answer_bsdauthrespond},
187 {MONITOR_REQ_SKEYQUERY, MON_ISAUTH, mm_answer_skeyquery},
188 {MONITOR_REQ_SKEYRESPOND, MON_AUTH, mm_answer_skeyrespond},
190 {MONITOR_REQ_KEYALLOWED, MON_ISAUTH, mm_answer_keyallowed},
191 {MONITOR_REQ_KEYVERIFY, MON_AUTH, mm_answer_keyverify},
193 {MONITOR_REQ_GSSSETUP, MON_ISAUTH, mm_answer_gss_setup_ctx},
194 {MONITOR_REQ_GSSSTEP, MON_ISAUTH, mm_answer_gss_accept_ctx},
195 {MONITOR_REQ_GSSUSEROK, MON_AUTH, mm_answer_gss_userok},
200 struct mon_table mon_dispatch_postauth20[] = {
201 {MONITOR_REQ_MODULI, 0, mm_answer_moduli},
202 {MONITOR_REQ_SIGN, 0, mm_answer_sign},
203 {MONITOR_REQ_PTY, 0, mm_answer_pty},
204 {MONITOR_REQ_PTYCLEANUP, 0, mm_answer_pty_cleanup},
205 {MONITOR_REQ_TERM, 0, mm_answer_term},
209 struct mon_table mon_dispatch_proto15[] = {
210 {MONITOR_REQ_PWNAM, MON_ONCE, mm_answer_pwnamallow},
211 {MONITOR_REQ_SESSKEY, MON_ONCE, mm_answer_sesskey},
212 {MONITOR_REQ_SESSID, MON_ONCE, mm_answer_sessid},
213 {MONITOR_REQ_AUTHPASSWORD, MON_AUTH, mm_answer_authpassword},
214 {MONITOR_REQ_RSAKEYALLOWED, MON_ISAUTH, mm_answer_rsa_keyallowed},
215 {MONITOR_REQ_KEYALLOWED, MON_ISAUTH, mm_answer_keyallowed},
216 {MONITOR_REQ_RSACHALLENGE, MON_ONCE, mm_answer_rsa_challenge},
217 {MONITOR_REQ_RSARESPONSE, MON_ONCE|MON_AUTHDECIDE, mm_answer_rsa_response},
219 {MONITOR_REQ_BSDAUTHQUERY, MON_ISAUTH, mm_answer_bsdauthquery},
220 {MONITOR_REQ_BSDAUTHRESPOND, MON_AUTH,mm_answer_bsdauthrespond},
223 {MONITOR_REQ_SKEYQUERY, MON_ISAUTH, mm_answer_skeyquery},
224 {MONITOR_REQ_SKEYRESPOND, MON_AUTH, mm_answer_skeyrespond},
227 {MONITOR_REQ_PAM_START, MON_ONCE, mm_answer_pam_start},
228 {MONITOR_REQ_PAM_ACCOUNT, 0, mm_answer_pam_account},
229 {MONITOR_REQ_PAM_INIT_CTX, MON_ISAUTH, mm_answer_pam_init_ctx},
230 {MONITOR_REQ_PAM_QUERY, MON_ISAUTH, mm_answer_pam_query},
231 {MONITOR_REQ_PAM_RESPOND, MON_ISAUTH, mm_answer_pam_respond},
232 {MONITOR_REQ_PAM_FREE_CTX, MON_ONCE|MON_AUTHDECIDE, mm_answer_pam_free_ctx},
237 struct mon_table mon_dispatch_postauth15[] = {
238 {MONITOR_REQ_PTY, MON_ONCE, mm_answer_pty},
239 {MONITOR_REQ_PTYCLEANUP, MON_ONCE, mm_answer_pty_cleanup},
240 {MONITOR_REQ_TERM, 0, mm_answer_term},
244 struct mon_table *mon_dispatch;
246 /* Specifies if a certain message is allowed at the moment */
249 monitor_permit(struct mon_table *ent, enum monitor_reqtype type, int permit)
251 while (ent->f != NULL) {
252 if (ent->type == type) {
253 ent->flags &= ~MON_PERMIT;
254 ent->flags |= permit ? MON_PERMIT : 0;
262 monitor_permit_authentications(int permit)
264 struct mon_table *ent = mon_dispatch;
266 while (ent->f != NULL) {
267 if (ent->flags & MON_AUTH) {
268 ent->flags &= ~MON_PERMIT;
269 ent->flags |= permit ? MON_PERMIT : 0;
276 monitor_child_preauth(Authctxt *_authctxt, struct monitor *pmonitor)
278 struct mon_table *ent;
279 int authenticated = 0;
281 debug3("preauth child monitor started");
283 authctxt = _authctxt;
284 memset(authctxt, 0, sizeof(*authctxt));
287 mon_dispatch = mon_dispatch_proto20;
289 /* Permit requests for moduli and signatures */
290 monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1);
291 monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1);
293 mon_dispatch = mon_dispatch_proto15;
295 monitor_permit(mon_dispatch, MONITOR_REQ_SESSKEY, 1);
298 /* The first few requests do not require asynchronous access */
299 while (!authenticated) {
300 authenticated = monitor_read(pmonitor, mon_dispatch, &ent);
302 if (!(ent->flags & MON_AUTHDECIDE))
303 fatal("%s: unexpected authentication from %d",
304 __func__, ent->type);
305 if (authctxt->pw->pw_uid == 0 &&
306 !auth_root_allowed(auth_method))
309 /* PAM needs to perform account checks after auth */
310 if (options.use_pam) {
314 mm_request_receive_expect(pmonitor->m_sendfd,
315 MONITOR_REQ_PAM_ACCOUNT, &m);
316 authenticated = mm_answer_pam_account(pmonitor->m_sendfd, &m);
322 if (ent->flags & MON_AUTHDECIDE) {
323 auth_log(authctxt, authenticated, auth_method,
324 compat20 ? " ssh2" : "");
326 authctxt->failures++;
330 if (!authctxt->valid)
331 fatal("%s: authenticated invalid user", __func__);
333 debug("%s: %s has been authenticated by privileged process",
334 __func__, authctxt->user);
336 mm_get_keystate(pmonitor);
340 monitor_set_child_handler(pid_t pid)
342 monitor_child_pid = pid;
346 monitor_child_handler(int signal)
348 kill(monitor_child_pid, signal);
352 monitor_child_postauth(struct monitor *pmonitor)
354 monitor_set_child_handler(pmonitor->m_pid);
355 signal(SIGHUP, &monitor_child_handler);
356 signal(SIGTERM, &monitor_child_handler);
359 mon_dispatch = mon_dispatch_postauth20;
361 /* Permit requests for moduli and signatures */
362 monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1);
363 monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1);
364 monitor_permit(mon_dispatch, MONITOR_REQ_TERM, 1);
366 mon_dispatch = mon_dispatch_postauth15;
367 monitor_permit(mon_dispatch, MONITOR_REQ_TERM, 1);
370 monitor_permit(mon_dispatch, MONITOR_REQ_PTY, 1);
371 monitor_permit(mon_dispatch, MONITOR_REQ_PTYCLEANUP, 1);
375 monitor_read(pmonitor, mon_dispatch, NULL);
379 monitor_sync(struct monitor *pmonitor)
381 if (options.compression) {
382 /* The member allocation is not visible, so sync it */
383 mm_share_sync(&pmonitor->m_zlib, &pmonitor->m_zback);
388 monitor_read(struct monitor *pmonitor, struct mon_table *ent,
389 struct mon_table **pent)
397 mm_request_receive(pmonitor->m_sendfd, &m);
398 type = buffer_get_char(&m);
400 debug3("%s: checking request %d", __func__, type);
402 while (ent->f != NULL) {
403 if (ent->type == type)
408 if (ent->f != NULL) {
409 if (!(ent->flags & MON_PERMIT))
410 fatal("%s: unpermitted request %d", __func__,
412 ret = (*ent->f)(pmonitor->m_sendfd, &m);
415 /* The child may use this request only once, disable it */
416 if (ent->flags & MON_ONCE) {
417 debug2("%s: %d used once, disabling now", __func__,
419 ent->flags &= ~MON_PERMIT;
428 fatal("%s: unsupported request: %d", __func__, type);
434 /* allowed key state */
436 monitor_allowed_key(u_char *blob, u_int bloblen)
438 /* make sure key is allowed */
439 if (key_blob == NULL || key_bloblen != bloblen ||
440 memcmp(key_blob, blob, key_bloblen))
446 monitor_reset_key_state(void)
449 if (key_blob != NULL)
451 if (hostbased_cuser != NULL)
452 xfree(hostbased_cuser);
453 if (hostbased_chost != NULL)
454 xfree(hostbased_chost);
457 key_blobtype = MM_NOKEY;
458 hostbased_cuser = NULL;
459 hostbased_chost = NULL;
463 mm_answer_moduli(int socket, Buffer *m)
468 min = buffer_get_int(m);
469 want = buffer_get_int(m);
470 max = buffer_get_int(m);
472 debug3("%s: got parameters: %d %d %d",
473 __func__, min, want, max);
474 /* We need to check here, too, in case the child got corrupted */
475 if (max < min || want < min || max < want)
476 fatal("%s: bad parameters: %d %d %d",
477 __func__, min, want, max);
481 dh = choose_dh(min, want, max);
483 buffer_put_char(m, 0);
486 /* Send first bignum */
487 buffer_put_char(m, 1);
488 buffer_put_bignum2(m, dh->p);
489 buffer_put_bignum2(m, dh->g);
493 mm_request_send(socket, MONITOR_ANS_MODULI, m);
498 mm_answer_sign(int socket, Buffer *m)
503 u_int siglen, datlen;
506 debug3("%s", __func__);
508 keyid = buffer_get_int(m);
509 p = buffer_get_string(m, &datlen);
512 fatal("%s: data length incorrect: %u", __func__, datlen);
514 /* save session id, it will be passed on the first call */
515 if (session_id2_len == 0) {
516 session_id2_len = datlen;
517 session_id2 = xmalloc(session_id2_len);
518 memcpy(session_id2, p, session_id2_len);
521 if ((key = get_hostkey_by_index(keyid)) == NULL)
522 fatal("%s: no hostkey from index %d", __func__, keyid);
523 if (key_sign(key, &signature, &siglen, p, datlen) < 0)
524 fatal("%s: key_sign failed", __func__);
526 debug3("%s: signature %p(%u)", __func__, signature, siglen);
529 buffer_put_string(m, signature, siglen);
534 mm_request_send(socket, MONITOR_ANS_SIGN, m);
536 /* Turn on permissions for getpwnam */
537 monitor_permit(mon_dispatch, MONITOR_REQ_PWNAM, 1);
542 /* Retrieves the password entry and also checks if the user is permitted */
545 mm_answer_pwnamallow(int socket, Buffer *m)
548 struct passwd *pwent;
551 debug3("%s", __func__);
553 if (authctxt->attempt++ != 0)
554 fatal("%s: multiple attempts for getpwnam", __func__);
556 login = buffer_get_string(m, NULL);
558 pwent = getpwnamallow(login);
560 authctxt->user = xstrdup(login);
561 setproctitle("%s [priv]", pwent ? login : "unknown");
567 buffer_put_char(m, 0);
572 authctxt->pw = pwent;
575 buffer_put_char(m, 1);
576 buffer_put_string(m, pwent, sizeof(struct passwd));
577 buffer_put_cstring(m, pwent->pw_name);
578 buffer_put_cstring(m, "*");
579 buffer_put_cstring(m, pwent->pw_gecos);
580 #ifdef HAVE_PW_CLASS_IN_PASSWD
581 buffer_put_cstring(m, pwent->pw_class);
583 buffer_put_cstring(m, pwent->pw_dir);
584 buffer_put_cstring(m, pwent->pw_shell);
587 debug3("%s: sending MONITOR_ANS_PWNAM: %d", __func__, allowed);
588 mm_request_send(socket, MONITOR_ANS_PWNAM, m);
590 /* For SSHv1 allow authentication now */
592 monitor_permit_authentications(1);
594 /* Allow service/style information on the auth context */
595 monitor_permit(mon_dispatch, MONITOR_REQ_AUTHSERV, 1);
596 monitor_permit(mon_dispatch, MONITOR_REQ_AUTH2_READ_BANNER, 1);
601 monitor_permit(mon_dispatch, MONITOR_REQ_PAM_START, 1);
607 int mm_answer_auth2_read_banner(int socket, Buffer *m)
612 banner = auth2_read_banner();
613 buffer_put_cstring(m, banner != NULL ? banner : "");
614 mm_request_send(socket, MONITOR_ANS_AUTH2_READ_BANNER, m);
623 mm_answer_authserv(int socket, Buffer *m)
625 monitor_permit_authentications(1);
627 authctxt->service = buffer_get_string(m, NULL);
628 authctxt->style = buffer_get_string(m, NULL);
629 debug3("%s: service=%s, style=%s",
630 __func__, authctxt->service, authctxt->style);
632 if (strlen(authctxt->style) == 0) {
633 xfree(authctxt->style);
634 authctxt->style = NULL;
641 mm_answer_authpassword(int socket, Buffer *m)
643 static int call_count;
648 passwd = buffer_get_string(m, &plen);
649 /* Only authenticate if the context is valid */
650 authenticated = options.password_authentication &&
651 auth_password(authctxt, passwd);
652 memset(passwd, 0, strlen(passwd));
656 buffer_put_int(m, authenticated);
658 debug3("%s: sending result %d", __func__, authenticated);
659 mm_request_send(socket, MONITOR_ANS_AUTHPASSWORD, m);
662 if (plen == 0 && call_count == 1)
663 auth_method = "none";
665 auth_method = "password";
667 /* Causes monitor loop to terminate if authenticated */
668 return (authenticated);
673 mm_answer_bsdauthquery(int socket, Buffer *m)
675 char *name, *infotxt;
681 success = bsdauth_query(authctxt, &name, &infotxt, &numprompts,
682 &prompts, &echo_on) < 0 ? 0 : 1;
685 buffer_put_int(m, success);
687 buffer_put_cstring(m, prompts[0]);
689 debug3("%s: sending challenge success: %u", __func__, success);
690 mm_request_send(socket, MONITOR_ANS_BSDAUTHQUERY, m);
703 mm_answer_bsdauthrespond(int socket, Buffer *m)
708 if (authctxt->as == 0)
709 fatal("%s: no bsd auth session", __func__);
711 response = buffer_get_string(m, NULL);
712 authok = options.challenge_response_authentication &&
713 auth_userresponse(authctxt->as, response, 0);
715 debug3("%s: <%s> = <%d>", __func__, response, authok);
719 buffer_put_int(m, authok);
721 debug3("%s: sending authenticated: %d", __func__, authok);
722 mm_request_send(socket, MONITOR_ANS_BSDAUTHRESPOND, m);
724 auth_method = "bsdauth";
726 return (authok != 0);
732 mm_answer_skeyquery(int socket, Buffer *m)
735 char challenge[1024];
738 success = skeychallenge(&skey, authctxt->user, challenge) < 0 ? 0 : 1;
741 buffer_put_int(m, success);
743 buffer_put_cstring(m, challenge);
745 debug3("%s: sending challenge success: %u", __func__, success);
746 mm_request_send(socket, MONITOR_ANS_SKEYQUERY, m);
752 mm_answer_skeyrespond(int socket, Buffer *m)
757 response = buffer_get_string(m, NULL);
759 authok = (options.challenge_response_authentication &&
761 skey_haskey(authctxt->pw->pw_name) == 0 &&
762 skey_passcheck(authctxt->pw->pw_name, response) != -1);
767 buffer_put_int(m, authok);
769 debug3("%s: sending authenticated: %d", __func__, authok);
770 mm_request_send(socket, MONITOR_ANS_SKEYRESPOND, m);
772 auth_method = "skey";
774 return (authok != 0);
780 mm_answer_pam_start(int socket, Buffer *m)
784 if (!options.use_pam)
785 fatal("UsePAM not set, but ended up in %s anyway", __func__);
787 user = buffer_get_string(m, NULL);
793 monitor_permit(mon_dispatch, MONITOR_REQ_PAM_ACCOUNT, 1);
799 mm_answer_pam_account(int socket, Buffer *m)
803 if (!options.use_pam)
804 fatal("UsePAM not set, but ended up in %s anyway", __func__);
806 ret = do_pam_account();
808 buffer_put_int(m, ret);
810 mm_request_send(socket, MONITOR_ANS_PAM_ACCOUNT, m);
815 static void *sshpam_ctxt, *sshpam_authok;
816 extern KbdintDevice sshpam_device;
819 mm_answer_pam_init_ctx(int socket, Buffer *m)
822 debug3("%s", __func__);
823 authctxt->user = buffer_get_string(m, NULL);
824 sshpam_ctxt = (sshpam_device.init_ctx)(authctxt);
825 sshpam_authok = NULL;
827 if (sshpam_ctxt != NULL) {
828 monitor_permit(mon_dispatch, MONITOR_REQ_PAM_FREE_CTX, 1);
829 buffer_put_int(m, 1);
831 buffer_put_int(m, 0);
833 mm_request_send(socket, MONITOR_ANS_PAM_INIT_CTX, m);
838 mm_answer_pam_query(int socket, Buffer *m)
840 char *name, *info, **prompts;
844 debug3("%s", __func__);
845 sshpam_authok = NULL;
846 ret = (sshpam_device.query)(sshpam_ctxt, &name, &info, &num, &prompts, &echo_on);
847 if (ret == 0 && num == 0)
848 sshpam_authok = sshpam_ctxt;
849 if (num > 1 || name == NULL || info == NULL)
852 buffer_put_int(m, ret);
853 buffer_put_cstring(m, name);
855 buffer_put_cstring(m, info);
857 buffer_put_int(m, num);
858 for (i = 0; i < num; ++i) {
859 buffer_put_cstring(m, prompts[i]);
861 buffer_put_int(m, echo_on[i]);
867 mm_request_send(socket, MONITOR_ANS_PAM_QUERY, m);
872 mm_answer_pam_respond(int socket, Buffer *m)
878 debug3("%s", __func__);
879 sshpam_authok = NULL;
880 num = buffer_get_int(m);
882 resp = xmalloc(num * sizeof(char *));
883 for (i = 0; i < num; ++i)
884 resp[i] = buffer_get_string(m, NULL);
885 ret = (sshpam_device.respond)(sshpam_ctxt, num, resp);
886 for (i = 0; i < num; ++i)
890 ret = (sshpam_device.respond)(sshpam_ctxt, num, NULL);
893 buffer_put_int(m, ret);
894 mm_request_send(socket, MONITOR_ANS_PAM_RESPOND, m);
895 auth_method = "keyboard-interactive/pam";
897 sshpam_authok = sshpam_ctxt;
902 mm_answer_pam_free_ctx(int socket, Buffer *m)
905 debug3("%s", __func__);
906 (sshpam_device.free_ctx)(sshpam_ctxt);
908 mm_request_send(socket, MONITOR_ANS_PAM_FREE_CTX, m);
909 return (sshpam_authok == sshpam_ctxt);
914 mm_append_debug(Buffer *m)
916 if (auth_debug_init && buffer_len(&auth_debug)) {
917 debug3("%s: Appending debug messages for child", __func__);
918 buffer_append(m, buffer_ptr(&auth_debug),
919 buffer_len(&auth_debug));
920 buffer_clear(&auth_debug);
925 mm_answer_keyallowed(int socket, Buffer *m)
931 enum mm_keytype type = 0;
934 debug3("%s entering", __func__);
936 type = buffer_get_int(m);
937 cuser = buffer_get_string(m, NULL);
938 chost = buffer_get_string(m, NULL);
939 blob = buffer_get_string(m, &bloblen);
941 key = key_from_blob(blob, bloblen);
943 if ((compat20 && type == MM_RSAHOSTKEY) ||
944 (!compat20 && type != MM_RSAHOSTKEY))
945 fatal("%s: key type and protocol mismatch", __func__);
947 debug3("%s: key_from_blob: %p", __func__, key);
949 if (key != NULL && authctxt->pw != NULL) {
952 allowed = options.pubkey_authentication &&
953 user_key_allowed(authctxt->pw, key);
956 allowed = options.hostbased_authentication &&
957 hostbased_key_allowed(authctxt->pw,
961 key->type = KEY_RSA1; /* XXX */
962 allowed = options.rhosts_rsa_authentication &&
963 auth_rhosts_rsa_key_allowed(authctxt->pw,
967 fatal("%s: unknown key type %d", __func__, type);
974 /* clear temporarily storage (used by verify) */
975 monitor_reset_key_state();
978 /* Save temporarily for comparison in verify */
980 key_bloblen = bloblen;
982 hostbased_cuser = cuser;
983 hostbased_chost = chost;
986 debug3("%s: key %p is %s",
987 __func__, key, allowed ? "allowed" : "disallowed");
990 buffer_put_int(m, allowed);
991 buffer_put_int(m, forced_command != NULL);
995 mm_request_send(socket, MONITOR_ANS_KEYALLOWED, m);
997 if (type == MM_RSAHOSTKEY)
998 monitor_permit(mon_dispatch, MONITOR_REQ_RSACHALLENGE, allowed);
1004 monitor_valid_userblob(u_char *data, u_int datalen)
1012 buffer_append(&b, data, datalen);
1014 if (datafellows & SSH_OLD_SESSIONID) {
1016 len = buffer_len(&b);
1017 if ((session_id2 == NULL) ||
1018 (len < session_id2_len) ||
1019 (memcmp(p, session_id2, session_id2_len) != 0))
1021 buffer_consume(&b, session_id2_len);
1023 p = buffer_get_string(&b, &len);
1024 if ((session_id2 == NULL) ||
1025 (len != session_id2_len) ||
1026 (memcmp(p, session_id2, session_id2_len) != 0))
1030 if (buffer_get_char(&b) != SSH2_MSG_USERAUTH_REQUEST)
1032 p = buffer_get_string(&b, NULL);
1033 if (strcmp(authctxt->user, p) != 0) {
1034 logit("wrong user name passed to monitor: expected %s != %.100s",
1039 buffer_skip_string(&b);
1040 if (datafellows & SSH_BUG_PKAUTH) {
1041 if (!buffer_get_char(&b))
1044 p = buffer_get_string(&b, NULL);
1045 if (strcmp("publickey", p) != 0)
1048 if (!buffer_get_char(&b))
1050 buffer_skip_string(&b);
1052 buffer_skip_string(&b);
1053 if (buffer_len(&b) != 0)
1060 monitor_valid_hostbasedblob(u_char *data, u_int datalen, char *cuser,
1069 buffer_append(&b, data, datalen);
1071 p = buffer_get_string(&b, &len);
1072 if ((session_id2 == NULL) ||
1073 (len != session_id2_len) ||
1074 (memcmp(p, session_id2, session_id2_len) != 0))
1078 if (buffer_get_char(&b) != SSH2_MSG_USERAUTH_REQUEST)
1080 p = buffer_get_string(&b, NULL);
1081 if (strcmp(authctxt->user, p) != 0) {
1082 logit("wrong user name passed to monitor: expected %s != %.100s",
1087 buffer_skip_string(&b); /* service */
1088 p = buffer_get_string(&b, NULL);
1089 if (strcmp(p, "hostbased") != 0)
1092 buffer_skip_string(&b); /* pkalg */
1093 buffer_skip_string(&b); /* pkblob */
1095 /* verify client host, strip trailing dot if necessary */
1096 p = buffer_get_string(&b, NULL);
1097 if (((len = strlen(p)) > 0) && p[len - 1] == '.')
1099 if (strcmp(p, chost) != 0)
1103 /* verify client user */
1104 p = buffer_get_string(&b, NULL);
1105 if (strcmp(p, cuser) != 0)
1109 if (buffer_len(&b) != 0)
1116 mm_answer_keyverify(int socket, Buffer *m)
1119 u_char *signature, *data, *blob;
1120 u_int signaturelen, datalen, bloblen;
1124 blob = buffer_get_string(m, &bloblen);
1125 signature = buffer_get_string(m, &signaturelen);
1126 data = buffer_get_string(m, &datalen);
1128 if (hostbased_cuser == NULL || hostbased_chost == NULL ||
1129 !monitor_allowed_key(blob, bloblen))
1130 fatal("%s: bad key, not previously allowed", __func__);
1132 key = key_from_blob(blob, bloblen);
1134 fatal("%s: bad public key blob", __func__);
1136 switch (key_blobtype) {
1138 valid_data = monitor_valid_userblob(data, datalen);
1141 valid_data = monitor_valid_hostbasedblob(data, datalen,
1142 hostbased_cuser, hostbased_chost);
1149 fatal("%s: bad signature data blob", __func__);
1151 verified = key_verify(key, signature, signaturelen, data, datalen);
1152 debug3("%s: key %p signature %s",
1153 __func__, key, verified ? "verified" : "unverified");
1160 auth_method = key_blobtype == MM_USERKEY ? "publickey" : "hostbased";
1162 monitor_reset_key_state();
1165 buffer_put_int(m, verified);
1166 mm_request_send(socket, MONITOR_ANS_KEYVERIFY, m);
1172 mm_record_login(Session *s, struct passwd *pw)
1175 struct sockaddr_storage from;
1178 * Get IP address of client. If the connection is not a socket, let
1179 * the address be 0.0.0.0.
1181 memset(&from, 0, sizeof(from));
1182 fromlen = sizeof(from);
1183 if (packet_connection_is_on_socket()) {
1184 if (getpeername(packet_get_connection_in(),
1185 (struct sockaddr *) & from, &fromlen) < 0) {
1186 debug("getpeername: %.100s", strerror(errno));
1190 /* Record that there was a login on that tty from the remote host. */
1191 record_login(s->pid, s->tty, pw->pw_name, pw->pw_uid,
1192 get_remote_name_or_ip(utmp_len, options.use_dns),
1193 (struct sockaddr *)&from, fromlen);
1197 mm_session_close(Session *s)
1199 debug3("%s: session %d pid %ld", __func__, s->self, (long)s->pid);
1200 if (s->ttyfd != -1) {
1201 debug3("%s: tty %s ptyfd %d", __func__, s->tty, s->ptyfd);
1202 session_pty_cleanup2(s);
1208 mm_answer_pty(int socket, Buffer *m)
1210 extern struct monitor *pmonitor;
1214 debug3("%s entering", __func__);
1220 s->authctxt = authctxt;
1221 s->pw = authctxt->pw;
1222 s->pid = pmonitor->m_pid;
1223 res = pty_allocate(&s->ptyfd, &s->ttyfd, s->tty, sizeof(s->tty));
1226 pty_setowner(authctxt->pw, s->tty);
1228 buffer_put_int(m, 1);
1229 buffer_put_cstring(m, s->tty);
1230 mm_request_send(socket, MONITOR_ANS_PTY, m);
1232 mm_send_fd(socket, s->ptyfd);
1233 mm_send_fd(socket, s->ttyfd);
1235 /* We need to trick ttyslot */
1236 if (dup2(s->ttyfd, 0) == -1)
1237 fatal("%s: dup2", __func__);
1239 mm_record_login(s, authctxt->pw);
1241 /* Now we can close the file descriptor again */
1244 /* make sure nothing uses fd 0 */
1245 if ((fd0 = open(_PATH_DEVNULL, O_RDONLY)) < 0)
1246 fatal("%s: open(/dev/null): %s", __func__, strerror(errno));
1248 error("%s: fd0 %d != 0", __func__, fd0);
1250 /* slave is not needed */
1252 s->ttyfd = s->ptyfd;
1253 /* no need to dup() because nobody closes ptyfd */
1254 s->ptymaster = s->ptyfd;
1256 debug3("%s: tty %s ptyfd %d", __func__, s->tty, s->ttyfd);
1262 mm_session_close(s);
1263 buffer_put_int(m, 0);
1264 mm_request_send(socket, MONITOR_ANS_PTY, m);
1269 mm_answer_pty_cleanup(int socket, Buffer *m)
1274 debug3("%s entering", __func__);
1276 tty = buffer_get_string(m, NULL);
1277 if ((s = session_by_tty(tty)) != NULL)
1278 mm_session_close(s);
1285 mm_answer_sesskey(int socket, Buffer *m)
1290 /* Turn off permissions */
1291 monitor_permit(mon_dispatch, MONITOR_REQ_SESSKEY, 1);
1293 if ((p = BN_new()) == NULL)
1294 fatal("%s: BN_new", __func__);
1296 buffer_get_bignum2(m, p);
1298 rsafail = ssh1_session_key(p);
1301 buffer_put_int(m, rsafail);
1302 buffer_put_bignum2(m, p);
1306 mm_request_send(socket, MONITOR_ANS_SESSKEY, m);
1308 /* Turn on permissions for sessid passing */
1309 monitor_permit(mon_dispatch, MONITOR_REQ_SESSID, 1);
1315 mm_answer_sessid(int socket, Buffer *m)
1319 debug3("%s entering", __func__);
1321 if (buffer_len(m) != 16)
1322 fatal("%s: bad ssh1 session id", __func__);
1323 for (i = 0; i < 16; i++)
1324 session_id[i] = buffer_get_char(m);
1326 /* Turn on permissions for getpwnam */
1327 monitor_permit(mon_dispatch, MONITOR_REQ_PWNAM, 1);
1333 mm_answer_rsa_keyallowed(int socket, Buffer *m)
1337 u_char *blob = NULL;
1341 debug3("%s entering", __func__);
1343 if (options.rsa_authentication && authctxt->valid) {
1344 if ((client_n = BN_new()) == NULL)
1345 fatal("%s: BN_new", __func__);
1346 buffer_get_bignum2(m, client_n);
1347 allowed = auth_rsa_key_allowed(authctxt->pw, client_n, &key);
1348 BN_clear_free(client_n);
1351 buffer_put_int(m, allowed);
1352 buffer_put_int(m, forced_command != NULL);
1354 /* clear temporarily storage (used by generate challenge) */
1355 monitor_reset_key_state();
1357 if (allowed && key != NULL) {
1358 key->type = KEY_RSA; /* cheat for key_to_blob */
1359 if (key_to_blob(key, &blob, &blen) == 0)
1360 fatal("%s: key_to_blob failed", __func__);
1361 buffer_put_string(m, blob, blen);
1363 /* Save temporarily for comparison in verify */
1366 key_blobtype = MM_RSAUSERKEY;
1373 mm_request_send(socket, MONITOR_ANS_RSAKEYALLOWED, m);
1375 monitor_permit(mon_dispatch, MONITOR_REQ_RSACHALLENGE, allowed);
1376 monitor_permit(mon_dispatch, MONITOR_REQ_RSARESPONSE, 0);
1381 mm_answer_rsa_challenge(int socket, Buffer *m)
1387 debug3("%s entering", __func__);
1389 if (!authctxt->valid)
1390 fatal("%s: authctxt not valid", __func__);
1391 blob = buffer_get_string(m, &blen);
1392 if (!monitor_allowed_key(blob, blen))
1393 fatal("%s: bad key, not previously allowed", __func__);
1394 if (key_blobtype != MM_RSAUSERKEY && key_blobtype != MM_RSAHOSTKEY)
1395 fatal("%s: key type mismatch", __func__);
1396 if ((key = key_from_blob(blob, blen)) == NULL)
1397 fatal("%s: received bad key", __func__);
1400 BN_clear_free(ssh1_challenge);
1401 ssh1_challenge = auth_rsa_generate_challenge(key);
1404 buffer_put_bignum2(m, ssh1_challenge);
1406 debug3("%s sending reply", __func__);
1407 mm_request_send(socket, MONITOR_ANS_RSACHALLENGE, m);
1409 monitor_permit(mon_dispatch, MONITOR_REQ_RSARESPONSE, 1);
1417 mm_answer_rsa_response(int socket, Buffer *m)
1420 u_char *blob, *response;
1424 debug3("%s entering", __func__);
1426 if (!authctxt->valid)
1427 fatal("%s: authctxt not valid", __func__);
1428 if (ssh1_challenge == NULL)
1429 fatal("%s: no ssh1_challenge", __func__);
1431 blob = buffer_get_string(m, &blen);
1432 if (!monitor_allowed_key(blob, blen))
1433 fatal("%s: bad key, not previously allowed", __func__);
1434 if (key_blobtype != MM_RSAUSERKEY && key_blobtype != MM_RSAHOSTKEY)
1435 fatal("%s: key type mismatch: %d", __func__, key_blobtype);
1436 if ((key = key_from_blob(blob, blen)) == NULL)
1437 fatal("%s: received bad key", __func__);
1438 response = buffer_get_string(m, &len);
1440 fatal("%s: received bad response to challenge", __func__);
1441 success = auth_rsa_verify_response(key, ssh1_challenge, response);
1447 auth_method = key_blobtype == MM_RSAUSERKEY ? "rsa" : "rhosts-rsa";
1450 BN_clear_free(ssh1_challenge);
1451 ssh1_challenge = NULL;
1452 monitor_reset_key_state();
1455 buffer_put_int(m, success);
1456 mm_request_send(socket, MONITOR_ANS_RSARESPONSE, m);
1462 mm_answer_term(int socket, Buffer *req)
1464 extern struct monitor *pmonitor;
1467 debug3("%s: tearing down sessions", __func__);
1469 /* The child is terminating */
1470 session_destroy_all(&mm_session_close);
1472 while (waitpid(pmonitor->m_pid, &status, 0) == -1)
1476 res = WIFEXITED(status) ? WEXITSTATUS(status) : 1;
1478 /* Terminate process */
1483 monitor_apply_keystate(struct monitor *pmonitor)
1486 set_newkeys(MODE_IN);
1487 set_newkeys(MODE_OUT);
1489 packet_set_protocol_flags(child_state.ssh1protoflags);
1490 packet_set_encryption_key(child_state.ssh1key,
1491 child_state.ssh1keylen, child_state.ssh1cipher);
1492 xfree(child_state.ssh1key);
1495 /* for rc4 and other stateful ciphers */
1496 packet_set_keycontext(MODE_OUT, child_state.keyout);
1497 xfree(child_state.keyout);
1498 packet_set_keycontext(MODE_IN, child_state.keyin);
1499 xfree(child_state.keyin);
1502 packet_set_iv(MODE_OUT, child_state.ivout);
1503 xfree(child_state.ivout);
1504 packet_set_iv(MODE_IN, child_state.ivin);
1505 xfree(child_state.ivin);
1508 memcpy(&incoming_stream, &child_state.incoming,
1509 sizeof(incoming_stream));
1510 memcpy(&outgoing_stream, &child_state.outgoing,
1511 sizeof(outgoing_stream));
1513 /* Update with new address */
1514 if (options.compression)
1515 mm_init_compression(pmonitor->m_zlib);
1517 /* Network I/O buffers */
1518 /* XXX inefficient for large buffers, need: buffer_init_from_string */
1519 buffer_clear(&input);
1520 buffer_append(&input, child_state.input, child_state.ilen);
1521 memset(child_state.input, 0, child_state.ilen);
1522 xfree(child_state.input);
1524 buffer_clear(&output);
1525 buffer_append(&output, child_state.output, child_state.olen);
1526 memset(child_state.output, 0, child_state.olen);
1527 xfree(child_state.output);
1531 mm_get_kex(Buffer *m)
1537 kex = xmalloc(sizeof(*kex));
1538 memset(kex, 0, sizeof(*kex));
1539 kex->session_id = buffer_get_string(m, &kex->session_id_len);
1540 if ((session_id2 == NULL) ||
1541 (kex->session_id_len != session_id2_len) ||
1542 (memcmp(kex->session_id, session_id2, session_id2_len) != 0))
1543 fatal("mm_get_get: internal error: bad session id");
1544 kex->we_need = buffer_get_int(m);
1545 kex->kex[KEX_DH_GRP1_SHA1] = kexdh_server;
1546 kex->kex[KEX_DH_GEX_SHA1] = kexgex_server;
1548 kex->hostkey_type = buffer_get_int(m);
1549 kex->kex_type = buffer_get_int(m);
1550 blob = buffer_get_string(m, &bloblen);
1551 buffer_init(&kex->my);
1552 buffer_append(&kex->my, blob, bloblen);
1554 blob = buffer_get_string(m, &bloblen);
1555 buffer_init(&kex->peer);
1556 buffer_append(&kex->peer, blob, bloblen);
1559 kex->flags = buffer_get_int(m);
1560 kex->client_version_string = buffer_get_string(m, NULL);
1561 kex->server_version_string = buffer_get_string(m, NULL);
1562 kex->load_host_key=&get_hostkey_by_type;
1563 kex->host_key_index=&get_hostkey_index;
1568 /* This function requries careful sanity checking */
1571 mm_get_keystate(struct monitor *pmonitor)
1575 u_int bloblen, plen;
1576 u_int32_t seqnr, packets;
1579 debug3("%s: Waiting for new keys", __func__);
1582 mm_request_receive_expect(pmonitor->m_sendfd, MONITOR_REQ_KEYEXPORT, &m);
1584 child_state.ssh1protoflags = buffer_get_int(&m);
1585 child_state.ssh1cipher = buffer_get_int(&m);
1586 child_state.ssh1key = buffer_get_string(&m,
1587 &child_state.ssh1keylen);
1588 child_state.ivout = buffer_get_string(&m,
1589 &child_state.ivoutlen);
1590 child_state.ivin = buffer_get_string(&m, &child_state.ivinlen);
1593 /* Get the Kex for rekeying */
1594 *pmonitor->m_pkex = mm_get_kex(&m);
1597 blob = buffer_get_string(&m, &bloblen);
1598 current_keys[MODE_OUT] = mm_newkeys_from_blob(blob, bloblen);
1601 debug3("%s: Waiting for second key", __func__);
1602 blob = buffer_get_string(&m, &bloblen);
1603 current_keys[MODE_IN] = mm_newkeys_from_blob(blob, bloblen);
1606 /* Now get sequence numbers for the packets */
1607 seqnr = buffer_get_int(&m);
1608 blocks = buffer_get_int64(&m);
1609 packets = buffer_get_int(&m);
1610 packet_set_state(MODE_OUT, seqnr, blocks, packets);
1611 seqnr = buffer_get_int(&m);
1612 blocks = buffer_get_int64(&m);
1613 packets = buffer_get_int(&m);
1614 packet_set_state(MODE_IN, seqnr, blocks, packets);
1617 /* Get the key context */
1618 child_state.keyout = buffer_get_string(&m, &child_state.keyoutlen);
1619 child_state.keyin = buffer_get_string(&m, &child_state.keyinlen);
1621 debug3("%s: Getting compression state", __func__);
1622 /* Get compression state */
1623 p = buffer_get_string(&m, &plen);
1624 if (plen != sizeof(child_state.outgoing))
1625 fatal("%s: bad request size", __func__);
1626 memcpy(&child_state.outgoing, p, sizeof(child_state.outgoing));
1629 p = buffer_get_string(&m, &plen);
1630 if (plen != sizeof(child_state.incoming))
1631 fatal("%s: bad request size", __func__);
1632 memcpy(&child_state.incoming, p, sizeof(child_state.incoming));
1635 /* Network I/O buffers */
1636 debug3("%s: Getting Network I/O buffers", __func__);
1637 child_state.input = buffer_get_string(&m, &child_state.ilen);
1638 child_state.output = buffer_get_string(&m, &child_state.olen);
1644 /* Allocation functions for zlib */
1646 mm_zalloc(struct mm_master *mm, u_int ncount, u_int size)
1648 size_t len = (size_t) size * ncount;
1651 if (len == 0 || ncount > SIZE_T_MAX / size)
1652 fatal("%s: mm_zalloc(%u, %u)", __func__, ncount, size);
1654 address = mm_malloc(mm, len);
1660 mm_zfree(struct mm_master *mm, void *address)
1662 mm_free(mm, address);
1666 mm_init_compression(struct mm_master *mm)
1668 outgoing_stream.zalloc = (alloc_func)mm_zalloc;
1669 outgoing_stream.zfree = (free_func)mm_zfree;
1670 outgoing_stream.opaque = mm;
1672 incoming_stream.zalloc = (alloc_func)mm_zalloc;
1673 incoming_stream.zfree = (free_func)mm_zfree;
1674 incoming_stream.opaque = mm;
1679 #define FD_CLOSEONEXEC(x) do { \
1680 if (fcntl(x, F_SETFD, 1) == -1) \
1681 fatal("fcntl(%d, F_SETFD)", x); \
1685 monitor_socketpair(int *pair)
1687 #ifdef HAVE_SOCKETPAIR
1688 if (socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1)
1689 fatal("%s: socketpair", __func__);
1691 fatal("%s: UsePrivilegeSeparation=yes not supported",
1694 FD_CLOSEONEXEC(pair[0]);
1695 FD_CLOSEONEXEC(pair[1]);
1698 #define MM_MEMSIZE 65536
1703 struct monitor *mon;
1706 mon = xmalloc(sizeof(*mon));
1708 monitor_socketpair(pair);
1710 mon->m_recvfd = pair[0];
1711 mon->m_sendfd = pair[1];
1713 /* Used to share zlib space across processes */
1714 if (options.compression) {
1715 mon->m_zback = mm_create(NULL, MM_MEMSIZE);
1716 mon->m_zlib = mm_create(mon->m_zback, 20 * MM_MEMSIZE);
1718 /* Compression needs to share state across borders */
1719 mm_init_compression(mon->m_zlib);
1726 monitor_reinit(struct monitor *mon)
1730 monitor_socketpair(pair);
1732 mon->m_recvfd = pair[0];
1733 mon->m_sendfd = pair[1];
1738 mm_answer_gss_setup_ctx(int socket, Buffer *m)
1744 oid.elements = buffer_get_string(m, &len);
1747 major = ssh_gssapi_server_ctx(&gsscontext, &oid);
1749 xfree(oid.elements);
1752 buffer_put_int(m, major);
1754 mm_request_send(socket,MONITOR_ANS_GSSSETUP, m);
1756 /* Now we have a context, enable the step */
1757 monitor_permit(mon_dispatch, MONITOR_REQ_GSSSTEP, 1);
1763 mm_answer_gss_accept_ctx(int socket, Buffer *m)
1766 gss_buffer_desc out = GSS_C_EMPTY_BUFFER;
1767 OM_uint32 major,minor;
1768 OM_uint32 flags = 0; /* GSI needs this */
1771 in.value = buffer_get_string(m, &len);
1773 major = ssh_gssapi_accept_ctx(gsscontext, &in, &out, &flags);
1777 buffer_put_int(m, major);
1778 buffer_put_string(m, out.value, out.length);
1779 buffer_put_int(m, flags);
1780 mm_request_send(socket, MONITOR_ANS_GSSSTEP, m);
1782 gss_release_buffer(&minor, &out);
1784 /* Complete - now we can do signing */
1785 if (major==GSS_S_COMPLETE) {
1786 monitor_permit(mon_dispatch, MONITOR_REQ_GSSSTEP, 0);
1787 monitor_permit(mon_dispatch, MONITOR_REQ_GSSUSEROK, 1);
1793 mm_answer_gss_userok(int socket, Buffer *m)
1797 authenticated = authctxt->valid && ssh_gssapi_userok(authctxt->user);
1800 buffer_put_int(m, authenticated);
1802 debug3("%s: sending result %d", __func__, authenticated);
1803 mm_request_send(socket, MONITOR_ANS_GSSUSEROK, m);
1805 auth_method="gssapi";
1807 /* Monitor loop will terminate if authenticated */
1808 return (authenticated);