gboolean ce_page_device_entry_get (GtkEntry *entry, int type, gboolean check_ifname, char **ifname, char **mac, const char *device_name, GError **error) { char *first, *second; const char *ifname_tmp = NULL, *mac_tmp = NULL; gboolean valid = TRUE; const char *str; g_return_val_if_fail (entry != NULL, FALSE); g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE); str = gtk_entry_get_text (entry); valid = _device_entry_parse (str, &first, &second); if (first) { if (nm_utils_hwaddr_valid (first, nm_utils_hwaddr_len (type))) mac_tmp = first; else if (!check_ifname || nm_utils_iface_valid_name (first)) ifname_tmp = first; else valid = FALSE; } if (second) { if (nm_utils_hwaddr_valid (second, nm_utils_hwaddr_len (type))) { if (!mac_tmp) mac_tmp = second; else valid = FALSE; } else if (!check_ifname || nm_utils_iface_valid_name (second)) { if (!ifname_tmp) ifname_tmp = second; else valid = FALSE; } else valid = FALSE; } if (ifname) *ifname = g_strdup (ifname_tmp); if (mac) *mac = g_strdup (mac_tmp); g_free (first); g_free (second); if (!valid) { g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid %s (%s)"), device_name ? device_name : _("device"), str); } return valid; }
/** * nm_setting_bond_validate_option: * @name: the name of the option to validate * @value: the value of the option to validate * * Checks whether @name is a valid bond option and @value is a valid value for * the @name. If @value is %NULL, the function only validates the option name. * * Returns: %TRUE, if the @value is valid for the given name. * If the @name is not a valid option, %FALSE will be returned. **/ gboolean nm_setting_bond_validate_option (const char *name, const char *value) { guint i; if (!name || !name[0]) return FALSE; for (i = 0; i < G_N_ELEMENTS (defaults); i++) { if (g_strcmp0 (defaults[i].opt, name) == 0) { if (value == NULL) return TRUE; switch (defaults[i].opt_type) { case NM_BOND_OPTION_TYPE_INT: return validate_int (name, value, &defaults[i]); case NM_BOND_OPTION_TYPE_STRING: return validate_list (name, value, &defaults[i]); case NM_BOND_OPTION_TYPE_BOTH: return ( validate_int (name, value, &defaults[i]) || validate_list (name, value, &defaults[i])); case NM_BOND_OPTION_TYPE_IP: return validate_ip (name, value); case NM_BOND_OPTION_TYPE_MAC: return nm_utils_hwaddr_valid (value, ETH_ALEN); case NM_BOND_OPTION_TYPE_IFNAME: return validate_ifname (name, value); } return FALSE; } } return FALSE; }
static gboolean verify (NMSetting *setting, NMConnection *connection, GError **error) { NMSettingWimaxPrivate *priv = NM_SETTING_WIMAX_GET_PRIVATE (setting); if (!priv->network_name) { g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_MISSING_PROPERTY, _("property is missing")); g_prefix_error (error, "%s.%s: ", NM_SETTING_WIMAX_SETTING_NAME, NM_SETTING_WIMAX_NETWORK_NAME); return FALSE; } if (!strlen (priv->network_name)) { g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, _("property is empty")); g_prefix_error (error, "%s.%s: ", NM_SETTING_WIMAX_SETTING_NAME, NM_SETTING_WIMAX_NETWORK_NAME); return FALSE; } if (priv->mac_address && !nm_utils_hwaddr_valid (priv->mac_address, ETH_ALEN)) { g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, _("property is invalid")); g_prefix_error (error, "%s.%s: ", NM_SETTING_WIMAX_SETTING_NAME, NM_SETTING_WIMAX_MAC_ADDRESS); return FALSE; } return TRUE; }
gboolean ce_page_mac_entry_valid (GtkEntry *entry, int type, const char *property_name, GError **error) { const char *mac; g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE); mac = gtk_entry_get_text (entry); if (mac && *mac) { if (!nm_utils_hwaddr_valid (mac, nm_utils_hwaddr_len (type))) { const char *addr_type; addr_type = type == ARPHRD_ETHER ? _("MAC address") : _("HW address"); if (property_name) { g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid %s for %s (%s)"), addr_type, property_name, mac); } else { g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid %s (%s)"), addr_type, mac); } return FALSE; } } return TRUE; }
/** * priv->address can only be set one to a certain (non NULL) value. Every later attempt * to reset it to another value will be ignored and a warning will be logged. **/ static void _set_property_address (NMBluezDevice *self, const char *addr) { NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self); if (g_strcmp0 (priv->address, addr) == 0) return; if (!addr) { nm_log_warn (LOGD_BT, "bluez[%s] cannot reset address from '%s' to NULL", priv->path, priv->address); return; } if (priv->address != NULL) { nm_log_warn (LOGD_BT, "bluez[%s] cannot reset address from '%s' to '%s'", priv->path, priv->address, addr); return; } if (!nm_utils_hwaddr_valid (addr, ETH_ALEN)) { nm_log_warn (LOGD_BT, "bluez[%s] cannot set address to '%s' (invalid value)", priv->path, addr); return; } priv->address = g_strdup (addr); g_object_notify (G_OBJECT (self), NM_BLUEZ_DEVICE_ADDRESS); }
static gboolean connection_compatible (NMDevice *device, NMConnection *connection, GError **error) { NMSettingWimax *s_wimax; const char *hwaddr, *setting_hwaddr; if (!NM_DEVICE_CLASS (nm_device_wimax_parent_class)->connection_compatible (device, connection, error)) return FALSE; if (!nm_connection_is_type (connection, NM_SETTING_WIMAX_SETTING_NAME)) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, _("The connection was not a WiMAX connection.")); return FALSE; } /* Check MAC address */ hwaddr = nm_device_wimax_get_hw_address (NM_DEVICE_WIMAX (device)); if (hwaddr) { if (!nm_utils_hwaddr_valid (hwaddr, ETH_ALEN)) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, _("Invalid device MAC address.")); return FALSE; } s_wimax = nm_connection_get_setting_wimax (connection); setting_hwaddr = nm_setting_wimax_get_mac_address (s_wimax); if (setting_hwaddr && !nm_utils_hwaddr_matches (setting_hwaddr, -1, hwaddr, -1)) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, _("The MACs of the device and the connection didn't match.")); return FALSE; } } return TRUE; }
static gboolean connection_compatible (NMDevice *device, NMConnection *connection, GError **error) { NMSettingInfiniband *s_infiniband; const char *hwaddr, *setting_hwaddr; if (!NM_DEVICE_CLASS (nm_device_infiniband_parent_class)->connection_compatible (device, connection, error)) return FALSE; if (!nm_connection_is_type (connection, NM_SETTING_INFINIBAND_SETTING_NAME)) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, _("The connection was not an InfiniBand connection.")); return FALSE; } hwaddr = nm_device_infiniband_get_hw_address (NM_DEVICE_INFINIBAND (device)); if (hwaddr) { if (!nm_utils_hwaddr_valid (hwaddr, INFINIBAND_ALEN)) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, _("Invalid device MAC address.")); return FALSE; } s_infiniband = nm_connection_get_setting_infiniband (connection); setting_hwaddr = nm_setting_infiniband_get_mac_address (s_infiniband); if (setting_hwaddr && !nm_utils_hwaddr_matches (setting_hwaddr, -1, hwaddr, -1)) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, _("The MACs of the device and the connection didn't match.")); return FALSE; } } return TRUE; }
static gboolean verify (NMSetting *setting, NMConnection *connection, GError **error) { NMSettingOlpcMeshPrivate *priv = NM_SETTING_OLPC_MESH_GET_PRIVATE (setting); gsize length; if (!priv->ssid) { g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_MISSING_PROPERTY, _("property is missing")); g_prefix_error (error, "%s.%s: ", NM_SETTING_OLPC_MESH_SETTING_NAME, NM_SETTING_OLPC_MESH_SSID); return FALSE; } length = g_bytes_get_size (priv->ssid); if (length == 0 || length > 32) { g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, _("SSID length is out of range <1-32> bytes")); g_prefix_error (error, "%s.%s: ", NM_SETTING_OLPC_MESH_SETTING_NAME, NM_SETTING_OLPC_MESH_SSID); return FALSE; } if (priv->channel == 0 || priv->channel > 13) { g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, _("'%d' is not a valid channel"), priv->channel); g_prefix_error (error, "%s.%s: ", NM_SETTING_OLPC_MESH_SETTING_NAME, NM_SETTING_OLPC_MESH_CHANNEL); return FALSE; } if (priv->dhcp_anycast_addr && !nm_utils_hwaddr_valid (priv->dhcp_anycast_addr, ETH_ALEN)) { g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, _("property is invalid")); g_prefix_error (error, "%s.%s: ", NM_SETTING_OLPC_MESH_SETTING_NAME, NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS); return FALSE; } return TRUE; }
void nm_ap_set_address (NMAccessPoint *ap, const char *addr) { NMAccessPointPrivate *priv; g_return_if_fail (NM_IS_AP (ap)); g_return_if_fail (addr != NULL); g_return_if_fail (nm_utils_hwaddr_valid (addr, ETH_ALEN)); priv = NM_AP_GET_PRIVATE (ap); if (!priv->address || !nm_utils_hwaddr_matches (addr, -1, priv->address, -1)) { g_free (priv->address); priv->address = g_strdup (addr); g_object_notify (G_OBJECT (ap), NM_AP_HW_ADDRESS); } }
static gboolean connection_compatible (NMDevice *device, NMConnection *connection, GError **error) { NMSettingBluetooth *s_bt; const char *hw_addr, *setting_addr; NMBluetoothCapabilities dev_caps; NMBluetoothCapabilities bt_type; if (!NM_DEVICE_CLASS (nm_device_bt_parent_class)->connection_compatible (device, connection, error)) return FALSE; if (!nm_connection_is_type (connection, NM_SETTING_BLUETOOTH_SETTING_NAME)) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, _("The connection was not a Bluetooth connection.")); return FALSE; } /* Check BT address */ hw_addr = nm_device_bt_get_hw_address (NM_DEVICE_BT (device)); if (hw_addr) { if (!nm_utils_hwaddr_valid (hw_addr, ETH_ALEN)) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, _("Invalid device Bluetooth address.")); return FALSE; } s_bt = nm_connection_get_setting_bluetooth (connection); setting_addr = nm_setting_bluetooth_get_bdaddr (s_bt); if (setting_addr && !nm_utils_hwaddr_matches (setting_addr, -1, hw_addr, -1)) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, _("The Bluetooth addresses 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_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, _("The device is lacking Bluetooth capabilities required by the connection.")); return FALSE; } return TRUE; }
static gboolean connection_compatible (NMDevice *device, NMConnection *connection, GError **error) { NMSettingWired *s_wired; gboolean is_pppoe = FALSE; if (!NM_DEVICE_CLASS (nm_device_ethernet_parent_class)->connection_compatible (device, connection, error)) return FALSE; if (nm_connection_is_type (connection, NM_SETTING_PPPOE_SETTING_NAME)) is_pppoe = TRUE; else if (!nm_connection_is_type (connection, NM_SETTING_WIRED_SETTING_NAME)) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, _("The connection was not an Ethernet or PPPoE connection.")); return FALSE; } s_wired = nm_connection_get_setting_wired (connection); /* Wired setting optional for PPPoE */ if (s_wired) { const char *perm_addr, *setting_addr; /* FIXME: filter using s390 subchannels when they are exported over the bus */ /* Check MAC address */ perm_addr = nm_device_ethernet_get_permanent_hw_address (NM_DEVICE_ETHERNET (device)); if (perm_addr) { if (!nm_utils_hwaddr_valid (perm_addr, ETH_ALEN)) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, _("Invalid device MAC address.")); return FALSE; } setting_addr = nm_setting_wired_get_mac_address (s_wired); if (setting_addr && !nm_utils_hwaddr_matches (setting_addr, -1, perm_addr, -1)) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, _("The MACs of the device and the connection didn't match.")); return FALSE; } } } return TRUE; }
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); }
static gboolean verify (NMSetting *setting, NMConnection *connection, GError **error) { NMSettingBluetoothPrivate *priv = NM_SETTING_BLUETOOTH_GET_PRIVATE (setting); if (!priv->bdaddr) { g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_MISSING_PROPERTY, _("property is missing")); g_prefix_error (error, "%s.%s: ", NM_SETTING_BLUETOOTH_SETTING_NAME, NM_SETTING_BLUETOOTH_BDADDR); return FALSE; } if (!nm_utils_hwaddr_valid (priv->bdaddr, ETH_ALEN)) { g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, _("property is invalid")); g_prefix_error (error, "%s.%s: ", NM_SETTING_BLUETOOTH_SETTING_NAME, NM_SETTING_BLUETOOTH_BDADDR); return FALSE; } if (!priv->type) { g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_MISSING_PROPERTY, _("property is missing")); g_prefix_error (error, "%s.%s: ", NM_SETTING_BLUETOOTH_SETTING_NAME, NM_SETTING_BLUETOOTH_TYPE); return FALSE; } else if (!g_str_equal (priv->type, NM_SETTING_BLUETOOTH_TYPE_DUN) && !g_str_equal (priv->type, NM_SETTING_BLUETOOTH_TYPE_PANU)) { g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, _("'%s' is not a valid value for the property"), priv->type); g_prefix_error (error, "%s.%s: ", NM_SETTING_BLUETOOTH_SETTING_NAME, NM_SETTING_BLUETOOTH_TYPE); return FALSE; } /* Make sure the corresponding 'type' setting is present */ if ( connection && !strcmp (priv->type, NM_SETTING_BLUETOOTH_TYPE_DUN)) { gboolean gsm = FALSE, cdma = FALSE; gsm = !!nm_connection_get_setting_gsm (connection); cdma = !!nm_connection_get_setting_cdma (connection); if (!gsm && !cdma) { /* We can't return MISSING_SETTING here, because we don't know * whether to prefix the message with NM_SETTING_GSM_SETTING_NAME or * NM_SETTING_CDMA_SETTING_NAME. */ g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_SETTING, _("'%s' connection requires '%s' or '%s' setting"), NM_SETTING_BLUETOOTH_TYPE_DUN, NM_SETTING_GSM_SETTING_NAME, NM_SETTING_CDMA_SETTING_NAME); g_prefix_error (error, "%s: ", NM_SETTING_BLUETOOTH_SETTING_NAME); return FALSE; } } /* PANU doesn't need a 'type' setting since no further configuration * is required at the interface level. */ return TRUE; }
char * nm_dhcp_dhclient_create_config (const char *interface, gboolean is_ip6, GBytes *client_id, const char *anycast_addr, const char *hostname, const char *fqdn, const char *orig_path, const char *orig_contents, GBytes **out_new_client_id) { GString *new_contents; GPtrArray *fqdn_opts, *reqs; int i; g_return_val_if_fail (!anycast_addr || nm_utils_hwaddr_valid (anycast_addr, ETH_ALEN), NULL); new_contents = g_string_new (_("# Created by NetworkManager\n")); fqdn_opts = g_ptr_array_sized_new (5); reqs = g_ptr_array_new_full (5, g_free); if (orig_contents) { char **lines, **line; gboolean in_alsoreq = FALSE; gboolean in_req = FALSE; g_string_append_printf (new_contents, _("# Merged from %s\n\n"), orig_path); lines = g_strsplit_set (orig_contents, "\n\r", 0); for (line = lines; lines && *line; line++) { char *p = *line; if (!strlen (g_strstrip (p))) continue; if (!strncmp (p, CLIENTID_TAG, strlen (CLIENTID_TAG))) { /* Override config file "dhcp-client-id" and use one from the connection */ if (client_id) continue; /* Otherwise capture and return the existing client id */ if (out_new_client_id) *out_new_client_id = read_client_id (p); } /* Override config file hostname and use one from the connection */ if (hostname || fqdn) { if (strncmp (p, HOSTNAME4_TAG, strlen (HOSTNAME4_TAG)) == 0) continue; if (strncmp (p, FQDN_TAG, strlen (FQDN_TAG)) == 0) continue; } /* To let user's FQDN options (except "fqdn.fqdn") override the * default ones set by NM, add them later */ if (!strncmp (p, FQDN_TAG_PREFIX, NM_STRLEN (FQDN_TAG_PREFIX))) { g_ptr_array_add (fqdn_opts, g_strdup (p + NM_STRLEN (FQDN_TAG_PREFIX))); continue; } /* Ignore 'script' since we pass our own */ if (g_str_has_prefix (p, "script ")) continue; /* Check for "request" */ if (!strncmp (p, REQ_TAG, strlen (REQ_TAG))) { in_req = TRUE; p += strlen (REQ_TAG); g_ptr_array_set_size (reqs, 0); } /* Save all request options for later use */ if (in_req) { in_req = !grab_request_options (reqs, p); continue; } /* Check for "also require" */ if (!strncmp (p, ALSOREQ_TAG, strlen (ALSOREQ_TAG))) { in_alsoreq = TRUE; p += strlen (ALSOREQ_TAG); } if (in_alsoreq) { in_alsoreq = !grab_request_options (reqs, p); continue; } /* Existing configuration line is OK, add it to new configuration */ g_string_append (new_contents, *line); g_string_append_c (new_contents, '\n'); } if (lines) g_strfreev (lines); } else g_string_append_c (new_contents, '\n'); if (is_ip6) { add_hostname6 (new_contents, hostname); add_request (reqs, "dhcp6.name-servers"); add_request (reqs, "dhcp6.domain-search"); add_request (reqs, "dhcp6.client-id"); } else { add_ip4_config (new_contents, client_id, hostname, fqdn); add_request (reqs, "rfc3442-classless-static-routes"); add_request (reqs, "ms-classless-static-routes"); add_request (reqs, "static-routes"); add_request (reqs, "wpad"); add_request (reqs, "ntp-servers"); } /* And add it to the dhclient configuration */ for (i = 0; i < reqs->len; i++) g_string_append_printf (new_contents, "also request %s;\n", (char *) reqs->pdata[i]); g_ptr_array_free (reqs, TRUE); for (i = 0; i < fqdn_opts->len; i++) { char *t = g_ptr_array_index (fqdn_opts, i); if (i == 0) g_string_append_printf (new_contents, "\n# FQDN options from %s\n", orig_path); g_string_append_printf (new_contents, FQDN_TAG_PREFIX "%s\n", t); g_free (t); } g_ptr_array_free (fqdn_opts, TRUE); g_string_append_c (new_contents, '\n'); if (anycast_addr) { g_string_append_printf (new_contents, "interface \"%s\" {\n" " initial-interval 1; \n" " anycast-mac ethernet %s;\n" "}\n", interface, anycast_addr); } return g_string_free (new_contents, FALSE); }
static gboolean connection_compatible (NMDevice *device, NMConnection *connection, GError **error) { NMSettingWired *s_wired; if (!NM_DEVICE_CLASS (nm_device_ethernet_parent_class)->connection_compatible (device, connection, error)) return FALSE; if (nm_connection_is_type (connection, NM_SETTING_PPPOE_SETTING_NAME)) { /* NOP */ } else if (!nm_connection_is_type (connection, NM_SETTING_WIRED_SETTING_NAME)) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, _("The connection was not an Ethernet or PPPoE connection.")); return FALSE; } s_wired = nm_connection_get_setting_wired (connection); /* Wired setting optional for PPPoE */ if (s_wired) { const char *perm_addr, *s_mac; gboolean try_mac = TRUE; const char * const *mac_blacklist; int i; /* Check s390 subchannels */ if (!match_subchans (NM_DEVICE_ETHERNET (device), s_wired, &try_mac)) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, _("The connection and device differ in S390 subchannels.")); return FALSE; } /* Check MAC address */ perm_addr = nm_device_ethernet_get_permanent_hw_address (NM_DEVICE_ETHERNET (device)); s_mac = nm_setting_wired_get_mac_address (s_wired); if (perm_addr) { if (!nm_utils_hwaddr_valid (perm_addr, ETH_ALEN)) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED, _("Invalid device MAC address.")); return FALSE; } if (try_mac && s_mac && !nm_utils_hwaddr_matches (s_mac, -1, perm_addr, -1)) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, _("The MACs of the device and the connection do not match.")); return FALSE; } /* Check for MAC address blacklist */ mac_blacklist = nm_setting_wired_get_mac_address_blacklist (s_wired); for (i = 0; mac_blacklist[i]; i++) { if (!nm_utils_hwaddr_valid (mac_blacklist[i], ETH_ALEN)) { g_warn_if_reached (); g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, _("Invalid MAC in the blacklist: %s."), mac_blacklist[i]); return FALSE; } if (nm_utils_hwaddr_matches (mac_blacklist[i], -1, perm_addr, -1)) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, _("Device MAC (%s) is blacklisted by the connection."), perm_addr); return FALSE; } } } } return TRUE; }
static gboolean connection_compatible (NMDevice *device, NMConnection *connection, GError **error) { NMSettingConnection *s_con; NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; const char *ctype; const char *hwaddr, *setting_hwaddr; NMDeviceWifiCapabilities wifi_caps; const char *key_mgmt; 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_WIRELESS_SETTING_NAME) != 0) { g_set_error (error, NM_DEVICE_WIFI_ERROR, NM_DEVICE_WIFI_ERROR_NOT_WIFI_CONNECTION, "The connection was not a Wi-Fi connection."); return FALSE; } s_wifi = nm_connection_get_setting_wireless (connection); if (!s_wifi) { g_set_error (error, NM_DEVICE_WIFI_ERROR, NM_DEVICE_WIFI_ERROR_INVALID_WIFI_CONNECTION, "The connection was not a valid Wi-Fi connection."); return FALSE; } /* Check MAC address */ hwaddr = nm_device_wifi_get_permanent_hw_address (NM_DEVICE_WIFI (device)); if (hwaddr) { if (!nm_utils_hwaddr_valid (hwaddr, ETH_ALEN)) { g_set_error (error, NM_DEVICE_WIFI_ERROR, NM_DEVICE_WIFI_ERROR_INVALID_DEVICE_MAC, "Invalid device MAC address."); return FALSE; } setting_hwaddr = nm_setting_wireless_get_mac_address (s_wifi); if (setting_hwaddr && !nm_utils_hwaddr_matches (setting_hwaddr, -1, hwaddr, -1)) { g_set_error (error, NM_DEVICE_WIFI_ERROR, NM_DEVICE_WIFI_ERROR_MAC_MISMATCH, "The MACs of the device and the connection didn't match."); return FALSE; } } /* Check device capabilities; we assume all devices can do WEP at least */ wifi_caps = nm_device_wifi_get_capabilities (NM_DEVICE_WIFI (device)); s_wsec = nm_connection_get_setting_wireless_security (connection); if (s_wsec) { /* Connection has security, verify it against the device's capabilities */ key_mgmt = nm_setting_wireless_security_get_key_mgmt (s_wsec); if ( !g_strcmp0 (key_mgmt, "wpa-none") || !g_strcmp0 (key_mgmt, "wpa-psk") || !g_strcmp0 (key_mgmt, "wpa-eap")) { /* Is device only WEP capable? */ if (!(wifi_caps & WPA_CAPS)) { g_set_error (error, NM_DEVICE_WIFI_ERROR, NM_DEVICE_WIFI_ERROR_MISSING_DEVICE_WPA_CAPS, "The device missed WPA capabilities required by the connection."); return FALSE; } /* Make sure WPA2/RSN-only connections don't get chosen for WPA-only cards */ if (has_proto (s_wsec, "rsn") && !has_proto (s_wsec, "wpa") && !(wifi_caps & RSN_CAPS)) { g_set_error (error, NM_DEVICE_WIFI_ERROR, NM_DEVICE_WIFI_ERROR_MISSING_DEVICE_RSN_CAPS, "The device missed WPA2/RSN capabilities required by the connection."); return FALSE; } } } return NM_DEVICE_CLASS (nm_device_wifi_parent_class)->connection_compatible (device, connection, error); }
char * nm_dhcp_dhclient_create_config (const char *interface, gboolean is_ip6, const char *dhcp_client_id, const char *anycast_addr, const char *hostname, const char *orig_path, const char *orig_contents) { GString *new_contents; GPtrArray *alsoreq; int i; g_return_val_if_fail (!anycast_addr || nm_utils_hwaddr_valid (anycast_addr, ETH_ALEN), NULL); new_contents = g_string_new (_("# Created by NetworkManager\n")); alsoreq = g_ptr_array_sized_new (5); if (orig_contents) { char **lines, **line; gboolean in_alsoreq = FALSE; g_string_append_printf (new_contents, _("# Merged from %s\n\n"), orig_path); lines = g_strsplit_set (orig_contents, "\n\r", 0); for (line = lines; lines && *line; line++) { char *p = *line; if (!strlen (g_strstrip (p))) continue; /* Override config file "dhcp-client-id" and use one from the * connection. */ if (dhcp_client_id && !strncmp (p, CLIENTID_TAG, strlen (CLIENTID_TAG))) continue; /* Override config file hostname and use one from the connection */ if (hostname) { if (strncmp (p, HOSTNAME4_TAG, strlen (HOSTNAME4_TAG)) == 0) continue; if (strncmp (p, HOSTNAME6_TAG, strlen (HOSTNAME6_TAG)) == 0) continue; } /* Ignore 'script' since we pass our own */ if (g_str_has_prefix (p, "script ")) continue; /* Check for "also require" */ if (!strncmp (p, ALSOREQ_TAG, strlen (ALSOREQ_TAG))) { in_alsoreq = TRUE; p += strlen (ALSOREQ_TAG); } if (in_alsoreq) { char **areq, **aiter; /* Grab each 'also require' option and save for later */ areq = g_strsplit_set (p, "\t ,", -1); for (aiter = areq; aiter && *aiter; aiter++) { if (!strlen (g_strstrip (*aiter))) continue; if (*aiter[0] == ';') { /* all done */ in_alsoreq = FALSE; break; } if (!g_ascii_isalnum ((*aiter)[0])) continue; if ((*aiter)[strlen (*aiter) - 1] == ';') { /* Remove the EOL marker */ (*aiter)[strlen (*aiter) - 1] = '\0'; in_alsoreq = FALSE; } add_also_request (alsoreq, *aiter); } if (areq) g_strfreev (areq); continue; } /* Existing configuration line is OK, add it to new configuration */ g_string_append (new_contents, *line); g_string_append_c (new_contents, '\n'); } if (lines) g_strfreev (lines); } else g_string_append_c (new_contents, '\n'); if (is_ip6) { add_ip6_config (new_contents, hostname); add_also_request (alsoreq, "dhcp6.name-servers"); add_also_request (alsoreq, "dhcp6.domain-search"); add_also_request (alsoreq, "dhcp6.client-id"); } else { add_ip4_config (new_contents, dhcp_client_id, hostname); add_also_request (alsoreq, "rfc3442-classless-static-routes"); add_also_request (alsoreq, "ms-classless-static-routes"); add_also_request (alsoreq, "static-routes"); add_also_request (alsoreq, "wpad"); add_also_request (alsoreq, "ntp-servers"); } /* And add it to the dhclient configuration */ for (i = 0; i < alsoreq->len; i++) { char *t = g_ptr_array_index (alsoreq, i); g_string_append_printf (new_contents, "also request %s;\n", t); g_free (t); } g_ptr_array_free (alsoreq, TRUE); g_string_append_c (new_contents, '\n'); if (anycast_addr) { g_string_append_printf (new_contents, "interface \"%s\" {\n" " initial-interval 1; \n" " anycast-mac ethernet %s;\n" "}\n", interface, anycast_addr); } return g_string_free (new_contents, FALSE); }
static gboolean verify (NMSetting *setting, NMConnection *connection, GError **error) { NMSettingConnection *s_con; NMSettingInfinibandPrivate *priv = NM_SETTING_INFINIBAND_GET_PRIVATE (setting); guint32 normerr_max_mtu = 0; if (priv->mac_address && !nm_utils_hwaddr_valid (priv->mac_address, INFINIBAND_ALEN)) { g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, _("property is invalid")); g_prefix_error (error, "%s.%s: ", NM_SETTING_INFINIBAND_SETTING_NAME, NM_SETTING_INFINIBAND_MAC_ADDRESS); return FALSE; } if (!g_strcmp0 (priv->transport_mode, "datagram")) { if (priv->mtu > 2044) normerr_max_mtu = 2044; } else if (!g_strcmp0 (priv->transport_mode, "connected")) { if (priv->mtu > 65520) normerr_max_mtu = 65520; } else { g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, _("property is invalid")); g_prefix_error (error, "%s.%s: ", NM_SETTING_INFINIBAND_SETTING_NAME, NM_SETTING_INFINIBAND_TRANSPORT_MODE); return FALSE; } if (priv->parent) { if (!nm_utils_iface_valid_name (priv->parent)) { g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, _("not a valid interface name")); g_prefix_error (error, "%s: ", NM_SETTING_INFINIBAND_PARENT); return FALSE; } if (priv->p_key == -1) { g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, _("Must specify a P_Key if specifying parent")); g_prefix_error (error, "%s: ", NM_SETTING_INFINIBAND_PARENT); } } if (priv->p_key != -1) { if (!priv->mac_address && !priv->parent) { g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_MISSING_PROPERTY, _("InfiniBand P_Key connection did not specify parent interface name")); g_prefix_error (error, "%s: ", NM_SETTING_INFINIBAND_PARENT); return FALSE; } } s_con = nm_connection_get_setting_connection (connection); if (s_con) { const char *interface_name = nm_setting_connection_get_interface_name (s_con); if (!interface_name) ; else if (!nm_utils_iface_valid_name (interface_name)) { /* report the error for NMSettingConnection:interface-name, because * it's that property that is invalid -- although we currently verify() * NMSettingInfiniband. **/ g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, _("'%s' is not a valid interface name"), interface_name); g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME); return FALSE; } else { if (priv->p_key != -1) { if (!priv->virtual_iface_name) priv->virtual_iface_name = g_strdup_printf ("%s.%04x", priv->parent, priv->p_key); if (strcmp (interface_name, priv->virtual_iface_name) != 0) { /* We don't support renaming software infiniband devices. Later we might, but * for now just reject such connections. **/ g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, _("interface name of software infiniband device must be '%s' or unset (instead it is '%s')"), priv->virtual_iface_name, interface_name); g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME); return FALSE; } } } } /* *** errors above here should be always fatal, below NORMALIZABLE_ERROR *** */ if (normerr_max_mtu > 0) { g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, _("mtu for transport mode '%s' can be at most %d but it is %d"), priv->transport_mode, normerr_max_mtu, priv->mtu); g_prefix_error (error, "%s.%s: ", NM_SETTING_INFINIBAND_SETTING_NAME, NM_SETTING_INFINIBAND_MTU); return NM_SETTING_VERIFY_NORMALIZABLE_ERROR; } return TRUE; }