| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #include <string.h>
- #include <mysql.h>
- #include <mysql/plugin_auth.h>
- #include <mysql/client_plugin.h>
- #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, LDAP_FILTER);
- 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;
|