Skip to content

Commit

Permalink
Added plain-store fallback to keyring
Browse files Browse the repository at this point in the history
  • Loading branch information
ManiacTwister committed Nov 1, 2013
1 parent 5dc6832 commit 01f5b87
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/common/secret_schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ get_hexchat_schema (void)
static const SecretSchema schema = {
"org.hexchat.Password", SECRET_SCHEMA_NONE,
{
{ "netname", SECRET_SCHEMA_ATTRIBUTE_STRING },
{ "network", SECRET_SCHEMA_ATTRIBUTE_STRING },
{ "NULL", 0 },
}
};
Expand Down
64 changes: 56 additions & 8 deletions src/common/servlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,9 @@ static const struct defaultserver def[] =
};

GSList *network_list = 0;
#ifdef USE_LIBSECRET
int pass_store_fallback = FALSE;
#endif

#if !GLIB_CHECK_VERSION(2,34,0)
#define g_slist_copy_deep servlist_slist_copy_deep
Expand Down Expand Up @@ -1061,7 +1064,7 @@ servlist_net_remove (ircnet *net)
#ifdef USE_LIBSECRET
/* To be sure that no old password is stored in the secret store we delete the password if net->pass is empty */
secret_password_clear (HEXCHAT_SCHEMA, NULL, NULL, NULL,
"netname", net->name, NULL);
"network", net->name, NULL);
#endif

free_and_clear(net->pass);
Expand Down Expand Up @@ -1266,9 +1269,10 @@ servlist_load (void)

#ifdef USE_LIBSECRET
gchar *password = secret_password_lookup_sync (HEXCHAT_SCHEMA, NULL, NULL,
"netname", net->name, NULL);
if (password != NULL) {
net->pass = g_strdup (password);
"network", net->name, NULL);
if (password != NULL)
{
net->pass = strdup (password);
secret_password_free (password);
}
#endif
Expand Down Expand Up @@ -1319,6 +1323,25 @@ servlist_check_encoding (char *charset)
return FALSE;
}

#ifdef USE_LIBSECRET
static void
on_password_stored (GObject *source, GAsyncResult *result, gpointer unused)
{
GError *error = NULL;

secret_password_store_finish (result, &error);
/* If storing the password in keyring failed try to store it again
* synchronously. If it fails again it will be stored in servlist config then.
*/
if (error != NULL) {
pass_store_fallback = TRUE;
servlist_save ();
pass_store_fallback = FALSE;
g_error_free (error);
}
}
#endif

int
servlist_save (void)
{
Expand Down Expand Up @@ -1378,9 +1401,26 @@ servlist_save (void)

dispName = g_strdup_printf(_("IRC (%s)"), net->name);

secret_password_store (HEXCHAT_SCHEMA, SECRET_COLLECTION_DEFAULT, dispName,
net->pass, NULL, NULL, NULL,
"netname", net->name, NULL);
if (hexchat_is_quitting || pass_store_fallback)
{
GError *error = NULL;
secret_password_store_sync (HEXCHAT_SCHEMA, SECRET_COLLECTION_DEFAULT, dispName,
net->pass, NULL, &error,
"network", net->name, NULL);
/* Store password in servlist config if storing in keyring fails */
if (error != NULL)
{
fprintf (fp, "P=%s\n", net->pass);
g_error_free (error);
}
}
else
{
secret_password_store (HEXCHAT_SCHEMA, SECRET_COLLECTION_DEFAULT, dispName,
net->pass, NULL, on_password_stored, NULL,
"network", net->name, NULL);
}
g_free (dispName);
#else
fprintf (fp, "P=%s\n", net->pass);
#endif
Expand All @@ -1389,8 +1429,16 @@ servlist_save (void)
else
{
/* To be sure that no old password is stored in the keyring we delete the password if net->pass is empty */
if (hexchat_is_quitting)
{
secret_password_clear_sync (HEXCHAT_SCHEMA, NULL, NULL,
"network", net->name, NULL);
}
else
{
secret_password_clear (HEXCHAT_SCHEMA, NULL, NULL, NULL,
"netname", net->name, NULL);
"network", net->name, NULL);
}
}
#endif
if (net->logintype)
Expand Down
8 changes: 8 additions & 0 deletions src/fe-gtk/servlistgui.c
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,10 @@ servlist_create_entry (GtkWidget *table, char *labeltext, int row,
static gint
servlist_delete_cb (GtkWidget *win, GdkEventAny *event, gpointer userdata)
{
#ifdef USE_LIBSECRET
if (sess_list == NULL)
hexchat_is_quitting = TRUE;
#endif
servlist_savegui ();
serverlist_win = NULL;
selected_net = NULL;
Expand All @@ -1281,6 +1285,10 @@ servlist_delete_cb (GtkWidget *win, GdkEventAny *event, gpointer userdata)
static void
servlist_close_cb (GtkWidget *button, gpointer userdata)
{
#ifdef USE_LIBSECRET
if (sess_list == NULL)
hexchat_is_quitting = TRUE;
#endif
servlist_savegui ();
gtk_widget_destroy (serverlist_win);
serverlist_win = NULL;
Expand Down

0 comments on commit 01f5b87

Please sign in to comment.