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:
Denis Kenzior 2018-06-14 19:10:11 -05:00
parent e24d6b54d2
commit 786365e2c7
4 changed files with 33 additions and 17 deletions

View File

@ -952,7 +952,8 @@ static int eap_peap_check_settings(struct l_settings *settings,
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,

View File

@ -764,7 +764,7 @@ static int eap_ttls_check_settings(struct l_settings *settings,
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);
}

View File

@ -431,13 +431,12 @@ static int eap_setting_exists(struct l_settings *settings,
return -ENOENT;
}
int eap_check_settings(struct l_settings *settings, struct l_queue *secrets,
const char *prefix, bool set_key_material,
struct l_queue **out_missing)
int __eap_check_settings(struct l_settings *settings, struct l_queue *secrets,
const char *prefix, bool set_key_material,
struct l_queue **missing)
{
char setting[64];
const char *method_name;
struct l_queue *missing = NULL;
const struct l_queue_entry *entry;
struct eap_method *method;
int ret = 0;
@ -470,11 +469,13 @@ int eap_check_settings(struct l_settings *settings, struct l_queue *secrets,
return -ENOTSUP;
}
if (method->check_settings)
if (method->check_settings) {
ret = method->check_settings(settings, secrets,
prefix, &missing);
if (ret)
goto error;
prefix, missing);
if (ret < 0)
return ret;
}
/*
* 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) {
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) {
l_error("Property %s is missing", setting);
ret = -ENOENT;
goto error;
return -ENOENT;
}
}
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)) {
l_queue_destroy(missing, NULL);
missing = NULL;
@ -499,10 +515,6 @@ int eap_check_settings(struct l_settings *settings, struct l_queue *secrets,
*out_missing = missing;
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,

View File

@ -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);
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,
const char *prefix, bool set_key_material,
struct l_queue **out_missing);