1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.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 	return MOSQ_ERR_SUCCESS;
16 }
17 
mosquitto_auth_plugin_cleanup(void * user_data,struct mosquitto_opt * auth_opts,int auth_opt_count)18 int mosquitto_auth_plugin_cleanup(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count)
19 {
20 	return MOSQ_ERR_SUCCESS;
21 }
22 
mosquitto_auth_security_init(void * user_data,struct mosquitto_opt * auth_opts,int auth_opt_count,bool reload)23 int mosquitto_auth_security_init(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count, bool reload)
24 {
25 	return MOSQ_ERR_SUCCESS;
26 }
27 
mosquitto_auth_security_cleanup(void * user_data,struct mosquitto_opt * auth_opts,int auth_opt_count,bool reload)28 int mosquitto_auth_security_cleanup(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count, bool reload)
29 {
30 	return MOSQ_ERR_SUCCESS;
31 }
32 
mosquitto_auth_acl_check(void * user_data,int access,struct mosquitto * client,const struct mosquitto_acl_msg * msg)33 int mosquitto_auth_acl_check(void *user_data, int access, struct mosquitto *client, const struct mosquitto_acl_msg *msg)
34 {
35 	if(access == MOSQ_ACL_SUBSCRIBE){
36 		return MOSQ_ERR_SUCCESS;
37 	}
38 
39 	if(!msg->topic || strcmp(msg->topic, "param/topic")){
40 		abort();
41 		return MOSQ_ERR_ACL_DENIED;
42 	}
43 
44 	if(!msg->payload || strncmp(msg->payload, "payload contents", strlen("payload contents"))){
45 		abort();
46 		return MOSQ_ERR_ACL_DENIED;
47 	}
48 
49 	if(msg->payloadlen != strlen("payload contents")){
50 		abort();
51 		return MOSQ_ERR_ACL_DENIED;
52 	}
53 
54 	if(msg->qos != 1){
55 		abort();
56 		return MOSQ_ERR_ACL_DENIED;
57 	}
58 
59 	if(!msg->retain){
60 		abort();
61 		return MOSQ_ERR_ACL_DENIED;
62 	}
63 
64 	return MOSQ_ERR_SUCCESS;
65 }
66 
mosquitto_auth_unpwd_check(void * user_data,struct mosquitto * client,const char * username,const char * password)67 int mosquitto_auth_unpwd_check(void *user_data, struct mosquitto *client, const char *username, const char *password)
68 {
69 	return MOSQ_ERR_PLUGIN_DEFER;
70 }
71 
mosquitto_auth_psk_key_get(void * user_data,struct mosquitto * client,const char * hint,const char * identity,char * key,int max_key_len)72 int mosquitto_auth_psk_key_get(void *user_data, struct mosquitto *client, const char *hint, const char *identity, char *key, int max_key_len)
73 {
74 	return MOSQ_ERR_AUTH;
75 }
76 
77