gnu: Add lierolibre.
[jackhill/guix/guix.git] / gnu / packages / selinux.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2016, 2017 Ricardo Wurmus <rekado@elephly.net>
3 ;;;
4 ;;; This file is part of GNU Guix.
5 ;;;
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.
10 ;;;
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.
15 ;;;
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/>.
18
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 utils)
24 #:use-module (guix build-system gnu)
25 #:use-module (guix build-system python)
26 #:use-module (gnu packages)
27 #:use-module (gnu packages admin)
28 #:use-module (gnu packages bison)
29 #:use-module (gnu packages docbook)
30 #:use-module (gnu packages flex)
31 #:use-module (gnu packages gettext)
32 #:use-module (gnu packages glib)
33 #:use-module (gnu packages linux)
34 #:use-module (gnu packages networking)
35 #:use-module (gnu packages pcre)
36 #:use-module (gnu packages pkg-config)
37 #:use-module (gnu packages python)
38 #:use-module (gnu packages swig)
39 #:use-module (gnu packages textutils)
40 #:use-module (gnu packages xml))
41
42 ;; Update the SELinux packages together!
43
44 (define-public libsepol
45 (package
46 (name "libsepol")
47 (version "2.6")
48 (source (let ((release "20161014"))
49 (origin
50 (method url-fetch)
51 (uri (string-append "https://github.com/SELinuxProject/selinux/"
52 "archive/" release ".tar.gz"))
53 (file-name (string-append "selinux-" release ".tar.gz"))
54 (sha256
55 (base32
56 "1dpwynfb6n31928343blac4159g4jbrwxdp61q5yffmxpy3c3czi")))))
57 (build-system gnu-build-system)
58 (arguments
59 `(#:tests? #f ; tests require checkpolicy, which requires libsepol
60 #:test-target "test"
61 #:make-flags
62 (let ((out (assoc-ref %outputs "out")))
63 (list (string-append "PREFIX=" out)
64 (string-append "DESTDIR=" out)
65 (string-append "MAN3DIR=" out "/share/man/man3")
66 (string-append "MAN5DIR=" out "/share/man/man5")
67 (string-append "MAN8DIR=" out "/share/man/man8")
68 (string-append "LDFLAGS=-Wl,-rpath=" out "/lib")
69 "CC=gcc"))
70 #:phases
71 (modify-phases %standard-phases
72 (delete 'configure)
73 (add-after 'unpack 'enter-dir
74 (lambda _ (chdir ,name) #t)))))
75 (native-inputs
76 `(("flex" ,flex)))
77 (home-page "https://selinuxproject.org/")
78 (synopsis "Library for manipulating SELinux policies")
79 (description
80 "The libsepol library provides an API for the manipulation of SELinux
81 binary policies. It is used by @code{checkpolicy} (the policy compiler) and
82 similar tools, and programs such as @code{load_policy}, which must perform
83 specific transformations on binary policies (for example, customizing policy
84 boolean settings).")
85 (license license:lgpl2.1+)))
86
87 (define-public checkpolicy
88 (package (inherit libsepol)
89 (name "checkpolicy")
90 (arguments
91 `(#:tests? #f ; there is no check target
92 #:make-flags
93 (let ((out (assoc-ref %outputs "out")))
94 (list (string-append "PREFIX=" out)
95 (string-append "LDLIBS="
96 (assoc-ref %build-inputs "libsepol")
97 "/lib/libsepol.a "
98 (assoc-ref %build-inputs "flex")
99 "/lib/libfl.a")
100 "CC=gcc"))
101 #:phases
102 (modify-phases %standard-phases
103 (delete 'configure)
104 (add-after 'unpack 'enter-dir
105 (lambda _ (chdir ,name) #t)))))
106 (inputs
107 `(("libsepol" ,libsepol)))
108 (native-inputs
109 `(("bison" ,bison)
110 ("flex" ,flex)))
111 (synopsis "Check SELinux security policy configurations and modules")
112 (description
113 "This package provides the tools \"checkpolicy\" and \"checkmodule\".
114 Checkpolicy is a program that checks and compiles a SELinux security policy
115 configuration into a binary representation that can be loaded into the kernel.
116 Checkmodule is a program that checks and compiles a SELinux security policy
117 module into a binary representation.")
118 ;; GPLv2 only
119 (license license:gpl2)))
120
121 (define-public libselinux
122 (package (inherit libsepol)
123 (name "libselinux")
124 (arguments
125 (substitute-keyword-arguments (package-arguments libsepol)
126 ((#:make-flags flags)
127 `(cons* "PYTHON=python3"
128 (string-append "PYSITEDIR="
129 (assoc-ref %outputs "out")
130 "/lib/python"
131 ,(version-major+minor (package-version python))
132 "/site-packages/")
133 ,flags))
134 ((#:phases phases)
135 `(modify-phases ,phases
136 (replace 'enter-dir
137 (lambda _ (chdir ,name) #t))
138 ;; libsepol.a is not located in this package's LIBDIR.
139 (add-after 'enter-dir 'patch-libsepol-path
140 (lambda* (#:key inputs #:allow-other-keys)
141 (substitute* "src/Makefile"
142 (("\\$\\(LIBDIR\\)/libsepol.a")
143 (string-append (assoc-ref inputs "libsepol")
144 "/lib/libsepol.a")))
145 #t))
146 (add-after 'enter-dir 'remove-Werror
147 (lambda _
148 ;; GCC complains about the fact that the output does not (yet)
149 ;; have an "include" directory, even though it is referenced.
150 (substitute* '("src/Makefile"
151 "utils/Makefile")
152 (("-Werror ") ""))
153 #t))
154 (add-after 'build 'pywrap
155 (lambda* (#:key make-flags #:allow-other-keys)
156 (zero? (apply system* "make" "pywrap" make-flags))))
157 (add-after 'install 'install-pywrap
158 (lambda* (#:key make-flags #:allow-other-keys)
159 (zero? (apply system* "make" "install-pywrap" make-flags))))))))
160 (inputs
161 `(("libsepol" ,libsepol)
162 ("pcre" ,pcre)
163 ;; For pywrap phase
164 ("python" ,python-wrapper)))
165 ;; These inputs are only needed for the pywrap phase.
166 (native-inputs
167 `(("swig" ,swig)
168 ("pkg-config" ,pkg-config)))
169 (synopsis "SELinux core libraries and utilities")
170 (description
171 "The libselinux library provides an API for SELinux applications to get
172 and set process and file security contexts, and to obtain security policy
173 decisions. It is required for any applications that use the SELinux API, and
174 used by all applications that are SELinux-aware. This package also includes
175 the core SELinux management utilities.")
176 (license license:public-domain)))
177
178 (define-public libsemanage
179 (package (inherit libsepol)
180 (name "libsemanage")
181 (arguments
182 (substitute-keyword-arguments (package-arguments libsepol)
183 ((#:make-flags flags)
184 `(cons* "PYTHON=python3"
185 (string-append "PYSITEDIR="
186 (assoc-ref %outputs "out")
187 "/lib/python"
188 ,(version-major+minor (package-version python))
189 "/site-packages/")
190 ,flags))
191 ((#:phases phases)
192 `(modify-phases ,phases
193 (replace 'enter-dir
194 (lambda _ (chdir ,name) #t))
195 (add-after 'build 'pywrap
196 (lambda* (#:key make-flags #:allow-other-keys)
197 (zero? (apply system* "make" "pywrap" make-flags))))
198 (add-after 'install 'install-pywrap
199 (lambda* (#:key make-flags #:allow-other-keys)
200 (zero? (apply system* "make" "install-pywrap" make-flags))))))))
201 (inputs
202 `(("libsepol" ,libsepol)
203 ("libselinux" ,libselinux)
204 ("audit" ,audit)
205 ("ustr" ,ustr)
206 ;; For pywrap phase
207 ("python" ,python-wrapper)))
208 (native-inputs
209 `(("bison" ,bison)
210 ("flex" ,flex)
211 ;; For pywrap phase
212 ("swig" ,swig)
213 ("pkg-config" ,pkg-config)))
214 (synopsis "SELinux policy management libraries")
215 (description
216 "The libsemanage library provides an API for the manipulation of SELinux
217 binary policies.")
218 (license license:lgpl2.1+)))
219
220 (define-public secilc
221 (package (inherit libsepol)
222 (name "secilc")
223 (arguments
224 (substitute-keyword-arguments (package-arguments libsepol)
225 ((#:make-flags flags)
226 `(let ((docbook (assoc-ref %build-inputs "docbook-xsl")))
227 (cons (string-append "XMLTO=xmlto --skip-validation -x "
228 docbook "/xml/xsl/docbook-xsl-"
229 ,(package-version docbook-xsl)
230 "/manpages/docbook.xsl")
231 ,flags)))
232 ((#:phases phases)
233 `(modify-phases ,phases
234 (replace 'enter-dir
235 (lambda _ (chdir ,name) #t))))))
236 (inputs
237 `(("libsepol" ,libsepol)))
238 (native-inputs
239 `(("xmlto" ,xmlto)
240 ("docbook-xsl" ,docbook-xsl)))
241 (synopsis "SELinux common intermediate language (CIL) compiler")
242 (description "The SELinux CIL compiler is a compiler that converts the
243 @dfn{common intermediate language} (CIL) into a kernel binary policy file.")
244 (license license:bsd-2)))
245
246 (define-public python-sepolgen
247 (package (inherit libsepol)
248 (name "python-sepolgen")
249 (arguments
250 `(#:modules ((srfi srfi-1)
251 (guix build gnu-build-system)
252 (guix build utils))
253 ,@(substitute-keyword-arguments (package-arguments libsepol)
254 ((#:phases phases)
255 `(modify-phases ,phases
256 (replace 'enter-dir
257 (lambda _ (chdir "sepolgen") #t))
258 ;; By default all Python files would be installed to
259 ;; $out/gnu/store/...-python-.../, so we override the
260 ;; PACKAGEDIR to fix this.
261 (add-after 'enter-dir 'fix-target-path
262 (lambda* (#:key inputs outputs #:allow-other-keys)
263 (let ((get-python-version
264 ;; FIXME: copied from python-build-system
265 (lambda (python)
266 (let* ((version (last (string-split python #\-)))
267 (components (string-split version #\.))
268 (major+minor (take components 2)))
269 (string-join major+minor ".")))))
270 (substitute* "src/sepolgen/Makefile"
271 (("^PACKAGEDIR.*")
272 (string-append "PACKAGEDIR="
273 (assoc-ref outputs "out")
274 "/lib/python"
275 (get-python-version
276 (assoc-ref inputs "python"))
277 "/site-packages/sepolgen")))
278 (substitute* "src/share/Makefile"
279 (("\\$\\(DESTDIR\\)") (assoc-ref outputs "out"))))
280 #t)))))))
281 (inputs
282 `(("python" ,python-wrapper)))
283 (native-inputs '())
284 (synopsis "Python module for generating SELinux policies")
285 (description
286 "This package contains a Python module that forms the core of
287 @code{audit2allow}, a part of the package @code{policycoreutils}. The
288 sepolgen library contains: Reference Policy Representation, which are Objects
289 for representing policies and the reference policy interfaces. It has objects
290 and algorithms for representing access and sets of access in an abstract way
291 and searching that access. It also has a parser for reference policy
292 \"headers\". It contains infrastructure for parsing SELinux related messages
293 as produced by the audit system. It has facilities for generating policy
294 based on required access.")
295 ;; GPLv2 only
296 (license license:gpl2)))
297
298 ;; The latest 4.1.x version does not work with the latest 2.6 release of
299 ;; policycoreutils, so we use the last 4.0.x release.
300 (define-public python-setools
301 (package
302 (name "python-setools")
303 (version "4.0.1")
304 (source (origin
305 (method url-fetch)
306 (uri (string-append "https://github.com/TresysTechnology/"
307 "setools/archive/" version ".tar.gz"))
308 (file-name (string-append name "-" version ".tar.gz"))
309 (sha256
310 (base32
311 "1zndpl4ck5c23p7s4sci06db89q1w87jig3jbd4f8s1ggy3lj82c"))))
312 (build-system python-build-system)
313 (arguments
314 `(#:tests? #f ; the test target causes a rebuild
315 #:phases
316 (modify-phases %standard-phases
317 (add-after 'unpack 'set-SEPOL-variable
318 (lambda* (#:key inputs #:allow-other-keys)
319 (setenv "SEPOL"
320 (string-append (assoc-ref inputs "libsepol")
321 "/lib/libsepol.a"))))
322 (add-after 'unpack 'remove-Werror
323 (lambda _
324 (substitute* "setup.py"
325 (("'-Werror',") ""))
326 #t))
327 (add-after 'unpack 'fix-target-paths
328 (lambda* (#:key outputs #:allow-other-keys)
329 (substitute* "setup.py"
330 (("join\\(sys.prefix")
331 (string-append "join(\"" (assoc-ref outputs "out") "/\"")))
332 #t)))))
333 (propagated-inputs
334 `(("python-networkx" ,python-networkx)))
335 (inputs
336 `(("libsepol" ,libsepol)
337 ("libselinux" ,libselinux)))
338 (native-inputs
339 `(("bison" ,bison)
340 ("flex" ,flex)
341 ("swig" ,swig)))
342 (home-page "https://github.com/TresysTechnology/setools")
343 (synopsis "Tools for SELinux policy analysis")
344 (description "SETools is a collection of graphical tools, command-line
345 tools, and libraries designed to facilitate SELinux policy analysis.")
346 ;; Some programs are under GPL, all libraries under LGPL.
347 (license (list license:lgpl2.1+
348 license:gpl2+))))
349
350 (define-public policycoreutils
351 (package (inherit libsepol)
352 (name "policycoreutils")
353 (source
354 (origin (inherit (package-source libsepol))
355 (patches (search-patches "policycoreutils-make-sepolicy-use-python3.patch"))
356 (patch-flags '("-p1" "-d" "policycoreutils"))))
357 (arguments
358 `(#:test-target "test"
359 #:make-flags
360 (let ((out (assoc-ref %outputs "out")))
361 (list "CC=gcc"
362 (string-append "PREFIX=" out)
363 (string-append "LOCALEDIR=" out "/share/locale")
364 (string-append "BASHCOMPLETIONDIR=" out
365 "/share/bash-completion/completions")
366 "INSTALL=install -c -p"
367 "INSTALL_DIR=install -d"
368 ;; These ones are needed because some Makefiles define the
369 ;; directories relative to DESTDIR, not relative to PREFIX.
370 (string-append "SBINDIR=" out "/sbin")
371 (string-append "ETCDIR=" out "/etc")
372 (string-append "SYSCONFDIR=" out "/etc/sysconfig")
373 (string-append "MAN5DIR=" out "/share/man/man5")
374 (string-append "INSTALL_NLS_DIR=" out "/share/locale")
375 (string-append "AUTOSTARTDIR=" out "/etc/xdg/autostart")
376 (string-append "DBUSSERVICEDIR=" out "/share/dbus-1/services")
377 (string-append "SYSTEMDDIR=" out "/lib/systemd")
378 (string-append "INITDIR=" out "/etc/rc.d/init.d")
379 (string-append "SELINUXDIR=" out "/etc/selinux")))
380 #:phases
381 (modify-phases %standard-phases
382 (delete 'configure)
383 (add-after 'unpack 'enter-dir
384 (lambda _ (chdir ,name) #t))
385 (add-after 'enter-dir 'ignore-/usr-tests
386 (lambda* (#:key inputs #:allow-other-keys)
387 ;; The Makefile decides to build restorecond only if it finds the
388 ;; inotify header somewhere under /usr.
389 (substitute* "Makefile"
390 (("ifeq.*") "")
391 (("endif.*") ""))
392 ;; Rewrite lookup paths for header files.
393 (substitute* '("newrole/Makefile"
394 "setfiles/Makefile"
395 "run_init/Makefile")
396 (("/usr(/include/security/pam_appl.h)" _ file)
397 (string-append (assoc-ref inputs "pam") file))
398 (("/usr(/include/libaudit.h)" _ file)
399 (string-append (assoc-ref inputs "audit") file)))
400 #t))
401 (add-after 'enter-dir 'fix-glib-cflags
402 (lambda* (#:key inputs #:allow-other-keys)
403 (substitute* "restorecond/Makefile"
404 (("/usr(/include/glib-2.0|/lib/glib-2.0/include)" _ path)
405 (string-append (assoc-ref inputs "glib") path))
406 (("/usr(/include/dbus-1.0|/lib/dbus-1.0/include)" _ path)
407 (string-append (assoc-ref inputs "dbus") path
408 " -I"
409 (assoc-ref inputs "dbus-glib") path)))
410 #t))
411 (add-after 'enter-dir 'fix-linkage-with-libsepol
412 (lambda* (#:key inputs #:allow-other-keys)
413 (substitute* '("semodule_deps/Makefile"
414 "sepolgen-ifgen/Makefile")
415 (("\\$\\(LIBDIR\\)")
416 (string-append (assoc-ref inputs "libsepol") "/lib/")))))
417 (add-after 'enter-dir 'fix-target-paths
418 (lambda* (#:key outputs #:allow-other-keys)
419 (let ((out (assoc-ref outputs "out")))
420 (substitute* "audit2allow/sepolgen-ifgen"
421 (("ATTR_HELPER = \"/usr/bin/sepolgen-ifgen-attr-helper\"")
422 (string-append "ATTR_HELPER = \"" out
423 "/bin/sepolgen-ifgen-attr-helper\"")))
424 (substitute* "sepolicy/sepolicy/__init__.py"
425 (("/usr/bin/sepolgen-ifgen")
426 (string-append out "/bin/sepolgen-ifgen")))
427 (substitute* "sepolicy/Makefile"
428 ;; By default all Python files would be installed to
429 ;; $out/gnu/store/...-python-.../.
430 (("setup.py install.*$")
431 (string-append "setup.py install --prefix=" out "\n"))
432 (("\\$\\(DESTDIR\\)/etc")
433 (string-append out "/etc"))
434 (("\\$\\(DESTDIR\\)/usr") out)))
435 #t))
436 (add-after 'install 'wrap-python-tools
437 (lambda* (#:key outputs #:allow-other-keys)
438 (let* ((out (assoc-ref outputs "out"))
439 (var (string-append out "/lib/python"
440 ,(version-major+minor (package-version python))
441 "/site-packages:"
442 (getenv "PYTHONPATH"))))
443 ;; The scripts' shebangs tell Python to ignore the PYTHONPATH,
444 ;; so we need to patch them before wrapping.
445 (for-each (lambda (file)
446 (let ((path (string-append out "/" file)))
447 (substitute* path
448 (("bin/python -Es") "bin/python -s"))
449 (wrap-program path
450 `("PYTHONPATH" ":" prefix (,var)))))
451 '("bin/audit2allow"
452 "bin/chcat"
453 "bin/sandbox"
454 "bin/sepolgen-ifgen"
455 "bin/sepolicy"
456 "sbin/semanage")))
457 #t)))))
458 (inputs
459 `(("python" ,python-wrapper)
460 ("audit" ,audit)
461 ("pam" ,linux-pam)
462 ("libsepol" ,libsepol)
463 ("libselinux" ,libselinux)
464 ("libsemanage" ,libsemanage)
465 ("python-sepolgen" ,python-sepolgen)
466 ("python-setools" ,python-setools)
467 ("python-ipy" ,python-ipy)
468 ("libcap-ng" ,libcap-ng)
469 ("pcre" ,pcre)
470 ("dbus" ,dbus)
471 ("dbus-glib" ,dbus-glib)
472 ("glib" ,glib)))
473 (native-inputs
474 `(("gettext" ,gettext-minimal)))
475 (synopsis "SELinux core utilities")
476 (description "The policycoreutils package contains the core utilities that
477 are required for the basic operation of an SELinux-enabled GNU system and its
478 policies. These utilities include @code{load_policy} to load policies,
479 @code{setfiles} to label file systems, @code{newrole} to switch roles, and
480 @code{run_init} to run service scripts in their proper context.")
481 (license license:gpl2+)))