diff options
author | Thomas Haller <thaller@redhat.com> | 2014-07-08 17:22:43 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2014-08-22 15:24:31 +0200 |
commit | f60256e035ff650a86e4a8073d91c512d02bcb4d (patch) | |
tree | e51f7c738c909316fb3fc29440c8e372e00b3817 | |
parent | cf44a15874f09c3d88a60dd4fa0b985bcfbaf8e2 (diff) | |
download | NetworkManager-f60256e035ff650a86e4a8073d91c512d02bcb4d.tar.gz |
libnm-core: stricter verification of NMSettingConnection:type property
Now also verify the 'type' property regardless of existing
@all_settings.
Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r-- | libnm-core/nm-setting-connection.c | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/libnm-core/nm-setting-connection.c b/libnm-core/nm-setting-connection.c index fdfe5f7214..baf94c7250 100644 --- a/libnm-core/nm-setting-connection.c +++ b/libnm-core/nm-setting-connection.c @@ -754,7 +754,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error) _("property is missing")); g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_ID); return FALSE; - } else if (!strlen (priv->id)) { + } else if (!priv->id[0]) { g_set_error_literal (error, NM_SETTING_CONNECTION_ERROR, NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY, @@ -831,35 +831,46 @@ verify (NMSetting *setting, GSList *all_settings, GError **error) _("property is missing")); g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_TYPE); return FALSE; - } else if (!strlen (priv->type)) { - g_set_error_literal (error, - NM_SETTING_CONNECTION_ERROR, - NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY, - _("property is empty")); - g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_TYPE); - return FALSE; - } + } else { + GType base_type; - /* Make sure the corresponding 'type' item is present */ - if (all_settings) { - NMSetting *s_base; + if (!priv->type[0]) { + g_set_error_literal (error, + NM_SETTING_CONNECTION_ERROR, + NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY, + _("property is empty")); + g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_TYPE); + return FALSE; + } - s_base = nm_setting_find_in_list (all_settings, priv->type); - if (!s_base) { + base_type = nm_setting_lookup_type (priv->type); + if (base_type == G_TYPE_INVALID) { g_set_error (error, NM_SETTING_CONNECTION_ERROR, - NM_SETTING_CONNECTION_ERROR_TYPE_SETTING_NOT_FOUND, - _("requires presence of '%s' setting in the connection"), + NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY, + _("connection type '%s' is not valid"), priv->type); g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_TYPE); return FALSE; } - if (!_nm_setting_is_base_type (s_base)) { + if (!_nm_setting_type_is_base_type (base_type)) { g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_CONNECTION_TYPE_INVALID, - _("connection type '%s' is not a base type"), + _("connection type '%s' is not a valid base type"), + priv->type); + g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_TYPE); + return FALSE; + } + + /* Make sure the corresponding 'type' item is present */ + if ( all_settings + && !nm_setting_find_in_list (all_settings, priv->type)) { + g_set_error (error, + NM_SETTING_CONNECTION_ERROR, + NM_SETTING_CONNECTION_ERROR_TYPE_SETTING_NOT_FOUND, + _("requires presence of '%s' setting in the connection"), priv->type); g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_TYPE); return FALSE; |