swh:1:snp:47f1e8bb459169b0feb652a9c3d9cbabd8526d4a
Raw File
Tip revision: af6b65d45ef179ed52087e80cb089f6b2349f4ec authored by Jonathan Nieder on 19 April 2020, 23:32:24 UTC
Git 2.26.2
Tip revision: af6b65d
access.c
#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;
}
back to top