#include #include #include #include #include "interfaces.h" #include "ldapReader.h" static IMySQLLDAPAuthModule* _module; static int authenticateUser(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info) { char *pkt; int pkt_len; /* read the password as null-terminated string, fail on error */ if ((pkt_len= vio->read_packet(vio, (unsigned char**) &pkt)) < 0) return CR_ERROR; /* fail on empty password */ if (!pkt_len || *pkt == '\0') { info->password_used= PASSWORD_USED_NO; return CR_ERROR; } info->password_used= PASSWORD_USED_YES; return _module->Authenticate(info->user_name, pkt) ? CR_OK : CR_ERROR; } static int auth_simple_client (MYSQL_PLUGIN_VIO *vio, MYSQL *mysql) { return vio->write_packet(vio, (const unsigned char *)mysql->passwd, strlen(mysql->passwd) + 1) ? CR_ERROR : CR_OK; } static struct st_mysql_auth auth_ldap_handler = { MYSQL_AUTHENTICATION_INTERFACE_VERSION, "auth_ldap", authenticateUser, NULL, NULL }; int initModule(void*) { _module = new LDAPReader(LDAP_URI, LDAP_ATTRIBUTE, LDAP_BASEDN); return 0; } int destroyModule(void*) { delete _module; _module = nullptr; return 0; } mysql_declare_plugin(auth_ldap) { MYSQL_AUTHENTICATION_PLUGIN, &auth_ldap_handler, "auth_ldap", "isundil", "LDAP authentication plugin", PLUGIN_LICENSE_GPL, initModule, destroyModule, 0x0100, NULL, NULL, NULL, 0 } mysql_declare_plugin_end; mysql_declare_client_plugin(AUTHENTICATION) "auth_ldap", "isundil", "LDAP Authentication plugin", {1,0,0}, "GPL", NULL, NULL, NULL, NULL, auth_simple_client mysql_end_client_plugin;