summaryrefslogtreecommitdiff
path: root/channels.c
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2001-05-08 20:07:39 +0000
committerBen Lindstrom <mouring@eviladmin.org>2001-05-08 20:07:39 +0000
commit69128668938c82e8d428e77726ef00b2b6f799b9 (patch)
tree1ee834a896b297768505ea963c1ed318dae3efdc /channels.c
parente487d84e03615256aca61431bb9b515db8c2b6e6 (diff)
- markus@cvs.openbsd.org 2001/05/08 19:17:31
[channels.c serverloop.c] adds correct error reporting to async connect()s fixes the server-discards-data-before-connected-bug found by onoe@sm.sony.co.jp
Diffstat (limited to 'channels.c')
-rw-r--r--channels.c80
1 files changed, 58 insertions, 22 deletions
diff --git a/channels.c b/channels.c
index 2bb0e9851..0f3d9ca97 100644
--- a/channels.c
+++ b/channels.c
@@ -40,7 +40,7 @@
40 */ 40 */
41 41
42#include "includes.h" 42#include "includes.h"
43RCSID("$OpenBSD: channels.c,v 1.113 2001/05/04 23:47:33 markus Exp $"); 43RCSID("$OpenBSD: channels.c,v 1.114 2001/05/08 19:17:30 markus Exp $");
44 44
45#include <openssl/rsa.h> 45#include <openssl/rsa.h>
46#include <openssl/dsa.h> 46#include <openssl/dsa.h>
@@ -842,22 +842,47 @@ channel_post_auth_listener(Channel *c, fd_set * readset, fd_set * writeset)
842void 842void
843channel_post_connecting(Channel *c, fd_set * readset, fd_set * writeset) 843channel_post_connecting(Channel *c, fd_set * readset, fd_set * writeset)
844{ 844{
845 int err = 0;
846 int sz = sizeof(err);
847
845 if (FD_ISSET(c->sock, writeset)) { 848 if (FD_ISSET(c->sock, writeset)) {
846 int err = 0; 849 if (getsockopt(c->sock, SOL_SOCKET, SO_ERROR, (char *)&err,
847 int sz = sizeof(err); 850 &sz) < 0) {
848 c->type = SSH_CHANNEL_OPEN; 851 err = errno;
849 if (getsockopt(c->sock, SOL_SOCKET, SO_ERROR, (char *)&err, &sz) < 0) { 852 error("getsockopt SO_ERROR failed");
850 debug("getsockopt SO_ERROR failed"); 853 }
854 if (err == 0) {
855 debug("channel %d: connected", c->self);
856 c->type = SSH_CHANNEL_OPEN;
857 if (compat20) {
858 packet_start(SSH2_MSG_CHANNEL_OPEN_CONFIRMATION);
859 packet_put_int(c->remote_id);
860 packet_put_int(c->self);
861 packet_put_int(c->local_window);
862 packet_put_int(c->local_maxpacket);
863 } else {
864 packet_start(SSH_MSG_CHANNEL_OPEN_CONFIRMATION);
865 packet_put_int(c->remote_id);
866 packet_put_int(c->self);
867 }
851 } else { 868 } else {
852 if (err == 0) { 869 debug("channel %d: not connected: %s",
853 debug("channel %d: connected", c->self); 870 c->self, strerror(err));
871 if (compat20) {
872 packet_start(SSH2_MSG_CHANNEL_OPEN_FAILURE);
873 packet_put_int(c->remote_id);
874 packet_put_int(SSH2_OPEN_CONNECT_FAILED);
875 if (!(datafellows & SSH_BUG_OPENFAILURE)) {
876 packet_put_cstring(strerror(err));
877 packet_put_cstring("");
878 }
854 } else { 879 } else {
855 debug("channel %d: not connected: %s", 880 packet_start(SSH_MSG_CHANNEL_OPEN_FAILURE);
856 c->self, strerror(err)); 881 packet_put_int(c->remote_id);
857 chan_read_failed(c);
858 chan_write_failed(c);
859 } 882 }
883 chan_mark_dead(c);
860 } 884 }
885 packet_send();
861 } 886 }
862} 887}
863 888
@@ -1521,6 +1546,22 @@ channel_input_open_confirmation(int type, int plen, void *ctxt)
1521 } 1546 }
1522} 1547}
1523 1548
1549char *
1550reason2txt(int reason)
1551{
1552 switch(reason) {
1553 case SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED:
1554 return "administratively prohibited";
1555 case SSH2_OPEN_CONNECT_FAILED:
1556 return "connect failed";
1557 case SSH2_OPEN_UNKNOWN_CHANNEL_TYPE:
1558 return "unknown channel type";
1559 case SSH2_OPEN_RESOURCE_SHORTAGE:
1560 return "resource shortage";
1561 }
1562 return "unkown reason";
1563}
1564
1524void 1565void
1525channel_input_open_failure(int type, int plen, void *ctxt) 1566channel_input_open_failure(int type, int plen, void *ctxt)
1526{ 1567{
@@ -1544,8 +1585,8 @@ channel_input_open_failure(int type, int plen, void *ctxt)
1544 lang = packet_get_string(NULL); 1585 lang = packet_get_string(NULL);
1545 } 1586 }
1546 packet_done(); 1587 packet_done();
1547 log("channel_open_failure: %d: reason %d %s", id, 1588 log("channel %d: open failed: %s%s%s", id,
1548 reason, msg ? msg : "<no additional info>"); 1589 reason2txt(reason), msg ? ": ": "", msg ? msg : "");
1549 if (msg != NULL) 1590 if (msg != NULL)
1550 xfree(msg); 1591 xfree(msg);
1551 if (lang != NULL) 1592 if (lang != NULL)
@@ -1671,7 +1712,7 @@ channel_still_open()
1671 case SSH_CHANNEL_CLOSED: 1712 case SSH_CHANNEL_CLOSED:
1672 case SSH_CHANNEL_AUTH_SOCKET: 1713 case SSH_CHANNEL_AUTH_SOCKET:
1673 case SSH_CHANNEL_DYNAMIC: 1714 case SSH_CHANNEL_DYNAMIC:
1674 case SSH_CHANNEL_CONNECTING: /* XXX ??? */ 1715 case SSH_CHANNEL_CONNECTING:
1675 continue; 1716 continue;
1676 case SSH_CHANNEL_LARVAL: 1717 case SSH_CHANNEL_LARVAL:
1677 if (!compat20) 1718 if (!compat20)
@@ -1713,10 +1754,10 @@ channel_find_open()
1713 case SSH_CHANNEL_PORT_LISTENER: 1754 case SSH_CHANNEL_PORT_LISTENER:
1714 case SSH_CHANNEL_RPORT_LISTENER: 1755 case SSH_CHANNEL_RPORT_LISTENER:
1715 case SSH_CHANNEL_OPENING: 1756 case SSH_CHANNEL_OPENING:
1757 case SSH_CHANNEL_CONNECTING:
1716 continue; 1758 continue;
1717 case SSH_CHANNEL_LARVAL: 1759 case SSH_CHANNEL_LARVAL:
1718 case SSH_CHANNEL_AUTH_SOCKET: 1760 case SSH_CHANNEL_AUTH_SOCKET:
1719 case SSH_CHANNEL_CONNECTING: /* XXX ??? */
1720 case SSH_CHANNEL_OPEN: 1761 case SSH_CHANNEL_OPEN:
1721 case SSH_CHANNEL_X11_OPEN: 1762 case SSH_CHANNEL_X11_OPEN:
1722 return i; 1763 return i;
@@ -2168,13 +2209,8 @@ channel_input_port_open(int type, int plen, void *ctxt)
2168 if (c == NULL) { 2209 if (c == NULL) {
2169 packet_start(SSH_MSG_CHANNEL_OPEN_FAILURE); 2210 packet_start(SSH_MSG_CHANNEL_OPEN_FAILURE);
2170 packet_put_int(remote_id); 2211 packet_put_int(remote_id);
2171 } else { 2212 packet_send();
2172 /*XXX delay answer? */
2173 packet_start(SSH_MSG_CHANNEL_OPEN_CONFIRMATION);
2174 packet_put_int(remote_id);
2175 packet_put_int(c->self);
2176 } 2213 }
2177 packet_send();
2178 xfree(host); 2214 xfree(host);
2179} 2215}
2180 2216