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));
67 * Note that if there is a pag already in the new groups we don't
68 * overwrite it with the old pag.
70 if (PagInCred(cred) == NOPAG) {
71 if (((treq.uid >> 24) & 0xff) == 'A') {
73 /* we've already done a setpag, so now we redo it */
74 AddPag(p, treq.uid, &cred);
83 setpag(struct proc *proc, afs_ucred_t *cred, afs_uint32 pagvalue,
84 afs_uint32 * newpag, int change_parent)
86 gid_t gidset[NGROUPS];
91 ngroups = osi_getgroups(*cred, NGROUPS, gidset);
92 if (afs_get_pag_from_groups(gidset[1], gidset[2]) == NOPAG) {
93 /* We will have to shift grouplist to make room for pag */
94 if (ngroups + 2 > NGROUPS) {
97 for (j = ngroups - 1; j >= 0; j--) {
98 gidset[j + 2] = gidset[j];
102 *newpag = (pagvalue == -1 ? genpag() : pagvalue);
103 afs_get_groups_from_pag(*newpag, &gidset[1], &gidset[2]);
104 code = osi_setgroups(proc, cred, ngroups, gidset, change_parent);
110 osi_getgroups(kauth_cred_t cred, int ngroups, gid_t * gidset)
112 int ngrps, savengrps;
113 struct kauth_cred *cr;
116 AFS_STATCNT(afs_getgroups);
118 cr = (struct kauth_cred *) cred;
119 savengrps = ngrps = MIN(ngroups, kauth_cred_ngroups(cred));
120 gp = cred->cr_groups;
128 osi_setgroups(struct proc *proc, kauth_cred_t *cred, int ngroups,
129 gid_t * gidset, int change_parent)
132 struct kauth_cred *cr;
134 AFS_STATCNT(afs_setgroups); /* XXX rename statcnt */
136 if (ngroups > NGROUPS)
139 cr = (struct kauth_cred *) *cred;
141 cr = kauth_cred_copy(cr);
143 for (i = 0; i < ngroups; i++)
144 cr->cr_groups[i] = gidset[i];
145 for (i = ngroups; i < NGROUPS; i++)
146 cr->cr_groups[i] = NOGROUP;
147 cr->cr_ngroups = ngroups;