Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/ttssh2/ttxssh/auth.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10642 - (show annotations) (download) (as text)
Thu Mar 23 12:41:33 2023 UTC (11 months, 2 weeks ago) by zmatsuo
File MIME type: text/x-csrc
File size: 61879 byte(s)
RSA/DSA/ECDSA/ED25519 key の Private key file 選択ダイアログのフィルタが機能しない

- OPENFILENAME.lpstrFilter が "\0\0" 終端に対応していなかった
  - r10614でGetI18nStr() から GetI18nStrWW() に変更したとき、ケアしていなかった
- ファイル名の取得はUnicode化
  - 取得したいファイル名は従来通りANSIで扱う

ticket #47602
1 /*
2 * Copyright (c) 1998-2001, Robert O'Callahan
3 * (c) 2004- 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 #if !defined(_CRTDBG_MAP_ALLOC)
43 #define _CRTDBG_MAP_ALLOC
44 #endif
45 #include <stdlib.h>
46 #include <crtdbg.h>
47
48 #include "resource.h"
49 #include "keyfiles.h"
50 #include "libputty.h"
51 #include "tipwin.h"
52 #include "auth.h"
53 #include "helpid.h"
54 #include "codeconv.h"
55 #include "asprintf.h"
56 #include "win32helper.h"
57 #include "compat_win.h"
58
59 #define AUTH_START_USER_AUTH_ON_ERROR_END 1
60
61 #define MAX_AUTH_CONTROL IDC_SSHUSEPAGEANT
62
63 #undef DialogBoxParam
64 #define DialogBoxParam(p1,p2,p3,p4,p5) \
65 TTDialogBoxParam(p1,p2,p3,p4,p5)
66 #undef EndDialog
67 #define EndDialog(p1,p2) \
68 TTEndDialog(p1, p2)
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 char chars[] = { (char) wParam, 0 };
111
112 SendMessageA(control, EM_REPLACESEL, (WPARAM) TRUE,
113 (LPARAM)chars);
114
115 if (data->tipwin == NULL) {
116 char 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 strcpy_s(uimsg, _countof(uimsg), pvar->UIMsg);
121 if (wParam == 'V' - 'A' + 1) {
122 // CTRL + V
123 strcat_s(uimsg, _countof(uimsg), "\n");
124 UTIL_get_lang_msg("DLG_AUTH_TIP_PASTE_KEY", pvar, "Use Shift + Insert to paste from clipboard");
125 strcat_s(uimsg, _countof(uimsg), pvar->UIMsg);
126 }
127 GetWindowRect(control, &rect);
128 data->tipwin = TipWinCreateA(hInst, 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 = CallWindowProcW(data->ProcOrg, control, msg, wParam, lParam);
142
143 if (msg == WM_NCDESTROY) {
144 SetWindowLongPtr(control, GWLP_WNDPROC, (LONG_PTR)data->ProcOrg);
145 password_wnd_proc_close_tooltip(data);
146 free(data);
147 }
148
149 return result;
150 }
151
152 void init_password_control(PTInstVar pvar, HWND dlg, int item, BOOL *UseControlChar)
153 {
154 HWND passwordControl = GetDlgItem(dlg, item);
155 TPasswordControlData *data = (TPasswordControlData *)malloc(sizeof(TPasswordControlData));
156 data->ProcOrg = (WNDPROC)GetWindowLongPtr(passwordControl, GWLP_WNDPROC);
157 data->pvar = pvar;
158 data->tipwin = NULL;
159 data->UseControlChar = UseControlChar;
160 SetWindowLongPtrW(passwordControl, GWLP_WNDPROC, (LONG_PTR)password_wnd_proc);
161 SetWindowLongPtrW(passwordControl, GWLP_USERDATA, (LONG_PTR)data);
162 SetFocus(passwordControl);
163 }
164
165 static void set_auth_options_status(HWND dlg, int controlID)
166 {
167 BOOL RSA_enabled = controlID == IDC_SSHUSERSA;
168 BOOL rhosts_enabled = controlID == IDC_SSHUSERHOSTS;
169 BOOL TIS_enabled = controlID == IDC_SSHUSETIS;
170 BOOL PAGEANT_enabled = controlID == IDC_SSHUSEPAGEANT;
171 int i;
172 static const int password_item_ids[] = {
173 IDC_SSHPASSWORDCAPTION,
174 IDC_SSHPASSWORD,
175 IDC_SSHPASSWORD_OPTION,
176 };
177 static const int rsa_item_ids[] = {
178 IDC_RSAFILENAMELABEL,
179 IDC_RSAFILENAME,
180 IDC_CHOOSERSAFILE,
181 };
182 static const int rhosts_item_ids[] = {
183 IDC_LOCALUSERNAMELABEL,
184 IDC_LOCALUSERNAME,
185 IDC_HOSTRSAFILENAMELABEL,
186 IDC_HOSTRSAFILENAME,
187 IDC_CHOOSEHOSTRSAFILE,
188 };
189
190 CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, controlID);
191
192 for (i = 0; i < _countof(password_item_ids); i++) {
193 EnableWindow(GetDlgItem(dlg, password_item_ids[i]), (!TIS_enabled && !PAGEANT_enabled));
194 }
195
196 for (i = 0; i < _countof(rsa_item_ids); i++) {
197 EnableWindow(GetDlgItem(dlg, rsa_item_ids[i]), RSA_enabled);
198 }
199
200 for (i = 0; i < _countof(rhosts_item_ids); i++) {
201 EnableWindow(GetDlgItem(dlg, rhosts_item_ids[i]), rhosts_enabled);
202 }
203 }
204
205 static void init_auth_machine_banner(PTInstVar pvar, HWND dlg)
206 {
207 wchar_t* buf;
208 wchar_t buf2[1024];
209 const char *host_name = SSH_get_host_name(pvar);
210 wchar_t *host_nameW = ToWcharA(host_name);
211
212 GetDlgItemTextW(dlg, IDC_SSHAUTHBANNER, buf2, _countof(buf2));
213 aswprintf(&buf, buf2, host_nameW);
214 SetDlgItemTextW(dlg, IDC_SSHAUTHBANNER, buf);
215 free(host_nameW);
216 free(buf);
217 }
218
219 static void update_server_supported_types(PTInstVar pvar, HWND dlg)
220 {
221 int supported_methods = pvar->auth_state.supported_types;
222 int cur_control = -1;
223 int control;
224 HWND focus = GetFocus();
225
226 if (supported_methods == 0) {
227 return;
228 }
229
230 for (control = IDC_SSHUSEPASSWORD; control <= MAX_AUTH_CONTROL;
231 control++) {
232 BOOL enabled = FALSE;
233 int method;
234 HWND item = GetDlgItem(dlg, control);
235
236 if (item != NULL) {
237 for (method = 0; method <= SSH_AUTH_MAX; method++) {
238 if (auth_types_to_control_IDs[method] == control
239 && (supported_methods & (1 << method)) != 0) {
240 enabled = TRUE;
241 }
242 }
243
244 EnableWindow(item, enabled);
245
246 if (IsDlgButtonChecked(dlg, control)) {
247 cur_control = control;
248 }
249 }
250 }
251
252 if (cur_control >= 0) {
253 if (!IsWindowEnabled(GetDlgItem(dlg, cur_control))) {
254 do {
255 cur_control++;
256 if (cur_control > MAX_AUTH_CONTROL) {
257 cur_control = IDC_SSHUSEPASSWORD;
258 }
259 } while (!IsWindowEnabled(GetDlgItem(dlg, cur_control)));
260
261 set_auth_options_status(dlg, cur_control);
262
263 if (focus != NULL && !IsWindowEnabled(focus)) {
264 SetFocus(GetDlgItem(dlg, cur_control));
265 }
266 }
267 }
268 }
269
270 static void init_auth_dlg(PTInstVar pvar, HWND dlg, BOOL *UseControlChar)
271 {
272 static const DlgTextInfo text_info[] = {
273 { 0, "DLG_AUTH_TITLE" },
274 { IDC_SSHAUTHBANNER, "DLG_AUTH_BANNER" },
275 { IDC_SSHAUTHBANNER2, "DLG_AUTH_BANNER2" },
276 { IDC_SSHUSERNAMELABEL, "DLG_AUTH_USERNAME" },
277 { IDC_SSHPASSWORDCAPTION, "DLG_AUTH_PASSWORD" },
278 { IDC_REMEMBER_PASSWORD, "DLG_AUTH_REMEMBER_PASSWORD" },
279 { IDC_FORWARD_AGENT, "DLG_AUTH_FWDAGENT" },
280 { IDC_SSHAUTHMETHOD, "DLG_AUTH_METHOD" },
281 { IDC_SSHUSEPASSWORD, "DLG_AUTH_METHOD_PASSWORD" },
282 { IDC_SSHUSERSA, "DLG_AUTH_METHOD_RSA" },
283 { IDC_SSHUSERHOSTS, "DLG_AUTH_METHOD_RHOST" },
284 { IDC_SSHUSEPAGEANT, "DLG_AUTH_METHOD_PAGEANT" },
285 { IDC_RSAFILENAMELABEL, "DLG_AUTH_PRIVATEKEY" },
286 { IDC_LOCALUSERNAMELABEL, "DLG_AUTH_LOCALUSER" },
287 { IDC_HOSTRSAFILENAMELABEL, "DLG_AUTH_HOST_PRIVATEKEY" },
288 { IDOK, "BTN_OK" },
289 { IDCANCEL, "BTN_DISCONNECT" },
290 };
291 int default_method = pvar->session_settings.DefaultAuthMethod;
292
293 SetI18nDlgStrsW(dlg, "TTSSH", text_info, _countof(text_info), pvar->ts->UILanguageFileW);
294
295 init_auth_machine_banner(pvar, dlg);
296 init_password_control(pvar, dlg, IDC_SSHPASSWORD, UseControlChar);
297
298 // �F�����s�������x������������
299 if (pvar->auth_state.failed_method != SSH_AUTH_NONE) {
300 /* must be retrying a failed attempt */
301 wchar_t uimsg[MAX_UIMSG];
302 UTIL_get_lang_msgW("DLG_AUTH_BANNER2_FAILED", pvar, L"Authentication failed. Please retry.", uimsg);
303 SetDlgItemTextW(dlg, IDC_SSHAUTHBANNER2, uimsg);
304 UTIL_get_lang_msgW("DLG_AUTH_TITLE_FAILED", pvar, L"Retrying SSH Authentication", uimsg);
305 SetWindowTextW(dlg, uimsg);
306 default_method = pvar->auth_state.failed_method;
307 }
308
309 // �p�X���[�h���o���������`�F�b�N�{�b�N�X�����f�t�H���g���L�������� (2006.8.3 yutaka)
310 if (pvar->ts_SSH->remember_password) {
311 SendMessage(GetDlgItem(dlg, IDC_REMEMBER_PASSWORD), BM_SETCHECK, BST_CHECKED, 0);
312 } else {
313 SendMessage(GetDlgItem(dlg, IDC_REMEMBER_PASSWORD), BM_SETCHECK, BST_UNCHECKED, 0);
314 }
315
316 // ForwardAgent �����������f���� (2008.12.4 maya)
317 CheckDlgButton(dlg, IDC_FORWARD_AGENT, pvar->settings.ForwardAgent);
318
319 // SSH �o�[�W������������ TIS �����x������������
320 if (pvar->settings.ssh_protocol_version == 1) {
321 UTIL_get_lang_msg("DLG_AUTH_METHOD_CHALLENGE1", pvar,
322 "Use challenge/response(&TIS) to log in");
323 SetDlgItemText(dlg, IDC_SSHUSETIS, pvar->UIMsg);
324 } else {
325 UTIL_get_lang_msg("DLG_AUTH_METHOD_CHALLENGE2", pvar,
326 "Use keyboard-&interactive to log in");
327 SetDlgItemText(dlg, IDC_SSHUSETIS, pvar->UIMsg);
328 }
329
330 if (pvar->auth_state.user != NULL) {
331 SetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->auth_state.user);
332 EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAME), FALSE);
333 EnableWindow(GetDlgItem(dlg, IDC_USERNAME_OPTION), FALSE);
334 EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAMELABEL), FALSE);
335 }
336 else if (strlen(pvar->ssh2_username) > 0) {
337 SetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->ssh2_username);
338 if (pvar->ssh2_autologin == 1) {
339 EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAME), FALSE);
340 EnableWindow(GetDlgItem(dlg, IDC_USERNAME_OPTION), FALSE);
341 EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAMELABEL), FALSE);
342 }
343 }
344 else {
345 switch(pvar->session_settings.DefaultUserType) {
346 case 0:
347 // ����������
348 break;
349 case 1:
350 // use DefaultUserName
351 if (pvar->session_settings.DefaultUserName[0] == 0) {
352 // �u�����������v����������
353 pvar->session_settings.DefaultUserType = 0;
354 } else {
355 SetDlgItemText(dlg, IDC_SSHUSERNAME,
356 pvar->session_settings.DefaultUserName);
357 }
358 break;
359 case 2: {
360 char user_name[UNLEN+1];
361 DWORD len = _countof(user_name);
362 BOOL r = GetUserName(user_name, &len);
363 if (r != 0) {
364 SetDlgItemText(dlg, IDC_SSHUSERNAME, user_name);
365 }
366 break;
367 }
368 default:
369 // ��������������������
370 pvar->session_settings.DefaultUserType = 0;
371 }
372 }
373
374 if (strlen(pvar->ssh2_password) > 0) {
375 SetDlgItemText(dlg, IDC_SSHPASSWORD, pvar->ssh2_password);
376 if (pvar->ssh2_autologin == 1) {
377 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD), FALSE);
378 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORDCAPTION), FALSE);
379 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD_OPTION), FALSE);
380 }
381 }
382
383 SetDlgItemText(dlg, IDC_RSAFILENAME,
384 pvar->session_settings.DefaultRSAPrivateKeyFile);
385 SetDlgItemText(dlg, IDC_HOSTRSAFILENAME,
386 pvar->session_settings.DefaultRhostsHostPrivateKeyFile);
387 SetDlgItemText(dlg, IDC_LOCALUSERNAME,
388 pvar->session_settings.DefaultRhostsLocalUserName);
389
390 if (pvar->ssh2_authmethod == SSH_AUTH_PASSWORD) {
391 CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, IDC_SSHUSEPASSWORD);
392
393 } else if (pvar->ssh2_authmethod == SSH_AUTH_RSA) {
394 CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, IDC_SSHUSERSA);
395
396 SetDlgItemText(dlg, IDC_RSAFILENAME, pvar->ssh2_keyfile);
397 if (pvar->ssh2_autologin == 1) {
398 EnableWindow(GetDlgItem(dlg, IDC_CHOOSERSAFILE), FALSE);
399 EnableWindow(GetDlgItem(dlg, IDC_RSAFILENAME), FALSE);
400 }
401
402 // /auth=challenge ������ (2007.10.5 maya)
403 } else if (pvar->ssh2_authmethod == SSH_AUTH_TIS) {
404 CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, IDC_SSHUSETIS);
405 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD), FALSE);
406 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD_OPTION), FALSE);
407 SetDlgItemText(dlg, IDC_SSHPASSWORD, "");
408
409 // /auth=pageant ������
410 } else if (pvar->ssh2_authmethod == SSH_AUTH_PAGEANT) {
411 CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, IDC_SSHUSEPAGEANT);
412 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD), FALSE);
413 EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD_OPTION), FALSE);
414 SetDlgItemText(dlg, IDC_SSHPASSWORD, "");
415
416 } else {
417 // �f�t�H���g���F�����\�b�h���_�C�A���O�����f
418 set_auth_options_status(dlg, auth_types_to_control_IDs[default_method]);
419
420 update_server_supported_types(pvar, dlg);
421
422 // �z�X�g�m�F�_�C�A���O��������������=�E�B���h�E���A�N�e�B�u������������
423 // �� SetFocus �����s�����A�R�}���h���C�����n�������F��������������������
424 // �����������A�������O�C���L������ SetFocus ������ (2009.1.31 maya)
425 if (default_method == SSH_AUTH_TIS) {
426 /* we disabled the password control, so fix the focus */
427 SetFocus(GetDlgItem(dlg, IDC_SSHUSETIS));
428 }
429 else if (default_method == SSH_AUTH_PAGEANT) {
430 SetFocus(GetDlgItem(dlg, IDC_SSHUSEPAGEANT));
431 }
432
433 }
434
435 if (GetWindowTextLength(GetDlgItem(dlg, IDC_SSHUSERNAME)) == 0) {
436 SetFocus(GetDlgItem(dlg, IDC_SSHUSERNAME));
437 }
438 else if (pvar->ask4passwd == 1) {
439 SetFocus(GetDlgItem(dlg, IDC_SSHPASSWORD));
440 }
441
442 // '/I' �w�������������������������� (2005.9.5 yutaka)
443 if (pvar->ts->Minimize) {
444 //20050822���� start T.Takahashi
445 ShowWindow(dlg,SW_MINIMIZE);
446 //20050822���� end T.Takahashi
447 }
448 }
449
450 static char *alloc_control_text(HWND ctl)
451 {
452 wchar_t *textW;
453 char *textA;
454 hGetWindowTextW(ctl, &textW);
455 textA = ToCharW(textW);
456 free(textW);
457 return textA;
458 }
459
460 static int get_key_file_name(HWND parent, char *buf, int bufsize, PTInstVar pvar)
461 {
462 static const wchar_t *fullname_def = L"identity";
463 static const wchar_t *filter_def =
464 L"identity files\\0identity;id_rsa;id_dsa;id_ecdsa;id_ed25519;*.ppk;*.pem\\0"
465 L"identity(RSA1)\\0identity\\0"
466 L"id_rsa(SSH2)\\0id_rsa\\0"
467 L"id_dsa(SSH2)\\0id_dsa\\0"
468 L"id_ecdsa(SSH2)\\0id_ecdsa\\0"
469 L"id_ed25519(SSH2)\\0id_ed25519\\0"
470 L"PuTTY(*.ppk)\\0*.ppk\\0"
471 L"PEM files(*.pem)\\0*.pem\\0"
472 L"all(*.*)\\0*.*\\0"
473 L"\\0";
474 const wchar_t *UILanguageFileW = pvar->ts->UILanguageFileW;
475 TTOPENFILENAMEW params;
476 wchar_t *filter;
477 wchar_t *title;
478 wchar_t *fullnameW;
479 BOOL r;
480
481 ZeroMemory(&params, sizeof(params));
482 params.hwndOwner = parent;
483 GetI18nStrWW("TTSSH", "FILEDLG_OPEN_PRIVATEKEY_FILTER", filter_def,
484 UILanguageFileW, &filter);
485 params.lpstrFilter = filter;
486 params.nFilterIndex = 0;
487 params.lpstrFile = fullname_def;
488 params.lpstrInitialDir = NULL;
489 GetI18nStrWW("TTSSH", "FILEDLG_OPEN_PRIVATEKEY_TITLE",
490 L"Choose a file with the RSA/DSA/ECDSA/ED25519 private key",
491 UILanguageFileW, &title);
492 params.lpstrTitle = title;
493 params.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
494 params.lpstrDefExt = NULL;
495
496 r = TTGetOpenFileNameW(&params, &fullnameW);
497 free(filter);
498 free(title);
499 if (r == FALSE) {
500 buf[0] = 0;
501 return 0;
502 }
503 else {
504 char *fullnameA = ToCharW(fullnameW);
505 copy_teraterm_dir_relative_path(buf, bufsize, fullnameA);
506 free(fullnameA);
507 free(fullnameW);
508 return 1;
509 }
510 }
511
512 static void choose_RSA_key_file(HWND dlg, PTInstVar pvar)
513 {
514 char buf[1024];
515
516 if (get_key_file_name(dlg, buf, sizeof(buf), pvar)) {
517 SetDlgItemText(dlg, IDC_RSAFILENAME, buf);
518 }
519 }
520
521 static void choose_host_RSA_key_file(HWND dlg, PTInstVar pvar)
522 {
523 char buf[1024];
524
525 if (get_key_file_name(dlg, buf, sizeof(buf), pvar)) {
526 SetDlgItemText(dlg, IDC_HOSTRSAFILENAME, buf);
527 }
528 }
529
530 static BOOL end_auth_dlg(PTInstVar pvar, HWND dlg)
531 {
532 int method = SSH_AUTH_PASSWORD;
533 char *password =
534 alloc_control_text(GetDlgItem(dlg, IDC_SSHPASSWORD));
535 Key *key_pair = NULL;
536
537 if (IsDlgButtonChecked(dlg, IDC_SSHUSERSA)) {
538 method = SSH_AUTH_RSA;
539 } else if (IsDlgButtonChecked(dlg, IDC_SSHUSERHOSTS)) {
540 if (GetWindowTextLength(GetDlgItem(dlg, IDC_HOSTRSAFILENAME)) > 0) {
541 method = SSH_AUTH_RHOSTS_RSA;
542 } else {
543 method = SSH_AUTH_RHOSTS;
544 }
545 } else if (IsDlgButtonChecked(dlg, IDC_SSHUSETIS)) {
546 method = SSH_AUTH_TIS;
547 } else if (IsDlgButtonChecked(dlg, IDC_SSHUSEPAGEANT)) {
548 method = SSH_AUTH_PAGEANT;
549 }
550
551 if (method == SSH_AUTH_RSA || method == SSH_AUTH_RHOSTS_RSA) {
552 char keyfile[2048];
553 int file_ctl_ID =
554 method == SSH_AUTH_RSA ? IDC_RSAFILENAME : IDC_HOSTRSAFILENAME;
555
556 keyfile[0] = 0;
557 GetDlgItemText(dlg, file_ctl_ID, keyfile, sizeof(keyfile));
558 if (keyfile[0] == 0) {
559 UTIL_get_lang_msg("MSG_KEYSPECIFY_ERROR", pvar,
560 "You must specify a file containing the RSA/DSA/ECDSA/ED25519 private key.");
561 notify_nonfatal_error(pvar, pvar->UIMsg);
562 SetFocus(GetDlgItem(dlg, file_ctl_ID));
563 destroy_malloced_string(&password);
564 return FALSE;
565 }
566
567 if (SSHv1(pvar)) {
568 BOOL invalid_passphrase = FALSE;
569
570 key_pair = KEYFILES_read_private_key(pvar, keyfile, password,
571 &invalid_passphrase,
572 FALSE);
573
574 if (key_pair == NULL) {
575 if (invalid_passphrase) {
576 HWND passwordCtl = GetDlgItem(dlg, IDC_SSHPASSWORD);
577
578 SetFocus(passwordCtl);
579 SendMessage(passwordCtl, EM_SETSEL, 0, -1);
580 } else {
581 SetFocus(GetDlgItem(dlg, file_ctl_ID));
582 }
583 destroy_malloced_string(&password);
584 return FALSE;
585 }
586
587 } else { // SSH2(yutaka)
588 BOOL invalid_passphrase = FALSE;
589 char errmsg[256];
590 FILE *fp = NULL;
591 ssh2_keyfile_type keyfile_type;
592
593 memset(errmsg, 0, sizeof(errmsg));
594
595 keyfile_type = get_ssh2_keytype(keyfile, &fp, errmsg, sizeof(errmsg));
596 switch (keyfile_type) {
597 case SSH2_KEYFILE_TYPE_OPENSSH:
598 {
599 key_pair = read_SSH2_private_key(pvar, fp, password,
600 &invalid_passphrase,
601 FALSE,
602 errmsg,
603 sizeof(errmsg)
604 );
605 break;
606 }
607 case SSH2_KEYFILE_TYPE_PUTTY:
608 {
609 key_pair = read_SSH2_PuTTY_private_key(pvar, fp, password,
610 &invalid_passphrase,
611 FALSE,
612 errmsg,
613 sizeof(errmsg)
614 );
615 break;
616 }
617 case SSH2_KEYFILE_TYPE_SECSH:
618 {
619 key_pair = read_SSH2_SECSH_private_key(pvar, fp, password,
620 &invalid_passphrase,
621 FALSE,
622 errmsg,
623 sizeof(errmsg)
624 );
625 break;
626 }
627 default:
628 {
629 char buf[1024];
630
631 // �t�@�C�����J�����������t�@�C���`�����s��������������������
632 if (fp != NULL) {
633 key_pair = read_SSH2_private_key(pvar, fp, password,
634 &invalid_passphrase,
635 FALSE,
636 errmsg,
637 sizeof(errmsg)
638 );
639 break;
640 }
641
642 UTIL_get_lang_msg("MSG_READKEY_ERROR", pvar,
643 "read error SSH2 private key file\r\n%s");
644 _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->UIMsg, errmsg);
645 notify_nonfatal_error(pvar, buf);
646 // ���������������������� SSH2 �������t�@�C�����J����������
647 // ���t�@�C�����I���{�^�����t�H�[�J�X������
648 SetFocus(GetDlgItem(dlg, IDC_CHOOSERSAFILE));
649 destroy_malloced_string(&password);
650 return FALSE;
651 }
652 }
653
654 if (key_pair == NULL) { // read error
655 char buf[1024];
656 UTIL_get_lang_msg("MSG_READKEY_ERROR", pvar,
657 "read error SSH2 private key file\r\n%s");
658 _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->UIMsg, errmsg);
659 notify_nonfatal_error(pvar, buf);
660 // �p�X�t���[�Y���������v����������������IDC_SSHPASSWORD���t�H�[�J�X������ (2006.10.29 yasuhide)
661 if (invalid_passphrase) {
662 HWND passwordCtl = GetDlgItem(dlg, IDC_SSHPASSWORD);
663
664 SetFocus(passwordCtl);
665 SendMessage(passwordCtl, EM_SETSEL, 0, -1);
666 } else {
667 SetFocus(GetDlgItem(dlg, file_ctl_ID));
668 }
669 destroy_malloced_string(&password);
670 return FALSE;
671 }
672
673 }
674
675 }
676 else if (method == SSH_AUTH_PAGEANT) {
677 pvar->pageant_key = NULL;
678 pvar->pageant_curkey = NULL;
679 pvar->pageant_keylistlen = 0;
680 pvar->pageant_keycount = 0;
681 pvar->pageant_keycurrent = 0;
682 pvar->pageant_keyfinal=FALSE;
683
684 // Pageant �����M
685 if (!putty_agent_exists()) {
686 UTIL_get_lang_msg("MSG_PAGEANT_NOTFOUND", pvar,
687 "Can't find Pageant.");
688 notify_nonfatal_error(pvar, pvar->UIMsg);
689
690 return FALSE;
691 }
692
693 if (SSHv1(pvar)) {
694 pvar->pageant_keylistlen = putty_get_ssh1_keylist(&pvar->pageant_key);
695 }
696 else {
697 pvar->pageant_keylistlen = putty_get_ssh2_keylist(&pvar->pageant_key);
698 }
699 if (pvar->pageant_keylistlen == 0) {
700 UTIL_get_lang_msg("MSG_PAGEANT_NOKEY", pvar,
701 "Pageant has no valid key.");
702 notify_nonfatal_error(pvar, pvar->UIMsg);
703
704 return FALSE;
705 }
706 pvar->pageant_curkey = pvar->pageant_key;
707
708 // ������
709 pvar->pageant_keycount = get_uint32_MSBfirst(pvar->pageant_curkey);
710 if (pvar->pageant_keycount == 0) {
711 UTIL_get_lang_msg("MSG_PAGEANT_NOKEY", pvar,
712 "Pageant has no valid key.");
713 notify_nonfatal_error(pvar, pvar->UIMsg);
714
715 return FALSE;
716 }
717 pvar->pageant_curkey += 4;
718 }
719
720 /* from here on, we cannot fail, so just munge cur_cred in place */
721 pvar->auth_state.cur_cred.method = method;
722 pvar->auth_state.cur_cred.key_pair = key_pair;
723 /* we can't change the user name once it's set. It may already have
724 been sent to the server, and it can only be sent once. */
725 if (pvar->auth_state.user == NULL) {
726 pvar->auth_state.user =
727 alloc_control_text(GetDlgItem(dlg, IDC_SSHUSERNAME));
728 }
729
730 // �p�X���[�h���������������������������� (2006.8.3 yutaka)
731 if (SendMessage(GetDlgItem(dlg, IDC_REMEMBER_PASSWORD), BM_GETCHECK, 0,0) == BST_CHECKED) {
732 pvar->settings.remember_password = 1; // �o��������
733 pvar->ts_SSH->remember_password = 1;
734 } else {
735 pvar->settings.remember_password = 0; // ���������������Y����
736 pvar->ts_SSH->remember_password = 0;
737 }
738
739 // ���J���F���������A�Z�b�V�������������p�X���[�h���g�����������������������������������B
740 // (2005.4.8 yutaka)
741 if (method == SSH_AUTH_PASSWORD || method == SSH_AUTH_RSA) {
742 pvar->auth_state.cur_cred.password = password;
743 } else {
744 destroy_malloced_string(&password);
745 }
746 if (method == SSH_AUTH_RHOSTS || method == SSH_AUTH_RHOSTS_RSA) {
747 if (pvar->session_settings.DefaultAuthMethod != SSH_AUTH_RHOSTS) {
748 UTIL_get_lang_msg("MSG_RHOSTS_NOTDEFAULT_ERROR", pvar,
749 "Rhosts authentication will probably fail because it was not "
750 "the default authentication method.\n"
751 "To use Rhosts authentication "
752 "in TTSSH, you need to set it to be the default by restarting\n"
753 "TTSSH and selecting \"SSH Authentication...\" from the Setup menu "
754 "before connecting.");
755 notify_nonfatal_error(pvar, pvar->UIMsg);
756 }
757
758 pvar->auth_state.cur_cred.rhosts_client_user =
759 alloc_control_text(GetDlgItem(dlg, IDC_LOCALUSERNAME));
760 }
761 pvar->auth_state.auth_dialog = NULL;
762
763 GetDlgItemText(dlg, IDC_RSAFILENAME,
764 pvar->session_settings.DefaultRSAPrivateKeyFile,
765 sizeof(pvar->session_settings.
766 DefaultRSAPrivateKeyFile));
767 GetDlgItemText(dlg, IDC_HOSTRSAFILENAME,
768 pvar->session_settings.DefaultRhostsHostPrivateKeyFile,
769 sizeof(pvar->session_settings.
770 DefaultRhostsHostPrivateKeyFile));
771 GetDlgItemText(dlg, IDC_LOCALUSERNAME,
772 pvar->session_settings.DefaultRhostsLocalUserName,
773 sizeof(pvar->session_settings.
774 DefaultRhostsLocalUserName));
775
776 if (SSHv1(pvar)) {
777 SSH_notify_user_name(pvar);
778 SSH_notify_cred(pvar);
779 } else {
780 // for SSH2(yutaka)
781 do_SSH2_userauth(pvar);
782 }
783
784 EndDialog(dlg, 1);
785
786 return TRUE;
787 }
788
789 static INT_PTR CALLBACK auth_dlg_proc(HWND dlg, UINT msg, WPARAM wParam,
790 LPARAM lParam)
791 {
792 const int IDC_TIMER1 = 300; // �������O�C�����L��������
793 const int IDC_TIMER2 = 301; // �T�|�[�g�������������\�b�h�������`�F�b�N(CheckAuthListFirst)
794 const int IDC_TIMER3 = 302; // challenge �� ask4passwd ��CheckAuthListFirst �� FALSE ������
795 const int autologin_timeout = 10; // �~���b
796 PTInstVar pvar;
797 static BOOL autologin_sent_none;
798 static BOOL UseControlChar;
799 static BOOL ShowPassPhrase;
800 static size_t username_str_len;
801 static wchar_t password_char; // �������L�����N�^
802
803 switch (msg) {
804 case WM_INITDIALOG:
805 pvar = (PTInstVar) lParam;
806 pvar->auth_state.auth_dialog = dlg;
807 SetWindowLongPtr(dlg, DWLP_USER, lParam);
808
809 UseControlChar = TRUE;
810 ShowPassPhrase = FALSE;
811 username_str_len = 0;
812 password_char = 0;
813 init_auth_dlg(pvar, dlg, &UseControlChar);
814
815 // "��"�������Z�b�g����
816 SetDlgItemIcon(dlg, IDC_USERNAME_OPTION, MAKEINTRESOURCEW(IDI_DROPDOWN), 16, 16);
817 SetDlgItemIcon(dlg, IDC_SSHPASSWORD_OPTION, MAKEINTRESOURCEW(IDI_DROPDOWN), 16, 16);
818
819 // SSH2 autologin���L�����������A�^�C�}���d�|�����B (2004.12.1 yutaka)
820 if (pvar->ssh2_autologin == 1) {
821 autologin_sent_none = FALSE;
822 SetTimer(dlg, IDC_TIMER1, autologin_timeout, 0);
823 }
824 else {
825 // �T�|�[�g�������������\�b�h���`�F�b�N�����B(2007.9.24 maya)
826 // �������L�����A�����������s�����������A���[�U�����m����������
827 if (pvar->session_settings.CheckAuthListFirst &&
828 !pvar->tryed_ssh2_authlist &&
829 GetWindowTextLength(GetDlgItem(dlg, IDC_SSHUSERNAME)) > 0) {
830 SetTimer(dlg, IDC_TIMER2, autologin_timeout, 0);
831 }
832 // /auth=challenge �� /ask4passwd ���w���������������[�U�����m����������
833 // �������AOK �{�^���������� TIS auth �_�C�A���O���o��
834 else if (pvar->ssh2_authmethod == SSH_AUTH_TIS &&
835 pvar->ask4passwd &&
836 GetWindowTextLength(GetDlgItem(dlg, IDC_SSHUSERNAME)) > 0) {
837 SetTimer(dlg, IDC_TIMER3, autologin_timeout, 0);
838 }
839 }
840 CenterWindow(dlg, GetParent(dlg));
841 return FALSE; /* because we set the focus */
842
843 case WM_TIMER:
844 pvar = (PTInstVar) GetWindowLongPtr(dlg, DWLP_USER);
845 // �F�������������������A�F���f�[�^�����M�����B�����������A�������B(2004.12.16 yutaka)
846 if (wParam == IDC_TIMER1) {
847 // �������O�C��������
848 if (!(pvar->ssh_state.status_flags & STATUS_DONT_SEND_USER_NAME) &&
849 (pvar->ssh_state.status_flags & STATUS_HOST_OK)) {
850 if (SSHv2(pvar) &&
851 pvar->session_settings.CheckAuthListFirst &&
852 !pvar->tryed_ssh2_authlist) {
853 if (!autologin_sent_none) {
854 autologin_sent_none = TRUE;
855
856 // �_�C�A���O�����[�U������������
857 if (pvar->auth_state.user == NULL) {
858 pvar->auth_state.user =
859 alloc_control_text(GetDlgItem(dlg, IDC_SSHUSERNAME));
860 }
861
862 // CheckAuthListFirst �� TRUE �������� AuthList ���A����������������
863 // IDOK �����������i�����������A�F�����\�b�h none ������ (2008.10.12 maya)
864 do_SSH2_userauth(pvar);
865 }
866 //else {
867 // none �������������A����������������
868 //}
869 }
870 else {
871 // SSH1 ������
872 // ������ CheckAuthListFirst �� FALSE ������
873 // ������ CheckAuthListFirst TRUE ���Aauthlist ���A������������
874 KillTimer(dlg, IDC_TIMER1);
875
876 // �_�C�A���O�����[�U������������
877 if (pvar->auth_state.user == NULL) {
878 pvar->auth_state.user =
879 alloc_control_text(GetDlgItem(dlg, IDC_SSHUSERNAME));
880 }
881
882 SendMessage(dlg, WM_COMMAND, IDOK, 0);
883 }
884 }
885 }
886 else if (wParam == IDC_TIMER2) {
887 // authlist ����������
888 if (!(pvar->ssh_state.status_flags & STATUS_DONT_SEND_USER_NAME) &&
889 (pvar->ssh_state.status_flags & STATUS_HOST_OK)) {
890 if (SSHv2(pvar)) {
891 KillTimer(dlg, IDC_TIMER2);
892
893 // �_�C�A���O�����[�U������������
894 if (pvar->auth_state.user == NULL) {
895 pvar->auth_state.user =
896 alloc_control_text(GetDlgItem(dlg, IDC_SSHUSERNAME));
897 }
898
899 // ���[�U�������X��������
900 EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAME), FALSE);
901 EnableWindow(GetDlgItem(dlg, IDC_USERNAME_OPTION), FALSE);
902
903 // �F�����\�b�h none ������
904 do_SSH2_userauth(pvar);
905
906 // TIS �p�� OK �����������F�������s������������������
907 // Unexpected SSH2 message �������B
908 }
909 else if (SSHv1(pvar)) {
910 KillTimer(dlg, IDC_TIMER2);
911
912 // TIS �p�� OK ������
913 if (pvar->ssh2_authmethod == SSH_AUTH_TIS) {
914 SendMessage(dlg, WM_COMMAND, IDOK, 0);
915 }
916 // SSH1 �����F�����\�b�h none ����������
917 }
918 // �v���g�R���o�[�W�����m���O������������
919 }
920 }
921 else if (wParam == IDC_TIMER3) {
922 if (!(pvar->ssh_state.status_flags & STATUS_DONT_SEND_USER_NAME) &&
923 (pvar->ssh_state.status_flags & STATUS_HOST_OK)) {
924 if (SSHv2(pvar) || SSHv1(pvar)) {
925 KillTimer(dlg, IDC_TIMER3);
926
927 // TIS �p�� OK ������
928 SendMessage(dlg, WM_COMMAND, IDOK, 0);
929 }
930 // �v���g�R���o�[�W�����m���O������������
931 }
932 }
933 return FALSE;
934
935 case WM_COMMAND:
936 pvar = (PTInstVar) GetWindowLongPtr(dlg, DWLP_USER);
937
938 switch (LOWORD(wParam)) {
939 case IDOK:
940 // �F�������T�[�o�������f�������������A�L�����Z�������������B(2014.3.31 yutaka)
941 if (!pvar->cv->Ready) {
942 goto canceled;
943 }
944
945 // �F�������������������A�F���f�[�^�����M�����B�����������A�������B(2001.1.25 yutaka)
946 if (pvar->userauth_retry_count == 0 &&
947 ((pvar->ssh_state.status_flags & STATUS_DONT_SEND_USER_NAME) ||
948 !(pvar->ssh_state.status_flags & STATUS_HOST_OK))) {
949 return FALSE;
950 }
951 else if (SSHv2(pvar) &&
952 pvar->session_settings.CheckAuthListFirst &&
953 !pvar->tryed_ssh2_authlist) {
954 // CheckAuthListFirst ���L�����F������������������������
955 // OK �������������������� (2008.10.4 maya)
956 return FALSE;
957 }
958
959 return end_auth_dlg(pvar, dlg);
960
961 case IDCANCEL: /* kill the connection */
962 canceled:
963 pvar->auth_state.auth_dialog = NULL;
964 notify_closed_connection(pvar, "authentication cancelled");
965 EndDialog(dlg, 0);
966 return TRUE;
967
968 case IDCLOSE:
969 // �F�������l�b�g���[�N���f�����������A���Y���b�Z�[�W���_�C�A���O���������B
970 pvar->auth_state.auth_dialog = NULL;
971 EndDialog(dlg, 0);
972 return TRUE;
973
974 case IDC_SSHUSERNAME:
975 switch (HIWORD(wParam)) {
976 case EN_KILLFOCUS: {
977 // ���[�U�����t�H�[�J�X������������ (2007.9.29 maya)
978 if (!(pvar->ssh_state.status_flags & STATUS_DONT_SEND_USER_NAME) &&
979 (pvar->ssh_state.status_flags & STATUS_HOST_OK)) {
980 // �������L���������������s��������������
981 if (SSHv2(pvar) &&
982 pvar->session_settings.CheckAuthListFirst &&
983 !pvar->tryed_ssh2_authlist) {
984 // �_�C�A���O�����[�U�������f
985 if (pvar->auth_state.user == NULL) {
986 pvar->auth_state.user =
987 alloc_control_text(GetDlgItem(dlg, IDC_SSHUSERNAME));
988 }
989
990 // ���[�U���������������������`�F�b�N����
991 if (strlen(pvar->auth_state.user) == 0) {
992 return FALSE;
993 }
994
995 // ���[�U�������X��������
996 EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAME), FALSE);
997 EnableWindow(GetDlgItem(dlg, IDC_USERNAME_OPTION), FALSE);
998
999 // �F�����\�b�h none ������
1000 do_SSH2_userauth(pvar);
1001 return TRUE;
1002 }
1003 }
1004 return FALSE;
1005 }
1006 case EN_CHANGE: {
1007 // ���[�U�[�����������������������A�I�v�V�������g�����������������A
1008 // tab�����t�H�[�J�X�������A�I�v�V�����{�^�����p�X��������������
1009 // �]���������L�[���������[�U�[�����p�X�t���[�Y���������\������
1010 HWND hWnd = (HWND)lParam;
1011 const int len = GetWindowTextLength(hWnd);
1012 if ((username_str_len == 0 && len != 0) ||
1013 (username_str_len != 0 && len == 0)) {
1014 // ���[�U�[������������ 0������ or 0������������ ����������
1015 const HWND hWndOption = GetDlgItem(dlg, IDC_USERNAME_OPTION);
1016 LONG_PTR style = GetWindowLongPtr(hWndOption, GWL_STYLE);
1017
1018 if (len > 0) {
1019 // �s�vtabstop
1020 style = style & (~(LONG_PTR)WS_TABSTOP);
1021 }
1022 else {
1023 // �vtabstop
1024 style = style | WS_TABSTOP;
1025 }
1026 SetWindowLongPtr(hWndOption, GWL_STYLE, style);
1027 }
1028 username_str_len = len;
1029 return FALSE;
1030 }
1031 }
1032 return FALSE;
1033
1034 case IDC_SSHUSEPASSWORD:
1035 case IDC_SSHUSERSA:
1036 case IDC_SSHUSERHOSTS:
1037 case IDC_SSHUSETIS:
1038 case IDC_SSHUSEPAGEANT:
1039 set_auth_options_status(dlg, LOWORD(wParam));
1040 return TRUE;
1041
1042 case IDC_CHOOSERSAFILE:
1043 choose_RSA_key_file(dlg, pvar);
1044 return TRUE;
1045
1046 case IDC_CHOOSEHOSTRSAFILE:
1047 choose_host_RSA_key_file(dlg, pvar);
1048 return TRUE;
1049
1050 case IDC_FORWARD_AGENT:
1051 // �����Z�b�V�������������f������ (2008.12.4 maya)
1052 pvar->session_settings.ForwardAgent = IsDlgButtonChecked(dlg, IDC_FORWARD_AGENT);
1053 return TRUE;
1054
1055 case IDC_SSHPASSWORD_OPTION: {
1056 RECT rect;
1057 HWND hWndButton;
1058 int result;
1059 HMENU hMenu= CreatePopupMenu();
1060 wchar_t *clipboard = GetClipboardTextW(dlg, FALSE);
1061 wchar_t *uimsg;
1062 GetI18nStrWW("TTSSH", "DLG_AUTH_PASTE_CLIPBOARD",
1063 L"Paste from &clipboard",
1064 pvar->ts->UILanguageFileW, &uimsg);
1065 AppendMenuW(hMenu, MF_ENABLED | MF_STRING | (clipboard == NULL ? MFS_DISABLED : 0), 1, uimsg);
1066 free(uimsg);
1067 GetI18nStrWW("ttssh", "DLG_AUTH_CLEAR_CLIPBOARD",
1068 L"Paste from &clipboard and cl&ear clipboard",
1069 pvar->ts->UILanguageFileW, &uimsg);
1070 AppendMenuW(hMenu, MF_ENABLED | MF_STRING | (clipboard == NULL ? MFS_DISABLED : 0), 2, uimsg);
1071 free(uimsg);
1072 GetI18nStrWW("ttssh", "DLG_AUTH_USE_CONTORL_CHARACTERS",
1073 L"Use control charac&ters",
1074 pvar->ts->UILanguageFileW, &uimsg);
1075 AppendMenuW(hMenu, MF_ENABLED | MF_STRING | (UseControlChar ? MFS_CHECKED : 0), 3, uimsg);
1076 free(uimsg);
1077 GetI18nStrWW("ttssh", "DLG_AUTH_SHOW_PASSPHRASE",
1078 L"&Show passphrase",
1079 pvar->ts->UILanguageFileW, &uimsg);
1080 AppendMenuW(hMenu, MF_ENABLED | MF_STRING | (ShowPassPhrase ? MFS_CHECKED : 0), 4, uimsg);
1081 free(uimsg);
1082 if (clipboard != NULL) {
1083 free(clipboard);
1084 }
1085 hWndButton = GetDlgItem(dlg, IDC_SSHPASSWORD_OPTION);
1086 GetWindowRect(hWndButton, &rect);
1087 result = TrackPopupMenu(hMenu, TPM_RETURNCMD, rect.left, rect.bottom, 0 , hWndButton, NULL);
1088 DestroyMenu(hMenu);
1089 switch(result) {
1090 case 1:
1091 case 2: {
1092 // �N���b�v�{�[�h�����y�[�X�g
1093 BOOL clear_clipboard = result == 2;
1094 clipboard = GetClipboardTextW(dlg, clear_clipboard);
1095 if (clipboard != NULL) {
1096 SetDlgItemTextW(dlg, IDC_SSHPASSWORD, clipboard);
1097 free(clipboard);
1098 SendDlgItemMessage(dlg, IDC_SSHPASSWORD, EM_SETSEL, 0, -1);
1099 SendMessage(dlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(dlg, IDC_SSHPASSWORD), TRUE);
1100 return FALSE;
1101 }
1102 return TRUE;
1103 }
1104 case 3:
1105 // �����R�[�h�g�p/���g�p
1106 UseControlChar = !UseControlChar;
1107 break;
1108 case 4:
1109 // �p�X�t���[�Y�\��/���\��
1110 ShowPassPhrase = !ShowPassPhrase;
1111 {
1112 // ������ on/off ������������
1113 HWND hWnd = GetDlgItem(dlg, IDC_SSHPASSWORD);
1114 if (password_char == 0) {
1115 password_char = (wchar_t)SendMessageW(hWnd, EM_GETPASSWORDCHAR, 0, 0);
1116 }
1117 if (ShowPassPhrase) {
1118 SendMessageW(hWnd, EM_SETPASSWORDCHAR, 0, 0);
1119 } else {
1120 if (IsWindowUnicode(hWnd)) {
1121 SendMessageW(hWnd, EM_SETPASSWORDCHAR, (WPARAM)password_char, 0);
1122 }
1123 else {
1124 // EM_GETPASSWORDCHAR �� Unicode �L�����N�^��������������
1125 // IsWindowUnicode(hWnd) == FALSE ������ Unicode ��������������
1126 SendMessageA(hWnd, EM_SETPASSWORDCHAR, (WPARAM)'*', 0);
1127 }
1128 }
1129 SendDlgItemMessage(dlg, IDC_SSHPASSWORD, EM_SETSEL, 0, -1);
1130 SendMessage(dlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(dlg, IDC_SSHPASSWORD), TRUE);
1131 return TRUE;
1132 }
1133 break;
1134 }
1135 break;
1136 }
1137
1138 case IDC_USERNAME_OPTION: {
1139 RECT rect;
1140 HWND hWndButton;
1141 HMENU hMenu= CreatePopupMenu();
1142 int result;
1143 const BOOL DisableDefaultUserName = pvar->session_settings.DefaultUserName[0] == 0;
1144 wchar_t *uimsg;
1145 GetI18nStrWW("TTSSH", "DLG_AUTH_USE_DEFAULT_USERNAME",
1146 L"Use &default username",
1147 pvar->ts->UILanguageFileW, &uimsg);
1148 AppendMenuW(hMenu, MF_ENABLED | MF_STRING | (DisableDefaultUserName ? MFS_DISABLED : 0), 1,
1149 uimsg);
1150 free(uimsg);
1151 GetI18nStrWW("TTSSH", "DLG_AUTH_USE_LOGON_USERNAME",
1152 L"Use &logon username",
1153 pvar->ts->UILanguageFileW, &uimsg);
1154 AppendMenuW(hMenu, MF_ENABLED | MF_STRING, 2, uimsg);
1155 free(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 char 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 return FALSE;
1185
1186 case WM_DPICHANGED:
1187 SendDlgItemMessage(dlg, IDC_USERNAME_OPTION, WM_DPICHANGED, wParam, lParam);
1188 SendDlgItemMessage(dlg, IDC_SSHPASSWORD_OPTION, WM_DPICHANGED, wParam, lParam);
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->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 static const DlgTextInfo text_info[] = {
1347 { 0, "DLG_TIS_TITLE" },
1348 { IDC_SSHAUTHBANNER, "DLG_TIS_BANNER" },
1349 { IDOK, "BTN_OK" },
1350 { IDCANCEL, "BTN_DISCONNECT" },
1351 };
1352 SetI18nDlgStrsW(dlg, "TTSSH", text_info, _countof(text_info), pvar->ts->UILanguageFileW);
1353
1354 init_auth_machine_banner(pvar, dlg);
1355 init_password_control(pvar, dlg, IDC_SSHPASSWORD, NULL);
1356
1357 if (pvar->auth_state.TIS_prompt != NULL) {
1358 if (strlen(pvar->auth_state.TIS_prompt) > 10000) {
1359 pvar->auth_state.TIS_prompt[10000] = 0;
1360 }
1361 SetDlgItemText(dlg, IDC_SSHAUTHBANNER2,
1362 pvar->auth_state.TIS_prompt);
1363 destroy_malloced_string(&pvar->auth_state.TIS_prompt);
1364 }
1365
1366 if (pvar->auth_state.echo) {
1367 SendMessage(GetDlgItem(dlg, IDC_SSHPASSWORD), EM_SETPASSWORDCHAR, 0, 0);
1368 }
1369 }
1370
1371 static BOOL end_TIS_dlg(PTInstVar pvar, HWND dlg)
1372 {
1373 char *password =
1374 alloc_control_text(GetDlgItem(dlg, IDC_SSHPASSWORD));
1375
1376 pvar->auth_state.cur_cred.method = SSH_AUTH_TIS;
1377 pvar->auth_state.cur_cred.password = password;
1378 pvar->auth_state.auth_dialog = NULL;
1379
1380 // add
1381 if (SSHv2(pvar)) {
1382 pvar->keyboard_interactive_password_input = 1;
1383 handle_SSH2_userauth_inforeq(pvar);
1384 }
1385
1386 SSH_notify_cred(pvar);
1387
1388 EndDialog(dlg, 1);
1389 return TRUE;
1390 }
1391
1392 static INT_PTR CALLBACK TIS_dlg_proc(HWND dlg, UINT msg, WPARAM wParam,
1393 LPARAM lParam)
1394 {
1395 PTInstVar pvar;
1396
1397 switch (msg) {
1398 case WM_INITDIALOG:
1399 pvar = (PTInstVar) lParam;
1400 pvar->auth_state.auth_dialog = dlg;
1401 SetWindowLongPtr(dlg, DWLP_USER, lParam);
1402
1403 init_TIS_dlg(pvar, dlg);
1404
1405 // /auth=challenge ������ (2007.10.5 maya)
1406 if (pvar->ssh2_autologin == 1) {
1407 SetDlgItemText(dlg, IDC_SSHPASSWORD, pvar->ssh2_password);
1408 SendMessage(dlg, WM_COMMAND, IDOK, 0);
1409 }
1410
1411 CenterWindow(dlg, GetParent(dlg));
1412 return FALSE; /* because we set the focus */
1413
1414 case WM_COMMAND:
1415 pvar = (PTInstVar) GetWindowLongPtr(dlg, DWLP_USER);
1416
1417 switch (LOWORD(wParam)) {
1418 case IDOK:
1419 return end_TIS_dlg(pvar, dlg);
1420
1421 case IDCANCEL: /* kill the connection */
1422 pvar->auth_state.auth_dialog = NULL;
1423 notify_closed_connection(pvar, "authentication cancelled");
1424 EndDialog(dlg, 0);
1425 return TRUE;
1426
1427 case IDCLOSE:
1428 // �F�������l�b�g���[�N���f�����������A���Y���b�Z�[�W���_�C�A���O���������B
1429 pvar->auth_state.auth_dialog = NULL;
1430 EndDialog(dlg, 0);
1431 return TRUE;
1432
1433 default:
1434 return FALSE;
1435 }
1436
1437 default:
1438 return FALSE;
1439 }
1440 }
1441
1442 void AUTH_do_cred_dialog(PTInstVar pvar)
1443 {
1444 if (pvar->auth_state.auth_dialog == NULL) {
1445 HWND cur_active = GetActiveWindow();
1446 DLGPROC dlg_proc;
1447 LPCTSTR dialog_template;
1448 INT_PTR r;
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 r = DialogBoxParam(hInst, dialog_template,
1462 cur_active !=
1463 NULL ? cur_active : pvar->NotificationWindow,
1464 dlg_proc, (LPARAM) pvar);
1465 if (r == -1) {
1466 UTIL_get_lang_msg("MSG_CREATEWINDOW_AUTH_ERROR", pvar,
1467 "Unable to display authentication dialog box.\n"
1468 "Connection terminated.");
1469 notify_fatal_error(pvar, pvar->UIMsg, TRUE);
1470 }
1471 }
1472 }
1473
1474 static void init_default_auth_dlg(PTInstVar pvar, HWND dlg)
1475 {
1476 int id;
1477 char user_name[UNLEN+1];
1478 DWORD len;
1479 char uimsg[MAX_UIMSG];
1480 char uimsg2[MAX_UIMSG];
1481 static const DlgTextInfo text_info[] = {
1482 { 0, "DLG_AUTHSETUP_TITLE" },
1483 { IDC_SSHAUTHBANNER, "DLG_AUTHSETUP_BANNER" },
1484 { IDC_SSH_USERNAME, "DLG_AUTHSETUP_USERNAME" },
1485 { IDC_SSH_NO_USERNAME, "DLG_AUTHSETUP_NO_USERNAME" },
1486 { IDC_SSH_DEFAULTUSERNAME, "DLG_AUTHSETUP_DEFAULT_USERNAME" },
1487 { IDC_SSH_WINDOWS_USERNAME, "DLG_AUTHSETUP_LOGON_USERNAME" },
1488 { IDC_SSH_WINDOWS_USERNAME_TEXT, "DLG_AUTHSETUP_LOGON_USERNAME_TEXT" },
1489 { IDC_SSH_AUTHMETHOD, "DLG_AUTHSETUP_METHOD" },
1490 { IDC_SSHUSEPASSWORD, "DLG_AUTHSETUP_METHOD_PASSWORD" },
1491 { IDC_SSHUSERSA, "DLG_AUTHSETUP_METHOD_RSA" },
1492 { IDC_SSHUSERHOSTS, "DLG_AUTHSETUP_METHOD_RHOST" },
1493 { IDC_SSHUSETIS, "DLG_AUTHSETUP_METHOD_CHALLENGE" },
1494 { IDC_SSHUSEPAGEANT, "DLG_AUTHSETUP_METHOD_PAGEANT" },
1495 { IDC_RSAFILENAMELABEL, "DLG_AUTH_PRIVATEKEY" },
1496 { IDC_LOCALUSERNAMELABEL, "DLG_AUTH_LOCALUSER" },
1497 { IDC_HOSTRSAFILENAMELABEL, "DLG_AUTH_HOST_PRIVATEKEY" },
1498 { IDC_CHECKAUTH, "DLG_AUTHSETUP_CHECKAUTH" },
1499 { IDOK, "BTN_OK" },
1500 { IDCANCEL, "BTN_CANCEL" },
1501 { IDC_SSHAUTHSETUP_HELP, "BTN_HELP" },
1502 };
1503
1504 SetI18nDlgStrsW(dlg, "TTSSH", text_info, _countof(text_info), pvar->ts->UILanguageFileW);
1505
1506 switch (pvar->settings.DefaultAuthMethod) {
1507 case SSH_AUTH_RSA:
1508 CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
1509 IDC_SSHUSERSA);
1510 break;
1511 case SSH_AUTH_RHOSTS:
1512 case SSH_AUTH_RHOSTS_RSA:
1513 CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
1514 IDC_SSHUSERHOSTS);
1515 break;
1516 case SSH_AUTH_TIS:
1517 CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
1518 IDC_SSHUSETIS);
1519 break;
1520 case SSH_AUTH_PAGEANT:
1521 CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
1522 IDC_SSHUSEPAGEANT);
1523 break;
1524 case SSH_AUTH_PASSWORD:
1525 default:
1526 CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
1527 IDC_SSHUSEPASSWORD);
1528 }
1529
1530 SetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->settings.DefaultUserName);
1531 SetDlgItemText(dlg, IDC_RSAFILENAME,
1532 pvar->settings.DefaultRSAPrivateKeyFile);
1533 SetDlgItemText(dlg, IDC_HOSTRSAFILENAME,
1534 pvar->settings.DefaultRhostsHostPrivateKeyFile);
1535 SetDlgItemText(dlg, IDC_LOCALUSERNAME,
1536 pvar->settings.DefaultRhostsLocalUserName);
1537
1538 if (pvar->settings.CheckAuthListFirst) {
1539 CheckDlgButton(dlg, IDC_CHECKAUTH, TRUE);
1540 }
1541
1542 if (pvar->settings.DefaultUserType == 1 &&
1543 pvar->settings.DefaultUserName[0] == 0) {
1544 // �u�f�t�H���g���[�U�����g�p�����v�����������[�U�������������A�u�����������v������
1545 pvar->settings.DefaultUserType = 0;
1546 }
1547 id = pvar->settings.DefaultUserType == 1 ? IDC_SSH_DEFAULTUSERNAME :
1548 pvar->settings.DefaultUserType == 2 ? IDC_SSH_WINDOWS_USERNAME :
1549 IDC_SSH_NO_USERNAME;
1550 CheckRadioButton(dlg, IDC_SSH_NO_USERNAME, IDC_SSH_WINDOWS_USERNAME, id);
1551
1552 len = _countof(user_name);
1553 GetUserName(user_name, &len);
1554
1555 GetDlgItemText(dlg, IDC_SSH_WINDOWS_USERNAME_TEXT, uimsg, _countof(uimsg));
1556 sprintf_s(uimsg2, _countof(uimsg2), uimsg, user_name);
1557 SetDlgItemText(dlg, IDC_SSH_WINDOWS_USERNAME_TEXT, uimsg2);
1558 }
1559
1560 static BOOL end_default_auth_dlg(PTInstVar pvar, HWND dlg)
1561 {
1562 if (IsDlgButtonChecked(dlg, IDC_SSHUSERSA)) {
1563 pvar->settings.DefaultAuthMethod = SSH_AUTH_RSA;
1564 } else if (IsDlgButtonChecked(dlg, IDC_SSHUSERHOSTS)) {
1565 if (GetWindowTextLength(GetDlgItem(dlg, IDC_HOSTRSAFILENAME)) > 0) {
1566 pvar->settings.DefaultAuthMethod = SSH_AUTH_RHOSTS_RSA;
1567 } else {
1568 pvar->settings.DefaultAuthMethod = SSH_AUTH_RHOSTS;
1569 }
1570 } else if (IsDlgButtonChecked(dlg, IDC_SSHUSETIS)) {
1571 pvar->settings.DefaultAuthMethod = SSH_AUTH_TIS;
1572 } else if (IsDlgButtonChecked(dlg, IDC_SSHUSEPAGEANT)) {
1573 pvar->settings.DefaultAuthMethod = SSH_AUTH_PAGEANT;
1574 } else {
1575 pvar->settings.DefaultAuthMethod = SSH_AUTH_PASSWORD;
1576 }
1577
1578 GetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->settings.DefaultUserName,
1579 sizeof(pvar->settings.DefaultUserName));
1580 GetDlgItemText(dlg, IDC_RSAFILENAME,
1581 pvar->settings.DefaultRSAPrivateKeyFile,
1582 sizeof(pvar->settings.DefaultRSAPrivateKeyFile));
1583 GetDlgItemText(dlg, IDC_HOSTRSAFILENAME,
1584 pvar->settings.DefaultRhostsHostPrivateKeyFile,
1585 sizeof(pvar->settings.DefaultRhostsHostPrivateKeyFile));
1586 GetDlgItemText(dlg, IDC_LOCALUSERNAME,
1587 pvar->settings.DefaultRhostsLocalUserName,
1588 sizeof(pvar->settings.DefaultRhostsLocalUserName));
1589 pvar->settings.DefaultUserType =
1590 IsDlgButtonChecked(dlg, IDC_SSH_DEFAULTUSERNAME) ? 1 :
1591 IsDlgButtonChecked(dlg, IDC_SSH_WINDOWS_USERNAME) ? 2 : 0;
1592
1593 if (IsDlgButtonChecked(dlg, IDC_CHECKAUTH)) {
1594 pvar->settings.CheckAuthListFirst = TRUE;
1595 }
1596 else {
1597 pvar->settings.CheckAuthListFirst = FALSE;
1598 }
1599
1600 EndDialog(dlg, 1);
1601 return TRUE;
1602 }
1603
1604 static INT_PTR CALLBACK default_auth_dlg_proc(HWND dlg, UINT msg,
1605 WPARAM wParam, LPARAM lParam)
1606 {
1607 PTInstVar pvar;
1608
1609 switch (msg) {
1610 case WM_INITDIALOG:
1611 pvar = (PTInstVar) lParam;
1612 SetWindowLongPtr(dlg, DWLP_USER, lParam);
1613
1614 init_default_auth_dlg(pvar, dlg);
1615 CenterWindow(dlg, GetParent(dlg));
1616 return TRUE; /* because we do not set the focus */
1617
1618 case WM_COMMAND:
1619 pvar = (PTInstVar) GetWindowLongPtr(dlg, DWLP_USER);
1620
1621 switch (LOWORD(wParam)) {
1622 case IDOK:
1623 return end_default_auth_dlg(pvar, dlg);
1624
1625 case IDCANCEL:
1626 EndDialog(dlg, 0);
1627 return TRUE;
1628
1629 case IDC_SSHAUTHSETUP_HELP:
1630 PostMessage(GetParent(dlg), WM_USER_DLGHELP2, HlpMenuSetupSshauth, 0);
1631 return TRUE;
1632
1633 case IDC_CHOOSERSAFILE:
1634 choose_RSA_key_file(dlg, pvar);
1635 return TRUE;
1636
1637 case IDC_CHOOSEHOSTRSAFILE:
1638 choose_host_RSA_key_file(dlg, pvar);
1639 return TRUE;
1640
1641 default:
1642 return FALSE;
1643 }
1644
1645 default:
1646 return FALSE;
1647 }
1648 }
1649
1650 void AUTH_init(PTInstVar pvar)
1651 {
1652 pvar->auth_state.failed_method = SSH_AUTH_NONE;
1653 pvar->auth_state.auth_dialog = NULL;
1654 pvar->auth_state.user = NULL;
1655 pvar->auth_state.flags = 0;
1656 pvar->auth_state.TIS_prompt = NULL;
1657 pvar->auth_state.echo = 0;
1658 pvar->auth_state.supported_types = 0;
1659 pvar->auth_state.cur_cred.method = SSH_AUTH_NONE;
1660 pvar->auth_state.cur_cred.password = NULL;
1661 pvar->auth_state.cur_cred.rhosts_client_user = NULL;
1662 pvar->auth_state.cur_cred.key_pair = NULL;
1663 AUTH_set_generic_mode(pvar);
1664 }
1665
1666 void AUTH_set_generic_mode(PTInstVar pvar)
1667 {
1668 pvar->auth_state.mode = GENERIC_AUTH_MODE;
1669 destroy_malloced_string(&pvar->auth_state.TIS_prompt);
1670 }
1671
1672 void AUTH_set_TIS_mode(PTInstVar pvar, char *prompt, int len, int echo)
1673 {
1674 if (pvar->auth_state.cur_cred.method == SSH_AUTH_TIS) {
1675 pvar->auth_state.mode = TIS_AUTH_MODE;
1676
1677 destroy_malloced_string(&pvar->auth_state.TIS_prompt);
1678 pvar->auth_state.TIS_prompt = malloc(len + 1);
1679 memcpy(pvar->auth_state.TIS_prompt, prompt, len);
1680 pvar->auth_state.TIS_prompt[len] = 0;
1681 pvar->auth_state.echo = echo;
1682 } else {
1683 AUTH_set_generic_mode(pvar);
1684 }
1685 }
1686
1687 void AUTH_do_default_cred_dialog(PTInstVar pvar)
1688 {
1689 HWND cur_active = GetActiveWindow();
1690
1691 if (DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SSHAUTHSETUP),
1692 cur_active != NULL ? cur_active
1693 : pvar->NotificationWindow,
1694 default_auth_dlg_proc, (LPARAM) pvar) == -1) {
1695 UTIL_get_lang_msg("MSG_CREATEWINDOW_AUTHSETUP_ERROR", pvar,
1696 "Unable to display authentication setup dialog box.");
1697 notify_nonfatal_error(pvar, pvar->UIMsg);
1698 }
1699 }
1700
1701 void AUTH_destroy_cur_cred(PTInstVar pvar)
1702 {
1703 destroy_malloced_string(&pvar->auth_state.cur_cred.password);
1704 destroy_malloced_string(&pvar->auth_state.cur_cred.rhosts_client_user);
1705 if (pvar->auth_state.cur_cred.key_pair != NULL) {
1706 key_free(pvar->auth_state.cur_cred.key_pair);
1707 pvar->auth_state.cur_cred.key_pair = NULL;
1708 }
1709 }
1710
1711 static const char *get_auth_method_name(SSHAuthMethod auth)
1712 {
1713 switch (auth) {
1714 case SSH_AUTH_PASSWORD:
1715 return "password";
1716 case SSH_AUTH_RSA:
1717 return "publickey";
1718 case SSH_AUTH_PAGEANT:
1719 return "publickey";
1720 case SSH_AUTH_RHOSTS:
1721 return "rhosts";
1722 case SSH_AUTH_RHOSTS_RSA:
1723 return "rhosts with RSA";
1724 case SSH_AUTH_TIS:
1725 return "challenge/response (TIS)";
1726 default:
1727 return "unknown method";
1728 }
1729 }
1730
1731 void AUTH_get_auth_info(PTInstVar pvar, char *dest, int len)
1732 {
1733 const char *method = "unknown";
1734 char buf[256];
1735
1736 if (pvar->auth_state.user == NULL) {
1737 strncpy_s(dest, len, "None", _TRUNCATE);
1738 } else if (pvar->auth_state.cur_cred.method != SSH_AUTH_NONE) {
1739 if (SSHv1(pvar)) {
1740 UTIL_get_lang_msgU8("DLG_ABOUT_AUTH_INFO", pvar, "User '%s', %s authentication");
1741 _snprintf_s(dest, len, _TRUNCATE, pvar->UIMsg,
1742 pvar->auth_state.user,
1743 get_auth_method_name(pvar->auth_state.cur_cred.method));
1744
1745 if (pvar->auth_state.cur_cred.method == SSH_AUTH_RSA) {
1746 UTIL_get_lang_msgU8("DLG_ABOUT_AUTH_INFO2", pvar, ", %s key");
1747 _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->UIMsg,
1748 "RSA");
1749 strncat_s(dest, len, buf, _TRUNCATE);
1750 }
1751 else if (pvar->auth_state.cur_cred.method == SSH_AUTH_PAGEANT) {
1752 UTIL_get_lang_msgU8("DLG_ABOUT_AUTH_INFO3", pvar, ", %s key");
1753 _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->UIMsg,
1754 "RSA");
1755 strncat_s(dest, len, buf, _TRUNCATE);
1756
1757 _snprintf_s(buf, sizeof(buf), _TRUNCATE, " (from Pageant)");
1758 strncat_s(dest, len, buf, _TRUNCATE);
1759 }
1760 } else {
1761 // SSH2:�F�����\�b�h������ (2004.12.23 yutaka)
1762 // keyboard-interactive���\�b�h������ (2005.3.12 yutaka)
1763 if (pvar->auth_state.cur_cred.method == SSH_AUTH_PASSWORD ||
1764 pvar->auth_state.cur_cred.method == SSH_AUTH_TIS) {
1765 // keyboard-interactive���\�b�h������ (2005.1.24 yutaka)
1766 if (pvar->auth_state.cur_cred.method == SSH_AUTH_TIS) {
1767 method = "keyboard-interactive";
1768 } else {
1769 method = get_auth_method_name(pvar->auth_state.cur_cred.method);
1770 }
1771 UTIL_get_lang_msgU8("DLG_ABOUT_AUTH_INFO", pvar, "User '%s', %s authentication");
1772 _snprintf_s(dest, len, _TRUNCATE, pvar->UIMsg,
1773 pvar->auth_state.user, method);
1774 }
1775 else if (pvar->auth_state.cur_cred.method == SSH_AUTH_RSA) {
1776 ssh_keyalgo pubkey_algo;
1777 char *digest_name;
1778
1779 method = get_auth_method_name(pvar->auth_state.cur_cred.method);
1780 UTIL_get_lang_msgU8("DLG_ABOUT_AUTH_INFO", pvar, "User '%s', %s authentication");
1781 _snprintf_s(dest, len, _TRUNCATE, pvar->UIMsg,
1782 pvar->auth_state.user,
1783 get_auth_method_name(pvar->auth_state.cur_cred.method));
1784
1785 pubkey_algo = choose_SSH2_keysign_algorithm(pvar, pvar->auth_state.cur_cred.key_pair->type);
1786 digest_name = get_ssh2_hostkey_algorithm_digest_name(pubkey_algo);
1787 if (strlen(digest_name) == 0) {
1788 UTIL_get_lang_msgU8("DLG_ABOUT_AUTH_INFO2", pvar, ", %s key");
1789 _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->UIMsg,
1790 ssh_key_type(pvar->auth_state.cur_cred.key_pair->type));
1791 strncat_s(dest, len, buf, _TRUNCATE);
1792 }
1793 else {
1794 UTIL_get_lang_msgU8("DLG_ABOUT_AUTH_INFO3", pvar, ", %s key with %s");
1795 _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->UIMsg,
1796 ssh_key_type(pvar->auth_state.cur_cred.key_pair->type),
1797 digest_name);
1798 strncat_s(dest, len, buf, _TRUNCATE);
1799 }
1800 }
1801 else if (pvar->auth_state.cur_cred.method == SSH_AUTH_PAGEANT) {
1802 int key_len = get_uint32_MSBfirst(pvar->pageant_curkey + 4);
1803 char *s = (char *)malloc(key_len+1);
1804 ssh_keytype keytype;
1805 ssh_keyalgo pubkey_algo;
1806 char *digest_name;
1807
1808 method = get_auth_method_name(pvar->auth_state.cur_cred.method);
1809 UTIL_get_lang_msgU8("DLG_ABOUT_AUTH_INFO", pvar, "User '%s', %s authentication");
1810 _snprintf_s(dest, len, _TRUNCATE, pvar->UIMsg,
1811 pvar->auth_state.user,
1812 get_auth_method_name(pvar->auth_state.cur_cred.method));
1813
1814 memcpy(s, pvar->pageant_curkey+4+4, key_len);
1815 s[key_len] = '\0';
1816 keytype = get_hostkey_type_from_name(s);
1817 pubkey_algo = choose_SSH2_keysign_algorithm(pvar, keytype);
1818 digest_name = get_ssh2_hostkey_algorithm_digest_name(pubkey_algo);
1819 if (strlen(digest_name) == 0) {
1820 UTIL_get_lang_msgU8("DLG_ABOUT_AUTH_INFO2", pvar, ", %s key");
1821 _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->UIMsg,
1822 ssh_key_type(get_hostkey_type_from_name(s)));
1823 strncat_s(dest, len, buf, _TRUNCATE);
1824 }
1825 else {
1826 UTIL_get_lang_msgU8("DLG_ABOUT_AUTH_INFO3", pvar, ", %s key with %s");
1827 _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->UIMsg,
1828 ssh_key_type(get_hostkey_type_from_name(s)),
1829 digest_name);
1830 strncat_s(dest, len, buf, _TRUNCATE);
1831 }
1832
1833 _snprintf_s(buf, sizeof(buf), _TRUNCATE, " (from Pageant)");
1834 strncat_s(dest, len, buf, _TRUNCATE);
1835
1836 free(s);
1837 }
1838 }
1839
1840 } else {
1841 UTIL_get_lang_msgU8("DLG_ABOUT_AUTH_INFO", pvar, "User '%s', using %s");
1842 _snprintf_s(dest, len, _TRUNCATE, pvar->UIMsg, pvar->auth_state.user,
1843 get_auth_method_name(pvar->auth_state.failed_method));
1844 }
1845
1846 dest[len - 1] = 0;
1847 }
1848
1849 void AUTH_notify_disconnecting(PTInstVar pvar)
1850 {
1851 if (pvar->auth_state.auth_dialog != NULL) {
1852 PostMessage(pvar->auth_state.auth_dialog, WM_COMMAND, IDCANCEL, 0);
1853 /* the main window might not go away if it's not enabled. (see vtwin.cpp) */
1854 EnableWindow(pvar->NotificationWindow, TRUE);
1855 }
1856 }
1857
1858 // TCP�Z�b�V�������N���[�Y�����������A�F���_�C�A���O���������������w�����o���B
1859 // AUTH_notify_disconnecting()�����������A�_�C�A���O���������������A
1860 // SSH�T�[�o�����m���o�������B
1861 void AUTH_notify_closing_on_exit(PTInstVar pvar)
1862 {
1863 if (pvar->auth_state.auth_dialog != NULL) {
1864 logprintf(LOG_LEVEL_INFO, "%s: Notify closing message to the authentication dialog.", __FUNCTION__);
1865 PostMessage(pvar->auth_state.auth_dialog, WM_COMMAND, IDCLOSE, 0);
1866 }
1867 }
1868
1869 void AUTH_end(PTInstVar pvar)
1870 {
1871 destroy_malloced_string(&pvar->auth_state.user);
1872 destroy_malloced_string(&pvar->auth_state.TIS_prompt);
1873
1874 AUTH_destroy_cur_cred(pvar);
1875 }
1876
1877 /* vim: set ts=4 sw=4 ff=dos : */

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