swh:1:snp:47f1e8bb459169b0feb652a9c3d9cbabd8526d4a
Raw File
Tip revision: c522f061d551c9bb8684a7c3859b2ece4499b56b authored by Junio C Hamano on 17 February 2020, 04:37:38 UTC
Git 2.25.1
Tip revision: c522f06
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