Skip to content

Commit

Permalink
Export userenv.h directly to swift code.
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Dec 15, 2024
1 parent ccc5f51 commit c08be77
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 76 deletions.
2 changes: 1 addition & 1 deletion windows/Sources/FabricSandbox/DiscordPipeSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Expand Down
8 changes: 4 additions & 4 deletions windows/Sources/Sandbox/AppContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class AppContainer: Trustee {
}

deinit {
_DeleteAppContainerProfile(name.wide)
DeleteAppContainerProfile(name.wide)
}

public static func create(
Expand All @@ -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)
Expand All @@ -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
Expand Down
46 changes: 0 additions & 46 deletions windows/Sources/WinSDKExtras/WinSDKExtras.cpp
Original file line number Diff line number Diff line change
@@ -1,53 +1,7 @@
#include "WinSDKExtras.h"

#include <userenv.h>
#include <VersionHelpers.h>

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;
}
Expand Down
25 changes: 1 addition & 24 deletions windows/Sources/WinSDKExtras/include/WinSDKExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,7 @@

#include <windows.h>
#include <sddl.h>

// 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 <userenv.h>

DWORD _PROC_THREAD_ATTRIBUTE_SECURITY_CAPABILITIES();

Expand Down
2 changes: 1 addition & 1 deletion windows/Sources/WindowsUtils/Sid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class Sid: CustomStringConvertible {
let capabilitySids = UnsafeMutablePointer<UnsafeMutablePointer<PSID?>?>.allocate(capacity: 0)
var capabilitySidsCount: DWORD = 0

let result = _DeriveCapabilitySidsFromName(
let result = DeriveCapabilitySidsFromName(
type.wide,
capabilityGroupSids,
&capabilityGroupSidsCount,
Expand Down

0 comments on commit c08be77

Please sign in to comment.