Skip to content

Commit

Permalink
Merge pull request #57 from jamesmcm/fixfileperms
Browse files Browse the repository at this point in the history
Fix config file permissions so not world readable
  • Loading branch information
jamesmcm authored Dec 21, 2020
2 parents 4acf49b + 5e57c22 commit 85cc336
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "vopono"
description = "Launch applications via VPN tunnels using temporary network namespaces"
version = "0.6.3"
version = "0.6.4"
authors = ["James McMurray <[email protected]>"]
edition = "2018"
license = "GPL-3.0-or-later"
Expand Down
14 changes: 13 additions & 1 deletion src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,26 @@ pub fn get_group(username: &str) -> anyhow::Result<String> {
}

pub fn set_config_permissions() -> anyhow::Result<()> {
use std::fs::Permissions;
use std::os::unix::fs::PermissionsExt;

let check_dir = vopono_dir()?;
let username = get_username()?;
let group = get_group(&username)?;

let file_permissions = Permissions::from_mode(0o640);
let dir_permissions = Permissions::from_mode(0o750);

let group = nix::unistd::Group::from_name(&group)?.map(|x| x.gid);
let user = nix::unistd::User::from_name(&username)?.map(|x| x.uid);
for entry in WalkDir::new(check_dir).into_iter().filter_map(|e| e.ok()) {
nix::unistd::chown(entry.path(), user, group)?;
let path = entry.path();
nix::unistd::chown(path, user, group)?;
if path.is_file() {
std::fs::set_permissions(path, file_permissions.clone())?;
} else {
std::fs::set_permissions(path, dir_permissions.clone())?;
}
}
Ok(())
}
Expand Down

0 comments on commit 85cc336

Please sign in to comment.