diff options
author | Marco Conte <gliderkite@gmail.com> | 2020-02-29 10:34:11 +0000 |
---|---|---|
committer | Marco Conte <gliderkite@gmail.com> | 2020-02-29 10:34:11 +0000 |
commit | 207d892707c0811848a502a4403e50422b2b32b1 (patch) | |
tree | 64c9b47e0fa5fb18a09a5abb2067d0e2ae60b32e /src/unistd.rs | |
parent | 922d5ee118a770435b14b08ec4be6f8ae9f7c30a (diff) | |
download | nix-207d892707c0811848a502a4403e50422b2b32b1.zip |
add setfsuid and setfsgid implementation for filesystem checks
Diffstat (limited to 'src/unistd.rs')
-rw-r--r-- | src/unistd.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/unistd.rs b/src/unistd.rs index 2dd5064b..904c1c81 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -1398,6 +1398,28 @@ pub fn setgid(gid: Gid) -> Result<()> { Errno::result(res).map(drop) } +/// Set the user identity used for filesystem checks per-thread. +/// On both success and failure, this call returns the previous filesystem user +/// ID of the caller. +/// +/// See also [setfsuid(2)](http://man7.org/linux/man-pages/man2/setfsuid.2.html) +#[cfg(any(target_os = "linux", target_os = "android"))] +pub fn setfsuid(uid: Uid) -> Uid { + let prev_fsuid = unsafe { libc::setfsuid(uid.into()) }; + Uid::from_raw(prev_fsuid as uid_t) +} + +/// Set the group identity used for filesystem checks per-thread. +/// On both success and failure, this call returns the previous filesystem group +/// ID of the caller. +/// +/// See also [setfsgid(2)](http://man7.org/linux/man-pages/man2/setfsgid.2.html) +#[cfg(any(target_os = "linux", target_os = "android"))] +pub fn setfsgid(gid: Gid) -> Gid { + let prev_fsgid = unsafe { libc::setfsgid(gid.into()) }; + Gid::from_raw(prev_fsgid as gid_t) +} + /// Get the list of supplementary group IDs of the calling process. /// /// [Further reading](http://pubs.opengroup.org/onlinepubs/009695399/functions/getgroups.html) |