Commit graph

408 commits

Author SHA1 Message Date
Stephen Smalley
2d1a6c63c6 libselinux,libsemanage: fix RUBYLIBS definition
The RUBYLIBS definition introduced by commit f5b9bc2a06
("libselinux,libsemanage: link Ruby wrappers with -lruby") did
not work on Debian.  Fix it based on a patch by Nicolas Iooss.

Reported-by: Laurent Bigonville <bigon@debian.org>
Suggested-by: Nicolas Iooss <nicolas.iooss@m4x.org>
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2017-06-28 09:35:57 -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
Patrick Steinhardt
2c651e0a28 genhomedircon: avoid use of non-standard getpwent_r
The `getpwent_r` function is a non-standard but reentrant version of the
POSIX-defined `getpwent` function. While it should provide the benefit
of being safe to use in multi-threaded environments, it disallows us
from compiling with libc implementations which stick to the POSIX
standard more closely.

As libsemanage may be used in a multi-threaded environment, being
reentrant may in fact be quite important to us. As such, simply
switching out `getpwent_r` against its non-reentrant function can prove
quite dangerous. But interestingly enough, the glibc implementation of
`getpwent_r` does not even guarantee being reentrant. Quoting from
getpwent_r(7):

    NOTES

    The function getpwent_r() is not really reentrant since it shares
    the reading position in the stream with all other threads.

As such, it is non-reentrant in the same sense as its simple `getpwent`
brother and can simply be switched out without losing any guarantees
here.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
2017-06-22 16:44:07 -04:00
Nicolas Iooss
cdd3b1d728 libsemanage/tests: fix linking
When -lbz2 is written before libsemanage.a in the linker command line,
the linker may fail to find all needed symbols. This occurs for example
when building on Ubuntu 14.04 without the gold linker (cf. Travis build
result https://travis-ci.org/fishilico/selinux/builds/245072498):

    gcc libsemanage-tests.o test_semanage_store.o test_utilities.o utilities.o
    -L/home/travis/build/fishilico/selinux/installdir/usr/lib -o libsemanage-tests
    -lcunit -lbz2 -laudit ../src/libsemanage.a -lselinux -lsepol
    ../src/libsemanage.a(direct_api.o): In function `bzip':
    direct_api.c:(.text+0xee6): undefined reference to `BZ2_bzWriteOpen'
    direct_api.c:(.text+0xf11): undefined reference to `BZ2_bzWriteClose'
    direct_api.c:(.text+0xf79): undefined reference to `BZ2_bzWrite'
    direct_api.c:(.text+0xfa1): undefined reference to `BZ2_bzWriteClose'
    direct_api.c:(.text+0xfe0): undefined reference to `BZ2_bzWriteClose'
    ../src/libsemanage.a(direct_api.o): In function `bunzip':
    direct_api.c:(.text+0x114e): undefined reference to `BZ2_bzReadOpen'
    direct_api.c:(.text+0x1249): undefined reference to `BZ2_bzRead'
    direct_api.c:(.text+0x13b4): undefined reference to `BZ2_bzReadClose'
    ../src/libsemanage.a(seusers_local.o): In function `semanage_seuser_audit':
    seusers_local.c:(.text+0x4c5): undefined reference to `audit_open'
    seusers_local.c:(.text+0x5b6): undefined reference to `audit_log_semanage_message'
    seusers_local.c:(.text+0x5cd): undefined reference to `audit_close'

As ../src/libsemanage.a is a dependency of $(EXECUTABLE) in the
Makefile, use $^ to include it in the command line. While at it, put $^
after $(LDFLAGS) as other Makefiles do.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-06-21 10:31:36 -04:00
Jason Zaman
15f2740733 Makefiles: override *FLAGS and *LIBS
There were several places in the makefiles where LDLIBS or CFLAGS were
supposed to include options to build. They were missing the override
keyword so would be skipped if these vars were set on the make cmdline.
Add the override directive to fix this.

Signed-off-by: Jason Zaman <jason@perfinion.com>
2017-06-20 12:15:04 -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
Bernhard M. Wiedemann
c18ea1df62 sort input files
when building packages (e.g. for openSUSE Linux)
(random) filesystem order of input files
influences ordering of functions in the output,
thus without the patch, builds (in disposable VMs) would usually differ.

See https://reproducible-builds.org/ for why this matters.
2017-06-01 14:00:30 -04:00
Stephen Smalley
f60244365c libsemanage: Fix snprintf warnings from gcc 7
Fixes the following warning from gcc7 by increasing the
buffer size to PATH_MAX.

semanage_store.c: In function ‘semanage_remove_directory’:
semanage_store.c:819:30: warning: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size 254 [-Wformat-truncation=]
   snprintf(s, sizeof(s), "%s/%s", path, namelist[i]->d_name);
                              ^~
semanage_store.c:819:3: note: ‘snprintf’ output 2 or more bytes (assuming 257) into a destination of size 255
   snprintf(s, sizeof(s), "%s/%s", path, namelist[i]->d_name);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2017-06-01 13:35:56 -04:00
Stephen Smalley
e41ae676c2 libsepol,libsemanage,libselinux: Fix fallthrough warnings from gcc 7
https://developers.redhat.com/blog/2017/03/10/wimplicit-fallthrough-in-gcc-7/

Fixes the following warnings by annotating with a /* FALLTHRU */ comment.
Unfortunately, the __attribute__ ((fallthrough)); approach does not appear
to work with older compilers.

../cil/src/cil_parser.c: In function ‘cil_parser’:
../cil/src/cil_parser.c:253:14: warning: this statement may fall through [-Wimplicit-fallthrough=]
    tok.value = tok.value+1;
    ~~~~~~~~~~^~~~~~~~~~~~~
../cil/src/cil_parser.c:254:3: note: here
   case SYMBOL:
   ^~~~
../cil/src/cil_parser.c:275:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
    if (tok.type != END_OF_FILE) {
       ^
../cil/src/cil_parser.c:279:3: note: here
   case END_OF_FILE:
   ^~~~

../cil/src/cil_post.c: In function ‘cil_post_fc_fill_data’:
../cil/src/cil_post.c:104:5: warning: this statement may fall through [-Wimplicit-fallthrough=]
    c++;
    ~^~
../cil/src/cil_post.c:105:3: note: here
   default:
   ^~~~~~~

regex.c: In function ‘regex_format_error’:
regex.c:541:10: warning: this statement may fall through [-Wimplicit-fallthrough=]
   *ptr++ = '.';
   ~~~~~~~^~~~~
regex.c:542:2: note: here
  case 3:
  ^~~~
regex.c:543:10: warning: this statement may fall through [-Wimplicit-fallthrough=]
   *ptr++ = '.';
   ~~~~~~~^~~~~
regex.c:544:2: note: here
  case 2:
  ^~~~
regex.c:545:10: warning: this statement may fall through [-Wimplicit-fallthrough=]
   *ptr++ = '.';
   ~~~~~~~^~~~~
regex.c:546:2: note: here
  case 1:
  ^~~~
regex.c: In function ‘regex_format_error’:
regex.c:541:10: warning: this statement may fall through [-Wimplicit-fallthrough=]
   *ptr++ = '.';
   ~~~~~~~^~~~~
regex.c:542:2: note: here
  case 3:
  ^~~~
regex.c:543:10: warning: this statement may fall through [-Wimplicit-fallthrough=]
   *ptr++ = '.';
   ~~~~~~~^~~~~
regex.c:544:2: note: here
  case 2:
  ^~~~
regex.c:545:10: warning: this statement may fall through [-Wimplicit-fallthrough=]
   *ptr++ = '.';
   ~~~~~~~^~~~~
regex.c:546:2: note: here
  case 1:
  ^~~~

modules.c: In function ‘semanage_module_get_path’:
modules.c:602:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
    if (file == NULL) file = "hll";
       ^
modules.c:603:3: note: here
   case SEMANAGE_MODULE_PATH_CIL:
   ^~~~
modules.c:604:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
    if (file == NULL) file = "cil";
       ^
modules.c:605:3: note: here
   case SEMANAGE_MODULE_PATH_LANG_EXT:
   ^~~~

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2017-06-01 13:35:45 -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
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
Jason Zaman
fcb5d5cc72 Makefiles: drop -L/-I to system paths
The toolchain automatically handles them and they break cross compiling.

LDFLAGS should also come before object files, some flags (eg,
-Wl,as-needed) can break things if they are in the wrong place)

Gentoo-Bug: https://bugs.gentoo.org/500674

Signed-off-by: Jason Zaman <jason@perfinion.com>
2017-04-25 08:27:05 -04:00
Stephen Smalley
8702a865e0 libsemanage: Save linked policy, skip re-link when possible
In commit b61922f727 ("libsemanage: revert
"Skip policy module re-link when only setting booleans"), we reverted
an optimization for setting booleans since it produced incorrect behavior.
This incorrect behavior was due to operating on the policy with local
changes already merged. However, reverting this change leaves us with
undesirable overhead for setsebool -P.  We also have long wanted
to support the same optimization for making other changes that do
not truly require module re-compilation/re-linking.

If we save the linked policy prior to merging local changes, we
can skip re-linking the policy modules in most cases, thereby
significantly improvement the performance and memory overhead of
semanage and setsebool -P commands.  Save the linked policy in the
policy sandbox and use it when we are not making a change that requires
recompilation of the CIL modules.  With this change, a re-link
is not performed when setting booleans or when adding, deleting, or
modifying port, node, interface, user, login (seusers) or fcontext
mappings.  We save linked versions of the kernel policy, seusers,
and users_extra produced from the CIL modules before any local
changes are merged.  This has an associated storage cost, primarily
storing an extra copy of the kernel policy file.

Before:
$ time setsebool -P zebra_write_config=1
real	0m8.714s
user	0m7.937s
sys	0m0.748s

After:
$ time setsebool -P zebra_write_config=1
real	0m1.070s
user	0m0.343s
sys	0m0.703s

Resolves: https://github.com/SELinuxProject/selinux/issues/50
Reported-by: Carlos Rodrigues <cefrodrigues@gmail.com>
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2017-04-12 14:56:29 -04:00
Nicolas Iooss
86e6ae67fd libsemanage: drop checks on semanage_module_info_destroy() value
semanage_module_info_destroy() always returns 0. Nevertheless
semanage_direct_list_all() uses its return value in a surprising way:

    cleanup:
        if (priorities != NULL) {
            /* ... */
            free(priorities);
        }
        /* ... */
        ret = semanage_module_info_destroy(sh, modinfo_tmp);
        if (ret != 0) {
            status = -1;
            goto cleanup;
        }

The last "goto cleanup;" leads clang's static analyzer to believe a
double free is possible. Even though this is a false positive, the
body of condition "if (ret != 0)" contains dead code. Remove it.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-04-11 14:22:59 -04:00
Stephen Smalley
b61922f727 libsemanage: revert "Skip policy module re-link when only setting booleans."
commit e5aaa01f81 ("Skip policy module
re-link when only setting booleans.") can lead to duplicate entries
(e.g. portcon entries) being added into the kernel policy because the
existing linked policy already includes the local customizations.
Revert this commit until we can come up with an approach that handles
this properly.  This means that setsebool -P triggers a full policy
rebuild.

From the original bug report:
I've noticed a strange interaction with custom ports and booleans.
After setting a boolean, the list of ports for a particular type
(which has been customized) shows duplicate entries.

Example:

    $ semanage port -a -t http_port_t -p tcp 12345
    $ semanage port -l | grep http_port_t
    http_port_t                    tcp      12345, 80, 81, ...
    $ setsebool -P zebra_write_config false
    $ semanage port -l | grep http_port_t
    http_port_t                    tcp      12345, 12345, 80, 81, ...
    $ setsebool -P zebra_write_config false
    $ semanage port -l | grep http_port_t
    http_port_t                    tcp      12345, 12345, 12345, 80, 81, ...

As can be seen, each time a boolean is set persistently (it doesn't
matter which boolean or which state), the custom port 12345 is
duplicated. Running "semodule -B" clears the duplicates.

However, if only the local customizations are listed, the port is
always listed only once:

    $ semanage port -l -C
    SELinux Port Type              Proto    Port Number
    http_port_t                    tcp      12345

Resolves: https://github.com/SELinuxProject/selinux/issues/50
Reported-by: Carlos Rodrigues <cefrodrigues@gmail.com>
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2017-04-10 11:04:39 -04:00
Nicolas Iooss
03298a22f7 libsemanage: genhomedircon: fix possible double-free
When write_contexts() frees variables context and new_context_str after
a line has been successfully emitted, these variables are not reset to
NULL. This leads the function to free them again if an error occurs when
processing the next line. Fix this by always resetting these variables
at the beginning of the loop.

This issue has been found using clang's static analyzer.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-03-29 10:26:59 -04:00
Nicolas Iooss
85da6194ea libsemanage: do not dereference a NULL pointer when calloc() fails
If "names = calloc(num_modinfos, sizeof(*names))" fails in
semanage_get_cil_paths(), the function tries to frees items in array
"names" even though it is NULL. Avoid this by returning directly.

This issue has been found using clang's static analyzer.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-03-29 10:26:55 -04:00
Nicolas Iooss
0438d5c421 libsemanage: do not close uninitialized file descriptors
When pipe() fails in semanage_pipe_data(), this function closes all file
descriptors in variables output_fd, err_fd and input_fd even when they
have not been initialized. Fix this by initializing the file descriptors
to -1.

This issue has been found using clang's static analyzer.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-03-29 10:26:50 -04:00
Nicolas Iooss
ccfbd9aa17 libsemanage/tests: include libsepol headers from $DESTDIR
When building and running tests on a system without SELinux with a
command similar to "make DESTDIR=/tmp/destdir install test", libsemanage
tests fail to build with the following error:

    In file included from utilities.h:20:0,
                     from utilities.c:24:
    ../src/handle.h:29:26: fatal error: sepol/handle.h: No such file or
    directory
     #include <sepol/handle.h>
                              ^

Fix this by adding the newly-installed directory under $DESTDIR (using
variable $PREFIX) in the search paths of the compiler.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-03-01 10:42:34 -05:00
Nicolas Iooss
4176a29235 libsemanage: never call memcpy with a NULL value
clang's static analyzer reports "Argument with 'nonnull' attribute
passed null" in append_str(), because argument t may be NULL but is used
in a call to memcpy().

Make append_str() do nothing when called with t=NULL.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-03-01 10:42:28 -05:00
Nicolas Iooss
1cd3e1a40a libselinux, libsemanage: make PYPREFIX computation more robust
On systems where $PYTHON is python3.5 (instead of python2 or python3),
pkg-config fails to find the Python package because it is named with a
dash (e.g. python-3.5).

Moreover the build system may have been using the pkg-config
configuration files for the wrong Python version when several Python
with the same major version number are installed (e.g. using python-3.5
on a system with both python-3.4 and python-3.5 and where
/usr/lib/pkgconfig/python3.pc is a symlink to python-3.5.pc).

In order to fix these two issues, compute $PYPREFIX from $PYTHON by
using the full major.minor version.

Moreover update Travis-Ci configuration to grab the relevant
configuration files for pkg-config from /opt/python (for example
/opt/python/3.5.2/lib/pkgconfig/python-3.5.pc) instead of using
system-provided files (/usr/lib/x86_64-linux-gnu/pkgconfig/python3.pc
and /usr/lib/x86_64-linux-gnu/pkgconfig/python2.pc).

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-02-21 13:42:52 -05:00
Nicolas Iooss
68a4203f87 libsemanage/tests: fix -Wwrite-strings warnings
Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-02-06 11:06:10 -05:00
Nicolas Iooss
a51b30ae23 libsemanage: make lang_ext parameter const in semanage_direct_write_langext()
When building with "clang -Wwrite-strings", the compiler reports the
following warnings:

    direct_api.c:1030:46: error: passing 'const char [4]' to parameter
    of type 'char *' discards qualifiers
    [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
                    status = semanage_direct_write_langext(sh, "cil", modinfo);
                                                               ^~~~~
    direct_api.c:898:11: note: passing argument to parameter 'lang_ext'
    here
                                    char *lang_ext,
                                          ^
    direct_api.c:1030:46: error: passing 'const char [4]' to parameter
    of type 'char *' discards qualifiers
    [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
                    status = semanage_direct_write_langext(sh, "cil", modinfo);
                                                               ^~~~~
    direct_api.c:898:11: note: passing argument to parameter 'lang_ext'
    here
                                    char *lang_ext,
                                          ^

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-02-06 11:05:38 -05:00
Nicolas Iooss
5b0ad2f00e libsemanage: genhomedircon: consider SEMANAGE_FCONTEXT_DIR in fcontext_matches()
When generating file_contexts.homedirs, libsemanage enumerates the users
on the system and tries to find misconfiguration issues by comparing
their home directories with file contexts defined in the policy. The
comparison is done by fcontext_matches().

Currently this function only operates on file contexts with type ALL,
but it makes sense to also operate on the DIR ones, as a comment states
in the function.

For example on a system with the following entry in /etc/passwd:

    mytestservice2000💯:/var/lib/mytestservice/dir:/bin/bash

and with the following file context definition:

    /var/lib/mytestservice/.* -d gen_context(system_u:object_r:var_lib_t,s0)

"semodule -B" now shows the following warning:

    libsemanage.get_home_dirs: mytestservice homedir
    /var/lib/mytestservice/dir or its parent directory conflicts with a
    file context already specified in the policy.  This usually
    indicates an incorrectly defined system account.  If it is a system
    account please make sure its uid is less than 1000 or greater than
    60000 or its login shell is /sbin/nologin.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-01-17 16:30:27 -05:00
Nicolas Iooss
1004a3b3f1 libsemanage: increment the right index variable in for loop
Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-01-06 14:08:26 -05:00
Nicolas Iooss
58fb53bc2b libsemanage: genhomedircon: remove duplicated test condition
Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-01-06 14:07:38 -05:00
Guido Trentalancia
0abc25a3e6 libsemanage: Fix unitialized variable compiler warnings
Fix unitialized variable compiler warnings when using the
"-O -Werror" flags on gcc6 by initializing the variables in
question. It was possible for err_data_len to be used without
initialization, but not cil_data_len.

Signed-off-by: Guido Trentalancia <guido@trentalancia.net>
Signed-off-by: James Carter <jwcart2@tycho.nsa.gov>
2017-01-06 12:15:23 -05:00
Nicolas Iooss
920ee9ee18 libsemanage: remove ustr library from Makefiles, README and pkg-config
This library is no longer used by libsemanage.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2016-12-21 13:40:11 -05:00
Nicolas Iooss
300b8ad423 libsemanage: genhomedircon: drop ustr dependency
ustr library uses old (pre-C99) "extern inline" semantic. This makes it
incompatible with recent versions of gcc and clang, which default to
C99 standard. Distributions have shipped patched versions of this
library to fix issues (e.g. Gentoo package uses this patch:
https://gitweb.gentoo.org/repo/gentoo.git/tree/dev-libs/ustr/files/ustr-1.0.4-gcc_5-check.patch?id=7dea6f8820f36bf389e6315044bea7507553bed0
) but there is no upstream solution to make ustr compatible with C99
standard.

The git tree of ustr (http://www.and.org/ustr/ustr.git) has not been
updated since 2008 and the developer of this project did not reply to
emails.

Therefore update genhomedircon implementation in order to no longer
rely on ustr library.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2016-12-21 13:40:11 -05:00
Nicolas Iooss
57a3b1b4b0 libsemanage: add semanage_str_replace() utility function
This function will be used in the next commit.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2016-12-21 13:40:11 -05:00
Nicolas Iooss
a228bb3736 libsemanage: simplify string utilities functions
Use string functions from C standard library instead of ustr. This makes
the code simpler and make utilities.c no longer depend on ustr library.

This changes how semanage_split() behaves when delim is not empty (NULL
or "") and the input string contains several successive delimiters:
semanage_split("foo::::bar", ":") returned "bar" and now returns ":bar".
This would not have any impact in the current code as semanage_split()
is only called with delim="=" (through semanage_findval(), in
libsemanage/src/genhomedircon.c), in order to split a "key=value"
statement.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2016-12-21 13:40:11 -05:00
Nicolas Iooss
fd6bc593b8 libsemanage/tests: test more cases of semanage_split*()
Before modifying semanage_split_on_space() and semanage_split(), test in
test_utilities.c how these functions behave for example when several
delimiter tokens are concatenated in the input string.

While at it, fix the memory leaks which were present in libsemanage
tests.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2016-12-21 13:40:11 -05:00
Nicolas Iooss
9e0cf6ec8a libsemanage/tests: make tests standalone
In order to run libsemanage tests, libsepol and libselinux source
directories need to exist next to libsemanage source directory. This
prevents tests to be run when using the released package.

As libsemanage tests only use public API of libselinux and libsepol,
link with the shared objects which are likely to be installed on the
system (or at least present in $DESTDIR).

While at it, drop TESTSRC variable as it was used to find libsemanage
internal headers but not the tested library (libsemanage.a). Moreover
add ../src/libsemanage.a to the target dependencies of the test
executable in order to rebuild it after libsemanage.a has been updated.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2016-12-21 13:40:11 -05:00
Nicolas Iooss
e51b233831 libsemanage/tests: make "make test" fail when a CUnit test fails
When modifications to libsemanage functions break the test cases tested
with the CUnit framework, "make test" currently succeeds, even though it
prints an output similar to:

    Suite: semanage_store
      Test: semanage_store_access_check ...passed
      Test: semanage_get_lock ...passed
      Test: semanage_nc_sort ...passed
    Suite: semanage_utilities
      Test: semanage_is_prefix ...passed
      Test: semanage_split_on_space ...FAILED
        1. test_utilities.c:150  - CU_ASSERT_STRING_EQUAL(temp,"baz")
      Test: semanage_split ...passed
      Test: semanage_list ...passed
      Test: semanage_str_count ...passed
      Test: semanage_rtrim ...passed
      Test: semanage_str_replace ...passed
      Test: semanage_findval ...passed
      Test: slurp_file_filter ...passed

Like commit 2489b50a91 ("libsepol: make "make test" fails when a CUnit
test fails") did for libsepol tests, modify the logic of function
do_tests() to return an error value when there has been at least one
failure. This makes "make test" fail as expected.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2016-12-21 13:40:11 -05:00
Nicolas Iooss
ab27085099 libsepol,libsemanage: write file name in flex output
Tools like lcov (for code coverage) does not like files named
"<stdout>". For example it reports errors like:

    genhtml: ERROR: cannot read
    /usr/src/selinux/libsemanage/src/<stdout>

When using flex -o option, the output file name gets written in the
generated C code, which solves this issue.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2016-11-29 08:47:36 -05:00
Nicolas Iooss
9140de74cf libselinux, libsemanage: use Python-specific .so extension
The Makefiles currently install the Python wrapper libraries using .so
suffix (_selinux.so, audit2why.so and _semanage.so). Even though this
works well with CPython 2 and 3, PyPy fails to find these files because
it is looking for files with a specific version token in the suffix (eg.
_selinux.pypy-41.so).

This suffix is advertised by the imp module. Here is the result of
'import imp;print([s for s, m, t in imp.get_suffixes() if t ==
imp.C_EXTENSION])' for several Python versions:

    Python 2.7.12: ['.so', 'module.so']
    Python 3.5.2: ['.cpython-35m-x86_64-linux-gnu.so', '.abi3.so', '.so']
    PyPy 5.4.1 (Python 2.7.10): ['.pypy-41.so']
    PyPy3 5.5.0-alpha0 (Python 3.3.5): ['.pypy3-55.so', '.pypy3-55.so']

Define the name of the installed Python-C extension using the first
extension of these lists, in order to make the Python extensions
compatible with pypy.

When building the Python wrappers for PyPy and PyPy3 on Linux, the
following environment variables need to be set (PyPy does not provide a
pkg-config file nor a platform-agnostic way to build the string
"-lpypy-c"):

    PYTHON=pypy (or PYTHON=pypy3)
    PYINC=-I$($PYTHON -c 'import sys;print(sys.prefix)')/include
    PYLIBS=-lpypy-c (or PYLIBS= if LDFLAGS does not have
        -Wl,-no-undefined)

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2016-11-18 08:52:38 -05:00
Stephen Smalley
7935dee8f6 Drop ChangeLog files
They can be generated as desired via git log.
No need to keep maintaining them by hand.

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-11-16 12:10:58 -05:00
Stephen Smalley
d0c82f8fb9 Updated libsemanage ChangeLog
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-11-15 17:28:49 -05:00
Nicolas Iooss
398266f95f libsemanage: use a macro prefixed with SEMANAGE to protect dso.h
Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2016-11-15 17:28:12 -05:00
Stephen Smalley
2ceadad8a3 Updated libselinux and libsemanage ChangeLog
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-11-15 11:14:24 -05:00
Nicolas Iooss
79db6da87f libselinux, libsemanage: swig: use SWIG_fail when an error occurs
Using SWIG_fail in the Python SWIG wrappers makes the wrapping function
destroy/free the memory which could have been dynamically allocated
before calling the wrapped function. This thus prevents possible memory
leaks in the wrappers of set*con(), set*con_raw(), security_compute_*(),
etc.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2016-11-15 11:11:25 -05:00
Nicolas Iooss
db17f12273 libselinux,libsemanage: fall back to gcc in exception.sh
clang does not support -aux-info option. When exception.sh is run with
CC=clang, use gcc to build selinuxswig_python_exception.i and
semanageswig_python_exception.i.

This does not solve the issue of building libselinux and libsemanage
Python wrappers on a system without gcc. However parsing the result of
"gcc -aux-info" is easier than parsing the header files so stay with
this command at least for now.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2016-11-15 11:10:57 -05:00
Stephen Smalley
2c1ae0f029 Updated libselinux and libsemanage ChangeLogs
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-11-15 11:07:20 -05:00
Nicolas Iooss
bb98da0948 libselinux,libsemanage: link Python wrapper with Python
When linking with -Wl,-no-undefined in LDFLAGS (in order to find
possible link-time errors), the Python wrapper module needs to be
linked with the right libpython.so. This library is found using
pkg-config in a new PYLIBS variable.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2016-11-15 11:04:00 -05:00
Nicolas Iooss
ad3aa7f52f libsemanage: query for python site-packages dir directly
Use the python interpreter to find the install directory, like commit
8162f10e67 ("libselinux: query for python site-packages dir directly")
did for libselinux.

While at it, do not install semanage.py (generated by SWIG) with
executable permission bits.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2016-11-15 11:04:00 -05:00
Nicolas Iooss
f5b9bc2a06 libselinux,libsemanage: link Ruby wrapper with -lruby
When linking with -Wl,-no-undefined in LDFLAGS (in order to find
possible link-time errors), the Ruby wrapper module needs to be linked
with the libruby.so which is used by $(RUBY). Introduce a new RUBYLIBS
variable to find this library.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2016-11-15 11:04:00 -05:00
Nicolas Iooss
22e3ad6633 libselinux,libsemanage: use Ruby to define RUBYINC
This makes building libselinux and libsemanage  more robust on systems
with several versions of Ruby installed: when building, only RUBY needs
to be set, without wondering about PKG_CONFIG_PATH or other environment
variables.

Using RbConfig::CONFIG["rubyarchhdrdir"] only works with Ruby >= 2.0 but
since previous Ruby versions are retired since 2015-02-23 this should
not have any impact
(https://www.ruby-lang.org/en/news/2015/02/23/support-for-ruby-1-9-3-has-ended/).

While at it, in libsemanage, use RbConfig::CONFIG["vendorarchdir"] to
install the Ruby extension, like commit 1cd80faa53 ("libselinux:
versioned ruby pkg-config and query vendorarchdir properly") did for
libselinux.

My main motivation with this patch is to make the build configuration
easier to define on Travis-CI or other continuous integration platforms.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2016-11-15 11:04:00 -05:00
Stephen Smalley
e0882cdbed Updated libsemanage ChangeLog
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-11-14 13:15:28 -05:00
Nicolas Iooss
b372170058 libsemanage: semanage_seuser_key_create: copy name
When removing a login using semanage with Python 3 the following error
occurs:

    # semanage login -l | grep my_user
    my_user                   user_u

    # semanage login --delete my_user
    ValueError: Login mapping for my_user is not defined

This is due to a use-after-free in the swig-generated code for python3
bindings.

Copy the user name in semanage_seuser_key_create() and free it in
semanage_seuser_key_free(), like commit eac6f1f1b5 ("libsepol:
sepol_{bool|iface|user}_key_create: copy name") did.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2016-11-14 13:14:33 -05:00
Stephen Smalley
b42a293978 Updated libselinux and libsemanage ChangeLogs
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-11-07 16:02:42 -05:00
Nicolas Iooss
70b986539e libselinux, libsemanage: remove *swig_python_exception.i if its creation failed
When compiling libselinux with CC=clang, "make pywrap" reports the
following message:

    bash exception.sh > selinuxswig_python_exception.i
    clang-3.9: error: no such file or directory: 'temp.aux'
    awk: fatal: cannot open file `temp.aux' for reading (No such file or
    directory)

This does not make the build fail as exception.sh returns an "OK"
status. Use "bash -e" with this script to make it return an error value.

In order not to keep an empty selinuxswig_python_exception.i file after
a build fails (which would make a second run of "make pywrap" incorrectly
succeed), remove the file when exception.sh fails.

As libsemanage uses the same code to build
semanageswig_python_exception.i, modify its Makefile too.

By the way, on Linux clang does not seem to currently support -aux-info
so it cannot be used to craft selinuxswig_python_exception.i.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2016-11-07 15:58:05 -05:00
Nicolas Iooss
5c620ead20 libsemanage: remove ruby_semanage.so with "make clean"
The Python wrapper is already removed in the clean target (with
$(SWIGSO)) so remove the Ruby wrapper too.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2016-11-07 15:56:53 -05:00
Stephen Smalley
6ff9318af9 Updated ChangeLogs
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-11-02 09:01:38 -04:00
Stephen Smalley
a0bd296a0d libsemanage: fix kernel pathname in semanage_verify_kernel()
Building with CC=clang, we get the following errors:

semanage_store.c:2177:20: error: implicit conversion from enumeration type 'enum semanage_final_defs' to different enumeration type 'enum semanage_store_defs' [-Werror,-Wenum-conversion]
            semanage_path(SEMANAGE_FINAL_TMP, SEMANAGE_KERNEL);
            ~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~
semanage_store.c:2177:40: error: implicit conversion from enumeration type 'enum semanage_final_path_defs' to different enumeration type 'enum semanage_sandbox_defs' [-Werror,-Wenum-conversion]
            semanage_path(SEMANAGE_FINAL_TMP, SEMANAGE_KERNEL);
            ~~~~~~~~~~~~~                     ^~~~~~~~~~~~~~~

This is an actual bug; semanage_verify_kernel() was never updated to
use semanage_final_path() when the rest were converted.  Fix it.
This pathname is only used if a kernel policy verifier is specified
in semanage.conf, so this is not used by default.

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-11-02 08:54:19 -04:00
Stephen Smalley
02b0d42113 Updated libsemanage ChangeLog
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-10-14 13:41:04 -04:00
Stephen Smalley
4cf9b9ce2d libsemanage: genhomedircon: only set MLS level if MLS is enabled
When a non-MLS policy was used with genhomedircon context_from_record()
in sepol would report an error because an MLS level was present when MLS
is disabled.  Based on a patch by Gary Tierney, amended to use
sepol_policydb_mls_enabled rather than semanage_mls_enabled because
we are testing the temporary working policy, not the active policy.

Reported-by: Jason Zaman <jason@perfinion.com>
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-10-14 13:36:37 -04:00
Stephen Smalley
b4cca24240 Update VERSION and ChangeLog files for 2.6 final release.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-10-14 11:31:26 -04:00
Stephen Smalley
4257778f18 Update VERSION and ChangeLog files for 2.6-rc2 release.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-10-06 10:23:40 -04:00
Stephen Smalley
d3467b67a0 Updated libsemanage ChangeLog
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-10-06 10:18:48 -04:00
Stephen Smalley
f9d1b1d16f libsemanage: genhomedircon: do not suppress logging from libsepol
As reported by Gary Tierney, genhomedircon suppresses logging from
libsepol when validating contexts.  This can result in an
empty file_contexts.homedirs file without any warning to the user
if policy has been incorrectly configured.  Remove the code that
was suppressing the logging so that errors are reported to the user.

Reported-by: Gary Tierney <gary.tierney@gmx.com>
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-10-06 10:13:12 -04:00
Stephen Smalley
4a6545c7df Updated libsemanage ChangeLog
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-10-06 09:52:53 -04:00
Gary Tierney
88e334f192 genhomedircon: use userprefix as the role for homedir content
Treat a users prefix like a mapping to the role for file context
specifications in users homedirs.  This behavior is only applicable when
the users prefix is the identifier of a role which is valid for the
given user.  If the prefix is not a valid role, then genhomedircon will
write contexts out as normal.

Additionally, this commit enables configuring RBACSEP in policy:

(tunableif enable_rbacsep
    (true
        (userprefix user_u user_r)
    (false
        (userprefix user_u object_r))))

Signed-off-by: Gary Tierney <gary.tierney@gmx.com>
2016-10-06 09:39:04 -04:00
Stephen Smalley
82f994550f Updated ChangeLogs
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-10-05 13:04:36 -04:00
Stephen Smalley
b514885063 libsepol, libsemanage: fix linker scripts / map files
The local: * entry should only be in the base entry, not in each of them.
This is part of resolving gold linker build failures reported by
Jason Zaman.

Reported-by: Jason Zaman <jason@perfinion.com>
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-10-05 12:54:46 -04:00
James Carter
790684d256 Updated libsemanage ChangeLog.
Signed-off-by: James Carter <jwcart2@tycho.nsa.gov>
2016-10-03 14:55:01 -04:00
James Carter
9d25ca6160 libsemanage: Fixes bug preventing the installation of base modules
Commit 7a728e46 changed module installation so that a module pp would
be installed using its module name instead of its filename and a warning
would be printed if they were different. With this change, base modules
could no longer be installed because of the way error handling was done.

This change fixes the error handling, so that when a base module is
installed it will be installed using its filename (since it does not
have a module name).

Based on bug report by Jason Zaman

Signed-off-by: James Carter <jwcart2@tycho.nsa.gov>
2016-10-03 14:30:23 -04:00
Stephen Smalley
0cea223d33 Update VERSION and ChangeLog files for 2.6-rc1 release.
Intentionally jumping versions in sepolgen to make it consistent
with the rest.

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-09-30 12:15:08 -04:00
Stephen Smalley
202fd6ed5d Updated libsemanage ChangeLog
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-09-29 10:49:35 -04:00
Nicolas Iooss
b08d7c159e Makefile: make distclean target work
A mispelling in the Makefile in the root directory prevented "make
distclean" to go into subdirectories.

In libsemanage/src/, semanageswig_python_exception.i was not cleaned by
"make distclean" because the target did not use $(GENERATED) and this
variable was being redefined in the Makefile.

Fix these two bugs.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2016-09-29 10:48:14 -04:00
Stephen Smalley
eb5bcc6752 Updated libsemanage ChangeLog
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-09-27 12:12:29 -04:00
Miroslav Grep
e3655a7378 libsemanage: Do not always print a module name warning
7a728e46 commit supposed to add a warning when a module name is
different than a filename, but this warning is printed always. This
commit fixes it.

Fixes:
$ semodule -X 400 -i testmod.pp
Warning: SELinux userspace will refer to the module from testmod.pp as
testmod rather than testmod

Signed-off-by: Miroslav Grepl <mgrepl@redhat.com>
2016-09-27 12:11:01 -04:00
James Carter
b0f76c3a4c Updated libsemanage and policycoreutils ChangeLogs.
Signed-off-by: James Carter <jwcart2@tycho.nsa.gov>
2016-09-26 11:47:03 -04:00
Petr Lautrbach
7a728e46a5 libsemanage: Use pp module name instead of filename
When a user installs a module, the filename is used as the module name.
This change was introduced with CIL language where a module name is not
stored in the module itself. It means that when a pp module has
different filename and stored module name, the filename is used instead
of the stored module name. It brings problems with compatibility for
scripts and modules which were built and used on older system and were
migrated to the new userspace.

This patch changes the behavior of semanage_direct_install_file() which
is used by 'semodule -i' so that when a module with pp language
extension is installed, it tries to get and use a stored module name
instead of a filename. A warning message is provided.

The warning message in policycoreutils/hll/pp is updated to reflect this
change:

$ semodule -X 400 -i /root/testfile.pp
Warning: SELinux userspace will refer to the module from /root/testfile.pp as testmod rather than testfile

$ /usr/libexec/selinux/hll/pp /root/testfile.pp testfile.cil
Warning: SELinux userspace will refer to the module from /root/testfile.pp as testmod rather than testfile

Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2016-09-26 11:38:45 -04:00
Stephen Smalley
badb849805 Updated ChangeLogs
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-09-26 11:03:33 -04:00
Nicolas Iooss
b7ac3286f2 libsemanage/tests: do not force using gcc
Allow using other compilers such as clang. Without this, the build fails
when $(CFLAGS) contains clang-specific flags:

    gcc: error: unrecognized command line option '-Weverything'

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2016-09-26 11:01:49 -04:00
Stephen Smalley
7a72a88019 Updated libsemanage ChangeLog
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-09-22 09:57:44 -04:00
Gary Tierney
d97292639c genhomedircon: remove hardcoded refpolicy strings
Removes the "system_u" and "s0" string literals from refpolicy and
replaces the seuser and range in each homedir, uid, and username context
specification for every user.

Signed-off-by: Gary Tierney <gary.tierney@gmx.com>
2016-09-22 09:47:25 -04:00
Stephen Smalley
36a21c38d1 Updated libsemanage ChangeLog
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-08-23 15:57:33 -04:00
Gary Tierney
67b328a91c genhomedircon: add support for %group syntax
semanage-login supports login mappings using the %group syntax, but
genhomedircon does not expand groups to the users belonging to them.

This commit adds support for generating home directory contexts for login
mappings using the group syntax and adds error reporting for handling cases
where there is ambiguity due to a user belonging to multiple groups mapped by
semanage-login. If a login mapping is added for the user which belongs to
multiple groups it will take precedence and resolve the ambiguity issue.

Signed-off-by: Gary Tierney <gary.tierney@gmx.com>
2016-08-23 15:54:45 -04:00
Gary Tierney
83ab9e258f genhomedircon: generate contexts for logins mapped to the default user
Removes a test in get_users() which excludes any logins that are
explicitly mapped to the default user from file context generation,
which results in logins mapped to the fallback user with home
directories outside of LU_HOMEDIRECTORY (in the absence of
usepasswd=True) having no matching file_contexts.homedirs entries.

Signed-off-by: Gary Tierney <gary.tierney@gmx.com>
2016-08-23 15:51:06 -04:00
Stephen Smalley
b0a9b464ae Updated libsemanage ChangeLog
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-08-17 16:44:38 -04:00
Stephen Smalley
a7334eb0de libsemanage: validate and compile file contexts before installing
libsemanage presently runs setfiles -c to validate the file_contexts
files and sefcontext_compile to compile them to file_contexts.bin
after installing the final files under /etc/selinux.  As a result,
any error that occurs during this processing may leave invalid files
in /etc/selinux.  Move this processing before installing the files
to their final location, and then copy the .bin files that were
generated.

This prevents an error like:
semanage fcontext -a -t httpd_exec_t "/foo["
from reaching the /etc/selinux directory at all, e.g.

$ sudo semanage fcontext -a -t httpd_exec_t "/foo["
[sudo] password for sds:
/var/lib/selinux/final/targeted/contexts/files/file_contexts.local:  line 4 has invalid regex /foo[:  missing terminating ] for character class
/var/lib/selinux/final/targeted/contexts/files/file_contexts: Invalid argument
libsemanage.semanage_validate_and_compile_fcontexts: setfiles returned error code 1.
OSError: Error

Reported-by: Vit Mojzis <vmojzis@redhat.com>
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-08-17 16:36:59 -04:00
James Carter
3f524c60fe Updated libsemanage ChangeLog.
Signed-off-by: James Carter <jwcart2@tycho.nsa.gov>
2016-08-10 10:29:16 -04:00
James Carter
999747aa57 Updated libselinux, libsemanage, libsepol, and policycoreutils ChangeLogs.
Signed-off-by: James Carter <jwcart2@tycho.nsa.gov>
2016-06-06 13:08:17 -04:00
Laurent Bigonville
fb85e5cc95 Sort object files for deterministic linking order
This patch is part of the Debian effort to make the build reproducible

Thank to Reiner Herrmann <reiner@reiner-h.de> for the patches

Signed-off-by: Laurent Bigonville <bigon@bigon.be>
2016-06-06 12:52:55 -04:00
Stephen Smalley
44e92a6959 Updated ChangeLogs.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-05-16 16:44:05 -04:00
Julien Pivotto
3fcda02a93 libsemanage: Support overriding Makefile RANLIB 2016-05-16 16:32:41 -04:00
Julien Pivotto
b13c44c367 libselinux, libsemanage: respect CC and PKG_CONFIG environment variable
Compilation tools respects certain environment variables, like CC.
However, in libselinux and libsemanage, they are not respected
everywhere. This command fixes respect for those variables, falling back
to the previous hardcoded values if not specified.
2016-05-16 16:29:07 -04:00
Nicolas Iooss
8e30f76c6d Update .gitignore files
Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2016-05-09 08:14:54 -04:00
Stephen Smalley
6ad28de149 Updated libselinux, libsemanage, libsepol, and policycoreutils ChangeLogs.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-05-02 08:45:45 -04:00
Laurent Bigonville
8586ee56be Fix multiple spelling errors
Thanks to the lintian utility from Debian
2016-05-02 08:45:45 -04:00
Stephen Smalley
fa5ca393cf Updated libsemanage ChangeLog.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-05-02 08:45:45 -04:00
Jason Zaman
5ebc83b1d3 genhomedircon: fix FALLBACK_NAME regex
Originally the fallback regex for the username was either ".*" or
"[^/]*". The second is more correct but still can match nothing.
changing the * to + means that it must match at least one character.

Signed-off-by: Jason Zaman <jason@perfinion.com>
2016-05-02 08:35:40 -04:00
Jason Zaman
4bbec88baa genhomedircon: write contexts for username and userid
Signed-off-by: Jason Zaman <jason@perfinion.com>
2016-05-02 08:35:26 -04:00
Jason Zaman
08cde98b60 genhomedircon: make USERID, USERNAME context lists
Signed-off-by: Jason Zaman <jason@perfinion.com>
2016-05-02 08:34:53 -04:00
Jason Zaman
3b23f12eb9 genhomedircon: Add uid and gid to struct user_entry
Signed-off-by: Jason Zaman <jason@perfinion.com>
2016-05-02 08:34:38 -04:00
Jason Zaman
c90780aaf7 genhomedircon: move fallback user to genhomedircon_user_entry_t
The fallback user is used in all the write functions, making all the
functions take the struct directly allows us to have everything
consistent between normal and fallback users.

Signed-off-by: Jason Zaman <jason@perfinion.com>
2016-05-02 08:34:25 -04:00
Jason Zaman
925914acea genhomedircon: rename FALLBACK #defines consistent with user struct
Signed-off-by: Jason Zaman <jason@perfinion.com>
2016-05-02 08:34:12 -04:00
Jason Zaman
a63b96b7e2 genhomedircon: factor out common replacement code
All the write_*_contexts() methods use exactly the same code.
This splits it off into a common helper function.

Signed-off-by: Jason Zaman <jason@perfinion.com>
2016-05-02 08:33:19 -04:00
Steve Lawrence
2b69984b0c Update ChangeLog and VERSION for final release
Signed-off-by: Steve Lawrence <slawrence@tresys.com>
2016-02-23 11:31:41 -05:00
Steve Lawrence
9d76b62fa7 Update libsepol, libsemanage, and policycoreutils ChangeLogs
Signed-off-by: Steve Lawrence <slawrence@tresys.com>
2016-02-17 08:52:11 -05:00
Nicolas Iooss
1e979a7a36 libsemanage: tests: do not overwrite CFLAGS and LDFLAGS
libsemanage/tests/Makefile currently overwrites CFLAGS and LDFLAGS
contents.  This makes building with custom flags (e.g. with address
sanitizer) harder.  Append flags to these variables instead.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2016-02-11 08:43:20 -05:00
Nicolas Iooss
5b6287fafc libsemanage: no longer use variables with unused attribute
Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2016-02-11 08:34:51 -05:00
Steve Lawrence
e97d3eca99 Update libsepol, libsemanage, policycoreutils, and sepolgen ChangeLogs
Signed-off-by: Steve Lawrence <slawrence@tresys.com>
2016-02-01 09:05:47 -05:00
Nicolas Iooss
033ea27c09 libsemanage: move modinfo_tmp definition before goto cleanup
In semanage_direct_set_module_info() and semanage_direct_list_all()
functions, when modinfo_tmp variable gets initialized, a branch to
"cleanup" label may have already been taken.  This leads to this
variable being possibly used uninitialized in these functions.

This is reported by clang:

    direct_api.c:2491:41: error: variable 'modinfo_tmp' may be
    uninitialized when used here [-Werror,-Wconditional-uninitialized]
            ret = semanage_module_info_destroy(sh, modinfo_tmp);
                                                   ^~~~~~~~~~~
    direct_api.c:2334:2: note: variable 'modinfo_tmp' is declared here
            semanage_module_info_t *modinfo_tmp = NULL;
            ^

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2016-02-01 08:25:13 -05:00
Nicolas Iooss
a11ce9dae5 libsemanage: initialize bools_modified variable.
In semanage_direct_commit() error path, bools_modified can be used in a
if statement without being initialized (when a "goto cleanup" is taken
early).  clang warns about this bug:

    direct_api.c:1441:18: error: variable 'bools_modified' may be
    uninitialized when used here [-Werror,-Wconditional-uninitialized]
            if (modified || bools_modified) {
                            ^~~~~~~~~~~~~~
    direct_api.c:1087:48: note: initialize the variable 'bools_modified'
    to silence this warning
                preserve_tunables_modified, bools_modified,
                                                          ^
                                                           = 0

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2016-02-01 08:25:13 -05:00
Steve Lawrence
b3b5ede9ca Update ChangeLog and VERSION for release candidate
Signed-off-by: Steve Lawrence <slawrence@tresys.com>
2016-01-07 10:01:31 -05:00
Stephen Smalley
33fb501474 Update libsemanage ChangeLog.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2015-10-28 08:55:16 -04:00
Laurent Bigonville
d92388a8b0 Load libsepol.so.1 instead of libsepol.so
libsepol.so symlink is usually part of the development package, try to
load the library directly instead.
2015-10-28 08:54:27 -04:00
Steve Lawrence
8f13ce624d Update libsemanage ChangeLog.
Signed-off-by: Steve Lawrence <slawrence@tresys.com>
2015-09-03 15:41:39 -04:00
Steve Lawrence
dbc639a35a libsemanage: store users_extra in the policy store
users_extra is needed by genhomedircon and when listing seusers, so it
must be kept in the policy store. Also move the FC_TMPL unlink() closer
to where the FC_TMPL is created; not a functional change, but eaiser to
follow.

Signed-off-by: Steve Lawrence <slawrence@tresys.com>
Acked-by:  Stephen Smalley <sds@tycho.nsa.gov>
2015-09-03 15:41:38 -04:00
Steve Lawrence
75dd8c062d libsemanage: save homedir_template in the policy store for genhomedircon
We don't currently store homedir_template in the policy store, which
means genhomedircon only has a template file to use if the
homedir_template was generated from the file contexts in the same
transaction.  But homedir_template isn't always generated, as in the
case with setsebool -P. In this and other cases, genhomedircon will not
have a template file resulting in an empty file_contexts.homedir file.

This commit changes this so that homedir_template is always stored in
the policy store so it can be used by genhomedircon regardless of how
policy was built. Also add the homedir_template file to the migration
script.

Signed-off by: Steve Lawrence <slawrence@tresys.com>
Acked-by:  Stephen Smalley <sds@tycho.nsa.gov>
2015-09-03 15:41:36 -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
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
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
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
de41db98e4 Updated libsemanage ChangeLog.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2015-07-06 11:08:33 -04:00
Yuli Khodorkovskiy
9638af24a1 libsemanage: Add policy binary and file_contexts.local to the store
This patch writes policy.kern and file_contexts.local to the policy store as
well as /etc/selinux/. Additionally, policy.kern and file_contexts.local
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.

This patch also renames /var/lib/selinux/tmp to 'final' and changes
policy.kern in the store to longer be a symlink.

Signed-off-by: Yuli Khodorkovskiy <ykhodorkovskiy@tresys.com>
2015-07-06 11:05:22 -04:00
Steve Lawrence
eda59e2777 Update libsemanage ChangeLog 2015-06-24 12:35:07 -04:00
Petr Lautrbach
b9124ecddb Allow to use compressed modules without a compression extension
When a compressed module doesn't have two extensions with lang and
compression, 'semodule -i <module>.<lang>' fails. This changes the
language detection to allow to use modules only with .<lang>
extension.

Fixes:
libsemanage.semanage_direct_install_file: Module does not have a valid
extension. (No such file or directory).

Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
Acked-by: Steve Lawrence <slawrence@tresys.com>
2015-06-24 12:26:52 -04:00
Steve Lawrence
ef1637b55c Update libsemanage ChangeLog 2015-04-23 08:35:39 -04:00
Jason Zaman
f5c226810d libsemanage: do not copy contexts in semanage_migrate_store
The modules from the old store were previously copied to the new one
using setfscreatecon and shutil.copy2(). Now that refpolicy has rules
about the new policy location[1], copying the contexts is redundant.

More importantly, the setcreatefscon caused a constraint violation[2]
which made the migration fail. In python3, shutil.copy2() copies xattrs
as well which again causes problems. shutil.copy() is enough for our
needs here as it will copy the file and permissions in both py2 and 3.
We do not need the extra things that copy2() does (mtime, xattr, etc).

[1] http://oss.tresys.com/pipermail/refpolicy/2014-December/007511.html

[2]
type=AVC msg=audit(1429438272.872:1869): avc:  denied  { create } for  pid=28739 comm="semanage_migrat" name="strict" scontext=staff_u:sysadm_r:semanage_t tcontext=system_u:object_r:semanage_store_t tclass=dir permissive=0
	constrain dir { create relabelfrom relabelto } ((u1 == u2 -Fail-)  or (t1 == can_change_object_identity -Fail-) ); Constraint DENIED
allow semanage_t semanage_store_t:dir create;

Signed-off-by: Jason Zaman <jason@perfinion.com>
Acked-by: Steve Lawrence <slawrence@tresys.com>

Changes from v1:
 - Changed some methods to not take a src param anymore.
2015-04-23 08:35:39 -04:00
Steve Lawrence
de4f82bb7f Move ChangeLog entry to the correct project 2015-04-21 08:49:32 -04:00
Steve Lawrence
6f79e5ed9e Update libselinux ChangeLog 2015-04-21 08:21:17 -04:00
Stephen Smalley
072bb765a1 Update libsemanage ChangeLog.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2015-03-19 13:02:52 -04:00
Thomas Hurd
a4e290e425 libsemanage: Fix logic in bunzip for uncompressed pp files
Unconditionally check the magic number before BZ2_bzReadOpen()
instead of only when bzip_blocksize=0, since it falls through.
That way if the file is not compressed it will return immediately
and map_file can mmap it. If the file is compressed then it will
go through the BZ2 functions and any errors will be reported correctly.

This fixes 0afd5de5c1 so that a bz2 error
isn't reported when a uncompressed pp is installed successfully.

Signed-off-by: Thomas Hurd <thurd@tresys.com>
2015-03-19 13:01:11 -04:00
Stephen Smalley
3057bcf6a0 Update ChangeLogs.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2015-03-18 08:37:10 -04:00
Petr Lautrbach
b6d5805c7a libsemanage: fix fname[] initialization in test_utilities.c
There's no guaranty that last item in "char fname[]" will be a null character.
Fixes segfault on some systems:

  Test: semanage_nc_sort ...passedtest_semanage_findval: : Invalid argument
libsemanage-tests: TestRun.c:160: CU_assertImplementation: Assertion `((void *)0) != f_pCurTest' failed.
make[1]: *** [test] Aborted (core dumped)

Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2015-03-18 08:16:04 -04:00
Steve Lawrence
8a9978727d libsemanage: use the new CIL API
- Do not pass in the policydb where not necessary
- Tell CIL what policy version and target platform to use when building
  the policydb

Signed-off-by: Steve Lawrence <slawrence@tresys.com>
2015-02-27 08:58:52 -05:00
Steve Lawrence
13d502d5f1 Update libsemanage ChangeLog 2015-02-27 08:45:21 -05:00
Yuli Khodorkovskiy
432077b4dd libsemanage: Fix memory leaks when parsing semanage.conf
- Free args as they are parsed and strdup args when neccessary. Memory used for
  lex initialization is now freed using yylex_destroy().
- Add noyywrap option to flex. This is the correct way to make the scanner
  not call yywrap upon an end of file. Before, we were overriding the
  function and returning 1.

Signed-off-by: Yuli Khodorkovskiy <ykhodorkovskiy@tresys.com>
Acked-by: Steve Lawrence <slawrence@tresys.com>
2015-02-27 08:42:09 -05:00
Yuli Khodorkovskiy
057197c69a libsemanage: Add option to remove HLL files after compilation
This adds a 'remove-hll' option to semanage.conf. If set to 'true', all
HLL files will be removed from the SELinux store after successfully
buildling the SELinux modules. The default for this option is 'false'.

In order to delete already compiled HLL files, the modules need to be
recompiled with the ignore-module-cache option.

Signed-off-by: Yuli Khodorkovskiy <ykhodorkovskiy@tresys.com>
Acked-by: Steve Lawrence <slawrence@tresys.com>
2015-02-27 08:41:59 -05:00
Steve Lawrence
65ed279322 Update libsemanage ChangeLog 2015-02-26 11:24:07 -05:00
Thomas Hurd
0afd5de5c1 libsemanage: Change bunzip to use heap instead of stack for buffer.
Fixes segfault on systems with less than 256K stack size.
After change, I was able to run semodule -l with a 32K stack size.
Additionally, fix potential memory leak on realloc failure.

Signed-off-by: Thomas Hurd <thurd@tresys.com>
Acked-by: Steve Lawrence <slawrence@tresys.com>
2015-02-26 11:15:51 -05:00
Steve Lawrence
f0c9966f88 Bump to final release 2015-02-02 09:38:10 -05:00
Steve Lawrence
823ebc8c6b Bump to release candidate 7 2014-12-03 10:06:26 -05:00
Steve Lawrence
f21b2e138c libsemanage: ensure migrated files have the correct types
All files in /var/lib/selinux/ are now labeled the same as those in
/etc/selinux/<store>/modules/active, which in refpolicy is semanage_store_t.

Signed-off-by: Steve Lawrence <slawrence@tresys.com>
Reviewed-by: Yuli Khodorkovskiy <ykhodorkovskiy@tresys.com>
2014-12-03 10:05:25 -05:00
Steve Lawrence
b817a523c4 libsemanage: close hll file descriptors
Stops leaking of file descriptors to things like load_policy and
setfiles.

Reported-by: Sven Vermeulen <sven.vermeulen@siphos.be>
Signed-off-by: Steve Lawrence <slawrence@tresys.com>
Reviewed-by: Yuli Khodorkovskiy <ykhodorkovskiy@tresys.com>
2014-12-03 10:05:24 -05:00
Jason Zaman
877acdb31f semanage_migrate_store: Python3 support
Mainly used the 2to3 conversion tool. Also added in a __future__
import so that the script continues to work on Python 2.

Tested on 2.7, 3.3, 3.4. Should work on 2.6 too but untested.

Signed-off-by: Jason Zaman <jason@perfinion.com>
Acked-by: Steve Lawrence <slawrence@tresys.com>
2014-11-20 09:59:11 -05:00
Steve Lawrence
07e75a9cc7 Bump to release candidate 6 2014-11-12 08:30:15 -05:00
Steve Lawrence
d1db56c52b Bump to release candidate 5 2014-10-29 11:01:03 -04:00
Steve Lawrence
dee40ec1f8 libsemanage: install to LIBDIR instead of SHLIBDIR
The libsemanage Makefile currently installs libsemanage.so.1 into
SHLIBDIR, but links libsemanage.so to libsemanage.so.1 in LIBDIR. This
means things will only work if SHLIBDIR and LIBDIR are the same.
Fortunately, by default, they are the same because the default of
SHLIBDIR is set to PREFIX/lib (same as LIBDIR default) instead of the
standard DESTDIR/lib.  Unfortunately, if a user overrides SHLIBDIR, by
doing something like the following:

    make DESTDIR=~/tmp/ LIBDIR=~/tmp/usr/lib SHLIBDIR=~/tmp/lib install

then a broken symlink is created. Note that in some cases this may still
work even when SHLIBDIR and LIBDIR are not the same, e.g.:

    make LIBDIR=/usr/lib64 SHLIBDIR=/lib64 install

But this only works because, in systems like Fedora, /lib is a symlink
to /usr/lib, so SHLIBDIR and LIBDIR are the same even though it doesn't
immediately look like it.

This patch changes the libsemanage Makefile to set the default value of
SHLIBDIR to the standard DESTDIR/lib to prevent confusion, and installs
libsemanage to LIBDIR and completely ignores SHLIBDIR.

Signed-off-by: Steve Lawrence <slawrence@tresys.com>
2014-10-22 08:22:56 -04:00
Steve Lawrence
6280387034 Bump to release candidate 4 2014-10-06 15:03:24 -04:00
Steve Lawrence
ff5bbe6dcf Bump VERSION/ChangeLog for release candidate 3
Signed-off-by: Steve Lawrence <slawrence@tresys.com>
2014-10-02 10:16:34 -04:00
Nicolas Iooss
c4a4a1a7ed Fix gcc -Wstrict-prototypes warnings
In C, defining a function with () means "any number of parameters", not
"no parameter".  Use (void) instead where applicable and add unused
parameters when needed.

Acked-by: Steve Lawrence <slawrence@tresys.com>
2014-10-02 09:56:38 -04:00