Skip to content

Commit 56aaaf5

Browse files
committed
repo: allow admin owned configs by admin users
Allow users in the administrator group to use git configs that are owned by administrators.
1 parent 5bc01a7 commit 56aaaf5

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/libgit2/repository.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,10 +509,13 @@ static int validate_ownership(const char *repo_path)
509509
{
510510
git_config *config = NULL;
511511
validate_ownership_data data = { repo_path, GIT_STR_INIT, false };
512+
git_fs_path_owner_t owner_level =
513+
GIT_FS_PATH_OWNER_CURRENT_USER |
514+
GIT_FS_PATH_USER_IS_ADMINISTRATOR;
512515
bool is_safe;
513516
int error;
514517

515-
if ((error = git_fs_path_owner_is_current_user(&is_safe, repo_path)) < 0) {
518+
if ((error = git_fs_path_owner_is(&is_safe, repo_path, owner_level)) < 0) {
516519
if (error == GIT_ENOTFOUND)
517520
error = 0;
518521

tests/libgit2/repo/open.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,13 @@ void test_repo_open__validates_dir_ownership(void)
489489
git_fs_path__set_owner(GIT_FS_PATH_OWNER_ADMINISTRATOR);
490490
cl_git_fail(git_repository_open(&repo, "empty_standard_repo"));
491491

492+
#ifdef GIT_WIN32
493+
/* When the user is an administrator, succeed on Windows. */
494+
git_fs_path__set_owner(GIT_FS_PATH_USER_IS_ADMINISTRATOR);
495+
cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
496+
git_repository_free(repo);
497+
#endif
498+
492499
/* When an unknown user owns the repo config, fail */
493500
git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER);
494501
cl_git_fail(git_repository_open(&repo, "empty_standard_repo"));
@@ -511,6 +518,13 @@ void test_repo_open__validates_bare_repo_ownership(void)
511518
git_fs_path__set_owner(GIT_FS_PATH_OWNER_ADMINISTRATOR);
512519
cl_git_fail(git_repository_open(&repo, "testrepo.git"));
513520

521+
#ifdef GIT_WIN32
522+
/* When the user is an administrator, succeed on Windows. */
523+
git_fs_path__set_owner(GIT_FS_PATH_USER_IS_ADMINISTRATOR);
524+
cl_git_pass(git_repository_open(&repo, "testrepo.git"));
525+
git_repository_free(repo);
526+
#endif
527+
514528
/* When an unknown user owns the repo config, fail */
515529
git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER);
516530
cl_git_fail(git_repository_open(&repo, "testrepo.git"));

0 commit comments

Comments
 (0)