summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md2
-rw-r--r--src/unistd.rs33
2 files changed, 35 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a6f5b0fe..913d09ab 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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.
diff --git a/src/unistd.rs b/src/unistd.rs
index 2c4a92c3..4549382d 100644
--- a/src/unistd.rs
+++ b/src/unistd.rs
@@ -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};
@@ -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<()> {