diff options
author | Ben Lindstrom <mouring@eviladmin.org> | 2001-05-08 20:07:39 +0000 |
---|---|---|
committer | Ben Lindstrom <mouring@eviladmin.org> | 2001-05-08 20:07:39 +0000 |
commit | 69128668938c82e8d428e77726ef00b2b6f799b9 (patch) | |
tree | 1ee834a896b297768505ea963c1ed318dae3efdc | |
parent | e487d84e03615256aca61431bb9b515db8c2b6e6 (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
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | channels.c | 80 | ||||
-rw-r--r-- | serverloop.c | 19 |
3 files changed, 74 insertions, 32 deletions
@@ -3,6 +3,11 @@ | |||
3 | - markus@cvs.openbsd.org 2001/05/06 21:23:31 | 3 | - markus@cvs.openbsd.org 2001/05/06 21:23:31 |
4 | [cli.c] | 4 | [cli.c] |
5 | cli_read() fails to catch SIGINT + overflow; from obdb@zzlevo.net | 5 | cli_read() fails to catch SIGINT + overflow; from obdb@zzlevo.net |
6 | - markus@cvs.openbsd.org 2001/05/08 19:17:31 | ||
7 | [channels.c serverloop.c] | ||
8 | adds correct error reporting to async connect()s | ||
9 | fixes the server-discards-data-before-connected-bug found by | ||
10 | onoe@sm.sony.co.jp | ||
6 | 11 | ||
7 | 20010508 | 12 | 20010508 |
8 | - (bal) Fixed configure test for USE_SIA. | 13 | - (bal) Fixed configure test for USE_SIA. |
@@ -5363,4 +5368,4 @@ | |||
5363 | - Wrote replacements for strlcpy and mkdtemp | 5368 | - Wrote replacements for strlcpy and mkdtemp |
5364 | - Released 1.0pre1 | 5369 | - Released 1.0pre1 |
5365 | 5370 | ||
5366 | $Id: ChangeLog,v 1.1206 2001/05/08 20:05:44 mouring Exp $ | 5371 | $Id: ChangeLog,v 1.1207 2001/05/08 20:07:39 mouring Exp $ |
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" |
43 | RCSID("$OpenBSD: channels.c,v 1.113 2001/05/04 23:47:33 markus Exp $"); | 43 | RCSID("$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) | |||
842 | void | 842 | void |
843 | channel_post_connecting(Channel *c, fd_set * readset, fd_set * writeset) | 843 | channel_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 | ||
1549 | char * | ||
1550 | reason2txt(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 | |||
1524 | void | 1565 | void |
1525 | channel_input_open_failure(int type, int plen, void *ctxt) | 1566 | channel_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 | ||
diff --git a/serverloop.c b/serverloop.c index 5b3135564..6a5f40c4b 100644 --- a/serverloop.c +++ b/serverloop.c | |||
@@ -35,7 +35,7 @@ | |||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #include "includes.h" | 37 | #include "includes.h" |
38 | RCSID("$OpenBSD: serverloop.c,v 1.64 2001/05/04 23:47:34 markus Exp $"); | 38 | RCSID("$OpenBSD: serverloop.c,v 1.65 2001/05/08 19:17:31 markus Exp $"); |
39 | 39 | ||
40 | #include "xmalloc.h" | 40 | #include "xmalloc.h" |
41 | #include "packet.h" | 41 | #include "packet.h" |
@@ -890,20 +890,21 @@ server_input_channel_open(int type, int plen, void *ctxt) | |||
890 | c->remote_id = rchan; | 890 | c->remote_id = rchan; |
891 | c->remote_window = rwindow; | 891 | c->remote_window = rwindow; |
892 | c->remote_maxpacket = rmaxpack; | 892 | c->remote_maxpacket = rmaxpack; |
893 | 893 | if (c->type != SSH_CHANNEL_CONNECTING) { | |
894 | packet_start(SSH2_MSG_CHANNEL_OPEN_CONFIRMATION); | 894 | packet_start(SSH2_MSG_CHANNEL_OPEN_CONFIRMATION); |
895 | packet_put_int(c->remote_id); | 895 | packet_put_int(c->remote_id); |
896 | packet_put_int(c->self); | 896 | packet_put_int(c->self); |
897 | packet_put_int(c->local_window); | 897 | packet_put_int(c->local_window); |
898 | packet_put_int(c->local_maxpacket); | 898 | packet_put_int(c->local_maxpacket); |
899 | packet_send(); | 899 | packet_send(); |
900 | } | ||
900 | } else { | 901 | } else { |
901 | debug("server_input_channel_open: failure %s", ctype); | 902 | debug("server_input_channel_open: failure %s", ctype); |
902 | packet_start(SSH2_MSG_CHANNEL_OPEN_FAILURE); | 903 | packet_start(SSH2_MSG_CHANNEL_OPEN_FAILURE); |
903 | packet_put_int(rchan); | 904 | packet_put_int(rchan); |
904 | packet_put_int(SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED); | 905 | packet_put_int(SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED); |
905 | if (!(datafellows & SSH_BUG_OPENFAILURE)) { | 906 | if (!(datafellows & SSH_BUG_OPENFAILURE)) { |
906 | packet_put_cstring("bla bla"); | 907 | packet_put_cstring("open failed"); |
907 | packet_put_cstring(""); | 908 | packet_put_cstring(""); |
908 | } | 909 | } |
909 | packet_send(); | 910 | packet_send(); |