Skip to content

Commit

Permalink
Use rustix for setgroups (#1334)
Browse files Browse the repository at this point in the history
  • Loading branch information
yujincheng08 authored Feb 1, 2024
1 parent f80769a commit f80d076
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions userspace/ksud/src/ksu.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::{Ok, Result};
use core::slice::SlicePattern;
use getopts::Options;
use std::env;
#[cfg(unix)]
Expand Down Expand Up @@ -38,14 +39,15 @@ fn print_usage(program: &str, opts: Options) {
}

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"))]
{
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 uid = unsafe { Uid::from_raw(uid) };
set_thread_res_gid(gid, gid, gid).ok();
Expand Down

0 comments on commit f80d076

Please sign in to comment.