Commit graph

38 commits

Author SHA1 Message Date
Vit Mojzis
671f83b42b policycoreutils/sepolicy: Check get_rpm_nvr_list() return value
get_rpm_nvr_list can fail to get the version of selinux-policy rpm
package, which leads to error during spec file creation (attempt to
invoke __getitem__ of "None" object).

This patch sets the policy number to "0.0.0" in case rpm failed to
get it. This change should be safe because it affects only an example
of spec file.

Variable "POLICYCOREUTILSVER" was removed (unused).

fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1321499

Failed to retrieve rpm info for selinux-policy
Traceback (most recent call last):
  File "/bin/selinux-polgengui", line 360, in forward
    self.generate_policy()
  File "/bin/selinux-polgengui", line 506, in generate_policy
    self.info(my_policy.generate(outputdir))
  File "/usr/lib64/python2.7/site-packages/sepolicy/generate.py", line 1382, in generate
    out += "%s # %s\n" % (self.write_spec(out_dir), _("Spec file"))
  File "/usr/lib64/python2.7/site-packages/sepolicy/generate.py", line 1228, in write_spec
    fd.write(self.generate_spec())
  File "/usr/lib64/python2.7/site-packages/sepolicy/generate.py", line 1190, in generate_spec
    selinux_policyver = get_rpm_nvr_list("selinux-policy")[1]
  TypeError: 'NoneType' object has no attribute '__getitem__'

Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
2016-08-09 15:55:08 -04:00
James Carter
b190e6e37d sepolicy: Add python3 support to test_sepolicy.py
Use assertNotEqual() and assertEqual() instead of assert_().
Convert print statements to print functions.

Signed-off-by: James Carter <jwcart2@tycho.nsa.gov>
2016-08-08 15:50:18 -04:00
Jason Zaman
af59544e5f policycoreutils: gettext compat for py2 and 3
Install gettext the same way everywhere and have fallbacks to use
str/unicode depending on python version.

Signed-off-by: James Carter <jwcart2@tycho.nsa.gov>
2016-08-05 12:57:08 -04:00
Jason Zaman
7f956419c2 sepolicy: dont alias sepolicy.search and sepolicy.info
Signed-off-by: James Carter <jwcart2@tycho.nsa.gov>
2016-08-05 12:57:08 -04:00
Jason Zaman
f300803045 sepolicy: update exceptions and print for python3
Signed-off-by: James Carter <jwcart2@tycho.nsa.gov>
2016-08-05 12:57:08 -04:00
Jason Zaman
b87db86f79 sepolicy: C Module init for python3
Signed-off-by: James Carter <jwcart2@tycho.nsa.gov>
2016-08-05 12:57:08 -04:00
Jason Zaman
356a6e2566 sepolicy: Add python3 PyInt and PyString defs
Signed-off-by: James Carter <jwcart2@tycho.nsa.gov>
2016-08-05 12:57:08 -04:00
Nicolas Iooss
061c4fcbd4 policycoreutils: sepolicy: do not overwrite CFLAGS
sepolicy Makefile overwrites CFLAGS value, which prevents compiling its
Python module with custom compilation flags.  Modify it to append flags
to CFLAGS instead, like other policycoreutils programs do.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2016-02-11 08:42:45 -05:00
Nicolas Iooss
168f653d28 policycoreutils: sepolicy: rename policy global variable
Variable policy is both a global variable and a parameter to some
functions in policycoreutils/sepolicy/search.c.  This makes the building
fail when using -Wshadow -Werror compilation flags.

Fix this by renaming the global variable global_policy.  This does not
change the API of the Python module.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2016-02-11 08:36:27 -05:00
Ville Skyttä
572fcef2ba libselinux, policycoreutils: Man page warning fixes
Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
2015-11-24 16:32:13 -05:00
Petr Lautrbach
8922ff887f policycoreutils: improve sepolicy command line interface
Previously, when sepolicy was run without any argument, the usage message
with the error "too few arguments" was shown. Using Python 3 it threw a traceback.
This patch unifies behavior on Py2 and Py3 so that sepolicy shows the help
message in this case.

Fixes:
Traceback (most recent call last):
  File "/usr/bin/sepolicy", line 647, in <module>
    args.func(args)
AttributeError: 'Namespace' object has no attribute 'func'

Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2015-11-19 16:17:51 -05:00
Jason Zaman
789d0ebbf9 policycoreutils: Fix PEP8 issues
When trying to get policycoreutils working in python3, I kept running
into TabErrors:

    Traceback (most recent call last):
      File "/usr/lib/python-exec/python3.3/semanage", line 27, in <module>
        import seobject
      File "/usr/lib64/python3.3/site-packages/seobject.py", line 154
        context = "%s%s" % (filler, raw)
                                       ^
    TabError: inconsistent use of tabs and spaces in indentation

Python3 is a lot stricter than python2 regarding whitespace and looks like
previous commits mixed the two.  When fixing this, I took the chance to fix
other PEP8 style issues at the same time.

This commit was made using:
$ file $(find . -type f) | grep -i python | sed 's/:.*$//' > pyfiles
$ autopep8 --in-place --ignore=E501,E265 $(cat pyfiles)

The ignore E501 is long lines since there are many that would be wrapped
otherwise, and E265 is block comments that start with ## instead of just #.

Signed-off-by: Jason Zaman <jason@perfinion.com>
2015-07-24 16:07:13 +08:00
Sven Vermeulen
73b7ff410c Only invoke RPM on RPM-enabled Linux distributions
When calling "sepolgen generate" to automatically generate a SELinux
policy template, the command fails when it cannot invoke RPM related
commands on Linux distributions that do not support RPM by default:

Failed to retrieve rpm info for selinux-policy
Traceback (most recent call last):
  File "/usr/lib/python-exec/python2.7/sepolicy", line 643, in <module>
    args.func(args)
  File "/usr/lib/python-exec/python2.7/sepolicy", line 517, in generate
    print mypolicy.generate(args.path)
  File "/usr/lib64/python2.7/site-packages/sepolicy/generate.py", line 1370, in generate
    out += "%s # %s\n" % (self.write_spec(out_dir), _("Spec file"))
  File "/usr/lib64/python2.7/site-packages/sepolicy/generate.py", line 1219, in write_spec
    fd.write(self.generate_spec())
  File "/usr/lib64/python2.7/site-packages/sepolicy/generate.py", line 1181, in generate_spec
    selinux_policyver = get_rpm_nvr_list("selinux-policy")[1]
TypeError: 'NoneType' object has no attribute '__getitem__'

As the RPM related steps are only needed on RPM-enabled distributions,
we should ignore these steps on other Linux distribution platforms.

In this patch, we use the Python platform module to get the Linux
distribution, and only start the RPM-related activities on Linux
distributions that use RPM as their native package manager.

Signed-off-by: Sven Vermeulen <sven.vermeulen@siphos.be>
2015-06-12 08:57:40 -04:00
Stephen Smalley
549912d229 org.selinux.policy: Require auth_admin_keep for all actions.
Fedora permits obtaining local policy customizations and the list
of policy modules without admin authentication, but we would prefer
more conservative defaults upstream.

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2015-04-16 09:40:31 -04:00
Nicolas Iooss
e4d693ae87 Use $(PYTHON) instead of "python" in every Makefile
This fixes the build with "make PYTHON=python2" on systems where python
is python3.

For PYLIBVER and PYTHONLIBDIR definitions, I tested Python 2.5, 2.6, 2.7,
3.3 and 3.4.  For each of them, these commands print the expected result:

    python -c 'import sys;print("python%d.%d" % sys.version_info[0:2])'"
    python -c "from distutils.sysconfig import *;print(get_python_lib(1))"

Acked-by: Steve Lawrence <slawrence@tresys.com>
2014-10-02 09:56:49 -04:00
Dan Walsh
7315245750 Add new icons for sepolicy gui 2013-11-13 11:07:17 -05:00
Stephen Smalley
11fa7dfc01 Merge branch 'master' into next
Conflicts:
	policycoreutils/ChangeLog
2013-11-13 11:06:54 -05:00
Dan Walsh
e8718ef514 Make sure we do the polkit check on all dbus interfaces.
Change policy kit to only allow access on the console.
2013-11-13 11:00:29 -05:00
Dan Walsh
ef102bf81a Call proper dbus function
Signed-off-by: Dan Walsh <dwalsh@redhat.com>
2013-11-13 11:00:18 -05:00
Dan Walsh
d5116bd45b Add support to return sesitivities and cats for python bindings.
Signed-off-by: Dan Walsh <dwalsh@redhat.com>
2013-11-08 15:51:52 -05:00
Dan Walsh
261a8a8385 Add domain to short list of domains, when -t and -d used together
Signed-off-by: Dan Walsh <dwalsh@redhat.com>
2013-11-08 15:50:38 -05:00
Dan Walsh
dc866db4dc Only return writeable files that are enabled
Signed-off-by: Dan Walsh <dwalsh@redhat.com>
2013-11-08 15:49:33 -05:00
Dan Walsh
635e803e1c Call proper dbus function
Signed-off-by: Dan Walsh <dwalsh@redhat.com>
2013-11-08 15:49:03 -05:00
Laurent Bigonville
2e93833b1b Minor manpages improvements 2013-11-06 09:36:33 -05:00
Dan Walsh
b33b4f42d5 Make yum/extract_rpms optional so that apt based systems can use tool 2013-10-31 12:11:04 -04:00
Stephen Smalley
f458b76076 Merge branch 'fedora' into master-merge
Conflicts:
	libselinux/src/Makefile
	libselinux/src/selinux_config.c
	policycoreutils/audit2allow/audit2allow.1
	policycoreutils/scripts/fixfiles.8
	policycoreutils/semanage/semanage.8
	policycoreutils/sepolicy/Makefile
	policycoreutils/sepolicy/sepolicy/transition.py
	policycoreutils/setsebool/setsebool.8
2013-10-24 15:24:17 -04:00
Dan Walsh
fc965a99c6 Remove test_booleans_l from test, it is bogus 2013-10-24 15:10:55 -04:00
Dan Walsh
e6a1298e54 These are massive changes involved in building new GUI.
Too difficult to break out into seperate patches at this point.
Since almost no other groups are using sepolicy yet, I will push together.
2013-10-24 13:58:41 -04:00
Dan Walsh
43c9e8c7e2 Fix error when policy does not match the system. 2013-10-24 13:58:40 -04:00
Dan Walsh
d0b1e420e7 seinfo needs to work if mls is disabled.
This patch stops seinfo from failing when MLS disabled.
2013-10-24 13:58:40 -04:00
Dan Walsh
cc3df76279 Return the type aliases.
We wanted this information in sepolicy.
2013-10-24 13:58:40 -04:00
Dan Walsh
85d76c1671 Add new test suite for sepolicy tool set.
This test should be run before we do any builds to make sure there are
no regressions
2013-10-24 13:58:40 -04:00
Dan Walsh
a9dfbeeb72 bash completsion scripts have moved.
This patch moves the semanage bash completion script to the new location.
2013-10-24 13:58:39 -04:00
Stephen Smalley
39b5a40295 Fix relabel target.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2013-10-23 12:44:30 -04:00
Sven Vermeulen
622ebe0994 Fix KeyError when using sepolicy transition
When calling "sepolicy transition", a KeyError exception occurred:

~# sepolicy transition -s sysadm_t -t portage_t
Traceback (most recent call last):
  File "/usr/bin/sepolicy-2.7", line 465, in <module>
    args.func(args)
  File "/usr/bin/sepolicy-2.7", line 309, in transition
    mytrans.output()
  File "/usr/lib64/python2.7/site-packages/sepolicy/transition.py", line 76, in output
    print self.out(self.source)
  File "/usr/lib64/python2.7/site-packages/sepolicy/transition.py", line 72, in out
    buf+= self.out(x, seen, "%s%s ... " % (header, name))
  File "/usr/lib64/python2.7/site-packages/sepolicy/transition.py", line 67, in out
    for t in self.sdict[name]["map"]:
KeyError: 'map'

By updating the code to first check if the "map" key is known to the dictionary
(and only then executing the mentioned code) this error is no longer prevalent:

~# sepolicy transition -s sysadm_t -t portage_t
sysadm_t @ portage_exec_t --> portage_t
sysadm_t ... dhcpc_t ... initrc_t ... puppet_t @ portage_exec_t --> portage_t
sysadm_t ... dhcpc_t ... initrc_t ... puppet_t ... portage_fetch_t @ portage_exec_t --> portage_t
sysadm_t ... dhcpc_t ... initrc_t ... crond_t @ portage_exec_t --> portage_t
sysadm_t ... dhcpc_t ... initrc_t ... crond_t ... system_cronjob_t @ portage_exec_t --> portage_t

Signed-off-by: Sven Vermeulen <sven.vermeulen@siphos.be>
2013-10-16 15:22:40 -04:00
Laurent Bigonville
c2824833a6 policycoreutils: Do not include LDFLAGS in CFLAGS when building sepolicy
For some reasons, -fpie and -fPIE are being set in LDFLAGS, this is
causing a FTBFS on Debian.

-fpie and -fPIE are anyway useless for libraries
2013-10-16 15:13:07 -04:00
Laurent Bigonville
3c20b742ca policycoreutils: init_policy() takes no arguments
Fix "function declaration isn't a prototype" error when
-Werror=strict-prototypes is set
2013-10-16 15:12:46 -04:00
Eric Paris
1dce0bf16d policycoreutils: sepolicy: new command to unite small utilities
Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
2013-02-05 20:14:28 -05:00