(
owner_pid: u32,
entrypoint_pid: u32,
identity_cache: &BinaryIdentityCache,
)
| 1413 | |
| 1414 | #[cfg(target_os = "linux")] |
| 1415 | fn resolve_owner_identity( |
| 1416 | owner_pid: u32, |
| 1417 | entrypoint_pid: u32, |
| 1418 | identity_cache: &BinaryIdentityCache, |
| 1419 | ) -> std::result::Result<ResolvedIdentity, IdentityError> { |
| 1420 | let bin_path = |
| 1421 | crate::procfs::binary_path(owner_pid.cast_signed()).map_err(|e| IdentityError { |
| 1422 | reason: format!("failed to resolve peer binary for PID {owner_pid}: {e}"), |
| 1423 | binary: None, |
| 1424 | binary_pid: Some(owner_pid), |
| 1425 | ancestors: vec![], |
| 1426 | })?; |
| 1427 | |
| 1428 | let bin_hash = identity_cache |
| 1429 | .verify_or_cache(&bin_path) |
| 1430 | .map_err(|e| IdentityError { |
| 1431 | reason: format!("binary integrity check failed: {e}"), |
| 1432 | binary: Some(bin_path.clone()), |
| 1433 | binary_pid: Some(owner_pid), |
| 1434 | ancestors: vec![], |
| 1435 | })?; |
| 1436 | |
| 1437 | let ancestors = crate::procfs::collect_ancestor_binaries(owner_pid, entrypoint_pid); |
| 1438 | |
| 1439 | for ancestor in &ancestors { |
| 1440 | identity_cache |
| 1441 | .verify_or_cache(ancestor) |
| 1442 | .map_err(|e| IdentityError { |
| 1443 | reason: format!( |
| 1444 | "ancestor integrity check failed for {}: {e}", |
| 1445 | ancestor.display() |
| 1446 | ), |
| 1447 | binary: Some(bin_path.clone()), |
| 1448 | binary_pid: Some(owner_pid), |
| 1449 | ancestors: ancestors.clone(), |
| 1450 | })?; |
| 1451 | } |
| 1452 | |
| 1453 | let mut exclude = ancestors.clone(); |
| 1454 | exclude.push(bin_path.clone()); |
| 1455 | let cmdline_paths = crate::procfs::collect_cmdline_paths(owner_pid, entrypoint_pid, &exclude); |
| 1456 | |
| 1457 | Ok(ResolvedIdentity { |
| 1458 | bin_path, |
| 1459 | binary_pid: owner_pid, |
| 1460 | ancestors, |
| 1461 | cmdline_paths, |
| 1462 | bin_hash, |
| 1463 | }) |
| 1464 | } |
| 1465 | |
| 1466 | /// Resolve the identity of the process owning a TCP peer connection. |
| 1467 | /// |
no test coverage detected