Return to vici_plugin.c CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / strongswan / src / libcharon / plugins / vici |
1.1 misho 1: /* 2: * Copyright (C) 2014 Martin Willi 3: * Copyright (C) 2014 revosec AG 4: * 5: * Copyright (C) 2015-2016 Andreas Steffen 6: * HSR Hochschule fuer Technik Rapperswil 7: * 8: * This program is free software; you can redistribute it and/or modify it 9: * under the terms of the GNU General Public License as published by the 10: * Free Software Foundation; either version 2 of the License, or (at your 11: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. 12: * 13: * This program is distributed in the hope that it will be useful, but 14: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16: * for more details. 17: */ 18: 19: /* 20: * Copyright (C) 2014 Timo Teräs <timo.teras@iki.fi> 21: * 22: * Permission is hereby granted, free of charge, to any person obtaining a copy 23: * of this software and associated documentation files (the "Software"), to deal 24: * in the Software without restriction, including without limitation the rights 25: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 26: * copies of the Software, and to permit persons to whom the Software is 27: * furnished to do so, subject to the following conditions: 28: * 29: * The above copyright notice and this permission notice shall be included in 30: * all copies or substantial portions of the Software. 31: * 32: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 33: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 34: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 35: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 36: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 37: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 38: * THE SOFTWARE. 39: */ 40: 41: #include "vici_plugin.h" 42: #include "vici_dispatcher.h" 43: #include "vici_query.h" 44: #include "vici_control.h" 45: #include "vici_cred.h" 46: #include "vici_config.h" 47: #include "vici_attribute.h" 48: #include "vici_authority.h" 49: #include "vici_logger.h" 50: 51: #include <library.h> 52: #include <daemon.h> 53: 54: typedef struct private_vici_plugin_t private_vici_plugin_t; 55: 56: /** 57: * Private members of vici_plugin_t 58: */ 59: struct private_vici_plugin_t { 60: 61: /** 62: * public functions 63: */ 64: vici_plugin_t public; 65: 66: /** 67: * Dispatcher, creating socket 68: */ 69: vici_dispatcher_t *dispatcher; 70: 71: /** 72: * Query commands 73: */ 74: vici_query_t *query; 75: 76: /** 77: * Control commands 78: */ 79: vici_control_t *control; 80: 81: /** 82: * Credential backend 83: */ 84: vici_cred_t *cred; 85: 86: /** 87: * Certification Authority backend 88: */ 89: vici_authority_t *authority; 90: 91: /** 92: * Configuration backend 93: */ 94: vici_config_t *config; 95: 96: /** 97: * IKE attribute backend 98: */ 99: vici_attribute_t *attrs; 100: 101: /** 102: * Generic debug logger 103: */ 104: vici_logger_t *logger; 105: }; 106: 107: METHOD(plugin_t, get_name, char*, 108: private_vici_plugin_t *this) 109: { 110: return "vici"; 111: } 112: 113: /** 114: * Register vici plugin features 115: */ 116: static bool register_vici(private_vici_plugin_t *this, 117: plugin_feature_t *feature, bool reg, void *data) 118: { 119: if (reg) 120: { 121: char *uri; 122: 123: uri = lib->settings->get_str(lib->settings, "%s.plugins.vici.socket", 124: VICI_DEFAULT_URI, lib->ns); 125: this->dispatcher = vici_dispatcher_create(uri); 126: if (this->dispatcher) 127: { 128: this->query = vici_query_create(this->dispatcher); 129: this->control = vici_control_create(this->dispatcher); 1.1.1.2 ! misho 130: this->authority = vici_authority_create(this->dispatcher); ! 131: this->cred = vici_cred_create(this->dispatcher, this->authority); 1.1 misho 132: lib->credmgr->add_set(lib->credmgr, &this->cred->set); 133: lib->credmgr->add_set(lib->credmgr, &this->authority->set); 134: this->config = vici_config_create(this->dispatcher, this->authority, 135: this->cred); 136: this->attrs = vici_attribute_create(this->dispatcher); 137: this->logger = vici_logger_create(this->dispatcher); 138: 139: charon->backends->add_backend(charon->backends, 140: &this->config->backend); 141: charon->attributes->add_provider(charon->attributes, 142: &this->attrs->provider); 143: charon->bus->add_logger(charon->bus, &this->logger->logger); 144: charon->bus->add_listener(charon->bus, &this->query->listener); 145: return TRUE; 146: } 147: return FALSE; 148: } 149: else 150: { 151: charon->bus->remove_listener(charon->bus, &this->query->listener); 152: charon->bus->remove_logger(charon->bus, &this->logger->logger); 153: charon->attributes->remove_provider(charon->attributes, 154: &this->attrs->provider); 155: charon->backends->remove_backend(charon->backends, 156: &this->config->backend); 157: 158: this->logger->destroy(this->logger); 159: this->attrs->destroy(this->attrs); 160: this->config->destroy(this->config); 161: lib->credmgr->remove_set(lib->credmgr, &this->cred->set); 162: lib->credmgr->remove_set(lib->credmgr, &this->authority->set); 163: this->authority->destroy(this->authority); 164: this->cred->destroy(this->cred); 165: this->control->destroy(this->control); 166: this->query->destroy(this->query); 167: this->dispatcher->destroy(this->dispatcher); 168: } 169: return TRUE; 170: } 171: 172: METHOD(plugin_t, get_features, int, 173: private_vici_plugin_t *this, plugin_feature_t *features[]) 174: { 175: static plugin_feature_t f[] = { 176: PLUGIN_CALLBACK((plugin_feature_callback_t)register_vici, NULL), 177: PLUGIN_PROVIDE(CUSTOM, "vici"), 178: PLUGIN_SDEPEND(CUSTOM, "counters"), 179: }; 180: *features = f; 181: return countof(f); 182: } 183: 184: METHOD(plugin_t, destroy, void, 185: private_vici_plugin_t *this) 186: { 187: free(this); 188: } 189: 190: /* 191: * see header file 192: */ 193: plugin_t *vici_plugin_create() 194: { 195: private_vici_plugin_t *this; 196: 197: INIT(this, 198: .public = { 199: .plugin = { 200: .get_name = _get_name, 201: .reload = (void*)return_false, 202: .get_features = _get_features, 203: .destroy = _destroy, 204: }, 205: }, 206: ); 207: 208: return &this->public.plugin; 209: }