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"
22 #include "afs/sysincludes.h"
23 #include "afsincludes.h"
24 #include "afs/afs_stats.h" /* statistics */
28 afs_getgroups(struct cred *cred, gid_t * gidset);
31 afs_setgroups(struct cred **cred, int ngroups, gid_t * gidset,
35 #if defined(AFS_SUN55_ENV)
37 afs_xsetgroups(uap, rvp)
38 u_int uap; /* this is gidsetsize */
39 gid_t *rvp; /* this is gidset */
46 afs_xsetgroups(uap, rvp)
47 struct setgroupsa *uap;
53 struct proc *proc = ttoproc(curthread);
55 AFS_STATCNT(afs_xsetgroups);
57 code = afs_InitReq(&treq, proc->p_cred);
61 code = setgroups(uap, rvp);
63 /* Note that if there is a pag already in the new groups we don't
64 * overwrite it with the old pag.
66 if (PagInCred(proc->p_cred) == NOPAG) {
67 if (((treq.uid >> 24) & 0xff) == 'A') {
69 /* we've already done a setpag, so now we redo it */
70 AddPag(treq.uid, &proc->p_cred);
78 setpag(cred, pagvalue, newpag, change_parent)
82 afs_uint32 change_parent;
90 gidset = (gid_t *) osi_AllocSmallSpace(AFS_SMALLOCSIZ);
92 mutex_enter(&curproc->p_crlock);
93 ngroups = afs_getgroups(*cred, gidset);
95 if (afs_get_pag_from_groups(gidset[0], gidset[1]) == NOPAG) {
96 /* We will have to shift grouplist to make room for pag */
97 if ((sizeof gidset[0]) * (ngroups + 2) > AFS_SMALLOCSIZ) {
98 osi_FreeSmallSpace((char *)gidset);
101 for (j = ngroups - 1; j >= 0; j--) {
102 gidset[j + 2] = gidset[j];
106 *newpag = (pagvalue == -1 ? genpag() : pagvalue);
107 afs_get_groups_from_pag(*newpag, &gidset[0], &gidset[1]);
108 /* afs_setgroups will release curproc->p_crlock */
109 if (code = afs_setgroups(cred, ngroups, gidset, change_parent)) {
110 osi_FreeSmallSpace((char *)gidset);
113 osi_FreeSmallSpace((char *)gidset);
119 afs_getgroups(struct cred *cred, gid_t * gidset)
121 int ngrps, savengrps;
124 AFS_STATCNT(afs_getgroups);
126 gidset[0] = gidset[1] = 0;
127 savengrps = ngrps = cred->cr_ngroups;
128 gp = cred->cr_groups;
137 afs_setgroups(struct cred **cred, int ngroups, gid_t * gidset,
144 AFS_STATCNT(afs_setgroups);
146 if (ngroups > ngroups_max) {
147 mutex_exit(&curproc->p_crlock);
151 *cred = (struct cred *)crcopy(*cred);
152 (*cred)->cr_ngroups = ngroups;
153 gp = (*cred)->cr_groups;
156 mutex_exit(&curproc->p_crlock);
158 crset(curproc, *cred); /* broadcast to all threads */