[gnome-control-center/gnome-3-16] network: Only share a new wifi connection if the user is allowed to



commit 7ef6adca9e68b206e19643ff0c59492f52bc4259
Author: Mathieu Bridon <bochecha daitauha fr>
Date:   Tue Jun 23 16:55:10 2015 +0200

    network: Only share a new wifi connection if the user is allowed to
    
    Making a new connection available to other users requires being an
    admin, or entering an admin password.
    
    If we enable that option by default for new connections, we effectively
    prevent non-admin users from connecting to new networks when they go to
    the coffee shop without their laptop admin.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=751378

 configure.ac                     |    3 ++-
 panels/network/net-device-wifi.c |   26 ++++++++++++++++++++++++--
 2 files changed, 26 insertions(+), 3 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 74672b7..933f5bc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -137,7 +137,8 @@ PKG_CHECK_MODULES(KEYBOARD_PANEL, $COMMON_MODULES
 PKG_CHECK_MODULES(MEDIA_PANEL, $COMMON_MODULES)
 PKG_CHECK_MODULES(MOUSE_PANEL, $COMMON_MODULES xi >= 1.2
                   gnome-settings-daemon >= $GSD_REQUIRED_VERSION x11)
-PKG_CHECK_MODULES(NETWORK_PANEL, $COMMON_MODULES gmodule-2.0)
+PKG_CHECK_MODULES(NETWORK_PANEL, $COMMON_MODULES gmodule-2.0
+                  polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION)
 PKG_CHECK_MODULES(NOTIFICATIONS_PANEL, $COMMON_MODULES)
 PKG_CHECK_MODULES(ONLINE_ACCOUNTS_PANEL, $COMMON_MODULES goa-1.0 goa-backend-1.0 >= $GOA_REQUIRED_VERSION)
 PKG_CHECK_MODULES(POWER_PANEL, $COMMON_MODULES upower-glib >= 0.99.0
diff --git a/panels/network/net-device-wifi.c b/panels/network/net-device-wifi.c
index 59aafd8..407ca0d 100644
--- a/panels/network/net-device-wifi.c
+++ b/panels/network/net-device-wifi.c
@@ -34,6 +34,7 @@
 #include <nm-setting-wireless-security.h>
 #include <nm-remote-connection.h>
 #include <nm-setting-wireless.h>
+#include <polkit/polkit.h>
 
 #include "shell/list-box-helper.h"
 #include "network-dialogs.h"
@@ -753,11 +754,32 @@ wireless_try_to_connect (NetDeviceWifi *device_wifi,
         g_debug ("no existing connection found for %s, creating", ssid_target);
 
         if (!is_8021x (device, ap_object_path)) {
+                GPermission *permission;
+                gboolean allowed_to_share = FALSE;
+                NMConnection *partial = NULL;
+
+                permission = polkit_permission_new_sync 
("org.freedesktop.NetworkManager.settings.modify.system",
+                                                         NULL, NULL, NULL);
+                if (permission) {
+                        allowed_to_share = g_permission_get_allowed (permission);
+                        g_object_unref (permission);
+                }
+
+                if (!allowed_to_share) {
+                        NMSettingConnection *s_con;
+
+                        s_con = (NMSettingConnection *)nm_setting_connection_new ();
+                        nm_setting_connection_add_permission (s_con, "user", g_get_user_name (), NULL);
+                        partial = nm_connection_new ();
+                        nm_connection_add_setting (partial, NM_SETTING (s_con));
+                }
+
                 g_debug ("no existing connection found for %s, creating and activating one", ssid_target);
-                nm_client_add_and_activate_connection (client,
-                                                       NULL,
+                nm_client_add_and_activate_connection (client, partial,
                                                        device, ap_object_path,
                                                        connection_add_activate_cb, device_wifi);
+
+                g_object_unref (partial);
         } else {
                 CcNetworkPanel *panel;
                 GVariantBuilder *builder;


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