fs: remove mock naming from change ownership constants The file ownership concepts can reflect the actual file ownership, they are not necessarily limited to mocking the interface. Rename them so that they can be more broadly applicable.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
diff --git a/src/util/fs_path.c b/src/util/fs_path.c
index 9bd773d..58bab70 100644
--- a/src/util/fs_path.c
+++ b/src/util/fs_path.c
@@ -1785,9 +1785,9 @@ done:
return supported;
}
-static git_fs_path__mock_owner_t mock_owner = GIT_FS_PATH_MOCK_OWNER_NONE;
+static git_fs_path_owner_t mock_owner = GIT_FS_PATH_OWNER_NONE;
-void git_fs_path__set_owner(git_fs_path__mock_owner_t owner)
+void git_fs_path__set_owner(git_fs_path_owner_t owner)
{
mock_owner = owner;
}
@@ -1885,7 +1885,7 @@ int git_fs_path_owner_is_current_user(bool *out, const char *path)
int error = -1;
if (mock_owner) {
- *out = (mock_owner == GIT_FS_PATH_MOCK_OWNER_CURRENT_USER);
+ *out = (mock_owner == GIT_FS_PATH_OWNER_CURRENT_USER);
return 0;
}
@@ -1907,7 +1907,7 @@ int git_fs_path_owner_is_system(bool *out, const char *path)
PSID owner_sid;
if (mock_owner) {
- *out = (mock_owner == GIT_FS_PATH_MOCK_OWNER_SYSTEM);
+ *out = (mock_owner == GIT_FS_PATH_OWNER_ADMINISTRATOR);
return 0;
}
@@ -1927,8 +1927,8 @@ int git_fs_path_owner_is_system_or_current_user(bool *out, const char *path)
int error = -1;
if (mock_owner) {
- *out = (mock_owner == GIT_FS_PATH_MOCK_OWNER_SYSTEM ||
- mock_owner == GIT_FS_PATH_MOCK_OWNER_CURRENT_USER);
+ *out = (mock_owner == GIT_FS_PATH_OWNER_ADMINISTRATOR ||
+ mock_owner == GIT_FS_PATH_OWNER_CURRENT_USER);
return 0;
}
@@ -1986,7 +1986,7 @@ int git_fs_path_owner_is_current_user(bool *out, const char *path)
uid_t userid = geteuid();
if (mock_owner) {
- *out = (mock_owner == GIT_FS_PATH_MOCK_OWNER_CURRENT_USER);
+ *out = (mock_owner == GIT_FS_PATH_OWNER_CURRENT_USER);
return 0;
}
@@ -1998,7 +1998,7 @@ int git_fs_path_owner_is_system(bool *out, const char *path)
uid_t userid = 0;
if (mock_owner) {
- *out = (mock_owner == GIT_FS_PATH_MOCK_OWNER_SYSTEM);
+ *out = (mock_owner == GIT_FS_PATH_OWNER_ADMINISTRATOR);
return 0;
}
@@ -2010,8 +2010,8 @@ int git_fs_path_owner_is_system_or_current_user(bool *out, const char *path)
uid_t userids[2] = { geteuid(), 0 };
if (mock_owner) {
- *out = (mock_owner == GIT_FS_PATH_MOCK_OWNER_SYSTEM ||
- mock_owner == GIT_FS_PATH_MOCK_OWNER_CURRENT_USER);
+ *out = (mock_owner == GIT_FS_PATH_OWNER_ADMINISTRATOR ||
+ mock_owner == GIT_FS_PATH_OWNER_CURRENT_USER);
return 0;
}
diff --git a/src/util/fs_path.h b/src/util/fs_path.h
index cf46641..ae28479 100644
--- a/src/util/fs_path.h
+++ b/src/util/fs_path.h
@@ -732,18 +732,31 @@ int git_fs_path_normalize_slashes(git_str *out, const char *path);
bool git_fs_path_supports_symlinks(const char *dir);
typedef enum {
- GIT_FS_PATH_MOCK_OWNER_NONE = 0, /* do filesystem lookups as normal */
- GIT_FS_PATH_MOCK_OWNER_SYSTEM = 1,
- GIT_FS_PATH_MOCK_OWNER_CURRENT_USER = 2,
- GIT_FS_PATH_MOCK_OWNER_OTHER = 3
-} git_fs_path__mock_owner_t;
+ GIT_FS_PATH_OWNER_NONE = 0,
+
+ /** The file must be owned by the current user. */
+ GIT_FS_PATH_OWNER_CURRENT_USER = (1 << 0),
+
+ /** The file must be owned by the system account. */
+ GIT_FS_PATH_OWNER_ADMINISTRATOR = (1 << 1),
+
+ /**
+ * The file may be owned by a system account if the current
+ * user is in an administrator group. Windows only; this is
+ * a noop on non-Windows systems.
+ */
+ GIT_FS_PATH_OWNER_CURRENT_USER_IS_ADMINISTRATOR = (1 << 2),
+
+ /** The file may be owned by another user. */
+ GIT_FS_PATH_OWNER_OTHER = (1 << 4)
+} git_fs_path_owner_t;
/**
* Sets the mock ownership for files; subsequent calls to
- * `git_fs_path_owner_is_*` functions will return this data until cleared
- * with `GIT_FS_PATH_MOCK_OWNER_NONE`.
+ * `git_fs_path_owner_is_*` functions will return this data until
+ * cleared with `GIT_FS_PATH_OWNER_NONE`.
*/
-void git_fs_path__set_owner(git_fs_path__mock_owner_t owner);
+void git_fs_path__set_owner(git_fs_path_owner_t owner);
/**
* Verify that the file in question is owned by an administrator or system
diff --git a/tests/libgit2/repo/open.c b/tests/libgit2/repo/open.c
index 1d0e79e..cb044a0 100644
--- a/tests/libgit2/repo/open.c
+++ b/tests/libgit2/repo/open.c
@@ -22,7 +22,7 @@ void test_repo_open__cleanup(void)
if (git_fs_path_isdir("alternate"))
git_futils_rmdir_r("alternate", NULL, GIT_RMDIR_REMOVE_FILES);
- git_fs_path__set_owner(GIT_FS_PATH_MOCK_OWNER_NONE);
+ git_fs_path__set_owner(GIT_FS_PATH_OWNER_NONE);
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, config_path.ptr));
git_buf_dispose(&config_path);
@@ -481,16 +481,16 @@ void test_repo_open__validates_dir_ownership(void)
cl_git_pass(cl_rename("empty_standard_repo/.gitted", "empty_standard_repo/.git"));
/* When the current user owns the repo config, that's acceptable */
- git_fs_path__set_owner(GIT_FS_PATH_MOCK_OWNER_CURRENT_USER);
+ git_fs_path__set_owner(GIT_FS_PATH_OWNER_CURRENT_USER);
cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
git_repository_free(repo);
/* When the system user owns the repo config, fail */
- git_fs_path__set_owner(GIT_FS_PATH_MOCK_OWNER_SYSTEM);
+ git_fs_path__set_owner(GIT_FS_PATH_OWNER_ADMINISTRATOR);
cl_git_fail(git_repository_open(&repo, "empty_standard_repo"));
/* When an unknown user owns the repo config, fail */
- git_fs_path__set_owner(GIT_FS_PATH_MOCK_OWNER_OTHER);
+ git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER);
cl_git_fail(git_repository_open(&repo, "empty_standard_repo"));
}
@@ -503,16 +503,16 @@ void test_repo_open__validates_bare_repo_ownership(void)
cl_fixture_sandbox("testrepo.git");
/* When the current user owns the repo config, that's acceptable */
- git_fs_path__set_owner(GIT_FS_PATH_MOCK_OWNER_CURRENT_USER);
+ git_fs_path__set_owner(GIT_FS_PATH_OWNER_CURRENT_USER);
cl_git_pass(git_repository_open(&repo, "testrepo.git"));
git_repository_free(repo);
/* When the system user owns the repo config, fail */
- git_fs_path__set_owner(GIT_FS_PATH_MOCK_OWNER_SYSTEM);
+ git_fs_path__set_owner(GIT_FS_PATH_OWNER_ADMINISTRATOR);
cl_git_fail(git_repository_open(&repo, "testrepo.git"));
/* When an unknown user owns the repo config, fail */
- git_fs_path__set_owner(GIT_FS_PATH_MOCK_OWNER_OTHER);
+ git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER);
cl_git_fail(git_repository_open(&repo, "testrepo.git"));
}
@@ -528,7 +528,7 @@ void test_repo_open__can_allowlist_dirs_with_problematic_ownership(void)
cl_fixture_sandbox("empty_standard_repo");
cl_git_pass(cl_rename("empty_standard_repo/.gitted", "empty_standard_repo/.git"));
- git_fs_path__set_owner(GIT_FS_PATH_MOCK_OWNER_OTHER);
+ git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER);
cl_git_fail(git_repository_open(&repo, "empty_standard_repo"));
/* Add safe.directory options to the global configuration */
@@ -572,7 +572,7 @@ void test_repo_open__can_allowlist_bare_gitdir(void)
cl_fixture_sandbox("testrepo.git");
- git_fs_path__set_owner(GIT_FS_PATH_MOCK_OWNER_OTHER);
+ git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER);
cl_git_fail(git_repository_open(&repo, "testrepo.git"));
/* Add safe.directory options to the global configuration */
@@ -617,7 +617,7 @@ void test_repo_open__can_reset_safe_directory_list(void)
cl_fixture_sandbox("empty_standard_repo");
cl_git_pass(cl_rename("empty_standard_repo/.gitted", "empty_standard_repo/.git"));
- git_fs_path__set_owner(GIT_FS_PATH_MOCK_OWNER_OTHER);
+ git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER);
cl_git_fail(git_repository_open(&repo, "empty_standard_repo"));
/* Add safe.directory options to the global configuration */