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))))))))
161 `(("libsepol" ,libsepol)
164 ("python" ,python-wrapper)))
165 ;; These inputs are only needed for the pywrap phase.
168 ("pkg-config" ,pkg-config)))
169 (synopsis "SELinux core libraries and utilities")
171 "The libselinux library provides an API for SELinux applications to get
172 and set process and file security contexts, and to obtain security policy
173 decisions. It is required for any applications that use the SELinux API, and
174 used by all applications that are SELinux-aware. This package also includes
175 the core SELinux management utilities.")
176 (license license:public-domain)))
178 (define-public libsemanage
179 (package (inherit libsepol)
182 (substitute-keyword-arguments (package-arguments libsepol)
183 ((#:make-flags flags)
184 `(cons* "PYTHON=python3"
185 (string-append "PYSITEDIR="
186 (assoc-ref %outputs "out")
188 ,(version-major+minor (package-version python))
192 `(modify-phases ,phases
194 (lambda _ (chdir ,name) #t))
195 (add-after 'build 'pywrap
196 (lambda* (#:key make-flags #:allow-other-keys)
197 (zero? (apply system* "make" "pywrap" make-flags))))
198 (add-after 'install 'install-pywrap
199 (lambda* (#:key make-flags #:allow-other-keys)
200 (zero? (apply system* "make" "install-pywrap" make-flags))))))))
202 `(("libsepol" ,libsepol)
203 ("libselinux" ,libselinux)
207 ("python" ,python-wrapper)))
213 ("pkg-config" ,pkg-config)))
214 (synopsis "SELinux policy management libraries")
216 "The libsemanage library provides an API for the manipulation of SELinux
218 (license license:lgpl2.1+)))
220 (define-public secilc
221 (package (inherit libsepol)
224 (substitute-keyword-arguments (package-arguments libsepol)
225 ((#:make-flags flags)
226 `(let ((docbook (assoc-ref %build-inputs "docbook-xsl")))
227 (cons (string-append "XMLTO=xmlto --skip-validation -x "
228 docbook "/xml/xsl/docbook-xsl-"
229 ,(package-version docbook-xsl)
230 "/manpages/docbook.xsl")
233 `(modify-phases ,phases
235 (lambda _ (chdir ,name) #t))))))
237 `(("libsepol" ,libsepol)))
240 ("docbook-xsl" ,docbook-xsl)))
241 (synopsis "SELinux common intermediate language (CIL) compiler")
242 (description "The SELinux CIL compiler is a compiler that converts the
243 @dfn{common intermediate language} (CIL) into a kernel binary policy file.")
244 (license license:bsd-2)))
246 (define-public python-sepolgen
247 (package (inherit libsepol)
248 (name "python-sepolgen")
250 `(#:modules ((srfi srfi-1)
251 (guix build gnu-build-system)
253 ,@(substitute-keyword-arguments (package-arguments libsepol)
255 `(modify-phases ,phases
257 (lambda _ (chdir "sepolgen") #t))
258 ;; By default all Python files would be installed to
259 ;; $out/gnu/store/...-python-.../, so we override the
260 ;; PACKAGEDIR to fix this.
261 (add-after 'enter-dir 'fix-target-path
262 (lambda* (#:key inputs outputs #:allow-other-keys)
263 (let ((get-python-version
264 ;; FIXME: copied from python-build-system
266 (let* ((version (last (string-split python #\-)))
267 (components (string-split version #\.))
268 (major+minor (take components 2)))
269 (string-join major+minor ".")))))
270 (substitute* "src/sepolgen/Makefile"
272 (string-append "PACKAGEDIR="
273 (assoc-ref outputs "out")
276 (assoc-ref inputs "python"))
277 "/site-packages/sepolgen")))
278 (substitute* "src/share/Makefile"
279 (("\\$\\(DESTDIR\\)") (assoc-ref outputs "out"))))
282 `(("python" ,python-wrapper)))
284 (synopsis "Python module for generating SELinux policies")
286 "This package contains a Python module that forms the core of
287 @code{audit2allow}, a part of the package @code{policycoreutils}. The
288 sepolgen library contains: Reference Policy Representation, which are Objects
289 for representing policies and the reference policy interfaces. It has objects
290 and algorithms for representing access and sets of access in an abstract way
291 and searching that access. It also has a parser for reference policy
292 \"headers\". It contains infrastructure for parsing SELinux related messages
293 as produced by the audit system. It has facilities for generating policy
294 based on required access.")
296 (license license:gpl2)))
298 ;; The latest 4.1.x version does not work with the latest 2.6 release of
299 ;; policycoreutils, so we use the last 4.0.x release.
300 (define-public python-setools
302 (name "python-setools")
306 (uri (string-append "https://github.com/TresysTechnology/"
307 "setools/archive/" version ".tar.gz"))
308 (file-name (string-append name "-" version ".tar.gz"))
311 "1zndpl4ck5c23p7s4sci06db89q1w87jig3jbd4f8s1ggy3lj82c"))))
312 (build-system python-build-system)
314 `(#:tests? #f ; the test target causes a rebuild
316 (modify-phases %standard-phases
317 (add-after 'unpack 'set-SEPOL-variable
318 (lambda* (#:key inputs #:allow-other-keys)
320 (string-append (assoc-ref inputs "libsepol")
321 "/lib/libsepol.a"))))
322 (add-after 'unpack 'remove-Werror
324 (substitute* "setup.py"
327 (add-after 'unpack 'fix-target-paths
328 (lambda* (#:key outputs #:allow-other-keys)
329 (substitute* "setup.py"
330 (("join\\(sys.prefix")
331 (string-append "join(\"" (assoc-ref outputs "out") "/\"")))
334 `(("python-networkx" ,python-networkx)))
336 `(("libsepol" ,libsepol)
337 ("libselinux" ,libselinux)))
342 (home-page "https://github.com/TresysTechnology/setools")
343 (synopsis "Tools for SELinux policy analysis")
344 (description "SETools is a collection of graphical tools, command-line
345 tools, and libraries designed to facilitate SELinux policy analysis.")
346 ;; Some programs are under GPL, all libraries under LGPL.
347 (license (list license:lgpl2.1+
350 (define-public policycoreutils
351 (package (inherit libsepol)
352 (name "policycoreutils")
354 (origin (inherit (package-source libsepol))
355 (patches (search-patches "policycoreutils-make-sepolicy-use-python3.patch"))
356 (patch-flags '("-p1" "-d" "policycoreutils"))))
358 `(#:test-target "test"
360 (let ((out (assoc-ref %outputs "out")))
362 (string-append "PREFIX=" out)
363 (string-append "LOCALEDIR=" out "/share/locale")
364 (string-append "BASHCOMPLETIONDIR=" out
365 "/share/bash-completion/completions")
366 "INSTALL=install -c -p"
367 "INSTALL_DIR=install -d"
368 ;; These ones are needed because some Makefiles define the
369 ;; directories relative to DESTDIR, not relative to PREFIX.
370 (string-append "SBINDIR=" out "/sbin")
371 (string-append "ETCDIR=" out "/etc")
372 (string-append "SYSCONFDIR=" out "/etc/sysconfig")
373 (string-append "MAN5DIR=" out "/share/man/man5")
374 (string-append "INSTALL_NLS_DIR=" out "/share/locale")
375 (string-append "AUTOSTARTDIR=" out "/etc/xdg/autostart")
376 (string-append "DBUSSERVICEDIR=" out "/share/dbus-1/services")
377 (string-append "SYSTEMDDIR=" out "/lib/systemd")
378 (string-append "INITDIR=" out "/etc/rc.d/init.d")
379 (string-append "SELINUXDIR=" out "/etc/selinux")))
381 (modify-phases %standard-phases
383 (add-after 'unpack 'enter-dir
384 (lambda _ (chdir ,name) #t))
385 (add-after 'enter-dir 'ignore-/usr-tests
386 (lambda* (#:key inputs #:allow-other-keys)
387 ;; The Makefile decides to build restorecond only if it finds the
388 ;; inotify header somewhere under /usr.
389 (substitute* "Makefile"
392 ;; Rewrite lookup paths for header files.
393 (substitute* '("newrole/Makefile"
396 (("/usr(/include/security/pam_appl.h)" _ file)
397 (string-append (assoc-ref inputs "pam") file))
398 (("/usr(/include/libaudit.h)" _ file)
399 (string-append (assoc-ref inputs "audit") file)))
401 (add-after 'enter-dir 'fix-glib-cflags
402 (lambda* (#:key inputs #:allow-other-keys)
403 (substitute* "restorecond/Makefile"
404 (("/usr(/include/glib-2.0|/lib/glib-2.0/include)" _ path)
405 (string-append (assoc-ref inputs "glib") path))
406 (("/usr(/include/dbus-1.0|/lib/dbus-1.0/include)" _ path)
407 (string-append (assoc-ref inputs "dbus") path
409 (assoc-ref inputs "dbus-glib") path)))
411 (add-after 'enter-dir 'fix-linkage-with-libsepol
412 (lambda* (#:key inputs #:allow-other-keys)
413 (substitute* '("semodule_deps/Makefile"
414 "sepolgen-ifgen/Makefile")
416 (string-append (assoc-ref inputs "libsepol") "/lib/")))))
417 (add-after 'enter-dir 'fix-target-paths
418 (lambda* (#:key outputs #:allow-other-keys)
419 (let ((out (assoc-ref outputs "out")))
420 (substitute* "audit2allow/sepolgen-ifgen"
421 (("ATTR_HELPER = \"/usr/bin/sepolgen-ifgen-attr-helper\"")
422 (string-append "ATTR_HELPER = \"" out
423 "/bin/sepolgen-ifgen-attr-helper\"")))
424 (substitute* "sepolicy/sepolicy/__init__.py"
425 (("/usr/bin/sepolgen-ifgen")
426 (string-append out "/bin/sepolgen-ifgen")))
427 (substitute* "sepolicy/Makefile"
428 ;; By default all Python files would be installed to
429 ;; $out/gnu/store/...-python-.../.
430 (("setup.py install.*$")
431 (string-append "setup.py install --prefix=" out "\n"))
432 (("\\$\\(DESTDIR\\)/etc")
433 (string-append out "/etc"))
434 (("\\$\\(DESTDIR\\)/usr") out)))
436 (add-after 'install 'wrap-python-tools
437 (lambda* (#:key outputs #:allow-other-keys)
438 (let* ((out (assoc-ref outputs "out"))
439 (var (string-append out "/lib/python"
440 ,(version-major+minor (package-version python))
442 (getenv "PYTHONPATH"))))
443 ;; The scripts' shebangs tell Python to ignore the PYTHONPATH,
444 ;; so we need to patch them before wrapping.
445 (for-each (lambda (file)
446 (let ((path (string-append out "/" file)))
448 (("bin/python -Es") "bin/python -s"))
450 `("PYTHONPATH" ":" prefix (,var)))))
459 `(("python" ,python-wrapper)
462 ("libsepol" ,libsepol)
463 ("libselinux" ,libselinux)
464 ("libsemanage" ,libsemanage)
465 ("python-sepolgen" ,python-sepolgen)
466 ("python-setools" ,python-setools)
467 ("python-ipy" ,python-ipy)
468 ("libcap-ng" ,libcap-ng)
471 ("dbus-glib" ,dbus-glib)
474 `(("gettext" ,gettext-minimal)))
475 (synopsis "SELinux core utilities")
476 (description "The policycoreutils package contains the core utilities that
477 are required for the basic operation of an SELinux-enabled GNU system and its
478 policies. These utilities include @code{load_policy} to load policies,
479 @code{setfiles} to label file systems, @code{newrole} to switch roles, and
480 @code{run_init} to run service scripts in their proper context.")
481 (license license:gpl2+)))