diff --git a/sys/i386/ibcs2/ibcs2_misc.c b/sys/i386/ibcs2/ibcs2_misc.c index 0eeb6de2d433..42bc4b775794 100644 --- a/sys/i386/ibcs2/ibcs2_misc.c +++ b/sys/i386/ibcs2/ibcs2_misc.c @@ -659,33 +659,28 @@ ibcs2_getgroups(td, uap) struct thread *td; struct ibcs2_getgroups_args *uap; { + struct ucred *cred; ibcs2_gid_t *iset; - gid_t *gp; u_int i, ngrp; int error; - if (uap->gidsetsize < td->td_ucred->cr_ngroups) { - if (uap->gidsetsize == 0) - ngrp = 0; - else - return (EINVAL); - } else - ngrp = td->td_ucred->cr_ngroups; - gp = malloc(ngrp * sizeof(*gp), M_TEMP, M_WAITOK); - error = kern_getgroups(td, &ngrp, gp); - if (error) + cred = td->td_ucred; + ngrp = cred->cr_ngroups; + + if (uap->gidsetsize == 0) { + error = 0; goto out; - if (uap->gidsetsize > 0) { - iset = malloc(ngrp * sizeof(*iset), M_TEMP, M_WAITOK); - for (i = 0; i < ngrp; i++) - iset[i] = (ibcs2_gid_t)gp[i]; - error = copyout(iset, uap->gidset, ngrp * sizeof(ibcs2_gid_t)); - free(iset, M_TEMP); } - if (error == 0) - td->td_retval[0] = ngrp; + if (uap->gidsetsize < ngrp) + return (EINVAL); + + iset = malloc(ngrp * sizeof(*iset), M_TEMP, M_WAITOK); + for (i = 0; i < ngrp; i++) + iset[i] = (ibcs2_gid_t)cred->cr_groups[i]; + error = copyout(iset, uap->gidset, ngrp * sizeof(ibcs2_gid_t)); + free(iset, M_TEMP); out: - free(gp, M_TEMP); + td->td_retval[0] = ngrp; return (error); } diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c index fd2b7f4021f8..f12468d83562 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -303,45 +303,24 @@ struct getgroups_args { int sys_getgroups(struct thread *td, register struct getgroups_args *uap) { - gid_t *groups; + struct ucred *cred; u_int ngrp; int error; - if (uap->gidsetsize < td->td_ucred->cr_ngroups) { - if (uap->gidsetsize == 0) - ngrp = 0; - else - return (EINVAL); - } else - ngrp = td->td_ucred->cr_ngroups; - groups = malloc(ngrp * sizeof(*groups), M_TEMP, M_WAITOK); - error = kern_getgroups(td, &ngrp, groups); - if (error) - goto out; - if (uap->gidsetsize > 0) - error = copyout(groups, uap->gidset, ngrp * sizeof(gid_t)); - if (error == 0) - td->td_retval[0] = ngrp; -out: - free(groups, M_TEMP); - return (error); -} - -int -kern_getgroups(struct thread *td, u_int *ngrp, gid_t *groups) -{ - struct ucred *cred; - cred = td->td_ucred; - if (*ngrp == 0) { - *ngrp = cred->cr_ngroups; - return (0); + ngrp = cred->cr_ngroups; + + if (uap->gidsetsize == 0) { + error = 0; + goto out; } - if (*ngrp < cred->cr_ngroups) + if (uap->gidsetsize < ngrp) return (EINVAL); - *ngrp = cred->cr_ngroups; - bcopy(cred->cr_groups, groups, *ngrp * sizeof(gid_t)); - return (0); + + error = copyout(cred->cr_groups, uap->gidset, ngrp * sizeof(gid_t)); +out: + td->td_retval[0] = ngrp; + return (error); } #ifndef _SYS_SYSPROTO_H_ diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h index 05e9be832f24..7098c43445a4 100644 --- a/sys/sys/syscallsubr.h +++ b/sys/sys/syscallsubr.h @@ -109,7 +109,6 @@ int kern_getdirentries(struct thread *td, int fd, char *buf, u_int count, long *basep, ssize_t *residp, enum uio_seg bufseg); int kern_getfsstat(struct thread *td, struct statfs **buf, size_t bufsize, enum uio_seg bufseg, int flags); -int kern_getgroups(struct thread *td, u_int *ngrp, gid_t *groups); int kern_getitimer(struct thread *, u_int, struct itimerval *); int kern_getppid(struct thread *); int kern_getpeername(struct thread *td, int fd, struct sockaddr **sa,