File 0018-repo-allow-admin-owned-configs-by-admin-users.patch of Package libgit2.25920

From 9e35f96e616300a04789b6572f874753dc5579af Mon Sep 17 00:00:00 2001
From: Edward Thomson <ethomson@edwardthomson.com>
Date: Mon, 4 Jul 2022 16:03:10 -0400
Subject: [PATCH 18/20] repo: allow admin owned configs by admin users

Allow users in the administrator group to use git configs that are owned
by administrators.
---
 src/repository.c  |  5 ++++-
 tests/repo/open.c | 14 ++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/repository.c b/src/repository.c
index cc69d9692..e770aa961 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -508,10 +508,13 @@ static int validate_ownership(const char *repo_path)
 {
 	git_config *config = NULL;
 	validate_ownership_data data = { repo_path, GIT_BUF_INIT, false };
+	git_path_owner_t owner_level =
+		GIT_PATH_OWNER_CURRENT_USER |
+		GIT_PATH_USER_IS_ADMINISTRATOR;
 	bool is_safe;
 	int error;
 
-	if ((error = git_path_owner_is_current_user(&is_safe, repo_path)) < 0) {
+	if ((error = git_path_owner_is(&is_safe, repo_path, owner_level)) < 0) {
 		if (error == GIT_ENOTFOUND)
 			error = 0;
 
diff --git a/tests/repo/open.c b/tests/repo/open.c
index de15b3fc7..72cdc066f 100644
--- a/tests/repo/open.c
+++ b/tests/repo/open.c
@@ -489,6 +489,13 @@ void test_repo_open__validates_dir_ownership(void)
 	git_path__set_owner(GIT_PATH_OWNER_ADMINISTRATOR);
 	cl_git_fail(git_repository_open(&repo, "empty_standard_repo"));
 
+#ifdef GIT_WIN32
+	/* When the user is an administrator, succeed on Windows. */
+	git_path__set_owner(GIT_PATH_USER_IS_ADMINISTRATOR);
+	cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
+	git_repository_free(repo);
+#endif
+
 	/* When an unknown user owns the repo config, fail */
 	git_path__set_owner(GIT_PATH_OWNER_OTHER);
 	cl_git_fail(git_repository_open(&repo, "empty_standard_repo"));
@@ -511,6 +518,13 @@ void test_repo_open__validates_bare_repo_ownership(void)
 	git_path__set_owner(GIT_PATH_OWNER_ADMINISTRATOR);
 	cl_git_fail(git_repository_open(&repo, "testrepo.git"));
 
+#ifdef GIT_WIN32
+	/* When the user is an administrator, succeed on Windows. */
+	git_path__set_owner(GIT_PATH_USER_IS_ADMINISTRATOR);
+	cl_git_pass(git_repository_open(&repo, "testrepo.git"));
+	git_repository_free(repo);
+#endif
+
 	/* When an unknown user owns the repo config, fail */
 	git_path__set_owner(GIT_PATH_OWNER_OTHER);
 	cl_git_fail(git_repository_open(&repo, "testrepo.git"));
-- 
2.37.1

openSUSE Build Service is sponsored by