[gnome-software] Never request auth for setting the proxy



commit 1973f332c0654bc8c3b0c580536dcf78dda88b9c
Author: Richard Hughes <richard hughsie com>
Date:   Tue Feb 23 12:50:02 2016 +0000

    Never request auth for setting the proxy
    
    Resolves: https://bugzilla.gnome.org/show_bug.cgi?id=751776

 src/Makefile.am                          |    2 ++
 src/gs-update-monitor.c                  |    9 +--------
 src/gs-utils.c                           |   26 ++++++++++++++++++++++++++
 src/gs-utils.h                           |    1 +
 src/plugins/gs-plugin-packagekit-proxy.c |   14 ++++++++++++++
 5 files changed, 44 insertions(+), 8 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 8ee862f..0e85fa7 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -96,6 +96,7 @@ gnome_software_cmd_SOURCES =                          \
 
 gnome_software_cmd_LDADD =                             \
        $(APPSTREAM_LIBS)                               \
+       $(POLKIT_LIBS)                                  \
        $(SOUP_LIBS)                                    \
        $(GLIB_LIBS)                                    \
        $(GTK_LIBS)
@@ -293,6 +294,7 @@ gs_self_test_SOURCES =                                              \
 
 gs_self_test_LDADD =                                           \
        $(APPSTREAM_LIBS)                                       \
+       $(POLKIT_LIBS)                                          \
        $(SOUP_LIBS)                                            \
        $(GLIB_LIBS)                                            \
        $(GTK_LIBS)
diff --git a/src/gs-update-monitor.c b/src/gs-update-monitor.c
index 14dee09..a37c13c 100644
--- a/src/gs-update-monitor.c
+++ b/src/gs-update-monitor.c
@@ -26,10 +26,6 @@
 #include <glib/gi18n.h>
 #include <gsettings-desktop-schemas/gdesktop-enums.h>
 
-#ifdef HAVE_POLKIT
-#include <polkit/polkit.h>
-#endif
-
 #include "gs-update-monitor.h"
 #include "gs-plugin-loader.h"
 #include "gs-utils.h"
@@ -757,11 +753,8 @@ GPermission *
 gs_update_monitor_permission_get (void)
 {
        static GPermission *permission = NULL;
-#ifdef HAVE_POLKIT
        if (permission == NULL)
-               permission = polkit_permission_new_sync ("org.freedesktop.packagekit.trigger-offline-update",
-                                                         NULL, NULL, NULL);
-#endif
+               permission = gs_utils_get_permission ("org.freedesktop.packagekit.trigger-offline-update");
        return permission;
 }
 
diff --git a/src/gs-utils.c b/src/gs-utils.c
index 5709f9f..9597e7f 100644
--- a/src/gs-utils.c
+++ b/src/gs-utils.c
@@ -25,6 +25,10 @@
 #include <gio/gdesktopappinfo.h>
 #include <errno.h>
 
+#ifdef HAVE_POLKIT
+#include <polkit/polkit.h>
+#endif
+
 #include "gs-app.h"
 #include "gs-utils.h"
 #include "gs-plugin.h"
@@ -501,4 +505,26 @@ gs_utils_get_user_hash (GError **error)
        return g_compute_checksum_for_string (G_CHECKSUM_SHA1, salted, -1);
 }
 
+/**
+ * gs_utils_get_permission:
+ **/
+GPermission *
+gs_utils_get_permission (const gchar *id)
+{
+#ifdef HAVE_POLKIT
+       g_autoptr(GPermission) permission = NULL;
+       g_autoptr(GError) error = NULL;
+
+       permission = polkit_permission_new_sync (id, NULL, NULL, &error);
+       if (permission == NULL) {
+               g_warning ("Failed to create permission %s: %s", id, error->message);
+               return NULL;
+       }
+       return g_steal_pointer (&permission);
+#else
+       g_debug ("no PolicyKit, so can't return GPermission for %s", id);
+       return NULL;
+#endif
+}
+
 /* vim: set noexpandtab: */
diff --git a/src/gs-utils.h b/src/gs-utils.h
index 54df901..2abdbf3 100644
--- a/src/gs-utils.h
+++ b/src/gs-utils.h
@@ -63,6 +63,7 @@ const gchar    *gs_user_agent                 (void);
 gchar          *gs_utils_get_cachedir          (const gchar    *kind,
                                                 GError         **error);
 gchar          *gs_utils_get_user_hash         (GError         **error);
+GPermission    *gs_utils_get_permission        (const gchar    *id);
 
 G_END_DECLS
 
diff --git a/src/plugins/gs-plugin-packagekit-proxy.c b/src/plugins/gs-plugin-packagekit-proxy.c
index a3fcbd1..8959b03 100644
--- a/src/plugins/gs-plugin-packagekit-proxy.c
+++ b/src/plugins/gs-plugin-packagekit-proxy.c
@@ -28,6 +28,7 @@
 #include <gsettings-desktop-schemas/gdesktop-enums.h>
 
 #include <gs-plugin.h>
+#include <gs-utils.h>
 
 /*
  * SECTION:
@@ -135,6 +136,19 @@ reload_proxy_settings (GsPlugin *plugin)
 {
        g_autofree gchar *proxy_http = NULL;
        g_autofree gchar *proxy_ftp = NULL;
+       g_autoptr(GPermission) permission = NULL;
+
+       /* only if we can achieve the action *without* an auth dialog */
+       permission = gs_utils_get_permission ("org.freedesktop.packagekit."
+                                             "system-network-proxy-configure");
+       if (permission == NULL) {
+               g_debug ("not setting proxy as no permission");
+               return;
+       }
+       if (!g_permission_get_allowed (permission)) {
+               g_debug ("not setting proxy as no auth requested");
+               return;
+       }
 
        proxy_http = get_proxy_http (plugin);
        proxy_ftp = get_proxy_ftp (plugin);


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