Struct SecurityContext

Source
pub struct SecurityContext<'context> { /* private fields */ }
Expand description

SELinux security context.

Implementations§

Source§

impl<'context> SecurityContext<'context>

Source

pub fn is_raw_format(&self) -> bool

Return false if security context translation must be performed.

Source

pub fn as_ptr(&self) -> *const c_char

Return the managed raw pointer to c_char.

Source

pub fn as_mut_ptr(&mut self) -> *mut c_char

Return the managed raw pointer to c_char.

Source

pub fn as_bytes(&self) -> &[u8]

Return the security context’s byte slice.

Source

pub fn to_c_string(&self) -> Result<Option<Cow<'_, CStr>>>

Return the string value of this security context.

If the context is empty, then this returns Ok(None).

Source

pub fn from_c_str( c_context: &'context CStr, raw_format: bool, ) -> SecurityContext<'context>

Return the security context identified by context.

⚠️ The returned instance does NOT own the provided context. When the returned instance get dropped, it will NOT deallocate the provided context.

Source

pub fn current(raw_format: bool) -> Result<Self>

Return the security context of the current process.

See: getcon().

Source

pub fn previous(raw_format: bool) -> Result<Self>

Return the security context of the current process before the last exec.

See: getprevcon().

Source

pub fn previous_of_process( process_id: Option<pid_t>, raw_format: bool, ) -> Result<Self>

Return the security context, of the current or specified process, before the last exec.

If process_id is None, then the current process is queried.

Specifying a particular process id (process_id.is_some()) requires libselinux version 3.5 or later.

See: getprevcon(), getpidprevcon().

Source

pub fn set_as_current(&self) -> Result<()>

Set the current security context of the process to this context.

See: setcon().

Source

pub fn of_initial_kernel_context(name: &str, raw_format: bool) -> Result<Self>

Get the context of a kernel initial security identifier specified by name.

See: security_get_initial_context().

Source

pub fn of_media_type(name: &str) -> Result<Self>

Get the default SELinux security context for the specified media type from the policy.

See: matchmediacon().

Source

pub fn of_process(process_id: pid_t, raw_format: bool) -> Result<Self>

Return the process context for the specified process identifier.

See: getpidcon().

Source

pub fn to_raw_format(&self) -> Result<Self>

Perform context translation from the human-readable format (translated) to the internal system format (raw).

See: selinux_trans_to_raw_context().

Source

pub fn to_translated_format(&self) -> Result<Self>

Perform context translation from the internal system format (raw) to the human-readable format (translated).

See: selinux_raw_to_trans_context().

Source

pub fn of_se_user_with_selected_context( se_user: &str, raw_format: bool, ) -> Result<Self>

Ask the user to manually enter a context as a fallback if a list of authorized contexts could not be obtained.

See: manual_user_enter_context().

Source

pub fn default_for_se_user( se_user: &str, role: Option<&str>, level: Option<&str>, reachable_from_context: Option<&Self>, raw_format: bool, ) -> Result<Self>

Obtain a context, for the specified SELinux user identity, that is reachable from the specified reachable_from_context.

See: get_default_context(), get_default_context_with_level(), get_default_context_with_role(), get_default_context_with_rolelevel().

Source

pub fn of_next_exec(raw_format: bool) -> Result<Option<Self>>

Get the context used for executing a new process.

See: getexeccon().

Source

pub fn set_default_context_for_next_exec() -> Result<()>

Reset the context, used for the next execve() call, to the default policy behavior.

See: setexeccon().

Source

pub fn set_for_next_exec(&self) -> Result<()>

Set the context used for the next execve() call.

See: setexeccon().

Source

pub fn of_new_file_system_objects(raw_format: bool) -> Result<Option<Self>>

Get the context used for creating a new file system object.

See: getfscreatecon().

Source

pub fn set_default_context_for_new_file_system_objects() -> Result<()>

Reset the context, used for creating a new file system object, to the default policy behavior.

See: setfscreatecon().

Source

pub fn set_for_new_file_system_objects(&self, raw_format: bool) -> Result<()>

Set the context used for creating a new file system object.

See: setfscreatecon().

Source

pub fn of_new_kernel_key_rings(raw_format: bool) -> Result<Option<Self>>

Get the context used for creating a new kernel key ring.

See: getkeycreatecon().

Source

pub fn set_default_context_for_new_kernel_key_rings() -> Result<()>

Set the context, used for creating a new kernel key ring, to the default policy behavior.

See: setkeycreatecon().

Source

pub fn set_for_new_kernel_key_rings(&self, raw_format: bool) -> Result<()>

Set the context used for creating a new kernel key ring.

See: setkeycreatecon().

Source

pub fn of_new_labeled_sockets(raw_format: bool) -> Result<Option<Self>>

Get the context used for creating a new labeled network socket.

See: getsockcreatecon().

Source

pub fn set_default_context_for_new_labeled_sockets() -> Result<()>

Set the context, used for creating a new labeled network sockets, to the default policy behavior.

See: setsockcreatecon().

Source

pub fn set_for_new_labeled_sockets(&self, raw_format: bool) -> Result<()>

Set the context used for creating a new labeled network sockets.

See: setsockcreatecon().

Source

pub fn of_path( path: impl AsRef<Path>, follow_symbolic_links: bool, raw_format: bool, ) -> Result<Option<Self>>

Get the context associated with the given path in the file system.

See: lgetfilecon(), getfilecon().

Source

pub fn set_default_for_path(path: impl AsRef<Path>) -> Result<()>

Set the file context to the system defaults.

See: selinux_lsetfilecon_default().

Source

pub fn set_for_path( &self, path: impl AsRef<Path>, follow_symbolic_links: bool, raw_format: bool, ) -> Result<()>

Set the SELinux security context of a file system object.

See: lsetfilecon(), setfilecon().

Source

pub fn of_file<T>(fd: &T, raw_format: bool) -> Result<Option<Self>>
where T: AsRawFd,

Get the SELinux security context of a file system object.

See: fgetfilecon().

Source

pub fn set_for_file<T>(&self, fd: &T) -> Result<()>
where T: AsRawFd,

Set the SELinux security context of the file system object identified by an open file descriptor.

See: fsetfilecon().

Source

pub fn of_peer_socket<T>(socket: &T, raw_format: bool) -> Result<Self>
where T: AsRawFd,

Set the SELinux security context of the peer socket identified by an open file descriptor.

See: getpeercon().

Source

pub fn query_access_decision( &self, target_context: &Self, target_class: SecurityClass, requested_access: access_vector_t, ) -> Result<av_decision>

Return whether the policy permits this source context to access target_context via target_class with the requested access vector.

See: security_compute_av_flags().

Source

pub fn of_labeling_decision( &self, target_context: &Self, target_class: SecurityClass, object_name: &str, ) -> Result<Self>

Compute a context to use for labeling a new named object in a particular class based on a SID pair.

See: security_compute_create_name().

Source

pub fn of_relabeling_decision( &self, target_context: &Self, target_class: SecurityClass, ) -> Result<Self>

Compute the new context to use when relabeling an object.

See: security_compute_relabel().

Source

pub fn of_polyinstantiation_member_decision( &self, target_context: &Self, target_class: SecurityClass, ) -> Result<Self>

Compute the context to use when labeling a polyinstantiated object instance.

See: security_compute_member().

Source

pub fn validate_transition( &self, target_context: &Self, target_class: SecurityClass, new_context: &Self, ) -> Result<()>

Determine if a transition from this context to new_context using target_context as the object is valid for object class target_class.

This checks against the mlsvalidatetrans and validatetrans constraints in the loaded policy.

This function requires libselinux version 3.0 or later.

See: security_validatetrans().

Source

pub fn check(&self) -> Option<bool>

Check the validity of an SELinux context.

See: security_check_context(), is_selinux_enabled().

Source

pub fn canonicalize(&self) -> Result<Self>

Canonicalize this security context.

See: security_canonicalize_context().

Source

pub fn check_access( &self, target_context: &Self, target_class: &str, requested_permission: &str, audit_data: *mut c_void, ) -> Result<bool>

Check if this context has the access permission for the specified class on the target context.

See: selinux_check_access().

Source

pub fn check_securetty_context(&self) -> bool

Check whether a SELinux tty security context is defined as a securetty context.

See: selinux_check_securetty_context().

Source

pub fn is_customizable(&self) -> Result<bool>

Check whether SELinux context type is customizable by the administrator.

See: is_context_customizable().

Source

pub fn to_color(&self) -> Result<SecurityContextColors>

Return the color string for this SELinux security context.

See: selinux_raw_context_to_color().

Source

pub fn compare_user_insensitive(&self, other: &Self) -> Ordering

Compare this SELinux security context with another one, excluding the user component.

See: selinux_file_context_cmp().

Source

pub fn verify_file_context( path: impl AsRef<Path>, mode: Option<FileAccessMode>, ) -> Result<bool>

Compare the SELinux security context on disk to the default security context required by the policy file contexts file.

See: selinux_file_context_verify().

Trait Implementations§

Source§

impl<'context> Debug for SecurityContext<'context>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for SecurityContext<'_>

Source§

fn drop(&mut self)

See: freecon().

Source§

impl<'context> PartialEq for SecurityContext<'context>

Source§

fn eq(&self, that: &Self) -> bool

Test whether this security context is equal to another security context, potentially after canonicalizing both of them.

If a security context fails canonicalization, then it is used as is for the purpose of this equality test.

1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'context> Eq for SecurityContext<'context>

Auto Trait Implementations§

§

impl<'context> Freeze for SecurityContext<'context>

§

impl<'context> RefUnwindSafe for SecurityContext<'context>

§

impl<'context> !Send for SecurityContext<'context>

§

impl<'context> !Sync for SecurityContext<'context>

§

impl<'context> Unpin for SecurityContext<'context>

§

impl<'context> UnwindSafe for SecurityContext<'context>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.