Fix include paths for plugins to use the public API of pppd

This change does a few different things.
 * Projects that needs #include "config.h" should use a config.h.in for the project generated by configure in the project's local directory.
 * All projects will use #include <pppd/pppd.h>, and Makefile will add -I${top_srcdir} to the appropriate *_CPPFLAGS variable.
 * The inclusion of <pppd/pppdconf.h> will set the presidence for all features enabled/disabled in pppd
 * Plugins will now need to use PPPD_VERSION as it conflicts with VERSION from config.h generated by autotools for third party packages

Currently, only pppoe require the use of config.h to correctly set the defines for which header files and so on was detected by configure

Other projects only needed to include <pppd/pppd.h> (and maybe a few other header files), a future change will fixup <pppd/pppd.h> to include features as needed such that it's the only needed include for a plugin. This will avoid littering the code with #ifdef/#endif constructs.

BREAKING CHANGE!

pppd/pppd.h no longer provide VERSION, third party packages are required to switch to use PPPD_VERSION. This is to avoid conflict with a source package's own VERSION as set by autotools / config.h. Also, the use of PPP_VERSION conflicts with public header files from Glibc/Linux kernel.

Example:

   char pppd_version[] = PPPD_VERSION;

pppd will load plugins, and also look for the symbol "pppd_version" to validate that the plugin was built for the current version of pppd.

Signed-off-by: Eivind Næss <eivnaes@yahoo.com>
This commit is contained in:
Eivind Næss 2021-08-10 16:38:45 -07:00
parent e8605bcddb
commit bdd34ab1f2
28 changed files with 161 additions and 127 deletions

2
.gitignore vendored
View File

@ -35,6 +35,8 @@ autom4te.cache
/pppd/config.h
/pppd/config.h.in
/pppd/pppdconf.h
/pppd/plugins/pppoe/config.h
/pppd/plugins/pppoe/stamp-h3
# https://www.gnu.org/software/libtool/
/libtool

View File

@ -11,7 +11,7 @@ AM_MAINTAINER_MODE([enable])
AC_LANG(C)
AC_CONFIG_SRCDIR([pppd/main.c])
AC_CONFIG_HEADERS([pppd/config.h pppd/pppdconf.h])
AC_CONFIG_HEADERS([pppd/config.h pppd/pppdconf.h pppd/plugins/pppoe/config.h])
# Checks for programs.
AC_PROG_CC
@ -305,6 +305,7 @@ if test "x${with_gtk}" = "xyes"; then
fi
AM_CONDITIONAL([WITH_GTK], test "x${with_gtk}" = "xyes")
AC_DEFINE_UNQUOTED(PPPD_VERSION, "$VERSION", [Version of pppd])
AC_CONFIG_FILES([
Makefile

View File

@ -1,7 +1,7 @@
pppd_plugin_LTLIBRARIES = minconn.la passprompt.la passwordfd.la winbind.la
pppd_plugindir = $(PPPD_PLUGIN_DIR)
PLUGIN_CPPFLAGS = -I${top_srcdir}/include -I${top_srcdir}/pppd
PLUGIN_CPPFLAGS = -I${top_srcdir}/include -I${top_srcdir}
PLUGIN_LDFLAGS = -module -avoid-version
minconn_la_CPPFLAGS = $(PLUGIN_CPPFLAGS)

View File

@ -32,15 +32,12 @@
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stddef.h>
#include <time.h>
#include "pppd.h"
#include <pppd/pppd.h>
char pppd_version[] = VERSION;
char pppd_version[] = PPPD_VERSION;
static int minconnect = 0;

View File

@ -9,17 +9,13 @@
* 2 of the License, or (at your option) any later version.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <errno.h>
#include <unistd.h>
#include <sys/wait.h>
#include <syslog.h>
#include "pppd.h"
#include <pppd/pppd.h>
char pppd_version[] = VERSION;
char pppd_version[] = PPPD_VERSION;
static char promptprog[PATH_MAX+1];
static int promptprog_refused = 0;

View File

@ -7,18 +7,14 @@
* with pap- and chap-secrets files.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include "pppd.h"
#include <pppd/pppd.h>
char pppd_version[] = VERSION;
char pppd_version[] = PPPD_VERSION;
static int passwdfd = -1;
static char save_passwd[MAXSECRETLEN];

View File

@ -6,7 +6,7 @@ noinst_HEADERS = \
atmres.h \
atmsap.h
pppoatm_la_CPPFLAGS = -I${top_srcdir}/include -I${top_srcdir}/pppd
pppoatm_la_CPPFLAGS = -I${top_srcdir}/include -I${top_srcdir}
pppoatm_la_LDFLAGS = -module -avoid-version
pppoatm_la_SOURCES = pppoatm.c

View File

@ -13,17 +13,10 @@
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include "pppd.h"
#include "pathnames.h"
#include "fsm.h" /* Needed for lcp.h to include cleanly */
#include "lcp.h"
#include <atm.h>
#include <linux/atmdev.h>
#include <linux/atmppp.h>
@ -31,7 +24,13 @@
#include <net/if.h>
#include <sys/ioctl.h>
const char pppd_version[] = VERSION;
#include <pppd/pppd.h>
#include <pppd/pathnames.h>
#include <pppd/fsm.h> /* Needed for lcp.h to include cleanly */
#include <pppd/lcp.h>
const char pppd_version[] = PPPD_VERSION;
static struct sockaddr_atmpvc pvcaddr;
static char *qosstr = NULL;

View File

@ -6,7 +6,7 @@ dist_man8_MANS = pppoe-discovery.8
noinst_HEADERS = \
pppoe.h
pppoe_la_CPPFLAGS = -I${top_srcdir} -I${top_srcdir}/include
pppoe_la_CPPFLAGS = -I${top_srcdir}/include -I${top_srcdir}
pppoe_la_LDFLAGS = -module -avoid-version
pppoe_la_SOURCES = plugin.c discovery.c if.c common.c

View File

@ -17,12 +17,12 @@ static char const RCSID[] =
"$Id: common.c,v 1.3 2008/06/09 08:34:23 paulus Exp $";
#ifdef HAVE_CONFIG_H
#include <config.h>
#include "config.h"
#endif
#define _GNU_SOURCE 1
#include "pppoe.h"
#include "pppd/pppd.h"
#include <pppd/pppd.h>
#include <string.h>
#include <errno.h>

View File

@ -0,0 +1,56 @@
/* pppd/config.h.in. Generated from configure.ac by autoheader. */
/* Define to 1 if you have the <asm/types.h> header file. */
#undef HAVE_ASM_TYPES_H
/* Define to 1 if you have the <linux/if_ether.h> header file. */
#undef HAVE_LINUX_IF_ETHER_H
/* Define to 1 if you have the <linux/if.h> header file. */
#undef HAVE_LINUX_IF_H
/* Define to 1 if you have the <linux/if_packet.h> header file. */
#undef HAVE_LINUX_IF_PACKET_H
/* Define to 1 if you have the <net/if_arp.h> header file. */
#undef HAVE_NET_IF_ARP_H
/* Define to 1 if you have the <net/if_types.h> header file. */
#undef HAVE_NET_IF_TYPES_H
/* Define to 1 if you have the <netinet/if_ether.h> header file. */
#undef HAVE_NETINET_IF_ETHER_H
/* Define to 1 if you have the <netpacket/packet.h> header file. */
#undef HAVE_NETPACKET_PACKET_H
/* Define to 1 if you have the <net/bpf.h> header file. */
#undef HAVE_NET_BPF_H
/* Define to 1 if you have the <net/if.h> header file. */
#undef HAVE_NET_IF_H
/* Define to 1 if you have the <sys/dlpi.h> header file. */
#undef HAVE_SYS_DLPI_H
/* Define to 1 if you have the <sys/ioctl.h> header file. */
#undef HAVE_SYS_IOCTL_H
/* Define to 1 if you have the <sys/socket.h> header file. */
#undef HAVE_SYS_SOCKET_H
/* Define to 1 if you have the <sys/uio.h> header file. */
#undef HAVE_SYS_UIO_H
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* The size of `unsigned int', as computed by sizeof. */
#undef SIZEOF_UNSIGNED_INT
/* The size of `unsigned long', as computed by sizeof. */
#undef SIZEOF_UNSIGNED_LONG
/* The size of `unsigned short', as computed by sizeof. */
#undef SIZEOF_UNSIGNED_SHORT

View File

@ -12,14 +12,14 @@ static char const RCSID[] =
"$Id: discovery.c,v 1.6 2008/06/15 04:35:50 paulus Exp $";
#ifdef HAVE_CONFIG_H
#include <config.h>
#include "config.h"
#endif
#define _GNU_SOURCE 1
#include "pppoe.h"
#include "pppd/pppd.h"
#include "pppd/fsm.h"
#include "pppd/lcp.h"
#include <pppd/pppd.h>
#include <pppd/fsm.h>
#include <pppd/lcp.h>
#include <string.h>
#include <stdlib.h>

View File

@ -17,12 +17,12 @@ static char const RCSID[] =
"$Id: if.c,v 1.2 2008/06/09 08:34:23 paulus Exp $";
#ifdef HAVE_CONFIG_H
#include <config.h>
#include "config.h"
#endif
#define _GNU_SOURCE 1
#include "pppoe.h"
#include "pppd/pppd.h"
#include <pppd/pppd.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>

View File

@ -26,19 +26,12 @@ static char const RCSID[] =
"$Id: plugin.c,v 1.17 2008/06/15 04:35:50 paulus Exp $";
#ifdef HAVE_CONFIG_H
#include <config.h>
#include "config.h"
#endif
#define _GNU_SOURCE 1
#include "pppoe.h"
#include "pppd/pppd.h"
#include "pppd/fsm.h"
#include "pppd/lcp.h"
#include "pppd/ipcp.h"
#include "pppd/ccp.h"
/* #include "pppd/pathnames.h" */
#include <linux/types.h>
#include <sys/ioctl.h>
#include <sys/types.h>
@ -54,13 +47,20 @@ static char const RCSID[] =
#include <linux/ppp_defs.h>
#include <linux/if_pppox.h>
#include <pppd/pppd.h>
#include <pppd/fsm.h>
#include <pppd/lcp.h>
#include <pppd/ipcp.h>
#include <pppd/ccp.h>
/* #include <pppd/pathnames.h> ?, see below ... */
#ifndef _ROOT_PATH
#define _ROOT_PATH ""
#endif
#define _PATH_ETHOPT _ROOT_PATH "/etc/ppp/options."
char pppd_version[] = VERSION;
char pppd_version[] = PPPD_VERSION;
/* From sys-linux.c in pppd -- MUST FIX THIS! */
extern int new_style_driver;
@ -427,7 +427,7 @@ plugin_init(void)
add_options(Options);
info("PPPoE plugin from pppd %s", VERSION);
info("PPPoE plugin from pppd %s", PPPD_VERSION);
}
void pppoe_check_options(void)

View File

@ -10,7 +10,7 @@
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#include "config.h"
#endif
#include <stdarg.h>
@ -207,7 +207,7 @@ int main(int argc, char *argv[])
optarg, strerror(errno));
exit(1);
}
fprintf(debugFile, "pppoe-discovery from pppd %s\n", VERSION);
fprintf(debugFile, "pppoe-discovery from pppd %s\n", PPPD_VERSION);
break;
case 'I':
conn->ifName = xstrdup(optarg);
@ -269,5 +269,5 @@ usage(void)
" -U -- Use Host-Unique to allow multiple PPPoE sessions.\n"
" -W hexvalue -- Set the Host-Unique to the supplied hex string.\n"
" -h -- Print usage information.\n");
fprintf(stderr, "\npppoe-discovery from pppd " VERSION "\n");
fprintf(stderr, "\npppoe-discovery from pppd " PPPD_VERSION "\n");
}

View File

@ -18,7 +18,7 @@
#include <ctype.h>
#include <string.h>
#include "pppd/pppd.h" /* For error */
#include <pppd/pppd.h> /* For error */
/* How do we access raw Ethernet devices? */
#undef USE_LINUX_PACKET

View File

@ -4,10 +4,10 @@ pppd_plugindir = $(PPPD_PLUGIN_DIR)
noinst_HEADERS = \
l2tp_event.h
pppol2tp_la_CPPFLAGS = -I${top_srcdir}/include -I${top_srcdir}/pppd
pppol2tp_la_CPPFLAGS = -I${top_srcdir}/include -I${top_srcdir}
pppol2tp_la_LDFLAGS = -module -avoid-version
pppol2tp_la_SOURCES = pppol2tp.c
openl2tp_la_CPPFLAGS = -I${top_srcdir}/include -I${top_srcdir}/pppd
openl2tp_la_CPPFLAGS = -I${top_srcdir}/include -I${top_srcdir}
openl2tp_la_LDFLAGS = -module -avoid-version
openl2tp_la_SOURCES = openl2tp.c

View File

@ -19,20 +19,11 @@
/* pppd plugin for interfacing to openl2tpd */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include "pppd.h"
#include "pathnames.h"
#include "fsm.h"
#include "lcp.h"
#include "ccp.h"
#include "ipcp.h"
#include <sys/stat.h>
#include <net/if.h>
#include <sys/ioctl.h>
@ -43,6 +34,14 @@
#include <linux/version.h>
#include <linux/sockios.h>
#include <pppd/pppd.h>
#include <pppd/pathnames.h>
#include <pppd/fsm.h>
#include <pppd/lcp.h>
#include <pppd/ccp.h>
#include <pppd/ipcp.h>
#ifndef aligned_u64
/* should be defined in sys/types.h */
#define aligned_u64 unsigned long long __attribute__((aligned(8)))
@ -63,7 +62,7 @@ extern void (*pppol2tp_send_accm_hook)(int tunnel_id, int session_id,
uint32_t send_accm, uint32_t recv_accm);
extern void (*pppol2tp_ip_updown_hook)(int tunnel_id, int session_id, int up);
const char pppd_version[] = VERSION;
const char pppd_version[] = PPPD_VERSION;
static int openl2tp_fd = -1;

View File

@ -20,20 +20,10 @@
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include "pppd.h"
#include "pathnames.h"
#include "fsm.h"
#include "lcp.h"
#include "ccp.h"
#include "ipcp.h"
#include <sys/stat.h>
#include <net/if.h>
#include <sys/ioctl.h>
@ -42,10 +32,12 @@
#include <signal.h>
#include <linux/version.h>
#include <linux/sockios.h>
#ifndef aligned_u64
/* should be defined in sys/types.h */
#define aligned_u64 unsigned long long __attribute__((aligned(8)))
#endif
#include <linux/types.h>
#include <linux/if_ether.h>
#include <linux/ppp_defs.h>
@ -53,12 +45,20 @@
#include <linux/if_pppox.h>
#include <linux/if_pppol2tp.h>
#include <pppd/pppd.h>
#include <pppd/pathnames.h>
#include <pppd/fsm.h>
#include <pppd/lcp.h>
#include <pppd/ccp.h>
#include <pppd/ipcp.h>
/* should be added to system's socket.h... */
#ifndef SOL_PPPOL2TP
#define SOL_PPPOL2TP 273
#endif
const char pppd_version[] = VERSION;
const char pppd_version[] = PPPD_VERSION;
static int setdevname_pppol2tp(char **argv);

View File

@ -25,7 +25,7 @@ EXTRA_ETC = \
etc/realms \
etc/servers
RADIUS_CPPFLAGS = -I${top_srcdir}/include -I${top_srcdir}/pppd -DRC_LOG_FACILITY=LOG_DAEMON
RADIUS_CPPFLAGS = -I${top_srcdir}/include -I${top_srcdir} -DRC_LOG_FACILITY=LOG_DAEMON
RADIUS_LDFLAGS = -module -avoid-version $(LDFLAGS)
radius_la_CPPFLAGS = $(RADIUS_CPPFLAGS)

View File

@ -47,7 +47,7 @@
#include <time.h>
#include "magic.h"
#include <pppd/magic.h>
/* rlib/lock.c */
int do_lock_exclusive(int);

View File

@ -1,7 +1,7 @@
/*
* $Id: md5.c,v 1.1 2004/11/14 07:26:26 paulus Exp $
*/
#include "md5.h"
#include <pppd/md5.h>
void rc_md5_calc (unsigned char *output, unsigned char *input, unsigned int inlen)
{

View File

@ -17,21 +17,17 @@
static char const RCSID[] =
"$Id: radattr.c,v 1.2 2004/10/28 00:24:40 paulus Exp $";
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "pppd.h"
#include "radiusclient.h"
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pppd/pppd.h>
#include "radiusclient.h"
extern void (*radius_attributes_hook)(VALUE_PAIR *);
static void print_attributes(VALUE_PAIR *);
static void cleanup(void *opaque, int arg);
char pppd_version[] = VERSION;
char pppd_version[] = PPPD_VERSION;
/**********************************************************************
* %FUNCTION: plugin_init

View File

@ -26,22 +26,6 @@
static char const RCSID[] =
"$Id: radius.c,v 1.32 2008/05/26 09:18:08 paulus Exp $";
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "pppd.h"
#include "chap-new.h"
#ifdef PPP_WITH_CHAPMS
#include "chap_ms.h"
#ifdef PPP_WITH_MPPE
#include "mppe.h"
#include "md5.h"
#endif
#endif
#include "radiusclient.h"
#include "fsm.h"
#include "ipcp.h"
#include <syslog.h>
#include <sys/types.h>
#include <sys/time.h>
@ -49,6 +33,20 @@ static char const RCSID[] =
#include <netinet/in.h>
#include <stdlib.h>
#include <pppd/pppd.h>
#include <pppd/chap-new.h>
#ifdef PPP_WITH_CHAPMS
#include <pppd/chap_ms.h>
#ifdef PPP_WITH_MPPE
#include <pppd/mppe.h>
#include <pppd/md5.h>
#endif
#endif
#include <pppd/fsm.h>
#include <pppd/ipcp.h>
#include "radiusclient.h"
#define BUF_LEN 1024
#define MD5_HASH_SIZE 16
@ -140,7 +138,7 @@ void (*radius_pre_auth_hook)(char const *user,
static struct radius_state rstate;
char pppd_version[] = VERSION;
char pppd_version[] = PPPD_VERSION;
/**********************************************************************
* %FUNCTION: plugin_init

View File

@ -17,10 +17,10 @@
#ifndef RADIUSCLIENT_H
#define RADIUSCLIENT_H
#include <sys/types.h>
#include <stdio.h>
#include <time.h>
#include "pppd.h"
#include <sys/types.h>
#include <stdio.h>
#include <time.h>
#include <pppd/pppd.h>
#ifndef _UINT4_T
/* This works for all machines that Linux runs on... */

View File

@ -17,17 +17,14 @@
static char const RCSID[] =
"$Id: radrealms.c,v 1.2 2004/11/14 07:26:26 paulus Exp $";
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "pppd.h"
#include "radiusclient.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <pppd/pppd.h>
char pppd_version[] = VERSION;
#include "radiusclient.h"
char pppd_version[] = PPPD_VERSION;
char radrealms_config[MAXPATHLEN] = "/etc/radiusclient/realms";

View File

@ -34,16 +34,6 @@
*
***********************************************************************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "pppd.h"
#include "chap-new.h"
#include "chap_ms.h"
#include "fsm.h"
#include "ipcp.h"
#include "mppe.h"
#include <syslog.h>
#include <sys/types.h>
#include <sys/stat.h>
@ -56,6 +46,13 @@
#include <errno.h>
#include <ctype.h>
#include <pppd/pppd.h>
#include <pppd/chap-new.h>
#include <pppd/chap_ms.h>
#include <pppd/fsm.h>
#include <pppd/ipcp.h>
#include <pppd/mppe.h>
#define BUF_LEN 1024
#define NOT_AUTHENTICATED 0
@ -104,7 +101,7 @@ static int winbind_chap_verify(char *user, char *ourname, int id,
char *message, int message_space);
static int winbind_allowed_address(u_int32_t addr);
char pppd_version[] = VERSION;
char pppd_version[] = PPPD_VERSION;
/**********************************************************************
* %FUNCTION: plugin_init

View File

@ -57,5 +57,5 @@
/* Use included sha included with pppd */
#undef USE_SHA
/* Version number of package */
#undef VERSION
/* The pppd version */
#undef PPPD_VERSION