auth_plugin.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <mosquitto.h>
  5. #include <mosquitto_broker.h>
  6. #include <mosquitto_plugin.h>
  7. int mosquitto_auth_plugin_version(void)
  8. {
  9. return MOSQ_AUTH_PLUGIN_VERSION;
  10. }
  11. int mosquitto_auth_plugin_init(void **user_data, struct mosquitto_opt *auth_opts, int auth_opt_count)
  12. {
  13. srandom(time(NULL));
  14. return MOSQ_ERR_SUCCESS;
  15. }
  16. int mosquitto_auth_plugin_cleanup(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count)
  17. {
  18. return MOSQ_ERR_SUCCESS;
  19. }
  20. int mosquitto_auth_security_init(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count, bool reload)
  21. {
  22. return MOSQ_ERR_SUCCESS;
  23. }
  24. int mosquitto_auth_security_cleanup(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count, bool reload)
  25. {
  26. return MOSQ_ERR_SUCCESS;
  27. }
  28. int mosquitto_auth_acl_check(void *user_data, int access, struct mosquitto *client, const struct mosquitto_acl_msg *msg)
  29. {
  30. if(random() % 2 == 0){
  31. return MOSQ_ERR_SUCCESS;
  32. }else{
  33. return MOSQ_ERR_ACL_DENIED;
  34. }
  35. }
  36. int mosquitto_auth_unpwd_check(void *user_data, struct mosquitto *client, const char *username, const char *password)
  37. {
  38. if(random() % 2 == 0){
  39. return MOSQ_ERR_SUCCESS;
  40. }else{
  41. return MOSQ_ERR_AUTH;
  42. }
  43. }
  44. int mosquitto_auth_psk_key_get(void *user_data, struct mosquitto *client, const char *hint, const char *identity, char *key, int max_key_len)
  45. {
  46. return MOSQ_ERR_AUTH;
  47. }