2 * Copyright (C) 2013 Tobias Brunner
3 * Copyright (C) 2012 Reto Guadagnini
4 * Hochschule fuer Technik Rapperswil
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>.
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
17 #include "ipseckey_plugin.h"
20 #include "ipseckey_cred.h"
22 typedef struct private_ipseckey_plugin_t private_ipseckey_plugin_t
;
26 * private data of the ipseckey plugin
28 struct private_ipseckey_plugin_t
{
31 * implements plugin interface
33 ipseckey_plugin_t
public;
38 ipseckey_cred_t
*cred
;
41 * IPSECKEY based authentication enabled
46 METHOD(plugin_t
, get_name
, char*,
47 private_ipseckey_plugin_t
*this)
52 METHOD(plugin_t
, reload
, bool,
53 private_ipseckey_plugin_t
*this)
55 bool enabled
= lib
->settings
->get_bool(lib
->settings
,
56 "%s.plugins.ipseckey.enable", FALSE
, lib
->ns
);
58 if (enabled
!= this->enabled
)
62 lib
->credmgr
->add_set(lib
->credmgr
, &this->cred
->set
);
66 lib
->credmgr
->remove_set(lib
->credmgr
, &this->cred
->set
);
68 this->enabled
= enabled
;
70 DBG1(DBG_CFG
, "ipseckey plugin is %sabled", this->enabled
? "en" : "dis");
75 * Create resolver and register credential set
77 static bool plugin_cb(private_ipseckey_plugin_t
*this,
78 plugin_feature_t
*feature
, bool reg
, void *cb_data
)
84 res
= lib
->resolver
->create(lib
->resolver
);
87 DBG1(DBG_CFG
, "failed to create a DNS resolver instance");
91 this->cred
= ipseckey_cred_create(res
);
98 lib
->credmgr
->remove_set(lib
->credmgr
, &this->cred
->set
);
100 this->cred
->destroy(this->cred
);
105 METHOD(plugin_t
, get_features
, int,
106 private_ipseckey_plugin_t
*this, plugin_feature_t
*features
[])
108 static plugin_feature_t f
[] = {
109 PLUGIN_CALLBACK((plugin_feature_callback_t
)plugin_cb
, NULL
),
110 PLUGIN_PROVIDE(CUSTOM
, "ipseckey"),
111 PLUGIN_DEPENDS(RESOLVER
),
112 PLUGIN_DEPENDS(PUBKEY
, KEY_RSA
),
113 PLUGIN_DEPENDS(CERT_ENCODE
, CERT_TRUSTED_PUBKEY
),
119 METHOD(plugin_t
, destroy
, void,
120 private_ipseckey_plugin_t
*this)
128 plugin_t
*ipseckey_plugin_create()
130 private_ipseckey_plugin_t
*this;
135 .get_name
= _get_name
,
136 .get_features
= _get_features
,
143 return &this->public.plugin
;