Tell plugins which plugin versions the broker supports.

This commit is contained in:
Roger A. Light 2020-10-24 00:13:45 +01:00
parent 06b933c3ba
commit 42b9d94e91
2 changed files with 26 additions and 16 deletions

View File

@ -21,9 +21,12 @@ Contributors:
extern "C" {
#endif
#define MOSQ_AUTH_PLUGIN_VERSION 5
/* The generic plugin interface starts at version 5 */
#define MOSQ_PLUGIN_VERSION 5
/* The old auth only interface stopped at version 4 */
#define MOSQ_AUTH_PLUGIN_VERSION 4
#define MOSQ_ACL_NONE 0x00
#define MOSQ_ACL_READ 0x01
#define MOSQ_ACL_WRITE 0x02
@ -113,13 +116,15 @@ struct mosquitto_acl_msg {
* ========================================================================= */
/*
* Function: mosquitto_auth_plugin_version
* Function: mosquitto_plugin_version
*
* The broker will call this function immediately after loading the plugin to
* check it is a supported plugin version. Your code must simply return
* the plugin interface version you support, i.e. 5.
* The broker will attempt to call this function immediately after loading the
* plugin to check it is a supported plugin version. Your code must simply
* return the plugin interface version you support, i.e. 5.
*
* The supported_versions array tells you which plugin versions the broker supports.
*/
int mosquitto_plugin_version(void);
int mosquitto_plugin_version(int supported_version_count, const int *supported_versions);
/*
* Function: mosquitto_auth_plugin_init

View File

@ -27,6 +27,7 @@ Contributors:
#include "utlist.h"
typedef int (*FUNC_auth_plugin_version)(void);
typedef int (*FUNC_plugin_version)(int, const int *);
static int security__cleanup_single(struct mosquitto__security_options *opts, bool reload);
@ -287,10 +288,13 @@ int security__load_v4(struct mosquitto__auth_plugin *plugin, struct mosquitto_op
static int security__module_init_single(struct mosquitto__listener *listener, struct mosquitto__security_options *opts)
{
void *lib;
int (*plugin_version)(void) = NULL;
int (*plugin_version)(int, const int*) = NULL;
int (*plugin_auth_version)(void) = NULL;
int version;
int i;
int rc;
const int plugin_versions[] = {5, 4, 3, 2};
int plugin_version_count = sizeof(plugin_versions)/sizeof(int);
if(opts->auth_plugin_config_count == 0){
return MOSQ_ERR_SUCCESS;
@ -311,16 +315,17 @@ static int security__module_init_single(struct mosquitto__listener *listener, st
}
opts->auth_plugin_configs[i].plugin.lib = NULL;
if(!(plugin_version = (FUNC_auth_plugin_version)LIB_SYM(lib, "mosquitto_plugin_version"))){
if(!(plugin_version = (FUNC_auth_plugin_version)LIB_SYM(lib, "mosquitto_auth_plugin_version"))){
if((plugin_version = (FUNC_plugin_version)LIB_SYM(lib, "mosquitto_plugin_version"))){
version = plugin_version(plugin_version_count, plugin_versions);
}else if((plugin_auth_version = (FUNC_auth_plugin_version)LIB_SYM(lib, "mosquitto_auth_plugin_version"))){
version = plugin_auth_version();
}else{
log__printf(NULL, MOSQ_LOG_ERR,
"Error: Unable to load auth plugin function mosquitto_auth_plugin_version() or mosquitto_plugin_version().");
LIB_ERROR();
LIB_CLOSE(lib);
return 1;
}
}
version = plugin_version();
opts->auth_plugin_configs[i].plugin.version = version;
if(version == 5){
rc = plugin__load_v5(