From 26273e386d4a09cc5f00cc1442e15f71ca82525c Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Tue, 20 Nov 2012 21:16:01 +0200 Subject: [PATCH] plugins: Add version checking Ensure that plugin is always built from the same version as the main rrdd executable. If the version numbers don't match, don't load the plugin. This will ensure there are no strange bugs that appear when plugin code is not built against the same source as the main executable. Signed-off-by: Timo Kokkonen --- .gitignore | 3 +++ onewire_parser.c | 2 ++ plugin.h | 3 +++ plugin_manager.c | 14 ++++++++++++++ 4 files changed, 22 insertions(+) diff --git a/.gitignore b/.gitignore index 6add126..a16043e 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,6 @@ database.h *.conf *.rrd *.so + +version.h +.* diff --git a/onewire_parser.c b/onewire_parser.c index 287fec1..e440810 100644 --- a/onewire_parser.c +++ b/onewire_parser.c @@ -6,6 +6,7 @@ #include "string.h" #include "utils.h" #include "plugin.h" +#include "version.h" static int parse_opts(const char *str, char *ow_path, size_t pathlen, double *offset) { @@ -140,4 +141,5 @@ static int init_onewire_parser(void) struct plugin_info plugin_info = { .name = "onewire_parser", .init = init_onewire_parser, + .version = RRDD_VERSION, }; diff --git a/plugin.h b/plugin.h index da22b4d..4492057 100644 --- a/plugin.h +++ b/plugin.h @@ -4,6 +4,9 @@ typedef int (plugin_init_fn_t)(void); struct plugin_info { + /* Plugin version, must match with main executable version */ + const char *version; + /* Name of the plugin, used in debug prints */ const char *name; diff --git a/plugin_manager.c b/plugin_manager.c index 1c33951..6ddac4c 100644 --- a/plugin_manager.c +++ b/plugin_manager.c @@ -6,6 +6,7 @@ #include "plugin_manager.h" #include "plugin.h" #include "debug.h" +#include "version.h" static char *exec_path; @@ -36,6 +37,19 @@ int load_plugin(const char *path) goto out; } + if (!info->version) { + pr_err("Plugin %s version info missing\n", path); + ret = -1; + goto out; + } + + if (strcmp(RRDD_VERSION, info->version)) { + pr_err("Plugin %s version mismatch, expected %s, got %s\n", + path, RRDD_VERSION, info->version); + ret = -1; + goto out; + } + if (!info->init) { pr_err("Plugin info structure has NULL .init callback\n"); goto out; -- 2.45.0