Skip to content

Code/test feature for sharing security descriptors#209

Closed
DefaultRyan wants to merge 18 commits intomicrosoft:mainfrom
DefaultRyan:user/defaultryan/accesscontrol_code
Closed

Code/test feature for sharing security descriptors#209
DefaultRyan wants to merge 18 commits intomicrosoft:mainfrom
DefaultRyan:user/defaultryan/accesscontrol_code

Conversation

@DefaultRyan
Copy link
Copy Markdown
Member

This is the implementation and test code for #188

@ghost ghost added the needs-triage label Sep 24, 2020
@jonwis
Copy link
Copy Markdown
Member

jonwis commented Sep 30, 2020

Can you remove one level of directory structure so it's not "s.ac/s.ac/files" ?

Copy link
Copy Markdown
Member

@jonwis jonwis left a comment

Choose a reason for hiding this comment

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

Is the WinRT variant coming soon?

THROW_WIN32(err);
}
tg.reset(static_cast<TOKEN_GROUPS*>(::HeapAlloc(::GetProcessHeap(), HEAP_ZERO_MEMORY, length)));
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

https://github.com/microsoft/wil/blob/master/include/wil/token_helpers.h could acquire this as a helper! (We need to eventually invert the lookup, so you can pass the token info type you want... there are several information classes that share the same output struct.)

&length));

auto sidLength = ::GetLengthSid(tg->Groups[0].Sid);
result.reset(::HeapAlloc(::GetProcessHeap(), 0, sidLength));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of allocating a new thing, maybe just return "tg" and let the caller root around in it? This is an internal method so nicety isn't necessarily required.

_In_opt_ PSID principal,
uint32_t principalAccessMask,
_Outptr_ PSECURITY_DESCRIPTOR* securityDescriptor
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use a function-level try/catch to reduce one level of indentation. This should probably be marked noexcept as well.

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.

This function is the implementation of a "Flat C" API. So we have a larger question of whether we are going to mark those APIs as noexcept in the headers.

Clearly, that keyword won't work for plain C consumers. It's only available for C++ consumers if they are running C++11 or greater. I'm in favor of this, but not sure if this decision has been made yet.

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.

I have moved the API into extern "C" which has a similar benefit to noexcept when compiling with /EHsc (which is the recommended setting).

try
{
vector<EXPLICIT_ACCESS> ea;
if (accessRequestCount == UINT32_MAX)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Consider removing this "overflow' check; if the reserve fails then eventually the push-backs will fail later and that's OK.

ea.push_back(entry);
}

wil::unique_any<PACL, decltype(&::LocalFree), ::LocalFree> acl;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Another thing to wil-ify as unique_hlocal_acl ? (No rush on any "put this in wil" comments.)


auto result = wil::make_unique_hlocal<SECURITY_DESCRIPTOR>();
THROW_IF_WIN32_BOOL_FALSE(::InitializeSecurityDescriptor(result.get(), SECURITY_DESCRIPTOR_REVISION));
THROW_IF_WIN32_BOOL_FALSE(::SetSecurityDescriptorDacl(result.get(), TRUE, acl.get(), FALSE));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Check out https://docs.microsoft.com/en-us/windows/win32/secauthz/absolute-and-self-relative-security-descriptors - this method needs to hand out a self-relative SD (and be documented as such) so the "binary bytes" thing and freeing the SD works correctly.

{
STARTUPINFO si{};
si.cb = sizeof(si);
PROCESS_INFORMATION pi{};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

See also:

    using unique_process_information = unique_struct<PROCESS_INFORMATION, decltype(&details::CloseProcessInformation), details::CloseProcessInformation>;

@DefaultRyan DefaultRyan changed the base branch from master to main October 29, 2020 20:38
@ghost
Copy link
Copy Markdown

ghost commented Sep 3, 2021

It's sitting idle for like almost one full year. Windows App SDK still only supports medium IL process. Dynamic Dependencies most likely won't support Elevation by this year. No mention of AppContainer scenarios either.

@DefaultRyan Are we about to get sort of an update on this anytime sooner ?

@DefaultRyan
Copy link
Copy Markdown
Member Author

This PR got so old that it was easier to create a new one. See #2005

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.

6 participants