From 2dff663b9964c1df245d90e2cfc9beb4a8673bf8 Mon Sep 17 00:00:00 2001 From: Christopher Schramm Date: Sat, 26 Sep 2020 23:10:29 +0200 Subject: [PATCH] Pass object path instead of network interface name to DhcpClient --- blueman/main/DhcpClient.py | 1 + blueman/plugins/applet/DhcpClient.py | 12 +++++++----- blueman/plugins/manager/Services.py | 2 +- blueman/plugins/mechanism/Network.py | 5 +++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/blueman/main/DhcpClient.py b/blueman/main/DhcpClient.py index 0bf9e85f..6c26a0f9 100644 --- a/blueman/main/DhcpClient.py +++ b/blueman/main/DhcpClient.py @@ -24,6 +24,7 @@ class DhcpClient(GObject.GObject): quering = [] def __init__(self, interface, timeout=30): + """The interface name has to be trusted / sanitized!""" super().__init__() self._interface = interface diff --git a/blueman/plugins/applet/DhcpClient.py b/blueman/plugins/applet/DhcpClient.py index 334cda34..e2650372 100644 --- a/blueman/plugins/applet/DhcpClient.py +++ b/blueman/plugins/applet/DhcpClient.py @@ -1,7 +1,7 @@ # coding=utf-8 import logging -from blueman.bluez.Network import AnyNetwork +from blueman.bluez.Network import AnyNetwork, Network from blueman.gui.Notification import Notification from blueman.plugins.AppletPlugin import AppletPlugin from blueman.main.DBusProxies import Mechanism @@ -25,12 +25,14 @@ class DhcpClient(AppletPlugin): def on_unload(self): del self._any_network - def _on_network_prop_changed(self, _network, key, value, _path): + def _on_network_prop_changed(self, _network, key, value, object_path): if key == "Interface": if value != "": - self.dhcp_acquire(value) + self.dhcp_acquire(object_path) + + def dhcp_acquire(self, object_path): + device = Network(obj_path=object_path)["Interface"] - def dhcp_acquire(self, device): if device not in self.quering: self.quering.append(device) else: @@ -56,4 +58,4 @@ class DhcpClient(AppletPlugin): icon_name="network-workgroup").show() m = Mechanism() - m.DhcpClient('(s)', device, result_handler=reply, error_handler=err, timeout=120 * 1000) + m.DhcpClient('(s)', object_path, result_handler=reply, error_handler=err, timeout=120 * 1000) diff --git a/blueman/plugins/manager/Services.py b/blueman/plugins/manager/Services.py index eb355cbe..e6e8cd52 100644 --- a/blueman/plugins/manager/Services.py +++ b/blueman/plugins/manager/Services.py @@ -75,7 +75,7 @@ class Services(ManagerPlugin): if service.group == 'network' and service.connected: if "DhcpClient" in appl.QueryPlugins(): def renew(x): - appl.DhcpClient('(s)', Network(device.get_object_path())["Interface"]) + appl.DhcpClient('(s)', device.get_object_path()) item = create_menuitem(_("Renew IP Address"), "view-refresh") item.connect("activate", renew) diff --git a/blueman/plugins/mechanism/Network.py b/blueman/plugins/mechanism/Network.py index 1834829e..862052ec 100644 --- a/blueman/plugins/mechanism/Network.py +++ b/blueman/plugins/mechanism/Network.py @@ -1,5 +1,6 @@ # coding=utf-8 +from blueman.bluez.Network import Network as BluezNetwork from blueman.plugins.MechanismPlugin import MechanismPlugin from blueman.main.NetConf import NetConf, DnsMasqHandler, DhcpdHandler, UdhcpdHandler @@ -15,7 +16,7 @@ class Network(MechanismPlugin): self.parent.add_method("ReloadNetwork", (), "", self._reload_network, pass_sender=True) self.parent.add_method("DisableNetwork", (), "", self._disable_network, pass_sender=True) - def _run_dhcp_client(self, net_interface, caller, ok, err): + def _run_dhcp_client(self, object_path, caller, ok, err): self.timer.stop() self.confirm_authorization(caller, "org.blueman.dhcp.client") @@ -30,7 +31,7 @@ class Network(MechanismPlugin): ok(ip) self.timer.resume() - dh = DhcpClient(net_interface) + dh = DhcpClient(BluezNetwork(obj_path=object_path)["Interface"]) dh.connect("error-occurred", dh_error, ok, err) dh.connect("connected", dh_connected, ok, err) try: -- 2.28.0