rust-lang / rust-lang/libs-team

Add security_attributes() to windows::OpenOptionsExt

Open
#314 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

api-change-proposal
Dominant language
Rust
Stars
178
Forks
28
Avg merge
15m
Merged PRs (30d)
1

Description

Proposal

Problem statement

There is currently no means, using std::fs, to provide SECURITY_ATTRIBUTES when opening a file. A private implementation of OpenOptions do have a security_attributes function but it is not expose through the OpenOptionExt trait. In order to provide a SECURITY_ATTRIBUTES, one must use the windows crate directly calling C ffi bindings.

Motivating examples or use cases

let file = std::fs::File::options()
    .access_mode(1179785u32) // FILE_GENERIC_READ
    .share_mode(0) // FILE_SHARE_NONE
    // no means to pass security attributes to add more security.
    .open("foo.txt").unwrap();

Solution sketch

Extends OpenOptionsExt for windows

pub trait OpenOptionsExt {
    // Required methods
    fn [access_mode](https://doc.rust-lang.org/std/os/windows/fs/trait.OpenOptionsExt.html#tymethod.access_mode)(&mut self, access: [u32](https://doc.rust-lang.org/std/primitive.u32.html)) -> [&mut Self](https://doc.rust-lang.org/std/primitive.reference.html);
    // ...

   fn security_attributes(&mut self, attributes: SECURITY_ATTRIBUTES) -> &mut Self;
}
let attributes = // ...;

let file = std::fs::File::options()
    .access_mode(1179785u32) // FILE_GENERIC_READ
    .share_mode(0) // FILE_SHARE_NONE
    .security_attributes(attributes)
    .open("foo.txt").unwrap();

Links and related work

windows_security.go

Design issue

The main design issue I see is how to provide a safe way to create security attributes.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Windows OpenOptionsExt trait and the existing private OpenOptions security_attributes implementation described in the issue. Determine a safe public representation for SECURITY_ATTRIBUTES and its ownership requirements; done means the trait exposes the capability without requiring direct windows-crate FFI, with appropriate coverage for the proposed usage.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
operating-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.