From 7308e009c9c2161fa4d3f5532104c7da53e5ac27 Mon Sep 17 00:00:00 2001 From: nia Date: Wed, 4 Aug 2021 15:32:31 +0200 Subject: [PATCH] auth_socket: Add SO_PEERCRED definitions for NetBSD A getsockopt level of 0 is requied on NetBSD when using Unix-domain socket LOCAL_* options, SOL_SOCKET will not work. --- plugin/auth_socket/CMakeLists.txt | 16 ++++++++++++++++ plugin/auth_socket/auth_socket.c | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/plugin/auth_socket/CMakeLists.txt b/plugin/auth_socket/CMakeLists.txt index a3f42d416a7..7f44b3ff37a 100644 --- a/plugin/auth_socket/CMakeLists.txt +++ b/plugin/auth_socket/CMakeLists.txt @@ -57,6 +57,21 @@ IF (HAVE_XUCRED) SET(ok 1) ELSE() +# NetBSD, is that you? +CHECK_CXX_SOURCE_COMPILES( +"#include +#include +int main() { + struct unpcbid unp; + socklen_t unpl = sizeof(unp); + getsockopt(0, 0, LOCAL_PEEREID, &unp, &unpl); + }" HAVE_UNPCBID) + +IF (HAVE_UNPCBID) + ADD_DEFINITIONS(-DHAVE_UNPCBID) + SET(ok 1) +ELSE() + # illumos, is that you? CHECK_CXX_SOURCE_COMPILES( "#include @@ -104,6 +119,7 @@ ENDIF() ENDIF() ENDIF() ENDIF() +ENDIF() IF(ok) MYSQL_ADD_PLUGIN(auth_socket auth_socket.c DEFAULT) diff --git a/plugin/auth_socket/auth_socket.c b/plugin/auth_socket/auth_socket.c index c20defed872..3a933b6ab62 100644 --- a/plugin/auth_socket/auth_socket.c +++ b/plugin/auth_socket/auth_socket.c @@ -47,6 +47,13 @@ #define uid cr_uid #define ucred xucred +#elif defined HAVE_UNPCBID +#include +#define level 0 +#define SO_PEERCRED LOCAL_PEEREID +#define uid unp_euid +#define ucred unpcbid + #elif defined HAVE_GETPEERUCRED #include