apparmor.scm 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2022 Hilton Chain <hako@ultrarare.space>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (gnu packages apparmor)
  19. #:use-module ((guix licenses) #:prefix license:)
  20. #:use-module (gnu packages autotools)
  21. #:use-module (gnu packages base)
  22. #:use-module (gnu packages bison)
  23. #:use-module (gnu packages dejagnu)
  24. #:use-module (gnu packages flex)
  25. #:use-module (gnu packages gawk)
  26. #:use-module (gnu packages gettext)
  27. #:use-module (gnu packages linux)
  28. #:use-module (gnu packages perl)
  29. #:use-module (gnu packages pkg-config)
  30. #:use-module (gnu packages python)
  31. #:use-module (gnu packages python-xyz)
  32. #:use-module (gnu packages ruby)
  33. #:use-module (gnu packages swig)
  34. #:use-module (guix build-system gnu)
  35. #:use-module (guix gexp)
  36. #:use-module (guix git-download)
  37. #:use-module (guix packages)
  38. #:use-module (guix utils))
  39. (define-public libapparmor
  40. (package
  41. (name "libapparmor")
  42. (version "3.1.2")
  43. (source (origin
  44. (method git-fetch)
  45. (uri (git-reference
  46. (url "https://gitlab.com/apparmor/apparmor")
  47. (commit (string-append "v" version))))
  48. (file-name (git-file-name name version))
  49. (sha256
  50. (base32
  51. "1h77a7ww0rxfv5nsi1iy4fffklxdr2vq6r7kdsqm15yysglhbjyi"))))
  52. (build-system gnu-build-system)
  53. (arguments
  54. (list #:configure-flags
  55. #~(list (string-append "LDFLAGS=-Wl,-rpath=" #$output "/lib")
  56. "--with-perl" "--with-python" "--with-ruby")
  57. #:phases
  58. #~(modify-phases %standard-phases
  59. (add-after 'unpack 'fix-paths
  60. (lambda* (#:key inputs #:allow-other-keys)
  61. (for-each patch-shebang
  62. '("common/list_af_names.sh"
  63. "common/list_capabilities.sh"))
  64. (for-each (lambda (file)
  65. (substitute* file
  66. (("/usr") "")
  67. (("/bin/\\<(pod2man|pod2html|podchecker|prove)\\>" path)
  68. (search-input-file inputs path))
  69. (("/include/linux/capability.h" path)
  70. (search-input-file inputs path))))
  71. '("common/Make-po.rules"
  72. "common/Make.rules"
  73. "binutils/Makefile"
  74. "parser/Makefile"
  75. "parser/tst/Makefile"
  76. "profiles/Makefile"
  77. "utils/Makefile"
  78. "utils/python-tools-setup.py"
  79. "utils/vim/Makefile"))))
  80. (add-after 'fix-paths 'change-directory
  81. (lambda _
  82. (chdir "libraries/libapparmor"))))))
  83. (native-inputs
  84. (list autoconf
  85. automake
  86. bison
  87. dejagnu
  88. flex
  89. libtool
  90. perl
  91. python-minimal
  92. ruby
  93. swig
  94. which))
  95. (home-page "https://apparmor.net")
  96. (synopsis "Linux kernel security module")
  97. (description
  98. "AppArmor is an effective and easy-to-use Linux application security
  99. system.
  100. AppArmor proactively protects the operating system and applications from
  101. external or internal threats, even zero-day attacks, by enforcing good
  102. behavior and preventing both known and unknown application flaws from being
  103. exploited.
  104. AppArmor supplements the traditional Unix discretionary access control (DAC)
  105. model by providing mandatory access control (MAC). It has been included in
  106. the mainline Linux kernel since version 2.6.36 and its development has been
  107. supported by Canonical since 2009.")
  108. (license license:lgpl2.1)
  109. (supported-systems (filter (lambda (system)
  110. (string-suffix? "-linux" system))
  111. %supported-systems))))
  112. (define-public apparmor
  113. (let ((base libapparmor))
  114. (package
  115. (inherit base)
  116. (name "apparmor")
  117. (arguments
  118. (append
  119. (list #:make-flags
  120. #~(list (string-append "CC=" #$(cc-for-target))
  121. (string-append "DESTDIR=" #$output)
  122. "USE_SYSTEM=1"
  123. ;; No need to run the linter
  124. "PYFLAKES=true"))
  125. (substitute-keyword-arguments (package-arguments base)
  126. ((#:phases phases)
  127. #~(modify-phases #$phases
  128. (delete 'configure)
  129. ;; apparmor-binutils
  130. (replace 'change-directory
  131. (lambda _
  132. (chdir "binutils")))
  133. ;; apparmor-parser
  134. (add-after 'install 'chdir-parser
  135. (lambda _
  136. (chdir "../parser")))
  137. (add-after 'chdir-parser 'patch-source-shebangs-parser
  138. (assoc-ref %standard-phases 'patch-source-shebangs))
  139. (add-after 'patch-source-shebangs-parser 'build-parser
  140. (assoc-ref %standard-phases 'build))
  141. (add-after 'build-parser 'check-parser
  142. (assoc-ref %standard-phases 'check))
  143. (add-after 'check-parser 'install-parser
  144. (assoc-ref %standard-phases 'install))
  145. ;; apparmor-utils
  146. ;; FIXME: Tests required Python library from this package
  147. ;; (itself).
  148. (add-after 'install-parser 'chdir-utils
  149. (lambda _
  150. (chdir "../utils")
  151. ;; Fix paths to installed policygroups and templates for
  152. ;; easyprof.
  153. (substitute* "easyprof/easyprof.conf"
  154. (("/usr") #$output))))
  155. (add-after 'chdir-utils 'build-utils
  156. (assoc-ref %standard-phases 'build))
  157. (add-after 'build-utils 'install-utils
  158. (assoc-ref %standard-phases 'install))
  159. ;; apparmor-profiles
  160. ;; FIXME: Tests need an AppArmor-enabled system.
  161. (add-after 'install-utils 'chdir-profiles
  162. (lambda _
  163. (chdir "../profiles")))
  164. (add-after 'chdir-profiles 'build-profiles
  165. (assoc-ref %standard-phases 'build))
  166. (add-after 'check-build 'install-profiles
  167. (assoc-ref %standard-phases 'install)))))))
  168. (propagated-inputs
  169. (list libapparmor))
  170. ;; Python module `readline' needed
  171. (native-inputs
  172. (list bison flex gettext-minimal perl python which))
  173. (license license:gpl2))))
  174. (define-public pam-apparmor
  175. (let ((base apparmor))
  176. (package
  177. (inherit base)
  178. (name "pam-apparmor")
  179. (arguments
  180. (append
  181. (list #:tests? #f) ;no tests
  182. (substitute-keyword-arguments (package-arguments base)
  183. ((#:phases phases)
  184. #~(modify-phases #$phases
  185. (delete 'chdir-parser)
  186. (delete 'chdir-utils)
  187. (delete 'chdir-profiles)
  188. (replace 'change-directory
  189. (lambda _
  190. (chdir "changehat/pam_apparmor"))))))))
  191. (native-inputs (list pkg-config perl which))
  192. (inputs (list libapparmor linux-pam))
  193. (license license:bsd-3))))