[Ttssh2-commit] [4682] クライアントとサーバのバージョンが一致しない場合に接続しないようにした

svnno****@sourc***** svnno****@sourc*****
2011年 10月 22日 (土) 00:58:49 JST


Revision: 4682
          http://sourceforge.jp/projects/ttssh2/svn/view?view=rev&revision=4682
Author:   maya
Date:     2011-10-22 00:58:49 +0900 (Sat, 22 Oct 2011)

Log Message:
-----------
クライアントとサーバのバージョンが一致しない場合に接続しないようにした
クライアントが SSH1 でサーバが 1.99 の場合に SSH2 で接続される問題を修正
  http://sourceforge.jp/ticket/browse.php?group_id=1412&tid=26566

Modified Paths:
--------------
    trunk/doc/en/html/about/history.html
    trunk/doc/ja/html/about/history.html
    trunk/installer/release/lang/English.lng
    trunk/installer/release/lang/French.lng
    trunk/installer/release/lang/German.lng
    trunk/installer/release/lang/Japanese.lng
    trunk/ttssh2/ttxssh/ssh.c


-------------- next part --------------
Modified: trunk/doc/en/html/about/history.html
===================================================================
--- trunk/doc/en/html/about/history.html	2011-10-17 15:48:21 UTC (rev 4681)
+++ trunk/doc/en/html/about/history.html	2011-10-21 15:58:49 UTC (rev 4682)
@@ -1745,9 +1745,16 @@
 
 <h3><a name="ttssh_2.59">2011.11.xx (Ver 2.59)</a></h3>
 <ul class="history">
+  <li>Changes
+    <ul>
+      <!--li>ƒT[ƒo‚̃vƒƒgƒRƒ‹ƒo[ƒWƒ‡ƒ“‚ÆŽw’肵‚½ SSH ‚̃o[ƒWƒ‡ƒ“‚ªˆê’v‚µ‚È‚¢ê‡AÚ‘±‚µ‚È‚¢‚悤‚É‚µ‚½B</li-->
+    </ul>
+  </li>
+
   <li>Bug fixes
     <ul>
       <li>The control characters(^A-^_) can be inputed as the password string on the key generator dialog.</li>
+      <!--li>ƒT[ƒo‚̃vƒƒgƒRƒ‹ƒo[ƒWƒ‡ƒ“‚ª 1.99 ‚̏ꍇ‚ɁAƒvƒƒgƒRƒ‹‚É SSH1 ‚ðŽw’肵‚Ä‚à SSH2 ‚Őڑ±‚³‚ê‚é–â‘è‚ðC³‚µ‚½B</li-->
     </ul>
   </li>
 

Modified: trunk/doc/ja/html/about/history.html
===================================================================
--- trunk/doc/ja/html/about/history.html	2011-10-17 15:48:21 UTC (rev 4681)
+++ trunk/doc/ja/html/about/history.html	2011-10-21 15:58:49 UTC (rev 4682)
@@ -1746,9 +1746,16 @@
 
 <h3><a name="ttssh_2.59">2011.11.xx (Ver 2.59)</a></h3>
 <ul class="history">
+  <li>•ÏX
+    <ul>
+      <li>ƒT[ƒo‚̃vƒƒgƒRƒ‹ƒo[ƒWƒ‡ƒ“‚ÆŽw’肵‚½ SSH ‚̃o[ƒWƒ‡ƒ“‚ªˆê’v‚µ‚È‚¢ê‡AÚ‘±‚µ‚È‚¢‚悤‚É‚µ‚½B</li>
+    </ul>
+  </li>
+
   <li>ƒoƒOC³
     <ul>
       <li>Œ®¶¬ƒ_ƒCƒAƒƒO‚ŃpƒXƒ[ƒh‚ɐ§Œä•¶Žš(^A-^_)‚ð“ü—Í‚Å‚«‚é‚悤‚É‚µ‚½B</li>
+      <li>ƒT[ƒo‚̃vƒƒgƒRƒ‹ƒo[ƒWƒ‡ƒ“‚ª 1.99 ‚̏ꍇ‚ɁAƒvƒƒgƒRƒ‹‚É SSH1 ‚ðŽw’肵‚Ä‚à SSH2 ‚Őڑ±‚³‚ê‚é–â‘è‚ðC³‚µ‚½B</li>
     </ul>
   </li>
 

Modified: trunk/installer/release/lang/English.lng
===================================================================
--- trunk/installer/release/lang/English.lng	2011-10-17 15:48:21 UTC (rev 4681)
+++ trunk/installer/release/lang/English.lng	2011-10-21 15:58:49 UTC (rev 4682)
@@ -744,6 +744,7 @@
 MSG_SSH_SERVER_DISCON_ERROR=Server disconnected with message '%s'.%s
 MSG_SSH_SERVER_DISCON_NORES_ERROR=Server disconnected (no reason given).%s
 MSG_SSH_VERSION_ERROR=This program does not understand the server's version of the protocol.
+MSG_SSH_VERSION_MISMATCH=Protocol version mismatch. server:%d.%d client:%d
 MSG_SSH_SEND_ID_ERROR=An error occurred while sending the SSH ID string.\nThe connection will close.
 MSG_SSH_UNEXP_MSG2_ERROR=Unexpected SSH2 message(%d) on current stage(%d)
 MSG_SSH_UNEXP_MSG_ERROR=Unexpected packet type received: %d

Modified: trunk/installer/release/lang/French.lng
===================================================================
--- trunk/installer/release/lang/French.lng	2011-10-17 15:48:21 UTC (rev 4681)
+++ trunk/installer/release/lang/French.lng	2011-10-21 15:58:49 UTC (rev 4682)
@@ -736,6 +736,7 @@
 MSG_SSH_SERVER_DISCON_ERROR=Serveur déconnecté avec le message '%s'.%s
 MSG_SSH_SERVER_DISCON_NORES_ERROR=Serveur déconnecté (cause inconnue).%s
 MSG_SSH_VERSION_ERROR=Ce programme ne comprend pas la version de protocole du serveur.
+MSG_SSH_VERSION_MISMATCH=Protocol version mismatch. server:%d.%d client:%d
 MSG_SSH_SEND_ID_ERROR=Une erreur est survenue en cours d'envoi du SSH ID.\nConnexion coupée.
 MSG_SSH_UNEXP_MSG2_ERROR=Message inattendu de SSH2(%d) à l'étape courante (%d)
 MSG_SSH_UNEXP_MSG_ERROR=Reçu un type de paquet inattendu: %d

Modified: trunk/installer/release/lang/German.lng
===================================================================
--- trunk/installer/release/lang/German.lng	2011-10-17 15:48:21 UTC (rev 4681)
+++ trunk/installer/release/lang/German.lng	2011-10-21 15:58:49 UTC (rev 4682)
@@ -734,6 +734,7 @@
 MSG_SSH_SERVER_DISCON_ERROR=Server disconnected with message '%s'.%s
 MSG_SSH_SERVER_DISCON_NORES_ERROR=Server disconnected (no reason given).%s
 MSG_SSH_VERSION_ERROR=This program does not understand the server's version of the protocol.
+MSG_SSH_VERSION_MISMATCH=Protocol version mismatch. server:%d.%d client:%d
 MSG_SSH_SEND_ID_ERROR=An error occurred while sending the SSH ID string.\nThe connection will close.
 MSG_SSH_UNEXP_MSG2_ERROR=Unexpected SSH2 message(%d) on current stage(%d)
 MSG_SSH_UNEXP_MSG_ERROR=Unexpected packet type received: %d

Modified: trunk/installer/release/lang/Japanese.lng
===================================================================
--- trunk/installer/release/lang/Japanese.lng	2011-10-17 15:48:21 UTC (rev 4681)
+++ trunk/installer/release/lang/Japanese.lng	2011-10-21 15:58:49 UTC (rev 4682)
@@ -744,6 +744,7 @@
 MSG_SSH_SERVER_DISCON_ERROR=ƒT[ƒo‚ÉŽŸ‚Ì——R‚Őؒf‚³‚ê‚Ü‚µ‚½.  '%s'.%s
 MSG_SSH_SERVER_DISCON_NORES_ERROR=ƒT[ƒo‚©‚çØ’f‚³‚ê‚Ü‚µ‚½ (Ø’f——R‚Í‚ ‚è‚Ü‚¹‚ñ). %s
 MSG_SSH_VERSION_ERROR=ƒT[ƒo‚̃vƒƒgƒRƒ‹ƒo[ƒWƒ‡ƒ“‚ª•s–¾‚Å‚·.
+MSG_SSH_VERSION_MISMATCH=ƒvƒƒgƒRƒ‹ƒo[ƒWƒ‡ƒ“‚ªˆê’v‚µ‚Ü‚¹‚ñ. ƒT[ƒo:%d.%d ƒNƒ‰ƒCƒAƒ“ƒg:%d
 MSG_SSH_SEND_ID_ERROR=SSH ID •¶Žš—ñ‘—M’†‚ɃGƒ‰[‚ª”­¶‚µ‚Ü‚µ‚½. \nØ’f‚µ‚Ü‚·.
 MSG_SSH_UNEXP_MSG2_ERROR=Œ»Ý‚̃Xƒe[ƒW‚Å‚Í‘z’èŠO‚ÌSSH2 ƒƒbƒZ[ƒW(%d) ‚Å‚·. (%d)
 MSG_SSH_UNEXP_MSG_ERROR=‘z’èŠO‚ÌŽí•Ê‚̃pƒPƒbƒg‚ðŽóM‚µ‚Ü‚µ‚½: %d

Modified: trunk/ttssh2/ttxssh/ssh.c
===================================================================
--- trunk/ttssh2/ttxssh/ssh.c	2011-10-17 15:48:21 UTC (rev 4681)
+++ trunk/ttssh2/ttxssh/ssh.c	2011-10-21 15:58:49 UTC (rev 4682)
@@ -1605,21 +1605,6 @@
 	pvar->protocol_major = atoi(ID + 4);
 	pvar->protocol_minor = atoi(str + 1);
 
-	// for SSH2(yutaka)
-	// 1.99‚È‚çSSH2‚ł̐ڑ±‚ðs‚¤
-	if (pvar->protocol_major == 1 && pvar->protocol_minor == 99) {
-		// ƒ†[ƒU‚ª SSH2 ‚ð‘I‘ð‚µ‚Ä‚¢‚é‚Ì‚È‚ç‚Î
-		if (pvar->settings.ssh_protocol_version == 2) {
-			pvar->protocol_major = 2;
-			pvar->protocol_minor = 0;
-		}
-
-	}
-
-	// SSH ƒo[ƒWƒ‡ƒ“‚ð teraterm ‘¤‚ɃZƒbƒg‚·‚é
-	// SCP ƒRƒ}ƒ“ƒh‚Ì‚½‚ß (2008.2.3 maya)
-	pvar->cv->isSSH = pvar->protocol_major;
-
 	for (str = str + 1; *str >= '0' && *str <= '9'; str++) {
 	}
 
@@ -1631,22 +1616,41 @@
 protocol number. We replace the fields with the protocol number we will
 actually use, or return FALSE if there is no usable protocol version.
 */
-static BOOL negotiate_protocol(PTInstVar pvar)
+static int negotiate_protocol(PTInstVar pvar)
 {
 	switch (pvar->protocol_major) {
 	case 1:
+		if (pvar->protocol_minor == 99 &&
+		    pvar->settings.ssh_protocol_version == 2) {
+			// ƒT[ƒo‚ª 1.99 ‚ц[ƒU‚ª SSH2 ‚ð‘I‘ð‚µ‚Ä‚¢‚é‚Ì‚È‚ç‚Î
+			// 2.0 Ú‘±‚Æ‚·‚é
+			pvar->protocol_major = 2;
+			pvar->protocol_minor = 0;
+			return 0;
+		}
+
+		if (pvar->settings.ssh_protocol_version == 2) {
+			// ƒo[ƒWƒ‡ƒ“ˆá‚¢
+			return -1;
+		}
+
 		if (pvar->protocol_minor > 5) {
 			pvar->protocol_minor = 5;
 		}
 
-		return TRUE;
+		return 0;
 
 	// for SSH2(yutaka)
 	case 2:
-		return TRUE;			// SSH2 support
+		if (pvar->settings.ssh_protocol_version == 1) {
+			// ƒo[ƒWƒ‡ƒ“ˆá‚¢
+			return -1;
+		}
 
+		return 0;			// SSH2 support
+
 	default:
-		return FALSE;
+		return 1;
 	}
 }
 
@@ -1705,6 +1709,8 @@
 BOOL SSH_handle_server_ID(PTInstVar pvar, char FAR * ID, int ID_len)
 {
 	static char prefix[64];
+	int negotiate;
+	char uimsg[MAX_UIMSG];
 
 	// initialize SSH2 memory dump (2005.3.7 yutaka)
 	init_memdump();
@@ -1753,15 +1759,32 @@
 
 			pvar->ssh_state.server_ID = _strdup(ID);
 
-			if (!parse_protocol_ID(pvar, ID) || !negotiate_protocol(pvar)) {
+			if (!parse_protocol_ID(pvar, ID)) {
 				UTIL_get_lang_msg("MSG_SSH_VERSION_ERROR", pvar,
 				                  "This program does not understand the server's version of the protocol.");
 				notify_fatal_error(pvar, pvar->ts->UIMsg);
-			} else {
+			}
+			else if ((negotiate = negotiate_protocol(pvar)) == 1) {
+				UTIL_get_lang_msg("MSG_SSH_VERSION_ERROR", pvar,
+				                  "This program does not understand the server's version of the protocol.");
+				notify_fatal_error(pvar, pvar->ts->UIMsg);
+			}
+			else if (negotiate == -1) {
+				UTIL_get_lang_msg("MSG_SSH_VERSION_MISMATCH", pvar,
+				                  "Protocol version mismatch. server:%d.%d client:%d");
+				_snprintf_s(uimsg, sizeof(uimsg), _TRUNCATE, pvar->ts->UIMsg,
+				            pvar->protocol_major, pvar->protocol_minor, pvar->settings.ssh_protocol_version);
+				notify_fatal_error(pvar, uimsg);
+			}
+			else {
 				char TTSSH_ID[1024];
 				int TTSSH_ID_len;
 				int a, b, c, d;
 
+				// SSH ƒo[ƒWƒ‡ƒ“‚ð teraterm ‘¤‚ɃZƒbƒg‚·‚é
+				// SCP ƒRƒ}ƒ“ƒh‚Ì‚½‚ß (2008.2.3 maya)
+				pvar->cv->isSSH = pvar->protocol_major;
+
 				// Ž©•ªŽ©g‚̃o[ƒWƒ‡ƒ“‚ðŽæ“¾‚·‚é (2005.3.3 yutaka)
 				get_file_version("ttxssh.dll", &a, &b, &c, &d);
 



Ttssh2-commit メーリングリストの案内