MXS-1842 Compile all authenticators as C++

Minimal changes, only what is needed to compile.
This commit is contained in:
Johan Wikman
2018-05-02 15:41:03 +03:00
parent aa1c956aa7
commit eba6c0c596
23 changed files with 68 additions and 31 deletions

View File

@ -1,4 +1,4 @@
add_library(cdcplainauth SHARED cdc_plain_auth.c) add_library(cdcplainauth SHARED cdc_plain_auth.cc)
target_link_libraries(cdcplainauth maxscale-common) target_link_libraries(cdcplainauth maxscale-common)
set_target_properties(cdcplainauth PROPERTIES VERSION "1.0.0") set_target_properties(cdcplainauth PROPERTIES VERSION "1.0.0")
install_module(cdcplainauth core) install_module(cdcplainauth core)

View File

@ -107,7 +107,7 @@ static bool cdc_add_new_user(const MODULECMD_ARG *args, json_t** output)
if (fd != -1) if (fd != -1)
{ {
if (write(fd, final_data, sizeof(final_data)) == sizeof(final_data)) if (write(fd, final_data, sizeof(final_data)) == static_cast<int>(sizeof(final_data)))
{ {
MXS_NOTICE("Added user '%s' to service '%s'", user, service->name); MXS_NOTICE("Added user '%s' to service '%s'", user, service->name);
rval = true; rval = true;
@ -137,6 +137,8 @@ static bool cdc_add_new_user(const MODULECMD_ARG *args, json_t** output)
return rval; return rval;
} }
extern "C"
{
/** /**
* The module entry point routine. It is this routine that * The module entry point routine. It is this routine that
* must populate the structure that is referred to as the * must populate the structure that is referred to as the
@ -192,6 +194,8 @@ MXS_MODULE* MXS_CREATE_MODULE()
return &info; return &info;
} }
}
/** /**
* @brief Function to easily call authentication check. * @brief Function to easily call authentication check.
* *

View File

@ -3,11 +3,11 @@ if(BUILD_CDC)
endif() endif()
add_subdirectory(GSSAPI) add_subdirectory(GSSAPI)
add_subdirectory(PAM)
add_subdirectory(HTTPAuth) add_subdirectory(HTTPAuth)
add_subdirectory(MaxAdminAuth) add_subdirectory(MaxAdminAuth)
add_subdirectory(MySQLAuth) add_subdirectory(MySQLAuth)
add_subdirectory(MySQLBackendAuth) add_subdirectory(MySQLBackendAuth)
add_subdirectory(NullAuthAllow) add_subdirectory(NullAuthAllow)
add_subdirectory(NullAuthDeny) add_subdirectory(NullAuthDeny)
add_subdirectory(PAM)

View File

@ -1,4 +1,4 @@
add_library(gssapiauth SHARED gssapi_auth.c ../gssapi_auth_common.c) add_library(gssapiauth SHARED gssapi_auth.cc ../gssapi_auth_common.cc)
target_link_libraries(gssapiauth maxscale-common ${GSSAPI_LIBS} ${SQLITE_LIBRARIES} mysqlcommon) target_link_libraries(gssapiauth maxscale-common ${GSSAPI_LIBS} ${SQLITE_LIBRARIES} mysqlcommon)
set_target_properties(gssapiauth PROPERTIES VERSION "1.0.0") set_target_properties(gssapiauth PROPERTIES VERSION "1.0.0")
install_module(gssapiauth core) install_module(gssapiauth core)

View File

@ -106,7 +106,7 @@ typedef struct gssapi_instance
*/ */
void* gssapi_auth_init(char **options) void* gssapi_auth_init(char **options)
{ {
GSSAPI_INSTANCE *instance = MXS_MALLOC(sizeof(GSSAPI_INSTANCE)); GSSAPI_INSTANCE *instance = static_cast<GSSAPI_INSTANCE*>(MXS_MALLOC(sizeof(GSSAPI_INSTANCE)));
if (instance) if (instance)
{ {
@ -162,7 +162,7 @@ void* gssapi_auth_init(char **options)
void* gssapi_auth_alloc(void *instance) void* gssapi_auth_alloc(void *instance)
{ {
gssapi_auth_t* rval = MXS_MALLOC(sizeof(gssapi_auth_t)); gssapi_auth_t* rval = static_cast<gssapi_auth_t*>(MXS_MALLOC(sizeof(gssapi_auth_t)));
if (rval) if (rval)
{ {
@ -250,7 +250,7 @@ bool store_client_token(DCB *dcb, GWBUF *buffer)
size_t plen = gw_mysql_get_byte3(hdr); size_t plen = gw_mysql_get_byte3(hdr);
MYSQL_session *ses = (MYSQL_session*)dcb->data; MYSQL_session *ses = (MYSQL_session*)dcb->data;
if ((ses->auth_token = MXS_MALLOC(plen))) if ((ses->auth_token = static_cast<uint8_t*>(MXS_MALLOC(plen))))
{ {
gwbuf_copy_data(buffer, MYSQL_HEADER_LEN, plen, ses->auth_token); gwbuf_copy_data(buffer, MYSQL_HEADER_LEN, plen, ses->auth_token);
ses->auth_token_len = plen; ses->auth_token_len = plen;
@ -384,7 +384,7 @@ static bool validate_gssapi_token(char* principal, uint8_t* token, size_t len, c
return false; return false;
} }
char *princ_name = MXS_MALLOC(client_name.length + 1); char *princ_name = static_cast<char*>(MXS_MALLOC(client_name.length + 1));
if (!princ_name) if (!princ_name)
{ {
@ -515,7 +515,7 @@ void gssapi_auth_free_data(DCB *dcb)
{ {
if (dcb->data) if (dcb->data)
{ {
MYSQL_session *ses = dcb->data; MYSQL_session *ses = static_cast<MYSQL_session*>(dcb->data);
MXS_FREE(ses->auth_token); MXS_FREE(ses->auth_token);
MXS_FREE(ses); MXS_FREE(ses);
dcb->data = NULL; dcb->data = NULL;
@ -667,6 +667,8 @@ int gssapi_auth_load_users(SERV_LISTENER *listener)
return rval; return rval;
} }
extern "C"
{
/** /**
* Module handle entry point * Module handle entry point
*/ */
@ -705,3 +707,5 @@ MXS_MODULE* MXS_CREATE_MODULE()
return &info; return &info;
} }
}

View File

@ -1,4 +1,4 @@
add_library(gssapibackendauth SHARED gssapi_backend_auth.c ../gssapi_auth_common.c) add_library(gssapibackendauth SHARED gssapi_backend_auth.cc ../gssapi_auth_common.cc)
target_link_libraries(gssapibackendauth maxscale-common ${GSSAPI_LIBS} mysqlcommon) target_link_libraries(gssapibackendauth maxscale-common ${GSSAPI_LIBS} mysqlcommon)
set_target_properties(gssapibackendauth PROPERTIES VERSION "1.0.0") set_target_properties(gssapibackendauth PROPERTIES VERSION "1.0.0")
install_module(gssapibackendauth core) install_module(gssapibackendauth core)

View File

@ -28,7 +28,7 @@
void* gssapi_backend_auth_alloc(void *instance) void* gssapi_backend_auth_alloc(void *instance)
{ {
gssapi_auth_t* rval = MXS_MALLOC(sizeof(gssapi_auth_t)); gssapi_auth_t* rval = static_cast<gssapi_auth_t*>(MXS_MALLOC(sizeof(gssapi_auth_t)));
if (rval) if (rval)
{ {
@ -176,7 +176,7 @@ bool extract_principal_name(DCB *dcb, GWBUF *buffer)
if (buflen > 0) if (buflen > 0)
{ {
uint8_t *principal = MXS_MALLOC(buflen + 1); uint8_t *principal = static_cast<uint8_t*>(MXS_MALLOC(buflen + 1));
if (principal) if (principal)
{ {
@ -264,6 +264,8 @@ static int gssapi_backend_auth_authenticate(DCB *dcb)
return rval; return rval;
} }
extern "C"
{
/** /**
* Module handle entry point * Module handle entry point
*/ */
@ -302,3 +304,5 @@ MXS_MODULE* MXS_CREATE_MODULE()
return &info; return &info;
} }
}

View File

@ -1,4 +1,4 @@
add_library(httpauth SHARED http_auth.c) add_library(httpauth SHARED http_auth.cc)
target_link_libraries(httpauth maxscale-common) target_link_libraries(httpauth maxscale-common)
set_target_properties(httpauth PROPERTIES VERSION "1.0.0") set_target_properties(httpauth PROPERTIES VERSION "1.0.0")
install_module(httpauth core) install_module(httpauth core)

View File

@ -47,6 +47,8 @@ typedef struct http_auth
char* pw; char* pw;
} HTTP_AUTH; } HTTP_AUTH;
extern "C"
{
/** /**
* The module entry point routine. It is this routine that * The module entry point routine. It is this routine that
* must populate the structure that is referred to as the * must populate the structure that is referred to as the
@ -91,6 +93,7 @@ MXS_MODULE* MXS_CREATE_MODULE()
return &info; return &info;
} }
/*lint +e14 */ /*lint +e14 */
}
/** /**
* @brief Authentication of a user/password combination. * @brief Authentication of a user/password combination.
@ -153,7 +156,7 @@ http_auth_set_protocol_data(DCB *dcb, GWBUF *buf)
if (pw_start) if (pw_start)
{ {
*pw_start++ = '\0'; *pw_start++ = '\0';
HTTP_AUTH *ses = MXS_MALLOC(sizeof(*ses)); HTTP_AUTH *ses = static_cast<HTTP_AUTH*>(MXS_MALLOC(sizeof(*ses)));
char* user = MXS_STRDUP(outbuf); char* user = MXS_STRDUP(outbuf);
char* pw = MXS_STRDUP(pw_start); char* pw = MXS_STRDUP(pw_start);

View File

@ -1,4 +1,4 @@
add_library(maxadminauth SHARED max_admin_auth.c) add_library(maxadminauth SHARED max_admin_auth.cc)
target_link_libraries(maxadminauth maxscale-common) target_link_libraries(maxadminauth maxscale-common)
set_target_properties(maxadminauth PROPERTIES VERSION "1.0.0") set_target_properties(maxadminauth PROPERTIES VERSION "1.0.0")
install_module(maxadminauth core) install_module(maxadminauth core)

View File

@ -41,6 +41,8 @@ static bool max_admin_auth_is_client_ssl_capable(DCB *dcb);
static int max_admin_auth_authenticate(DCB *dcb); static int max_admin_auth_authenticate(DCB *dcb);
static void max_admin_auth_free_client_data(DCB *dcb); static void max_admin_auth_free_client_data(DCB *dcb);
extern "C"
{
/** /**
* The module entry point routine. It is this routine that * The module entry point routine. It is this routine that
* must populate the structure that is referred to as the * must populate the structure that is referred to as the
@ -85,6 +87,7 @@ MXS_MODULE* MXS_CREATE_MODULE()
return &info; return &info;
} }
/*lint +e14 */ /*lint +e14 */
}
/** /**
* @brief Authentication of a user/password combination. * @brief Authentication of a user/password combination.

View File

@ -1,7 +1,7 @@
if(SQLITE_VERSION VERSION_LESS 3.3) if(SQLITE_VERSION VERSION_LESS 3.3)
message(FATAL_ERROR "SQLite version 3.3 or higher is required") message(FATAL_ERROR "SQLite version 3.3 or higher is required")
else() else()
add_library(mysqlauth SHARED mysql_auth.c dbusers.c) add_library(mysqlauth SHARED mysql_auth.cc dbusers.cc)
target_link_libraries(mysqlauth maxscale-common mysqlcommon) target_link_libraries(mysqlauth maxscale-common mysqlcommon)
set_target_properties(mysqlauth PROPERTIES VERSION "1.0.0") set_target_properties(mysqlauth PROPERTIES VERSION "1.0.0")
install_module(mysqlauth core) install_module(mysqlauth core)

View File

@ -62,7 +62,7 @@ static char* get_new_users_query(const char *server_version, bool include_root)
const char *with_root = include_root ? "" : " AND u.user NOT IN ('root')"; const char *with_root = include_root ? "" : " AND u.user NOT IN ('root')";
size_t n_bytes = snprintf(NULL, 0, NEW_LOAD_DBUSERS_QUERY, password, with_root, password, with_root); size_t n_bytes = snprintf(NULL, 0, NEW_LOAD_DBUSERS_QUERY, password, with_root, password, with_root);
char *rval = MXS_MALLOC(n_bytes + 1); char *rval = static_cast<char*>(MXS_MALLOC(n_bytes + 1));
if (rval) if (rval)
{ {
@ -536,12 +536,12 @@ static bool check_server_permissions(SERVICE *service, SERVER* server,
mxs_mysql_set_server_version(mysql, server); mxs_mysql_set_server_version(mysql, server);
} }
const char *template = "SELECT user, host, %s, Select_priv FROM mysql.user limit 1"; const char* format = "SELECT user, host, %s, Select_priv FROM mysql.user limit 1";
const char* query_pw = strstr(server->version_string, "5.7.") ? const char* query_pw = strstr(server->version_string, "5.7.") ?
MYSQL57_PASSWORD : MYSQL_PASSWORD; MYSQL57_PASSWORD : MYSQL_PASSWORD;
char query[strlen(template) + strlen(query_pw) + 1]; char query[strlen(format) + strlen(query_pw) + 1];
bool rval = true; bool rval = true;
sprintf(query, template, query_pw); sprintf(query, format, query_pw);
if (mxs_mysql_query(mysql, query) != 0) if (mxs_mysql_query(mysql, query) != 0)
{ {

View File

@ -66,6 +66,9 @@ int mysql_auth_reauthenticate(DCB *dcb, const char *user,
uint8_t *token, size_t token_len, uint8_t *token, size_t token_len,
uint8_t *scramble, size_t scramble_len, uint8_t *scramble, size_t scramble_len,
uint8_t *output_token, size_t output_token_len); uint8_t *output_token, size_t output_token_len);
extern "C"
{
/** /**
* The module entry point routine. It is this routine that * The module entry point routine. It is this routine that
* must populate the structure that is referred to as the * must populate the structure that is referred to as the
@ -110,6 +113,8 @@ MXS_MODULE* MXS_CREATE_MODULE()
return &info; return &info;
} }
}
static bool open_instance_database(const char *path, sqlite3 **handle) static bool open_instance_database(const char *path, sqlite3 **handle)
{ {
int rc = sqlite3_open_v2(path, handle, db_flags, NULL); int rc = sqlite3_open_v2(path, handle, db_flags, NULL);
@ -170,9 +175,10 @@ static bool should_check_permissions(MYSQL_AUTH* instance)
*/ */
static void* mysql_auth_init(char **options) static void* mysql_auth_init(char **options)
{ {
MYSQL_AUTH *instance = MXS_MALLOC(sizeof(*instance)); MYSQL_AUTH *instance = static_cast<MYSQL_AUTH*>(MXS_MALLOC(sizeof(*instance)));
if (instance && (instance->handles = MXS_CALLOC(config_threadcount(), sizeof(sqlite3*)))) if (instance &&
(instance->handles = static_cast<sqlite3**>(MXS_CALLOC(config_threadcount(), sizeof(sqlite3*)))))
{ {
bool error = false; bool error = false;
instance->cache_dir = NULL; instance->cache_dir = NULL;
@ -404,7 +410,7 @@ mysql_auth_set_client_data(
MySQLProtocol *protocol, MySQLProtocol *protocol,
GWBUF *buffer) GWBUF *buffer)
{ {
size_t client_auth_packet_size = gwbuf_length(buffer); int client_auth_packet_size = gwbuf_length(buffer);
uint8_t client_auth_packet[client_auth_packet_size]; uint8_t client_auth_packet[client_auth_packet_size];
gwbuf_copy_data(buffer, 0, client_auth_packet_size, client_auth_packet); gwbuf_copy_data(buffer, 0, client_auth_packet_size, client_auth_packet);

View File

@ -1,4 +1,4 @@
add_library(mysqlbackendauth SHARED mysql_backend_auth.c) add_library(mysqlbackendauth SHARED mysql_backend_auth.cc)
target_link_libraries(mysqlbackendauth maxscale-common mysqlcommon) target_link_libraries(mysqlbackendauth maxscale-common mysqlcommon)
set_target_properties(mysqlbackendauth PROPERTIES VERSION "1.0.0") set_target_properties(mysqlbackendauth PROPERTIES VERSION "1.0.0")
install_module(mysqlbackendauth core) install_module(mysqlbackendauth core)

View File

@ -50,7 +50,7 @@ typedef struct mysql_backend_auth
*/ */
void* auth_backend_create(void *instance) void* auth_backend_create(void *instance)
{ {
mysql_backend_auth_t* mba = MXS_MALLOC(sizeof(*mba)); mysql_backend_auth_t* mba = static_cast<mysql_backend_auth_t*>(MXS_MALLOC(sizeof(*mba)));
if (mba) if (mba)
{ {
@ -143,6 +143,8 @@ static bool auth_backend_ssl(DCB *dcb)
return dcb->server->server_ssl != NULL; return dcb->server->server_ssl != NULL;
} }
extern "C"
{
/** /**
* The module entry point routine. It is this routine that * The module entry point routine. It is this routine that
* must populate the structure that is referred to as the * must populate the structure that is referred to as the
@ -189,3 +191,4 @@ MXS_MODULE* MXS_CREATE_MODULE()
return &info; return &info;
} }
/*lint +e14 */ /*lint +e14 */
}

View File

@ -1,4 +1,4 @@
add_library(nullauthallow SHARED null_auth_allow.c) add_library(nullauthallow SHARED null_auth_allow.cc)
target_link_libraries(nullauthallow maxscale-common mysqlcommon) target_link_libraries(nullauthallow maxscale-common mysqlcommon)
set_target_properties(nullauthallow PROPERTIES VERSION "1.0.0") set_target_properties(nullauthallow PROPERTIES VERSION "1.0.0")
install_module(nullauthallow core) install_module(nullauthallow core)

View File

@ -43,6 +43,8 @@ static bool null_auth_is_client_ssl_capable(DCB *dcb);
static int null_auth_authenticate(DCB *dcb); static int null_auth_authenticate(DCB *dcb);
static void null_auth_free_client_data(DCB *dcb); static void null_auth_free_client_data(DCB *dcb);
extern "C"
{
/** /**
* The module entry point routine. It is this routine that * The module entry point routine. It is this routine that
* must populate the structure that is referred to as the * must populate the structure that is referred to as the
@ -89,6 +91,7 @@ MXS_MODULE* MXS_CREATE_MODULE()
return &info; return &info;
} }
/*lint +e14 */ /*lint +e14 */
}
/** /**
* @brief Null authentication of a user. * @brief Null authentication of a user.

View File

@ -1,4 +1,4 @@
add_library(nullauthdeny SHARED null_auth_deny.c) add_library(nullauthdeny SHARED null_auth_deny.cc)
target_link_libraries(nullauthdeny maxscale-common) target_link_libraries(nullauthdeny maxscale-common)
set_target_properties(nullauthdeny PROPERTIES VERSION "1.0.0") set_target_properties(nullauthdeny PROPERTIES VERSION "1.0.0")
install_module(nullauthdeny core) install_module(nullauthdeny core)

View File

@ -40,6 +40,8 @@ static bool null_auth_is_client_ssl_capable(DCB *dcb);
static int null_auth_authenticate(DCB *dcb); static int null_auth_authenticate(DCB *dcb);
static void null_auth_free_client_data(DCB *dcb); static void null_auth_free_client_data(DCB *dcb);
extern "C"
{
/** /**
* The module entry point routine. It is this routine that * The module entry point routine. It is this routine that
* must populate the structure that is referred to as the * must populate the structure that is referred to as the
@ -86,6 +88,7 @@ MXS_MODULE* MXS_CREATE_MODULE()
return &info; return &info;
} }
/*lint +e14 */ /*lint +e14 */
}
/** /**
* @brief Null authentication of a user. * @brief Null authentication of a user.

View File

@ -152,7 +152,8 @@ static json_t* pam_auth_diagnostic_json(const SERV_LISTENER *listener)
return inst->diagnostic_json(); return inst->diagnostic_json();
} }
MXS_BEGIN_DECLS extern "C"
{
/** /**
* Module handle entry point * Module handle entry point
*/ */
@ -191,4 +192,5 @@ MXS_MODULE* MXS_CREATE_MODULE()
return &info; return &info;
} }
MXS_END_DECLS
}

View File

@ -71,7 +71,8 @@ static int pam_backend_auth_authenticate(DCB *dcb)
return pses->authenticate(dcb); return pses->authenticate(dcb);
} }
MXS_BEGIN_DECLS extern "C"
{
/** /**
* Module handle entry point * Module handle entry point
*/ */
@ -110,4 +111,5 @@ MXS_MODULE* MXS_CREATE_MODULE()
return &info; return &info;
} }
MXS_END_DECLS
}