From b07f3752b6f72b57c05b000987b14302eefb195a Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Fri, 19 Feb 2016 17:37:53 +0300 Subject: unistd: add setuid, setgid syscalls --- src/unistd.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/unistd.rs') diff --git a/src/unistd.rs b/src/unistd.rs index a4e66618..1e3bdfb8 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -13,7 +13,7 @@ pub use self::linux::*; mod ffi { use libc::{c_char, c_int, size_t}; - pub use libc::{fork, close, read, write, pipe, ftruncate, unlink, setpgid, getegid, geteuid, getgid, getpid, getppid, getuid}; + pub use libc::{fork, close, read, write, pipe, ftruncate, unlink, setpgid, getegid, geteuid, getgid, getpid, getppid, getuid, setuid, setgid}; #[allow(improper_ctypes)] extern { @@ -369,6 +369,20 @@ pub fn getegid() -> gid_t { unsafe { ffi::getegid() } } +#[inline] +pub fn setuid(uid: uid_t) -> Result<()> { + let res = unsafe { ffi::setuid(uid) }; + + Errno::result(res).map(drop) +} + +#[inline] +pub fn setgid(gid: gid_t) -> Result<()> { + let res = unsafe { ffi::setgid(gid) }; + + Errno::result(res).map(drop) +} + #[cfg(any(target_os = "linux", target_os = "android"))] mod linux { use sys::syscall::{syscall, SYSPIVOTROOT}; -- cgit v1.2.3