diff --git a/include/zfsacl.h b/include/zfsacl.h index 8157c5771f5b..b600598c6adf 100644 --- a/include/zfsacl.h +++ b/include/zfsacl.h @@ -25,7 +25,7 @@ */ #ifndef __ZFSACL_H__ -#define __ZFSACL_H__ extern __attribute__((visibility("default"))) +#define __ZFSACL_H__ #include #include @@ -35,9 +35,6 @@ #include #include -#define zfsace4 zfsacl_entry -typedef unsigned int uint_t; - /* * BRAND_ACCESS and BRAND_DEFAULT * values chosen so can convert easily @@ -75,86 +72,38 @@ struct native_acl { zfsacl_brand_t brand; }; -#ifdef __linux__ -struct zfsacl_entry { uint_t netlong[5]; }; +#if defined (FREEBSD) + +#define zfsacl_entry acl_entry +#define zfsacl acl_t_struct + +#else + +struct zfsacl_entry { uint netlong[5]; }; struct zfsacl { - size_t aclbuf_size; - zfsacl_brand_t brand; - uint_t *aclbuf; + size_t aclbuf_size; + zfsacl_brand_t brand; + uint *aclbuf; }; -#else -#define _ACL_PRIVATE -#define zfsacl_entry acl_entry -#define zfsacl acl_t_struct + #endif typedef struct zfsacl_entry *zfsacl_entry_t; typedef struct zfsacl *zfsacl_t; typedef unsigned int zfsace_flagset_t; -typedef int zfsace_permset_t; +typedef unsigned int zfsace_permset_t; typedef uid_t zfsace_id_t; typedef unsigned int zfsacl_aclflags_t; -#define ZFSACL_UNDEFINED_ID ((uid_t)-1) -#define ZFSACL_APPEND_ENTRY -1 -#define ZFSACL_MAX_ENTRIES 64 +#define ZFSACL_UNDEFINED_ID ((uid_t)-1) +#define ZFSACL_APPEND_ENTRY -1 +#define ZFSACL_MAX_ENTRIES 1024 #ifndef ARRAY_SIZE #define ARRAY_SIZE(a) ((int)(sizeof (a)/sizeof (a[0]))) #endif -/* - * this is a warning hack. The idea is to use this everywhere that we - * get the "discarding const" warning from gcc. That doesn't actually - * fix the problem of course, but it means that when we do get to - * cleaning them up we can do it by searching the code for - * discard_const. - * - * It also means that other error types aren't as swamped by the noise - * of hundreds of const warnings, so we are more likely to notice when - * we get new errors. - * - * Please only add more uses of this macro when you find it - * _really_ hard to fix const warnings. Our aim is to eventually use - * this function in only a very few places. - * - * Also, please call this via the discard_const_p() macro interface, as that - * makes the return type safe. - */ -#ifndef discard_const -#define discard_const(ptr) ((void *)((uintptr_t)(ptr))) -#endif - -/* - * Type-safe version of discard_const - */ -#ifndef discard_const_p -#define discard_const_p(type, ptr) ((type *)discard_const(ptr)) -#endif - -typedef struct aclflags2name { - zfsacl_aclflags_t flag; - const char *name; -} aclflags2name_t; - -typedef struct aceperms2name { - zfsace_permset_t perm; - const char *name; - char letter; -} aceperms2name_t; - -typedef struct aceflags2name { - zfsace_flagset_t flag; - const char *name; - char letter; -} aceflags2name_t; - -typedef struct aceswho2name { - zfsace_who_t who; - const char *name; -} aceswho2name_t; - boolean_t zfsacl_set_fd(int _fd, zfsacl_t _acl); boolean_t zfsacl_set_file(const char *_path_p, zfsacl_t _acl); boolean_t zfsacl_set_link(const char *_path_p, zfsacl_t _acl); @@ -290,6 +239,9 @@ boolean_t zfsace_set_who(zfsacl_entry_t _entry, zfsace_who_t _who, zfsace_id_t _aeid); boolean_t zfsace_set_entry_type(zfsacl_entry_t _entry, zfsace_entry_type_t _tp); +zfsacl_t zfsacl_calculate_inherited_acl(zfsacl_t p, zfsacl_t t, boolean_t dir); + + /* * NFSv4 ACL-wide flags * used in zfsacl_get_aclflags() and zfsacl_set_aclflags() @@ -379,4 +331,64 @@ boolean_t zfsace_set_entry_type(zfsacl_entry_t _entry, zfsace_entry_type_t _tp); (who != ZFSACL_GROUP_OBJ) && (who != ZFSACL_GROUP) && \ (who != ZFSACL_EVERYONE)) +static const struct { + zfsacl_aclflags_t flag; + const char *name; +} aclflag2name[] = { + { ZFSACL_AUTO_INHERIT, "AUTO_INHERIT" }, + { ZFSACL_PROTECTED, "PROTECTED" }, + { ZFSACL_DEFAULTED, "DEFAULTED" }, + { ZFSACL_IS_TRIVIAL, "ACL_IS_TRIVIAL" }, + { ZFSACL_IS_DIR, "IS_DIRECTORY" }, +}; + +static const struct { + zfsace_permset_t perm; + const char *name; + char letter; +} aceperm2name[] = { + { ZFSACE_READ_DATA, "READ_DATA", 'r' }, + { ZFSACE_LIST_DIRECTORY, "LIST_DIRECTORY", '\0' }, + { ZFSACE_WRITE_DATA, "WRITE_DATA", 'w' }, + { ZFSACE_ADD_FILE, "ADD_FILE", '\0' }, + { ZFSACE_APPEND_DATA, "APPEND_DATA", 'p' }, + { ZFSACE_DELETE, "DELETE", 'd' }, + { ZFSACE_DELETE_CHILD, "DELETE_CHILD", 'D' }, + { ZFSACE_ADD_SUBDIRECTORY, "ADD_SUBDIRECTORY", '\0' }, + { ZFSACE_READ_ATTRIBUTES, "READ_ATTRIBUTES", 'a' }, + { ZFSACE_WRITE_ATTRIBUTES, "WRITE_ATTRIBUTES", 'A' }, + { ZFSACE_READ_NAMED_ATTRS, "READ_NAMED_ATTRS", 'R' }, + { ZFSACE_WRITE_NAMED_ATTRS, "WRITE_NAMED_ATTRS", 'W' }, + { ZFSACE_READ_ACL, "READ_ACL", 'c' }, + { ZFSACE_WRITE_ACL, "WRITE_ACL", 'C' }, + { ZFSACE_WRITE_OWNER, "WRITE_OWNER", 'o' }, + { ZFSACE_SYNCHRONIZE, "SYNCHRONIZE", 's' }, +}; + +static const struct { + zfsace_flagset_t flag; + const char *name; + char letter; +} aceflag2name[] = { + { ZFSACE_FILE_INHERIT, "FILE_INHERIT", 'f' }, + { ZFSACE_DIRECTORY_INHERIT, "DIRECTORY_INHERIT", 'd' }, + { ZFSACE_INHERIT_ONLY, "INHERIT_ONLY", 'i' }, + { ZFSACE_NO_PROPAGATE_INHERIT, "NO_PROPAGATE_INHERIT", 'n' }, + { ZFSACE_INHERITED_ACE, "INHERITED", 'I' }, +}; + +static const struct { + zfsace_who_t who; + const char *name; +} acewho2name[] = { + { ZFSACL_UNDEFINED_TAG, "UNDEFINED" }, + { ZFSACL_USER_OBJ, "USER_OBJ" }, + { ZFSACL_GROUP_OBJ, "GROUP_OBJ" }, + { ZFSACL_EVERYONE, "EVERYONE" }, + { ZFSACL_USER, "USER" }, + { ZFSACL_GROUP, "GROUP" }, + { ZFSACL_OTHER, "OTHER" }, + { ZFSACL_MASK, "MASK" }, +}; + #endif /* __ZFSACL_H__ */ diff --git a/lib/libzfsacl/libpyzfsacl.c b/lib/libzfsacl/libpyzfsacl.c index ca0e8ce08e0f..618eaa105f2f 100644 --- a/lib/libzfsacl/libpyzfsacl.c +++ b/lib/libzfsacl/libpyzfsacl.c @@ -50,6 +50,8 @@ typedef struct { int current_idx; } py_acl_iterator; +static PyObject *py_acl_inherit(PyObject *, PyObject *, PyObject *); + static void set_exc_from_errno(const char *func) { @@ -100,14 +102,6 @@ PyTypeObject PyACLIterator = { .tp_iter = PyObject_SelfIter, }; -aclflags2name_t aclflag2name[] = { - { ZFSACL_AUTO_INHERIT, "AUTO_INHERIT" }, - { ZFSACL_PROTECTED, "PROTECTED" }, - { ZFSACL_DEFAULTED, "DEFAULTED" }, - { ZFSACL_IS_TRIVIAL, "ACL_IS_TRIVIAL" }, - { ZFSACL_IS_DIR, "IS_DIRECTORY" }, -}; - static inline PyObject * aclflag_to_pylist(zfsacl_aclflags_t flags) { @@ -143,26 +137,6 @@ aclflag_to_pylist(zfsacl_aclflags_t flags) return (out); } - -aceperms2name_t aceperm2name[] = { - { ZFSACE_READ_DATA, "READ_DATA", 'r' }, - { ZFSACE_LIST_DIRECTORY, "LIST_DIRECTORY", '\0' }, - { ZFSACE_WRITE_DATA, "WRITE_DATA", 'w' }, - { ZFSACE_ADD_FILE, "ADD_FILE", '\0' }, - { ZFSACE_APPEND_DATA, "APPEND_DATA", 'p' }, - { ZFSACE_DELETE, "DELETE", 'd' }, - { ZFSACE_DELETE_CHILD, "DELETE_CHILD", 'D' }, - { ZFSACE_ADD_SUBDIRECTORY, "ADD_SUBDIRECTORY", '\0' }, - { ZFSACE_READ_ATTRIBUTES, "READ_ATTRIBUTES", 'a' }, - { ZFSACE_WRITE_ATTRIBUTES, "WRITE_ATTRIBUTES", 'A' }, - { ZFSACE_READ_NAMED_ATTRS, "READ_NAMED_ATTRS", 'R' }, - { ZFSACE_WRITE_NAMED_ATTRS, "WRITE_NAMED_ATTRS", 'W' }, - { ZFSACE_READ_ACL, "READ_ACL", 'c' }, - { ZFSACE_WRITE_ACL, "WRITE_ACL", 'C' }, - { ZFSACE_WRITE_OWNER, "WRITE_OWNER", 'o' }, - { ZFSACE_SYNCHRONIZE, "SYNCHRONIZE", 's' }, -}; - static PyObject * permset_to_pylist(zfsace_permset_t perms) { @@ -198,14 +172,6 @@ permset_to_pylist(zfsace_permset_t perms) return (out); } -aceflags2name_t _aceflag2name[] = { - { ZFSACE_FILE_INHERIT, "FILE_INHERIT", 'f' }, - { ZFSACE_DIRECTORY_INHERIT, "DIRECTORY_INHERIT", 'd' }, - { ZFSACE_INHERIT_ONLY, "INHERIT_ONLY", 'i' }, - { ZFSACE_NO_PROPAGATE_INHERIT, "NO_PROPAGATE_INHERIT", 'n' }, - { ZFSACE_INHERITED_ACE, "INHERITED", 'I' }, -}; - static PyObject * flagset_to_pylist(zfsace_flagset_t flags) { @@ -216,14 +182,14 @@ flagset_to_pylist(zfsace_flagset_t flags) return (NULL); } - for (i = 0; i < ARRAY_SIZE(_aceflag2name); i++) { + for (i = 0; i < ARRAY_SIZE(aceflag2name); i++) { PyObject *val = NULL; - if ((flags & _aceflag2name[i].flag) == 0) { + if ((flags & aceflag2name[i].flag) == 0) { continue; } - val = Py_BuildValue("s", _aceflag2name[i].name); + val = Py_BuildValue("s", aceflag2name[i].name); if (val == NULL) { Py_DECREF(out); return (NULL); @@ -240,17 +206,6 @@ flagset_to_pylist(zfsace_flagset_t flags) return (out); } -aceswho2name_t acewho2name[] = { - { ZFSACL_UNDEFINED_TAG, "UNDEFINED" }, - { ZFSACL_USER_OBJ, "USER_OBJ" }, - { ZFSACL_GROUP_OBJ, "GROUP_OBJ" }, - { ZFSACL_EVERYONE, "EVERYONE" }, - { ZFSACL_USER, "USER" }, - { ZFSACL_GROUP, "GROUP" }, - { ZFSACL_OTHER, "OTHER" }, - { ZFSACL_MASK, "MASK" }, -}; - static PyObject * whotype_to_pystring(zfsace_who_t whotype) { @@ -824,30 +779,30 @@ PyDoc_STRVAR(py_ace_entry_type__doc__, static PyGetSetDef ace_object_getsetters[] = { { - .name = discard_const_p(char, "idx"), + .name = "idx", .get = (getter)ace_get_idx, .doc = py_ace_idx__doc__, }, { - .name = discard_const_p(char, "permset"), + .name = "permset", .get = (getter)ace_get_permset, .set = (setter)ace_set_permset, .doc = py_ace_permset__doc__, }, { - .name = discard_const_p(char, "flagset"), + .name = "flagset", .get = (getter)ace_get_flagset, .set = (setter)ace_set_flagset, .doc = py_ace_flagset__doc__, }, { - .name = discard_const_p(char, "who"), + .name = "who", .get = (getter)ace_get_who, .set = (setter)ace_set_who, .doc = py_ace_who__doc__, }, { - .name = discard_const_p(char, "entry_type"), + .name = "entry_type", .get = (getter)ace_get_entry_type, .set = (setter)ace_set_entry_type, .doc = py_ace_entry_type__doc__, @@ -1348,6 +1303,12 @@ static PyMethodDef acl_object_methods[] = { .ml_flags = METH_VARARGS, .ml_doc = py_acl_delete_entry__doc__ }, + { + .ml_name = "calculate_inherited_acl", + .ml_meth = (PyCFunction)py_acl_inherit, + .ml_flags = METH_VARARGS|METH_KEYWORDS, + .ml_doc = "calculate an inherited ACL" + }, { NULL, NULL, 0, NULL } }; @@ -1377,24 +1338,24 @@ PyDoc_STRVAR(py_acl_ace_count__doc__, static PyGetSetDef acl_object_getsetters[] = { { - .name = discard_const_p(char, "verbose_output"), + .name = "verbose_output", .get = (getter)acl_get_verbose, .set = (setter)acl_set_verbose, .doc = py_acl_verbose__doc__, }, { - .name = discard_const_p(char, "acl_flags"), + .name = "acl_flags", .get = (getter)acl_get_flags, .set = (setter)acl_set_flags, .doc = py_acl_flags__doc__, }, { - .name = discard_const_p(char, "brand"), + .name = "brand", .get = (getter)acl_get_brand, .doc = py_acl_brand__doc__, }, { - .name = discard_const_p(char, "ace_count"), + .name = "ace_count", .get = (getter)acl_get_acecnt, .doc = py_acl_ace_count__doc__, }, @@ -1414,6 +1375,38 @@ static PyTypeObject PyZfsACL = { .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_ITER, }; +static PyObject * +py_acl_inherit(PyObject *obj, PyObject *args, PyObject *kwargs) +{ + py_acl *self = (py_acl *)obj, *out = NULL; + boolean_t ok, isdir = B_TRUE; + zfsacl_t parent, result; + + char *kwnames [] = { "is_dir", NULL }; + + ok = PyArg_ParseTupleAndKeywords(args, kwargs, "|bO", kwnames, + &isdir); + + if (!ok) { + return (NULL); + } + + parent = self->theacl; + + result = zfsacl_calculate_inherited_acl(parent, NULL, isdir); + if (result == NULL) { + return (NULL); + } + + out = (py_acl *)PyObject_CallFunction((PyObject *)&PyZfsACL, NULL); + if (out == NULL) { + return (NULL); + } + + out->theacl = result; + return ((PyObject *)out); +} + static PyMethodDef acl_module_methods[] = { { .ml_name = NULL } }; diff --git a/lib/libzfsacl/setup.py.in b/lib/libzfsacl/setup.py.in index fbad9b4edf86..80a055f23841 100644 --- a/lib/libzfsacl/setup.py.in +++ b/lib/libzfsacl/setup.py.in @@ -6,10 +6,11 @@ srcdir = '@abs_top_srcdir@/lib/libzfsacl' topsrcdir = '@abs_top_srcdir@' incdir = [topsrcdir, topsrcdir + '/include', topsrcdir + '/lib/libspl/include'] +src = ['zfsacl/libzfsacl_impl_common.c', 'libpyzfsacl.c'] if sys.platform.startswith('linux'): - src = ['zfsacl/libzfsacl_impl_linux.c', 'libpyzfsacl.c'] + src.append('zfsacl/libzfsacl_impl_linux.c') else: - src = ['zfsacl/libzfsacl_impl_freebsd.c', 'libpyzfsacl.c'] + src.append('zfsacl/libzfsacl_impl_freebsd.c') libzfsacl_mod = Extension('libzfsacl', include_dirs=incdir, sources=src) setup( diff --git a/lib/libzfsacl/zfsacl/Makefile.am b/lib/libzfsacl/zfsacl/Makefile.am index 0acf91e09636..5e85ba203b33 100644 --- a/lib/libzfsacl/zfsacl/Makefile.am +++ b/lib/libzfsacl/zfsacl/Makefile.am @@ -7,11 +7,13 @@ libzfsacl_la_CPPFLAGS = $(AM_CPPFLAGS) if BUILD_LINUX dist_libzfsacl_la_SOURCES = \ + %D%/libzfsacl_impl_common.c \ %D%/libzfsacl_impl_linux.c endif if BUILD_FREEBSD dist_libzfsacl_la_SOURCES = \ + %D%/libzfsacl_impl_common.c \ %D%/libzfsacl_impl_freebsd.c endif diff --git a/lib/libzfsacl/zfsacl/libzfsacl_impl_common.c b/lib/libzfsacl/zfsacl/libzfsacl_impl_common.c new file mode 100644 index 000000000000..c3ab80d4e5f7 --- /dev/null +++ b/lib/libzfsacl/zfsacl/libzfsacl_impl_common.c @@ -0,0 +1,224 @@ +#include + +#define INHERITANCE_FLAGS ZFSACE_FILE_INHERIT | \ + ZFSACE_DIRECTORY_INHERIT | \ + ZFSACE_NO_PROPAGATE_INHERIT + +static boolean_t +copy_ace(zfsacl_entry_t target, zfsacl_entry_t source, + zfsace_flagset_t new_flags) +{ + zfsace_permset_t aeperms; + zfsace_who_t aewho; + zfsace_id_t aeid; + zfsace_entry_type_t aetp; + + if (!zfsace_get_permset(source, &aeperms)) { + return (B_FALSE); + } + + if (!zfsace_get_who(source, &aewho, &aeid)) { + return (B_FALSE); + } + + if (!zfsace_get_entry_type(source, &aetp)) { + return (B_FALSE); + } + + if (!zfsace_set_permset(target, aeperms)) { + return (B_FALSE); + } + + if (!zfsace_set_who(target, aewho, aeid)) { + return (B_FALSE); + } + + if (!zfsace_set_entry_type(target, aetp)) { + return (B_FALSE); + } + + if (!zfsace_set_flagset(target, new_flags)) { + return (B_FALSE); + } + + return (B_TRUE); +} + +static boolean_t +add_non_inherited_entries(zfsacl_t target, zfsacl_t source) +{ + uint i, cnt; + + if (!zfsacl_get_acecnt(source, &cnt)) { + return (B_FALSE); + } + + for (i = 0; i < cnt; i++) { + zfsacl_entry_t ae = NULL; + zfsacl_entry_t new = NULL; + zfsace_flagset_t flags = 0; + + if (!zfsacl_get_aclentry(source, i, &ae)) { + return (B_FALSE); + } + + if (!zfsace_get_flagset(ae, &flags)) { + return (B_FALSE); + } + + if (flags & ZFSACE_INHERITED_ACE) { + continue; + } + + if (!zfsacl_create_aclentry(target, ZFSACL_APPEND_ENTRY, + &new)) { + return (B_FALSE); + } + + if (!copy_ace(new, ae, flags)) { + return (B_FALSE); + } + } + + return (B_TRUE); +} + +static boolean_t +add_inherited_ace(zfsacl_t target, zfsacl_entry_t ae, + zfsace_flagset_t flags, boolean_t isdir) +{ + zfsacl_entry_t new = NULL; + + if (!zfsacl_create_aclentry(target, ZFSACL_APPEND_ENTRY, + &new)) { + return (B_FALSE); + } + + if (isdir) { + if (flags & ZFSACE_INHERIT_ONLY) { + flags &= ~ZFSACE_INHERIT_ONLY; + } else if (flags & ZFSACE_NO_PROPAGATE_INHERIT) { + flags &= ~INHERITANCE_FLAGS; + } + } else { + flags &= ~(ZFSACE_INHERIT_ONLY | INHERITANCE_FLAGS); + } + + flags |= ZFSACE_INHERITED_ACE; + + return copy_ace(new, ae, flags); +} + +static boolean_t +add_inherited_entries(zfsacl_t target, zfsacl_t source, boolean_t isdir) +{ + uint i, cnt; + + if (!zfsacl_get_acecnt(source, &cnt)) { + return (B_FALSE); + } + + for (i = 0; i < cnt; i++) { + zfsacl_entry_t ae = NULL; + zfsace_flagset_t flags = 0; + + if (!zfsacl_get_aclentry(source, i, &ae)) { + return (B_FALSE); + } + + if (!zfsace_get_flagset(ae, &flags)) { + return (B_FALSE); + } + + if ((flags & (ZFSACE_FILE_INHERIT | + ZFSACE_DIRECTORY_INHERIT)) == 0) { + // Not inheritable, skip + continue; + } + + if (((flags & ZFSACE_DIRECTORY_INHERIT) == 0) && + isdir) { + /* + * Inheritable only on files and this ACL is for + * a directory. + */ + continue; + } + + if (((flags & ZFSACE_FILE_INHERIT) == 0) && !isdir) { + /* + * Inheritable only on directories and this ACL + * is for a file. + */ + continue; + } + + if (!add_inherited_ace(target, ae, flags, isdir)) { + return (B_FALSE); + } + } + + return (B_TRUE); +} + +/* + * Permissions auto-inheritance is only a NFSv4 ACL feature + */ +static boolean_t acl_may_inherit(zfsacl_t parent, zfsacl_t target) +{ + zfsacl_brand_t brand; + + if (parent == NULL) { + errno = EINVAL; + return (B_FALSE); + } + + if (!zfsacl_get_brand(parent, &brand)) { + return (B_FALSE); + } + + if (brand != ZFSACL_BRAND_NFSV4) { + errno = EOPNOTSUPP; + return (B_FALSE); + } + + if (target) { + if (!zfsacl_get_brand(target, &brand)) { + return (B_FALSE); + } + + + if (brand != ZFSACL_BRAND_NFSV4) { + errno = EOPNOTSUPP; + return (B_FALSE); + } + } + + return (B_TRUE); +} + +zfsacl_t zfsacl_calculate_inherited_acl(zfsacl_t parent, + zfsacl_t target, boolean_t is_dir) +{ + zfsacl_t out = NULL; + + if (!acl_may_inherit(parent, target)) { + return NULL; + } + + out = zfsacl_init(ZFSACL_MAX_ENTRIES, ZFSACL_BRAND_NFSV4); + + if (target) { + if (!add_non_inherited_entries(out, target)) { + zfsacl_free(&out); + return NULL; + } + } + + if (!add_inherited_entries(out, parent, is_dir)) { + zfsacl_free(&out); + return NULL; + } + + return out; +} diff --git a/lib/libzfsacl/zfsacl/libzfsacl_impl_linux.c b/lib/libzfsacl/zfsacl/libzfsacl_impl_linux.c index abebf7b64c3e..7e5db6d2c2e5 100644 --- a/lib/libzfsacl/zfsacl/libzfsacl_impl_linux.c +++ b/lib/libzfsacl/zfsacl/libzfsacl_impl_linux.c @@ -30,8 +30,8 @@ #include -#define ACL4_MAX_ENTRIES 64 -#define ACL4_XATTR "system.nfs4_acl_xdr" +#define ACL4_MAX_ENTRIES ZFSACL_MAX_ENTRIES +#define ACL4_XATTR "system.nfs4_acl_xdr" /* Non-ACL metadata */ #define ACL_GET_SZ(aclp) ((size_t)*(aclp)) @@ -48,6 +48,7 @@ (zfsacl_entry_t)((char *)aclp + ACL4SZ_FROM_ACECNT(idx)) #define ACLBUF_TO_ACES(aclp) ( +#define zfsace4 zfsacl_entry #define ACL4BUF_TO_ACES(aclp) ((struct zfsace4 *)(aclp + 2)) static boolean_t @@ -745,25 +746,6 @@ zfsacl_is_trivial(zfsacl_t _acl, boolean_t *trivialp) #define MAX_ENTRY_LENGTH 512 -aceperms2name_t _aceperm2name[] = { - { ZFSACE_READ_DATA, "READ_DATA", 'r' }, - { ZFSACE_LIST_DIRECTORY, "LIST_DIRECTORY", '\0' }, - { ZFSACE_WRITE_DATA, "WRITE_DATA", 'w' }, - { ZFSACE_ADD_FILE, "ADD_FILE", '\0' }, - { ZFSACE_APPEND_DATA, "APPEND_DATA", 'p' }, - { ZFSACE_DELETE, "DELETE", 'd' }, - { ZFSACE_DELETE_CHILD, "DELETE_CHILD", 'D' }, - { ZFSACE_ADD_SUBDIRECTORY, "ADD_SUBDIRECTORY", '\0' }, - { ZFSACE_READ_ATTRIBUTES, "READ_ATTRIBUTES", 'a' }, - { ZFSACE_WRITE_ATTRIBUTES, "WRITE_ATTRIBUTES", 'A' }, - { ZFSACE_READ_NAMED_ATTRS, "READ_NAMED_ATTRS", 'R' }, - { ZFSACE_WRITE_NAMED_ATTRS, "WRITE_NAMED_ATTRS", 'W' }, - { ZFSACE_READ_ACL, "READ_ACL", 'c' }, - { ZFSACE_WRITE_ACL, "WRITE_ACL", 'C' }, - { ZFSACE_WRITE_OWNER, "WRITE_OWNER", 'o' }, - { ZFSACE_SYNCHRONIZE, "SYNCHRONIZE", 's' }, -}; - static boolean_t format_perms(char *str, const zfsacl_entry_t entry, size_t *off) { @@ -774,14 +756,14 @@ format_perms(char *str, const zfsacl_entry_t entry, size_t *off) return (B_FALSE); } - for (i = 0; i < ARRAY_SIZE(_aceperm2name); i++) { + for (i = 0; i < ARRAY_SIZE(aceperm2name); i++) { char to_set; - if (_aceperm2name[i].letter == '\0') { + if (aceperm2name[i].letter == '\0') { continue; } - if (p & _aceperm2name[i].perm) { - to_set = _aceperm2name[i].letter; + if (p & aceperm2name[i].perm) { + to_set = aceperm2name[i].letter; } else { to_set = '-'; } @@ -793,14 +775,6 @@ format_perms(char *str, const zfsacl_entry_t entry, size_t *off) return (B_TRUE); } -aceflags2name_t aceflag2name[] = { - { ZFSACE_FILE_INHERIT, "FILE_INHERIT", 'f' }, - { ZFSACE_DIRECTORY_INHERIT, "DIRECTORY_INHERIT", 'd' }, - { ZFSACE_INHERIT_ONLY, "INHERIT_ONLY", 'i' }, - { ZFSACE_NO_PROPAGATE_INHERIT, "NO_PROPAGATE_INHERIT", 'n' }, - { ZFSACE_INHERITED_ACE, "INHERITED", 'I' }, -}; - static boolean_t format_flags(char *str, const zfsacl_entry_t entry, size_t *off) { @@ -924,8 +898,6 @@ static size_t format_entry(char *str, size_t sz, const zfsacl_entry_t _entry) { size_t off = 0; - size_t slen = 0; - size_t tocopy = 0; char buf[MAX_ENTRY_LENGTH + 1] = { 0 }; if (!format_who(buf, sizeof (buf), _entry, &off)) @@ -950,14 +922,7 @@ format_entry(char *str, size_t sz, const zfsacl_entry_t _entry) return (-1); buf[off] = '\n'; - slen = strlen(buf); - if (slen >= sz) - tocopy = sz - 1; - else - tocopy = slen; - memcpy(str, buf, tocopy); - str[tocopy] = '\0'; - return (tocopy); + return strlcpy(str, buf, sz); } char *