Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /branches/ssh_chacha20poly1305/ttssh2/ttxssh/auth.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8218 - (hide annotations) (download) (as text)
Sun Sep 22 11:00:31 2019 UTC (4 years, 6 months ago) by yutakapon
Original Path: trunk/ttssh2/ttxssh/auth.c
File MIME type: text/x-csrc
File size: 62204 byte(s)
SSHユーザ認証ダイアログで、ユーザ欄からTABキーでパスフレーズ欄への移動に遅延がある問題を改善した。

1 maya 3227 /*
2 doda 6841 * Copyright (c) 1998-2001, Robert O'Callahan
3 zmatsuo 7605 * (C) 2004-2019 TeraTerm Project
4 doda 6841 * All rights reserved.
5     *
6     * Redistribution and use in source and binary forms, with or without
7     * modification, are permitted provided that the following conditions
8     * are met:
9     *
10     * 1. Redistributions of source code must retain the above copyright
11     * notice, this list of conditions and the following disclaimer.
12     * 2. Redistributions in binary form must reproduce the above copyright
13     * notice, this list of conditions and the following disclaimer in the
14     * documentation and/or other materials provided with the distribution.
15     * 3. The name of the author may not be used to endorse or promote products
16     * derived from this software without specific prior written permission.
17     *
18     * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
19     * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20     * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21     * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22     * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23     * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24     * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25     * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27     * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28     */
29 maya 3227
30     #include "ttxssh.h"
31     #include "util.h"
32     #include "ssh.h"
33 maya 4304 #include "key.h"
34 zmatsuo 7360 #include "ttlib.h"
35 zmatsuo 7560 #include "dlglib.h"
36 maya 3227
37     #include <io.h>
38     #include <fcntl.h>
39     #include <stdlib.h>
40     #include <errno.h>
41 zmatsuo 8072 #include <lmcons.h> // for UNLEN
42 zmatsuo 7605 #include <crtdbg.h>
43 maya 3227
44     #include "resource.h"
45     #include "keyfiles.h"
46     #include "libputty.h"
47 zmatsuo 7507 #include "tipwin.h"
48 zmatsuo 7605 #include "auth.h"
49 yutakapon 8089 #include "helpid.h"
50 maya 3227
51 zmatsuo 7636 #if defined(_DEBUG) && !defined(_CRTDBG_MAP_ALLOC)
52 zmatsuo 7605 #define malloc(l) _malloc_dbg((l), _NORMAL_BLOCK, __FILE__, __LINE__)
53     #define free(p) _free_dbg((p), _NORMAL_BLOCK)
54     #endif
55    
56 maya 3227 #define AUTH_START_USER_AUTH_ON_ERROR_END 1
57    
58     #define MAX_AUTH_CONTROL IDC_SSHUSEPAGEANT
59    
60 zmatsuo 7560 #undef DialogBoxParam
61     #define DialogBoxParam(p1,p2,p3,p4,p5) \
62     TTDialogBoxParam(p1,p2,p3,p4,p5)
63     #undef EndDialog
64     #define EndDialog(p1,p2) \
65     TTEndDialog(p1, p2)
66 maya 3227
67 doda 6801 void destroy_malloced_string(char **str)
68 maya 3227 {
69     if (*str != NULL) {
70 yutakapon 6229 SecureZeroMemory(*str, strlen(*str));
71 maya 3227 free(*str);
72     *str = NULL;
73     }
74     }
75    
76     static int auth_types_to_control_IDs[] = {
77     -1, IDC_SSHUSERHOSTS, IDC_SSHUSERSA, IDC_SSHUSEPASSWORD,
78     IDC_SSHUSERHOSTS, IDC_SSHUSETIS, -1,
79     -1, -1, -1, -1, -1, -1, -1, -1, -1, IDC_SSHUSEPAGEANT, -1
80     };
81    
82 zmatsuo 7605 typedef struct {
83     WNDPROC ProcOrg;
84     PTInstVar pvar;
85     TipWin *tipwin;
86 zmatsuo 7632 BOOL *UseControlChar;
87 zmatsuo 7605 } TPasswordControlData;
88    
89 zmatsuo 7632 static void password_wnd_proc_close_tooltip(TPasswordControlData *data)
90     {
91     if (data->tipwin != NULL) {
92     TipWinDestroy(data->tipwin);
93     data->tipwin = NULL;
94     }
95     }
96    
97 zmatsuo 7605 static LRESULT CALLBACK password_wnd_proc(HWND control, UINT msg,
98     WPARAM wParam, LPARAM lParam)
99 maya 3227 {
100 zmatsuo 7605 LRESULT result;
101     TPasswordControlData *data = (TPasswordControlData *)GetWindowLongPtr(control, GWLP_USERDATA);
102 maya 3227 switch (msg) {
103     case WM_CHAR:
104 zmatsuo 7632 if ((data->UseControlChar == NULL || *data->UseControlChar == TRUE) &&
105     (GetKeyState(VK_CONTROL) & 0x8000) != 0)
106     { // �����������g�p���� && CTRL�L�[��������������
107 zmatsuo 7507 TCHAR chars[] = { (TCHAR) wParam, 0 };
108 maya 3227
109     SendMessage(control, EM_REPLACESEL, (WPARAM) TRUE,
110 zmatsuo 7507 (LPARAM) (TCHAR *) chars);
111    
112 zmatsuo 7605 if (data->tipwin == NULL) {
113     TCHAR uimsg[MAX_UIMSG];
114 maya 7508 RECT rect;
115 zmatsuo 7605 PTInstVar pvar = data->pvar;
116     UTIL_get_lang_msg("DLG_AUTH_TIP_CONTROL_CODE", pvar, "control character is entered");
117     _tcscpy_s(uimsg, _countof(uimsg), pvar->ts->UIMsg);
118 zmatsuo 7507 if (wParam == 'V' - 'A' + 1) {
119 zmatsuo 7605 // CTRL + V
120     _tcscat_s(uimsg, _countof(uimsg), _T("\n"));
121     UTIL_get_lang_msg("DLG_AUTH_TIP_PASTE_KEY", pvar, "Use Shift + Insert to paste from clipboard");
122     _tcscat_s(uimsg, _countof(uimsg), pvar->ts->UIMsg);
123 zmatsuo 7507 }
124     GetWindowRect(control, &rect);
125 yutakapon 8097 data->tipwin = TipWinCreate(control, rect.left, rect.bottom, uimsg);
126 zmatsuo 7507 }
127    
128 maya 3227 return 0;
129 zmatsuo 7507 } else {
130 zmatsuo 7632 password_wnd_proc_close_tooltip(data);
131 maya 3227 }
132 zmatsuo 7507 break;
133 zmatsuo 7611 case WM_KILLFOCUS:
134 zmatsuo 7632 password_wnd_proc_close_tooltip(data);
135 zmatsuo 7611 break;
136 zmatsuo 7605 }
137    
138     result = CallWindowProc((WNDPROC)data->ProcOrg,
139     control, msg, wParam, lParam);
140    
141     if (msg == WM_NCDESTROY) {
142     SetWindowLongPtr(control, GWLP_WNDPROC, (LONG_PTR)data->ProcOrg);
143 zmatsuo 7632 password_wnd_proc_close_tooltip(data);
144 zmatsuo 7605 free(data);
145 maya 3227 }
146    
147 zmatsuo 7605 return result;
148 maya 3227 }
149    
150 zmatsuo 7632 void init_password_control(PTInstVar pvar, HWND dlg, int item, BOOL *UseControlChar)
151 maya 3227 {
152 zmatsuo 7605 HWND passwordControl = GetDlgItem(dlg, item);
153     TPasswordControlData *data = (TPasswordControlData *)malloc(sizeof(TPasswordControlData));
154     data->ProcOrg = (WNDPROC)GetWindowLongPtr(passwordControl, GWLP_WNDPROC);
155     data->pvar = pvar;
156     data->tipwin = NULL;
157 zmatsuo 7632 data->UseControlChar = UseControlChar;
158 zmatsuo 7605 SetWindowLongPtr(passwordControl, GWLP_WNDPROC, (LONG_PTR)password_wnd_proc);
159     SetWindowLongPtr(passwordControl, GWLP_USERDATA, (LONG_PTR)data);
160 maya 3227 SetFocus(passwordControl);
161     }
162    
163     static void set_auth_options_status(HWND dlg, int controlID)
164     {
165     BOOL RSA_enabled = controlID == IDC_SSHUSERSA;
166     BOOL rhosts_enabled = controlID == IDC_SSHUSERHOSTS;
167     BOOL TIS_enabled = controlID == IDC_SSHUSETIS;
168     BOOL PAGEANT_enabled = controlID == IDC_SSHUSEPAGEANT;
169     int i;
170    
171     CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, controlID);
172    
173     EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORDCAPTION), (!TIS_enabled && !PAGEANT_enabled));
174     EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD), (!TIS_enabled && !PAGEANT_enabled));
175 zmatsuo 7632 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD_OPTION), (!TIS_enabled && !PAGEANT_enabled));
176 maya 3227
177     for (i = IDC_CHOOSERSAFILE; i <= IDC_RSAFILENAME; i++) {
178     EnableWindow(GetDlgItem(dlg, i), RSA_enabled);
179     }
180    
181     for (i = IDC_LOCALUSERNAMELABEL; i <= IDC_HOSTRSAFILENAME; i++) {
182     EnableWindow(GetDlgItem(dlg, i), rhosts_enabled);
183     }
184     }
185    
186     static void init_auth_machine_banner(PTInstVar pvar, HWND dlg)
187     {
188     char buf[1024], buf2[1024];
189    
190     GetDlgItemText(dlg, IDC_SSHAUTHBANNER, buf2, sizeof(buf2));
191     _snprintf_s(buf, sizeof(buf), _TRUNCATE, buf2, SSH_get_host_name(pvar));
192     SetDlgItemText(dlg, IDC_SSHAUTHBANNER, buf);
193     }
194    
195     static void update_server_supported_types(PTInstVar pvar, HWND dlg)
196     {
197     int supported_methods = pvar->auth_state.supported_types;
198     int cur_control = -1;
199     int control;
200     HWND focus = GetFocus();
201    
202     if (supported_methods == 0) {
203     return;
204     }
205    
206     for (control = IDC_SSHUSEPASSWORD; control <= MAX_AUTH_CONTROL;
207     control++) {
208     BOOL enabled = FALSE;
209     int method;
210     HWND item = GetDlgItem(dlg, control);
211    
212     if (item != NULL) {
213     for (method = 0; method <= SSH_AUTH_MAX; method++) {
214     if (auth_types_to_control_IDs[method] == control
215     && (supported_methods & (1 << method)) != 0) {
216     enabled = TRUE;
217     }
218     }
219    
220     EnableWindow(item, enabled);
221    
222     if (IsDlgButtonChecked(dlg, control)) {
223     cur_control = control;
224     }
225     }
226     }
227    
228     if (cur_control >= 0) {
229     if (!IsWindowEnabled(GetDlgItem(dlg, cur_control))) {
230     do {
231     cur_control++;
232     if (cur_control > MAX_AUTH_CONTROL) {
233     cur_control = IDC_SSHUSEPASSWORD;
234     }
235     } while (!IsWindowEnabled(GetDlgItem(dlg, cur_control)));
236    
237     set_auth_options_status(dlg, cur_control);
238    
239     if (focus != NULL && !IsWindowEnabled(focus)) {
240     SetFocus(GetDlgItem(dlg, cur_control));
241     }
242     }
243     }
244     }
245    
246 yutakapon 8218 typedef struct {
247     int tab_focus_entered;
248     WNDPROC proc_org;
249     size_t str_len;
250     } username_proc_data_t;
251    
252 zmatsuo 7639 static LRESULT CALLBACK username_proc(HWND hWnd, UINT msg,
253     WPARAM wParam, LPARAM lParam)
254     {
255 yutakapon 8218 username_proc_data_t *data = (username_proc_data_t *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
256     const WNDPROC ProcOrg = data->proc_org;
257 zmatsuo 7639 const LRESULT result = CallWindowProc(ProcOrg, hWnd, msg, wParam, lParam);
258 yutakapon 8218
259    
260 zmatsuo 7639 switch (msg) {
261     case WM_CHAR:
262 yutakapon 8218 case WM_SETTEXT:
263     if (data->tab_focus_entered == 0) {
264     // ���[�U�[�����������������������A�I�v�V�������g�����������������A
265     // tab�����t�H�[�J�X�������A�I�v�V�����{�^�����p�X��������������
266     // �]���������L�[���������[�U�[�����p�X�t���[�Y���������\������
267     const int len = GetWindowTextLength(hWnd);
268     #if 0
269     if (len > 0) {
270     // ���[�U�[�������������ATAB����������������������������������������������
271     // ���������x�����������������������ATAB�X�g�b�v�s�v���|��
272     data->tab_focus_entered = 1;
273     }
274     #endif
275     if ((data->str_len == 0 && len != 0) ||
276     (data->str_len != 0 && len == 0)) {
277     // ���[�U�[������������ 0������ or 0������������ ����������
278     const HWND dlg = GetParent(hWnd);
279     const HWND hWndOption = GetDlgItem(dlg, IDC_USERNAME_OPTION);
280     LONG_PTR style = GetWindowLongPtr(hWndOption, GWL_STYLE);
281    
282     if (len > 0) {
283     // �s�vtabstop
284     style = style & (~(LONG_PTR)WS_TABSTOP);
285     }
286     else {
287     // �vtabstop
288     style = style | WS_TABSTOP;
289     }
290     SetWindowLongPtr(hWndOption, GWL_STYLE, style);
291     data->str_len = len;
292     }
293 zmatsuo 7639 }
294 yutakapon 8218 break;
295     case WM_NCDESTROY:
296     free(data);
297     break;
298 zmatsuo 7639 }
299     return result;
300     }
301    
302 zmatsuo 7632 static void init_auth_dlg(PTInstVar pvar, HWND dlg, BOOL *UseControlChar)
303 maya 3227 {
304 zmatsuo 7632 const static DlgTextInfo text_info[] = {
305     { 0, "DLG_AUTH_TITLE" },
306     { IDC_SSHAUTHBANNER, "DLG_AUTH_BANNER" },
307     { IDC_SSHAUTHBANNER2, "DLG_AUTH_BANNER2" },
308     { IDC_SSHUSERNAMELABEL, "DLG_AUTH_USERNAME" },
309     { IDC_SSHPASSWORDCAPTION, "DLG_AUTH_PASSWORD" },
310     { IDC_REMEMBER_PASSWORD, "DLG_AUTH_REMEMBER_PASSWORD" },
311     { IDC_FORWARD_AGENT, "DLG_AUTH_FWDAGENT" },
312 maya 8046 { IDC_SSHAUTHMETHOD, "DLG_AUTH_METHOD" },
313 zmatsuo 7632 { IDC_SSHUSEPASSWORD, "DLG_AUTH_METHOD_PASSWORD" },
314     { IDC_SSHUSERSA, "DLG_AUTH_METHOD_RSA" },
315     { IDC_SSHUSERHOSTS, "DLG_AUTH_METHOD_RHOST" },
316     { IDC_SSHUSEPAGEANT, "DLG_AUTH_METHOD_PAGEANT" },
317     { IDC_RSAFILENAMELABEL, "DLG_AUTH_PRIVATEKEY" },
318     { IDC_LOCALUSERNAMELABEL, "DLG_AUTH_LOCALUSER" },
319     { IDC_HOSTRSAFILENAMELABEL, "DLG_AUTH_HOST_PRIVATEKEY" },
320     { IDOK, "BTN_OK" },
321     { IDCANCEL, "BTN_DISCONNECT" },
322     };
323 maya 3227 int default_method = pvar->session_settings.DefaultAuthMethod;
324    
325 zmatsuo 7632 SetI18DlgStrs("TTSSH", dlg, text_info, _countof(text_info), pvar->ts->UILanguageFile);
326 maya 3227
327     init_auth_machine_banner(pvar, dlg);
328 zmatsuo 7632 init_password_control(pvar, dlg, IDC_SSHPASSWORD, UseControlChar);
329 maya 3227
330 maya 3342 // �F�����s�������x������������
331 maya 3227 if (pvar->auth_state.failed_method != SSH_AUTH_NONE) {
332     /* must be retrying a failed attempt */
333     UTIL_get_lang_msg("DLG_AUTH_BANNER2_FAILED", pvar, "Authentication failed. Please retry.");
334     SetDlgItemText(dlg, IDC_SSHAUTHBANNER2, pvar->ts->UIMsg);
335     UTIL_get_lang_msg("DLG_AUTH_TITLE_FAILED", pvar, "Retrying SSH Authentication");
336     SetWindowText(dlg, pvar->ts->UIMsg);
337     default_method = pvar->auth_state.failed_method;
338     }
339    
340 maya 3342 // �p�X���[�h���o���������`�F�b�N�{�b�N�X�����f�t�H���g���L�������� (2006.8.3 yutaka)
341     if (pvar->ts_SSH->remember_password) {
342     SendMessage(GetDlgItem(dlg, IDC_REMEMBER_PASSWORD), BM_SETCHECK, BST_CHECKED, 0);
343     } else {
344     SendMessage(GetDlgItem(dlg, IDC_REMEMBER_PASSWORD), BM_SETCHECK, BST_UNCHECKED, 0);
345     }
346 maya 3227
347 maya 3342 // ForwardAgent �����������f���� (2008.12.4 maya)
348     CheckDlgButton(dlg, IDC_FORWARD_AGENT, pvar->settings.ForwardAgent);
349    
350     // SSH �o�[�W������������ TIS �����x������������
351     if (pvar->settings.ssh_protocol_version == 1) {
352     UTIL_get_lang_msg("DLG_AUTH_METHOD_CHALLENGE1", pvar,
353 doda 7101 "Use challenge/response(&TIS) to log in");
354 maya 3342 SetDlgItemText(dlg, IDC_SSHUSETIS, pvar->ts->UIMsg);
355     } else {
356     UTIL_get_lang_msg("DLG_AUTH_METHOD_CHALLENGE2", pvar,
357 doda 7101 "Use keyboard-&interactive to log in");
358 maya 3342 SetDlgItemText(dlg, IDC_SSHUSETIS, pvar->ts->UIMsg);
359 maya 3227 }
360    
361 zmatsuo 7639 // username���T�u�N���X��
362     {
363     HWND hWndUserName = GetDlgItem(dlg, IDC_SSHUSERNAME);
364 yutakapon 8218 username_proc_data_t *data = (username_proc_data_t *)malloc(sizeof(username_proc_data_t));
365     if (data != NULL) {
366     SetWindowLongPtr(hWndUserName, GWLP_USERDATA, (LONG_PTR)data);
367     data->tab_focus_entered = 0;
368     data->str_len = 0;
369     data->proc_org =
370     (WNDPROC)SetWindowLongPtr(hWndUserName, GWLP_WNDPROC, (LONG_PTR)username_proc);
371     }
372 zmatsuo 7639 }
373    
374 maya 3227 if (pvar->auth_state.user != NULL) {
375     SetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->auth_state.user);
376     EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAME), FALSE);
377 zmatsuo 7632 EnableWindow(GetDlgItem(dlg, IDC_USERNAME_OPTION), FALSE);
378 maya 3227 EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAMELABEL), FALSE);
379 maya 3342 }
380 maya 4759 else if (strlen(pvar->ssh2_username) > 0) {
381 maya 3342 SetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->ssh2_username);
382     if (pvar->ssh2_autologin == 1) {
383     EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAME), FALSE);
384 zmatsuo 7632 EnableWindow(GetDlgItem(dlg, IDC_USERNAME_OPTION), FALSE);
385 maya 3342 EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAMELABEL), FALSE);
386     }
387     }
388 zmatsuo 7632 else {
389     switch(pvar->session_settings.DefaultUserType) {
390     case 0:
391     // ����������
392     break;
393     case 1:
394     // use DefaultUserName
395     if (pvar->session_settings.DefaultUserName[0] == 0) {
396     // �u�����������v����������
397     pvar->session_settings.DefaultUserType = 0;
398     } else {
399     SetDlgItemText(dlg, IDC_SSHUSERNAME,
400     pvar->session_settings.DefaultUserName);
401     }
402     break;
403     case 2: {
404     TCHAR user_name[UNLEN+1];
405     DWORD len = _countof(user_name);
406     BOOL r = GetUserName(user_name, &len);
407     if (r != 0) {
408     SetDlgItemText(dlg, IDC_SSHUSERNAME, user_name);
409     }
410     break;
411     }
412     default:
413     // ��������������������
414     pvar->session_settings.DefaultUserType = 0;
415     }
416 maya 3227 }
417    
418 maya 3342 if (strlen(pvar->ssh2_password) > 0) {
419     SetDlgItemText(dlg, IDC_SSHPASSWORD, pvar->ssh2_password);
420     if (pvar->ssh2_autologin == 1) {
421     EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD), FALSE);
422     EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORDCAPTION), FALSE);
423 zmatsuo 7632 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD_OPTION), FALSE);
424 maya 3342 }
425     }
426    
427 maya 3227 SetDlgItemText(dlg, IDC_RSAFILENAME,
428     pvar->session_settings.DefaultRSAPrivateKeyFile);
429     SetDlgItemText(dlg, IDC_HOSTRSAFILENAME,
430     pvar->session_settings.DefaultRhostsHostPrivateKeyFile);
431     SetDlgItemText(dlg, IDC_LOCALUSERNAME,
432     pvar->session_settings.DefaultRhostsLocalUserName);
433    
434 maya 3342 if (pvar->ssh2_authmethod == SSH_AUTH_PASSWORD) {
435     CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, IDC_SSHUSEPASSWORD);
436 maya 3227
437 maya 3342 } else if (pvar->ssh2_authmethod == SSH_AUTH_RSA) {
438     CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, IDC_SSHUSERSA);
439 maya 3227
440 maya 3342 SetDlgItemText(dlg, IDC_RSAFILENAME, pvar->ssh2_keyfile);
441 maya 3227 if (pvar->ssh2_autologin == 1) {
442 maya 3342 EnableWindow(GetDlgItem(dlg, IDC_CHOOSERSAFILE), FALSE);
443     EnableWindow(GetDlgItem(dlg, IDC_RSAFILENAME), FALSE);
444 maya 3227 }
445    
446 maya 3342 // /auth=challenge ������ (2007.10.5 maya)
447     } else if (pvar->ssh2_authmethod == SSH_AUTH_TIS) {
448     CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, IDC_SSHUSETIS);
449     EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD), FALSE);
450 zmatsuo 7632 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD_OPTION), FALSE);
451 maya 3342 SetDlgItemText(dlg, IDC_SSHPASSWORD, "");
452 maya 3227
453 maya 3342 // /auth=pageant ������
454     } else if (pvar->ssh2_authmethod == SSH_AUTH_PAGEANT) {
455     CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, IDC_SSHUSEPAGEANT);
456     EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD), FALSE);
457 zmatsuo 7632 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD_OPTION), FALSE);
458 maya 3342 SetDlgItemText(dlg, IDC_SSHPASSWORD, "");
459 maya 3227
460 maya 3342 } else {
461     // �f�t�H���g���F�����\�b�h���_�C�A���O�����f
462     set_auth_options_status(dlg, auth_types_to_control_IDs[default_method]);
463 maya 3227
464 maya 3342 update_server_supported_types(pvar, dlg);
465 maya 3227
466 maya 3342 // �z�X�g�m�F�_�C�A���O��������������=�E�B���h�E���A�N�e�B�u������������
467     // �� SetFocus �����s�����A�R�}���h���C�����n�������F��������������������
468     // �����������A�������O�C���L������ SetFocus ������ (2009.1.31 maya)
469     if (default_method == SSH_AUTH_TIS) {
470     /* we disabled the password control, so fix the focus */
471     SetFocus(GetDlgItem(dlg, IDC_SSHUSETIS));
472 maya 3227 }
473 maya 3342 else if (default_method == SSH_AUTH_PAGEANT) {
474     SetFocus(GetDlgItem(dlg, IDC_SSHUSEPAGEANT));
475     }
476 maya 3227
477     }
478    
479 maya 3342 if (GetWindowTextLength(GetDlgItem(dlg, IDC_SSHUSERNAME)) == 0) {
480     SetFocus(GetDlgItem(dlg, IDC_SSHUSERNAME));
481 maya 3227 }
482 maya 3342 else if (pvar->ask4passwd == 1) {
483     SetFocus(GetDlgItem(dlg, IDC_SSHPASSWORD));
484     }
485 maya 3227
486 maya 3342 // '/I' �w�������������������������� (2005.9.5 yutaka)
487     if (pvar->ts->Minimize) {
488     //20050822���� start T.Takahashi
489     ShowWindow(dlg,SW_MINIMIZE);
490     //20050822���� end T.Takahashi
491 maya 3227 }
492     }
493    
494 doda 6801 static char *alloc_control_text(HWND ctl)
495 maya 3227 {
496     int len = GetWindowTextLength(ctl);
497 doda 6801 char *result = malloc(len + 1);
498 maya 3227
499     if (result != NULL) {
500     GetWindowText(ctl, result, len + 1);
501     result[len] = 0;
502     }
503    
504     return result;
505     }
506    
507 doda 6801 static int get_key_file_name(HWND parent, char *buf, int bufsize, PTInstVar pvar)
508 maya 3227 {
509     OPENFILENAME params;
510     char fullname_buf[2048] = "identity";
511     char filter[MAX_UIMSG];
512    
513     ZeroMemory(&params, sizeof(params));
514 zmatsuo 7360 params.lStructSize = get_OPENFILENAME_SIZE();
515 maya 3227 params.hwndOwner = parent;
516     // �t�B���^������ (2004.12.19 yutaka)
517     // 3�t�@�C���t�B���^������ (2005.4.26 yutaka)
518     UTIL_get_lang_msg("FILEDLG_OPEN_PRIVATEKEY_FILTER", pvar,
519 doda 7373 "identity files\\0identity;id_rsa;id_dsa;id_ecdsa;id_ed25519;*.ppk;*.pem\\0identity(RSA1)\\0identity\\0id_rsa(SSH2)\\0id_rsa\\0id_dsa(SSH2)\\0id_dsa\\0id_ecdsa(SSH2)\\0id_ecdsa\\0id_ed25519(SSH2)\\0id_ed25519\\0PuTTY(*.ppk)\\0*.ppk\\0PEM files(*.pem)\\0*.pem\\0all(*.*)\\0*.*\\0\\0");
520 maya 3227 memcpy(filter, pvar->ts->UIMsg, sizeof(filter));
521     params.lpstrFilter = filter;
522     params.lpstrCustomFilter = NULL;
523     params.nFilterIndex = 0;
524     buf[0] = 0;
525     params.lpstrFile = fullname_buf;
526     params.nMaxFile = sizeof(fullname_buf);
527     params.lpstrFileTitle = NULL;
528     params.lpstrInitialDir = NULL;
529     UTIL_get_lang_msg("FILEDLG_OPEN_PRIVATEKEY_TITLE", pvar,
530 maya 5553 "Choose a file with the RSA/DSA/ECDSA/ED25519 private key");
531 maya 3227 params.lpstrTitle = pvar->ts->UIMsg;
532 maya 7775 params.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
533 maya 3227 params.lpstrDefExt = NULL;
534    
535     if (GetOpenFileName(&params) != 0) {
536     copy_teraterm_dir_relative_path(buf, bufsize, fullname_buf);
537     return 1;
538     } else {
539     return 0;
540     }
541     }
542    
543     static void choose_RSA_key_file(HWND dlg, PTInstVar pvar)
544     {
545     char buf[1024];
546    
547     if (get_key_file_name(dlg, buf, sizeof(buf), pvar)) {
548     SetDlgItemText(dlg, IDC_RSAFILENAME, buf);
549     }
550     }
551    
552     static void choose_host_RSA_key_file(HWND dlg, PTInstVar pvar)
553     {
554     char buf[1024];
555    
556     if (get_key_file_name(dlg, buf, sizeof(buf), pvar)) {
557     SetDlgItemText(dlg, IDC_HOSTRSAFILENAME, buf);
558     }
559     }
560    
561     static BOOL end_auth_dlg(PTInstVar pvar, HWND dlg)
562     {
563     int method = SSH_AUTH_PASSWORD;
564 doda 6801 char *password =
565 maya 3227 alloc_control_text(GetDlgItem(dlg, IDC_SSHPASSWORD));
566 maya 4307 Key *key_pair = NULL;
567 maya 3227
568     if (IsDlgButtonChecked(dlg, IDC_SSHUSERSA)) {
569     method = SSH_AUTH_RSA;
570     } else if (IsDlgButtonChecked(dlg, IDC_SSHUSERHOSTS)) {
571     if (GetWindowTextLength(GetDlgItem(dlg, IDC_HOSTRSAFILENAME)) > 0) {
572     method = SSH_AUTH_RHOSTS_RSA;
573     } else {
574     method = SSH_AUTH_RHOSTS;
575     }
576     } else if (IsDlgButtonChecked(dlg, IDC_SSHUSETIS)) {
577     method = SSH_AUTH_TIS;
578     } else if (IsDlgButtonChecked(dlg, IDC_SSHUSEPAGEANT)) {
579     method = SSH_AUTH_PAGEANT;
580     }
581    
582     if (method == SSH_AUTH_RSA || method == SSH_AUTH_RHOSTS_RSA) {
583 maya 5767 char keyfile[2048];
584 maya 3227 int file_ctl_ID =
585     method == SSH_AUTH_RSA ? IDC_RSAFILENAME : IDC_HOSTRSAFILENAME;
586    
587 maya 5767 keyfile[0] = 0;
588     GetDlgItemText(dlg, file_ctl_ID, keyfile, sizeof(keyfile));
589     if (keyfile[0] == 0) {
590 maya 3227 UTIL_get_lang_msg("MSG_KEYSPECIFY_ERROR", pvar,
591 maya 5553 "You must specify a file containing the RSA/DSA/ECDSA/ED25519 private key.");
592 maya 3227 notify_nonfatal_error(pvar, pvar->ts->UIMsg);
593     SetFocus(GetDlgItem(dlg, file_ctl_ID));
594     destroy_malloced_string(&password);
595     return FALSE;
596     }
597    
598     if (SSHv1(pvar)) {
599     BOOL invalid_passphrase = FALSE;
600    
601 maya 5767 key_pair = KEYFILES_read_private_key(pvar, keyfile, password,
602 maya 3227 &invalid_passphrase,
603     FALSE);
604    
605     if (key_pair == NULL) {
606     if (invalid_passphrase) {
607     HWND passwordCtl = GetDlgItem(dlg, IDC_SSHPASSWORD);
608    
609     SetFocus(passwordCtl);
610     SendMessage(passwordCtl, EM_SETSEL, 0, -1);
611     } else {
612     SetFocus(GetDlgItem(dlg, file_ctl_ID));
613     }
614     destroy_malloced_string(&password);
615     return FALSE;
616     }
617    
618     } else { // SSH2(yutaka)
619     BOOL invalid_passphrase = FALSE;
620     char errmsg[256];
621 maya 5056 FILE *fp = NULL;
622     ssh2_keyfile_type keyfile_type;
623 maya 3227
624     memset(errmsg, 0, sizeof(errmsg));
625    
626 maya 5767 keyfile_type = get_ssh2_keytype(keyfile, &fp, errmsg, sizeof(errmsg));
627 maya 5056 switch (keyfile_type) {
628     case SSH2_KEYFILE_TYPE_OPENSSH:
629     {
630     key_pair = read_SSH2_private_key(pvar, fp, password,
631     &invalid_passphrase,
632     FALSE,
633     errmsg,
634     sizeof(errmsg)
635     );
636     break;
637     }
638     case SSH2_KEYFILE_TYPE_PUTTY:
639     {
640     key_pair = read_SSH2_PuTTY_private_key(pvar, fp, password,
641     &invalid_passphrase,
642     FALSE,
643     errmsg,
644     sizeof(errmsg)
645     );
646     break;
647     }
648     case SSH2_KEYFILE_TYPE_SECSH:
649     {
650     key_pair = read_SSH2_SECSH_private_key(pvar, fp, password,
651     &invalid_passphrase,
652     FALSE,
653     errmsg,
654     sizeof(errmsg)
655     );
656     break;
657     }
658     default:
659     {
660     char buf[1024];
661 maya 5552
662     // �t�@�C�����J�����������t�@�C���`�����s��������������������
663     if (fp != NULL) {
664     key_pair = read_SSH2_private_key(pvar, fp, password,
665     &invalid_passphrase,
666     FALSE,
667     errmsg,
668     sizeof(errmsg)
669     );
670     break;
671     }
672    
673 maya 5056 UTIL_get_lang_msg("MSG_READKEY_ERROR", pvar,
674     "read error SSH2 private key file\r\n%s");
675     _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg, errmsg);
676     notify_nonfatal_error(pvar, buf);
677 maya 5552 // ���������������������� SSH2 �������t�@�C�����J����������
678 maya 5056 // ���t�@�C�����I���{�^�����t�H�[�J�X������
679     SetFocus(GetDlgItem(dlg, IDC_CHOOSERSAFILE));
680     destroy_malloced_string(&password);
681     return FALSE;
682     }
683     }
684 maya 3227
685     if (key_pair == NULL) { // read error
686     char buf[1024];
687     UTIL_get_lang_msg("MSG_READKEY_ERROR", pvar,
688     "read error SSH2 private key file\r\n%s");
689     _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg, errmsg);
690     notify_nonfatal_error(pvar, buf);
691     // �p�X�t���[�Y���������v����������������IDC_SSHPASSWORD���t�H�[�J�X������ (2006.10.29 yasuhide)
692     if (invalid_passphrase) {
693     HWND passwordCtl = GetDlgItem(dlg, IDC_SSHPASSWORD);
694    
695     SetFocus(passwordCtl);
696     SendMessage(passwordCtl, EM_SETSEL, 0, -1);
697     } else {
698     SetFocus(GetDlgItem(dlg, file_ctl_ID));
699     }
700     destroy_malloced_string(&password);
701     return FALSE;
702     }
703    
704     }
705    
706     }
707     else if (method == SSH_AUTH_PAGEANT) {
708     pvar->pageant_key = NULL;
709     pvar->pageant_curkey = NULL;
710     pvar->pageant_keylistlen = 0;
711     pvar->pageant_keycount = 0;
712     pvar->pageant_keycurrent = 0;
713     pvar->pageant_keyfinal=FALSE;
714    
715     // Pageant �����M
716     if (SSHv1(pvar)) {
717     pvar->pageant_keylistlen = putty_get_ssh1_keylist(&pvar->pageant_key);
718     }
719     else {
720     pvar->pageant_keylistlen = putty_get_ssh2_keylist(&pvar->pageant_key);
721     }
722     if (pvar->pageant_keylistlen == 0) {
723     UTIL_get_lang_msg("MSG_PAGEANT_NOTFOUND", pvar,
724     "Can't find Pageant.");
725     notify_nonfatal_error(pvar, pvar->ts->UIMsg);
726    
727     return FALSE;
728     }
729     pvar->pageant_curkey = pvar->pageant_key;
730    
731     // ������
732     pvar->pageant_keycount = get_uint32_MSBfirst(pvar->pageant_curkey);
733     if (pvar->pageant_keycount == 0) {
734     UTIL_get_lang_msg("MSG_PAGEANT_NOKEY", pvar,
735     "Pageant has no valid key.");
736     notify_nonfatal_error(pvar, pvar->ts->UIMsg);
737    
738     return FALSE;
739     }
740     pvar->pageant_curkey += 4;
741     }
742    
743     /* from here on, we cannot fail, so just munge cur_cred in place */
744     pvar->auth_state.cur_cred.method = method;
745     pvar->auth_state.cur_cred.key_pair = key_pair;
746     /* we can't change the user name once it's set. It may already have
747     been sent to the server, and it can only be sent once. */
748     if (pvar->auth_state.user == NULL) {
749     pvar->auth_state.user =
750     alloc_control_text(GetDlgItem(dlg, IDC_SSHUSERNAME));
751     }
752    
753     // �p�X���[�h���������������������������� (2006.8.3 yutaka)
754     if (SendMessage(GetDlgItem(dlg, IDC_REMEMBER_PASSWORD), BM_GETCHECK, 0,0) == BST_CHECKED) {
755     pvar->settings.remember_password = 1; // �o��������
756     pvar->ts_SSH->remember_password = 1;
757     } else {
758     pvar->settings.remember_password = 0; // ���������������Y����
759     pvar->ts_SSH->remember_password = 0;
760     }
761    
762     // ���J���F���������A�Z�b�V�������������p�X���[�h���g�����������������������������������B
763     // (2005.4.8 yutaka)
764     if (method == SSH_AUTH_PASSWORD || method == SSH_AUTH_RSA) {
765     pvar->auth_state.cur_cred.password = password;
766     } else {
767     destroy_malloced_string(&password);
768     }
769     if (method == SSH_AUTH_RHOSTS || method == SSH_AUTH_RHOSTS_RSA) {
770     if (pvar->session_settings.DefaultAuthMethod != SSH_AUTH_RHOSTS) {
771     UTIL_get_lang_msg("MSG_RHOSTS_NOTDEFAULT_ERROR", pvar,
772     "Rhosts authentication will probably fail because it was not "
773     "the default authentication method.\n"
774     "To use Rhosts authentication "
775     "in TTSSH, you need to set it to be the default by restarting\n"
776 yutakapon 6019 "TTSSH and selecting \"SSH Authentication...\" from the Setup menu "
777 maya 3227 "before connecting.");
778     notify_nonfatal_error(pvar, pvar->ts->UIMsg);
779     }
780    
781     pvar->auth_state.cur_cred.rhosts_client_user =
782     alloc_control_text(GetDlgItem(dlg, IDC_LOCALUSERNAME));
783     }
784     pvar->auth_state.auth_dialog = NULL;
785    
786     GetDlgItemText(dlg, IDC_RSAFILENAME,
787     pvar->session_settings.DefaultRSAPrivateKeyFile,
788     sizeof(pvar->session_settings.
789     DefaultRSAPrivateKeyFile));
790     GetDlgItemText(dlg, IDC_HOSTRSAFILENAME,
791     pvar->session_settings.DefaultRhostsHostPrivateKeyFile,
792     sizeof(pvar->session_settings.
793     DefaultRhostsHostPrivateKeyFile));
794     GetDlgItemText(dlg, IDC_LOCALUSERNAME,
795     pvar->session_settings.DefaultRhostsLocalUserName,
796     sizeof(pvar->session_settings.
797     DefaultRhostsLocalUserName));
798    
799     if (SSHv1(pvar)) {
800     SSH_notify_user_name(pvar);
801     SSH_notify_cred(pvar);
802     } else {
803     // for SSH2(yutaka)
804     do_SSH2_userauth(pvar);
805     }
806    
807     EndDialog(dlg, 1);
808    
809     return TRUE;
810     }
811    
812 zmatsuo 7507 /**
813     * �N���b�v�{�[�h����ANSI����������������
814     * �����������K�v��������strlen()��������
815     * @param hWnd
816     * @param emtpy TRUE�������N���b�v�{�[�h����������
817     * @retval �����������|�C���^ �g�p��free()��������
818     * ����������(�������G���[��)��NULL
819     */
820     char *GetClipboardTextA(HWND hWnd, BOOL empty)
821     {
822     HGLOBAL hGlobal;
823     const char *lpStr;
824     size_t length;
825     char *pool;
826    
827     OpenClipboard(hWnd);
828     hGlobal = (HGLOBAL)GetClipboardData(CF_TEXT);
829     if (hGlobal == NULL) {
830     CloseClipboard();
831     return NULL;
832     }
833     lpStr = (const char *)GlobalLock(hGlobal);
834     length = GlobalSize(hGlobal);
835     if (length == 0) {
836     pool = NULL;
837     } else {
838     pool = (char *)malloc(length + 1); // +1 for terminator
839     memcpy(pool, lpStr, length);
840     pool[length] = '\0';
841     }
842     GlobalUnlock(hGlobal);
843     if (empty) {
844     EmptyClipboard();
845     }
846     CloseClipboard();
847    
848     return pool;
849     }
850    
851    
852 maya 3227 BOOL autologin_sent_none;
853 zmatsuo 7896 static INT_PTR CALLBACK auth_dlg_proc(HWND dlg, UINT msg, WPARAM wParam,
854     LPARAM lParam)
855 maya 3227 {
856 maya 3342 const int IDC_TIMER1 = 300; // �������O�C�����L��������
857     const int IDC_TIMER2 = 301; // �T�|�[�g�������������\�b�h�������`�F�b�N(CheckAuthListFirst)
858     const int IDC_TIMER3 = 302; // challenge �� ask4passwd ��CheckAuthListFirst �� FALSE ������
859 maya 3227 const int autologin_timeout = 10; // �~���b
860     PTInstVar pvar;
861 zmatsuo 7632 static BOOL UseControlChar;
862     static BOOL ShowPassPhrase;
863 zmatsuo 7634 static HICON hIconDropdown;
864 zmatsuo 7730 TCHAR uimsg[MAX_UIMSG];
865 maya 3227
866     switch (msg) {
867     case WM_INITDIALOG:
868     pvar = (PTInstVar) lParam;
869     pvar->auth_state.auth_dialog = dlg;
870 zmatsuo 7896 SetWindowLongPtr(dlg, DWLP_USER, lParam);
871 maya 3227
872 zmatsuo 7632 UseControlChar = TRUE;
873     ShowPassPhrase = FALSE;
874     init_auth_dlg(pvar, dlg, &UseControlChar);
875 zmatsuo 7703
876 zmatsuo 7639 // "��"�������Z�b�g����
877 zmatsuo 7634 hIconDropdown = LoadImage(hInst, MAKEINTRESOURCE(IDI_DROPDOWN),
878     IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
879     SendMessage(GetDlgItem(dlg, IDC_USERNAME_OPTION), BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIconDropdown);
880     SendMessage(GetDlgItem(dlg, IDC_SSHPASSWORD_OPTION), BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIconDropdown);
881 zmatsuo 7632
882 maya 3227 // SSH2 autologin���L�����������A�^�C�}���d�|�����B (2004.12.1 yutaka)
883     if (pvar->ssh2_autologin == 1) {
884     autologin_sent_none = FALSE;
885     SetTimer(dlg, IDC_TIMER1, autologin_timeout, 0);
886     }
887     else {
888     // �T�|�[�g�������������\�b�h���`�F�b�N�����B(2007.9.24 maya)
889     // �������L�����A�����������s�����������A���[�U�����m����������
890     if (pvar->session_settings.CheckAuthListFirst &&
891     !pvar->tryed_ssh2_authlist &&
892     GetWindowTextLength(GetDlgItem(dlg, IDC_SSHUSERNAME)) > 0) {
893     SetTimer(dlg, IDC_TIMER2, autologin_timeout, 0);
894     }
895 maya 3342 // /auth=challenge �� /ask4passwd ���w���������������[�U�����m����������
896     // �������AOK �{�^���������� TIS auth �_�C�A���O���o��
897     else if (pvar->ssh2_authmethod == SSH_AUTH_TIS &&
898     pvar->ask4passwd &&
899     GetWindowTextLength(GetDlgItem(dlg, IDC_SSHUSERNAME)) > 0) {
900 maya 3227 SetTimer(dlg, IDC_TIMER3, autologin_timeout, 0);
901     }
902     }
903 zmatsuo 7592 CenterWindow(dlg, GetParent(dlg));
904 maya 3227 return FALSE; /* because we set the focus */
905    
906     case WM_TIMER:
907 zmatsuo 7896 pvar = (PTInstVar) GetWindowLongPtr(dlg, DWLP_USER);
908 maya 3227 // �F�������������������A�F���f�[�^�����M�����B�����������A�������B(2004.12.16 yutaka)
909     if (wParam == IDC_TIMER1) {
910     // �������O�C��������
911     if (!(pvar->ssh_state.status_flags & STATUS_DONT_SEND_USER_NAME) &&
912     (pvar->ssh_state.status_flags & STATUS_HOST_OK)) {
913     if (SSHv2(pvar) &&
914     pvar->session_settings.CheckAuthListFirst &&
915     !pvar->tryed_ssh2_authlist) {
916     if (!autologin_sent_none) {
917 maya 3342 autologin_sent_none = TRUE;
918    
919 maya 3336 // �_�C�A���O�����[�U������������
920     if (pvar->auth_state.user == NULL) {
921     pvar->auth_state.user =
922     alloc_control_text(GetDlgItem(dlg, IDC_SSHUSERNAME));
923     }
924    
925 maya 3342 // CheckAuthListFirst �� TRUE �������� AuthList ���A����������������
926     // IDOK �����������i�����������A�F�����\�b�h none ������ (2008.10.12 maya)
927 maya 3227 do_SSH2_userauth(pvar);
928     }
929     //else {
930     // none �������������A����������������
931     //}
932     }
933     else {
934 maya 3342 // SSH1 ������
935     // ������ CheckAuthListFirst �� FALSE ������
936     // ������ CheckAuthListFirst TRUE ���Aauthlist ���A������������
937 maya 3346 KillTimer(dlg, IDC_TIMER1);
938 maya 3342
939     // �_�C�A���O�����[�U������������
940     if (pvar->auth_state.user == NULL) {
941     pvar->auth_state.user =
942     alloc_control_text(GetDlgItem(dlg, IDC_SSHUSERNAME));
943     }
944    
945 maya 3227 SendMessage(dlg, WM_COMMAND, IDOK, 0);
946     }
947     }
948     }
949     else if (wParam == IDC_TIMER2) {
950     // authlist ����������
951 maya 3346 if (!(pvar->ssh_state.status_flags & STATUS_DONT_SEND_USER_NAME) &&
952     (pvar->ssh_state.status_flags & STATUS_HOST_OK)) {
953     if (SSHv2(pvar)) {
954 maya 3227 KillTimer(dlg, IDC_TIMER2);
955    
956     // �_�C�A���O�����[�U������������
957     if (pvar->auth_state.user == NULL) {
958     pvar->auth_state.user =
959     alloc_control_text(GetDlgItem(dlg, IDC_SSHUSERNAME));
960     }
961    
962     // ���[�U�������X��������
963     EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAME), FALSE);
964 zmatsuo 7632 EnableWindow(GetDlgItem(dlg, IDC_USERNAME_OPTION), FALSE);
965 maya 3227
966 maya 3342 // �F�����\�b�h none ������
967 maya 3227 do_SSH2_userauth(pvar);
968    
969 maya 3342 // TIS �p�� OK �����������F�������s������������������
970 maya 3227 // Unexpected SSH2 message �������B
971     }
972 maya 3346 else if (SSHv1(pvar)) {
973     KillTimer(dlg, IDC_TIMER2);
974    
975     // TIS �p�� OK ������
976     if (pvar->ssh2_authmethod == SSH_AUTH_TIS) {
977     SendMessage(dlg, WM_COMMAND, IDOK, 0);
978     }
979     // SSH1 �����F�����\�b�h none ����������
980 maya 3227 }
981 maya 3346 // �v���g�R���o�[�W�����m���O������������
982 maya 3227 }
983     }
984     else if (wParam == IDC_TIMER3) {
985 maya 3346 if (!(pvar->ssh_state.status_flags & STATUS_DONT_SEND_USER_NAME) &&
986     (pvar->ssh_state.status_flags & STATUS_HOST_OK)) {
987     if (SSHv2(pvar) || SSHv1(pvar)) {
988     KillTimer(dlg, IDC_TIMER3);
989    
990     // TIS �p�� OK ������
991     SendMessage(dlg, WM_COMMAND, IDOK, 0);
992 maya 3227 }
993 maya 3346 // �v���g�R���o�[�W�����m���O������������
994 maya 3227 }
995     }
996     return FALSE;
997    
998     case WM_COMMAND:
999 zmatsuo 7896 pvar = (PTInstVar) GetWindowLongPtr(dlg, DWLP_USER);
1000 maya 3227
1001     switch (LOWORD(wParam)) {
1002     case IDOK:
1003 yutakapon 5562 // �F�������T�[�o�������f�������������A�L�����Z�������������B(2014.3.31 yutaka)
1004     if (!pvar->cv->Ready) {
1005     goto canceled;
1006     }
1007    
1008 maya 3227 // �F�������������������A�F���f�[�^�����M�����B�����������A�������B(2001.1.25 yutaka)
1009     if (pvar->userauth_retry_count == 0 &&
1010     ((pvar->ssh_state.status_flags & STATUS_DONT_SEND_USER_NAME) ||
1011     !(pvar->ssh_state.status_flags & STATUS_HOST_OK))) {
1012     return FALSE;
1013     }
1014     else if (SSHv2(pvar) &&
1015     pvar->session_settings.CheckAuthListFirst &&
1016     !pvar->tryed_ssh2_authlist) {
1017     // CheckAuthListFirst ���L�����F������������������������
1018     // OK �������������������� (2008.10.4 maya)
1019     return FALSE;
1020     }
1021    
1022     return end_auth_dlg(pvar, dlg);
1023    
1024     case IDCANCEL: /* kill the connection */
1025 yutakapon 5562 canceled:
1026 maya 3227 pvar->auth_state.auth_dialog = NULL;
1027 maya 5678 notify_closed_connection(pvar, "authentication cancelled");
1028 maya 3227 EndDialog(dlg, 0);
1029     return TRUE;
1030    
1031 yutakapon 8093 case IDCLOSE:
1032     // �F�������l�b�g���[�N���f�����������A���Y���b�Z�[�W���_�C�A���O���������B
1033     pvar->auth_state.auth_dialog = NULL;
1034     EndDialog(dlg, 0);
1035     return TRUE;
1036    
1037 maya 3227 case IDC_SSHUSERNAME:
1038     // ���[�U�����t�H�[�J�X������������ (2007.9.29 maya)
1039     if (!(pvar->ssh_state.status_flags & STATUS_DONT_SEND_USER_NAME) &&
1040     (pvar->ssh_state.status_flags & STATUS_HOST_OK) &&
1041     HIWORD(wParam) == EN_KILLFOCUS) {
1042     // �������L���������������s��������������
1043     if (SSHv2(pvar) &&
1044     pvar->session_settings.CheckAuthListFirst &&
1045     !pvar->tryed_ssh2_authlist) {
1046     // �_�C�A���O�����[�U�������f
1047     if (pvar->auth_state.user == NULL) {
1048     pvar->auth_state.user =
1049     alloc_control_text(GetDlgItem(dlg, IDC_SSHUSERNAME));
1050     }
1051    
1052     // ���[�U���������������������`�F�b�N����
1053     if (strlen(pvar->auth_state.user) == 0) {
1054     return FALSE;
1055     }
1056    
1057     // ���[�U�������X��������
1058     EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAME), FALSE);
1059 zmatsuo 7632 EnableWindow(GetDlgItem(dlg, IDC_USERNAME_OPTION), FALSE);
1060 maya 3227
1061 maya 3342 // �F�����\�b�h none ������
1062 maya 3227 do_SSH2_userauth(pvar);
1063     return TRUE;
1064     }
1065     }
1066    
1067     return FALSE;
1068    
1069     case IDC_SSHUSEPASSWORD:
1070     case IDC_SSHUSERSA:
1071     case IDC_SSHUSERHOSTS:
1072     case IDC_SSHUSETIS:
1073     case IDC_SSHUSEPAGEANT:
1074     set_auth_options_status(dlg, LOWORD(wParam));
1075     return TRUE;
1076    
1077     case IDC_CHOOSERSAFILE:
1078     choose_RSA_key_file(dlg, pvar);
1079     return TRUE;
1080    
1081     case IDC_CHOOSEHOSTRSAFILE:
1082     choose_host_RSA_key_file(dlg, pvar);
1083     return TRUE;
1084    
1085     case IDC_FORWARD_AGENT:
1086     // �����Z�b�V�������������f������ (2008.12.4 maya)
1087     pvar->session_settings.ForwardAgent = IsDlgButtonChecked(dlg, IDC_FORWARD_AGENT);
1088     return TRUE;
1089    
1090 zmatsuo 7632 case IDC_SSHPASSWORD_OPTION: {
1091 zmatsuo 7635 RECT rect;
1092     HWND hWndButton;
1093     int result;
1094 zmatsuo 7632 HMENU hMenu= CreatePopupMenu();
1095 zmatsuo 7636 char *clipboard = GetClipboardTextA(dlg, FALSE);
1096 zmatsuo 7632 GetI18nStrT("TTSSH", "DLG_AUTH_PASTE_CLIPBOARD",
1097     uimsg, _countof(uimsg),
1098     "Paste from &clipboard",
1099     pvar->ts->UILanguageFile);
1100 zmatsuo 7636 AppendMenu(hMenu, MF_ENABLED | MF_STRING | (clipboard == NULL ? MFS_DISABLED : 0), 1, uimsg);
1101 zmatsuo 7632 GetI18nStrT("ttssh", "DLG_AUTH_CLEAR_CLIPBOARD",
1102     uimsg, _countof(uimsg),
1103     "Paste from &clipboard and cl&ear clipboard",
1104     pvar->ts->UILanguageFile);
1105 zmatsuo 7636 AppendMenu(hMenu, MF_ENABLED | MF_STRING | (clipboard == NULL ? MFS_DISABLED : 0), 2, uimsg);
1106 zmatsuo 7632 GetI18nStrT("ttssh", "DLG_AUTH_USE_CONTORL_CHARACTERS",
1107     uimsg, _countof(uimsg),
1108     "Use control charac&ters",
1109     pvar->ts->UILanguageFile);
1110     AppendMenu(hMenu, MF_ENABLED | MF_STRING | (UseControlChar ? MFS_CHECKED : 0), 3, uimsg);
1111     GetI18nStrT("ttssh", "DLG_AUTH_SHOW_PASSPHRASE",
1112     uimsg, _countof(uimsg),
1113     "&Show passphrase",
1114     pvar->ts->UILanguageFile);
1115     AppendMenu(hMenu, MF_ENABLED | MF_STRING | (ShowPassPhrase ? MFS_CHECKED : 0), 4, uimsg);
1116 zmatsuo 7636 if (clipboard != NULL) {
1117     free(clipboard);
1118     }
1119 zmatsuo 7635 hWndButton = GetDlgItem(dlg, IDC_SSHPASSWORD_OPTION);
1120 zmatsuo 7632 GetWindowRect(hWndButton, &rect);
1121 zmatsuo 7635 result = TrackPopupMenu(hMenu, TPM_RETURNCMD, rect.left, rect.bottom, 0 , hWndButton, NULL);
1122 zmatsuo 7632 DestroyMenu(hMenu);
1123     switch(result) {
1124     case 1:
1125     case 2: {
1126     // �N���b�v�{�[�h�����y�[�X�g
1127     BOOL clear_clipboard = result == 2;
1128 zmatsuo 7636 clipboard = GetClipboardTextA(dlg, clear_clipboard);
1129 zmatsuo 7632 if (clipboard != NULL) {
1130     SetDlgItemTextA(dlg, IDC_SSHPASSWORD, clipboard);
1131     free(clipboard);
1132     SendDlgItemMessage(dlg, IDC_SSHPASSWORD, EM_SETSEL, 0, -1);
1133     SendMessage(dlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(dlg, IDC_SSHPASSWORD), TRUE);
1134     return FALSE;
1135     }
1136     return TRUE;
1137 zmatsuo 7507 }
1138 zmatsuo 7632 case 3:
1139     // �����R�[�h�g�p/���g�p
1140     UseControlChar = !UseControlChar;
1141     break;
1142     case 4:
1143     // �p�X�t���[�Y�\��/���\��
1144     ShowPassPhrase = !ShowPassPhrase;
1145     {
1146     // ������ on/off ������������
1147     HWND hWnd = GetDlgItem(dlg, IDC_SSHPASSWORD);
1148     static wchar_t password_char;
1149     if (password_char == 0) {
1150     wchar_t c = (wchar_t)SendMessage(hWnd, EM_GETPASSWORDCHAR, 0, 0);
1151     password_char = c;
1152     }
1153     if (ShowPassPhrase) {
1154     SendMessage(hWnd, EM_SETPASSWORDCHAR, 0, 0);
1155     } else {
1156     #if !defined(UNICODE)
1157     if (password_char < 0x100) {
1158     SendMessageA(hWnd, EM_SETPASSWORDCHAR, (WPARAM)password_char, 0);
1159     } else {
1160     // TODO W�n������ ����������������
1161     //SendMessageW(hWnd, EM_SETPASSWORDCHAR, (WPARAM)password_char, 0);
1162     SendMessageA(hWnd, EM_SETPASSWORDCHAR, (WPARAM)'*', 0);
1163     }
1164     #else
1165     SendMessageW(hWnd, EM_SETPASSWORDCHAR, (WPARAM)password_char, 0);
1166     #endif
1167     }
1168     //InvalidateRect(hWnd, NULL, TRUE);
1169     SendDlgItemMessage(dlg, IDC_SSHPASSWORD, EM_SETSEL, 0, -1);
1170     SendMessage(dlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(dlg, IDC_SSHPASSWORD), TRUE);
1171     return TRUE;
1172     }
1173     break;
1174     }
1175     break;
1176     }
1177    
1178     case IDC_USERNAME_OPTION: {
1179 zmatsuo 7635 RECT rect;
1180     HWND hWndButton;
1181 zmatsuo 7632 HMENU hMenu= CreatePopupMenu();
1182 zmatsuo 7635 int result;
1183 zmatsuo 7730 const BOOL DisableDefaultUserName = pvar->session_settings.DefaultUserName[0] == 0;
1184 zmatsuo 7731 GetI18nStrT("TTSSH", "DLG_AUTH_USE_DEFAULT_USERNAME",
1185 zmatsuo 7730 uimsg, _countof(uimsg),
1186 zmatsuo 7731 "Use &default username",
1187 zmatsuo 7730 pvar->ts->UILanguageFile);
1188     AppendMenu(hMenu, MF_ENABLED | MF_STRING | (DisableDefaultUserName ? MFS_DISABLED : 0), 1,
1189     uimsg);
1190 maya 7754 GetI18nStrT("TTSSH", "DLG_AUTH_USE_LOGON_USERNAME",
1191 zmatsuo 7632 uimsg, _countof(uimsg),
1192 maya 7754 "Use &logon username",
1193 zmatsuo 7632 pvar->ts->UILanguageFile);
1194 zmatsuo 7730 AppendMenu(hMenu, MF_ENABLED | MF_STRING, 2, uimsg);
1195 zmatsuo 7635 hWndButton = GetDlgItem(dlg, IDC_USERNAME_OPTION);
1196 zmatsuo 7632 GetWindowRect(hWndButton, &rect);
1197 zmatsuo 7635 result = TrackPopupMenu(hMenu, TPM_RETURNCMD, rect.left, rect.bottom, 0 , hWndButton, NULL);
1198 zmatsuo 7632 DestroyMenu(hMenu);
1199     switch (result) {
1200 zmatsuo 7730 case 1:
1201     SetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->session_settings.DefaultUserName);
1202     goto after_user_name_set;
1203     case 2: {
1204 zmatsuo 7632 TCHAR user_name[UNLEN+1];
1205     DWORD len = _countof(user_name);
1206     BOOL r = GetUserName(user_name, &len);
1207 zmatsuo 7730 if (r == 0) {
1208     break;
1209 zmatsuo 7632 }
1210 zmatsuo 7730 SetDlgItemText(dlg, IDC_SSHUSERNAME, user_name);
1211     after_user_name_set:
1212     SendDlgItemMessage(dlg, IDC_SSHUSERNAME, EM_SETSEL, 0, -1);
1213     SendMessage(dlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(dlg, IDC_SSHUSERNAME), TRUE);
1214 zmatsuo 7632 break;
1215     }
1216     }
1217 zmatsuo 7507 return TRUE;
1218     }
1219    
1220 maya 3227 default:
1221     return FALSE;
1222     }
1223    
1224 zmatsuo 7634 case WM_DESTROY:
1225     if (hIconDropdown != NULL) {
1226     DeleteObject(hIconDropdown);
1227     }
1228     return FALSE;
1229    
1230 maya 3227 default:
1231     return FALSE;
1232     }
1233     }
1234    
1235 doda 6801 char *AUTH_get_user_name(PTInstVar pvar)
1236 maya 3227 {
1237     return pvar->auth_state.user;
1238     }
1239    
1240     int AUTH_set_supported_auth_types(PTInstVar pvar, int types)
1241     {
1242 doda 6809 logprintf(LOG_LEVEL_VERBOSE, "Server reports supported authentication method mask = %d", types);
1243 maya 3227
1244     if (SSHv1(pvar)) {
1245     types &= (1 << SSH_AUTH_PASSWORD) | (1 << SSH_AUTH_RSA)
1246     | (1 << SSH_AUTH_RHOSTS_RSA) | (1 << SSH_AUTH_RHOSTS)
1247     | (1 << SSH_AUTH_TIS) | (1 << SSH_AUTH_PAGEANT);
1248     } else {
1249     // for SSH2(yutaka)
1250     // types &= (1 << SSH_AUTH_PASSWORD);
1251     // ���J���F�����L�������� (2004.12.18 yutaka)
1252     // TIS�������BSSH2����keyboard-interactive�����������B(2005.3.12 yutaka)
1253     types &= (1 << SSH_AUTH_PASSWORD) | (1 << SSH_AUTH_RSA)
1254     | (1 << SSH_AUTH_TIS) | (1 << SSH_AUTH_PAGEANT);
1255     }
1256     pvar->auth_state.supported_types = types;
1257    
1258     if (types == 0) {
1259     UTIL_get_lang_msg("MSG_NOAUTHMETHOD_ERROR", pvar,
1260     "Server does not support any of the authentication options\n"
1261     "provided by TTSSH. This connection will now close.");
1262 maya 5678 notify_fatal_error(pvar, pvar->ts->UIMsg, TRUE);
1263 maya 3227 return 0;
1264     } else {
1265     if (pvar->auth_state.auth_dialog != NULL) {
1266 doda 6809 update_server_supported_types(pvar, pvar->auth_state.auth_dialog);
1267 maya 3227 }
1268    
1269     return 1;
1270     }
1271     }
1272    
1273     static void start_user_auth(PTInstVar pvar)
1274     {
1275     // �F���_�C�A���O���\�������� (2004.12.1 yutaka)
1276     PostMessage(pvar->NotificationWindow, WM_COMMAND, (WPARAM) ID_SSHAUTH,
1277     (LPARAM) NULL);
1278     pvar->auth_state.cur_cred.method = SSH_AUTH_NONE;
1279     }
1280    
1281     static void try_default_auth(PTInstVar pvar)
1282     {
1283     if (pvar->session_settings.TryDefaultAuth) {
1284     switch (pvar->session_settings.DefaultAuthMethod) {
1285     case SSH_AUTH_RSA:{
1286     BOOL invalid_passphrase;
1287     char password[] = "";
1288    
1289     pvar->auth_state.cur_cred.key_pair
1290     =
1291     KEYFILES_read_private_key(pvar,
1292     pvar->session_settings.
1293     DefaultRSAPrivateKeyFile,
1294     password,
1295     &invalid_passphrase, TRUE);
1296     if (pvar->auth_state.cur_cred.key_pair == NULL) {
1297     return;
1298     } else {
1299     pvar->auth_state.cur_cred.method = SSH_AUTH_RSA;
1300     }
1301     break;
1302     }
1303    
1304     case SSH_AUTH_RHOSTS:
1305     if (pvar->session_settings.
1306     DefaultRhostsHostPrivateKeyFile[0] != 0) {
1307     BOOL invalid_passphrase;
1308     char password[] = "";
1309    
1310     pvar->auth_state.cur_cred.key_pair
1311     =
1312     KEYFILES_read_private_key(pvar,
1313     pvar->session_settings.
1314     DefaultRhostsHostPrivateKeyFile,
1315     password,
1316     &invalid_passphrase, TRUE);
1317     if (pvar->auth_state.cur_cred.key_pair == NULL) {
1318     return;
1319     } else {
1320     pvar->auth_state.cur_cred.method = SSH_AUTH_RHOSTS_RSA;
1321     }
1322     } else {
1323     pvar->auth_state.cur_cred.method = SSH_AUTH_RHOSTS;
1324     }
1325    
1326     pvar->auth_state.cur_cred.rhosts_client_user =
1327     _strdup(pvar->session_settings.DefaultRhostsLocalUserName);
1328     break;
1329    
1330     case SSH_AUTH_PAGEANT:
1331     pvar->auth_state.cur_cred.method = SSH_AUTH_PAGEANT;
1332     break;
1333    
1334     case SSH_AUTH_PASSWORD:
1335     pvar->auth_state.cur_cred.password = _strdup("");
1336     pvar->auth_state.cur_cred.method = SSH_AUTH_PASSWORD;
1337     break;
1338    
1339     case SSH_AUTH_TIS:
1340     default:
1341     return;
1342     }
1343    
1344     pvar->auth_state.user =
1345     _strdup(pvar->session_settings.DefaultUserName);
1346     }
1347     }
1348    
1349     void AUTH_notify_end_error(PTInstVar pvar)
1350     {
1351     if ((pvar->auth_state.flags & AUTH_START_USER_AUTH_ON_ERROR_END) != 0) {
1352     start_user_auth(pvar);
1353     pvar->auth_state.flags &= ~AUTH_START_USER_AUTH_ON_ERROR_END;
1354     }
1355     }
1356    
1357     void AUTH_advance_to_next_cred(PTInstVar pvar)
1358     {
1359 yutakapon 8086 logprintf(LOG_LEVEL_VERBOSE, "User authentication will be shown by %d method.", pvar->auth_state.cur_cred.method);
1360    
1361 maya 3227 pvar->auth_state.failed_method = pvar->auth_state.cur_cred.method;
1362    
1363     if (pvar->auth_state.cur_cred.method == SSH_AUTH_NONE) {
1364     try_default_auth(pvar);
1365    
1366     if (pvar->auth_state.cur_cred.method == SSH_AUTH_NONE) {
1367     if (pvar->err_msg != NULL) {
1368     pvar->auth_state.flags |=
1369     AUTH_START_USER_AUTH_ON_ERROR_END;
1370     } else {
1371     // �������F���_�C�A���O���o�������� (2004.12.1 yutaka)
1372     // �R�}���h���C���w������������
1373     start_user_auth(pvar);
1374     }
1375     }
1376     } else {
1377     // �������F���_�C�A���O���o�������� (2004.12.1 yutaka)
1378     // �R�}���h���C���w������(/auth=xxxx)������
1379     start_user_auth(pvar);
1380     }
1381     }
1382    
1383     static void init_TIS_dlg(PTInstVar pvar, HWND dlg)
1384     {
1385     char uimsg[MAX_UIMSG];
1386    
1387     GetWindowText(dlg, uimsg, sizeof(uimsg));
1388     UTIL_get_lang_msg("DLG_TIS_TITLE", pvar, uimsg);
1389     SetWindowText(dlg, pvar->ts->UIMsg);
1390     GetDlgItemText(dlg, IDC_SSHAUTHBANNER, uimsg, sizeof(uimsg));
1391     UTIL_get_lang_msg("DLG_TIS_BANNER", pvar, uimsg);
1392     SetDlgItemText(dlg, IDC_SSHAUTHBANNER, pvar->ts->UIMsg);
1393     GetDlgItemText(dlg, IDOK, uimsg, sizeof(uimsg));
1394     UTIL_get_lang_msg("BTN_OK", pvar, uimsg);
1395     SetDlgItemText(dlg, IDOK, pvar->ts->UIMsg);
1396     GetDlgItemText(dlg, IDCANCEL, uimsg, sizeof(uimsg));
1397     UTIL_get_lang_msg("BTN_DISCONNECT", pvar, uimsg);
1398     SetDlgItemText(dlg, IDCANCEL, pvar->ts->UIMsg);
1399    
1400     init_auth_machine_banner(pvar, dlg);
1401 zmatsuo 7632 init_password_control(pvar, dlg, IDC_SSHPASSWORD, NULL);
1402 maya 3227
1403     if (pvar->auth_state.TIS_prompt != NULL) {
1404     if (strlen(pvar->auth_state.TIS_prompt) > 10000) {
1405     pvar->auth_state.TIS_prompt[10000] = 0;
1406     }
1407     SetDlgItemText(dlg, IDC_SSHAUTHBANNER2,
1408     pvar->auth_state.TIS_prompt);
1409     destroy_malloced_string(&pvar->auth_state.TIS_prompt);
1410     }
1411 doda 7477
1412     if (pvar->auth_state.echo) {
1413     SendMessage(GetDlgItem(dlg, IDC_SSHPASSWORD), EM_SETPASSWORDCHAR, 0, 0);
1414     }
1415 maya 3227 }
1416    
1417     static BOOL end_TIS_dlg(PTInstVar pvar, HWND dlg)
1418     {
1419 doda 6801 char *password =
1420 maya 3227 alloc_control_text(GetDlgItem(dlg, IDC_SSHPASSWORD));
1421    
1422     pvar->auth_state.cur_cred.method = SSH_AUTH_TIS;
1423     pvar->auth_state.cur_cred.password = password;
1424     pvar->auth_state.auth_dialog = NULL;
1425    
1426     // add
1427     if (SSHv2(pvar)) {
1428     pvar->keyboard_interactive_password_input = 1;
1429     handle_SSH2_userauth_inforeq(pvar);
1430     }
1431    
1432     SSH_notify_cred(pvar);
1433    
1434     EndDialog(dlg, 1);
1435     return TRUE;
1436     }
1437    
1438 zmatsuo 7896 static INT_PTR CALLBACK TIS_dlg_proc(HWND dlg, UINT msg, WPARAM wParam,
1439     LPARAM lParam)
1440 maya 3227 {
1441     PTInstVar pvar;
1442    
1443     switch (msg) {
1444     case WM_INITDIALOG:
1445     pvar = (PTInstVar) lParam;
1446     pvar->auth_state.auth_dialog = dlg;
1447 zmatsuo 7896 SetWindowLongPtr(dlg, DWLP_USER, lParam);
1448 maya 3227
1449     init_TIS_dlg(pvar, dlg);
1450 zmatsuo 7703
1451 maya 3227 // /auth=challenge ������ (2007.10.5 maya)
1452     if (pvar->ssh2_autologin == 1) {
1453     SetDlgItemText(dlg, IDC_SSHPASSWORD, pvar->ssh2_password);
1454     SendMessage(dlg, WM_COMMAND, IDOK, 0);
1455     }
1456    
1457 zmatsuo 7592 CenterWindow(dlg, GetParent(dlg));
1458 maya 3227 return FALSE; /* because we set the focus */
1459    
1460     case WM_COMMAND:
1461 zmatsuo 7896 pvar = (PTInstVar) GetWindowLongPtr(dlg, DWLP_USER);
1462 maya 3227
1463     switch (LOWORD(wParam)) {
1464     case IDOK:
1465     return end_TIS_dlg(pvar, dlg);
1466    
1467     case IDCANCEL: /* kill the connection */
1468     pvar->auth_state.auth_dialog = NULL;
1469 maya 5678 notify_closed_connection(pvar, "authentication cancelled");
1470 maya 3227 EndDialog(dlg, 0);
1471     return TRUE;
1472    
1473 yutakapon 8093 case IDCLOSE:
1474     // �F�������l�b�g���[�N���f�����������A���Y���b�Z�[�W���_�C�A���O���������B
1475     pvar->auth_state.auth_dialog = NULL;
1476     EndDialog(dlg, 0);
1477     return TRUE;
1478    
1479 maya 3227 default:
1480     return FALSE;
1481     }
1482    
1483     default:
1484     return FALSE;
1485     }
1486     }
1487    
1488     void AUTH_do_cred_dialog(PTInstVar pvar)
1489     {
1490     if (pvar->auth_state.auth_dialog == NULL) {
1491     HWND cur_active = GetActiveWindow();
1492     DLGPROC dlg_proc;
1493     LPCTSTR dialog_template;
1494 zmatsuo 8210 INT_PTR r;
1495 maya 3227
1496     switch (pvar->auth_state.mode) {
1497     case TIS_AUTH_MODE:
1498     dialog_template = MAKEINTRESOURCE(IDD_SSHTISAUTH);
1499     dlg_proc = TIS_dlg_proc;
1500     break;
1501     case GENERIC_AUTH_MODE:
1502     default:
1503     dialog_template = MAKEINTRESOURCE(IDD_SSHAUTH);
1504     dlg_proc = auth_dlg_proc;
1505     }
1506    
1507 zmatsuo 8210 r = DialogBoxParam(hInst, dialog_template,
1508     cur_active !=
1509     NULL ? cur_active : pvar->NotificationWindow,
1510     dlg_proc, (LPARAM) pvar);
1511     if (r == -1) {
1512 maya 3227 UTIL_get_lang_msg("MSG_CREATEWINDOW_AUTH_ERROR", pvar,
1513     "Unable to display authentication dialog box.\n"
1514     "Connection terminated.");
1515 maya 5678 notify_fatal_error(pvar, pvar->ts->UIMsg, TRUE);
1516 maya 3227 }
1517     }
1518     }
1519    
1520     static void init_default_auth_dlg(PTInstVar pvar, HWND dlg)
1521     {
1522 zmatsuo 7632 int id;
1523     TCHAR user_name[UNLEN+1];
1524     DWORD len;
1525     TCHAR uimsg[MAX_UIMSG];
1526     TCHAR uimsg2[MAX_UIMSG];
1527     const static DlgTextInfo text_info[] = {
1528     { 0, "DLG_AUTHSETUP_TITLE" },
1529     { IDC_SSHAUTHBANNER, "DLG_AUTHSETUP_BANNER" },
1530 maya 8046 { IDC_SSH_USERNAME, "DLG_AUTHSETUP_USERNAME" },
1531 zmatsuo 7632 { IDC_SSH_NO_USERNAME, "DLG_AUTHSETUP_NO_USERNAME" },
1532 zmatsuo 7739 { IDC_SSH_DEFAULTUSERNAME, "DLG_AUTHSETUP_DEFAULT_USERNAME" },
1533 maya 7754 { IDC_SSH_WINDOWS_USERNAME, "DLG_AUTHSETUP_LOGON_USERNAME" },
1534     { IDC_SSH_WINDOWS_USERNAME_TEXT, "DLG_AUTHSETUP_LOGON_USERNAME_TEXT" },
1535 maya 8046 { IDC_SSH_AUTHMETHOD, "DLG_AUTHSETUP_METHOD" },
1536 zmatsuo 7632 { IDC_SSHUSEPASSWORD, "DLG_AUTHSETUP_METHOD_PASSWORD" },
1537     { IDC_SSHUSERSA, "DLG_AUTHSETUP_METHOD_RSA" },
1538     { IDC_SSHUSERHOSTS, "DLG_AUTHSETUP_METHOD_RHOST" },
1539     { IDC_SSHUSETIS, "DLG_AUTHSETUP_METHOD_CHALLENGE" },
1540     { IDC_SSHUSEPAGEANT, "DLG_AUTHSETUP_METHOD_PAGEANT" },
1541     { IDC_RSAFILENAMELABEL, "DLG_AUTH_PRIVATEKEY" },
1542     { IDC_LOCALUSERNAMELABEL, "DLG_AUTH_LOCALUSER" },
1543     { IDC_HOSTRSAFILENAMELABEL, "DLG_AUTH_HOST_PRIVATEKEY" },
1544     { IDC_CHECKAUTH, "DLG_AUTHSETUP_CHECKAUTH" },
1545     { IDOK, "BTN_OK" },
1546     { IDCANCEL, "BTN_CANCEL" },
1547 yutakapon 8089 { IDC_SSHAUTHSETUP_HELP, "BTN_HELP" },
1548 zmatsuo 7632 };
1549 maya 3227
1550 zmatsuo 7632 SetI18DlgStrs("TTSSH", dlg, text_info, _countof(text_info), pvar->ts->UILanguageFile);
1551 maya 3227
1552     switch (pvar->settings.DefaultAuthMethod) {
1553     case SSH_AUTH_RSA:
1554     CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
1555     IDC_SSHUSERSA);
1556     break;
1557     case SSH_AUTH_RHOSTS:
1558     case SSH_AUTH_RHOSTS_RSA:
1559     CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
1560     IDC_SSHUSERHOSTS);
1561     break;
1562     case SSH_AUTH_TIS:
1563     CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
1564     IDC_SSHUSETIS);
1565     break;
1566     case SSH_AUTH_PAGEANT:
1567     CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
1568     IDC_SSHUSEPAGEANT);
1569     break;
1570     case SSH_AUTH_PASSWORD:
1571     default:
1572     CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
1573     IDC_SSHUSEPASSWORD);
1574     }
1575    
1576     SetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->settings.DefaultUserName);
1577     SetDlgItemText(dlg, IDC_RSAFILENAME,
1578     pvar->settings.DefaultRSAPrivateKeyFile);
1579     SetDlgItemText(dlg, IDC_HOSTRSAFILENAME,
1580     pvar->settings.DefaultRhostsHostPrivateKeyFile);
1581     SetDlgItemText(dlg, IDC_LOCALUSERNAME,
1582     pvar->settings.DefaultRhostsLocalUserName);
1583    
1584     if (pvar->settings.CheckAuthListFirst) {
1585     CheckDlgButton(dlg, IDC_CHECKAUTH, TRUE);
1586     }
1587 zmatsuo 7632
1588 zmatsuo 7729 if (pvar->settings.DefaultUserType == 1 &&
1589     pvar->session_settings.DefaultUserName[0] == 0) {
1590 zmatsuo 7632 // ���������u�����������v����������
1591 zmatsuo 7729 pvar->settings.DefaultUserType = 0;
1592 zmatsuo 7632 }
1593     id = pvar->settings.DefaultUserType == 1 ? IDC_SSH_DEFAULTUSERNAME :
1594     pvar->settings.DefaultUserType == 2 ? IDC_SSH_WINDOWS_USERNAME :
1595     IDC_SSH_NO_USERNAME;
1596     CheckRadioButton(dlg, IDC_SSH_NO_USERNAME, IDC_SSH_WINDOWS_USERNAME, id);
1597    
1598     len = _countof(user_name);
1599     GetUserName(user_name, &len);
1600    
1601     GetDlgItemText(dlg, IDC_SSH_WINDOWS_USERNAME_TEXT, uimsg, _countof(uimsg));
1602     _stprintf_s(uimsg2, _countof(uimsg2), uimsg, user_name);
1603     SetDlgItemText(dlg, IDC_SSH_WINDOWS_USERNAME_TEXT, uimsg2);
1604 maya 3227 }
1605    
1606     static BOOL end_default_auth_dlg(PTInstVar pvar, HWND dlg)
1607     {
1608     if (IsDlgButtonChecked(dlg, IDC_SSHUSERSA)) {
1609     pvar->settings.DefaultAuthMethod = SSH_AUTH_RSA;
1610     } else if (IsDlgButtonChecked(dlg, IDC_SSHUSERHOSTS)) {
1611     if (GetWindowTextLength(GetDlgItem(dlg, IDC_HOSTRSAFILENAME)) > 0) {
1612     pvar->settings.DefaultAuthMethod = SSH_AUTH_RHOSTS_RSA;
1613     } else {
1614     pvar->settings.DefaultAuthMethod = SSH_AUTH_RHOSTS;
1615     }
1616     } else if (IsDlgButtonChecked(dlg, IDC_SSHUSETIS)) {
1617     pvar->settings.DefaultAuthMethod = SSH_AUTH_TIS;
1618     } else if (IsDlgButtonChecked(dlg, IDC_SSHUSEPAGEANT)) {
1619     pvar->settings.DefaultAuthMethod = SSH_AUTH_PAGEANT;
1620     } else {
1621     pvar->settings.DefaultAuthMethod = SSH_AUTH_PASSWORD;
1622     }
1623    
1624     GetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->settings.DefaultUserName,
1625     sizeof(pvar->settings.DefaultUserName));
1626     GetDlgItemText(dlg, IDC_RSAFILENAME,
1627     pvar->settings.DefaultRSAPrivateKeyFile,
1628     sizeof(pvar->settings.DefaultRSAPrivateKeyFile));
1629     GetDlgItemText(dlg, IDC_HOSTRSAFILENAME,
1630     pvar->settings.DefaultRhostsHostPrivateKeyFile,
1631     sizeof(pvar->settings.DefaultRhostsHostPrivateKeyFile));
1632     GetDlgItemText(dlg, IDC_LOCALUSERNAME,
1633     pvar->settings.DefaultRhostsLocalUserName,
1634     sizeof(pvar->settings.DefaultRhostsLocalUserName));
1635 zmatsuo 7632 pvar->settings.DefaultUserType =
1636     IsDlgButtonChecked(dlg, IDC_SSH_DEFAULTUSERNAME) ? 1 :
1637     IsDlgButtonChecked(dlg, IDC_SSH_WINDOWS_USERNAME) ? 2 : 0;
1638 maya 3227
1639     if (IsDlgButtonChecked(dlg, IDC_CHECKAUTH)) {
1640     pvar->settings.CheckAuthListFirst = TRUE;
1641     }
1642     else {
1643     pvar->settings.CheckAuthListFirst = FALSE;
1644     }
1645    
1646     EndDialog(dlg, 1);
1647     return TRUE;
1648     }
1649    
1650 zmatsuo 7896 static INT_PTR CALLBACK default_auth_dlg_proc(HWND dlg, UINT msg,
1651     WPARAM wParam, LPARAM lParam)
1652 maya 3227 {
1653     PTInstVar pvar;
1654    
1655     switch (msg) {
1656     case WM_INITDIALOG:
1657     pvar = (PTInstVar) lParam;
1658 zmatsuo 7896 SetWindowLongPtr(dlg, DWLP_USER, lParam);
1659 maya 3227
1660     init_default_auth_dlg(pvar, dlg);
1661 zmatsuo 7592 CenterWindow(dlg, GetParent(dlg));
1662 maya 3227 return TRUE; /* because we do not set the focus */
1663    
1664     case WM_COMMAND:
1665 zmatsuo 7896 pvar = (PTInstVar) GetWindowLongPtr(dlg, DWLP_USER);
1666 maya 3227
1667     switch (LOWORD(wParam)) {
1668     case IDOK:
1669     return end_default_auth_dlg(pvar, dlg);
1670    
1671     case IDCANCEL:
1672     EndDialog(dlg, 0);
1673     return TRUE;
1674    
1675 yutakapon 8089 case IDC_SSHAUTHSETUP_HELP:
1676     PostMessage(GetParent(dlg), WM_USER_DLGHELP2, HlpMenuSetupSshauth, 0);
1677     return TRUE;
1678    
1679 maya 3227 case IDC_CHOOSERSAFILE:
1680     choose_RSA_key_file(dlg, pvar);
1681     return TRUE;
1682    
1683     case IDC_CHOOSEHOSTRSAFILE:
1684     choose_host_RSA_key_file(dlg, pvar);
1685     return TRUE;
1686    
1687     default:
1688     return FALSE;
1689     }
1690    
1691     default:
1692     return FALSE;
1693     }
1694     }
1695    
1696     void AUTH_init(PTInstVar pvar)
1697     {
1698     pvar->auth_state.failed_method = SSH_AUTH_NONE;
1699     pvar->auth_state.auth_dialog = NULL;
1700     pvar->auth_state.user = NULL;
1701     pvar->auth_state.flags = 0;
1702     pvar->auth_state.TIS_prompt = NULL;
1703 doda 7477 pvar->auth_state.echo = 0;
1704 maya 3227 pvar->auth_state.supported_types = 0;
1705     pvar->auth_state.cur_cred.method = SSH_AUTH_NONE;
1706     pvar->auth_state.cur_cred.password = NULL;
1707     pvar->auth_state.cur_cred.rhosts_client_user = NULL;
1708     pvar->auth_state.cur_cred.key_pair = NULL;
1709     AUTH_set_generic_mode(pvar);
1710     }
1711    
1712     void AUTH_set_generic_mode(PTInstVar pvar)
1713     {
1714     pvar->auth_state.mode = GENERIC_AUTH_MODE;
1715     destroy_malloced_string(&pvar->auth_state.TIS_prompt);
1716     }
1717    
1718 doda 7477 void AUTH_set_TIS_mode(PTInstVar pvar, char *prompt, int len, int echo)
1719 maya 3227 {
1720     if (pvar->auth_state.cur_cred.method == SSH_AUTH_TIS) {
1721     pvar->auth_state.mode = TIS_AUTH_MODE;
1722    
1723     destroy_malloced_string(&pvar->auth_state.TIS_prompt);
1724     pvar->auth_state.TIS_prompt = malloc(len + 1);
1725     memcpy(pvar->auth_state.TIS_prompt, prompt, len);
1726     pvar->auth_state.TIS_prompt[len] = 0;
1727 doda 7477 pvar->auth_state.echo = echo;
1728 maya 3227 } else {
1729     AUTH_set_generic_mode(pvar);
1730     }
1731     }
1732    
1733     void AUTH_do_default_cred_dialog(PTInstVar pvar)
1734     {
1735     HWND cur_active = GetActiveWindow();
1736    
1737     if (DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SSHAUTHSETUP),
1738     cur_active != NULL ? cur_active
1739     : pvar->NotificationWindow,
1740     default_auth_dlg_proc, (LPARAM) pvar) == -1) {
1741     UTIL_get_lang_msg("MSG_CREATEWINDOW_AUTHSETUP_ERROR", pvar,
1742     "Unable to display authentication setup dialog box.");
1743     notify_nonfatal_error(pvar, pvar->ts->UIMsg);
1744     }
1745     }
1746    
1747     void AUTH_destroy_cur_cred(PTInstVar pvar)
1748     {
1749     destroy_malloced_string(&pvar->auth_state.cur_cred.password);
1750     destroy_malloced_string(&pvar->auth_state.cur_cred.rhosts_client_user);
1751     if (pvar->auth_state.cur_cred.key_pair != NULL) {
1752 maya 4307 key_free(pvar->auth_state.cur_cred.key_pair);
1753 maya 3227 pvar->auth_state.cur_cred.key_pair = NULL;
1754     }
1755     }
1756    
1757 maya 4307 static const char *get_auth_method_name(SSHAuthMethod auth)
1758 maya 3227 {
1759     switch (auth) {
1760     case SSH_AUTH_PASSWORD:
1761     return "password";
1762     case SSH_AUTH_RSA:
1763 maya 5550 return "publickey";
1764 maya 3227 case SSH_AUTH_PAGEANT:
1765 maya 5550 return "publickey";
1766 maya 3227 case SSH_AUTH_RHOSTS:
1767     return "rhosts";
1768     case SSH_AUTH_RHOSTS_RSA:
1769     return "rhosts with RSA";
1770     case SSH_AUTH_TIS:
1771     return "challenge/response (TIS)";
1772     default:
1773     return "unknown method";
1774     }
1775     }
1776    
1777 doda 6801 void AUTH_get_auth_info(PTInstVar pvar, char *dest, int len)
1778 maya 3227 {
1779 maya 4307 const char *method = "unknown";
1780 yutakapon 5545 char buf[256];
1781 maya 3227
1782     if (pvar->auth_state.user == NULL) {
1783     strncpy_s(dest, len, "None", _TRUNCATE);
1784     } else if (pvar->auth_state.cur_cred.method != SSH_AUTH_NONE) {
1785     if (SSHv1(pvar)) {
1786     UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO", pvar, "User '%s', using %s");
1787 maya 5550 _snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg,
1788     pvar->auth_state.user,
1789 maya 3227 get_auth_method_name(pvar->auth_state.cur_cred.method));
1790    
1791 maya 5550 if (pvar->auth_state.cur_cred.method == SSH_AUTH_RSA) {
1792     UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO2", pvar, " with %s key");
1793     _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg,
1794     "RSA");
1795     strncat_s(dest, len, buf, _TRUNCATE);
1796     }
1797     else if (pvar->auth_state.cur_cred.method == SSH_AUTH_PAGEANT) {
1798     UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO3", pvar, " with %s key from Pageant");
1799     _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg,
1800     "RSA");
1801     strncat_s(dest, len, buf, _TRUNCATE);
1802     }
1803 maya 3227 } else {
1804     // SSH2:�F�����\�b�h������ (2004.12.23 yutaka)
1805     // keyboard-interactive���\�b�h������ (2005.3.12 yutaka)
1806     if (pvar->auth_state.cur_cred.method == SSH_AUTH_PASSWORD ||
1807     pvar->auth_state.cur_cred.method == SSH_AUTH_TIS) {
1808     // keyboard-interactive���\�b�h������ (2005.1.24 yutaka)
1809     if (pvar->auth_state.cur_cred.method == SSH_AUTH_TIS) {
1810     method = "keyboard-interactive";
1811     } else {
1812     method = get_auth_method_name(pvar->auth_state.cur_cred.method);
1813     }
1814     UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO", pvar, "User '%s', using %s");
1815 maya 5550 _snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg,
1816     pvar->auth_state.user, method);
1817     }
1818     else if (pvar->auth_state.cur_cred.method == SSH_AUTH_RSA) {
1819     method = get_auth_method_name(pvar->auth_state.cur_cred.method);
1820     UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO", pvar, "User '%s', using %s");
1821     _snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg,
1822     pvar->auth_state.user,
1823     get_auth_method_name(pvar->auth_state.cur_cred.method));
1824 maya 3227
1825 maya 5550 UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO2", pvar, " with %s key");
1826     _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg,
1827     ssh_key_type(pvar->auth_state.cur_cred.key_pair->type));
1828     strncat_s(dest, len, buf, _TRUNCATE);
1829     }
1830     else if (pvar->auth_state.cur_cred.method == SSH_AUTH_PAGEANT) {
1831     int key_len = get_uint32_MSBfirst(pvar->pageant_curkey + 4);
1832     char *s = (char *)malloc(key_len+1);
1833 yutakapon 5545
1834 maya 5550 method = get_auth_method_name(pvar->auth_state.cur_cred.method);
1835     UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO", pvar, "User '%s', using %s");
1836     _snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg,
1837     pvar->auth_state.user,
1838     get_auth_method_name(pvar->auth_state.cur_cred.method));
1839 maya 3227
1840 maya 5550 memcpy(s, pvar->pageant_curkey+4+4, key_len);
1841     s[key_len] = '\0';
1842     UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO3", pvar, " with %s key from Pageant");
1843     _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg,
1844     ssh_key_type(get_keytype_from_name(s)));
1845     strncat_s(dest, len, buf, _TRUNCATE);
1846    
1847     free(s);
1848 maya 3227 }
1849     }
1850    
1851     } else {
1852     UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO", pvar, "User '%s', using %s");
1853     _snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg, pvar->auth_state.user,
1854     get_auth_method_name(pvar->auth_state.failed_method));
1855     }
1856    
1857     dest[len - 1] = 0;
1858     }
1859    
1860     void AUTH_notify_disconnecting(PTInstVar pvar)
1861     {
1862     if (pvar->auth_state.auth_dialog != NULL) {
1863     PostMessage(pvar->auth_state.auth_dialog, WM_COMMAND, IDCANCEL, 0);
1864     /* the main window might not go away if it's not enabled. (see vtwin.cpp) */
1865     EnableWindow(pvar->NotificationWindow, TRUE);
1866     }
1867     }
1868    
1869 yutakapon 8093 // TCP�Z�b�V�������N���[�Y�����������A�F���_�C�A���O���������������w�����o���B
1870     // AUTH_notify_disconnecting()�����������A�_�C�A���O���������������A
1871     // SSH�T�[�o�����m���o�������B
1872     void AUTH_notify_closing_on_exit(PTInstVar pvar)
1873     {
1874     if (pvar->auth_state.auth_dialog != NULL) {
1875     logprintf(LOG_LEVEL_INFO, "%s: Notify closing message to the authentication dialog.", __FUNCTION__);
1876     PostMessage(pvar->auth_state.auth_dialog, WM_COMMAND, IDCLOSE, 0);
1877     }
1878     }
1879    
1880 maya 3227 void AUTH_end(PTInstVar pvar)
1881     {
1882     destroy_malloced_string(&pvar->auth_state.user);
1883     destroy_malloced_string(&pvar->auth_state.TIS_prompt);
1884    
1885     AUTH_destroy_cur_cred(pvar);
1886     }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26