Print this page
3691 setgroups() needs a sorted GID list for more than 16 groups
Reviewed-By: Marcel Telka <marcel@telka.sk>
Reviewed-By: Richard Lowe <richlowe@richlowe.net>


   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*



  22  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
  23  */
  24 
  25 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  26 /*        All Rights Reserved   */
  27 
  28 /*
  29  * University Copyright- Copyright (c) 1982, 1986, 1988
  30  * The Regents of the University of California
  31  * All Rights Reserved
  32  *
  33  * University Acknowledgment- Portions of this document are derived from
  34  * software developed by the University of California, Berkeley, and its
  35  * contributors.
  36  */
  37 
  38 #include <sys/types.h>
  39 #include <sys/sysmacros.h>
  40 #include <sys/param.h>
  41 #include <sys/systm.h>


1423                 crklpd_rele(cr->cr_klpd);
1424         cr->cr_klpd = crklpd;
1425 }
1426 
1427 credgrp_t *
1428 crgrpcopyin(int n, gid_t *gidset)
1429 {
1430         credgrp_t *mem;
1431         size_t sz = CREDGRPSZ(n);
1432 
1433         ASSERT(n > 0);
1434 
1435         mem = kmem_alloc(sz, KM_SLEEP);
1436 
1437         if (copyin(gidset, mem->crg_groups, sizeof (gid_t) * n)) {
1438                 kmem_free(mem, sz);
1439                 return (NULL);
1440         }
1441         mem->crg_ref = 1;
1442         mem->crg_ngroups = n;

1443         return (mem);
1444 }
1445 
1446 const gid_t *
1447 crgetggroups(const credgrp_t *grps)
1448 {
1449         return (grps->crg_groups);
1450 }
1451 
1452 void
1453 crsetcredgrp(cred_t *cr, credgrp_t *grps)
1454 {
1455         ASSERT(cr->cr_ref <= 2);
1456 
1457         if (cr->cr_grps != NULL)
1458                 crgrprele(cr->cr_grps);
1459 
1460         cr->cr_grps = grps;
1461 }
1462 


   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 2013, Ira Cooper.  All rights reserved.
  23  */
  24 /*
  25  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
  26  */
  27 
  28 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  29 /*        All Rights Reserved   */
  30 
  31 /*
  32  * University Copyright- Copyright (c) 1982, 1986, 1988
  33  * The Regents of the University of California
  34  * All Rights Reserved
  35  *
  36  * University Acknowledgment- Portions of this document are derived from
  37  * software developed by the University of California, Berkeley, and its
  38  * contributors.
  39  */
  40 
  41 #include <sys/types.h>
  42 #include <sys/sysmacros.h>
  43 #include <sys/param.h>
  44 #include <sys/systm.h>


1426                 crklpd_rele(cr->cr_klpd);
1427         cr->cr_klpd = crklpd;
1428 }
1429 
1430 credgrp_t *
1431 crgrpcopyin(int n, gid_t *gidset)
1432 {
1433         credgrp_t *mem;
1434         size_t sz = CREDGRPSZ(n);
1435 
1436         ASSERT(n > 0);
1437 
1438         mem = kmem_alloc(sz, KM_SLEEP);
1439 
1440         if (copyin(gidset, mem->crg_groups, sizeof (gid_t) * n)) {
1441                 kmem_free(mem, sz);
1442                 return (NULL);
1443         }
1444         mem->crg_ref = 1;
1445         mem->crg_ngroups = n;
1446         qsort(mem->crg_groups, n, sizeof (gid_t), gidcmp);
1447         return (mem);
1448 }
1449 
1450 const gid_t *
1451 crgetggroups(const credgrp_t *grps)
1452 {
1453         return (grps->crg_groups);
1454 }
1455 
1456 void
1457 crsetcredgrp(cred_t *cr, credgrp_t *grps)
1458 {
1459         ASSERT(cr->cr_ref <= 2);
1460 
1461         if (cr->cr_grps != NULL)
1462                 crgrprele(cr->cr_grps);
1463 
1464         cr->cr_grps = grps;
1465 }
1466