auth_plugin_acl.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. const char *username = mosquitto_client_username(client);
  29. if(username && !strcmp(username, "readonly") && access == MOSQ_ACL_READ){
  30. return MOSQ_ERR_SUCCESS;
  31. }else if(username && !strcmp(username, "readonly") && access == MOSQ_ACL_SUBSCRIBE &&!strchr(msg->topic, '#') && !strchr(msg->topic, '+')) {
  32. return MOSQ_ERR_SUCCESS;
  33. }else{
  34. return MOSQ_ERR_ACL_DENIED;
  35. }
  36. }
  37. int mosquitto_auth_unpwd_check(void *user_data, struct mosquitto *client, const char *username, const char *password)
  38. {
  39. return MOSQ_ERR_PLUGIN_DEFER;
  40. }
  41. int mosquitto_auth_psk_key_get(void *user_data, struct mosquitto *client, const char *hint, const char *identity, char *key, int max_key_len)
  42. {
  43. return MOSQ_ERR_AUTH;
  44. }