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; }
/* Print details of connection */ static void show_connection (NMConnection *connection) { NMSettingConnection *s_con; guint64 timestamp; char *timestamp_str; char timestamp_real_str[64]; const char *val1, *val2, *val3, *val3a, *val4, *val5; s_con = nm_connection_get_setting_connection (connection); if (s_con) { /* Get various info from NMSettingConnection and show it */ timestamp = nm_setting_connection_get_timestamp (s_con); timestamp_str = g_strdup_printf ("%" G_GUINT64_FORMAT, timestamp); strftime (timestamp_real_str, sizeof (timestamp_real_str), "%c", localtime ((time_t *) ×tamp)); val1 = nm_setting_connection_get_id (s_con); val2 = nm_setting_connection_get_uuid (s_con); val3 = nm_setting_connection_get_connection_type (s_con); val3a = nm_setting_connection_get_interface_name (s_con); val4 = nm_connection_get_path (connection); val5 = timestamp ? timestamp_real_str : "never"; printf ("%-25s | %s | %-15s | %10s | %-43s | %s\n", val1, val2, val3, val3a, val4, val5); g_free (timestamp_str); } }
/** * nmt_editor_new: * @connection: the #NMConnection to edit * * Creates a new #NmtEditor to edit @connection. * * Returns: a new #NmtEditor */ NmtNewtForm * nmt_editor_new (NMConnection *connection) { NMEditorConnectionTypeData *type_data; type_data = nm_editor_utils_get_connection_type_data (connection); if (!type_data) { NMSettingConnection *s_con; s_con = nm_connection_get_setting_connection (connection); if (s_con) { nmt_newt_message_dialog (_("Could not create editor for connection '%s' of type '%s'."), nm_connection_get_id (connection), nm_setting_connection_get_connection_type (s_con)); } else { nmt_newt_message_dialog (_("Could not create editor for invalid connection '%s'."), nm_connection_get_id (connection)); } return NULL; } return g_object_new (NMT_TYPE_EDITOR, "connection", connection, "type-data", type_data, "title", _("Edit connection"), "fullscreen-vertical", TRUE, NULL); }
static gboolean real_check_connection_compatible (NMDevice *device, NMConnection *connection, GError **error) { NMSettingConnection *s_con; NMSettingOlpcMesh *s_mesh; s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION)); g_assert (s_con); if (strcmp (nm_setting_connection_get_connection_type (s_con), NM_SETTING_OLPC_MESH_SETTING_NAME)) { g_set_error (error, NM_OLPC_MESH_ERROR, NM_OLPC_MESH_ERROR_CONNECTION_NOT_MESH, "The connection was not a Mesh connection."); return FALSE; } s_mesh = NM_SETTING_OLPC_MESH (nm_connection_get_setting (connection, NM_TYPE_SETTING_OLPC_MESH)); if (!s_mesh) { g_set_error (error, NM_OLPC_MESH_ERROR, NM_OLPC_MESH_ERROR_CONNECTION_INVALID, "The connection was not a valid Mesh connection."); return FALSE; } return TRUE; }
static gboolean connection_compatible (NMDevice *device, NMConnection *connection, GError **error) { NMSettingConnection *s_con; const char *ctype, *iface_name; s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); ctype = nm_setting_connection_get_connection_type (s_con); if (strcmp (ctype, NM_SETTING_GENERIC_SETTING_NAME) != 0) { g_set_error (error, NM_DEVICE_GENERIC_ERROR, NM_DEVICE_GENERIC_ERROR_NOT_GENERIC_CONNECTION, "The connection was not a generic connection."); return FALSE; } iface_name = nm_setting_connection_get_interface_name (s_con); if (!iface_name) { g_set_error (error, NM_DEVICE_GENERIC_ERROR, NM_DEVICE_GENERIC_ERROR_MISSING_INTERFACE_NAME, "The connection did not specify an interface name."); return FALSE; } return NM_DEVICE_CLASS (nm_device_generic_parent_class)->connection_compatible (device, connection, error); }
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; }
static gboolean check_connection_compatible (NMModem *modem, NMConnection *connection, GError **error) { NMSettingConnection *s_con; NMSettingGsm *s_gsm; s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); if (strcmp (nm_setting_connection_get_connection_type (s_con), NM_SETTING_GSM_SETTING_NAME)) { g_set_error (error, NM_GSM_ERROR, NM_GSM_ERROR_CONNECTION_NOT_GSM, "The connection was not a GSM connection."); return FALSE; } s_gsm = nm_connection_get_setting_gsm (connection); if (!s_gsm) { g_set_error (error, NM_GSM_ERROR, NM_GSM_ERROR_CONNECTION_INVALID, "The connection was not a valid GSM connection."); return FALSE; } return TRUE; }
static gboolean connection_compatible (NMDevice *device, NMConnection *connection, GError **error) { NMSettingConnection *s_con; NMSettingOlpcMesh *s_olpc_mesh; const char *ctype; s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); ctype = nm_setting_connection_get_connection_type (s_con); if (strcmp (ctype, NM_SETTING_OLPC_MESH_SETTING_NAME) != 0) { g_set_error (error, NM_DEVICE_OLPC_MESH_ERROR, NM_DEVICE_OLPC_MESH_ERROR_NOT_OLPC_MESH_CONNECTION, "The connection was not a Olpc Mesh connection."); return FALSE; } s_olpc_mesh = nm_connection_get_setting_olpc_mesh (connection); if (!s_olpc_mesh) { g_set_error (error, NM_DEVICE_OLPC_MESH_ERROR, NM_DEVICE_OLPC_MESH_ERROR_INVALID_OLPC_MESH_CONNECTION, "The connection was not a valid Olpc Mesh connection."); return FALSE; } return NM_DEVICE_CLASS (nm_device_olpc_mesh_parent_class)->connection_compatible (device, connection, error); }
static gboolean check_connection_compatible (NMDevice *device, NMConnection *connection) { NMSettingConnection *s_con; NMSettingWimax *s_wimax; const char *connection_type; const char *mac; if (!NM_DEVICE_CLASS (nm_device_wimax_parent_class)->check_connection_compatible (device, connection)) return FALSE; s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); connection_type = nm_setting_connection_get_connection_type (s_con); if (strcmp (connection_type, NM_SETTING_WIMAX_SETTING_NAME)) return FALSE; s_wimax = nm_connection_get_setting_wimax (connection); if (!s_wimax) return FALSE; mac = nm_setting_wimax_get_mac_address (s_wimax); if (mac && !nm_utils_hwaddr_matches (mac, -1, nm_device_get_hw_address (device), -1)) return FALSE; return TRUE; }
static gboolean connection_compatible (NMDevice *device, NMConnection *connection, GError **error) { NMSettingConnection *s_con; NMSettingAdsl *s_adsl; const char *ctype; s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); ctype = nm_setting_connection_get_connection_type (s_con); if (strcmp (ctype, NM_SETTING_ADSL_SETTING_NAME) != 0) { g_set_error (error, NM_DEVICE_ADSL_ERROR, NM_DEVICE_ADSL_ERROR_NOT_ADSL_CONNECTION, "The connection was not an ADSL connection."); return FALSE; } s_adsl = nm_connection_get_setting_adsl (connection); if (!s_adsl) { g_set_error (error, NM_DEVICE_ADSL_ERROR, NM_DEVICE_ADSL_ERROR_INVALID_ADSL_CONNECTION, "The connection was not a valid ADSL connection."); return FALSE; } return NM_DEVICE_CLASS (nm_device_adsl_parent_class)->connection_compatible (device, connection, error); }
/** * nm_wimax_nsp_connection_valid: * @nsp: an #NMWimaxNsp to validate @connection against * @connection: an #NMConnection to validate against @nsp * * Validates a given connection against a given WiMAX NSP to ensure that the * connection may be activated with that NSP. The connection must match the * @nsp's network name and other attributes. * * Returns: %TRUE if the connection may be activated with this WiMAX NSP, * %FALSE if it cannot be. **/ gboolean nm_wimax_nsp_connection_valid (NMWimaxNsp *nsp, NMConnection *connection) { NMSettingConnection *s_con; NMSettingWimax *s_wimax; const char *ctype; const char *nsp_name; const char *setting_name; s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); ctype = nm_setting_connection_get_connection_type (s_con); if (strcmp (ctype, NM_SETTING_WIMAX_SETTING_NAME) != 0) return FALSE; s_wimax = nm_connection_get_setting_wimax (connection); if (!s_wimax) return FALSE; setting_name = nm_setting_wimax_get_network_name (s_wimax); if (!setting_name) return FALSE; nsp_name = nm_wimax_nsp_get_name (nsp); g_warn_if_fail (nsp_name != NULL); if (g_strcmp0 (nsp_name, setting_name) != 0) return FALSE; return TRUE; }
static void nmt_slave_list_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { NmtSlaveListPrivate *priv = NMT_SLAVE_LIST_GET_PRIVATE (object); switch (prop_id) { case PROP_MASTER: priv->master = g_value_dup_object (value); if (priv->master) { NMSettingConnection *s_con = nm_connection_get_setting_connection (priv->master); priv->master_type = nm_setting_connection_get_connection_type (s_con); priv->master_uuid = nm_setting_connection_get_uuid (s_con); } break; case PROP_TYPE_FILTER: priv->type_filter = g_value_get_pointer (value); break; case PROP_TYPE_FILTER_DATA: priv->type_filter_data = g_value_get_pointer (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static void nm_secret_agent_simple_get_secrets (NMSecretAgentOld *agent, NMConnection *connection, const gchar *connection_path, const gchar *setting_name, const gchar **hints, NMSecretAgentGetSecretsFlags flags, NMSecretAgentOldGetSecretsFunc callback, gpointer callback_data) { NMSecretAgentSimple *self = NM_SECRET_AGENT_SIMPLE (agent); NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE (self); NMSecretAgentSimpleRequest *request; NMSettingConnection *s_con; const char *connection_type; char *request_id; GError *error; request_id = g_strdup_printf ("%s/%s", connection_path, setting_name); if (g_hash_table_lookup (priv->requests, request_id) != NULL) { /* We already have a request pending for this (connection, setting) */ error = g_error_new (NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_FAILED, "Request for %s secrets already pending", request_id); nope: callback (agent, connection, NULL, error, callback_data); g_error_free (error); g_free (request_id); return; } s_con = nm_connection_get_setting_connection (connection); connection_type = nm_setting_connection_get_connection_type (s_con); if (!strcmp (connection_type, NM_SETTING_VPN_SETTING_NAME)) { /* We don't support VPN secrets yet */ error = g_error_new (NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_NO_SECRETS, "VPN secrets not supported"); goto nope; } if (!(flags & NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION)) { /* We don't do stored passwords */ error = g_error_new (NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_NO_SECRETS, "Stored passwords not supported"); goto nope; } request = g_slice_new (NMSecretAgentSimpleRequest); request->self = g_object_ref (self); request->connection = g_object_ref (connection); request->hints = g_strdupv ((gchar **)hints); request->callback = callback; request->callback_data = callback_data; request->request_id = request_id; g_hash_table_replace (priv->requests, request->request_id, request); if (priv->enabled) request_secrets_from_ui (request); }
static gboolean extract_details_from_connection (NMConnection *connection, const char *secrets_setting_name, const char **username, const char **password, GError **error) { NMSettingConnection *s_con; NMSetting *setting; const char *setting_name; g_return_val_if_fail (connection != NULL, FALSE); g_return_val_if_fail (username != NULL, FALSE); g_return_val_if_fail (password != NULL, FALSE); if (secrets_setting_name) setting_name = secrets_setting_name; else { /* Get the setting matching the connection type */ s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); setting_name = nm_setting_connection_get_connection_type (s_con); g_assert (setting_name); /* In case of bluetooth connection, use GSM or CDMA setting */ if (strcmp (setting_name, NM_SETTING_BLUETOOTH_SETTING_NAME) == 0) { if (nm_connection_get_setting_gsm (connection)) setting_name = NM_SETTING_GSM_SETTING_NAME; else setting_name = NM_SETTING_CDMA_SETTING_NAME; } } setting = nm_connection_get_setting_by_name (connection, setting_name); if (!setting) { /* This shouldn't ever happen */ g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_FAILED, "Missing type-specific setting; no secrets could be found."); return FALSE; } if (NM_IS_SETTING_PPPOE (setting)) { *username = nm_setting_pppoe_get_username (NM_SETTING_PPPOE (setting)); *password = nm_setting_pppoe_get_password (NM_SETTING_PPPOE (setting)); } else if (NM_IS_SETTING_ADSL (setting)) { *username = nm_setting_adsl_get_username (NM_SETTING_ADSL (setting)); *password = nm_setting_adsl_get_password (NM_SETTING_ADSL (setting)); } else if (NM_IS_SETTING_GSM (setting)) { *username = nm_setting_gsm_get_username (NM_SETTING_GSM (setting)); *password = nm_setting_gsm_get_password (NM_SETTING_GSM (setting)); } else if (NM_IS_SETTING_CDMA (setting)) { *username = nm_setting_cdma_get_username (NM_SETTING_CDMA (setting)); *password = nm_setting_cdma_get_password (NM_SETTING_CDMA (setting)); } return TRUE; }
static gboolean connection_compatible (NMDevice *device, NMConnection *connection, GError **error) { NMSettingConnection *s_con; NMSettingBluetooth *s_bt; const char *ctype; const GByteArray *mac; const char *hw_str; struct ether_addr *hw_mac; NMBluetoothCapabilities dev_caps; NMBluetoothCapabilities bt_type; g_return_val_if_fail (error == NULL || *error == NULL, FALSE); s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); ctype = nm_setting_connection_get_connection_type (s_con); if (strcmp (ctype, NM_SETTING_BLUETOOTH_SETTING_NAME) != 0) { g_set_error (error, NM_DEVICE_BT_ERROR, NM_DEVICE_BT_ERROR_NOT_BT_CONNECTION, "The connection was not a Bluetooth connection."); return FALSE; } s_bt = nm_connection_get_setting_bluetooth (connection); if (!s_bt) { g_set_error (error, NM_DEVICE_BT_ERROR, NM_DEVICE_BT_ERROR_INVALID_BT_CONNECTION, "The connection was not a valid Bluetooth connection."); return FALSE; } /* Check BT address */ hw_str = nm_device_bt_get_hw_address (NM_DEVICE_BT (device)); if (hw_str) { hw_mac = ether_aton (hw_str); if (!hw_mac) { g_set_error (error, NM_DEVICE_BT_ERROR, NM_DEVICE_BT_ERROR_INVALID_DEVICE_MAC, "Invalid device MAC address."); return FALSE; } mac = nm_setting_bluetooth_get_bdaddr (s_bt); if (mac && hw_mac && memcmp (mac->data, hw_mac->ether_addr_octet, ETH_ALEN)) { g_set_error (error, NM_DEVICE_BT_ERROR, NM_DEVICE_BT_ERROR_MAC_MISMATCH, "The MACs of the device and the connection didn't match."); return FALSE; } } dev_caps = nm_device_bt_get_capabilities (NM_DEVICE_BT (device)); bt_type = get_connection_bt_type (connection); if (!(bt_type & dev_caps)) { g_set_error (error, NM_DEVICE_BT_ERROR, NM_DEVICE_BT_ERROR_MISSING_DEVICE_CAPS, "The device missed BT capabilities required by the connection."); return FALSE; } return TRUE; }
static gboolean connection_compatible (NMDevice *device, NMConnection *connection, GError **error) { NMSettingConnection *s_con; NMSettingVlan *s_vlan; NMSettingWired *s_wired; const char *ctype, *dev_iface_name, *vlan_iface_name; const GByteArray *mac_address; char *mac_address_str; s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); ctype = nm_setting_connection_get_connection_type (s_con); if (strcmp (ctype, NM_SETTING_VLAN_SETTING_NAME) != 0) { g_set_error (error, NM_DEVICE_VLAN_ERROR, NM_DEVICE_VLAN_ERROR_NOT_VLAN_CONNECTION, "The connection was not a VLAN connection."); return FALSE; } s_vlan = nm_connection_get_setting_vlan (connection); if (!s_vlan) { g_set_error (error, NM_DEVICE_VLAN_ERROR, NM_DEVICE_VLAN_ERROR_INVALID_VLAN_CONNECTION, "The connection was not a valid VLAN connection."); return FALSE; } if (nm_setting_vlan_get_id (s_vlan) != nm_device_vlan_get_vlan_id (NM_DEVICE_VLAN (device))) { g_set_error (error, NM_DEVICE_VLAN_ERROR, NM_DEVICE_VLAN_ERROR_ID_MISMATCH, "The VLAN identifiers of the device and the connection didn't match."); return FALSE; } dev_iface_name = nm_device_get_iface (device); vlan_iface_name = nm_setting_vlan_get_interface_name (s_vlan); if (vlan_iface_name && g_strcmp0 (dev_iface_name, vlan_iface_name) != 0) { g_set_error (error, NM_DEVICE_VLAN_ERROR, NM_DEVICE_VLAN_ERROR_INTERFACE_MISMATCH, "The interfaces of the device and the connection didn't match."); return FALSE; } s_wired = nm_connection_get_setting_wired (connection); if (s_wired) mac_address = nm_setting_wired_get_mac_address (s_wired); else mac_address = NULL; if (mac_address) { mac_address_str = nm_utils_hwaddr_ntoa_len (mac_address->data, mac_address->len); if (!g_strcmp0 (mac_address_str, NM_DEVICE_VLAN_GET_PRIVATE (device)->hw_address)) { g_set_error (error, NM_DEVICE_VLAN_ERROR, NM_DEVICE_VLAN_ERROR_MAC_MISMATCH, "The hardware address of the device and the connection didn't match."); } g_free (mac_address_str); } return NM_DEVICE_CLASS (nm_device_vlan_parent_class)->connection_compatible (device, connection, error); }
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 NMDevice * find_vlan_parent (GSList *connections, NMApplet *applet) { const GPtrArray *devices; NMDevice *parent_device; GSList *iter; devices = nm_client_get_devices (applet->nm_client); if (!devices) return NULL; for (iter = connections; iter; iter = iter->next) { NMConnection *connection = iter->data; NMSettingVlan *s_vlan; const char *parent; s_vlan = nm_connection_get_setting_vlan (connection); g_return_val_if_fail (s_vlan != NULL, NULL); parent = nm_setting_vlan_get_parent (s_vlan); if (parent && nm_utils_iface_valid_name (parent)) { parent_device = find_device_by_iface (parent, devices); } else { NMSettingConnection *s_con; NMSetting *s_hw; const char *type; GByteArray *mac; s_con = nm_connection_get_setting_connection (connection); type = nm_setting_connection_get_connection_type (s_con); s_hw = nm_connection_get_setting_by_name (connection, type); if (!s_hw) { g_warn_if_reached (); continue; } if (!g_object_class_find_property (G_OBJECT_GET_CLASS (s_hw), "mac-address")) continue; g_object_get (G_OBJECT (s_hw), "mac-address", &mac, NULL); if (mac) { parent_device = find_device_by_mac (mac, devices); g_byte_array_unref (mac); } else parent_device = NULL; } if (parent_device) return parent_device; } return NULL; }
static gboolean check_ethernet_compatible (NMDeviceEthernet *device, NMConnection *connection, GError **error) { NMSettingConnection *s_con; NMSettingWired *s_wired; const char *connection_type; gboolean is_pppoe = FALSE; g_return_val_if_fail (error == NULL || *error == NULL, FALSE); s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION)); g_assert (s_con); connection_type = nm_setting_connection_get_connection_type (s_con); if ( strcmp (connection_type, NM_SETTING_WIRED_SETTING_NAME) && strcmp (connection_type, NM_SETTING_PPPOE_SETTING_NAME)) { g_set_error (error, 0, 0, "The connection was not a wired or PPPoE connection."); return FALSE; } if (!strcmp (connection_type, NM_SETTING_PPPOE_SETTING_NAME)) is_pppoe = TRUE; s_wired = (NMSettingWired *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRED); /* Wired setting is optional for PPPoE */ if (!is_pppoe && !s_wired) { g_set_error (error, 0, 0, "The connection was not a valid wired connection."); return FALSE; } if (s_wired) { const GByteArray *mac; const char *device_mac_str; struct ether_addr *device_mac; device_mac_str = nm_device_ethernet_get_hw_address (device); device_mac = ether_aton (device_mac_str); if (!device_mac) { g_set_error (error, 0, 0, "Invalid device MAC address."); return FALSE; } mac = nm_setting_wired_get_mac_address (s_wired); if (mac && memcmp (mac->data, device_mac->ether_addr_octet, ETH_ALEN)) { g_set_error (error, 0, 0, "The connection's MAC address did not match this device."); return FALSE; } } // FIXME: check bitrate against device capabilities return TRUE; }
static gboolean real_check_connection_compatible (NMDevice *device, NMConnection *connection, GError **error) { NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (device); NMSettingConnection *s_con; NMSettingBluetooth *s_bt; const GByteArray *array; char *str; int addr_match = FALSE; guint32 bt_type; s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION)); g_assert (s_con); if (strcmp (nm_setting_connection_get_connection_type (s_con), NM_SETTING_BLUETOOTH_SETTING_NAME)) { g_set_error (error, NM_BT_ERROR, NM_BT_ERROR_CONNECTION_NOT_BT, "The connection was not a Bluetooth connection."); return FALSE; } s_bt = NM_SETTING_BLUETOOTH (nm_connection_get_setting (connection, NM_TYPE_SETTING_BLUETOOTH)); if (!s_bt) { g_set_error (error, NM_BT_ERROR, NM_BT_ERROR_CONNECTION_INVALID, "The connection was not a valid Bluetooth connection."); return FALSE; } array = nm_setting_bluetooth_get_bdaddr (s_bt); if (!array || (array->len != ETH_ALEN)) { g_set_error (error, NM_BT_ERROR, NM_BT_ERROR_CONNECTION_INVALID, "The connection did not contain a valid Bluetooth address."); return FALSE; } bt_type = get_connection_bt_type (connection); if (!(bt_type & priv->capabilities)) { g_set_error (error, NM_BT_ERROR, NM_BT_ERROR_CONNECTION_INCOMPATIBLE, "The connection was not compatible with the device's capabilities."); return FALSE; } str = g_strdup_printf ("%02X:%02X:%02X:%02X:%02X:%02X", array->data[0], array->data[1], array->data[2], array->data[3], array->data[4], array->data[5]); addr_match = !strcmp (priv->bdaddr, str); g_free (str); return addr_match; }
static gboolean connection_compatible (NMDevice *device, NMConnection *connection, GError **error) { NMSettingConnection *s_con; NMSettingWired *s_wired; const char *ctype; gboolean is_pppoe = FALSE; s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); ctype = nm_setting_connection_get_connection_type (s_con); if (!strcmp (ctype, NM_SETTING_PPPOE_SETTING_NAME)) is_pppoe = TRUE; else if (strcmp (ctype, NM_SETTING_WIRED_SETTING_NAME) != 0) { g_set_error (error, NM_DEVICE_ETHERNET_ERROR, NM_DEVICE_ETHERNET_ERROR_NOT_ETHERNET_CONNECTION, "The connection was not a wired or PPPoE connection."); return FALSE; } s_wired = nm_connection_get_setting_wired (connection); /* Wired setting optional for PPPoE */ if (!is_pppoe && !s_wired) { g_set_error (error, NM_DEVICE_ETHERNET_ERROR, NM_DEVICE_ETHERNET_ERROR_INVALID_ETHERNET_CONNECTION, "The connection was not a valid ethernet connection."); return FALSE; } if (s_wired) { const GByteArray *mac; const char *perm_str; struct ether_addr *perm_mac; /* FIXME: filter using s390 subchannels when they are exported over the bus */ /* Check MAC address */ perm_str = nm_device_ethernet_get_permanent_hw_address (NM_DEVICE_ETHERNET (device)); if (perm_str) { perm_mac = ether_aton (perm_str); if (!perm_mac) { g_set_error (error, NM_DEVICE_ETHERNET_ERROR, NM_DEVICE_ETHERNET_ERROR_INVALID_DEVICE_MAC, "Invalid device MAC address."); return FALSE; } mac = nm_setting_wired_get_mac_address (s_wired); if (mac && perm_mac && memcmp (mac->data, perm_mac->ether_addr_octet, ETH_ALEN)) { g_set_error (error, NM_DEVICE_ETHERNET_ERROR, NM_DEVICE_ETHERNET_ERROR_MAC_MISMATCH, "The MACs of the device and the connection didn't match."); return FALSE; } } } return NM_DEVICE_CLASS (nm_device_ethernet_parent_class)->connection_compatible (device, connection, error); }
static GtkWidget * create_info_label_security (NMConnection *connection) { NMSettingConnection *s_con; char *label = NULL; GtkWidget *w; const char *connection_type; s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION)); g_assert (s_con); connection_type = nm_setting_connection_get_connection_type (s_con); if (!strcmp (connection_type, NM_SETTING_WIRELESS_SETTING_NAME)) { NMSettingWireless *s_wireless; NMSettingWirelessSecurity *s_wireless_sec; NMSetting8021x *s_8021x; const char *security; s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS)); s_wireless_sec = (NMSettingWirelessSecurity *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS_SECURITY); s_8021x = (NMSetting8021x *) nm_connection_get_setting (connection, NM_TYPE_SETTING_802_1X); security = s_wireless ? nm_setting_wireless_get_security (s_wireless) : NULL; if (security && !strcmp (security, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME) && s_wireless_sec) { const char *key_mgmt = nm_setting_wireless_security_get_key_mgmt (s_wireless_sec); if (!strcmp (key_mgmt, "none")) label = g_strdup (_("WEP")); else if (!strcmp (key_mgmt, "wpa-none")) label = g_strdup (_("WPA/WPA2")); else if (!strcmp (key_mgmt, "wpa-psk")) label = g_strdup (_("WPA/WPA2")); else label = get_eap_label (s_wireless_sec, s_8021x); } else { label = g_strdup (_("None")); } } else if (!strcmp (connection_type, NM_SETTING_WIRED_SETTING_NAME)) { NMSetting8021x *s_8021x; s_8021x = (NMSetting8021x *) nm_connection_get_setting (connection, NM_TYPE_SETTING_802_1X); if (s_8021x) label = get_eap_label (NULL, s_8021x); else label = g_strdup (_("None")); } w = create_info_label (label ? label : _("Unknown"), TRUE); g_free (label); return w; }
static gboolean check_wifi_compatible (NMDeviceWifi *device, NMConnection *connection, GError **error) { NMSettingConnection *s_con; NMSettingWireless *s_wireless; g_return_val_if_fail (error == NULL || *error == NULL, FALSE); s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION)); g_assert (s_con); if (strcmp (nm_setting_connection_get_connection_type (s_con), NM_SETTING_WIRELESS_SETTING_NAME)) { g_set_error (error, 0, 0, "The connection was not a WiFi connection."); return FALSE; } s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS)); if (!s_wireless) { g_set_error (error, 0, 0, "The connection was not a valid WiFi connection."); return FALSE; } if (s_wireless) { const GByteArray *mac; const char *device_mac_str; struct ether_addr *device_mac; device_mac_str = nm_device_wifi_get_hw_address (device); device_mac = ether_aton (device_mac_str); if (!device_mac) { g_set_error (error, 0, 0, "Invalid device MAC address."); return FALSE; } mac = nm_setting_wireless_get_mac_address (s_wireless); if (mac && memcmp (mac->data, device_mac->ether_addr_octet, ETH_ALEN)) { g_set_error (error, 0, 0, "The connection's MAC address did not match this device."); return FALSE; } } // FIXME: check channel/freq/band against bands the hardware supports // FIXME: check encryption against device capabilities // FIXME: check bitrate against device capabilities return TRUE; }
static gboolean connection_compatible (NMDevice *device, NMConnection *connection, GError **error) { NMSettingConnection *s_con; NMSettingInfiniband *s_infiniband; const char *ctype, *hwaddr_str; const GByteArray *mac; guint8 *hwaddr, hwaddr_buf[INFINIBAND_ALEN]; s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); ctype = nm_setting_connection_get_connection_type (s_con); if (strcmp (ctype, NM_SETTING_INFINIBAND_SETTING_NAME) != 0) { g_set_error (error, NM_DEVICE_INFINIBAND_ERROR, NM_DEVICE_INFINIBAND_ERROR_NOT_INFINIBAND_CONNECTION, "The connection was not a InfiniBand connection."); return FALSE; } s_infiniband = nm_connection_get_setting_infiniband (connection); if (!s_infiniband) { g_set_error (error, NM_DEVICE_INFINIBAND_ERROR, NM_DEVICE_INFINIBAND_ERROR_INVALID_INFINIBAND_CONNECTION, "The connection was not a valid InfiniBand connection."); return FALSE; } hwaddr_str = nm_device_infiniband_get_hw_address (NM_DEVICE_INFINIBAND (device)); if (hwaddr_str) { hwaddr = nm_utils_hwaddr_aton (hwaddr_str, ARPHRD_INFINIBAND, hwaddr_buf); if (!hwaddr) { g_set_error (error, NM_DEVICE_INFINIBAND_ERROR, NM_DEVICE_INFINIBAND_ERROR_INVALID_DEVICE_MAC, "Invalid device MAC address."); return FALSE; } mac = nm_setting_infiniband_get_mac_address (s_infiniband); /* We only match against the last 8 bytes */ if (mac && hwaddr && memcmp (mac->data + INFINIBAND_ALEN - 8, hwaddr + INFINIBAND_ALEN - 8, 8)) { g_set_error (error, NM_DEVICE_INFINIBAND_ERROR, NM_DEVICE_INFINIBAND_ERROR_MAC_MISMATCH, "The MACs of the device and the connection didn't match."); return FALSE; } } return NM_DEVICE_CLASS (nm_device_infiniband_parent_class)->connection_compatible (device, connection, error); }
static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { NMSettingConnection *setting = NM_SETTING_CONNECTION (object); NMSettingConnectionPrivate *priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting); switch (prop_id) { case PROP_ID: g_value_set_string (value, nm_setting_connection_get_id (setting)); break; case PROP_UUID: g_value_set_string (value, nm_setting_connection_get_uuid (setting)); break; case PROP_TYPE: g_value_set_string (value, nm_setting_connection_get_connection_type (setting)); break; case PROP_PERMISSIONS: g_value_take_boxed (value, perm_permlist_to_stringlist (priv->permissions)); break; case PROP_AUTOCONNECT: g_value_set_boolean (value, nm_setting_connection_get_autoconnect (setting)); break; case PROP_TIMESTAMP: g_value_set_uint64 (value, nm_setting_connection_get_timestamp (setting)); break; case PROP_READ_ONLY: g_value_set_boolean (value, nm_setting_connection_get_read_only (setting)); break; case PROP_ZONE: g_value_set_string (value, nm_setting_connection_get_zone (setting)); break; case PROP_MASTER: g_value_set_string (value, nm_setting_connection_get_master (setting)); break; case PROP_SLAVE_TYPE: g_value_set_string (value, nm_setting_connection_get_slave_type (setting)); break; case PROP_SECONDARIES: g_value_set_boxed (value, priv->secondaries); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static int get_sort_order_for_connection (NMConnection *conn) { NMSettingConnection *s_con; const char *type; int i; s_con = nm_connection_get_setting_connection (conn); type = nm_setting_connection_get_connection_type (s_con); for (i = 0; i < device_sort_order_len; i++) { if (!strcmp (type, device_sort_order[i])) return i; } return -1; }
static gboolean connection_compatible (NMDevice *device, NMConnection *connection, GError **error) { NMSettingConnection *s_con; NMSettingWimax *s_wimax; const char *ctype; const GByteArray *mac; const char *hw_str; struct ether_addr *hw_mac; s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); ctype = nm_setting_connection_get_connection_type (s_con); if (strcmp (ctype, NM_SETTING_WIMAX_SETTING_NAME) != 0) { g_set_error (error, NM_DEVICE_WIMAX_ERROR, NM_DEVICE_WIMAX_ERROR_NOT_WIMAX_CONNECTION, "The connection was not a Wimax connection."); return FALSE; } s_wimax = nm_connection_get_setting_wimax (connection); if (!s_wimax) { g_set_error (error, NM_DEVICE_WIMAX_ERROR, NM_DEVICE_WIMAX_ERROR_INVALID_WIMAX_CONNECTION, "The connection was not a valid Wimax connection."); return FALSE; } /* Check MAC address */ hw_str = nm_device_wimax_get_hw_address (NM_DEVICE_WIMAX (device)); if (hw_str) { hw_mac = ether_aton (hw_str); if (!hw_mac) { g_set_error (error, NM_DEVICE_WIMAX_ERROR, NM_DEVICE_WIMAX_ERROR_INVALID_DEVICE_MAC, "Invalid device MAC address."); return FALSE; } mac = nm_setting_wimax_get_mac_address (s_wimax); if (mac && hw_mac && memcmp (mac->data, hw_mac->ether_addr_octet, ETH_ALEN)) { g_set_error (error, NM_DEVICE_WIMAX_ERROR, NM_DEVICE_WIMAX_ERROR_MAC_MISMATCH, "The MACs of the device and the connection didn't match."); return FALSE; } } return NM_DEVICE_CLASS (nm_device_wimax_parent_class)->connection_compatible (device, connection, error); }
static NMConnection * real_get_best_auto_connection (NMDevice *device, GSList *connections, char **specific_object) { NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (device); GSList *iter; for (iter = connections; iter; iter = g_slist_next (iter)) { NMConnection *connection = NM_CONNECTION (iter->data); NMSettingConnection *s_con; NMSettingWimax *s_wimax; const char *connection_type; const GByteArray *mac; 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; connection_type = nm_setting_connection_get_connection_type (s_con); if (strcmp (connection_type, NM_SETTING_WIMAX_SETTING_NAME)) continue; s_wimax = (NMSettingWimax *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIMAX); if (!s_wimax) continue; mac = nm_setting_wimax_get_mac_address (s_wimax); if (mac && memcmp (mac->data, priv->hw_addr.ether_addr_octet, ETH_ALEN)) continue; for (iter = priv->nsp_list; iter; iter = iter->next) { NMWimaxNsp *nsp = NM_WIMAX_NSP (iter->data); if (nm_wimax_nsp_check_compatible (nsp, connection)) { *specific_object = (char *) nm_wimax_nsp_get_dbus_path (nsp); return connection; } } } return NULL; }
static gboolean check_connection_compatible (NMDevice *device, NMConnection *connection, GError **error) { NMSettingConnection *s_con; NMSettingWimax *s_wimax; const char *connection_type; const GByteArray *mac; if (!NM_DEVICE_CLASS (nm_device_wimax_parent_class)->check_connection_compatible (device, connection, error)) return FALSE; s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); connection_type = nm_setting_connection_get_connection_type (s_con); if (strcmp (connection_type, NM_SETTING_WIMAX_SETTING_NAME)) { g_set_error (error, NM_WIMAX_ERROR, NM_WIMAX_ERROR_CONNECTION_NOT_WIMAX, "The connection was not a WiMAX connection."); return FALSE; } s_wimax = nm_connection_get_setting_wimax (connection); if (!s_wimax) { g_set_error (error, NM_WIMAX_ERROR, NM_WIMAX_ERROR_CONNECTION_INVALID, "The connection was not a valid WiMAX connection."); return FALSE; } mac = nm_setting_wimax_get_mac_address (s_wimax); if (mac && memcmp (mac->data, nm_device_get_hw_address (device, NULL), ETH_ALEN)) { g_set_error (error, NM_WIMAX_ERROR, NM_WIMAX_ERROR_CONNECTION_INCOMPATIBLE, "The connection's MAC address did not match this device."); return FALSE; } return TRUE; }
static gboolean is_connection_always_ask (NMConnection *connection) { NMSettingConnection *s_con; const char *ctype; NMSetting *setting; /* For the given connection type, check if the secrets for that connection * are always-ask or not. */ s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); ctype = nm_setting_connection_get_connection_type (s_con); setting = nm_connection_get_setting_by_name (connection, ctype); g_return_val_if_fail (setting != NULL, FALSE); if (has_always_ask (setting)) return TRUE; /* Try type-specific settings too; be a bit paranoid and only consider * secrets from settings relevant to the connection type. */ if (NM_IS_SETTING_WIRELESS (setting)) { setting = nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS_SECURITY); if (setting && has_always_ask (setting)) return TRUE; setting = nm_connection_get_setting (connection, NM_TYPE_SETTING_802_1X); if (setting && has_always_ask (setting)) return TRUE; } else if (NM_IS_SETTING_WIRED (setting)) { setting = nm_connection_get_setting (connection, NM_TYPE_SETTING_PPPOE); if (setting && has_always_ask (setting)) return TRUE; setting = nm_connection_get_setting (connection, NM_TYPE_SETTING_802_1X); if (setting && has_always_ask (setting)) return TRUE; } return FALSE; }