2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
22 #include <afsconfig.h>
23 #include "afs/param.h"
26 #include "afs/sysincludes.h"
27 #include "afsincludes.h"
28 #include "afs/afs_stats.h" /* statistics */
32 afs_getgroups(struct cred *cred, gid_t * gidset);
35 afs_setgroups(struct cred **cred, int ngroups, gid_t * gidset,
39 #if defined(AFS_SUN55_ENV)
41 afs_xsetgroups(uap, rvp)
42 u_int uap; /* this is gidsetsize */
43 gid_t *rvp; /* this is gidset */
50 afs_xsetgroups(uap, rvp)
51 struct setgroupsa *uap;
57 struct proc *proc = ttoproc(curthread);
59 AFS_STATCNT(afs_xsetgroups);
61 code = afs_InitReq(&treq, proc->p_cred);
65 code = setgroups(uap, rvp);
67 /* Note that if there is a pag already in the new groups we don't
68 * overwrite it with the old pag.
70 if (PagInCred(proc->p_cred) == NOPAG) {
71 if (((treq.uid >> 24) & 0xff) == 'A') {
73 /* we've already done a setpag, so now we redo it */
74 AddPag(treq.uid, &proc->p_cred);
82 setpag(cred, pagvalue, newpag, change_parent)
86 afs_uint32 change_parent;
94 gidset = (gid_t *) osi_AllocSmallSpace(AFS_SMALLOCSIZ);
96 mutex_enter(&curproc->p_crlock);
97 ngroups = afs_getgroups(*cred, gidset);
99 if (afs_get_pag_from_groups(gidset[0], gidset[1]) == NOPAG) {
100 /* We will have to shift grouplist to make room for pag */
101 if ((sizeof gidset[0]) * (ngroups + 2) > AFS_SMALLOCSIZ) {
102 osi_FreeSmallSpace((char *)gidset);
105 for (j = ngroups - 1; j >= 0; j--) {
106 gidset[j + 2] = gidset[j];
110 *newpag = (pagvalue == -1 ? genpag() : pagvalue);
111 afs_get_groups_from_pag(*newpag, &gidset[0], &gidset[1]);
112 /* afs_setgroups will release curproc->p_crlock */
113 if (code = afs_setgroups(cred, ngroups, gidset, change_parent)) {
114 osi_FreeSmallSpace((char *)gidset);
117 osi_FreeSmallSpace((char *)gidset);
123 afs_getgroups(struct cred *cred, gid_t * gidset)
125 int ngrps, savengrps;
128 AFS_STATCNT(afs_getgroups);
130 gidset[0] = gidset[1] = 0;
131 #if defined(AFS_SUN510_ENV)
132 savengrps = ngrps = crgetngroups(cred);
133 gp = crgetgroups(cred);
135 savengrps = ngrps = cred->cr_ngroups;
136 gp = cred->cr_groups;
146 afs_setgroups(struct cred **cred, int ngroups, gid_t * gidset,
151 AFS_STATCNT(afs_setgroups);
153 if (ngroups > ngroups_max) {
154 mutex_exit(&curproc->p_crlock);
158 *cred = (struct cred *)crcopy(*cred);
159 #if defined(AFS_SUN510_ENV)
160 crsetgroups(*cred, ngroups, gidset);
161 gp = crgetgroups(*cred);
163 (*cred)->cr_ngroups = ngroups;
164 gp = (*cred)->cr_groups;
168 mutex_exit(&curproc->p_crlock);
170 crset(curproc, *cred); /* broadcast to all threads */