mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 20:47:46 +00:00
id: use uucore::entries
This commit is contained in:
parent
2b96f8f0c1
commit
369c2c2d83
2 changed files with 164 additions and 256 deletions
|
@ -9,8 +9,11 @@ path = "id.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
getopts = "*"
|
getopts = "*"
|
||||||
libc = "*"
|
|
||||||
uucore = { path="../uucore" }
|
[dependencies.uucore]
|
||||||
|
path = "../uucore"
|
||||||
|
default-features = false
|
||||||
|
features = ["entries", "process"]
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "id"
|
name = "id"
|
||||||
|
|
397
src/id/id.rs
397
src/id/id.rs
|
@ -1,43 +1,40 @@
|
||||||
#![crate_name = "uu_id"]
|
#![crate_name = "uu_id"]
|
||||||
|
|
||||||
/*
|
// This file is part of the uutils coreutils package.
|
||||||
* This file is part of the uutils coreutils package.
|
//
|
||||||
*
|
// (c) Alan Andrade <alan.andradec@gmail.com>
|
||||||
* (c) Alan Andrade <alan.andradec@gmail.com>
|
// (c) Jian Zeng <anonymousknight96 AT gmail.com>
|
||||||
*
|
//
|
||||||
* For the full copyright and license information, please view the LICENSE
|
// For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
// file that was distributed with this source code.
|
||||||
*
|
//
|
||||||
* Synced with:
|
// Synced with:
|
||||||
* http://ftp-archive.freebsd.org/mirror/FreeBSD-Archive/old-releases/i386/1.0-RELEASE/ports/shellutils/src/id.c
|
// 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
|
// http://www.opensource.apple.com/source/shell_cmds/shell_cmds-118/id/id.c
|
||||||
*/
|
//
|
||||||
|
|
||||||
#![allow(non_camel_case_types)]
|
#![allow(non_camel_case_types)]
|
||||||
extern crate getopts;
|
#![allow(dead_code)]
|
||||||
extern crate libc;
|
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate uucore;
|
extern crate uucore;
|
||||||
|
pub use uucore::libc;
|
||||||
use libc::{getgid, getuid, uid_t, getegid, geteuid, getlogin};
|
use uucore::libc::{getlogin, uid_t};
|
||||||
use std::ffi::CStr;
|
use uucore::entries::{self, Passwd, Group, Locate};
|
||||||
|
use uucore::process::{getgid, getuid, getegid, geteuid};
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::ptr::read;
|
use std::ffi::CStr;
|
||||||
use uucore::c_types::{
|
|
||||||
c_passwd,
|
|
||||||
c_group,
|
|
||||||
get_groups,
|
|
||||||
get_group_list,
|
|
||||||
get_pw_from_args,
|
|
||||||
getpwuid,
|
|
||||||
group
|
|
||||||
};
|
|
||||||
|
|
||||||
#[cfg(not(target_os = "linux"))]
|
macro_rules! cstr2cow {
|
||||||
|
($v:expr) => (
|
||||||
|
unsafe { CStr::from_ptr($v).to_string_lossy() }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "linu"))]
|
||||||
mod audit {
|
mod audit {
|
||||||
pub use std::mem::uninitialized;
|
pub use std::mem::uninitialized;
|
||||||
use libc::{uid_t, pid_t, c_int, c_uint, uint64_t, dev_t};
|
use super::libc::{uid_t, pid_t, c_int, c_uint, uint64_t, dev_t};
|
||||||
|
|
||||||
pub type au_id_t = uid_t;
|
pub type au_id_t = uid_t;
|
||||||
pub type au_asid_t = pid_t;
|
pub type au_asid_t = pid_t;
|
||||||
|
@ -48,7 +45,7 @@ mod audit {
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct au_mask {
|
pub struct au_mask {
|
||||||
pub am_success: c_uint,
|
pub am_success: c_uint,
|
||||||
pub am_failure: c_uint
|
pub am_failure: c_uint,
|
||||||
}
|
}
|
||||||
pub type au_mask_t = au_mask;
|
pub type au_mask_t = au_mask;
|
||||||
|
|
||||||
|
@ -60,56 +57,52 @@ mod audit {
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct c_auditinfo_addr {
|
pub struct c_auditinfo_addr {
|
||||||
pub ai_auid: au_id_t, /* Audit user ID */
|
pub ai_auid: au_id_t, // Audit user ID
|
||||||
pub ai_mask: au_mask_t, /* Audit masks. */
|
pub ai_mask: au_mask_t, // Audit masks.
|
||||||
pub ai_termid: au_tid_addr_t, /* Terminal ID. */
|
pub ai_termid: au_tid_addr_t, // Terminal ID.
|
||||||
pub ai_asid: au_asid_t, /* Audit session ID. */
|
pub ai_asid: au_asid_t, // Audit session ID.
|
||||||
pub ai_flags: uint64_t /* Audit session flags */
|
pub ai_flags: uint64_t, // Audit session flags
|
||||||
}
|
}
|
||||||
pub type c_auditinfo_addr_t = c_auditinfo_addr;
|
pub type c_auditinfo_addr_t = c_auditinfo_addr;
|
||||||
|
|
||||||
extern {
|
extern "C" {
|
||||||
pub fn getaudit(auditinfo_addr: *mut c_auditinfo_addr_t) -> c_int;
|
pub fn getaudit(auditinfo_addr: *mut c_auditinfo_addr_t) -> c_int;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern {
|
static SYNTAX: &'static str = "[OPTION]... [USER]";
|
||||||
fn getgrgid(gid: uid_t) -> *const c_group;
|
static SUMMARY: &'static str = "Print user and group information for the specified USER,\n or (when USER omitted) for the current user.";
|
||||||
}
|
|
||||||
|
|
||||||
static NAME: &'static str = "id";
|
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let mut opts = getopts::Options::new();
|
let mut opts = new_coreopts!(SYNTAX, SUMMARY, "");
|
||||||
opts.optflag("h", "", "Show help");
|
opts.optflag("A",
|
||||||
opts.optflag("A", "", "Display the process audit (not available on Linux)");
|
"",
|
||||||
|
"Display the process audit (not available on Linux)");
|
||||||
opts.optflag("G", "", "Display the different group IDs");
|
opts.optflag("G", "", "Display the different group IDs");
|
||||||
opts.optflag("g", "", "Display the effective group ID as a number");
|
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("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", "", "Display the id as a password file entry");
|
||||||
opts.optflag("p", "", "Make the output human-readable");
|
opts.optflag("p", "", "Make the output human-readable");
|
||||||
opts.optflag("r", "", "Display the real ID for the -g and -u options");
|
opts.optflag("r", "", "Display the real ID for the -g and -u options");
|
||||||
opts.optflag("u", "", "Display the effective user ID as a number");
|
opts.optflag("u", "", "Display the effective user ID as a number");
|
||||||
|
|
||||||
let matches = match opts.parse(&args[1..]) {
|
let matches = opts.parse(args);
|
||||||
Ok(m) => { m },
|
|
||||||
Err(_) => {
|
|
||||||
println!("{}", opts.usage(NAME));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if matches.opt_present("h") {
|
|
||||||
println!("{}", opts.usage(NAME));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if matches.opt_present("A") {
|
if matches.opt_present("A") {
|
||||||
auditid();
|
auditid();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
let possible_pw = get_pw_from_args(&matches.free);
|
let possible_pw = if matches.free.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
match Passwd::locate(matches.free[0].as_str()) {
|
||||||
|
Ok(p) => Some(p),
|
||||||
|
Err(_) => crash!(1, "No such user/group: {}", matches.free[0]),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let nflag = matches.opt_present("n");
|
let nflag = matches.opt_present("n");
|
||||||
let uflag = matches.opt_present("u");
|
let uflag = matches.opt_present("u");
|
||||||
|
@ -117,55 +110,57 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let rflag = matches.opt_present("r");
|
let rflag = matches.opt_present("r");
|
||||||
|
|
||||||
if gflag {
|
if gflag {
|
||||||
let id = if possible_pw.is_some() {
|
let id = possible_pw.map(|p| p.gid()).unwrap_or(if rflag {
|
||||||
possible_pw.unwrap().pw_gid
|
getgid()
|
||||||
} else {
|
} else {
|
||||||
if rflag {
|
getegid()
|
||||||
unsafe { getgid() }
|
});
|
||||||
|
println!("{}",
|
||||||
|
if nflag {
|
||||||
|
entries::gid2grp(id).unwrap_or(id.to_string())
|
||||||
} else {
|
} else {
|
||||||
unsafe { getegid() }
|
id.to_string()
|
||||||
}
|
});
|
||||||
};
|
|
||||||
let gr = unsafe { getgrgid(id) };
|
|
||||||
|
|
||||||
if nflag && !gr.is_null() {
|
|
||||||
let gr_name = unsafe { String::from_utf8_lossy(CStr::from_ptr(read(gr).gr_name).to_bytes()).to_string() };
|
|
||||||
println!("{}", gr_name);
|
|
||||||
} else {
|
|
||||||
println!("{}", id);
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if uflag {
|
if uflag {
|
||||||
let id = if possible_pw.is_some() {
|
let id = possible_pw.map(|p| p.uid()).unwrap_or(if rflag {
|
||||||
possible_pw.unwrap().pw_uid
|
getuid()
|
||||||
} else if rflag {
|
|
||||||
unsafe { getuid() }
|
|
||||||
} else {
|
} else {
|
||||||
unsafe { geteuid() }
|
geteuid()
|
||||||
};
|
});
|
||||||
|
println!("{}",
|
||||||
let pw = unsafe { getpwuid(id) };
|
if nflag {
|
||||||
if nflag && !pw.is_null() {
|
entries::uid2usr(id).unwrap_or(id.to_string())
|
||||||
let pw_name = unsafe {
|
|
||||||
String::from_utf8_lossy(CStr::from_ptr(read(pw).pw_name).to_bytes()).to_string()
|
|
||||||
};
|
|
||||||
println!("{}", pw_name);
|
|
||||||
} else {
|
} else {
|
||||||
println!("{}", id);
|
id.to_string()
|
||||||
}
|
});
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if matches.opt_present("G") {
|
if matches.opt_present("G") {
|
||||||
group(possible_pw, nflag);
|
println!("{}",
|
||||||
|
if nflag {
|
||||||
|
possible_pw.map(|p| p.belongs_to())
|
||||||
|
.unwrap_or(entries::get_groups().unwrap())
|
||||||
|
.iter()
|
||||||
|
.map(|&id| entries::gid2grp(id).unwrap())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(" ")
|
||||||
|
} else {
|
||||||
|
possible_pw.map(|p| p.belongs_to())
|
||||||
|
.unwrap_or(entries::get_groups().unwrap())
|
||||||
|
.iter()
|
||||||
|
.map(|&id| id.to_string())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(" ")
|
||||||
|
});
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if matches.opt_present("P") {
|
if matches.opt_present("P") {
|
||||||
pline(possible_pw);
|
pline(possible_pw.map(|v| v.uid()));
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -183,120 +178,86 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pretty(possible_pw: Option<c_passwd>) {
|
fn pretty(possible_pw: Option<Passwd>) {
|
||||||
if possible_pw.is_some() {
|
if let Some(p) = possible_pw {
|
||||||
let pw = possible_pw.unwrap();
|
print!("uid\t{}\ngroups\t", p.name());
|
||||||
|
println!("{}",
|
||||||
let pw_name = unsafe { String::from_utf8_lossy(CStr::from_ptr(pw.pw_name).to_bytes()).to_string() };
|
p.belongs_to().iter().map(|&gr| entries::gid2grp(gr).unwrap()).collect::<Vec<_>>().join(" "));
|
||||||
print!("uid\t{}\ngroups\t", pw_name);
|
|
||||||
group(possible_pw, true);
|
|
||||||
} else {
|
} else {
|
||||||
let login = unsafe { String::from_utf8_lossy(CStr::from_ptr((getlogin() as *const _)).to_bytes()).to_string() };
|
let login = cstr2cow!(getlogin() as *const _);
|
||||||
let rid = unsafe { getuid() };
|
let rid = getuid();
|
||||||
let pw = unsafe { getpwuid(rid) };
|
if let Ok(p) = Passwd::locate(rid) {
|
||||||
|
if login == p.name() {
|
||||||
let is_same_user = unsafe {
|
|
||||||
String::from_utf8_lossy(CStr::from_ptr(read(pw).pw_name).to_bytes()) == login
|
|
||||||
};
|
|
||||||
|
|
||||||
if pw.is_null() || is_same_user {
|
|
||||||
println!("login\t{}", login);
|
println!("login\t{}", login);
|
||||||
}
|
}
|
||||||
|
println!("uid\t{}", p.name());
|
||||||
if !pw.is_null() {
|
|
||||||
println!(
|
|
||||||
"uid\t{}",
|
|
||||||
unsafe { String::from_utf8_lossy(CStr::from_ptr(read(pw).pw_name).to_bytes()).to_string() })
|
|
||||||
} else {
|
} else {
|
||||||
println!("uid\t{}\n", rid);
|
println!("uid\t{}", rid);
|
||||||
}
|
}
|
||||||
|
|
||||||
let eid = unsafe { getegid() };
|
let eid = getegid();
|
||||||
if eid == rid {
|
if eid == rid {
|
||||||
let pw = unsafe { getpwuid(eid) };
|
if let Ok(p) = Passwd::locate(eid) {
|
||||||
if !pw.is_null() {
|
println!("euid\t{}", p.name());
|
||||||
println!(
|
|
||||||
"euid\t{}",
|
|
||||||
unsafe { String::from_utf8_lossy(CStr::from_ptr(read(pw).pw_name).to_bytes()).to_string() });
|
|
||||||
} else {
|
} else {
|
||||||
println!("euid\t{}", eid);
|
println!("euid\t{}", eid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let rid = unsafe { getgid() };
|
let rid = getgid();
|
||||||
|
|
||||||
if rid != eid {
|
if rid != eid {
|
||||||
let gr = unsafe { getgrgid(rid) };
|
if let Ok(g) = Group::locate(rid) {
|
||||||
if !gr.is_null() {
|
println!("euid\t{}", g.name());
|
||||||
println!(
|
|
||||||
"rgid\t{}",
|
|
||||||
unsafe { String::from_utf8_lossy(CStr::from_ptr(read(gr).gr_name).to_bytes()).to_string() });
|
|
||||||
} else {
|
} else {
|
||||||
println!("rgid\t{}", rid);
|
println!("euid\t{}", rid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print!("groups\t");
|
println!("groups\t{}",
|
||||||
group(None, true);
|
entries::get_groups()
|
||||||
|
.unwrap()
|
||||||
|
.iter()
|
||||||
|
.map(|&gr| entries::gid2grp(gr).unwrap())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(" "));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_os = "macos", target_os = "freebsd"))]
|
#[cfg(any(target_os = "macos", target_os = "freebsd"))]
|
||||||
fn pline(possible_pw: Option<c_passwd>) {
|
fn pline(possible_uid: Option<uid_t>) {
|
||||||
let pw = if possible_pw.is_none() {
|
let uid = possible_uid.unwrap_or(getuid());
|
||||||
unsafe { read(getpwuid(getuid())) }
|
let pw = Passwd::locate(uid).unwrap();
|
||||||
} else {
|
|
||||||
possible_pw.unwrap()
|
|
||||||
};
|
|
||||||
|
|
||||||
let pw_name = unsafe { String::from_utf8_lossy(CStr::from_ptr(pw.pw_name ).to_bytes()).to_string()};
|
println!("{}:{}:{}:{}:{}:{}:{}:{}:{}:{}",
|
||||||
let pw_passwd = unsafe { String::from_utf8_lossy(CStr::from_ptr(pw.pw_passwd).to_bytes()).to_string()};
|
pw.name(),
|
||||||
let pw_class = unsafe { String::from_utf8_lossy(CStr::from_ptr(pw.pw_class ).to_bytes()).to_string()};
|
pw.user_passwd(),
|
||||||
let pw_gecos = unsafe { String::from_utf8_lossy(CStr::from_ptr(pw.pw_gecos ).to_bytes()).to_string()};
|
pw.uid(),
|
||||||
let pw_dir = unsafe { String::from_utf8_lossy(CStr::from_ptr(pw.pw_dir ).to_bytes()).to_string()};
|
pw.gid(),
|
||||||
let pw_shell = unsafe { String::from_utf8_lossy(CStr::from_ptr(pw.pw_shell ).to_bytes()).to_string()};
|
pw.user_access_class(),
|
||||||
|
pw.passwd_change_time(),
|
||||||
println!(
|
pw.expiration(),
|
||||||
"{}:{}:{}:{}:{}:{}:{}:{}:{}:{}",
|
pw.user_info(),
|
||||||
pw_name,
|
pw.user_dir(),
|
||||||
pw_passwd,
|
pw.user_shell());
|
||||||
pw.pw_uid,
|
|
||||||
pw.pw_gid,
|
|
||||||
pw_class,
|
|
||||||
pw.pw_change,
|
|
||||||
pw.pw_expire,
|
|
||||||
pw_gecos,
|
|
||||||
pw_dir,
|
|
||||||
pw_shell);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
fn pline(possible_pw: Option<c_passwd>) {
|
fn pline(possible_uid: Option<uid_t>) {
|
||||||
let pw = if possible_pw.is_none() {
|
let uid = possible_uid.unwrap_or(getuid());
|
||||||
unsafe { read(getpwuid(getuid())) }
|
let pw = Passwd::locate(uid).unwrap();
|
||||||
} else {
|
|
||||||
possible_pw.unwrap()
|
|
||||||
};
|
|
||||||
|
|
||||||
let pw_name = unsafe { String::from_utf8_lossy(CStr::from_ptr(pw.pw_name ).to_bytes()).to_string()};
|
println!("{}:{}:{}:{}:{}:{}:{}",
|
||||||
let pw_passwd = unsafe { String::from_utf8_lossy(CStr::from_ptr(pw.pw_passwd).to_bytes()).to_string()};
|
pw.name(),
|
||||||
let pw_gecos = unsafe { String::from_utf8_lossy(CStr::from_ptr(pw.pw_gecos ).to_bytes()).to_string()};
|
pw.user_passwd(),
|
||||||
let pw_dir = unsafe { String::from_utf8_lossy(CStr::from_ptr(pw.pw_dir ).to_bytes()).to_string()};
|
pw.uid(),
|
||||||
let pw_shell = unsafe { String::from_utf8_lossy(CStr::from_ptr(pw.pw_shell ).to_bytes()).to_string()};
|
pw.gid(),
|
||||||
|
pw.user_info(),
|
||||||
println!(
|
pw.user_dir(),
|
||||||
"{}:{}:{}:{}:{}:{}:{}",
|
pw.user_shell());
|
||||||
pw_name,
|
|
||||||
pw_passwd,
|
|
||||||
pw.pw_uid,
|
|
||||||
pw.pw_gid,
|
|
||||||
pw_gecos,
|
|
||||||
pw_dir,
|
|
||||||
pw_shell);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
fn auditid() { }
|
fn auditid() {}
|
||||||
|
|
||||||
#[cfg(not(target_os = "linux"))]
|
#[cfg(not(target_os = "linux"))]
|
||||||
fn auditid() {
|
fn auditid() {
|
||||||
|
@ -314,83 +275,27 @@ fn auditid() {
|
||||||
println!("asid={}", auditinfo.ai_asid);
|
println!("asid={}", auditinfo.ai_asid);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn id_print(possible_pw: Option<c_passwd>, p_euid: bool, p_egid: bool) {
|
fn id_print(possible_pw: Option<Passwd>, p_euid: bool, p_egid: bool) {
|
||||||
let uid;
|
let (uid, gid) = possible_pw.map(|p| (p.uid(), p.gid())).unwrap_or((getuid(), getgid()));;
|
||||||
let gid;
|
|
||||||
|
|
||||||
if possible_pw.is_some() {
|
let groups = Passwd::locate(uid).unwrap().belongs_to();
|
||||||
uid = possible_pw.unwrap().pw_uid;
|
|
||||||
gid = possible_pw.unwrap().pw_gid;
|
|
||||||
} else {
|
|
||||||
uid = unsafe { getuid() };
|
|
||||||
gid = unsafe { getgid() };
|
|
||||||
}
|
|
||||||
|
|
||||||
let groups = match possible_pw {
|
print!("uid={}({})", uid, entries::uid2usr(uid).unwrap());
|
||||||
Some(pw) => Ok(get_group_list(pw.pw_name, pw.pw_gid)),
|
print!(" gid={}({})", gid, entries::gid2grp(gid).unwrap());
|
||||||
None => get_groups(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let groups = groups.unwrap_or_else(|errno| {
|
let euid = geteuid();
|
||||||
crash!(1, "failed to get group list (errno={})", errno);
|
|
||||||
});
|
|
||||||
|
|
||||||
if possible_pw.is_some() {
|
|
||||||
print!(
|
|
||||||
"uid={}({})",
|
|
||||||
uid,
|
|
||||||
unsafe { String::from_utf8_lossy(CStr::from_ptr(possible_pw.unwrap().pw_name).to_bytes()).to_string() });
|
|
||||||
} else {
|
|
||||||
print!("uid={}", unsafe { getuid() });
|
|
||||||
}
|
|
||||||
|
|
||||||
print!(" gid={}", gid);
|
|
||||||
let gr = unsafe { getgrgid(gid) };
|
|
||||||
if !gr.is_null() {
|
|
||||||
print!(
|
|
||||||
"({})",
|
|
||||||
unsafe { String::from_utf8_lossy(CStr::from_ptr(read(gr).gr_name).to_bytes()).to_string() });
|
|
||||||
}
|
|
||||||
|
|
||||||
let euid = unsafe { geteuid() };
|
|
||||||
if p_euid && (euid != uid) {
|
if p_euid && (euid != uid) {
|
||||||
print!(" euid={}", euid);
|
print!(" euid={}({})", euid, entries::uid2usr(euid).unwrap());
|
||||||
let pw = unsafe { getpwuid(euid) };
|
|
||||||
if !pw.is_null() {
|
|
||||||
print!(
|
|
||||||
"({})",
|
|
||||||
unsafe { String::from_utf8_lossy(CStr::from_ptr(read(pw).pw_name).to_bytes()).to_string() });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let egid = unsafe { getegid() };
|
let egid = getegid();
|
||||||
if p_egid && (egid != gid) {
|
if p_egid && (egid != gid) {
|
||||||
print!(" egid={}", egid);
|
print!(" egid={}({})", euid, entries::gid2grp(egid).unwrap());
|
||||||
unsafe {
|
|
||||||
let grp = getgrgid(egid);
|
|
||||||
if !grp.is_null() {
|
|
||||||
print!("({})", String::from_utf8_lossy(CStr::from_ptr(read(grp).gr_name).to_bytes()).to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !groups.is_empty() {
|
println!(" groups={}",
|
||||||
print!(" groups=");
|
groups.iter()
|
||||||
|
.map(|&gr| format!("{}({})", gr, entries::gid2grp(gr).unwrap()))
|
||||||
let mut first = true;
|
.collect::<Vec<_>>()
|
||||||
for &gr in &groups {
|
.join(","));
|
||||||
if !first { print!(",") }
|
|
||||||
print!("{}", gr);
|
|
||||||
let group = unsafe { getgrgid(gr) };
|
|
||||||
if !group.is_null() {
|
|
||||||
let name = unsafe {
|
|
||||||
String::from_utf8_lossy(CStr::from_ptr(read(group).gr_name).to_bytes()).to_string()
|
|
||||||
};
|
|
||||||
print!("({})", name);
|
|
||||||
}
|
|
||||||
first = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("");
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue