aboutsummaryrefslogtreecommitdiff
path: root/src/httprpc.cpp
diff options
context:
space:
mode:
authorJonas Schnelli <dev@jonasschnelli.ch>2016-09-22 09:58:13 +0200
committerJonas Schnelli <dev@jonasschnelli.ch>2016-10-19 14:47:27 +0200
commite7156ad61be2fe935fdb64e9d0e877fa0e9f7f9e (patch)
tree19dcb95789fea3e6d168a7b2e1ecb7d66a5e006f /src/httprpc.cpp
parent69d1c25768a8649bfc7eb8e9c35b8fe9874ac9fc (diff)
[RPC] pass HTTP basic authentication username to the JSONRequest object
Diffstat (limited to 'src/httprpc.cpp')
-rw-r--r--src/httprpc.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/httprpc.cpp b/src/httprpc.cpp
index 54651911aa..e35acb6cd9 100644
--- a/src/httprpc.cpp
+++ b/src/httprpc.cpp
@@ -127,7 +127,7 @@ static bool multiUserAuthorized(std::string strUserPass)
return false;
}
-static bool RPCAuthorized(const std::string& strAuth)
+static bool RPCAuthorized(const std::string& strAuth, std::string& strAuthUsernameOut)
{
if (strRPCUserColonPass.empty()) // Belt-and-suspenders measure if InitRPCAuthentication was not called
return false;
@@ -136,7 +136,10 @@ static bool RPCAuthorized(const std::string& strAuth)
std::string strUserPass64 = strAuth.substr(6);
boost::trim(strUserPass64);
std::string strUserPass = DecodeBase64(strUserPass64);
-
+
+ if (strUserPass.find(":") != std::string::npos)
+ strAuthUsernameOut = strUserPass.substr(0, strUserPass.find(":"));
+
//Check if authorized under single-user field
if (TimingResistantEqual(strUserPass, strRPCUserColonPass)) {
return true;
@@ -159,7 +162,8 @@ static bool HTTPReq_JSONRPC(HTTPRequest* req, const std::string &)
return false;
}
- if (!RPCAuthorized(authHeader.second)) {
+ JSONRPCRequest jreq;
+ if (!RPCAuthorized(authHeader.second, jreq.authUser)) {
LogPrintf("ThreadRPCServer incorrect password attempt from %s\n", req->GetPeer().ToString());
/* Deter brute-forcing
@@ -172,7 +176,6 @@ static bool HTTPReq_JSONRPC(HTTPRequest* req, const std::string &)
return false;
}
- JSONRPCRequest jreq;
try {
// Parse request
UniValue valRequest;