[Ttssh2-commit] [6811] SSH2_MSG_CHANNEL_REQUEST の取り扱いまわりを修正

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2017年 6月 19日 (月) 21:51:25 JST


Revision: 6811
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/6811
Author:   doda
Date:     2017-06-19 21:51:25 +0900 (Mon, 19 Jun 2017)
Log Message:
-----------
SSH2_MSG_CHANNEL_REQUEST の取り扱いまわりを修正

・want_reply が 1 の時にログが文字化けするのを修正
・exit-status をログに記録
・keepa****@opens***** を受けた時に SSH2_MSG_CHANNEL_SUCCESS を返すようにした (意味無いけれど)

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

-------------- next part --------------
Modified: trunk/ttssh2/ttxssh/ssh.c
===================================================================
--- trunk/ttssh2/ttxssh/ssh.c	2017-06-19 12:51:04 UTC (rev 6810)
+++ trunk/ttssh2/ttxssh/ssh.c	2017-06-19 12:51:25 UTC (rev 6811)
@@ -8895,12 +8895,9 @@
 	int len;
 	char *data;
 	int id;
-	int buflen;
-	char *str;
-	int reply;
+	char *request;
+	int want_reply;
 	int success = 0;
-	char *emsg = "exit-status";
-	int estat = 0;
 	Channel_t *c;
 
 	// 6byte\x81i\x83T\x83C\x83Y\x81{\x83p\x83f\x83B\x83\x93\x83O\x81{\x83^\x83C\x83v\x81j\x82\xF0\x8E\xE6\x82菜\x82\xA2\x82\xBD\x88ȍ~\x82̃y\x83C\x83\x8D\x81[\x83h
@@ -8908,9 +8905,7 @@
 	// \x83p\x83P\x83b\x83g\x83T\x83C\x83Y - (\x83p\x83f\x83B\x83\x93\x83O\x83T\x83C\x83Y+1)\x81G\x90^\x82̃p\x83P\x83b\x83g\x83T\x83C\x83Y
 	len = pvar->ssh_state.payloadlen;
 
-	//debug_print(98, data, len);
-
-	// ID(4) + string(any) + reply(1) + exit status(4)
+	// ID(4) + string(any) + want_reply(1) + exit status(4)
 	id = get_uint32_MSBfirst(data);
 	data += 4;
 	c = ssh2_channel_lookup(id);
@@ -8919,23 +8914,33 @@
 		return FALSE;
 	}
 
-	buflen = get_uint32_MSBfirst(data);
-	data += 4;
-	str = data;
-	data += buflen;
+	request = buffer_get_string(&data, NULL);
 
-	reply = data[0];
+	want_reply = data[0];
 	data += 1;
 
-	logprintf(LOG_LEVEL_VERBOSE, "SSH2_MSG_CHANNEL_REQUEST was received. local:%d remote:%d %s reply:%d", c->self_id, c->remote_id, str, reply);
+	logprintf(LOG_LEVEL_VERBOSE, "SSH2_MSG_CHANNEL_REQUEST was received. "
+		"local:%d remote:%d request:%s want_reply:%d",
+		c->self_id, c->remote_id, request?request:"(null)", want_reply);
 
-	// \x8FI\x97\xB9\x83R\x81[\x83h\x82\xAA\x8A܂܂\xEA\x82Ă\xA2\x82\xE9\x82Ȃ\xE7\x82\xCE
-	if (memcmp(str, emsg, strlen(emsg)) == 0) {
-		success = 1;
-		estat = get_uint32_MSBfirst(data);
+	if (request) {
+		if (strcmp(request, "exit-status") == 0) {
+			// \x8FI\x97\xB9\x83R\x81[\x83h\x82\xAA\x8A܂܂\xEA\x82Ă\xA2\x82\xE9\x82Ȃ\xE7\x82\xCE
+			int estat = get_uint32_MSBfirst(data);
+			success = 1;
+			logprintf(LOG_LEVEL_VERBOSE, __FUNCTION__ ": exit-status=%d", estat);
+		}
+		else if (strcmp(request, "keepa****@opens*****") == 0) {
+			// OpenSSH client \x82ł\xCD success = 1 \x82ɂ\xB5\x82Ă\xA2\x82Ȃ\xA2\x82\xAF\x82\xEA\x82ǁA
+			// server \x91\xA4\x82\xCD SUCCESS/FAILURE \x82ǂ\xBF\x82\xE7\x82ł\xE0 OK \x82Ȃ̂\xC5
+			// \x82Ƃ肠\x82\xA6\x82\xB8 SUCCESS \x82\xF0\x95Ԃ\xB7\x81B
+			success = 1;
+		}
+
+		free(request);
 	}
 
-	if (reply) {
+	if (want_reply) {
 		buffer_t *msg;
 		unsigned char *outmsg;
 		int len;
@@ -8961,9 +8966,9 @@
 		buffer_free(msg);
 
 		if (success) {
-			logputs(LOG_LEVEL_VERBOSE, "SSH2_MSG_CHANNEL_SUCCESS was sent at handle_SSH2_channel_request().");
+			logputs(LOG_LEVEL_VERBOSE, __FUNCTION__ ": SSH2_MSG_CHANNEL_SUCCESS was sent.");
 		} else {
-			logputs(LOG_LEVEL_VERBOSE, "SSH2_MSG_CHANNEL_FAILURE was sent at handle_SSH2_channel_request().");
+			logputs(LOG_LEVEL_VERBOSE, __FUNCTION__ ": SSH2_MSG_CHANNEL_FAILURE was sent.");
 		}
 	}
 



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