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

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