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

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