summaryrefslogtreecommitdiff
path: root/src/unistd.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/unistd.rs')
-rw-r--r--src/unistd.rs33
1 files changed, 33 insertions, 0 deletions
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<()> {