Check return code before calling last_os_error
@@ -49,7 +49,7 @@ impl Account {
};
let mut name_size: u32 = 0;
let mut domain_size: u32 = 0;
- unsafe {
+ let ret = unsafe {
LookupAccountSidW(null(),
sid.raw.as_ptr() as *mut _,
null_mut(),
@@ -58,6 +58,7 @@ impl Account {
&mut domain_size as LPDWORD,
null_mut())
};
+ if ret == 0 {
match Error::last_os_error().raw_os_error().unwrap() as u32 {
ERROR_INSUFFICIENT_BUFFER => {}
ERROR_NONE_MAPPED => return None,
@@ -68,6 +69,7 @@ impl Account {
return None;
}
}
+ }
let mut name: Vec<u16> = Vec::with_capacity(name_size as usize);
let mut domain: Vec<u16> = Vec::with_capacity(domain_size as usize);
@@ -135,7 +137,7 @@ fn lookup_account(name: &str, system_name: Option<String>) -> Option<Account> {
let mut sid_size: u32 = 0;
let mut domain_size: u32 = 0;
let wide = WideCString::from_str(stripped_name).unwrap();
- unsafe {
+ let ret = unsafe {
LookupAccountNameW(null_mut(),
wide.as_ptr(),
null_mut(),
@@ -144,6 +146,7 @@ fn lookup_account(name: &str, system_name: Option<String>) -> Option<Account> {
&mut domain_size as LPDWORD,
null_mut())
};
+ if ret == 0 {
match Error::last_os_error().raw_os_error().unwrap() as u32 {
ERROR_INSUFFICIENT_BUFFER => {}
ERROR_NONE_MAPPED => return None,
@@ -154,6 +157,7 @@ fn lookup_account(name: &str, system_name: Option<String>) -> Option<Account> {
return None;
}
}
+ }
let mut sid: Vec<u8> = Vec::with_capacity(sid_size as usize);
let mut domain: Vec<u16> = Vec::with_capacity(domain_size as usize);
