diff --git a/webauthn-authenticator-rs/src/win10/rdp/channel.rs b/webauthn-authenticator-rs/src/win10/rdp/channel.rs index efe92c23..15c95764 100644 --- a/webauthn-authenticator-rs/src/win10/rdp/channel.rs +++ b/webauthn-authenticator-rs/src/win10/rdp/channel.rs @@ -1,29 +1,18 @@ use std::{ - ffi::c_void, - mem::{forget, transmute}, ops::{DerefMut, RangeInclusive}, slice, sync::{Arc, Mutex, RwLock}, }; use windows::{ - core::{ - implement, s, w, AsImpl, ComInterface, Error, IUnknown, IntoParam, Result, BSTR, GUID, - HRESULT, HSTRING, PCSTR, PCWSTR, - }, + core::{implement, IUnknown, Result, BSTR, HRESULT, PCSTR}, Win32::{ Foundation::{ - FreeLibrary, BOOL, DBG_UNABLE_TO_PROVIDE_HANDLE, ERROR_CONNECTION_REFUSED, E_FAIL, - MAX_PATH, NTE_BAD_LEN, NTE_INVALID_PARAMETER, S_OK, + BOOL, DBG_UNABLE_TO_PROVIDE_HANDLE, ERROR_CONNECTION_REFUSED, E_FAIL, MAX_PATH, + NTE_BAD_LEN, NTE_INVALID_PARAMETER, S_OK, }, - System::{ - Com::{CoInitializeEx, COINIT_MULTITHREADED}, - LibraryLoader::{GetProcAddress, LoadLibraryW}, - Registry::{RegGetValueW, HKEY_LOCAL_MACHINE, RRF_RT_REG_SZ}, - RemoteDesktop::{ - IWTSListener, IWTSListenerCallback, IWTSPlugin, IWTSVirtualChannel, - IWTSVirtualChannelCallback, IWTSVirtualChannelManager, - IWTSVirtualChannelManager_Impl, IWTSVirtualChannel_Impl, - }, + System::RemoteDesktop::{ + IWTSListener, IWTSListenerCallback, IWTSVirtualChannel, IWTSVirtualChannelCallback, + IWTSVirtualChannelManager, IWTSVirtualChannelManager_Impl, IWTSVirtualChannel_Impl, }, }, }; diff --git a/webauthn-authenticator-rs/src/win10/rdp/plugin.rs b/webauthn-authenticator-rs/src/win10/rdp/plugin.rs index 152f77aa..170ec426 100644 --- a/webauthn-authenticator-rs/src/win10/rdp/plugin.rs +++ b/webauthn-authenticator-rs/src/win10/rdp/plugin.rs @@ -1,28 +1,12 @@ -use std::{ - ffi::c_void, - mem::{forget, transmute}, - ops::{DerefMut, RangeInclusive}, - slice, - sync::{Arc, Mutex, RwLock}, -}; +use std::{ffi::c_void, mem::transmute}; use windows::{ - core::{ - implement, s, w, AsImpl, ComInterface, Error, IntoParam, BSTR, GUID, HRESULT, HSTRING, - PCSTR, PCWSTR, Result, - }, + core::{s, w, ComInterface, Error, IntoParam, Result, GUID, HRESULT, HSTRING, PCSTR, PCWSTR}, Win32::{ - Foundation::{ - FreeLibrary, BOOL, DBG_UNABLE_TO_PROVIDE_HANDLE, ERROR_CONNECTION_REFUSED, E_FAIL, - MAX_PATH, NTE_BAD_LEN, NTE_INVALID_PARAMETER, S_OK, - }, + Foundation::{FreeLibrary, NTE_BAD_LEN}, System::{ - Com::{CoInitializeEx, COINIT_MULTITHREADED}, LibraryLoader::{GetProcAddress, LoadLibraryW}, Registry::{RegGetValueW, HKEY_LOCAL_MACHINE, RRF_RT_REG_SZ}, - RemoteDesktop::{ - IWTSListenerCallback, IWTSPlugin, IWTSVirtualChannel, IWTSVirtualChannelCallback, - IWTSVirtualChannelManager, IWTSVirtualChannelManager_Impl, IWTSVirtualChannel_Impl, - }, + RemoteDesktop::IWTSPlugin, }, }, }; @@ -30,6 +14,8 @@ use windows::{ /// type VirtualChannelGetInstance = unsafe fn(&GUID, &mut u32, *mut *mut c_void) -> HRESULT; +const VIRTUAL_CHANNEL_GET_INSTANCE: PCSTR = s!("VirtualChannelGetInstance"); + /// Load a function from a given library. /// /// This is a small wrapper around `LoadLibrary` and `GetProcAddress`. @@ -117,22 +103,23 @@ fn get_webauthn_rdp_plugin_path() -> Result { /// Gets an instance of the WebAuthn [IWTSPlugin]. pub fn get_webauthn_iwtsplugin() -> Result { let path = get_webauthn_rdp_plugin_path()?; - let virtual_channel_get_instance: VirtualChannelGetInstance = - unsafe { transmute(delay_load(&path, s!("VirtualChannelGetInstance"))?) }; + unsafe { transmute(delay_load(&path, VIRTUAL_CHANNEL_GET_INSTANCE)?) }; let mut instance = Option::None; let mut num_objs = 1; - let plugin: IWTSPlugin = unsafe { - let ret = virtual_channel_get_instance( + Ok(unsafe { + let plugin = virtual_channel_get_instance( &IWTSPlugin::IID, &mut num_objs, &mut instance as *mut _ as *mut _, ) .and_some(instance)?; - assert_eq!(1, num_objs); - ret - }; - Ok(plugin) + if num_objs != 1 { + return Err(NTE_BAD_LEN.into()); + } + + plugin + }) }