summaryrefslogtreecommitdiff
path: root/monitor_wrap.c
diff options
context:
space:
mode:
Diffstat (limited to 'monitor_wrap.c')
-rw-r--r--monitor_wrap.c41
1 files changed, 30 insertions, 11 deletions
diff --git a/monitor_wrap.c b/monitor_wrap.c
index eff912562..b559c77bf 100644
--- a/monitor_wrap.c
+++ b/monitor_wrap.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: monitor_wrap.c,v 1.57 2007/06/07 19:37:34 pvalchev Exp $ */ 1/* $OpenBSD: monitor_wrap.c,v 1.63 2008/07/10 18:08:11 markus Exp $ */
2/* 2/*
3 * Copyright 2002 Niels Provos <provos@citi.umich.edu> 3 * Copyright 2002 Niels Provos <provos@citi.umich.edu>
4 * Copyright 2002 Markus Friedl <markus@openbsd.org> 4 * Copyright 2002 Markus Friedl <markus@openbsd.org>
@@ -41,6 +41,7 @@
41#include <openssl/bn.h> 41#include <openssl/bn.h>
42#include <openssl/dh.h> 42#include <openssl/dh.h>
43 43
44#include "openbsd-compat/sys-queue.h"
44#include "xmalloc.h" 45#include "xmalloc.h"
45#include "ssh.h" 46#include "ssh.h"
46#include "dh.h" 47#include "dh.h"
@@ -222,8 +223,8 @@ mm_getpwnamallow(const char *username)
222 mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PWNAM, &m); 223 mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PWNAM, &m);
223 224
224 if (buffer_get_char(&m) == 0) { 225 if (buffer_get_char(&m) == 0) {
225 buffer_free(&m); 226 pw = NULL;
226 return (NULL); 227 goto out;
227 } 228 }
228 pw = buffer_get_string(&m, &len); 229 pw = buffer_get_string(&m, &len);
229 if (len != sizeof(struct passwd)) 230 if (len != sizeof(struct passwd))
@@ -237,6 +238,7 @@ mm_getpwnamallow(const char *username)
237 pw->pw_dir = buffer_get_string(&m, NULL); 238 pw->pw_dir = buffer_get_string(&m, NULL);
238 pw->pw_shell = buffer_get_string(&m, NULL); 239 pw->pw_shell = buffer_get_string(&m, NULL);
239 240
241out:
240 /* copy options block as a Match directive may have changed some */ 242 /* copy options block as a Match directive may have changed some */
241 newopts = buffer_get_string(&m, &len); 243 newopts = buffer_get_string(&m, &len);
242 if (len != sizeof(*newopts)) 244 if (len != sizeof(*newopts))
@@ -571,7 +573,7 @@ mm_send_keystate(struct monitor *monitor)
571 u_char *blob, *p; 573 u_char *blob, *p;
572 u_int bloblen, plen; 574 u_int bloblen, plen;
573 u_int32_t seqnr, packets; 575 u_int32_t seqnr, packets;
574 u_int64_t blocks; 576 u_int64_t blocks, bytes;
575 577
576 buffer_init(&m); 578 buffer_init(&m);
577 579
@@ -620,14 +622,16 @@ mm_send_keystate(struct monitor *monitor)
620 buffer_put_string(&m, blob, bloblen); 622 buffer_put_string(&m, blob, bloblen);
621 xfree(blob); 623 xfree(blob);
622 624
623 packet_get_state(MODE_OUT, &seqnr, &blocks, &packets); 625 packet_get_state(MODE_OUT, &seqnr, &blocks, &packets, &bytes);
624 buffer_put_int(&m, seqnr); 626 buffer_put_int(&m, seqnr);
625 buffer_put_int64(&m, blocks); 627 buffer_put_int64(&m, blocks);
626 buffer_put_int(&m, packets); 628 buffer_put_int(&m, packets);
627 packet_get_state(MODE_IN, &seqnr, &blocks, &packets); 629 buffer_put_int64(&m, bytes);
630 packet_get_state(MODE_IN, &seqnr, &blocks, &packets, &bytes);
628 buffer_put_int(&m, seqnr); 631 buffer_put_int(&m, seqnr);
629 buffer_put_int64(&m, blocks); 632 buffer_put_int64(&m, blocks);
630 buffer_put_int(&m, packets); 633 buffer_put_int(&m, packets);
634 buffer_put_int64(&m, bytes);
631 635
632 debug3("%s: New keys have been sent", __func__); 636 debug3("%s: New keys have been sent", __func__);
633 skip: 637 skip:
@@ -664,7 +668,20 @@ mm_pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, size_t namebuflen)
664{ 668{
665 Buffer m; 669 Buffer m;
666 char *p, *msg; 670 char *p, *msg;
667 int success = 0; 671 int success = 0, tmp1 = -1, tmp2 = -1;
672
673 /* Kludge: ensure there are fds free to receive the pty/tty */
674 if ((tmp1 = dup(pmonitor->m_recvfd)) == -1 ||
675 (tmp2 = dup(pmonitor->m_recvfd)) == -1) {
676 error("%s: cannot allocate fds for pty", __func__);
677 if (tmp1 > 0)
678 close(tmp1);
679 if (tmp2 > 0)
680 close(tmp2);
681 return 0;
682 }
683 close(tmp1);
684 close(tmp2);
668 685
669 buffer_init(&m); 686 buffer_init(&m);
670 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PTY, &m); 687 mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PTY, &m);
@@ -688,8 +705,9 @@ mm_pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, size_t namebuflen)
688 buffer_append(&loginmsg, msg, strlen(msg)); 705 buffer_append(&loginmsg, msg, strlen(msg));
689 xfree(msg); 706 xfree(msg);
690 707
691 *ptyfd = mm_receive_fd(pmonitor->m_recvfd); 708 if ((*ptyfd = mm_receive_fd(pmonitor->m_recvfd)) == -1 ||
692 *ttyfd = mm_receive_fd(pmonitor->m_recvfd); 709 (*ttyfd = mm_receive_fd(pmonitor->m_recvfd)) == -1)
710 fatal("%s: receive fds failed", __func__);
693 711
694 /* Success */ 712 /* Success */
695 return (1); 713 return (1);
@@ -708,8 +726,9 @@ mm_session_pty_cleanup2(Session *s)
708 buffer_free(&m); 726 buffer_free(&m);
709 727
710 /* closed dup'ed master */ 728 /* closed dup'ed master */
711 if (close(s->ptymaster) < 0) 729 if (s->ptymaster != -1 && close(s->ptymaster) < 0)
712 error("close(s->ptymaster): %s", strerror(errno)); 730 error("close(s->ptymaster/%d): %s",
731 s->ptymaster, strerror(errno));
713 732
714 /* unlink pty from session */ 733 /* unlink pty from session */
715 s->ttyfd = -1; 734 s->ttyfd = -1;