From: Topi Miettinen <toiwoton@gmail.com>
To: selinux@vger.kernel.org
Cc: Topi Miettinen <toiwoton@gmail.com>
Subject: [PATCH v3] semanage, sepolicy: list also ports not attributed with port_type
Date: Tue, 13 Jun 2023 21:07:57 +0300 [thread overview]
Message-ID: <20230613180756.12978-1-toiwoton@gmail.com> (raw)
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 <toiwoton@gmail.com>
---
v3: use even better version, thanks to Petr Lautrbach
v2: fix other cases and use better version courtesy of Petr Lautrbach
---
python/semanage/semanage-bash-completion.sh | 2 +-
python/semanage/seobject.py | 2 +-
python/sepolicy/sepolicy-bash-completion.sh | 2 +-
python/sepolicy/sepolicy/__init__.py | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/python/semanage/semanage-bash-completion.sh b/python/semanage/semanage-bash-completion.sh
index d0dd139f..1e3f6f9d 100644
--- a/python/semanage/semanage-bash-completion.sh
+++ b/python/semanage/semanage-bash-completion.sh
@@ -37,7 +37,7 @@ __get_all_types () {
seinfo -t 2> /dev/null | tail -n +3
}
__get_all_port_types () {
- seinfo -aport_type -x 2>/dev/null | tail -n +2
+ sepolicy network -l
}
__get_all_domains () {
seinfo -adomain -x 2>/dev/null | tail -n +2
diff --git a/python/semanage/seobject.py b/python/semanage/seobject.py
index d82da494..323aae3f 100644
--- a/python/semanage/seobject.py
+++ b/python/semanage/seobject.py
@@ -1055,7 +1055,7 @@ class portRecords(semanageRecords):
def __init__(self, args = None):
semanageRecords.__init__(self, args)
try:
- self.valid_types = list(list(sepolicy.info(sepolicy.ATTRIBUTE, "port_type"))[0]["types"])
+ self.valid_types = [x["type"] for x in sepolicy.info(sepolicy.PORT)]
except RuntimeError:
pass
diff --git a/python/sepolicy/sepolicy-bash-completion.sh b/python/sepolicy/sepolicy-bash-completion.sh
index 13638e4d..467333b8 100644
--- a/python/sepolicy/sepolicy-bash-completion.sh
+++ b/python/sepolicy/sepolicy-bash-completion.sh
@@ -52,7 +52,7 @@ __get_all_classes () {
seinfo -c 2> /dev/null | tail -n +2
}
__get_all_port_types () {
- seinfo -aport_type -x 2> /dev/null | tail -n +2
+ sepolicy network -l
}
__get_all_domain_types () {
seinfo -adomain -x 2> /dev/null | tail -n +2
diff --git a/python/sepolicy/sepolicy/__init__.py b/python/sepolicy/sepolicy/__init__.py
index c177cdfc..9d3b640b 100644
--- a/python/sepolicy/sepolicy/__init__.py
+++ b/python/sepolicy/sepolicy/__init__.py
@@ -989,7 +989,7 @@ def get_all_port_types():
global port_types
if port_types:
return port_types
- port_types = list(sorted(info(ATTRIBUTE, "port_type"))[0]["types"])
+ port_types = [x["type"] for x in info(PORT)]
return port_types
--
2.39.2
next reply other threads:[~2023-06-13 18:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-13 18:07 Topi Miettinen [this message]
2023-06-14 10:03 ` [PATCH v3] semanage, sepolicy: list also ports not attributed with port_type Petr Lautrbach
2023-06-14 17:09 ` Topi Miettinen
2023-06-16 6:08 ` Petr Lautrbach
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230613180756.12978-1-toiwoton@gmail.com \
--to=toiwoton@gmail.com \
--cc=selinux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox