aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHennadii Stepanov <32963518+hebasto@users.noreply.github.com>2023-02-06 11:08:03 +0000
committerHennadii Stepanov <32963518+hebasto@users.noreply.github.com>2023-02-06 11:08:03 +0000
commit581f16ef3404274cb5c1a79dd3d6ee7b584f9844 (patch)
tree82d42c6eb31a803dbc55967711e0433e356a7b02
parent8a6219e54379911605aed860519e0194f1433b72 (diff)
Apply default umask in `SetupEnvironment()`
This change makes all filesystem artifacts--files and directories--being created with the default umask.
-rw-r--r--src/i2p.cpp2
-rw-r--r--src/init.cpp2
-rw-r--r--src/rpc/request.cpp2
-rw-r--r--src/util/system.cpp5
4 files changed, 7 insertions, 4 deletions
diff --git a/src/i2p.cpp b/src/i2p.cpp
index d4139bb8e5..8e98440747 100644
--- a/src/i2p.cpp
+++ b/src/i2p.cpp
@@ -336,7 +336,7 @@ void Session::GenerateAndSavePrivateKey(const Sock& sock)
{
DestGenerate(sock);
- // umask is set to 077 in init.cpp, which is ok.
+ // umask is set to 0077 in util/system.cpp, which is ok.
if (!WriteBinaryFile(m_private_key_file,
std::string(m_private_key.begin(), m_private_key.end()))) {
throw std::runtime_error(
diff --git a/src/init.cpp b/src/init.cpp
index c4a07069e7..73ae36e4f7 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -816,8 +816,6 @@ bool AppInitBasicSetup(const ArgsManager& args)
}
#ifndef WIN32
- umask(077);
-
// Clean shutdown on SIGTERM
registerSignalHandler(SIGTERM, HandleSIGTERM);
registerSignalHandler(SIGINT, HandleSIGTERM);
diff --git a/src/rpc/request.cpp b/src/rpc/request.cpp
index f554ee2116..6f37fe2a99 100644
--- a/src/rpc/request.cpp
+++ b/src/rpc/request.cpp
@@ -86,7 +86,7 @@ bool GenerateAuthCookie(std::string *cookie_out)
std::string cookie = COOKIEAUTH_USER + ":" + HexStr(rand_pwd);
/** the umask determines what permissions are used to create this file -
- * these are set to 077 in init.cpp.
+ * these are set to 0077 in util/system.cpp.
*/
std::ofstream file;
fs::path filepath_tmp = GetAuthCookieFile(true);
diff --git a/src/util/system.cpp b/src/util/system.cpp
index 0cea283ece..e72c970157 100644
--- a/src/util/system.cpp
+++ b/src/util/system.cpp
@@ -1360,6 +1360,11 @@ void SetupEnvironment()
SetConsoleCP(CP_UTF8);
SetConsoleOutputCP(CP_UTF8);
#endif
+
+#ifndef WIN32
+ constexpr mode_t private_umask = 0077;
+ umask(private_umask);
+#endif
}
bool SetupNetworking()