Skip to content

Commit 71ed4c8

Browse files
authored
Do no allow to run dura as root (#134)
If `dura` runs as root, libgit2 will create files that will be owned by root. The repo will appear as corrupted to a non-root user.
1 parent 4dc1029 commit 71ed4c8

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

Cargo.lock

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ toml = "0.5.8"
2323
tracing = { version = "0.1.5"}
2424
tracing-subscriber = { version = "0.3", features = ["env-filter", "registry"] }
2525
walkdir = "2.3.2"
26+
sudo = "0.6.0"
2627

2728
[dev-dependencies]
2829
tempfile = "3.2.0"

src/main.rs

+15
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ use tracing_subscriber::{EnvFilter, Registry};
2020

2121
#[tokio::main]
2222
async fn main() {
23+
if !check_if_user() {
24+
eprintln!("Dura cannot be run as root, to avoid data corruption");
25+
process::exit(1);
26+
}
27+
2328
let cwd = std::env::current_dir().expect("Failed to get current directory");
2429

2530
let suffix = option_env!("DURA_VERSION_SUFFIX")
@@ -246,6 +251,16 @@ fn unwatch_dir(path: &std::path::Path) {
246251
config.save();
247252
}
248253

254+
#[cfg(all(unix))]
255+
fn check_if_user() -> bool {
256+
sudo::check() != sudo::RunningAs::Root
257+
}
258+
259+
#[cfg(target_os = "windows")]
260+
fn check_if_user() -> bool {
261+
true
262+
}
263+
249264
/// kills running dura poller
250265
///
251266
/// poller's check to make sure that their pid is the same as the pid

0 commit comments

Comments
 (0)