Skip to content

Commit e385ea6

Browse files
authored
fix: resolve Rust 1.90.0 compatibility issue with TOKEN_USER handling (#9)
* fix: resolve Rust 1.90.0 compatibility issue with TOKEN_USER handling * fix: lint * fix
1 parent f8ef453 commit e385ea6

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

src/command/commands.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ impl Fallible for Write<'_> {
110110

111111
/// Update various properties on a placeholder.
112112
#[derive(Debug)]
113+
#[allow(dead_code)]
113114
pub struct Update<'a> {
114115
/// Whether or not to mark the placeholder as "synced."
115116
pub mark_in_sync: bool,

src/ext/file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl SyncRootInfo {
9292
// unsafe { &*self.info }.HydrationPolicy.Primary.into()
9393
// }
9494

95-
/// The hydration type of the sync root.
95+
// /// The hydration type of the sync root.
9696
// pub fn hydration_type(&self) -> HydrationPolicy {
9797
// unsafe { &*self.info }.HydrationPolicy.Modifier.into()
9898
// }

src/root/sync_root_id.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl SyncRootIdBuilder {
6666
name.len()
6767
);
6868
assert!(
69-
!name.as_slice().iter().any(|c| *c == SyncRootId::SEPARATOR),
69+
!name.as_slice().contains(&SyncRootId::SEPARATOR),
7070
"provider name must not contain exclamation points"
7171
);
7272

@@ -245,7 +245,7 @@ impl SecurityId {
245245
pub fn new(id: impl AsRef<OsStr>) -> Self {
246246
let id = U16String::from_os_str(&id);
247247
assert!(
248-
!id.as_slice().iter().any(|x| *x == SyncRootId::SEPARATOR),
248+
!id.as_slice().contains(&SyncRootId::SEPARATOR),
249249
"security id cannot contain exclamation points"
250250
);
251251

@@ -256,31 +256,36 @@ impl SecurityId {
256256
pub fn current_user() -> core::Result<Self> {
257257
unsafe {
258258
let mut token_size = 0;
259-
let mut token = MaybeUninit::<TOKEN_USER>::uninit();
260259

261260
// get the token size
262-
if let Err(e) = GetTokenInformation(
261+
let info = GetTokenInformation(
263262
Self::CURRENT_THREAD_EFFECTIVE_TOKEN,
264263
Security::TokenUser,
265264
None,
266265
0,
267266
&mut token_size,
268-
) {
267+
);
268+
269+
if let Err(e) = info {
269270
if e.code() != ERROR_INSUFFICIENT_BUFFER.to_hresult() {
270271
Err(e)?;
271272
}
272-
GetTokenInformation(
273-
Self::CURRENT_THREAD_EFFECTIVE_TOKEN,
274-
Security::TokenUser,
275-
Some(&mut token as *mut _ as *mut _),
276-
token_size,
277-
&mut token_size,
278-
)?;
279273
}
280274

281-
let token = token.assume_init();
275+
let mut buffer = Vec::<MaybeUninit<u8>>::with_capacity(token_size as usize);
276+
buffer.set_len(token_size as usize);
277+
278+
GetTokenInformation(
279+
Self::CURRENT_THREAD_EFFECTIVE_TOKEN,
280+
Security::TokenUser,
281+
Some(buffer.as_mut_ptr() as *mut _),
282+
token_size,
283+
&mut token_size,
284+
)?;
285+
286+
let token_user = &*(buffer.as_ptr() as *const TOKEN_USER);
282287
let mut sid = PWSTR(ptr::null_mut());
283-
ConvertSidToStringSidW(token.User.Sid, &mut sid as *mut _)?;
288+
ConvertSidToStringSidW(token_user.User.Sid, &mut sid as *mut _)?;
284289

285290
let string_sid = U16CStr::from_ptr_str(sid.0).to_os_string();
286291
LocalFree(HLOCAL(sid.0 as *mut _));

0 commit comments

Comments
 (0)