static gboolean validate (CEPage *page, NMConnection *connection, GError **error) { CEPageWired *self = CE_PAGE_WIRED (page); CEPageWiredPrivate *priv = CE_PAGE_WIRED_GET_PRIVATE (self); gboolean invalid = FALSE; GByteArray *ignore; GtkWidget *entry; entry = gtk_bin_get_child (GTK_BIN (priv->device_mac)); if (entry) { ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), &invalid); if (invalid) return FALSE; if (ignore) g_byte_array_free (ignore, TRUE); } ignore = ce_page_entry_to_mac (priv->cloned_mac, &invalid); if (invalid) return FALSE; if (ignore) g_byte_array_free (ignore, TRUE); ui_to_setting (self); return nm_setting_verify (NM_SETTING (priv->setting), NULL, error); }
static gboolean validate (CEPage *page, NMConnection *connection, GError **error) { GtkWidget *entry; GByteArray *ignore; gboolean invalid; gchar *security; NMSettingWireless *setting; gboolean ret = TRUE; entry = gtk_bin_get_child (GTK_BIN (gtk_builder_get_object (page->builder, "combo_bssid"))); ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, &invalid); if (invalid) { widget_set_error (entry); ret = FALSE; } else { if (ignore) g_byte_array_free (ignore, TRUE); widget_unset_error (entry); } entry = gtk_bin_get_child (GTK_BIN (gtk_builder_get_object (page->builder, "combo_mac"))); ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, &invalid); if (invalid) { widget_set_error (entry); ret = FALSE; } else { if (ignore) g_byte_array_free (ignore, TRUE); widget_unset_error (entry); } entry = GTK_WIDGET (gtk_builder_get_object (page->builder, "entry_cloned_mac")); ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, &invalid); if (invalid) { widget_set_error (entry); ret = FALSE; } else { if (ignore) g_byte_array_free (ignore, TRUE); widget_unset_error (entry); } if (!ret) return ret; ui_to_setting (CE_PAGE_WIFI (page)); /* A hack to not check the wifi security here */ setting = CE_PAGE_WIFI (page)->setting; security = g_strdup (nm_setting_wireless_get_security (setting)); g_object_set (setting, NM_SETTING_WIRELESS_SEC, NULL, NULL); ret = nm_setting_verify (NM_SETTING (setting), NULL, error); g_object_set (setting, NM_SETTING_WIRELESS_SEC, security, NULL); g_free (security); return ret; }
static gboolean validate (CEPage *page, NMConnection *connection, GError **error) { CEPageWireless *self = CE_PAGE_WIRELESS (page); CEPageWirelessPrivate *priv = CE_PAGE_WIRELESS_GET_PRIVATE (self); char *security; gboolean success; gboolean invalid = FALSE; GByteArray *ignore; ignore = ce_page_entry_to_mac (priv->bssid, &invalid); if (invalid) return FALSE; ignore = ce_page_entry_to_mac (priv->mac, &invalid); if (invalid) return FALSE; ui_to_setting (self); /* A hack to not check the wireless security here */ security = g_strdup (nm_setting_wireless_get_security (priv->setting)); g_object_set (priv->setting, NM_SETTING_WIRELESS_SEC, NULL, NULL); success = nm_setting_verify (NM_SETTING (priv->setting), NULL, error); g_object_set (priv->setting, NM_SETTING_WIRELESS_SEC, security, NULL); g_free (security); return success; }
static gboolean ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error) { CEPageWifi *self = CE_PAGE_WIFI (page); CEPageWifiPrivate *priv = CE_PAGE_WIFI_GET_PRIVATE (self); gboolean success; GtkWidget *entry; entry = gtk_bin_get_child (GTK_BIN (priv->bssid)); if (entry) { if (!ce_page_mac_entry_valid (GTK_ENTRY (entry), ARPHRD_ETHER, _("bssid"), error)) return FALSE; } entry = gtk_bin_get_child (GTK_BIN (priv->device_combo)); if (entry) { if (!ce_page_device_entry_get (GTK_ENTRY (entry), ARPHRD_ETHER, TRUE, NULL, NULL, _("Wi-Fi device"), error)) return FALSE; } if (!ce_page_mac_entry_valid (priv->cloned_mac, ARPHRD_ETHER, _("cloned MAC"), error)) return FALSE; ui_to_setting (self); success = nm_setting_verify (NM_SETTING (priv->setting), NULL, error); return success; }
static gboolean complete_connection (NMDevice *device, NMConnection *connection, const char *specific_object, const GSList *existing_connections, GError **error) { NMSettingAdsl *s_adsl; /* * We can't telepathically figure out the username, so if * it wasn't given, we can't complete the connection. */ s_adsl = nm_connection_get_setting_adsl (connection); if (s_adsl && !nm_setting_verify (NM_SETTING (s_adsl), NULL, error)) return FALSE; nm_utils_complete_generic (connection, NM_SETTING_ADSL_SETTING_NAME, existing_connections, _("ADSL connection %d"), NULL, FALSE); /* No IPv6 yet by default */ return TRUE; }
static gboolean ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error) { CEPageBridgePort *self = CE_PAGE_BRIDGE_PORT (page); CEPageBridgePortPrivate *priv = CE_PAGE_BRIDGE_PORT_GET_PRIVATE (self); ui_to_setting (self); return nm_setting_verify (NM_SETTING (priv->setting), NULL, error); }
static gboolean validate (CEPage *page, NMConnection *connection, GError **error) { CEPagePpp *self = CE_PAGE_PPP (page); CEPagePppPrivate *priv = CE_PAGE_PPP_GET_PRIVATE (self); ui_to_setting (self); return nm_setting_verify (NM_SETTING (priv->setting), NULL, error); }
static gboolean validate (CEPage *page, NMConnection *connection, GError **error) { CEPageMobile *self = CE_PAGE_MOBILE (page); CEPageMobilePrivate *priv = CE_PAGE_MOBILE_GET_PRIVATE (self); ui_to_setting (self); return nm_setting_verify (priv->setting, NULL, error); }
static gboolean ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error) { CEPageDsl *self = CE_PAGE_DSL (page); CEPageDslPrivate *priv = CE_PAGE_DSL_GET_PRIVATE (self); ui_to_setting (self); return nm_setting_verify (NM_SETTING (priv->setting), connection, error); }
static gboolean ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error) { CEPageIP4 *self = CE_PAGE_IP4 (page); CEPageIP4Private *priv = CE_PAGE_IP4_GET_PRIVATE (self); if (!ui_to_setting (self, error)) return FALSE; return nm_setting_verify (NM_SETTING (priv->setting), NULL, error); }
static gboolean validate (CEPage *page, NMConnection *connection, GError **error) { if (!ui_to_setting (CE_PAGE_IP6 (page))) return FALSE; return nm_setting_verify (NM_SETTING (CE_PAGE_IP6 (page)->setting), NULL, error); }
static gboolean validate (CEPage *page, NMConnection *connection, GError **error) { CEPageEthernet *self = CE_PAGE_ETHERNET (page); gboolean invalid = FALSE; GByteArray *ignore; GtkWidget *entry; gboolean ret = TRUE; entry = gtk_bin_get_child (GTK_BIN (self->device_mac)); if (entry) { ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, &invalid); if (invalid) { widget_set_error (entry); ret = FALSE; } else { if (ignore) g_byte_array_free (ignore, TRUE); widget_unset_error (entry); } } ignore = ce_page_entry_to_mac (self->cloned_mac, ARPHRD_ETHER, &invalid); if (invalid) { widget_set_error (GTK_WIDGET (self->cloned_mac)); ret = FALSE; } else { if (ignore) g_byte_array_free (ignore, TRUE); widget_unset_error (GTK_WIDGET (self->cloned_mac)); } if (!ret) return ret; ui_to_setting (self); return nm_setting_verify (NM_SETTING (self->setting_connection), NULL, error) && nm_setting_verify (NM_SETTING (self->setting_wired), NULL, error); }
static gboolean ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error) { CEPageBluetooth *self = CE_PAGE_BLUETOOTH (page); CEPageBluetoothPrivate *priv = CE_PAGE_BLUETOOTH_GET_PRIVATE (self); if (!ce_page_mac_entry_valid (priv->bdaddr, ARPHRD_ETHER, _("bdaddr"), error)) return FALSE; ui_to_setting (self); return nm_setting_verify (NM_SETTING (priv->setting), NULL, error); }
static gboolean validate (CEPage *page, NMConnection *connection, GError **error) { CEPageBond *self = CE_PAGE_BOND (page); CEPageBondPrivate *priv = CE_PAGE_BOND_GET_PRIVATE (self); if (!CE_PAGE_CLASS (ce_page_bond_parent_class)->validate (page, connection, error)) return FALSE; ui_to_setting (self); return nm_setting_verify (NM_SETTING (priv->setting), NULL, error); }
static gboolean validate (CEPage *page, NMConnection *connection, GError **error) { CEPageVlan *self = CE_PAGE_VLAN (page); CEPageVlanPrivate *priv = CE_PAGE_VLAN_GET_PRIVATE (self); gboolean invalid = FALSE; GByteArray *ignore; int parent_id; const char *parent; char *parent_iface; parent_id = gtk_combo_box_get_active (GTK_COMBO_BOX (priv->parent)); if (parent_id == -1) { gboolean valid; parent = gtk_entry_get_text (priv->parent_entry); parent_iface = g_strndup (parent, strcspn (parent, " ")); valid = nm_utils_iface_valid_name (parent_iface); g_free (parent_iface); if (!valid) return FALSE; } ignore = ce_page_entry_to_mac (priv->cloned_mac, ARPHRD_ETHER, &invalid); if (invalid) return FALSE; if (ignore) g_byte_array_free (ignore, TRUE); ui_to_setting (self); if ( priv->s_hw && !nm_setting_verify (priv->s_hw, NULL, error)) return FALSE; return nm_setting_verify (NM_SETTING (priv->setting), NULL, error); }
static void test_setting_gsm_apn_bad_chars (void) { NMSettingGsm *s_gsm; s_gsm = (NMSettingGsm *) nm_setting_gsm_new (); ASSERT (s_gsm != NULL, "gsm-apn-bad-chars", "error creating GSM setting"); g_object_set (s_gsm, NM_SETTING_GSM_NUMBER, "*99#", NULL); /* Make sure a valid APN works */ g_object_set (s_gsm, NM_SETTING_GSM_APN, "foobar123.-baz", NULL); ASSERT (nm_setting_verify (NM_SETTING (s_gsm), NULL, NULL) == TRUE, "gsm-apn-bad-chars", "unexpectedly invalid GSM setting"); /* Random invalid chars */ g_object_set (s_gsm, NM_SETTING_GSM_APN, "@#%$@#%@#%", NULL); ASSERT (nm_setting_verify (NM_SETTING (s_gsm), NULL, NULL) == FALSE, "gsm-apn-bad-chars", "unexpectedly valid GSM setting"); /* Spaces */ g_object_set (s_gsm, NM_SETTING_GSM_APN, "foobar baz", NULL); ASSERT (nm_setting_verify (NM_SETTING (s_gsm), NULL, NULL) == FALSE, "gsm-apn-bad-chars", "unexpectedly valid GSM setting"); /* 0 characters long */ g_object_set (s_gsm, NM_SETTING_GSM_APN, "", NULL); ASSERT (nm_setting_verify (NM_SETTING (s_gsm), NULL, NULL) == FALSE, "gsm-apn-bad-chars", "unexpectedly valid GSM setting"); /* 65-character long */ g_object_set (s_gsm, NM_SETTING_GSM_APN, "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl1", NULL); ASSERT (nm_setting_verify (NM_SETTING (s_gsm), NULL, NULL) == FALSE, "gsm-apn-bad-chars", "unexpectedly valid GSM setting"); }
static gboolean validate (CEPage *page, NMConnection *connection, GError **error) { CEPageWired *self = CE_PAGE_WIRED (page); CEPageWiredPrivate *priv = CE_PAGE_WIRED_GET_PRIVATE (self); gboolean invalid = FALSE; GByteArray *ignore; ignore = ce_page_entry_to_mac (priv->mac, &invalid); if (invalid) return FALSE; ui_to_setting (self); return nm_setting_verify (NM_SETTING (priv->setting), NULL, error); }
static gboolean ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error) { CEPageBond *self = CE_PAGE_BOND (page); CEPageBondPrivate *priv = CE_PAGE_BOND_GET_PRIVATE (self); if (!CE_PAGE_CLASS (ce_page_bond_parent_class)->ce_page_validate_v (page, connection, error)) return FALSE; if (!ce_page_interface_name_valid (gtk_entry_get_text (priv->primary), _("primary"), error)) return FALSE; ui_to_setting (self); return nm_setting_verify (NM_SETTING (priv->setting), connection, error); }
static gboolean validate (CEPage *page, NMConnection *connection, GError **error) { CEPageWifi *self = CE_PAGE_WIFI (page); CEPageWifiPrivate *priv = CE_PAGE_WIFI_GET_PRIVATE (self); char *security; gboolean success; gboolean invalid = FALSE; GByteArray *ignore; GtkWidget *entry; entry = gtk_bin_get_child (GTK_BIN (priv->bssid)); if (entry) { ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, &invalid); if (invalid) return FALSE; if (ignore) g_byte_array_free (ignore, TRUE); } entry = gtk_bin_get_child (GTK_BIN (priv->device_mac)); if (entry) { ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, &invalid); if (invalid) return FALSE; if (ignore) g_byte_array_free (ignore, TRUE); } ignore = ce_page_entry_to_mac (priv->cloned_mac, ARPHRD_ETHER, &invalid); if (invalid) return FALSE; if (ignore) g_byte_array_free (ignore, TRUE); ui_to_setting (self); /* A hack to not check the wifi security here */ security = g_strdup (nm_setting_wireless_get_security (priv->setting)); g_object_set (priv->setting, NM_SETTING_WIRELESS_SEC, NULL, NULL); success = nm_setting_verify (NM_SETTING (priv->setting), NULL, error); g_object_set (priv->setting, NM_SETTING_WIRELESS_SEC, security, NULL); g_free (security); return success; }
static gboolean validate (CEPage *page, NMConnection *connection, GError **error) { CEPageInfiniband *self = CE_PAGE_INFINIBAND (page); CEPageInfinibandPrivate *priv = CE_PAGE_INFINIBAND_GET_PRIVATE (self); GtkWidget *entry; char buf[INFINIBAND_ALEN]; const char *hwaddr; entry = gtk_bin_get_child (GTK_BIN (priv->device_mac)); hwaddr = gtk_entry_get_text (GTK_ENTRY (entry)); if (hwaddr && *hwaddr && !nm_utils_hwaddr_aton (hwaddr, ARPHRD_INFINIBAND, buf)) return FALSE; ui_to_setting (self); return nm_setting_verify (NM_SETTING (priv->setting), NULL, error); }
static gboolean ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error) { CEPageDcb *self = CE_PAGE_DCB (page); CEPageDcbPrivate *priv = CE_PAGE_DCB_GET_PRIVATE (self); NMSettingDcb *s_dcb; if (!gtk_toggle_button_get_active (priv->enabled)) { nm_connection_remove_setting (connection, NM_TYPE_SETTING_DCB); return TRUE; } s_dcb = nm_connection_get_setting_dcb (connection); if (!s_dcb) { s_dcb = (NMSettingDcb *) nm_setting_dcb_new (); nm_connection_add_setting (connection, NM_SETTING (s_dcb)); } ui_to_setting (self, s_dcb); return nm_setting_verify (NM_SETTING (s_dcb), NULL, error); }
static gboolean validate (CEPage *page, NMConnection *connection, GError **error) { CEPageVpn *self = CE_PAGE_VPN (page); GtkWidget *widget; g_object_set (self->setting_connection, NM_SETTING_CONNECTION_ID, gtk_entry_get_text (self->name), NULL); widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "combo_zone")); firewall_ui_to_setting (self->setting_connection, widget); if (!nm_setting_verify (NM_SETTING (self->setting_connection), NULL, error)) return FALSE; if (!self->ui) return TRUE; return nm_vpn_plugin_ui_widget_interface_update_connection (self->ui, connection, error); }
static gboolean complete_connection (NMDevice *device, NMConnection *connection, const char *specific_object, const GSList *existing_connections, GError **error) { NMDeviceWimax *self = NM_DEVICE_WIMAX (device); NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self); NMSettingWimax *s_wimax; const char *setting_mac; const char *hw_address; const char *nsp_name = NULL; NMWimaxNsp *nsp = NULL; GSList *iter; s_wimax = nm_connection_get_setting_wimax (connection); if (!specific_object) { /* If not given a specific object, we need at minimum an NSP name */ if (!s_wimax) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION, "A 'wimax' setting is required if no NSP path was given."); return FALSE; } nsp_name = nm_setting_wimax_get_network_name (s_wimax); if (!nsp_name || !strlen (nsp_name)) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION, "A 'wimax' setting with a valid network name is required if no NSP path was given."); return FALSE; } /* Find a compatible NSP in the list */ nsp = get_nsp_by_name (self, nsp_name); /* If we still don't have an NSP, then the WiMAX settings needs to be * fully specified by the client. Might not be able to find the NSP * if the scan didn't find the NSP yet. */ if (!nsp) { if (!nm_setting_verify (NM_SETTING (s_wimax), NULL, error)) return FALSE; } } else { /* Find a compatible NSP in the list */ for (iter = priv->nsp_list; iter; iter = g_slist_next (iter)) { if (!strcmp (specific_object, nm_wimax_nsp_get_dbus_path (NM_WIMAX_NSP (iter->data)))) { nsp = NM_WIMAX_NSP (iter->data); break; } } if (!nsp) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_SPECIFIC_OBJECT_NOT_FOUND, "The NSP %s was not in the scan list.", specific_object); return FALSE; } nsp_name = nm_wimax_nsp_get_name (nsp); } /* Add a WiMAX setting if one doesn't exist */ if (!s_wimax) { s_wimax = (NMSettingWimax *) nm_setting_wimax_new (); nm_connection_add_setting (connection, NM_SETTING (s_wimax)); } g_assert (nsp_name); nm_utils_complete_generic (connection, NM_SETTING_WIMAX_SETTING_NAME, existing_connections, nsp_name, nsp_name, NULL, TRUE); g_object_set (G_OBJECT (s_wimax), NM_SETTING_WIMAX_NETWORK_NAME, nsp_name, NULL); setting_mac = nm_setting_wimax_get_mac_address (s_wimax); hw_address = nm_device_get_hw_address (device); if (setting_mac) { /* Make sure the setting MAC (if any) matches the device's permanent MAC */ if (!nm_utils_hwaddr_matches (setting_mac, -1, hw_address, -1)) { g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, _("connection does not match device")); g_prefix_error (error, "%s.%s: ", NM_SETTING_WIMAX_SETTING_NAME, NM_SETTING_WIMAX_MAC_ADDRESS); return FALSE; } } else { /* Lock the connection to this device by default */ if (!nm_utils_hwaddr_matches (hw_address, -1, NULL, ETH_ALEN)) g_object_set (G_OBJECT (s_wimax), NM_SETTING_WIMAX_MAC_ADDRESS, hw_address, NULL); } return TRUE; }
gboolean nm_ap_utils_complete_connection (const GByteArray *ap_ssid, const guint8 ap_bssid[ETH_ALEN], NM80211Mode ap_mode, guint32 ap_flags, guint32 ap_wpa_flags, guint32 ap_rsn_flags, NMConnection *connection, gboolean lock_bssid, GError **error) { NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; NMSetting8021x *s_8021x; const GByteArray *ssid; const char *mode, *key_mgmt, *auth_alg, *leap_username; gboolean adhoc = FALSE; s_wifi = nm_connection_get_setting_wireless (connection); g_assert (s_wifi); s_wsec = nm_connection_get_setting_wireless_security (connection); s_8021x = nm_connection_get_setting_802_1x (connection); /* Fill in missing SSID */ ssid = nm_setting_wireless_get_ssid (s_wifi); if (!ssid) g_object_set (G_OBJECT (s_wifi), NM_SETTING_WIRELESS_SSID, ap_ssid, NULL); else if ( ssid->len != ap_ssid->len || memcmp (ssid->data, ap_ssid->data, ssid->len)) { g_set_error_literal (error, NM_SETTING_WIRELESS_ERROR, NM_SETTING_WIRELESS_ERROR_INVALID_PROPERTY, "Setting SSID did not match AP SSID"); return FALSE; } if (lock_bssid && !nm_setting_wireless_get_bssid (s_wifi)) { GByteArray *bssid; bssid = g_byte_array_sized_new (ETH_ALEN); g_byte_array_append (bssid, ap_bssid, ETH_ALEN); g_object_set (G_OBJECT (s_wifi), NM_SETTING_WIRELESS_BSSID, bssid, NULL); g_byte_array_free (bssid, TRUE); } /* And mode */ mode = nm_setting_wireless_get_mode (s_wifi); if (mode) { gboolean valid = FALSE; /* Make sure the supplied mode matches the AP's */ if (!strcmp (mode, NM_SETTING_WIRELESS_MODE_INFRA)) { if (ap_mode == NM_802_11_MODE_INFRA) valid = TRUE; } else if (!strcmp (mode, NM_SETTING_WIRELESS_MODE_ADHOC)) { if (ap_mode == NM_802_11_MODE_ADHOC) valid = TRUE; adhoc = TRUE; } if (valid == FALSE) { g_set_error (error, NM_SETTING_WIRELESS_ERROR, NM_SETTING_WIRELESS_ERROR_INVALID_PROPERTY, NM_SETTING_WIRELESS_MODE); return FALSE; } } else { mode = NM_SETTING_WIRELESS_MODE_INFRA; if (ap_mode == NM_802_11_MODE_ADHOC) { mode = NM_SETTING_WIRELESS_MODE_ADHOC; adhoc = TRUE; } g_object_set (G_OBJECT (s_wifi), NM_SETTING_WIRELESS_MODE, mode, NULL); } /* Security */ /* Open */ if ( !(ap_flags & NM_802_11_AP_FLAGS_PRIVACY) && (ap_wpa_flags == NM_802_11_AP_SEC_NONE) && (ap_rsn_flags == NM_802_11_AP_SEC_NONE)) { /* Make sure the connection doesn't specify security */ if (nm_setting_wireless_get_security (s_wifi) || s_wsec || s_8021x) { g_set_error_literal (error, NM_SETTING_WIRELESS_SECURITY_ERROR, NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, "AP is unencrypted but setting specifies security"); return FALSE; } return TRUE; } /* Everything else requires security */ g_object_set (G_OBJECT (s_wifi), NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NULL); if (!s_wsec) { s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); nm_connection_add_setting (connection, NM_SETTING (s_wsec)); } key_mgmt = nm_setting_wireless_security_get_key_mgmt (s_wsec); auth_alg = nm_setting_wireless_security_get_auth_alg (s_wsec); leap_username = nm_setting_wireless_security_get_leap_username (s_wsec); /* Ad-Hoc checks */ if (!verify_adhoc (s_wsec, s_8021x, adhoc, error)) return FALSE; /* Static WEP, Dynamic WEP, or LEAP */ if ( (ap_flags & NM_802_11_AP_FLAGS_PRIVACY) && (ap_wpa_flags == NM_802_11_AP_SEC_NONE) && (ap_rsn_flags == NM_802_11_AP_SEC_NONE)) { const char *tag = "WEP"; gboolean is_dynamic_wep = FALSE; if (!verify_leap (s_wsec, s_8021x, adhoc, error)) return FALSE; if (leap_username) { tag = "LEAP"; } else { /* Static or Dynamic WEP */ if (!verify_dynamic_wep (s_wsec, s_8021x, adhoc, error)) return FALSE; if (s_8021x || (key_mgmt && !strcmp (key_mgmt, "ieee8021x"))) { is_dynamic_wep = TRUE; tag = "Dynamic WEP"; } } /* Nothing WPA-related can be set */ if (!verify_no_wpa (s_wsec, tag, error)) return FALSE; if (leap_username) { /* LEAP */ g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x", NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "leap", NULL); } else if (is_dynamic_wep) { /* Dynamic WEP */ g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x", NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "open", NULL); nm_setting_wireless_security_add_pairwise (s_wsec, "wep40"); nm_setting_wireless_security_add_pairwise (s_wsec, "wep104"); nm_setting_wireless_security_add_group (s_wsec, "wep40"); nm_setting_wireless_security_add_group (s_wsec, "wep104"); if (s_8021x) { /* Dynamic WEP requires a valid 802.1x setting since we can't * autocomplete 802.1x. */ if (!nm_setting_verify (NM_SETTING (s_8021x), NULL, error)) return FALSE; } } else { /* Static WEP */ g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", NULL); } return TRUE; } /* WPA/RSN */ g_assert (ap_wpa_flags || ap_rsn_flags); /* Ensure key management is valid for WPA */ if ((key_mgmt && !strcmp (key_mgmt, "ieee8021x")) || leap_username) { g_set_error_literal (error, NM_SETTING_WIRELESS_SECURITY_ERROR, NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, "WPA incompatible with non-EAP (original) LEAP or Dynamic WEP"); return FALSE; } /* 'shared' auth incompatible with any type of WPA */ if (auth_alg && strcmp (auth_alg, "open")) { g_set_error_literal (error, NM_SETTING_WIRELESS_SECURITY_ERROR, NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, "WPA incompatible with Shared Key authentication"); return FALSE; } if (!verify_no_wep (s_wsec, "WPA", error)) return FALSE; if (!verify_wpa_psk (s_wsec, s_8021x, adhoc, ap_wpa_flags, ap_rsn_flags, error)) return FALSE; if (!adhoc && !verify_wpa_eap (s_wsec, s_8021x, ap_wpa_flags, ap_rsn_flags, error)) return FALSE; if (adhoc) { g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-none", NULL); /* Ad-Hoc does not support RSN/WPA2 */ nm_setting_wireless_security_add_proto (s_wsec, "wpa"); nm_setting_wireless_security_add_pairwise (s_wsec, "none"); nm_setting_wireless_security_add_group (s_wsec, "tkip"); } else if (s_8021x) { g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-eap", NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "open", NULL); /* Leave proto/pairwise/group as client set them; if they are unset the * supplicant will figure out the best combination at connect time. */ /* 802.1x also requires the client to completely fill in the 8021x * setting. Since there's so much configuration required for it, there's * no way it can be automatically completed. */ } else if ( (key_mgmt && !strcmp (key_mgmt, "wpa-psk")) || (ap_wpa_flags & NM_802_11_AP_SEC_KEY_MGMT_PSK) || (ap_rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_PSK)) { g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-psk", NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "open", NULL); /* Leave proto/pairwise/group as client set them; if they are unset the * supplicant will figure out the best combination at connect time. */ } else { g_set_error_literal (error, NM_SETTING_WIRELESS_SECURITY_ERROR, NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, "Failed to determine AP security information"); return FALSE; } return TRUE; }
static gboolean real_complete_connection (NMDevice *device, NMConnection *connection, const char *specific_object, const GSList *existing_connections, GError **error) { NMDeviceWimax *self = NM_DEVICE_WIMAX (device); NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self); NMSettingWimax *s_wimax; const GByteArray *setting_mac; char *format; const char *nsp_name = NULL; NMWimaxNsp *nsp = NULL; GSList *iter; s_wimax = nm_connection_get_setting_wimax (connection); if (!specific_object) { /* If not given a specific object, we need at minimum an NSP name */ if (!s_wimax) { g_set_error_literal (error, NM_WIMAX_ERROR, NM_WIMAX_ERROR_CONNECTION_INVALID, "A 'wimax' setting is required if no NSP path was given."); return FALSE; } nsp_name = nm_setting_wimax_get_network_name (s_wimax); if (!nsp_name || !strlen (nsp_name)) { g_set_error_literal (error, NM_WIMAX_ERROR, NM_WIMAX_ERROR_CONNECTION_INVALID, "A 'wimax' setting with a valid network name is required if no NSP path was given."); return FALSE; } /* Find a compatible NSP in the list */ nsp = get_nsp_by_name (self, nsp_name); /* If we still don't have an NSP, then the WiMAX settings needs to be * fully specified by the client. Might not be able to find the NSP * if the scan didn't find the NSP yet. */ if (!nsp) { if (!nm_setting_verify (NM_SETTING (s_wimax), NULL, error)) return FALSE; } } else { /* Find a compatible NSP in the list */ for (iter = priv->nsp_list; iter; iter = g_slist_next (iter)) { if (!strcmp (specific_object, nm_wimax_nsp_get_dbus_path (NM_WIMAX_NSP (iter->data)))) { nsp = NM_WIMAX_NSP (iter->data); break; } } if (!nsp) { g_set_error (error, NM_WIMAX_ERROR, NM_WIMAX_ERROR_NSP_NOT_FOUND, "The NSP %s was not in the scan list.", specific_object); return FALSE; } nsp_name = nm_wimax_nsp_get_name (nsp); } /* Add a WiMAX setting if one doesn't exist */ if (!s_wimax) { s_wimax = (NMSettingWimax *) nm_setting_wimax_new (); nm_connection_add_setting (connection, NM_SETTING (s_wimax)); } g_assert (nsp_name); format = g_strdup_printf ("%s %%d", nsp_name); nm_utils_complete_generic (connection, NM_SETTING_WIMAX_SETTING_NAME, existing_connections, format, nsp_name, TRUE); g_free (format); g_object_set (G_OBJECT (s_wimax), NM_SETTING_WIMAX_NETWORK_NAME, nsp_name, NULL); setting_mac = nm_setting_wimax_get_mac_address (s_wimax); if (setting_mac) { /* Make sure the setting MAC (if any) matches the device's permanent MAC */ if (memcmp (setting_mac->data, &priv->hw_addr.ether_addr_octet, ETH_ALEN)) { g_set_error (error, NM_SETTING_WIMAX_ERROR, NM_SETTING_WIMAX_ERROR_INVALID_PROPERTY, NM_SETTING_WIMAX_MAC_ADDRESS); return FALSE; } } else { GByteArray *mac; const guint8 null_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 }; /* Lock the connection to this device by default */ if (memcmp (&priv->hw_addr.ether_addr_octet, null_mac, ETH_ALEN)) { mac = g_byte_array_sized_new (ETH_ALEN); g_byte_array_append (mac, priv->hw_addr.ether_addr_octet, ETH_ALEN); g_object_set (G_OBJECT (s_wimax), NM_SETTING_WIMAX_MAC_ADDRESS, mac, NULL); g_byte_array_free (mac, TRUE); } } return TRUE; }