From owner-svn-src-head@freebsd.org Fri Oct 26 21:17:07 2018 Return-Path: Delivered-To: svn-src-head@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 97C011088BA8; Fri, 26 Oct 2018 21:17:07 +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 3CC546A67D; Fri, 26 Oct 2018 21:17:07 +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 193102655D; Fri, 26 Oct 2018 21:17:07 +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 w9QLH6ZX096705; Fri, 26 Oct 2018 21:17:06 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w9QLH6gU096703; Fri, 26 Oct 2018 21:17:06 GMT (envelope-from markj@FreeBSD.org) Message-Id: <201810262117.w9QLH6gU096703@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Fri, 26 Oct 2018 21:17:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r339793 - head/bin/setfacl X-SVN-Group: head X-SVN-Commit-Author: markj X-SVN-Commit-Paths: head/bin/setfacl X-SVN-Commit-Revision: 339793 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Oct 2018 21:17:07 -0000 Author: markj Date: Fri Oct 26 21:17:06 2018 New Revision: 339793 URL: https://svnweb.freebsd.org/changeset/base/339793 Log: Don't set NFSv4 ACL inheritance flags on non-directories. They only make sense in the context of directory ACLs, and attempting to set them on regular files results in errors, causing a recursive setfacl invocation to abort. This is derived from patches by Shawn Webb and Mitchell Horne . PR: 155163 MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D15061 Modified: head/bin/setfacl/setfacl.1 head/bin/setfacl/setfacl.c Modified: head/bin/setfacl/setfacl.1 ============================================================================== --- head/bin/setfacl/setfacl.1 Fri Oct 26 21:15:36 2018 (r339792) +++ head/bin/setfacl/setfacl.1 Fri Oct 26 21:17:06 2018 (r339793) @@ -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: head/bin/setfacl/setfacl.c ============================================================================== --- head/bin/setfacl/setfacl.c Fri Oct 26 21:15:36 2018 (r339792) +++ head/bin/setfacl/setfacl.c Fri Oct 26 21:17:06 2018 (r339793) @@ -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; } ret = 0;