fixed segmentation fault due to null pointer
[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 charon->sim->remove_card(charon->sim, &this->card->card);
63 charon->sim->remove_provider(charon->sim, &this->provider->provider);
64 this->card->destroy(this->card);
65 this->provider->destroy(this->provider);
66 this->triplets->destroy(this->triplets);
67 free(this);
68 }
69
70 /**
71 * See header
72 */
73 plugin_t *eap_sim_file_plugin_create()
74 {
75 private_eap_sim_file_t *this;
76
77 INIT(this,
78 .public = {
79 .plugin = {
80 .get_name = _get_name,
81 .reload = (void*)return_false,
82 .destroy = _destroy,
83 },
84 },
85 .triplets = eap_sim_file_triplets_create(TRIPLET_FILE),
86 );
87
88 this->provider = eap_sim_file_provider_create(this->triplets);
89 if (!this->provider)
90 {
91 this->triplets->destroy(this->triplets);
92 free(this);
93 return NULL;
94 }
95 this->card = eap_sim_file_card_create(this->triplets);
96
97 charon->sim->add_card(charon->sim, &this->card->card);
98 charon->sim->add_provider(charon->sim, &this->provider->provider);
99
100 return &this->public.plugin;
101 }
102