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.29 2002/09/26 11:38:43 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_gss_setup_ctx(int, Buffer *);
130 int mm_answer_gss_accept_ctx(int, Buffer *);
131 int mm_answer_gss_userok(int, Buffer *);
132 int mm_answer_gss_localname(int, Buffer *);
133 int mm_answer_gss_sign(int, Buffer *);
134 int mm_answer_gss_indicate_mechs(int, Buffer *);
135 int mm_answer_gss_display_status(int, Buffer *);
139 int mm_answer_gsi_gridmap(int, Buffer *);
143 int mm_answer_krb4(int, Buffer *);
146 int mm_answer_krb5(int, Buffer *);
149 static Authctxt *authctxt;
150 static BIGNUM *ssh1_challenge = NULL; /* used for ssh1 rsa auth */
152 /* local state for key verify */
153 static u_char *key_blob = NULL;
154 static u_int key_bloblen = 0;
155 static int key_blobtype = MM_NOKEY;
156 static char *hostbased_cuser = NULL;
157 static char *hostbased_chost = NULL;
158 static char *auth_method = "unknown";
159 static int session_id2_len = 0;
160 static u_char *session_id2 = NULL;
163 enum monitor_reqtype type;
165 int (*f)(int, Buffer *);
168 #define MON_ISAUTH 0x0004 /* Required for Authentication */
169 #define MON_AUTHDECIDE 0x0008 /* Decides Authentication */
170 #define MON_ONCE 0x0010 /* Disable after calling */
172 #define MON_AUTH (MON_ISAUTH|MON_AUTHDECIDE)
174 #define MON_PERMIT 0x1000 /* Request is permitted */
176 struct mon_table mon_dispatch_proto20[] = {
177 {MONITOR_REQ_MODULI, MON_ONCE, mm_answer_moduli},
178 {MONITOR_REQ_SIGN, MON_ONCE, mm_answer_sign},
179 {MONITOR_REQ_PWNAM, MON_AUTH, mm_answer_pwnamallow},
180 {MONITOR_REQ_AUTHSERV, MON_ONCE, mm_answer_authserv},
181 {MONITOR_REQ_AUTH2_READ_BANNER, MON_ONCE, mm_answer_auth2_read_banner},
182 {MONITOR_REQ_AUTHPASSWORD, MON_AUTH, mm_answer_authpassword},
184 {MONITOR_REQ_PAM_START, MON_ISAUTH, mm_answer_pam_start},
187 {MONITOR_REQ_BSDAUTHQUERY, MON_ISAUTH, mm_answer_bsdauthquery},
188 {MONITOR_REQ_BSDAUTHRESPOND, MON_AUTH,mm_answer_bsdauthrespond},
191 {MONITOR_REQ_SKEYQUERY, MON_ISAUTH, mm_answer_skeyquery},
192 {MONITOR_REQ_SKEYRESPOND, MON_AUTH, mm_answer_skeyrespond},
195 {MONITOR_REQ_GSSSETUP, MON_ISAUTH, mm_answer_gss_setup_ctx},
196 {MONITOR_REQ_GSSSTEP, MON_ISAUTH, mm_answer_gss_accept_ctx},
197 {MONITOR_REQ_GSSSIGN, MON_ONCE, mm_answer_gss_sign},
198 {MONITOR_REQ_GSSMECHS, MON_ISAUTH, mm_answer_gss_indicate_mechs},
199 {MONITOR_REQ_GSSSTAT, MON_ISAUTH, mm_answer_gss_display_status},
200 {MONITOR_REQ_GSSUSEROK, MON_AUTH, mm_answer_gss_userok},
201 {MONITOR_REQ_GSSLOCALNAME, MON_AUTH, mm_answer_gss_localname},
203 {MONITOR_REQ_KEYALLOWED, MON_ISAUTH, mm_answer_keyallowed},
204 {MONITOR_REQ_KEYVERIFY, MON_AUTH, mm_answer_keyverify},
208 struct mon_table mon_dispatch_postauth20[] = {
210 {MONITOR_REQ_GSSSETUP, 0, mm_answer_gss_setup_ctx},
211 {MONITOR_REQ_GSSSTEP, 0, mm_answer_gss_accept_ctx},
212 {MONITOR_REQ_GSSSIGN, 0, mm_answer_gss_sign},
213 {MONITOR_REQ_GSSMECHS, 0, mm_answer_gss_indicate_mechs},
214 {MONITOR_REQ_GSSSTAT, 0, mm_answer_gss_display_status},
216 {MONITOR_REQ_MODULI, 0, mm_answer_moduli},
217 {MONITOR_REQ_SIGN, 0, mm_answer_sign},
218 {MONITOR_REQ_PTY, 0, mm_answer_pty},
219 {MONITOR_REQ_PTYCLEANUP, 0, mm_answer_pty_cleanup},
220 {MONITOR_REQ_TERM, 0, mm_answer_term},
224 struct mon_table mon_dispatch_proto15[] = {
225 {MONITOR_REQ_PWNAM, MON_ONCE, mm_answer_pwnamallow},
226 {MONITOR_REQ_SESSKEY, MON_ONCE, mm_answer_sesskey},
227 {MONITOR_REQ_SESSID, MON_ONCE, mm_answer_sessid},
228 {MONITOR_REQ_AUTHPASSWORD, MON_AUTH, mm_answer_authpassword},
229 {MONITOR_REQ_RSAKEYALLOWED, MON_ISAUTH, mm_answer_rsa_keyallowed},
230 {MONITOR_REQ_KEYALLOWED, MON_ISAUTH, mm_answer_keyallowed},
231 {MONITOR_REQ_RSACHALLENGE, MON_ONCE, mm_answer_rsa_challenge},
232 {MONITOR_REQ_RSARESPONSE, MON_ONCE|MON_AUTHDECIDE, mm_answer_rsa_response},
234 {MONITOR_REQ_BSDAUTHQUERY, MON_ISAUTH, mm_answer_bsdauthquery},
235 {MONITOR_REQ_BSDAUTHRESPOND, MON_AUTH,mm_answer_bsdauthrespond},
238 {MONITOR_REQ_SKEYQUERY, MON_ISAUTH, mm_answer_skeyquery},
239 {MONITOR_REQ_SKEYRESPOND, MON_AUTH, mm_answer_skeyrespond},
242 {MONITOR_REQ_GSSSETUP, MON_ISAUTH, mm_answer_gss_setup_ctx},
243 {MONITOR_REQ_GSSSTEP, MON_ISAUTH, mm_answer_gss_accept_ctx},
244 {MONITOR_REQ_GSSSIGN, MON_ONCE, mm_answer_gss_sign},
245 {MONITOR_REQ_GSSUSEROK, MON_AUTH, mm_answer_gss_userok},
246 {MONITOR_REQ_GSSMECHS, MON_ISAUTH, mm_answer_gss_indicate_mechs},
247 {MONITOR_REQ_GSSSTAT, MON_ISAUTH, mm_answer_gss_display_status},
250 {MONITOR_REQ_GSIGRIDMAP, MON_PERMIT, mm_answer_gsi_gridmap},
253 {MONITOR_REQ_PAM_START, MON_ISAUTH, mm_answer_pam_start},
256 {MONITOR_REQ_KRB4, MON_ONCE|MON_AUTH, mm_answer_krb4},
259 {MONITOR_REQ_KRB5, MON_ONCE|MON_AUTH, mm_answer_krb5},
264 struct mon_table mon_dispatch_postauth15[] = {
266 {MONITOR_REQ_GSSSETUP, 0, mm_answer_gss_setup_ctx},
267 {MONITOR_REQ_GSSSTEP, 0, mm_answer_gss_accept_ctx},
268 {MONITOR_REQ_GSSSIGN, 0, mm_answer_gss_sign},
269 {MONITOR_REQ_GSSMECHS, 0, mm_answer_gss_indicate_mechs},
270 {MONITOR_REQ_GSSSTAT, 0, mm_answer_gss_display_status},
272 {MONITOR_REQ_PTY, MON_ONCE, mm_answer_pty},
273 {MONITOR_REQ_PTYCLEANUP, MON_ONCE, mm_answer_pty_cleanup},
274 {MONITOR_REQ_TERM, 0, mm_answer_term},
278 struct mon_table *mon_dispatch;
280 /* Specifies if a certain message is allowed at the moment */
283 monitor_permit(struct mon_table *ent, enum monitor_reqtype type, int permit)
285 while (ent->f != NULL) {
286 if (ent->type == type) {
287 ent->flags &= ~MON_PERMIT;
288 ent->flags |= permit ? MON_PERMIT : 0;
296 monitor_permit_authentications(int permit)
298 struct mon_table *ent = mon_dispatch;
300 while (ent->f != NULL) {
301 if (ent->flags & MON_AUTH) {
302 ent->flags &= ~MON_PERMIT;
303 ent->flags |= permit ? MON_PERMIT : 0;
310 monitor_child_preauth(struct monitor *pmonitor)
312 struct mon_table *ent;
313 int authenticated = 0;
315 debug3("preauth child monitor started");
318 mon_dispatch = mon_dispatch_proto20;
320 /* Permit requests for moduli and signatures */
321 monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1);
322 monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1);
324 /* and for the GSSAPI key exchange */
325 monitor_permit(mon_dispatch, MONITOR_REQ_GSSSETUP, 1);
326 monitor_permit(mon_dispatch, MONITOR_REQ_GSSSTEP, 1);
327 monitor_permit(mon_dispatch, MONITOR_REQ_GSSSIGN, 1);
328 monitor_permit(mon_dispatch, MONITOR_REQ_GSSMECHS, 1);
329 monitor_permit(mon_dispatch, MONITOR_REQ_GSSSTAT, 1);
332 mon_dispatch = mon_dispatch_proto15;
334 monitor_permit(mon_dispatch, MONITOR_REQ_SESSKEY, 1);
336 monitor_permit(mon_dispatch, MONITOR_REQ_GSSSIGN, 1);
337 monitor_permit(mon_dispatch, MONITOR_REQ_GSSMECHS, 1);
338 monitor_permit(mon_dispatch, MONITOR_REQ_GSSSTAT, 1);
341 monitor_permit(mon_dispatch, MONITOR_REQ_GSIGRIDMAP, 1);
345 authctxt = authctxt_new();
347 /* The first few requests do not require asynchronous access */
348 while (!authenticated) {
349 authenticated = monitor_read(pmonitor, mon_dispatch, &ent);
351 if (!(ent->flags & MON_AUTHDECIDE))
352 fatal("%s: unexpected authentication from %d",
353 __func__, ent->type);
354 if (authctxt->pw->pw_uid == 0 &&
355 !auth_root_allowed(auth_method))
358 if (!do_pam_account(authctxt->pw->pw_name, NULL))
363 if (ent->flags & MON_AUTHDECIDE) {
364 auth_log(authctxt, authenticated, auth_method,
365 compat20 ? " ssh2" : "");
367 authctxt->failures++;
371 if (!authctxt->valid)
372 fatal("%s: authenticated invalid user", __func__);
374 debug("%s: %s has been authenticated by privileged process",
375 __func__, authctxt->user);
377 mm_get_keystate(pmonitor);
383 monitor_child_postauth(struct monitor *pmonitor)
386 mon_dispatch = mon_dispatch_postauth20;
388 /* Permit requests for moduli and signatures */
389 monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1);
390 monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1);
391 monitor_permit(mon_dispatch, MONITOR_REQ_TERM, 1);
394 mon_dispatch = mon_dispatch_postauth15;
395 monitor_permit(mon_dispatch, MONITOR_REQ_TERM, 1);
398 monitor_permit(mon_dispatch, MONITOR_REQ_GSSSTAT, 1);
401 monitor_permit(mon_dispatch, MONITOR_REQ_PTY, 1);
402 monitor_permit(mon_dispatch, MONITOR_REQ_PTYCLEANUP, 1);
406 monitor_read(pmonitor, mon_dispatch, NULL);
410 monitor_sync(struct monitor *pmonitor)
412 if (options.compression) {
413 /* The member allocation is not visible, so sync it */
414 mm_share_sync(&pmonitor->m_zlib, &pmonitor->m_zback);
419 monitor_read(struct monitor *pmonitor, struct mon_table *ent,
420 struct mon_table **pent)
428 mm_request_receive(pmonitor->m_sendfd, &m);
429 type = buffer_get_char(&m);
431 debug3("%s: checking request %d", __func__, type);
433 while (ent->f != NULL) {
434 if (ent->type == type)
439 if (ent->f != NULL) {
440 if (!(ent->flags & MON_PERMIT))
441 fatal("%s: unpermitted request %d", __func__,
443 ret = (*ent->f)(pmonitor->m_sendfd, &m);
446 /* The child may use this request only once, disable it */
447 if (ent->flags & MON_ONCE) {
448 debug2("%s: %d used once, disabling now", __func__,
450 ent->flags &= ~MON_PERMIT;
459 fatal("%s: unsupported request: %d", __func__, type);
465 /* allowed key state */
467 monitor_allowed_key(u_char *blob, u_int bloblen)
469 /* make sure key is allowed */
470 if (key_blob == NULL || key_bloblen != bloblen ||
471 memcmp(key_blob, blob, key_bloblen))
477 monitor_reset_key_state(void)
480 if (key_blob != NULL)
482 if (hostbased_cuser != NULL)
483 xfree(hostbased_cuser);
484 if (hostbased_chost != NULL)
485 xfree(hostbased_chost);
488 key_blobtype = MM_NOKEY;
489 hostbased_cuser = NULL;
490 hostbased_chost = NULL;
494 mm_answer_moduli(int socket, Buffer *m)
499 min = buffer_get_int(m);
500 want = buffer_get_int(m);
501 max = buffer_get_int(m);
503 debug3("%s: got parameters: %d %d %d",
504 __func__, min, want, max);
505 /* We need to check here, too, in case the child got corrupted */
506 if (max < min || want < min || max < want)
507 fatal("%s: bad parameters: %d %d %d",
508 __func__, min, want, max);
512 dh = choose_dh(min, want, max);
514 buffer_put_char(m, 0);
517 /* Send first bignum */
518 buffer_put_char(m, 1);
519 buffer_put_bignum2(m, dh->p);
520 buffer_put_bignum2(m, dh->g);
524 mm_request_send(socket, MONITOR_ANS_MODULI, m);
529 mm_answer_sign(int socket, Buffer *m)
534 u_int siglen, datlen;
537 debug3("%s", __func__);
539 keyid = buffer_get_int(m);
540 p = buffer_get_string(m, &datlen);
543 fatal("%s: data length incorrect: %u", __func__, datlen);
545 /* save session id, it will be passed on the first call */
546 if (session_id2_len == 0) {
547 session_id2_len = datlen;
548 session_id2 = xmalloc(session_id2_len);
549 memcpy(session_id2, p, session_id2_len);
552 if ((key = get_hostkey_by_index(keyid)) == NULL)
553 fatal("%s: no hostkey from index %d", __func__, keyid);
554 if (key_sign(key, &signature, &siglen, p, datlen) < 0)
555 fatal("%s: key_sign failed", __func__);
557 debug3("%s: signature %p(%u)", __func__, signature, siglen);
560 buffer_put_string(m, signature, siglen);
565 mm_request_send(socket, MONITOR_ANS_SIGN, m);
567 /* Turn on permissions for getpwnam */
568 monitor_permit(mon_dispatch, MONITOR_REQ_PWNAM, 1);
573 /* Retrieves the password entry and also checks if the user is permitted */
576 mm_answer_pwnamallow(int socket, Buffer *m)
579 struct passwd *pwent;
582 debug3("%s", __func__);
584 login = buffer_get_string(m, NULL);
586 pwent = getpwnamallow(login);
588 if (authctxt->user) xfree(authctxt->user);
589 authctxt->user = xstrdup(login);
590 setproctitle("%s [priv]", pwent ? login : "unknown");
596 buffer_put_char(m, 0);
601 authctxt->pw = pwent;
604 buffer_put_char(m, 1);
605 buffer_put_string(m, pwent, sizeof(struct passwd));
606 buffer_put_cstring(m, pwent->pw_name);
607 buffer_put_cstring(m, "*");
608 buffer_put_cstring(m, pwent->pw_gecos);
609 #ifdef HAVE_PW_CLASS_IN_PASSWD
610 buffer_put_cstring(m, pwent->pw_class);
612 buffer_put_cstring(m, pwent->pw_dir);
613 buffer_put_cstring(m, pwent->pw_shell);
616 debug3("%s: sending MONITOR_ANS_PWNAM: %d", __func__, allowed);
617 mm_request_send(socket, MONITOR_ANS_PWNAM, m);
619 /* For SSHv1 allow authentication now */
621 monitor_permit_authentications(1);
623 /* Allow service/style information on the auth context */
624 monitor_permit(mon_dispatch, MONITOR_REQ_AUTHSERV, 1);
625 monitor_permit(mon_dispatch, MONITOR_REQ_AUTH2_READ_BANNER, 1);
629 monitor_permit(mon_dispatch, MONITOR_REQ_PAM_START, 1);
635 int mm_answer_auth2_read_banner(int socket, Buffer *m)
640 banner = auth2_read_banner();
641 buffer_put_cstring(m, banner != NULL ? banner : "");
642 mm_request_send(socket, MONITOR_ANS_AUTH2_READ_BANNER, m);
651 mm_answer_authserv(int socket, Buffer *m)
653 monitor_permit_authentications(1);
655 authctxt->service = buffer_get_string(m, NULL);
656 authctxt->style = buffer_get_string(m, NULL);
657 debug3("%s: service=%s, style=%s",
658 __func__, authctxt->service, authctxt->style);
660 if (strlen(authctxt->style) == 0) {
661 xfree(authctxt->style);
662 authctxt->style = NULL;
669 mm_answer_authpassword(int socket, Buffer *m)
671 static int call_count;
676 passwd = buffer_get_string(m, &plen);
677 /* Only authenticate if the context is valid */
678 authenticated = options.password_authentication &&
679 authctxt->valid && auth_password(authctxt, passwd);
680 memset(passwd, 0, strlen(passwd));
684 buffer_put_int(m, authenticated);
686 debug3("%s: sending result %d", __func__, authenticated);
687 mm_request_send(socket, MONITOR_ANS_AUTHPASSWORD, m);
690 if (plen == 0 && call_count == 1)
691 auth_method = "none";
693 auth_method = "password";
695 /* Causes monitor loop to terminate if authenticated */
696 return (authenticated);
701 mm_answer_bsdauthquery(int socket, Buffer *m)
703 char *name, *infotxt;
709 res = bsdauth_query(authctxt, &name, &infotxt, &numprompts,
713 buffer_put_int(m, res);
715 buffer_put_cstring(m, prompts[0]);
717 debug3("%s: sending challenge res: %d", __func__, res);
718 mm_request_send(socket, MONITOR_ANS_BSDAUTHQUERY, m);
731 mm_answer_bsdauthrespond(int socket, Buffer *m)
736 if (authctxt->as == 0)
737 fatal("%s: no bsd auth session", __func__);
739 response = buffer_get_string(m, NULL);
740 authok = options.challenge_response_authentication &&
741 auth_userresponse(authctxt->as, response, 0);
743 debug3("%s: <%s> = <%d>", __func__, response, authok);
747 buffer_put_int(m, authok);
749 debug3("%s: sending authenticated: %d", __func__, authok);
750 mm_request_send(socket, MONITOR_ANS_BSDAUTHRESPOND, m);
752 auth_method = "bsdauth";
754 return (authok != 0);
760 mm_answer_skeyquery(int socket, Buffer *m)
763 char challenge[1024];
766 res = skeychallenge(&skey, authctxt->user, challenge);
769 buffer_put_int(m, res);
771 buffer_put_cstring(m, challenge);
773 debug3("%s: sending challenge res: %d", __func__, res);
774 mm_request_send(socket, MONITOR_ANS_SKEYQUERY, m);
780 mm_answer_skeyrespond(int socket, Buffer *m)
785 response = buffer_get_string(m, NULL);
787 authok = (options.challenge_response_authentication &&
789 skey_haskey(authctxt->pw->pw_name) == 0 &&
790 skey_passcheck(authctxt->pw->pw_name, response) != -1);
795 buffer_put_int(m, authok);
797 debug3("%s: sending authenticated: %d", __func__, authok);
798 mm_request_send(socket, MONITOR_ANS_SKEYRESPOND, m);
800 auth_method = "skey";
802 return (authok != 0);
808 mm_answer_pam_start(int socket, Buffer *m)
812 user = buffer_get_string(m, NULL);
823 mm_append_debug(Buffer *m)
825 if (auth_debug_init && buffer_len(&auth_debug)) {
826 debug3("%s: Appending debug messages for child", __func__);
827 buffer_append(m, buffer_ptr(&auth_debug),
828 buffer_len(&auth_debug));
829 buffer_clear(&auth_debug);
834 mm_answer_keyallowed(int socket, Buffer *m)
840 enum mm_keytype type = 0;
843 debug3("%s entering", __func__);
845 type = buffer_get_int(m);
846 cuser = buffer_get_string(m, NULL);
847 chost = buffer_get_string(m, NULL);
848 blob = buffer_get_string(m, &bloblen);
850 key = key_from_blob(blob, bloblen);
852 if ((compat20 && type == MM_RSAHOSTKEY) ||
853 (!compat20 && type != MM_RSAHOSTKEY))
854 fatal("%s: key type and protocol mismatch", __func__);
856 debug3("%s: key_from_blob: %p", __func__, key);
858 if (key != NULL && authctxt->pw != NULL) {
861 allowed = options.pubkey_authentication &&
862 user_key_allowed(authctxt->pw, key);
865 allowed = options.hostbased_authentication &&
866 hostbased_key_allowed(authctxt->pw,
870 key->type = KEY_RSA1; /* XXX */
871 allowed = options.rhosts_rsa_authentication &&
872 auth_rhosts_rsa_key_allowed(authctxt->pw,
876 fatal("%s: unknown key type %d", __func__, type);
882 /* clear temporarily storage (used by verify) */
883 monitor_reset_key_state();
886 /* Save temporarily for comparison in verify */
888 key_bloblen = bloblen;
890 hostbased_cuser = cuser;
891 hostbased_chost = chost;
894 debug3("%s: key %p is %s",
895 __func__, key, allowed ? "allowed" : "disallowed");
898 buffer_put_int(m, allowed);
902 mm_request_send(socket, MONITOR_ANS_KEYALLOWED, m);
904 if (type == MM_RSAHOSTKEY)
905 monitor_permit(mon_dispatch, MONITOR_REQ_RSACHALLENGE, allowed);
911 monitor_valid_userblob(u_char *data, u_int datalen)
919 buffer_append(&b, data, datalen);
921 if (datafellows & SSH_OLD_SESSIONID) {
923 len = buffer_len(&b);
924 if ((session_id2 == NULL) ||
925 (len < session_id2_len) ||
926 (memcmp(p, session_id2, session_id2_len) != 0))
928 buffer_consume(&b, session_id2_len);
930 p = buffer_get_string(&b, &len);
931 if ((session_id2 == NULL) ||
932 (len != session_id2_len) ||
933 (memcmp(p, session_id2, session_id2_len) != 0))
937 if (buffer_get_char(&b) != SSH2_MSG_USERAUTH_REQUEST)
939 p = buffer_get_string(&b, NULL);
940 if (strcmp(authctxt->user, p) != 0) {
941 log("wrong user name passed to monitor: expected %s != %.100s",
946 buffer_skip_string(&b);
947 if (datafellows & SSH_BUG_PKAUTH) {
948 if (!buffer_get_char(&b))
951 p = buffer_get_string(&b, NULL);
952 if (strcmp("publickey", p) != 0)
955 if (!buffer_get_char(&b))
957 buffer_skip_string(&b);
959 buffer_skip_string(&b);
960 if (buffer_len(&b) != 0)
967 monitor_valid_hostbasedblob(u_char *data, u_int datalen, char *cuser,
976 buffer_append(&b, data, datalen);
978 p = buffer_get_string(&b, &len);
979 if ((session_id2 == NULL) ||
980 (len != session_id2_len) ||
981 (memcmp(p, session_id2, session_id2_len) != 0))
985 if (buffer_get_char(&b) != SSH2_MSG_USERAUTH_REQUEST)
987 p = buffer_get_string(&b, NULL);
988 if (strcmp(authctxt->user, p) != 0) {
989 log("wrong user name passed to monitor: expected %s != %.100s",
994 buffer_skip_string(&b); /* service */
995 p = buffer_get_string(&b, NULL);
996 if (strcmp(p, "hostbased") != 0)
999 buffer_skip_string(&b); /* pkalg */
1000 buffer_skip_string(&b); /* pkblob */
1002 /* verify client host, strip trailing dot if necessary */
1003 p = buffer_get_string(&b, NULL);
1004 if (((len = strlen(p)) > 0) && p[len - 1] == '.')
1006 if (strcmp(p, chost) != 0)
1010 /* verify client user */
1011 p = buffer_get_string(&b, NULL);
1012 if (strcmp(p, cuser) != 0)
1016 if (buffer_len(&b) != 0)
1023 mm_answer_keyverify(int socket, Buffer *m)
1026 u_char *signature, *data, *blob;
1027 u_int signaturelen, datalen, bloblen;
1031 blob = buffer_get_string(m, &bloblen);
1032 signature = buffer_get_string(m, &signaturelen);
1033 data = buffer_get_string(m, &datalen);
1035 if (hostbased_cuser == NULL || hostbased_chost == NULL ||
1036 !monitor_allowed_key(blob, bloblen))
1037 fatal("%s: bad key, not previously allowed", __func__);
1039 key = key_from_blob(blob, bloblen);
1041 fatal("%s: bad public key blob", __func__);
1043 switch (key_blobtype) {
1045 valid_data = monitor_valid_userblob(data, datalen);
1048 valid_data = monitor_valid_hostbasedblob(data, datalen,
1049 hostbased_cuser, hostbased_chost);
1056 fatal("%s: bad signature data blob", __func__);
1058 verified = key_verify(key, signature, signaturelen, data, datalen);
1059 debug3("%s: key %p signature %s",
1060 __func__, key, verified ? "verified" : "unverified");
1067 auth_method = key_blobtype == MM_USERKEY ? "publickey" : "hostbased";
1069 monitor_reset_key_state();
1072 buffer_put_int(m, verified);
1073 mm_request_send(socket, MONITOR_ANS_KEYVERIFY, m);
1079 mm_record_login(Session *s, struct passwd *pw)
1082 struct sockaddr_storage from;
1085 * Get IP address of client. If the connection is not a socket, let
1086 * the address be 0.0.0.0.
1088 memset(&from, 0, sizeof(from));
1089 fromlen = sizeof(from);
1090 if (packet_connection_is_on_socket()) {
1091 if (getpeername(packet_get_connection_in(),
1092 (struct sockaddr *) & from, &fromlen) < 0) {
1093 debug("getpeername: %.100s", strerror(errno));
1097 /* Record that there was a login on that tty from the remote host. */
1098 record_login(s->pid, s->tty, pw->pw_name, pw->pw_uid,
1099 get_remote_name_or_ip(utmp_len, options.verify_reverse_mapping),
1100 (struct sockaddr *)&from, fromlen);
1104 mm_session_close(Session *s)
1106 debug3("%s: session %d pid %d", __func__, s->self, s->pid);
1107 if (s->ttyfd != -1) {
1108 debug3("%s: tty %s ptyfd %d", __func__, s->tty, s->ptyfd);
1109 fatal_remove_cleanup(session_pty_cleanup2, (void *)s);
1110 session_pty_cleanup2(s);
1116 mm_answer_pty(int socket, Buffer *m)
1118 extern struct monitor *pmonitor;
1122 debug3("%s entering", __func__);
1128 s->authctxt = authctxt;
1129 s->pw = authctxt->pw;
1130 s->pid = pmonitor->m_pid;
1131 res = pty_allocate(&s->ptyfd, &s->ttyfd, s->tty, sizeof(s->tty));
1134 fatal_add_cleanup(session_pty_cleanup2, (void *)s);
1135 pty_setowner(authctxt->pw, s->tty);
1137 buffer_put_int(m, 1);
1138 buffer_put_cstring(m, s->tty);
1139 mm_request_send(socket, MONITOR_ANS_PTY, m);
1141 mm_send_fd(socket, s->ptyfd);
1142 mm_send_fd(socket, s->ttyfd);
1144 /* We need to trick ttyslot */
1145 if (dup2(s->ttyfd, 0) == -1)
1146 fatal("%s: dup2", __func__);
1148 mm_record_login(s, authctxt->pw);
1150 /* Now we can close the file descriptor again */
1153 /* make sure nothing uses fd 0 */
1154 if ((fd0 = open(_PATH_DEVNULL, O_RDONLY)) < 0)
1155 fatal("%s: open(/dev/null): %s", __func__, strerror(errno));
1157 error("%s: fd0 %d != 0", __func__, fd0);
1159 /* slave is not needed */
1161 s->ttyfd = s->ptyfd;
1162 /* no need to dup() because nobody closes ptyfd */
1163 s->ptymaster = s->ptyfd;
1165 debug3("%s: tty %s ptyfd %d", __func__, s->tty, s->ttyfd);
1171 mm_session_close(s);
1172 buffer_put_int(m, 0);
1173 mm_request_send(socket, MONITOR_ANS_PTY, m);
1178 mm_answer_pty_cleanup(int socket, Buffer *m)
1183 debug3("%s entering", __func__);
1185 tty = buffer_get_string(m, NULL);
1186 if ((s = session_by_tty(tty)) != NULL)
1187 mm_session_close(s);
1194 mm_answer_sesskey(int socket, Buffer *m)
1199 /* Turn off permissions */
1200 monitor_permit(mon_dispatch, MONITOR_REQ_SESSKEY, 1);
1202 if ((p = BN_new()) == NULL)
1203 fatal("%s: BN_new", __func__);
1205 buffer_get_bignum2(m, p);
1207 rsafail = ssh1_session_key(p);
1210 buffer_put_int(m, rsafail);
1211 buffer_put_bignum2(m, p);
1215 mm_request_send(socket, MONITOR_ANS_SESSKEY, m);
1217 /* Turn on permissions for sessid passing */
1218 monitor_permit(mon_dispatch, MONITOR_REQ_SESSID, 1);
1224 mm_answer_sessid(int socket, Buffer *m)
1228 debug3("%s entering", __func__);
1230 if (buffer_len(m) != 16)
1231 fatal("%s: bad ssh1 session id", __func__);
1232 for (i = 0; i < 16; i++)
1233 session_id[i] = buffer_get_char(m);
1235 /* Turn on permissions for getpwnam */
1236 monitor_permit(mon_dispatch, MONITOR_REQ_PWNAM, 1);
1242 mm_answer_rsa_keyallowed(int socket, Buffer *m)
1246 u_char *blob = NULL;
1250 debug3("%s entering", __func__);
1252 if (options.rsa_authentication && authctxt->valid) {
1253 if ((client_n = BN_new()) == NULL)
1254 fatal("%s: BN_new", __func__);
1255 buffer_get_bignum2(m, client_n);
1256 allowed = auth_rsa_key_allowed(authctxt->pw, client_n, &key);
1257 BN_clear_free(client_n);
1260 buffer_put_int(m, allowed);
1262 /* clear temporarily storage (used by generate challenge) */
1263 monitor_reset_key_state();
1265 if (allowed && key != NULL) {
1266 key->type = KEY_RSA; /* cheat for key_to_blob */
1267 if (key_to_blob(key, &blob, &blen) == 0)
1268 fatal("%s: key_to_blob failed", __func__);
1269 buffer_put_string(m, blob, blen);
1271 /* Save temporarily for comparison in verify */
1274 key_blobtype = MM_RSAUSERKEY;
1280 mm_request_send(socket, MONITOR_ANS_RSAKEYALLOWED, m);
1282 monitor_permit(mon_dispatch, MONITOR_REQ_RSACHALLENGE, allowed);
1283 monitor_permit(mon_dispatch, MONITOR_REQ_RSARESPONSE, 0);
1288 mm_answer_rsa_challenge(int socket, Buffer *m)
1294 debug3("%s entering", __func__);
1296 if (!authctxt->valid)
1297 fatal("%s: authctxt not valid", __func__);
1298 blob = buffer_get_string(m, &blen);
1299 if (!monitor_allowed_key(blob, blen))
1300 fatal("%s: bad key, not previously allowed", __func__);
1301 if (key_blobtype != MM_RSAUSERKEY && key_blobtype != MM_RSAHOSTKEY)
1302 fatal("%s: key type mismatch", __func__);
1303 if ((key = key_from_blob(blob, blen)) == NULL)
1304 fatal("%s: received bad key", __func__);
1307 BN_clear_free(ssh1_challenge);
1308 ssh1_challenge = auth_rsa_generate_challenge(key);
1311 buffer_put_bignum2(m, ssh1_challenge);
1313 debug3("%s sending reply", __func__);
1314 mm_request_send(socket, MONITOR_ANS_RSACHALLENGE, m);
1316 monitor_permit(mon_dispatch, MONITOR_REQ_RSARESPONSE, 1);
1321 mm_answer_rsa_response(int socket, Buffer *m)
1324 u_char *blob, *response;
1328 debug3("%s entering", __func__);
1330 if (!authctxt->valid)
1331 fatal("%s: authctxt not valid", __func__);
1332 if (ssh1_challenge == NULL)
1333 fatal("%s: no ssh1_challenge", __func__);
1335 blob = buffer_get_string(m, &blen);
1336 if (!monitor_allowed_key(blob, blen))
1337 fatal("%s: bad key, not previously allowed", __func__);
1338 if (key_blobtype != MM_RSAUSERKEY && key_blobtype != MM_RSAHOSTKEY)
1339 fatal("%s: key type mismatch: %d", __func__, key_blobtype);
1340 if ((key = key_from_blob(blob, blen)) == NULL)
1341 fatal("%s: received bad key", __func__);
1342 response = buffer_get_string(m, &len);
1344 fatal("%s: received bad response to challenge", __func__);
1345 success = auth_rsa_verify_response(key, ssh1_challenge, response);
1350 auth_method = key_blobtype == MM_RSAUSERKEY ? "rsa" : "rhosts-rsa";
1353 BN_clear_free(ssh1_challenge);
1354 ssh1_challenge = NULL;
1355 monitor_reset_key_state();
1358 buffer_put_int(m, success);
1359 mm_request_send(socket, MONITOR_ANS_RSARESPONSE, m);
1366 mm_answer_krb4(int socket, Buffer *m)
1368 KTEXT_ST auth, reply;
1373 reply.length = auth.length = 0;
1375 p = buffer_get_string(m, &alen);
1376 if (alen >= MAX_KTXT_LEN)
1377 fatal("%s: auth too large", __func__);
1378 memcpy(auth.dat, p, alen);
1383 success = options.kerberos_authentication &&
1385 auth_krb4(authctxt, &auth, &client, &reply);
1387 memset(auth.dat, 0, alen);
1389 buffer_put_int(m, success);
1392 buffer_put_cstring(m, client);
1393 buffer_put_string(m, reply.dat, reply.length);
1397 memset(reply.dat, 0, reply.length);
1400 debug3("%s: sending result %d", __func__, success);
1401 mm_request_send(socket, MONITOR_ANS_KRB4, m);
1403 auth_method = "kerberos";
1405 /* Causes monitor loop to terminate if authenticated */
1412 mm_answer_krb5(int socket, Buffer *m)
1414 krb5_data tkt, reply;
1419 /* use temporary var to avoid size issues on 64bit arch */
1420 tkt.data = buffer_get_string(m, &len);
1423 success = options.kerberos_authentication &&
1425 auth_krb5(authctxt, &tkt, &client_user, &reply);
1431 buffer_put_int(m, success);
1434 buffer_put_cstring(m, client_user);
1435 buffer_put_string(m, reply.data, reply.length);
1441 mm_request_send(socket, MONITOR_ANS_KRB5, m);
1448 mm_answer_term(int socket, Buffer *req)
1450 extern struct monitor *pmonitor;
1453 debug3("%s: tearing down sessions", __func__);
1455 /* The child is terminating */
1456 session_destroy_all(&mm_session_close);
1458 while (waitpid(pmonitor->m_pid, &status, 0) == -1)
1462 res = WIFEXITED(status) ? WEXITSTATUS(status) : 1;
1464 /* Terminate process */
1469 monitor_apply_keystate(struct monitor *pmonitor)
1472 set_newkeys(MODE_IN);
1473 set_newkeys(MODE_OUT);
1475 packet_set_protocol_flags(child_state.ssh1protoflags);
1476 packet_set_encryption_key(child_state.ssh1key,
1477 child_state.ssh1keylen, child_state.ssh1cipher);
1478 xfree(child_state.ssh1key);
1481 /* for rc4 and other stateful ciphers */
1482 packet_set_keycontext(MODE_OUT, child_state.keyout);
1483 xfree(child_state.keyout);
1484 packet_set_keycontext(MODE_IN, child_state.keyin);
1485 xfree(child_state.keyin);
1488 packet_set_iv(MODE_OUT, child_state.ivout);
1489 xfree(child_state.ivout);
1490 packet_set_iv(MODE_IN, child_state.ivin);
1491 xfree(child_state.ivin);
1494 memcpy(&incoming_stream, &child_state.incoming,
1495 sizeof(incoming_stream));
1496 memcpy(&outgoing_stream, &child_state.outgoing,
1497 sizeof(outgoing_stream));
1499 /* Update with new address */
1500 if (options.compression)
1501 mm_init_compression(pmonitor->m_zlib);
1503 /* Network I/O buffers */
1504 /* XXX inefficient for large buffers, need: buffer_init_from_string */
1505 buffer_clear(&input);
1506 buffer_append(&input, child_state.input, child_state.ilen);
1507 memset(child_state.input, 0, child_state.ilen);
1508 xfree(child_state.input);
1510 buffer_clear(&output);
1511 buffer_append(&output, child_state.output, child_state.olen);
1512 memset(child_state.output, 0, child_state.olen);
1513 xfree(child_state.output);
1517 mm_get_kex(Buffer *m)
1523 kex = xmalloc(sizeof(*kex));
1524 memset(kex, 0, sizeof(*kex));
1525 kex->session_id = buffer_get_string(m, &kex->session_id_len);
1526 if ((session_id2 == NULL) ||
1527 (kex->session_id_len != session_id2_len) ||
1528 (memcmp(kex->session_id, session_id2, session_id2_len) != 0))
1529 fatal("mm_get_get: internal error: bad session id");
1530 kex->we_need = buffer_get_int(m);
1532 kex->hostkey_type = buffer_get_int(m);
1533 kex->kex_type = buffer_get_int(m);
1534 blob = buffer_get_string(m, &bloblen);
1535 buffer_init(&kex->my);
1536 buffer_append(&kex->my, blob, bloblen);
1538 blob = buffer_get_string(m, &bloblen);
1539 buffer_init(&kex->peer);
1540 buffer_append(&kex->peer, blob, bloblen);
1543 kex->flags = buffer_get_int(m);
1544 kex->client_version_string = buffer_get_string(m, NULL);
1545 kex->server_version_string = buffer_get_string(m, NULL);
1546 kex->load_host_key=&get_hostkey_by_type;
1547 kex->host_key_index=&get_hostkey_index;
1552 /* This function requries careful sanity checking */
1555 mm_get_keystate(struct monitor *pmonitor)
1559 u_int bloblen, plen;
1561 debug3("%s: Waiting for new keys", __func__);
1564 mm_request_receive_expect(pmonitor->m_sendfd, MONITOR_REQ_KEYEXPORT, &m);
1566 child_state.ssh1protoflags = buffer_get_int(&m);
1567 child_state.ssh1cipher = buffer_get_int(&m);
1568 child_state.ssh1key = buffer_get_string(&m,
1569 &child_state.ssh1keylen);
1570 child_state.ivout = buffer_get_string(&m,
1571 &child_state.ivoutlen);
1572 child_state.ivin = buffer_get_string(&m, &child_state.ivinlen);
1575 /* Get the Kex for rekeying */
1576 *pmonitor->m_pkex = mm_get_kex(&m);
1579 blob = buffer_get_string(&m, &bloblen);
1580 current_keys[MODE_OUT] = mm_newkeys_from_blob(blob, bloblen);
1583 debug3("%s: Waiting for second key", __func__);
1584 blob = buffer_get_string(&m, &bloblen);
1585 current_keys[MODE_IN] = mm_newkeys_from_blob(blob, bloblen);
1588 /* Now get sequence numbers for the packets */
1589 packet_set_seqnr(MODE_OUT, buffer_get_int(&m));
1590 packet_set_seqnr(MODE_IN, buffer_get_int(&m));
1593 /* Get the key context */
1594 child_state.keyout = buffer_get_string(&m, &child_state.keyoutlen);
1595 child_state.keyin = buffer_get_string(&m, &child_state.keyinlen);
1597 debug3("%s: Getting compression state", __func__);
1598 /* Get compression state */
1599 p = buffer_get_string(&m, &plen);
1600 if (plen != sizeof(child_state.outgoing))
1601 fatal("%s: bad request size", __func__);
1602 memcpy(&child_state.outgoing, p, sizeof(child_state.outgoing));
1605 p = buffer_get_string(&m, &plen);
1606 if (plen != sizeof(child_state.incoming))
1607 fatal("%s: bad request size", __func__);
1608 memcpy(&child_state.incoming, p, sizeof(child_state.incoming));
1611 /* Network I/O buffers */
1612 debug3("%s: Getting Network I/O buffers", __func__);
1613 child_state.input = buffer_get_string(&m, &child_state.ilen);
1614 child_state.output = buffer_get_string(&m, &child_state.olen);
1620 /* Allocation functions for zlib */
1622 mm_zalloc(struct mm_master *mm, u_int ncount, u_int size)
1624 size_t len = size * ncount;
1627 if (len == 0 || ncount > SIZE_T_MAX / size)
1628 fatal("%s: mm_zalloc(%u, %u)", __func__, ncount, size);
1630 address = mm_malloc(mm, len);
1636 mm_zfree(struct mm_master *mm, void *address)
1638 mm_free(mm, address);
1642 mm_init_compression(struct mm_master *mm)
1644 outgoing_stream.zalloc = (alloc_func)mm_zalloc;
1645 outgoing_stream.zfree = (free_func)mm_zfree;
1646 outgoing_stream.opaque = mm;
1648 incoming_stream.zalloc = (alloc_func)mm_zalloc;
1649 incoming_stream.zfree = (free_func)mm_zfree;
1650 incoming_stream.opaque = mm;
1655 #define FD_CLOSEONEXEC(x) do { \
1656 if (fcntl(x, F_SETFD, 1) == -1) \
1657 fatal("fcntl(%d, F_SETFD)", x); \
1661 monitor_socketpair(int *pair)
1663 #ifdef HAVE_SOCKETPAIR
1664 if (socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1)
1665 fatal("%s: socketpair", __func__);
1667 fatal("%s: UsePrivilegeSeparation=yes not supported",
1670 FD_CLOSEONEXEC(pair[0]);
1671 FD_CLOSEONEXEC(pair[1]);
1674 #define MM_MEMSIZE 65536
1679 struct monitor *mon;
1682 mon = xmalloc(sizeof(*mon));
1684 monitor_socketpair(pair);
1686 mon->m_recvfd = pair[0];
1687 mon->m_sendfd = pair[1];
1689 /* Used to share zlib space across processes */
1690 if (options.compression) {
1691 mon->m_zback = mm_create(NULL, MM_MEMSIZE);
1692 mon->m_zlib = mm_create(mon->m_zback, 20 * MM_MEMSIZE);
1694 /* Compression needs to share state across borders */
1695 mm_init_compression(mon->m_zlib);
1702 monitor_reinit(struct monitor *mon)
1706 monitor_socketpair(pair);
1708 mon->m_recvfd = pair[0];
1709 mon->m_sendfd = pair[1];
1715 mm_answer_gss_setup_ctx(int socket, Buffer *m) {
1720 oid.elements=buffer_get_string(m,&len);
1723 major=ssh_gssapi_server_ctx(&gsscontext,&oid);
1725 xfree(oid.elements);
1728 buffer_put_int(m,major);
1730 mm_request_send(socket,MONITOR_ANS_GSSSETUP,m);
1736 mm_answer_gss_accept_ctx(int socket, Buffer *m) {
1737 gss_buffer_desc in,out;
1738 OM_uint32 major,minor;
1739 OM_uint32 flags = 0; /* GSI needs this */
1741 in.value = buffer_get_string(m,&in.length);
1742 major=ssh_gssapi_accept_ctx(gsscontext,&in,&out,&flags);
1746 buffer_put_int(m, major);
1747 buffer_put_string(m, out.value, out.length);
1748 buffer_put_int(m, flags);
1749 mm_request_send(socket,MONITOR_ANS_GSSSTEP,m);
1751 gss_release_buffer(&minor, &out);
1756 mm_answer_gss_userok(int socket, Buffer *m) {
1759 authenticated = authctxt->valid && ssh_gssapi_userok(authctxt->user);
1762 buffer_put_int(m, authenticated);
1764 debug3("%s: sending result %d", __func__, authenticated);
1765 mm_request_send(socket, MONITOR_ANS_GSSUSEROK, m);
1767 auth_method="gssapi";
1769 /* Monitor loop will terminate if authenticated */
1770 return(authenticated);
1773 mm_answer_gss_localname(int socket, Buffer *m) {
1776 ssh_gssapi_localname(&name);
1780 buffer_put_cstring(m, name);
1781 debug3("%s: sending result %s", __func__, name);
1784 buffer_put_cstring(m, "");
1785 debug3("%s: sending result \"\"", __func__);
1788 mm_request_send(socket, MONITOR_ANS_GSSLOCALNAME, m);
1794 mm_answer_gss_sign(int socket, Buffer *m) {
1795 gss_buffer_desc data,hash;
1796 OM_uint32 major,minor;
1798 data.value = buffer_get_string(m,&data.length);
1799 if (data.length != 16) { /* HACK - i.e. we are using SSHv1 */
1800 if (data.length != 20)
1801 fatal("%s: data length incorrect: %d", __func__, data.length);
1803 /* Save the session ID - only first time round */
1804 if (session_id2_len == 0) {
1805 session_id2_len=data.length;
1806 session_id2 = xmalloc(session_id2_len);
1807 memcpy(session_id2, data.value, session_id2_len);
1810 major=ssh_gssapi_sign(gsscontext, &data, &hash);
1815 buffer_put_int(m, major);
1816 buffer_put_string(m, hash.value, hash.length);
1818 mm_request_send(socket,MONITOR_ANS_GSSSIGN,m);
1820 gss_release_buffer(&minor,&hash);
1822 /* Turn on permissions for getpwnam */
1823 monitor_permit(mon_dispatch, MONITOR_REQ_PWNAM, 1);
1829 mm_answer_gss_indicate_mechs(int socket, Buffer *m) {
1830 OM_uint32 major,minor;
1831 gss_OID_set mech_set;
1834 major=gss_indicate_mechs(&minor, &mech_set);
1837 buffer_put_int(m, major);
1838 buffer_put_int(m, mech_set->count);
1839 for (i=0; i < mech_set->count; i++) {
1840 buffer_put_string(m, mech_set->elements[i].elements,
1841 mech_set->elements[i].length);
1844 mm_request_send(socket,MONITOR_ANS_GSSMECHS,m);
1850 mm_answer_gss_display_status(int socket, Buffer *m) {
1851 OM_uint32 major,minor,status_value,message_context;
1853 gss_OID_desc mech_type_desc;
1855 gss_buffer_desc status_string;
1858 status_value = buffer_get_int(m);
1859 status_type = buffer_get_int(m);
1860 mech_type_desc.elements = buffer_get_string(m, &length);
1861 mech_type_desc.length = length;
1863 mech_type = &mech_type_desc;
1864 } else if (gsscontext) {
1865 mech_type = gsscontext->oid;
1867 mech_type = GSS_C_NO_OID;
1869 message_context = buffer_get_int(m);
1871 major=gss_display_status(&minor, status_value, status_type, mech_type,
1872 &message_context, &status_string);
1875 buffer_put_int(m, message_context);
1876 buffer_put_string(m, status_string.value, status_string.length);
1878 mm_request_send(socket,MONITOR_ANS_GSSSTAT,m);
1880 if (mech_type_desc.elements) {
1881 xfree(mech_type_desc.elements);
1892 mm_answer_gsi_gridmap(int socket, Buffer *m) {
1893 char *subject, *name;
1895 subject = buffer_get_string(m, NULL);
1897 gsi_gridmap(subject, &name);
1901 buffer_put_cstring(m, name);
1902 debug3("%s: sending result %s", __func__, name);
1905 buffer_put_cstring(m, "");
1906 debug3("%s: sending result \"\"", __func__);
1909 mm_request_send(socket, MONITOR_ANS_GSIGRIDMAP, m);