https://gitlab.gnome.org/GNOME/network-manager-sstp/-/commit/4cd0ec66174011925c93aa04edccca92b4d1387f.patch From 4cd0ec66174011925c93aa04edccca92b4d1387f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eivind=20N=C3=A6ss?= Date: Sat, 25 Feb 2023 05:10:19 +0000 Subject: [PATCH] Support to compile against pppd-2.5.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Eivind Næss --- Makefile.am | 13 ++- configure.ac | 84 ++++++++++++---- src/nm-sstp-pppd-compat.h | 95 +++++++++++++++++++ src/nm-sstp-pppd-mppe.c | 7 +- src/nm-sstp-pppd-plugin.c | 77 ++++++++------- ...{nm-ppp-status.h => nm-sstp-pppd-status.h} | 0 src/nm-sstp-service.c | 2 +- 7 files changed, 214 insertions(+), 64 deletions(-) create mode 100644 src/nm-sstp-pppd-compat.h rename src/{nm-ppp-status.h => nm-sstp-pppd-status.h} (100%) diff --git a/Makefile.am b/Makefile.am index 8a66ce9..30b63a2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -96,7 +96,7 @@ src_nm_sstp_service_SOURCES = \ shared/utils.c \ shared/utils.h \ shared/nm-service-defines.h \ - src/nm-ppp-status.h \ + src/nm-sstp-pppd-status.h \ src/nm-sstp-service.h \ src/nm-sstp-service.c src_nm_sstp_service_CPPFLAGS = \ @@ -114,12 +114,15 @@ pppd_plugin_LTLIBRARIES = src/nm-sstp-pppd-plugin.la src_nm_sstp_pppd_plugin_la_SOURCES = \ shared/nm-utils/nm-shared-utils.c \ src/nm-sstp-pppd-plugin.c \ - src/nm-sstp-pppd-mppe.c \ src/nm-sstp-pppd-mppe.h \ - src/nm-ppp-status.h + src/nm-sstp-pppd-compat.h \ + src/nm-sstp-pppd-status.h +if !WITH_PPP_MPPE_KEYS +src_nm_sstp_pppd_plugin_la_SOURCES += \ + src/nm-sstp-pppd-mppe.h +endif src_nm_sstp_pppd_plugin_la_CPPFLAGS = \ - $(src_cppflags) \ - -DUSE_EAPTLS -DINET6 + $(src_cppflags) src_nm_sstp_pppd_plugin_la_LDFLAGS = \ -module -avoid-version src_nm_sstp_pppd_plugin_la_LIBADD = \ diff --git a/configure.ac b/configure.ac index b80b4ae..80b5a1f 100644 --- a/configure.ac +++ b/configure.ac @@ -9,7 +9,6 @@ AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_HEADERS([config.h]) - dnl Define _SYSTEM_EXTENSIONS for various things like strcasestr() AC_USE_SYSTEM_EXTENSIONS @@ -19,8 +18,11 @@ dnl AC_PROG_CC AM_PROG_CC_C_O AC_PROG_INSTALL +AC_PROG_SED LT_INIT + AC_PATH_PROG(GLIB_COMPILE_RESOURCES, glib-compile-resources) +PKG_PROG_PKG_CONFIG() AC_CHECK_PROG([has_file], file, yes, no) if test x$has_file = xno ; then @@ -32,10 +34,17 @@ if test x$has_find = xno ; then AC_MSG_ERROR(["find" utility not found.]) fi -AC_CHECK_HEADERS(fcntl.h paths.h sys/ioctl.h syslog.h unistd.h) +AC_CHECK_HEADERS([ + fcntl.h + paths.h + syslog.h + stdarg.h + stdbool.h + sys/ioctl.h + unistd.h]) dnl -dnl Versions >= 2.4.10 will have pkgconfig support +dnl Versions >= 2.5.0 will have pkg-config support PKG_CHECK_EXISTS([pppd], [AS_VAR_SET([pppd_pkgconfig_support],[yes])]) @@ -45,32 +54,46 @@ AC_CHECK_HEADERS(pppd/pppd.h,, [AC_MSG_ERROR([pppd.h missing, Hint: apt-get install ppp-dev])]) dnl -dnl Check if the version of mppe.h define mppe_keys_xxx() functions, 2.4.9 does not; but 2.4.10 will. +dnl Check the presense of other pppd/*.h files +AC_CHECK_HEADERS([ + pppd/chap.h + pppd/chap-new.h + pppd/chap_ms.h + ]) + +dnl +dnl Check if the version of mppe.h define mppe_keys_isset() functions, this has been backported to 2.4.9 on some Linux distributions CFLAGS_OLD="$CFLAGS" CFLAGS="$CFLAGS -Werror" -AC_CACHE_CHECK([if pppd/mppe.h defines mppe_keys_xyz() functions], ac_cv_working_mppe_h, -[AC_COMPILE_IFELSE( - [AC_LANG_PROGRAM([[ - @%:@define MPPE 1 - @%:@include - @%:@include - @%:@include ]], - [[if (mppe_keys_isset()) - return 0;]])], +AC_CACHE_CHECK([for mppe_keys_isset() function], ac_cv_working_mppe_h, [ + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([[ + @%:@define MPPE 1 + @%:@include + @%:@include + @%:@include + ]], [[ + if (mppe_keys_isset()) + return 0; + ]] + )], [ac_cv_working_mppe_h=yes], - [ac_cv_working_mppe_h=no])]) -if test $ac_cv_working_mppe_h = xyes; then + [ac_cv_working_mppe_h=no]) +]) +if test $ac_cv_working_mppe_h = yes; then AC_DEFINE(HAVE_MPPE_KEYS_FUNCTIONS, 1, [Define to 1 if you have and it declares the mppe_keys_xyz() functions]) fi CFLAGS="$CFLAGS_OLD" +AM_CONDITIONAL(WITH_PPP_MPPE_KEYS, test "x${ac_cv_working_mppe_h}" != "xno") + dnl -dnl Support for the auth notify callback in pppd >= 2.4.9 +dnl Support for the auth notify callback in pppd >= 2.4.9 AC_ARG_WITH([pppd-auth-notify-support], [AS_HELP_STRING([--with-pppd-auth-notify-support], [is the auth-notifier supported by pppd])]) if test x"$with_pppd_auth_notify_support" != xyes; then - if test x"$pppd_pkgconfig_support" = xyes; then # pkgconfig implies pppd > 2.4.9 + if test x"$pppd_pkgconfig_support" = xyes; then AS_VAR_SET([with_pppd_auth_notify_support],[yes]) fi fi @@ -81,11 +104,20 @@ else fi dnl -dnl Enable support for extended tls settings in pppd > 2.4.9 -AC_ARG_WITH([pppd-ext-tls-settings-suppport], - [AS_HELP_STRING([--with-pppd-ext-tls-settings-support], [is settings such as pkcs12, tls-verify-method, tls-verify-key-usage and max-tls-version supported in by pppd])]) +dnl Get the version of pppd using pkg-config, assume 2.4.9 if not present +PPPD_VERSION=2.4.9 +if test x"$pppd_pkgconfig_support" = xyes; then + PPPD_VERSION=`$PKG_CONFIG --modversion pppd` +fi + +dnl +dnl Enable support for extended tls settings in pppd >= 2.5.0 +AC_ARG_WITH([pppd-ext-tls-settings-suppport], [ + AS_HELP_STRING([--with-pppd-ext-tls-settings-support], + [is settings such as pkcs12, tls-verify-method, tls-verify-key-usage and max-tls-version supported in by pppd]) + ]) if test x"$with_pppd_ext_tls_settings_support" != xyes; then - if test x"$pppd_pkgconfig_support" = xyes; then # pkgconfig implies pppd > 2.4.9 + if test x"$pppd_pkgconfig_support" = xyes; then AS_VAR_SET([with_pppd_ext_tls_settings_support],[yes]) fi fi @@ -95,6 +127,16 @@ else AS_VAR_SET([with_pppd_ext_tls_settings_support],[no]) fi +dnl The version of pppd dictates what code can be included, i.e. enable use of +dnl #if WITH_PPP_VERSION >= PPP_VERSION(2,5,0) in the code +AC_DEFINE_UNQUOTED([PPP_VERSION(x,y,z)], + [((x & 0xFF) << 16 | (y & 0xFF) << 8 | (z & 0xFF) << 0)], + [Macro to help determine the particular version of pppd]) +PPP_VERSION=$(echo $PPPD_VERSION | sed -e "s/\./\,/g") +AC_DEFINE_UNQUOTED(WITH_PPP_VERSION, PPP_VERSION($PPP_VERSION), + [The real version of pppd represented as an int]) + + dnl dnl Specify the path of the pppd plugin directory AC_ARG_WITH([pppd-plugin-dir], diff --git a/src/nm-sstp-pppd-compat.h b/src/nm-sstp-pppd-compat.h new file mode 100644 index 0000000..4ae7c26 --- /dev/null +++ b/src/nm-sstp-pppd-compat.h @@ -0,0 +1,95 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* nm-sstp-service - sstp (and other pppd) integration with NetworkManager + * + * (C) 2007 - 2008 Novell, Inc. + * (C) 2008 - 2009 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#ifndef __NM_SSTP_PPPD_COMPAT_H__ +#define __NM_SSTP_PPPD_COMPAT_H__ + +#define USE_EAPTLS 1 +#define INET6 1 + +// PPP < 2.5.0 defines and exports VERSION which overlaps with current package VERSION define. +// this silly macro magic is to work around that. + +#undef VERSION +#include + +#ifndef PPPD_VERSION +#define PPPD_VERSION VERSION +#endif + +#include +#include +#include +#include +#include +#include +#include + +#ifdef HAVE_PPPD_CHAP_H + #include +#endif + +#ifdef HAVE_PPPD_CHAP_NEW_H + #include +#endif + +#ifdef HAVE_PPPD_CHAP_MS_H + #include +#endif + +#ifndef PPP_PROTO_CHAP +#define PPP_PROTO_CHAP 0xc223 +#endif + +#ifndef PPP_PROTO_EAP +#define PPP_PROTO_EAP 0xc227 +#endif + +#if WITH_PPP_VERSION < PPP_VERSION(2,5,0) + +static inline bool debug_on(void) +{ + return debug; +} + +static inline const char *ppp_ipparam(void) +{ + return ipparam; +} + +static inline int ppp_ifunit(void) +{ + return ifunit; +} + +static inline const char *ppp_ifname(void) +{ + return ifname; +} + +static inline int ppp_get_mtu(int idx) +{ + return netif_get_mtu(idx); +} + +#endif // #if WITH_PPP_VERSION < PPP_VERSION(2,5,0) +#endif // #ifdef __NM_SSTP_PPPD_COMPAT_H__ diff --git a/src/nm-sstp-pppd-mppe.c b/src/nm-sstp-pppd-mppe.c index 827e4aa..b1b086a 100644 --- a/src/nm-sstp-pppd-mppe.c +++ b/src/nm-sstp-pppd-mppe.c @@ -21,8 +21,9 @@ */ #include - +#include #include + #include "nm-sstp-pppd-mppe.h" #ifndef HAVE_MPPE_KEYS_FUNCTIONS @@ -39,7 +40,7 @@ int mppe_get_send_key(u_char *send_key, int length) if (mppe_keys_isset()) { if (length > MPPE_MAX_KEY_SIZE) length = MPPE_MAX_KEY_SIZE; - BCOPY(mppe_send_key, send_key, length); + memcpy(mppe_send_key, send_key, length); return length; } return 0; @@ -53,7 +54,7 @@ int mppe_get_recv_key(u_char *recv_key, int length) if (mppe_keys_isset()) { if (length > MPPE_MAX_KEY_SIZE) length = MPPE_MAX_KEY_SIZE; - BCOPY(mppe_recv_key, recv_key, length); + memcpy(mppe_recv_key, recv_key, length); return length; } return 0; diff --git a/src/nm-sstp-pppd-plugin.c b/src/nm-sstp-pppd-plugin.c index 0d8b03f..f9fc815 100644 --- a/src/nm-sstp-pppd-plugin.c +++ b/src/nm-sstp-pppd-plugin.c @@ -20,19 +20,10 @@ * */ -#include +#ifndef __CONFIG_H__ #define __CONFIG_H__ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "nm-default.h" +#include +#endif #include #include @@ -43,26 +34,26 @@ #include #include #include + #include -#include "nm-ppp-status.h" -#include "nm-sstp-service.h" +#include "nm-sstp-pppd-compat.h" +#include "nm-sstp-pppd-status.h" #include "nm-sstp-pppd-mppe.h" + +#include "nm-default.h" +#include "nm-sstp-service.h" #include "nm-utils/nm-shared-utils.h" #include "nm-utils/nm-vpn-plugin-macros.h" #ifndef USE_PPPD_AUTH_HOOK - -#define PPP_PROTO_CHAP 0xc223 -#define PPP_PROTO_EAP 0xc227 - static int sstp_notify_sent = 0; - #endif /* USE_PPPD_AUTH_HOOK */ int plugin_init (void); -char pppd_version[] = VERSION; + +char pppd_version[] = PPPD_VERSION; /*****************************************************************************/ typedef void (*protrej_fn)(int unit); @@ -200,7 +191,7 @@ nm_sstp_getsock(void) /* Setup the address */ addr.sun_family = AF_UNIX; - snprintf(addr.sun_path, sizeof(addr.sun_path), "/var/run/sstpc/sstpc-%s", ipparam); + snprintf(addr.sun_path, sizeof(addr.sun_path), "/var/run/sstpc/sstpc-%s", ppp_ipparam()); /* Connect the socket */ ret = connect(sock, (struct sockaddr*) &addr, alen); @@ -371,7 +362,7 @@ nm_sstp_notify(void) if (key_len > 0) { sstp_api_attr_add(msg, SSTP_API_ATTR_MPPE_SEND, key_len, key); - if (debug) { + if (debug_on()) { slprintf(key_buf, sizeof(key_buf)-1, "%0.*B", key_len, key); _LOGI ("The MPPE-Send-Key: %s", key); } @@ -382,7 +373,7 @@ nm_sstp_notify(void) if (key_len > 0) { sstp_api_attr_add(msg, SSTP_API_ATTR_MPPE_RECV, key_len, key); - if (debug) { + if (debug_on()) { slprintf(key_buf, sizeof(key_buf)-1, "%0.*B", key_len, key); _LOGI ("The MPPE-Recv-Key: %s", key); } @@ -471,7 +462,7 @@ nm_ip4_add_route(GVariantBuilder *builder, int network, int gateway, int prefix, static GVariant* nm_ip4_get_params(void) { - guint32 pppd_made_up_address = htonl (0x0a404040 + ifunit); + guint32 pppd_made_up_address = htonl (0x0a404040 + ppp_ifunit()); ipcp_options *opts = &ipcp_gotoptions[0]; ipcp_options *peer_opts = &ipcp_hisoptions[0]; GVariantBuilder builder; @@ -584,9 +575,9 @@ nm_send_config (void) g_variant_builder_add (&builder, "{sv}", NM_VPN_PLUGIN_CONFIG_TUNDEV, - g_variant_new_string (ifname)); + g_variant_new_string (ppp_ifname())); - mtu = netif_get_mtu (ifunit); + mtu = ppp_get_mtu (ppp_ifunit()); g_variant_builder_add (&builder, "{sv}", NM_VPN_PLUGIN_CONFIG_MTU, g_variant_new_uint32 (mtu)); @@ -870,6 +861,31 @@ nm_exit_notify (void *data, int arg) g_clear_object (&gl.proxy); } +#if WITH_PPP_VERSION >= PPP_VERSION(2,5,0) +static void +nm_add_notifiers (void) +{ + ppp_add_notify (NF_PHASE_CHANGE, nm_phasechange, NULL); + ppp_add_notify (NF_EXIT, nm_exit_notify, NULL); + ppp_add_notify (NF_IP_UP, nm_ip_up, NULL); + ppp_add_notify (NF_IPV6_UP, nm_ip6_up, NULL); + ppp_add_notify (NF_AUTH_UP, nm_auth_notify, NULL); +} +#else +static void +nm_add_notifiers (void) +{ + add_notifier (&phasechange, nm_phasechange, NULL); + add_notifier (&exitnotify, nm_exit_notify, NULL); + add_notifier (&ip_up_notifier, nm_ip_up, NULL); + add_notifier (&ipv6_up_notifier, nm_ip6_up, NULL); + +#ifdef USE_PPPD_AUTH_HOOK + add_notifier (&auth_up_notifier, nm_auth_notify, NULL); +#endif +} +#endif + int plugin_init (void) { @@ -916,14 +932,7 @@ plugin_init (void) snoop_recv_hook = nm_snoop_recv; new_phase_hook = nm_new_phase; #endif - - add_notifier (&phasechange, nm_phasechange, NULL); - add_notifier (&exitnotify, nm_exit_notify, NULL); - add_notifier (&ip_up_notifier, nm_ip_up, NULL); - add_notifier (&ipv6_up_notifier, nm_ip6_up, NULL); -#ifdef USE_PPPD_AUTH_HOOK - add_notifier (&auth_up_notifier, nm_auth_notify, NULL); -#endif + nm_add_notifiers(); gl.old_protrej = ipv6cp_protent.protrej; ipv6cp_protent.protrej = nm_ipv6_protrej; diff --git a/src/nm-ppp-status.h b/src/nm-sstp-pppd-status.h similarity index 100% rename from src/nm-ppp-status.h rename to src/nm-sstp-pppd-status.h diff --git a/src/nm-sstp-service.c b/src/nm-sstp-service.c index 0b1eea4..bdf977e 100644 --- a/src/nm-sstp-service.c +++ b/src/nm-sstp-service.c @@ -44,7 +44,7 @@ #include #include "utils.h" -#include "nm-ppp-status.h" +#include "nm-sstp-pppd-status.h" #include "nm-sstp-pppd-service-dbus.h" #include "nm-utils/nm-shared-utils.h" #include "nm-utils/nm-vpn-plugin-macros.h" -- GitLab