From 7b301aee94c6c6e62ef5afc0c3be88735f03ba0e Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 23 Jul 2013 19:50:34 +0000 Subject: Fix credential access with libsecret, bug 704744 When storing attributes in libsecret, string attributes are not permitted to have NULL values. The existing workaround for this was wrong, as it removed the ability to store passwords for username-less connections. Fix this by terminating the attribute list with a NULL attribute, thus ending the list, if there is no username. --- diff --git a/plugins/vnc/vinagre-vnc-tab.c b/plugins/vnc/vinagre-vnc-tab.c index 7cae9f2..73a13b8 100644 --- a/plugins/vnc/vinagre-vnc-tab.c +++ b/plugins/vnc/vinagre-vnc-tab.c @@ -492,11 +492,7 @@ vnc_authentication_cb (VncDisplay *vnc, GValueArray *credList, VinagreVncTab *vn if (need_password || need_username) { - /* libsecret does not support NULL attributes, bug 685041. */ - if (vinagre_connection_get_username (conn) != NULL) - { - vinagre_tab_find_credentials_in_keyring (tab, &username, &password); - } + vinagre_tab_find_credentials_in_keyring (tab, &username, &password); if ( (need_username && !username) || (need_password && !password) ) { diff --git a/vinagre/vinagre-tab.c b/vinagre/vinagre-tab.c index 2f06e0d..284e469 100644 --- a/vinagre/vinagre-tab.c +++ b/vinagre/vinagre-tab.c @@ -745,19 +745,21 @@ vinagre_tab_get_from_connection (VinagreConnection *conn) gboolean vinagre_tab_find_credentials_in_keyring (VinagreTab *tab, gchar **username, gchar **password) { + const gchar *conn_user = vinagre_connection_get_username (tab->priv->conn); *username = NULL; + /* "user" goes last, to terminate the attribute list if conn_user is NULL. */ *password = secret_password_lookup_sync (SECRET_SCHEMA_COMPAT_NETWORK, NULL, NULL, - "user", vinagre_connection_get_username (tab->priv->conn), "server", vinagre_connection_get_host (tab->priv->conn), "protocol", vinagre_connection_get_protocol (tab->priv->conn), "port", vinagre_connection_get_port (tab->priv->conn), + conn_user ? "user" : NULL, conn_user, NULL); if (*password == NULL) return FALSE; - *username = g_strdup (vinagre_connection_get_username (tab->priv->conn)); + *username = g_strdup (conn_user); return TRUE; } @@ -771,18 +773,20 @@ vinagre_tab_save_credentials_in_keyring (VinagreTab *tab) { GError *error = NULL; gchar *label; + const gchar *conn_user = vinagre_connection_get_username (tab->priv->conn); if (!tab->priv->save_credentials) return; label = g_strdup_printf (_("Remote desktop password: %s"), vinagre_connection_get_host (tab->priv->conn)); + /* "user" goes last, to terminate the attribute list if conn_user is NULL. */ secret_password_store_sync (SECRET_SCHEMA_COMPAT_NETWORK, NULL, label, vinagre_connection_get_password (tab->priv->conn), NULL, &error, - "user", vinagre_connection_get_username (tab->priv->conn), "server", vinagre_connection_get_host (tab->priv->conn), "protocol", vinagre_connection_get_protocol (tab->priv->conn), "port", vinagre_connection_get_port (tab->priv->conn), + conn_user ? "user" : NULL, conn_user, NULL); g_free (label); @@ -803,11 +807,13 @@ void vinagre_tab_remove_credentials_from_keyring (VinagreTab *tab) { if (tab->priv->saved_credentials) { + /* Put "user" last, to terminate the attributes if conn_user is NULL. */ + const gchar *conn_user = vinagre_connection_get_username (tab->priv->conn); secret_password_clear_sync (SECRET_SCHEMA_COMPAT_NETWORK, NULL, NULL, - "user", vinagre_connection_get_username (tab->priv->conn), "server", vinagre_connection_get_host (tab->priv->conn), "protocol", vinagre_connection_get_protocol (tab->priv->conn), "port", vinagre_connection_get_port (tab->priv->conn), + conn_user ? "user" : NULL, conn_user, NULL); tab->priv->saved_credentials = FALSE; } -- cgit v0.9.2