static void recheck_services_enabled (NmaBtDevice *self) { NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (self); GSList *list, *iter; gboolean pan = FALSE, dun = FALSE; /* Retrieve initial enabled state for both PAN and DUN; if there are any * existing Bluetooth connections for the given device for either PAN * or DUN, then we consider that service enabled. */ list = nm_remote_settings_list_connections (priv->settings); for (iter = list; iter != NULL; iter = g_slist_next (iter)) { NMConnection *connection = iter->data; if (match_connection_bdaddr (connection, priv->bdaddr_array)) { NMSettingBluetooth *s_bt; const char *type; s_bt = nm_connection_get_setting_bluetooth (connection); g_assert (s_bt); type = nm_setting_bluetooth_get_connection_type (s_bt); if (priv->has_pan && g_strcmp0 (type, NM_SETTING_BLUETOOTH_TYPE_PANU) == 0) pan = TRUE; else if (priv->has_dun && g_strcmp0 (type, NM_SETTING_BLUETOOTH_TYPE_DUN) == 0) dun = TRUE; } } g_slist_free (list); _set_pan_enabled (self, pan); _set_dun_enabled (self, dun); }
static GSList * valid_connections_for_device (NMRemoteSettings *remote_settings, NMDevice *device) { GSList *all, *filtered, *iterator, *valid; NMConnection *connection; NMSettingConnection *s_con; all = nm_remote_settings_list_connections (remote_settings); filtered = nm_device_filter_connections (device, all); g_slist_free (all); valid = NULL; for (iterator = filtered; iterator; iterator = iterator->next) { connection = iterator->data; s_con = nm_connection_get_setting_connection (connection); if (!s_con) continue; if (nm_setting_connection_get_master (s_con)) continue; valid = g_slist_prepend (valid, connection); } g_slist_free (filtered); return g_slist_reverse (valid); }
static void remove_connections_read (NMRemoteSettings *settings, gpointer user_data) { RemoveInfo *info = user_data; GSList *list, *iter; g_source_remove (info->timeout_id); g_message ("Removing Bluetooth connections for %s", info->str_bdaddr); list = nm_remote_settings_list_connections (settings); for (iter = list; iter != NULL; iter = g_slist_next (iter)) { NMConnection *connection = iter->data; NMSettingBluetooth *s_bt; const GByteArray *tmp; s_bt = nm_connection_get_setting_bluetooth (connection); if (s_bt) { tmp = nm_setting_bluetooth_get_bdaddr (s_bt); if (tmp && memcmp (tmp->data, info->bdaddr->data, tmp->len) == 0) nm_remote_connection_delete (NM_REMOTE_CONNECTION (connection), delete_cb, NULL); } } g_slist_free (list); remove_cleanup (info); }
static void import_cb (NMConnection *connection, gpointer user_data) { NewVpnInfo *info = (NewVpnInfo *) user_data; NMSettingConnection *s_con; NMSettingVPN *s_vpn; const char *service_type; char *s; GError *error = NULL; /* Basic sanity checks of the connection */ s_con = nm_connection_get_setting_connection (connection); if (!s_con) { s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ()); nm_connection_add_setting (connection, NM_SETTING (s_con)); } s = (char *) nm_setting_connection_get_id (s_con); if (!s) { GSList *connections; connections = nm_remote_settings_list_connections (info->settings); s = ce_page_get_next_available_name (connections, _("VPN connection %d")); g_object_set (s_con, NM_SETTING_CONNECTION_ID, s, NULL); g_free (s); g_slist_free (connections); } s = (char *) nm_setting_connection_get_connection_type (s_con); if (!s || strcmp (s, NM_SETTING_VPN_SETTING_NAME)) g_object_set (s_con, NM_SETTING_CONNECTION_TYPE, NM_SETTING_VPN_SETTING_NAME, NULL); s = (char *) nm_setting_connection_get_uuid (s_con); if (!s) { s = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_UUID, s, NULL); g_free (s); } s_vpn = nm_connection_get_setting_vpn (connection); service_type = s_vpn ? nm_setting_vpn_get_service_type (s_vpn) : NULL; if (!service_type || !strlen (service_type)) { g_object_unref (connection); connection = NULL; error = g_error_new_literal (NMA_ERROR, NMA_ERROR_GENERIC, _("The VPN plugin failed to import the VPN connection correctly\n\nError: no VPN service type.")); } info->result_func (connection, FALSE, error, info->user_data); g_clear_error (&error); g_object_unref (info->settings); g_slice_free (NewVpnInfo, info); }
static void test_make_invisible (void) { time_t start, now; GSList *list, *iter; DBusGProxy *proxy; gboolean done = FALSE, has_settings = FALSE; char *path; g_assert (remote != NULL); /* Listen for the remove event when the connection becomes invisible */ g_signal_connect (remote, "removed", G_CALLBACK (invis_removed_cb), &done); path = g_strdup (nm_connection_get_path (NM_CONNECTION (remote))); proxy = dbus_g_proxy_new_for_name (bus, NM_DBUS_SERVICE, path, NM_DBUS_IFACE_SETTINGS_CONNECTION); g_assert (proxy != NULL); /* Bypass the NMRemoteSettings object so we can test it independently */ dbus_g_proxy_begin_call (proxy, "SetVisible", set_visible_cb, NULL, NULL, G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID); /* Wait for the connection to be removed */ 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); g_signal_handlers_disconnect_by_func (remote, G_CALLBACK (invis_removed_cb), &done); /* Ensure NMRemoteSettings no longer has the connection */ list = nm_remote_settings_list_connections (settings); for (iter = list; iter; iter = g_slist_next (iter)) { NMConnection *candidate = NM_CONNECTION (iter->data); g_assert ((gpointer) remote != (gpointer) candidate); g_assert (strcmp (path, nm_connection_get_path (candidate)) != 0); } /* And ensure the invisible connection no longer has any settings */ g_assert (remote); nm_connection_for_each_setting_value (NM_CONNECTION (remote), invis_has_settings_cb, &has_settings); g_assert (has_settings == FALSE); g_free (path); g_object_unref (proxy); }
void bond_connection_new (GtkWindow *parent, const char *detail, NMRemoteSettings *settings, PageNewConnectionResultFunc result_func, gpointer user_data) { NMConnection *connection; int bond_num, max_bond_num, num; GSList *connections, *iter; NMConnection *conn2; NMSettingBond *s_bond; const char *iface; char *my_iface; connection = ce_page_new_connection (_("Bond connection %d"), NM_SETTING_BOND_SETTING_NAME, TRUE, settings, user_data); nm_connection_add_setting (connection, nm_setting_bond_new ()); /* Find an available interface name */ bond_num = max_bond_num = 0; connections = nm_remote_settings_list_connections (settings); for (iter = connections; iter; iter = iter->next) { conn2 = iter->data; if (!nm_connection_is_type (conn2, NM_SETTING_BOND_SETTING_NAME)) continue; s_bond = nm_connection_get_setting_bond (conn2); if (!s_bond) continue; iface = nm_setting_bond_get_interface_name (s_bond); if (!iface || strncmp (iface, "bond", 4) != 0 || !g_ascii_isdigit (iface[4])) continue; num = atoi (iface + 4); if (num > max_bond_num) max_bond_num = num; if (num == bond_num) bond_num = max_bond_num + 1; } g_slist_free (connections); my_iface = g_strdup_printf ("bond%d", bond_num); s_bond = nm_connection_get_setting_bond (connection); g_object_set (G_OBJECT (s_bond), NM_SETTING_BOND_INTERFACE_NAME, my_iface, NULL); g_free (my_iface); (*result_func) (connection, FALSE, NULL, user_data); }
static void delete_connections_of_type (NMRemoteSettings *settings, const GByteArray *bdaddr, gboolean pan) { GSList *list, *iter; list = nm_remote_settings_list_connections (settings); for (iter = list; iter != NULL; iter = g_slist_next (iter)) { NMRemoteConnection *remote = iter->data; if (match_connection_service (NM_CONNECTION (remote), bdaddr, pan)) nm_remote_connection_delete (remote, delete_cb, NULL); } g_slist_free (list); }
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); }
static NMConnection * get_connection (NMRemoteSettings *settings, const gchar *id) { const gchar *uuid; NMConnection *connection = NULL; GSList *list, *l; list = nm_remote_settings_list_connections (settings); for (l = list; l; l = l->next) { connection = l->data; uuid = nm_connection_get_uuid (connection); if (g_strcmp0 (uuid, id) == 0) { g_slist_free (list); return connection; } } g_slist_free (list); return NULL; }
static void row_activated (GtkListBox *box, GtkListBoxRow *row, GisNetworkPage *page) { GisNetworkPagePrivate *priv = gis_network_page_get_instance_private (page); gchar *object_path; GSList *list, *filtered, *l; NMConnection *connection; NMConnection *connection_to_activate; NMSettingWireless *setting; const GByteArray *ssid_target; const GByteArray *ssid; GtkWidget *child; if (priv->refreshing) return; child = gtk_bin_get_child (GTK_BIN (row)); object_path = g_object_get_data (G_OBJECT (child), "object-path"); ssid_target = g_object_get_data (G_OBJECT (child), "ssid"); if (g_strcmp0 (object_path, "ap-other...") == 0) { connect_to_hidden_network (page); goto out; } list = nm_remote_settings_list_connections (priv->nm_settings); filtered = nm_device_filter_connections (priv->nm_device, list); connection_to_activate = NULL; for (l = filtered; l; l = l->next) { connection = NM_CONNECTION (l->data); setting = nm_connection_get_setting_wireless (connection); if (!NM_IS_SETTING_WIRELESS (setting)) continue; ssid = nm_setting_wireless_get_ssid (setting); if (ssid == NULL) continue; if (nm_utils_same_ssid (ssid, ssid_target, TRUE)) { connection_to_activate = connection; break; } } g_slist_free (list); g_slist_free (filtered); if (connection_to_activate != NULL) { nm_client_activate_connection (priv->nm_client, connection_to_activate, priv->nm_device, NULL, connection_activate_cb, page); goto out; } nm_client_add_and_activate_connection (priv->nm_client, NULL, priv->nm_device, object_path, connection_add_activate_cb, page); out: refresh_wireless_list (page); }
static void build_vlan_parent_list (CEPageVlan *self, GSList *devices) { CEPageVlanPrivate *priv = CE_PAGE_VLAN_GET_PRIVATE (self); GSList *connections, *c_iter, *d_iter; GPtrArray *parents; VlanParent *parent; NMDevice *device; const char *iface, *mac, *id; int i; parents = g_ptr_array_new (); /* Devices with no L2 configuration can spawn VLANs directly. At the * moment, this means just Ethernet. */ for (d_iter = devices; d_iter; d_iter = d_iter->next) { device = d_iter->data; if (!NM_IS_DEVICE_ETHERNET (device)) continue; parent = g_slice_new (VlanParent); parent->device = device; parent->connection = NULL; iface = nm_device_get_iface (device); mac = nm_device_ethernet_get_permanent_hw_address (NM_DEVICE_ETHERNET (device)); parent->label = g_strdup_printf ("%s (%s)", iface, mac); g_ptr_array_add (parents, parent); } /* Otherwise, VLANs have to be built on top of configured connections */ connections = nm_remote_settings_list_connections (CE_PAGE (self)->settings); for (c_iter = connections; c_iter; c_iter = c_iter->next) { NMConnection *candidate = c_iter->data; NMSettingConnection *s_con = nm_connection_get_setting_connection (candidate); if (nm_setting_connection_get_master (s_con)) continue; for (d_iter = devices; d_iter; d_iter = d_iter->next) { device = d_iter->data; if (nm_device_connection_valid (device, candidate)) { parent = g_slice_new (VlanParent); parent->device = device; parent->connection = candidate; iface = nm_device_get_iface (device); id = nm_setting_connection_get_id (s_con); parent->label = g_strdup_printf ("%s (%s)", iface, id); g_ptr_array_add (parents, parent); /* no break here; the connection may apply to multiple devices */ } } } g_slist_free (connections); g_ptr_array_sort (parents, sort_parents); g_ptr_array_add (parents, NULL); priv->parent_labels = g_new (char *, parents->len); priv->parents = (VlanParent **)g_ptr_array_free (parents, FALSE); for (i = 0; priv->parents[i]; i++) priv->parent_labels[i] = priv->parents[i]->label; priv->parent_labels[i] = NULL; }
static void nmt_connect_connection_list_rebuild (NmtConnectConnectionList *list) { NmtConnectConnectionListPrivate *priv = NMT_CONNECT_CONNECTION_LIST_GET_PRIVATE (list); NmtNewtListbox *listbox = NMT_NEWT_LISTBOX (list); const GPtrArray *devices, *acs; int max_width; char **names, *row, active_col; const char *strength_col; GSList *connections; GSList *nmt_devices, *diter, *citer; NmtConnectDevice *nmtdev; NmtConnectConnection *nmtconn; g_slist_free_full (priv->nmt_devices, (GDestroyNotify) nmt_connect_device_free); priv->nmt_devices = NULL; nmt_newt_listbox_clear (listbox); devices = nm_client_get_devices (nm_client); acs = nm_client_get_active_connections (nm_client); connections = nm_remote_settings_list_connections (nm_settings); nmt_devices = NULL; if (devices) { names = nm_device_disambiguate_names ((NMDevice **) devices->pdata, devices->len); nmt_devices = append_nmt_devices_for_devices (nmt_devices, devices, names, connections); g_strfreev (names); } nmt_devices = append_nmt_devices_for_virtual_devices (nmt_devices, connections); nmt_devices = append_nmt_devices_for_vpns (nmt_devices, connections); nmt_devices = g_slist_sort (nmt_devices, sort_nmt_devices); g_slist_free (connections); max_width = 0; for (diter = nmt_devices; diter; diter = diter->next) { nmtdev = diter->data; for (citer = nmtdev->conns; citer; citer = citer->next) { nmtconn = citer->data; max_width = MAX (max_width, nmt_newt_text_width (nmtconn->name)); } } for (diter = nmt_devices; diter; diter = diter->next) { nmtdev = diter->data; if (diter != nmt_devices) nmt_newt_listbox_append (listbox, "", NULL); nmt_newt_listbox_append (listbox, nmtdev->name, NULL); for (citer = nmtdev->conns; citer; citer = citer->next) { nmtconn = citer->data; if (nmtconn->conn) nmtconn->active = connection_find_ac (nmtconn->conn, acs); if (nmtconn->active) { g_object_ref (nmtconn->active); active_col = '*'; } else active_col = ' '; if (nmtconn->ap) { guint8 strength = nm_access_point_get_strength (nmtconn->ap); if (strength > 80) strength_col = strength_full; else if (strength > 55) strength_col = strength_high; else if (strength > 30) strength_col = strength_med; else if (strength > 5) strength_col = strength_low; else strength_col = strength_none; } else strength_col = NULL; row = g_strdup_printf ("%c %s%-*s%s%s", active_col, nmtconn->name, (int)(max_width - nmt_newt_text_width (nmtconn->name)), "", strength_col ? " " : "", strength_col ? strength_col : ""); nmt_newt_listbox_append (listbox, row, nmtconn); g_free (row); } } priv->nmt_devices = nmt_devices; g_object_notify (G_OBJECT (listbox), "active"); g_object_notify (G_OBJECT (listbox), "active-key"); }
static void wireless_dialog_response_cb (GtkDialog *foo, gint response, gpointer user_data) { NMAWirelessDialog *dialog = NMA_WIRELESS_DIALOG (foo); WirelessDialogClosure *closure = user_data; NMConnection *connection, *fuzzy_match = NULL; NMDevice *device; NMAccessPoint *ap; GSList *all, *iter; if (response != GTK_RESPONSE_OK) goto done; if (!nma_wireless_dialog_get_nag_ignored (dialog)) { GtkWidget *nag_dialog; /* Nag the user about certificates or whatever. Only destroy the dialog * if no nagging was done. */ nag_dialog = nma_wireless_dialog_nag_user (dialog); 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; } } /* nma_wireless_dialog_get_connection() returns a connection with the * refcount incremented, so the caller must remember to unref it. */ connection = nma_wireless_dialog_get_connection (dialog, &device, &ap); g_assert (connection); g_assert (device); /* Find a similar connection and use that instead */ all = nm_remote_settings_list_connections (closure->settings); for (iter = all; iter; iter = g_slist_next (iter)) { if (nm_connection_compare (connection, NM_CONNECTION (iter->data), (NM_SETTING_COMPARE_FLAG_FUZZY | NM_SETTING_COMPARE_FLAG_IGNORE_ID))) { fuzzy_match = NM_CONNECTION (iter->data); break; } } g_slist_free (all); if (fuzzy_match) { nm_client_activate_connection (closure->client, fuzzy_match, device, ap ? nm_object_get_path (NM_OBJECT (ap)) : NULL, activate_existing_cb, NULL); } else { NMSetting *s_con; NMSettingWireless *s_wifi; const char *mode = NULL; /* Entirely new connection */ /* Don't autoconnect adhoc networks by default for now */ s_wifi = (NMSettingWireless *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS); if (s_wifi) mode = nm_setting_wireless_get_mode (s_wifi); if (g_strcmp0 (mode, "adhoc") == 0) { s_con = nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION); if (!s_con) { s_con = nm_setting_connection_new (); nm_connection_add_setting (connection, s_con); } g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_AUTOCONNECT, FALSE, NULL); } nm_client_add_and_activate_connection (closure->client, connection, device, ap ? nm_object_get_path (NM_OBJECT (ap)) : NULL, activate_new_cb, NULL); } /* Balance nma_wireless_dialog_get_connection() */ g_object_unref (connection); done: gtk_widget_hide (GTK_WIDGET (dialog)); gtk_widget_destroy (GTK_WIDGET (dialog)); }