[NetworkManager-openvpn/th/auth-validation: 2/2] editor: when editing show unknown "auth" parameter in combo box



commit 01363cea4fef5566b6fa4369fee0f39634d17674
Author: Thomas Haller <thaller redhat com>
Date:   Thu Sep 27 08:52:52 2018 +0200

    editor: when editing show unknown "auth" parameter in combo box
    
    The "auth" parameter really depends on the SSL library which
    openvpn uses. We should accept values gracefully. In the GUI,
    the parameter is a combobox, so we must know which values
    are valid there. However, when editing an existing profile (for
    example, imported from .ovpn file), also accept an unknown digest
    and list it as valid selection in the GUI.
    
    This allows a user to set "auth" names which are unsupported by the
    GUI, and later editing the connection will not destroy the value.
    
    Also, get rid of HMACAUTH_COL_DEFAULT. It's not needed, because we
    can encode the default by having a %NULL HMACAUTH_COL_VALUE.
    
    Also, fix leaking "hmacauth" string in advanced_dialog_new_hash_from_dialog().
    
    https://gitlab.gnome.org/GNOME/NetworkManager-openvpn/issues/8

 properties/nm-openvpn-editor.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)
---
diff --git a/properties/nm-openvpn-editor.c b/properties/nm-openvpn-editor.c
index 2b6aa68..27b1261 100644
--- a/properties/nm-openvpn-editor.c
+++ b/properties/nm-openvpn-editor.c
@@ -894,12 +894,11 @@ populate_cipher_combo (GtkComboBox *box, const char *user_cipher)
 
 #define HMACAUTH_COL_NAME 0
 #define HMACAUTH_COL_VALUE 1
-#define HMACAUTH_COL_DEFAULT 2
 
 static void
 populate_hmacauth_combo (GtkComboBox *box, const char *hmacauth)
 {
-       GtkListStore *store;
+       gs_unref_object GtkListStore *store = NULL;
        GtkTreeIter iter;
        gboolean active_initialized = FALSE;
        int i;
@@ -925,7 +924,7 @@ populate_hmacauth_combo (GtkComboBox *box, const char *hmacauth)
        gtk_list_store_append (store, &iter);
        gtk_list_store_set (store, &iter,
                            HMACAUTH_COL_NAME, _("Default"),
-                           HMACAUTH_COL_DEFAULT, TRUE, -1);
+                           -1);
 
        for (i = 0; i < G_N_ELEMENTS (items); i++) {
                const char *name = items[i].name;
@@ -934,17 +933,21 @@ populate_hmacauth_combo (GtkComboBox *box, const char *hmacauth)
                gtk_list_store_set (store, &iter,
                                    HMACAUTH_COL_NAME, _(items[i].pretty_name),
                                    HMACAUTH_COL_VALUE, name,
-                                   HMACAUTH_COL_DEFAULT, FALSE, -1);
+                                   -1);
                if (hmacauth && !g_ascii_strcasecmp (name, hmacauth)) {
                        gtk_combo_box_set_active_iter (box, &iter);
                        active_initialized = TRUE;
                }
        }
 
-       if (!active_initialized)
-               gtk_combo_box_set_active (box, 0);
-
-       g_object_unref (store);
+       if (!active_initialized) {
+               gtk_list_store_append (store, &iter);
+               gtk_list_store_set (store, &iter,
+                                   HMACAUTH_COL_NAME, hmacauth,
+                                   HMACAUTH_COL_VALUE, hmacauth,
+                                   -1);
+               gtk_combo_box_set_active_iter (box, &iter);
+       }
 }
 
 #define TLS_REMOTE_MODE_NONE        "none"
@@ -2012,15 +2015,13 @@ advanced_dialog_new_hash_from_dialog (GtkWidget *dialog, GError **error)
        widget = GTK_WIDGET (gtk_builder_get_object (builder, "hmacauth_combo"));
        model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
        if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter)) {
-               char *hmacauth = NULL;
-               gboolean is_default = TRUE;
+               char *hmacauth;
 
                gtk_tree_model_get (model, &iter,
                                    HMACAUTH_COL_VALUE, &hmacauth,
-                                   HMACAUTH_COL_DEFAULT, &is_default, -1);
-               if (!is_default && hmacauth) {
-                       g_hash_table_insert (hash, g_strdup (NM_OPENVPN_KEY_AUTH), g_strdup (hmacauth));
-               }
+                                   -1);
+               if (hmacauth)
+                       g_hash_table_insert (hash, g_strdup (NM_OPENVPN_KEY_AUTH), hmacauth);
        }
 
        contype = g_object_get_data (G_OBJECT (dialog), "connection-type");


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]