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
16 #include <afsconfig.h>
17 #include "afs/param.h"
21 #include "afs/sysincludes.h"
22 #include "afsincludes.h"
23 #include "afs/afs_stats.h" /* statistics */
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);
63 if (code) return code;
64 code = setgroups(uap, rvp);
66 /* Note that if there is a pag already in the new groups we don't
67 * overwrite it with the old pag.
69 if (PagInCred(proc->p_cred) == NOPAG) {
70 if (((treq.uid >> 24) & 0xff) == 'A') {
72 /* we've already done a setpag, so now we redo it */
73 AddPag(treq.uid, &proc->p_cred);
81 setpag(cred, pagvalue, newpag, change_parent)
85 afs_uint32 change_parent;
93 gidset = (gid_t *) osi_AllocSmallSpace(AFS_SMALLOCSIZ);
95 mutex_enter(&curproc->p_crlock);
96 ngroups = afs_getgroups(*cred, gidset);
98 if (afs_get_pag_from_groups(gidset[0], gidset[1]) == NOPAG) {
99 /* We will have to shift grouplist to make room for pag */
100 if ((sizeof gidset[0])*(ngroups + 2) > AFS_SMALLOCSIZ) {
101 osi_FreeSmallSpace((char *)gidset);
104 for (j = ngroups -1; j >= 0; j--) {
105 gidset[j+2] = gidset[j];
109 *newpag = (pagvalue == -1 ? genpag(): pagvalue);
110 afs_get_groups_from_pag(*newpag, &gidset[0], &gidset[1]);
111 /* afs_setgroups will release curproc->p_crlock */
112 if (code = afs_setgroups(cred, ngroups, gidset, change_parent)) {
113 osi_FreeSmallSpace((char *)gidset);
116 osi_FreeSmallSpace((char *)gidset);
126 int ngrps, savengrps;
129 AFS_STATCNT(afs_getgroups);
131 gidset[0] = gidset[1] = 0;
132 savengrps = ngrps = cred->cr_ngroups;
133 gp = cred->cr_groups;
152 AFS_STATCNT(afs_setgroups);
154 if (ngroups > ngroups_max) {
155 mutex_exit(&curproc->p_crlock);
159 *cred = (struct cred *)crcopy(*cred);
160 (*cred)->cr_ngroups = ngroups;
161 gp = (*cred)->cr_groups;
164 mutex_exit(&curproc->p_crlock);
166 crset(curproc, *cred); /* broadcast to all threads */