MCPcopy Create free account
hub / github.com/ElementsProject/elements / InitRPCAuthentication

Function InitRPCAuthentication

src/httprpc.cpp:242–290  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

240}
241
242static bool InitRPCAuthentication()
243{
244 if (gArgs.GetArg("-rpcpassword", "") == "")
245 {
246 LogPrintf("Using random cookie authentication.\n");
247 if (!GenerateAuthCookie(&strRPCUserColonPass)) {
248 return false;
249 }
250 } else {
251 LogPrintf("Config options rpcuser and rpcpassword will soon be deprecated. Locally-run instances may remove rpcuser to use cookie-based auth, or may be replaced with rpcauth. Please see share/rpcauth for rpcauth auth generation.\n");
252 strRPCUserColonPass = gArgs.GetArg("-rpcuser", "") + ":" + gArgs.GetArg("-rpcpassword", "");
253 }
254 if (gArgs.GetArg("-rpcauth","") != "")
255 {
256 LogPrintf("Using rpcauth authentication.\n");
257 for (const std::string& rpcauth : gArgs.GetArgs("-rpcauth")) {
258 std::vector<std::string> fields;
259 boost::split(fields, rpcauth, boost::is_any_of(":$"));
260 if (fields.size() == 3) {
261 g_rpcauth.push_back(fields);
262 } else {
263 LogPrintf("Invalid -rpcauth argument.\n");
264 return false;
265 }
266 }
267 }
268
269 g_rpc_whitelist_default = gArgs.GetBoolArg("-rpcwhitelistdefault", gArgs.IsArgSet("-rpcwhitelist"));
270 for (const std::string& strRPCWhitelist : gArgs.GetArgs("-rpcwhitelist")) {
271 auto pos = strRPCWhitelist.find(':');
272 std::string strUser = strRPCWhitelist.substr(0, pos);
273 bool intersect = g_rpc_whitelist.count(strUser);
274 std::set<std::string>& whitelist = g_rpc_whitelist[strUser];
275 if (pos != std::string::npos) {
276 std::string strWhitelist = strRPCWhitelist.substr(pos + 1);
277 std::set<std::string> new_whitelist;
278 boost::split(new_whitelist, strWhitelist, boost::is_any_of(", "));
279 if (intersect) {
280 std::set<std::string> tmp_whitelist;
281 std::set_intersection(new_whitelist.begin(), new_whitelist.end(),
282 whitelist.begin(), whitelist.end(), std::inserter(tmp_whitelist, tmp_whitelist.end()));
283 new_whitelist = std::move(tmp_whitelist);
284 }
285 whitelist = std::move(new_whitelist);
286 }
287 }
288
289 return true;
290}
291
292bool StartHTTPRPC(const std::any& context)
293{

Callers 1

StartHTTPRPCFunction · 0.85

Calls 11

GenerateAuthCookieFunction · 0.85
GetArgMethod · 0.80
GetArgsMethod · 0.80
GetBoolArgMethod · 0.80
IsArgSetMethod · 0.80
findMethod · 0.80
countMethod · 0.80
sizeMethod · 0.45
push_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected