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,
40 afs_xsetgroups(uap, rvp)
41 u_int uap; /* this is gidsetsize */
42 gid_t *rvp; /* this is gidset */
46 struct proc *proc = ttoproc(curthread);
48 AFS_STATCNT(afs_xsetgroups);
50 code = afs_InitReq(&treq, proc->p_cred);
54 code = setgroups(uap, rvp);
56 /* Note that if there is a pag already in the new groups we don't
57 * overwrite it with the old pag.
59 if (PagInCred(proc->p_cred) == NOPAG) {
60 if (((treq.uid >> 24) & 0xff) == 'A') {
62 /* we've already done a setpag, so now we redo it */
63 AddPag(treq.uid, &proc->p_cred);
71 setpag(cred, pagvalue, newpag, change_parent)
75 afs_uint32 change_parent;
83 gidset = (gid_t *) osi_AllocSmallSpace(AFS_SMALLOCSIZ);
85 mutex_enter(&curproc->p_crlock);
86 ngroups = afs_getgroups(*cred, gidset);
88 if (afs_get_pag_from_groups(gidset[0], gidset[1]) == NOPAG) {
89 /* We will have to shift grouplist to make room for pag */
90 if ((sizeof gidset[0]) * (ngroups + 2) > AFS_SMALLOCSIZ) {
91 osi_FreeSmallSpace((char *)gidset);
94 for (j = ngroups - 1; j >= 0; j--) {
95 gidset[j + 2] = gidset[j];
99 *newpag = (pagvalue == -1 ? genpag() : pagvalue);
100 afs_get_groups_from_pag(*newpag, &gidset[0], &gidset[1]);
101 /* afs_setgroups will release curproc->p_crlock */
102 if (code = afs_setgroups(cred, ngroups, gidset, change_parent)) {
103 osi_FreeSmallSpace((char *)gidset);
106 osi_FreeSmallSpace((char *)gidset);
112 afs_getgroups(struct cred *cred, gid_t * gidset)
114 int ngrps, savengrps;
117 AFS_STATCNT(afs_getgroups);
119 gidset[0] = gidset[1] = 0;
120 #if defined(AFS_SUN510_ENV)
121 savengrps = ngrps = crgetngroups(cred);
122 gp = crgetgroups(cred);
124 savengrps = ngrps = cred->cr_ngroups;
125 gp = cred->cr_groups;
135 afs_setgroups(struct cred **cred, int ngroups, gid_t * gidset,
140 AFS_STATCNT(afs_setgroups);
142 if (ngroups > ngroups_max) {
143 mutex_exit(&curproc->p_crlock);
147 *cred = (struct cred *)crcopy(*cred);
148 #if defined(AFS_SUN510_ENV)
149 crsetgroups(*cred, ngroups, gidset);
150 gp = crgetgroups(*cred);
152 (*cred)->cr_ngroups = ngroups;
153 gp = (*cred)->cr_groups;
157 mutex_exit(&curproc->p_crlock);
159 crset(curproc, *cred); /* broadcast to all threads */