config: add exe client criteria
This commit is contained in:
parent
cc734a135c
commit
a6257910bb
13 changed files with 85 additions and 2 deletions
|
|
@ -1,6 +1,7 @@
|
|||
use {
|
||||
crate::utils::{errorfmt::ErrorFmt, oserror::OsError},
|
||||
bstr::ByteSlice,
|
||||
std::os::unix::ffi::OsStrExt,
|
||||
uapi::{OwnedFd, c},
|
||||
};
|
||||
|
||||
|
|
@ -8,6 +9,7 @@ pub struct PidInfo {
|
|||
pub uid: c::uid_t,
|
||||
pub pid: c::pid_t,
|
||||
pub comm: String,
|
||||
pub exe: String,
|
||||
}
|
||||
|
||||
pub fn get_pid_info(uid: c::uid_t, pid: c::pid_t) -> PidInfo {
|
||||
|
|
@ -18,7 +20,24 @@ pub fn get_pid_info(uid: c::uid_t, pid: c::pid_t) -> PidInfo {
|
|||
"Unknown".to_string()
|
||||
}
|
||||
};
|
||||
PidInfo { uid, pid, comm }
|
||||
let exe = match std::fs::read_link(format!("/proc/{}/exe", pid)) {
|
||||
Ok(name) => name
|
||||
.as_os_str()
|
||||
.as_bytes()
|
||||
.trim_ascii_end()
|
||||
.as_bstr()
|
||||
.to_string(),
|
||||
Err(e) => {
|
||||
log::warn!("Could not read `exe` of pid {}: {}", pid, ErrorFmt(e));
|
||||
"Unknown".to_string()
|
||||
}
|
||||
};
|
||||
PidInfo {
|
||||
uid,
|
||||
pid,
|
||||
comm,
|
||||
exe,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_socket_creds(socket: &OwnedFd) -> Option<(c::uid_t, c::pid_t)> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue