Return to dnscert_plugin.c CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / strongswan / src / libcharon / plugins / dnscert |
1.1 misho 1: /* 2: * Copyright (C) 2013 Tobias Brunner 3: * Copyright (C) 2012 Reto Guadagnini 4: * HSR Hochschule fuer Technik Rapperswil 5: * 6: * This program is free software; you can redistribute it and/or modify it 7: * under the terms of the GNU General Public License as published by the 8: * Free Software Foundation; either version 2 of the License, or (at your 9: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. 10: * 11: * This program is distributed in the hope that it will be useful, but 12: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 13: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14: * for more details. 15: */ 16: /* 17: * Copyright (C) 2013 Ruslan Marchenko 18: * 19: * Permission is hereby granted, free of charge, to any person obtaining a copy 20: * of this software and associated documentation files (the "Software"), to deal 21: * in the Software without restriction, including without limitation the rights 22: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 23: * copies of the Software, and to permit persons to whom the Software is 24: * furnished to do so, subject to the following conditions: 25: * 26: * The above copyright notice and this permission notice shall be included in 27: * all copies or substantial portions of the Software. 28: * 29: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 31: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 32: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 33: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 34: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 35: * THE SOFTWARE. 36: */ 37: 38: #include "dnscert_plugin.h" 39: 40: #include <daemon.h> 41: #include "dnscert_cred.h" 42: 43: typedef struct private_dnscert_plugin_t private_dnscert_plugin_t; 44: 45: 46: /** 47: * private data of the dnscert plugin 48: */ 49: struct private_dnscert_plugin_t { 50: 51: /** 52: * implements plugin interface 53: */ 54: dnscert_plugin_t public; 55: 56: /** 57: * credential set 58: */ 59: dnscert_cred_t *cred; 60: 61: /** 62: * DNSCERT based authentication enabled 63: */ 64: bool enabled; 65: }; 66: 67: METHOD(plugin_t, get_name, char*, 68: private_dnscert_plugin_t *this) 69: { 70: return "dnscert"; 71: } 72: 73: METHOD(plugin_t, reload, bool, 74: private_dnscert_plugin_t *this) 75: { 76: bool enabled = lib->settings->get_bool(lib->settings, 77: "%s.plugins.dnscert.enable", FALSE, lib->ns); 78: 79: if (enabled != this->enabled) 80: { 81: if (enabled) 82: { 83: lib->credmgr->add_set(lib->credmgr, &this->cred->set); 84: } 85: else 86: { 87: lib->credmgr->remove_set(lib->credmgr, &this->cred->set); 88: } 89: this->enabled = enabled; 90: } 91: DBG1(DBG_CFG, "dnscert plugin is %sabled", this->enabled ? "en" : "dis"); 92: return TRUE; 93: } 94: 95: /** 96: * Create resolver and register credential set 97: */ 98: static bool plugin_cb(private_dnscert_plugin_t *this, 99: plugin_feature_t *feature, bool reg, void *cb_data) 100: { 101: if (reg) 102: { 103: resolver_t *res; 104: 105: res = lib->resolver->create(lib->resolver); 106: if (!res) 107: { 108: DBG1(DBG_CFG, "failed to create a DNS resolver instance"); 109: return FALSE; 110: } 111: 112: this->cred = dnscert_cred_create(res); 113: reload(this); 114: } 115: else 116: { 117: if (this->enabled) 118: { 119: lib->credmgr->remove_set(lib->credmgr, &this->cred->set); 120: } 121: this->cred->destroy(this->cred); 122: } 123: return TRUE; 124: } 125: 126: METHOD(plugin_t, get_features, int, 127: private_dnscert_plugin_t *this, plugin_feature_t *features[]) 128: { 129: static plugin_feature_t f[] = { 130: PLUGIN_CALLBACK((plugin_feature_callback_t)plugin_cb, NULL), 131: PLUGIN_PROVIDE(CUSTOM, "dnscert"), 132: PLUGIN_DEPENDS(RESOLVER), 133: PLUGIN_DEPENDS(CERT_DECODE, CERT_ANY), 134: PLUGIN_SDEPEND(CERT_DECODE, CERT_X509), 135: PLUGIN_SDEPEND(CERT_DECODE, CERT_GPG), 136: }; 137: *features = f; 138: return countof(f); 139: } 140: 141: METHOD(plugin_t, destroy, void, 142: private_dnscert_plugin_t *this) 143: { 144: free(this); 145: } 146: 147: /* 148: * see header file 149: */ 150: plugin_t *dnscert_plugin_create() 151: { 152: private_dnscert_plugin_t *this; 153: 154: INIT(this, 155: .public = { 156: .plugin = { 157: .get_name = _get_name, 158: .get_features = _get_features, 159: .reload = _reload, 160: .destroy = _destroy, 161: }, 162: }, 163: ); 164: 165: return &this->public.plugin; 166: }