summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Aigner <aigner.erik@gmail.com>2019-08-01 20:04:11 +0200
committerErik Aigner <aigner.erik@gmail.com>2019-08-01 20:04:11 +0200
commit952fbbfbfc624c66405e4ab26e0588d3eaddc5e7 (patch)
tree9a510f0aa42324d1c640da26a5484c19b7ce0e3b
parente3adc99e1f9b71ceaddd650eba9c7c644290e4a6 (diff)
downloadlibgit2-952fbbfbfc624c66405e4ab26e0588d3eaddc5e7.tar.gz
config: check if we are running in a sandboxed environment
On macOS the $HOME environment variable returns the path to the sandbox container instead of the actual user $HOME for sandboxed apps. To get the correct path, we have to get it from the password file entry.
-rw-r--r--src/sysdir.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/sysdir.c b/src/sysdir.c
index e07ba7199..9e86dc88c 100644
--- a/src/sysdir.c
+++ b/src/sysdir.c
@@ -82,15 +82,25 @@ static int git_sysdir_guess_global_dirs(git_buf *out)
#else
int error;
uid_t uid, euid;
+ const char *sandbox_id;
uid = getuid();
euid = geteuid();
+ /**
+ * If APP_SANDBOX_CONTAINER_ID is set, we are running in a
+ * sandboxed environment on macOS.
+ */
+ sandbox_id = getenv("APP_SANDBOX_CONTAINER_ID");
+
/*
* In case we are running setuid, use the configuration
* of the effective user.
+ *
+ * If we are running in a sandboxed environment on macOS,
+ * we have to get the HOME dir from the password entry file.
*/
- if (uid == euid)
+ if (!sandbox_id && uid == euid)
error = git__getenv(out, "HOME");
else
error = get_passwd_home(out, euid);