summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorArturo Borrero Gonzalez <arturo@netfilter.org>2017-10-02 15:06:49 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2018-01-08 22:00:31 +0100
commit8f0fff33137807838b39a4dfd01438d6b25f7175 (patch)
tree11d394b6e5561f1bfb9e4cd4dc9ce16995628a00 /src
parent10a85d467da4e045fbc754489dfcdd8c097ed44e (diff)
ulogd: load all plugins by default
This new configuration behaviour option eases a bit the configuration of ulogd2 by allowing to load all plugins in one go, without having to know their full path. Choosing concrete plugins and using full path for them is great for some environmnets, but I don't think it's a common case. The common case is to load all plugins, even ignoring where do they live in the filesystem. Even worse, the full path may be architecture-dependant, which makes copying the ulogd.conf file between machines unnecesarily complex. To experiment this new behaviour, don't put any 'plugin=' directive in the config file. Plugins will be loaded from a default directory, choosen at build/configure time (--with-ulogd2libdir). If no specified, this is something like '/usr/local/lib/ulogd/'. This new configuration option doesn't implement any special logic. We simply open the dir and try to load all files ending with '.so'. The log message level for plugins loading is increased so users can see by default which plugins are loaded. Signed-off-by: Arturo Borrero Gonzalez <arturo@netfilter.org> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src')
-rw-r--r--src/ulogd.c40
1 files changed, 39 insertions, 1 deletions
diff --git a/src/ulogd.c b/src/ulogd.c
index 684444f..b8bc57c 100644
--- a/src/ulogd.c
+++ b/src/ulogd.c
@@ -404,7 +404,7 @@ void ulogd_register_plugin(struct ulogd_plugin *me)
me->name);
exit(EXIT_FAILURE);
}
- ulogd_log(ULOGD_DEBUG, "registering plugin `%s'\n", me->name);
+ ulogd_log(ULOGD_NOTICE, "registering plugin `%s'\n", me->name);
llist_add(&me->list, &ulogd_plugins);
} else {
get_plugin_infos(me);
@@ -728,6 +728,41 @@ static int load_plugin(const char *file)
return 0;
}
+static int load_all_plugins(void)
+{
+ DIR *d;
+ struct dirent *dent;
+ char path[PATH_MAX];
+
+ d = opendir(ULOGD2_LIBDIR);
+ if (d == NULL) {
+ ulogd_log(ULOGD_ERROR, "load_all_plugins: opendir(%s): %s\n",
+ ULOGD2_LIBDIR, strerror(errno));
+ return -1;
+ }
+
+ ulogd_log(ULOGD_NOTICE, "loading all plugins at %s\n", ULOGD2_LIBDIR);
+
+ while ((dent = readdir(d)) != NULL) {
+ if (strcmp(dent->d_name, ".") == 0 ||
+ strcmp(dent->d_name, "..") == 0)
+ continue;
+
+ int len = strlen(dent->d_name);
+ if (len < 3)
+ continue;
+
+ if (strcmp(&dent->d_name[len - 3], ".so") != 0)
+ continue;
+
+ snprintf(path, sizeof(path), "%s/%s", ULOGD2_LIBDIR,
+ dent->d_name);
+ if (load_plugin(path) != 0)
+ return -1;
+ }
+ return 0;
+}
+
/* find an output key in a given stack, starting at 'start' */
static struct ulogd_key *
find_okey_in_stack(char *name,
@@ -925,6 +960,9 @@ static int create_stack(const char *option)
char *tok;
int ret;
+ if (llist_empty(&ulogd_plugins_handle))
+ load_all_plugins();
+
if (!buf) {
ulogd_log(ULOGD_ERROR, "");
ret = -ENOMEM;