| 1 |
yutakakn |
2728 |
/* |
| 2 |
|
|
Copyright (c) 1998-2001, Robert O'Callahan |
| 3 |
|
|
All rights reserved. |
| 4 |
|
|
|
| 5 |
|
|
Redistribution and use in source and binary forms, with or without modification, |
| 6 |
|
|
are permitted provided that the following conditions are met: |
| 7 |
|
|
|
| 8 |
|
|
Redistributions of source code must retain the above copyright notice, this list of |
| 9 |
|
|
conditions and the following disclaimer. |
| 10 |
|
|
|
| 11 |
|
|
Redistributions in binary form must reproduce the above copyright notice, this list |
| 12 |
|
|
of conditions and the following disclaimer in the documentation and/or other materials |
| 13 |
|
|
provided with the distribution. |
| 14 |
|
|
|
| 15 |
|
|
The name of Robert O'Callahan may not be used to endorse or promote products derived from |
| 16 |
|
|
this software without specific prior written permission. |
| 17 |
|
|
|
| 18 |
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND |
| 19 |
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 20 |
|
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
| 21 |
|
|
THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 22 |
|
|
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 24 |
|
|
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 25 |
|
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 26 |
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
|
|
*/ |
| 28 |
|
|
|
| 29 |
|
|
#include "ttxssh.h" |
| 30 |
|
|
#include "util.h" |
| 31 |
|
|
|
| 32 |
|
|
#include <io.h> |
| 33 |
|
|
#include <fcntl.h> |
| 34 |
|
|
#include <stdlib.h> |
| 35 |
|
|
#include <errno.h> |
| 36 |
|
|
|
| 37 |
|
|
#include "resource.h" |
| 38 |
|
|
#include "keyfiles.h" |
| 39 |
|
|
|
| 40 |
|
|
#define AUTH_START_USER_AUTH_ON_ERROR_END 1 |
| 41 |
|
|
|
| 42 |
|
|
#define MAX_AUTH_CONTROL IDC_SSHUSETIS |
| 43 |
|
|
|
| 44 |
|
|
static void destroy_malloced_string(char FAR * FAR * str) |
| 45 |
|
|
{ |
| 46 |
|
|
if (*str != NULL) { |
| 47 |
|
|
memset(*str, 0, strlen(*str)); |
| 48 |
|
|
free(*str); |
| 49 |
|
|
*str = NULL; |
| 50 |
|
|
} |
| 51 |
|
|
} |
| 52 |
|
|
|
| 53 |
|
|
static int auth_types_to_control_IDs[] = { |
| 54 |
|
|
-1, IDC_SSHUSERHOSTS, IDC_SSHUSERSA, IDC_SSHUSEPASSWORD, |
| 55 |
|
|
IDC_SSHUSERHOSTS, IDC_SSHUSETIS, -1 |
| 56 |
|
|
}; |
| 57 |
|
|
|
| 58 |
|
|
static LRESULT CALLBACK password_wnd_proc(HWND control, UINT msg, |
| 59 |
|
|
WPARAM wParam, LPARAM lParam) |
| 60 |
|
|
{ |
| 61 |
|
|
switch (msg) { |
| 62 |
|
|
case WM_CHAR: |
| 63 |
|
|
if ((GetKeyState(VK_CONTROL) & 0x8000) != 0) { |
| 64 |
|
|
char chars[] = { (char) wParam, 0 }; |
| 65 |
|
|
|
| 66 |
|
|
SendMessage(control, EM_REPLACESEL, (WPARAM) TRUE, |
| 67 |
|
|
(LPARAM) (char FAR *) chars); |
| 68 |
|
|
return 0; |
| 69 |
|
|
} |
| 70 |
|
|
} |
| 71 |
|
|
|
| 72 |
|
|
return CallWindowProc((WNDPROC) GetWindowLong(control, GWL_USERDATA), |
| 73 |
|
|
control, msg, wParam, lParam); |
| 74 |
|
|
} |
| 75 |
|
|
|
| 76 |
|
|
static void init_password_control(HWND dlg) |
| 77 |
|
|
{ |
| 78 |
|
|
HWND passwordControl = GetDlgItem(dlg, IDC_SSHPASSWORD); |
| 79 |
|
|
|
| 80 |
|
|
SetWindowLong(passwordControl, GWL_USERDATA, |
| 81 |
|
|
SetWindowLong(passwordControl, GWL_WNDPROC, |
| 82 |
|
|
(LONG) password_wnd_proc)); |
| 83 |
|
|
|
| 84 |
|
|
SetFocus(passwordControl); |
| 85 |
|
|
} |
| 86 |
|
|
|
| 87 |
|
|
static void set_auth_options_status(HWND dlg, int controlID) |
| 88 |
|
|
{ |
| 89 |
|
|
BOOL RSA_enabled = controlID == IDC_SSHUSERSA; |
| 90 |
|
|
BOOL rhosts_enabled = controlID == IDC_SSHUSERHOSTS; |
| 91 |
|
|
BOOL TIS_enabled = controlID == IDC_SSHUSETIS; |
| 92 |
|
|
int i; |
| 93 |
|
|
|
| 94 |
|
|
CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, controlID); |
| 95 |
|
|
|
| 96 |
|
|
EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORDCAPTION), !TIS_enabled); |
| 97 |
|
|
EnableWindow(GetDlgItem(dlg, IDC_SSHPASSWORD), !TIS_enabled); |
| 98 |
|
|
|
| 99 |
|
|
for (i = IDC_CHOOSERSAFILE; i <= IDC_RSAFILENAME; i++) { |
| 100 |
|
|
EnableWindow(GetDlgItem(dlg, i), RSA_enabled); |
| 101 |
|
|
} |
| 102 |
|
|
|
| 103 |
|
|
for (i = IDC_LOCALUSERNAMELABEL; i <= IDC_HOSTRSAFILENAME; i++) { |
| 104 |
|
|
EnableWindow(GetDlgItem(dlg, i), rhosts_enabled); |
| 105 |
|
|
} |
| 106 |
|
|
} |
| 107 |
|
|
|
| 108 |
|
|
static void init_auth_machine_banner(PTInstVar pvar, HWND dlg) |
| 109 |
|
|
{ |
| 110 |
|
|
char buf[1024] = "Logging in to "; |
| 111 |
|
|
|
| 112 |
|
|
if (strlen(buf) + strlen(SSH_get_host_name(pvar)) < sizeof(buf) - 2) { |
| 113 |
|
|
strcat(buf, SSH_get_host_name(pvar)); |
| 114 |
|
|
} |
| 115 |
|
|
SetDlgItemText(dlg, IDC_SSHAUTHBANNER, buf); |
| 116 |
|
|
} |
| 117 |
|
|
|
| 118 |
|
|
static void update_server_supported_types(PTInstVar pvar, HWND dlg) |
| 119 |
|
|
{ |
| 120 |
|
|
int supported_methods = pvar->auth_state.supported_types; |
| 121 |
|
|
int cur_control = -1; |
| 122 |
|
|
int control; |
| 123 |
|
|
HWND focus = GetFocus(); |
| 124 |
|
|
|
| 125 |
|
|
if (supported_methods == 0) { |
| 126 |
|
|
return; |
| 127 |
|
|
} |
| 128 |
|
|
|
| 129 |
|
|
for (control = IDC_SSHUSEPASSWORD; control <= MAX_AUTH_CONTROL; |
| 130 |
|
|
control++) { |
| 131 |
|
|
BOOL enabled = FALSE; |
| 132 |
|
|
int method; |
| 133 |
|
|
HWND item = GetDlgItem(dlg, control); |
| 134 |
|
|
|
| 135 |
|
|
if (item != NULL) { |
| 136 |
|
|
for (method = 0; method <= SSH_AUTH_MAX; method++) { |
| 137 |
|
|
if (auth_types_to_control_IDs[method] == control |
| 138 |
|
|
&& (supported_methods & (1 << method)) != 0) { |
| 139 |
|
|
enabled = TRUE; |
| 140 |
|
|
} |
| 141 |
|
|
} |
| 142 |
|
|
|
| 143 |
|
|
EnableWindow(item, enabled); |
| 144 |
|
|
|
| 145 |
|
|
if (IsDlgButtonChecked(dlg, control)) { |
| 146 |
|
|
cur_control = control; |
| 147 |
|
|
} |
| 148 |
|
|
} |
| 149 |
|
|
} |
| 150 |
|
|
|
| 151 |
|
|
if (cur_control >= 0) { |
| 152 |
|
|
if (!IsWindowEnabled(GetDlgItem(dlg, cur_control))) { |
| 153 |
|
|
do { |
| 154 |
|
|
cur_control++; |
| 155 |
|
|
if (cur_control > MAX_AUTH_CONTROL) { |
| 156 |
|
|
cur_control = IDC_SSHUSEPASSWORD; |
| 157 |
|
|
} |
| 158 |
|
|
} while (!IsWindowEnabled(GetDlgItem(dlg, cur_control))); |
| 159 |
|
|
|
| 160 |
|
|
set_auth_options_status(dlg, cur_control); |
| 161 |
|
|
|
| 162 |
|
|
if (focus != NULL && !IsWindowEnabled(focus)) { |
| 163 |
|
|
SetFocus(GetDlgItem(dlg, cur_control)); |
| 164 |
|
|
} |
| 165 |
|
|
} |
| 166 |
|
|
} |
| 167 |
|
|
} |
| 168 |
|
|
|
| 169 |
|
|
static void init_auth_dlg(PTInstVar pvar, HWND dlg) |
| 170 |
|
|
{ |
| 171 |
|
|
int default_method = pvar->session_settings.DefaultAuthMethod; |
| 172 |
|
|
|
| 173 |
|
|
init_auth_machine_banner(pvar, dlg); |
| 174 |
|
|
init_password_control(dlg); |
| 175 |
|
|
|
| 176 |
|
|
if (pvar->auth_state.failed_method != SSH_AUTH_NONE) { |
| 177 |
|
|
/* must be retrying a failed attempt */ |
| 178 |
|
|
SetDlgItemText(dlg, IDC_SSHAUTHBANNER2, |
| 179 |
|
|
"Authentication failed. Please retry."); |
| 180 |
|
|
SetWindowText(dlg, "Retrying SSH Authentication"); |
| 181 |
|
|
default_method = pvar->auth_state.failed_method; |
| 182 |
|
|
} |
| 183 |
|
|
|
| 184 |
|
|
set_auth_options_status(dlg, |
| 185 |
|
|
auth_types_to_control_IDs[default_method]); |
| 186 |
|
|
|
| 187 |
|
|
if (default_method == SSH_AUTH_TIS) { |
| 188 |
|
|
/* we disabled the password control, so fix the focus */ |
| 189 |
|
|
SetFocus(GetDlgItem(dlg, IDC_SSHUSETIS)); |
| 190 |
|
|
} |
| 191 |
|
|
|
| 192 |
|
|
if (pvar->auth_state.user != NULL) { |
| 193 |
|
|
SetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->auth_state.user); |
| 194 |
|
|
EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAME), FALSE); |
| 195 |
|
|
EnableWindow(GetDlgItem(dlg, IDC_SSHUSERNAMELABEL), FALSE); |
| 196 |
|
|
} else if (pvar->session_settings.DefaultUserName[0] != 0) { |
| 197 |
|
|
SetDlgItemText(dlg, IDC_SSHUSERNAME, |
| 198 |
|
|
pvar->session_settings.DefaultUserName); |
| 199 |
|
|
} else { |
| 200 |
|
|
SetFocus(GetDlgItem(dlg, IDC_SSHUSERNAME)); |
| 201 |
|
|
} |
| 202 |
|
|
|
| 203 |
|
|
SetDlgItemText(dlg, IDC_RSAFILENAME, |
| 204 |
|
|
pvar->session_settings.DefaultRSAPrivateKeyFile); |
| 205 |
|
|
SetDlgItemText(dlg, IDC_HOSTRSAFILENAME, |
| 206 |
|
|
pvar->session_settings.DefaultRhostsHostPrivateKeyFile); |
| 207 |
|
|
SetDlgItemText(dlg, IDC_LOCALUSERNAME, |
| 208 |
|
|
pvar->session_settings.DefaultRhostsLocalUserName); |
| 209 |
|
|
|
| 210 |
|
|
update_server_supported_types(pvar, dlg); |
| 211 |
|
|
} |
| 212 |
|
|
|
| 213 |
|
|
static char FAR *alloc_control_text(HWND ctl) |
| 214 |
|
|
{ |
| 215 |
|
|
int len = GetWindowTextLength(ctl); |
| 216 |
|
|
char FAR *result = malloc(len + 1); |
| 217 |
|
|
|
| 218 |
|
|
if (result != NULL) { |
| 219 |
|
|
GetWindowText(ctl, result, len + 1); |
| 220 |
|
|
result[len] = 0; |
| 221 |
|
|
} |
| 222 |
|
|
|
| 223 |
|
|
return result; |
| 224 |
|
|
} |
| 225 |
|
|
|
| 226 |
|
|
static int get_key_file_name(HWND parent, char FAR * buf, int bufsize) |
| 227 |
|
|
{ |
| 228 |
|
|
#ifdef TERATERM32 |
| 229 |
|
|
OPENFILENAME params; |
| 230 |
|
|
char fullname_buf[2048] = "identity"; |
| 231 |
|
|
|
| 232 |
|
|
params.lStructSize = sizeof(OPENFILENAME); |
| 233 |
|
|
params.hwndOwner = parent; |
| 234 |
|
|
params.lpstrFilter = NULL; |
| 235 |
|
|
params.lpstrCustomFilter = NULL; |
| 236 |
|
|
params.nFilterIndex = 0; |
| 237 |
|
|
buf[0] = 0; |
| 238 |
|
|
params.lpstrFile = fullname_buf; |
| 239 |
|
|
params.nMaxFile = sizeof(fullname_buf); |
| 240 |
|
|
params.lpstrFileTitle = NULL; |
| 241 |
|
|
params.lpstrInitialDir = NULL; |
| 242 |
|
|
params.lpstrTitle = "Choose a file with the RSA private key"; |
| 243 |
|
|
params.Flags = |
| 244 |
|
|
OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY; |
| 245 |
|
|
params.lpstrDefExt = NULL; |
| 246 |
|
|
|
| 247 |
|
|
if (GetOpenFileName(¶ms) != 0) { |
| 248 |
|
|
copy_teraterm_dir_relative_path(buf, bufsize, fullname_buf); |
| 249 |
|
|
return 1; |
| 250 |
|
|
} else { |
| 251 |
|
|
return 0; |
| 252 |
|
|
} |
| 253 |
|
|
#else |
| 254 |
|
|
return 0; |
| 255 |
|
|
#endif |
| 256 |
|
|
} |
| 257 |
|
|
|
| 258 |
|
|
static void choose_RSA_key_file(HWND dlg) |
| 259 |
|
|
{ |
| 260 |
|
|
char buf[1024]; |
| 261 |
|
|
|
| 262 |
|
|
if (get_key_file_name(dlg, buf, sizeof(buf))) { |
| 263 |
|
|
SetDlgItemText(dlg, IDC_RSAFILENAME, buf); |
| 264 |
|
|
} |
| 265 |
|
|
} |
| 266 |
|
|
|
| 267 |
|
|
static void choose_host_RSA_key_file(HWND dlg) |
| 268 |
|
|
{ |
| 269 |
|
|
char buf[1024]; |
| 270 |
|
|
|
| 271 |
|
|
if (get_key_file_name(dlg, buf, sizeof(buf))) { |
| 272 |
|
|
SetDlgItemText(dlg, IDC_HOSTRSAFILENAME, buf); |
| 273 |
|
|
} |
| 274 |
|
|
} |
| 275 |
|
|
|
| 276 |
|
|
static BOOL end_auth_dlg(PTInstVar pvar, HWND dlg) |
| 277 |
|
|
{ |
| 278 |
|
|
int method = SSH_AUTH_PASSWORD; |
| 279 |
|
|
char FAR *password = |
| 280 |
|
|
alloc_control_text(GetDlgItem(dlg, IDC_SSHPASSWORD)); |
| 281 |
|
|
CRYPTKeyPair FAR *key_pair = NULL; |
| 282 |
|
|
|
| 283 |
|
|
if (IsDlgButtonChecked(dlg, IDC_SSHUSERSA)) { |
| 284 |
|
|
method = SSH_AUTH_RSA; |
| 285 |
|
|
} else if (IsDlgButtonChecked(dlg, IDC_SSHUSERHOSTS)) { |
| 286 |
|
|
if (GetWindowTextLength(GetDlgItem(dlg, IDC_HOSTRSAFILENAME)) > 0) { |
| 287 |
|
|
method = SSH_AUTH_RHOSTS_RSA; |
| 288 |
|
|
} else { |
| 289 |
|
|
method = SSH_AUTH_RHOSTS; |
| 290 |
|
|
} |
| 291 |
|
|
} else if (IsDlgButtonChecked(dlg, IDC_SSHUSETIS)) { |
| 292 |
|
|
method = SSH_AUTH_TIS; |
| 293 |
|
|
} |
| 294 |
|
|
|
| 295 |
|
|
if (method == SSH_AUTH_RSA || method == SSH_AUTH_RHOSTS_RSA) { |
| 296 |
|
|
char buf[2048]; |
| 297 |
|
|
int file_ctl_ID = |
| 298 |
|
|
method == SSH_AUTH_RSA ? IDC_RSAFILENAME : IDC_HOSTRSAFILENAME; |
| 299 |
|
|
|
| 300 |
|
|
buf[0] = 0; |
| 301 |
|
|
GetDlgItemText(dlg, file_ctl_ID, buf, sizeof(buf)); |
| 302 |
|
|
if (buf[0] == 0) { |
| 303 |
|
|
notify_nonfatal_error(pvar, |
| 304 |
|
|
"You must specify a file containing the RSA private key."); |
| 305 |
|
|
SetFocus(GetDlgItem(dlg, file_ctl_ID)); |
| 306 |
|
|
destroy_malloced_string(&password); |
| 307 |
|
|
return FALSE; |
| 308 |
|
|
} else { |
| 309 |
|
|
BOOL invalid_passphrase = FALSE; |
| 310 |
|
|
|
| 311 |
|
|
key_pair = KEYFILES_read_private_key(pvar, buf, password, |
| 312 |
|
|
&invalid_passphrase, |
| 313 |
|
|
FALSE); |
| 314 |
|
|
|
| 315 |
|
|
if (key_pair == NULL) { |
| 316 |
|
|
if (invalid_passphrase) { |
| 317 |
|
|
HWND passwordCtl = GetDlgItem(dlg, IDC_SSHPASSWORD); |
| 318 |
|
|
|
| 319 |
|
|
SetFocus(passwordCtl); |
| 320 |
|
|
SendMessage(passwordCtl, EM_SETSEL, 0, -1); |
| 321 |
|
|
} else { |
| 322 |
|
|
SetFocus(GetDlgItem(dlg, file_ctl_ID)); |
| 323 |
|
|
} |
| 324 |
|
|
destroy_malloced_string(&password); |
| 325 |
|
|
return FALSE; |
| 326 |
|
|
} |
| 327 |
|
|
} |
| 328 |
|
|
} |
| 329 |
|
|
|
| 330 |
|
|
/* from here on, we cannot fail, so just munge cur_cred in place */ |
| 331 |
|
|
pvar->auth_state.cur_cred.method = method; |
| 332 |
|
|
pvar->auth_state.cur_cred.key_pair = key_pair; |
| 333 |
|
|
/* we can't change the user name once it's set. It may already have |
| 334 |
|
|
been sent to the server, and it can only be sent once. */ |
| 335 |
|
|
if (pvar->auth_state.user == NULL) { |
| 336 |
|
|
pvar->auth_state.user = |
| 337 |
|
|
alloc_control_text(GetDlgItem(dlg, IDC_SSHUSERNAME)); |
| 338 |
|
|
} |
| 339 |
|
|
if (method == SSH_AUTH_PASSWORD) { |
| 340 |
|
|
pvar->auth_state.cur_cred.password = password; |
| 341 |
|
|
} else { |
| 342 |
|
|
destroy_malloced_string(&password); |
| 343 |
|
|
} |
| 344 |
|
|
if (method == SSH_AUTH_RHOSTS || method == SSH_AUTH_RHOSTS_RSA) { |
| 345 |
|
|
if (pvar->session_settings.DefaultAuthMethod != SSH_AUTH_RHOSTS) { |
| 346 |
|
|
notify_nonfatal_error(pvar, |
| 347 |
|
|
"Rhosts authentication will probably fail because it was not " |
| 348 |
|
|
"the default authentication method.\n" |
| 349 |
|
|
"To use Rhosts authentication " |
| 350 |
|
|
"in TTSSH, you need to set it to be the default by restarting\n" |
| 351 |
|
|
"TTSSH and selecting \"SSH Authentication...\" from the Setup menu" |
| 352 |
|
|
"before connecting."); |
| 353 |
|
|
} |
| 354 |
|
|
|
| 355 |
|
|
pvar->auth_state.cur_cred.rhosts_client_user = |
| 356 |
|
|
alloc_control_text(GetDlgItem(dlg, IDC_LOCALUSERNAME)); |
| 357 |
|
|
} |
| 358 |
|
|
pvar->auth_state.auth_dialog = NULL; |
| 359 |
|
|
|
| 360 |
|
|
GetDlgItemText(dlg, IDC_RSAFILENAME, |
| 361 |
|
|
pvar->session_settings.DefaultRSAPrivateKeyFile, |
| 362 |
|
|
sizeof(pvar->session_settings. |
| 363 |
|
|
DefaultRSAPrivateKeyFile)); |
| 364 |
|
|
GetDlgItemText(dlg, IDC_HOSTRSAFILENAME, |
| 365 |
|
|
pvar->session_settings.DefaultRhostsHostPrivateKeyFile, |
| 366 |
|
|
sizeof(pvar->session_settings. |
| 367 |
|
|
DefaultRhostsHostPrivateKeyFile)); |
| 368 |
|
|
GetDlgItemText(dlg, IDC_LOCALUSERNAME, |
| 369 |
|
|
pvar->session_settings.DefaultRhostsLocalUserName, |
| 370 |
|
|
sizeof(pvar->session_settings. |
| 371 |
|
|
DefaultRhostsLocalUserName)); |
| 372 |
|
|
|
| 373 |
|
|
if (SSHv1(pvar)) { |
| 374 |
|
|
SSH_notify_user_name(pvar); |
| 375 |
|
|
SSH_notify_cred(pvar); |
| 376 |
|
|
} else { |
| 377 |
|
|
// for SSH2(yutaka) |
| 378 |
|
|
do_SSH2_userauth(pvar); |
| 379 |
|
|
} |
| 380 |
|
|
|
| 381 |
|
|
EndDialog(dlg, 1); |
| 382 |
|
|
return TRUE; |
| 383 |
|
|
} |
| 384 |
|
|
|
| 385 |
|
|
static BOOL CALLBACK auth_dlg_proc(HWND dlg, UINT msg, WPARAM wParam, |
| 386 |
|
|
LPARAM lParam) |
| 387 |
|
|
{ |
| 388 |
|
|
PTInstVar pvar; |
| 389 |
|
|
|
| 390 |
|
|
switch (msg) { |
| 391 |
|
|
case WM_INITDIALOG: |
| 392 |
|
|
pvar = (PTInstVar) lParam; |
| 393 |
|
|
pvar->auth_state.auth_dialog = dlg; |
| 394 |
|
|
SetWindowLong(dlg, DWL_USER, lParam); |
| 395 |
|
|
|
| 396 |
|
|
init_auth_dlg(pvar, dlg); |
| 397 |
|
|
return FALSE; /* because we set the focus */ |
| 398 |
|
|
|
| 399 |
|
|
case WM_COMMAND: |
| 400 |
|
|
pvar = (PTInstVar) GetWindowLong(dlg, DWL_USER); |
| 401 |
|
|
|
| 402 |
|
|
switch (LOWORD(wParam)) { |
| 403 |
|
|
case IDOK: |
| 404 |
|
|
return end_auth_dlg(pvar, dlg); |
| 405 |
|
|
|
| 406 |
|
|
case IDCANCEL: /* kill the connection */ |
| 407 |
|
|
pvar->auth_state.auth_dialog = NULL; |
| 408 |
|
|
notify_closed_connection(pvar); |
| 409 |
|
|
EndDialog(dlg, 0); |
| 410 |
|
|
return TRUE; |
| 411 |
|
|
|
| 412 |
|
|
case IDC_SSHUSEPASSWORD: |
| 413 |
|
|
case IDC_SSHUSERSA: |
| 414 |
|
|
case IDC_SSHUSERHOSTS: |
| 415 |
|
|
case IDC_SSHUSETIS: |
| 416 |
|
|
set_auth_options_status(dlg, LOWORD(wParam)); |
| 417 |
|
|
return TRUE; |
| 418 |
|
|
|
| 419 |
|
|
case IDC_CHOOSERSAFILE: |
| 420 |
|
|
choose_RSA_key_file(dlg); |
| 421 |
|
|
return TRUE; |
| 422 |
|
|
|
| 423 |
|
|
case IDC_CHOOSEHOSTRSAFILE: |
| 424 |
|
|
choose_host_RSA_key_file(dlg); |
| 425 |
|
|
return TRUE; |
| 426 |
|
|
|
| 427 |
|
|
default: |
| 428 |
|
|
return FALSE; |
| 429 |
|
|
} |
| 430 |
|
|
|
| 431 |
|
|
default: |
| 432 |
|
|
return FALSE; |
| 433 |
|
|
} |
| 434 |
|
|
} |
| 435 |
|
|
|
| 436 |
|
|
char FAR *AUTH_get_user_name(PTInstVar pvar) |
| 437 |
|
|
{ |
| 438 |
|
|
return pvar->auth_state.user; |
| 439 |
|
|
} |
| 440 |
|
|
|
| 441 |
|
|
int AUTH_set_supported_auth_types(PTInstVar pvar, int types) |
| 442 |
|
|
{ |
| 443 |
|
|
char buf[1024]; |
| 444 |
|
|
|
| 445 |
|
|
_snprintf(buf, sizeof(buf), |
| 446 |
|
|
"Server reports supported authentication method mask = %d", |
| 447 |
|
|
types); |
| 448 |
|
|
buf[sizeof(buf) - 1] = 0; |
| 449 |
|
|
notify_verbose_message(pvar, buf, LOG_LEVEL_VERBOSE); |
| 450 |
|
|
|
| 451 |
|
|
if (SSHv1(pvar)) { |
| 452 |
|
|
types &= (1 << SSH_AUTH_PASSWORD) | (1 << SSH_AUTH_RSA) |
| 453 |
|
|
| (1 << SSH_AUTH_RHOSTS_RSA) | (1 << SSH_AUTH_RHOSTS) |
| 454 |
|
|
| (1 << SSH_AUTH_TIS); |
| 455 |
|
|
} else { |
| 456 |
|
|
// for SSH2(yutaka) |
| 457 |
|
|
types &= (1 << SSH_AUTH_PASSWORD); |
| 458 |
|
|
// types &= (1 << SSH_AUTH_PASSWORD) | (1 << SSH_AUTH_RSA) |
| 459 |
|
|
// | (1 << SSH_AUTH_DSA); |
| 460 |
|
|
} |
| 461 |
|
|
pvar->auth_state.supported_types = types; |
| 462 |
|
|
|
| 463 |
|
|
if (types == 0) { |
| 464 |
|
|
notify_fatal_error(pvar, |
| 465 |
|
|
"Server does not support any of the authentication options\n" |
| 466 |
|
|
"provided by TTSSH. This connection will now close."); |
| 467 |
|
|
return 0; |
| 468 |
|
|
} else { |
| 469 |
|
|
if (pvar->auth_state.auth_dialog != NULL) { |
| 470 |
|
|
update_server_supported_types(pvar, |
| 471 |
|
|
pvar->auth_state.auth_dialog); |
| 472 |
|
|
} |
| 473 |
|
|
|
| 474 |
|
|
return 1; |
| 475 |
|
|
} |
| 476 |
|
|
} |
| 477 |
|
|
|
| 478 |
|
|
static void start_user_auth(PTInstVar pvar) |
| 479 |
|
|
{ |
| 480 |
|
|
PostMessage(pvar->NotificationWindow, WM_COMMAND, (WPARAM) ID_SSHAUTH, |
| 481 |
|
|
(LPARAM) NULL); |
| 482 |
|
|
pvar->auth_state.cur_cred.method = SSH_AUTH_NONE; |
| 483 |
|
|
} |
| 484 |
|
|
|
| 485 |
|
|
static void try_default_auth(PTInstVar pvar) |
| 486 |
|
|
{ |
| 487 |
|
|
if (pvar->session_settings.TryDefaultAuth) { |
| 488 |
|
|
switch (pvar->session_settings.DefaultAuthMethod) { |
| 489 |
|
|
case SSH_AUTH_RSA:{ |
| 490 |
|
|
BOOL invalid_passphrase; |
| 491 |
|
|
char password[] = ""; |
| 492 |
|
|
|
| 493 |
|
|
pvar->auth_state.cur_cred.key_pair |
| 494 |
|
|
= |
| 495 |
|
|
KEYFILES_read_private_key(pvar, |
| 496 |
|
|
pvar->session_settings. |
| 497 |
|
|
DefaultRSAPrivateKeyFile, |
| 498 |
|
|
password, |
| 499 |
|
|
&invalid_passphrase, TRUE); |
| 500 |
|
|
if (pvar->auth_state.cur_cred.key_pair == NULL) { |
| 501 |
|
|
return; |
| 502 |
|
|
} else { |
| 503 |
|
|
pvar->auth_state.cur_cred.method = SSH_AUTH_RSA; |
| 504 |
|
|
} |
| 505 |
|
|
break; |
| 506 |
|
|
} |
| 507 |
|
|
|
| 508 |
|
|
case SSH_AUTH_RHOSTS: |
| 509 |
|
|
if (pvar->session_settings. |
| 510 |
|
|
DefaultRhostsHostPrivateKeyFile[0] != 0) { |
| 511 |
|
|
BOOL invalid_passphrase; |
| 512 |
|
|
char password[] = ""; |
| 513 |
|
|
|
| 514 |
|
|
pvar->auth_state.cur_cred.key_pair |
| 515 |
|
|
= |
| 516 |
|
|
KEYFILES_read_private_key(pvar, |
| 517 |
|
|
pvar->session_settings. |
| 518 |
|
|
DefaultRhostsHostPrivateKeyFile, |
| 519 |
|
|
password, |
| 520 |
|
|
&invalid_passphrase, TRUE); |
| 521 |
|
|
if (pvar->auth_state.cur_cred.key_pair == NULL) { |
| 522 |
|
|
return; |
| 523 |
|
|
} else { |
| 524 |
|
|
pvar->auth_state.cur_cred.method = SSH_AUTH_RHOSTS_RSA; |
| 525 |
|
|
} |
| 526 |
|
|
} else { |
| 527 |
|
|
pvar->auth_state.cur_cred.method = SSH_AUTH_RHOSTS; |
| 528 |
|
|
} |
| 529 |
|
|
|
| 530 |
|
|
pvar->auth_state.cur_cred.rhosts_client_user = |
| 531 |
|
|
_strdup(pvar->session_settings.DefaultRhostsLocalUserName); |
| 532 |
|
|
break; |
| 533 |
|
|
|
| 534 |
|
|
case SSH_AUTH_PASSWORD: |
| 535 |
|
|
pvar->auth_state.cur_cred.password = _strdup(""); |
| 536 |
|
|
pvar->auth_state.cur_cred.method = SSH_AUTH_PASSWORD; |
| 537 |
|
|
break; |
| 538 |
|
|
|
| 539 |
|
|
case SSH_AUTH_TIS: |
| 540 |
|
|
default: |
| 541 |
|
|
return; |
| 542 |
|
|
} |
| 543 |
|
|
|
| 544 |
|
|
pvar->auth_state.user = |
| 545 |
|
|
_strdup(pvar->session_settings.DefaultUserName); |
| 546 |
|
|
} |
| 547 |
|
|
} |
| 548 |
|
|
|
| 549 |
|
|
void AUTH_notify_end_error(PTInstVar pvar) |
| 550 |
|
|
{ |
| 551 |
|
|
if ((pvar->auth_state.flags & AUTH_START_USER_AUTH_ON_ERROR_END) != 0) { |
| 552 |
|
|
start_user_auth(pvar); |
| 553 |
|
|
pvar->auth_state.flags &= ~AUTH_START_USER_AUTH_ON_ERROR_END; |
| 554 |
|
|
} |
| 555 |
|
|
} |
| 556 |
|
|
|
| 557 |
|
|
void AUTH_advance_to_next_cred(PTInstVar pvar) |
| 558 |
|
|
{ |
| 559 |
|
|
pvar->auth_state.failed_method = pvar->auth_state.cur_cred.method; |
| 560 |
|
|
|
| 561 |
|
|
if (pvar->auth_state.cur_cred.method == SSH_AUTH_NONE) { |
| 562 |
|
|
try_default_auth(pvar); |
| 563 |
|
|
|
| 564 |
|
|
if (pvar->auth_state.cur_cred.method == SSH_AUTH_NONE) { |
| 565 |
|
|
if (pvar->err_msg != NULL) { |
| 566 |
|
|
pvar->auth_state.flags |= |
| 567 |
|
|
AUTH_START_USER_AUTH_ON_ERROR_END; |
| 568 |
|
|
} else { |
| 569 |
|
|
start_user_auth(pvar); |
| 570 |
|
|
} |
| 571 |
|
|
} |
| 572 |
|
|
} else { |
| 573 |
|
|
start_user_auth(pvar); |
| 574 |
|
|
} |
| 575 |
|
|
} |
| 576 |
|
|
|
| 577 |
|
|
static void init_TIS_dlg(PTInstVar pvar, HWND dlg) |
| 578 |
|
|
{ |
| 579 |
|
|
init_auth_machine_banner(pvar, dlg); |
| 580 |
|
|
init_password_control(dlg); |
| 581 |
|
|
|
| 582 |
|
|
if (pvar->auth_state.TIS_prompt != NULL) { |
| 583 |
|
|
if (strlen(pvar->auth_state.TIS_prompt) > 10000) { |
| 584 |
|
|
pvar->auth_state.TIS_prompt[10000] = 0; |
| 585 |
|
|
} |
| 586 |
|
|
SetDlgItemText(dlg, IDC_SSHAUTHBANNER2, |
| 587 |
|
|
pvar->auth_state.TIS_prompt); |
| 588 |
|
|
destroy_malloced_string(&pvar->auth_state.TIS_prompt); |
| 589 |
|
|
} |
| 590 |
|
|
} |
| 591 |
|
|
|
| 592 |
|
|
static BOOL end_TIS_dlg(PTInstVar pvar, HWND dlg) |
| 593 |
|
|
{ |
| 594 |
|
|
char FAR *password = |
| 595 |
|
|
alloc_control_text(GetDlgItem(dlg, IDC_SSHPASSWORD)); |
| 596 |
|
|
|
| 597 |
|
|
pvar->auth_state.cur_cred.method = SSH_AUTH_TIS; |
| 598 |
|
|
pvar->auth_state.cur_cred.password = password; |
| 599 |
|
|
pvar->auth_state.auth_dialog = NULL; |
| 600 |
|
|
|
| 601 |
|
|
SSH_notify_cred(pvar); |
| 602 |
|
|
|
| 603 |
|
|
EndDialog(dlg, 1); |
| 604 |
|
|
return TRUE; |
| 605 |
|
|
} |
| 606 |
|
|
|
| 607 |
|
|
static BOOL CALLBACK TIS_dlg_proc(HWND dlg, UINT msg, WPARAM wParam, |
| 608 |
|
|
LPARAM lParam) |
| 609 |
|
|
{ |
| 610 |
|
|
PTInstVar pvar; |
| 611 |
|
|
|
| 612 |
|
|
switch (msg) { |
| 613 |
|
|
case WM_INITDIALOG: |
| 614 |
|
|
pvar = (PTInstVar) lParam; |
| 615 |
|
|
pvar->auth_state.auth_dialog = dlg; |
| 616 |
|
|
SetWindowLong(dlg, DWL_USER, lParam); |
| 617 |
|
|
|
| 618 |
|
|
init_TIS_dlg(pvar, dlg); |
| 619 |
|
|
return FALSE; /* because we set the focus */ |
| 620 |
|
|
|
| 621 |
|
|
case WM_COMMAND: |
| 622 |
|
|
pvar = (PTInstVar) GetWindowLong(dlg, DWL_USER); |
| 623 |
|
|
|
| 624 |
|
|
switch (LOWORD(wParam)) { |
| 625 |
|
|
case IDOK: |
| 626 |
|
|
return end_TIS_dlg(pvar, dlg); |
| 627 |
|
|
|
| 628 |
|
|
case IDCANCEL: /* kill the connection */ |
| 629 |
|
|
pvar->auth_state.auth_dialog = NULL; |
| 630 |
|
|
notify_closed_connection(pvar); |
| 631 |
|
|
EndDialog(dlg, 0); |
| 632 |
|
|
return TRUE; |
| 633 |
|
|
|
| 634 |
|
|
default: |
| 635 |
|
|
return FALSE; |
| 636 |
|
|
} |
| 637 |
|
|
|
| 638 |
|
|
default: |
| 639 |
|
|
return FALSE; |
| 640 |
|
|
} |
| 641 |
|
|
} |
| 642 |
|
|
|
| 643 |
|
|
void AUTH_do_cred_dialog(PTInstVar pvar) |
| 644 |
|
|
{ |
| 645 |
|
|
if (pvar->auth_state.auth_dialog == NULL) { |
| 646 |
|
|
HWND cur_active = GetActiveWindow(); |
| 647 |
|
|
DLGPROC dlg_proc; |
| 648 |
|
|
LPCTSTR dialog_template; |
| 649 |
|
|
|
| 650 |
|
|
switch (pvar->auth_state.mode) { |
| 651 |
|
|
case TIS_AUTH_MODE: |
| 652 |
|
|
dialog_template = MAKEINTRESOURCE(IDD_SSHTISAUTH); |
| 653 |
|
|
dlg_proc = TIS_dlg_proc; |
| 654 |
|
|
break; |
| 655 |
|
|
case GENERIC_AUTH_MODE: |
| 656 |
|
|
default: |
| 657 |
|
|
dialog_template = MAKEINTRESOURCE(IDD_SSHAUTH); |
| 658 |
|
|
dlg_proc = auth_dlg_proc; |
| 659 |
|
|
} |
| 660 |
|
|
|
| 661 |
|
|
if (!DialogBoxParam(hInst, dialog_template, |
| 662 |
|
|
cur_active != |
| 663 |
|
|
NULL ? cur_active : pvar->NotificationWindow, |
| 664 |
|
|
dlg_proc, (LPARAM) pvar) == -1) { |
| 665 |
|
|
notify_fatal_error(pvar, |
| 666 |
|
|
"Unable to display authentication dialog box.\n" |
| 667 |
|
|
"Connection terminated."); |
| 668 |
|
|
} |
| 669 |
|
|
} |
| 670 |
|
|
} |
| 671 |
|
|
|
| 672 |
|
|
static void init_default_auth_dlg(PTInstVar pvar, HWND dlg) |
| 673 |
|
|
{ |
| 674 |
|
|
switch (pvar->settings.DefaultAuthMethod) { |
| 675 |
|
|
case SSH_AUTH_RSA: |
| 676 |
|
|
CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, |
| 677 |
|
|
IDC_SSHUSERSA); |
| 678 |
|
|
break; |
| 679 |
|
|
case SSH_AUTH_RHOSTS: |
| 680 |
|
|
case SSH_AUTH_RHOSTS_RSA: |
| 681 |
|
|
CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, |
| 682 |
|
|
IDC_SSHUSERHOSTS); |
| 683 |
|
|
break; |
| 684 |
|
|
case SSH_AUTH_TIS: |
| 685 |
|
|
CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, |
| 686 |
|
|
IDC_SSHUSETIS); |
| 687 |
|
|
break; |
| 688 |
|
|
case SSH_AUTH_PASSWORD: |
| 689 |
|
|
default: |
| 690 |
|
|
CheckRadioButton(dlg, IDC_SSHUSEPASSWORD, MAX_AUTH_CONTROL, |
| 691 |
|
|
IDC_SSHUSEPASSWORD); |
| 692 |
|
|
} |
| 693 |
|
|
|
| 694 |
|
|
SetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->settings.DefaultUserName); |
| 695 |
|
|
SetDlgItemText(dlg, IDC_RSAFILENAME, |
| 696 |
|
|
pvar->settings.DefaultRSAPrivateKeyFile); |
| 697 |
|
|
SetDlgItemText(dlg, IDC_HOSTRSAFILENAME, |
| 698 |
|
|
pvar->settings.DefaultRhostsHostPrivateKeyFile); |
| 699 |
|
|
SetDlgItemText(dlg, IDC_LOCALUSERNAME, |
| 700 |
|
|
pvar->settings.DefaultRhostsLocalUserName); |
| 701 |
|
|
} |
| 702 |
|
|
|
| 703 |
|
|
static BOOL end_default_auth_dlg(PTInstVar pvar, HWND dlg) |
| 704 |
|
|
{ |
| 705 |
|
|
if (IsDlgButtonChecked(dlg, IDC_SSHUSERSA)) { |
| 706 |
|
|
pvar->settings.DefaultAuthMethod = SSH_AUTH_RSA; |
| 707 |
|
|
} else if (IsDlgButtonChecked(dlg, IDC_SSHUSERHOSTS)) { |
| 708 |
|
|
if (GetWindowTextLength(GetDlgItem(dlg, IDC_HOSTRSAFILENAME)) > 0) { |
| 709 |
|
|
pvar->settings.DefaultAuthMethod = SSH_AUTH_RHOSTS_RSA; |
| 710 |
|
|
} else { |
| 711 |
|
|
pvar->settings.DefaultAuthMethod = SSH_AUTH_RHOSTS; |
| 712 |
|
|
} |
| 713 |
|
|
} else if (IsDlgButtonChecked(dlg, IDC_SSHUSETIS)) { |
| 714 |
|
|
pvar->settings.DefaultAuthMethod = SSH_AUTH_TIS; |
| 715 |
|
|
} else { |
| 716 |
|
|
pvar->settings.DefaultAuthMethod = SSH_AUTH_PASSWORD; |
| 717 |
|
|
} |
| 718 |
|
|
|
| 719 |
|
|
GetDlgItemText(dlg, IDC_SSHUSERNAME, pvar->settings.DefaultUserName, |
| 720 |
|
|
sizeof(pvar->settings.DefaultUserName)); |
| 721 |
|
|
GetDlgItemText(dlg, IDC_RSAFILENAME, |
| 722 |
|
|
pvar->settings.DefaultRSAPrivateKeyFile, |
| 723 |
|
|
sizeof(pvar->settings.DefaultRSAPrivateKeyFile)); |
| 724 |
|
|
GetDlgItemText(dlg, IDC_HOSTRSAFILENAME, |
| 725 |
|
|
pvar->settings.DefaultRhostsHostPrivateKeyFile, |
| 726 |
|
|
sizeof(pvar->settings.DefaultRhostsHostPrivateKeyFile)); |
| 727 |
|
|
GetDlgItemText(dlg, IDC_LOCALUSERNAME, |
| 728 |
|
|
pvar->settings.DefaultRhostsLocalUserName, |
| 729 |
|
|
sizeof(pvar->settings.DefaultRhostsLocalUserName)); |
| 730 |
|
|
|
| 731 |
|
|
EndDialog(dlg, 1); |
| 732 |
|
|
return TRUE; |
| 733 |
|
|
} |
| 734 |
|
|
|
| 735 |
|
|
static BOOL CALLBACK default_auth_dlg_proc(HWND dlg, UINT msg, |
| 736 |
|
|
WPARAM wParam, LPARAM lParam) |
| 737 |
|
|
{ |
| 738 |
|
|
PTInstVar pvar; |
| 739 |
|
|
|
| 740 |
|
|
switch (msg) { |
| 741 |
|
|
case WM_INITDIALOG: |
| 742 |
|
|
pvar = (PTInstVar) lParam; |
| 743 |
|
|
SetWindowLong(dlg, DWL_USER, lParam); |
| 744 |
|
|
|
| 745 |
|
|
init_default_auth_dlg(pvar, dlg); |
| 746 |
|
|
return TRUE; /* because we do not set the focus */ |
| 747 |
|
|
|
| 748 |
|
|
case WM_COMMAND: |
| 749 |
|
|
pvar = (PTInstVar) GetWindowLong(dlg, DWL_USER); |
| 750 |
|
|
|
| 751 |
|
|
switch (LOWORD(wParam)) { |
| 752 |
|
|
case IDOK: |
| 753 |
|
|
return end_default_auth_dlg(pvar, dlg); |
| 754 |
|
|
|
| 755 |
|
|
case IDCANCEL: |
| 756 |
|
|
EndDialog(dlg, 0); |
| 757 |
|
|
return TRUE; |
| 758 |
|
|
|
| 759 |
|
|
case IDC_CHOOSERSAFILE: |
| 760 |
|
|
choose_RSA_key_file(dlg); |
| 761 |
|
|
return TRUE; |
| 762 |
|
|
|
| 763 |
|
|
case IDC_CHOOSEHOSTRSAFILE: |
| 764 |
|
|
choose_host_RSA_key_file(dlg); |
| 765 |
|
|
return TRUE; |
| 766 |
|
|
|
| 767 |
|
|
default: |
| 768 |
|
|
return FALSE; |
| 769 |
|
|
} |
| 770 |
|
|
|
| 771 |
|
|
default: |
| 772 |
|
|
return FALSE; |
| 773 |
|
|
} |
| 774 |
|
|
} |
| 775 |
|
|
|
| 776 |
|
|
void AUTH_init(PTInstVar pvar) |
| 777 |
|
|
{ |
| 778 |
|
|
pvar->auth_state.failed_method = SSH_AUTH_NONE; |
| 779 |
|
|
pvar->auth_state.auth_dialog = NULL; |
| 780 |
|
|
pvar->auth_state.user = NULL; |
| 781 |
|
|
pvar->auth_state.flags = 0; |
| 782 |
|
|
pvar->auth_state.TIS_prompt = NULL; |
| 783 |
|
|
pvar->auth_state.supported_types = 0; |
| 784 |
|
|
pvar->auth_state.cur_cred.method = SSH_AUTH_NONE; |
| 785 |
|
|
pvar->auth_state.cur_cred.password = NULL; |
| 786 |
|
|
pvar->auth_state.cur_cred.rhosts_client_user = NULL; |
| 787 |
|
|
pvar->auth_state.cur_cred.key_pair = NULL; |
| 788 |
|
|
AUTH_set_generic_mode(pvar); |
| 789 |
|
|
} |
| 790 |
|
|
|
| 791 |
|
|
void AUTH_set_generic_mode(PTInstVar pvar) |
| 792 |
|
|
{ |
| 793 |
|
|
pvar->auth_state.mode = GENERIC_AUTH_MODE; |
| 794 |
|
|
destroy_malloced_string(&pvar->auth_state.TIS_prompt); |
| 795 |
|
|
} |
| 796 |
|
|
|
| 797 |
|
|
void AUTH_set_TIS_mode(PTInstVar pvar, char FAR * prompt, int len) |
| 798 |
|
|
{ |
| 799 |
|
|
if (pvar->auth_state.cur_cred.method == SSH_AUTH_TIS) { |
| 800 |
|
|
pvar->auth_state.mode = TIS_AUTH_MODE; |
| 801 |
|
|
|
| 802 |
|
|
destroy_malloced_string(&pvar->auth_state.TIS_prompt); |
| 803 |
|
|
pvar->auth_state.TIS_prompt = malloc(len + 1); |
| 804 |
|
|
memcpy(pvar->auth_state.TIS_prompt, prompt, len); |
| 805 |
|
|
pvar->auth_state.TIS_prompt[len] = 0; |
| 806 |
|
|
} else { |
| 807 |
|
|
AUTH_set_generic_mode(pvar); |
| 808 |
|
|
} |
| 809 |
|
|
} |
| 810 |
|
|
|
| 811 |
|
|
void AUTH_do_default_cred_dialog(PTInstVar pvar) |
| 812 |
|
|
{ |
| 813 |
|
|
HWND cur_active = GetActiveWindow(); |
| 814 |
|
|
|
| 815 |
|
|
if (DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SSHAUTHSETUP), |
| 816 |
|
|
cur_active != |
| 817 |
|
|
NULL ? cur_active : pvar->NotificationWindow, |
| 818 |
|
|
default_auth_dlg_proc, (LPARAM) pvar) == -1) { |
| 819 |
|
|
notify_nonfatal_error(pvar, |
| 820 |
|
|
"Unable to display authentication setup dialog box."); |
| 821 |
|
|
} |
| 822 |
|
|
} |
| 823 |
|
|
|
| 824 |
|
|
void AUTH_destroy_cur_cred(PTInstVar pvar) |
| 825 |
|
|
{ |
| 826 |
|
|
destroy_malloced_string(&pvar->auth_state.cur_cred.password); |
| 827 |
|
|
destroy_malloced_string(&pvar->auth_state.cur_cred.rhosts_client_user); |
| 828 |
|
|
if (pvar->auth_state.cur_cred.key_pair != NULL) { |
| 829 |
|
|
CRYPT_free_key_pair(pvar->auth_state.cur_cred.key_pair); |
| 830 |
|
|
pvar->auth_state.cur_cred.key_pair = NULL; |
| 831 |
|
|
} |
| 832 |
|
|
} |
| 833 |
|
|
|
| 834 |
|
|
static char FAR *get_auth_method_name(SSHAuthMethod auth) |
| 835 |
|
|
{ |
| 836 |
|
|
switch (auth) { |
| 837 |
|
|
case SSH_AUTH_PASSWORD: |
| 838 |
|
|
return "password"; |
| 839 |
|
|
case SSH_AUTH_RSA: |
| 840 |
|
|
return "RSA"; |
| 841 |
|
|
case SSH_AUTH_RHOSTS: |
| 842 |
|
|
return "rhosts"; |
| 843 |
|
|
case SSH_AUTH_RHOSTS_RSA: |
| 844 |
|
|
return "rhosts with RSA"; |
| 845 |
|
|
case SSH_AUTH_TIS: |
| 846 |
|
|
return "challenge/response (TIS)"; |
| 847 |
|
|
default: |
| 848 |
|
|
return "unknown method"; |
| 849 |
|
|
} |
| 850 |
|
|
} |
| 851 |
|
|
|
| 852 |
|
|
void AUTH_get_auth_info(PTInstVar pvar, char FAR * dest, int len) |
| 853 |
|
|
{ |
| 854 |
|
|
if (pvar->auth_state.user == NULL) { |
| 855 |
|
|
strncpy(dest, "None", len); |
| 856 |
|
|
} else if (pvar->auth_state.cur_cred.method != SSH_AUTH_NONE) { |
| 857 |
|
|
_snprintf(dest, len, "User '%s', using %s", pvar->auth_state.user, |
| 858 |
|
|
get_auth_method_name(pvar->auth_state.cur_cred.method)); |
| 859 |
|
|
} else { |
| 860 |
|
|
_snprintf(dest, len, "User '%s', using %s", pvar->auth_state.user, |
| 861 |
|
|
get_auth_method_name(pvar->auth_state.failed_method)); |
| 862 |
|
|
} |
| 863 |
|
|
|
| 864 |
|
|
dest[len - 1] = 0; |
| 865 |
|
|
} |
| 866 |
|
|
|
| 867 |
|
|
void AUTH_notify_disconnecting(PTInstVar pvar) |
| 868 |
|
|
{ |
| 869 |
|
|
if (pvar->auth_state.auth_dialog != NULL) { |
| 870 |
|
|
PostMessage(pvar->auth_state.auth_dialog, WM_COMMAND, IDCANCEL, 0); |
| 871 |
|
|
/* the main window might not go away if it's not enabled. (see vtwin.cpp) */ |
| 872 |
|
|
EnableWindow(pvar->NotificationWindow, TRUE); |
| 873 |
|
|
} |
| 874 |
|
|
} |
| 875 |
|
|
|
| 876 |
|
|
void AUTH_end(PTInstVar pvar) |
| 877 |
|
|
{ |
| 878 |
|
|
destroy_malloced_string(&pvar->auth_state.user); |
| 879 |
|
|
destroy_malloced_string(&pvar->auth_state.TIS_prompt); |
| 880 |
|
|
|
| 881 |
|
|
AUTH_destroy_cur_cred(pvar); |
| 882 |
|
|
} |