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.36 2003/04/01 10:22:21 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 montior 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 *);
129 int mm_answer_krb4(int, Buffer *);
132 int mm_answer_krb5(int, Buffer *);
136 int mm_answer_gss_setup_ctx(int, Buffer *);
137 int mm_answer_gss_accept_ctx(int, Buffer *);
138 int mm_answer_gss_userok(int, Buffer *);
139 int mm_answer_gss_sign(int, Buffer *);
140 int mm_answer_gss_error(int, Buffer *);
141 int mm_answer_gss_indicate_mechs(int, Buffer *);
142 int mm_answer_gss_localname(int, Buffer *);
145 static Authctxt *authctxt;
146 static BIGNUM *ssh1_challenge = NULL; /* used for ssh1 rsa auth */
148 /* local state for key verify */
149 static u_char *key_blob = NULL;
150 static u_int key_bloblen = 0;
151 static int key_blobtype = MM_NOKEY;
152 static char *hostbased_cuser = NULL;
153 static char *hostbased_chost = NULL;
154 static char *auth_method = "unknown";
155 static int session_id2_len = 0;
156 static u_char *session_id2 = NULL;
159 enum monitor_reqtype type;
161 int (*f)(int, Buffer *);
164 #define MON_ISAUTH 0x0004 /* Required for Authentication */
165 #define MON_AUTHDECIDE 0x0008 /* Decides Authentication */
166 #define MON_ONCE 0x0010 /* Disable after calling */
168 #define MON_AUTH (MON_ISAUTH|MON_AUTHDECIDE)
170 #define MON_PERMIT 0x1000 /* Request is permitted */
172 struct mon_table mon_dispatch_proto20[] = {
173 {MONITOR_REQ_MODULI, MON_ONCE, mm_answer_moduli},
174 {MONITOR_REQ_SIGN, MON_ONCE, mm_answer_sign},
175 {MONITOR_REQ_PWNAM, MON_ONCE, mm_answer_pwnamallow},
176 {MONITOR_REQ_AUTHSERV, MON_ONCE, mm_answer_authserv},
177 {MONITOR_REQ_AUTH2_READ_BANNER, MON_ONCE, mm_answer_auth2_read_banner},
178 {MONITOR_REQ_AUTHPASSWORD, MON_AUTH, mm_answer_authpassword},
180 {MONITOR_REQ_PAM_START, MON_ONCE, mm_answer_pam_start},
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},
191 {MONITOR_REQ_GSSSETUP, MON_ISAUTH, mm_answer_gss_setup_ctx},
192 {MONITOR_REQ_GSSSTEP, MON_ISAUTH, mm_answer_gss_accept_ctx},
193 {MONITOR_REQ_GSSSIGN, MON_ONCE, mm_answer_gss_sign},
194 {MONITOR_REQ_GSSERR, MON_ISAUTH | MON_ONCE, mm_answer_gss_error},
195 {MONITOR_REQ_GSSMECHS, MON_ISAUTH, mm_answer_gss_indicate_mechs},
196 {MONITOR_REQ_GSSUSEROK, MON_AUTH, mm_answer_gss_userok},
197 /* Turn this off until we use it */
199 {MONITOR_REQ_GSSLOCALNAME, MON_ISAUTH, mm_answer_gss_localname},
202 {MONITOR_REQ_KEYALLOWED, MON_ISAUTH, mm_answer_keyallowed},
203 {MONITOR_REQ_KEYVERIFY, MON_AUTH, mm_answer_keyverify},
207 struct mon_table mon_dispatch_postauth20[] = {
209 {MONITOR_REQ_GSSSETUP, 0, mm_answer_gss_setup_ctx},
210 {MONITOR_REQ_GSSSTEP, 0, mm_answer_gss_accept_ctx},
211 {MONITOR_REQ_GSSSIGN, 0, mm_answer_gss_sign},
212 {MONITOR_REQ_GSSERR, 0, mm_answer_gss_error},
213 {MONITOR_REQ_GSSMECHS, 0, mm_answer_gss_indicate_mechs},
215 {MONITOR_REQ_MODULI, 0, mm_answer_moduli},
216 {MONITOR_REQ_SIGN, 0, mm_answer_sign},
217 {MONITOR_REQ_PTY, 0, mm_answer_pty},
218 {MONITOR_REQ_PTYCLEANUP, 0, mm_answer_pty_cleanup},
219 {MONITOR_REQ_TERM, 0, mm_answer_term},
223 struct mon_table mon_dispatch_proto15[] = {
224 {MONITOR_REQ_PWNAM, MON_ONCE, mm_answer_pwnamallow},
225 {MONITOR_REQ_SESSKEY, MON_ONCE, mm_answer_sesskey},
226 {MONITOR_REQ_SESSID, MON_ONCE, mm_answer_sessid},
227 {MONITOR_REQ_AUTHPASSWORD, MON_AUTH, mm_answer_authpassword},
228 {MONITOR_REQ_RSAKEYALLOWED, MON_ISAUTH, mm_answer_rsa_keyallowed},
229 {MONITOR_REQ_KEYALLOWED, MON_ISAUTH, mm_answer_keyallowed},
230 {MONITOR_REQ_RSACHALLENGE, MON_ONCE, mm_answer_rsa_challenge},
231 {MONITOR_REQ_RSARESPONSE, MON_ONCE|MON_AUTHDECIDE, mm_answer_rsa_response},
233 {MONITOR_REQ_BSDAUTHQUERY, MON_ISAUTH, mm_answer_bsdauthquery},
234 {MONITOR_REQ_BSDAUTHRESPOND, MON_AUTH,mm_answer_bsdauthrespond},
237 {MONITOR_REQ_SKEYQUERY, MON_ISAUTH, mm_answer_skeyquery},
238 {MONITOR_REQ_SKEYRESPOND, MON_AUTH, mm_answer_skeyrespond},
241 {MONITOR_REQ_PAM_START, MON_ONCE, mm_answer_pam_start},
244 {MONITOR_REQ_KRB4, MON_ONCE|MON_AUTH, mm_answer_krb4},
247 {MONITOR_REQ_KRB5, MON_ONCE|MON_AUTH, mm_answer_krb5},
252 struct mon_table mon_dispatch_postauth15[] = {
253 {MONITOR_REQ_PTY, MON_ONCE, mm_answer_pty},
254 {MONITOR_REQ_PTYCLEANUP, MON_ONCE, mm_answer_pty_cleanup},
255 {MONITOR_REQ_TERM, 0, mm_answer_term},
259 struct mon_table *mon_dispatch;
261 /* Specifies if a certain message is allowed at the moment */
264 monitor_permit(struct mon_table *ent, enum monitor_reqtype type, int permit)
266 while (ent->f != NULL) {
267 if (ent->type == type) {
268 ent->flags &= ~MON_PERMIT;
269 ent->flags |= permit ? MON_PERMIT : 0;
277 monitor_permit_authentications(int permit)
279 struct mon_table *ent = mon_dispatch;
281 while (ent->f != NULL) {
282 if (ent->flags & MON_AUTH) {
283 ent->flags &= ~MON_PERMIT;
284 ent->flags |= permit ? MON_PERMIT : 0;
291 monitor_child_preauth(struct monitor *pmonitor)
293 struct mon_table *ent;
294 int authenticated = 0;
296 debug3("preauth child monitor started");
299 mon_dispatch = mon_dispatch_proto20;
301 /* Permit requests for moduli and signatures */
302 monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1);
303 monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1);
305 /* and for the GSSAPI key exchange */
306 monitor_permit(mon_dispatch, MONITOR_REQ_GSSSETUP, 1);
307 monitor_permit(mon_dispatch, MONITOR_REQ_GSSERR, 1);
308 monitor_permit(mon_dispatch, MONITOR_REQ_GSSMECHS, 1);
311 mon_dispatch = mon_dispatch_proto15;
313 monitor_permit(mon_dispatch, MONITOR_REQ_SESSKEY, 1);
316 authctxt = authctxt_new();
318 /* The first few requests do not require asynchronous access */
319 while (!authenticated) {
320 authenticated = monitor_read(pmonitor, mon_dispatch, &ent);
322 if (!(ent->flags & MON_AUTHDECIDE))
323 fatal("%s: unexpected authentication from %d",
324 __func__, ent->type);
325 if (authctxt->pw->pw_uid == 0 &&
326 !auth_root_allowed(auth_method))
329 if (!do_pam_account(authctxt->pw->pw_name, NULL))
334 if (ent->flags & MON_AUTHDECIDE) {
335 auth_log(authctxt, authenticated, auth_method,
336 compat20 ? " ssh2" : "");
338 authctxt->failures++;
342 if (!authctxt->valid)
343 fatal("%s: authenticated invalid user", __func__);
345 debug("%s: %s has been authenticated by privileged process",
346 __func__, authctxt->user);
348 mm_get_keystate(pmonitor);
354 monitor_child_postauth(struct monitor *pmonitor)
357 mon_dispatch = mon_dispatch_postauth20;
359 /* Permit requests for moduli and signatures */
360 monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1);
361 monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1);
362 monitor_permit(mon_dispatch, MONITOR_REQ_TERM, 1);
365 /* and for the GSSAPI key exchange */
366 monitor_permit(mon_dispatch, MONITOR_REQ_GSSMECHS,1);
367 monitor_permit(mon_dispatch, MONITOR_REQ_GSSSETUP,1);
368 monitor_permit(mon_dispatch, MONITOR_REQ_GSSERR,1);
372 mon_dispatch = mon_dispatch_postauth15;
373 monitor_permit(mon_dispatch, MONITOR_REQ_TERM, 1);
376 monitor_permit(mon_dispatch, MONITOR_REQ_PTY, 1);
377 monitor_permit(mon_dispatch, MONITOR_REQ_PTYCLEANUP, 1);
381 monitor_read(pmonitor, mon_dispatch, NULL);
385 monitor_sync(struct monitor *pmonitor)
387 if (options.compression) {
388 /* The member allocation is not visible, so sync it */
389 mm_share_sync(&pmonitor->m_zlib, &pmonitor->m_zback);
394 monitor_read(struct monitor *pmonitor, struct mon_table *ent,
395 struct mon_table **pent)
403 mm_request_receive(pmonitor->m_sendfd, &m);
404 type = buffer_get_char(&m);
406 debug3("%s: checking request %d", __func__, type);
408 while (ent->f != NULL) {
409 if (ent->type == type)
414 if (ent->f != NULL) {
415 if (!(ent->flags & MON_PERMIT))
416 fatal("%s: unpermitted request %d", __func__,
418 ret = (*ent->f)(pmonitor->m_sendfd, &m);
421 /* The child may use this request only once, disable it */
422 if (ent->flags & MON_ONCE) {
423 debug2("%s: %d used once, disabling now", __func__,
425 ent->flags &= ~MON_PERMIT;
434 fatal("%s: unsupported request: %d", __func__, type);
440 /* allowed key state */
442 monitor_allowed_key(u_char *blob, u_int bloblen)
444 /* make sure key is allowed */
445 if (key_blob == NULL || key_bloblen != bloblen ||
446 memcmp(key_blob, blob, key_bloblen))
452 monitor_reset_key_state(void)
455 if (key_blob != NULL)
457 if (hostbased_cuser != NULL)
458 xfree(hostbased_cuser);
459 if (hostbased_chost != NULL)
460 xfree(hostbased_chost);
463 key_blobtype = MM_NOKEY;
464 hostbased_cuser = NULL;
465 hostbased_chost = NULL;
469 mm_answer_moduli(int socket, Buffer *m)
474 min = buffer_get_int(m);
475 want = buffer_get_int(m);
476 max = buffer_get_int(m);
478 debug3("%s: got parameters: %d %d %d",
479 __func__, min, want, max);
480 /* We need to check here, too, in case the child got corrupted */
481 if (max < min || want < min || max < want)
482 fatal("%s: bad parameters: %d %d %d",
483 __func__, min, want, max);
487 dh = choose_dh(min, want, max);
489 buffer_put_char(m, 0);
492 /* Send first bignum */
493 buffer_put_char(m, 1);
494 buffer_put_bignum2(m, dh->p);
495 buffer_put_bignum2(m, dh->g);
499 mm_request_send(socket, MONITOR_ANS_MODULI, m);
504 mm_answer_sign(int socket, Buffer *m)
509 u_int siglen, datlen;
512 debug3("%s", __func__);
514 keyid = buffer_get_int(m);
515 p = buffer_get_string(m, &datlen);
518 fatal("%s: data length incorrect: %u", __func__, datlen);
520 /* save session id, it will be passed on the first call */
521 if (session_id2_len == 0) {
522 session_id2_len = datlen;
523 session_id2 = xmalloc(session_id2_len);
524 memcpy(session_id2, p, session_id2_len);
527 if ((key = get_hostkey_by_index(keyid)) == NULL)
528 fatal("%s: no hostkey from index %d", __func__, keyid);
529 if (key_sign(key, &signature, &siglen, p, datlen) < 0)
530 fatal("%s: key_sign failed", __func__);
532 debug3("%s: signature %p(%u)", __func__, signature, siglen);
535 buffer_put_string(m, signature, siglen);
540 mm_request_send(socket, MONITOR_ANS_SIGN, m);
542 /* Turn on permissions for getpwnam */
543 monitor_permit(mon_dispatch, MONITOR_REQ_PWNAM, 1);
548 /* Retrieves the password entry and also checks if the user is permitted */
551 mm_answer_pwnamallow(int socket, Buffer *m)
554 struct passwd *pwent;
557 debug3("%s", __func__);
559 if (authctxt->attempt++ != 0)
560 fatal("%s: multiple attempts for getpwnam", __func__);
562 login = buffer_get_string(m, NULL);
564 pwent = getpwnamallow(login);
566 authctxt->user = xstrdup(login);
567 setproctitle("%s [priv]", pwent ? login : "unknown");
573 buffer_put_char(m, 0);
578 authctxt->pw = pwent;
581 buffer_put_char(m, 1);
582 buffer_put_string(m, pwent, sizeof(struct passwd));
583 buffer_put_cstring(m, pwent->pw_name);
584 buffer_put_cstring(m, "*");
585 buffer_put_cstring(m, pwent->pw_gecos);
586 #ifdef HAVE_PW_CLASS_IN_PASSWD
587 buffer_put_cstring(m, pwent->pw_class);
589 buffer_put_cstring(m, pwent->pw_dir);
590 buffer_put_cstring(m, pwent->pw_shell);
593 debug3("%s: sending MONITOR_ANS_PWNAM: %d", __func__, allowed);
594 mm_request_send(socket, MONITOR_ANS_PWNAM, m);
596 /* For SSHv1 allow authentication now */
598 monitor_permit_authentications(1);
600 /* Allow service/style information on the auth context */
601 monitor_permit(mon_dispatch, MONITOR_REQ_AUTHSERV, 1);
602 monitor_permit(mon_dispatch, MONITOR_REQ_AUTH2_READ_BANNER, 1);
606 monitor_permit(mon_dispatch, MONITOR_REQ_PAM_START, 1);
612 int mm_answer_auth2_read_banner(int socket, Buffer *m)
617 banner = auth2_read_banner();
618 buffer_put_cstring(m, banner != NULL ? banner : "");
619 mm_request_send(socket, MONITOR_ANS_AUTH2_READ_BANNER, m);
628 mm_answer_authserv(int socket, Buffer *m)
630 monitor_permit_authentications(1);
632 authctxt->service = buffer_get_string(m, NULL);
633 authctxt->style = buffer_get_string(m, NULL);
634 debug3("%s: service=%s, style=%s",
635 __func__, authctxt->service, authctxt->style);
637 if (strlen(authctxt->style) == 0) {
638 xfree(authctxt->style);
639 authctxt->style = NULL;
646 mm_answer_authpassword(int socket, Buffer *m)
648 static int call_count;
653 passwd = buffer_get_string(m, &plen);
654 /* Only authenticate if the context is valid */
655 authenticated = options.password_authentication &&
656 authctxt->valid && auth_password(authctxt, passwd);
657 memset(passwd, 0, strlen(passwd));
661 buffer_put_int(m, authenticated);
663 debug3("%s: sending result %d", __func__, authenticated);
664 mm_request_send(socket, MONITOR_ANS_AUTHPASSWORD, m);
667 if (plen == 0 && call_count == 1)
668 auth_method = "none";
670 auth_method = "password";
672 /* Causes monitor loop to terminate if authenticated */
673 return (authenticated);
678 mm_answer_bsdauthquery(int socket, Buffer *m)
680 char *name, *infotxt;
686 success = bsdauth_query(authctxt, &name, &infotxt, &numprompts,
687 &prompts, &echo_on) < 0 ? 0 : 1;
690 buffer_put_int(m, success);
692 buffer_put_cstring(m, prompts[0]);
694 debug3("%s: sending challenge success: %u", __func__, success);
695 mm_request_send(socket, MONITOR_ANS_BSDAUTHQUERY, m);
708 mm_answer_bsdauthrespond(int socket, Buffer *m)
713 if (authctxt->as == 0)
714 fatal("%s: no bsd auth session", __func__);
716 response = buffer_get_string(m, NULL);
717 authok = options.challenge_response_authentication &&
718 auth_userresponse(authctxt->as, response, 0);
720 debug3("%s: <%s> = <%d>", __func__, response, authok);
724 buffer_put_int(m, authok);
726 debug3("%s: sending authenticated: %d", __func__, authok);
727 mm_request_send(socket, MONITOR_ANS_BSDAUTHRESPOND, m);
729 auth_method = "bsdauth";
731 return (authok != 0);
737 mm_answer_skeyquery(int socket, Buffer *m)
740 char challenge[1024];
743 success = skeychallenge(&skey, authctxt->user, challenge) < 0 ? 0 : 1;
746 buffer_put_int(m, success);
748 buffer_put_cstring(m, challenge);
750 debug3("%s: sending challenge success: %u", __func__, success);
751 mm_request_send(socket, MONITOR_ANS_SKEYQUERY, m);
757 mm_answer_skeyrespond(int socket, Buffer *m)
762 response = buffer_get_string(m, NULL);
764 authok = (options.challenge_response_authentication &&
766 skey_haskey(authctxt->pw->pw_name) == 0 &&
767 skey_passcheck(authctxt->pw->pw_name, response) != -1);
772 buffer_put_int(m, authok);
774 debug3("%s: sending authenticated: %d", __func__, authok);
775 mm_request_send(socket, MONITOR_ANS_SKEYRESPOND, m);
777 auth_method = "skey";
779 return (authok != 0);
785 mm_answer_pam_start(int socket, Buffer *m)
789 user = buffer_get_string(m, NULL);
800 mm_append_debug(Buffer *m)
802 if (auth_debug_init && buffer_len(&auth_debug)) {
803 debug3("%s: Appending debug messages for child", __func__);
804 buffer_append(m, buffer_ptr(&auth_debug),
805 buffer_len(&auth_debug));
806 buffer_clear(&auth_debug);
811 mm_answer_keyallowed(int socket, Buffer *m)
817 enum mm_keytype type = 0;
820 debug3("%s entering", __func__);
822 type = buffer_get_int(m);
823 cuser = buffer_get_string(m, NULL);
824 chost = buffer_get_string(m, NULL);
825 blob = buffer_get_string(m, &bloblen);
827 key = key_from_blob(blob, bloblen);
829 if ((compat20 && type == MM_RSAHOSTKEY) ||
830 (!compat20 && type != MM_RSAHOSTKEY))
831 fatal("%s: key type and protocol mismatch", __func__);
833 debug3("%s: key_from_blob: %p", __func__, key);
835 if (key != NULL && authctxt->pw != NULL) {
838 allowed = options.pubkey_authentication &&
839 user_key_allowed(authctxt->pw, key);
842 allowed = options.hostbased_authentication &&
843 hostbased_key_allowed(authctxt->pw,
847 key->type = KEY_RSA1; /* XXX */
848 allowed = options.rhosts_rsa_authentication &&
849 auth_rhosts_rsa_key_allowed(authctxt->pw,
853 fatal("%s: unknown key type %d", __func__, type);
860 /* clear temporarily storage (used by verify) */
861 monitor_reset_key_state();
864 /* Save temporarily for comparison in verify */
866 key_bloblen = bloblen;
868 hostbased_cuser = cuser;
869 hostbased_chost = chost;
872 debug3("%s: key %p is %s",
873 __func__, key, allowed ? "allowed" : "disallowed");
876 buffer_put_int(m, allowed);
877 buffer_put_int(m, forced_command != NULL);
881 mm_request_send(socket, MONITOR_ANS_KEYALLOWED, m);
883 if (type == MM_RSAHOSTKEY)
884 monitor_permit(mon_dispatch, MONITOR_REQ_RSACHALLENGE, allowed);
890 monitor_valid_userblob(u_char *data, u_int datalen)
898 buffer_append(&b, data, datalen);
900 if (datafellows & SSH_OLD_SESSIONID) {
902 len = buffer_len(&b);
903 if ((session_id2 == NULL) ||
904 (len < session_id2_len) ||
905 (memcmp(p, session_id2, session_id2_len) != 0))
907 buffer_consume(&b, session_id2_len);
909 p = buffer_get_string(&b, &len);
910 if ((session_id2 == NULL) ||
911 (len != session_id2_len) ||
912 (memcmp(p, session_id2, session_id2_len) != 0))
916 if (buffer_get_char(&b) != SSH2_MSG_USERAUTH_REQUEST)
918 p = buffer_get_string(&b, NULL);
919 if (strcmp(authctxt->user, p) != 0) {
920 log("wrong user name passed to monitor: expected %s != %.100s",
925 buffer_skip_string(&b);
926 if (datafellows & SSH_BUG_PKAUTH) {
927 if (!buffer_get_char(&b))
930 p = buffer_get_string(&b, NULL);
931 if (strcmp("publickey", p) != 0)
934 if (!buffer_get_char(&b))
936 buffer_skip_string(&b);
938 buffer_skip_string(&b);
939 if (buffer_len(&b) != 0)
946 monitor_valid_hostbasedblob(u_char *data, u_int datalen, char *cuser,
955 buffer_append(&b, data, datalen);
957 p = buffer_get_string(&b, &len);
958 if ((session_id2 == NULL) ||
959 (len != session_id2_len) ||
960 (memcmp(p, session_id2, session_id2_len) != 0))
964 if (buffer_get_char(&b) != SSH2_MSG_USERAUTH_REQUEST)
966 p = buffer_get_string(&b, NULL);
967 if (strcmp(authctxt->user, p) != 0) {
968 log("wrong user name passed to monitor: expected %s != %.100s",
973 buffer_skip_string(&b); /* service */
974 p = buffer_get_string(&b, NULL);
975 if (strcmp(p, "hostbased") != 0)
978 buffer_skip_string(&b); /* pkalg */
979 buffer_skip_string(&b); /* pkblob */
981 /* verify client host, strip trailing dot if necessary */
982 p = buffer_get_string(&b, NULL);
983 if (((len = strlen(p)) > 0) && p[len - 1] == '.')
985 if (strcmp(p, chost) != 0)
989 /* verify client user */
990 p = buffer_get_string(&b, NULL);
991 if (strcmp(p, cuser) != 0)
995 if (buffer_len(&b) != 0)
1002 mm_answer_keyverify(int socket, Buffer *m)
1005 u_char *signature, *data, *blob;
1006 u_int signaturelen, datalen, bloblen;
1010 blob = buffer_get_string(m, &bloblen);
1011 signature = buffer_get_string(m, &signaturelen);
1012 data = buffer_get_string(m, &datalen);
1014 if (hostbased_cuser == NULL || hostbased_chost == NULL ||
1015 !monitor_allowed_key(blob, bloblen))
1016 fatal("%s: bad key, not previously allowed", __func__);
1018 key = key_from_blob(blob, bloblen);
1020 fatal("%s: bad public key blob", __func__);
1022 switch (key_blobtype) {
1024 valid_data = monitor_valid_userblob(data, datalen);
1027 valid_data = monitor_valid_hostbasedblob(data, datalen,
1028 hostbased_cuser, hostbased_chost);
1035 fatal("%s: bad signature data blob", __func__);
1037 verified = key_verify(key, signature, signaturelen, data, datalen);
1038 debug3("%s: key %p signature %s",
1039 __func__, key, verified ? "verified" : "unverified");
1046 auth_method = key_blobtype == MM_USERKEY ? "publickey" : "hostbased";
1048 monitor_reset_key_state();
1051 buffer_put_int(m, verified);
1052 mm_request_send(socket, MONITOR_ANS_KEYVERIFY, m);
1058 mm_record_login(Session *s, struct passwd *pw)
1061 struct sockaddr_storage from;
1064 * Get IP address of client. If the connection is not a socket, let
1065 * the address be 0.0.0.0.
1067 memset(&from, 0, sizeof(from));
1068 fromlen = sizeof(from);
1069 if (packet_connection_is_on_socket()) {
1070 if (getpeername(packet_get_connection_in(),
1071 (struct sockaddr *) & from, &fromlen) < 0) {
1072 debug("getpeername: %.100s", strerror(errno));
1076 /* Record that there was a login on that tty from the remote host. */
1077 record_login(s->pid, s->tty, pw->pw_name, pw->pw_uid,
1078 get_remote_name_or_ip(utmp_len, options.verify_reverse_mapping),
1079 (struct sockaddr *)&from, fromlen);
1083 mm_session_close(Session *s)
1085 debug3("%s: session %d pid %d", __func__, s->self, s->pid);
1086 if (s->ttyfd != -1) {
1087 debug3("%s: tty %s ptyfd %d", __func__, s->tty, s->ptyfd);
1088 fatal_remove_cleanup(session_pty_cleanup2, (void *)s);
1089 session_pty_cleanup2(s);
1095 mm_answer_pty(int socket, Buffer *m)
1097 extern struct monitor *pmonitor;
1101 debug3("%s entering", __func__);
1107 s->authctxt = authctxt;
1108 s->pw = authctxt->pw;
1109 s->pid = pmonitor->m_pid;
1110 res = pty_allocate(&s->ptyfd, &s->ttyfd, s->tty, sizeof(s->tty));
1113 fatal_add_cleanup(session_pty_cleanup2, (void *)s);
1114 pty_setowner(authctxt->pw, s->tty);
1116 buffer_put_int(m, 1);
1117 buffer_put_cstring(m, s->tty);
1118 mm_request_send(socket, MONITOR_ANS_PTY, m);
1120 mm_send_fd(socket, s->ptyfd);
1121 mm_send_fd(socket, s->ttyfd);
1123 /* We need to trick ttyslot */
1124 if (dup2(s->ttyfd, 0) == -1)
1125 fatal("%s: dup2", __func__);
1127 mm_record_login(s, authctxt->pw);
1129 /* Now we can close the file descriptor again */
1132 /* make sure nothing uses fd 0 */
1133 if ((fd0 = open(_PATH_DEVNULL, O_RDONLY)) < 0)
1134 fatal("%s: open(/dev/null): %s", __func__, strerror(errno));
1136 error("%s: fd0 %d != 0", __func__, fd0);
1138 /* slave is not needed */
1140 s->ttyfd = s->ptyfd;
1141 /* no need to dup() because nobody closes ptyfd */
1142 s->ptymaster = s->ptyfd;
1144 debug3("%s: tty %s ptyfd %d", __func__, s->tty, s->ttyfd);
1150 mm_session_close(s);
1151 buffer_put_int(m, 0);
1152 mm_request_send(socket, MONITOR_ANS_PTY, m);
1157 mm_answer_pty_cleanup(int socket, Buffer *m)
1162 debug3("%s entering", __func__);
1164 tty = buffer_get_string(m, NULL);
1165 if ((s = session_by_tty(tty)) != NULL)
1166 mm_session_close(s);
1173 mm_answer_sesskey(int socket, Buffer *m)
1178 /* Turn off permissions */
1179 monitor_permit(mon_dispatch, MONITOR_REQ_SESSKEY, 1);
1181 if ((p = BN_new()) == NULL)
1182 fatal("%s: BN_new", __func__);
1184 buffer_get_bignum2(m, p);
1186 rsafail = ssh1_session_key(p);
1189 buffer_put_int(m, rsafail);
1190 buffer_put_bignum2(m, p);
1194 mm_request_send(socket, MONITOR_ANS_SESSKEY, m);
1196 /* Turn on permissions for sessid passing */
1197 monitor_permit(mon_dispatch, MONITOR_REQ_SESSID, 1);
1203 mm_answer_sessid(int socket, Buffer *m)
1207 debug3("%s entering", __func__);
1209 if (buffer_len(m) != 16)
1210 fatal("%s: bad ssh1 session id", __func__);
1211 for (i = 0; i < 16; i++)
1212 session_id[i] = buffer_get_char(m);
1214 /* Turn on permissions for getpwnam */
1215 monitor_permit(mon_dispatch, MONITOR_REQ_PWNAM, 1);
1221 mm_answer_rsa_keyallowed(int socket, Buffer *m)
1225 u_char *blob = NULL;
1229 debug3("%s entering", __func__);
1231 if (options.rsa_authentication && authctxt->valid) {
1232 if ((client_n = BN_new()) == NULL)
1233 fatal("%s: BN_new", __func__);
1234 buffer_get_bignum2(m, client_n);
1235 allowed = auth_rsa_key_allowed(authctxt->pw, client_n, &key);
1236 BN_clear_free(client_n);
1239 buffer_put_int(m, allowed);
1240 buffer_put_int(m, forced_command != NULL);
1242 /* clear temporarily storage (used by generate challenge) */
1243 monitor_reset_key_state();
1245 if (allowed && key != NULL) {
1246 key->type = KEY_RSA; /* cheat for key_to_blob */
1247 if (key_to_blob(key, &blob, &blen) == 0)
1248 fatal("%s: key_to_blob failed", __func__);
1249 buffer_put_string(m, blob, blen);
1251 /* Save temporarily for comparison in verify */
1254 key_blobtype = MM_RSAUSERKEY;
1261 mm_request_send(socket, MONITOR_ANS_RSAKEYALLOWED, m);
1263 monitor_permit(mon_dispatch, MONITOR_REQ_RSACHALLENGE, allowed);
1264 monitor_permit(mon_dispatch, MONITOR_REQ_RSARESPONSE, 0);
1269 mm_answer_rsa_challenge(int socket, Buffer *m)
1275 debug3("%s entering", __func__);
1277 if (!authctxt->valid)
1278 fatal("%s: authctxt not valid", __func__);
1279 blob = buffer_get_string(m, &blen);
1280 if (!monitor_allowed_key(blob, blen))
1281 fatal("%s: bad key, not previously allowed", __func__);
1282 if (key_blobtype != MM_RSAUSERKEY && key_blobtype != MM_RSAHOSTKEY)
1283 fatal("%s: key type mismatch", __func__);
1284 if ((key = key_from_blob(blob, blen)) == NULL)
1285 fatal("%s: received bad key", __func__);
1288 BN_clear_free(ssh1_challenge);
1289 ssh1_challenge = auth_rsa_generate_challenge(key);
1292 buffer_put_bignum2(m, ssh1_challenge);
1294 debug3("%s sending reply", __func__);
1295 mm_request_send(socket, MONITOR_ANS_RSACHALLENGE, m);
1297 monitor_permit(mon_dispatch, MONITOR_REQ_RSARESPONSE, 1);
1305 mm_answer_rsa_response(int socket, Buffer *m)
1308 u_char *blob, *response;
1312 debug3("%s entering", __func__);
1314 if (!authctxt->valid)
1315 fatal("%s: authctxt not valid", __func__);
1316 if (ssh1_challenge == NULL)
1317 fatal("%s: no ssh1_challenge", __func__);
1319 blob = buffer_get_string(m, &blen);
1320 if (!monitor_allowed_key(blob, blen))
1321 fatal("%s: bad key, not previously allowed", __func__);
1322 if (key_blobtype != MM_RSAUSERKEY && key_blobtype != MM_RSAHOSTKEY)
1323 fatal("%s: key type mismatch: %d", __func__, key_blobtype);
1324 if ((key = key_from_blob(blob, blen)) == NULL)
1325 fatal("%s: received bad key", __func__);
1326 response = buffer_get_string(m, &len);
1328 fatal("%s: received bad response to challenge", __func__);
1329 success = auth_rsa_verify_response(key, ssh1_challenge, response);
1335 auth_method = key_blobtype == MM_RSAUSERKEY ? "rsa" : "rhosts-rsa";
1338 BN_clear_free(ssh1_challenge);
1339 ssh1_challenge = NULL;
1340 monitor_reset_key_state();
1343 buffer_put_int(m, success);
1344 mm_request_send(socket, MONITOR_ANS_RSARESPONSE, m);
1351 mm_answer_krb4(int socket, Buffer *m)
1353 KTEXT_ST auth, reply;
1358 reply.length = auth.length = 0;
1360 p = buffer_get_string(m, &alen);
1361 if (alen >= MAX_KTXT_LEN)
1362 fatal("%s: auth too large", __func__);
1363 memcpy(auth.dat, p, alen);
1368 success = options.kerberos_authentication &&
1370 auth_krb4(authctxt, &auth, &client, &reply);
1372 memset(auth.dat, 0, alen);
1374 buffer_put_int(m, success);
1377 buffer_put_cstring(m, client);
1378 buffer_put_string(m, reply.dat, reply.length);
1382 memset(reply.dat, 0, reply.length);
1385 debug3("%s: sending result %d", __func__, success);
1386 mm_request_send(socket, MONITOR_ANS_KRB4, m);
1388 auth_method = "kerberos";
1390 /* Causes monitor loop to terminate if authenticated */
1397 mm_answer_krb5(int socket, Buffer *m)
1399 krb5_data tkt, reply;
1404 /* use temporary var to avoid size issues on 64bit arch */
1405 tkt.data = buffer_get_string(m, &len);
1408 success = options.kerberos_authentication &&
1410 auth_krb5(authctxt, &tkt, &client_user, &reply);
1416 buffer_put_int(m, success);
1419 buffer_put_cstring(m, client_user);
1420 buffer_put_string(m, reply.data, reply.length);
1426 mm_request_send(socket, MONITOR_ANS_KRB5, m);
1433 mm_answer_term(int socket, Buffer *req)
1435 extern struct monitor *pmonitor;
1438 debug3("%s: tearing down sessions", __func__);
1440 /* The child is terminating */
1441 session_destroy_all(&mm_session_close);
1443 while (waitpid(pmonitor->m_pid, &status, 0) == -1)
1447 res = WIFEXITED(status) ? WEXITSTATUS(status) : 1;
1449 /* Terminate process */
1454 monitor_apply_keystate(struct monitor *pmonitor)
1457 set_newkeys(MODE_IN);
1458 set_newkeys(MODE_OUT);
1460 packet_set_protocol_flags(child_state.ssh1protoflags);
1461 packet_set_encryption_key(child_state.ssh1key,
1462 child_state.ssh1keylen, child_state.ssh1cipher);
1463 xfree(child_state.ssh1key);
1466 /* for rc4 and other stateful ciphers */
1467 packet_set_keycontext(MODE_OUT, child_state.keyout);
1468 xfree(child_state.keyout);
1469 packet_set_keycontext(MODE_IN, child_state.keyin);
1470 xfree(child_state.keyin);
1473 packet_set_iv(MODE_OUT, child_state.ivout);
1474 xfree(child_state.ivout);
1475 packet_set_iv(MODE_IN, child_state.ivin);
1476 xfree(child_state.ivin);
1479 memcpy(&incoming_stream, &child_state.incoming,
1480 sizeof(incoming_stream));
1481 memcpy(&outgoing_stream, &child_state.outgoing,
1482 sizeof(outgoing_stream));
1484 /* Update with new address */
1485 if (options.compression)
1486 mm_init_compression(pmonitor->m_zlib);
1488 /* Network I/O buffers */
1489 /* XXX inefficient for large buffers, need: buffer_init_from_string */
1490 buffer_clear(&input);
1491 buffer_append(&input, child_state.input, child_state.ilen);
1492 memset(child_state.input, 0, child_state.ilen);
1493 xfree(child_state.input);
1495 buffer_clear(&output);
1496 buffer_append(&output, child_state.output, child_state.olen);
1497 memset(child_state.output, 0, child_state.olen);
1498 xfree(child_state.output);
1502 mm_get_kex(Buffer *m)
1508 kex = xmalloc(sizeof(*kex));
1509 memset(kex, 0, sizeof(*kex));
1510 kex->session_id = buffer_get_string(m, &kex->session_id_len);
1511 if ((session_id2 == NULL) ||
1512 (kex->session_id_len != session_id2_len) ||
1513 (memcmp(kex->session_id, session_id2, session_id2_len) != 0))
1514 fatal("mm_get_get: internal error: bad session id");
1515 kex->we_need = buffer_get_int(m);
1516 kex->kex[KEX_DH_GRP1_SHA1] = kexdh_server;
1517 kex->kex[KEX_DH_GEX_SHA1] = kexgex_server;
1519 kex->kex[KEX_GSS_GRP1_SHA1] =kexgss_server;
1522 kex->hostkey_type = buffer_get_int(m);
1523 kex->kex_type = buffer_get_int(m);
1524 blob = buffer_get_string(m, &bloblen);
1525 buffer_init(&kex->my);
1526 buffer_append(&kex->my, blob, bloblen);
1528 blob = buffer_get_string(m, &bloblen);
1529 buffer_init(&kex->peer);
1530 buffer_append(&kex->peer, blob, bloblen);
1533 kex->flags = buffer_get_int(m);
1534 kex->client_version_string = buffer_get_string(m, NULL);
1535 kex->server_version_string = buffer_get_string(m, NULL);
1536 kex->load_host_key=&get_hostkey_by_type;
1537 kex->host_key_index=&get_hostkey_index;
1542 /* This function requries careful sanity checking */
1545 mm_get_keystate(struct monitor *pmonitor)
1549 u_int bloblen, plen;
1551 debug3("%s: Waiting for new keys", __func__);
1554 mm_request_receive_expect(pmonitor->m_sendfd, MONITOR_REQ_KEYEXPORT, &m);
1556 child_state.ssh1protoflags = buffer_get_int(&m);
1557 child_state.ssh1cipher = buffer_get_int(&m);
1558 child_state.ssh1key = buffer_get_string(&m,
1559 &child_state.ssh1keylen);
1560 child_state.ivout = buffer_get_string(&m,
1561 &child_state.ivoutlen);
1562 child_state.ivin = buffer_get_string(&m, &child_state.ivinlen);
1565 /* Get the Kex for rekeying */
1566 *pmonitor->m_pkex = mm_get_kex(&m);
1569 blob = buffer_get_string(&m, &bloblen);
1570 current_keys[MODE_OUT] = mm_newkeys_from_blob(blob, bloblen);
1573 debug3("%s: Waiting for second key", __func__);
1574 blob = buffer_get_string(&m, &bloblen);
1575 current_keys[MODE_IN] = mm_newkeys_from_blob(blob, bloblen);
1578 /* Now get sequence numbers for the packets */
1579 packet_set_seqnr(MODE_OUT, buffer_get_int(&m));
1580 packet_set_seqnr(MODE_IN, buffer_get_int(&m));
1583 /* Get the key context */
1584 child_state.keyout = buffer_get_string(&m, &child_state.keyoutlen);
1585 child_state.keyin = buffer_get_string(&m, &child_state.keyinlen);
1587 debug3("%s: Getting compression state", __func__);
1588 /* Get compression state */
1589 p = buffer_get_string(&m, &plen);
1590 if (plen != sizeof(child_state.outgoing))
1591 fatal("%s: bad request size", __func__);
1592 memcpy(&child_state.outgoing, p, sizeof(child_state.outgoing));
1595 p = buffer_get_string(&m, &plen);
1596 if (plen != sizeof(child_state.incoming))
1597 fatal("%s: bad request size", __func__);
1598 memcpy(&child_state.incoming, p, sizeof(child_state.incoming));
1601 /* Network I/O buffers */
1602 debug3("%s: Getting Network I/O buffers", __func__);
1603 child_state.input = buffer_get_string(&m, &child_state.ilen);
1604 child_state.output = buffer_get_string(&m, &child_state.olen);
1610 /* Allocation functions for zlib */
1612 mm_zalloc(struct mm_master *mm, u_int ncount, u_int size)
1614 size_t len = (size_t) size * ncount;
1617 if (len == 0 || ncount > SIZE_T_MAX / size)
1618 fatal("%s: mm_zalloc(%u, %u)", __func__, ncount, size);
1620 address = mm_malloc(mm, len);
1626 mm_zfree(struct mm_master *mm, void *address)
1628 mm_free(mm, address);
1632 mm_init_compression(struct mm_master *mm)
1634 outgoing_stream.zalloc = (alloc_func)mm_zalloc;
1635 outgoing_stream.zfree = (free_func)mm_zfree;
1636 outgoing_stream.opaque = mm;
1638 incoming_stream.zalloc = (alloc_func)mm_zalloc;
1639 incoming_stream.zfree = (free_func)mm_zfree;
1640 incoming_stream.opaque = mm;
1645 #define FD_CLOSEONEXEC(x) do { \
1646 if (fcntl(x, F_SETFD, 1) == -1) \
1647 fatal("fcntl(%d, F_SETFD)", x); \
1651 monitor_socketpair(int *pair)
1653 #ifdef HAVE_SOCKETPAIR
1654 if (socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1)
1655 fatal("%s: socketpair", __func__);
1657 fatal("%s: UsePrivilegeSeparation=yes not supported",
1660 FD_CLOSEONEXEC(pair[0]);
1661 FD_CLOSEONEXEC(pair[1]);
1664 #define MM_MEMSIZE 65536
1669 struct monitor *mon;
1672 mon = xmalloc(sizeof(*mon));
1674 monitor_socketpair(pair);
1676 mon->m_recvfd = pair[0];
1677 mon->m_sendfd = pair[1];
1679 /* Used to share zlib space across processes */
1680 if (options.compression) {
1681 mon->m_zback = mm_create(NULL, MM_MEMSIZE);
1682 mon->m_zlib = mm_create(mon->m_zback, 20 * MM_MEMSIZE);
1684 /* Compression needs to share state across borders */
1685 mm_init_compression(mon->m_zlib);
1692 monitor_reinit(struct monitor *mon)
1696 monitor_socketpair(pair);
1698 mon->m_recvfd = pair[0];
1699 mon->m_sendfd = pair[1];
1705 mm_answer_gss_setup_ctx(int socket, Buffer *m) {
1709 oid.elements=buffer_get_string(m,&oid.length);
1711 major=ssh_gssapi_server_ctx(&gsscontext,&oid);
1713 xfree(oid.elements);
1716 buffer_put_int(m,major);
1718 mm_request_send(socket,MONITOR_ANS_GSSSETUP,m);
1720 /* Now we have a context, enable the step and sign */
1721 monitor_permit(mon_dispatch, MONITOR_REQ_GSSSTEP,1);
1727 mm_answer_gss_accept_ctx(int socket, Buffer *m) {
1728 gss_buffer_desc in,out;
1729 OM_uint32 major,minor;
1730 OM_uint32 flags = 0; /* GSI needs this */
1732 in.value = buffer_get_string(m,&in.length);
1733 major=ssh_gssapi_accept_ctx(gsscontext,&in,&out,&flags);
1737 buffer_put_int(m, major);
1738 buffer_put_string(m, out.value, out.length);
1739 buffer_put_int(m, flags);
1740 mm_request_send(socket,MONITOR_ANS_GSSSTEP,m);
1742 gss_release_buffer(&minor, &out);
1744 /* Complete - now we can do signing */
1745 if (major==GSS_S_COMPLETE) {
1746 monitor_permit(mon_dispatch, MONITOR_REQ_GSSSTEP,0);
1747 monitor_permit(mon_dispatch, MONITOR_REQ_GSSSIGN,1);
1753 mm_answer_gss_userok(int socket, Buffer *m) {
1756 authenticated = authctxt->valid && ssh_gssapi_userok(authctxt->user);
1759 buffer_put_int(m, authenticated);
1761 debug3("%s: sending result %d", __func__, authenticated);
1762 mm_request_send(socket, MONITOR_ANS_GSSUSEROK, m);
1764 /* XXX - auth method could also be 'external' */
1765 auth_method="gssapi";
1767 /* Monitor loop will terminate if authenticated */
1768 return(authenticated);
1772 mm_answer_gss_sign(int socket, Buffer *m) {
1773 gss_buffer_desc data,hash;
1774 OM_uint32 major,minor;
1776 data.value = buffer_get_string(m,&data.length);
1777 if (data.length != 20)
1778 fatal("%s: data length incorrect: %d", __func__, data.length);
1780 /* Save the session ID - only first time round */
1781 if (session_id2_len == 0) {
1782 session_id2_len=data.length;
1783 session_id2 = xmalloc(session_id2_len);
1784 memcpy(session_id2, data.value, session_id2_len);
1786 major=ssh_gssapi_sign(gsscontext, &data, &hash);
1791 buffer_put_int(m, major);
1792 buffer_put_string(m, hash.value, hash.length);
1794 mm_request_send(socket,MONITOR_ANS_GSSSIGN,m);
1796 gss_release_buffer(&minor,&hash);
1798 /* Turn on permissions for getpwnam */
1799 monitor_permit(mon_dispatch, MONITOR_REQ_PWNAM, 1);
1805 mm_answer_gss_error(int socket, Buffer *m) {
1806 OM_uint32 major,minor;
1809 msg=ssh_gssapi_last_error(gsscontext,&major,&minor);
1811 buffer_put_int(m,major);
1812 buffer_put_int(m,minor);
1813 buffer_put_cstring(m,msg);
1815 mm_request_send(socket,MONITOR_ANS_GSSERR,m);
1823 mm_answer_gss_indicate_mechs(int socket, Buffer *m) {
1824 OM_uint32 major,minor;
1825 gss_OID_set mech_set;
1828 major=gss_indicate_mechs(&minor, &mech_set);
1831 buffer_put_int(m, major);
1832 buffer_put_int(m, mech_set->count);
1833 for (i=0; i < mech_set->count; i++) {
1834 buffer_put_string(m, mech_set->elements[i].elements,
1835 mech_set->elements[i].length);
1838 gss_release_oid_set(&minor,&mech_set);
1840 mm_request_send(socket,MONITOR_ANS_GSSMECHS,m);
1846 mm_answer_gss_localname(int socket, Buffer *m) {
1849 ssh_gssapi_localname(&name);
1853 buffer_put_cstring(m, name);
1854 debug3("%s: sending result %s", __func__, name);
1857 buffer_put_cstring(m, "");
1858 debug3("%s: sending result \"\"", __func__);
1861 mm_request_send(socket, MONITOR_ANS_GSSLOCALNAME, m);