From e0306e8c05c16b176f9861b271d358bcdded74d2 Mon Sep 17 00:00:00 2001 From: Jim Rees Date: Tue, 24 Jun 2003 20:24:18 +0000 Subject: [PATCH] openbsd-groups-20030624 openbsd: use the right creds in afs_xsetgroups don't clobber the ucred pool by running off the end of the group list don't over-hold creds --- src/afs/OBSD/osi_groups.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/afs/OBSD/osi_groups.c b/src/afs/OBSD/osi_groups.c index 2f7a0015a5..c170b1e2a5 100644 --- a/src/afs/OBSD/osi_groups.c +++ b/src/afs/OBSD/osi_groups.c @@ -55,7 +55,7 @@ Afs_xsetgroups(p, args, retval) AFS_STATCNT(afs_xsetgroups); AFS_GLOCK(); - code = afs_InitReq(&treq, osi_curcred()); + code = afs_InitReq(&treq, p->p_rcred); AFS_GUNLOCK(); if (code) return code; @@ -65,7 +65,7 @@ Afs_xsetgroups(p, args, retval) * Note that if there is a pag already in the new groups we don't * overwrite it with the old pag. */ - if (PagInCred(osi_curcred()) == NOPAG) { + if (PagInCred(p->p_rcred) == NOPAG) { if (((treq.uid >> 24) & 0xff) == 'A') { AFS_GLOCK(); /* we've already done a setpag, so now we redo it */ @@ -130,26 +130,23 @@ afs_setgroups( gid_t *gidset, int change_parent) { - gid_t *gp; - struct ucred *newcr, *cr; + struct ucred *cr = *cred; + int i; AFS_STATCNT(afs_setgroups); - /* - * The real setgroups() call does this, so maybe we should too. - */ + if (ngroups > NGROUPS) return EINVAL; - cr = *cred; + if (!change_parent) - newcr = crdup(cr); - else - newcr = cr; - newcr->cr_ngroups = ngroups; - gp = newcr->cr_groups; - while (ngroups--) - *gp++ = *gidset++; - for ( ; gp < &(*cred)->cr_groups[NGROUPS]; gp++) - *gp = NOGROUP; - *cred = newcr; + cr = crcopy(cr); + + for (i = 0; i < ngroups; i++) + cr->cr_groups[i] = gidset[i]; + for (i = ngroups; i < NGROUPS; i++) + cr->cr_groups[i] = NOGROUP; + cr->cr_ngroups = ngroups; + + *cred = cr; return(0); }