293 useradd/del/mod should be ZFS-aware
[illumos-gate.git] / usr / src / cmd / oamuser / lib / file.c
blob964b21866703c3623c904b6e7bade2f1681abc0a
1 /*
2 * CDDL HEADER START
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.
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]
20 * CDDL HEADER END
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
26 #ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.3 */
28 #include <sys/types.h>
29 #include <sys/stat.h>
31 int
32 check_perm( statbuf, uid, gid, perm )
33 struct stat statbuf;
34 uid_t uid;
35 gid_t gid;
36 mode_t perm;
38 int fail = -1; /* assume no permission at onset */
40 /* Make sure we're dealing with a directory */
41 if( S_ISDIR( statbuf.st_mode )) {
44 * Have a directory, so make sure user has permission
45 * by the various possible methods to this directory.
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;
59 return( fail );