Skip to content

Commit 94b0d31

Browse files
senamakelmedullabot
andcommitted
fix: retain share-enforced Windows directory handles
Co-authored-by: Medulla <medulla@tinyhumans.ai>
1 parent 2094c5b commit 94b0d31

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

‎crates/tinysecurity-audit/src/windows.rs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ use windows_permissions::{
1616
wrappers,
1717
};
1818

19-
const READ_CONTROL_ATTRIBUTES: u32 = 0x0002_0080;
19+
// Metadata-only opens do not participate in NTFS share-access accounting.
20+
// FILE_LIST_DIRECTORY makes the no-delete share mode an actual rename pin.
21+
const PIN_ACCESS: u32 = 0x0002_0081;
2022
const PIN_DIRECTORY: u32 = 0x0220_0000;
2123
const OPEN_REPARSE: u32 = 0x0020_0000;
2224
const REPARSE: u32 = 0x400;
@@ -164,7 +166,7 @@ fn verify_volume(root: &str) -> Result<()> {
164166
}
165167
fn pin(path: &Path) -> Result<File> {
166168
let file = OpenOptions::new()
167-
.access_mode(READ_CONTROL_ATTRIBUTES)
169+
.access_mode(PIN_ACCESS)
168170
.share_mode(3)
169171
.custom_flags(PIN_DIRECTORY)
170172
.open(path)

‎crates/tinysecurity-audit/src/windows_tests.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub(crate) fn diagnose(path: &Path) {
2323
eprintln!("audit-stage=volume result={:?}", verify_volume(root));
2424
}
2525
let handle = match OpenOptions::new()
26-
.access_mode(READ_CONTROL_ATTRIBUTES)
26+
.access_mode(PIN_ACCESS)
2727
.share_mode(3)
2828
.custom_flags(PIN_DIRECTORY)
2929
.open(&current)
@@ -56,7 +56,7 @@ pub(crate) fn diagnose(path: &Path) {
5656
("existing-journal", "audit.journal"),
5757
] {
5858
match OpenOptions::new()
59-
.access_mode(READ_CONTROL_ATTRIBUTES)
59+
.access_mode(PIN_ACCESS)
6060
.share_mode(3)
6161
.custom_flags(OPEN_REPARSE)
6262
.open(path.join(name))

0 commit comments

Comments
 (0)