diff options
author | Chris Wilson <chris+github@qwirx.com> | 2014-12-06 15:03:40 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2014-12-06 15:03:40 +0000 |
commit | f3a1ce8af043dbdc9240df76f69424c20446e2a5 (patch) | |
tree | 095f57ccb104e7536febcedd7f62676d397c5c98 /lib/server | |
parent | 9ce77cc16d4a8aeb72ec0dc925966e11c85a985e (diff) |
Add support for getsockopt(SO_PEERCRED) on OpenBSD 5.2.
OpenBSD requires different headers to be included, including a bug which
makes it essential to include sys/param.h before sys/ucred.h, and gives the
fields of struct ucred different names than Linux does.
This fixes compilation on OpenBSD and allows the user connecting to a UNIX
socket to be checked, increasing security of the command socket on this
platform.
Diffstat (limited to 'lib/server')
-rw-r--r-- | lib/server/SocketStream.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/server/SocketStream.cpp b/lib/server/SocketStream.cpp index ab0a54ae..22ca1551 100644 --- a/lib/server/SocketStream.cpp +++ b/lib/server/SocketStream.cpp @@ -29,6 +29,14 @@ #include <bsd/unistd.h> #endif +#ifdef HAVE_SYS_PARAM_H + #include <sys/param.h> +#endif + +#ifdef HAVE_SYS_UCRED_H + #include <sys/ucred.h> +#endif + #include "autogen_ConnectionException.h" #include "autogen_ServerException.h" #include "SocketStream.h" @@ -511,8 +519,13 @@ bool SocketStream::GetPeerCredentials(uid_t &rUidOut, gid_t &rGidOut) if(::getsockopt(mSocketHandle, SOL_SOCKET, SO_PEERCRED, &cred, &credLen) == 0) { +#ifdef HAVE_STRUCT_CRED_UID rUidOut = cred.uid; rGidOut = cred.gid; +#else // HAVE_STRUCT_CRED_CR_UID + rUidOut = cred.cr_uid; + rGidOut = cred.cr_gid; +#endif return true; } |