[Box Backup-commit] COMMIT r2348 - in box/trunk: . lib/common lib/server

boxbackup-dev@boxbackup.org boxbackup-dev@boxbackup.org
Sat, 11 Oct 2008 22:01:38 +0100 (BST)


Author: chris
Date: 2008-10-11 22:01:38 +0100 (Sat, 11 Oct 2008)
New Revision: 2348

Modified:
   box/trunk/configure.ac
   box/trunk/lib/common/BoxPlatform.h
   box/trunk/lib/server/SocketStream.cpp
Log:
Use getpeerucred() to identify connecting socket clients on Solaris,
and silence warnings that the peer cannot be identified on this
platform.

Remove another use of uname -o which doesn't work on Solaris.


Modified: box/trunk/configure.ac
===================================================================
--- box/trunk/configure.ac	2008-10-11 21:00:18 UTC (rev 2347)
+++ box/trunk/configure.ac	2008-10-11 21:01:38 UTC (rev 2348)
@@ -182,6 +182,10 @@
 AC_CHECK_DECLS([SO_PEERCRED],,, [[#include <sys/socket.h>]])
 AC_CHECK_DECLS([O_BINARY],,,)
 
+# Solaris provides getpeerucred() instead of getpeereid() or SO_PEERCRED
+AC_CHECK_HEADERS([ucred.h])
+AC_CHECK_FUNCS([getpeerucred])
+
 AC_CHECK_DECLS([optreset],,, [[#include <getopt.h>]])
 AC_CHECK_DECLS([dirfd],,,
 	[[
@@ -311,10 +315,9 @@
 build_dir=`cd $build_dir && pwd`
 client_parcel_dir=`perl infrastructure/parcelpath.pl backup-client $target_os`
 
-os_name=`uname -o`
-if test "$os_name" = "Cygwin"; then
+if test "$build_os" = "cygwin"; then
 	client_parcel_dir=`cygpath -wa $client_parcel_dir | sed -e 's|\\\|/|g'`
-	build_dir=`cygpath -wa $build_dir | sed -e 's|\\\|/|g'`
+	build_dir=`        cygpath -wa $build_dir         | sed -e 's|\\\|/|g'`
 fi
 
 AC_SUBST([client_parcel_dir])

Modified: box/trunk/lib/common/BoxPlatform.h
===================================================================
--- box/trunk/lib/common/BoxPlatform.h	2008-10-11 21:00:18 UTC (rev 2347)
+++ box/trunk/lib/common/BoxPlatform.h	2008-10-11 21:01:38 UTC (rev 2348)
@@ -72,10 +72,14 @@
 #endif
 
 // Find out if credentials on UNIX sockets can be obtained
-#ifndef HAVE_GETPEEREID
-	#if !HAVE_DECL_SO_PEERCRED
-		#define PLATFORM_CANNOT_FIND_PEER_UID_OF_UNIX_SOCKET
-	#endif
+#ifdef HAVE_GETPEEREID
+	//
+#elif HAVE_DECL_SO_PEERCRED
+	//
+#elif HAVE_UCRED_H && HAVE_GETPEERUCRED
+	//
+#else
+	#define PLATFORM_CANNOT_FIND_PEER_UID_OF_UNIX_SOCKET
 #endif
 
 #ifdef HAVE_DEFINE_PRAGMA

Modified: box/trunk/lib/server/SocketStream.cpp
===================================================================
--- box/trunk/lib/server/SocketStream.cpp	2008-10-11 21:00:18 UTC (rev 2347)
+++ box/trunk/lib/server/SocketStream.cpp	2008-10-11 21:01:38 UTC (rev 2348)
@@ -18,9 +18,13 @@
 #include <string.h>
 
 #ifndef WIN32
-#include <poll.h>
+	#include <poll.h>
 #endif
 
+#ifdef HAVE_UCRED_H
+	#include <ucred.h>
+#endif
+
 #include "SocketStream.h"
 #include "ServerException.h"
 #include "CommonException.h"
@@ -478,10 +482,26 @@
 	BOX_LOG_SYS_ERROR("Failed to get peer credentials on socket");
 #endif
 
+#if HAVE_UCRED_H && HAVE_GETPEERUCRED
+	ucred_t *pucred = NULL;
+	if(::getpeerucred(mSocketHandle, &pucred) == 0)
+	{
+		rUidOut = ucred_geteuid(pucred);
+		rGidOut = ucred_getegid(pucred);
+		ucred_free(pucred);
+		if (rUidOut == -1 || rGidOut == -1)
+		{
+			BOX_ERROR("Failed to get peer credentials on "
+				"socket: insufficient information");
+			return false;
+		}
+		return true;
+	}
+
+	BOX_LOG_SYS_ERROR("Failed to get peer credentials on socket");
+#endif
+
 	// Not available
 	return false;
 }
 
-
-
-