* 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
*
#define DEBUG_SUBSYSTEM S_SEC
#include <linux/user_namespace.h>
-#ifdef HAVE_UIDGID_HEADER
-# include <linux/uidgid.h>
-#endif
+#include <linux/uidgid.h>
+
#include <lustre_idmap.h>
#include <upcall_cache.h>
#include <md_object.h>
* 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;
}
return 0;
}
+EXPORT_SYMBOL(lustre_groups_search);
void lustre_groups_from_list(struct group_info *ginfo, gid_t *glist)
{
/* 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;
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);