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 8437 - (hide annotations) (download) (as text)
Fri Dec 13 03:11:16 2019 UTC (4 years, 3 months ago) by doda
Original Path: branches/4-stable/ttssh2/ttxssh/auth.c
File MIME type: text/x-csrc
File size: 60676 byte(s)
Tera Term 4.xx メンテナンス用ブランチを作成

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

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