args: Support -norpccookiefile for bitcoind and bitcoin-cli

Replaces belt & suspenders check for initialization in RPCAuthorized() with not allowing empty passwords further down.
This commit is contained in:
Hodlinator
2024-12-03 10:20:31 +01:00
parent e82ad88452
commit 39cbd4f37c
2 changed files with 18 additions and 6 deletions

View File

@@ -86,6 +86,9 @@ static const char* const COOKIEAUTH_FILE = ".cookie";
static fs::path GetAuthCookieFile(bool temp=false)
{
fs::path arg = gArgs.GetPathArg("-rpccookiefile", COOKIEAUTH_FILE);
if (arg.empty()) {
return {}; // -norpccookiefile was specified
}
if (temp) {
arg += ".tmp";
}
@@ -106,6 +109,9 @@ bool GenerateAuthCookie(std::string* cookie_out, std::optional<fs::perms> cookie
*/
std::ofstream file;
fs::path filepath_tmp = GetAuthCookieFile(true);
if (filepath_tmp.empty()) {
return true; // -norpccookiefile
}
file.open(filepath_tmp);
if (!file.is_open()) {
LogWarning("Unable to open cookie authentication file %s for writing", fs::PathToString(filepath_tmp));
@@ -142,6 +148,9 @@ bool GetAuthCookie(std::string *cookie_out)
std::ifstream file;
std::string cookie;
fs::path filepath = GetAuthCookieFile();
if (filepath.empty()) {
return true; // -norpccookiefile
}
file.open(filepath);
if (!file.is_open())
return false;