static GHashTable *
add_security (GHashTable *security)
{
	GHashTable *oldsecurity;
	const char *ssid, *value;
	char *ssid_key;
	gboolean is_hex_ssid;

	/* Every security information should have a ssid */
	ssid = g_hash_table_lookup (security, "ssid");
	if (!ssid) {
		destroy_security (security);
		return NULL;
	}

	/* Hex format begins with " */
	is_hex_ssid = (ssid[0] != '"');
	if ((value = g_hash_table_lookup (security, "disabled")) != NULL) {
		if (strcmp (value, "1") == 0) {
			destroy_security (security);
			return NULL;
		}
	}

	/* Default priority is 1 */
	if (g_hash_table_lookup (security, "priority") == NULL)
		g_hash_table_insert (security, g_strdup ("priority"),
				     g_strdup ("1"));

	oldsecurity = g_hash_table_lookup (wsec_table, ssid);
	/* Security with lower priority will be ignored */
	if (oldsecurity != NULL) {
		if (wpa_get_long (oldsecurity, "priority") >=
		    wpa_get_long (security, "priority")) {
			destroy_security (security);
			return NULL;
		} else {
			g_hash_table_remove (wsec_table, ssid);
			destroy_security (oldsecurity);
		}
	}

	/* format ssid */
	ssid_key =
	    is_hex_ssid ? g_strdup_printf ("0x%s",
					   ssid) :
	    strip_string (g_strdup (ssid), '"');
	g_hash_table_insert (wsec_table, ssid_key, security);
	return security;
}
Пример #2
0
void
wpa_parser_destroy (void)
{
	GHashTableIter iter;
	gpointer key;
	gpointer value;

	/* Destroy security */
	if (wsec_table) {
		g_hash_table_iter_init (&iter, wsec_table);
		while (g_hash_table_iter_next (&iter, &key, &value)) {
			destroy_security ((GHashTable *) value);
			g_free (key);
		}

		g_hash_table_destroy (wsec_table);
		wsec_table = NULL;
	}

	/* Destroy global data */
	if (wsec_global_table) {
		g_hash_table_iter_init (&iter, wsec_global_table);
		while (g_hash_table_iter_next (&iter, &key, &value)) {
			g_free (key);
			g_free (value);
		}

		g_hash_table_destroy (wsec_global_table);
		wsec_global_table = NULL;
	}
}
Пример #3
0
gboolean
wpa_delete_security (const char *ssid)
{
	gpointer old_key, old_value;

	g_return_val_if_fail (wsec_table != NULL && ssid != NULL, FALSE);
	nm_log_info (LOGD_SETTINGS, "Deleting security for %s", ssid);
	if (!g_hash_table_lookup_extended
	    (wsec_table, ssid, &old_key, &old_value))
		return FALSE;
	g_hash_table_remove (wsec_table, old_key);
	g_free (old_key);
	destroy_security ((GHashTable *) old_value);
	wpa_parser_data_changed = TRUE;
	return TRUE;

}