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.
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.
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]
22 * Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 #include <sys/param.h>
29 #include <sys/types.h>
30 #include <sys/sysmacros.h>
31 #include <sys/systm.h>
34 #include <sys/errno.h>
36 #include <sys/debug.h>
38 #include <sys/policy.h>
41 setgroups(int gidsetsize
, gid_t
*gidset
)
49 ksidlist_t
*ksl
= NULL
;
51 struct credgrp
*grps
= NULL
;
53 /* Perform the cheapest tests before grabbing p_crlock */
54 if (n
> ngroups_max
|| n
< 0)
55 return (set_errno(EINVAL
));
57 zone
= crgetzone(CRED());
61 grps
= crgrpcopyin(n
, gidset
);
64 return (set_errno(EFAULT
));
66 groups
= crgetggroups(grps
);
68 for (i
= 0; i
< n
; i
++) {
69 if (!VALID_GID(groups
[i
], zone
)) {
71 return (set_errno(EINVAL
));
73 if (groups
[i
] > MAXUID
)
77 ksl
= kcrsid_gidstosids(zone
, n
, (gid_t
*)groups
);
80 return (set_errno(EINVAL
));
87 * Need to pre-allocate the new cred structure before acquiring
90 newcr
= cralloc_ksid();
91 p
= ttoproc(curthread
);
92 mutex_enter(&p
->p_crlock
);
96 mutex_exit(&p
->p_crlock
);
98 if ((error
= secpolicy_allow_setid(cr
, -1, B_FALSE
)) != 0) {
105 return (set_errno(error
));
107 mutex_enter(&p
->p_crlock
);
113 crsetsidlist(newcr
, ksl
);
114 crsetcredgrp(newcr
, grps
);
117 crhold(newcr
); /* hold for the current thread */
118 crfree(cr
); /* free the old one */
119 mutex_exit(&p
->p_crlock
);
122 * Broadcast new cred to process threads (including the current one).
130 getgroups(int gidsetsize
, gid_t
*gidset
)
135 cr
= curthread
->t_cred
;
136 n
= crgetngroups(cr
);
138 if (gidsetsize
!= 0) {
140 return (set_errno(EINVAL
));
141 if (copyout(crgetgroups(cr
), gidset
, n
* sizeof (gid_t
)))
142 return (set_errno(EFAULT
));