Commit 638075e5 authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-6577 auth_socket.so does not build in kFreeBSD

if it has to be a mess of ifdefs, then mess of ifdefs it is
parent 695781a5
......@@ -22,18 +22,49 @@ int main() {
getsockopt(0, SOL_SOCKET, SO_PEERCRED, &cred, 0);
}" HAVE_PEERCRED)
IF (NOT HAVE_PEERCRED)
# Hi, OpenBSD!
CHECK_CXX_SOURCE_COMPILES(
"#include <sys/types.h>
#include <sys/socket.h>
int main() {
struct sockpeercred cred;
getsockopt(0, SOL_SOCKET, SO_PEERCRED, &cred, 0);
}" HAVE_SOCKPEERCRED)
ADD_DEFINITIONS(-Ducred=sockpeercred)
IF (HAVE_PEERCRED)
ADD_DEFINITIONS(-DHAVE_PEERCRED)
SET(ok 1)
ELSE()
# Hi, OpenBSD!
CHECK_CXX_SOURCE_COMPILES(
"#include <sys/types.h>
#include <sys/socket.h>
int main() {
struct sockpeercred cred;
getsockopt(0, SOL_SOCKET, SO_PEERCRED, &cred, 0);
}" HAVE_SOCKPEERCRED)
IF (HAVE_SOCKPEERCRED)
ADD_DEFINITIONS(-DHAVE_SOCKPEERCRED)
SET(ok 1)
ELSE()
# FreeBSD, is that you?
CHECK_CXX_SOURCE_COMPILES(
"#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/ucred.h>
int main() {
struct xucred cred;
getsockopt(0, 0, LOCAL_PEERCRED, &cred, 0);
}" HAVE_XUCRED)
IF (HAVE_XUCRED)
ADD_DEFINITIONS(-DHAVE_XUCRED)
SET(ok 1)
ELSE()
# Who else? Anyone?
# C'mon, show your creativity, be different! ifdef's are fun, aren't they?
ENDIF()
ENDIF()
ENDIF()
IF(HAVE_PEERCRED OR HAVE_SOCKPEERCRED)
IF(ok)
MYSQL_ADD_PLUGIN(auth_socket auth_socket.c MODULE_ONLY)
ENDIF()
......@@ -27,9 +27,29 @@
#define _GNU_SOURCE 1 /* for struct ucred */
#include <mysql/plugin_auth.h>
#include <sys/socket.h>
#include <pwd.h>
#include <string.h>
#include <pwd.h>
#include <sys/socket.h>
#include <sys/types.h>
#ifdef HAVE_PEERCRED
#define level SOL_SOCKET
#elif defined HAVE_SOCKPEERCRED
#define level SOL_SOCKET
#define ucred socketpeercred
#elif defined HAVE_XUCRED
#include <sys/un.h>
#include <sys/ucred.h>
#define level 0
#define SO_PEERCRED LOCAL_PEERCRED
#define uid cr_uid
#define ucred xucred
#else
#error impossible
#endif
/**
perform the unix socket based authentication
......@@ -63,7 +83,7 @@ static int socket_auth(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info)
return CR_ERROR;
/* get the UID of the client process */
if (getsockopt(vio_info.socket, SOL_SOCKET, SO_PEERCRED, &cred, &cred_len))
if (getsockopt(vio_info.socket, level, SO_PEERCRED, &cred, &cred_len))
return CR_ERROR;
if (cred_len != sizeof(cred))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment