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, 2022 Marius Bakke <marius@gnu.org>
5 ;;; Copyright © 2021 Efraim Flashner <efraim@flashner.co.il>
6 ;;; Copyright © 2021 Guillaume Le Vaillant <glv@posteo.net>
8 ;;; This file is part of GNU Guix.
10 ;;; GNU Guix is free software; you can redistribute it and/or modify it
11 ;;; under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 3 of the License, or (at
13 ;;; your option) any later version.
15 ;;; GNU Guix is distributed in the hope that it will be useful, but
16 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
23 (define-module (gnu packages selinux)
24 #:use-module ((guix licenses) #:prefix license:)
25 #:use-module (guix packages)
26 #:use-module (guix gexp)
27 #:use-module (guix download)
28 #:use-module (guix git-download)
29 #:use-module (guix utils)
30 #:use-module (guix build-system gnu)
31 #:use-module (guix build-system python)
32 #:use-module (gnu packages)
33 #:use-module (gnu packages admin)
34 #:use-module (gnu packages bison)
35 #:use-module (gnu packages docbook)
36 #:use-module (gnu packages flex)
37 #:use-module (gnu packages gettext)
38 #:use-module (gnu packages glib)
39 #:use-module (gnu packages linux)
40 #:use-module (gnu packages networking)
41 #:use-module (gnu packages pcre)
42 #:use-module (gnu packages pkg-config)
43 #:use-module (gnu packages python)
44 #:use-module (gnu packages python-xyz)
45 #:use-module (gnu packages qt)
46 #:use-module (gnu packages swig)
47 #:use-module (gnu packages xml))
49 ;; Update the SELinux packages together!
51 (define-public libsepol
58 (url "https://github.com/SELinuxProject/selinux")
60 (file-name (git-file-name "selinux" version))
63 "1lcmgmfr0q7g5cwg6b7jm6ncw8cw6c1jblkm93v1g37bfhcgrqc0"))))
64 (build-system gnu-build-system)
67 #:tests? #f ; tests require checkpolicy, which requires libsepol
70 #~(let ((out #$output))
71 (list (string-append "PREFIX=" out)
72 (string-append "SHLIBDIR=" out "/lib")
73 (string-append "MAN3DIR=" out "/share/man/man3")
74 (string-append "MAN5DIR=" out "/share/man/man5")
75 (string-append "MAN8DIR=" out "/share/man/man8")
76 (string-append "CFLAGS=-Wno-error")
77 (string-append "LDFLAGS=-Wl,-rpath=" out "/lib")
78 (string-append "CC=" #$(cc-for-target))))
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
107 #:tests? #f ; there is no check target
109 #~(list (string-append "PREFIX=" #$output)
110 (string-append "LIBSEPOLA="
111 (search-input-file %build-inputs
113 (string-append "CC=" #$(cc-for-target)))
115 #~(modify-phases %standard-phases
117 (delete 'portability)
118 (add-after 'unpack 'enter-dir
119 (lambda _ (chdir #$name))))))
124 (synopsis "Check SELinux security policy configurations and modules")
126 "This package provides the tools \"checkpolicy\" and \"checkmodule\".
127 Checkpolicy is a program that checks and compiles a SELinux security policy
128 configuration into a binary representation that can be loaded into the kernel.
129 Checkmodule is a program that checks and compiles a SELinux security policy
130 module into a binary representation.")
132 (license license:gpl2)))
134 (define-public libselinux
135 (package/inherit libsepol
137 (outputs '("out" "python"))
139 (substitute-keyword-arguments (package-arguments libsepol)
140 ((#:make-flags flags)
141 #~(cons* "PYTHON=python3"
142 (string-append "LIBSEPOLA="
143 (search-input-file %build-inputs
145 (string-append "PYTHONLIBDIR="
148 #$(version-major+minor (package-version python))
152 #~(modify-phases #$phases
153 (delete 'portability)
155 (lambda _ (chdir #$name)))
156 (add-after 'build 'pywrap
157 (lambda* (#:key make-flags #:allow-other-keys)
158 (apply invoke "make" "pywrap" make-flags)))
159 (add-after 'install 'install-pywrap
160 (lambda* (#:key make-flags #:allow-other-keys)
161 ;; The build system uses "python setup.py install" to install
162 ;; Python bindings. Instruct it to use the correct output.
163 (substitute* "src/Makefile"
164 (("--prefix=\\$\\(PREFIX\\)")
165 (string-append "--prefix=" #$output:python)))
167 (apply invoke "make" "install-pywrap" make-flags)))))))
168 ;; These libraries are in "Requires.private" in libselinux.pc.
170 (list libsepol pcre2))
173 (list python-wrapper))
174 ;; These inputs are only needed for the pywrap phase.
176 (list pkg-config swig))
177 (synopsis "SELinux core libraries and utilities")
179 "The libselinux library provides an API for SELinux applications to get
180 and set process and file security contexts, and to obtain security policy
181 decisions. It is required for any applications that use the SELinux API, and
182 used by all applications that are SELinux-aware. This package also includes
183 the core SELinux management utilities.")
184 (license license:public-domain)))
186 (define-public libsemanage
187 (package/inherit libsepol
190 (substitute-keyword-arguments (package-arguments libsepol)
191 ((#:make-flags flags)
192 #~(cons* "PYTHON=python3"
193 (string-append "PYTHONLIBDIR="
196 #$(version-major+minor (package-version python))
200 #~(modify-phases #$phases
201 (delete 'portability)
203 (lambda _ (chdir #$name)))
204 (add-before 'install 'adjust-semanage-conf-location
206 (substitute* "src/Makefile"
207 (("DEFAULT_SEMANAGE_CONF_LOCATION=/etc")
208 "DEFAULT_SEMANAGE_CONF_LOCATION=$(PREFIX)/etc"))))
209 (add-after 'build 'pywrap
210 (lambda* (#:key make-flags #:allow-other-keys)
211 (apply invoke "make" "pywrap" make-flags)))
212 (add-after 'install 'install-pywrap
213 (lambda* (#:key make-flags #:allow-other-keys)
214 (apply invoke "make" "install-pywrap" make-flags)))))))
216 (list audit libsepol libselinux python-wrapper))
218 (list bison flex pkg-config swig))
219 (synopsis "SELinux policy management libraries")
221 "The libsemanage library provides an API for the manipulation of SELinux
223 (license license:lgpl2.1+)))
225 (define-public secilc
226 (package/inherit libsepol
229 (substitute-keyword-arguments (package-arguments libsepol)
230 ((#:make-flags flags)
231 #~(let ((xsl (search-input-directory %build-inputs "xml/xsl")))
232 (cons (string-append "XMLTO=xmlto --skip-validation -x "
235 (this-package-native-input "docbook-xsl"))
236 "/manpages/docbook.xsl")
239 #~(modify-phases #$phases
240 (delete 'portability)
242 (lambda _ (chdir #$name)))))))
246 (list xmlto docbook-xsl))
247 (synopsis "SELinux common intermediate language (CIL) compiler")
248 (description "The SELinux CIL compiler is a compiler that converts the
249 @dfn{common intermediate language} (CIL) into a kernel binary policy file.")
250 (license license:bsd-2)))
252 (define-public python-sepolgen
253 (package/inherit libsepol
254 (name "python-sepolgen")
256 (substitute-keyword-arguments (package-arguments libsepol)
257 ((#:modules _ #~%gnu-build-system-modules)
259 (guix build gnu-build-system)
262 #~(modify-phases #$phases
263 (delete 'portability)
265 (lambda _ (chdir "python/sepolgen")))
266 ;; By default all Python files would be installed to
267 ;; $out/gnu/store/...-python-.../, so we override the
268 ;; PACKAGEDIR to fix this.
269 (add-after 'enter-dir 'fix-target-path
270 (lambda* (#:key inputs #:allow-other-keys)
271 (let ((get-python-version
272 ;; FIXME: copied from python-build-system
274 (let* ((version (last (string-split python #\-)))
275 (components (string-split version #\.))
276 (major+minor (take components 2)))
277 (string-join major+minor "."))))
278 (python (dirname (dirname (search-input-file
279 inputs "bin/python3")))))
280 (substitute* "src/sepolgen/Makefile"
282 (string-append "PACKAGEDIR="
285 (get-python-version python)
286 "/site-packages/sepolgen")))
287 (substitute* "src/share/Makefile"
288 (("\\$\\(DESTDIR\\)") #$output)))))))))
290 (list python-wrapper))
292 (synopsis "Python module for generating SELinux policies")
294 "This package contains a Python module that forms the core of
295 @code{audit2allow}, a part of the package @code{policycoreutils}. The
296 sepolgen library contains: Reference Policy Representation, which are Objects
297 for representing policies and the reference policy interfaces. It has objects
298 and algorithms for representing access and sets of access in an abstract way
299 and searching that access. It also has a parser for reference policy
300 \"headers\". It contains infrastructure for parsing SELinux related messages
301 as produced by the audit system. It has facilities for generating policy
302 based on required access.")
304 (license license:gpl2)))
306 (define-public python-setools
308 (name "python-setools")
313 (url "https://github.com/SELinuxProject/setools")
315 (file-name (string-append name "-" version "-checkout"))
318 "1qvd5j6zwq4fmlahg45swjplhif2z89x7s6pnp07gvcp2fbqdsh5"))))
319 (build-system python-build-system)
321 `(#:tests? #f ; the test target causes a rebuild
323 (modify-phases %standard-phases
324 (delete 'portability)
325 (add-after 'unpack 'set-SEPOL-variable
326 (lambda* (#:key inputs #:allow-other-keys)
328 (search-input-file inputs "/lib/libsepol.a"))))
329 (add-after 'unpack 'remove-Werror
331 (substitute* "setup.py"
334 (add-after 'unpack 'fix-target-paths
335 (lambda* (#:key outputs #:allow-other-keys)
336 (substitute* "setup.py"
337 (("join\\(sys.prefix")
338 (string-append "join(\"" (assoc-ref outputs "out") "/\"")))
341 (list python-networkx))
343 (list libsepol libselinux python-pyqt))
345 (list bison flex python-cython swig))
346 (home-page "https://github.com/SELinuxProject/setools")
347 (synopsis "Tools for SELinux policy analysis")
348 (description "SETools is a collection of graphical tools, command-line
349 tools, and libraries designed to facilitate SELinux policy analysis.")
350 ;; Some programs are under GPL, all libraries under LGPL.
351 (license (list license:lgpl2.1+
354 (define-public policycoreutils
355 (package/inherit libsepol
356 (name "policycoreutils")
361 #~(let ((out #$output))
362 (list (string-append "CC=" #$(cc-for-target))
363 (string-append "PREFIX=" out)
364 (string-append "LOCALEDIR=" out "/share/locale")
365 (string-append "BASHCOMPLETIONDIR=" out
366 "/share/bash-completion/completions")
367 "INSTALL=install -c -p"
368 "INSTALL_DIR=install -d"
369 ;; These ones are needed because some Makefiles define the
370 ;; directories relative to DESTDIR, not relative to PREFIX.
371 (string-append "SBINDIR=" out "/sbin")
372 (string-append "ETCDIR=" out "/etc")
373 (string-append "SYSCONFDIR=" out "/etc/sysconfig")
374 (string-append "MAN5DIR=" out "/share/man/man5")
375 (string-append "INSTALL_NLS_DIR=" out "/share/locale")
376 (string-append "AUTOSTARTDIR=" out "/etc/xdg/autostart")
377 (string-append "DBUSSERVICEDIR=" out "/share/dbus-1/services")
378 (string-append "SYSTEMDDIR=" out "/lib/systemd")
379 (string-append "INITDIR=" out "/etc/rc.d/init.d")
380 (string-append "SELINUXDIR=" out "/etc/selinux")))
382 #~(modify-phases %standard-phases
384 (add-after 'unpack 'enter-dir
385 (lambda _ (chdir #$name)))
386 (add-after 'enter-dir 'ignore-/usr-tests
387 (lambda* (#:key inputs #:allow-other-keys)
388 ;; Rewrite lookup paths for header files.
389 (substitute* '("newrole/Makefile"
392 (("/usr(/include/security/pam_appl.h)" _ file)
393 (search-input-file inputs file))
394 (("/usr(/include/libaudit.h)" _ file)
395 (search-input-file inputs file))))))))
403 (list gettext-minimal))
404 (synopsis "SELinux core utilities")
405 (description "The policycoreutils package contains the core utilities that
406 are required for the basic operation of an SELinux-enabled GNU system and its
407 policies. These utilities include @code{load_policy} to load policies,
408 @code{setfiles} to label file systems, @code{newrole} to switch roles, and
409 @code{run_init} to run service scripts in their proper context.")
410 (license license:gpl2+)))