Ejemplo n.º 1
0
static void
remove_connection (SettingsPluginIfcfg *self, NMIfcfgConnection *connection)
{
	SettingsPluginIfcfgPrivate *priv = SETTINGS_PLUGIN_IFCFG_GET_PRIVATE (self);
	gboolean unmanaged, unrecognized;

	g_return_if_fail (self != NULL);
	g_return_if_fail (connection != NULL);

	_LOGI ("remove "NM_IFCFG_CONNECTION_LOG_FMT, NM_IFCFG_CONNECTION_LOG_ARG (connection));

	unmanaged = !!nm_ifcfg_connection_get_unmanaged_spec (connection);
	unrecognized = !!nm_ifcfg_connection_get_unrecognized_spec (connection);

	g_object_ref (connection);
	g_hash_table_remove (priv->connections, nm_connection_get_uuid (NM_CONNECTION (connection)));
	if (!unmanaged && !unrecognized)
		nm_settings_connection_signal_remove (NM_SETTINGS_CONNECTION (connection));
	g_object_unref (connection);

	/* Emit changes _after_ removing the connection */
	if (unmanaged)
		g_signal_emit_by_name (self, NM_SETTINGS_PLUGIN_UNMANAGED_SPECS_CHANGED);
	if (unrecognized)
		g_signal_emit_by_name (self, NM_SETTINGS_PLUGIN_UNRECOGNIZED_SPECS_CHANGED);
}
static gboolean
get_parent_iter_for_connection (NMConnectionList *list,
                                NMRemoteConnection *connection,
                                GtkTreeIter *iter)
{
	NMSettingConnection *s_con;
	const char *str_type;
	GType type, row_type;

	s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection));
	g_assert (s_con);
	str_type = nm_setting_connection_get_connection_type (s_con);
	if (!str_type) {
		g_warning ("Ignoring incomplete connection");
		return FALSE;
	}

	if (!strcmp (str_type, NM_SETTING_CDMA_SETTING_NAME))
		str_type = NM_SETTING_GSM_SETTING_NAME;
	type = nm_connection_lookup_setting_type (str_type);

	if (gtk_tree_model_get_iter_first (list->model, iter)) {
		do {
			gtk_tree_model_get (list->model, iter,
			                    COL_GTYPE, &row_type,
			                    -1);
			if (row_type == type)
				return TRUE;
		} while (gtk_tree_model_iter_next (list->model, iter));
	}

	g_warning ("Unsupported connection type '%s'", str_type);
	return FALSE;
}
static void
delete_slaves_of_connection (NMConnectionList *list, NMConnection *connection)
{
	const char *uuid, *iface;
	GtkTreeIter iter, types_iter;

	if (!gtk_tree_model_get_iter_first (list->model, &types_iter))
		return;

	uuid = nm_connection_get_uuid (connection);
	iface = nm_connection_get_virtual_iface_name (connection);

	do {
		if (!gtk_tree_model_iter_children (list->model, &iter, &types_iter))
			continue;

		do {
			NMRemoteConnection *candidate = NULL;
			NMSettingConnection *s_con;
			const char *master;

			gtk_tree_model_get (list->model, &iter,
			                    COL_CONNECTION, &candidate,
			                    -1);
			s_con = nm_connection_get_setting_connection (NM_CONNECTION (candidate));
			master = nm_setting_connection_get_master (s_con);
			if (master) {
				if (!g_strcmp0 (master, uuid) || !g_strcmp0 (master, iface))
					nm_remote_connection_delete (candidate, NULL, NULL);
			}

			g_object_unref (candidate);
		} while (gtk_tree_model_iter_next (list->model, &iter));
	} while (gtk_tree_model_iter_next (list->model, &types_iter));
}
static void
test_add_connection (void)
{
	NMConnection *connection;
	time_t start, now;
	gboolean done = FALSE;

	connection = nmtst_create_minimal_connection (TEST_CON_ID, NULL, NM_SETTING_WIRED_SETTING_NAME, NULL);

	nm_client_add_connection_async (client,
	                                connection,
	                                TRUE,
	                                NULL,
	                                add_cb,
	                                &done);

	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);
	g_object_unref (connection);
}
Ejemplo n.º 5
0
static void
added_cb (GObject *client,
          GAsyncResult *result,
          gpointer user_data)
{
	GMainLoop *loop = user_data;
	NMRemoteConnection *remote;
	GError *error;

	/* NM responded to our request; either handle the resulting error or
	 * print out the object path of the connection we just added.
	 */
	remote = nm_client_add_connection_finish (NM_CLIENT (client), result, &error);

	if (error) {
		g_print ("Error adding connection: %s", error->message);
		g_error_free (error);
	} else {
		g_print ("Added: %s\n", nm_connection_get_path (NM_CONNECTION (remote)));
		g_object_unref (remote);
	}

	/* Tell the mainloop we're done and we can quit now */
	g_main_loop_quit (loop);
}
char *
nm_device_ethernet_utils_get_default_wired_name (const GSList *connections)
{
	const GSList *iter;
	char *cname = NULL;
	int i = 0;

	/* Find the next available unique connection name */
	while (!cname && (i++ < 10000)) {
		char *temp;
		gboolean found = FALSE;

		temp = g_strdup_printf (_("Wired connection %d"), i);
		for (iter = connections; iter; iter = iter->next) {
			if (g_strcmp0 (nm_connection_get_id (NM_CONNECTION (iter->data)), temp) == 0) {
				found = TRUE;
				g_free (temp);
				break;
			}
		}

		if (found == FALSE)
			cname = temp;
	}

	return cname;
}
Ejemplo n.º 7
0
static NMConnection *
real_get_best_auto_connection (NMDevice *device,
                               GSList *connections,
                               char **specific_object)
{
	NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (device);
	GSList *iter;

	for (iter = connections; iter; iter = g_slist_next (iter)) {
		NMConnection *connection = NM_CONNECTION (iter->data);
		NMSettingConnection *s_con;
		guint32 bt_type;

		s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
		g_assert (s_con);

		if (!nm_setting_connection_get_autoconnect (s_con))
			continue;

		if (strcmp (nm_setting_connection_get_connection_type (s_con), NM_SETTING_BLUETOOTH_SETTING_NAME))
			continue;

		bt_type = get_connection_bt_type (connection);
		if (!(bt_type & priv->capabilities))
			continue;

		return connection;
	}
	return NULL;
}
Ejemplo n.º 8
0
static NMConnection *
connection_match_config (NMDevice *self, const GSList *connections)
{
	const GSList *iter;
	GSList *bridge_matches;
	NMConnection *match;

	/* First narrow @connections down to those that match in their
	 * NMSettingBridge configuration.
	 */
	bridge_matches = NULL;
	for (iter = connections; iter; iter = iter->next) {
		NMConnection *candidate = NM_CONNECTION (iter->data);

		if (!nm_connection_is_type (candidate, NM_SETTING_BRIDGE_SETTING_NAME))
			continue;
		if (!bridge_match_config (self, candidate))
			continue;

		bridge_matches = g_slist_prepend (bridge_matches, candidate);
	}

	/* Now pass those to the super method, which will check IP config */
	bridge_matches = g_slist_reverse (bridge_matches);
	match = NM_DEVICE_CLASS (nm_device_bridge_parent_class)->connection_match_config (self, bridge_matches);
	g_slist_free (bridge_matches);

	return match;
}
static void
show_details (GtkButton *button, NetDeviceEthernet *device, const gchar *title)
{
        GtkWidget *row;
        NMConnection *connection;
        GtkWidget *window;
        NetConnectionEditor *editor;
        NMClient *client;
        NMRemoteSettings *settings;
        NMDevice *nmdev;

        window = gtk_widget_get_toplevel (GTK_WIDGET (button));

        row = GTK_WIDGET (g_object_get_data (G_OBJECT (button), "row"));
        connection = NM_CONNECTION (g_object_get_data (G_OBJECT (row), "connection"));

        nmdev = net_device_get_nm_device (NET_DEVICE (device));
        client = net_object_get_client (NET_OBJECT (device));
        settings = net_object_get_remote_settings (NET_OBJECT (device));
        editor = net_connection_editor_new (GTK_WINDOW (window), connection, nmdev, NULL, client, settings);
        if (title)
                net_connection_editor_set_title (editor, title);
        g_signal_connect (editor, "done", G_CALLBACK (editor_done), device);
        net_connection_editor_run (editor);
}
static NMConnection *
get_best_auto_connection (NMDevice *device,
                          GSList *connections,
                          char **specific_object)
{
    NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (device);
    GSList *iter;

    for (iter = connections; iter; iter = g_slist_next (iter)) {
        NMConnection *connection = NM_CONNECTION (iter->data);
        guint32 bt_type;

        if (!nm_connection_is_type (connection, NM_SETTING_BLUETOOTH_SETTING_NAME))
            continue;

        bt_type = get_connection_bt_type (connection);
        if (!(bt_type & priv->capabilities))
            continue;

        /* Can't auto-activate a DUN connection without ModemManager */
        if (bt_type == NM_BT_CAPABILITY_DUN && priv->mm_running == FALSE)
            continue;

        return connection;
    }
    return NULL;
}
Ejemplo n.º 11
0
static char *
get_new_connection_name (const GSList *existing,
                         const char *preferred,
                         const char *fallback_prefix)
{
	GSList *names = NULL;
	const GSList *iter;
	char *cname = NULL;
	int i = 0;
	gboolean preferred_found = FALSE;

	g_assert (fallback_prefix);

	for (iter = existing; iter; iter = g_slist_next (iter)) {
		NMConnection *candidate = NM_CONNECTION (iter->data);
		const char *id;

		id = nm_connection_get_id (candidate);
		g_assert (id);
		names = g_slist_append (names, (gpointer) id);

		if (preferred && !preferred_found && (strcmp (preferred, id) == 0))
			preferred_found = TRUE;
	}

	/* Return the preferred name if it was unique */
	if (preferred && !preferred_found) {
		g_slist_free (names);
		return g_strdup (preferred);
	}

	/* Otherwise find the next available unique connection name using the given
	 * connection name template.
	 */
	while (!cname && (i++ < 10000)) {
		char *temp;
		gboolean found = FALSE;

		/* Translators: the first %s is a prefix for the connection id, such
		 * as "Wired Connection" or "VPN Connection". The %d is a number
		 * that is combined with the first argument to create a unique
		 * connection id. */
		temp = g_strdup_printf (C_("connection id fallback", "%s %d"),
		                        fallback_prefix, i);
		for (iter = names; iter; iter = g_slist_next (iter)) {
			if (!strcmp (iter->data, temp)) {
				found = TRUE;
				break;
			}
		}
		if (!found)
			cname = temp;
		else
			g_free (temp);
	}

	g_slist_free (names);
	return cname;
}
static void
delete_connection_cb (NMRemoteConnection *connection, gboolean deleted, gpointer user_data)
{
	NMConnectionList *list = user_data;

	if (deleted)
		delete_slaves_of_connection (list, NM_CONNECTION (connection));
}
Ejemplo n.º 13
0
static void
bind_device_to_connection (SCPluginIfupdown *self,
                           GUdevDevice *device,
                           NMIfupdownConnection *exported)
{
	GByteArray *mac_address;
	NMSetting *s_wired = NULL;
	NMSetting *s_wifi = NULL;
	const char *iface, *address;
	struct ether_addr *tmp_mac;

	iface = g_udev_device_get_name (device);
	if (!iface) {
		PLUGIN_WARN ("SCPluginIfupdown", "failed to get ifname for device.");
		return;
	}

	address = g_udev_device_get_sysfs_attr (device, "address");
	if (!address || !strlen (address)) {
		PLUGIN_WARN ("SCPluginIfupdown", "failed to get MAC address for %s", iface);
		return;
	}

	tmp_mac = ether_aton (address);
	if (!tmp_mac) {
		PLUGIN_WARN ("SCPluginIfupdown", "failed to parse MAC address '%s' for %s",
		             address, iface);
		return;
	}

	mac_address = g_byte_array_sized_new (ETH_ALEN);
	g_byte_array_append (mac_address, &(tmp_mac->ether_addr_octet[0]), ETH_ALEN);

	s_wired = nm_connection_get_setting (NM_CONNECTION (exported), NM_TYPE_SETTING_WIRED);
	s_wifi = nm_connection_get_setting (NM_CONNECTION (exported), NM_TYPE_SETTING_WIRELESS);
	if (s_wired) {
		PLUGIN_PRINT ("SCPluginIfupdown", "locking wired connection setting");
		g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac_address, NULL);
	} else if (s_wifi) {
		PLUGIN_PRINT ("SCPluginIfupdown", "locking wireless connection setting");
		g_object_set (s_wifi, NM_SETTING_WIRELESS_MAC_ADDRESS, mac_address, NULL);
	}
	g_byte_array_free (mac_address, TRUE);

	nm_settings_connection_commit_changes (NM_SETTINGS_CONNECTION (exported), ignore_cb, NULL);
}    
Ejemplo n.º 14
0
static void
load_connections (NMBluezDevice *self)
{
	NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self);
	const GSList *connections, *iter;

	connections = nm_connection_provider_get_connections (priv->provider);
	for (iter = connections; iter; iter = g_slist_next (iter))
		cp_connection_added (priv->provider, NM_CONNECTION (iter->data), self);
}
Ejemplo n.º 15
0
static void
bind_device_to_connection (SCPluginIfupdown *self,
                           GUdevDevice *device,
                           NMIfupdownConnection *exported)
{
	GByteArray *mac_address;
	NMSettingWired *s_wired;
	NMSettingWireless *s_wifi;
	const char *iface, *address;

	iface = g_udev_device_get_name (device);
	if (!iface) {
		PLUGIN_WARN ("SCPluginIfupdown", "failed to get ifname for device.");
		return;
	}

	address = g_udev_device_get_sysfs_attr (device, "address");
	if (!address || !strlen (address)) {
		PLUGIN_WARN ("SCPluginIfupdown", "failed to get MAC address for %s", iface);
		return;
	}

	mac_address = nm_utils_hwaddr_atoba (address, ARPHRD_ETHER);
	if (!mac_address) {
		PLUGIN_WARN ("SCPluginIfupdown", "failed to parse MAC address '%s' for %s",
		             address, iface);
		return;
	}

	s_wired = nm_connection_get_setting_wired (NM_CONNECTION (exported));
	s_wifi = nm_connection_get_setting_wireless (NM_CONNECTION (exported));
	if (s_wired) {
		PLUGIN_PRINT ("SCPluginIfupdown", "locking wired connection setting");
		g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac_address, NULL);
	} else if (s_wifi) {
		PLUGIN_PRINT ("SCPluginIfupdown", "locking wireless connection setting");
		g_object_set (s_wifi, NM_SETTING_WIRELESS_MAC_ADDRESS, mac_address, NULL);
	}
	g_byte_array_free (mac_address, TRUE);

	nm_settings_connection_commit_changes (NM_SETTINGS_CONNECTION (exported), ignore_cb, NULL);
}    
Ejemplo n.º 16
0
void
nmt_remove_connection (NMRemoteConnection *connection)
{
	const GPtrArray *all_conns;
	GSList *slaves, *iter;
	int i;
	NMRemoteConnection *slave;
	NMSettingConnection *s_con;
	const char *uuid, *iface, *master;
	int choice;

	choice = nmt_newt_choice_dialog (_("Cancel"),
	                                 _("Delete"),
	                                 _("Are you sure you want to delete the connection '%s'?"),
	                                 nm_connection_get_id (NM_CONNECTION (connection)));
	if (choice == 1)
		return;

	g_object_ref (connection);
	remove_one_connection (connection);

	uuid = nm_connection_get_uuid (NM_CONNECTION (connection));
	iface = nm_connection_get_interface_name (NM_CONNECTION (connection));

	all_conns = nm_client_get_connections (nm_client);
	slaves = NULL;
	for (i = 0; i < all_conns->len; i++) {
		slave = all_conns->pdata[i];
		s_con = nm_connection_get_setting_connection (NM_CONNECTION (slave));
		master = nm_setting_connection_get_master (s_con);
		if (master) {
			if (!g_strcmp0 (master, uuid) || !g_strcmp0 (master, iface))
				slaves = g_slist_prepend (slaves, g_object_ref (slave));
		}
	}

	for (iter = slaves; iter; iter = iter->next)
		remove_one_connection (iter->data);
	g_slist_free_full (slaves, g_object_unref);

	g_object_unref (connection);
}
static void
updated_connection_cb (NMRemoteConnection *connection,
                       GError             *error,
                       gpointer            data)
{
        NetConnectionEditor *editor = data;

        nm_connection_clear_secrets (NM_CONNECTION (connection));

        update_complete (editor, error);
}
Ejemplo n.º 18
0
NmtNewtForm *
nmtui_edit (gboolean is_top, int argc, char **argv)
{
	NMConnection *conn = NULL;

	if (argc == 2) {
		if (nm_utils_is_uuid (argv[1]))
			conn = NM_CONNECTION (nm_client_get_connection_by_uuid (nm_client, argv[1]));
		if (!conn)
			conn = NM_CONNECTION (nm_client_get_connection_by_id (nm_client, argv[1]));

		if (!conn) {
			nmt_newt_message_dialog ("%s: no such connection '%s'\n", argv[0], argv[1]);
			return NULL;
		}

		return nmt_editor_new (conn);
	} else
		return nmt_edit_main_connection_list (is_top);
}
static void
connection_removed_cb (NMRemoteConnection *remote, gpointer user_data)
{
	NMRemoteSettings *self = NM_REMOTE_SETTINGS (user_data);
	NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
	const char *path;

	path = nm_connection_get_path (NM_CONNECTION (remote));
	g_hash_table_remove (priv->connections, path);
	g_hash_table_remove (priv->pending, path);
}
Ejemplo n.º 20
0
const char *
nm_active_connection_get_settings_connection_id (NMActiveConnection *self)
{
	NMSettingsConnection *con;

	g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (self), NULL);

	con = NM_ACTIVE_CONNECTION_GET_PRIVATE (self)->settings_connection;
	return con
	       ? nm_connection_get_id (NM_CONNECTION (con))
	       : NULL;
}
Ejemplo n.º 21
0
static char *
get_new_connection_name (const GSList *existing,
                         const char *format,
                         const char *preferred)
{
	GSList *names = NULL;
	const GSList *iter;
	char *cname = NULL;
	int i = 0;
	gboolean preferred_found = FALSE;

	for (iter = existing; iter; iter = g_slist_next (iter)) {
		NMConnection *candidate = NM_CONNECTION (iter->data);
		const char *id;

		id = nm_connection_get_id (candidate);
		g_assert (id);
		names = g_slist_append (names, (gpointer) id);

		if (preferred && !preferred_found && (strcmp (preferred, id) == 0))
			preferred_found = TRUE;
	}

	/* Return the preferred name if it was unique */
	if (preferred && !preferred_found) {
		g_slist_free (names);
		return g_strdup (preferred);
	}

	/* Otherwise find the next available unique connection name using the given
	 * connection name template.
	 */
	while (!cname && (i++ < 10000)) {
		char *temp;
		gboolean found = FALSE;

		temp = g_strdup_printf (format, i);
		for (iter = names; iter; iter = g_slist_next (iter)) {
			if (!strcmp (iter->data, temp)) {
				found = TRUE;
				break;
			}
		}
		if (!found)
			cname = temp;
		else
			g_free (temp);
	}

	g_slist_free (names);
	return cname;
}
static void
connection_added (NMRemoteSettings *settings,
                  NMRemoteConnection *connection,
                  gpointer user_data)
{
	NMConnectionList *self = NM_CONNECTION_LIST (user_data);
	GtkTreeIter parent_iter, iter;
	NMSettingConnection *s_con;
	char *last_used;
	gboolean expand = TRUE;

	if (!get_parent_iter_for_connection (self, connection, &parent_iter))
		return;

	s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection));

	last_used = format_last_used (nm_setting_connection_get_timestamp (s_con));

	gtk_tree_store_append (GTK_TREE_STORE (self->model), &iter, &parent_iter);
	gtk_tree_store_set (GTK_TREE_STORE (self->model), &iter,
	                    COL_ID, nm_setting_connection_get_id (s_con),
	                    COL_LAST_USED, last_used,
	                    COL_TIMESTAMP, nm_setting_connection_get_timestamp (s_con),
	                    COL_CONNECTION, connection,
	                    -1);

	g_free (last_used);

	if (self->displayed_type) {
		GType added_type;

		gtk_tree_model_get (self->model, &parent_iter,
		                    COL_GTYPE, &added_type,
		                    -1);
		if (added_type != self->displayed_type)
			expand = FALSE;
	}

	if (expand) {
		GtkTreePath *path, *filtered_path;

		path = gtk_tree_model_get_path (self->model, &parent_iter);
		filtered_path = gtk_tree_model_filter_convert_child_path_to_path (self->filter, path);
		gtk_tree_view_expand_row (self->connection_list, filtered_path, FALSE);
		gtk_tree_path_free (filtered_path);
		gtk_tree_path_free (path);
	}

	g_signal_connect (connection, NM_REMOTE_CONNECTION_REMOVED, G_CALLBACK (connection_removed), self);
	g_signal_connect (connection, NM_REMOTE_CONNECTION_UPDATED, G_CALLBACK (connection_updated), self);
	gtk_tree_model_filter_refilter (self->filter);
}
Ejemplo n.º 23
0
static void
bind_device_to_connection (SettingsPluginIfupdown *self,
                           GUdevDevice *device,
                           NMIfupdownConnection *exported)
{
	NMSettingWired *s_wired;
	NMSettingWireless *s_wifi;
	const char *iface, *address;

	iface = g_udev_device_get_name (device);
	if (!iface) {
		nm_log_warn (LOGD_SETTINGS, "failed to get ifname for device.");
		return;
	}

	address = g_udev_device_get_sysfs_attr (device, "address");
	if (!address || !strlen (address)) {
		nm_log_warn (LOGD_SETTINGS, "failed to get MAC address for %s", iface);
		return;
	}

	if (!nm_utils_hwaddr_valid (address, ETH_ALEN)) {
		nm_log_warn (LOGD_SETTINGS, "failed to parse MAC address '%s' for %s",
		             address, iface);
		return;
	}

	s_wired = nm_connection_get_setting_wired (NM_CONNECTION (exported));
	s_wifi = nm_connection_get_setting_wireless (NM_CONNECTION (exported));
	if (s_wired) {
		nm_log_info (LOGD_SETTINGS, "locking wired connection setting");
		g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, address, NULL);
	} else if (s_wifi) {
		nm_log_info (LOGD_SETTINGS, "locking wireless connection setting");
		g_object_set (s_wifi, NM_SETTING_WIRELESS_MAC_ADDRESS, address, NULL);
	}

	nm_settings_connection_commit_changes (NM_SETTINGS_CONNECTION (exported), NM_SETTINGS_CONNECTION_COMMIT_REASON_NONE, NULL, NULL);
}    
void
nm_settings_service_export_connection (NMSettingsService *self,
                                       NMSettingsConnectionInterface *connection)
{
	NMSettingsServicePrivate *priv = NM_SETTINGS_SERVICE_GET_PRIVATE (self);
	static guint32 ec_counter = 0;
	char *path;

	g_return_if_fail (connection != NULL);
	g_return_if_fail (NM_IS_SETTINGS_CONNECTION_INTERFACE (connection));
	g_return_if_fail (priv->bus != NULL);

	/* Don't allow exporting twice */
	g_return_if_fail (nm_connection_get_path (NM_CONNECTION (connection)) == NULL);

	path = g_strdup_printf ("%s/%u", NM_DBUS_PATH_SETTINGS, ec_counter++);
	nm_connection_set_path (NM_CONNECTION (connection), path);
	nm_connection_set_scope (NM_CONNECTION (connection), priv->scope);

	dbus_g_connection_register_g_object (priv->bus, path, G_OBJECT (connection));
	g_free (path);
}
Ejemplo n.º 25
0
static NMIfcfgConnection *
_internal_new_connection (SCPluginIfcfg *self,
                          const char *path,
                          NMConnection *source,
                          GError **error)
{
    SCPluginIfcfgPrivate *priv = SC_PLUGIN_IFCFG_GET_PRIVATE (self);
    NMIfcfgConnection *connection;
    const char *cid;
    GError *local = NULL;
    gboolean ignore_error = FALSE;

    if (!source) {
        PLUGIN_PRINT (IFCFG_PLUGIN_NAME, "parsing %s ... ", path);
    }

    connection = nm_ifcfg_connection_new (path, source, &local, &ignore_error);
    if (!connection) {
        if (!ignore_error) {
            PLUGIN_PRINT (IFCFG_PLUGIN_NAME, "    error: %s",
                          (local && local->message) ? local->message : "(unknown)");
        }
        g_propagate_error (error, local);
        return NULL;
    }

    cid = nm_connection_get_id (NM_CONNECTION (connection));
    g_assert (cid);

    g_hash_table_insert (priv->connections,
                         (gpointer) nm_ifcfg_connection_get_path (connection),
                         connection);
    PLUGIN_PRINT (IFCFG_PLUGIN_NAME, "    read connection '%s'", cid);

    if (nm_ifcfg_connection_get_unmanaged_spec (connection)) {
        PLUGIN_PRINT (IFCFG_PLUGIN_NAME, "Ignoring connection '%s' and its "
                      "device due to NM_CONTROLLED/BRIDGE/VLAN.", cid);
    } else {
        /* Wait for the connection to become unmanaged once it knows the
         * hardware IDs of its device, if/when the device gets plugged in.
         */
        g_signal_connect (G_OBJECT (connection), "notify::" NM_IFCFG_CONNECTION_UNMANAGED,
                          G_CALLBACK (connection_unmanaged_changed), self);
    }

    /* watch changes of ifcfg hardlinks */
    g_signal_connect (G_OBJECT (connection), "ifcfg-changed",
                      G_CALLBACK (connection_ifcfg_changed), self);

    return connection;
}
Ejemplo n.º 26
0
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;
}
Ejemplo n.º 27
0
/**
 * nm_wimax_nsp_filter_connections:
 * @nsp: an #NMWimaxNsp to filter connections for
 * @connections: (element-type NetworkManager.Connection): a list of
 * #NMConnection objects to filter
 *
 * Filters a given list of connections for a given #NMWimaxNsp object and
 * return connections which may be activated with the access point.  Any
 * returned connections will match the @nsp's network name and other attributes.
 *
 * Returns: (transfer container) (element-type NetworkManager.Connection): a
 * list of #NMConnection objects that could be activated with the given @nsp.
 * The elements of the list are owned by their creator and should not be freed
 * by the caller, but the returned list itself is owned by the caller and should
 * be freed with g_slist_free() when it is no longer required.
 **/
GSList *
nm_wimax_nsp_filter_connections (NMWimaxNsp *nsp, const GSList *connections)
{
	GSList *filtered = NULL;
	const GSList *iter;

	for (iter = connections; iter; iter = g_slist_next (iter)) {
		NMConnection *candidate = NM_CONNECTION (iter->data);

		if (nm_wimax_nsp_connection_valid (nsp, candidate))
			filtered = g_slist_prepend (filtered, candidate);
	}

	return g_slist_reverse (filtered);
}
Ejemplo n.º 28
0
static NMConnection *
get_best_auto_connection (NMModem *modem,
                          GSList *connections,
                          char **specific_object)
{
	GSList *iter;

	for (iter = connections; iter; iter = g_slist_next (iter)) {
		NMConnection *connection = NM_CONNECTION (iter->data);

		if (nm_connection_is_type (connection, NM_SETTING_GSM_SETTING_NAME))
			return connection;
	}
	return NULL;
}
Ejemplo n.º 29
0
/**
 * nm_access_point_filter_connections:
 * @ap: an #NMAccessPoint to filter connections for
 * @connections: (element-type NMConnection): a list of
 * #NMConnection objects to filter
 *
 * Filters a given list of connections for a given #NMAccessPoint object and
 * return connections which may be activated with the access point.  Any
 * returned connections will match the @ap's SSID and (if given) BSSID and
 * other attributes like security settings, channel, etc.
 *
 * To obtain the list of connections that are compatible with this access point,
 * use nm_remote_settings_list_connections() and then filter the returned list
 * for a given #NMDevice using nm_device_filter_connections() and finally
 * filter that list with this function.
 *
 * Returns: (transfer container) (element-type NMConnection): a
 * list of #NMConnection objects that could be activated with the given @ap.
 * The elements of the list are owned by their creator and should not be freed
 * by the caller, but the returned list itself is owned by the caller and should
 * be freed with g_slist_free() when it is no longer required.
 **/
GSList *
nm_access_point_filter_connections (NMAccessPoint *ap, const GSList *connections)
{
	GSList *filtered = NULL;
	const GSList *iter;

	for (iter = connections; iter; iter = g_slist_next (iter)) {
		NMConnection *candidate = NM_CONNECTION (iter->data);

		if (nm_access_point_connection_valid (ap, candidate))
			filtered = g_slist_prepend (filtered, candidate);
	}

	return g_slist_reverse (filtered);
}
static void
constructed (GObject *object)
{
    NMConnection *connection;
    NMSetting *setting;

    if (G_OBJECT_CLASS (nm_ethernet_item_parent_class)->constructed)
        G_OBJECT_CLASS (nm_ethernet_item_parent_class)->constructed (object);

    connection = NM_CONNECTION (nm_connection_item_get_connection (NM_CONNECTION_ITEM (object)));
    setting = nm_connection_get_setting (connection, NM_TYPE_SETTING_802_1X);

    if (setting)
        g_object_set (object, NM_LIST_ITEM_SECURITY, _("802.1x"), NULL);
}