Commit graph

1348 commits

Author SHA1 Message Date
Stephen Smalley
c95ede0034 Updated libselinux ChangeLog.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2015-08-06 11:35:16 -04:00
Stephen Smalley
9f9e3f2102 libselinux: test for file_contexts.bin format
Check to see if the file whose path is passed to selabel_open() starts
with the file_contexts.bin magic number, and if so, automatically
treat it as a file_contexts.bin file.  This allows one to open
file_contexts.bin formatted files without necessarily having a .bin
file suffix.  This removes the need for the previously added
.bin file suffix test.

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2015-08-06 11:34:21 -04:00
Stephen Smalley
6f295008ef libselinux: add selabel_cmp interface and label_file backend
Add a selabel_cmp() interface for comparing two label configurations,
and implement it for the file backend (i.e. for file_contexts). This
allows comparing two file_contexts configurations to see if the first
is a subset of, equal/identical to, a superset of, or incomparable to
the second.  The motivating use case is to allow comparing two
file_contexts.bin files in Android CTS to confirm that a device
file_contexts.bin file contains all of the entries in the AOSP
general file_contexts.

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2015-08-06 11:34:00 -04:00
James Carter
774f859bce Updated libsemanage and policycoreutils ChangeLogs.
Signed-off-by: James Carter <jwcart2@tycho.nsa.gov>
2015-08-06 11:01:03 -04:00
Yuli Khodorkovskiy
65c6325271 policycoreutils/semodule: update semodule to allow extracting modules
Add --extract/-E, --cil/-c, and --hll/-H to extract modules. If -c/-H
are not provided, the module will be output as HLL by default. Only
--cil or --hll (which will use the lang_ext in the semodule store) are valid
options to use with -E. The module is written to the current working directory
as <module_name>.<lang_ext>.

If a module exists as HLL and is exported as CIL, it will first compile into
CIL and cache to the module store. Once compiled, exporting will
continue.

If no priority is provided when extracting a module, then extraction at
the default priority, 400, will be attempted. If the module does not
exist at the default priority, then it will be exported at the highest
existing priority.

Examples:

Extract the wireshark module in a .cil format. If the module only exists
as HLL on the system, the module will be compiled into CIL and placed
into the module store. This command will then write wireshark.cil to the CWD.

    semodule --cil --extract wireshark

Extract the wireshark module in HLL format. Since the original HLL file
was a policy package, a wireshark.pp will be written to the CWD.

    semodule -E wireshark

Extract the wireshark module as CIL and HLL and extract the puppet
module as CIL at priority 400.

    semodule --hll -E wireshark --cil -E wireshark -X 400 --cil -E puppet

Signed-off-by: Yuli Khodorkovskiy <ykhodorkovskiy@tresys.com>
Signed-off-by: James Carter <jwcart2@tycho.nsa.gov>
2015-08-06 10:59:44 -04:00
Yuli Khodorkovskiy
d4f3ba7c50 libsemanage: Fix null pointer dereference in semanage_module_key_destroy
If modkey is NULL, semanage_module_key_destroy() would still try to
initialize a modkey after freeing it.

Signed-off-by: Yuli Khodorkovskiy <ykhodorkovskiy@tresys.com>
Signed-off-by: James Carter <jwcart2@tycho.nsa.gov>
2015-08-06 10:59:28 -04:00
Yuli Khodorkovskiy
228261a51a libsemanage: Add ability to extract modules
Add semanage_module_extract() to extract a module as CIL or HLL. The
function takes a module name and whether to extract as CIL or HLL.

If a CIL file is requested, but does not exist, semanage_module_extract()
will compile the HLL to CIL and cache the CIL in the store as well as
extract the module. A module that was installed from a CIL file will export
as CIL when the HLL version of the file is requested.

Signed-off-by: Yuli Khodorkovskiy <ykhodorkovskiy@tresys.com>
Signed-off-by: James Carter <jwcart2@tycho.nsa.gov>
2015-08-06 10:59:22 -04:00
Stephen Smalley
40b80ad8b2 Updated sepolgen ChangeLog.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2015-08-05 15:16:18 -04:00
Robert Kuska
1ee796ccb7 sepolgen: convert cmp functions to key functions
In python3 it is needed to pass compare function as a key argument
instead of directly passing compare function to sort function

Signed-off-by: Robert Kuska <rkuska@redhat.com>
2015-08-05 15:10:21 -04:00
Robert Kuska
60956ac7ec sepolgen: Decode output from Popen in Python3
In Python3 output from Popen communicate function
returns bytes, to handle output as a string it is needed
to properly decode it.

Signed-off-by: Robert Kuska <rkuska@redhat.com>
2015-08-05 15:10:16 -04:00
Stephen Smalley
ec861462fa Updated libselinux ChangeLog.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2015-08-05 13:05:00 -04:00
Stephen Smalley
09ea624d12 libselinux: support specifying file_contexts.bin file path
At present, the label_file backend expects to be provided the path
to the text file_contexts file and always appends the .bin suffix
when checking for the binary file_contexts.bin file.  If one
attempts to directly specify the path to a file_contexts.bin file
to selabel_open(), it will fail as the code will append a second
.bin suffix to it.  Check to see if the file path already has a .bin
suffix and do not append it in that case.

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2015-08-05 13:03:36 -04:00
Stephen Smalley
0454b7ac2c libselinux: support file_contexts.bin without file_contexts
Change the label_file backend in libselinux to support systems
that only have file_contexts.bin files installed and do not ship
a file_contexts file at all.  Only fail if neither file can be
loaded.

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2015-08-05 13:03:23 -04:00
Stephen Smalley
509e60775d Update libsemanage ChangeLog.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2015-08-04 11:12:47 -04:00
Petr Lautrbach
3c3006f791 semanage_migrate_store: add -r <root> option for migrating inside chroots
-r, --root
  Set an alternative root for the migration (default: /)

Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2015-08-04 11:11:46 -04:00
Stephen Smalley
1874317293 Update libsepol ChangeLog.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2015-08-04 11:11:22 -04:00
Yuli Khodorkovskiy
6ea58f548b libsepol: Replace sscanf in module_to_cil
Some platforms do not have %ms support in sscanf. This adds a tokenize()
function to be used instead of sscanf. tokenize() has the ability to split on any
delimiter. All whitespace delimiters will be squashed.

Signed-off-by: Yuli Khodorkovskiy <ykhodorkovskiy@tresys.com>
2015-08-04 11:10:05 -04:00
Stephen Smalley
23f6db52a5 Updated policycoreutils and sepolgen ChangeLogs.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2015-07-31 11:18:39 -04:00
Petr Lautrbach
7bd95d71f1 policycoreutils: Comment constraint rules in audit2allow and sepolgen output
Constraint rules in output need to be commented in order to make a policy
compilable.

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

Patch-by: Miroslav Grepl <mgrepl@redhat.com>
Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2015-07-31 11:16:00 -04:00
Stephen Smalley
5b73ba0f84 Updated checkpolicy ChangeLog.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2015-07-31 09:04:52 -04:00
Stephen Smalley
a3691b87be checkpolicy: fix double free on name-based type transitions
checkpolicy was directly assigning type sets rather than using
type_set_cpy() and therefore creating pointer aliases to the
same type set from multiple filename-based type transition rules
if they specified multiple classes.  This would then yield a double
free when destroying the rules afterward and a segmentation fault.
Fix it to use type_set_cpy().

Reported-by: William C Roberts <william.c.roberts@intel.com>
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2015-07-31 08:57:32 -04:00
Stephen Smalley
38feeaddf7 Updated policycoreutils ChangeLog.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2015-07-24 09:05:33 -04: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
Steve Lawrence
d19cda0c80 Updated libsepol ChangeLog
Signed-off-by: Steve Lawrence <slawrence@tresys.com>
2015-07-22 11:02:32 -04:00
Steve Lawrence
5eae956abf libsepol/cil: Improve resolution error messages
In some cases, if a statement failed to resolve inside an optional, we
would still log a failed to resolve error message, even though the
optional was disabled and everything successfully compiled. This was
confusing. Additionally, if a resolution failure occurred outside of an
optional, the error message did not include the actual name that could
not be resolved--it only logged the statement type (e.g. allow,
booleanif, etc.) and file/line number.

This patch removes resolution error messages which should not always be
printed, as well as improves the resolution failure message to also
print the last name that was attempted to be resolved. Also makes some
less important error messages INFO rather than WARN, which tended to
just clutter things and hide actual error messages.

Signed-off-by: Steve Lawrence <slawrence@tresys.com>
2015-07-22 11:02:16 -04:00
Stephen Smalley
92cc7b0112 Updated policycoreutils ChangeLog.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2015-07-22 10:08:05 -04:00
Stephen Smalley
4031618396 policycoreutils: semanage: fix moduleRecords deleteall method
commit 2ff279e21e ("policycoreutils:
 semanage: update to new source policy infrastructure") introduced
new methods for enabling/disabling modules but failed to update
the deleteall method of class moduleRecords to use the new method.
The deleteall method was introduced by commit
3dafb1046d ("Add deleteall customizations
field for modules.") as a way to re-enable all locally disabled modules.

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2015-07-22 09:59:35 -04:00
Stephen Smalley
5ee1befee4 policycoreutils: semanage: kwarg -> kwargs
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2015-07-22 09:33:12 -04:00
Stephen Smalley
bcdb745f87 Updated libsemanage ChangeLog.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2015-07-22 09:24:19 -04:00
Yuli Khodorkovskiy
d56c2b434e libsemanage: Add file_contexts and seusers to the store
This patch writes file_contexts and seusers to the policy store as well as
/etc/selinux/. Additionally, file_contexts and seusers are now parsed from the
store rather than the final directory which was the old behavior. This allows
all policy related files to be kept in the policy store.

Signed-off-by: Yuli Khodorkovskiy <ykhodorkovskiy@tresys.com>
2015-07-22 09:23:38 -04:00
Stephen Smalley
d7b1bf3ff2 Updated policycoreutils ChangeLog.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2015-07-22 09:21:23 -04:00
Michal Srb
7574a50f18 policycoreutils/scripts: improve compatibility with Python 3
- __builtin__ module has been renamed to "builtins" in Python 3
- use reserved word `as` in try-except
- replace print statement with print function
- migrate from commands to subprocess
- fix formatting

Signed-off-by: Michal Srb <msrb@redhat.com>
2015-07-22 09:20:44 -04:00
Michal Srb
349239e677 policycoreutils/semanage: improve compatibility with Python 3
- gettext.install() only takes "unicode" keyword argument in Python 2
- __builtin__ module has been renamed to "builtins" in Python 3
- use reserved word `as` in try-except
- replace print statement with print function

Signed-off-by: Michal Srb <msrb@redhat.com>
2015-07-22 09:20:44 -04:00
Michal Srb
a9ce2e7358 policycoreutils/sandbox: improve compatibility with Python 3
- gettext.install() only takes optional "unicode" keyword argument in
  Python 2, and its default value is "False". This keyword argument
  doesn't exist in Python 3
- __builtin__ module has been renamed to "builtins" in Python 3
- raw_input() has been renamed to input() in Python 3
- specify octal literals in form compatible with both Python 2 and 3
- migrate from commands to subprocess
- replace print statement with print function
- use reserved word `as` in try-except
- replace deprecated assert_() method with assertTrue() in unit tests

Signed-off-by: Michal Srb <msrb@redhat.com>
2015-07-22 09:20:44 -04:00
Michal Srb
d135951152 policycoreutils/audit2allow: improve compatibility with Python 3
- replace print statement with print function
- use reserved word `as` in try-except
- replace deprecated assert_() method with assertTrue() in unit tests

Signed-off-by: Michal Srb <msrb@redhat.com>
2015-07-22 09:20:44 -04:00
Stephen Smalley
5c5183171d Updated libselinux ChangeLog.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2015-07-22 09:20:29 -04:00
Stephen Smalley
fec839cf17 libselinux: simplify procattr cache
https://github.com/systemd/systemd/issues/475 identified a problem
in libselinux with using getpid(3) rather than getpid(2) due to direct
use of the clone() system call by systemd.  We could change libselinux
to use getpid(2) instead, but this would impose a getpid(2) system call
overhead on each get*con() or set*con() call.  Rather than do this,
we can instead simplify the procattr cache and get rid of the
caching of the pid and tid entirely, along with the atfork handler.
With commit 3430519109 ("use
/proc/thread-self when available"), we only need the tid when
on Linux < 3.17, so we can just always call gettid() in that case (as
done prior to the procattr cache) and drop the cached tid. The cached
pid and atfork handlers were only needed to reset the cached tid, so
those can also be dropped. The rest of the cached attributes are not
reset by the kernel on fork, only on exec, so we do not need to
flush them upon fork/clone.

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2015-07-20 12:56:01 -04:00
Stephen Smalley
2202a68d5a Updated sepolgen ChangeLog.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2015-07-16 13:11:14 -04:00
Stephen Smalley
1eebc7748f Updated policycoreutils ChangeLog.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2015-07-16 13:11:01 -04:00
Robert Kuska
a280b06dd9 sepolgen: Edit tests so they pass even on Python3 where hash is random.
By default in Python3 hash uses random seed as salt, this leads to
different order in output from functions which rely on hash as are
dicts and sets. Tests in sepolgen relied on the frozen order.

Signed-off-by: Robert Kuska <rkuska@redhat.com>
2015-07-16 13:06:03 -04:00
Robert Kuska
a9fb9053f7 sepolgen: Close files after reading/writing in tests.
Signed-off-by: Robert Kuska <rkuska@redhat.com>
2015-07-16 13:06:03 -04:00
Robert Kuska
15a7553d22 sepolgen: Apply fixes discovered by 2to3 where needed.
Replace usage of print statement with print function.
Use `in` instead of `has_key` when checking for key in dict.
When using `raise` add text (if any) as parameter of exception function.
Add Python3 imports of moved modules.
Replace `map` with list comprehension.
Use reserved word `as` in try-except when catching exception.
Replace `ifilter` function with `filter`.

Signed-off-by: Robert Kuska <rkuska@redhat.com>
2015-07-16 13:06:03 -04:00
Robert Kuska
c2ecb8e3ec sepolgen: Replace usage of xrange inside of tests.
xrange function is gone in Python3 and instead range is
xrange by default. Also it doesnt seem to be important
to have xrange used in tests on Python2.

Signed-off-by: Robert Kuska <rkuska@redhat.com>
2015-07-16 13:06:02 -04:00
Robert Kuska
2747dfb880 sepolgen: Replace usage of attributes of types module
In Python3 all strings are by default Unicode and both Unicode and String
types are removed from types module. We introduce separate
variables `bytes_type` and `string_type` to reflect Python3 understanding
of strings, on Python2 `bytes_type` refers to <str> and `string_type` to
<unicode>, on Python3 `bytes_type` are <bytes> and `string_type` <str>.
As all strings are Unicodes by default on Python3 we encode them to
bytes when needed as late as possible.

Also other attributes were replaced with their equivalents from
builtins which are available for both Python3 and Python2.

Signed-off-by: Robert Kuska <rkuska@redhat.com>
2015-07-16 13:06:02 -04:00
Robert Kuska
aa903a27ba sepolgen: Replace usage of __cmp__ with rich comparison.
In Python3 the __cmp__ function is removed, and rich
comparison should be used instead.
Also the cmp function is gone in Python3 therefore it is
reimplemented in util.py and used if running on Python3.

Signed-off-by: Robert Kuska <rkuska@redhat.com>
2015-07-16 13:06:02 -04:00
Robert Kuska
aee172010a sepolgen: Unicode-objects must be encoded before hashing.
sha256 hash operates with bytes and in Python3 all strings are unicode
by default, we must encode the data before hashing to ensure they
are bytes in Python3

Signed-off-by: Robert Kuska <rkuska@redhat.com>
2015-07-16 13:06:02 -04:00
Robert Kuska
788f5dba54 sepolgen: Use sort function with key parameter.
Since Python 2.4 .sort() as well as the new sorted() function
take a key parameter which should be a function that returns
a sorting key.

Signed-off-by: Robert Kuska <rkuska@redhat.com>
2015-07-16 13:06:02 -04:00
Robert Kuska
467c2a45b9 sepolgen: Replace func_code calls with __code__.
In Python 3, special function attributes have been
renamed for consistency with other attributes.
__code__ attribute is also present in py2.7 and py2.6

Signed-off-by: Robert Kuska <rkuska@redhat.com>
2015-07-16 13:06:02 -04:00
Robert Kuska
fd00e882c4 sepolgen: Use relative imports for modules within sepolgen.
Python 3 changes the syntax for imports from within a package,
requiring you to use the relative import syntax,
saying from . import mymodule instead of the just import mymodule.

Signed-off-by: Robert Kuska <rkuska@redhat.com>
2015-07-16 13:06:02 -04:00
Robert Kuska
e25d39addc sepolgen: Replace deprecated *Equals functions in tests
Also remove usage of cmp in tests as cmp is removed in Python3

Signed-off-by: Robert Kuska <rkuska@redhat.com>
2015-07-16 13:06:02 -04:00