summaryrefslogtreecommitdiff
path: root/compat
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2019-05-13 14:50:35 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-05-13 14:50:35 (GMT)
commit40bef4992ea86b79fa80ebd7e6fd19fecdc5879b (patch)
treeef0cb96e86ee1f50cc1d88d65253af1b74c5b77c /compat
parentb51a0fdc3822c2ef260f6d496b6df6d33b101e8a (diff)
parent400caafb2bb63712bb23cfa4d800261aab8e5cae (diff)
downloadgit-40bef4992ea86b79fa80ebd7e6fd19fecdc5879b.zip
git-40bef4992ea86b79fa80ebd7e6fd19fecdc5879b.tar.gz
git-40bef4992ea86b79fa80ebd7e6fd19fecdc5879b.tar.bz2
Merge branch 'cc/access-on-aix-workaround'
Workaround for standard-compliant but less-than-useful behaviour of access(2) for the root user. * cc/access-on-aix-workaround: git-compat-util: work around for access(X_OK) under root
Diffstat (limited to 'compat')
-rw-r--r--compat/access.c31
-rw-r--r--compat/fileno.c2
2 files changed, 32 insertions, 1 deletions
diff --git a/compat/access.c b/compat/access.c
new file mode 100644
index 0000000..19fda3e
--- /dev/null
+++ b/compat/access.c
@@ -0,0 +1,31 @@
+#define COMPAT_CODE_ACCESS
+#include "../git-compat-util.h"
+
+/* Do the same thing access(2) does, but use the effective uid,
+ * and don't make the mistake of telling root that any file is
+ * executable. This version uses stat(2).
+ */
+int git_access(const char *path, int mode)
+{
+ struct stat st;
+
+ /* do not interfere a normal user */
+ if (geteuid())
+ return access(path, mode);
+
+ if (stat(path, &st) < 0)
+ return -1;
+
+ /* Root can read or write any file. */
+ if (!(mode & X_OK))
+ return 0;
+
+ /* Root can execute any file that has any one of the execute
+ * bits set.
+ */
+ if (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))
+ return 0;
+
+ errno = EACCES;
+ return -1;
+}
diff --git a/compat/fileno.c b/compat/fileno.c
index 7b105f4..8e80ef3 100644
--- a/compat/fileno.c
+++ b/compat/fileno.c
@@ -1,4 +1,4 @@
-#define COMPAT_CODE
+#define COMPAT_CODE_FILENO
#include "../git-compat-util.h"
int git_fileno(FILE *stream)