1
0
mirror of https://github.com/winscp/winscp.git synced 2026-10-24 02:28:55 +03:00

More meaningful error message when credentials are missing in scripting and .NET assembly

Source commit: a374ebe71eea553a366120f46b8d3169ad735a7a
This commit is contained in:
Martin Prikryl
2023-08-24 13:45:56 +00:00
parent c83979cda8
commit acd12ea3d7
7 changed files with 22 additions and 11 deletions

View File

@@ -468,7 +468,7 @@ void __fastcall TFTPFileSystem::Open()
if (!FTerminal->PromptUser(Data, pkUserName, LoadStr(USERNAME_TITLE), L"",
LoadStr(USERNAME_PROMPT2), true, 0, UserName))
{
FTerminal->FatalError(NULL, LoadStr(AUTHENTICATION_FAILED));
FTerminal->FatalError(NULL, LoadStr(CREDENTIALS_NOT_SPECIFIED));
}
else
{
@@ -487,7 +487,7 @@ void __fastcall TFTPFileSystem::Open()
if (!FTerminal->PromptUser(Data, pkPassword, LoadStr(PASSWORD_TITLE), L"",
LoadStr(PASSWORD_PROMPT), false, 0, Password))
{
FTerminal->FatalError(NULL, LoadStr(AUTHENTICATION_FAILED));
FTerminal->FatalError(NULL, LoadStr(CREDENTIALS_NOT_SPECIFIED));
}
}

View File

@@ -353,8 +353,7 @@ void __fastcall TS3FileSystem::Open()
if (!FTerminal->PromptUser(Data, pkUserName, LoadStr(S3_ACCESS_KEY_ID_TITLE), L"",
LoadStr(S3_ACCESS_KEY_ID_PROMPT), true, 0, AccessKeyId))
{
// note that we never get here actually
throw Exception(L"");
FTerminal->FatalError(NULL, LoadStr(CREDENTIALS_NOT_SPECIFIED));
}
}
FAccessKeyId = UTF8String(AccessKeyId);
@@ -379,8 +378,7 @@ void __fastcall TS3FileSystem::Open()
if (!FTerminal->PromptUser(Data, pkPassword, LoadStr(S3_SECRET_ACCESS_KEY_TITLE), L"",
LoadStr(S3_SECRET_ACCESS_KEY_PROMPT), false, 0, SecretAccessKey))
{
// note that we never get here actually
throw Exception(L"");
FTerminal->FatalError(NULL, LoadStr(CREDENTIALS_NOT_SPECIFIED));
}
}
FSecretAccessKey = UTF8String(SecretAccessKey);

View File

@@ -107,6 +107,7 @@ void __fastcall TSecureShell::ResetConnection()
FStoredPasswordTried = false;
FStoredPasswordTriedForKI = false;
FStoredPassphraseTried = false;
FAuthenticationCancelled = false;
delete FLogPolicy;
FLogPolicy = NULL;
delete FSeat;
@@ -447,6 +448,7 @@ void __fastcall TSecureShell::Open()
PuttyFatalError(InitError);
}
FUI->Information(LoadStr(STATUS_CONNECT), true);
FAuthenticationCancelled = false;
if (!Active && DebugAlwaysTrue(HasLocalProxy()))
{
FActive = true;
@@ -965,6 +967,7 @@ bool __fastcall TSecureShell::PromptUser(bool /*ToServer*/,
if (!Result)
{
LogEvent(L"Prompt cancelled.");
FAuthenticationCancelled = true;
}
else
{
@@ -1786,19 +1789,28 @@ void inline __fastcall TSecureShell::CheckConnection(int Message)
UnicodeString Str;
UnicodeString HelpKeyword;
int ExitCode = backend_exitcode(FBackendHandle);
if (Message >= 0)
{
Str = LoadStr(Message);
}
else
{
Str = LoadStr(NOT_CONNECTED);
HelpKeyword = HELP_NOT_CONNECTED;
if ((ExitCode == 0) && FAuthenticationCancelled)
{
Str = LoadStr(CREDENTIALS_NOT_SPECIFIED);
// The 0 code is not coming from the server
ExitCode = -1;
}
else
{
Str = LoadStr(NOT_CONNECTED);
HelpKeyword = HELP_NOT_CONNECTED;
}
}
Str = MainInstructions(Str);
int ExitCode = backend_exitcode(FBackendHandle);
if (ExitCode >= 0)
{
Str += L" " + FMTLOAD(SSH_EXITCODE, (ExitCode));

View File

@@ -45,6 +45,7 @@ private:
bool FStoredPasswordTried;
bool FStoredPasswordTriedForKI;
bool FStoredPassphraseTried;
bool FAuthenticationCancelled;
bool FOpened;
bool FClosed;
int FWaiting;

View File

@@ -1904,7 +1904,6 @@ int TWebDAVFileSystem::NeonRequestAuth(
if (!Terminal->PromptUser(SessionData, pkUserName, LoadStr(USERNAME_TITLE), L"",
LoadStr(USERNAME_PROMPT2), true, NE_ABUFSIZ, FileSystem->FUserName))
{
// note that we never get here actually
Result = false;
}
}
@@ -1946,7 +1945,6 @@ int TWebDAVFileSystem::NeonRequestAuth(
{
// Asking for password (or using configured password) the first time,
// and asking for password.
// Note that we never get false here actually
Terminal->LogEvent(L"Password prompt");
Result =
Terminal->PromptUser(

View File

@@ -287,6 +287,7 @@
#define CERTIFICATE_CANNOT_COMBINE 763
#define KEYGEN_NOT_PUBLIC 764
#define INCONSISTENT_SIZE 765
#define CREDENTIALS_NOT_SPECIFIED 766
#define CORE_CONFIRMATION_STRINGS 300
#define CONFIRM_PROLONG_TIMEOUT3 301

View File

@@ -259,6 +259,7 @@ BEGIN
CERTIFICATE_CANNOT_COMBINE, "Unable to combine certificate in \"%s\" with private key."
KEYGEN_NOT_PUBLIC, "File \"%s\" is not a public key in a known format."
INCONSISTENT_SIZE, "File part \"%s\" size is %s, but %s was expected."
CREDENTIALS_NOT_SPECIFIED, "Credentials were not specified."
CORE_CONFIRMATION_STRINGS, "CORE_CONFIRMATION"
CONFIRM_PROLONG_TIMEOUT3, "Host is not communicating for %d seconds.\n\nWait for another %0:d seconds?"