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

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