| 41 |
#include "dns.h" |
#include "dns.h" |
| 42 |
#include "dlglib.h" |
#include "dlglib.h" |
| 43 |
#include "compat_win.h" |
#include "compat_win.h" |
| 44 |
|
#include "codeconv.h" |
| 45 |
|
|
| 46 |
#include <openssl/bn.h> |
#include <openssl/bn.h> |
| 47 |
#include <openssl/evp.h> |
#include <openssl/evp.h> |
| 54 |
#include <sys/stat.h> |
#include <sys/stat.h> |
| 55 |
#include <direct.h> |
#include <direct.h> |
| 56 |
#include <memory.h> |
#include <memory.h> |
| 57 |
|
#include <wchar.h> |
| 58 |
|
|
| 59 |
#include "codeconv.h" |
#include "codeconv.h" |
| 60 |
#include "asprintf.h" |
#include "asprintf.h" |
| 74 |
void HOSTS_cancel_session_after_known_hosts(PTInstVar pvar); |
void HOSTS_cancel_session_after_known_hosts(PTInstVar pvar); |
| 75 |
|
|
| 76 |
|
|
| 77 |
static char **parse_multi_path(char *buf) |
static wchar_t **parse_multi_path(wchar_t *buf) |
| 78 |
{ |
{ |
| 79 |
int i; |
int i; |
| 80 |
int ch; |
wchar_t ch; |
| 81 |
int num_paths = 1; |
int num_paths = 1; |
| 82 |
char ** result; |
wchar_t ** result; |
| 83 |
int last_path_index; |
int last_path_index; |
| 84 |
|
|
| 85 |
for (i = 0; (ch = buf[i]) != 0; i++) { |
for (i = 0; (ch = buf[i]) != 0; i++) { |
| 89 |
} |
} |
| 90 |
|
|
| 91 |
result = |
result = |
| 92 |
(char **) malloc(sizeof(char *) * (num_paths + 1)); |
(wchar_t **) malloc(sizeof(wchar_t *) * (num_paths + 1)); |
| 93 |
|
|
| 94 |
last_path_index = 0; |
last_path_index = 0; |
| 95 |
num_paths = 0; |
num_paths = 0; |
| 96 |
for (i = 0; (ch = buf[i]) != 0; i++) { |
for (i = 0; (ch = buf[i]) != 0; i++) { |
| 97 |
if (ch == ';') { |
if (ch == ';') { |
| 98 |
buf[i] = 0; |
buf[i] = 0; |
| 99 |
result[num_paths] = _strdup(buf + last_path_index); |
result[num_paths] = _wcsdup(buf + last_path_index); |
| 100 |
num_paths++; |
num_paths++; |
| 101 |
buf[i] = ch; |
buf[i] = ch; |
| 102 |
last_path_index = i + 1; |
last_path_index = i + 1; |
| 103 |
} |
} |
| 104 |
} |
} |
| 105 |
if (i > last_path_index) { |
if (i > last_path_index) { |
| 106 |
result[num_paths] = _strdup(buf + last_path_index); |
result[num_paths] = _wcsdup(buf + last_path_index); |
| 107 |
num_paths++; |
num_paths++; |
| 108 |
} |
} |
| 109 |
result[num_paths] = NULL; |
result[num_paths] = NULL; |
| 125 |
|
|
| 126 |
void HOSTS_open(PTInstVar pvar) |
void HOSTS_open(PTInstVar pvar) |
| 127 |
{ |
{ |
| 128 |
|
wchar_t *known_hosts_filesW = ToWcharA(pvar->session_settings.KnownHostsFiles); |
| 129 |
pvar->hosts_state.file_names = |
pvar->hosts_state.file_names = |
| 130 |
parse_multi_path(pvar->session_settings.KnownHostsFiles); |
parse_multi_path(known_hosts_filesW); |
| 131 |
|
free(known_hosts_filesW); |
| 132 |
} |
} |
| 133 |
|
|
| 134 |
// |
// |
| 135 |
// known_hostsファイルの内容をすべて pvar->hosts_state.file_data へ読み込む |
// known_hostsファイルの内容をすべて pvar->hosts_state.file_data へ読み込む |
| 136 |
// |
// |
| 137 |
static int begin_read_file(PTInstVar pvar, char *name, |
static int begin_read_file(PTInstVar pvar, wchar_t *name, |
| 138 |
int suppress_errors) |
int suppress_errors) |
| 139 |
{ |
{ |
| 140 |
int fd; |
int fd; |
| 141 |
int length; |
int length; |
| 142 |
int amount_read; |
int amount_read; |
| 143 |
char buf[2048]; |
wchar_t *bufW; |
| 144 |
|
|
| 145 |
get_teraterm_dir_relative_name(buf, sizeof(buf), name); |
bufW = get_teraterm_dir_relative_nameW(name); |
| 146 |
fd = _open(buf, _O_RDONLY | _O_SEQUENTIAL | _O_BINARY); |
fd = _wopen(bufW, _O_RDONLY | _O_SEQUENTIAL | _O_BINARY); |
| 147 |
|
free(bufW); |
| 148 |
if (fd == -1) { |
if (fd == -1) { |
| 149 |
if (!suppress_errors) { |
if (!suppress_errors) { |
| 150 |
if (errno == ENOENT) { |
if (errno == ENOENT) { |
| 565 |
do { |
do { |
| 566 |
if (pvar->hosts_state.file_data == NULL |
if (pvar->hosts_state.file_data == NULL |
| 567 |
|| pvar->hosts_state.file_data[pvar->hosts_state.file_data_index] == 0) { |
|| pvar->hosts_state.file_data[pvar->hosts_state.file_data_index] == 0) { |
| 568 |
char *filename; |
wchar_t *filename; |
| 569 |
int keep_going = 1; |
int keep_going = 1; |
| 570 |
|
|
| 571 |
if (pvar->hosts_state.file_data != NULL) { |
if (pvar->hosts_state.file_data != NULL) { |
| 802 |
int success = 0; |
int success = 0; |
| 803 |
int suppress_errors = 1; |
int suppress_errors = 1; |
| 804 |
unsigned short tcpport; |
unsigned short tcpport; |
| 805 |
char *filename; |
wchar_t *filename; |
| 806 |
char *hostname; |
char *hostname; |
| 807 |
Key *key; |
Key *key; |
| 808 |
|
|
| 1243 |
|
|
| 1244 |
static void add_host_key(PTInstVar pvar) |
static void add_host_key(PTInstVar pvar) |
| 1245 |
{ |
{ |
| 1246 |
char *name = NULL; |
wchar_t *name = NULL; |
| 1247 |
|
|
| 1248 |
if ( pvar->hosts_state.file_names != NULL) |
if ( pvar->hosts_state.file_names != NULL) |
| 1249 |
name = pvar->hosts_state.file_names[0]; |
name = pvar->hosts_state.file_names[0]; |
| 1259 |
int fd; |
int fd; |
| 1260 |
int amount_written; |
int amount_written; |
| 1261 |
int close_result; |
int close_result; |
| 1262 |
char buf[FILENAME_MAX]; |
wchar_t *buf; |
| 1263 |
|
|
| 1264 |
get_teraterm_dir_relative_name(buf, sizeof(buf), name); |
buf = get_teraterm_dir_relative_nameW(name); |
| 1265 |
fd = _open(buf, |
fd = _wopen(buf, |
| 1266 |
_O_APPEND | _O_CREAT | _O_WRONLY | _O_SEQUENTIAL | _O_BINARY, |
_O_APPEND | _O_CREAT | _O_WRONLY | _O_SEQUENTIAL | _O_BINARY, |
| 1267 |
_S_IREAD | _S_IWRITE); |
_S_IREAD | _S_IWRITE); |
| 1268 |
|
free(buf); |
| 1269 |
if (fd == -1) { |
if (fd == -1) { |
| 1270 |
if (errno == EACCES) { |
if (errno == EACCES) { |
| 1271 |
UTIL_get_lang_msg("MSG_HOSTS_WRITE_EACCES_ERROR", pvar, |
UTIL_get_lang_msg("MSG_HOSTS_WRITE_EACCES_ERROR", pvar, |
| 1297 |
// 指定したキーを known_hosts に追加する。 |
// 指定したキーを known_hosts に追加する。 |
| 1298 |
void HOSTS_add_host_key(PTInstVar pvar, Key *key) |
void HOSTS_add_host_key(PTInstVar pvar, Key *key) |
| 1299 |
{ |
{ |
| 1300 |
char *name = NULL; |
wchar_t *name = NULL; |
| 1301 |
char *hostname; |
char *hostname; |
| 1302 |
unsigned short tcpport; |
unsigned short tcpport; |
| 1303 |
|
|
| 1319 |
int fd; |
int fd; |
| 1320 |
int amount_written; |
int amount_written; |
| 1321 |
int close_result; |
int close_result; |
| 1322 |
char buf[FILENAME_MAX]; |
wchar_t *buf; |
| 1323 |
|
|
| 1324 |
get_teraterm_dir_relative_name(buf, sizeof(buf), name); |
buf = get_teraterm_dir_relative_nameW(name); |
| 1325 |
fd = _open(buf, |
fd = _wopen(buf, |
| 1326 |
_O_APPEND | _O_CREAT | _O_WRONLY | _O_SEQUENTIAL | _O_BINARY, |
_O_APPEND | _O_CREAT | _O_WRONLY | _O_SEQUENTIAL | _O_BINARY, |
| 1327 |
_S_IREAD | _S_IWRITE); |
_S_IREAD | _S_IWRITE); |
| 1328 |
|
free(buf); |
| 1329 |
if (fd == -1) { |
if (fd == -1) { |
| 1330 |
if (errno == EACCES) { |
if (errno == EACCES) { |
| 1331 |
UTIL_get_lang_msg("MSG_HOSTS_WRITE_EACCES_ERROR", pvar, |
UTIL_get_lang_msg("MSG_HOSTS_WRITE_EACCES_ERROR", pvar, |
| 1361 |
// |
// |
| 1362 |
static void delete_different_key(PTInstVar pvar) |
static void delete_different_key(PTInstVar pvar) |
| 1363 |
{ |
{ |
| 1364 |
char *name = pvar->hosts_state.file_names[0]; |
wchar_t *name = pvar->hosts_state.file_names[0]; |
| 1365 |
|
|
| 1366 |
if (name == NULL || name[0] == 0) { |
if (name == NULL || name[0] == 0) { |
| 1367 |
UTIL_get_lang_msg("MSG_HOSTS_FILE_UNSPECIFY_ERROR", pvar, |
UTIL_get_lang_msg("MSG_HOSTS_FILE_UNSPECIFY_ERROR", pvar, |
| 1380 |
int amount_written = 0; |
int amount_written = 0; |
| 1381 |
int close_result; |
int close_result; |
| 1382 |
int data_index = 0; |
int data_index = 0; |
| 1383 |
char buf[FILENAME_MAX]; |
wchar_t *buf; |
| 1384 |
|
wchar_t *filenameW; |
| 1385 |
|
|
| 1386 |
// 書き込み一時ファイルを開く |
// 書き込み一時ファイルを開く |
| 1387 |
#if _MSC_VER < 1900 // less than VSC2015(VC14.0) |
#if _MSC_VER < 1900 // less than VSC2015(VC14.0) |
| 1535 |
} |
} |
| 1536 |
|
|
| 1537 |
// 書き込み一時ファイルからリネーム |
// 書き込み一時ファイルからリネーム |
| 1538 |
get_teraterm_dir_relative_name(buf, sizeof(buf), name); |
buf = get_teraterm_dir_relative_nameW(name); |
| 1539 |
_unlink(buf); |
_wunlink(buf); |
| 1540 |
rename(filename, buf); |
filenameW = ToWcharA(filename); |
| 1541 |
|
_wrename(filenameW, buf); |
| 1542 |
|
free(buf); |
| 1543 |
|
free(filenameW); |
| 1544 |
|
|
| 1545 |
error2: |
error2: |
| 1546 |
_unlink(filename); |
_unlink(filename); |
| 1555 |
|
|
| 1556 |
void HOSTS_delete_all_hostkeys(PTInstVar pvar) |
void HOSTS_delete_all_hostkeys(PTInstVar pvar) |
| 1557 |
{ |
{ |
| 1558 |
char *name = pvar->hosts_state.file_names[0]; |
wchar_t *name = pvar->hosts_state.file_names[0]; |
| 1559 |
char *hostname; |
char *hostname; |
| 1560 |
unsigned short tcpport; |
unsigned short tcpport; |
| 1561 |
|
|
| 1579 |
int amount_written = 0; |
int amount_written = 0; |
| 1580 |
int close_result; |
int close_result; |
| 1581 |
int data_index = 0; |
int data_index = 0; |
| 1582 |
char buf[FILENAME_MAX]; |
wchar_t *buf; |
| 1583 |
|
wchar_t *filenameW; |
| 1584 |
|
|
| 1585 |
// 書き込み一時ファイルを開く |
// 書き込み一時ファイルを開く |
| 1586 |
#if _MSC_VER < 1900 // less than VSC2015(VC14.0) |
#if _MSC_VER < 1900 // less than VSC2015(VC14.0) |
| 1732 |
} |
} |
| 1733 |
|
|
| 1734 |
// 書き込み一時ファイルからリネーム |
// 書き込み一時ファイルからリネーム |
| 1735 |
get_teraterm_dir_relative_name(buf, sizeof(buf), name); |
buf = get_teraterm_dir_relative_nameW(name); |
| 1736 |
_unlink(buf); |
_wunlink(buf); |
| 1737 |
rename(filename, buf); |
filenameW = ToWcharA(filename); |
| 1738 |
|
_wrename(filenameW, buf); |
| 1739 |
|
free(filenameW); |
| 1740 |
|
free(buf); |
| 1741 |
|
|
| 1742 |
error2: |
error2: |
| 1743 |
_unlink(filename); |
_unlink(filename); |