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"
20 #include "afs/sysincludes.h"
21 #include "afsincludes.h"
22 #include "afs/afs_stats.h" /* statistics */
25 afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset);
28 afs_setgroups(struct ucred **cred, int ngroups, gid_t * gidset,
37 AFS_STATCNT(afs_xsetgroups);
39 code = afs_InitReq(&treq, p_cred(u.u_procp));
45 /* Note that if there is a pag already in the new groups we don't
46 * overwrite it with the old pag.
48 if (PagInCred(p_cred(u.u_procp)) == NOPAG) {
49 if (((treq.uid >> 24) & 0xff) == 'A') {
52 /* we've already done a setpag, so now we redo it */
53 cred = p_cred(u.u_procp);
54 AddPag(treq.uid, &cred);
62 setpag(cred, pagvalue, newpag, change_parent)
66 afs_uint32 change_parent;
68 gid_t gidset[NGROUPS];
73 ngroups = afs_getgroups(*cred, NGROUPS, gidset);
74 if (afs_get_pag_from_groups(gidset[0], gidset[1]) == NOPAG) {
75 /* We will have to shift grouplist to make room for pag */
76 if (ngroups + 2 > NGROUPS) {
77 return (setuerror(E2BIG), E2BIG);
79 for (j = ngroups - 1; j >= 0; j--) {
80 gidset[j + 2] = gidset[j];
84 *newpag = (pagvalue == -1 ? genpag() : pagvalue);
85 afs_get_groups_from_pag(*newpag, &gidset[0], &gidset[1]);
87 if (code = afs_setgroups(cred, ngroups, gidset, change_parent)) {
88 return (setuerror(code), code);
95 afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset)
100 gidset[0] = gidset[1] = 0;
101 AFS_STATCNT(afs_getgroups);
103 for (gp = &cred->cr_groups[NGROUPS]; gp > cred->cr_groups; gp--) {
104 if (gp[-1] != NOGROUP)
107 savengrps = ngrps = MIN(ngroups, gp - cred->cr_groups);
108 for (gp = cred->cr_groups; ngrps--;)
116 afs_setgroups(struct ucred **cred, int ngroups, gid_t * gidset,
124 #if defined(AFS_HPUX110_ENV)
125 register ulong_t context;
128 AFS_STATCNT(afs_setgroups);
130 if (!change_parent) {
131 newcr = (struct ucred *)crdup(*cred);
132 /* nobody else has the pointer to newcr because we
133 ** just allocated it, so no need for locking */
135 /* somebody else might have a pointer to this structure.
136 ** make sure we do not have a race condition */
138 #if defined(AFS_HPUX110_ENV)
139 /* all of the uniprocessor spinlocks are not defined. */
140 /* I assume the UP and MP are now handled together */
141 MP_SPINLOCK_USAV(cred_lock, context);
149 /* copy the group info */
150 gp = newcr->cr_groups;
153 for (; gp < &(newcr)->cr_groups[NGROUPS]; gp++)
156 if (!change_parent) {
157 /* replace the new cred structure in the proc area */
160 set_p_cred(u.u_procp, newcr);
163 #if defined(AFS_HPUX110_ENV)
164 MP_SPINUNLOCK_USAV(cred_lock, context);
167 SPINUNLOCK(cred_lock);
171 return (setuerror(0), 0);