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

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