[ttssh2-commit] [9554] D&DによるSCP送信で、多数のファイルを一括送信するとエラーになる問題を修正した。

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2021年 12月 3日 (金) 21:12:04 JST


Revision: 9554
          https://osdn.net/projects/ttssh2/scm/svn/commits/9554
Author:   youlab
Date:     2021-12-03 21:12:03 +0900 (Fri, 03 Dec 2021)
Log Message:
-----------
D&DによるSCP送信で、多数のファイルを一括送信するとエラーになる問題を修正した。
sshd_configのMaxSessions=10の場合、10個目の送信でエラーとなっていた。

Feedback from 
r8924

Revision Links:
--------------
    https://osdn.net/projects/ttssh2/scm/svn/commits/8924

Modified Paths:
--------------
    trunk/doc/en/html/about/history.html
    trunk/doc/ja/html/about/history.html
    trunk/teraterm/common/tttypes.h
    trunk/teraterm/teraterm/vtwin.cpp
    trunk/ttssh2/ttxssh/ssh.c
    trunk/ttssh2/ttxssh/ssh.h
    trunk/ttssh2/ttxssh/ttxssh.c
    trunk/ttssh2/ttxssh/ttxssh.def

Property Changed:
----------------
    trunk/
    trunk/teraterm/

-------------- next part --------------
Index: trunk
===================================================================
--- trunk	2021-12-03 11:43:08 UTC (rev 9553)
+++ trunk	2021-12-03 12:12:03 UTC (rev 9554)

Property changes on: trunk
___________________________________________________________________
Modified: svn:mergeinfo
## -1,4 +1,4 ##
-/branches/4-stable:9256-9257
+/branches/4-stable:8924,9256-9257
 /branches/drag_and_drop:7130,7139,7141,7143-7147
 /branches/flowctrl_dsrdtr:7825-7827
 /branches/move_code_script:9026-9185
Modified: trunk/doc/en/html/about/history.html
===================================================================
--- trunk/doc/en/html/about/history.html	2021-12-03 11:43:08 UTC (rev 9553)
+++ trunk/doc/en/html/about/history.html	2021-12-03 12:12:03 UTC (rev 9554)
@@ -3280,6 +3280,7 @@
     <ul>
       <li>When the Virtual Store is enabled on Windows Vista or later and the Host key rotation is enabled,  the original host key is accidentally deleted from known_hosts file.</li>
       <li>When the Virtual Store is enabled on Windows Vista or later and the host key type is same but key contents is different,  the host key can not be deleted from known_hosts file.</li>
+      <li>When many files are sent in a batch by using D&D's SCP sending, an error occurs.</li>
     </ul>
   </li>
 

Modified: trunk/doc/ja/html/about/history.html
===================================================================
--- trunk/doc/ja/html/about/history.html	2021-12-03 11:43:08 UTC (rev 9553)
+++ trunk/doc/ja/html/about/history.html	2021-12-03 12:12:03 UTC (rev 9554)
@@ -3286,6 +3286,7 @@
     <ul>
       <li>Windows Vista\x88ȍ~\x82\xC5Virtual Store\x82\xAA\x97L\x8C\xF8\x82̏ꍇ\x82ł\xA9\x82\xC2Host key rotation\x82\xAA\x97L\x8C\xF8\x82̏ꍇ\x81Aknown_hosts\x82\xA9\x82猳\x81X\x82\xA0\x82\xC1\x82\xBD\x83z\x83X\x83g\x8C\xAE\x82\xF0\x8D폜\x82\xB5\x82Ă\xB5\x82܂\xA4\x96\xE2\x91\xE8\x82\xF0\x8FC\x90\xB3\x82\xB5\x82\xBD\x81B</li>
       <li>Windows Vista\x88ȍ~\x82\xC5Virtual Store\x82\xAA\x97L\x8C\xF8\x82̏ꍇ\x81A\x83z\x83X\x83g\x8C\xAE\x82̎\xED\x97ނ\xAA\x93\xAF\x82\xB6\x82ŁA\x8C\xAE\x82̓\xE0\x97e\x82\xAA\x88قȂ\xE9\x82Ƃ\xAB\x82ɁAknown_hosts\x82\xA9\x82\xE7\x82̌\xAE\x8D폜\x82\xAA\x82ł\xAB\x82Ȃ\xA2\x96\xE2\x91\xE8\x82\xF0\x8FC\x90\xB3\x82\xB5\x82\xBD\x81B</li>
+      <li>D&D\x82ɂ\xE6\x82\xE9SCP\x91\x97\x90M\x82ŁA\x91\xBD\x90\x94\x82̃t\x83@\x83C\x83\x8B\x82\xF0\x88ꊇ\x91\x97\x90M\x82\xB7\x82\xE9\x82ƃG\x83\x89\x81[\x82ɂȂ\xE9\x96\xE2\x91\xE8\x82\xF0\x8FC\x90\xB3\x82\xB5\x82\xBD\x81B</li>
     </ul>
   </li>
 

Index: trunk/teraterm
===================================================================
--- trunk/teraterm	2021-12-03 11:43:08 UTC (rev 9553)
+++ trunk/teraterm	2021-12-03 12:12:03 UTC (rev 9554)

Property changes on: trunk/teraterm
___________________________________________________________________
Modified: svn:mergeinfo
## -1,4 +1,4 ##
-/branches/4-stable/teraterm:9256-9257
+/branches/4-stable/teraterm:8924,9256-9257
 /branches/drag_and_drop/teraterm:7130,7139,7141,7143-7147
 /branches/flowctrl_dsrdtr/teraterm:7825-7827
 /branches/move_code_script/teraterm:9026-9185
Modified: trunk/teraterm/common/tttypes.h
===================================================================
--- trunk/teraterm/common/tttypes.h	2021-12-03 11:43:08 UTC (rev 9553)
+++ trunk/teraterm/common/tttypes.h	2021-12-03 12:12:03 UTC (rev 9554)
@@ -46,6 +46,7 @@
 #define IdPrnProcTimer       9
 #define IdCancelConnectTimer 10  // add (2007.1.10 yutaka)
 #define IdPasteDelayTimer    11
+#define IdScpSendingTimer    12
 
   /* Window Id */
 #define IdVT  1

Modified: trunk/teraterm/teraterm/vtwin.cpp
===================================================================
--- trunk/teraterm/teraterm/vtwin.cpp	2021-12-03 11:43:08 UTC (rev 9553)
+++ trunk/teraterm/teraterm/vtwin.cpp	2021-12-03 12:12:03 UTC (rev 9554)
@@ -125,6 +125,11 @@
 
 static int AutoDisconnectedPort = -1;
 
+static BOOL SendScpDoing;
+static WCHAR **DropListsSendScp;
+static int DropListCountSendScp;
+static int DropListsSendScpIndex;
+
 UnicodeDebugParam_t UnicodeDebugParam;
 typedef struct {
 	char dbcs_lead_byte;
@@ -1571,9 +1576,12 @@
 static bool SendScp(wchar_t *Filenames[], int FileCount, const char *SendDir)
 {
 	typedef int (CALLBACK *PSSH_start_scp)(char *, char *);
+	typedef int(CALLBACK * PSSH_scp_sending_status)(void);
 	static PSSH_start_scp func = NULL;
+	static PSSH_scp_sending_status func_status = NULL;
 	static HMODULE h = NULL;
 	char msg[128];
+	char *FileName;
 
 	if (h == NULL) {
 		if ( ((h = GetModuleHandle("ttxssh.dll")) == NULL) ) {
@@ -1590,15 +1598,36 @@
 			goto scp_send_error;
 		}
 	}
+	if (func_status == NULL) {
+		func_status = (PSSH_scp_sending_status)GetProcAddress(h, "TTXScpSendingStatus");
+		if (func_status == NULL) {
+			_snprintf_s(msg, sizeof(msg), _TRUNCATE, "GetProcAddress(\"TTXScpSendingStatus\")) %d", GetLastError());
+			goto scp_send_error;
+		}
+	}
 
-	for (int i = 0; i < FileCount; i++) {
-		char *FileName = ToU8W(Filenames[i]);
-		func(FileName, ts.ScpSendDir);
-		free(FileName);
+	if (SendScpDoing) {
+		if (func_status()) {
+			return false;
+		}
+		else {
+			DropListsSendScpIndex++;
+		}
 	}
+
+	FileName = ToU8W(Filenames[0]);
+	func(FileName, ts.ScpSendDir);
+	free(FileName);
+
 	return true;
 }
 
+static void StartSendScpTimer(void)
+{
+	DropListsSendScpIndex = 0;
+	SetTimer(HVTWin, IdScpSendingTimer, 100, NULL);
+}
+
 void CVTWindow::DropListFree()
 {
 	if (DropListCount > 0) {
@@ -1767,14 +1796,40 @@
 		}
 		case DROP_TYPE_SCP:
 		{
-			// send by scp
-			wchar_t **FileNames = &DropLists[i];
-			int FileCount = DoSameProcess ? DropListCount - i : 1;
-			if (!SendScp(FileNames, FileCount, ts.ScpSendDir)) {
+			// \x82\xB7\x82ł\xC9SCP\x91\x97\x90M\x92\x86\x82Ȃ牽\x82\xE0\x82\xB5\x82Ȃ\xA2\x81B
+			if (SendScpDoing) {
+				// do nothing.
 				goto finish;
 			}
-			i += FileCount - 1;
-			break;
+			else {
+				// \x88ꊇ\x91\x97\x90M\x82̏ꍇ\x82̓^\x83C\x83}\x81[\x8F\x88\x97\x9D\x82\xF0\x8Ds\x82\xA4\x82\xB1\x82ƂŁA\x98A\x91\xB1\x91\x97\x90M\x82ɂ\xE6\x82\xE9
+				// \x83G\x83\x89\x81[\x82\xAA\x8BN\x82\xB1\x82\xE7\x82Ȃ\xA2\x82悤\x82ɂ\xB7\x82\xE9\x81B
+				if (DoSameProcess) {
+					int j;
+
+					DropListCountSendScp = DropListCount - i;
+					DropListsSendScp = (wchar_t **)malloc(sizeof(wchar_t *) * DropListCountSendScp);
+
+					for (j = 0; j < DropListCountSendScp; j++) {
+						DropListsSendScp[j] = _wcsdup(DropLists[j]);
+					}
+					SendScpDoing = TRUE;
+
+					StartSendScpTimer();
+					goto finish;
+				}
+				else {
+					// send by scp
+					wchar_t **FileNames = &DropLists[i];
+					int FileCount = 1;
+					if (!SendScp(FileNames, FileCount, ts.ScpSendDir)) {
+						goto finish;
+					}
+					i += FileCount - 1;
+					break;
+				}
+			}
+
 		}
 		}
 	}
@@ -2612,7 +2667,33 @@
 			//::PostMessage(HVTWin, WM_USER_COMMNOTIFY, 0, FD_CLOSE);
 		}
 	}
+	else if (nIDEvent == IdScpSendingTimer) {
+		wchar_t **FileNames;
+		int FileCount;
+		int j;
 
+		if (DropListsSendScpIndex >= DropListCountSendScp) {
+			::KillTimer(HVTWin, IdScpSendingTimer);
+
+			for (j = 0; j < DropListCountSendScp; j++) {
+				free(DropListsSendScp[j]);
+				DropListsSendScp[j] = NULL;
+			}
+			free(DropListsSendScp);
+			DropListCountSendScp = 0;
+
+			SendScpDoing = FALSE;
+		}
+		else {
+			FileNames = &DropListsSendScp[DropListsSendScpIndex];
+			FileCount = DropListCountSendScp;
+
+			SendScp(FileNames, FileCount, ts.ScpSendDir);
+		}
+
+		return;
+	}
+
 	::KillTimer(HVTWin, nIDEvent);
 
 	switch (nIDEvent) {

Modified: trunk/ttssh2/ttxssh/ssh.c
===================================================================
--- trunk/ttssh2/ttxssh/ssh.c	2021-12-03 11:43:08 UTC (rev 9553)
+++ trunk/ttssh2/ttxssh/ssh.c	2021-12-03 12:12:03 UTC (rev 9554)
@@ -99,6 +99,8 @@
 
 static CRITICAL_SECTION g_ssh_scp_lock;   /* SCP\x8E\xF3\x90M\x97p\x83\x8D\x83b\x83N */
 
+static int g_scp_sending;  /* SCP\x91\x97\x90M\x92\x86\x82\xA9? */
+
 static void try_send_credentials(PTInstVar pvar);
 static void prep_compression(PTInstVar pvar);
 
@@ -357,6 +359,8 @@
 		// Windows9x\x82ŗ\x8E\x82\xBF\x82\xE9\x96\xE2\x91\xE8\x82\xF0\x8FC\x90\xB3\x82\xB5\x82\xBD\x81B
 		if (c->scp.dir == FROMREMOTE)
 			ssh2_scp_free_packetlist(c);
+
+		g_scp_sending = FALSE;
 	}
 	if (c->type == TYPE_AGENT) {
 		buffer_free(c->agent_msg);
@@ -4254,6 +4258,8 @@
 	finish_send_packet(pvar);
 	buffer_free(msg);
 
+	g_scp_sending = TRUE;
+
 	logputs(LOG_LEVEL_VERBOSE, "SSH2_MSG_CHANNEL_OPEN was sent at SSH_scp_transaction().");
 
 	return TRUE;
@@ -4272,6 +4278,11 @@
 	return SSH_scp_transaction(pvar, sendfile, dstfile, TOREMOTE);
 }
 
+int SSH_scp_sending_status(void)
+{
+	return g_scp_sending;
+}
+
 int SSH_start_scp_receive(PTInstVar pvar, char *filename)
 {
 	return SSH_scp_transaction(pvar, filename, NULL, FROMREMOTE);

Modified: trunk/ttssh2/ttxssh/ssh.h
===================================================================
--- trunk/ttssh2/ttxssh/ssh.h	2021-12-03 11:43:08 UTC (rev 9553)
+++ trunk/ttssh2/ttxssh/ssh.h	2021-12-03 12:12:03 UTC (rev 9554)
@@ -478,6 +478,7 @@
                       char *originator, unsigned short originator_port);
 
 int SSH_start_scp(PTInstVar pvar, char *sendfile, char *dstfile);
+int SSH_scp_sending_status(void);
 int SSH_start_scp_receive(PTInstVar pvar, char *filename);
 int SSH_scp_transaction(PTInstVar pvar, char *sendfile, char *dstfile, enum scp_dir direction);
 int SSH_sftp_transaction(PTInstVar pvar);

Modified: trunk/ttssh2/ttxssh/ttxssh.c
===================================================================
--- trunk/ttssh2/ttxssh/ttxssh.c	2021-12-03 11:43:08 UTC (rev 9553)
+++ trunk/ttssh2/ttxssh/ttxssh.c	2021-12-03 12:12:03 UTC (rev 9554)
@@ -3439,6 +3439,11 @@
 	return SSH_start_scp(pvar, filename, dstfile);
 }
 
+__declspec(dllexport) int CALLBACK TTXScpSendingStatus(void)
+{
+	return SSH_scp_sending_status();
+}
+
 __declspec(dllexport) int CALLBACK TTXScpReceivefile(char *remotefile, char *localfile)
 {
 	return SSH_scp_transaction(pvar, remotefile, localfile, FROMREMOTE);

Modified: trunk/ttssh2/ttxssh/ttxssh.def
===================================================================
--- trunk/ttssh2/ttxssh/ttxssh.def	2021-12-03 11:43:08 UTC (rev 9553)
+++ trunk/ttssh2/ttxssh/ttxssh.def	2021-12-03 12:12:03 UTC (rev 9554)
@@ -4,4 +4,5 @@
 	TTXScpSendfile @1
 	TTXScpReceivefile @2
 	TTXReadKnownHostsFile @3
+	TTXScpSendingStatus @4
 	
\ No newline at end of file


ttssh2-commit メーリングリストの案内
Back to archive index