php_auth_ldap.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include <php.h>
  2. #include <mysqlnd.h>
  3. #include <zend_extensions.h>
  4. #include <ext/standard/info.h>
  5. static zend_uchar* mysqlnd_ldap_auth_get_auth_data(struct st_mysqlnd_authentication_plugin * self,
  6. size_t * auth_data_len,
  7. MYSQLND_CONN_DATA * conn, const char * const user, const char * const passwd,
  8. const size_t passwd_len, zend_uchar * auth_plugin_data, const size_t auth_plugin_data_len,
  9. const MYSQLND_SESSION_OPTIONS * const session_options,
  10. const MYSQLND_PFC_DATA * const pfc_data,
  11. const zend_ulong mysql_flags)
  12. {
  13. zend_uchar * ret = NULL;
  14. if (passwd && passwd_len)
  15. ret = (zend_uchar*) zend_strndup(passwd, passwd_len);
  16. *auth_data_len = passwd_len;
  17. return ret;
  18. }
  19. static struct st_mysqlnd_authentication_plugin* mysqlnd_plugin_auth_ldap_ptr = NULL;
  20. static PHP_MINIT_FUNCTION(mysql_auth_ldap)
  21. {
  22. struct st_mysqlnd_authentication_plugin mysqlnd_plugin_auth_ldap =
  23. {
  24. {
  25. MYSQLND_PLUGIN_API_VERSION,
  26. "auth_plugin_auth_ldap",
  27. MYSQLND_VERSION_ID,
  28. PHP_MYSQLND_VERSION,
  29. "PHP License 3.01",
  30. "isundil <isundill@gmail.com>",
  31. {
  32. NULL,
  33. NULL
  34. },
  35. {
  36. NULL
  37. }
  38. },
  39. {
  40. mysqlnd_ldap_auth_get_auth_data,
  41. NULL
  42. }
  43. };
  44. mysqlnd_plugin_auth_ldap_ptr = (struct st_mysqlnd_authentication_plugin*) malloc(sizeof(mysqlnd_plugin_auth_ldap));
  45. memcpy(mysqlnd_plugin_auth_ldap_ptr, &mysqlnd_plugin_auth_ldap, sizeof(mysqlnd_plugin_auth_ldap));
  46. mysqlnd_plugin_register_ex((struct st_mysqlnd_plugin_header *) mysqlnd_plugin_auth_ldap_ptr);
  47. }
  48. static PHP_MSHUTDOWN_FUNCTION(mysql_auth_ldap)
  49. {
  50. static int call_count = 0;
  51. if (++call_count > 1)
  52. free(mysqlnd_plugin_auth_ldap_ptr);
  53. }
  54. static const zend_module_dep mysql_auth_ldap_dep[] = { ZEND_MOD_REQUIRED("mysqlnd") ZEND_MOD_END };
  55. static zend_function_entry mysqlnd_functions[] = { PHP_FE_END };
  56. PHP_MINFO_FUNCTION(mysql_auth_ldap)
  57. {
  58. php_info_print_table_start();
  59. php_info_print_table_row(2, "mysql ldap auth plugin", "enabled");
  60. php_info_print_table_end();
  61. }
  62. zend_module_entry mysql_auth_ldap_module_entry = {
  63. STANDARD_MODULE_HEADER_EX, NULL, mysql_auth_ldap_dep,
  64. "mysql_auth_ldap",
  65. mysqlnd_functions,
  66. PHP_MINIT(mysql_auth_ldap),
  67. PHP_MSHUTDOWN(mysql_auth_ldap),
  68. NULL, NULL,
  69. NULL,
  70. "0.1", STANDARD_MODULE_PROPERTIES
  71. };
  72. ZEND_GET_MODULE(mysql_auth_ldap)