Capabilities

Struct Capabilities 

Source
pub struct Capabilities { /* private fields */ }
Expand description

A capability set that can be manipulated.

Implementations§

Source§

impl Capabilities

Source

pub fn new() -> Result<Capabilities, Error>

Create a new empty capability set

Examples found in repository?
examples/demo.rs (line 9)
7fn main() {
8
9    let mut capability_set = Capabilities::new().unwrap();
10    capability_set.reset_all();
11
12    let flags = [Capability::CAP_CHOWN, Capability::CAP_SETUID, Capability::CAP_SYS_RESOURCE];
13
14    capability_set.update(&flags, Flag::Permitted, true);
15    capability_set.update(&flags, Flag::Effective, true);
16    capability_set.update(&[Capability::CAP_SYS_TIME], Flag::Permitted, true);
17
18    println!("Working set - {}", capability_set);
19
20    match capability_set.apply() {
21        Ok(_) => {
22            let current = Capabilities::from_current_proc().unwrap();
23            println!("Current - {}", current);
24        }
25        Err(e) => {
26            println!("Unable to apply capabilities - {}", e.to_string());
27        }
28    }
29}
Source

pub fn from_fd(fd: isize) -> Result<Capabilities, Error>

Create a capability set from the specified file descriptor

Source

pub fn from_file(path: &str) -> Result<Capabilities, Error>

Create a capability set base on the supplied file path

Source

pub fn from_pid(pid: isize) -> Result<Capabilities, Error>

Create a capability set from the supplied process ID.

Source

pub fn from_current_proc() -> Result<Capabilities, Error>

Create a capability set based on the current processes capabilities.

Examples found in repository?
examples/demo.rs (line 22)
7fn main() {
8
9    let mut capability_set = Capabilities::new().unwrap();
10    capability_set.reset_all();
11
12    let flags = [Capability::CAP_CHOWN, Capability::CAP_SETUID, Capability::CAP_SYS_RESOURCE];
13
14    capability_set.update(&flags, Flag::Permitted, true);
15    capability_set.update(&flags, Flag::Effective, true);
16    capability_set.update(&[Capability::CAP_SYS_TIME], Flag::Permitted, true);
17
18    println!("Working set - {}", capability_set);
19
20    match capability_set.apply() {
21        Ok(_) => {
22            let current = Capabilities::from_current_proc().unwrap();
23            println!("Current - {}", current);
24        }
25        Err(e) => {
26            println!("Unable to apply capabilities - {}", e.to_string());
27        }
28    }
29}
Source

pub fn reset_all(&mut self)

Clear all the entries in the capability set.

Examples found in repository?
examples/demo.rs (line 10)
7fn main() {
8
9    let mut capability_set = Capabilities::new().unwrap();
10    capability_set.reset_all();
11
12    let flags = [Capability::CAP_CHOWN, Capability::CAP_SETUID, Capability::CAP_SYS_RESOURCE];
13
14    capability_set.update(&flags, Flag::Permitted, true);
15    capability_set.update(&flags, Flag::Effective, true);
16    capability_set.update(&[Capability::CAP_SYS_TIME], Flag::Permitted, true);
17
18    println!("Working set - {}", capability_set);
19
20    match capability_set.apply() {
21        Ok(_) => {
22            let current = Capabilities::from_current_proc().unwrap();
23            println!("Current - {}", current);
24        }
25        Err(e) => {
26            println!("Unable to apply capabilities - {}", e.to_string());
27        }
28    }
29}
Source

pub fn reset_flag(&mut self, flag: Flag)

Clear all instances of the supplied flag.

Source

pub fn check(&self, cap: Capability, flag: Flag) -> bool

Check if the supplied capability has the flag set in this capability set.

Source

pub fn update(&mut self, caps: &[Capability], flag: Flag, set: bool) -> bool

Update the capability set adding the supplied capabilities. Each of the supplied capabilities will have the flag set or cleared depending on the value supplied for set.

Examples found in repository?
examples/demo.rs (line 14)
7fn main() {
8
9    let mut capability_set = Capabilities::new().unwrap();
10    capability_set.reset_all();
11
12    let flags = [Capability::CAP_CHOWN, Capability::CAP_SETUID, Capability::CAP_SYS_RESOURCE];
13
14    capability_set.update(&flags, Flag::Permitted, true);
15    capability_set.update(&flags, Flag::Effective, true);
16    capability_set.update(&[Capability::CAP_SYS_TIME], Flag::Permitted, true);
17
18    println!("Working set - {}", capability_set);
19
20    match capability_set.apply() {
21        Ok(_) => {
22            let current = Capabilities::from_current_proc().unwrap();
23            println!("Current - {}", current);
24        }
25        Err(e) => {
26            println!("Unable to apply capabilities - {}", e.to_string());
27        }
28    }
29}
Source

pub fn apply(&self) -> Result<(), Error>

Attempt to apply the capability set to the current process.

Examples found in repository?
examples/demo.rs (line 20)
7fn main() {
8
9    let mut capability_set = Capabilities::new().unwrap();
10    capability_set.reset_all();
11
12    let flags = [Capability::CAP_CHOWN, Capability::CAP_SETUID, Capability::CAP_SYS_RESOURCE];
13
14    capability_set.update(&flags, Flag::Permitted, true);
15    capability_set.update(&flags, Flag::Effective, true);
16    capability_set.update(&[Capability::CAP_SYS_TIME], Flag::Permitted, true);
17
18    println!("Working set - {}", capability_set);
19
20    match capability_set.apply() {
21        Ok(_) => {
22            let current = Capabilities::from_current_proc().unwrap();
23            println!("Current - {}", current);
24        }
25        Err(e) => {
26            println!("Unable to apply capabilities - {}", e.to_string());
27        }
28    }
29}
Source

pub fn apply_to_fd(&self, fd: i32) -> Result<(), Error>

Attempt to apply the capability set to the supplied file descriptor.

Source

pub fn apply_to_file(&self, path: &str) -> Result<(), Error>

Attempt to apply the capability set to the supplied file.

Trait Implementations§

Source§

impl Clone for Capabilities

Source§

fn clone(&self) -> Capabilities

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 Display for Capabilities

Source§

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

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

impl Drop for Capabilities

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl FromStr for Capabilities

Source§

type Err = ()

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

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

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

impl PartialEq for Capabilities

Source§

fn eq(&self, other: &Self) -> 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 Eq for Capabilities

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.