diff options
author | Thomas Haller <thaller@redhat.com> | 2015-09-11 23:12:24 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-09-11 23:12:24 +0200 |
commit | 2805bf20329cd50578d4fcaf70ef456c200c15bc (patch) | |
tree | e23d9c6f7fbc91ca7bd4419611708a18a496bbe7 | |
parent | eaf99061fba3cde9b94d3b802ff0e7d17bdfd41b (diff) | |
parent | bd20efeb915a6f2959e061f75a84abe23fea39e6 (diff) | |
download | network-manager-applet-2805bf20329cd50578d4fcaf70ef456c200c15bc.tar.gz |
c-e: merge branch 'th/validation-error-bgo754832'
https://bugzilla.gnome.org/show_bug.cgi?id=754832
46 files changed, 388 insertions, 237 deletions
diff --git a/src/connection-editor/ce-page.c b/src/connection-editor/ce-page.c index 5fa84839..2a2cf515 100644 --- a/src/connection-editor/ce-page.c +++ b/src/connection-editor/ce-page.c @@ -128,8 +128,13 @@ ce_page_validate (CEPage *self, NMConnection *connection, GError **error) g_return_val_if_fail (CE_IS_PAGE (self), FALSE); g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE); - if (CE_PAGE_GET_CLASS (self)->validate) - return CE_PAGE_GET_CLASS (self)->validate (self, connection, error); + if (CE_PAGE_GET_CLASS (self)->ce_page_validate_v) { + if (!CE_PAGE_GET_CLASS (self)->ce_page_validate_v (self, connection, error)) { + if (error && !*error) + g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("unspecified error")); + return FALSE; + } + } return TRUE; } @@ -210,18 +215,51 @@ ce_page_setup_mac_combo (CEPage *self, GtkComboBox *combo, } gboolean -ce_page_mac_entry_valid (GtkEntry *entry, int type) +ce_page_mac_entry_valid (GtkEntry *entry, int type, const char *property_name, GError **error) { const char *mac; - g_return_val_if_fail (entry != NULL, FALSE); g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE); mac = gtk_entry_get_text (entry); - if (!mac || !*mac) - return TRUE; + if (mac && *mac) { + if (!nm_utils_hwaddr_valid (mac, nm_utils_hwaddr_len (type))) { + const char *addr_type; + + addr_type = type == ARPHRD_ETHER ? _("MAC address") : _("HW addreess"); + if (property_name) { + g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, + _("invalid %s for %s (%s)"), + addr_type, property_name, mac); + } else { + g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, + _("invalid %s (%s)"), + addr_type, mac); + } + return FALSE; + } + } + return TRUE; +} - return nm_utils_hwaddr_valid (mac, nm_utils_hwaddr_len (type)); +gboolean +ce_page_interface_name_valid (const char *iface, const char *property_name, GError **error) +{ + if (iface && *iface) { + if (!nm_utils_iface_valid_name (iface)) { + if (property_name) { + g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, + _("invalid interface-name for %s (%s)"), + property_name, iface); + } else { + g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, + _("invalid interface-name (%s)"), + iface); + } + return FALSE; + } + } + return TRUE; } static char ** @@ -376,16 +414,19 @@ ce_page_setup_device_combo (CEPage *self, } gboolean -ce_page_device_entry_get (GtkEntry *entry, int type, char **ifname, char **mac) +ce_page_device_entry_get (GtkEntry *entry, int type, char **ifname, char **mac, const char *device_name, GError **error) { char *first, *second; const char *ifname_tmp = NULL, *mac_tmp = NULL; gboolean valid = TRUE; + const char *str; g_return_val_if_fail (entry != NULL, FALSE); g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE); - valid = _device_entry_parse (gtk_entry_get_text (entry), &first, &second); + str = gtk_entry_get_text (entry); + + valid = _device_entry_parse (str, &first, &second); if (first) { if (nm_utils_hwaddr_valid (first, nm_utils_hwaddr_len (type))) @@ -418,6 +459,13 @@ ce_page_device_entry_get (GtkEntry *entry, int type, char **ifname, char **mac) g_free (first); g_free (second); + if (!valid) { + g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, + _("invalid %s (%s)"), + device_name ? device_name : _("device"), + str); + } + return valid; } diff --git a/src/connection-editor/ce-page.h b/src/connection-editor/ce-page.h index 1251aea5..2c115142 100644 --- a/src/connection-editor/ce-page.h +++ b/src/connection-editor/ce-page.h @@ -78,7 +78,7 @@ typedef struct { GObjectClass parent; /* Virtual functions */ - gboolean (*validate) (CEPage *self, NMConnection *connection, GError **error); + gboolean (*ce_page_validate_v) (CEPage *self, NMConnection *connection, GError **error); gboolean (*last_update) (CEPage *self, NMConnection *connection, GError **error); /* Signals */ @@ -114,9 +114,12 @@ void ce_page_setup_device_combo (CEPage *self, const char *mac, const char *mac_property, gboolean ifname_first); -gboolean ce_page_mac_entry_valid (GtkEntry *entry, int type); +gboolean ce_page_mac_entry_valid (GtkEntry *entry, int type, const char *property_name, GError **error); +gboolean ce_page_interface_name_valid (const char *iface, const char *property_name, GError **error); gboolean ce_page_device_entry_get (GtkEntry *entry, int type, - char **ifname, char **mac); + char **ifname, char **mac, + const char *device_name, + GError **error); void ce_page_changed (CEPage *self); diff --git a/src/connection-editor/ce-polkit-button.c b/src/connection-editor/ce-polkit-button.c index c72177f0..2269eb59 100644 --- a/src/connection-editor/ce-polkit-button.c +++ b/src/connection-editor/ce-polkit-button.c @@ -34,18 +34,15 @@ G_DEFINE_TYPE (CEPolkitButton, ce_polkit_button, GTK_TYPE_BUTTON) typedef struct { char *tooltip; char *auth_tooltip; - gboolean master_sensitive; + char *validation_error; GtkWidget *stock; GtkWidget *auth; NMClient *client; NMClientPermission permission; - /* authorized = TRUE if either explicitly authorized or if the action - * could be performed if the user successfully authenticated to gain the - * authorization. - */ - gboolean authorized; + + NMClientPermissionResult permission_result; guint perm_id; } CEPolkitButtonPrivate; @@ -59,19 +56,28 @@ enum { static guint signals[LAST_SIGNAL] = { 0 }; static void -update_button (CEPolkitButton *self, gboolean actionable) +update_button (CEPolkitButton *self) { CEPolkitButtonPrivate *priv = CE_POLKIT_BUTTON_GET_PRIVATE (self); + gboolean actionable; + + actionable = ce_polkit_button_get_actionable (self); gtk_widget_set_sensitive (GTK_WIDGET (self), actionable); - if (priv->authorized) { + if (priv->validation_error) + gtk_widget_set_tooltip_text (GTK_WIDGET (self), priv->validation_error); + else if (priv->permission_result == NM_CLIENT_PERMISSION_RESULT_AUTH) gtk_widget_set_tooltip_text (GTK_WIDGET (self), priv->auth_tooltip); - gtk_button_set_image (GTK_BUTTON (self), priv->auth); - } else { + else if (priv->permission_result == NM_CLIENT_PERMISSION_RESULT_YES) gtk_widget_set_tooltip_text (GTK_WIDGET (self), priv->tooltip); + else + gtk_widget_set_tooltip_text (GTK_WIDGET (self), _("No polkit authorization to perform the action")); + + if (priv->permission_result == NM_CLIENT_PERMISSION_RESULT_YES) gtk_button_set_image (GTK_BUTTON (self), priv->stock); - } + else + gtk_button_set_image (GTK_BUTTON (self), priv->auth); } static void @@ -80,22 +86,30 @@ update_and_emit (CEPolkitButton *self, gboolean old_actionable) gboolean new_actionable; new_actionable = ce_polkit_button_get_actionable (self); - update_button (self, new_actionable); + update_button (self); if (new_actionable != old_actionable) g_signal_emit (self, signals[ACTIONABLE], 0, new_actionable); } void -ce_polkit_button_set_master_sensitive (CEPolkitButton *self, gboolean sensitive) +ce_polkit_button_set_validation_error (CEPolkitButton *self, const char *validation_error) { + CEPolkitButtonPrivate *priv; gboolean old_actionable; g_return_if_fail (self != NULL); g_return_if_fail (CE_IS_POLKIT_BUTTON (self)); - old_actionable = ce_polkit_button_get_actionable (self); - CE_POLKIT_BUTTON_GET_PRIVATE (self)->master_sensitive = sensitive; - update_and_emit (self, old_actionable); + priv = CE_POLKIT_BUTTON_GET_PRIVATE (self); + + if (g_strcmp0 (validation_error, priv->validation_error) != 0) { + old_actionable = ce_polkit_button_get_actionable (self); + + g_free (priv->validation_error); + priv->validation_error = g_strdup (validation_error); + + update_and_emit (self, old_actionable); + } } gboolean @@ -108,16 +122,22 @@ ce_polkit_button_get_actionable (CEPolkitButton *self) priv = CE_POLKIT_BUTTON_GET_PRIVATE (self); - return priv->master_sensitive && priv->authorized; + return !priv->validation_error + && ce_polkit_button_get_authorized (self); } gboolean ce_polkit_button_get_authorized (CEPolkitButton *self) { + CEPolkitButtonPrivate *priv; + g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (CE_IS_POLKIT_BUTTON (self), FALSE); - return CE_POLKIT_BUTTON_GET_PRIVATE (self)->authorized; + priv = CE_POLKIT_BUTTON_GET_PRIVATE (self); + + return priv->permission_result == NM_CLIENT_PERMISSION_RESULT_YES + || priv->permission_result == NM_CLIENT_PERMISSION_RESULT_AUTH; } static void @@ -127,16 +147,16 @@ permission_changed_cb (NMClient *client, CEPolkitButton *self) { CEPolkitButtonPrivate *priv = CE_POLKIT_BUTTON_GET_PRIVATE (self); - gboolean old_actionable, old_authorized; + gboolean old_actionable; - old_actionable = ce_polkit_button_get_actionable (self); - old_authorized = priv->authorized; + if (priv->permission_result == result) + return; - priv->authorized = (result == NM_CLIENT_PERMISSION_RESULT_YES || result == NM_CLIENT_PERMISSION_RESULT_AUTH); + old_actionable = ce_polkit_button_get_actionable (self); + priv->permission_result = result; update_and_emit (self, old_actionable); - if (priv->authorized != old_authorized) - g_signal_emit (self, signals[AUTHORIZED], 0, priv->authorized); + g_signal_emit (self, signals[AUTHORIZED], 0, ce_polkit_button_get_authorized (self)); } GtkWidget * @@ -172,8 +192,7 @@ ce_polkit_button_new (const char *label, g_object_ref_sink (priv->auth); gtk_button_set_label (GTK_BUTTON (object), label); - update_button (CE_POLKIT_BUTTON (object), - ce_polkit_button_get_actionable (CE_POLKIT_BUTTON (object))); + update_button (CE_POLKIT_BUTTON (object)); permission_changed_cb (client, permission, @@ -207,6 +226,7 @@ finalize (GObject *object) g_free (priv->tooltip); g_free (priv->auth_tooltip); + g_free (priv->validation_error); G_OBJECT_CLASS (ce_polkit_button_parent_class)->finalize (object); } diff --git a/src/connection-editor/ce-polkit-button.h b/src/connection-editor/ce-polkit-button.h index da2f3e37..a81963b3 100644 --- a/src/connection-editor/ce-polkit-button.h +++ b/src/connection-editor/ce-polkit-button.h @@ -56,7 +56,7 @@ GtkWidget *ce_polkit_button_new (const char *label, NMClient *client, NMClientPermission permission); -void ce_polkit_button_set_master_sensitive (CEPolkitButton *button, gboolean sensitive); +void ce_polkit_button_set_validation_error (CEPolkitButton *self, const char *validation_error); gboolean ce_polkit_button_get_actionable (CEPolkitButton *button); diff --git a/src/connection-editor/nm-connection-editor.c b/src/connection-editor/nm-connection-editor.c index fa918f93..9c7a1ef4 100644 --- a/src/connection-editor/nm-connection-editor.c +++ b/src/connection-editor/nm-connection-editor.c @@ -108,7 +108,7 @@ nm_connection_editor_update_title (NMConnectionEditor *editor) } static gboolean -ui_to_setting (NMConnectionEditor *editor) +ui_to_setting (NMConnectionEditor *editor, GError **error) { NMSettingConnection *s_con; GtkWidget *widget; @@ -123,8 +123,10 @@ ui_to_setting (NMConnectionEditor *editor) g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_ID, name, NULL); nm_connection_editor_update_title (editor); - if (!name || !strlen (name)) + if (!name || !strlen (name)) { + g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("Missing connection name")); return FALSE; + } return TRUE; } @@ -180,43 +182,54 @@ static void connection_editor_validate (NMConnectionEditor *editor) { NMSettingConnection *s_con; - gboolean valid = FALSE, printed = FALSE; GSList *iter; + char *validation_error = NULL; + GError *error = NULL; - if (!editor_is_initialized (editor)) + if (!editor_is_initialized (editor)) { + validation_error = g_strdup (_("Editor initializing...")); goto done; + } s_con = nm_connection_get_setting_connection (editor->connection); g_assert (s_con); - if (nm_setting_connection_get_read_only (s_con)) + if (nm_setting_connection_get_read_only (s_con)) { + validation_error = g_strdup (_("Connection cannot be modified")); goto done; + } - if (!ui_to_setting (editor)) + if (!ui_to_setting (editor, &error)) { + validation_error = g_strdup (error->message); + g_clear_error (&error); goto done; + } - valid = TRUE; for (iter = editor->pages; iter; iter = g_slist_next (iter)) { - GError *error = NULL; - if (!ce_page_validate (CE_PAGE (iter->data), editor->connection, &error)) { - valid = FALSE; - - /* FIXME: use the error to indicate which UI widgets are invalid */ - if (!printed) { - printed = TRUE; - if (error) { - g_warning ("Invalid setting %s: %s", CE_PAGE (iter->data)->title, error->message); - g_error_free (error); - } else - g_warning ("Invalid setting %s", CE_PAGE (iter->data)->title); + if (!validation_error) { + validation_error = g_strdup_printf (_("Invalid setting %s: %s"), + CE_PAGE (iter->data)->title, + error->message); } + g_clear_error (&error); } } done: - ce_polkit_button_set_master_sensitive (CE_POLKIT_BUTTON (editor->ok_button), valid); - gtk_widget_set_sensitive (editor->export_button, valid); + if (g_strcmp0 (validation_error, editor->last_validation_error) != 0) { + if (editor->last_validation_error && !validation_error) + g_message ("Connection validates and can be saved"); + else if (validation_error) + g_message ("Cannot save connection due to error: %s", validation_error); + g_free (editor->last_validation_error); + editor->last_validation_error = g_strdup (validation_error); + } + ce_polkit_button_set_validation_error (CE_POLKIT_BUTTON (editor->ok_button), validation_error); + gtk_widget_set_sensitive (editor->export_button, !!validation_error); + update_sensitivity (editor); + + g_free (validation_error); } static void @@ -229,8 +242,8 @@ ok_button_actionable_cb (GtkWidget *button, static void permissions_changed_cb (NMClient *client, - NMClientPermission permission, - NMClientPermissionResult result, + NMClientPermission permission, + NMClientPermissionResult result, NMConnectionEditor *editor) { if (permission != NM_CLIENT_PERMISSION_SETTINGS_MODIFY_SYSTEM) @@ -346,6 +359,8 @@ dispose (GObject *object) g_signal_handler_disconnect (editor->client, editor->permission_id); g_object_unref (editor->client); + g_clear_pointer (&editor->last_validation_error, g_free); + out: G_OBJECT_CLASS (nm_connection_editor_parent_class)->dispose (object); } diff --git a/src/connection-editor/nm-connection-editor.h b/src/connection-editor/nm-connection-editor.h index 7c953b85..259e8dc2 100644 --- a/src/connection-editor/nm-connection-editor.h +++ b/src/connection-editor/nm-connection-editor.h @@ -64,6 +64,8 @@ typedef struct { gboolean busy; gboolean init_run; guint validate_id; + + char *last_validation_error; } NMConnectionEditor; typedef struct { diff --git a/src/connection-editor/nm-connection-list.c b/src/connection-editor/nm-connection-list.c index 1149433d..d961b1fe 100644 --- a/src/connection-editor/nm-connection-list.c +++ b/src/connection-editor/nm-connection-list.c @@ -389,12 +389,12 @@ pk_button_selection_changed_cb (GtkTreeSelection *selection, gpointer user_data) if (connection) { s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection)); g_assert (s_con); - + sensitive = !nm_setting_connection_get_read_only (s_con); } } - ce_polkit_button_set_master_sensitive (button, sensitive); + ce_polkit_button_set_validation_error (button, sensitive ? NULL : _("Connection cannot be modified")); } static void diff --git a/src/connection-editor/page-8021x-security.c b/src/connection-editor/page-8021x-security.c index 0c62d85d..f484a5d2 100644 --- a/src/connection-editor/page-8021x-security.c +++ b/src/connection-editor/page-8021x-security.c @@ -134,7 +134,7 @@ ce_page_8021x_security_new (NMConnection *connection, } static gboolean -validate (CEPage *page, NMConnection *connection, GError **error) +ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error) { CEPage8021xSecurityPrivate *priv = CE_PAGE_8021X_SECURITY_GET_PRIVATE (page); gboolean valid = TRUE; @@ -143,8 +143,7 @@ validate (CEPage *page, NMConnection *connection, GError **error) NMConnection *tmp_connection; NMSetting *s_8021x; - /* FIXME: get failed property and error out of wireless security objects */ - valid = wireless_security_validate (priv->security); + valid = wireless_security_validate (priv->security, error); if (valid) { NMSetting *s_con; @@ -164,8 +163,7 @@ validate (CEPage *page, NMConnection *connection, GError **error) nm_connection_add_setting (connection, NM_SETTING (g_object_ref (s_8021x))); g_object_unref (tmp_connection); - } else - g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, "Invalid 802.1x security"); + } } else { nm_connection_remove_setting (connection, NM_TYPE_SETTING_802_1X); valid = TRUE; @@ -203,5 +201,5 @@ ce_page_8021x_security_class_init (CEPage8021xSecurityClass *security_class) /* virtual methods */ object_class->dispose = dispose; - parent_class->validate = validate; + parent_class->ce_page_validate_v = ce_page_validate_v; } diff --git a/src/connection-editor/page-bluetooth.c b/src/connection-editor/page-bluetooth.c index 7ee30040..23ec596a 100644 --- a/src/connection-editor/page-bluetooth.c +++ b/src/connection-editor/page-bluetooth.c @@ -140,12 +140,12 @@ ui_to_setting (CEPageBluetooth *self) } static gboolean -validate (CEPage *page, NMConnection *connection, GError **error) +ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error) { CEPageBluetooth *self = CE_PAGE_BLUETOOTH (page); CEPageBluetoothPrivate *priv = CE_PAGE_BLUETOOTH_GET_PRIVATE (self); - if (!ce_page_mac_entry_valid (priv->bdaddr, ARPHRD_ETHER)) + if (!ce_page_mac_entry_valid (priv->bdaddr, ARPHRD_ETHER, _("bdaddr"), error)) return FALSE; ui_to_setting (self); @@ -166,7 +166,7 @@ ce_page_bluetooth_class_init (CEPageBluetoothClass *bluetooth_class) g_type_class_add_private (object_class, sizeof (CEPageBluetoothPrivate)); /* virtual methods */ - parent_class->validate = validate; + parent_class->ce_page_validate_v = ce_page_validate_v; } typedef struct { diff --git a/src/connection-editor/page-bond.c b/src/connection-editor/page-bond.c index cb690266..9d3b7898 100644 --- a/src/connection-editor/page-bond.c +++ b/src/connection-editor/page-bond.c @@ -554,17 +554,16 @@ ui_to_setting (CEPageBond *self) } static gboolean -validate (CEPage *page, NMConnection *connection, GError **error) +ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error) { CEPageBond *self = CE_PAGE_BOND (page); CEPageBondPrivate *priv = CE_PAGE_BOND_GET_PRIVATE (self); - const char *primary; - if (!CE_PAGE_CLASS (ce_page_bond_parent_class)->validate (page, connection, error)) + if (!CE_PAGE_CLASS (ce_page_bond_parent_class)->ce_page_validate_v (page, connection, error)) return FALSE; - primary = gtk_entry_get_text (priv->primary); - if (primary && *primary && !nm_utils_iface_valid_name (primary)) + if (!ce_page_interface_name_valid (gtk_entry_get_text (priv->primary), + _("primary"), error)) return FALSE; ui_to_setting (self); @@ -591,7 +590,7 @@ ce_page_bond_class_init (CEPageBondClass *bond_class) g_type_class_add_private (object_class, sizeof (CEPageBondPrivate)); /* virtual methods */ - parent_class->validate = validate; + parent_class->ce_page_validate_v = ce_page_validate_v; master_class->connection_added = connection_added; master_class->connection_removed = connection_removed; diff --git a/src/connection-editor/page-bridge-port.c b/src/connection-editor/page-bridge-port.c index 8d654b12..52e62601 100644 --- a/src/connection-editor/page-bridge-port.c +++ b/src/connection-editor/page-bridge-port.c @@ -139,7 +139,7 @@ ui_to_setting (CEPageBridgePort *self) } static gboolean -validate (CEPage *page, NMConnection *connection, GError **error) +ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error) { CEPageBridgePort *self = CE_PAGE_BRIDGE_PORT (page); CEPageBridgePortPrivate *priv = CE_PAGE_BRIDGE_PORT_GET_PRIVATE (self); @@ -162,5 +162,5 @@ ce_page_bridge_port_class_init (CEPageBridgePortClass *bridge_port_class) g_type_class_add_private (object_class, sizeof (CEPageBridgePortPrivate)); /* virtual methods */ - parent_class->validate = validate; + parent_class->ce_page_validate_v = ce_page_validate_v; } diff --git a/src/connection-editor/page-bridge.c b/src/connection-editor/page-bridge.c index 30fe5260..d3007a41 100644 --- a/src/connection-editor/page-bridge.c +++ b/src/connection-editor/page-bridge.c @@ -260,12 +260,12 @@ ui_to_setting (CEPageBridge *self) } static gboolean -validate (CEPage *page, NMConnection *connection, GError **error) +ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error) { CEPageBridge *self = CE_PAGE_BRIDGE (page); CEPageBridgePrivate *priv = CE_PAGE_BRIDGE_GET_PRIVATE (self); - if (!CE_PAGE_CLASS (ce_page_bridge_parent_class)->validate (page, connection, error)) + if (!CE_PAGE_CLASS (ce_page_bridge_parent_class)->ce_page_validate_v (page, connection, error)) return FALSE; ui_to_setting (self); @@ -287,7 +287,7 @@ ce_page_bridge_class_init (CEPageBridgeClass *bridge_class) g_type_class_add_private (object_class, sizeof (CEPageBridgePrivate)); /* virtual methods */ - parent_class->validate = validate; + parent_class->ce_page_validate_v = ce_page_validate_v; master_class->create_connection = create_connection; master_class->add_slave = add_slave; } diff --git a/src/connection-editor/page-dcb.c b/src/connection-editor/page-dcb.c index 2d18666c..b8405fe1 100644 --- a/src/connection-editor/page-dcb.c +++ b/src/connection-editor/page-dcb.c @@ -726,7 +726,7 @@ ui_to_setting (CEPageDcb *self, NMSettingDcb *s_dcb) } static gboolean -validate (CEPage *page, NMConnection *connection, GError **error) +ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error) { CEPageDcb *self = CE_PAGE_DCB (page); CEPageDcbPrivate *priv = CE_PAGE_DCB_GET_PRIVATE (self); @@ -773,5 +773,5 @@ ce_page_dcb_class_init (CEPageDcbClass *security_class) /* virtual methods */ object_class->dispose = dispose; - parent_class->validate = validate; + parent_class->ce_page_validate_v = ce_page_validate_v; } diff --git a/src/connection-editor/page-dsl.c b/src/connection-editor/page-dsl.c index ac480eee..aeb9f55e 100644 --- a/src/connection-editor/page-dsl.c +++ b/src/connection-editor/page-dsl.c @@ -175,7 +175,7 @@ ui_to_setting (CEPageDsl *self) } static gboolean -validate (CEPage *page, NMConnection *connection, GError **error) +ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error) { CEPageDsl *self = CE_PAGE_DSL (page); CEPageDslPrivate *priv = CE_PAGE_DSL_GET_PRIVATE (self); @@ -198,7 +198,7 @@ ce_page_dsl_class_init (CEPageDslClass *dsl_class) g_type_class_add_private (object_class, sizeof (CEPageDslPrivate)); /* virtual methods */ - parent_class->validate = validate; + parent_class->ce_page_validate_v = ce_page_validate_v; } diff --git a/src/connection-editor/page-ethernet.c b/src/connection-editor/page-ethernet.c index 5363d9a7..d52e00cf 100644 --- a/src/connection-editor/page-ethernet.c +++ b/src/connection-editor/page-ethernet.c @@ -304,7 +304,7 @@ ui_to_setting (CEPageEthernet *self) entry = gtk_bin_get_child (GTK_BIN (priv->device_combo)); if (entry) - ce_page_device_entry_get (GTK_ENTRY (entry), ARPHRD_ETHER, &ifname, &device_mac); + ce_page_device_entry_get (GTK_ENTRY (entry), ARPHRD_ETHER, &ifname, &device_mac, NULL, NULL); cloned_mac = gtk_entry_get_text (priv->cloned_mac); g_object_set (s_con, @@ -325,7 +325,7 @@ ui_to_setting (CEPageEthernet *self) } static gboolean -validate (CEPage *page, NMConnection *connection, GError **error) +ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error) { CEPageEthernet *self = CE_PAGE_ETHERNET (page); CEPageEthernetPrivate *priv = CE_PAGE_ETHERNET_GET_PRIVATE (self); @@ -333,11 +333,11 @@ validate (CEPage *page, NMConnection *connection, GError **error) entry = gtk_bin_get_child (GTK_BIN (priv->device_combo)); if (entry) { - if (!ce_page_device_entry_get (GTK_ENTRY (entry), ARPHRD_ETHER, NULL, NULL)) + if (!ce_page_device_entry_get (GTK_ENTRY (entry), ARPHRD_ETHER, NULL, NULL, _("Ethernet device"), error)) return FALSE; } - if (!ce_page_mac_entry_valid (priv->cloned_mac, ARPHRD_ETHER)) + if (!ce_page_mac_entry_valid (priv->cloned_mac, ARPHRD_ETHER, _("cloned MAC"), error)) return FALSE; ui_to_setting (self); @@ -358,7 +358,7 @@ ce_page_ethernet_class_init (CEPageEthernetClass *ethernet_class) g_type_class_add_private (object_class, sizeof (CEPageEthernetPrivate)); /* virtual methods */ - parent_class->validate = validate; + parent_class->ce_page_validate_v = ce_page_validate_v; } diff --git a/src/connection-editor/page-general.c b/src/connection-editor/page-general.c index 477c0be2..1f713287 100644 --- a/src/connection-editor/page-general.c +++ b/src/connection-editor/page-general.c @@ -413,7 +413,7 @@ ui_to_setting (CEPageGeneral *self) } static gboolean -validate (CEPage *page, NMConnection *connection, GError **error) +ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error) { CEPageGeneral *self = CE_PAGE_GENERAL (page); CEPageGeneralPrivate *priv = CE_PAGE_GENERAL_GET_PRIVATE (self); @@ -438,6 +438,6 @@ ce_page_general_class_init (CEPageGeneralClass *connection_class) /* virtual methods */ object_class->dispose = dispose; - parent_class->validate = validate; + parent_class->ce_page_validate_v = ce_page_validate_v; } diff --git a/src/connection-editor/page-infiniband.c b/src/connection-editor/page-infiniband.c index a936f447..09c9b8f9 100644 --- a/src/connection-editor/page-infiniband.c +++ b/src/connection-editor/page-infiniband.c @@ -190,7 +190,7 @@ ui_to_setting (CEPageInfiniband *self) entry = gtk_bin_get_child (GTK_BIN (priv->device_combo)); if (entry) - ce_page_device_entry_get (GTK_ENTRY (entry), ARPHRD_INFINIBAND, &ifname, &device_mac); + ce_page_device_entry_get (GTK_ENTRY (entry), ARPHRD_INFINIBAND, &ifname, &device_mac, NULL, NULL); g_object_set (s_con, NM_SETTING_CONNECTION_INTERFACE_NAME, ifname, @@ -206,7 +206,7 @@ ui_to_setting (CEPageInfiniband *self) } static gboolean -validate (CEPage *page, NMConnection *connection, GError **error) +ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error) { CEPageInfiniband *self = CE_PAGE_INFINIBAND (page); CEPageInfinibandPrivate *priv = CE_PAGE_INFINIBAND_GET_PRIVATE (self); @@ -214,7 +214,7 @@ validate (CEPage *page, NMConnection *connection, GError **error) entry = gtk_bin_get_child (GTK_BIN (priv->device_combo)); if (entry) { - if (!ce_page_device_entry_get (GTK_ENTRY (entry), ARPHRD_INFINIBAND, NULL, NULL)) + if (!ce_page_device_entry_get (GTK_ENTRY (entry), ARPHRD_INFINIBAND, NULL, NULL, _("infiniband device"), error)) return FALSE; } @@ -236,7 +236,7 @@ ce_page_infiniband_class_init (CEPageInfinibandClass *infiniband_class) g_type_class_add_private (object_class, sizeof (CEPageInfinibandPrivate)); /* virtual methods */ - parent_class->validate = validate; + parent_class->ce_page_validate_v = ce_page_validate_v; } diff --git a/src/connection-editor/page-ip4.c b/src/connection-editor/page-ip4.c index 30f33840..48d6041f 100644 --- a/src/connection-editor/page-ip4.c +++ b/src/connection-editor/page-ip4.c @@ -1174,7 +1174,7 @@ free_one_addr (gpointer data) } static gboolean -ui_to_setting (CEPageIP4 *self) +ui_to_setting (CEPageIP4 *self, GError **error) { CEPageIP4Private *priv = CE_PAGE_IP4_GET_PRIVATE (self); GtkTreeModel *model; @@ -1239,8 +1239,7 @@ ui_to_setting (CEPageIP4 *self) if ( !addr || !nm_utils_ipaddr_valid (AF_INET, addr) || is_address_unspecified (addr)) { - g_warning ("%s: IPv4 address '%s' missing or invalid!", - __func__, addr ? addr : "<none>"); + g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, _("IPv4 address \"%s\" invalid"), addr ? addr : ""); g_free (addr); g_free (netmask); g_free (addr_gw); @@ -1248,8 +1247,7 @@ ui_to_setting (CEPageIP4 *self) } if (!parse_netmask (netmask, &prefix)) { - g_warning ("%s: IPv4 prefix '%s' missing or invalid!", - __func__, netmask ? netmask : "<none>"); + g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, _("IPv4 address netmask \"%s\" invalid"), netmask ? netmask : ""); g_free (addr); g_free (netmask); g_free (addr_gw); @@ -1258,8 +1256,7 @@ ui_to_setting (CEPageIP4 *self) /* Gateway is optional... */ if (addr_gw && *addr_gw && !nm_utils_ipaddr_valid (AF_INET, addr_gw)) { - g_warning ("%s: IPv4 gateway '%s' invalid!", - __func__, addr_gw); + g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, _("IPv4 gateway \"%s\" invalid"), addr_gw); g_free (addr); g_free (netmask); g_free (addr_gw); @@ -1302,6 +1299,7 @@ ui_to_setting (CEPageIP4 *self) if (inet_pton (AF_INET, stripped, &tmp_addr)) g_ptr_array_add (tmp_array, g_strdup (stripped)); else { + g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, _("IPv4 DNS server \"%s\" invalid"), stripped); g_strfreev (items); g_ptr_array_free (tmp_array, TRUE); goto out; @@ -1364,12 +1362,12 @@ out: } static gboolean -validate (CEPage *page, NMConnection *connection, GError **error) +ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error) { CEPageIP4 *self = CE_PAGE_IP4 (page); CEPageIP4Private *priv = CE_PAGE_IP4_GET_PRIVATE (self); - if (!ui_to_setting (self)) + if (!ui_to_setting (self, error)) return FALSE; return nm_setting_verify (NM_SETTING (priv->setting), NULL, error); } @@ -1409,6 +1407,6 @@ ce_page_ip4_class_init (CEPageIP4Class *ip4_class) g_type_class_add_private (object_class, sizeof (CEPageIP4Private)); /* virtual methods */ - parent_class->validate = validate; + parent_class->ce_page_validate_v = ce_page_validate_v; object_class->dispose = dispose; } diff --git a/src/connection-editor/page-ip6.c b/src/connection-editor/page-ip6.c index 6c0e9f40..439858ab 100644 --- a/src/connection-editor/page-ip6.c +++ b/src/connection-editor/page-ip6.c @@ -1176,7 +1176,7 @@ ce_page_ip6_new (NMConnection *connection, } static gboolean -ui_to_setting (CEPageIP6 *self) +ui_to_setting (CEPageIP6 *self, GError **error) { CEPageIP6Private *priv = CE_PAGE_IP6_GET_PRIVATE (self); GtkTreeModel *model; @@ -1245,8 +1245,7 @@ ui_to_setting (CEPageIP6 *self) if ( !addr_str || !nm_utils_ipaddr_valid (AF_INET6, addr_str) || is_address_unspecified (addr_str)) { - g_warning ("%s: IPv6 address '%s' missing or invalid!", - __func__, addr_str ? addr_str : "<none>"); + g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, _("IPv6 address \"%s\" invalid"), addr_str ? addr_str : ""); g_free (addr_str); g_free (prefix_str); g_free (addr_gw_str); @@ -1254,10 +1253,7 @@ ui_to_setting (CEPageIP6 *self) } if (!is_prefix_valid (prefix_str, &prefix)) { - if (!prefix_str) - g_warning ("%s: IPv6 prefix missing!", __func__); - else - g_warning ("%s: IPv6 prefix '%s' invalid!", __func__, prefix_str); + g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, _("IPv6 prefix \"%s\" invalid"), prefix_str ? prefix_str : ""); g_free (addr_str); g_free (prefix_str); g_free (addr_gw_str); @@ -1266,8 +1262,7 @@ ui_to_setting (CEPageIP6 *self) /* Gateway is optional... */ if (addr_gw_str && *addr_gw_str && !nm_utils_ipaddr_valid (AF_INET6, addr_gw_str)) { - g_warning ("%s: IPv6 gateway '%s' invalid!", - __func__, addr_gw_str); + g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, _("IPv6 gateway \"%s\" invalid"), addr_gw_str); g_free (addr_str); g_free (prefix_str); g_free (addr_gw_str); @@ -1309,6 +1304,7 @@ ui_to_setting (CEPageIP6 *self) if (inet_pton (AF_INET6, stripped, &tmp_addr)) { nm_setting_ip_config_add_dns (priv->setting, stripped); } else { + g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, _("IPv6 DNS server \"%s\" invalid"), stripped); g_strfreev (items); goto out; } @@ -1361,12 +1357,12 @@ out: } static gboolean -validate (CEPage *page, NMConnection *connection, GError **error) +ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error) { CEPageIP6 *self = CE_PAGE_IP6 (page); CEPageIP6Private *priv = CE_PAGE_IP6_GET_PRIVATE (self); - if (!ui_to_setting (self)) + if (!ui_to_setting (self, error)) return FALSE; return nm_setting_verify (NM_SETTING (priv->setting), NULL, error); } @@ -1406,6 +1402,6 @@ ce_page_ip6_class_init (CEPageIP6Class *ip6_class) g_type_class_add_private (object_class, sizeof (CEPageIP6Private)); /* virtual methods */ - parent_class->validate = validate; + parent_class->ce_page_validate_v = ce_page_validate_v; object_class->dispose = dispose; } diff --git a/src/connection-editor/page-master.c b/src/connection-editor/page-master.c index 58b3bc6f..82072a4e 100644 --- a/src/connection-editor/page-master.c +++ b/src/connection-editor/page-master.c @@ -604,7 +604,7 @@ ui_to_setting (CEPageMaster *self) } static gboolean -validate (CEPage *page, NMConnection *connection, GError **error) +ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error) { CEPageMaster *self = CE_PAGE_MASTER (page); @@ -614,7 +614,7 @@ validate (CEPage *page, NMConnection *connection, GError **error) ui_to_setting (self); - /* Subtype validate() method will validate the interface name */ + /* Subtype ce_page_validate_v() method will validate the interface name */ return TRUE; } @@ -678,7 +678,7 @@ ce_page_master_class_init (CEPageMasterClass *master_class) object_class->constructed = constructed; object_class->dispose = dispose; - parent_class->validate = validate; + parent_class->ce_page_validate_v = ce_page_validate_v; parent_class->last_update = last_update; /* Signals */ diff --git a/src/connection-editor/page-mobile.c b/src/connection-editor/page-mobile.c index 56bfd219..375b7173 100644 --- a/src/connection-editor/page-mobile.c +++ b/src/connection-editor/page-mobile.c @@ -392,7 +392,7 @@ ui_to_setting (CEPageMobile *self) } static gboolean -validate (CEPage *page, NMConnection *connection, GError **error) +ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error) { CEPageMobile *self = CE_PAGE_MOBILE (page); CEPageMobilePrivate *priv = CE_PAGE_MOBILE_GET_PRIVATE (self); @@ -423,7 +423,7 @@ ce_page_mobile_class_init (CEPageMobileClass *mobile_class) g_type_class_add_private (object_class, sizeof (CEPageMobilePrivate)); /* virtual methods */ - parent_class->validate = validate; + parent_class->ce_page_validate_v = ce_page_validate_v; object_class->dispose = dispose; } diff --git a/src/connection-editor/page-ppp.c b/src/connection-editor/page-ppp.c index e509a72e..a6e28ee8 100644 --- a/src/connection-editor/page-ppp.c +++ b/src/connection-editor/page-ppp.c @@ -355,7 +355,7 @@ ui_to_setting (CEPagePpp *self) } static gboolean -validate (CEPage *page, NMConnection *connection, GError **error) +ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error) { CEPagePpp *self = CE_PAGE_PPP (page); CEPagePppPrivate *priv = CE_PAGE_PPP_GET_PRIVATE (self); @@ -389,6 +389,6 @@ ce_page_ppp_class_init (CEPagePppClass *ppp_class) g_type_class_add_private (object_class, sizeof (CEPagePppPrivate)); /* virtual methods */ - parent_class->validate = validate; + parent_class->ce_page_validate_v = ce_page_validate_v; object_class->dispose = dispose; } diff --git a/src/connection-editor/page-team-port.c b/src/connection-editor/page-team-port.c index 5b24bb55..ebf86e01 100644 --- a/src/connection-editor/page-team-port.c +++ b/src/connection-editor/page-team-port.c @@ -191,7 +191,7 @@ ui_to_setting (CEPageTeamPort *self) } static gboolean -validate (CEPage *page, NMConnection *connection, GError **error) +ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error) { CEPageTeamPort *self = CE_PAGE_TEAM_PORT (page); CEPageTeamPortPrivate *priv = CE_PAGE_TEAM_PORT_GET_PRIVATE (self); @@ -214,5 +214,5 @@ ce_page_team_port_class_init (CEPageTeamPortClass *team_port_class) g_type_class_add_private (object_class, sizeof (CEPageTeamPortPrivate)); /* virtual methods */ - parent_class->validate = validate; + parent_class->ce_page_validate_v = ce_page_validate_v; } diff --git a/src/connection-editor/page-team.c b/src/connection-editor/page-team.c index 910123be..1ac337fb 100644 --- a/src/connection-editor/page-team.c +++ b/src/connection-editor/page-team.c @@ -319,12 +319,12 @@ ui_to_setting (CEPageTeam *self) } static gboolean -validate (CEPage *page, NMConnection *connection, GError **error) +ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error) { CEPageTeam *self = CE_PAGE_TEAM (page); CEPageTeamPrivate *priv = CE_PAGE_TEAM_GET_PRIVATE (self); - if (!CE_PAGE_CLASS (ce_page_team_parent_class)->validate (page, connection, error)) + if (!CE_PAGE_CLASS (ce_page_team_parent_class)->ce_page_validate_v (page, connection, error)) return FALSE; ui_to_setting (self); @@ -351,7 +351,7 @@ ce_page_team_class_init (CEPageTeamClass *team_class) g_type_class_add_private (object_class, sizeof (CEPageTeamPrivate)); /* virtual methods */ - parent_class->validate = validate; + parent_class->ce_page_validate_v = ce_page_validate_v; master_class->create_connection = create_connection; master_class->connection_added = connection_added; master_class->connection_removed = connection_removed; diff --git a/src/connection-editor/page-vlan.c b/src/connection-editor/page-vlan.c index 9a0cc86c..5df091c4 100644 --- a/src/connection-editor/page-vlan.c +++ b/src/connection-editor/page-vlan.c @@ -714,7 +714,7 @@ ui_to_setting (CEPageVlan *self) } static gboolean -validate (CEPage *page, NMConnection *connection, GError **error) +ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error) { CEPageVlan *self = CE_PAGE_VLAN (page); CEPageVlanPrivate *priv = CE_PAGE_VLAN_GET_PRIVATE (self); @@ -722,17 +722,16 @@ validate (CEPage *page, NMConnection *connection, GError **error) char *parent_iface; if (gtk_combo_box_get_active (GTK_COMBO_BOX (priv->parent)) == -1) { - gboolean valid; - parent = gtk_entry_get_text (priv->parent_entry); parent_iface = g_strndup (parent, strcspn (parent, " ")); - valid = nm_utils_iface_valid_name (parent_iface); - g_free (parent_iface); - if (!valid) + if (!ce_page_interface_name_valid (parent_iface, _("vlan parent"), error)) { + g_free (parent_iface); return FALSE; + } + g_free (parent_iface); } - if (!ce_page_mac_entry_valid (priv->cloned_mac, ARPHRD_ETHER)) + if (!ce_page_mac_entry_valid (priv->cloned_mac, ARPHRD_ETHER, _("cloned MAC"), error)) return FALSE; ui_to_setting (self); @@ -775,7 +774,7 @@ ce_page_vlan_class_init (CEPageVlanClass *vlan_class) /* virtual methods */ object_class->finalize = finalize; - parent_class->validate = validate; + parent_class->ce_page_validate_v = ce_page_validate_v; } diff --git a/src/connection-editor/page-vpn.c b/src/connection-editor/page-vpn.c index 1b976562..376a40a3 100644 --- a/src/connection-editor/page-vpn.c +++ b/src/connection-editor/page-vpn.c @@ -138,7 +138,7 @@ ce_page_vpn_can_export (CEPageVpn *page) } static gboolean -validate (CEPage *page, NMConnection *connection, GError **error) +ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error) { CEPageVpn *self = CE_PAGE_VPN (page); CEPageVpnPrivate *priv = CE_PAGE_VPN_GET_PRIVATE (self); @@ -173,7 +173,7 @@ ce_page_vpn_class_init (CEPageVpnClass *vpn_class) /* virtual methods */ object_class->dispose = dispose; - parent_class->validate = validate; + parent_class->ce_page_validate_v = ce_page_validate_v; } typedef struct { diff --git a/src/connection-editor/page-wifi-security.c b/src/connection-editor/page-wifi-security.c index 3e8d50e4..67611a9e 100644 --- a/src/connection-editor/page-wifi-security.c +++ b/src/connection-editor/page-wifi-security.c @@ -448,7 +448,7 @@ dispose (GObject *object) } static gboolean -validate (CEPage *page, NMConnection *connection, GError **error) +ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error) { CEPageWifiSecurity *self = CE_PAGE_WIFI_SECURITY (page); CEPageWifiSecurityPrivate *priv = CE_PAGE_WIFI_SECURITY_GET_PRIVATE (self); @@ -475,20 +475,17 @@ validate (CEPage *page, NMConnection *connection, GError **error) GBytes *ssid = nm_setting_wireless_get_ssid (s_wireless); if (ssid) { - /* FIXME: get failed property and error out of wifi security objects */ - valid = wireless_security_validate (sec); + valid = wireless_security_validate (sec, error); if (valid) wireless_security_fill_connection (sec, connection); - else - g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, "Invalid Wi-Fi security"); } else { - g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, "Missing SSID"); + g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, _("missing SSID")); valid = FALSE; } if (priv->adhoc) { if (!wireless_security_adhoc_compatible (sec)) { - g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, "Security not compatible with Ad-Hoc mode"); + g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, _("Security not compatible with Ad-Hoc mode")); valid = FALSE; } } @@ -515,5 +512,5 @@ ce_page_wifi_security_class_init (CEPageWifiSecurityClass *wireless_security_cla /* virtual methods */ object_class->dispose = dispose; - parent_class->validate = validate; + parent_class->ce_page_validate_v = ce_page_validate_v; } diff --git a/src/connection-editor/page-wifi.c b/src/connection-editor/page-wifi.c index ea508054..b0455ff7 100644 --- a/src/connection-editor/page-wifi.c +++ b/src/connection-editor/page-wifi.c @@ -529,7 +529,7 @@ ui_to_setting (CEPageWifi *self) bssid = gtk_entry_get_text (GTK_ENTRY (entry)); entry = gtk_bin_get_child (GTK_BIN (priv->device_combo)); if (entry) - ce_page_device_entry_get (GTK_ENTRY (entry), ARPHRD_ETHER, &ifname, &device_mac); + ce_page_device_entry_get (GTK_ENTRY (entry), ARPHRD_ETHER, &ifname, &device_mac, NULL, NULL); cloned_mac = gtk_entry_get_text (priv->cloned_mac); g_object_set (s_con, @@ -554,7 +554,7 @@ ui_to_setting (CEPageWifi *self) } static gboolean -validate (CEPage *page, NMConnection *connection, GError **error) +ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error) { CEPageWifi *self = CE_PAGE_WIFI (page); CEPageWifiPrivate *priv = CE_PAGE_WIFI_GET_PRIVATE (self); @@ -563,17 +563,17 @@ validate (CEPage *page, NMConnection *connection, GError **error) entry = gtk_bin_get_child (GTK_BIN (priv->bssid)); if (entry) { - if (!ce_page_mac_entry_valid (GTK_ENTRY (entry), ARPHRD_ETHER)) + if (!ce_page_mac_entry_valid (GTK_ENTRY (entry), ARPHRD_ETHER, _("bssid"), error)) return FALSE; } entry = gtk_bin_get_child (GTK_BIN (priv->device_combo)); if (entry) { - if (!ce_page_device_entry_get (GTK_ENTRY (entry), ARPHRD_ETHER, NULL, NULL)) + if (!ce_page_device_entry_get (GTK_ENTRY (entry), ARPHRD_ETHER, NULL, NULL, _("Wi-Fi device"), error)) return FALSE; } - if (!ce_page_mac_entry_valid (priv->cloned_mac, ARPHRD_ETHER)) + if (!ce_page_mac_entry_valid (priv->cloned_mac, ARPHRD_ETHER, _("cloned MAC"), error)) return FALSE; ui_to_setting (self); @@ -597,7 +597,7 @@ ce_page_wifi_class_init (CEPageWifiClass *wifi_class) g_type_class_add_private (object_class, sizeof (CEPageWifiPrivate)); /* virtual methods */ - parent_class->validate = validate; + parent_class->ce_page_validate_v = ce_page_validate_v; } diff --git a/src/ethernet-dialog.c b/src/ethernet-dialog.c index a35ae61b..03ded50a 100644 --- a/src/ethernet-dialog.c +++ b/src/ethernet-dialog.c @@ -36,8 +36,8 @@ static void stuff_changed_cb (WirelessSecurity *sec, gpointer user_data) { GtkWidget *button = GTK_WIDGET (user_data); - - gtk_widget_set_sensitive (button, wireless_security_validate (sec)); + + gtk_widget_set_sensitive (button, wireless_security_validate (sec, NULL)); } static void diff --git a/src/libnm-gtk/nm-wifi-dialog.c b/src/libnm-gtk/nm-wifi-dialog.c index aef1bc32..396217ba 100644 --- a/src/libnm-gtk/nm-wifi-dialog.c +++ b/src/libnm-gtk/nm-wifi-dialog.c @@ -276,7 +276,7 @@ stuff_changed_cb (WirelessSecurity *sec, gpointer user_data) GByteArray *ssid = NULL; gboolean free_ssid = TRUE; gboolean valid = FALSE; - + if (priv->connection) { NMSettingWireless *s_wireless; s_wireless = nm_connection_get_setting_wireless (priv->connection); @@ -288,7 +288,7 @@ stuff_changed_cb (WirelessSecurity *sec, gpointer user_data) } if (ssid) { - valid = wireless_security_validate (sec); + valid = wireless_security_validate (sec, NULL); if (free_ssid) g_byte_array_free (ssid, TRUE); } @@ -328,7 +328,7 @@ ssid_entry_changed (GtkWidget *entry, gpointer user_data) gtk_tree_model_get (model, &iter, S_SEC_COLUMN, &sec, -1); if (sec) { - valid = wireless_security_validate (sec); + valid = wireless_security_validate (sec, NULL); wireless_security_unref (sec); } else { valid = TRUE; diff --git a/src/libnma/nma-wifi-dialog.c b/src/libnma/nma-wifi-dialog.c index f760bedc..9b49fa16 100644 --- a/src/libnma/nma-wifi-dialog.c +++ b/src/libnma/nma-wifi-dialog.c @@ -248,7 +248,7 @@ validate_dialog_ssid (NMAWifiDialog *self) widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "network_name_entry")); ssid = gtk_entry_get_text (GTK_ENTRY (widget)); - + if (!ssid || strlen (ssid) == 0 || strlen (ssid) > 32) return NULL; @@ -264,7 +264,7 @@ stuff_changed_cb (WirelessSecurity *sec, gpointer user_data) GBytes *ssid = NULL; gboolean free_ssid = TRUE; gboolean valid = FALSE; - + if (priv->connection) { NMSettingWireless *s_wireless; s_wireless = nm_connection_get_setting_wireless (priv->connection); @@ -276,7 +276,7 @@ stuff_changed_cb (WirelessSecurity *sec, gpointer user_data) } if (ssid) { - valid = wireless_security_validate (sec); + valid = wireless_security_validate (sec, NULL); if (free_ssid) g_bytes_unref (ssid); } @@ -316,7 +316,7 @@ ssid_entry_changed (GtkWidget *entry, gpointer user_data) gtk_tree_model_get (model, &iter, S_SEC_COLUMN, &sec, -1); if (sec) { - valid = wireless_security_validate (sec); + valid = wireless_security_validate (sec, NULL); wireless_security_unref (sec); } else { valid = TRUE; diff --git a/src/wireless-security/eap-method-fast.c b/src/wireless-security/eap-method-fast.c index 1071e767..d9b0d8c8 100644 --- a/src/wireless-security/eap-method-fast.c +++ b/src/wireless-security/eap-method-fast.c @@ -28,6 +28,7 @@ #include "eap-method.h" #include "wireless-security.h" +#include "utils.h" #define I_NAME_COLUMN 0 #define I_METHOD_COLUMN 1 @@ -50,7 +51,7 @@ destroy (EAPMethod *parent) } static gboolean -validate (EAPMethod *parent) +validate (EAPMethod *parent, GError **error) { GtkWidget *widget; GtkTreeModel *model; @@ -66,8 +67,10 @@ validate (EAPMethod *parent) widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "eap_fast_pac_file_button")); g_assert (widget); file = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget)); - if (!provisioning && !file) + if (!provisioning && !file) { + g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("missing EAP-FAST PAC file")); return FALSE; + } widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "eap_fast_inner_auth_combo")); g_assert (widget); @@ -75,7 +78,7 @@ validate (EAPMethod *parent) gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter); gtk_tree_model_get (model, &iter, I_METHOD_COLUMN, &eap, -1); g_assert (eap); - valid = eap_method_validate (eap); + valid = eap_method_validate (eap, error); eap_method_unref (eap); return valid; } diff --git a/src/wireless-security/eap-method-leap.c b/src/wireless-security/eap-method-leap.c index e8b12fd0..599f80fe 100644 --- a/src/wireless-security/eap-method-leap.c +++ b/src/wireless-security/eap-method-leap.c @@ -22,11 +22,13 @@ #include <ctype.h> #include <string.h> +#include <glib/gi18n.h> #include "eap-method.h" #include "wireless-security.h" #include "helpers.h" #include "nma-ui-utils.h" +#include "utils.h" struct _EAPMethodLEAP { EAPMethod parent; @@ -50,18 +52,22 @@ show_toggled_cb (GtkToggleButton *button, EAPMethodLEAP *method) } static gboolean -validate (EAPMethod *parent) +validate (EAPMethod *parent, GError **error) { EAPMethodLEAP *method = (EAPMethodLEAP *)parent; const char *text; text = gtk_entry_get_text (method->username_entry); - if (!text || !strlen (text)) + if (!text || !strlen (text)) { + g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("missing EAP-LEAP username")); return FALSE; + } - text = gtk_entry_get_text (method->password_entry); + text = gtk_entry_get_text (method->password_entry); { if (!text || !strlen (text)) + g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("missing EAP-LEAP password")); return FALSE; + } return TRUE; } diff --git a/src/wireless-security/eap-method-peap.c b/src/wireless-security/eap-method-peap.c index 623f854b..85416331 100644 --- a/src/wireless-security/eap-method-peap.c +++ b/src/wireless-security/eap-method-peap.c @@ -28,6 +28,7 @@ #include "eap-method.h" #include "wireless-security.h" +#include "utils.h" #define I_NAME_COLUMN 0 #define I_METHOD_COLUMN 1 @@ -50,18 +51,24 @@ destroy (EAPMethod *parent) } static gboolean -validate (EAPMethod *parent) +validate (EAPMethod *parent, GError **error) { GtkWidget *widget; GtkTreeModel *model; GtkTreeIter iter; EAPMethod *eap = NULL; gboolean valid = FALSE; + GError *local = NULL; - if (!eap_method_validate_filepicker (parent->builder, "eap_peap_ca_cert_button", TYPE_CA_CERT, NULL, NULL)) + if (!eap_method_validate_filepicker (parent->builder, "eap_peap_ca_cert_button", TYPE_CA_CERT, NULL, NULL, &local)) { + g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid EAP-PEAP CA certificate: %s"), local->message); + g_clear_error (&local); return FALSE; - if (eap_method_ca_cert_required (parent->builder, "eap_peap_ca_cert_not_required_checkbox", "eap_peap_ca_cert_button") ) + } + if (eap_method_ca_cert_required (parent->builder, "eap_peap_ca_cert_not_required_checkbox", "eap_peap_ca_cert_button")) { + g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid EAP-PEAP CA ertificate: no certificate specified")); return FALSE; + } widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "eap_peap_inner_auth_combo")); g_assert (widget); @@ -70,7 +77,7 @@ validate (EAPMethod *parent) gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter); gtk_tree_model_get (model, &iter, I_METHOD_COLUMN, &eap, -1); g_assert (eap); - valid = eap_method_validate (eap); + valid = eap_method_validate (eap, error); eap_method_unref (eap); return valid; } diff --git a/src/wireless-security/eap-method-simple.c b/src/wireless-security/eap-method-simple.c index 05679d74..b13062f5 100644 --- a/src/wireless-security/eap-method-simple.c +++ b/src/wireless-security/eap-method-simple.c @@ -22,11 +22,13 @@ #include <ctype.h> #include <string.h> +#include <glib/gi18n.h> #include "eap-method.h" #include "wireless-security.h" #include "helpers.h" #include "nma-ui-utils.h" +#include "utils.h" struct _EAPMethodSimple { EAPMethod parent; @@ -59,22 +61,26 @@ always_ask_selected (GtkEntry *passwd_entry) } static gboolean -validate (EAPMethod *parent) +validate (EAPMethod *parent, GError **error) { EAPMethodSimple *method = (EAPMethodSimple *)parent; const char *text; text = gtk_entry_get_text (method->username_entry); - if (!text || !strlen (text)) + if (!text || !strlen (text)) { + g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("missing EAP username")); return FALSE; + } /* Check if the password should always be requested */ if (always_ask_selected (method->password_entry)) return TRUE; text = gtk_entry_get_text (method->password_entry); - if (!text || !strlen (text)) + if (!text || !strlen (text)) { + g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("missing EAP password")); return FALSE; + } return TRUE; } diff --git a/src/wireless-security/eap-method-tls.c b/src/wireless-security/eap-method-tls.c index 723c2de8..b778f85e 100644 --- a/src/wireless-security/eap-method-tls.c +++ b/src/wireless-security/eap-method-tls.c @@ -30,6 +30,7 @@ #include "wireless-security.h" #include "helpers.h" #include "nma-ui-utils.h" +#include "utils.h" struct _EAPMethodTLS { EAPMethod parent; @@ -52,40 +53,56 @@ show_toggled_cb (GtkCheckButton *button, EAPMethod *method) } static gboolean -validate (EAPMethod *parent) +validate (EAPMethod *parent, GError **error) { NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; GtkWidget *widget; const char *password, *identity; + GError *local = NULL; widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "eap_tls_identity_entry")); g_assert (widget); identity = gtk_entry_get_text (GTK_ENTRY (widget)); - if (!identity || !strlen (identity)) + if (!identity || !strlen (identity)) { + g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("missing EAP-TLS identity")); return FALSE; + } - if (!eap_method_validate_filepicker (parent->builder, "eap_tls_ca_cert_button", TYPE_CA_CERT, NULL, NULL)) + if (!eap_method_validate_filepicker (parent->builder, "eap_tls_ca_cert_button", TYPE_CA_CERT, NULL, NULL, &local)) { + g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid EAP-TLS CA certificate: %s"), local->message); + g_clear_error (&local); return FALSE; - if (eap_method_ca_cert_required (parent->builder, "eap_tls_ca_cert_not_required_checkbox", "eap_tls_ca_cert_button") ) + } + if (eap_method_ca_cert_required (parent->builder, "eap_tls_ca_cert_not_required_checkbox", "eap_tls_ca_cert_button")) { + g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid EAP-TLS CA certificate: no certificate specified")); return FALSE; - + } widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "eap_tls_private_key_password_entry")); g_assert (widget); password = gtk_entry_get_text (GTK_ENTRY (widget)); - if (!password || !strlen (password)) + if (!password || !strlen (password)) { + g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid EAP-TLS password: missing")); return FALSE; + } if (!eap_method_validate_filepicker (parent->builder, "eap_tls_private_key_button", TYPE_PRIVATE_KEY, password, - &format)) + &format, + &local)) { + g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid EAP-TLS private-key: %s"), local->message); + g_clear_error (&local); return FALSE; + } if (format != NM_SETTING_802_1X_CK_FORMAT_PKCS12) { - if (!eap_method_validate_filepicker (parent->builder, "eap_tls_user_cert_button", TYPE_CLIENT_CERT, NULL, NULL)) + if (!eap_method_validate_filepicker (parent->builder, "eap_tls_user_cert_button", TYPE_CLIENT_CERT, NULL, NULL, &local)) { + g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid EAP-TLS user-certificate: %s"), local->message); + g_clear_error (&local); return FALSE; + } } return TRUE; diff --git a/src/wireless-security/eap-method-ttls.c b/src/wireless-security/eap-method-ttls.c index d0043730..9a76f78c 100644 --- a/src/wireless-security/eap-method-ttls.c +++ b/src/wireless-security/eap-method-ttls.c @@ -28,6 +28,7 @@ #include "eap-method.h" #include "wireless-security.h" +#include "utils.h" #define I_NAME_COLUMN 0 #define I_METHOD_COLUMN 1 @@ -50,18 +51,24 @@ destroy (EAPMethod *parent) } static gboolean -validate (EAPMethod *parent) +validate (EAPMethod *parent, GError **error) { GtkWidget *widget; GtkTreeModel *model; GtkTreeIter iter; EAPMethod *eap = NULL; gboolean valid = FALSE; + GError *local = NULL; - if (!eap_method_validate_filepicker (parent->builder, "eap_ttls_ca_cert_button", TYPE_CA_CERT, NULL, NULL)) + if (!eap_method_validate_filepicker (parent->builder, "eap_ttls_ca_cert_button", TYPE_CA_CERT, NULL, NULL, &local)) { + g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid EAP-TTLS CA certificate: %s"), local->message); + g_clear_error (&local); return FALSE; - if (eap_method_ca_cert_required (parent->builder, "eap_ttls_ca_cert_not_required_checkbox", "eap_ttls_ca_cert_button") ) + } + if (eap_method_ca_cert_required (parent->builder, "eap_ttls_ca_cert_not_required_checkbox", "eap_ttls_ca_cert_button")) { + g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid EAP-TTLS CA certificate: no certificate specified")); return FALSE; + } widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "eap_ttls_inner_auth_combo")); g_assert (widget); @@ -70,7 +77,7 @@ validate (EAPMethod *parent) gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter); gtk_tree_model_get (model, &iter, I_METHOD_COLUMN, &eap, -1); g_assert (eap); - valid = eap_method_validate (eap); + valid = eap_method_validate (eap, error); eap_method_unref (eap); return valid; } diff --git a/src/wireless-security/eap-method.c b/src/wireless-security/eap-method.c index 2218353c..978e0deb 100644 --- a/src/wireless-security/eap-method.c +++ b/src/wireless-security/eap-method.c @@ -34,6 +34,7 @@ #include "eap-method.h" #include "nm-utils.h" +#include "utils.h" G_DEFINE_BOXED_TYPE (EAPMethod, eap_method, eap_method_ref, eap_method_unref) @@ -46,12 +47,17 @@ eap_method_get_widget (EAPMethod *method) } gboolean -eap_method_validate (EAPMethod *method) +eap_method_validate (EAPMethod *method, GError **error) { + gboolean result; + g_return_val_if_fail (method != NULL, FALSE); g_assert (method->validate); - return (*(method->validate)) (method); + result = (*(method->validate)) (method, error); + if (!result && error && !*error) + g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("undefined error in 802.1x security (wpa-eap)")); + return result; } void @@ -207,13 +213,13 @@ eap_method_validate_filepicker (GtkBuilder *builder, const char *name, guint32 item_type, const char *password, - NMSetting8021xCKFormat *out_format) + NMSetting8021xCKFormat *out_format, + GError **error) { GtkWidget *widget; char *filename; NMSetting8021x *setting; gboolean success = FALSE; - GError *error = NULL; if (item_type == TYPE_PRIVATE_KEY) { g_return_val_if_fail (password != NULL, FALSE); @@ -232,25 +238,13 @@ eap_method_validate_filepicker (GtkBuilder *builder, setting = (NMSetting8021x *) nm_setting_802_1x_new (); if (item_type == TYPE_PRIVATE_KEY) { - if (!nm_setting_802_1x_set_private_key (setting, filename, password, NM_SETTING_802_1X_CK_SCHEME_PATH, out_format, &error)) { - g_warning ("Error: couldn't verify private key: %d %s", - error ? error->code : -1, error ? error->message : "(none)"); - g_clear_error (&error); - } else + if (nm_setting_802_1x_set_private_key (setting, filename, password, NM_SETTING_802_1X_CK_SCHEME_PATH, out_format, error)) success = TRUE; } else if (item_type == TYPE_CLIENT_CERT) { - if (!nm_setting_802_1x_set_client_cert (setting, filename, NM_SETTING_802_1X_CK_SCHEME_PATH, out_format, &error)) { - g_warning ("Error: couldn't verify client certificate: %d %s", - error ? error->code : -1, error ? error->message : "(none)"); - g_clear_error (&error); - } else + if (nm_setting_802_1x_set_client_cert (setting, filename, NM_SETTING_802_1X_CK_SCHEME_PATH, out_format, error)) success = TRUE; } else if (item_type == TYPE_CA_CERT) { - if (!nm_setting_802_1x_set_ca_cert (setting, filename, NM_SETTING_802_1X_CK_SCHEME_PATH, out_format, &error)) { - g_warning ("Error: couldn't verify CA certificate: %d %s", - error ? error->code : -1, error ? error->message : "(none)"); - g_clear_error (&error); - } else + if (nm_setting_802_1x_set_ca_cert (setting, filename, NM_SETTING_802_1X_CK_SCHEME_PATH, out_format, error)) success = TRUE; } else g_warning ("%s: invalid item type %d.", __func__, item_type); @@ -259,6 +253,9 @@ eap_method_validate_filepicker (GtkBuilder *builder, out: g_free (filename); + + if (!success && error && !*error) + g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("unspecified error validating eap-method file")); return success; } diff --git a/src/wireless-security/eap-method.h b/src/wireless-security/eap-method.h index e2ceb0a9..84c1c788 100644 --- a/src/wireless-security/eap-method.h +++ b/src/wireless-security/eap-method.h @@ -41,7 +41,7 @@ typedef void (*EMAddToSizeGroupFunc) (EAPMethod *method, GtkSizeGroup *gr typedef void (*EMFillConnectionFunc) (EAPMethod *method, NMConnection *connection, NMSettingSecretFlags flags); typedef void (*EMUpdateSecretsFunc) (EAPMethod *method, NMConnection *connection); typedef void (*EMDestroyFunc) (EAPMethod *method); -typedef gboolean (*EMValidateFunc) (EAPMethod *method); +typedef gboolean (*EMValidateFunc) (EAPMethod *method, GError **error); struct _EAPMethod { guint32 refcount; @@ -68,7 +68,7 @@ struct _EAPMethod { GtkWidget *eap_method_get_widget (EAPMethod *method); -gboolean eap_method_validate (EAPMethod *method); +gboolean eap_method_validate (EAPMethod *method, GError **error); void eap_method_add_to_size_group (EAPMethod *method, GtkSizeGroup *group); @@ -116,7 +116,8 @@ gboolean eap_method_validate_filepicker (GtkBuilder *builder, const char *name, guint32 item_type, const char *password, - NMSetting8021xCKFormat *out_format); + NMSetting8021xCKFormat *out_format, + GError **error); void eap_method_phase2_update_secrets_helper (EAPMethod *method, NMConnection *connection, diff --git a/src/wireless-security/wireless-security.c b/src/wireless-security/wireless-security.c index 12fee1eb..8c4e798f 100644 --- a/src/wireless-security/wireless-security.c +++ b/src/wireless-security/wireless-security.c @@ -30,6 +30,7 @@ #include "wireless-security.h" #include "eap-method.h" +#include "utils.h" G_DEFINE_BOXED_TYPE (WirelessSecurity, wireless_security, wireless_security_ref, wireless_security_unref) @@ -62,12 +63,18 @@ wireless_security_changed_cb (GtkWidget *ignored, gpointer user_data) } gboolean -wireless_security_validate (WirelessSecurity *sec) +wireless_security_validate (WirelessSecurity *sec, GError **error) { + gboolean result; + g_return_val_if_fail (sec != NULL, FALSE); + g_return_val_if_fail (!error || !*error, FALSE); g_assert (sec->validate); - return (*(sec->validate)) (sec); + result = (*(sec->validate)) (sec, error); + if (!result && error && !error) + g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("Unknown error validating 802.1x security")); + return result; } void @@ -287,7 +294,7 @@ ws_802_1x_add_to_size_group (WirelessSecurity *sec, } gboolean -ws_802_1x_validate (WirelessSecurity *sec, const char *combo_name) +ws_802_1x_validate (WirelessSecurity *sec, const char *combo_name, GError **error) { GtkWidget *widget; GtkTreeModel *model; @@ -302,7 +309,7 @@ ws_802_1x_validate (WirelessSecurity *sec, const char *combo_name) gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter); gtk_tree_model_get (model, &iter, AUTH_METHOD_COLUMN, &eap, -1); g_assert (eap); - valid = eap_method_validate (eap); + valid = eap_method_validate (eap, error); eap_method_unref (eap); return valid; } diff --git a/src/wireless-security/wireless-security.h b/src/wireless-security/wireless-security.h index 93a53a33..2cd845e4 100644 --- a/src/wireless-security/wireless-security.h +++ b/src/wireless-security/wireless-security.h @@ -42,7 +42,7 @@ typedef void (*WSAddToSizeGroupFunc) (WirelessSecurity *sec, GtkSizeGroup *group typedef void (*WSFillConnectionFunc) (WirelessSecurity *sec, NMConnection *connection); typedef void (*WSUpdateSecretsFunc) (WirelessSecurity *sec, NMConnection *connection); typedef void (*WSDestroyFunc) (WirelessSecurity *sec); -typedef gboolean (*WSValidateFunc) (WirelessSecurity *sec); +typedef gboolean (*WSValidateFunc) (WirelessSecurity *sec, GError **error); typedef GtkWidget * (*WSNagUserFunc) (WirelessSecurity *sec); struct _WirelessSecurity { @@ -74,7 +74,7 @@ void wireless_security_set_changed_notify (WirelessSecurity *sec, WSChangedFunc func, gpointer user_data); -gboolean wireless_security_validate (WirelessSecurity *sec); +gboolean wireless_security_validate (WirelessSecurity *sec, GError **error); void wireless_security_add_to_size_group (WirelessSecurity *sec, GtkSizeGroup *group); @@ -139,7 +139,7 @@ void ws_802_1x_auth_combo_changed (GtkWidget *combo, const char *vbox_name, GtkSizeGroup *size_group); -gboolean ws_802_1x_validate (WirelessSecurity *sec, const char *combo_name); +gboolean ws_802_1x_validate (WirelessSecurity *sec, const char *combo_name, GError **error); void ws_802_1x_add_to_size_group (WirelessSecurity *sec, GtkSizeGroup *size_group, diff --git a/src/wireless-security/ws-dynamic-wep.c b/src/wireless-security/ws-dynamic-wep.c index a450edbb..a5431adc 100644 --- a/src/wireless-security/ws-dynamic-wep.c +++ b/src/wireless-security/ws-dynamic-wep.c @@ -43,9 +43,9 @@ destroy (WirelessSecurity *parent) } static gboolean -validate (WirelessSecurity *parent) +validate (WirelessSecurity *parent, GError **error) { - return ws_802_1x_validate (parent, "dynamic_wep_auth_combo"); + return ws_802_1x_validate (parent, "dynamic_wep_auth_combo", error); } static void diff --git a/src/wireless-security/ws-leap.c b/src/wireless-security/ws-leap.c index 194571b3..b247e31b 100644 --- a/src/wireless-security/ws-leap.c +++ b/src/wireless-security/ws-leap.c @@ -21,10 +21,12 @@ */ #include <string.h> +#include <glib/gi18n.h> #include "wireless-security.h" #include "helpers.h" #include "nma-ui-utils.h" +#include "utils.h" struct _WirelessSecurityLEAP { WirelessSecurity parent; @@ -46,7 +48,7 @@ show_toggled_cb (GtkCheckButton *button, WirelessSecurity *sec) } static gboolean -validate (WirelessSecurity *parent) +validate (WirelessSecurity *parent, GError **error) { GtkWidget *entry; const char *text; @@ -54,14 +56,18 @@ validate (WirelessSecurity *parent) entry = GTK_WIDGET (gtk_builder_get_object (parent->builder, "leap_username_entry")); g_assert (entry); text = gtk_entry_get_text (GTK_ENTRY (entry)); - if (!text || !strlen (text)) + if (!text || !strlen (text)) { + g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("missing leap-username")); return FALSE; + } entry = GTK_WIDGET (gtk_builder_get_object (parent->builder, "leap_password_entry")); g_assert (entry); text = gtk_entry_get_text (GTK_ENTRY (entry)); - if (!text || !strlen (text)) + if (!text || !strlen (text)) { + g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("missing leap-password")); return FALSE; + } return TRUE; } diff --git a/src/wireless-security/ws-wep-key.c b/src/wireless-security/ws-wep-key.c index 57021ca6..14db35ef 100644 --- a/src/wireless-security/ws-wep-key.c +++ b/src/wireless-security/ws-wep-key.c @@ -22,6 +22,7 @@ #include <string.h> #include <glib.h> +#include <glib/gi18n.h> #include "wireless-security.h" #include "utils.h" @@ -89,7 +90,7 @@ destroy (WirelessSecurity *parent) } static gboolean -validate (WirelessSecurity *parent) +validate (WirelessSecurity *parent, GError **error) { WirelessSecurityWEPKey *sec = (WirelessSecurityWEPKey *) parent; GtkWidget *entry; @@ -100,26 +101,38 @@ validate (WirelessSecurity *parent) g_assert (entry); key = gtk_entry_get_text (GTK_ENTRY (entry)); - if (!key) + if (!key) { + g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("missing wep-key")); return FALSE; + } if (sec->type == NM_WEP_KEY_TYPE_KEY) { if ((strlen (key) == 10) || (strlen (key) == 26)) { for (i = 0; i < strlen (key); i++) { - if (!g_ascii_isxdigit (key[i])) + if (!g_ascii_isxdigit (key[i])) { + g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid wep-key: key with a length of %zu must contain only hex-digits"), strlen (key)); return FALSE; + } } } else if ((strlen (key) == 5) || (strlen (key) == 13)) { for (i = 0; i < strlen (key); i++) { - if (!utils_char_is_ascii_print (key[i])) + if (!utils_char_is_ascii_print (key[i])) { + g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid wep-key: key with a length of %zu must contain only ascii characters"), strlen (key)); return FALSE; + } } } else { + g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid wep-key: wrong key length %zu. A key must be either of length 5/13 (ascii) or 10/26 (hex)"), strlen (key)); return FALSE; } } else if (sec->type == NM_WEP_KEY_TYPE_PASSPHRASE) { - if (!strlen (key) || (strlen (key) > 64)) + if (!*key || (strlen (key) > 64)) { + if (!*key) + g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid wep-key: passphrase must be non-empty")); + else + g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid wep-key: passphrase must be shorter then 64 characters")); return FALSE; + } } return TRUE; diff --git a/src/wireless-security/ws-wpa-eap.c b/src/wireless-security/ws-wpa-eap.c index 3f888082..273479f3 100644 --- a/src/wireless-security/ws-wpa-eap.c +++ b/src/wireless-security/ws-wpa-eap.c @@ -44,9 +44,9 @@ destroy (WirelessSecurity *parent) } static gboolean -validate (WirelessSecurity *parent) +validate (WirelessSecurity *parent, GError **error) { - return ws_802_1x_validate (parent, "wpa_eap_auth_combo"); + return ws_802_1x_validate (parent, "wpa_eap_auth_combo", error); } static void diff --git a/src/wireless-security/ws-wpa-psk.c b/src/wireless-security/ws-wpa-psk.c index aed1f6ef..11a2752d 100644 --- a/src/wireless-security/ws-wpa-psk.c +++ b/src/wireless-security/ws-wpa-psk.c @@ -22,10 +22,12 @@ #include <ctype.h> #include <string.h> +#include <glib/gi18n.h> #include "wireless-security.h" #include "helpers.h" #include "nma-ui-utils.h" +#include "utils.h" #define WPA_PMK_LEN 32 @@ -50,26 +52,30 @@ show_toggled_cb (GtkCheckButton *button, WirelessSecurity *sec) } static gboolean -validate (WirelessSecurity *parent) +validate (WirelessSecurity *parent, GError **error) { GtkWidget *entry; const char *key; - guint32 len; + gsize len; int i; entry = GTK_WIDGET (gtk_builder_get_object (parent->builder, "wpa_psk_entry")); g_assert (entry); key = gtk_entry_get_text (GTK_ENTRY (entry)); - len = strlen (key); - if ((len < 8) || (len > 64)) + len = key ? strlen (key) : 0; + if ((len < 8) || (len > 64)) { + g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid wpa-psk: invalid key-length %zu. Must be [8,63] bytes or 64 hex digits"), len); return FALSE; + } if (len == 64) { /* Hex PSK */ for (i = 0; i < len; i++) { - if (!isxdigit (key[i])) + if (!isxdigit (key[i])) { + g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid wpa-psk: cannot interpret key with 64 bytes as hex")); return FALSE; + } } } |