Format authenticator and protocol modules

This commit is contained in:
Markus Mäkelä
2019-05-09 10:47:55 +03:00
parent 0d13e694e4
commit 6625c1296b
22 changed files with 609 additions and 610 deletions

View File

@ -147,8 +147,8 @@ extern "C"
* *
* @return The module object * @return The module object
*/ */
MXS_MODULE* MXS_CREATE_MODULE() MXS_MODULE* MXS_CREATE_MODULE()
{ {
static modulecmd_arg_type_t args[] = static modulecmd_arg_type_t args[] =
{ {
{MODULECMD_ARG_SERVICE, "Service where the user is added"}, {MODULECMD_ARG_SERVICE, "Service where the user is added"},
@ -198,7 +198,7 @@ extern "C"
}; };
return &info; return &info;
} }
} }
/** /**

View File

@ -703,8 +703,8 @@ extern "C"
/** /**
* Module handle entry point * Module handle entry point
*/ */
MXS_MODULE* MXS_CREATE_MODULE() MXS_MODULE* MXS_CREATE_MODULE()
{ {
static MXS_AUTHENTICATOR MyObject = static MXS_AUTHENTICATOR MyObject =
{ {
gssapi_auth_init, /* Initialize authenticator */ gssapi_auth_init, /* Initialize authenticator */
@ -739,5 +739,5 @@ extern "C"
}; };
return &info; return &info;
} }
} }

View File

@ -226,8 +226,8 @@ extern "C"
/** /**
* Module handle entry point * Module handle entry point
*/ */
MXS_MODULE* MXS_CREATE_MODULE() MXS_MODULE* MXS_CREATE_MODULE()
{ {
static MXS_AUTHENTICATOR MyObject = static MXS_AUTHENTICATOR MyObject =
{ {
NULL, /* No initialize entry point */ NULL, /* No initialize entry point */
@ -262,5 +262,5 @@ extern "C"
}; };
return &info; return &info;
} }
} }

View File

@ -57,14 +57,14 @@ extern "C"
* *
* @return The module object * @return The module object
*/ */
MXS_MODULE* MXS_CREATE_MODULE() MXS_MODULE* MXS_CREATE_MODULE()
{ {
static MXS_AUTHENTICATOR MyObject = static MXS_AUTHENTICATOR MyObject =
{ {
NULL, /* No initialize entry point */ NULL, /* No initialize entry point */
NULL, /* No create entry point */ NULL, /* No create entry point */
http_auth_set_protocol_data, /* Extract data into structure */ http_auth_set_protocol_data, /* Extract data into structure */
http_auth_is_client_ssl_capable,/* Check if client supports SSL */ http_auth_is_client_ssl_capable, /* Check if client supports SSL */
http_auth_authenticate, /* Authenticate user credentials */ http_auth_authenticate, /* Authenticate user credentials */
http_auth_free_client_data, /* Free the client data held in DCB */ http_auth_free_client_data, /* Free the client data held in DCB */
NULL, /* No destroy entry point */ NULL, /* No destroy entry point */
@ -93,7 +93,7 @@ extern "C"
}; };
return &info; return &info;
} }
/*lint +e14 */ /*lint +e14 */
} }

View File

@ -51,8 +51,8 @@ extern "C"
* *
* @return The module object * @return The module object
*/ */
MXS_MODULE* MXS_CREATE_MODULE() MXS_MODULE* MXS_CREATE_MODULE()
{ {
static MXS_AUTHENTICATOR MyObject = static MXS_AUTHENTICATOR MyObject =
{ {
NULL, /* No initialize entry point */ NULL, /* No initialize entry point */
@ -87,7 +87,7 @@ extern "C"
}; };
return &info; return &info;
} }
/*lint +e14 */ /*lint +e14 */
} }

View File

@ -80,8 +80,8 @@ extern "C"
* *
* @return The module object * @return The module object
*/ */
MXS_MODULE* MXS_CREATE_MODULE() MXS_MODULE* MXS_CREATE_MODULE()
{ {
static MXS_AUTHENTICATOR MyObject = static MXS_AUTHENTICATOR MyObject =
{ {
mysql_auth_init, /* Initialize the authenticator */ mysql_auth_init, /* Initialize the authenticator */
@ -116,7 +116,7 @@ extern "C"
}; };
return &info; return &info;
} }
} }
static bool open_instance_database(const char* path, sqlite3** handle) static bool open_instance_database(const char* path, sqlite3** handle)
@ -301,7 +301,7 @@ static GWBUF* gen_auth_switch_request_packet(MySQLProtocol* proto, MYSQL_session
bufdata += GW_MYSQL_SCRAMBLE_SIZE; bufdata += GW_MYSQL_SCRAMBLE_SIZE;
*bufdata = '\0'; *bufdata = '\0';
return buffer; return buffer;
}; }
/** /**
* @brief Authenticates a MySQL user who is a client to MaxScale. * @brief Authenticates a MySQL user who is a client to MaxScale.
* *
@ -448,8 +448,8 @@ static bool mysql_auth_set_protocol_data(DCB* dcb, GWBUF* buf)
* contain required data. If the buffer is unexpectedly large (likely an erroneous or malicious client), * contain required data. If the buffer is unexpectedly large (likely an erroneous or malicious client),
* discard the packet as parsing it may cause overflow. The limit is just a guess, but it seems the * discard the packet as parsing it may cause overflow. The limit is just a guess, but it seems the
* packets from most plugins are < 100 bytes. */ * packets from most plugins are < 100 bytes. */
if ((!client_data->auth_switch_sent && if ((!client_data->auth_switch_sent
(client_auth_packet_size >= MYSQL_AUTH_PACKET_BASE_SIZE && client_auth_packet_size < 1028)) && (client_auth_packet_size >= MYSQL_AUTH_PACKET_BASE_SIZE && client_auth_packet_size < 1028))
// If the client is replying to an AuthSwitchRequest, the length is predetermined. // If the client is replying to an AuthSwitchRequest, the length is predetermined.
|| (client_data->auth_switch_sent || (client_data->auth_switch_sent
&& (client_auth_packet_size == MYSQL_HEADER_LEN + MYSQL_SCRAMBLE_LEN))) && (client_auth_packet_size == MYSQL_HEADER_LEN + MYSQL_SCRAMBLE_LEN)))
@ -461,8 +461,6 @@ static bool mysql_auth_set_protocol_data(DCB* dcb, GWBUF* buf)
/* Packet is not big enough */ /* Packet is not big enough */
return false; return false;
} }
} }
/** /**
@ -497,7 +495,7 @@ static bool read_zstr(const uint8_t* client_auth_packet, size_t client_auth_pack
{ {
return false; return false;
} }
}; }
/** /**
* @brief Transfer detailed data from the authentication request to the DCB. * @brief Transfer detailed data from the authentication request to the DCB.
@ -558,8 +556,8 @@ static bool mysql_auth_set_client_data(MYSQL_session* client_data,
client_data->auth_token_len = client_auth_packet[packet_length_used]; client_data->auth_token_len = client_auth_packet[packet_length_used];
packet_length_used++; packet_length_used++;
if (client_auth_packet_size < if (client_auth_packet_size
(packet_length_used + client_data->auth_token_len)) < (packet_length_used + client_data->auth_token_len))
{ {
/* Packet was too small to contain authentication token */ /* Packet was too small to contain authentication token */
return false; return false;

View File

@ -153,8 +153,8 @@ extern "C"
* *
* @return The module object * @return The module object
*/ */
MXS_MODULE* MXS_CREATE_MODULE() MXS_MODULE* MXS_CREATE_MODULE()
{ {
static MXS_AUTHENTICATOR MyObject = static MXS_AUTHENTICATOR MyObject =
{ {
NULL, /* No initialize entry point */ NULL, /* No initialize entry point */
@ -189,6 +189,6 @@ extern "C"
}; };
return &info; return &info;
} }
/*lint +e14 */ /*lint +e14 */
} }

View File

@ -53,14 +53,14 @@ extern "C"
* *
* @return The module object * @return The module object
*/ */
MXS_MODULE* MXS_CREATE_MODULE() MXS_MODULE* MXS_CREATE_MODULE()
{ {
static MXS_AUTHENTICATOR MyObject = static MXS_AUTHENTICATOR MyObject =
{ {
NULL, /* No initialize entry point */ NULL, /* No initialize entry point */
NULL, /* No create entry point */ NULL, /* No create entry point */
null_auth_set_protocol_data, /* Extract data into structure */ null_auth_set_protocol_data, /* Extract data into structure */
null_auth_is_client_ssl_capable,/* Check if client supports SSL */ null_auth_is_client_ssl_capable, /* Check if client supports SSL */
null_auth_authenticate, /* Authenticate user credentials */ null_auth_authenticate, /* Authenticate user credentials */
null_auth_free_client_data, /* Free the client data held in DCB */ null_auth_free_client_data, /* Free the client data held in DCB */
NULL, /* No destroy entry point */ NULL, /* No destroy entry point */
@ -89,7 +89,7 @@ extern "C"
}; };
return &info; return &info;
} }
/*lint +e14 */ /*lint +e14 */
} }

View File

@ -50,14 +50,14 @@ extern "C"
* *
* @return The module object * @return The module object
*/ */
MXS_MODULE* MXS_CREATE_MODULE() MXS_MODULE* MXS_CREATE_MODULE()
{ {
static MXS_AUTHENTICATOR MyObject = static MXS_AUTHENTICATOR MyObject =
{ {
NULL, /* No initialize entry point */ NULL, /* No initialize entry point */
NULL, /* No create entry point */ NULL, /* No create entry point */
null_auth_set_protocol_data, /* Extract data into structure */ null_auth_set_protocol_data, /* Extract data into structure */
null_auth_is_client_ssl_capable,/* Check if client supports SSL */ null_auth_is_client_ssl_capable, /* Check if client supports SSL */
null_auth_authenticate, /* Authenticate user credentials */ null_auth_authenticate, /* Authenticate user credentials */
null_auth_free_client_data, /* Free the client data held in DCB */ null_auth_free_client_data, /* Free the client data held in DCB */
NULL, /* No destroy entry point */ NULL, /* No destroy entry point */
@ -86,7 +86,7 @@ extern "C"
}; };
return &info; return &info;
} }
/*lint +e14 */ /*lint +e14 */
} }

View File

@ -158,8 +158,8 @@ extern "C"
/** /**
* Module handle entry point * Module handle entry point
*/ */
MXS_MODULE* MXS_CREATE_MODULE() MXS_MODULE* MXS_CREATE_MODULE()
{ {
static MXS_AUTHENTICATOR MyObject = static MXS_AUTHENTICATOR MyObject =
{ {
pam_auth_init, /* Initialize authenticator */ pam_auth_init, /* Initialize authenticator */
@ -194,5 +194,5 @@ extern "C"
}; };
return &info; return &info;
} }
} }

View File

@ -74,7 +74,6 @@ int user_services_cb(void* data, int columns, char** column_vals, char** column_
} }
return 0; return 0;
} }
} }
PamClientSession::PamClientSession(sqlite3* dbhandle, const PamInstance& instance) PamClientSession::PamClientSession(sqlite3* dbhandle, const PamInstance& instance)
@ -152,7 +151,7 @@ void PamClientSession::get_pam_user_services(const DCB* dcb, const MYSQL_session
// Check if a matching anonymous user exists. // Check if a matching anonymous user exists.
const string anon_query = string("SELECT authentication_string FROM ") + m_instance.m_tablename const string anon_query = string("SELECT authentication_string FROM ") + m_instance.m_tablename
+ " WHERE " + FIELD_USER + " = ''" + " WHERE " + FIELD_USER + " = ''"
+ " AND '" + dcb->remote + "' LIKE " + FIELD_HOST + + " AND '" + dcb->remote + "' LIKE " + FIELD_HOST
+ " AND " + FIELD_PROXY + " = '1' ORDER BY authentication_string;"; + " AND " + FIELD_PROXY + " = '1' ORDER BY authentication_string;";
MXS_DEBUG("PAM proxy user services search sql: '%s'.", anon_query.c_str()); MXS_DEBUG("PAM proxy user services search sql: '%s'.", anon_query.c_str());

View File

@ -33,7 +33,9 @@ public:
bool extract(DCB* dcb, GWBUF* read_buffer); bool extract(DCB* dcb, GWBUF* read_buffer);
private: private:
PamClientSession(sqlite3* dbhandle, const PamInstance& instance); PamClientSession(sqlite3* dbhandle, const PamInstance& instance);
void get_pam_user_services(const DCB* dcb, const MYSQL_session* session, StringVector* services_out); void get_pam_user_services(const DCB* dcb,
const MYSQL_session* session,
StringVector* services_out);
maxscale::Buffer create_auth_change_packet() const; maxscale::Buffer create_auth_change_packet() const;
pam_auth_state m_state; /**< Authentication state*/ pam_auth_state m_state; /**< Authentication state*/

View File

@ -243,7 +243,7 @@ int PamInstance::load_users(SERVICE* service)
while ((row = mysql_fetch_row(res))) while ((row = mysql_fetch_row(res)))
{ {
add_pam_user(row[0], row[1], // user, host add_pam_user(row[0], row[1], // user, host
row[2], row[3] && strcasecmp(row[3], "Y") == 0, // db, anydb row[2], row[3] && strcasecmp(row[3], "Y") == 0,// db, anydb
row[4], // pam service row[4], // pam service
false); // not a proxy false); // not a proxy
} }
@ -383,7 +383,7 @@ bool PamInstance::fetch_anon_proxy_users(SERVER* server, MYSQL* conn)
{ {
add_pam_user("", elem.first.c_str(), // user, host add_pam_user("", elem.first.c_str(), // user, host
NULL, false, // Unused NULL, false, // Unused
elem.second.c_str(), true); // service, proxy elem.second.c_str(), true);// service, proxy
break; break;
} }
} }

View File

@ -75,8 +75,8 @@ extern "C"
/** /**
* Module handle entry point * Module handle entry point
*/ */
MXS_MODULE* MXS_CREATE_MODULE() MXS_MODULE* MXS_CREATE_MODULE()
{ {
static MXS_AUTHENTICATOR MyObject = static MXS_AUTHENTICATOR MyObject =
{ {
NULL, /* No initialize entry point */ NULL, /* No initialize entry point */
@ -111,5 +111,5 @@ extern "C"
}; };
return &info; return &info;
} }
} }

View File

@ -71,8 +71,8 @@ extern "C"
* *
* @return The module object * @return The module object
*/ */
MXS_MODULE* MXS_CREATE_MODULE() MXS_MODULE* MXS_CREATE_MODULE()
{ {
static MXS_PROTOCOL MyObject = static MXS_PROTOCOL MyObject =
{ {
cdc_read_event, /* Read - EPOLLIN handler */ cdc_read_event, /* Read - EPOLLIN handler */
@ -109,7 +109,7 @@ extern "C"
}; };
return &info; return &info;
} }
} }
/** /**

View File

@ -65,8 +65,8 @@ extern "C"
* *
* @return The module object * @return The module object
*/ */
MXS_MODULE* MXS_CREATE_MODULE() MXS_MODULE* MXS_CREATE_MODULE()
{ {
static MXS_PROTOCOL MyObject = static MXS_PROTOCOL MyObject =
{ {
httpd_read_event, /**< Read - EPOLLIN handler */ httpd_read_event, /**< Read - EPOLLIN handler */
@ -103,7 +103,7 @@ extern "C"
}; };
return &info; return &info;
} }
} }
/*lint +e14 */ /*lint +e14 */

View File

@ -72,8 +72,8 @@ extern "C"
* *
* @return The module object * @return The module object
*/ */
MXS_MODULE* MXS_CREATE_MODULE() MXS_MODULE* MXS_CREATE_MODULE()
{ {
static MXS_PROTOCOL MyObject = static MXS_PROTOCOL MyObject =
{ {
gw_read_backend_event, /* Read - EPOLLIN handler */ gw_read_backend_event, /* Read - EPOLLIN handler */
@ -110,7 +110,7 @@ extern "C"
}; };
return &info; return &info;
} }
} }
/** /**

View File

@ -166,8 +166,8 @@ extern "C"
* *
* @return The module object * @return The module object
*/ */
MXS_MODULE* MXS_CREATE_MODULE() MXS_MODULE* MXS_CREATE_MODULE()
{ {
MXS_INFO("Initialise MaxScaled Protocol module."); MXS_INFO("Initialise MaxScaled Protocol module.");
static MXS_PROTOCOL MyObject = static MXS_PROTOCOL MyObject =
@ -206,7 +206,7 @@ extern "C"
}; };
return &info; return &info;
} }
} }
/*lint +e14 */ /*lint +e14 */

View File

@ -85,8 +85,8 @@ extern "C"
* *
* @return The module object * @return The module object
*/ */
MXS_MODULE* MXS_CREATE_MODULE() MXS_MODULE* MXS_CREATE_MODULE()
{ {
MXS_INFO("Initialise Telnetd Protocol module."); MXS_INFO("Initialise Telnetd Protocol module.");
static MXS_PROTOCOL MyObject = static MXS_PROTOCOL MyObject =
@ -124,7 +124,7 @@ extern "C"
} }
}; };
return &info; return &info;
} }
} }
/*lint +e14 */ /*lint +e14 */