[Ttssh2-commit] [6717] シェルではなくサブシステムを起動する機能の追加 ticket :37165

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2017年 5月 12日 (金) 21:42:07 JST


Revision: 6717
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/6717
Author:   doda
Date:     2017-05-12 21:42:07 +0900 (Fri, 12 May 2017)
Log Message:
-----------
シェルではなくサブシステムを起動する機能の追加 ticket:37165

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

-------------- next part --------------
Modified: trunk/ttssh2/ttxssh/ssh.c
===================================================================
--- trunk/ttssh2/ttxssh/ssh.c	2017-05-12 12:42:01 UTC (rev 6716)
+++ trunk/ttssh2/ttxssh/ssh.c	2017-05-12 12:42:07 UTC (rev 6717)
@@ -6799,7 +6799,13 @@
 	// FWD_prep_forwarding()\x82\xC5shell ID\x82\xF0\x8Eg\x82\xA4\x82̂ŁA\x90\xE6\x82ɐݒ\xE8\x82\xF0\x8E\x9D\x82\xC1\x82Ă\xAD\x82\xE9\x81B(2005.7.3 yutaka)
 	// changed window size from 64KB to 32KB. (2006.3.6 yutaka)
 	// changed window size from 32KB to 128KB. (2007.10.29 maya)
-	c = ssh2_channel_new(CHAN_SES_WINDOW_DEFAULT, CHAN_SES_PACKET_DEFAULT, TYPE_SHELL, -1);
+	if (pvar->use_subsystem) {
+		c = ssh2_channel_new(CHAN_SES_WINDOW_DEFAULT, CHAN_SES_PACKET_DEFAULT, TYPE_SUBSYSTEM_GEN, -1);
+	}
+	else {
+		c = ssh2_channel_new(CHAN_SES_WINDOW_DEFAULT, CHAN_SES_PACKET_DEFAULT, TYPE_SHELL, -1);
+	}
+
 	if (c == NULL) {
 		UTIL_get_lang_msg("MSG_SSH_NO_FREE_CHANNEL", pvar,
 		                  "Could not open new channel. TTSSH is already opening too many channels.");
@@ -7541,7 +7547,7 @@
 	buffer_put_int(msg, remote_id);
 	if (c->type == TYPE_SCP) {
 		s = "exec";
-	} else if (c->type == TYPE_SFTP) {
+	} else if (c->type == TYPE_SFTP || c->type == TYPE_SUBSYSTEM_GEN) {
 		s = "subsystem";
 	} else {
 		s = "";  // NOT REACHED
@@ -7566,6 +7572,10 @@
 		char *sbuf = "sftp";
 		buffer_put_string(msg, sbuf, strlen(sbuf));
 	}
+	else if (c->type == TYPE_SUBSYSTEM_GEN) {
+		buffer_put_string(msg, pvar->subsystem_name, strlen(pvar->subsystem_name));
+		pvar->session_nego_status = 0;
+	}
 
 	len = buffer_len(msg);
 	outmsg = begin_send_packet(pvar, SSH2_MSG_CHANNEL_REQUEST, len);
@@ -7831,16 +7841,25 @@
 		return FALSE;
 	}
 
-	if (pvar->session_nego_status == 1 && pvar->shell_id == channel_id) {
-		// \x83\x8A\x83\x82\x81[\x83g\x82\xC5 auth-****@opens***** \x82\xAA\x83T\x83|\x81[\x83g\x82\xB3\x82\xEA\x82ĂȂ\xA2\x82̂\xC5
-		// \x83G\x83\x89\x81[\x82͋C\x82ɂ\xB9\x82\xB8\x8E\x9F\x82֐i\x82\xDE
+	if (pvar->shell_id == channel_id) {
+		if (c->type == TYPE_SUBSYSTEM_GEN) {
+			// \x83T\x83u\x83V\x83X\x83e\x83\x80\x82̋N\x93\xAE\x82Ɏ\xB8\x94s\x82\xB5\x82\xBD\x82̂Ő؂\xE9\x81B
+			notify_fatal_error(pvar, "subsystem request failed.", 1);
+			return TRUE;
+		}
+		else { // TYPE_SHELL
+			if (pvar->session_nego_status == 1) {
+				// \x83\x8A\x83\x82\x81[\x83g\x82\xC5 auth-****@opens***** \x82\xAA\x83T\x83|\x81[\x83g\x82\xB3\x82\xEA\x82ĂȂ\xA2\x82̂\xC5
+				// \x83G\x83\x89\x81[\x82͋C\x82ɂ\xB9\x82\xB8\x8E\x9F\x82֐i\x82\xDE
 
-		strncpy_s(buf, sizeof(buf),
-		          "auth-****@opens***** is not supported by remote host.",
-		          _TRUNCATE);
-		notify_verbose_message(pvar, buf, LOG_LEVEL_VERBOSE);
+				strncpy_s(buf, sizeof(buf),
+					  "auth-****@opens***** is not supported by remote host.",
+					  _TRUNCATE);
+				notify_verbose_message(pvar, buf, LOG_LEVEL_VERBOSE);
 
-		return send_pty_request(pvar, c);
+				return send_pty_request(pvar, c);
+			}
+		}
 	}
 
 	ssh2_channel_delete(c);
@@ -8608,7 +8627,7 @@
 	}
 
 	// \x83y\x83C\x83\x8D\x81[\x83h\x82Ƃ\xB5\x82ăN\x83\x89\x83C\x83A\x83\x93\x83g(Tera Term)\x82֓n\x82\xB7
-	if (c->type == TYPE_SHELL) {
+	if (c->type == TYPE_SHELL || c->type == TYPE_SUBSYSTEM_GEN) {
 		pvar->ssh_state.payload_datalen = str_len;
 		pvar->ssh_state.payload_datastart = 8; // id + strlen
 
@@ -8689,7 +8708,7 @@
 	}
 
 	// \x83y\x83C\x83\x8D\x81[\x83h\x82Ƃ\xB5\x82ăN\x83\x89\x83C\x83A\x83\x93\x83g(Tera Term)\x82֓n\x82\xB7
-	if (c->type == TYPE_SHELL) {
+	if (c->type == TYPE_SHELL || c->type == TYPE_SUBSYSTEM_GEN) {
 		pvar->ssh_state.payload_datalen = strlen;
 		pvar->ssh_state.payload_datastart = 12; // id + data_type + strlen
 
@@ -8934,7 +8953,7 @@
 	_snprintf_s(log, sizeof(log), _TRUNCATE, "SSH2_MSG_CHANNEL_CLOSE was received. local:%d remote:%d", c->self_id, c->remote_id);
 	notify_verbose_message(pvar, log, LOG_LEVEL_VERBOSE);
 
-	if (c->type == TYPE_SHELL) {
+	if (c->type == TYPE_SHELL || c->type == TYPE_SUBSYSTEM_GEN) {
 		ssh2_channel_send_close(pvar, c);
 
 		// TCP connection closed

Modified: trunk/ttssh2/ttxssh/ssh.h
===================================================================
--- trunk/ttssh2/ttxssh/ssh.h	2017-05-12 12:42:01 UTC (rev 6716)
+++ trunk/ttssh2/ttxssh/ssh.h	2017-05-12 12:42:07 UTC (rev 6717)
@@ -112,7 +112,7 @@
 #define SSH_PROTOFLAG_HOST_IN_FWD_OPEN 2
 
 enum channel_type {
-	TYPE_SHELL, TYPE_PORTFWD, TYPE_SCP, TYPE_SFTP, TYPE_AGENT,
+	TYPE_SHELL, TYPE_PORTFWD, TYPE_SCP, TYPE_SFTP, TYPE_AGENT, TYPE_SUBSYSTEM_GEN,
 };
 
 // for SSH1

Modified: trunk/ttssh2/ttxssh/ttxssh.c
===================================================================
--- trunk/ttssh2/ttxssh/ttxssh.c	2017-05-12 12:42:01 UTC (rev 6716)
+++ trunk/ttssh2/ttxssh/ttxssh.c	2017-05-12 12:42:07 UTC (rev 6717)
@@ -1930,6 +1930,11 @@
 					else {
 						pvar->settings.IconID = IDI_SECURETT;
 					}
+				} else if (MATCH_STR(option + 4, "-subsystem=") == 0) {
+					pvar->use_subsystem = TRUE;
+					strncpy_s(pvar->subsystem_name,
+					          sizeof(pvar->subsystem_name),
+					          option + 15, _TRUNCATE);
 
 				// /ssh1 \x82\xC6 /ssh2 \x83I\x83v\x83V\x83\x87\x83\x93\x82̐V\x8BK\x92lj\xC1 (2006.9.16 maya)
 				} else if (strcmp(option + 4, "1") == 0) {

Modified: trunk/ttssh2/ttxssh/ttxssh.h
===================================================================
--- trunk/ttssh2/ttxssh/ttxssh.h	2017-05-12 12:42:01 UTC (rev 6716)
+++ trunk/ttssh2/ttxssh/ttxssh.h	2017-05-12 12:42:07 UTC (rev 6717)
@@ -324,6 +324,9 @@
 	unsigned int server_compat_flag;
 
 	void *hostkey_ctx;
+
+	BOOL use_subsystem;
+	char subsystem_name[256];
 } TInstVar;
 
 #define LOG_LEVEL_FATAL      5



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