//--------------------------------------------------------------------------- int COptions::GetInstanceOptionVal(CApiLog * Instance, int OptionID) { ASSERT(Instance); ASSERT(NB_STATIC_DOWNCAST(TFileZillaIntern, Instance) != NULL); TFileZillaIntern * Intern = NB_STATIC_DOWNCAST(TFileZillaIntern, Instance); const TFileZillaIntf * Intf = Intern->GetOwner(); ASSERT(Intf != NULL); return (int)Intf->OptionVal(OptionID); }
int from_backend(void * frontend, int is_stderr, const char * data, int datalen) { DebugAssert(frontend); if (is_stderr >= 0) { DebugAssert((is_stderr == 0) || (is_stderr == 1)); (NB_STATIC_DOWNCAST(TSecureShell, frontend))->FromBackend((is_stderr == 1), reinterpret_cast<const uint8_t *>(data), datalen); } else { DebugAssert(is_stderr == -1); (NB_STATIC_DOWNCAST(TSecureShell, frontend))->CWrite(data, datalen); } return 0; }
extern "C" char * do_select(Plug plug, SOCKET skt, int startup) { void * frontend = nullptr; if (!is_ssh(plug) && !is_pfwd(plug)) { // If it is not SSH/PFwd plug, then it must be Proxy plug. // Get SSH/PFwd plug which it wraps. Proxy_Socket ProxySocket = (reinterpret_cast<Proxy_Plug>(plug))->proxy_socket; plug = ProxySocket->plug; } bool pfwd = is_pfwd(plug) != 0; if (pfwd) { plug = static_cast<Plug>(get_pfwd_backend(plug)); } frontend = get_ssh_frontend(plug); DebugAssert(frontend); TSecureShell * SecureShell = NB_STATIC_DOWNCAST(TSecureShell, frontend); if (!pfwd) { SecureShell->UpdateSocket(skt, startup != 0); } else { SecureShell->UpdatePortFwdSocket(skt, startup != 0); } return nullptr; }
void logevent(void * frontend, const char * str) { // Frontend maybe NULL here if (frontend != nullptr) { (NB_STATIC_DOWNCAST(TSecureShell, frontend))->PuttyLogEvent(str); } }
int askalg(void * frontend, const char * algtype, const char * algname, void (* /*callback*/)(void * ctx, int result), void * /*ctx*/) { DebugAssert(frontend != nullptr); (NB_STATIC_DOWNCAST(TSecureShell, frontend))->AskAlg(algtype, algname); // We should return 0 when alg was not confirmed, we throw exception instead. return 1; }
//--------------------------------------------------------------------------- CString COptions::GetInstanceOption(CApiLog * Instance, int OptionID) { ASSERT(Instance); ASSERT(NB_STATIC_DOWNCAST(TFileZillaIntern, Instance) != NULL); TFileZillaIntern * Intern = NB_STATIC_DOWNCAST(TFileZillaIntern, Instance); const TFileZillaIntf * Intf = Intern->GetOwner(); ASSERT(Intf != NULL); CString Result = Intf->Option(OptionID); switch (OptionID) { case OPTION_PROXYPASS: case OPTION_FWPASS: Result = CCrypt::encrypt(Result); break; } return Result; }
int verify_ssh_host_key(void * frontend, char * host, int port, char * keytype, char * keystr, char * fingerprint, void (* /*callback*/)(void * ctx, int result), void * /*ctx*/) { DebugAssert(frontend != nullptr); (NB_STATIC_DOWNCAST(TSecureShell, frontend))->VerifyHostKey(UnicodeString(host), port, keytype, keystr, fingerprint); // We should return 0 when key was not confirmed, we throw exception instead. return 1; }
void connection_fatal(void * frontend, const char * fmt, ...) { va_list Param; char Buf[200]; va_start(Param, fmt); vsnprintf_s(Buf, _countof(Buf), fmt, Param); \ Buf[_countof(Buf) - 1] = '\0'; \ va_end(Param); assert(frontend != nullptr); (NB_STATIC_DOWNCAST(TSecureShell, frontend))->PuttyFatalError(UnicodeString(Buf)); }
void connection_fatal(void * frontend, const char * fmt, ...) { va_list Param; std::string Buf; Buf.resize(32 * 1024); va_start(Param, fmt); vsnprintf((char *)Buf.c_str(), Buf.size(), fmt, Param); Buf[Buf.size() - 1] = '\0'; va_end(Param); DebugAssert(frontend != nullptr); (NB_STATIC_DOWNCAST(TSecureShell, frontend))->PuttyFatalError(UnicodeString(Buf.c_str())); }
Exception * CloneException(Exception * E) { Exception * Result; // this list has to be in sync with ExceptionMessage ExtException * Ext = NB_STATIC_DOWNCAST(ExtException, E); if (Ext != nullptr) { Result = Ext->Clone(); } else if (NB_STATIC_DOWNCAST(ECallbackGuardAbort, E) != nullptr) { Result = new ECallbackGuardAbort(); } else if (NB_STATIC_DOWNCAST(EAbort, E) != nullptr) { Result = new EAbort(E->Message); } else if (WellKnownException(E, nullptr, nullptr, &Result, false)) { // noop } else { // we do not expect this to happen if (ALWAYS_FALSE(IsInternalException(E))) { // to save exception stack trace Result = ExtException::CloneFrom(E); } else { Result = new Exception(E->Message); } } return Result; }
void RethrowException(Exception * E) { // this list has to be in sync with ExceptionMessage if (NB_STATIC_DOWNCAST(EFatal, E) != nullptr) { throw EFatal(E, L""); } else if (NB_STATIC_DOWNCAST(ECallbackGuardAbort, E) != nullptr) { throw ECallbackGuardAbort(); } else if (NB_STATIC_DOWNCAST(EAbort, E) != nullptr) { throw EAbort(E->Message); } else if (WellKnownException(E, nullptr, nullptr, nullptr, true)) { // noop, should never get here } else { throw ExtException(E, L""); } }
TStrings * ExceptionToMoreMessages(Exception * E) { TStrings * Result = nullptr; UnicodeString Message; if (ExceptionMessage(E, Message)) { Result = new TStringList(); Result->Add(Message); ExtException * ExtE = NB_STATIC_DOWNCAST(ExtException, E); if ((ExtE != nullptr) && (ExtE->GetMoreMessages() != nullptr)) { Result->AddStrings(ExtE->GetMoreMessages()); } } return Result; }
int GetUserpassInput(prompts_t * p, const uint8_t * /*in*/, int /*inlen*/) { assert(p != nullptr); TSecureShell * SecureShell = NB_STATIC_DOWNCAST(TSecureShell, p->frontend); assert(SecureShell != nullptr); int Result; std::unique_ptr<TStrings> Prompts(new TStringList()); std::unique_ptr<TStrings> Results(new TStringList()); { for (size_t Index = 0; Index < p->n_prompts; ++Index) { prompt_t * Prompt = p->prompts[Index]; Prompts->AddObject(Prompt->prompt, reinterpret_cast<TObject *>(static_cast<size_t>(FLAGMASK(Prompt->echo, pupEcho)))); // this fails, when new passwords do not match on change password prompt, // and putty retries the prompt assert(Prompt->resultsize == 0); Results->Add(L""); } if (SecureShell->PromptUser(p->to_server != 0, p->name, p->name_reqd != 0, UnicodeString(p->instruction), p->instr_reqd != 0, Prompts.get(), Results.get())) { for (size_t Index = 0; Index < p->n_prompts; ++Index) { prompt_t * Prompt = p->prompts[Index]; prompt_set_result(Prompt, AnsiString(Results->GetString(Index).c_str()).c_str()); } Result = 1; } else { Result = 0; } } return Result; }
void TSynchronizeController::SynchronizeChange( TObject * /*Sender*/, const UnicodeString & Directory, bool & SubdirsChanged) { try { UnicodeString RemoteDirectory; UnicodeString RootLocalDirectory; RootLocalDirectory = ::IncludeTrailingBackslash(FSynchronizeParams.LocalDirectory); RemoteDirectory = core::UnixIncludeTrailingBackslash(FSynchronizeParams.RemoteDirectory); UnicodeString LocalDirectory = ::IncludeTrailingBackslash(Directory); assert(LocalDirectory.SubString(1, RootLocalDirectory.Length()) == RootLocalDirectory); RemoteDirectory = RemoteDirectory + core::ToUnixPath(LocalDirectory.SubString(RootLocalDirectory.Length() + 1, LocalDirectory.Length() - RootLocalDirectory.Length())); SynchronizeLog(slChange, FMTLOAD(SYNCHRONIZE_CHANGE, ::ExcludeTrailingBackslash(LocalDirectory).c_str())); if (FOnSynchronize != nullptr) { // this is completely wrong as the options structure // can contain non-root specific options in future TSynchronizeOptions * Options = ((LocalDirectory == RootLocalDirectory) ? FOptions : nullptr); TSynchronizeChecklist * Checklist = nullptr; FOnSynchronize(this, LocalDirectory, RemoteDirectory, FCopyParam, FSynchronizeParams, &Checklist, Options, false); if (Checklist != nullptr) { std::unique_ptr<TSynchronizeChecklist> ChecklistPtr(Checklist); (void)ChecklistPtr; if (FLAGSET(FSynchronizeParams.Options, soRecurse)) { SubdirsChanged = false; assert(Checklist != nullptr); for (intptr_t Index = 0; Index < Checklist->GetCount(); ++Index) { const TChecklistItem * Item = Checklist->GetItem(Index); // note that there may be action saDeleteRemote even if nothing has changed // so this is sub-optimal if (Item->IsDirectory) { if ((Item->Action == saUploadNew) || (Item->Action == saDeleteRemote)) { SubdirsChanged = true; break; } else { assert(false); } } } } else { SubdirsChanged = false; } } } } catch (Exception & E) { SynchronizeAbort(NB_STATIC_DOWNCAST(EFatal, &E) != nullptr); } }
TFarConfiguration * GetFarConfiguration() { return NB_STATIC_DOWNCAST(TFarConfiguration, GetConfiguration()); }
void display_banner(void * frontend, const char * banner, int size) { DebugAssert(frontend); UnicodeString Banner(banner, size); (NB_STATIC_DOWNCAST(TSecureShell, frontend))->DisplayBanner(Banner); }
int GetUserpassInput(prompts_t * p, const uint8_t * /*in*/, int /*inlen*/) { DebugAssert(p != nullptr); TSecureShell * SecureShell = NB_STATIC_DOWNCAST(TSecureShell, p->frontend); DebugAssert(SecureShell != nullptr); int Result; std::unique_ptr<TStrings> Prompts(new TStringList()); std::unique_ptr<TStrings> Results(new TStringList()); { UnicodeString Name = UTF8ToString(p->name); UnicodeString AName = Name; TPromptKind PromptKind = SecureShell->IdentifyPromptKind(AName); bool UTF8Prompt = (PromptKind != pkPassphrase); for (size_t Index = 0; Index < p->n_prompts; ++Index) { prompt_t * Prompt = p->prompts[Index]; UnicodeString S; if (UTF8Prompt) { S = UTF8ToString(Prompt->prompt); } else { S = UnicodeString(AnsiString(Prompt->prompt)); } Prompts->AddObject(S, reinterpret_cast<TObject *>(static_cast<size_t>(FLAGMASK(Prompt->echo, pupEcho)))); // this fails, when new passwords do not match on change password prompt, // and putty retries the prompt DebugAssert(Prompt->resultsize == 0); Results->Add(L""); } UnicodeString Instructions = UTF8ToString(p->instruction); if (SecureShell->PromptUser(p->to_server != 0, Name, p->name_reqd != 0, Instructions, p->instr_reqd != 0, Prompts.get(), Results.get())) { for (size_t Index = 0; Index < p->n_prompts; ++Index) { prompt_t * Prompt = p->prompts[Index]; RawByteString S; if (UTF8Prompt) { S = RawByteString(UTF8String(Results->GetString(Index))); } else { S = RawByteString(AnsiString(Results->GetString(Index))); } prompt_set_result(Prompt, S.c_str()); } Result = 1; } else { Result = 0; } } __finally { // delete Prompts; // delete Results; }; return Result; }