Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

semanage: list all ports even if not attributed with port_type #394

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

topimiettinen
Copy link
Contributor

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:

Traceback (most recent call last):
File "/usr/sbin/semanage", line 975, in
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'
^^^^^^^^^^^^^^^^^^^^^^^^^
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

@topimiettinen
Copy link
Contributor Author

An analogous problem exists with nodes, which don't have the attribute node_type, but there the fix would be more complex.

@bachradsusi
Copy link
Member

Hello, thanks for the patch!

In order to get the patch reviewed and accepted, it's necessary to send it to [email protected] mailing list. The best way is to use git send-email command, e.g.:

git send-email --from='Your Name <[email protected]>' [email protected] --smtp-server=my.smtp.server --confirm=auto -1

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants