sepolicy: support non-MLS policy in manpage

"sepolicy manpage" fails when the system does not use MLS because
using x.context.range_ raises an exception. Avoid using range and levels
when _pol.mls is False.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
This commit is contained in:
Nicolas Iooss 2017-08-05 18:37:48 +02:00 committed by Stephen Smalley
parent 07d06cc430
commit 908340e8e7
2 changed files with 17 additions and 4 deletions

View File

@ -207,6 +207,7 @@ def info(setype, name=None):
elif len(ports) == 1: elif len(ports) == 1:
q.ports = (ports[0], ports[0]) q.ports = (ports[0], ports[0])
if _pol.mls:
return ({ return ({
'high': x.ports.high, 'high': x.ports.high,
'protocol': str(x.protocol), 'protocol': str(x.protocol),
@ -214,18 +215,29 @@ def info(setype, name=None):
'type': str(x.context.type_), 'type': str(x.context.type_),
'low': x.ports.low, 'low': x.ports.low,
} for x in q.results()) } for x in q.results())
return ({
'high': x.ports.high,
'protocol': str(x.protocol),
'type': str(x.context.type_),
'low': x.ports.low,
} for x in q.results())
elif setype == USER: elif setype == USER:
q = setools.UserQuery(_pol) q = setools.UserQuery(_pol)
if name: if name:
q.name = name q.name = name
if _pol.mls:
return ({ return ({
'range': str(x.mls_range), 'range': str(x.mls_range),
'name': str(x), 'name': str(x),
'roles': list(map(str, x.roles)), 'roles': list(map(str, x.roles)),
'level': str(x.mls_level), 'level': str(x.mls_level),
} for x in q.results()) } for x in q.results())
return ({
'name': str(x),
'roles': list(map(str, x.roles)),
} for x in q.results())
elif setype == BOOLEAN: elif setype == BOOLEAN:
q = setools.BoolQuery(_pol) q = setools.BoolQuery(_pol)

View File

@ -84,6 +84,7 @@ def get_all_users_info():
for d in allusers_info: for d in allusers_info:
allusers.append(d['name']) allusers.append(d['name'])
if 'range' in d:
users_range[d['name'].split("_")[0]] = d['range'] users_range[d['name'].split("_")[0]] = d['range']
for u in allusers: for u in allusers: