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 5882 - (hide annotations) (download) (as text)
Sat May 23 12:42:04 2015 UTC (8 years, 10 months ago) by maya
Original Path: trunk/ttssh2/ttxssh/ttxssh.c
File MIME type: text/x-csrc
File size: 191765 byte(s)
http://osdn.jp/ticket/browse.php?group_id=1412&tid=35182 引数の解析処理を統一する
  コマンドラインオプションの分解処理を ttlib.c の GetParam() にまとめた
  各オプションのクォート解除処理を ttlib.c の DequoteParam() にまとめた
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 maya 5882 char *option2 = (char *)calloc(opt_len, sizeof(char));
1641 maya 5869 int action;
1642 maya 5874 PCHAR start, cur, next;
1643 maya 5869
1644     if (pvar->hostdlg_activated) {
1645     pvar->settings.Enabled = pvar->hostdlg_Enabled;
1646     }
1647    
1648 maya 5874 /* the first term shuld be executable filename of Tera Term */
1649     start = GetParam(option, opt_len, param);
1650    
1651     cur = start;
1652 maya 5869 while (next = GetParam(option, opt_len, cur)) {
1653     action = OPTION_NONE;
1654    
1655     if ((option[0] == '-' || option[0] == '/')) {
1656     if (MATCH_STR(option + 1, "ssh") == 0) {
1657     if (MATCH_STR(option + 4, "-f=") == 0) {
1658 maya 5882 DequoteParam(option2, opt_len, option + 7);
1659     read_ssh_options_from_user_file(pvar, option2);
1660 maya 5869 action = OPTION_CLEAR;
1661     } else if (MATCH_STR(option + 4, "-consume=") == 0) {
1662 maya 5882 DequoteParam(option2, opt_len, option + 13);
1663     read_ssh_options_from_user_file(pvar, option2);
1664     DeleteFile(option2);
1665 maya 5869 action = OPTION_CLEAR;
1666     }
1667    
1668     // ttermpro.exe �� /F= �w������ TTSSH ������������ (2006.10.11 maya)
1669     } else if (MATCH_STR_I(option + 1, "f=") == 0) {
1670 maya 5882 DequoteParam(option2, opt_len, option + 3);
1671     read_ssh_options_from_user_file(pvar, option2);
1672 maya 5869 // Tera Term���������������K�v������������������
1673     }
1674     }
1675    
1676     switch (action) {
1677     case OPTION_CLEAR:
1678     memset(cur, ' ', next-cur);
1679     break;
1680     case OPTION_REPLACE:
1681     memset(cur, ' ', next-cur);
1682     memcpy(cur+1, option, strlen(option));
1683     break;
1684     }
1685    
1686     cur = next;
1687     }
1688    
1689 maya 5874 cur = start;
1690 maya 5869 while (next = GetParam(option, opt_len, cur)) {
1691     action = OPTION_NONE;
1692    
1693     if ((option[0] == '-' || option[0] == '/')) {
1694     action = OPTION_CLEAR;
1695     if (MATCH_STR(option + 1, "ssh") == 0) {
1696     if (option[4] == 0) {
1697     pvar->settings.Enabled = 1;
1698     } else if (MATCH_STR(option + 4, "-L") == 0 ||
1699     MATCH_STR(option + 4, "-R") == 0 ||
1700     _stricmp(option + 4, "-X") == 0) {
1701     add_forward_param(pvar, option+5);
1702     } else if (MATCH_STR(option + 4, "-X") == 0) {
1703     add_forward_param(pvar, "X");
1704     strncpy_s(pvar->settings.X11Display,
1705     sizeof(pvar->settings.X11Display),
1706     option + 6, _TRUNCATE);
1707     } else if (MATCH_STR(option + 4, "-v") == 0) {
1708     pvar->settings.LogLevel = LOG_LEVEL_VERBOSE;
1709     } else if (_stricmp(option + 4, "-autologin") == 0 ||
1710     _stricmp(option + 4, "-autologon") == 0) {
1711     pvar->settings.TryDefaultAuth = TRUE;
1712     } else if (MATCH_STR_I(option + 4, "-agentconfirm=") == 0) {
1713     if ((_stricmp(option+18, "off") == 0) ||
1714     (_stricmp(option+18, "no") == 0) ||
1715     (_stricmp(option+18, "false") == 0) ||
1716     (_stricmp(option+18, "0") == 0) ||
1717     (_stricmp(option+18, "n") == 0)) {
1718     pvar->settings.ForwardAgentConfirm = 0;
1719     }
1720     else {
1721     pvar->settings.ForwardAgentConfirm = 1;
1722     }
1723    
1724     // -axx������������������
1725     } else if (MATCH_STR(option + 4, "-a") == 0) {
1726     pvar->settings.ForwardAgent = FALSE;
1727     } else if (MATCH_STR(option + 4, "-A") == 0) {
1728     pvar->settings.ForwardAgent = TRUE;
1729    
1730     } else if (MATCH_STR(option + 4, "-C=") == 0) {
1731     pvar->settings.CompressionLevel = atoi(option+7);
1732     if (pvar->settings.CompressionLevel < 0) {
1733     pvar->settings.CompressionLevel = 0;
1734     }
1735     else if (pvar->settings.CompressionLevel > 9) {
1736     pvar->settings.CompressionLevel = 9;
1737     }
1738     } else if (MATCH_STR(option + 4, "-C") == 0) {
1739     pvar->settings.CompressionLevel = 6;
1740     } else if (MATCH_STR(option + 4, "-c") == 0) {
1741     pvar->settings.CompressionLevel = 0;
1742     } else if (MATCH_STR_I(option + 4, "-icon=") == 0) {
1743     if ((_stricmp(option+10, "old") == 0) ||
1744     (_stricmp(option+10, "yellow") == 0) ||
1745     (_stricmp(option+10, "securett_yellow") == 0)) {
1746     pvar->settings.IconID = IDI_SECURETT_YELLOW;
1747     }
1748     else {
1749     pvar->settings.IconID = IDI_SECURETT;
1750     }
1751    
1752     // /ssh1 �� /ssh2 �I�v�V�������V�K���� (2006.9.16 maya)
1753     } else if (MATCH_STR(option + 4, "1") == 0) {
1754     pvar->settings.Enabled = 1;
1755     pvar->settings.ssh_protocol_version = 1;
1756     } else if (MATCH_STR(option + 4, "2") == 0) {
1757     pvar->settings.Enabled = 1;
1758     pvar->settings.ssh_protocol_version = 2;
1759    
1760     } else {
1761     char buf[1024];
1762    
1763     UTIL_get_lang_msg("MSG_UNKNOWN_OPTION_ERROR", pvar,
1764     "Unrecognized command-line option: %s");
1765     _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg, option);
1766    
1767     MessageBox(NULL, buf, "TTSSH", MB_OK | MB_ICONEXCLAMATION);
1768     }
1769    
1770     // ttermpro.exe �� /T= �w�������p�������A������������ (2006.10.19 maya)
1771     } else if (MATCH_STR_I(option + 1, "t=") == 0) {
1772     if (strcmp(option + 3, "2") == 0) {
1773     pvar->settings.Enabled = 1;
1774     // /t=2��ttssh�������g������������
1775     } else {
1776     pvar->settings.Enabled = 0;
1777     action = OPTION_NONE; // Tera Term������������������������
1778     }
1779    
1780     // /1 ������ /2 �I�v�V�������V�K���� (2004.10.3 yutaka)
1781     } else if (MATCH_STR(option + 1, "1") == 0) {
1782     // command line: /ssh /1 is SSH1 only
1783     pvar->settings.ssh_protocol_version = 1;
1784    
1785     } else if (MATCH_STR(option + 1, "2") == 0) {
1786     // command line: /ssh /2 is SSH2 & SSH1
1787     pvar->settings.ssh_protocol_version = 2;
1788    
1789     } else if (MATCH_STR(option + 1, "nossh") == 0) {
1790     // '/nossh' �I�v�V�����������B
1791     // TERATERM.INI ��SSH���L�������������������A������Cygterm���N��������������
1792     // �����������������B(2004.10.11 yutaka)
1793     pvar->settings.Enabled = 0;
1794    
1795     } else if (MATCH_STR(option + 1, "telnet") == 0) {
1796     // '/telnet' ���w�������������������� '/nossh' ��������
1797     // SSH������������ (2006.9.16 maya)
1798     pvar->settings.Enabled = 0;
1799     // Tera Term �� Telnet �t���O���t����
1800     pvar->ts->Telnet = 1;
1801    
1802     } else if (MATCH_STR(option + 1, "auth") == 0) {
1803     // SSH2�������O�C���I�v�V����������
1804     //
1805     // SYNOPSIS: /ssh /auth=passowrd /user=���[�U�� /passwd=�p�X���[�h
1806     // /ssh /auth=publickey /user=���[�U�� /passwd=�p�X���[�h /keyfile=�p�X
1807     // EXAMPLE: /ssh /auth=password /user=nike /passwd=a@bc
1808     // /ssh /auth=publickey /user=foo /passwd=bar /keyfile=d:\tmp\id_rsa
1809     // NOTICE: �p�X���[�h���p�X�������������������A�u�����N���������� @ ���g�������B
1810     //
1811     // (2004.11.30 yutaka)
1812     // (2005.1.26 yutaka) ���������B���J���F���T�|�[�g�B
1813     //
1814     pvar->ssh2_autologin = 1; // for SSH2 (2004.11.30 yutaka)
1815    
1816     if (MATCH_STR(option + 5, "=password") == 0) { // �p�X���[�h
1817     //pvar->auth_state.cur_cred.method = SSH_AUTH_PASSWORD;
1818     pvar->ssh2_authmethod = SSH_AUTH_PASSWORD;
1819    
1820     // /auth=challenge ������ (2007.10.5 maya)
1821     } else if (MATCH_STR(option + 5, "=challenge") == 0) { // keyboard-interactive�F��
1822     //pvar->auth_state.cur_cred.method = SSH_AUTH_TIS;
1823     pvar->ssh2_authmethod = SSH_AUTH_TIS;
1824    
1825     } else if (MATCH_STR(option + 5, "=publickey") == 0) { // ���J���F��
1826     //pvar->auth_state.cur_cred.method = SSH_AUTH_RSA;
1827     pvar->ssh2_authmethod = SSH_AUTH_RSA;
1828    
1829     } else if (MATCH_STR(option + 5, "=pageant") == 0) { // ���J���F�� by Pageant
1830     //pvar->auth_state.cur_cred.method = SSH_AUTH_RSA;
1831     pvar->ssh2_authmethod = SSH_AUTH_PAGEANT;
1832    
1833     } else {
1834     // TODO:
1835    
1836     }
1837    
1838     } else if (MATCH_STR(option + 1, "user=") == 0) {
1839 maya 5882 DequoteParam(option2, opt_len, option + 6);
1840     _snprintf_s(pvar->ssh2_username, sizeof(pvar->ssh2_username), _TRUNCATE, "%s", option2);
1841 maya 5869
1842     } else if (MATCH_STR(option + 1, "passwd=") == 0) {
1843 maya 5882 DequoteParam(option2, opt_len, option + 8);
1844     _snprintf_s(pvar->ssh2_password, sizeof(pvar->ssh2_password), _TRUNCATE, "%s", option2);
1845 maya 5869
1846     } else if (MATCH_STR(option + 1, "keyfile=") == 0) {
1847 maya 5882 DequoteParam(option2, opt_len, option + 9);
1848     _snprintf_s(pvar->ssh2_keyfile, sizeof(pvar->ssh2_keyfile), _TRUNCATE, "%s", option2);
1849 maya 5869
1850     } else if (MATCH_STR(option + 1, "ask4passwd") == 0) {
1851     // �p�X���[�h������ (2006.9.18 maya)
1852     pvar->ask4passwd = 1;
1853    
1854     } else if (MATCH_STR(option + 1, "nosecuritywarning") == 0) {
1855     // known_hosts�`�F�b�N���������B���Y�I�v�V�������g�����A�Z�L�����e�B������������
1856     // �����A�B���I�v�V���������������B
1857     // (2009.10.4 yutaka)
1858     pvar->nocheck_known_hosts = TRUE;
1859    
1860     }
1861     else { // Other (not ttssh) option
1862     action = OPTION_NONE; // ttssh���I�v�V������������������������
1863     }
1864    
1865     // �p�X���[�h�������������������O�C��������������
1866     // /auth ���F�����\�b�h���w�������������p������ (2006.9.18 maya)
1867     if (pvar->ask4passwd == 1) {
1868     pvar->ssh2_autologin = 0;
1869     }
1870    
1871     }
1872     else if ((MATCH_STR_I(option, "ssh://") == 0) ||
1873     (MATCH_STR_I(option, "ssh1://") == 0) ||
1874     (MATCH_STR_I(option, "ssh2://") == 0) ||
1875     (MATCH_STR_I(option, "slogin://") == 0) ||
1876     (MATCH_STR_I(option, "slogin1://") == 0) ||
1877     (MATCH_STR_I(option, "slogin2://") == 0)) {
1878     //
1879     // ssh://user@host/ ����URL�`�����T�|�[�g
1880     // ���{�I�������� telnet:// URL��������
1881     //
1882     // �Q�l:
1883     // RFC3986: Uniform Resource Identifier (URI): Generic Syntax
1884     // RFC4248: The telnet URI Scheme
1885     //
1886     char *p, *p2, *p3;
1887     int optlen, hostlen;
1888    
1889     optlen = strlen(option);
1890    
1891     // ������':'���O�����������������������A������ssh�v���g�R���o�[�W������������
1892     p = _mbschr(option, ':');
1893     switch (*(p-1)) {
1894     case '1':
1895     pvar->settings.ssh_protocol_version = 1;
1896     break;
1897     case '2':
1898     pvar->settings.ssh_protocol_version = 2;
1899     break;
1900     }
1901    
1902     // authority part �����|�C���^������
1903     p += 3;
1904    
1905     // path part ������������
1906     if ((p2 = _mbschr(p, '/')) != NULL) {
1907     *p2 = 0;
1908     }
1909    
1910     // '@'�������������A���������O�����[�U����
1911     if ((p2 = _mbschr(p, '@')) != NULL) {
1912     *p2 = 0;
1913     // ':'���~���p�X���[�h
1914     if ((p3 = _mbschr(p, ':')) != NULL) {
1915     *p3 = 0;
1916     percent_decode(pvar->ssh2_password, sizeof(pvar->ssh2_password), p3 + 1);
1917     }
1918     percent_decode(pvar->ssh2_username, sizeof(pvar->ssh2_username), p);
1919     // p �� host part ������('@'����������)����������������
1920     p = p2 + 1;
1921     }
1922    
1923     // host part �� option �����������������Ascheme part ������
1924     // port�w����������������port���������������������m��������������
1925     hostlen = strlen(p);
1926     memmove_s(option, optlen, p, hostlen);
1927     option[hostlen] = 0;
1928    
1929     // �|�[�g�w������������":22"������
1930     #ifndef NO_INET6
1931     if (option[0] == '[' && option[hostlen-1] == ']' || // IPv6 raw address without port
1932     option[0] != '[' && _mbschr(option, ':') == NULL) { // hostname or IPv4 raw address without port
1933     #else
1934     if (_mbschr(option, ':') == NULL) {
1935     #endif /* NO_INET6 */
1936     memcpy_s(option+hostlen, optlen-hostlen, ":22", 3);
1937     hostlen += 3;
1938     }
1939    
1940     // �|�[�g�w�����������������X�y�[�X������
1941     memset(option+hostlen, ' ', optlen-hostlen);
1942    
1943     pvar->settings.Enabled = 1;
1944    
1945     action = OPTION_REPLACE;
1946     }
1947     else if (_mbschr(option, '@') != NULL) {
1948     //
1949     // user@host �`�����T�|�[�g
1950     // ����������ssh�������T�|�[�g�����A���[�U����ttssh���������B
1951     // (ssh�������O -- ttssh�������W������������)
1952     // �����I��telnet authentication option���T�|�[�g��������
1953     // Tera Term�{�����������������������\���B
1954     //
1955     char *p;
1956     p = _mbschr(option, '@');
1957     *p = 0;
1958    
1959     strncpy_s(pvar->ssh2_username, sizeof(pvar->ssh2_username), option, _TRUNCATE);
1960    
1961     // ���[�U���������X�y�[�X�������B
1962     // ������TTX��Tera Term�{�������������������X�y�[�X�����������������A
1963     // �z�X�g�����������l�����K�v�������B
1964     memset(option, ' ', p-option+1);
1965    
1966     action = OPTION_REPLACE;
1967     }
1968    
1969    
1970     switch (action) {
1971     case OPTION_CLEAR:
1972     memset(cur, ' ', next-cur);
1973     break;
1974     case OPTION_REPLACE:
1975     memset(cur, ' ', next-cur);
1976     memcpy(cur+1, option, strlen(option));
1977     break;
1978     }
1979    
1980     cur = next;
1981     }
1982    
1983     free(option);
1984    
1985     FWDUI_load_settings(pvar);
1986    
1987     (pvar->ParseParam) (param, ts, DDETopic);
1988     }
1989     #else
1990 maya 3227 /* returns 1 if the option text must be deleted */
1991     static int parse_option(PTInstVar pvar, char FAR * option)
1992     {
1993     if ((option[0] == '-' || option[0] == '/')) {
1994     if (MATCH_STR(option + 1, "ssh") == 0) {
1995     if (option[4] == 0) {
1996     pvar->settings.Enabled = 1;
1997     } else if (MATCH_STR(option + 4, "-L") == 0 ||
1998     MATCH_STR(option + 4, "-R") == 0 ||
1999     _stricmp(option + 4, "-X") == 0) {
2000 doda 5799 add_forward_param(pvar, option+5);
2001     } else if (MATCH_STR(option + 4, "-X") == 0) {
2002     add_forward_param(pvar, "X");
2003 doda 5793 strncpy_s(pvar->settings.X11Display,
2004     sizeof(pvar->settings.X11Display),
2005 doda 5799 option + 6, _TRUNCATE);
2006 maya 3227 } else if (MATCH_STR(option + 4, "-f=") == 0) {
2007     read_ssh_options_from_user_file(pvar, option + 7);
2008     } else if (MATCH_STR(option + 4, "-v") == 0) {
2009     pvar->settings.LogLevel = LOG_LEVEL_VERBOSE;
2010     } else if (_stricmp(option + 4, "-autologin") == 0 ||
2011     _stricmp(option + 4, "-autologon") == 0) {
2012     pvar->settings.TryDefaultAuth = TRUE;
2013 doda 4235 } else if (MATCH_STR_I(option + 4, "-agentconfirm=") == 0) {
2014     if ((_stricmp(option+18, "off") == 0) ||
2015     (_stricmp(option+18, "no") == 0) ||
2016     (_stricmp(option+18, "false") == 0) ||
2017     (_stricmp(option+18, "0") == 0) ||
2018     (_stricmp(option+18, "n") == 0)) {
2019     pvar->settings.ForwardAgentConfirm = 0;
2020     }
2021     else {
2022     pvar->settings.ForwardAgentConfirm = 1;
2023     }
2024 maya 3227
2025     // -axx������������������
2026     } else if (MATCH_STR(option + 4, "-a") == 0) {
2027     pvar->settings.ForwardAgent = FALSE;
2028     } else if (MATCH_STR(option + 4, "-A") == 0) {
2029     pvar->settings.ForwardAgent = TRUE;
2030    
2031     } else if (MATCH_STR(option + 4, "-consume=") == 0) {
2032     read_ssh_options_from_user_file(pvar, option + 13);
2033     DeleteFile(option + 13);
2034    
2035 doda 4151 } else if (MATCH_STR(option + 4, "-C=") == 0) {
2036     pvar->settings.CompressionLevel = atoi(option+7);
2037     if (pvar->settings.CompressionLevel < 0) {
2038     pvar->settings.CompressionLevel = 0;
2039     }
2040     else if (pvar->settings.CompressionLevel > 9) {
2041     pvar->settings.CompressionLevel = 9;
2042     }
2043     } else if (MATCH_STR(option + 4, "-C") == 0) {
2044     pvar->settings.CompressionLevel = 6;
2045     } else if (MATCH_STR(option + 4, "-c") == 0) {
2046     pvar->settings.CompressionLevel = 0;
2047 doda 5261 } else if (MATCH_STR_I(option + 4, "-icon=") == 0) {
2048     if ((_stricmp(option+10, "old") == 0) ||
2049     (_stricmp(option+10, "yellow") == 0) ||
2050     (_stricmp(option+10, "securett_yellow") == 0)) {
2051     pvar->settings.IconID = IDI_SECURETT_YELLOW;
2052     }
2053     else {
2054     pvar->settings.IconID = IDI_SECURETT;
2055     }
2056 doda 4151
2057 maya 3227 // /ssh1 �� /ssh2 �I�v�V�������V�K���� (2006.9.16 maya)
2058     } else if (MATCH_STR(option + 4, "1") == 0) {
2059     pvar->settings.Enabled = 1;
2060     pvar->settings.ssh_protocol_version = 1;
2061     } else if (MATCH_STR(option + 4, "2") == 0) {
2062     pvar->settings.Enabled = 1;
2063     pvar->settings.ssh_protocol_version = 2;
2064    
2065     } else {
2066     char buf[1024];
2067    
2068     UTIL_get_lang_msg("MSG_UNKNOWN_OPTION_ERROR", pvar,
2069     "Unrecognized command-line option: %s");
2070     _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg, option);
2071    
2072     MessageBox(NULL, buf, "TTSSH", MB_OK | MB_ICONEXCLAMATION);
2073     }
2074    
2075     // ttermpro.exe �� /T= �w�������p�������A������������ (2006.10.19 maya)
2076     } else if (MATCH_STR_I(option + 1, "t=") == 0) {
2077     if (strcmp(option + 3, "2") == 0) {
2078     pvar->settings.Enabled = 1;
2079 doda 3307 return OPTION_CLEAR; // /t=2��ttssh�������g������������
2080 maya 3227 } else {
2081     pvar->settings.Enabled = 0;
2082 doda 3307 return OPTION_NONE; // Tera Term������������������������
2083 maya 3227 }
2084    
2085     // ttermpro.exe �� /F= �w������ TTSSH ������������ (2006.10.11 maya)
2086     } else if (MATCH_STR_I(option + 1, "f=") == 0) {
2087     read_ssh_options_from_user_file(pvar, option + 3);
2088 doda 3307 return OPTION_NONE; // Tera Term���������������K�v������������������
2089 maya 3227
2090     // /1 ������ /2 �I�v�V�������V�K���� (2004.10.3 yutaka)
2091     } else if (MATCH_STR(option + 1, "1") == 0) {
2092     // command line: /ssh /1 is SSH1 only
2093     pvar->settings.ssh_protocol_version = 1;
2094    
2095     } else if (MATCH_STR(option + 1, "2") == 0) {
2096     // command line: /ssh /2 is SSH2 & SSH1
2097     pvar->settings.ssh_protocol_version = 2;
2098    
2099     } else if (MATCH_STR(option + 1, "nossh") == 0) {
2100     // '/nossh' �I�v�V�����������B
2101     // TERATERM.INI ��SSH���L�������������������A������Cygterm���N��������������
2102     // �����������������B(2004.10.11 yutaka)
2103     pvar->settings.Enabled = 0;
2104    
2105     } else if (MATCH_STR(option + 1, "telnet") == 0) {
2106     // '/telnet' ���w�������������������� '/nossh' ��������
2107     // SSH������������ (2006.9.16 maya)
2108     pvar->settings.Enabled = 0;
2109 maya 3533 // Tera Term �� Telnet �t���O���t����
2110     pvar->ts->Telnet = 1;
2111 maya 3227
2112     } else if (MATCH_STR(option + 1, "auth") == 0) {
2113     // SSH2�������O�C���I�v�V����������
2114     //
2115     // SYNOPSIS: /ssh /auth=passowrd /user=���[�U�� /passwd=�p�X���[�h
2116     // /ssh /auth=publickey /user=���[�U�� /passwd=�p�X���[�h /keyfile=�p�X
2117     // EXAMPLE: /ssh /auth=password /user=nike /passwd=a@bc
2118     // /ssh /auth=publickey /user=foo /passwd=bar /keyfile=d:\tmp\id_rsa
2119     // NOTICE: �p�X���[�h���p�X�������������������A�u�����N���������� @ ���g�������B
2120     //
2121     // (2004.11.30 yutaka)
2122     // (2005.1.26 yutaka) ���������B���J���F���T�|�[�g�B
2123     //
2124     pvar->ssh2_autologin = 1; // for SSH2 (2004.11.30 yutaka)
2125    
2126     if (MATCH_STR(option + 5, "=password") == 0) { // �p�X���[�h
2127     //pvar->auth_state.cur_cred.method = SSH_AUTH_PASSWORD;
2128     pvar->ssh2_authmethod = SSH_AUTH_PASSWORD;
2129    
2130     // /auth=challenge ������ (2007.10.5 maya)
2131     } else if (MATCH_STR(option + 5, "=challenge") == 0) { // keyboard-interactive�F��
2132     //pvar->auth_state.cur_cred.method = SSH_AUTH_TIS;
2133     pvar->ssh2_authmethod = SSH_AUTH_TIS;
2134    
2135     } else if (MATCH_STR(option + 5, "=publickey") == 0) { // ���J���F��
2136     //pvar->auth_state.cur_cred.method = SSH_AUTH_RSA;
2137     pvar->ssh2_authmethod = SSH_AUTH_RSA;
2138    
2139     } else if (MATCH_STR(option + 5, "=pageant") == 0) { // ���J���F�� by Pageant
2140     //pvar->auth_state.cur_cred.method = SSH_AUTH_RSA;
2141     pvar->ssh2_authmethod = SSH_AUTH_PAGEANT;
2142    
2143     } else {
2144     // TODO:
2145    
2146     }
2147    
2148     } else if (MATCH_STR(option + 1, "user=") == 0) {
2149 maya 3433 _snprintf_s(pvar->ssh2_username, sizeof(pvar->ssh2_username), _TRUNCATE, "%s", option + 6);
2150    
2151 maya 3227 } else if (MATCH_STR(option + 1, "passwd=") == 0) {
2152 maya 3433 _snprintf_s(pvar->ssh2_password, sizeof(pvar->ssh2_password), _TRUNCATE, "%s", option + 8);
2153 maya 3227
2154     } else if (MATCH_STR(option + 1, "keyfile=") == 0) {
2155 maya 3433 _snprintf_s(pvar->ssh2_keyfile, sizeof(pvar->ssh2_keyfile), _TRUNCATE, "%s", option + 9);
2156 maya 3227
2157     } else if (MATCH_STR(option + 1, "ask4passwd") == 0) {
2158     // �p�X���[�h������ (2006.9.18 maya)
2159     pvar->ask4passwd = 1;
2160    
2161 yutakapon 3631 } else if (MATCH_STR(option + 1, "nosecuritywarning") == 0) {
2162     // known_hosts�`�F�b�N���������B���Y�I�v�V�������g�����A�Z�L�����e�B������������
2163     // �����A�B���I�v�V���������������B
2164     // (2009.10.4 yutaka)
2165     pvar->nocheck_known_hosts = TRUE;
2166    
2167 maya 3227 }
2168 doda 3307 else { // Other (not ttssh) option
2169     return OPTION_NONE; // ttssh���I�v�V������������������������
2170     }
2171 maya 3227
2172     // �p�X���[�h�������������������O�C��������������
2173     // /auth ���F�����\�b�h���w�������������p������ (2006.9.18 maya)
2174     if (pvar->ask4passwd == 1) {
2175     pvar->ssh2_autologin = 0;
2176     }
2177 doda 3307 return OPTION_CLEAR;
2178 maya 3227
2179     }
2180     else if ((MATCH_STR_I(option, "ssh://") == 0) ||
2181     (MATCH_STR_I(option, "ssh1://") == 0) ||
2182     (MATCH_STR_I(option, "ssh2://") == 0) ||
2183     (MATCH_STR_I(option, "slogin://") == 0) ||
2184     (MATCH_STR_I(option, "slogin1://") == 0) ||
2185     (MATCH_STR_I(option, "slogin2://") == 0)) {
2186     //
2187     // ssh://user@host/ ����URL�`�����T�|�[�g
2188     // ���{�I�������� telnet:// URL��������
2189     //
2190     // �Q�l:
2191     // RFC3986: Uniform Resource Identifier (URI): Generic Syntax
2192     // RFC4248: The telnet URI Scheme
2193     //
2194     char *p, *p2, *p3;
2195     int optlen, hostlen;
2196    
2197     optlen = strlen(option);
2198    
2199     // ������':'���O�����������������������A������ssh�v���g�R���o�[�W������������
2200 doda 3232 p = _mbschr(option, ':');
2201 maya 3227 switch (*(p-1)) {
2202     case '1':
2203     pvar->settings.ssh_protocol_version = 1;
2204     break;
2205     case '2':
2206     pvar->settings.ssh_protocol_version = 2;
2207     break;
2208     }
2209    
2210     // authority part �����|�C���^������
2211     p += 3;
2212    
2213     // path part ������������
2214 doda 3232 if ((p2 = _mbschr(p, '/')) != NULL) {
2215 maya 3227 *p2 = 0;
2216     }
2217    
2218     // '@'�������������A���������O�����[�U����
2219 doda 3232 if ((p2 = _mbschr(p, '@')) != NULL) {
2220 maya 3227 *p2 = 0;
2221     // ':'���~���p�X���[�h
2222 doda 3232 if ((p3 = _mbschr(p, ':')) != NULL) {
2223 maya 3227 *p3 = 0;
2224     percent_decode(pvar->ssh2_password, sizeof(pvar->ssh2_password), p3 + 1);
2225     }
2226     percent_decode(pvar->ssh2_username, sizeof(pvar->ssh2_username), p);
2227     // p �� host part ������('@'����������)����������������
2228     p = p2 + 1;
2229     }
2230    
2231     // host part �� option �����������������Ascheme part ������
2232     // port�w����������������port���������������������m��������������
2233     hostlen = strlen(p);
2234     memmove_s(option, optlen, p, hostlen);
2235     option[hostlen] = 0;
2236    
2237     // �|�[�g�w������������":22"������
2238     #ifndef NO_INET6
2239     if (option[0] == '[' && option[hostlen-1] == ']' || // IPv6 raw address without port
2240 doda 3232 option[0] != '[' && _mbschr(option, ':') == NULL) { // hostname or IPv4 raw address without port
2241 maya 3227 #else
2242 doda 3232 if (_mbschr(option, ':') == NULL) {
2243 maya 3227 #endif /* NO_INET6 */
2244     memcpy_s(option+hostlen, optlen-hostlen, ":22", 3);
2245     hostlen += 3;
2246     }
2247    
2248     // �|�[�g�w�����������������X�y�[�X������
2249     memset(option+hostlen, ' ', optlen-hostlen);
2250    
2251     pvar->settings.Enabled = 1;
2252    
2253     return OPTION_REPLACE;
2254     }
2255 doda 3232 else if (_mbschr(option, '@') != NULL) {
2256 maya 3227 //
2257     // user@host �`�����T�|�[�g
2258     // ����������ssh�������T�|�[�g�����A���[�U����ttssh���������B
2259     // (ssh�������O -- ttssh�������W������������)
2260     // �����I��telnet authentication option���T�|�[�g��������
2261     // Tera Term�{�����������������������\���B
2262     //
2263     char *p;
2264 doda 3232 p = _mbschr(option, '@');
2265 maya 3227 *p = 0;
2266    
2267     strncpy_s(pvar->ssh2_username, sizeof(pvar->ssh2_username), option, _TRUNCATE);
2268    
2269     // ���[�U���������X�y�[�X�������B
2270     // ������TTX��Tera Term�{�������������������X�y�[�X�����������������A
2271     // �z�X�g�����������l�����K�v�������B
2272     memset(option, ' ', p-option+1);
2273    
2274     return OPTION_REPLACE;
2275     }