pub struct KeyPermissions(_);
Expand description

Construct key permissions for use with Key::set_perms or returned by Metadata::get_perms.

Usage:

use linux_keyutils::{Permission, KeyPermissions};

let mut perms = KeyPermissions::new();
perms.set_user_perms(Permission::ALL);
perms.set_group_perms(Permission::VIEW);

Implementations§

Create a new KeyPermissions object, defaults to empty permissions

Examples found in repository?
src/permissions.rs (line 58)
57
58
59
    fn default() -> Self {
        Self::new()
    }

Construct the permissions manually

Examples found in repository?
src/metadata.rs (line 67)
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        // Begin parsing
        let mut iter = s.split(';');

        // Parse type into KeyType
        let ktype: KeyType = iter
            .next()
            .and_then(|v| v.try_into().ok())
            .ok_or(KeyError::InvalidDescription)?;

        // Parse the UID
        let uid = iter
            .next()
            .and_then(|v| v.parse().ok())
            .ok_or(KeyError::InvalidDescription)?;

        // Parse the GID
        let gid = iter
            .next()
            .and_then(|v| v.parse().ok())
            .ok_or(KeyError::InvalidDescription)?;

        // Parse the permissions
        let perms: u32 = iter
            .next()
            .and_then(|v| u32::from_str_radix(v, 16).ok())
            .ok_or(KeyError::InvalidDescription)?;

        // Copy the actual description
        let description = iter.next().ok_or(KeyError::InvalidDescription)?.to_string();

        // Create the description
        Ok(Self {
            ktype,
            uid,
            gid,
            perm: KeyPermissions::from_u32(perms),
            description,
        })
    }

Obtain the u32 bits for this set

Examples found in repository?
src/key.rs (line 129)
125
126
127
128
129
130
131
132
    pub fn set_perms(&self, perm: KeyPermissions) -> Result<(), KeyError> {
        _ = ffi::keyctl!(
            KeyCtlOperation::SetPerm,
            self.0.as_raw_id() as libc::c_ulong,
            perm.bits() as _
        )?;
        Ok(())
    }

Set the permissions available to the key’s possessor

Examples found in repository?
src/permissions.rs (line 111)
110
111
112
113
    pub fn posessor(mut self, perm: Permission) -> Self {
        self.0.set_posessor_perms(perm);
        self
    }

Set the permissions available to the key’s owning user (UID)

Examples found in repository?
src/permissions.rs (line 117)
116
117
118
119
    pub fn user(mut self, perm: Permission) -> Self {
        self.0.set_user_perms(perm);
        self
    }

Set the permissions available to the key’s owning group (GID)

Examples found in repository?
src/permissions.rs (line 123)
122
123
124
125
    pub fn group(mut self, perm: Permission) -> Self {
        self.0.set_group_perms(perm);
        self
    }

Set the permissions available to any 3rd party

Examples found in repository?
src/permissions.rs (line 129)
128
129
130
131
    pub fn world(mut self, perm: Permission) -> Self {
        self.0.set_world_perms(perm);
        self
    }

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.