mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-03 17:54:19 +02:00
Merge bitcoin/bitcoin#28167: init: Add option for rpccookie permissions (replace 26088)
73f0a6cbd0doc: detail -rpccookieperms option (willcl-ark)d2afa2690ctest: add rpccookieperms test (willcl-ark)f467aede78init: add option for rpccookie permissions (willcl-ark)7df03f1a92util: add perm string helper functions (willcl-ark) Pull request description: This PR picks up #26088 by aureleoules which adds a bitcoind launch option `-rpccookieperms` to set the file permissions of the cookie generated by bitcoin core. Example usage to make the generated cookie group-readable: `./src/bitcoind -rpccookieperms=group`. Accepted values for `-rpccookieperms` are `[owner|group|all]`. We let `fs::perms` handle platform-specific permissions changes. ACKs for top commit: achow101: ACK73f0a6cbd0ryanofsky: Code review ACK73f0a6cbd0. Main change since last review is no longer throwing a skip exception in the rpc test on windows, so other checks can run after it, and overall test result is passing, not skipped. Also were clarifying renames and documentation improvements. tdb3: cr ACK73f0a6cbd0Tree-SHA512: e800d59a44aca10e1c58ca69bf3fdde9f6ccf5eab4b7b962645af6d6bc0cfa3a357701e409c8c60d8d7744fcd33a91e77ada11790aa88cd7811ef60fab86ab11
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <system_error>
|
||||
#include <utility>
|
||||
@@ -269,3 +270,42 @@ bool TryCreateDirectories(const fs::path& p)
|
||||
// create_directories didn't create the directory, it had to have existed already
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string PermsToSymbolicString(fs::perms p)
|
||||
{
|
||||
std::string perm_str(9, '-');
|
||||
|
||||
auto set_perm = [&](size_t pos, fs::perms required_perm, char letter) {
|
||||
if ((p & required_perm) != fs::perms::none) {
|
||||
perm_str[pos] = letter;
|
||||
}
|
||||
};
|
||||
|
||||
set_perm(0, fs::perms::owner_read, 'r');
|
||||
set_perm(1, fs::perms::owner_write, 'w');
|
||||
set_perm(2, fs::perms::owner_exec, 'x');
|
||||
set_perm(3, fs::perms::group_read, 'r');
|
||||
set_perm(4, fs::perms::group_write, 'w');
|
||||
set_perm(5, fs::perms::group_exec, 'x');
|
||||
set_perm(6, fs::perms::others_read, 'r');
|
||||
set_perm(7, fs::perms::others_write, 'w');
|
||||
set_perm(8, fs::perms::others_exec, 'x');
|
||||
|
||||
return perm_str;
|
||||
}
|
||||
|
||||
std::optional<fs::perms> InterpretPermString(const std::string& s)
|
||||
{
|
||||
if (s == "owner") {
|
||||
return fs::perms::owner_read | fs::perms::owner_write;
|
||||
} else if (s == "group") {
|
||||
return fs::perms::owner_read | fs::perms::owner_write |
|
||||
fs::perms::group_read;
|
||||
} else if (s == "all") {
|
||||
return fs::perms::owner_read | fs::perms::owner_write |
|
||||
fs::perms::group_read |
|
||||
fs::perms::others_read;
|
||||
} else {
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <cstdio>
|
||||
#include <iosfwd>
|
||||
#include <limits>
|
||||
#include <optional>
|
||||
|
||||
/**
|
||||
* Ensure file contents are fully committed to disk, using a platform-specific
|
||||
@@ -62,6 +63,19 @@ void ReleaseDirectoryLocks();
|
||||
bool TryCreateDirectories(const fs::path& p);
|
||||
fs::path GetDefaultDataDir();
|
||||
|
||||
/** Convert fs::perms to symbolic string of the form 'rwxrwxrwx'
|
||||
*
|
||||
* @param[in] p the perms to be converted
|
||||
* @return Symbolic permissions string
|
||||
*/
|
||||
std::string PermsToSymbolicString(fs::perms p);
|
||||
/** Interpret a custom permissions level string as fs::perms
|
||||
*
|
||||
* @param[in] s Permission level string
|
||||
* @return Permissions as fs::perms
|
||||
*/
|
||||
std::optional<fs::perms> InterpretPermString(const std::string& s);
|
||||
|
||||
#ifdef WIN32
|
||||
fs::path GetSpecialFolderPath(int nFolder, bool fCreate = true);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user