summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/common/BoxPlatform.h12
-rw-r--r--lib/server/SocketStream.cpp28
2 files changed, 32 insertions, 8 deletions
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 <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;
}
-
-
-