summaryrefslogtreecommitdiffstats
path: root/tdecore
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-09-09 20:40:11 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-09-09 20:40:11 -0500
commitb5bdfd2c41c0be5b79831c1b9d5a3f292d129264 (patch)
tree8956791ee1e32656b6abd8eb9eb3dd8800472302 /tdecore
parent642f227036520a1a616e27db086a2c82e7dd1489 (diff)
downloadtdelibs-b5bdfd2c41c0be5b79831c1b9d5a3f292d129264.tar.gz
tdelibs-b5bdfd2c41c0be5b79831c1b9d5a3f292d129264.zip
Extend API to include default device(s)
Diffstat (limited to 'tdecore')
-rw-r--r--tdecore/networkbackends/network-manager/network-manager.cpp355
-rw-r--r--tdecore/networkbackends/network-manager/network-manager.h4
-rw-r--r--tdecore/tdenetworkconnections.cpp30
-rw-r--r--tdecore/tdenetworkconnections.h62
4 files changed, 423 insertions, 28 deletions
diff --git a/tdecore/networkbackends/network-manager/network-manager.cpp b/tdecore/networkbackends/network-manager/network-manager.cpp
index 1b639aa25..d5af43248 100644
--- a/tdecore/networkbackends/network-manager/network-manager.cpp
+++ b/tdecore/networkbackends/network-manager/network-manager.cpp
@@ -16,6 +16,8 @@
Boston, MA 02110-1301, USA.
*/
+#include "tdehardwaredevices.h"
+
#include "network-manager.h"
#include "network-manager_p.h"
@@ -913,11 +915,21 @@ char tdeParityToNMParity(TDENetworkParity::TDENetworkParity parity) {
return ret;
}
-TDENetworkWepKeyType::TDENetworkWepKeyType nmWepKeyTypeToTDEWepKeyType(unsigned int nm) {
+TDENetworkWepKeyType::TDENetworkWepKeyType nmWepKeyTypeToTDEWepKeyType(unsigned int nm, TQString key=TQString::null) {
TDENetworkWepKeyType::TDENetworkWepKeyType ret = TDENetworkWepKeyType::Hexadecimal;
if (nm == NM_WEP_TYPE_HEXADECIMAL) {
- ret = TDENetworkWepKeyType::Hexadecimal;
+ if (key.isNull()) {
+ ret = TDENetworkWepKeyType::Hexadecimal;
+ }
+ else {
+ if ((key.length() == 10) || (key.length() == 26)) {
+ ret = TDENetworkWepKeyType::Hexadecimal;
+ }
+ else {
+ ret = TDENetworkWepKeyType::Ascii;
+ }
+ }
}
else if (nm == NM_WEP_TYPE_PASSPHRASE) {
ret = TDENetworkWepKeyType::Passphrase;
@@ -932,6 +944,9 @@ unsigned int tdeWepKeyTypeToNMWepKeyType(TDENetworkWepKeyType::TDENetworkWepKeyT
if (type == TDENetworkWepKeyType::Hexadecimal) {
ret = NM_WEP_TYPE_HEXADECIMAL;
}
+ else if (type == TDENetworkWepKeyType::Ascii) {
+ ret = NM_WEP_TYPE_HEXADECIMAL;
+ }
else if (type == TDENetworkWepKeyType::Passphrase) {
ret = NM_WEP_TYPE_PASSPHRASE;
}
@@ -1172,6 +1187,90 @@ TQString TDENetworkConnectionManager_BackendNM::deviceInterfaceString(TQString m
}
}
+TQString macAddressForGenericDevice(TQT_DBusObjectPath path) {
+ TQT_DBusError error;
+
+ DBus::DeviceProxy genericDevice(NM_DBUS_SERVICE, path);
+ genericDevice.setConnection(TQT_DBusConnection::systemBus());
+ TQ_UINT32 deviceType = genericDevice.getDeviceType(error);
+ if (error.isValid()) {
+ // Error!
+ PRINT_ERROR(error.name())
+ return TQString();
+ }
+ else if (deviceType == NM_DEVICE_TYPE_ETHERNET) {
+ DBus::EthernetDeviceProxy ethernetDevice(NM_DBUS_SERVICE, path);
+ ethernetDevice.setConnection(TQT_DBusConnection::systemBus());
+ TQString candidateMACAddress = ethernetDevice.getPermHwAddress(error);
+ if (!error.isValid()) {
+ return candidateMACAddress.lower();
+ }
+ }
+ else if (deviceType == NM_DEVICE_TYPE_INFINIBAND) {
+ DBus::InfinibandDeviceProxy infinibandDevice(NM_DBUS_SERVICE, path);
+ infinibandDevice.setConnection(TQT_DBusConnection::systemBus());
+ TQString candidateMACAddress = infinibandDevice.getHwAddress(error);
+ if (!error.isValid()) {
+ return candidateMACAddress.lower();
+ }
+ }
+ else if (deviceType == NM_DEVICE_TYPE_WIFI) {
+ DBus::WiFiDeviceProxy wiFiDevice(NM_DBUS_SERVICE, path);
+ wiFiDevice.setConnection(TQT_DBusConnection::systemBus());
+ TQString candidateMACAddress = wiFiDevice.getPermHwAddress(error);
+ if (!error.isValid()) {
+ return candidateMACAddress.lower();
+ }
+ }
+ else if (deviceType == NM_DEVICE_TYPE_WIMAX) {
+ DBus::WiMaxDeviceProxy wiMaxDevice(NM_DBUS_SERVICE, path);
+ wiMaxDevice.setConnection(TQT_DBusConnection::systemBus());
+ TQString candidateMACAddress = wiMaxDevice.getHwAddress(error);
+ if (!error.isValid()) {
+ return candidateMACAddress.lower();
+ }
+ }
+ else if (deviceType == NM_DEVICE_TYPE_OLPC_MESH) {
+ DBus::OlpcMeshDeviceProxy olpcMeshDevice(NM_DBUS_SERVICE, path);
+ olpcMeshDevice.setConnection(TQT_DBusConnection::systemBus());
+ TQString candidateMACAddress = olpcMeshDevice.getHwAddress(error);
+ if (!error.isValid()) {
+ return candidateMACAddress.lower();
+ }
+ }
+ else if (deviceType == NM_DEVICE_TYPE_BT) {
+ DBus::BluetoothDeviceProxy bluetoothDevice(NM_DBUS_SERVICE, path);
+ bluetoothDevice.setConnection(TQT_DBusConnection::systemBus());
+ TQString candidateMACAddress = bluetoothDevice.getHwAddress(error);
+ if (!error.isValid()) {
+ return candidateMACAddress.lower();
+ }
+ }
+ // FIXME
+ // Add other supported device types here
+
+ return TQString::null;
+}
+
+TQString tdeDeviceUUIDForMACAddress(TQString macAddress) {
+ TDEHardwareDevices *hwdevices = KGlobal::hardwareDevices();
+ if (!hwdevices) {
+ return TQString::null;
+ }
+
+ TDEGenericHardwareList devices = hwdevices->listByDeviceClass(TDEGenericDeviceType::Network);
+ for (TDEGenericHardwareList::iterator it = devices.begin(); it != devices.end(); ++it) {
+ TDENetworkDevice* dev = dynamic_cast<TDENetworkDevice*>(*it);
+ if (dev) {
+ if (macAddress.lower() == dev->macAddress().lower()) {
+ return dev->uniqueID();
+ }
+ }
+ }
+
+ return TQString::null;
+}
+
TDENetworkConnectionManager_BackendNM::TDENetworkConnectionManager_BackendNM(TQString macAddress) : TDENetworkConnectionManager(macAddress) {
d = new TDENetworkConnectionManager_BackendNMPrivate(this);
@@ -2603,8 +2702,34 @@ void TDENetworkConnectionManager_BackendNM::loadConnectionAllowedValues(TDENetwo
// While this separate separate routine is needed to get the secrets, note that secrets must
// be saved using the same connection map save routine that all other settings use above.
bool TDENetworkConnectionManager_BackendNM::loadConnectionSecrets(TQString uuid) {
+ TDENetworkConnection* connection = findConnectionByUUID(uuid);
+ if (!connection) {
+ PRINT_ERROR(TQString("Unable to locate connection with uuid '%1' in local database. Did you run loadConnectionInformation() first?"));
+ return FALSE;
+ }
+ //TDEWiredEthernetConnection* ethernetConnection = dynamic_cast<TDEWiredEthernetConnection*>(connection);
+ //TDEWiredInfinibandConnection* infinibandConnection = dynamic_cast<TDEWiredInfinibandConnection*>(connection);
+ TDEWiFiConnection* wiFiConnection = dynamic_cast<TDEWiFiConnection*>(connection);
+ TDEVPNConnection* vpnConnection = dynamic_cast<TDEVPNConnection*>(connection);
+ //TDEWiMaxConnection* wiMaxConnection = dynamic_cast<TDEWiMaxConnection*>(connection);
+ //TDEVLANConnection* vlanConnection = dynamic_cast<TDEVLANConnection*>(connection);
+ //TDEOLPCMeshConnection* olpcMeshConnection = dynamic_cast<TDEVLANConnection*>(connection);
+ //TDEBluetoothConnection* bluetoothConnection = dynamic_cast<TDEBluetoothConnection*>(connection);
+ TDEModemConnection* modemConnection = dynamic_cast<TDEModemConnection*>(connection);
+
bool ret = TRUE;
ret = ret && loadConnectionSecretsForGroup(uuid, "802-1x");
+ if (wiFiConnection) {
+ ret = ret && loadConnectionSecretsForGroup(uuid, "802-11-wireless-security");
+ }
+ if (vpnConnection) {
+ ret = ret && loadConnectionSecretsForGroup(uuid, "vpn");
+ }
+ ret = ret && loadConnectionSecretsForGroup(uuid, "pppoe");
+ if (modemConnection) {
+ ret = ret && loadConnectionSecretsForGroup(uuid, "cdma");
+ ret = ret && loadConnectionSecretsForGroup(uuid, "gsm");
+ }
return ret;
}
@@ -2713,15 +2838,19 @@ bool TDENetworkConnectionManager_BackendNM::loadConnectionSecretsForGroup(TQStri
if ((outerKeyValue.lower() == "802-11-wireless-security") && (wiFiConnection)) {
if (keyValue.lower() == "wep-key0") {
wiFiConnection->securitySettings.wepKey0 = dataValue2.toString();
+ wiFiConnection->securitySettings.wepKeyType = nmWepKeyTypeToTDEWepKeyType(tdeWepKeyTypeToNMWepKeyType(wiFiConnection->securitySettings.wepKeyType), wiFiConnection->securitySettings.wepKey0);
}
else if (keyValue.lower() == "wep-key1") {
wiFiConnection->securitySettings.wepKey1 = dataValue2.toString();
+ wiFiConnection->securitySettings.wepKeyType = nmWepKeyTypeToTDEWepKeyType(tdeWepKeyTypeToNMWepKeyType(wiFiConnection->securitySettings.wepKeyType), wiFiConnection->securitySettings.wepKey1);
}
else if (keyValue.lower() == "wep-key2") {
wiFiConnection->securitySettings.wepKey2 = dataValue2.toString();
+ wiFiConnection->securitySettings.wepKeyType = nmWepKeyTypeToTDEWepKeyType(tdeWepKeyTypeToNMWepKeyType(wiFiConnection->securitySettings.wepKeyType), wiFiConnection->securitySettings.wepKey2);
}
else if (keyValue.lower() == "wep-key3") {
wiFiConnection->securitySettings.wepKey3 = dataValue2.toString();
+ wiFiConnection->securitySettings.wepKeyType = nmWepKeyTypeToTDEWepKeyType(tdeWepKeyTypeToNMWepKeyType(wiFiConnection->securitySettings.wepKeyType), wiFiConnection->securitySettings.wepKey3);
}
else if (keyValue.lower() == "psk") {
wiFiConnection->securitySettings.psk = dataValue2.toString();
@@ -3406,13 +3535,13 @@ bool TDENetworkConnectionManager_BackendNM::saveConnection(TDENetworkConnection*
settingsMap["wep-key-type"] = convertDBUSDataToVariantData(TQT_DBusData::fromUInt32(tdeWepKeyTypeToNMWepKeyType(wiFiConnection->securitySettings.wepKeyType)));
settingsMap["psk-flags"] = convertDBUSDataToVariantData(TQT_DBusData::fromUInt32(tdePasswordFlagsToNMPasswordFlags(wiFiConnection->securitySettings.pskFlags)));
settingsMap["leap-password-flags"] = convertDBUSDataToVariantData(TQT_DBusData::fromUInt32(tdePasswordFlagsToNMPasswordFlags(wiFiConnection->securitySettings.leapPasswordFlags)));
- if (connection->eapConfig.secretsValid) {
- settingsMap["wep-key0"] = convertDBUSDataToVariantData(TQT_DBusData::fromString(wiFiConnection->securitySettings.wepKey0));
- settingsMap["wep-key1"] = convertDBUSDataToVariantData(TQT_DBusData::fromString(wiFiConnection->securitySettings.wepKey1));
- settingsMap["wep-key2"] = convertDBUSDataToVariantData(TQT_DBusData::fromString(wiFiConnection->securitySettings.wepKey2));
- settingsMap["wep-key3"] = convertDBUSDataToVariantData(TQT_DBusData::fromString(wiFiConnection->securitySettings.wepKey3));
- settingsMap["psk"] = convertDBUSDataToVariantData(TQT_DBusData::fromString(wiFiConnection->securitySettings.psk));
- settingsMap["leap-password"] = convertDBUSDataToVariantData(TQT_DBusData::fromString(wiFiConnection->securitySettings.leapPassword));
+ if (wiFiConnection->securitySettings.secretsValid) {
+ UPDATE_STRING_SETTING_IF_VALID(wiFiConnection->securitySettings.wepKey0, "wep-key0", settingsMap)
+ UPDATE_STRING_SETTING_IF_VALID(wiFiConnection->securitySettings.wepKey1, "wep-key1", settingsMap)
+ UPDATE_STRING_SETTING_IF_VALID(wiFiConnection->securitySettings.wepKey2, "wep-key2", settingsMap)
+ UPDATE_STRING_SETTING_IF_VALID(wiFiConnection->securitySettings.wepKey3, "wep-key3", settingsMap)
+ UPDATE_STRING_SETTING_IF_VALID(wiFiConnection->securitySettings.psk, "psk", settingsMap)
+ UPDATE_STRING_SETTING_IF_VALID(wiFiConnection->securitySettings.leapPassword, "leap-password", settingsMap)
}
else {
settingsMap.remove("wep-key0");
@@ -4133,14 +4262,166 @@ bool TDENetworkConnectionManager_BackendNM::deleteConnection(TQString uuid) {
}
}
else {
- PRINT_ERROR(TQString("invalid internal network-manager settings proxy object").arg(uuid));
+ PRINT_ERROR(TQString("invalid internal network-manager settings proxy object"));
return FALSE;
}
}
-bool TDENetworkConnectionManager_BackendNM::verifyConnectionSettings(TDENetworkConnection* connection) {
+bool TDENetworkConnectionManager_BackendNM::verifyConnectionSettings(TDENetworkConnection* connection, TDENetworkConnectionErrorFlags::TDENetworkConnectionErrorFlags* type, TDENetworkErrorStringMap* reason) {
// FIXME
- // This should actually attempt to validate the settings!
+ // This should actually attempt to validate all the settings!
+
+ if (!connection) {
+ return false;
+ }
+
+ if (connection->friendlyName == "") {
+ if (reason) (*reason)[TDENetworkConnectionErrorFlags::InvalidConnectionSetting] = i18n("Connection name is invalid");
+ if (type) *type |= TDENetworkConnectionErrorFlags::InvalidConnectionSetting;
+ return false;
+ }
+
+ if (connection->ipConfig.valid) {
+ // Iterate over all addresses
+ TDENetworkSingleIPConfigurationList::iterator it;
+ for (it = connection->ipConfig.ipConfigurations.begin(); it != connection->ipConfig.ipConfigurations.end(); ++it) {
+ if ((*it).isIPv4()) {
+ if (!(connection->ipConfig.connectionFlags & TDENetworkIPConfigurationFlags::IPV4DHCPIP)) {
+ if (!TDENetworkConnectionManager::validateIPAddress((*it).ipAddress)) {
+ if (reason) (*reason)[TDENetworkConnectionErrorFlags::InvalidIPv4Setting] = i18n("IPv4 address is invalid");
+ if (type) *type |= TDENetworkConnectionErrorFlags::InvalidIPv4Setting;
+ return false;
+ }
+ }
+ }
+ else if ((*it).isIPv6()) {
+ if (!(connection->ipConfig.connectionFlags & TDENetworkIPConfigurationFlags::IPV6DHCPIP)) {
+ if (!TDENetworkConnectionManager::validateIPAddress((*it).ipAddress)) {
+ if (reason) (*reason)[TDENetworkConnectionErrorFlags::InvalidIPv6Setting] = i18n("IPv6 address is invalid");
+ if (type) *type |= TDENetworkConnectionErrorFlags::InvalidIPv6Setting;
+ return false;
+ }
+ }
+ }
+ }
+ }
+
+ TDEWiFiConnection* wiFiConnection = dynamic_cast<TDEWiFiConnection*>(connection);
+ if (wiFiConnection) {
+ if (wiFiConnection->SSID.count() < 1) {
+ if (reason) (*reason)[TDENetworkConnectionErrorFlags::InvalidWirelessSetting] = i18n("No SSID provided");
+ if (type) *type |= TDENetworkConnectionErrorFlags::InvalidWirelessSetting;
+ return false;
+ }
+ if (wiFiConnection->securityRequired) {
+ if (wiFiConnection->securitySettings.secretsValid) {
+ if ((wiFiConnection->securitySettings.keyType == TDENetworkWiFiKeyType::WEP) || ((wiFiConnection->securitySettings.keyType == TDENetworkWiFiKeyType::DynamicWEP) && ((wiFiConnection->securitySettings.authType == TDENetworkWiFiAuthType::Open) || (wiFiConnection->securitySettings.authType == TDENetworkWiFiAuthType::Shared)))) {
+ if (wiFiConnection->securitySettings.wepKeyType == TDENetworkWepKeyType::Hexadecimal) {
+ if (wiFiConnection->securitySettings.wepKey0 != "") {
+ if ((wiFiConnection->securitySettings.wepKey0.length() != 10) && (wiFiConnection->securitySettings.wepKey0.length() != 26)) {
+ if (reason) (*reason)[TDENetworkConnectionErrorFlags::InvalidWirelessKey] = i18n("WEP key 0 has invalid length");
+ if (type) *type |= TDENetworkConnectionErrorFlags::InvalidWirelessKey;
+ return false;
+ }
+ }
+ if (wiFiConnection->securitySettings.wepKey1 != "") {
+ if ((wiFiConnection->securitySettings.wepKey1.length() != 10) && (wiFiConnection->securitySettings.wepKey1.length() != 26)) {
+ if (reason) (*reason)[TDENetworkConnectionErrorFlags::InvalidWirelessKey] = i18n("WEP key 1 has invalid length");
+ if (type) *type |= TDENetworkConnectionErrorFlags::InvalidWirelessKey;
+ return false;
+ }
+ }
+ if (wiFiConnection->securitySettings.wepKey2 != "") {
+ if ((wiFiConnection->securitySettings.wepKey2.length() != 10) && (wiFiConnection->securitySettings.wepKey2.length() != 26)) {
+ if (reason) (*reason)[TDENetworkConnectionErrorFlags::InvalidWirelessKey] = i18n("WEP key 2 has invalid length");
+ if (type) *type |= TDENetworkConnectionErrorFlags::InvalidWirelessKey;
+ return false;
+ }
+ }
+ if (wiFiConnection->securitySettings.wepKey3 != "") {
+ if ((wiFiConnection->securitySettings.wepKey3.length() != 10) && (wiFiConnection->securitySettings.wepKey3.length() != 26)) {
+ if (reason) (*reason)[TDENetworkConnectionErrorFlags::InvalidWirelessKey] = i18n("WEP key 3 has invalid length");
+ if (type) *type |= TDENetworkConnectionErrorFlags::InvalidWirelessKey;
+ return false;
+ }
+ }
+ if ((wiFiConnection->securitySettings.wepKey0 == "") && (wiFiConnection->securitySettings.wepKey1 == "") && (wiFiConnection->securitySettings.wepKey2 == "") && (wiFiConnection->securitySettings.wepKey3 == "")) {
+ if (reason) (*reason)[TDENetworkConnectionErrorFlags::InvalidWirelessKey] = i18n("No WEP key(s) provided");
+ if (type) *type |= TDENetworkConnectionErrorFlags::InvalidWirelessKey;
+ return false;
+ }
+ }
+ else if (wiFiConnection->securitySettings.wepKeyType == TDENetworkWepKeyType::Ascii) {
+ if (wiFiConnection->securitySettings.wepKey0 != "") {
+ if ((wiFiConnection->securitySettings.wepKey0.length() != 5) && (wiFiConnection->securitySettings.wepKey0.length() != 13)) {
+ if (reason) (*reason)[TDENetworkConnectionErrorFlags::InvalidWirelessKey] = i18n("WEP key 0 has invalid length");
+ if (type) *type |= TDENetworkConnectionErrorFlags::InvalidWirelessKey;
+ return false;
+ }
+ }
+ if (wiFiConnection->securitySettings.wepKey1 != "") {
+ if ((wiFiConnection->securitySettings.wepKey1.length() != 5) && (wiFiConnection->securitySettings.wepKey1.length() != 13)) {
+ if (reason) (*reason)[TDENetworkConnectionErrorFlags::InvalidWirelessKey] = i18n("WEP key 1 has invalid length");
+ if (type) *type |= TDENetworkConnectionErrorFlags::InvalidWirelessKey;
+ return false;
+ }
+ }
+ if (wiFiConnection->securitySettings.wepKey2 != "") {
+ if ((wiFiConnection->securitySettings.wepKey2.length() != 5) && (wiFiConnection->securitySettings.wepKey2.length() != 13)) {
+ if (reason) (*reason)[TDENetworkConnectionErrorFlags::InvalidWirelessKey] = i18n("WEP key 2 has invalid length");
+ if (type) *type |= TDENetworkConnectionErrorFlags::InvalidWirelessKey;
+ return false;
+ }
+ }
+ if (wiFiConnection->securitySettings.wepKey3 != "") {
+ if ((wiFiConnection->securitySettings.wepKey3.length() != 5) && (wiFiConnection->securitySettings.wepKey3.length() != 13)) {
+ if (reason) (*reason)[TDENetworkConnectionErrorFlags::InvalidWirelessKey] = i18n("WEP key 3 has invalid length");
+ if (type) *type |= TDENetworkConnectionErrorFlags::InvalidWirelessKey;
+ return false;
+ }
+ }
+ if ((wiFiConnection->securitySettings.wepKey0 == "") && (wiFiConnection->securitySettings.wepKey1 == "") && (wiFiConnection->securitySettings.wepKey2 == "") && (wiFiConnection->securitySettings.wepKey3 == "")) {
+ if (reason) (*reason)[TDENetworkConnectionErrorFlags::InvalidWirelessKey] = i18n("No WEP key(s) provided");
+ if (type) *type |= TDENetworkConnectionErrorFlags::InvalidWirelessKey;
+ return false;
+ }
+ }
+ else if (wiFiConnection->securitySettings.wepKeyType == TDENetworkWepKeyType::Ascii) {
+ if ((wiFiConnection->securitySettings.wepKey0 == "") && (wiFiConnection->securitySettings.wepKey1 == "") && (wiFiConnection->securitySettings.wepKey2 == "") && (wiFiConnection->securitySettings.wepKey3 == "")) {
+ if (reason) (*reason)[TDENetworkConnectionErrorFlags::InvalidWirelessKey] = i18n("No WEP key(s) provided");
+ if (type) *type |= TDENetworkConnectionErrorFlags::InvalidWirelessKey;
+ return false;
+ }
+ }
+ }
+ else if ((wiFiConnection->securitySettings.keyType == TDENetworkWiFiKeyType::DynamicWEP) && (wiFiConnection->securitySettings.authType == TDENetworkWiFiAuthType::LEAP)) {
+ if ((wiFiConnection->securitySettings.leapUsername.length() < 1) || (wiFiConnection->securitySettings.leapPassword.length() < 1)) {
+ if (reason) (*reason)[TDENetworkConnectionErrorFlags::InvalidWirelessKey] = i18n("LEAP username and/or password not provided");
+ if (type) *type |= TDENetworkConnectionErrorFlags::InvalidWirelessKey;
+ return false;
+ }
+ }
+ else if ((wiFiConnection->securitySettings.keyType == TDENetworkWiFiKeyType::WPAAdHoc) || (wiFiConnection->securitySettings.keyType == TDENetworkWiFiKeyType::WPAInfrastructure) || (wiFiConnection->securitySettings.keyType == TDENetworkWiFiKeyType::WPAEnterprise)) {
+ if (wiFiConnection->securitySettings.psk.length() == 64) {
+ // Verify that only hex characters are present in the string
+ bool ok;
+ wiFiConnection->securitySettings.psk.toULongLong(&ok, 16);
+ if (!ok) {
+ if (reason) (*reason)[TDENetworkConnectionErrorFlags::InvalidWirelessKey] = i18n("Hexadecimal length PSK contains non-hexadecimal characters");
+ if (type) *type |= TDENetworkConnectionErrorFlags::InvalidWirelessKey;
+ return false;
+ }
+ }
+ else if ((wiFiConnection->securitySettings.psk.length() < 8) || (wiFiConnection->securitySettings.psk.length() > 63)) {
+ if (reason) (*reason)[TDENetworkConnectionErrorFlags::InvalidWirelessKey] = i18n("No PSK provided");
+ if (type) *type |= TDENetworkConnectionErrorFlags::InvalidWirelessKey;
+ return false;
+ }
+ }
+ }
+ }
+ }
+
return TRUE;
}
@@ -4193,7 +4474,7 @@ TDENetworkConnectionStatus::TDENetworkConnectionStatus TDENetworkConnectionManag
}
}
else {
- PRINT_ERROR(TQString("invalid internal network-manager settings proxy object").arg(uuid));
+ PRINT_ERROR(TQString("invalid internal network-manager settings proxy object"));
return TDENetworkConnectionStatus::Invalid;
}
}
@@ -4215,7 +4496,7 @@ TDENetworkConnectionStatus::TDENetworkConnectionStatus TDENetworkConnectionManag
return TDENetworkConnectionStatus::Invalid;
}
else {
- PRINT_ERROR(TQString("invalid internal network-manager settings proxy object").arg(uuid));
+ PRINT_ERROR(TQString("invalid internal network-manager settings proxy object"));
return TDENetworkConnectionStatus::Invalid;
}
}
@@ -4238,9 +4519,8 @@ TQStringList TDENetworkConnectionManager_BackendNM::connectionPhysicalDeviceUUID
TQValueList<TQT_DBusObjectPath> deviceList = activeConnection.getDevices(error);
TQT_DBusObjectPathList::iterator it2;
for (it2 = deviceList.begin(); it2 != deviceList.end(); ++it2) {
- DBus::DeviceProxy underlyingNetworkDeviceProxy(NM_DBUS_SERVICE, *it2);
- underlyingNetworkDeviceProxy.setConnection(TQT_DBusConnection::systemBus());
- TQString devUUID = underlyingNetworkDeviceProxy.getUdi(error);
+ TQString macAddress = macAddressForGenericDevice(*it2);
+ TQString devUUID = tdeDeviceUUIDForMACAddress(macAddress);
if (devUUID != "") {
ret.append(devUUID);
}
@@ -4250,7 +4530,7 @@ TQStringList TDENetworkConnectionManager_BackendNM::connectionPhysicalDeviceUUID
return ret;
}
else {
- PRINT_ERROR(TQString("invalid internal network-manager settings proxy object").arg(uuid));
+ PRINT_ERROR(TQString("invalid internal network-manager settings proxy object"));
return TQStringList();
}
}
@@ -4303,7 +4583,7 @@ TDENetworkConnectionStatus::TDENetworkConnectionStatus TDENetworkConnectionManag
}
}
else {
- PRINT_ERROR(TQString("invalid internal network-manager settings proxy object").arg(uuid));
+ PRINT_ERROR(TQString("invalid internal network-manager settings proxy object"));
return TDENetworkConnectionStatus::Invalid;
}
}
@@ -4474,6 +4754,43 @@ bool TDENetworkConnectionManager_BackendNM::wiFiEnabled() {
}
}
+TQStringList TDENetworkConnectionManager_BackendNM::defaultNetworkDevices() {
+ // Cycle through all available connections and see which one is default, then find all devices for that connection...
+ TQStringList ret;
+
+ TQT_DBusObjectPath existingConnection;
+ TQT_DBusError error;
+ if (d->m_networkManagerProxy) {
+ TQT_DBusObjectPathList activeConnections = d->m_networkManagerProxy->getActiveConnections(error);
+ TQT_DBusObjectPathList::iterator it;
+ for (it = activeConnections.begin(); it != activeConnections.end(); ++it) {
+ DBus::ActiveConnectionProxy activeConnection(NM_DBUS_SERVICE, (*it));
+ activeConnection.setConnection(TQT_DBusConnection::systemBus());
+ if (activeConnection.getDefault(error)) {
+ // This is the default ipv4 connection
+ TQString uuid = activeConnection.getUuid(error);
+ TQStringList devices = connectionPhysicalDeviceUUIDs(uuid);
+ for (TQStringList::Iterator it2 = devices.begin(); it2 != devices.end(); ++it2) {
+ ret.append(*it);
+ }
+ }
+ else if (activeConnection.getDefault6(error)) {
+ // This is the default ipv6 connection
+ TQString uuid = activeConnection.getUuid(error);
+ TQStringList devices = connectionPhysicalDeviceUUIDs(uuid);
+ for (TQStringList::Iterator it2 = devices.begin(); it2 != devices.end(); ++it2) {
+ ret.append(*it);
+ }
+ }
+ }
+ return ret;
+ }
+ else {
+ PRINT_ERROR(TQString("invalid internal network-manager settings proxy object"));
+ return TQStringList();
+ }
+}
+
TDENetworkConnectionManager_BackendNMPrivate::TDENetworkConnectionManager_BackendNMPrivate(TDENetworkConnectionManager_BackendNM* parent) : m_networkManagerProxy(NULL), m_networkManagerSettings(NULL), m_networkDeviceProxy(NULL), m_wiFiDeviceProxy(NULL), m_parent(parent) {
//
}
diff --git a/tdecore/networkbackends/network-manager/network-manager.h b/tdecore/networkbackends/network-manager/network-manager.h
index 620841ba3..def7c9522 100644
--- a/tdecore/networkbackends/network-manager/network-manager.h
+++ b/tdecore/networkbackends/network-manager/network-manager.h
@@ -146,7 +146,7 @@ class TDECORE_EXPORT TDENetworkConnectionManager_BackendNM : public TDENetworkCo
virtual bool loadConnectionSecrets(TQString uuid);
virtual bool saveConnection(TDENetworkConnection* connection);
virtual bool deleteConnection(TQString uuid);
- virtual bool verifyConnectionSettings(TDENetworkConnection* connection);
+ virtual bool verifyConnectionSettings(TDENetworkConnection* connection, TDENetworkConnectionErrorFlags::TDENetworkConnectionErrorFlags* type=NULL, TDENetworkErrorStringMap* reason=NULL);
virtual TDENetworkConnectionStatus::TDENetworkConnectionStatus initiateConnection(TQString uuid);
virtual TDENetworkConnectionStatus::TDENetworkConnectionStatus checkConnectionStatus(TQString uuid);
@@ -162,6 +162,8 @@ class TDECORE_EXPORT TDENetworkConnectionManager_BackendNM : public TDENetworkCo
virtual bool enableWiFi(bool enable);
virtual bool wiFiEnabled();
+ virtual TQStringList defaultNetworkDevices();
+
private:
TDENetworkDeviceType::TDENetworkDeviceType nmDeviceTypeToTDEDeviceType(TQ_UINT32 nmType);
TQString deviceInterfaceString(TQString macAddress);
diff --git a/tdecore/tdenetworkconnections.cpp b/tdecore/tdenetworkconnections.cpp
index 9b435b2ac..f3f427687 100644
--- a/tdecore/tdenetworkconnections.cpp
+++ b/tdecore/tdenetworkconnections.cpp
@@ -781,6 +781,27 @@ TQString TDENetworkConnectionManager::friendlyConnectionTypeName(TDENetworkConne
}
}
+bool TDENetworkConnectionManager::validateIPAddress(TQHostAddress address) {
+ if (address.isIPv4Address()) {
+ TQ_UINT32 rawaddress = address.toIPv4Address();
+ if ((((rawaddress & 0xff000000) >> 24) == 0) || ((rawaddress & 0x000000ff) == 0) || ((rawaddress & 0x000000ff) == 255)) {
+ return false;
+ }
+ }
+ else if (address.isIPv6Address()) {
+ Q_IPV6ADDR rawaddress = address.toIPv6Address();
+ if (rawaddress.c[0] == 0xff) {
+ return false;
+ }
+ }
+ return true;
+}
+
+bool TDENetworkConnectionManager::validateIPNeworkMask(TQHostAddress netmask) {
+ Q_UNUSED(netmask);
+ return TRUE;
+}
+
void TDENetworkConnectionManager::clearTDENetworkConnectionList() {
TDENetworkConnection *connection;
for (connection = m_connectionList->first(); connection; connection = m_connectionList->next()) {
@@ -870,9 +891,9 @@ bool TDEGlobalNetworkManager::deleteConnection(TQString uuid) {
return m_internalConnectionManager->deleteConnection(uuid);
}
-bool TDEGlobalNetworkManager::verifyConnectionSettings(TDENetworkConnection* connection) {
+bool TDEGlobalNetworkManager::verifyConnectionSettings(TDENetworkConnection* connection, TDENetworkConnectionErrorFlags::TDENetworkConnectionErrorFlags* type, TDENetworkErrorStringMap* reason) {
if (!m_internalConnectionManager) return false;
- return m_internalConnectionManager->verifyConnectionSettings(connection);
+ return m_internalConnectionManager->verifyConnectionSettings(connection, type, reason);
}
TDENetworkConnectionStatus::TDENetworkConnectionStatus TDEGlobalNetworkManager::initiateConnection(TQString uuid) {
@@ -925,6 +946,11 @@ bool TDEGlobalNetworkManager::wiFiEnabled() {
return m_internalConnectionManager->wiFiEnabled();
}
+TQStringList TDEGlobalNetworkManager::defaultNetworkDevices() {
+ if (!m_internalConnectionManager) return NULL;
+ return m_internalConnectionManager->defaultNetworkDevices();
+}
+
TDENetworkConnectionList* TDEGlobalNetworkManager::connections() {
if (!m_internalConnectionManager) return NULL;
return m_internalConnectionManager->connections();
diff --git a/tdecore/tdenetworkconnections.h b/tdecore/tdenetworkconnections.h
index 04a9e1c79..a193f3f6b 100644
--- a/tdecore/tdenetworkconnections.h
+++ b/tdecore/tdenetworkconnections.h
@@ -99,6 +99,23 @@ namespace TDENetworkConnectionType {
};
};
+namespace TDENetworkConnectionErrorFlags {
+ enum TDENetworkConnectionErrorFlags {
+ NoError = 0x00000000,
+ InvalidConnectionSetting = 0x00000001,
+ InvalidIPv4Setting = 0x00000002,
+ InvalidIPv6Setting = 0x00000004,
+ InvalidEAPSetting = 0x00000008,
+ InvalidEAPKey = 0x00000010,
+ InvalidWirelessSetting = 0x00000020,
+ InvalidWirelessKey = 0x00000040
+ };
+
+ CREATE_FLAG_BITWISE_MANIPULATION_FUNCTIONS(TDENetworkConnectionErrorFlags)
+};
+
+typedef TQMap<TDENetworkConnectionErrorFlags::TDENetworkConnectionErrorFlags, TQString> TDENetworkErrorStringMap;
+
namespace TDENetworkInfinibandTransportMode {
enum TDENetworkInfinibandTransportMode {
Datagram,
@@ -301,6 +318,7 @@ namespace TDENetworkWiFiConnectionCipher {
namespace TDENetworkWepKeyType {
enum TDENetworkWepKeyType {
Hexadecimal,
+ Ascii,
Passphrase
};
};
@@ -1017,9 +1035,13 @@ class TDECORE_EXPORT TDENetworkConnectionManager : public TQObject
/**
* @param connection a pointer to a TDENetworkConnection object containing a
* connection for which to verify integrity of all settings.
+ * @param type a pointer to an TDENetworkConnectionErrorFlags::TDENetworkConnectionErrorFlags
+ * which will be filled with the generic error type code if provided.
+ * @param reason a pointer to a TDENetworkErrorStringMap which will be filled with translated
+ * strings containing the reason for the failure if provided.
* @return true on success, false if invalid settings are detected.
*/
- virtual bool verifyConnectionSettings(TDENetworkConnection* connection) = 0;
+ virtual bool verifyConnectionSettings(TDENetworkConnection* connection, TDENetworkConnectionErrorFlags::TDENetworkConnectionErrorFlags* type=NULL, TDENetworkErrorStringMap* reason=NULL) = 0;
/**
* Initiates a connection with UUID @param uuid.
@@ -1055,7 +1077,8 @@ class TDECORE_EXPORT TDENetworkConnectionManager : public TQObject
virtual TDENetworkHWNeighborList* siteSurvey() = 0;
/**
- * @return a TQStringList containing the UUIDs of all physical devices used by this connection
+ * @return a TQStringList containing the UUIDs of all physical devices used by the connection
+ * with UUID @param uuid.
* This function may return an empty list if the connection is inactive, this behaviour is
* dependend on the specific network backend in use.
*/
@@ -1088,6 +1111,12 @@ class TDECORE_EXPORT TDENetworkConnectionManager : public TQObject
*/
virtual bool wiFiEnabled() = 0;
+ /**
+ * @return a list of UUIDs of the default network devices, or an empty list if no such devices exist.
+ * The default network devices are normally the devices holding the highest priority default route.
+ */
+ virtual TQStringList defaultNetworkDevices() = 0;
+
signals:
/**
* Emitted whenever the state of the system's connection changes
@@ -1147,7 +1176,7 @@ class TDECORE_EXPORT TDENetworkConnectionManager : public TQObject
/**
* @return a pointer to a TDENetworkDevice object with the specified @param uuid,
- * or a NULL pointer if no such connection exists.
+ * or a NULL pointer if no such device exists.
*
* Note that the returned object is internally managed and must not be deleted!
*/
@@ -1166,6 +1195,16 @@ class TDECORE_EXPORT TDENetworkConnectionManager : public TQObject
*/
static TQString friendlyConnectionTypeName(TDENetworkConnectionType::TDENetworkConnectionType type);
+ /**
+ * @return true if @param address is valid, false if not
+ */
+ static bool validateIPAddress(TQHostAddress address);
+
+ /**
+ * @return true if @param netmask is valid, false if not
+ */
+ static bool validateIPNeworkMask(TQHostAddress netmask);
+
protected:
/**
* @internal Safely clears out the master connection list and deletes all member objects
@@ -1275,9 +1314,13 @@ class TDECORE_EXPORT TDEGlobalNetworkManager : public TQObject
/**
* @param connection a pointer to a TDENetworkConnection object containing a
* connection for which to verify integrity of all settings.
+ * @param type a pointer to an TDENetworkConnectionErrorFlags::TDENetworkConnectionErrorFlags
+ * which will be filled with the generic error type code if provided.
+ * @param reason a pointer to a TDENetworkErrorStringMap which will be filled with translated
+ * strings containing the reason for the failure if provided.
* @return true on success, false if invalid settings are detected.
*/
- virtual bool verifyConnectionSettings(TDENetworkConnection* connection);
+ virtual bool verifyConnectionSettings(TDENetworkConnection* connection, TDENetworkConnectionErrorFlags::TDENetworkConnectionErrorFlags* type=NULL, TDENetworkErrorStringMap* reason=NULL);
/**
* Initiates a connection with UUID @param uuid.
@@ -1311,7 +1354,8 @@ class TDECORE_EXPORT TDEGlobalNetworkManager : public TQObject
virtual TDENetworkHWNeighborList* siteSurvey();
/**
- * @return a TQStringList containing the UUIDs of all physical devices used by this connection
+ * @return a TQStringList containing the UUIDs of all physical devices used by the connection
+ * with UUID @param uuid.
* This function may return an empty list if the connection is inactive, this behaviour is
* dependend on the specific network backend in use.
*/
@@ -1344,6 +1388,12 @@ class TDECORE_EXPORT TDEGlobalNetworkManager : public TQObject
*/
virtual bool wiFiEnabled();
+ /**
+ * @return a list of UUIDs of the default network devices, or an empty list if no such devices exist.
+ * The default network devices are normally the devices holding the highest priority default route.
+ */
+ virtual TQStringList defaultNetworkDevices();
+
signals:
/**
* Emitted whenever the state of the system's connection changes
@@ -1397,7 +1447,7 @@ class TDECORE_EXPORT TDEGlobalNetworkManager : public TQObject
/**
* @return a pointer to a TDENetworkDevice object with the specified @param uuid,
- * or a NULL pointer if no such connection exists.
+ * or a NULL pointer if no such device exists.
*
* Note that the returned object is internally managed and must not be deleted!
*/