2014-07-06 08:13:36 +00:00
|
|
|
#![crate_name = "id"]
|
2014-02-02 09:54:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the uutils coreutils package.
|
|
|
|
*
|
|
|
|
* (c) Alan Andrade <alan.andradec@gmail.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*
|
|
|
|
* Synced with:
|
|
|
|
* http://ftp-archive.freebsd.org/mirror/FreeBSD-Archive/old-releases/i386/1.0-RELEASE/ports/shellutils/src/id.c
|
|
|
|
* http://www.opensource.apple.com/source/shell_cmds/shell_cmds-118/id/id.c
|
|
|
|
*/
|
|
|
|
|
2014-03-31 16:40:21 +00:00
|
|
|
#![allow(non_camel_case_types)]
|
2014-02-16 21:29:31 +00:00
|
|
|
extern crate getopts;
|
2014-04-26 05:03:08 +00:00
|
|
|
extern crate libc;
|
2014-02-02 09:54:38 +00:00
|
|
|
|
2015-11-24 01:00:51 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate uucore;
|
|
|
|
|
2015-11-16 04:47:09 +00:00
|
|
|
use libc::{getgid, getuid, uid_t, getegid, geteuid, getlogin};
|
2015-02-22 12:58:57 +00:00
|
|
|
use std::ffi::CStr;
|
2015-05-21 02:45:43 +00:00
|
|
|
use std::io::Write;
|
2014-02-16 21:29:31 +00:00
|
|
|
use std::ptr::read;
|
2015-11-24 01:00:51 +00:00
|
|
|
use uucore::c_types::{
|
2014-02-24 05:55:01 +00:00
|
|
|
c_passwd,
|
2014-02-25 17:23:58 +00:00
|
|
|
c_group,
|
2014-06-17 12:45:10 +00:00
|
|
|
get_groups,
|
|
|
|
get_group_list,
|
2014-02-25 17:23:58 +00:00
|
|
|
get_pw_from_args,
|
|
|
|
getpwuid,
|
|
|
|
group
|
2014-02-24 05:55:01 +00:00
|
|
|
};
|
2014-02-02 09:54:38 +00:00
|
|
|
|
2014-02-16 21:29:31 +00:00
|
|
|
#[cfg(not(target_os = "linux"))]
|
|
|
|
mod audit {
|
2014-05-28 04:11:49 +00:00
|
|
|
pub use std::mem::uninitialized;
|
2014-04-26 05:03:08 +00:00
|
|
|
use libc::{uid_t, pid_t, c_int, c_uint, uint64_t, dev_t};
|
2014-02-02 09:54:38 +00:00
|
|
|
|
2014-02-19 01:10:32 +00:00
|
|
|
pub type au_id_t = uid_t;
|
|
|
|
pub type au_asid_t = pid_t;
|
|
|
|
pub type au_event_t = c_uint;
|
|
|
|
pub type au_emod_t = c_uint;
|
|
|
|
pub type au_class_t = c_int;
|
2014-02-02 09:54:38 +00:00
|
|
|
|
2014-09-23 22:42:25 +00:00
|
|
|
#[repr(C)]
|
2014-02-19 01:10:32 +00:00
|
|
|
pub struct au_mask {
|
2014-04-26 05:03:08 +00:00
|
|
|
pub am_success: c_uint,
|
|
|
|
pub am_failure: c_uint
|
2014-02-16 21:29:31 +00:00
|
|
|
}
|
2014-02-19 01:10:32 +00:00
|
|
|
pub type au_mask_t = au_mask;
|
2014-02-16 21:29:31 +00:00
|
|
|
|
2014-09-23 22:42:25 +00:00
|
|
|
#[repr(C)]
|
2014-02-19 01:10:32 +00:00
|
|
|
pub struct au_tid_addr {
|
2014-04-26 05:03:08 +00:00
|
|
|
pub port: dev_t,
|
2014-02-16 21:29:31 +00:00
|
|
|
}
|
2014-02-19 01:10:32 +00:00
|
|
|
pub type au_tid_addr_t = au_tid_addr;
|
2014-02-16 21:29:31 +00:00
|
|
|
|
2014-09-23 22:42:25 +00:00
|
|
|
#[repr(C)]
|
2014-02-19 01:10:32 +00:00
|
|
|
pub struct c_auditinfo_addr {
|
2014-04-26 05:03:08 +00:00
|
|
|
pub ai_auid: au_id_t, /* Audit user ID */
|
|
|
|
pub ai_mask: au_mask_t, /* Audit masks. */
|
|
|
|
pub ai_termid: au_tid_addr_t, /* Terminal ID. */
|
|
|
|
pub ai_asid: au_asid_t, /* Audit session ID. */
|
|
|
|
pub ai_flags: uint64_t /* Audit session flags */
|
2014-02-16 21:29:31 +00:00
|
|
|
}
|
|
|
|
pub type c_auditinfo_addr_t = c_auditinfo_addr;
|
|
|
|
|
|
|
|
extern {
|
2014-06-30 11:13:38 +00:00
|
|
|
pub fn getaudit(auditinfo_addr: *mut c_auditinfo_addr_t) -> c_int;
|
2014-02-16 21:29:31 +00:00
|
|
|
}
|
2014-02-02 09:54:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extern {
|
2014-06-30 11:13:38 +00:00
|
|
|
fn getgrgid(gid: uid_t) -> *const c_group;
|
2014-02-02 09:54:38 +00:00
|
|
|
}
|
|
|
|
|
2014-02-23 22:18:04 +00:00
|
|
|
static NAME: &'static str = "id";
|
|
|
|
|
2015-02-06 13:48:07 +00:00
|
|
|
pub fn uumain(args: Vec<String>) -> i32 {
|
2015-05-21 02:45:43 +00:00
|
|
|
let mut opts = getopts::Options::new();
|
|
|
|
opts.optflag("h", "", "Show help");
|
|
|
|
opts.optflag("A", "", "Display the process audit (not available on Linux)");
|
|
|
|
opts.optflag("G", "", "Display the different group IDs");
|
|
|
|
opts.optflag("g", "", "Display the effective group ID as a number");
|
|
|
|
opts.optflag("n", "", "Display the name of the user or group ID for the -G, -g and -u options");
|
|
|
|
opts.optflag("P", "", "Display the id as a password file entry");
|
|
|
|
opts.optflag("p", "", "Make the output human-readable");
|
|
|
|
opts.optflag("r", "", "Display the real ID for the -g and -u options");
|
|
|
|
opts.optflag("u", "", "Display the effective user ID as a number");
|
|
|
|
|
|
|
|
let matches = match opts.parse(&args[1..]) {
|
2014-02-02 09:54:38 +00:00
|
|
|
Ok(m) => { m },
|
|
|
|
Err(_) => {
|
2015-05-21 02:45:43 +00:00
|
|
|
println!("{}", opts.usage(NAME));
|
2014-06-22 14:44:31 +00:00
|
|
|
return 1;
|
2014-02-02 09:54:38 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if matches.opt_present("h") {
|
2015-05-21 02:45:43 +00:00
|
|
|
println!("{}", opts.usage(NAME));
|
2014-06-08 07:56:37 +00:00
|
|
|
return 0;
|
2014-02-02 09:54:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if matches.opt_present("A") {
|
|
|
|
auditid();
|
2014-06-08 07:56:37 +00:00
|
|
|
return 0;
|
2014-02-02 09:54:38 +00:00
|
|
|
}
|
|
|
|
|
2014-02-25 17:23:58 +00:00
|
|
|
let possible_pw = get_pw_from_args(&matches.free);
|
2014-02-02 09:54:38 +00:00
|
|
|
|
|
|
|
let nflag = matches.opt_present("n");
|
|
|
|
let uflag = matches.opt_present("u");
|
|
|
|
let gflag = matches.opt_present("g");
|
|
|
|
let rflag = matches.opt_present("r");
|
|
|
|
|
|
|
|
if gflag {
|
|
|
|
let id = if possible_pw.is_some() {
|
|
|
|
possible_pw.unwrap().pw_gid
|
|
|
|
} else {
|
|
|
|
if rflag {
|
2014-06-16 20:09:04 +00:00
|
|
|
unsafe { getgid() }
|
2014-02-02 09:54:38 +00:00
|
|
|
} else {
|
2014-06-16 20:09:04 +00:00
|
|
|
unsafe { getegid() }
|
2014-02-02 09:54:38 +00:00
|
|
|
}
|
2014-06-16 20:09:04 +00:00
|
|
|
};
|
2014-02-02 09:54:38 +00:00
|
|
|
let gr = unsafe { getgrgid(id) };
|
|
|
|
|
2015-01-10 15:48:29 +00:00
|
|
|
if nflag && !gr.is_null() {
|
2015-02-22 12:58:57 +00:00
|
|
|
let gr_name = unsafe { String::from_utf8_lossy(CStr::from_ptr(read(gr).gr_name).to_bytes()).to_string() };
|
2014-11-21 09:09:43 +00:00
|
|
|
println!("{}", gr_name);
|
2014-02-02 09:54:38 +00:00
|
|
|
} else {
|
2014-11-21 09:09:43 +00:00
|
|
|
println!("{}", id);
|
2014-02-02 09:54:38 +00:00
|
|
|
}
|
2014-06-08 07:56:37 +00:00
|
|
|
return 0;
|
2014-02-02 09:54:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if uflag {
|
|
|
|
let id = if possible_pw.is_some() {
|
|
|
|
possible_pw.unwrap().pw_uid
|
|
|
|
} else if rflag {
|
2014-06-16 20:09:04 +00:00
|
|
|
unsafe { getgid() }
|
2014-02-02 09:54:38 +00:00
|
|
|
} else {
|
2014-06-16 20:09:04 +00:00
|
|
|
unsafe { getegid() }
|
2014-02-02 09:54:38 +00:00
|
|
|
};
|
|
|
|
|
2014-02-25 17:23:58 +00:00
|
|
|
let pw = unsafe { getpwuid(id) };
|
2015-01-10 15:48:29 +00:00
|
|
|
if nflag && !pw.is_null() {
|
2014-02-02 09:54:38 +00:00
|
|
|
let pw_name = unsafe {
|
2015-02-22 12:58:57 +00:00
|
|
|
String::from_utf8_lossy(CStr::from_ptr(read(pw).pw_name).to_bytes()).to_string()
|
2014-02-02 09:54:38 +00:00
|
|
|
};
|
2014-11-21 09:09:43 +00:00
|
|
|
println!("{}", pw_name);
|
2014-02-02 09:54:38 +00:00
|
|
|
} else {
|
2014-11-21 09:09:43 +00:00
|
|
|
println!("{}", id);
|
2014-02-02 09:54:38 +00:00
|
|
|
}
|
|
|
|
|
2014-06-08 07:56:37 +00:00
|
|
|
return 0;
|
2014-02-02 09:54:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if matches.opt_present("G") {
|
|
|
|
group(possible_pw, nflag);
|
2014-06-08 07:56:37 +00:00
|
|
|
return 0;
|
2014-02-02 09:54:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if matches.opt_present("P") {
|
|
|
|
pline(possible_pw);
|
2014-06-08 07:56:37 +00:00
|
|
|
return 0;
|
2014-02-02 09:54:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if matches.opt_present("p") {
|
|
|
|
pretty(possible_pw);
|
2014-06-08 07:56:37 +00:00
|
|
|
return 0;
|
2014-02-02 09:54:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if possible_pw.is_some() {
|
2014-06-17 12:28:19 +00:00
|
|
|
id_print(possible_pw, false, false)
|
2014-02-02 09:54:38 +00:00
|
|
|
} else {
|
2014-06-17 12:28:19 +00:00
|
|
|
id_print(possible_pw, true, true)
|
2014-02-02 09:54:38 +00:00
|
|
|
}
|
2014-06-08 07:56:37 +00:00
|
|
|
|
2014-06-12 04:41:53 +00:00
|
|
|
0
|
2014-02-02 09:54:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn pretty(possible_pw: Option<c_passwd>) {
|
|
|
|
if possible_pw.is_some() {
|
|
|
|
let pw = possible_pw.unwrap();
|
|
|
|
|
2015-02-22 12:58:57 +00:00
|
|
|
let pw_name = unsafe { String::from_utf8_lossy(CStr::from_ptr(pw.pw_name).to_bytes()).to_string() };
|
2014-11-21 09:09:43 +00:00
|
|
|
print!("uid\t{}\ngroups\t", pw_name);
|
2014-02-02 09:54:38 +00:00
|
|
|
group(possible_pw, true);
|
|
|
|
} else {
|
2015-02-22 12:58:57 +00:00
|
|
|
let login = unsafe { String::from_utf8_lossy(CStr::from_ptr((getlogin() as *const i8)).to_bytes()).to_string() };
|
2014-02-02 09:54:38 +00:00
|
|
|
let rid = unsafe { getuid() };
|
2014-06-16 20:09:04 +00:00
|
|
|
let pw = unsafe { getpwuid(rid) };
|
2014-02-02 09:54:38 +00:00
|
|
|
|
|
|
|
let is_same_user = unsafe {
|
2015-02-22 12:58:57 +00:00
|
|
|
String::from_utf8_lossy(CStr::from_ptr(read(pw).pw_name).to_bytes()).to_string() == login
|
2014-02-02 09:54:38 +00:00
|
|
|
};
|
|
|
|
|
2014-02-16 21:29:31 +00:00
|
|
|
if pw.is_null() || is_same_user {
|
2014-11-21 09:09:43 +00:00
|
|
|
println!("login\t{}", login);
|
2014-02-02 09:54:38 +00:00
|
|
|
}
|
|
|
|
|
2015-01-10 15:48:29 +00:00
|
|
|
if !pw.is_null() {
|
2014-02-02 09:54:38 +00:00
|
|
|
println!(
|
2014-11-21 09:09:43 +00:00
|
|
|
"uid\t{}",
|
2015-02-22 12:58:57 +00:00
|
|
|
unsafe { String::from_utf8_lossy(CStr::from_ptr(read(pw).pw_name).to_bytes()).to_string() })
|
2014-02-02 09:54:38 +00:00
|
|
|
} else {
|
2014-11-21 09:09:43 +00:00
|
|
|
println!("uid\t{}\n", rid);
|
2014-02-02 09:54:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let eid = unsafe { getegid() };
|
|
|
|
if eid == rid {
|
2014-06-16 20:09:04 +00:00
|
|
|
let pw = unsafe { getpwuid(eid) };
|
2015-01-10 15:48:29 +00:00
|
|
|
if !pw.is_null() {
|
2014-02-02 09:54:38 +00:00
|
|
|
println!(
|
2014-11-21 09:09:43 +00:00
|
|
|
"euid\t{}",
|
2015-02-22 12:58:57 +00:00
|
|
|
unsafe { String::from_utf8_lossy(CStr::from_ptr(read(pw).pw_name).to_bytes()).to_string() });
|
2014-02-02 09:54:38 +00:00
|
|
|
} else {
|
2014-11-21 09:09:43 +00:00
|
|
|
println!("euid\t{}", eid);
|
2014-02-02 09:54:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let rid = unsafe { getgid() };
|
|
|
|
|
|
|
|
if rid != eid {
|
|
|
|
let gr = unsafe { getgrgid(rid) };
|
2015-01-10 15:48:29 +00:00
|
|
|
if !gr.is_null() {
|
2014-02-02 09:54:38 +00:00
|
|
|
println!(
|
2014-11-21 09:09:43 +00:00
|
|
|
"rgid\t{}",
|
2015-02-22 12:58:57 +00:00
|
|
|
unsafe { String::from_utf8_lossy(CStr::from_ptr(read(gr).gr_name).to_bytes()).to_string() });
|
2014-02-02 09:54:38 +00:00
|
|
|
} else {
|
2014-11-21 09:09:43 +00:00
|
|
|
println!("rgid\t{}", rid);
|
2014-02-02 09:54:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
print!("groups\t");
|
|
|
|
group(None, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-02 17:55:06 +00:00
|
|
|
#[cfg(any(target_os = "macos", target_os = "freebsd"))]
|
2014-02-02 09:54:38 +00:00
|
|
|
fn pline(possible_pw: Option<c_passwd>) {
|
|
|
|
let pw = if possible_pw.is_none() {
|
2014-06-16 21:53:33 +00:00
|
|
|
unsafe { read(getpwuid(getuid())) }
|
2014-02-02 09:54:38 +00:00
|
|
|
} else {
|
|
|
|
possible_pw.unwrap()
|
|
|
|
};
|
|
|
|
|
2015-02-22 12:58:57 +00:00
|
|
|
let pw_name = unsafe { String::from_utf8_lossy(CStr::from_ptr(pw.pw_name ).to_bytes()).to_string()};
|
|
|
|
let pw_passwd = unsafe { String::from_utf8_lossy(CStr::from_ptr(pw.pw_passwd).to_bytes()).to_string()};
|
|
|
|
let pw_class = unsafe { String::from_utf8_lossy(CStr::from_ptr(pw.pw_class ).to_bytes()).to_string()};
|
|
|
|
let pw_gecos = unsafe { String::from_utf8_lossy(CStr::from_ptr(pw.pw_gecos ).to_bytes()).to_string()};
|
|
|
|
let pw_dir = unsafe { String::from_utf8_lossy(CStr::from_ptr(pw.pw_dir ).to_bytes()).to_string()};
|
|
|
|
let pw_shell = unsafe { String::from_utf8_lossy(CStr::from_ptr(pw.pw_shell ).to_bytes()).to_string()};
|
2014-02-02 09:54:38 +00:00
|
|
|
|
|
|
|
println!(
|
2014-11-21 09:09:43 +00:00
|
|
|
"{}:{}:{}:{}:{}:{}:{}:{}:{}:{}",
|
2014-02-02 09:54:38 +00:00
|
|
|
pw_name,
|
|
|
|
pw_passwd,
|
|
|
|
pw.pw_uid,
|
|
|
|
pw.pw_gid,
|
|
|
|
pw_class,
|
|
|
|
pw.pw_change,
|
|
|
|
pw.pw_expire,
|
|
|
|
pw_gecos,
|
|
|
|
pw_dir,
|
|
|
|
pw_shell);
|
2014-06-15 10:23:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
fn pline(possible_pw: Option<c_passwd>) {
|
|
|
|
let pw = if possible_pw.is_none() {
|
2014-06-16 20:09:04 +00:00
|
|
|
unsafe { read(getpwuid(getuid())) }
|
2014-06-15 10:23:41 +00:00
|
|
|
} else {
|
|
|
|
possible_pw.unwrap()
|
|
|
|
};
|
|
|
|
|
2015-02-22 12:58:57 +00:00
|
|
|
let pw_name = unsafe { String::from_utf8_lossy(CStr::from_ptr(pw.pw_name ).to_bytes()).to_string()};
|
|
|
|
let pw_passwd = unsafe { String::from_utf8_lossy(CStr::from_ptr(pw.pw_passwd).to_bytes()).to_string()};
|
|
|
|
let pw_gecos = unsafe { String::from_utf8_lossy(CStr::from_ptr(pw.pw_gecos ).to_bytes()).to_string()};
|
|
|
|
let pw_dir = unsafe { String::from_utf8_lossy(CStr::from_ptr(pw.pw_dir ).to_bytes()).to_string()};
|
|
|
|
let pw_shell = unsafe { String::from_utf8_lossy(CStr::from_ptr(pw.pw_shell ).to_bytes()).to_string()};
|
2014-06-15 10:23:41 +00:00
|
|
|
|
|
|
|
println!(
|
2014-11-21 09:09:43 +00:00
|
|
|
"{}:{}:{}:{}:{}:{}:{}",
|
2014-06-15 10:23:41 +00:00
|
|
|
pw_name,
|
|
|
|
pw_passwd,
|
|
|
|
pw.pw_uid,
|
|
|
|
pw.pw_gid,
|
|
|
|
pw_gecos,
|
|
|
|
pw_dir,
|
|
|
|
pw_shell);
|
2014-02-02 09:54:38 +00:00
|
|
|
}
|
|
|
|
|
2014-02-16 21:29:31 +00:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
fn auditid() { }
|
|
|
|
|
|
|
|
#[cfg(not(target_os = "linux"))]
|
|
|
|
fn auditid() {
|
2014-07-01 00:28:02 +00:00
|
|
|
let mut auditinfo: audit::c_auditinfo_addr_t = unsafe { audit::uninitialized() };
|
|
|
|
let address = &mut auditinfo as *mut audit::c_auditinfo_addr_t;
|
2014-02-16 21:29:31 +00:00
|
|
|
if unsafe { audit::getaudit(address) } < 0 {
|
2014-06-17 12:48:37 +00:00
|
|
|
println!("couldn't retrieve information");
|
2014-02-02 09:54:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-21 09:09:43 +00:00
|
|
|
println!("auid={}", auditinfo.ai_auid);
|
2014-02-02 09:54:38 +00:00
|
|
|
println!("mask.success=0x{:x}", auditinfo.ai_mask.am_success);
|
|
|
|
println!("mask.failure=0x{:x}", auditinfo.ai_mask.am_failure);
|
|
|
|
println!("termid.port=0x{:x}", auditinfo.ai_termid.port);
|
2014-11-21 09:09:43 +00:00
|
|
|
println!("asid={}", auditinfo.ai_asid);
|
2014-02-02 09:54:38 +00:00
|
|
|
}
|
|
|
|
|
2015-05-21 02:45:43 +00:00
|
|
|
fn id_print(possible_pw: Option<c_passwd>, p_euid: bool, p_egid: bool) {
|
2014-02-02 09:54:38 +00:00
|
|
|
let uid;
|
|
|
|
let gid;
|
|
|
|
|
|
|
|
if possible_pw.is_some() {
|
|
|
|
uid = possible_pw.unwrap().pw_uid;
|
|
|
|
gid = possible_pw.unwrap().pw_gid;
|
|
|
|
} else {
|
2014-06-16 20:09:04 +00:00
|
|
|
uid = unsafe { getuid() };
|
|
|
|
gid = unsafe { getgid() };
|
2014-02-02 09:54:38 +00:00
|
|
|
}
|
|
|
|
|
2014-06-17 12:45:10 +00:00
|
|
|
let groups = match possible_pw {
|
2014-06-18 03:47:29 +00:00
|
|
|
Some(pw) => Ok(get_group_list(pw.pw_name, pw.pw_gid)),
|
2014-06-17 12:45:10 +00:00
|
|
|
None => get_groups(),
|
|
|
|
};
|
2014-02-02 09:54:38 +00:00
|
|
|
|
2014-06-17 12:45:10 +00:00
|
|
|
let groups = groups.unwrap_or_else(|errno| {
|
2014-11-21 09:09:43 +00:00
|
|
|
crash!(1, "failed to get group list (errno={})", errno);
|
2014-06-17 12:45:10 +00:00
|
|
|
});
|
2014-02-02 09:54:38 +00:00
|
|
|
|
|
|
|
if possible_pw.is_some() {
|
|
|
|
print!(
|
2014-11-21 09:09:43 +00:00
|
|
|
"uid={}({})",
|
2014-02-02 09:54:38 +00:00
|
|
|
uid,
|
2015-02-22 12:58:57 +00:00
|
|
|
unsafe { String::from_utf8_lossy(CStr::from_ptr(possible_pw.unwrap().pw_name).to_bytes()).to_string() });
|
2014-02-02 09:54:38 +00:00
|
|
|
} else {
|
2014-11-21 09:09:43 +00:00
|
|
|
print!("uid={}", unsafe { getuid() });
|
2014-02-02 09:54:38 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 09:09:43 +00:00
|
|
|
print!(" gid={}", gid);
|
2014-06-16 20:09:04 +00:00
|
|
|
let gr = unsafe { getgrgid(gid) };
|
2015-01-10 15:48:29 +00:00
|
|
|
if !gr.is_null() {
|
2014-02-02 09:54:38 +00:00
|
|
|
print!(
|
2014-11-21 09:09:43 +00:00
|
|
|
"({})",
|
2015-02-22 12:58:57 +00:00
|
|
|
unsafe { String::from_utf8_lossy(CStr::from_ptr(read(gr).gr_name).to_bytes()).to_string() });
|
2014-02-02 09:54:38 +00:00
|
|
|
}
|
|
|
|
|
2014-04-26 05:03:08 +00:00
|
|
|
let euid = unsafe { geteuid() };
|
2014-06-16 20:09:04 +00:00
|
|
|
if p_euid && (euid != uid) {
|
2014-11-21 09:09:43 +00:00
|
|
|
print!(" euid={}", euid);
|
2014-06-16 20:09:04 +00:00
|
|
|
let pw = unsafe { getpwuid(euid) };
|
2015-01-10 15:48:29 +00:00
|
|
|
if !pw.is_null() {
|
2014-02-02 09:54:38 +00:00
|
|
|
print!(
|
2014-11-21 09:09:43 +00:00
|
|
|
"({})",
|
2015-02-22 12:58:57 +00:00
|
|
|
unsafe { String::from_utf8_lossy(CStr::from_ptr(read(pw).pw_name).to_bytes()).to_string() });
|
2014-02-02 09:54:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let egid = unsafe { getegid() };
|
2014-06-17 12:46:02 +00:00
|
|
|
if p_egid && (egid != gid) {
|
2014-11-21 09:09:43 +00:00
|
|
|
print!(" egid={}", egid);
|
2014-02-02 09:54:38 +00:00
|
|
|
unsafe {
|
|
|
|
let grp = getgrgid(egid);
|
2015-01-10 15:48:29 +00:00
|
|
|
if !grp.is_null() {
|
2015-02-22 12:58:57 +00:00
|
|
|
print!("({})", String::from_utf8_lossy(CStr::from_ptr(read(grp).gr_name).to_bytes()).to_string());
|
2014-02-02 09:54:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-17 12:45:10 +00:00
|
|
|
if groups.len() > 0 {
|
2014-02-02 09:54:38 +00:00
|
|
|
print!(" groups=");
|
|
|
|
|
|
|
|
let mut first = true;
|
|
|
|
for &gr in groups.iter() {
|
|
|
|
if !first { print!(",") }
|
2014-11-21 09:09:43 +00:00
|
|
|
print!("{}", gr);
|
2014-06-17 12:45:10 +00:00
|
|
|
let group = unsafe { getgrgid(gr) };
|
2015-01-10 15:48:29 +00:00
|
|
|
if !group.is_null() {
|
2014-02-02 09:54:38 +00:00
|
|
|
let name = unsafe {
|
2015-02-22 12:58:57 +00:00
|
|
|
String::from_utf8_lossy(CStr::from_ptr(read(group).gr_name).to_bytes()).to_string()
|
2014-02-02 09:54:38 +00:00
|
|
|
};
|
2014-11-21 09:09:43 +00:00
|
|
|
print!("({})", name);
|
2014-02-02 09:54:38 +00:00
|
|
|
}
|
|
|
|
first = false
|
|
|
|
}
|
|
|
|
}
|
2014-06-17 12:45:10 +00:00
|
|
|
|
|
|
|
println!("");
|
2014-02-02 09:54:38 +00:00
|
|
|
}
|
2015-11-22 20:45:04 +00:00
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
fn main() {
|
|
|
|
std::process::exit(uumain(std::env::args().collect()));
|
|
|
|
}
|