Develop and Download Open Source Software

Browse Subversion Repository

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8220 - (hide annotations) (download) (as text)
Mon Sep 23 11:41:18 2019 UTC (4 years, 6 months ago) by zmatsuo
Original Path: trunk/ttssh2/ttxssh/auth.c
File MIME type: text/x-csrc
File size: 61129 byte(s)
SSHユーザー名オプションボタンのTABストップを修正

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

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