summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-01-28 00:36:08 +0100
committerThomas Haller <thaller@redhat.com>2019-02-01 17:02:57 +0100
commitefbcac25b8f087211039874abd9b03afd3f1c5c6 (patch)
tree352317d2c9d474f308136f1da6fef4716d6cb1bf
parentab5b6f6f8130c809cc5c598e996db3c77b503c1d (diff)
downloadNetworkManager-efbcac25b8f087211039874abd9b03afd3f1c5c6.tar.gz
libnm-core: fix and cleanup validation of WPS-method for Wi-Fi P2P setting
The check for Wi-Fi P2P's wps-method was not correct. While at it, move the logic to validate WPS-method flags in an utility function.
-rw-r--r--libnm-core/nm-setting-p2p-wireless.c27
-rw-r--r--libnm-core/nm-setting-wireless-security.c22
-rw-r--r--libnm-core/nm-utils-private.h6
-rw-r--r--libnm-core/nm-utils.c40
4 files changed, 56 insertions, 39 deletions
diff --git a/libnm-core/nm-setting-p2p-wireless.c b/libnm-core/nm-setting-p2p-wireless.c
index 32597e1dde..e791749bfd 100644
--- a/libnm-core/nm-setting-p2p-wireless.c
+++ b/libnm-core/nm-setting-p2p-wireless.c
@@ -134,29 +134,12 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
return FALSE;
}
- if (priv->wps_method > NM_SETTING_WIRELESS_SECURITY_WPS_METHOD_PIN) {
- g_set_error_literal (error,
- NM_CONNECTION_ERROR,
- NM_CONNECTION_ERROR_INVALID_PROPERTY,
- _("property is invalid"));
+ if (!_nm_utils_wps_method_validate (priv->wps_method,
+ NM_SETTING_P2P_WIRELESS_SETTING_NAME,
+ NM_SETTING_P2P_WIRELESS_WPS_METHOD,
+ TRUE,
+ error))
return FALSE;
- }
-
- if (priv->wps_method > NM_SETTING_WIRELESS_SECURITY_WPS_METHOD_DISABLED) {
- g_set_error_literal (error,
- NM_CONNECTION_ERROR,
- NM_CONNECTION_ERROR_INVALID_PROPERTY,
- _("P2P connections require WPS"));
- return FALSE;
- }
-
- if (priv->wps_method > NM_SETTING_WIRELESS_SECURITY_WPS_METHOD_DISABLED) {
- g_set_error_literal (error,
- NM_CONNECTION_ERROR,
- NM_CONNECTION_ERROR_INVALID_PROPERTY,
- _("P2P connections require WPS"));
- return FALSE;
- }
return TRUE;
}
diff --git a/libnm-core/nm-setting-wireless-security.c b/libnm-core/nm-setting-wireless-security.c
index fe339d9e36..c38d21ff10 100644
--- a/libnm-core/nm-setting-wireless-security.c
+++ b/libnm-core/nm-setting-wireless-security.c
@@ -1084,24 +1084,12 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
return FALSE;
}
- /* WPS */
- if (priv->wps_method > NM_SETTING_WIRELESS_SECURITY_WPS_METHOD_PIN) {
- g_set_error_literal (error,
- NM_CONNECTION_ERROR,
- NM_CONNECTION_ERROR_INVALID_PROPERTY,
- _("property is invalid"));
- g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_WPS_METHOD);
- return FALSE;
- }
-
- if (priv->wps_method & NM_SETTING_WIRELESS_SECURITY_WPS_METHOD_DISABLED && priv->wps_method != NM_SETTING_WIRELESS_SECURITY_WPS_METHOD_DISABLED) {
- g_set_error_literal (error,
- NM_CONNECTION_ERROR,
- NM_CONNECTION_ERROR_INVALID_PROPERTY,
- _("can't be simultaneously disabled and enabled"));
- g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_WPS_METHOD);
+ if (!_nm_utils_wps_method_validate (priv->wps_method,
+ NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
+ NM_SETTING_WIRELESS_SECURITY_WPS_METHOD,
+ FALSE,
+ error))
return FALSE;
- }
return TRUE;
}
diff --git a/libnm-core/nm-utils-private.h b/libnm-core/nm-utils-private.h
index 58822cdeff..b61260cb22 100644
--- a/libnm-core/nm-utils-private.h
+++ b/libnm-core/nm-utils-private.h
@@ -41,6 +41,12 @@ struct _NMVariantAttributeSpec {
gboolean _nm_utils_string_slist_validate (GSList *list,
const char **valid_values);
+gboolean _nm_utils_wps_method_validate (NMSettingWirelessSecurityWpsMethod wps_method,
+ const char *setting_name,
+ const char *property_name,
+ gboolean wps_required,
+ GError **error);
+
/* D-Bus transform funcs */
GVariant *_nm_utils_hwaddr_cloned_get (NMSetting *setting,
diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c
index 4709971281..bb43a9aec0 100644
--- a/libnm-core/nm-utils.c
+++ b/libnm-core/nm-utils.c
@@ -4311,6 +4311,46 @@ _nm_utils_hwaddr_from_dbus (GVariant *dbus_value,
/*****************************************************************************/
+gboolean
+_nm_utils_wps_method_validate (NMSettingWirelessSecurityWpsMethod wps_method,
+ const char *setting_name,
+ const char *property_name,
+ gboolean wps_required,
+ GError **error)
+{
+ if (wps_method > NM_SETTING_WIRELESS_SECURITY_WPS_METHOD_PIN) {
+ g_set_error_literal (error,
+ NM_CONNECTION_ERROR,
+ NM_CONNECTION_ERROR_INVALID_PROPERTY,
+ _("property is invalid"));
+ g_prefix_error (error, "%s.%s: ", setting_name, property_name);
+ return FALSE;
+ }
+
+ if (NM_FLAGS_HAS (wps_method, NM_SETTING_WIRELESS_SECURITY_WPS_METHOD_DISABLED)) {
+ if (wps_method != NM_SETTING_WIRELESS_SECURITY_WPS_METHOD_DISABLED) {
+ g_set_error_literal (error,
+ NM_CONNECTION_ERROR,
+ NM_CONNECTION_ERROR_INVALID_PROPERTY,
+ _("can't be simultaneously disabled and enabled"));
+ g_prefix_error (error, "%s.%s: ", setting_name, property_name);
+ return FALSE;
+ }
+ if (wps_required) {
+ g_set_error_literal (error,
+ NM_CONNECTION_ERROR,
+ NM_CONNECTION_ERROR_INVALID_PROPERTY,
+ _("WPS is required"));
+ g_prefix_error (error, "%s.%s: ", setting_name, property_name);
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+/*****************************************************************************/
+
static char *
_split_word (char *s)
{