[Ttssh2-commit] [3433] TTSSH のコマンドラインで @ をスペースに、 @@ を @ にする仕様を廃止した。

アーカイブの一覧に戻る

svnno****@sourc***** svnno****@sourc*****
2009年 6月 2日 (火) 22:03:25 JST


Revision: 3433
          http://svn.sourceforge.jp/view?root=ttssh2&view=rev&rev=3433
Author:   maya
Date:     2009-06-02 22:03:24 +0900 (Tue, 02 Jun 2009)

Log Message:
-----------
TTSSH のコマンドラインで @ をスペースに、@@ を @ にする仕様を廃止した。

Modified Paths:
--------------
    trunk/ttpmenu/ttpmenu.cpp
    trunk/ttssh2/ttxssh/ttxssh.c


-------------- next part --------------
Modified: trunk/ttpmenu/ttpmenu.cpp
===================================================================
--- trunk/ttpmenu/ttpmenu.cpp	2009-06-01 19:34:31 UTC (rev 3432)
+++ trunk/ttpmenu/ttpmenu.cpp	2009-06-02 13:03:24 UTC (rev 3433)
@@ -1060,6 +1060,46 @@
 }
 
 
+static void _dquote_string(char *str, char *dst, int dst_len)
+{
+	int i, len, n;
+	
+	len = strlen(str);
+	n = 0;
+	for (i = 0 ; i < len ; i++) {
+		if (str[i] == '"')
+			n++;
+	}
+	if (dst_len < (len + 2*n + 2 + 1))
+		return;
+
+	*dst++ = '"';
+	for (i = 0 ; i < len ; i++) {
+		if (str[i] == '"') {
+			*dst++ = '"';
+			*dst++ = '"';
+
+		} else {
+			*dst++ = str[i];
+
+		}
+	}
+	*dst++ = '"';
+	*dst = '\0';
+}
+
+static void dquote_string(char *str, char *dst, int dst_len)
+{
+	// " ‚ÅŽn‚Ü‚é‚©AƒXƒy[ƒX‚ªŠÜ‚Ü‚ê‚éê‡‚ɂ̓NƒI[ƒg‚·‚é
+	if (str[0] == '"' || strchr(str, '" ') != NULL) {
+		_dquote_string(str, dst, dst_len);
+		return;
+	}
+	// ‚»‚̂܂܃Rƒs[‚µ‚Ä–ß‚é
+	strncpy_s(dst, dst_len, str, _TRUNCATE);
+}
+
+#ifdef USE_ATCMDLINE
 // ‹ó”’‚ð @ ‚É’u‚«Š·‚¦‚éB@Ž©g‚Í@@‚É‚·‚éB(2005.1.28 yutaka)
 static void replace_blank_to_mark(char *str, char *dst, int dst_len)
 {
@@ -1090,6 +1130,7 @@
 	*dst = '\0';
 
 }
+#endif
 
 
 /* ==========================================================================
@@ -1186,8 +1227,13 @@
 			char passwd[MAX_PATH], keyfile[MAX_PATH];
 
 			strcpy(tmp, szArgment);
+#ifdef USE_ATCMDLINE
 			replace_blank_to_mark(jobInfo.szPassword, passwd, sizeof(passwd));
 			replace_blank_to_mark(jobInfo.PrivateKeyFile, keyfile, sizeof(keyfile));
+#else
+			dquote_string(jobInfo.szPassword, passwd, sizeof(passwd));
+			dquote_string(jobInfo.PrivateKeyFile, keyfile, sizeof(keyfile));
+#endif
 
 			if (jobInfo.bChallenge) { // keyboard-interactive
 				_snprintf(szArgment, sizeof(szArgment), "%s:22 /ssh /auth=challenge /user=%s /passwd=%s %s", 

Modified: trunk/ttssh2/ttxssh/ttxssh.c
===================================================================
--- trunk/ttssh2/ttxssh/ttxssh.c	2009-06-01 19:34:31 UTC (rev 3432)
+++ trunk/ttssh2/ttxssh/ttxssh.c	2009-06-02 13:03:24 UTC (rev 3433)
@@ -1432,7 +1432,7 @@
 	FWDUI_load_settings(pvar);
 }
 
-
+#ifdef USE_ATCMDLINE
 // @‚ðƒuƒ‰ƒ“ƒN‚É’uŠ·‚·‚éB (2005.1.26 yutaka)
 static void replace_to_blank(char *src, char *dst, int dst_len)
 {
@@ -1456,6 +1456,7 @@
 	}
 	*dst = '\0';
 }
+#endif
 
 // Percent-encode‚³‚ꂽ•¶Žš—ñsrc‚ðƒfƒR[ƒh‚µ‚Ädst‚ɃRƒs[‚·‚éB
 // dstlen‚Ídst‚̃TƒCƒYB‚±‚ê‚æ‚茋‰Ê‚ª’·‚¢ê‡A‚»‚Ì•ª‚͐؂èŽÌ‚Ä‚ç‚ê‚éB
@@ -1612,15 +1613,28 @@
 			}
 
 		} else if (MATCH_STR(option + 1, "user=") == 0) {
+#ifdef USE_ATCMDLINE
 			replace_to_blank(option + 6, pvar->ssh2_username, sizeof(pvar->ssh2_username));
 			//_snprintf(pvar->ssh2_username, sizeof(pvar->ssh2_username), "%s", option + 6);
 
+#else
+			_snprintf_s(pvar->ssh2_username, sizeof(pvar->ssh2_username), _TRUNCATE, "%s", option + 6);
+#endif
+
 		} else if (MATCH_STR(option + 1, "passwd=") == 0) {
+#ifdef USE_ATCMDLINE
 			replace_to_blank(option + 8, pvar->ssh2_password, sizeof(pvar->ssh2_password));
 			//_snprintf(pvar->ssh2_password, sizeof(pvar->ssh2_password), "%s", option + 8);
+#else
+			_snprintf_s(pvar->ssh2_password, sizeof(pvar->ssh2_password), _TRUNCATE, "%s", option + 8);
+#endif
 
 		} else if (MATCH_STR(option + 1, "keyfile=") == 0) {
+#ifdef USE_ATCMDLINE
 			replace_to_blank(option + 9, pvar->ssh2_keyfile, sizeof(pvar->ssh2_keyfile));
+#else
+			_snprintf_s(pvar->ssh2_keyfile, sizeof(pvar->ssh2_keyfile), _TRUNCATE, "%s", option + 9);
+#endif
 
 		} else if (MATCH_STR(option + 1, "ask4passwd") == 0) {
 			// ƒpƒXƒ[ƒh‚ð•·‚­ (2006.9.18 maya)
@@ -1742,7 +1756,7 @@
 static void FAR PASCAL TTXParseParam(PCHAR param, PTTSet ts,
                                      PCHAR DDETopic)
 {
-#if 1
+#ifndef USE_ATCMDLINE
 	int i;
 	BOOL inParam = FALSE;
 	BOOL inQuotes = FALSE;
@@ -1760,17 +1774,12 @@
 		if (inQuotes) {
 			// Œ»ÝˆÊ’u‚ª"‚Ì’†
 			if (param[i] == '"') {
-#if 0
-// "‚ð•\‚·‚½‚ß‚É""‚ð“n‚·Žd—l‚É‚·‚éê‡
 				if (param[i+1] == '"') {
-					buf[buf_len] = param[i];
-					buf_len++;
+					buf[buflen] = param[i];
+					buflen++;
 					i++;
 				}
 				else {
-#else
-				{
-#endif
 					// ƒNƒH[ƒg‚µ‚Ä‚¢‚é‚Æ‚«‚Í‚±‚±‚ŏI‚í‚è
 					// "‚ðbuf‚É“ü‚ꂸ‚ɉðÍ‚É“n‚·
 					switch (parse_option(pvar, buf)) {
@@ -4015,6 +4024,46 @@
 }
 
 
+static void _dquote_string(char *str, char *dst, int dst_len)
+{
+	int i, len, n;
+	
+	len = strlen(str);
+	n = 0;
+	for (i = 0 ; i < len ; i++) {
+		if (str[i] == '"')
+			n++;
+	}
+	if (dst_len < (len + 2*n + 2 + 1))
+		return;
+
+	*dst++ = '"';
+	for (i = 0 ; i < len ; i++) {
+		if (str[i] == '"') {
+			*dst++ = '"';
+			*dst++ = '"';
+
+		} else {
+			*dst++ = str[i];
+
+		}
+	}
+	*dst++ = '"';
+	*dst = '\0';
+}
+
+static void dquote_string(char *str, char *dst, int dst_len)
+{
+	// " ‚ÅŽn‚Ü‚é‚©AƒXƒy[ƒX‚ªŠÜ‚Ü‚ê‚éê‡‚ɂ̓NƒI[ƒg‚·‚é
+	if (str[0] == '"' || strchr(str, '" ') != NULL) {
+		_dquote_string(str, dst, dst_len);
+		return;
+	}
+	// ‚»‚̂܂܃Rƒs[‚µ‚Ä–ß‚é
+	strncpy_s(dst, dst_len, str, _TRUNCATE);
+}
+
+#ifdef USE_ATCMDLINE
 // ˆÈ‰º‚ÍTeraTerm Menu‚̃R[ƒh(ttpmenu.cpp)‚Æ“¯ˆêB
 // ‹ó”’‚ð @ ‚É’u‚«Š·‚¦‚éB@Ž©g‚Í@@‚É‚·‚éB(2005.1.28 yutaka)
 static void replace_blank_to_mark(char *str, char *dst, int dst_len)
@@ -4046,6 +4095,7 @@
 	*dst = '\0';
 
 }
+#endif
 
 static void PASCAL FAR TTXSetCommandLine(PCHAR cmd, int cmdlen,
 										 PGetHNRec rec)
@@ -4122,25 +4172,41 @@
 			// ƒpƒXƒ[ƒh‚ðŠo‚¦‚Ä‚¢‚éê‡‚̂݁AƒRƒ}ƒ“ƒhƒ‰ƒCƒ“‚É“n‚·B(2006.8.3 yutaka)
 			if (pvar->settings.remember_password &&
 			    pvar->auth_state.cur_cred.method == SSH_AUTH_PASSWORD) {
+#ifdef USE_ATCMDLINE
 				replace_blank_to_mark(pvar->auth_state.cur_cred.password, mark, sizeof(mark));
+#else
+				dquote_string(pvar->auth_state.cur_cred.password, mark, sizeof(mark));
+#endif
 				_snprintf_s(tmp, sizeof(tmp), _TRUNCATE,
 				            " /auth=password /user=%s /passwd=%s", pvar->auth_state.user, mark);
 				strncat_s(cmd, cmdlen, tmp, _TRUNCATE);
 
 			} else if (pvar->settings.remember_password &&
 			           pvar->auth_state.cur_cred.method == SSH_AUTH_RSA) {
+#ifdef USE_ATCMDLINE
 				replace_blank_to_mark(pvar->auth_state.cur_cred.password, mark, sizeof(mark));
+#else
+				dquote_string(pvar->auth_state.cur_cred.password, mark, sizeof(mark));
+#endif
 				_snprintf_s(tmp, sizeof(tmp), _TRUNCATE,
 				            " /auth=publickey /user=%s /passwd=%s", pvar->auth_state.user, mark);
 				strncat_s(cmd, cmdlen, tmp, _TRUNCATE);
 
+#ifdef USE_ATCMDLINE
 				replace_blank_to_mark(pvar->session_settings.DefaultRSAPrivateKeyFile, mark, sizeof(mark));
+#else
+				dquote_string(pvar->session_settings.DefaultRSAPrivateKeyFile, mark, sizeof(mark));
+#endif
 				_snprintf_s(tmp, sizeof(tmp), _TRUNCATE, " /keyfile=%s", mark);
 				strncat_s(cmd, cmdlen, tmp, _TRUNCATE);
 
 			} else if (pvar->settings.remember_password &&
 			           pvar->auth_state.cur_cred.method == SSH_AUTH_TIS) {
+#ifdef USE_ATCMDLINE
 				replace_blank_to_mark(pvar->auth_state.cur_cred.password, mark, sizeof(mark));
+#else
+				dquote_string(pvar->auth_state.cur_cred.password, mark, sizeof(mark));
+#endif
 				_snprintf_s(tmp, sizeof(tmp), _TRUNCATE,
 				            " /auth=challenge /user=%s /passwd=%s", pvar->auth_state.user, mark);
 				strncat_s(cmd, cmdlen, tmp, _TRUNCATE);



Ttssh2-commit メーリングリストの案内
アーカイブの一覧に戻る