diff --git a/client/SDL/SDL3/dialogs/sdl_dialogs.cpp b/client/SDL/SDL3/dialogs/sdl_dialogs.cpp index 0505778b0..207f48780 100644 --- a/client/SDL/SDL3/dialogs/sdl_dialogs.cpp +++ b/client/SDL/SDL3/dialogs/sdl_dialogs.cpp @@ -585,7 +585,23 @@ BOOL sdl_auth_dialog_show(const SDL_UserAuthArg* args) flags = { 0, 0, SdlInputWidgetPair::SDL_INPUT_MASK }; } } - SdlInputWidgetPairList ilist(args->title, prompt, initial, flags); + + ssize_t selected = -1; + switch (args->result) + { + case AUTH_SMARTCARD_PIN: + case AUTH_RDSTLS: + break; + default: + if (args->user) + { + selected++; + if (args->domain) + selected++; + } + break; + } + SdlInputWidgetPairList ilist(args->title, prompt, initial, flags, selected); rc = ilist.run(result); } @@ -606,6 +622,7 @@ BOOL sdl_auth_dialog_show(const SDL_UserAuthArg* args) pwd = _strdup(result[2].c_str()); } } + return sdl_push_user_event(SDL_EVENT_USER_AUTH_RESULT, user, domain, pwd, rc); } diff --git a/client/SDL/SDL3/dialogs/sdl_input_widget_pair_list.cpp b/client/SDL/SDL3/dialogs/sdl_input_widget_pair_list.cpp index 9c2f3882d..261024c57 100644 --- a/client/SDL/SDL3/dialogs/sdl_input_widget_pair_list.cpp +++ b/client/SDL/SDL3/dialogs/sdl_input_widget_pair_list.cpp @@ -30,7 +30,7 @@ static const Uint32 vpadding = 5; SdlInputWidgetPairList::SdlInputWidgetPairList(const std::string& title, const std::vector& labels, const std::vector& initial, - const std::vector& flags) + const std::vector& flags, ssize_t selected) { assert(labels.size() == initial.size()); assert(labels.size() == flags.size()); @@ -52,13 +52,14 @@ SdlInputWidgetPairList::SdlInputWidgetPairList(const std::string& title, { std::shared_ptr widget(new SdlInputWidgetPair( _renderer, labels[x], initial[x], flags[x], x, widget_width, widget_heigth)); - _list.emplace_back(widget); + m_list.emplace_back(widget); } _buttons.populate(_renderer, buttonlabels, buttonids, total_width, static_cast(input_height), static_cast(widget_width), static_cast(widget_heigth)); _buttons.set_highlight(0); + m_currentActiveTextInput = selected; } } @@ -69,7 +70,7 @@ ssize_t SdlInputWidgetPairList::next(ssize_t current) do { - if (iteration >= _list.size()) + if (iteration >= m_list.size()) return -1; if (iteration == 0) @@ -82,7 +83,7 @@ ssize_t SdlInputWidgetPairList::next(ssize_t current) else val++; iteration++; - val %= _list.size(); + val %= m_list.size(); } while (!valid(static_cast(val))); return static_cast(val); } @@ -92,9 +93,9 @@ bool SdlInputWidgetPairList::valid(ssize_t current) const if (current < 0) return false; auto s = static_cast(current); - if (s >= _list.size()) + if (s >= m_list.size()) return false; - return !_list[s]->readonly(); + return !m_list[s]->readonly(); } std::shared_ptr SdlInputWidgetPairList::get(ssize_t index) @@ -102,20 +103,20 @@ std::shared_ptr SdlInputWidgetPairList::get(ssize_t index) if (index < 0) return nullptr; auto s = static_cast(index); - if (s >= _list.size()) + if (s >= m_list.size()) return nullptr; - return _list[s]; + return m_list[s]; } SdlInputWidgetPairList::~SdlInputWidgetPairList() { - _list.clear(); + m_list.clear(); _buttons.clear(); } bool SdlInputWidgetPairList::updateInternal() { - for (auto& btn : _list) + for (auto& btn : m_list) { if (!btn->update()) return false; @@ -130,9 +131,9 @@ ssize_t SdlInputWidgetPairList::get_index(const SDL_MouseButtonEvent& button) { const auto x = button.x; const auto y = button.y; - for (size_t i = 0; i < _list.size(); i++) + for (size_t i = 0; i < m_list.size(); i++) { - auto& cur = _list[i]; + auto& cur = m_list[i]; auto r = cur->input_rect(); if ((x >= r.x) && (x <= r.x + r.w) && (y >= r.y) && (y <= r.y + r.h)) @@ -145,7 +146,7 @@ int SdlInputWidgetPairList::run(std::vector& result) { int res = -1; ssize_t LastActiveTextInput = -1; - ssize_t CurrentActiveTextInput = next(-1); + m_currentActiveTextInput = next(m_currentActiveTextInput); if (!_window || !_renderer) return -2; @@ -174,7 +175,7 @@ int SdlInputWidgetPairList::run(std::vector& result) { case SDLK_BACKSPACE: { - auto cur = get(CurrentActiveTextInput); + auto cur = get(m_currentActiveTextInput); if (cur) { if ((event.key.mod & SDL_KMOD_CTRL) != 0) @@ -191,7 +192,7 @@ int SdlInputWidgetPairList::run(std::vector& result) } break; case SDLK_TAB: - CurrentActiveTextInput = next(CurrentActiveTextInput); + m_currentActiveTextInput = next(m_currentActiveTextInput); break; case SDLK_RETURN: case SDLK_RETURN2: @@ -206,7 +207,7 @@ int SdlInputWidgetPairList::run(std::vector& result) case SDLK_V: if ((event.key.mod & SDL_KMOD_CTRL) != 0) { - auto cur = get(CurrentActiveTextInput); + auto cur = get(m_currentActiveTextInput); if (cur) { auto text = SDL_GetClipboardText(); @@ -221,7 +222,7 @@ int SdlInputWidgetPairList::run(std::vector& result) break; case SDL_EVENT_TEXT_INPUT: { - auto cur = get(CurrentActiveTextInput); + auto cur = get(m_currentActiveTextInput); if (cur) { if (!cur->append_str(event.text.text)) @@ -232,14 +233,14 @@ int SdlInputWidgetPairList::run(std::vector& result) case SDL_EVENT_MOUSE_MOTION: { auto TextInputIndex = get_index(event.button); - for (auto& cur : _list) + for (auto& cur : m_list) { if (!cur->set_mouseover(false)) throw; } if (TextInputIndex >= 0) { - auto& cur = _list[static_cast(TextInputIndex)]; + auto& cur = m_list[static_cast(TextInputIndex)]; if (!cur->set_mouseover(true)) throw; } @@ -251,7 +252,7 @@ int SdlInputWidgetPairList::run(std::vector& result) { auto val = get_index(event.button); if (valid(val)) - CurrentActiveTextInput = val; + m_currentActiveTextInput = val; auto button = _buttons.get_selected(event.button); if (button) @@ -273,17 +274,17 @@ int SdlInputWidgetPairList::run(std::vector& result) } } while (SDL_PollEvent(&event)); - if (LastActiveTextInput != CurrentActiveTextInput) + if (LastActiveTextInput != m_currentActiveTextInput) { - LastActiveTextInput = CurrentActiveTextInput; + LastActiveTextInput = m_currentActiveTextInput; } - for (auto& cur : _list) + for (auto& cur : m_list) { if (!cur->set_highlight(false)) throw; } - auto cur = get(CurrentActiveTextInput); + auto cur = get(m_currentActiveTextInput); if (cur) { if (!cur->set_highlight(true)) @@ -298,7 +299,7 @@ int SdlInputWidgetPairList::run(std::vector& result) } } - for (auto& cur : _list) + for (auto& cur : m_list) result.push_back(cur->value()); } catch (...) diff --git a/client/SDL/SDL3/dialogs/sdl_input_widget_pair_list.hpp b/client/SDL/SDL3/dialogs/sdl_input_widget_pair_list.hpp index 28b597d5e..0b42cca16 100644 --- a/client/SDL/SDL3/dialogs/sdl_input_widget_pair_list.hpp +++ b/client/SDL/SDL3/dialogs/sdl_input_widget_pair_list.hpp @@ -32,7 +32,7 @@ class SdlInputWidgetPairList : public SdlWidgetList public: SdlInputWidgetPairList(const std::string& title, const std::vector& labels, const std::vector& initial, - const std::vector& flags); + const std::vector& flags, ssize_t selected = -1); SdlInputWidgetPairList(const SdlInputWidgetPairList& other) = delete; SdlInputWidgetPairList(SdlInputWidgetPairList&& other) = delete; @@ -58,5 +58,6 @@ class SdlInputWidgetPairList : public SdlWidgetList [[nodiscard]] bool valid(ssize_t current) const; std::shared_ptr get(ssize_t index); - std::vector> _list; + std::vector> m_list; + ssize_t m_currentActiveTextInput = -1; }; diff --git a/client/common/client.c b/client/common/client.c index 06912abc9..f62ebdb56 100644 --- a/client/common/client.c +++ b/client/common/client.c @@ -507,6 +507,7 @@ static BOOL client_cli_authenticate_raw(freerdp* instance, rdp_auth_reason reaso const char* domainAuth = "Domain: "; const char* pwdAuth = "Password: "; BOOL pinOnly = FALSE; + BOOL queryAll = FALSE; WINPR_ASSERT(instance); WINPR_ASSERT(instance->context); @@ -519,6 +520,8 @@ static BOOL client_cli_authenticate_raw(freerdp* instance, rdp_auth_reason reaso pinOnly = TRUE; break; case AUTH_RDSTLS: + queryAll = TRUE; + break; case AUTH_TLS: case AUTH_RDP: case AUTH_NLA: @@ -539,16 +542,24 @@ static BOOL client_cli_authenticate_raw(freerdp* instance, rdp_auth_reason reaso if (!pinOnly) { - const int rc = client_cli_read_string(instance, userAuth, *username, username); - if (rc < 0) - goto fail; + const char* suggest = *username; + if (queryAll || !suggest) + { + const int rc = client_cli_read_string(instance, userAuth, suggest, username); + if (rc < 0) + goto fail; + } } if (!pinOnly) { - const int rc = client_cli_read_string(instance, domainAuth, *domain, domain); - if (rc < 0) - goto fail; + const char* suggest = *domain; + if (queryAll || !suggest) + { + const int rc = client_cli_read_string(instance, domainAuth, suggest, domain); + if (rc < 0) + goto fail; + } } { diff --git a/libfreerdp/utils/passphrase.c b/libfreerdp/utils/passphrase.c index 7c6f8b84f..73c88ac5f 100644 --- a/libfreerdp/utils/passphrase.c +++ b/libfreerdp/utils/passphrase.c @@ -443,6 +443,8 @@ SSIZE_T freerdp_interruptible_get_line(rdpContext* context, char** plineptr, siz if (!n) { + free(ptr); + *plineptr = NULL; return -1; } @@ -479,6 +481,7 @@ SSIZE_T freerdp_interruptible_get_line(rdpContext* context, char** plineptr, siz if (c == EOF) { free(ptr); + *plineptr = NULL; return EOF; } *plineptr = ptr;