From 30fc28693a844ba7dedf876af60eddbd187b20d8 Mon Sep 17 00:00:00 2001 From: Alessandro Pilotti Date: Sun, 13 Jul 2014 14:50:22 +0200 Subject: [PATCH] Adds support for domain user logins The user name can now be specified as UPN (e.g. user@domain.com) or down-level logon name (e.g. DOMAIN\user). URL decoding has been added for form elements as well, although this should be handled in EHS. --- wsgate/wsgate_main.cpp | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/wsgate/wsgate_main.cpp b/wsgate/wsgate_main.cpp index 1740a7e1..bf1a9ec9 100644 --- a/wsgate/wsgate_main.cpp +++ b/wsgate/wsgate_main.cpp @@ -42,6 +42,8 @@ #include #include #include +#include +#include #ifdef HAVE_SIGNAL_H # include @@ -103,6 +105,7 @@ namespace po = boost::program_options; namespace fs = boost::filesystem; namespace pt = boost::posix_time; using boost::filesystem::path; +using namespace utility::conversions; namespace wsgate { static const char * const ws_magic = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; @@ -121,6 +124,32 @@ namespace wsgate { return ret; } + void SplitUserDomain(const string& fullUsername, string& username, string& domain) + { + std::vector strs; + boost::split(strs, fullUsername, boost::is_any_of("\\")); + if (strs.size() > 1) + { + username = strs[1]; + domain = strs[0]; + } + else + { + strs.clear(); + boost::split(strs, fullUsername, boost::is_any_of("@")); + if (strs.size() > 1) + { + username = strs[0]; + domain = strs[1]; + } + else + { + username = fullUsername; + domain = ""; + } + } + } + // subclass of EHS that defines a custom HTTP response. class WsGate : public EHS { @@ -505,9 +534,9 @@ namespace wsgate { else { dtsize = request->FormValues("dtsize").m_sBody; - rdphost = request->FormValues("host").m_sBody; + rdphost = to_utf8string(web::uri::decode(to_string_t(request->FormValues("host").m_sBody))); rdppcb = request->FormValues("pcb").m_sBody; - rdpuser = request->FormValues("user").m_sBody; + rdpuser = to_utf8string(web::uri::decode(to_string_t(request->FormValues("user").m_sBody))); istringstream(request->FormValues("port").m_sBody) >> rdpport; rdppass = base64_decode(request->FormValues("pass").m_sBody); } @@ -1500,7 +1529,11 @@ namespace wsgate { rdp_ptr r(new RDP(h.get())); m_cmap[conn] = conn_tuple(c, h, r); - r->Connect(host, pcb, user, string() /*domain*/, pass, params); + string username; + string domain; + SplitUserDomain(user, username, domain); + + r->Connect(host, pcb, username, domain, pass, params); m_parent->RegisterRdpSession(r); } catch(...)