Develop and Download Open Source Software

Browse Subversion Repository

Diff of /trunk/ttssh2/ttxssh/hosts.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 9350 by zmatsuo, Tue Aug 10 14:42:28 2021 UTC revision 9504 by zmatsuo, Fri Oct 29 15:19:06 2021 UTC
# Line 41  See LICENSE.TXT for the license. Line 41  See LICENSE.TXT for the license.
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>
# Line 53  See LICENSE.TXT for the license. Line 54  See LICENSE.TXT for the license.
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"
# Line 72  BOOL HOSTS_resume_session_after_known_ho Line 74  BOOL HOSTS_resume_session_after_known_ho
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++) {
# Line 87  static char **parse_multi_path(char *buf Line 89  static char **parse_multi_path(char *buf
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;
# Line 123  void HOSTS_init(PTInstVar pvar) Line 125  void HOSTS_init(PTInstVar pvar)
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) {
# Line 560  static int read_host_key(PTInstVar pvar, Line 565  static int read_host_key(PTInstVar pvar,
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) {
# Line 797  int HOSTS_hostkey_foreach(PTInstVar pvar Line 802  int HOSTS_hostkey_foreach(PTInstVar pvar
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    
# Line 1238  static char *format_specified_host_key(K Line 1243  static char *format_specified_host_key(K
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];
# Line 1254  static void add_host_key(PTInstVar pvar) Line 1259  static void add_host_key(PTInstVar pvar)
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,
# Line 1291  static void add_host_key(PTInstVar pvar) Line 1297  static void add_host_key(PTInstVar 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    
# Line 1313  void HOSTS_add_host_key(PTInstVar pvar, Line 1319  void HOSTS_add_host_key(PTInstVar pvar,
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,
# Line 1354  void HOSTS_add_host_key(PTInstVar pvar, Line 1361  void HOSTS_add_host_key(PTInstVar 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,
# Line 1373  static void delete_different_key(PTInstV Line 1380  static void delete_different_key(PTInstV
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)
# Line 1527  error1: Line 1535  error1:
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);
# Line 1544  error2: Line 1555  error2:
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    
# Line 1568  void HOSTS_delete_all_hostkeys(PTInstVar Line 1579  void HOSTS_delete_all_hostkeys(PTInstVar
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)
# Line 1720  void HOSTS_delete_all_hostkeys(PTInstVar Line 1732  void HOSTS_delete_all_hostkeys(PTInstVar
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);

Legend:
Removed from v.9350  
changed lines
  Added in v.9504

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26