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

Add setresuid and setresgid #448

Merged
merged 1 commit into from
Oct 27, 2016
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 @@ -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