Skip to content

Commit 4e3f28a

Browse files
Merge branch 'main' into feat/package-auto-update-policy
2 parents 2df2b86 + 311a10f commit 4e3f28a

54 files changed

Lines changed: 1729 additions & 436 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎clients/openframe-client/src/doctor/checks.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,6 @@ fn service_config_dir() -> std::path::PathBuf {
416416
}
417417
#[cfg(target_os = "windows")]
418418
{
419-
let pf = std::env::var("ProgramFiles").unwrap_or_else(|_| r"C:\Program Files".into());
420-
std::path::PathBuf::from(pf).join("OpenFrame").join("bin")
419+
crate::platform::directories::get_install_directory().join("bin")
421420
}
422421
}

‎clients/openframe-client/src/doctor/healing/webview2_installer.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ const SIGNATURE_CHECK_SCRIPT: &str =
155155
/// Rejects the download unless it carries a valid Microsoft Authenticode signature.
156156
#[cfg(windows)]
157157
async fn verify_microsoft_signature(path: &std::path::Path) -> anyhow::Result<()> {
158-
use anyhow::{anyhow, bail, Context};
158+
use anyhow::{bail, Context};
159159

160-
let powershell = crate::platform::get_powershell_path().map_err(|e| anyhow!(e))?;
160+
let powershell = crate::platform::get_powershell_path();
161161
let script = SIGNATURE_CHECK_SCRIPT.replace("{path}", &path.display().to_string());
162162

163163
let output = tokio::time::timeout(

‎clients/openframe-client/src/executor/windows/mod.rs‎

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ use anyhow::{anyhow, Result};
1111

1212
use crate::executor::tempfile::{temp_script_name, write_temp_script, TempFileGuard};
1313
use crate::executor::{ExecResult, ScriptParams};
14+
use crate::platform::directories::get_app_support_directory;
15+
use crate::platform::powershell::{get_powershell_path, resolve_system32_exe};
1416

1517
pub(crate) struct Interpreter {
1618
pub exe: String,
@@ -94,10 +96,7 @@ fn spawn_error(msg: String) -> ExecResult {
9496
fn resolve_interpreter(shell: &str) -> Option<Interpreter> {
9597
match shell {
9698
"powershell" => Some(Interpreter {
97-
exe: resolve_exe(
98-
r"System32\WindowsPowerShell\v1.0\powershell.exe",
99-
"powershell.exe",
100-
),
99+
exe: get_powershell_path(),
101100
flags: &[
102101
"-NonInteractive",
103102
"-NoProfile",
@@ -108,32 +107,16 @@ fn resolve_interpreter(shell: &str) -> Option<Interpreter> {
108107
ext: "ps1",
109108
}),
110109
"cmd" => Some(Interpreter {
111-
exe: resolve_exe(r"System32\cmd.exe", "cmd.exe"),
110+
exe: resolve_system32_exe(r"System32\cmd.exe", "cmd.exe"),
112111
flags: &["/C"],
113112
ext: "bat",
114113
}),
115114
_ => None,
116115
}
117116
}
118117

119-
fn resolve_exe(system32_rel: &str, bare: &str) -> String {
120-
let windir = std::env::var_os("WINDIR")
121-
.or_else(|| std::env::var_os("SystemRoot"))
122-
.map(PathBuf::from);
123-
if let Some(windir) = windir {
124-
let abs = windir.join(system32_rel);
125-
if abs.is_file() {
126-
return abs.to_string_lossy().into_owned();
127-
}
128-
}
129-
bare.to_string()
130-
}
131-
132118
fn win_tmp_dir() -> Result<PathBuf> {
133-
let base = std::env::var_os("PROGRAMDATA")
134-
.map(PathBuf::from)
135-
.unwrap_or_else(std::env::temp_dir);
136-
let dir = base.join("OpenFrame");
119+
let dir = get_app_support_directory();
137120
std::fs::create_dir_all(&dir).map_err(|e| anyhow!("failed to create temp dir: {e}"))?;
138121
Ok(dir)
139122
}

‎clients/openframe-client/src/lib.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,8 @@ impl Client {
794794

795795
self.nats_connection_manager.start_connection_watchdog();
796796

797+
self.update_handler_service.publish_running_version().await;
798+
797799
// Handle any pending update from previous run (after NATS is connected)
798800
if let Err(e) = self.update_handler_service.handle_pending_update().await {
799801
error!("Failed to handle pending update: {:#}", e);

‎clients/openframe-client/src/logging/.platform.md‎

Lines changed: 0 additions & 31 deletions
This file was deleted.

‎clients/openframe-client/src/logging/platform.rs‎

Lines changed: 0 additions & 93 deletions
This file was deleted.

‎clients/openframe-client/src/logging/platform_tests.rs‎

Lines changed: 0 additions & 15 deletions
This file was deleted.

‎clients/openframe-client/src/platform/directories.rs‎

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,10 @@ impl From<PermissionError> for DirectoryError {
9494
pub fn get_app_support_directory() -> PathBuf {
9595
#[cfg(target_os = "windows")]
9696
{
97-
let program_data =
98-
std::env::var_os("ProgramData").expect("ProgramData environment variable not found");
99-
let mut path = PathBuf::from(program_data);
100-
path.push("OpenFrame");
101-
path
97+
std::env::var_os("ProgramData")
98+
.map(PathBuf::from)
99+
.unwrap_or_else(|| PathBuf::from("C:\\ProgramData"))
100+
.join("OpenFrame")
102101
}
103102

104103
#[cfg(target_os = "macos")]
@@ -136,12 +135,7 @@ pub fn get_logs_directory() -> PathBuf {
136135
// If no override, use platform-specific defaults
137136
#[cfg(target_os = "windows")]
138137
{
139-
let program_data =
140-
std::env::var_os("ProgramData").expect("ProgramData environment variable not found");
141-
let mut path = PathBuf::from(program_data);
142-
path.push("OpenFrame");
143-
path.push("logs");
144-
path
138+
get_app_support_directory().join("logs")
145139
}
146140

147141
#[cfg(target_os = "macos")]
@@ -159,12 +153,7 @@ pub fn get_logs_directory() -> PathBuf {
159153
pub fn get_secured_directory() -> PathBuf {
160154
#[cfg(target_os = "windows")]
161155
{
162-
let program_data =
163-
std::env::var_os("ProgramData").expect("ProgramData environment variable not found");
164-
let mut path = PathBuf::from(program_data);
165-
path.push("OpenFrame");
166-
path.push("secured");
167-
path
156+
get_app_support_directory().join("secured")
168157
}
169158

170159
#[cfg(target_os = "macos")]
@@ -178,6 +167,29 @@ pub fn get_secured_directory() -> PathBuf {
178167
}
179168
}
180169

170+
/// Returns the Windows install root, %ProgramFiles%\OpenFrame (the binary is in `bin`)
171+
#[cfg(target_os = "windows")]
172+
pub fn get_install_directory() -> PathBuf {
173+
let program_files =
174+
std::env::var("ProgramFiles").unwrap_or_else(|_| "C:\\Program Files".to_string());
175+
PathBuf::from(program_files).join("OpenFrame")
176+
}
177+
178+
/// Returns where the self-update stages the new binary and the updater script.
179+
/// On Windows it is under Program Files\OpenFrame, which our published AV exclusions
180+
/// cover: script-blocking tools deny PowerShell reading scripts from SystemTemp.
181+
pub fn get_update_staging_directory() -> PathBuf {
182+
#[cfg(target_os = "windows")]
183+
{
184+
get_install_directory().join("update")
185+
}
186+
187+
#[cfg(not(target_os = "windows"))]
188+
{
189+
std::env::temp_dir()
190+
}
191+
}
192+
181193
/// Sets the correct platform-specific permissions on a directory
182194
pub fn set_directory_permissions(path: &Path) -> io::Result<()> {
183195
#[cfg(target_os = "windows")]
Lines changed: 18 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,27 @@
11
use std::path::PathBuf;
2-
use std::process::{Command, Stdio};
32

4-
/// Get PowerShell path - tries PATH first, then known locations
5-
/// Returns ready-to-use path string
3+
/// Get the Windows PowerShell path the same way RMM scripts run it: the absolute
4+
/// System32 binary, so a PATH entry can't shadow it and security tools that allow
5+
/// PowerShell by path match it. Falls back to the bare name.
66
#[cfg(windows)]
7-
pub fn get_powershell_path() -> Result<String, &'static str> {
8-
// Try powershell.exe from PATH first
9-
if let Ok(mut child) = Command::new("powershell.exe")
10-
.arg("-NoProfile")
11-
.arg("-Command")
12-
.arg("exit 0")
13-
.stdin(Stdio::null())
14-
.stdout(Stdio::null())
15-
.stderr(Stdio::null())
16-
.spawn()
17-
{
18-
let _ = child.wait();
19-
return Ok("powershell.exe".to_string());
20-
}
21-
22-
// Fallback to known locations
23-
find_powershell_path()
24-
.map(|p| p.to_string_lossy().to_string())
25-
.ok_or("PowerShell not found")
7+
pub fn get_powershell_path() -> String {
8+
resolve_system32_exe(
9+
r"System32\WindowsPowerShell\v1.0\powershell.exe",
10+
"powershell.exe",
11+
)
2612
}
2713

28-
/// Find an existing PowerShell path on the system
14+
/// Absolute path of a System32 executable under %WINDIR%, or `bare` when it is missing.
2915
#[cfg(windows)]
30-
fn find_powershell_path() -> Option<PathBuf> {
31-
let system_root = std::env::var("SystemRoot").unwrap_or_else(|_| "C:\\Windows".to_string());
32-
let program_files =
33-
std::env::var("ProgramFiles").unwrap_or_else(|_| "C:\\Program Files".to_string());
34-
let program_files_x86 = std::env::var("ProgramFiles(x86)")
35-
.unwrap_or_else(|_| "C:\\Program Files (x86)".to_string());
36-
37-
let paths = [
38-
// Windows PowerShell
39-
format!(
40-
"{}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
41-
system_root
42-
),
43-
format!(
44-
"{}\\SysWOW64\\WindowsPowerShell\\v1.0\\powershell.exe",
45-
system_root
46-
),
47-
"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe".to_string(),
48-
"C:\\Windows\\SysWOW64\\WindowsPowerShell\\v1.0\\powershell.exe".to_string(),
49-
// PowerShell 7
50-
format!("{}\\PowerShell\\7\\pwsh.exe", program_files),
51-
format!("{}\\PowerShell\\7\\pwsh.exe", program_files_x86),
52-
];
53-
54-
for path in paths {
55-
let p = PathBuf::from(&path);
56-
if p.exists() {
57-
return Some(p);
16+
pub fn resolve_system32_exe(system32_rel: &str, bare: &str) -> String {
17+
let windir = std::env::var_os("WINDIR")
18+
.or_else(|| std::env::var_os("SystemRoot"))
19+
.map(PathBuf::from);
20+
if let Some(windir) = windir {
21+
let abs = windir.join(system32_rel);
22+
if abs.is_file() {
23+
return abs.to_string_lossy().into_owned();
5824
}
5925
}
60-
61-
None
26+
bare.to_string()
6227
}

0 commit comments

Comments
 (0)