1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
24 * access() euid/egid implementation
31 #include "FEATURE/eaccess"
39 #if defined(__EXPORT__)
40 #define extern __EXPORT__
44 eaccess(const char* path
, register int flags
)
47 return access(path
, flags
|EFF_ONLY_OK
);
50 return euidaccess(path
, flags
);
67 init
= (ruid
== euid
&& rgid
== egid
) ? 1 : -1;
69 if (init
> 0 || flags
== F_OK
)
70 return access(path
, flags
);
76 if (!S_ISREG(st
.st_mode
) || !(flags
& X_OK
) || (st
.st_mode
& (S_IXUSR
|S_IXGRP
|S_IXOTH
)))
80 else if (euid
== st
.st_uid
)
89 else if (egid
== st
.st_gid
)
106 static int ngroups
= -2;
107 static gid_t
* groups
;
111 if ((ngroups
= getgroups(0, (gid_t
*)0)) <= 0)
112 ngroups
= NGROUPS_MAX
;
113 if (!(groups
= newof(0, gid_t
, ngroups
+ 1, 0)))
116 ngroups
= getgroups(ngroups
, groups
);
120 if (groups
[n
] == st
.st_gid
)
130 if ((st
.st_mode
& mode
) == mode
)