- 后端结构体
struct backend_p { void *conf; /* Handle to backend */ char *name; f_kill *kill; f_getuser *getuser; f_superuser *superuser; f_aclcheck *aclcheck; }; Mosquitto主程序调用插件流程mosquitto尝试读取mosquitto_auth_plugin_version,此时插件打印"*** auth-plug: startup"尝试读取插件中
mosquitto_auth_plugin_init() mosquitto_auth_plugin_cleanup() mosquitto_auth_security_init() mosquitto_auth_security_cleanup() mosquitto_auth_acl_check() mosquitto_auth_unpwd_check() mosquitto_auth_psk_key_get()函数,如果缺少函数或函数定义存在问题,则返回失败
调用
mosquitto_auth_plugin_init()进行初始化之后主程序接收到输入的用户名密码后会采用回调的方式将参数传递给插件
- 接口函数定义及用途
mosquitto_auth_plugin_version(void)日志初始化、提示插件被调用、返回插件版本 返回值:`MOSQ_AUTH_PLUGIN_VERSION`<-全局定义int mosquitto_auth_plugin_init(void **userdata, struct mosquitto_auth_opt *auth_opts, int auth_opt_count)userdata为插件用户数据存放处,需要由插件进行内存堆申请,之后可在内放入插件间共享数据- 初始化
userdata至初始值 - 遍历所有使能鉴权方式1并从中获取
userdata结构体中所需参数 - 配置后端
- 遍历
mosquitto的conf中配置的后端,并将其存入userdata->be_list中 - 根据不同后端进行不同的初始化配置
- 遍历
int mosquitto_auth_security_init(void *userdata, struct mosquitto_auth_opt *auth_opts, int auth_opt_count, bool reload)- 初始化插件函数执行完成后调用
int mosquitto_auth_unpwd_check(void *userdata, const char *username, const char *password)- 实际鉴权函数,
mosquitto通过该函数得到鉴权结果
- 实际鉴权函数,
int mosquitto_auth_acl_check(void *userdata, const char *clientid, const char *username, const char *topic, int access)- ACL权限查询函数,用于控制各用户对应topic的权限
int mosquitto_auth_security_cleanup(void *userdata, struct mosquitto_auth_opt *auth_opts, int auth_opt_count, bool reload)mosquitto退出时调用
int mosquitto_auth_plugin_cleanup(void *userdata, struct mosquitto_auth_opt *auth_opts, int auth_opt_count)mosquitto退出时调用
此处从该函数的回调参数
auth_optsauth_opt_count获得对应信息,这些信息从mosquitto的conf文件中获得 ↩︎