Merge branch 'master' into staging
[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 ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
4 ;;;
5 ;;; This file is part of GNU Guix.
6 ;;;
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
11 ;;;
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
16 ;;;
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19
20 (define-module (gnu packages selinux)
21 #:use-module ((guix licenses) #:prefix license:)
22 #:use-module (guix packages)
23 #:use-module (guix download)
24 #:use-module (guix git-download)
25 #:use-module (guix utils)
26 #:use-module (guix build-system gnu)
27 #:use-module (guix build-system python)
28 #:use-module (gnu packages)
29 #:use-module (gnu packages admin)
30 #:use-module (gnu packages bison)
31 #:use-module (gnu packages docbook)
32 #:use-module (gnu packages flex)
33 #:use-module (gnu packages gettext)
34 #:use-module (gnu packages glib)
35 #:use-module (gnu packages linux)
36 #:use-module (gnu packages networking)
37 #:use-module (gnu packages pcre)
38 #:use-module (gnu packages pkg-config)
39 #:use-module (gnu packages python)
40 #:use-module (gnu packages python-xyz)
41 #:use-module (gnu packages swig)
42 #:use-module (gnu packages textutils)
43 #:use-module (gnu packages xml))
44
45 ;; Update the SELinux packages together!
46
47 (define-public libsepol
48 (package
49 (name "libsepol")
50 (version "2.7")
51 (source (let ((release "20170804"))
52 (origin
53 (method git-fetch)
54 (uri (git-reference
55 (url "https://github.com/SELinuxProject/selinux.git")
56 (commit release)))
57 (file-name (string-append "selinux-" release "-checkout"))
58 (sha256
59 (base32
60 "1l1nn8bx08v4cxkw5kb0wgr61rfqj5ra9dh1dy5jslillj93vivq")))))
61 (build-system gnu-build-system)
62 (arguments
63 `(#:tests? #f ; tests require checkpolicy, which requires libsepol
64 #:test-target "test"
65 #:make-flags
66 (let ((out (assoc-ref %outputs "out")))
67 (list (string-append "PREFIX=" out)
68 (string-append "DESTDIR=" out)
69 (string-append "MAN3DIR=" out "/share/man/man3")
70 (string-append "MAN5DIR=" out "/share/man/man5")
71 (string-append "MAN8DIR=" out "/share/man/man8")
72 (string-append "LDFLAGS=-Wl,-rpath=" out "/lib")
73 "CC=gcc"))
74 #:phases
75 (modify-phases %standard-phases
76 (delete 'configure)
77 (add-after 'unpack 'enter-dir
78 (lambda _ (chdir ,name) #t))
79 (add-after 'enter-dir 'portability
80 (lambda _
81 (substitute* "src/ibpkeys.c"
82 (("#include \"ibpkey_internal.h\"" line)
83 (string-append line "\n#include <inttypes.h>\n"))
84 (("%#lx") "%#\" PRIx64 \""))
85 #t)))))
86 (native-inputs
87 `(("flex" ,flex)))
88 (home-page "https://selinuxproject.org/")
89 (synopsis "Library for manipulating SELinux policies")
90 (description
91 "The libsepol library provides an API for the manipulation of SELinux
92 binary policies. It is used by @code{checkpolicy} (the policy compiler) and
93 similar tools, and programs such as @code{load_policy}, which must perform
94 specific transformations on binary policies (for example, customizing policy
95 boolean settings).")
96 (license license:lgpl2.1+)))
97
98 (define-public checkpolicy
99 (package (inherit libsepol)
100 (name "checkpolicy")
101 (arguments
102 `(#:tests? #f ; there is no check target
103 #:make-flags
104 (let ((out (assoc-ref %outputs "out")))
105 (list (string-append "PREFIX=" out)
106 (string-append "LIBSEPOLA="
107 (assoc-ref %build-inputs "libsepol")
108 "/lib/libsepol.a")
109 "CC=gcc"))
110 #:phases
111 (modify-phases %standard-phases
112 (delete 'configure)
113 (delete 'portability)
114 (add-after 'unpack 'enter-dir
115 (lambda _ (chdir ,name) #t)))))
116 (inputs
117 `(("libsepol" ,libsepol)))
118 (native-inputs
119 `(("bison" ,bison)
120 ("flex" ,flex)))
121 (synopsis "Check SELinux security policy configurations and modules")
122 (description
123 "This package provides the tools \"checkpolicy\" and \"checkmodule\".
124 Checkpolicy is a program that checks and compiles a SELinux security policy
125 configuration into a binary representation that can be loaded into the kernel.
126 Checkmodule is a program that checks and compiles a SELinux security policy
127 module into a binary representation.")
128 ;; GPLv2 only
129 (license license:gpl2)))
130
131 (define-public libselinux
132 (package (inherit libsepol)
133 (name "libselinux")
134 (arguments
135 (substitute-keyword-arguments (package-arguments libsepol)
136 ((#:make-flags flags)
137 `(cons* "PYTHON=python3"
138 (string-append "LIBSEPOLA="
139 (assoc-ref %build-inputs "libsepol")
140 "/lib/libsepol.a")
141 (string-append "PYSITEDIR="
142 (assoc-ref %outputs "out")
143 "/lib/python"
144 ,(version-major+minor (package-version python))
145 "/site-packages/")
146 ,flags))
147 ((#:phases phases)
148 `(modify-phases ,phases
149 (delete 'portability)
150 (replace 'enter-dir
151 (lambda _ (chdir ,name) #t))
152 (add-after 'enter-dir 'remove-Werror
153 (lambda _
154 ;; GCC complains about the fact that the output does not (yet)
155 ;; have an "include" directory, even though it is referenced.
156 (substitute* '("src/Makefile"
157 "utils/Makefile")
158 (("-Werror ") ""))
159 #t))
160 (add-after 'build 'pywrap
161 (lambda* (#:key make-flags #:allow-other-keys)
162 (apply invoke "make" "pywrap" make-flags)))
163 (add-after 'install 'install-pywrap
164 (lambda* (#:key make-flags #:allow-other-keys)
165 (apply invoke "make" "install-pywrap" make-flags)))))))
166 ;; These libraries are in "Requires.private" in libselinux.pc.
167 (propagated-inputs
168 `(("libsepol" ,libsepol)
169 ("pcre" ,pcre)))
170 ;; For pywrap phase
171 (inputs
172 `(("python" ,python-wrapper)))
173 ;; These inputs are only needed for the pywrap phase.
174 (native-inputs
175 `(("swig" ,swig)
176 ("pkg-config" ,pkg-config)))
177 (synopsis "SELinux core libraries and utilities")
178 (description
179 "The libselinux library provides an API for SELinux applications to get
180 and set process and file security contexts, and to obtain security policy
181 decisions. It is required for any applications that use the SELinux API, and
182 used by all applications that are SELinux-aware. This package also includes
183 the core SELinux management utilities.")
184 (license license:public-domain)))
185
186 (define-public libsemanage
187 (package (inherit libsepol)
188 (name "libsemanage")
189 (arguments
190 (substitute-keyword-arguments (package-arguments libsepol)
191 ((#:make-flags flags)
192 `(cons* "PYTHON=python3"
193 (string-append "PYSITEDIR="
194 (assoc-ref %outputs "out")
195 "/lib/python"
196 ,(version-major+minor (package-version python))
197 "/site-packages/")
198 ,flags))
199 ((#:phases phases)
200 `(modify-phases ,phases
201 (delete 'portability)
202 (replace 'enter-dir
203 (lambda _ (chdir ,name) #t))
204 (add-after 'build 'pywrap
205 (lambda* (#:key make-flags #:allow-other-keys)
206 (apply invoke "make" "pywrap" make-flags)))
207 (add-after 'install 'install-pywrap
208 (lambda* (#:key make-flags #:allow-other-keys)
209 (apply invoke "make" "install-pywrap" make-flags)))))))
210 (inputs
211 `(("libsepol" ,libsepol)
212 ("libselinux" ,libselinux)
213 ("audit" ,audit)
214 ("ustr" ,ustr)
215 ;; For pywrap phase
216 ("python" ,python-wrapper)))
217 (native-inputs
218 `(("bison" ,bison)
219 ("flex" ,flex)
220 ;; For pywrap phase
221 ("swig" ,swig)
222 ("pkg-config" ,pkg-config)))
223 (synopsis "SELinux policy management libraries")
224 (description
225 "The libsemanage library provides an API for the manipulation of SELinux
226 binary policies.")
227 (license license:lgpl2.1+)))
228
229 (define-public secilc
230 (package (inherit libsepol)
231 (name "secilc")
232 (arguments
233 (substitute-keyword-arguments (package-arguments libsepol)
234 ((#:make-flags flags)
235 `(let ((docbook (assoc-ref %build-inputs "docbook-xsl")))
236 (cons (string-append "XMLTO=xmlto --skip-validation -x "
237 docbook "/xml/xsl/docbook-xsl-"
238 ,(package-version docbook-xsl)
239 "/manpages/docbook.xsl")
240 ,flags)))
241 ((#:phases phases)
242 `(modify-phases ,phases
243 (delete 'portability)
244 (replace 'enter-dir
245 (lambda _ (chdir ,name) #t))))))
246 (inputs
247 `(("libsepol" ,libsepol)))
248 (native-inputs
249 `(("xmlto" ,xmlto)
250 ("docbook-xsl" ,docbook-xsl)))
251 (synopsis "SELinux common intermediate language (CIL) compiler")
252 (description "The SELinux CIL compiler is a compiler that converts the
253 @dfn{common intermediate language} (CIL) into a kernel binary policy file.")
254 (license license:bsd-2)))
255
256 (define-public python-sepolgen
257 (package (inherit libsepol)
258 (name "python-sepolgen")
259 (arguments
260 `(#:modules ((srfi srfi-1)
261 (guix build gnu-build-system)
262 (guix build utils))
263 ,@(substitute-keyword-arguments (package-arguments libsepol)
264 ((#:phases phases)
265 `(modify-phases ,phases
266 (delete 'portability)
267 (replace 'enter-dir
268 (lambda _ (chdir "python/sepolgen") #t))
269 ;; By default all Python files would be installed to
270 ;; $out/gnu/store/...-python-.../, so we override the
271 ;; PACKAGEDIR to fix this.
272 (add-after 'enter-dir 'fix-target-path
273 (lambda* (#:key inputs outputs #:allow-other-keys)
274 (let ((get-python-version
275 ;; FIXME: copied from python-build-system
276 (lambda (python)
277 (let* ((version (last (string-split python #\-)))
278 (components (string-split version #\.))
279 (major+minor (take components 2)))
280 (string-join major+minor ".")))))
281 (substitute* "src/sepolgen/Makefile"
282 (("^PACKAGEDIR.*")
283 (string-append "PACKAGEDIR="
284 (assoc-ref outputs "out")
285 "/lib/python"
286 (get-python-version
287 (assoc-ref inputs "python"))
288 "/site-packages/sepolgen")))
289 (substitute* "src/share/Makefile"
290 (("\\$\\(DESTDIR\\)") (assoc-ref outputs "out"))))
291 #t)))))))
292 (inputs
293 `(("python" ,python-wrapper)))
294 (native-inputs '())
295 (synopsis "Python module for generating SELinux policies")
296 (description
297 "This package contains a Python module that forms the core of
298 @code{audit2allow}, a part of the package @code{policycoreutils}. The
299 sepolgen library contains: Reference Policy Representation, which are Objects
300 for representing policies and the reference policy interfaces. It has objects
301 and algorithms for representing access and sets of access in an abstract way
302 and searching that access. It also has a parser for reference policy
303 \"headers\". It contains infrastructure for parsing SELinux related messages
304 as produced by the audit system. It has facilities for generating policy
305 based on required access.")
306 ;; GPLv2 only
307 (license license:gpl2)))
308
309 (define-public python-setools
310 (package
311 (name "python-setools")
312 (version "4.1.1")
313 (source (origin
314 (method git-fetch)
315 (uri (git-reference
316 (url "https://github.com/TresysTechnology/setools.git")
317 (commit version)))
318 (file-name (string-append name "-" version "-checkout"))
319 (sha256
320 (base32
321 "0459xxly6zzqc5azcwk3rbbcxvj60dq08f8z6xr05y7dsbb16cg6"))))
322 (build-system python-build-system)
323 (arguments
324 `(#:tests? #f ; the test target causes a rebuild
325 #:phases
326 (modify-phases %standard-phases
327 (delete 'portability)
328 (add-after 'unpack 'set-SEPOL-variable
329 (lambda* (#:key inputs #:allow-other-keys)
330 (setenv "SEPOL"
331 (string-append (assoc-ref inputs "libsepol")
332 "/lib/libsepol.a"))))
333 (add-after 'unpack 'remove-Werror
334 (lambda _
335 (substitute* "setup.py"
336 (("'-Werror',") ""))
337 #t))
338 (add-after 'unpack 'fix-target-paths
339 (lambda* (#:key outputs #:allow-other-keys)
340 (substitute* "setup.py"
341 (("join\\(sys.prefix")
342 (string-append "join(\"" (assoc-ref outputs "out") "/\"")))
343 #t)))))
344 (propagated-inputs
345 `(("python-networkx" ,python-networkx)))
346 (inputs
347 `(("libsepol" ,libsepol)
348 ("libselinux" ,libselinux)))
349 (native-inputs
350 `(("bison" ,bison)
351 ("flex" ,flex)
352 ("swig" ,swig)))
353 (home-page "https://github.com/TresysTechnology/setools")
354 (synopsis "Tools for SELinux policy analysis")
355 (description "SETools is a collection of graphical tools, command-line
356 tools, and libraries designed to facilitate SELinux policy analysis.")
357 ;; Some programs are under GPL, all libraries under LGPL.
358 (license (list license:lgpl2.1+
359 license:gpl2+))))
360
361 (define-public policycoreutils
362 (package (inherit libsepol)
363 (name "policycoreutils")
364 (arguments
365 `(#:test-target "test"
366 #:make-flags
367 (let ((out (assoc-ref %outputs "out")))
368 (list "CC=gcc"
369 (string-append "PREFIX=" out)
370 (string-append "LOCALEDIR=" out "/share/locale")
371 (string-append "BASHCOMPLETIONDIR=" out
372 "/share/bash-completion/completions")
373 "INSTALL=install -c -p"
374 "INSTALL_DIR=install -d"
375 ;; These ones are needed because some Makefiles define the
376 ;; directories relative to DESTDIR, not relative to PREFIX.
377 (string-append "SBINDIR=" out "/sbin")
378 (string-append "ETCDIR=" out "/etc")
379 (string-append "SYSCONFDIR=" out "/etc/sysconfig")
380 (string-append "MAN5DIR=" out "/share/man/man5")
381 (string-append "INSTALL_NLS_DIR=" out "/share/locale")
382 (string-append "AUTOSTARTDIR=" out "/etc/xdg/autostart")
383 (string-append "DBUSSERVICEDIR=" out "/share/dbus-1/services")
384 (string-append "SYSTEMDDIR=" out "/lib/systemd")
385 (string-append "INITDIR=" out "/etc/rc.d/init.d")
386 (string-append "SELINUXDIR=" out "/etc/selinux")))
387 #:phases
388 (modify-phases %standard-phases
389 (delete 'configure)
390 (delete 'portability)
391 (add-after 'unpack 'enter-dir
392 (lambda _ (chdir ,name) #t))
393 (add-after 'enter-dir 'ignore-/usr-tests
394 (lambda* (#:key inputs #:allow-other-keys)
395 ;; The Makefile decides to build restorecond only if it finds the
396 ;; inotify header somewhere under /usr.
397 (substitute* "Makefile"
398 (("ifeq.*") "")
399 (("endif.*") ""))
400 ;; Rewrite lookup paths for header files.
401 (substitute* '("newrole/Makefile"
402 "setfiles/Makefile"
403 "run_init/Makefile")
404 (("/usr(/include/security/pam_appl.h)" _ file)
405 (string-append (assoc-ref inputs "pam") file))
406 (("/usr(/include/libaudit.h)" _ file)
407 (string-append (assoc-ref inputs "audit") file)))
408 #t)))))
409 (inputs
410 `(("audit" ,audit)
411 ("pam" ,linux-pam)
412 ("libsepol" ,libsepol)
413 ("libselinux" ,libselinux)
414 ("libsemanage" ,libsemanage)))
415 (native-inputs
416 `(("gettext" ,gettext-minimal)))
417 (synopsis "SELinux core utilities")
418 (description "The policycoreutils package contains the core utilities that
419 are required for the basic operation of an SELinux-enabled GNU system and its
420 policies. These utilities include @code{load_policy} to load policies,
421 @code{setfiles} to label file systems, @code{newrole} to switch roles, and
422 @code{run_init} to run service scripts in their proper context.")
423 (license license:gpl2+)))