dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libsec / common / aclmode.c
blobb59f95a72509ea31f20fda4ee3b4c8bfbf7560d4
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
23 * Copyright (c) 1993-1997 by Sun Microsystems, Inc.
24 * All rights reserved
27 #pragma ident "%Z%%M% %I% %E% SMI"
28 /* LINTLIBRARY */
31 * Convert ACL to/from permission bits
34 #include <errno.h>
35 #include <sys/acl.h>
37 int
38 acltomode(aclent_t *aclbufp, int nentries, mode_t *modep)
40 aclent_t *tp;
41 unsigned long mode;
42 unsigned long grpmode;
43 unsigned long mask;
44 int which;
45 int got_mask = 0;
47 *modep = 0;
48 if (aclcheck(aclbufp, nentries, &which) != 0) {
49 errno = EINVAL;
50 return (-1); /* errno is set in aclcheck() */
52 for (tp = aclbufp; nentries--; tp++) {
53 if (tp->a_type == USER_OBJ) {
54 mode = tp->a_perm;
55 if (mode > 07)
56 return (-1);
57 *modep |= (mode << 6);
58 continue;
60 if (tp->a_type == GROUP_OBJ) {
61 grpmode = tp->a_perm;
62 if (grpmode > 07)
63 return (-1);
64 continue;
66 if (tp->a_type == CLASS_OBJ) {
67 got_mask = 1;
68 mask = tp->a_perm;
69 if (mask > 07)
70 return (-1);
71 *modep |= (mask << 3);
72 continue;
74 if (tp->a_type == OTHER_OBJ) {
75 mode = tp->a_perm;
76 if (mode > 07)
77 return (-1);
78 *modep |= mode;
79 continue; /* we may break here if it is sorted */
82 if (!got_mask)
83 *modep |= (grpmode << 3);
84 return (0);
88 int
89 aclfrommode(aclent_t *aclbufp, int nentries, mode_t *modep)
91 aclent_t *tp;
92 aclent_t *savp;
93 mode_t mode;
94 mode_t grpmode;
95 int which;
96 int got_mask = 0;
98 if (aclcheck(aclbufp, nentries, &which) != 0) {
99 errno = EINVAL;
100 return (-1); /* errno is set in aclcheck() */
102 for (tp = aclbufp; nentries--; tp++) {
103 if (tp->a_type == USER_OBJ) {
104 mode = (*modep & 0700);
105 tp->a_perm = (mode >> 6);
106 continue;
108 if (tp->a_type == GROUP_OBJ) {
109 grpmode = (*modep & 070);
110 savp = tp;
111 continue;
113 if (tp->a_type == CLASS_OBJ) {
114 got_mask = 1;
115 mode = (*modep & 070);
116 tp->a_perm = (mode >> 3);
117 continue;
119 if (tp->a_type == OTHER_OBJ) {
120 mode = (*modep & 07);
121 tp->a_perm = (o_mode_t)mode;
122 continue; /* we may break here if it is sorted */
125 if (!got_mask)
126 savp->a_perm = (grpmode >> 3);
127 return (0);