1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2016, 2017, 2018 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 git-download)
24 #:use-module (guix utils)
25 #:use-module (guix build-system gnu)
26 #:use-module (guix build-system python)
27 #:use-module (gnu packages)
28 #:use-module (gnu packages admin)
29 #:use-module (gnu packages bison)
30 #:use-module (gnu packages docbook)
31 #:use-module (gnu packages flex)
32 #:use-module (gnu packages gettext)
33 #:use-module (gnu packages glib)
34 #:use-module (gnu packages linux)
35 #:use-module (gnu packages networking)
36 #:use-module (gnu packages pcre)
37 #:use-module (gnu packages pkg-config)
38 #:use-module (gnu packages python)
39 #:use-module (gnu packages swig)
40 #:use-module (gnu packages textutils)
41 #:use-module (gnu packages xml))
43 ;; Update the SELinux packages together!
45 (define-public libsepol
49 (source (let ((release "20170804"))
53 (url "https://github.com/SELinuxProject/selinux.git")
55 (file-name (string-append "selinux-" release "-checkout"))
58 "1l1nn8bx08v4cxkw5kb0wgr61rfqj5ra9dh1dy5jslillj93vivq")))))
59 (build-system gnu-build-system)
61 `(#:tests? #f ; tests require checkpolicy, which requires libsepol
64 (let ((out (assoc-ref %outputs "out")))
65 (list (string-append "PREFIX=" out)
66 (string-append "DESTDIR=" out)
67 (string-append "MAN3DIR=" out "/share/man/man3")
68 (string-append "MAN5DIR=" out "/share/man/man5")
69 (string-append "MAN8DIR=" out "/share/man/man8")
70 (string-append "LDFLAGS=-Wl,-rpath=" out "/lib")
73 (modify-phases %standard-phases
75 (add-after 'unpack 'enter-dir
76 (lambda _ (chdir ,name) #t))
77 (add-after 'enter-dir 'portability
79 (substitute* "src/ibpkeys.c"
80 (("#include \"ibpkey_internal.h\"" line)
81 (string-append line "\n#include <inttypes.h>\n"))
82 (("%#lx") "%#\" PRIx64 \""))
86 (home-page "https://selinuxproject.org/")
87 (synopsis "Library for manipulating SELinux policies")
89 "The libsepol library provides an API for the manipulation of SELinux
90 binary policies. It is used by @code{checkpolicy} (the policy compiler) and
91 similar tools, and programs such as @code{load_policy}, which must perform
92 specific transformations on binary policies (for example, customizing policy
94 (license license:lgpl2.1+)))
96 (define-public checkpolicy
97 (package (inherit libsepol)
100 `(#:tests? #f ; there is no check target
102 (let ((out (assoc-ref %outputs "out")))
103 (list (string-append "PREFIX=" out)
104 (string-append "LIBSEPOLA="
105 (assoc-ref %build-inputs "libsepol")
109 (modify-phases %standard-phases
111 (delete 'portability)
112 (add-after 'unpack 'enter-dir
113 (lambda _ (chdir ,name) #t)))))
115 `(("libsepol" ,libsepol)))
119 (synopsis "Check SELinux security policy configurations and modules")
121 "This package provides the tools \"checkpolicy\" and \"checkmodule\".
122 Checkpolicy is a program that checks and compiles a SELinux security policy
123 configuration into a binary representation that can be loaded into the kernel.
124 Checkmodule is a program that checks and compiles a SELinux security policy
125 module into a binary representation.")
127 (license license:gpl2)))
129 (define-public libselinux
130 (package (inherit libsepol)
133 (substitute-keyword-arguments (package-arguments libsepol)
134 ((#:make-flags flags)
135 `(cons* "PYTHON=python3"
136 (string-append "LIBSEPOLA="
137 (assoc-ref %build-inputs "libsepol")
139 (string-append "PYSITEDIR="
140 (assoc-ref %outputs "out")
142 ,(version-major+minor (package-version python))
146 `(modify-phases ,phases
147 (delete 'portability)
149 (lambda _ (chdir ,name) #t))
150 (add-after 'enter-dir 'remove-Werror
152 ;; GCC complains about the fact that the output does not (yet)
153 ;; have an "include" directory, even though it is referenced.
154 (substitute* '("src/Makefile"
158 (add-after 'build 'pywrap
159 (lambda* (#:key make-flags #:allow-other-keys)
160 (zero? (apply system* "make" "pywrap" make-flags))))
161 (add-after 'install 'install-pywrap
162 (lambda* (#:key make-flags #:allow-other-keys)
163 (zero? (apply system* "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 "PYSITEDIR="
192 (assoc-ref %outputs "out")
194 ,(version-major+minor (package-version python))
198 `(modify-phases ,phases
199 (delete 'portability)
201 (lambda _ (chdir ,name) #t))
202 (add-after 'build 'pywrap
203 (lambda* (#:key make-flags #:allow-other-keys)
204 (zero? (apply system* "make" "pywrap" make-flags))))
205 (add-after 'install 'install-pywrap
206 (lambda* (#:key make-flags #:allow-other-keys)
207 (zero? (apply system* "make" "install-pywrap" make-flags))))))))
209 `(("libsepol" ,libsepol)
210 ("libselinux" ,libselinux)
214 ("python" ,python-wrapper)))
220 ("pkg-config" ,pkg-config)))
221 (synopsis "SELinux policy management libraries")
223 "The libsemanage library provides an API for the manipulation of SELinux
225 (license license:lgpl2.1+)))
227 (define-public secilc
228 (package (inherit libsepol)
231 (substitute-keyword-arguments (package-arguments libsepol)
232 ((#:make-flags flags)
233 `(let ((docbook (assoc-ref %build-inputs "docbook-xsl")))
234 (cons (string-append "XMLTO=xmlto --skip-validation -x "
235 docbook "/xml/xsl/docbook-xsl-"
236 ,(package-version docbook-xsl)
237 "/manpages/docbook.xsl")
240 `(modify-phases ,phases
241 (delete 'portability)
243 (lambda _ (chdir ,name) #t))))))
245 `(("libsepol" ,libsepol)))
248 ("docbook-xsl" ,docbook-xsl)))
249 (synopsis "SELinux common intermediate language (CIL) compiler")
250 (description "The SELinux CIL compiler is a compiler that converts the
251 @dfn{common intermediate language} (CIL) into a kernel binary policy file.")
252 (license license:bsd-2)))
254 (define-public python-sepolgen
255 (package (inherit libsepol)
256 (name "python-sepolgen")
258 `(#:modules ((srfi srfi-1)
259 (guix build gnu-build-system)
261 ,@(substitute-keyword-arguments (package-arguments libsepol)
263 `(modify-phases ,phases
264 (delete 'portability)
266 (lambda _ (chdir "python/sepolgen") #t))
267 ;; By default all Python files would be installed to
268 ;; $out/gnu/store/...-python-.../, so we override the
269 ;; PACKAGEDIR to fix this.
270 (add-after 'enter-dir 'fix-target-path
271 (lambda* (#:key inputs outputs #:allow-other-keys)
272 (let ((get-python-version
273 ;; FIXME: copied from python-build-system
275 (let* ((version (last (string-split python #\-)))
276 (components (string-split version #\.))
277 (major+minor (take components 2)))
278 (string-join major+minor ".")))))
279 (substitute* "src/sepolgen/Makefile"
281 (string-append "PACKAGEDIR="
282 (assoc-ref outputs "out")
285 (assoc-ref inputs "python"))
286 "/site-packages/sepolgen")))
287 (substitute* "src/share/Makefile"
288 (("\\$\\(DESTDIR\\)") (assoc-ref outputs "out"))))
291 `(("python" ,python-wrapper)))
293 (synopsis "Python module for generating SELinux policies")
295 "This package contains a Python module that forms the core of
296 @code{audit2allow}, a part of the package @code{policycoreutils}. The
297 sepolgen library contains: Reference Policy Representation, which are Objects
298 for representing policies and the reference policy interfaces. It has objects
299 and algorithms for representing access and sets of access in an abstract way
300 and searching that access. It also has a parser for reference policy
301 \"headers\". It contains infrastructure for parsing SELinux related messages
302 as produced by the audit system. It has facilities for generating policy
303 based on required access.")
305 (license license:gpl2)))
307 (define-public python-setools
309 (name "python-setools")
314 (url "https://github.com/TresysTechnology/setools.git")
316 (file-name (string-append name "-" version "-checkout"))
319 "0459xxly6zzqc5azcwk3rbbcxvj60dq08f8z6xr05y7dsbb16cg6"))))
320 (build-system python-build-system)
322 `(#:tests? #f ; the test target causes a rebuild
324 (modify-phases %standard-phases
325 (delete 'portability)
326 (add-after 'unpack 'set-SEPOL-variable
327 (lambda* (#:key inputs #:allow-other-keys)
329 (string-append (assoc-ref inputs "libsepol")
330 "/lib/libsepol.a"))))
331 (add-after 'unpack 'remove-Werror
333 (substitute* "setup.py"
336 (add-after 'unpack 'fix-target-paths
337 (lambda* (#:key outputs #:allow-other-keys)
338 (substitute* "setup.py"
339 (("join\\(sys.prefix")
340 (string-append "join(\"" (assoc-ref outputs "out") "/\"")))
343 `(("python-networkx" ,python-networkx)))
345 `(("libsepol" ,libsepol)
346 ("libselinux" ,libselinux)))
351 (home-page "https://github.com/TresysTechnology/setools")
352 (synopsis "Tools for SELinux policy analysis")
353 (description "SETools is a collection of graphical tools, command-line
354 tools, and libraries designed to facilitate SELinux policy analysis.")
355 ;; Some programs are under GPL, all libraries under LGPL.
356 (license (list license:lgpl2.1+
359 (define-public policycoreutils
360 (package (inherit libsepol)
361 (name "policycoreutils")
363 `(#:test-target "test"
365 (let ((out (assoc-ref %outputs "out")))
367 (string-append "PREFIX=" out)
368 (string-append "LOCALEDIR=" out "/share/locale")
369 (string-append "BASHCOMPLETIONDIR=" out
370 "/share/bash-completion/completions")
371 "INSTALL=install -c -p"
372 "INSTALL_DIR=install -d"
373 ;; These ones are needed because some Makefiles define the
374 ;; directories relative to DESTDIR, not relative to PREFIX.
375 (string-append "SBINDIR=" out "/sbin")
376 (string-append "ETCDIR=" out "/etc")
377 (string-append "SYSCONFDIR=" out "/etc/sysconfig")
378 (string-append "MAN5DIR=" out "/share/man/man5")
379 (string-append "INSTALL_NLS_DIR=" out "/share/locale")
380 (string-append "AUTOSTARTDIR=" out "/etc/xdg/autostart")
381 (string-append "DBUSSERVICEDIR=" out "/share/dbus-1/services")
382 (string-append "SYSTEMDDIR=" out "/lib/systemd")
383 (string-append "INITDIR=" out "/etc/rc.d/init.d")
384 (string-append "SELINUXDIR=" out "/etc/selinux")))
386 (modify-phases %standard-phases
388 (delete 'portability)
389 (add-after 'unpack 'enter-dir
390 (lambda _ (chdir ,name) #t))
391 (add-after 'enter-dir 'ignore-/usr-tests
392 (lambda* (#:key inputs #:allow-other-keys)
393 ;; The Makefile decides to build restorecond only if it finds the
394 ;; inotify header somewhere under /usr.
395 (substitute* "Makefile"
398 ;; Rewrite lookup paths for header files.
399 (substitute* '("newrole/Makefile"
402 (("/usr(/include/security/pam_appl.h)" _ file)
403 (string-append (assoc-ref inputs "pam") file))
404 (("/usr(/include/libaudit.h)" _ file)
405 (string-append (assoc-ref inputs "audit") file)))
410 ("libsepol" ,libsepol)
411 ("libselinux" ,libselinux)
412 ("libsemanage" ,libsemanage)))
414 `(("gettext" ,gettext-minimal)))
415 (synopsis "SELinux core utilities")
416 (description "The policycoreutils package contains the core utilities that
417 are required for the basic operation of an SELinux-enabled GNU system and its
418 policies. These utilities include @code{load_policy} to load policies,
419 @code{setfiles} to label file systems, @code{newrole} to switch roles, and
420 @code{run_init} to run service scripts in their proper context.")
421 (license license:gpl2+)))