From 0f5c53d3e5d48fbb511bfa95e515f60da7f7862b Mon Sep 17 00:00:00 2001 From: akallabeth Date: Sun, 7 Dec 2025 08:15:33 +0100 Subject: [PATCH 1/4] [client,common] handle AUTH_RDSTLS separate The requirements for that authentication type are different, so handle it not like the rest. --- client/common/client.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) 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; + } } { From 266bf0e153fbfa8af9c00252dcd50173548f0e2a Mon Sep 17 00:00:00 2001 From: akallabeth Date: Sun, 7 Dec 2025 08:50:23 +0100 Subject: [PATCH 2/4] [client,sdl] position active input When querying for credentials position the selected input field to the first element not already containing a value. --- client/SDL/SDL3/dialogs/sdl_dialogs.cpp | 19 ++++++++++++++++- .../dialogs/sdl_input_widget_pair_list.cpp | 21 ++++++++++--------- .../dialogs/sdl_input_widget_pair_list.hpp | 3 ++- 3 files changed, 31 insertions(+), 12 deletions(-) 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..132198f23 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()); @@ -59,6 +59,7 @@ SdlInputWidgetPairList::SdlInputWidgetPairList(const std::string& title, static_cast(input_height), static_cast(widget_width), static_cast(widget_heigth)); _buttons.set_highlight(0); + _CurrentActiveTextInput = selected; } } @@ -145,7 +146,7 @@ int SdlInputWidgetPairList::run(std::vector& result) { int res = -1; ssize_t LastActiveTextInput = -1; - ssize_t CurrentActiveTextInput = next(-1); + _CurrentActiveTextInput = next(_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(_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); + _CurrentActiveTextInput = next(_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(_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(_CurrentActiveTextInput); if (cur) { if (!cur->append_str(event.text.text)) @@ -251,7 +252,7 @@ int SdlInputWidgetPairList::run(std::vector& result) { auto val = get_index(event.button); if (valid(val)) - CurrentActiveTextInput = val; + _CurrentActiveTextInput = val; auto button = _buttons.get_selected(event.button); if (button) @@ -273,9 +274,9 @@ int SdlInputWidgetPairList::run(std::vector& result) } } while (SDL_PollEvent(&event)); - if (LastActiveTextInput != CurrentActiveTextInput) + if (LastActiveTextInput != _CurrentActiveTextInput) { - LastActiveTextInput = CurrentActiveTextInput; + LastActiveTextInput = _CurrentActiveTextInput; } for (auto& cur : _list) @@ -283,7 +284,7 @@ int SdlInputWidgetPairList::run(std::vector& result) if (!cur->set_highlight(false)) throw; } - auto cur = get(CurrentActiveTextInput); + auto cur = get(_CurrentActiveTextInput); if (cur) { if (!cur->set_highlight(true)) 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..5b05657e9 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; @@ -59,4 +59,5 @@ class SdlInputWidgetPairList : public SdlWidgetList std::shared_ptr get(ssize_t index); std::vector> _list; + ssize_t _CurrentActiveTextInput = -1; }; From 78c9779eb17b3ef60fbcd05be9ef96427f0c8cfd Mon Sep 17 00:00:00 2001 From: akallabeth Date: Sun, 7 Dec 2025 09:02:39 +0100 Subject: [PATCH 3/4] [utils,passphrase] fix dangling pointers --- libfreerdp/utils/passphrase.c | 3 +++ 1 file changed, 3 insertions(+) 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; From 7973abe51c6265d96597cc9fa638b111ec9d172a Mon Sep 17 00:00:00 2001 From: akallabeth Date: Sun, 7 Dec 2025 10:08:51 +0100 Subject: [PATCH 4/4] [client,sdl] rename member variables --- .../dialogs/sdl_input_widget_pair_list.cpp | 50 +++++++++---------- .../dialogs/sdl_input_widget_pair_list.hpp | 4 +- 2 files changed, 27 insertions(+), 27 deletions(-) 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 132198f23..261024c57 100644 --- a/client/SDL/SDL3/dialogs/sdl_input_widget_pair_list.cpp +++ b/client/SDL/SDL3/dialogs/sdl_input_widget_pair_list.cpp @@ -52,14 +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); - _CurrentActiveTextInput = selected; + m_currentActiveTextInput = selected; } } @@ -70,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) @@ -83,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); } @@ -93,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) @@ -103,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; @@ -131,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)) @@ -146,7 +146,7 @@ int SdlInputWidgetPairList::run(std::vector& result) { int res = -1; ssize_t LastActiveTextInput = -1; - _CurrentActiveTextInput = next(_CurrentActiveTextInput); + m_currentActiveTextInput = next(m_currentActiveTextInput); if (!_window || !_renderer) return -2; @@ -175,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) @@ -192,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: @@ -207,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(); @@ -222,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)) @@ -233,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; } @@ -252,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) @@ -274,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)) @@ -299,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 5b05657e9..0b42cca16 100644 --- a/client/SDL/SDL3/dialogs/sdl_input_widget_pair_list.hpp +++ b/client/SDL/SDL3/dialogs/sdl_input_widget_pair_list.hpp @@ -58,6 +58,6 @@ class SdlInputWidgetPairList : public SdlWidgetList [[nodiscard]] bool valid(ssize_t current) const; std::shared_ptr get(ssize_t index); - std::vector> _list; - ssize_t _CurrentActiveTextInput = -1; + std::vector> m_list; + ssize_t m_currentActiveTextInput = -1; };