Diff-minimise

This commit is contained in:
Luke Dashjr 2024-05-16 21:38:09 +00:00
parent 5f4907b033
commit 2dcaa7311a
2 changed files with 9 additions and 5 deletions

View File

@ -249,7 +249,7 @@ static bool InitRPCAuthentication()
{ {
if (gArgs.GetArg("-rpcpassword", "") == "") if (gArgs.GetArg("-rpcpassword", "") == "")
{ {
LogInfo("Using random cookie authentication.\n"); LogPrintf("Using random cookie authentication.\n");
std::optional<fs::perms> cookie_perms{DEFAULT_COOKIE_PERMS}; std::optional<fs::perms> cookie_perms{DEFAULT_COOKIE_PERMS};
auto cookie_perms_arg{gArgs.GetArg("-rpccookieperms")}; auto cookie_perms_arg{gArgs.GetArg("-rpccookieperms")};

View File

@ -5,11 +5,12 @@
#include <rpc/request.h> #include <rpc/request.h>
#include <util/fs.h>
#include <common/args.h> #include <common/args.h>
#include <logging.h> #include <logging.h>
#include <random.h> #include <random.h>
#include <rpc/protocol.h> #include <rpc/protocol.h>
#include <util/fs.h>
#include <util/fs_helpers.h> #include <util/fs_helpers.h>
#include <util/strencodings.h> #include <util/strencodings.h>
@ -90,6 +91,9 @@ bool GenerateAuthCookie(std::string* cookie_out, const std::pair<std::optional<f
GetRandBytes(rand_pwd); GetRandBytes(rand_pwd);
std::string cookie = COOKIEAUTH_USER + ":" + HexStr(rand_pwd); std::string cookie = COOKIEAUTH_USER + ":" + HexStr(rand_pwd);
/** the umask determines what permissions are used to create this file -
* these are set to 0077 in common/system.cpp.
*/
std::ofstream file; std::ofstream file;
fs::path filepath_tmp = GetAuthCookieFile(true); fs::path filepath_tmp = GetAuthCookieFile(true);
try { try {
@ -99,7 +103,7 @@ bool GenerateAuthCookie(std::string* cookie_out, const std::pair<std::optional<f
} }
file.open(filepath_tmp); file.open(filepath_tmp);
if (!file.is_open()) { if (!file.is_open()) {
LogInfo("Unable to open cookie authentication file %s for writing\n", fs::PathToString(filepath_tmp)); LogPrintf("Unable to open cookie authentication file %s for writing\n", fs::PathToString(filepath_tmp));
return false; return false;
} }
@ -127,12 +131,12 @@ bool GenerateAuthCookie(std::string* cookie_out, const std::pair<std::optional<f
// ignore // ignore
} }
if (!RenameOver(filepath_tmp, filepath)) { if (!RenameOver(filepath_tmp, filepath)) {
LogInfo("Unable to rename cookie authentication file %s to %s\n", fs::PathToString(filepath_tmp), fs::PathToString(filepath)); LogPrintf("Unable to rename cookie authentication file %s to %s\n", fs::PathToString(filepath_tmp), fs::PathToString(filepath));
return false; return false;
} }
g_generated_cookie = cookie; g_generated_cookie = cookie;
LogInfo("Generated RPC authentication cookie %s\n", fs::PathToString(filepath)); LogPrintf("Generated RPC authentication cookie %s\n", fs::PathToString(filepath));
LogInfo("Permissions used for cookie%s: %s\n", LogInfo("Permissions used for cookie%s: %s\n",
(cookie_perms.first && cookie_perms.second) ? " (set by -rpccookieperms)" : "", (cookie_perms.first && cookie_perms.second) ? " (set by -rpccookieperms)" : "",
PermsToString(fs::status(filepath).permissions())); PermsToString(fs::status(filepath).permissions()));