Skip to content

Commit 68bd04e

Browse files
authored
cuprated: private file permissions (Unix) (#562)
* set_private_global_file_permissions() * clippy expect for Windows * remove proptest-regression * add `target_os_lib` feature * use target_os_lib
1 parent a9ef306 commit 68bd04e

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

binaries/cuprated/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ cuprate-txpool = { workspace = true }
3838
cuprate-types = { workspace = true, features = ["json"] }
3939
cuprate-wire = { workspace = true }
4040

41-
4241
# TODO: after v1.0.0, remove unneeded dependencies.
4342
axum = { workspace = true, features = ["tokio", "http1", "http2"] }
4443
anyhow = { workspace = true }

binaries/cuprated/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ mod txpool;
5454
mod version;
5555

5656
fn main() {
57+
// Set global private permissions for created files.
58+
cuprate_helper::fs::set_private_global_file_permissions();
59+
5760
// Initialize global static `LazyLock` data.
5861
statics::init_lazylock_statics();
5962

helper/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ asynch = ["dep:futures", "dep:rayon"]
1717
cast = []
1818
constants = []
1919
crypto = ["dep:curve25519-dalek", "dep:monero-oxide", "std"]
20-
fs = ["dep:dirs", "std"]
20+
fs = ["dep:dirs", "std", "dep:target_os_lib"]
2121
num = []
2222
map = ["cast", "dep:monero-oxide", "dep:cuprate-constants"]
2323
time = ["dep:chrono", "std"]
@@ -45,7 +45,7 @@ serde = { workspace = true, optional = true, features = ["derive"] }
4545
[target.'cfg(windows)'.dependencies]
4646
target_os_lib = { package = "windows", version = ">=0.51", features = ["Win32_System_Threading", "Win32_Foundation"], optional = true }
4747
[target.'cfg(unix)'.dependencies]
48-
target_os_lib = { package = "libc", version = "0.2.158", optional = true }
48+
target_os_lib = { package = "libc", version = "0.2", optional = true }
4949

5050
[dev-dependencies]
5151
tokio = { workspace = true, features = ["full"] }

helper/src/fs.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,34 @@ pub fn address_book_path(cache_dir: &Path, network: Network) -> PathBuf {
230230
path_with_network(cache_dir, network).join("addressbook")
231231
}
232232

233+
// Set global private permissions for created files.
234+
//
235+
// # Unix
236+
// `rwxr-x---`
237+
//
238+
// # Windows
239+
// TODO: does nothing.
240+
#[cfg_attr(
241+
target_os = "windows",
242+
expect(
243+
clippy::missing_const_for_fn,
244+
reason = "remove when Windows is implemented"
245+
)
246+
)]
247+
pub fn set_private_global_file_permissions() {
248+
#[cfg(target_family = "unix")]
249+
// SAFETY: calling C.
250+
unsafe {
251+
target_os_lib::umask(0o027);
252+
}
253+
254+
#[cfg(target_os = "windows")]
255+
// TODO: impl for Windows.
256+
{
257+
use target_os_lib as _;
258+
}
259+
}
260+
233261
//---------------------------------------------------------------------------------------------------- Tests
234262
#[cfg(test)]
235263
mod test {

0 commit comments

Comments
 (0)