Commit Graph

19 Commits

Author SHA1 Message Date
Nicolas Iooss b550c0e202
Fix many misspellings
Use codespell (https://github.com/codespell-project/codespell) in order
to find many common misspellings that are present in English texts.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2019-09-18 22:47:35 +02:00
Vit Mojzis 2ff0fbffcf Revert "mcstransd select correct colour range."
This reverts commit fe17b3d2d9.

MLS ranges should be compared based on dominance.

This fixes mlscolor-test on mcstrans examples.

Eg. mlscolor-test using /usr/share/mcstrans/examples/urcsts when executed on mls
machine fails as follows:

\#pushd /usr/share/mcstrans/examples/urcsts
\#cp -f secolor.conf /etc/selinux/mls/secolor.conf
\#cp -f setrans.conf /etc/selinux/mls/setrans.conf
\#systemctl restart mcstransd
\#python3 /usr/share/mcstrans/util/mlscolor-test urcsts.color
For 'system_u:system_r:inetd_t:SystemLow' got
	'#000000 #000000 #000000 #000000 #000000 #000000 #000000 #000000' expected
	'#000000 #000000 #000000 #000000 #000000 #000000 #000000 #008000'
...
mlscolor-test done with 19 errors

Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
2019-09-16 15:43:24 -04:00
Laurent Bigonville 5a5e739e5e Add documentation key in systemd .service files
Signed-off-by: Laurent Bigonville <bigon@bigon.be>
2019-07-18 09:51:43 -05:00
Petr Lautrbach 8a8a4f8e05 mcstrans: Fix check in raw_color()
raw_color() uses color_str as an output argument which is assigned to a new
allocated memory. Therefore it should fail when color_str is null; or
when *color_str is not null in order to avoid a memory leak.

Fixes:
>>> selinux.selinux_raw_context_to_color('system_u:system_r:inetd_t:s0')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 0] Error

Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2018-12-20 15:13:12 +01:00
Yuli Khodorkovskiy 95b3552451 mcstrans: remove unused getpeercon_raw() call
There is a call to getpeercon_raw() in mcstransd, but nothing is done
with the context. The purpose of process_request() is to translate a
context and we would like that to succeed even if, for some reason,
getpeercon_raw() fails.

Signed-off-by: Yuli Khodorkovskiy <yuli@crunchydata.com>
Signed-off-by: Joshua Brindle <joshua.brindle@crunchydata.com>
2018-10-26 09:53:11 -04:00
Nicolas Iooss d0ca433e21
mcstrans: fix memory leaks reported by clang's static analyzer
There are many memory leaks in mcstrans. Clean them up in order to
reduce the noise in clang's static analyzer report. Some are remaining,
because they are more complex to fix.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2018-07-04 22:09:06 +02:00
Marcus Folkesson fc7a4e0798 mcstrans: build: follow standard semantics for DESTDIR and PREFIX
Signed-off-by: Marcus Folkesson <marcus.folkesson@gmail.com>
2018-02-14 15:59:38 +01:00
Petr Lautrbach 43c0d1f889 mcstrans: Allow overriding libsepol.a location during build
Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2017-06-23 08:15:40 -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
Nicolas Iooss 6305bfbc00 mcstrans: do not dereference color_str if it is NULL
This bug has been found using clang static analyzer.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-03-01 10:42:39 -05:00
Nicolas Iooss 0df0b25d95 mcstrans: fix -Wwrite-strings warnings
Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-02-06 11:05:52 -05:00
Nicolas Iooss c667b33a04 mcstransd: fix and reorder includes
- Sort included header files by their number of path components then
  alphabetically.
- Include unistd.h and sys/types.h only once.
- Include sys/uio.h to get readv() and writev() declarations when
  compiling with musl libc.
- Include poll.h instead of sys/poll.h as building with musl results in
  the following message:

    /usr/lib/musl/include/sys/poll.h:1:2: error: #warning redirecting
    incorrect #include <sys/poll.h> to <poll.h> [-Werror=cpp]
     #warning redirecting incorrect #include <sys/poll.h> to <poll.h>
     ^~~~~~~

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2017-01-09 16:00:28 -05:00
Nicolas Iooss a441d51011 mcstrans: fix global "make install"
When running "make install" in the root directory of the project, with
variable DESTDIR set and while being on a system without SELinux, the
compiler complains while building:

    fatal error: selinux/selinux.h: No such file or directory

Other subdirectories add -I$(PREFIX)/include to CFLAGS and -L$(LIBDIR)
to the linking command line, in order to find libselinux headers and .so
file. Do this too in mcstrans.

While at it, mcstrans Makefile uses -I../include but this directory does
not exist. Remove this option.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
2016-11-17 16:49:24 -05:00
Stephen Smalley 07ba7c6853 mcstrans: Fix signed/unsigned warnings
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-11-16 14:54:28 -05:00
Jason Zaman 089000ad1c mcstrans: take LIBDIR from args, dont guess
All the other makefiles just have LIBDIR optionally set so it can be
overridden. These makefiles were autodetecting incorrectly. uname -i
returns "GenuineIntel" so should have been uname -m.

Signed-off-by: Jason Zaman <jason@perfinion.com>
2016-11-16 11:20:05 -05:00
Jason Zaman 30cbe52c5b mcstrans: Fix Werror=shadow errors
gcc -g3 -O0 -gdwarf-2 -fno-strict-aliasing -Wall -Wshadow -Werror -I../include -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -fPIE -c -o mcstrans.o mcstrans.c
mcstrans.c: In function ‘violates_constraints’:
mcstrans.c:551:14: error: declaration of ‘common’ shadows a previous local [-Werror=shadow]
    ebitmap_t common;
              ^
mcstrans.c:545:13: error: shadowed declaration is here [-Werror=shadow]
   ebitmap_t common;
             ^
mcstrans.c: In function ‘build_regexps’:
mcstrans.c:1048:7: error: declaration of ‘i’ shadows a previous local [-Werror=shadow]
   int i=0;
       ^
mcstrans.c:993:15: error: shadowed declaration is here [-Werror=shadow]
  size_t n_el, i;
               ^
mcstrans.c: In function ‘compute_raw_from_trans’:
mcstrans.c:1166:9: error: declaration of ‘rc’ shadows a previous local [-Werror=shadow]
     int rc = pcre_exec(g->prefix_regexp, 0, work, work_len, 0, 0, ovector, OVECCOUNT);
         ^
mcstrans.c:1123:6: error: shadowed declaration is here [-Werror=shadow]
  int rc = pcre_exec(domain->base_classification_regexp, 0, work, work_len, 0, PCRE_ANCHORED, ovector, OVECCOUNT);
      ^
mcstrans.c:1174:9: error: declaration of ‘rc’ shadows a previous local [-Werror=shadow]
     int rc = pcre_exec(g->suffix_regexp, 0, work, work_len, 0, 0, ovector, OVECCOUNT);
         ^
mcstrans.c:1123:6: error: shadowed declaration is here [-Werror=shadow]
  int rc = pcre_exec(domain->base_classification_regexp, 0, work, work_len, 0, PCRE_ANCHORED, ovector, OVECCOUNT);
      ^
mcstrans.c:1189:9: error: declaration of ‘rc’ shadows a previous local [-Werror=shadow]
     int rc = pcre_exec(g->word_regexp, 0, s, l, 0, 0, ovector, OVECCOUNT);
         ^
mcstrans.c:1123:6: error: shadowed declaration is here [-Werror=shadow]
  int rc = pcre_exec(domain->base_classification_regexp, 0, work, work_len, 0, PCRE_ANCHORED, ovector, OVECCOUNT);
      ^
mcstrans.c: In function ‘compute_trans_from_raw’:
mcstrans.c:1328:14: error: declaration of ‘unhandled’ shadows a previous local [-Werror=shadow]
    ebitmap_t unhandled, orig_unhandled;
              ^
mcstrans.c:1291:49: error: shadowed declaration is here [-Werror=shadow]
  ebitmap_t bit_diff, temp, handled, nothandled, unhandled, orig_unhandled;
                                                 ^
mcstrans.c:1328:25: error: declaration of ‘orig_unhandled’ shadows a previous local [-Werror=shadow]
    ebitmap_t unhandled, orig_unhandled;
                         ^
mcstrans.c:1291:60: error: shadowed declaration is here [-Werror=shadow]
  ebitmap_t bit_diff, temp, handled, nothandled, unhandled, orig_unhandled;
                                                            ^
mcstrans.c:1360:15: error: declaration of ‘handled’ shadows a previous local [-Werror=shadow]
     ebitmap_t handled, nothandled;
               ^
mcstrans.c:1291:28: error: shadowed declaration is here [-Werror=shadow]
  ebitmap_t bit_diff, temp, handled, nothandled, unhandled, orig_unhandled;
                            ^
mcstrans.c:1360:24: error: declaration of ‘nothandled’ shadows a previous local [-Werror=shadow]
     ebitmap_t handled, nothandled;
                        ^
mcstrans.c:1291:37: error: shadowed declaration is here [-Werror=shadow]
  ebitmap_t bit_diff, temp, handled, nothandled, unhandled, orig_unhandled;
                                     ^
mcstrans.c:1377:17: error: declaration of ‘temp’ shadows a previous local [-Werror=shadow]
       ebitmap_t temp;
                 ^
mcstrans.c:1291:22: error: shadowed declaration is here [-Werror=shadow]
  ebitmap_t bit_diff, temp, handled, nothandled, unhandled, orig_unhandled;
                      ^
mcstrans.c:1378:17: error: declaration of ‘bit_diff’ shadows a previous local [-Werror=shadow]
       ebitmap_t bit_diff;
                 ^
mcstrans.c:1291:12: error: shadowed declaration is here [-Werror=shadow]
  ebitmap_t bit_diff, temp, handled, nothandled, unhandled, orig_unhandled;
            ^
mcstrans.c:1403:16: error: declaration of ‘bit_diff’ shadows a previous local [-Werror=shadow]
      ebitmap_t bit_diff;
                ^
mcstrans.c:1291:12: error: shadowed declaration is here [-Werror=shadow]
  ebitmap_t bit_diff, temp, handled, nothandled, unhandled, orig_unhandled;
            ^
mcstrans.c:1407:16: error: declaration of ‘temp’ shadows a previous local [-Werror=shadow]
      ebitmap_t temp;
                ^
mcstrans.c:1291:22: error: shadowed declaration is here [-Werror=shadow]
  ebitmap_t bit_diff, temp, handled, nothandled, unhandled, orig_unhandled;
                      ^
mcstrans.c:1434:19: error: declaration of ‘g’ shadows a previous local [-Werror=shadow]
     word_group_t *g;
                   ^
mcstrans.c:1335:18: error: shadowed declaration is here [-Werror=shadow]
    word_group_t *g;
                  ^
cc1: all warnings being treated as errors
Makefile:35: recipe for target 'mcstrans.o' failed
make[2]: *** [mcstrans.o] Error 1

Signed-off-by: Jason Zaman <jason@perfinion.com>
2016-11-16 11:20:05 -05:00
Stephen Smalley 6e4bb702af mcstrans: fix clang warnings
Fix the following warnings from clang.

mcstrans.c:1309:6: warning: variable 'groups' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
        if (violates_constraints(l)) {
            ^~~~~~~~~~~~~~~~~~~~~~~
mcstrans.c:1491:9: note: uninitialized use occurs here
        while (groups)
               ^~~~~~
mcstrans.c:1309:2: note: remove the 'if' if its condition is always false
        if (violates_constraints(l)) {
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mcstrans.c:1303:6: warning: variable 'groups' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
        if (!l)
            ^~
mcstrans.c:1491:9: note: uninitialized use occurs here
        while (groups)
               ^~~~~~
mcstrans.c:1303:2: note: remove the 'if' if its condition is always false
        if (!l)
        ^~~~~~~
mcstrans.c:1299:6: warning: variable 'groups' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
        if (!level)
            ^~~~~~
mcstrans.c:1491:9: note: uninitialized use occurs here
        while (groups)
               ^~~~~~
mcstrans.c:1299:2: note: remove the 'if' if its condition is always false
        if (!level)
        ^~~~~~~~~~~
mcstrans.c:1316:2: note: variable 'groups' is declared here
        word_group_t *groups = NULL;
        ^
3 warnings generated.
mcscolor.c:334:24: warning: size argument in 'strncat' call appears to be size of the source [-Wstrncat-size]
                strncat(result, buf, sizeof(buf));

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-11-16 11:19:51 -05:00
Stephen Smalley 233fe333f8 mcstrans: Add .gitignore file
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-11-16 11:19:50 -05:00
Stephen Smalley 4cc808671a Move policycoreutils/mcstrans to mcstrans.
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2016-11-16 11:19:50 -05:00