Esempio n. 1
0
gboolean
is_static_ip4 (const char *conn_name)
{
	const char *data = ifnet_get_data (conn_name, "config");
	const char *dhcp6;

	if (!data)
		return FALSE;
	if (!strcmp (data, "shared"))
		return FALSE;
	if (!strcmp (data, "autoip"))
		return FALSE;
	dhcp6 = strstr (data, "dhcp6");
	if (dhcp6) {
		gchar *dhcp4;

		if (strstr (data, "dhcp "))
			return FALSE;
		dhcp4 = strstr (data, "dhcp");
		if (!dhcp4)
			return TRUE;
		if (dhcp4[4] == '\0')
			return FALSE;
		return TRUE;
	}
	return strstr (data, "dhcp") == NULL ? TRUE : FALSE;
}
Esempio n. 2
0
ip_block *
convert_ip4_routes_block (const char *conn_name)
{
	gchar **ipset;
	guint length;
	guint i;
	gchar *ip;
	ip_block *start = NULL, *current = NULL, *iblock = NULL;

	g_return_val_if_fail (conn_name != NULL, NULL);

	ipset = split_routes (ifnet_get_data (conn_name, "routes"));
	length = ipset ? g_strv_length (ipset) : 0;
	for (i = 0; i < length; i++) {
		ip = ipset[i];
		if (find_default_gateway_str (ip) || strstr (ip, "::")
		    || !find_gateway_str (ip))
			continue;
		ip = strip_string (ip, '"');
		iblock = create_ip4_block (ip);
		if (iblock == NULL)
			continue;
		iblock->next_hop = get_ip4_gateway (ip);
		if (start == NULL)
			start = current = iblock;
		else {
			current->next = iblock;
			current = iblock;
		}
	}
	g_strfreev (ipset);
	return start;
}
gboolean
has_default_route (gchar * conn_name, gboolean (*check_fn) (gchar *))
{
	gchar *routes = NULL, *tmp, *end;

	g_return_val_if_fail (conn_name != NULL, FALSE);
	tmp = ifnet_get_data (conn_name, "routes");
	if (!tmp)
		return FALSE;
	routes = g_strdup (tmp);
	tmp = find_default_gateway_str (routes);
	if (!tmp) {
		goto error;
	}
	g_strstrip (tmp);
	if ((end = strstr (tmp, "\"")) != NULL)
		*end = '\0';
	if (check_fn (tmp)) {
		g_free (routes);
		return TRUE;
	}
      error:
	g_free (routes);
	return FALSE;
}
ip6_block *
convert_ip6_config_block (gchar * conn_name)
{
	gchar **ipset;
	guint length;
	guint i;
	gchar *ip;
	ip6_block *start = NULL, *current = NULL, *iblock = NULL;

	g_return_val_if_fail (conn_name != NULL, NULL);
	ipset = g_strsplit (ifnet_get_data (conn_name, "config"), "\" \"", 0);
	length = g_strv_length (ipset);
	for (i = 0; i < length; i++) {
		ip = ipset[i];
		ip = strip_string (ip, '"');
		iblock = create_ip6_block (ip);
		if (iblock == NULL)
			continue;
		if (start == NULL)
			start = current = iblock;
		else {
			current->next = iblock;
			current = iblock;
		}
	}
	g_strfreev (ipset);
	return start;
}
Esempio n. 5
0
void
set_ip6_dns_servers (NMSettingIPConfig *s_ip6, const char *conn_name)
{
	const char *dns_servers;
	gchar **server_list, *stripped;
	guint length, i;
	struct in6_addr tmp_ip6_addr;

	dns_servers = ifnet_get_data (conn_name, "dns_servers");
	if (!dns_servers)
		return;

	stripped = g_strdup (dns_servers);
	strip_string (stripped, '"');
	server_list = g_strsplit (stripped, " ", 0);
	g_free (stripped);

	length = g_strv_length (server_list);
	if (length)
		g_object_set (s_ip6, NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS,
			      TRUE, NULL);
	for (i = 0; i < length; i++) {
		g_strstrip (server_list[i]);
		if (server_list[i][0] == '\0')
			continue;
		if (!inet_pton (AF_INET6, server_list[i], &tmp_ip6_addr)) {
			if (is_ip6_address (server_list[i]))
				nm_log_warn (LOGD_SETTINGS, "ignored dns: %s\n", server_list[i]);
			continue;
		}
		if (!nm_setting_ip_config_add_dns (s_ip6, server_list[i]))
			nm_log_warn (LOGD_SETTINGS, "warning: duplicate DNS server %s", server_list[i]);
	}
	g_strfreev (server_list);
}
static void
check_unmanaged (gpointer key, gpointer data, gpointer user_data)
{
	GSList **list = (GSList **) user_data;
	gchar *conn_name = (gchar *) key;
	const char *unmanaged_spec;
	GSList *iter;

	if (is_managed (conn_name))
		return;
	PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Checking unmanaged: %s", conn_name);
	unmanaged_spec = ifnet_get_data (conn_name, "mac");
	if (!unmanaged_spec)
		return;

	/* Just return if the unmanaged spec is already in the list */
	for (iter = *list; iter; iter = g_slist_next (iter)) {
		if (!strcmp ((char *) iter->data, unmanaged_spec))
			return;
	}

	PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Add unmanaged: %s", unmanaged_spec);
	*list =
	    g_slist_prepend (*list, g_strdup_printf ("mac:%s", unmanaged_spec));
}
gboolean
is_static_ip6 (gchar * conn_name)
{
	gchar *data = ifnet_get_data (conn_name, "config");

	if (!data)
		return TRUE;
	return strstr (data, "dhcp6") == NULL ? TRUE : FALSE;
}
ip6_block *
convert_ip6_routes_block (gchar * conn_name)
{
	gchar **ipset;
	guint length;
	guint i;
	gchar *ip, *tmp_addr;
	gchar *routes;
	ip6_block *start = NULL, *current = NULL, *iblock = NULL;
	struct in6_addr *tmp_ip6_addr;

	g_return_val_if_fail (conn_name != NULL, NULL);
	routes = ifnet_get_data (conn_name, "routes");
	if (!routes)
		return NULL;
	ipset = g_strsplit (routes, "\" \"", 0);
	length = g_strv_length (ipset);
	for (i = 0; i < length; i++) {
		ip = ipset[i];
		ip = strip_string (ip, '"');
		if (ip[0] == '\0')
			continue;
		if ((tmp_addr = find_default_gateway_str (ip)) != NULL) {
			if (!is_ip6_address (tmp_addr))
				continue;
			else {
				tmp_ip6_addr = g_slice_new0 (struct in6_addr);

				if (inet_pton (AF_INET6, "::", tmp_ip6_addr)) {
					iblock = g_slice_new0 (ip6_block);
					iblock->ip = tmp_ip6_addr;
					iblock->prefix = 128;
				} else {
					g_slice_free (struct in6_addr,
						      tmp_ip6_addr);
					continue;
				}
			}
		} else
			iblock = create_ip6_block (ip);
		if (iblock == NULL)
			continue;
		iblock->next_hop = get_ip6_next_hop (ip);
		if (iblock->next_hop == NULL) {
			destroy_ip6_block (iblock);
			continue;
		}
		if (start == NULL)
			start = current = iblock;
		else {
			current->next = iblock;
			current = iblock;
		}
	}
Esempio n. 9
0
ip_block *
convert_ip4_config_block (const char *conn_name)
{
	gchar **ipset;
	guint length;
	guint i;
	gchar *ip;
	char *def_gateway = NULL;
	const char *routes;
	ip_block *start = NULL, *current = NULL, *iblock = NULL;

	g_return_val_if_fail (conn_name != NULL, NULL);

	ipset = split_addresses (ifnet_get_data (conn_name, "config"));
	length = ipset ? g_strv_length (ipset) : 0;

	routes = ifnet_get_data (conn_name, "routes");
	if (routes)
		def_gateway = get_ip4_gateway (strstr (routes, "default"));

	for (i = 0; i < length; i++) {
		ip = ipset[i];
		ip = strip_string (ip, '"');
		iblock = create_ip4_block (ip);
		if (iblock == NULL)
			continue;
		if (!iblock->next_hop && def_gateway != NULL)
			iblock->next_hop = g_strdup (def_gateway);
		if (start == NULL)
			start = current = iblock;
		else {
			current->next = iblock;
			current = iblock;
		}
	}
	g_strfreev (ipset);
	g_free (def_gateway);
	return start;
}
Esempio n. 10
0
gboolean
is_managed (const char *conn_name)
{
	gchar *config;

	g_return_val_if_fail (conn_name != NULL, FALSE);
	config = (gchar *) ifnet_get_data (conn_name, "managed");
	if (!config)
		return TRUE;
	if (strcmp (config, "false") == 0)
		return FALSE;
	return TRUE;
}
Esempio n. 11
0
static void
test_getdata (void)
{
	g_assert (ifnet_get_data ("eth1", "config") &&
	          strcmp (ifnet_get_data ("eth1", "config"), "( \"dhcp\" )") == 0);
	g_assert (ifnet_get_data ("ppp0", "username") &&
	          strcmp (ifnet_get_data ("ppp0", "username"), "user") == 0);
	g_assert (ifnet_get_data ("ppp0", "password") &&
	          strcmp (ifnet_get_data ("ppp0", "password"), "password") == 0);
	g_assert (ifnet_get_global_data ("modules") &&
	          strcmp ("!wpa_supplicant", ifnet_get_global_data ("modules")) == 0);
}
Esempio n. 12
0
ip_block *
convert_ip6_routes_block (const char *conn_name)
{
	gchar **ipset;
	guint length;
	guint i;
	gchar *ip, *tmp_addr;
	ip_block *start = NULL, *current = NULL, *iblock = NULL;

	g_return_val_if_fail (conn_name != NULL, NULL);
	ipset = split_routes (ifnet_get_data (conn_name, "routes"));
	length = ipset ? g_strv_length (ipset) : 0;
	for (i = 0; i < length; i++) {
		ip = ipset[i];
		ip = strip_string (ip, '"');
		if (ip[0] == '\0')
			continue;
		if ((tmp_addr = find_default_gateway_str (ip)) != NULL) {
			if (!is_ip6_address (tmp_addr))
				continue;
			else {
				iblock = g_slice_new0 (ip_block);
				iblock->ip = g_strdup ("::");
				iblock->prefix = 128;
			}
		} else
			iblock = create_ip_block (ip);
		if (iblock == NULL)
			continue;
		iblock->next_hop = get_ip6_next_hop (ip);
		if (iblock->next_hop == NULL) {
			destroy_ip_block (iblock);
			continue;
		}
		if (start == NULL)
			start = current = iblock;
		else {
			current->next = iblock;
			current = iblock;
		}
	}
	g_strfreev (ipset);
	return start;
}
Esempio n. 13
0
static void
test_getdata ()
{
	ASSERT (ifnet_get_data ("eth1", "config")
		&& strcmp (ifnet_get_data ("eth1", "config"), "dhcp") == 0,
		"get data", "config_eth1 is not correct");
	ASSERT (ifnet_get_data ("ppp0", "username")
		&& strcmp (ifnet_get_data ("ppp0", "username"), "user") == 0,
		"get data", "config_ppp0 username is not correctly read");
	ASSERT (ifnet_get_data ("ppp0", "password")
		&& strcmp (ifnet_get_data ("ppp0", "password"),
			   "password") == 0, "get data",
		"config_ppp0 password is not correctly read");
}
gboolean
has_ip6_address (gchar * conn_name)
{
	gchar **ipset;
	guint length;
	guint i;

	g_return_val_if_fail (conn_name != NULL, FALSE);
	ipset = g_strsplit (ifnet_get_data (conn_name, "config"), "\" \"", 0);
	length = g_strv_length (ipset);
	for (i = 0; i < length; i++) {
		if (!is_ip6_address (ipset[i]))
			continue;
		else {
			g_strfreev (ipset);
			return TRUE;
		}

	}
	g_strfreev (ipset);
	return FALSE;
}
Esempio n. 15
0
gboolean
has_default_route (const char *conn_name, gboolean (*check_fn) (const char *))
{
	char *routes = NULL, *end, *tmp;
	gboolean success = FALSE;

	g_return_val_if_fail (conn_name != NULL, FALSE);

	routes = g_strdup (ifnet_get_data (conn_name, "routes"));
	if (!routes)
		return FALSE;
	tmp = find_default_gateway_str (routes);
	if (tmp) {
		g_strstrip (tmp);
		if ((end = strstr (tmp, "\"")) != NULL)
			*end = '\0';
		if (check_fn (tmp))
			success = TRUE;
	}

	g_free (routes);
	return success;
}
Esempio n. 16
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);
}
ip_block *
convert_ip4_config_block (gchar * conn_name)
{
	gchar **ipset;
	guint length;
	guint i;
	gchar *ip;
	guint32 def_gateway;
	gchar *routes;
	gchar *pos;
	ip_block *start = NULL, *current = NULL, *iblock = NULL;
	gchar *pattern =
	    "((\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.)\\{(\\d{1,3})\\.\\.(\\d{1,3})\\}(/\\d{1,2}))";
	GRegex *regex = g_regex_new (pattern, 0, 0, NULL);

	g_return_val_if_fail (conn_name != NULL, NULL);
	ipset = g_strsplit (ifnet_get_data (conn_name, "config"), "\" \"", 0);
	length = g_strv_length (ipset);
	routes = ifnet_get_data (conn_name, "routes");
	if (routes)
		def_gateway = get_ip4_gateway (strstr (routes, "default"));
	else
		def_gateway = 0;
	for (i = 0; i < length; i++) {
		ip = ipset[i];
		ip = strip_string (ip, '"');
		//Handle ip like 192.168.4.{1..3}
		if ((pos = strchr (ip, '{')) != NULL) {
			gchar *ip_start, *ip_prefix;
			gchar *begin_str, *end_str;
			int begin, end, j;
			GMatchInfo *match_info;

			g_regex_match (regex, ip, 0, &match_info);
			if (!g_match_info_matches (match_info)) {
				g_match_info_free (match_info);
				continue;
			}
			begin_str = g_match_info_fetch (match_info, 3);
			end_str = g_match_info_fetch (match_info, 4);
			begin = atoi (begin_str);
			end = atoi (end_str);
			ip_start = g_match_info_fetch (match_info, 2);
			ip_prefix = g_match_info_fetch (match_info, 5);
			if (end < begin || begin < 1 || end > 254) {
				g_match_info_free (match_info);
				continue;
			}

			for (j = begin; j <= end; j++) {
				char suf[4];
				gchar *newip;

				sprintf (suf, "%d", j);
				newip =
				    g_strconcat (ip_start, suf, ip_prefix,
						 NULL);
				iblock = create_ip4_block (newip);
				if (iblock == NULL) {
					g_free (newip);
					continue;
				}
				if (!iblock->gateway && def_gateway != 0)
					iblock->gateway = def_gateway;
				if (start == NULL)
					start = current = iblock;
				else {
					current->next = iblock;
					current = iblock;
				}
				g_free (newip);
			}
			g_free (begin_str);
			g_free (end_str);
			g_free (ip_start);
			g_free (ip_prefix);
			g_match_info_free (match_info);
		} else {
			iblock = create_ip4_block (ip);
			if (iblock == NULL)
				continue;
			if (!iblock->gateway && def_gateway != 0)
				iblock->gateway = def_gateway;
			if (start == NULL)
				start = current = iblock;
			else {
				current->next = iblock;
				current = iblock;
			}
		}
	}
	g_strfreev (ipset);
	g_regex_unref (regex);
	return start;
}