summaryrefslogtreecommitdiff
path: root/debian/patches/Allow-to-create-connections-without-admin-privileges.patch
blob: 2e3f2fa5e9c1d2796f6730fe2a0d0a34814d41ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
From: Michael Biebl <biebl@debian.org>
Date: Tue, 18 Mar 2014 10:49:13 +0100
Subject: Allow to create connections without admin privileges
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit

Set passwords as agent-owned when they need to, to allow users without
root permissions to easily configure their connections.
The logic is:
- Bluetooth, CDMA and GSM connections: always user-owned
- WEP/WPA connections: system-owned if user has the permissions
  (with NM’s config, that is netdev or sudo membership), user-owned
  otherwise. The password is stored in the keyring for WPA, not for
  WEP.
- WiMax / Wired connections: always system-owned (with 802.1x
  passwords in the keyring).

Closes: #696256
---
 src/applet-device-wifi.c            | 25 +++++++++++++++++++++++++
 src/connection-editor/page-mobile.c | 10 ++++++++++
 src/connection-editor/page-vpn.c    |  9 +++++++++
 src/connection-editor/page-wifi.c   | 13 +++++++++++++
 src/libnm-gtk/nm-wifi-dialog.c      |  4 ++++
 src/mobile-helpers.c                |  3 +++
 src/utils/utils.c                   |  7 +++++++
 src/utils/utils.h                   |  3 +++
 src/wireless-security/ws-wep-key.c  |  7 +++++++
 src/wireless-security/ws-wpa-psk.c  |  5 +++++
 10 files changed, 86 insertions(+)

diff --git a/src/applet-device-wifi.c b/src/applet-device-wifi.c
index 9944fb4..1c287b0 100644
--- a/src/applet-device-wifi.c
+++ b/src/applet-device-wifi.c
@@ -526,6 +526,7 @@ _do_new_auto_connection (NMApplet *applet,
 	NMSettingWirelessSecurity *s_wsec = NULL;
 	NMSetting8021x *s_8021x = NULL;
 	GBytes *ssid;
+	NM80211ApFlags flags;
 	NM80211ApSecurityFlags wpa_flags, rsn_flags;
 	GtkWidget *dialog;
 	MoreInfo *more_info;
@@ -557,6 +558,7 @@ _do_new_auto_connection (NMApplet *applet,
 	/* If the AP is WPA[2]-Enterprise then we need to set up a minimal 802.1x
 	 * setting and ask the user for more information.
 	 */
+	flags = nm_access_point_get_flags (ap);
 	rsn_flags = nm_access_point_get_rsn_flags (ap);
 	wpa_flags = nm_access_point_get_wpa_flags (ap);
 	if (   (rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)
@@ -585,6 +587,29 @@ _do_new_auto_connection (NMApplet *applet,
 		nm_connection_add_setting (connection, NM_SETTING (s_8021x));
 	}
 
+	if (utils_default_to_private_connection (applet->nm_client)) {
+		if (!s_con) {
+			s_con = (NMSettingConnection *) nm_setting_connection_new ();
+			nm_connection_add_setting (connection, NM_SETTING (s_con));
+		}
+		nm_setting_connection_add_permission (s_con, "user", g_get_user_name (), NULL);
+
+		if ((rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_PSK) ||
+		    (wpa_flags & NM_802_11_AP_SEC_KEY_MGMT_PSK)) {
+			if (!s_wsec) {
+				s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
+				nm_connection_add_setting (connection, NM_SETTING (s_wsec));
+			}
+			g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS, NM_SETTING_SECRET_FLAG_AGENT_OWNED, NULL);
+		} else if (flags & NM_802_11_AP_FLAGS_PRIVACY) {
+			if (!s_wsec) {
+				s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
+				nm_connection_add_setting (connection, NM_SETTING (s_wsec));
+			}
+			g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS, NM_SETTING_SECRET_FLAG_AGENT_OWNED, NULL);
+		}
+	}
+
 	/* If it's an 802.1x connection, we need more information, so pop up the
 	 * Dialog Of Doom.
 	 */
diff --git a/src/connection-editor/page-mobile.c b/src/connection-editor/page-mobile.c
index 8a1aa64..44c0f81 100644
--- a/src/connection-editor/page-mobile.c
+++ b/src/connection-editor/page-mobile.c
@@ -442,6 +442,7 @@ new_connection_mobile_wizard_done (NMAMobileWizard *wizard,
 	NMConnection *connection = NULL;
 
 	if (!canceled && method) {
+		NMSettingConnection *s_con;
 		NMSetting *type_setting;
 		const char *ctype = NULL;
 		char *detail = NULL;
@@ -455,6 +456,7 @@ new_connection_mobile_wizard_done (NMAMobileWizard *wizard,
 			              NM_SETTING_GSM_NUMBER, "*99#",
 			              NM_SETTING_GSM_USERNAME, method->username,
 			              NM_SETTING_GSM_PASSWORD, method->password,
+			              NM_SETTING_GSM_PASSWORD_FLAGS, NM_SETTING_SECRET_FLAG_AGENT_OWNED,
 			              NM_SETTING_GSM_APN, method->gsm_apn,
 			              NULL);
 			break;
@@ -466,6 +468,7 @@ new_connection_mobile_wizard_done (NMAMobileWizard *wizard,
 			              NM_SETTING_CDMA_NUMBER, "#777",
 			              NM_SETTING_GSM_USERNAME, method->username,
 			              NM_SETTING_GSM_PASSWORD, method->password,
+			              NM_SETTING_GSM_PASSWORD_FLAGS, NM_SETTING_SECRET_FLAG_AGENT_OWNED,
 			              NULL);
 			break;
 		default:
@@ -480,6 +483,13 @@ new_connection_mobile_wizard_done (NMAMobileWizard *wizard,
 		connection = ce_page_new_connection (detail, ctype, FALSE, info->client, info->user_data);
 		g_free (detail);
 
+		s_con = nm_connection_get_setting_connection (connection);
+		if (!s_con) {
+			s_con = (NMSettingConnection *) nm_setting_connection_new ();
+			nm_connection_add_setting (connection, NM_SETTING (s_con));
+		}
+		nm_setting_connection_add_permission (s_con, "user", g_get_user_name (), NULL);
+
 		nm_connection_add_setting (connection, type_setting);
 		nm_connection_add_setting (connection, nm_setting_ppp_new ());
 	}
diff --git a/src/connection-editor/page-vpn.c b/src/connection-editor/page-vpn.c
index d07f491..0a4d538 100644
--- a/src/connection-editor/page-vpn.c
+++ b/src/connection-editor/page-vpn.c
@@ -277,6 +277,7 @@ vpn_connection_new (GtkWindow *parent,
                     gpointer user_data)
 {
 	NMConnection *connection;
+	NMSettingConnection *s_con;
 	NMSetting *s_vpn;
 
 	if (!detail) {
@@ -302,6 +303,14 @@ vpn_connection_new (GtkWindow *parent,
 	                                     FALSE,
 	                                     client,
 	                                     user_data);
+
+	s_con = nm_connection_get_setting_connection (connection);
+	if (!s_con) {
+		s_con = (NMSettingConnection *) nm_setting_connection_new ();
+		nm_connection_add_setting (connection, NM_SETTING (s_con));
+	}
+	nm_setting_connection_add_permission (s_con, "user", g_get_user_name (), NULL);
+
 	s_vpn = nm_setting_vpn_new ();
 	g_object_set (s_vpn, NM_SETTING_VPN_SERVICE_TYPE, detail, NULL);
 	nm_connection_add_setting (connection, s_vpn);
diff --git a/src/connection-editor/page-wifi.c b/src/connection-editor/page-wifi.c
index 8215cb3..394e977 100644
--- a/src/connection-editor/page-wifi.c
+++ b/src/connection-editor/page-wifi.c
@@ -26,6 +26,8 @@
 #include <math.h>
 
 #include "nm-connection-editor.h"
+#include "utils.h"
+
 #include "page-wifi.h"
 
 G_DEFINE_TYPE (CEPageWifi, ce_page_wifi, CE_TYPE_PAGE)
@@ -621,6 +623,17 @@ wifi_connection_new (GtkWindow *parent,
 	                                     TRUE,
 	                                     client,
 	                                     user_data);
+
+	if (utils_default_to_private_connection (client)) {
+		NMSettingConnection *s_con;
+		s_con = nm_connection_get_setting_connection (connection);
+		if (!s_con) {
+			s_con = (NMSettingConnection *) nm_setting_connection_new ();
+			nm_connection_add_setting (connection, NM_SETTING (s_con));
+		}
+		nm_setting_connection_add_permission (s_con, "user", g_get_user_name (), NULL);
+	}
+
 	s_wifi = nm_setting_wireless_new ();
 	g_object_set (s_wifi, NM_SETTING_WIRELESS_MODE, "infrastructure", NULL);
 	nm_connection_add_setting (connection, s_wifi);
diff --git a/src/libnm-gtk/nm-wifi-dialog.c b/src/libnm-gtk/nm-wifi-dialog.c
index 1bf1bf4..7c29a5b 100644
--- a/src/libnm-gtk/nm-wifi-dialog.c
+++ b/src/libnm-gtk/nm-wifi-dialog.c
@@ -36,6 +36,7 @@
 #include "wireless-security.h"
 #include "nm-ui-utils.h"
 #include "eap-method.h"
+#include "utils.h"
 
 G_DEFINE_TYPE (NMAWifiDialog, nma_wifi_dialog, GTK_TYPE_DIALOG)
 
@@ -1229,6 +1230,9 @@ nma_wifi_dialog_get_connection (NMAWifiDialog *self,
 			      NM_SETTING_CONNECTION_UUID, uuid,
 			      NULL);
 		g_free (uuid);
+		if (utils_default_to_private_connection (priv->client)) {
+			nm_setting_connection_add_permission (s_con, "user", g_get_user_name (), NULL);
+		}
 		nm_connection_add_setting (connection, (NMSetting *) s_con);
 
 		s_wireless = (NMSettingWireless *) nm_setting_wireless_new ();
diff --git a/src/mobile-helpers.c b/src/mobile-helpers.c
index 406e3e0..751bea1 100644
--- a/src/mobile-helpers.c
+++ b/src/mobile-helpers.c
@@ -183,6 +183,7 @@ mobile_wizard_done (NMAMobileWizard *wizard,
 			              NM_SETTING_CDMA_NUMBER, "#777",
 			              NM_SETTING_CDMA_USERNAME, method->username,
 			              NM_SETTING_CDMA_PASSWORD, method->password,
+			              NM_SETTING_CDMA_PASSWORD_FLAGS, NM_SETTING_SECRET_FLAG_AGENT_OWNED,
 			              NULL);
 			nm_connection_add_setting (connection, setting);
 		} else if (method->devtype == NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) {
@@ -193,6 +194,7 @@ mobile_wizard_done (NMAMobileWizard *wizard,
 			              NM_SETTING_GSM_USERNAME, method->username,
 			              NM_SETTING_GSM_PASSWORD, method->password,
 			              NM_SETTING_GSM_APN, method->gsm_apn,
+			              NM_SETTING_GSM_PASSWORD_FLAGS, NM_SETTING_SECRET_FLAG_AGENT_OWNED,
 			              NULL);
 			nm_connection_add_setting (connection, setting);
 		} else
@@ -223,6 +225,7 @@ mobile_wizard_done (NMAMobileWizard *wizard,
 		                                      "user", g_get_user_name (), NULL);
 		g_free (uuid);
 		g_free (id);
+		nm_setting_connection_add_permission ((NMSettingConnection *) setting, "user", g_get_user_name (), NULL);
 		nm_connection_add_setting (connection, setting);
 	}
 
diff --git a/src/utils/utils.c b/src/utils/utils.c
index fd573cc..172d3f8 100644
--- a/src/utils/utils.c
+++ b/src/utils/utils.c
@@ -370,3 +370,10 @@ utils_fake_return_key (GdkEventKey *event)
 	g_free (keys);
 }
 
+gboolean
+utils_default_to_private_connection (NMClient *client)
+{
+	NMClientPermissionResult perms;
+	perms = nm_client_get_permission_result (client, NM_CLIENT_PERMISSION_SETTINGS_MODIFY_SYSTEM);
+	return (perms != NM_CLIENT_PERMISSION_RESULT_YES);
+}
diff --git a/src/utils/utils.h b/src/utils/utils.h
index 908741c..64a53ea 100644
--- a/src/utils/utils.h
+++ b/src/utils/utils.h
@@ -34,6 +34,7 @@
 #include <nm-connection.h>
 #include <nm-device.h>
 #include <nm-access-point.h>
+#include <nm-client.h>
 #else
 #error neither LIBNM_BUILD nor LIBNM_GLIB_BUILD defined
 #endif
@@ -65,6 +66,8 @@ void utils_show_error_dialog (const char *title,
                               gboolean modal,
                               GtkWindow *parent);
 
+gboolean utils_default_to_private_connection (NMClient *client);
+
 #define NMA_ERROR (g_quark_from_static_string ("nma-error-quark"))
 
 typedef enum  {
diff --git a/src/wireless-security/ws-wep-key.c b/src/wireless-security/ws-wep-key.c
index 3628d67..18d9300 100644
--- a/src/wireless-security/ws-wep-key.c
+++ b/src/wireless-security/ws-wep-key.c
@@ -157,6 +157,7 @@ static void
 fill_connection (WirelessSecurity *parent, NMConnection *connection)
 {
 	WirelessSecurityWEPKey *sec = (WirelessSecurityWEPKey *) parent;
+	NMSettingConnection *s_con;
 	NMSettingWirelessSecurity *s_wsec;
 	NMSettingSecretFlags secret_flags;
 	GtkWidget *widget, *passwd_entry;
@@ -183,6 +184,12 @@ fill_connection (WirelessSecurity *parent, NMConnection *connection)
 	              NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, sec->type,
 	              NULL);
 
+	s_con = nm_connection_get_setting_connection (connection);
+
+	/* If the connection is user-owned, mark the secrets as agent-owned */
+	if (s_con && nm_setting_connection_get_num_permissions (s_con))
+		g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS, NM_SETTING_SECRET_FLAG_AGENT_OWNED, NULL);
+
 	for (i = 0; i < 4; i++) {
 		if (strlen (sec->keys[i]))
 			nm_setting_wireless_security_set_wep_key (s_wsec, i, sec->keys[i]);
diff --git a/src/wireless-security/ws-wpa-psk.c b/src/wireless-security/ws-wpa-psk.c
index aec5563..6bdb852 100644
--- a/src/wireless-security/ws-wpa-psk.c
+++ b/src/wireless-security/ws-wpa-psk.c
@@ -103,12 +103,14 @@ fill_connection (WirelessSecurity *parent, NMConnection *connection)
 	WirelessSecurityWPAPSK *wpa_psk = (WirelessSecurityWPAPSK *) parent;
 	GtkWidget *widget, *passwd_entry;
 	const char *key;
+	NMSettingConnection *s_con;
 	NMSettingWireless *s_wireless;
 	NMSettingWirelessSecurity *s_wireless_sec;
 	NMSettingSecretFlags secret_flags;
 	const char *mode;
 	gboolean is_adhoc = FALSE;
 
+	s_con = nm_connection_get_setting_connection (connection);
 	s_wireless = nm_connection_get_setting_wireless (connection);
 	g_assert (s_wireless);
 
@@ -124,6 +126,9 @@ fill_connection (WirelessSecurity *parent, NMConnection *connection)
 	passwd_entry = widget;
 	key = gtk_entry_get_text (GTK_ENTRY (widget));
 	g_object_set (s_wireless_sec, NM_SETTING_WIRELESS_SECURITY_PSK, key, NULL);
+	/* If the connection is user-owned, mark the secrets as agent-owned */
+	if (s_con && nm_setting_connection_get_num_permissions (s_con))
+		g_object_set (s_wireless_sec, NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS, NM_SETTING_SECRET_FLAG_AGENT_OWNED, NULL);
 
 	/* Save PSK_FLAGS to the connection */
 	secret_flags = nma_utils_menu_to_secret_flags (passwd_entry);