Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow reordering tabs when UAC is disabled #11221

Merged
4 commits merged into from
Sep 16, 2021
Merged

Conversation

zadjii-msft
Copy link
Member

@zadjii-msft zadjii-msft commented Sep 14, 2021

When we're elevated, we disable drag/dropping tabs when elevated, because of a platform limitation that causes the app to crash (see #4874). However, if the user has UAC disabled, this actually works alright. So I'm adding it back in that case.

I'm not positive if this is the best way to check if UAC is disabled, but normally, you'll get a TokenElevationTypeFull when elevated, not TokenElevationTypeDefault. If the app is elevated, but there's not a split token, that kinda implies there's no user account separation. If I'm wrong, it's just code, let's replace this with something that does work.

Validation Steps Performed

Booted up a Win10 VM, set enableLUA to 0, rebooted, and checked if this exploded. It didn't.

References #4874
References #3581
Work done in pursuit of #11096
Closes #7754

@ghost ghost added Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-2 A description (P2) Product-Terminal The new Windows Terminal. labels Sep 14, 2021
@github-actions

This comment has been minimized.

Comment on lines 146 to 148
OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken);
GetTokenInformation(hToken.get(), TokenElevationType, &elevationType, sizeof(elevationType), &dwSize);
GetTokenInformation(hToken.get(), TokenElevation, &elevationState, sizeof(elevationState), &dwSize);
Copy link
Member

Choose a reason for hiding this comment

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

THROW_IF_WIN32_BOOL_FALSE?

Comment on lines 141 to 148
DWORD dwSize;
wil::unique_handle hToken;
TOKEN_ELEVATION_TYPE elevationType;
TOKEN_ELEVATION elevationState{ 0 };

OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken);
THROW_IF_WIN32_BOOL_FALSE(GetTokenInformation(hToken.get(), TokenElevationType, &elevationType, sizeof(elevationType), &dwSize));
THROW_IF_WIN32_BOOL_FALSE(GetTokenInformation(hToken.get(), TokenElevation, &elevationState, sizeof(elevationState), &dwSize));
Copy link
Member

@DHowett DHowett Sep 15, 2021

Choose a reason for hiding this comment

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

You're gonna think this is crazy, but... check this out.

I think you can do this with WIL, and I believe that you can even use the pseudotokens that do not need lifetime management.

Suggested change
DWORD dwSize;
wil::unique_handle hToken;
TOKEN_ELEVATION_TYPE elevationType;
TOKEN_ELEVATION elevationState{ 0 };
OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken);
THROW_IF_WIN32_BOOL_FALSE(GetTokenInformation(hToken.get(), TokenElevationType, &elevationType, sizeof(elevationType), &dwSize));
THROW_IF_WIN32_BOOL_FALSE(GetTokenInformation(hToken.get(), TokenElevation, &elevationState, sizeof(elevationState), &dwSize));
auto elevationType = wil::get_token_information<TOKEN_ELEVATION_TYPE>(GetCurrentProcessToken());
auto elevationState = wil::get_token_information<TOKEN_ELEVATION>(GetCurrentProcessToken());

Copy link
Member

Choose a reason for hiding this comment

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

Make sure to include token_helpers.h somewhere

Comment on lines 160 to 162
SID_IDENTIFIER_AUTHORITY ntAuthority{ SECURITY_NT_AUTHORITY };
wil::unique_sid adminGroupSid{};
THROW_IF_WIN32_BOOL_FALSE(AllocateAndInitializeSid(&ntAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &adminGroupSid));
Copy link
Member

Choose a reason for hiding this comment

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

holy f---

wil has an automatic helper for this too. wil::test_token_membership. It takes a list of SIDs and Authorities.

https://github.com/microsoft/wil/wiki/Token-Helpers#wiltest_token_membership

Copy link
Member

Choose a reason for hiding this comment

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

If you don't want to do these, I will gladly come by in a followup PR and just do 'em. 😄

@zadjii-msft zadjii-msft added the AutoMerge Marked for automatic merge by the bot when requirements are met label Sep 16, 2021
@ghost
Copy link

ghost commented Sep 16, 2021

Hello @zadjii-msft!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 4793541 into main Sep 16, 2021
@ghost ghost deleted the dev/migrie/b/7754-elevated-tearing branch September 16, 2021 17:13
@ghost
Copy link

ghost commented Oct 20, 2021

🎉Windows Terminal Preview v1.12.2922.0 has been released which incorporates this pull request.:tada:

Handy links:

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-2 A description (P2) Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to drag/drop a file to terminal with UAC turned off
4 participants