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