X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fobdclass%2Fidmap.c;h=dab099b448b376655f73f1dff4f4322867db0d3b;hb=HEAD;hp=021d0d60e9e67b023decf7d3c241e24db239ff20;hpb=8c3c81fb787ab0a0152ebf497d1b4aef480bb82f;p=fs%2Flustre-release.git diff --git a/lustre/obdclass/idmap.c b/lustre/obdclass/idmap.c index 021d0d6..4bca952 100644 --- a/lustre/obdclass/idmap.c +++ b/lustre/obdclass/idmap.c @@ -1,35 +1,14 @@ -/* - * GPL HEADER START - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 only, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License version 2 for more details (a copy is included - * in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU General Public License - * version 2 along with this program; If not, see - * http://www.gnu.org/licenses/gpl-2.0.html - * - * GPL HEADER END - */ +// SPDX-License-Identifier: GPL-2.0 + /* * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, 2016, Intel Corporation. + * Copyright (c) 2012, 2017, Intel Corporation. */ + /* * This file is part of Lustre, http://www.lustre.org/ - * Lustre is a trademark of Sun Microsystems, Inc. - * - * lustre/obdclass/idmap.c * * Lustre user identity mapping. * @@ -39,9 +18,8 @@ #define DEBUG_SUBSYSTEM S_SEC #include -#ifdef HAVE_UIDGID_HEADER -# include -#endif +#include + #include #include #include @@ -51,8 +29,7 @@ * groups_search() is copied from linux kernel! * A simple bsearch. */ -static int lustre_groups_search(struct group_info *group_info, - gid_t grp) +int lustre_groups_search(struct group_info *group_info, gid_t grp) { int left, right; @@ -75,6 +52,7 @@ static int lustre_groups_search(struct group_info *group_info, } return 0; } +EXPORT_SYMBOL(lustre_groups_search); void lustre_groups_from_list(struct group_info *ginfo, gid_t *glist) { @@ -97,16 +75,37 @@ void lustre_groups_from_list(struct group_info *ginfo, gid_t *glist) } EXPORT_SYMBOL(lustre_groups_from_list); +void lustre_list_from_groups(gid_t *glist, struct group_info *ginfo) +{ +#ifdef HAVE_GROUP_INFO_GID + memcpy(glist, ginfo->gid, ginfo->ngroups * sizeof(__u32)); +#else + int i; + int count = ginfo->ngroups; + + /* fill in gid array from group_info */ + for (i = 0; i < ginfo->nblocks && count > 0; i++) { + int cp_count = min(CFS_NGROUPS_PER_BLOCK, count); + int off = i * CFS_NGROUPS_PER_BLOCK; + int len = cp_count * sizeof(*glist); + + memcpy(glist + off, ginfo->blocks[i], len); + count -= cp_count; + } +#endif +} +EXPORT_SYMBOL(lustre_list_from_groups); + /* groups_sort() is copied from linux kernel! */ /* a simple shell-metzner sort */ void lustre_groups_sort(struct group_info *group_info) { - int base, max, stride; - int gidsetsize = group_info->ngroups; + int base, max, stride; + int gidsetsize = group_info->ngroups; - for (stride = 1; stride < gidsetsize; stride = 3 * stride + 1) - ; /* nothing */ - stride /= 3; + for (stride = 1; stride < gidsetsize; stride = 3 * stride + 1) + ; /* nothing */ + stride /= 3; while (stride) { max = gidsetsize - stride; @@ -153,11 +152,36 @@ int lustre_in_group_p(struct lu_ucred *mu, gid_t grp) if (!group_info) return 0; - atomic_inc(&group_info->usage); + get_group_info(group_info); rc = lustre_groups_search(group_info, grp); - if (atomic_dec_and_test(&group_info->usage)) - groups_free(group_info); + put_group_info(group_info); } return rc; } EXPORT_SYMBOL(lustre_in_group_p); + +/* make sure fsgid is one of primary or supplementary groups + * fetched from identity upcall + */ +int has_proper_groups(struct lu_ucred *ucred) +{ + struct group_info *group_info = NULL; + int rc; + + if (!ucred->uc_identity) + return 1; + + if (ucred->uc_fsgid == ucred->uc_identity->mi_gid) + return 1; + + group_info = ucred->uc_identity->mi_ginfo; + if (!group_info) + return 0; + + get_group_info(group_info); + rc = lustre_groups_search(group_info, ucred->uc_fsgid); + put_group_info(group_info); + + return rc; +} +EXPORT_SYMBOL(has_proper_groups);