comparison common-session.c @ 275:7f9adaf85fca

Exit with a message if the ssh protocol version is incompatible
author Matt Johnston <matt@ucc.asn.au>
date Sat, 04 Mar 2006 08:22:16 +0000
parents 3311f4aa52cb
children bf29e6659fb9
comparison
equal deleted inserted replaced
274:8438ff0cdb74 275:7f9adaf85fca
230 if (atomicio(write, ses.sock, LOCAL_IDENT "\r\n", 230 if (atomicio(write, ses.sock, LOCAL_IDENT "\r\n",
231 strlen(LOCAL_IDENT "\r\n")) == DROPBEAR_FAILURE) { 231 strlen(LOCAL_IDENT "\r\n")) == DROPBEAR_FAILURE) {
232 dropbear_exit("Error writing ident string"); 232 dropbear_exit("Error writing ident string");
233 } 233 }
234 234
235 /* We allow up to 9 lines before the actual version string, to 235 /* If they send more than 50 lines, something is wrong */
236 * account for wrappers/cruft etc. According to the spec only the client 236 for (i = 0; i < 50; i++) {
237 * needs to handle this, but no harm in letting the server handle it too */
238 for (i = 0; i < 10; i++) {
239 len = ident_readln(ses.sock, linebuf, sizeof(linebuf)); 237 len = ident_readln(ses.sock, linebuf, sizeof(linebuf));
240 238
241 if (len < 0 && errno != EINTR) { 239 if (len < 0 && errno != EINTR) {
242 /* It failed */ 240 /* It failed */
243 break; 241 break;
256 } else { 254 } else {
257 /* linebuf is already null terminated */ 255 /* linebuf is already null terminated */
258 ses.remoteident = m_malloc(len); 256 ses.remoteident = m_malloc(len);
259 memcpy(ses.remoteident, linebuf, len); 257 memcpy(ses.remoteident, linebuf, len);
260 } 258 }
259
260 /* Shall assume that 2.x will be backwards compatible. */
261 if (strncmp(ses.remoteident, "SSH-2.", 6) != 0
262 && strncmp(ses.remoteident, "SSH-1.99-", 9) != 0) {
263 dropbear_exit("Incompatible remote version '%s'", ses.remoteident);
264 }
261 265
262 TRACE(("remoteident: %s", ses.remoteident)) 266 TRACE(("remoteident: %s", ses.remoteident))
263 267
264 } 268 }
265 269