Read setuid/setgid/sticky bits

The problem here was that we were using `metadata.permissions().mode()`, which is capped at 0o777, rather than `metadata.mode()`, which exposes every bit. With this change, we can access the higher-order permission bits, and put them in the Permissions struct.
This commit is contained in:
Benjamin Sago 2017-05-30 15:29:29 +01:00
parent bd860b8fab
commit f9f7ad2230
3 changed files with 23 additions and 7 deletions

View File

@ -67,6 +67,10 @@ pub struct Permissions {
pub other_read: bool,
pub other_write: bool,
pub other_execute: bool,
pub sticky: bool,
pub setgid: bool,
pub setuid: bool,
}
/// The three pieces of information that are displayed as a single column in

View File

@ -309,19 +309,25 @@ impl<'dir> File<'dir> {
/// This files permissions, with flags for each bit.
pub fn permissions(&self) -> f::Permissions {
let bits = self.metadata.permissions().mode();
let bits = self.metadata.mode();
let has_bit = |bit| { bits & bit == bit };
f::Permissions {
user_read: has_bit(modes::USER_READ),
user_write: has_bit(modes::USER_WRITE),
user_execute: has_bit(modes::USER_EXECUTE),
group_read: has_bit(modes::GROUP_READ),
group_write: has_bit(modes::GROUP_WRITE),
group_execute: has_bit(modes::GROUP_EXECUTE),
other_read: has_bit(modes::OTHER_READ),
other_write: has_bit(modes::OTHER_WRITE),
other_execute: has_bit(modes::OTHER_EXECUTE),
sticky: has_bit(modes::STICKY),
setgid: has_bit(modes::SETGID),
setuid: has_bit(modes::SETUID),
}
}
@ -437,12 +443,18 @@ mod modes {
pub const USER_READ: Mode = libc::S_IRUSR as Mode;
pub const USER_WRITE: Mode = libc::S_IWUSR as Mode;
pub const USER_EXECUTE: Mode = libc::S_IXUSR as Mode;
pub const GROUP_READ: Mode = libc::S_IRGRP as Mode;
pub const GROUP_WRITE: Mode = libc::S_IWGRP as Mode;
pub const GROUP_EXECUTE: Mode = libc::S_IXGRP as Mode;
pub const OTHER_READ: Mode = libc::S_IROTH as Mode;
pub const OTHER_WRITE: Mode = libc::S_IWOTH as Mode;
pub const OTHER_EXECUTE: Mode = libc::S_IXOTH as Mode;
pub const STICKY: Mode = libc::S_ISVTX as Mode;
pub const SETGID: Mode = libc::S_ISGID as Mode;
pub const SETUID: Mode = libc::S_ISUID as Mode;
}

View File

@ -79,9 +79,9 @@ pub mod test {
details.colours.punctuation = Fixed(44).normal();
let bits = f::Permissions {
user_read: false, user_write: false, user_execute: false,
group_read: false, group_write: false, group_execute: false,
other_read: false, other_write: false, other_execute: false,
user_read: false, user_write: false, user_execute: false, setuid: false,
group_read: false, group_write: false, group_execute: false, setgid: false,
other_read: false, other_write: false, other_execute: false, sticky: false,
};
let expected = TextCellContents::from(vec![
@ -109,9 +109,9 @@ pub mod test {
details.colours.perms.other_execute = Fixed(109).normal();
let bits = f::Permissions {
user_read: true, user_write: true, user_execute: true,
group_read: true, group_write: true, group_execute: true,
other_read: true, other_write: true, other_execute: true,
user_read: true, user_write: true, user_execute: true, setuid: false,
group_read: true, group_write: true, group_execute: true, setgid: false,
other_read: true, other_write: true, other_execute: true, sticky: false,
};
let expected = TextCellContents::from(vec![