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 8093 - (show annotations) (download) (as text)
Sun Sep 8 10:16:41 2019 UTC (4 years, 7 months ago) by yutakapon
Original Path: trunk/ttssh2/ttxssh/auth.c
File MIME type: text/x-csrc
File size: 61331 byte(s)
・known_hostsダイアログおよびユーザ認証ダイアログの表示中に、SSHサーバ側からネットワーク切断された場合、ダイアログを自動で閉じるようにした。
・known_hostsダイアログの表示中にSSHサーバ側からネットワーク切断されると、アプリがクラッシュすることがある問題を修正した。
・SSH1: /nosecuritywarningオプションが機能していなかった問題を修正した。
・/nosecuritywarningオプションに関する注意事項を追記した。

branches/ttssh_improvedからリビジョン8036をマージ:
SSHサーバと認証中にネットワーク切断された場合、認証ダイアログが残ったままとならないようにした。

........
branches/ttssh_improvedからリビジョン8044をマージ:
r8036でダイアログの処理追加漏れ。
SSHサーバと認証中にネットワーク切断された場合、認証ダイアログが残ったままとならないようにした。

........

branches/ttssh_improvedからリビジョン8063をマージ:
known_hostsダイアログが表示されている状態で、サーバから切断を行うと、
TTXCloseTCPが呼び出され、TTSSHのリソースが解放されてしまう。
SSHハンドラの延長でknown_hostsダイアログを出して止まっているため、
ダイアログを閉じて、処理再開すると、SSHの内部情報が壊れる。
その状態で再度SSH接続しようとすると100%アプリが落ちる。

上記問題に対して、まずは SSH1 に処置した。

........

branches/ttssh_improvedからリビジョン8081をマージ:
known_hostsダイアログが表示されている状態で、サーバから切断を行うと、
TTXCloseTCPが呼び出され、TTSSHのリソースが解放されてしまう。
SSHハンドラの延長でknown_hostsダイアログを出して止まっているため、
ダイアログを閉じて、処理再開すると、SSHの内部情報が壊れる。
その状態で再度SSH接続しようとすると100%アプリが落ちる。

上記問題に対して、SSH2 に対応した。

パケット受信時のSSHハンドラのコンテキストで known_hosts ダイアログを表示
させていたが、TTXCloseTCPの非同期呼び出しに対処できないため、
TTSSH1で使われていたknown_hosts ダイアログの非同期呼び出しに
実装を変更した。
これにより、比較的大きくロジックの修正を行っている。

........

branches/ttssh_improvedからリビジョン8085をマージ:
前回のオプション指定(/nosecuritywarning)が残らないように初期化する。
........


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 IDCLOSE:
999 // �F�������l�b�g���[�N���f�����������A���Y���b�Z�[�W���_�C�A���O���������B
1000 pvar->auth_state.auth_dialog = NULL;
1001 EndDialog(dlg, 0);
1002 return TRUE;
1003
1004 case IDC_SSHUSERNAME:
1005 // ���[�U�����t�H�[�J�X������������ (2007.9.29 maya)
1006 if (!(pvar->ssh_state.status_flags & STATUS_DONT_SEND_USER_NAME) &&
1007 (pvar->ssh_state.status_flags & STATUS_HOST_OK) &&
1008 HIWORD(wParam) == EN_KILLFOCUS) {
1009 // �������L���������������s��������������
1010 if (SSHv2(pvar) &&
1011 pvar->session_settings.CheckAuthListFirst &&
1012 !pvar->tryed_ssh2_authlist) {
1013 // �_�C�A���O�����[�U�������f
1014 if (pvar->auth_state.user == NULL) {
1015 pvar->auth_state.user =
1016 alloc_control_text(GetDlgItem(dlg, IDC_SSHUSERNAME));
1017 }
1018
1019 // ���[�U���������������������`�F�b�N����
1020 if (strlen(pvar->auth_state.user) == 0) {
1021 return FALSE;
1022 }
1023
1024 // ���[�U�������X��������
1025 EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAME), FALSE);
1026 EnableWindow(GetDlgItem(dlg, IDC_USERNAME_OPTION), FALSE);
1027
1028 // �F�����\�b�h none ������
1029 do_SSH2_userauth(pvar);
1030 return TRUE;
1031 }
1032 }
1033
1034 return FALSE;
1035
1036 case IDC_SSHUSEPASSWORD:
1037 case IDC_SSHUSERSA:
1038 case IDC_SSHUSERHOSTS:
1039 case IDC_SSHUSETIS:
1040 case IDC_SSHUSEPAGEANT:
1041 set_auth_options_status(dlg, LOWORD(wParam));
1042 return TRUE;
1043
1044 case IDC_CHOOSERSAFILE:
1045 choose_RSA_key_file(dlg, pvar);
1046 return TRUE;
1047
1048 case IDC_CHOOSEHOSTRSAFILE:
1049 choose_host_RSA_key_file(dlg, pvar);
1050 return TRUE;
1051
1052 case IDC_FORWARD_AGENT:
1053 // �����Z�b�V�������������f������ (2008.12.4 maya)
1054 pvar->session_settings.ForwardAgent = IsDlgButtonChecked(dlg, IDC_FORWARD_AGENT);
1055 return TRUE;
1056
1057 case IDC_SSHPASSWORD_OPTION: {
1058 RECT rect;
1059 HWND hWndButton;
1060 int result;
1061 HMENU hMenu= CreatePopupMenu();
1062 char *clipboard = GetClipboardTextA(dlg, FALSE);
1063 GetI18nStrT("TTSSH", "DLG_AUTH_PASTE_CLIPBOARD",
1064 uimsg, _countof(uimsg),
1065 "Paste from &clipboard",
1066 pvar->ts->UILanguageFile);
1067 AppendMenu(hMenu, MF_ENABLED | MF_STRING | (clipboard == NULL ? MFS_DISABLED : 0), 1, uimsg);
1068 GetI18nStrT("ttssh", "DLG_AUTH_CLEAR_CLIPBOARD",
1069 uimsg, _countof(uimsg),
1070 "Paste from &clipboard and cl&ear clipboard",
1071 pvar->ts->UILanguageFile);
1072 AppendMenu(hMenu, MF_ENABLED | MF_STRING | (clipboard == NULL ? MFS_DISABLED : 0), 2, uimsg);
1073 GetI18nStrT("ttssh", "DLG_AUTH_USE_CONTORL_CHARACTERS",
1074 uimsg, _countof(uimsg),
1075 "Use control charac&ters",
1076 pvar->ts->UILanguageFile);
1077 AppendMenu(hMenu, MF_ENABLED | MF_STRING | (UseControlChar ? MFS_CHECKED : 0), 3, uimsg);
1078 GetI18nStrT("ttssh", "DLG_AUTH_SHOW_PASSPHRASE",
1079 uimsg, _countof(uimsg),
1080 "&Show passphrase",
1081 pvar->ts->UILanguageFile);
1082 AppendMenu(hMenu, MF_ENABLED | MF_STRING | (ShowPassPhrase ? MFS_CHECKED : 0), 4, uimsg);
1083 if (clipboard != NULL) {
1084 free(clipboard);
1085 }
1086 hWndButton = GetDlgItem(dlg, IDC_SSHPASSWORD_OPTION);
1087 GetWindowRect(hWndButton, &rect);
1088 result = TrackPopupMenu(hMenu, TPM_RETURNCMD, rect.left, rect.bottom, 0 , hWndButton, NULL);
1089 DestroyMenu(hMenu);
1090 switch(result) {
1091 case 1:
1092 case 2: {
1093 // �N���b�v�{�[�h�����y�[�X�g
1094 BOOL clear_clipboard = result == 2;
1095 clipboard = GetClipboardTextA(dlg, clear_clipboard);
1096 if (clipboard != NULL) {
1097 SetDlgItemTextA(dlg, IDC_SSHPASSWORD, clipboard);
1098 free(clipboard);
1099 SendDlgItemMessage(dlg, IDC_SSHPASSWORD, EM_SETSEL, 0, -1);
1100 SendMessage(dlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(dlg, IDC_SSHPASSWORD), TRUE);
1101 return FALSE;
1102 }
1103 return TRUE;
1104 }
1105 case 3:
1106 // �����R�[�h�g�p/���g�p
1107 UseControlChar = !UseControlChar;
1108 break;
1109 case 4:
1110 // �p�X�t���[�Y�\��/���\��
1111 ShowPassPhrase = !ShowPassPhrase;
1112 {
1113 // ������ on/off ������������
1114 HWND hWnd = GetDlgItem(dlg, IDC_SSHPASSWORD);
1115 static wchar_t password_char;
1116 if (password_char == 0) {
1117 wchar_t c = (wchar_t)SendMessage(hWnd, EM_GETPASSWORDCHAR, 0, 0);
1118 password_char = c;
1119 }
1120 if (ShowPassPhrase) {
1121 SendMessage(hWnd, EM_SETPASSWORDCHAR, 0, 0);
1122 } else {
1123 #if !defined(UNICODE)
1124 if (password_char < 0x100) {
1125 SendMessageA(hWnd, EM_SETPASSWORDCHAR, (WPARAM)password_char, 0);
1126 } else {
1127 // TODO W�n������ ����������������
1128 //SendMessageW(hWnd, EM_SETPASSWORDCHAR, (WPARAM)password_char, 0);
1129 SendMessageA(hWnd, EM_SETPASSWORDCHAR, (WPARAM)'*', 0);
1130 }
1131 #else
1132 SendMessageW(hWnd, EM_SETPASSWORDCHAR, (WPARAM)password_char, 0);
1133 #endif
1134 }
1135 //InvalidateRect(hWnd, NULL, TRUE);
1136 SendDlgItemMessage(dlg, IDC_SSHPASSWORD, EM_SETSEL, 0, -1);
1137 SendMessage(dlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(dlg, IDC_SSHPASSWORD), TRUE);
1138 return TRUE;
1139 }
1140 break;
1141 }
1142 break;
1143 }
1144
1145 case IDC_USERNAME_OPTION: {
1146 RECT rect;
1147 HWND hWndButton;
1148 HMENU hMenu= CreatePopupMenu();
1149 int result;
1150 const BOOL DisableDefaultUserName = pvar->session_settings.DefaultUserName[0] == 0;
1151 GetI18nStrT("TTSSH", "DLG_AUTH_USE_DEFAULT_USERNAME",
1152 uimsg, _countof(uimsg),
1153 "Use &default username",
1154 pvar->ts->UILanguageFile);
1155 AppendMenu(hMenu, MF_ENABLED | MF_STRING | (DisableDefaultUserName ? MFS_DISABLED : 0), 1,
1156 uimsg);
1157 GetI18nStrT("TTSSH", "DLG_AUTH_USE_LOGON_USERNAME",
1158 uimsg, _countof(uimsg),
1159 "Use &logon username",
1160 pvar->ts->UILanguageFile);
1161 AppendMenu(hMenu, MF_ENABLED | MF_STRING, 2, uimsg);
1162 hWndButton = GetDlgItem(dlg, IDC_USERNAME_OPTION);
1163 GetWindowRect(hWndButton, &rect);
1164 result = TrackPopupMenu(hMenu, TPM_RETURNCMD, rect.left, rect.bottom, 0 , hWndButton, NULL);
1165 DestroyMenu(hMenu);
1166 switch (result) {
1167 case 1:
1168 SetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->session_settings.DefaultUserName);
1169 goto after_user_name_set;
1170 case 2: {
1171 TCHAR user_name[UNLEN+1];
1172 DWORD len = _countof(user_name);
1173 BOOL r = GetUserName(user_name, &len);
1174 if (r == 0) {
1175 break;
1176 }
1177 SetDlgItemText(dlg, IDC_SSHUSERNAME, user_name);
1178 after_user_name_set:
1179 SendDlgItemMessage(dlg, IDC_SSHUSERNAME, EM_SETSEL, 0, -1);
1180 SendMessage(dlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(dlg, IDC_SSHUSERNAME), TRUE);
1181 break;
1182 }
1183 }
1184 return TRUE;
1185 }
1186
1187 default:
1188 return FALSE;
1189 }
1190
1191 case WM_DESTROY:
1192 if (hIconDropdown != NULL) {
1193 DeleteObject(hIconDropdown);
1194 }
1195 return FALSE;
1196
1197 default:
1198 return FALSE;
1199 }
1200 }
1201
1202 char *AUTH_get_user_name(PTInstVar pvar)
1203 {
1204 return pvar->auth_state.user;
1205 }
1206
1207 int AUTH_set_supported_auth_types(PTInstVar pvar, int types)
1208 {
1209 logprintf(LOG_LEVEL_VERBOSE, "Server reports supported authentication method mask = %d", types);
1210
1211 if (SSHv1(pvar)) {
1212 types &= (1 << SSH_AUTH_PASSWORD) | (1 << SSH_AUTH_RSA)
1213 | (1 << SSH_AUTH_RHOSTS_RSA) | (1 << SSH_AUTH_RHOSTS)
1214 | (1 << SSH_AUTH_TIS) | (1 << SSH_AUTH_PAGEANT);
1215 } else {
1216 // for SSH2(yutaka)
1217 // types &= (1 << SSH_AUTH_PASSWORD);
1218 // ���J���F�����L�������� (2004.12.18 yutaka)
1219 // TIS�������BSSH2����keyboard-interactive�����������B(2005.3.12 yutaka)
1220 types &= (1 << SSH_AUTH_PASSWORD) | (1 << SSH_AUTH_RSA)
1221 | (1 << SSH_AUTH_TIS) | (1 << SSH_AUTH_PAGEANT);
1222 }
1223 pvar->auth_state.supported_types = types;
1224
1225 if (types == 0) {
1226 UTIL_get_lang_msg("MSG_NOAUTHMETHOD_ERROR", pvar,
1227 "Server does not support any of the authentication options\n"
1228 "provided by TTSSH. This connection will now close.");
1229 notify_fatal_error(pvar, pvar->ts->UIMsg, TRUE);
1230 return 0;
1231 } else {
1232 if (pvar->auth_state.auth_dialog != NULL) {
1233 update_server_supported_types(pvar, pvar->auth_state.auth_dialog);
1234 }
1235
1236 return 1;
1237 }
1238 }
1239
1240 static void start_user_auth(PTInstVar pvar)
1241 {
1242 // �F���_�C�A���O���\�������� (2004.12.1 yutaka)
1243 PostMessage(pvar->NotificationWindow, WM_COMMAND, (WPARAM) ID_SSHAUTH,
1244 (LPARAM) NULL);
1245 pvar->auth_state.cur_cred.method = SSH_AUTH_NONE;
1246 }
1247
1248 static void try_default_auth(PTInstVar pvar)
1249 {
1250 if (pvar->session_settings.TryDefaultAuth) {
1251 switch (pvar->session_settings.DefaultAuthMethod) {
1252 case SSH_AUTH_RSA:{
1253 BOOL invalid_passphrase;
1254 char password[] = "";
1255
1256 pvar->auth_state.cur_cred.key_pair
1257 =
1258 KEYFILES_read_private_key(pvar,
1259 pvar->session_settings.
1260 DefaultRSAPrivateKeyFile,
1261 password,
1262 &invalid_passphrase, TRUE);
1263 if (pvar->auth_state.cur_cred.key_pair == NULL) {
1264 return;
1265 } else {
1266 pvar->auth_state.cur_cred.method = SSH_AUTH_RSA;
1267 }
1268 break;
1269 }
1270
1271 case SSH_AUTH_RHOSTS:
1272 if (pvar->session_settings.
1273 DefaultRhostsHostPrivateKeyFile[0] != 0) {
1274 BOOL invalid_passphrase;
1275 char password[] = "";
1276
1277 pvar->auth_state.cur_cred.key_pair
1278 =
1279 KEYFILES_read_private_key(pvar,
1280 pvar->session_settings.
1281 DefaultRhostsHostPrivateKeyFile,
1282 password,
1283 &invalid_passphrase, TRUE);
1284 if (pvar->auth_state.cur_cred.key_pair == NULL) {
1285 return;
1286 } else {
1287 pvar->auth_state.cur_cred.method = SSH_AUTH_RHOSTS_RSA;
1288 }
1289 } else {
1290 pvar->auth_state.cur_cred.method = SSH_AUTH_RHOSTS;
1291 }
1292
1293 pvar->auth_state.cur_cred.rhosts_client_user =
1294 _strdup(pvar->session_settings.DefaultRhostsLocalUserName);
1295 break;
1296
1297 case SSH_AUTH_PAGEANT:
1298 pvar->auth_state.cur_cred.method = SSH_AUTH_PAGEANT;
1299 break;
1300
1301 case SSH_AUTH_PASSWORD:
1302 pvar->auth_state.cur_cred.password = _strdup("");
1303 pvar->auth_state.cur_cred.method = SSH_AUTH_PASSWORD;
1304 break;
1305
1306 case SSH_AUTH_TIS:
1307 default:
1308 return;
1309 }
1310
1311 pvar->auth_state.user =
1312 _strdup(pvar->session_settings.DefaultUserName);
1313 }
1314 }
1315
1316 void AUTH_notify_end_error(PTInstVar pvar)
1317 {
1318 if ((pvar->auth_state.flags & AUTH_START_USER_AUTH_ON_ERROR_END) != 0) {
1319 start_user_auth(pvar);
1320 pvar->auth_state.flags &= ~AUTH_START_USER_AUTH_ON_ERROR_END;
1321 }
1322 }
1323
1324 void AUTH_advance_to_next_cred(PTInstVar pvar)
1325 {
1326 logprintf(LOG_LEVEL_VERBOSE, "User authentication will be shown by %d method.", pvar->auth_state.cur_cred.method);
1327
1328 pvar->auth_state.failed_method = pvar->auth_state.cur_cred.method;
1329
1330 if (pvar->auth_state.cur_cred.method == SSH_AUTH_NONE) {
1331 try_default_auth(pvar);
1332
1333 if (pvar->auth_state.cur_cred.method == SSH_AUTH_NONE) {
1334 if (pvar->err_msg != NULL) {
1335 pvar->auth_state.flags |=
1336 AUTH_START_USER_AUTH_ON_ERROR_END;
1337 } else {
1338 // �������F���_�C�A���O���o�������� (2004.12.1 yutaka)
1339 // �R�}���h���C���w������������
1340 start_user_auth(pvar);
1341 }
1342 }
1343 } else {
1344 // �������F���_�C�A���O���o�������� (2004.12.1 yutaka)
1345 // �R�}���h���C���w������(/auth=xxxx)������
1346 start_user_auth(pvar);
1347 }
1348 }
1349
1350 static void init_TIS_dlg(PTInstVar pvar, HWND dlg)
1351 {
1352 char uimsg[MAX_UIMSG];
1353
1354 GetWindowText(dlg, uimsg, sizeof(uimsg));
1355 UTIL_get_lang_msg("DLG_TIS_TITLE", pvar, uimsg);
1356 SetWindowText(dlg, pvar->ts->UIMsg);
1357 GetDlgItemText(dlg, IDC_SSHAUTHBANNER, uimsg, sizeof(uimsg));
1358 UTIL_get_lang_msg("DLG_TIS_BANNER", pvar, uimsg);
1359 SetDlgItemText(dlg, IDC_SSHAUTHBANNER, pvar->ts->UIMsg);
1360 GetDlgItemText(dlg, IDOK, uimsg, sizeof(uimsg));
1361 UTIL_get_lang_msg("BTN_OK", pvar, uimsg);
1362 SetDlgItemText(dlg, IDOK, pvar->ts->UIMsg);
1363 GetDlgItemText(dlg, IDCANCEL, uimsg, sizeof(uimsg));
1364 UTIL_get_lang_msg("BTN_DISCONNECT", pvar, uimsg);
1365 SetDlgItemText(dlg, IDCANCEL, pvar->ts->UIMsg);
1366
1367 init_auth_machine_banner(pvar, dlg);
1368 init_password_control(pvar, dlg, IDC_SSHPASSWORD, NULL);
1369
1370 if (pvar->auth_state.TIS_prompt != NULL) {
1371 if (strlen(pvar->auth_state.TIS_prompt) > 10000) {
1372 pvar->auth_state.TIS_prompt[10000] = 0;
1373 }
1374 SetDlgItemText(dlg, IDC_SSHAUTHBANNER2,
1375 pvar->auth_state.TIS_prompt);
1376 destroy_malloced_string(&pvar->auth_state.TIS_prompt);
1377 }
1378
1379 if (pvar->auth_state.echo) {
1380 SendMessage(GetDlgItem(dlg, IDC_SSHPASSWORD), EM_SETPASSWORDCHAR, 0, 0);
1381 }
1382 }
1383
1384 static BOOL end_TIS_dlg(PTInstVar pvar, HWND dlg)
1385 {
1386 char *password =
1387 alloc_control_text(GetDlgItem(dlg, IDC_SSHPASSWORD));
1388
1389 pvar->auth_state.cur_cred.method = SSH_AUTH_TIS;
1390 pvar->auth_state.cur_cred.password = password;
1391 pvar->auth_state.auth_dialog = NULL;
1392
1393 // add
1394 if (SSHv2(pvar)) {
1395 pvar->keyboard_interactive_password_input = 1;
1396 handle_SSH2_userauth_inforeq(pvar);
1397 }
1398
1399 SSH_notify_cred(pvar);
1400
1401 EndDialog(dlg, 1);
1402 return TRUE;
1403 }
1404
1405 static INT_PTR CALLBACK TIS_dlg_proc(HWND dlg, UINT msg, WPARAM wParam,
1406 LPARAM lParam)
1407 {
1408 PTInstVar pvar;
1409
1410 switch (msg) {
1411 case WM_INITDIALOG:
1412 pvar = (PTInstVar) lParam;
1413 pvar->auth_state.auth_dialog = dlg;
1414 SetWindowLongPtr(dlg, DWLP_USER, lParam);
1415
1416 init_TIS_dlg(pvar, dlg);
1417
1418 // /auth=challenge ������ (2007.10.5 maya)
1419 if (pvar->ssh2_autologin == 1) {
1420 SetDlgItemText(dlg, IDC_SSHPASSWORD, pvar->ssh2_password);
1421 SendMessage(dlg, WM_COMMAND, IDOK, 0);
1422 }
1423
1424 CenterWindow(dlg, GetParent(dlg));
1425 return FALSE; /* because we set the focus */
1426
1427 case WM_COMMAND:
1428 pvar = (PTInstVar) GetWindowLongPtr(dlg, DWLP_USER);
1429
1430 switch (LOWORD(wParam)) {
1431 case IDOK:
1432 return end_TIS_dlg(pvar, dlg);
1433
1434 case IDCANCEL: /* kill the connection */
1435 pvar->auth_state.auth_dialog = NULL;
1436 notify_closed_connection(pvar, "authentication cancelled");
1437 EndDialog(dlg, 0);
1438 return TRUE;
1439
1440 case IDCLOSE:
1441 // �F�������l�b�g���[�N���f�����������A���Y���b�Z�[�W���_�C�A���O���������B
1442 pvar->auth_state.auth_dialog = NULL;
1443 EndDialog(dlg, 0);
1444 return TRUE;
1445
1446 default:
1447 return FALSE;
1448 }
1449
1450 default:
1451 return FALSE;
1452 }
1453 }
1454
1455 void AUTH_do_cred_dialog(PTInstVar pvar)
1456 {
1457 if (pvar->auth_state.auth_dialog == NULL) {
1458 HWND cur_active = GetActiveWindow();
1459 DLGPROC dlg_proc;
1460 LPCTSTR dialog_template;
1461
1462 switch (pvar->auth_state.mode) {
1463 case TIS_AUTH_MODE:
1464 dialog_template = MAKEINTRESOURCE(IDD_SSHTISAUTH);
1465 dlg_proc = TIS_dlg_proc;
1466 break;
1467 case GENERIC_AUTH_MODE:
1468 default:
1469 dialog_template = MAKEINTRESOURCE(IDD_SSHAUTH);
1470 dlg_proc = auth_dlg_proc;
1471 }
1472
1473 if (!DialogBoxParam(hInst, dialog_template,
1474 cur_active !=
1475 NULL ? cur_active : pvar->NotificationWindow,
1476 dlg_proc, (LPARAM) pvar) == -1) {
1477 UTIL_get_lang_msg("MSG_CREATEWINDOW_AUTH_ERROR", pvar,
1478 "Unable to display authentication dialog box.\n"
1479 "Connection terminated.");
1480 notify_fatal_error(pvar, pvar->ts->UIMsg, TRUE);
1481 }
1482 }
1483 }
1484
1485 static void init_default_auth_dlg(PTInstVar pvar, HWND dlg)
1486 {
1487 int id;
1488 TCHAR user_name[UNLEN+1];
1489 DWORD len;
1490 TCHAR uimsg[MAX_UIMSG];
1491 TCHAR uimsg2[MAX_UIMSG];
1492 const static DlgTextInfo text_info[] = {
1493 { 0, "DLG_AUTHSETUP_TITLE" },
1494 { IDC_SSHAUTHBANNER, "DLG_AUTHSETUP_BANNER" },
1495 { IDC_SSH_USERNAME, "DLG_AUTHSETUP_USERNAME" },
1496 { IDC_SSH_NO_USERNAME, "DLG_AUTHSETUP_NO_USERNAME" },
1497 { IDC_SSH_DEFAULTUSERNAME, "DLG_AUTHSETUP_DEFAULT_USERNAME" },
1498 { IDC_SSH_WINDOWS_USERNAME, "DLG_AUTHSETUP_LOGON_USERNAME" },
1499 { IDC_SSH_WINDOWS_USERNAME_TEXT, "DLG_AUTHSETUP_LOGON_USERNAME_TEXT" },
1500 { IDC_SSH_AUTHMETHOD, "DLG_AUTHSETUP_METHOD" },
1501 { IDC_SSHUSEPASSWORD, "DLG_AUTHSETUP_METHOD_PASSWORD" },
1502 { IDC_SSHUSERSA, "DLG_AUTHSETUP_METHOD_RSA" },
1503 { IDC_SSHUSERHOSTS, "DLG_AUTHSETUP_METHOD_RHOST" },
1504 { IDC_SSHUSETIS, "DLG_AUTHSETUP_METHOD_CHALLENGE" },
1505 { IDC_SSHUSEPAGEANT, "DLG_AUTHSETUP_METHOD_PAGEANT" },
1506 { IDC_RSAFILENAMELABEL, "DLG_AUTH_PRIVATEKEY" },
1507 { IDC_LOCALUSERNAMELABEL, "DLG_AUTH_LOCALUSER" },
1508 { IDC_HOSTRSAFILENAMELABEL, "DLG_AUTH_HOST_PRIVATEKEY" },
1509 { IDC_CHECKAUTH, "DLG_AUTHSETUP_CHECKAUTH" },
1510 { IDOK, "BTN_OK" },
1511 { IDCANCEL, "BTN_CANCEL" },
1512 { IDC_SSHAUTHSETUP_HELP, "BTN_HELP" },
1513 };
1514
1515 SetI18DlgStrs("TTSSH", dlg, text_info, _countof(text_info), pvar->ts->UILanguageFile);
1516
1517 switch (pvar->settings.DefaultAuthMethod) {
1518 case SSH_AUTH_RSA:
1519 CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
1520 IDC_SSHUSERSA);
1521 break;
1522 case SSH_AUTH_RHOSTS:
1523 case SSH_AUTH_RHOSTS_RSA:
1524 CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
1525 IDC_SSHUSERHOSTS);
1526 break;
1527 case SSH_AUTH_TIS:
1528 CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
1529 IDC_SSHUSETIS);
1530 break;
1531 case SSH_AUTH_PAGEANT:
1532 CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
1533 IDC_SSHUSEPAGEANT);
1534 break;
1535 case SSH_AUTH_PASSWORD:
1536 default:
1537 CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL,
1538 IDC_SSHUSEPASSWORD);
1539 }
1540
1541 SetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->settings.DefaultUserName);
1542 SetDlgItemText(dlg, IDC_RSAFILENAME,
1543 pvar->settings.DefaultRSAPrivateKeyFile);
1544 SetDlgItemText(dlg, IDC_HOSTRSAFILENAME,
1545 pvar->settings.DefaultRhostsHostPrivateKeyFile);
1546 SetDlgItemText(dlg, IDC_LOCALUSERNAME,
1547 pvar->settings.DefaultRhostsLocalUserName);
1548
1549 if (pvar->settings.CheckAuthListFirst) {
1550 CheckDlgButton(dlg, IDC_CHECKAUTH, TRUE);
1551 }
1552
1553 if (pvar->settings.DefaultUserType == 1 &&
1554 pvar->session_settings.DefaultUserName[0] == 0) {
1555 // ���������u�����������v����������
1556 pvar->settings.DefaultUserType = 0;
1557 }
1558 id = pvar->settings.DefaultUserType == 1 ? IDC_SSH_DEFAULTUSERNAME :
1559 pvar->settings.DefaultUserType == 2 ? IDC_SSH_WINDOWS_USERNAME :
1560 IDC_SSH_NO_USERNAME;
1561 CheckRadioButton(dlg, IDC_SSH_NO_USERNAME, IDC_SSH_WINDOWS_USERNAME, id);
1562
1563 len = _countof(user_name);
1564 GetUserName(user_name, &len);
1565
1566 GetDlgItemText(dlg, IDC_SSH_WINDOWS_USERNAME_TEXT, uimsg, _countof(uimsg));
1567 _stprintf_s(uimsg2, _countof(uimsg2), uimsg, user_name);
1568 SetDlgItemText(dlg, IDC_SSH_WINDOWS_USERNAME_TEXT, uimsg2);
1569 }
1570
1571 static BOOL end_default_auth_dlg(PTInstVar pvar, HWND dlg)
1572 {
1573 if (IsDlgButtonChecked(dlg, IDC_SSHUSERSA)) {
1574 pvar->settings.DefaultAuthMethod = SSH_AUTH_RSA;
1575 } else if (IsDlgButtonChecked(dlg, IDC_SSHUSERHOSTS)) {
1576 if (GetWindowTextLength(GetDlgItem(dlg, IDC_HOSTRSAFILENAME)) > 0) {
1577 pvar->settings.DefaultAuthMethod = SSH_AUTH_RHOSTS_RSA;
1578 } else {
1579 pvar->settings.DefaultAuthMethod = SSH_AUTH_RHOSTS;
1580 }
1581 } else if (IsDlgButtonChecked(dlg, IDC_SSHUSETIS)) {
1582 pvar->settings.DefaultAuthMethod = SSH_AUTH_TIS;
1583 } else if (IsDlgButtonChecked(dlg, IDC_SSHUSEPAGEANT)) {
1584 pvar->settings.DefaultAuthMethod = SSH_AUTH_PAGEANT;
1585 } else {
1586 pvar->settings.DefaultAuthMethod = SSH_AUTH_PASSWORD;
1587 }
1588
1589 GetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->settings.DefaultUserName,
1590 sizeof(pvar->settings.DefaultUserName));
1591 GetDlgItemText(dlg, IDC_RSAFILENAME,
1592 pvar->settings.DefaultRSAPrivateKeyFile,
1593 sizeof(pvar->settings.DefaultRSAPrivateKeyFile));
1594 GetDlgItemText(dlg, IDC_HOSTRSAFILENAME,
1595 pvar->settings.DefaultRhostsHostPrivateKeyFile,
1596 sizeof(pvar->settings.DefaultRhostsHostPrivateKeyFile));
1597 GetDlgItemText(dlg, IDC_LOCALUSERNAME,
1598 pvar->settings.DefaultRhostsLocalUserName,
1599 sizeof(pvar->settings.DefaultRhostsLocalUserName));
1600 pvar->settings.DefaultUserType =
1601 IsDlgButtonChecked(dlg, IDC_SSH_DEFAULTUSERNAME) ? 1 :
1602 IsDlgButtonChecked(dlg, IDC_SSH_WINDOWS_USERNAME) ? 2 : 0;
1603
1604 if (IsDlgButtonChecked(dlg, IDC_CHECKAUTH)) {
1605 pvar->settings.CheckAuthListFirst = TRUE;
1606 }
1607 else {
1608 pvar->settings.CheckAuthListFirst = FALSE;
1609 }
1610
1611 EndDialog(dlg, 1);
1612 return TRUE;
1613 }
1614
1615 static INT_PTR CALLBACK default_auth_dlg_proc(HWND dlg, UINT msg,
1616 WPARAM wParam, LPARAM lParam)
1617 {
1618 PTInstVar pvar;
1619
1620 switch (msg) {
1621 case WM_INITDIALOG:
1622 pvar = (PTInstVar) lParam;
1623 SetWindowLongPtr(dlg, DWLP_USER, lParam);
1624
1625 init_default_auth_dlg(pvar, dlg);
1626 CenterWindow(dlg, GetParent(dlg));
1627 return TRUE; /* because we do not set the focus */
1628
1629 case WM_COMMAND:
1630 pvar = (PTInstVar) GetWindowLongPtr(dlg, DWLP_USER);
1631
1632 switch (LOWORD(wParam)) {
1633 case IDOK:
1634 return end_default_auth_dlg(pvar, dlg);
1635
1636 case IDCANCEL:
1637 EndDialog(dlg, 0);
1638 return TRUE;
1639
1640 case IDC_SSHAUTHSETUP_HELP:
1641 PostMessage(GetParent(dlg), WM_USER_DLGHELP2, HlpMenuSetupSshauth, 0);
1642 return TRUE;
1643
1644 case IDC_CHOOSERSAFILE:
1645 choose_RSA_key_file(dlg, pvar);
1646 return TRUE;
1647
1648 case IDC_CHOOSEHOSTRSAFILE:
1649 choose_host_RSA_key_file(dlg, pvar);
1650 return TRUE;
1651
1652 default:
1653 return FALSE;
1654 }
1655
1656 default:
1657 return FALSE;
1658 }
1659 }
1660
1661 void AUTH_init(PTInstVar pvar)
1662 {
1663 pvar->auth_state.failed_method = SSH_AUTH_NONE;
1664 pvar->auth_state.auth_dialog = NULL;
1665 pvar->auth_state.user = NULL;
1666 pvar->auth_state.flags = 0;
1667 pvar->auth_state.TIS_prompt = NULL;
1668 pvar->auth_state.echo = 0;
1669 pvar->auth_state.supported_types = 0;
1670 pvar->auth_state.cur_cred.method = SSH_AUTH_NONE;
1671 pvar->auth_state.cur_cred.password = NULL;
1672 pvar->auth_state.cur_cred.rhosts_client_user = NULL;
1673 pvar->auth_state.cur_cred.key_pair = NULL;
1674 AUTH_set_generic_mode(pvar);
1675 }
1676
1677 void AUTH_set_generic_mode(PTInstVar pvar)
1678 {
1679 pvar->auth_state.mode = GENERIC_AUTH_MODE;
1680 destroy_malloced_string(&pvar->auth_state.TIS_prompt);
1681 }
1682
1683 void AUTH_set_TIS_mode(PTInstVar pvar, char *prompt, int len, int echo)
1684 {
1685 if (pvar->auth_state.cur_cred.method == SSH_AUTH_TIS) {
1686 pvar->auth_state.mode = TIS_AUTH_MODE;
1687
1688 destroy_malloced_string(&pvar->auth_state.TIS_prompt);
1689 pvar->auth_state.TIS_prompt = malloc(len + 1);
1690 memcpy(pvar->auth_state.TIS_prompt, prompt, len);
1691 pvar->auth_state.TIS_prompt[len] = 0;
1692 pvar->auth_state.echo = echo;
1693 } else {
1694 AUTH_set_generic_mode(pvar);
1695 }
1696 }
1697
1698 void AUTH_do_default_cred_dialog(PTInstVar pvar)
1699 {
1700 HWND cur_active = GetActiveWindow();
1701
1702 if (DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SSHAUTHSETUP),
1703 cur_active != NULL ? cur_active
1704 : pvar->NotificationWindow,
1705 default_auth_dlg_proc, (LPARAM) pvar) == -1) {
1706 UTIL_get_lang_msg("MSG_CREATEWINDOW_AUTHSETUP_ERROR", pvar,
1707 "Unable to display authentication setup dialog box.");
1708 notify_nonfatal_error(pvar, pvar->ts->UIMsg);
1709 }
1710 }
1711
1712 void AUTH_destroy_cur_cred(PTInstVar pvar)
1713 {
1714 destroy_malloced_string(&pvar->auth_state.cur_cred.password);
1715 destroy_malloced_string(&pvar->auth_state.cur_cred.rhosts_client_user);
1716 if (pvar->auth_state.cur_cred.key_pair != NULL) {
1717 key_free(pvar->auth_state.cur_cred.key_pair);
1718 pvar->auth_state.cur_cred.key_pair = NULL;
1719 }
1720 }
1721
1722 static const char *get_auth_method_name(SSHAuthMethod auth)
1723 {
1724 switch (auth) {
1725 case SSH_AUTH_PASSWORD:
1726 return "password";
1727 case SSH_AUTH_RSA:
1728 return "publickey";
1729 case SSH_AUTH_PAGEANT:
1730 return "publickey";
1731 case SSH_AUTH_RHOSTS:
1732 return "rhosts";
1733 case SSH_AUTH_RHOSTS_RSA:
1734 return "rhosts with RSA";
1735 case SSH_AUTH_TIS:
1736 return "challenge/response (TIS)";
1737 default:
1738 return "unknown method";
1739 }
1740 }
1741
1742 void AUTH_get_auth_info(PTInstVar pvar, char *dest, int len)
1743 {
1744 const char *method = "unknown";
1745 char buf[256];
1746
1747 if (pvar->auth_state.user == NULL) {
1748 strncpy_s(dest, len, "None", _TRUNCATE);
1749 } else if (pvar->auth_state.cur_cred.method != SSH_AUTH_NONE) {
1750 if (SSHv1(pvar)) {
1751 UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO", pvar, "User '%s', using %s");
1752 _snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg,
1753 pvar->auth_state.user,
1754 get_auth_method_name(pvar->auth_state.cur_cred.method));
1755
1756 if (pvar->auth_state.cur_cred.method == SSH_AUTH_RSA) {
1757 UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO2", pvar, " with %s key");
1758 _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg,
1759 "RSA");
1760 strncat_s(dest, len, buf, _TRUNCATE);
1761 }
1762 else if (pvar->auth_state.cur_cred.method == SSH_AUTH_PAGEANT) {
1763 UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO3", pvar, " with %s key from Pageant");
1764 _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg,
1765 "RSA");
1766 strncat_s(dest, len, buf, _TRUNCATE);
1767 }
1768 } else {
1769 // SSH2:�F�����\�b�h������ (2004.12.23 yutaka)
1770 // keyboard-interactive���\�b�h������ (2005.3.12 yutaka)
1771 if (pvar->auth_state.cur_cred.method == SSH_AUTH_PASSWORD ||
1772 pvar->auth_state.cur_cred.method == SSH_AUTH_TIS) {
1773 // keyboard-interactive���\�b�h������ (2005.1.24 yutaka)
1774 if (pvar->auth_state.cur_cred.method == SSH_AUTH_TIS) {
1775 method = "keyboard-interactive";
1776 } else {
1777 method = get_auth_method_name(pvar->auth_state.cur_cred.method);
1778 }
1779 UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO", pvar, "User '%s', using %s");
1780 _snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg,
1781 pvar->auth_state.user, method);
1782 }
1783 else if (pvar->auth_state.cur_cred.method == SSH_AUTH_RSA) {
1784 method = get_auth_method_name(pvar->auth_state.cur_cred.method);
1785 UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO", pvar, "User '%s', using %s");
1786 _snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg,
1787 pvar->auth_state.user,
1788 get_auth_method_name(pvar->auth_state.cur_cred.method));
1789
1790 UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO2", pvar, " with %s key");
1791 _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg,
1792 ssh_key_type(pvar->auth_state.cur_cred.key_pair->type));
1793 strncat_s(dest, len, buf, _TRUNCATE);
1794 }
1795 else if (pvar->auth_state.cur_cred.method == SSH_AUTH_PAGEANT) {
1796 int key_len = get_uint32_MSBfirst(pvar->pageant_curkey + 4);
1797 char *s = (char *)malloc(key_len+1);
1798
1799 method = get_auth_method_name(pvar->auth_state.cur_cred.method);
1800 UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO", pvar, "User '%s', using %s");
1801 _snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg,
1802 pvar->auth_state.user,
1803 get_auth_method_name(pvar->auth_state.cur_cred.method));
1804
1805 memcpy(s, pvar->pageant_curkey+4+4, key_len);
1806 s[key_len] = '\0';
1807 UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO3", pvar, " with %s key from Pageant");
1808 _snprintf_s(buf, sizeof(buf), _TRUNCATE, pvar->ts->UIMsg,
1809 ssh_key_type(get_keytype_from_name(s)));
1810 strncat_s(dest, len, buf, _TRUNCATE);
1811
1812 free(s);
1813 }
1814 }
1815
1816 } else {
1817 UTIL_get_lang_msg("DLG_ABOUT_AUTH_INFO", pvar, "User '%s', using %s");
1818 _snprintf_s(dest, len, _TRUNCATE, pvar->ts->UIMsg, pvar->auth_state.user,
1819 get_auth_method_name(pvar->auth_state.failed_method));
1820 }
1821
1822 dest[len - 1] = 0;
1823 }
1824
1825 void AUTH_notify_disconnecting(PTInstVar pvar)
1826 {
1827 if (pvar->auth_state.auth_dialog != NULL) {
1828 PostMessage(pvar->auth_state.auth_dialog, WM_COMMAND, IDCANCEL, 0);
1829 /* the main window might not go away if it's not enabled. (see vtwin.cpp) */
1830 EnableWindow(pvar->NotificationWindow, TRUE);
1831 }
1832 }
1833
1834 // TCP�Z�b�V�������N���[�Y�����������A�F���_�C�A���O���������������w�����o���B
1835 // AUTH_notify_disconnecting()�����������A�_�C�A���O���������������A
1836 // SSH�T�[�o�����m���o�������B
1837 void AUTH_notify_closing_on_exit(PTInstVar pvar)
1838 {
1839 if (pvar->auth_state.auth_dialog != NULL) {
1840 logprintf(LOG_LEVEL_INFO, "%s: Notify closing message to the authentication dialog.", __FUNCTION__);
1841 PostMessage(pvar->auth_state.auth_dialog, WM_COMMAND, IDCLOSE, 0);
1842 }
1843 }
1844
1845 void AUTH_end(PTInstVar pvar)
1846 {
1847 destroy_malloced_string(&pvar->auth_state.user);
1848 destroy_malloced_string(&pvar->auth_state.TIS_prompt);
1849
1850 AUTH_destroy_cur_cred(pvar);
1851 }

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