static gboolean
real_connect (NMVPNPlugin   *plugin,
              NMConnection  *connection,
              GError       **error)
{
	NMSettingVPN *s_vpn;
	gint openconnect_fd = -1;

	s_vpn = NM_SETTING_VPN (nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN));
	g_assert (s_vpn);
	if (!nm_openconnect_properties_validate (s_vpn, error))
		goto out;
	if (!nm_openconnect_secrets_validate (s_vpn, error))
		goto out;

	if (debug)
		nm_connection_dump (connection);

	openconnect_fd = nm_openconnect_start_openconnect_binary (NM_OPENCONNECT_PLUGIN (plugin), s_vpn, error);
	if (!openconnect_fd)
		return TRUE;

 out:
	return FALSE;
}
static void
print_connection (DBusGConnection *bus, const char *service, const char *path)
{
	DBusGProxy *proxy;
	GError *error = NULL;
	GHashTable *hash = NULL;
	NMConnection *connection = NULL;

	/* This function asks the Settings Service that provides this network
	 * configuration for the details of that configuration.
	 */

	/* Create the D-Bus proxy for the Settings Service so we can ask it for the
	 * connection configuration details.
	 */
	proxy = dbus_g_proxy_new_for_name (bus,
	                                   service,
	                                   path,
	                                   NM_DBUS_IFACE_SETTINGS_CONNECTION);
	g_assert (proxy);

	/* Request the all the configuration of the Connection */
	if (!dbus_g_proxy_call (proxy, "GetSettings", &error,
	                        G_TYPE_INVALID,
	                        DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &hash,
	                        G_TYPE_INVALID)) {
		g_warning ("Failed to get active connection Connection property: %s",
		           error->message);
		g_error_free (error);
		goto out;
	}

	/* Using the raw configuration, create an NMConnection object for it.  This
	 * step also verifies that the data we got from the settings service is
	 * valid. */
	connection = nm_connection_new_from_hash (hash, &error);
	if (!connection) {
		g_warning ("Received invalid connection data: %s", error->message);
		g_error_free (error);
		goto out;
	}

	/* And finally dump all the configuration to stdout */
	g_message ("%s => %s", service, path);
	nm_connection_dump (connection);

out:
	if (connection)
		g_object_unref (connection);
	if (hash)
		g_hash_table_destroy (hash);
	g_object_unref (proxy);
}
static gboolean
real_connect (NMVpnServicePlugin   *plugin,
              NMConnection         *connection,
              GError              **error)
{
	NMSstpPluginPrivate *priv = NM_SSTP_PLUGIN_GET_PRIVATE (plugin);
	NMSettingVpn *s_vpn;
	const char *gwaddr;
	const char *value;

	s_vpn = nm_connection_get_setting_vpn (connection);
	g_assert (s_vpn);

	gwaddr = nm_setting_vpn_get_data_item (s_vpn, NM_SSTP_KEY_GATEWAY);
	if (!gwaddr || !strlen (gwaddr)) {
		g_set_error_literal (error,
		                     NM_VPN_PLUGIN_ERROR,
		                     NM_VPN_PLUGIN_ERROR_LAUNCH_FAILED,
		                     _("Invalid or missing SSTP gateway."));
		return FALSE;
	}

	/*  Set the UUID of the connection */
	value = nm_connection_get_uuid(connection);
	if (value && strlen(value))
		nm_setting_vpn_add_data_item(s_vpn, NM_SSTP_KEY_UUID, value);

	if (!nm_sstp_properties_validate (s_vpn, error))
		return FALSE;

	if (!nm_sstp_secrets_validate (s_vpn, error))
		return FALSE;

	priv->connection = g_object_ref (connection);

	if (getenv ("NM_PPP_DUMP_CONNECTION") || debug)
		nm_connection_dump (connection);

	return nm_sstp_start_pppd_binary (NM_SSTP_PLUGIN (plugin),
	                                  s_vpn,
	                                  gwaddr,
	                                  error);
}
Ejemplo n.º 4
0
static gboolean
real_connect (NMVPNPlugin   *plugin,
              NMConnection  *connection,
              GError       **error)
{
	NML2tpPluginPrivate *priv = NM_L2TP_PLUGIN_GET_PRIVATE (plugin);
	NMSettingVPN *s_vpn;
	const char *value;

	if (getenv ("NM_PPP_DUMP_CONNECTION") || debug)
		nm_connection_dump (connection);

	s_vpn = NM_SETTING_VPN (nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN));
	g_assert (s_vpn);

	if (!nm_l2tp_properties_validate (s_vpn, error))
		return FALSE;

	if (!nm_l2tp_secrets_validate (s_vpn, error))
		return FALSE;

	/* Start our pppd plugin helper service */
	if (priv->service)
		g_object_unref (priv->service);
	if (priv->connection) {
		g_object_unref (priv->connection);
		priv->connection = NULL;
	}

	priv->service = nm_l2tp_ppp_service_new (connection, error);
	if (!priv->service) {
		g_set_error (error,
		             NM_VPN_PLUGIN_ERROR,
		             NM_VPN_PLUGIN_ERROR_LAUNCH_FAILED,
		             "%s",
		             _("Could not start pppd plugin helper service."));
		return FALSE;
	}

	priv->connection = g_object_ref (connection);

	g_signal_connect (G_OBJECT (priv->service), "plugin-alive", G_CALLBACK (service_plugin_alive_cb), plugin);
	g_signal_connect (G_OBJECT (priv->service), "ppp-state", G_CALLBACK (service_ppp_state_cb), plugin);
	g_signal_connect (G_OBJECT (priv->service), "ip4-config", G_CALLBACK (service_ip4_config_cb), plugin);

	/* Cache the username and password so we can relay the secrets to the pppd
	 * plugin when it asks for them.
	 */
	if (!_service_cache_credentials (priv->service, connection, error))
		return FALSE;

	if (!nm_l2tp_resolve_gateway (NM_L2TP_PLUGIN (plugin), s_vpn, error))
		return FALSE;

	if (!nm_l2tp_config_write (NM_L2TP_PLUGIN (plugin), s_vpn, error))
		return FALSE;

	value = nm_setting_vpn_get_data_item (s_vpn, NM_L2TP_KEY_IPSEC_ENABLE);
	g_message(_("ipsec enable flag: %s"), value?value:"(null)");
	if(value && !strcmp(value,"yes")) {
		g_message(_("starting ipsec"));
		if (!nm_l2tp_start_ipsec(NM_L2TP_PLUGIN (plugin), s_vpn, error))
			return FALSE;
	}

	if (!nm_l2tp_start_l2tpd_binary (NM_L2TP_PLUGIN (plugin), s_vpn, error))
		return FALSE;

	return TRUE;
}