auth_plugin_v2.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include <string.h>
  2. #include <stdbool.h>
  3. #include "mosquitto_plugin_v2.h"
  4. /*
  5. * Following constant come from mosquitto.h
  6. *
  7. * They are copied here to fix value of those constant at the time of MOSQ_AUTH_PLUGIN_VERSION == 2
  8. */
  9. enum mosq_err_t {
  10. MOSQ_ERR_SUCCESS = 0,
  11. MOSQ_ERR_AUTH = 11,
  12. MOSQ_ERR_ACL_DENIED = 12
  13. };
  14. int mosquitto_auth_plugin_version(void)
  15. {
  16. return 2;
  17. }
  18. int mosquitto_auth_plugin_init(void **user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count)
  19. {
  20. return MOSQ_ERR_SUCCESS;
  21. }
  22. int mosquitto_auth_plugin_cleanup(void *user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count)
  23. {
  24. return MOSQ_ERR_SUCCESS;
  25. }
  26. int mosquitto_auth_security_init(void *user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count, bool reload)
  27. {
  28. return MOSQ_ERR_SUCCESS;
  29. }
  30. int mosquitto_auth_security_cleanup(void *user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count, bool reload)
  31. {
  32. return MOSQ_ERR_SUCCESS;
  33. }
  34. int mosquitto_auth_acl_check(void *user_data, const char *clientid, const char *username, const char *topic, int access)
  35. {
  36. if(!strcmp(username, "readonly") && access == MOSQ_ACL_READ){
  37. return MOSQ_ERR_SUCCESS;
  38. }else{
  39. return MOSQ_ERR_ACL_DENIED;
  40. }
  41. }
  42. int mosquitto_auth_unpwd_check(void *user_data, const char *username, const char *password)
  43. {
  44. if(!strcmp(username, "test-username") && password && !strcmp(password, "cnwTICONIURW")){
  45. return MOSQ_ERR_SUCCESS;
  46. }else if(!strcmp(username, "readonly")){
  47. return MOSQ_ERR_SUCCESS;
  48. }else if(!strcmp(username, "test-username@v2")){
  49. return MOSQ_ERR_SUCCESS;
  50. }else{
  51. return MOSQ_ERR_AUTH;
  52. }
  53. }
  54. int mosquitto_auth_psk_key_get(void *user_data, const char *hint, const char *identity, char *key, int max_key_len)
  55. {
  56. return MOSQ_ERR_AUTH;
  57. }