Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5bc01a7

Browse files
committed
fs: allow ownership match if user is in admin group
Allow the user ownership to match if the file is owned by the admin group and the user is in the admin group, even if the current process is not running as administrator directly.
1 parent 433f016 commit 5bc01a7

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

src/util/fs_path.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,6 +1885,7 @@ int git_fs_path_owner_is(
18851885
git_fs_path_owner_t owner_type)
18861886
{
18871887
PSID owner_sid = NULL, user_sid = NULL;
1888+
BOOL is_admin, admin_owned;
18881889
int error;
18891890

18901891
if (mock_owner) {
@@ -1905,12 +1906,22 @@ int git_fs_path_owner_is(
19051906
}
19061907
}
19071908

1908-
if ((owner_type & GIT_FS_PATH_OWNER_ADMINISTRATOR) != 0) {
1909-
if (IsWellKnownSid(owner_sid, WinBuiltinAdministratorsSid) ||
1910-
IsWellKnownSid(owner_sid, WinLocalSystemSid)) {
1911-
*out = true;
1912-
goto done;
1913-
}
1909+
admin_owned =
1910+
IsWellKnownSid(owner_sid, WinBuiltinAdministratorsSid) ||
1911+
IsWellKnownSid(owner_sid, WinLocalSystemSid);
1912+
1913+
if (admin_owned &&
1914+
(owner_type & GIT_FS_PATH_OWNER_ADMINISTRATOR) != 0) {
1915+
*out = true;
1916+
goto done;
1917+
}
1918+
1919+
if (admin_owned &&
1920+
(owner_type & GIT_FS_PATH_USER_IS_ADMINISTRATOR) != 0 &&
1921+
CheckTokenMembership(NULL, owner_sid, &is_admin) &&
1922+
is_admin) {
1923+
*out = true;
1924+
goto done;
19141925
}
19151926

19161927
*out = false;
@@ -1962,6 +1973,7 @@ int git_fs_path_owner_is(
19621973

19631974
return 0;
19641975
}
1976+
19651977
#endif
19661978

19671979
int git_fs_path_owner_is_current_user(bool *out, const char *path)

src/util/fs_path.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,8 +740,15 @@ typedef enum {
740740
/** The file must be owned by the system account. */
741741
GIT_FS_PATH_OWNER_ADMINISTRATOR = (1 << 1),
742742

743+
/**
744+
* The file may be owned by a system account if the current
745+
* user is in an administrator group. Windows only; this is
746+
* a noop on non-Windows systems.
747+
*/
748+
GIT_FS_PATH_USER_IS_ADMINISTRATOR = (1 << 2),
749+
743750
/** The file may be owned by another user. */
744-
GIT_FS_PATH_OWNER_OTHER = (1 << 2)
751+
GIT_FS_PATH_OWNER_OTHER = (1 << 3)
745752
} git_fs_path_owner_t;
746753

747754
/**

0 commit comments

Comments
 (0)