Merge pull request #3699 from shmsh9/master
Enable active directory users in create_process_with_logon and fix set_path_permission for non-english windows
This commit is contained in:
commit
c54b4286b0
@ -17,10 +17,11 @@ use std::{
|
|||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
sync::{Arc, Mutex},
|
sync::{Arc, Mutex},
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
|
collections::HashMap
|
||||||
};
|
};
|
||||||
use winapi::{
|
use winapi::{
|
||||||
ctypes::c_void,
|
ctypes::c_void,
|
||||||
shared::{minwindef::*, ntdef::NULL, windef::*},
|
shared::{minwindef::*, ntdef::NULL, windef::*, winerror::*},
|
||||||
um::{
|
um::{
|
||||||
errhandlingapi::GetLastError,
|
errhandlingapi::GetLastError,
|
||||||
handleapi::CloseHandle,
|
handleapi::CloseHandle,
|
||||||
@ -1762,9 +1763,15 @@ pub fn send_message_to_hnwd(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_process_with_logon(user: &str, pwd: &str, exe: &str, arg: &str) -> ResultType<()> {
|
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 {
|
unsafe {
|
||||||
let wuser = wide_string(user);
|
let user_split = user.split("\\").collect::<Vec<&str>>();
|
||||||
let wpc = wide_string("");
|
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 wpwd = wide_string(pwd);
|
||||||
let cmd = if arg.is_empty() {
|
let cmd = if arg.is_empty() {
|
||||||
format!("\"{}\"", exe)
|
format!("\"{}\"", exe)
|
||||||
@ -1794,7 +1801,14 @@ pub fn create_process_with_logon(user: &str, pwd: &str, exe: &str, arg: &str) ->
|
|||||||
&mut pi as *mut PROCESS_INFORMATION,
|
&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(());
|
return Ok(());
|
||||||
@ -1804,7 +1818,7 @@ pub fn set_path_permission(dir: &PathBuf, permission: &str) -> ResultType<()> {
|
|||||||
std::process::Command::new("icacls")
|
std::process::Command::new("icacls")
|
||||||
.arg(dir.as_os_str())
|
.arg(dir.as_os_str())
|
||||||
.arg("/grant")
|
.arg("/grant")
|
||||||
.arg(format!("Everyone:(OI)(CI){}", permission))
|
.arg(format!("*S-1-1-0:(OI)(CI){}", permission))
|
||||||
.arg("/T")
|
.arg("/T")
|
||||||
.spawn()?;
|
.spawn()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user