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

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