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