From patchwork Sat Sep 5 10:27:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Gruenbacher X-Patchwork-Id: 7128481 Return-Path: X-Original-To: patchwork-cifs-client@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 322C3BEEC1 for ; Sat, 5 Sep 2015 10:37:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 590DF2076E for ; Sat, 5 Sep 2015 10:37:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 80BF5207AA for ; Sat, 5 Sep 2015 10:37:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753002AbbIEK3c (ORCPT ); Sat, 5 Sep 2015 06:29:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58437 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752059AbbIEK23 (ORCPT ); Sat, 5 Sep 2015 06:28:29 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 83B7E341AC6; Sat, 5 Sep 2015 10:28:29 +0000 (UTC) Received: from nuc.home.com (vpn1-7-178.ams2.redhat.com [10.36.7.178]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t85ARbEK023920; Sat, 5 Sep 2015 06:28:28 -0400 From: Andreas Gruenbacher To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-api@vger.kernel.org, linux-cifs@vger.kernel.org, linux-security-module@vger.kernel.org Subject: [RFC v7 27/41] richacl: Create richacl from mode values Date: Sat, 5 Sep 2015 12:27:22 +0200 Message-Id: <1441448856-13478-28-git-send-email-agruenba@redhat.com> In-Reply-To: <1441448856-13478-1-git-send-email-agruenba@redhat.com> References: <1441448856-13478-1-git-send-email-agruenba@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SUSPICIOUS_RECIPS, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A file can have "no acl" in the sense that only the file mode permission bits determine access. In that case, the getxattr system call fails with errno == ENODATA (No such attribute). Over the NFSv4 protocol, a file always has an acl, and we convert the file mode permission bits into an equivalent acl with richacl_from_mode. Such "trivial" acls can be converted back to a file mode with richacl_equiv_mode. Signed-off-by: Andreas Gruenbacher Reviewed-by: J. Bruce Fields --- fs/richacl_compat.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/richacl.h | 1 + 2 files changed, 89 insertions(+) diff --git a/fs/richacl_compat.c b/fs/richacl_compat.c index 9681efe..632409f 100644 --- a/fs/richacl_compat.c +++ b/fs/richacl_compat.c @@ -840,3 +840,91 @@ richacl_apply_masks(struct richacl **acl, kuid_t owner) return 0; } EXPORT_SYMBOL_GPL(richacl_apply_masks); + +/** + * richacl_from_mode - create an acl which corresponds to @mode + * + * The resulting acl doesn't have the RICHACL_MASKED flag set. + * + * @mode: file mode including the file type + */ +struct richacl * +richacl_from_mode(mode_t mode) +{ + unsigned int owner_mask = richacl_mode_to_mask(mode >> 6); + unsigned int group_mask = richacl_mode_to_mask(mode >> 3); + unsigned int other_mask = richacl_mode_to_mask(mode); + unsigned int denied; + unsigned int entries = 0; + struct richacl *acl; + struct richace *ace; + + /* RICHACE_DELETE_CHILD is meaningless for non-directories. */ + if (!S_ISDIR(mode)) { + owner_mask &= ~RICHACE_DELETE_CHILD; + group_mask &= ~RICHACE_DELETE_CHILD; + other_mask &= ~RICHACE_DELETE_CHILD; + } + + denied = ~owner_mask & (group_mask | other_mask); + if (denied) + entries++; /* owner@ deny entry needed */ + if (owner_mask & ~(group_mask & other_mask)) + entries++; /* owner@ allow entry needed */ + denied = ~group_mask & other_mask; + if (denied) + entries++; /* group@ deny entry needed */ + if (group_mask & ~other_mask) + entries++; /* group@ allow entry needed */ + if (other_mask) + entries++; /* everyone@ allow entry needed */ + + acl = richacl_alloc(entries, GFP_KERNEL); + if (!acl) + return NULL; + acl->a_owner_mask = owner_mask; + acl->a_group_mask = group_mask; + acl->a_other_mask = other_mask; + ace = acl->a_entries; + + denied = ~owner_mask & (group_mask | other_mask); + if (denied) { + ace->e_type = RICHACE_ACCESS_DENIED_ACE_TYPE; + ace->e_flags = RICHACE_SPECIAL_WHO; + ace->e_mask = denied; + ace->e_id.special = RICHACE_OWNER_SPECIAL_ID; + ace++; + } + if (owner_mask & ~(group_mask & other_mask)) { + ace->e_type = RICHACE_ACCESS_ALLOWED_ACE_TYPE; + ace->e_flags = RICHACE_SPECIAL_WHO; + ace->e_mask = owner_mask; + ace->e_id.special = RICHACE_OWNER_SPECIAL_ID; + ace++; + } + denied = ~group_mask & other_mask; + if (denied) { + ace->e_type = RICHACE_ACCESS_DENIED_ACE_TYPE; + ace->e_flags = RICHACE_SPECIAL_WHO; + ace->e_mask = denied; + ace->e_id.special = RICHACE_GROUP_SPECIAL_ID; + ace++; + } + if (group_mask & ~other_mask) { + ace->e_type = RICHACE_ACCESS_ALLOWED_ACE_TYPE; + ace->e_flags = RICHACE_SPECIAL_WHO; + ace->e_mask = group_mask; + ace->e_id.special = RICHACE_GROUP_SPECIAL_ID; + ace++; + } + if (other_mask) { + ace->e_type = RICHACE_ACCESS_ALLOWED_ACE_TYPE; + ace->e_flags = RICHACE_SPECIAL_WHO; + ace->e_mask = other_mask; + ace->e_id.special = RICHACE_EVERYONE_SPECIAL_ID; + ace++; + } + + return acl; +} +EXPORT_SYMBOL_GPL(richacl_from_mode); diff --git a/include/linux/richacl.h b/include/linux/richacl.h index a945f3c..f48c04e 100644 --- a/include/linux/richacl.h +++ b/include/linux/richacl.h @@ -334,5 +334,6 @@ extern struct richacl *richacl_create(struct inode *, struct inode *); /* richacl_compat.c */ extern int richacl_apply_masks(struct richacl **, kuid_t); +extern struct richacl *richacl_from_mode(mode_t); #endif /* __RICHACL_H */