[gnome-software/gnome-3-26] snap: Stop using snapd-login-service for versions of snapd that supports it



commit e715a49fa5e72f6b3b9ab48a93c0ab148aef808b
Author: Robert Ancell <robert ancell canonical com>
Date:   Mon Oct 30 15:56:11 2017 +1300

    snap: Stop using snapd-login-service for versions of snapd that supports it

 plugins/snap/gs-plugin-snap.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
---
diff --git a/plugins/snap/gs-plugin-snap.c b/plugins/snap/gs-plugin-snap.c
index 1eb049ec..0367b014 100644
--- a/plugins/snap/gs-plugin-snap.c
+++ b/plugins/snap/gs-plugin-snap.c
@@ -27,6 +27,7 @@
 
 struct GsPluginData {
        SnapdAuthData           *auth_data;
+       gboolean                 snapd_supports_polkit;
        SnapdSystemConfinement   system_confinement;
        GsAuth                  *auth;
 
@@ -196,6 +197,7 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
        GsPluginData *priv = gs_plugin_get_data (plugin);
        g_autoptr(SnapdClient) client = NULL;
        g_autoptr(SnapdSystemInformation) system_information = NULL;
+       g_auto(GStrv) version = NULL;
 
        client = get_client (plugin, error);
        if (client == NULL)
@@ -206,6 +208,15 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
                return FALSE;
        priv->system_confinement = snapd_system_information_get_confinement (system_information);
 
+       version = g_strsplit (snapd_system_information_get_version (system_information), ".", -1);
+       if (g_strv_length (version) >= 2) {
+               int major = g_ascii_strtoull (version[0], NULL, 10);
+               int minor = g_ascii_strtoull (version[1], NULL, 10);
+
+               if (major > 2 || (major == 2 && minor >= 28))
+                       priv->snapd_supports_polkit = TRUE;
+       }
+
        /* load from disk */
        gs_auth_add_metadata (priv->auth, "macaroon", NULL);
        if (!gs_auth_store_load (priv->auth,
@@ -934,8 +945,20 @@ gs_plugin_auth_login (GsPlugin *plugin, GsAuth *auth,
        if (auth != priv->auth)
                return TRUE;
 
+       /* snapd < 2.28 required root access to login, so we went via a D-Bus service (snapd-login-service).
+        * For newer versions we just access it directly */
        g_clear_object (&priv->auth_data);
-       priv->auth_data = snapd_login_sync (gs_auth_get_username (auth), gs_auth_get_password (auth), 
gs_auth_get_pin (auth), NULL, error);
+       if (priv->snapd_supports_polkit) {
+               g_autoptr(SnapdClient) client = NULL;
+
+               client = get_client (plugin, error);
+               if (client == NULL)
+                       return FALSE;
+
+               priv->auth_data = snapd_client_login_sync (client, gs_auth_get_username (auth), 
gs_auth_get_password (auth), gs_auth_get_pin (auth), NULL, error);
+       }
+       else
+               priv->auth_data = snapd_login_sync (gs_auth_get_username (auth), gs_auth_get_password (auth), 
gs_auth_get_pin (auth), NULL, error);
        if (priv->auth_data == NULL) {
                snapd_error_convert (error);
                return FALSE;


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