pub struct UnixSocketCapability {
pub original: PathBuf,
pub resolved: PathBuf,
pub scope: SocketScope,
pub mode: UnixSocketMode,
pub source: CapabilitySource,
}Expand description
A capability granting AF_UNIX socket access on a filesystem path.
Only pathname sockets (filesystem-backed) are grantable through this
type. Abstract-namespace sockets (sun_path[0] == '\0') and unnamed
sockets are never covered by a grant — see issue #685 for the design
note. Those kinds are denied by the sandbox’s decide_network_notification
policy on Linux and have no analog on macOS.
Invariants:
path-canonicalize: canonicalised at construction. ForConnectBindgrants where the socket itself doesn’t yet exist, we canonicalise the parent directory and re-append the final component (bind creates the socket file).lib-policy-free: this is a pure data type. Policy coupling (e.g. auto-granting an impliedFsCapability) lives innono-cli.
Fields§
§original: PathBufOriginal path as specified by the caller, pre-canonicalisation.
Retained for diagnostic output and for macOS dual-path emission
(/tmp/foo.sock vs /private/tmp/foo.sock).
resolved: PathBufCanonical absolute path.
scope: SocketScopePath matching scope for this grant.
mode: UnixSocketModeWhich socket operations are permitted.
source: CapabilitySourceWhere this capability originated.
Implementations§
Source§impl UnixSocketCapability
impl UnixSocketCapability
Sourcepub fn new_file(path: impl AsRef<Path>, mode: UnixSocketMode) -> Result<Self>
pub fn new_file(path: impl AsRef<Path>, mode: UnixSocketMode) -> Result<Self>
Grant for a single socket file.
If mode == Connect, the path must already exist and must not be
a directory.
If mode == ConnectBind, the path may not yet exist (bind creates
it). In that case the parent directory must exist; canonicalisation
resolves the parent and re-appends the final path component.
Sourcepub fn new_dir(path: impl AsRef<Path>, mode: UnixSocketMode) -> Result<Self>
pub fn new_dir(path: impl AsRef<Path>, mode: UnixSocketMode) -> Result<Self>
Grant for any pathname socket directly within a directory.
Non-recursive: a socket one level deeper (e.g. <dir>/subdir/foo.sock)
is not covered. The directory itself must already exist.
Rejects the filesystem root (/) as defence-in-depth against
accidental grants that would cover sockets anywhere at top level
(cf. [validate_platform_rule]’s rejection of root-level subpath
grants for filesystem rules). Use explicit subdirectory paths.
Sourcepub fn new_dir_subtree(
path: impl AsRef<Path>,
mode: UnixSocketMode,
) -> Result<Self>
pub fn new_dir_subtree( path: impl AsRef<Path>, mode: UnixSocketMode, ) -> Result<Self>
Grant for any pathname socket within a directory subtree.
Recursive: sockets in nested subdirectories are covered. The directory itself must already exist.
Sourcepub fn covers(&self, sockaddr_path: &Path) -> bool
pub fn covers(&self, sockaddr_path: &Path) -> bool
True if sockaddr_path is covered by this grant.
- File grants:
sockaddr_path == resolvedexactly. - Direct-child directory grants:
sockaddr_path’s parent equalsresolved, component-wise (non-recursive). - Subtree directory grants:
sockaddr_pathstarts withresolved, component-wise.
Uses Path component semantics; never string prefix
(path-component-compare invariant).
Sourcepub fn is_directory(&self) -> bool
pub fn is_directory(&self) -> bool
Whether this grant is directory-backed.
Trait Implementations§
Source§impl Clone for UnixSocketCapability
impl Clone for UnixSocketCapability
Source§fn clone(&self) -> UnixSocketCapability
fn clone(&self) -> UnixSocketCapability
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more