/[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.1 - (show annotations) (download)
Mon Jan 24 07:31:49 2011 UTC (7 years, 8 months ago) by qiaomuf
Branch: MAIN
Revision bump wrt bug #350476

(Portage version: 2.1.9.25/cvs/Linux x86_64)

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

  ViewVC Help
Powered by ViewVC 1.1.20