summaryrefslogtreecommitdiffstats
path: root/dcop
diff options
context:
space:
mode:
authorOBATA Akio <obache@wizdas.com>2020-08-12 17:29:38 +0900
committerMichele Calgaro <michele.calgaro@yahoo.it>2020-08-12 22:57:27 +0900
commit93c6d3795f061cd93f255c8a3156d880be4bd84d (patch)
tree490769bae92b4805e4ad949b9edd56fd092c84a3 /dcop
parentc136ff9700242052ed5125baf07072707df0453f (diff)
downloadtdelibs-93c6d3795f061cd93f255c8a3156d880be4bd84d.tar.gz
tdelibs-93c6d3795f061cd93f255c8a3156d880be4bd84d.zip
Add LOCAL_PEEREID sockopt support for peer socket uid check
It is supported on NetBSD 5 and later. Signed-off-by: OBATA Akio <obache@wizdas.com> (cherry picked from commit 7827038ab45c300b86bee1b9fb6cf0f78461c0e7)
Diffstat (limited to 'dcop')
-rw-r--r--dcop/dcopclient.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/dcop/dcopclient.cpp b/dcop/dcopclient.cpp
index cfa912362..5dff084af 100644
--- a/dcop/dcopclient.cpp
+++ b/dcop/dcopclient.cpp
@@ -41,6 +41,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <sys/stat.h>
#include <sys/file.h>
#include <sys/socket.h>
+#include <sys/un.h>
#include <fcntl.h>
#include <unistd.h>
@@ -713,10 +714,12 @@ bool DCOPClient::isSuspended() const
return !d->notifier->isEnabled();
}
-#ifdef SO_PEERCRED
+#if defined(SO_PEERCRED) || defined(LOCAL_PEEREID)
+#define USE_PEER_IS_US
// Check whether the remote end is owned by the same user.
static bool peerIsUs(int sockfd)
{
+#ifdef SO_PEERCRED
#if defined(__OpenBSD__)
struct sockpeercred cred;
#else
@@ -726,6 +729,13 @@ static bool peerIsUs(int sockfd)
if (getsockopt(sockfd, SOL_SOCKET, SO_PEERCRED, &cred, &siz) != 0)
return false;
return (cred.uid == getuid());
+#elif defined LOCAL_PEEREID
+ struct unpcbid cred;
+ socklen_t siz = sizeof(cred);
+ if (getsockopt(sockfd, 0, LOCAL_PEEREID, &cred, &siz) != 0 || siz != sizeof(cred))
+ return false;
+ return (cred.unp_euid == geteuid());
+#endif
}
#else
// Check whether the socket is owned by the same user.
@@ -871,7 +881,7 @@ bool DCOPClient::attachInternal( bool registerAsAnonymous )
return false;
}
-#ifdef SO_PEERCRED
+#ifdef USE_PEER_IS_US
d->foreign_server = !peerIsUs(socket());
#else
d->foreign_server = !isServerSocketOwnedByUser(d->serverAddr);