1PORTNAME=		openvpn
2DISTVERSION=		2.6.14
3PORTREVISION?=		0
4CATEGORIES=		security net
5MASTER_SITES=		https://swupdate.openvpn.org/community/releases/ \
6			https://build.openvpn.net/downloads/releases/ \
7			FREEBSD_LOCAL/mandree
8
9MAINTAINER=		ports@MidnightBSD.org
10COMMENT?=		Secure IP/Ethernet tunnel daemon
11WWW=			https://openvpn.net/community/
12
13LICENSE=		gpl2
14LICENSE_FILE=		${WRKSRC}/COPYRIGHT.GPL
15
16BUILD_DEPENDS+=		cmocka>=0:sysutils/cmocka \
17			rst2man:textproc/py-docutils@${PY_FLAVOR}
18
19USES=			cpe libtool localbase:ldflags pkgconfig python:build shebangfix ssl
20USE_RC_SUBR=		openvpn
21
22SHEBANG_FILES=		sample/sample-scripts/auth-pam.pl \
23			sample/sample-scripts/totpauth.py \
24			sample/sample-scripts/ucn.pl \
25			sample/sample-scripts/verify-cn
26
27GNU_CONFIGURE=		yes
28CONFIGURE_ARGS+=	--enable-strict --with-crypto-library=openssl
29# set PLUGIN_LIBDIR so that unqualified plugin paths are found:
30CONFIGURE_ENV+=		PLUGINDIR="${PREFIX}/lib/openvpn/plugins"
31
32CONFLICTS_INSTALL?=	openvpn-2* openvpn-devel openvpn-mbedtls
33
34SUB_FILES=		pkg-message openvpn-client
35
36USERS=			openvpn
37GROUPS=			openvpn
38
39PORTDOCS=		*
40PORTEXAMPLES=		*
41
42OPTIONS_DEFINE=		ASYNC_PUSH DOCS EASYRSA EXAMPLES LZ4 LZO PKCS11 SMALL \
43			TEST UNITTESTS X509ALTUSERNAME
44OPTIONS_DEFAULT=	EASYRSA LZ4 LZO PKCS11 TEST
45ASYNC_PUSH_DESC=	Enable async-push support
46EASYRSA_DESC=		Install security/easy-rsa RSA helper package
47LZO_DESC=		LZO compression (incompatible with LibreSSL)
48PKCS11_DESC=		Use security/pkcs11-helper, needs same SSL lib!
49SMALL_DESC=		Build a smaller executable with fewer features
50UNITTESTS_DESC=		Enable unit tests
51X509ALTUSERNAME_DESC=	Enable --x509-username-field
52
53ASYNC_PUSH_LIB_DEPENDS=	libinotify.so:devel/libinotify
54ASYNC_PUSH_CONFIGURE_ENABLE=	async-push
55
56EASYRSA_RUN_DEPENDS=	easy-rsa>=0:security/easy-rsa
57
58LZ4_LIB_DEPENDS+=	liblz4.so:archivers/liblz4
59LZ4_CONFIGURE_ENABLE=	lz4
60
61LZO_LIB_DEPENDS+=	liblzo2.so:archivers/lzo2
62LZO_CONFIGURE_ENABLE=	lzo
63
64PKCS11_LIB_DEPENDS=	libpkcs11-helper.so:security/pkcs11-helper
65PKCS11_CONFIGURE_ENABLE=	pkcs11
66
67SMALL_CONFIGURE_ENABLE=	small
68
69TEST_ALL_TARGET=	check
70TEST_TEST_TARGET_OFF=	check
71
72UNITTESTS_BUILD_DEPENDS=	cmocka>=0:sysutils/cmocka
73UNITTESTS_CONFIGURE_ENABLE=	unit-tests
74
75X509ALTUSERNAME_CONFIGURE_ENABLE=	x509-alt-username
76
77.ifdef (LOG_OPENVPN)
78CFLAGS+=		-DLOG_OPENVPN=${LOG_OPENVPN}
79.endif
80
81.include <bsd.mport.options.mk>
82
83.if ${PORT_OPTIONS:MLZO}
84IGNORE_SSL=libressl libressl-devel
85IGNORE_SSL_REASON=OpenVPN does not have permission to include LZO with LibreSSL. Compile against OpenSSL, or if your setups support it, disable LZO support
86.endif
87
88.if ! ${PORT_OPTIONS:MLZ4} && ! ${PORT_OPTIONS:MLZO}
89CONFIGURE_ARGS+=	--enable-comp-stub
90.endif
91
92.include <bsd.port.pre.mk>
93
94.if !empty(PORT_OPTIONS:MLZO) && !empty(SSL_DEFAULT:Nbase:Nopenssl*)
95# in-depth security net if Mk/Uses/ssl.mk changes
96pre-everything::
97	@${ECHO_CMD} >&2 "ERROR: OpenVPN is not licensed to combine LZO with other OpenSSL-licensed libraries than OpenSSL. Compile against OpenSSL, or if your setups support it, disable LZO support."
98	@${SHELL} -c 'exit 1'
99.endif
100
101post-patch:
102	${REINPLACE_CMD} -E -i '' -e 's/(user|group) nobody/\1 openvpn/' \
103		-e 's/"nobody"( after init)/"openvpn" \1/' \
104		${WRKSRC}/sample/sample-config-files/*.conf \
105		${WRKSRC}/doc/man-sections/generic-options.rst
106
107pre-configure:
108	# just too many of sign-compare; bitwise-instead-of-logical was audited and is intentional,
109	# and unused-function affects test---these are developer-side warnings, not relevant on end systems
110	${REINPLACE_CMD} 's/-Wsign-compare/-Wno-unknown-warning-option -Wno-sign-compare -Wno-bitwise-instead-of-logical -Wno-unused-function/' ${WRKSRC}/configure
111.ifdef (LOG_OPENVPN)
112	@${ECHO} "Building with LOG_OPENVPN=${LOG_OPENVPN}"
113.else
114	@${ECHO} ""
115	@${ECHO} "You may use the following build options:"
116	@${ECHO} ""
117	@${ECHO} "      LOG_OPENVPN={Valid syslog facility, default LOG_DAEMON}"
118	@${ECHO} "      EXAMPLE:  make LOG_OPENVPN=LOG_LOCAL6"
119	@${ECHO} ""
120.endif
121.if !empty(SSL_DEFAULT:Mlibressl*)
122	@${ECHO} "### --------------------------------------------------------- ###"
123	@${ECHO} "### NOTE that libressl is not primarily supported by OpenVPN  ###"
124	@${ECHO} "### Do not report bugs without fixes/patches unless the issue ###"
125	@${ECHO} "### can be reproduced with a released OpenSSL version.        ###"
126	@${ECHO} "### --------------------------------------------------------- ###"
127	@sleep 10
128.endif
129
130post-configure:
131	${REINPLACE_CMD} '/^CFLAGS =/s/$$/ -fPIC/' \
132	 	${WRKSRC}/src/plugins/auth-pam/Makefile \
133	 	${WRKSRC}/src/plugins/down-root/Makefile
134
135# sanity check that we don't inherit incompatible SSL libs through,
136# for instance, pkcs11-helper:
137_tlslibs=libssl libcrypto
138post-build:
139	@a=$$(LC_ALL=C ldd -f '%o\n' ${WRKSRC}/src/openvpn/openvpn \
140	|	${SORT} -u) ; set -- $$(for i in ${_tlslibs} ; do ${PRINTF} '%s\n' "$$a" | ${GREP} $${i}.so | wc -l ; done | ${SORT} -u) ;\
141	if test "$$*" != "1" ; then ( set -x ; ldd -a ${WRKSRC}/src/openvpn/openvpn ) ; ${PRINTF} '%s\n' "$$a" ; ${ECHO_CMD} >&2 "${.CURDIR} FAILED: either of ${_tlslibs} libraries linked multiple times" ; ${RM} ${BUILD_COOKIE} ; exit 1 ; fi
142
143post-install:
144	${STRIP_CMD} ${PREFIX}/lib/openvpn/plugins/openvpn-plugin-auth-pam.so
145	${STRIP_CMD} ${PREFIX}/lib/openvpn/plugins/openvpn-plugin-down-root.so
146	${INSTALL_SCRIPT} ${WRKSRC}/contrib/pull-resolv-conf/client.up ${PREFIX}/libexec/openvpn-client.up
147	${INSTALL_SCRIPT} ${WRKSRC}/contrib/pull-resolv-conf/client.down ${PREFIX}/libexec/openvpn-client.down
148	${INSTALL_SCRIPT} ${WRKDIR}/openvpn-client ${PREFIX}/sbin/openvpn-client
149	${MKDIR} ${PREFIX}/include
150
151post-install-DOCS-on:
152	${MKDIR} ${FAKE_DESTDIR}${DOCSDIR}/
153.for i in AUTHORS ChangeLog PORTS
154	${INSTALL_DATA} ${WRKSRC}/${i} ${FAKE_DESTDIR}${DOCSDIR}/
155.endfor
156
157post-install-EXAMPLES-on:
158	(cd ${WRKSRC}/sample && ${COPYTREE_SHARE} \* ${FAKE_DESTDIR}${EXAMPLESDIR}/)
159	${CHMOD} ${BINMODE} ${FAKE_DESTDIR}${EXAMPLESDIR}/sample-scripts/*
160	-${RM} ${FAKE_DESTDIR}${EXAMPLESDIR}/sample-config-files/*.orig
161
162.include <bsd.port.post.mk>
163