[Box Backup-commit] COMMIT r3437 - in box/trunk: infrastructure/m4 lib/server

subversion at boxbackup.org subversion at boxbackup.org
Sat Dec 6 15:03:40 GMT 2014


Author: chris
Date: 2014-12-06 15:03:40 +0000 (Sat, 06 Dec 2014)
New Revision: 3437

Modified:
   box/trunk/infrastructure/m4/boxbackup_tests.m4
   box/trunk/lib/server/SocketStream.cpp
Log:
Add support for getsockopt(SO_PEERCRED) on OpenBSD 5.2.

OpenBSD requires different headers to be included, including a bug which
makes it essential to include sys/param.h before sys/ucred.h, and gives the
fields of struct ucred different names than Linux does.

This fixes compilation on OpenBSD and allows the user connecting to a UNIX
socket to be checked, increasing security of the command socket on this
platform.


Modified: box/trunk/infrastructure/m4/boxbackup_tests.m4
===================================================================
--- box/trunk/infrastructure/m4/boxbackup_tests.m4	2014-12-06 12:56:03 UTC (rev 3436)
+++ box/trunk/infrastructure/m4/boxbackup_tests.m4	2014-12-06 15:03:40 UTC (rev 3437)
@@ -138,6 +138,11 @@
 AC_CHECK_HEADERS([netinet/in.h netinet/tcp.h])
 AC_CHECK_HEADERS([sys/file.h sys/param.h sys/poll.h sys/socket.h sys/time.h])
 AC_CHECK_HEADERS([sys/types.h sys/uio.h sys/un.h sys/wait.h sys/xattr.h])
+AC_CHECK_HEADERS([sys/ucred.h],,, [
+	#ifdef HAVE_SYS_PARAM_H
+	#	include <sys/param.h>
+	#endif
+	])
 AC_CHECK_HEADERS([bsd/unistd.h])
 AC_CHECK_HEADERS([sys/socket.h], [have_sys_socket_h=yes])
 AC_CHECK_HEADERS([winsock2.h], [have_winsock2_h=yes])
@@ -217,7 +222,21 @@
 # Solaris provides getpeerucred() instead of getpeereid() or SO_PEERCRED
 AC_CHECK_HEADERS([ucred.h])
 AC_CHECK_FUNCS([getpeerucred])
+AC_CHECK_MEMBERS([struct ucred.uid, struct ucred.cr_uid],,,
+	[[
+		#ifdef HAVE_UCRED_H
+		#	include <ucred.h>
+		#endif
 
+		#ifdef HAVE_SYS_PARAM_H
+		#	include <sys/param.h>
+		#endif
+
+		#ifdef HAVE_SYS_UCRED_H
+		#	include <sys/ucred.h>
+		#endif
+	]])
+
 AC_CHECK_DECLS([optreset],,, [[#include <getopt.h>]])
 AC_CHECK_DECLS([dirfd],,,
 	[[

Modified: box/trunk/lib/server/SocketStream.cpp
===================================================================
--- box/trunk/lib/server/SocketStream.cpp	2014-12-06 12:56:03 UTC (rev 3436)
+++ box/trunk/lib/server/SocketStream.cpp	2014-12-06 15:03:40 UTC (rev 3437)
@@ -29,6 +29,14 @@
 	#include <bsd/unistd.h>
 #endif
 
+#ifdef HAVE_SYS_PARAM_H
+	#include <sys/param.h>
+#endif
+
+#ifdef HAVE_SYS_UCRED_H
+	#include <sys/ucred.h>
+#endif
+
 #include "autogen_ConnectionException.h"
 #include "autogen_ServerException.h"
 #include "SocketStream.h"
@@ -511,8 +519,13 @@
 	if(::getsockopt(mSocketHandle, SOL_SOCKET, SO_PEERCRED, &cred,
 		&credLen) == 0)
 	{
+#ifdef HAVE_STRUCT_CRED_UID
 		rUidOut = cred.uid;
 		rGidOut = cred.gid;
+#else // HAVE_STRUCT_CRED_CR_UID
+		rUidOut = cred.cr_uid;
+		rGidOut = cred.cr_gid;
+#endif
 		return true;
 	}
 




More information about the Boxbackup-commit mailing list