| 1 |
/* |
/* |
| 2 |
* Copyright (c) 1998-2001, Robert O'Callahan |
* Copyright (c) 1998-2001, Robert O'Callahan |
| 3 |
* (C) 2004-2017 TeraTerm Project |
* (C) 2004-2019 TeraTerm Project |
| 4 |
* All rights reserved. |
* All rights reserved. |
| 5 |
* |
* |
| 6 |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
| 38 |
#include <fcntl.h> |
#include <fcntl.h> |
| 39 |
#include <stdlib.h> |
#include <stdlib.h> |
| 40 |
#include <errno.h> |
#include <errno.h> |
| 41 |
|
#include <crtdbg.h> |
| 42 |
|
|
| 43 |
#include "resource.h" |
#include "resource.h" |
| 44 |
#include "keyfiles.h" |
#include "keyfiles.h" |
| 45 |
#include "libputty.h" |
#include "libputty.h" |
| 46 |
#include "tipwin.h" |
#include "tipwin.h" |
| 47 |
|
#include "auth.h" |
| 48 |
|
|
| 49 |
|
#if defined(_DEBUG) |
| 50 |
|
#define malloc(l) _malloc_dbg((l), _NORMAL_BLOCK, __FILE__, __LINE__) |
| 51 |
|
#define free(p) _free_dbg((p), _NORMAL_BLOCK) |
| 52 |
|
#endif |
| 53 |
|
|
| 54 |
#define AUTH_START_USER_AUTH_ON_ERROR_END 1 |
#define AUTH_START_USER_AUTH_ON_ERROR_END 1 |
| 55 |
|
|
| 80 |
IDC_SSHUSERHOSTS, IDC_SSHUSETIS, -1, |
IDC_SSHUSERHOSTS, IDC_SSHUSETIS, -1, |
| 81 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, IDC_SSHUSEPAGEANT, -1 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, IDC_SSHUSEPAGEANT, -1 |
| 82 |
}; |
}; |
|
static TipWin *tipwin; |
|
| 83 |
|
|
| 84 |
LRESULT CALLBACK password_wnd_proc(HWND control, UINT msg, |
typedef struct { |
| 85 |
WPARAM wParam, LPARAM lParam) |
WNDPROC ProcOrg; |
| 86 |
|
PTInstVar pvar; |
| 87 |
|
TipWin *tipwin; |
| 88 |
|
} TPasswordControlData; |
| 89 |
|
|
| 90 |
|
static LRESULT CALLBACK password_wnd_proc(HWND control, UINT msg, |
| 91 |
|
WPARAM wParam, LPARAM lParam) |
| 92 |
{ |
{ |
| 93 |
|
LRESULT result; |
| 94 |
|
TPasswordControlData *data = (TPasswordControlData *)GetWindowLongPtr(control, GWLP_USERDATA); |
| 95 |
switch (msg) { |
switch (msg) { |
| 96 |
case WM_CHAR: |
case WM_CHAR: |
| 97 |
if ((GetKeyState(VK_CONTROL) & 0x8000) != 0) { |
if ((GetKeyState(VK_CONTROL) & 0x8000) != 0) { |
| 100 |
SendMessage(control, EM_REPLACESEL, (WPARAM) TRUE, |
SendMessage(control, EM_REPLACESEL, (WPARAM) TRUE, |
| 101 |
(LPARAM) (TCHAR *) chars); |
(LPARAM) (TCHAR *) chars); |
| 102 |
|
|
| 103 |
if (tipwin == NULL) { |
if (data->tipwin == NULL) { |
| 104 |
TCHAR *s; |
TCHAR uimsg[MAX_UIMSG]; |
| 105 |
RECT rect; |
RECT rect; |
| 106 |
|
PTInstVar pvar = data->pvar; |
| 107 |
|
UTIL_get_lang_msg("DLG_AUTH_TIP_CONTROL_CODE", pvar, "control character is entered"); |
| 108 |
|
_tcscpy_s(uimsg, _countof(uimsg), pvar->ts->UIMsg); |
| 109 |
if (wParam == 'V' - 'A' + 1) { |
if (wParam == 'V' - 'A' + 1) { |
| 110 |
s = _T("制御文字を入力しています") |
// CTRL + V |
| 111 |
_T("\n") |
_tcscat_s(uimsg, _countof(uimsg), _T("\n")); |
| 112 |
_T("クリップボードからの貼り付けのショートカットはCTRL+Insertです"); |
UTIL_get_lang_msg("DLG_AUTH_TIP_PASTE_KEY", pvar, "Use Shift + Insert to paste from clipboard"); |
| 113 |
} else { |
_tcscat_s(uimsg, _countof(uimsg), pvar->ts->UIMsg); |
|
s = _T("制御文字を入力しています"); |
|
| 114 |
} |
} |
| 115 |
GetWindowRect(control, &rect); |
GetWindowRect(control, &rect); |
| 116 |
tipwin = TipWinCreate(control, rect.left, rect.bottom, s); |
data->tipwin = TipWinCreate(control, rect.left, rect.bottom, uimsg); |
| 117 |
} |
} |
| 118 |
|
|
| 119 |
return 0; |
return 0; |
| 120 |
} else { |
} else { |
| 121 |
if (tipwin != NULL) { |
if (data->tipwin != NULL) { |
| 122 |
TipWinDestroy(tipwin); |
TipWinDestroy(data->tipwin); |
| 123 |
tipwin = NULL; |
data->tipwin = NULL; |
| 124 |
} |
} |
| 125 |
} |
} |
| 126 |
break; |
break; |
| 127 |
case WM_NCDESTROY: |
} |
| 128 |
if (tipwin != NULL) { |
|
| 129 |
TipWinDestroy(tipwin); |
result = CallWindowProc((WNDPROC)data->ProcOrg, |
| 130 |
tipwin = NULL; |
control, msg, wParam, lParam); |
| 131 |
|
|
| 132 |
|
if (msg == WM_NCDESTROY) { |
| 133 |
|
SetWindowLongPtr(control, GWLP_WNDPROC, (LONG_PTR)data->ProcOrg); |
| 134 |
|
if (data->tipwin != NULL) { |
| 135 |
|
TipWinDestroy(data->tipwin); |
| 136 |
|
data->tipwin = NULL; |
| 137 |
} |
} |
| 138 |
break; |
free(data); |
| 139 |
} |
} |
| 140 |
|
|
| 141 |
return CallWindowProc((WNDPROC) GetWindowLong(control, GWL_USERDATA), |
return result; |
|
control, msg, wParam, lParam); |
|
| 142 |
} |
} |
| 143 |
|
|
| 144 |
static void init_password_control(HWND dlg) |
void init_password_control(PTInstVar pvar, HWND dlg, int item) |
| 145 |
{ |
{ |
| 146 |
HWND passwordControl = GetDlgItem(dlg, IDC_SSHPASSWORD); |
HWND passwordControl = GetDlgItem(dlg, item); |
| 147 |
|
TPasswordControlData *data = (TPasswordControlData *)malloc(sizeof(TPasswordControlData)); |
| 148 |
SetWindowLong(passwordControl, GWL_USERDATA, |
data->ProcOrg = (WNDPROC)GetWindowLongPtr(passwordControl, GWLP_WNDPROC); |
| 149 |
SetWindowLong(passwordControl, GWL_WNDPROC, |
data->pvar = pvar; |
| 150 |
(LONG) password_wnd_proc)); |
data->tipwin = NULL; |
| 151 |
|
SetWindowLongPtr(passwordControl, GWLP_WNDPROC, (LONG_PTR)password_wnd_proc); |
| 152 |
|
SetWindowLongPtr(passwordControl, GWLP_USERDATA, (LONG_PTR)data); |
| 153 |
SetFocus(passwordControl); |
SetFocus(passwordControl); |
| 154 |
} |
} |
| 155 |
|
|
| 291 |
SetDlgItemText(dlg, IDCANCEL, pvar->ts->UIMsg); |
SetDlgItemText(dlg, IDCANCEL, pvar->ts->UIMsg); |
| 292 |
|
|
| 293 |
init_auth_machine_banner(pvar, dlg); |
init_auth_machine_banner(pvar, dlg); |
| 294 |
init_password_control(dlg); |
init_password_control(pvar, dlg, IDC_SSHPASSWORD); |
| 295 |
|
|
| 296 |
// 認証失敗後はラベルを書き換え |
// 認証失敗後はラベルを書き換え |
| 297 |
if (pvar->auth_state.failed_method != SSH_AUTH_NONE) { |
if (pvar->auth_state.failed_method != SSH_AUTH_NONE) { |
| 1219 |
SetDlgItemText(dlg, IDCANCEL, pvar->ts->UIMsg); |
SetDlgItemText(dlg, IDCANCEL, pvar->ts->UIMsg); |
| 1220 |
|
|
| 1221 |
init_auth_machine_banner(pvar, dlg); |
init_auth_machine_banner(pvar, dlg); |
| 1222 |
init_password_control(dlg); |
init_password_control(pvar, dlg, IDC_SSHPASSWORD); |
| 1223 |
|
|
| 1224 |
if (pvar->auth_state.TIS_prompt != NULL) { |
if (pvar->auth_state.TIS_prompt != NULL) { |
| 1225 |
if (strlen(pvar->auth_state.TIS_prompt) > 10000) { |
if (strlen(pvar->auth_state.TIS_prompt) > 10000) { |