PERFORCE change 100233 for review

John Baldwin jhb at FreeBSD.org
Wed Jun 28 21:08:47 UTC 2006


http://perforce.freebsd.org/chv.cgi?CH=100233

Change 100233 by jhb at jhb_mutex on 2006/06/28 21:07:46

	Add a kern_getgroups() for ibcs2.

Affected files ...

.. //depot/projects/smpng/sys/i386/ibcs2/ibcs2_misc.c#23 edit
.. //depot/projects/smpng/sys/kern/kern_prot.c#92 edit
.. //depot/projects/smpng/sys/sys/syscallsubr.h#36 edit

Differences ...

==== //depot/projects/smpng/sys/i386/ibcs2/ibcs2_misc.c#23 (text+ko) ====

@@ -651,35 +651,31 @@
 	struct thread *td;
 	struct ibcs2_getgroups_args *uap;
 {
+	ibcs2_gid_t *iset;
+	gid_t *gp;
 	int error, i;
-	ibcs2_gid_t *iset = NULL;
-	struct getgroups_args sa;
-	gid_t *gp;
-	caddr_t sg = stackgap_init();
 
 	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));
+	if (uap->gidsetsize)
+		gp = malloc(uap->gidsetsize * sizeof(gid_t), M_TEMP, M_WAITOK);
+	else
+		gp = NULL;
+
+	error = kern_getgroups(td, uap->gidsetsize, gp, UIO_SYSSPACE);
+	if (error == 0 && gp != NULL && td->td_retval[0] > 0) {
+		iset = malloc(td->td_retval[0] * sizeof(ibcs2_gid_t), M_TEMP,
+		    M_WAITOK);
+		for (i = 0; i < td->td_retval[0]; i++)
+			iset[i] = (ibcs2_gid_t)gp[i];
+		error = copyout(iset, uap->gidset, td->td_retval[0] *
+		    sizeof(ibcs2_gid_t));
+		free(iset, M_TEMP);
 	}
-	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;
+	free(gp, M_TEMP);
+	return (error);
 }
 
 int

==== //depot/projects/smpng/sys/kern/kern_prot.c#92 (text+ko) ====

@@ -63,7 +63,9 @@
 #include <sys/resourcevar.h>
 #include <sys/socket.h>
 #include <sys/socketvar.h>
+#include <sys/syscallsubr.h>
 #include <sys/sysctl.h>
+#include <sys/uio.h>
 
 #include <security/audit/audit.h>
 
@@ -297,19 +299,32 @@
 int
 getgroups(struct thread *td, register struct getgroups_args *uap)
 {
+	return (kern_getgroups(td, uap->gidsetsize, uap->gidset,
+	    UIO_USERSPACE));
+}
+
+int
+kern_getgroups(struct thread *td, u_int gidsetsize, gid_t *gidset,
+    enum uio_seg gidsetseg)
+{
 	struct ucred *cred;
 	u_int ngrp;
 	int error;
 
 	cred = td->td_ucred;
-	if ((ngrp = uap->gidsetsize) == 0) {
+	if ((ngrp = gidsetsize) == 0) {
 		td->td_retval[0] = cred->cr_ngroups;
 		return (0);
 	}
 	if (ngrp < cred->cr_ngroups)
 		return (EINVAL);
 	ngrp = cred->cr_ngroups;
-	error = copyout(cred->cr_groups, uap->gidset, ngrp * sizeof(gid_t));
+	if (gidsetseg == UIO_USERSPACE)
+		error = copyout(cred->cr_groups, gidset, ngrp * sizeof(gid_t));
+	else {
+		bcopy(cred->cr_groups, gidset, ngrp * sizeof(gid_t));
+		error = 0;
+	}
 	if (error == 0)
 		td->td_retval[0] = ngrp;
 	return (error);

==== //depot/projects/smpng/sys/sys/syscallsubr.h#36 (text+ko) ====

@@ -83,6 +83,8 @@
 	    enum uio_seg tptrseg);
 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 gidsetsize, gid_t *gidset,
+	    enum uio_seg gidsetseg);
 int	kern_getitimer(struct thread *, u_int, struct itimerval *);
 int	kern_getpeername(struct thread *td, int fd, struct sockaddr **sa,
 	    socklen_t *alen);


More information about the p4-projects mailing list