From 473c477978c5336529fa7c4f18382add31f9ad28 Mon Sep 17 00:00:00 2001 From: Andreas Steffen Date: Wed, 26 Oct 2011 10:31:48 +0200 Subject: [PATCH] added listplugins support to pluto and whack --- src/pluto/Makefile.am | 1 + src/pluto/plugin_list.c | 71 +++++++++++++++++++++++++++++++++++++++++ src/pluto/plugin_list.h | 21 ++++++++++++ src/pluto/rcv_whack.c | 6 ++++ src/whack/whack.c | 4 +++ src/whack/whack.h | 3 +- 6 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 src/pluto/plugin_list.c create mode 100644 src/pluto/plugin_list.h diff --git a/src/pluto/Makefile.am b/src/pluto/Makefile.am index 4689305585..68ba163460 100644 --- a/src/pluto/Makefile.am +++ b/src/pluto/Makefile.am @@ -39,6 +39,7 @@ nat_traversal.c nat_traversal.h \ ocsp.c ocsp.h \ packet.c packet.h \ pkcs7.c pkcs7.h \ +plugin_list.c plugin_list.h \ pluto.c pluto.h \ plutomain.c \ rcv_whack.c rcv_whack.h \ diff --git a/src/pluto/plugin_list.c b/src/pluto/plugin_list.c new file mode 100644 index 0000000000..d6ace1de35 --- /dev/null +++ b/src/pluto/plugin_list.c @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2011 Martin Willi, revosec AG + * Copyright (C) 2011 Andreas Steffen, HSR Hochschule fuer Technik Rapperswil + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See . + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include + +#include +#include + +/** + * List loaded plugin information + */ +void plugin_list(void) +{ + plugin_feature_t *features, *fp; + enumerator_t *enumerator; + linked_list_t *list; + plugin_t *plugin; + int count, i; + bool loaded; + char *str; + + whack_log(RC_COMMENT, " "); + whack_log(RC_COMMENT, "List of loaded Plugins:"); + whack_log(RC_COMMENT, " "); + + enumerator = lib->plugins->create_plugin_enumerator(lib->plugins); + while (enumerator->enumerate(enumerator, &plugin, &list)) + { + whack_log(RC_COMMENT, "%s:", plugin->get_name(plugin)); + if (plugin->get_features) + { + count = plugin->get_features(plugin, &features); + for (i = 0; i < count; i++) + { + str = plugin_feature_get_string(&features[i]); + switch (features[i].kind) + { + case FEATURE_PROVIDE: + fp = &features[i]; + loaded = list->find_first(list, NULL, + (void**)&fp) == SUCCESS; + whack_log(RC_COMMENT, " %s%s", + str, loaded ? "" : " (not loaded)"); + break; + case FEATURE_DEPENDS: + whack_log(RC_COMMENT, " %s", str); + break; + case FEATURE_SDEPEND: + whack_log(RC_COMMENT, " %s(soft)", str); + break; + default: + break; + } + free(str); + } + } + } + enumerator->destroy(enumerator); +} diff --git a/src/pluto/plugin_list.h b/src/pluto/plugin_list.h new file mode 100644 index 0000000000..62e4a167d3 --- /dev/null +++ b/src/pluto/plugin_list.h @@ -0,0 +1,21 @@ +/* Generates a list of all loaded plugins and their dependencies + * Copyright (C) 2011 Andreas Steffen + * HSR Hochschule fuer Technik Rapperswil + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See . + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#ifndef _PLUGIN_LIST_H +#define _PLUGIN_LIST_H + +extern void plugin_list(void); + +#endif /* _PLUGIN_LIST_H */ diff --git a/src/pluto/rcv_whack.c b/src/pluto/rcv_whack.c index 94b07bd756..0a7b33ab50 100644 --- a/src/pluto/rcv_whack.c +++ b/src/pluto/rcv_whack.c @@ -57,6 +57,7 @@ #include "myid.h" #include "kernel_alg.h" #include "ike_alg.h" +#include "plugin_list.h" #include "whack_attribute.h" /* helper variables and function to decode strings from whack message */ @@ -557,6 +558,11 @@ void whack_handle(int whackctlfd) kernel_alg_list(); } + if (msg.whack_list & LIST_PLUGINS) + { + plugin_list(); + } + if (msg.whack_key) { /* add a public key */ diff --git a/src/whack/whack.c b/src/whack/whack.c index b277a68e54..a7945d6d83 100644 --- a/src/whack/whack.c +++ b/src/whack/whack.c @@ -207,6 +207,7 @@ static void help(void) " [--listcrls]" " [--listocsp]" " [--listcards]" + " [--listplugins]" " [--listall]" "\n\n" "purge: whack" @@ -379,6 +380,7 @@ enum { LST_CRLS, LST_OCSP, LST_CARDS, + LST_PLUGINS, LST_ALL, # define LST_LAST LST_ALL /* last list option */ @@ -571,6 +573,7 @@ static const struct option long_opts[] = { { "listcrls", no_argument, NULL, LST_CRLS + OO }, { "listocsp", no_argument, NULL, LST_OCSP + OO }, { "listcards", no_argument, NULL, LST_CARDS + OO }, + { "listplugins", no_argument, NULL, LST_PLUGINS + OO }, { "listall", no_argument, NULL, LST_ALL + OO }, /* options for an end description */ @@ -1234,6 +1237,7 @@ int main(int argc, char **argv) case LST_CRLS: /* --listcrls */ case LST_OCSP: /* --listocsp */ case LST_CARDS: /* --listcards */ + case LST_PLUGINS: /* --listplugins */ msg.whack_list |= LELEM(c - LST_ALGS); continue; diff --git a/src/whack/whack.h b/src/whack/whack.h index f8e6a9a882..c92eaf3cf9 100644 --- a/src/whack/whack.h +++ b/src/whack/whack.h @@ -333,8 +333,9 @@ enum rc_type { #define LIST_CRLS 0x0200 /* list all crls */ #define LIST_OCSP 0x0400 /* list all ocsp cache entries */ #define LIST_CARDS 0x0800 /* list all smartcard records */ +#define LIST_PLUGINS 0x1000 /* list all plugins with dependencies */ -#define LIST_ALL LRANGES(LIST_ALGS, LIST_CARDS) /* all list options */ +#define LIST_ALL LRANGES(LIST_ALGS, LIST_PLUGINS) /* all list options */ /* options of whack --reread*** command */ -- 2.47.2