static void
reload_connections (gpointer config)
{
	SCPluginIfnet *self = SC_PLUGIN_IFNET (config);
	SCPluginIfnetPrivate *priv = SC_PLUGIN_IFNET_GET_PRIVATE (self);
	GList *conn_names = NULL, *n_iter = NULL;

	/* save names for removing unused connections */
	GHashTable *new_conn_names = NULL;
	GHashTableIter iter;
	gpointer key;
	gpointer value;

	if (priv->unmanaged_well_known)
		return;

	if (!reload_parsers ())
		return;
	PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Loading connections");
	conn_names = ifnet_get_connection_names ();
	new_conn_names =
	    g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
	for (n_iter = conn_names; n_iter; n_iter = g_list_next (n_iter)) {
		NMIfnetConnection *exported;
		NMIfnetConnection *old;
		gchar *conn_name = g_strdup (n_iter->data);

		/* add the new connection */
		exported = nm_ifnet_connection_new (conn_name);
		if (!exported) {
			g_free (conn_name);
			continue;
		}
		g_signal_connect (G_OBJECT (exported), "ifnet_setup_monitors",
				  G_CALLBACK (setup_monitors), config);
		g_signal_connect (G_OBJECT (exported), "ifnet_cancel_monitors",
				  G_CALLBACK (cancel_monitors), config);
		old = g_hash_table_lookup (priv->config_connections, conn_name);
		if (old && exported) {
			gchar *auto_refresh =
			    ifnet_get_global_setting (IFNET_KEY_FILE_GROUP,
						      "auto_refresh");

			if (auto_refresh && is_true (auto_refresh)) {
				if (!nm_connection_compare (NM_CONNECTION (old),
							    NM_CONNECTION
							    (exported),
							    NM_SETTING_COMPARE_FLAG_EXACT))
				{
					PLUGIN_PRINT (IFNET_PLUGIN_NAME,
						      "Auto refreshing %s",
						      conn_name);
					g_signal_emit_by_name (old,
							       NM_SETTINGS_CONNECTION_INTERFACE_REMOVED);
					g_hash_table_remove
					    (priv->config_connections,
					     conn_name);
					g_hash_table_insert
					    (priv->config_connections,
					     g_strdup (conn_name), exported);
					if (is_managed (conn_name))
						g_signal_emit_by_name (self,
								       NM_SYSTEM_CONFIG_INTERFACE_CONNECTION_ADDED,
								       exported);
				}
			} else
				update_old_connection (conn_name, old,
						       exported, priv);
			g_signal_emit_by_name (self,
					       NM_SYSTEM_CONFIG_INTERFACE_UNMANAGED_SPECS_CHANGED);
		} else if (exported) {
			g_hash_table_insert (priv->config_connections,
					     g_strdup (conn_name), exported);
			if (is_managed (conn_name))
				g_signal_emit_by_name (self,
						       NM_SYSTEM_CONFIG_INTERFACE_CONNECTION_ADDED,
						       exported);
		}
		g_hash_table_insert (new_conn_names, conn_name, conn_name);
	}
	/* remove unused connections */
	g_hash_table_iter_init (&iter, priv->config_connections);
	while (g_hash_table_iter_next (&iter, &key, &value)) {
		if (!g_hash_table_lookup (new_conn_names, key)) {
			g_signal_emit_by_name (value,
					       NM_SETTINGS_CONNECTION_INTERFACE_REMOVED);
			g_hash_table_remove (priv->config_connections, key);
		}
	}
	g_hash_table_remove_all (new_conn_names);
	g_hash_table_destroy (new_conn_names);
	g_list_free (conn_names);
}
Beispiel #2
0
/* Reading wep security information from /etc/conf.d/net.
 * This should not be used in future, use wpa_supplicant instead. */
static void
add_keys_from_net ()
{
	GList *names = ifnet_get_connection_names ();
	GList *iter = names;
	gchar *wep_keys = "(\\[([1-4])\\]\\s+(s:\\w{5}|s:\\w{13}|"
	    "([\\da-fA-F]{4}\\-){2}[\\da-fA-F]{2}|"
	    "([\\da-fA-F]{4}\\-){6}[\\da-fA-F]{2})\\s+)";
	gchar *key_method =
	    "\\s+key\\s+\\[([1-4])\\]\\s+enc\\s+(open|restricted)";
	GRegex *regex_keys = g_regex_new (wep_keys, 0, 0, NULL);
	GRegex *regex_method = g_regex_new (key_method, 0, 0, NULL);
	GMatchInfo *keys_info;
	GMatchInfo *method_info;

	while (iter) {
		gchar *conn_name = iter->data;
		GHashTable *table;
		const char *key_str;

		if ((key_str = ifnet_get_data (conn_name, "key")) == NULL) {
			iter = g_list_next (iter);
			continue;
		}

		wpa_add_security (conn_name);
		table = _get_hash_table (conn_name);
		/* Give lowest priority */
		wpa_set_data (conn_name, "priority", "0");
		g_regex_match (regex_keys, key_str, 0, &keys_info);
		/* add wep keys */
		while (g_match_info_matches (keys_info)) {
			gchar *key_num = g_match_info_fetch (keys_info, 2);
			gchar *one_wep_key = g_match_info_fetch (keys_info, 3);

			add_one_wep_key (table, atoi (key_num), one_wep_key);
			g_free (key_num);
			g_free (one_wep_key);
			g_match_info_next (keys_info, NULL);
		}
		g_match_info_free (keys_info);

		g_regex_match (regex_method, key_str, 0, &method_info);
		/* set default key index and auth alg */
		if (g_match_info_matches (method_info)) {
			gchar *default_idx =
			    g_match_info_fetch (method_info, 1);
			gchar *method = g_match_info_fetch (method_info, 2);

			default_idx[0]--;
			g_hash_table_insert (table, g_strdup ("wep_tx_keyidx"),
					     default_idx);
			g_hash_table_insert (table, g_strdup ("auth_alg"),
					     g_ascii_strup (method, -1));
		}
		g_match_info_free (method_info);
		add_security (table);
		iter = g_list_next (iter);
	}
	g_list_free (names);
	g_regex_unref (regex_keys);
	g_regex_unref (regex_method);
}