Implement support for wep-tx-keyidx in ifupdown system config plugin.
=== modified file 'ChangeLog' --- a/ChangeLog 2008-10-03 02:25:06 +0000 +++ b/ChangeLog 2008-10-03 21:51:57 +0000 @@ -1,8 +1,22 @@ +2008-10-02 Alexander Sack <[EMAIL PROTECTED]> + + Implement support for wep-tx-keyidx in ifupdown system + config plugin. + + * system-settings/plugins/ifupdown/parser.c + - (update_wireless_security_setting_from_if_block): introduce + free_type_mapping func table; rename a few local + variables to improve readability; add wpa security mapping + for wep-tx-keyidx property + - (string_to_gpointerint): new function used for the auto_type_mapping + of new wep-tx-keyidx property + - (slist_free_all): free func used for mapped slist types + 2008-10-03 Alexander Sack <[EMAIL PROTECTED]> Fix crash of nm-system-settings in add_default_dhcp_connection when wired device gets removed. * system-settings/src/main.c: - (add_default_dhcp_connection,device_removed_cb): passing the "key" instead of the value as second argument === modified file 'system-settings/plugins/ifupdown/parser.c' --- a/system-settings/plugins/ifupdown/parser.c 2008-10-02 13:48:41 +0000 +++ b/system-settings/plugins/ifupdown/parser.c 2008-10-04 00:54:28 +0000 @@ -18,16 +18,18 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * (C) Copyright 2008 Canonical Ltd. */ #include <string.h> #include <arpa/inet.h> +#include <stdlib.h> +#include <errno.h> #include <nm-connection.h> #include <NetworkManager.h> #include <nm-setting-connection.h> #include <nm-setting-ip4-config.h> #include <nm-setting-ppp.h> #include <nm-setting-wired.h> #include <nm-setting-wireless.h> @@ -202,16 +204,23 @@ static char *normalize_psk (gpointer val pbkdf2_sha1 (value, (char *) s_wireless->ssid->data, s_wireless->ssid->len, 4096, buf, WPA_PMK_LEN); normalized = utils_bin2hexstr ((const char *) buf, WPA_PMK_LEN, WPA_PMK_LEN * 2); g_free (buf); } return normalized; } static gpointer +string_to_gpointerint(const gchar* data) +{ + gint result = (gint) strtol (data, NULL, 10); + return GINT_TO_POINTER(result); +} + +static gpointer string_to_glist_of_strings(const gchar* data) { GSList *ret = NULL; gchar *string = (gchar*) data; while(string) { gchar* next = NULL; if( (next = strchr(string, ' ')) || (next = strchr(string, '\t')) || @@ -226,16 +235,24 @@ string_to_glist_of_strings(const gchar* } else { string = NULL; } } return ret; } static void +slist_free_all(gpointer slist) +{ + GSList *list = (GSList *) slist; + g_slist_foreach (list, (GFunc) g_free, NULL); + g_slist_free (list); +} + +static void update_wireless_security_setting_from_if_block(NMConnection *connection, if_block *block) { gint wpa_l= strlen("wpa-"); gint wireless_l= strlen("wireless-"); if_data *curr = block->info; const gchar* value = ifparser_getkey (block, "inet"); struct _Mapping mapping[] = { @@ -247,16 +264,17 @@ update_wireless_security_setting_from_if {"group", "group"}, {"pairwise", "pairwise"}, {"proto", "proto"}, {"pin", "pin"}, {"wep-key0", "wep-key0"}, {"wep-key1", "wep-key1"}, {"wep-key2", "wep-key2"}, {"wep-key3", "wep-key3"}, + {"wep-tx-keyidx", "wep-tx-keyidx"}, { NULL, NULL} }; struct _Mapping dupe_mapping[] = { {"psk", normalize_psk}, {"identity", normalize_dupe}, {"password", normalize_dupe}, {"key", normalize_dupe}, @@ -264,26 +282,34 @@ update_wireless_security_setting_from_if {"group", normalize_tolower}, {"pairwise", normalize_tolower}, {"proto", normalize_tolower}, {"pin", normalize_dupe}, {"wep-key0", normalize_dupe}, {"wep-key1", normalize_dupe}, {"wep-key2", normalize_dupe}, {"wep-key3", normalize_dupe}, + {"wep-tx-keyidx", normalize_dupe}, { NULL, NULL} }; struct _Mapping type_mapping[] = { {"group", string_to_glist_of_strings}, {"pairwise", string_to_glist_of_strings}, {"proto", string_to_glist_of_strings}, + {"wep-tx-keyidx", string_to_gpointerint}, { NULL, NULL} }; + struct _Mapping free_type_mapping[] = { + {"group", slist_free_all}, + {"pairwise", slist_free_all}, + {"proto", slist_free_all}, + { NULL, NULL} + }; NMSettingWirelessSecurity *wireless_security_setting; NMSettingWireless *s_wireless; gboolean security = FALSE; if(value && !strcmp("ppp", value)) { return; } @@ -296,49 +322,59 @@ update_wireless_security_setting_from_if wireless_security_setting = NM_SETTING_WIRELESS_SECURITY(nm_setting_wireless_security_new()); while(curr) { if(strlen(curr->key) > wireless_l && !strncmp("wireless-", curr->key, wireless_l)) { gchar *property_value = NULL; - gpointer property_value2 = NULL; + gpointer typed_property_value = NULL; const gchar* newkey = map_by_mapping(mapping, curr->key+wireless_l); - IfupdownStrDupeFunc func = map_by_mapping (dupe_mapping, curr->key+wireless_l); - IfupdownStrToTypeFunc func1 = map_by_mapping (type_mapping, curr->key+wireless_l); - if(!newkey || !func) { + IfupdownStrDupeFunc dupe_func = map_by_mapping (dupe_mapping, curr->key+wireless_l); + IfupdownStrToTypeFunc type_map_func = map_by_mapping (type_mapping, curr->key+wireless_l); + GFreeFunc free_func = map_by_mapping (free_type_mapping, curr->key+wireless_l); + if(!newkey || !dupe_func) { g_warning("no (wireless) mapping found for key: %s", curr->key); goto next; } - property_value = (*func) (curr->data, connection); + property_value = (*dupe_func) (curr->data, connection); PLUGIN_PRINT ("SCPlugin-Ifupdown", "setting wireless security key: %s=%s", newkey, property_value); - if(func1) - property_value2 = (*func1) (property_value); + + if (type_map_func) { + errno = 0; + typed_property_value = (*type_map_func) (property_value); + if(errno) + goto wireless_next; + } g_object_set(wireless_security_setting, - newkey, property_value2 ? property_value2 : property_value, + newkey, typed_property_value ? typed_property_value : property_value, NULL); security = TRUE; + + wireless_next: g_free(property_value); - if(property_value) - g_free(property_value2); + if (typed_property_value && free_func) + (*free_func) (typed_property_value); + } else if(strlen(curr->key) > wpa_l && !strncmp("wpa-", curr->key, wpa_l)) { gchar *property_value = NULL; - gpointer property_value2 = NULL; + gpointer typed_property_value = NULL; const gchar* newkey = map_by_mapping(mapping, curr->key+wpa_l); - IfupdownStrDupeFunc func = map_by_mapping (dupe_mapping, curr->key+wpa_l); - IfupdownStrToTypeFunc func1 = map_by_mapping (type_mapping, curr->key+wpa_l); - if(!newkey || !func) { + IfupdownStrDupeFunc dupe_func = map_by_mapping (dupe_mapping, curr->key+wpa_l); + IfupdownStrToTypeFunc type_map_func = map_by_mapping (type_mapping, curr->key+wpa_l); + GFreeFunc free_func = map_by_mapping (free_type_mapping, curr->key+wpa_l); + if(!newkey || !dupe_func) { goto next; } - property_value = (*func) (curr->data, connection); + property_value = (*dupe_func) (curr->data, connection); PLUGIN_PRINT ("SCPlugin-Ifupdown", "setting wpa security key: %s=%s", newkey, #ifdef DEBUG_SECRETS property_value #else // DEBUG_SECRETS !strcmp("key", newkey) || !strcmp("password", newkey) || !strcmp("pin", newkey) || @@ -347,24 +383,32 @@ update_wireless_security_setting_from_if !strcmp("wep-key1", newkey) || !strcmp("wep-key2", newkey) || !strcmp("wep-key3", newkey) || NULL ? "<omitted>" : property_value #endif // DEBUG_SECRETS ); - if(func1) - property_value2 = (*func1) (property_value); + if (type_map_func) { + errno = 0; + typed_property_value = (*type_map_func) (property_value); + if(errno) + goto wpa_next; + } g_object_set(wireless_security_setting, - newkey, property_value2 ? property_value2 : property_value, + newkey, typed_property_value ? typed_property_value : property_value, NULL); security = TRUE; + + wpa_next: g_free(property_value); + if (free_func && typed_property_value) + (*free_func) (typed_property_value); } next: curr = curr->next; } if(security) { nm_connection_add_setting(connection, NM_SETTING(wireless_security_setting)); - Alexander _______________________________________________ NetworkManager-list mailing list NetworkManager-list@gnome.org http://mail.gnome.org/mailman/listinfo/networkmanager-list