2012-09-08 00:20:57 +02:00
|
|
|
From 53b3dc5944c595e143fb0fb848c566d6aecb4bb9 Mon Sep 17 00:00:00 2001
|
2012-06-29 10:51:24 +02:00
|
|
|
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
|
|
|
|
---
|
2012-09-08 00:20:57 +02:00
|
|
|
js/ui/status/network.js | 59 +++++++++++++++++++++++++++++++++--------------
|
|
|
|
1 file changed, 42 insertions(+), 17 deletions(-)
|
2012-06-29 10:51:24 +02:00
|
|
|
|
2012-09-21 21:21:31 +02:00
|
|
|
Index: gnome-shell-3.5.92/js/ui/status/network.js
|
2012-09-08 00:20:57 +02:00
|
|
|
===================================================================
|
2012-09-21 21:21:31 +02:00
|
|
|
--- gnome-shell-3.5.92.orig/js/ui/status/network.js
|
|
|
|
+++ gnome-shell-3.5.92/js/ui/status/network.js
|
2012-09-08 00:20:57 +02:00
|
|
|
@@ -5,8 +5,10 @@ const Gio = imports.gi.Gio;
|
|
|
|
const Lang = imports.lang;
|
2012-06-29 10:51:24 +02:00
|
|
|
const NetworkManager = imports.gi.NetworkManager;
|
|
|
|
const NMClient = imports.gi.NMClient;
|
|
|
|
+const Polkit = imports.gi.Polkit;
|
|
|
|
const Signals = imports.signals;
|
|
|
|
const St = imports.gi.St;
|
|
|
|
+const System = imports.system;
|
|
|
|
|
|
|
|
const Main = imports.ui.main;
|
|
|
|
const PanelMenu = imports.ui.panelMenu;
|
2012-09-08 00:20:57 +02:00
|
|
|
@@ -237,8 +239,9 @@ const NMDevice = new Lang.Class({
|
2012-06-29 10:51:24 +02:00
|
|
|
Name: 'NMDevice',
|
|
|
|
Abstract: true,
|
|
|
|
|
|
|
|
- _init: function(client, device, connections) {
|
|
|
|
+ _init: function(client, device, connections, privateConnections) {
|
|
|
|
this.device = device;
|
|
|
|
+
|
|
|
|
if (device) {
|
|
|
|
this.device._delegate = this;
|
|
|
|
this._stateChangedId = this.device.connect('state-changed', Lang.bind(this, this._deviceStateChanged));
|
2012-09-08 00:20:57 +02:00
|
|
|
@@ -247,6 +250,8 @@ const NMDevice = new Lang.Class({
|
2012-06-29 10:51:24 +02:00
|
|
|
|
|
|
|
// protected
|
|
|
|
this._client = client;
|
|
|
|
+ this._privateConnections = privateConnections;
|
|
|
|
+
|
|
|
|
this._connections = [ ];
|
|
|
|
for (let i = 0; i < connections.length; i++) {
|
2012-09-08 00:20:57 +02:00
|
|
|
if (!connections[i].get_uuid())
|
|
|
|
@@ -659,11 +664,11 @@ const NMDeviceWired = new Lang.Class({
|
2012-06-29 10:51:24 +02:00
|
|
|
Name: 'NMDeviceWired',
|
|
|
|
Extends: NMDevice,
|
|
|
|
|
|
|
|
- _init: function(client, device, connections) {
|
|
|
|
+ _init: function(client, device, connections, privateConnections) {
|
|
|
|
this._autoConnectionName = _("Auto Ethernet");
|
|
|
|
this.category = NMConnectionCategory.WIRED;
|
|
|
|
|
|
|
|
- this.parent(client, device, connections);
|
|
|
|
+ this.parent(client, device, connections, privateConnections);
|
|
|
|
},
|
|
|
|
|
|
|
|
_createSection: function() {
|
2012-09-08 00:20:57 +02:00
|
|
|
@@ -681,12 +686,15 @@ const NMDeviceWired = new Lang.Class({
|
2012-06-29 10:51:24 +02:00
|
|
|
let connection = new NetworkManager.Connection();
|
2012-09-08 00:20:57 +02:00
|
|
|
let uuid = NetworkManager.utils_uuid_generate();
|
2012-06-29 10:51:24 +02:00
|
|
|
connection.add_setting(new NetworkManager.SettingWired());
|
|
|
|
- connection.add_setting(new NetworkManager.SettingConnection({
|
|
|
|
+ let connectionSetting = new NetworkManager.SettingConnection({
|
2012-09-08 00:20:57 +02:00
|
|
|
uuid: uuid,
|
2012-06-29 10:51:24 +02:00
|
|
|
id: this._autoConnectionName,
|
|
|
|
type: NetworkManager.SETTING_WIRED_SETTING_NAME,
|
|
|
|
autoconnect: true
|
|
|
|
- }));
|
|
|
|
+ });
|
|
|
|
+ if (this._privateConnections)
|
|
|
|
+ connectionSetting.add_permission('user', GLib.get_user_name(), null);
|
|
|
|
+ connection.add_setting(connectionSetting);
|
|
|
|
return connection;
|
|
|
|
}
|
|
|
|
});
|
2012-09-08 00:20:57 +02:00
|
|
|
@@ -695,7 +703,7 @@ const NMDeviceModem = new Lang.Class({
|
2012-06-29 10:51:24 +02:00
|
|
|
Name: 'NMDeviceModem',
|
|
|
|
Extends: NMDevice,
|
|
|
|
|
|
|
|
- _init: function(client, device, connections) {
|
|
|
|
+ _init: function(client, device, connections, privateConnections) {
|
|
|
|
let is_wwan = false;
|
|
|
|
|
|
|
|
this._enabled = true;
|
2012-09-08 00:20:57 +02:00
|
|
|
@@ -742,7 +750,7 @@ const NMDeviceModem = new Lang.Class({
|
2012-06-29 10:51:24 +02:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
- this.parent(client, device, connections);
|
|
|
|
+ this.parent(client, device, connections, privateConnections);
|
|
|
|
},
|
|
|
|
|
|
|
|
setEnabled: function(enabled) {
|
2012-09-08 00:20:57 +02:00
|
|
|
@@ -815,25 +823,28 @@ const NMDeviceBluetooth = new Lang.Class
|
2012-06-29 10:51:24 +02:00
|
|
|
Name: 'NMDeviceBluetooth',
|
|
|
|
Extends: NMDevice,
|
|
|
|
|
|
|
|
- _init: function(client, device, connections) {
|
|
|
|
+ _init: function(client, device, connections, privateConnections) {
|
|
|
|
this._autoConnectionName = this._makeConnectionName(device);
|
|
|
|
device.connect('notify::name', Lang.bind(this, this._updateAutoConnectionName));
|
|
|
|
|
|
|
|
this.category = NMConnectionCategory.WWAN;
|
|
|
|
|
|
|
|
- this.parent(client, device, connections);
|
|
|
|
+ this.parent(client, device, connections, privateConnections);
|
|
|
|
},
|
|
|
|
|
|
|
|
_createAutomaticConnection: function() {
|
|
|
|
let connection = new NetworkManager.Connection;
|
2012-09-08 00:20:57 +02:00
|
|
|
let uuid = NetworkManager.utils_uuid_generate();
|
2012-06-29 10:51:24 +02:00
|
|
|
connection.add_setting(new NetworkManager.SettingBluetooth);
|
|
|
|
- connection.add_setting(new NetworkManager.SettingConnection({
|
|
|
|
+ let connectionSetting = new NetworkManager.SettingConnection({
|
2012-09-08 00:20:57 +02:00
|
|
|
uuid: uuid,
|
2012-06-29 10:51:24 +02:00
|
|
|
id: this._autoConnectionName,
|
|
|
|
type: NetworkManager.SETTING_BLUETOOTH_SETTING_NAME,
|
|
|
|
autoconnect: false
|
|
|
|
- }));
|
|
|
|
+ });
|
|
|
|
+ if (this._privateConnections)
|
|
|
|
+ connectionSetting.add_permission('user', GLib.get_user_name(), null);
|
|
|
|
+ connection.add_setting(connectionSetting);
|
|
|
|
return connection;
|
|
|
|
},
|
|
|
|
|
2012-09-08 00:20:57 +02:00
|
|
|
@@ -961,7 +972,7 @@ const NMDeviceWireless = new Lang.Class(
|
2012-06-29 10:51:24 +02:00
|
|
|
Name: 'NMDeviceWireless',
|
|
|
|
Extends: NMDevice,
|
|
|
|
|
|
|
|
- _init: function(client, device, connections) {
|
|
|
|
+ _init: function(client, device, connections, privateConnections) {
|
|
|
|
this.category = NMConnectionCategory.WIRELESS;
|
|
|
|
|
|
|
|
this._overflowItem = null;
|
2012-09-08 00:20:57 +02:00
|
|
|
@@ -1036,7 +1047,7 @@ const NMDeviceWireless = new Lang.Class(
|
2012-06-29 10:51:24 +02:00
|
|
|
this._apAddedId = device.connect('access-point-added', Lang.bind(this, this._accessPointAdded));
|
|
|
|
this._apRemovedId = device.connect('access-point-removed', Lang.bind(this, this._accessPointRemoved));
|
|
|
|
|
|
|
|
- this.parent(client, device, validConnections);
|
|
|
|
+ this.parent(client, device, validConnections, privateConnections);
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
2012-09-08 00:20:57 +02:00
|
|
|
@@ -1479,12 +1490,15 @@ const NMDeviceWireless = new Lang.Class(
|
2012-06-29 10:51:24 +02:00
|
|
|
|
|
|
|
let connection = new NetworkManager.Connection();
|
|
|
|
connection.add_setting(new NetworkManager.SettingWireless());
|
|
|
|
- connection.add_setting(new NetworkManager.SettingConnection({
|
|
|
|
+ let connectionSetting = new NetworkManager.SettingConnection({
|
|
|
|
id: name,
|
|
|
|
autoconnect: true, // NetworkManager will know to ignore this if appropriate
|
|
|
|
uuid: NetworkManager.utils_uuid_generate(),
|
|
|
|
type: NetworkManager.SETTING_WIRELESS_SETTING_NAME
|
|
|
|
- }));
|
|
|
|
+ });
|
|
|
|
+ if (this._privateConnections)
|
|
|
|
+ connectionSetting.add_permission('user', GLib.get_user_name(), null);
|
|
|
|
+ connection.add_setting(connectionSetting);
|
|
|
|
return connection;
|
|
|
|
},
|
|
|
|
|
2012-09-21 21:21:31 +02:00
|
|
|
@@ -1569,6 +1583,18 @@ const NMApplet = new Lang.Class({
|
|
|
|
|
2012-06-29 10:51:24 +02:00
|
|
|
this._client = NMClient.Client.new();
|
|
|
|
|
|
|
|
+ // Check if newly created connections should be private or not
|
|
|
|
+ this._privateConnections = true;
|
|
|
|
+ let authority = Polkit.Authority.get_sync(null);
|
|
|
|
+ let subject = new Polkit.UnixProcess({ pid: System.getpid(), uid: System.getuid() });
|
|
|
|
+ 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._statusSection = new PopupMenu.PopupMenuSection();
|
2012-09-21 21:21:31 +02:00
|
|
|
this._statusItem = new PopupMenu.PopupMenuItem('', { reactive: false });
|
2012-06-29 10:51:24 +02:00
|
|
|
this._statusSection.addMenuItem(this._statusItem);
|
2012-09-21 21:21:31 +02:00
|
|
|
@@ -1760,7 +1786,7 @@ const NMApplet = new Lang.Class({
|
2012-09-08 00:20:57 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
_makeWrapperDevice: function(wrapperClass, device) {
|
|
|
|
- let wrapper = new wrapperClass(this._client, device, this._connections);
|
|
|
|
+ let wrapper = new wrapperClass(this._client, device, this._connections, this._privateConnections);
|
|
|
|
|
|
|
|
wrapper._activationFailedId = wrapper.connect('activation-failed', Lang.bind(this, function(device, reason) {
|
|
|
|
// XXX: nm-applet has no special text depending on reason
|