gnu: python-mako: Update to 1.0.7.
[jackhill/guix/guix.git] / gnu / packages / selinux.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2016, 2017, 2018 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 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))
42
43 ;; Update the SELinux packages together!
44
45 (define-public libsepol
46 (package
47 (name "libsepol")
48 (version "2.7")
49 (source (let ((release "20170804"))
50 (origin
51 (method git-fetch)
52 (uri (git-reference
53 (url "https://github.com/SELinuxProject/selinux.git")
54 (commit release)))
55 (file-name (string-append "selinux-" release "-checkout"))
56 (sha256
57 (base32
58 "1l1nn8bx08v4cxkw5kb0wgr61rfqj5ra9dh1dy5jslillj93vivq")))))
59 (build-system gnu-build-system)
60 (arguments
61 `(#:tests? #f ; tests require checkpolicy, which requires libsepol
62 #:test-target "test"
63 #:make-flags
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")
71 "CC=gcc"))
72 #:phases
73 (modify-phases %standard-phases
74 (delete 'configure)
75 (add-after 'unpack 'enter-dir
76 (lambda _ (chdir ,name) #t))
77 (add-after 'enter-dir 'portability
78 (lambda _
79 (substitute* "src/ibpkeys.c"
80 (("#include \"ibpkey_internal.h\"" line)
81 (string-append line "\n#include <inttypes.h>\n"))
82 (("%#lx") "%#\" PRIx64 \""))
83 #t)))))
84 (native-inputs
85 `(("flex" ,flex)))
86 (home-page "https://selinuxproject.org/")
87 (synopsis "Library for manipulating SELinux policies")
88 (description
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
93 boolean settings).")
94 (license license:lgpl2.1+)))
95
96 (define-public checkpolicy
97 (package (inherit libsepol)
98 (name "checkpolicy")
99 (arguments
100 `(#:tests? #f ; there is no check target
101 #:make-flags
102 (let ((out (assoc-ref %outputs "out")))
103 (list (string-append "PREFIX=" out)
104 (string-append "LIBSEPOLA="
105 (assoc-ref %build-inputs "libsepol")
106 "/lib/libsepol.a")
107 "CC=gcc"))
108 #:phases
109 (modify-phases %standard-phases
110 (delete 'configure)
111 (delete 'portability)
112 (add-after 'unpack 'enter-dir
113 (lambda _ (chdir ,name) #t)))))
114 (inputs
115 `(("libsepol" ,libsepol)))
116 (native-inputs
117 `(("bison" ,bison)
118 ("flex" ,flex)))
119 (synopsis "Check SELinux security policy configurations and modules")
120 (description
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.")
126 ;; GPLv2 only
127 (license license:gpl2)))
128
129 (define-public libselinux
130 (package (inherit libsepol)
131 (name "libselinux")
132 (arguments
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")
138 "/lib/libsepol.a")
139 (string-append "PYSITEDIR="
140 (assoc-ref %outputs "out")
141 "/lib/python"
142 ,(version-major+minor (package-version python))
143 "/site-packages/")
144 ,flags))
145 ((#:phases phases)
146 `(modify-phases ,phases
147 (delete 'portability)
148 (replace 'enter-dir
149 (lambda _ (chdir ,name) #t))
150 (add-after 'enter-dir 'remove-Werror
151 (lambda _
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"
155 "utils/Makefile")
156 (("-Werror ") ""))
157 #t))
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.
165 (propagated-inputs
166 `(("libsepol" ,libsepol)
167 ("pcre" ,pcre)))
168 ;; For pywrap phase
169 (inputs
170 `(("python" ,python-wrapper)))
171 ;; These inputs are only needed for the pywrap phase.
172 (native-inputs
173 `(("swig" ,swig)
174 ("pkg-config" ,pkg-config)))
175 (synopsis "SELinux core libraries and utilities")
176 (description
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)))
183
184 (define-public libsemanage
185 (package (inherit libsepol)
186 (name "libsemanage")
187 (arguments
188 (substitute-keyword-arguments (package-arguments libsepol)
189 ((#:make-flags flags)
190 `(cons* "PYTHON=python3"
191 (string-append "PYSITEDIR="
192 (assoc-ref %outputs "out")
193 "/lib/python"
194 ,(version-major+minor (package-version python))
195 "/site-packages/")
196 ,flags))
197 ((#:phases phases)
198 `(modify-phases ,phases
199 (delete 'portability)
200 (replace 'enter-dir
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))))))))
208 (inputs
209 `(("libsepol" ,libsepol)
210 ("libselinux" ,libselinux)
211 ("audit" ,audit)
212 ("ustr" ,ustr)
213 ;; For pywrap phase
214 ("python" ,python-wrapper)))
215 (native-inputs
216 `(("bison" ,bison)
217 ("flex" ,flex)
218 ;; For pywrap phase
219 ("swig" ,swig)
220 ("pkg-config" ,pkg-config)))
221 (synopsis "SELinux policy management libraries")
222 (description
223 "The libsemanage library provides an API for the manipulation of SELinux
224 binary policies.")
225 (license license:lgpl2.1+)))
226
227 (define-public secilc
228 (package (inherit libsepol)
229 (name "secilc")
230 (arguments
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")
238 ,flags)))
239 ((#:phases phases)
240 `(modify-phases ,phases
241 (delete 'portability)
242 (replace 'enter-dir
243 (lambda _ (chdir ,name) #t))))))
244 (inputs
245 `(("libsepol" ,libsepol)))
246 (native-inputs
247 `(("xmlto" ,xmlto)
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)))
253
254 (define-public python-sepolgen
255 (package (inherit libsepol)
256 (name "python-sepolgen")
257 (arguments
258 `(#:modules ((srfi srfi-1)
259 (guix build gnu-build-system)
260 (guix build utils))
261 ,@(substitute-keyword-arguments (package-arguments libsepol)
262 ((#:phases phases)
263 `(modify-phases ,phases
264 (delete 'portability)
265 (replace 'enter-dir
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
274 (lambda (python)
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"
280 (("^PACKAGEDIR.*")
281 (string-append "PACKAGEDIR="
282 (assoc-ref outputs "out")
283 "/lib/python"
284 (get-python-version
285 (assoc-ref inputs "python"))
286 "/site-packages/sepolgen")))
287 (substitute* "src/share/Makefile"
288 (("\\$\\(DESTDIR\\)") (assoc-ref outputs "out"))))
289 #t)))))))
290 (inputs
291 `(("python" ,python-wrapper)))
292 (native-inputs '())
293 (synopsis "Python module for generating SELinux policies")
294 (description
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.")
304 ;; GPLv2 only
305 (license license:gpl2)))
306
307 (define-public python-setools
308 (package
309 (name "python-setools")
310 (version "4.1.1")
311 (source (origin
312 (method git-fetch)
313 (uri (git-reference
314 (url "https://github.com/TresysTechnology/setools.git")
315 (commit version)))
316 (file-name (string-append name "-" version "-checkout"))
317 (sha256
318 (base32
319 "0459xxly6zzqc5azcwk3rbbcxvj60dq08f8z6xr05y7dsbb16cg6"))))
320 (build-system python-build-system)
321 (arguments
322 `(#:tests? #f ; the test target causes a rebuild
323 #:phases
324 (modify-phases %standard-phases
325 (delete 'portability)
326 (add-after 'unpack 'set-SEPOL-variable
327 (lambda* (#:key inputs #:allow-other-keys)
328 (setenv "SEPOL"
329 (string-append (assoc-ref inputs "libsepol")
330 "/lib/libsepol.a"))))
331 (add-after 'unpack 'remove-Werror
332 (lambda _
333 (substitute* "setup.py"
334 (("'-Werror',") ""))
335 #t))
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") "/\"")))
341 #t)))))
342 (propagated-inputs
343 `(("python-networkx" ,python-networkx)))
344 (inputs
345 `(("libsepol" ,libsepol)
346 ("libselinux" ,libselinux)))
347 (native-inputs
348 `(("bison" ,bison)
349 ("flex" ,flex)
350 ("swig" ,swig)))
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+
357 license:gpl2+))))
358
359 (define-public policycoreutils
360 (package (inherit libsepol)
361 (name "policycoreutils")
362 (arguments
363 `(#:test-target "test"
364 #:make-flags
365 (let ((out (assoc-ref %outputs "out")))
366 (list "CC=gcc"
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")))
385 #:phases
386 (modify-phases %standard-phases
387 (delete 'configure)
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"
396 (("ifeq.*") "")
397 (("endif.*") ""))
398 ;; Rewrite lookup paths for header files.
399 (substitute* '("newrole/Makefile"
400 "setfiles/Makefile"
401 "run_init/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)))
406 #t)))))
407 (inputs
408 `(("audit" ,audit)
409 ("pam" ,linux-pam)
410 ("libsepol" ,libsepol)
411 ("libselinux" ,libselinux)
412 ("libsemanage" ,libsemanage)))
413 (native-inputs
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+)))