]> git.proxmox.com Git - mirror_spl-debian.git/blobdiff - module/spl/spl-cred.c
Imported Upstream version 0.6.5.9
[mirror_spl-debian.git] / module / spl / spl-cred.c
index a03f459e04efc25499a4783d3774026a75fb4dd0..1d486c1f0b1b62ceec02632abeba095d32b6cd55 100644 (file)
@@ -62,19 +62,17 @@ cr_groups_search(const struct group_info *group_info, gid_t grp)
        return 0;
 }
 
-/* Hold a reference on the credential and group info */
+/* Hold a reference on the credential */
 void
 crhold(cred_t *cr)
 {
        (void)get_cred((const cred_t *)cr);
-       (void)get_group_info(cr->group_info);
 }
 
-/* Free a reference on the credential and group info */
+/* Free a reference on the credential */
 void
 crfree(cred_t *cr)
 {
-       put_group_info(cr->group_info);
        put_cred((const cred_t *)cr);
 }
 
@@ -85,28 +83,42 @@ crgetngroups(const cred_t *cr)
        struct group_info *gi;
        int rc;
 
-       gi = get_group_info(cr->group_info);
+       gi = cr->group_info;
        rc = gi->ngroups;
-       put_group_info(gi);
-
+#ifndef HAVE_GROUP_INFO_GID
+       /*
+        * For Linux <= 4.8,
+        * crgetgroups will only returns gi->blocks[0], which contains only
+        * the first NGROUPS_PER_BLOCK groups.
+        */
+       if (rc > NGROUPS_PER_BLOCK) {
+               WARN_ON_ONCE(1);
+               rc = NGROUPS_PER_BLOCK;
+       }
+#endif
        return rc;
 }
 
 /*
  * Return an array of supplemental gids.  The returned address is safe
  * to use as long as the caller has taken a reference with crhold().
- * The caller is responsible for releasing the reference with crfree().
+ *
+ * Linux 4.9 API change, group_info changed from 2d array via ->blocks to 1d
+ * array via ->gid.
  */
 gid_t *
 crgetgroups(const cred_t *cr)
 {
        struct group_info *gi;
-       gid_t *gids;
-
-       gi = get_group_info(cr->group_info);
-       gids = KGIDP_TO_SGIDP(gi->blocks[0]);
-       put_group_info(gi);
+       gid_t *gids = NULL;
 
+       gi = cr->group_info;
+#ifdef HAVE_GROUP_INFO_GID
+       gids = KGIDP_TO_SGIDP(gi->gid);
+#else
+       if (gi->nblocks > 0)
+               gids = KGIDP_TO_SGIDP(gi->blocks[0]);
+#endif
        return gids;
 }
 
@@ -117,9 +129,8 @@ groupmember(gid_t gid, const cred_t *cr)
        struct group_info *gi;
        int rc;
 
-       gi = get_group_info(cr->group_info);
+       gi = cr->group_info;
        rc = cr_groups_search(gi, SGID_TO_KGID(gid));
-       put_group_info(gi);
 
        return rc;
 }