diff options
-rw-r--r-- | configure.ac | 9 | ||||
-rw-r--r-- | lib/common/BoxPlatform.h | 12 | ||||
-rw-r--r-- | lib/server/SocketStream.cpp | 28 |
3 files changed, 38 insertions, 11 deletions
diff --git a/configure.ac b/configure.ac index d83c601c..e7f2f8fa 100644 --- a/configure.ac +++ b/configure.ac @@ -182,6 +182,10 @@ AC_CHECK_DECLS([INFTIM],,, [[#include <poll.h>]]) 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=`dirname $0` 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]) 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; } - - - |