[Ttssh2-commit] [7616] ttsshのSSH認証設定ダイアログにデフォルトユーザー名タイプ設定を追加

scmno****@osdn***** scmno****@osdn*****
2019年 4月 24日 (水) 23:09:52 JST


Revision: 7616
          https://osdn.net/projects/ttssh2/scm/svn/commits/7616
Author:   zmatsuo
Date:     2019-04-24 23:09:52 +0900 (Wed, 24 Apr 2019)
Log Message:
-----------
ttsshのSSH認証設定ダイアログにデフォルトユーザー名タイプ設定を追加
ttsshのauthダイアログは設定に沿って動作するよう変更

Modified Paths:
--------------
    branches/ssh_auth_dialog/ttssh2/ttxssh/auth.c
    branches/ssh_auth_dialog/ttssh2/ttxssh/resource.h
    branches/ssh_auth_dialog/ttssh2/ttxssh/ttxssh.c
    branches/ssh_auth_dialog/ttssh2/ttxssh/ttxssh.h
    branches/ssh_auth_dialog/ttssh2/ttxssh/ttxssh.rc

-------------- next part --------------
Modified: branches/ssh_auth_dialog/ttssh2/ttxssh/auth.c
===================================================================
--- branches/ssh_auth_dialog/ttssh2/ttxssh/auth.c	2019-04-24 14:09:40 UTC (rev 7615)
+++ branches/ssh_auth_dialog/ttssh2/ttxssh/auth.c	2019-04-24 14:09:52 UTC (rev 7616)
@@ -244,9 +244,31 @@
 
 static void init_auth_dlg(PTInstVar pvar, HWND dlg)
 {
+	const static DlgTextInfo text_info[] = {
+		{ 0, "DLG_AUTH_TITLE" },
+		{ IDC_SSHAUTHBANNER, "DLG_AUTH_BANNER" },
+		{ IDC_SSHAUTHBANNER2, "DLG_AUTH_BANNER2" },
+		{ IDC_SSHUSERNAMELABEL, "DLG_AUTH_USERNAME" },
+		{ IDC_SSHPASSWORDCAPTION, "DLG_AUTH_PASSWORD" },
+		{ IDC_REMEMBER_PASSWORD, "DLG_AUTH_REMEMBER_PASSWORD" },
+		{ IDC_FORWARD_AGENT, "DLG_AUTH_FWDAGENT" },
+		{ IDC_SSHUSEPASSWORD, "DLG_AUTH_METHOD_PASSWORD" },
+		{ IDC_SSHUSERSA, "DLG_AUTH_METHOD_RSA" },
+		{ IDC_SSHUSERHOSTS, "DLG_AUTH_METHOD_RHOST" },
+		{ IDC_SSHUSEPAGEANT, "DLG_AUTH_METHOD_PAGEANT" },
+		//{ IDC_CHOOSERSAFILE, "DLG_AUTH_PRIVATEKEY" },
+		{ IDC_RSAFILENAMELABEL, "DLG_AUTH_PRIVATEKEY" },
+		{ IDC_LOCALUSERNAMELABEL, "DLG_AUTH_LOCALUSER" },
+		//{ IDC_CHOOSEHOSTRSAFILE, "DLG_AUTH_HOST_PRIVATEKEY" },
+		{ IDC_HOSTRSAFILENAMELABEL, "DLG_AUTH_HOST_PRIVATEKEY" },
+		{ IDOK, "BTN_OK" },
+		{ IDCANCEL, "BTN_DISCONNECT" },
+	};
 	int default_method = pvar->session_settings.DefaultAuthMethod;
+
+	SetI18DlgStrs("TTSSH", dlg, text_info, _countof(text_info), pvar->ts->UILanguageFile);
+#if 0
 	char uimsg[MAX_UIMSG];
-
 	GetWindowText(dlg, uimsg, sizeof(uimsg));
 	UTIL_get_lang_msg("DLG_AUTH_TITLE", pvar, uimsg);
 	SetWindowText(dlg, pvar->ts->UIMsg);
@@ -295,6 +317,7 @@
 	GetDlgItemText(dlg, IDCANCEL, uimsg, sizeof(uimsg));
 	UTIL_get_lang_msg("BTN_DISCONNECT", pvar, uimsg);
 	SetDlgItemText(dlg, IDCANCEL, pvar->ts->UIMsg);
+#endif
 
 	init_auth_machine_banner(pvar, dlg);
 	init_password_control(pvar, dlg, IDC_SSHPASSWORD);
@@ -333,6 +356,7 @@
 	if (pvar->auth_state.user != NULL) {
 		SetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->auth_state.user);
 		EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAME), FALSE);
+		EnableWindow(GetDlgItem(dlg, IDC_FROM_GETUSERNAME), FALSE);
 		EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAMELABEL), FALSE);
 	}
 	else if (strlen(pvar->ssh2_username) > 0) {
@@ -339,12 +363,38 @@
 		SetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->ssh2_username);
 		if (pvar->ssh2_autologin == 1) {
 			EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAME), FALSE);
+			EnableWindow(GetDlgItem(dlg, IDC_FROM_GETUSERNAME), FALSE);
 			EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAMELABEL), FALSE);
 		}
 	}
-	else if (pvar->session_settings.DefaultUserName[0] != 0) {
-		SetDlgItemText(dlg, IDC_SSHUSERNAME,
-		               pvar->session_settings.DefaultUserName);
+	else {
+		switch(pvar->session_settings.DefaultUserType) {
+		case 0:
+			// \x93\xFC\x97͂\xB5\x82Ȃ\xA2
+			break;
+		case 1:
+			// use DefaultUserName
+			if (pvar->session_settings.DefaultUserName[0] == 0) {
+				// \x81u\x93\xFC\x97͂\xB5\x82Ȃ\xA2\x81v\x82ɂ\xB5\x82Ă\xA8\x82\xAD
+				pvar->session_settings.DefaultUserType = 0;
+			} else {
+				SetDlgItemText(dlg, IDC_SSHUSERNAME,
+							   pvar->session_settings.DefaultUserName);
+			}
+			break;
+		case 2: {
+			TCHAR user_name[UNLEN+1];
+			DWORD len = _countof(user_name);
+			BOOL r = GetUserName(user_name, &len);
+			if (r != 0) {
+				SetDlgItemText(dlg, IDC_SSHUSERNAME, user_name);
+			}
+			break;
+		}
+		default:
+			// \x93\xFC\x97͂\xB5\x82Ȃ\xA2\x82ɂ\xB5\x82Ă\xA8\x82\xAD
+			pvar->session_settings.DefaultUserType = 0;
+		}
 	}
 
 	if (strlen(pvar->ssh2_password) > 0) {
@@ -838,7 +888,7 @@
 #endif
 		UseControlChar = TRUE;
 		CheckDlgButton(dlg, IDC_USE_CONTROL_CHARACTER, UseControlChar ? BST_CHECKED : BST_UNCHECKED);
-		CheckDlgButton(dlg, IDC_CLEAR_CLIPBOARD, BST_UNCHECKED);
+		CheckDlgButton(dlg, IDC_CLEAR_CLIPBOARD, BST_CHECKED);
 
 		// SSH2 autologin\x82\xAA\x97L\x8C\xF8\x82̏ꍇ\x82́A\x83^\x83C\x83}\x82\xF0\x8Ed\x8A|\x82\xAF\x82\xE9\x81B (2004.12.1 yutaka)
 		if (pvar->ssh2_autologin == 1) {
@@ -922,6 +972,7 @@
 
 					// \x83\x86\x81[\x83U\x96\xBC\x82\xF0\x95ύX\x82\xB3\x82\xB9\x82Ȃ\xA2
 					EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAME), FALSE);
+					EnableWindow(GetDlgItem(dlg, IDC_FROM_GETUSERNAME), FALSE);
 
 					// \x94F\x8F؃\x81\x83\\x83b\x83h none \x82𑗂\xE9
 					do_SSH2_userauth(pvar);
@@ -1015,6 +1066,7 @@
 
 					// \x83\x86\x81[\x83U\x96\xBC\x82\xF0\x95ύX\x82\xB3\x82\xB9\x82Ȃ\xA2
 					EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAME), FALSE);
+					EnableWindow(GetDlgItem(dlg, IDC_FROM_GETUSERNAME), FALSE);
 
 					// \x94F\x8F؃\x81\x83\\x83b\x83h none \x82𑗂\xE9
 					do_SSH2_userauth(pvar);
@@ -1415,6 +1467,33 @@
 
 static void init_default_auth_dlg(PTInstVar pvar, HWND dlg)
 {
+	int id;
+	TCHAR user_name[UNLEN+1];
+	DWORD len;
+	TCHAR uimsg[MAX_UIMSG];
+	TCHAR uimsg2[MAX_UIMSG];
+	const static DlgTextInfo text_info[] = {
+		{ 0, "DLG_AUTHSETUP_TITLE" },
+		{ IDC_SSHAUTHBANNER, "DLG_AUTHSETUP_BANNER" },
+//		{ IDC_SSHUSERNAMELABEL, "DLG_AUTHSETUP_USERNAME" },
+		{ IDC_SSH_DEFAULTUSERNAME, "DLG_AUTHSETUP_USERNAME" },
+		{ IDC_SSHUSEPASSWORD, "DLG_AUTHSETUP_METHOD_PASSWORD" },
+		{ IDC_SSHUSERSA, "DLG_AUTHSETUP_METHOD_RSA" },
+		{ IDC_SSHUSERHOSTS, "DLG_AUTHSETUP_METHOD_RHOST" },
+		{ IDC_SSHUSETIS, "DLG_AUTHSETUP_METHOD_CHALLENGE" },
+		{ IDC_SSHUSEPAGEANT, "DLG_AUTHSETUP_METHOD_PAGEANT" },
+		//{ IDC_CHOOSERSAFILE, "DLG_AUTH_PRIVATEKEY" },
+		{ IDC_RSAFILENAMELABEL, "DLG_AUTH_PRIVATEKEY" },
+		{ IDC_LOCALUSERNAMELABEL, "DLG_AUTH_LOCALUSER" },
+		//{ IDC_CHOOSEHOSTRSAFILE, "DLG_AUTH_HOST_PRIVATEKEY" },
+		{ IDC_HOSTRSAFILENAMELABEL, "DLG_AUTH_HOST_PRIVATEKEY" },
+		{ IDC_CHECKAUTH, "DLG_AUTHSETUP_CHECKAUTH" },
+		{ IDOK, "BTN_OK" },
+		{ IDCANCEL, "BTN_CANCEL" },
+	};
+
+	SetI18DlgStrs("TTSSH", dlg, text_info, _countof(text_info), pvar->ts->UILanguageFile);
+#if 0
 	char uimsg[MAX_UIMSG];
 
 	GetWindowText(dlg, uimsg, sizeof(uimsg));
@@ -1459,6 +1538,7 @@
 	GetDlgItemText(dlg, IDCANCEL, uimsg, sizeof(uimsg));
 	UTIL_get_lang_msg("BTN_CANCEL", pvar, uimsg);
 	SetDlgItemText(dlg, IDCANCEL, pvar->ts->UIMsg);
+#endif
 
 	switch (pvar->settings.DefaultAuthMethod) {
 	case SSH_AUTH_RSA:
@@ -1495,6 +1575,18 @@
 	if (pvar->settings.CheckAuthListFirst) {
 		CheckDlgButton(dlg, IDC_CHECKAUTH, TRUE);
 	}
+
+	id = pvar->settings.DefaultUserType == 1 ? IDC_SSH_DEFAULTUSERNAME :
+		pvar->settings.DefaultUserType == 2 ? IDC_SSH_WINDOWS_USERNAME :
+		IDC_SSH_NO_USERNAME;
+	CheckRadioButton(dlg, IDC_SSH_NO_USERNAME, IDC_SSH_WINDOWS_USERNAME, id);
+
+	len = _countof(user_name);
+	GetUserName(user_name, &len);
+
+	GetDlgItemText(dlg, IDC_SSH_WINDOWS_USERNAME_TEXT, uimsg, _countof(uimsg));
+	_stprintf_s(uimsg2, _countof(uimsg2), uimsg, user_name);
+	SetDlgItemText(dlg, IDC_SSH_WINDOWS_USERNAME_TEXT, uimsg2);
 }
 
 static BOOL end_default_auth_dlg(PTInstVar pvar, HWND dlg)
@@ -1526,6 +1618,9 @@
 	GetDlgItemText(dlg, IDC_LOCALUSERNAME,
 	               pvar->settings.DefaultRhostsLocalUserName,
 	               sizeof(pvar->settings.DefaultRhostsLocalUserName));
+	pvar->settings.DefaultUserType =
+		IsDlgButtonChecked(dlg, IDC_SSH_DEFAULTUSERNAME) ? 1 :
+		IsDlgButtonChecked(dlg, IDC_SSH_WINDOWS_USERNAME) ? 2 : 0;
 
 	if (IsDlgButtonChecked(dlg, IDC_CHECKAUTH)) {
 		pvar->settings.CheckAuthListFirst = TRUE;

Modified: branches/ssh_auth_dialog/ttssh2/ttxssh/resource.h
===================================================================
--- branches/ssh_auth_dialog/ttssh2/ttxssh/resource.h	2019-04-24 14:09:40 UTC (rev 7615)
+++ branches/ssh_auth_dialog/ttssh2/ttxssh/resource.h	2019-04-24 14:09:52 UTC (rev 7616)
@@ -36,7 +36,6 @@
 #define IDC_SSHUSERNAME                 1000
 #define IDC_HOSTTELNET                  1000
 #define IDC_HOSTSSH                     1001
-#define IDC_SSHUSERNAME2                1001
 #define IDC_SSHPASSWORD                 1002
 #define IDC_HOSTOTHER                   1002
 #define IDC_SSHAUTHBANNER               1003
@@ -200,13 +199,10 @@
 #define IDC_SSHUSEPAGEANT               1205
 #define IDC_SSHUSETIS2                  1206
 #define IDC_REMEMBERPASSWORD            1207
-#define IDC_SSHUSERSA2                  1207
 #define IDC_SENDFILE_TO                 1208
 #define IDC_SFTP_CONSOLE                1208
 #define IDC_REMOVEKEY_EDIT              1208
-#define IDC_SSHUSERSA3                  1208
 #define IDC_PUTTY_VERSION               1209
-#define IDC_SSHUSERSA4                  1209
 #define IDC_ED25519_TYPE                1211
 #define IDC_HOSTKEY_ROTATION_STATIC     1212
 #define IDC_LIST1                       1213
@@ -234,8 +230,12 @@
 #define IDC_USE_CONTROL_CHARACTER       1234
 #define IDC_HOSTRSAFILENAMELABEL        1235
 #define IDC_RSAFILENAMELABEL            1236
-#define IDC_FROM_GETUSERNAME            1237
-#define IDC_RSAFILENAMELABEL2           1237
+#define IDC_SSH_NO_USERNAME             1237
+#define IDC_SSH_DEFAULTUSERNAME         1238
+#define IDC_SSH_WINDOWS_USERNAME        1239
+#define IDC_FROM_GETUSERNAME            1240
+#define IDC_RSAFILENAMELABEL2           1241
+#define IDC_SSH_WINDOWS_USERNAME_TEXT   1241
 
 // Next default values for new objects
 // 
@@ -243,7 +243,7 @@
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_NEXT_RESOURCE_VALUE        118
 #define _APS_NEXT_COMMAND_VALUE         40001
-#define _APS_NEXT_CONTROL_VALUE         1237
+#define _APS_NEXT_CONTROL_VALUE         1242
 #define _APS_NEXT_SYMED_VALUE           101
 #endif
 #endif

Modified: branches/ssh_auth_dialog/ttssh2/ttxssh/ttxssh.c
===================================================================
--- branches/ssh_auth_dialog/ttssh2/ttxssh/ttxssh.c	2019-04-24 14:09:40 UTC (rev 7615)
+++ branches/ssh_auth_dialog/ttssh2/ttxssh/ttxssh.c	2019-04-24 14:09:52 UTC (rev 7616)
@@ -446,6 +446,8 @@
 	}
 
 	READ_STD_STRING_OPTION(DefaultUserName);
+	settings->DefaultUserType = GetPrivateProfileInt("TTSSH", "DefaultUserType", 1, fileName);
+
 	READ_STD_STRING_OPTION(DefaultForwarding);
 	READ_STD_STRING_OPTION(DefaultRhostsLocalUserName);
 	READ_STD_STRING_OPTION(DefaultRhostsHostPrivateKeyFile);
@@ -570,6 +572,8 @@
 	_itoa(settings->CompressionLevel, buf, 10);
 	WritePrivateProfileString("TTSSH", "Compression", buf, fileName);
 
+	_itoa(settings->DefaultUserType, buf, 10);
+	WritePrivateProfileString("TTSSH", "DefaultUserType", buf, fileName);
 	WritePrivateProfileString("TTSSH", "DefaultUserName",
 	                          settings->DefaultUserName, fileName);
 

Modified: branches/ssh_auth_dialog/ttssh2/ttxssh/ttxssh.h
===================================================================
--- branches/ssh_auth_dialog/ttssh2/ttxssh/ttxssh.h	2019-04-24 14:09:40 UTC (rev 7615)
+++ branches/ssh_auth_dialog/ttssh2/ttxssh/ttxssh.h	2019-04-24 14:09:52 UTC (rev 7616)
@@ -136,6 +136,8 @@
 typedef struct _TS_SSH {
 	BOOL Enabled;
 	int CompressionLevel; /* 0 = NONE, else 1-9 */
+
+	int DefaultUserType;	/* 0/1/2 = no input/DefaultUserName/Windows logon user */
 	char DefaultUserName[256];
 
 	/* this next option is a string of digits. Each digit represents a

Modified: branches/ssh_auth_dialog/ttssh2/ttxssh/ttxssh.rc
===================================================================
--- branches/ssh_auth_dialog/ttssh2/ttxssh/ttxssh.rc	2019-04-24 14:09:40 UTC (rev 7615)
+++ branches/ssh_auth_dialog/ttssh2/ttxssh/ttxssh.rc	2019-04-24 14:09:52 UTC (rev 7616)
@@ -64,7 +64,7 @@
     PUSHBUTTON      "Paste from &clipboard",IDC_FROM_CLIPBOARD,28,107,80,14
     CONTROL         "Cl&ear clipboard after paste",IDC_CLEAR_CLIPBOARD,
                     "Button",BS_AUTOCHECKBOX | WS_TABSTOP,40,125,132,10
-    CONTROL         "Use control character&s",IDC_USE_CONTROL_CHARACTER,
+    CONTROL         "Use control charac&ters",IDC_USE_CONTROL_CHARACTER,
                     "Button",BS_AUTOCHECKBOX | WS_TABSTOP,28,139,132,10
     CONTROL         "&Show passphrase",IDC_SHOW_PASSPHRASE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,28,153,132,10
     CONTROL         "Remember password in &memory",IDC_REMEMBER_PASSWORD,
@@ -223,11 +223,11 @@
 BEGIN
     LTEXT           "Select defaults for authentication:",IDC_SSHAUTHBANNER,6,7,166,10
     GROUPBOX        "User name",IDC_STATIC,6,22,295,88
-    CONTROL         "User name is empty",IDC_SSHUSERSA2,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,19,35,152,10
-    CONTROL         "Use following use name",IDC_SSHUSERSA4,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,19,50,152,10
-    CONTROL         "Use system user name",IDC_SSHUSERSA3,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,19,78,152,10
+    CONTROL         "Do not enter username",IDC_SSH_NO_USERNAME,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,19,35,152,10
+    CONTROL         "Use following username",IDC_SSH_DEFAULTUSERNAME,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,19,50,152,10
+    CONTROL         "Use system username",IDC_SSH_WINDOWS_USERNAME,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,19,78,152,10
     EDITTEXT        IDC_SSHUSERNAME,35,62,145,12,ES_AUTOHSCROLL
-    LTEXT           "Current user name is ""%s""",IDC_RSAFILENAMELABEL2,35,93,128,10
+    LTEXT           "Current username is ""%s""",IDC_SSH_WINDOWS_USERNAME_TEXT,35,93,128,10
     GROUPBOX        "Authentication methods ",IDC_STATIC,6,120,295,200
     CONTROL         "Use p&lain password to log in",IDC_SSHUSEPASSWORD,
                     "Button",BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,19,134,120,10
@@ -613,8 +613,11 @@
 
 2 TEXTINCLUDE 
 BEGIN
-    "#include ""afxres.h""\r\n"
-    "\0"
+	"#include <windows.h>\r\n"
+	"#ifndef IDC_STATIC\r\n"
+	"#define IDC_STATIC -1\r\n"
+	"#endif\r\n"
+	"\0"
 END
 
 3 TEXTINCLUDE 


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