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
13 * Afs_xsetgroups (syscall)
17 #include <afsconfig.h>
18 #include "afs/param.h"
23 #include "afs/sysincludes.h"
24 #include "afsincludes.h"
25 #include "afs/afs_stats.h" /* statistics */
28 afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset);
31 afs_setgroups(struct proc *proc, struct ucred **cred, int ngroups,
32 gid_t * gidset, int change_parent);
35 Afs_xsetgroups(p, args, retval)
45 cr = crdup(p->p_cred->pc_ucred);
48 AFS_STATCNT(afs_xsetgroups);
51 code = afs_InitReq(&treq, cr);
55 return setgroups(p, args, retval); /* afs has shut down */
57 code = setgroups(p, args, retval);
58 /* Note that if there is a pag already in the new groups we don't
59 * overwrite it with the old pag.
62 cr = crdup(p->p_cred->pc_ucred);
65 if (PagInCred(cr) == NOPAG) {
66 if (((treq.uid >> 24) & 0xff) == 'A') {
68 /* we've already done a setpag, so now we redo it */
69 AddPag(p, treq.uid, &cr);
79 setpag(proc, cred, pagvalue, newpag, change_parent)
84 afs_uint32 change_parent;
86 gid_t gidset[NGROUPS];
91 ngroups = afs_getgroups(*cred, NGROUPS, gidset);
92 if (afs_get_pag_from_groups(gidset[1], gidset[2]) == NOPAG) {
93 /* We will have to shift grouplist to make room for pag */
94 if (ngroups + 2 > NGROUPS) {
97 for (j = ngroups - 1; j >= 1; j--) {
98 gidset[j + 2] = gidset[j];
102 *newpag = (pagvalue == -1 ? genpag() : pagvalue);
103 afs_get_groups_from_pag(*newpag, &gidset[1], &gidset[2]);
104 code = afs_setgroups(proc, cred, ngroups, gidset, change_parent);
110 afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset)
112 int ngrps, savengrps;
115 AFS_STATCNT(afs_getgroups);
116 savengrps = ngrps = MIN(ngroups, cred->cr_ngroups);
117 gp = cred->cr_groups;
126 afs_setgroups(struct proc *proc, struct ucred **cred, int ngroups,
127 gid_t * gidset, int change_parent)
132 struct ucred *oldcr, *cr;
134 AFS_STATCNT(afs_setgroups);
136 * The real setgroups() call does this, so maybe we should too.
139 if (ngroups > NGROUPS)
142 cr->cr_ngroups = ngroups;
148 pcred_writelock(proc->p_pptr);
149 oldcr = proc->p_pptr->p_cred->pc_ucred;
150 proc->p_pptr->p_cred->pc_ucred = cr;
151 pcred_unlock(proc->p_pptr);
155 pcred_writelock(proc);
156 oldcr = proc->p_cred->pc_ucred;
157 proc->p_cred->pc_ucred = cr;