Page MenuHomeFreeBSD

D28255.id82637.diff
No OneTemporary

D28255.id82637.diff

Index: bin/getfacl/getfacl.c
===================================================================
--- bin/getfacl/getfacl.c
+++ bin/getfacl/getfacl.c
@@ -83,97 +83,6 @@
return (gr->gr_name);
}
-/*
- * return an ACL corresponding to the permissions
- * contained in mode_t
- */
-static acl_t
-acl_from_mode(const mode_t mode)
-{
- acl_t acl;
- acl_entry_t entry;
- acl_permset_t perms;
-
- /* create the ACL */
- acl = acl_init(3);
- if (!acl)
- return NULL;
-
- /* First entry: ACL_USER_OBJ */
- if (acl_create_entry(&acl, &entry) == -1)
- return NULL;
- if (acl_set_tag_type(entry, ACL_USER_OBJ) == -1)
- return NULL;
-
- if (acl_get_permset(entry, &perms) == -1)
- return NULL;
- if (acl_clear_perms(perms) == -1)
- return NULL;
-
- /* calculate user mode */
- if (mode & S_IRUSR)
- if (acl_add_perm(perms, ACL_READ) == -1)
- return NULL;
- if (mode & S_IWUSR)
- if (acl_add_perm(perms, ACL_WRITE) == -1)
- return NULL;
- if (mode & S_IXUSR)
- if (acl_add_perm(perms, ACL_EXECUTE) == -1)
- return NULL;
- if (acl_set_permset(entry, perms) == -1)
- return NULL;
-
- /* Second entry: ACL_GROUP_OBJ */
- if (acl_create_entry(&acl, &entry) == -1)
- return NULL;
- if (acl_set_tag_type(entry, ACL_GROUP_OBJ) == -1)
- return NULL;
-
- if (acl_get_permset(entry, &perms) == -1)
- return NULL;
- if (acl_clear_perms(perms) == -1)
- return NULL;
-
- /* calculate group mode */
- if (mode & S_IRGRP)
- if (acl_add_perm(perms, ACL_READ) == -1)
- return NULL;
- if (mode & S_IWGRP)
- if (acl_add_perm(perms, ACL_WRITE) == -1)
- return NULL;
- if (mode & S_IXGRP)
- if (acl_add_perm(perms, ACL_EXECUTE) == -1)
- return NULL;
- if (acl_set_permset(entry, perms) == -1)
- return NULL;
-
- /* Third entry: ACL_OTHER */
- if (acl_create_entry(&acl, &entry) == -1)
- return NULL;
- if (acl_set_tag_type(entry, ACL_OTHER) == -1)
- return NULL;
-
- if (acl_get_permset(entry, &perms) == -1)
- return NULL;
- if (acl_clear_perms(perms) == -1)
- return NULL;
-
- /* calculate other mode */
- if (mode & S_IROTH)
- if (acl_add_perm(perms, ACL_READ) == -1)
- return NULL;
- if (mode & S_IWOTH)
- if (acl_add_perm(perms, ACL_WRITE) == -1)
- return NULL;
- if (mode & S_IXOTH)
- if (acl_add_perm(perms, ACL_EXECUTE) == -1)
- return NULL;
- if (acl_set_permset(entry, perms) == -1)
- return NULL;
-
- return(acl);
-}
-
static int
print_acl(char *path, acl_type_t type, int hflag, int iflag, int nflag,
int qflag, int vflag)
@@ -229,7 +138,7 @@
errno = 0;
if (type == ACL_TYPE_DEFAULT)
return(0);
- acl = acl_from_mode(sb.st_mode);
+ acl = acl_from_mode_np(sb.st_mode);
if (!acl) {
warn("%s: acl_from_mode() failed", path);
return(-1);
Index: lib/libc/posix1e/Makefile.inc
===================================================================
--- lib/libc/posix1e/Makefile.inc
+++ lib/libc/posix1e/Makefile.inc
@@ -11,13 +11,16 @@
CONFS+= posix1e/mac.conf
SRCS+= acl_branding.c \
acl_calc_mask.c \
+ acl_cmp_np.c \
acl_compat.c \
acl_copy.c \
acl_delete.c \
acl_delete_entry.c \
acl_entry.c \
+ acl_equiv_mode_np.c \
acl_flag.c \
acl_free.c \
+ acl_from_mode_np.c \
acl_from_text.c \
acl_from_text_nfs4.c \
acl_get.c \
@@ -46,6 +49,7 @@
acl_calc_mask.3 \
acl_clear_flags_np.3 \
acl_clear_perms.3 \
+ acl_cmp_np.3 \
acl_copy_entry.3 \
acl_create_entry.3 \
acl_delete.3 \
@@ -53,7 +57,9 @@
acl_delete_flag_np.3 \
acl_delete_perm.3 \
acl_dup.3 \
+ acl_equiv_mode_np.3 \
acl_free.3 \
+ acl_from_mode_np.3 \
acl_from_text.3 \
acl_get.3 \
acl_get_brand_np.3 \
Index: lib/libc/posix1e/Symbol.map
===================================================================
--- lib/libc/posix1e/Symbol.map
+++ lib/libc/posix1e/Symbol.map
@@ -84,3 +84,9 @@
acl_strip_np;
acl_to_text_np;
};
+
+FBSD_1.6 {
+ acl_cmp_np;
+ acl_equiv_mode_np;
+ acl_from_mode_np;
+};
Index: lib/libc/posix1e/acl_cmp_np.3
===================================================================
--- /dev/null
+++ lib/libc/posix1e/acl_cmp_np.3
@@ -0,0 +1,84 @@
+.\"-
+.\" Copyright (c) 2021 Gleb Popov
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd January 20, 2021
+.Dt ACL_CMP_NP 3
+.Os
+.Sh NAME
+.Nm acl_cmp
+.Nd compare between two ACLs
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft int
+.Fn acl_cmp_np "acl_t acl1" "acl_t acl2"
+.Sh DESCRIPTION
+The
+.Fn acl_cmp_np
+function is a non-portable call that checks if ACLs pointed to by
+.Va acl1
+and
+.Va acl2
+are equivalent. The two ACLs are considered equal when they contain the same
+entries with matching tag types, qualifiers and permissions.
+.Sh RETURN VALUES
+Upon successful completion, this function returns 0 if the given ACLs are
+equivalent and 1 if they differ.
+Otherwise, the value -1 shall be returned, and
+.Va errno
+shall be set to indicate the error.
+.Sh ERRORS
+If any of the following conditions occur, the
+.Fn acl_cmp_np
+function shall return a value of
+.Va -1
+and set
+.Va errno
+to the corresponding value:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+Either first or second argument does not point to a valid ACL.
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr posix1e 3
+.Sh STANDARDS
+POSIX.1e is described in IEEE POSIX.1e draft 17.
+Discussion
+of the draft continues on the cross-platform POSIX.1e implementation
+mailing list.
+To join this list, see the
+.Fx
+POSIX.1e implementation
+page for more information.
+.Sh HISTORY
+POSIX.1e support was introduced in
+.Fx 4.0 ,
+and development continues.
+.Sh AUTHORS
+.An Gleb Popov
Index: lib/libc/posix1e/acl_cmp_np.c
===================================================================
--- /dev/null
+++ lib/libc/posix1e/acl_cmp_np.c
@@ -0,0 +1,57 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2021 Gleb Popov
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+/*
+ * acl_cmp_np: Compare two ACL's.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/acl.h>
+#include <sys/errno.h>
+#include "acl_support.h"
+
+/*
+ * returns 0 if acl_t's are identical, 1 otherwise
+ */
+int
+acl_cmp_np(acl_t acl1, acl_t acl2)
+{
+ if (_acl_brand(acl1) != _acl_brand(acl2))
+ return 1;
+
+ // _acl_differs doesn't handle ACL_BRAND_UNKNOWN
+ if (_acl_brand(acl1) == ACL_BRAND_UNKNOWN ||
+ _acl_brand(acl2) == ACL_BRAND_UNKNOWN)
+ {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ return _acl_differs(acl1, acl2);
+}
Index: lib/libc/posix1e/acl_equiv_mode_np.3
===================================================================
--- /dev/null
+++ lib/libc/posix1e/acl_equiv_mode_np.3
@@ -0,0 +1,96 @@
+.\"-
+.\" Copyright (c) 2021 Gleb Popov
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd January 20, 2021
+.Dt ACL_EQUIV_MODE_NP 3
+.Os
+.Sh NAME
+.Nm acl_equiv_mode_np
+.Nd check if ACL can be represented as UNIX permissions
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft int
+.Fn acl_equiv_mode_np "acl_t acl" "mode_t* mode_p"
+.Sh DESCRIPTION
+The
+.Fn acl_equiv_mode_np
+function is a non-portable call checks that entries contained in the
+.Va acl
+argument have only ACL_USER_OBJ, ACL_GROUP_OBJ, and ACL_OTHER tag types, and that
+permissions contained in these entries consist only of ACL_READ, ACL_WRITE and
+ACL_EXECUTE. If the check succeeds, the ACL can be represented as traditional UNIX
+file permissions bits set.
+.Pp
+If
+.Va mode_p
+is not NULL and the check succeeds, the function fills the argument with mode
+value corresponding to permissions contained in the ACL.
+.Sh RETURN VALUES
+Upon successful completion, the function return 0 if the ACL can be represented
+as UNIX permissions and 1 if it is not possible.
+Otherwise, a value
+of
+.Va -1
+is returned, and
+.Va errno
+is set to indicate the error.
+.Sh ERRORS
+If any of the following conditions occur, the
+.Fn acl_equiv_mode_np
+function shall return a value of
+.Va -1
+and set
+.Va errno
+to the corresponding value:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+Argument
+.Fa acl
+does not point to a valid ACL.
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_from_mode_np 3 ,
+.Xr posix1e 3
+.Sh STANDARDS
+POSIX.1e is described in IEEE POSIX.1e draft 17.
+Discussion
+of the draft continues on the cross-platform POSIX.1e implementation
+mailing list.
+To join this list, see the
+.Fx
+POSIX.1e implementation
+page for more information.
+.Sh HISTORY
+POSIX.1e support was introduced in
+.Fx 4.0 ,
+and development continues.
+.Sh AUTHORS
+.An Gleb Popov
Index: lib/libc/posix1e/acl_equiv_mode_np.c
===================================================================
--- /dev/null
+++ lib/libc/posix1e/acl_equiv_mode_np.c
@@ -0,0 +1,96 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2021 Gleb Popov
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+/*
+ * acl_equiv_mode_np: Check if an ACL can be represented as a mode_t.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/errno.h>
+#include <sys/stat.h>
+#include <sys/acl.h>
+#include "acl_support.h"
+
+int
+acl_equiv_mode_np(acl_t acl, mode_t *mode_p)
+{
+ int cur_entry = 0;
+ mode_t ret_mode;
+ // TODO: is this correct?
+ if (_acl_brand(acl) != ACL_BRAND_POSIX)
+ {
+ errno = EINVAL;
+ return -1;
+ }
+
+ while (cur_entry < acl->ats_acl.acl_cnt)
+ {
+ acl_entry_t entry = &acl->ats_acl.acl_entry[cur_entry++];
+
+ if ((entry->ae_perm & ACL_PERM_BITS) != entry->ae_tag)
+ return 1;
+
+ switch (entry->ae_tag)
+ {
+ case ACL_USER_OBJ:
+ if (entry->ae_perm & ACL_READ)
+ ret_mode |= S_IRUSR;
+ if (entry->ae_perm & ACL_WRITE)
+ ret_mode |= S_IWUSR;
+ if (entry->ae_perm & ACL_EXECUTE)
+ ret_mode |= S_IXUSR;
+ continue;
+ case ACL_GROUP_OBJ:
+ if (entry->ae_perm & ACL_READ)
+ ret_mode |= S_IRGRP;
+ if (entry->ae_perm & ACL_WRITE)
+ ret_mode |= S_IWGRP;
+ if (entry->ae_perm & ACL_EXECUTE)
+ ret_mode |= S_IXGRP;
+ continue;
+ case ACL_OTHER:
+ if (entry->ae_perm & ACL_READ)
+ ret_mode |= S_IROTH;
+ if (entry->ae_perm & ACL_WRITE)
+ ret_mode |= S_IWOTH;
+ if (entry->ae_perm & ACL_EXECUTE)
+ ret_mode |= S_IXOTH;
+ continue;
+ default:
+ return 1;
+ }
+ }
+
+ if (mode_p)
+ *mode_p = ret_mode;
+
+ return 0;
+}
Index: lib/libc/posix1e/acl_from_mode_np.3
===================================================================
--- /dev/null
+++ lib/libc/posix1e/acl_from_mode_np.3
@@ -0,0 +1,97 @@
+.\"-
+.\" Copyright (c) 2021 Gleb Popov
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd January 20, 2021
+.Dt ACL_FROM_MODE_NP 3
+.Os
+.Sh NAME
+.Nm acl_from_mode_np
+.Nd create an ACL from status information
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft acl_t
+.Fn acl_from_mode_np "const mode_t mode"
+.Sh DESCRIPTION
+The
+.Fn acl_from_mode_np
+function is a non-portable call that converts the permissions set referred to by
+.Va mode
+into the corresponding minimal ACL structure, appropriate for applying to
+files or manipulating.
+.Pp
+This function causes memory to be allocated.
+The caller should free any
+releasable memory, when the new ACL is no longer required, by calling
+.Xr acl_free 3
+with the
+.Va (void *)acl_t
+as an argument.
+.Sh RETURN VALUES
+Upon successful completion, the function shall return a pointer to the
+internal representation of the ACL in working storage.
+Otherwise, a value
+of
+.Va (acl_t)NULL
+shall be returned, and
+.Va errno
+shall be set to indicate the error.
+.Sh ERRORS
+If any of the following conditions occur, the
+.Fn acl_from_mode_np
+function shall return a value of
+.Va (acl_t)NULL
+and set
+.Va errno
+to the corresponding value:
+.Bl -tag -width Er
+.It Bq Er ENOMEM
+The ACL working storage requires more memory than is allowed by the
+hardware or system-imposed memory management constraints.
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_free 3 ,
+.Xr acl_from_text 3 ,
+.Xr posix1e 3
+.Sh STANDARDS
+POSIX.1e is described in IEEE POSIX.1e draft 17.
+Discussion
+of the draft continues on the cross-platform POSIX.1e implementation
+mailing list.
+To join this list, see the
+.Fx
+POSIX.1e implementation
+page for more information.
+.Sh HISTORY
+POSIX.1e support was introduced in
+.Fx 4.0 ,
+and development continues.
+.Sh AUTHORS
+.An Gleb Popov
Index: lib/libc/posix1e/acl_from_mode_np.c
===================================================================
--- /dev/null
+++ lib/libc/posix1e/acl_from_mode_np.c
@@ -0,0 +1,115 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2021 Robert N M Watson, Gleb Popov
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+/*
+ * acl_from_mode_np: Create an ACL from a mode_t.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/acl.h>
+#include <sys/stat.h>
+
+/*
+ * return an ACL corresponding to the permissions
+ * contained in mode_t
+ */
+acl_t
+acl_from_mode_np(const mode_t mode)
+{
+ acl_t acl;
+ acl_entry_t entry;
+ acl_permset_t perms;
+
+ /* create the ACL */
+ acl = acl_init(3);
+ /* here and below, the only possible reason to fail is ENOMEM, so
+ * no need to set errno again
+ */
+ if (!acl)
+ return NULL;
+
+ /* First entry: ACL_USER_OBJ */
+ if (acl_create_entry(&acl, &entry) == -1)
+ return NULL;
+ /* TODO: need to handle error there and below? */
+ acl_set_tag_type(entry, ACL_USER_OBJ);
+
+ acl_get_permset(entry, &perms);
+ acl_clear_perms(perms);
+
+ /* calculate user mode */
+ if (mode & S_IRUSR)
+ acl_add_perm(perms, ACL_READ);
+ if (mode & S_IWUSR)
+ acl_add_perm(perms, ACL_WRITE);
+ if (mode & S_IXUSR)
+ acl_add_perm(perms, ACL_EXECUTE);
+
+ acl_set_permset(entry, perms);
+
+ /* Second entry: ACL_GROUP_OBJ */
+ if (acl_create_entry(&acl, &entry) == -1)
+ return NULL;
+ acl_set_tag_type(entry, ACL_GROUP_OBJ);
+
+ acl_get_permset(entry, &perms);
+ acl_clear_perms(perms);
+
+ /* calculate group mode */
+ if (mode & S_IRGRP)
+ acl_add_perm(perms, ACL_READ);
+ if (mode & S_IWGRP)
+ acl_add_perm(perms, ACL_WRITE);
+ if (mode & S_IXGRP)
+ acl_add_perm(perms, ACL_EXECUTE);
+
+ acl_set_permset(entry, perms);
+
+ /* Third entry: ACL_OTHER */
+ if (acl_create_entry(&acl, &entry) == -1)
+ return NULL;
+ acl_set_tag_type(entry, ACL_OTHER);
+
+ acl_get_permset(entry, &perms);
+ acl_clear_perms(perms);
+
+ /* calculate other mode */
+ if (mode & S_IROTH)
+ acl_add_perm(perms, ACL_READ);
+ if (mode & S_IWOTH)
+ acl_add_perm(perms, ACL_WRITE);
+ if (mode & S_IXOTH)
+ acl_add_perm(perms, ACL_EXECUTE);
+
+ acl_set_permset(entry, perms);
+
+ return(acl);
+}
Index: sys/sys/acl.h
===================================================================
--- sys/sys/acl.h
+++ sys/sys/acl.h
@@ -30,7 +30,7 @@
*
* $FreeBSD$
*/
-/*
+/*
* Developed by the TrustedBSD Project.
* Support for POSIX.1e and NFSv4 access control lists.
*/
@@ -363,6 +363,7 @@
int acl_calc_mask(acl_t *_acl_p);
int acl_clear_flags_np(acl_flagset_t _flagset_d);
int acl_clear_perms(acl_permset_t _permset_d);
+int acl_cmp_np(acl_t _acl1, acl_t _acl2);
int acl_copy_entry(acl_entry_t _dest_d, acl_entry_t _src_d);
ssize_t acl_copy_ext(void *_buf_p, acl_t _acl, ssize_t _size);
acl_t acl_copy_int(const void *_buf_p);
@@ -378,7 +379,9 @@
int acl_delete_flag_np(acl_flagset_t _flagset_d, acl_flag_t _flag);
int acl_delete_perm(acl_permset_t _permset_d, acl_perm_t _perm);
acl_t acl_dup(acl_t _acl);
+int acl_equiv_mode_np(acl_t acl, mode_t *mode_p);
int acl_free(void *_obj_p);
+acl_t acl_from_mode_np(const mode_t mode);
acl_t acl_from_text(const char *_buf_p);
int acl_get_brand_np(acl_t _acl, int *_brand_p);
int acl_get_entry(acl_t _acl, int _entry_id, acl_entry_t *_entry_p);

File Metadata

Mime Type
text/plain
Expires
Wed, Jun 24, 8:02 AM (5 h, 12 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34277974
Default Alt Text
D28255.id82637.diff (22 KB)

Event Timeline