示例#1
0
    def _checkUbridgePermissions(self):
        """
        Checks that uBridge can interact with network interfaces.
        """

        path = os.path.abspath(self._settings["ubridge_path"])

        if not path or len(path) == 0 or not os.path.exists(path):
            return False

        if sys.platform.startswith("win"):
            # do not check anything on Windows
            return True

        if os.geteuid() == 0:
            # we are root, so we should have privileged access.
            return True

        request_setuid = False
        if sys.platform.startswith("linux"):
            # test if the executable has the CAP_NET_RAW capability (Linux only)
            try:
                if "security.capability" in os.listxattr(path):
                    caps = os.getxattr(path, "security.capability")
                    # test the 2nd byte and check if the 13th bit (CAP_NET_RAW) is set
                    if not struct.unpack("<IIIII", caps)[1] & 1 << 13:
                        proceed = QtWidgets.QMessageBox.question(
                            self.parent(),
                            "uBridge",
                            "uBridge requires CAP_NET_RAW capability to interact with network interfaces. Set the capability to uBridge? All users on the system will be able to read packet from the network interfaces.",
                            QtWidgets.QMessageBox.Yes,
                            QtWidgets.QMessageBox.No)
                        if proceed == QtWidgets.QMessageBox.Yes:
                            sudo(["setcap", "cap_net_admin,cap_net_raw=ep"])
                else:
                    # capabilities not supported
                    request_setuid = True
            except AttributeError:
                # Due to a Python bug, os.listxattr could be missing: https://github.com/GNS3/gns3-gui/issues/2010
                log.warning("Could not determine if CAP_NET_RAW capability is set for uBridge (Python bug)")
                return True
            except OSError as e:
                QtWidgets.QMessageBox.critical(self.parent(), "uBridge", "Can't set CAP_NET_RAW capability to uBridge {}: {}".format(path, str(e)))
                return False

        if sys.platform.startswith("darwin") or request_setuid:
            try:
                if os.stat(path).st_uid != 0 or not os.stat(path).st_mode & stat.S_ISUID:
                    proceed = QtWidgets.QMessageBox.question(
                        self.parent(),
                        "uBridge",
                        "uBridge requires root permissions to interact with network interfaces. Set root permissions to uBridge?  All admin users on the system will be able to read packet from the network interfaces.",
                        QtWidgets.QMessageBox.Yes,
                        QtWidgets.QMessageBox.No)
                    if proceed == QtWidgets.QMessageBox.Yes:
                        sudo(["chown", "root:admin", path], ["chmod", "4750", path])
            except OSError as e:
                QtWidgets.QMessageBox.critical(self.parent(), "uBridge", "Can't set root permissions to uBridge {}: {}".format(path, str(e)))
                return False
        return True
    def _resetVmnetSlot(self):
        """
        Deletes all vmnet interface but vmnet1 and vmnet8
        """

        gns3vmnet = self._getGNS3Vmnet()
        if gns3vmnet is None:
            return
        command = [gns3vmnet, "-C"]
        sudo(command, parent=self)
    def _resetVmnetSlot(self):
        """
        Deletes all vmnet interface but vmnet1 and vmnet8
        """

        gns3vmnet = self._getGNS3Vmnet()
        if gns3vmnet is None:
            return
        command = [gns3vmnet, "-C"]
        sudo(command, parent=self)
    def _configureVmnetSlot(self):
        """
        Configure the vmnet interfaces.
        """

        vmnet_start = str(self.uiVMnetStartRangeSpinBox.value())
        vmnet_end = str(self.uiVMnetEndRangeSpinBox.value())
        gns3vmnet = self._getGNS3Vmnet()
        if gns3vmnet is None:
            return
        command = [gns3vmnet, "-r", vmnet_start, vmnet_end]
        sudo(command, parent=self)
    def _configureVmnetSlot(self):
        """
        Configure the vmnet interfaces.
        """

        vmnet_start = str(self.uiVMnetStartRangeSpinBox.value())
        vmnet_end = str(self.uiVMnetEndRangeSpinBox.value())
        gns3vmnet = self._getGNS3Vmnet()
        if gns3vmnet is None:
            return
        command = [gns3vmnet, "-r", vmnet_start, vmnet_end]
        sudo(command, parent=self)