Commit a98b7feb by Edward Thomson

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.
parent 3d481958
...@@ -1779,9 +1779,9 @@ done: ...@@ -1779,9 +1779,9 @@ done:
return supported; 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; mock_owner = owner;
} }
...@@ -1879,7 +1879,7 @@ int git_fs_path_owner_is_current_user(bool *out, const char *path) ...@@ -1879,7 +1879,7 @@ int git_fs_path_owner_is_current_user(bool *out, const char *path)
int error = -1; int error = -1;
if (mock_owner) { if (mock_owner) {
*out = (mock_owner == GIT_FS_PATH_MOCK_OWNER_CURRENT_USER); *out = (mock_owner == GIT_FS_PATH_OWNER_CURRENT_USER);
return 0; return 0;
} }
...@@ -1901,7 +1901,7 @@ int git_fs_path_owner_is_system(bool *out, const char *path) ...@@ -1901,7 +1901,7 @@ int git_fs_path_owner_is_system(bool *out, const char *path)
PSID owner_sid; PSID owner_sid;
if (mock_owner) { if (mock_owner) {
*out = (mock_owner == GIT_FS_PATH_MOCK_OWNER_SYSTEM); *out = (mock_owner == GIT_FS_PATH_OWNER_ADMINISTRATOR);
return 0; return 0;
} }
...@@ -1921,8 +1921,8 @@ int git_fs_path_owner_is_system_or_current_user(bool *out, const char *path) ...@@ -1921,8 +1921,8 @@ int git_fs_path_owner_is_system_or_current_user(bool *out, const char *path)
int error = -1; int error = -1;
if (mock_owner) { if (mock_owner) {
*out = (mock_owner == GIT_FS_PATH_MOCK_OWNER_SYSTEM || *out = (mock_owner == GIT_FS_PATH_OWNER_ADMINISTRATOR ||
mock_owner == GIT_FS_PATH_MOCK_OWNER_CURRENT_USER); mock_owner == GIT_FS_PATH_OWNER_CURRENT_USER);
return 0; return 0;
} }
...@@ -1980,7 +1980,7 @@ int git_fs_path_owner_is_current_user(bool *out, const char *path) ...@@ -1980,7 +1980,7 @@ int git_fs_path_owner_is_current_user(bool *out, const char *path)
uid_t userid = geteuid(); uid_t userid = geteuid();
if (mock_owner) { if (mock_owner) {
*out = (mock_owner == GIT_FS_PATH_MOCK_OWNER_CURRENT_USER); *out = (mock_owner == GIT_FS_PATH_OWNER_CURRENT_USER);
return 0; return 0;
} }
...@@ -1992,7 +1992,7 @@ int git_fs_path_owner_is_system(bool *out, const char *path) ...@@ -1992,7 +1992,7 @@ int git_fs_path_owner_is_system(bool *out, const char *path)
uid_t userid = 0; uid_t userid = 0;
if (mock_owner) { if (mock_owner) {
*out = (mock_owner == GIT_FS_PATH_MOCK_OWNER_SYSTEM); *out = (mock_owner == GIT_FS_PATH_OWNER_ADMINISTRATOR);
return 0; return 0;
} }
...@@ -2004,8 +2004,8 @@ int git_fs_path_owner_is_system_or_current_user(bool *out, const char *path) ...@@ -2004,8 +2004,8 @@ int git_fs_path_owner_is_system_or_current_user(bool *out, const char *path)
uid_t userids[2] = { geteuid(), 0 }; uid_t userids[2] = { geteuid(), 0 };
if (mock_owner) { if (mock_owner) {
*out = (mock_owner == GIT_FS_PATH_MOCK_OWNER_SYSTEM || *out = (mock_owner == GIT_FS_PATH_OWNER_ADMINISTRATOR ||
mock_owner == GIT_FS_PATH_MOCK_OWNER_CURRENT_USER); mock_owner == GIT_FS_PATH_OWNER_CURRENT_USER);
return 0; return 0;
} }
......
...@@ -732,18 +732,31 @@ int git_fs_path_normalize_slashes(git_str *out, const char *path); ...@@ -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); bool git_fs_path_supports_symlinks(const char *dir);
typedef enum { typedef enum {
GIT_FS_PATH_MOCK_OWNER_NONE = 0, /* do filesystem lookups as normal */ GIT_FS_PATH_OWNER_NONE = 0,
GIT_FS_PATH_MOCK_OWNER_SYSTEM = 1,
GIT_FS_PATH_MOCK_OWNER_CURRENT_USER = 2, /** The file must be owned by the current user. */
GIT_FS_PATH_MOCK_OWNER_OTHER = 3 GIT_FS_PATH_OWNER_CURRENT_USER = (1 << 0),
} git_fs_path__mock_owner_t;
/** 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 * Sets the mock ownership for files; subsequent calls to
* `git_fs_path_owner_is_*` functions will return this data until cleared * `git_fs_path_owner_is_*` functions will return this data until
* with `GIT_FS_PATH_MOCK_OWNER_NONE`. * 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 * Verify that the file in question is owned by an administrator or system
......
...@@ -22,7 +22,7 @@ void test_repo_open__cleanup(void) ...@@ -22,7 +22,7 @@ void test_repo_open__cleanup(void)
if (git_fs_path_isdir("alternate")) if (git_fs_path_isdir("alternate"))
git_futils_rmdir_r("alternate", NULL, GIT_RMDIR_REMOVE_FILES); 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)); cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, config_path.ptr));
git_buf_dispose(&config_path); git_buf_dispose(&config_path);
...@@ -481,16 +481,16 @@ void test_repo_open__validates_dir_ownership(void) ...@@ -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")); cl_git_pass(cl_rename("empty_standard_repo/.gitted", "empty_standard_repo/.git"));
/* When the current user owns the repo config, that's acceptable */ /* 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")); cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
git_repository_free(repo); git_repository_free(repo);
/* When the system user owns the repo config, fail */ /* 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")); cl_git_fail(git_repository_open(&repo, "empty_standard_repo"));
/* When an unknown user owns the repo config, fail */ /* 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")); cl_git_fail(git_repository_open(&repo, "empty_standard_repo"));
} }
...@@ -503,16 +503,16 @@ void test_repo_open__validates_bare_repo_ownership(void) ...@@ -503,16 +503,16 @@ void test_repo_open__validates_bare_repo_ownership(void)
cl_fixture_sandbox("testrepo.git"); cl_fixture_sandbox("testrepo.git");
/* When the current user owns the repo config, that's acceptable */ /* 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")); cl_git_pass(git_repository_open(&repo, "testrepo.git"));
git_repository_free(repo); git_repository_free(repo);
/* When the system user owns the repo config, fail */ /* 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")); cl_git_fail(git_repository_open(&repo, "testrepo.git"));
/* When an unknown user owns the repo config, fail */ /* 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")); cl_git_fail(git_repository_open(&repo, "testrepo.git"));
} }
...@@ -528,7 +528,7 @@ void test_repo_open__can_allowlist_dirs_with_problematic_ownership(void) ...@@ -528,7 +528,7 @@ void test_repo_open__can_allowlist_dirs_with_problematic_ownership(void)
cl_fixture_sandbox("empty_standard_repo"); cl_fixture_sandbox("empty_standard_repo");
cl_git_pass(cl_rename("empty_standard_repo/.gitted", "empty_standard_repo/.git")); 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")); cl_git_fail(git_repository_open(&repo, "empty_standard_repo"));
/* Add safe.directory options to the global configuration */ /* Add safe.directory options to the global configuration */
...@@ -572,7 +572,7 @@ void test_repo_open__can_allowlist_bare_gitdir(void) ...@@ -572,7 +572,7 @@ void test_repo_open__can_allowlist_bare_gitdir(void)
cl_fixture_sandbox("testrepo.git"); 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")); cl_git_fail(git_repository_open(&repo, "testrepo.git"));
/* Add safe.directory options to the global configuration */ /* Add safe.directory options to the global configuration */
...@@ -617,7 +617,7 @@ void test_repo_open__can_reset_safe_directory_list(void) ...@@ -617,7 +617,7 @@ void test_repo_open__can_reset_safe_directory_list(void)
cl_fixture_sandbox("empty_standard_repo"); cl_fixture_sandbox("empty_standard_repo");
cl_git_pass(cl_rename("empty_standard_repo/.gitted", "empty_standard_repo/.git")); 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")); cl_git_fail(git_repository_open(&repo, "empty_standard_repo"));
/* Add safe.directory options to the global configuration */ /* Add safe.directory options to the global configuration */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment