diff options
Diffstat (limited to 'sshconnect.c')
-rw-r--r-- | sshconnect.c | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/sshconnect.c b/sshconnect.c index 0ee726637..07800a65f 100644 --- a/sshconnect.c +++ b/sshconnect.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: sshconnect.c,v 1.234 2011/05/24 07:15:47 djm Exp $ */ | 1 | /* $OpenBSD: sshconnect.c,v 1.236 2012/09/14 16:51:34 markus Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -429,6 +429,24 @@ ssh_connect(const char *host, struct sockaddr_storage * hostaddr, | |||
429 | return 0; | 429 | return 0; |
430 | } | 430 | } |
431 | 431 | ||
432 | static void | ||
433 | send_client_banner(int connection_out, int minor1) | ||
434 | { | ||
435 | /* Send our own protocol version identification. */ | ||
436 | if (compat20) { | ||
437 | xasprintf(&client_version_string, "SSH-%d.%d-%.100s\r\n", | ||
438 | PROTOCOL_MAJOR_2, PROTOCOL_MINOR_2, SSH_VERSION); | ||
439 | } else { | ||
440 | xasprintf(&client_version_string, "SSH-%d.%d-%.100s\n", | ||
441 | PROTOCOL_MAJOR_1, minor1, SSH_VERSION); | ||
442 | } | ||
443 | if (roaming_atomicio(vwrite, connection_out, client_version_string, | ||
444 | strlen(client_version_string)) != strlen(client_version_string)) | ||
445 | fatal("write: %.100s", strerror(errno)); | ||
446 | chop(client_version_string); | ||
447 | debug("Local version string %.100s", client_version_string); | ||
448 | } | ||
449 | |||
432 | /* | 450 | /* |
433 | * Waits for the server identification string, and sends our own | 451 | * Waits for the server identification string, and sends our own |
434 | * identification string. | 452 | * identification string. |
@@ -440,7 +458,7 @@ ssh_exchange_identification(int timeout_ms) | |||
440 | int remote_major, remote_minor, mismatch; | 458 | int remote_major, remote_minor, mismatch; |
441 | int connection_in = packet_get_connection_in(); | 459 | int connection_in = packet_get_connection_in(); |
442 | int connection_out = packet_get_connection_out(); | 460 | int connection_out = packet_get_connection_out(); |
443 | int minor1 = PROTOCOL_MINOR_1; | 461 | int minor1 = PROTOCOL_MINOR_1, client_banner_sent = 0; |
444 | u_int i, n; | 462 | u_int i, n; |
445 | size_t len; | 463 | size_t len; |
446 | int fdsetsz, remaining, rc; | 464 | int fdsetsz, remaining, rc; |
@@ -450,6 +468,16 @@ ssh_exchange_identification(int timeout_ms) | |||
450 | fdsetsz = howmany(connection_in + 1, NFDBITS) * sizeof(fd_mask); | 468 | fdsetsz = howmany(connection_in + 1, NFDBITS) * sizeof(fd_mask); |
451 | fdset = xcalloc(1, fdsetsz); | 469 | fdset = xcalloc(1, fdsetsz); |
452 | 470 | ||
471 | /* | ||
472 | * If we are SSH2-only then we can send the banner immediately and | ||
473 | * save a round-trip. | ||
474 | */ | ||
475 | if (options.protocol == SSH_PROTO_2) { | ||
476 | enable_compat20(); | ||
477 | send_client_banner(connection_out, 0); | ||
478 | client_banner_sent = 1; | ||
479 | } | ||
480 | |||
453 | /* Read other side's version identification. */ | 481 | /* Read other side's version identification. */ |
454 | remaining = timeout_ms; | 482 | remaining = timeout_ms; |
455 | for (n = 0;;) { | 483 | for (n = 0;;) { |
@@ -552,18 +580,9 @@ ssh_exchange_identification(int timeout_ms) | |||
552 | fatal("Protocol major versions differ: %d vs. %d", | 580 | fatal("Protocol major versions differ: %d vs. %d", |
553 | (options.protocol & SSH_PROTO_2) ? PROTOCOL_MAJOR_2 : PROTOCOL_MAJOR_1, | 581 | (options.protocol & SSH_PROTO_2) ? PROTOCOL_MAJOR_2 : PROTOCOL_MAJOR_1, |
554 | remote_major); | 582 | remote_major); |
555 | /* Send our own protocol version identification. */ | 583 | if (!client_banner_sent) |
556 | snprintf(buf, sizeof buf, "SSH-%d.%d-%.100s%s", | 584 | send_client_banner(connection_out, minor1); |
557 | compat20 ? PROTOCOL_MAJOR_2 : PROTOCOL_MAJOR_1, | ||
558 | compat20 ? PROTOCOL_MINOR_2 : minor1, | ||
559 | SSH_VERSION, compat20 ? "\r\n" : "\n"); | ||
560 | if (roaming_atomicio(vwrite, connection_out, buf, strlen(buf)) | ||
561 | != strlen(buf)) | ||
562 | fatal("write: %.100s", strerror(errno)); | ||
563 | client_version_string = xstrdup(buf); | ||
564 | chop(client_version_string); | ||
565 | chop(server_version_string); | 585 | chop(server_version_string); |
566 | debug("Local version string %.100s", client_version_string); | ||
567 | } | 586 | } |
568 | 587 | ||
569 | /* defaults to 'no' */ | 588 | /* defaults to 'no' */ |