Skip to content

Commit 7308e00

Browse files
alarixniagrooverdan
authored andcommitted
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.
1 parent 2db692f commit 7308e00

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

plugin/auth_socket/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@ IF (HAVE_XUCRED)
5757
SET(ok 1)
5858
ELSE()
5959

60+
# NetBSD, is that you?
61+
CHECK_CXX_SOURCE_COMPILES(
62+
"#include <sys/un.h>
63+
#include <sys/socket.h>
64+
int main() {
65+
struct unpcbid unp;
66+
socklen_t unpl = sizeof(unp);
67+
getsockopt(0, 0, LOCAL_PEEREID, &unp, &unpl);
68+
}" HAVE_UNPCBID)
69+
70+
IF (HAVE_UNPCBID)
71+
ADD_DEFINITIONS(-DHAVE_UNPCBID)
72+
SET(ok 1)
73+
ELSE()
74+
6075
# illumos, is that you?
6176
CHECK_CXX_SOURCE_COMPILES(
6277
"#include <ucred.h>
@@ -104,6 +119,7 @@ ENDIF()
104119
ENDIF()
105120
ENDIF()
106121
ENDIF()
122+
ENDIF()
107123

108124
IF(ok)
109125
MYSQL_ADD_PLUGIN(auth_socket auth_socket.c DEFAULT)

plugin/auth_socket/auth_socket.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@
4747
#define uid cr_uid
4848
#define ucred xucred
4949

50+
#elif defined HAVE_UNPCBID
51+
#include <sys/un.h>
52+
#define level 0
53+
#define SO_PEERCRED LOCAL_PEEREID
54+
#define uid unp_euid
55+
#define ucred unpcbid
56+
5057
#elif defined HAVE_GETPEERUCRED
5158
#include <ucred.h>
5259

0 commit comments

Comments
 (0)