[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[et-mgmt-tools] [PATCH] virt-manager: network devices vs qemu:///session



Hi,
I might be completely of track here but isn't the logic virt-manger uses
to determine the network devices one can add a bit bogus: 

Currently it's based on the uid of the user, shouldn't this be based on
the connection type instead? Otherwise a user can't add multiple nics to
qemu:///system he's otherwise authorized to change in every way.

Possible patch attached.
Chees,
 -- Guido
# HG changeset patch
# User "Guido Günther <agx sigxcpu org>"
# Date 1222098649 -7200
# Node ID 1e2e85e9ff9e4e3610ff408b8fafbf28cb3ea476
# Parent  b121112a70c23f772215c896c75dd80da9d1fb80
fix network handling in qemu session mode

diff -r b121112a70c2 -r 1e2e85e9ff9e src/virtManager/addhardware.py
--- a/src/virtManager/addhardware.py	Thu Sep 18 11:13:49 2008 -0400
+++ b/src/virtManager/addhardware.py	Mon Sep 22 17:50:49 2008 +0200
@@ -217,11 +217,10 @@
         model = self.window.get_widget("hardware-type").get_model()
         model.clear()
         model.append(["Storage device", gtk.STOCK_HARDDISK, PAGE_DISK])
-        # Can't use shared or virtual networking as regular user
+        # Can't use shared or virtual networking in qemu:///session
         # Can only have one usermode network device
-        if (os.getuid() == 0 or
-            (self.vm.get_connection().get_type().lower() == "qemu" and
-             len(self.vm.get_network_devices()) == 0)):
+        if not self.vm.get_connection().is_qemu_session() or \
+           len(self.vm.get_network_devices()) == 0:
             model.append(["Network card", gtk.STOCK_NETWORK, PAGE_NETWORK])
 
         # Can only customize HVM guests, no Xen PV
@@ -242,7 +241,8 @@
 
         hwtype = self.get_config_hardware_type()
         if notebook.get_current_page() == PAGE_INTRO and \
-           (hwtype != PAGE_NETWORK or os.getuid() == 0):
+           (hwtype != PAGE_NETWORK or \
+            not self.vm.get_connection().is_qemu_session()):
             notebook.set_current_page(hwtype)
         else:
             notebook.set_current_page(PAGE_SUMMARY)
@@ -255,7 +255,8 @@
 
         if notebook.get_current_page() == PAGE_SUMMARY:
             hwtype = self.get_config_hardware_type()
-            if hwtype == PAGE_NETWORK and os.getuid() != 0:
+            if hwtype == PAGE_NETWORK and \
+               self.vm.get_connection().is_qemu_session():
                 notebook.set_current_page(PAGE_INTRO)
             else:
                 notebook.set_current_page(hwtype)
@@ -344,7 +345,7 @@
             return None
 
     def get_config_network(self):
-        if os.getuid() != 0:
+        if self.vm.get_connection().is_qemu_session():
             return ["user"]
 
         if self.window.get_widget("net-type-network").get_active():
@@ -496,7 +497,7 @@
         self.close()
 
     def add_network(self):
-        if self._dev is None and os.getuid() != 0:
+        if self._dev is None and self.vm.get_connection().is_qemu_session():
             self._dev = virtinst.VirtualNetworkInterface(type="user")
         self._dev.setup(self.vm.get_connection().vmm)
         self.add_device(self._dev.get_xml_config())
diff -r b121112a70c2 -r 1e2e85e9ff9e src/virtManager/connection.py
--- a/src/virtManager/connection.py	Thu Sep 18 11:13:49 2008 -0400
+++ b/src/virtManager/connection.py	Mon Sep 22 17:50:49 2008 +0200
@@ -346,6 +346,12 @@
             return True
         except:
             return True
+
+    def is_qemu_session(self):
+        (scheme, username, netloc, path, query, fragment) = uri_split(self.uri)
+        if path == "/session" and scheme.startswith("qemu"):
+            return True
+        return False
 
     def get_uri(self):
         return self.uri

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]