Skip to content

Commit 6e0843a

Browse files
authored
Merge pull request #6 from bgilbert/euid
*: check effective UID instead of real UID
2 parents e01f000 + 8dc619d commit 6e0843a

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/keys.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::os::unix::fs::{MetadataExt, PermissionsExt};
1919
use std::path::{Path, PathBuf};
2020

2121
use error_chain::{bail, ChainedError};
22-
use users::get_current_uid;
22+
use users::get_effective_uid;
2323

2424
use crate::errors::{Result, ResultExt};
2525

@@ -79,7 +79,7 @@ fn ensure_safe_permissions(path: &Path) -> Result<()> {
7979

8080
// owned by user or root
8181
let uid = metadata.uid();
82-
if uid != 0 && uid != get_current_uid() {
82+
if uid != 0 && uid != get_effective_uid() {
8383
bail!("bad ownership on {}: {}", path.display(), uid);
8484
}
8585

@@ -218,7 +218,7 @@ mod tests {
218218

219219
#[test]
220220
fn test_read_keys() {
221-
if get_current_uid() == 0 {
221+
if get_effective_uid() == 0 {
222222
panic!("can't run tests as root");
223223
}
224224

src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ fn run() -> Result<()> {
9090
mod tests {
9191
use super::*;
9292

93-
use users::{get_current_uid, get_current_username};
93+
use users::{get_current_username, get_effective_uid};
9494

9595
fn wrap_switch_user(username: &str) -> Result<User> {
9696
switch_user(&OsString::from(username)).map(|(u, _g)| u)
9797
}
9898

9999
#[test]
100100
fn test_switch_user() {
101-
if get_current_uid() == 0 {
101+
if get_effective_uid() == 0 {
102102
panic!("can't run tests as root");
103103
}
104104
assert_eq!(

0 commit comments

Comments
 (0)