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

Make windows fast again (on domain connected machines) #297

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
46 changes: 3 additions & 43 deletions src/meta/windows_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,49 +85,11 @@ pub fn get_file_data(path: &PathBuf) -> Result<(Owner, Permissions), io::Error>
// This structure will be returned
let owner = Owner::new(owner, group);

// Get the size and allocate bytes for a 1-sub-authority SID
// 1 sub-authority because the Windows World SID is always S-1-1-0, with
// only a single sub-authority.
//
// Assumptions: None
// "This function cannot fail"
// -- Windows Dev Center docs
let mut world_sid_len: u32 = unsafe { winapi::um::securitybaseapi::GetSidLengthRequired(1) };
let mut world_sid = vec![0u8; world_sid_len as usize];

// Assumptions:
// - world_sid_len is no larger than the number of bytes available at
// world_sid
// - world_sid is appropriately aligned (if there are strange crashes this
// might be why)
let result = unsafe {
winapi::um::securitybaseapi::CreateWellKnownSid(
winnt::WinWorldSid,
null_mut(),
world_sid.as_mut_ptr() as *mut _,
&mut world_sid_len,
)
};

if result == 0 {
// Failed to create the SID
// Assumptions: Same as the other identical calls
unsafe {
winapi::um::winbase::LocalFree(sd_ptr);
}

// Assumptions: None (GetLastError shouldn't ever fail)
return Err(io::Error::from_raw_os_error(unsafe {
winapi::um::errhandlingapi::GetLastError()
} as i32));
}

// Assumptions:
// - xxxxx_sid_ptr are valid pointers to SIDs
// - xxxxx_trustee is only valid as long as its SID pointer is
let mut owner_trustee = unsafe { trustee_from_sid(owner_sid_ptr) };
let mut group_trustee = unsafe { trustee_from_sid(group_sid_ptr) };
let mut world_trustee = unsafe { trustee_from_sid(world_sid.as_mut_ptr() as *mut _) };

// Assumptions:
// - xxxxx_trustee are still valid (including underlying SID)
Expand All @@ -136,8 +98,6 @@ pub fn get_file_data(path: &PathBuf) -> Result<(Owner, Permissions), io::Error>

let group_access_mask = unsafe { get_acl_access_mask(dacl_ptr as *mut _, &mut group_trustee) }?;

let world_access_mask = unsafe { get_acl_access_mask(dacl_ptr as *mut _, &mut world_trustee) }?;

let has_bit = |field: u32, bit: u32| field & bit != 0;

let permissions = Permissions {
Expand All @@ -149,9 +109,9 @@ pub fn get_file_data(path: &PathBuf) -> Result<(Owner, Permissions), io::Error>
group_write: has_bit(group_access_mask, winnt::FILE_GENERIC_WRITE),
group_execute: has_bit(group_access_mask, winnt::FILE_GENERIC_EXECUTE),

other_read: has_bit(world_access_mask, winnt::FILE_GENERIC_READ),
other_write: has_bit(world_access_mask, winnt::FILE_GENERIC_WRITE),
other_execute: has_bit(world_access_mask, winnt::FILE_GENERIC_EXECUTE),
other_read: false,
other_write: false,
other_execute: false,

sticky: false,
setuid: false,
Expand Down