/[gentoo-x86]/net-misc/networkmanager/files/networkmanager-0.8.2-shared-connection.patch
Gentoo

Contents of /net-misc/networkmanager/files/networkmanager-0.8.2-shared-connection.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download)
Tue Aug 23 23:17:09 2011 UTC (3 years, 3 months ago) by nirbheek
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +0 -0 lines
FILE REMOVED
Bump for the 0.9.0 release, go forth and test. Also, remove old ebuilds and unused patches.

(Portage version: 2.2.0_alpha51/cvs/Linux x86_64)

1 From d252fad6aa69aefa17b592111c2db23864f63907 Mon Sep 17 00:00:00 2001
2 From: Mu Qiao <qiaomuf@gentoo.org>
3 Date: Tue, 25 Jan 2011 10:31:53 +0000
4 Subject: [PATCH] shared-connection
5
6 Signed-off-by: Mu Qiao <qiaomuf@gentoo.org>
7 ---
8 system-settings/plugins/ifnet/connection_parser.c | 90 ++++++++++++++------
9 system-settings/plugins/ifnet/net_parser.c | 55 +++++++-----
10 system-settings/plugins/ifnet/net_parser.h | 4 +-
11 system-settings/plugins/ifnet/net_utils.c | 6 +-
12 .../plugins/ifnet/nm-ifnet-connection.c | 8 +-
13 system-settings/plugins/ifnet/wpa_parser.c | 21 +++--
14 6 files changed, 122 insertions(+), 62 deletions(-)
15
16 diff --git a/system-settings/plugins/ifnet/connection_parser.c b/system-settings/plugins/ifnet/connection_parser.c
17 index f9fae51..9b5ddc1 100644
18 --- a/system-settings/plugins/ifnet/connection_parser.c
19 +++ b/system-settings/plugins/ifnet/connection_parser.c
20 @@ -557,7 +557,7 @@ make_ip4_setting (NMConnection * connection, gchar * conn_name, GError ** error)
21
22 NMSettingIP4Config *ip4_setting =
23 NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ());
24 - gchar *value;
25 + gchar *value, *method = NULL;
26 gboolean is_static_block = is_static_ip4 (conn_name);
27 ip_block *iblock = NULL;
28
29 @@ -569,13 +569,41 @@ make_ip4_setting (NMConnection * connection, gchar * conn_name, GError ** error)
30 && strstr (value, "nogateway") ? TRUE : FALSE, NULL);
31
32 if (!is_static_block) {
33 - g_object_set (ip4_setting,
34 - NM_SETTING_IP4_CONFIG_METHOD,
35 - NM_SETTING_IP4_CONFIG_METHOD_AUTO,
36 - NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, FALSE, NULL);
37 - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Using DHCP for %s",
38 - conn_name);
39 - } else {
40 + method = ifnet_get_data (conn_name, "config");
41 + if (!method){
42 + g_set_error (error, ifnet_plugin_error_quark (), 0,
43 + "Unknown config for %s", conn_name);
44 + g_object_unref (ip4_setting);
45 + return;
46 + }
47 + if (!strcmp (method, "dhcp"))
48 + g_object_set (ip4_setting,
49 + NM_SETTING_IP4_CONFIG_METHOD,
50 + NM_SETTING_IP4_CONFIG_METHOD_AUTO,
51 + NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, FALSE, NULL);
52 + else if (!strcmp (method, "autoip")){
53 + g_object_set (ip4_setting,
54 + NM_SETTING_IP4_CONFIG_METHOD,
55 + NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL,
56 + NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, FALSE, NULL);
57 + nm_connection_add_setting (connection, NM_SETTING (ip4_setting));
58 + return;
59 + } else if (!strcmp (method, "shared")){
60 + g_object_set (ip4_setting,
61 + NM_SETTING_IP4_CONFIG_METHOD,
62 + NM_SETTING_IP4_CONFIG_METHOD_SHARED,
63 + NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, FALSE, NULL);
64 + nm_connection_add_setting (connection, NM_SETTING (ip4_setting));
65 + return;
66 + } else {
67 + g_set_error (error, ifnet_plugin_error_quark (), 0,
68 + "Unknown config for %s", conn_name);
69 + g_object_unref (ip4_setting);
70 + return;
71 + }
72 + PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Using %s method for %s",
73 + method, conn_name);
74 + }else {
75 iblock = convert_ip4_config_block (conn_name);
76 if (!iblock) {
77 g_set_error (error, ifnet_plugin_error_quark (), 0,
78 @@ -625,7 +653,7 @@ make_ip4_setting (NMConnection * connection, gchar * conn_name, GError ** error)
79 }
80
81 /* add dhcp hostname and client id */
82 - if (!is_static_block) {
83 + if (method && !strcmp (method, "dhcp")) {
84 gchar *dhcp_hostname, *client_id;
85
86 get_dhcp_hostname_and_client_id (&dhcp_hostname, &client_id);
87 @@ -712,7 +740,6 @@ make_ip4_setting (NMConnection * connection, gchar * conn_name, GError ** error)
88 iblock = iblock->next;
89 destroy_ip_block (current_iblock);
90 }
91 -
92 /* Finally add setting to connection */
93 nm_connection_add_setting (connection, NM_SETTING (ip4_setting));
94 }
95 @@ -1243,10 +1270,10 @@ parse_wpa_psk (gchar * psk, GError ** error)
96 * the passphrase contains spaces.
97 */
98
99 - p = psk;
100 - if (p[0] == '"' && psk[strlen (psk) - 1] == '"')
101 + p = g_strdup (psk);
102 + if (p[0] == '"' && p[strlen (p) - 1] == '"')
103 quoted = TRUE;
104 - if (!quoted && (strlen (psk) == 64)) {
105 + if (!quoted && (strlen (p) == 64)) {
106 /* Verify the hex PSK; 64 digits */
107 if (!is_hex (p)) {
108 g_set_error (error, ifnet_plugin_error_quark (),
109 @@ -1254,7 +1281,7 @@ parse_wpa_psk (gchar * psk, GError ** error)
110 "Invalid WPA_PSK (contains non-hexadecimal characters)");
111 goto out;
112 }
113 - hashed = g_strdup (psk);
114 + hashed = g_strdup (p);
115 } else {
116 strip_string (p, '"');
117
118 @@ -1276,6 +1303,7 @@ parse_wpa_psk (gchar * psk, GError ** error)
119 }
120
121 out:
122 + g_free (p);
123 return hashed;
124 }
125
126 @@ -2085,7 +2113,8 @@ write_wireless_security_setting (NMConnection * connection,
127 } else if (!strcmp (key_mgmt, "wpa-eap")) {
128 wpa_set_data (conn_name, "key_mgmt", "WPA-EAP");
129 wpa = TRUE;
130 - }
131 + } else
132 + PLUGIN_WARN (IFNET_PLUGIN_NAME, "Unknown key_mgmt: %s", key_mgmt);
133
134 if (auth_alg) {
135 if (!strcmp (auth_alg, "shared"))
136 @@ -2180,8 +2209,11 @@ write_wireless_security_setting (NMConnection * connection,
137 g_string_append (quoted, psk);
138 g_string_append_c (quoted, '"');
139 }
140 - wpa_set_data (conn_name, "psk",
141 - quoted ? quoted->str : (gchar *) psk);
142 + if (psk)
143 + wpa_set_data (conn_name, "psk",
144 + quoted ? quoted->str : (gchar *) psk);
145 + else
146 + PLUGIN_WARN (IFNET_PLUGIN_NAME, "Use WPA, but no psk received from NM");
147 if (quoted)
148 g_string_free (quoted, TRUE);
149 } else
150 @@ -2190,15 +2222,19 @@ write_wireless_security_setting (NMConnection * connection,
151 return TRUE;
152 }
153
154 -/* remove old ssid and add new one*/
155 +/* Only remove old config when ssid is changed.
156 + * See bug #350476.
157 + * */
158 static void
159 update_wireless_ssid (NMConnection * connection, gchar * conn_name,
160 gchar * ssid, gboolean hex)
161 {
162 - ifnet_delete_network (conn_name);
163 - ifnet_add_connection (ssid, "wireless");
164 + if (strcmp (conn_name, ssid)){
165 + ifnet_delete_network (conn_name);
166 + wpa_delete_security (conn_name);
167 + }
168
169 - wpa_delete_security (conn_name);
170 + ifnet_add_network (ssid, "wireless");
171 wpa_add_security (ssid);
172 }
173
174 @@ -2443,7 +2479,11 @@ write_ip4_setting (NMConnection * connection, gchar * conn_name,
175 }
176 ifnet_set_data (conn_name, "config", ips->str);
177 g_string_free (ips, TRUE);
178 - } else
179 + } else if (!strcmp (value, NM_SETTING_IP4_CONFIG_METHOD_SHARED))
180 + ifnet_set_data (conn_name, "config", "shared");
181 + else if (!strcmp (value, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL))
182 + ifnet_set_data (conn_name, "config", "autoip");
183 + else
184 ifnet_set_data (conn_name, "config", "dhcp");
185
186 /* DNS Servers */
187 @@ -2858,7 +2898,7 @@ get_wired_name ()
188 for (; i < 256; i++) {
189 gchar *conn_name = g_strdup_printf ("eth%d", i);
190
191 - if (!ifnet_has_connection (conn_name)) {
192 + if (!ifnet_has_network (conn_name)) {
193 return conn_name;
194 } else
195 g_free (conn_name);
196 @@ -2875,7 +2915,7 @@ get_ppp_name ()
197 for (; i < 256; i++) {
198 gchar *conn_name = g_strdup_printf ("ppp%d", i);
199
200 - if (!ifnet_has_connection (conn_name)) {
201 + if (!ifnet_has_network (conn_name)) {
202 return conn_name;
203 } else
204 g_free (conn_name);
205 @@ -2982,7 +3022,7 @@ ifnet_add_new_connection (NMConnection * connection,
206 goto out;
207 }
208
209 - if (ifnet_add_connection (new_name, new_type))
210 + if (ifnet_add_network (new_name, new_type))
211 success =
212 ifnet_update_parsers_by_connection (connection, new_name,
213 NULL, config_file,
214 diff --git a/system-settings/plugins/ifnet/net_parser.c b/system-settings/plugins/ifnet/net_parser.c
215 index b4a381d..de2db8a 100644
216 --- a/system-settings/plugins/ifnet/net_parser.c
217 +++ b/system-settings/plugins/ifnet/net_parser.c
218 @@ -37,6 +37,9 @@ static GList *functions_list;
219 /* Used to decide whether to write changes to file*/
220 static gboolean net_parser_data_changed = FALSE;
221
222 +static void
223 +destroy_connection_config (GHashTable * conn);
224 +
225 static GHashTable *
226 add_new_connection_config (const gchar * type, const gchar * name)
227 {
228 @@ -58,8 +61,10 @@ add_new_connection_config (const gchar * type, const gchar * name)
229 }
230
231 gboolean
232 -ifnet_add_connection (gchar * name, gchar * type)
233 +ifnet_add_network (gchar * name, gchar * type)
234 {
235 + if (ifnet_has_network (name))
236 + return TRUE;
237 if (add_new_connection_config (type, name)) {
238 PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Adding network for %s", name);
239 net_parser_data_changed = TRUE;
240 @@ -69,11 +74,27 @@ ifnet_add_connection (gchar * name, gchar * type)
241 }
242
243 gboolean
244 -ifnet_has_connection (gchar * conn_name)
245 +ifnet_has_network (gchar * conn_name)
246 {
247 return g_hash_table_lookup (conn_table, conn_name) != NULL;
248 }
249
250 +gboolean
251 +ifnet_delete_network (gchar * conn_name)
252 +{
253 + GHashTable *network = NULL;
254 +
255 + g_return_val_if_fail (conn_table != NULL && conn_name != NULL, FALSE);
256 + PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Deleting network for %s", conn_name);
257 + network = g_hash_table_lookup (conn_table, conn_name);
258 + if (!network)
259 + return FALSE;
260 + g_hash_table_remove (conn_table, conn_name);
261 + destroy_connection_config (network);
262 + net_parser_data_changed = TRUE;
263 + return TRUE;
264 +}
265 +
266 static GHashTable *
267 get_connection_config (gchar * name)
268 {
269 @@ -377,21 +398,27 @@ ifnet_set_data (gchar * conn_name, gchar * key, gchar * value)
270 {
271 gpointer orin_key = NULL, orin_value = NULL;
272 GHashTable *conn = g_hash_table_lookup (conn_table, conn_name);
273 + gchar *new_value = NULL;
274
275 if (!conn) {
276 PLUGIN_WARN (IFNET_PLUGIN_NAME,
277 "%s does not exsit!", conn_name);
278 return;
279 }
280 + if (value){
281 + new_value = g_strdup (value);
282 + strip_string (new_value, '"');
283 + }
284 /* Remove existing key value pair */
285 if (g_hash_table_lookup_extended (conn, key, &orin_key, &orin_value)) {
286 + if (new_value && !strcmp (orin_value, new_value))
287 + return;
288 g_hash_table_remove (conn, orin_key);
289 g_free (orin_key);
290 g_free (orin_value);
291 }
292 - if (value)
293 - g_hash_table_insert (conn, g_strdup (key),
294 - strip_string (g_strdup (value), '"'));
295 + if (new_value)
296 + g_hash_table_insert (conn, g_strdup (key), new_value);
297 net_parser_data_changed = TRUE;
298 }
299
300 @@ -467,7 +494,7 @@ ifnet_flush_to_file (gchar * config_file)
301 gboolean result = FALSE;
302
303 if (!net_parser_data_changed)
304 - return FALSE;
305 + return TRUE;
306 if (!conn_table || !global_settings_table)
307 return FALSE;
308
309 @@ -583,22 +610,6 @@ ifnet_flush_to_file (gchar * config_file)
310 return result;
311 }
312
313 -gboolean
314 -ifnet_delete_network (gchar * conn_name)
315 -{
316 - GHashTable *network = NULL;
317 -
318 - g_return_val_if_fail (conn_table != NULL && conn_name != NULL, FALSE);
319 - PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Deleting network for %s", conn_name);
320 - network = g_hash_table_lookup (conn_table, conn_name);
321 - if (!network)
322 - return FALSE;
323 - g_hash_table_remove (conn_table, conn_name);
324 - destroy_connection_config (network);
325 - net_parser_data_changed = TRUE;
326 - return TRUE;
327 -}
328 -
329 void
330 ifnet_destroy (void)
331 {
332 diff --git a/system-settings/plugins/ifnet/net_parser.h b/system-settings/plugins/ifnet/net_parser.h
333 index 73a44c8..b71a01f 100644
334 --- a/system-settings/plugins/ifnet/net_parser.h
335 +++ b/system-settings/plugins/ifnet/net_parser.h
336 @@ -36,11 +36,11 @@ GList *ifnet_get_connection_names (void);
337 gchar *ifnet_get_data (gchar * conn_name, const gchar * key);
338 gchar *ifnet_get_global_data (const gchar * key);
339 gchar *ifnet_get_global_setting (gchar * group, gchar * key);
340 -gboolean ifnet_has_connection (gchar * conn_name);
341 +gboolean ifnet_has_network (gchar * conn_name);
342
343 /* Writer functions */
344 gboolean ifnet_flush_to_file (gchar * config_file);
345 void ifnet_set_data (gchar * conn_name, gchar * key, gchar * value);
346 -gboolean ifnet_add_connection (gchar * name, gchar * type);
347 +gboolean ifnet_add_network (gchar * name, gchar * type);
348 gboolean ifnet_delete_network (gchar * conn_name);
349 #endif
350 diff --git a/system-settings/plugins/ifnet/net_utils.c b/system-settings/plugins/ifnet/net_utils.c
351 index 2dc253c..83b4325 100644
352 --- a/system-settings/plugins/ifnet/net_utils.c
353 +++ b/system-settings/plugins/ifnet/net_utils.c
354 @@ -278,6 +278,10 @@ is_static_ip4 (gchar * conn_name)
355
356 if (!data)
357 return FALSE;
358 + if (!strcmp (data, "shared"))
359 + return FALSE;
360 + if (!strcmp (data, "autoip"))
361 + return FALSE;
362 dhcp6 = strstr (data, "dhcp6");
363 if (dhcp6) {
364 gchar *dhcp4;
365 @@ -942,8 +946,8 @@ get_dhcp_hostname_and_client_id (char **hostname, char **client_id)
366 else if ((tmp = strstr (line, "send host-name")) != NULL) {
367 tmp += strlen ("send host-name");
368 g_strstrip (tmp);
369 - strip_string (tmp, '"');
370 strip_string (tmp, ';');
371 + strip_string (tmp, '"');
372 if (tmp[0] != '\0')
373 *hostname = g_strdup (tmp);
374 else
375 diff --git a/system-settings/plugins/ifnet/nm-ifnet-connection.c b/system-settings/plugins/ifnet/nm-ifnet-connection.c
376 index e47495c..ebe2581 100644
377 --- a/system-settings/plugins/ifnet/nm-ifnet-connection.c
378 +++ b/system-settings/plugins/ifnet/nm-ifnet-connection.c
379 @@ -71,12 +71,14 @@ nm_ifnet_connection_new (gchar * conn_name)
380 {
381 NMConnection *tmp;
382 GObject *object;
383 - GError **error = NULL;
384 + GError *error = NULL;
385
386 g_return_val_if_fail (conn_name != NULL, NULL);
387 - tmp = ifnet_update_connection_from_config_block (conn_name, error);
388 - if (!tmp)
389 + tmp = ifnet_update_connection_from_config_block (conn_name, &error);
390 + if (!tmp){
391 + g_error_free (error);
392 return NULL;
393 + }
394 object = (GObject *) g_object_new (NM_TYPE_IFNET_CONNECTION,
395 NM_IFNET_CONNECTION_CONN_NAME,
396 conn_name, NULL);
397 diff --git a/system-settings/plugins/ifnet/wpa_parser.c b/system-settings/plugins/ifnet/wpa_parser.c
398 index 5e94108..42c52c3 100644
399 --- a/system-settings/plugins/ifnet/wpa_parser.c
400 +++ b/system-settings/plugins/ifnet/wpa_parser.c
401 @@ -366,7 +366,7 @@ wpa_flush_to_file (gchar * config_file)
402 gboolean result = FALSE;
403
404 if (!wpa_parser_data_changed)
405 - return FALSE;
406 + return TRUE;
407 if (!wsec_table || !wsec_global_table)
408 return FALSE;
409
410 @@ -450,26 +450,29 @@ wpa_set_data (gchar * ssid, gchar * key, gchar * value)
411 {
412 gpointer orig_key = NULL, orig_value = NULL;
413 GHashTable *security = g_hash_table_lookup (wsec_table, ssid);
414 + gchar *new_value = NULL;
415
416 g_return_if_fail (security != NULL);
417
418 + if (value){
419 + new_value = g_strdup(value);
420 + if (strcmp (key, "ssid") != 0 && strcmp (key, "psk") != 0
421 + && !g_str_has_prefix (key, "wep_key"))
422 + strip_string (new_value, '"');
423 + }
424 /* Remove old key value pairs */
425 if (g_hash_table_lookup_extended
426 (security, key, &orig_key, &orig_value)) {
427 + if (new_value && !strcmp(orig_value, new_value))
428 + return;
429 g_hash_table_remove (security, orig_key);
430 g_free (orig_key);
431 g_free (orig_value);
432 }
433
434 /* Add new key value */
435 - if (value) {
436 - gchar *new_value = g_strdup (value);
437 -
438 - if (strcmp (key, "ssid") != 0 && strcmp (key, "psk") != 0
439 - && !g_str_has_prefix (key, "wep_key"))
440 - strip_string (new_value, '"');
441 + if (new_value)
442 g_hash_table_insert (security, g_strdup (key), new_value);
443 - }
444 wpa_parser_data_changed = TRUE;
445 }
446
447 @@ -483,7 +486,7 @@ gboolean
448 wpa_add_security (gchar * ssid)
449 {
450 if (wpa_has_security (ssid))
451 - return FALSE;
452 + return TRUE;
453 else {
454 GHashTable *security =
455 g_hash_table_new (g_str_hash, g_str_equal);
456 --
457 1.7.3.4

  ViewVC Help
Powered by ViewVC 1.1.20