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 thread *td, struct ucred **cred, int ngroups,
34 gid_t * gidset, int change_parent);
38 Afs_xsetgroups(struct thread *td, struct setgroups_args *uap)
44 cr = crdup(td->td_ucred);
46 AFS_STATCNT(afs_xsetgroups);
49 code = afs_InitReq(&treq, cr);
53 return setgroups(td, uap); /* afs has shut down */
55 code = setgroups(td, uap);
56 /* Note that if there is a pag already in the new groups we don't
57 * overwrite it with the old pag.
59 cr = crdup(td->td_ucred);
61 if (PagInCred(cr) == NOPAG) {
62 if (((treq.uid >> 24) & 0xff) == 'A') {
64 /* we've already done a setpag, so now we redo it */
65 AddPag(td, treq.uid, &cr);
75 setpag(struct thread *td, struct ucred **cred, afs_uint32 pagvalue,
76 afs_uint32 * newpag, int change_parent)
78 #if defined(AFS_FBSD81_ENV)
80 int gidset_len = ngroups_max + 1;
81 #elif defined(AFS_FBSD80_ENV)
83 int gidset_len = NGROUPS; /* 1024 */
85 gid_t gidset[NGROUPS];
86 int gidset_len = NGROUPS; /* 16 */
93 gidset = osi_Alloc(gidset_len * sizeof(gid_t));
95 ngroups = afs_getgroups(*cred, gidset_len, gidset);
96 if (afs_get_pag_from_groups(gidset[1], gidset[2]) == NOPAG) {
97 /* We will have to shift grouplist to make room for pag */
98 if (ngroups + 2 > gidset_len) {
101 for (j = ngroups - 1; j >= 1; j--) {
102 gidset[j + 2] = gidset[j];
106 *newpag = (pagvalue == -1 ? genpag() : pagvalue);
107 afs_get_groups_from_pag(*newpag, &gidset[1], &gidset[2]);
108 code = afs_setgroups(td, cred, ngroups, gidset, change_parent);
109 #ifdef AFS_FBSD80_ENV
110 osi_Free(gidset, gidset_len * sizeof(gid_t));
117 afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset)
119 int ngrps, savengrps;
122 AFS_STATCNT(afs_getgroups);
123 savengrps = ngrps = MIN(ngroups, cred->cr_ngroups);
124 gp = cred->cr_groups;
132 afs_setgroups(struct thread *td, struct ucred **cred, int ngroups,
133 gid_t * gidset, int change_parent)