Skip to content

Commit b1c418e

Browse files
committed
Merge branch 'jn/config-ignore-inaccessible' into maint
A git daemon that starts as "root" and then drops privilege often leaves $HOME set to that of the root user, which is unreadable by the daemon process, which was diagnosed as a configuration error. Make per-user configuration files that are inaccessible due to EACCES as though these files do not exist to avoid this issue, as the tightening which was originally meant as an additional security has annoyed enough sysadmins. * jn/config-ignore-inaccessible: config: allow inaccessible configuration under $HOME
2 parents fd50030 + 4698c8f commit b1c418e

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

builtin/config.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
379379
*/
380380
die("$HOME not set");
381381

382-
if (access_or_warn(user_config, R_OK) &&
383-
xdg_config && !access_or_warn(xdg_config, R_OK))
382+
if (access_or_warn(user_config, R_OK, 0) &&
383+
xdg_config && !access_or_warn(xdg_config, R_OK, 0))
384384
given_config_file = xdg_config;
385385
else
386386
given_config_file = user_config;

config.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static int handle_path_include(const char *path, struct config_include_data *inc
5858
path = buf.buf;
5959
}
6060

61-
if (!access_or_die(path, R_OK)) {
61+
if (!access_or_die(path, R_OK, 0)) {
6262
if (++inc->depth > MAX_INCLUDE_DEPTH)
6363
die(include_depth_advice, MAX_INCLUDE_DEPTH, path,
6464
cf && cf->name ? cf->name : "the command line");
@@ -954,23 +954,23 @@ int git_config_early(config_fn_t fn, void *data, const char *repo_config)
954954

955955
home_config_paths(&user_config, &xdg_config, "config");
956956

957-
if (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK)) {
957+
if (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK, 0)) {
958958
ret += git_config_from_file(fn, git_etc_gitconfig(),
959959
data);
960960
found += 1;
961961
}
962962

963-
if (xdg_config && !access_or_die(xdg_config, R_OK)) {
963+
if (xdg_config && !access_or_die(xdg_config, R_OK, ACCESS_EACCES_OK)) {
964964
ret += git_config_from_file(fn, xdg_config, data);
965965
found += 1;
966966
}
967967

968-
if (user_config && !access_or_die(user_config, R_OK)) {
968+
if (user_config && !access_or_die(user_config, R_OK, ACCESS_EACCES_OK)) {
969969
ret += git_config_from_file(fn, user_config, data);
970970
found += 1;
971971
}
972972

973-
if (repo_config && !access_or_die(repo_config, R_OK)) {
973+
if (repo_config && !access_or_die(repo_config, R_OK, 0)) {
974974
ret += git_config_from_file(fn, repo_config, data);
975975
found += 1;
976976
}

dir.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,9 +1545,9 @@ void setup_standard_excludes(struct dir_struct *dir)
15451545
home_config_paths(NULL, &xdg_path, "ignore");
15461546
excludes_file = xdg_path;
15471547
}
1548-
if (!access_or_warn(path, R_OK))
1548+
if (!access_or_warn(path, R_OK, 0))
15491549
add_excludes_from_file(dir, path);
1550-
if (excludes_file && !access_or_warn(excludes_file, R_OK))
1550+
if (excludes_file && !access_or_warn(excludes_file, R_OK, 0))
15511551
add_excludes_from_file(dir, excludes_file);
15521552
}
15531553

git-compat-util.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,9 @@ int remove_or_warn(unsigned int mode, const char *path);
692692
* Call access(2), but warn for any error except "missing file"
693693
* (ENOENT or ENOTDIR).
694694
*/
695-
int access_or_warn(const char *path, int mode);
696-
int access_or_die(const char *path, int mode);
695+
#define ACCESS_EACCES_OK (1U << 0)
696+
int access_or_warn(const char *path, int mode, unsigned flag);
697+
int access_or_die(const char *path, int mode, unsigned flag);
697698

698699
/* Warn on an inaccessible file that ought to be accessible */
699700
void warn_on_inaccessible(const char *path);

wrapper.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,18 +408,24 @@ void warn_on_inaccessible(const char *path)
408408
warning(_("unable to access '%s': %s"), path, strerror(errno));
409409
}
410410

411-
int access_or_warn(const char *path, int mode)
411+
static int access_error_is_ok(int err, unsigned flag)
412+
{
413+
return err == ENOENT || err == ENOTDIR ||
414+
((flag & ACCESS_EACCES_OK) && err == EACCES);
415+
}
416+
417+
int access_or_warn(const char *path, int mode, unsigned flag)
412418
{
413419
int ret = access(path, mode);
414-
if (ret && errno != ENOENT && errno != ENOTDIR)
420+
if (ret && !access_error_is_ok(errno, flag))
415421
warn_on_inaccessible(path);
416422
return ret;
417423
}
418424

419-
int access_or_die(const char *path, int mode)
425+
int access_or_die(const char *path, int mode, unsigned flag)
420426
{
421427
int ret = access(path, mode);
422-
if (ret && errno != ENOENT && errno != ENOTDIR)
428+
if (ret && !access_error_is_ok(errno, flag))
423429
die_errno(_("unable to access '%s'"), path);
424430
return ret;
425431
}

0 commit comments

Comments
 (0)