Skip to content

Commit e49dfac

Browse files
committed
rpccookieperms: Set permissions on temporary file, prior to writing the cookie
Github-Pull: na Rebased-From: 74cc11bbde33dad0f4856731bf16cb674069b3c4
1 parent 8cb6ab0 commit e49dfac

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

src/rpc/request.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,16 @@ bool GenerateAuthCookie(std::string* cookie_out, std::optional<fs::perms> cookie
117117
LogWarning("Unable to open cookie authentication file %s for writing", fs::PathToString(filepath_tmp));
118118
return false;
119119
}
120+
121+
if (cookie_perms) {
122+
std::error_code code;
123+
fs::permissions(filepath_tmp, cookie_perms.value(), fs::perm_options::replace, code);
124+
if (code) {
125+
LogWarning("Unable to set permissions on cookie authentication file %s", fs::PathToString(filepath_tmp));
126+
return false;
127+
}
128+
}
129+
120130
file << cookie;
121131
file.close();
122132

@@ -125,14 +135,6 @@ bool GenerateAuthCookie(std::string* cookie_out, std::optional<fs::perms> cookie
125135
LogWarning("Unable to rename cookie authentication file %s to %s", fs::PathToString(filepath_tmp), fs::PathToString(filepath));
126136
return false;
127137
}
128-
if (cookie_perms) {
129-
std::error_code code;
130-
fs::permissions(filepath, cookie_perms.value(), fs::perm_options::replace, code);
131-
if (code) {
132-
LogWarning("Unable to set permissions on cookie authentication file %s", fs::PathToString(filepath));
133-
return false;
134-
}
135-
}
136138

137139
g_generated_cookie = true;
138140
LogInfo("Generated RPC authentication cookie %s\n", fs::PathToString(filepath));

0 commit comments

Comments
 (0)