Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 16 May 2009 18:42:18 +0000 (UTC)
From:      Dmitry Chagin <dchagin@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r192203 - head/sys/compat/linux
Message-ID:  <200905161842.n4GIgIbY066612@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dchagin
Date: Sat May 16 18:42:18 2009
New Revision: 192203
URL: http://svn.freebsd.org/changeset/base/192203

Log:
  Emulate SO_PEERCRED socket option.
  Temporarily use 0 for pid member as the FreeBSD does not cache remote
  UNIX domain socket peer pid.
  
  PR:		kern/102956
  Reviewed by:	rwatson
  Approved by:	kib (mentor)
  MFC after:	1 month

Modified:
  head/sys/compat/linux/linux_socket.c
  head/sys/compat/linux/linux_socket.h

Modified: head/sys/compat/linux/linux_socket.c
==============================================================================
--- head/sys/compat/linux/linux_socket.c	Sat May 16 18:08:28 2009	(r192202)
+++ head/sys/compat/linux/linux_socket.c	Sat May 16 18:42:18 2009	(r192203)
@@ -1354,7 +1354,9 @@ linux_getsockopt(struct thread *td, stru
 	} */ bsd_args;
 	l_timeval linux_tv;
 	struct timeval tv;
-	socklen_t tv_len;
+	socklen_t tv_len, xulen;
+	struct xucred xu;
+	struct l_ucred lxu;
 	int error, name;
 
 	bsd_args.s = args->s;
@@ -1377,6 +1379,23 @@ linux_getsockopt(struct thread *td, stru
 			    sizeof(linux_tv)));
 			/* NOTREACHED */
 			break;
+		case LOCAL_PEERCRED:
+			if (args->optlen != sizeof(lxu))
+				return (EINVAL);
+			xulen = sizeof(xu);
+			error = kern_getsockopt(td, args->s, bsd_args.level,
+			    name, &xu, UIO_SYSSPACE, &xulen);
+			if (error)
+				return (error);
+			/*
+			 * XXX Use 0 for pid as the FreeBSD does not cache peer pid.
+			 */
+			lxu.pid = 0;
+			lxu.uid = xu.cr_uid;
+			lxu.gid = xu.cr_gid;
+			return (copyout(&lxu, PTRIN(args->optval), sizeof(lxu)));
+			/* NOTREACHED */
+			break;
 		default:
 			break;
 		}

Modified: head/sys/compat/linux/linux_socket.h
==============================================================================
--- head/sys/compat/linux/linux_socket.h	Sat May 16 18:08:28 2009	(r192202)
+++ head/sys/compat/linux/linux_socket.h	Sat May 16 18:42:18 2009	(r192203)
@@ -90,4 +90,10 @@
 #define	LINUX_AF_APPLETALK	5
 #define	LINUX_AF_INET6		10
 
+struct l_ucred {
+	uint32_t	pid;
+	uint32_t	uid;
+	uint32_t	gid;
+};
+
 #endif /* _LINUX_SOCKET_H_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200905161842.n4GIgIbY066612>