Skip to content
  • Jonathan Nieder's avatar
    config: allow inaccessible configuration under $HOME · 4698c8fe
    Jonathan Nieder authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    The changes v1.7.12.1~2^2~4 (config: warn on inaccessible files,
    2012-08-21) and v1.8.1.1~22^2~2 (config: treat user and xdg config
    permission problems as errors, 2012-10-13) were intended to prevent
    important configuration (think "[transfer] fsckobjects") from being
    ignored when the configuration is unintentionally unreadable (for
    example with EIO on a flaky filesystem, or with ENOMEM due to a DoS
    attack).  Usually ~/.gitconfig and ~/.config/git are readable by the
    current user, and if they aren't then it would be easy to fix those
    permissions, so the damage from adding this check should have been
    minimal.
    
    Unfortunately the access() check often trips when git is being run as
    a server.  A daemon (such as inetd or git-daemon) starts as "root",
    creates a listening socket, and then drops privileges, meaning that
    when git commands are invoked they cannot access $HOME and die with
    
     fatal: unable to access '/root/.config/git/config': Permission denied
    
    Any patch to fix this would have one of three problems:
    
      1. We annoy sysadmins who need to take an extra step to handle HOME
         when dropping privileges (the current behavior, or any other
         proposal that they have to opt into).
    
      2. We annoy sysadmins who want to set HOME when dropping privileges,
         either by making what they want to do impossible, or making them
         set an extra variable or option to accomplish what used to work
         (e.g., a patch to git-daemon to set HOME when --user is passed).
    
      3. We loosen the check, so some cases which might be noteworthy are
         not caught.
    
    This patch is of type (3).
    
    Treat user and xdg configuration that are inaccessible due to
    permissions (EACCES) as though no user configuration was provided at
    all.
    
    An alternative method would be to check if $HOME is readable, but that
    would not help in cases where the user who dropped privileges had a
    globally readable HOME with only .config or .gitconfig being private.
    
    This does not change the behavior when /etc/gitconfig or .git/config
    is unreadable (since those are more serious configuration errors),
    nor when ~/.gitconfig or ~/.config/git is unreadable due to problems
    other than permissions.
    
    Signed-off-by: default avatarJonathan Nieder <jrnieder@gmail.com>
    Improved-by: default avatarJeff King <peff@peff.net>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    4698c8fe