Use https by default
[gentoo.git] / sec-policy / selinux-base / selinux-base-2.20141203-r8.ebuild
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4 EAPI="5"
5
6 inherit eutils
7
8 if [[ ${PV} == 9999* ]]; then
9         EGIT_REPO_URI="${SELINUX_GIT_REPO:-git://anongit.gentoo.org/proj/hardened-refpolicy.git https://anongit.gentoo.org/git/proj/hardened-refpolicy.git}"
10         EGIT_BRANCH="${SELINUX_GIT_BRANCH:-master}"
11         EGIT_CHECKOUT_DIR="${WORKDIR}/refpolicy"
12
13         inherit git-r3
14
15         KEYWORDS=""
16 else
17         SRC_URI="https://raw.githubusercontent.com/wiki/TresysTechnology/refpolicy/files/refpolicy-${PV}.tar.bz2
18                         https://dev.gentoo.org/~swift/patches/selinux-base-policy/patchbundle-selinux-base-policy-${PVR}.tar.bz2"
19
20         KEYWORDS="~amd64 ~x86"
21 fi
22
23 IUSE="+peer_perms +open_perms +ubac +unconfined doc"
24
25 DESCRIPTION="Gentoo base policy for SELinux"
26 HOMEPAGE="https://www.gentoo.org/proj/en/hardened/selinux/"
27 LICENSE="GPL-2"
28 SLOT="0"
29
30 RDEPEND=">=sys-apps/policycoreutils-2.3
31         virtual/udev
32         !<=sec-policy/selinux-base-policy-2.20120725"
33 DEPEND="${RDEPEND}
34         sys-devel/m4
35         >=sys-apps/checkpolicy-2.3"
36
37 S=${WORKDIR}/
38
39 #src_unpack() {
40 #       git-2_src_unpack
41 #}
42
43 src_prepare() {
44         if [[ ${PV} != 9999* ]]; then
45                 # Apply the gentoo patches to the policy. These patches are only necessary
46                 # for base policies, or for interface changes on modules.
47                 EPATCH_MULTI_MSG="Applying SELinux policy updates ... " \
48                 EPATCH_SUFFIX="patch" \
49                 EPATCH_SOURCE="${WORKDIR}" \
50                 EPATCH_FORCE="yes" \
51                 epatch
52         fi
53
54         cd "${S}/refpolicy"
55         make bare
56
57         epatch_user
58 }
59
60 src_configure() {
61         [ -z "${POLICY_TYPES}" ] && local POLICY_TYPES="targeted strict mls mcs"
62
63         # Update the SELinux refpolicy capabilities based on the users' USE flags.
64
65         if ! use peer_perms; then
66                 sed -i -e '/network_peer_controls/d' \
67                         "${S}/refpolicy/policy/policy_capabilities"
68         fi
69
70         if ! use open_perms; then
71                 sed -i -e '/open_perms/d' \
72                         "${S}/refpolicy/policy/policy_capabilities"
73         fi
74
75         if ! use ubac; then
76                 sed -i -e '/^UBAC/s/y/n/' "${S}/refpolicy/build.conf" \
77                         || die "Failed to disable User Based Access Control"
78         fi
79
80         echo "DISTRO = gentoo" >> "${S}/refpolicy/build.conf"
81
82         # Prepare initial configuration
83         cd "${S}/refpolicy";
84         make conf || die "Make conf failed"
85
86         # Setup the policies based on the types delivered by the end user.
87         # These types can be "targeted", "strict", "mcs" and "mls".
88         for i in ${POLICY_TYPES}; do
89                 cp -a "${S}/refpolicy" "${S}/${i}"
90                 cd "${S}/${i}";
91
92                 #cp "${FILESDIR}/modules-2.20120215.conf" "${S}/${i}/policy/modules.conf"
93                 sed -i -e "/= module/d" "${S}/${i}/policy/modules.conf"
94
95                 sed -i -e '/^QUIET/s/n/y/' -e "/^NAME/s/refpolicy/$i/" \
96                         "${S}/${i}/build.conf" || die "build.conf setup failed."
97
98                 if [[ "${i}" == "mls" ]] || [[ "${i}" == "mcs" ]];
99                 then
100                         # MCS/MLS require additional settings
101                         sed -i -e "/^TYPE/s/standard/${i}/" "${S}/${i}/build.conf" \
102                                 || die "failed to set type to mls"
103                 fi
104
105                 if [ "${i}" == "targeted" ]; then
106                         sed -i -e '/root/d' -e 's/user_u/unconfined_u/' \
107                         "${S}/${i}/config/appconfig-standard/seusers" \
108                         || die "targeted seusers setup failed."
109                 fi
110
111                 if [ "${i}" != "targeted" ] && [ "${i}" != "strict" ] && use unconfined; then
112                         sed -i -e '/root/d' -e 's/user_u/unconfined_u/' \
113                         "${S}/${i}/config/appconfig-${i}/seusers" \
114                         || die "policy seusers setup failed."
115                 fi
116         done
117 }
118
119 src_compile() {
120         [ -z "${POLICY_TYPES}" ] && local POLICY_TYPES="targeted strict mls mcs"
121
122         for i in ${POLICY_TYPES}; do
123                 cd "${S}/${i}"
124                 emake base || die "${i} compile failed"
125                 if use doc; then
126                         make html || die
127                 fi
128         done
129 }
130
131 src_install() {
132         [ -z "${POLICY_TYPES}" ] && local POLICY_TYPES="targeted strict mls mcs"
133
134         for i in ${POLICY_TYPES}; do
135                 cd "${S}/${i}"
136
137                 make DESTDIR="${D}" install \
138                         || die "${i} install failed."
139
140                 make DESTDIR="${D}" install-headers \
141                         || die "${i} headers install failed."
142
143                 echo "run_init_t" > "${D}/etc/selinux/${i}/contexts/run_init_type"
144
145                 echo "textrel_shlib_t" >> "${D}/etc/selinux/${i}/contexts/customizable_types"
146
147                 # libsemanage won't make this on its own
148                 keepdir "/etc/selinux/${i}/policy"
149
150                 if use doc; then
151                         dohtml doc/html/*;
152                 fi
153
154                 insinto /usr/share/selinux/devel;
155                 doins doc/policy.xml;
156
157         done
158
159         dodoc doc/Makefile.example doc/example.{te,fc,if}
160
161         doman man/man8/*.8;
162
163         insinto /etc/selinux
164         doins "${FILESDIR}/config"
165 }
166
167 pkg_preinst() {
168         has_version "<${CATEGORY}/${PN}-2.20101213-r13"
169         previous_less_than_r13=$?
170 }