summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2004-08-24 04:10:37 +0000
committerMatt Johnston <matt@ucc.asn.au>2004-08-24 04:10:37 +0000
commitd0473eae68aabb0218d1396ff77c60aa55a1f83d (patch)
tree98aff38c512b4a91aa32ee86aac59914d5bd1ba0
parentbd0f979f3f1d94bd7b2d74f8d31b055cd67e3ca1 (diff)
downloaddropbear-d0473eae68aabb0218d1396ff77c60aa55a1f83d.tar.gz
Allow leading lines before the ident banner when connecting
-rw-r--r--common-session.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/common-session.c b/common-session.c
index 601136f..420e03b 100644
--- a/common-session.c
+++ b/common-session.c
@@ -223,6 +223,7 @@ void session_identification() {
char linebuf[256];
int len = 0;
char done = 0;
+ int i;
/* write our version string, this blocks */
if (atomicio(write, ses.sock, LOCAL_IDENT "\r\n",
@@ -230,14 +231,27 @@ void session_identification() {
dropbear_exit("Error writing ident string");
}
- len = ident_readln(ses.sock, linebuf, 256);
- if (len >= 4 && memcmp(linebuf, "SSH-", 4) == 0) {
- /* start of line matches */
- done = 1;
+ /* We allow up to 9 lines before the actual version string, to
+ * account for wrappers/cruft etc. According to the spec only the client
+ * needs to handle this, but no harm in letting the server handle it too */
+ for (i = 0; i < 10; i++) {
+ len = ident_readln(ses.sock, linebuf, sizzeof(linebuf));
+
+ if (len < 0 && errno != EINTR) {
+ /* It failed */
+ break;
+ }
+
+ if (len >= 4 && memcmp(linebuf, "SSH-", 4) == 0) {
+ /* start of line matches */
+ done = 1;
+ break;
+ }
}
if (!done) {
- dropbear_exit("Failed to get client version");
+ TRACE(("err: %s for '%s'\n", strerror(errno), linebuf));
+ dropbear_exit("Failed to get remote version");
} else {
/* linebuf is already null terminated */
ses.remoteident = m_malloc(len);