From c08be770e4807bd9279b32f2c54ff166e1ec0e7a Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Sun, 15 Dec 2024 17:36:34 +0000 Subject: [PATCH] Export userenv.h directly to swift code. --- .../FabricSandbox/DiscordPipeSupport.swift | 2 +- windows/Sources/Sandbox/AppContainer.swift | 8 ++-- windows/Sources/WinSDKExtras/WinSDKExtras.cpp | 46 ------------------- .../WinSDKExtras/include/WinSDKExtras.h | 25 +--------- windows/Sources/WindowsUtils/Sid.swift | 2 +- 5 files changed, 7 insertions(+), 76 deletions(-) diff --git a/windows/Sources/FabricSandbox/DiscordPipeSupport.swift b/windows/Sources/FabricSandbox/DiscordPipeSupport.swift index 94e1a4a..63e95a4 100644 --- a/windows/Sources/FabricSandbox/DiscordPipeSupport.swift +++ b/windows/Sources/FabricSandbox/DiscordPipeSupport.swift @@ -21,7 +21,7 @@ public func grantAccessToDiscordPipes(trustee: Trustee) throws { // Remove any existing ACEs for the trustee and then grant full access // Ensure we only modify the DACL if the trustee doesn't already have access, to avoid breaking an existing connection - var hasEntry = try hasAceEntry(pipe, trustee: trustee) + let hasEntry = try hasAceEntry(pipe, trustee: trustee) if !hasEntry { try grantAccess(pipe, trustee: trustee, accessPermissions: [.genericAll]) } diff --git a/windows/Sources/Sandbox/AppContainer.swift b/windows/Sources/Sandbox/AppContainer.swift index f8a9ee3..e68b0c8 100644 --- a/windows/Sources/Sandbox/AppContainer.swift +++ b/windows/Sources/Sandbox/AppContainer.swift @@ -29,7 +29,7 @@ public class AppContainer: Trustee { } deinit { - _DeleteAppContainerProfile(name.wide) + DeleteAppContainerProfile(name.wide) } public static func create( @@ -51,12 +51,12 @@ public class AppContainer: Trustee { */ // Fow now delete an existing container if it exists - let _ = _DeleteAppContainerProfile(name.wide) + let _ = DeleteAppContainerProfile(name.wide) var capabilities = attributes.map { $0.sidAttributes } var sid: PSID? = nil let result = capabilities.withUnsafeMutableBufferPointer { capabilities in - _CreateAppContainerProfile( + CreateAppContainerProfile( name.wide, name.wide, description.wide, capabilities.count > 0 ? capabilities.baseAddress : nil, DWORD(capabilities.count), &sid) @@ -70,7 +70,7 @@ public class AppContainer: Trustee { private static func getExisting(_ name: String) -> Sid? { var sid: PSID? = nil - let result = _DeriveAppContainerSidFromAppContainerName(name.wide, &sid) + let result = DeriveAppContainerSidFromAppContainerName(name.wide, &sid) guard result == S_OK, let sid = sid else { return nil diff --git a/windows/Sources/WinSDKExtras/WinSDKExtras.cpp b/windows/Sources/WinSDKExtras/WinSDKExtras.cpp index 4a2379d..353b711 100644 --- a/windows/Sources/WinSDKExtras/WinSDKExtras.cpp +++ b/windows/Sources/WinSDKExtras/WinSDKExtras.cpp @@ -1,53 +1,7 @@ #include "WinSDKExtras.h" -#include #include -HRESULT _CreateAppContainerProfile( - _In_ PCWSTR pszAppContainerName, - _In_ PCWSTR pszDisplayName, - _In_ PCWSTR pszDescription, - _In_ PSID_AND_ATTRIBUTES pCapabilities, - _In_ DWORD dwCapabilityCount, - _Outptr_ PSID* ppSidAppContainerSid) { - return CreateAppContainerProfile( - pszAppContainerName, - pszDisplayName, - pszDescription, - pCapabilities, - dwCapabilityCount, - ppSidAppContainerSid); -} - -HRESULT _DeleteAppContainerProfile( - _In_ PCWSTR pszAppContainerName) { - return DeleteAppContainerProfile(pszAppContainerName); -} - -HRESULT _DeriveAppContainerSidFromAppContainerName( - _In_ PCWSTR pszAppContainerName, - _Outptr_ PSID* ppSidAppContainerSid) -{ - return DeriveAppContainerSidFromAppContainerName( - pszAppContainerName, - ppSidAppContainerSid); -} - -BOOL _DeriveCapabilitySidsFromName( - _In_ LPCWSTR CapName, - _Outptr_ PSID **CapabilityGroupSids, - _Outptr_ DWORD *CapabilityGroupSidCount, - _Outptr_ PSID **CapabilitySids, - _Outptr_ DWORD *CapabilitySidCount -) { - return DeriveCapabilitySidsFromName( - CapName, - CapabilityGroupSids, - CapabilityGroupSidCount, - CapabilitySids, - CapabilitySidCount); -} - DWORD _PROC_THREAD_ATTRIBUTE_SECURITY_CAPABILITIES() { return PROC_THREAD_ATTRIBUTE_SECURITY_CAPABILITIES; } diff --git a/windows/Sources/WinSDKExtras/include/WinSDKExtras.h b/windows/Sources/WinSDKExtras/include/WinSDKExtras.h index 1447d62..42b06c4 100644 --- a/windows/Sources/WinSDKExtras/include/WinSDKExtras.h +++ b/windows/Sources/WinSDKExtras/include/WinSDKExtras.h @@ -2,30 +2,7 @@ #include #include - -// userenv.h -HRESULT _CreateAppContainerProfile( - _In_ PCWSTR pszAppContainerName, - _In_ PCWSTR pszDisplayName, - _In_ PCWSTR pszDescription, - _In_ PSID_AND_ATTRIBUTES pCapabilities, - _In_ DWORD dwCapabilityCount, - _Outptr_ PSID* ppSidAppContainerSid); - -HRESULT _DeleteAppContainerProfile( - _In_ PCWSTR pszAppContainerName); - -HRESULT _DeriveAppContainerSidFromAppContainerName( - _In_ PCWSTR pszAppContainerName, - _Outptr_ PSID* ppSidAppContainerSid); - -BOOL _DeriveCapabilitySidsFromName( - _In_ LPCWSTR CapName, - _Outptr_ PSID **CapabilityGroupSids, - _Outptr_ DWORD *CapabilityGroupSidCount, - _Outptr_ PSID **CapabilitySids, - _Outptr_ DWORD *CapabilitySidCount -); +#include DWORD _PROC_THREAD_ATTRIBUTE_SECURITY_CAPABILITIES(); diff --git a/windows/Sources/WindowsUtils/Sid.swift b/windows/Sources/WindowsUtils/Sid.swift index 0ac71d2..72d0585 100644 --- a/windows/Sources/WindowsUtils/Sid.swift +++ b/windows/Sources/WindowsUtils/Sid.swift @@ -56,7 +56,7 @@ public class Sid: CustomStringConvertible { let capabilitySids = UnsafeMutablePointer?>.allocate(capacity: 0) var capabilitySidsCount: DWORD = 0 - let result = _DeriveCapabilitySidsFromName( + let result = DeriveCapabilitySidsFromName( type.wide, capabilityGroupSids, &capabilityGroupSidsCount,