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"
19 #include <sys/param.h>
21 #include <sys/sysproto.h>
25 #include "afs/sysincludes.h"
26 #include "afsincludes.h"
27 #include "afs/afs_stats.h" /* statistics */
30 afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset);
33 afs_setgroups(struct proc *proc, struct ucred **cred, int ngroups,
34 gid_t * gidset, int change_parent);
38 * This does nothing useful yet.
39 * In 5.0, creds are associated not with a process, but with a thread.
40 * Probably the right thing to do is replace struct proc with struct thread
41 * everywhere, including setpag.
42 * That will be a tedious undertaking.
43 * For now, I'm just passing curproc to AddPag.
44 * This is probably wrong and I don't know what the consequences might be.
48 Afs_xsetgroups(struct thread *td, struct setgroups_args *uap)
54 cr = crdup(td->td_ucred);
56 AFS_STATCNT(afs_xsetgroups);
59 code = afs_InitReq(&treq, cr);
63 return setgroups(td, uap); /* afs has shut down */
65 code = setgroups(td, uap);
66 /* Note that if there is a pag already in the new groups we don't
67 * overwrite it with the old pag.
69 cr = crdup(td->td_ucred);
71 if (PagInCred(cr) == NOPAG) {
72 if (((treq.uid >> 24) & 0xff) == 'A') {
74 /* we've already done a setpag, so now we redo it */
75 AddPag(curproc, treq.uid, &cr);
84 Afs_xsetgroups(p, args, retval)
93 cr = crdup(p->p_cred->pc_ucred);
95 AFS_STATCNT(afs_xsetgroups);
98 code = afs_InitReq(&treq, cr);
102 return setgroups(p, args, retval); /* afs has shut down */
104 code = setgroups(p, args, retval);
105 /* Note that if there is a pag already in the new groups we don't
106 * overwrite it with the old pag.
108 cr = crdup(p->p_cred->pc_ucred);
110 if (PagInCred(cr) == NOPAG) {
111 if (((treq.uid >> 24) & 0xff) == 'A') {
113 /* we've already done a setpag, so now we redo it */
114 AddPag(p, treq.uid, &cr);
125 setpag(struct proc *proc, struct ucred **cred, afs_uint32 pagvalue,
126 afs_uint32 * newpag, int change_parent)
128 gid_t gidset[NGROUPS];
133 ngroups = afs_getgroups(*cred, NGROUPS, gidset);
134 if (afs_get_pag_from_groups(gidset[1], gidset[2]) == NOPAG) {
135 /* We will have to shift grouplist to make room for pag */
136 if (ngroups + 2 > NGROUPS) {
139 for (j = ngroups - 1; j >= 1; j--) {
140 gidset[j + 2] = gidset[j];
144 *newpag = (pagvalue == -1 ? genpag() : pagvalue);
145 afs_get_groups_from_pag(*newpag, &gidset[1], &gidset[2]);
146 code = afs_setgroups(proc, cred, ngroups, gidset, change_parent);
152 afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset)
154 int ngrps, savengrps;
157 AFS_STATCNT(afs_getgroups);
158 savengrps = ngrps = MIN(ngroups, cred->cr_ngroups);
159 gp = cred->cr_groups;
167 afs_setgroups(struct proc *proc, struct ucred **cred, int ngroups,
168 gid_t * gidset, int change_parent)
170 #ifndef AFS_FBSD50_ENV
174 struct ucred *oldcr, *cr;
176 AFS_STATCNT(afs_setgroups);
178 * The real setgroups() call does this, so maybe we should too.
181 if (ngroups > NGROUPS)
184 cr->cr_ngroups = ngroups;
190 oldcr = proc->p_pptr->p_cred->pc_ucred;
191 proc->p_pptr->p_cred->pc_ucred = cr;
195 oldcr = proc->p_cred->pc_ucred;
196 proc->p_cred->pc_ucred = cr;