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