]> git.ipfire.org Git - thirdparty/git.git/commit
mingw: special-case administrators even more
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Tue, 25 Mar 2025 10:38:29 +0000 (10:38 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 25 Mar 2025 11:45:56 +0000 (04:45 -0700)
commit03a4e46d122d5f24b6e1cd872eb996851c1563da
treecd2af28eb6588e612994ead041381f32bf262c3f
parent683c54c999c301c2cd6f715c411407c413b1d84e
mingw: special-case administrators even more

The check for dubious ownership has one particular quirk on Windows: if
running as an administrator, files owned by the Administrators _group_
are considered owned by the user.

The rationale for that is: When running in elevated mode, Git creates
files that aren't owned by the individual user but by the Administrators
group.

There is yet another quirk, though: The check I introduced to determine
whether the current user is an administrator uses the
`CheckTokenMembership()` function with the current process token. And
that check only succeeds when running in elevated mode!

Let's be a bit more lenient here and look harder whether the current
user is an administrator. We do this by looking for a so-called "linked
token". That token exists when administrators run in non-elevated mode,
and can be used to create a new process in elevated mode. And feeding
_that_ token to the `CheckTokenMembership()` function succeeds!

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
compat/mingw.c