/// Credentials of a process. #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pubstruct UCred { /// PID (process ID) of the process.
pid: Option<unix::pid_t>, /// UID (user ID) of the process.
uid: unix::uid_t, /// GID (group ID) of the process.
gid: unix::gid_t,
}
impl UCred { /// Gets UID (user ID) of the process. pubfn uid(&self) -> unix::uid_t { self.uid
}
/// Gets GID (group ID) of the process. pubfn gid(&self) -> unix::gid_t { self.gid
}
/// Gets PID (process ID) of the process. /// /// This is only implemented under Linux, Android, iOS, macOS, Solaris and /// Illumos. On other platforms this will always return `None`. pubfn pid(&self) -> Option<unix::pid_t> { self.pid
}
}
use libc::{c_void, getpeereid, getsockopt, pid_t, LOCAL_PEEREPID, SOL_LOCAL}; use std::io; use std::mem::size_of; use std::mem::MaybeUninit; use std::os::unix::io::AsRawFd;
if getsockopt(
raw_fd,
SOL_LOCAL,
LOCAL_PEEREPID,
pid.as_mut_ptr() as *mut c_void,
pid_size.as_mut_ptr(),
) != 0
{ return Err(io::Error::last_os_error());
}
assert!(pid_size.assume_init() == (size_of::<pid_t>() as u32));
let ret = getpeereid(raw_fd, uid.as_mut_ptr(), gid.as_mut_ptr());
if ret == 0 {
Ok(super::UCred {
uid: uid.assume_init() as unix::uid_t,
gid: gid.assume_init() as unix::gid_t,
pid: Some(pid.assume_init() as unix::pid_t),
})
} else {
Err(io::Error::last_os_error())
}
}
}
}
#[cfg(any(target_os = "solaris", target_os = "illumos"))] pub(crate) mod impl_solaris { usecrate::net::unix::{self, UnixStream}; use std::io; use std::os::unix::io::AsRawFd; use std::ptr;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.