Merge remote-tracking branch 'remotes/github/pr/157'.
[gentoo.git] / net-wireless / wpa_supplicant / wpa_supplicant-2.4-r4.ebuild
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 EAPI=5
6
7 inherit eutils toolchain-funcs qt4-r2 systemd multilib
8
9 DESCRIPTION="IEEE 802.1X/WPA supplicant for secure wireless transfers"
10 HOMEPAGE="http://hostap.epitest.fi/wpa_supplicant/"
11 SRC_URI="http://hostap.epitest.fi/releases/${P}.tar.gz"
12 LICENSE="|| ( GPL-2 BSD )"
13
14 SLOT="0"
15 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~ia64 ~mips ~ppc ~ppc64 ~sparc ~x86 ~x86-fbsd"
16 IUSE="ap dbus gnutls eap-sim fasteap +hs2-0 p2p ps3 qt4 readline selinux smartcard ssl tdls uncommon-eap-types wimax wps kernel_linux kernel_FreeBSD"
17 REQUIRED_USE="fasteap? ( !gnutls !ssl ) smartcard? ( ssl )"
18
19 CDEPEND="dbus? ( sys-apps/dbus )
20         kernel_linux? (
21                 eap-sim? ( sys-apps/pcsc-lite )
22                 dev-libs/libnl:3
23                 net-wireless/crda
24         )
25         !kernel_linux? ( net-libs/libpcap )
26         qt4? (
27                 dev-qt/qtcore:4
28                 dev-qt/qtgui:4
29                 dev-qt/qtsvg:4
30         )
31         readline? (
32                 sys-libs/ncurses
33                 sys-libs/readline:0
34         )
35         ssl? ( dev-libs/openssl:0 )
36         !ssl? ( gnutls? ( net-libs/gnutls ) )
37         !ssl? ( !gnutls? ( dev-libs/libtommath ) )
38 "
39 DEPEND="${CDEPEND}
40         virtual/pkgconfig
41 "
42 RDEPEND="${CDEPEND}
43         selinux? ( sec-policy/selinux-networkmanager )
44 "
45
46 S="${WORKDIR}/${P}/${PN}"
47
48 Kconfig_style_config() {
49                 #param 1 is CONFIG_* item
50                 #param 2 is what to set it = to, defaulting in y
51                 CONFIG_PARAM="${CONFIG_HEADER:-CONFIG_}$1"
52                 setting="${2:-y}"
53
54                 if [ ! $setting = n ]; then
55                         #first remove any leading "# " if $2 is not n
56                         sed -i "/^# *$CONFIG_PARAM=/s/^# *//" .config || echo "Kconfig_style_config error uncommenting $CONFIG_PARAM"
57                         #set item = $setting (defaulting to y)
58                         sed -i "/^$CONFIG_PARAM/s/=.*/=$setting/" .config || echo "Kconfig_style_config error setting $CONFIG_PARAM=$setting"
59                 else
60                         #ensure item commented out
61                         sed -i "/^$CONFIG_PARAM/s/$CONFIG_PARAM/# $CONFIG_PARAM/" .config || echo "Kconfig_style_config error commenting $CONFIG_PARAM"
62                 fi
63 }
64
65 pkg_setup() {
66         if use gnutls && use ssl ; then
67                 elog "You have both 'gnutls' and 'ssl' USE flags enabled: defaulting to USE=\"ssl\""
68         fi
69 }
70
71 src_prepare() {
72         # net/bpf.h needed for net-libs/libpcap on Gentoo/FreeBSD
73         sed -i \
74                 -e "s:\(#include <pcap\.h>\):#include <net/bpf.h>\n\1:" \
75                 ../src/l2_packet/l2_packet_freebsd.c || die
76
77         # People seem to take the example configuration file too literally (bug #102361)
78         sed -i \
79                 -e "s:^\(opensc_engine_path\):#\1:" \
80                 -e "s:^\(pkcs11_engine_path\):#\1:" \
81                 -e "s:^\(pkcs11_module_path\):#\1:" \
82                 wpa_supplicant.conf || die
83
84         # Change configuration to match Gentoo locations (bug #143750)
85         sed -i \
86                 -e "s:/usr/lib/opensc:/usr/$(get_libdir):" \
87                 -e "s:/usr/lib/pkcs11:/usr/$(get_libdir):" \
88                 wpa_supplicant.conf || die
89
90         if use dbus; then
91                 epatch "${FILESDIR}/${P}-dbus-path-fix.patch"
92         fi
93
94         # systemd entries to D-Bus service files (bug #372877)
95         echo 'SystemdService=wpa_supplicant.service' \
96                 | tee -a dbus/*.service >/dev/null || die
97
98         cd "${WORKDIR}/${P}"
99
100         if use wimax; then
101                 # generate-libeap-peer.patch comes before
102                 # fix-undefined-reference-to-random_get_bytes.patch
103                 epatch "${FILESDIR}/${P}-generate-libeap-peer.patch"
104
105                 # multilib-strict fix (bug #373685)
106                 sed -e "s/\/usr\/lib/\/usr\/$(get_libdir)/" -i src/eap_peer/Makefile
107         fi
108
109         # bug (548742)
110         epatch "${FILESDIR}/2015-1/0001-P2P-Validate-SSID-element-length-before-copying-it-C.patch"
111         epatch "${FILESDIR}/2015-2/0001-WPS-Fix-HTTP-chunked-transfer-encoding-parser.patch"
112         epatch "${FILESDIR}/2015-3/0001-AP-WMM-Fix-integer-underflow-in-WMM-Action-frame-par.patch"
113         epatch "${FILESDIR}/2015-4/0001-EAP-pwd-peer-Fix-payload-length-validation-for-Commi.patch"
114         epatch "${FILESDIR}/2015-4/0002-EAP-pwd-server-Fix-payload-length-validation-for-Com.patch"
115         epatch "${FILESDIR}/2015-4/0003-EAP-pwd-peer-Fix-Total-Length-parsing-for-fragment-r.patch"
116         epatch "${FILESDIR}/2015-4/0004-EAP-pwd-server-Fix-Total-Length-parsing-for-fragment.patch"
117         epatch "${FILESDIR}/2015-4/0005-EAP-pwd-peer-Fix-asymmetric-fragmentation-behavior.patch"
118
119         # bug (554860)
120         epatch "${FILESDIR}/2015-5/0001-NFC-Avoid-misaligned-read-of-an-NDEF-field.patch"
121         epatch "${FILESDIR}/2015-5/0002-NFC-Fix-payload-length-validation-in-NDEF-record-par.patch"
122
123         # bug (320097)
124         epatch "${FILESDIR}/${P}-do-not-call-dbus-functions-with-NULL-path.patch"
125
126         # TODO - NEED TESTING TO SEE IF STILL NEEDED, NOT COMPATIBLE WITH 1.0 OUT OF THE BOX,
127         # SO WOULD BE NICE TO JUST DROP IT, IF IT IS NOT NEEDED.
128         # bug (374089)
129         #epatch "${FILESDIR}/${P}-dbus-WPAIE-fix.patch"
130 }
131
132 src_configure() {
133         # Toolchain setup
134         tc-export CC
135
136         cp defconfig .config
137
138         # Basic setup
139         Kconfig_style_config CTRL_IFACE
140         Kconfig_style_config BACKEND file
141         Kconfig_style_config IBSS_RSN
142         Kconfig_style_config IEEE80211W
143         Kconfig_style_config IEEE80211R
144
145         # Basic authentication methods
146         # NOTE: we don't set GPSK or SAKE as they conflict
147         # with the below options
148         Kconfig_style_config EAP_GTC
149         Kconfig_style_config EAP_MD5
150         Kconfig_style_config EAP_OTP
151         Kconfig_style_config EAP_PAX
152         Kconfig_style_config EAP_PSK
153         Kconfig_style_config EAP_TLV
154         Kconfig_style_config EAP_EXE
155         Kconfig_style_config IEEE8021X_EAPOL
156         Kconfig_style_config PKCS12
157         Kconfig_style_config PEERKEY
158         Kconfig_style_config EAP_LEAP
159         Kconfig_style_config EAP_MSCHAPV2
160         Kconfig_style_config EAP_PEAP
161         Kconfig_style_config EAP_TLS
162         Kconfig_style_config EAP_TTLS
163
164         # Enabling background scanning.
165         Kconfig_style_config BGSCAN_SIMPLE
166         Kconfig_style_config BGSCAN_LEARN
167
168         if use dbus ; then
169                 Kconfig_style_config CTRL_IFACE_DBUS
170                 Kconfig_style_config CTRL_IFACE_DBUS_NEW
171                 Kconfig_style_config CTRL_IFACE_DBUS_INTRO
172         fi
173
174         # Enable support for writing debug info to a log file and syslog.
175         Kconfig_style_config DEBUG_FILE
176         Kconfig_style_config DEBUG_SYSLOG
177
178         if use hs2-0 ; then
179                 Kconfig_style_config INTERWORKING
180                 Kconfig_style_config HS20
181         fi
182
183         if use uncommon-eap-types; then
184                 Kconfig_style_config EAP_GPSK
185                 Kconfig_style_config EAP_SAKE
186                 Kconfig_style_config EAP_GPSK_SHA256
187                 Kconfig_style_config EAP_IKEV2
188                 Kconfig_style_config EAP_EKE
189         fi
190
191         if use eap-sim ; then
192                 # Smart card authentication
193                 Kconfig_style_config EAP_SIM
194                 Kconfig_style_config EAP_AKA
195                 Kconfig_style_config EAP_AKA_PRIME
196                 Kconfig_style_config PCSC
197         fi
198
199         if use fasteap ; then
200                 Kconfig_style_config EAP_FAST
201         fi
202
203         if use readline ; then
204                 # readline/history support for wpa_cli
205                 Kconfig_style_config READLINE
206         else
207                 #internal line edit mode for wpa_cli
208                 Kconfig_style_config WPA_CLI_EDIT
209         fi
210
211         # SSL authentication methods
212         if use ssl ; then
213                 Kconfig_style_config TLS openssl
214         elif use gnutls ; then
215                 Kconfig_style_config TLS gnutls
216                 Kconfig_style_config GNUTLS_EXTRA
217         else
218                 Kconfig_style_config TLS internal
219         fi
220
221         if use smartcard ; then
222                 Kconfig_style_config SMARTCARD
223         fi
224
225         if use tdls ; then
226                 Kconfig_style_config TDLS
227         fi
228
229         if use kernel_linux ; then
230                 # Linux specific drivers
231                 Kconfig_style_config DRIVER_ATMEL
232                 Kconfig_style_config DRIVER_HOSTAP
233                 Kconfig_style_config DRIVER_IPW
234                 Kconfig_style_config DRIVER_NL80211
235                 Kconfig_style_config DRIVER_RALINK
236                 Kconfig_style_config DRIVER_WEXT
237                 Kconfig_style_config DRIVER_WIRED
238
239                 if use ps3 ; then
240                         Kconfig_style_config DRIVER_PS3
241                 fi
242
243         elif use kernel_FreeBSD ; then
244                 # FreeBSD specific driver
245                 Kconfig_style_config DRIVER_BSD
246         fi
247
248         # Wi-Fi Protected Setup (WPS)
249         if use wps ; then
250                 Kconfig_style_config WPS
251                 Kconfig_style_config WPS2
252                 # USB Flash Drive
253                 Kconfig_style_config WPS_UFD
254                 # External Registrar
255                 Kconfig_style_config WPS_ER
256                 # Universal Plug'n'Play
257                 Kconfig_style_config WPS_UPNP
258                 # Near Field Communication
259                 Kconfig_style_config WPS_NFC
260         fi
261
262         # Wi-Fi Direct (WiDi)
263         if use p2p ; then
264                 Kconfig_style_config P2P
265                 Kconfig_style_config WIFI_DISPLAY
266         fi
267
268         # Access Point Mode
269         if use ap ; then
270                 Kconfig_style_config AP
271         fi
272
273         # Enable mitigation against certain attacks against TKIP
274         Kconfig_style_config DELAYED_MIC_ERROR_REPORT
275
276         # If we are using libnl 2.0 and above, enable support for it
277         # Bug 382159
278         # Removed for now, since the 3.2 version is broken, and we don't
279         # support it.
280         if has_version ">=dev-libs/libnl-3.2"; then
281                 Kconfig_style_config LIBNL32
282         fi
283
284         if use qt4 ; then
285                 pushd "${S}"/wpa_gui-qt4 > /dev/null
286                 eqmake4 wpa_gui.pro
287                 popd > /dev/null
288         fi
289 }
290
291 src_compile() {
292         einfo "Building wpa_supplicant"
293         emake V=1 BINDIR=/usr/sbin
294
295         if use wimax; then
296                 emake -C ../src/eap_peer clean
297                 emake -C ../src/eap_peer
298         fi
299
300         if use qt4 ; then
301                 pushd "${S}"/wpa_gui-qt4 > /dev/null
302                 einfo "Building wpa_gui"
303                 emake
304                 popd > /dev/null
305         fi
306 }
307
308 src_install() {
309         dosbin wpa_supplicant
310         dobin wpa_cli wpa_passphrase
311
312         # baselayout-1 compat
313         if has_version "<sys-apps/baselayout-2.0.0"; then
314                 dodir /sbin
315                 dosym /usr/sbin/wpa_supplicant /sbin/wpa_supplicant
316                 dodir /bin
317                 dosym /usr/bin/wpa_cli /bin/wpa_cli
318         fi
319
320         if has_version ">=sys-apps/openrc-0.5.0"; then
321                 newinitd "${FILESDIR}/${PN}-init.d" wpa_supplicant
322                 newconfd "${FILESDIR}/${PN}-conf.d" wpa_supplicant
323         fi
324
325         exeinto /etc/wpa_supplicant/
326         newexe "${FILESDIR}/wpa_cli.sh" wpa_cli.sh
327
328         dodoc ChangeLog {eap_testing,todo}.txt README{,-WPS} \
329                 wpa_supplicant.conf
330
331         newdoc .config build-config
332
333         doman doc/docbook/*.{5,8}
334
335         if use qt4 ; then
336                 into /usr
337                 dobin wpa_gui-qt4/wpa_gui
338                 doicon wpa_gui-qt4/icons/wpa_gui.svg
339                 make_desktop_entry wpa_gui "WPA Supplicant Administration GUI" "wpa_gui" "Qt;Network;"
340         fi
341
342         use wimax && emake DESTDIR="${D}" -C ../src/eap_peer install
343
344         if use dbus ; then
345                 pushd "${S}"/dbus > /dev/null
346                 insinto /etc/dbus-1/system.d
347                 newins dbus-wpa_supplicant.conf wpa_supplicant.conf
348                 insinto /usr/share/dbus-1/system-services
349                 doins fi.epitest.hostap.WPASupplicant.service fi.w1.wpa_supplicant1.service
350                 popd > /dev/null
351
352                 # This unit relies on dbus support, bug 538600.
353                 systemd_dounit systemd/wpa_supplicant.service
354         fi
355
356         systemd_dounit "systemd/wpa_supplicant@.service"
357         systemd_dounit "systemd/wpa_supplicant-nl80211@.service"
358         systemd_dounit "systemd/wpa_supplicant-wired@.service"
359 }
360
361 pkg_postinst() {
362         elog "If this is a clean installation of wpa_supplicant, you"
363         elog "have to create a configuration file named"
364         elog "/etc/wpa_supplicant/wpa_supplicant.conf"
365         elog
366         elog "An example configuration file is available for reference in"
367         elog "/usr/share/doc/${PF}/"
368
369         if [[ -e ${ROOT}etc/wpa_supplicant.conf ]] ; then
370                 echo
371                 ewarn "WARNING: your old configuration file ${ROOT}etc/wpa_supplicant.conf"
372                 ewarn "needs to be moved to ${ROOT}etc/wpa_supplicant/wpa_supplicant.conf"
373         fi
374
375         # Mea culpa, feel free to remove that after some time --mgorny.
376         local fn
377         for fn in wpa_supplicant{,@wlan0}.service; do
378                 if [[ -e "${ROOT}"/etc/systemd/system/network.target.wants/${fn} ]]
379                 then
380                         ebegin "Moving ${fn} to multi-user.target"
381                         mv "${ROOT}"/etc/systemd/system/network.target.wants/${fn} \
382                                 "${ROOT}"/etc/systemd/system/multi-user.target.wants/
383                         eend ${?} \
384                                 "Please try to re-enable ${fn}"
385                 fi
386         done
387 }