コード例 #1
0
static void
add_pan_connection (NmaBtDevice *self)
{
	NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (self);
	NMConnection *connection;
	NMSetting *setting, *bt_setting, *ip_setting;
	char *id, *uuid;

	/* The connection */
	connection = nm_connection_new ();

	/* The connection settings */
	setting = nm_setting_connection_new ();
	id = g_strdup_printf (_("%s Network"), priv->alias ? priv->alias : priv->bdaddr);
	uuid = nm_utils_uuid_generate ();
	g_object_set (G_OBJECT (setting),
	              NM_SETTING_CONNECTION_ID, id,
	              NM_SETTING_CONNECTION_UUID, uuid,
	              NM_SETTING_CONNECTION_TYPE, NM_SETTING_BLUETOOTH_SETTING_NAME,
	              NM_SETTING_CONNECTION_AUTOCONNECT, FALSE,
	              NULL);
	g_free (id);
	g_free (uuid);
	nm_setting_connection_add_permission ((NMSettingConnection *) setting, "user", g_get_user_name (), NULL);
	nm_connection_add_setting (connection, setting);

	/* The Bluetooth settings */
	bt_setting = nm_setting_bluetooth_new ();
	g_object_set (G_OBJECT (bt_setting),
	              NM_SETTING_BLUETOOTH_BDADDR, priv->bdaddr_array,
	              NM_SETTING_BLUETOOTH_TYPE, NM_SETTING_BLUETOOTH_TYPE_PANU,
	              NULL);
	nm_connection_add_setting (connection, bt_setting);

	/* IPv4 */
	ip_setting = nm_setting_ip4_config_new ();
	g_object_set (G_OBJECT (ip_setting),
	              NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
	              NM_SETTING_IP4_CONFIG_MAY_FAIL, FALSE,
	              NULL);
	nm_connection_add_setting (connection, ip_setting);

	/* IPv6 */
	ip_setting = nm_setting_ip6_config_new ();
	g_object_set (G_OBJECT (ip_setting),
	              NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
	              NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
	              NULL);
	nm_connection_add_setting (connection, ip_setting);

	/* Add the connection to the settings service */
	nm_remote_settings_add_connection (priv->settings,
	                                   connection,
	                                   pan_add_cb,
	                                   self);
}
コード例 #2
0
static NMConnection *
dun_new_gsm (NMAMobileWizardAccessMethod *method)
{
	NMConnection *connection;
	NMSetting *setting;
	char *uuid, *id;

	connection = nm_connection_new ();

	setting = nm_setting_gsm_new ();
	g_object_set (setting,
	              NM_SETTING_GSM_NUMBER, "*99#",
	              NM_SETTING_GSM_USERNAME, method->username,
	              NM_SETTING_GSM_PASSWORD, method->password,
	              NM_SETTING_GSM_PASSWORD_FLAGS, NM_SETTING_SECRET_FLAG_AGENT_OWNED,
	              NM_SETTING_GSM_APN, method->gsm_apn,
	              NULL);
	nm_connection_add_setting (connection, setting);

	/* Serial setting */
	setting = nm_setting_serial_new ();
	g_object_set (setting,
	              NM_SETTING_SERIAL_BAUD, 115200,
	              NM_SETTING_SERIAL_BITS, 8,
	              NM_SETTING_SERIAL_PARITY, 'n',
	              NM_SETTING_SERIAL_STOPBITS, 1,
	              NULL);
	nm_connection_add_setting (connection, setting);

	nm_connection_add_setting (connection, nm_setting_ppp_new ());

	setting = nm_setting_connection_new ();
	id = utils_create_mobile_connection_id (method->provider_name, method->plan_name);
	uuid = nm_utils_uuid_generate ();
	g_object_set (setting,
	              NM_SETTING_CONNECTION_ID, id,
	              NM_SETTING_CONNECTION_TYPE, NM_SETTING_BLUETOOTH_SETTING_NAME,
	              NM_SETTING_CONNECTION_AUTOCONNECT, FALSE,
	              NM_SETTING_CONNECTION_UUID, uuid,
	              NULL);
	g_free (uuid);
	g_free (id);
	nm_setting_connection_add_permission ((NMSettingConnection *) setting, "user", g_get_user_name (), NULL);
	nm_connection_add_setting (connection, setting);

	return connection;
}
コード例 #3
0
static void
test_add_connection (void)
{
	gs_unref_object NMConnection *connection = NULL;
	NMSettingConnection *s_con;
	NMSettingWired *s_wired;
	char *uuid;
	gboolean success;
	time_t start, now;
	gboolean done = FALSE;

	connection = nm_connection_new ();

	s_con = (NMSettingConnection *) nm_setting_connection_new ();
	uuid = nm_utils_uuid_generate ();
	g_object_set (G_OBJECT (s_con),
	              NM_SETTING_CONNECTION_ID, TEST_CON_ID,
	              NM_SETTING_CONNECTION_UUID, uuid,
	              NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME,
	              NULL);
	g_free (uuid);
	nm_connection_add_setting (connection, NM_SETTING (s_con));

	s_wired = (NMSettingWired *) nm_setting_wired_new ();
	nm_connection_add_setting (connection, NM_SETTING (s_wired));

	success = nm_remote_settings_add_connection (settings,
	                                             connection,
	                                             add_cb,
	                                             &done);
	g_assert (success == TRUE);

	start = time (NULL);
	do {
		now = time (NULL);
		g_main_context_iteration (NULL, FALSE);
	} while ((done == FALSE) && (now - start < 5));
	g_assert (done == TRUE);
	g_assert (remote != NULL);

	/* Make sure the connection is the same as what we added */
	g_assert (nm_connection_compare (connection,
	                                 NM_CONNECTION (remote),
	                                 NM_SETTING_COMPARE_FLAG_EXACT) == TRUE);
}
コード例 #4
0
static gboolean
add_connection (NMRemoteSettings *settings, GMainLoop *loop, const char *con_name)
{
	NMConnection *connection;
	NMSettingConnection *s_con;
	NMSettingWired *s_wired;
	NMSettingIP4Config *s_ip4;
	char *uuid;
	gboolean success;

	/* Create a new connection object */
	connection = nm_connection_new ();

	/* Build up the 'connection' Setting */
	s_con = (NMSettingConnection *) nm_setting_connection_new ();
	uuid = nm_utils_uuid_generate ();
	g_object_set (G_OBJECT (s_con),
	              NM_SETTING_CONNECTION_UUID, uuid,
	              NM_SETTING_CONNECTION_ID, con_name,
	              NM_SETTING_CONNECTION_TYPE, "802-3-ethernet",
	              NULL);
	g_free (uuid);
	nm_connection_add_setting (connection, NM_SETTING (s_con));

	/* Build up the 'wired' Setting */
	s_wired = (NMSettingWired *) nm_setting_wired_new ();
	nm_connection_add_setting (connection, NM_SETTING (s_wired));

	/* Build up the 'ipv4' Setting */
	s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
	g_object_set (G_OBJECT (s_ip4),
	              NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
	              NULL);
	nm_connection_add_setting (connection, NM_SETTING (s_ip4));

	/* Ask the settings service to add the new connection; we'll quit the
	 * mainloop and exit when the callback is called.
	 */
	success = nm_remote_settings_add_connection (settings, connection, added_cb, loop);
	if (!success)
		g_print ("Error adding connection\n");

	g_object_unref (connection);
	return success;
}
コード例 #5
0
static void
add_profile (GtkButton *button, NetDeviceEthernet *device)
{
        NMRemoteSettings *settings;
        NMConnection *connection;
        NMSettingConnection *sc;
        gchar *uuid, *id;
        NetConnectionEditor *editor;
        GtkWidget *window;
        NMClient *client;
        NMDevice *nmdev;
        GSList *connections;

        connection = nm_connection_new ();
        sc = NM_SETTING_CONNECTION (nm_setting_connection_new ());
        nm_connection_add_setting (connection, NM_SETTING (sc));

        uuid = nm_utils_uuid_generate ();

        settings = net_object_get_remote_settings (NET_OBJECT (device));
        connections = nm_remote_settings_list_connections (settings);
        id = ce_page_get_next_available_name (connections, _("Profile %d"));
        g_slist_free (connections);

        g_object_set (sc,
                      NM_SETTING_CONNECTION_UUID, uuid,
                      NM_SETTING_CONNECTION_ID, id,
                      NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME,
                      NM_SETTING_CONNECTION_AUTOCONNECT, TRUE,
                      NULL);

        nm_connection_add_setting (connection, nm_setting_wired_new ());

        g_free (uuid);
        g_free (id);

        window = gtk_widget_get_toplevel (GTK_WIDGET (button));

        nmdev = net_device_get_nm_device (NET_DEVICE (device));
        client = net_object_get_client (NET_OBJECT (device));
        editor = net_connection_editor_new (GTK_WINDOW (window), connection, nmdev, NULL, client, settings);
        g_signal_connect (editor, "done", G_CALLBACK (editor_done), device);
        net_connection_editor_run (editor);
}
コード例 #6
0
static NMConnection *
dun_new_cdma (NMAMobileWizardAccessMethod *method)
{
	NMConnection *connection;
	NMSetting *setting;
	char *uuid, *id;

	connection = nm_connection_new ();

	setting = nm_setting_cdma_new ();
	g_object_set (setting,
	              NM_SETTING_CDMA_NUMBER, "#777",
	              NM_SETTING_CDMA_USERNAME, method->username,
	              NM_SETTING_CDMA_PASSWORD, method->password,
	              NULL);
	nm_connection_add_setting (connection, setting);

	/* Serial setting */
	setting = nm_setting_serial_new ();
	g_object_set (setting,
	              NM_SETTING_SERIAL_BAUD, 115200,
	              NM_SETTING_SERIAL_BITS, 8,
	              NM_SETTING_SERIAL_PARITY, 'n',
	              NM_SETTING_SERIAL_STOPBITS, 1,
	              NULL);
	nm_connection_add_setting (connection, setting);

	nm_connection_add_setting (connection, nm_setting_ppp_new ());

	setting = nm_setting_connection_new ();
	id = utils_create_mobile_connection_id (method->provider_name, method->plan_name);
	uuid = nm_utils_uuid_generate ();
	g_object_set (setting,
	              NM_SETTING_CONNECTION_ID, id,
	              NM_SETTING_CONNECTION_TYPE, NM_SETTING_BLUETOOTH_SETTING_NAME,
	              NM_SETTING_CONNECTION_AUTOCONNECT, FALSE,
	              NM_SETTING_CONNECTION_UUID, uuid,
	              NULL);
	g_free (uuid);
	g_free (id);
	nm_connection_add_setting (connection, setting);

	return connection;
}
コード例 #7
0
static gboolean
wimax_new_auto_connection (NMDevice *device,
                           gpointer dclass_data,
                           AppletNewAutoConnectionCallback callback,
                           gpointer callback_data)
{
	WimaxMenuItemInfo *info = dclass_data;
	NMConnection *connection;
	NMSettingWimax *s_wimax = NULL;
	NMSettingConnection *s_con;
	char *uuid;
	const char *nsp_name;

	nsp_name = nm_wimax_nsp_get_name (info->nsp);

	connection = nm_connection_new ();

	s_wimax = NM_SETTING_WIMAX (nm_setting_wimax_new ());
	g_object_set (s_wimax,
	              NM_SETTING_WIMAX_NETWORK_NAME, nsp_name,
	              NULL);
	nm_connection_add_setting (connection, NM_SETTING (s_wimax));

	s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
	uuid = nm_utils_uuid_generate ();
	g_object_set (s_con,
				  NM_SETTING_CONNECTION_ID, nsp_name,
				  NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIMAX_SETTING_NAME,
				  NM_SETTING_CONNECTION_AUTOCONNECT, TRUE,
				  NM_SETTING_CONNECTION_UUID, uuid,
				  NULL);
	g_free (uuid);

	nm_connection_add_setting (connection, NM_SETTING (s_con));

	(*callback) (connection, TRUE, FALSE, callback_data);
	return TRUE;
}
コード例 #8
0
ファイル: wired-dialog.c プロジェクト: mirsal/nm-applet
NMSettingsConnectionInterface *
nma_wired_dialog_get_connection (GtkWidget *dialog)
{
	NMSettingsConnectionInterface *connection;
	WirelessSecurity *security;
	NMConnection *tmp_connection;
	NMSetting *s_8021x, *s_con;

	g_return_val_if_fail (dialog != NULL, NULL);

	connection = g_object_get_data (G_OBJECT (dialog), "connection");
	security = g_object_get_data (G_OBJECT (dialog), "security");

	/* Here's a nice hack to work around the fact that ws_802_1x_fill_connection()
	 * needs a wireless setting and a connection setting for various things.
	 */
	tmp_connection = nm_connection_new ();

	/* Add the fake connection setting (mainly for the UUID for cert ignore checking) */
	s_con = nm_connection_get_setting (NM_CONNECTION (connection), NM_TYPE_SETTING_CONNECTION);
	g_assert (s_con);
	nm_connection_add_setting (tmp_connection, NM_SETTING (g_object_ref (s_con)));

	/* And the fake wireless setting */
	nm_connection_add_setting (tmp_connection, nm_setting_wireless_new ());

	/* Fill up the 802.1x setting */
	ws_802_1x_fill_connection (security, "wpa_eap_auth_combo", tmp_connection);

	/* Grab it and add it to our original connection */
	s_8021x = nm_connection_get_setting (tmp_connection, NM_TYPE_SETTING_802_1X);
	nm_connection_add_setting (NM_CONNECTION (connection), NM_SETTING (g_object_ref (s_8021x)));

	g_object_unref (tmp_connection);

	return connection;
}
コード例 #9
0
ファイル: cli-add.c プロジェクト: vzupanovic/cuvaj
static int
add_connection (DBusGProxy *proxy, char *con_name, char *apn, char *pin, 
				char *username, char *password, int ntype, char *number,
				char *auth, char *comp, char *aut, char *netid, char *enc,
				int ecoint, int ecofail, char *uuid, int sbits, char sparity,
				int stbits, int sbaud)
{
	NMConnection *connection;
	NMSettingConnection *s_con;
	NMSettingIP4Config *s_ip4;
	NMSettingGsm *s_gsm;
	NMSettingPPP *s_ppp;
	NMSettingSerial *s_serial;
	
	char *new_con_path = NULL;
	GHashTable *hash;
	GError *error = NULL;
	
	int autoconnect = 1;
	int uuid_generated = 0;
	
	
	if ((aut != NULL) && (aut[0] != 't'))
		autoconnect = 0;
	
	connection = (NMConnection *)nm_connection_new ();
	if (connection == NULL){
		printf("Unable to allocate new connection... Sorry.\n");
		return NMC_RESULT_ERROR_CON_ADD;
	}

	s_con = (NMSettingConnection *) nm_setting_connection_new ();
	if (s_con == NULL){
		printf("Failed to allocate new %s setting... Sorry.\n",NM_SETTING_CONNECTION_SETTING_NAME);
		return NMC_RESULT_ERROR_CON_ADD;
	}
	 
	nm_connection_add_setting (connection, NM_SETTING (s_con));
	
	
	if (uuid == NULL){
		uuid = nm_utils_uuid_generate ();
		uuid_generated = 1;
	}
		
	
	/*global settings*/
	              
	g_object_set (s_con,
	              NM_SETTING_CONNECTION_ID, con_name,
	              NM_SETTING_CONNECTION_UUID, uuid,
	              NM_SETTING_CONNECTION_AUTOCONNECT, (autoconnect == 1) ? TRUE : FALSE,
	              NM_SETTING_CONNECTION_TYPE, NM_SETTING_GSM_SETTING_NAME,
	              NULL);
	              
	if(uuid_generated == 1)
		g_free (uuid);
    
	/* GSM setting */
	s_gsm = (NMSettingGsm *) nm_setting_gsm_new ();
	
	if (s_gsm == NULL){
		printf("Failed to allocate new %s setting...Sorry.\n",NM_SETTING_GSM_SETTING_NAME);
		return NMC_RESULT_ERROR_CON_ADD;
	}
	
	nm_connection_add_setting (connection, NM_SETTING (s_gsm));

	/*Network type
					    Network preference to force the device to only use 
					    specific network technologies.  The permitted values
					    are: -1: any, 0: 3G only, 1: GPRS/EDGE only, 
					    2: prefer 3G, and 3: prefer 2G, 4: prefer 4G (LTE),
                                            5: 4G (LTE) only. Note that not all 
					    devices allow network preference control.
	*/ 
					   
	g_object_set (s_gsm, 
	              NM_SETTING_GSM_NUMBER, (number == NULL) ? "*99#" : number,
	              NM_SETTING_GSM_APN, apn,
	              NM_SETTING_GSM_USERNAME, username,
	              NM_SETTING_GSM_PASSWORD, password,
	              NM_SETTING_GSM_PIN, pin,
	              NM_SETTING_GSM_NETWORK_TYPE, ntype, 
	              NM_SETTING_GSM_NETWORK_ID, netid,
	              NULL);

	/* Serial setting */
	s_serial = (NMSettingSerial *) nm_setting_serial_new ();
	
	if (s_serial == NULL){
		printf("Failed to allocate new %s setting...Sorry.\n",NM_SETTING_SERIAL_SETTING_NAME);
		return NMC_RESULT_ERROR_CON_ADD;
	}
	
	nm_connection_add_setting (connection, NM_SETTING (s_serial));

	g_object_set (s_serial,
	              NM_SETTING_SERIAL_BAUD, sbaud,
	              NM_SETTING_SERIAL_BITS, sbits,
	              NM_SETTING_SERIAL_PARITY, sparity,
	              NM_SETTING_SERIAL_STOPBITS, stbits,
	              NULL);

	/* IP4 setting */
	s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
	
	if (s_ip4 == NULL){
		printf("Failed to allocate new %s setting... Sorry.\n",NM_SETTING_IP4_CONFIG_SETTING_NAME);
		return NMC_RESULT_ERROR_CON_ADD;
	}
	
	nm_connection_add_setting (connection, NM_SETTING (s_ip4));

	g_object_set (s_ip4,
	              NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
	              NULL);

	/* PPP setting */
	s_ppp = (NMSettingPPP *) nm_setting_ppp_new ();
	
	if (s_ppp == NULL){
		printf("Failed to allocate new %s setting... Sorry.\n", NM_SETTING_PPP_SETTING_NAME);
		return NMC_RESULT_ERROR_CON_ADD;
	}
	
	
	g_object_set(s_ppp,
				NM_SETTING_PPP_REFUSE_EAP, (auth[0] == 't') ? FALSE : TRUE,
				NM_SETTING_PPP_REFUSE_PAP, (auth[1] == 't') ? FALSE : TRUE,
				NM_SETTING_PPP_REFUSE_CHAP, (auth[2] == 't') ? FALSE : TRUE,
				NM_SETTING_PPP_REFUSE_MSCHAP, (auth[3] == 't') ? FALSE : TRUE,
				NM_SETTING_PPP_REFUSE_MSCHAPV2, (auth[4] == 't') ? FALSE : TRUE,
				NM_SETTING_PPP_NOBSDCOMP, (comp[0] == 't') ? FALSE : TRUE,
				NM_SETTING_PPP_NODEFLATE, (comp[1] == 't') ? FALSE : TRUE,
				NM_SETTING_PPP_NO_VJ_COMP,(comp[2] == 't') ? FALSE : TRUE, //tcp header compression
				NM_SETTING_PPP_REQUIRE_MPPE, (strcmp(enc, "ff")==0) ? FALSE : TRUE,
				NM_SETTING_PPP_MPPE_STATEFUL, (enc[1] == 't') ? TRUE : FALSE,
				NM_SETTING_PPP_REQUIRE_MPPE_128, (enc[0] == 't') ? TRUE : FALSE,
				NM_SETTING_PPP_LCP_ECHO_FAILURE, (ecofail > 0) ? ecofail : 0,
				NM_SETTING_PPP_LCP_ECHO_INTERVAL, (ecoint > 0) ? ecoint: 0,
				NULL);

	nm_connection_add_setting (connection, NM_SETTING (s_ppp));
	
	hash = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL);

	/* Call AddConnection with the hash as argument */
	if (!dbus_g_proxy_call (proxy, "AddConnection", &error,
	                        DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, hash,
	                        G_TYPE_INVALID,
	                        DBUS_TYPE_G_OBJECT_PATH, &new_con_path,
	                        G_TYPE_INVALID)) {
		g_print ("Error adding connection: %s %s\n",
		         dbus_g_error_get_name (error),
		         error->message);
		g_clear_error (&error);
		g_hash_table_destroy (hash);
		g_object_unref (connection);
		return NMC_RESULT_ERROR_CON_ADD;
	} else {
		g_print ("\n\tConnection added successfully at: %s \n\tUse: nmcli con list id %s - to see connection detailed info \n\tcon delete id %s - to delete connection\n", 
		         new_con_path, con_name, con_name);
		g_print ("\tTo bring connection up use: nmcli con up id %s.\n",con_name);
		g_print ("\tTo see connection status use: nmcli con status id %s.\n\n",con_name);
		g_free (new_con_path);
	}

	g_hash_table_destroy (hash);
	g_object_unref (connection);
	
	return 0;
}
コード例 #10
0
static NMConnection *
import (NMVpnPluginUiInterface *iface, const char *path, GError **error)
{
	NMConnection *connection;
	NMSettingConnection *s_con;
	NMSettingVPN *s_vpn;
	NMSettingIP4Config *s_ip4;
	GKeyFile *keyfile;
	GKeyFileFlags flags;
	const char *buf;

	keyfile = g_key_file_new ();
	flags = G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS;

	if (!g_key_file_load_from_file (keyfile, path, flags, error)) {
		g_set_error (error,
		             NM_IODINE_IMPORT_EXPORT_ERROR,
		             NM_IODINE_IMPORT_EXPORT_ERROR_NOT_IODINE,
		             "does not look like a %s VPN connection (parse failed)",
		             IODINE_PLUGIN_NAME);
		return NULL;
	}

	connection = nm_connection_new ();
	s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
	nm_connection_add_setting (connection, NM_SETTING (s_con));

	s_vpn = NM_SETTING_VPN (nm_setting_vpn_new ());
	g_object_set (s_vpn,
	              NM_SETTING_VPN_SERVICE_TYPE,
	              NM_DBUS_SERVICE_IODINE,
	              NULL);
	nm_connection_add_setting (connection, NM_SETTING (s_vpn));

	s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ());
	nm_connection_add_setting (connection, NM_SETTING (s_ip4));

	/* top level domain */
	buf = g_key_file_get_string (keyfile, "iodine", "topdomain", NULL);
	if (buf) {
		nm_setting_vpn_add_data_item (s_vpn, NM_IODINE_KEY_TOPDOMAIN, buf);
	} else {
		g_set_error (error,
		             NM_IODINE_IMPORT_EXPORT_ERROR,
		             NM_IODINE_IMPORT_EXPORT_ERROR_NOT_IODINE,
		             "does not look like a %s VPN connection "
		             "(no top level domain)",
		             IODINE_PLUGIN_NAME);
		g_object_unref (connection);
		return NULL;
	}

	/* Optional Settings */
	/* Description */
	buf = g_key_file_get_string (keyfile, "iodine", "Description", NULL);
	if (buf)
		g_object_set (s_con, NM_SETTING_CONNECTION_ID, buf, NULL);

	/* Name server */
	buf = g_key_file_get_string (keyfile, "iodine", "Nameserver", NULL);
	if (buf)
		nm_setting_vpn_add_data_item (s_vpn, NM_IODINE_KEY_NAMESERVER, buf);

	/* Fragment size */
	buf = g_key_file_get_string (keyfile, "iodine", "Fragsize", NULL);
	if (buf)
		nm_setting_vpn_add_data_item (s_vpn, NM_IODINE_KEY_FRAGSIZE, "yes");

	return connection;
}
コード例 #11
0
NMConnection *
connection_from_file (const char *filename, GError **error)
{
	GKeyFile *key_file;
	struct stat statbuf;
	gboolean bad_owner, bad_permissions;
	NMConnection *connection = NULL;
	NMSettingConnection *s_con;
	NMSettingBluetooth *s_bt;
	NMSetting *setting;
	gchar **groups;
	gsize length;
	int i;
	gboolean vpn_secrets = FALSE;
	const char *ctype, *tmp;
	GError *verify_error = NULL;

	if (stat (filename, &statbuf) != 0 || !S_ISREG (statbuf.st_mode)) {
		g_set_error_literal (error, KEYFILE_PLUGIN_ERROR, 0,
		                     "File did not exist or was not a regular file");
		return NULL;
	}

	bad_owner = getuid () != statbuf.st_uid;
	bad_permissions = statbuf.st_mode & 0077;

	if (bad_owner || bad_permissions) {
		g_set_error (error, KEYFILE_PLUGIN_ERROR, 0,
		             "File permissions (%o) or owner (%d) were insecure",
		             statbuf.st_mode, statbuf.st_uid);
		return NULL;
	}

	key_file = g_key_file_new ();
	if (!g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, error))
		goto out;

	connection = nm_connection_new ();

	groups = g_key_file_get_groups (key_file, &length);
	for (i = 0; i < length; i++) {
		/* Only read out secrets when needed */
		if (!strcmp (groups[i], VPN_SECRETS_GROUP)) {
			vpn_secrets = TRUE;
			continue;
		}

		setting = read_setting (key_file, groups[i]);
		if (setting)
			nm_connection_add_setting (connection, setting);
	}

	/* Make sure that we have the base device type setting even if
	 * the keyfile didn't include it, which can happen when the base
	 * device type setting is all default values (like ethernet).
	 */
	s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
	if (s_con) {
		ctype = nm_setting_connection_get_connection_type (s_con);
		setting = nm_connection_get_setting_by_name (connection, ctype);
		if (ctype) {
			gboolean add_serial = FALSE;
			NMSetting *new_setting = NULL;

			if (!setting && !strcmp (ctype, NM_SETTING_WIRED_SETTING_NAME))
				new_setting = nm_setting_wired_new ();
			else if (!strcmp (ctype, NM_SETTING_BLUETOOTH_SETTING_NAME)) {
				s_bt = (NMSettingBluetooth *) nm_connection_get_setting (connection, NM_TYPE_SETTING_BLUETOOTH);
				if (s_bt) {
					tmp = nm_setting_bluetooth_get_connection_type (s_bt);
					if (tmp && !strcmp (tmp, NM_SETTING_BLUETOOTH_TYPE_DUN))
						add_serial = TRUE;
				}
			} else if (!strcmp (ctype, NM_SETTING_GSM_SETTING_NAME))
				add_serial = TRUE;
			else if (!strcmp (ctype, NM_SETTING_CDMA_SETTING_NAME))
				add_serial = TRUE;

			/* Bluetooth DUN, GSM, and CDMA connections require a serial setting */
			if (add_serial && !nm_connection_get_setting (connection, NM_TYPE_SETTING_SERIAL))
				new_setting = nm_setting_serial_new ();

			if (new_setting)
				nm_connection_add_setting (connection, new_setting);
		}
	}

	/* Serial connections require a PPP setting too */
	if (nm_connection_get_setting (connection, NM_TYPE_SETTING_SERIAL)) {
		if (!nm_connection_get_setting (connection, NM_TYPE_SETTING_PPP))
			nm_connection_add_setting (connection, nm_setting_ppp_new ());
	}

	/* Handle vpn secrets after the 'vpn' setting was read */
	if (vpn_secrets) {
		NMSettingVPN *s_vpn;

		s_vpn = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN);
		if (s_vpn)
			read_vpn_secrets (key_file, s_vpn);
	}

	g_strfreev (groups);

	/* Verify the connection */
	if (!nm_connection_verify (connection, &verify_error)) {
		g_set_error (error, KEYFILE_PLUGIN_ERROR, 0,
			         "invalid or missing connection property '%s'",
			         (verify_error && verify_error->message) ? verify_error->message : "(unknown)");
		g_clear_error (&verify_error);
		g_object_unref (connection);
		connection = NULL;
	}

out:
	g_key_file_free (key_file);
	return connection;
}
コード例 #12
0
static void
test_update_secrets_wifi (void)
{
	NMConnection *connection;
	NMSettingConnection *s_con;
	NMSettingWireless *s_wifi;
	NMSettingWirelessSecurity *s_wsec;
	unsigned char tmpssid[] = { 0x31, 0x33, 0x33, 0x37 };
	const char *wepkey = "11111111111111111111111111";
	GHashTable *secrets;
	GError *error = NULL;
	char *uuid;
	GByteArray *ssid;
	gboolean success;

	connection = nm_connection_new ();
	g_assert (connection);

	/* Connection setting */
	s_con = (NMSettingConnection *) nm_setting_connection_new ();
	g_assert (s_con);

	uuid = nm_utils_uuid_generate ();
	g_object_set (s_con,
	              NM_SETTING_CONNECTION_ID, "Test Wireless",
	              NM_SETTING_CONNECTION_UUID, uuid,
	              NM_SETTING_CONNECTION_AUTOCONNECT, FALSE,
	              NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME,
	              NULL);
	g_free (uuid);
	nm_connection_add_setting (connection, NM_SETTING (s_con));

	/* Wireless setting */
	s_wifi = (NMSettingWireless *) nm_setting_wireless_new ();
	g_assert (s_wifi);

	ssid = g_byte_array_sized_new (sizeof (tmpssid));
	g_byte_array_append (ssid, &tmpssid[0], sizeof (tmpssid));
	g_object_set (s_wifi,
	              NM_SETTING_WIRELESS_SSID, ssid,
	              NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
	              NULL);
	g_byte_array_free (ssid, TRUE);
	nm_connection_add_setting (connection, NM_SETTING (s_wifi));

	/* Wifi security */
	s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
	g_assert (s_wsec);

	g_object_set (G_OBJECT (s_wsec),
	              NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none",
	              NULL);
	nm_connection_add_setting (connection, NM_SETTING (s_wsec));

	/* Build up the secrets hash */
	secrets = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, value_destroy);
	g_hash_table_insert (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, string_to_gvalue (wepkey));
	g_hash_table_insert (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, uint_to_gvalue (NM_WEP_KEY_TYPE_KEY));

	success = nm_connection_update_secrets (connection,
	                                        NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
	                                        secrets,
	                                        &error);
	if (!success) {
		/* Print the warning message before we assert success */
		g_assert (error);
		g_warning ("Error updating connection secrets: %s", error->message);
		g_clear_error (&error);
	}
	g_assert (success);
}
コード例 #13
0
static NMConnection *
make_tls_connection (const char *detail, NMSetting8021xCKScheme scheme)
{
	NMConnection *connection;
	NMSettingConnection *s_con;
	NMSetting8021x *s_8021x;
	NMSettingWired *s_wired;
	NMSettingIP4Config *s_ip4;
	char *uuid;
	gboolean success;
	GError *error = NULL;

	connection = nm_connection_new ();
	ASSERT (connection != NULL,
	        detail, "failed to allocate new connection");

	/* Connection setting */
	s_con = (NMSettingConnection *) nm_setting_connection_new ();
	ASSERT (s_con != NULL,
	        detail, "failed to allocate new %s setting",
	        NM_SETTING_CONNECTION_SETTING_NAME);
	nm_connection_add_setting (connection, NM_SETTING (s_con));

	uuid = nm_utils_uuid_generate ();
	g_object_set (s_con,
	              NM_SETTING_CONNECTION_ID, "Test Need TLS Secrets",
	              NM_SETTING_CONNECTION_UUID, uuid,
	              NM_SETTING_CONNECTION_AUTOCONNECT, TRUE,
	              NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME,
	              NULL);
	g_free (uuid);

	/* Wired setting */
	s_wired = (NMSettingWired *) nm_setting_wired_new ();
	ASSERT (s_wired != NULL,
	        detail, "failed to allocate new %s setting",
	        NM_SETTING_WIRED_SETTING_NAME);
	nm_connection_add_setting (connection, NM_SETTING (s_wired));

	/* Wireless security setting */
	s_8021x = (NMSetting8021x *) nm_setting_802_1x_new ();
	ASSERT (s_8021x != NULL,
	        detail, "failed to allocate new %s setting",
	        NM_SETTING_802_1X_SETTING_NAME);
	nm_connection_add_setting (connection, NM_SETTING (s_8021x));

	g_object_set (s_8021x, NM_SETTING_802_1X_IDENTITY, "Bill Smith", NULL);

	nm_setting_802_1x_add_eap_method (s_8021x, "tls");

	success = nm_setting_802_1x_set_ca_cert (s_8021x,
	                                         TEST_NEED_SECRETS_EAP_TLS_CA_CERT,
	                                         scheme,
	                                         NULL,
	                                         &error);
	ASSERT (success == TRUE,
	        detail, "failed to set CA certificate '%s': %s",
	        TEST_NEED_SECRETS_EAP_TLS_CA_CERT, error->message);

	success = nm_setting_802_1x_set_client_cert (s_8021x,
	                                             TEST_NEED_SECRETS_EAP_TLS_CLIENT_CERT,
	                                             scheme,
	                                             NULL,
	                                             &error);
	ASSERT (success == TRUE,
	        detail, "failed to set client certificate '%s': %s",
	        TEST_NEED_SECRETS_EAP_TLS_CLIENT_CERT, error->message);

	success = nm_setting_802_1x_set_private_key (s_8021x,
	                                             TEST_NEED_SECRETS_EAP_TLS_PRIVATE_KEY,
	                                             "test",
	                                             scheme,
	                                             NULL,
	                                             &error);
	ASSERT (success == TRUE,
	        detail, "failed to set private key '%s': %s",
	        TEST_NEED_SECRETS_EAP_TLS_PRIVATE_KEY, error->message);

	/* IP4 setting */
	s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
	ASSERT (s_ip4 != NULL,
			detail, "failed to allocate new %s setting",
			NM_SETTING_IP4_CONFIG_SETTING_NAME);
	nm_connection_add_setting (connection, NM_SETTING (s_ip4));

	g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);

	ASSERT (nm_connection_verify (connection, &error) == TRUE,
	        detail, "failed to verify connection: %s",
	        (error && error->message) ? error->message : "(unknown)");

	return connection;
}
コード例 #14
0
ファイル: reader.c プロジェクト: T100012/NetworkManager
NMConnection *
nm_keyfile_plugin_connection_from_file (const char *filename, GError **error)
{
	GKeyFile *key_file;
	struct stat statbuf;
	gboolean bad_owner, bad_permissions;
	NMConnection *connection = NULL;
	NMSettingConnection *s_con;
	NMSetting *setting;
	gchar **groups;
	gsize length;
	int i;
	gboolean vpn_secrets = FALSE;
	const char *ctype;
	GError *verify_error = NULL;

	if (stat (filename, &statbuf) != 0 || !S_ISREG (statbuf.st_mode)) {
		g_set_error_literal (error, KEYFILE_PLUGIN_ERROR, 0,
		                     "File did not exist or was not a regular file");
		return NULL;
	}

	bad_owner = getuid () != statbuf.st_uid;
	bad_permissions = statbuf.st_mode & 0077;

	if (bad_owner || bad_permissions) {
		g_set_error (error, KEYFILE_PLUGIN_ERROR, 0,
		             "File permissions (%o) or owner (%d) were insecure",
		             statbuf.st_mode, statbuf.st_uid);
		return NULL;
	}

	key_file = g_key_file_new ();
	if (!g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, error))
		goto out;

	connection = nm_connection_new ();

	groups = g_key_file_get_groups (key_file, &length);
	for (i = 0; i < length; i++) {
		/* Only read out secrets when needed */
		if (!strcmp (groups[i], VPN_SECRETS_GROUP)) {
			vpn_secrets = TRUE;
			continue;
		}

		setting = read_setting (key_file, filename, groups[i]);
		if (setting)
			nm_connection_add_setting (connection, setting);
	}

	/* Make sure that we have the base device type setting even if
	 * the keyfile didn't include it, which can happen when the base
	 * device type setting is all default values (like ethernet).
	 */
	s_con = nm_connection_get_setting_connection (connection);
	if (s_con) {
		ctype = nm_setting_connection_get_connection_type (s_con);
		setting = nm_connection_get_setting_by_name (connection, ctype);
		if (ctype) {
			if (!setting && !strcmp (ctype, NM_SETTING_WIRED_SETTING_NAME))
				nm_connection_add_setting (connection, nm_setting_wired_new ());
		}
	}

	/* Handle vpn secrets after the 'vpn' setting was read */
	if (vpn_secrets) {
		NMSettingVPN *s_vpn;

		s_vpn = nm_connection_get_setting_vpn (connection);
		if (s_vpn)
			read_vpn_secrets (key_file, s_vpn);
	}

	g_strfreev (groups);

	/* Verify the connection */
	if (!nm_connection_verify (connection, &verify_error)) {
		g_set_error (error, KEYFILE_PLUGIN_ERROR, 0,
			         "invalid or missing connection property '%s/%s'",
			         verify_error ? g_type_name (nm_connection_lookup_setting_type_by_quark (verify_error->domain)) : "(unknown)",
			         (verify_error && verify_error->message) ? verify_error->message : "(unknown)");
		g_clear_error (&verify_error);
		g_object_unref (connection);
		connection = NULL;
		g_warning ("Connection failed to verify: %s",
			verify_error ? g_type_name (nm_connection_lookup_setting_type_by_quark (verify_error->domain)) : "(unknown)");
	}

out:
	g_key_file_free (key_file);
	return connection;
}
コード例 #15
0
static void
mobile_wizard_done (NMAMobileWizard *wizard,
                    gboolean cancelled,
                    NMAMobileWizardAccessMethod *method,
                    gpointer user_data)
{
	AutoWizardInfo *info = user_data;
	NMConnection *connection = NULL;

	if (!cancelled && method) {
		NMSetting *setting;
		char *uuid, *id;
		const char *setting_name;

		if (method->devtype != info->requested_capability) {
			g_warning ("Unexpected device type");
			cancelled = TRUE;
			goto done;
		}

		connection = nm_connection_new ();

		if (method->devtype == NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO) {
			setting_name = NM_SETTING_CDMA_SETTING_NAME;
			setting = nm_setting_cdma_new ();
			g_object_set (setting,
			              NM_SETTING_CDMA_NUMBER, "#777",
			              NM_SETTING_CDMA_USERNAME, method->username,
			              NM_SETTING_CDMA_PASSWORD, method->password,
			              NM_SETTING_CDMA_PASSWORD_FLAGS, NM_SETTING_SECRET_FLAG_AGENT_OWNED,
			              NULL);
			nm_connection_add_setting (connection, setting);
		} else if (method->devtype == NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) {
			setting_name = NM_SETTING_GSM_SETTING_NAME;
			setting = nm_setting_gsm_new ();
			g_object_set (setting,
			              NM_SETTING_GSM_NUMBER, "*99#",
			              NM_SETTING_GSM_USERNAME, method->username,
			              NM_SETTING_GSM_PASSWORD, method->password,
			              NM_SETTING_GSM_APN, method->gsm_apn,
			              NM_SETTING_GSM_PASSWORD_FLAGS, NM_SETTING_SECRET_FLAG_AGENT_OWNED,
			              NULL);
			nm_connection_add_setting (connection, setting);
		} else
			g_assert_not_reached ();

		/* Serial setting */
		setting = nm_setting_serial_new ();
		g_object_set (setting,
		              NM_SETTING_SERIAL_BAUD, 115200,
		              NM_SETTING_SERIAL_BITS, 8,
		              NM_SETTING_SERIAL_PARITY, 'n',
		              NM_SETTING_SERIAL_STOPBITS, 1,
		              NULL);
		nm_connection_add_setting (connection, setting);

		nm_connection_add_setting (connection, nm_setting_ppp_new ());

		setting = nm_setting_connection_new ();
		id = utils_create_mobile_connection_id (method->provider_name, method->plan_name);
		uuid = nm_utils_uuid_generate ();
		g_object_set (setting,
		              NM_SETTING_CONNECTION_ID, id,
		              NM_SETTING_CONNECTION_TYPE, setting_name,
		              NM_SETTING_CONNECTION_AUTOCONNECT, FALSE,
		              NM_SETTING_CONNECTION_UUID, uuid,
		              NULL);
		g_free (uuid);
		g_free (id);
		nm_setting_connection_add_permission ((NMSettingConnection *) setting, "user", g_get_user_name (), NULL);
		nm_connection_add_setting (connection, setting);
	}

done:
	(*(info->callback)) (connection, TRUE, cancelled, info->callback_data);

	if (wizard)
		nma_mobile_wizard_destroy (wizard);
	g_free (info);
}
コード例 #16
0
static void
dialog_response (GtkDialog *dialog,
                 gint response,
                 gpointer user_data)
{
    NMAWirelessDialog *self = NMA_WIRELESS_DIALOG (user_data);
    NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
    NMSetting *setting;
    GtkTreeModel *model;
    GtkTreeIter iter;
    WirelessSecurity *sec = NULL;

    if (response != GTK_RESPONSE_OK)
        goto out;

    if (!priv->connection) {
        /* Create new connection */
        char *id;
        char *uuid;
        GByteArray *ssid;

        priv->connection = nm_connection_new ();

        /* Wireless setting */
        setting = nm_setting_wireless_new ();
        ssid = validate_dialog_ssid (self);
        g_object_set (setting, NM_SETTING_WIRELESS_SSID, ssid, NULL);
        nm_connection_add_setting (priv->connection, setting);

        if (ssid) {
            id = nm_utils_ssid_to_utf8 ((char *) ssid->data, ssid->len);
            g_byte_array_free (ssid, TRUE);
        } else
            id = NULL;

        /* Connection setting */
        setting = nm_setting_connection_new ();
        uuid = nm_utils_uuid_generate ();

        /* FIXME: don't autoconnect until the connection is successful at least once */
        /* Don't autoconnect adhoc networks by default for now */
        g_object_set (setting,
                      NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME,
                      NM_SETTING_CONNECTION_UUID, uuid,
                      NM_SETTING_CONNECTION_ID, id,
                      NM_SETTING_CONNECTION_AUTOCONNECT, !priv->adhoc_create,
                      NULL);

        g_free (uuid);
        g_free (id);
        nm_connection_add_setting (priv->connection, setting);

        /* IPv4 setting */
        if (priv->adhoc_create) {
            g_object_set (setting, NM_SETTING_WIRELESS_MODE, "adhoc", NULL);

            setting = nm_setting_ip4_config_new ();
            g_object_set (setting,
                          NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_SHARED,
                          NULL);

            nm_connection_add_setting (priv->connection, setting);
        }
    }

    model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->sec_combo));
    gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->sec_combo), &iter);
    gtk_tree_model_get (model, &iter, S_SEC_COLUMN, &sec, -1);

    if (sec && !priv->nag_ignored) {
        GtkWidget *nag_dialog;

        /* Nag the user about certificates or whatever.  Only destroy the dialog
         * if no nagging was done.
         */
        nag_dialog = wireless_security_nag_user (sec);
        if (nag_dialog) {
            gtk_window_set_transient_for (GTK_WINDOW (nag_dialog), GTK_WINDOW (dialog));
            g_signal_connect (nag_dialog, "response",
                              G_CALLBACK (nag_dialog_response_cb),
                              dialog);
            return;
        }
    }

    /* Fill security */
    if (sec) {
        wireless_security_fill_connection (sec, priv->connection);
        wireless_security_unref (sec);
    } else {
        /* Unencrypted */
        setting = nm_connection_get_setting (priv->connection, NM_TYPE_SETTING_WIRELESS);
        g_object_set (setting, NM_SETTING_WIRELESS_SEC, NULL, NULL);
    }

 out:
    g_signal_emit (self, signals[DONE], 0, response);
    nm_utils_dialog_done ();

    /* FIXME: clear security? */
}
コード例 #17
0
static void
gsm_mobile_wizard_done (NMAMobileWizard *wizard,
                        gboolean canceled,
                        NMAMobileWizardAccessMethod *method,
                        gpointer user_data)
{
    NMConnection *connection = NULL;

    if (!canceled && method) {
        NMSetting *setting;
        char *uuid, *id;

        if (method->devtype != NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) {
            g_warning ("Unexpected device type (not GSM).");
            canceled = TRUE;
            goto done;
        }

        connection = nm_connection_new ();

        setting = nm_setting_gsm_new ();
        g_object_set (setting,
                      NM_SETTING_GSM_NUMBER, "*99#",
                      NM_SETTING_GSM_USERNAME, method->username,
                      NM_SETTING_GSM_PASSWORD, method->password,
                      NM_SETTING_GSM_APN, method->gsm_apn,
                      NULL);
        nm_connection_add_setting (connection, setting);

        /* Serial setting */
        setting = nm_setting_serial_new ();
        g_object_set (setting,
                      NM_SETTING_SERIAL_BAUD, 115200,
                      NM_SETTING_SERIAL_BITS, 8,
                      NM_SETTING_SERIAL_PARITY, 'n',
                      NM_SETTING_SERIAL_STOPBITS, 1,
                      NULL);
        nm_connection_add_setting (connection, setting);

        nm_connection_add_setting (connection, nm_setting_ppp_new ());

        setting = nm_setting_connection_new ();
        if (method->plan_name)
            id = g_strdup_printf ("%s %s", method->provider_name, method->plan_name);
        else
            id = g_strdup_printf ("%s connection", method->provider_name);
        uuid = nm_utils_uuid_generate ();
        g_object_set (setting,
                      NM_SETTING_CONNECTION_ID, id,
                      NM_SETTING_CONNECTION_TYPE, NM_SETTING_GSM_SETTING_NAME,
                      NM_SETTING_CONNECTION_AUTOCONNECT, FALSE,
                      NM_SETTING_CONNECTION_UUID, uuid,
                      NULL);
        g_free (uuid);
        g_free (id);
        nm_connection_add_setting (connection, setting);
    }

done:
    connect_3g (connection, canceled, user_data);
    nma_mobile_wizard_destroy (wizard);
}
コード例 #18
0
void
cc_network_panel_connect_to_8021x_network (CcNetworkPanel   *panel,
        NMClient         *client,
        NMRemoteSettings *settings,
        NMDevice         *device,
        const gchar      *arg_access_point)
{
    NMConnection *connection;
    NMSettingConnection *s_con;
    NMSettingWireless *s_wifi;
    NMSettingWirelessSecurity *s_wsec;
    NMSetting8021x *s_8021x;
    NM80211ApSecurityFlags wpa_flags, rsn_flags;
    GtkWidget *dialog;
    char *uuid;
    NMAccessPoint *ap;

    g_debug ("connect to 8021x wifi");
    ap = nm_device_wifi_get_access_point_by_path (NM_DEVICE_WIFI (device), arg_access_point);
    if (ap == NULL) {
        g_warning ("didn't find access point with path %s", arg_access_point);
        return;
    }

    /* If the AP is WPA[2]-Enterprise then we need to set up a minimal 802.1x
    * setting and ask the user for more information.
     */
    rsn_flags = nm_access_point_get_rsn_flags (ap);
    wpa_flags = nm_access_point_get_wpa_flags (ap);
    if (!(rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)
            && !(wpa_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)) {
        g_warning ("Network panel loaded with connect-8021x-wifi but the "
                   "access point does not support 802.1x");
        return;
    }

    connection = nm_connection_new ();

    /* Need a UUID for the "always ask" stuff in the Dialog of Doom */
    s_con = (NMSettingConnection *) nm_setting_connection_new ();
    uuid = nm_utils_uuid_generate ();
    g_object_set (s_con, NM_SETTING_CONNECTION_UUID, uuid, NULL);
    g_free (uuid);
    nm_connection_add_setting (connection, NM_SETTING (s_con));

    s_wifi = (NMSettingWireless *) nm_setting_wireless_new ();
    nm_connection_add_setting (connection, NM_SETTING (s_wifi));
    g_object_set (s_wifi,
                  NM_SETTING_WIRELESS_SSID, nm_access_point_get_ssid (ap),
                  NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
                  NULL);

    s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
    g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-eap", NULL);
    nm_connection_add_setting (connection, NM_SETTING (s_wsec));

    s_8021x = (NMSetting8021x *) nm_setting_802_1x_new ();
    nm_setting_802_1x_add_eap_method (s_8021x, "ttls");
    g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_AUTH, "mschapv2", NULL);
    nm_connection_add_setting (connection, NM_SETTING (s_8021x));

    dialog = nma_wireless_dialog_new (client, settings, connection, device, ap, FALSE);
    show_wireless_dialog (panel, client, settings, dialog);
}
コード例 #19
0
ファイル: pam_8021x.c プロジェクト: ehbello/pam-8021x
static void
add_connection (pam_handle_t *pamh, DBusGProxy *proxy, const char *con_name, 
  const char *con_identity,
  const char *con_pwd)
{
  NMConnection *connection;
  NMSettingConnection *s_con;
  NMSettingWired *s_wired;
  NMSetting8021x *s_8021x;
  NMSettingIP4Config *s_ip4;
  char *uuid, *new_con_path = NULL;
  GHashTable *hash;
  GError *error = NULL;

  /* Create a new connection object */
  if (debug)
  {
    pam_syslog (pamh, LOG_INFO, "Creating new connection object.");
  }
  connection = (NMConnection *) nm_connection_new ();

  /* Build up the 'connection' Setting */
  if (debug)
  {
    pam_syslog (pamh, LOG_INFO, "Building up the 'connection' setting.");
  }
  s_con = (NMSettingConnection *) nm_setting_connection_new ();
  uuid = nm_utils_uuid_generate ();
  g_object_set (G_OBJECT (s_con),
    NM_SETTING_CONNECTION_UUID, uuid,
    NM_SETTING_CONNECTION_ID, con_name,
    NM_SETTING_CONNECTION_TYPE, "802-3-ethernet",
    NULL);
  g_free (uuid);
  nm_connection_add_setting (connection, NM_SETTING (s_con));

  /* Build up the 'wired' Setting */
  if (debug)
  {
    pam_syslog (pamh, LOG_INFO, "Building up the 'wired' setting.");
  }
  s_wired = (NMSettingWired *) nm_setting_wired_new ();
  nm_connection_add_setting (connection, NM_SETTING (s_wired));

  /* Build up the '8021x' Setting */
  if (debug)
  {
    pam_syslog (pamh, LOG_INFO, "Building up the '8021x' setting.");
  }
  s_8021x = (NMSetting8021x *) nm_setting_802_1x_new ();
  g_object_set (G_OBJECT (s_8021x),
    NM_SETTING_802_1X_SYSTEM_CA_CERTS, TRUE,
    NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD_FLAGS, TRUE,
    NM_SETTING_802_1X_ANONYMOUS_IDENTITY, "*****@*****.**",
    NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD_FLAGS, TRUE,
    NM_SETTING_802_1X_IDENTITY, con_identity,
    NM_SETTING_802_1X_PHASE2_AUTH, "mschapv2",
    NM_SETTING_802_1X_PASSWORD, con_pwd,
    NULL);
  nm_setting_802_1x_add_phase2_altsubject_match(s_8021x, "DNS:radius.example.com");
  nm_setting_802_1x_add_eap_method(s_8021x, "peap");
  nm_connection_add_setting (connection, NM_SETTING (s_8021x));

  /* Build up the 'ipv4' Setting */
  if (debug)
  {
    pam_syslog (pamh, LOG_INFO, "Building up the 'ipv4' setting.");
  }
  s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
  g_object_set (G_OBJECT (s_ip4),
    NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
    NULL);
  nm_connection_add_setting (connection, NM_SETTING (s_ip4));

  hash = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL);

  /* Call AddConnection with the hash as argument */
  if (debug)
  {
    pam_syslog (pamh, LOG_INFO, "Calling AddConnection D-BUS method.");
  }
  if (!dbus_g_proxy_call (proxy, "AddConnection", &error,
    DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, hash,
    G_TYPE_INVALID,
    DBUS_TYPE_G_OBJECT_PATH, &new_con_path,
    G_TYPE_INVALID)) {
      g_print ("Error adding connection: %s %s",
      dbus_g_error_get_name (error),
      error->message);
      pam_syslog (pamh, LOG_ERR, "Error adding connection: %s %s",
      dbus_g_error_get_name (error),
      error->message);
    g_clear_error (&error);
  } else {
    g_print ("Added: %s\n", new_con_path);
    pam_syslog (pamh, LOG_ERR, "Added: %s\n", new_con_path);
    g_free (new_con_path);
  }

  g_hash_table_destroy (hash);
  g_object_unref (connection);
}
static void
test_wifi_wpa_psk (const char *detail,
                   OptType key_type,
                   const char *key_data,
                   const unsigned char *expected,
                   size_t expected_size)
{
	NMConnection *connection;
	NMSettingConnection *s_con;
	NMSettingWireless *s_wifi;
	NMSettingWirelessSecurity *s_wsec;
	NMSettingIP4Config *s_ip4;
	NMSupplicantConfig *config;
	GHashTable *hash;
	char *uuid;
	gboolean success;
	GError *error = NULL;
	GByteArray *ssid;
	const unsigned char ssid_data[] = { 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44 };
	GByteArray *bssid;
	const unsigned char bssid_data[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };
	const char *bssid_str = "11:22:33:44:55:66";

	connection = nm_connection_new ();
	ASSERT (connection != NULL,
	        detail, "failed to allocate new connection");

	/* Connection setting */
	s_con = (NMSettingConnection *) nm_setting_connection_new ();
	ASSERT (s_con != NULL,
	        detail, "failed to allocate new %s setting",
	        NM_SETTING_CONNECTION_SETTING_NAME);
	nm_connection_add_setting (connection, NM_SETTING (s_con));

	uuid = nm_utils_uuid_generate ();
	g_object_set (s_con,
	              NM_SETTING_CONNECTION_ID, "Test Wifi WEP Key",
	              NM_SETTING_CONNECTION_UUID, uuid,
	              NM_SETTING_CONNECTION_AUTOCONNECT, TRUE,
	              NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME,
	              NULL);
	g_free (uuid);

	/* Wifi setting */
	s_wifi = (NMSettingWireless *) nm_setting_wireless_new ();
	ASSERT (s_wifi != NULL,
	        detail, "failed to allocate new %s setting",
	        NM_SETTING_WIRELESS_SETTING_NAME);
	nm_connection_add_setting (connection, NM_SETTING (s_wifi));

	ssid = g_byte_array_sized_new (sizeof (ssid_data));
	g_byte_array_append (ssid, ssid_data, sizeof (ssid_data));
	bssid = g_byte_array_sized_new (sizeof (bssid_data));
	g_byte_array_append (bssid, bssid_data, sizeof (bssid_data));

	g_object_set (s_wifi,
	              NM_SETTING_WIRELESS_SSID, ssid,
	              NM_SETTING_WIRELESS_BSSID, bssid,
	              NM_SETTING_WIRELESS_MODE, "infrastructure",
	              NM_SETTING_WIRELESS_BAND, "bg",
	              NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
	              NULL);

	g_byte_array_free (ssid, TRUE);
	g_byte_array_free (bssid, TRUE);

	/* Wifi Security setting */
	s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
	ASSERT (s_wsec != NULL,
	        detail, "failed to allocate new %s setting",
	        NM_SETTING_WIRELESS_SECURITY_SETTING_NAME);
	nm_connection_add_setting (connection, NM_SETTING (s_wsec));

	g_object_set (s_wsec,
	              NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-psk",
	              NM_SETTING_WIRELESS_SECURITY_PSK, key_data,
	              NULL);

	nm_setting_wireless_security_add_proto (s_wsec, "wpa");
	nm_setting_wireless_security_add_proto (s_wsec, "rsn");
	nm_setting_wireless_security_add_pairwise (s_wsec, "tkip");
	nm_setting_wireless_security_add_pairwise (s_wsec, "ccmp");
	nm_setting_wireless_security_add_group (s_wsec, "tkip");
	nm_setting_wireless_security_add_group (s_wsec, "ccmp");

	/* IP4 setting */
	s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
	ASSERT (s_ip4 != NULL,
	        detail, "failed to allocate new %s setting",
	        NM_SETTING_IP4_CONFIG_SETTING_NAME);
	nm_connection_add_setting (connection, NM_SETTING (s_ip4));

	g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);

	ASSERT (nm_connection_verify (connection, &error) == TRUE,
	        detail, "failed to verify connection: %s",
	        (error && error->message) ? error->message : "(unknown)");

	config = nm_supplicant_config_new ();
	ASSERT (config != NULL,
	        detail, "failed to create new supplicant config");

	success = nm_supplicant_config_add_setting_wireless (config, s_wifi, TRUE, 0, TRUE);
	ASSERT (success == TRUE,
	        detail, "failed to add wireless setting to supplicant config.");

	success = nm_supplicant_config_add_setting_wireless_security (config,
	                                                              s_wsec,
	                                                              NULL,
	                                                              "376aced7-b28c-46be-9a62-fcdf072571da");
	ASSERT (success == TRUE,
	        detail, "failed to add wireless security to supplicant config.");

	hash = nm_supplicant_config_get_hash (config);
	ASSERT (hash != NULL,
	        detail, "failed to hash supplicant config options.");

	validate_opt (detail, hash, "scan_ssid", TYPE_INT, GINT_TO_POINTER (1), -1);
	validate_opt (detail, hash, "ssid", TYPE_BYTES, ssid_data, sizeof (ssid_data));
	validate_opt (detail, hash, "bssid", TYPE_KEYWORD, bssid_str, -1);
	validate_opt (detail, hash, "key_mgmt", TYPE_KEYWORD, "WPA-PSK", -1);
	validate_opt (detail, hash, "proto", TYPE_KEYWORD, "WPA RSN", -1);
	validate_opt (detail, hash, "pairwise", TYPE_KEYWORD, "TKIP CCMP", -1);
	validate_opt (detail, hash, "group", TYPE_KEYWORD, "TKIP CCMP", -1);
	validate_opt (detail, hash, "psk", key_type, expected, expected_size);

	g_object_unref (connection);
}
static void
test_wifi_open (void)
{
	NMConnection *connection;
	NMSettingConnection *s_con;
	NMSettingWireless *s_wifi;
	NMSettingIP4Config *s_ip4;
	NMSupplicantConfig *config;
	GHashTable *hash;
	char *uuid;
	gboolean success;
	GError *error = NULL;
	GByteArray *ssid;
	const unsigned char ssid_data[] = { 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44 };
	GByteArray *bssid;
	const unsigned char bssid_data[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };
	const char *bssid_str = "11:22:33:44:55:66";

	connection = nm_connection_new ();
	ASSERT (connection != NULL,
	        "wifi-open", "failed to allocate new connection");

	/* Connection setting */
	s_con = (NMSettingConnection *) nm_setting_connection_new ();
	ASSERT (s_con != NULL,
	        "wifi-open", "failed to allocate new %s setting",
	        NM_SETTING_CONNECTION_SETTING_NAME);
	nm_connection_add_setting (connection, NM_SETTING (s_con));

	uuid = nm_utils_uuid_generate ();
	g_object_set (s_con,
	              NM_SETTING_CONNECTION_ID, "Test Wifi Open",
	              NM_SETTING_CONNECTION_UUID, uuid,
	              NM_SETTING_CONNECTION_AUTOCONNECT, TRUE,
	              NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME,
	              NULL);
	g_free (uuid);

	/* Wifi setting */
	s_wifi = (NMSettingWireless *) nm_setting_wireless_new ();
	ASSERT (s_wifi != NULL,
	        "wifi-open", "failed to allocate new %s setting",
	        NM_SETTING_WIRELESS_SETTING_NAME);
	nm_connection_add_setting (connection, NM_SETTING (s_wifi));

	ssid = g_byte_array_sized_new (sizeof (ssid_data));
	g_byte_array_append (ssid, ssid_data, sizeof (ssid_data));
	bssid = g_byte_array_sized_new (sizeof (bssid_data));
	g_byte_array_append (bssid, bssid_data, sizeof (bssid_data));

	g_object_set (s_wifi,
	              NM_SETTING_WIRELESS_SSID, ssid,
	              NM_SETTING_WIRELESS_BSSID, bssid,
	              NM_SETTING_WIRELESS_MODE, "infrastructure",
	              NM_SETTING_WIRELESS_BAND, "bg",
	              NULL);

	g_byte_array_free (ssid, TRUE);
	g_byte_array_free (bssid, TRUE);

	/* IP4 setting */
	s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
	ASSERT (s_ip4 != NULL,
	        "wifi-open", "failed to allocate new %s setting",
	        NM_SETTING_IP4_CONFIG_SETTING_NAME);
	nm_connection_add_setting (connection, NM_SETTING (s_ip4));

	g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);

	ASSERT (nm_connection_verify (connection, &error) == TRUE,
	        "wifi-open", "failed to verify connection: %s",
	        (error && error->message) ? error->message : "(unknown)");

	config = nm_supplicant_config_new ();
	ASSERT (config != NULL,
	        "wifi-open", "failed to create new supplicant config");

	success = nm_supplicant_config_add_setting_wireless (config, s_wifi, TRUE, 0, TRUE);
	ASSERT (success == TRUE,
	        "wifi-open", "failed to add wireless setting to supplicant config.");

	success = nm_supplicant_config_add_no_security (config);
	ASSERT (success == TRUE,
	        "wifi-open", "failed to add wireless security to supplicant config.");

	hash = nm_supplicant_config_get_hash (config);
	ASSERT (hash != NULL,
	        "wifi-open", "failed to hash supplicant config options.");

	validate_opt ("wifi-open", hash, "scan_ssid", TYPE_INT, GINT_TO_POINTER (1), -1);
	validate_opt ("wifi-open", hash, "ssid", TYPE_BYTES, ssid_data, sizeof (ssid_data));
	validate_opt ("wifi-open", hash, "bssid", TYPE_KEYWORD, bssid_str, -1);
	validate_opt ("wifi-open", hash, "key_mgmt", TYPE_KEYWORD, "NONE", -1);

	g_object_unref (connection);
}
コード例 #22
0
void WifiStatusNM::setConnectedAccessPoint(WifiAccessPoint *ap, String psk) {
  ScopedPointer<StringArray> cmd;

  for (const auto& listener : listeners)
    listener->handleWifiBusy();

  // disconnect if no ap provided
  if (ap == nullptr) {
    NMActiveConnection *conn = nm_device_get_active_connection(nmdevice);
    removeNMConnection(nmdevice, conn);

    return;
  }
  // try to connect to ap, dispatch events on success and failure
  else {
    NMConnection *connection = NULL;
    NMSettingWireless *s_wifi = NULL;
    NMSettingWirelessSecurity *s_wsec = NULL;
    const char *nm_ap_path = NULL;
    const GPtrArray *ap_list;
    NMAccessPoint *candidate_ap;

    //FIXME: expand WifiAccessPoint struct to know which NMAccessPoint it is
    ap_list = nm_device_wifi_get_access_points(NM_DEVICE_WIFI(nmdevice));
    if (ap_list == NULL)
      return;

    for (int i = 0; i < ap_list->len; i++) {
      const char *candidate_hash;
      candidate_ap = (NMAccessPoint *) g_ptr_array_index(ap_list, i);
      candidate_hash = utils_hash_ap(nm_access_point_get_ssid(candidate_ap),
                                     nm_access_point_get_mode(candidate_ap),
                                     nm_access_point_get_flags(candidate_ap),
                                     nm_access_point_get_wpa_flags(candidate_ap),
                                     nm_access_point_get_rsn_flags(candidate_ap));

      if (ap->hash == candidate_hash) {
        nm_ap_path = nm_object_get_path(NM_OBJECT(candidate_ap));
        break;
      }
    }

    if (!nm_ap_path)
      return;

    connecting = true;

    connection = nm_connection_new();
    s_wifi = (NMSettingWireless *) nm_setting_wireless_new();
    nm_connection_add_setting(connection, NM_SETTING(s_wifi));
    g_object_set(s_wifi,
                 NM_SETTING_WIRELESS_SSID, nm_access_point_get_ssid(candidate_ap),
                 NM_SETTING_WIRELESS_HIDDEN, false,
                 NULL);

    if (!psk.isEmpty()) {
      s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new();
      nm_connection_add_setting(connection, NM_SETTING(s_wsec));

      if (nm_access_point_get_wpa_flags(candidate_ap) == NM_802_11_AP_SEC_NONE &&
          nm_access_point_get_rsn_flags(candidate_ap) == NM_802_11_AP_SEC_NONE) {
        /* WEP */
        nm_setting_wireless_security_set_wep_key(s_wsec, 0, psk.toRawUTF8());
	if (isValidWEPKeyFormat(psk))
          g_object_set(G_OBJECT(s_wsec), NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE,
                       NM_WEP_KEY_TYPE_KEY, NULL);
	else if (isValidWEPPassphraseFormat(psk))
          g_object_set(G_OBJECT(s_wsec), NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE,
                       NM_WEP_KEY_TYPE_PASSPHRASE, NULL);
	else
	  DBG("User input invalid WEP Key type, psk.length() = " << psk.length()
              << ", not in [5,10,13,26]");
      } else {
        g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_PSK, psk.toRawUTF8(), NULL);
      }
    }

    nm_client_add_and_activate_connection(nmclient,
                                                connection,
                                                nmdevice,
                                                nm_ap_path,
                                                handle_add_and_activate_finish,
                                                this);
  }
}
コード例 #23
0
static NMConnection *
import (NMVpnPluginUiInterface *iface, const char *path, GError **error)
{
	NMConnection *connection;
	NMSettingConnection *s_con;
	NMSettingVPN *s_vpn;
	NMSettingIP4Config *s_ip4;
	GKeyFile *keyfile;
	GKeyFileFlags flags;
	const char *buf;
	gboolean bval;

	keyfile = g_key_file_new ();
	flags = G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS;

	if (!g_key_file_load_from_file (keyfile, path, flags, NULL)) {
		g_set_error (error,
		             NM_OPENCONNECT_IMPORT_EXPORT_ERROR,
		             NM_OPENCONNECT_IMPORT_EXPORT_ERROR_NOT_OPENCONNECT,
		             "does not look like a %s VPN connection (parse failed)",
		             OPENCONNECT_PLUGIN_NAME);
		return NULL;
	}

	connection = nm_connection_new ();
	s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
	nm_connection_add_setting (connection, NM_SETTING (s_con));

	s_vpn = NM_SETTING_VPN (nm_setting_vpn_new ());
	g_object_set (s_vpn, NM_SETTING_VPN_SERVICE_TYPE, NM_DBUS_SERVICE_OPENCONNECT, NULL);
	nm_connection_add_setting (connection, NM_SETTING (s_vpn));

	s_ip4 = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ());
	nm_connection_add_setting (connection, NM_SETTING (s_ip4));

	/* Host */
	buf = g_key_file_get_string (keyfile, "openconnect", "Host", NULL);
	if (buf) {
		nm_setting_vpn_add_data_item (s_vpn, NM_OPENCONNECT_KEY_GATEWAY, buf);
	} else {
		g_set_error (error,
		             NM_OPENCONNECT_IMPORT_EXPORT_ERROR,
		             NM_OPENCONNECT_IMPORT_EXPORT_ERROR_BAD_DATA,
		             "does not look like a %s VPN connection (no Host)",
		             OPENCONNECT_PLUGIN_NAME);
		g_object_unref (connection);
		return NULL;
	}

	/* Optional Settings */

	/* Description */
	buf = g_key_file_get_string (keyfile, "openconnect", "Description", NULL);
	if (buf)
		g_object_set (s_con, NM_SETTING_CONNECTION_ID, buf, NULL);

	/* CA Certificate */
	buf = g_key_file_get_string (keyfile, "openconnect", "CACert", NULL);
	if (buf)
		nm_setting_vpn_add_data_item (s_vpn, NM_OPENCONNECT_KEY_CACERT, buf);

	/* Proxy */
	buf = g_key_file_get_string (keyfile, "openconnect", "Proxy", NULL);
	if (buf)
		nm_setting_vpn_add_data_item (s_vpn, NM_OPENCONNECT_KEY_PROXY, buf);

	/* Cisco Secure Desktop */
	bval = g_key_file_get_boolean (keyfile, "openconnect", "CSDEnable", NULL);
	if (bval)
		nm_setting_vpn_add_data_item (s_vpn, NM_OPENCONNECT_KEY_CSD_ENABLE, "yes");

	/* Cisco Secure Desktop wrapper */
	buf = g_key_file_get_string (keyfile, "openconnect", "CSDWrapper", NULL);
	if (buf)
		nm_setting_vpn_add_data_item (s_vpn, NM_OPENCONNECT_KEY_CSD_WRAPPER, buf);

	/* User Certificate */
	buf = g_key_file_get_string (keyfile, "openconnect", "UserCertificate", NULL);
	if (buf)
		nm_setting_vpn_add_data_item (s_vpn, NM_OPENCONNECT_KEY_USERCERT, buf);

	/* Private Key */
	buf = g_key_file_get_string (keyfile, "openconnect", "PrivateKey", NULL);
	if (buf)
		nm_setting_vpn_add_data_item (s_vpn, NM_OPENCONNECT_KEY_PRIVKEY, buf);

	/* FSID */
	bval = g_key_file_get_boolean (keyfile, "openconnect", "FSID", NULL);
	if (bval)
		nm_setting_vpn_add_data_item (s_vpn, NM_OPENCONNECT_KEY_PEM_PASSPHRASE_FSID, "yes");

	/* Soft token mode */
	buf = g_key_file_get_string (keyfile, "openconnect", "StokenSource", NULL);
	if (buf)
		nm_setting_vpn_add_data_item (s_vpn, NM_OPENCONNECT_KEY_TOKEN_MODE, buf);

	/* Soft token secret */
	buf = g_key_file_get_string (keyfile, "openconnect", "StokenString", NULL);
	if (buf)
		nm_setting_vpn_add_secret (s_vpn, NM_OPENCONNECT_KEY_TOKEN_SECRET, buf);

	return connection;
}