Skip to content

Commit 50b7a50

Browse files
committed
RPC: Keep .cookie if it was replaced after being generated
Github-Pull: bitcoin#28784 Rebased-From: d95dde9441fb791046394ed3784a840a54ef2ab9
1 parent 1248d0d commit 50b7a50

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/rpc/request.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static fs::path GetAuthCookieFile(bool temp=false)
9292
return AbsPathForConfigVal(gArgs, arg);
9393
}
9494

95-
static bool g_generated_cookie = false;
95+
static std::optional<std::string> g_generated_cookie;
9696

9797
bool GenerateAuthCookie(std::string* cookie_out, std::optional<fs::perms> cookie_perms)
9898
{
@@ -128,7 +128,7 @@ bool GenerateAuthCookie(std::string* cookie_out, std::optional<fs::perms> cookie
128128
}
129129
}
130130

131-
g_generated_cookie = true;
131+
g_generated_cookie = cookie;
132132
LogInfo("Generated RPC authentication cookie %s\n", fs::PathToString(filepath));
133133
LogInfo("Permissions used for cookie: %s\n", PermsToSymbolicString(fs::status(filepath).permissions()));
134134

@@ -156,8 +156,9 @@ bool GetAuthCookie(std::string *cookie_out)
156156
void DeleteAuthCookie()
157157
{
158158
try {
159-
if (g_generated_cookie) {
160-
// Delete the cookie file if it was generated by this process
159+
std::string existing_cookie;
160+
if (GetAuthCookie(&existing_cookie) && g_generated_cookie == existing_cookie) {
161+
// Delete the cookie file if it exists and was generated by this process
161162
fs::remove(GetAuthCookieFile());
162163
}
163164
} catch (const fs::filesystem_error& e) {

0 commit comments

Comments
 (0)