1 /* Copyright (C) 1995, 1989, 1998 Transarc Corporation - All rights reserved */
3 * (C) COPYRIGHT IBM CORPORATION 1987, 1988
4 * LICENSED MATERIALS - PROPERTY OF IBM
14 #include "../afs/param.h"
15 #include "../afs/sysincludes.h"
16 #include "../afs/afsincludes.h"
17 #include "../afs/afs_stats.h" /* statistics */
33 #if defined(AFS_SUN55_ENV)
35 afs_xsetgroups(uap, rvp)
36 u_int uap; /* this is gidsetsize */
37 gid_t *rvp; /* this is gidset */
44 afs_xsetgroups(uap, rvp)
45 struct setgroupsa *uap;
51 struct proc *proc = ttoproc(curthread);
53 AFS_STATCNT(afs_xsetgroups);
55 code = afs_InitReq(&treq, proc->p_cred);
57 if (code) return code;
58 code = setgroups(uap, rvp);
60 /* Note that if there is a pag already in the new groups we don't
61 * overwrite it with the old pag.
63 if (PagInCred(proc->p_cred) == NOPAG) {
64 if (((treq.uid >> 24) & 0xff) == 'A') {
66 /* we've already done a setpag, so now we redo it */
67 AddPag(treq.uid, &proc->p_cred);
75 setpag(cred, pagvalue, newpag, change_parent)
79 afs_uint32 change_parent;
87 gidset = (gid_t *) osi_AllocSmallSpace(AFS_SMALLOCSIZ);
88 ngroups = afs_getgroups(*cred, gidset);
90 if (afs_get_pag_from_groups(gidset[0], gidset[1]) == NOPAG) {
91 /* We will have to shift grouplist to make room for pag */
92 if ((sizeof gidset[0])*(ngroups + 2) > AFS_SMALLOCSIZ) {
93 osi_FreeSmallSpace((char *)gidset);
96 for (j = ngroups -1; j >= 0; j--) {
97 gidset[j+2] = gidset[j];
101 *newpag = (pagvalue == -1 ? genpag(): pagvalue);
102 afs_get_groups_from_pag(*newpag, &gidset[0], &gidset[1]);
103 if (code = afs_setgroups(cred, ngroups, gidset, change_parent)) {
104 osi_FreeSmallSpace((char *)gidset);
107 osi_FreeSmallSpace((char *)gidset);
117 int ngrps, savengrps;
120 AFS_STATCNT(afs_getgroups);
122 gidset[0] = gidset[1] = 0;
123 savengrps = ngrps = cred->cr_ngroups;
124 gp = cred->cr_groups;
143 AFS_STATCNT(afs_setgroups);
145 if (ngroups > ngroups_max)
148 *cred = (struct cred *)crcopy(*cred);
149 (*cred)->cr_ngroups = ngroups;
150 gp = (*cred)->cr_groups;
153 if (!change_parent) {
154 struct proc *proc = ttoproc(curthread);
155 crset(proc, *cred); /* broadcast to all threads */