Subject

Enum Subject 

Source
pub enum Subject {
    Process(Process),
    Jail(Jail),
    User(User),
    LoginClass(LoginClass),
}
Expand description

A struct representing an RCTL subject.

From rctl(8):

Subject defines the kind of entity the rule applies to. It can be either process, user, login class, or jail.

Subject ID identifies the subject. It can be user name, numerical user ID login class name, or jail name.

Variants§

§

Process(Process)

§

Jail(Jail)

§

User(User)

§

LoginClass(LoginClass)

Implementations§

Source§

impl Subject

Source

pub fn process_id(pid: pid_t) -> Self

Source

pub fn user_name(name: &str) -> Result<Self, ParseError>

Source

pub fn user_id(uid: uid_t) -> Self

Examples found in repository?
examples/serialize.rs (line 11)
8fn main() {
9    let uid = unsafe { libc::getuid() };
10
11    let subject = rctl::Subject::user_id(uid);
12
13    let serialized = serde_json::to_string(&subject).expect("Could not serialize RCTL subject.");
14
15    println!("{serialized}");
16}
More examples
Hide additional examples
examples/usage.rs (line 9)
4fn main() {
5    println!("RCTL is {}", rctl::State::check());
6
7    let uid = unsafe { libc::getuid() };
8
9    let subject = rctl::Subject::user_id(uid);
10
11    let usage = subject.usage().expect("Could not get RCTL usage");
12
13    println!("{usage:#?}");
14}
Source

pub fn login_class<S: Into<String>>(name: S) -> Self

Source

pub fn jail_name<S: Into<String>>(name: S) -> Self

Source

pub fn usage(&self) -> Result<HashMap<Resource, usize>, Error>

Get the resource usage for a specific Subject.

§Example
extern crate libc;

let uid = unsafe { libc::getuid() };
let subject = rctl::Subject::user_id(uid);

let usage = subject.usage()
    .expect("Could not get RCTL usage");

println!("{:#?}", usage);
Examples found in repository?
examples/usage.rs (line 11)
4fn main() {
5    println!("RCTL is {}", rctl::State::check());
6
7    let uid = unsafe { libc::getuid() };
8
9    let subject = rctl::Subject::user_id(uid);
10
11    let usage = subject.usage().expect("Could not get RCTL usage");
12
13    println!("{usage:#?}");
14}
Source

pub fn limits(&self) -> Result<RuleParsingIntoIter<String>, Error>

Get an IntoIterator over the rules that apply to this subject.

Trait Implementations§

Source§

impl Clone for Subject

Source§

fn clone(&self) -> Subject

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Subject

Source§

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

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

impl Display for Subject

Source§

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

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

impl<'a> From<&'a Subject> for Filter

Source§

fn from(subject: &'a Subject) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a Subject> for String

Source§

fn from(subject: &'a Subject) -> String

Converts to this type from the input type.
Source§

impl<'a> From<&'a Subject> for SubjectType

Source§

fn from(subject: &'a Subject) -> Self

Converts to this type from the input type.
Source§

impl From<Subject> for Filter

Source§

fn from(subject: Subject) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Subject

Source§

type Err = ParseError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for Subject

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Subject

Source§

fn eq(&self, other: &Subject) -> bool

Tests for self and other values to be equal, and is used by ==.
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 Serialize for Subject

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Subject

Source§

impl StructuralPartialEq for Subject

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.