Cygwin: user profile: Make an effort to unload unused user profiles

Does this work?  There's not much feedback given.

TODO: We might want to try unloading the user profile at process
exit as well, FWIW.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen
2019-02-23 17:30:44 +01:00
parent 331653a215
commit 71b8777a71
6 changed files with 25 additions and 3 deletions

View File

@@ -3603,8 +3603,17 @@ seteuid32 (uid_t uid)
{
NTSTATUS status;
if (!request_restricted_uid_switch)
load_user_profile (new_token, pw_new, usersid);
if (!request_restricted_uid_switch
&& new_token != cygheap->user.imp_profile_token)
{
if (cygheap->user.imp_profile_token && cygheap->user.imp_profile)
unload_user_profile (cygheap->user.imp_profile_token,
cygheap->user.imp_profile);
cygheap->user.imp_profile = load_user_profile (new_token, pw_new,
usersid);
if (cygheap->user.imp_profile)
cygheap->user.imp_profile_token = new_token;
}
/* Try setting owner to same value as user. */
status = NtSetInformationToken (new_token, TokenOwner,
@@ -3634,7 +3643,7 @@ seteuid32 (uid_t uid)
issamesid = (usersid == cygheap->user.sid ());
cygheap->user.set_sid (usersid);
cygheap->user.curr_primary_token = new_token == hProcToken ? NO_IMPERSONATION
: new_token;
: new_token;
cygheap->user.curr_token_is_restricted = false;
cygheap->user.setuid_to_restricted = false;
if (cygheap->user.curr_imp_token != NO_IMPERSONATION)