Files
proxy-suite-flake/windows/crates/ps-service/src/components.rs
T
faumarayandClaude Opus 5.5 d678976c2d windows: protect the state directory, names that become files, logs
The state directory gets a protected DACL (SYSTEM and Administrators)
at every start; on Windows programs run only from its bin\, never from
PATH; rule-set and geodata names are validated before they become file
names, and checked again where they do; logs need the secrets scope.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 23:16:40 +03:00

45 lines
1.3 KiB
Rust

//! Where the backend programs are.
//!
//! The service installs each into `bin\<component>\` (the component manager); a program
//! found there wins. Elsewhere (development on Linux) the one on PATH is taken.
use std::path::{Path, PathBuf};
pub struct Components {
bin: PathBuf,
}
impl Components {
pub fn new(bin: PathBuf) -> Self {
Self { bin }
}
/// The program `name` (without `.exe`) of `component`. On Windows only the protected
/// `bin\` counts: what the service runs, it runs as SYSTEM, and PATH may hold a directory
/// any user can write.
pub fn find(&self, component: &str, name: &str) -> Option<PathBuf> {
let file = if cfg!(windows) { format!("{name}.exe") } else { name.to_owned() };
let installed = self.bin.join(component).join(&file);
if installed.is_file() {
return Some(installed);
}
if cfg!(windows) {
return None;
}
let path = std::env::var_os("PATH")?;
std::env::split_paths(&path).map(|dir| dir.join(&file)).find(|p| p.is_file())
}
pub fn sing_box(&self) -> Option<PathBuf> {
self.find("sing-box", "sing-box")
}
pub fn xray(&self) -> Option<PathBuf> {
self.find("xray", "xray")
}
pub fn bin_dir(&self) -> &Path {
&self.bin
}
}