Esempio n. 1
0
/*
 * Once the timeserver list (ts_list) is created, we start querying the
 * servers one by one. If resolving fails on one of them, we move to the
 * next one. The user can enter either an IP address or a URL for the
 * timeserver. We only resolve the urls. Once we have a IP for the NTP
 * server, we start querying it for time corrections.
 */
void __connman_timeserver_sync_next()
{
	if (ts_current) {
		g_free(ts_current);
		ts_current = NULL;
	}

	__connman_ntp_stop();

	/* Get the 1st server in the list */
	if (!ts_list)
		return;

	ts_current = ts_list->data;

	ts_list = g_slist_delete_link(ts_list, ts_list);

	/* if its a IP , directly query it. */
	if (connman_inet_check_ipaddress(ts_current) > 0) {
		DBG("Using timeserver %s", ts_current);

		__connman_ntp_start(ts_current);

		return;
	}

	DBG("Resolving server %s", ts_current);

	resolv_id = g_resolv_lookup_hostname(resolv, ts_current,
						resolv_result, NULL);

	return;
}
Esempio n. 2
0
static void wpad_result(GResolvResultStatus status,
					char **results, gpointer user_data)
{
	struct connman_wpad *wpad = user_data;
	const char *ptr;
	char *hostname;

	DBG("status %d", status);

	if (status == G_RESOLV_RESULT_STATUS_SUCCESS) {
		char *url;

		if (!results || g_strv_length(results) == 0)
			goto failed;

		url = g_strdup_printf("http://%s/wpad.dat", wpad->hostname);

		__connman_service_set_proxy_autoconfig(wpad->service, url);

		wpad->addrlist = g_strdupv(results);
		if (wpad->addrlist)
			download_pac(wpad, "wpad.dat");

		g_free(url);

		__connman_wispr_start(wpad->service,
					CONNMAN_IPCONFIG_TYPE_IPV4);

		return;
	}

	hostname = wpad->hostname;

	if (strlen(hostname) < 6)
		goto failed;

	ptr = strchr(hostname + 5, '.');
	if (!ptr || strlen(ptr) < 2)
		goto failed;

	if (!strchr(ptr + 1, '.'))
		goto failed;

	wpad->hostname = g_strdup_printf("wpad.%s", ptr + 1);
	g_free(hostname);

	DBG("hostname %s", wpad->hostname);

	g_resolv_lookup_hostname(wpad->resolv, wpad->hostname,
							wpad_result, wpad);

	return;

failed:
	connman_service_set_proxy_method(wpad->service,
				CONNMAN_SERVICE_PROXY_METHOD_DIRECT);

	__connman_wispr_start(wpad->service,
					CONNMAN_IPCONFIG_TYPE_IPV4);
}
Esempio n. 3
0
static void provider_resolv_host_addr(struct connman_provider *provider)
{
	if (provider->host == NULL)
		return;

	if (connman_inet_check_ipaddress(provider->host) > 0)
		return;

	if (provider->host_ip != NULL)
		return;

	/*
	 * If the hostname is not numeric, try to resolv it. We do not wait
	 * the result as it might take some time. We will get the result
	 * before VPN will feed routes to us because VPN client will need
	 * the IP address also before VPN connection can be established.
	 */
	provider->resolv = g_resolv_new(0);
	if (provider->resolv == NULL) {
		DBG("Cannot resolv %s", provider->host);
		return;
	}

	DBG("Trying to resolv %s", provider->host);

	connman_provider_ref(provider);

	g_resolv_lookup_hostname(provider->resolv, provider->host,
				resolv_result, provider);
}
Esempio n. 4
0
int __connman_wpad_start(struct connman_service *service)
{
	struct connman_wpad *wpad;
	const char *domainname;
	char **nameservers;
	int index;
	int i;

	DBG("service %p", service);

	if (!wpad_list)
		return -EINVAL;

	index = __connman_service_get_index(service);
	if (index < 0)
		return -EINVAL;

	domainname = connman_service_get_domainname(service);
	if (!domainname)
		return -EINVAL;

	nameservers = connman_service_get_nameservers(service);
	if (!nameservers)
		return -EINVAL;

	wpad = g_try_new0(struct connman_wpad, 1);
	if (!wpad) {
		g_strfreev(nameservers);
		return -ENOMEM;
	}

	wpad->service = service;
	wpad->resolv = g_resolv_new(index);
	if (!wpad->resolv) {
		g_strfreev(nameservers);
		g_free(wpad);
		return -ENOMEM;
	}

	if (getenv("CONNMAN_RESOLV_DEBUG"))
		g_resolv_set_debug(wpad->resolv, resolv_debug, "RESOLV");

	for (i = 0; nameservers[i]; i++)
		g_resolv_add_nameserver(wpad->resolv, nameservers[i], 53, 0);

	g_strfreev(nameservers);

	wpad->hostname = g_strdup_printf("wpad.%s", domainname);

	DBG("hostname %s", wpad->hostname);

	g_resolv_lookup_hostname(wpad->resolv, wpad->hostname,
							wpad_result, wpad);

	connman_service_ref(service);
	g_hash_table_replace(wpad_list, GINT_TO_POINTER(index), wpad);

	return 0;
}
Esempio n. 5
0
static void resolv_host_addr(struct connection_data *data)
{
	if (data->host == NULL)
		return;

	if (connman_inet_check_ipaddress(data->host) > 0)
		return;

	if (data->host_ip != NULL)
		return;

	data->resolv = g_resolv_new(0);
	if (data->resolv == NULL) {
		DBG("Cannot resolv %s", data->host);
		return;
	}

	DBG("Trying to resolv %s", data->host);

	data->resolv_id = g_resolv_lookup_hostname(data->resolv, data->host,
						resolv_result, data);
}
Esempio n. 6
0
static guint do_request(GWeb *web, const char *url,
				const char *type, GWebInputFunc input,
				int fd, gsize length, GWebResultFunc func,
				GWebRouteFunc route, gpointer user_data)
{
	struct web_session *session;

	if (web == NULL || url == NULL)
		return 0;

	debug(web, "request %s", url);

	session = g_try_new0(struct web_session, 1);
	if (session == NULL)
		return 0;

	if (parse_url(session, url, web->proxy) < 0) {
		free_session(session);
		return 0;
	}

	debug(web, "address %s", session->address);
	debug(web, "port %u", session->port);
	debug(web, "host %s", session->host);
	debug(web, "flags %lu", session->flags);
	debug(web, "request %s", session->request);

	if (type != NULL) {
		session->content_type = g_strdup(type);

		debug(web, "content-type %s", session->content_type);
	}

	session->web = web;

	session->result_func = func;
	session->route_func = route;
	session->input_func = input;
	session->fd = fd;
	session->length = length;
	session->offset = 0;
	session->user_data = user_data;

	session->receive_buffer = g_try_malloc(DEFAULT_BUFFER_SIZE);
	if (session->receive_buffer == NULL) {
		free_session(session);
		return 0;
	}

	session->result.headers = g_hash_table_new_full(g_str_hash, g_str_equal,
							g_free, g_free);
	if (session->result.headers == NULL) {
		free_session(session);
		return 0;
	}

	session->receive_space = DEFAULT_BUFFER_SIZE;
	session->send_buffer = g_string_sized_new(0);
	session->current_header = g_string_sized_new(0);
	session->header_done = FALSE;
	session->body_done = FALSE;

	if (session->address == NULL && inet_aton(session->host, NULL) == 0) {
		session->resolv_action = g_resolv_lookup_hostname(web->resolv,
					session->host, resolv_result, session);
		if (session->resolv_action == 0) {
			free_session(session);
			return 0;
		}
	} else {
		struct addrinfo hints;
		char *port;
		int ret;

		if (session->address == NULL)
			session->address = g_strdup(session->host);

		memset(&hints, 0, sizeof(struct addrinfo));
		hints.ai_flags = AI_NUMERICHOST;
		hints.ai_family = session->web->family;

		if (session->addr != NULL) {
			freeaddrinfo(session->addr);
			session->addr = NULL;
		}

		port = g_strdup_printf("%u", session->port);
		ret = getaddrinfo(session->address, port, &hints,
							&session->addr);
		g_free(port);
		if (ret != 0 || session->addr == NULL) {
			free_session(session);
			return 0;
		}

		if (create_transport(session) < 0) {
			free_session(session);
			return 0;
		}
	}

	web->session_list = g_list_append(web->session_list, session);

	return web->next_query_id++;
}