diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2014-03-11 14:33:10 +0100 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2014-03-11 14:49:19 +0100 |
commit | 2bd131ba74802f67ce8e9e726b440e12a0b63929 (patch) | |
tree | 7d5933985f04b69a1b99fec116527ee1904801ca | |
parent | 2c9c8cdc100bc2e7fdb69eb9d4ad4312cffc460e (diff) | |
download | libgit2-cmn/config-ignore-access.tar.gz |
repository: allow the global and system configs to fail loadingcmn/config-ignore-access
Common misconfigurations on the server side means that $HOME may point
to the privileged use the application was running as before it dropped
privileges. Similarly, the system config file may not always be
readable.
Allow for reading both of these configurations to fail. This fixes #2122.
-rw-r--r-- | src/repository.c | 6 | ||||
-rw-r--r-- | tests/repo/config.c | 19 |
2 files changed, 22 insertions, 3 deletions
diff --git a/src/repository.c b/src/repository.c index fccc16faa..744bd9860 100644 --- a/src/repository.c +++ b/src/repository.c @@ -538,19 +538,19 @@ static int load_config( git_buf_free(&config_path); if (global_config_path != NULL && - (error = git_config_add_file_ondisk( + (error = git_config_add_file_ondisk_gently( cfg, global_config_path, GIT_CONFIG_LEVEL_GLOBAL, 0)) < 0 && error != GIT_ENOTFOUND) goto on_error; if (xdg_config_path != NULL && - (error = git_config_add_file_ondisk( + (error = git_config_add_file_ondisk_gently( cfg, xdg_config_path, GIT_CONFIG_LEVEL_XDG, 0)) < 0 && error != GIT_ENOTFOUND) goto on_error; if (system_config_path != NULL && - (error = git_config_add_file_ondisk( + (error = git_config_add_file_ondisk_gently( cfg, system_config_path, GIT_CONFIG_LEVEL_SYSTEM, 0)) < 0 && error != GIT_ENOTFOUND) goto on_error; diff --git a/tests/repo/config.c b/tests/repo/config.c index 2e7be37aa..c0597b92c 100644 --- a/tests/repo/config.c +++ b/tests/repo/config.c @@ -51,6 +51,25 @@ void test_repo_config__open_missing_global(void) git_sysdir_global_shutdown(); } +void test_repo_config__inaccessible_global(void) +{ + git_repository *repo; + + cl_git_pass(git_libgit2_opts( + GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr)); + cl_git_pass(git_libgit2_opts( + GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, path.ptr)); + cl_git_pass(git_libgit2_opts( + GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, path.ptr)); + + cl_must_pass(p_chmod(path.ptr, 0000)); + + cl_git_pass(git_repository_open(&repo, "empty_standard_repo")); + git_repository_free(repo); + + cl_must_pass(p_chmod(path.ptr, 0777)); +} + void test_repo_config__open_missing_global_with_separators(void) { git_repository *repo; |