Merge pull request #670 from gavinandresen/rpcauth_speedup

Speed up RPC authentication (reworked pull from Joel Katz)
This commit is contained in:
Gavin Andresen 2011-12-01 13:01:59 -08:00
commit 173efb1865

View File

@ -36,6 +36,8 @@ void ThreadRPCServer2(void* parg);
typedef Value(*rpcfn_type)(const Array& params, bool fHelp); typedef Value(*rpcfn_type)(const Array& params, bool fHelp);
extern map<string, rpcfn_type> mapCallTable; extern map<string, rpcfn_type> mapCallTable;
static std::string strRPCUserColonPass;
static int64 nWalletUnlockTime; static int64 nWalletUnlockTime;
static CCriticalSection cs_nWalletUnlockTime; static CCriticalSection cs_nWalletUnlockTime;
@ -2023,12 +2025,7 @@ bool HTTPAuthorized(map<string, string>& mapHeaders)
return false; return false;
string strUserPass64 = strAuth.substr(6); boost::trim(strUserPass64); string strUserPass64 = strAuth.substr(6); boost::trim(strUserPass64);
string strUserPass = DecodeBase64(strUserPass64); string strUserPass = DecodeBase64(strUserPass64);
string::size_type nColon = strUserPass.find(":"); return strUserPass == strRPCUserColonPass;
if (nColon == string::npos)
return false;
string strUser = strUserPass.substr(0, nColon);
string strPassword = strUserPass.substr(nColon+1);
return (strUser == mapArgs["-rpcuser"] && strPassword == mapArgs["-rpcpassword"]);
} }
// //
@ -2161,7 +2158,8 @@ void ThreadRPCServer2(void* parg)
{ {
printf("ThreadRPCServer started\n"); printf("ThreadRPCServer started\n");
if (mapArgs["-rpcuser"] == "" && mapArgs["-rpcpassword"] == "") strRPCUserColonPass = mapArgs["-rpcuser"] + ":" + mapArgs["-rpcpassword"];
if (strRPCUserColonPass == ":")
{ {
string strWhatAmI = "To use bitcoind"; string strWhatAmI = "To use bitcoind";
if (mapArgs.count("-server")) if (mapArgs.count("-server"))