mirror of
https://github.com/morgan9e/FreeRDP
synced 2026-04-15 00:44:19 +09:00
Merge pull request #12050 from akallabeth/from-stdin
From stdin and sdl-creds improve
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ static const Uint32 vpadding = 5;
|
||||
SdlInputWidgetPairList::SdlInputWidgetPairList(const std::string& title,
|
||||
const std::vector<std::string>& labels,
|
||||
const std::vector<std::string>& initial,
|
||||
const std::vector<Uint32>& flags)
|
||||
const std::vector<Uint32>& 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<SdlInputWidgetPair> 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<Sint32>(input_height), static_cast<Sint32>(widget_width),
|
||||
static_cast<Sint32>(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<ssize_t>(val)));
|
||||
return static_cast<ssize_t>(val);
|
||||
}
|
||||
@@ -92,9 +93,9 @@ bool SdlInputWidgetPairList::valid(ssize_t current) const
|
||||
if (current < 0)
|
||||
return false;
|
||||
auto s = static_cast<size_t>(current);
|
||||
if (s >= _list.size())
|
||||
if (s >= m_list.size())
|
||||
return false;
|
||||
return !_list[s]->readonly();
|
||||
return !m_list[s]->readonly();
|
||||
}
|
||||
|
||||
std::shared_ptr<SdlInputWidgetPair> SdlInputWidgetPairList::get(ssize_t index)
|
||||
@@ -102,20 +103,20 @@ std::shared_ptr<SdlInputWidgetPair> SdlInputWidgetPairList::get(ssize_t index)
|
||||
if (index < 0)
|
||||
return nullptr;
|
||||
auto s = static_cast<size_t>(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<std::string>& 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<std::string>& 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<std::string>& 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<std::string>& 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<std::string>& 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<std::string>& 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<size_t>(TextInputIndex)];
|
||||
auto& cur = m_list[static_cast<size_t>(TextInputIndex)];
|
||||
if (!cur->set_mouseover(true))
|
||||
throw;
|
||||
}
|
||||
@@ -251,7 +252,7 @@ int SdlInputWidgetPairList::run(std::vector<std::string>& 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<std::string>& 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<std::string>& result)
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& cur : _list)
|
||||
for (auto& cur : m_list)
|
||||
result.push_back(cur->value());
|
||||
}
|
||||
catch (...)
|
||||
|
||||
@@ -32,7 +32,7 @@ class SdlInputWidgetPairList : public SdlWidgetList
|
||||
public:
|
||||
SdlInputWidgetPairList(const std::string& title, const std::vector<std::string>& labels,
|
||||
const std::vector<std::string>& initial,
|
||||
const std::vector<Uint32>& flags);
|
||||
const std::vector<Uint32>& 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<SdlInputWidgetPair> get(ssize_t index);
|
||||
|
||||
std::vector<std::shared_ptr<SdlInputWidgetPair>> _list;
|
||||
std::vector<std::shared_ptr<SdlInputWidgetPair>> m_list;
|
||||
ssize_t m_currentActiveTextInput = -1;
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user