From 42f7080f59c973446e9a61b0971f2614851c78d6 Mon Sep 17 00:00:00 2001 From: Martin Matuska Date: Thu, 19 Jan 2017 00:40:36 +0100 Subject: [PATCH] Replace archive_acl_count() with archive_acl_types() where possible Report all types of ACLs in archive_entry_strmode() Simplify archive_write_disk_set_acls() --- libarchive/archive_acl.c | 9 +++++ libarchive/archive_acl_private.h | 1 + libarchive/archive_entry.c | 2 +- libarchive/archive_entry_strmode.c | 2 +- libarchive/archive_write_disk_acl.c | 53 ++++++++++++++--------------- 5 files changed, 38 insertions(+), 29 deletions(-) diff --git a/libarchive/archive_acl.c b/libarchive/archive_acl.c index a1edc6d6d..1e9ddbb24 100644 --- a/libarchive/archive_acl.c +++ b/libarchive/archive_acl.c @@ -348,6 +348,15 @@ archive_acl_count(struct archive_acl *acl, int want_type) return (count); } +/* + * Return a bitmask of stored ACL types in an ACL list + */ +int +archive_acl_types(struct archive_acl *acl) +{ + return (acl->acl_types); +} + /* * Prepare for reading entries from the ACL data. Returns a count * of entries matching "want_type", or zero if there are no diff --git a/libarchive/archive_acl_private.h b/libarchive/archive_acl_private.h index 0aac6fff2..ef0b0234c 100644 --- a/libarchive/archive_acl_private.h +++ b/libarchive/archive_acl_private.h @@ -56,6 +56,7 @@ struct archive_acl { void archive_acl_clear(struct archive_acl *); void archive_acl_copy(struct archive_acl *, struct archive_acl *); int archive_acl_count(struct archive_acl *, int); +int archive_acl_types(struct archive_acl *); int archive_acl_reset(struct archive_acl *, int); int archive_acl_next(struct archive *, struct archive_acl *, int, int *, int *, int *, int *, const char **); diff --git a/libarchive/archive_entry.c b/libarchive/archive_entry.c index 5af030729..d4f061b5b 100644 --- a/libarchive/archive_entry.c +++ b/libarchive/archive_entry.c @@ -1447,7 +1447,7 @@ archive_entry_acl_add_entry_w(struct archive_entry *entry, int archive_entry_acl_types(struct archive_entry *entry) { - return ((&entry->acl)->acl_types); + return (archive_acl_types(&entry->acl)); } /* diff --git a/libarchive/archive_entry_strmode.c b/libarchive/archive_entry_strmode.c index 16cb3f7bb..af2517a32 100644 --- a/libarchive/archive_entry_strmode.c +++ b/libarchive/archive_entry_strmode.c @@ -80,7 +80,7 @@ archive_entry_strmode(struct archive_entry *entry) if (mode & 0001) bp[9] = 't'; else bp[9] = 'T'; } - if (archive_entry_acl_count(entry, ARCHIVE_ENTRY_ACL_TYPE_ACCESS)) + if (archive_entry_acl_types(entry) != 0) bp[10] = '+'; return (bp); diff --git a/libarchive/archive_write_disk_acl.c b/libarchive/archive_write_disk_acl.c index fa44da157..a20852665 100644 --- a/libarchive/archive_write_disk_acl.c +++ b/libarchive/archive_write_disk_acl.c @@ -62,48 +62,47 @@ static int set_acl(struct archive *, int fd, const char *, struct archive_acl *, acl_type_t, int archive_entry_acl_type, const char *tn); -/* - * XXX TODO: What about ACL types other than ACCESS and DEFAULT? - */ int archive_write_disk_set_acls(struct archive *a, int fd, const char *name, struct archive_acl *abstract_acl) { - int ret; + int ret = ARCHIVE_OK; +#if HAVE_SUN_ACL + const int acltype_nfs4 = ACE_T; +#elif HAVE_ACL_TYPE_NFS4 + const int acltype_nfs4 = ACL_TYPE_NFS4; +#endif - if (archive_acl_count(abstract_acl, - ARCHIVE_ENTRY_ACL_TYPE_POSIX1E) > 0) { + if ((archive_acl_types(abstract_acl) + & ARCHIVE_ENTRY_ACL_TYPE_POSIX1E) != 0) { #if HAVE_SUN_ACL /* Solaris writes POSIX.1e access and default ACLs together */ ret = set_acl(a, fd, name, abstract_acl, ACLENT_T, ARCHIVE_ENTRY_ACL_TYPE_POSIX1E, "posix1e"); #else - ret = set_acl(a, fd, name, abstract_acl, ACL_TYPE_ACCESS, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, "access"); - if (ret != ARCHIVE_OK) - return (ret); - ret = set_acl(a, fd, name, abstract_acl, ACL_TYPE_DEFAULT, - ARCHIVE_ENTRY_ACL_TYPE_DEFAULT, "default"); + if ((archive_acl_types(abstract_acl) + & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0) { + ret = set_acl(a, fd, name, abstract_acl, + ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_TYPE_ACCESS, + "access"); + if (ret != ARCHIVE_OK) + return (ret); + } + if ((archive_acl_types(abstract_acl) + & ARCHIVE_ENTRY_ACL_TYPE_DEFAULT) != 0) + ret = set_acl(a, fd, name, abstract_acl, + ACL_TYPE_DEFAULT, ARCHIVE_ENTRY_ACL_TYPE_DEFAULT, + "default"); #endif - return (ret); } #if HAVE_ACL_TYPE_NFS4 || HAVE_SUN_ACL - else if (archive_acl_count(abstract_acl, - ARCHIVE_ENTRY_ACL_TYPE_NFS4) > 0) { -#if HAVE_SUN_ACL - ret = set_acl(a, fd, name, abstract_acl, ACE_T, + else if ((archive_acl_types(abstract_acl) & + ARCHIVE_ENTRY_ACL_TYPE_NFS4) != 0) { + ret = set_acl(a, fd, name, abstract_acl, acltype_nfs4, ARCHIVE_ENTRY_ACL_TYPE_NFS4, "nfs4"); -#else /* !HAVE_SUN_ACL */ - ret = set_acl(a, fd, name, abstract_acl, ACL_TYPE_NFS4, - ARCHIVE_ENTRY_ACL_TYPE_NFS4, "nfs4"); -#endif /* !HAVE_SUN_ACL */ - return (ret); - } -#endif /* HAVE_ACL_TYPE_NFS4 && HAVE_SUN_ACL */ - else { - /* No ACLs found */ - return ARCHIVE_OK; } +#endif /* HAVE_ACL_TYPE_NFS4 || HAVE_SUN_ACL */ + return (ret); } /* -- 2.47.2