17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5ee519a1fSgjelinek * Common Development and Distribution License (the "License"). 6ee519a1fSgjelinek * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22bf8b6031Smarks * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/ 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #include <grp.h> 297c478bd9Sstevel@tonic-gate #include <pwd.h> 307c478bd9Sstevel@tonic-gate #include <string.h> 317c478bd9Sstevel@tonic-gate #include <limits.h> 327c478bd9Sstevel@tonic-gate #include <stdlib.h> 33fa9e4066Sahrens #include <errno.h> 347c478bd9Sstevel@tonic-gate #include <sys/param.h> 357c478bd9Sstevel@tonic-gate #include <sys/types.h> 365a5eeccaSmarks #include <sys/stat.h> 377c478bd9Sstevel@tonic-gate #include <sys/acl.h> 38fa9e4066Sahrens #include <aclutils.h> 39b249c65cSmarks #include <idmap.h> 40fa9e4066Sahrens 415a5eeccaSmarks #define ID_STR_MAX 20 /* digits in LONG_MAX */ 425a5eeccaSmarks 435a5eeccaSmarks #define APPENDED_ID_MAX ID_STR_MAX + 1 /* id + colon */ 445a5eeccaSmarks /* 455a5eeccaSmarks * yyinteractive controls whether yyparse should print out 465a5eeccaSmarks * error messages to stderr, and whether or not id's should be 475a5eeccaSmarks * allowed from acl_fromtext(). 485a5eeccaSmarks */ 495a5eeccaSmarks int yyinteractive; 505a5eeccaSmarks acl_t *yyacl; 515a5eeccaSmarks char *yybuf; 52fa9e4066Sahrens 53fa9e4066Sahrens extern acl_t *acl_alloc(enum acl_type); 547c478bd9Sstevel@tonic-gate 55b249c65cSmarks /* 56b249c65cSmarks * dynamic string that will increase in size on an 57b249c65cSmarks * as needed basis. 58b249c65cSmarks */ 59b249c65cSmarks typedef struct dynaclstr { 60b249c65cSmarks size_t d_bufsize; /* current size of aclexport */ 61b249c65cSmarks char *d_aclexport; 62b249c65cSmarks int d_pos; 63b249c65cSmarks } dynaclstr_t; 6411e32170Shm123892 65b249c65cSmarks static int str_append(dynaclstr_t *, char *); 66b249c65cSmarks static int aclent_perm_txt(dynaclstr_t *, o_mode_t); 677c478bd9Sstevel@tonic-gate 685a5eeccaSmarks static void 695a5eeccaSmarks aclent_perms(int perm, char *txt_perms) 70fa9e4066Sahrens { 715a5eeccaSmarks if (perm & S_IROTH) 725a5eeccaSmarks txt_perms[0] = 'r'; 735a5eeccaSmarks else 745a5eeccaSmarks txt_perms[0] = '-'; 755a5eeccaSmarks if (perm & S_IWOTH) 765a5eeccaSmarks txt_perms[1] = 'w'; 775a5eeccaSmarks else 785a5eeccaSmarks txt_perms[1] = '-'; 795a5eeccaSmarks if (perm & S_IXOTH) 805a5eeccaSmarks txt_perms[2] = 'x'; 815a5eeccaSmarks else 825a5eeccaSmarks txt_perms[2] = '-'; 835a5eeccaSmarks txt_perms[3] = '\0'; 845a5eeccaSmarks } 85fa9e4066Sahrens 865a5eeccaSmarks static char * 87afe1f701Smarks pruname(uid_t uid, char *uidp, size_t buflen, int noresolve) 885a5eeccaSmarks { 8945a17f45Sgjelinek struct passwd *passwdp = NULL; 90fa9e4066Sahrens 9145a17f45Sgjelinek if (noresolve == 0) 925a5eeccaSmarks passwdp = getpwuid(uid); 935a5eeccaSmarks if (passwdp == (struct passwd *)NULL) { 945a5eeccaSmarks /* could not get passwd information: display uid instead */ 95f48205beScasper (void) snprintf(uidp, buflen, "%u", uid); 96afe1f701Smarks } else { 97afe1f701Smarks (void) strlcpy(uidp, passwdp->pw_name, buflen); 98afe1f701Smarks } 995a5eeccaSmarks return (uidp); 1005a5eeccaSmarks } 101fa9e4066Sahrens 1025a5eeccaSmarks static char * 103afe1f701Smarks prgname(gid_t gid, char *gidp, size_t buflen, int noresolve) 1045a5eeccaSmarks { 10545a17f45Sgjelinek struct group *groupp = NULL; 106fa9e4066Sahrens 10745a17f45Sgjelinek if (noresolve == 0) 1085a5eeccaSmarks groupp = getgrgid(gid); 1095a5eeccaSmarks if (groupp == (struct group *)NULL) { 1105a5eeccaSmarks /* could not get group information: display gid instead */ 111f48205beScasper (void) snprintf(gidp, buflen, "%u", gid); 112afe1f701Smarks } else { 113afe1f701Smarks (void) strlcpy(gidp, groupp->gr_name, buflen); 114afe1f701Smarks } 1155a5eeccaSmarks return (gidp); 1165a5eeccaSmarks } 117b249c65cSmarks 118*909c9a9fSMark Shellenbaum static int 119*909c9a9fSMark Shellenbaum getsidname(uid_t who, boolean_t user, char **sidp, boolean_t noresolve) 120b249c65cSmarks { 121b249c65cSmarks idmap_handle_t *idmap_hdl = NULL; 122b249c65cSmarks idmap_get_handle_t *get_hdl = NULL; 123b249c65cSmarks idmap_stat status; 124b249c65cSmarks idmap_rid_t rid; 125*909c9a9fSMark Shellenbaum int error = IDMAP_ERR_NORESULT; 126b249c65cSmarks int len; 127b249c65cSmarks char *domain; 128b249c65cSmarks char *name; 129b249c65cSmarks 130*909c9a9fSMark Shellenbaum *sidp = NULL; 131b249c65cSmarks 132b249c65cSmarks /* 133b249c65cSmarks * First try and get windows name 134b249c65cSmarks */ 135b249c65cSmarks 136*909c9a9fSMark Shellenbaum if (!noresolve) { 137b249c65cSmarks if (user) 138*909c9a9fSMark Shellenbaum error = idmap_getwinnamebyuid(who, 139*909c9a9fSMark Shellenbaum IDMAP_REQ_FLG_USE_CACHE, &name, &domain); 140b249c65cSmarks else 141*909c9a9fSMark Shellenbaum error = idmap_getwinnamebygid(who, 142*909c9a9fSMark Shellenbaum IDMAP_REQ_FLG_USE_CACHE, &name, &domain); 143*909c9a9fSMark Shellenbaum } 144*909c9a9fSMark Shellenbaum if (error != IDMAP_SUCCESS) { 145*909c9a9fSMark Shellenbaum if (idmap_init(&idmap_hdl) == IDMAP_SUCCESS && 146*909c9a9fSMark Shellenbaum idmap_get_create(idmap_hdl, &get_hdl) == IDMAP_SUCCESS) { 147b249c65cSmarks if (user) 148b249c65cSmarks error = idmap_get_sidbyuid(get_hdl, who, 1493ee87bcaSJulian Pullen IDMAP_REQ_FLG_USE_CACHE, &domain, &rid, 1503ee87bcaSJulian Pullen &status); 151b249c65cSmarks else 152b249c65cSmarks error = idmap_get_sidbygid(get_hdl, who, 1533ee87bcaSJulian Pullen IDMAP_REQ_FLG_USE_CACHE, &domain, &rid, 1543ee87bcaSJulian Pullen &status); 155*909c9a9fSMark Shellenbaum if (error == IDMAP_SUCCESS && 156*909c9a9fSMark Shellenbaum idmap_get_mappings(get_hdl) == 0) { 157*909c9a9fSMark Shellenbaum if (status == IDMAP_SUCCESS) { 158*909c9a9fSMark Shellenbaum len = snprintf(NULL, 0, 159*909c9a9fSMark Shellenbaum "%s-%d", domain, rid); 160*909c9a9fSMark Shellenbaum if (*sidp = malloc(len + 1)) { 161*909c9a9fSMark Shellenbaum (void) snprintf(*sidp, len + 1, 162*909c9a9fSMark Shellenbaum "%s-%d", domain, rid); 163b249c65cSmarks } 164*909c9a9fSMark Shellenbaum } 165*909c9a9fSMark Shellenbaum } 166b249c65cSmarks } 167b249c65cSmarks if (get_hdl) 168b249c65cSmarks idmap_get_destroy(get_hdl); 169b249c65cSmarks if (idmap_hdl) 170b249c65cSmarks (void) idmap_fini(idmap_hdl); 171b249c65cSmarks } else { 172b249c65cSmarks int len; 173*909c9a9fSMark Shellenbaum 174b249c65cSmarks len = snprintf(NULL, 0, "%s@%d", name, domain); 175*909c9a9fSMark Shellenbaum if (*sidp = malloc(len + 1)) 176b249c65cSmarks (void) snprintf(*sidp, len + 1, "%s@%s", name, domain); 177b249c65cSmarks } 178*909c9a9fSMark Shellenbaum return (*sidp ? 0 : 1); 179b249c65cSmarks } 180b249c65cSmarks 1815a5eeccaSmarks static void 1825a5eeccaSmarks aclent_printacl(acl_t *aclp) 1835a5eeccaSmarks { 1845a5eeccaSmarks aclent_t *tp; 1855a5eeccaSmarks int aclcnt; 1865a5eeccaSmarks int mask; 1875a5eeccaSmarks int slot = 0; 1885a5eeccaSmarks char perm[4]; 189afe1f701Smarks char uidp[ID_STR_MAX]; 190afe1f701Smarks char gidp[ID_STR_MAX]; 1915a5eeccaSmarks 1925a5eeccaSmarks /* display ACL: assume it is sorted. */ 1935a5eeccaSmarks aclcnt = aclp->acl_cnt; 1945a5eeccaSmarks for (tp = aclp->acl_aclp; tp && aclcnt--; tp++) { 1955a5eeccaSmarks if (tp->a_type == CLASS_OBJ) 1965a5eeccaSmarks mask = tp->a_perm; 1975a5eeccaSmarks } 1985a5eeccaSmarks aclcnt = aclp->acl_cnt; 1995a5eeccaSmarks for (tp = aclp->acl_aclp; aclcnt--; tp++) { 2005a5eeccaSmarks (void) printf(" %d:", slot++); 2015a5eeccaSmarks switch (tp->a_type) { 2025a5eeccaSmarks case USER: 2035a5eeccaSmarks aclent_perms(tp->a_perm, perm); 2045a5eeccaSmarks (void) printf("user:%s:%s\t\t", 205afe1f701Smarks pruname(tp->a_id, uidp, sizeof (uidp), 0), perm); 2065a5eeccaSmarks aclent_perms((tp->a_perm & mask), perm); 2075a5eeccaSmarks (void) printf("#effective:%s\n", perm); 2085a5eeccaSmarks break; 2095a5eeccaSmarks case USER_OBJ: 2105a5eeccaSmarks /* no need to display uid */ 2115a5eeccaSmarks aclent_perms(tp->a_perm, perm); 2125a5eeccaSmarks (void) printf("user::%s\n", perm); 2135a5eeccaSmarks break; 2145a5eeccaSmarks case GROUP: 2155a5eeccaSmarks aclent_perms(tp->a_perm, perm); 2165a5eeccaSmarks (void) printf("group:%s:%s\t\t", 217afe1f701Smarks prgname(tp->a_id, gidp, sizeof (gidp), 0), perm); 2185a5eeccaSmarks aclent_perms(tp->a_perm & mask, perm); 2195a5eeccaSmarks (void) printf("#effective:%s\n", perm); 2205a5eeccaSmarks break; 2215a5eeccaSmarks case GROUP_OBJ: 2225a5eeccaSmarks aclent_perms(tp->a_perm, perm); 2235a5eeccaSmarks (void) printf("group::%s\t\t", perm); 2245a5eeccaSmarks aclent_perms(tp->a_perm & mask, perm); 2255a5eeccaSmarks (void) printf("#effective:%s\n", perm); 2265a5eeccaSmarks break; 2275a5eeccaSmarks case CLASS_OBJ: 2285a5eeccaSmarks aclent_perms(tp->a_perm, perm); 2295a5eeccaSmarks (void) printf("mask:%s\n", perm); 2305a5eeccaSmarks break; 2315a5eeccaSmarks case OTHER_OBJ: 2325a5eeccaSmarks aclent_perms(tp->a_perm, perm); 2335a5eeccaSmarks (void) printf("other:%s\n", perm); 2345a5eeccaSmarks break; 2355a5eeccaSmarks case DEF_USER: 2365a5eeccaSmarks aclent_perms(tp->a_perm, perm); 2375a5eeccaSmarks (void) printf("default:user:%s:%s\n", 238afe1f701Smarks pruname(tp->a_id, uidp, sizeof (uidp), 0), perm); 2395a5eeccaSmarks break; 2405a5eeccaSmarks case DEF_USER_OBJ: 2415a5eeccaSmarks aclent_perms(tp->a_perm, perm); 2425a5eeccaSmarks (void) printf("default:user::%s\n", perm); 2435a5eeccaSmarks break; 2445a5eeccaSmarks case DEF_GROUP: 2455a5eeccaSmarks aclent_perms(tp->a_perm, perm); 2465a5eeccaSmarks (void) printf("default:group:%s:%s\n", 247afe1f701Smarks prgname(tp->a_id, gidp, sizeof (gidp), 0), perm); 2485a5eeccaSmarks break; 2495a5eeccaSmarks case DEF_GROUP_OBJ: 2505a5eeccaSmarks aclent_perms(tp->a_perm, perm); 2515a5eeccaSmarks (void) printf("default:group::%s\n", perm); 2525a5eeccaSmarks break; 2535a5eeccaSmarks case DEF_CLASS_OBJ: 2545a5eeccaSmarks aclent_perms(tp->a_perm, perm); 2555a5eeccaSmarks (void) printf("default:mask:%s\n", perm); 2565a5eeccaSmarks break; 2575a5eeccaSmarks case DEF_OTHER_OBJ: 2585a5eeccaSmarks aclent_perms(tp->a_perm, perm); 2595a5eeccaSmarks (void) printf("default:other:%s\n", perm); 2605a5eeccaSmarks break; 2615a5eeccaSmarks default: 2625a5eeccaSmarks (void) fprintf(stderr, 2635b233e2dSmarks dgettext(TEXT_DOMAIN, "unrecognized entry\n")); 2645a5eeccaSmarks break; 2655a5eeccaSmarks } 2665a5eeccaSmarks } 2675a5eeccaSmarks } 2685a5eeccaSmarks 2695a5eeccaSmarks static void 2705a5eeccaSmarks split_line(char *str, int cols) 2715a5eeccaSmarks { 2725a5eeccaSmarks char *ptr; 2735a5eeccaSmarks int len; 2745a5eeccaSmarks int i; 2755a5eeccaSmarks int last_split; 2765a5eeccaSmarks char *pad = ""; 2775a5eeccaSmarks int pad_len; 2785a5eeccaSmarks 2795a5eeccaSmarks len = strlen(str); 2805a5eeccaSmarks ptr = str; 2815a5eeccaSmarks pad_len = 0; 2825a5eeccaSmarks 2835a5eeccaSmarks ptr = str; 2845a5eeccaSmarks last_split = 0; 2855a5eeccaSmarks for (i = 0; i != len; i++) { 2865a5eeccaSmarks if ((i + pad_len + 4) >= cols) { 2875a5eeccaSmarks (void) printf("%s%.*s\n", pad, last_split, ptr); 2885a5eeccaSmarks ptr = &ptr[last_split]; 2895a5eeccaSmarks len = strlen(ptr); 2905a5eeccaSmarks i = 0; 2915a5eeccaSmarks pad_len = 4; 2925a5eeccaSmarks pad = " "; 2935a5eeccaSmarks } else { 2945a5eeccaSmarks if (ptr[i] == '/' || ptr[i] == ':') { 2955a5eeccaSmarks last_split = i; 2965a5eeccaSmarks } 2975a5eeccaSmarks } 2985a5eeccaSmarks } 2995a5eeccaSmarks if (i == len) { 3005a5eeccaSmarks (void) printf("%s%s\n", pad, ptr); 3015a5eeccaSmarks } 3025a5eeccaSmarks } 3035a5eeccaSmarks 304b249c65cSmarks /* 305b249c65cSmarks * compute entry type string, such as user:joe, group:staff,... 306b249c65cSmarks */ 307b249c65cSmarks static int 308b249c65cSmarks aclent_type_txt(dynaclstr_t *dstr, aclent_t *aclp, int flags) 3095a5eeccaSmarks { 310afe1f701Smarks char idp[ID_STR_MAX]; 311b249c65cSmarks int error; 3125a5eeccaSmarks 313b249c65cSmarks switch (aclp->a_type) { 314b249c65cSmarks case DEF_USER_OBJ: 315b249c65cSmarks case USER_OBJ: 316b249c65cSmarks if (aclp->a_type == USER_OBJ) 317b249c65cSmarks error = str_append(dstr, "user::"); 318b249c65cSmarks else 319b249c65cSmarks error = str_append(dstr, "defaultuser::"); 320b249c65cSmarks break; 321b249c65cSmarks 322b249c65cSmarks case DEF_USER: 323b249c65cSmarks case USER: 324b249c65cSmarks if (aclp->a_type == USER) 325b249c65cSmarks error = str_append(dstr, "user:"); 326b249c65cSmarks else 327b249c65cSmarks error = str_append(dstr, "defaultuser:"); 328b249c65cSmarks if (error) 329b249c65cSmarks break; 330b249c65cSmarks error = str_append(dstr, pruname(aclp->a_id, idp, 331b249c65cSmarks sizeof (idp), flags & ACL_NORESOLVE)); 332b249c65cSmarks if (error == 0) 333b249c65cSmarks error = str_append(dstr, ":"); 334b249c65cSmarks break; 335b249c65cSmarks 336b249c65cSmarks case DEF_GROUP_OBJ: 337b249c65cSmarks case GROUP_OBJ: 338b249c65cSmarks if (aclp->a_type == GROUP_OBJ) 339b249c65cSmarks error = str_append(dstr, "group::"); 340b249c65cSmarks else 341b249c65cSmarks error = str_append(dstr, "defaultgroup::"); 342b249c65cSmarks break; 343b249c65cSmarks 344b249c65cSmarks case DEF_GROUP: 345b249c65cSmarks case GROUP: 346b249c65cSmarks if (aclp->a_type == GROUP) 347b249c65cSmarks error = str_append(dstr, "group:"); 348b249c65cSmarks else 349b249c65cSmarks error = str_append(dstr, "defaultgroup:"); 350b249c65cSmarks if (error) 351b249c65cSmarks break; 352b249c65cSmarks error = str_append(dstr, prgname(aclp->a_id, idp, 353b249c65cSmarks sizeof (idp), flags & ACL_NORESOLVE)); 354b249c65cSmarks if (error == 0) 355b249c65cSmarks error = str_append(dstr, ":"); 356b249c65cSmarks break; 357b249c65cSmarks 358b249c65cSmarks case DEF_CLASS_OBJ: 359b249c65cSmarks case CLASS_OBJ: 360b249c65cSmarks if (aclp->a_type == CLASS_OBJ) 361b249c65cSmarks error = str_append(dstr, "mask:"); 362b249c65cSmarks else 363b249c65cSmarks error = str_append(dstr, "defaultmask:"); 364b249c65cSmarks break; 365b249c65cSmarks 366b249c65cSmarks case DEF_OTHER_OBJ: 367b249c65cSmarks case OTHER_OBJ: 368b249c65cSmarks if (aclp->a_type == OTHER_OBJ) 369b249c65cSmarks error = str_append(dstr, "other:"); 370b249c65cSmarks else 371b249c65cSmarks error = str_append(dstr, "defaultother:"); 372b249c65cSmarks break; 373b249c65cSmarks 374b249c65cSmarks default: 375b249c65cSmarks error = 1; 376b249c65cSmarks break; 377b249c65cSmarks } 378b249c65cSmarks 379b249c65cSmarks return (error); 380b249c65cSmarks } 381b249c65cSmarks 382b249c65cSmarks /* 383b249c65cSmarks * compute entry type string such as, owner@:, user:joe, group:staff,... 384b249c65cSmarks */ 385b249c65cSmarks static int 386b249c65cSmarks ace_type_txt(dynaclstr_t *dynstr, ace_t *acep, int flags) 387b249c65cSmarks { 388b249c65cSmarks char idp[ID_STR_MAX]; 389b249c65cSmarks int error; 390b249c65cSmarks char *sidp = NULL; 3915a5eeccaSmarks 3925a5eeccaSmarks switch (acep->a_flags & ACE_TYPE_FLAGS) { 3935a5eeccaSmarks case ACE_OWNER: 394b249c65cSmarks error = str_append(dynstr, OWNERAT_TXT); 3955a5eeccaSmarks break; 3965a5eeccaSmarks 3975a5eeccaSmarks case ACE_GROUP|ACE_IDENTIFIER_GROUP: 398b249c65cSmarks error = str_append(dynstr, GROUPAT_TXT); 3995a5eeccaSmarks break; 4005a5eeccaSmarks 4015a5eeccaSmarks case ACE_IDENTIFIER_GROUP: 402b249c65cSmarks if ((flags & ACL_SID_FMT) && acep->a_who > MAXUID) { 403b249c65cSmarks if (error = str_append(dynstr, 404b249c65cSmarks GROUPSID_TXT)) 405b249c65cSmarks break; 406*909c9a9fSMark Shellenbaum if (error = getsidname(acep->a_who, B_FALSE, 407*909c9a9fSMark Shellenbaum &sidp, flags & ACL_NORESOLVE)) 408*909c9a9fSMark Shellenbaum break; 409*909c9a9fSMark Shellenbaum error = str_append(dynstr, sidp); 410b249c65cSmarks } else { 411b249c65cSmarks if (error = str_append(dynstr, GROUP_TXT)) 412b249c65cSmarks break; 413b249c65cSmarks error = str_append(dynstr, prgname(acep->a_who, idp, 414afe1f701Smarks sizeof (idp), flags & ACL_NORESOLVE)); 415b249c65cSmarks } 416b249c65cSmarks if (error == 0) 417b249c65cSmarks error = str_append(dynstr, ":"); 4185a5eeccaSmarks break; 4195a5eeccaSmarks 4205a5eeccaSmarks case ACE_EVERYONE: 421b249c65cSmarks error = str_append(dynstr, EVERYONEAT_TXT); 4225a5eeccaSmarks break; 4235a5eeccaSmarks 4245a5eeccaSmarks case 0: 425b249c65cSmarks if ((flags & ACL_SID_FMT) && acep->a_who > MAXUID) { 426b249c65cSmarks if (error = str_append(dynstr, USERSID_TXT)) 427b249c65cSmarks break; 428*909c9a9fSMark Shellenbaum if (error = getsidname(acep->a_who, B_TRUE, 429*909c9a9fSMark Shellenbaum &sidp, flags & ACL_NORESOLVE)) 430*909c9a9fSMark Shellenbaum break; 431*909c9a9fSMark Shellenbaum error = str_append(dynstr, sidp); 432b249c65cSmarks } else { 433b249c65cSmarks if (error = str_append(dynstr, USER_TXT)) 434b249c65cSmarks break; 435b249c65cSmarks error = str_append(dynstr, pruname(acep->a_who, idp, 436afe1f701Smarks sizeof (idp), flags & ACL_NORESOLVE)); 437b249c65cSmarks } 438b249c65cSmarks if (error == 0) 439b249c65cSmarks error = str_append(dynstr, ":"); 440b249c65cSmarks break; 441b249c65cSmarks default: 442b249c65cSmarks error = 0; 4435a5eeccaSmarks break; 4445a5eeccaSmarks } 4455a5eeccaSmarks 446b249c65cSmarks if (sidp) 447b249c65cSmarks free(sidp); 448b249c65cSmarks return (error); 4495a5eeccaSmarks } 4505a5eeccaSmarks 451b249c65cSmarks /* 452b249c65cSmarks * compute string of permissions, such as read_data/write_data or 453b249c65cSmarks * rwxp,... 454b249c65cSmarks * The format depends on the flags field which indicates whether the compact 455b249c65cSmarks * or verbose format should be used. 456b249c65cSmarks */ 457b249c65cSmarks static int 458b249c65cSmarks ace_perm_txt(dynaclstr_t *dstr, uint32_t mask, 4595a5eeccaSmarks uint32_t iflags, int isdir, int flags) 4605a5eeccaSmarks { 461b249c65cSmarks int error = 0; 4625a5eeccaSmarks 4635a5eeccaSmarks if (flags & ACL_COMPACT_FMT) { 464b249c65cSmarks char buf[16]; 4655a5eeccaSmarks 4665a5eeccaSmarks if (mask & ACE_READ_DATA) 4675a5eeccaSmarks buf[0] = 'r'; 4685a5eeccaSmarks else 4695a5eeccaSmarks buf[0] = '-'; 4705a5eeccaSmarks if (mask & ACE_WRITE_DATA) 4715a5eeccaSmarks buf[1] = 'w'; 4725a5eeccaSmarks else 4735a5eeccaSmarks buf[1] = '-'; 4745a5eeccaSmarks if (mask & ACE_EXECUTE) 4755a5eeccaSmarks buf[2] = 'x'; 4765a5eeccaSmarks else 4775a5eeccaSmarks buf[2] = '-'; 4785a5eeccaSmarks if (mask & ACE_APPEND_DATA) 4795a5eeccaSmarks buf[3] = 'p'; 4805a5eeccaSmarks else 4815a5eeccaSmarks buf[3] = '-'; 4825a5eeccaSmarks if (mask & ACE_DELETE) 4835a5eeccaSmarks buf[4] = 'd'; 4845a5eeccaSmarks else 4855a5eeccaSmarks buf[4] = '-'; 4865a5eeccaSmarks if (mask & ACE_DELETE_CHILD) 4875a5eeccaSmarks buf[5] = 'D'; 4885a5eeccaSmarks else 4895a5eeccaSmarks buf[5] = '-'; 4905a5eeccaSmarks if (mask & ACE_READ_ATTRIBUTES) 4915a5eeccaSmarks buf[6] = 'a'; 4925a5eeccaSmarks else 4935a5eeccaSmarks buf[6] = '-'; 4945a5eeccaSmarks if (mask & ACE_WRITE_ATTRIBUTES) 4955a5eeccaSmarks buf[7] = 'A'; 4965a5eeccaSmarks else 4975a5eeccaSmarks buf[7] = '-'; 4985a5eeccaSmarks if (mask & ACE_READ_NAMED_ATTRS) 4995a5eeccaSmarks buf[8] = 'R'; 5005a5eeccaSmarks else 5015a5eeccaSmarks buf[8] = '-'; 5025a5eeccaSmarks if (mask & ACE_WRITE_NAMED_ATTRS) 5035a5eeccaSmarks buf[9] = 'W'; 5045a5eeccaSmarks else 5055a5eeccaSmarks buf[9] = '-'; 5065a5eeccaSmarks if (mask & ACE_READ_ACL) 5075a5eeccaSmarks buf[10] = 'c'; 5085a5eeccaSmarks else 5095a5eeccaSmarks buf[10] = '-'; 5105a5eeccaSmarks if (mask & ACE_WRITE_ACL) 5115a5eeccaSmarks buf[11] = 'C'; 5125a5eeccaSmarks else 5135a5eeccaSmarks buf[11] = '-'; 5145a5eeccaSmarks if (mask & ACE_WRITE_OWNER) 5155a5eeccaSmarks buf[12] = 'o'; 5165a5eeccaSmarks else 5175a5eeccaSmarks buf[12] = '-'; 5185a5eeccaSmarks if (mask & ACE_SYNCHRONIZE) 5195a5eeccaSmarks buf[13] = 's'; 5205a5eeccaSmarks else 5215a5eeccaSmarks buf[13] = '-'; 522b249c65cSmarks buf[14] = ':'; 523b249c65cSmarks buf[15] = '\0'; 524b249c65cSmarks error = str_append(dstr, buf); 5255a5eeccaSmarks } else { 5265a5eeccaSmarks /* 5275a5eeccaSmarks * If ACE is a directory, but inheritance indicates its 5285a5eeccaSmarks * for a file then print permissions for file rather than 5295a5eeccaSmarks * dir. 5305a5eeccaSmarks */ 5315a5eeccaSmarks if (isdir) { 5325a5eeccaSmarks if (mask & ACE_LIST_DIRECTORY) { 5335a5eeccaSmarks if (iflags == ACE_FILE_INHERIT_ACE) { 534b249c65cSmarks error = str_append(dstr, 535b249c65cSmarks READ_DATA_TXT); 5365a5eeccaSmarks } else { 537b249c65cSmarks error = 538b249c65cSmarks str_append(dstr, READ_DIR_TXT); 5395a5eeccaSmarks } 5405a5eeccaSmarks } 541b249c65cSmarks if (error == 0 && (mask & ACE_ADD_FILE)) { 5425a5eeccaSmarks if (iflags == ACE_FILE_INHERIT_ACE) { 543b249c65cSmarks error = 544b249c65cSmarks str_append(dstr, WRITE_DATA_TXT); 5455a5eeccaSmarks } else { 546b249c65cSmarks error = 547b249c65cSmarks str_append(dstr, ADD_FILE_TXT); 5485a5eeccaSmarks } 5495a5eeccaSmarks } 550b249c65cSmarks if (error == 0 && (mask & ACE_ADD_SUBDIRECTORY)) { 5515a5eeccaSmarks if (iflags == ACE_FILE_INHERIT_ACE) { 552b249c65cSmarks error = str_append(dstr, 553b249c65cSmarks APPEND_DATA_TXT); 5545a5eeccaSmarks } else { 555b249c65cSmarks error = str_append(dstr, 556b249c65cSmarks ADD_DIR_TXT); 5575a5eeccaSmarks } 5585a5eeccaSmarks } 5595a5eeccaSmarks } else { 5605a5eeccaSmarks if (mask & ACE_READ_DATA) { 561b249c65cSmarks error = str_append(dstr, READ_DATA_TXT); 5625a5eeccaSmarks } 563b249c65cSmarks if (error == 0 && (mask & ACE_WRITE_DATA)) { 564b249c65cSmarks error = str_append(dstr, WRITE_DATA_TXT); 5655a5eeccaSmarks } 566b249c65cSmarks if (error == 0 && (mask & ACE_APPEND_DATA)) { 567b249c65cSmarks error = str_append(dstr, APPEND_DATA_TXT); 5685a5eeccaSmarks } 5695a5eeccaSmarks } 570b249c65cSmarks if (error == 0 && (mask & ACE_READ_NAMED_ATTRS)) { 571b249c65cSmarks error = str_append(dstr, READ_XATTR_TXT); 5725a5eeccaSmarks } 573b249c65cSmarks if (error == 0 && (mask & ACE_WRITE_NAMED_ATTRS)) { 574b249c65cSmarks error = str_append(dstr, WRITE_XATTR_TXT); 5755a5eeccaSmarks } 576b249c65cSmarks if (error == 0 && (mask & ACE_EXECUTE)) { 577b249c65cSmarks error = str_append(dstr, EXECUTE_TXT); 5785a5eeccaSmarks } 579b249c65cSmarks if (error == 0 && (mask & ACE_DELETE_CHILD)) { 580b249c65cSmarks error = str_append(dstr, DELETE_CHILD_TXT); 5815a5eeccaSmarks } 582b249c65cSmarks if (error == 0 && (mask & ACE_READ_ATTRIBUTES)) { 583b249c65cSmarks error = str_append(dstr, READ_ATTRIBUTES_TXT); 5845a5eeccaSmarks } 585b249c65cSmarks if (error == 0 && (mask & ACE_WRITE_ATTRIBUTES)) { 586b249c65cSmarks error = str_append(dstr, WRITE_ATTRIBUTES_TXT); 5875a5eeccaSmarks } 588b249c65cSmarks if (error == 0 && (mask & ACE_DELETE)) { 589b249c65cSmarks error = str_append(dstr, DELETE_TXT); 5905a5eeccaSmarks } 591b249c65cSmarks if (error == 0 && (mask & ACE_READ_ACL)) { 592b249c65cSmarks error = str_append(dstr, READ_ACL_TXT); 5935a5eeccaSmarks } 594b249c65cSmarks if (error == 0 && (mask & ACE_WRITE_ACL)) { 595b249c65cSmarks error = str_append(dstr, WRITE_ACL_TXT); 5965a5eeccaSmarks } 597b249c65cSmarks if (error == 0 && (mask & ACE_WRITE_OWNER)) { 598b249c65cSmarks error = str_append(dstr, WRITE_OWNER_TXT); 5995a5eeccaSmarks } 600b249c65cSmarks if (error == 0 && (mask & ACE_SYNCHRONIZE)) { 601b249c65cSmarks error = str_append(dstr, SYNCHRONIZE_TXT); 602b249c65cSmarks } 603b249c65cSmarks if (error == 0 && dstr->d_aclexport[dstr->d_pos-1] == '/') { 604b249c65cSmarks dstr->d_aclexport[--dstr->d_pos] = '\0'; 605b249c65cSmarks } 606b249c65cSmarks if (error == 0) 607b249c65cSmarks error = str_append(dstr, ":"); 608b249c65cSmarks } 609b249c65cSmarks return (error); 6105a5eeccaSmarks } 6115a5eeccaSmarks 612b249c65cSmarks /* 613b249c65cSmarks * compute string of access type, such as allow, deny, ... 614b249c65cSmarks */ 615b249c65cSmarks static int 616b249c65cSmarks ace_access_txt(dynaclstr_t *dstr, int type) 6175a5eeccaSmarks { 618b249c65cSmarks int error; 6195a5eeccaSmarks 620b249c65cSmarks if (type == ACE_ACCESS_ALLOWED_ACE_TYPE) 621b249c65cSmarks error = str_append(dstr, ALLOW_TXT); 622b249c65cSmarks else if (type == ACE_ACCESS_DENIED_ACE_TYPE) 623b249c65cSmarks error = str_append(dstr, DENY_TXT); 624b249c65cSmarks else if (type == ACE_SYSTEM_AUDIT_ACE_TYPE) 625b249c65cSmarks error = str_append(dstr, AUDIT_TXT); 626b249c65cSmarks else if (type == ACE_SYSTEM_ALARM_ACE_TYPE) 627b249c65cSmarks error = str_append(dstr, ALARM_TXT); 628b249c65cSmarks else 629b249c65cSmarks error = str_append(dstr, UNKNOWN_TXT); 6305a5eeccaSmarks 631b249c65cSmarks return (error); 6325a5eeccaSmarks } 6335a5eeccaSmarks 634b249c65cSmarks static int 635b249c65cSmarks ace_inherit_txt(dynaclstr_t *dstr, uint32_t iflags, int flags) 6365a5eeccaSmarks { 637b249c65cSmarks int error = 0; 6385a5eeccaSmarks 6395a5eeccaSmarks if (flags & ACL_COMPACT_FMT) { 640b249c65cSmarks char buf[9]; 641b249c65cSmarks 6425a5eeccaSmarks if (iflags & ACE_FILE_INHERIT_ACE) 6435a5eeccaSmarks buf[0] = 'f'; 6445a5eeccaSmarks else 6455a5eeccaSmarks buf[0] = '-'; 6465a5eeccaSmarks if (iflags & ACE_DIRECTORY_INHERIT_ACE) 6475a5eeccaSmarks buf[1] = 'd'; 6485a5eeccaSmarks else 6495a5eeccaSmarks buf[1] = '-'; 6505a5eeccaSmarks if (iflags & ACE_INHERIT_ONLY_ACE) 6515a5eeccaSmarks buf[2] = 'i'; 6525a5eeccaSmarks else 6535a5eeccaSmarks buf[2] = '-'; 6545a5eeccaSmarks if (iflags & ACE_NO_PROPAGATE_INHERIT_ACE) 6555a5eeccaSmarks buf[3] = 'n'; 6565a5eeccaSmarks else 6575a5eeccaSmarks buf[3] = '-'; 6585a5eeccaSmarks if (iflags & ACE_SUCCESSFUL_ACCESS_ACE_FLAG) 6595a5eeccaSmarks buf[4] = 'S'; 6605a5eeccaSmarks else 6615a5eeccaSmarks buf[4] = '-'; 6625a5eeccaSmarks if (iflags & ACE_FAILED_ACCESS_ACE_FLAG) 6635a5eeccaSmarks buf[5] = 'F'; 6645a5eeccaSmarks else 6655a5eeccaSmarks buf[5] = '-'; 666da6c28aaSamw if (iflags & ACE_INHERITED_ACE) 667da6c28aaSamw buf[6] = 'I'; 668da6c28aaSamw else 669da6c28aaSamw buf[6] = '-'; 670b249c65cSmarks buf[7] = ':'; 671b249c65cSmarks buf[8] = '\0'; 672b249c65cSmarks error = str_append(dstr, buf); 6735a5eeccaSmarks } else { 6745a5eeccaSmarks if (iflags & ACE_FILE_INHERIT_ACE) { 675b249c65cSmarks error = str_append(dstr, FILE_INHERIT_TXT); 6765a5eeccaSmarks } 677b249c65cSmarks if (error == 0 && (iflags & ACE_DIRECTORY_INHERIT_ACE)) { 678b249c65cSmarks error = str_append(dstr, DIR_INHERIT_TXT); 6795a5eeccaSmarks } 680b249c65cSmarks if (error == 0 && (iflags & ACE_NO_PROPAGATE_INHERIT_ACE)) { 681b249c65cSmarks error = str_append(dstr, NO_PROPAGATE_TXT); 6825a5eeccaSmarks } 683b249c65cSmarks if (error == 0 && (iflags & ACE_INHERIT_ONLY_ACE)) { 684b249c65cSmarks error = str_append(dstr, INHERIT_ONLY_TXT); 6855a5eeccaSmarks } 686b249c65cSmarks if (error == 0 && (iflags & ACE_SUCCESSFUL_ACCESS_ACE_FLAG)) { 687b249c65cSmarks error = str_append(dstr, SUCCESSFUL_ACCESS_TXT); 688da6c28aaSamw } 689b249c65cSmarks if (error == 0 && (iflags & ACE_FAILED_ACCESS_ACE_FLAG)) { 690b249c65cSmarks error = str_append(dstr, FAILED_ACCESS_TXT); 691da6c28aaSamw } 692b249c65cSmarks if (error == 0 && (iflags & ACE_INHERITED_ACE)) { 693b249c65cSmarks error = str_append(dstr, INHERITED_ACE_TXT); 694b249c65cSmarks } 695b249c65cSmarks if (error == 0 && dstr->d_aclexport[dstr->d_pos-1] == '/') { 696b249c65cSmarks dstr->d_aclexport[--dstr->d_pos] = '\0'; 697b249c65cSmarks error = str_append(dstr, ":"); 698b249c65cSmarks } 699da6c28aaSamw } 7005a5eeccaSmarks 701b249c65cSmarks return (error); 702fa9e4066Sahrens } 7037c478bd9Sstevel@tonic-gate 7047c478bd9Sstevel@tonic-gate /* 7057c478bd9Sstevel@tonic-gate * Convert internal acl representation to external representation. 7067c478bd9Sstevel@tonic-gate * 7077c478bd9Sstevel@tonic-gate * The length of a non-owning user name or non-owning group name ie entries 7087c478bd9Sstevel@tonic-gate * of type DEF_USER, USER, DEF_GROUP or GROUP, can exceed LOGNAME_MAX. We 7097c478bd9Sstevel@tonic-gate * thus check the length of these entries, and if greater than LOGNAME_MAX, 7107c478bd9Sstevel@tonic-gate * we realloc() via increase_length(). 7117c478bd9Sstevel@tonic-gate * 7127c478bd9Sstevel@tonic-gate * The LOGNAME_MAX, ENTRYTYPELEN and PERMS limits are otherwise always 7137c478bd9Sstevel@tonic-gate * adhered to. 7147c478bd9Sstevel@tonic-gate */ 7155a5eeccaSmarks 7165a5eeccaSmarks /* 7175a5eeccaSmarks * acltotext() converts each ACL entry to look like this: 7185a5eeccaSmarks * 7195a5eeccaSmarks * entry_type:uid^gid^name:perms[:id] 7205a5eeccaSmarks * 7215a5eeccaSmarks * The maximum length of entry_type is 14 ("defaultgroup::" and 7225a5eeccaSmarks * "defaultother::") hence ENTRYTYPELEN is set to 14. 7235a5eeccaSmarks * 7245a5eeccaSmarks * The max length of a uid^gid^name entry (in theory) is 8, hence we use, 7255a5eeccaSmarks * however the ID could be a number so we therefore use ID_STR_MAX 7265a5eeccaSmarks * 7275a5eeccaSmarks * The length of a perms entry is 4 to allow for the comma appended to each 7285a5eeccaSmarks * to each acl entry. Hence PERMS is set to 4. 7295a5eeccaSmarks */ 7305a5eeccaSmarks 7315a5eeccaSmarks #define ENTRYTYPELEN 14 7325a5eeccaSmarks #define PERMS 4 7335a5eeccaSmarks #define ACL_ENTRY_SIZE (ENTRYTYPELEN + ID_STR_MAX + PERMS + APPENDED_ID_MAX) 7345a5eeccaSmarks 7357c478bd9Sstevel@tonic-gate char * 7365a5eeccaSmarks aclent_acltotext(aclent_t *aclp, int aclcnt, int flags) 7377c478bd9Sstevel@tonic-gate { 738b249c65cSmarks dynaclstr_t *dstr; 739*909c9a9fSMark Shellenbaum char *aclexport = NULL; 740b249c65cSmarks int i; 741b249c65cSmarks int error = 0; 7427c478bd9Sstevel@tonic-gate 7437c478bd9Sstevel@tonic-gate if (aclp == NULL) 7447c478bd9Sstevel@tonic-gate return (NULL); 745b249c65cSmarks if ((dstr = malloc(sizeof (dynaclstr_t))) == NULL) 7467c478bd9Sstevel@tonic-gate return (NULL); 747b249c65cSmarks dstr->d_bufsize = aclcnt * ACL_ENTRY_SIZE; 748b249c65cSmarks if ((dstr->d_aclexport = malloc(dstr->d_bufsize)) == NULL) { 7497c478bd9Sstevel@tonic-gate free(dstr); 7507c478bd9Sstevel@tonic-gate return (NULL); 7517c478bd9Sstevel@tonic-gate } 752b249c65cSmarks *dstr->d_aclexport = '\0'; 753b249c65cSmarks dstr->d_pos = 0; 7547c478bd9Sstevel@tonic-gate 7557c478bd9Sstevel@tonic-gate for (i = 0; i < aclcnt; i++, aclp++) { 756b249c65cSmarks if (error = aclent_type_txt(dstr, aclp, flags)) 7577c478bd9Sstevel@tonic-gate break; 758b249c65cSmarks if (error = aclent_perm_txt(dstr, aclp->a_perm)) 7597c478bd9Sstevel@tonic-gate break; 7605a5eeccaSmarks 7615a5eeccaSmarks if ((flags & ACL_APPEND_ID) && ((aclp->a_type == USER) || 7625a5eeccaSmarks (aclp->a_type == DEF_USER) || (aclp->a_type == GROUP) || 7635a5eeccaSmarks (aclp->a_type == DEF_GROUP))) { 764b249c65cSmarks char id[ID_STR_MAX], *idstr; 765b249c65cSmarks 766b249c65cSmarks if (error = str_append(dstr, ":")) 767b249c65cSmarks break; 7685a5eeccaSmarks id[ID_STR_MAX - 1] = '\0'; /* null terminate buffer */ 7695a5eeccaSmarks idstr = lltostr(aclp->a_id, &id[ID_STR_MAX - 1]); 770b249c65cSmarks if (error = str_append(dstr, idstr)) 771b249c65cSmarks break; 7725a5eeccaSmarks } 7737c478bd9Sstevel@tonic-gate if (i < aclcnt - 1) 774b249c65cSmarks if (error = str_append(dstr, ",")) 775b249c65cSmarks break; 7767c478bd9Sstevel@tonic-gate } 777b249c65cSmarks if (error) { 778b249c65cSmarks if (dstr->d_aclexport) 779b249c65cSmarks free(dstr->d_aclexport); 780b249c65cSmarks } else { 781b249c65cSmarks aclexport = dstr->d_aclexport; 782b249c65cSmarks } 7837c478bd9Sstevel@tonic-gate free(dstr); 7847c478bd9Sstevel@tonic-gate return (aclexport); 7857c478bd9Sstevel@tonic-gate } 7867c478bd9Sstevel@tonic-gate 7875a5eeccaSmarks char * 7885a5eeccaSmarks acltotext(aclent_t *aclp, int aclcnt) 7897c478bd9Sstevel@tonic-gate { 7905a5eeccaSmarks return (aclent_acltotext(aclp, aclcnt, 0)); 791fa9e4066Sahrens } 792fa9e4066Sahrens 7937c478bd9Sstevel@tonic-gate 794fa9e4066Sahrens aclent_t * 795fa9e4066Sahrens aclfromtext(char *aclstr, int *aclcnt) 796fa9e4066Sahrens { 797fa9e4066Sahrens acl_t *aclp; 798fa9e4066Sahrens aclent_t *aclentp; 799fa9e4066Sahrens int error; 800fa9e4066Sahrens 8015a5eeccaSmarks error = acl_fromtext(aclstr, &aclp); 802fa9e4066Sahrens if (error) 803fa9e4066Sahrens return (NULL); 804fa9e4066Sahrens 805fa9e4066Sahrens aclentp = aclp->acl_aclp; 806fa9e4066Sahrens aclp->acl_aclp = NULL; 807fa9e4066Sahrens *aclcnt = aclp->acl_cnt; 8085a5eeccaSmarks 8095a5eeccaSmarks acl_free(aclp); 810fa9e4066Sahrens return (aclentp); 811fa9e4066Sahrens } 812fa9e4066Sahrens 813fa9e4066Sahrens 8147c478bd9Sstevel@tonic-gate /* 815*909c9a9fSMark Shellenbaum * Append string onto dynaclstr_t. 816*909c9a9fSMark Shellenbaum * 817*909c9a9fSMark Shellenbaum * Return 0 on success, 1 for failure. 8187c478bd9Sstevel@tonic-gate */ 8197c478bd9Sstevel@tonic-gate static int 820b249c65cSmarks str_append(dynaclstr_t *dstr, char *newstr) 8217c478bd9Sstevel@tonic-gate { 822b249c65cSmarks size_t len = strlen(newstr); 8237c478bd9Sstevel@tonic-gate 824b249c65cSmarks if ((len + dstr->d_pos) >= dstr->d_bufsize) { 825b249c65cSmarks dstr->d_aclexport = realloc(dstr->d_aclexport, 826b249c65cSmarks dstr->d_bufsize + len + 1); 827b249c65cSmarks if (dstr->d_aclexport == NULL) 8287c478bd9Sstevel@tonic-gate return (1); 829b249c65cSmarks dstr->d_bufsize += len; 830b249c65cSmarks } 831b249c65cSmarks (void) strcat(&dstr->d_aclexport[dstr->d_pos], newstr); 832b249c65cSmarks dstr->d_pos += len; 8337c478bd9Sstevel@tonic-gate return (0); 8347c478bd9Sstevel@tonic-gate } 835fa9e4066Sahrens 836b249c65cSmarks static int 837b249c65cSmarks aclent_perm_txt(dynaclstr_t *dstr, o_mode_t perm) 838b249c65cSmarks { 839b249c65cSmarks char buf[4]; 840b249c65cSmarks 841b249c65cSmarks if (perm & S_IROTH) 842b249c65cSmarks buf[0] = 'r'; 843b249c65cSmarks else 844b249c65cSmarks buf[0] = '-'; 845b249c65cSmarks if (perm & S_IWOTH) 846b249c65cSmarks buf[1] = 'w'; 847b249c65cSmarks else 848b249c65cSmarks buf[1] = '-'; 849b249c65cSmarks if (perm & S_IXOTH) 850b249c65cSmarks buf[2] = 'x'; 851b249c65cSmarks else 852b249c65cSmarks buf[2] = '-'; 853b249c65cSmarks buf[3] = '\0'; 854b249c65cSmarks return (str_append(dstr, buf)); 855b249c65cSmarks } 856b249c65cSmarks 857fa9e4066Sahrens /* 8585a5eeccaSmarks * ace_acltotext() convert each ace formatted acl to look like this: 859fa9e4066Sahrens * 8605a5eeccaSmarks * entry_type:uid^gid^name:perms[:flags]:<allow|deny>[:id][,] 861fa9e4066Sahrens * 862fa9e4066Sahrens * The maximum length of entry_type is 5 ("group") 863fa9e4066Sahrens * 8645a5eeccaSmarks * The max length of a uid^gid^name entry (in theory) is 8, 8655a5eeccaSmarks * however id could be a number so we therefore use ID_STR_MAX 866fa9e4066Sahrens * 867fa9e4066Sahrens * The length of a perms entry is 144 i.e read_data/write_data... 868fa9e4066Sahrens * to each acl entry. 869fa9e4066Sahrens * 870da6c28aaSamw * iflags: file_inherit/dir_inherit/inherit_only/no_propagate/successful_access 871da6c28aaSamw * /failed_access 872fa9e4066Sahrens * 873fa9e4066Sahrens */ 874fa9e4066Sahrens 875fa9e4066Sahrens #define ACE_ENTRYTYPLEN 6 876da6c28aaSamw #define IFLAGS_STR "file_inherit/dir_inherit/inherit_only/no_propagate/" \ 877da6c28aaSamw "successful_access/failed_access/inherited" 878da6c28aaSamw #define IFLAGS_SIZE (sizeof (IFLAGS_STR) - 1) 8795a5eeccaSmarks #define ACCESS_TYPE_SIZE 7 /* if unknown */ 880fa9e4066Sahrens #define COLON_CNT 3 881fa9e4066Sahrens #define PERMS_LEN 216 8825a5eeccaSmarks #define ACE_ENTRY_SIZE (ACE_ENTRYTYPLEN + ID_STR_MAX + PERMS_LEN + \ 8835a5eeccaSmarks ACCESS_TYPE_SIZE + IFLAGS_SIZE + COLON_CNT + APPENDED_ID_MAX) 884fa9e4066Sahrens 885fa9e4066Sahrens static char * 8865a5eeccaSmarks ace_acltotext(acl_t *aceaclp, int flags) 887fa9e4066Sahrens { 888fa9e4066Sahrens ace_t *aclp = aceaclp->acl_aclp; 889fa9e4066Sahrens int aclcnt = aceaclp->acl_cnt; 8905a5eeccaSmarks int i; 891b249c65cSmarks int error = 0; 892fa9e4066Sahrens int isdir = (aceaclp->acl_flags & ACL_IS_DIR); 893b249c65cSmarks dynaclstr_t *dstr; 894*909c9a9fSMark Shellenbaum char *aclexport = NULL; 895fa9e4066Sahrens 896fa9e4066Sahrens if (aclp == NULL) 897fa9e4066Sahrens return (NULL); 898fa9e4066Sahrens 899b249c65cSmarks if ((dstr = malloc(sizeof (dynaclstr_t))) == NULL) 900b249c65cSmarks return (NULL); 901b249c65cSmarks dstr->d_bufsize = aclcnt * ACL_ENTRY_SIZE; 902b249c65cSmarks if ((dstr->d_aclexport = malloc(dstr->d_bufsize)) == NULL) { 903b249c65cSmarks free(dstr); 904b249c65cSmarks return (NULL); 905b249c65cSmarks } 906b249c65cSmarks *dstr->d_aclexport = '\0'; 907b249c65cSmarks dstr->d_pos = 0; 908b249c65cSmarks 909fa9e4066Sahrens for (i = 0; i < aclcnt; i++, aclp++) { 910fa9e4066Sahrens 911b249c65cSmarks if (error = ace_type_txt(dstr, aclp, flags)) 912b249c65cSmarks break; 913b249c65cSmarks if (error = ace_perm_txt(dstr, aclp->a_access_mask, 914b249c65cSmarks aclp->a_flags, isdir, flags)) 915b249c65cSmarks break; 916b249c65cSmarks if (error = ace_inherit_txt(dstr, aclp->a_flags, flags)) 917b249c65cSmarks break; 918b249c65cSmarks if (error = ace_access_txt(dstr, aclp->a_type)) 919b249c65cSmarks break; 920fa9e4066Sahrens 9215a5eeccaSmarks if ((flags & ACL_APPEND_ID) && 9225a5eeccaSmarks (((aclp->a_flags & ACE_TYPE_FLAGS) == 0) || 9235a5eeccaSmarks ((aclp->a_flags & ACE_TYPE_FLAGS) == 9245a5eeccaSmarks ACE_IDENTIFIER_GROUP))) { 925b249c65cSmarks char id[ID_STR_MAX], *idstr; 926b249c65cSmarks 927b249c65cSmarks if (error = str_append(dstr, ":")) 928b249c65cSmarks break; 9295a5eeccaSmarks id[ID_STR_MAX -1] = '\0'; /* null terminate buffer */ 930b249c65cSmarks idstr = lltostr((aclp->a_who > MAXUID && 931b249c65cSmarks !(flags & ACL_NORESOLVE)) ? UID_NOBODY : 932b249c65cSmarks aclp->a_who, &id[ID_STR_MAX - 1]); 933b249c65cSmarks if (error = str_append(dstr, idstr)) 934b249c65cSmarks break; 9355a5eeccaSmarks } 9365a5eeccaSmarks if (i < aclcnt - 1) { 937b249c65cSmarks if (error = str_append(dstr, ",")) 938b249c65cSmarks break; 939fa9e4066Sahrens } 940fa9e4066Sahrens } 941b249c65cSmarks if (error) { 942b249c65cSmarks if (dstr->d_aclexport) 943b249c65cSmarks free(dstr->d_aclexport); 944b249c65cSmarks } else { 945b249c65cSmarks aclexport = dstr->d_aclexport; 946b249c65cSmarks } 947b249c65cSmarks free(dstr); 948fa9e4066Sahrens return (aclexport); 949fa9e4066Sahrens } 950fa9e4066Sahrens 9515a5eeccaSmarks char * 9525a5eeccaSmarks acl_totext(acl_t *aclp, int flags) 953fa9e4066Sahrens { 9545a5eeccaSmarks char *txtp; 955fa9e4066Sahrens 956fa9e4066Sahrens if (aclp == NULL) 957fa9e4066Sahrens return (NULL); 958fa9e4066Sahrens 959fa9e4066Sahrens switch (aclp->acl_type) { 960fa9e4066Sahrens case ACE_T: 9615a5eeccaSmarks txtp = ace_acltotext(aclp, flags); 9625a5eeccaSmarks break; 963fa9e4066Sahrens case ACLENT_T: 9645a5eeccaSmarks txtp = aclent_acltotext(aclp->acl_aclp, aclp->acl_cnt, flags); 9655a5eeccaSmarks break; 966fa9e4066Sahrens } 9675a5eeccaSmarks 9685a5eeccaSmarks return (txtp); 969fa9e4066Sahrens } 970fa9e4066Sahrens 971fa9e4066Sahrens int 972fa9e4066Sahrens acl_fromtext(const char *acltextp, acl_t **ret_aclp) 973fa9e4066Sahrens { 9745a5eeccaSmarks int error; 9755a5eeccaSmarks char *buf; 9765a5eeccaSmarks 9775a5eeccaSmarks buf = malloc(strlen(acltextp) + 2); 9785a5eeccaSmarks if (buf == NULL) 9795a5eeccaSmarks return (EACL_MEM_ERROR); 9805a5eeccaSmarks strcpy(buf, acltextp); 9815a5eeccaSmarks strcat(buf, "\n"); 9825a5eeccaSmarks yybuf = buf; 9835a5eeccaSmarks yyreset(); 9845a5eeccaSmarks error = yyparse(); 9855a5eeccaSmarks free(buf); 9865a5eeccaSmarks 9875a5eeccaSmarks if (yyacl) { 9885a5eeccaSmarks if (error == 0) 9895a5eeccaSmarks *ret_aclp = yyacl; 9905a5eeccaSmarks else { 9915a5eeccaSmarks acl_free(yyacl); 9925a5eeccaSmarks } 9935a5eeccaSmarks yyacl = NULL; 9945a5eeccaSmarks } 9955a5eeccaSmarks return (error); 9965a5eeccaSmarks } 9975a5eeccaSmarks 9985a5eeccaSmarks int 9995a5eeccaSmarks acl_parse(const char *acltextp, acl_t **aclp) 10005a5eeccaSmarks { 1001fa9e4066Sahrens int error; 1002fa9e4066Sahrens 10035a5eeccaSmarks yyinteractive = 1; 10045a5eeccaSmarks error = acl_fromtext(acltextp, aclp); 10055a5eeccaSmarks yyinteractive = 0; 1006fa9e4066Sahrens return (error); 1007fa9e4066Sahrens } 10085a5eeccaSmarks 10095a5eeccaSmarks static void 10105a5eeccaSmarks ace_compact_printacl(acl_t *aclp) 10115a5eeccaSmarks { 10125a5eeccaSmarks int cnt; 10135a5eeccaSmarks ace_t *acep; 1014b249c65cSmarks dynaclstr_t *dstr; 1015b249c65cSmarks int len; 10165a5eeccaSmarks 1017b249c65cSmarks if ((dstr = malloc(sizeof (dynaclstr_t))) == NULL) 1018b249c65cSmarks return; 1019b249c65cSmarks dstr->d_bufsize = ACE_ENTRY_SIZE; 1020b249c65cSmarks if ((dstr->d_aclexport = malloc(dstr->d_bufsize)) == NULL) { 1021b249c65cSmarks free(dstr); 1022b249c65cSmarks return; 1023b249c65cSmarks } 1024b249c65cSmarks *dstr->d_aclexport = '\0'; 1025b249c65cSmarks 1026b249c65cSmarks dstr->d_pos = 0; 10275a5eeccaSmarks for (cnt = 0, acep = aclp->acl_aclp; 10285a5eeccaSmarks cnt != aclp->acl_cnt; cnt++, acep++) { 1029b249c65cSmarks dstr->d_aclexport[0] = '\0'; 1030b249c65cSmarks dstr->d_pos = 0; 1031b249c65cSmarks 1032b249c65cSmarks if (ace_type_txt(dstr, acep, 0)) 1033b249c65cSmarks break; 1034b249c65cSmarks len = strlen(&dstr->d_aclexport[0]); 1035b249c65cSmarks if (ace_perm_txt(dstr, acep->a_access_mask, acep->a_flags, 1036b249c65cSmarks aclp->acl_flags & ACL_IS_DIR, ACL_COMPACT_FMT)) 1037b249c65cSmarks break; 1038b249c65cSmarks if (ace_inherit_txt(dstr, acep->a_flags, ACL_COMPACT_FMT)) 1039b249c65cSmarks break; 1040b249c65cSmarks if (ace_access_txt(dstr, acep->a_type) == -1) 1041b249c65cSmarks break; 1042b249c65cSmarks (void) printf(" %20.*s%s\n", len, dstr->d_aclexport, 1043b249c65cSmarks &dstr->d_aclexport[len]); 10445a5eeccaSmarks } 1045b249c65cSmarks 1046b249c65cSmarks if (dstr->d_aclexport) 1047b249c65cSmarks free(dstr->d_aclexport); 1048b249c65cSmarks free(dstr); 10495a5eeccaSmarks } 10505a5eeccaSmarks 10515a5eeccaSmarks static void 10525a5eeccaSmarks ace_printacl(acl_t *aclp, int cols, int compact) 10535a5eeccaSmarks { 10545a5eeccaSmarks int slot = 0; 10555a5eeccaSmarks char *token; 10565a5eeccaSmarks char *acltext; 10575a5eeccaSmarks 10585a5eeccaSmarks if (compact) { 10595a5eeccaSmarks ace_compact_printacl(aclp); 10605a5eeccaSmarks return; 10615a5eeccaSmarks } 10625a5eeccaSmarks 10635a5eeccaSmarks acltext = acl_totext(aclp, 0); 10645a5eeccaSmarks 10655a5eeccaSmarks if (acltext == NULL) 10665a5eeccaSmarks return; 10675a5eeccaSmarks 10685a5eeccaSmarks token = strtok(acltext, ","); 10695a5eeccaSmarks if (token == NULL) { 10705a5eeccaSmarks free(acltext); 10715a5eeccaSmarks return; 10725a5eeccaSmarks } 10735a5eeccaSmarks 10745a5eeccaSmarks do { 10755a5eeccaSmarks (void) printf(" %d:", slot++); 10765a5eeccaSmarks split_line(token, cols - 5); 10775a5eeccaSmarks } while (token = strtok(NULL, ",")); 10785a5eeccaSmarks free(acltext); 10795a5eeccaSmarks } 10805a5eeccaSmarks 10815a5eeccaSmarks /* 10825a5eeccaSmarks * pretty print an ACL. 10835a5eeccaSmarks * For aclent_t ACL's the format is 10845a5eeccaSmarks * similar to the old format used by getfacl, 10855a5eeccaSmarks * with the addition of adding a "slot" number 10865a5eeccaSmarks * before each entry. 10875a5eeccaSmarks * 10885a5eeccaSmarks * for ace_t ACL's the cols variable will break up 10895a5eeccaSmarks * the long lines into multiple lines and will also 10905a5eeccaSmarks * print a "slot" number. 10915a5eeccaSmarks */ 10925a5eeccaSmarks void 10935a5eeccaSmarks acl_printacl(acl_t *aclp, int cols, int compact) 10945a5eeccaSmarks { 10955a5eeccaSmarks 10965a5eeccaSmarks switch (aclp->acl_type) { 10975a5eeccaSmarks case ACLENT_T: 10985a5eeccaSmarks aclent_printacl(aclp); 10995a5eeccaSmarks break; 11005a5eeccaSmarks case ACE_T: 11015a5eeccaSmarks ace_printacl(aclp, cols, compact); 11025a5eeccaSmarks break; 11035a5eeccaSmarks } 11045a5eeccaSmarks } 11055a5eeccaSmarks 11065a5eeccaSmarks typedef struct value_table { 11075a5eeccaSmarks char p_letter; /* perm letter such as 'r' */ 11085a5eeccaSmarks uint32_t p_value; /* value for perm when pletter found */ 11095a5eeccaSmarks } value_table_t; 11105a5eeccaSmarks 11115a5eeccaSmarks /* 1112da6c28aaSamw * The permission tables are laid out in positional order 11135a5eeccaSmarks * a '-' character will indicate a permission at a given 11145a5eeccaSmarks * position is not specified. The '-' is not part of the 11155a5eeccaSmarks * table, but will be checked for in the permission computation 11165a5eeccaSmarks * routine. 11175a5eeccaSmarks */ 1118da6c28aaSamw value_table_t ace_perm_table[] = { 11195a5eeccaSmarks { 'r', ACE_READ_DATA}, 11205a5eeccaSmarks { 'w', ACE_WRITE_DATA}, 11215a5eeccaSmarks { 'x', ACE_EXECUTE}, 11225a5eeccaSmarks { 'p', ACE_APPEND_DATA}, 11235a5eeccaSmarks { 'd', ACE_DELETE}, 11245a5eeccaSmarks { 'D', ACE_DELETE_CHILD}, 11255a5eeccaSmarks { 'a', ACE_READ_ATTRIBUTES}, 11265a5eeccaSmarks { 'A', ACE_WRITE_ATTRIBUTES}, 11275a5eeccaSmarks { 'R', ACE_READ_NAMED_ATTRS}, 11285a5eeccaSmarks { 'W', ACE_WRITE_NAMED_ATTRS}, 11295a5eeccaSmarks { 'c', ACE_READ_ACL}, 11305a5eeccaSmarks { 'C', ACE_WRITE_ACL}, 11315a5eeccaSmarks { 'o', ACE_WRITE_OWNER}, 11325a5eeccaSmarks { 's', ACE_SYNCHRONIZE} 11335a5eeccaSmarks }; 11345a5eeccaSmarks 1135da6c28aaSamw #define ACE_PERM_COUNT (sizeof (ace_perm_table) / sizeof (value_table_t)) 11365a5eeccaSmarks 1137da6c28aaSamw value_table_t aclent_perm_table[] = { 11385a5eeccaSmarks { 'r', S_IROTH}, 11395a5eeccaSmarks { 'w', S_IWOTH}, 11405a5eeccaSmarks { 'x', S_IXOTH} 11415a5eeccaSmarks }; 11425a5eeccaSmarks 1143da6c28aaSamw #define ACLENT_PERM_COUNT (sizeof (aclent_perm_table) / sizeof (value_table_t)) 1144da6c28aaSamw 1145da6c28aaSamw value_table_t inherit_table[] = { 11465a5eeccaSmarks {'f', ACE_FILE_INHERIT_ACE}, 11475a5eeccaSmarks {'d', ACE_DIRECTORY_INHERIT_ACE}, 11485a5eeccaSmarks {'i', ACE_INHERIT_ONLY_ACE}, 11495a5eeccaSmarks {'n', ACE_NO_PROPAGATE_INHERIT_ACE}, 11505a5eeccaSmarks {'S', ACE_SUCCESSFUL_ACCESS_ACE_FLAG}, 1151da6c28aaSamw {'F', ACE_FAILED_ACCESS_ACE_FLAG}, 1152da6c28aaSamw {'I', ACE_INHERITED_ACE} 11535a5eeccaSmarks }; 11545a5eeccaSmarks 1155da6c28aaSamw #define IFLAG_COUNT (sizeof (inherit_table) / sizeof (value_table_t)) 1156bf8b6031Smarks #define IFLAG_COUNT_V1 6 /* Older version compatibility */ 1157da6c28aaSamw 11585a5eeccaSmarks /* 11595a5eeccaSmarks * compute value from a permission table or inheritance table 11605a5eeccaSmarks * based on string passed in. If positional is set then 11615a5eeccaSmarks * string must match order in permtab, otherwise any order 11625a5eeccaSmarks * is allowed. 11635a5eeccaSmarks */ 11645a5eeccaSmarks int 11655a5eeccaSmarks compute_values(value_table_t *permtab, int count, 11665a5eeccaSmarks char *permstr, int positional, uint32_t *mask) 11675a5eeccaSmarks { 11685a5eeccaSmarks uint32_t perm_val = 0; 11695a5eeccaSmarks char *pstr; 11705a5eeccaSmarks int i, found; 11715a5eeccaSmarks 11725a5eeccaSmarks if (count < 0) 11735a5eeccaSmarks return (1); 11745a5eeccaSmarks 11755a5eeccaSmarks if (positional) { 11765a5eeccaSmarks for (i = 0, pstr = permstr; i != count && pstr && 11775a5eeccaSmarks *pstr; i++, pstr++) { 11785a5eeccaSmarks if (*pstr == permtab[i].p_letter) { 11795a5eeccaSmarks perm_val |= permtab[i].p_value; 11805a5eeccaSmarks } else if (*pstr != '-') { 11815a5eeccaSmarks return (1); 11825a5eeccaSmarks } 11835a5eeccaSmarks } 11845a5eeccaSmarks } else { /* random order single letters with no '-' */ 11855a5eeccaSmarks for (pstr = permstr; pstr && *pstr; pstr++) { 11865a5eeccaSmarks for (found = 0, i = 0; i != count; i++) { 11875a5eeccaSmarks if (*pstr == permtab[i].p_letter) { 11885a5eeccaSmarks perm_val |= permtab[i].p_value; 11895a5eeccaSmarks found = 1; 11905a5eeccaSmarks break; 11915a5eeccaSmarks } 11925a5eeccaSmarks } 11935a5eeccaSmarks if (found == 0) 11945a5eeccaSmarks return (1); 11955a5eeccaSmarks } 11965a5eeccaSmarks } 11975a5eeccaSmarks 11985a5eeccaSmarks *mask = perm_val; 11995a5eeccaSmarks return (0); 12005a5eeccaSmarks } 12015a5eeccaSmarks 1202bf8b6031Smarks 1203bf8b6031Smarks int 1204bf8b6031Smarks ace_inherit_helper(char *str, uint32_t *imask, int table_length) 1205bf8b6031Smarks { 1206bf8b6031Smarks int rc = 0; 1207bf8b6031Smarks 1208bf8b6031Smarks if (strlen(str) == table_length) { 1209bf8b6031Smarks /* 1210bf8b6031Smarks * If the string == table_length then first check to see it's 1211bf8b6031Smarks * in positional format. If that fails then see if it's in 1212bf8b6031Smarks * non-positional format. 1213bf8b6031Smarks */ 1214bf8b6031Smarks if (compute_values(inherit_table, table_length, str, 1215bf8b6031Smarks 1, imask) && compute_values(inherit_table, 1216bf8b6031Smarks table_length, str, 0, imask)) { 1217bf8b6031Smarks rc = 1; 1218bf8b6031Smarks } 1219bf8b6031Smarks } else { 1220bf8b6031Smarks rc = compute_values(inherit_table, table_length, str, 0, imask); 1221bf8b6031Smarks } 1222bf8b6031Smarks 1223bf8b6031Smarks return (rc ? EACL_INHERIT_ERROR : 0); 1224bf8b6031Smarks } 1225bf8b6031Smarks 12265a5eeccaSmarks /* 12275a5eeccaSmarks * compute value for inheritance flags. 12285a5eeccaSmarks */ 12295a5eeccaSmarks int 12305a5eeccaSmarks compute_ace_inherit(char *str, uint32_t *imask) 12315a5eeccaSmarks { 1232bf8b6031Smarks int rc = 0; 12335a5eeccaSmarks 1234bf8b6031Smarks rc = ace_inherit_helper(str, imask, IFLAG_COUNT); 12355a5eeccaSmarks 1236bf8b6031Smarks if (rc && strlen(str) != IFLAG_COUNT) { 12375a5eeccaSmarks 1238bf8b6031Smarks /* is it an old formatted inherit string? */ 1239bf8b6031Smarks rc = ace_inherit_helper(str, imask, IFLAG_COUNT_V1); 1240bf8b6031Smarks } 12415a5eeccaSmarks 1242bf8b6031Smarks return (rc); 12435a5eeccaSmarks } 12445a5eeccaSmarks 12455a5eeccaSmarks 12465a5eeccaSmarks /* 12475a5eeccaSmarks * compute value for ACE permissions. 12485a5eeccaSmarks */ 12495a5eeccaSmarks int 12505a5eeccaSmarks compute_ace_perms(char *str, uint32_t *mask) 12515a5eeccaSmarks { 12525a5eeccaSmarks int positional = 0; 12535a5eeccaSmarks int error; 12545a5eeccaSmarks 12555a5eeccaSmarks if (strlen(str) == ACE_PERM_COUNT) 12565a5eeccaSmarks positional = 1; 12575a5eeccaSmarks 12585a5eeccaSmarks error = compute_values(ace_perm_table, ACE_PERM_COUNT, 12595a5eeccaSmarks str, positional, mask); 12605a5eeccaSmarks 12615a5eeccaSmarks if (error && positional) { 12625a5eeccaSmarks /* 12635a5eeccaSmarks * If positional was set, then make sure permissions 12645a5eeccaSmarks * aren't actually valid in non positional case where 12655a5eeccaSmarks * all permissions are specified, just in random order. 12665a5eeccaSmarks */ 12675a5eeccaSmarks error = compute_values(ace_perm_table, 12685a5eeccaSmarks ACE_PERM_COUNT, str, 0, mask); 12695a5eeccaSmarks } 12705a5eeccaSmarks if (error) 12715a5eeccaSmarks error = EACL_PERM_MASK_ERROR; 12725a5eeccaSmarks 12735a5eeccaSmarks return (error); 12745a5eeccaSmarks } 12755a5eeccaSmarks 12765a5eeccaSmarks 12775a5eeccaSmarks 12785a5eeccaSmarks /* 12795a5eeccaSmarks * compute values for aclent permissions. 12805a5eeccaSmarks */ 12815a5eeccaSmarks int 12825a5eeccaSmarks compute_aclent_perms(char *str, o_mode_t *mask) 12835a5eeccaSmarks { 12845a5eeccaSmarks int error; 12855a5eeccaSmarks uint32_t pmask; 12865a5eeccaSmarks 12875a5eeccaSmarks if (strlen(str) != ACLENT_PERM_COUNT) 12885a5eeccaSmarks return (EACL_PERM_MASK_ERROR); 12895a5eeccaSmarks 12905a5eeccaSmarks *mask = 0; 12915a5eeccaSmarks error = compute_values(aclent_perm_table, ACLENT_PERM_COUNT, 12925a5eeccaSmarks str, 1, &pmask); 12935a5eeccaSmarks if (error == 0) { 12945a5eeccaSmarks *mask = (o_mode_t)pmask; 12955a5eeccaSmarks } else 12965a5eeccaSmarks error = EACL_PERM_MASK_ERROR; 12975a5eeccaSmarks return (error); 12985a5eeccaSmarks } 12995a5eeccaSmarks 13005a5eeccaSmarks /* 13015a5eeccaSmarks * determine ACE permissions. 13025a5eeccaSmarks */ 13035a5eeccaSmarks int 13045a5eeccaSmarks ace_perm_mask(struct acl_perm_type *aclperm, uint32_t *mask) 13055a5eeccaSmarks { 13065a5eeccaSmarks int error; 13075a5eeccaSmarks 13085a5eeccaSmarks if (aclperm->perm_style == PERM_TYPE_EMPTY) { 13095a5eeccaSmarks *mask = 0; 13105a5eeccaSmarks return (0); 13115a5eeccaSmarks } 13125a5eeccaSmarks 13135a5eeccaSmarks if (aclperm->perm_style == PERM_TYPE_ACE) { 13145a5eeccaSmarks *mask = aclperm->perm_val; 13155a5eeccaSmarks return (0); 13165a5eeccaSmarks } 13175a5eeccaSmarks 13185a5eeccaSmarks error = compute_ace_perms(aclperm->perm_str, mask); 13195a5eeccaSmarks if (error) { 13205b233e2dSmarks acl_error(dgettext(TEXT_DOMAIN, 13215b233e2dSmarks "Invalid permission(s) '%s' specified\n"), 13225a5eeccaSmarks aclperm->perm_str); 13235a5eeccaSmarks return (EACL_PERM_MASK_ERROR); 13245a5eeccaSmarks } 13255a5eeccaSmarks 13265a5eeccaSmarks return (0); 13275a5eeccaSmarks } 1328