Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /branches/ssh_chacha20poly1305/ttssh2/ttxssh/ttxssh.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8089 - (hide annotations) (download) (as text)
Sun Sep 8 04:29:40 2019 UTC (4 years, 7 months ago) by yutakapon
Original Path: trunk/ttssh2/ttxssh/ttxssh.c
File MIME type: text/x-csrc
File size: 176599 byte(s)
設定ダイアログ:SSH、SSH認証、SSH転送、SSH鍵生成にヘルプボタンを追加した。

branches/ttssh_improvedからリビジョン8058をマージ:
設定ダイアログ:SSH、SSH認証、SSH転送、SSH鍵生成
ヘルプボタンを追加した。

........
branches/ttssh_improvedからリビジョン8060をマージ:
rcファイル内のコントロールの位置を移動
........


1 maya 3227 /*
2 doda 6841 * Copyright (c) 1998-2001, Robert O'Callahan
3 zmatsuo 7605 * (C) 2004-2019 TeraTerm Project
4 doda 6841 * All rights reserved.
5     *
6     * Redistribution and use in source and binary forms, with or without
7     * modification, are permitted provided that the following conditions
8     * are met:
9     *
10     * 1. Redistributions of source code must retain the above copyright
11     * notice, this list of conditions and the following disclaimer.
12     * 2. Redistributions in binary form must reproduce the above copyright
13     * notice, this list of conditions and the following disclaimer in the
14     * documentation and/or other materials provided with the distribution.
15     * 3. The name of the author may not be used to endorse or promote products
16     * derived from this software without specific prior written permission.
17     *
18     * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
19     * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20     * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21     * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22     * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23     * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24     * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25     * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27     * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28     */
29 maya 3227
30     /* Tera Term extension mechanism
31     Robert O'Callahan (roc+tt@cs.cmu.edu)
32    
33     Tera Term by Takashi Teranishi (teranishi@rikaxp.riken.go.jp)
34     */
35    
36 zmatsuo 7554 #include "teraterm_conf.h"
37 maya 3227 #include "ttxssh.h"
38     #include "fwdui.h"
39     #include "util.h"
40     #include "ssh.h"
41     #include "ttcommon.h"
42 r850 3298 #include "ttlib.h"
43 yutakapon 5545 #include "keyfiles.h"
44 doda 6250 #include "arc4random.h"
45 zmatsuo 7605 #include "auth.h"
46 yutakapon 8089 #include "helpid.h"
47 maya 3227
48     #include <stdlib.h>
49     #include <stdio.h>
50     #include <string.h>
51     #include <io.h>
52     #include <fcntl.h>
53     #include <sys/stat.h>
54     #include <time.h>
55 doda 3232 #include <mbstring.h>
56 maya 3227
57     #include "resource.h"
58     #include <commctrl.h>
59     #include <commdlg.h>
60     #include <winsock2.h>
61 yasuhide 8064 static char *ProtocolFamilyList[] = { "AUTO", "IPv6", "IPv4", NULL };
62 maya 3227
63 zmatsuo 7542 #include <lmcons.h>
64 maya 3227
65     // include OpenSSL header file
66     #include <openssl/evp.h>
67     #include <openssl/rsa.h>
68     #include <openssl/dsa.h>
69     #include <openssl/bn.h>
70     #include <openssl/pem.h>
71     #include <openssl/rand.h>
72     #include <openssl/rc4.h>
73     #include <openssl/md5.h>
74    
75     // include ZLib header file
76     #include <zlib.h>
77    
78     #include "buffer.h"
79     #include "cipher.h"
80 maya 4321 #include "key.h"
81 zmatsuo 7560 #include "dlglib.h"
82 maya 3227
83     #include "sftp.h"
84    
85     #include "compat_w95.h"
86 zmatsuo 7554 #include "compat_win.h"
87 maya 3227
88 maya 6625 #include "libputty.h"
89 yutakapon 4533
90 zmatsuo 7560 #undef DialogBoxParam
91     #define DialogBoxParam(p1,p2,p3,p4,p5) \
92     TTDialogBoxParam(p1,p2,p3,p4,p5)
93     #undef EndDialog
94     #define EndDialog(p1,p2) \
95     TTEndDialog(p1, p2)
96    
97 maya 3227 #define MATCH_STR(s, o) strncmp((s), (o), NUM_ELEM(o) - 1)
98     #define MATCH_STR_I(s, o) _strnicmp((s), (o), NUM_ELEM(o) - 1)
99    
100     /* This extension implements SSH, so we choose a load order in the
101     "protocols" range. */
102     #define ORDER 2500
103    
104     static HICON SecureLargeIcon = NULL;
105     static HICON SecureSmallIcon = NULL;
106 doda 6691 static HICON SecureNotifyIcon = NULL;
107     static HICON OldNotifyIcon = NULL;
108 maya 3227
109 doda 6801 static TInstVar *pvar;
110 maya 3227
111     typedef struct {
112 maya 4307 int cnt;
113     HWND dlg;
114 maya 4378 ssh_keytype type;
115 maya 3227 } cbarg_t;
116    
117     /* WIN32 allows multiple instances of a DLL */
118     static TInstVar InstVar;
119    
120     /*
121     This code makes lots of assumptions about the order in which Tera Term
122     does things, and how. A key assumption is that the Notification window
123     passed into WSAAsyncSelect is the main terminal window. We also assume
124     that the socket used in the first WSAconnect is the main session socket.
125     */
126    
127     static void init_TTSSH(PTInstVar pvar)
128     {
129     pvar->socket = INVALID_SOCKET;
130     pvar->OldLargeIcon = NULL;
131     pvar->OldSmallIcon = NULL;
132     pvar->NotificationWindow = NULL;
133     pvar->hostdlg_activated = FALSE;
134     pvar->socket = INVALID_SOCKET;
135     pvar->NotificationWindow = NULL;
136     pvar->protocol_major = 0;
137     pvar->protocol_minor = 0;
138    
139     PKT_init(pvar);
140     SSH_init(pvar);
141     CRYPT_init(pvar);
142     AUTH_init(pvar);
143     HOSTS_init(pvar);
144     FWD_init(pvar);
145     FWDUI_init(pvar);
146    
147     ssh_heartbeat_lock_initialize();
148     }
149    
150     static void uninit_TTSSH(PTInstVar pvar)
151     {
152     halt_ssh_heartbeat_thread(pvar);
153    
154     ssh2_channel_free();
155    
156     SSH_end(pvar);
157     PKT_end(pvar);
158     AUTH_end(pvar);
159     CRYPT_end(pvar);
160     HOSTS_end(pvar);
161     FWD_end(pvar);
162     FWDUI_end(pvar);
163    
164     if (pvar->OldLargeIcon != NULL) {
165     PostMessage(pvar->NotificationWindow, WM_SETICON, ICON_BIG,
166     (LPARAM) pvar->OldLargeIcon);
167     pvar->OldLargeIcon = NULL;
168     }
169     if (pvar->OldSmallIcon != NULL) {
170     PostMessage(pvar->NotificationWindow, WM_SETICON, ICON_SMALL,
171     (LPARAM) pvar->OldSmallIcon);
172     pvar->OldSmallIcon = NULL;
173     }
174 doda 6691 if (OldNotifyIcon) {
175     SetCustomNotifyIcon(OldNotifyIcon);
176     }
177 maya 3227
178     ssh_heartbeat_lock_finalize();
179     }
180    
181 doda 6801 static void PASCAL TTXInit(PTTSet ts, PComVar cv)
182 maya 3227 {
183     pvar->settings = *pvar->ts_SSH;
184     pvar->ts = ts;
185     pvar->cv = cv;
186     pvar->fatal_error = FALSE;
187     pvar->showing_err = FALSE;
188     pvar->err_msg = NULL;
189    
190     init_TTSSH(pvar);
191     }
192    
193 maya 4378 static void normalize_generic_order(char *buf, char default_strings[], int default_strings_len)
194     {
195     char listed[max(KEX_DH_MAX,max(SSH_CIPHER_MAX,max(KEY_MAX,max(HMAC_MAX,COMP_MAX)))) + 1];
196     char allowed[max(KEX_DH_MAX,max(SSH_CIPHER_MAX,max(KEY_MAX,max(HMAC_MAX,COMP_MAX)))) + 1];
197 maya 6031 int i, j, k=-1;
198 maya 4378
199     memset(listed, 0, sizeof(listed));
200     memset(allowed, 0, sizeof(allowed));
201 yutakapon 6508
202     // �����������������������X�g�������B
203 maya 4378 for (i = 0; i < default_strings_len ; i++) {
204     allowed[default_strings[i]] = 1;
205     }
206    
207 yutakapon 6508 // �w�����������������������A���������������������A�d���������������������B
208     //
209     // ex. (i=5 ����������������)
210     // i=012345
211     // >:=9<87;A@?B3026(\0)
212     // i+1
213     // <------------>
214     // ��
215     // >:=9<7;A@?B3026(\0)
216     //
217 maya 4378 for (i = 0; buf[i] != 0; i++) {
218     int num = buf[i] - '0';
219    
220     if (num < 0 || num > default_strings_len
221     || !allowed[num]
222     || listed[num]) {
223     memmove(buf + i, buf + i + 1, strlen(buf + i + 1) + 1);
224     i--;
225     } else {
226     listed[num] = 1;
227     }
228 maya 6031
229 yutakapon 6508 // disabled line���������A���u���o���������B
230 maya 6031 if (num == 0) {
231     k = i;
232     }
233 maya 4378 }
234    
235 yutakapon 6508 // �w���������������������������Adisabled line�����O���}�������B
236     //
237     // ex. (Z���}������)
238     // k
239     // >:=9<87;A@?B3026(\0)
240     // k+1
241     // <---->
242     // �� k
243     // >:=9<87;A@?B30026(\0)
244     // �� k
245     // >:=9<87;A@?B3Z026(\0)
246     //
247 maya 6031 for (j = 0; j < default_strings_len && default_strings[j] != 0; j++) {
248     int num = default_strings[j];
249    
250     if (!listed[num] && k >= 0) {
251 yutakapon 6508 int copylen = strlen(buf + k + 1) + 1;
252    
253     memmove(buf + k + 1, buf + k, copylen);
254     buf[k + 1 + copylen] = '\0'; // �I�[���Y�������t�����B
255 maya 6031 buf[k] = num + '0';
256     k++;
257     i++;
258     }
259     }
260     if (k < 0) {
261     j = 0;
262     }
263     else {
264     j++;
265     }
266 yutakapon 6508
267     // disabled line�������������������A�����������������������B
268 maya 6031 for (; j < default_strings_len ; j++) {
269     int num = default_strings[j];
270    
271     if (!listed[num]) {
272     buf[i] = num + '0';
273 doda 7454 listed[num] = 1;
274 maya 6031 i++;
275     }
276     }
277 maya 4378
278     buf[i] = 0;
279     }
280    
281 maya 3227 /*
282     * Remove unsupported cipher or duplicated cipher.
283     * Add unspecified ciphers at the end of list.
284     */
285 doda 6801 static void normalize_cipher_order(char *buf)
286 maya 3227 {
287     /* SSH_CIPHER_NONE means that all ciphers below that one are disabled.
288     We *never* allow no encryption. */
289 maya 4378 static char default_strings[] = {
290 doda 6985 SSH2_CIPHER_AES256_GCM,
291 doda 4433 SSH2_CIPHER_CAMELLIA256_CTR,
292 maya 3227 SSH2_CIPHER_AES256_CTR,
293 doda 4433 SSH2_CIPHER_CAMELLIA256_CBC,
294 maya 3227 SSH2_CIPHER_AES256_CBC,
295 doda 4433 SSH2_CIPHER_CAMELLIA192_CTR,
296 maya 3227 SSH2_CIPHER_AES192_CTR,
297 doda 4433 SSH2_CIPHER_CAMELLIA192_CBC,
298 maya 3227 SSH2_CIPHER_AES192_CBC,
299 doda 6985 SSH2_CIPHER_AES128_GCM,
300 doda 4433 SSH2_CIPHER_CAMELLIA128_CTR,
301 maya 3227 SSH2_CIPHER_AES128_CTR,
302 doda 4433 SSH2_CIPHER_CAMELLIA128_CBC,
303 maya 3227 SSH2_CIPHER_AES128_CBC,
304 doda 3850 SSH2_CIPHER_3DES_CTR,
305 maya 3227 SSH2_CIPHER_3DES_CBC,
306 doda 3850 SSH2_CIPHER_BLOWFISH_CTR,
307 maya 3227 SSH2_CIPHER_BLOWFISH_CBC,
308 doda 3850 SSH2_CIPHER_CAST128_CTR,
309 maya 3227 SSH2_CIPHER_CAST128_CBC,
310     SSH_CIPHER_3DES,
311     SSH_CIPHER_NONE,
312 maya 5917 SSH2_CIPHER_ARCFOUR256,
313     SSH2_CIPHER_ARCFOUR128,
314     SSH2_CIPHER_ARCFOUR,
315     SSH_CIPHER_BLOWFISH,
316 maya 3227 SSH_CIPHER_DES,
317 maya 4432 0, 0, 0 // Dummy for SSH_CIPHER_IDEA, SSH_CIPHER_TSS, SSH_CIPHER_RC4
318 maya 3227 };
319    
320 maya 4378 normalize_generic_order(buf, default_strings, NUM_ELEM(default_strings));
321 maya 3227 }
322    
323 doda 6801 static void normalize_kex_order(char *buf)
324 yutakapon 4367 {
325     static char default_strings[] = {
326     KEX_ECDH_SHA2_256,
327     KEX_ECDH_SHA2_384,
328     KEX_ECDH_SHA2_521,
329 doda 6310 KEX_DH_GRP18_SHA512,
330     KEX_DH_GRP16_SHA512,
331 doda 6263 KEX_DH_GRP14_SHA256,
332 yutakapon 4367 KEX_DH_GEX_SHA256,
333     KEX_DH_GEX_SHA1,
334     KEX_DH_GRP14_SHA1,
335     KEX_DH_GRP1_SHA1,
336     KEX_DH_NONE,
337     };
338    
339     normalize_generic_order(buf, default_strings, NUM_ELEM(default_strings));
340     }
341    
342 doda 6801 static void normalize_host_key_order(char *buf)
343 yutakapon 4367 {
344     static char default_strings[] = {
345     KEY_ECDSA256,
346     KEY_ECDSA384,
347     KEY_ECDSA521,
348 yutakapon 5545 KEY_ED25519,
349 yutakapon 4367 KEY_RSA,
350     KEY_DSA,
351     KEY_NONE,
352     };
353    
354     normalize_generic_order(buf, default_strings, NUM_ELEM(default_strings));
355     }
356    
357 doda 6801 static void normalize_mac_order(char *buf)
358 yutakapon 4367 {
359     static char default_strings[] = {
360 doda 6969 HMAC_SHA2_512_EtM,
361     HMAC_SHA2_256_EtM,
362     HMAC_SHA1_EtM,
363 doda 4434 HMAC_SHA2_512,
364     HMAC_SHA2_256,
365 yutakapon 4367 HMAC_SHA1,
366 doda 6969 HMAC_RIPEMD160_EtM,
367 doda 4423 HMAC_RIPEMD160,
368 doda 6969 HMAC_MD5_EtM,
369 yutakapon 4367 HMAC_MD5,
370 doda 4426 HMAC_NONE,
371 doda 6969 HMAC_SHA1_96_EtM,
372     HMAC_MD5_96_EtM,
373 doda 4434 HMAC_SHA1_96,
374     HMAC_MD5_96,
375 doda 5016 0, // Dummy for HMAC_SHA2_512_96,
376     0, // Dummy for HMAC_SHA2_256_96,
377 yutakapon 4367 };
378    
379     normalize_generic_order(buf, default_strings, NUM_ELEM(default_strings));
380     }
381    
382 doda 6801 static void normalize_comp_order(char *buf)
383 yutakapon 4367 {
384     static char default_strings[] = {
385 doda 4371 COMP_DELAYED,
386     COMP_ZLIB,
387 maya 4378 COMP_NOCOMP,
388 yutakapon 4367 COMP_NONE,
389     };
390    
391     normalize_generic_order(buf, default_strings, NUM_ELEM(default_strings));
392     }
393    
394    
395 maya 3227 /* Remove local settings from the shared memory block. */
396     static void clear_local_settings(PTInstVar pvar)
397     {
398     pvar->ts_SSH->TryDefaultAuth = FALSE;
399     }
400    
401 doda 6801 static BOOL read_BOOL_option(PCHAR fileName, char *keyName, BOOL def)
402 maya 3227 {
403     char buf[1024];
404    
405     buf[0] = 0;
406     GetPrivateProfileString("TTSSH", keyName, "", buf, sizeof(buf),
407     fileName);
408     if (buf[0] == 0) {
409     return def;
410     } else {
411     return atoi(buf) != 0 ||
412     _stricmp(buf, "yes") == 0 ||
413     _stricmp(buf, "y") == 0;
414     }
415     }
416    
417 doda 6801 static void read_string_option(PCHAR fileName, char *keyName,
418     char *def, char *buf, int bufSize)
419 maya 3227 {
420    
421     buf[0] = 0;
422     GetPrivateProfileString("TTSSH", keyName, def, buf, bufSize, fileName);
423     }
424    
425     static void read_ssh_options(PTInstVar pvar, PCHAR fileName)
426     {
427     char buf[1024];
428 doda 6801 TS_SSH *settings = pvar->ts_SSH;
429 maya 3227
430     #define READ_STD_STRING_OPTION(name) \
431     read_string_option(fileName, #name, "", settings->name, sizeof(settings->name))
432    
433     settings->Enabled = read_BOOL_option(fileName, "Enabled", FALSE);
434    
435     buf[0] = 0;
436     GetPrivateProfileString("TTSSH", "Compression", "", buf, sizeof(buf),
437     fileName);
438     settings->CompressionLevel = atoi(buf);
439     if (settings->CompressionLevel < 0 || settings->CompressionLevel > 9) {
440     settings->CompressionLevel = 0;
441     }
442    
443     READ_STD_STRING_OPTION(DefaultUserName);
444 zmatsuo 7632 settings->DefaultUserType = GetPrivateProfileInt("TTSSH", "DefaultUserType", 1, fileName);
445    
446 maya 3227 READ_STD_STRING_OPTION(DefaultForwarding);
447     READ_STD_STRING_OPTION(DefaultRhostsLocalUserName);
448     READ_STD_STRING_OPTION(DefaultRhostsHostPrivateKeyFile);
449     READ_STD_STRING_OPTION(DefaultRSAPrivateKeyFile);
450    
451     READ_STD_STRING_OPTION(CipherOrder);
452     normalize_cipher_order(settings->CipherOrder);
453    
454 yutakapon 4367 // KEX order
455     READ_STD_STRING_OPTION(KexOrder);
456     normalize_kex_order(settings->KexOrder);
457     // Host Key algorithm order
458     READ_STD_STRING_OPTION(HostKeyOrder);
459     normalize_host_key_order(settings->HostKeyOrder);
460 doda 6821 // HMAC order
461 yutakapon 4367 READ_STD_STRING_OPTION(MacOrder);
462     normalize_mac_order(settings->MacOrder);
463     // Compression algorithm order
464     READ_STD_STRING_OPTION(CompOrder);
465     normalize_comp_order(settings->CompOrder);
466    
467 maya 3227 read_string_option(fileName, "KnownHostsFiles", "ssh_known_hosts",
468     settings->KnownHostsFiles,
469     sizeof(settings->KnownHostsFiles));
470    
471     buf[0] = 0;
472     GetPrivateProfileString("TTSSH", "DefaultAuthMethod", "", buf,
473     sizeof(buf), fileName);
474     settings->DefaultAuthMethod = atoi(buf);
475     if (settings->DefaultAuthMethod != SSH_AUTH_PASSWORD
476     && settings->DefaultAuthMethod != SSH_AUTH_RSA
477     && settings->DefaultAuthMethod != SSH_AUTH_TIS // add (2005.3.12 yutaka)
478     && settings->DefaultAuthMethod != SSH_AUTH_RHOSTS
479     && settings->DefaultAuthMethod != SSH_AUTH_PAGEANT) {
480     /* this default can never be SSH_AUTH_RHOSTS_RSA because that is not a
481     selection in the dialog box; SSH_AUTH_RHOSTS_RSA is automatically chosen
482     when the dialog box has rhosts selected and an host private key file
483     is supplied. */
484     settings->DefaultAuthMethod = SSH_AUTH_PASSWORD;
485     }
486    
487     buf[0] = 0;
488     GetPrivateProfileString("TTSSH", "LogLevel", "", buf, sizeof(buf),
489     fileName);
490     settings->LogLevel = atoi(buf);
491    
492     buf[0] = 0;
493     GetPrivateProfileString("TTSSH", "WriteBufferSize", "", buf,
494     sizeof(buf), fileName);
495     settings->WriteBufferSize = atoi(buf);
496     if (settings->WriteBufferSize <= 0) {
497     settings->WriteBufferSize = (PACKET_MAX_SIZE / 2); // 2MB
498     }
499    
500     // SSH protocol version (2004.10.11 yutaka)
501     // default is SSH2 (2004.11.30 yutaka)
502     settings->ssh_protocol_version = GetPrivateProfileInt("TTSSH", "ProtocolVersion", 2, fileName);
503    
504     // SSH heartbeat time(second) (2004.12.11 yutaka)
505     settings->ssh_heartbeat_overtime = GetPrivateProfileInt("TTSSH", "HeartBeat", 60, fileName);
506    
507     // �p�X���[�h�F�����������J���F�����g���p�X���[�h����������������������������������
508     // �\���B(2006.8.5 yutaka)
509     settings->remember_password = GetPrivateProfileInt("TTSSH", "RememberPassword", 1, fileName);
510    
511     // �������F���_�C�A���O���T�|�[�g�������������\�b�h���`�F�b�N���A
512     // ���������\�b�h���O���C�A�E�g���� (2007.9.24 maya)
513     settings->CheckAuthListFirst = read_BOOL_option(fileName, "CheckAuthListFirst", FALSE);
514    
515     // 768bit ������ RSA ���������T�[�o�����������L�������� (2008.9.11 maya)
516     settings->EnableRsaShortKeyServer = read_BOOL_option(fileName, "EnableRsaShortKeyServer", FALSE);
517    
518     // agent forward ���L�������� (2008.11.25 maya)
519     settings->ForwardAgent = read_BOOL_option(fileName, "ForwardAgent", FALSE);
520    
521 maya 4229 // agent forward �m�F���L��������
522     settings->ForwardAgentConfirm = read_BOOL_option(fileName, "ForwardAgentConfirm", TRUE);
523    
524 doda 6663 // agent forward �m�F���L��������
525     settings->ForwardAgentNotify = read_BOOL_option(fileName, "ForwardAgentNotify", TRUE);
526    
527 doda 4531 // �z�X�g���� DNS �����`�F�b�N (RFC 4255)
528 doda 4619 settings->VerifyHostKeyDNS = read_BOOL_option(fileName, "VerifyHostKeyDNS", TRUE);
529 doda 4531
530 doda 5261 // icon
531     GetPrivateProfileString("TTSSH", "SSHIcon", "", buf, sizeof(buf), fileName);
532     if ((_stricmp(buf, "old") == 0) ||
533     (_stricmp(buf, "yellow") == 0) ||
534     (_stricmp(buf, "securett_yellow") == 0)) {
535     settings->IconID = IDI_SECURETT_YELLOW;
536     }
537 maya 6386 else if ((_stricmp(buf, "green") == 0) ||
538     (_stricmp(buf, "securett_green") == 0)) {
539     settings->IconID = IDI_SECURETT_GREEN;
540     }
541 doda 5261 else {
542     settings->IconID = IDI_SECURETT;
543     }
544    
545 yutakapon 5620 // �G���[�������x�������|�b�v�A�b�v���b�Z�[�W���}�~���� (2014.6.26 yutaka)
546     settings->DisablePopupMessage = GetPrivateProfileInt("TTSSH", "DisablePopupMessage", 0, fileName);
547    
548 doda 5793 READ_STD_STRING_OPTION(X11Display);
549    
550 yutakapon 5849 settings->UpdateHostkeys = GetPrivateProfileInt("TTSSH", "UpdateHostkeys", 0, fileName);
551 yutakapon 5839
552 doda 5900 settings->GexMinimalGroupSize = GetPrivateProfileInt("TTSSH", "GexMinimalGroupSize", 0, fileName);
553    
554 doda 7048 settings->AuthBanner = GetPrivateProfileInt("TTSSH", "AuthBanner", 1, fileName);
555    
556 maya 3227 clear_local_settings(pvar);
557     }
558    
559     static void write_ssh_options(PTInstVar pvar, PCHAR fileName,
560 doda 6801 TS_SSH *settings, BOOL copy_forward)
561 maya 3227 {
562     char buf[1024];
563    
564     WritePrivateProfileString("TTSSH", "Enabled",
565     settings->Enabled ? "1" : "0", fileName);
566    
567     _itoa(settings->CompressionLevel, buf, 10);
568     WritePrivateProfileString("TTSSH", "Compression", buf, fileName);
569    
570 zmatsuo 7632 _itoa(settings->DefaultUserType, buf, 10);
571     WritePrivateProfileString("TTSSH", "DefaultUserType", buf, fileName);
572 maya 3227 WritePrivateProfileString("TTSSH", "DefaultUserName",
573     settings->DefaultUserName, fileName);
574    
575     if (copy_forward) {
576     WritePrivateProfileString("TTSSH", "DefaultForwarding",
577 maya 5960 settings->DefaultForwarding, fileName);
578 maya 3227 }
579    
580     WritePrivateProfileString("TTSSH", "CipherOrder",
581     settings->CipherOrder, fileName);
582    
583 yutakapon 4367 WritePrivateProfileString("TTSSH", "KexOrder",
584     settings->KexOrder, fileName);
585    
586     WritePrivateProfileString("TTSSH", "HostKeyOrder",
587     settings->HostKeyOrder, fileName);
588    
589     WritePrivateProfileString("TTSSH", "MacOrder",
590     settings->MacOrder, fileName);
591    
592     WritePrivateProfileString("TTSSH", "CompOrder",
593     settings->CompOrder, fileName);
594    
595 maya 3227 WritePrivateProfileString("TTSSH", "KnownHostsFiles",
596     settings->KnownHostsFiles, fileName);
597    
598     WritePrivateProfileString("TTSSH", "DefaultRhostsLocalUserName",
599     settings->DefaultRhostsLocalUserName,
600     fileName);
601    
602     WritePrivateProfileString("TTSSH", "DefaultRhostsHostPrivateKeyFile",
603     settings->DefaultRhostsHostPrivateKeyFile,
604     fileName);
605    
606     WritePrivateProfileString("TTSSH", "DefaultRSAPrivateKeyFile",
607     settings->DefaultRSAPrivateKeyFile,
608     fileName);
609    
610     _itoa(settings->DefaultAuthMethod, buf, 10);
611     WritePrivateProfileString("TTSSH", "DefaultAuthMethod", buf, fileName);
612    
613     _itoa(settings->LogLevel, buf, 10);
614     WritePrivateProfileString("TTSSH", "LogLevel", buf, fileName);
615    
616     _itoa(settings->WriteBufferSize, buf, 10);
617     WritePrivateProfileString("TTSSH", "WriteBufferSize", buf, fileName);
618    
619     // SSH protocol version (2004.10.11 yutaka)
620     WritePrivateProfileString("TTSSH", "ProtocolVersion",
621     settings->ssh_protocol_version==2 ? "2" : "1",
622     fileName);
623    
624     // SSH heartbeat time(second) (2004.12.11 yutaka)
625     _snprintf_s(buf, sizeof(buf), _TRUNCATE,
626     "%d", settings->ssh_heartbeat_overtime);
627     WritePrivateProfileString("TTSSH", "HeartBeat", buf, fileName);
628    
629     // Remember password (2006.8.5 yutaka)
630     WritePrivateProfileString("TTSSH", "RememberPassword",
631     settings->remember_password ? "1" : "0",
632     fileName);
633    
634     // �������F���_�C�A���O���T�|�[�g�������������\�b�h���`�F�b�N���A
635     // ���������\�b�h���O���C�A�E�g���� (2007.9.24 maya)
636     WritePrivateProfileString("TTSSH", "CheckAuthListFirst",
637     settings->CheckAuthListFirst ? "1" : "0", fileName);
638    
639     // 768bit ������ RSA ���������T�[�o�����������L�������� (2008.9.11 maya)
640     WritePrivateProfileString("TTSSH", "EnableRsaShortKeyServer",
641     settings->EnableRsaShortKeyServer ? "1" : "0", fileName);
642    
643     // agent forward ���L�������� (2008.11.25 maya)
644     WritePrivateProfileString("TTSSH", "ForwardAgent",
645     settings->ForwardAgent ? "1" : "0", fileName);
646 maya 4229
647     // agent forward �m�F���L��������
648     WritePrivateProfileString("TTSSH", "ForwardAgentConfirm",
649     settings->ForwardAgentConfirm ? "1" : "0", fileName);
650 doda 4531
651 doda 6663 // agent forward ���m���L��������
652     WritePrivateProfileString("TTSSH", "ForwardAgentNotify",
653     settings->ForwardAgentNotify ? "1" : "0", fileName);
654    
655 doda 4531 // �z�X�g���� DNS �����`�F�b�N (RFC 4255)
656     WritePrivateProfileString("TTSSH", "VerifyHostKeyDNS",
657     settings->VerifyHostKeyDNS ? "1" : "0", fileName);
658 doda 5294
659     // SSH �A�C�R��
660 maya 6386 if (settings->IconID==IDI_SECURETT_YELLOW) {
661     WritePrivateProfileString("TTSSH", "SSHIcon", "yellow", fileName);
662     }
663     else if (settings->IconID==IDI_SECURETT_GREEN) {
664     WritePrivateProfileString("TTSSH", "SSHIcon", "green", fileName);
665     }
666     else {
667     WritePrivateProfileString("TTSSH", "SSHIcon", "Default", fileName);
668     }
669 yutakapon 5620
670     _itoa(settings->DisablePopupMessage, buf, 10);
671     WritePrivateProfileString("TTSSH", "DisablePopupMessage", buf, fileName);
672 doda 5793
673     WritePrivateProfileString("TTSSH", "X11Display", settings->X11Display, fileName);
674 yutakapon 5839
675 yutakapon 5849 _snprintf_s(buf, sizeof(buf), _TRUNCATE,
676     "%d", settings->UpdateHostkeys);
677     WritePrivateProfileString("TTSSH", "UpdateHostkeys", buf, fileName);
678 doda 5900
679     _itoa_s(settings->GexMinimalGroupSize, buf, sizeof(buf), 10);
680     WritePrivateProfileString("TTSSH", "GexMinimalGroupSize", buf, fileName);
681 doda 7048
682     _itoa_s(settings->AuthBanner, buf, sizeof(buf), 10);
683     WritePrivateProfileString("TTSSH", "AuthBanner", buf, fileName);
684 maya 3227 }
685    
686    
687     /* find free port in all protocol family */
688     static unsigned short find_local_port(PTInstVar pvar)
689     {
690     int tries;
691     SOCKET connecter;
692     struct addrinfo hints;
693 doda 6801 struct addrinfo *res;
694     struct addrinfo *res0;
695 maya 3227 unsigned short port;
696     char pname[NI_MAXHOST];
697    
698     if (pvar->session_settings.DefaultAuthMethod != SSH_AUTH_RHOSTS) {
699     return 0;
700     }
701    
702     /* The random numbers here are only used to try to get fresh
703     ports across runs (dangling ports can cause bind errors
704     if we're unlucky). They do not need to be (and are not)
705     cryptographically strong.
706     */
707     srand((unsigned) GetTickCount());
708    
709     for (tries = 20; tries > 0; tries--) {
710     memset(&hints, 0, sizeof(hints));
711     hints.ai_family = pvar->ts->ProtocolFamily;
712     hints.ai_flags = AI_PASSIVE;
713     hints.ai_socktype = SOCK_STREAM;
714     port = (unsigned) rand() % 512 + 512;
715     _snprintf_s(pname, sizeof(pname), _TRUNCATE, "%d", (int) port);
716     if (getaddrinfo(NULL, pname, &hints, &res0)) {
717     return 0;
718     /* NOT REACHED */
719     }
720    
721     for (res = res0; res; res = res->ai_next) {
722     if (res->ai_family == AF_INET || res->ai_family == AF_INET6)
723     continue;
724    
725     connecter =
726     socket(res->ai_family, res->ai_socktype, res->ai_protocol);
727     if (connecter == INVALID_SOCKET) {
728     freeaddrinfo(res0);
729     return 0;
730     }
731    
732     if (bind(connecter, res->ai_addr, res->ai_addrlen) !=
733     SOCKET_ERROR) {
734     return port;
735     freeaddrinfo(res0);
736     closesocket(connecter);
737     } else if (WSAGetLastError() != WSAEADDRINUSE) {
738     closesocket(connecter);
739     freeaddrinfo(res0);
740     return 0;
741     }
742    
743     closesocket(connecter);
744     }
745     freeaddrinfo(res0);
746     }
747    
748     return 0;
749     }
750    
751 doda 6801 static int PASCAL TTXconnect(SOCKET s,
752     const struct sockaddr *name,
753 maya 3227 int namelen)
754     {
755 maya 4584 if (pvar->socket == INVALID_SOCKET || pvar->socket != s) {
756 maya 3227 struct sockaddr_storage ss;
757     int len;
758    
759     pvar->socket = s;
760    
761     memset(&ss, 0, sizeof(ss));
762     switch (pvar->ts->ProtocolFamily) {
763     case AF_INET:
764     len = sizeof(struct sockaddr_in);
765 doda 6801 ((struct sockaddr_in *) &ss)->sin_family = AF_INET;
766     ((struct sockaddr_in *) &ss)->sin_addr.s_addr = INADDR_ANY;
767     ((struct sockaddr_in *) &ss)->sin_port =
768 maya 3227 htons(find_local_port(pvar));
769     break;
770     case AF_INET6:
771     len = sizeof(struct sockaddr_in6);
772 doda 6801 ((struct sockaddr_in6 *) &ss)->sin6_family = AF_INET6;
773 zmatsuo 7197 ((struct sockaddr_in6 *) &ss)->sin6_addr = in6addr_any;
774 doda 6801 ((struct sockaddr_in6 *) &ss)->sin6_port =
775 maya 3227 htons(find_local_port(pvar));
776     break;
777     default:
778 maya 4586 /* UNSPEC */
779 zmatsuo 7197 len = sizeof(ss);
780     ss.ss_family = AF_UNSPEC;
781 maya 3227 break;
782     }
783    
784 doda 6801 bind(s, (struct sockaddr *) &ss, len);
785 maya 3227 }
786    
787     return (pvar->Pconnect) (s, name, namelen);
788     }
789    
790 doda 6801 static int PASCAL TTXWSAAsyncSelect(SOCKET s, HWND hWnd, u_int wMsg,
791 maya 3227 long lEvent)
792     {
793     if (s == pvar->socket) {
794     pvar->notification_events = lEvent;
795     pvar->notification_msg = wMsg;
796    
797     if (pvar->NotificationWindow == NULL) {
798     pvar->NotificationWindow = hWnd;
799 yutakapon 8086 // AUTH_advance_to_next_cred()�������o�������������B
800     // NotificationWindow���n���h�������������������A�����^�C�~���O����
801     // �F���_�C�A���O���o���������������BProxy��NAT�o�R���T�[�o������
802     // �������������A���������f�����������������A�F���_�C�A���O��
803     // �\�������������������������B
804 maya 3227 }
805     }
806    
807     return (pvar->PWSAAsyncSelect) (s, hWnd, wMsg, lEvent);
808     }
809    
810 doda 6801 static int PASCAL TTXrecv(SOCKET s, char *buf, int len, int flags)
811 maya 3227 {
812     if (s == pvar->socket) {
813     int ret;
814    
815     ssh_heartbeat_lock();
816     ret = PKT_recv(pvar, buf, len);
817     ssh_heartbeat_unlock();
818     return (ret);
819    
820     } else {
821     return (pvar->Precv) (s, buf, len, flags);
822     }
823     }
824    
825 doda 6801 static int PASCAL TTXsend(SOCKET s, char const *buf, int len,
826 maya 3227 int flags)
827     {
828     if (s == pvar->socket) {
829     ssh_heartbeat_lock();
830     SSH_send(pvar, buf, len);
831     ssh_heartbeat_unlock();
832     return len;
833     } else {
834     return (pvar->Psend) (s, buf, len, flags);
835     }
836     }
837    
838     void notify_established_secure_connection(PTInstVar pvar)
839     {
840     int fuLoad = LR_DEFAULTCOLOR;
841    
842 yutakapon 6286 if (IsWindowsNT4()) {
843 maya 3227 fuLoad = LR_VGACOLOR;
844     }
845    
846     // LoadIcon �������� LoadImage ���g�����������A
847     // 16x16 ���A�C�R���������I�������������������� (2006.8.9 maya)
848     if (SecureLargeIcon == NULL) {
849 doda 5261 SecureLargeIcon = LoadImage(hInst, MAKEINTRESOURCE(pvar->settings.IconID),
850 maya 3227 IMAGE_ICON, 0, 0, fuLoad);
851     }
852     if (SecureSmallIcon == NULL) {
853 doda 5261 SecureSmallIcon = LoadImage(hInst, MAKEINTRESOURCE(pvar->settings.IconID),
854 maya 3227 IMAGE_ICON, 16, 16, fuLoad);
855     }
856    
857     if (SecureLargeIcon != NULL && SecureSmallIcon != NULL) {
858     pvar->OldLargeIcon =
859 maya 3454 (HICON) SendMessage(pvar->NotificationWindow, WM_GETICON,
860     ICON_BIG, 0);
861 maya 3227 pvar->OldSmallIcon =
862     (HICON) SendMessage(pvar->NotificationWindow, WM_GETICON,
863     ICON_SMALL, 0);
864    
865     PostMessage(pvar->NotificationWindow, WM_SETICON, ICON_BIG,
866     (LPARAM) SecureLargeIcon);
867     PostMessage(pvar->NotificationWindow, WM_SETICON, ICON_SMALL,
868     (LPARAM) SecureSmallIcon);
869     }
870    
871 doda 6691 if (IsWindows2000()) {
872     if (SecureNotifyIcon == NULL) {
873     SecureNotifyIcon = LoadImage(hInst, MAKEINTRESOURCE(pvar->settings.IconID),
874     IMAGE_ICON, 0, 0, LR_VGACOLOR | LR_SHARED);
875     }
876     OldNotifyIcon = GetCustomNotifyIcon();
877     SetCustomNotifyIcon(SecureNotifyIcon);
878     }
879    
880 doda 6809 logputs(LOG_LEVEL_VERBOSE, "Entering secure mode");
881 maya 3227 }
882    
883 doda 6801 void notify_closed_connection(PTInstVar pvar, char *send_msg)
884 maya 3227 {
885 maya 5678 SSH_notify_disconnecting(pvar, send_msg);
886 maya 3227 AUTH_notify_disconnecting(pvar);
887     HOSTS_notify_disconnecting(pvar);
888    
889     PostMessage(pvar->NotificationWindow, WM_USER_COMMNOTIFY,
890     pvar->socket, MAKELPARAM(FD_CLOSE, 0));
891     }
892    
893 yutakapon 8087 // non-fatal������fatal�����G���[���b�Z�[�W���o���������B
894     // ���x�A�o�������b�Z�[�W���������A���s���������������������B
895 doda 6801 static void add_err_msg(PTInstVar pvar, char *msg)
896 maya 3227 {
897     if (pvar->err_msg != NULL) {
898 yutakapon 8087 int buf_len;
899     char *buf;
900 maya 3227
901 yutakapon 8087 // �������������b�Z�[�W���o�^�����������������������B
902     if (strstr(pvar->err_msg, msg))
903     return;
904    
905     buf_len = strlen(pvar->err_msg) + 3 + strlen(msg);
906     buf = malloc(buf_len);
907     // ���������m���������������������������B
908     if (buf == NULL)
909     return;
910    
911 maya 3227 strncpy_s(buf, buf_len, pvar->err_msg, _TRUNCATE);
912     strncat_s(buf, buf_len, "\n\n", _TRUNCATE);
913     strncat_s(buf, buf_len, msg, _TRUNCATE);
914     free(pvar->err_msg);
915     pvar->err_msg = buf;
916     } else {
917 yutakapon 8087 // ���������m�����������������A_strdup()��NULL�������B
918 maya 3227 pvar->err_msg = _strdup(msg);
919     }
920     }
921    
922 doda 6801 void notify_nonfatal_error(PTInstVar pvar, char *msg)
923 maya 3227 {
924     if (!pvar->showing_err) {
925     // �������������������m���E�B���h�E�����������A�f�X�N�g�b�v���I�[�i�[������
926     // ���b�Z�[�W�{�b�N�X���o���������B(2006.6.11 yutaka)
927     if (pvar->NotificationWindow == NULL) {
928 doda 6688 UTIL_get_lang_msg("MSG_NONFATAL_ERROR", pvar,
929 maya 3227 "Tera Term: not fatal error");
930     MessageBox(NULL, msg, pvar->ts->UIMsg, MB_OK|MB_ICONINFORMATION);
931     msg[0] = '\0';
932    
933     } else {
934     PostMessage(pvar->NotificationWindow, WM_COMMAND,
935     ID_SSHASYNCMESSAGEBOX, 0);
936     }
937     }
938     if (msg[0] != 0) {
939 doda 6809 logputs(LOG_LEVEL_ERROR, msg);
940 maya 3227 add_err_msg(pvar, msg);
941     }
942     }
943    
944 doda 6801 void notify_fatal_error(PTInstVar pvar, char *msg, BOOL send_disconnect)
945 maya 3227 {
946     if (msg[0] != 0) {
947 doda 6809 logputs(LOG_LEVEL_FATAL, msg);
948 maya 3227 add_err_msg(pvar, msg);
949     }
950    
951     if (!pvar->fatal_error) {
952     pvar->fatal_error = TRUE;
953    
954 maya 5678 if (send_disconnect) {
955     SSH_notify_disconnecting(pvar, msg);
956     }
957 maya 3227 AUTH_notify_disconnecting(pvar);
958     HOSTS_notify_disconnecting(pvar);
959    
960     PostMessage(pvar->NotificationWindow, WM_USER_COMMNOTIFY,
961     pvar->socket, MAKELPARAM(FD_CLOSE,
962     (pvar->PWSAGetLastError) ()));
963     }
964     }
965    
966 doda 6809 void logputs(int level, char *msg)
967 maya 3227 {
968 doda 6823 if (level <= pvar->settings.LogLevel) {
969 doda 7016 char buf[4096];
970 maya 3227 int file;
971    
972     get_teraterm_dir_relative_name(buf, NUM_ELEM(buf), "TTSSH.LOG");
973     file = _open(buf, _O_RDWR | _O_APPEND | _O_CREAT | _O_TEXT,
974     _S_IREAD | _S_IWRITE);
975    
976     if (file >= 0) {
977 doda 6778 char *strtime = mctimelocal("%Y-%m-%d %H:%M:%S.%NZ", TRUE);
978 maya 4546 DWORD processid;
979 maya 3227 char tmp[26];
980 maya 4546
981     _write(file, strtime, strlen(strtime));
982 maya 3227 GetWindowThreadProcessId(pvar->cv->HWin, &processid);
983     _snprintf_s(tmp, sizeof(tmp), _TRUNCATE, " [%lu] ",processid);
984     _write(file, tmp, strlen(tmp));
985     _write(file, msg, strlen(msg));
986     _write(file, "\n", 1);
987     _close(file);
988     }
989     }
990     }
991    
992 zmatsuo 7648 #if defined(_MSC_VER)
993     void logprintf(int level, _Printf_format_string_ const char *fmt, ...)
994     #else
995     void logprintf(int level, const char *fmt, ...)
996     #endif
997 doda 6051 {
998     char buff[4096];
999     va_list params;
1000    
1001 doda 6823 if (level <= pvar->settings.LogLevel) {
1002 doda 6051 va_start(params, fmt);
1003     vsnprintf_s(buff, sizeof(buff), _TRUNCATE, fmt, params);
1004     va_end(params);
1005    
1006 doda 6809 logputs(level, buff);
1007 doda 6051 }
1008     }
1009    
1010 yutakapon 6302 static void format_line_hexdump(char *buf, int buflen, int addr, int *bytes, int byte_cnt)
1011     {
1012     int i, c;
1013     char tmp[128];
1014    
1015     buf[0] = 0;
1016    
1017     /* �������A�h���X�\�� */
1018     _snprintf_s(tmp, sizeof(tmp), _TRUNCATE, "%08X : ", addr);
1019     strncat_s(buf, buflen, tmp, _TRUNCATE);
1020    
1021     /* �o�C�i���\���i4�o�C�g�������������}���j*/
1022     for (i = 0; i < byte_cnt; i++) {
1023     if (i > 0 && i % 4 == 0) {
1024     strncat_s(buf, buflen, " ", _TRUNCATE);
1025     }
1026    
1027     _snprintf_s(tmp, sizeof(tmp), _TRUNCATE, "%02X", bytes[i]);
1028     strncat_s(buf, buflen, tmp, _TRUNCATE);
1029     }
1030    
1031     /* ASCII�\���������������������� */
1032     _snprintf_s(tmp, sizeof(tmp), _TRUNCATE, " %*s%*s", (16 - byte_cnt) * 2 + 1, " ", (16 - byte_cnt + 3) / 4, " ");
1033     strncat_s(buf, buflen, tmp, _TRUNCATE);
1034    
1035     /* ASCII�\�� */
1036     for (i = 0; i < byte_cnt; i++) {
1037     c = bytes[i];
1038     if (isprint(c)) {
1039     _snprintf_s(tmp, sizeof(tmp), _TRUNCATE, "%c", c);
1040     strncat_s(buf, buflen, tmp, _TRUNCATE);
1041     }
1042     else {
1043     strncat_s(buf, buflen, ".", _TRUNCATE);
1044     }
1045     }
1046    
1047     //strncat_s(buf, buflen, "\n", _TRUNCATE);
1048     }
1049    
1050 zmatsuo 7648 #if defined(_MSC_VER)
1051     void logprintf_hexdump(int level, const char *data, int len, _Printf_format_string_ const char *fmt, ...)
1052     #else
1053     void logprintf_hexdump(int level, const char *data, int len, const char *fmt, ...)
1054     #endif
1055 yutakapon 6302 {
1056     char buff[4096];
1057     va_list params;
1058     int c, addr;
1059     int bytes[16], *ptr;
1060     int byte_cnt;
1061     int i;
1062    
1063 doda 6823 if (level <= pvar->settings.LogLevel) {
1064 yutakapon 6302 va_start(params, fmt);
1065     vsnprintf_s(buff, sizeof(buff), _TRUNCATE, fmt, params);
1066     va_end(params);
1067    
1068 doda 6809 logputs(level, buff);
1069 yutakapon 6302
1070     addr = 0;
1071     byte_cnt = 0;
1072     ptr = bytes;
1073     for (i = 0; i < len; i++) {
1074     c = data[i];
1075     *ptr++ = c & 0xff;
1076     byte_cnt++;
1077    
1078     if (byte_cnt == 16) {
1079     format_line_hexdump(buff, sizeof(buff), addr, bytes, byte_cnt);
1080 doda 6809 logputs(level, buff);
1081 yutakapon 6302
1082     addr += 16;
1083     byte_cnt = 0;
1084     ptr = bytes;
1085     }
1086     }
1087    
1088     if (byte_cnt > 0) {
1089     format_line_hexdump(buff, sizeof(buff), addr, bytes, byte_cnt);
1090 doda 6809 logputs(level, buff);
1091 yutakapon 6302 }
1092     }
1093     }
1094    
1095 doda 6801 static void PASCAL TTXOpenTCP(TTXSockHooks *hooks)
1096 maya 3227 {
1097     if (pvar->settings.Enabled) {
1098     // TCPLocalEcho/TCPCRSend ������������ (maya 2007.4.25)
1099 doda 3579 pvar->origDisableTCPEchoCR = pvar->ts->DisableTCPEchoCR;
1100 maya 3227 pvar->ts->DisableTCPEchoCR = TRUE;
1101    
1102     pvar->session_settings = pvar->settings;
1103    
1104 doda 6809 logputs(LOG_LEVEL_VERBOSE, "---------------------------------------------------------------------");
1105     logputs(LOG_LEVEL_VERBOSE, "Initiating SSH session");
1106 maya 3227
1107     FWDUI_load_settings(pvar);
1108    
1109     pvar->cv->TelAutoDetect = FALSE;
1110     /* This next line should not be needed because Tera Term's
1111     CommLib should find ts->Telnet == 0 ... but we'll do this
1112     just to be on the safe side. */
1113     pvar->cv->TelFlag = FALSE;
1114 doda 3495 pvar->cv->TelLineMode = FALSE;
1115 maya 3227
1116     pvar->Precv = *hooks->Precv;
1117     pvar->Psend = *hooks->Psend;
1118     pvar->PWSAAsyncSelect = *hooks->PWSAAsyncSelect;
1119     pvar->Pconnect = *hooks->Pconnect;
1120     pvar->PWSAGetLastError = *hooks->PWSAGetLastError;
1121    
1122     *hooks->Precv = TTXrecv;
1123     *hooks->Psend = TTXsend;
1124     *hooks->PWSAAsyncSelect = TTXWSAAsyncSelect;
1125     *hooks->Pconnect = TTXconnect;
1126    
1127     SSH_open(pvar);
1128     HOSTS_open(pvar);
1129     FWDUI_open(pvar);
1130    
1131     // ������ myproposal �����f���������A�������O�����������B (2006.6.26 maya)
1132     SSH2_update_cipher_myproposal(pvar);
1133 yutakapon 4367 SSH2_update_kex_myproposal(pvar);
1134     SSH2_update_host_key_myproposal(pvar);
1135     SSH2_update_hmac_myproposal(pvar);
1136 maya 3227 SSH2_update_compression_myproposal(pvar);
1137     }
1138     }
1139    
1140 doda 6801 static void PASCAL TTXCloseTCP(TTXSockHooks *hooks)
1141 maya 3227 {
1142     if (pvar->session_settings.Enabled) {
1143     pvar->socket = INVALID_SOCKET;
1144    
1145 doda 6809 logputs(LOG_LEVEL_VERBOSE, "Terminating SSH session...");
1146 maya 3227
1147     *hooks->Precv = pvar->Precv;
1148     *hooks->Psend = pvar->Psend;
1149     *hooks->PWSAAsyncSelect = pvar->PWSAAsyncSelect;
1150     *hooks->Pconnect = pvar->Pconnect;
1151 doda 3579
1152     pvar->ts->DisableTCPEchoCR = pvar->origDisableTCPEchoCR;
1153 maya 3227 }
1154    
1155     uninit_TTSSH(pvar);
1156     init_TTSSH(pvar);
1157     }
1158    
1159     static void enable_dlg_items(HWND dlg, int from, int to, BOOL enabled)
1160     {
1161     for (; from <= to; from++) {
1162     EnableWindow(GetDlgItem(dlg, from), enabled);
1163     }
1164     }
1165    
1166     // C-p/C-n/C-b/C-f/C-a/C-e ���T�|�[�g (2007.9.5 maya)
1167     // C-d/C-k ���T�|�[�g (2007.10.3 yutaka)
1168     // �h���b�v�_�E���������G�f�B�b�g�R���g���[����
1169     // �T�u�N���X�������������E�C���h�E�v���V�[�W��
1170     WNDPROC OrigHostnameEditProc; // Original window procedure
1171     LRESULT CALLBACK HostnameEditProc(HWND dlg, UINT msg,
1172 maya 5868 WPARAM wParam, LPARAM lParam)
1173 maya 3227 {
1174     HWND parent;
1175     int max, select, len;
1176     char *str, *orgstr;
1177    
1178     switch (msg) {
1179     // �L�[�����������������m����
1180     case WM_KEYDOWN:
1181     if (GetKeyState(VK_CONTROL) < 0) {
1182     switch (wParam) {
1183     case 0x50: // Ctrl+p ... up
1184     parent = GetParent(dlg);
1185     select = SendMessage(parent, CB_GETCURSEL, 0, 0);
1186     if (select > 0) {
1187     PostMessage(parent, CB_SETCURSEL, select - 1, 0);
1188     }
1189     return 0;
1190     case 0x4e: // Ctrl+n ... down
1191     parent = GetParent(dlg);
1192     max = SendMessage(parent, CB_GETCOUNT, 0, 0);
1193     select = SendMessage(parent, CB_GETCURSEL, 0, 0);
1194     if (select < max - 1) {
1195     PostMessage(parent, CB_SETCURSEL, select + 1, 0);
1196     }
1197     return 0;
1198     case 0x42: // Ctrl+b ... left
1199     SendMessage(dlg, EM_GETSEL, 0, (LPARAM)&select);
1200     PostMessage(dlg, EM_SETSEL, select-1, select-1);
1201     return 0;
1202     case 0x46: // Ctrl+f ... right
1203     SendMessage(dlg, EM_GETSEL, 0, (LPARAM)&select);
1204     max = GetWindowTextLength(dlg) ;
1205     PostMessage(dlg, EM_SETSEL, select+1, select+1);
1206     return 0;
1207     case 0x41: // Ctrl+a ... home
1208     PostMessage(dlg, EM_SETSEL, 0, 0);
1209     return 0;
1210     case 0x45: // Ctrl+e ... end
1211     max = GetWindowTextLength(dlg) ;
1212     PostMessage(dlg, EM_SETSEL, max, max);
1213     return 0;
1214    
1215     case 0x44: // Ctrl+d
1216     case 0x4b: // Ctrl+k
1217     case 0x55: // Ctrl+u
1218     SendMessage(dlg, EM_GETSEL, 0, (LPARAM)&select);
1219     max = GetWindowTextLength(dlg);
1220     max++; // '\0'
1221     orgstr = str = malloc(max);
1222     if (str != NULL) {
1223     len = GetWindowText(dlg, str, max);
1224     if (select >= 0 && select < len) {
1225     if (wParam == 0x44) { // �J�[�\���z����������������������
1226     memmove(&str[select], &str[select + 1], len - select - 1);
1227     str[len - 1] = '\0';
1228    
1229     } else if (wParam == 0x4b) { // �J�[�\�������s��������������
1230     str[select] = '\0';
1231    
1232     }
1233     }
1234    
1235     if (wParam == 0x55) { // �J�[�\����������������������
1236     if (select >= len) {
1237     str[0] = '\0';
1238     } else {
1239     str = &str[select];
1240     }
1241     select = 0;
1242     }
1243    
1244     SetWindowText(dlg, str);
1245     SendMessage(dlg, EM_SETSEL, select, select);
1246     free(orgstr);
1247     return 0;
1248     }
1249     break;
1250     }
1251     }
1252     break;
1253    
1254     // �����L�[��������������������������������������������
1255     case WM_CHAR:
1256     switch (wParam) {
1257     case 0x01:
1258     case 0x02:
1259     case 0x04:
1260     case 0x05:
1261     case 0x06:
1262     case 0x0b:
1263     case 0x0e:
1264     case 0x10:
1265     case 0x15:
1266     return 0;
1267     }
1268     }
1269    
1270     return CallWindowProc(OrigHostnameEditProc, dlg, msg, wParam, lParam);
1271     }
1272    
1273 zmatsuo 7896 static INT_PTR CALLBACK TTXHostDlg(HWND dlg, UINT msg, WPARAM wParam,
1274     LPARAM lParam)
1275 maya 3227 {
1276     static char *ssh_version[] = {"SSH1", "SSH2", NULL};
1277     PGetHNRec GetHNRec;
1278     char EntName[128];
1279     char TempHost[HostNameMaxLength + 1];
1280     WORD i, j, w;
1281     WORD ComPortTable[MAXCOMPORT];
1282     static char *ComPortDesc[MAXCOMPORT];
1283     int comports;
1284     BOOL Ok;
1285     char uimsg[MAX_UIMSG];
1286     static HWND hwndHostname = NULL; // HOSTNAME dropdown
1287     static HWND hwndHostnameEdit = NULL; // Edit control on HOSTNAME dropdown
1288    
1289     switch (msg) {
1290     case WM_INITDIALOG:
1291     GetHNRec = (PGetHNRec) lParam;
1292 zmatsuo 7896 SetWindowLongPtr(dlg, DWLP_USER, lParam);
1293 maya 3227
1294     GetWindowText(dlg, uimsg, sizeof(uimsg));
1295     UTIL_get_lang_msg("DLG_HOST_TITLE", pvar, uimsg);
1296     SetWindowText(dlg, pvar->ts->UIMsg);
1297     GetDlgItemText(dlg, IDC_HOSTNAMELABEL, uimsg, sizeof(uimsg));
1298     UTIL_get_lang_msg("DLG_HOST_TCPIPHOST", pvar, uimsg);
1299     SetDlgItemText(dlg, IDC_HOSTNAMELABEL, pvar->ts->UIMsg);
1300     GetDlgItemText(dlg, IDC_HISTORY, uimsg, sizeof(uimsg));
1301     UTIL_get_lang_msg("DLG_HOST_TCPIPHISTORY", pvar, uimsg);
1302     SetDlgItemText(dlg, IDC_HISTORY, pvar->ts->UIMsg);
1303     GetDlgItemText(dlg, IDC_SERVICELABEL, uimsg, sizeof(uimsg));
1304     UTIL_get_lang_msg("DLG_HOST_TCPIPSERVICE", pvar, uimsg);
1305     SetDlgItemText(dlg, IDC_SERVICELABEL, pvar->ts->UIMsg);
1306     GetDlgItemText(dlg, IDC_HOSTOTHER, uimsg, sizeof(uimsg));
1307     UTIL_get_lang_msg("DLG_HOST_TCPIPOTHER", pvar, uimsg);
1308     SetDlgItemText(dlg, IDC_HOSTOTHER, pvar->ts->UIMsg);
1309     GetDlgItemText(dlg, IDC_HOSTTCPPORTLABEL, uimsg, sizeof(uimsg));
1310     UTIL_get_lang_msg("DLG_HOST_TCPIPPORT", pvar, uimsg);
1311     SetDlgItemText(dlg, IDC_HOSTTCPPORTLABEL, pvar->ts->UIMsg);
1312     GetDlgItemText(dlg, IDC_SSH_VERSION_LABEL, uimsg, sizeof(uimsg));
1313     UTIL_get_lang_msg("DLG_HOST_TCPIPSSHVERSION", pvar, uimsg);
1314     SetDlgItemText(dlg, IDC_SSH_VERSION_LABEL, pvar->ts->UIMsg);
1315     GetDlgItemText(dlg, IDC_HOSTTCPPROTOCOLLABEL, uimsg, sizeof(uimsg));
1316     UTIL_get_lang_msg("DLG_HOST_TCPIPPROTOCOL", pvar, uimsg);
1317     SetDlgItemText(dlg, IDC_HOSTTCPPROTOCOLLABEL, pvar->ts->UIMsg);
1318     GetDlgItemText(dlg, IDC_HOSTSERIAL, uimsg, sizeof(uimsg));
1319     UTIL_get_lang_msg("DLG_HOST_SERIAL", pvar, uimsg);
1320     SetDlgItemText(dlg, IDC_HOSTSERIAL, pvar->ts->UIMsg);
1321     GetDlgItemText(dlg, IDC_HOSTCOMLABEL, uimsg, sizeof(uimsg));
1322     UTIL_get_lang_msg("DLG_HOST_SERIALPORT", pvar, uimsg);
1323     SetDlgItemText(dlg, IDC_HOSTCOMLABEL, pvar->ts->UIMsg);
1324     GetDlgItemText(dlg, IDC_HOSTHELP, uimsg, sizeof(uimsg));
1325     UTIL_get_lang_msg("DLG_HOST_HELP", pvar, uimsg);
1326     SetDlgItemText(dlg, IDC_HOSTHELP, pvar->ts->UIMsg);
1327     GetDlgItemText(dlg, IDOK, uimsg, sizeof(uimsg));
1328     UTIL_get_lang_msg("BTN_OK", pvar, uimsg);
1329     SetDlgItemText(dlg, IDOK, pvar->ts->UIMsg);
1330     GetDlgItemText(dlg, IDCANCEL, uimsg, sizeof(uimsg));
1331     UTIL_get_lang_msg("BTN_CANCEL", pvar, uimsg);
1332     SetDlgItemText(dlg, IDCANCEL, pvar->ts->UIMsg);
1333    
1334     // �z�X�g�q�X�g�����`�F�b�N�{�b�N�X������ (2005.10.21 yutaka)
1335     if (pvar->ts->HistoryList > 0) {
1336     SendMessage(GetDlgItem(dlg, IDC_HISTORY), BM_SETCHECK, BST_CHECKED, 0);
1337     } else {
1338     SendMessage(GetDlgItem(dlg, IDC_HISTORY), BM_SETCHECK, BST_UNCHECKED, 0);
1339     }
1340    
1341 yutakapon 4860 // �t�@�C�����������O�t���p�C�v�������ATCP/IP�����������B
1342     if (GetHNRec->PortType == IdFile ||
1343     GetHNRec->PortType == IdNamedPipe
1344     )
1345 maya 3227 GetHNRec->PortType = IdTCPIP;
1346    
1347     strncpy_s(EntName, sizeof(EntName), "Host", _TRUNCATE);
1348    
1349     i = 1;
1350     do {
1351     _snprintf_s(&EntName[4], sizeof(EntName)-4, _TRUNCATE, "%d", i);
1352     GetPrivateProfileString("Hosts", EntName, "",
1353     TempHost, sizeof(TempHost),
1354     GetHNRec->SetupFN);
1355     if (strlen(TempHost) > 0)
1356     SendDlgItemMessage(dlg, IDC_HOSTNAME, CB_ADDSTRING,
1357     0, (LPARAM) TempHost);
1358     i++;
1359 maya 4963 } while (i <= MAXHOSTLIST);
1360 maya 3227
1361     SendDlgItemMessage(dlg, IDC_HOSTNAME, EM_LIMITTEXT,
1362     HostNameMaxLength - 1, 0);
1363    
1364     SendDlgItemMessage(dlg, IDC_HOSTNAME, CB_SETCURSEL, 0, 0);
1365    
1366     // C-n/C-p ���������T�u�N���X�� (2007.9.4 maya)
1367     hwndHostname = GetDlgItem(dlg, IDC_HOSTNAME);
1368     hwndHostnameEdit = GetWindow(hwndHostname, GW_CHILD);
1369 zmatsuo 7896 OrigHostnameEditProc = (WNDPROC)GetWindowLongPtr(hwndHostnameEdit, GWLP_WNDPROC);
1370     SetWindowLongPtr(hwndHostnameEdit, GWLP_WNDPROC, (LONG_PTR)HostnameEditProc);
1371 maya 3227
1372     CheckRadioButton(dlg, IDC_HOSTTELNET, IDC_HOSTOTHER,
1373     pvar->settings.Enabled ? IDC_HOSTSSH : GetHNRec->
1374     Telnet ? IDC_HOSTTELNET : IDC_HOSTOTHER);
1375     SendDlgItemMessage(dlg, IDC_HOSTTCPPORT, EM_LIMITTEXT, 5, 0);
1376     SetDlgItemInt(dlg, IDC_HOSTTCPPORT, GetHNRec->TCPPort, FALSE);
1377     for (i = 0; ProtocolFamilyList[i]; ++i) {
1378     SendDlgItemMessage(dlg, IDC_HOSTTCPPROTOCOL, CB_ADDSTRING,
1379     0, (LPARAM) ProtocolFamilyList[i]);
1380     }
1381     SendDlgItemMessage(dlg, IDC_HOSTTCPPROTOCOL, EM_LIMITTEXT,
1382     ProtocolFamilyMaxLength - 1, 0);
1383     SendDlgItemMessage(dlg, IDC_HOSTTCPPROTOCOL, CB_SETCURSEL, 0, 0);
1384    
1385     /////// SSH version
1386     for (i = 0; ssh_version[i]; ++i) {
1387     SendDlgItemMessage(dlg, IDC_SSH_VERSION, CB_ADDSTRING,
1388     0, (LPARAM) ssh_version[i]);
1389     }
1390     SendDlgItemMessage(dlg, IDC_SSH_VERSION, EM_LIMITTEXT,
1391     NUM_ELEM(ssh_version) - 1, 0);
1392    
1393     if (pvar->settings.ssh_protocol_version == 1) {
1394     SendDlgItemMessage(dlg, IDC_SSH_VERSION, CB_SETCURSEL, 0, 0); // SSH1
1395     } else {
1396     SendDlgItemMessage(dlg, IDC_SSH_VERSION, CB_SETCURSEL, 1, 0); // SSH2
1397     }
1398    
1399     if (IsDlgButtonChecked(dlg, IDC_HOSTSSH)) {
1400     enable_dlg_items(dlg, IDC_SSH_VERSION, IDC_SSH_VERSION, TRUE); // enabled
1401     } else {
1402     enable_dlg_items(dlg, IDC_SSH_VERSION, IDC_SSH_VERSION, FALSE); // disabled
1403     }
1404     /////// SSH version
1405    
1406    
1407     j = 0;
1408     w = 1;
1409     if ((comports=DetectComPorts(ComPortTable, GetHNRec->MaxComPort, ComPortDesc)) >= 0) {
1410     for (i=0; i<comports; i++) {
1411     // MaxComPort ���z�����|�[�g���\��������
1412     if (ComPortTable[i] > GetHNRec->MaxComPort) {
1413     continue;
1414     }
1415    
1416     // �g�p�����|�[�g���\��������
1417     if (CheckCOMFlag(ComPortTable[i]) == 1) {
1418     continue;
1419     }
1420    
1421     _snprintf_s(EntName, sizeof(EntName), _TRUNCATE, "COM%d", ComPortTable[i]);
1422     if (ComPortDesc[i] != NULL) {
1423     strncat_s(EntName, sizeof(EntName), ": ", _TRUNCATE);
1424     strncat_s(EntName, sizeof(EntName), ComPortDesc[i], _TRUNCATE);
1425     }
1426     SendDlgItemMessage(dlg, IDC_HOSTCOM, CB_ADDSTRING,
1427     0, (LPARAM)EntName);
1428     j++;
1429     if (GetHNRec->ComPort == ComPortTable[i])
1430     w = j;
1431     }
1432    
1433     } else {
1434     for (i = 1; i <= GetHNRec->MaxComPort; i++) {
1435     // �g�p�����|�[�g���\��������
1436     if (CheckCOMFlag(i) == 1) {
1437     continue;
1438     }
1439    
1440     _snprintf_s(EntName, sizeof(EntName), _TRUNCATE, "COM%d", i);
1441     SendDlgItemMessage(dlg, IDC_HOSTCOM, CB_ADDSTRING,
1442     0, (LPARAM) EntName);
1443     j++;
1444     if (GetHNRec->ComPort == i)
1445     w = j;
1446     }
1447     }
1448    
1449     if (j > 0)
1450     SendDlgItemMessage(dlg, IDC_HOSTCOM, CB_SETCURSEL, w - 1, 0);
1451     else { /* All com ports are already used */
1452     GetHNRec->PortType = IdTCPIP;
1453     enable_dlg_items(dlg, IDC_HOSTSERIAL, IDC_HOSTSERIAL, FALSE);
1454     }
1455    
1456     CheckRadioButton(dlg, IDC_HOSTTCPIP, IDC_HOSTSERIAL,
1457     IDC_HOSTTCPIP + GetHNRec->PortType - 1);
1458    
1459     if (GetHNRec->PortType == IdTCPIP) {
1460     enable_dlg_items(dlg, IDC_HOSTCOMLABEL, IDC_HOSTCOM, FALSE);
1461    
1462     enable_dlg_items(dlg, IDC_SSH_VERSION, IDC_SSH_VERSION, TRUE);
1463     enable_dlg_items(dlg, IDC_SSH_VERSION_LABEL, IDC_SSH_VERSION_LABEL, TRUE);
1464    
1465     enable_dlg_items(dlg, IDC_HISTORY, IDC_HISTORY, TRUE); // enabled
1466     }
1467     else {
1468     enable_dlg_items(dlg, IDC_HOSTNAMELABEL, IDC_HOSTTCPPORT,
1469     FALSE);
1470     enable_dlg_items(dlg, IDC_HOSTTCPPROTOCOLLABEL,
1471     IDC_HOSTTCPPROTOCOL, FALSE);
1472    
1473     enable_dlg_items(dlg, IDC_SSH_VERSION, IDC_SSH_VERSION, FALSE); // disabled
1474     enable_dlg_items(dlg, IDC_SSH_VERSION_LABEL, IDC_SSH_VERSION_LABEL, FALSE); // disabled (2004.11.23 yutaka)
1475    
1476     enable_dlg_items(dlg, IDC_HISTORY, IDC_HISTORY, FALSE); // disabled
1477     }
1478    
1479     // Host dialog���t�H�[�J�X�������� (2004.10.2 yutaka)
1480     if (GetHNRec->PortType == IdTCPIP) {
1481     HWND hwnd = GetDlgItem(dlg, IDC_HOSTNAME);
1482     SetFocus(hwnd);
1483     } else {
1484     HWND hwnd = GetDlgItem(dlg, IDC_HOSTCOM);
1485     SetFocus(hwnd);
1486     }
1487    
1488 zmatsuo 7592 CenterWindow(dlg, GetParent(dlg));
1489    
1490 maya 3227 // SetFocus()���t�H�[�J�X���������������AFALSE�������K�v�������B
1491     // TRUE���������ATABSTOP�������������������R���g���[�����I�������B
1492     // (2004.11.23 yutaka)
1493     return FALSE;
1494     //return TRUE;
1495    
1496     case WM_COMMAND:
1497     switch (LOWORD(wParam)) {
1498     case IDOK:
1499 zmatsuo 7896 GetHNRec = (PGetHNRec) GetWindowLongPtr(dlg, DWLP_USER);
1500 maya 3227 if (GetHNRec != NULL) {
1501     if (IsDlgButtonChecked(dlg, IDC_HOSTTCPIP)) {
1502     char afstr[BUFSIZ];
1503     i = GetDlgItemInt(dlg, IDC_HOSTTCPPORT, &Ok, FALSE);
1504     if (Ok) {
1505     GetHNRec->TCPPort = i;
1506     } else {
1507     UTIL_get_lang_msg("MSG_TCPPORT_NAN_ERROR", pvar,
1508     "The TCP port must be a number.");
1509     MessageBox(dlg, pvar->ts->UIMsg,
1510     "Tera Term", MB_OK | MB_ICONEXCLAMATION);
1511     return TRUE;
1512     }
1513     #define getaf(str) \
1514     ((strcmp((str), "IPv6") == 0) ? AF_INET6 : \
1515     ((strcmp((str), "IPv4") == 0) ? AF_INET : AF_UNSPEC))
1516     memset(afstr, 0, sizeof(afstr));
1517     GetDlgItemText(dlg, IDC_HOSTTCPPROTOCOL, afstr,
1518     sizeof(afstr));
1519     GetHNRec->ProtocolFamily = getaf(afstr);
1520     GetHNRec->PortType = IdTCPIP;
1521     GetDlgItemText(dlg, IDC_HOSTNAME, GetHNRec->HostName,
1522     HostNameMaxLength);
1523     pvar->hostdlg_activated = TRUE;
1524     pvar->hostdlg_Enabled = FALSE;
1525     if (IsDlgButtonChecked(dlg, IDC_HOSTTELNET)) {
1526     GetHNRec->Telnet = TRUE;
1527     } else if (IsDlgButtonChecked(dlg, IDC_HOSTSSH)) {
1528     pvar->hostdlg_Enabled = TRUE;
1529    
1530     // check SSH protocol version
1531     memset(afstr, 0, sizeof(afstr));
1532     GetDlgItemText(dlg, IDC_SSH_VERSION, afstr, sizeof(afstr));
1533     if (_stricmp(afstr, "SSH1") == 0) {
1534     pvar->settings.ssh_protocol_version = 1;
1535     } else {
1536     pvar->settings.ssh_protocol_version = 2;
1537     }
1538     }
1539 doda 3541 else { // IDC_HOSTOTHER
1540     GetHNRec->Telnet = FALSE;
1541     }
1542 maya 3227
1543     // host history check button
1544     if (SendMessage(GetDlgItem(dlg, IDC_HISTORY), BM_GETCHECK, 0, 0) == BST_CHECKED) {
1545     pvar->ts->HistoryList = 1;
1546     } else {
1547     pvar->ts->HistoryList = 0;
1548     }
1549    
1550     } else {
1551     GetHNRec->PortType = IdSerial;
1552     GetHNRec->HostName[0] = 0;
1553     memset(EntName, 0, sizeof(EntName));
1554     GetDlgItemText(dlg, IDC_HOSTCOM, EntName,
1555     sizeof(EntName) - 1);
1556     if (strncmp(EntName, "COM", 3) == 0 && EntName[3] != '\0') {
1557     GetHNRec->ComPort = atoi(&EntName[3]);
1558     if (GetHNRec->ComPort > GetHNRec->MaxComPort)
1559     GetHNRec->ComPort = 1;
1560     } else {
1561     GetHNRec->ComPort = 1;
1562     }
1563     }
1564     }
1565 zmatsuo 7896 SetWindowLongPtr(hwndHostnameEdit, GWLP_WNDPROC, (LONG_PTR)OrigHostnameEditProc);
1566 maya 3227 EndDialog(dlg, 1);
1567     return TRUE;
1568    
1569     case IDCANCEL:
1570 zmatsuo 7896 SetWindowLongPtr(hwndHostnameEdit, GWLP_WNDPROC, (LONG_PTR)OrigHostnameEditProc);
1571 maya 3227 EndDialog(dlg, 0);
1572     return TRUE;
1573    
1574     case IDC_HOSTTCPIP:
1575     enable_dlg_items(dlg, IDC_HOSTNAMELABEL, IDC_HOSTTCPPORT,
1576     TRUE);
1577     enable_dlg_items(dlg, IDC_HOSTTCPPROTOCOLLABEL,
1578     IDC_HOSTTCPPROTOCOL, TRUE);
1579     enable_dlg_items(dlg, IDC_HOSTCOMLABEL, IDC_HOSTCOM, FALSE);
1580    
1581     enable_dlg_items(dlg, IDC_SSH_VERSION_LABEL, IDC_SSH_VERSION_LABEL, TRUE); // disabled (2004.11.23 yutaka)
1582     if (IsDlgButtonChecked(dlg, IDC_HOSTSSH)) {
1583     enable_dlg_items(dlg, IDC_SSH_VERSION, IDC_SSH_VERSION, TRUE);
1584     } else {
1585     enable_dlg_items(dlg, IDC_SSH_VERSION, IDC_SSH_VERSION, FALSE); // disabled
1586     }
1587    
1588     enable_dlg_items(dlg, IDC_HISTORY, IDC_HISTORY, TRUE); // disabled
1589    
1590     return TRUE;
1591    
1592     case IDC_HOSTSERIAL:
1593     enable_dlg_items(dlg, IDC_HOSTCOMLABEL, IDC_HOSTCOM, TRUE);
1594     enable_dlg_items(dlg, IDC_HOSTNAMELABEL, IDC_HOSTTCPPORT,
1595     FALSE);
1596     enable_dlg_items(dlg, IDC_HOSTTCPPROTOCOLLABEL,
1597     IDC_HOSTTCPPROTOCOL, FALSE);
1598     enable_dlg_items(dlg, IDC_SSH_VERSION, IDC_SSH_VERSION, FALSE); // disabled
1599     enable_dlg_items(dlg, IDC_SSH_VERSION_LABEL, IDC_SSH_VERSION_LABEL, FALSE); // disabled (2004.11.23 yutaka)
1600    
1601     enable_dlg_items(dlg, IDC_HISTORY, IDC_HISTORY, FALSE); // disabled
1602    
1603     return TRUE;
1604    
1605     case IDC_HOSTSSH:
1606     enable_dlg_items(dlg, IDC_SSH_VERSION,
1607     IDC_SSH_VERSION, TRUE);
1608     goto hostssh_enabled;
1609    
1610     case IDC_HOSTTELNET:
1611     case IDC_HOSTOTHER:
1612     enable_dlg_items(dlg, IDC_SSH_VERSION, IDC_SSH_VERSION, FALSE); // disabled
1613     hostssh_enabled:
1614    
1615 zmatsuo 7896 GetHNRec = (PGetHNRec) GetWindowLongPtr(dlg, DWLP_USER);
1616 maya 3227
1617     if (IsDlgButtonChecked(dlg, IDC_HOSTTELNET)) {
1618     if (GetHNRec != NULL)
1619     SetDlgItemInt(dlg, IDC_HOSTTCPPORT, GetHNRec->TelPort,
1620     FALSE);
1621     } else if (IsDlgButtonChecked(dlg, IDC_HOSTSSH)) {
1622     SetDlgItemInt(dlg, IDC_HOSTTCPPORT, 22, FALSE);
1623     }
1624     return TRUE;
1625    
1626     case IDC_HOSTCOM:
1627     if(HIWORD(wParam) == CBN_DROPDOWN) {
1628     HWND hostcom = GetDlgItem(dlg, IDC_HOSTCOM);
1629     int count = SendMessage(hostcom, CB_GETCOUNT, 0, 0);
1630     int i, len, max_len = 0;
1631     char *lbl;
1632     HDC TmpDC = GetDC(hostcom);
1633     SIZE s;
1634     for (i=0; i<count; i++) {
1635     len = SendMessage(hostcom, CB_GETLBTEXTLEN, i, 0);
1636     lbl = (char *)calloc(len+1, sizeof(char));
1637     SendMessage(hostcom, CB_GETLBTEXT, i, (LPARAM)lbl);
1638     GetTextExtentPoint32(TmpDC, lbl, len, &s);
1639     if (s.cx > max_len)
1640     max_len = s.cx;
1641     free(lbl);
1642     }
1643     SendMessage(hostcom, CB_SETDROPPEDWIDTH,
1644     max_len + GetSystemMetrics(SM_CXVSCROLL), 0);
1645     }
1646     break;
1647    
1648     case IDC_HOSTHELP:
1649     PostMessage(GetParent(dlg), WM_USER_DLGHELP2, 0, 0);
1650     }
1651     }
1652     return FALSE;
1653     }
1654    
1655 zmatsuo 7560 static void UTIL_SetDialogFont()
1656     {
1657 zmatsuo 7706 SetDialogFont(pvar->ts->DialogFontName, pvar->ts->DialogFontPoint, pvar->ts->DialogFontCharSet,
1658     pvar->ts->UILanguageFile, "TTSSH", "DLG_TAHOMA_FONT");
1659 zmatsuo 7560 }
1660    
1661 doda 6801 static BOOL PASCAL TTXGetHostName(HWND parent, PGetHNRec rec)
1662 maya 3227 {
1663 zmatsuo 7706 SetDialogFont(pvar->ts->DialogFontName, pvar->ts->DialogFontPoint, pvar->ts->DialogFontCharSet,
1664 zmatsuo 7589 pvar->ts->UILanguageFile, "TTSSH", "DLG_SYSTEM_FONT");
1665 maya 3227 return (BOOL) DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_HOSTDLG),
1666 zmatsuo 7560 parent, TTXHostDlg, (LPARAM)rec);
1667 maya 3227 }
1668    
1669 doda 6801 static void PASCAL TTXGetUIHooks(TTXUIHooks *hooks)
1670 maya 3227 {
1671     *hooks->GetHostName = TTXGetHostName;
1672     }
1673    
1674 doda 6801 static void PASCAL TTXReadINIFile(PCHAR fileName, PTTSet ts)
1675 maya 3227 {
1676     (pvar->ReadIniFile) (fileName, ts);
1677     read_ssh_options(pvar, fileName);
1678     pvar->settings = *pvar->ts_SSH;
1679 doda 6809 logputs(LOG_LEVEL_VERBOSE, "Reading INI file");
1680 maya 3227 FWDUI_load_settings(pvar);
1681     }
1682    
1683 doda 6801 static void PASCAL TTXWriteINIFile(PCHAR fileName, PTTSet ts)
1684 maya 3227 {
1685     (pvar->WriteIniFile) (fileName, ts);
1686     *pvar->ts_SSH = pvar->settings;
1687     clear_local_settings(pvar);
1688 doda 6809 logputs(LOG_LEVEL_VERBOSE, "Writing INI file");
1689 maya 3227 write_ssh_options(pvar, fileName, pvar->ts_SSH, TRUE);
1690     }
1691    
1692     static void read_ssh_options_from_user_file(PTInstVar pvar,
1693 doda 6801 char *user_file_name)
1694 maya 3227 {
1695     if (user_file_name[0] == '.') {
1696     read_ssh_options(pvar, user_file_name);
1697     } else {
1698     char buf[1024];
1699    
1700     get_teraterm_dir_relative_name(buf, sizeof(buf), user_file_name);
1701     read_ssh_options(pvar, buf);
1702     }
1703    
1704     pvar->settings = *pvar->ts_SSH;
1705     FWDUI_load_settings(pvar);
1706     }
1707    
1708     // Percent-encode������������src���f�R�[�h����dst���R�s�[�����B
1709     // dstlen��dst���T�C�Y�B�����������������������A�����������������������B
1710     static void percent_decode(char *dst, int dstlen, char *src) {
1711     if (src == NULL || dst == NULL || dstlen < 1) {
1712     return;
1713     }
1714    
1715     while (*src != 0 && dstlen > 1) {
1716     if (*src == '%' && isxdigit(*(src+1)) && isxdigit(*(src+2))) {
1717     src++; *dst = (isalpha(*src) ? (*src|0x20) - 'a' + 10 : *src - '0') << 4;
1718     src++; *dst |= (isalpha(*src) ? (*src|0x20) - 'a' + 10 : *src - '0');
1719     src++; dst++;
1720     }
1721     else {
1722     *dst++ = *src++;
1723     }
1724     dstlen--;
1725     }
1726     *dst = 0;
1727     return;
1728     }
1729    
1730 doda 5799 void add_forward_param(PTInstVar pvar, char *param)
1731     {
1732     if (pvar->settings.DefaultForwarding[0] == 0) {
1733     strncpy_s(pvar->settings.DefaultForwarding,
1734     sizeof(pvar->settings.DefaultForwarding),
1735     param, _TRUNCATE);
1736     } else {
1737     strncat_s(pvar->settings.DefaultForwarding,
1738     sizeof(pvar->settings.DefaultForwarding),
1739     ";", _TRUNCATE);
1740     strncat_s(pvar->settings.DefaultForwarding,
1741     sizeof(pvar->settings.DefaultForwarding),
1742     param, _TRUNCATE);
1743     }
1744     }
1745    
1746 doda 6801 static void PASCAL TTXParseParam(PCHAR param, PTTSet ts, PCHAR DDETopic) {
1747 maya 5869 int param_len=strlen(param);
1748     int opt_len = param_len+1;
1749     char *option = (char *)calloc(opt_len, sizeof(char));
1750 maya 5882 char *option2 = (char *)calloc(opt_len, sizeof(char));
1751 maya 5869 int action;
1752 maya 5874 PCHAR start, cur, next;
1753 maya 5908 size_t i;
1754 maya 5869
1755     if (pvar->hostdlg_activated) {
1756     pvar->settings.Enabled = pvar->hostdlg_Enabled;
1757     }
1758    
1759 maya 5874 /* the first term shuld be executable filename of Tera Term */
1760     start = GetParam(option, opt_len, param);
1761    
1762     cur = start;
1763 maya 5869 while (next = GetParam(option, opt_len, cur)) {
1764 doda 6140 DequoteParam(option, opt_len, option);
1765 maya 5869 action = OPTION_NONE;
1766    
1767     if ((option[0] == '-' || option[0] == '/')) {
1768     if (MATCH_STR(option + 1, "ssh") == 0) {
1769     if (MATCH_STR(option + 4, "-f=") == 0) {
1770 doda 6140 strncpy_s(option2, opt_len, option + 7, _TRUNCATE);
1771 maya 5882 read_ssh_options_from_user_file(pvar, option2);
1772 maya 5869 action = OPTION_CLEAR;
1773     } else if (MATCH_STR(option + 4, "-consume=") == 0) {
1774 doda 6140 strncpy_s(option2, opt_len, option + 13, _TRUNCATE);
1775 maya 5882 read_ssh_options_from_user_file(pvar, option2);
1776     DeleteFile(option2);
1777 maya 5869 action = OPTION_CLEAR;
1778     }
1779    
1780     // ttermpro.exe �� /F= �w������ TTSSH ������������ (2006.10.11 maya)
1781     } else if (MATCH_STR_I(option + 1, "f=") == 0) {
1782 doda 6140 strncpy_s(option2, opt_len, option + 3, _TRUNCATE);
1783 maya 5882 read_ssh_options_from_user_file(pvar, option2);
1784 maya 5869 // Tera Term���������������K�v������������������
1785     }
1786     }
1787    
1788     switch (action) {
1789     case OPTION_CLEAR:
1790     memset(cur, ' ', next-cur);
1791     break;
1792     case OPTION_REPLACE:
1793     memset(cur, ' ', next-cur);
1794     memcpy(cur+1, option, strlen(option));
1795     break;
1796     }
1797    
1798     cur = next;
1799     }
1800    
1801 maya 5874 cur = start;
1802 maya 5869 while (next = GetParam(option, opt_len, cur)) {
1803 doda 6140 DequoteParam(option, opt_len, option);
1804 maya 5869 action = OPTION_NONE;
1805    
1806     if ((option[0] == '-' || option[0] == '/')) {
1807     action = OPTION_CLEAR;
1808     if (MATCH_STR(option + 1, "ssh") == 0) {
1809     if (option[4] == 0) {
1810     pvar->settings.Enabled = 1;
1811     } else if (MATCH_STR(option + 4, "-L") == 0 ||
1812 doda 6846 MATCH_STR(option + 4, "-R") == 0 ||
1813     MATCH_STR(option + 4, "-D") == 0) {
1814 doda 5959 char *p = option + 5;
1815     option2[0] = *p;
1816     i = 1;
1817     while (*++p) {
1818     if (*p == ';' || *p == ',') {
1819     option2[i] = 0;
1820     add_forward_param(pvar, option2);
1821     i = 1;
1822 maya 5908 }
1823 doda 5959 else {
1824     option2[i++] = *p;
1825     }
1826 maya 5908 }
1827 doda 5959 if (i > 1) {
1828     option2[i] = 0;
1829     add_forward_param(pvar, option2);
1830     }
1831 maya 5869 } else if (MATCH_STR(option + 4, "-X") == 0) {
1832     add_forward_param(pvar, "X");
1833 doda 5959 if (option+6 != 0) {
1834     strncpy_s(pvar->settings.X11Display,
1835     sizeof(pvar->settings.X11Display),
1836     option + 6, _TRUNCATE);
1837     }
1838 doda 6473 } else if (strcmp(option + 4, "-v") == 0) {
1839 maya 5869 pvar->settings.LogLevel = LOG_LEVEL_VERBOSE;
1840     } else if (_stricmp(option + 4, "-autologin") == 0 ||
1841     _stricmp(option + 4, "-autologon") == 0) {
1842     pvar->settings.TryDefaultAuth = TRUE;
1843     } else if (MATCH_STR_I(option + 4, "-agentconfirm=") == 0) {
1844     if ((_stricmp(option+18, "off") == 0) ||
1845     (_stricmp(option+18, "no") == 0) ||
1846     (_stricmp(option+18, "false") == 0) ||
1847     (_stricmp(option+18, "0") == 0) ||
1848     (_stricmp(option+18, "n") == 0)) {
1849     pvar->settings.ForwardAgentConfirm = 0;
1850     }
1851     else {
1852     pvar->settings.ForwardAgentConfirm = 1;
1853     }
1854 doda 6473 } else if (strcmp(option + 4, "-a") == 0) {
1855 maya 5869 pvar->settings.ForwardAgent = FALSE;
1856 doda 6473 } else if (strcmp(option + 4, "-A") == 0) {
1857 maya 5869 pvar->settings.ForwardAgent = TRUE;
1858    
1859     } else if (MATCH_STR(option + 4, "-C=") == 0) {
1860     pvar->settings.CompressionLevel = atoi(option+7);
1861     if (pvar->settings.CompressionLevel < 0) {
1862     pvar->settings.CompressionLevel = 0;
1863     }
1864     else if (pvar->settings.CompressionLevel > 9) {
1865     pvar->settings.CompressionLevel = 9;
1866     }
1867 doda 6473 } else if (strcmp(option + 4, "-C") == 0) {
1868 maya 5869 pvar->settings.CompressionLevel = 6;
1869 doda 6473 } else if (strcmp(option + 4, "-c") == 0) {
1870 maya 5869 pvar->settings.CompressionLevel = 0;
1871     } else if (MATCH_STR_I(option + 4, "-icon=") == 0) {
1872     if ((_stricmp(option+10, "old") == 0) ||
1873     (_stricmp(option+10, "yellow") == 0) ||
1874     (_stricmp(option+10, "securett_yellow") == 0)) {
1875     pvar->settings.IconID = IDI_SECURETT_YELLOW;
1876     }
1877 maya 6386 else if ((_stricmp(option+10, "green") == 0) ||
1878     (_stricmp(option+10, "securett_green") == 0)) {
1879     pvar->settings.IconID = IDI_SECURETT_GREEN;
1880     }
1881 maya 5869 else {
1882     pvar->settings.IconID = IDI_SECURETT;
1883     }
1884 doda 6717 } else if (MATCH_STR(option + 4, "-subsystem=") == 0) {
1885     pvar->use_subsystem = TRUE;
1886     strncpy_s(pvar->subsystem_name,
1887     sizeof(pvar->subsystem_name),
1888     option + 15, _TRUNCATE);
1889 doda 7364 } else if (strcmp(option + 4, "-N") == 0) {
1890 doda 7363 pvar->nosession = TRUE;
1891 maya 5869
1892     // /ssh1 �� /ssh2 �I�v�V�������V�K���� (2006.9.16 maya)
1893 doda 6473 } else if (strcmp(option + 4, "1") == 0) {
1894 maya 5869 pvar->settings.Enabled = 1;
1895     pvar->settings.ssh_protocol_version = 1;
1896 doda 6473 } else if (strcmp(option + 4, "2") == 0) {
1897 maya 5869 pvar->settings.Enabled = 1;
1898     pvar->settings.ssh_protocol_version = 2;
1899    
1900     } else {
1901     char buf[1024];
1902    
1903     UTIL_get_lang_msg("MSG_UNKNOWN_OPTION_ERROR", pvar,
1904     "Unrecognized command-line option: %s");
1905     _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg, option);
1906    
1907     MessageBox(NULL, buf, "TTSSH", MB_OK | MB_ICONEXCLAMATION);
1908     }
1909    
1910     // ttermpro.exe �� /T= �w�������p�������A������������ (2006.10.19 maya)
1911     } else if (MATCH_STR_I(option + 1, "t=") == 0) {
1912     if (strcmp(option + 3, "2") == 0) {
1913     pvar->settings.Enabled = 1;
1914     // /t=2��ttssh�������g������������
1915     } else {
1916     pvar->settings.Enabled = 0;
1917     action = OPTION_NONE; // Tera Term������������������������
1918     }
1919    
1920     // /1 ������ /2 �I�v�V�������V�K���� (2004.10.3 yutaka)
1921 doda 6473 } else if (strcmp(option + 1, "1") == 0) {
1922 maya 5869 // command line: /ssh /1 is SSH1 only
1923     pvar->settings.ssh_protocol_version = 1;
1924    
1925 doda 6473 } else if (strcmp(option + 1, "2") == 0) {
1926 maya 5869 // command line: /ssh /2 is SSH2 & SSH1
1927     pvar->settings.ssh_protocol_version = 2;
1928    
1929 doda 6473 } else if (strcmp(option + 1, "nossh") == 0) {
1930 maya 5869 // '/nossh' �I�v�V�����������B
1931     // TERATERM.INI ��SSH���L�������������������A������Cygterm���N��������������
1932     // �����������������B(2004.10.11 yutaka)
1933     pvar->settings.Enabled = 0;
1934    
1935 doda 6473 } else if (strcmp(option + 1, "telnet") == 0) {
1936 maya 5869 // '/telnet' ���w�������������������� '/nossh' ��������
1937     // SSH������������ (2006.9.16 maya)
1938     pvar->settings.Enabled = 0;
1939     // Tera Term �� Telnet �t���O���t����
1940     pvar->ts->Telnet = 1;
1941    
1942 doda 6473 } else if (MATCH_STR(option + 1, "auth=") == 0) {
1943 maya 5869 // SSH2�������O�C���I�v�V����������
1944     //
1945     // SYNOPSIS: /ssh /auth=passowrd /user=���[�U�� /passwd=�p�X���[�h
1946     // /ssh /auth=publickey /user=���[�U�� /passwd=�p�X���[�h /keyfile=�p�X
1947 doda 6472 // EXAMPLE: /ssh /auth=password /user=nike /passwd="a b""c" ; �p�X���[�h: �ua b"c�v
1948 maya 5869 // /ssh /auth=publickey /user=foo /passwd=bar /keyfile=d:\tmp\id_rsa
1949 doda 6472 // NOTICE: �p�X���[�h���p�X���������Z�~�R���������������������_�u���N�H�[�g " ������
1950     // �p�X���[�h���_�u���N�H�[�g�����������������A�������_�u���N�H�[�g "" ���u��������
1951 maya 5869 //
1952     pvar->ssh2_autologin = 1; // for SSH2 (2004.11.30 yutaka)
1953    
1954 doda 6473 if (_stricmp(option + 6, "password") == 0) { // �p�X���[�h
1955 maya 5869 //pvar->auth_state.cur_cred.method = SSH_AUTH_PASSWORD;
1956     pvar->ssh2_authmethod = SSH_AUTH_PASSWORD;
1957    
1958 doda 7101 } else if (_stricmp(option + 6, "keyboard-interactive") == 0) { // keyboard-interactive�F��
1959     //pvar->auth_state.cur_cred.method = SSH_AUTH_TIS;
1960     pvar->ssh2_authmethod = SSH_AUTH_TIS;
1961    
1962 doda 6473 } else if (_stricmp(option + 6, "challenge") == 0) { // keyboard-interactive�F��
1963 maya 5869 //pvar->auth_state.cur_cred.method = SSH_AUTH_TIS;
1964     pvar->ssh2_authmethod = SSH_AUTH_TIS;
1965    
1966 doda 6473 } else if (_stricmp(option + 6, "publickey") == 0) { // ���J���F��
1967 maya 5869 //pvar->auth_state.cur_cred.method = SSH_AUTH_RSA;
1968     pvar->ssh2_authmethod = SSH_AUTH_RSA;
1969    
1970 doda 6473 } else if (_stricmp(option + 6, "pageant") == 0) { // ���J���F�� by Pageant
1971 maya 5869 //pvar->auth_state.cur_cred.method = SSH_AUTH_RSA;
1972     pvar->ssh2_authmethod = SSH_AUTH_PAGEANT;
1973    
1974     } else {
1975     // TODO:
1976     }
1977    
1978     } else if (MATCH_STR(option + 1, "user=") == 0) {
1979 doda 6140 _snprintf_s(pvar->ssh2_username, sizeof(pvar->ssh2_username), _TRUNCATE, "%s", option+6);
1980 maya 5869
1981     } else if (MATCH_STR(option + 1, "passwd=") == 0) {
1982 doda 6140 _snprintf_s(pvar->ssh2_password, sizeof(pvar->ssh2_password), _TRUNCATE, "%s", option+8);
1983 maya 5869
1984     } else if (MATCH_STR(option + 1, "keyfile=") == 0) {
1985 doda 6140 _snprintf_s(pvar->ssh2_keyfile, sizeof(pvar->ssh2_keyfile), _TRUNCATE, "%s", option+9);
1986 maya 5869
1987 doda 6473 } else if (strcmp(option + 1, "ask4passwd") == 0) {
1988 maya 5869 // �p�X���[�h������ (2006.9.18 maya)
1989     pvar->ask4passwd = 1;
1990    
1991 doda 6473 } else if (strcmp(option + 1, "nosecuritywarning") == 0) {
1992 maya 5869 // known_hosts�`�F�b�N���������B���Y�I�v�V�������g�����A�Z�L�����e�B������������
1993     // �����A�B���I�v�V���������������B
1994     // (2009.10.4 yutaka)
1995     pvar->nocheck_known_hosts = TRUE;
1996    
1997     }
1998     else { // Other (not ttssh) option
1999     action = OPTION_NONE; // ttssh���I�v�V������������������������
2000     }
2001    
2002     // �p�X���[�h�������������������O�C��������������
2003     // /auth ���F�����\�b�h���w�������������p������ (2006.9.18 maya)
2004     if (pvar->ask4passwd == 1) {
2005     pvar->ssh2_autologin = 0;
2006     }
2007    
2008     }
2009     else if ((MATCH_STR_I(option, "ssh://") == 0) ||
2010     (MATCH_STR_I(option, "ssh1://") == 0) ||
2011     (MATCH_STR_I(option, "ssh2://") == 0) ||
2012     (MATCH_STR_I(option, "slogin://") == 0) ||
2013     (MATCH_STR_I(option, "slogin1://") == 0) ||
2014     (MATCH_STR_I(option, "slogin2://") == 0)) {
2015     //
2016     // ssh://user@host/ ����URL�`�����T�|�[�g
2017     // ���{�I�������� telnet:// URL��������
2018     //
2019     // �Q�l:
2020     // RFC3986: Uniform Resource Identifier (URI): Generic Syntax
2021     // RFC4248: The telnet URI Scheme
2022     //
2023     char *p, *p2, *p3;
2024     int optlen, hostlen;
2025    
2026     optlen = strlen(option);
2027    
2028     // ������':'���O�����������������������A������ssh�v���g�R���o�[�W������������
2029     p = _mbschr(option, ':');
2030     switch (*(p-1)) {
2031     case '1':
2032     pvar->settings.ssh_protocol_version = 1;
2033     break;
2034     case '2':
2035     pvar->settings.ssh_protocol_version = 2;
2036     break;
2037     }
2038    
2039     // authority part �����|�C���^������
2040     p += 3;
2041    
2042     // path part ������������
2043     if ((p2 = _mbschr(p, '/')) != NULL) {
2044     *p2 = 0;
2045     }
2046    
2047     // '@'�������������A���������O�����[�U����
2048     if ((p2 = _mbschr(p, '@')) != NULL) {
2049     *p2 = 0;
2050     // ':'���~���p�X���[�h
2051     if ((p3 = _mbschr(p, ':')) != NULL) {
2052     *p3 = 0;
2053     percent_decode(pvar->ssh2_password, sizeof(pvar->ssh2_password), p3 + 1);
2054     }
2055     percent_decode(pvar->ssh2_username, sizeof(pvar->ssh2_username), p);
2056     // p �� host part ������('@'����������)����������������
2057     p = p2 + 1;
2058     }
2059    
2060     // host part �� option �����������������Ascheme part ������
2061     // port�w����������������port���������������������m��������������
2062     hostlen = strlen(p);
2063     memmove_s(option, optlen, p, hostlen);
2064     option[hostlen] = 0;
2065    
2066     // �|�[�g�w������������":22"������
2067     if (option[0] == '[' && option[hostlen-1] == ']' || // IPv6 raw address without port
2068     option[0] != '[' && _mbschr(option, ':') == NULL) { // hostname or IPv4 raw address without port
2069     memcpy_s(option+hostlen, optlen-hostlen, ":22", 3);
2070     hostlen += 3;
2071     }
2072    
2073     // �|�[�g�w�����������������X�y�[�X������
2074     memset(option+hostlen, ' ', optlen-hostlen);
2075    
2076     pvar->settings.Enabled = 1;
2077    
2078     action = OPTION_REPLACE;
2079     }
2080     else if (_mbschr(option, '@') != NULL) {
2081     //
2082     // user@host �`�����T�|�[�g
2083     // ����������ssh�������T�|�[�g�����A���[�U����ttssh���������B
2084     // (ssh�������O -- ttssh�������W������������)
2085     // �����I��telnet authentication option���T�|�[�g��������
2086     // Tera Term�{�����������������������\���B
2087     //
2088     char *p;
2089     p = _mbschr(option, '@');
2090     *p = 0;
2091    
2092     strncpy_s(pvar->ssh2_username, sizeof(pvar->ssh2_username), option, _TRUNCATE);
2093    
2094     // ���[�U���������X�y�[�X�������B
2095     // ������TTX��Tera Term�{�������������������X�y�[�X�����������������A
2096     // �z�X�g�����������l�����K�v�������B
2097     memset(option, ' ', p-option+1);
2098    
2099     action = OPTION_REPLACE;
2100     }
2101    
2102    
2103     switch (action) {
2104     case OPTION_CLEAR:
2105     memset(cur, ' ', next-cur);
2106     break;
2107     case OPTION_REPLACE:
2108     memset(cur, ' ', next-cur);
2109     memcpy(cur+1, option, strlen(option));
2110     break;
2111     }
2112    
2113     cur = next;
2114     }
2115    
2116     free(option);
2117    
2118     FWDUI_load_settings(pvar);
2119    
2120     (pvar->ParseParam) (param, ts, DDETopic);
2121     }
2122 maya 3227
2123 doda 6801 static void PASCAL TTXGetSetupHooks(TTXSetupHooks *hooks)
2124 maya 3227 {
2125     pvar->ReadIniFile = *hooks->ReadIniFile;
2126     pvar->WriteIniFile = *hooks->WriteIniFile;
2127     pvar->ParseParam = *hooks->ParseParam;
2128    
2129     *hooks->ReadIniFile = TTXReadINIFile;
2130     *hooks->WriteIniFile = TTXWriteINIFile;
2131     *hooks->ParseParam = TTXParseParam;
2132     }
2133    
2134 doda 6801 static void PASCAL TTXSetWinSize(int rows, int cols)
2135 maya 3227 {
2136     SSH_notify_win_size(pvar, cols, rows);
2137     }
2138    
2139     static void insertMenuBeforeItem(HMENU menu, WORD beforeItemID, WORD flags,
2140 doda 6801 WORD newItemID, char *text)
2141 maya 3227 {
2142     int i, j;
2143    
2144     for (i = GetMenuItemCount(menu) - 1; i >= 0; i--) {
2145     HMENU submenu = GetSubMenu(menu, i);
2146    
2147     for (j = GetMenuItemCount(submenu) - 1; j >= 0; j--) {
2148     if (GetMenuItemID(submenu, j) == beforeItemID) {
2149     InsertMenu(submenu, j, MF_BYPOSITION | flags, newItemID, text);
2150     return;
2151     }
2152     }
2153     }
2154     }
2155    
2156 doda 4463 #define GetFileMenu(menu) GetSubMenuByChildID(menu, 50110) // ID_FILE_NEWCONNECTION
2157     #define GetEditMenu(menu) GetSubMenuByChildID(menu, 50210) // ID_EDIT_COPY2
2158     #define GetSetupMenu(menu) GetSubMenuByChildID(menu, 50310) // ID_SETUP_TERMINAL
2159     #define GetControlMenu(menu) GetSubMenuByChildID(menu, 50410) // ID_CONTROL_RESETTERMINAL
2160     #define GetHelpMenu(menu) GetSubMenuByChildID(menu, 50990) // ID_HELP_ABOUT
2161    
2162     HMENU GetSubMenuByChildID(HMENU menu, UINT id) {
2163     int i, j, items, subitems, cur_id;
2164     HMENU m;
2165    
2166     items = GetMenuItemCount(menu);
2167    
2168     for (i=0; i<items; i++) {
2169     if (m = GetSubMenu(menu, i)) {
2170     subitems = GetMenuItemCount(m);
2171     for (j=0; j<subitems; j++) {
2172     cur_id = GetMenuItemID(m, j);
2173     if (cur_id == id) {
2174     return m;
2175     }
2176     }
2177     }
2178     }
2179     return NULL;
2180     }
2181    
2182 doda 6801 static void PASCAL TTXModifyMenu(HMENU menu)
2183 maya 3227 {
2184 doda 4463 pvar->FileMenu = GetFileMenu(menu);
2185    
2186 maya 3227 /* inserts before ID_HELP_ABOUT */
2187     UTIL_get_lang_msg("MENU_ABOUT", pvar, "About &TTSSH...");
2188     insertMenuBeforeItem(menu, 50990, MF_ENABLED, ID_ABOUTMENU, pvar->ts->UIMsg);
2189    
2190     /* inserts before ID_SETUP_TCPIP */
2191     UTIL_get_lang_msg("MENU_SSH", pvar, "SS&H...");
2192     insertMenuBeforeItem(menu, 50360, MF_ENABLED, ID_SSHSETUPMENU, pvar->ts->UIMsg);
2193     /* inserts before ID_SETUP_TCPIP */
2194     UTIL_get_lang_msg("MENU_SSH_AUTH", pvar, "SSH &Authentication...");
2195     insertMenuBeforeItem(menu, 50360, MF_ENABLED, ID_SSHAUTHSETUPMENU, pvar->ts->UIMsg);
2196     /* inserts before ID_SETUP_TCPIP */
2197     UTIL_get_lang_msg("MENU_SSH_FORWARD", pvar, "SSH F&orwarding...");
2198     insertMenuBeforeItem(menu, 50360, MF_ENABLED, ID_SSHFWDSETUPMENU, pvar->ts->UIMsg);
2199     UTIL_get_lang_msg("MENU_SSH_KEYGEN", pvar, "SSH KeyGe&nerator...");
2200     insertMenuBeforeItem(menu, 50360, MF_ENABLED, ID_SSHKEYGENMENU, pvar->ts->UIMsg);
2201    
2202     /* inserts before ID_FILE_CHANGEDIR */
2203     UTIL_get_lang_msg("MENU_SSH_SCP", pvar, "SS&H SCP...");
2204 doda 4463 insertMenuBeforeItem(menu, 50170, MF_GRAYED, ID_SSHSCPMENU, pvar->ts->UIMsg);
2205 maya 3227 }
2206    
2207 doda 6801 static void PASCAL TTXModifyPopupMenu(HMENU menu) {
2208 doda 4463 if (menu == pvar->FileMenu) {
2209 maya 6997 if (pvar->cv->Ready && pvar->socket != INVALID_SOCKET)
2210 doda 4463 EnableMenuItem(menu, ID_SSHSCPMENU, MF_BYCOMMAND | MF_ENABLED);
2211     else
2212     EnableMenuItem(menu, ID_SSHSCPMENU, MF_BYCOMMAND | MF_GRAYED);
2213     }
2214     }
2215    
2216 maya 6132 static void about_dlg_set_abouttext(PTInstVar pvar, HWND dlg, digest_algorithm dgst_alg)
2217 maya 3227 {
2218 maya 6135 char buf[1024], buf2[2048];
2219 yutakapon 5575 char *fp = NULL;
2220 maya 3227
2221     // TTSSH�_�C�A���O���\������SSH������������ (2004.10.30 yutaka)
2222     if (pvar->socket != INVALID_SOCKET) {
2223 maya 6135 buf2[0] = '\0';
2224 maya 6132
2225 maya 3227 if (SSHv1(pvar)) {
2226 maya 6135 UTIL_get_lang_msg("DLG_ABOUT_SERVERID", pvar, "Server ID:");
2227     strncat_s(buf2, sizeof(buf2), pvar->ts->UIMsg, _TRUNCATE);
2228     strncat_s(buf2, sizeof(buf2), " ", _TRUNCATE);
2229 maya 3227 SSH_get_server_ID_info(pvar, buf, sizeof(buf));
2230 maya 6135 strncat_s(buf2, sizeof(buf2), buf, _TRUNCATE);
2231     strncat_s(buf2, sizeof(buf2), "\r\n", _TRUNCATE);
2232    
2233 maya 3227