Revision: 9503 https://osdn.net/projects/ttssh2/scm/svn/commits/9503 Author: zmatsuo Date: 2021-10-30 00:18:57 +0900 (Sat, 30 Oct 2021) Log Message: ----------- TTXReadKnownHostsFile() APIを変更、Unicode 化 - ssh_knwon_hosts ファイルを取得する関数 - 従来、ファイル名のみ返ってきていたので、表示する際にフルパス化していた - ttssh が実際に使用するフルパスと、表示時のフルパス化の方法が異なっていた - フルパスファイル名を返すようにした、ファイル名をUnicode化、ファイル名サイズを返すようにした - VirtualStore パス作成を誤っていたので修正 - warning: cast between incompatible function types from 'FARPROC' {aka 'long long int (*)()'} to 'PSSH_read_known_hosts_file' {aka 'int (*)(wchar_t*, long long unsigned int)'} [-Wcast-function-type] Modified Paths: -------------- trunk/teraterm/teraterm/setupdirdlg.cpp trunk/ttssh2/ttxssh/ttxssh.c -------------- next part -------------- Modified: trunk/teraterm/teraterm/setupdirdlg.cpp =================================================================== --- trunk/teraterm/teraterm/setupdirdlg.cpp 2021-10-27 12:48:59 UTC (rev 9502) +++ trunk/teraterm/teraterm/setupdirdlg.cpp 2021-10-29 15:18:57 UTC (rev 9503) @@ -42,6 +42,7 @@ #include <stdlib.h> #include <crtdbg.h> #include <string.h> +#include <assert.h> #include <shlobj.h> #include <windows.h> @@ -286,7 +287,7 @@ wchar_t *local_appdata; _SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &local_appdata); wchar_t *vs_file; - aswprintf(&vs_file, L"%s\\VirtualStore%s", local_appdata, path_nodrive, file); + aswprintf(&vs_file, L"%s\\VirtualStore%s\\%s", local_appdata, path_nodrive, file); free(local_appdata); // \x8DŌ\xE3\x82ɁAVirtual Store\x82Ƀt\x83@\x83C\x83\x8B\x82\xAA\x82\xA0\x82邩\x82ǂ\xA4\x82\xA9\x82ׂ\xE9\x81B @@ -396,29 +397,22 @@ // ssh_known_hosts { - typedef int (CALLBACK *PSSH_read_known_hosts_file)(char *, int); - HMODULE h = NULL; - PSSH_read_known_hosts_file func = NULL; - if (((h = GetModuleHandle("ttxssh.dll")) != NULL)) { - func = (PSSH_read_known_hosts_file)GetProcAddress(h, "TTXReadKnownHostsFile"); + HMODULE h = GetModuleHandle("ttxssh.dll"); + if (h != NULL) { + size_t (CALLBACK *func)(wchar_t *, size_t) = NULL; + void **pfunc = (void **)&func; + *pfunc = (void *)GetProcAddress(h, "TTXReadKnownHostsFile"); if (func) { - char temp[MAX_PATH]; - int ret = func(temp, sizeof(temp)); - if (ret) { - char *s = strstr(temp, ":\\"); + size_t size = func(NULL, 0); + if (size != 0) { + wchar_t *temp = (wchar_t *)malloc(sizeof(wchar_t) * size); + func(temp, size); + assert(!IsRelativePathW(temp)); - if (s) { // full path - tmpbufW = ToWcharA(temp); - } - else { // relative path - aswprintf(&tmpbufW, L"%s\\%hs", pts->HomeDirW, temp); - } + SetDlgItemTextW(hDlgWnd, IDC_SSH_SETUPDIR_EDIT, temp); - SetDlgItemTextW(hDlgWnd, IDC_SSH_SETUPDIR_EDIT, tmpbufW); - /// (2) Virutal Store\x82ւ̕ϊ\xB7 - ret = convertVirtualStoreW(tmpbufW, &vs); - free(tmpbufW); + ret = convertVirtualStoreW(temp, &vs); hWnd = GetDlgItem(hDlgWnd, IDC_SSH_SETUPDIR_STATIC_VSTORE); EnableWindow(hWnd, ret); hWnd = GetDlgItem(hDlgWnd, IDC_SSH_SETUPDIR_EDIT_VSTORE); @@ -430,7 +424,7 @@ else { SetDlgItemTextA(hDlgWnd, IDC_SSH_SETUPDIR_EDIT_VSTORE, ""); } - + free(temp); } } } Modified: trunk/ttssh2/ttxssh/ttxssh.c =================================================================== --- trunk/ttssh2/ttxssh/ttxssh.c 2021-10-27 12:48:59 UTC (rev 9502) +++ trunk/ttssh2/ttxssh/ttxssh.c 2021-10-29 15:18:57 UTC (rev 9503) @@ -3427,26 +3427,44 @@ } -// TTSSH\x82̐ݒ\xE8\x93\xE0\x97e(known hosts file)\x82\xF0\x95Ԃ\xB7\x81B -// -// return TRUE: \x95ԋp\x90\xAC\x8C\xF7 -// FALSE: \x8E\xB8\x94s -// (2015.3.9 yutaka) -__declspec(dllexport) int CALLBACK TTXReadKnownHostsFile(char *filename, int maxlen) +/** + * TTSSH\x82̐ݒ\xE8\x93\xE0\x97e(known hosts file)\x82\xF0\x95Ԃ\xB7\x81B + * \x83t\x83\x8B\x83p\x83X\x82ŕԂ\xB7 + * + * @param[in] filename \x83t\x83@\x83C\x83\x8B\x96\xBC\x82ւ̃|\x83C\x83\x93\x83^ + * NULL\x82̎\x9E\x95\xB6\x8E\x9A\x90\x94\x82\xF0\x95Ԃ\xB7 + * @param[in] maxlen \x83t\x83@\x83C\x83\x8B\x96\xBC\x82̕\xB6\x8E\x9A\x90\x94 + * (filename != NULL\x82̎\x9E\x97L\x8C\xF8) + * @retval \x95\xB6\x8E\x9A\x90\x94(0\x88ȊO),(filename == NULL\x82̎\x9E\x82\xCD'\0'\x82\xE0\x8A܂\xDE) + * 0 \x83G\x83\x89\x81[ + */ +__declspec(dllexport) size_t CALLBACK TTXReadKnownHostsFile(wchar_t *filename, size_t maxlen) { - int ret = FALSE; - char *p; + if (!pvar->settings.Enabled) { + return 0; + } + else { + wchar_t *fullpath; + wchar_t *filenameW = ToWcharA(pvar->settings.KnownHostsFiles); + wchar_t *p = wcschr(filenameW, L';'); + size_t ret; + if (p) { + *p = 0; // cut readonly ssh known hosts + } - if (pvar->settings.Enabled) { - strncpy_s(filename, maxlen, pvar->settings.KnownHostsFiles, _TRUNCATE); - p = strchr(filename, ';'); - if (p) - *p = 0; + fullpath = get_teraterm_dir_relative_nameW(filenameW); + ret = wcslen(fullpath); + if (filename != NULL) { + wcsncpy_s(filename, maxlen, fullpath, _TRUNCATE); + } + else { + ret++; + } + free(fullpath); + free(filenameW); - ret = TRUE; + return ret; } - - return (ret); }