summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-04-14 15:45:03 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-04-14 15:45:03 +0000
commitaf59a15c5e03457db7ebd1743e9ecc14bc2de2f1 (patch)
treed61dbec1e7a14578c7a72672123fea2b7a74ae07
parent54fb2cf3ee949586a52e79fec4a6c7203232b2f5 (diff)
parent24d0e11193336f5d39e2fddd5cdc60be20e164dc (diff)
downloadnix-af59a15c5e03457db7ebd1743e9ecc14bc2de2f1.zip
Merge #1044
1044: Add unistd::{seteuid,setegid} r=asomers a=jmmv This is for the benefit of those platforms that do not provide setresuid nor setresgid, like macOS. Co-authored-by: Julio Merino <julio@meroh.net>
-rw-r--r--CHANGELOG.md3
-rw-r--r--src/unistd.rs22
2 files changed, 24 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 83885f5e..b09bc709 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
([#1036](https://github.com/nix-rust/nix/pull/1036))
- Added `from_std` and `to_std` methods for `sys::socket::IpAddr`
([#1043](https://github.com/nix-rust/nix/pull/1043))
+- Added `nix::unistd:seteuid` and `nix::unistd::setegid` for those platforms that do
+ not support `setresuid` nor `setresgid` respectively.
+ ([#1044](https://github.com/nix-rust/nix/pull/1044))
### Changed
- `PollFd` event flags renamed to `PollFlags` ([#1024](https://github.com/nix-rust/nix/pull/1024/))
diff --git a/src/unistd.rs b/src/unistd.rs
index 85cec3da..c3b2b61e 100644
--- a/src/unistd.rs
+++ b/src/unistd.rs
@@ -1236,6 +1236,26 @@ pub fn getegid() -> Gid {
Gid(unsafe { libc::getegid() })
}
+/// Set the effective user ID
+///
+/// See also [seteuid(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/seteuid.html)
+#[inline]
+pub fn seteuid(euid: Uid) -> Result<()> {
+ let res = unsafe { libc::seteuid(euid.into()) };
+
+ Errno::result(res).map(drop)
+}
+
+/// Set the effective group ID
+///
+/// See also [setegid(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/setegid.html)
+#[inline]
+pub fn setegid(egid: Gid) -> Result<()> {
+ let res = unsafe { libc::setegid(egid.into()) };
+
+ Errno::result(res).map(drop)
+}
+
/// Set the user ID
///
/// See also [setuid(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/setuid.html)
@@ -1246,7 +1266,7 @@ pub fn setuid(uid: Uid) -> Result<()> {
Errno::result(res).map(drop)
}
-/// Set the user ID
+/// Set the group ID
///
/// See also [setgid(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/setgid.html)
#[inline]