Skip to content

Commit 0e2f1df

Browse files
committed
see if this makes a difference on windows (#386)
1 parent d6c6ec6 commit 0e2f1df

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

git-sec/src/lib.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ pub mod identity {
5252
use std::borrow::Cow;
5353
use std::path::Path;
5454

55-
fn err(msg: &str) -> std::io::Error {
56-
std::io::Error::new(std::io::ErrorKind::Other, msg)
55+
fn err(msg: impl Into<String>) -> std::io::Error {
56+
std::io::Error::new(std::io::ErrorKind::Other, msg.into())
5757
}
5858

5959
pub fn is_path_owned_by_current_user(path: Cow<'_, Path>) -> std::io::Result<bool> {
@@ -75,12 +75,12 @@ pub mod identity {
7575
.map_err(|_| err("Failed to open process token"))?;
7676

7777
let mut len = 0_u32;
78-
if Security::GetTokenInformation(&handle, Security::TokenUser, std::ptr::null_mut(), 0, &mut len)
78+
if !Security::GetTokenInformation(handle, Security::TokenUser, std::ptr::null_mut(), 0, &mut len)
7979
.as_bool()
8080
{
8181
let mut token_user = Security::TOKEN_USER::default();
8282
if Security::GetTokenInformation(
83-
&handle,
83+
handle,
8484
Security::TokenUser,
8585
&mut token_user as *mut _ as *mut std::ffi::c_void,
8686
len,
@@ -113,16 +113,16 @@ pub mod identity {
113113
if res == ERROR_SUCCESS.0 && Security::IsValidSid(path_sid).as_bool() {
114114
is_owned = Security::EqualSid(path_sid, token_user.User.Sid).as_bool();
115115
} else {
116-
err_msg = "couldn't get owner for path or it wasn't valid".into();
116+
err_msg = format!("couldn't get owner for path or it wasn't valid: {}", res).into();
117117
}
118118
} else {
119-
err_msg = "owner id of current process wasn't set or valid".into();
119+
err_msg = String::from("owner id of current process wasn't set or valid").into();
120120
}
121121
} else {
122-
err_msg = "Could not get information about the token user".into();
122+
err_msg = String::from("Could not get information about the token user").into();
123123
}
124124
} else {
125-
err_msg = "Could not get token information for length of token user".into();
125+
err_msg = String::from("Could not get token information for length of token user").into();
126126
}
127127
CloseHandle(handle);
128128
if !descriptor.is_invalid() {

0 commit comments

Comments
 (0)