2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 1999-2002 Robert N. M. Watson
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * acl_to_text - return a text string with a text representation of the acl
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <sys/types.h>
37 #include "namespace.h"
39 #include "un-namespace.h"
40 #include <sys/errno.h>
45 #include "acl_support.h"
48 * acl_to_text - generate a text form of an acl
49 * spec says nothing about output ordering, so leave in acl order
51 * This function will not produce nice results if it is called with
52 * a non-POSIX.1e semantics ACL.
55 char *_nfs4_acl_to_text_np(const acl_t acl, ssize_t *len_p, int flags);
58 _posix1e_acl_to_text(acl_t acl, ssize_t *len_p, int flags)
62 char name_buf[MAXLOGNAME];
63 char perm_buf[_POSIX1E_ACL_STRING_PERM_MAXSIZE+1],
64 effective_perm_buf[_POSIX1E_ACL_STRING_PERM_MAXSIZE+1];
68 acl_perm_t ae_perm, effective_perm, mask_perm;
74 acl_int = &acl->ats_acl;
76 mask_perm = ACL_PERM_BITS; /* effective is regular if no mask */
77 for (i = 0; i < acl_int->acl_cnt; i++)
78 if (acl_int->acl_entry[i].ae_tag == ACL_MASK)
79 mask_perm = acl_int->acl_entry[i].ae_perm;
81 for (i = 0; i < acl_int->acl_cnt; i++) {
82 ae_tag = acl_int->acl_entry[i].ae_tag;
83 ae_id = acl_int->acl_entry[i].ae_id;
84 ae_perm = acl_int->acl_entry[i].ae_perm;
88 error = _posix1e_acl_perm_to_string(ae_perm,
89 _POSIX1E_ACL_STRING_PERM_MAXSIZE+1, perm_buf);
92 len = asprintf(&tmpbuf, "%suser::%s\n", buf,
101 error = _posix1e_acl_perm_to_string(ae_perm,
102 _POSIX1E_ACL_STRING_PERM_MAXSIZE+1, perm_buf);
106 error = _posix1e_acl_id_to_name(ae_tag, ae_id,
107 MAXLOGNAME, name_buf, flags);
111 effective_perm = ae_perm & mask_perm;
112 if (effective_perm != ae_perm) {
113 error = _posix1e_acl_perm_to_string(
115 _POSIX1E_ACL_STRING_PERM_MAXSIZE+1,
119 len = asprintf(&tmpbuf, "%suser:%s:%s\t\t# "
121 buf, name_buf, perm_buf,
124 len = asprintf(&tmpbuf, "%suser:%s:%s\n", buf,
134 error = _posix1e_acl_perm_to_string(ae_perm,
135 _POSIX1E_ACL_STRING_PERM_MAXSIZE+1, perm_buf);
139 effective_perm = ae_perm & mask_perm;
140 if (effective_perm != ae_perm) {
141 error = _posix1e_acl_perm_to_string(
143 _POSIX1E_ACL_STRING_PERM_MAXSIZE+1,
147 len = asprintf(&tmpbuf, "%sgroup::%s\t\t# "
149 buf, perm_buf, effective_perm_buf);
151 len = asprintf(&tmpbuf, "%sgroup::%s\n", buf,
161 error = _posix1e_acl_perm_to_string(ae_perm,
162 _POSIX1E_ACL_STRING_PERM_MAXSIZE+1, perm_buf);
166 error = _posix1e_acl_id_to_name(ae_tag, ae_id,
167 MAXLOGNAME, name_buf, flags);
171 effective_perm = ae_perm & mask_perm;
172 if (effective_perm != ae_perm) {
173 error = _posix1e_acl_perm_to_string(
175 _POSIX1E_ACL_STRING_PERM_MAXSIZE+1,
179 len = asprintf(&tmpbuf, "%sgroup:%s:%s\t\t# "
181 buf, name_buf, perm_buf,
184 len = asprintf(&tmpbuf, "%sgroup:%s:%s\n", buf,
194 error = _posix1e_acl_perm_to_string(ae_perm,
195 _POSIX1E_ACL_STRING_PERM_MAXSIZE+1, perm_buf);
199 len = asprintf(&tmpbuf, "%smask::%s\n", buf,
208 error = _posix1e_acl_perm_to_string(ae_perm,
209 _POSIX1E_ACL_STRING_PERM_MAXSIZE+1, perm_buf);
213 len = asprintf(&tmpbuf, "%sother::%s\n", buf,
228 *len_p = strlen(buf);
233 /* jump to here sets errno already, we just clean up */
239 acl_to_text_np(acl_t acl, ssize_t *len_p, int flags)
247 switch (_acl_brand(acl)) {
248 case ACL_BRAND_POSIX:
249 return (_posix1e_acl_to_text(acl, len_p, flags));
251 return (_nfs4_acl_to_text_np(acl, len_p, flags));
259 acl_to_text(acl_t acl, ssize_t *len_p)
262 return (acl_to_text_np(acl, len_p, 0));