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/server/SocketStream.cpp | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'lib/server/SocketStream.cpp') 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