1 Star 0 Fork 0

robertosassu/ra-verifier

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
util.py 3.24 KB
一键复制 编辑 原始数据 按行查看 历史
robertosassu 提交于 2021-04-06 10:19 . Migrate to python 3
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# util.py: some useful functions
#
# Copyright (C) 2014 Politecnico di Torino, Italy
# TORSEC group -- http://security.polito.it
#
# Author: Roberto Sassu <roberto.sassu@polito.it>
# Tao Su <tao.su@polito.it>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see
# <http://www.gnu.org/licenses/>.
from collections import deque
def merge_dict(dest_dict, source_dict):
try:
keys = list(source_dict.keys())
childdictkeys = list(source_dict[keys[0]].keys())
for key in keys:
try:
merge_dict(dest_dict[key], source_dict[key])
except:
dest_dict[key] = source_dict[key]
except:
dest_dict.update(source_dict)
def propagation_rule(status, propagation):
propagation_map = {}
propagation_map['ok'] = 0
propagation_map['newpackage'] = 0
propagation_map['testing'] = 0
propagation_map['release'] = 0
propagation_map['name-mismatch'] = 1
propagation_map['enhancement'] = 2
propagation_map['bugfix'] = 3
propagation_map['security'] = 4
propagation_map['unknown'] = 4
propagation_map['not-found'] = 10
propagation_map['fake-lib'] = 10
propagation_map['undefined'] = -1
propagation_map['error'] = -1
return propagation_map[status] < propagation_map[propagation]
def edge_list_tags(graph, source, target):
try:
return [tag[9:] for tag in graph[source][target] \
if tag.startswith('edge_tag_')]
except:
return []
def edge_match_tags(graph, source, target, tags, excluded_tags):
return tags is None or \
len(set(edge_list_tags(graph, source, target)) & set(tags)) > 0 and \
len(set(edge_list_tags(graph, source, target)) & set(excluded_tags)) == 0
def bfs(g, source, edge_list = None, prop_set = False, only_prop_true = False, excluded_edge_list = []):
queue = deque([(None, source)])
while queue:
parent, n = queue.popleft()
yield parent, n
new = set(g[n])
queue.extend([(n, child) for child in new
if edge_match_tags(g, n, child, edge_list, excluded_edge_list) and (not prop_set or \
('propagation' in g[n][child] and (not only_prop_true or \
g[n][child]['propagation'] == True)))])
def selinux_context(label):
label_split = label.split(':')
return ':'.join(label_split[:-1])
def selinux_type(label):
label_split = label.split(':')
if len(label_split) >= 4:
return label_split[2]
return label_split[0]
def selinux_class(label):
label_split = label.split(':')
return label_split[-1]
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/robertosassu/ra-verifier.git
git@gitee.com:robertosassu/ra-verifier.git
robertosassu
ra-verifier
ra-verifier
master

搜索帮助