[Ttssh2-commit] [6844] SSH channel open 要求の結果を Forwarding Filter に渡すようにした。

svnno****@sourc***** svnno****@sourc*****
2017年 7月 5日 (水) 00:02:54 JST


Revision: 6844
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/6844
Author:   doda
Date:     2017-07-05 00:02:54 +0900 (Wed, 05 Jul 2017)
Log Message:
-----------
SSH channel open 要求の結果を Forwarding Filter に渡すようにした。

SSH2_MSG_CHANNEL_OPEN_FAILURE を受けた時に FWD_failed_open() を呼ぶようにした。
FWD_free_channel() の呼び出しを削除。(FWD_failed_open() の中で呼ばれる)

Modified Paths:
--------------
    trunk/ttssh2/ttxssh/fwd.c
    trunk/ttssh2/ttxssh/fwd.h
    trunk/ttssh2/ttxssh/ssh.c

-------------- next part --------------
Modified: trunk/ttssh2/ttxssh/fwd.c
===================================================================
--- trunk/ttssh2/ttxssh/fwd.c	2017-07-04 15:02:48 UTC (rev 6843)
+++ trunk/ttssh2/ttxssh/fwd.c	2017-07-04 15:02:54 UTC (rev 6844)
@@ -1517,11 +1517,27 @@
 {
 	SOCKET s;
 	FWDChannel *channel;
+	FwdFilterResult action = FWD_FILTER_RETAIN;
 
 	if (!FWD_check_local_channel_num(pvar, local_channel_num))
 		return;
 
 	channel = pvar->fwd_state.channels + local_channel_num;
+
+	if (channel->filter != NULL) {
+		action = channel->filter(channel->filter_closure, FWD_FILTER_OPENCONFIRM, NULL, NULL);
+		switch (action) {
+		case FWD_FILTER_REMOVE:
+			channel->filter(channel->filter_closure, FWD_FILTER_CLEANUP, NULL, NULL);
+			channel->filter = NULL;
+			channel->filter_closure = NULL;
+			break;
+		case FWD_FILTER_CLOSECHANNEL:
+			closed_local_connection(pvar, local_channel_num);
+			break;
+		}
+	}
+
 	s = channel->local_socket;
 	if (s != INVALID_SOCKET) {
 		channel->remote_num = remote_channel_num;
@@ -1535,15 +1551,28 @@
 	}
 }
 
-void FWD_failed_open(PTInstVar pvar, uint32 local_channel_num)
+void FWD_failed_open(PTInstVar pvar, uint32 local_channel_num, int reason)
 {
+	FWDChannel *channel;
+	int r = reason;
+
 	if (!FWD_check_local_channel_num(pvar, local_channel_num))
 		return;
 
-	UTIL_get_lang_msg("MSG_FWD_DENIED_BY_SERVER_ERROR", pvar,
-	                  "A program on the local machine attempted to connect to a forwarded port.\n"
-	                  "The forwarding request was denied by the server. The connection has been closed.");
-	notify_nonfatal_error(pvar, pvar->ts->UIMsg);
+	channel = pvar->fwd_state.channels + local_channel_num;
+
+	// SSH2 \x82ł͌Ăяo\x82\xB5\x8C\xB3\x82Ŋ\xF9\x82Ƀ|\x83b\x83v\x83A\x83b\x83v\x82\xF0\x8Fo\x82\xB5\x82Ă\xA2\x82\xE9\x82̂ŁA
+	// \x82\xB1\x82\xB1\x82ł\xCD SSH1 \x82̎\x9E\x82̂݃|\x83b\x83v\x83A\x83b\x83v\x82\xF0\x8Fo\x82\xB7
+	if (SSHv1(pvar)) {
+		UTIL_get_lang_msg("MSG_FWD_DENIED_BY_SERVER_ERROR", pvar,
+		                  "A program on the local machine attempted to connect to a forwarded port.\n"
+		                  "The forwarding request was denied by the server. The connection has been closed.");
+		notify_nonfatal_error(pvar, pvar->ts->UIMsg);
+	}
+
+	if (channel->filter != NULL) {
+		channel->filter(channel->filter_closure, FWD_FILTER_OPENFAILURE, &r, NULL);
+	}
 	FWD_free_channel(pvar, local_channel_num);
 }
 

Modified: trunk/ttssh2/ttxssh/fwd.h
===================================================================
--- trunk/ttssh2/ttxssh/fwd.h	2017-07-04 15:02:48 UTC (rev 6843)
+++ trunk/ttssh2/ttxssh/fwd.h	2017-07-04 15:02:54 UTC (rev 6844)
@@ -50,6 +50,8 @@
 
 typedef enum {
 	FWD_FILTER_CLEANUP,
+	FWD_FILTER_OPENCONFIRM,
+	FWD_FILTER_OPENFAILURE,
 	FWD_FILTER_FROM_CLIENT,
 	FWD_FILTER_FROM_SERVER
 } FwdFilterEvent;
@@ -143,7 +145,7 @@
                   int *chan_num);
 void FWD_confirmed_open(PTInstVar pvar, uint32 local_channel_num,
   uint32 remote_channel_num);
-void FWD_failed_open(PTInstVar pvar, uint32 local_channel_num);
+void FWD_failed_open(PTInstVar pvar, uint32 local_channel_num, int reason);
 void FWD_received_data(PTInstVar pvar, uint32 local_channel_num,
   unsigned char *data, int length);
 void FWD_channel_input_eof(PTInstVar pvar, uint32 local_channel_num);

Modified: trunk/ttssh2/ttxssh/ssh.c
===================================================================
--- trunk/ttssh2/ttxssh/ssh.c	2017-07-04 15:02:48 UTC (rev 6843)
+++ trunk/ttssh2/ttxssh/ssh.c	2017-07-04 15:02:54 UTC (rev 6844)
@@ -1946,7 +1946,7 @@
 static BOOL handle_channel_open_failure(PTInstVar pvar)
 {
 	if (grab_payload(pvar, 4)) {
-		FWD_failed_open(pvar, get_payload_uint32(pvar, 0));
+		FWD_failed_open(pvar, get_payload_uint32(pvar, 0), -1);
 	}
 	return FALSE;
 }
@@ -7688,9 +7688,8 @@
 
 	free(cstring);
 
-	// \x93]\x91\x97\x83`\x83\x83\x83l\x83\x8B\x93\xE0\x82ɂ\xA0\x82\xE9\x83\\x83P\x83b\x83g\x82̉\xF0\x95\xFA\x98R\x82\xEA\x82\xF0\x8FC\x90\xB3 (2007.7.26 maya)
 	if (c->type == TYPE_PORTFWD) {
-		FWD_free_channel(pvar, c->local_num);
+		FWD_failed_open(pvar, c->local_num, reason);
 	}
 
 	// \x83`\x83\x83\x83l\x83\x8B\x82̉\xF0\x95\xFA\x98R\x82\xEA\x82\xF0\x8FC\x90\xB3 (2007.5.1 maya)



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