/***** * * Copyright (C) 2002 Vincent Glaume * All Rights Reserved * * This file is part of the Prelude program. * * 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, or (at your option) * any later version. * * 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. * * You should have received a copy of the GNU General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * *****/ #include #include #include #include #include #include #include #include #include "plugin-firewall.h" static plugin_container_t *fw; static LIST_HEAD(firewall_plugins_list); static int subscribe(plugin_container_t *pc) { log(LOG_INFO, "- Subscribing %s to active firewall plugins.\n", pc->plugin->name); fw = pc; return plugin_add(pc, &firewall_plugins_list, NULL); } static void unsubscribe(plugin_container_t *pc) { log(LOG_INFO, "- Un-subscribing %s from active firewall plugins.\n", pc->plugin->name); fw = NULL; plugin_del(pc); } int firewall_plugins_run(cm_firewall_msg_t *fw_msg) { int ret = -1; if ( ! fw ) return -1; plugin_run_with_return_value(fw, plugin_firewall_t, run, ret, fw_msg); return ret; } int firewall_plugins_clean(int *timeout) { int ret = -1; if ( ! fw ) return -1; plugin_run_with_return_value(fw, plugin_firewall_t, clean, ret, timeout); return ret; } int firewall_plugins_init(const char *dirname, int argc, char **argv) { int ret; ret = access(dirname, F_OK); if ( ret < 0 ) { if ( errno == ENOENT ) return 0; log(LOG_ERR, "can't access %s.\n", dirname); return -1; } ret = plugin_load_from_dir(dirname, argc, argv, subscribe, unsubscribe); if ( ret < 0 && errno != ENOENT ) { log(LOG_ERR, "couldn't load plugin subsystem.\n"); return -1; } return ret; } int firewall_plugins_available(void) { return list_empty(&firewall_plugins_list) ? -1 : 0; }