/[gentoo-x86]/eclass/selinux-policy-2.eclass
Gentoo

Contents of /eclass/selinux-policy-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.11 - (hide annotations) (download)
Mon Aug 29 01:28:10 2011 UTC (2 years, 7 months ago) by vapier
Branch: MAIN
Changes since 1.10: +3 -3 lines
trim useless trailing whitespace

1 blueness 1.7 # Copyright 1999-2011 Gentoo Foundation
2 pebenito 1.1 # Distributed under the terms of the GNU General Public License v2
3 vapier 1.11 # $Header: /var/cvsroot/gentoo-x86/eclass/selinux-policy-2.eclass,v 1.10 2011/08/22 19:51:33 swift Exp $
4 pebenito 1.1
5     # Eclass for installing SELinux policy, and optionally
6 blueness 1.5 # reloading the reference-policy based modules.
7 pebenito 1.1
8 blueness 1.7 # @ECLASS: selinux-policy-2.eclass
9 vapier 1.9 # @MAINTAINER:
10 blueness 1.7 # selinux@gentoo.org
11     # @BLURB: This eclass supports the deployment of the various SELinux modules in sec-policy
12     # @DESCRIPTION:
13     # The selinux-policy-2.eclass supports deployment of the various SELinux modules
14     # defined in the sec-policy category. It is responsible for extracting the
15     # specific bits necessary for single-module deployment (instead of full-blown
16     # policy rebuilds) and applying the necessary patches.
17 vapier 1.9 #
18 blueness 1.7 # Also, it supports for bundling patches to make the whole thing just a bit more
19     # manageable.
20    
21     # @ECLASS-VARIABLE: MODS
22 vapier 1.9 # @DESCRIPTION:
23 blueness 1.7 # This variable contains the (upstream) module name for the SELinux module.
24     # This name is only the module name, not the category!
25     : ${MODS:="_illegal"}
26    
27     # @ECLASS-VARIABLE: BASEPOL
28     # @DESCRIPTION:
29     # This variable contains the version string of the selinux-base-policy package
30     # that this module build depends on. It is used to patch with the appropriate
31 vapier 1.9 # patch bundle(s) that are part of selinux-base-policy.
32 blueness 1.7 : ${BASEPOL:=""}
33    
34     # @ECLASS-VARIABLE: POLICY_PATCH
35     # @DESCRIPTION:
36     # This variable contains the additional patch(es) that need to be applied on top
37     # of the patchset already contained within the BASEPOL variable. The variable
38     # can be both a simple string (space-separated) or a bash array.
39     : ${POLICY_PATCH:=""}
40    
41     # @ECLASS-VARIABLE: POLICY_TYPES
42     # @DESCRIPTION:
43     # This variable informs the eclass for which SELinux policies the module should
44     # be built. Currently, Gentoo supports targeted, strict, mcs and mls.
45     # This variable is the same POLICY_TYPES variable that we tell SELinux
46     # users to set in /etc/make.conf. Therefor, it is not the module that should
47     # override it, but the user.
48     : ${POLICY_TYPES:="targeted strict mcs mls"}
49    
50 pebenito 1.1 inherit eutils
51    
52     IUSE=""
53    
54     HOMEPAGE="http://www.gentoo.org/proj/en/hardened/selinux/"
55 blueness 1.7 if [[ -n ${BASEPOL} ]];
56     then
57     SRC_URI="http://oss.tresys.com/files/refpolicy/refpolicy-${PV}.tar.bz2
58 swift 1.8 http://dev.gentoo.org/~swift/patches/selinux-base-policy/patchbundle-selinux-base-policy-${BASEPOL}.tar.bz2"
59 blueness 1.7 else
60     SRC_URI="http://oss.tresys.com/files/refpolicy/refpolicy-${PV}.tar.bz2"
61     fi
62 pebenito 1.1
63     LICENSE="GPL-2"
64     SLOT="0"
65     S="${WORKDIR}/"
66 blueness 1.7 PATCHBUNDLE="${DISTDIR}/patchbundle-selinux-base-policy-${BASEPOL}.tar.bz2"
67 pebenito 1.1
68 blueness 1.7 # Modules should always depend on at least the first release of the
69     # selinux-base-policy for which they are generated.
70     if [[ -n ${BASEPOL} ]];
71     then
72     RDEPEND=">=sys-apps/policycoreutils-2.0.82
73     >=sec-policy/selinux-base-policy-${BASEPOL}"
74     else
75     RDEPEND=">=sys-apps/policycoreutils-2.0.82
76     >=sec-policy/selinux-base-policy-${PV}"
77     fi
78 pebenito 1.1 DEPEND="${RDEPEND}
79     sys-devel/m4
80 blueness 1.7 >=sys-apps/checkpolicy-2.0.21"
81 pebenito 1.1
82 blueness 1.7 SELINUX_EXPF="src_unpack src_compile src_install pkg_postinst"
83     case "${EAPI:-0}" in
84     2|3|4) SELINUX_EXPF+=" src_prepare" ;;
85     *) ;;
86     esac
87    
88     EXPORT_FUNCTIONS ${SELINUX_EXPF}
89    
90     # @FUNCTION: selinux-policy-2_src_unpack
91     # @DESCRIPTION:
92     # Unpack the policy sources as offered by upstream (refpolicy). In case of EAPI
93     # older than 2, call src_prepare too.
94 pebenito 1.1 selinux-policy-2_src_unpack() {
95 blueness 1.7 unpack ${A}
96    
97     # Call src_prepare explicitly for EAPI 0 or 1
98     has "${EAPI:-0}" 0 1 && selinux-policy-2_src_prepare
99     }
100    
101     # @FUNCTION: selinux-policy-2_src_prepare
102     # @DESCRIPTION:
103     # Patch the reference policy sources with our set of enhancements. Start with
104     # the base patchbundle referred to by the ebuilds through the BASEPOL variable,
105     # then apply the additional patches as offered by the ebuild.
106 vapier 1.11 #
107 blueness 1.7 # Next, extract only those files needed for this particular module (i.e. the .te
108     # and .fc files for the given module in the MODS variable).
109 vapier 1.11 #
110 blueness 1.7 # Finally, prepare the build environments for each of the supported SELinux
111     # types (such as targeted or strict), depending on the POLICY_TYPES variable
112     # content.
113     selinux-policy-2_src_prepare() {
114 pebenito 1.2 local modfiles
115    
116 blueness 1.7 # Patch the sources with the base patchbundle
117     if [[ -n ${BASEPOL} ]];
118     then
119     cd "${S}"
120 swift 1.10 EPATCH_MULTI_MSG="Applying SELinux policy updates ... " \
121     EPATCH_SUFFIX="patch" \
122     EPATCH_SOURCE="${WORKDIR}" \
123     EPATCH_FORCE="yes" \
124     epatch
125 blueness 1.7 fi
126    
127     # Apply the additional patches refered to by the module ebuild.
128     # But first some magic to differentiate between bash arrays and strings
129     if [[ "$(declare -p POLICY_PATCH 2>/dev/null 2>&1)" == "declare -a"* ]];
130     then
131     cd "${S}/refpolicy/policy/modules"
132     for POLPATCH in "${POLICY_PATCH[@]}";
133     do
134     epatch "${POLPATCH}"
135     done
136     else
137     if [[ -n ${POLICY_PATCH} ]];
138     then
139     cd "${S}/refpolicy/policy/modules"
140     for POLPATCH in ${POLICY_PATCH};
141     do
142     epatch "${POLPATCH}"
143     done
144     fi
145     fi
146 pebenito 1.1
147 blueness 1.7 # Collect only those files needed for this particular module
148 pebenito 1.1 for i in ${MODS}; do
149 blueness 1.7 modfiles="$(find ${S}/refpolicy/policy/modules -iname $i.te) $modfiles"
150     modfiles="$(find ${S}/refpolicy/policy/modules -iname $i.fc) $modfiles"
151 pebenito 1.1 done
152    
153     for i in ${POLICY_TYPES}; do
154 blueness 1.7 mkdir "${S}"/${i} || die "Failed to create directory ${S}/${i}"
155     cp "${S}"/refpolicy/doc/Makefile.example "${S}"/${i}/Makefile \
156     || die "Failed to copy Makefile.example to ${S}/${i}/Makefile"
157 kaiowas 1.3
158 blueness 1.7 cp ${modfiles} "${S}"/${i} \
159     || die "Failed to copy the module files to ${S}/${i}"
160 pebenito 1.1 done
161     }
162    
163 blueness 1.7 # @FUNCTION: selinux-policy-2_src_compile
164 vapier 1.9 # @DESCRIPTION:
165 blueness 1.7 # Build the SELinux policy module (.pp file) for just the selected module, and
166     # this for each SELinux policy mentioned in POLICY_TYPES
167 pebenito 1.1 selinux-policy-2_src_compile() {
168     for i in ${POLICY_TYPES}; do
169 blueness 1.7 # Parallel builds are broken, so we need to force -j1 here
170     emake -j1 NAME=$i -C "${S}"/${i} || die "${i} compile failed"
171 pebenito 1.1 done
172     }
173    
174 blueness 1.7 # @FUNCTION: selinux-policy-2_src_install
175     # @DESCRIPTION:
176     # Install the built .pp files in the correct subdirectory within
177     # /usr/share/selinux.
178 pebenito 1.1 selinux-policy-2_src_install() {
179 pebenito 1.2 local BASEDIR="/usr/share/selinux"
180 pebenito 1.1
181     for i in ${POLICY_TYPES}; do
182     for j in ${MODS}; do
183 blueness 1.7 einfo "Installing ${i} ${j} policy package"
184 pebenito 1.1 insinto ${BASEDIR}/${i}
185 blueness 1.7 doins "${S}"/${i}/${j}.pp || die "Failed to add ${j}.pp to ${i}"
186 pebenito 1.1 done
187     done
188     }
189    
190 blueness 1.7 # @FUNCTION: selinux-policy-2_pkg_postinst
191     # @DESCRIPTION:
192     # Install the built .pp files in the SELinux policy stores, effectively
193     # activating the policy on the system.
194 pebenito 1.1 selinux-policy-2_pkg_postinst() {
195     # build up the command in the case of multiple modules
196     local COMMAND
197     for i in ${MODS}; do
198     COMMAND="-i ${i}.pp ${COMMAND}"
199     done
200    
201 blueness 1.5 for i in ${POLICY_TYPES}; do
202     einfo "Inserting the following modules into the $i module store: ${MODS}"
203 pebenito 1.1
204 blueness 1.7 cd /usr/share/selinux/${i} || die "Could not enter /usr/share/selinux/${i}"
205 blueness 1.6 semodule -s ${i} ${COMMAND} || die "Failed to load in modules ${MODS} in the $i policy store"
206 blueness 1.5 done
207 pebenito 1.1 }

  ViewVC Help
Powered by ViewVC 1.1.20