ipseckey: Use proper daemon name for enable option
[strongswan.git] / src / libcharon / plugins / ipseckey / ipseckey_plugin.c
1 /*
2 * Copyright (C) 2012 Reto Guadagnini
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include "ipseckey_plugin.h"
17
18 #include <daemon.h>
19 #include "ipseckey_cred.h"
20
21 typedef struct private_ipseckey_plugin_t private_ipseckey_plugin_t;
22
23
24 /**
25 * private data of the ipseckey plugin
26 */
27 struct private_ipseckey_plugin_t {
28
29 /**
30 * implements plugin interface
31 */
32 ipseckey_plugin_t public;
33
34 /**
35 * DNS resolver instance
36 */
37 resolver_t *res;
38
39 /**
40 * credential set
41 */
42 ipseckey_cred_t *cred;
43
44 /**
45 * IPSECKEY based authentication enabled
46 */
47 bool enabled;
48 };
49
50 METHOD(plugin_t, get_name, char*,
51 private_ipseckey_plugin_t *this)
52 {
53 return "ipseckey";
54 }
55
56 METHOD(plugin_t, destroy, void,
57 private_ipseckey_plugin_t *this)
58 {
59 if (this->enabled)
60 {
61 lib->credmgr->remove_set(lib->credmgr, &this->cred->set);
62 }
63 DESTROY_IF(this->res);
64 DESTROY_IF(this->cred);
65 free(this);
66 }
67
68 /*
69 * see header file
70 */
71 plugin_t *ipseckey_plugin_create()
72 {
73 private_ipseckey_plugin_t *this;
74
75 INIT(this,
76 .public = {
77 .plugin = {
78 .get_name = _get_name,
79 .reload = (void*)return_false,
80 .destroy = _destroy,
81 },
82 },
83 .res = lib->resolver->create(lib->resolver),
84 .enabled = lib->settings->get_bool(lib->settings,
85 "%s.plugins.ipseckey.enable", FALSE, charon->name),
86 );
87
88 if (!this->res)
89 {
90 DBG1(DBG_CFG, "failed to create a DNS resolver instance");
91 destroy(this);
92 return NULL;
93 }
94
95 if (this->enabled)
96 {
97 this->cred = ipseckey_cred_create(this->res);
98 lib->credmgr->add_set(lib->credmgr, &this->cred->set);
99 }
100
101 return &this->public.plugin;
102 }
103