Don't load eap-sim-file plugin if no valid triplet file found
This commit is contained in:
@@ -56,6 +56,32 @@ METHOD(plugin_t, get_name, char*,
|
|||||||
return "eap-sim-file";
|
return "eap-sim-file";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load triplet file
|
||||||
|
*/
|
||||||
|
static bool load_triplets(private_eap_sim_file_t *this,
|
||||||
|
plugin_feature_t *feature, bool reg, void *data)
|
||||||
|
{
|
||||||
|
if (reg)
|
||||||
|
{
|
||||||
|
this->triplets = eap_sim_file_triplets_create(TRIPLET_FILE);
|
||||||
|
if (!this->triplets)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
this->provider = eap_sim_file_provider_create(this->triplets);
|
||||||
|
this->card = eap_sim_file_card_create(this->triplets);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
this->card->destroy(this->card);
|
||||||
|
this->provider->destroy(this->provider);
|
||||||
|
this->triplets->destroy(this->triplets);
|
||||||
|
this->card = NULL;
|
||||||
|
this->provider = NULL;
|
||||||
|
this->triplets = NULL;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback providing our card to register
|
* Callback providing our card to register
|
||||||
*/
|
*/
|
||||||
@@ -76,12 +102,16 @@ METHOD(plugin_t, get_features, int,
|
|||||||
private_eap_sim_file_t *this, plugin_feature_t *features[])
|
private_eap_sim_file_t *this, plugin_feature_t *features[])
|
||||||
{
|
{
|
||||||
static plugin_feature_t f[] = {
|
static plugin_feature_t f[] = {
|
||||||
|
PLUGIN_CALLBACK((void*)load_triplets, NULL),
|
||||||
|
PLUGIN_PROVIDE(CUSTOM, "eap-sim-file-triplets"),
|
||||||
PLUGIN_CALLBACK(simaka_manager_register, get_card),
|
PLUGIN_CALLBACK(simaka_manager_register, get_card),
|
||||||
PLUGIN_PROVIDE(CUSTOM, "sim-card"),
|
PLUGIN_PROVIDE(CUSTOM, "sim-card"),
|
||||||
PLUGIN_DEPENDS(CUSTOM, "sim-manager"),
|
PLUGIN_DEPENDS(CUSTOM, "sim-manager"),
|
||||||
|
PLUGIN_DEPENDS(CUSTOM, "eap-sim-file-triplets"),
|
||||||
PLUGIN_CALLBACK(simaka_manager_register, get_provider),
|
PLUGIN_CALLBACK(simaka_manager_register, get_provider),
|
||||||
PLUGIN_PROVIDE(CUSTOM, "sim-provider"),
|
PLUGIN_PROVIDE(CUSTOM, "sim-provider"),
|
||||||
PLUGIN_DEPENDS(CUSTOM, "sim-manager"),
|
PLUGIN_DEPENDS(CUSTOM, "sim-manager"),
|
||||||
|
PLUGIN_DEPENDS(CUSTOM, "eap-sim-file-triplets"),
|
||||||
};
|
};
|
||||||
*features = f;
|
*features = f;
|
||||||
return countof(f);
|
return countof(f);
|
||||||
@@ -90,9 +120,6 @@ METHOD(plugin_t, get_features, int,
|
|||||||
METHOD(plugin_t, destroy, void,
|
METHOD(plugin_t, destroy, void,
|
||||||
private_eap_sim_file_t *this)
|
private_eap_sim_file_t *this)
|
||||||
{
|
{
|
||||||
this->card->destroy(this->card);
|
|
||||||
this->provider->destroy(this->provider);
|
|
||||||
this->triplets->destroy(this->triplets);
|
|
||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,10 +138,7 @@ plugin_t *eap_sim_file_plugin_create()
|
|||||||
.destroy = _destroy,
|
.destroy = _destroy,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
.triplets = eap_sim_file_triplets_create(TRIPLET_FILE),
|
|
||||||
);
|
);
|
||||||
this->provider = eap_sim_file_provider_create(this->triplets);
|
|
||||||
this->card = eap_sim_file_card_create(this->triplets);
|
|
||||||
|
|
||||||
return &this->public.plugin;
|
return &this->public.plugin;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ static void parse_token(char *to, char *from, size_t len)
|
|||||||
/**
|
/**
|
||||||
* Read the triplets from the file
|
* Read the triplets from the file
|
||||||
*/
|
*/
|
||||||
static void read_triplets(private_eap_sim_file_triplets_t *this, char *path)
|
static bool read_triplets(private_eap_sim_file_triplets_t *this, char *path)
|
||||||
{
|
{
|
||||||
char line[512];
|
char line[512];
|
||||||
FILE *file;
|
FILE *file;
|
||||||
@@ -161,7 +161,7 @@ static void read_triplets(private_eap_sim_file_triplets_t *this, char *path)
|
|||||||
{
|
{
|
||||||
DBG1(DBG_CFG, "opening triplet file %s failed: %s",
|
DBG1(DBG_CFG, "opening triplet file %s failed: %s",
|
||||||
path, strerror(errno));
|
path, strerror(errno));
|
||||||
return;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read line by line */
|
/* read line by line */
|
||||||
@@ -227,6 +227,7 @@ static void read_triplets(private_eap_sim_file_triplets_t *this, char *path)
|
|||||||
|
|
||||||
DBG1(DBG_CFG, "read %d triplets from %s",
|
DBG1(DBG_CFG, "read %d triplets from %s",
|
||||||
this->triplets->get_count(this->triplets), path);
|
this->triplets->get_count(this->triplets), path);
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
METHOD(eap_sim_file_triplets_t, destroy, void,
|
METHOD(eap_sim_file_triplets_t, destroy, void,
|
||||||
@@ -252,8 +253,12 @@ eap_sim_file_triplets_t *eap_sim_file_triplets_create(char *file)
|
|||||||
.triplets = linked_list_create(),
|
.triplets = linked_list_create(),
|
||||||
.mutex = mutex_create(MUTEX_TYPE_DEFAULT),
|
.mutex = mutex_create(MUTEX_TYPE_DEFAULT),
|
||||||
);
|
);
|
||||||
read_triplets(this, file);
|
|
||||||
|
|
||||||
|
if (!read_triplets(this, file))
|
||||||
|
{
|
||||||
|
destroy(this);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
return &this->public;
|
return &this->public;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user