[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bug#768140: torsocks: FTBFS on kfreebsd-*



intrigeri@debian.org wrote:
> The fix for #766306 makes torsocks FTBFS on kfreebsd-*:
>   https://buildd.debian.org/status/package.php?p=torsocks

Hi,

SO_DOMAIN was only accepted into POSIX earlier this year:
http://austingroupbugs.net/view.php?id=840
it seems to be only available yet on Linux and Solaris.

For FreeBSD I came up with the attached, hackish workaround
using SO_TYPE (widely available), and out of the available
protocols in PF_LOCAL (= AF_UNIX), assume that only
SOCK_{DGRAM,SEQPACKET,STREAM} are candidates for fd passing.

Perhaps someone has a better idea?

Regards,
-- 
Steven Chamberlain
steven@pyro.eu.org
--- a/src/lib/recv.c
+++ b/src/lib/recv.c
@@ -60,7 +60,11 @@
  */
 LIBC_RECVMSG_RET_TYPE tsocks_recvmsg(LIBC_RECVMSG_SIG)
 {
+#ifdef SO_DOMAIN
 	int sock_domain;
+#else
+	int sock_type;
+#endif
 	socklen_t optlen;
 	ssize_t ret = 0;
 	char dummy, recv_fd[CMSG_SPACE(SCM_MAX_FD)];
@@ -68,6 +72,7 @@
 	struct cmsghdr *cmsg;
 	struct msghdr msg_hdr;
 
+#ifdef SO_DOMAIN
 	/* Don't bother if the socket family is NOT Unix. */
 	optlen = sizeof(sock_domain);
 	ret = getsockopt(sockfd, SOL_SOCKET, SO_DOMAIN, &sock_domain, &optlen);
@@ -79,6 +84,21 @@
 	if (sock_domain != AF_UNIX) {
 		goto libc;
 	}
+#else
+	/* Don't bother if the socket type unsuitable for fd passing */
+	optlen = sizeof(sock_type);
+	ret = getsockopt(sockfd, SOL_SOCKET, SO_TYPE, &sock_type, &optlen);
+	if (ret < 0) {
+		DBG("[recvmsg] Fail getsockopt() on sock %d", sockfd);
+		errno = EBADF;
+		goto error;
+	}
+	if (sock_type != SOCK_DGRAM &&
+	    sock_type != SOCK_SEQPACKET &&
+	    sock_type != SOCK_STREAM) {
+		goto libc;
+	}
+#endif
 
 	memset(&msg_hdr, 0, sizeof(msg_hdr));
 

Reply to: