2 * Copyright (c) 1999-2002 Robert N. M. Watson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * acl_to_text - return a text string with a text representation of the acl
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <sys/types.h>
35 #include "namespace.h"
37 #include "un-namespace.h"
38 #include <sys/errno.h>
43 #include "acl_support.h"
46 * acl_to_text - generate a text form of an acl
47 * spec says nothing about output ordering, so leave in acl order
49 * This function will not produce nice results if it is called with
50 * a non-POSIX.1e semantics ACL.
53 char *_nfs4_acl_to_text_np(const acl_t acl, ssize_t *len_p, int flags);
56 _posix1e_acl_to_text(acl_t acl, ssize_t *len_p, int flags)
60 char name_buf[MAXLOGNAME];
61 char perm_buf[_POSIX1E_ACL_STRING_PERM_MAXSIZE+1],
62 effective_perm_buf[_POSIX1E_ACL_STRING_PERM_MAXSIZE+1];
66 acl_perm_t ae_perm, effective_perm, mask_perm;
72 acl_int = &acl->ats_acl;
74 mask_perm = ACL_PERM_BITS; /* effective is regular if no mask */
75 for (i = 0; i < acl_int->acl_cnt; i++)
76 if (acl_int->acl_entry[i].ae_tag == ACL_MASK)
77 mask_perm = acl_int->acl_entry[i].ae_perm;
79 for (i = 0; i < acl_int->acl_cnt; i++) {
80 ae_tag = acl_int->acl_entry[i].ae_tag;
81 ae_id = acl_int->acl_entry[i].ae_id;
82 ae_perm = acl_int->acl_entry[i].ae_perm;
86 error = _posix1e_acl_perm_to_string(ae_perm,
87 _POSIX1E_ACL_STRING_PERM_MAXSIZE+1, perm_buf);
90 len = asprintf(&tmpbuf, "%suser::%s\n", buf,
99 error = _posix1e_acl_perm_to_string(ae_perm,
100 _POSIX1E_ACL_STRING_PERM_MAXSIZE+1, perm_buf);
104 error = _posix1e_acl_id_to_name(ae_tag, ae_id,
105 MAXLOGNAME, name_buf, flags);
109 effective_perm = ae_perm & mask_perm;
110 if (effective_perm != ae_perm) {
111 error = _posix1e_acl_perm_to_string(
113 _POSIX1E_ACL_STRING_PERM_MAXSIZE+1,
117 len = asprintf(&tmpbuf, "%suser:%s:%s\t\t# "
119 buf, name_buf, perm_buf,
122 len = asprintf(&tmpbuf, "%suser:%s:%s\n", buf,
132 error = _posix1e_acl_perm_to_string(ae_perm,
133 _POSIX1E_ACL_STRING_PERM_MAXSIZE+1, perm_buf);
137 effective_perm = ae_perm & mask_perm;
138 if (effective_perm != ae_perm) {
139 error = _posix1e_acl_perm_to_string(
141 _POSIX1E_ACL_STRING_PERM_MAXSIZE+1,
145 len = asprintf(&tmpbuf, "%sgroup::%s\t\t# "
147 buf, perm_buf, effective_perm_buf);
149 len = asprintf(&tmpbuf, "%sgroup::%s\n", buf,
159 error = _posix1e_acl_perm_to_string(ae_perm,
160 _POSIX1E_ACL_STRING_PERM_MAXSIZE+1, perm_buf);
164 error = _posix1e_acl_id_to_name(ae_tag, ae_id,
165 MAXLOGNAME, name_buf, flags);
169 effective_perm = ae_perm & mask_perm;
170 if (effective_perm != ae_perm) {
171 error = _posix1e_acl_perm_to_string(
173 _POSIX1E_ACL_STRING_PERM_MAXSIZE+1,
177 len = asprintf(&tmpbuf, "%sgroup:%s:%s\t\t# "
179 buf, name_buf, perm_buf,
182 len = asprintf(&tmpbuf, "%sgroup:%s:%s\n", buf,
192 error = _posix1e_acl_perm_to_string(ae_perm,
193 _POSIX1E_ACL_STRING_PERM_MAXSIZE+1, perm_buf);
197 len = asprintf(&tmpbuf, "%smask::%s\n", buf,
206 error = _posix1e_acl_perm_to_string(ae_perm,
207 _POSIX1E_ACL_STRING_PERM_MAXSIZE+1, perm_buf);
211 len = asprintf(&tmpbuf, "%sother::%s\n", buf,
226 *len_p = strlen(buf);
231 /* jump to here sets errno already, we just clean up */
237 acl_to_text_np(acl_t acl, ssize_t *len_p, int flags)
245 switch (_acl_brand(acl)) {
246 case ACL_BRAND_POSIX:
247 return (_posix1e_acl_to_text(acl, len_p, flags));
249 return (_nfs4_acl_to_text_np(acl, len_p, flags));
257 acl_to_text(acl_t acl, ssize_t *len_p)
260 return (acl_to_text_np(acl, len_p, 0));