Skip to content

Commit

Permalink
fixed #966 - don't try to change config permissions unless necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeny committed Mar 23, 2024
1 parent 3207867 commit 81cefeb
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions warpgate-common/src/helpers/fs.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
use std::os::unix::prelude::PermissionsExt;
use std::path::Path;

fn maybe_apply_permissions<P: AsRef<Path>>(
path: P,
permissions: std::fs::Permissions,
) -> std::io::Result<()> {
let current = std::fs::metadata(&path)?.permissions();
if current != permissions {
std::fs::set_permissions(path, permissions)?;
}
Ok(())
}

pub fn secure_directory<P: AsRef<Path>>(path: P) -> std::io::Result<()> {
std::fs::set_permissions(path.as_ref(), std::fs::Permissions::from_mode(0o700))
maybe_apply_permissions(path.as_ref(), std::fs::Permissions::from_mode(0o700))
}

pub fn secure_file<P: AsRef<Path>>(path: P) -> std::io::Result<()> {
std::fs::set_permissions(path.as_ref(), std::fs::Permissions::from_mode(0o600))
maybe_apply_permissions(path.as_ref(), std::fs::Permissions::from_mode(0o600))
}

0 comments on commit 81cefeb

Please sign in to comment.