Skip to content

Commit d37c813

Browse files
committed
rpc: Refactor to process -rpcauth once
1 parent 86bf3ae commit d37c813

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/httprpc.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class HTTPRPCTimerInterface : public RPCTimerInterface
6868
static std::string strRPCUserColonPass;
6969
/* Stored RPC timer interface (for unregistration) */
7070
static std::unique_ptr<HTTPRPCTimerInterface> httpRPCTimerInterface;
71+
/* List of -rpcauth values */
72+
static std::vector<std::vector<std::string>> g_rpcauth;
7173
/* RPC Auth Whitelist */
7274
static std::map<std::string, std::set<std::string>> g_rpc_whitelist;
7375
static bool g_rpc_whitelist_default = false;
@@ -99,15 +101,7 @@ static bool multiUserAuthorized(std::string strUserPass)
99101
std::string strUser = strUserPass.substr(0, strUserPass.find(':'));
100102
std::string strPass = strUserPass.substr(strUserPass.find(':') + 1);
101103

102-
for (const std::string& strRPCAuth : gArgs.GetArgs("-rpcauth")) {
103-
//Search for multi-user login/pass "rpcauth" from config
104-
std::vector<std::string> vFields;
105-
boost::split(vFields, strRPCAuth, boost::is_any_of(":$"));
106-
if (vFields.size() != 3) {
107-
//Incorrect formatting in config file
108-
continue;
109-
}
110-
104+
for (const auto& vFields : g_rpcauth) {
111105
std::string strName = vFields[0];
112106
if (!TimingResistantEqual(strName, strUser)) {
113107
continue;
@@ -259,6 +253,13 @@ static bool InitRPCAuthentication()
259253
if (gArgs.GetArg("-rpcauth","") != "")
260254
{
261255
LogPrintf("Using rpcauth authentication.\n");
256+
for (std::string rpcauth : gArgs.GetArgs("-rpcauth")) {
257+
std::vector<std::string> fields;
258+
boost::split(fields, rpcauth, boost::is_any_of(":$"));
259+
if (fields.size() == 3) {
260+
g_rpcauth.push_back(fields);
261+
}
262+
}
262263
}
263264

264265
g_rpc_whitelist_default = gArgs.GetBoolArg("-rpcwhitelistdefault", gArgs.IsArgSet("-rpcwhitelist"));

0 commit comments

Comments
 (0)