pub struct RestrictSelf { /* private fields */ }Expand description
Builder for calling landlock_restrict_self() without creating a
Landlock domain.
Use this when you want to configure landlock_restrict_self() flags
without creating a ruleset or a Landlock domain (e.g., muting
subdomain audit logs for nested domains).
Only log_subdomains() is available
on this builder. Domain-specific setters
(log_same_exec(),
log_new_exec()) require a
Landlock domain via RulesetCreated.
Available since Landlock ABI v7.
no_new_privs is enforced by default; call
no_new_privs(false) to opt out.
§Example
use landlock::*;
let status = RestrictSelf::default()
.log_subdomains(false)?
.apply()?;
println!("Landlock status: {:?}", status.landlock);Use set_compatibility() to control
how unsupported flags are handled.
apply() returns a RestrictSelfStatus with the
Landlock support status and the effective flag states. Its name
differs from RulesetCreated::restrict_self()
to avoid the redundant RestrictSelf::restrict_self().
Implementations§
Source§impl RestrictSelf
impl RestrictSelf
Sourcepub fn no_new_privs(self, yes: bool) -> Self
pub fn no_new_privs(self, yes: bool) -> Self
Configures whether to call prctl(PR_SET_NO_NEW_PRIVS) during
apply(). Defaults to true.
This prctl(2) call is never ignored, even if an error was
encountered while CompatLevel::SoftRequirement was set.
See RestrictSelfAttr::log_subdomains() for compat-state
behavior when toggling this setter on unsupported kernels.
Sourcepub fn apply(self) -> Result<RestrictSelfStatus, RulesetError>
pub fn apply(self) -> Result<RestrictSelfStatus, RulesetError>
Applies the configured restrict_self flags by calling
landlock_restrict_self(-1, flags).
If no_new_privs is configured (default), also calls
prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) first, since the kernel
requires no_new_privs (or CAP_SYS_ADMIN) for
landlock_restrict_self(). See
no_new_privs() to opt out.
Returns a RestrictSelfStatus with the Landlock support status.
Skips the restrict_self syscall if no flags are enforceable.
Trait Implementations§
Source§impl Compatible for RestrictSelf
impl Compatible for RestrictSelf
Source§fn set_compatibility(self, level: CompatLevel) -> Self
fn set_compatibility(self, level: CompatLevel) -> Self
set_compatibility(). Read more