gnu: quilt: Update to 0.66.
[jackhill/guix/guix.git] / gnu / packages / selinux.scm
CommitLineData
f269ad25 1;;; GNU Guix --- Functional package management for GNU
ca56021c 2;;; Copyright © 2016, 2017, 2018 Ricardo Wurmus <rekado@elephly.net>
bb6c3d23 3;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
f269ad25
RW
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)
ca56021c 24 #:use-module (guix git-download)
f269ad25
RW
25 #:use-module (guix utils)
26 #:use-module (guix build-system gnu)
4724d729 27 #:use-module (guix build-system python)
f269ad25 28 #:use-module (gnu packages)
32be6601 29 #:use-module (gnu packages admin)
66af08fb 30 #:use-module (gnu packages bison)
c837027d 31 #:use-module (gnu packages docbook)
4724d729 32 #:use-module (gnu packages flex)
6ef94ecb
RW
33 #:use-module (gnu packages gettext)
34 #:use-module (gnu packages glib)
35 #:use-module (gnu packages linux)
36 #:use-module (gnu packages networking)
4724d729
RW
37 #:use-module (gnu packages pcre)
38 #:use-module (gnu packages pkg-config)
39 #:use-module (gnu packages python)
44d10b1f 40 #:use-module (gnu packages python-xyz)
32be6601 41 #:use-module (gnu packages swig)
c837027d
RW
42 #:use-module (gnu packages textutils)
43 #:use-module (gnu packages xml))
f269ad25
RW
44
45;; Update the SELinux packages together!
46
47(define-public libsepol
48 (package
49 (name "libsepol")
ca56021c
RW
50 (version "2.7")
51 (source (let ((release "20170804"))
f269ad25 52 (origin
ca56021c
RW
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"))
f269ad25
RW
58 (sha256
59 (base32
ca56021c 60 "1l1nn8bx08v4cxkw5kb0wgr61rfqj5ra9dh1dy5jslillj93vivq")))))
f269ad25
RW
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
50e87903
RW
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)))))
f269ad25
RW
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
92binary policies. It is used by @code{checkpolicy} (the policy compiler) and
93similar tools, and programs such as @code{load_policy}, which must perform
94specific transformations on binary policies (for example, customizing policy
95boolean settings).")
96 (license license:lgpl2.1+)))
66af08fb
RW
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)
ca56021c 106 (string-append "LIBSEPOLA="
66af08fb 107 (assoc-ref %build-inputs "libsepol")
ca56021c 108 "/lib/libsepol.a")
66af08fb
RW
109 "CC=gcc"))
110 #:phases
111 (modify-phases %standard-phases
112 (delete 'configure)
50e87903 113 (delete 'portability)
66af08fb
RW
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\".
124Checkpolicy is a program that checks and compiles a SELinux security policy
125configuration into a binary representation that can be loaded into the kernel.
126Checkmodule is a program that checks and compiles a SELinux security policy
127module into a binary representation.")
128 ;; GPLv2 only
129 (license license:gpl2)))
4724d729
RW
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"
ca56021c
RW
138 (string-append "LIBSEPOLA="
139 (assoc-ref %build-inputs "libsepol")
140 "/lib/libsepol.a")
4724d729
RW
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
50e87903 149 (delete 'portability)
4724d729
RW
150 (replace 'enter-dir
151 (lambda _ (chdir ,name) #t))
4724d729
RW
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)
927c52c4 162 (apply invoke "make" "pywrap" make-flags)))
4724d729
RW
163 (add-after 'install 'install-pywrap
164 (lambda* (#:key make-flags #:allow-other-keys)
927c52c4 165 (apply invoke "make" "install-pywrap" make-flags)))))))
9ffc1f0e
KK
166 ;; These libraries are in "Requires.private" in libselinux.pc.
167 (propagated-inputs
4724d729 168 `(("libsepol" ,libsepol)
9ffc1f0e
KK
169 ("pcre" ,pcre)))
170 ;; For pywrap phase
171 (inputs
172 `(("python" ,python-wrapper)))
4724d729
RW
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
180and set process and file security contexts, and to obtain security policy
181decisions. It is required for any applications that use the SELinux API, and
182used by all applications that are SELinux-aware. This package also includes
183the core SELinux management utilities.")
184 (license license:public-domain)))
32be6601
RW
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
50e87903 201 (delete 'portability)
32be6601
RW
202 (replace 'enter-dir
203 (lambda _ (chdir ,name) #t))
204 (add-after 'build 'pywrap
205 (lambda* (#:key make-flags #:allow-other-keys)
bb6c3d23 206 (apply invoke "make" "pywrap" make-flags)))
32be6601
RW
207 (add-after 'install 'install-pywrap
208 (lambda* (#:key make-flags #:allow-other-keys)
bb6c3d23 209 (apply invoke "make" "install-pywrap" make-flags)))))))
32be6601
RW
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
226binary policies.")
227 (license license:lgpl2.1+)))
c837027d
RW
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
50e87903 243 (delete 'portability)
c837027d
RW
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)))
d7e2d273
RW
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
50e87903 266 (delete 'portability)
d7e2d273 267 (replace 'enter-dir
ca56021c 268 (lambda _ (chdir "python/sepolgen") #t))
d7e2d273
RW
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
299sepolgen library contains: Reference Policy Representation, which are Objects
300for representing policies and the reference policy interfaces. It has objects
301and algorithms for representing access and sets of access in an abstract way
302and searching that access. It also has a parser for reference policy
303\"headers\". It contains infrastructure for parsing SELinux related messages
304as produced by the audit system. It has facilities for generating policy
305based on required access.")
306 ;; GPLv2 only
307 (license license:gpl2)))
41da8dbe 308
41da8dbe
RW
309(define-public python-setools
310 (package
311 (name "python-setools")
ca56021c 312 (version "4.1.1")
41da8dbe 313 (source (origin
ca56021c
RW
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"))
41da8dbe
RW
319 (sha256
320 (base32
ca56021c 321 "0459xxly6zzqc5azcwk3rbbcxvj60dq08f8z6xr05y7dsbb16cg6"))))
41da8dbe
RW
322 (build-system python-build-system)
323 (arguments
324 `(#:tests? #f ; the test target causes a rebuild
325 #:phases
326 (modify-phases %standard-phases
50e87903 327 (delete 'portability)
41da8dbe
RW
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
356tools, 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+))))
6ef94ecb
RW
360
361(define-public policycoreutils
362 (package (inherit libsepol)
363 (name "policycoreutils")
6ef94ecb
RW
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)
50e87903 390 (delete 'portability)
6ef94ecb
RW
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)))
6ef94ecb
RW
408 #t)))))
409 (inputs
ca56021c 410 `(("audit" ,audit)
6ef94ecb
RW
411 ("pam" ,linux-pam)
412 ("libsepol" ,libsepol)
413 ("libselinux" ,libselinux)
ca56021c 414 ("libsemanage" ,libsemanage)))
6ef94ecb
RW
415 (native-inputs
416 `(("gettext" ,gettext-minimal)))
417 (synopsis "SELinux core utilities")
418 (description "The policycoreutils package contains the core utilities that
419are required for the basic operation of an SELinux-enabled GNU system and its
420policies. 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+)))