|
| 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; |
0 commit comments