Skip to content

Commit

Permalink
Add FreeBSD, OpenBSD support for setresuid/setresgid
Browse files Browse the repository at this point in the history
  • Loading branch information
wezm committed Aug 7, 2017
1 parent 607ab97 commit c925bed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
has changed type from `c_int` to `SockProtocol`.
It accepts a `None` value for default protocol that was specified with zero using `c_int`.
([#647](https://github.com/nix-rust/nix/pull/647))
- Exposed `unistd::setresuid` and `unistd::setresgid` on FreeBSD and OpenBSD
([#721](https://github.com/nix-rust/nix/pull/721))

## [0.9.0] 2017-07-23

Expand Down
18 changes: 14 additions & 4 deletions src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ use void::Void;
use sys::stat::Mode;
use std::fmt;

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "android", target_os = "linux"))]
pub use self::linux::*;

#[cfg(any(target_os = "android", target_os = "freebsd",
target_os = "linux", target_os = "openbsd"))]
pub use self::setres::*;

/// User identifier
///
/// Newtype pattern around `uid_t` (which is just alias). It prevents bugs caused by accidentally
Expand Down Expand Up @@ -1601,12 +1605,10 @@ pub fn sysconf(var: SysconfVar) -> Result<Option<c_long>> {
}
}

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "android", target_os = "linux"))]
mod linux {
use libc;
use sys::syscall::{syscall, SYSPIVOTROOT};
use {Errno, Result, NixPath};
use super::{Uid, Gid};

pub fn pivot_root<P1: ?Sized + NixPath, P2: ?Sized + NixPath>(
new_root: &P1, put_old: &P2) -> Result<()> {
Expand All @@ -1620,6 +1622,14 @@ mod linux {

Errno::result(res).map(drop)
}
}

#[cfg(any(target_os = "android", target_os = "freebsd",
target_os = "linux", target_os = "openbsd"))]
mod setres {
use libc;
use {Errno, Result};
use super::{Uid, Gid};

/// Sets the real, effective, and saved uid.
/// ([see setresuid(2)](http://man7.org/linux/man-pages/man2/setresuid.2.html))
Expand Down

0 comments on commit c925bed

Please sign in to comment.