comparison common-session.c @ 103:8aeac62a968f

Allow leading lines before the ident banner when connecting
author Matt Johnston <matt@ucc.asn.au>
date Tue, 24 Aug 2004 04:10:37 +0000
parents 18eccbfb9641
children d3eb1fa8484e
comparison
equal deleted inserted replaced
102:6571b480fa04 103:8aeac62a968f
221 221
222 /* max length of 255 chars */ 222 /* max length of 255 chars */
223 char linebuf[256]; 223 char linebuf[256];
224 int len = 0; 224 int len = 0;
225 char done = 0; 225 char done = 0;
226 int i;
226 227
227 /* write our version string, this blocks */ 228 /* write our version string, this blocks */
228 if (atomicio(write, ses.sock, LOCAL_IDENT "\r\n", 229 if (atomicio(write, ses.sock, LOCAL_IDENT "\r\n",
229 strlen(LOCAL_IDENT "\r\n")) == DROPBEAR_FAILURE) { 230 strlen(LOCAL_IDENT "\r\n")) == DROPBEAR_FAILURE) {
230 dropbear_exit("Error writing ident string"); 231 dropbear_exit("Error writing ident string");
231 } 232 }
232 233
233 len = ident_readln(ses.sock, linebuf, 256); 234 /* We allow up to 9 lines before the actual version string, to
234 if (len >= 4 && memcmp(linebuf, "SSH-", 4) == 0) { 235 * account for wrappers/cruft etc. According to the spec only the client
235 /* start of line matches */ 236 * needs to handle this, but no harm in letting the server handle it too */
236 done = 1; 237 for (i = 0; i < 10; i++) {
238 len = ident_readln(ses.sock, linebuf, sizzeof(linebuf));
239
240 if (len < 0 && errno != EINTR) {
241 /* It failed */
242 break;
243 }
244
245 if (len >= 4 && memcmp(linebuf, "SSH-", 4) == 0) {
246 /* start of line matches */
247 done = 1;
248 break;
249 }
237 } 250 }
238 251
239 if (!done) { 252 if (!done) {
240 dropbear_exit("Failed to get client version"); 253 TRACE(("err: %s for '%s'\n", strerror(errno), linebuf));
254 dropbear_exit("Failed to get remote version");
241 } else { 255 } else {
242 /* linebuf is already null terminated */ 256 /* linebuf is already null terminated */
243 ses.remoteident = m_malloc(len); 257 ses.remoteident = m_malloc(len);
244 memcpy(ses.remoteident, linebuf, len); 258 memcpy(ses.remoteident, linebuf, len);
245 } 259 }