diff options
author | jhb <jhb@FreeBSD.org> | 2006-07-06 21:32:20 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2006-07-06 21:32:20 +0000 |
commit | 54c687571c8f72bead8ce1053420ca0930c940ec (patch) | |
tree | 7d521d8fd39be4b32b8ff3987e7932bc3716c43f /sys/i386/ibcs2 | |
parent | 6fe08fdbd364751465599ae63ca8f140a122cce0 (diff) | |
download | FreeBSD-src-54c687571c8f72bead8ce1053420ca0930c940ec.zip FreeBSD-src-54c687571c8f72bead8ce1053420ca0930c940ec.tar.gz |
Add kern_setgroups() and kern_getgroups() and use them to implement
ibcs2_[gs]etgroups() rather than using the stackgap. This also makes
ibcs2_[gs]etgroups() MPSAFE. Also, it cleans up one bit of weirdness in
the old setgroups() where it allocated an entire credential just so it had
a place to copy the group list into. Now setgroups just allocates a
NGROUPS_MAX array on the stack that it copies into and then passes to
kern_setgroups().
Diffstat (limited to 'sys/i386/ibcs2')
-rw-r--r-- | sys/i386/ibcs2/ibcs2_misc.c | 67 | ||||
-rw-r--r-- | sys/i386/ibcs2/syscalls.xenix | 4 |
2 files changed, 27 insertions, 44 deletions
diff --git a/sys/i386/ibcs2/ibcs2_misc.c b/sys/i386/ibcs2/ibcs2_misc.c index c4efc02..c875075 100644 --- a/sys/i386/ibcs2/ibcs2_misc.c +++ b/sys/i386/ibcs2/ibcs2_misc.c @@ -651,35 +651,25 @@ ibcs2_getgroups(td, uap) struct thread *td; struct ibcs2_getgroups_args *uap; { - int error, i; - ibcs2_gid_t *iset = NULL; - struct getgroups_args sa; - gid_t *gp; - caddr_t sg = stackgap_init(); + ibcs2_gid_t iset[NGROUPS_MAX]; + gid_t gp[NGROUPS_MAX]; + u_int i, ngrp; + int error; if (uap->gidsetsize < 0) return (EINVAL); - if (uap->gidsetsize > NGROUPS_MAX) - uap->gidsetsize = NGROUPS_MAX; - sa.gidsetsize = uap->gidsetsize; - if (uap->gidsetsize) { - sa.gidset = stackgap_alloc(&sg, NGROUPS_MAX * - sizeof(gid_t *)); - iset = stackgap_alloc(&sg, uap->gidsetsize * - sizeof(ibcs2_gid_t)); + ngrp = MIN(uap->gidsetsize, NGROUPS_MAX); + error = kern_getgroups(td, &ngrp, gp); + if (error) + return (error); + if (uap->gidsetsize > 0) { + for (i = 0; i < ngrp; i++) + iset[i] = (ibcs2_gid_t)gp[i]; + error = copyout(iset, uap->gidset, ngrp * sizeof(ibcs2_gid_t)); } - if ((error = getgroups(td, &sa)) != 0) - return error; - if (uap->gidsetsize == 0) - return 0; - - for (i = 0, gp = sa.gidset; i < td->td_retval[0]; i++) - iset[i] = (ibcs2_gid_t)*gp++; - if (td->td_retval[0] && (error = copyout((caddr_t)iset, - (caddr_t)uap->gidset, - sizeof(ibcs2_gid_t) * td->td_retval[0]))) - return error; - return 0; + if (error == 0) + td->td_retval[0] = ngrp; + return (error); } int @@ -687,28 +677,21 @@ ibcs2_setgroups(td, uap) struct thread *td; struct ibcs2_setgroups_args *uap; { + ibcs2_gid_t iset[NGROUPS_MAX]; + gid_t gp[NGROUPS_MAX]; int error, i; - ibcs2_gid_t *iset; - struct setgroups_args sa; - gid_t *gp; - caddr_t sg = stackgap_init(); if (uap->gidsetsize < 0 || uap->gidsetsize > NGROUPS_MAX) return (EINVAL); - sa.gidsetsize = uap->gidsetsize; - sa.gidset = stackgap_alloc(&sg, sa.gidsetsize * - sizeof(gid_t *)); - iset = stackgap_alloc(&sg, sa.gidsetsize * - sizeof(ibcs2_gid_t *)); - if (sa.gidsetsize) { - if ((error = copyin((caddr_t)uap->gidset, (caddr_t)iset, - sizeof(ibcs2_gid_t *) * - uap->gidsetsize)) != 0) - return error; + if (uap->gidsetsize && uap->gidset) { + error = copyin(uap->gidset, iset, sizeof(ibcs2_gid_t) * + uap->gidsetsize); + if (error) + return (error); + for (i = 0; i < uap->gidsetsize; i++) + gp[i] = (gid_t)iset[i]; } - for (i = 0, gp = sa.gidset; i < sa.gidsetsize; i++) - *gp++ = (gid_t)iset[i]; - return setgroups(td, &sa); + return (kern_setgroups(td, uap->gidsetsize, gp)); } int diff --git a/sys/i386/ibcs2/syscalls.xenix b/sys/i386/ibcs2/syscalls.xenix index ae8be83..8b9b84a 100644 --- a/sys/i386/ibcs2/syscalls.xenix +++ b/sys/i386/ibcs2/syscalls.xenix @@ -56,9 +56,9 @@ ibcs2_sigset_t *oset); } 41 AUE_NULL MSTD { int ibcs2_sigpending(ibcs2_sigset_t *mask); } 42 AUE_NULL MSTD { int ibcs2_sigsuspend(ibcs2_sigset_t *mask); } -43 AUE_GETGROUPS STD { int ibcs2_getgroups(int gidsetsize, \ +43 AUE_GETGROUPS MSTD { int ibcs2_getgroups(int gidsetsize, \ ibcs2_gid_t *gidset); } -44 AUE_SETGROUPS STD { int ibcs2_setgroups(int gidsetsize, \ +44 AUE_SETGROUPS MSTD { int ibcs2_setgroups(int gidsetsize, \ ibcs2_gid_t *gidset); } 45 AUE_NULL MSTD { int ibcs2_sysconf(int name); } 46 AUE_PATHCONF MSTD { int ibcs2_pathconf(char *path, int name); } |