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>
27 #include "afs/sysincludes.h"
28 #include "afsincludes.h"
29 #include "afs/afs_stats.h" /* statistics */
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);
40 * This does nothing useful yet.
41 * In 5.0, creds are associated not with a process, but with a thread.
42 * Probably the right thing to do is replace struct proc with struct thread
43 * everywhere, including setpag.
44 * That will be a tedious undertaking.
45 * For now, I'm just passing curproc to AddPag.
46 * This is probably wrong and I don't know what the consequences might be.
50 Afs_xsetgroups(struct thread *td, struct setgroups_args *uap)
56 cr = crdup(td->td_ucred);
58 AFS_STATCNT(afs_xsetgroups);
61 code = afs_InitReq(&treq, cr);
65 return setgroups(td, uap); /* afs has shut down */
67 code = setgroups(td, uap);
68 /* Note that if there is a pag already in the new groups we don't
69 * overwrite it with the old pag.
71 cr = crdup(td->td_ucred);
73 if (PagInCred(cr) == NOPAG) {
74 if (((treq.uid >> 24) & 0xff) == 'A') {
76 /* we've already done a setpag, so now we redo it */
77 AddPag(curproc, treq.uid, &cr);
86 Afs_xsetgroups(p, args, retval)
95 cr = crdup(p->p_cred->pc_ucred);
97 AFS_STATCNT(afs_xsetgroups);
100 code = afs_InitReq(&treq, cr);
104 return setgroups(p, args, retval); /* afs has shut down */
106 code = setgroups(p, args, retval);
107 /* Note that if there is a pag already in the new groups we don't
108 * overwrite it with the old pag.
110 cr = crdup(p->p_cred->pc_ucred);
112 if (PagInCred(cr) == NOPAG) {
113 if (((treq.uid >> 24) & 0xff) == 'A') {
115 /* we've already done a setpag, so now we redo it */
116 AddPag(p, treq.uid, &cr);
127 setpag(struct proc *proc, struct ucred **cred, afs_uint32 pagvalue,
128 afs_uint32 * newpag, int change_parent)
130 gid_t gidset[NGROUPS];
135 ngroups = afs_getgroups(*cred, NGROUPS, gidset);
136 if (afs_get_pag_from_groups(gidset[1], gidset[2]) == NOPAG) {
137 /* We will have to shift grouplist to make room for pag */
138 if (ngroups + 2 > NGROUPS) {
141 for (j = ngroups - 1; j >= 1; j--) {
142 gidset[j + 2] = gidset[j];
146 *newpag = (pagvalue == -1 ? genpag() : pagvalue);
147 afs_get_groups_from_pag(*newpag, &gidset[1], &gidset[2]);
148 code = afs_setgroups(proc, cred, ngroups, gidset, change_parent);
154 afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset)
156 int ngrps, savengrps;
159 AFS_STATCNT(afs_getgroups);
160 savengrps = ngrps = MIN(ngroups, cred->cr_ngroups);
161 gp = cred->cr_groups;
169 afs_setgroups(struct proc *proc, struct ucred **cred, int ngroups,
170 gid_t * gidset, int change_parent)
172 #ifndef AFS_FBSD50_ENV
176 struct ucred *oldcr, *cr;
178 AFS_STATCNT(afs_setgroups);
180 * The real setgroups() call does this, so maybe we should too.
183 if (ngroups > NGROUPS)
186 cr->cr_ngroups = ngroups;
192 oldcr = proc->p_pptr->p_cred->pc_ucred;
193 proc->p_pptr->p_cred->pc_ucred = cr;
197 oldcr = proc->p_cred->pc_ucred;
198 proc->p_cred->pc_ucred = cr;