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 29 30 31 32 33 34 35 36
|
extern crate uzers;
use std::mem::drop;
use uzers::switch::switch_user_group;
use uzers::{get_current_gid, get_current_uid, get_effective_gid, get_effective_uid, uid_t};
extern crate env_logger;
const SAMPLE_ID: uid_t = 502;
fn main() {
env_logger::init();
println!("\nInitial values:");
print_state();
println!("\nValues after switching:");
let guard = switch_user_group(SAMPLE_ID, SAMPLE_ID);
print_state();
println!("\nValues after switching back:");
drop(guard);
print_state();
}
fn print_state() {
println!(
"Current UID/GID: {}/{}",
get_current_uid(),
get_current_gid()
);
println!(
"Effective UID/GID: {}/{}",
get_effective_uid(),
get_effective_gid()
);
}
|