Skip to content

Add constexpr security descriptor building#628

Open
jonwis wants to merge 6 commits intomicrosoft:masterfrom
jonwis:user/jonwis/static-sddl
Open

Add constexpr security descriptor building#628
jonwis wants to merge 6 commits intomicrosoft:masterfrom
jonwis:user/jonwis/static-sddl

Conversation

@jonwis
Copy link
Copy Markdown
Member

@jonwis jonwis commented Apr 1, 2026

We have a lot of code in various startup paths that uses ConvertStringSecurityDescriptorToSecurityDescriptor, or worse, does hand-building of SECURITY_DESCRIPTOR with building all the ACEs, parsing SID strings, etc.

This introduces a constexpr SD builder, skipping all that and building a self-relative SD at compile time. So now you can say things like:

constexpr auto sd = wil::make_self_relative_sd(
        wil::sd_owner<"S-1-5-32-544">(),                     // BUILTIN\Administrators
        wil::sd_group<"S-1-5-32-545">(),                     // BUILTIN\Users
        wil::make_deny_ace<"S-1-5-7">(GENERIC_WRITE),        // deny ANONYMOUS LOGON
        wil::make_allow_ace<"S-1-5-11">(GENERIC_READ));       // allow Authenticated Users

jonwis added 6 commits April 1, 2026 15:15
…elf_relative_sd(), make_allow_ace(), make_deny_ace(),\nsd_owner(), sd_group(), and no_sid for composing self-relative\nsecurity descriptors at compile time from static SIDs and typed\nACEs. C++20 only, gated behind _HAS_CXX20.\n\nSupports allow/deny ACE types, per-ACE inheritance flags, and\noptional owner/group SIDs. Deny-before-allow ordering enforced\nvia WI_ASSERT."
…n\nParse SID string literals (e.g. \"S-1-5-32-544\") into static_sid_t\nat compile time via C++20 class-type NTTPs. The resulting SID works\nwith all existing helpers: sd_owner, sd_group, make_allow_ace, etc.\n\nGuarded behind __WIL_HAS_CLASS_NTTP which checks for class-type\nNTTP support on both MSVC and Clang."
size_t count = 0;
for (size_t i = 0; i < S.length; ++i)
{
if (S.data[i] == '-')
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Style standard is usually to always have { } even for single line if blocks.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair - i'll ask GHCP why it didn't follow the clang-format conventions.

uint64_t value = 0;
while (pos < len && str[pos] >= '0' && str[pos] <= '9')
{
value = value * 10 + static_cast<uint64_t>(str[pos] - '0');
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to glare at this for a minute to be sure order of operations was intended. Consider adding ( ) around the multiply to make it obviously-intentional.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants