Skip to content

Commit 9bc150a

Browse files
committed
semanage, sepolicy: list also ports not attributed with port_type
For `semanage port -l` and `sepolicy network -t type`, show also ports which are not attributed with `port_type`. Such ports may exist in custom policies and even the attribute `port_type` may not be defined. This fixes the following error with `semanage port -l` (and similar error with `sepolicy network -t type`): Traceback (most recent call last): File "/usr/sbin/semanage", line 975, in <module> do_parser() File "/usr/sbin/semanage", line 947, in do_parser args.func(args) File "/usr/sbin/semanage", line 441, in handlePort OBJECT = object_dict['port'](args) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/seobject.py", line 1057, in __init__ self.valid_types = list(list(sepolicy.info(sepolicy.ATTRIBUTE, "port_type"))[0]["types"]) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^ IndexError: list index out of range Signed-off-by: Topi Miettinen <[email protected]> --- v5: fix from Petr Lautrbach v4: keep types found with attribute port_type for compatibility with types which are not portcons v3: use even better version, thanks to Petr Lautrbach v2: fix other cases and use better version courtesy of Petr Lautrbach
1 parent 820f019 commit 9bc150a

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

python/semanage/semanage-bash-completion.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ __get_all_types () {
3737
seinfo -t 2> /dev/null | tail -n +3
3838
}
3939
__get_all_port_types () {
40-
seinfo -aport_type -x 2>/dev/null | tail -n +2
40+
sepolicy network -l
4141
}
4242
__get_all_domains () {
4343
seinfo -adomain -x 2>/dev/null | tail -n +2

python/semanage/seobject.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ class portRecords(semanageRecords):
10551055
def __init__(self, args = None):
10561056
semanageRecords.__init__(self, args)
10571057
try:
1058-
self.valid_types = list(list(sepolicy.info(sepolicy.ATTRIBUTE, "port_type"))[0]["types"])
1058+
self.valid_types = [x["type"] for x in [*sepolicy.info(sepolicy.ATTRIBUTE, "port_type"), *sepolicy.info(sepolicy.PORT)]]
10591059
except RuntimeError:
10601060
pass
10611061

python/sepolicy/sepolicy-bash-completion.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ __get_all_classes () {
5252
seinfo -c 2> /dev/null | tail -n +2
5353
}
5454
__get_all_port_types () {
55-
seinfo -aport_type -x 2> /dev/null | tail -n +2
55+
sepolicy network -l
5656
}
5757
__get_all_domain_types () {
5858
seinfo -adomain -x 2> /dev/null | tail -n +2

python/sepolicy/sepolicy/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -989,8 +989,8 @@ def get_all_port_types():
989989
global port_types
990990
if port_types:
991991
return port_types
992-
port_types = list(sorted(info(ATTRIBUTE, "port_type"))[0]["types"])
993-
return port_types
992+
port_types = set(next(info(ATTRIBUTE, "port_type"))["types"] + [x["type"] for x in info(PORT)])
993+
return sorted(port_types)
994994

995995

996996
def get_all_bools():

0 commit comments

Comments
 (0)