diff options
Diffstat (limited to 'libnm-util/nm-setting-wireless-security.c')
-rw-r--r-- | libnm-util/nm-setting-wireless-security.c | 441 |
1 files changed, 287 insertions, 154 deletions
diff --git a/libnm-util/nm-setting-wireless-security.c b/libnm-util/nm-setting-wireless-security.c index 9e4beccab..40c561813 100644 --- a/libnm-util/nm-setting-wireless-security.c +++ b/libnm-util/nm-setting-wireless-security.c @@ -19,13 +19,15 @@ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA. * - * (C) Copyright 2007 - 2011 Red Hat, Inc. + * (C) Copyright 2007 - 2014 Red Hat, Inc. * (C) Copyright 2007 - 2008 Novell, Inc. */ #include <config.h> #include <string.h> #include <dbus/dbus-glib.h> +#include <glib/gi18n.h> + #include "nm-setting-wireless-security.h" #include "nm-setting-8021x.h" #include "nm-param-spec-specialized.h" @@ -36,17 +38,17 @@ /** * SECTION:nm-setting-wireless-security - * @short_description: Describes connection properties for WiFi networks that + * @short_description: Describes connection properties for Wi-Fi networks that * use WEP, LEAP, WPA or WPA2/RSN security * @include: nm-setting-wireless-security.h * * The #NMSettingWirelessSecurity object is a #NMSetting subclass that describes - * properties necessary for connection to encrypted WiFi networks. + * properties necessary for connection to encrypted Wi-Fi networks. * * It's a good idea to read up on wpa_supplicant configuration before using this * setting extensively, since most of the options here correspond closely with * the relevant wpa_supplicant configuration options. To get a better overview - * of how WiFi security works, you may want to get copies of the following books. + * of how Wi-Fi security works, you may want to get copies of the following books. * * 802.11 Wireless Networks: The Definitive Guide, Second Edition * Author: Matthew Gast @@ -165,7 +167,7 @@ nm_setting_wireless_security_get_key_mgmt (NMSettingWirelessSecurity *setting) * @setting: the #NMSettingWirelessSecurity * * Returns: the number of security protocols this connection allows when - * connecting to secure WiFi networks + * connecting to secure Wi-Fi networks **/ guint32 nm_setting_wireless_security_get_num_protos (NMSettingWirelessSecurity *setting) @@ -200,9 +202,9 @@ nm_setting_wireless_security_get_proto (NMSettingWirelessSecurity *setting, guin * @setting: the #NMSettingWirelessSecurity * @proto: the protocol to add, one of "wpa" or "rsn" * - * Adds a WiFi security protocol (one of "wpa" or "rsn") to the allowed list; + * Adds a Wi-Fi security protocol (one of "wpa" or "rsn") to the allowed list; * only protocols in this list will be used when finding and connecting to - * the WiFi network specified by this connection. For example, if the + * the Wi-Fi network specified by this connection. For example, if the * protocol list contains only "wpa" but the access point for the SSID specified * by this connection only supports WPA2/RSN, the connection cannot be used * with the access point. @@ -226,6 +228,7 @@ nm_setting_wireless_security_add_proto (NMSettingWirelessSecurity *setting, cons } priv->proto = g_slist_append (priv->proto, g_ascii_strdown (proto, -1)); + g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_PROTO); return TRUE; } @@ -250,6 +253,39 @@ nm_setting_wireless_security_remove_proto (NMSettingWirelessSecurity *setting, g g_free (elt->data); priv->proto = g_slist_delete_link (priv->proto, elt); + g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_PROTO); +} + +/** + * nm_setting_wireless_security_remove_proto_by_value: + * @setting: the #NMSettingWirelessSecurity + * @proto: the protocol to remove, one of "wpa" or "rsn" + * + * Removes a protocol from the allowed protocol list. + * + * Returns: %TRUE if the protocol was found and removed; %FALSE it it was not. + * + * Since: 0.9.10 + **/ +gboolean +nm_setting_wireless_security_remove_proto_by_value (NMSettingWirelessSecurity *setting, + const char *proto) +{ + NMSettingWirelessSecurityPrivate *priv; + GSList *iter; + + g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), FALSE); + g_return_val_if_fail (proto != NULL, FALSE); + + priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting); + for (iter = priv->proto; iter; iter = g_slist_next (iter)) { + if (strcasecmp (proto, (char *) iter->data) == 0) { + priv->proto = g_slist_delete_link (priv->proto, iter); + g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_PROTO); + return TRUE; + } + } + return FALSE; } /** @@ -267,8 +303,9 @@ nm_setting_wireless_security_clear_protos (NMSettingWirelessSecurity *setting) g_return_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting)); priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting); - nm_utils_slist_free (priv->proto, g_free); + g_slist_free_full (priv->proto, g_free); priv->proto = NULL; + g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_PROTO); } /** @@ -311,8 +348,7 @@ nm_setting_wireless_security_get_pairwise (NMSettingWirelessSecurity *setting, g /** * nm_setting_wireless_security_add_pairwise: * @setting: the #NMSettingWirelessSecurity - * @pairwise: the encryption algorithm to add, one of "wep40", "wep104", - * "tkip", or "ccmp" + * @pairwise: the encryption algorithm to add, one of "tkip" or "ccmp" * * Adds an encryption algorithm to the list of allowed pairwise encryption * algorithms. If the list is not empty, then only access points that support @@ -338,6 +374,7 @@ nm_setting_wireless_security_add_pairwise (NMSettingWirelessSecurity *setting, c } priv->pairwise = g_slist_append (priv->pairwise, g_ascii_strdown (pairwise, -1)); + g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_PAIRWISE); return TRUE; } @@ -363,6 +400,40 @@ nm_setting_wireless_security_remove_pairwise (NMSettingWirelessSecurity *setting g_free (elt->data); priv->pairwise = g_slist_delete_link (priv->pairwise, elt); + g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_PAIRWISE); +} + +/** + * nm_setting_wireless_security_remove_pairwise_by_value: + * @setting: the #NMSettingWirelessSecurity + * @pairwise: the encryption algorithm to remove, one of "tkip" or "ccmp" + * + * Removes an encryption algorithm from the allowed pairwise encryption + * algorithm list. + * + * Returns: %TRUE if the encryption algorith was found and removed; %FALSE it it was not. + * + * Since: 0.9.10 + **/ +gboolean +nm_setting_wireless_security_remove_pairwise_by_value (NMSettingWirelessSecurity *setting, + const char *pairwise) +{ + NMSettingWirelessSecurityPrivate *priv; + GSList *iter; + + g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), FALSE); + g_return_val_if_fail (pairwise != NULL, FALSE); + + priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting); + for (iter = priv->pairwise; iter; iter = g_slist_next (iter)) { + if (strcasecmp (pairwise, (char *) iter->data) == 0) { + priv->pairwise = g_slist_delete_link (priv->pairwise, iter); + g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_PAIRWISE); + return TRUE; + } + } + return FALSE; } /** @@ -380,8 +451,9 @@ nm_setting_wireless_security_clear_pairwise (NMSettingWirelessSecurity *setting) g_return_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting)); priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting); - nm_utils_slist_free (priv->pairwise, g_free); + g_slist_free_full (priv->pairwise, g_free); priv->pairwise = NULL; + g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_PAIRWISE); } /** @@ -451,6 +523,7 @@ nm_setting_wireless_security_add_group (NMSettingWirelessSecurity *setting, cons } priv->group = g_slist_append (priv->group, g_ascii_strdown (group, -1)); + g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_GROUP); return TRUE; } @@ -476,6 +549,41 @@ nm_setting_wireless_security_remove_group (NMSettingWirelessSecurity *setting, g g_free (elt->data); priv->group = g_slist_delete_link (priv->group, elt); + g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_GROUP); +} + +/** + * nm_setting_wireless_security_remove_group_by_value: + * @setting: the #NMSettingWirelessSecurity + * @group: the encryption algorithm to remove, one of "wep40", "wep104", + * "tkip", or "ccmp" + * + * Removes an encryption algorithm from the allowed groupwise encryption + * algorithm list. + * + * Returns: %TRUE if the algorithm was found and removed; %FALSE it it was not. + * + * Since: 0.9.10 + **/ +gboolean +nm_setting_wireless_security_remove_group_by_value (NMSettingWirelessSecurity *setting, + const char *group) +{ + NMSettingWirelessSecurityPrivate *priv; + GSList *iter; + + g_return_val_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting), FALSE); + g_return_val_if_fail (group != NULL, FALSE); + + priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting); + for (iter = priv->group; iter; iter = g_slist_next (iter)) { + if (strcasecmp (group, (char *) iter->data) == 0) { + priv->group = g_slist_delete_link (priv->group, iter); + g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_GROUP); + return TRUE; + } + } + return FALSE; } /** @@ -493,8 +601,9 @@ nm_setting_wireless_security_clear_groups (NMSettingWirelessSecurity *setting) g_return_if_fail (NM_IS_SETTING_WIRELESS_SECURITY (setting)); priv = NM_SETTING_WIRELESS_SECURITY_GET_PRIVATE (setting); - nm_utils_slist_free (priv->group, g_free); + g_slist_free_full (priv->group, g_free); priv->group = NULL; + g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_GROUP); } /** @@ -621,18 +730,22 @@ nm_setting_wireless_security_set_wep_key (NMSettingWirelessSecurity *setting, gu case 0: g_free (priv->wep_key0); priv->wep_key0 = g_strdup (key); + g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_WEP_KEY0); break; case 1: g_free (priv->wep_key1); priv->wep_key1 = g_strdup (key); + g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_WEP_KEY1); break; case 2: g_free (priv->wep_key2); priv->wep_key2 = g_strdup (key); + g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_WEP_KEY2); break; case 3: g_free (priv->wep_key3); priv->wep_key3 = g_strdup (key); + g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SECURITY_WEP_KEY3); break; default: g_assert_not_reached (); @@ -703,10 +816,6 @@ need_secrets (NMSetting *setting) GPtrArray *secrets; secrets = g_ptr_array_sized_new (4); - if (!secrets) { - g_warning ("Not enough memory to create required secrets array."); - return NULL; - } g_assert (priv->key_mgmt); @@ -767,15 +876,6 @@ no_secrets: return NULL; } -static gint -find_setting_by_name (gconstpointer a, gconstpointer b) -{ - NMSetting *setting = NM_SETTING (a); - const char *str = (const char *) b; - - return strcmp (nm_setting_get_name (setting), str); -} - static gboolean verify (NMSetting *setting, GSList *all_settings, GError **error) { @@ -784,14 +884,15 @@ verify (NMSetting *setting, GSList *all_settings, GError **error) const char *valid_key_mgmt[] = { "none", "ieee8021x", "wpa-none", "wpa-psk", "wpa-eap", NULL }; const char *valid_auth_algs[] = { "open", "shared", "leap", NULL }; const char *valid_protos[] = { "wpa", "rsn", NULL }; - const char *valid_pairwise[] = { "wep40", "wep104", "tkip", "ccmp", NULL }; + const char *valid_pairwise[] = { "tkip", "ccmp", NULL }; const char *valid_groups[] = { "wep40", "wep104", "tkip", "ccmp", NULL }; if (!priv->key_mgmt) { - g_set_error (error, - NM_SETTING_WIRELESS_SECURITY_ERROR, - NM_SETTING_WIRELESS_SECURITY_ERROR_MISSING_PROPERTY, - NM_SETTING_WIRELESS_SECURITY_KEY_MGMT); + g_set_error_literal (error, + NM_SETTING_WIRELESS_SECURITY_ERROR, + NM_SETTING_WIRELESS_SECURITY_ERROR_MISSING_PROPERTY, + _("property is missing")); + g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT); return FALSE; } @@ -799,7 +900,9 @@ verify (NMSetting *setting, GSList *all_settings, GError **error) g_set_error (error, NM_SETTING_WIRELESS_SECURITY_ERROR, NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, - NM_SETTING_WIRELESS_SECURITY_KEY_MGMT); + _("'%s' is not a valid value for the property"), + priv->key_mgmt); + g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT); return FALSE; } @@ -809,42 +912,49 @@ verify (NMSetting *setting, GSList *all_settings, GError **error) g_set_error (error, NM_SETTING_WIRELESS_SECURITY_ERROR, NM_SETTING_WIRELESS_SECURITY_ERROR_LEAP_REQUIRES_802_1X, - NM_SETTING_WIRELESS_SECURITY_AUTH_ALG); + _("'%s' security requires '%s=%s'"), + "leap", NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x"); + g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_AUTH_ALG); return FALSE; } if (!priv->leap_username) { - g_set_error (error, - NM_SETTING_WIRELESS_SECURITY_ERROR, - NM_SETTING_WIRELESS_SECURITY_ERROR_LEAP_REQUIRES_USERNAME, - NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME); + g_set_error_literal (error, + NM_SETTING_WIRELESS_SECURITY_ERROR, + NM_SETTING_WIRELESS_SECURITY_ERROR_LEAP_REQUIRES_USERNAME, + _("property is empty")); + g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME); return FALSE; } if (priv->leap_password && !strlen (priv->leap_password)) { - g_set_error (error, - NM_SETTING_WIRELESS_SECURITY_ERROR, - NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, - NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD); + g_set_error_literal (error, + NM_SETTING_WIRELESS_SECURITY_ERROR, + NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, + _("property is empty")); + g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD); return FALSE; } } else { if ( (strcmp (priv->key_mgmt, "ieee8021x") == 0) || (strcmp (priv->key_mgmt, "wpa-eap") == 0)) { /* Need an 802.1x setting too */ - if (!g_slist_find_custom (all_settings, NM_SETTING_802_1X_SETTING_NAME, find_setting_by_name)) { + if (!nm_setting_find_in_list (all_settings, NM_SETTING_802_1X_SETTING_NAME)) { g_set_error (error, NM_SETTING_WIRELESS_SECURITY_ERROR, NM_SETTING_WIRELESS_SECURITY_ERROR_MISSING_802_1X_SETTING, - NULL); + _("'%s' security requires '%s' setting presence"), + priv->key_mgmt, NM_SETTING_802_1X_SETTING_NAME); + g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT); return FALSE; } } } if (priv->leap_username && !strlen (priv->leap_username)) { - g_set_error (error, - NM_SETTING_WIRELESS_SECURITY_ERROR, - NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, - NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME); + g_set_error_literal (error, + NM_SETTING_WIRELESS_SECURITY_ERROR, + NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, + _("property is empty")); + g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME); return FALSE; } @@ -852,68 +962,78 @@ verify (NMSetting *setting, GSList *all_settings, GError **error) g_set_error (error, NM_SETTING_WIRELESS_SECURITY_ERROR, NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, - NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX); + _("'%d' value is out of range <0-3>"), + priv->wep_tx_keyidx); + g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX); return FALSE; } if (priv->wep_key_type > NM_WEP_KEY_TYPE_LAST) { - g_set_error (error, - NM_SETTING_WIRELESS_SECURITY_ERROR, - NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, - NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE); + g_set_error_literal (error, + NM_SETTING_WIRELESS_SECURITY_ERROR, + NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, + _("property is invalid")); + g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE); return FALSE; } if (priv->wep_key0 && !nm_utils_wep_key_valid (priv->wep_key0, priv->wep_key_type)) { - g_set_error (error, - NM_SETTING_WIRELESS_SECURITY_ERROR, - NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, - NM_SETTING_WIRELESS_SECURITY_WEP_KEY0); + g_set_error_literal (error, + NM_SETTING_WIRELESS_SECURITY_ERROR, + NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, + _("property is invalid")); + g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0); return FALSE; } if (priv->wep_key1 && !nm_utils_wep_key_valid (priv->wep_key1, priv->wep_key_type)) { - g_set_error (error, - NM_SETTING_WIRELESS_SECURITY_ERROR, - NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, - NM_SETTING_WIRELESS_SECURITY_WEP_KEY1); + g_set_error_literal (error, + NM_SETTING_WIRELESS_SECURITY_ERROR, + NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, + _("property is invalid")); + g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_WEP_KEY1); return FALSE; } if (priv->wep_key2 && !nm_utils_wep_key_valid (priv->wep_key2, priv->wep_key_type)) { - g_set_error (error, - NM_SETTING_WIRELESS_SECURITY_ERROR, - NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, - NM_SETTING_WIRELESS_SECURITY_WEP_KEY2); + g_set_error_literal (error, + NM_SETTING_WIRELESS_SECURITY_ERROR, + NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, + _("property is invalid")); + g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_WEP_KEY2); return FALSE; } if (priv->wep_key3 && !nm_utils_wep_key_valid (priv->wep_key3, priv->wep_key_type)) { - g_set_error (error, - NM_SETTING_WIRELESS_SECURITY_ERROR, - NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, - NM_SETTING_WIRELESS_SECURITY_WEP_KEY3); + g_set_error_literal (error, + NM_SETTING_WIRELESS_SECURITY_ERROR, + NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, + _("property is invalid")); + g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_WEP_KEY3); return FALSE; } if (priv->auth_alg && !_nm_utils_string_in_list (priv->auth_alg, valid_auth_algs)) { - g_set_error (error, - NM_SETTING_WIRELESS_SECURITY_ERROR, - NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, - NM_SETTING_WIRELESS_SECURITY_AUTH_ALG); + g_set_error_literal (error, + NM_SETTING_WIRELESS_SECURITY_ERROR, + NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, + _("property is invalid")); + g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_AUTH_ALG); return FALSE; } if (priv->psk && !nm_utils_wpa_psk_valid (priv->psk)) { - g_set_error (error, - NM_SETTING_WIRELESS_SECURITY_ERROR, - NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, - NM_SETTING_WIRELESS_SECURITY_PSK); + g_set_error_literal (error, + NM_SETTING_WIRELESS_SECURITY_ERROR, + NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, + _("property is invalid")); + g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_PSK); return FALSE; } if (priv->proto && !_nm_utils_string_slist_validate (priv->proto, valid_protos)) { - g_set_error (error, - NM_SETTING_WIRELESS_SECURITY_ERROR, - NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, - NM_SETTING_WIRELESS_SECURITY_PROTO); + g_set_error_literal (error, + NM_SETTING_WIRELESS_SECURITY_ERROR, + NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, + _("property is invalid")); + g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_PROTO); return FALSE; } @@ -939,23 +1059,27 @@ verify (NMSetting *setting, GSList *all_settings, GError **error) g_set_error (error, NM_SETTING_WIRELESS_SECURITY_ERROR, NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, - NM_SETTING_WIRELESS_SECURITY_PAIRWISE); + _("'%s' connections require '%s' in this property"), + NM_SETTING_WIRELESS_MODE_ADHOC, "none"); + g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_PAIRWISE); return FALSE; } } else if (!_nm_utils_string_slist_validate (priv->pairwise, valid_pairwise)) { - g_set_error (error, - NM_SETTING_WIRELESS_SECURITY_ERROR, - NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, - NM_SETTING_WIRELESS_SECURITY_PAIRWISE); + g_set_error_literal (error, + NM_SETTING_WIRELESS_SECURITY_ERROR, + NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, + _("property is invalid")); + g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_PAIRWISE); return FALSE; } } if (priv->group && !_nm_utils_string_slist_validate (priv->group, valid_groups)) { - g_set_error (error, - NM_SETTING_WIRELESS_SECURITY_ERROR, - NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, - NM_SETTING_WIRELESS_SECURITY_GROUP); + g_set_error_literal (error, + NM_SETTING_WIRELESS_SECURITY_ERROR, + NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, + _("property is invalid")); + g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_GROUP); return FALSE; } @@ -965,7 +1089,9 @@ verify (NMSetting *setting, GSList *all_settings, GError **error) g_set_error (error, NM_SETTING_WIRELESS_SECURITY_ERROR, NM_SETTING_WIRELESS_SECURITY_ERROR_SHARED_KEY_REQUIRES_WEP, - NM_SETTING_WIRELESS_SECURITY_AUTH_ALG); + _("'%s' can only be used with '%s=%s' (WEP)"), + "shared", NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none"); + g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_AUTH_ALG); return FALSE; } } @@ -1028,7 +1154,6 @@ set_secret_flags (NMSetting *setting, static void nm_setting_wireless_security_init (NMSettingWirelessSecurity *setting) { - g_object_set (setting, NM_SETTING_NAME, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NULL); } static void @@ -1049,9 +1174,9 @@ finalize (GObject *object) g_free (priv->psk); g_free (priv->leap_password); - nm_utils_slist_free (priv->proto, g_free); - nm_utils_slist_free (priv->pairwise, g_free); - nm_utils_slist_free (priv->group, g_free); + g_slist_free_full (priv->proto, g_free); + g_slist_free_full (priv->pairwise, g_free); + g_slist_free_full (priv->group, g_free); G_OBJECT_CLASS (nm_setting_wireless_security_parent_class)->finalize (object); } @@ -1079,15 +1204,15 @@ set_property (GObject *object, guint prop_id, priv->auth_alg = str ? g_ascii_strdown (str, -1) : NULL; break; case PROP_PROTO: - nm_utils_slist_free (priv->proto, g_free); + g_slist_free_full (priv->proto, g_free); priv->proto = g_value_dup_boxed (value); break; case PROP_PAIRWISE: - nm_utils_slist_free (priv->pairwise, g_free); + g_slist_free_full (priv->pairwise, g_free); priv->pairwise = g_value_dup_boxed (value); break; case PROP_GROUP: - nm_utils_slist_free (priv->group, g_free); + g_slist_free_full (priv->group, g_free); priv->group = g_value_dup_boxed (value); break; case PROP_LEAP_USERNAME: @@ -1095,16 +1220,20 @@ set_property (GObject *object, guint prop_id, priv->leap_username = g_value_dup_string (value); break; case PROP_WEP_KEY0: - nm_setting_wireless_security_set_wep_key (setting, 0, g_value_get_string (value)); + g_free (priv->wep_key0); + priv->wep_key0 = g_value_dup_string (value); break; case PROP_WEP_KEY1: - nm_setting_wireless_security_set_wep_key (setting, 1, g_value_get_string (value)); + g_free (priv->wep_key1); + priv->wep_key1 = g_value_dup_string (value); break; case PROP_WEP_KEY2: - nm_setting_wireless_security_set_wep_key (setting, 2, g_value_get_string (value)); + g_free (priv->wep_key2); + priv->wep_key2 = g_value_dup_string (value); break; case PROP_WEP_KEY3: - nm_setting_wireless_security_set_wep_key (setting, 3, g_value_get_string (value)); + g_free (priv->wep_key3); + priv->wep_key3 = g_value_dup_string (value); break; case PROP_WEP_KEY_FLAGS: priv->wep_key_flags = g_value_get_uint (value); @@ -1219,10 +1348,10 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *setting /** * NMSettingWirelessSecurity:key-mgmt: * - * Key management used for the connection. One of 'none' (WEP), 'ieee8021x' - * (Dynamic WEP), 'wpa-none' (Ad-Hoc WPA-PSK), 'wpa-psk' (infrastructure - * WPA-PSK), or 'wpa-eap' (WPA-Enterprise). This property must be set for - * any WiFi connection that uses security. + * Key management used for the connection. One of "none" (WEP), "ieee8021x" + * (Dynamic WEP), "wpa-none" (Ad-Hoc WPA-PSK), "wpa-psk" (infrastructure + * WPA-PSK), or "wpa-eap" (WPA-Enterprise). This property must be set for + * any Wi-Fi connection that uses security. **/ g_object_class_install_property (object_class, PROP_KEY_MGMT, @@ -1232,14 +1361,14 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *setting "'none' (WEP), 'ieee8021x' (Dynamic WEP), 'wpa-none' " "(WPA-PSK Ad-Hoc), 'wpa-psk' (infrastructure WPA-PSK), " "or 'wpa-eap' (WPA-Enterprise). This property must " - "be set for any WiFi connection that uses security.", + "be set for any Wi-Fi connection that uses security.", NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_REQUIRED)); + G_PARAM_READWRITE | NM_SETTING_PARAM_REQUIRED)); /** * NMSettingWirelessSecurity:wep-tx-keyidx: * - * When static WEP is used (ie, key-mgmt = 'none') and a non-default WEP key + * When static WEP is used (ie, key-mgmt = "none") and a non-default WEP key * index is used by the AP, put that WEP key index here. Valid values are 0 * (default key) through 3. Note that some consumer access points (like the * Linksys WRT54G) number the keys 1 - 4. @@ -1254,16 +1383,16 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *setting "through 3. Note that some consumer access points " "(like the Linksys WRT54G) number the keys 1 - 4.", 0, 3, 0, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_SERIALIZE)); + G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); /** * NMSettingWirelessSecurity:auth-alg: * - * When WEP is used (ie, key-mgmt = 'none' or 'ieee8021x') indicate the - * 802.11 authentication algorithm required by the AP here. One of 'open' - * for Open System, 'shared' for Shared Key, or 'leap' for Cisco LEAP. - * When using Cisco LEAP (ie, key-mgmt = 'ieee8021x' and auth-alg = 'leap') - * the 'leap-username' and 'leap-password' properties must be specified. + * When WEP is used (ie, key-mgmt = "none" or "ieee8021x") indicate the + * 802.11 authentication algorithm required by the AP here. One of "open" + * for Open System, "shared" for Shared Key, or "leap" for Cisco LEAP. When + * using Cisco LEAP (ie, key-mgmt = "ieee8021x" and auth-alg = "leap") the + * "leap-username" and "leap-password" properties must be specified. **/ g_object_class_install_property (object_class, PROP_AUTH_ALG, @@ -1277,13 +1406,13 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *setting "'ieee8021x' and auth-alg = 'leap') the 'leap-username' " "and 'leap-password' properties must be specified.", NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE)); + G_PARAM_READWRITE)); /** * NMSettingWirelessSecurity:proto: * * List of strings specifying the allowed WPA protocol versions to use. - * Each element may be one 'wpa' (allow WPA) or 'rsn' (allow WPA2/RSN). If + * Each element may be one "wpa" (allow WPA) or "rsn" (allow WPA2/RSN). If * not specified, both WPA and RSN connections are allowed. **/ g_object_class_install_property @@ -1296,15 +1425,15 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *setting "WPA2/RSN). If not specified, both WPA and RSN " "connections are allowed.", DBUS_TYPE_G_LIST_OF_STRING, - G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE)); + G_PARAM_READWRITE)); /** * NMSettingWirelessSecurity:pairwise: * * A list of pairwise encryption algorithms which prevents connections to - * Wi-Fi networks that do not utilize one of the algorithms in the list. For - * maximum compatibility leave this property empty. Each list element may - * be one of 'wep40', 'wep104', 'tkip', or 'ccmp'. + * Wi-Fi networks that do not utilize one of the algorithms in the list. + * For maximum compatibility leave this property empty. Each list element + * may be one of "tkip" or "ccmp". **/ g_object_class_install_property (object_class, PROP_PAIRWISE, @@ -1314,10 +1443,10 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *setting "prevents connections to Wi-Fi networks that do " "not utilize one of the algorithms in the list. " "For maximum compatibility leave this property " - "empty. Each list element may be one of 'wep40', " - "'wep104', 'tkip' or 'ccmp'.", + "empty. Each list element may be one of 'tkip' " + "or 'ccmp'.", DBUS_TYPE_G_LIST_OF_STRING, - G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE)); + G_PARAM_READWRITE)); /** * NMSettingWirelessSecurity:group: @@ -1325,7 +1454,7 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *setting * A list of group/broadcast encryption algorithms which prevents * connections to Wi-Fi networks that do not utilize one of the algorithms * in the list. For maximum compatibility leave this property empty. Each - * list element may be one of 'wep40', 'wep104', 'tkip', or 'ccmp'. + * list element may be one of "wep40", "wep104", "tkip", or "ccmp". **/ g_object_class_install_property (object_class, PROP_GROUP, @@ -1338,13 +1467,13 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *setting "property empty. Each list element may be one " " of 'wep40', 'wep104', 'tkip', or 'ccmp'.", DBUS_TYPE_G_LIST_OF_STRING, - G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE)); + G_PARAM_READWRITE)); /** * NMSettingWirelessSecurity:leap-username: * * The login username for legacy LEAP connections (ie, key-mgmt = - * 'ieee8021x' and auth-alg = 'leap'). + * "ieee8021x" and auth-alg = "leap"). **/ g_object_class_install_property (object_class, PROP_LEAP_USERNAME, @@ -1353,13 +1482,13 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *setting "The login username for legacy LEAP connections " "(ie, key-mgmt = 'ieee8021x' and auth-alg = 'leap').", NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE)); + G_PARAM_READWRITE)); /** * NMSettingWirelessSecurity:wep-key0: * * Index 0 WEP key. This is the WEP key used in most networks. See the - * 'wep-key-type' property for a description of how this key is interpreted. + * "wep-key-type" property for a description of how this key is interpreted. **/ g_object_class_install_property (object_class, PROP_WEP_KEY0, @@ -1369,13 +1498,13 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *setting "networks. See the 'wep-key-type' property for a " "description of how this key is interpreted.", NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_SECRET)); + G_PARAM_READWRITE | NM_SETTING_PARAM_SECRET)); /** * NMSettingWirelessSecurity:wep-key1: * * Index 1 WEP key. This WEP index is not used by most networks. See the - * 'wep-key-type' property for a description of how this key is interpreted. + * "wep-key-type" property for a description of how this key is interpreted. **/ g_object_class_install_property (object_class, PROP_WEP_KEY1, @@ -1385,13 +1514,13 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *setting "networks. See the 'wep-key-type' property for a " "description of how this key is interpreted.", NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_SECRET)); + G_PARAM_READWRITE | NM_SETTING_PARAM_SECRET)); /** * NMSettingWirelessSecurity:wep-key2: * * Index 2 WEP key. This WEP index is not used by most networks. See the - * 'wep-key-type' property for a description of how this key is interpreted. + * "wep-key-type" property for a description of how this key is interpreted. **/ g_object_class_install_property (object_class, PROP_WEP_KEY2, @@ -1401,13 +1530,13 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *setting "networks. See the 'wep-key-type' property for a " "description of how this key is interpreted.", NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_SECRET)); + G_PARAM_READWRITE | NM_SETTING_PARAM_SECRET)); /** * NMSettingWirelessSecurity:wep-key3: * * Index 3 WEP key. This WEP index is not used by most networks. See the - * 'wep-key-type' property for a description of how this key is interpreted. + * "wep-key-type" property for a description of how this key is interpreted. **/ g_object_class_install_property (object_class, PROP_WEP_KEY3, @@ -1417,12 +1546,14 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *setting "networks. See the 'wep-key-type' property for a " "description of how this key is interpreted.", NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_SECRET)); + G_PARAM_READWRITE | NM_SETTING_PARAM_SECRET)); /** * NMSettingWirelessSecurity:wep-key-flags: * - * Flags indicating how to handle #NMSettingWirelessSecurity WEP keys. + * Flags indicating how to handle the #NMSettingWirelessSecurity:wep-key0, + * #NMSettingWirelessSecurity:wep-key1, #NMSettingWirelessSecurity:wep-key2, + * and #NMSettingWirelessSecurity:wep-key3 properties. **/ g_object_class_install_property (object_class, PROP_WEP_KEY_FLAGS, g_param_spec_uint (NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS, @@ -1431,7 +1562,7 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *setting NM_SETTING_SECRET_FLAG_NONE, NM_SETTING_SECRET_FLAGS_ALL, NM_SETTING_SECRET_FLAG_NONE, - G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE)); + G_PARAM_READWRITE)); /** * NMSettingWirelessSecurity:psk: @@ -1439,9 +1570,9 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *setting * Pre-Shared-Key for WPA networks. If the key is 64-characters long, it * must contain only hexadecimal characters and is interpreted as a * hexadecimal WPA key. Otherwise, the key must be between 8 and 63 ASCII - * characters (as specified in the 802.11i standard) and is interpreted as - * a WPA passphrase, and is hashed to derive the actual WPA-PSK used when - * connecting to the WiFi network. + * characters (as specified in the 802.11i standard) and is interpreted as a + * WPA passphrase, and is hashed to derive the actual WPA-PSK used when + * connecting to the Wi-Fi network. **/ g_object_class_install_property (object_class, PROP_PSK, @@ -1454,14 +1585,15 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *setting "ASCII characters (as specified in the 802.11i standard) " "and is interpreted as a WPA passphrase, and is hashed " "to derive the actual WPA-PSK used when connecting to " - "the WiFi network.", + "the Wi-Fi network.", NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_SECRET)); + G_PARAM_READWRITE | NM_SETTING_PARAM_SECRET)); /** * NMSettingWirelessSecurity:psk-flags: * - * Flags indicating how to handle #NMSettingWirelessSecurity:psk + * Flags indicating how to handle the #NMSettingWirelessSecurity:psk + * property. **/ g_object_class_install_property (object_class, PROP_PSK_FLAGS, g_param_spec_uint (NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS, @@ -1470,13 +1602,13 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *setting NM_SETTING_SECRET_FLAG_NONE, NM_SETTING_SECRET_FLAGS_ALL, NM_SETTING_SECRET_FLAG_NONE, - G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE)); + G_PARAM_READWRITE)); /** * NMSettingWirelessSecurity:leap-password: * * The login password for legacy LEAP connections (ie, key-mgmt = - * 'ieee8021x' and auth-alg = 'leap'). + * "ieee8021x" and auth-alg = "leap"). **/ g_object_class_install_property (object_class, PROP_LEAP_PASSWORD, @@ -1485,12 +1617,13 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *setting "The login password for legacy LEAP connections " "(ie, key-mgmt = 'ieee8021x' and auth-alg = 'leap').", NULL, - G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_SECRET)); + G_PARAM_READWRITE | NM_SETTING_PARAM_SECRET)); /** * NMSettingWirelessSecurity:leap-password-flags: * - * Flags indicating how to handle #NMSettingWirelessSecurity:leap-password. + * Flags indicating how to handle the + * #NMSettingWirelessSecurity:leap-password property. **/ g_object_class_install_property (object_class, PROP_LEAP_PASSWORD_FLAGS, g_param_spec_uint (NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS, @@ -1499,17 +1632,17 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *setting NM_SETTING_SECRET_FLAG_NONE, NM_SETTING_SECRET_FLAGS_ALL, NM_SETTING_SECRET_FLAG_NONE, - G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE)); + G_PARAM_READWRITE)); /** * NMSettingWirelessSecurity:wep-key-type: * - * Controls the interpretation of WEP keys. Allowed values are those given - * by %NMWepKeyType. If set to 1 and the keys are hexadecimal, they must be - * either 10 or 26 characters in length. If set to 1 and the keys are - * ASCII keys, they must be either 5 or 13 characters in length. If set to - * 2, the passphrase is hashed using the de-facto MD5 method to derive the - * actual WEP key. + * Controls the interpretation of WEP keys. Allowed values are + * %NM_WEP_KEY_TYPE_KEY, in which case the key is either a 10- or + * 26-character hexadecimal string, or a 5- or 13-character ASCII password; + * or %NM_WEP_KEY_TYPE_PASSPHRASE, in which case the passphrase is provided + * as a string and will be hashed using the de-facto MD5 method to derive + * the actual WEP key. **/ g_object_class_install_property (object_class, PROP_WEP_KEY_TYPE, @@ -1526,5 +1659,5 @@ nm_setting_wireless_security_class_init (NMSettingWirelessSecurityClass *setting NM_WEP_KEY_TYPE_UNKNOWN, NM_WEP_KEY_TYPE_LAST, NM_WEP_KEY_TYPE_UNKNOWN, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_SERIALIZE)); + G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); } |