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 "../afs/afsincludes.h"
23 #include "../afs/afs_stats.h" /* statistics */
44 AFS_STATCNT(afs_xsetgroups);
46 code = afs_InitReq(&treq, p_cred(u.u_procp));
48 if (code) return code;
51 /* Note that if there is a pag already in the new groups we don't
52 * overwrite it with the old pag.
54 if (PagInCred(p_cred(u.u_procp)) == NOPAG) {
55 if (((treq.uid >> 24) & 0xff) == 'A') {
58 /* we've already done a setpag, so now we redo it */
59 cred = p_cred(u.u_procp);
60 AddPag(treq.uid, &cred);
68 setpag(cred, pagvalue, newpag, change_parent)
72 afs_uint32 change_parent;
74 gid_t gidset[NGROUPS];
79 ngroups = afs_getgroups(*cred, NGROUPS, gidset);
80 if (afs_get_pag_from_groups(gidset[0], gidset[1]) == NOPAG) {
81 /* We will have to shift grouplist to make room for pag */
82 if (ngroups + 2 > NGROUPS) {
83 return (setuerror(E2BIG), E2BIG);
85 for (j = ngroups -1; j >= 0; j--) {
86 gidset[j+2] = gidset[j];
90 *newpag = (pagvalue == -1 ? genpag(): pagvalue);
91 afs_get_groups_from_pag(*newpag, &gidset[0], &gidset[1]);
93 if (code = afs_setgroups(cred, ngroups, gidset, change_parent)) {
94 return (setuerror(code), code);
106 int ngrps, savengrps;
109 gidset[0] = gidset[1] = 0;
110 AFS_STATCNT(afs_getgroups);
112 for (gp = &cred->cr_groups[NGROUPS]; gp > cred->cr_groups; gp--) {
113 if (gp[-1] != NOGROUP)
116 savengrps = ngrps = MIN(ngroups, gp - cred->cr_groups);
117 for (gp = cred->cr_groups; ngrps--; )
137 AFS_STATCNT(afs_setgroups);
141 newcr = (struct ucred *)crdup(*cred);
142 /* nobody else has the pointer to newcr because we
143 ** just allocated it, so no need for locking */
147 /* somebody else might have a pointer to this structure.
148 ** make sure we do not have a race condition */
154 /* copy the group info */
155 gp = newcr->cr_groups;
158 for ( ; gp < &(newcr)->cr_groups[NGROUPS]; gp++)
163 /* replace the new cred structure in the proc area */
166 set_p_cred(u.u_procp, newcr);
172 SPINUNLOCK(cred_lock);
174 return (setuerror(0), 0);