6d84d596b89c93cde91c0ad17882bc0d1c76c2ac
[strongswan.git] / src / libcharon / plugins / eap_sim_file / eap_sim_file_plugin.c
1 /*
2 * Copyright (C) 2008 Martin Willi
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 "eap_sim_file_plugin.h"
17 #include "eap_sim_file_card.h"
18 #include "eap_sim_file_provider.h"
19 #include "eap_sim_file_triplets.h"
20
21 #include <daemon.h>
22
23 #define TRIPLET_FILE IPSEC_CONFDIR "/ipsec.d/triplets.dat"
24
25 typedef struct private_eap_sim_file_t private_eap_sim_file_t;
26
27 /**
28 * Private data of an eap_sim_file_t object.
29 */
30 struct private_eap_sim_file_t {
31
32 /**
33 * Public eap_sim_file_plugin_t interface.
34 */
35 eap_sim_file_plugin_t public;
36
37 /**
38 * SIM card
39 */
40 eap_sim_file_card_t *card;
41
42 /**
43 * SIM provider
44 */
45 eap_sim_file_provider_t *provider;
46
47 /**
48 * Triplet source
49 */
50 eap_sim_file_triplets_t *triplets;
51 };
52
53 METHOD(plugin_t, get_name, char*,
54 private_eap_sim_file_t *this)
55 {
56 return "eap-sim-file";
57 }
58
59 METHOD(plugin_t, destroy, void,
60 private_eap_sim_file_t *this)
61 {
62 simaka_manager_t *mgr;
63
64 mgr = lib->get(lib, "sim-manager");
65 if (mgr)
66 {
67 mgr->remove_card(mgr, &this->card->card);
68 mgr->remove_provider(mgr, &this->provider->provider);
69 }
70 this->card->destroy(this->card);
71 this->provider->destroy(this->provider);
72 this->triplets->destroy(this->triplets);
73 free(this);
74 }
75
76 /**
77 * See header
78 */
79 plugin_t *eap_sim_file_plugin_create()
80 {
81 private_eap_sim_file_t *this;
82 simaka_manager_t *mgr;
83
84 INIT(this,
85 .public = {
86 .plugin = {
87 .get_name = _get_name,
88 .reload = (void*)return_false,
89 .destroy = _destroy,
90 },
91 },
92 .triplets = eap_sim_file_triplets_create(TRIPLET_FILE),
93 );
94
95 this->provider = eap_sim_file_provider_create(this->triplets);
96 if (!this->provider)
97 {
98 this->triplets->destroy(this->triplets);
99 free(this);
100 return NULL;
101 }
102 this->card = eap_sim_file_card_create(this->triplets);
103
104 mgr = lib->get(lib, "sim-manager");
105 if (mgr)
106 {
107 mgr->add_card(mgr, &this->card->card);
108 mgr->add_provider(mgr, &this->provider->provider);
109 }
110 return &this->public.plugin;
111 }
112