Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable setresuid/setresgid on FreeBSD and OpenBSD #721

Merged
merged 1 commit into from
Aug 7, 2017
Merged
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: 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