Qualify Windows IPC client runtime and prepare bounded native providers
Rust development slice / linux (push) Failing after 7s
Rust development slice / linux (push) Failing after 7s
This commit is contained in:
@@ -8,7 +8,8 @@ use anyhow::{Result, anyhow, ensure};
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::Serialize;
|
||||
use std::sync::Mutex;
|
||||
/// Flip only after native SID-bound ALPC, readiness and fail-closed qualification.
|
||||
/// Flip only after native account AND service-bound ALPC, positive readiness,
|
||||
/// wrong-account/wrong-service denial and fail-closed qualification.
|
||||
pub const ADAPTER_QUALIFIED: bool = false;
|
||||
const SECOND: u64 = 10_000_000;
|
||||
const MAX_AGE: u64 = 3600 * SECOND;
|
||||
@@ -191,7 +192,7 @@ impl NativeClock {
|
||||
transport: if self.diagnostic {
|
||||
"ncacn_np:W32TIME_ALT:diagnostic_only"
|
||||
} else {
|
||||
"ncalrpc:SID19:mutual_auth"
|
||||
"ncalrpc:SID19:W32Time:V5_descriptor:mutual_auth"
|
||||
},
|
||||
status: None,
|
||||
query_ticks: ticks,
|
||||
@@ -258,6 +259,38 @@ pub fn named_pipe_diagnostic() -> ClockReport {
|
||||
}
|
||||
.report()
|
||||
}
|
||||
/// Read-only negative controls for the separate native readiness program.
|
||||
/// Neither control can produce clock authority, even if the OS accepts it.
|
||||
/// Rejection without a successful genuine status query is not identity proof.
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct IdentityControls {
|
||||
pub wrong_account_rpc_code: u32,
|
||||
pub wrong_service_rpc_code: u32,
|
||||
pub both_access_denied: bool,
|
||||
pub diagnostic_only: bool,
|
||||
}
|
||||
pub fn identity_controls() -> IdentityControls {
|
||||
#[cfg(windows)]
|
||||
let codes = {
|
||||
static WORKER: std::sync::OnceLock<Mutex<RpcWorker>> = std::sync::OnceLock::new();
|
||||
let worker = WORKER.get_or_init(|| Mutex::new(RpcWorker::new(raw_control)));
|
||||
match worker.try_lock() {
|
||||
Ok(mut worker) => (
|
||||
worker.call(true, std::time::Duration::from_secs(1)).0,
|
||||
worker.call(false, std::time::Duration::from_secs(1)).0,
|
||||
),
|
||||
Err(_) => (170, 170),
|
||||
}
|
||||
};
|
||||
#[cfg(not(windows))]
|
||||
let codes = (50, 50);
|
||||
IdentityControls {
|
||||
wrong_account_rpc_code: codes.0,
|
||||
wrong_service_rpc_code: codes.1,
|
||||
both_access_denied: codes == (5, 5),
|
||||
diagnostic_only: true,
|
||||
}
|
||||
}
|
||||
impl rmm_agent_core::reconcile::SyncClock for NativeClock {
|
||||
fn now(&self) -> Result<DateTime<Utc>> {
|
||||
NativeClock::now(self)
|
||||
@@ -300,6 +333,26 @@ fn raw_query(diagnostic: bool) -> (u32, Status) {
|
||||
};
|
||||
(code, status)
|
||||
}
|
||||
#[cfg(windows)]
|
||||
fn raw_control(wrong_account: bool) -> (u32, Status) {
|
||||
#[link(name = "rmm_clock_rpc", kind = "static")]
|
||||
#[link(name = "rpcrt4")]
|
||||
#[link(name = "advapi32")]
|
||||
unsafe extern "C" {
|
||||
fn rmm_clock_wrong_account(status: *mut Status) -> u32;
|
||||
fn rmm_clock_wrong_service(status: *mut Status) -> u32;
|
||||
}
|
||||
let mut status = Status::default();
|
||||
// SAFETY: fixed C ABI, fixed two local negative identities, contained SEH.
|
||||
let code = unsafe {
|
||||
if wrong_account {
|
||||
rmm_clock_wrong_account(&mut status)
|
||||
} else {
|
||||
rmm_clock_wrong_service(&mut status)
|
||||
}
|
||||
};
|
||||
(code, status)
|
||||
}
|
||||
#[cfg(any(windows, test))]
|
||||
type RpcReply = std::sync::mpsc::SyncSender<(u32, Status)>;
|
||||
#[cfg(any(windows, test))]
|
||||
|
||||
Reference in New Issue
Block a user