|
|
@@ -0,0 +1,91 @@
|
|
|
+
|
|
|
+#include <string.h>
|
|
|
+
|
|
|
+#include <mysql.h>
|
|
|
+#include <mysql/plugin_auth.h>
|
|
|
+#include <mysql/client_plugin.h>
|
|
|
+
|
|
|
+#include "interfaces.h"
|
|
|
+#include "MySQLLDAPAuthModule.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 MySQLLDAPAuthModule(std::make_unique<LDAPReader>());
|
|
|
+ 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;
|
|
|
+
|