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>
5 ;;; This file is part of GNU Guix.
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.
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.
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/>.
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))
45 ;; Update the SELinux packages together!
47 (define-public libsepol
51 (source (let ((release "20170804"))
55 (url "https://github.com/SELinuxProject/selinux.git")
57 (file-name (string-append "selinux-" release "-checkout"))
60 "1l1nn8bx08v4cxkw5kb0wgr61rfqj5ra9dh1dy5jslillj93vivq")))))
61 (build-system gnu-build-system)
63 `(#:tests? #f ; tests require checkpolicy, which requires libsepol
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")
75 (modify-phases %standard-phases
77 (add-after 'unpack 'enter-dir
78 (lambda _ (chdir ,name) #t))
79 (add-after 'enter-dir 'portability
81 (substitute* "src/ibpkeys.c"
82 (("#include \"ibpkey_internal.h\"" line)
83 (string-append line "\n#include <inttypes.h>\n"))
84 (("%#lx") "%#\" PRIx64 \""))
88 (home-page "https://selinuxproject.org/")
89 (synopsis "Library for manipulating SELinux policies")
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
96 (license license:lgpl2.1+)))
98 (define-public checkpolicy
99 (package (inherit libsepol)
102 `(#:tests? #f ; there is no check target
104 (let ((out (assoc-ref %outputs "out")))
105 (list (string-append "PREFIX=" out)
106 (string-append "LIBSEPOLA="
107 (assoc-ref %build-inputs "libsepol")
111 (modify-phases %standard-phases
113 (delete 'portability)
114 (add-after 'unpack 'enter-dir
115 (lambda _ (chdir ,name) #t)))))
117 `(("libsepol" ,libsepol)))
121 (synopsis "Check SELinux security policy configurations and modules")
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.")
129 (license license:gpl2)))
131 (define-public libselinux
132 (package (inherit libsepol)
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")
141 (string-append "PYSITEDIR="
142 (assoc-ref %outputs "out")
144 ,(version-major+minor (package-version python))
148 `(modify-phases ,phases
149 (delete 'portability)
151 (lambda _ (chdir ,name) #t))
152 (add-after 'enter-dir 'remove-Werror
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"
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.
168 `(("libsepol" ,libsepol)
172 `(("python" ,python-wrapper)))
173 ;; These inputs are only needed for the pywrap phase.
176 ("pkg-config" ,pkg-config)))
177 (synopsis "SELinux core libraries and utilities")
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)))
186 (define-public libsemanage
187 (package (inherit libsepol)
190 (substitute-keyword-arguments (package-arguments libsepol)
191 ((#:make-flags flags)
192 `(cons* "PYTHON=python3"
193 (string-append "PYSITEDIR="
194 (assoc-ref %outputs "out")
196 ,(version-major+minor (package-version python))
200 `(modify-phases ,phases
201 (delete 'portability)
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)))))))
211 `(("libsepol" ,libsepol)
212 ("libselinux" ,libselinux)
216 ("python" ,python-wrapper)))
222 ("pkg-config" ,pkg-config)))
223 (synopsis "SELinux policy management libraries")
225 "The libsemanage library provides an API for the manipulation of SELinux
227 (license license:lgpl2.1+)))
229 (define-public secilc
230 (package (inherit libsepol)
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")
242 `(modify-phases ,phases
243 (delete 'portability)
245 (lambda _ (chdir ,name) #t))))))
247 `(("libsepol" ,libsepol)))
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)))
256 (define-public python-sepolgen
257 (package (inherit libsepol)
258 (name "python-sepolgen")
260 `(#:modules ((srfi srfi-1)
261 (guix build gnu-build-system)
263 ,@(substitute-keyword-arguments (package-arguments libsepol)
265 `(modify-phases ,phases
266 (delete 'portability)
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
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"
283 (string-append "PACKAGEDIR="
284 (assoc-ref outputs "out")
287 (assoc-ref inputs "python"))
288 "/site-packages/sepolgen")))
289 (substitute* "src/share/Makefile"
290 (("\\$\\(DESTDIR\\)") (assoc-ref outputs "out"))))
293 `(("python" ,python-wrapper)))
295 (synopsis "Python module for generating SELinux policies")
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.")
307 (license license:gpl2)))
309 (define-public python-setools
311 (name "python-setools")
316 (url "https://github.com/TresysTechnology/setools.git")
318 (file-name (string-append name "-" version "-checkout"))
321 "0459xxly6zzqc5azcwk3rbbcxvj60dq08f8z6xr05y7dsbb16cg6"))))
322 (build-system python-build-system)
324 `(#:tests? #f ; the test target causes a rebuild
326 (modify-phases %standard-phases
327 (delete 'portability)
328 (add-after 'unpack 'set-SEPOL-variable
329 (lambda* (#:key inputs #:allow-other-keys)
331 (string-append (assoc-ref inputs "libsepol")
332 "/lib/libsepol.a"))))
333 (add-after 'unpack 'remove-Werror
335 (substitute* "setup.py"
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") "/\"")))
345 `(("python-networkx" ,python-networkx)))
347 `(("libsepol" ,libsepol)
348 ("libselinux" ,libselinux)))
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+
361 (define-public policycoreutils
362 (package (inherit libsepol)
363 (name "policycoreutils")
365 `(#:test-target "test"
367 (let ((out (assoc-ref %outputs "out")))
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")))
388 (modify-phases %standard-phases
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"
400 ;; Rewrite lookup paths for header files.
401 (substitute* '("newrole/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)))
412 ("libsepol" ,libsepol)
413 ("libselinux" ,libselinux)
414 ("libsemanage" ,libsemanage)))
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+)))