Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
cgettys-microsoft committed Mar 7, 2025
1 parent d4a4a3e commit c0a1a67
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 17 deletions.
7 changes: 5 additions & 2 deletions crates/libs/core/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,12 @@ impl ApiTable {
Ok(unsafe { T::from_raw(result) })
}

pub fn get_fabric_client_default_settings_fn(&self) -> crate::WinResult<IFabricClientSettingsResult> {
pub fn get_fabric_client_default_settings(
&self,
) -> crate::WinResult<IFabricClientSettingsResult> {
let mut result = std::ptr::null_mut::<IFabricClientSettingsResult>();
unsafe { (self.get_fabric_client_default_settings_fn)(std::ptr::addr_of_mut!(result)) }.ok()?;
unsafe { (self.get_fabric_client_default_settings_fn)(std::ptr::addr_of_mut!(result)) }
.ok()?;
Ok(unsafe { IFabricClientSettingsResult::from_raw(result as *mut core::ffi::c_void) })
}

Expand Down
4 changes: 2 additions & 2 deletions crates/libs/core/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ fn create_local_client_internal<T: Interface>(
.expect("failed to cast fabric client to IFabricClientSettings2");
if let Some(desired_settings) = client_settings {
desired_settings
.set(&setting_interface)
.apply(&setting_interface)
.expect("failed to set client settings")
}
if let Some(desired_credentials) = client_credentials {
desired_credentials
.set(&setting_interface)
.apply(&setting_interface)
.expect("failed to set client settings")
}
// TODO: error handling
Expand Down
16 changes: 9 additions & 7 deletions crates/libs/core/src/types/client/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,13 @@ impl From<&FABRIC_CLIENT_SETTINGS> for FabricClientSettings {

impl FabricClientSettings {
/// Get the current settings via the COM interface
pub fn get_defaults(com: &IFabricClientSettings2) -> FabricClientSettings {
pub fn get_defaults() -> crate::Result<FabricClientSettings> {
// TODO: error handling?
// SAFETY: IFabricClientSettings2 implements this COM interface
// TODO: replace this with GetFabricClientDefaultSettings
let result = unsafe { com.GetSettings() }.expect("GetSettings failed");
let result = crate::API_TABLE
.get_fabric_client_default_settings()
.map_err(crate::Error::from)?;
// Note: inner scope outlives result, which is critical as otherwise we'd have UB.
let converted = {
// SAFETY: FABRIC_CLIENT_SETTINGS_EX1.ClientFriendlyName is only accessed while IFabricClientSettingsResult is in scope
Expand All @@ -178,7 +180,7 @@ impl FabricClientSettings {
FabricClientSettings::from(my_ref)
};
drop(result);
converted
Ok(converted)
}
}

Expand Down Expand Up @@ -281,14 +283,14 @@ fn combine_settings_with_overrides(

impl FabricClientSettings {
/// Note: only overrides non-default settings; leaves any settings set previously that don't explicitly have new values alone
pub fn set(&self, settings_interface: &IFabricClientSettings2) -> windows_core::Result<()> {
pub fn apply(&self, settings_interface: &IFabricClientSettings2) -> crate::Result<()> {
// SAFETY: setting_interface implements the required COM interface.
let existing_settings = FabricClientSettings::get_defaults(settings_interface);
let existing_settings = FabricClientSettings::get_defaults()?;
let new_settings = combine_settings_with_overrides(existing_settings, self.clone());
new_settings.set_inner(settings_interface)
}

fn set_inner(&self, settings_interface: &IFabricClientSettings2) -> windows_core::Result<()> {
fn set_inner(&self, settings_interface: &IFabricClientSettings2) -> crate::Result<()> {
// TODO: ex5 missing from IDL?
let ex4 = FABRIC_CLIENT_SETTINGS_EX4 {
// Deprecated, should always be zero
Expand Down Expand Up @@ -351,6 +353,6 @@ impl FabricClientSettings {
// CALL THE FUNCTION:
let val_ptr = std::ptr::addr_of!(val);
// SAFETY: val is valid for the duration of the call
unsafe { settings_interface.SetSettings(val_ptr) }
unsafe { settings_interface.SetSettings(val_ptr) }.map_err(crate::Error::from)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use super::FabricProtectionLevel;
struct FabricClaimsCredentials {
pub ServerCommonNames: Vec<WString>,
pub IssuerThumbprints: Vec<WString>,
pub LocalClaims: windows_core::PCWSTR,
pub LocalClaims: WString,
pub ProtectionLevel: FabricProtectionLevel,
/// FABRIC_CLAIMS_CREDENTIALS_EX1
pub ServerThumbprints: Option<Vec<WString>>,
Expand Down
6 changes: 3 additions & 3 deletions crates/libs/core/src/types/common/security_credentials/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ impl From<FabricProtectionLevel> for FABRIC_PROTECTION_LEVEL {
}

trait FabricSecurityCredentialKind {
fn set_inner(&self, settings_interface: &IFabricClientSettings2) -> windows_core::Result<()>;
fn apply_inner(&self, settings_interface: &IFabricClientSettings2) -> crate::Result<()>;
}

impl FabricSecurityCredentials {
// TODO: may belong on the other side?
pub fn set(&self, settings_interface: &IFabricClientSettings2) -> windows_core::Result<()> {
pub fn apply(&self, settings_interface: &IFabricClientSettings2) -> crate::Result<()> {
match &self {
FabricSecurityCredentials::FabricX509Credentials(v) => v,
}
.set_inner(settings_interface)
.apply_inner(settings_interface)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ pub struct FabricX509Credentials {
}

impl FabricSecurityCredentialKind for FabricX509Credentials {
fn set_inner(
fn apply_inner(
&self,
settings_interface: &mssf_com::FabricClient::IFabricClientSettings2,
) -> windows_core::Result<()> {
) -> crate::Result<()> {
let allowed_common_names: Box<[PCWSTR]> = self
.AllowedCommonNames
.iter()
Expand Down Expand Up @@ -134,5 +134,6 @@ impl FabricSecurityCredentialKind for FabricX509Credentials {

// SAFETY: COM interop. SetSecurityCredentials does not retain reference to the passed in data after function returns.
unsafe { settings_interface.SetSecurityCredentials(&security_credentials) }
.map_err(crate::Error::from)
}
}

0 comments on commit c0a1a67

Please sign in to comment.