Ejemplo n.º 1
0
static DBusMessage *l2tp_get_sec(struct connman_task *task,
			DBusMessage *msg, void *user_data)
{
	const char *user, *passwd;
	struct connman_provider *provider = user_data;

	if (dbus_message_get_no_reply(msg) == FALSE) {
		DBusMessage *reply;

		user = connman_provider_get_string(provider, "L2TP.User");
		passwd = connman_provider_get_string(provider, "L2TP.Password");

		if (user == NULL || strlen(user) == 0 ||
				passwd == NULL || strlen(passwd) == 0)
			return NULL;

		reply = dbus_message_new_method_return(msg);
		if (reply == NULL)
			return NULL;

		dbus_message_append_args(reply, DBUS_TYPE_STRING, &user,
						DBUS_TYPE_STRING, &passwd,
						DBUS_TYPE_INVALID);

		return reply;
	}

	return NULL;
}
Ejemplo n.º 2
0
static int l2tp_write_fields(struct connman_provider *provider,
						int fd, int sub)
{
	int i;
	const char *opt_s;

	for (i = 0; i < (int)ARRAY_SIZE(pppd_options); i++) {
		if (pppd_options[i].sub != sub)
			continue;

		opt_s = connman_provider_get_string(provider,
					pppd_options[i].cm_opt);
		if (!opt_s)
			opt_s = pppd_options[i].vpn_default;

		if (!opt_s)
			continue;

		if (pppd_options[i].type == OPT_STRING)
			l2tp_write_section(fd,
				pppd_options[i].pppd_opt, opt_s);
		else if (pppd_options[i].type == OPT_BOOL)
			l2tp_write_bool_option(fd,
				pppd_options[i].pppd_opt, opt_s);
	}

	return 0;
}
Ejemplo n.º 3
0
static int vc_write_config_data(struct connman_provider *provider, int fd)
{
	const char *opt_s;
	int i;

	for (i = 0; i < (int)ARRAY_SIZE(vpnc_options); i++) {
		opt_s = connman_provider_get_string(provider,
					vpnc_options[i].cm_opt);
		if (!opt_s)
			opt_s= vpnc_options[i].vpnc_default;

		if(!opt_s)
			continue;

		if (vpnc_options[i].type == OPT_STRING) {
			if (write_option(fd,
					vpnc_options[i].vpnc_opt, opt_s) < 0)
				return -EIO;
		} else if (vpnc_options[i].type == OPT_BOOLEAN) {
			if (write_bool_option(fd,
					vpnc_options[i].vpnc_opt, opt_s) < 0)
				return -EIO;
		}

	}

	return 0;
}
Ejemplo n.º 4
0
static int vc_connect(struct connman_provider *provider,
		struct connman_task *task, const char *if_name)
{
	const char *option;
	int err, fd;

	option = connman_provider_get_string(provider, "Host");
	if (option == NULL) {
		connman_error("Host not set; cannot enable VPN");
		return -EINVAL;
	}
	option = connman_provider_get_string(provider, "VPNC.IPSec.ID");
	if (option == NULL) {
		connman_error("Group not set; cannot enable VPN");
		return -EINVAL;
	}

	connman_task_add_argument(task, "--non-inter", NULL);
	connman_task_add_argument(task, "--no-detach", NULL);

	connman_task_add_argument(task, "--ifname", if_name);
	connman_task_add_argument(task, "--ifmode", "tun");

	connman_task_add_argument(task, "--script",
				SCRIPTDIR "/openconnect-script");

	option = connman_provider_get_string(provider, "VPNC.Debug");
	if (option != NULL)
		connman_task_add_argument(task, "--debug", option);

	connman_task_add_argument(task, "-", NULL);

	err = connman_task_run(task, vpn_died, provider,
				&fd, NULL, NULL);
	if (err < 0) {
		connman_error("vpnc failed to start");
		return -EIO;
	}

	err = vc_write_config_data(provider, fd);

	close(fd);

	return err;
}
Ejemplo n.º 5
0
static int l2tp_connect(struct connman_provider *provider,
		struct connman_task *task, const char *if_name)
{
	const char *host;
	char *l2tp_name, *pppd_name;
	int l2tp_fd, pppd_fd;
	int err;

	if (connman_task_set_notify(task, "getsec",
					l2tp_get_sec, provider))
		return -ENOMEM;

	host = connman_provider_get_string(provider, "Host");
	if (host == NULL) {
		connman_error("Host not set; cannot enable VPN");
		return -EINVAL;
	}

	l2tp_name = g_strdup_printf("/var/run/connman/connman-xl2tpd.conf");

	l2tp_fd = open(l2tp_name, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);
	if (l2tp_fd < 0) {
		g_free(l2tp_name);
		connman_error("Error writing l2tp config");
		return -EIO;
	}

	pppd_name = g_strdup_printf("/var/run/connman/connman-ppp-option.conf");

	pppd_fd = open(pppd_name, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);
	if (pppd_fd < 0) {
		connman_error("Error writing pppd config");
		g_free(l2tp_name);
		g_free(pppd_name);
		close(l2tp_fd);
		return -EIO;
	}

	l2tp_write_config(provider, pppd_name, l2tp_fd);

	write_pppd_option(provider, pppd_fd);

	connman_task_add_argument(task, "-D", NULL);
	connman_task_add_argument(task, "-c", l2tp_name);

	g_free(l2tp_name);
	g_free(pppd_name);

	err = connman_task_run(task, l2tp_died, provider,
				NULL, NULL, NULL);
	if (err < 0) {
		connman_error("l2tp failed to start");
		return -EIO;
	}

	return 0;
}
Ejemplo n.º 6
0
static int l2tp_save(struct connman_provider *provider, GKeyFile *keyfile)
{
	const char *option;
	int i;

	for (i = 0; i < (int)ARRAY_SIZE(pppd_options); i++) {
		if (strncmp(pppd_options[i].cm_opt, "L2TP.", 5) == 0) {
			option = connman_provider_get_string(provider,
							pppd_options[i].cm_opt);
			if (option == NULL)
				continue;

			g_key_file_set_string(keyfile,
					connman_provider_get_save_group(provider),
					pppd_options[i].cm_opt, option);
		}
	}
	return 0;
}
Ejemplo n.º 7
0
static int l2tp_write_config(struct connman_provider *provider,
					const char *pppd_name, int fd)
{
	const char *option;

	l2tp_write_option(fd, "[global]", NULL);
	l2tp_write_fields(provider, fd, OPT_L2G);

	l2tp_write_option(fd, "[lac l2tp]", NULL);

	option = connman_provider_get_string(provider, "Host");
	l2tp_write_option(fd, "lns =", option);

	l2tp_write_fields(provider, fd, OPT_ALL);
	l2tp_write_fields(provider, fd, OPT_L2);

	l2tp_write_option(fd, "pppoptfile =", pppd_name);

	return 0;
}
Ejemplo n.º 8
0
static int task_append_config_data(struct connman_provider *provider,
					struct connman_task *task)
{
	const char *option;
	int i;

	for (i = 0; i < (int)ARRAY_SIZE(ov_options); i++) {
		option = connman_provider_get_string(provider,
					ov_options[i].cm_opt);
		if (option == NULL)
			continue;

		if (connman_task_add_argument(task,
					ov_options[i].ov_opt,
					ov_options[i].has_value ? option : NULL) < 0) {
			return -EIO;
		}
	}

	return 0;
}
Ejemplo n.º 9
0
static int write_pppd_option(struct connman_provider *provider, int fd)
{
	int i;
	const char *opt_s;

	l2tp_write_option(fd, "nodetach", NULL);
	l2tp_write_option(fd, "lock", NULL);
	l2tp_write_option(fd, "usepeerdns", NULL);
	l2tp_write_option(fd, "noipdefault", NULL);
	l2tp_write_option(fd, "noauth", NULL);
	l2tp_write_option(fd, "nodefaultroute", NULL);
	l2tp_write_option(fd, "ipparam", "l2tp_plugin");

	for (i = 0; i < (int)ARRAY_SIZE(pppd_options); i++) {
		if (pppd_options[i].sub != OPT_ALL &&
			pppd_options[i].sub != OPT_PPPD)
			continue;

		opt_s = connman_provider_get_string(provider,
					pppd_options[i].cm_opt);
		if (!opt_s)
			opt_s = pppd_options[i].vpn_default;

		if (!opt_s)
			continue;

		if (pppd_options[i].type == OPT_STRING)
			l2tp_write_option(fd,
				pppd_options[i].pppd_opt, opt_s);
		else if (pppd_options[i].type == OPT_BOOL)
			l2tp_write_bool_option(fd,
				pppd_options[i].pppd_opt, opt_s);
	}

	l2tp_write_option(fd, "plugin",
				SCRIPTDIR "/libppp-plugin.so");

	return 0;
}
Ejemplo n.º 10
0
static int vc_save(struct connman_provider *provider, GKeyFile *keyfile)
{
	const char *option;
	int i;

	for (i = 0; i < (int)ARRAY_SIZE(vpnc_options); i++) {
		if (strncmp(vpnc_options[i].cm_opt, "VPNC.", 5) == 0) {

			if (vpnc_options[i].cm_save == FALSE)
				continue;

			option = connman_provider_get_string(provider,
							vpnc_options[i].cm_opt);
			if (option == NULL)
				continue;

			g_key_file_set_string(keyfile,
					connman_provider_get_save_group(provider),
					vpnc_options[i].cm_opt, option);
		}
	}
	return 0;
}
Ejemplo n.º 11
0
static int l2tp_notify(DBusMessage *msg, struct connman_provider *provider)
{
	DBusMessageIter iter, dict;
	const char *reason, *key, *value;
	char *addressv4 = NULL, *netmask = NULL, *gateway = NULL;
	char *ifname = NULL, *nameservers = NULL;
	struct connman_ipaddress *ipaddress = NULL;

	dbus_message_iter_init(msg, &iter);

	dbus_message_iter_get_basic(&iter, &reason);
	dbus_message_iter_next(&iter);

	if (!provider) {
		connman_error("No provider found");
		return VPN_STATE_FAILURE;
	}

	if (strcmp(reason, "auth failed") == 0)
		return VPN_STATE_AUTH_FAILURE;

	if (strcmp(reason, "connect"))
		return VPN_STATE_DISCONNECT;

	dbus_message_iter_recurse(&iter, &dict);

	while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
		DBusMessageIter entry;

		dbus_message_iter_recurse(&dict, &entry);
		dbus_message_iter_get_basic(&entry, &key);
		dbus_message_iter_next(&entry);
		dbus_message_iter_get_basic(&entry, &value);

		DBG("%s = %s", key, value);

		if (!strcmp(key, "INTERNAL_IP4_ADDRESS")) {
			connman_provider_set_string(provider, "Address", value);
			addressv4 = g_strdup(value);
		}

		if (!strcmp(key, "INTERNAL_IP4_NETMASK")) {
			connman_provider_set_string(provider, "Netmask", value);
			netmask = g_strdup(value);
		}

		if (!strcmp(key, "INTERNAL_IP4_DNS")) {
			connman_provider_set_string(provider, "DNS", value);
			nameservers = g_strdup(value);
		}

		if (!strcmp(key, "INTERNAL_IFNAME"))
			ifname = g_strdup(value);

		dbus_message_iter_next(&dict);
	}

	if (vpn_set_ifname(provider, ifname) < 0) {
		g_free(ifname);
		g_free(addressv4);
		g_free(netmask);
		g_free(nameservers);
		return VPN_STATE_FAILURE;
	}

	if (addressv4 != NULL)
		ipaddress = connman_ipaddress_alloc(AF_INET);

	g_free(ifname);

	if (ipaddress == NULL) {
		connman_error("No IP address for provider");
		g_free(addressv4);
		g_free(netmask);
		g_free(nameservers);
		return VPN_STATE_FAILURE;
	}

	value = connman_provider_get_string(provider, "Host");
	if (value != NULL) {
		connman_provider_set_string(provider, "Gateway", value);
		gateway = g_strdup(value);
	}

	if (addressv4 != NULL)
		connman_ipaddress_set_ipv4(ipaddress, addressv4, netmask,
					gateway);

	connman_provider_set_ipaddress(provider, ipaddress);
	connman_provider_set_nameservers(provider, nameservers);

	g_free(addressv4);
	g_free(netmask);
	g_free(gateway);
	g_free(nameservers);
	connman_ipaddress_free(ipaddress);

	return VPN_STATE_CONNECT;
}
Ejemplo n.º 12
0
static int ov_connect(struct connman_provider *provider,
		struct connman_task *task, const char *if_name)
{
	const char *option;
	int err, fd;

	option = connman_provider_get_string(provider, "Host");
	if (option == NULL) {
		connman_error("Host not set; cannot enable VPN");
		return -EINVAL;
	}

	task_append_config_data(provider, task);

	connman_task_add_argument(task, "--syslog", NULL);

	connman_task_add_argument(task, "--script-security", "2");

	connman_task_add_argument(task, "--up",
					SCRIPTDIR "/openvpn-script");
	connman_task_add_argument(task, "--up-restart", NULL);

	connman_task_add_argument(task, "--setenv", NULL);
	connman_task_add_argument(task, "CONNMAN_BUSNAME",
					dbus_bus_get_unique_name(connection));

	connman_task_add_argument(task, "--setenv", NULL);
	connman_task_add_argument(task, "CONNMAN_INTERFACE",
					CONNMAN_TASK_INTERFACE);

	connman_task_add_argument(task, "--setenv", NULL);
	connman_task_add_argument(task, "CONNMAN_PATH",
					connman_task_get_path(task));

	connman_task_add_argument(task, "--dev", if_name);
	connman_task_add_argument(task, "--dev-type", "tun");

	connman_task_add_argument(task, "--tls-client", NULL);
	connman_task_add_argument(task, "--nobind", NULL);
	connman_task_add_argument(task, "--persist-key", NULL);
	connman_task_add_argument(task, "--persist-tun", NULL);

	connman_task_add_argument(task, "--route-noexec", NULL);
	connman_task_add_argument(task, "--ifconfig-noexec", NULL);

	/*
	 * Disable client restarts because we can't handle this at the
	 * moment. The problem is that when OpenVPN decides to switch
	 * from CONNECTED state to RECONNECTING and then to RESOLVE,
	 * it is not possible to do a DNS lookup. The DNS server is
	 * not accessable through the tunnel anymore and so we end up
	 * trying to resolve the OpenVPN servers address.
	 */
	connman_task_add_argument(task, "--ping-restart", "0");

	connman_task_add_argument(task, "--client", NULL);

	fd = fileno(stderr);
	err = connman_task_run(task, vpn_died, provider,
			NULL, &fd, &fd);
	if (err < 0) {
		connman_error("openvpn failed to start");
		return -EIO;
	}

	return 0;
}