diff options
author | Chris Wilson <chris+github@qwirx.com> | 2008-10-11 21:01:38 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2008-10-11 21:01:38 +0000 |
commit | ec5d4ab2b2cf334240673ca918ed1240a6dfb4b8 (patch) | |
tree | bfb4d5297246408480d7d6f7ebb062a8237eed5d /lib/server/SocketStream.cpp | |
parent | 23221c54b485a4b7625d43987ba44cf2278a4f12 (diff) |
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.
Diffstat (limited to 'lib/server/SocketStream.cpp')
-rw-r--r-- | lib/server/SocketStream.cpp | 28 |
1 files changed, 24 insertions, 4 deletions
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 <string.h> #ifndef WIN32 -#include <poll.h> + #include <poll.h> +#endif + +#ifdef HAVE_UCRED_H + #include <ucred.h> #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; } - - - |