(
path: &Path,
expected_uid: u32,
label: &str,
)
| 323 | |
| 324 | #[cfg(unix)] |
| 325 | fn checked_directory_metadata( |
| 326 | path: &Path, |
| 327 | expected_uid: u32, |
| 328 | label: &str, |
| 329 | ) -> Result<std::fs::Metadata> { |
| 330 | let metadata = std::fs::symlink_metadata(path).map_err(|err| { |
| 331 | Error::execution(format!( |
| 332 | "failed to stat {label} '{}': {err}", |
| 333 | path.display() |
| 334 | )) |
| 335 | })?; |
| 336 | let file_type = metadata.file_type(); |
| 337 | if file_type.is_symlink() { |
| 338 | return Err(Error::execution(format!( |
| 339 | "{label} '{}' is a symlink; refusing to use it", |
| 340 | path.display() |
| 341 | ))); |
| 342 | } |
| 343 | if !file_type.is_dir() { |
| 344 | return Err(Error::execution(format!( |
| 345 | "{label} '{}' is not a directory", |
| 346 | path.display() |
| 347 | ))); |
| 348 | } |
| 349 | if metadata.uid() != expected_uid { |
| 350 | return Err(Error::execution(format!( |
| 351 | "{label} '{}' is owned by uid {} but current euid is {}", |
| 352 | path.display(), |
| 353 | metadata.uid(), |
| 354 | expected_uid |
| 355 | ))); |
| 356 | } |
| 357 | Ok(metadata) |
| 358 | } |
| 359 | |
| 360 | #[cfg(unix)] |
| 361 | fn remove_stale_socket(socket_path: &Path, expected_uid: u32) -> Result<()> { |
no outgoing calls
no test coverage detected