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 118909c9a9fSMark Shellenbaum static int 119909c9a9fSMark 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; 125909c9a9fSMark Shellenbaum int error = IDMAP_ERR_NORESULT; 126b249c65cSmarks int len; 127b249c65cSmarks char *domain; 128b249c65cSmarks char *name; 129b249c65cSmarks 130909c9a9fSMark Shellenbaum *sidp = NULL; 131b249c65cSmarks 132b249c65cSmarks /* 133b249c65cSmarks * First try and get windows name 134b249c65cSmarks */ 135b249c65cSmarks 136909c9a9fSMark Shellenbaum if (!noresolve) { 137b249c65cSmarks if (user) 138909c9a9fSMark Shellenbaum error = idmap_getwinnamebyuid(who, 139909c9a9fSMark Shellenbaum IDMAP_REQ_FLG_USE_CACHE, &name, &domain); 140b249c65cSmarks else 141909c9a9fSMark Shellenbaum error = idmap_getwinnamebygid(who, 142909c9a9fSMark Shellenbaum IDMAP_REQ_FLG_USE_CACHE, &name, &domain); 143909c9a9fSMark Shellenbaum } 144909c9a9fSMark Shellenbaum if (error != IDMAP_SUCCESS) { 145909c9a9fSMark Shellenbaum if (idmap_init(&idmap_hdl) == IDMAP_SUCCESS && 146909c9a9fSMark 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); 155909c9a9fSMark Shellenbaum if (error == IDMAP_SUCCESS && 156909c9a9fSMark Shellenbaum idmap_get_mappings(get_hdl) == 0) { 157909c9a9fSMark Shellenbaum if (status == IDMAP_SUCCESS) { 158909c9a9fSMark Shellenbaum len = snprintf(NULL, 0, 159909c9a9fSMark Shellenbaum "%s-%d", domain, rid); 160909c9a9fSMark Shellenbaum if (*sidp = malloc(len + 1)) { 161909c9a9fSMark Shellenbaum (void) snprintf(*sidp, len + 1, 162909c9a9fSMark Shellenbaum "%s-%d", domain, rid); 163b249c65cSmarks } 164909c9a9fSMark Shellenbaum } 165909c9a9fSMark 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; 173909c9a9fSMark Shellenbaum 174*5f41bf46SMark Shellenbaum len = snprintf(NULL, 0, "%s@%s", name, domain); 175909c9a9fSMark Shellenbaum if (*sidp = malloc(len + 1)) 176b249c65cSmarks (void) snprintf(*sidp, len + 1, "%s@%s", name, domain); 177*5f41bf46SMark Shellenbaum free(name); 178*5f41bf46SMark Shellenbaum free(domain); 179b249c65cSmarks } 180909c9a9fSMark Shellenbaum return (*sidp ? 0 : 1); 181b249c65cSmarks } 182b249c65cSmarks 1835a5eeccaSmarks static void 1845a5eeccaSmarks aclent_printacl(acl_t *aclp) 1855a5eeccaSmarks { 1865a5eeccaSmarks aclent_t *tp; 1875a5eeccaSmarks int aclcnt; 1885a5eeccaSmarks int mask; 1895a5eeccaSmarks int slot = 0; 1905a5eeccaSmarks char perm[4]; 191afe1f701Smarks char uidp[ID_STR_MAX]; 192afe1f701Smarks char gidp[ID_STR_MAX]; 1935a5eeccaSmarks 1945a5eeccaSmarks /* display ACL: assume it is sorted. */ 1955a5eeccaSmarks aclcnt = aclp->acl_cnt; 1965a5eeccaSmarks for (tp = aclp->acl_aclp; tp && aclcnt--; tp++) { 1975a5eeccaSmarks if (tp->a_type == CLASS_OBJ) 1985a5eeccaSmarks mask = tp->a_perm; 1995a5eeccaSmarks } 2005a5eeccaSmarks aclcnt = aclp->acl_cnt; 2015a5eeccaSmarks for (tp = aclp->acl_aclp; aclcnt--; tp++) { 2025a5eeccaSmarks (void) printf(" %d:", slot++); 2035a5eeccaSmarks switch (tp->a_type) { 2045a5eeccaSmarks case USER: 2055a5eeccaSmarks aclent_perms(tp->a_perm, perm); 2065a5eeccaSmarks (void) printf("user:%s:%s\t\t", 207afe1f701Smarks pruname(tp->a_id, uidp, sizeof (uidp), 0), perm); 2085a5eeccaSmarks aclent_perms((tp->a_perm & mask), perm); 2095a5eeccaSmarks (void) printf("#effective:%s\n", perm); 2105a5eeccaSmarks break; 2115a5eeccaSmarks case USER_OBJ: 2125a5eeccaSmarks /* no need to display uid */ 2135a5eeccaSmarks aclent_perms(tp->a_perm, perm); 2145a5eeccaSmarks (void) printf("user::%s\n", perm); 2155a5eeccaSmarks break; 2165a5eeccaSmarks case GROUP: 2175a5eeccaSmarks aclent_perms(tp->a_perm, perm); 2185a5eeccaSmarks (void) printf("group:%s:%s\t\t", 219afe1f701Smarks prgname(tp->a_id, gidp, sizeof (gidp), 0), perm); 2205a5eeccaSmarks aclent_perms(tp->a_perm & mask, perm); 2215a5eeccaSmarks (void) printf("#effective:%s\n", perm); 2225a5eeccaSmarks break; 2235a5eeccaSmarks case GROUP_OBJ: 2245a5eeccaSmarks aclent_perms(tp->a_perm, perm); 2255a5eeccaSmarks (void) printf("group::%s\t\t", perm); 2265a5eeccaSmarks aclent_perms(tp->a_perm & mask, perm); 2275a5eeccaSmarks (void) printf("#effective:%s\n", perm); 2285a5eeccaSmarks break; 2295a5eeccaSmarks case CLASS_OBJ: 2305a5eeccaSmarks aclent_perms(tp->a_perm, perm); 2315a5eeccaSmarks (void) printf("mask:%s\n", perm); 2325a5eeccaSmarks break; 2335a5eeccaSmarks case OTHER_OBJ: 2345a5eeccaSmarks aclent_perms(tp->a_perm, perm); 2355a5eeccaSmarks (void) printf("other:%s\n", perm); 2365a5eeccaSmarks break; 2375a5eeccaSmarks case DEF_USER: 2385a5eeccaSmarks aclent_perms(tp->a_perm, perm); 2395a5eeccaSmarks (void) printf("default:user:%s:%s\n", 240afe1f701Smarks pruname(tp->a_id, uidp, sizeof (uidp), 0), perm); 2415a5eeccaSmarks break; 2425a5eeccaSmarks case DEF_USER_OBJ: 2435a5eeccaSmarks aclent_perms(tp->a_perm, perm); 2445a5eeccaSmarks (void) printf("default:user::%s\n", perm); 2455a5eeccaSmarks break; 2465a5eeccaSmarks case DEF_GROUP: 2475a5eeccaSmarks aclent_perms(tp->a_perm, perm); 2485a5eeccaSmarks (void) printf("default:group:%s:%s\n", 249afe1f701Smarks prgname(tp->a_id, gidp, sizeof (gidp), 0), perm); 2505a5eeccaSmarks break; 2515a5eeccaSmarks case DEF_GROUP_OBJ: 2525a5eeccaSmarks aclent_perms(tp->a_perm, perm); 2535a5eeccaSmarks (void) printf("default:group::%s\n", perm); 2545a5eeccaSmarks break; 2555a5eeccaSmarks case DEF_CLASS_OBJ: 2565a5eeccaSmarks aclent_perms(tp->a_perm, perm); 2575a5eeccaSmarks (void) printf("default:mask:%s\n", perm); 2585a5eeccaSmarks break; 2595a5eeccaSmarks case DEF_OTHER_OBJ: 2605a5eeccaSmarks aclent_perms(tp->a_perm, perm); 2615a5eeccaSmarks (void) printf("default:other:%s\n", perm); 2625a5eeccaSmarks break; 2635a5eeccaSmarks default: 2645a5eeccaSmarks (void) fprintf(stderr, 2655b233e2dSmarks dgettext(TEXT_DOMAIN, "unrecognized entry\n")); 2665a5eeccaSmarks break; 2675a5eeccaSmarks } 2685a5eeccaSmarks } 2695a5eeccaSmarks } 2705a5eeccaSmarks 2715a5eeccaSmarks static void 2725a5eeccaSmarks split_line(char *str, int cols) 2735a5eeccaSmarks { 2745a5eeccaSmarks char *ptr; 2755a5eeccaSmarks int len; 2765a5eeccaSmarks int i; 2775a5eeccaSmarks int last_split; 2785a5eeccaSmarks char *pad = ""; 2795a5eeccaSmarks int pad_len; 2805a5eeccaSmarks 2815a5eeccaSmarks len = strlen(str); 2825a5eeccaSmarks ptr = str; 2835a5eeccaSmarks pad_len = 0; 2845a5eeccaSmarks 2855a5eeccaSmarks ptr = str; 2865a5eeccaSmarks last_split = 0; 2875a5eeccaSmarks for (i = 0; i != len; i++) { 2885a5eeccaSmarks if ((i + pad_len + 4) >= cols) { 2895a5eeccaSmarks (void) printf("%s%.*s\n", pad, last_split, ptr); 2905a5eeccaSmarks ptr = &ptr[last_split]; 2915a5eeccaSmarks len = strlen(ptr); 2925a5eeccaSmarks i = 0; 2935a5eeccaSmarks pad_len = 4; 2945a5eeccaSmarks pad = " "; 2955a5eeccaSmarks } else { 2965a5eeccaSmarks if (ptr[i] == '/' || ptr[i] == ':') { 2975a5eeccaSmarks last_split = i; 2985a5eeccaSmarks } 2995a5eeccaSmarks } 3005a5eeccaSmarks } 3015a5eeccaSmarks if (i == len) { 3025a5eeccaSmarks (void) printf("%s%s\n", pad, ptr); 3035a5eeccaSmarks } 3045a5eeccaSmarks } 3055a5eeccaSmarks 306b249c65cSmarks /* 307b249c65cSmarks * compute entry type string, such as user:joe, group:staff,... 308b249c65cSmarks */ 309b249c65cSmarks static int 310b249c65cSmarks aclent_type_txt(dynaclstr_t *dstr, aclent_t *aclp, int flags) 3115a5eeccaSmarks { 312afe1f701Smarks char idp[ID_STR_MAX]; 313b249c65cSmarks int error; 3145a5eeccaSmarks 315b249c65cSmarks switch (aclp->a_type) { 316b249c65cSmarks case DEF_USER_OBJ: 317b249c65cSmarks case USER_OBJ: 318b249c65cSmarks if (aclp->a_type == USER_OBJ) 319b249c65cSmarks error = str_append(dstr, "user::"); 320b249c65cSmarks else 321b249c65cSmarks error = str_append(dstr, "defaultuser::"); 322b249c65cSmarks break; 323b249c65cSmarks 324b249c65cSmarks case DEF_USER: 325b249c65cSmarks case USER: 326b249c65cSmarks if (aclp->a_type == USER) 327b249c65cSmarks error = str_append(dstr, "user:"); 328b249c65cSmarks else 329b249c65cSmarks error = str_append(dstr, "defaultuser:"); 330b249c65cSmarks if (error) 331b249c65cSmarks break; 332b249c65cSmarks error = str_append(dstr, pruname(aclp->a_id, idp, 333b249c65cSmarks sizeof (idp), flags & ACL_NORESOLVE)); 334b249c65cSmarks if (error == 0) 335b249c65cSmarks error = str_append(dstr, ":"); 336b249c65cSmarks break; 337b249c65cSmarks 338b249c65cSmarks case DEF_GROUP_OBJ: 339b249c65cSmarks case GROUP_OBJ: 340b249c65cSmarks if (aclp->a_type == GROUP_OBJ) 341b249c65cSmarks error = str_append(dstr, "group::"); 342b249c65cSmarks else 343b249c65cSmarks error = str_append(dstr, "defaultgroup::"); 344b249c65cSmarks break; 345b249c65cSmarks 346b249c65cSmarks case DEF_GROUP: 347b249c65cSmarks case GROUP: 348b249c65cSmarks if (aclp->a_type == GROUP) 349b249c65cSmarks error = str_append(dstr, "group:"); 350b249c65cSmarks else 351b249c65cSmarks error = str_append(dstr, "defaultgroup:"); 352b249c65cSmarks if (error) 353b249c65cSmarks break; 354b249c65cSmarks error = str_append(dstr, prgname(aclp->a_id, idp, 355b249c65cSmarks sizeof (idp), flags & ACL_NORESOLVE)); 356b249c65cSmarks if (error == 0) 357b249c65cSmarks error = str_append(dstr, ":"); 358b249c65cSmarks break; 359b249c65cSmarks 360b249c65cSmarks case DEF_CLASS_OBJ: 361b249c65cSmarks case CLASS_OBJ: 362b249c65cSmarks if (aclp->a_type == CLASS_OBJ) 363b249c65cSmarks error = str_append(dstr, "mask:"); 364b249c65cSmarks else 365b249c65cSmarks error = str_append(dstr, "defaultmask:"); 366b249c65cSmarks break; 367b249c65cSmarks 368b249c65cSmarks case DEF_OTHER_OBJ: 369b249c65cSmarks case OTHER_OBJ: 370b249c65cSmarks if (aclp->a_type == OTHER_OBJ) 371b249c65cSmarks error = str_append(dstr, "other:"); 372b249c65cSmarks else 373b249c65cSmarks error = str_append(dstr, "defaultother:"); 374b249c65cSmarks break; 375b249c65cSmarks 376b249c65cSmarks default: 377b249c65cSmarks error = 1; 378b249c65cSmarks break; 379b249c65cSmarks } 380b249c65cSmarks 381b249c65cSmarks return (error); 382b249c65cSmarks } 383b249c65cSmarks 384b249c65cSmarks /* 385b249c65cSmarks * compute entry type string such as, owner@:, user:joe, group:staff,... 386b249c65cSmarks */ 387b249c65cSmarks static int 388b249c65cSmarks ace_type_txt(dynaclstr_t *dynstr, ace_t *acep, int flags) 389b249c65cSmarks { 390b249c65cSmarks char idp[ID_STR_MAX]; 391b249c65cSmarks int error; 392b249c65cSmarks char *sidp = NULL; 3935a5eeccaSmarks 3945a5eeccaSmarks switch (acep->a_flags & ACE_TYPE_FLAGS) { 3955a5eeccaSmarks case ACE_OWNER: 396b249c65cSmarks error = str_append(dynstr, OWNERAT_TXT); 3975a5eeccaSmarks break; 3985a5eeccaSmarks 3995a5eeccaSmarks case ACE_GROUP|ACE_IDENTIFIER_GROUP: 400b249c65cSmarks error = str_append(dynstr, GROUPAT_TXT); 4015a5eeccaSmarks break; 4025a5eeccaSmarks 4035a5eeccaSmarks case ACE_IDENTIFIER_GROUP: 404b249c65cSmarks if ((flags & ACL_SID_FMT) && acep->a_who > MAXUID) { 405b249c65cSmarks if (error = str_append(dynstr, 406b249c65cSmarks GROUPSID_TXT)) 407b249c65cSmarks break; 408909c9a9fSMark Shellenbaum if (error = getsidname(acep->a_who, B_FALSE, 409909c9a9fSMark Shellenbaum &sidp, flags & ACL_NORESOLVE)) 410909c9a9fSMark Shellenbaum break; 411909c9a9fSMark Shellenbaum error = str_append(dynstr, sidp); 412b249c65cSmarks } else { 413b249c65cSmarks if (error = str_append(dynstr, GROUP_TXT)) 414b249c65cSmarks break; 415b249c65cSmarks error = str_append(dynstr, prgname(acep->a_who, idp, 416afe1f701Smarks sizeof (idp), flags & ACL_NORESOLVE)); 417b249c65cSmarks } 418b249c65cSmarks if (error == 0) 419b249c65cSmarks error = str_append(dynstr, ":"); 4205a5eeccaSmarks break; 4215a5eeccaSmarks 4225a5eeccaSmarks case ACE_EVERYONE: 423b249c65cSmarks error = str_append(dynstr, EVERYONEAT_TXT); 4245a5eeccaSmarks break; 4255a5eeccaSmarks 4265a5eeccaSmarks case 0: 427b249c65cSmarks if ((flags & ACL_SID_FMT) && acep->a_who > MAXUID) { 428b249c65cSmarks if (error = str_append(dynstr, USERSID_TXT)) 429b249c65cSmarks break; 430909c9a9fSMark Shellenbaum if (error = getsidname(acep->a_who, B_TRUE, 431909c9a9fSMark Shellenbaum &sidp, flags & ACL_NORESOLVE)) 432909c9a9fSMark Shellenbaum break; 433909c9a9fSMark Shellenbaum error = str_append(dynstr, sidp); 434b249c65cSmarks } else { 435b249c65cSmarks if (error = str_append(dynstr, USER_TXT)) 436b249c65cSmarks break; 437b249c65cSmarks error = str_append(dynstr, pruname(acep->a_who, idp, 438afe1f701Smarks sizeof (idp), flags & ACL_NORESOLVE)); 439b249c65cSmarks } 440b249c65cSmarks if (error == 0) 441b249c65cSmarks error = str_append(dynstr, ":"); 442b249c65cSmarks break; 443b249c65cSmarks default: 444b249c65cSmarks error = 0; 4455a5eeccaSmarks break; 4465a5eeccaSmarks } 4475a5eeccaSmarks 448b249c65cSmarks if (sidp) 449b249c65cSmarks free(sidp); 450b249c65cSmarks return (error); 4515a5eeccaSmarks } 4525a5eeccaSmarks 453b249c65cSmarks /* 454b249c65cSmarks * compute string of permissions, such as read_data/write_data or 455b249c65cSmarks * rwxp,... 456b249c65cSmarks * The format depends on the flags field which indicates whether the compact 457b249c65cSmarks * or verbose format should be used. 458b249c65cSmarks */ 459b249c65cSmarks static int 460b249c65cSmarks ace_perm_txt(dynaclstr_t *dstr, uint32_t mask, 4615a5eeccaSmarks uint32_t iflags, int isdir, int flags) 4625a5eeccaSmarks { 463b249c65cSmarks int error = 0; 4645a5eeccaSmarks 4655a5eeccaSmarks if (flags & ACL_COMPACT_FMT) { 466b249c65cSmarks char buf[16]; 4675a5eeccaSmarks 4685a5eeccaSmarks if (mask & ACE_READ_DATA) 4695a5eeccaSmarks buf[0] = 'r'; 4705a5eeccaSmarks else 4715a5eeccaSmarks buf[0] = '-'; 4725a5eeccaSmarks if (mask & ACE_WRITE_DATA) 4735a5eeccaSmarks buf[1] = 'w'; 4745a5eeccaSmarks else 4755a5eeccaSmarks buf[1] = '-'; 4765a5eeccaSmarks if (mask & ACE_EXECUTE) 4775a5eeccaSmarks buf[2] = 'x'; 4785a5eeccaSmarks else 4795a5eeccaSmarks buf[2] = '-'; 4805a5eeccaSmarks if (mask & ACE_APPEND_DATA) 4815a5eeccaSmarks buf[3] = 'p'; 4825a5eeccaSmarks else 4835a5eeccaSmarks buf[3] = '-'; 4845a5eeccaSmarks if (mask & ACE_DELETE) 4855a5eeccaSmarks buf[4] = 'd'; 4865a5eeccaSmarks else 4875a5eeccaSmarks buf[4] = '-'; 4885a5eeccaSmarks if (mask & ACE_DELETE_CHILD) 4895a5eeccaSmarks buf[5] = 'D'; 4905a5eeccaSmarks else 4915a5eeccaSmarks buf[5] = '-'; 4925a5eeccaSmarks if (mask & ACE_READ_ATTRIBUTES) 4935a5eeccaSmarks buf[6] = 'a'; 4945a5eeccaSmarks else 4955a5eeccaSmarks buf[6] = '-'; 4965a5eeccaSmarks if (mask & ACE_WRITE_ATTRIBUTES) 4975a5eeccaSmarks buf[7] = 'A'; 4985a5eeccaSmarks else 4995a5eeccaSmarks buf[7] = '-'; 5005a5eeccaSmarks if (mask & ACE_READ_NAMED_ATTRS) 5015a5eeccaSmarks buf[8] = 'R'; 5025a5eeccaSmarks else 5035a5eeccaSmarks buf[8] = '-'; 5045a5eeccaSmarks if (mask & ACE_WRITE_NAMED_ATTRS) 5055a5eeccaSmarks buf[9] = 'W'; 5065a5eeccaSmarks else 5075a5eeccaSmarks buf[9] = '-'; 5085a5eeccaSmarks if (mask & ACE_READ_ACL) 5095a5eeccaSmarks buf[10] = 'c'; 5105a5eeccaSmarks else 5115a5eeccaSmarks buf[10] = '-'; 5125a5eeccaSmarks if (mask & ACE_WRITE_ACL) 5135a5eeccaSmarks buf[11] = 'C'; 5145a5eeccaSmarks else 5155a5eeccaSmarks buf[11] = '-'; 5165a5eeccaSmarks if (mask & ACE_WRITE_OWNER) 5175a5eeccaSmarks buf[12] = 'o'; 5185a5eeccaSmarks else 5195a5eeccaSmarks buf[12] = '-'; 5205a5eeccaSmarks if (mask & ACE_SYNCHRONIZE) 5215a5eeccaSmarks buf[13] = 's'; 5225a5eeccaSmarks else 5235a5eeccaSmarks buf[13] = '-'; 524b249c65cSmarks buf[14] = ':'; 525b249c65cSmarks buf[15] = '\0'; 526b249c65cSmarks error = str_append(dstr, buf); 5275a5eeccaSmarks } else { 5285a5eeccaSmarks /* 5295a5eeccaSmarks * If ACE is a directory, but inheritance indicates its 5305a5eeccaSmarks * for a file then print permissions for file rather than 5315a5eeccaSmarks * dir. 5325a5eeccaSmarks */ 5335a5eeccaSmarks if (isdir) { 5345a5eeccaSmarks if (mask & ACE_LIST_DIRECTORY) { 5355a5eeccaSmarks if (iflags == ACE_FILE_INHERIT_ACE) { 536b249c65cSmarks error = str_append(dstr, 537b249c65cSmarks READ_DATA_TXT); 5385a5eeccaSmarks } else { 539b249c65cSmarks error = 540b249c65cSmarks str_append(dstr, READ_DIR_TXT); 5415a5eeccaSmarks } 5425a5eeccaSmarks } 543b249c65cSmarks if (error == 0 && (mask & ACE_ADD_FILE)) { 5445a5eeccaSmarks if (iflags == ACE_FILE_INHERIT_ACE) { 545b249c65cSmarks error = 546b249c65cSmarks str_append(dstr, WRITE_DATA_TXT); 5475a5eeccaSmarks } else { 548b249c65cSmarks error = 549b249c65cSmarks str_append(dstr, ADD_FILE_TXT); 5505a5eeccaSmarks } 5515a5eeccaSmarks } 552b249c65cSmarks if (error == 0 && (mask & ACE_ADD_SUBDIRECTORY)) { 5535a5eeccaSmarks if (iflags == ACE_FILE_INHERIT_ACE) { 554b249c65cSmarks error = str_append(dstr, 555b249c65cSmarks APPEND_DATA_TXT); 5565a5eeccaSmarks } else { 557b249c65cSmarks error = str_append(dstr, 558b249c65cSmarks ADD_DIR_TXT); 5595a5eeccaSmarks } 5605a5eeccaSmarks } 5615a5eeccaSmarks } else { 5625a5eeccaSmarks if (mask & ACE_READ_DATA) { 563b249c65cSmarks error = str_append(dstr, READ_DATA_TXT); 5645a5eeccaSmarks } 565b249c65cSmarks if (error == 0 && (mask & ACE_WRITE_DATA)) { 566b249c65cSmarks error = str_append(dstr, WRITE_DATA_TXT); 5675a5eeccaSmarks } 568b249c65cSmarks if (error == 0 && (mask & ACE_APPEND_DATA)) { 569b249c65cSmarks error = str_append(dstr, APPEND_DATA_TXT); 5705a5eeccaSmarks } 5715a5eeccaSmarks } 572b249c65cSmarks if (error == 0 && (mask & ACE_READ_NAMED_ATTRS)) { 573b249c65cSmarks error = str_append(dstr, READ_XATTR_TXT); 5745a5eeccaSmarks } 575b249c65cSmarks if (error == 0 && (mask & ACE_WRITE_NAMED_ATTRS)) { 576b249c65cSmarks error = str_append(dstr, WRITE_XATTR_TXT); 5775a5eeccaSmarks } 578b249c65cSmarks if (error == 0 && (mask & ACE_EXECUTE)) { 579b249c65cSmarks error = str_append(dstr, EXECUTE_TXT); 5805a5eeccaSmarks } 581b249c65cSmarks if (error == 0 && (mask & ACE_DELETE_CHILD)) { 582b249c65cSmarks error = str_append(dstr, DELETE_CHILD_TXT); 5835a5eeccaSmarks } 584b249c65cSmarks if (error == 0 && (mask & ACE_READ_ATTRIBUTES)) { 585b249c65cSmarks error = str_append(dstr, READ_ATTRIBUTES_TXT); 5865a5eeccaSmarks } 587b249c65cSmarks if (error == 0 && (mask & ACE_WRITE_ATTRIBUTES)) { 588b249c65cSmarks error = str_append(dstr, WRITE_ATTRIBUTES_TXT); 5895a5eeccaSmarks } 590b249c65cSmarks if (error == 0 && (mask & ACE_DELETE)) { 591b249c65cSmarks error = str_append(dstr, DELETE_TXT); 5925a5eeccaSmarks } 593b249c65cSmarks if (error == 0 && (mask & ACE_READ_ACL)) { 594b249c65cSmarks error = str_append(dstr, READ_ACL_TXT); 5955a5eeccaSmarks } 596b249c65cSmarks if (error == 0 && (mask & ACE_WRITE_ACL)) { 597b249c65cSmarks error = str_append(dstr, WRITE_ACL_TXT); 5985a5eeccaSmarks } 599b249c65cSmarks if (error == 0 && (mask & ACE_WRITE_OWNER)) { 600b249c65cSmarks error = str_append(dstr, WRITE_OWNER_TXT); 6015a5eeccaSmarks } 602b249c65cSmarks if (error == 0 && (mask & ACE_SYNCHRONIZE)) { 603b249c65cSmarks error = str_append(dstr, SYNCHRONIZE_TXT); 604b249c65cSmarks } 605b249c65cSmarks if (error == 0 && dstr->d_aclexport[dstr->d_pos-1] == '/') { 606b249c65cSmarks dstr->d_aclexport[--dstr->d_pos] = '\0'; 607b249c65cSmarks } 608b249c65cSmarks if (error == 0) 609b249c65cSmarks error = str_append(dstr, ":"); 610b249c65cSmarks } 611b249c65cSmarks return (error); 6125a5eeccaSmarks } 6135a5eeccaSmarks 614b249c65cSmarks /* 615b249c65cSmarks * compute string of access type, such as allow, deny, ... 616b249c65cSmarks */ 617b249c65cSmarks static int 618b249c65cSmarks ace_access_txt(dynaclstr_t *dstr, int type) 6195a5eeccaSmarks { 620b249c65cSmarks int error; 6215a5eeccaSmarks 622b249c65cSmarks if (type == ACE_ACCESS_ALLOWED_ACE_TYPE) 623b249c65cSmarks error = str_append(dstr, ALLOW_TXT); 624b249c65cSmarks else if (type == ACE_ACCESS_DENIED_ACE_TYPE) 625b249c65cSmarks error = str_append(dstr, DENY_TXT); 626b249c65cSmarks else if (type == ACE_SYSTEM_AUDIT_ACE_TYPE) 627b249c65cSmarks error = str_append(dstr, AUDIT_TXT); 628b249c65cSmarks else if (type == ACE_SYSTEM_ALARM_ACE_TYPE) 629b249c65cSmarks error = str_append(dstr, ALARM_TXT); 630b249c65cSmarks else 631b249c65cSmarks error = str_append(dstr, UNKNOWN_TXT); 6325a5eeccaSmarks 633b249c65cSmarks return (error); 6345a5eeccaSmarks } 6355a5eeccaSmarks 636b249c65cSmarks static int 637b249c65cSmarks ace_inherit_txt(dynaclstr_t *dstr, uint32_t iflags, int flags) 6385a5eeccaSmarks { 639b249c65cSmarks int error = 0; 6405a5eeccaSmarks 6415a5eeccaSmarks if (flags & ACL_COMPACT_FMT) { 642b249c65cSmarks char buf[9]; 643b249c65cSmarks 6445a5eeccaSmarks if (iflags & ACE_FILE_INHERIT_ACE) 6455a5eeccaSmarks buf[0] = 'f'; 6465a5eeccaSmarks else 6475a5eeccaSmarks buf[0] = '-'; 6485a5eeccaSmarks if (iflags & ACE_DIRECTORY_INHERIT_ACE) 6495a5eeccaSmarks buf[1] = 'd'; 6505a5eeccaSmarks else 6515a5eeccaSmarks buf[1] = '-'; 6525a5eeccaSmarks if (iflags & ACE_INHERIT_ONLY_ACE) 6535a5eeccaSmarks buf[2] = 'i'; 6545a5eeccaSmarks else 6555a5eeccaSmarks buf[2] = '-'; 6565a5eeccaSmarks if (iflags & ACE_NO_PROPAGATE_INHERIT_ACE) 6575a5eeccaSmarks buf[3] = 'n'; 6585a5eeccaSmarks else 6595a5eeccaSmarks buf[3] = '-'; 6605a5eeccaSmarks if (iflags & ACE_SUCCESSFUL_ACCESS_ACE_FLAG) 6615a5eeccaSmarks buf[4] = 'S'; 6625a5eeccaSmarks else 6635a5eeccaSmarks buf[4] = '-'; 6645a5eeccaSmarks if (iflags & ACE_FAILED_ACCESS_ACE_FLAG) 6655a5eeccaSmarks buf[5] = 'F'; 6665a5eeccaSmarks else 6675a5eeccaSmarks buf[5] = '-'; 668da6c28aaSamw if (iflags & ACE_INHERITED_ACE) 669da6c28aaSamw buf[6] = 'I'; 670da6c28aaSamw else 671da6c28aaSamw buf[6] = '-'; 672b249c65cSmarks buf[7] = ':'; 673b249c65cSmarks buf[8] = '\0'; 674b249c65cSmarks error = str_append(dstr, buf); 6755a5eeccaSmarks } else { 6765a5eeccaSmarks if (iflags & ACE_FILE_INHERIT_ACE) { 677b249c65cSmarks error = str_append(dstr, FILE_INHERIT_TXT); 6785a5eeccaSmarks } 679b249c65cSmarks if (error == 0 && (iflags & ACE_DIRECTORY_INHERIT_ACE)) { 680b249c65cSmarks error = str_append(dstr, DIR_INHERIT_TXT); 6815a5eeccaSmarks } 682b249c65cSmarks if (error == 0 && (iflags & ACE_NO_PROPAGATE_INHERIT_ACE)) { 683b249c65cSmarks error = str_append(dstr, NO_PROPAGATE_TXT); 6845a5eeccaSmarks } 685b249c65cSmarks if (error == 0 && (iflags & ACE_INHERIT_ONLY_ACE)) { 686b249c65cSmarks error = str_append(dstr, INHERIT_ONLY_TXT); 6875a5eeccaSmarks } 688b249c65cSmarks if (error == 0 && (iflags & ACE_SUCCESSFUL_ACCESS_ACE_FLAG)) { 689b249c65cSmarks error = str_append(dstr, SUCCESSFUL_ACCESS_TXT); 690da6c28aaSamw } 691b249c65cSmarks if (error == 0 && (iflags & ACE_FAILED_ACCESS_ACE_FLAG)) { 692b249c65cSmarks error = str_append(dstr, FAILED_ACCESS_TXT); 693da6c28aaSamw } 694b249c65cSmarks if (error == 0 && (iflags & ACE_INHERITED_ACE)) { 695b249c65cSmarks error = str_append(dstr, INHERITED_ACE_TXT); 696b249c65cSmarks } 697b249c65cSmarks if (error == 0 && dstr->d_aclexport[dstr->d_pos-1] == '/') { 698b249c65cSmarks dstr->d_aclexport[--dstr->d_pos] = '\0'; 699b249c65cSmarks error = str_append(dstr, ":"); 700b249c65cSmarks } 701da6c28aaSamw } 7025a5eeccaSmarks 703b249c65cSmarks return (error); 704fa9e4066Sahrens } 7057c478bd9Sstevel@tonic-gate 7067c478bd9Sstevel@tonic-gate /* 7077c478bd9Sstevel@tonic-gate * Convert internal acl representation to external representation. 7087c478bd9Sstevel@tonic-gate * 7097c478bd9Sstevel@tonic-gate * The length of a non-owning user name or non-owning group name ie entries 7107c478bd9Sstevel@tonic-gate * of type DEF_USER, USER, DEF_GROUP or GROUP, can exceed LOGNAME_MAX. We 7117c478bd9Sstevel@tonic-gate * thus check the length of these entries, and if greater than LOGNAME_MAX, 7127c478bd9Sstevel@tonic-gate * we realloc() via increase_length(). 7137c478bd9Sstevel@tonic-gate * 7147c478bd9Sstevel@tonic-gate * The LOGNAME_MAX, ENTRYTYPELEN and PERMS limits are otherwise always 7157c478bd9Sstevel@tonic-gate * adhered to. 7167c478bd9Sstevel@tonic-gate */ 7175a5eeccaSmarks 7185a5eeccaSmarks /* 7195a5eeccaSmarks * acltotext() converts each ACL entry to look like this: 7205a5eeccaSmarks * 7215a5eeccaSmarks * entry_type:uid^gid^name:perms[:id] 7225a5eeccaSmarks * 7235a5eeccaSmarks * The maximum length of entry_type is 14 ("defaultgroup::" and 7245a5eeccaSmarks * "defaultother::") hence ENTRYTYPELEN is set to 14. 7255a5eeccaSmarks * 7265a5eeccaSmarks * The max length of a uid^gid^name entry (in theory) is 8, hence we use, 7275a5eeccaSmarks * however the ID could be a number so we therefore use ID_STR_MAX 7285a5eeccaSmarks * 7295a5eeccaSmarks * The length of a perms entry is 4 to allow for the comma appended to each 7305a5eeccaSmarks * to each acl entry. Hence PERMS is set to 4. 7315a5eeccaSmarks */ 7325a5eeccaSmarks 7335a5eeccaSmarks #define ENTRYTYPELEN 14 7345a5eeccaSmarks #define PERMS 4 7355a5eeccaSmarks #define ACL_ENTRY_SIZE (ENTRYTYPELEN + ID_STR_MAX + PERMS + APPENDED_ID_MAX) 7365a5eeccaSmarks 7377c478bd9Sstevel@tonic-gate char * 7385a5eeccaSmarks aclent_acltotext(aclent_t *aclp, int aclcnt, int flags) 7397c478bd9Sstevel@tonic-gate { 740b249c65cSmarks dynaclstr_t *dstr; 741909c9a9fSMark Shellenbaum char *aclexport = NULL; 742b249c65cSmarks int i; 743b249c65cSmarks int error = 0; 7447c478bd9Sstevel@tonic-gate 7457c478bd9Sstevel@tonic-gate if (aclp == NULL) 7467c478bd9Sstevel@tonic-gate return (NULL); 747b249c65cSmarks if ((dstr = malloc(sizeof (dynaclstr_t))) == NULL) 7487c478bd9Sstevel@tonic-gate return (NULL); 749b249c65cSmarks dstr->d_bufsize = aclcnt * ACL_ENTRY_SIZE; 750b249c65cSmarks if ((dstr->d_aclexport = malloc(dstr->d_bufsize)) == NULL) { 7517c478bd9Sstevel@tonic-gate free(dstr); 7527c478bd9Sstevel@tonic-gate return (NULL); 7537c478bd9Sstevel@tonic-gate } 754b249c65cSmarks *dstr->d_aclexport = '\0'; 755b249c65cSmarks dstr->d_pos = 0; 7567c478bd9Sstevel@tonic-gate 7577c478bd9Sstevel@tonic-gate for (i = 0; i < aclcnt; i++, aclp++) { 758b249c65cSmarks if (error = aclent_type_txt(dstr, aclp, flags)) 7597c478bd9Sstevel@tonic-gate break; 760b249c65cSmarks if (error = aclent_perm_txt(dstr, aclp->a_perm)) 7617c478bd9Sstevel@tonic-gate break; 7625a5eeccaSmarks 7635a5eeccaSmarks if ((flags & ACL_APPEND_ID) && ((aclp->a_type == USER) || 7645a5eeccaSmarks (aclp->a_type == DEF_USER) || (aclp->a_type == GROUP) || 7655a5eeccaSmarks (aclp->a_type == DEF_GROUP))) { 766b249c65cSmarks char id[ID_STR_MAX], *idstr; 767b249c65cSmarks 768b249c65cSmarks if (error = str_append(dstr, ":")) 769b249c65cSmarks break; 7705a5eeccaSmarks id[ID_STR_MAX - 1] = '\0'; /* null terminate buffer */ 7715a5eeccaSmarks idstr = lltostr(aclp->a_id, &id[ID_STR_MAX - 1]); 772b249c65cSmarks if (error = str_append(dstr, idstr)) 773b249c65cSmarks break; 7745a5eeccaSmarks } 7757c478bd9Sstevel@tonic-gate if (i < aclcnt - 1) 776b249c65cSmarks if (error = str_append(dstr, ",")) 777b249c65cSmarks break; 7787c478bd9Sstevel@tonic-gate } 779b249c65cSmarks if (error) { 780b249c65cSmarks if (dstr->d_aclexport) 781b249c65cSmarks free(dstr->d_aclexport); 782b249c65cSmarks } else { 783b249c65cSmarks aclexport = dstr->d_aclexport; 784b249c65cSmarks } 7857c478bd9Sstevel@tonic-gate free(dstr); 7867c478bd9Sstevel@tonic-gate return (aclexport); 7877c478bd9Sstevel@tonic-gate } 7887c478bd9Sstevel@tonic-gate 7895a5eeccaSmarks char * 7905a5eeccaSmarks acltotext(aclent_t *aclp, int aclcnt) 7917c478bd9Sstevel@tonic-gate { 7925a5eeccaSmarks return (aclent_acltotext(aclp, aclcnt, 0)); 793fa9e4066Sahrens } 794fa9e4066Sahrens 7957c478bd9Sstevel@tonic-gate 796fa9e4066Sahrens aclent_t * 797fa9e4066Sahrens aclfromtext(char *aclstr, int *aclcnt) 798fa9e4066Sahrens { 799fa9e4066Sahrens acl_t *aclp; 800fa9e4066Sahrens aclent_t *aclentp; 801fa9e4066Sahrens int error; 802fa9e4066Sahrens 8035a5eeccaSmarks error = acl_fromtext(aclstr, &aclp); 804fa9e4066Sahrens if (error) 805fa9e4066Sahrens return (NULL); 806fa9e4066Sahrens 807fa9e4066Sahrens aclentp = aclp->acl_aclp; 808fa9e4066Sahrens aclp->acl_aclp = NULL; 809fa9e4066Sahrens *aclcnt = aclp->acl_cnt; 8105a5eeccaSmarks 8115a5eeccaSmarks acl_free(aclp); 812fa9e4066Sahrens return (aclentp); 813fa9e4066Sahrens } 814fa9e4066Sahrens 815fa9e4066Sahrens 8167c478bd9Sstevel@tonic-gate /* 817909c9a9fSMark Shellenbaum * Append string onto dynaclstr_t. 818909c9a9fSMark Shellenbaum * 819909c9a9fSMark Shellenbaum * Return 0 on success, 1 for failure. 8207c478bd9Sstevel@tonic-gate */ 8217c478bd9Sstevel@tonic-gate static int 822b249c65cSmarks str_append(dynaclstr_t *dstr, char *newstr) 8237c478bd9Sstevel@tonic-gate { 824b249c65cSmarks size_t len = strlen(newstr); 8257c478bd9Sstevel@tonic-gate 826b249c65cSmarks if ((len + dstr->d_pos) >= dstr->d_bufsize) { 827b249c65cSmarks dstr->d_aclexport = realloc(dstr->d_aclexport, 828b249c65cSmarks dstr->d_bufsize + len + 1); 829b249c65cSmarks if (dstr->d_aclexport == NULL) 8307c478bd9Sstevel@tonic-gate return (1); 831b249c65cSmarks dstr->d_bufsize += len; 832b249c65cSmarks } 833b249c65cSmarks (void) strcat(&dstr->d_aclexport[dstr->d_pos], newstr); 834b249c65cSmarks dstr->d_pos += len; 8357c478bd9Sstevel@tonic-gate return (0); 8367c478bd9Sstevel@tonic-gate } 837fa9e4066Sahrens 838b249c65cSmarks static int 839b249c65cSmarks aclent_perm_txt(dynaclstr_t *dstr, o_mode_t perm) 840b249c65cSmarks { 841b249c65cSmarks char buf[4]; 842b249c65cSmarks 843b249c65cSmarks if (perm & S_IROTH) 844b249c65cSmarks buf[0] = 'r'; 845b249c65cSmarks else 846b249c65cSmarks buf[0] = '-'; 847b249c65cSmarks if (perm & S_IWOTH) 848b249c65cSmarks buf[1] = 'w'; 849b249c65cSmarks else 850b249c65cSmarks buf[1] = '-'; 851b249c65cSmarks if (perm & S_IXOTH) 852b249c65cSmarks buf[2] = 'x'; 853b249c65cSmarks else 854b249c65cSmarks buf[2] = '-'; 855b249c65cSmarks buf[3] = '\0'; 856b249c65cSmarks return (str_append(dstr, buf)); 857b249c65cSmarks } 858b249c65cSmarks 859fa9e4066Sahrens /* 8605a5eeccaSmarks * ace_acltotext() convert each ace formatted acl to look like this: 861fa9e4066Sahrens * 8625a5eeccaSmarks * entry_type:uid^gid^name:perms[:flags]:<allow|deny>[:id][,] 863fa9e4066Sahrens * 864fa9e4066Sahrens * The maximum length of entry_type is 5 ("group") 865fa9e4066Sahrens * 8665a5eeccaSmarks * The max length of a uid^gid^name entry (in theory) is 8, 8675a5eeccaSmarks * however id could be a number so we therefore use ID_STR_MAX 868fa9e4066Sahrens * 869fa9e4066Sahrens * The length of a perms entry is 144 i.e read_data/write_data... 870fa9e4066Sahrens * to each acl entry. 871fa9e4066Sahrens * 872da6c28aaSamw * iflags: file_inherit/dir_inherit/inherit_only/no_propagate/successful_access 873da6c28aaSamw * /failed_access 874fa9e4066Sahrens * 875fa9e4066Sahrens */ 876fa9e4066Sahrens 877fa9e4066Sahrens #define ACE_ENTRYTYPLEN 6 878da6c28aaSamw #define IFLAGS_STR "file_inherit/dir_inherit/inherit_only/no_propagate/" \ 879da6c28aaSamw "successful_access/failed_access/inherited" 880da6c28aaSamw #define IFLAGS_SIZE (sizeof (IFLAGS_STR) - 1) 8815a5eeccaSmarks #define ACCESS_TYPE_SIZE 7 /* if unknown */ 882fa9e4066Sahrens #define COLON_CNT 3 883fa9e4066Sahrens #define PERMS_LEN 216 8845a5eeccaSmarks #define ACE_ENTRY_SIZE (ACE_ENTRYTYPLEN + ID_STR_MAX + PERMS_LEN + \ 8855a5eeccaSmarks ACCESS_TYPE_SIZE + IFLAGS_SIZE + COLON_CNT + APPENDED_ID_MAX) 886fa9e4066Sahrens 887fa9e4066Sahrens static char * 8885a5eeccaSmarks ace_acltotext(acl_t *aceaclp, int flags) 889fa9e4066Sahrens { 890fa9e4066Sahrens ace_t *aclp = aceaclp->acl_aclp; 891fa9e4066Sahrens int aclcnt = aceaclp->acl_cnt; 8925a5eeccaSmarks int i; 893b249c65cSmarks int error = 0; 894fa9e4066Sahrens int isdir = (aceaclp->acl_flags & ACL_IS_DIR); 895b249c65cSmarks dynaclstr_t *dstr; 896909c9a9fSMark Shellenbaum char *aclexport = NULL; 897fa9e4066Sahrens 898fa9e4066Sahrens if (aclp == NULL) 899fa9e4066Sahrens return (NULL); 900fa9e4066Sahrens 901b249c65cSmarks if ((dstr = malloc(sizeof (dynaclstr_t))) == NULL) 902b249c65cSmarks return (NULL); 903b249c65cSmarks dstr->d_bufsize = aclcnt * ACL_ENTRY_SIZE; 904b249c65cSmarks if ((dstr->d_aclexport = malloc(dstr->d_bufsize)) == NULL) { 905b249c65cSmarks free(dstr); 906b249c65cSmarks return (NULL); 907b249c65cSmarks } 908b249c65cSmarks *dstr->d_aclexport = '\0'; 909b249c65cSmarks dstr->d_pos = 0; 910b249c65cSmarks 911fa9e4066Sahrens for (i = 0; i < aclcnt; i++, aclp++) { 912fa9e4066Sahrens 913b249c65cSmarks if (error = ace_type_txt(dstr, aclp, flags)) 914b249c65cSmarks break; 915b249c65cSmarks if (error = ace_perm_txt(dstr, aclp->a_access_mask, 916b249c65cSmarks aclp->a_flags, isdir, flags)) 917b249c65cSmarks break; 918b249c65cSmarks if (error = ace_inherit_txt(dstr, aclp->a_flags, flags)) 919b249c65cSmarks break; 920b249c65cSmarks if (error = ace_access_txt(dstr, aclp->a_type)) 921b249c65cSmarks break; 922fa9e4066Sahrens 9235a5eeccaSmarks if ((flags & ACL_APPEND_ID) && 9245a5eeccaSmarks (((aclp->a_flags & ACE_TYPE_FLAGS) == 0) || 9255a5eeccaSmarks ((aclp->a_flags & ACE_TYPE_FLAGS) == 9265a5eeccaSmarks ACE_IDENTIFIER_GROUP))) { 927b249c65cSmarks char id[ID_STR_MAX], *idstr; 928*5f41bf46SMark Shellenbaum char *rawsidp; 929b249c65cSmarks 930b249c65cSmarks if (error = str_append(dstr, ":")) 931b249c65cSmarks break; 932*5f41bf46SMark Shellenbaum 933*5f41bf46SMark Shellenbaum rawsidp = NULL; 934*5f41bf46SMark Shellenbaum id[ID_STR_MAX -1] = '\0'; /* null terminate */ 935*5f41bf46SMark Shellenbaum if (aclp->a_who > MAXUID && (flags & ACL_SID_FMT)) { 936*5f41bf46SMark Shellenbaum 937*5f41bf46SMark Shellenbaum error = getsidname(aclp->a_who, 938*5f41bf46SMark Shellenbaum ((aclp->a_flags & ACE_TYPE_FLAGS) == 0) ? 939*5f41bf46SMark Shellenbaum B_TRUE : B_FALSE, &idstr, 1); 940*5f41bf46SMark Shellenbaum if (error) 941*5f41bf46SMark Shellenbaum break; 942*5f41bf46SMark Shellenbaum rawsidp = idstr; 943*5f41bf46SMark Shellenbaum } else if (aclp->a_who > MAXUID && 944*5f41bf46SMark Shellenbaum !(flags & ACL_NORESOLVE)) { 945*5f41bf46SMark Shellenbaum idstr = lltostr(UID_NOBODY, 946*5f41bf46SMark Shellenbaum &id[ID_STR_MAX - 1]); 947*5f41bf46SMark Shellenbaum } else { 948*5f41bf46SMark Shellenbaum idstr = lltostr(aclp->a_who, 949*5f41bf46SMark Shellenbaum &id[ID_STR_MAX - 1]); 950*5f41bf46SMark Shellenbaum } 951b249c65cSmarks if (error = str_append(dstr, idstr)) 952b249c65cSmarks break; 953*5f41bf46SMark Shellenbaum if (rawsidp) 954*5f41bf46SMark Shellenbaum free(rawsidp); 9555a5eeccaSmarks } 9565a5eeccaSmarks if (i < aclcnt - 1) { 957b249c65cSmarks if (error = str_append(dstr, ",")) 958b249c65cSmarks break; 959fa9e4066Sahrens } 960fa9e4066Sahrens } 961b249c65cSmarks if (error) { 962b249c65cSmarks if (dstr->d_aclexport) 963b249c65cSmarks free(dstr->d_aclexport); 964b249c65cSmarks } else { 965b249c65cSmarks aclexport = dstr->d_aclexport; 966b249c65cSmarks } 967b249c65cSmarks free(dstr); 968fa9e4066Sahrens return (aclexport); 969fa9e4066Sahrens } 970fa9e4066Sahrens 9715a5eeccaSmarks char * 9725a5eeccaSmarks acl_totext(acl_t *aclp, int flags) 973fa9e4066Sahrens { 9745a5eeccaSmarks char *txtp; 975fa9e4066Sahrens 976fa9e4066Sahrens if (aclp == NULL) 977fa9e4066Sahrens return (NULL); 978fa9e4066Sahrens 979fa9e4066Sahrens switch (aclp->acl_type) { 980fa9e4066Sahrens case ACE_T: 9815a5eeccaSmarks txtp = ace_acltotext(aclp, flags); 9825a5eeccaSmarks break; 983fa9e4066Sahrens case ACLENT_T: 9845a5eeccaSmarks txtp = aclent_acltotext(aclp->acl_aclp, aclp->acl_cnt, flags); 9855a5eeccaSmarks break; 986fa9e4066Sahrens } 9875a5eeccaSmarks 9885a5eeccaSmarks return (txtp); 989fa9e4066Sahrens } 990fa9e4066Sahrens 991fa9e4066Sahrens int 992fa9e4066Sahrens acl_fromtext(const char *acltextp, acl_t **ret_aclp) 993fa9e4066Sahrens { 9945a5eeccaSmarks int error; 9955a5eeccaSmarks char *buf; 9965a5eeccaSmarks 9975a5eeccaSmarks buf = malloc(strlen(acltextp) + 2); 9985a5eeccaSmarks if (buf == NULL) 9995a5eeccaSmarks return (EACL_MEM_ERROR); 10005a5eeccaSmarks strcpy(buf, acltextp); 10015a5eeccaSmarks strcat(buf, "\n"); 10025a5eeccaSmarks yybuf = buf; 10035a5eeccaSmarks yyreset(); 10045a5eeccaSmarks error = yyparse(); 10055a5eeccaSmarks free(buf); 10065a5eeccaSmarks 10075a5eeccaSmarks if (yyacl) { 10085a5eeccaSmarks if (error == 0) 10095a5eeccaSmarks *ret_aclp = yyacl; 10105a5eeccaSmarks else { 10115a5eeccaSmarks acl_free(yyacl); 10125a5eeccaSmarks } 10135a5eeccaSmarks yyacl = NULL; 10145a5eeccaSmarks } 10155a5eeccaSmarks return (error); 10165a5eeccaSmarks } 10175a5eeccaSmarks 10185a5eeccaSmarks int 10195a5eeccaSmarks acl_parse(const char *acltextp, acl_t **aclp) 10205a5eeccaSmarks { 1021fa9e4066Sahrens int error; 1022fa9e4066Sahrens 10235a5eeccaSmarks yyinteractive = 1; 10245a5eeccaSmarks error = acl_fromtext(acltextp, aclp); 10255a5eeccaSmarks yyinteractive = 0; 1026fa9e4066Sahrens return (error); 1027fa9e4066Sahrens } 10285a5eeccaSmarks 10295a5eeccaSmarks static void 10305a5eeccaSmarks ace_compact_printacl(acl_t *aclp) 10315a5eeccaSmarks { 10325a5eeccaSmarks int cnt; 10335a5eeccaSmarks ace_t *acep; 1034b249c65cSmarks dynaclstr_t *dstr; 1035b249c65cSmarks int len; 10365a5eeccaSmarks 1037b249c65cSmarks if ((dstr = malloc(sizeof (dynaclstr_t))) == NULL) 1038b249c65cSmarks return; 1039b249c65cSmarks dstr->d_bufsize = ACE_ENTRY_SIZE; 1040b249c65cSmarks if ((dstr->d_aclexport = malloc(dstr->d_bufsize)) == NULL) { 1041b249c65cSmarks free(dstr); 1042b249c65cSmarks return; 1043b249c65cSmarks } 1044b249c65cSmarks *dstr->d_aclexport = '\0'; 1045b249c65cSmarks 1046b249c65cSmarks dstr->d_pos = 0; 10475a5eeccaSmarks for (cnt = 0, acep = aclp->acl_aclp; 10485a5eeccaSmarks cnt != aclp->acl_cnt; cnt++, acep++) { 1049b249c65cSmarks dstr->d_aclexport[0] = '\0'; 1050b249c65cSmarks dstr->d_pos = 0; 1051b249c65cSmarks 1052b249c65cSmarks if (ace_type_txt(dstr, acep, 0)) 1053b249c65cSmarks break; 1054b249c65cSmarks len = strlen(&dstr->d_aclexport[0]); 1055b249c65cSmarks if (ace_perm_txt(dstr, acep->a_access_mask, acep->a_flags, 1056b249c65cSmarks aclp->acl_flags & ACL_IS_DIR, ACL_COMPACT_FMT)) 1057b249c65cSmarks break; 1058b249c65cSmarks if (ace_inherit_txt(dstr, acep->a_flags, ACL_COMPACT_FMT)) 1059b249c65cSmarks break; 1060b249c65cSmarks if (ace_access_txt(dstr, acep->a_type) == -1) 1061b249c65cSmarks break; 1062b249c65cSmarks (void) printf(" %20.*s%s\n", len, dstr->d_aclexport, 1063b249c65cSmarks &dstr->d_aclexport[len]); 10645a5eeccaSmarks } 1065b249c65cSmarks 1066b249c65cSmarks if (dstr->d_aclexport) 1067b249c65cSmarks free(dstr->d_aclexport); 1068b249c65cSmarks free(dstr); 10695a5eeccaSmarks } 10705a5eeccaSmarks 10715a5eeccaSmarks static void 10725a5eeccaSmarks ace_printacl(acl_t *aclp, int cols, int compact) 10735a5eeccaSmarks { 10745a5eeccaSmarks int slot = 0; 10755a5eeccaSmarks char *token; 10765a5eeccaSmarks char *acltext; 10775a5eeccaSmarks 10785a5eeccaSmarks if (compact) { 10795a5eeccaSmarks ace_compact_printacl(aclp); 10805a5eeccaSmarks return; 10815a5eeccaSmarks } 10825a5eeccaSmarks 10835a5eeccaSmarks acltext = acl_totext(aclp, 0); 10845a5eeccaSmarks 10855a5eeccaSmarks if (acltext == NULL) 10865a5eeccaSmarks return; 10875a5eeccaSmarks 10885a5eeccaSmarks token = strtok(acltext, ","); 10895a5eeccaSmarks if (token == NULL) { 10905a5eeccaSmarks free(acltext); 10915a5eeccaSmarks return; 10925a5eeccaSmarks } 10935a5eeccaSmarks 10945a5eeccaSmarks do { 10955a5eeccaSmarks (void) printf(" %d:", slot++); 10965a5eeccaSmarks split_line(token, cols - 5); 10975a5eeccaSmarks } while (token = strtok(NULL, ",")); 10985a5eeccaSmarks free(acltext); 10995a5eeccaSmarks } 11005a5eeccaSmarks 11015a5eeccaSmarks /* 11025a5eeccaSmarks * pretty print an ACL. 11035a5eeccaSmarks * For aclent_t ACL's the format is 11045a5eeccaSmarks * similar to the old format used by getfacl, 11055a5eeccaSmarks * with the addition of adding a "slot" number 11065a5eeccaSmarks * before each entry. 11075a5eeccaSmarks * 11085a5eeccaSmarks * for ace_t ACL's the cols variable will break up 11095a5eeccaSmarks * the long lines into multiple lines and will also 11105a5eeccaSmarks * print a "slot" number. 11115a5eeccaSmarks */ 11125a5eeccaSmarks void 11135a5eeccaSmarks acl_printacl(acl_t *aclp, int cols, int compact) 11145a5eeccaSmarks { 11155a5eeccaSmarks 11165a5eeccaSmarks switch (aclp->acl_type) { 11175a5eeccaSmarks case ACLENT_T: 11185a5eeccaSmarks aclent_printacl(aclp); 11195a5eeccaSmarks break; 11205a5eeccaSmarks case ACE_T: 11215a5eeccaSmarks ace_printacl(aclp, cols, compact); 11225a5eeccaSmarks break; 11235a5eeccaSmarks } 11245a5eeccaSmarks } 11255a5eeccaSmarks 11265a5eeccaSmarks typedef struct value_table { 11275a5eeccaSmarks char p_letter; /* perm letter such as 'r' */ 11285a5eeccaSmarks uint32_t p_value; /* value for perm when pletter found */ 11295a5eeccaSmarks } value_table_t; 11305a5eeccaSmarks 11315a5eeccaSmarks /* 1132da6c28aaSamw * The permission tables are laid out in positional order 11335a5eeccaSmarks * a '-' character will indicate a permission at a given 11345a5eeccaSmarks * position is not specified. The '-' is not part of the 11355a5eeccaSmarks * table, but will be checked for in the permission computation 11365a5eeccaSmarks * routine. 11375a5eeccaSmarks */ 1138da6c28aaSamw value_table_t ace_perm_table[] = { 11395a5eeccaSmarks { 'r', ACE_READ_DATA}, 11405a5eeccaSmarks { 'w', ACE_WRITE_DATA}, 11415a5eeccaSmarks { 'x', ACE_EXECUTE}, 11425a5eeccaSmarks { 'p', ACE_APPEND_DATA}, 11435a5eeccaSmarks { 'd', ACE_DELETE}, 11445a5eeccaSmarks { 'D', ACE_DELETE_CHILD}, 11455a5eeccaSmarks { 'a', ACE_READ_ATTRIBUTES}, 11465a5eeccaSmarks { 'A', ACE_WRITE_ATTRIBUTES}, 11475a5eeccaSmarks { 'R', ACE_READ_NAMED_ATTRS}, 11485a5eeccaSmarks { 'W', ACE_WRITE_NAMED_ATTRS}, 11495a5eeccaSmarks { 'c', ACE_READ_ACL}, 11505a5eeccaSmarks { 'C', ACE_WRITE_ACL}, 11515a5eeccaSmarks { 'o', ACE_WRITE_OWNER}, 11525a5eeccaSmarks { 's', ACE_SYNCHRONIZE} 11535a5eeccaSmarks }; 11545a5eeccaSmarks 1155da6c28aaSamw #define ACE_PERM_COUNT (sizeof (ace_perm_table) / sizeof (value_table_t)) 11565a5eeccaSmarks 1157da6c28aaSamw value_table_t aclent_perm_table[] = { 11585a5eeccaSmarks { 'r', S_IROTH}, 11595a5eeccaSmarks { 'w', S_IWOTH}, 11605a5eeccaSmarks { 'x', S_IXOTH} 11615a5eeccaSmarks }; 11625a5eeccaSmarks 1163da6c28aaSamw #define ACLENT_PERM_COUNT (sizeof (aclent_perm_table) / sizeof (value_table_t)) 1164da6c28aaSamw 1165da6c28aaSamw value_table_t inherit_table[] = { 11665a5eeccaSmarks {'f', ACE_FILE_INHERIT_ACE}, 11675a5eeccaSmarks {'d', ACE_DIRECTORY_INHERIT_ACE}, 11685a5eeccaSmarks {'i', ACE_INHERIT_ONLY_ACE}, 11695a5eeccaSmarks {'n', ACE_NO_PROPAGATE_INHERIT_ACE}, 11705a5eeccaSmarks {'S', ACE_SUCCESSFUL_ACCESS_ACE_FLAG}, 1171da6c28aaSamw {'F', ACE_FAILED_ACCESS_ACE_FLAG}, 1172da6c28aaSamw {'I', ACE_INHERITED_ACE} 11735a5eeccaSmarks }; 11745a5eeccaSmarks 1175da6c28aaSamw #define IFLAG_COUNT (sizeof (inherit_table) / sizeof (value_table_t)) 1176bf8b6031Smarks #define IFLAG_COUNT_V1 6 /* Older version compatibility */ 1177da6c28aaSamw 11785a5eeccaSmarks /* 11795a5eeccaSmarks * compute value from a permission table or inheritance table 11805a5eeccaSmarks * based on string passed in. If positional is set then 11815a5eeccaSmarks * string must match order in permtab, otherwise any order 11825a5eeccaSmarks * is allowed. 11835a5eeccaSmarks */ 11845a5eeccaSmarks int 11855a5eeccaSmarks compute_values(value_table_t *permtab, int count, 11865a5eeccaSmarks char *permstr, int positional, uint32_t *mask) 11875a5eeccaSmarks { 11885a5eeccaSmarks uint32_t perm_val = 0; 11895a5eeccaSmarks char *pstr; 11905a5eeccaSmarks int i, found; 11915a5eeccaSmarks 11925a5eeccaSmarks if (count < 0) 11935a5eeccaSmarks return (1); 11945a5eeccaSmarks 11955a5eeccaSmarks if (positional) { 11965a5eeccaSmarks for (i = 0, pstr = permstr; i != count && pstr && 11975a5eeccaSmarks *pstr; i++, pstr++) { 11985a5eeccaSmarks if (*pstr == permtab[i].p_letter) { 11995a5eeccaSmarks perm_val |= permtab[i].p_value; 12005a5eeccaSmarks } else if (*pstr != '-') { 12015a5eeccaSmarks return (1); 12025a5eeccaSmarks } 12035a5eeccaSmarks } 12045a5eeccaSmarks } else { /* random order single letters with no '-' */ 12055a5eeccaSmarks for (pstr = permstr; pstr && *pstr; pstr++) { 12065a5eeccaSmarks for (found = 0, i = 0; i != count; i++) { 12075a5eeccaSmarks if (*pstr == permtab[i].p_letter) { 12085a5eeccaSmarks perm_val |= permtab[i].p_value; 12095a5eeccaSmarks found = 1; 12105a5eeccaSmarks break; 12115a5eeccaSmarks } 12125a5eeccaSmarks } 12135a5eeccaSmarks if (found == 0) 12145a5eeccaSmarks return (1); 12155a5eeccaSmarks } 12165a5eeccaSmarks } 12175a5eeccaSmarks 12185a5eeccaSmarks *mask = perm_val; 12195a5eeccaSmarks return (0); 12205a5eeccaSmarks } 12215a5eeccaSmarks 1222bf8b6031Smarks 1223bf8b6031Smarks int 1224bf8b6031Smarks ace_inherit_helper(char *str, uint32_t *imask, int table_length) 1225bf8b6031Smarks { 1226bf8b6031Smarks int rc = 0; 1227bf8b6031Smarks 1228bf8b6031Smarks if (strlen(str) == table_length) { 1229bf8b6031Smarks /* 1230bf8b6031Smarks * If the string == table_length then first check to see it's 1231bf8b6031Smarks * in positional format. If that fails then see if it's in 1232bf8b6031Smarks * non-positional format. 1233bf8b6031Smarks */ 1234bf8b6031Smarks if (compute_values(inherit_table, table_length, str, 1235bf8b6031Smarks 1, imask) && compute_values(inherit_table, 1236bf8b6031Smarks table_length, str, 0, imask)) { 1237bf8b6031Smarks rc = 1; 1238bf8b6031Smarks } 1239bf8b6031Smarks } else { 1240bf8b6031Smarks rc = compute_values(inherit_table, table_length, str, 0, imask); 1241bf8b6031Smarks } 1242bf8b6031Smarks 1243bf8b6031Smarks return (rc ? EACL_INHERIT_ERROR : 0); 1244bf8b6031Smarks } 1245bf8b6031Smarks 12465a5eeccaSmarks /* 12475a5eeccaSmarks * compute value for inheritance flags. 12485a5eeccaSmarks */ 12495a5eeccaSmarks int 12505a5eeccaSmarks compute_ace_inherit(char *str, uint32_t *imask) 12515a5eeccaSmarks { 1252bf8b6031Smarks int rc = 0; 12535a5eeccaSmarks 1254bf8b6031Smarks rc = ace_inherit_helper(str, imask, IFLAG_COUNT); 12555a5eeccaSmarks 1256bf8b6031Smarks if (rc && strlen(str) != IFLAG_COUNT) { 12575a5eeccaSmarks 1258bf8b6031Smarks /* is it an old formatted inherit string? */ 1259bf8b6031Smarks rc = ace_inherit_helper(str, imask, IFLAG_COUNT_V1); 1260bf8b6031Smarks } 12615a5eeccaSmarks 1262bf8b6031Smarks return (rc); 12635a5eeccaSmarks } 12645a5eeccaSmarks 12655a5eeccaSmarks 12665a5eeccaSmarks /* 12675a5eeccaSmarks * compute value for ACE permissions. 12685a5eeccaSmarks */ 12695a5eeccaSmarks int 12705a5eeccaSmarks compute_ace_perms(char *str, uint32_t *mask) 12715a5eeccaSmarks { 12725a5eeccaSmarks int positional = 0; 12735a5eeccaSmarks int error; 12745a5eeccaSmarks 12755a5eeccaSmarks if (strlen(str) == ACE_PERM_COUNT) 12765a5eeccaSmarks positional = 1; 12775a5eeccaSmarks 12785a5eeccaSmarks error = compute_values(ace_perm_table, ACE_PERM_COUNT, 12795a5eeccaSmarks str, positional, mask); 12805a5eeccaSmarks 12815a5eeccaSmarks if (error && positional) { 12825a5eeccaSmarks /* 12835a5eeccaSmarks * If positional was set, then make sure permissions 12845a5eeccaSmarks * aren't actually valid in non positional case where 12855a5eeccaSmarks * all permissions are specified, just in random order. 12865a5eeccaSmarks */ 12875a5eeccaSmarks error = compute_values(ace_perm_table, 12885a5eeccaSmarks ACE_PERM_COUNT, str, 0, mask); 12895a5eeccaSmarks } 12905a5eeccaSmarks if (error) 12915a5eeccaSmarks error = EACL_PERM_MASK_ERROR; 12925a5eeccaSmarks 12935a5eeccaSmarks return (error); 12945a5eeccaSmarks } 12955a5eeccaSmarks 12965a5eeccaSmarks 12975a5eeccaSmarks 12985a5eeccaSmarks /* 12995a5eeccaSmarks * compute values for aclent permissions. 13005a5eeccaSmarks */ 13015a5eeccaSmarks int 13025a5eeccaSmarks compute_aclent_perms(char *str, o_mode_t *mask) 13035a5eeccaSmarks { 13045a5eeccaSmarks int error; 13055a5eeccaSmarks uint32_t pmask; 13065a5eeccaSmarks 13075a5eeccaSmarks if (strlen(str) != ACLENT_PERM_COUNT) 13085a5eeccaSmarks return (EACL_PERM_MASK_ERROR); 13095a5eeccaSmarks 13105a5eeccaSmarks *mask = 0; 13115a5eeccaSmarks error = compute_values(aclent_perm_table, ACLENT_PERM_COUNT, 13125a5eeccaSmarks str, 1, &pmask); 13135a5eeccaSmarks if (error == 0) { 13145a5eeccaSmarks *mask = (o_mode_t)pmask; 13155a5eeccaSmarks } else 13165a5eeccaSmarks error = EACL_PERM_MASK_ERROR; 13175a5eeccaSmarks return (error); 13185a5eeccaSmarks } 13195a5eeccaSmarks 13205a5eeccaSmarks /* 13215a5eeccaSmarks * determine ACE permissions. 13225a5eeccaSmarks */ 13235a5eeccaSmarks int 13245a5eeccaSmarks ace_perm_mask(struct acl_perm_type *aclperm, uint32_t *mask) 13255a5eeccaSmarks { 13265a5eeccaSmarks int error; 13275a5eeccaSmarks 13285a5eeccaSmarks if (aclperm->perm_style == PERM_TYPE_EMPTY) { 13295a5eeccaSmarks *mask = 0; 13305a5eeccaSmarks return (0); 13315a5eeccaSmarks } 13325a5eeccaSmarks 13335a5eeccaSmarks if (aclperm->perm_style == PERM_TYPE_ACE) { 13345a5eeccaSmarks *mask = aclperm->perm_val; 13355a5eeccaSmarks return (0); 13365a5eeccaSmarks } 13375a5eeccaSmarks 13385a5eeccaSmarks error = compute_ace_perms(aclperm->perm_str, mask); 13395a5eeccaSmarks if (error) { 13405b233e2dSmarks acl_error(dgettext(TEXT_DOMAIN, 13415b233e2dSmarks "Invalid permission(s) '%s' specified\n"), 13425a5eeccaSmarks aclperm->perm_str); 13435a5eeccaSmarks return (EACL_PERM_MASK_ERROR); 13445a5eeccaSmarks } 13455a5eeccaSmarks 13465a5eeccaSmarks return (0); 13475a5eeccaSmarks } 1348