mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-08-05 06:24:49 +02:00
RPC: Keep .cookie if it was replaced after being generated
Github-Pull: #28784 Rebased-From: d95dde9441fb791046394ed3784a840a54ef2ab9
This commit is contained in:
parent
55bd5d8015
commit
4842324b7d
@ -80,7 +80,7 @@ static fs::path GetAuthCookieFile(bool temp=false)
|
|||||||
return AbsPathForConfigVal(gArgs, arg);
|
return AbsPathForConfigVal(gArgs, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool g_generated_cookie = false;
|
static std::optional<std::string> g_generated_cookie;
|
||||||
|
|
||||||
bool GenerateAuthCookie(std::string *cookie_out)
|
bool GenerateAuthCookie(std::string *cookie_out)
|
||||||
{
|
{
|
||||||
@ -107,7 +107,7 @@ bool GenerateAuthCookie(std::string *cookie_out)
|
|||||||
LogPrintf("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 = true;
|
g_generated_cookie = cookie;
|
||||||
LogPrintf("Generated RPC authentication cookie %s\n", fs::PathToString(filepath));
|
LogPrintf("Generated RPC authentication cookie %s\n", fs::PathToString(filepath));
|
||||||
|
|
||||||
if (cookie_out)
|
if (cookie_out)
|
||||||
@ -134,8 +134,9 @@ bool GetAuthCookie(std::string *cookie_out)
|
|||||||
void DeleteAuthCookie()
|
void DeleteAuthCookie()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (g_generated_cookie) {
|
std::string existing_cookie;
|
||||||
// Delete the cookie file if it was generated by this process
|
if (GetAuthCookie(&existing_cookie) && g_generated_cookie == existing_cookie) {
|
||||||
|
// Delete the cookie file if it exists and was generated by this process
|
||||||
fs::remove(GetAuthCookieFile());
|
fs::remove(GetAuthCookieFile());
|
||||||
}
|
}
|
||||||
} catch (const fs::filesystem_error& e) {
|
} catch (const fs::filesystem_error& e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user