1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use clap::{App, Arg, AppSettings};
use crate::{Shell, Arguments};
use crate::errors::*;
use crate::ffi;
use libc::gid_t;
use std::result;

pub fn setgroups(_sh: &mut Shell, args: Arguments) -> Result<()> {
    let matches = App::new("setgroups")
        .setting(AppSettings::DisableVersion)
        .about("Call setgroups(2)")
        .arg(Arg::with_name("group")
            .multiple(true)
            .help("The groups that should be set")
        )
        .get_matches_from_safe(args)?;

    let groups = match matches.values_of("group") {
        Some(groups) => groups
            .map(|x| x.parse())
            .collect::<result::Result<Vec<gid_t>, _>>()?,
        None => Vec::new(),
    };

    ffi::setgroups(&groups)?;

    Ok(())
}