auth_plugin_pwd.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <mosquitto.h>
  4. #include <mosquitto_broker.h>
  5. #include <mosquitto_plugin.h>
  6. int mosquitto_auth_plugin_version(void)
  7. {
  8. return 4;
  9. }
  10. int mosquitto_auth_plugin_init(void **user_data, struct mosquitto_opt *auth_opts, int auth_opt_count)
  11. {
  12. return MOSQ_ERR_SUCCESS;
  13. }
  14. int mosquitto_auth_plugin_cleanup(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count)
  15. {
  16. return MOSQ_ERR_SUCCESS;
  17. }
  18. int mosquitto_auth_security_init(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count, bool reload)
  19. {
  20. return MOSQ_ERR_SUCCESS;
  21. }
  22. int mosquitto_auth_security_cleanup(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count, bool reload)
  23. {
  24. return MOSQ_ERR_SUCCESS;
  25. }
  26. int mosquitto_auth_acl_check(void *user_data, int access, struct mosquitto *client, const struct mosquitto_acl_msg *msg)
  27. {
  28. return MOSQ_ERR_PLUGIN_DEFER;
  29. }
  30. int mosquitto_auth_unpwd_check(void *user_data, struct mosquitto *client, const char *username, const char *password)
  31. {
  32. if(!strcmp(username, "test-username") && password && !strcmp(password, "cnwTICONIURW")){
  33. return MOSQ_ERR_SUCCESS;
  34. }else if(!strcmp(username, "readonly")){
  35. return MOSQ_ERR_SUCCESS;
  36. }else if(!strcmp(username, "test-username@v2")){
  37. return MOSQ_ERR_PLUGIN_DEFER;
  38. }else{
  39. return MOSQ_ERR_AUTH;
  40. }
  41. }
  42. int mosquitto_auth_psk_key_get(void *user_data, struct mosquitto *client, const char *hint, const char *identity, char *key, int max_key_len)
  43. {
  44. return MOSQ_ERR_AUTH;
  45. }