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 7754 - (hide annotations) (download) (as text)
Mon Jun 10 14:16:10 2019 UTC (4 years, 10 months ago) by maya
Original Path: trunk/ttssh2/ttxssh/auth.c
File MIME type: text/x-csrc
File size: 60080 byte(s)
SSH 認証に使用するユーザ名 system username を logon username に変更
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     params.Flags =
498     OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;
499     params.lpstrDefExt = NULL;
500    
501     if (GetOpenFileName(&params) != 0) {
502     copy_teraterm_dir_relative_path(buf, bufsize, fullname_buf);
503     return 1;
504     } else {
505     return 0;
506     }
507     }
508    
509     static void choose_RSA_key_file(HWND dlg, PTInstVar pvar)
510     {
511     char buf[1024];
512    
513     if (get_key_file_name(dlg, buf, sizeof(buf), pvar)) {
514     SetDlgItemText(dlg, IDC_RSAFILENAME, buf);
515     }
516     }
517    
518     static void choose_host_RSA_key_file(HWND dlg, PTInstVar pvar)
519     {
520     char buf[1024];
521    
522     if (get_key_file_name(dlg, buf, sizeof(buf), pvar)) {
523     SetDlgItemText(dlg, IDC_HOSTRSAFILENAME, buf);
524     }
525     }
526    
527     static BOOL end_auth_dlg(PTInstVar pvar, HWND dlg)
528     {
529     int method = SSH_AUTH_PASSWORD;
530 doda 6801 char *password =
531 maya 3227 alloc_control_text(GetDlgItem(dlg, IDC_SSHPASSWORD));
532 maya 4307 Key *key_pair = NULL;
533 maya 3227
534     if (IsDlgButtonChecked(dlg, IDC_SSHUSERSA)) {
535     method = SSH_AUTH_RSA;
536     } else if (IsDlgButtonChecked(dlg, IDC_SSHUSERHOSTS)) {
537     if (GetWindowTextLength(GetDlgItem(dlg, IDC_HOSTRSAFILENAME)) > 0) {
538     method = SSH_AUTH_RHOSTS_RSA;
539     } else {
540     method = SSH_AUTH_RHOSTS;
541     }
542     } else if (IsDlgButtonChecked(dlg, IDC_SSHUSETIS)) {
543     method = SSH_AUTH_TIS;
544     } else if (IsDlgButtonChecked(dlg, IDC_SSHUSEPAGEANT)) {
545     method = SSH_AUTH_PAGEANT;
546     }
547    
548     if (method == SSH_AUTH_RSA || method == SSH_AUTH_RHOSTS_RSA) {
549 maya 5767 char keyfile[2048];
550 maya 3227 int file_ctl_ID =
551     method == SSH_AUTH_RSA ? IDC_RSAFILENAME : IDC_HOSTRSAFILENAME;
552    
553 maya 5767 keyfile[0] = 0;
554     GetDlgItemText(dlg, file_ctl_ID, keyfile, sizeof(keyfile));
555     if (keyfile[0] == 0) {
556 maya 3227 UTIL_get_lang_msg("MSG_KEYSPECIFY_ERROR", pvar,
557 maya 5553 "You must specify a file containing the RSA/DSA/ECDSA/ED25519 private key.");
558 maya 3227 notify_nonfatal_error(pvar, pvar->ts->UIMsg);
559     SetFocus(GetDlgItem(dlg, file_ctl_ID));
560     destroy_malloced_string(&password);
561     return FALSE;
562     }
563    
564     if (SSHv1(pvar)) {
565     BOOL invalid_passphrase = FALSE;
566    
567 maya 5767 key_pair = KEYFILES_read_private_key(pvar, keyfile, password,
568 maya 3227 &invalid_passphrase,
569     FALSE);
570    
571     if (key_pair == NULL) {
572     if (invalid_passphrase) {
573     HWND passwordCtl = GetDlgItem(dlg, IDC_SSHPASSWORD);
574    
575     SetFocus(passwordCtl);
576     SendMessage(passwordCtl, EM_SETSEL, 0, -1);
577     } else {
578     SetFocus(GetDlgItem(dlg, file_ctl_ID));
579     }
580     destroy_malloced_string(&password);
581     return FALSE;
582     }
583    
584     } else { // SSH2(yutaka)
585     BOOL invalid_passphrase = FALSE;
586     char errmsg[256];
587 maya 5056 FILE *fp = NULL;
588     ssh2_keyfile_type keyfile_type;
589 maya 3227
590     memset(errmsg, 0, sizeof(errmsg));
591    
592 maya 5767 keyfile_type = get_ssh2_keytype(keyfile, &fp, errmsg, sizeof(errmsg));
593 maya 5056 switch (keyfile_type) {
594     case SSH2_KEYFILE_TYPE_OPENSSH:
595     {
596     key_pair = read_SSH2_private_key(pvar, fp, password,
597     &invalid_passphrase,
598     FALSE,
599     errmsg,
600     sizeof(errmsg)
601     );
602     break;
603     }
604     case SSH2_KEYFILE_TYPE_PUTTY:
605     {
606     key_pair = read_SSH2_PuTTY_private_key(pvar, fp, password,
607     &invalid_passphrase,
608     FALSE,
609     errmsg,
610     sizeof(errmsg)
611     );
612     break;
613     }
614     case SSH2_KEYFILE_TYPE_SECSH:
615     {
616     key_pair = read_SSH2_SECSH_private_key(pvar, fp, password,
617     &invalid_passphrase,
618     FALSE,
619     errmsg,
620     sizeof(errmsg)
621     );
622     break;
623     }
624     default:
625     {
626     char buf[1024];
627 maya 5552
628     // �t�@�C�����J�����������t�@�C���`�����s��������������������
629     if (fp != NULL) {
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    
639 maya 5056 UTIL_get_lang_msg("MSG_READKEY_ERROR", pvar,
640     "read error SSH2 private key file\r\n%s");
641     _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg, errmsg);
642     notify_nonfatal_error(pvar, buf);
643 maya 5552 // ���������������������� SSH2 �������t�@�C�����J����������
644 maya 5056 // ���t�@�C�����I���{�^�����t�H�[�J�X������
645     SetFocus(GetDlgItem(dlg, IDC_CHOOSERSAFILE));
646     destroy_malloced_string(&password);
647     return FALSE;
648     }
649     }
650 maya 3227
651     if (key_pair == NULL) { // read error
652     char buf[1024];
653     UTIL_get_lang_msg("MSG_READKEY_ERROR", pvar,
654     "read error SSH2 private key file\r\n%s");
655     _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg, errmsg);
656     notify_nonfatal_error(pvar, buf);
657     // �p�X�t���[�Y���������v����������������IDC_SSHPASSWORD���t�H�[�J�X������ (2006.10.29 yasuhide)
658     if (invalid_passphrase) {
659     HWND passwordCtl = GetDlgItem(dlg, IDC_SSHPASSWORD);
660    
661     SetFocus(passwordCtl);
662     SendMessage(passwordCtl, EM_SETSEL, 0, -1);
663     } else {
664     SetFocus(GetDlgItem(dlg, file_ctl_ID));
665     }
666     destroy_malloced_string(&password);
667     return FALSE;
668     }
669    
670     }
671    
672     }
673     else if (method == SSH_AUTH_PAGEANT) {
674     pvar->pageant_key = NULL;
675     pvar->pageant_curkey = NULL;
676     pvar->pageant_keylistlen = 0;
677     pvar->pageant_keycount = 0;
678     pvar->pageant_keycurrent = 0;
679     pvar->pageant_keyfinal=FALSE;
680    
681     // Pageant �����M
682     if (SSHv1(pvar)) {
683     pvar->pageant_keylistlen = putty_get_ssh1_keylist(&pvar->pageant_key);
684     }
685     else {
686     pvar->pageant_keylistlen = putty_get_ssh2_keylist(&pvar->pageant_key);
687     }
688     if (pvar->pageant_keylistlen == 0) {
689     UTIL_get_lang_msg("MSG_PAGEANT_NOTFOUND", pvar,
690     "Can't find Pageant.");
691     notify_nonfatal_error(pvar, pvar->ts->UIMsg);
692    
693     return FALSE;
694     }
695     pvar->pageant_curkey = pvar->pageant_key;
696    
697     // ������
698     pvar->pageant_keycount = get_uint32_MSBfirst(pvar->pageant_curkey);
699     if (pvar->pageant_keycount == 0) {
700     UTIL_get_lang_msg("MSG_PAGEANT_NOKEY", pvar,
701     "Pageant has no valid key.");
702     notify_nonfatal_error(pvar, pvar->ts->UIMsg);
703    
704     return FALSE;
705     }
706     pvar->pageant_curkey += 4;
707     }
708    
709     /* from here on, we cannot fail, so just munge cur_cred in place */
710     pvar->auth_state.cur_cred.method = method;
711     pvar->auth_state.cur_cred.key_pair = key_pair;
712     /* we can't change the user name once it's set. It may already have
713     been sent to the server, and it can only be sent once. */
714     if (pvar->auth_state.user == NULL) {
715     pvar->auth_state.user =
716     alloc_control_text(GetDlgItem(dlg, IDC_SSHUSERNAME));
717     }
718    
719     // �p�X���[�h���������������������������� (2006.8.3 yutaka)
720     if (SendMessage(GetDlgItem(dlg, IDC_REMEMBER_PASSWORD), BM_GETCHECK, 0,0) == BST_CHECKED) {
721     pvar->settings.remember_password = 1; // �o��������
722     pvar->ts_SSH->remember_password = 1;
723     } else {
724     pvar->settings.remember_password = 0; // ���������������Y����
725     pvar->ts_SSH->remember_password = 0;
726     }
727    
728     // ���J���F���������A�Z�b�V�������������p�X���[�h���g�����������������������������������B
729     // (2005.4.8 yutaka)
730     if (method == SSH_AUTH_PASSWORD || method == SSH_AUTH_RSA) {
731     pvar->auth_state.cur_cred.password = password;
732     } else {
733     destroy_malloced_string(&password);
734     }
735     if (method == SSH_AUTH_RHOSTS || method == SSH_AUTH_RHOSTS_RSA) {
736     if (pvar->session_settings.DefaultAuthMethod != SSH_AUTH_RHOSTS) {
737     UTIL_get_lang_msg("MSG_RHOSTS_NOTDEFAULT_ERROR", pvar,
738     "Rhosts authentication will probably fail because it was not "
739     "the default authentication method.\n"
740     "To use Rhosts authentication "
741     "in TTSSH, you need to set it to be the default by restarting\n"
742 yutakapon 6019 "TTSSH and selecting \"SSH Authentication...\" from the Setup menu "
743 maya 3227 "before connecting.");
744     notify_nonfatal_error(pvar, pvar->ts->UIMsg);
745     }
746    
747     pvar->auth_state.cur_cred.rhosts_client_user =
748     alloc_control_text(GetDlgItem(dlg, IDC_LOCALUSERNAME));
749     }
750     pvar->auth_state.auth_dialog = NULL;
751    
752     GetDlgItemText(dlg, IDC_RSAFILENAME,
753     pvar->session_settings.DefaultRSAPrivateKeyFile,
754     sizeof(pvar->session_settings.
755     DefaultRSAPrivateKeyFile));
756     GetDlgItemText(dlg, IDC_HOSTRSAFILENAME,
757     pvar->session_settings.DefaultRhostsHostPrivateKeyFile,
758     sizeof(pvar->session_settings.
759     DefaultRhostsHostPrivateKeyFile));
760     GetDlgItemText(dlg, IDC_LOCALUSERNAME,
761     pvar->session_settings.DefaultRhostsLocalUserName,
762     sizeof(pvar->session_settings.
763     DefaultRhostsLocalUserName));
764    
765     if (SSHv1(pvar)) {
766     SSH_notify_user_name(pvar);
767     SSH_notify_cred(pvar);
768     } else {
769     // for SSH2(yutaka)
770     do_SSH2_userauth(pvar);
771     }
772    
773     EndDialog(dlg, 1);
774    
775     return TRUE;
776     }
777    
778 zmatsuo 7507 /**
779     * �N���b�v�{�[�h����ANSI����������������
780     * �����������K�v��������strlen()��������
781     * @param hWnd
782     * @param emtpy TRUE�������N���b�v�{�[�h����������
783     * @retval �����������|�C���^ �g�p��free()��������
784     * ����������(�������G���[��)��NULL
785     */
786     char *GetClipboardTextA(HWND hWnd, BOOL empty)
787     {
788     HGLOBAL hGlobal;
789     const char *lpStr;
790     size_t length;
791     char *pool;
792    
793     OpenClipboard(hWnd);
794     hGlobal = (HGLOBAL)GetClipboardData(CF_TEXT);
795     if (hGlobal == NULL) {
796     CloseClipboard();
797     return NULL;
798     }
799     lpStr = (const char *)GlobalLock(hGlobal);
800     length = GlobalSize(hGlobal);
801     if (length == 0) {
802     pool = NULL;
803     } else {
804     pool = (char *)malloc(length + 1); // +1 for terminator
805     memcpy(pool, lpStr, length);
806     pool[length] = '\0';
807     }
808     GlobalUnlock(hGlobal);
809     if (empty) {
810     EmptyClipboard();
811     }
812     CloseClipboard();
813    
814     return pool;
815     }
816    
817    
818 maya 3227 BOOL autologin_sent_none;
819     static BOOL CALLBACK auth_dlg_proc(HWND dlg, UINT msg, WPARAM wParam,
820     LPARAM lParam)
821     {
822 maya 3342 const int IDC_TIMER1 = 300; // �������O�C�����L��������
823     const int IDC_TIMER2 = 301; // �T�|�[�g�������������\�b�h�������`�F�b�N(CheckAuthListFirst)
824     const int IDC_TIMER3 = 302; // challenge �� ask4passwd ��CheckAuthListFirst �� FALSE ������
825 maya 3227 const int autologin_timeout = 10; // �~���b
826     PTInstVar pvar;
827 zmatsuo 7632 static BOOL UseControlChar;
828     static BOOL ShowPassPhrase;
829 zmatsuo 7634 static HICON hIconDropdown;
830 zmatsuo 7730 TCHAR uimsg[MAX_UIMSG];
831 maya 3227
832     switch (msg) {
833     case WM_INITDIALOG:
834     pvar = (PTInstVar) lParam;
835     pvar->auth_state.auth_dialog = dlg;
836     SetWindowLong(dlg, DWL_USER, lParam);
837    
838 zmatsuo 7632 UseControlChar = TRUE;
839     ShowPassPhrase = FALSE;
840     init_auth_dlg(pvar, dlg, &UseControlChar);
841 zmatsuo 7703
842 zmatsuo 7639 // "��"�������Z�b�g����
843 zmatsuo 7634 hIconDropdown = LoadImage(hInst, MAKEINTRESOURCE(IDI_DROPDOWN),
844     IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
845     SendMessage(GetDlgItem(dlg, IDC_USERNAME_OPTION), BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIconDropdown);
846     SendMessage(GetDlgItem(dlg, IDC_SSHPASSWORD_OPTION), BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIconDropdown);
847 zmatsuo 7632
848 maya 3227 // SSH2 autologin���L�����������A�^�C�}���d�|�����B (2004.12.1 yutaka)
849     if (pvar->ssh2_autologin == 1) {
850     autologin_sent_none = FALSE;
851     SetTimer(dlg, IDC_TIMER1, autologin_timeout, 0);
852     }
853     else {
854     // �T�|�[�g�������������\�b�h���`�F�b�N�����B(2007.9.24 maya)
855     // �������L�����A�����������s�����������A���[�U�����m����������
856     if (pvar->session_settings.CheckAuthListFirst &&
857     !pvar->tryed_ssh2_authlist &&
858     GetWindowTextLength(GetDlgItem(dlg, IDC_SSHUSERNAME)) > 0) {
859     SetTimer(dlg, IDC_TIMER2, autologin_timeout, 0);
860     }
861 maya 3342 // /auth=challenge �� /ask4passwd ���w���������������[�U�����m����������
862     // �������AOK �{�^���������� TIS auth �_�C�A���O���o��
863     else if (pvar->ssh2_authmethod == SSH_AUTH_TIS &&
864     pvar->ask4passwd &&
865     GetWindowTextLength(GetDlgItem(dlg, IDC_SSHUSERNAME)) > 0) {
866 maya 3227 SetTimer(dlg, IDC_TIMER3, autologin_timeout, 0);
867     }
868     }
869 zmatsuo 7592 CenterWindow(dlg, GetParent(dlg));
870 maya 3227 return FALSE; /* because we set the focus */
871    
872     case WM_TIMER:
873     pvar = (PTInstVar) GetWindowLong(dlg, DWL_USER);
874     // �F�������������������A�F���f�[�^�����M�����B�����������A�������B(2004.12.16 yutaka)
875     if (wParam == IDC_TIMER1) {
876     // �������O�C��������
877     if (!(pvar->ssh_state.status_flags & STATUS_DONT_SEND_USER_NAME) &&
878     (pvar->ssh_state.status_flags & STATUS_HOST_OK)) {
879     if (SSHv2(pvar) &&
880     pvar->session_settings.CheckAuthListFirst &&
881     !pvar->tryed_ssh2_authlist) {
882     if (!autologin_sent_none) {
883 maya 3342 autologin_sent_none = TRUE;
884    
885 maya 3336 // �_�C�A���O�����[�U������������
886     if (pvar->auth_state.user == NULL) {
887     pvar->auth_state.user =
888     alloc_control_text(GetDlgItem(dlg, IDC_SSHUSERNAME));
889     }
890    
891 maya 3342 // CheckAuthListFirst �� TRUE �������� AuthList ���A����������������
892     // IDOK �����������i�����������A�F�����\�b�h none ������ (2008.10.12 maya)
893 maya 3227 do_SSH2_userauth(pvar);
894     }
895     //else {
896     // none �������������A����������������
897     //}
898     }
899     else {
900 maya 3342 // SSH1 ������
901     // ������ CheckAuthListFirst �� FALSE ������
902     // ������ CheckAuthListFirst TRUE ���Aauthlist ���A������������
903 maya 3346 KillTimer(dlg, IDC_TIMER1);
904 maya 3342
905     // �_�C�A���O�����[�U������������
906     if (pvar->auth_state.user == NULL) {
907     pvar->auth_state.user =
908     alloc_control_text(GetDlgItem(dlg, IDC_SSHUSERNAME));
909     }
910    
911 maya 3227 SendMessage(dlg, WM_COMMAND, IDOK, 0);
912     }
913     }
914     }
915     else if (wParam == IDC_TIMER2) {
916     // authlist ����������
917 maya 3346 if (!(pvar->ssh_state.status_flags & STATUS_DONT_SEND_USER_NAME) &&
918     (pvar->ssh_state.status_flags & STATUS_HOST_OK)) {
919     if (SSHv2(pvar)) {
920 maya 3227 KillTimer(dlg, IDC_TIMER2);
921    
922     // �_�C�A���O�����[�U������������
923     if (pvar->auth_state.user == NULL) {
924     pvar->auth_state.user =
925     alloc_control_text(GetDlgItem(dlg, IDC_SSHUSERNAME));
926     }
927    
928     // ���[�U�������X��������
929     EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAME), FALSE);
930 zmatsuo 7632 EnableWindow(GetDlgItem(dlg, IDC_USERNAME_OPTION), FALSE);
931 maya 3227
932 maya 3342 // �F�����\�b�h none ������
933 maya 3227 do_SSH2_userauth(pvar);
934    
935 maya 3342 // TIS �p�� OK �����������F�������s������������������
936 maya 3227 // Unexpected SSH2 message �������B
937     }
938 maya 3346 else if (SSHv1(pvar)) {
939     KillTimer(dlg, IDC_TIMER2);
940    
941     // TIS �p�� OK ������
942     if (pvar->ssh2_authmethod == SSH_AUTH_TIS) {
943     SendMessage(dlg, WM_COMMAND, IDOK, 0);
944     }
945     // SSH1 �����F�����\�b�h none ����������
946 maya 3227 }
947 maya 3346 // �v���g�R���o�[�W�����m���O������������
948 maya 3227 }
949     }
950     else if (wParam == IDC_TIMER3) {
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) || SSHv1(pvar)) {
954     KillTimer(dlg, IDC_TIMER3);
955    
956     // TIS �p�� OK ������
957     SendMessage(dlg, WM_COMMAND, IDOK, 0);
958 maya 3227 }
959 maya 3346 // �v���g�R���o�[�W�����m���O������������
960 maya 3227 }
961     }
962     return FALSE;
963    
964     case WM_COMMAND:
965     pvar = (PTInstVar) GetWindowLong(dlg, DWL_USER);
966    
967     switch (LOWORD(wParam)) {
968     case IDOK:
969 yutakapon 5562 // �F�������T�[�o�������f�������������A�L�����Z�������������B(2014.3.31 yutaka)
970     if (!pvar->cv->Ready) {
971     goto canceled;
972     }
973    
974 maya 3227 // �F�������������������A�F���f�[�^�����M�����B�����������A�������B(2001.1.25 yutaka)
975     if (pvar->userauth_retry_count == 0 &&
976     ((pvar->ssh_state.status_flags & STATUS_DONT_SEND_USER_NAME) ||
977     !(pvar->ssh_state.status_flags & STATUS_HOST_OK))) {
978     return FALSE;
979     }
980     else if (SSHv2(pvar) &&
981     pvar->session_settings.CheckAuthListFirst &&
982     !pvar->tryed_ssh2_authlist) {
983     // CheckAuthListFirst ���L�����F������������������������
984     // OK �������������������� (2008.10.4 maya)
985     return FALSE;
986     }
987    
988     return end_auth_dlg(pvar, dlg);
989    
990     case IDCANCEL: /* kill the connection */
991 yutakapon 5562 canceled:
992 maya 3227 pvar->auth_state.auth_dialog = NULL;
993 maya 5678 notify_closed_connection(pvar, "authentication cancelled");
994 maya 3227 EndDialog(dlg, 0);
995     return TRUE;
996    
997     case IDC_SSHUSERNAME:
998     // ���[�U�����t�H�[�J�X������������ (2007.9.29 maya)
999     if (!(pvar->ssh_state.status_flags & STATUS_DONT_SEND_USER_NAME) &&
1000     (pvar->ssh_state.status_flags & STATUS_HOST_OK) &&
1001     HIWORD(wParam) == EN_KILLFOCUS) {
1002     // �������L���������������s��������������
1003     if (SSHv2(pvar) &&
1004     pvar->session_settings.CheckAuthListFirst &&
1005     !pvar->tryed_ssh2_authlist) {
1006     // �_�C�A���O�����[�U�������f
1007     if (pvar->auth_state.user == NULL) {
1008     pvar->auth_state.user =
1009     alloc_control_text(GetDlgItem(dlg, IDC_SSHUSERNAME));
1010     }
1011    
1012     // ���[�U���������������������`�F�b�N����
1013     if (strlen(pvar->auth_state.user) == 0) {
1014     return FALSE;
1015     }
1016    
1017     // ���[�U�������X��������
1018     EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAME), FALSE);
1019 zmatsuo 7632 EnableWindow(GetDlgItem(dlg, IDC_USERNAME_OPTION), FALSE);
1020 maya 3227
1021 maya 3342 // �F�����\�b�h none ������
1022 maya 3227 do_SSH2_userauth(pvar);
1023     return TRUE;
1024     }
1025     }
1026    
1027     return FALSE;
1028    
1029     case IDC_SSHUSEPASSWORD:
1030     case IDC_SSHUSERSA:
1031     case IDC_SSHUSERHOSTS:
1032     case IDC_SSHUSETIS:
1033     case IDC_SSHUSEPAGEANT:
1034     set_auth_options_status(dlg, LOWORD(wParam));
1035     return TRUE;
1036    
1037     case IDC_CHOOSERSAFILE:
1038     choose_RSA_key_file(dlg, pvar);
1039     return TRUE;
1040    
1041     case IDC_CHOOSEHOSTRSAFILE:
1042     choose_host_RSA_key_file(dlg, pvar);
1043     return TRUE;
1044    
1045     case IDC_FORWARD_AGENT:
1046     // �����Z�b�V�������������f������ (2008.12.4 maya)
1047     pvar->session_settings.ForwardAgent = IsDlgButtonChecked(dlg, IDC_FORWARD_AGENT);
1048     return TRUE;
1049    
1050 zmatsuo 7632 case IDC_SSHPASSWORD_OPTION: {
1051 zmatsuo 7635 RECT rect;
1052     HWND hWndButton;
1053     int result;
1054 zmatsuo 7632 HMENU hMenu= CreatePopupMenu();
1055 zmatsuo 7636 char *clipboard = GetClipboardTextA(dlg, FALSE);
1056 zmatsuo 7632 GetI18nStrT("TTSSH", "DLG_AUTH_PASTE_CLIPBOARD",
1057     uimsg, _countof(uimsg),
1058     "Paste from &clipboard",
1059     pvar->ts->UILanguageFile);
1060 zmatsuo 7636 AppendMenu(hMenu, MF_ENABLED | MF_STRING | (clipboard == NULL ? MFS_DISABLED : 0), 1, uimsg);
1061 zmatsuo 7632 GetI18nStrT("ttssh", "DLG_AUTH_CLEAR_CLIPBOARD",
1062     uimsg, _countof(uimsg),
1063     "Paste from &clipboard and cl&ear clipboard",
1064     pvar->ts->UILanguageFile);
1065 zmatsuo 7636 AppendMenu(hMenu, MF_ENABLED | MF_STRING | (clipboard == NULL ? MFS_DISABLED : 0), 2, uimsg);
1066 zmatsuo 7632 GetI18nStrT("ttssh", "DLG_AUTH_USE_CONTORL_CHARACTERS",
1067     uimsg, _countof(uimsg),
1068     "Use control charac&ters",
1069     pvar->ts->UILanguageFile);
1070     AppendMenu(hMenu, MF_ENABLED | MF_STRING | (UseControlChar ? MFS_CHECKED : 0), 3, uimsg);
1071     GetI18nStrT("ttssh", "DLG_AUTH_SHOW_PASSPHRASE",
1072     uimsg, _countof(uimsg),
1073     "&Show passphrase",
1074     pvar->ts->UILanguageFile);
1075     AppendMenu(hMenu, MF_ENABLED | MF_STRING | (ShowPassPhrase ? MFS_CHECKED : 0), 4, uimsg);
1076 zmatsuo 7636 if (clipboard != NULL) {
1077     free(clipboard);
1078     }
1079 zmatsuo 7635 hWndButton = GetDlgItem(dlg, IDC_SSHPASSWORD_OPTION);
1080 zmatsuo 7632 GetWindowRect(hWndButton, &rect);
1081 zmatsuo 7635 result = TrackPopupMenu(hMenu, TPM_RETURNCMD, rect.left, rect.bottom, 0 , hWndButton, NULL);
1082 zmatsuo 7632 DestroyMenu(hMenu);
1083     switch(result) {
1084     case 1:
1085     case 2: {
1086     // �N���b�v�{�[�h�����y�[�X�g
1087     BOOL clear_clipboard = result == 2;
1088 zmatsuo 7636 clipboard = GetClipboardTextA(dlg, clear_clipboard);
1089 zmatsuo 7632 if (clipboard != NULL) {
1090     SetDlgItemTextA(dlg, IDC_SSHPASSWORD, clipboard);
1091     free(clipboard);
1092     SendDlgItemMessage(dlg, IDC_SSHPASSWORD, EM_SETSEL, 0, -1);
1093     SendMessage(dlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(dlg, IDC_SSHPASSWORD), TRUE);
1094     return FALSE;
1095     }
1096     return TRUE;
1097 zmatsuo 7507 }
1098 zmatsuo 7632 case 3:
1099     // �����R�[�h�g�p/���g�p
1100     UseControlChar = !UseControlChar;
1101     break;
1102     case 4:
1103     // �p�X�t���[�Y�\��/���\��
1104     ShowPassPhrase = !ShowPassPhrase;
1105     {
1106     // ������ on/off ������������
1107     HWND hWnd = GetDlgItem(dlg, IDC_SSHPASSWORD);
1108     static wchar_t password_char;
1109     if (password_char == 0) {
1110     wchar_t c = (wchar_t)SendMessage(hWnd, EM_GETPASSWORDCHAR, 0, 0);
1111     password_char = c;
1112     }
1113     if (ShowPassPhrase) {
1114     SendMessage(hWnd, EM_SETPASSWORDCHAR, 0, 0);
1115     } else {
1116     #if !defined(UNICODE)
1117     if (password_char < 0x100) {
1118     SendMessageA(hWnd, EM_SETPASSWORDCHAR, (WPARAM)password_char, 0);
1119     } else {
1120     // TODO W�n������ ����������������
1121     //SendMessageW(hWnd, EM_SETPASSWORDCHAR, (WPARAM)password_char, 0);
1122     SendMessageA(hWnd, EM_SETPASSWORDCHAR, (WPARAM)'*', 0);
1123     }
1124     #else
1125     SendMessageW(hWnd, EM_SETPASSWORDCHAR, (WPARAM)password_char, 0);
1126     #endif
1127     }
1128     //InvalidateRect(hWnd, NULL, TRUE);
1129     SendDlgItemMessage(dlg, IDC_SSHPASSWORD, EM_SETSEL, 0, -1);
1130     SendMessage(dlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(dlg, IDC_SSHPASSWORD), TRUE);
1131     return TRUE;
1132     }
1133     break;
1134     }
1135     break;
1136     }
1137    
1138     case IDC_USERNAME_OPTION: {
1139 zmatsuo 7635 RECT rect;
1140     HWND hWndButton;
1141 zmatsuo 7632 HMENU hMenu= CreatePopupMenu();
1142 zmatsuo 7635 int result;
1143 zmatsuo 7730 const BOOL DisableDefaultUserName = pvar->session_settings.DefaultUserName[0] == 0;
1144 zmatsuo 7731 GetI18nStrT("TTSSH", "DLG_AUTH_USE_DEFAULT_USERNAME",
1145 zmatsuo 7730 uimsg, _countof(uimsg),
1146 zmatsuo 7731 "Use &default username",
1147 zmatsuo 7730 pvar->ts->UILanguageFile);
1148     AppendMenu(hMenu, MF_ENABLED | MF_STRING | (DisableDefaultUserName ? MFS_DISABLED : 0), 1,
1149     uimsg);
1150 maya 7754 GetI18nStrT("TTSSH", "DLG_AUTH_USE_LOGON_USERNAME",
1151 zmatsuo 7632 uimsg, _countof(uimsg),
1152 maya 7754 "Use &logon username",
1153 zmatsuo 7632 pvar->ts->UILanguageFile);
1154 zmatsuo 7730 AppendMenu(hMenu, MF_ENABLED | MF_STRING, 2, uimsg);
1155 zmatsuo 7635 hWndButton = GetDlgItem(dlg, IDC_USERNAME_OPTION);
1156 zmatsuo 7632 GetWindowRect(hWndButton, &rect);
1157 zmatsuo 7635 result = TrackPopupMenu(hMenu, TPM_RETURNCMD, rect.left, rect.bottom, 0 , hWndButton, NULL);
1158 zmatsuo 7632 DestroyMenu(hMenu);
1159     switch (result) {
1160 zmatsuo 7730 case 1:
1161     SetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->session_settings.DefaultUserName);
1162     goto after_user_name_set;
1163     case 2: {
1164 zmatsuo 7632 TCHAR user_name[UNLEN+1];
1165     DWORD len = _countof(user_name);
1166     BOOL r = GetUserName(user_name, &len);
1167 zmatsuo 7730 if (r == 0) {
1168     break;
1169 zmatsuo 7632 }
1170 zmatsuo 7730 SetDlgItemText(dlg, IDC_SSHUSERNAME, user_name);
1171     after_user_name_set:
1172     SendDlgItemMessage(dlg, IDC_SSHUSERNAME, EM_SETSEL, 0, -1);
1173     SendMessage(dlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(dlg, IDC_SSHUSERNAME), TRUE);
1174 zmatsuo 7632 break;
1175     }
1176     }
1177 zmatsuo 7507 return TRUE;
1178     }
1179    
1180 maya 3227 default:
1181     return FALSE;
1182     }
1183    
1184 zmatsuo 7634 case WM_DESTROY:
1185     if (hIconDropdown != NULL) {
1186     DeleteObject(hIconDropdown);
1187     }
1188     return FALSE;
1189    
1190 maya 3227 default:
1191     return FALSE;
1192     }
1193     }
1194    
1195 doda 6801 char *AUTH_get_user_name(PTInstVar pvar)
1196 maya 3227 {
1197     return pvar->auth_state.user;
1198     }
1199    
1200     int AUTH_set_supported_auth_types(PTInstVar pvar, int types)
1201     {
1202 doda 6809 logprintf(LOG_LEVEL_VERBOSE, "Server reports supported authentication method mask = %d", types);
1203 maya 3227
1204     if (SSHv1(pvar)) {
1205     types &= (1 << SSH_AUTH_PASSWORD) | (1 << SSH_AUTH_RSA)
1206     | (1 << SSH_AUTH_RHOSTS_RSA) | (1 << SSH_AUTH_RHOSTS)
1207     | (1 << SSH_AUTH_TIS) | (1 << SSH_AUTH_PAGEANT);
1208     } else {
1209     // for SSH2(yutaka)
1210     // types &= (1 << SSH_AUTH_PASSWORD);
1211     // ���J���F�����L�������� (2004.12.18 yutaka)
1212     // TIS�������BSSH2����keyboard-interactive�����������B(2005.3.12 yutaka)
1213     types &= (1 << SSH_AUTH_PASSWORD) | (1 << SSH_AUTH_RSA)
1214     | (1 << SSH_AUTH_TIS) | (1 << SSH_AUTH_PAGEANT);
1215     }
1216     pvar->auth_state.supported_types = types;
1217    
1218     if (types == 0) {
1219     UTIL_get_lang_msg("MSG_NOAUTHMETHOD_ERROR", pvar,
1220     "Server does not support any of the authentication options\n"
1221     "provided by TTSSH. This connection will now close.");
1222 maya 5678 notify_fatal_error(pvar, pvar->ts->UIMsg, TRUE);
1223 maya 3227 return 0;
1224     } else {
1225     if (pvar->auth_state.auth_dialog != NULL) {
1226 doda 6809 update_server_supported_types(pvar, pvar->auth_state.auth_dialog);
1227 maya 3227 }
1228    
1229     return 1;
1230     }
1231     }
1232    
1233     static void start_user_auth(PTInstVar pvar)
1234     {
1235     // �F���_�C�A���O���\�������� (2004.12.1 yutaka)
1236     PostMessage(pvar->NotificationWindow, WM_COMMAND, (WPARAM) ID_SSHAUTH,
1237     (LPARAM) NULL);
1238     pvar->auth_state.cur_cred.method = SSH_AUTH_NONE;
1239     }
1240    
1241     static void try_default_auth(PTInstVar pvar)
1242     {
1243     if (pvar->session_settings.TryDefaultAuth) {
1244     switch (pvar->session_settings.DefaultAuthMethod) {
1245     case SSH_AUTH_RSA:{
1246     BOOL invalid_passphrase;
1247     char password[] = "";
1248    
1249     pvar->auth_state.cur_cred.key_pair
1250     =
1251     KEYFILES_read_private_key(pvar,
1252     pvar->session_settings.
1253     DefaultRSAPrivateKeyFile,
1254     password,
1255     &invalid_passphrase, TRUE);
1256     if (pvar->auth_state.cur_cred.key_pair == NULL) {
1257     return;
1258     } else {
1259     pvar->auth_state.cur_cred.method = SSH_AUTH_RSA;
1260     }
1261     break;
1262     }
1263    
1264     case SSH_AUTH_RHOSTS:
1265     if (pvar->session_settings.
1266     DefaultRhostsHostPrivateKeyFile[0] != 0) {
1267     BOOL invalid_passphrase;
1268     char password[] = "";
1269    
1270     pvar->auth_state.cur_cred.key_pair
1271     =
1272     KEYFILES_read_private_key(pvar,
1273     pvar->session_settings.
1274     DefaultRhostsHostPrivateKeyFile,
1275     password,
1276     &invalid_passphrase, TRUE);
1277     if (pvar->auth_state.cur_cred.key_pair == NULL) {
1278     return;
1279     } else {
1280     pvar->auth_state.cur_cred.method = SSH_AUTH_RHOSTS_RSA;
1281     }
1282     } else {
1283     pvar->auth_state.cur_cred.method = SSH_AUTH_RHOSTS;
1284     }
1285    
1286     pvar->auth_state.cur_cred.rhosts_client_user =
1287     _strdup(pvar->session_settings.DefaultRhostsLocalUserName);
1288     break;
1289    
1290     case SSH_AUTH_PAGEANT:
1291     pvar->auth_state.cur_cred.method = SSH_AUTH_PAGEANT;
1292     break;
1293    
1294     case SSH_AUTH_PASSWORD:
1295     pvar->auth_state.cur_cred.password = _strdup("");
1296     pvar->auth_state.cur_cred.method = SSH_AUTH_PASSWORD;
1297     break;
1298    
1299     case SSH_AUTH_TIS:
1300     default:
1301     return;
1302     }
1303    
1304     pvar->auth_state.user =
1305     _strdup(pvar->session_settings.DefaultUserName);
1306     }
1307     }
1308    
1309     void AUTH_notify_end_error(PTInstVar pvar)
1310     {
1311     if ((pvar->auth_state.flags & AUTH_START_USER_AUTH_ON_ERROR_END) != 0) {
1312     start_user_auth(pvar);
1313     pvar->auth_state.flags &= ~AUTH_START_USER_AUTH_ON_ERROR_END;
1314     }
1315     }
1316    
1317     void AUTH_advance_to_next_cred(PTInstVar pvar)
1318     {
1319     pvar->auth_state.failed_method = pvar->auth_state.cur_cred.method;
1320    
1321     if (pvar->auth_state.cur_cred.method == SSH_AUTH_NONE) {
1322     try_default_auth(pvar);
1323    
1324     if (pvar->auth_state.cur_cred.method == SSH_AUTH_NONE) {
1325     if (pvar->err_msg != NULL) {
1326     pvar->auth_state.flags |=
1327     AUTH_START_USER_AUTH_ON_ERROR_END;
1328     } else {
1329     // �������F���_�C�A���O���o�������� (2004.12.1 yutaka)
1330     // �R�}���h���C���w������������
1331     start_user_auth(pvar);
1332     }
1333     }
1334     } else {
1335     // �������F���_�C�A���O���o�������� (2004.12.1 yutaka)
1336     // �R�}���h���C���w������(/auth=xxxx)������
1337     start_user_auth(pvar);
1338     }
1339     }
1340    
1341     static void init_TIS_dlg(PTInstVar pvar, HWND dlg)
1342     {
1343     char uimsg[MAX_UIMSG];
1344    
1345     GetWindowText(dlg, uimsg, sizeof(uimsg));
1346     UTIL_get_lang_msg("DLG_TIS_TITLE", pvar, uimsg);
1347     SetWindowText(dlg, pvar->ts->UIMsg);
1348     GetDlgItemText(dlg, IDC_SSHAUTHBANNER, uimsg, sizeof(uimsg));
1349     UTIL_get_lang_msg("DLG_TIS_BANNER", pvar, uimsg);
1350     SetDlgItemText(dlg, IDC_SSHAUTHBANNER, pvar->ts->UIMsg);
1351     GetDlgItemText(dlg, IDOK, uimsg, sizeof(uimsg));
1352     UTIL_get_lang_msg("BTN_OK", pvar, uimsg);
1353     SetDlgItemText(dlg, IDOK, pvar->ts->UIMsg);
1354     GetDlgItemText(dlg, IDCANCEL, uimsg, sizeof(uimsg));
1355     UTIL_get_lang_msg("BTN_DISCONNECT", pvar, uimsg);
1356     SetDlgItemText(dlg, IDCANCEL, pvar->ts->UIMsg);
1357    
1358     init_auth_machine_banner(pvar, dlg);
1359 zmatsuo 7632 init_password_control(pvar, dlg, IDC_SSHPASSWORD, NULL);
1360 maya 3227
1361     if (pvar->auth_state.TIS_prompt != NULL) {
1362     if (strlen(pvar->auth_state.TIS_prompt) > 10000) {
1363     pvar->auth_state.TIS_prompt[10000] = 0;
1364     }
1365     SetDlgItemText(dlg, IDC_SSHAUTHBANNER2,
1366     pvar->auth_state.TIS_prompt);
1367     destroy_malloced_string(&pvar->auth_state.TIS_prompt);
1368     }
1369 doda 7477
1370     if (pvar->auth_state.echo) {
1371     SendMessage(GetDlgItem(dlg, IDC_SSHPASSWORD), EM_SETPASSWORDCHAR, 0, 0);
1372     }
1373 maya 3227 }
1374    
1375     static BOOL end_TIS_dlg(PTInstVar pvar, HWND dlg)
1376     {
1377 doda 6801 char *password =
1378 maya 3227 alloc_control_text(GetDlgItem(dlg, IDC_SSHPASSWORD));
1379    
1380     pvar->auth_state.cur_cred.method = SSH_AUTH_TIS;
1381     pvar->auth_state.cur_cred.password = password;
1382     pvar->auth_state.auth_dialog = NULL;
1383    
1384     // add
1385     if (SSHv2(pvar)) {
1386     pvar->keyboard_interactive_password_input = 1;
1387     handle_SSH2_userauth_inforeq(pvar);
1388     }
1389    
1390     SSH_notify_cred(pvar);
1391    
1392     EndDialog(dlg, 1);
1393     return TRUE;
1394     }
1395    
1396     static BOOL CALLBACK TIS_dlg_proc(HWND dlg, UINT msg, WPARAM wParam,
1397     LPARAM lParam)
1398     {
1399     PTInstVar pvar;
1400    
1401     switch (msg) {
1402     case WM_INITDIALOG:
1403     pvar = (PTInstVar) lParam;
1404     pvar->auth_state.auth_dialog = dlg;
1405     SetWindowLong(dlg, DWL_USER, lParam);
1406    
1407     init_TIS_dlg(pvar, dlg);
1408 zmatsuo 7703
1409 maya 3227 // /auth=challenge ������ (2007.10.5 maya)
1410     if (pvar->ssh2_autologin == 1) {
1411     SetDlgItemText(dlg, IDC_SSHPASSWORD, pvar->ssh2_password);
1412     SendMessage(dlg, WM_COMMAND, IDOK, 0);
1413     }
1414    
1415 zmatsuo 7592 CenterWindow(dlg, GetParent(dlg));
1416 maya 3227 return FALSE; /* because we set the focus */
1417    
1418     case WM_COMMAND:
1419     pvar = (PTInstVar) GetWindowLong(dlg, DWL_USER);
1420    
1421     switch (LOWORD(wParam)) {
1422     case IDOK:
1423     return end_TIS_dlg(pvar, dlg);
1424    
1425     case IDCANCEL: /* kill the connection */
1426     pvar->auth_state.auth_dialog = NULL;
1427 maya 5678 notify_closed_connection(pvar, "authentication cancelled");
1428 maya 3227 EndDialog(dlg, 0);
1429     return TRUE;
1430    
1431     default:
1432     return FALSE;
1433     }
1434    
1435     default:
1436     return FALSE;
1437     }
1438     }
1439    
1440     void AUTH_do_cred_dialog(PTInstVar pvar)
1441     {
1442     if (pvar->auth_state.auth_dialog == NULL) {
1443     HWND cur_active = GetActiveWindow();
1444     DLGPROC dlg_proc;
1445     LPCTSTR dialog_template;
1446    
1447     switch (pvar->auth_state.mode) {
1448     case TIS_AUTH_MODE:
1449     dialog_template = MAKEINTRESOURCE(IDD_SSHTISAUTH);
1450     dlg_proc = TIS_dlg_proc;
1451     break;
1452     case GENERIC_AUTH_MODE:
1453     default:
1454     dialog_template = MAKEINTRESOURCE(IDD_SSHAUTH);
1455     dlg_proc = auth_dlg_proc;
1456     }
1457    
1458     if (!DialogBoxParam(hInst, dialog_template,
1459     cur_active !=
1460     NULL ? cur_active : pvar->NotificationWindow,
1461     dlg_proc, (LPARAM) pvar) == -1) {
1462     UTIL_get_lang_msg("MSG_CREATEWINDOW_AUTH_ERROR", pvar,
1463     "Unable to display authentication dialog box.\n"
1464     "Connection terminated.");
1465 maya 5678 notify_fatal_error(pvar, pvar->ts->UIMsg, TRUE);
1466 maya 3227 }
1467     }
1468     }
1469    
1470     static void init_default_auth_dlg(PTInstVar pvar, HWND dlg)
1471     {
1472 zmatsuo 7632 int id;
1473     TCHAR user_name[UNLEN+1];
1474     DWORD len;
1475     TCHAR uimsg[MAX_UIMSG];
1476     TCHAR uimsg2[MAX_UIMSG];
1477     const static DlgTextInfo text_info[] = {
1478     { 0, "DLG_AUTHSETUP_TITLE" },
1479     { IDC_SSHAUTHBANNER, "DLG_AUTHSETUP_BANNER" },
1480     { IDC_SSH_NO_USERNAME, "DLG_AUTHSETUP_NO_USERNAME" },
1481 zmatsuo 7739 { IDC_SSH_DEFAULTUSERNAME, "DLG_AUTHSETUP_DEFAULT_USERNAME" },
1482 maya 7754 { IDC_SSH_WINDOWS_USERNAME, "DLG_AUTHSETUP_LOGON_USERNAME" },
1483     { IDC_SSH_WINDOWS_USERNAME_TEXT, "DLG_AUTHSETUP_LOGON_USERNAME_TEXT" },
1484 zmatsuo 7632 { IDC_SSHUSEPASSWORD, "DLG_AUTHSETUP_METHOD_PASSWORD" },
1485     { IDC_SSHUSERSA, "DLG_AUTHSETUP_METHOD_RSA" },
1486     { IDC_SSHUSERHOSTS, "DLG_AUTHSETUP_METHOD_RHOST" },
1487     { IDC_SSHUSETIS, "DLG_AUTHSETUP_METHOD_CHALLENGE" },
1488     { IDC_SSHUSEPAGEANT, "DLG_AUTHSETUP_METHOD_PAGEANT" },
1489     { IDC_RSAFILENAMELABEL, "DLG_AUTH_PRIVATEKEY" },
1490     { IDC_LOCALUSERNAMELABEL, "DLG_AUTH_LOCALUSER" },
1491     { IDC_HOSTRSAFILENAMELABEL, "DLG_AUTH_HOST_PRIVATEKEY" },
1492     { IDC_CHECKAUTH, "DLG_AUTHSETUP_CHECKAUTH" },
1493     { IDOK, "BTN_OK" },
1494     { IDCANCEL, "BTN_CANCEL" },
1495     };
1496 maya 3227
1497 zmatsuo 7632 SetI18DlgStrs("TTSSH", dlg, text_info, _countof(text_info), pvar->ts->UILanguageFile);
1498 maya 3227
1499     switch (pvar->settings.DefaultAuthMethod) {
1500     case SSH_AUTH_RSA:
1501     CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
1502     IDC_SSHUSERSA);
1503     break;
1504     case SSH_AUTH_RHOSTS:
1505     case SSH_AUTH_RHOSTS_RSA:
1506     CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
1507     IDC_SSHUSERHOSTS);
1508     break;
1509     case SSH_AUTH_TIS:
1510     CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
1511     IDC_SSHUSETIS);
1512     break;
1513     case SSH_AUTH_PAGEANT:
1514     CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
1515     IDC_SSHUSEPAGEANT);
1516     break;
1517     case SSH_AUTH_PASSWORD:
1518     default:
1519     CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
1520     IDC_SSHUSEPASSWORD);
1521     }
1522    
1523     SetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->settings.DefaultUserName);
1524     SetDlgItemText(dlg, IDC_RSAFILENAME,
1525     pvar->settings.DefaultRSAPrivateKeyFile);
1526     SetDlgItemText(dlg, IDC_HOSTRSAFILENAME,
1527     pvar->settings.DefaultRhostsHostPrivateKeyFile);
1528     SetDlgItemText(dlg, IDC_LOCALUSERNAME,
1529     pvar->settings.DefaultRhostsLocalUserName);
1530    
1531     if (pvar->settings.CheckAuthListFirst) {
1532     CheckDlgButton(dlg, IDC_CHECKAUTH, TRUE);
1533     }
1534 zmatsuo 7632
1535 zmatsuo 7729 if (pvar->settings.DefaultUserType == 1 &&
1536     pvar->session_settings.DefaultUserName[0] == 0) {
1537 zmatsuo 7632 // ���������u�����������v����������
1538 zmatsuo 7729 pvar->settings.DefaultUserType = 0;
1539 zmatsuo 7632 }
1540     id = pvar->settings.DefaultUserType == 1 ? IDC_SSH_DEFAULTUSERNAME :
1541     pvar->settings.DefaultUserType == 2 ? IDC_SSH_WINDOWS_USERNAME :
1542     IDC_SSH_NO_USERNAME;
1543     CheckRadioButton(dlg, IDC_SSH_NO_USERNAME, IDC_SSH_WINDOWS_USERNAME, id);
1544    
1545     len = _countof(user_name);
1546     GetUserName(user_name, &len);
1547    
1548     GetDlgItemText(dlg, IDC_SSH_WINDOWS_USERNAME_TEXT, uimsg, _countof(uimsg));
1549     _stprintf_s(uimsg2, _countof(uimsg2), uimsg, user_name);
1550     SetDlgItemText(dlg, IDC_SSH_WINDOWS_USERNAME_TEXT, uimsg2);
1551 maya 3227 }
1552    
1553     static BOOL end_default_auth_dlg(PTInstVar pvar, HWND dlg)
1554     {
1555     if (IsDlgButtonChecked(dlg, IDC_SSHUSERSA)) {
1556     pvar->settings.DefaultAuthMethod = SSH_AUTH_RSA;
1557     } else if (IsDlgButtonChecked(dlg, IDC_SSHUSERHOSTS)) {
1558     if (GetWindowTextLength(GetDlgItem(dlg, IDC_HOSTRSAFILENAME)) > 0) {
1559     pvar->settings.DefaultAuthMethod = SSH_AUTH_RHOSTS_RSA;
1560     } else {
1561     pvar->settings.DefaultAuthMethod = SSH_AUTH_RHOSTS;
1562     }
1563     } else if (IsDlgButtonChecked(dlg, IDC_SSHUSETIS)) {
1564     pvar->settings.DefaultAuthMethod = SSH_AUTH_TIS;
1565     } else if (IsDlgButtonChecked(dlg, IDC_SSHUSEPAGEANT)) {
1566     pvar->settings.DefaultAuthMethod = SSH_AUTH_PAGEANT;
1567     } else {
1568     pvar->settings.DefaultAuthMethod = SSH_AUTH_PASSWORD;
1569     }
1570    
1571     GetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->settings.DefaultUserName,
1572     sizeof(pvar->settings.DefaultUserName));
1573     GetDlgItemText(dlg, IDC_RSAFILENAME,
1574     pvar->settings.DefaultRSAPrivateKeyFile,
1575     sizeof(pvar->settings.DefaultRSAPrivateKeyFile));
1576     GetDlgItemText(dlg, IDC_HOSTRSAFILENAME,
1577     pvar->settings.DefaultRhostsHostPrivateKeyFile,
1578     sizeof(pvar->settings.DefaultRhostsHostPrivateKeyFile));
1579     GetDlgItemText(dlg, IDC_LOCALUSERNAME,
1580     pvar->settings.DefaultRhostsLocalUserName,
1581     sizeof(pvar->settings.DefaultRhostsLocalUserName));
1582 zmatsuo 7632 pvar->settings.DefaultUserType =
1583     IsDlgButtonChecked(dlg, IDC_SSH_DEFAULTUSERNAME) ? 1 :
1584     IsDlgButtonChecked(dlg, IDC_SSH_WINDOWS_USERNAME) ? 2 : 0;
1585 maya 3227
1586     if (IsDlgButtonChecked(dlg, IDC_CHECKAUTH)) {
1587     pvar->settings.CheckAuthListFirst = TRUE;
1588     }
1589     else {
1590     pvar->settings.CheckAuthListFirst = FALSE;
1591     }
1592    
1593     EndDialog(dlg, 1);
1594     return TRUE;
1595     }
1596    
1597     static BOOL CALLBACK default_auth_dlg_proc(HWND dlg, UINT msg,
1598     WPARAM wParam, LPARAM lParam)
1599     {
1600     PTInstVar pvar;
1601    
1602     switch (msg) {
1603     case WM_INITDIALOG:
1604     pvar = (PTInstVar) lParam;
1605     SetWindowLong(dlg, DWL_USER, lParam);
1606    
1607     init_default_auth_dlg(pvar, dlg);
1608 zmatsuo 7592 CenterWindow(dlg, GetParent(dlg));
1609 maya 3227 return TRUE; /* because we do not set the focus */
1610    
1611     case WM_COMMAND:
1612     pvar = (PTInstVar) GetWindowLong(dlg, DWL_USER);
1613    
1614     switch (LOWORD(wParam)) {
1615     case IDOK:
1616     return end_default_auth_dlg(pvar, dlg);
1617    
1618     case IDCANCEL:
1619     EndDialog(dlg, 0);
1620     return TRUE;
1621    
1622     case IDC_CHOOSERSAFILE:
1623     choose_RSA_key_file(dlg, pvar);
1624     return TRUE;
1625    
1626     case IDC_CHOOSEHOSTRSAFILE:
1627     choose_host_RSA_key_file(dlg, pvar);
1628     return TRUE;
1629    
1630     default:
1631     return FALSE;
1632     }
1633    
1634     default:
1635     return FALSE;
1636     }
1637     }
1638    
1639     void AUTH_init(PTInstVar pvar)
1640     {
1641     pvar->auth_state.failed_method = SSH_AUTH_NONE;
1642     pvar->auth_state.auth_dialog = NULL;
1643     pvar->auth_state.user = NULL;
1644     pvar->auth_state.flags = 0;
1645     pvar->auth_state.TIS_prompt = NULL;
1646 doda 7477 pvar->auth_state.echo = 0;
1647 maya 3227 pvar->auth_state.supported_types = 0;
1648     pvar->auth_state.cur_cred.method = SSH_AUTH_NONE;
1649     pvar->auth_state.cur_cred.password = NULL;
1650     pvar->auth_state.cur_cred.rhosts_client_user = NULL;
1651     pvar->auth_state.cur_cred.key_pair = NULL;
1652     AUTH_set_generic_mode(pvar);
1653     }
1654    
1655     void AUTH_set_generic_mode(PTInstVar pvar)
1656     {
1657     pvar->auth_state.mode = GENERIC_AUTH_MODE;
1658     destroy_malloced_string(&pvar->auth_state.TIS_prompt);
1659     }
1660    
1661 doda 7477 void AUTH_set_TIS_mode(PTInstVar pvar, char *prompt, int len, int echo)
1662 maya 3227 {
1663     if (pvar->auth_state.cur_cred.method == SSH_AUTH_TIS) {
1664     pvar->auth_state.mode = TIS_AUTH_MODE;
1665    
1666     destroy_malloced_string(&pvar->auth_state.TIS_prompt);
1667     pvar->auth_state.TIS_prompt = malloc(len + 1);
1668     memcpy(pvar->auth_state.TIS_prompt, prompt, len);
1669     pvar->auth_state.TIS_prompt[len] = 0;
1670 doda 7477 pvar->auth_state.echo = echo;
1671 maya 3227 } else {
1672     AUTH_set_generic_mode(pvar);
1673     }
1674     }
1675    
1676     void AUTH_do_default_cred_dialog(PTInstVar pvar)
1677     {
1678     HWND cur_active = GetActiveWindow();
1679    
1680     if (DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SSHAUTHSETUP),
1681     cur_active != NULL ? cur_active
1682     : pvar->NotificationWindow,
1683     default_auth_dlg_proc, (LPARAM) pvar) == -1) {
1684     UTIL_get_lang_msg("MSG_CREATEWINDOW_AUTHSETUP_ERROR", pvar,
1685     "Unable to display authentication setup dialog box.");
1686     notify_nonfatal_error(pvar, pvar->ts->UIMsg);
1687     }
1688     }
1689    
1690     void AUTH_destroy_cur_cred(PTInstVar pvar)
1691     {
1692     destroy_malloced_string(&pvar->auth_state.cur_cred.password);
1693     destroy_malloced_string(&pvar->auth_state.cur_cred.rhosts_client_user);
1694     if (pvar->auth_state.cur_cred.key_pair != NULL) {
1695 maya 4307 key_free(pvar->auth_state.cur_cred.key_pair);
1696 maya 3227 pvar->auth_state.cur_cred.key_pair = NULL;
1697     }
1698     }
1699    
1700 maya 4307 static const char *get_auth_method_name(SSHAuthMethod auth)
1701 maya 3227 {
1702     switch (auth) {
1703     case SSH_AUTH_PASSWORD:
1704     return "password";
1705     case SSH_AUTH_RSA:
1706 maya 5550 return "publickey";
1707 maya 3227 case SSH_AUTH_PAGEANT:
1708 maya 5550 return "publickey";
1709 maya 3227 case SSH_AUTH_RHOSTS:
1710     return "rhosts";
1711     case SSH_AUTH_RHOSTS_RSA:
1712     return "rhosts with RSA";
1713     case SSH_AUTH_TIS:
1714     return "challenge/response (TIS)";
1715     default:
1716     return "unknown method";
1717     }
1718     }
1719    
1720 doda 6801 void AUTH_get_auth_info(PTInstVar pvar, char *dest, int len)
1721 maya 3227 {
1722 maya 4307 const char *method = "unknown";
1723 yutakapon 5545 char buf[256];
1724 maya 3227
1725     if (pvar->auth_state.user == NULL) {
1726     strncpy_s(dest, len, "None", _TRUNCATE);
1727     } else if (pvar->auth_state.cur_cred.method != SSH_AUTH_NONE) {
1728     if (SSHv1(pvar)) {
1729     UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO", pvar, "User '%s', using %s");
1730 maya 5550 _snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg,
1731     pvar->auth_state.user,
1732 maya 3227 get_auth_method_name(pvar->auth_state.cur_cred.method));
1733    
1734 maya 5550 if (pvar->auth_state.cur_cred.method == SSH_AUTH_RSA) {
1735     UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO2", pvar, " with %s key");
1736     _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg,
1737     "RSA");
1738     strncat_s(dest, len, buf, _TRUNCATE);
1739     }
1740     else if (pvar->auth_state.cur_cred.method == SSH_AUTH_PAGEANT) {
1741     UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO3", pvar, " with %s key from Pageant");
1742     _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg,
1743     "RSA");
1744     strncat_s(dest, len, buf, _TRUNCATE);
1745     }
1746 maya 3227 } else {
1747     // SSH2:�F�����\�b�h������ (2004.12.23 yutaka)
1748     // keyboard-interactive���\�b�h������ (2005.3.12 yutaka)
1749     if (pvar->auth_state.cur_cred.method == SSH_AUTH_PASSWORD ||
1750     pvar->auth_state.cur_cred.method == SSH_AUTH_TIS) {
1751     // keyboard-interactive���\�b�h������ (2005.1.24 yutaka)
1752     if (pvar->auth_state.cur_cred.method == SSH_AUTH_TIS) {
1753     method = "keyboard-interactive";
1754     } else {
1755     method = get_auth_method_name(pvar->auth_state.cur_cred.method);
1756     }
1757     UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO", pvar, "User '%s', using %s");
1758 maya 5550 _snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg,
1759     pvar->auth_state.user, method);
1760     }
1761     else if (pvar->auth_state.cur_cred.method == SSH_AUTH_RSA) {
1762     method = get_auth_method_name(pvar->auth_state.cur_cred.method);
1763     UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO", pvar, "User '%s', using %s");
1764     _snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg,
1765     pvar->auth_state.user,
1766     get_auth_method_name(pvar->auth_state.cur_cred.method));
1767 maya 3227
1768 maya 5550 UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO2", pvar, " with %s key");
1769     _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg,
1770     ssh_key_type(pvar->auth_state.cur_cred.key_pair->type));
1771     strncat_s(dest, len, buf, _TRUNCATE);
1772     }
1773     else if (pvar->auth_state.cur_cred.method == SSH_AUTH_PAGEANT) {
1774     int key_len = get_uint32_MSBfirst(pvar->pageant_curkey + 4);
1775     char *s = (char *)malloc(key_len+1);
1776 yutakapon 5545
1777 maya 5550 method = get_auth_method_name(pvar->auth_state.cur_cred.method);
1778     UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO", pvar, "User '%s', using %s");
1779     _snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg,
1780     pvar->auth_state.user,
1781     get_auth_method_name(pvar->auth_state.cur_cred.method));
1782 maya 3227
1783 maya 5550 memcpy(s, pvar->pageant_curkey+4+4, key_len);
1784     s[key_len] = '\0';
1785     UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO3", pvar, " with %s key from Pageant");
1786     _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg,
1787     ssh_key_type(get_keytype_from_name(s)));
1788     strncat_s(dest, len, buf, _TRUNCATE);
1789    
1790     free(s);
1791 maya 3227 }
1792     }
1793    
1794     } else {
1795     UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO", pvar, "User '%s', using %s");
1796     _snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg, pvar->auth_state.user,
1797     get_auth_method_name(pvar->auth_state.failed_method));
1798     }
1799    
1800     dest[len - 1] = 0;
1801     }
1802    
1803     void AUTH_notify_disconnecting(PTInstVar pvar)
1804     {
1805     if (pvar->auth_state.auth_dialog != NULL) {
1806     PostMessage(pvar->auth_state.auth_dialog, WM_COMMAND, IDCANCEL, 0);
1807     /* the main window might not go away if it's not enabled. (see vtwin.cpp) */
1808     EnableWindow(pvar->NotificationWindow, TRUE);
1809     }
1810     }
1811    
1812     void AUTH_end(PTInstVar pvar)
1813     {
1814     destroy_malloced_string(&pvar->auth_state.user);
1815     destroy_malloced_string(&pvar->auth_state.TIS_prompt);
1816    
1817     AUTH_destroy_cur_cred(pvar);
1818     }

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