xref: /illumos-gate/usr/src/cmd/oamuser/lib/file.c (revision 7c478bd9)
1 /*
2  * CDDL HEADER START
3  *
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
7  * with the License.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 #ident	"%Z%%M%	%I%	%E% SMI"       /* SVr4.0 1.3 */
27 
28 #include	<sys/types.h>
29 #include	<sys/stat.h>
30 
31 int
check_perm(statbuf,uid,gid,perm)32 check_perm( statbuf, uid, gid, perm )
33 struct stat statbuf;
34 uid_t uid;
35 gid_t gid;
36 mode_t perm;
37 {
38 	int fail = -1;	/* assume no permission at onset */
39 
40 	/* Make sure we're dealing with a directory */
41 	if( S_ISDIR( statbuf.st_mode )) {
42 
43 		/*
44 		 * Have a directory, so make sure user has permission
45 		 * by the various possible methods to this directory.
46 		 */
47 		if( (statbuf.st_uid == uid) &&
48 		    (statbuf.st_mode & (perm << 6)) == (perm << 6) )
49 			fail = 0;
50 		else
51 		if( (statbuf.st_gid == gid) &&
52 		    (statbuf.st_mode & (perm << 3)) == (perm << 3) )
53 			fail = 0;
54 		else
55 		if( (statbuf.st_mode & perm) == perm )
56 			fail = 0;
57 	}
58 
59 	return( fail );
60 }
61