Develop and Download Open Source Software

Browse Subversion Repository

Contents of /branches/ssh_chacha20poly1305/ttssh2/ttxssh/auth.c

Parent Directory Parent Directory | Revision Log Revision Log


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

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