1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright (c) 1993-1997 by Sun Microsystems, Inc. 24*0Sstevel@tonic-gate * All rights reserved 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate /* LINTLIBRARY */ 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate /* 31*0Sstevel@tonic-gate * Convert ACL to/from permission bits 32*0Sstevel@tonic-gate */ 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gate #include <errno.h> 35*0Sstevel@tonic-gate #include <sys/acl.h> 36*0Sstevel@tonic-gate 37*0Sstevel@tonic-gate int 38*0Sstevel@tonic-gate acltomode(aclent_t *aclbufp, int nentries, mode_t *modep) 39*0Sstevel@tonic-gate { 40*0Sstevel@tonic-gate aclent_t *tp; 41*0Sstevel@tonic-gate unsigned long mode; 42*0Sstevel@tonic-gate unsigned long grpmode; 43*0Sstevel@tonic-gate unsigned long mask; 44*0Sstevel@tonic-gate int which; 45*0Sstevel@tonic-gate int got_mask = 0; 46*0Sstevel@tonic-gate 47*0Sstevel@tonic-gate *modep = 0; 48*0Sstevel@tonic-gate if (aclcheck(aclbufp, nentries, &which) != 0) { 49*0Sstevel@tonic-gate errno = EINVAL; 50*0Sstevel@tonic-gate return (-1); /* errno is set in aclcheck() */ 51*0Sstevel@tonic-gate } 52*0Sstevel@tonic-gate for (tp = aclbufp; nentries--; tp++) { 53*0Sstevel@tonic-gate if (tp->a_type == USER_OBJ) { 54*0Sstevel@tonic-gate mode = tp->a_perm; 55*0Sstevel@tonic-gate if (mode > 07) 56*0Sstevel@tonic-gate return (-1); 57*0Sstevel@tonic-gate *modep |= (mode << 6); 58*0Sstevel@tonic-gate continue; 59*0Sstevel@tonic-gate } 60*0Sstevel@tonic-gate if (tp->a_type == GROUP_OBJ) { 61*0Sstevel@tonic-gate grpmode = tp->a_perm; 62*0Sstevel@tonic-gate if (grpmode > 07) 63*0Sstevel@tonic-gate return (-1); 64*0Sstevel@tonic-gate continue; 65*0Sstevel@tonic-gate } 66*0Sstevel@tonic-gate if (tp->a_type == CLASS_OBJ) { 67*0Sstevel@tonic-gate got_mask = 1; 68*0Sstevel@tonic-gate mask = tp->a_perm; 69*0Sstevel@tonic-gate if (mask > 07) 70*0Sstevel@tonic-gate return (-1); 71*0Sstevel@tonic-gate *modep |= (mask << 3); 72*0Sstevel@tonic-gate continue; 73*0Sstevel@tonic-gate } 74*0Sstevel@tonic-gate if (tp->a_type == OTHER_OBJ) { 75*0Sstevel@tonic-gate mode = tp->a_perm; 76*0Sstevel@tonic-gate if (mode > 07) 77*0Sstevel@tonic-gate return (-1); 78*0Sstevel@tonic-gate *modep |= mode; 79*0Sstevel@tonic-gate continue; /* we may break here if it is sorted */ 80*0Sstevel@tonic-gate } 81*0Sstevel@tonic-gate } 82*0Sstevel@tonic-gate if (!got_mask) 83*0Sstevel@tonic-gate *modep |= (grpmode << 3); 84*0Sstevel@tonic-gate return (0); 85*0Sstevel@tonic-gate } 86*0Sstevel@tonic-gate 87*0Sstevel@tonic-gate 88*0Sstevel@tonic-gate int 89*0Sstevel@tonic-gate aclfrommode(aclent_t *aclbufp, int nentries, mode_t *modep) 90*0Sstevel@tonic-gate { 91*0Sstevel@tonic-gate aclent_t *tp; 92*0Sstevel@tonic-gate aclent_t *savp; 93*0Sstevel@tonic-gate mode_t mode; 94*0Sstevel@tonic-gate mode_t grpmode; 95*0Sstevel@tonic-gate int which; 96*0Sstevel@tonic-gate int got_mask = 0; 97*0Sstevel@tonic-gate 98*0Sstevel@tonic-gate if (aclcheck(aclbufp, nentries, &which) != 0) { 99*0Sstevel@tonic-gate errno = EINVAL; 100*0Sstevel@tonic-gate return (-1); /* errno is set in aclcheck() */ 101*0Sstevel@tonic-gate } 102*0Sstevel@tonic-gate for (tp = aclbufp; nentries--; tp++) { 103*0Sstevel@tonic-gate if (tp->a_type == USER_OBJ) { 104*0Sstevel@tonic-gate mode = (*modep & 0700); 105*0Sstevel@tonic-gate tp->a_perm = (mode >> 6); 106*0Sstevel@tonic-gate continue; 107*0Sstevel@tonic-gate } 108*0Sstevel@tonic-gate if (tp->a_type == GROUP_OBJ) { 109*0Sstevel@tonic-gate grpmode = (*modep & 070); 110*0Sstevel@tonic-gate savp = tp; 111*0Sstevel@tonic-gate continue; 112*0Sstevel@tonic-gate } 113*0Sstevel@tonic-gate if (tp->a_type == CLASS_OBJ) { 114*0Sstevel@tonic-gate got_mask = 1; 115*0Sstevel@tonic-gate mode = (*modep & 070); 116*0Sstevel@tonic-gate tp->a_perm = (mode >> 3); 117*0Sstevel@tonic-gate continue; 118*0Sstevel@tonic-gate } 119*0Sstevel@tonic-gate if (tp->a_type == OTHER_OBJ) { 120*0Sstevel@tonic-gate mode = (*modep & 07); 121*0Sstevel@tonic-gate tp->a_perm = (o_mode_t)mode; 122*0Sstevel@tonic-gate continue; /* we may break here if it is sorted */ 123*0Sstevel@tonic-gate } 124*0Sstevel@tonic-gate } 125*0Sstevel@tonic-gate if (!got_mask) 126*0Sstevel@tonic-gate savp->a_perm = (grpmode >> 3); 127*0Sstevel@tonic-gate return (0); 128*0Sstevel@tonic-gate } 129