From f5a0bcc5deac78f6dccf27febad4376bff72f760 Mon Sep 17 00:00:00 2001 From: mrmiywj Date: Tue, 9 Jun 2020 23:49:29 -0700 Subject: [PATCH 1/2] support setresgid in os module --- vm/src/stdlib/os.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/vm/src/stdlib/os.rs b/vm/src/stdlib/os.rs index 05b0f985c..f9754c785 100644 --- a/vm/src/stdlib/os.rs +++ b/vm/src/stdlib/os.rs @@ -1524,7 +1524,23 @@ 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 { +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<(i32)> { let ret = unsafe { libc::setregid(rgid, egid) }; if ret == 0 { Ok(0) @@ -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), From 6a1d7a8d11edf8e98c56c0b6a21af158910f4afd Mon Sep 17 00:00:00 2001 From: mrmiywj Date: Wed, 10 Jun 2020 00:07:15 -0700 Subject: [PATCH 2/2] return None if setregid success --- vm/src/stdlib/os.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vm/src/stdlib/os.rs b/vm/src/stdlib/os.rs index f9754c785..0c2ffabf8 100644 --- a/vm/src/stdlib/os.rs +++ b/vm/src/stdlib/os.rs @@ -1530,7 +1530,7 @@ fn os_setresgid(rgid: u32, egid: u32, sgid: u32, vm: &VirtualMachine) -> PyResul Gid::from_raw(egid), Gid::from_raw(sgid), ) - .map_err(|err| convert_nix_error(vm, err)); + .map_err(|err| convert_nix_error(vm, err)) } // cfg from nix @@ -1540,10 +1540,10 @@ fn os_setresgid(rgid: u32, egid: u32, sgid: u32, vm: &VirtualMachine) -> PyResul target_os = "linux", target_os = "openbsd" ))] -fn os_setregid(rgid: u32, egid: u32, vm: &VirtualMachine) -> PyResult<(i32)> { +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)) }