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