Skip to content

Commit d4a24fa

Browse files
committed
support initgroups in os module
1 parent 53ada9f commit d4a24fa

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

vm/src/stdlib/os.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,19 @@ fn os_setregid(rgid: u32, egid: u32, vm: &VirtualMachine) -> PyResult<i32> {
15121512
}
15131513
}
15141514

1515+
// cfg from nix
1516+
#[cfg(any(
1517+
target_os = "android",
1518+
target_os = "freebsd",
1519+
target_os = "linux",
1520+
target_os = "openbsd"
1521+
))]
1522+
fn os_initgroups(user_name: PyStringRef, gid: u32, vm: &VirtualMachine) -> PyResult<()> {
1523+
let user = ffi::CString::new(user_name.as_str()).unwrap();
1524+
let gid = Gid::from_raw(gid);
1525+
unistd::initgroups(&user, gid).map_err(|err| convert_nix_error(vm, err))
1526+
}
1527+
15151528
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
15161529
let ctx = &vm.ctx;
15171530

@@ -1746,6 +1759,7 @@ fn extend_module_platform_specific(vm: &VirtualMachine, module: &PyObjectRef) {
17461759
"getresuid" => ctx.new_function(os_getresuid),
17471760
"getresgid" => ctx.new_function(os_getresgid),
17481761
"setregid" => ctx.new_function(os_setregid),
1762+
"initgroups" => ctx.new_function(os_initgroups),
17491763
});
17501764

17511765
// cfg taken from nix

0 commit comments

Comments
 (0)