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