Move credential removal operations into helper functions

This allows the same functions to be used for both the control interface
and the D-Bus interface.

Signed-off-by: Damien Dejean <damiendejean@chromium.org>
This commit is contained in:
Damien Dejean 2021-12-08 07:45:31 +00:00 committed by Jouni Malinen
parent e232d97776
commit 4262e6ca49
3 changed files with 83 additions and 51 deletions

View file

@ -3793,47 +3793,6 @@ static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
}
static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
struct wpa_cred *cred)
{
struct wpa_ssid *ssid;
char str[20];
int id;
if (cred == NULL) {
wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
return -1;
}
id = cred->id;
if (wpa_config_remove_cred(wpa_s->conf, id) < 0) {
wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
return -1;
}
wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id);
/* Remove any network entry created based on the removed credential */
ssid = wpa_s->conf->ssid;
while (ssid) {
if (ssid->parent_cred == cred) {
int res;
wpa_printf(MSG_DEBUG, "Remove network id %d since it "
"used the removed credential", ssid->id);
res = os_snprintf(str, sizeof(str), "%d", ssid->id);
if (os_snprintf_error(sizeof(str), res))
str[sizeof(str) - 1] = '\0';
ssid = ssid->next;
wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
} else
ssid = ssid->next;
}
return 0;
}
static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
char *cmd)
{
@ -3844,13 +3803,7 @@ static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
* "provisioning_sp=<FQDN> */
if (os_strcmp(cmd, "all") == 0) {
wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
cred = wpa_s->conf->cred;
while (cred) {
prev = cred;
cred = cred->next;
wpas_ctrl_remove_cred(wpa_s, prev);
}
return 0;
return wpas_remove_all_creds(wpa_s);
}
if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
@ -3866,7 +3819,7 @@ static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
if (os_strcmp(prev->domain[i], cmd + 8)
!= 0)
continue;
wpas_ctrl_remove_cred(wpa_s, prev);
wpas_remove_cred(wpa_s, prev);
break;
}
}
@ -3883,7 +3836,7 @@ static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
cred = cred->next;
if (prev->provisioning_sp &&
os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
wpas_ctrl_remove_cred(wpa_s, prev);
wpas_remove_cred(wpa_s, prev);
}
return 0;
}
@ -3892,7 +3845,7 @@ static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
cred = wpa_config_get_cred(wpa_s->conf, id);
return wpas_ctrl_remove_cred(wpa_s, cred);
return wpas_remove_cred(wpa_s, cred);
}

View file

@ -4512,6 +4512,82 @@ void wpa_supplicant_select_network(struct wpa_supplicant *wpa_s,
}
/**
* wpas_remove_cred - Remove the specified credential and all the network
* entries created based on the removed credential
* @wpa_s: wpa_supplicant structure for a network interface
* @cred: The credential to remove
* Returns: 0 on success, -1 on failure
*/
int wpas_remove_cred(struct wpa_supplicant *wpa_s, struct wpa_cred *cred)
{
struct wpa_ssid *ssid, *next;
int id;
if (!cred) {
wpa_printf(MSG_DEBUG, "Could not find cred");
return -1;
}
id = cred->id;
if (wpa_config_remove_cred(wpa_s->conf, id) < 0) {
wpa_printf(MSG_DEBUG, "Could not find cred %d", id);
return -1;
}
wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id);
/* Remove any network entry created based on the removed credential */
ssid = wpa_s->conf->ssid;
while (ssid) {
next = ssid->next;
if (ssid->parent_cred == cred) {
wpa_printf(MSG_DEBUG,
"Remove network id %d since it used the removed credential",
ssid->id);
if (wpa_supplicant_remove_network(wpa_s, ssid->id) ==
-1) {
wpa_printf(MSG_DEBUG,
"Could not find network id=%d",
ssid->id);
}
}
ssid = next;
}
return 0;
}
/**
* wpas_remove_cred - Remove all the Interworking credentials
* @wpa_s: wpa_supplicant structure for a network interface
* Returns: 0 on success, -1 on failure
*/
int wpas_remove_all_creds(struct wpa_supplicant *wpa_s)
{
int res, ret = 0;
struct wpa_cred *cred, *prev;
cred = wpa_s->conf->cred;
while (cred) {
prev = cred;
cred = cred->next;
res = wpas_remove_cred(wpa_s, prev);
if (res < 0) {
wpa_printf(MSG_DEBUG,
"Removal of all credentials failed - failed to remove credential id=%d",
prev->id);
ret = -1;
}
}
return ret;
}
/**
* wpas_set_pkcs11_engine_and_module_path - Set PKCS #11 engine and module path
* @wpa_s: wpa_supplicant structure for a network interface

View file

@ -38,6 +38,7 @@ struct wpa_bss;
struct wpa_scan_results;
struct hostapd_hw_modes;
struct wpa_driver_associate_params;
struct wpa_cred;
/*
* Forward declarations of private structures used within the ctrl_iface
@ -1578,6 +1579,8 @@ void wpa_supplicant_disable_network(struct wpa_supplicant *wpa_s,
struct wpa_ssid *ssid);
void wpa_supplicant_select_network(struct wpa_supplicant *wpa_s,
struct wpa_ssid *ssid);
int wpas_remove_cred(struct wpa_supplicant *wpa_s, struct wpa_cred *cred);
int wpas_remove_all_creds(struct wpa_supplicant *wpa_s);
int wpas_set_pkcs11_engine_and_module_path(struct wpa_supplicant *wpa_s,
const char *pkcs11_engine_path,
const char *pkcs11_module_path);