Skip to content

Commit 727251b

Browse files
committed
api: clean up permissions APIs
1 parent d03be06 commit 727251b

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/api.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,8 @@ impl Keyring {
396396
///
397397
/// Requires the `setattr` permission on the keyring and the SysAdmin capability if the current
398398
/// user does not own the keyring.
399-
pub fn set_permissions(&mut self, perms: KeyPermissions) -> Result<()> {
400-
check_call(unsafe { keyctl_setperm(self.id, perms) }, ())
399+
pub fn set_permissions(&mut self, perms: Permission) -> Result<()> {
400+
check_call(unsafe { keyctl_setperm(self.id, perms.bits()) }, ())
401401
}
402402

403403
fn description_raw(&self) -> Result<String> {
@@ -534,7 +534,7 @@ impl Key {
534534
///
535535
/// Requires the `setattr` permission on the key and the SysAdmin capability if the current
536536
/// user does not own the key.
537-
pub fn set_permissions(&mut self, perms: KeyPermissions) -> Result<()> {
537+
pub fn set_permissions(&mut self, perms: Permission) -> Result<()> {
538538
Keyring::new_impl(self.id).set_permissions(perms)
539539
}
540540

@@ -607,7 +607,7 @@ pub struct Description {
607607
/// The group owner of the key.
608608
pub gid: libc::gid_t,
609609
/// The permissions of the key.
610-
pub perms: KeyPermissions,
610+
pub perms: Permission,
611611
/// The plaintext description of the key.
612612
pub description: String,
613613
}
@@ -628,11 +628,12 @@ impl Description {
628628
https://github.com/mathstuf/rust-keyutils: {}",
629629
desc);
630630
}
631+
let bits = KeyPermissions::from_str_radix(pieces[1], 16).unwrap();
631632
Some(Description {
632633
type_: pieces[4].to_owned(),
633634
uid: pieces[3].parse::<libc::uid_t>().unwrap(),
634635
gid: pieces[2].parse::<libc::gid_t>().unwrap(),
635-
perms: KeyPermissions::from_str_radix(pieces[1], 16).unwrap(),
636+
perms: Permission::from_bits_truncate(bits),
636637
description: pieces[0].to_owned(),
637638
})
638639
}

src/constants.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ impl From<i32> for DefaultKeyring {
126126
}
127127
}
128128

129-
/// The kernel type for representing a keyring's (or key's) permission.
129+
/// The kernel type for representing a keyring's or key's permission.
130130
///
131-
/// See `KeyringPermission`.
131+
/// See `Permission`.
132132
pub type KeyPermissions = u32;
133133

134134
bitflags! {
@@ -144,7 +144,7 @@ bitflags! {
144144
/// "possession" requires the `search` permission, association from the calling thread
145145
/// (the session, process, and thread keyrings), or is linked to from a possessed keyring. See
146146
/// `keyrings(7)` for complete details.
147-
struct KeyringPermission: key_perm_t {
147+
pub struct Permission: KeyPermissions {
148148
/// Possession allows viewing attributes about the key or keyring.
149149
const POSSESSOR_VIEW = KEY_POS_VIEW;
150150
/// Possession allows reading a key's contents or a keyring's subkeys.

0 commit comments

Comments
 (0)