@@ -41,6 +41,15 @@ use crate::pyobject::{
41
41
} ;
42
42
use crate :: vm:: VirtualMachine ;
43
43
44
+ // cfg from nix
45
+ #[ cfg( any(
46
+ target_os = "android" ,
47
+ target_os = "freebsd" ,
48
+ target_os = "linux" ,
49
+ target_os = "openbsd"
50
+ ) ) ]
51
+ use crate :: pyobject:: PyIterable ;
52
+
44
53
#[ cfg( windows) ]
45
54
pub const MODULE_NAME : & str = "nt" ;
46
55
#[ cfg( not( windows) ) ]
@@ -1537,6 +1546,25 @@ fn os_initgroups(user_name: PyStringRef, gid: u32, vm: &VirtualMachine) -> PyRes
1537
1546
unistd:: initgroups ( & user, gid) . map_err ( |err| convert_nix_error ( vm, err) )
1538
1547
}
1539
1548
1549
+ // cfg from nix
1550
+ #[ cfg( any(
1551
+ target_os = "android" ,
1552
+ target_os = "freebsd" ,
1553
+ target_os = "linux" ,
1554
+ target_os = "openbsd"
1555
+ ) ) ]
1556
+ fn os_setgroups ( group_ids : PyIterable < u32 > , vm : & VirtualMachine ) -> PyResult < ( ) > {
1557
+ let gids = group_ids
1558
+ . iter ( vm) ?
1559
+ . map ( |entry| match entry {
1560
+ Ok ( id) => Ok ( unistd:: Gid :: from_raw ( id) ) ,
1561
+ Err ( err) => Err ( err) ,
1562
+ } )
1563
+ . collect :: < Result < Vec < _ > , _ > > ( ) ?;
1564
+ let ret = unistd:: setgroups ( & gids) ;
1565
+ ret. map_err ( |err| convert_nix_error ( vm, err) )
1566
+ }
1567
+
1540
1568
pub fn make_module ( vm : & VirtualMachine ) -> PyObjectRef {
1541
1569
let ctx = & vm. ctx ;
1542
1570
@@ -1772,6 +1800,7 @@ fn extend_module_platform_specific(vm: &VirtualMachine, module: &PyObjectRef) {
1772
1800
"getresgid" => ctx. new_function( os_getresgid) ,
1773
1801
"setregid" => ctx. new_function( os_setregid) ,
1774
1802
"initgroups" => ctx. new_function( os_initgroups) ,
1803
+ "setgroups" => ctx. new_function( os_setgroups) ,
1775
1804
} ) ;
1776
1805
1777
1806
// cfg taken from nix
0 commit comments