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 */
27 afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset);
30 afs_setgroups(struct ucred **cred, int ngroups, gid_t * gidset,
39 AFS_STATCNT(afs_xsetgroups);
41 code = afs_InitReq(&treq, p_cred(u.u_procp));
47 /* Note that if there is a pag already in the new groups we don't
48 * overwrite it with the old pag.
50 if (PagInCred(p_cred(u.u_procp)) == NOPAG) {
51 if (((treq.uid >> 24) & 0xff) == 'A') {
54 /* we've already done a setpag, so now we redo it */
55 cred = p_cred(u.u_procp);
56 AddPag(treq.uid, &cred);
64 setpag(cred, pagvalue, newpag, change_parent)
68 afs_uint32 change_parent;
70 gid_t gidset[NGROUPS];
75 ngroups = afs_getgroups(*cred, NGROUPS, gidset);
76 if (afs_get_pag_from_groups(gidset[0], gidset[1]) == NOPAG) {
77 /* We will have to shift grouplist to make room for pag */
78 if (ngroups + 2 > NGROUPS) {
79 return (setuerror(E2BIG), E2BIG);
81 for (j = ngroups - 1; j >= 0; j--) {
82 gidset[j + 2] = gidset[j];
86 *newpag = (pagvalue == -1 ? genpag() : pagvalue);
87 afs_get_groups_from_pag(*newpag, &gidset[0], &gidset[1]);
89 if (code = afs_setgroups(cred, ngroups, gidset, change_parent)) {
90 return (setuerror(code), code);
97 afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset)
102 gidset[0] = gidset[1] = 0;
103 AFS_STATCNT(afs_getgroups);
105 for (gp = &cred->cr_groups[NGROUPS]; gp > cred->cr_groups; gp--) {
106 if (gp[-1] != NOGROUP)
109 savengrps = ngrps = MIN(ngroups, gp - cred->cr_groups);
110 for (gp = cred->cr_groups; ngrps--;)
118 afs_setgroups(struct ucred **cred, int ngroups, gid_t * gidset,
126 #if defined(AFS_HPUX110_ENV)
127 register ulong_t context;
130 AFS_STATCNT(afs_setgroups);
132 if (!change_parent) {
133 newcr = (struct ucred *)crdup(*cred);
134 /* nobody else has the pointer to newcr because we
135 ** just allocated it, so no need for locking */
137 /* somebody else might have a pointer to this structure.
138 ** make sure we do not have a race condition */
140 #if defined(AFS_HPUX110_ENV)
141 /* all of the uniprocessor spinlocks are not defined. */
142 /* I assume the UP and MP are now handled together */
143 MP_SPINLOCK_USAV(cred_lock, context);
151 /* copy the group info */
152 gp = newcr->cr_groups;
155 for (; gp < &(newcr)->cr_groups[NGROUPS]; gp++)
158 if (!change_parent) {
159 /* replace the new cred structure in the proc area */
162 set_p_cred(u.u_procp, newcr);
165 #if defined(AFS_HPUX110_ENV)
166 MP_SPINUNLOCK_USAV(cred_lock, context);
169 SPINUNLOCK(cred_lock);
173 return (setuerror(0), 0);