Skip to content

Commit

Permalink
Auto merge of #448 - dgreid:setresuid, r=posborne
Browse files Browse the repository at this point in the history
Add setresuid and setresgid

These were both recently added to libc, add wrappers.

Signed-off-by: Dylan Reid <dgreid@chromium.org>
  • Loading branch information
homu committed Oct 27, 2016
2 parents 284c9f4 + 6c85f43 commit 8d0e312
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Added function `epoll_create1` and bitflags `EpollCreateFlags` in
`::nix::sys::epoll` in order to support `::libc::epoll_create1`.
([#410](https://github.com/nix-rust/nix/pull/410))
- Added `setresuid` and `setresgid` for Linux in `::nix::unistd`
([#448](https://github.com/nix-rust/nix/pull/448))

### Changed
- The minimum supported version of rustc is now 1.7.0.
Expand Down
33 changes: 33 additions & 0 deletions src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ pub fn mkstemp<P: ?Sized + NixPath>(template: &P) -> Result<(RawFd, PathBuf)> {

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

Expand All @@ -587,6 +588,38 @@ mod linux {
Errno::result(res).map(drop)
}

/// Sets the real, effective, and saved uid.
/// ([see setresuid(2)](http://man7.org/linux/man-pages/man2/setresuid.2.html))
///
/// * `ruid`: real user id
/// * `euid`: effective user id
/// * `suid`: saved user id
/// * returns: Ok or libc error code.
///
/// Err is returned if the user doesn't have permission to set this UID.
#[inline]
pub fn setresuid(ruid: uid_t, euid: uid_t, suid: uid_t) -> Result<()> {
let res = unsafe { libc::setresuid(ruid, euid, suid) };

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

/// Sets the real, effective, and saved gid.
/// ([see setresuid(2)](http://man7.org/linux/man-pages/man2/setresuid.2.html))
///
/// * `rgid`: real user id
/// * `egid`: effective user id
/// * `sgid`: saved user id
/// * returns: Ok or libc error code.
///
/// Err is returned if the user doesn't have permission to set this GID.
#[inline]
pub fn setresgid(rgid: gid_t, egid: gid_t, sgid: gid_t) -> Result<()> {
let res = unsafe { libc::setresgid(rgid, egid, sgid) };

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

#[inline]
#[cfg(feature = "execvpe")]
pub fn execvpe(filename: &CString, args: &[CString], env: &[CString]) -> Result<()> {
Expand Down

0 comments on commit 8d0e312

Please sign in to comment.