From 0476f2932e068e7eeadab0e59fd5e674ef8290b7 Mon Sep 17 00:00:00 2001 From: grossmj Date: Wed, 27 May 2015 13:56:27 -0600 Subject: [PATCH] Prevent users to add links to running Qemu VMs and start a capture on running VirtualBox VMs. --- gns3server/handlers/api/virtualbox_handler.py | 2 +- gns3server/modules/qemu/qemu_vm.py | 4 +++- gns3server/modules/virtualbox/virtualbox_vm.py | 5 +++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/gns3server/handlers/api/virtualbox_handler.py b/gns3server/handlers/api/virtualbox_handler.py index 62cc4e6a..38274a3a 100644 --- a/gns3server/handlers/api/virtualbox_handler.py +++ b/gns3server/handlers/api/virtualbox_handler.py @@ -344,7 +344,7 @@ class VirtualBoxHandler: vm = vbox_manager.get_vm(request.match_info["vm_id"], project_id=request.match_info["project_id"]) adapter_number = int(request.match_info["adapter_number"]) pcap_file_path = os.path.join(vm.project.capture_working_directory(), request.json["capture_file_name"]) - vm.start_capture(adapter_number, pcap_file_path) + yield from vm.start_capture(adapter_number, pcap_file_path) response.json({"pcap_file_path": pcap_file_path}) @Route.post( diff --git a/gns3server/modules/qemu/qemu_vm.py b/gns3server/modules/qemu/qemu_vm.py index e93e4630..73c18d2e 100644 --- a/gns3server/modules/qemu/qemu_vm.py +++ b/gns3server/modules/qemu/qemu_vm.py @@ -741,6 +741,8 @@ class QemuVM(BaseVM): adapter_number=adapter_number)) if self.is_running(): + raise QemuError("Sorry, adding a link to a started Qemu VM is not supported.") + # FIXME: does the code below work? very undocumented feature... # dynamically configure an UDP tunnel on the QEMU VM adapter if nio and isinstance(nio, NIOUDP): if self._legacy_networking: @@ -751,7 +753,6 @@ class QemuVM(BaseVM): nio.rport, nio.rhost)) else: - # FIXME: does it work? very undocumented feature... # Apparently there is a bug in Qemu... # netdev_add [user|tap|socket|hubport|netmap],id=str[,prop=value][,...] -- add host network device # netdev_del id -- remove host network device @@ -785,6 +786,7 @@ class QemuVM(BaseVM): adapter_number=adapter_number)) if self.is_running(): + # FIXME: does the code below work? very undocumented feature... # dynamically disable the QEMU VM adapter yield from self._control_vm("host_net_remove {} gns3-{}".format(adapter_number, adapter_number)) yield from self._control_vm("host_net_add user vlan={},name=gns3-{}".format(adapter_number, adapter_number)) diff --git a/gns3server/modules/virtualbox/virtualbox_vm.py b/gns3server/modules/virtualbox/virtualbox_vm.py index b9b91424..ddeb6089 100644 --- a/gns3server/modules/virtualbox/virtualbox_vm.py +++ b/gns3server/modules/virtualbox/virtualbox_vm.py @@ -851,6 +851,7 @@ class VirtualBoxVM(BaseVM): adapter_number=adapter_number)) return nio + @asyncio.coroutine def start_capture(self, adapter_number, output_file): """ Starts a packet capture. @@ -865,6 +866,10 @@ class VirtualBoxVM(BaseVM): raise VirtualBoxError("Adapter {adapter_number} doesn't exist on VirtualBox VM '{name}'".format(name=self.name, adapter_number=adapter_number)) + vm_state = yield from self._get_vm_state() + if vm_state == "running" or vm_state == "paused" or vm_state == "stuck": + raise VirtualBoxError("Sorry, packet capturing on a started VirtualBox VM is not supported.") + nio = adapter.get_nio(0) if nio.capturing: raise VirtualBoxError("Packet capture is already activated on adapter {adapter_number}".format(adapter_number=adapter_number))