286
294
g_warning ("Unsupported value type for %s.%s", account, name);
297
if (!tp_strdiff (param, "password"))
299
/* Empathy 3.0 was meant to migrate passwords from MC to
300
* itself, but it couldn't complete the migration by
301
* deleting the password from MC, because MC had several
302
* bugs that meant deleting passwords didn't work. To atone
303
* for our past sins, detect an incomplete migration and
305
GnomeKeyringResult empathy_ok =
306
GNOME_KEYRING_RESULT_NO_KEYRING_DAEMON;
307
GnomeKeyringAttributeList *empathy_match =
308
gnome_keyring_attribute_list_new ();
309
GList *empathy_items = NULL;
311
gnome_keyring_attribute_list_append_string (empathy_match,
312
"account-id", account);
313
gnome_keyring_attribute_list_append_string (empathy_match,
314
"param-name", "password");
316
empathy_ok = gnome_keyring_find_items_sync (
317
GNOME_KEYRING_ITEM_GENERIC_SECRET, empathy_match,
320
if (empathy_ok == GNOME_KEYRING_RESULT_OK &&
321
empathy_items != NULL)
323
KeyringSetData *ksd = g_slice_new0 (KeyringSetData);
325
DEBUG ("An Empathy 3.0 password migration wasn't finished "
326
"due to fd.o #42088. Finishing it now by deleting the "
327
"password for %s", account);
329
ksd->account = g_strdup (account);
330
ksd->name = g_strdup ("password");
333
gnome_keyring_delete_password (&keyring_schema,
334
_keyring_set_cb, ksd, NULL,
340
gnome_keyring_found_list_free (empathy_items);
342
/* behave as if it had already been deleted, i.e. we never
343
* actually found it... */
289
348
if (param != NULL && value != NULL)
291
350
gchar *key = g_strdup_printf ("param-%s", param);
360
419
return g_build_filename (base, "accounts.cfg", NULL);
423
account_filename_in (const gchar *dir)
425
return g_build_filename (dir, "telepathy", "mission-control", "accounts.cfg",
364
430
mcd_account_manager_default_init (McdAccountManagerDefault *self)
366
432
DEBUG ("mcd_account_manager_default_init");
367
self->filename = get_account_conf_filename ();
433
self->filename = account_filename_in (g_get_user_data_dir ());
368
434
self->keyfile = g_key_file_new ();
369
435
self->secrets = g_key_file_new ();
370
436
self->removed = g_key_file_new ();
380
446
DEBUG ("mcd_account_manager_default_class_init");
384
_have_config (McdAccountManagerDefault *self)
386
DEBUG ("checking for %s", self->filename);
387
return g_file_test (self->filename, G_FILE_TEST_EXISTS);
391
_create_config (McdAccountManagerDefault *self)
393
gchar *dir = g_path_get_dirname (self->filename);
396
g_mkdir_with_parents (dir, 0700);
398
g_file_set_contents (self->filename, INITIAL_CONFIG, -1, NULL);
399
DEBUG ("created %s", self->filename);
402
449
/* We happen to know that the string MC gave us is "sufficiently escaped" to
403
450
* put it in the keyfile as-is. */
609
656
McdAccountManagerDefault *amd = MCD_ACCOUNT_MANAGER_DEFAULT (self);
610
657
gboolean rval = FALSE;
659
GError *error = NULL;
615
if (!_have_config (amd))
616
_create_config (amd);
664
dir = g_path_get_dirname (amd->filename);
666
DEBUG ("Saving accounts to %s", amd->filename);
668
if (!mcd_ensure_directory (dir, &error))
670
g_warning ("%s", error->message);
671
g_error_free (error);
672
/* fall through anyway: writing to the file will fail, but it does
673
* give us a chance to commit to the keyring too */
618
678
data = g_key_file_to_data (amd->keyfile, &n, NULL);
619
rval = g_file_set_contents (amd->filename, data, n, NULL);
679
rval = g_file_set_contents (amd->filename, data, n, &error);
687
g_warning ("%s", error->message);
688
g_error_free (error);
623
693
_keyring_commit (self, am, account);
699
am_default_load_keyfile (McdAccountManagerDefault *self,
700
const gchar *filename)
702
GError *error = NULL;
704
if (g_key_file_load_from_file (self->keyfile, filename,
705
G_KEY_FILE_KEEP_COMMENTS, &error))
707
DEBUG ("Loaded accounts from %s", filename);
711
DEBUG ("Failed to load accounts from %s: %s", filename, error->message);
712
g_error_free (error);
714
/* Start with a blank configuration, but do not save straight away;
715
* we don't want to overwrite a corrupt-but-maybe-recoverable
716
* configuration file with an empty one until given a reason to
718
g_key_file_load_from_data (self->keyfile, INITIAL_CONFIG, -1,
719
G_KEY_FILE_KEEP_COMMENTS, NULL);
629
724
_list (const McpAccountStorage *self,
630
725
const McpAccountManager *am)
635
730
GList *rval = NULL;
636
731
McdAccountManagerDefault *amd = MCD_ACCOUNT_MANAGER_DEFAULT (self);
638
if (!_have_config (amd))
639
_create_config (amd);
642
amd->loaded = g_key_file_load_from_file (amd->keyfile, amd->filename,
643
G_KEY_FILE_KEEP_COMMENTS, NULL);
733
if (!amd->loaded && g_file_test (amd->filename, G_FILE_TEST_EXISTS))
735
/* If the file exists, but loading it fails, we deliberately
736
* do not fall through to the "initial configuration" case,
737
* because we don't want to overwrite a corrupted file
738
* with an empty one until an actual write takes place. */
739
am_default_load_keyfile (amd, amd->filename);
745
const gchar * const *iter;
747
for (iter = g_get_system_data_dirs ();
748
iter != NULL && *iter != NULL;
751
gchar *filename = account_filename_in (*iter);
753
if (g_file_test (filename, G_FILE_TEST_EXISTS))
755
am_default_load_keyfile (amd, filename);
757
/* Do not set amd->save: we don't need to write it to a
758
* higher-priority directory until it actually changes. */
770
gchar *old_filename = get_old_filename ();
772
if (g_file_test (old_filename, G_FILE_TEST_EXISTS))
774
am_default_load_keyfile (amd, old_filename);
778
if (_commit (self, am, NULL))
780
DEBUG ("Migrated %s to new location: deleting old copy");
781
if (g_unlink (old_filename) != 0)
782
g_warning ("Unable to delete %s: %s", old_filename,
787
g_free (old_filename);
792
DEBUG ("Creating initial account data");
793
g_key_file_load_from_data (amd->keyfile, INITIAL_CONFIG, -1,
794
G_KEY_FILE_KEEP_COMMENTS, NULL);
797
_commit (self, am, NULL);
645
800
accounts = g_key_file_get_groups (amd->keyfile, &n);