Skip to content

Commit 768d0e0

Browse files
committed
upgrade windows to v0.52
1 parent e06ab59 commit 768d0e0

File tree

3 files changed

+51
-35
lines changed

3 files changed

+51
-35
lines changed

Cargo.lock

Lines changed: 21 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gix-sec/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ libc = "0.2.123"
2727

2828
[target.'cfg(windows)'.dependencies]
2929
gix-path = { version = "^0.10.1", path = "../gix-path" }
30-
windows = { version = "0.48", features = [
30+
windows = { version = "0.52.0", features = [
3131
"Win32_Foundation",
3232
"Win32_Security_Authorization",
3333
"Win32_Storage_FileSystem",

gix-sec/src/identity.rs

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,14 @@ mod impl_ {
6262
use windows::{
6363
core::{Error, PCWSTR},
6464
Win32::{
65-
Foundation::{CloseHandle, BOOL, HANDLE, HLOCAL, PSID},
65+
Foundation::{CloseHandle, LocalFree, BOOL, HANDLE, HLOCAL, PSID},
6666
Security::{
6767
Authorization::{GetNamedSecurityInfoW, SE_FILE_OBJECT},
6868
CheckTokenMembership, EqualSid, GetTokenInformation, IsWellKnownSid, TokenOwner,
6969
WinBuiltinAdministratorsSid, OWNER_SECURITY_INFORMATION, PSECURITY_DESCRIPTOR, TOKEN_OWNER,
7070
TOKEN_QUERY,
7171
},
72-
System::{
73-
Memory::LocalFree,
74-
Threading::{GetCurrentProcess, GetCurrentThread, OpenProcessToken, OpenThreadToken},
75-
},
72+
System::Threading::{GetCurrentProcess, GetCurrentThread, OpenProcessToken, OpenThreadToken},
7673
},
7774
};
7875

@@ -113,43 +110,43 @@ mod impl_ {
113110
let mut token = HANDLE::default();
114111
// Use the current thread token if possible, otherwise open the process token
115112
OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, true, &mut token)
116-
.ok()
117-
.or_else(|_| OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &mut token).ok())?;
113+
.or_else(|_| OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &mut token))?;
118114

119115
let mut buffer_size = 0;
120116
let mut buffer = Vec::<u8>::new();
121-
GetTokenInformation(token, TokenOwner, None, 0, &mut buffer_size);
117+
GetTokenInformation(token, TokenOwner, None, 0, &mut buffer_size).ok();
122118
if buffer_size != 0 {
123119
buffer.resize(buffer_size as usize, 0);
124-
if GetTokenInformation(
120+
match GetTokenInformation(
125121
token,
126122
TokenOwner,
127123
Some(buffer.as_mut_ptr() as *mut std::ffi::c_void),
128124
buffer_size,
129125
&mut buffer_size,
130-
)
131-
.as_bool()
132-
{
133-
let token_owner = buffer.as_ptr() as *const TOKEN_OWNER;
134-
let token_owner = (*token_owner).Owner;
135-
136-
is_owned = EqualSid(folder_owner, token_owner).as_bool();
137-
138-
// Admin-group owned folders are considered owned by the current user, if they are in the admin group
139-
if !is_owned && IsWellKnownSid(token_owner, WinBuiltinAdministratorsSid).as_bool() {
140-
let mut is_member = BOOL::default();
141-
// TODO: re-use the handle
142-
match CheckTokenMembership(HANDLE::default(), token_owner, &mut is_member).ok() {
143-
Err(e) => err_msg = Some(format!("Couldn't check if user is an administrator: {}", e)),
144-
Ok(()) => is_owned = is_member.as_bool(),
126+
) {
127+
Ok(()) => {
128+
let token_owner = buffer.as_ptr() as *const TOKEN_OWNER;
129+
let token_owner = (*token_owner).Owner;
130+
131+
is_owned = EqualSid(folder_owner, token_owner).is_ok();
132+
133+
// Admin-group owned folders are considered owned by the current user, if they are in the admin group
134+
if !is_owned && IsWellKnownSid(token_owner, WinBuiltinAdministratorsSid).as_bool() {
135+
let mut is_member = BOOL::default();
136+
// TODO: re-use the handle
137+
match CheckTokenMembership(HANDLE::default(), token_owner, &mut is_member) {
138+
Err(e) => {
139+
err_msg = Some(format!("Couldn't check if user is an administrator: {}", e))
140+
}
141+
Ok(()) => is_owned = is_member.as_bool(),
142+
}
145143
}
146144
}
147-
} else {
148-
err_msg = format!(
149-
"Couldn't get actual token information for current process with err: {}",
150-
Error::from_win32()
151-
)
152-
.into();
145+
Err(err) => {
146+
err_msg =
147+
format!("Couldn't get actual token information for current process with err: {err}",)
148+
.into();
149+
}
153150
}
154151
} else {
155152
err_msg = format!(
@@ -158,7 +155,7 @@ mod impl_ {
158155
)
159156
.into();
160157
}
161-
CloseHandle(token);
158+
CloseHandle(token)?;
162159
} else {
163160
err_msg = format!(
164161
"Couldn't get security information for path '{}' with err {}",
@@ -167,7 +164,7 @@ mod impl_ {
167164
)
168165
.into();
169166
}
170-
LocalFree(HLOCAL(pdescriptor.0 as isize)).ok();
167+
LocalFree(HLOCAL(pdescriptor.0)).ok();
171168
}
172169

173170
err_msg.map(|msg| Err(err(msg))).unwrap_or(Ok(is_owned))

0 commit comments

Comments
 (0)