~ubuntu-desktop/gnome-software/ubuntu-zesty

« back to all changes in this revision

Viewing changes to debian/patches/0001-snap-Only-show-snaps-as-sandboxed-if-snapd-supports-.patch

  • Committer: Robert Ancell
  • Date: 2017-10-26 23:07:23 UTC
  • Revision ID: robert.ancell@canonical.com-20171026230723-hjocl1r695t639wu
* debian/patches/0001-snap-Protect-store-cache-with-a-lock.patch:
  - Fix crash due to multiple threads accessing a cache (LP: #1716633)
* debian/patches/0001-snap-Don-t-attempt-to-refine-snaps-without-a-valid-n.patch:
  - Fix potential crash from invalid snaps
* debian/patches/0001-snap-Fix-leak-of-GsApp.patch:
  - Fix small memory leak
* debian/patches/0001-snap-Only-show-snaps-as-sandboxed-if-snapd-supports-.patch:
  - Simple patch added to make above patches apply cleanly

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
From d43048a036f66e21dbc39ab4e7c907ca11dae58e Mon Sep 17 00:00:00 2001
 
2
From: Robert Ancell <robert.ancell@canonical.com>
 
3
Date: Fri, 7 Jul 2017 11:43:03 +1200
 
4
Subject: [PATCH] snap: Only show snaps as sandboxed if snapd supports
 
5
 confinmenent
 
6
 
 
7
---
 
8
 src/plugins/gs-plugin-snap.c | 10 +++++++++-
 
9
 src/plugins/gs-snapd.c       | 42 ++++++++++++++++++++++++++++++++++++++++++
 
10
 src/plugins/gs-snapd.h       |  3 +++
 
11
 3 files changed, 54 insertions(+), 1 deletion(-)
 
12
 
 
13
diff --git a/src/plugins/gs-plugin-snap.c b/src/plugins/gs-plugin-snap.c
 
14
index 80b74ae5..5dea8575 100644
 
15
--- a/src/plugins/gs-plugin-snap.c
 
16
+++ b/src/plugins/gs-plugin-snap.c
 
17
@@ -28,6 +28,7 @@
 
18
 #include "gs-snapd.h"
 
19
 
 
20
 struct GsPluginData {
 
21
+       gboolean         system_is_confined;
 
22
        GsAuth          *auth;
 
23
        GHashTable      *store_snaps;
 
24
 };
 
25
@@ -63,6 +64,12 @@ gboolean
 
26
 gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
 
27
 {
 
28
        GsPluginData *priv = gs_plugin_get_data (plugin);
 
29
+       g_autoptr(JsonObject) system_information = NULL;
 
30
+
 
31
+       system_information = gs_snapd_get_system_info (cancellable, error);
 
32
+       if (system_information == NULL)
 
33
+               return FALSE;
 
34
+       priv->system_is_confined = g_strcmp0 (json_object_get_string_member (system_information, "confinement"), "strict") == 0;
 
35
 
 
36
        /* load from disk */
 
37
        gs_auth_add_metadata (priv->auth, "macaroon", NULL);
 
38
@@ -170,6 +177,7 @@ get_snap_title (JsonObject *snap)
 
39
 static GsApp *
 
40
 snap_to_app (GsPlugin *plugin, JsonObject *snap)
 
41
 {
 
42
+       GsPluginData *priv = gs_plugin_get_data (plugin);
 
43
        GsApp *app;
 
44
 
 
45
        /* create a unique ID for deduplication, TODO: branch? */
 
46
@@ -182,7 +190,7 @@ snap_to_app (GsPlugin *plugin, JsonObject *snap)
 
47
        gs_app_set_name (app, GS_APP_QUALITY_HIGHEST, get_snap_title (snap));
 
48
        if (gs_plugin_check_distro_id (plugin, "ubuntu"))
 
49
                gs_app_add_quirk (app, AS_APP_QUIRK_PROVENANCE);
 
50
-       if (g_strcmp0 (json_object_get_string_member (snap, "confinement"), "strict") == 0)
 
51
+       if (priv->system_is_confined && g_strcmp0 (json_object_get_string_member (snap, "confinement"), "strict") == 0)
 
52
                gs_app_add_kudo (app, GS_APP_KUDO_SANDBOXED);
 
53
 
 
54
        return app;
 
55
diff --git a/src/plugins/gs-snapd.c b/src/plugins/gs-snapd.c
 
56
index 79574936..deb34cd8 100644
 
57
--- a/src/plugins/gs-snapd.c
 
58
+++ b/src/plugins/gs-snapd.c
 
59
@@ -344,6 +344,48 @@ parse_result (const gchar *response, const gchar *response_type, GError **error)
 
60
        return g_object_ref (parser);
 
61
 }
 
62
 
 
63
+JsonObject *
 
64
+gs_snapd_get_system_info (GCancellable *cancellable, GError **error)
 
65
+{
 
66
+       guint status_code;
 
67
+       g_autofree gchar *reason_phrase = NULL;
 
68
+       g_autofree gchar *response_type = NULL;
 
69
+       g_autofree gchar *response = NULL;
 
70
+       g_autoptr(JsonParser) parser = NULL;
 
71
+       JsonObject *root, *result;
 
72
+
 
73
+       if (!send_request ("GET", "/v2/system-info", NULL,
 
74
+                          NULL, NULL,
 
75
+                          &status_code, &reason_phrase,
 
76
+                          &response_type, &response, NULL,
 
77
+                          cancellable, error))
 
78
+               return NULL;
 
79
+
 
80
+       if (status_code != SOUP_STATUS_OK) {
 
81
+               g_set_error (error,
 
82
+                            GS_PLUGIN_ERROR,
 
83
+                            GS_PLUGIN_ERROR_INVALID_FORMAT,
 
84
+                            "snapd returned status code %u: %s",
 
85
+                            status_code, reason_phrase);
 
86
+               return NULL;
 
87
+       }
 
88
+
 
89
+       parser = parse_result (response, response_type, error);
 
90
+       if (parser == NULL)
 
91
+               return NULL;
 
92
+       root = json_node_get_object (json_parser_get_root (parser));
 
93
+       result = json_object_get_object_member (root, "result");
 
94
+       if (result == NULL) {
 
95
+               g_set_error (error,
 
96
+                            GS_PLUGIN_ERROR,
 
97
+                            GS_PLUGIN_ERROR_INVALID_FORMAT,
 
98
+                            "snapd returned no system information");
 
99
+               return NULL;
 
100
+       }
 
101
+
 
102
+       return json_object_ref (result);
 
103
+}
 
104
+
 
105
 JsonObject *
 
106
 gs_snapd_list_one (const gchar *macaroon, gchar **discharges,
 
107
                   const gchar *name,
 
108
diff --git a/src/plugins/gs-snapd.h b/src/plugins/gs-snapd.h
 
109
index dc78db35..b0cf8341 100644
 
110
--- a/src/plugins/gs-snapd.h
 
111
+++ b/src/plugins/gs-snapd.h
 
112
@@ -29,6 +29,9 @@ typedef void (*GsSnapdProgressCallback) (JsonObject *object, gpointer user_data)
 
113
 
 
114
 gboolean gs_snapd_exists               (void);
 
115
 
 
116
+JsonObject *gs_snapd_get_system_info   (GCancellable   *cancellable,
 
117
+                                        GError         **error);
 
118
+
 
119
 JsonObject *gs_snapd_list_one          (const gchar    *macaroon,
 
120
                                         gchar          **discharges,
 
121
                                         const gchar    *name,
 
122
-- 
 
123
2.14.1
 
124