eap: Add __eap_check_settings
Since PEAP & TTLS expect to use eap_check_settings recursively, make them use a private version of that API that does not perform cleanup and can contain side-effects. eap_check_settings itself will guarantee that no side effects happen on error. It is meant to be used by code outside of the eap subsystem.
This commit is contained in:
parent
e24d6b54d2
commit
786365e2c7
|
@ -952,7 +952,8 @@ static int eap_peap_check_settings(struct l_settings *settings,
|
||||||
|
|
||||||
snprintf(entry, sizeof(entry), "%sPEAP-Phase2-", prefix);
|
snprintf(entry, sizeof(entry), "%sPEAP-Phase2-", prefix);
|
||||||
|
|
||||||
return eap_check_settings(settings, secrets, entry, false, out_missing);
|
return __eap_check_settings(settings, secrets, entry, false,
|
||||||
|
out_missing);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool eap_peap_load_settings(struct eap_state *eap,
|
static bool eap_peap_load_settings(struct eap_state *eap,
|
||||||
|
|
|
@ -764,7 +764,7 @@ static int eap_ttls_check_settings(struct l_settings *settings,
|
||||||
|
|
||||||
snprintf(setting, sizeof(setting), "%sTTLS-Phase2-", prefix);
|
snprintf(setting, sizeof(setting), "%sTTLS-Phase2-", prefix);
|
||||||
|
|
||||||
return eap_check_settings(settings, secrets, setting, false,
|
return __eap_check_settings(settings, secrets, setting, false,
|
||||||
out_missing);
|
out_missing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
42
src/eap.c
42
src/eap.c
|
@ -431,13 +431,12 @@ static int eap_setting_exists(struct l_settings *settings,
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
int eap_check_settings(struct l_settings *settings, struct l_queue *secrets,
|
int __eap_check_settings(struct l_settings *settings, struct l_queue *secrets,
|
||||||
const char *prefix, bool set_key_material,
|
const char *prefix, bool set_key_material,
|
||||||
struct l_queue **out_missing)
|
struct l_queue **missing)
|
||||||
{
|
{
|
||||||
char setting[64];
|
char setting[64];
|
||||||
const char *method_name;
|
const char *method_name;
|
||||||
struct l_queue *missing = NULL;
|
|
||||||
const struct l_queue_entry *entry;
|
const struct l_queue_entry *entry;
|
||||||
struct eap_method *method;
|
struct eap_method *method;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
@ -470,11 +469,13 @@ int eap_check_settings(struct l_settings *settings, struct l_queue *secrets,
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (method->check_settings)
|
if (method->check_settings) {
|
||||||
ret = method->check_settings(settings, secrets,
|
ret = method->check_settings(settings, secrets,
|
||||||
prefix, &missing);
|
prefix, missing);
|
||||||
if (ret)
|
|
||||||
goto error;
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Methods that provide the get_identity callback are responsible
|
* Methods that provide the get_identity callback are responsible
|
||||||
|
@ -484,14 +485,29 @@ int eap_check_settings(struct l_settings *settings, struct l_queue *secrets,
|
||||||
if (!method->get_identity) {
|
if (!method->get_identity) {
|
||||||
snprintf(setting, sizeof(setting), "%sIdentity", prefix);
|
snprintf(setting, sizeof(setting), "%sIdentity", prefix);
|
||||||
|
|
||||||
ret = eap_setting_exists(settings, setting, secrets, missing);
|
ret = eap_setting_exists(settings, setting, secrets, *missing);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
l_error("Property %s is missing", setting);
|
l_error("Property %s is missing", setting);
|
||||||
ret = -ENOENT;
|
return -ENOENT;
|
||||||
goto error;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int eap_check_settings(struct l_settings *settings, struct l_queue *secrets,
|
||||||
|
const char *prefix, bool set_key_material,
|
||||||
|
struct l_queue **out_missing)
|
||||||
|
{
|
||||||
|
struct l_queue *missing = NULL;
|
||||||
|
int ret = __eap_check_settings(settings, secrets, prefix,
|
||||||
|
set_key_material, &missing);
|
||||||
|
|
||||||
|
if (ret < 0) {
|
||||||
|
l_queue_destroy(missing, eap_secret_info_free);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
if (missing && l_queue_isempty(missing)) {
|
if (missing && l_queue_isempty(missing)) {
|
||||||
l_queue_destroy(missing, NULL);
|
l_queue_destroy(missing, NULL);
|
||||||
missing = NULL;
|
missing = NULL;
|
||||||
|
@ -499,10 +515,6 @@ int eap_check_settings(struct l_settings *settings, struct l_queue *secrets,
|
||||||
|
|
||||||
*out_missing = missing;
|
*out_missing = missing;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
|
||||||
l_queue_destroy(missing, eap_secret_info_free);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool eap_load_settings(struct eap_state *eap, struct l_settings *settings,
|
bool eap_load_settings(struct eap_state *eap, struct l_settings *settings,
|
||||||
|
|
|
@ -66,6 +66,9 @@ void eap_append_secret(struct l_queue **out_missing, enum eap_secret_type type,
|
||||||
const char *id, const char *id2, const char *parameter);
|
const char *id, const char *id2, const char *parameter);
|
||||||
void eap_secret_info_free(void *data);
|
void eap_secret_info_free(void *data);
|
||||||
|
|
||||||
|
int __eap_check_settings(struct l_settings *settings, struct l_queue *secrets,
|
||||||
|
const char *prefix, bool set_key_material,
|
||||||
|
struct l_queue **missing);
|
||||||
int eap_check_settings(struct l_settings *settings, struct l_queue *secrets,
|
int eap_check_settings(struct l_settings *settings, struct l_queue *secrets,
|
||||||
const char *prefix, bool set_key_material,
|
const char *prefix, bool set_key_material,
|
||||||
struct l_queue **out_missing);
|
struct l_queue **out_missing);
|
||||||
|
|
Loading…
Reference in New Issue