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 9208 - (hide annotations) (download) (as text)
Sat Apr 17 06:15:51 2021 UTC (2 years, 11 months ago) by nmaya
File MIME type: text/x-csrc
File size: 60961 byte(s)
create a branch for chacha20-poly1305

from 4-stable
planned to merge to 4-stable and trunk

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

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