1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2016, 2017, 2018 Ricardo Wurmus <rekado@elephly.net>
3 ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
4 ;;; Copyright © 2019, 2020 Marius Bakke <mbakke@fastmail.com>
5 ;;; Copyright © 2021 Efraim Flashner <efraim@flashner.co.il>
7 ;;; This file is part of GNU Guix.
9 ;;; GNU Guix is free software; you can redistribute it and/or modify it
10 ;;; under the terms of the GNU General Public License as published by
11 ;;; the Free Software Foundation; either version 3 of the License, or (at
12 ;;; your option) any later version.
14 ;;; GNU Guix is distributed in the hope that it will be useful, but
15 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;;; GNU General Public License for more details.
19 ;;; You should have received a copy of the GNU General Public License
20 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
22 (define-module (gnu packages selinux)
23 #:use-module ((guix licenses) #:prefix license:)
24 #:use-module (guix packages)
25 #:use-module (guix download)
26 #:use-module (guix git-download)
27 #:use-module (guix utils)
28 #:use-module (guix build-system gnu)
29 #:use-module (guix build-system python)
30 #:use-module (gnu packages)
31 #:use-module (gnu packages admin)
32 #:use-module (gnu packages bison)
33 #:use-module (gnu packages docbook)
34 #:use-module (gnu packages flex)
35 #:use-module (gnu packages gettext)
36 #:use-module (gnu packages glib)
37 #:use-module (gnu packages linux)
38 #:use-module (gnu packages networking)
39 #:use-module (gnu packages pcre)
40 #:use-module (gnu packages pkg-config)
41 #:use-module (gnu packages python)
42 #:use-module (gnu packages python-xyz)
43 #:use-module (gnu packages swig)
44 #:use-module (gnu packages xml))
46 ;; Update the SELinux packages together!
48 (define-public libsepol
55 (url "https://github.com/SELinuxProject/selinux")
57 (file-name (git-file-name "selinux" version))
60 "03p3lmvrvkcvsmiczsjzhyfgxlxdkdyq0p8igv3s3hdak5n92jjn"))))
61 (build-system gnu-build-system)
63 `(#:tests? #f ; tests require checkpolicy, which requires libsepol
66 (let ((out (assoc-ref %outputs "out"))
67 (target ,(%current-target-system)))
68 (list (string-append "PREFIX=" out)
69 (string-append "SHLIBDIR=" out "/lib")
70 (string-append "MAN3DIR=" out "/share/man/man3")
71 (string-append "MAN5DIR=" out "/share/man/man5")
72 (string-append "MAN8DIR=" out "/share/man/man8")
73 (string-append "LDFLAGS=-Wl,-rpath=" out "/lib")
76 (string-append (assoc-ref %build-inputs "cross-gcc")
77 "/bin/" target "-gcc")
80 (modify-phases %standard-phases
82 (add-after 'unpack 'enter-dir
83 (lambda _ (chdir ,name)))
84 (add-after 'enter-dir 'portability
86 (substitute* "src/ibpkeys.c"
87 (("#include \"ibpkey_internal.h\"" line)
88 (string-append line "\n#include <inttypes.h>\n"))
89 (("%#lx") "%#\" PRIx64 \"")))))))
92 (home-page "https://selinuxproject.org/")
93 (synopsis "Library for manipulating SELinux policies")
95 "The libsepol library provides an API for the manipulation of SELinux
96 binary policies. It is used by @code{checkpolicy} (the policy compiler) and
97 similar tools, and programs such as @code{load_policy}, which must perform
98 specific transformations on binary policies (for example, customizing policy
100 (license license:lgpl2.1+)))
102 (define-public checkpolicy
103 (package/inherit libsepol
106 `(#:tests? #f ; there is no check target
108 (let ((out (assoc-ref %outputs "out"))
109 (target ,(%current-target-system)))
110 (list (string-append "PREFIX=" out)
111 (string-append "LIBSEPOLA="
112 (assoc-ref %build-inputs "libsepol")
116 (string-append (assoc-ref %build-inputs "cross-gcc")
117 "/bin/" target "-gcc")
120 (modify-phases %standard-phases
122 (delete 'portability)
123 (add-after 'unpack 'enter-dir
124 (lambda _ (chdir ,name))))))
126 `(("libsepol" ,libsepol)))
130 (synopsis "Check SELinux security policy configurations and modules")
132 "This package provides the tools \"checkpolicy\" and \"checkmodule\".
133 Checkpolicy is a program that checks and compiles a SELinux security policy
134 configuration into a binary representation that can be loaded into the kernel.
135 Checkmodule is a program that checks and compiles a SELinux security policy
136 module into a binary representation.")
138 (license license:gpl2)))
140 (define-public libselinux
141 (package/inherit libsepol
143 (outputs '("out" "python"))
145 (substitute-keyword-arguments (package-arguments libsepol)
146 ((#:make-flags flags)
147 `(cons* "PYTHON=python3"
148 (string-append "LIBSEPOLA="
149 (assoc-ref %build-inputs "libsepol")
151 (string-append "PYTHONLIBDIR="
152 (assoc-ref %outputs "python")
154 ,(version-major+minor (package-version python))
158 `(modify-phases ,phases
159 (delete 'portability)
161 (lambda _ (chdir ,name)))
162 (add-after 'build 'pywrap
163 (lambda* (#:key make-flags #:allow-other-keys)
164 (apply invoke "make" "pywrap" make-flags)))
165 (add-after 'install 'install-pywrap
166 (lambda* (#:key make-flags outputs #:allow-other-keys)
167 ;; The build system uses "python setup.py install" to install
168 ;; Python bindings. Instruct it to use the correct output.
169 (substitute* "src/Makefile"
170 (("--prefix=\\$\\(PREFIX\\)")
171 (string-append "--prefix=" (assoc-ref outputs "python"))))
173 (apply invoke "make" "install-pywrap" make-flags)))))))
174 ;; These libraries are in "Requires.private" in libselinux.pc.
176 `(("libsepol" ,libsepol)
180 `(("python" ,python-wrapper)))
181 ;; These inputs are only needed for the pywrap phase.
184 ("pkg-config" ,pkg-config)))
185 (synopsis "SELinux core libraries and utilities")
187 "The libselinux library provides an API for SELinux applications to get
188 and set process and file security contexts, and to obtain security policy
189 decisions. It is required for any applications that use the SELinux API, and
190 used by all applications that are SELinux-aware. This package also includes
191 the core SELinux management utilities.")
192 (license license:public-domain)))
194 (define-public libsemanage
195 (package/inherit libsepol
198 (substitute-keyword-arguments (package-arguments libsepol)
199 ((#:make-flags flags)
200 `(cons* "PYTHON=python3"
201 (string-append "PYTHONLIBDIR="
202 (assoc-ref %outputs "out")
204 ,(version-major+minor (package-version python))
208 `(modify-phases ,phases
209 (delete 'portability)
211 (lambda _ (chdir ,name)))
212 (add-before 'install 'adjust-semanage-conf-location
214 (substitute* "src/Makefile"
215 (("DEFAULT_SEMANAGE_CONF_LOCATION=/etc")
216 "DEFAULT_SEMANAGE_CONF_LOCATION=$(PREFIX)/etc"))))
217 (add-after 'build 'pywrap
218 (lambda* (#:key make-flags #:allow-other-keys)
219 (apply invoke "make" "pywrap" make-flags)))
220 (add-after 'install 'install-pywrap
221 (lambda* (#:key make-flags #:allow-other-keys)
222 (apply invoke "make" "install-pywrap" make-flags)))))))
224 `(("libsepol" ,libsepol)
225 ("libselinux" ,libselinux)
228 ("python" ,python-wrapper)))
234 ("pkg-config" ,pkg-config)))
235 (synopsis "SELinux policy management libraries")
237 "The libsemanage library provides an API for the manipulation of SELinux
239 (license license:lgpl2.1+)))
241 (define-public secilc
242 (package/inherit libsepol
245 (substitute-keyword-arguments (package-arguments libsepol)
246 ((#:make-flags flags)
247 `(let ((docbook (assoc-ref %build-inputs "docbook-xsl")))
248 (cons (string-append "XMLTO=xmlto --skip-validation -x "
249 docbook "/xml/xsl/docbook-xsl-"
250 ,(package-version docbook-xsl)
251 "/manpages/docbook.xsl")
254 `(modify-phases ,phases
255 (delete 'portability)
257 (lambda _ (chdir ,name)))))))
259 `(("libsepol" ,libsepol)))
262 ("docbook-xsl" ,docbook-xsl)))
263 (synopsis "SELinux common intermediate language (CIL) compiler")
264 (description "The SELinux CIL compiler is a compiler that converts the
265 @dfn{common intermediate language} (CIL) into a kernel binary policy file.")
266 (license license:bsd-2)))
268 (define-public python-sepolgen
269 (package/inherit libsepol
270 (name "python-sepolgen")
272 `(#:modules ((srfi srfi-1)
273 (guix build gnu-build-system)
275 ,@(substitute-keyword-arguments (package-arguments libsepol)
277 `(modify-phases ,phases
278 (delete 'portability)
280 (lambda _ (chdir "python/sepolgen")))
281 ;; By default all Python files would be installed to
282 ;; $out/gnu/store/...-python-.../, so we override the
283 ;; PACKAGEDIR to fix this.
284 (add-after 'enter-dir 'fix-target-path
285 (lambda* (#:key inputs outputs #:allow-other-keys)
286 (let ((get-python-version
287 ;; FIXME: copied from python-build-system
289 (let* ((version (last (string-split python #\-)))
290 (components (string-split version #\.))
291 (major+minor (take components 2)))
292 (string-join major+minor ".")))))
293 (substitute* "src/sepolgen/Makefile"
295 (string-append "PACKAGEDIR="
296 (assoc-ref outputs "out")
299 (assoc-ref inputs "python"))
300 "/site-packages/sepolgen")))
301 (substitute* "src/share/Makefile"
302 (("\\$\\(DESTDIR\\)") (assoc-ref outputs "out")))))))))))
304 `(("python" ,python-wrapper)))
306 (synopsis "Python module for generating SELinux policies")
308 "This package contains a Python module that forms the core of
309 @code{audit2allow}, a part of the package @code{policycoreutils}. The
310 sepolgen library contains: Reference Policy Representation, which are Objects
311 for representing policies and the reference policy interfaces. It has objects
312 and algorithms for representing access and sets of access in an abstract way
313 and searching that access. It also has a parser for reference policy
314 \"headers\". It contains infrastructure for parsing SELinux related messages
315 as produced by the audit system. It has facilities for generating policy
316 based on required access.")
318 (license license:gpl2)))
320 (define-public python-setools
322 (name "python-setools")
327 (url "https://github.com/TresysTechnology/setools")
329 (file-name (string-append name "-" version "-checkout"))
332 "0459xxly6zzqc5azcwk3rbbcxvj60dq08f8z6xr05y7dsbb16cg6"))))
333 (build-system python-build-system)
335 `(#:tests? #f ; the test target causes a rebuild
337 (modify-phases %standard-phases
338 (delete 'portability)
339 (add-after 'unpack 'set-SEPOL-variable
340 (lambda* (#:key inputs #:allow-other-keys)
342 (string-append (assoc-ref inputs "libsepol")
343 "/lib/libsepol.a"))))
344 (add-after 'unpack 'remove-Werror
346 (substitute* "setup.py"
349 (add-after 'unpack 'fix-target-paths
350 (lambda* (#:key outputs #:allow-other-keys)
351 (substitute* "setup.py"
352 (("join\\(sys.prefix")
353 (string-append "join(\"" (assoc-ref outputs "out") "/\"")))
356 `(("python-networkx" ,python-networkx)))
358 `(("libsepol" ,libsepol)
359 ("libselinux" ,libselinux)))
364 (home-page "https://github.com/TresysTechnology/setools")
365 (synopsis "Tools for SELinux policy analysis")
366 (description "SETools is a collection of graphical tools, command-line
367 tools, and libraries designed to facilitate SELinux policy analysis.")
368 ;; Some programs are under GPL, all libraries under LGPL.
369 (license (list license:lgpl2.1+
372 (define-public policycoreutils
373 (package/inherit libsepol
374 (name "policycoreutils")
376 `(#:test-target "test"
378 (let ((out (assoc-ref %outputs "out")))
380 (string-append "PREFIX=" out)
381 (string-append "LOCALEDIR=" out "/share/locale")
382 (string-append "BASHCOMPLETIONDIR=" out
383 "/share/bash-completion/completions")
384 "INSTALL=install -c -p"
385 "INSTALL_DIR=install -d"
386 ;; These ones are needed because some Makefiles define the
387 ;; directories relative to DESTDIR, not relative to PREFIX.
388 (string-append "SBINDIR=" out "/sbin")
389 (string-append "ETCDIR=" out "/etc")
390 (string-append "SYSCONFDIR=" out "/etc/sysconfig")
391 (string-append "MAN5DIR=" out "/share/man/man5")
392 (string-append "INSTALL_NLS_DIR=" out "/share/locale")
393 (string-append "AUTOSTARTDIR=" out "/etc/xdg/autostart")
394 (string-append "DBUSSERVICEDIR=" out "/share/dbus-1/services")
395 (string-append "SYSTEMDDIR=" out "/lib/systemd")
396 (string-append "INITDIR=" out "/etc/rc.d/init.d")
397 (string-append "SELINUXDIR=" out "/etc/selinux")))
399 (modify-phases %standard-phases
401 (add-after 'unpack 'enter-dir
402 (lambda _ (chdir ,name)))
403 (add-after 'enter-dir 'ignore-/usr-tests
404 (lambda* (#:key inputs #:allow-other-keys)
405 ;; Rewrite lookup paths for header files.
406 (substitute* '("newrole/Makefile"
409 (("/usr(/include/security/pam_appl.h)" _ file)
410 (string-append (assoc-ref inputs "pam") file))
411 (("/usr(/include/libaudit.h)" _ file)
412 (string-append (assoc-ref inputs "audit") file))))))))
416 ("libsepol" ,libsepol)
417 ("libselinux" ,libselinux)
418 ("libsemanage" ,libsemanage)))
420 `(("gettext" ,gettext-minimal)))
421 (synopsis "SELinux core utilities")
422 (description "The policycoreutils package contains the core utilities that
423 are required for the basic operation of an SELinux-enabled GNU system and its
424 policies. These utilities include @code{load_policy} to load policies,
425 @code{setfiles} to label file systems, @code{newrole} to switch roles, and
426 @code{run_init} to run service scripts in their proper context.")
427 (license license:gpl2+)))