File gnome-shell-private-connection.patch of Package gnome-shell.705

From f9a23ba5908fb93d25ef702510ea182c220db8aa Mon Sep 17 00:00:00 2001
From: Giovanni Campagna <gcampagna@src.gnome.org>
Date: Thu, 31 Mar 2011 15:56:13 +0200
Subject: [PATCH] NetworkMenu: create private connections if the user is not
 authorized

Check polkit setting at startup and add, if needed, the "permissions"
setting to the connections we create, so that polkit authentication is
never needed. The connection is thus only available to other users
if the system administrator decides so.

https://bugzilla.gnome.org/show_bug.cgi?id=646187
---
 js/ui/status/network.js | 38 +++++++++++++++++++++++++++++++++-----
 1 file changed, 33 insertions(+), 5 deletions(-)

diff --git a/js/ui/status/network.js b/js/ui/status/network.js
index 0ff2037..7deb7f4 100644
--- a/js/ui/status/network.js
+++ b/js/ui/status/network.js
@@ -7,6 +7,7 @@ const Gtk = imports.gi.Gtk;
 const Lang = imports.lang;
 const NetworkManager = imports.gi.NetworkManager;
 const NMClient = imports.gi.NMClient;
+const Polkit = imports.gi.Polkit;
 const NMGtk = imports.gi.NMGtk;
 const Signals = imports.signals;
 const St = imports.gi.St;
@@ -506,10 +507,12 @@ const NMDeviceBluetooth = new Lang.Class({
     Extends: NMConnectionDevice,
     category: NMConnectionCategory.WWAN,
 
-    _init: function(client, device, settings) {
+
+    _init: function(client, device, settings, privateConnections) {
         this.parent(client, device, settings);
 
         this.item.menu.addMenuItem(createSettingsAction(_("Mobile Broadband Settings"), device));
+        this._privateConnections = privateConnections;
     },
 
     _autoConnect: function() {
@@ -520,6 +523,11 @@ const NMDeviceBluetooth = new Lang.Class({
         // that this phone supports PAN
 
         let connection = new NetworkManager.Connection();
+        if (this._privateConnections) {
+            let connectionSetting = new NetworkManager.SettingConnection();
+            connectionSetting.add_permission('user', GLib.get_user_name(), null);
+            connection.add_setting(connectionSetting);
+        }
         this._client.add_and_activate_connection(connection, this._device, null, null);
         return true;
     },
@@ -624,11 +632,12 @@ const NMWirelessDialog = new Lang.Class({
     Name: 'NMWirelessDialog',
     Extends: ModalDialog.ModalDialog,
 
-    _init: function(client, device, settings) {
+    _init: function(client, device, settings, privateConnections) {
         this.parent({ styleClass: 'nm-dialog' });
 
         this._client = client;
         this._device = device;
+	this._privateConnections = privateConnections;
 
         this._networks = [];
         this._buildLayout();
@@ -766,6 +775,11 @@ const NMWirelessDialog = new Lang.Class({
                             this._device.get_path(), accessPoints[0].dbus_path]);
             } else {
                 let connection = new NetworkManager.Connection();
+                if (this._privateConnections) {
+                    let connectionSetting = new NetworkManager.SettingConnection();
+                    connectionSetting.add_permission('user', GLib.get_user_name(), null);
+                    connection.add_setting(connectionSetting);
+                }
                 this._client.add_and_activate_connection(connection, this._device, accessPoints[0].dbus_path, null)
             }
         }
@@ -994,10 +1008,11 @@ const NMDeviceWireless = new Lang.Class({
     Name: 'NMDeviceWireless',
     category: NMConnectionCategory.WIRELESS,
 
-    _init: function(client, device, settings) {
+    _init: function(client, device, settings, privateConnections) {
         this._client = client;
         this._device = device;
         this._settings = settings;
+        this._privateConnections = privateConnections;
 
         this._description = '';
 
@@ -1065,7 +1080,7 @@ const NMDeviceWireless = new Lang.Class({
     },
 
     _showDialog: function() {
-        this._dialog = new NMWirelessDialog(this._client, this._device, this._settings);
+        this._dialog = new NMWirelessDialog(this._client, this._device, this._settings, this._privateConnections);
         this._dialog.connect('closed', Lang.bind(this, this._dialogClosed));
         this._dialog.open();
     },
@@ -1326,6 +1341,19 @@ const NMApplet = new Lang.Class({
         if (!this._client || !this._settings)
             return;
 
+        // Check if newly created connections should be private or not
+        this._privateConnections = true;
+        let authority = Polkit.Authority.get_sync(null);
+        let credential = new Gio.Credentials();
+        let subject = new Polkit.UnixProcess({ pid: credential.get_unix_pid(), uid: credential.get_unix_user() });
+        let authResult = authority.check_authorization_sync(subject,
+                                                            'org.freedesktop.NetworkManager.settings.modify.system',
+                                                            null /* details */,
+                                                            Polkit.CheckAuthorizationFlags.NONE,
+                                                            null /* cancellable */);
+        if (authResult)
+            this._privateConnections = !authResult.get_is_authorized();
+
         this._activeConnections = [ ];
         this._connections = [ ];
 
@@ -1441,7 +1469,7 @@ const NMApplet = new Lang.Class({
 
         let wrapperClass = this._dtypes[device.get_device_type()];
         if (wrapperClass) {
-            let wrapper = new wrapperClass(this._client, device, this._settings);
+            let wrapper = new wrapperClass(this._client, device, this._settings, this._privateConnections);
             device._delegate = wrapper;
             this._addDeviceWrapper(wrapper);
 
-- 
1.8.1.4

openSUSE Build Service is sponsored by