1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2016, 2017 Ricardo Wurmus <rekado@elephly.net>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (gnu packages selinux)
20 #:use-module ((guix licenses) #:prefix license:)
21 #:use-module (guix packages)
22 #:use-module (guix download)
23 #:use-module (guix utils)
24 #:use-module (guix build-system gnu)
25 #:use-module (guix build-system python)
26 #:use-module (gnu packages)
27 #:use-module (gnu packages admin)
28 #:use-module (gnu packages bison)
29 #:use-module (gnu packages docbook)
30 #:use-module (gnu packages flex)
31 #:use-module (gnu packages gettext)
32 #:use-module (gnu packages glib)
33 #:use-module (gnu packages linux)
34 #:use-module (gnu packages networking)
35 #:use-module (gnu packages pcre)
36 #:use-module (gnu packages pkg-config)
37 #:use-module (gnu packages python)
38 #:use-module (gnu packages swig)
39 #:use-module (gnu packages textutils)
40 #:use-module (gnu packages xml))
42 ;; Update the SELinux packages together!
44 (define-public libsepol
48 (source (let ((release "20161014"))
51 (uri (string-append "https://github.com/SELinuxProject/selinux/"
52 "archive/" release ".tar.gz"))
53 (file-name (string-append "selinux-" release ".tar.gz"))
56 "1dpwynfb6n31928343blac4159g4jbrwxdp61q5yffmxpy3c3czi")))))
57 (build-system gnu-build-system)
59 `(#:tests? #f ; tests require checkpolicy, which requires libsepol
62 (let ((out (assoc-ref %outputs "out")))
63 (list (string-append "PREFIX=" out)
64 (string-append "DESTDIR=" out)
65 (string-append "MAN3DIR=" out "/share/man/man3")
66 (string-append "MAN5DIR=" out "/share/man/man5")
67 (string-append "MAN8DIR=" out "/share/man/man8")
68 (string-append "LDFLAGS=-Wl,-rpath=" out "/lib")
71 (modify-phases %standard-phases
73 (add-after 'unpack 'enter-dir
74 (lambda _ (chdir ,name) #t)))))
77 (home-page "https://selinuxproject.org/")
78 (synopsis "Library for manipulating SELinux policies")
80 "The libsepol library provides an API for the manipulation of SELinux
81 binary policies. It is used by @code{checkpolicy} (the policy compiler) and
82 similar tools, and programs such as @code{load_policy}, which must perform
83 specific transformations on binary policies (for example, customizing policy
85 (license license:lgpl2.1+)))
87 (define-public checkpolicy
88 (package (inherit libsepol)
91 `(#:tests? #f ; there is no check target
93 (let ((out (assoc-ref %outputs "out")))
94 (list (string-append "PREFIX=" out)
95 (string-append "LDLIBS="
96 (assoc-ref %build-inputs "libsepol")
98 (assoc-ref %build-inputs "flex")
102 (modify-phases %standard-phases
104 (add-after 'unpack 'enter-dir
105 (lambda _ (chdir ,name) #t)))))
107 `(("libsepol" ,libsepol)))
111 (synopsis "Check SELinux security policy configurations and modules")
113 "This package provides the tools \"checkpolicy\" and \"checkmodule\".
114 Checkpolicy is a program that checks and compiles a SELinux security policy
115 configuration into a binary representation that can be loaded into the kernel.
116 Checkmodule is a program that checks and compiles a SELinux security policy
117 module into a binary representation.")
119 (license license:gpl2)))
121 (define-public libselinux
122 (package (inherit libsepol)
125 (substitute-keyword-arguments (package-arguments libsepol)
126 ((#:make-flags flags)
127 `(cons* "PYTHON=python3"
128 (string-append "PYSITEDIR="
129 (assoc-ref %outputs "out")
131 ,(version-major+minor (package-version python))
135 `(modify-phases ,phases
137 (lambda _ (chdir ,name) #t))
138 ;; libsepol.a is not located in this package's LIBDIR.
139 (add-after 'enter-dir 'patch-libsepol-path
140 (lambda* (#:key inputs #:allow-other-keys)
141 (substitute* "src/Makefile"
142 (("\\$\\(LIBDIR\\)/libsepol.a")
143 (string-append (assoc-ref inputs "libsepol")
146 (add-after 'enter-dir 'remove-Werror
148 ;; GCC complains about the fact that the output does not (yet)
149 ;; have an "include" directory, even though it is referenced.
150 (substitute* '("src/Makefile"
154 (add-after 'build 'pywrap
155 (lambda* (#:key make-flags #:allow-other-keys)
156 (zero? (apply system* "make" "pywrap" make-flags))))
157 (add-after 'install 'install-pywrap
158 (lambda* (#:key make-flags #:allow-other-keys)
159 (zero? (apply system* "make" "install-pywrap" make-flags))))))))
160 ;; These libraries are in "Requires.private" in libselinux.pc.
162 `(("libsepol" ,libsepol)
166 `(("python" ,python-wrapper)))
167 ;; These inputs are only needed for the pywrap phase.
170 ("pkg-config" ,pkg-config)))
171 (synopsis "SELinux core libraries and utilities")
173 "The libselinux library provides an API for SELinux applications to get
174 and set process and file security contexts, and to obtain security policy
175 decisions. It is required for any applications that use the SELinux API, and
176 used by all applications that are SELinux-aware. This package also includes
177 the core SELinux management utilities.")
178 (license license:public-domain)))
180 (define-public libsemanage
181 (package (inherit libsepol)
184 (substitute-keyword-arguments (package-arguments libsepol)
185 ((#:make-flags flags)
186 `(cons* "PYTHON=python3"
187 (string-append "PYSITEDIR="
188 (assoc-ref %outputs "out")
190 ,(version-major+minor (package-version python))
194 `(modify-phases ,phases
196 (lambda _ (chdir ,name) #t))
197 (add-after 'build 'pywrap
198 (lambda* (#:key make-flags #:allow-other-keys)
199 (zero? (apply system* "make" "pywrap" make-flags))))
200 (add-after 'install 'install-pywrap
201 (lambda* (#:key make-flags #:allow-other-keys)
202 (zero? (apply system* "make" "install-pywrap" make-flags))))))))
204 `(("libsepol" ,libsepol)
205 ("libselinux" ,libselinux)
209 ("python" ,python-wrapper)))
215 ("pkg-config" ,pkg-config)))
216 (synopsis "SELinux policy management libraries")
218 "The libsemanage library provides an API for the manipulation of SELinux
220 (license license:lgpl2.1+)))
222 (define-public secilc
223 (package (inherit libsepol)
226 (substitute-keyword-arguments (package-arguments libsepol)
227 ((#:make-flags flags)
228 `(let ((docbook (assoc-ref %build-inputs "docbook-xsl")))
229 (cons (string-append "XMLTO=xmlto --skip-validation -x "
230 docbook "/xml/xsl/docbook-xsl-"
231 ,(package-version docbook-xsl)
232 "/manpages/docbook.xsl")
235 `(modify-phases ,phases
237 (lambda _ (chdir ,name) #t))))))
239 `(("libsepol" ,libsepol)))
242 ("docbook-xsl" ,docbook-xsl)))
243 (synopsis "SELinux common intermediate language (CIL) compiler")
244 (description "The SELinux CIL compiler is a compiler that converts the
245 @dfn{common intermediate language} (CIL) into a kernel binary policy file.")
246 (license license:bsd-2)))
248 (define-public python-sepolgen
249 (package (inherit libsepol)
250 (name "python-sepolgen")
252 `(#:modules ((srfi srfi-1)
253 (guix build gnu-build-system)
255 ,@(substitute-keyword-arguments (package-arguments libsepol)
257 `(modify-phases ,phases
259 (lambda _ (chdir "sepolgen") #t))
260 ;; By default all Python files would be installed to
261 ;; $out/gnu/store/...-python-.../, so we override the
262 ;; PACKAGEDIR to fix this.
263 (add-after 'enter-dir 'fix-target-path
264 (lambda* (#:key inputs outputs #:allow-other-keys)
265 (let ((get-python-version
266 ;; FIXME: copied from python-build-system
268 (let* ((version (last (string-split python #\-)))
269 (components (string-split version #\.))
270 (major+minor (take components 2)))
271 (string-join major+minor ".")))))
272 (substitute* "src/sepolgen/Makefile"
274 (string-append "PACKAGEDIR="
275 (assoc-ref outputs "out")
278 (assoc-ref inputs "python"))
279 "/site-packages/sepolgen")))
280 (substitute* "src/share/Makefile"
281 (("\\$\\(DESTDIR\\)") (assoc-ref outputs "out"))))
284 `(("python" ,python-wrapper)))
286 (synopsis "Python module for generating SELinux policies")
288 "This package contains a Python module that forms the core of
289 @code{audit2allow}, a part of the package @code{policycoreutils}. The
290 sepolgen library contains: Reference Policy Representation, which are Objects
291 for representing policies and the reference policy interfaces. It has objects
292 and algorithms for representing access and sets of access in an abstract way
293 and searching that access. It also has a parser for reference policy
294 \"headers\". It contains infrastructure for parsing SELinux related messages
295 as produced by the audit system. It has facilities for generating policy
296 based on required access.")
298 (license license:gpl2)))
300 ;; The latest 4.1.x version does not work with the latest 2.6 release of
301 ;; policycoreutils, so we use the last 4.0.x release.
302 (define-public python-setools
304 (name "python-setools")
308 (uri (string-append "https://github.com/TresysTechnology/"
309 "setools/archive/" version ".tar.gz"))
310 (file-name (string-append name "-" version ".tar.gz"))
313 "1zndpl4ck5c23p7s4sci06db89q1w87jig3jbd4f8s1ggy3lj82c"))))
314 (build-system python-build-system)
316 `(#:tests? #f ; the test target causes a rebuild
318 (modify-phases %standard-phases
319 (add-after 'unpack 'set-SEPOL-variable
320 (lambda* (#:key inputs #:allow-other-keys)
322 (string-append (assoc-ref inputs "libsepol")
323 "/lib/libsepol.a"))))
324 (add-after 'unpack 'remove-Werror
326 (substitute* "setup.py"
329 (add-after 'unpack 'fix-target-paths
330 (lambda* (#:key outputs #:allow-other-keys)
331 (substitute* "setup.py"
332 (("join\\(sys.prefix")
333 (string-append "join(\"" (assoc-ref outputs "out") "/\"")))
336 `(("python-networkx" ,python-networkx)))
338 `(("libsepol" ,libsepol)
339 ("libselinux" ,libselinux)))
344 (home-page "https://github.com/TresysTechnology/setools")
345 (synopsis "Tools for SELinux policy analysis")
346 (description "SETools is a collection of graphical tools, command-line
347 tools, and libraries designed to facilitate SELinux policy analysis.")
348 ;; Some programs are under GPL, all libraries under LGPL.
349 (license (list license:lgpl2.1+
352 (define-public policycoreutils
353 (package (inherit libsepol)
354 (name "policycoreutils")
356 (origin (inherit (package-source libsepol))
357 (patches (search-patches "policycoreutils-make-sepolicy-use-python3.patch"))
358 (patch-flags '("-p1" "-d" "policycoreutils"))))
360 `(#:test-target "test"
362 (let ((out (assoc-ref %outputs "out")))
364 (string-append "PREFIX=" out)
365 (string-append "LOCALEDIR=" out "/share/locale")
366 (string-append "BASHCOMPLETIONDIR=" out
367 "/share/bash-completion/completions")
368 "INSTALL=install -c -p"
369 "INSTALL_DIR=install -d"
370 ;; These ones are needed because some Makefiles define the
371 ;; directories relative to DESTDIR, not relative to PREFIX.
372 (string-append "SBINDIR=" out "/sbin")
373 (string-append "ETCDIR=" out "/etc")
374 (string-append "SYSCONFDIR=" out "/etc/sysconfig")
375 (string-append "MAN5DIR=" out "/share/man/man5")
376 (string-append "INSTALL_NLS_DIR=" out "/share/locale")
377 (string-append "AUTOSTARTDIR=" out "/etc/xdg/autostart")
378 (string-append "DBUSSERVICEDIR=" out "/share/dbus-1/services")
379 (string-append "SYSTEMDDIR=" out "/lib/systemd")
380 (string-append "INITDIR=" out "/etc/rc.d/init.d")
381 (string-append "SELINUXDIR=" out "/etc/selinux")))
383 (modify-phases %standard-phases
385 (add-after 'unpack 'enter-dir
386 (lambda _ (chdir ,name) #t))
387 (add-after 'enter-dir 'ignore-/usr-tests
388 (lambda* (#:key inputs #:allow-other-keys)
389 ;; The Makefile decides to build restorecond only if it finds the
390 ;; inotify header somewhere under /usr.
391 (substitute* "Makefile"
394 ;; Rewrite lookup paths for header files.
395 (substitute* '("newrole/Makefile"
398 (("/usr(/include/security/pam_appl.h)" _ file)
399 (string-append (assoc-ref inputs "pam") file))
400 (("/usr(/include/libaudit.h)" _ file)
401 (string-append (assoc-ref inputs "audit") file)))
403 (add-after 'enter-dir 'fix-glib-cflags
404 (lambda* (#:key inputs #:allow-other-keys)
405 (substitute* "restorecond/Makefile"
406 (("/usr(/include/glib-2.0|/lib/glib-2.0/include)" _ path)
407 (string-append (assoc-ref inputs "glib") path))
408 (("/usr(/include/dbus-1.0|/lib/dbus-1.0/include)" _ path)
409 (string-append (assoc-ref inputs "dbus") path
411 (assoc-ref inputs "dbus-glib") path)))
413 (add-after 'enter-dir 'fix-linkage-with-libsepol
414 (lambda* (#:key inputs #:allow-other-keys)
415 (substitute* '("semodule_deps/Makefile"
416 "sepolgen-ifgen/Makefile")
418 (string-append (assoc-ref inputs "libsepol") "/lib/")))))
419 (add-after 'enter-dir 'fix-target-paths
420 (lambda* (#:key outputs #:allow-other-keys)
421 (let ((out (assoc-ref outputs "out")))
422 (substitute* "audit2allow/sepolgen-ifgen"
423 (("ATTR_HELPER = \"/usr/bin/sepolgen-ifgen-attr-helper\"")
424 (string-append "ATTR_HELPER = \"" out
425 "/bin/sepolgen-ifgen-attr-helper\"")))
426 (substitute* "sepolicy/sepolicy/__init__.py"
427 (("/usr/bin/sepolgen-ifgen")
428 (string-append out "/bin/sepolgen-ifgen")))
429 (substitute* "sepolicy/Makefile"
430 ;; By default all Python files would be installed to
431 ;; $out/gnu/store/...-python-.../.
432 (("setup.py install.*$")
433 (string-append "setup.py install --prefix=" out "\n"))
434 (("\\$\\(DESTDIR\\)/etc")
435 (string-append out "/etc"))
436 (("\\$\\(DESTDIR\\)/usr") out)))
438 (add-after 'install 'wrap-python-tools
439 (lambda* (#:key outputs #:allow-other-keys)
440 (let* ((out (assoc-ref outputs "out"))
441 (var (string-append out "/lib/python"
442 ,(version-major+minor (package-version python))
444 (getenv "PYTHONPATH"))))
445 ;; The scripts' shebangs tell Python to ignore the PYTHONPATH,
446 ;; so we need to patch them before wrapping.
447 (for-each (lambda (file)
448 (let ((path (string-append out "/" file)))
450 (("bin/python -Es") "bin/python -s"))
452 `("PYTHONPATH" ":" prefix (,var)))))
461 `(("python" ,python-wrapper)
464 ("libsepol" ,libsepol)
465 ("libselinux" ,libselinux)
466 ("libsemanage" ,libsemanage)
467 ("python-sepolgen" ,python-sepolgen)
468 ("python-setools" ,python-setools)
469 ("python-ipy" ,python-ipy)
470 ("libcap-ng" ,libcap-ng)
473 ("dbus-glib" ,dbus-glib)
476 `(("gettext" ,gettext-minimal)))
477 (synopsis "SELinux core utilities")
478 (description "The policycoreutils package contains the core utilities that
479 are required for the basic operation of an SELinux-enabled GNU system and its
480 policies. These utilities include @code{load_policy} to load policies,
481 @code{setfiles} to label file systems, @code{newrole} to switch roles, and
482 @code{run_init} to run service scripts in their proper context.")
483 (license license:gpl2+)))