Commit graph

88 commits

Author SHA1 Message Date
Nicolas Iooss
b8296872fe python/sepolicy: Fix translated strings with parameters
When a translated string takes parameters with %, the % and the
parameters need to be after the call to the underline function in order
to work properly.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2018-02-23 15:23:47 -05:00
Petr Lautrbach
41f1882724 python/sepolicy: Do not use types.BooleanType
It was removed from Python 3

Fixes:
File "polgengui.py", line 390, in forward
  self.generate_policy()
File "polgengui.py", line 491, in generate_policy
  my_policy.set_use_syslog(self.syslog_checkbutton.get_active() == 1)
File "/home/plautrba/devel/github/bachradsusi/SELinuxProject-selinux/python/sepolicy/sepolicy/generate.py",  line 468, in set_use_syslog
  if not isinstance(val, types.BooleanType):
AttributeError: module 'types' has no attribute 'BooleanType'

Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2018-02-23 15:23:47 -05:00
Petr Lautrbach
7281132977 python/sepolicy: Use list instead of map
map() returns an iterator in python3, list in python2

Fixes:
File "/usr/lib/python3.6/site-packages/sepolicy/generate.py", line 114, in get_all_users
  users.remove("system_u")
AttributeError: 'map' object has no attribute 'remove'

Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2018-02-23 15:23:47 -05:00
Marcus Folkesson
88a6216ddb python: build: move modules from platform-specific to platform-shared
Signed-off-by: Marcus Folkesson <marcus.folkesson@gmail.com>
2018-02-14 20:02:02 +01:00
Marcus Folkesson
11aaf180ef python: build: follow standard semantics for DESTDIR and PREFIX
Signed-off-by: Marcus Folkesson <marcus.folkesson@gmail.com>
2018-02-14 20:02:01 +01:00
Vit Mojzis
2f26c1db5d python/semanage: Remove redundant and broken moduleRecords.modify()
moduleRecords.modify() calls nonexistent function
semanage_module_update_file (maybe it should have been
semanage_module_upgrade_file which is now obsolete and calls
semanage_module_install_file) and the job of updating a module is done
by moduleRecords.add().

Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
2018-01-16 09:23:40 -05:00
Petr Lautrbach
653b393f42 python/semanage: bring semanageRecords.set_reload back
It's used by third parties, e.g. Ansible modules

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1527745

Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2018-01-16 09:07:05 -05:00
Petr Lautrbach
5e81672ca0 python/semanage: make seobject.py backward compatible
Commit 985753f changed behavior of seobject class constructors. While
semanage itself was fixed, there are other tools like
system-config-selinux and chcat which depend on the original behavior.
This change make the constructors backward compatible.

Fixes: $ system-config-selinux
Traceback (most recent call last):
  File "/usr/share/system-config-selinux/system-config-selinux.py", line 196, in <module>
    app = childWindow()
  File "/usr/share/system-config-selinux/system-config-selinux.py", line 100, in __init__
    self.add_page(booleansPage.booleansPage(xml))
  File "/usr/share/system-config-selinux/booleansPage.py", line 142, in __init__
    self.load(self.filter)
  File "/usr/share/system-config-selinux/booleansPage.py", line 212, in load
    self.booleans = seobject.booleanRecords()
TypeError: __init__() missing 1 required positional argument: 'args'

Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2017-12-18 15:46:53 -05:00
Lukas Vrabec
5c48d93271 python/sepolicy: Fix sepolicy manpage.
Arguments generate and gui was mixed together and information didn't make sense. This fix split gui and generate sections.

Signed-off-by: Lukas Vrabec <lvrabec@redhat.com>
2017-11-22 09:47:50 +01:00
Vit Mojzis
2d21207796 python/semanage: Update Infiniband code to work on python3
Update Infiniband "port" and "key" listing and export to work on
python3.
{}.keys() does not support .sort() operation on Py3.

Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
2017-11-14 09:15:00 +01:00
Vit Mojzis
2927532b1c python/semanage: Fix export of ibendport entries
Replace nonexistent switch "-x" by "-z" (entry name).
Fix invalid index (the dictionary key is a 2-tuple).
Add MLS/MCS range (present in all entries).

Fixes:
 #semanage ibendport -E
  File "/usr/sbin/semanage", line 1049, in <module>
    do_parser()
  File "/usr/sbin/semanage", line 1028, in do_parser
    args.func(args)
  File "/usr/sbin/semanage", line 605, in handleIbendport
    for i in OBJECT.customized():
  File "/usr/lib64/python2.7/site-packages/seobject/__init__.py", line 1806, in customized
    l.append("-a -t %s -x %s %s" % (ddict[k][0], k[2], k[0]))
  IndexError: tuple index out of range

Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
2017-11-14 09:14:27 +01:00
Petr Lautrbach
ebbf42d408 python/semanage: Enforce noreload only if it's requested by -N option
We want to call semanage_set_reload() only if -N option is used.

Fixes:

$ sudo umount /sys/fs/selinux

$ sudo semanage fcontext -a --type=postfix_local_tmp_t /var/opt/01789667
SELinux:  Could not downgrade policy file /etc/selinux/targeted/policy/policy.31, searching for an older version.
SELinux:  Could not open policy file <= /etc/selinux/targeted/policy/policy.31:  No such file or directory
/sbin/load_policy:  Can't load policy:  No such file or directory
libsemanage.semanage_reload_policy: load_policy returned error code 2. (No such file or directory).
SELinux:  Could not downgrade policy file /etc/selinux/targeted/policy/policy.31, searching for an older version.
SELinux:  Could not open policy file <= /etc/selinux/targeted/policy/policy.31:  No such file or directory
/sbin/load_policy:  Can't load policy:  No such file or directory
libsemanage.semanage_reload_policy: load_policy returned error code 2. (No such file or directory).
FileNotFoundError: [Errno 2] No such file or directory

Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2017-11-08 14:56:20 +08:00
Petr Lautrbach
985753f11b python/semanage: Don't use global setup variable
In order to do that we need to propagate args into seobject objects and
use args.store to get a store name.

Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2017-11-08 14:56:20 +08:00
Petr Lautrbach
d05eaaf098 python/semanage: drop *_ini functions
Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2017-11-08 14:56:20 +08:00
Vit Mojzis
393bafd3c5 python/semanage: Enable listing file_contexts.homedirs
Include entries from file_contexts.homedirs when listing file contexts
via "semanage fcontext -l"

"semanage fcontext -l" so far ignored content of file_contexts.homedirs
file, which is confusing for users (more specific rules may be ignored in
favor of rules unseen to the user since file_contexts.homedirs has
higher priority than file_contexts).

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1409813

Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
2017-10-04 14:18:58 -04:00
Nicolas Iooss
305aacbc4b sepolicy: support non-MLS policy in gui
Several "sepolic gui" tabs raise exceptions when using a policy without
MLS because some dictionaries describing users and logins lack level and
range properties. Use conditions and get() where appropriate in order
to make "sepolicy gui" usable again with a non-MLS policy.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-09-25 12:59:29 -04:00
Nicolas Iooss
175efbf3ae sepolicy: ignore comments and empty lines in file_contexts.subs_dist
In refpolicy, file_contexts.subs_dist begins with comments:

    # This file can is used to configure base path aliases as in:
    #
    # /aliased_path /original_path_as_configured_in_file_contexts
    #

The first line gets parsed in read_file_equiv even though it is not a
valid path substitution and the second line triggers an exception when
accessing f[1]:

    IndexError: list index out of range

Parse substitutions only for lines which are not comment.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-09-25 12:58:16 -04:00
Nicolas Iooss
8f0ea463bc sepolicy: do not fail when file_contexts.local or .subs do not exist
On a system without any file context customizations, "sepolicy gui"
fails to load because it tries to read a non-existing file:

    FileNotFoundError: [Errno 2] No such file or directory:
    '/etc/selinux/refpolicy-git/contexts/files/file_contexts.local'

Once this issue is fixed, another one is triggered:

    FileNotFoundError: [Errno 2] No such file or directory:
    '/etc/selinux/refpolicy-git/contexts/files/file_contexts.subs

Use try/except to catch these exceptions and use OSError/errno.ENOENT to
keep the code compatible with Python 2.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-09-21 16:15:54 -04:00
Nicolas Iooss
bd75c5695c sepolicy: remove stray space in section "SEE ALSO"
The space after "sepolicy(8)" breaks the formatting of section SEE ALSO
in man pages generated with sepolicy:

  SEE ALSO
    selinux(8), ssh(8), semanage(8), restorecon(8), chcon(1), sepolicy(8)  ,  setsebool(8),

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-08-07 10:44:23 -04:00
Nicolas Iooss
9f8e539419 sepolicy: support non-MCS policy in manpage
This prevents the following exception to occur when using "sepolicy
manpage":

    Traceback (most recent call last):
      File "/bin/sepolicy", line 699, in <module>
        args.func(args)
      File "/bin/sepolicy", line 359, in manpage
        m = ManPage(domain, path, args.root, args.source_files, args.web)
      File "/usr/lib/python3.6/site-packages/sepolicy/manpage.py", line 459, in __init__
        self.__gen_man_page()
      File "/usr/lib/python3.6/site-packages/sepolicy/manpage.py", line 548, in __gen_man_page
        self._mcs_types()
      File "/usr/lib/python3.6/site-packages/sepolicy/manpage.py", line 978, in _mcs_types
        mcs_constrained_type = next(sepolicy.info(sepolicy.ATTRIBUTE, "mcs_constrained_type"))
    StopIteration

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-08-07 10:44:23 -04:00
Nicolas Iooss
908340e8e7 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>
2017-08-07 10:44:23 -04:00
Nicolas Iooss
07d06cc430 sepolicy: fix misspelling of _ra_content_t suffix
When "sepolicy manpage" generates descriptions for file type, it uses a
mispelled _ra_content_t suffix for prettyprinting, which results in an
unwanted double-space on the line.

For example sepolicy manpage -d httpd_t produces:

    .EX
    .P
    .B httpd_apcupsd_cgi_ra_content_t
    .EE

    - Set files with the httpd_apcupsd_cgi_ra_content_t type, if you
    want to treat the files as httpd apcupsd cgi  read/append content.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-08-07 10:44:23 -04:00
Nicolas Iooss
d329bb5465 sepolicy: do not fail when file_contexts.local does not exist
When running "sepolicy manpage" on a system without file_contexts.local,
the command fails with:

    FileNotFoundError: [Errno 2] No such file or directory:
    '//etc/selinux/refpolicy/contexts/files/file_contexts.local'

Verify that the file exists before using it.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-08-07 10:44:23 -04:00
Nicolas Iooss
3edb139789 sepolicy: fix Python3 syntax in manpage
Commit c624c4abaa ("sepolicy: Fix syntax errors in 'manpage -w'")
missed an occurence of print statement. While at it, fix self.os_version
test.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-08-07 10:44:23 -04:00
Stephen Smalley
1bac758bf6 Update VERSION files for 2.7 release.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2017-08-04 09:31:00 -04:00
Stephen Smalley
dfda6a5b2c Update VERSION files for 2.7-rc6
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2017-07-28 15:43:47 -04:00
Petr Lautrbach
f80ea84698 sepolicy: File labels used to be sorted in a man page
Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2017-07-27 09:49:32 -04:00
Petr Lautrbach
960b943b2f sepolicy: Make manpage and transition faster
SETools4 and Python 3 versions of map() and filter() uses iterators to
generates query results and these iterators can't be imply re-used. It
makes manpage and transitions operations really slow as they do lot of queries.

This patch changes it in the way that it caches results in lists for all
types, allow rules and transitions first and use cached results to
filter them using Python's filter() function.

Before:
$ time sepolicy manpage -d httpd_t sshd_t init_t
real    0m53.486s
user    0m53.171s
sys     0m0.054s

After:
$ time sepolicy manpage -d httpd_t sshd_t init_t
real    0m10.532s
user    0m10.368s
sys     0m0.114s

Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2017-07-27 09:49:32 -04:00
Petr Lautrbach
c624c4abaa sepolicy: Fix syntax errors in 'manpage -w'
Fixes:
  File "python/sepolicy/sepolicy/manpage.py", line 373, in _gen_css
    print("%s has been created") % style_css
TypeError: unsupported operand type(s) for %: 'NoneType' and 'str'

Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2017-07-27 09:49:32 -04:00
Petr Lautrbach
dabb4c06ca sepolicy: Fix minor typo in 'transition -s' test
Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2017-07-27 09:49:32 -04:00
Stephen Smalley
9f1730fa39 Update VERSION files for 2.7-rc5
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2017-07-18 12:01:26 -04:00
Stephen Smalley
83fbc0979d Update VERSION files for 2.7-rc4 release.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2017-06-30 13:41:33 -04:00
Laurent Bigonville
57ac60769c Fix consistency of PYTHONLIBDIR variable across modules
PYTHONLIBDIR is currently also used in sepolgen but has a different
behaviour regarding DESTDIR. Let's try to make this consistant.

Signed-off-by: Laurent Bigonville <bigon@bigon.be>
2017-06-30 12:54:43 -04:00
Stephen Smalley
6fab7923ce Update VERSION files for 2.7-rc3 release.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2017-06-23 13:01:45 -04:00
Nicolas Iooss
f027db4f2f python/sepolicy: remove definition of SYSCONFDIR
This variable is not used in any Makefile in python/.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-06-21 10:31:36 -04:00
Stephen Smalley
7b5699bfd7 Fix BINDIR/SBINDIR/... variables in Makefiles
As reported by Nicolas Iooss, there are still some inconsistencies
in the definitions and usage of Makefile variables related to bin
and sbin directories. Since we need to still support non-usrmerge
systems, we cannot completely synchronize them, but we can eliminate
unnecessary differences, remove unused variables, and drop the
USRSBINDIR variables.

Before:
$ find . -name Makefile -exec cat {} + |grep '^[A-Z_]*BINDIR' |sort -u
BINDIR=$(PREFIX)/bin
BINDIR ?= $(PREFIX)/bin
BINDIR ?= $(PREFIX)/sbin
SBINDIR ?= $(DESTDIR)/sbin
SBINDIR ?= $(PREFIX)/sbin
USRSBINDIR ?= $(PREFIX)/sbin

After:
$ find . -name Makefile -exec cat {} + | grep '^[A-Z_]*BINDIR' | sort -u
BINDIR ?= $(PREFIX)/bin
SBINDIR ?= $(DESTDIR)/sbin
SBINDIR ?= $(PREFIX)/sbin

This does not change the actual install location of any file.
It does drop the legacy symlink from /usr/sbin/load_policy to
/sbin/load_policy; packagers can create that separately if
desired.

Reported-by: Nicolas Iooss <nicolas.iooss@m4x.org>
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2017-06-20 12:18:26 -04:00
Stephen Smalley
08d4b030ea Update VERSION files for 2.7-rc2 release.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2017-06-16 12:50:03 -04:00
Stephen Smalley
2f602f6cb9 Update VERSION files for 2.7-rc1 release.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2017-06-09 10:36:06 -04:00
Petr Lautrbach
641d4ff55b sepolicy: Fix sorting of port_strings in python 3
Fixes:
$ sepolicy network -d httpd_t

httpd_t: tcp name_connect
Traceback (most recent call last):
  File /usr/bin/sepolicy, line 699, in <module>
    args.func(args)
  File /usr/bin/sepolicy, line 319, in network
    _print_net(d, tcp, name_connect)
  File /usr/bin/sepolicy, line 276, in _print_net
    port_strings.sort(numcmp)
TypeError: must use keyword argument for key function

Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2017-06-02 16:14:45 -04:00
Petr Lautrbach
acc43466f5 sepolicy/interface: Use relative python 3 imports
Fixes:
Verify sepolicy interface -c -i works ... Traceback (most recent call last):
  File "/usr/bin/sepolicy", line 699, in <module>
    args.func(args)
  File "/usr/bin/sepolicy", line 508, in interface
    print_interfaces(args.interfaces, args)
  File "/usr/bin/sepolicy", line 492, in print_interfaces
    interface_compile_test(i)
  File "/usr/lib/python3.6/site-packages/sepolicy/interface.py", line 226, in interface_compile_test
    fd.write(generate_compile_te(interface, idict))
  File "/usr/lib/python3.6/site-packages/sepolicy/interface.py", line 184, in generate_compile_te
    from templates import test_module
ModuleNotFoundError: No module named 'templates'

Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2017-06-02 16:14:45 -04:00
Daniel Jurgens
a2fe18614b semanage: Fix manpage author for ibpkey and ibendport pages.
Signed-off-by: Daniel Jurgens <danielj@mellanox.com>
2017-05-30 09:40:33 -04:00
Stephen Smalley
5219dec6fe python/semanage: print is a function in python3
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2017-05-26 10:33:57 -04:00
Petr Lautrbach
5b61d8fba8 Fix recently introduced TabError's
Commits a3d2c7a 6a7a5aa introduced inconsistent use of tabs and spaces
in indentation what makes python3.6 unhappy.

Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2017-05-26 10:19:10 -04:00
Daniel Jurgens
b217ffd77e semanage: Update man pages for infiniband
Update the main man page and add specific pages for ibpkeys and
ibendports.

Signed-off-by: Daniel Jurgens <danielj@mellanox.com>
2017-05-23 16:20:55 -04:00
Daniel Jurgens
9a3d2c7a9b semanage: Update semanage to allow runtime labeling of ibendports
Update libsepol and libsemanage to work with ibendport records. Add local
storage for new and modified ibendport records in ibendports.local.
Update semanage to parse the ibendport command options to add, modify,
and delete them.

Signed-off-by: Daniel Jurgens <danielj@mellanox.com>
2017-05-23 16:20:55 -04:00
Daniel Jurgens
6a7a5aafe5 semanage: Update semanage to allow runtime labeling of Infiniband Pkeys
Update libsepol and libsemanage to work with pkey records. Add local
storage for new and modified pkey records in pkeys.local. Update semanage
to parse the pkey command options to add, modify, and delete pkeys.

Signed-off-by: Daniel Jurgens <danielj@mellanox.com>
2017-05-23 16:20:55 -04:00
Petr Lautrbach
a9b6ef426d sepolicy/gui: Update text strings to use better gettext templates
Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2017-05-05 11:52:19 -04:00
Petr Lautrbach
11e9676ce1 sepolicy: info() should provide attributes for a TYPE
"attributes" used to be there when sepolicy.info() used setools3

Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2017-05-05 11:52:19 -04:00
Petr Lautrbach
89399a9c8e sepolicy: Fix several issues in 'sepolicy manpage -a'
Fixes:
$ sepolicy manpage -a
Traceback (most recent call last):
  File "/usr/bin/sepolicy", line 699, in <module>
    args.func(args)
  File "/usr/bin/sepolicy", line 359, in manpage
    m = ManPage(domain, path, args.root, args.source_files, args.web)
  File "/usr/lib/python3.6/site-packages/sepolicy/manpage.py", line 408, in __init__
    self.__gen_man_page()
  File "/usr/lib/python3.6/site-packages/sepolicy/manpage.py", line 495, in __gen_man_page
    self._entrypoints()
  File "/usr/lib/python3.6/site-packages/sepolicy/manpage.py", line 903, in _entrypoints
    if len(entrypoints) > 1:
TypeError: object of type 'map' has no len()

$ sepolicy manpage -a
Traceback (most recent call last):
  File "/usr/bin/sepolicy", line 699, in <module>
    args.func(args)
  File "/usr/bin/sepolicy", line 359, in manpage
    m = ManPage(domain, path, args.root, args.source_files, args.web)
  File "/usr/lib/python3.6/site-packages/sepolicy/manpage.py", line 408, in __init__
    self.__gen_man_page()
  File "/usr/lib/python3.6/site-packages/sepolicy/manpage.py", line 497, in __gen_man_page
    self._mcs_types()
  File "/usr/lib/python3.6/site-packages/sepolicy/manpage.py", line 927, in _mcs_types
    attributes = sepolicy.info(sepolicy.TYPE, (self.type))[0]["attributes"]
TypeError: 'generator' object is not subscriptable

Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2017-05-05 11:52:19 -04:00
Petr Lautrbach
471e6b0fc9 sepolicy: setools.*Query wants a list in ruletype
This fixes a problem introduced in 18410c86 where ruletype is specified
as a string not a list.

Fixes:
>>> sepolicy.get_all_role_allows()
Traceback (most recent call last):
  File "/usr/lib64/python3.6/site-packages/setools/policyrep/util.py", line 60, in lookup
    return cls(value)
  File "/usr/lib64/python3.6/enum.py", line 291, in __call__
    return cls.__new__(cls, value)
  File "/usr/lib64/python3.6/enum.py", line 533, in __new__
    return cls._missing_(value)
  File "/usr/lib64/python3.6/enum.py", line 546, in _missing_
    raise ValueError("%r is not a valid %s" % (value, cls.__name__))
ValueError: 'a' is not a valid RBACRuletype

Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2017-05-05 11:52:19 -04:00