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>
6 ;;; This file is part of GNU Guix.
8 ;;; GNU Guix is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
13 ;;; GNU Guix is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;; GNU General Public License for more details.
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
21 (define-module (gnu packages selinux)
22 #:use-module ((guix licenses) #:prefix license:)
23 #:use-module (guix packages)
24 #:use-module (guix download)
25 #:use-module (guix git-download)
26 #:use-module (guix utils)
27 #:use-module (guix build-system gnu)
28 #:use-module (guix build-system python)
29 #:use-module (gnu packages)
30 #:use-module (gnu packages admin)
31 #:use-module (gnu packages bison)
32 #:use-module (gnu packages docbook)
33 #:use-module (gnu packages flex)
34 #:use-module (gnu packages gettext)
35 #:use-module (gnu packages glib)
36 #:use-module (gnu packages linux)
37 #:use-module (gnu packages networking)
38 #:use-module (gnu packages pcre)
39 #:use-module (gnu packages pkg-config)
40 #:use-module (gnu packages python)
41 #:use-module (gnu packages python-xyz)
42 #:use-module (gnu packages swig)
43 #:use-module (gnu packages xml))
45 ;; Update the SELinux packages together!
47 (define-public libsepol
51 (source (let ((release "20191204"))
55 (url "https://github.com/SELinuxProject/selinux")
57 (file-name (string-append "selinux-" release "-checkout"))
60 "05rpzm72cgprd0ccr6lvx9hm8j8b5nkqi4avshlsyg7s3sdlcxjs")))))
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) #t))
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 \""))
93 (home-page "https://selinuxproject.org/")
94 (synopsis "Library for manipulating SELinux policies")
96 "The libsepol library provides an API for the manipulation of SELinux
97 binary policies. It is used by @code{checkpolicy} (the policy compiler) and
98 similar tools, and programs such as @code{load_policy}, which must perform
99 specific transformations on binary policies (for example, customizing policy
101 (license license:lgpl2.1+)))
103 (define-public checkpolicy
104 (package/inherit libsepol
107 `(#:tests? #f ; there is no check target
109 (let ((out (assoc-ref %outputs "out"))
110 (target ,(%current-target-system)))
111 (list (string-append "PREFIX=" out)
112 (string-append "LIBSEPOLA="
113 (assoc-ref %build-inputs "libsepol")
117 (string-append (assoc-ref %build-inputs "cross-gcc")
118 "/bin/" target "-gcc")
121 (modify-phases %standard-phases
123 (delete 'portability)
124 (add-after 'unpack 'enter-dir
125 (lambda _ (chdir ,name) #t)))))
127 `(("libsepol" ,libsepol)))
131 (synopsis "Check SELinux security policy configurations and modules")
133 "This package provides the tools \"checkpolicy\" and \"checkmodule\".
134 Checkpolicy is a program that checks and compiles a SELinux security policy
135 configuration into a binary representation that can be loaded into the kernel.
136 Checkmodule is a program that checks and compiles a SELinux security policy
137 module into a binary representation.")
139 (license license:gpl2)))
141 (define-public libselinux
142 (package/inherit libsepol
144 (outputs '("out" "python"))
146 (substitute-keyword-arguments (package-arguments libsepol)
147 ((#:make-flags flags)
148 `(cons* "PYTHON=python3"
149 (string-append "LIBSEPOLA="
150 (assoc-ref %build-inputs "libsepol")
152 (string-append "PYTHONLIBDIR="
153 (assoc-ref %outputs "python")
155 ,(version-major+minor (package-version python))
159 `(modify-phases ,phases
160 (delete 'portability)
162 (lambda _ (chdir ,name) #t))
163 (add-after 'build 'pywrap
164 (lambda* (#:key make-flags #:allow-other-keys)
165 (apply invoke "make" "pywrap" make-flags)))
166 (add-after 'install 'install-pywrap
167 (lambda* (#:key make-flags outputs #:allow-other-keys)
168 ;; The build system uses "python setup.py install" to install
169 ;; Python bindings. Instruct it to use the correct output.
170 (substitute* "src/Makefile"
171 (("--prefix=\\$\\(PREFIX\\)")
172 (string-append "--prefix=" (assoc-ref outputs "python"))))
174 (apply invoke "make" "install-pywrap" make-flags)))))))
175 ;; These libraries are in "Requires.private" in libselinux.pc.
177 `(("libsepol" ,libsepol)
181 `(("python" ,python-wrapper)))
182 ;; These inputs are only needed for the pywrap phase.
185 ("pkg-config" ,pkg-config)))
186 (synopsis "SELinux core libraries and utilities")
188 "The libselinux library provides an API for SELinux applications to get
189 and set process and file security contexts, and to obtain security policy
190 decisions. It is required for any applications that use the SELinux API, and
191 used by all applications that are SELinux-aware. This package also includes
192 the core SELinux management utilities.")
193 (license license:public-domain)))
195 (define-public libsemanage
196 (package/inherit libsepol
199 (substitute-keyword-arguments (package-arguments libsepol)
200 ((#:make-flags flags)
201 `(cons* "PYTHON=python3"
202 (string-append "PYTHONLIBDIR="
203 (assoc-ref %outputs "out")
205 ,(version-major+minor (package-version python))
209 `(modify-phases ,phases
210 (delete 'portability)
212 (lambda _ (chdir ,name) #t))
213 (add-before 'install 'adjust-semanage-conf-location
215 (substitute* "src/Makefile"
216 (("DEFAULT_SEMANAGE_CONF_LOCATION=/etc")
217 "DEFAULT_SEMANAGE_CONF_LOCATION=$(PREFIX)/etc"))
219 (add-after 'build 'pywrap
220 (lambda* (#:key make-flags #:allow-other-keys)
221 (apply invoke "make" "pywrap" make-flags)))
222 (add-after 'install 'install-pywrap
223 (lambda* (#:key make-flags #:allow-other-keys)
224 (apply invoke "make" "install-pywrap" make-flags)))))))
226 `(("libsepol" ,libsepol)
227 ("libselinux" ,libselinux)
230 ("python" ,python-wrapper)))
236 ("pkg-config" ,pkg-config)))
237 (synopsis "SELinux policy management libraries")
239 "The libsemanage library provides an API for the manipulation of SELinux
241 (license license:lgpl2.1+)))
243 (define-public secilc
244 (package/inherit libsepol
247 (substitute-keyword-arguments (package-arguments libsepol)
248 ((#:make-flags flags)
249 `(let ((docbook (assoc-ref %build-inputs "docbook-xsl")))
250 (cons (string-append "XMLTO=xmlto --skip-validation -x "
251 docbook "/xml/xsl/docbook-xsl-"
252 ,(package-version docbook-xsl)
253 "/manpages/docbook.xsl")
256 `(modify-phases ,phases
257 (delete 'portability)
259 (lambda _ (chdir ,name) #t))))))
261 `(("libsepol" ,libsepol)))
264 ("docbook-xsl" ,docbook-xsl)))
265 (synopsis "SELinux common intermediate language (CIL) compiler")
266 (description "The SELinux CIL compiler is a compiler that converts the
267 @dfn{common intermediate language} (CIL) into a kernel binary policy file.")
268 (license license:bsd-2)))
270 (define-public python-sepolgen
271 (package/inherit libsepol
272 (name "python-sepolgen")
274 `(#:modules ((srfi srfi-1)
275 (guix build gnu-build-system)
277 ,@(substitute-keyword-arguments (package-arguments libsepol)
279 `(modify-phases ,phases
280 (delete 'portability)
282 (lambda _ (chdir "python/sepolgen") #t))
283 ;; By default all Python files would be installed to
284 ;; $out/gnu/store/...-python-.../, so we override the
285 ;; PACKAGEDIR to fix this.
286 (add-after 'enter-dir 'fix-target-path
287 (lambda* (#:key inputs outputs #:allow-other-keys)
288 (let ((get-python-version
289 ;; FIXME: copied from python-build-system
291 (let* ((version (last (string-split python #\-)))
292 (components (string-split version #\.))
293 (major+minor (take components 2)))
294 (string-join major+minor ".")))))
295 (substitute* "src/sepolgen/Makefile"
297 (string-append "PACKAGEDIR="
298 (assoc-ref outputs "out")
301 (assoc-ref inputs "python"))
302 "/site-packages/sepolgen")))
303 (substitute* "src/share/Makefile"
304 (("\\$\\(DESTDIR\\)") (assoc-ref outputs "out"))))
307 `(("python" ,python-wrapper)))
309 (synopsis "Python module for generating SELinux policies")
311 "This package contains a Python module that forms the core of
312 @code{audit2allow}, a part of the package @code{policycoreutils}. The
313 sepolgen library contains: Reference Policy Representation, which are Objects
314 for representing policies and the reference policy interfaces. It has objects
315 and algorithms for representing access and sets of access in an abstract way
316 and searching that access. It also has a parser for reference policy
317 \"headers\". It contains infrastructure for parsing SELinux related messages
318 as produced by the audit system. It has facilities for generating policy
319 based on required access.")
321 (license license:gpl2)))
323 (define-public python-setools
325 (name "python-setools")
330 (url "https://github.com/TresysTechnology/setools")
332 (file-name (string-append name "-" version "-checkout"))
335 "0459xxly6zzqc5azcwk3rbbcxvj60dq08f8z6xr05y7dsbb16cg6"))))
336 (build-system python-build-system)
338 `(#:tests? #f ; the test target causes a rebuild
340 (modify-phases %standard-phases
341 (delete 'portability)
342 (add-after 'unpack 'set-SEPOL-variable
343 (lambda* (#:key inputs #:allow-other-keys)
345 (string-append (assoc-ref inputs "libsepol")
346 "/lib/libsepol.a"))))
347 (add-after 'unpack 'remove-Werror
349 (substitute* "setup.py"
352 (add-after 'unpack 'fix-target-paths
353 (lambda* (#:key outputs #:allow-other-keys)
354 (substitute* "setup.py"
355 (("join\\(sys.prefix")
356 (string-append "join(\"" (assoc-ref outputs "out") "/\"")))
359 `(("python-networkx" ,python-networkx)))
361 `(("libsepol" ,libsepol)
362 ("libselinux" ,libselinux)))
367 (home-page "https://github.com/TresysTechnology/setools")
368 (synopsis "Tools for SELinux policy analysis")
369 (description "SETools is a collection of graphical tools, command-line
370 tools, and libraries designed to facilitate SELinux policy analysis.")
371 ;; Some programs are under GPL, all libraries under LGPL.
372 (license (list license:lgpl2.1+
375 (define-public policycoreutils
376 (package/inherit libsepol
377 (name "policycoreutils")
379 `(#:test-target "test"
381 (let ((out (assoc-ref %outputs "out")))
383 (string-append "PREFIX=" out)
384 (string-append "LOCALEDIR=" out "/share/locale")
385 (string-append "BASHCOMPLETIONDIR=" out
386 "/share/bash-completion/completions")
387 "INSTALL=install -c -p"
388 "INSTALL_DIR=install -d"
389 ;; These ones are needed because some Makefiles define the
390 ;; directories relative to DESTDIR, not relative to PREFIX.
391 (string-append "SBINDIR=" out "/sbin")
392 (string-append "ETCDIR=" out "/etc")
393 (string-append "SYSCONFDIR=" out "/etc/sysconfig")
394 (string-append "MAN5DIR=" out "/share/man/man5")
395 (string-append "INSTALL_NLS_DIR=" out "/share/locale")
396 (string-append "AUTOSTARTDIR=" out "/etc/xdg/autostart")
397 (string-append "DBUSSERVICEDIR=" out "/share/dbus-1/services")
398 (string-append "SYSTEMDDIR=" out "/lib/systemd")
399 (string-append "INITDIR=" out "/etc/rc.d/init.d")
400 (string-append "SELINUXDIR=" out "/etc/selinux")))
402 (modify-phases %standard-phases
404 (delete 'portability)
405 (add-after 'unpack 'enter-dir
406 (lambda _ (chdir ,name) #t))
407 (add-after 'enter-dir 'ignore-/usr-tests
408 (lambda* (#:key inputs #:allow-other-keys)
409 ;; Rewrite lookup paths for header files.
410 (substitute* '("newrole/Makefile"
413 (("/usr(/include/security/pam_appl.h)" _ file)
414 (string-append (assoc-ref inputs "pam") file))
415 (("/usr(/include/libaudit.h)" _ file)
416 (string-append (assoc-ref inputs "audit") file)))
421 ("libsepol" ,libsepol)
422 ("libselinux" ,libselinux)
423 ("libsemanage" ,libsemanage)))
425 `(("gettext" ,gettext-minimal)))
426 (synopsis "SELinux core utilities")
427 (description "The policycoreutils package contains the core utilities that
428 are required for the basic operation of an SELinux-enabled GNU system and its
429 policies. These utilities include @code{load_policy} to load policies,
430 @code{setfiles} to label file systems, @code{newrole} to switch roles, and
431 @code{run_init} to run service scripts in their proper context.")
432 (license license:gpl2+)))