From owner-svn-src-all@freebsd.org Sat Nov 10 20:35:01 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1CBAB1109B05; Sat, 10 Nov 2018 20:35:01 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 9CD997AECF; Sat, 10 Nov 2018 20:35:00 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 7976727EB1; Sat, 10 Nov 2018 20:35:00 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id wAAKZ0R8058684; Sat, 10 Nov 2018 20:35:00 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id wAAKZ0l6058682; Sat, 10 Nov 2018 20:35:00 GMT (envelope-from markj@FreeBSD.org) Message-Id: <201811102035.wAAKZ0l6058682@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Sat, 10 Nov 2018 20:35:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r340332 - stable/12/bin/setfacl X-SVN-Group: stable-12 X-SVN-Commit-Author: markj X-SVN-Commit-Paths: stable/12/bin/setfacl X-SVN-Commit-Revision: 340332 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 9CD997AECF X-Spamd-Result: default: False [-106.88 / 200.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; ALLOW_DOMAIN_WHITELIST(-100.00)[FreeBSD.org]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; HAS_XAW(0.00)[]; R_SPF_SOFTFAIL(0.00)[~all]; DMARC_NA(0.00)[FreeBSD.org]; RCVD_COUNT_THREE(0.00)[4]; MX_GOOD(-0.01)[cached: mx1.FreeBSD.org]; NEURAL_HAM_SHORT(-1.00)[-1.000,0]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; IP_SCORE(-3.77)[ip: (-9.91), ipnet: 2610:1c1:1::/48(-4.93), asn: 11403(-3.89), country: US(-0.09)] X-Rspamd-Server: mx1.freebsd.org X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 10 Nov 2018 20:35:01 -0000 Author: markj Date: Sat Nov 10 20:34:59 2018 New Revision: 340332 URL: https://svnweb.freebsd.org/changeset/base/340332 Log: MFC r339793: Don't set NFSv4 ACL inheritance flags on non-directories. PR: 155163 Approved by: re (gjb) Modified: stable/12/bin/setfacl/setfacl.1 stable/12/bin/setfacl/setfacl.c Directory Properties: stable/12/ (props changed) Modified: stable/12/bin/setfacl/setfacl.1 ============================================================================== --- stable/12/bin/setfacl/setfacl.1 Sat Nov 10 20:33:08 2018 (r340331) +++ stable/12/bin/setfacl/setfacl.1 Sat Nov 10 20:34:59 2018 (r340332) @@ -26,7 +26,7 @@ .\" .\" $FreeBSD$ .\" -.Dd April 10, 2018 +.Dd October 26, 2018 .Dt SETFACL 1 .Os .Sh NAME @@ -136,6 +136,8 @@ option is specified, no symbolic links are followed. This is the default. .It Fl R Perform the action recursively on any specified directories. +When modifying or adding NFSv4 ACL entries, inheritance flags +are applied only to directories. .It Fl x Ar entries | position If .Ar entries Modified: stable/12/bin/setfacl/setfacl.c ============================================================================== --- stable/12/bin/setfacl/setfacl.c Sat Nov 10 20:33:08 2018 (r340331) +++ stable/12/bin/setfacl/setfacl.c Sat Nov 10 20:34:59 2018 (r340332) @@ -27,9 +27,7 @@ #include __FBSDID("$FreeBSD$"); -#include #include -#include #include #include @@ -73,6 +71,7 @@ static bool need_mask; static acl_type_t acl_type = ACL_TYPE_ACCESS; static int handle_file(FTS *ftsp, FTSENT *file); +static acl_t clear_inheritance_flags(acl_t acl); static char **stdin_files(void); static void usage(void); @@ -124,10 +123,57 @@ stdin_files(void) return (files_list); } +/* + * Remove any inheritance flags from NFSv4 ACLs when running in recursive + * mode. This is to avoid files being assigned identical ACLs to their + * parent directory while also being set to inherit them. + * + * The acl argument is assumed to be valid. + */ +static acl_t +clear_inheritance_flags(acl_t acl) +{ + acl_t nacl; + acl_entry_t acl_entry; + acl_flagset_t acl_flagset; + int acl_brand, entry_id; + + (void)acl_get_brand_np(acl, &acl_brand); + if (acl_brand != ACL_BRAND_NFS4) + return (acl); + + nacl = acl_dup(acl); + if (nacl == NULL) { + warn("acl_dup() failed"); + return (acl); + } + + entry_id = ACL_FIRST_ENTRY; + while (acl_get_entry(nacl, entry_id, &acl_entry) == 1) { + entry_id = ACL_NEXT_ENTRY; + if (acl_get_flagset_np(acl_entry, &acl_flagset) != 0) { + warn("acl_get_flagset_np() failed"); + continue; + } + if (acl_get_flag_np(acl_flagset, ACL_ENTRY_INHERIT_ONLY) == 1) { + if (acl_delete_entry(nacl, acl_entry) != 0) + warn("acl_delete_entry() failed"); + continue; + } + if (acl_delete_flag_np(acl_flagset, + ACL_ENTRY_FILE_INHERIT | + ACL_ENTRY_DIRECTORY_INHERIT | + ACL_ENTRY_NO_PROPAGATE_INHERIT) != 0) + warn("acl_delete_flag_np() failed"); + } + + return (nacl); +} + static int handle_file(FTS *ftsp, FTSENT *file) { - acl_t acl; + acl_t acl, nacl; acl_entry_t unused_entry; int local_error, ret; struct sf_entry *entry; @@ -193,17 +239,20 @@ handle_file(FTS *ftsp, FTSENT *file) /* Cycle through each option. */ TAILQ_FOREACH(entry, &entrylist, next) { - if (local_error) - continue; - - switch(entry->op) { + nacl = entry->acl; + switch (entry->op) { case OP_ADD_ACL: - local_error += add_acl(entry->acl, entry->entry_number, - &acl, file->fts_path); + if (R_flag && file->fts_info != FTS_D && + acl_type == ACL_TYPE_NFS4) + nacl = clear_inheritance_flags(nacl); + local_error += add_acl(nacl, entry->entry_number, &acl, + file->fts_path); break; case OP_MERGE_ACL: - local_error += merge_acl(entry->acl, &acl, - file->fts_path); + if (R_flag && file->fts_info != FTS_D && + acl_type == ACL_TYPE_NFS4) + nacl = clear_inheritance_flags(nacl); + local_error += merge_acl(nacl, &acl, file->fts_path); need_mask = true; break; case OP_REMOVE_EXT: @@ -240,8 +289,7 @@ handle_file(FTS *ftsp, FTSENT *file) need_mask = false; break; case OP_REMOVE_ACL: - local_error += remove_acl(entry->acl, &acl, - file->fts_path); + local_error += remove_acl(nacl, &acl, file->fts_path); need_mask = true; break; case OP_REMOVE_BY_NUMBER: @@ -250,6 +298,13 @@ handle_file(FTS *ftsp, FTSENT *file) need_mask = true; break; } + + if (nacl != entry->acl) { + acl_free(nacl); + nacl = NULL; + } + if (local_error) + break; } /*