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 
mosquitto_auth_plugin_version(void)8 int mosquitto_auth_plugin_version(void)
9 {
10 	return MOSQ_AUTH_PLUGIN_VERSION;
11 }
12 
mosquitto_auth_plugin_init(void ** user_data,struct mosquitto_opt * auth_opts,int auth_opt_count)13 int mosquitto_auth_plugin_init(void **user_data, struct mosquitto_opt *auth_opts, int auth_opt_count)
14 {
15 	srandom(time(NULL));
16 	return MOSQ_ERR_SUCCESS;
17 }
18 
mosquitto_auth_plugin_cleanup(void * user_data,struct mosquitto_opt * auth_opts,int auth_opt_count)19 int mosquitto_auth_plugin_cleanup(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count)
20 {
21 	return MOSQ_ERR_SUCCESS;
22 }
23 
mosquitto_auth_security_init(void * user_data,struct mosquitto_opt * auth_opts,int auth_opt_count,bool reload)24 int mosquitto_auth_security_init(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count, bool reload)
25 {
26 	return MOSQ_ERR_SUCCESS;
27 }
28 
mosquitto_auth_security_cleanup(void * user_data,struct mosquitto_opt * auth_opts,int auth_opt_count,bool reload)29 int mosquitto_auth_security_cleanup(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count, bool reload)
30 {
31 	return MOSQ_ERR_SUCCESS;
32 }
33 
mosquitto_auth_acl_check(void * user_data,int access,struct mosquitto * client,const struct mosquitto_acl_msg * msg)34 int mosquitto_auth_acl_check(void *user_data, int access, struct mosquitto *client, const struct mosquitto_acl_msg *msg)
35 {
36 	if(random() % 2 == 0){
37 		return MOSQ_ERR_SUCCESS;
38 	}else{
39 		return MOSQ_ERR_ACL_DENIED;
40 	}
41 }
42 
mosquitto_auth_unpwd_check(void * user_data,struct mosquitto * client,const char * username,const char * password)43 int mosquitto_auth_unpwd_check(void *user_data, struct mosquitto *client, const char *username, const char *password)
44 {
45 	if(random() % 2 == 0){
46 		return MOSQ_ERR_SUCCESS;
47 	}else{
48 		return MOSQ_ERR_AUTH;
49 	}
50 }
51 
mosquitto_auth_psk_key_get(void * user_data,struct mosquitto * client,const char * hint,const char * identity,char * key,int max_key_len)52 int mosquitto_auth_psk_key_get(void *user_data, struct mosquitto *client, const char *hint, const char *identity, char *key, int max_key_len)
53 {
54 	return MOSQ_ERR_AUTH;
55 }
56 
57