diff -Nur ppp-2.4.6.orig/chat/Makefile.linux ppp-2.4.6/chat/Makefile.linux
--- ppp-2.4.6.orig/chat/Makefile.linux	2014-01-02 05:42:08.000000000 +0100
+++ ppp-2.4.6/chat/Makefile.linux	2014-02-24 09:00:16.666577906 +0100
@@ -1,7 +1,7 @@
 #	$Id: Makefile.linux,v 1.15 2006/06/04 05:07:46 paulus Exp $
 
 DESTDIR = $(INSTROOT)@DESTDIR@
-BINDIR = $(DESTDIR)/sbin
+BINDIR = $(DESTDIR)/bin
 MANDIR = $(DESTDIR)/share/man/man8
 
 CDEF1=	-DTERMIOS			# Use the termios structure
@@ -10,7 +10,8 @@
 CDEF4=	-DFNDELAY=O_NDELAY		# Old name value
 CDEFS=	$(CDEF1) $(CDEF2) $(CDEF3) $(CDEF4)
 
-COPTS=	-O2 -g -pipe
+COPTS=	@CFLAGS@
+LDFLAGS=	@LDFLAGS@
 CFLAGS=	$(COPTS) $(CDEFS)
 
 INSTALL= install
@@ -21,7 +22,7 @@
 	$(CC) -o chat chat.o
 
 chat.o:	chat.c
-	$(CC) -c $(CFLAGS) -o chat.o chat.c
+	$(CC) -c $(CFLAGS) $(LDFLAGS) -o chat.o chat.c
 
 install: chat
 	mkdir -p $(BINDIR) $(MANDIR)
diff -Nur ppp-2.4.6.orig/configure ppp-2.4.6/configure
--- ppp-2.4.6.orig/configure	2014-01-02 05:42:08.000000000 +0100
+++ ppp-2.4.6/configure	2014-02-24 09:00:16.743242620 +0100
@@ -185,7 +185,10 @@
     rm -f $2
     if [ -f $1 ]; then
 	echo "  $2 <= $1"
-	sed -e "s,@DESTDIR@,$DESTDIR,g" -e "s,@SYSCONF@,$SYSCONF,g" $1 >$2
+	sed -e "s|@DESTDIR@|$DESTDIR|g" \
+	    -e "s|@SYSCONF@|$SYSCONF|g" \
+	    -e "s|@CFLAGS@|$CFLAGS|g" \
+	    -e "s|@LDFLAGS@|$LDFLAGS|g" $1 >$2
     fi
 }
 
diff -Nur ppp-2.4.6.orig/linux/Makefile.top ppp-2.4.6/linux/Makefile.top
--- ppp-2.4.6.orig/linux/Makefile.top	2014-01-02 05:42:08.000000000 +0100
+++ ppp-2.4.6/linux/Makefile.top	2014-02-24 09:00:16.743242620 +0100
@@ -1,7 +1,7 @@
 # PPP top-level Makefile for Linux.
 
 DESTDIR = $(INSTROOT)@DESTDIR@
-BINDIR = $(DESTDIR)/sbin
+BINDIR = $(DESTDIR)/bin
 INCDIR = $(DESTDIR)/include
 MANDIR = $(DESTDIR)/share/man
 ETCDIR = $(INSTROOT)@SYSCONF@/ppp
diff -Nur ppp-2.4.6.orig/pppd/Makefile.linux ppp-2.4.6/pppd/Makefile.linux
--- ppp-2.4.6.orig/pppd/Makefile.linux	2014-01-02 05:42:08.000000000 +0100
+++ ppp-2.4.6/pppd/Makefile.linux	2014-02-24 09:00:16.743242620 +0100
@@ -5,7 +5,7 @@
 
 # Default installation locations
 DESTDIR = $(INSTROOT)@DESTDIR@
-BINDIR = $(DESTDIR)/sbin
+BINDIR = $(DESTDIR)/bin
 MANDIR = $(DESTDIR)/share/man/man8
 INCDIR = $(DESTDIR)/include
 
@@ -32,7 +32,8 @@
 
 # CC = gcc
 #
-COPTS = -O2 -pipe -Wall -g
+COPTS = @CFLAGS@
+LDFLAGS = @LDFLAGS@
 LIBS =
 
 # Uncomment the next 2 lines to include support for Microsoft's
diff -Nur ppp-2.4.6.orig/pppd/plugins/Makefile.linux ppp-2.4.6/pppd/plugins/Makefile.linux
--- ppp-2.4.6.orig/pppd/plugins/Makefile.linux	2014-01-02 05:42:08.000000000 +0100
+++ ppp-2.4.6/pppd/plugins/Makefile.linux	2014-02-24 09:00:16.779908379 +0100
@@ -1,11 +1,11 @@
 #CC	= gcc
-COPTS	= -O2 -g
+COPTS	= @CFLAGS@
 CFLAGS	= $(COPTS) -I.. -I../../include -fPIC
-LDFLAGS	= -shared
+LDFLAGS	= @LDFLAGS@ -shared
 INSTALL	= install
 
 DESTDIR = $(INSTROOT)@DESTDIR@
-BINDIR = $(DESTDIR)/sbin
+BINDIR = $(DESTDIR)/bin
 MANDIR = $(DESTDIR)/share/man/man8
 LIBDIR = $(DESTDIR)/lib/pppd/$(VERSION)
 
diff -Nur ppp-2.4.6.orig/pppd/plugins/pppoatm/Makefile.linux ppp-2.4.6/pppd/plugins/pppoatm/Makefile.linux
--- ppp-2.4.6.orig/pppd/plugins/pppoatm/Makefile.linux	2014-01-02 05:42:08.000000000 +0100
+++ ppp-2.4.6/pppd/plugins/pppoatm/Makefile.linux	2014-02-24 09:00:16.809907637 +0100
@@ -1,7 +1,7 @@
 #CC	= gcc
-COPTS	= -O2 -g
+COPTS	= @CFLAGS@
 CFLAGS	= $(COPTS) -I../.. -I../../../include -fPIC
-LDFLAGS	= -shared
+LDFLAGS	= @LDFLAGS@
 INSTALL	= install
 
 #***********************************************************************
@@ -33,7 +33,7 @@
 all: $(PLUGIN)
 
 $(PLUGIN): $(PLUGIN_OBJS)
-	$(CC) $(CFLAGS) -o $@ -shared $^ $(LIBS)
+	$(CC) $(CFLAGS) -o $@ $(LDFLAGS) -shared $^ $(LIBS)
 
 install: all
 	$(INSTALL) -d -m 755 $(LIBDIR)
diff -Nur ppp-2.4.6.orig/pppd/plugins/pppol2tp/Makefile.linux ppp-2.4.6/pppd/plugins/pppol2tp/Makefile.linux
--- ppp-2.4.6.orig/pppd/plugins/pppol2tp/Makefile.linux	2014-01-02 05:42:08.000000000 +0100
+++ ppp-2.4.6/pppd/plugins/pppol2tp/Makefile.linux	2014-02-24 09:01:06.325349425 +0100
@@ -1,12 +1,12 @@
 #CC	= gcc
-COPTS	= -O2 -g
+COPTS	= @CFLAGS@
 CFLAGS	= $(COPTS) -I. -I../.. -I../../../include -fPIC
-LDFLAGS	= -shared
+LDFLAGS	= @LDFLAGS@
 INSTALL	= install
 
 #***********************************************************************
 
-DESTDIR = @DESTDIR@
+DESTDIR = $(INSTROOT)@DESTDIR@
 LIBDIR = $(DESTDIR)/lib/pppd/$(VERSION)
 
 VERSION = $(shell awk -F '"' '/VERSION/ { print $$2; }' ../../patchlevel.h)
@@ -16,7 +16,7 @@
 all: $(PLUGINS)
 
 %.so: %.o
-	$(CC) $(CFLAGS) -o $@ -shared $^ $(LIBS)
+	$(CC) $(CFLAGS) -o $@ $(LDFLAGS) -shared $^ $(LIBS)
 
 install: all
 	$(INSTALL) -d -m 755 $(LIBDIR)
diff -Nur ppp-2.4.6.orig/pppd/plugins/radius/Makefile.linux ppp-2.4.6/pppd/plugins/radius/Makefile.linux
--- ppp-2.4.6.orig/pppd/plugins/radius/Makefile.linux	2014-01-02 05:42:08.000000000 +0100
+++ ppp-2.4.6/pppd/plugins/radius/Makefile.linux	2014-02-24 09:00:16.809907637 +0100
@@ -12,7 +12,8 @@
 INSTALL	= install
 
 PLUGIN=radius.so radattr.so radrealms.so
-CFLAGS=-I. -I../.. -I../../../include -O2 -fPIC -DRC_LOG_FACILITY=LOG_DAEMON
+CFLAGS=@CFLAGS@ -I. -I../.. -I../../../include -O2 -fPIC -DRC_LOG_FACILITY=LOG_DAEMON
+LDFLAGS=@LDFLAGS@
 
 # Uncomment the next line to include support for Microsoft's
 # MS-CHAP authentication protocol.
@@ -43,13 +44,13 @@
 	$(INSTALL) -c -m 444 pppd-radattr.8 $(MANDIR)
 
 radius.so: radius.o libradiusclient.a
-	$(CC) -o radius.so -shared radius.o libradiusclient.a
+	$(CC) -o radius.so -shared $(LDFLAGS) radius.o libradiusclient.a
 
 radattr.so: radattr.o
-	$(CC) -o radattr.so -shared radattr.o
+	$(CC) -o radattr.so -shared $(LDFLAGS) radattr.o
 
 radrealms.so: radrealms.o
-	$(CC) -o radrealms.so -shared radrealms.o
+	$(CC) -o radrealms.so -shared $(LDFLAGS) radrealms.o
 
 CLIENTOBJS = avpair.o buildreq.o config.o dict.o ip_util.o \
 	clientid.o sendserver.o lock.o util.o md5.o
diff -Nur ppp-2.4.6.orig/pppd/plugins/rp-pppoe/Makefile.linux ppp-2.4.6/pppd/plugins/rp-pppoe/Makefile.linux
--- ppp-2.4.6.orig/pppd/plugins/rp-pppoe/Makefile.linux	2014-01-02 05:42:08.000000000 +0100
+++ ppp-2.4.6/pppd/plugins/rp-pppoe/Makefile.linux	2014-02-24 09:00:16.809907637 +0100
@@ -15,7 +15,7 @@
 #***********************************************************************
 
 DESTDIR = $(INSTROOT)@DESTDIR@
-BINDIR = $(DESTDIR)/sbin
+BINDIR = $(DESTDIR)/bin
 LIBDIR = $(DESTDIR)/lib/pppd/$(PPPDVERSION)
 
 PPPDVERSION = $(shell awk -F '"' '/VERSION/ { print $$2; }' ../../patchlevel.h)
@@ -25,12 +25,14 @@
 # Version is set ONLY IN THE MAKEFILE!  Don't delete this!
 RP_VERSION=3.8p
 
-COPTS=-O2 -g
+COPTS=@CFLAGS@
 CFLAGS=$(COPTS) -I../../../include '-DRP_VERSION="$(RP_VERSION)"'
+LDFLAGS=@LDFLAGS@
+
 all: rp-pppoe.so pppoe-discovery
 
 pppoe-discovery: pppoe-discovery.o debug.o
-	$(CC) -o pppoe-discovery pppoe-discovery.o debug.o
+	$(CC) -o pppoe-discovery $(LDFLAGS) pppoe-discovery.o debug.o
 
 pppoe-discovery.o: pppoe-discovery.c
 	$(CC) $(CFLAGS) -c -o pppoe-discovery.o pppoe-discovery.c
@@ -39,7 +41,7 @@
 	$(CC) $(CFLAGS) -c -o debug.o debug.c
 
 rp-pppoe.so: plugin.o discovery.o if.o common.o
-	$(CC) -o rp-pppoe.so -shared plugin.o discovery.o if.o common.o
+	$(CC) -o rp-pppoe.so -shared $(LDFLAGS) plugin.o discovery.o if.o common.o
 
 install: all
 	$(INSTALL) -d -m 755 $(LIBDIR)
diff -Nur ppp-2.4.6.orig/pppdump/Makefile.linux ppp-2.4.6/pppdump/Makefile.linux
--- ppp-2.4.6.orig/pppdump/Makefile.linux	2014-01-02 05:42:08.000000000 +0100
+++ ppp-2.4.6/pppdump/Makefile.linux	2014-02-24 09:00:16.809907637 +0100
@@ -1,8 +1,9 @@
 DESTDIR = $(INSTROOT)@DESTDIR@
-BINDIR = $(DESTDIR)/sbin
+BINDIR = $(DESTDIR)/bin
 MANDIR = $(DESTDIR)/share/man/man8
 
-CFLAGS= -O -I../include/net
+CFLAGS = @CFLAGS@ -I../include/net
+LDFLAGS = @LDFLAGS@
 OBJS = pppdump.o bsd-comp.o deflate.o zlib.o
 
 INSTALL= install
@@ -10,7 +11,7 @@
 all:	pppdump
 
 pppdump: $(OBJS)
-	$(CC) -o pppdump $(OBJS)
+	$(CC) $(LDFLAGS) -o pppdump $(OBJS)
 
 clean:
 	rm -f pppdump $(OBJS) *~
diff -Nur ppp-2.4.6.orig/pppstats/Makefile.linux ppp-2.4.6/pppstats/Makefile.linux
--- ppp-2.4.6.orig/pppstats/Makefile.linux	2014-01-02 05:42:08.000000000 +0100
+++ ppp-2.4.6/pppstats/Makefile.linux	2014-02-24 09:00:16.809907637 +0100
@@ -3,14 +3,15 @@
 # $Id: Makefile.linux,v 1.9 2006/06/04 05:07:46 paulus Exp $
 #
 DESTDIR = $(INSTROOT)@DESTDIR@
-BINDIR = $(DESTDIR)/sbin
+BINDIR = $(DESTDIR)/bin
 MANDIR = $(DESTDIR)/share/man/man8
 
 PPPSTATSRCS = pppstats.c
 PPPSTATOBJS = pppstats.o
 
 #CC = gcc
-COPTS = -O
+COPTS = @CFLAGS@
+LDFLAGS = @LDFLAGS@
 COMPILE_FLAGS = -I../include
 LIBS =
 
@@ -26,7 +27,7 @@
 	$(INSTALL) -c -m 444 pppstats.8 $(MANDIR)
 
 pppstats: $(PPPSTATSRCS)
-	$(CC) $(CFLAGS) -o pppstats pppstats.c $(LIBS)
+	$(CC) $(CFLAGS) $(LDFLAGS) -o pppstats pppstats.c $(LIBS)
 
 clean:
 	rm -f pppstats *~ #* core
Fix buffer overflow in rc_mksid()

rc_mksid converts the PID of pppd to hex to generate a pseudo-unique string.
If the process id is bigger than 65535 (FFFF), its hex representation will be
longer than 4 characters, resulting in a buffer overflow.
 
The bug can be exploited to cause a remote DoS.
--- ppp-2.4.7/pppd/plugins/radius/util.c
+++ ppp-2.4.7/pppd/plugins/radius/util.c
@@ -77,7 +77,7 @@ rc_mksid (void)
   static unsigned short int cnt = 0;
   sprintf (buf, "%08lX%04X%02hX",
 	   (unsigned long int) time (NULL),
-	   (unsigned int) getpid (),
+	   (unsigned int) getpid () & 0xFFFF,
 	   cnt & 0xFF);
   cnt++;
   return buf;
From 50a2997b256e0e0ef7a46fae133f56f60fce539c Mon Sep 17 00:00:00 2001
From: Lubomir Rintel <lkundrak@v3.sk>
Date: Mon, 9 Jan 2017 13:34:23 +0000
Subject: [PATCH] pppoe: include netinet/in.h before linux/in.h

This fixes builds with newer kernels. Basically, <netinet/in.h> needs to be
included before <linux/in.h> otherwise the earlier, unaware of the latter,
tries to redefine symbols and structures. Also, <linux/if_pppox.h> doesn't work
alone anymore, since it pulls the headers in the wrong order, so we better
include <netinet/in.h> early.
---
 pppd/plugins/rp-pppoe/pppoe.h | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/pppd/plugins/rp-pppoe/pppoe.h b/pppd/plugins/rp-pppoe/pppoe.h
index 9ab2eee3..c4aaa6e6 100644
--- a/pppd/plugins/rp-pppoe/pppoe.h
+++ b/pppd/plugins/rp-pppoe/pppoe.h
@@ -47,6 +47,10 @@
 #include <sys/socket.h>
 #endif
 
+/* This has to be included before Linux 4.8's linux/in.h
+ * gets dragged in. */
+#include <netinet/in.h>
+
 /* Ugly header files on some Linux boxes... */
 #if defined(HAVE_LINUX_IF_H)
 #include <linux/if.h>
@@ -84,8 +88,6 @@ typedef unsigned long UINT32_t;
 #include <linux/if_ether.h>
 #endif
 
-#include <netinet/in.h>
-
 #ifdef HAVE_NETINET_IF_ETHER_H
 #include <sys/types.h>
 
@@ -98,7 +100,6 @@ typedef unsigned long UINT32_t;
 #endif
 
 
-
 /* Ethernet frame types according to RFC 2516 */
 #define ETH_PPPOE_DISCOVERY 0x8863
 #define ETH_PPPOE_SESSION   0x8864
From 3c7b86229f7bd2600d74db14b1fe5b3896be3875 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jaroslav=20=C5=A0karvada?= <jskarvad@redhat.com>
Date: Fri, 6 Apr 2018 14:27:18 +0200
Subject: [PATCH] pppd: Use openssl for the DES instead of the libcrypt / glibc
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

It seems the latest glibc (in Fedora glibc-2.27.9000-12.fc29) dropped
libcrypt.  The libxcrypt standalone package can be used instead, but
it dropped the old setkey/encrypt API which ppp uses for DES.  There
is support for using openssl in pppcrypt.c, but it contains typos
preventing it from compiling and seems to be written for an ancient
openssl version.

This updates the code to use current openssl.

[paulus@ozlabs.org - wrote the commit description, fixed comment in
 Makefile.linux.]

Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
---
 pppd/Makefile.linux |  7 ++++---
 pppd/pppcrypt.c     | 18 +++++++++---------
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/pppd/Makefile.linux b/pppd/Makefile.linux
index 36d2b036..8d5ce99d 100644
--- a/pppd/Makefile.linux
+++ b/pppd/Makefile.linux
@@ -35,10 +35,10 @@ endif
 COPTS = -O2 -pipe -Wall -g
 LIBS =
 
-# Uncomment the next 2 lines to include support for Microsoft's
+# Uncomment the next line to include support for Microsoft's
 # MS-CHAP authentication protocol.  Also, edit plugins/radius/Makefile.linux.
 CHAPMS=y
-USE_CRYPT=y
+#USE_CRYPT=y
 # Don't use MSLANMAN unless you really know what you're doing.
 #MSLANMAN=y
 # Uncomment the next line to include support for MPPE.  CHAPMS (above) must
@@ -137,7 +137,8 @@ endif
 
 ifdef NEEDDES
 ifndef USE_CRYPT
-LIBS     += -ldes $(LIBS)
+CFLAGS   += -I/usr/include/openssl
+LIBS     += -lcrypto
 else
 CFLAGS   += -DUSE_CRYPT=1
 endif
diff --git a/pppd/pppcrypt.c b/pppd/pppcrypt.c
index 8b85b132..6b35375e 100644
--- a/pppd/pppcrypt.c
+++ b/pppd/pppcrypt.c
@@ -64,7 +64,7 @@ u_char *des_key;	/* OUT 64 bit DES key with parity bits added */
 	des_key[7] = Get7Bits(key, 49);
 
 #ifndef USE_CRYPT
-	des_set_odd_parity((des_cblock *)des_key);
+	DES_set_odd_parity((DES_cblock *)des_key);
 #endif
 }
 
@@ -158,25 +158,25 @@ u_char *clear;	/* OUT 8 octets */
 }
 
 #else /* USE_CRYPT */
-static des_key_schedule	key_schedule;
+static DES_key_schedule	key_schedule;
 
 bool
 DesSetkey(key)
 u_char *key;
 {
-	des_cblock des_key;
+	DES_cblock des_key;
 	MakeKey(key, des_key);
-	des_set_key(&des_key, key_schedule);
+	DES_set_key(&des_key, &key_schedule);
 	return (1);
 }
 
 bool
-DesEncrypt(clear, key, cipher)
+DesEncrypt(clear, cipher)
 u_char *clear;	/* IN  8 octets */
 u_char *cipher;	/* OUT 8 octets */
 {
-	des_ecb_encrypt((des_cblock *)clear, (des_cblock *)cipher,
-	    key_schedule, 1);
+	DES_ecb_encrypt((DES_cblock *)clear, (DES_cblock *)cipher,
+	    &key_schedule, 1);
 	return (1);
 }
 
@@ -185,8 +185,8 @@ DesDecrypt(cipher, clear)
 u_char *cipher;	/* IN  8 octets */
 u_char *clear;	/* OUT 8 octets */
 {
-	des_ecb_encrypt((des_cblock *)cipher, (des_cblock *)clear,
-	    key_schedule, 0);
+	DES_ecb_encrypt((DES_cblock *)cipher, (DES_cblock *)clear,
+	    &key_schedule, 0);
 	return (1);
 }
 

