#![allow(unsafe_code)]
use std::io;
#[cfg(windows)]
mod windows;
#[cfg(windows)]
pub use windows::OwnerOnlySecurity;
#[cfg(windows)]
pub fn owner_only_security() -> io::Result<OwnerOnlySecurity> {
OwnerOnlySecurity::new()
}
#[cfg(not(windows))]
pub fn owner_only_security() -> io::Result<()> {
Err(unsupported())
}
#[cfg(windows)]
pub fn reject_remote_client(pipe: &impl std::os::windows::io::AsRawHandle) -> io::Result<()> {
reject_remote_client_raw(pipe.as_raw_handle())
}
#[cfg(windows)]
pub fn reject_remote_client_raw(handle: std::os::windows::raw::HANDLE) -> io::Result<()> {
windows::local_client_pid(handle).map(|_| ())
}
#[cfg(windows)]
pub(crate) use windows::local_client_pid;
#[cfg(all(windows, feature = "tokio"))]
pub fn create_end(
pipe_name: &std::ffi::OsStr,
first: bool,
) -> io::Result<tokio::net::windows::named_pipe::NamedPipeServer> {
owner_only_security()?.create_end(pipe_name, first)
}
#[cfg(not(windows))]
pub fn reject_remote_client(_pipe: &std::fs::File) -> io::Result<()> {
Err(unsupported())
}
#[cfg(windows)]
pub fn current_user_sid_string() -> io::Result<String> {
windows::current_user_sid_string()
}
#[cfg(not(windows))]
pub fn current_user_sid_string() -> io::Result<String> {
Err(unsupported())
}
#[cfg(not(windows))]
fn unsupported() -> io::Error {
io::Error::new(
io::ErrorKind::Unsupported,
"named pipes exist only on Windows",
)
}