After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 755316 - backends: Factorize common code in credential handling
backends: Factorize common code in credential handling
Status: RESOLVED OBSOLETE
Product: gnome-online-accounts
Classification: Core
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: GNOME Online Accounts maintainer(s)
GNOME Online Accounts maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2015-09-20 16:41 UTC by Christophe Fergeau
Modified: 2021-07-05 10:58 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
provider: Add goa_utils_get_credentials helper (3.44 KB, patch)
2015-09-20 16:41 UTC, Christophe Fergeau
none Details | Review
providers: Use goa_utils_get_credentials() (11.23 KB, patch)
2015-09-20 16:41 UTC, Christophe Fergeau
none Details | Review
imap-smtp: Use goa_utils_get_credentials in the provider (6.63 KB, patch)
2015-09-20 16:41 UTC, Christophe Fergeau
none Details | Review
imap-smtp: Fix c&p typo in error message (1.11 KB, patch)
2015-09-20 16:41 UTC, Christophe Fergeau
none Details | Review
Add goa_object_skeleton_attach_password_based (6.25 KB, patch)
2015-09-20 16:41 UTC, Christophe Fergeau
none Details | Review
providers: Use goa_object_skeleton_attach_password_based helper (13.36 KB, patch)
2015-09-20 16:41 UTC, Christophe Fergeau
none Details | Review
provider: Add goa_utils_get_credentials helper (3.49 KB, patch)
2015-10-17 11:00 UTC, Christophe Fergeau
none Details | Review
providers: Use goa_utils_get_credentials() (11.27 KB, patch)
2015-10-17 11:00 UTC, Christophe Fergeau
none Details | Review
imap-smtp: Use goa_utils_get_credentials in the provider (6.68 KB, patch)
2015-10-17 11:00 UTC, Christophe Fergeau
none Details | Review
imap-smtp: Fix c&p typo in error message (1.16 KB, patch)
2015-10-17 11:00 UTC, Christophe Fergeau
none Details | Review
Add goa_object_skeleton_attach_password_based (6.30 KB, patch)
2015-10-17 11:00 UTC, Christophe Fergeau
none Details | Review
providers: Use goa_object_skeleton_attach_password_based helper (13.41 KB, patch)
2015-10-17 11:00 UTC, Christophe Fergeau
none Details | Review
provider: Add goa_utils_get_credentials helper (3.49 KB, patch)
2015-11-17 11:22 UTC, Christophe Fergeau
none Details | Review
providers: Use goa_utils_get_credentials() (11.91 KB, patch)
2015-11-17 11:22 UTC, Christophe Fergeau
none Details | Review
imap-smtp: Use goa_utils_get_credentials in the provider (6.99 KB, patch)
2015-11-17 11:22 UTC, Christophe Fergeau
none Details | Review
imap-smtp: Fix c&p typo in error message (1.16 KB, patch)
2015-11-17 11:23 UTC, Christophe Fergeau
committed Details | Review
Add goa_object_skeleton_attach_password_based (6.63 KB, patch)
2015-11-17 11:23 UTC, Christophe Fergeau
none Details | Review
providers: Use goa_object_skeleton_attach_password_based helper (14.38 KB, patch)
2015-11-17 11:23 UTC, Christophe Fergeau
none Details | Review
provider: Add goa_utils_get_credentials helper (3.88 KB, patch)
2015-12-08 11:36 UTC, Christophe Fergeau
none Details | Review
providers: Use goa_utils_get_credentials() (12.78 KB, patch)
2015-12-08 11:36 UTC, Christophe Fergeau
none Details | Review
imap-smtp: Use goa_utils_get_credentials in the provider (6.99 KB, patch)
2015-12-08 11:37 UTC, Christophe Fergeau
none Details | Review
Add goa_object_skeleton_attach_password_based (6.57 KB, patch)
2015-12-08 11:37 UTC, Christophe Fergeau
none Details | Review
providers: Use goa_object_skeleton_attach_password_based helper (14.29 KB, patch)
2015-12-08 11:37 UTC, Christophe Fergeau
none Details | Review
utils: Add goa_utils_get_credentials helper (3.75 KB, patch)
2016-01-21 13:36 UTC, Debarshi Ray
committed Details | Review
exchange, lastfm, owncloud: Use goa_utils_get_credentials() (11.34 KB, patch)
2016-01-21 13:37 UTC, Debarshi Ray
committed Details | Review
imap-smtp: Use goa_utils_get_credentials in the provider (6.31 KB, patch)
2016-01-21 14:13 UTC, Debarshi Ray
committed Details | Review
Add goa_object_skeleton_attach_password_based (6.31 KB, patch)
2016-01-26 10:15 UTC, Christophe Fergeau
none Details | Review
providers: Use goa_object_skeleton_attach_password_based helper (13.49 KB, patch)
2016-01-26 10:15 UTC, Christophe Fergeau
none Details | Review
backend: Add and use GoaPasswordBased base class (26.66 KB, patch)
2016-02-15 19:59 UTC, Christophe Fergeau
none Details | Review
backend: Add and use GoaPasswordBased base class (25.67 KB, patch)
2017-10-21 17:44 UTC, Christophe Fergeau
none Details | Review

Description Christophe Fergeau 2015-09-20 16:41:17 UTC
This series adds a few helpers to help remove duplicated code in the various
backends.
Comment 1 Christophe Fergeau 2015-09-20 16:41:21 UTC
Created attachment 311708 [details] [review]
provider: Add goa_utils_get_credentials helper

This helper gathers code which is duplicated among several
password-based providers. Eventually, a GoaPasswordBasedProvider base
class could be introduced similarly to what is done for the oauth based
providers.
Comment 2 Christophe Fergeau 2015-09-20 16:41:27 UTC
Created attachment 311709 [details] [review]
providers: Use goa_utils_get_credentials()
Comment 3 Christophe Fergeau 2015-09-20 16:41:34 UTC
Created attachment 311710 [details] [review]
imap-smtp: Use goa_utils_get_credentials in the provider

Less straightforward that the other ones as the username is not obtained
through goa_account_get_identity() but comes from the config file.
Also, the credentials GVariant was used twice, once for IMAP and once
for SMTP. I chose to call goa_utils_get_credentials() twice instead.
Comment 4 Christophe Fergeau 2015-09-20 16:41:40 UTC
Created attachment 311711 [details] [review]
imap-smtp: Fix c&p typo in error message

When failing to authenticate with the SMTP server using the SMTP
login/password, the error message would mention the IMAP login, not the
SMTP login.
Comment 5 Christophe Fergeau 2015-09-20 16:41:47 UTC
Created attachment 311712 [details] [review]
Add goa_object_skeleton_attach_password_based

This code is copied and pasted between all providers implementing the
GoaPasswordBased DBus interface. This commit adds a helper method so
that the various backend can share the code instead of duplicating it.
Comment 6 Christophe Fergeau 2015-09-20 16:41:53 UTC
Created attachment 311713 [details] [review]
providers: Use goa_object_skeleton_attach_password_based helper

This allows to remove quite a bit of code.
Comment 7 Christophe Fergeau 2015-10-17 11:00:26 UTC
Created attachment 313522 [details] [review]
provider: Add goa_utils_get_credentials helper

This helper gathers code which is duplicated among several
password-based providers. Eventually, a GoaPasswordBasedProvider base
class could be introduced similarly to what is done for the oauth based
providers.
Comment 8 Christophe Fergeau 2015-10-17 11:00:32 UTC
Created attachment 313523 [details] [review]
providers: Use goa_utils_get_credentials()
Comment 9 Christophe Fergeau 2015-10-17 11:00:37 UTC
Created attachment 313524 [details] [review]
imap-smtp: Use goa_utils_get_credentials in the provider

Less straightforward that the other ones as the username is not obtained
through goa_account_get_identity() but comes from the config file.
Also, the credentials GVariant was used twice, once for IMAP and once
for SMTP. I chose to call goa_utils_get_credentials() twice instead.
Comment 10 Christophe Fergeau 2015-10-17 11:00:41 UTC
Created attachment 313525 [details] [review]
imap-smtp: Fix c&p typo in error message

When failing to authenticate with the SMTP server using the SMTP
login/password, the error message would mention the IMAP login, not the
SMTP login.
Comment 11 Christophe Fergeau 2015-10-17 11:00:47 UTC
Created attachment 313526 [details] [review]
Add goa_object_skeleton_attach_password_based

This code is copied and pasted between all providers implementing the
GoaPasswordBased DBus interface. This commit adds a helper method so
that the various backend can share the code instead of duplicating it.
Comment 12 Christophe Fergeau 2015-10-17 11:00:52 UTC
Created attachment 313527 [details] [review]
providers: Use goa_object_skeleton_attach_password_based helper

This allows to remove quite a bit of code.
Comment 13 Christophe Fergeau 2015-10-17 11:02:45 UTC
Only change in the updated patches is that I added the bug reference to the commit logs
Comment 14 Christophe Fergeau 2015-11-17 11:22:47 UTC
Created attachment 315737 [details] [review]
provider: Add goa_utils_get_credentials helper

This helper gathers code which is duplicated among several
password-based providers. Eventually, a GoaPasswordBasedProvider base
class could be introduced similarly to what is done for the oauth based
providers.
Comment 15 Christophe Fergeau 2015-11-17 11:22:52 UTC
Created attachment 315738 [details] [review]
providers: Use goa_utils_get_credentials()
Comment 16 Christophe Fergeau 2015-11-17 11:22:58 UTC
Created attachment 315739 [details] [review]
imap-smtp: Use goa_utils_get_credentials in the provider

Less straightforward that the other ones as the username is not obtained
through goa_account_get_identity() but comes from the config file.
Also, the credentials GVariant was used twice, once for IMAP and once
for SMTP. I chose to call goa_utils_get_credentials() twice instead.
Comment 17 Christophe Fergeau 2015-11-17 11:23:02 UTC
Created attachment 315740 [details] [review]
imap-smtp: Fix c&p typo in error message

When failing to authenticate with the SMTP server using the SMTP
login/password, the error message would mention the IMAP login, not the
SMTP login.
Comment 18 Christophe Fergeau 2015-11-17 11:23:08 UTC
Created attachment 315741 [details] [review]
Add goa_object_skeleton_attach_password_based

This code is copied and pasted between all providers implementing the
GoaPasswordBased DBus interface. This commit adds a helper method so
that the various backend can share the code instead of duplicating it.
Comment 19 Christophe Fergeau 2015-11-17 11:23:13 UTC
Created attachment 315742 [details] [review]
providers: Use goa_object_skeleton_attach_password_based helper

This allows to remove quite a bit of code.
Comment 20 Christophe Fergeau 2015-11-17 11:24:17 UTC
Rebased on top of master to take into account "595cb4f Sprinkle some debug messages when handling D-Bus calls", no other changes.
Comment 21 Debarshi Ray 2015-11-19 13:17:08 UTC
Review of attachment 315737 [details] [review]:

Thanks for the patches, Christophe.

::: src/goabackend/goautils.c
@@ +628,3 @@
+
+  account = goa_object_peek_account (object);
+  username = goa_account_get_identity (account);

Note that it is dangerous to use goa_object_peek_account and goa_account_get_identity here. We should use goa_account_get_account and goa_account_dup_identity.

If you grep for HANDLE_METHOD_INVOCATIONS_IN_THREAD, then you will notice that this code gets used in a thread other than the one where "object" was created. If you happen to call goa_object_peek_account at the same instant when the org.gnome.OnlineAccounts.Account interface is removed from the GoaObject, then the code will crash. The reason it doesn't crash so much in practice is because we almost never remove the org.gnome.OnlineAccounts.Account interface, unlike ones like org.gnome.OnlineAccounts.Mail and org.gnome.OnlineAccounts.Photos which get toggled by the GtkSwitch in Settings -> Online Accounts.

This is an error induced by cargo-culting the same code over and over and has been like this since forever. Recently we were discussing this in the context of bug 756498

Since you are touching this code, maybe take the opportunity to also use the right method calls? Or we can do it in a separate patch. Up to you.

@@ +651,3 @@
+    *out_username = username;
+  if (out_password)
+    *out_password = password;

We already asserted that out_username and out_password can't be NULL, so the checks are not needed. Although it does seem to be a nice touch to be able to atleast pass a NULL out_username.
Comment 22 Debarshi Ray 2015-11-19 13:27:45 UTC
Review of attachment 315737 [details] [review]:

::: src/goabackend/goautils.c
@@ +637,3 @@
+                                GOA_ERROR_FAILED, /* TODO: more specific */
+                                _("Did not find '%s' with identity ‘%s’ in credentials"),
+                                id, username);

g_set_error would be nicer. We won't have to worry about a NULL error, and we are already using it everywhere.

(We should fix the few remaining uses of g_error_new.)
Comment 23 Debarshi Ray 2015-11-19 13:31:06 UTC
Review of attachment 315738 [details] [review]:

::: src/goabackend/goaexchangeprovider.c
@@ +960,3 @@
+                                   object,
+                                   "password",
+                                   &identity,

We don't need 'identity' anymore. This is what made me think that being able to pass NULL would be nice.

::: src/goabackend/goaowncloudprovider.c
@@ +1112,3 @@
+                                   &password,
+                                   NULL, /* GCancellable */
+                                   &error);

Ditto.
Comment 24 Debarshi Ray 2015-11-19 13:34:01 UTC
Review of attachment 315739 [details] [review]:

::: src/goabackend/goaimapsmtpprovider.c
@@ +326,3 @@
+                                   object,
+                                   "imap-password",
+                                   NULL,

You can't pass NULL the way things stand at the moment. :)

@@ +390,3 @@
+                                   object,
+                                   "smtp-password",
+                                   NULL,

Ditto.
Comment 25 Debarshi Ray 2015-11-19 13:36:41 UTC
Review of attachment 315740 [details] [review]:

Good catch. Thanks.
Comment 26 Debarshi Ray 2015-11-19 14:04:33 UTC
Review of attachment 315741 [details] [review]:

I wonder what the pros and cons of adding a GoaPasswordProvider base class would be. These providers, by their very nature, don't have much in common other than the GetPassword implementations, but a base class would be consistent with the way we handle the OAuth and OAuth2.

::: src/goabackend/goaobjectskeletonutils.c
@@ +60,3 @@
+                                   /* FIXME: is this going to be fine for owncloud/... ? */
+                                   /* used to be a hardcoded "password" */
+                                   id,

Both the Exchange and ownCloud providers do this. I checked all known users, and evolution-data-server passes "" instead of "password" as the ID. So, maybe, add a check like this for the time being:
if (id == NULL || id[0] == '\0')
  id = "password";

That would make life easier for developers who might have a mismatch between their g-o-a and e-d-s versions. In the meantime we can make e-d-s pass "password".
Comment 27 Debarshi Ray 2015-11-19 14:24:32 UTC
Comment on attachment 315740 [details] [review]
imap-smtp: Fix c&p typo in error message

Pushed to master, gnome-3-18, gnome-3-16 and gnome-3-14.
Comment 28 Christophe Fergeau 2015-12-08 11:36:53 UTC
Created attachment 316926 [details] [review]
provider: Add goa_utils_get_credentials helper

This helper gathers code which is duplicated among several
password-based providers. Eventually, a GoaPasswordBasedProvider base
class could be introduced similarly to what is done for the oauth based
providers.

The addition of this new helper is used as an opportunity for small
cleanups in the code which was copied/pasted between the various
providers:
- g_set_error is used instead of g_error_new
- goa_object_get_account and goa_account_dup_identity are used instead
  of goa_object_peek_account and goa_account_get_identity as using the
  former has some thread-safety issues (see bug #755316 for details)
Comment 29 Christophe Fergeau 2015-12-08 11:36:59 UTC
Created attachment 316927 [details] [review]
providers: Use goa_utils_get_credentials()
Comment 30 Christophe Fergeau 2015-12-08 11:37:05 UTC
Created attachment 316928 [details] [review]
imap-smtp: Use goa_utils_get_credentials in the provider

Less straightforward that the other ones as the username is not obtained
through goa_account_get_identity() but comes from the config file.
Also, the credentials GVariant was used twice, once for IMAP and once
for SMTP. I chose to call goa_utils_get_credentials() twice instead.
Comment 31 Christophe Fergeau 2015-12-08 11:37:11 UTC
Created attachment 316929 [details] [review]
Add goa_object_skeleton_attach_password_based

This code is copied and pasted between all providers implementing the
GoaPasswordBased DBus interface. This commit adds a helper method so
that the various backend can share the code instead of duplicating it.
Comment 32 Christophe Fergeau 2015-12-08 11:37:16 UTC
Created attachment 316930 [details] [review]
providers: Use goa_object_skeleton_attach_password_based helper

This allows to remove quite a bit of code.
Comment 33 Christophe Fergeau 2015-12-08 11:39:05 UTC
Review of attachment 315741 [details] [review]:

I've resent the patches without trying your base class suggestion, I'll try looking into it, but not sure when I will have time to spend on that.

::: src/goabackend/goaobjectskeletonutils.c
@@ +60,3 @@
+                                   /* FIXME: is this going to be fine for owncloud/... ? */
+                                   /* used to be a hardcoded "password" */
+                                   id,

Empathy is also passing "" so I've added the check and a g_warning.
Comment 34 Christophe Fergeau 2015-12-08 11:41:09 UTC
Review of attachment 316927 [details] [review]:

::: src/goabackend/goautils.c
@@ -619,3 @@
-  g_return_val_if_fail (out_username != NULL, FALSE);
-  g_return_val_if_fail (out_password != NULL, FALSE);
-

Sorry, this hunk is out of place and should go in the previous commit
Comment 35 Debarshi Ray 2016-01-21 13:35:16 UTC
Review of attachment 316926 [details] [review]:

Thanks Christophe. A few small things:

::: src/goabackend/goautils.c
@@ +633,3 @@
+    {
+      g_set_error (error, GOA_ERROR, GOA_ERROR_FAILED, /* TODO: more specific */
+                   _("Did not find '%s' with identity ‘%s’ in credentials"),

Nitpick. Don't use the ASCII single quotes around the first %s. Two reasons:
(i) The strings that we are about to replace don't use the first set of quotes.
(ii) More importantly, if we really want to use quotes, then we should use Unicode ones. Philip spent some time fixing those up (see bug 707435), so it is better not to regress on that front.

@@ +636,3 @@
+                   id, username);
+      g_free (username);
+      username = NULL;

I will sleep better if we freed them in only one spot. We can accomplish that by assigning the values to the 'out' variables just before the 'out:' target, and setting the local variables to NULL.

@@ +644,3 @@
+out:
+  if (account != NULL)
+    g_object_unref (account);

g_clear_object will make this simpler.

@@ +646,3 @@
+    g_object_unref (account);
+  if (credentials != NULL)
+    g_variant_unref (credentials);

Ditto, but g_clear_pointer.
Comment 36 Debarshi Ray 2016-01-21 13:35:48 UTC
Review of attachment 316927 [details] [review]:

::: src/goabackend/goaowncloudprovider.c
@@ +347,3 @@
   gboolean accept_ssl_errors;
   gboolean ret;
+  gchar *username;

This should be NULL initialized. Otherwise we are relying on goa_utils_get_credentials to set it to NULL even when it failed. That is a bit fragile.

@@ +1113,3 @@
+                                   NULL, /* GCancellable */
+                                   &error);
+  if (!ret)

Nitpick. We could directly check the return value inside the if (...).
Comment 37 Debarshi Ray 2016-01-21 13:36:53 UTC
Created attachment 319492 [details] [review]
utils: Add goa_utils_get_credentials helper

I took the liberty to address the above comments and also moved the chunk from the other patch.
Comment 38 Debarshi Ray 2016-01-21 13:37:28 UTC
Created attachment 319493 [details] [review]
exchange, lastfm, owncloud: Use goa_utils_get_credentials()
Comment 39 Debarshi Ray 2016-01-21 14:12:32 UTC
Review of attachment 316928 [details] [review]:

::: src/goabackend/goaimapsmtpprovider.c
@@ +387,3 @@
     }
 
+  ret = goa_utils_get_credentials (provider,

Oops! The older code had a bug lurking in here. If the g_variant_lookup failed, we would throw an error but still return TRUE. :(

Let's fix this in a separate patch so that we can backport it to older branches.
Comment 40 Debarshi Ray 2016-01-21 14:13:47 UTC
Created attachment 319499 [details] [review]
imap-smtp: Use goa_utils_get_credentials in the provider

I took the liberty to make the above adjustment.
Comment 41 Debarshi Ray 2016-01-22 15:31:04 UTC
(In reply to Debarshi Ray from comment #39)
> Review of attachment 316928 [details] [review] [review]:
> 
> ::: src/goabackend/goaimapsmtpprovider.c
> @@ +387,3 @@
>      }
>  
> +  ret = goa_utils_get_credentials (provider,
> 
> Oops! The older code had a bug lurking in here. If the g_variant_lookup
> failed, we would throw an error but still return TRUE. :(
> 
> Let's fix this in a separate patch so that we can backport it to older
> branches.

I filed bug 760991 for it.
Comment 42 Christophe Fergeau 2016-01-26 10:15:01 UTC
Created attachment 319740 [details] [review]
Add goa_object_skeleton_attach_password_based

This code is copied and pasted between all providers implementing the
GoaPasswordBased DBus interface. This commit adds a helper method so
that the various backend can share the code instead of duplicating it.
Comment 43 Christophe Fergeau 2016-01-26 10:15:08 UTC
Created attachment 319741 [details] [review]
providers: Use goa_object_skeleton_attach_password_based helper

This allows to remove quite a bit of code.
Comment 44 Christophe Fergeau 2016-01-26 10:16:31 UTC
I've rebased the 2 remaining patches on top of master. Let me know if you'd prefer if I explore now the base class suggestion you made in comment #26.
Comment 45 Christophe Fergeau 2016-01-26 10:19:22 UTC
Alternatively, now that the goa_utils_get_credentials() patches went in, these last 2 patches could also be managed as part of a larger series I still have pending which add goa_object_skeleton_attach_{calendar,files,contacts,...} helpers.
Comment 46 Christophe Fergeau 2016-02-15 19:59:53 UTC
Created attachment 321309 [details] [review]
backend: Add and use GoaPasswordBased base class

This code is copied and pasted between all providers implementing the
GoaPasswordBased DBus interface. This commit adds a base
GoaPasswordBased class so that the various backend can share the code
instead of duplicating it.
Comment 47 Christophe Fergeau 2017-10-21 17:44:06 UTC
Created attachment 362020 [details] [review]
backend: Add and use GoaPasswordBased base class

This code is copied and pasted between all providers implementing the
GoaPasswordBased DBus interface. This commit adds a base
GoaPasswordBased class so that the various backend can share the code
instead of duplicating it.
Comment 48 GNOME Infrastructure Team 2021-07-05 10:58:35 UTC
GNOME is going to shut down bugzilla.gnome.org in favor of gitlab.gnome.org.
As part of that, we are mass-closing older open tickets in bugzilla.gnome.org
which have not seen updates for a longer time (resources are unfortunately
quite limited so not every ticket can get handled).

If you can still reproduce the situation described in this ticket in a recent
and supported software version, then please follow
  https://wiki.gnome.org/GettingInTouch/BugReportingGuidelines
and create a new ticket at
  https://gitlab.gnome.org/GNOME/gnome-online-accounts/-/issues/

Thank you for your understanding and your help.