glibc-2 patches

2.1.x patches
This commit is contained in:
Michael Hipp 1997-05-28 10:07:40 +00:00
parent e720a4aace
commit 9659542cec
8 changed files with 237 additions and 162 deletions

View File

@ -3,7 +3,6 @@
# $Id$
#
HAVE_LIBBSD := @HAVE_LIBBSD@
HAVE_LIBDES := @HAVE_LIBDES@
HAVE_LIBCRYPT := @HAVE_LIBCRYPT@
HAVE_SHADOW_H := @HAVE_SHADOW_H@
@ -35,7 +34,6 @@ MANPAGES = pppd.8
PPPDOBJS = main.o magic.o fsm.o lcp.o ipcp.o upap.o chap.o md5.o ccp.o \
auth.o options.o sys-linux.o cbcp.o ipxcp.o
ifeq ($(HAVE_LIBBSD),1)
all: ipppd
uninstall:
@ -47,16 +45,6 @@ install: ipppd
$(INSTALL_SBIN) ipppd $(SBINDIR)/ipppd
$(INSTALL_DATA) ipppd.8 $(MANDIR)/man8/ipppd.8
else
all:
@echo -n "\n\nLibrary libbsd not found, ipppd NOT built\n\n"
install:
@echo -n "\n\nLibrary libbsd not found, ipppd NOT installed\n\n"
endif
#
# include dependancies if present and backup if as a header file
ifeq (.depend,$(wildcard .depend))
include .depend
HEADERS := $(HEADERS) .depend
@ -67,7 +55,12 @@ COMPILE_FLAGS =
COPTS =
CFLAGS = -O2 -fomit-frame-pointer -m486 -Wall
VER = 2.2.0
LIBS = -lbsd
# it's a hack
ifeq ($(HAVE_LIBCRYPT),1)
LIBS = -lcrypt -lutil
endif
SOURCE = RELNOTES configure *.in $(PPPDSRCS) $(HEADERS) $(MANPAGES)

View File

@ -19,7 +19,7 @@ removed checking of ~/.ppprc file ('options from user' feature)
------------------------------------------------------------
I added a few new options:
CHANGELOG:
- 'useifip' will get (if not set to 0.0.0.0) the IP address
for the negotiation from the attached network-interface.
(also: ipppd will try to negotiate 'pointopoint' IP as remote IP)
@ -52,6 +52,8 @@ I added a few new options:
- added 'pidfile <own pidfilename>' option ..
- added 'set_userip' .. you may define valid IPs in /etc/ppp/useriptab
(it's a patch from: Meno Abels <Meno.Abels@Technical.Adviser.com>)
- added glibc-2 patches from: Andreas Jaeger <aj@arthur.rhein-neckar.de>
- added 2.1.X patches by Miquel van Smoorenburg <miquels@cistron.nl>
The ipppd can handle multiple devices. This is necessary to
link several connections together to one bundle.

View File

@ -52,6 +52,10 @@ char auth_rcsid[] = "$Id$";
#include <netinet/in.h>
#include <arpa/inet.h>
#if defined __GLIBC__ && __GLIBC__ >= 2
# include <crypt.h>
#endif
#include "config.h"
#ifdef HAVE_SHADOW_H
#include <shadow.h>
@ -97,8 +101,8 @@ void check_access __P((FILE *, char *));
static void network_phase __P((int));
static void callback_phase __P((int));
static int link_lastlink(int);
static int login __P((char *, char *, char **, int *,int));
static void logout __P((int));
static int check_login __P((char *, char *, char **, int *,int));
static void do_logout __P((int));
static int null_login __P((int));
static int get_upap_passwd __P((void));
static int have_upap_secret __P((void));
@ -128,7 +132,7 @@ void link_terminated(int linkunit)
if (lns[linkunit].phase == PHASE_DEAD)
return;
if (lns[linkunit].logged_in) {
logout(linkunit);
do_logout(linkunit);
lns[linkunit].logged_in = 0;
}
lns[linkunit].phase = PHASE_DEAD;
@ -583,7 +587,7 @@ int check_passwd(int linkunit,char *auser,int userlen,char *apasswd,int passwdle
}
if (uselogin && ret == UPAP_AUTHACK) {
ret = login(user, passwd, msg, msglen,linkunit);
ret = check_login(user, passwd, msg, msglen,linkunit);
if (ret == UPAP_AUTHNAK) {
syslog(LOG_WARNING, "PAP login failure for %s", user);
}
@ -622,7 +626,7 @@ int check_passwd(int linkunit,char *auser,int userlen,char *apasswd,int passwdle
/*
* login - Check the user name and password against the system
* check_login - Check the user name and password against the system
* password database, and login the user if OK.
*
* returns:
@ -630,7 +634,7 @@ int check_passwd(int linkunit,char *auser,int userlen,char *apasswd,int passwdle
* UPAP_AUTHACK: Login succeeded.
* In either case, msg points to an appropriate message.
*/
static int login(char *user,char *passwd,char **msg,int *msglen,int unit)
static int check_login(char *user,char *passwd,char **msg,int *msglen,int unit)
{
struct passwd *pw;
char *epasswd;
@ -679,7 +683,7 @@ static int login(char *user,char *passwd,char **msg,int *msglen,int unit)
tty = lns[unit].devnam;
if (strncmp(tty, "/dev/", 5) == 0)
tty += 5;
logwtmp(unit, tty, user, ""); /* Add wtmp login entry */
logwtmputmp(unit, tty, user, ""); /* Add wtmp login entry */
return (UPAP_AUTHACK);
}
@ -687,14 +691,14 @@ static int login(char *user,char *passwd,char **msg,int *msglen,int unit)
/*
* logout - Logout the user.
*/
static void logout(int unit)
static void do_logout(int unit)
{
char *tty;
tty = lns[unit].devnam;
if (strncmp(tty, "/dev/", 5) == 0)
tty += 5;
logwtmp(unit, tty, "", ""); /* Wipe out wtmp logout entry */
logwtmputmp(unit, tty, "", ""); /* Wipe out wtmp logout entry */
}

View File

@ -32,11 +32,20 @@
#include <sys/param.h> /* for MAXPATHLEN and BSD4_4, if defined */
#include <sys/types.h> /* for u_int32_t, if defined */
#include <sys/bitypes.h>
#include <linux/ppp_defs.h>
#include <linux/isdn_ppp.h>
#if defined __GLIBC__ && __GLIBC__ >= 2
# include <net/ppp_defs.h>
# include <linux/isdn_ppp.h>
#else
# include <linux/ppp_defs.h>
# include <linux/isdn_ppp.h>
#endif
#include <stdio.h>
#include <net/if.h>
#if defined __GLIBC__ && __GLIBC__ >= 2
# include <utmp.h>
#endif
#define NUM_PPP 16 /* 16 PPP interface supported (per process) */
struct wordlist {
@ -284,7 +293,7 @@ int cifproxyarp (int unit, u_int32_t his_adr);
int sipxfaddr (int unit, u_int32_t network, unsigned char * node );
int cipxfaddr (int linkunit);
int ppp_available(void);
int logwtmp (int unit,char *line, char *name, char *host);
int logwtmputmp (int unit,char *line, char *name, char *host);
int lock (char *dev);
void unlock(void);
void setifip(int);

View File

@ -48,8 +48,13 @@ char lcp_rcsid[] = "$Id$";
#include "ipxcp.h"
#ifdef __linux__ /* Needs ppp ioctls */
#include <net/if.h>
#include <linux/if_ppp.h>
#if defined __GLIBC__ && __GLIBC__ >= 2
# include <net/if.h>
# include <net/if_ppp.h>
#else
# include <net/if.h>
# include <linux/if_ppp.h>
#endif
#endif
u_char our_discr_class = 4; /* 0x2; */

View File

@ -243,9 +243,27 @@ void main(int argc,char **argv)
* Detach ourselves from the terminal, if required,
* and identify who is running us.
*/
if (!nodetach && daemon(0, 0) < 0) {
perror("Couldn't detach from controlling terminal");
exit(1);
if (!nodetach) {
int a,f;
f = fork();
if(f < 0) {
perror("Couldn't detach from controlling terminal");
exit(1);
}
if(f)
exit(0);
setsid();
chdir("/");
a = open("/dev/null",O_RDWR);
if(a < 0) {
perror("Couldn't open /dev/null");
exit(1);
}
dup2(a,0);
dup2(a,1);
dup2(a,2);
close(a);
}
pid = getpid();

View File

@ -1553,6 +1553,11 @@ static int setnetmask(int slot,char **argv)
{
u_int32_t mask;
if (strcmp(*argv, "255.255.255.255") == 0) {
netmask = 0xffffffff;
return 1;
}
if ((mask = inet_addr(*argv)) == -1 || (netmask & ~mask) != 0) {
fprintf(stderr, "Invalid netmask %s\n", *argv);
return 0;

View File

@ -34,6 +34,7 @@ char sys_rcsid[] = "$Id$";
#include <sys/errno.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <sys/utsname.h>
#include <stdio.h>
#include <stdlib.h>
@ -50,11 +51,17 @@ char sys_rcsid[] = "$Id$";
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <linux/ppp_defs.h>
#include <linux/if_ppp.h>
#include <net/if_arp.h>
#include <net/route.h>
#include <linux/if_ether.h>
#if defined __GLIBC__ && __GLIBC__ >= 2
# include <net/ppp_defs.h>
# include <net/if_ppp.h>
# include <net/ethernet.h>
#else
# include <linux/ppp_defs.h>
# include <linux/if_ppp.h>
# include <linux/if_ether.h>
#endif
#include "fsm.h"
#include "ipppd.h"
@ -68,9 +75,12 @@ static int has_default_route = 0;
static int driver_version = 0;
static int driver_modification = 0;
static int driver_patch = 0;
static int devroute = -1; /* 0 for Linux >= 2.1.x */
static int last_net_mask = 0; /* Ugly! */
int get_ether_addr (u_int32_t ipaddr, struct sockaddr *hwaddr, char *name);
static void decode_version (char *buf, int *version,
int *modification, int *patch);
int sockfd; /* socket for doing interface ioctls */
static char *lock_file;
@ -160,6 +170,9 @@ static void set_flags (int flags,int tu)
*/
void sys_init(void)
{
struct utsname uts;
int maj, min, pat;
openlog("ipppd", LOG_PID | LOG_NDELAY, LOG_PPP);
setlogmask(LOG_UPTO(LOG_INFO));
if (debug)
@ -171,6 +184,15 @@ void sys_init(void)
syslog(LOG_ERR, "Couldn't create IP socket: %m");
die(1);
}
if (devroute < 0) {
uname(&uts);
maj = min = pat = 0;
decode_version(uts.release, &maj, &min, &pat);
if (maj >= 2 && min >= 1) /* Linux >= 2.1.x */
devroute = 0;
else
devroute = 1;
}
}
/*
@ -532,66 +554,69 @@ int sifaddr (int unit, int our_adr, int his_adr, int net_mask)
* Set our IP address
*/
((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = our_adr;
if (ioctl(sockfd, SIOCSIFADDR, (caddr_t) &ifr) < 0)
{
if (errno != EEXIST)
{
syslog (LOG_ERR, "ioctl(SIOCAIFADDR): %m");
}
else
{
syslog (LOG_WARNING, "ioctl(SIOCAIFADDR): Address already exists");
}
return (0);
}
if (ioctl(sockfd, SIOCSIFADDR, (caddr_t) &ifr) < 0) {
if (errno != EEXIST) {
syslog (LOG_ERR, "ioctl(SIOCAIFADDR): %m");
} else {
syslog (LOG_WARNING, "ioctl(SIOCAIFADDR): Address already exists");
}
return (0);
}
/*
* Set the gateway address
*/
((struct sockaddr_in *) &ifr.ifr_dstaddr)->sin_addr.s_addr = his_adr;
if (ioctl(sockfd, SIOCSIFDSTADDR, (caddr_t) &ifr) < 0)
{
syslog (LOG_ERR, "ioctl(SIOCSIFDSTADDR): %m");
return (0);
}
if (ioctl(sockfd, SIOCSIFDSTADDR, (caddr_t) &ifr) < 0) {
syslog (LOG_ERR, "ioctl(SIOCSIFDSTADDR): %m");
return (0);
}
#if 0
/*
* Set the netmask
*/
if (net_mask != 0)
{
((struct sockaddr_in *) &ifr.ifr_netmask)->sin_addr.s_addr = net_mask;
if (ioctl(sockfd, SIOCSIFNETMASK, (caddr_t) &ifr) < 0)
{
syslog (LOG_ERR, "ioctl(SIOCSIFNETMASK): %m");
return (0);
}
}
#endif
if (net_mask != 0) {
((struct sockaddr_in *) &ifr.ifr_netmask)->sin_addr.s_addr = net_mask;
if (ioctl(sockfd, SIOCSIFNETMASK, (caddr_t) &ifr) < 0) {
syslog (LOG_ERR, "ioctl(SIOCSIFNETMASK): %m");
return (0);
}
}
last_net_mask = net_mask;
/*
* Add the device route
*/
if (hostroute)
{
SET_SA_FAMILY (rt.rt_dst, AF_INET);
SET_SA_FAMILY (rt.rt_gateway, AF_INET);
rt.rt_dev = lns[unit].ifname; /* MJC */
if (!devroute)
return 1;
((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = 0L;
((struct sockaddr_in *) &rt.rt_dst)->sin_addr.s_addr = his_adr;
rt.rt_flags = RTF_UP | RTF_HOST;
if (hostroute) {
SET_SA_FAMILY (rt.rt_dst, AF_INET);
SET_SA_FAMILY (rt.rt_gateway, AF_INET);
SET_SA_FAMILY (rt.rt_genmask, AF_INET);
rt.rt_dev = lns[unit].ifname; /* MJC */
if (ioctl(sockfd, SIOCADDRT, &rt) < 0)
{
syslog (LOG_ERR, "ioctl(SIOCADDRT) device route: %m");
if (net_mask)
his_adr &= net_mask;
((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = 0L;
((struct sockaddr_in *) &rt.rt_dst)->sin_addr.s_addr = his_adr;
((struct sockaddr_in *) &rt.rt_genmask)->sin_addr.s_addr = net_mask;
rt.rt_flags = RTF_UP;
if (net_mask == 0)
rt.rt_flags |= RTF_HOST;
if (ioctl(sockfd, SIOCADDRT, &rt) < 0) {
syslog (LOG_ERR, "ioctl(SIOCADDRT) device route (%s/%s/%08x): %m",
rt.rt_dev,
inet_ntoa(((struct sockaddr_in *)&rt.rt_dst)->sin_addr),
ntohl(net_mask));
return (0);
}
}
}
return 1;
}
}
return 1;
}
/*
* cifaddr - Clear the interface IP addresses, and delete routes
@ -599,32 +624,40 @@ int sifaddr (int unit, int our_adr, int his_adr, int net_mask)
*/
int cifaddr (int unit, int our_adr, int his_adr)
{
{
struct rtentry rt;
/*
* Delete the route through the device
*/
if (!devroute)
return 1;
memset (&rt, '\0', sizeof (rt));
SET_SA_FAMILY (rt.rt_dst, AF_INET);
SET_SA_FAMILY (rt.rt_gateway, AF_INET);
SET_SA_FAMILY (rt.rt_genmask, AF_INET);
rt.rt_dev = lns[unit].ifname; /* MJC */
if (last_net_mask)
his_adr &= last_net_mask;
((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = 0;
((struct sockaddr_in *) &rt.rt_dst)->sin_addr.s_addr = his_adr;
rt.rt_flags = RTF_UP | RTF_HOST;
((struct sockaddr_in *) &rt.rt_genmask)->sin_addr.s_addr = last_net_mask;
rt.rt_flags = RTF_UP;
if (last_net_mask == 0)
rt.rt_flags |= RTF_HOST;
if (ioctl(sockfd, SIOCDELRT, &rt) < 0 && errno != ESRCH)
{
if (still_ppp(unit))
{
syslog (LOG_ERR, "ioctl(SIOCDELRT) device route: %m");
return (0);
}
}
return 1;
}
if (ioctl(sockfd, SIOCDELRT, &rt) < 0 && errno != ESRCH) {
if (still_ppp(unit)) {
syslog (LOG_ERR, "ioctl(SIOCDELRT) device route: %m");
return (0);
}
}
return 1;
}
/*
* path_to_proc - determine the path to the proc file system data
@ -679,13 +712,12 @@ static char *path_to_proc (void)
*/
static void close_route_table (void)
{
if (route_fd != (FILE *) 0)
{
fclose (route_fd);
route_fd = (FILE *) 0;
}
}
{
if (route_fd != (FILE *) 0) {
fclose (route_fd);
route_fd = (FILE *) 0;
}
}
/*
* open_route_table - open the interface to the route table
@ -1023,6 +1055,11 @@ int get_ether_addr (u_int32_t ipaddr, struct sockaddr *hwaddr, char *name)
* any non-point-to-point interfaces which might appear to be on the same
* network as `addr'. If we find any, we OR in their netmask to the
* user-specified netmask.
*
* If our address happens to be in the same network/subnet as one of
* the other interfaces, set the netmask to 255.255.255.255
*
* FIXME: This stuff is OLD and should be rewritten (we now use CIDR remember).
*/
static u_int32_t local_GetMask (u_int32_t addr, struct ifreq *ifs, int ifs_len)
@ -1031,80 +1068,74 @@ static u_int32_t local_GetMask (u_int32_t addr, struct ifreq *ifs, int ifs_len)
struct ifreq *ifr, *ifend, ifreq;
struct ifconf ifc;
addr = ntohl(addr);
ina = ntohl(addr);
if (IN_CLASSA(addr)) /* determine network mask for address class */
{
nmask = IN_CLASSA_NET;
}
else
{
if (IN_CLASSB(addr))
{
nmask = IN_CLASSB_NET;
}
else
{
nmask = IN_CLASSC_NET;
}
}
/* class D nets are disallowed by bad_ip_adrs */
mask = netmask | htonl(nmask);
if (IN_CLASSA(ina)) { /* determine network mask for address class */
nmask = IN_CLASSA_NET;
} else {
if (IN_CLASSB(ina)) {
nmask = IN_CLASSB_NET;
} else {
nmask = IN_CLASSC_NET;
}
}
nmask = htonl(nmask);
if (ifs == (void *) 0)
{
return mask;
}
/* class D nets are disallowed by bad_ip_adrs */
mask = netmask | nmask;
if (ifs == (void *) 0) {
return mask;
}
/*
* Scan through the system's network interfaces.
*/
ifc.ifc_len = ifs_len;
ifc.ifc_req = ifs;
if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0)
{
syslog(LOG_WARNING, "ioctl(SIOCGIFCONF): %m");
return mask;
}
ifc.ifc_len = ifs_len;
ifc.ifc_req = ifs;
if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
syslog(LOG_WARNING, "ioctl(SIOCGIFCONF): %m");
return mask;
}
ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
for (ifr = ifc.ifc_req; ifr < ifend; ifr++)
{
/*
* Check the interface's internet address.
*/
if (ifr->ifr_addr.sa_family != AF_INET)
{
continue;
}
ina = ((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr.s_addr;
if (((ntohl(ina) ^ addr) & nmask) != 0)
{
continue;
}
ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
for (ifr = ifc.ifc_req; ifr < ifend; ifr++) {
if (ifr->ifr_addr.sa_family != AF_INET) {
continue;
}
/*
* Check that the interface is up, and not point-to-point nor loopback.
*/
strncpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name));
if (ioctl(sockfd, SIOCGIFFLAGS, &ifreq) < 0)
{
continue;
}
strncpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name));
if (ioctl(sockfd, SIOCGIFFLAGS, &ifreq) < 0)
continue;
if (((ifreq.ifr_flags ^ FLAGS_GOOD) & FLAGS_MASK) != 0)
{
continue;
}
if (((ifreq.ifr_flags ^ FLAGS_GOOD) & FLAGS_MASK) != 0)
continue;
/*
* See if our IP address is part of this subnet.
*/
ina = ((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr.s_addr;
if (ina == addr)
continue;
if ((ina & nmask) == (addr & nmask)) {
mask = 0xFFFFFFFF;
break;
}
/*
* Check the interface's internet address.
*/
if (((ina ^ addr) & nmask) != 0)
continue;
/*
* Get its netmask and OR it into our mask.
*/
if (ioctl(sockfd, SIOCGIFNETMASK, &ifreq) < 0)
{
continue;
}
mask |= ((struct sockaddr_in *)&ifreq.ifr_addr)->sin_addr.s_addr;
break;
}
if (ioctl(sockfd, SIOCGIFNETMASK, &ifreq) < 0)
continue;
mask |= ((struct sockaddr_in *)&ifreq.ifr_addr)->sin_addr.s_addr;
break;
}
return mask;
}
@ -1113,6 +1144,12 @@ u_int32_t GetMask (u_int32_t addr)
int ifs_len;
u_int32_t answer;
void *base_addr;
/*
* If user set netmask assume he knows what he's doing.
*/
if (netmask) return netmask;
/*
* Allocate memory to hold the request.
*/
@ -1216,11 +1253,10 @@ int ppp_available(void)
return 1;
}
/*
* Update the wtmp file with the appropriate user name and tty device.
*/
int logwtmp (int unit,char *line, char *name, char *host)
int logwtmputmp (int unit,char *line, char *name, char *host)
{
int wtmp;
struct utmp ut, *utp;
@ -1285,6 +1321,9 @@ int logwtmp (int unit,char *line, char *name, char *host)
/*
* Update the wtmp file.
*/
#if (defined __GLIBC__ && __GLIBC__ >= 2)
updwtmp (_PATH_WTMP, &ut);
#else
wtmp = open(_PATH_WTMP, O_APPEND|O_WRONLY);
if (wtmp >= 0)
{
@ -1296,10 +1335,10 @@ int logwtmp (int unit,char *line, char *name, char *host)
flock(wtmp, LOCK_UN);
}
#endif
return 0;
}
/*
* Code for locking/unlocking the serial device.
* This code is derived from chat.c.