From ec5d4ab2b2cf334240673ca918ed1240a6dfb4b8 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 11 Oct 2008 21:01:38 +0000 Subject: 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. --- lib/common/BoxPlatform.h | 12 ++++++++---- lib/server/SocketStream.cpp | 28 ++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/common/BoxPlatform.h b/lib/common/BoxPlatform.h index 3af893b7..4f7a587c 100644 --- a/lib/common/BoxPlatform.h +++ b/lib/common/BoxPlatform.h @@ -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 diff --git a/lib/server/SocketStream.cpp b/lib/server/SocketStream.cpp index a6f99dad..d6565984 100644 --- a/lib/server/SocketStream.cpp +++ b/lib/server/SocketStream.cpp @@ -18,7 +18,11 @@ #include #ifndef WIN32 -#include + #include +#endif + +#ifdef HAVE_UCRED_H + #include #endif #include "SocketStream.h" @@ -478,10 +482,26 @@ bool SocketStream::GetPeerCredentials(uid_t &rUidOut, gid_t &rGidOut) 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; } - - - -- cgit v1.2.3