-
Notifications
You must be signed in to change notification settings - Fork 165
/
auth-plugin.c
80 lines (61 loc) · 2.37 KB
/
auth-plugin.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <mosquitto.h>
#include <mosquitto_plugin.h>
#include "go-auth.h"
int mosquitto_auth_plugin_version(void) {
return MOSQ_AUTH_PLUGIN_VERSION;
}
int mosquitto_auth_plugin_init(void **user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count) {
/*
Pass auth_opts hash as keys and values char* arrays to Go in order to initialize them there.
*/
GoInt32 opts_count = auth_opt_count;
GoString keys[auth_opt_count];
GoString values[auth_opt_count];
int i;
struct mosquitto_auth_opt *o;
for (i = 0, o = auth_opts; i < auth_opt_count; i++, o++) {
GoString opt_key = {o->key, strlen(o->key)};
GoString opt_value = {o->value, strlen(o->value)};
keys[i] = opt_key;
values[i] = opt_value;
}
GoSlice keysSlice = {keys, auth_opt_count, auth_opt_count};
GoSlice valuesSlice = {values, auth_opt_count, auth_opt_count};
AuthPluginInit(keysSlice, valuesSlice, opts_count);
return MOSQ_ERR_SUCCESS;
}
int mosquitto_auth_plugin_cleanup(void *user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count) {
AuthPluginCleanup();
return MOSQ_ERR_SUCCESS;
}
int mosquitto_auth_security_init(void *user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count, bool reload) {
return MOSQ_ERR_SUCCESS;
}
int mosquitto_auth_security_cleanup(void *user_data, struct mosquitto_auth_opt *auth_opts, int auth_opt_count, bool reload) {
return MOSQ_ERR_SUCCESS;
}
int mosquitto_auth_unpwd_check(void *user_data, const char *username, const char *password) {
GoString go_username = {username, strlen(username)};
GoString go_password = {password, strlen(password)};
if(AuthUnpwdCheck(go_username, go_password)){
return MOSQ_ERR_SUCCESS;
}
return MOSQ_ERR_ACL_DENIED;
}
int mosquitto_auth_acl_check(void *user_data, const char *clientid, const char *username, const char *topic, int access) {
GoString go_clientid = {clientid, strlen(clientid)};
GoString go_username = {username, strlen(username)};
GoString go_topic = {topic, strlen(topic)};
GoInt32 go_access = access;
if(AuthAclCheck(go_clientid, go_username, go_topic, go_access)){
return MOSQ_ERR_SUCCESS;
}
return MOSQ_ERR_ACL_DENIED;
}
int mosquitto_auth_psk_key_get(void *user_data, const char *hint, const char *identity, char *key, int max_key_len) {
return MOSQ_ERR_AUTH;
}