Use rustix for setgroups (#1334)
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
use anyhow::{Ok, Result};
|
use anyhow::{Ok, Result};
|
||||||
|
use core::slice::SlicePattern;
|
||||||
use getopts::Options;
|
use getopts::Options;
|
||||||
use std::env;
|
use std::env;
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
@@ -38,14 +39,15 @@ fn print_usage(program: &str, opts: Options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn set_identity(uid: u32, gid: u32, groups: &[u32]) {
|
fn set_identity(uid: u32, gid: u32, groups: &[u32]) {
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
|
||||||
unsafe {
|
|
||||||
if !groups.is_empty() {
|
|
||||||
libc::setgroups(groups.len(), groups.as_ptr());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
{
|
{
|
||||||
|
rustix::process::set_groups(
|
||||||
|
groups
|
||||||
|
.iter()
|
||||||
|
.map(|g| unsafe { Gid::from_raw(*g) })
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.as_slice(),
|
||||||
|
);
|
||||||
let gid = unsafe { Gid::from_raw(gid) };
|
let gid = unsafe { Gid::from_raw(gid) };
|
||||||
let uid = unsafe { Uid::from_raw(uid) };
|
let uid = unsafe { Uid::from_raw(uid) };
|
||||||
set_thread_res_gid(gid, gid, gid).ok();
|
set_thread_res_gid(gid, gid, gid).ok();
|
||||||
|
|||||||
Reference in New Issue
Block a user