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>
20 #include <sys/sysproto.h>
23 #include "afs/sysincludes.h"
24 #include "afsincludes.h"
25 #include "afs/afs_stats.h" /* statistics */
28 afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset);
31 afs_setgroups(struct thread *td, struct ucred **cred, int ngroups,
32 gid_t * gidset, int change_parent);
36 Afs_xsetgroups(struct thread *td, struct setgroups_args *uap)
42 cr = crdup(td->td_ucred);
44 AFS_STATCNT(afs_xsetgroups);
47 code = afs_InitReq(&treq, cr);
51 #if (__FreeBSD_version >= 900044)
52 return sys_setgroups(td, uap); /* afs has shut down */
54 return setgroups(td, uap); /* afs has shut down */
57 #if (__FreeBSD_version >= 900044)
58 code = sys_setgroups(td, uap);
60 code = setgroups(td, uap);
62 /* Note that if there is a pag already in the new groups we don't
63 * overwrite it with the old pag.
65 cr = crdup(td->td_ucred);
67 if (PagInCred(cr) == NOPAG) {
68 if (((treq.uid >> 24) & 0xff) == 'A') {
70 /* we've already done a setpag, so now we redo it */
71 AddPag(td, treq.uid, &cr);
81 setpag(struct thread *td, struct ucred **cred, afs_uint32 pagvalue,
82 afs_uint32 * newpag, int change_parent)
84 #if defined(AFS_FBSD81_ENV)
86 int gidset_len = ngroups_max + 1;
89 int gidset_len = NGROUPS; /* 1024 */
95 gidset = osi_Alloc(gidset_len * sizeof(gid_t));
96 ngroups = afs_getgroups(*cred, gidset_len, gidset);
97 if (afs_get_pag_from_groups(gidset[1], gidset[2]) == NOPAG) {
98 /* We will have to shift grouplist to make room for pag */
99 if (ngroups + 2 > gidset_len) {
102 for (j = ngroups - 1; j >= 1; j--) {
103 gidset[j + 2] = gidset[j];
107 *newpag = (pagvalue == -1 ? genpag() : pagvalue);
108 afs_get_groups_from_pag(*newpag, &gidset[1], &gidset[2]);
109 code = afs_setgroups(td, cred, ngroups, gidset, change_parent);
110 osi_Free(gidset, gidset_len * sizeof(gid_t));
116 afs_getgroups(struct ucred *cred, int ngroups, gid_t * gidset)
118 int ngrps, savengrps;
121 AFS_STATCNT(afs_getgroups);
122 savengrps = ngrps = MIN(ngroups, cred->cr_ngroups);
123 gp = cred->cr_groups;
131 afs_setgroups(struct thread *td, struct ucred **cred, int ngroups,
132 gid_t * gidset, int change_parent)