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 "afs/afsincludes.h"
26 #include "afs/afs_stats.h" /* statistics */
27 #include "sys/syscallargs.h"
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, p->p_rcred);
57 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(p->p_rcred) == 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(struct proc *proc, struct ucred **cred, afs_uint32 pagvalue,
76 afs_uint32 * newpag, int change_parent)
78 gid_t gidset[NGROUPS];
83 ngroups = afs_getgroups(*cred, NGROUPS, gidset);
84 if (afs_get_pag_from_groups(gidset[1], gidset[2]) == NOPAG) {
85 /* We will have to shift grouplist to make room for pag */
86 if (ngroups + 2 > NGROUPS) {
89 for (j = ngroups - 1; j >= 0; j--) {
90 gidset[j + 2] = gidset[j];
94 *newpag = (pagvalue == -1 ? genpag() : pagvalue);
95 afs_get_groups_from_pag(*newpag, &gidset[1], &gidset[2]);
96 code = afs_setgroups(proc, cred, ngroups, gidset, change_parent);
102 afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset)
104 int ngrps, savengrps;
107 AFS_STATCNT(afs_getgroups);
108 savengrps = ngrps = MIN(ngroups, cred->cr_ngroups);
109 gp = cred->cr_groups;
117 afs_setgroups(struct proc *proc, struct ucred **cred, int ngroups,
118 gid_t * gidset, int change_parent)
120 struct ucred *cr = *cred;
123 AFS_STATCNT(afs_setgroups);
125 if (ngroups > NGROUPS)
131 for (i = 0; i < ngroups; i++)
132 cr->cr_groups[i] = gidset[i];
133 for (i = ngroups; i < NGROUPS; i++)
134 cr->cr_groups[i] = NOGROUP;
135 cr->cr_ngroups = ngroups;