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"
22 #include "afs/sysincludes.h"
23 #include "afsincludes.h"
24 #include "afs/afs_stats.h" /* statistics */
26 #define NOCRED ((struct ucred *) -1)
27 #define NOUID ((uid_t) -1)
28 #define NOGID ((gid_t) -1)
32 afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset);
35 afs_setgroups(struct proc *proc, struct ucred **cred, int ngroups,
36 gid_t * gidset, int change_parent);
39 Afs_xsetgroups(p, args, retval)
47 AFS_STATCNT(afs_xsetgroups);
50 /* code = afs_InitReq(&treq, u.u_cred); */
51 code = afs_InitReq(&treq, curproc->p_cred->pc_ucred);
56 code = setgroups(p, args, retval);
57 /* Note that if there is a pag already in the new groups we don't
58 * overwrite it with the old pag.
60 if (PagInCred(curproc->p_cred->pc_ucred) == NOPAG) {
61 if (((treq.uid >> 24) & 0xff) == 'A') {
63 /* we've already done a setpag, so now we redo it */
64 AddPag(p, treq.uid, &p->p_rcred);
73 setpag(proc, cred, pagvalue, newpag, change_parent)
78 afs_uint32 change_parent;
80 gid_t gidset[NGROUPS];
85 ngroups = afs_getgroups(*cred, NGROUPS, gidset);
86 if (afs_get_pag_from_groups(gidset[0], gidset[1]) == NOPAG) {
87 /* We will have to shift grouplist to make room for pag */
88 if (ngroups + 2 > NGROUPS) {
91 for (j = ngroups - 1; j >= 0; j--) {
92 gidset[j + 2] = gidset[j];
96 *newpag = (pagvalue == -1 ? genpag() : pagvalue);
97 afs_get_groups_from_pag(*newpag, &gidset[0], &gidset[1]);
98 code = afs_setgroups(proc, cred, ngroups, gidset, change_parent);
104 afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset)
106 int ngrps, savengrps;
109 AFS_STATCNT(afs_getgroups);
110 savengrps = ngrps = MIN(ngroups, cred->cr_ngroups);
111 gp = cred->cr_groups;
120 afs_setgroups(struct proc *proc, struct ucred **cred, int ngroups,
121 gid_t * gidset, int change_parent)
126 struct ucred *newcr, *cr;
128 AFS_STATCNT(afs_setgroups);
130 * The real setgroups() call does this, so maybe we should too.
133 if (ngroups > NGROUPS)
136 if (!change_parent) {
141 newcr->cr_ngroups = ngroups;
142 gp = newcr->cr_groups;
145 if (!change_parent) {
146 substitute_real_creds(proc, NOUID, NOUID, NOGID, NOGID, newcr);