Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add no-windows-permissions feature, to disable access/owner checks #484

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -56,3 +56,4 @@ serial_test = "0.5"

[features]
sudo = []
no-windows-permissions = []
15 changes: 8 additions & 7 deletions src/meta/mod.rs
Original file line number Diff line number Diff line change
@@ -212,14 +212,15 @@ impl Meta {
};

#[cfg(unix)]
let owner = Owner::from(&metadata);
#[cfg(unix)]
let permissions = Permissions::from(&metadata);
let (owner, permissions) = (Some(Owner::from(&metadata)), Some(Permissions::from(&metadata)));

#[cfg(all(windows, feature = "no-windows-permissions"))]
let (owner, permissions) = (None, None);

#[cfg(windows)]
#[cfg(all(windows, not(feature = "no-windows-permissions")))]
Comment on lines +217 to +220
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about checking this feature inside windows_utils.rs, so that we can keep checking unix/windows and drop the necessary to set owner and permissions as Optional, and keep the logic of Windows inside windows_utils.rs?

@meain

let (owner, permissions) = windows_utils::get_file_data(&path)?;

let file_type = FileType::new(&metadata, symlink_meta.as_ref(), &permissions);
let file_type = FileType::new(&metadata, symlink_meta.as_ref(), &permissions.unwrap_or_default());
let name = Name::new(&path, file_type);
let inode = INode::from(&metadata);
let links = Links::from(&metadata);
@@ -232,8 +233,8 @@ impl Meta {
size: Size::from(&metadata),
date: Date::from(&metadata),
indicator: Indicator::from(file_type),
owner,
permissions,
owner: owner.unwrap_or_default(),
permissions: permissions.unwrap_or_default(),
name,
file_type,
content: None,
19 changes: 17 additions & 2 deletions src/meta/owner.rs
Original file line number Diff line number Diff line change
@@ -15,6 +15,13 @@ impl Owner {
}
}

impl Default for Owner {
fn default() -> Owner
{
Owner { user: String::from(""), group: String::from("") }
}
}

#[cfg(unix)]
impl<'a> From<&'a Metadata> for Owner {
fn from(meta: &Metadata) -> Self {
@@ -37,10 +44,18 @@ impl<'a> From<&'a Metadata> for Owner {

impl Owner {
pub fn render_user(&self, colors: &Colors) -> ColoredString {
colors.colorize(self.user.clone(), &Elem::User)
if self.user.len() == 0 {
colors.colorize("?".to_owned(), &Elem::User)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as #484 (comment) mentioned, this should be -, right?

@meain

} else {
colors.colorize(self.user.clone(), &Elem::User)
}
}

pub fn render_group(&self, colors: &Colors) -> ColoredString {
colors.colorize(self.group.clone(), &Elem::Group)
if self.group.len() == 0 {
colors.colorize("?".to_owned(), &Elem::Group)
} else {
colors.colorize(self.group.clone(), &Elem::Group)
}
}
}
20 changes: 20 additions & 0 deletions src/meta/permissions.rs
Original file line number Diff line number Diff line change
@@ -103,6 +103,26 @@ impl Permissions {
}
}

impl Default for Permissions
{
fn default() -> Permissions {
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,
sticky: false,
setgid: false,
setuid: false
}
}
}

// More readable aliases for the permission bits exposed by libc.
#[allow(trivial_numeric_casts)]
#[cfg(unix)]
4 changes: 2 additions & 2 deletions src/meta/windows_utils.rs
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ use super::{Owner, Permissions};

const BUF_SIZE: u32 = 256;

pub fn get_file_data(path: &Path) -> Result<(Owner, Permissions), io::Error> {
pub fn get_file_data(path: &Path) -> Result<(Option<Owner>, Option<Permissions>), io::Error> {
// Overall design:
// This function allocates some data with GetNamedSecurityInfoW,
// manipulates it only through WinAPI calls (treating the pointers as
@@ -168,7 +168,7 @@ pub fn get_file_data(path: &Path) -> Result<(Owner, Permissions), io::Error> {
winapi::um::winbase::LocalFree(sd_ptr);
}

Ok((owner, permissions))
Ok((Some(owner), Some(permissions)))
}

/// Evaluate an ACL for a particular trustee and get its access rights