Skip to content

Commit c142e76

Browse files
committed
Add non-elevated admin owner patch to libgit2 overlay
Add patch from libgit2/libgit2#7200 to vcpkg overlay. Allows non-elevated processes run by Administrators group members to be considered the owner of repositories owned by that group. Assisted-by: Claude Opus 4.6 Signed-off-by: Tyrie Vella <tyrielv@gmail.com>
1 parent 3d08ce4 commit c142e76

3 files changed

Lines changed: 77 additions & 0 deletions

File tree

overlays/libgit2/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ that were missing from v1.9.1.
1212

1313
- `dependencies.diff` — adjusts CMake dependency resolution for vcpkg
1414
(copied from official vcpkg port, required for PCRE discovery)
15+
- `non-elevated-admin-owner.diff` — support non-elevated admin user
16+
ownership check on Windows ([libgit2/libgit2#7200](https://github.com/libgit2/libgit2/pull/7200)).
17+
Allows non-elevated processes run by Administrators group members to be
18+
considered the owner of repos owned by that group. Related to
19+
[libgit2/libgit2#6279](https://github.com/libgit2/libgit2/issues/6279).
1520

1621
Additional patches can be added to the `PATCHES` list in `portfile.cmake`
1722
to apply fixes that haven't shipped in an official libgit2 release yet.
@@ -27,6 +32,7 @@ and then modified as noted below.
2732
| `vcpkg.json` | Official vcpkg port | Unchanged |
2833
| `dependencies.diff` | Official vcpkg port | Unchanged |
2934
| `portfile.cmake` | Official vcpkg port | Removed patches not needed for MSVC x64: `c-standard.diff` (C99 inline keyword — MSVC handles natively), `cli-include-dirs.diff` (CLI tool build — we set `BUILD_CLI=OFF`), `mingw-winhttp.diff` (MinGW only) |
35+
| `non-elevated-admin-owner.diff` | [libgit2/libgit2#7200](https://github.com/libgit2/libgit2/pull/7200) | PR diff, verbatim |
3036
| `README.md` | New | VFSForGit-specific documentation |
3137

3238
When updating to a new libgit2 version, compare these files against the
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
diff --git a/src/util/fs_path.c b/src/util/fs_path.c
2+
index ff0836ff874..5be2da35b34 100644
3+
--- a/src/util/fs_path.c
4+
+++ b/src/util/fs_path.c
5+
@@ -1853,12 +1853,16 @@ static PSID *sid_dup(PSID sid)
6+
return dup;
7+
}
8+
9+
-static int current_user_sid(PSID *out)
10+
+static int current_user_sid(PSID *sid, HANDLE *linked_token)
11+
{
12+
TOKEN_USER *info = NULL;
13+
HANDLE token = NULL;
14+
DWORD len = 0;
15+
int error = -1;
16+
+ TOKEN_ELEVATION_TYPE elevation_type;
17+
+ DWORD size;
18+
+
19+
+ *linked_token = NULL;
20+
21+
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token)) {
22+
git_error_set(GIT_ERROR_OS, "could not lookup process information");
23+
@@ -1879,9 +1883,19 @@ static int current_user_sid(PSID *out)
24+
goto done;
25+
}
26+
27+
- if ((*out = sid_dup(info->User.Sid)))
28+
+ if ((*sid = sid_dup(info->User.Sid)))
29+
error = 0;
30+
31+
+ if (GetTokenInformation(token, TokenElevationType, &elevation_type, sizeof(elevation_type), &size) &&
32+
+ elevation_type == TokenElevationTypeLimited) {
33+
+ /*
34+
+ * The current process is run by a member of the Administrators group
35+
+ * but is not running elevated.
36+
+ */
37+
+ if (!GetTokenInformation(token, TokenLinkedToken, linked_token, sizeof(HANDLE), &size)) {
38+
+ linked_token = NULL;
39+
+ }
40+
+ }
41+
done:
42+
if (token)
43+
CloseHandle(token);
44+
@@ -1926,6 +1940,7 @@ int git_fs_path_owner_is(
45+
git_fs_path_owner_t owner_type)
46+
{
47+
PSID owner_sid = NULL, user_sid = NULL;
48+
+ static HANDLE linked_token;
49+
BOOL is_admin, admin_owned;
50+
int error;
51+
52+
@@ -1938,7 +1953,7 @@ int git_fs_path_owner_is(
53+
goto done;
54+
55+
if ((owner_type & GIT_FS_PATH_OWNER_CURRENT_USER) != 0) {
56+
- if ((error = current_user_sid(&user_sid)) < 0)
57+
+ if ((error = current_user_sid(&user_sid, &linked_token)) < 0)
58+
goto done;
59+
60+
if (EqualSid(owner_sid, user_sid)) {
61+
@@ -1959,7 +1974,8 @@ int git_fs_path_owner_is(
62+
63+
if (admin_owned &&
64+
(owner_type & GIT_FS_PATH_USER_IS_ADMINISTRATOR) != 0 &&
65+
- CheckTokenMembership(NULL, owner_sid, &is_admin) &&
66+
+ (CheckTokenMembership(NULL, owner_sid, &is_admin) &&
67+
+ CheckTokenMembership(linked_token, owner_sid, &is_admin)) &&
68+
is_admin) {
69+
*out = true;
70+
goto done;

overlays/libgit2/portfile.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ vcpkg_from_github(
66
HEAD_REF main
77
PATCHES
88
dependencies.diff
9+
non-elevated-admin-owner.diff
910
)
1011

1112
file(REMOVE_RECURSE

0 commit comments

Comments
 (0)