Blame SOURCES/0002-firewall.core.fw_nm-identify-the-connections-by-uuid.patch

15ccd1
From 0ce07e30014a8ee6b2a8a4909c313f207d9c9b31 Mon Sep 17 00:00:00 2001
15ccd1
From: Lubomir Rintel <lkundrak@v3.sk>
15ccd1
Date: Mon, 16 Jul 2018 17:43:04 +0200
15ccd1
Subject: [PATCH 2/3] firewall.core.fw_nm: identify the connections by uuid
15ccd1
15ccd1
...as opposed by id. Uuid is guarranteed to be uniquie, while the id is
15ccd1
provided merely for convenience without any guarrantees.
15ccd1
15ccd1
(cherry picked from commit 624039964bd16e5e0e8ffb73e708d3d0c40e89d3)
15ccd1
---
15ccd1
 src/firewall-applet        | 38 ++++++++++++++++++++------------------
15ccd1
 src/firewall-config        | 45 +++++++++++++++++++++++++--------------------
15ccd1
 src/firewall/core/fw_nm.py | 16 ++++++++--------
15ccd1
 3 files changed, 53 insertions(+), 46 deletions(-)
15ccd1
15ccd1
diff --git a/src/firewall-applet b/src/firewall-applet
15ccd1
index 3dc149c32755..86aaccab9f88 100755
15ccd1
--- a/src/firewall-applet
15ccd1
+++ b/src/firewall-applet
15ccd1
@@ -155,11 +155,12 @@ class ZoneInterfaceEditor(QtGui.QDialog):
15ccd1
 # ZoneConnectionEditor ########################################################
15ccd1
 
15ccd1
 class ZoneConnectionEditor(ZoneInterfaceEditor):
15ccd1
-    def __init__(self, fw, connection, zone):
15ccd1
+    def __init__(self, fw, connection, connection_name, zone):
15ccd1
         self.fw = fw
15ccd1
         self.connection = connection
15ccd1
+        self.connection_name = connection_name
15ccd1
         self.zone = None
15ccd1
-        self.title = _("Select zone for connection '%s'") % self.connection
15ccd1
+        self.title = _("Select zone for connection '%s'") % self.connection_name
15ccd1
 
15ccd1
         QtGui.QDialog.__init__(self)
15ccd1
         self.create_ui(zone)
15ccd1
@@ -168,12 +169,12 @@ class ZoneConnectionEditor(ZoneInterfaceEditor):
15ccd1
         # apply changes
15ccd1
         try:
15ccd1
             nm_set_zone_of_connection(self.get_zone(), self.connection)
15ccd1
-        except Exception as msg:
15ccd1
-            text = _("Failed to set zone {zone} for connection {connection}")
15ccd1
+        except Exception:
15ccd1
+            text = _("Failed to set zone {zone} for connection {connection_name}")
15ccd1
             QtGui.QMessageBox.warning(None, fromUTF8(escape(self.title)),
15ccd1
                                       escape(text.format(
15ccd1
                                           zone=self.get_zone(),
15ccd1
-                                          connection=self.connection)))
15ccd1
+                                          connection_name=self.connection_name)))
15ccd1
         self.hide()
15ccd1
 
15ccd1
 # ZoneSourceEditor ############################################################
15ccd1
@@ -428,7 +429,7 @@ class TrayApplet(QtGui.QSystemTrayIcon):
15ccd1
 
15ccd1
         self.active_zones = { }
15ccd1
         self.connections = { }
15ccd1
-        self.connections_uuid = { }
15ccd1
+        self.connections_name = { }
15ccd1
         self.default_zone = None
15ccd1
         self.zone_connection_editors = { }
15ccd1
         self.zone_interface_editors = { }
15ccd1
@@ -666,30 +667,31 @@ class TrayApplet(QtGui.QSystemTrayIcon):
15ccd1
         # NM controlled connections
15ccd1
         for interface in self.connections:
15ccd1
             connection = self.connections[interface]
15ccd1
-            if connection not in self.connections_uuid:
15ccd1
-                uuid = None
15ccd1
+            if connection not in self.connections_name:
15ccd1
+                connection_name = None
15ccd1
             else:
15ccd1
-                uuid = self.connections_uuid[connection]
15ccd1
+                connection_name = self.connections_name[connection]
15ccd1
             zone = nm_get_zone_of_connection(connection)
15ccd1
-            connections[connection] = [ zone, uuid ]
15ccd1
+            connections[connection] = [ zone, connection_name ]
15ccd1
 
15ccd1
         binding = _("{entry} (Zone: {zone})")
15ccd1
 
15ccd1
         # add NM controlled bindings
15ccd1
         for connection in sorted(connections):
15ccd1
             zone = connections[connection][0]
15ccd1
+            connection_name = connections[connection][1]
15ccd1
             if zone == "":
15ccd1
                 _binding = _("{entry} (Default Zone: {default_zone})")
15ccd1
                 action = QtGui.QAction(
15ccd1
                     fromUTF8(escape(
15ccd1
                         _binding.format(default_zone=self.default_zone,
15ccd1
-                                        entry=connection))), self)
15ccd1
+                                        entry=connection_name))), self)
15ccd1
             else:
15ccd1
                 action = QtGui.QAction(
15ccd1
                     fromUTF8(escape(binding.format(zone=zone,
15ccd1
-                                                   entry=connection))), self)
15ccd1
+                                                   entry=connection_name))), self)
15ccd1
             action.triggered.connect(functools.partial(
15ccd1
-                self.zone_connection_editor, connection, zone))
15ccd1
+                self.zone_connection_editor, connection, connection_name, zone))
15ccd1
             self.left_menu.addAction(action)
15ccd1
 
15ccd1
         # add interfaces entry
15ccd1
@@ -729,13 +731,13 @@ class TrayApplet(QtGui.QSystemTrayIcon):
15ccd1
         editor.raise_()
15ccd1
         editor.show()
15ccd1
 
15ccd1
-    def zone_connection_editor(self, connection, zone):
15ccd1
+    def zone_connection_editor(self, connection, connection_name, zone):
15ccd1
         if connection in self.zone_connection_editors:
15ccd1
             self.zone_connection_editors[connection].set_zone(zone)
15ccd1
             self.zone_connection_editors[connection].show()
15ccd1
             return self.zone_connection_editors[connection].raise_()
15ccd1
 
15ccd1
-        editor = ZoneConnectionEditor(self.fw, connection, zone)
15ccd1
+        editor = ZoneConnectionEditor(self.fw, connection, connection_name, zone)
15ccd1
         self.zone_connection_editors[connection] = editor
15ccd1
         editor.show()
15ccd1
         editor.raise_()
15ccd1
@@ -755,15 +757,15 @@ class TrayApplet(QtGui.QSystemTrayIcon):
15ccd1
 
15ccd1
     def nm_signal_receiver(self, *args, **kwargs):
15ccd1
         self.connections.clear()
15ccd1
-        self.connections_uuid.clear()
15ccd1
+        self.connections_name.clear()
15ccd1
 
15ccd1
         # do not use NMClient could result in python core dump
15ccd1
 
15ccd1
         if nm_is_imported():
15ccd1
             text = _("Failed to get connections from NetworkManager")
15ccd1
             try:
15ccd1
-                nm_get_connections(self.connections, self.connections_uuid)
15ccd1
-            except Exception as msg:
15ccd1
+                nm_get_connections(self.connections, self.connections_name)
15ccd1
+            except Exception:
15ccd1
                 self.notify(escape(text), urgency=Notify.Urgency.CRITICAL)
15ccd1
                 if text not in self.tooltip_messages:
15ccd1
                     self.tooltip_messages.append(text)
15ccd1
diff --git a/src/firewall-config b/src/firewall-config
15ccd1
index 02bffabf457c..223c0ff6d27d 100755
15ccd1
--- a/src/firewall-config
15ccd1
+++ b/src/firewall-config
15ccd1
@@ -1368,7 +1368,7 @@ class FirewallConfig(object):
15ccd1
         # connect
15ccd1
 
15ccd1
         self.connections = { }
15ccd1
-        self.connections_uuid = { }
15ccd1
+        self.connections_name = { }
15ccd1
 
15ccd1
         if nm_is_imported():
15ccd1
             self.fw.bus.add_signal_receiver(
15ccd1
@@ -1428,11 +1428,11 @@ class FirewallConfig(object):
15ccd1
             self.fw.changeZoneOfInterface(editor.get_zone(), interface)
15ccd1
         del self.zone_interface_editors[interface]
15ccd1
 
15ccd1
-    def change_zone_connection_editor(self, item, connection, zone):
15ccd1
+    def change_zone_connection_editor(self, item, connection, connection_name, zone):
15ccd1
         if connection in self.zone_connection_editors:
15ccd1
             return self.zone_connection_editors[connection].present()
15ccd1
 
15ccd1
-        editor = ZoneConnectionEditor(self.fw, connection, zone)
15ccd1
+        editor = ZoneConnectionEditor(self.fw, connection, connection_name, zone)
15ccd1
         editor.set_icon(self.icon)
15ccd1
         editor.set_position(Gtk.WindowPosition.CENTER_ON_PARENT)
15ccd1
         editor.set_transient_for(self.mainWindow)
15ccd1
@@ -1557,14 +1557,14 @@ class FirewallConfig(object):
15ccd1
         self.update_active_zones()
15ccd1
 
15ccd1
         self.connections.clear()
15ccd1
-        self.connections_uuid.clear()
15ccd1
+        self.connections_name.clear()
15ccd1
 
15ccd1
         # do not use NMClient could result in python core dump
15ccd1
 
15ccd1
         if nm_is_imported():
15ccd1
             try:
15ccd1
-                nm_get_connections(self.connections, self.connections_uuid)
15ccd1
-            except Exception as msg:
15ccd1
+                nm_get_connections(self.connections, self.connections_name)
15ccd1
+            except Exception:
15ccd1
                 text = _("Failed to get connections from NetworkManager")
15ccd1
                 self._warning(text)
15ccd1
 
15ccd1
@@ -1572,12 +1572,14 @@ class FirewallConfig(object):
15ccd1
         while iter:
15ccd1
             interface = self.interfaceStore.get_value(iter, 0)
15ccd1
             if interface in self.connections:
15ccd1
-                zone = nm_get_zone_of_connection(self.connections[interface])
15ccd1
+                connection = self.connections[interface]
15ccd1
+                connection_name = self.connections_name[connection]
15ccd1
+                zone = nm_get_zone_of_connection(connection)
15ccd1
                 if zone == "":
15ccd1
                     comment = self.default_zone_used_by_label % \
15ccd1
-                              self.connections[interface]
15ccd1
+                              connection_name
15ccd1
                 else:
15ccd1
-                    comment = self.used_by_label % self.connections[interface]
15ccd1
+                    comment = self.used_by_label % connection_name
15ccd1
                 self.interfaceStore.set_value(iter, 1, comment)
15ccd1
             iter = self.interfaceStore.iter_next(iter)
15ccd1
         self.change_interface_selection_cb(self.interfaceView.get_selection())
15ccd1
@@ -2427,37 +2429,38 @@ class FirewallConfig(object):
15ccd1
         # add NM controlled entries
15ccd1
         for connection in sorted(connections):
15ccd1
             [ zone, _interfaces ] = connections[connection]
15ccd1
+            connection_name = self.connections_name[connection]
15ccd1
 
15ccd1
             item = Gtk.MenuItem.new()
15ccd1
             hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6)
15ccd1
             label = Gtk.Label()
15ccd1
             if zone == "":
15ccd1
                 label.set_markup("%s (%s)\n<small>%s: %s</small>" % \
15ccd1
-                                 (connection, ",".join(_interfaces),
15ccd1
+                                 (connection_name, ",".join(_interfaces),
15ccd1
                                   escape(_("Default Zone")), self.default_zone))
15ccd1
             else:
15ccd1
                 label.set_markup("%s (%s)\n<small>%s: %s</small>" % \
15ccd1
-                                 (connection, ",".join(_interfaces),
15ccd1
+                                 (connection_name, ",".join(_interfaces),
15ccd1
                                   escape(_("Zone")), zone))
15ccd1
             label.set_alignment(0, 0.5)
15ccd1
             label.set_padding(12, 0)
15ccd1
             hbox.pack_start(label, True, True, 0)
15ccd1
             item.add(hbox)
15ccd1
-            item.connect("activate", self.change_zone_connection_editor, connection, zone)
15ccd1
+            item.connect("activate", self.change_zone_connection_editor, connection, connection_name, zone)
15ccd1
             self.left_menu.append(item)
15ccd1
 
15ccd1
             if zone == "":
15ccd1
                 self.bindingsStore.append(
15ccd1
                     self.connectionsIter,
15ccd1
                     [ "%s (%s)\n<small>%s</small>" % (
15ccd1
-                        connection, ",".join(_interfaces),
15ccd1
+                        connection_name, ",".join(_interfaces),
15ccd1
                         _("Default Zone: %s") % self.default_zone),
15ccd1
                       connection, zone ])
15ccd1
             else:
15ccd1
                 self.bindingsStore.append(
15ccd1
                     self.connectionsIter,
15ccd1
                     [ "%s (%s)\n<small>%s</small>" % (
15ccd1
-                        connection, ",".join(_interfaces),
15ccd1
+                        connection_name, ",".join(_interfaces),
15ccd1
                         _("Zone: %s") % zone),
15ccd1
                       connection, zone ])
15ccd1
 
15ccd1
@@ -2683,7 +2686,7 @@ class FirewallConfig(object):
15ccd1
         zone = self.bindingsStore.get_value(iter, 2)
15ccd1
 
15ccd1
         if self.bindingsStore.get_value(parent_iter, 0) == _("Connections"):
15ccd1
-            self.change_zone_connection_editor(None, item, zone)
15ccd1
+            self.change_zone_connection_editor(None, item, self.connections_name[item], zone)
15ccd1
         elif self.bindingsStore.get_value(parent_iter, 0) == _("Interfaces"):
15ccd1
             self.change_zone_interface_editor(None, item, zone)
15ccd1
         elif self.bindingsStore.get_value(parent_iter, 0) == _("Sources"):
15ccd1
@@ -3894,9 +3897,10 @@ class FirewallConfig(object):
15ccd1
         interface = self.interfaceStore.get_value(iter, 0)
15ccd1
         if interface in self.connections:
15ccd1
             connection = self.connections[interface]
15ccd1
+            connection_name = self.connections_name[connection]
15ccd1
             if selected_zone == self.default_zone:
15ccd1
                 selected_zone = nm_get_zone_of_connection(connection)
15ccd1
-            editor = ZoneConnectionEditor(self.fw, connection, selected_zone)
15ccd1
+            editor = ZoneConnectionEditor(self.fw, connection, connection_name, selected_zone)
15ccd1
             editor.set_icon(self.icon)
15ccd1
             editor.set_position(Gtk.WindowPosition.CENTER_ON_PARENT)
15ccd1
             editor.set_transient_for(self.mainWindow)
15ccd1
@@ -3905,9 +3909,9 @@ class FirewallConfig(object):
15ccd1
                 result = editor.run()
15ccd1
             except Exception:
15ccd1
                 text = _("Failed to set zone {zone} "
15ccd1
-                         "for connection {connection}")
15ccd1
+                         "for connection {connection_name}")
15ccd1
                 self._warning(text.format(zone=editor.get_zone(),
15ccd1
-                                          connection=editor.connection))
15ccd1
+                                          connection_name=editor.connection_name))
15ccd1
             editor.hide()
15ccd1
         else:
15ccd1
             self.add_edit_interface(False)
15ccd1
@@ -8115,11 +8119,12 @@ class ZoneInterfaceEditor(Gtk.Dialog):
15ccd1
         self.fw.changeZoneOfInterface(self.get_zone(), self.interface)
15ccd1
 
15ccd1
 class ZoneConnectionEditor(ZoneInterfaceEditor):
15ccd1
-    def __init__(self, fw, connection, zone):
15ccd1
+    def __init__(self, fw, connection, connection_name, zone):
15ccd1
         self.fw = fw
15ccd1
         self.connection = connection
15ccd1
+        self.connection_name = connection_name
15ccd1
         self.zone = None
15ccd1
-        self.title = _("Select zone for connection '%s'") % self.connection
15ccd1
+        self.title = _("Select zone for connection '%s'") % self.connection_name
15ccd1
 
15ccd1
         Gtk.Dialog.__init__(self, self.title)
15ccd1
         self.create_ui(zone)
15ccd1
diff --git a/src/firewall/core/fw_nm.py b/src/firewall/core/fw_nm.py
15ccd1
index 76901cee2adf..d21cc25feb8b 100644
15ccd1
--- a/src/firewall/core/fw_nm.py
15ccd1
+++ b/src/firewall/core/fw_nm.py
15ccd1
@@ -73,7 +73,7 @@ def nm_get_zone_of_connection(connection):
15ccd1
     """
15ccd1
     check_nm_imported()
15ccd1
 
15ccd1
-    con = nm_get_client().get_connection_by_id(connection)
15ccd1
+    con = nm_get_client().get_connection_by_uuid(connection)
15ccd1
     if con is None:
15ccd1
         return False
15ccd1
 
15ccd1
@@ -94,7 +94,7 @@ def nm_set_zone_of_connection(zone, connection):
15ccd1
     """
15ccd1
     check_nm_imported()
15ccd1
 
15ccd1
-    con = nm_get_client().get_connection_by_id(connection)
15ccd1
+    con = nm_get_client().get_connection_by_uuid(connection)
15ccd1
     if con is None:
15ccd1
         return False
15ccd1
 
15ccd1
@@ -107,14 +107,14 @@ def nm_set_zone_of_connection(zone, connection):
15ccd1
     setting_con.set_property("zone", zone)
15ccd1
     return con.commit_changes(True, None)
15ccd1
 
15ccd1
-def nm_get_connections(connections, connections_uuid):
15ccd1
+def nm_get_connections(connections, connections_name):
15ccd1
     """Get active connections from NM
15ccd1
     @param connections return dict
15ccd1
-    @param connections_uuid return dict
15ccd1
+    @param connections_name return dict
15ccd1
     """
15ccd1
 
15ccd1
     connections.clear()
15ccd1
-    connections_uuid.clear()
15ccd1
+    connections_name.clear()
15ccd1
 
15ccd1
     check_nm_imported()
15ccd1
 
15ccd1
@@ -129,9 +129,9 @@ def nm_get_connections(connections, connections_uuid):
15ccd1
         uuid = active_con.get_uuid()
15ccd1
         devices = active_con.get_devices()
15ccd1
 
15ccd1
-        connections_uuid[name] = uuid
15ccd1
+        connections_name[uuid] = name
15ccd1
         for dev in devices:
15ccd1
-            connections[dev.get_iface()] = name
15ccd1
+            connections[dev.get_iface()] = uuid
15ccd1
 
15ccd1
 def nm_get_connection_of_interface(interface):
15ccd1
     """Get connection from NM that is using the interface
15ccd1
@@ -148,7 +148,7 @@ def nm_get_connection_of_interface(interface):
15ccd1
     if active_con is None:
15ccd1
         return None
15ccd1
 
15ccd1
-    return active_con.get_id()
15ccd1
+    return active_con.get_uuid()
15ccd1
 
15ccd1
 def nm_get_bus_name():
15ccd1
     if not _nm_imported:
15ccd1
-- 
15ccd1
2.16.3
15ccd1