diff --git a/net-vpn/openvpn/Manifest b/net-vpn/openvpn/Manifest index 6757d7d3eac56..01ec096c508d8 100644 --- a/net-vpn/openvpn/Manifest +++ b/net-vpn/openvpn/Manifest @@ -6,3 +6,5 @@ DIST openvpn-2.7.5.tar.gz 2101063 BLAKE2B ea660165d76391239e07522b919936a483944d DIST openvpn-2.7.5.tar.gz.asc 833 BLAKE2B 538b890e60d20f812e21c98e30a231383713f3e0dfae22a05e9693b598abde7d45ded005e1718525f4585b084bfa80ab550d7c6eee134f04e13dc56734be975d SHA512 a60bf826a048e4b2f254fd9c9030e671c1cbea1a302b678b9ac49ae299f41543f2229058a8f91ee4d99ad3df190c3a63ecb0c981533ab1ac060bb881acc3f998 DIST openvpn-2.7.6.tar.gz 2105678 BLAKE2B 0cf4f6c7337ef3e31cb6f261423863b86fedcaaa69272d26811f4066afcece873ccebca167cb5e9f37bc474ccbbad7f71effc0678b98ed52864a96351a8cc3f0 SHA512 2e45d147f0983b6f343b6772c20b17e67bff0143e7bcf3c2a10551b77d9929c64c86e53b4ade5493023517f3ccd92b0c1011d03cb3543321d0f9faea408e6020 DIST openvpn-2.7.6.tar.gz.asc 833 BLAKE2B 28d5e137fbe0ee84de4862f03a682bb6313b604c6beded797bfe00e5936ff8ccb33e7266e7ec0a9604d1b4e26c756117292899f8c9779d5b16a766ff82a6b6a3 SHA512 79af977aa59ca3fcf0dc4c3f6c26d397e1b3eac85b92d1282440445486404a5943f1e1e55fed367be28fa38ccaba68cd08fd59613703b15b65f4d091360d02b4 +DIST openvpn-2.7.7.tar.gz 2128305 BLAKE2B 6f4230df1f238f0b0e1bdcc978850cf3f49c8c61dcebcdc819861399bf68016d14800140a2fb69bfc7fdc8fa4987cde531d59249f3f91533d7c9244080d557fc SHA512 27c12b94569c21fb09a081607bca8d959f70039d72335b6bf4a39d4fe02ddd1b60d8787594e0b878b1237892fd4372cf9888373609fde1469f9636eeb6ecb541 +DIST openvpn-2.7.7.tar.gz.asc 833 BLAKE2B d38bdb313bd053f915963eae91e86232c77027fb04f2de16da596945678158fc91c79475cc8137c49e6bbbeef47cfc6c2ae2a4fa31248c7e9b71b84b3de2bcd6 SHA512 da821e90da9be07418ce884f09c0e78c715d5b0036eefafbf50615a7b4e1d1cd123e48c5cd22c79b5b32884d6ae879beea5a02ccc3f60920fd061124056f52da diff --git a/net-vpn/openvpn/files/openvpn-2.2.init b/net-vpn/openvpn/files/openvpn-2.2.init new file mode 100644 index 0000000000000..85b2d78084203 --- /dev/null +++ b/net-vpn/openvpn/files/openvpn-2.2.init @@ -0,0 +1,146 @@ +#!/sbin/openrc-run +# Copyright 1999-2026 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +VPNDIR=${VPNDIR:-/etc/openvpn} +VPN=${SVCNAME#*.} +if [ -n "${VPN}" ] && [ ${SVCNAME} != "openvpn" ]; then + VPNPID="/run/openvpn.${VPN}.pid" +else + VPNPID="/run/openvpn.pid" +fi +VPNCONF="${VPNDIR}/${VPN}.conf" + +depend() { + need localmount net + use dns + after bootmisc + # provide a generic and specific vpn service #644702 + provide vpn vpn-${VPN} +} + +checkconfig() { + # Linux has good dynamic tun/tap creation + if [ "$RC_UNAME" = "Linux" ] ; then + if [ ! -e /dev/net/tun ]; then + if ! modprobe tun ; then + eerror "TUN/TAP support is not available" \ + "in this kernel" + return 1 + fi + fi + if [ -h /dev/net/tun ] && [ -c /dev/misc/net/tun ]; then + ebegin "Detected broken /dev/net/tun symlink, fixing..." + rm -f /dev/net/tun + ln -s /dev/misc/net/tun /dev/net/tun + eend $? + fi + return 0 + fi + + # Other OS's don't, so we rely on a pre-configured interface + # per vpn instance + local ifname=$(sed -n -e 's/[[:space:]]*dev[[:space:]][[:space:]]*\([^[:space:]]*\).*/\1/p' "${VPNCONF}") + if [ -z ${ifname} ] ; then + eerror "You need to specify the interface that this openvpn" \ + "instance should use" \ + "by using the dev option in ${VPNCONF}" + return 1 + fi + + if ! ifconfig "${ifname}" >/dev/null 2>/dev/null ; then + # Try and create it + echo > /dev/"${ifname}" >/dev/null + fi + if ! ifconfig "${ifname}" >/dev/null 2>/dev/null ; then + eerror "${VPNCONF} requires interface ${ifname}" \ + "but that does not exist" + return 1 + fi +} + +# Like https://github.com/OpenRC/openrc/blob/master/service-script-guide.md#dont-restartreload-with-a-broken-config +start_pre() { + if [ "${RC_CMD}" != "restart" ] ; then + checkconfig || return $? + fi +} +stop_pre() { + if [ "${RC_CMD}" = "restart" ] ; then + checkconfig || return $? + fi +} + +start() { + # If we are re-called by the openvpn gentoo-up.sh script + # then we don't actually want to start openvpn + [ "${IN_BACKGROUND}" = "true" ] && return 0 + + ebegin "Starting ${SVCNAME}" + + local args="" reenter=${RE_ENTER:-no} + # If the config file does not specify the cd option, we do + # But if we specify it, we override the config option which we do not want + if ! grep -q "^[ ]*cd[ ].*" "${VPNCONF}" ; then + args="${args} --cd ${VPNDIR}" + fi + + # We mark the service as inactive and then start it. + # When we get an authenticated packet from the peer then we run our script + # which configures our DNS if any and marks us as up. + if [ "${DETECT_CLIENT:-yes}" = "yes" ] && \ + grep -q "^[ ]*remote[ ].*" "${VPNCONF}" ; then + reenter="yes" + args="${args} --up-delay --up-restart" + args="${args} --script-security 2" + args="${args} --up /etc/openvpn/up.sh" + args="${args} --down-pre --down /etc/openvpn/down.sh" + + # Warn about setting scripts as we override them + if grep -Eq "^[ ]*(up|down)[ ].*" "${VPNCONF}" ; then + ewarn "WARNING: You have defined your own up/down scripts" + ewarn "As you're running as a client, we now force Gentoo specific" + ewarn "scripts to be run for up and down events." + ewarn "These scripts will call /etc/openvpn/${SVCNAME}-{up,down}.sh" + ewarn "where you can put your own code." + fi + + # Warn about the inability to change ip/route/dns information when + # dropping privs + if grep -q "^[ ]*user[ ].*" "${VPNCONF}" ; then + ewarn "WARNING: You are dropping root privileges!" + ewarn "As such openvpn may not be able to change ip, routing" + ewarn "or DNS configuration." + fi + else + # So we're a server. Run as openvpn unless otherwise specified + grep -q "^[ ]*user[ ].*" "${VPNCONF}" || args="${args} --user openvpn" + grep -q "^[ ]*group[ ].*" "${VPNCONF}" || args="${args} --group openvpn" + fi + + # Ensure that our scripts get the PEER_DNS variable + [ -n "${PEER_DNS}" ] && args="${args} --setenv PEER_DNS ${PEER_DNS}" + + [ "${reenter}" = "yes" ] && mark_service_inactive "${SVCNAME}" + start-stop-daemon --start --exec /usr/sbin/openvpn --pidfile "${VPNPID}" \ + -- --config "${VPNCONF}" --writepid "${VPNPID}" --daemon \ + --setenv SVCNAME "${SVCNAME}" ${args} + eend $? "Check your logs to see why startup failed" +} + +stop() { + # If we are re-called by the openvpn gentoo-down.sh script + # then we don't actually want to stop openvpn + if [ "${IN_BACKGROUND}" = "true" ] ; then + mark_service_inactive "${SVCNAME}" + return 0 + fi + + ebegin "Stopping ${SVCNAME}" + start-stop-daemon --stop --quiet \ + --exec /usr/sbin/openvpn --pidfile "${VPNPID}" \ + -- --config "${VPNCONF}" + eend $? +} + +# vim: set ts=4 : diff --git a/net-vpn/openvpn/openvpn-2.7.7.ebuild b/net-vpn/openvpn/openvpn-2.7.7.ebuild new file mode 100644 index 0000000000000..acd450bf39ae8 --- /dev/null +++ b/net-vpn/openvpn/openvpn-2.7.7.ebuild @@ -0,0 +1,214 @@ +# Copyright 1999-2026 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=8 + +inherit autotools dot-a systemd linux-info tmpfiles toolchain-funcs + +DESCRIPTION="Robust and highly flexible tunneling application compatible with many OSes" +HOMEPAGE="https://community.openvpn.net/ https://openvpn.net" + +if [[ ${PV} == "9999" ]]; then + EGIT_REPO_URI="https://github.com/OpenVPN/${PN}.git" + inherit git-r3 +else + VERIFY_SIG_OPENPGP_KEY_PATH=/usr/share/openpgp-keys/openvpn.asc + inherit verify-sig + + SRC_URI=" + https://build.openvpn.net/downloads/releases/${P}.tar.gz + verify-sig? ( https://build.openvpn.net/downloads/releases/${P}.tar.gz.asc ) + " + KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~loong ~mips ~ppc ~ppc64 ~riscv ~sparc ~x86" +fi + +LICENSE="GPL-2" +SLOT="0" + +IUSE="dco down-root examples inotify iproute2 kernel-ovpn +lz4 +lzo mbedtls" +IUSE+=" +openssl pam pkcs11 +plugins selinux systemd test" + +RESTRICT="!test? ( test )" +REQUIRED_USE=" + ^^ ( openssl mbedtls ) + pkcs11? ( !mbedtls ) + !plugins? ( !pam !down-root ) + inotify? ( plugins ) + dco? ( !iproute2 ) +" + +COMMON_DEPEND=" + kernel_linux? ( + iproute2? ( sys-apps/iproute2[-minimal] ) + ) + lz4? ( app-arch/lz4 ) + lzo? ( >=dev-libs/lzo-1.07 ) + mbedtls? ( net-libs/mbedtls:3= ) + openssl? ( >=dev-libs/openssl-1.0.2:0= ) + pam? ( sys-libs/pam ) + pkcs11? ( >=dev-libs/pkcs11-helper-1.11 ) + selinux? ( sys-libs/libselinux ) + systemd? ( sys-apps/systemd ) + dco? ( + !kernel-ovpn? ( >=net-vpn/ovpn-dco-0.2 ) + >=dev-libs/libnl-3.2.29:= + ) + sys-libs/libcap-ng:= +" + +BDEPEND=" + virtual/pkgconfig +" + +DEPEND=" + ${COMMON_DEPEND} + test? ( dev-util/cmocka ) +" +RDEPEND=" + ${COMMON_DEPEND} + acct-group/openvpn + acct-user/openvpn + selinux? ( sec-policy/selinux-openvpn ) +" + +if [[ ${PV} = "9999" ]]; then + BDEPEND+=" dev-python/docutils" +else + BDEPEND+=" verify-sig? ( >=sec-keys/openpgp-keys-openvpn-202600704 )" +fi + +pkg_setup() { + local CONFIG_CHECK="~TUN" + if use kernel-ovpn; then + local CONFIG_CHECK+=" ~OVPN" + fi + linux-info_pkg_setup +} + +src_prepare() { + default + + eautoreconf +} + +src_configure() { + local -a myeconfargs + + # See tests-no-lto.patch (done unconditionally to not have the build + # vary with and without tests) + lto-guarantee-fat + + local MBEDTLS_CFLAGS + local MBEDTLS_LIBS + if ! use mbedtls; then + myeconfargs+=( + $(use_enable pkcs11) + ) + else + MBEDTLS_CFLAGS="$($(tc-getPKG_CONFIG) --cflags mbedtls-3 mbedcrypto-3 mbedx509-3)" + MBEDTLS_LIBS="$($(tc-getPKG_CONFIG) --libs mbedtls-3 mbedcrypto-3 mbedx509-3)" + fi + + myeconfargs+=( + $(use_enable inotify async-push) + --with-crypto-library=$(usex mbedtls mbedtls openssl) + $(use_enable lz4) + $(use_enable lzo) + $(use_enable plugins) + $(use_enable iproute2) + $(use_enable pam plugin-auth-pam) + $(use_enable down-root plugin-down-root) + $(use_enable selinux) + $(use_enable systemd) + $(use_enable dco) + ) + + SYSTEMD_UNIT_DIR=$(systemd_get_systemunitdir) \ + TMPFILES_DIR="/usr/lib/tmpfiles.d" \ + IPROUTE=$(usex iproute2 '/bin/ip' '') \ + MBEDTLS_CFLAGS="${MBEDTLS_CFLAGS}" \ + MBEDTLS_LIBS="${MBEDTLS_LIBS}" \ + econf "${myeconfargs[@]}" +} + +src_test() { + local -x RUN_SUDO=false + + elog "Running top-level tests" + emake check + + elog "Running unit tests" + emake -C tests/unit_tests check +} + +src_install() { + default + + find "${ED}/usr" -type f -name '*.la' -delete || die + + # Install some helper scripts + keepdir /etc/openvpn + exeinto /etc/openvpn + doexe "${FILESDIR}/up.sh" + doexe "${FILESDIR}/down.sh" + + # Install the init script and config file + newinitd "${FILESDIR}/${PN}-2.2.init" openvpn + newconfd "${FILESDIR}/${PN}-2.1.conf" openvpn + + # install examples, controlled by the respective useflag + if use examples ; then + docinto examples + dodoc -r sample contrib + fi + + # https://github.com/OpenVPN/openvpn/issues/482 (bug #857648) + newtmpfiles distro/systemd/tmpfiles-openvpn.conf openvpn.conf +} + +pkg_postinst() { + tmpfiles_process openvpn.conf + + if systemd_is_booted || has_version sys-apps/systemd ; then + elog "In order to use OpenVPN with systemd please use the correct systemd service file." + elog + elog "server:" + elog + elog "- Place your server configuration file in /etc/openvpn/server" + elog "- Use the openvpn-server@.service like so" + elog "systemctl start openvpn-server@{Server-config}" + elog + elog "client:" + elog + elog "- Place your client configuration file in /etc/openvpn/client" + elog "- Use the openvpn-client@.service like so:" + elog "systemctl start openvpn-client@{Client-config}" + else + elog "The openvpn init script expects to find the configuration file" + elog "openvpn.conf in /etc/openvpn along with any extra files it may need." + elog + elog "To create more VPNs, simply create a new .conf file for it and" + elog "then create a symlink to the openvpn init script from a link called" + elog "openvpn.newconfname - like so" + elog " cd /etc/openvpn" + elog " ${EDITOR##*/} foo.conf" + elog " cd /etc/init.d" + elog " ln -s openvpn openvpn.foo" + elog + elog "You can then treat openvpn.foo as any other service, so you can" + elog "stop one vpn and start another if you need to." + fi + + if grep -Eq "^[ \t]*(up|down)[ \t].*" "${ROOT}/etc/openvpn"/*.conf 2>/dev/null ; then + ewarn + ewarn "WARNING: If you use the remote keyword then you are deemed to be" + ewarn "a client by our init script and as such we force up,down scripts." + ewarn "These scripts call /etc/openvpn/\$SVCNAME-{up,down}.sh where you" + ewarn "can move your scripts to." + fi + + if use plugins ; then + einfo + einfo "plugins have been installed into /usr/$(get_libdir)/${PN}/plugins" + fi +} diff --git a/net-vpn/openvpn/openvpn-9999.ebuild b/net-vpn/openvpn/openvpn-9999.ebuild index 070d0b7bf7315..acd450bf39ae8 100644 --- a/net-vpn/openvpn/openvpn-9999.ebuild +++ b/net-vpn/openvpn/openvpn-9999.ebuild @@ -137,10 +137,8 @@ src_test() { elog "Running top-level tests" emake check - pushd tests/unit_tests &>/dev/null || die elog "Running unit tests" - emake check - popd &>/dev/null || die + emake -C tests/unit_tests check } src_install() { @@ -148,9 +146,6 @@ src_install() { find "${ED}/usr" -type f -name '*.la' -delete || die - # install documentation - dodoc AUTHORS ChangeLog PORTS README - # Install some helper scripts keepdir /etc/openvpn exeinto /etc/openvpn @@ -158,20 +153,15 @@ src_install() { doexe "${FILESDIR}/down.sh" # Install the init script and config file - newinitd "${FILESDIR}/${PN}-2.1.init" openvpn + newinitd "${FILESDIR}/${PN}-2.2.init" openvpn newconfd "${FILESDIR}/${PN}-2.1.conf" openvpn # install examples, controlled by the respective useflag if use examples ; then - # (is the below comment relevant anymore?) - ## dodoc does not supportly support directory traversal, #15193 docinto examples dodoc -r sample contrib fi - # https://bugs.gentoo.org/755680#c3 - doman doc/openvpn.8 - # https://github.com/OpenVPN/openvpn/issues/482 (bug #857648) newtmpfiles distro/systemd/tmpfiles-openvpn.conf openvpn.conf }