From 4c213a238af15b9d5198c64abe1e702d3f40896d Mon Sep 17 00:00:00 2001 From: Carbonari Date: Fri, 17 Mar 2023 12:36:35 +0100 Subject: [PATCH 1/3] Allow Active Directory credentials for elevation --- src/platform/windows.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/platform/windows.rs b/src/platform/windows.rs index 696a18ab9..e27339865 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -1762,9 +1762,15 @@ pub fn send_message_to_hnwd( } pub fn create_process_with_logon(user: &str, pwd: &str, exe: &str, arg: &str) -> ResultType<()> { + let last_error_table = HashMap::from([ + (ERROR_LOGON_FAILURE, "The user name or password is incorrect."), + (ERROR_ACCESS_DENIED, "Access is denied.") + ]); + unsafe { - let wuser = wide_string(user); - let wpc = wide_string(""); + let user_split = user.split("\\").collect::>(); + let wuser = wide_string(user_split.get(1).unwrap_or(&user)); + let wpc = wide_string(user_split.get(0).unwrap_or(&"")); let wpwd = wide_string(pwd); let cmd = if arg.is_empty() { format!("\"{}\"", exe) @@ -1794,7 +1800,14 @@ pub fn create_process_with_logon(user: &str, pwd: &str, exe: &str, arg: &str) -> &mut pi as *mut PROCESS_INFORMATION, ) { - bail!("CreateProcessWithLogonW failed, errno={}", GetLastError()); + let last_error = GetLastError(); + bail!( + "CreateProcessWithLogonW failed : \"{}\", errno={}", + last_error_table + .get(&last_error) + .unwrap_or(&"Unknown error"), + last_error + ); } } return Ok(()); From e9d2a72d005445334c170f27d39503840dff9dc9 Mon Sep 17 00:00:00 2001 From: Carbonari Date: Fri, 17 Mar 2023 12:37:11 +0100 Subject: [PATCH 2/3] fix icacls for non-english versions of windows --- src/platform/windows.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/windows.rs b/src/platform/windows.rs index e27339865..5fd91c881 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -1817,7 +1817,7 @@ pub fn set_path_permission(dir: &PathBuf, permission: &str) -> ResultType<()> { std::process::Command::new("icacls") .arg(dir.as_os_str()) .arg("/grant") - .arg(format!("Everyone:(OI)(CI){}", permission)) + .arg(format!("*S-1-1-0:(OI)(CI){}", permission)) .arg("/T") .spawn()?; Ok(()) From 50bf518af1fd3e41f0bfef0c34f3c2f9e08c394b Mon Sep 17 00:00:00 2001 From: Carbonari Date: Fri, 17 Mar 2023 13:01:37 +0100 Subject: [PATCH 3/3] missing imports --- src/platform/windows.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/platform/windows.rs b/src/platform/windows.rs index 5fd91c881..00cae20cd 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -17,10 +17,11 @@ use std::{ path::PathBuf, sync::{Arc, Mutex}, time::{Duration, Instant}, + collections::HashMap }; use winapi::{ ctypes::c_void, - shared::{minwindef::*, ntdef::NULL, windef::*}, + shared::{minwindef::*, ntdef::NULL, windef::*, winerror::*}, um::{ errhandlingapi::GetLastError, handleapi::CloseHandle,