Merge pull request #1961 from mrmiywj/support_setresgid_in_os_module

Support setresgid in os module
This commit is contained in:
Aviv Palivoda authored and GitHub committed 2020-06-12 09:17:06 +03:00
commit 7a89a4bcfd
1 file changed
+19 -2
+19 -2
View File
@@ -1524,10 +1524,26 @@ fn os_getresgid(vm: &VirtualMachine) -> PyResult<(u32, u32, u32)> {
target_os = "linux",
target_os = "openbsd"
))]
fn os_setregid(rgid: u32, egid: u32, vm: &VirtualMachine) -> PyResult<i32> {
fn os_setresgid(rgid: u32, egid: u32, sgid: u32, vm: &VirtualMachine) -> PyResult<()> {
unistd::setresgid(
Gid::from_raw(rgid),
Gid::from_raw(egid),
Gid::from_raw(sgid),
)
.map_err(|err| convert_nix_error(vm, err))
}
// cfg from nix
#[cfg(any(
target_os = "android",
target_os = "freebsd",
target_os = "linux",
target_os = "openbsd"
))]
fn os_setregid(rgid: u32, egid: u32, vm: &VirtualMachine) -> PyResult<()> {
let ret = unsafe { libc::setregid(rgid, egid) };
if ret == 0 {
Ok(0)
Ok(())
} else {
Err(errno_err(vm))
}
@@ -1798,6 +1814,7 @@ fn extend_module_platform_specific(vm: &VirtualMachine, module: &PyObjectRef) {
"setresuid" => ctx.new_function(os_setresuid),
"getresuid" => ctx.new_function(os_getresuid),
"getresgid" => ctx.new_function(os_getresgid),
"setresgid" => ctx.new_function(os_setresgid),
"setregid" => ctx.new_function(os_setregid),
"initgroups" => ctx.new_function(os_initgroups),
"setgroups" => ctx.new_function(os_setgroups),