Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion distrod/distrod-exec/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ where
{
log::debug!("distrod-exec: exec_command");
let cred = get_real_credential().with_context(|| "Failed to get the real credential.")?;
cred.drop_privilege();
let _ = cred.try_drop_privilege();

let path = CString::new(command.as_ref().as_os_str().as_bytes()).with_context(|| {
format!(
Expand Down
17 changes: 8 additions & 9 deletions distrod/libs/src/passwd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,17 @@ impl Credential {
})
}

pub fn drop_privilege(&self) {
let inner = || -> Result<()> {
nix::unistd::setgroups(&self.groups)?;
nix::unistd::setresgid(self.gid, self.gid, self.gid)?;
nix::unistd::setresuid(self.uid, self.uid, self.uid)?;
pub fn try_drop_privilege(&self) -> Result<(), nix::Error> {
nix::unistd::setgroups(&self.groups)
.and(nix::unistd::setresgid(self.gid, self.gid, self.gid))
.and(nix::unistd::setresuid(self.uid, self.uid, self.uid))
}

Ok(())
};
if inner().is_err() {
pub fn drop_privilege(&self) {
if self.try_drop_privilege().is_err() {
log::error!("Failed to drop_privilege. Aborting.");
std::process::exit(1);
}
};
}
}

Expand Down