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 6250 - (hide annotations) (download) (as text)
Tue Jan 5 12:05:47 2016 UTC (8 years, 3 months ago) by doda
Original Path: trunk/ttssh2/ttxssh/ttxssh.c
File MIME type: text/x-csrc
File size: 196741 byte(s)
arc4random() の実装を OpenSSH の ChaCha20 ベースの物に置き換え
# チェックが不十分に思うけれど、度々 conflict するのに心が折れたのでとりあえずコミット
# あと MIN や uint32 とかの定義場所を整理したかったけれど後で

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