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 "afs/afsincludes.h"
24 #include "afs/afs_stats.h" /* statistics */
25 #include "sys/syscallargs.h"
27 #define NOUID ((uid_t) -1)
28 #define NOGID ((gid_t) -1)
31 * NetBSD has a very flexible and elegant replacement for Unix
32 * groups KPIs, see KAUTH(9).
37 osi_getgroups(kauth_cred_t cred, int ngroups, gid_t * gidset);
40 /* why **? are we returning or reallocating creat? */
42 osi_setgroups(struct proc *proc, kauth_cred_t *cred, int ngroups,
43 gid_t * gidset, int change_parent);
46 Afs_xsetgroups(struct proc *p, void *args, int *retval)
50 kauth_cred_t cred = osi_proccred(p);
52 AFS_STATCNT(afs_xsetgroups);
55 code = afs_InitReq(&treq, (afs_ucred_t *) cred);
62 * XXX Does treq.uid == osi_crgetruid(cred)?
65 code = kauth_cred_setgroups(cred, args, retval, osi_crgetruid(cred), UIO_SYSSPACE);
67 code = kauth_cred_setgroups(cred, args, retval, osi_crgetruid(cred));
70 * Note that if there is a pag already in the new groups we don't
71 * overwrite it with the old pag.
73 if (PagInCred(cred) == NOPAG) {
74 if (((treq.uid >> 24) & 0xff) == 'A') {
76 /* we've already done a setpag, so now we redo it */
77 AddPag(p, treq.uid, &cred);
86 setpag(struct proc *proc, afs_ucred_t *cred, afs_uint32 pagvalue,
87 afs_uint32 * newpag, int change_parent)
89 gid_t gidset[NGROUPS];
94 ngroups = osi_getgroups(*cred, NGROUPS, gidset);
95 if (afs_get_pag_from_groups(gidset[1], gidset[2]) == NOPAG) {
96 /* We will have to shift grouplist to make room for pag */
97 if (ngroups + 2 > NGROUPS) {
100 for (j = ngroups - 1; j >= 0; j--) {
101 gidset[j + 2] = gidset[j];
105 *newpag = (pagvalue == -1 ? genpag() : pagvalue);
106 afs_get_groups_from_pag(*newpag, &gidset[1], &gidset[2]);
107 code = osi_setgroups(proc, cred, ngroups, gidset, change_parent);
113 osi_getgroups(kauth_cred_t cred, int ngroups, gid_t * gidset)
115 int ngrps, savengrps;
116 struct kauth_cred *cr;
119 AFS_STATCNT(afs_getgroups);
121 cr = (struct kauth_cred *) cred;
122 savengrps = ngrps = MIN(ngroups, kauth_cred_ngroups(cred));
123 gp = cred->cr_groups;
131 osi_setgroups(struct proc *proc, kauth_cred_t *cred, int ngroups,
132 gid_t * gidset, int change_parent)
135 struct kauth_cred *cr;
137 AFS_STATCNT(afs_setgroups); /* XXX rename statcnt */
139 if (ngroups > NGROUPS)
142 cr = (struct kauth_cred *) *cred;
144 cr = kauth_cred_copy(cr);
146 for (i = 0; i < ngroups; i++)
147 cr->cr_groups[i] = gidset[i];
148 for (i = ngroups; i < NGROUPS; i++)
149 cr->cr_groups[i] = NOGROUP;
150 cr->cr_ngroups = ngroups;