diff options
author | Thomas Haller <thaller@redhat.com> | 2019-05-26 23:39:25 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-06-13 16:10:53 +0200 |
commit | ceaf64eee7c2e7e9cf596bbd601420557dd8feee (patch) | |
tree | 61c8540b30fadd5eb2f4308374bbc89db2467779 | |
parent | 25de86abb62488b1a88b7d34f05676a2a901515f (diff) | |
download | NetworkManager-ceaf64eee7c2e7e9cf596bbd601420557dd8feee.tar.gz |
settings,libnm: move is-adhoc-wpa check to libnm
"nm-settings.c" is complex enough. Move this trivial helper function to libnm-core.
-rw-r--r-- | libnm-core/nm-core-internal.h | 2 | ||||
-rw-r--r-- | libnm-core/nm-utils.c | 27 | ||||
-rw-r--r-- | src/settings/nm-settings.c | 36 |
3 files changed, 31 insertions, 34 deletions
diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index 406b170e15..d369a75949 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -815,4 +815,6 @@ void _nm_bridge_vlan_str_append_rest (const NMBridgeVlan *vlan, GString *string, gboolean leading_space); +gboolean nm_utils_connection_is_adhoc_wpa (NMConnection *connection); + #endif diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 31ef2978a1..44b1703e11 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -6049,3 +6049,30 @@ _nm_utils_bridge_vlan_verify_list (GPtrArray *vlans, return TRUE; } + +gboolean +nm_utils_connection_is_adhoc_wpa (NMConnection *connection) +{ + NMSettingWireless *s_wifi; + NMSettingWirelessSecurity *s_wsec; + const char *key_mgmt; + const char *mode; + + s_wifi = nm_connection_get_setting_wireless (connection); + if (!s_wifi) + return FALSE; + + mode = nm_setting_wireless_get_mode (s_wifi); + if (!nm_streq0 (mode, NM_SETTING_WIRELESS_MODE_ADHOC)) + return FALSE; + + s_wsec = nm_connection_get_setting_wireless_security (connection); + if (!s_wsec) + return FALSE; + + key_mgmt = nm_setting_wireless_security_get_key_mgmt (s_wsec); + if (!nm_streq0 (key_mgmt, "wpa-none")) + return FALSE; + + return TRUE; +} diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c index 6a14e195c0..0bd0f05cc3 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -711,38 +711,6 @@ pk_add_cb (NMAuthChain *chain, send_agent_owned_secrets (self, added, subject); } -/* FIXME: remove if/when kernel supports adhoc wpa */ -static gboolean -is_adhoc_wpa (NMConnection *connection) -{ - NMSettingWireless *s_wifi; - NMSettingWirelessSecurity *s_wsec; - const char *mode, *key_mgmt; - - /* The kernel doesn't support Ad-Hoc WPA connections well at this time, - * and turns them into open networks. It's been this way since at least - * 2.6.30 or so; until that's fixed, disable WPA-protected Ad-Hoc networks. - */ - - s_wifi = nm_connection_get_setting_wireless (connection); - if (!s_wifi) - return FALSE; - - mode = nm_setting_wireless_get_mode (s_wifi); - if (g_strcmp0 (mode, NM_SETTING_WIRELESS_MODE_ADHOC) != 0) - return FALSE; - - s_wsec = nm_connection_get_setting_wireless_security (connection); - if (!s_wsec) - return FALSE; - - key_mgmt = nm_setting_wireless_security_get_key_mgmt (s_wsec); - if (g_strcmp0 (key_mgmt, "wpa-none") != 0) - return FALSE; - - return TRUE; -} - void nm_settings_add_connection_dbus (NMSettings *self, NMConnection *connection, @@ -772,11 +740,11 @@ nm_settings_add_connection_dbus (NMSettings *self, goto done; } - /* The kernel doesn't support Ad-Hoc WPA connections well at this time, + /* FIXME: The kernel doesn't support Ad-Hoc WPA connections well at this time, * and turns them into open networks. It's been this way since at least * 2.6.30 or so; until that's fixed, disable WPA-protected Ad-Hoc networks. */ - if (is_adhoc_wpa (connection)) { + if (nm_utils_connection_is_adhoc_wpa (connection)) { error = g_error_new_literal (NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, "WPA Ad-Hoc disabled due to kernel bugs"); |