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 8067 - (hide annotations) (download) (as text)
Fri Sep 6 11:31:51 2019 UTC (4 years, 7 months ago) by yutakapon
Original Path: trunk/ttssh2/ttxssh/auth.c
File MIME type: text/x-csrc
File size: 60200 byte(s)
r8066 の修正でSSH認証のパスワードダイアログにおけるツールチップの表示位置を調整した。
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 yutakapon 8067 data->tipwin = TipWinCreate(control, rect.left, rect.bottom, uimsg, FALSE);
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 maya 8046 { IDC_SSHAUTHMETHOD, "DLG_AUTH_METHOD" },
284 zmatsuo 7632 { IDC_SSHUSEPASSWORD, "DLG_AUTH_METHOD_PASSWORD" },
285     { IDC_SSHUSERSA, "DLG_AUTH_METHOD_RSA" },
286     { IDC_SSHUSERHOSTS, "DLG_AUTH_METHOD_RHOST" },
287     { IDC_SSHUSEPAGEANT, "DLG_AUTH_METHOD_PAGEANT" },
288     { IDC_RSAFILENAMELABEL, "DLG_AUTH_PRIVATEKEY" },
289     { IDC_LOCALUSERNAMELABEL, "DLG_AUTH_LOCALUSER" },
290     { IDC_HOSTRSAFILENAMELABEL, "DLG_AUTH_HOST_PRIVATEKEY" },
291     { IDOK, "BTN_OK" },
292     { IDCANCEL, "BTN_DISCONNECT" },
293     };
294 maya 3227 int default_method = pvar->session_settings.DefaultAuthMethod;
295    
296 zmatsuo 7632 SetI18DlgStrs("TTSSH", dlg, text_info, _countof(text_info), pvar->ts->UILanguageFile);
297 maya 3227
298     init_auth_machine_banner(pvar, dlg);
299 zmatsuo 7632 init_password_control(pvar, dlg, IDC_SSHPASSWORD, UseControlChar);
300 maya 3227
301 maya 3342 // �F�����s�������x������������
302 maya 3227 if (pvar->auth_state.failed_method != SSH_AUTH_NONE) {
303     /* must be retrying a failed attempt */
304     UTIL_get_lang_msg("DLG_AUTH_BANNER2_FAILED", pvar, "Authentication failed. Please retry.");
305     SetDlgItemText(dlg, IDC_SSHAUTHBANNER2, pvar->ts->UIMsg);
306     UTIL_get_lang_msg("DLG_AUTH_TITLE_FAILED", pvar, "Retrying SSH Authentication");
307     SetWindowText(dlg, pvar->ts->UIMsg);
308     default_method = pvar->auth_state.failed_method;
309     }
310    
311 maya 3342 // �p�X���[�h���o���������`�F�b�N�{�b�N�X�����f�t�H���g���L�������� (2006.8.3 yutaka)
312     if (pvar->ts_SSH->remember_password) {
313     SendMessage(GetDlgItem(dlg, IDC_REMEMBER_PASSWORD), BM_SETCHECK, BST_CHECKED, 0);
314     } else {
315     SendMessage(GetDlgItem(dlg, IDC_REMEMBER_PASSWORD), BM_SETCHECK, BST_UNCHECKED, 0);
316     }
317 maya 3227
318 maya 3342 // ForwardAgent �����������f���� (2008.12.4 maya)
319     CheckDlgButton(dlg, IDC_FORWARD_AGENT, pvar->settings.ForwardAgent);
320    
321     // SSH �o�[�W������������ TIS �����x������������
322     if (pvar->settings.ssh_protocol_version == 1) {
323     UTIL_get_lang_msg("DLG_AUTH_METHOD_CHALLENGE1", pvar,
324 doda 7101 "Use challenge/response(&TIS) to log in");
325 maya 3342 SetDlgItemText(dlg, IDC_SSHUSETIS, pvar->ts->UIMsg);
326     } else {
327     UTIL_get_lang_msg("DLG_AUTH_METHOD_CHALLENGE2", pvar,
328 doda 7101 "Use keyboard-&interactive to log in");
329 maya 3342 SetDlgItemText(dlg, IDC_SSHUSETIS, pvar->ts->UIMsg);
330 maya 3227 }
331    
332 zmatsuo 7639 // username���T�u�N���X��
333     {
334     HWND hWndUserName = GetDlgItem(dlg, IDC_SSHUSERNAME);
335     LONG_PTR ProcOrg =
336     SetWindowLongPtr(hWndUserName, GWLP_WNDPROC, (LONG_PTR)username_proc);
337     SetWindowLongPtr(hWndUserName, GWLP_USERDATA, ProcOrg);
338     }
339    
340 maya 3227 if (pvar->auth_state.user != NULL) {
341     SetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->auth_state.user);
342     EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAME), FALSE);
343 zmatsuo 7632 EnableWindow(GetDlgItem(dlg, IDC_USERNAME_OPTION), FALSE);
344 maya 3227 EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAMELABEL), FALSE);
345 maya 3342 }
346 maya 4759 else if (strlen(pvar->ssh2_username) > 0) {
347 maya 3342 SetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->ssh2_username);
348     if (pvar->ssh2_autologin == 1) {
349     EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAME), FALSE);
350 zmatsuo 7632 EnableWindow(GetDlgItem(dlg, IDC_USERNAME_OPTION), FALSE);
351 maya 3342 EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAMELABEL), FALSE);
352     }
353     }
354 zmatsuo 7632 else {
355     switch(pvar->session_settings.DefaultUserType) {
356     case 0:
357     // ����������
358     break;
359     case 1:
360     // use DefaultUserName
361     if (pvar->session_settings.DefaultUserName[0] == 0) {
362     // �u�����������v����������
363     pvar->session_settings.DefaultUserType = 0;
364     } else {
365     SetDlgItemText(dlg, IDC_SSHUSERNAME,
366     pvar->session_settings.DefaultUserName);
367     }
368     break;
369     case 2: {
370     TCHAR user_name[UNLEN+1];
371     DWORD len = _countof(user_name);
372     BOOL r = GetUserName(user_name, &len);
373     if (r != 0) {
374     SetDlgItemText(dlg, IDC_SSHUSERNAME, user_name);
375     }
376     break;
377     }
378     default:
379     // ��������������������
380     pvar->session_settings.DefaultUserType = 0;
381     }
382 maya 3227 }
383    
384 maya 3342 if (strlen(pvar->ssh2_password) > 0) {
385     SetDlgItemText(dlg, IDC_SSHPASSWORD, pvar->ssh2_password);
386     if (pvar->ssh2_autologin == 1) {
387     EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD), FALSE);
388     EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORDCAPTION), FALSE);
389 zmatsuo 7632 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD_OPTION), FALSE);
390 maya 3342 }
391     }
392    
393 maya 3227 SetDlgItemText(dlg, IDC_RSAFILENAME,
394     pvar->session_settings.DefaultRSAPrivateKeyFile);
395     SetDlgItemText(dlg, IDC_HOSTRSAFILENAME,
396     pvar->session_settings.DefaultRhostsHostPrivateKeyFile);
397     SetDlgItemText(dlg, IDC_LOCALUSERNAME,
398     pvar->session_settings.DefaultRhostsLocalUserName);
399    
400 maya 3342 if (pvar->ssh2_authmethod == SSH_AUTH_PASSWORD) {
401     CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, IDC_SSHUSEPASSWORD);
402 maya 3227
403 maya 3342 } else if (pvar->ssh2_authmethod == SSH_AUTH_RSA) {
404     CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, IDC_SSHUSERSA);
405 maya 3227
406 maya 3342 SetDlgItemText(dlg, IDC_RSAFILENAME, pvar->ssh2_keyfile);
407 maya 3227 if (pvar->ssh2_autologin == 1) {
408 maya 3342 EnableWindow(GetDlgItem(dlg, IDC_CHOOSERSAFILE), FALSE);
409     EnableWindow(GetDlgItem(dlg, IDC_RSAFILENAME), FALSE);
410 maya 3227 }
411    
412 maya 3342 // /auth=challenge ������ (2007.10.5 maya)
413     } else if (pvar->ssh2_authmethod == SSH_AUTH_TIS) {
414     CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, IDC_SSHUSETIS);
415     EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD), FALSE);
416 zmatsuo 7632 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD_OPTION), FALSE);
417 maya 3342 SetDlgItemText(dlg, IDC_SSHPASSWORD, "");
418 maya 3227
419 maya 3342 // /auth=pageant ������
420     } else if (pvar->ssh2_authmethod == SSH_AUTH_PAGEANT) {
421     CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, IDC_SSHUSEPAGEANT);
422     EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD), FALSE);
423 zmatsuo 7632 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD_OPTION), FALSE);
424 maya 3342 SetDlgItemText(dlg, IDC_SSHPASSWORD, "");
425 maya 3227
426 maya 3342 } else {
427     // �f�t�H���g���F�����\�b�h���_�C�A���O�����f
428     set_auth_options_status(dlg, auth_types_to_control_IDs[default_method]);
429 maya 3227
430 maya 3342 update_server_supported_types(pvar, dlg);
431 maya 3227
432 maya 3342 // �z�X�g�m�F�_�C�A���O��������������=�E�B���h�E���A�N�e�B�u������������
433     // �� SetFocus �����s�����A�R�}���h���C�����n�������F��������������������
434     // �����������A�������O�C���L������ SetFocus ������ (2009.1.31 maya)
435     if (default_method == SSH_AUTH_TIS) {
436     /* we disabled the password control, so fix the focus */
437     SetFocus(GetDlgItem(dlg, IDC_SSHUSETIS));
438 maya 3227 }
439 maya 3342 else if (default_method == SSH_AUTH_PAGEANT) {
440     SetFocus(GetDlgItem(dlg, IDC_SSHUSEPAGEANT));
441     }
442 maya 3227
443     }
444    
445 maya 3342 if (GetWindowTextLength(GetDlgItem(dlg, IDC_SSHUSERNAME)) == 0) {
446     SetFocus(GetDlgItem(dlg, IDC_SSHUSERNAME));
447 maya 3227 }
448 maya 3342 else if (pvar->ask4passwd == 1) {
449     SetFocus(GetDlgItem(dlg, IDC_SSHPASSWORD));
450     }
451 maya 3227
452 maya 3342 // '/I' �w�������������������������� (2005.9.5 yutaka)
453     if (pvar->ts->Minimize) {
454     //20050822���� start T.Takahashi
455     ShowWindow(dlg,SW_MINIMIZE);
456     //20050822���� end T.Takahashi
457 maya 3227 }
458     }
459    
460 doda 6801 static char *alloc_control_text(HWND ctl)
461 maya 3227 {
462     int len = GetWindowTextLength(ctl);
463 doda 6801 char *result = malloc(len + 1);
464 maya 3227
465     if (result != NULL) {
466     GetWindowText(ctl, result, len + 1);
467     result[len] = 0;
468     }
469    
470     return result;
471     }
472    
473 doda 6801 static int get_key_file_name(HWND parent, char *buf, int bufsize, PTInstVar pvar)
474 maya 3227 {
475     OPENFILENAME params;
476     char fullname_buf[2048] = "identity";
477     char filter[MAX_UIMSG];
478    
479     ZeroMemory(&params, sizeof(params));
480 zmatsuo 7360 params.lStructSize = get_OPENFILENAME_SIZE();
481 maya 3227 params.hwndOwner = parent;
482     // �t�B���^������ (2004.12.19 yutaka)
483     // 3�t�@�C���t�B���^������ (2005.4.26 yutaka)
484     UTIL_get_lang_msg("FILEDLG_OPEN_PRIVATEKEY_FILTER", pvar,
485 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");
486 maya 3227 memcpy(filter, pvar->ts->UIMsg, sizeof(filter));
487     params.lpstrFilter = filter;
488     params.lpstrCustomFilter = NULL;
489     params.nFilterIndex = 0;
490     buf[0] = 0;
491     params.lpstrFile = fullname_buf;
492     params.nMaxFile = sizeof(fullname_buf);
493     params.lpstrFileTitle = NULL;
494     params.lpstrInitialDir = NULL;
495     UTIL_get_lang_msg("FILEDLG_OPEN_PRIVATEKEY_TITLE", pvar,
496 maya 5553 "Choose a file with the RSA/DSA/ECDSA/ED25519 private key");
497 maya 3227 params.lpstrTitle = pvar->ts->UIMsg;
498 maya 7775 params.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
499 maya 3227 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 zmatsuo 7896 static INT_PTR CALLBACK auth_dlg_proc(HWND dlg, UINT msg, WPARAM wParam,
820     LPARAM lParam)
821 maya 3227 {
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 zmatsuo 7896 SetWindowLongPtr(dlg, DWLP_USER, lParam);
837 maya 3227
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 zmatsuo 7896 pvar = (PTInstVar) GetWindowLongPtr(dlg, DWLP_USER);
874 maya 3227 // �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 zmatsuo 7896 pvar = (PTInstVar) GetWindowLongPtr(dlg, DWLP_USER);
966 maya 3227
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 zmatsuo 7896 static INT_PTR CALLBACK TIS_dlg_proc(HWND dlg, UINT msg, WPARAM wParam,
1397     LPARAM lParam)
1398 maya 3227 {
1399     PTInstVar pvar;
1400    
1401     switch (msg) {
1402     case WM_INITDIALOG:
1403     pvar = (PTInstVar) lParam;
1404     pvar->auth_state.auth_dialog = dlg;
1405 zmatsuo 7896 SetWindowLongPtr(dlg, DWLP_USER, lParam);
1406 maya 3227
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 zmatsuo 7896 pvar = (PTInstVar) GetWindowLongPtr(dlg, DWLP_USER);
1420 maya 3227
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 maya 8046 { IDC_SSH_USERNAME, "DLG_AUTHSETUP_USERNAME" },
1481 zmatsuo 7632 { IDC_SSH_NO_USERNAME, "DLG_AUTHSETUP_NO_USERNAME" },
1482 zmatsuo 7739 { IDC_SSH_DEFAULTUSERNAME, "DLG_AUTHSETUP_DEFAULT_USERNAME" },
1483 maya 7754 { IDC_SSH_WINDOWS_USERNAME, "DLG_AUTHSETUP_LOGON_USERNAME" },
1484     { IDC_SSH_WINDOWS_USERNAME_TEXT, "DLG_AUTHSETUP_LOGON_USERNAME_TEXT" },
1485 maya 8046 { IDC_SSH_AUTHMETHOD, "DLG_AUTHSETUP_METHOD" },
1486 zmatsuo 7632 { IDC_SSHUSEPASSWORD, "DLG_AUTHSETUP_METHOD_PASSWORD" },
1487     { IDC_SSHUSERSA, "DLG_AUTHSETUP_METHOD_RSA" },
1488     { IDC_SSHUSERHOSTS, "DLG_AUTHSETUP_METHOD_RHOST" },
1489     { IDC_SSHUSETIS, "DLG_AUTHSETUP_METHOD_CHALLENGE" },
1490     { IDC_SSHUSEPAGEANT, "DLG_AUTHSETUP_METHOD_PAGEANT" },
1491     { IDC_RSAFILENAMELABEL, "DLG_AUTH_PRIVATEKEY" },
1492     { IDC_LOCALUSERNAMELABEL, "DLG_AUTH_LOCALUSER" },
1493     { IDC_HOSTRSAFILENAMELABEL, "DLG_AUTH_HOST_PRIVATEKEY" },
1494     { IDC_CHECKAUTH, "DLG_AUTHSETUP_CHECKAUTH" },
1495     { IDOK, "BTN_OK" },
1496     { IDCANCEL, "BTN_CANCEL" },
1497     };
1498 maya 3227
1499 zmatsuo 7632 SetI18DlgStrs("TTSSH", dlg, text_info, _countof(text_info), pvar->ts->UILanguageFile);
1500 maya 3227
1501     switch (pvar->settings.DefaultAuthMethod) {
1502     case SSH_AUTH_RSA:
1503     CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
1504     IDC_SSHUSERSA);
1505     break;
1506     case SSH_AUTH_RHOSTS:
1507     case SSH_AUTH_RHOSTS_RSA:
1508     CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
1509     IDC_SSHUSERHOSTS);
1510     break;
1511     case SSH_AUTH_TIS:
1512     CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
1513     IDC_SSHUSETIS);
1514     break;
1515     case SSH_AUTH_PAGEANT:
1516     CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
1517     IDC_SSHUSEPAGEANT);
1518     break;
1519     case SSH_AUTH_PASSWORD:
1520     default:
1521     CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
1522     IDC_SSHUSEPASSWORD);
1523     }
1524    
1525     SetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->settings.DefaultUserName);
1526     SetDlgItemText(dlg, IDC_RSAFILENAME,
1527     pvar->settings.DefaultRSAPrivateKeyFile);
1528     SetDlgItemText(dlg, IDC_HOSTRSAFILENAME,
1529     pvar->settings.DefaultRhostsHostPrivateKeyFile);
1530     SetDlgItemText(dlg, IDC_LOCALUSERNAME,
1531     pvar->settings.DefaultRhostsLocalUserName);
1532    
1533     if (pvar->settings.CheckAuthListFirst) {
1534     CheckDlgButton(dlg, IDC_CHECKAUTH, TRUE);
1535     }
1536 zmatsuo 7632
1537 zmatsuo 7729 if (pvar->settings.DefaultUserType == 1 &&
1538     pvar->session_settings.DefaultUserName[0] == 0) {
1539 zmatsuo 7632 // ���������u�����������v����������
1540 zmatsuo 7729 pvar->settings.DefaultUserType = 0;
1541 zmatsuo 7632 }
1542     id = pvar->settings.DefaultUserType == 1 ? IDC_SSH_DEFAULTUSERNAME :
1543     pvar->settings.DefaultUserType == 2 ? IDC_SSH_WINDOWS_USERNAME :
1544     IDC_SSH_NO_USERNAME;
1545     CheckRadioButton(dlg, IDC_SSH_NO_USERNAME, IDC_SSH_WINDOWS_USERNAME, id);
1546    
1547     len = _countof(user_name);
1548     GetUserName(user_name, &len);
1549    
1550     GetDlgItemText(dlg, IDC_SSH_WINDOWS_USERNAME_TEXT, uimsg, _countof(uimsg));
1551     _stprintf_s(uimsg2, _countof(uimsg2), uimsg, user_name);
1552     SetDlgItemText(dlg, IDC_SSH_WINDOWS_USERNAME_TEXT, uimsg2);
1553 maya 3227 }
1554    
1555     static BOOL end_default_auth_dlg(PTInstVar pvar, HWND dlg)
1556     {
1557     if (IsDlgButtonChecked(dlg, IDC_SSHUSERSA)) {
1558     pvar->settings.DefaultAuthMethod = SSH_AUTH_RSA;
1559     } else if (IsDlgButtonChecked(dlg, IDC_SSHUSERHOSTS)) {
1560     if (GetWindowTextLength(GetDlgItem(dlg, IDC_HOSTRSAFILENAME)) > 0) {
1561     pvar->settings.DefaultAuthMethod = SSH_AUTH_RHOSTS_RSA;
1562     } else {
1563     pvar->settings.DefaultAuthMethod = SSH_AUTH_RHOSTS;
1564     }
1565     } else if (IsDlgButtonChecked(dlg, IDC_SSHUSETIS)) {
1566     pvar->settings.DefaultAuthMethod = SSH_AUTH_TIS;
1567     } else if (IsDlgButtonChecked(dlg, IDC_SSHUSEPAGEANT)) {
1568     pvar->settings.DefaultAuthMethod = SSH_AUTH_PAGEANT;
1569     } else {
1570     pvar->settings.DefaultAuthMethod = SSH_AUTH_PASSWORD;
1571     }
1572    
1573     GetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->settings.DefaultUserName,
1574     sizeof(pvar->settings.DefaultUserName));
1575     GetDlgItemText(dlg, IDC_RSAFILENAME,
1576     pvar->settings.DefaultRSAPrivateKeyFile,
1577     sizeof(pvar->settings.DefaultRSAPrivateKeyFile));
1578     GetDlgItemText(dlg, IDC_HOSTRSAFILENAME,
1579     pvar->settings.DefaultRhostsHostPrivateKeyFile,
1580     sizeof(pvar->settings.DefaultRhostsHostPrivateKeyFile));
1581     GetDlgItemText(dlg, IDC_LOCALUSERNAME,
1582     pvar->settings.DefaultRhostsLocalUserName,
1583     sizeof(pvar->settings.DefaultRhostsLocalUserName));
1584 zmatsuo 7632 pvar->settings.DefaultUserType =
1585     IsDlgButtonChecked(dlg, IDC_SSH_DEFAULTUSERNAME) ? 1 :
1586     IsDlgButtonChecked(dlg, IDC_SSH_WINDOWS_USERNAME) ? 2 : 0;
1587 maya 3227
1588     if (IsDlgButtonChecked(dlg, IDC_CHECKAUTH)) {
1589     pvar->settings.CheckAuthListFirst = TRUE;
1590     }
1591     else {
1592     pvar->settings.CheckAuthListFirst = FALSE;
1593     }
1594    
1595     EndDialog(dlg, 1);
1596     return TRUE;
1597     }
1598    
1599 zmatsuo 7896 static INT_PTR CALLBACK default_auth_dlg_proc(HWND dlg, UINT msg,
1600     WPARAM wParam, LPARAM lParam)
1601 maya 3227 {
1602     PTInstVar pvar;
1603    
1604     switch (msg) {
1605     case WM_INITDIALOG:
1606     pvar = (PTInstVar) lParam;
1607 zmatsuo 7896 SetWindowLongPtr(dlg, DWLP_USER, lParam);
1608 maya 3227
1609     init_default_auth_dlg(pvar, dlg);
1610 zmatsuo 7592 CenterWindow(dlg, GetParent(dlg));
1611 maya 3227 return TRUE; /* because we do not set the focus */
1612    
1613     case WM_COMMAND:
1614 zmatsuo 7896 pvar = (PTInstVar) GetWindowLongPtr(dlg, DWLP_USER);
1615 maya 3227
1616     switch (LOWORD(wParam)) {
1617     case IDOK:
1618     return end_default_auth_dlg(pvar, dlg);
1619    
1620     case IDCANCEL:
1621     EndDialog(dlg, 0);
1622     return TRUE;
1623    
1624     case IDC_CHOOSERSAFILE:
1625     choose_RSA_key_file(dlg, pvar);
1626     return TRUE;
1627    
1628     case IDC_CHOOSEHOSTRSAFILE:
1629     choose_host_RSA_key_file(dlg, pvar);
1630     return TRUE;
1631    
1632     default:
1633     return FALSE;
1634     }
1635    
1636     default:
1637     return FALSE;
1638     }
1639     }
1640    
1641     void AUTH_init(PTInstVar pvar)
1642     {
1643     pvar->auth_state.failed_method = SSH_AUTH_NONE;
1644     pvar->auth_state.auth_dialog = NULL;
1645     pvar->auth_state.user = NULL;
1646     pvar->auth_state.flags = 0;
1647     pvar->auth_state.TIS_prompt = NULL;
1648 doda 7477 pvar->auth_state.echo = 0;
1649 maya 3227 pvar->auth_state.supported_types = 0;
1650     pvar->auth_state.cur_cred.method = SSH_AUTH_NONE;
1651     pvar->auth_state.cur_cred.password = NULL;
1652     pvar->auth_state.cur_cred.rhosts_client_user = NULL;
1653     pvar->auth_state.cur_cred.key_pair = NULL;
1654     AUTH_set_generic_mode(pvar);
1655     }
1656    
1657     void AUTH_set_generic_mode(PTInstVar pvar)
1658     {
1659     pvar->auth_state.mode = GENERIC_AUTH_MODE;
1660     destroy_malloced_string(&pvar->auth_state.TIS_prompt);
1661     }
1662    
1663 doda 7477 void AUTH_set_TIS_mode(PTInstVar pvar, char *prompt, int len, int echo)
1664 maya 3227 {
1665     if (pvar->auth_state.cur_cred.method == SSH_AUTH_TIS) {
1666     pvar->auth_state.mode = TIS_AUTH_MODE;
1667    
1668     destroy_malloced_string(&pvar->auth_state.TIS_prompt);
1669     pvar->auth_state.TIS_prompt = malloc(len + 1);
1670     memcpy(pvar->auth_state.TIS_prompt, prompt, len);
1671     pvar->auth_state.TIS_prompt[len] = 0;
1672 doda 7477 pvar->auth_state.echo = echo;
1673 maya 3227 } else {
1674     AUTH_set_generic_mode(pvar);
1675     }
1676     }
1677    
1678     void AUTH_do_default_cred_dialog(PTInstVar pvar)
1679     {
1680     HWND cur_active = GetActiveWindow();
1681    
1682     if (DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SSHAUTHSETUP),
1683     cur_active != NULL ? cur_active
1684     : pvar->NotificationWindow,
1685     default_auth_dlg_proc, (LPARAM) pvar) == -1) {
1686     UTIL_get_lang_msg("MSG_CREATEWINDOW_AUTHSETUP_ERROR", pvar,
1687     "Unable to display authentication setup dialog box.");
1688     notify_nonfatal_error(pvar, pvar->ts->UIMsg);
1689     }
1690     }
1691    
1692     void AUTH_destroy_cur_cred(PTInstVar pvar)
1693     {
1694     destroy_malloced_string(&pvar->auth_state.cur_cred.password);
1695     destroy_malloced_string(&pvar->auth_state.cur_cred.rhosts_client_user);
1696     if (pvar->auth_state.cur_cred.key_pair != NULL) {
1697 maya 4307 key_free(pvar->auth_state.cur_cred.key_pair);
1698 maya 3227 pvar->auth_state.cur_cred.key_pair = NULL;
1699     }
1700     }
1701    
1702 maya 4307 static const char *get_auth_method_name(SSHAuthMethod auth)
1703 maya 3227 {
1704     switch (auth) {
1705     case SSH_AUTH_PASSWORD:
1706     return "password";
1707     case SSH_AUTH_RSA:
1708 maya 5550 return "publickey";
1709 maya 3227 case SSH_AUTH_PAGEANT:
1710 maya 5550 return "publickey";
1711 maya 3227 case SSH_AUTH_RHOSTS:
1712     return "rhosts";
1713     case SSH_AUTH_RHOSTS_RSA:
1714     return "rhosts with RSA";
1715     case SSH_AUTH_TIS:
1716     return "challenge/response (TIS)";
1717     default:
1718     return "unknown method";
1719     }
1720     }
1721    
1722 doda 6801 void AUTH_get_auth_info(PTInstVar pvar, char *dest, int len)
1723 maya 3227 {
1724 maya 4307 const char *method = "unknown";
1725 yutakapon 5545 char buf[256];
1726 maya 3227
1727     if (pvar->auth_state.user == NULL) {
1728     strncpy_s(dest, len, "None", _TRUNCATE);
1729     } else if (pvar->auth_state.cur_cred.method != SSH_AUTH_NONE) {
1730     if (SSHv1(pvar)) {
1731     UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO", pvar, "User '%s', using %s");
1732 maya 5550 _snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg,
1733     pvar->auth_state.user,
1734 maya 3227 get_auth_method_name(pvar->auth_state.cur_cred.method));
1735    
1736 maya 5550 if (pvar->auth_state.cur_cred.method == SSH_AUTH_RSA) {
1737     UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO2", pvar, " with %s key");
1738     _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg,
1739     "RSA");
1740     strncat_s(dest, len, buf, _TRUNCATE);
1741     }
1742     else if (pvar->auth_state.cur_cred.method == SSH_AUTH_PAGEANT) {
1743     UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO3", pvar, " with %s key from Pageant");
1744     _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg,
1745     "RSA");
1746     strncat_s(dest, len, buf, _TRUNCATE);
1747     }
1748 maya 3227 } else {
1749     // SSH2:�F�����\�b�h������ (2004.12.23 yutaka)
1750     // keyboard-interactive���\�b�h������ (2005.3.12 yutaka)
1751     if (pvar->auth_state.cur_cred.method == SSH_AUTH_PASSWORD ||
1752     pvar->auth_state.cur_cred.method == SSH_AUTH_TIS) {
1753     // keyboard-interactive���\�b�h������ (2005.1.24 yutaka)
1754     if (pvar->auth_state.cur_cred.method == SSH_AUTH_TIS) {
1755     method = "keyboard-interactive";
1756     } else {
1757     method = get_auth_method_name(pvar->auth_state.cur_cred.method);
1758     }
1759     UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO", pvar, "User '%s', using %s");
1760 maya 5550 _snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg,
1761     pvar->auth_state.user, method);
1762     }
1763     else if (pvar->auth_state.cur_cred.method == SSH_AUTH_RSA) {
1764     method = get_auth_method_name(pvar->auth_state.cur_cred.method);
1765     UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO", pvar, "User '%s', using %s");
1766     _snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg,
1767     pvar->auth_state.user,
1768     get_auth_method_name(pvar->auth_state.cur_cred.method));
1769 maya 3227
1770 maya 5550 UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO2", pvar, " with %s key");
1771     _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg,
1772     ssh_key_type(pvar->auth_state.cur_cred.key_pair->type));
1773     strncat_s(dest, len, buf, _TRUNCATE);
1774     }
1775     else if (pvar->auth_state.cur_cred.method == SSH_AUTH_PAGEANT) {
1776     int key_len = get_uint32_MSBfirst(pvar->pageant_curkey + 4);
1777     char *s = (char *)malloc(key_len+1);
1778 yutakapon 5545
1779 maya 5550 method = get_auth_method_name(pvar->auth_state.cur_cred.method);
1780     UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO", pvar, "User '%s', using %s");
1781     _snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg,
1782     pvar->auth_state.user,
1783     get_auth_method_name(pvar->auth_state.cur_cred.method));
1784 maya 3227
1785 maya 5550 memcpy(s, pvar->pageant_curkey+4+4, key_len);
1786     s[key_len] = '\0';
1787     UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO3", pvar, " with %s key from Pageant");
1788     _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg,
1789     ssh_key_type(get_keytype_from_name(s)));
1790     strncat_s(dest, len, buf, _TRUNCATE);
1791    
1792     free(s);
1793 maya 3227 }
1794     }
1795    
1796     } else {
1797     UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO", pvar, "User '%s', using %s");
1798     _snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg, pvar->auth_state.user,
1799     get_auth_method_name(pvar->auth_state.failed_method));
1800     }
1801    
1802     dest[len - 1] = 0;
1803     }
1804    
1805     void AUTH_notify_disconnecting(PTInstVar pvar)
1806     {
1807     if (pvar->auth_state.auth_dialog != NULL) {
1808     PostMessage(pvar->auth_state.auth_dialog, WM_COMMAND, IDCANCEL, 0);
1809     /* the main window might not go away if it's not enabled. (see vtwin.cpp) */
1810     EnableWindow(pvar->NotificationWindow, TRUE);
1811     }
1812     }
1813    
1814     void AUTH_end(PTInstVar pvar)
1815     {
1816     destroy_malloced_string(&pvar->auth_state.user);
1817     destroy_malloced_string(&pvar->auth_state.TIS_prompt);
1818    
1819     AUTH_destroy_cur_cred(pvar);
1820     }

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