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
14 * Afs_xsetgroups (syscall)
18 #include <afsconfig.h>
19 #include "afs/param.h"
24 #include "afs/sysincludes.h"
25 #include "afsincludes.h"
26 #include "afs/afs_stats.h" /* statistics */
28 #define NOCRED ((struct ucred *) -1)
29 #define NOUID ((uid_t) -1)
30 #define NOGID ((gid_t) -1)
34 afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset);
37 afs_setgroups(struct proc *proc, struct ucred **cred, int ngroups,
38 gid_t * gidset, int change_parent);
41 Afs_xsetgroups(p, args, retval)
49 AFS_STATCNT(afs_xsetgroups);
52 /* code = afs_InitReq(&treq, u.u_cred); */
53 code = afs_InitReq(&treq, curproc->p_cred->pc_ucred);
58 code = setgroups(p, args, retval);
59 /* Note that if there is a pag already in the new groups we don't
60 * overwrite it with the old pag.
62 if (PagInCred(curproc->p_cred->pc_ucred) == NOPAG) {
63 if (((treq.uid >> 24) & 0xff) == 'A') {
65 /* we've already done a setpag, so now we redo it */
66 AddPag(p, treq.uid, &p->p_rcred);
75 setpag(proc, cred, pagvalue, newpag, change_parent)
80 afs_uint32 change_parent;
82 gid_t gidset[NGROUPS];
87 ngroups = afs_getgroups(*cred, NGROUPS, gidset);
88 if (afs_get_pag_from_groups(gidset[0], gidset[1]) == NOPAG) {
89 /* We will have to shift grouplist to make room for pag */
90 if (ngroups + 2 > NGROUPS) {
93 for (j = ngroups - 1; j >= 0; j--) {
94 gidset[j + 2] = gidset[j];
98 *newpag = (pagvalue == -1 ? genpag() : pagvalue);
99 afs_get_groups_from_pag(*newpag, &gidset[0], &gidset[1]);
100 code = afs_setgroups(proc, cred, ngroups, gidset, change_parent);
106 afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset)
108 int ngrps, savengrps;
111 AFS_STATCNT(afs_getgroups);
112 savengrps = ngrps = MIN(ngroups, cred->cr_ngroups);
113 gp = cred->cr_groups;
122 afs_setgroups(struct proc *proc, struct ucred **cred, int ngroups,
123 gid_t * gidset, int change_parent)
128 struct ucred *newcr, *cr;
130 AFS_STATCNT(afs_setgroups);
132 * The real setgroups() call does this, so maybe we should too.
135 if (ngroups > NGROUPS)
138 if (!change_parent) {
143 newcr->cr_ngroups = ngroups;
144 gp = newcr->cr_groups;
147 if (!change_parent) {
148 substitute_real_creds(proc, NOUID, NOUID, NOGID, NOGID, newcr);