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 8089 - (show annotations) (download) (as text)
Sun Sep 8 04:29:40 2019 UTC (4 years, 7 months ago) by yutakapon
Original Path: trunk/ttssh2/ttxssh/auth.c
File MIME type: text/x-csrc
File size: 60507 byte(s)
設定ダイアログ:SSH、SSH認証、SSH転送、SSH鍵生成にヘルプボタンを追加した。

branches/ttssh_improvedからリビジョン8058をマージ:
設定ダイアログ:SSH、SSH認証、SSH転送、SSH鍵生成
ヘルプボタンを追加した。

........
branches/ttssh_improvedからリビジョン8060をマージ:
rcファイル内のコントロールの位置を移動
........


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 #include "helpid.h"
50
51 #if defined(_DEBUG) && !defined(_CRTDBG_MAP_ALLOC)
52 #define malloc(l) _malloc_dbg((l), _NORMAL_BLOCK, __FILE__, __LINE__)
53 #define free(p) _free_dbg((p), _NORMAL_BLOCK)
54 #endif
55
56 #define AUTH_START_USER_AUTH_ON_ERROR_END 1
57
58 #define MAX_AUTH_CONTROL IDC_SSHUSEPAGEANT
59
60 #undef DialogBoxParam
61 #define DialogBoxParam(p1,p2,p3,p4,p5) \
62 TTDialogBoxParam(p1,p2,p3,p4,p5)
63 #undef EndDialog
64 #define EndDialog(p1,p2) \
65 TTEndDialog(p1, p2)
66
67 void destroy_malloced_string(char **str)
68 {
69 if (*str != NULL) {
70 SecureZeroMemory(*str, strlen(*str));
71 free(*str);
72 *str = NULL;
73 }
74 }
75
76 static int auth_types_to_control_IDs[] = {
77 -1, IDC_SSHUSERHOSTS, IDC_SSHUSERSA, IDC_SSHUSEPASSWORD,
78 IDC_SSHUSERHOSTS, IDC_SSHUSETIS, -1,
79 -1, -1, -1, -1, -1, -1, -1, -1, -1, IDC_SSHUSEPAGEANT, -1
80 };
81
82 typedef struct {
83 WNDPROC ProcOrg;
84 PTInstVar pvar;
85 TipWin *tipwin;
86 BOOL *UseControlChar;
87 } TPasswordControlData;
88
89 static void password_wnd_proc_close_tooltip(TPasswordControlData *data)
90 {
91 if (data->tipwin != NULL) {
92 TipWinDestroy(data->tipwin);
93 data->tipwin = NULL;
94 }
95 }
96
97 static LRESULT CALLBACK password_wnd_proc(HWND control, UINT msg,
98 WPARAM wParam, LPARAM lParam)
99 {
100 LRESULT result;
101 TPasswordControlData *data = (TPasswordControlData *)GetWindowLongPtr(control, GWLP_USERDATA);
102 switch (msg) {
103 case WM_CHAR:
104 if ((data->UseControlChar == NULL || *data->UseControlChar == TRUE) &&
105 (GetKeyState(VK_CONTROL) & 0x8000) != 0)
106 { // �����������g�p���� && CTRL�L�[��������������
107 TCHAR chars[] = { (TCHAR) wParam, 0 };
108
109 SendMessage(control, EM_REPLACESEL, (WPARAM) TRUE,
110 (LPARAM) (TCHAR *) chars);
111
112 if (data->tipwin == NULL) {
113 TCHAR uimsg[MAX_UIMSG];
114 RECT rect;
115 PTInstVar pvar = data->pvar;
116 UTIL_get_lang_msg("DLG_AUTH_TIP_CONTROL_CODE", pvar, "control character is entered");
117 _tcscpy_s(uimsg, _countof(uimsg), pvar->ts->UIMsg);
118 if (wParam == 'V' - 'A' + 1) {
119 // CTRL + V
120 _tcscat_s(uimsg, _countof(uimsg), _T("\n"));
121 UTIL_get_lang_msg("DLG_AUTH_TIP_PASTE_KEY", pvar, "Use Shift + Insert to paste from clipboard");
122 _tcscat_s(uimsg, _countof(uimsg), pvar->ts->UIMsg);
123 }
124 GetWindowRect(control, &rect);
125 data->tipwin = TipWinCreate(control, rect.left, rect.bottom, uimsg, FALSE);
126 }
127
128 return 0;
129 } else {
130 password_wnd_proc_close_tooltip(data);
131 }
132 break;
133 case WM_KILLFOCUS:
134 password_wnd_proc_close_tooltip(data);
135 break;
136 }
137
138 result = CallWindowProc((WNDPROC)data->ProcOrg,
139 control, msg, wParam, lParam);
140
141 if (msg == WM_NCDESTROY) {
142 SetWindowLongPtr(control, GWLP_WNDPROC, (LONG_PTR)data->ProcOrg);
143 password_wnd_proc_close_tooltip(data);
144 free(data);
145 }
146
147 return result;
148 }
149
150 void init_password_control(PTInstVar pvar, HWND dlg, int item, BOOL *UseControlChar)
151 {
152 HWND passwordControl = GetDlgItem(dlg, item);
153 TPasswordControlData *data = (TPasswordControlData *)malloc(sizeof(TPasswordControlData));
154 data->ProcOrg = (WNDPROC)GetWindowLongPtr(passwordControl, GWLP_WNDPROC);
155 data->pvar = pvar;
156 data->tipwin = NULL;
157 data->UseControlChar = UseControlChar;
158 SetWindowLongPtr(passwordControl, GWLP_WNDPROC, (LONG_PTR)password_wnd_proc);
159 SetWindowLongPtr(passwordControl, GWLP_USERDATA, (LONG_PTR)data);
160 SetFocus(passwordControl);
161 }
162
163 static void set_auth_options_status(HWND dlg, int controlID)
164 {
165 BOOL RSA_enabled = controlID == IDC_SSHUSERSA;
166 BOOL rhosts_enabled = controlID == IDC_SSHUSERHOSTS;
167 BOOL TIS_enabled = controlID == IDC_SSHUSETIS;
168 BOOL PAGEANT_enabled = controlID == IDC_SSHUSEPAGEANT;
169 int i;
170
171 CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, controlID);
172
173 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORDCAPTION), (!TIS_enabled && !PAGEANT_enabled));
174 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD), (!TIS_enabled && !PAGEANT_enabled));
175 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD_OPTION), (!TIS_enabled && !PAGEANT_enabled));
176
177 for (i = IDC_CHOOSERSAFILE; i <= IDC_RSAFILENAME; i++) {
178 EnableWindow(GetDlgItem(dlg, i), RSA_enabled);
179 }
180
181 for (i = IDC_LOCALUSERNAMELABEL; i <= IDC_HOSTRSAFILENAME; i++) {
182 EnableWindow(GetDlgItem(dlg, i), rhosts_enabled);
183 }
184 }
185
186 static void init_auth_machine_banner(PTInstVar pvar, HWND dlg)
187 {
188 char buf[1024], buf2[1024];
189
190 GetDlgItemText(dlg, IDC_SSHAUTHBANNER, buf2, sizeof(buf2));
191 _snprintf_s(buf, sizeof(buf), _TRUNCATE, buf2, SSH_get_host_name(pvar));
192 SetDlgItemText(dlg, IDC_SSHAUTHBANNER, buf);
193 }
194
195 static void update_server_supported_types(PTInstVar pvar, HWND dlg)
196 {
197 int supported_methods = pvar->auth_state.supported_types;
198 int cur_control = -1;
199 int control;
200 HWND focus = GetFocus();
201
202 if (supported_methods == 0) {
203 return;
204 }
205
206 for (control = IDC_SSHUSEPASSWORD; control <= MAX_AUTH_CONTROL;
207 control++) {
208 BOOL enabled = FALSE;
209 int method;
210 HWND item = GetDlgItem(dlg, control);
211
212 if (item != NULL) {
213 for (method = 0; method <= SSH_AUTH_MAX; method++) {
214 if (auth_types_to_control_IDs[method] == control
215 && (supported_methods & (1 << method)) != 0) {
216 enabled = TRUE;
217 }
218 }
219
220 EnableWindow(item, enabled);
221
222 if (IsDlgButtonChecked(dlg, control)) {
223 cur_control = control;
224 }
225 }
226 }
227
228 if (cur_control >= 0) {
229 if (!IsWindowEnabled(GetDlgItem(dlg, cur_control))) {
230 do {
231 cur_control++;
232 if (cur_control > MAX_AUTH_CONTROL) {
233 cur_control = IDC_SSHUSEPASSWORD;
234 }
235 } while (!IsWindowEnabled(GetDlgItem(dlg, cur_control)));
236
237 set_auth_options_status(dlg, cur_control);
238
239 if (focus != NULL && !IsWindowEnabled(focus)) {
240 SetFocus(GetDlgItem(dlg, cur_control));
241 }
242 }
243 }
244 }
245
246 static LRESULT CALLBACK username_proc(HWND hWnd, UINT msg,
247 WPARAM wParam, LPARAM lParam)
248 {
249 const WNDPROC ProcOrg = (WNDPROC)GetWindowLongPtr(hWnd, GWLP_USERDATA);
250 const LRESULT result = CallWindowProc(ProcOrg, hWnd, msg, wParam, lParam);
251 switch (msg) {
252 case WM_CHAR:
253 case WM_SETTEXT: {
254 // ���[�U�[�����������������������A�I�v�V�������g�����������������A
255 // tab�����t�H�[�J�X�������A�I�v�V�����{�^�����p�X��������������
256 // �]���������L�[���������[�U�[�����p�X�t���[�Y���������\������
257 const HWND dlg = GetParent(hWnd);
258 const HWND hWndOption = GetDlgItem(dlg, IDC_USERNAME_OPTION);
259 const int len = GetWindowTextLength(hWnd);
260 LONG_PTR style = GetWindowLongPtr(hWndOption, GWL_STYLE);
261 if (len > 0) {
262 // �s�vtabstop
263 style = style & (~(LONG_PTR)WS_TABSTOP);
264 } else {
265 // �vtabstop
266 style = style | WS_TABSTOP;
267 }
268 SetWindowLongPtr(hWndOption, GWL_STYLE, style);
269 }
270 }
271 return result;
272 }
273
274 static void init_auth_dlg(PTInstVar pvar, HWND dlg, BOOL *UseControlChar)
275 {
276 const static DlgTextInfo text_info[] = {
277 { 0, "DLG_AUTH_TITLE" },
278 { IDC_SSHAUTHBANNER, "DLG_AUTH_BANNER" },
279 { IDC_SSHAUTHBANNER2, "DLG_AUTH_BANNER2" },
280 { IDC_SSHUSERNAMELABEL, "DLG_AUTH_USERNAME" },
281 { IDC_SSHPASSWORDCAPTION, "DLG_AUTH_PASSWORD" },
282 { IDC_REMEMBER_PASSWORD, "DLG_AUTH_REMEMBER_PASSWORD" },
283 { IDC_FORWARD_AGENT, "DLG_AUTH_FWDAGENT" },
284 { IDC_SSHAUTHMETHOD, "DLG_AUTH_METHOD" },
285 { IDC_SSHUSEPASSWORD, "DLG_AUTH_METHOD_PASSWORD" },
286 { IDC_SSHUSERSA, "DLG_AUTH_METHOD_RSA" },
287 { IDC_SSHUSERHOSTS, "DLG_AUTH_METHOD_RHOST" },
288 { IDC_SSHUSEPAGEANT, "DLG_AUTH_METHOD_PAGEANT" },
289 { IDC_RSAFILENAMELABEL, "DLG_AUTH_PRIVATEKEY" },
290 { IDC_LOCALUSERNAMELABEL, "DLG_AUTH_LOCALUSER" },
291 { IDC_HOSTRSAFILENAMELABEL, "DLG_AUTH_HOST_PRIVATEKEY" },
292 { IDOK, "BTN_OK" },
293 { IDCANCEL, "BTN_DISCONNECT" },
294 };
295 int default_method = pvar->session_settings.DefaultAuthMethod;
296
297 SetI18DlgStrs("TTSSH", dlg, text_info, _countof(text_info), pvar->ts->UILanguageFile);
298
299 init_auth_machine_banner(pvar, dlg);
300 init_password_control(pvar, dlg, IDC_SSHPASSWORD, UseControlChar);
301
302 // �F�����s�������x������������
303 if (pvar->auth_state.failed_method != SSH_AUTH_NONE) {
304 /* must be retrying a failed attempt */
305 UTIL_get_lang_msg("DLG_AUTH_BANNER2_FAILED", pvar, "Authentication failed. Please retry.");
306 SetDlgItemText(dlg, IDC_SSHAUTHBANNER2, pvar->ts->UIMsg);
307 UTIL_get_lang_msg("DLG_AUTH_TITLE_FAILED", pvar, "Retrying SSH Authentication");
308 SetWindowText(dlg, pvar->ts->UIMsg);
309 default_method = pvar->auth_state.failed_method;
310 }
311
312 // �p�X���[�h���o���������`�F�b�N�{�b�N�X�����f�t�H���g���L�������� (2006.8.3 yutaka)
313 if (pvar->ts_SSH->remember_password) {
314 SendMessage(GetDlgItem(dlg, IDC_REMEMBER_PASSWORD), BM_SETCHECK, BST_CHECKED, 0);
315 } else {
316 SendMessage(GetDlgItem(dlg, IDC_REMEMBER_PASSWORD), BM_SETCHECK, BST_UNCHECKED, 0);
317 }
318
319 // ForwardAgent �����������f���� (2008.12.4 maya)
320 CheckDlgButton(dlg, IDC_FORWARD_AGENT, pvar->settings.ForwardAgent);
321
322 // SSH �o�[�W������������ TIS �����x������������
323 if (pvar->settings.ssh_protocol_version == 1) {
324 UTIL_get_lang_msg("DLG_AUTH_METHOD_CHALLENGE1", pvar,
325 "Use challenge/response(&TIS) to log in");
326 SetDlgItemText(dlg, IDC_SSHUSETIS, pvar->ts->UIMsg);
327 } else {
328 UTIL_get_lang_msg("DLG_AUTH_METHOD_CHALLENGE2", pvar,
329 "Use keyboard-&interactive to log in");
330 SetDlgItemText(dlg, IDC_SSHUSETIS, pvar->ts->UIMsg);
331 }
332
333 // username���T�u�N���X��
334 {
335 HWND hWndUserName = GetDlgItem(dlg, IDC_SSHUSERNAME);
336 LONG_PTR ProcOrg =
337 SetWindowLongPtr(hWndUserName, GWLP_WNDPROC, (LONG_PTR)username_proc);
338 SetWindowLongPtr(hWndUserName, GWLP_USERDATA, ProcOrg);
339 }
340
341 if (pvar->auth_state.user != NULL) {
342 SetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->auth_state.user);
343 EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAME), FALSE);
344 EnableWindow(GetDlgItem(dlg, IDC_USERNAME_OPTION), FALSE);
345 EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAMELABEL), FALSE);
346 }
347 else if (strlen(pvar->ssh2_username) > 0) {
348 SetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->ssh2_username);
349 if (pvar->ssh2_autologin == 1) {
350 EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAME), FALSE);
351 EnableWindow(GetDlgItem(dlg, IDC_USERNAME_OPTION), FALSE);
352 EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAMELABEL), FALSE);
353 }
354 }
355 else {
356 switch(pvar->session_settings.DefaultUserType) {
357 case 0:
358 // ����������
359 break;
360 case 1:
361 // use DefaultUserName
362 if (pvar->session_settings.DefaultUserName[0] == 0) {
363 // �u�����������v����������
364 pvar->session_settings.DefaultUserType = 0;
365 } else {
366 SetDlgItemText(dlg, IDC_SSHUSERNAME,
367 pvar->session_settings.DefaultUserName);
368 }
369 break;
370 case 2: {
371 TCHAR user_name[UNLEN+1];
372 DWORD len = _countof(user_name);
373 BOOL r = GetUserName(user_name, &len);
374 if (r != 0) {
375 SetDlgItemText(dlg, IDC_SSHUSERNAME, user_name);
376 }
377 break;
378 }
379 default:
380 // ��������������������
381 pvar->session_settings.DefaultUserType = 0;
382 }
383 }
384
385 if (strlen(pvar->ssh2_password) > 0) {
386 SetDlgItemText(dlg, IDC_SSHPASSWORD, pvar->ssh2_password);
387 if (pvar->ssh2_autologin == 1) {
388 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD), FALSE);
389 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORDCAPTION), FALSE);
390 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD_OPTION), FALSE);
391 }
392 }
393
394 SetDlgItemText(dlg, IDC_RSAFILENAME,
395 pvar->session_settings.DefaultRSAPrivateKeyFile);
396 SetDlgItemText(dlg, IDC_HOSTRSAFILENAME,
397 pvar->session_settings.DefaultRhostsHostPrivateKeyFile);
398 SetDlgItemText(dlg, IDC_LOCALUSERNAME,
399 pvar->session_settings.DefaultRhostsLocalUserName);
400
401 if (pvar->ssh2_authmethod == SSH_AUTH_PASSWORD) {
402 CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, IDC_SSHUSEPASSWORD);
403
404 } else if (pvar->ssh2_authmethod == SSH_AUTH_RSA) {
405 CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, IDC_SSHUSERSA);
406
407 SetDlgItemText(dlg, IDC_RSAFILENAME, pvar->ssh2_keyfile);
408 if (pvar->ssh2_autologin == 1) {
409 EnableWindow(GetDlgItem(dlg, IDC_CHOOSERSAFILE), FALSE);
410 EnableWindow(GetDlgItem(dlg, IDC_RSAFILENAME), FALSE);
411 }
412
413 // /auth=challenge ������ (2007.10.5 maya)
414 } else if (pvar->ssh2_authmethod == SSH_AUTH_TIS) {
415 CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, IDC_SSHUSETIS);
416 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD), FALSE);
417 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD_OPTION), FALSE);
418 SetDlgItemText(dlg, IDC_SSHPASSWORD, "");
419
420 // /auth=pageant ������
421 } else if (pvar->ssh2_authmethod == SSH_AUTH_PAGEANT) {
422 CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, IDC_SSHUSEPAGEANT);
423 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD), FALSE);
424 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD_OPTION), FALSE);
425 SetDlgItemText(dlg, IDC_SSHPASSWORD, "");
426
427 } else {
428 // �f�t�H���g���F�����\�b�h���_�C�A���O�����f
429 set_auth_options_status(dlg, auth_types_to_control_IDs[default_method]);
430
431 update_server_supported_types(pvar, dlg);
432
433 // �z�X�g�m�F�_�C�A���O��������������=�E�B���h�E���A�N�e�B�u������������
434 // �� SetFocus �����s�����A�R�}���h���C�����n�������F��������������������
435 // �����������A�������O�C���L������ SetFocus ������ (2009.1.31 maya)
436 if (default_method == SSH_AUTH_TIS) {
437 /* we disabled the password control, so fix the focus */
438 SetFocus(GetDlgItem(dlg, IDC_SSHUSETIS));
439 }
440 else if (default_method == SSH_AUTH_PAGEANT) {
441 SetFocus(GetDlgItem(dlg, IDC_SSHUSEPAGEANT));
442 }
443
444 }
445
446 if (GetWindowTextLength(GetDlgItem(dlg, IDC_SSHUSERNAME)) == 0) {
447 SetFocus(GetDlgItem(dlg, IDC_SSHUSERNAME));
448 }
449 else if (pvar->ask4passwd == 1) {
450 SetFocus(GetDlgItem(dlg, IDC_SSHPASSWORD));
451 }
452
453 // '/I' �w�������������������������� (2005.9.5 yutaka)
454 if (pvar->ts->Minimize) {
455 //20050822���� start T.Takahashi
456 ShowWindow(dlg,SW_MINIMIZE);
457 //20050822���� end T.Takahashi
458 }
459 }
460
461 static char *alloc_control_text(HWND ctl)
462 {
463 int len = GetWindowTextLength(ctl);
464 char *result = malloc(len + 1);
465
466 if (result != NULL) {
467 GetWindowText(ctl, result, len + 1);
468 result[len] = 0;
469 }
470
471 return result;
472 }
473
474 static int get_key_file_name(HWND parent, char *buf, int bufsize, PTInstVar pvar)
475 {
476 OPENFILENAME params;
477 char fullname_buf[2048] = "identity";
478 char filter[MAX_UIMSG];
479
480 ZeroMemory(&params, sizeof(params));
481 params.lStructSize = get_OPENFILENAME_SIZE();
482 params.hwndOwner = parent;
483 // �t�B���^������ (2004.12.19 yutaka)
484 // 3�t�@�C���t�B���^������ (2005.4.26 yutaka)
485 UTIL_get_lang_msg("FILEDLG_OPEN_PRIVATEKEY_FILTER", pvar,
486 "identity files\\0identity;id_rsa;id_dsa;id_ecdsa;id_ed25519;*.ppk;*.pem\\0identity(RSA1)\\0identity\\0id_rsa(SSH2)\\0id_rsa\\0id_dsa(SSH2)\\0id_dsa\\0id_ecdsa(SSH2)\\0id_ecdsa\\0id_ed25519(SSH2)\\0id_ed25519\\0PuTTY(*.ppk)\\0*.ppk\\0PEM files(*.pem)\\0*.pem\\0all(*.*)\\0*.*\\0\\0");
487 memcpy(filter, pvar->ts->UIMsg, sizeof(filter));
488 params.lpstrFilter = filter;
489 params.lpstrCustomFilter = NULL;
490 params.nFilterIndex = 0;
491 buf[0] = 0;
492 params.lpstrFile = fullname_buf;
493 params.nMaxFile = sizeof(fullname_buf);
494 params.lpstrFileTitle = NULL;
495 params.lpstrInitialDir = NULL;
496 UTIL_get_lang_msg("FILEDLG_OPEN_PRIVATEKEY_TITLE", pvar,
497 "Choose a file with the RSA/DSA/ECDSA/ED25519 private key");
498 params.lpstrTitle = pvar->ts->UIMsg;
499 params.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
500 params.lpstrDefExt = NULL;
501
502 if (GetOpenFileName(&params) != 0) {
503 copy_teraterm_dir_relative_path(buf, bufsize, fullname_buf);
504 return 1;
505 } else {
506 return 0;
507 }
508 }
509
510 static void choose_RSA_key_file(HWND dlg, PTInstVar pvar)
511 {
512 char buf[1024];
513
514 if (get_key_file_name(dlg, buf, sizeof(buf), pvar)) {
515 SetDlgItemText(dlg, IDC_RSAFILENAME, buf);
516 }
517 }
518
519 static void choose_host_RSA_key_file(HWND dlg, PTInstVar pvar)
520 {
521 char buf[1024];
522
523 if (get_key_file_name(dlg, buf, sizeof(buf), pvar)) {
524 SetDlgItemText(dlg, IDC_HOSTRSAFILENAME, buf);
525 }
526 }
527
528 static BOOL end_auth_dlg(PTInstVar pvar, HWND dlg)
529 {
530 int method = SSH_AUTH_PASSWORD;
531 char *password =
532 alloc_control_text(GetDlgItem(dlg, IDC_SSHPASSWORD));
533 Key *key_pair = NULL;
534
535 if (IsDlgButtonChecked(dlg, IDC_SSHUSERSA)) {
536 method = SSH_AUTH_RSA;
537 } else if (IsDlgButtonChecked(dlg, IDC_SSHUSERHOSTS)) {
538 if (GetWindowTextLength(GetDlgItem(dlg, IDC_HOSTRSAFILENAME)) > 0) {
539 method = SSH_AUTH_RHOSTS_RSA;
540 } else {
541 method = SSH_AUTH_RHOSTS;
542 }
543 } else if (IsDlgButtonChecked(dlg, IDC_SSHUSETIS)) {
544 method = SSH_AUTH_TIS;
545 } else if (IsDlgButtonChecked(dlg, IDC_SSHUSEPAGEANT)) {
546 method = SSH_AUTH_PAGEANT;
547 }
548
549 if (method == SSH_AUTH_RSA || method == SSH_AUTH_RHOSTS_RSA) {
550 char keyfile[2048];
551 int file_ctl_ID =
552 method == SSH_AUTH_RSA ? IDC_RSAFILENAME : IDC_HOSTRSAFILENAME;
553
554 keyfile[0] = 0;
555 GetDlgItemText(dlg, file_ctl_ID, keyfile, sizeof(keyfile));
556 if (keyfile[0] == 0) {
557 UTIL_get_lang_msg("MSG_KEYSPECIFY_ERROR", pvar,
558 "You must specify a file containing the RSA/DSA/ECDSA/ED25519 private key.");
559 notify_nonfatal_error(pvar, pvar->ts->UIMsg);
560 SetFocus(GetDlgItem(dlg, file_ctl_ID));
561 destroy_malloced_string(&password);
562 return FALSE;
563 }
564
565 if (SSHv1(pvar)) {
566 BOOL invalid_passphrase = FALSE;
567
568 key_pair = KEYFILES_read_private_key(pvar, keyfile, password,
569 &invalid_passphrase,
570 FALSE);
571
572 if (key_pair == NULL) {
573 if (invalid_passphrase) {
574 HWND passwordCtl = GetDlgItem(dlg, IDC_SSHPASSWORD);
575
576 SetFocus(passwordCtl);
577 SendMessage(passwordCtl, EM_SETSEL, 0, -1);
578 } else {
579 SetFocus(GetDlgItem(dlg, file_ctl_ID));
580 }
581 destroy_malloced_string(&password);
582 return FALSE;
583 }
584
585 } else { // SSH2(yutaka)
586 BOOL invalid_passphrase = FALSE;
587 char errmsg[256];
588 FILE *fp = NULL;
589 ssh2_keyfile_type keyfile_type;
590
591 memset(errmsg, 0, sizeof(errmsg));
592
593 keyfile_type = get_ssh2_keytype(keyfile, &fp, errmsg, sizeof(errmsg));
594 switch (keyfile_type) {
595 case SSH2_KEYFILE_TYPE_OPENSSH:
596 {
597 key_pair = read_SSH2_private_key(pvar, fp, password,
598 &invalid_passphrase,
599 FALSE,
600 errmsg,
601 sizeof(errmsg)
602 );
603 break;
604 }
605 case SSH2_KEYFILE_TYPE_PUTTY:
606 {
607 key_pair = read_SSH2_PuTTY_private_key(pvar, fp, password,
608 &invalid_passphrase,
609 FALSE,
610 errmsg,
611 sizeof(errmsg)
612 );
613 break;
614 }
615 case SSH2_KEYFILE_TYPE_SECSH:
616 {
617 key_pair = read_SSH2_SECSH_private_key(pvar, fp, password,
618 &invalid_passphrase,
619 FALSE,
620 errmsg,
621 sizeof(errmsg)
622 );
623 break;
624 }
625 default:
626 {
627 char buf[1024];
628
629 // �t�@�C�����J�����������t�@�C���`�����s��������������������
630 if (fp != NULL) {
631 key_pair = read_SSH2_private_key(pvar, fp, password,
632 &invalid_passphrase,
633 FALSE,
634 errmsg,
635 sizeof(errmsg)
636 );
637 break;
638 }
639
640 UTIL_get_lang_msg("MSG_READKEY_ERROR", pvar,
641 "read error SSH2 private key file\r\n%s");
642 _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg, errmsg);
643 notify_nonfatal_error(pvar, buf);
644 // ���������������������� SSH2 �������t�@�C�����J����������
645 // ���t�@�C�����I���{�^�����t�H�[�J�X������
646 SetFocus(GetDlgItem(dlg, IDC_CHOOSERSAFILE));
647 destroy_malloced_string(&password);
648 return FALSE;
649 }
650 }
651
652 if (key_pair == NULL) { // read error
653 char buf[1024];
654 UTIL_get_lang_msg("MSG_READKEY_ERROR", pvar,
655 "read error SSH2 private key file\r\n%s");
656 _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg, errmsg);
657 notify_nonfatal_error(pvar, buf);
658 // �p�X�t���[�Y���������v����������������IDC_SSHPASSWORD���t�H�[�J�X������ (2006.10.29 yasuhide)
659 if (invalid_passphrase) {
660 HWND passwordCtl = GetDlgItem(dlg, IDC_SSHPASSWORD);
661
662 SetFocus(passwordCtl);
663 SendMessage(passwordCtl, EM_SETSEL, 0, -1);
664 } else {
665 SetFocus(GetDlgItem(dlg, file_ctl_ID));
666 }
667 destroy_malloced_string(&password);
668 return FALSE;
669 }
670
671 }
672
673 }
674 else if (method == SSH_AUTH_PAGEANT) {
675 pvar->pageant_key = NULL;
676 pvar->pageant_curkey = NULL;
677 pvar->pageant_keylistlen = 0;
678 pvar->pageant_keycount = 0;
679 pvar->pageant_keycurrent = 0;
680 pvar->pageant_keyfinal=FALSE;
681
682 // Pageant �����M
683 if (SSHv1(pvar)) {
684 pvar->pageant_keylistlen = putty_get_ssh1_keylist(&pvar->pageant_key);
685 }
686 else {
687 pvar->pageant_keylistlen = putty_get_ssh2_keylist(&pvar->pageant_key);
688 }
689 if (pvar->pageant_keylistlen == 0) {
690 UTIL_get_lang_msg("MSG_PAGEANT_NOTFOUND", pvar,
691 "Can't find Pageant.");
692 notify_nonfatal_error(pvar, pvar->ts->UIMsg);
693
694 return FALSE;
695 }
696 pvar->pageant_curkey = pvar->pageant_key;
697
698 // ������
699 pvar->pageant_keycount = get_uint32_MSBfirst(pvar->pageant_curkey);
700 if (pvar->pageant_keycount == 0) {
701 UTIL_get_lang_msg("MSG_PAGEANT_NOKEY", pvar,
702 "Pageant has no valid key.");
703 notify_nonfatal_error(pvar, pvar->ts->UIMsg);
704
705 return FALSE;
706 }
707 pvar->pageant_curkey += 4;
708 }
709
710 /* from here on, we cannot fail, so just munge cur_cred in place */
711 pvar->auth_state.cur_cred.method = method;
712 pvar->auth_state.cur_cred.key_pair = key_pair;
713 /* we can't change the user name once it's set. It may already have
714 been sent to the server, and it can only be sent once. */
715 if (pvar->auth_state.user == NULL) {
716 pvar->auth_state.user =
717 alloc_control_text(GetDlgItem(dlg, IDC_SSHUSERNAME));
718 }
719
720 // �p�X���[�h���������������������������� (2006.8.3 yutaka)
721 if (SendMessage(GetDlgItem(dlg, IDC_REMEMBER_PASSWORD), BM_GETCHECK, 0,0) == BST_CHECKED) {
722 pvar->settings.remember_password = 1; // �o��������
723 pvar->ts_SSH->remember_password = 1;
724 } else {
725 pvar->settings.remember_password = 0; // ���������������Y����
726 pvar->ts_SSH->remember_password = 0;
727 }
728
729 // ���J���F���������A�Z�b�V�������������p�X���[�h���g�����������������������������������B
730 // (2005.4.8 yutaka)
731 if (method == SSH_AUTH_PASSWORD || method == SSH_AUTH_RSA) {
732 pvar->auth_state.cur_cred.password = password;
733 } else {
734 destroy_malloced_string(&password);
735 }
736 if (method == SSH_AUTH_RHOSTS || method == SSH_AUTH_RHOSTS_RSA) {
737 if (pvar->session_settings.DefaultAuthMethod != SSH_AUTH_RHOSTS) {
738 UTIL_get_lang_msg("MSG_RHOSTS_NOTDEFAULT_ERROR", pvar,
739 "Rhosts authentication will probably fail because it was not "
740 "the default authentication method.\n"
741 "To use Rhosts authentication "
742 "in TTSSH, you need to set it to be the default by restarting\n"
743 "TTSSH and selecting \"SSH Authentication...\" from the Setup menu "
744 "before connecting.");
745 notify_nonfatal_error(pvar, pvar->ts->UIMsg);
746 }
747
748 pvar->auth_state.cur_cred.rhosts_client_user =
749 alloc_control_text(GetDlgItem(dlg, IDC_LOCALUSERNAME));
750 }
751 pvar->auth_state.auth_dialog = NULL;
752
753 GetDlgItemText(dlg, IDC_RSAFILENAME,
754 pvar->session_settings.DefaultRSAPrivateKeyFile,
755 sizeof(pvar->session_settings.
756 DefaultRSAPrivateKeyFile));
757 GetDlgItemText(dlg, IDC_HOSTRSAFILENAME,
758 pvar->session_settings.DefaultRhostsHostPrivateKeyFile,
759 sizeof(pvar->session_settings.
760 DefaultRhostsHostPrivateKeyFile));
761 GetDlgItemText(dlg, IDC_LOCALUSERNAME,
762 pvar->session_settings.DefaultRhostsLocalUserName,
763 sizeof(pvar->session_settings.
764 DefaultRhostsLocalUserName));
765
766 if (SSHv1(pvar)) {
767 SSH_notify_user_name(pvar);
768 SSH_notify_cred(pvar);
769 } else {
770 // for SSH2(yutaka)
771 do_SSH2_userauth(pvar);
772 }
773
774 EndDialog(dlg, 1);
775
776 return TRUE;
777 }
778
779 /**
780 * �N���b�v�{�[�h����ANSI����������������
781 * �����������K�v��������strlen()��������
782 * @param hWnd
783 * @param emtpy TRUE�������N���b�v�{�[�h����������
784 * @retval �����������|�C���^ �g�p��free()��������
785 * ����������(�������G���[��)��NULL
786 */
787 char *GetClipboardTextA(HWND hWnd, BOOL empty)
788 {
789 HGLOBAL hGlobal;
790 const char *lpStr;
791 size_t length;
792 char *pool;
793
794 OpenClipboard(hWnd);
795 hGlobal = (HGLOBAL)GetClipboardData(CF_TEXT);
796 if (hGlobal == NULL) {
797 CloseClipboard();
798 return NULL;
799 }
800 lpStr = (const char *)GlobalLock(hGlobal);
801 length = GlobalSize(hGlobal);
802 if (length == 0) {
803 pool = NULL;
804 } else {
805 pool = (char *)malloc(length + 1); // +1 for terminator
806 memcpy(pool, lpStr, length);
807 pool[length] = '\0';
808 }
809 GlobalUnlock(hGlobal);
810 if (empty) {
811 EmptyClipboard();
812 }
813 CloseClipboard();
814
815 return pool;
816 }
817
818
819 BOOL autologin_sent_none;
820 static INT_PTR CALLBACK auth_dlg_proc(HWND dlg, UINT msg, WPARAM wParam,
821 LPARAM lParam)
822 {
823 const int IDC_TIMER1 = 300; // �������O�C�����L��������
824 const int IDC_TIMER2 = 301; // �T�|�[�g�������������\�b�h�������`�F�b�N(CheckAuthListFirst)
825 const int IDC_TIMER3 = 302; // challenge �� ask4passwd ��CheckAuthListFirst �� FALSE ������
826 const int autologin_timeout = 10; // �~���b
827 PTInstVar pvar;
828 static BOOL UseControlChar;
829 static BOOL ShowPassPhrase;
830 static HICON hIconDropdown;
831 TCHAR uimsg[MAX_UIMSG];
832
833 switch (msg) {
834 case WM_INITDIALOG:
835 pvar = (PTInstVar) lParam;
836 pvar->auth_state.auth_dialog = dlg;
837 SetWindowLongPtr(dlg, DWLP_USER, lParam);
838
839 UseControlChar = TRUE;
840 ShowPassPhrase = FALSE;
841 init_auth_dlg(pvar, dlg, &UseControlChar);
842
843 // "��"�������Z�b�g����
844 hIconDropdown = LoadImage(hInst, MAKEINTRESOURCE(IDI_DROPDOWN),
845 IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
846 SendMessage(GetDlgItem(dlg, IDC_USERNAME_OPTION), BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIconDropdown);
847 SendMessage(GetDlgItem(dlg, IDC_SSHPASSWORD_OPTION), BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIconDropdown);
848
849 // SSH2 autologin���L�����������A�^�C�}���d�|�����B (2004.12.1 yutaka)
850 if (pvar->ssh2_autologin == 1) {
851 autologin_sent_none = FALSE;
852 SetTimer(dlg, IDC_TIMER1, autologin_timeout, 0);
853 }
854 else {
855 // �T�|�[�g�������������\�b�h���`�F�b�N�����B(2007.9.24 maya)
856 // �������L�����A�����������s�����������A���[�U�����m����������
857 if (pvar->session_settings.CheckAuthListFirst &&
858 !pvar->tryed_ssh2_authlist &&
859 GetWindowTextLength(GetDlgItem(dlg, IDC_SSHUSERNAME)) > 0) {
860 SetTimer(dlg, IDC_TIMER2, autologin_timeout, 0);
861 }
862 // /auth=challenge �� /ask4passwd ���w���������������[�U�����m����������
863 // �������AOK �{�^���������� TIS auth �_�C�A���O���o��
864 else if (pvar->ssh2_authmethod == SSH_AUTH_TIS &&
865 pvar->ask4passwd &&
866 GetWindowTextLength(GetDlgItem(dlg, IDC_SSHUSERNAME)) > 0) {
867 SetTimer(dlg, IDC_TIMER3, autologin_timeout, 0);
868 }
869 }
870 CenterWindow(dlg, GetParent(dlg));
871 return FALSE; /* because we set the focus */
872
873 case WM_TIMER:
874 pvar = (PTInstVar) GetWindowLongPtr(dlg, DWLP_USER);
875 // �F�������������������A�F���f�[�^�����M�����B�����������A�������B(2004.12.16 yutaka)
876 if (wParam == IDC_TIMER1) {
877 // �������O�C��������
878 if (!(pvar->ssh_state.status_flags & STATUS_DONT_SEND_USER_NAME) &&
879 (pvar->ssh_state.status_flags & STATUS_HOST_OK)) {
880 if (SSHv2(pvar) &&
881 pvar->session_settings.CheckAuthListFirst &&
882 !pvar->tryed_ssh2_authlist) {
883 if (!autologin_sent_none) {
884 autologin_sent_none = TRUE;
885
886 // �_�C�A���O�����[�U������������
887 if (pvar->auth_state.user == NULL) {
888 pvar->auth_state.user =
889 alloc_control_text(GetDlgItem(dlg, IDC_SSHUSERNAME));
890 }
891
892 // CheckAuthListFirst �� TRUE �������� AuthList ���A����������������
893 // IDOK �����������i�����������A�F�����\�b�h none ������ (2008.10.12 maya)
894 do_SSH2_userauth(pvar);
895 }
896 //else {
897 // none �������������A����������������
898 //}
899 }
900 else {
901 // SSH1 ������
902 // ������ CheckAuthListFirst �� FALSE ������
903 // ������ CheckAuthListFirst TRUE ���Aauthlist ���A������������
904 KillTimer(dlg, IDC_TIMER1);
905
906 // �_�C�A���O�����[�U������������
907 if (pvar->auth_state.user == NULL) {
908 pvar->auth_state.user =
909 alloc_control_text(GetDlgItem(dlg, IDC_SSHUSERNAME));
910 }
911
912 SendMessage(dlg, WM_COMMAND, IDOK, 0);
913 }
914 }
915 }
916 else if (wParam == IDC_TIMER2) {
917 // authlist ����������
918 if (!(pvar->ssh_state.status_flags & STATUS_DONT_SEND_USER_NAME) &&
919 (pvar->ssh_state.status_flags & STATUS_HOST_OK)) {
920 if (SSHv2(pvar)) {
921 KillTimer(dlg, IDC_TIMER2);
922
923 // �_�C�A���O�����[�U������������
924 if (pvar->auth_state.user == NULL) {
925 pvar->auth_state.user =
926 alloc_control_text(GetDlgItem(dlg, IDC_SSHUSERNAME));
927 }
928
929 // ���[�U�������X��������
930 EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAME), FALSE);
931 EnableWindow(GetDlgItem(dlg, IDC_USERNAME_OPTION), FALSE);
932
933 // �F�����\�b�h none ������
934 do_SSH2_userauth(pvar);
935
936 // TIS �p�� OK �����������F�������s������������������
937 // Unexpected SSH2 message �������B
938 }
939 else if (SSHv1(pvar)) {
940 KillTimer(dlg, IDC_TIMER2);
941
942 // TIS �p�� OK ������
943 if (pvar->ssh2_authmethod == SSH_AUTH_TIS) {
944 SendMessage(dlg, WM_COMMAND, IDOK, 0);
945 }
946 // SSH1 �����F�����\�b�h none ����������
947 }
948 // �v���g�R���o�[�W�����m���O������������
949 }
950 }
951 else if (wParam == IDC_TIMER3) {
952 if (!(pvar->ssh_state.status_flags & STATUS_DONT_SEND_USER_NAME) &&
953 (pvar->ssh_state.status_flags & STATUS_HOST_OK)) {
954 if (SSHv2(pvar) || SSHv1(pvar)) {
955 KillTimer(dlg, IDC_TIMER3);
956
957 // TIS �p�� OK ������
958 SendMessage(dlg, WM_COMMAND, IDOK, 0);
959 }
960 // �v���g�R���o�[�W�����m���O������������
961 }
962 }
963 return FALSE;
964
965 case WM_COMMAND:
966 pvar = (PTInstVar) GetWindowLongPtr(dlg, DWLP_USER);
967
968 switch (LOWORD(wParam)) {
969 case IDOK:
970 // �F�������T�[�o�������f�������������A�L�����Z�������������B(2014.3.31 yutaka)
971 if (!pvar->cv->Ready) {
972 goto canceled;
973 }
974
975 // �F�������������������A�F���f�[�^�����M�����B�����������A�������B(2001.1.25 yutaka)
976 if (pvar->userauth_retry_count == 0 &&
977 ((pvar->ssh_state.status_flags & STATUS_DONT_SEND_USER_NAME) ||
978 !(pvar->ssh_state.status_flags & STATUS_HOST_OK))) {
979 return FALSE;
980 }
981 else if (SSHv2(pvar) &&
982 pvar->session_settings.CheckAuthListFirst &&
983 !pvar->tryed_ssh2_authlist) {
984 // CheckAuthListFirst ���L�����F������������������������
985 // OK �������������������� (2008.10.4 maya)
986 return FALSE;
987 }
988
989 return end_auth_dlg(pvar, dlg);
990
991 case IDCANCEL: /* kill the connection */
992 canceled:
993 pvar->auth_state.auth_dialog = NULL;
994 notify_closed_connection(pvar, "authentication cancelled");
995 EndDialog(dlg, 0);
996 return TRUE;
997
998 case IDC_SSHUSERNAME:
999 // ���[�U�����t�H�[�J�X������������ (2007.9.29 maya)
1000 if (!(pvar->ssh_state.status_flags & STATUS_DONT_SEND_USER_NAME) &&
1001 (pvar->ssh_state.status_flags & STATUS_HOST_OK) &&
1002 HIWORD(wParam) == EN_KILLFOCUS) {
1003 // �������L���������������s��������������
1004 if (SSHv2(pvar) &&
1005 pvar->session_settings.CheckAuthListFirst &&
1006 !pvar->tryed_ssh2_authlist) {
1007 // �_�C�A���O�����[�U�������f
1008 if (pvar->auth_state.user == NULL) {
1009 pvar->auth_state.user =
1010 alloc_control_text(GetDlgItem(dlg, IDC_SSHUSERNAME));
1011 }
1012
1013 // ���[�U���������������������`�F�b�N����
1014 if (strlen(pvar->auth_state.user) == 0) {
1015 return FALSE;
1016 }
1017
1018 // ���[�U�������X��������
1019 EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAME), FALSE);
1020 EnableWindow(GetDlgItem(dlg, IDC_USERNAME_OPTION), FALSE);
1021
1022 // �F�����\�b�h none ������
1023 do_SSH2_userauth(pvar);
1024 return TRUE;
1025 }
1026 }
1027
1028 return FALSE;
1029
1030 case IDC_SSHUSEPASSWORD:
1031 case IDC_SSHUSERSA:
1032 case IDC_SSHUSERHOSTS:
1033 case IDC_SSHUSETIS:
1034 case IDC_SSHUSEPAGEANT:
1035 set_auth_options_status(dlg, LOWORD(wParam));
1036 return TRUE;
1037
1038 case IDC_CHOOSERSAFILE:
1039 choose_RSA_key_file(dlg, pvar);
1040 return TRUE;
1041
1042 case IDC_CHOOSEHOSTRSAFILE:
1043 choose_host_RSA_key_file(dlg, pvar);
1044 return TRUE;
1045
1046 case IDC_FORWARD_AGENT:
1047 // �����Z�b�V�������������f������ (2008.12.4 maya)
1048 pvar->session_settings.ForwardAgent = IsDlgButtonChecked(dlg, IDC_FORWARD_AGENT);
1049 return TRUE;
1050
1051 case IDC_SSHPASSWORD_OPTION: {
1052 RECT rect;
1053 HWND hWndButton;
1054 int result;
1055 HMENU hMenu= CreatePopupMenu();
1056 char *clipboard = GetClipboardTextA(dlg, FALSE);
1057 GetI18nStrT("TTSSH", "DLG_AUTH_PASTE_CLIPBOARD",
1058 uimsg, _countof(uimsg),
1059 "Paste from &clipboard",
1060 pvar->ts->UILanguageFile);
1061 AppendMenu(hMenu, MF_ENABLED | MF_STRING | (clipboard == NULL ? MFS_DISABLED : 0), 1, uimsg);
1062 GetI18nStrT("ttssh", "DLG_AUTH_CLEAR_CLIPBOARD",
1063 uimsg, _countof(uimsg),
1064 "Paste from &clipboard and cl&ear clipboard",
1065 pvar->ts->UILanguageFile);
1066 AppendMenu(hMenu, MF_ENABLED | MF_STRING | (clipboard == NULL ? MFS_DISABLED : 0), 2, uimsg);
1067 GetI18nStrT("ttssh", "DLG_AUTH_USE_CONTORL_CHARACTERS",
1068 uimsg, _countof(uimsg),
1069 "Use control charac&ters",
1070 pvar->ts->UILanguageFile);
1071 AppendMenu(hMenu, MF_ENABLED | MF_STRING | (UseControlChar ? MFS_CHECKED : 0), 3, uimsg);
1072 GetI18nStrT("ttssh", "DLG_AUTH_SHOW_PASSPHRASE",
1073 uimsg, _countof(uimsg),
1074 "&Show passphrase",
1075 pvar->ts->UILanguageFile);
1076 AppendMenu(hMenu, MF_ENABLED | MF_STRING | (ShowPassPhrase ? MFS_CHECKED : 0), 4, uimsg);
1077 if (clipboard != NULL) {
1078 free(clipboard);
1079 }
1080 hWndButton = GetDlgItem(dlg, IDC_SSHPASSWORD_OPTION);
1081 GetWindowRect(hWndButton, &rect);
1082 result = TrackPopupMenu(hMenu, TPM_RETURNCMD, rect.left, rect.bottom, 0 , hWndButton, NULL);
1083 DestroyMenu(hMenu);
1084 switch(result) {
1085 case 1:
1086 case 2: {
1087 // �N���b�v�{�[�h�����y�[�X�g
1088 BOOL clear_clipboard = result == 2;
1089 clipboard = GetClipboardTextA(dlg, clear_clipboard);
1090 if (clipboard != NULL) {
1091 SetDlgItemTextA(dlg, IDC_SSHPASSWORD, clipboard);
1092 free(clipboard);
1093 SendDlgItemMessage(dlg, IDC_SSHPASSWORD, EM_SETSEL, 0, -1);
1094 SendMessage(dlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(dlg, IDC_SSHPASSWORD), TRUE);
1095 return FALSE;
1096 }
1097 return TRUE;
1098 }
1099 case 3:
1100 // �����R�[�h�g�p/���g�p
1101 UseControlChar = !UseControlChar;
1102 break;
1103 case 4:
1104 // �p�X�t���[�Y�\��/���\��
1105 ShowPassPhrase = !ShowPassPhrase;
1106 {
1107 // ������ on/off ������������
1108 HWND hWnd = GetDlgItem(dlg, IDC_SSHPASSWORD);
1109 static wchar_t password_char;
1110 if (password_char == 0) {
1111 wchar_t c = (wchar_t)SendMessage(hWnd, EM_GETPASSWORDCHAR, 0, 0);
1112 password_char = c;
1113 }
1114 if (ShowPassPhrase) {
1115 SendMessage(hWnd, EM_SETPASSWORDCHAR, 0, 0);
1116 } else {
1117 #if !defined(UNICODE)
1118 if (password_char < 0x100) {
1119 SendMessageA(hWnd, EM_SETPASSWORDCHAR, (WPARAM)password_char, 0);
1120 } else {
1121 // TODO W�n������ ����������������
1122 //SendMessageW(hWnd, EM_SETPASSWORDCHAR, (WPARAM)password_char, 0);
1123 SendMessageA(hWnd, EM_SETPASSWORDCHAR, (WPARAM)'*', 0);
1124 }
1125 #else
1126 SendMessageW(hWnd, EM_SETPASSWORDCHAR, (WPARAM)password_char, 0);
1127 #endif
1128 }
1129 //InvalidateRect(hWnd, NULL, TRUE);
1130 SendDlgItemMessage(dlg, IDC_SSHPASSWORD, EM_SETSEL, 0, -1);
1131 SendMessage(dlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(dlg, IDC_SSHPASSWORD), TRUE);
1132 return TRUE;
1133 }
1134 break;
1135 }
1136 break;
1137 }
1138
1139 case IDC_USERNAME_OPTION: {
1140 RECT rect;
1141 HWND hWndButton;
1142 HMENU hMenu= CreatePopupMenu();
1143 int result;
1144 const BOOL DisableDefaultUserName = pvar->session_settings.DefaultUserName[0] == 0;
1145 GetI18nStrT("TTSSH", "DLG_AUTH_USE_DEFAULT_USERNAME",
1146 uimsg, _countof(uimsg),
1147 "Use &default username",
1148 pvar->ts->UILanguageFile);
1149 AppendMenu(hMenu, MF_ENABLED | MF_STRING | (DisableDefaultUserName ? MFS_DISABLED : 0), 1,
1150 uimsg);
1151 GetI18nStrT("TTSSH", "DLG_AUTH_USE_LOGON_USERNAME",
1152 uimsg, _countof(uimsg),
1153 "Use &logon username",
1154 pvar->ts->UILanguageFile);
1155 AppendMenu(hMenu, MF_ENABLED | MF_STRING, 2, uimsg);
1156 hWndButton = GetDlgItem(dlg, IDC_USERNAME_OPTION);
1157 GetWindowRect(hWndButton, &rect);
1158 result = TrackPopupMenu(hMenu, TPM_RETURNCMD, rect.left, rect.bottom, 0 , hWndButton, NULL);
1159 DestroyMenu(hMenu);
1160 switch (result) {
1161 case 1:
1162 SetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->session_settings.DefaultUserName);
1163 goto after_user_name_set;
1164 case 2: {
1165 TCHAR user_name[UNLEN+1];
1166 DWORD len = _countof(user_name);
1167 BOOL r = GetUserName(user_name, &len);
1168 if (r == 0) {
1169 break;
1170 }
1171 SetDlgItemText(dlg, IDC_SSHUSERNAME, user_name);
1172 after_user_name_set:
1173 SendDlgItemMessage(dlg, IDC_SSHUSERNAME, EM_SETSEL, 0, -1);
1174 SendMessage(dlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(dlg, IDC_SSHUSERNAME), TRUE);
1175 break;
1176 }
1177 }
1178 return TRUE;
1179 }
1180
1181 default:
1182 return FALSE;
1183 }
1184
1185 case WM_DESTROY:
1186 if (hIconDropdown != NULL) {
1187 DeleteObject(hIconDropdown);
1188 }
1189 return FALSE;
1190
1191 default:
1192 return FALSE;
1193 }
1194 }
1195
1196 char *AUTH_get_user_name(PTInstVar pvar)
1197 {
1198 return pvar->auth_state.user;
1199 }
1200
1201 int AUTH_set_supported_auth_types(PTInstVar pvar, int types)
1202 {
1203 logprintf(LOG_LEVEL_VERBOSE, "Server reports supported authentication method mask = %d", types);
1204
1205 if (SSHv1(pvar)) {
1206 types &= (1 << SSH_AUTH_PASSWORD) | (1 << SSH_AUTH_RSA)
1207 | (1 << SSH_AUTH_RHOSTS_RSA) | (1 << SSH_AUTH_RHOSTS)
1208 | (1 << SSH_AUTH_TIS) | (1 << SSH_AUTH_PAGEANT);
1209 } else {
1210 // for SSH2(yutaka)
1211 // types &= (1 << SSH_AUTH_PASSWORD);
1212 // ���J���F�����L�������� (2004.12.18 yutaka)
1213 // TIS�������BSSH2����keyboard-interactive�����������B(2005.3.12 yutaka)
1214 types &= (1 << SSH_AUTH_PASSWORD) | (1 << SSH_AUTH_RSA)
1215 | (1 << SSH_AUTH_TIS) | (1 << SSH_AUTH_PAGEANT);
1216 }
1217 pvar->auth_state.supported_types = types;
1218
1219 if (types == 0) {
1220 UTIL_get_lang_msg("MSG_NOAUTHMETHOD_ERROR", pvar,
1221 "Server does not support any of the authentication options\n"
1222 "provided by TTSSH. This connection will now close.");
1223 notify_fatal_error(pvar, pvar->ts->UIMsg, TRUE);
1224 return 0;
1225 } else {
1226 if (pvar->auth_state.auth_dialog != NULL) {
1227 update_server_supported_types(pvar, pvar->auth_state.auth_dialog);
1228 }
1229
1230 return 1;
1231 }
1232 }
1233
1234 static void start_user_auth(PTInstVar pvar)
1235 {
1236 // �F���_�C�A���O���\�������� (2004.12.1 yutaka)
1237 PostMessage(pvar->NotificationWindow, WM_COMMAND, (WPARAM) ID_SSHAUTH,
1238 (LPARAM) NULL);
1239 pvar->auth_state.cur_cred.method = SSH_AUTH_NONE;
1240 }
1241
1242 static void try_default_auth(PTInstVar pvar)
1243 {
1244 if (pvar->session_settings.TryDefaultAuth) {
1245 switch (pvar->session_settings.DefaultAuthMethod) {
1246 case SSH_AUTH_RSA:{
1247 BOOL invalid_passphrase;
1248 char password[] = "";
1249
1250 pvar->auth_state.cur_cred.key_pair
1251 =
1252 KEYFILES_read_private_key(pvar,
1253 pvar->session_settings.
1254 DefaultRSAPrivateKeyFile,
1255 password,
1256 &invalid_passphrase, TRUE);
1257 if (pvar->auth_state.cur_cred.key_pair == NULL) {
1258 return;
1259 } else {
1260 pvar->auth_state.cur_cred.method = SSH_AUTH_RSA;
1261 }
1262 break;
1263 }
1264
1265 case SSH_AUTH_RHOSTS:
1266 if (pvar->session_settings.
1267 DefaultRhostsHostPrivateKeyFile[0] != 0) {
1268 BOOL invalid_passphrase;
1269 char password[] = "";
1270
1271 pvar->auth_state.cur_cred.key_pair
1272 =
1273 KEYFILES_read_private_key(pvar,
1274 pvar->session_settings.
1275 DefaultRhostsHostPrivateKeyFile,
1276 password,
1277 &invalid_passphrase, TRUE);
1278 if (pvar->auth_state.cur_cred.key_pair == NULL) {
1279 return;
1280 } else {
1281 pvar->auth_state.cur_cred.method = SSH_AUTH_RHOSTS_RSA;
1282 }
1283 } else {
1284 pvar->auth_state.cur_cred.method = SSH_AUTH_RHOSTS;
1285 }
1286
1287 pvar->auth_state.cur_cred.rhosts_client_user =
1288 _strdup(pvar->session_settings.DefaultRhostsLocalUserName);
1289 break;
1290
1291 case SSH_AUTH_PAGEANT:
1292 pvar->auth_state.cur_cred.method = SSH_AUTH_PAGEANT;
1293 break;
1294
1295 case SSH_AUTH_PASSWORD:
1296 pvar->auth_state.cur_cred.password = _strdup("");
1297 pvar->auth_state.cur_cred.method = SSH_AUTH_PASSWORD;
1298 break;
1299
1300 case SSH_AUTH_TIS:
1301 default:
1302 return;
1303 }
1304
1305 pvar->auth_state.user =
1306 _strdup(pvar->session_settings.DefaultUserName);
1307 }
1308 }
1309
1310 void AUTH_notify_end_error(PTInstVar pvar)
1311 {
1312 if ((pvar->auth_state.flags & AUTH_START_USER_AUTH_ON_ERROR_END) != 0) {
1313 start_user_auth(pvar);
1314 pvar->auth_state.flags &= ~AUTH_START_USER_AUTH_ON_ERROR_END;
1315 }
1316 }
1317
1318 void AUTH_advance_to_next_cred(PTInstVar pvar)
1319 {
1320 logprintf(LOG_LEVEL_VERBOSE, "User authentication will be shown by %d method.", pvar->auth_state.cur_cred.method);
1321
1322 pvar->auth_state.failed_method = pvar->auth_state.cur_cred.method;
1323
1324 if (pvar->auth_state.cur_cred.method == SSH_AUTH_NONE) {
1325 try_default_auth(pvar);
1326
1327 if (pvar->auth_state.cur_cred.method == SSH_AUTH_NONE) {
1328 if (pvar->err_msg != NULL) {
1329 pvar->auth_state.flags |=
1330 AUTH_START_USER_AUTH_ON_ERROR_END;
1331 } else {
1332 // �������F���_�C�A���O���o�������� (2004.12.1 yutaka)
1333 // �R�}���h���C���w������������
1334 start_user_auth(pvar);
1335 }
1336 }
1337 } else {
1338 // �������F���_�C�A���O���o�������� (2004.12.1 yutaka)
1339 // �R�}���h���C���w������(/auth=xxxx)������
1340 start_user_auth(pvar);
1341 }
1342 }
1343
1344 static void init_TIS_dlg(PTInstVar pvar, HWND dlg)
1345 {
1346 char uimsg[MAX_UIMSG];
1347
1348 GetWindowText(dlg, uimsg, sizeof(uimsg));
1349 UTIL_get_lang_msg("DLG_TIS_TITLE", pvar, uimsg);
1350 SetWindowText(dlg, pvar->ts->UIMsg);
1351 GetDlgItemText(dlg, IDC_SSHAUTHBANNER, uimsg, sizeof(uimsg));
1352 UTIL_get_lang_msg("DLG_TIS_BANNER", pvar, uimsg);
1353 SetDlgItemText(dlg, IDC_SSHAUTHBANNER, pvar->ts->UIMsg);
1354 GetDlgItemText(dlg, IDOK, uimsg, sizeof(uimsg));
1355 UTIL_get_lang_msg("BTN_OK", pvar, uimsg);
1356 SetDlgItemText(dlg, IDOK, pvar->ts->UIMsg);
1357 GetDlgItemText(dlg, IDCANCEL, uimsg, sizeof(uimsg));
1358 UTIL_get_lang_msg("BTN_DISCONNECT", pvar, uimsg);
1359 SetDlgItemText(dlg, IDCANCEL, pvar->ts->UIMsg);
1360
1361 init_auth_machine_banner(pvar, dlg);
1362 init_password_control(pvar, dlg, IDC_SSHPASSWORD, NULL);
1363
1364 if (pvar->auth_state.TIS_prompt != NULL) {
1365 if (strlen(pvar->auth_state.TIS_prompt) > 10000) {
1366 pvar->auth_state.TIS_prompt[10000] = 0;
1367 }
1368 SetDlgItemText(dlg, IDC_SSHAUTHBANNER2,
1369 pvar->auth_state.TIS_prompt);
1370 destroy_malloced_string(&pvar->auth_state.TIS_prompt);
1371 }
1372
1373 if (pvar->auth_state.echo) {
1374 SendMessage(GetDlgItem(dlg, IDC_SSHPASSWORD), EM_SETPASSWORDCHAR, 0, 0);
1375 }
1376 }
1377
1378 static BOOL end_TIS_dlg(PTInstVar pvar, HWND dlg)
1379 {
1380 char *password =
1381 alloc_control_text(GetDlgItem(dlg, IDC_SSHPASSWORD));
1382
1383 pvar->auth_state.cur_cred.method = SSH_AUTH_TIS;
1384 pvar->auth_state.cur_cred.password = password;
1385 pvar->auth_state.auth_dialog = NULL;
1386
1387 // add
1388 if (SSHv2(pvar)) {
1389 pvar->keyboard_interactive_password_input = 1;
1390 handle_SSH2_userauth_inforeq(pvar);
1391 }
1392
1393 SSH_notify_cred(pvar);
1394
1395 EndDialog(dlg, 1);
1396 return TRUE;
1397 }
1398
1399 static INT_PTR CALLBACK TIS_dlg_proc(HWND dlg, UINT msg, WPARAM wParam,
1400 LPARAM lParam)
1401 {
1402 PTInstVar pvar;
1403
1404 switch (msg) {
1405 case WM_INITDIALOG:
1406 pvar = (PTInstVar) lParam;
1407 pvar->auth_state.auth_dialog = dlg;
1408 SetWindowLongPtr(dlg, DWLP_USER, lParam);
1409
1410 init_TIS_dlg(pvar, dlg);
1411
1412 // /auth=challenge ������ (2007.10.5 maya)
1413 if (pvar->ssh2_autologin == 1) {
1414 SetDlgItemText(dlg, IDC_SSHPASSWORD, pvar->ssh2_password);
1415 SendMessage(dlg, WM_COMMAND, IDOK, 0);
1416 }
1417
1418 CenterWindow(dlg, GetParent(dlg));
1419 return FALSE; /* because we set the focus */
1420
1421 case WM_COMMAND:
1422 pvar = (PTInstVar) GetWindowLongPtr(dlg, DWLP_USER);
1423
1424 switch (LOWORD(wParam)) {
1425 case IDOK:
1426 return end_TIS_dlg(pvar, dlg);
1427
1428 case IDCANCEL: /* kill the connection */
1429 pvar->auth_state.auth_dialog = NULL;
1430 notify_closed_connection(pvar, "authentication cancelled");
1431 EndDialog(dlg, 0);
1432 return TRUE;
1433
1434 default:
1435 return FALSE;
1436 }
1437
1438 default:
1439 return FALSE;
1440 }
1441 }
1442
1443 void AUTH_do_cred_dialog(PTInstVar pvar)
1444 {
1445 if (pvar->auth_state.auth_dialog == NULL) {
1446 HWND cur_active = GetActiveWindow();
1447 DLGPROC dlg_proc;
1448 LPCTSTR dialog_template;
1449
1450 switch (pvar->auth_state.mode) {
1451 case TIS_AUTH_MODE:
1452 dialog_template = MAKEINTRESOURCE(IDD_SSHTISAUTH);
1453 dlg_proc = TIS_dlg_proc;
1454 break;
1455 case GENERIC_AUTH_MODE:
1456 default:
1457 dialog_template = MAKEINTRESOURCE(IDD_SSHAUTH);
1458 dlg_proc = auth_dlg_proc;
1459 }
1460
1461 if (!DialogBoxParam(hInst, dialog_template,
1462 cur_active !=
1463 NULL ? cur_active : pvar->NotificationWindow,
1464 dlg_proc, (LPARAM) pvar) == -1) {
1465 UTIL_get_lang_msg("MSG_CREATEWINDOW_AUTH_ERROR", pvar,
1466 "Unable to display authentication dialog box.\n"
1467 "Connection terminated.");
1468 notify_fatal_error(pvar, pvar->ts->UIMsg, TRUE);
1469 }
1470 }
1471 }
1472
1473 static void init_default_auth_dlg(PTInstVar pvar, HWND dlg)
1474 {
1475 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 { IDC_SSH_USERNAME, "DLG_AUTHSETUP_USERNAME" },
1484 { IDC_SSH_NO_USERNAME, "DLG_AUTHSETUP_NO_USERNAME" },
1485 { IDC_SSH_DEFAULTUSERNAME, "DLG_AUTHSETUP_DEFAULT_USERNAME" },
1486 { IDC_SSH_WINDOWS_USERNAME, "DLG_AUTHSETUP_LOGON_USERNAME" },
1487 { IDC_SSH_WINDOWS_USERNAME_TEXT, "DLG_AUTHSETUP_LOGON_USERNAME_TEXT" },
1488 { IDC_SSH_AUTHMETHOD, "DLG_AUTHSETUP_METHOD" },
1489 { 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 { IDC_SSHAUTHSETUP_HELP, "BTN_HELP" },
1501 };
1502
1503 SetI18DlgStrs("TTSSH", dlg, text_info, _countof(text_info), pvar->ts->UILanguageFile);
1504
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
1541 if (pvar->settings.DefaultUserType == 1 &&
1542 pvar->session_settings.DefaultUserName[0] == 0) {
1543 // ���������u�����������v����������
1544 pvar->settings.DefaultUserType = 0;
1545 }
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 }
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 pvar->settings.DefaultUserType =
1589 IsDlgButtonChecked(dlg, IDC_SSH_DEFAULTUSERNAME) ? 1 :
1590 IsDlgButtonChecked(dlg, IDC_SSH_WINDOWS_USERNAME) ? 2 : 0;
1591
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 static INT_PTR CALLBACK default_auth_dlg_proc(HWND dlg, UINT msg,
1604 WPARAM wParam, LPARAM lParam)
1605 {
1606 PTInstVar pvar;
1607
1608 switch (msg) {
1609 case WM_INITDIALOG:
1610 pvar = (PTInstVar) lParam;
1611 SetWindowLongPtr(dlg, DWLP_USER, lParam);
1612
1613 init_default_auth_dlg(pvar, dlg);
1614 CenterWindow(dlg, GetParent(dlg));
1615 return TRUE; /* because we do not set the focus */
1616
1617 case WM_COMMAND:
1618 pvar = (PTInstVar) GetWindowLongPtr(dlg, DWLP_USER);
1619
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 case IDC_SSHAUTHSETUP_HELP:
1629 PostMessage(GetParent(dlg), WM_USER_DLGHELP2, HlpMenuSetupSshauth, 0);
1630 return TRUE;
1631
1632 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 pvar->auth_state.echo = 0;
1657 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 void AUTH_set_TIS_mode(PTInstVar pvar, char *prompt, int len, int echo)
1672 {
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 pvar->auth_state.echo = echo;
1681 } 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 key_free(pvar->auth_state.cur_cred.key_pair);
1706 pvar->auth_state.cur_cred.key_pair = NULL;
1707 }
1708 }
1709
1710 static const char *get_auth_method_name(SSHAuthMethod auth)
1711 {
1712 switch (auth) {
1713 case SSH_AUTH_PASSWORD:
1714 return "password";
1715 case SSH_AUTH_RSA:
1716 return "publickey";
1717 case SSH_AUTH_PAGEANT:
1718 return "publickey";
1719 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 void AUTH_get_auth_info(PTInstVar pvar, char *dest, int len)
1731 {
1732 const char *method = "unknown";
1733 char buf[256];
1734
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 _snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg,
1741 pvar->auth_state.user,
1742 get_auth_method_name(pvar->auth_state.cur_cred.method));
1743
1744 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 } 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 _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
1778 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
1787 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
1793 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 }
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 void AUTH_end(PTInstVar pvar)
1823 {
1824 destroy_malloced_string(&pvar->auth_state.user);
1825 destroy_malloced_string(&pvar->auth_state.TIS_prompt);
1826
1827 AUTH_destroy_cur_cred(pvar);
1828 }

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