Commit | Line | Data |
---|---|---|
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 | |
94 | binary policies. It is used by @code{checkpolicy} (the policy compiler) and | |
95 | similar tools, and programs such as @code{load_policy}, which must perform | |
96 | specific transformations on binary policies (for example, customizing policy | |
97 | boolean 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\". | |
125 | Checkpolicy is a program that checks and compiles a SELinux security policy | |
126 | configuration into a binary representation that can be loaded into the kernel. | |
127 | Checkmodule is a program that checks and compiles a SELinux security policy | |
128 | module 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) | |
139 | `(cons* "PYTHON=python3" | |
ca56021c RW |
140 | (string-append "LIBSEPOLA=" |
141 | (assoc-ref %build-inputs "libsepol") | |
142 | "/lib/libsepol.a") | |
9e837ea0 | 143 | (string-append "PYTHONLIBDIR=" |
568d0603 | 144 | (assoc-ref %outputs "python") |
4724d729 RW |
145 | "/lib/python" |
146 | ,(version-major+minor (package-version python)) | |
147 | "/site-packages/") | |
148 | ,flags)) | |
149 | ((#:phases phases) | |
150 | `(modify-phases ,phases | |
50e87903 | 151 | (delete 'portability) |
4724d729 | 152 | (replace 'enter-dir |
545aeb70 | 153 | (lambda _ (chdir ,name))) |
4724d729 RW |
154 | (add-after 'build 'pywrap |
155 | (lambda* (#:key make-flags #:allow-other-keys) | |
927c52c4 | 156 | (apply invoke "make" "pywrap" make-flags))) |
4724d729 | 157 | (add-after 'install 'install-pywrap |
9e837ea0 MB |
158 | (lambda* (#:key make-flags outputs #: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=" (assoc-ref outputs "python")))) | |
927c52c4 | 164 | (apply invoke "make" "install-pywrap" make-flags))))))) |
9ffc1f0e KK |
165 | ;; These libraries are in "Requires.private" in libselinux.pc. |
166 | (propagated-inputs | |
4724d729 | 167 | `(("libsepol" ,libsepol) |
0d79288f | 168 | ("pcre2" ,pcre2))) |
9ffc1f0e KK |
169 | ;; For pywrap phase |
170 | (inputs | |
171 | `(("python" ,python-wrapper))) | |
4724d729 RW |
172 | ;; These inputs are only needed for the pywrap phase. |
173 | (native-inputs | |
174 | `(("swig" ,swig) | |
175 | ("pkg-config" ,pkg-config))) | |
176 | (synopsis "SELinux core libraries and utilities") | |
177 | (description | |
178 | "The libselinux library provides an API for SELinux applications to get | |
179 | and set process and file security contexts, and to obtain security policy | |
180 | decisions. It is required for any applications that use the SELinux API, and | |
181 | used by all applications that are SELinux-aware. This package also includes | |
182 | the core SELinux management utilities.") | |
183 | (license license:public-domain))) | |
32be6601 RW |
184 | |
185 | (define-public libsemanage | |
1a265842 | 186 | (package/inherit libsepol |
32be6601 RW |
187 | (name "libsemanage") |
188 | (arguments | |
189 | (substitute-keyword-arguments (package-arguments libsepol) | |
190 | ((#:make-flags flags) | |
191 | `(cons* "PYTHON=python3" | |
9e837ea0 | 192 | (string-append "PYTHONLIBDIR=" |
32be6601 RW |
193 | (assoc-ref %outputs "out") |
194 | "/lib/python" | |
195 | ,(version-major+minor (package-version python)) | |
196 | "/site-packages/") | |
197 | ,flags)) | |
198 | ((#:phases phases) | |
199 | `(modify-phases ,phases | |
50e87903 | 200 | (delete 'portability) |
32be6601 | 201 | (replace 'enter-dir |
545aeb70 | 202 | (lambda _ (chdir ,name))) |
9e837ea0 MB |
203 | (add-before 'install 'adjust-semanage-conf-location |
204 | (lambda _ | |
205 | (substitute* "src/Makefile" | |
206 | (("DEFAULT_SEMANAGE_CONF_LOCATION=/etc") | |
545aeb70 | 207 | "DEFAULT_SEMANAGE_CONF_LOCATION=$(PREFIX)/etc")))) |
32be6601 RW |
208 | (add-after 'build 'pywrap |
209 | (lambda* (#:key make-flags #:allow-other-keys) | |
bb6c3d23 | 210 | (apply invoke "make" "pywrap" make-flags))) |
32be6601 RW |
211 | (add-after 'install 'install-pywrap |
212 | (lambda* (#:key make-flags #:allow-other-keys) | |
bb6c3d23 | 213 | (apply invoke "make" "install-pywrap" make-flags))))))) |
32be6601 RW |
214 | (inputs |
215 | `(("libsepol" ,libsepol) | |
216 | ("libselinux" ,libselinux) | |
217 | ("audit" ,audit) | |
32be6601 RW |
218 | ;; For pywrap phase |
219 | ("python" ,python-wrapper))) | |
220 | (native-inputs | |
221 | `(("bison" ,bison) | |
222 | ("flex" ,flex) | |
223 | ;; For pywrap phase | |
224 | ("swig" ,swig) | |
225 | ("pkg-config" ,pkg-config))) | |
226 | (synopsis "SELinux policy management libraries") | |
227 | (description | |
228 | "The libsemanage library provides an API for the manipulation of SELinux | |
229 | binary policies.") | |
230 | (license license:lgpl2.1+))) | |
c837027d RW |
231 | |
232 | (define-public secilc | |
1a265842 | 233 | (package/inherit libsepol |
c837027d RW |
234 | (name "secilc") |
235 | (arguments | |
236 | (substitute-keyword-arguments (package-arguments libsepol) | |
237 | ((#:make-flags flags) | |
238 | `(let ((docbook (assoc-ref %build-inputs "docbook-xsl"))) | |
239 | (cons (string-append "XMLTO=xmlto --skip-validation -x " | |
240 | docbook "/xml/xsl/docbook-xsl-" | |
241 | ,(package-version docbook-xsl) | |
242 | "/manpages/docbook.xsl") | |
243 | ,flags))) | |
244 | ((#:phases phases) | |
245 | `(modify-phases ,phases | |
50e87903 | 246 | (delete 'portability) |
c837027d | 247 | (replace 'enter-dir |
545aeb70 | 248 | (lambda _ (chdir ,name))))))) |
c837027d RW |
249 | (inputs |
250 | `(("libsepol" ,libsepol))) | |
251 | (native-inputs | |
252 | `(("xmlto" ,xmlto) | |
253 | ("docbook-xsl" ,docbook-xsl))) | |
254 | (synopsis "SELinux common intermediate language (CIL) compiler") | |
255 | (description "The SELinux CIL compiler is a compiler that converts the | |
256 | @dfn{common intermediate language} (CIL) into a kernel binary policy file.") | |
257 | (license license:bsd-2))) | |
d7e2d273 RW |
258 | |
259 | (define-public python-sepolgen | |
1a265842 | 260 | (package/inherit libsepol |
d7e2d273 RW |
261 | (name "python-sepolgen") |
262 | (arguments | |
263 | `(#:modules ((srfi srfi-1) | |
264 | (guix build gnu-build-system) | |
265 | (guix build utils)) | |
266 | ,@(substitute-keyword-arguments (package-arguments libsepol) | |
267 | ((#:phases phases) | |
268 | `(modify-phases ,phases | |
50e87903 | 269 | (delete 'portability) |
d7e2d273 | 270 | (replace 'enter-dir |
545aeb70 | 271 | (lambda _ (chdir "python/sepolgen"))) |
d7e2d273 RW |
272 | ;; By default all Python files would be installed to |
273 | ;; $out/gnu/store/...-python-.../, so we override the | |
274 | ;; PACKAGEDIR to fix this. | |
275 | (add-after 'enter-dir 'fix-target-path | |
276 | (lambda* (#:key inputs outputs #:allow-other-keys) | |
277 | (let ((get-python-version | |
278 | ;; FIXME: copied from python-build-system | |
279 | (lambda (python) | |
280 | (let* ((version (last (string-split python #\-))) | |
281 | (components (string-split version #\.)) | |
282 | (major+minor (take components 2))) | |
283 | (string-join major+minor "."))))) | |
284 | (substitute* "src/sepolgen/Makefile" | |
285 | (("^PACKAGEDIR.*") | |
286 | (string-append "PACKAGEDIR=" | |
287 | (assoc-ref outputs "out") | |
288 | "/lib/python" | |
289 | (get-python-version | |
290 | (assoc-ref inputs "python")) | |
291 | "/site-packages/sepolgen"))) | |
292 | (substitute* "src/share/Makefile" | |
545aeb70 | 293 | (("\\$\\(DESTDIR\\)") (assoc-ref outputs "out"))))))))))) |
d7e2d273 RW |
294 | (inputs |
295 | `(("python" ,python-wrapper))) | |
296 | (native-inputs '()) | |
297 | (synopsis "Python module for generating SELinux policies") | |
298 | (description | |
299 | "This package contains a Python module that forms the core of | |
300 | @code{audit2allow}, a part of the package @code{policycoreutils}. The | |
301 | sepolgen library contains: Reference Policy Representation, which are Objects | |
302 | for representing policies and the reference policy interfaces. It has objects | |
303 | and algorithms for representing access and sets of access in an abstract way | |
304 | and searching that access. It also has a parser for reference policy | |
305 | \"headers\". It contains infrastructure for parsing SELinux related messages | |
306 | as produced by the audit system. It has facilities for generating policy | |
307 | based on required access.") | |
308 | ;; GPLv2 only | |
309 | (license license:gpl2))) | |
41da8dbe | 310 | |
41da8dbe RW |
311 | (define-public python-setools |
312 | (package | |
313 | (name "python-setools") | |
ca56021c | 314 | (version "4.1.1") |
41da8dbe | 315 | (source (origin |
ca56021c RW |
316 | (method git-fetch) |
317 | (uri (git-reference | |
b0e7b699 | 318 | (url "https://github.com/TresysTechnology/setools") |
ca56021c RW |
319 | (commit version))) |
320 | (file-name (string-append name "-" version "-checkout")) | |
41da8dbe RW |
321 | (sha256 |
322 | (base32 | |
ca56021c | 323 | "0459xxly6zzqc5azcwk3rbbcxvj60dq08f8z6xr05y7dsbb16cg6")))) |
41da8dbe RW |
324 | (build-system python-build-system) |
325 | (arguments | |
326 | `(#:tests? #f ; the test target causes a rebuild | |
327 | #:phases | |
328 | (modify-phases %standard-phases | |
50e87903 | 329 | (delete 'portability) |
41da8dbe RW |
330 | (add-after 'unpack 'set-SEPOL-variable |
331 | (lambda* (#:key inputs #:allow-other-keys) | |
332 | (setenv "SEPOL" | |
377e9453 | 333 | (search-input-file inputs "/lib/libsepol.a")))) |
41da8dbe RW |
334 | (add-after 'unpack 'remove-Werror |
335 | (lambda _ | |
336 | (substitute* "setup.py" | |
337 | (("'-Werror',") "")) | |
338 | #t)) | |
339 | (add-after 'unpack 'fix-target-paths | |
340 | (lambda* (#:key outputs #:allow-other-keys) | |
341 | (substitute* "setup.py" | |
342 | (("join\\(sys.prefix") | |
343 | (string-append "join(\"" (assoc-ref outputs "out") "/\""))) | |
344 | #t))))) | |
345 | (propagated-inputs | |
8394619b | 346 | (list python-networkx)) |
41da8dbe | 347 | (inputs |
8394619b | 348 | (list libsepol libselinux)) |
41da8dbe | 349 | (native-inputs |
8394619b | 350 | (list bison flex swig)) |
41da8dbe RW |
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+)))) | |
6ef94ecb RW |
358 | |
359 | (define-public policycoreutils | |
1a265842 | 360 | (package/inherit libsepol |
6ef94ecb | 361 | (name "policycoreutils") |
6ef94ecb RW |
362 | (arguments |
363 | `(#:test-target "test" | |
364 | #:make-flags | |
365 | (let ((out (assoc-ref %outputs "out"))) | |
a55f6491 | 366 | (list (string-append "CC=" ,(cc-for-target)) |
6ef94ecb RW |
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 | (add-after 'unpack 'enter-dir | |
545aeb70 | 389 | (lambda _ (chdir ,name))) |
6ef94ecb RW |
390 | (add-after 'enter-dir 'ignore-/usr-tests |
391 | (lambda* (#:key inputs #:allow-other-keys) | |
6ef94ecb RW |
392 | ;; Rewrite lookup paths for header files. |
393 | (substitute* '("newrole/Makefile" | |
394 | "setfiles/Makefile" | |
395 | "run_init/Makefile") | |
396 | (("/usr(/include/security/pam_appl.h)" _ file) | |
425ccde6 | 397 | (search-input-file inputs file)) |
6ef94ecb | 398 | (("/usr(/include/libaudit.h)" _ file) |
425ccde6 | 399 | (search-input-file inputs file)))))))) |
6ef94ecb | 400 | (inputs |
ca56021c | 401 | `(("audit" ,audit) |
6ef94ecb RW |
402 | ("pam" ,linux-pam) |
403 | ("libsepol" ,libsepol) | |
404 | ("libselinux" ,libselinux) | |
ca56021c | 405 | ("libsemanage" ,libsemanage))) |
6ef94ecb RW |
406 | (native-inputs |
407 | `(("gettext" ,gettext-minimal))) | |
408 | (synopsis "SELinux core utilities") | |
409 | (description "The policycoreutils package contains the core utilities that | |
410 | are required for the basic operation of an SELinux-enabled GNU system and its | |
411 | policies. These utilities include @code{load_policy} to load policies, | |
412 | @code{setfiles} to label file systems, @code{newrole} to switch roles, and | |
413 | @code{run_init} to run service scripts in their proper context.") | |
414 | (license license:gpl2+))) |