diff options
author | David Woodhouse <dwmw2@infradead.org> | 2023-05-11 10:36:01 +0100 |
---|---|---|
committer | David Woodhouse <dwmw2@infradead.org> | 2023-05-11 13:15:53 +0100 |
commit | 715921a1fdef767dcb929dedf44959435151b571 (patch) | |
tree | e19dae2455e92bcadf3fec091dfe7872d1079a24 /src/nmtui | |
parent | 97f2a368f154dc315ebf7b4107cbe2fc7ec60b4a (diff) | |
download | NetworkManager-715921a1fdef767dcb929dedf44959435151b571.tar.gz |
nmcli, nmtui: reduce duplication around openconnect auth helper
Pull a bunch of stuff into nm_vpn_openconnect_authenticate_helper() that
both callers were doing for themselves, and make its API a bit simpler.
It's given the NMSettingVpn and the GPtrArray of secrets, and it simply
succeeds or fails.
Diffstat (limited to 'src/nmtui')
-rw-r--r-- | src/nmtui/nmtui-connect.c | 59 |
1 files changed, 3 insertions, 56 deletions
diff --git a/src/nmtui/nmtui-connect.c b/src/nmtui/nmtui-connect.c index ba9fffcaec..7369d6586b 100644 --- a/src/nmtui/nmtui-connect.c +++ b/src/nmtui/nmtui-connect.c @@ -31,16 +31,11 @@ * before starting the command and restored after it returns. */ static gboolean -openconnect_authenticate(NMConnection *connection, - char **cookie, - char **gateway, - char **gwcert, - char **resolve) +openconnect_authenticate(NMConnection *connection, GPtrArray *secrets) { GError *error = NULL; NMSettingVpn *s_vpn; gboolean ret; - int status = 0; nmt_newt_message_dialog( _("openconnect will be run to authenticate.\nIt will return to nmtui when completed.")); @@ -50,13 +45,7 @@ openconnect_authenticate(NMConnection *connection, newtSuspend(); - ret = nm_vpn_openconnect_authenticate_helper(s_vpn, - cookie, - gateway, - gwcert, - resolve, - &status, - &error); + ret = nm_vpn_openconnect_authenticate_helper(s_vpn, secrets, &error); newtResume(); @@ -66,16 +55,6 @@ openconnect_authenticate(NMConnection *connection, return FALSE; } - if (WIFEXITED(status)) { - if (WEXITSTATUS(status) != 0) { - nmt_newt_message_dialog(_("openconnect failed with status %d"), WEXITSTATUS(status)); - return FALSE; - } - } else if (WIFSIGNALED(status)) { - nmt_newt_message_dialog(_("openconnect failed with signal %d"), WTERMSIG(status)); - return FALSE; - } - return TRUE; } @@ -89,7 +68,6 @@ secrets_requested(NMSecretAgentSimple *agent, { NmtNewtForm *form; NMConnection *connection = NM_CONNECTION(user_data); - int i; /* Get secrets for OpenConnect VPN */ if (connection && nm_connection_is_type(connection, NM_SETTING_VPN_SETTING_NAME)) { @@ -97,38 +75,7 @@ secrets_requested(NMSecretAgentSimple *agent, if (nm_streq0(nm_setting_vpn_get_service_type(s_vpn), NM_SECRET_AGENT_VPN_TYPE_OPENCONNECT)) { - gs_free char *cookie = NULL; - gs_free char *gateway = NULL; - gs_free char *gwcert = NULL; - gs_free char *resolve = NULL; - - openconnect_authenticate(connection, &cookie, &gateway, &gwcert, &resolve); - - for (i = 0; i < secrets->len; i++) { - NMSecretAgentSimpleSecret *secret = secrets->pdata[i]; - - if (secret->secret_type != NM_SECRET_AGENT_SECRET_TYPE_VPN_SECRET) - continue; - if (!nm_streq0(secret->vpn_type, NM_SECRET_AGENT_VPN_TYPE_OPENCONNECT)) - continue; - if (nm_streq0(secret->entry_id, - NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRETS "cookie")) { - g_free(secret->value); - secret->value = g_steal_pointer(&cookie); - } else if (nm_streq0(secret->entry_id, - NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRETS "gateway")) { - g_free(secret->value); - secret->value = g_steal_pointer(&gateway); - } else if (nm_streq0(secret->entry_id, - NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRETS "gwcert")) { - g_free(secret->value); - secret->value = g_steal_pointer(&gwcert); - } else if (nm_streq0(secret->entry_id, - NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRETS "resolve")) { - g_free(secret->value); - secret->value = g_steal_pointer(&resolve); - } - } + openconnect_authenticate(connection, secrets); } } |