diff options
author | Nikolay Amiantov <ab@fmap.me> | 2016-02-19 17:37:53 +0300 |
---|---|---|
committer | Nikolay Amiantov <ab@fmap.me> | 2016-02-19 23:33:58 +0300 |
commit | b07f3752b6f72b57c05b000987b14302eefb195a (patch) | |
tree | 2cc8361c31b1b8ddfe861ca204134d831c75e480 /src/unistd.rs | |
parent | 7fa7206e9ffe4a74762e4a8c1cdc1b8a480d07bb (diff) | |
download | nix-b07f3752b6f72b57c05b000987b14302eefb195a.zip |
unistd: add setuid, setgid syscalls
Diffstat (limited to 'src/unistd.rs')
-rw-r--r-- | src/unistd.rs | 16 |
1 files changed, 15 insertions, 1 deletions
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}; |