Update public source
This commit is contained in:
+153
-8
@@ -533,6 +533,103 @@ class WiFiConnectionService:
|
|||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
def _get_active_access_point_bssid(self, interface):
|
||||||
|
|
||||||
|
device_path = self._device_path(
|
||||||
|
interface
|
||||||
|
)
|
||||||
|
|
||||||
|
parts = self._get_property(
|
||||||
|
device_path,
|
||||||
|
NM_DEVICE_WIRELESS,
|
||||||
|
"ActiveAccessPoint"
|
||||||
|
)
|
||||||
|
|
||||||
|
if len(parts) != 2 or parts[0] != "o":
|
||||||
|
raise WiFiConnectionError(
|
||||||
|
"Unexpected D-Bus type for ActiveAccessPoint."
|
||||||
|
)
|
||||||
|
|
||||||
|
object_path = parts[1]
|
||||||
|
|
||||||
|
if (
|
||||||
|
object_path == "/"
|
||||||
|
or
|
||||||
|
not object_path.startswith(
|
||||||
|
"/org/freedesktop/NetworkManager/AccessPoint/"
|
||||||
|
)
|
||||||
|
):
|
||||||
|
raise WiFiConnectionError(
|
||||||
|
"NetworkManager did not return the active access point."
|
||||||
|
)
|
||||||
|
|
||||||
|
parts = self._get_property(
|
||||||
|
object_path,
|
||||||
|
NM_ACCESS_POINT,
|
||||||
|
"HwAddress"
|
||||||
|
)
|
||||||
|
|
||||||
|
if len(parts) != 2 or parts[0] != "s":
|
||||||
|
raise WiFiConnectionError(
|
||||||
|
"Unexpected D-Bus type for the active access point BSSID."
|
||||||
|
)
|
||||||
|
|
||||||
|
bssid = parts[1]
|
||||||
|
|
||||||
|
self._validate_bssid(
|
||||||
|
bssid
|
||||||
|
)
|
||||||
|
|
||||||
|
return bssid.upper()
|
||||||
|
|
||||||
|
def _handle_failed_profile_creation(
|
||||||
|
self,
|
||||||
|
profile_name,
|
||||||
|
creation_error
|
||||||
|
):
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
output = self._nmcli(
|
||||||
|
"--terse",
|
||||||
|
"--escape",
|
||||||
|
"yes",
|
||||||
|
"--fields",
|
||||||
|
"NAME",
|
||||||
|
"connection",
|
||||||
|
"show"
|
||||||
|
)
|
||||||
|
|
||||||
|
except NetworkCommandError as inspection_error:
|
||||||
|
|
||||||
|
raise NetworkCleanupError(
|
||||||
|
"NetworkManager failed to create a temporary profile, "
|
||||||
|
"and its state could not be determined. "
|
||||||
|
f"Profile name: {profile_name}. "
|
||||||
|
f"Inspection failed: {inspection_error}"
|
||||||
|
) from creation_error
|
||||||
|
|
||||||
|
if profile_name in output.splitlines():
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
self._nmcli(
|
||||||
|
"connection",
|
||||||
|
"delete",
|
||||||
|
"id",
|
||||||
|
profile_name
|
||||||
|
)
|
||||||
|
|
||||||
|
except NetworkCommandError as cleanup_error:
|
||||||
|
|
||||||
|
raise NetworkCleanupError(
|
||||||
|
"NetworkManager may have created a temporary profile, "
|
||||||
|
"but it could not be deleted: "
|
||||||
|
f"{cleanup_error}"
|
||||||
|
) from creation_error
|
||||||
|
|
||||||
|
raise creation_error
|
||||||
|
|
||||||
def _create_temporary_profile(
|
def _create_temporary_profile(
|
||||||
self,
|
self,
|
||||||
interface,
|
interface,
|
||||||
@@ -575,9 +672,18 @@ class WiFiConnectionService:
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
self._nmcli(
|
try:
|
||||||
*arguments
|
|
||||||
)
|
self._nmcli(
|
||||||
|
*arguments
|
||||||
|
)
|
||||||
|
|
||||||
|
except NetworkCommandError as error:
|
||||||
|
|
||||||
|
self._handle_failed_profile_creation(
|
||||||
|
profile_name,
|
||||||
|
error
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
@@ -663,7 +769,7 @@ class WiFiConnectionService:
|
|||||||
"\n"
|
"\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
except Exception:
|
except Exception as error:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.close(
|
os.close(
|
||||||
@@ -676,8 +782,14 @@ class WiFiConnectionService:
|
|||||||
os.unlink(
|
os.unlink(
|
||||||
filename
|
filename
|
||||||
)
|
)
|
||||||
except OSError:
|
|
||||||
pass
|
except OSError as cleanup_error:
|
||||||
|
|
||||||
|
raise NetworkCleanupError(
|
||||||
|
"Could not prepare the temporary password file. "
|
||||||
|
"The file could not be deleted: "
|
||||||
|
f"{cleanup_error}"
|
||||||
|
) from error
|
||||||
|
|
||||||
raise
|
raise
|
||||||
|
|
||||||
@@ -704,6 +816,8 @@ class WiFiConnectionService:
|
|||||||
|
|
||||||
password_file = None
|
password_file = None
|
||||||
|
|
||||||
|
operation_error = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
if access_point.key_mgmt:
|
if access_point.key_mgmt:
|
||||||
@@ -735,6 +849,10 @@ class WiFiConnectionService:
|
|||||||
timeout=90
|
timeout=90
|
||||||
)
|
)
|
||||||
|
|
||||||
|
except Exception as error:
|
||||||
|
|
||||||
|
operation_error = error
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
|
||||||
if password_file:
|
if password_file:
|
||||||
@@ -743,8 +861,25 @@ class WiFiConnectionService:
|
|||||||
os.unlink(
|
os.unlink(
|
||||||
password_file
|
password_file
|
||||||
)
|
)
|
||||||
except OSError:
|
|
||||||
pass
|
except OSError as cleanup_error:
|
||||||
|
|
||||||
|
if operation_error:
|
||||||
|
|
||||||
|
raise NetworkCleanupError(
|
||||||
|
"Wi-Fi activation failed: "
|
||||||
|
f"{operation_error}. "
|
||||||
|
"The temporary password file could not be deleted: "
|
||||||
|
f"{cleanup_error}"
|
||||||
|
) from operation_error
|
||||||
|
|
||||||
|
raise NetworkCleanupError(
|
||||||
|
"The temporary password file could not be deleted: "
|
||||||
|
f"{cleanup_error}"
|
||||||
|
) from cleanup_error
|
||||||
|
|
||||||
|
if operation_error:
|
||||||
|
raise operation_error
|
||||||
|
|
||||||
def _delete_profile(self, profile_uuid):
|
def _delete_profile(self, profile_uuid):
|
||||||
|
|
||||||
@@ -846,6 +981,14 @@ class WiFiConnectionService:
|
|||||||
interface
|
interface
|
||||||
)
|
)
|
||||||
|
|
||||||
|
previous_bssid = None
|
||||||
|
|
||||||
|
if previous_uuid:
|
||||||
|
|
||||||
|
previous_bssid = self._get_active_access_point_bssid(
|
||||||
|
interface
|
||||||
|
)
|
||||||
|
|
||||||
profile_uuid = None
|
profile_uuid = None
|
||||||
success = False
|
success = False
|
||||||
operation_error = None
|
operation_error = None
|
||||||
@@ -891,6 +1034,8 @@ class WiFiConnectionService:
|
|||||||
previous_uuid,
|
previous_uuid,
|
||||||
"ifname",
|
"ifname",
|
||||||
interface,
|
interface,
|
||||||
|
"ap",
|
||||||
|
previous_bssid,
|
||||||
timeout=90
|
timeout=90
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user