當前位置: 首頁>>代碼示例>>Python>>正文


Python setools.PermissionMap類代碼示例

本文整理匯總了Python中setools.PermissionMap的典型用法代碼示例。如果您正苦於以下問題:Python PermissionMap類的具體用法?Python PermissionMap怎麽用?Python PermissionMap使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了PermissionMap類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_123_include_perm

    def test_123_include_perm(self):
        """PermMap include permission."""
        permmap = PermissionMap("tests/perm_map")
        permmap.exclude_permission("infoflow", "med_w")
        self.validate_permmap_entry(permmap.permmap, 'infoflow', 'med_w', 'w', 5, False)

        permmap.include_permission("infoflow", "med_w")
        self.validate_permmap_entry(permmap.permmap, 'infoflow', 'med_w', 'w', 5, True)
開發者ID:GitForNeo,項目名稱:setools,代碼行數:8,代碼來源:permmap.py

示例2: test_102_set_weight_low

    def test_102_set_weight_low(self):
        """PermMap set weight high"""
        permmap = PermissionMap("tests/perm_map")
        with self.assertRaises(ValueError):
            permmap.set_weight("infoflow2", "low_w", 11)

        with self.assertRaises(ValueError):
            permmap.set_weight("infoflow2", "low_w", 50)
開發者ID:GitForNeo,項目名稱:setools,代碼行數:8,代碼來源:permmap.py

示例3: test_132_include_class

    def test_132_include_class(self):
        """PermMap exclude class."""
        permmap = PermissionMap("tests/perm_map")
        permmap.exclude_class("file")
        self.validate_permmap_entry(permmap.permmap, 'file', 'execute', 'r', 10, False)
        self.validate_permmap_entry(permmap.permmap, 'file', 'entrypoint', 'r', 10, False)

        permmap.include_class("file")
        self.validate_permmap_entry(permmap.permmap, 'file', 'execute', 'r', 10, True)
        self.validate_permmap_entry(permmap.permmap, 'file', 'entrypoint', 'r', 10, True)
開發者ID:GitForNeo,項目名稱:setools,代碼行數:10,代碼來源:permmap.py

示例4: test_140_weight_read_only

    def test_140_weight_read_only(self):
        """PermMap get weight of read-only rule."""
        rule = Mock()
        rule.ruletype = "allow"
        rule.tclass = "infoflow"
        rule.perms = set(["med_r", "hi_r"])

        permmap = PermissionMap("tests/perm_map")
        r, w = permmap.rule_weight(rule)
        self.assertEqual(r, 10)
        self.assertEqual(w, 0)
開發者ID:GitForNeo,項目名稱:setools,代碼行數:11,代碼來源:permmap.py

示例5: test_141_weight_write_only

    def test_141_weight_write_only(self):
        """PermMap get weight of write-only rule."""
        rule = Mock()
        rule.ruletype = "allow"
        rule.tclass = "infoflow"
        rule.perms = set(["low_w", "med_w"])

        permmap = PermissionMap("tests/perm_map")
        r, w = permmap.rule_weight(rule)
        self.assertEqual(r, 0)
        self.assertEqual(w, 5)
開發者ID:GitForNeo,項目名稱:setools,代碼行數:11,代碼來源:permmap.py

示例6: test_142_weight_both

    def test_142_weight_both(self):
        """PermMap get weight of both rule."""
        rule = Mock()
        rule.ruletype = "allow"
        rule.tclass = "infoflow"
        rule.perms = set(["low_r", "hi_w"])

        permmap = PermissionMap("tests/perm_map")
        r, w = permmap.rule_weight(rule)
        self.assertEqual(r, 1)
        self.assertEqual(w, 10)
開發者ID:GitForNeo,項目名稱:setools,代碼行數:11,代碼來源:permmap.py

示例7: test_143_weight_none

    def test_143_weight_none(self):
        """PermMap get weight of none rule."""
        rule = Mock()
        rule.ruletype = "allow"
        rule.tclass = "infoflow3"
        rule.perms = set(["null"])

        permmap = PermissionMap("tests/perm_map")
        r, w = permmap.rule_weight(rule)
        self.assertEqual(r, 0)
        self.assertEqual(w, 0)
開發者ID:GitForNeo,項目名稱:setools,代碼行數:11,代碼來源:permmap.py

示例8: test_150_map_policy

    def test_150_map_policy(self):
        """PermMap create mappings for classes/perms in a policy."""
        policy = SELinuxPolicy("tests/permmap.conf")
        permmap = PermissionMap("tests/perm_map")
        permmap.map_policy(policy)

        self.validate_permmap_entry(permmap.permmap, 'infoflow2', 'new_perm', 'u', 1, True)

        self.assertIn("new_class", permmap.permmap)
        self.assertEqual(1, len(permmap.permmap['new_class']))
        self.validate_permmap_entry(permmap.permmap, 'new_class', 'new_class_perm', 'u', 1, True)
開發者ID:GitForNeo,項目名稱:setools,代碼行數:11,代碼來源:permmap.py

示例9: test_147_weight_excluded_permission

    def test_147_weight_excluded_permission(self):
        """PermMap get weight of a rule with excluded permission."""
        rule = Mock()
        rule.ruletype = TERuletype.allow
        rule.tclass = "infoflow"
        rule.perms = set(["med_r", "hi_r"])

        permmap = PermissionMap("tests/perm_map")
        permmap.exclude_permission("infoflow", "hi_r")
        r, w = permmap.rule_weight(rule)
        self.assertEqual(r, 5)
        self.assertEqual(w, 0)
開發者ID:TresysTechnology,項目名稱:setools,代碼行數:12,代碼來源:permmap.py

示例10: test_148_weight_excluded_class

    def test_148_weight_excluded_class(self):
        """PermMap get weight of a rule with excluded class."""
        rule = Mock()
        rule.ruletype = "allow"
        rule.tclass = "infoflow"
        rule.perms = set(["low_r", "med_r", "hi_r", "low_w", "med_w", "hi_w"])

        permmap = PermissionMap("tests/perm_map")
        permmap.exclude_class("infoflow")
        r, w = permmap.rule_weight(rule)
        self.assertEqual(r, 0)
        self.assertEqual(w, 0)
開發者ID:GitForNeo,項目名稱:setools,代碼行數:12,代碼來源:permmap.py

示例11: load_permmap

 def load_permmap(self, filename=None):
     try:
         self._permmap = PermissionMap(filename)
     except Exception as ex:
         self.log.critical("Failed to load default permission map: {0}".format(ex))
         self.error_msg.critical(self, "Permission map loading error", str(ex))
     else:
         if self._policy:
             self._permmap.map_policy(self._policy)
             self.apply_permmap()
開發者ID:TresysTechnology,項目名稱:setools,代碼行數:10,代碼來源:mainwindow.py

示例12: select_permmap

    def select_permmap(self):
        filename = QFileDialog.getOpenFileName(self, "Open permission map file", ".")[0]
        if filename:
            try:
                self._permmap = PermissionMap(filename)
            except Exception as ex:
                self.error_msg.critical(self, "Permission map loading error", str(ex))
            else:

                if self._policy:
                    self._permmap.map_policy(self._policy)
開發者ID:stevedlawrence,項目名稱:setools,代碼行數:11,代碼來源:mainwindow.py

示例13: __init__

    def __init__(self, filename):
        super(ApolMainWindow, self).__init__()
        self.log = logging.getLogger(__name__)

        if filename:
            self._policy = SELinuxPolicy(filename)
        else:
            self._policy = None

        try:
            # try to load default permission map
            self._permmap = PermissionMap()
        except (IOError, OSError) as ex:
            self.log.info("Failed to load default permission map: {0}".format(ex))
            self._permmap = None

        self.setupUi()
開發者ID:stevedlawrence,項目名稱:setools,代碼行數:17,代碼來源:mainwindow.py

示例14: ApolMainWindow

class ApolMainWindow(SEToolsWidget, QMainWindow):

    def __init__(self, filename):
        super(ApolMainWindow, self).__init__()
        self.log = logging.getLogger(__name__)

        if filename:
            self._policy = SELinuxPolicy(filename)
        else:
            self._policy = None

        try:
            # try to load default permission map
            self._permmap = PermissionMap()
        except (IOError, OSError) as ex:
            self.log.info("Failed to load default permission map: {0}".format(ex))
            self._permmap = None

        self.setupUi()

    def setupUi(self):
        self.load_ui("apol.ui")

        self.tab_counter = 0

        self.update_window_title()

        # set up error message dialog
        self.error_msg = QMessageBox(self)
        self.error_msg.setStandardButtons(QMessageBox.Ok)

        # set up tab name editor
        self.tab_editor = QLineEdit(self.AnalysisTabs)
        self.tab_editor.setWindowFlags(Qt.Popup)

        # configure tab bar context menu
        tabBar = self.AnalysisTabs.tabBar()
        tabBar.addAction(self.rename_tab_action)
        tabBar.addAction(self.close_tab_action)
        tabBar.setContextMenuPolicy(Qt.ActionsContextMenu)

        # capture INFO and higher Python messages from setools lib for status bar
        handler = LogHandlerToSignal()
        handler.message.connect(self.statusbar.showMessage)
        logging.getLogger("setools").addHandler(handler)
        logging.getLogger("setoolsgui").addHandler(handler)

        # connect signals
        self.open_policy.triggered.connect(self.select_policy)
        self.open_permmap.triggered.connect(self.select_permmap)
        self.new_analysis.triggered.connect(self.choose_analysis)
        self.AnalysisTabs.tabCloseRequested.connect(self.close_tab)
        self.AnalysisTabs.tabBarDoubleClicked.connect(self.tab_name_editor)
        self.tab_editor.editingFinished.connect(self.rename_tab)
        self.rename_tab_action.triggered.connect(self.rename_active_tab)
        self.close_tab_action.triggered.connect(self.close_active_tab)
        self.copy_action.triggered.connect(self.copy)
        self.cut_action.triggered.connect(self.cut)
        self.paste_action.triggered.connect(self.paste)

        self.show()

    def update_window_title(self):
        if self._policy:
            self.setWindowTitle("{0} - apol".format(self._policy))
        else:
            self.setWindowTitle("apol")

    def select_policy(self):
        filename = QFileDialog.getOpenFileName(self, "Open policy file", ".")[0]
        if filename:
            try:
                self._policy = SELinuxPolicy(filename)
            except Exception as ex:
                self.error_msg.critical(self, "Policy loading error", str(ex))
            else:
                self.update_window_title()

                if self._permmap:
                    self._permmap.map_policy(self._policy)

    def select_permmap(self):
        filename = QFileDialog.getOpenFileName(self, "Open permission map file", ".")[0]
        if filename:
            try:
                self._permmap = PermissionMap(filename)
            except Exception as ex:
                self.error_msg.critical(self, "Permission map loading error", str(ex))
            else:

                if self._policy:
                    self._permmap.map_policy(self._policy)

    def choose_analysis(self):
        if not self._policy:
            self.error_msg.critical(self, "No open policy",
                                    "Cannot start a new analysis. Please open a policy first.")

            self.select_policy()

#.........這裏部分代碼省略.........
開發者ID:stevedlawrence,項目名稱:setools,代碼行數:101,代碼來源:mainwindow.py

示例15: ApolMainWindow

class ApolMainWindow(SEToolsWidget, QMainWindow):

    def __init__(self, filename):
        super(ApolMainWindow, self).__init__()
        self.log = logging.getLogger(__name__)
        self._permmap = None
        self._policy = None
        self.setupUi()

        self.load_permmap()

        if filename:
            self.load_policy(filename)

        if self._policy:
            self.create_new_analysis("Summary", SummaryTab)

        self.update_window_title()

    def setupUi(self):
        self.load_ui("apol.ui")

        self.tab_counter = 0

        # set up analysis menu
        self.chooser = ChooseAnalysis(self)

        # set up error message dialog
        self.error_msg = QMessageBox(self)
        self.error_msg.setStandardButtons(QMessageBox.Ok)

        # set up permission map editor
        self.permmap_editor = PermissionMapEditor(self, True)

        # set up tab name editor
        self.tab_editor = QLineEdit(self.AnalysisTabs)
        self.tab_editor.setWindowFlags(Qt.Popup)

        # configure tab bar context menu
        tabBar = self.AnalysisTabs.tabBar()
        tabBar.addAction(self.rename_tab_action)
        tabBar.addAction(self.close_tab_action)
        tabBar.setContextMenuPolicy(Qt.ActionsContextMenu)

        # capture INFO and higher Python messages from setools lib for status bar
        handler = LogHandlerToSignal()
        handler.message.connect(self.statusbar.showMessage)
        logging.getLogger("setools").addHandler(handler)
        logging.getLogger("setoolsgui").addHandler(handler)

        # set up help browser process
        self.help_process = QProcess()

        # connect signals
        self.open_policy.triggered.connect(self.select_policy)
        self.close_policy_action.triggered.connect(self.close_policy)
        self.open_permmap.triggered.connect(self.select_permmap)
        self.new_analysis.triggered.connect(self.choose_analysis)
        self.AnalysisTabs.tabCloseRequested.connect(self.close_tab)
        self.AnalysisTabs.tabBarDoubleClicked.connect(self.tab_name_editor)
        self.tab_editor.editingFinished.connect(self.rename_tab)
        self.rename_tab_action.triggered.connect(self.rename_active_tab)
        self.close_tab_action.triggered.connect(self.close_active_tab)
        self.copy_action.triggered.connect(self.copy)
        self.cut_action.triggered.connect(self.cut)
        self.paste_action.triggered.connect(self.paste)
        self.edit_permmap_action.triggered.connect(self.edit_permmap)
        self.save_permmap_action.triggered.connect(self.save_permmap)
        self.about_apol_action.triggered.connect(self.about_apol)
        self.apol_help_action.triggered.connect(self.apol_help)

        self.show()

    def update_window_title(self):
        if self._policy:
            self.setWindowTitle("{0} - apol".format(self._policy))
        else:
            self.setWindowTitle("apol")

    #
    # Policy handling
    #
    def select_policy(self):
        old_policy = self._policy

        if old_policy and self.AnalysisTabs.count() > 0:
            reply = QMessageBox.question(
                self, "Continue?",
                "Loading a policy will close all existing analyses.  Continue?",
                QMessageBox.Yes | QMessageBox.No)

            if reply == QMessageBox.No:
                return

        filename = QFileDialog.getOpenFileName(self, "Open policy file", ".",
                                               "SELinux Policies (policy.* sepolicy);;"
                                               "All Files (*)")[0]
        if filename:
            self.load_policy(filename)

#.........這裏部分代碼省略.........
開發者ID:jakev,項目名稱:setools,代碼行數:101,代碼來源:mainwindow.py


注:本文中的setools.PermissionMap類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。