1
|
1 use nix;
|
|
2
|
0
|
3 fn main() {
|
1
|
4 let uid = getuid();
|
|
5 let gid = getgid();
|
2
|
6 let login_user = getlogin(uid);
|
|
7 println!("uid: {} gid: {} name: {}", uid, gid, login_user);
|
0
|
8 }
|
1
|
9
|
2
|
10 fn getlogin(uid: u32) -> &'static str {
|
|
11 use std::ffi::CStr;
|
1
|
12 let user_passwd = unsafe { nix::libc::getpwuid(uid)};
|
|
13 let c_str = unsafe { CStr::from_ptr((*user_passwd).pw_name)} ;
|
|
14 return c_str.to_str().unwrap();
|
|
15 }
|
|
16
|
|
17 fn getuid() -> u32 {
|
|
18 let uid_struct = nix::unistd::getuid();
|
|
19 return uid_struct.as_raw();
|
|
20 }
|
|
21
|
|
22 fn getgid() -> u32 {
|
|
23 let gid_struct = nix::unistd::getgid();
|
|
24 return gid_struct.as_raw();
|
|
25 }
|