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 (list (string-append "PREFIX=" out)
68 (string-append "SHLIBDIR=" out "/lib")
69 (string-append "MAN3DIR=" out "/share/man/man3")
70 (string-append "MAN5DIR=" out "/share/man/man5")
71 (string-append "MAN8DIR=" out "/share/man/man8")
72 (string-append "LDFLAGS=-Wl,-rpath=" out "/lib")
73 (string-append "CC=" ,(cc-for-target))))
75 (modify-phases %standard-phases
77 (add-after 'unpack 'enter-dir
78 (lambda _ (chdir ,name)))
79 (add-after 'enter-dir 'portability
81 (substitute* "src/ibpkeys.c"
82 (("#include \"ibpkey_internal.h\"" line)
83 (string-append line "\n#include <inttypes.h>\n"))
84 (("%#lx") "%#\" PRIx64 \"")))))))
87 (home-page "https://selinuxproject.org/")
88 (synopsis "Library for manipulating SELinux policies")
90 "The libsepol library provides an API for the manipulation of SELinux
91 binary policies. It is used by @code{checkpolicy} (the policy compiler) and
92 similar tools, and programs such as @code{load_policy}, which must perform
93 specific transformations on binary policies (for example, customizing policy
95 (license license:lgpl2.1+)))
97 (define-public checkpolicy
98 (package/inherit libsepol
101 `(#:tests? #f ; there is no check target
103 (let ((out (assoc-ref %outputs "out")))
104 (list (string-append "PREFIX=" out)
105 (string-append "LIBSEPOLA="
106 (assoc-ref %build-inputs "libsepol")
108 (string-append "CC=" ,(cc-for-target))))
110 (modify-phases %standard-phases
112 (delete 'portability)
113 (add-after 'unpack 'enter-dir
114 (lambda _ (chdir ,name))))))
116 `(("libsepol" ,libsepol)))
120 (synopsis "Check SELinux security policy configurations and modules")
122 "This package provides the tools \"checkpolicy\" and \"checkmodule\".
123 Checkpolicy is a program that checks and compiles a SELinux security policy
124 configuration into a binary representation that can be loaded into the kernel.
125 Checkmodule is a program that checks and compiles a SELinux security policy
126 module into a binary representation.")
128 (license license:gpl2)))
130 (define-public libselinux
131 (package/inherit libsepol
133 (outputs '("out" "python"))
135 (substitute-keyword-arguments (package-arguments libsepol)
136 ((#:make-flags flags)
137 `(cons* "PYTHON=python3"
138 (string-append "LIBSEPOLA="
139 (assoc-ref %build-inputs "libsepol")
141 (string-append "PYTHONLIBDIR="
142 (assoc-ref %outputs "python")
144 ,(version-major+minor (package-version python))
148 `(modify-phases ,phases
149 (delete 'portability)
151 (lambda _ (chdir ,name)))
152 (add-after 'build 'pywrap
153 (lambda* (#:key make-flags #:allow-other-keys)
154 (apply invoke "make" "pywrap" make-flags)))
155 (add-after 'install 'install-pywrap
156 (lambda* (#:key make-flags outputs #:allow-other-keys)
157 ;; The build system uses "python setup.py install" to install
158 ;; Python bindings. Instruct it to use the correct output.
159 (substitute* "src/Makefile"
160 (("--prefix=\\$\\(PREFIX\\)")
161 (string-append "--prefix=" (assoc-ref outputs "python"))))
163 (apply invoke "make" "install-pywrap" make-flags)))))))
164 ;; These libraries are in "Requires.private" in libselinux.pc.
166 `(("libsepol" ,libsepol)
170 `(("python" ,python-wrapper)))
171 ;; These inputs are only needed for the pywrap phase.
174 ("pkg-config" ,pkg-config)))
175 (synopsis "SELinux core libraries and utilities")
177 "The libselinux library provides an API for SELinux applications to get
178 and set process and file security contexts, and to obtain security policy
179 decisions. It is required for any applications that use the SELinux API, and
180 used by all applications that are SELinux-aware. This package also includes
181 the core SELinux management utilities.")
182 (license license:public-domain)))
184 (define-public libsemanage
185 (package/inherit libsepol
188 (substitute-keyword-arguments (package-arguments libsepol)
189 ((#:make-flags flags)
190 `(cons* "PYTHON=python3"
191 (string-append "PYTHONLIBDIR="
192 (assoc-ref %outputs "out")
194 ,(version-major+minor (package-version python))
198 `(modify-phases ,phases
199 (delete 'portability)
201 (lambda _ (chdir ,name)))
202 (add-before 'install 'adjust-semanage-conf-location
204 (substitute* "src/Makefile"
205 (("DEFAULT_SEMANAGE_CONF_LOCATION=/etc")
206 "DEFAULT_SEMANAGE_CONF_LOCATION=$(PREFIX)/etc"))))
207 (add-after 'build 'pywrap
208 (lambda* (#:key make-flags #:allow-other-keys)
209 (apply invoke "make" "pywrap" make-flags)))
210 (add-after 'install 'install-pywrap
211 (lambda* (#:key make-flags #:allow-other-keys)
212 (apply invoke "make" "install-pywrap" make-flags)))))))
214 `(("libsepol" ,libsepol)
215 ("libselinux" ,libselinux)
218 ("python" ,python-wrapper)))
224 ("pkg-config" ,pkg-config)))
225 (synopsis "SELinux policy management libraries")
227 "The libsemanage library provides an API for the manipulation of SELinux
229 (license license:lgpl2.1+)))
231 (define-public secilc
232 (package/inherit libsepol
235 (substitute-keyword-arguments (package-arguments libsepol)
236 ((#:make-flags flags)
237 `(let ((docbook (assoc-ref %build-inputs "docbook-xsl")))
238 (cons (string-append "XMLTO=xmlto --skip-validation -x "
239 docbook "/xml/xsl/docbook-xsl-"
240 ,(package-version docbook-xsl)
241 "/manpages/docbook.xsl")
244 `(modify-phases ,phases
245 (delete 'portability)
247 (lambda _ (chdir ,name)))))))
249 `(("libsepol" ,libsepol)))
252 ("docbook-xsl" ,docbook-xsl)))
253 (synopsis "SELinux common intermediate language (CIL) compiler")
254 (description "The SELinux CIL compiler is a compiler that converts the
255 @dfn{common intermediate language} (CIL) into a kernel binary policy file.")
256 (license license:bsd-2)))
258 (define-public python-sepolgen
259 (package/inherit libsepol
260 (name "python-sepolgen")
262 `(#:modules ((srfi srfi-1)
263 (guix build gnu-build-system)
265 ,@(substitute-keyword-arguments (package-arguments libsepol)
267 `(modify-phases ,phases
268 (delete 'portability)
270 (lambda _ (chdir "python/sepolgen")))
271 ;; By default all Python files would be installed to
272 ;; $out/gnu/store/...-python-.../, so we override the
273 ;; PACKAGEDIR to fix this.
274 (add-after 'enter-dir 'fix-target-path
275 (lambda* (#:key inputs outputs #:allow-other-keys)
276 (let ((get-python-version
277 ;; FIXME: copied from python-build-system
279 (let* ((version (last (string-split python #\-)))
280 (components (string-split version #\.))
281 (major+minor (take components 2)))
282 (string-join major+minor ".")))))
283 (substitute* "src/sepolgen/Makefile"
285 (string-append "PACKAGEDIR="
286 (assoc-ref outputs "out")
289 (assoc-ref inputs "python"))
290 "/site-packages/sepolgen")))
291 (substitute* "src/share/Makefile"
292 (("\\$\\(DESTDIR\\)") (assoc-ref outputs "out")))))))))))
294 `(("python" ,python-wrapper)))
296 (synopsis "Python module for generating SELinux policies")
298 "This package contains a Python module that forms the core of
299 @code{audit2allow}, a part of the package @code{policycoreutils}. The
300 sepolgen library contains: Reference Policy Representation, which are Objects
301 for representing policies and the reference policy interfaces. It has objects
302 and algorithms for representing access and sets of access in an abstract way
303 and searching that access. It also has a parser for reference policy
304 \"headers\". It contains infrastructure for parsing SELinux related messages
305 as produced by the audit system. It has facilities for generating policy
306 based on required access.")
308 (license license:gpl2)))
310 (define-public python-setools
312 (name "python-setools")
317 (url "https://github.com/TresysTechnology/setools")
319 (file-name (string-append name "-" version "-checkout"))
322 "0459xxly6zzqc5azcwk3rbbcxvj60dq08f8z6xr05y7dsbb16cg6"))))
323 (build-system python-build-system)
325 `(#:tests? #f ; the test target causes a rebuild
327 (modify-phases %standard-phases
328 (delete 'portability)
329 (add-after 'unpack 'set-SEPOL-variable
330 (lambda* (#:key inputs #:allow-other-keys)
332 (search-input-file inputs "/lib/libsepol.a"))))
333 (add-after 'unpack 'remove-Werror
335 (substitute* "setup.py"
338 (add-after 'unpack 'fix-target-paths
339 (lambda* (#:key outputs #:allow-other-keys)
340 (substitute* "setup.py"
341 (("join\\(sys.prefix")
342 (string-append "join(\"" (assoc-ref outputs "out") "/\"")))
345 `(("python-networkx" ,python-networkx)))
347 `(("libsepol" ,libsepol)
348 ("libselinux" ,libselinux)))
353 (home-page "https://github.com/TresysTechnology/setools")
354 (synopsis "Tools for SELinux policy analysis")
355 (description "SETools is a collection of graphical tools, command-line
356 tools, and libraries designed to facilitate SELinux policy analysis.")
357 ;; Some programs are under GPL, all libraries under LGPL.
358 (license (list license:lgpl2.1+
361 (define-public policycoreutils
362 (package/inherit libsepol
363 (name "policycoreutils")
365 `(#:test-target "test"
367 (let ((out (assoc-ref %outputs "out")))
368 (list (string-append "CC=" ,(cc-for-target))
369 (string-append "PREFIX=" out)
370 (string-append "LOCALEDIR=" out "/share/locale")
371 (string-append "BASHCOMPLETIONDIR=" out
372 "/share/bash-completion/completions")
373 "INSTALL=install -c -p"
374 "INSTALL_DIR=install -d"
375 ;; These ones are needed because some Makefiles define the
376 ;; directories relative to DESTDIR, not relative to PREFIX.
377 (string-append "SBINDIR=" out "/sbin")
378 (string-append "ETCDIR=" out "/etc")
379 (string-append "SYSCONFDIR=" out "/etc/sysconfig")
380 (string-append "MAN5DIR=" out "/share/man/man5")
381 (string-append "INSTALL_NLS_DIR=" out "/share/locale")
382 (string-append "AUTOSTARTDIR=" out "/etc/xdg/autostart")
383 (string-append "DBUSSERVICEDIR=" out "/share/dbus-1/services")
384 (string-append "SYSTEMDDIR=" out "/lib/systemd")
385 (string-append "INITDIR=" out "/etc/rc.d/init.d")
386 (string-append "SELINUXDIR=" out "/etc/selinux")))
388 (modify-phases %standard-phases
390 (add-after 'unpack 'enter-dir
391 (lambda _ (chdir ,name)))
392 (add-after 'enter-dir 'ignore-/usr-tests
393 (lambda* (#:key inputs #:allow-other-keys)
394 ;; Rewrite lookup paths for header files.
395 (substitute* '("newrole/Makefile"
398 (("/usr(/include/security/pam_appl.h)" _ file)
399 (search-input-file inputs file))
400 (("/usr(/include/libaudit.h)" _ file)
401 (search-input-file inputs file))))))))
405 ("libsepol" ,libsepol)
406 ("libselinux" ,libselinux)
407 ("libsemanage" ,libsemanage)))
409 `(("gettext" ,gettext-minimal)))
410 (synopsis "SELinux core utilities")
411 (description "The policycoreutils package contains the core utilities that
412 are required for the basic operation of an SELinux-enabled GNU system and its
413 policies. These utilities include @code{load_policy} to load policies,
414 @code{setfiles} to label file systems, @code{newrole} to switch roles, and
415 @code{run_init} to run service scripts in their proper context.")
416 (license license:gpl2+)))