4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
26 #ident "%Z%%M% %I% %E% SMI" /* from SVR4 bnu:strsave.c 1.5 */
30 /* #include <errno.h> */
31 /* #include <malloc.h> */
32 /* #include <string.h> */
33 /* #include <sys/types.h> */
34 /* #include <sys/stat.h> */
36 /* copy str into data space -- caller should report errors. */
44 rval
= (char *)malloc(strlen(str
) + 1);
50 /* Determine if the effective user id has the appropriate permission
51 on a file. Modeled after access(2).
53 00 just checks for file existence.
54 04 checks read permission.
55 02 checks write permission.
56 01 checks execute/search permission.
57 other bits are ignored quietly.
61 eaccess( path
, amode
)
63 register mode_t amode
;
68 if( stat( path
, &s
) == -1 )
69 return(-1); /* can't stat file */
72 if( (euid
= geteuid()) == 0 )
73 return(0); /* root can do all */
74 if( euid
== s
.st_uid
)
75 s
.st_mode
>>= 6; /* use owner bits */
76 else if( getegid() == s
.st_gid
)
77 s
.st_mode
>>= 3; /* use group bits */
79 if( (amode
& s
.st_mode
) == amode
)
80 return(0); /* access permitted */