gnu: mes: Update to 0.11.
[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 ;; These libraries are in "Requires.private" in libselinux.pc.
161 (propagated-inputs
162 `(("libsepol" ,libsepol)
163 ("pcre" ,pcre)))
164 ;; For pywrap phase
165 (inputs
166 `(("python" ,python-wrapper)))
167 ;; These inputs are only needed for the pywrap phase.
168 (native-inputs
169 `(("swig" ,swig)
170 ("pkg-config" ,pkg-config)))
171 (synopsis "SELinux core libraries and utilities")
172 (description
173 "The libselinux library provides an API for SELinux applications to get
174 and set process and file security contexts, and to obtain security policy
175 decisions. It is required for any applications that use the SELinux API, and
176 used by all applications that are SELinux-aware. This package also includes
177 the core SELinux management utilities.")
178 (license license:public-domain)))
179
180 (define-public libsemanage
181 (package (inherit libsepol)
182 (name "libsemanage")
183 (arguments
184 (substitute-keyword-arguments (package-arguments libsepol)
185 ((#:make-flags flags)
186 `(cons* "PYTHON=python3"
187 (string-append "PYSITEDIR="
188 (assoc-ref %outputs "out")
189 "/lib/python"
190 ,(version-major+minor (package-version python))
191 "/site-packages/")
192 ,flags))
193 ((#:phases phases)
194 `(modify-phases ,phases
195 (replace 'enter-dir
196 (lambda _ (chdir ,name) #t))
197 (add-after 'build 'pywrap
198 (lambda* (#:key make-flags #:allow-other-keys)
199 (zero? (apply system* "make" "pywrap" make-flags))))
200 (add-after 'install 'install-pywrap
201 (lambda* (#:key make-flags #:allow-other-keys)
202 (zero? (apply system* "make" "install-pywrap" make-flags))))))))
203 (inputs
204 `(("libsepol" ,libsepol)
205 ("libselinux" ,libselinux)
206 ("audit" ,audit)
207 ("ustr" ,ustr)
208 ;; For pywrap phase
209 ("python" ,python-wrapper)))
210 (native-inputs
211 `(("bison" ,bison)
212 ("flex" ,flex)
213 ;; For pywrap phase
214 ("swig" ,swig)
215 ("pkg-config" ,pkg-config)))
216 (synopsis "SELinux policy management libraries")
217 (description
218 "The libsemanage library provides an API for the manipulation of SELinux
219 binary policies.")
220 (license license:lgpl2.1+)))
221
222 (define-public secilc
223 (package (inherit libsepol)
224 (name "secilc")
225 (arguments
226 (substitute-keyword-arguments (package-arguments libsepol)
227 ((#:make-flags flags)
228 `(let ((docbook (assoc-ref %build-inputs "docbook-xsl")))
229 (cons (string-append "XMLTO=xmlto --skip-validation -x "
230 docbook "/xml/xsl/docbook-xsl-"
231 ,(package-version docbook-xsl)
232 "/manpages/docbook.xsl")
233 ,flags)))
234 ((#:phases phases)
235 `(modify-phases ,phases
236 (replace 'enter-dir
237 (lambda _ (chdir ,name) #t))))))
238 (inputs
239 `(("libsepol" ,libsepol)))
240 (native-inputs
241 `(("xmlto" ,xmlto)
242 ("docbook-xsl" ,docbook-xsl)))
243 (synopsis "SELinux common intermediate language (CIL) compiler")
244 (description "The SELinux CIL compiler is a compiler that converts the
245 @dfn{common intermediate language} (CIL) into a kernel binary policy file.")
246 (license license:bsd-2)))
247
248 (define-public python-sepolgen
249 (package (inherit libsepol)
250 (name "python-sepolgen")
251 (arguments
252 `(#:modules ((srfi srfi-1)
253 (guix build gnu-build-system)
254 (guix build utils))
255 ,@(substitute-keyword-arguments (package-arguments libsepol)
256 ((#:phases phases)
257 `(modify-phases ,phases
258 (replace 'enter-dir
259 (lambda _ (chdir "sepolgen") #t))
260 ;; By default all Python files would be installed to
261 ;; $out/gnu/store/...-python-.../, so we override the
262 ;; PACKAGEDIR to fix this.
263 (add-after 'enter-dir 'fix-target-path
264 (lambda* (#:key inputs outputs #:allow-other-keys)
265 (let ((get-python-version
266 ;; FIXME: copied from python-build-system
267 (lambda (python)
268 (let* ((version (last (string-split python #\-)))
269 (components (string-split version #\.))
270 (major+minor (take components 2)))
271 (string-join major+minor ".")))))
272 (substitute* "src/sepolgen/Makefile"
273 (("^PACKAGEDIR.*")
274 (string-append "PACKAGEDIR="
275 (assoc-ref outputs "out")
276 "/lib/python"
277 (get-python-version
278 (assoc-ref inputs "python"))
279 "/site-packages/sepolgen")))
280 (substitute* "src/share/Makefile"
281 (("\\$\\(DESTDIR\\)") (assoc-ref outputs "out"))))
282 #t)))))))
283 (inputs
284 `(("python" ,python-wrapper)))
285 (native-inputs '())
286 (synopsis "Python module for generating SELinux policies")
287 (description
288 "This package contains a Python module that forms the core of
289 @code{audit2allow}, a part of the package @code{policycoreutils}. The
290 sepolgen library contains: Reference Policy Representation, which are Objects
291 for representing policies and the reference policy interfaces. It has objects
292 and algorithms for representing access and sets of access in an abstract way
293 and searching that access. It also has a parser for reference policy
294 \"headers\". It contains infrastructure for parsing SELinux related messages
295 as produced by the audit system. It has facilities for generating policy
296 based on required access.")
297 ;; GPLv2 only
298 (license license:gpl2)))
299
300 ;; The latest 4.1.x version does not work with the latest 2.6 release of
301 ;; policycoreutils, so we use the last 4.0.x release.
302 (define-public python-setools
303 (package
304 (name "python-setools")
305 (version "4.0.1")
306 (source (origin
307 (method url-fetch)
308 (uri (string-append "https://github.com/TresysTechnology/"
309 "setools/archive/" version ".tar.gz"))
310 (file-name (string-append name "-" version ".tar.gz"))
311 (sha256
312 (base32
313 "1zndpl4ck5c23p7s4sci06db89q1w87jig3jbd4f8s1ggy3lj82c"))))
314 (build-system python-build-system)
315 (arguments
316 `(#:tests? #f ; the test target causes a rebuild
317 #:phases
318 (modify-phases %standard-phases
319 (add-after 'unpack 'set-SEPOL-variable
320 (lambda* (#:key inputs #:allow-other-keys)
321 (setenv "SEPOL"
322 (string-append (assoc-ref inputs "libsepol")
323 "/lib/libsepol.a"))))
324 (add-after 'unpack 'remove-Werror
325 (lambda _
326 (substitute* "setup.py"
327 (("'-Werror',") ""))
328 #t))
329 (add-after 'unpack 'fix-target-paths
330 (lambda* (#:key outputs #:allow-other-keys)
331 (substitute* "setup.py"
332 (("join\\(sys.prefix")
333 (string-append "join(\"" (assoc-ref outputs "out") "/\"")))
334 #t)))))
335 (propagated-inputs
336 `(("python-networkx" ,python-networkx)))
337 (inputs
338 `(("libsepol" ,libsepol)
339 ("libselinux" ,libselinux)))
340 (native-inputs
341 `(("bison" ,bison)
342 ("flex" ,flex)
343 ("swig" ,swig)))
344 (home-page "https://github.com/TresysTechnology/setools")
345 (synopsis "Tools for SELinux policy analysis")
346 (description "SETools is a collection of graphical tools, command-line
347 tools, and libraries designed to facilitate SELinux policy analysis.")
348 ;; Some programs are under GPL, all libraries under LGPL.
349 (license (list license:lgpl2.1+
350 license:gpl2+))))
351
352 (define-public policycoreutils
353 (package (inherit libsepol)
354 (name "policycoreutils")
355 (source
356 (origin (inherit (package-source libsepol))
357 (patches (search-patches "policycoreutils-make-sepolicy-use-python3.patch"))
358 (patch-flags '("-p1" "-d" "policycoreutils"))))
359 (arguments
360 `(#:test-target "test"
361 #:make-flags
362 (let ((out (assoc-ref %outputs "out")))
363 (list "CC=gcc"
364 (string-append "PREFIX=" out)
365 (string-append "LOCALEDIR=" out "/share/locale")
366 (string-append "BASHCOMPLETIONDIR=" out
367 "/share/bash-completion/completions")
368 "INSTALL=install -c -p"
369 "INSTALL_DIR=install -d"
370 ;; These ones are needed because some Makefiles define the
371 ;; directories relative to DESTDIR, not relative to PREFIX.
372 (string-append "SBINDIR=" out "/sbin")
373 (string-append "ETCDIR=" out "/etc")
374 (string-append "SYSCONFDIR=" out "/etc/sysconfig")
375 (string-append "MAN5DIR=" out "/share/man/man5")
376 (string-append "INSTALL_NLS_DIR=" out "/share/locale")
377 (string-append "AUTOSTARTDIR=" out "/etc/xdg/autostart")
378 (string-append "DBUSSERVICEDIR=" out "/share/dbus-1/services")
379 (string-append "SYSTEMDDIR=" out "/lib/systemd")
380 (string-append "INITDIR=" out "/etc/rc.d/init.d")
381 (string-append "SELINUXDIR=" out "/etc/selinux")))
382 #:phases
383 (modify-phases %standard-phases
384 (delete 'configure)
385 (add-after 'unpack 'enter-dir
386 (lambda _ (chdir ,name) #t))
387 (add-after 'enter-dir 'ignore-/usr-tests
388 (lambda* (#:key inputs #:allow-other-keys)
389 ;; The Makefile decides to build restorecond only if it finds the
390 ;; inotify header somewhere under /usr.
391 (substitute* "Makefile"
392 (("ifeq.*") "")
393 (("endif.*") ""))
394 ;; Rewrite lookup paths for header files.
395 (substitute* '("newrole/Makefile"
396 "setfiles/Makefile"
397 "run_init/Makefile")
398 (("/usr(/include/security/pam_appl.h)" _ file)
399 (string-append (assoc-ref inputs "pam") file))
400 (("/usr(/include/libaudit.h)" _ file)
401 (string-append (assoc-ref inputs "audit") file)))
402 #t))
403 (add-after 'enter-dir 'fix-glib-cflags
404 (lambda* (#:key inputs #:allow-other-keys)
405 (substitute* "restorecond/Makefile"
406 (("/usr(/include/glib-2.0|/lib/glib-2.0/include)" _ path)
407 (string-append (assoc-ref inputs "glib") path))
408 (("/usr(/include/dbus-1.0|/lib/dbus-1.0/include)" _ path)
409 (string-append (assoc-ref inputs "dbus") path
410 " -I"
411 (assoc-ref inputs "dbus-glib") path)))
412 #t))
413 (add-after 'enter-dir 'fix-linkage-with-libsepol
414 (lambda* (#:key inputs #:allow-other-keys)
415 (substitute* '("semodule_deps/Makefile"
416 "sepolgen-ifgen/Makefile")
417 (("\\$\\(LIBDIR\\)")
418 (string-append (assoc-ref inputs "libsepol") "/lib/")))))
419 (add-after 'enter-dir 'fix-target-paths
420 (lambda* (#:key outputs #:allow-other-keys)
421 (let ((out (assoc-ref outputs "out")))
422 (substitute* "audit2allow/sepolgen-ifgen"
423 (("ATTR_HELPER = \"/usr/bin/sepolgen-ifgen-attr-helper\"")
424 (string-append "ATTR_HELPER = \"" out
425 "/bin/sepolgen-ifgen-attr-helper\"")))
426 (substitute* "sepolicy/sepolicy/__init__.py"
427 (("/usr/bin/sepolgen-ifgen")
428 (string-append out "/bin/sepolgen-ifgen")))
429 (substitute* "sepolicy/Makefile"
430 ;; By default all Python files would be installed to
431 ;; $out/gnu/store/...-python-.../.
432 (("setup.py install.*$")
433 (string-append "setup.py install --prefix=" out "\n"))
434 (("\\$\\(DESTDIR\\)/etc")
435 (string-append out "/etc"))
436 (("\\$\\(DESTDIR\\)/usr") out)))
437 #t))
438 (add-after 'install 'wrap-python-tools
439 (lambda* (#:key outputs #:allow-other-keys)
440 (let* ((out (assoc-ref outputs "out"))
441 (var (string-append out "/lib/python"
442 ,(version-major+minor (package-version python))
443 "/site-packages:"
444 (getenv "PYTHONPATH"))))
445 ;; The scripts' shebangs tell Python to ignore the PYTHONPATH,
446 ;; so we need to patch them before wrapping.
447 (for-each (lambda (file)
448 (let ((path (string-append out "/" file)))
449 (substitute* path
450 (("bin/python -Es") "bin/python -s"))
451 (wrap-program path
452 `("PYTHONPATH" ":" prefix (,var)))))
453 '("bin/audit2allow"
454 "bin/chcat"
455 "bin/sandbox"
456 "bin/sepolgen-ifgen"
457 "bin/sepolicy"
458 "sbin/semanage")))
459 #t)))))
460 (inputs
461 `(("python" ,python-wrapper)
462 ("audit" ,audit)
463 ("pam" ,linux-pam)
464 ("libsepol" ,libsepol)
465 ("libselinux" ,libselinux)
466 ("libsemanage" ,libsemanage)
467 ("python-sepolgen" ,python-sepolgen)
468 ("python-setools" ,python-setools)
469 ("python-ipy" ,python-ipy)
470 ("libcap-ng" ,libcap-ng)
471 ("pcre" ,pcre)
472 ("dbus" ,dbus)
473 ("dbus-glib" ,dbus-glib)
474 ("glib" ,glib)))
475 (native-inputs
476 `(("gettext" ,gettext-minimal)))
477 (synopsis "SELinux core utilities")
478 (description "The policycoreutils package contains the core utilities that
479 are required for the basic operation of an SELinux-enabled GNU system and its
480 policies. These utilities include @code{load_policy} to load policies,
481 @code{setfiles} to label file systems, @code{newrole} to switch roles, and
482 @code{run_init} to run service scripts in their proper context.")
483 (license license:gpl2+)))