diff options
author | brian <brian@FreeBSD.org> | 1997-05-26 00:44:10 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 1997-05-26 00:44:10 +0000 |
commit | 12b254e3164dbf2f773ea486a20102fd4183173c (patch) | |
tree | f69d2306d93e872c8408a5c5f9931535f7ecf7b1 | |
parent | 8089164d6fdd97167753a3a56afb162c5a6f699c (diff) | |
download | FreeBSD-src-12b254e3164dbf2f773ea486a20102fd4183173c.zip FreeBSD-src-12b254e3164dbf2f773ea486a20102fd4183173c.tar.gz |
De-couple ppp from libalias. If libalias isn't there, the
alias commands simply won't work. Only root may specify the
location of the alias lib (otherwise, it's hard-coded).
Make logprintf silently fail if LogOpen hasn't been called.
Suggested by: eivind
-rw-r--r-- | usr.sbin/ppp/Makefile | 12 | ||||
-rw-r--r-- | usr.sbin/ppp/alias_cmd.c | 54 | ||||
-rw-r--r-- | usr.sbin/ppp/async.c | 3 | ||||
-rw-r--r-- | usr.sbin/ppp/auth.c | 3 | ||||
-rw-r--r-- | usr.sbin/ppp/ccp.c | 3 | ||||
-rw-r--r-- | usr.sbin/ppp/chap.c | 3 | ||||
-rw-r--r-- | usr.sbin/ppp/chat.c | 7 | ||||
-rw-r--r-- | usr.sbin/ppp/command.c | 41 | ||||
-rw-r--r-- | usr.sbin/ppp/hdlc.c | 3 | ||||
-rw-r--r-- | usr.sbin/ppp/ip.c | 11 | ||||
-rw-r--r-- | usr.sbin/ppp/ipcp.c | 6 | ||||
-rw-r--r-- | usr.sbin/ppp/lcp.c | 3 | ||||
-rw-r--r-- | usr.sbin/ppp/loadalias.c | 88 | ||||
-rw-r--r-- | usr.sbin/ppp/loadalias.h | 18 | ||||
-rw-r--r-- | usr.sbin/ppp/log.c | 10 | ||||
-rw-r--r-- | usr.sbin/ppp/lqr.c | 3 | ||||
-rw-r--r-- | usr.sbin/ppp/main.c | 14 | ||||
-rw-r--r-- | usr.sbin/ppp/modem.c | 3 | ||||
-rw-r--r-- | usr.sbin/ppp/nat_cmd.c | 54 | ||||
-rw-r--r-- | usr.sbin/ppp/os.c | 3 | ||||
-rw-r--r-- | usr.sbin/ppp/pap.c | 3 | ||||
-rw-r--r-- | usr.sbin/ppp/systems.c | 9 | ||||
-rw-r--r-- | usr.sbin/ppp/systems.h | 3 | ||||
-rw-r--r-- | usr.sbin/ppp/vars.c | 5 | ||||
-rw-r--r-- | usr.sbin/ppp/vars.h | 16 |
25 files changed, 259 insertions, 119 deletions
diff --git a/usr.sbin/ppp/Makefile b/usr.sbin/ppp/Makefile index 94e0c7f..b11a511 100644 --- a/usr.sbin/ppp/Makefile +++ b/usr.sbin/ppp/Makefile @@ -1,14 +1,14 @@ -# $Id: Makefile,v 1.18 1997/03/31 22:50:59 brian Exp $ +# $Id: Makefile,v 1.19 1997/05/23 04:53:49 brian Exp $ PROG= ppp SRCS= alias_cmd.c arp.c async.c auth.c ccp.c chap.c chat.c command.c \ - filter.c fsm.c hdlc.c ip.c ipcp.c lcp.c log.c lqr.c main.c mbuf.c \ - modem.c os.c pap.c passwdauth.c pred.c route.c sig.c slcompress.c \ - systems.c timer.c vars.c vjcomp.c + filter.c fsm.c hdlc.c ip.c ipcp.c lcp.c loadalias.c log.c lqr.c \ + main.c mbuf.c modem.c os.c pap.c passwdauth.c pred.c route.c sig.c \ + slcompress.c systems.c timer.c vars.c vjcomp.c #CFLAGS+= -DHAVE_SHELL_CMD_WITH_ANY_MODE CFLAGS += -Wall -DMSEXT -DPASSWDAUTH -LDADD += -lmd -lcrypt -lutil -lalias -DPADD += ${LIBMD} ${LIBCRYPT} ${LIBUTIL} ${LIBALIAS} +LDADD += -lmd -lcrypt -lutil +DPADD += ${LIBMD} ${LIBCRYPT} ${LIBUTIL} MAN8= ppp.8 BINMODE=4555 BINOWN= root diff --git a/usr.sbin/ppp/alias_cmd.c b/usr.sbin/ppp/alias_cmd.c index 1d99415..0603c7a 100644 --- a/usr.sbin/ppp/alias_cmd.c +++ b/usr.sbin/ppp/alias_cmd.c @@ -8,9 +8,10 @@ #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> -#include <alias.h> +#include "defs.h" #include "command.h" +#include "loadalias.h" #include "vars.h" static int @@ -29,8 +30,9 @@ AliasRedirectPort (struct cmdtab *list, char **argv, void *param) { - if (argc == 3) - { + if (!(mode & MODE_ALIAS)) + printf("alias not enabled\n"); + else if (argc == 3) { char proto_constant; char *proto; u_short local_port; @@ -41,32 +43,25 @@ AliasRedirectPort (struct cmdtab *list, struct alias_link *link; proto = argv[0]; - if (strcmp(proto, "tcp") == 0) - { + if (strcmp(proto, "tcp") == 0) { proto_constant = IPPROTO_TCP; - } - else if (strcmp(proto, "udp") == 0) - { + } else if (strcmp(proto, "udp") == 0) { proto_constant = IPPROTO_UDP; - } - else - { + } else { printf("port redirect: protocol must be tcp or udp\n"); printf("Usage: alias %s %s\n", list->name, list->syntax); return 1; } error = StrToAddrAndPort(argv[1], &local_addr, &local_port, proto); - if (error) - { + if (error) { printf("port redirect: error reading local addr:port\n"); printf("Usage: alias %s %s\n", list->name, list->syntax); return 1; } error = StrToPort(argv[2], &alias_port, proto); - if (error) - { + if (error) { printf("port redirect: error reading alias port\n"); printf("Usage: alias %s %s\n", list->name, list->syntax); return 1; @@ -74,7 +69,7 @@ AliasRedirectPort (struct cmdtab *list, null_addr.s_addr = 0; - link = PacketAliasRedirectPort(local_addr, local_port, + link = VarPacketAliasRedirectPort(local_addr, local_port, null_addr, 0, null_addr, alias_port, proto_constant); @@ -82,11 +77,9 @@ AliasRedirectPort (struct cmdtab *list, if (link == NULL) printf("port redirect: error returned by packed aliasing engine" "(code=%d)\n", error); + } else + printf("Usage: alias %s %s\n", list->name, list->syntax); - return 1; - } - - printf("Usage: alias %s %s\n", list->name, list->syntax); return 1; } @@ -97,39 +90,36 @@ AliasRedirectAddr(struct cmdtab *list, char **argv, void *param) { - if (argc == 2) - { + if (!(mode & MODE_ALIAS)) + printf("alias not enabled\n"); + else if (argc == 2) { int error; struct in_addr local_addr; struct in_addr alias_addr; struct alias_link *link; error = StrToAddr(argv[0], &local_addr); - if (error) - { + if (error) { printf("address redirect: invalid local address\n"); return 1; } error = StrToAddr(argv[1], &alias_addr); - if (error) - { + if (error) { printf("address redirect: invalid alias address\n"); printf("Usage: alias %s %s\n", list->name, list->syntax); return 1; } - link = PacketAliasRedirectAddr(local_addr, alias_addr); - if (link == NULL) - { + link = VarPacketAliasRedirectAddr(local_addr, alias_addr); + if (link == NULL) { printf("address redirect: packet aliasing engine error\n"); printf("Usage: alias %s %s\n", list->name, list->syntax); } - return 1; - } + } else + printf("Usage: alias %s %s\n", list->name, list->syntax); - printf("Usage: alias %s %s\n", list->name, list->syntax); return 1; } diff --git a/usr.sbin/ppp/async.c b/usr.sbin/ppp/async.c index f5eec86..f122c40 100644 --- a/usr.sbin/ppp/async.c +++ b/usr.sbin/ppp/async.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id$ + * $Id: async.c,v 1.7 1997/02/22 16:09:59 peter Exp $ * */ #include "fsm.h" @@ -25,6 +25,7 @@ #include "lcp.h" #include "lcpproto.h" #include "modem.h" +#include "loadalias.h" #include "vars.h" #include "os.h" diff --git a/usr.sbin/ppp/auth.c b/usr.sbin/ppp/auth.c index 29eb776..af99f04 100644 --- a/usr.sbin/ppp/auth.c +++ b/usr.sbin/ppp/auth.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: auth.c,v 1.11 1997/05/07 23:01:21 brian Exp $ + * $Id: auth.c,v 1.12 1997/05/10 01:22:05 brian Exp $ * * TODO: * o Implement check against with registered IP addresses. @@ -25,6 +25,7 @@ #include "fsm.h" #include "lcpproto.h" #include "ipcp.h" +#include "loadalias.h" #include "vars.h" #include "filter.h" #include "auth.h" diff --git a/usr.sbin/ppp/ccp.c b/usr.sbin/ppp/ccp.c index 99981fe..5b11272 100644 --- a/usr.sbin/ppp/ccp.c +++ b/usr.sbin/ppp/ccp.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: ccp.c,v 1.10 1997/02/22 16:10:03 peter Exp $ + * $Id: ccp.c,v 1.11 1997/05/10 01:22:06 brian Exp $ * * TODO: * o Support other compression protocols @@ -27,6 +27,7 @@ #include "lcp.h" #include "ccp.h" #include "phase.h" +#include "loadalias.h" #include "vars.h" #include "pred.h" #include "cdefs.h" diff --git a/usr.sbin/ppp/chap.c b/usr.sbin/ppp/chap.c index 31ba182..ee40421 100644 --- a/usr.sbin/ppp/chap.c +++ b/usr.sbin/ppp/chap.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: chap.c,v 1.15 1997/05/19 01:59:57 brian Exp $ + * $Id: chap.c,v 1.16 1997/05/24 17:32:32 brian Exp $ * * TODO: */ @@ -29,6 +29,7 @@ #include "lcp.h" #include "hdlc.h" #include "phase.h" +#include "loadalias.h" #include "vars.h" #include "auth.h" diff --git a/usr.sbin/ppp/chat.c b/usr.sbin/ppp/chat.c index a0b7ae6..6659ee2 100644 --- a/usr.sbin/ppp/chat.c +++ b/usr.sbin/ppp/chat.c @@ -18,7 +18,7 @@ * Columbus, OH 43221 * (614)451-1883 * - * $Id: chat.c,v 1.23 1997/05/07 23:01:23 brian Exp $ + * $Id: chat.c,v 1.24 1997/05/10 01:22:07 brian Exp $ * * TODO: * o Support more UUCP compatible control sequences. @@ -36,7 +36,12 @@ #include <errno.h> #include <signal.h> #include <sys/wait.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/param.h> +#include <netinet/in.h> #include "timeout.h" +#include "loadalias.h" #include "vars.h" #include "chat.h" #include "sig.h" diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c index 22f5e24..7ed7f30 100644 --- a/usr.sbin/ppp/command.c +++ b/usr.sbin/ppp/command.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: command.c,v 1.48 1997/05/23 04:54:01 brian Exp $ + * $Id: command.c,v 1.49 1997/05/24 17:32:33 brian Exp $ * */ #include <sys/types.h> @@ -41,11 +41,11 @@ #include "command.h" #include "alias_cmd.h" #include "hdlc.h" +#include "loadalias.h" #include "vars.h" #include "systems.h" #include "chat.h" #include "os.h" -#include "chat.h" extern void Cleanup(), TtyTermMode(), PacketMode(); extern int EnableCommand(), DisableCommand(), DisplayCommand(); @@ -79,7 +79,6 @@ struct cmdtab *plist; { struct cmdtab *cmd; int n; - char c; if (argc > 0) { for (cmd = plist; cmd->name; cmd++) { @@ -95,8 +94,7 @@ struct cmdtab *plist; n = 0; for (cmd = plist; cmd->func; cmd++) { if (cmd->name && (cmd->lauth & VarLocalAuth)) { - c = (n & 1)? '\n' : '\t'; - printf(" %-8s: %-20s%c", cmd->name, cmd->helpmes, c); + printf(" %-8s: %-20s\n", cmd->name, cmd->helpmes); n++; } } @@ -1272,14 +1270,21 @@ struct cmdtab *list; int argc; char **argv; { - if (argc == 1 && strcmp(argv[0], "yes") == 0) { - mode |= MODE_ALIAS; - } else if (argc == 1 && strcmp(argv[0], "no") == 0) { - mode &= ~MODE_ALIAS; - } else { - printf("Usage: alias %s %s\n", list->name, list->syntax); - } - return(1); + if (argc == 1 && strcmp(argv[0], "yes") == 0) { + if (!(mode & MODE_ALIAS)) + if (loadAliasHandlers(&VarAliasHandlers) == 0) + mode |= MODE_ALIAS; + else + printf("Cannot load alias library\n"); + } else if (argc == 1 && strcmp(argv[0], "no") == 0) { + if (mode & MODE_ALIAS) { + unloadAliasHandlers(); + mode &= ~MODE_ALIAS; + } + } else { + printf("Usage: alias %s %s\n", list->name, list->syntax); + } + return(1); } @@ -1291,9 +1296,15 @@ char **argv; void* param; { if (argc == 1 && strcmp(argv[0], "yes") == 0) { - SetPacketAliasMode((unsigned)param, (unsigned)param); + if (mode & MODE_ALIAS) + VarSetPacketAliasMode((unsigned)param, (unsigned)param); + else + printf("alias not enabled\n"); } else if (argc == 1 && strcmp(argv[0], "no") == 0) { - SetPacketAliasMode(0, (unsigned)param); + if (mode & MODE_ALIAS) + VarSetPacketAliasMode(0, (unsigned)param); + else + printf("alias not enabled\n"); } else { printf("Usage: alias %s %s\n", list->name, list->syntax); } diff --git a/usr.sbin/ppp/hdlc.c b/usr.sbin/ppp/hdlc.c index 8b44981..a7a37c8 100644 --- a/usr.sbin/ppp/hdlc.c +++ b/usr.sbin/ppp/hdlc.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: hdlc.c,v 1.13 1997/04/19 11:31:38 ache Exp $ + * $Id: hdlc.c,v 1.14 1997/05/10 01:22:10 brian Exp $ * * TODO: */ @@ -26,6 +26,7 @@ #include "lcpproto.h" #include "lcp.h" #include "lqr.h" +#include "loadalias.h" #include "vars.h" #include "pred.h" #include "modem.h" diff --git a/usr.sbin/ppp/ip.c b/usr.sbin/ppp/ip.c index fe78e9b..72b7a11 100644 --- a/usr.sbin/ppp/ip.c +++ b/usr.sbin/ppp/ip.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: ip.c,v 1.18 1997/05/23 04:54:02 brian Exp $ + * $Id: ip.c,v 1.19 1997/05/24 17:32:35 brian Exp $ * * TODO: * o Return ICMP message for filterd packet @@ -33,6 +33,7 @@ #include <netinet/tcp.h> #include <arpa/inet.h> #include <alias.h> +#include "loadalias.h" #include "vars.h" #include "filter.h" @@ -337,7 +338,7 @@ struct mbuf *bp; /* IN: Pointer to IP pakcet */ int iresult; char *fptr; - iresult = PacketAliasIn(tunbuff, sizeof tunbuff); + iresult = VarPacketAliasIn(tunbuff, sizeof tunbuff); nb = ntohs(((struct ip *) tunbuff)->ip_len); if (nb > MAX_MRU) { @@ -361,8 +362,8 @@ struct mbuf *bp; /* IN: Pointer to IP pakcet */ fprintf(stderr, "wrote %d, got %d\r\n", nb, nw); if (iresult == PKT_ALIAS_FOUND_HEADER_FRAGMENT) { - while ((fptr = GetNextFragmentPtr(tunbuff)) != NULL) { - FragmentAliasIn(tunbuff, fptr); + while ((fptr = VarGetNextFragmentPtr(tunbuff)) != NULL) { + VarFragmentAliasIn(tunbuff, fptr); nb = ntohs(((struct ip *) fptr)->ip_len); nw = write(tun_out, fptr, nb); if (nw != nb) @@ -379,7 +380,7 @@ struct mbuf *bp; /* IN: Pointer to IP pakcet */ } else { memcpy(fptr, tunbuff, nb); - SaveFragmentPtr(fptr); + VarSaveFragmentPtr(fptr); } } } diff --git a/usr.sbin/ppp/ipcp.c b/usr.sbin/ppp/ipcp.c index 2c414f3..2df6e87 100644 --- a/usr.sbin/ppp/ipcp.c +++ b/usr.sbin/ppp/ipcp.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: ipcp.c,v 1.18 1997/05/23 04:54:02 brian Exp $ + * $Id: ipcp.c,v 1.19 1997/05/24 17:32:35 brian Exp $ * * TODO: * o More RFC1772 backwoard compatibility @@ -31,10 +31,10 @@ #include <netinet/ip.h> #include <arpa/inet.h> #include <sys/socket.h> -#include <alias.h> #include "slcompress.h" #include "os.h" #include "phase.h" +#include "loadalias.h" #include "vars.h" extern void PutConfValue(); @@ -282,7 +282,7 @@ struct fsm *fp; IpcpStartReport(); StartIdleTimer(); if (mode & MODE_ALIAS) - SetPacketAliasAddress(IpcpInfo.want_ipaddr); + VarSetPacketAliasAddress(IpcpInfo.want_ipaddr); } void diff --git a/usr.sbin/ppp/lcp.c b/usr.sbin/ppp/lcp.c index b121ce7..2a63d00 100644 --- a/usr.sbin/ppp/lcp.c +++ b/usr.sbin/ppp/lcp.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: lcp.c,v 1.19 1997/05/19 02:00:04 brian Exp $ + * $Id: lcp.c,v 1.20 1997/05/24 17:32:38 brian Exp $ * * TODO: * o Validate magic number received from peer. @@ -33,6 +33,7 @@ #include "ccp.h" #include "lqr.h" #include "phase.h" +#include "loadalias.h" #include "vars.h" #include "auth.h" #include <arpa/inet.h> diff --git a/usr.sbin/ppp/loadalias.c b/usr.sbin/ppp/loadalias.c new file mode 100644 index 0000000..5e26bd4 --- /dev/null +++ b/usr.sbin/ppp/loadalias.c @@ -0,0 +1,88 @@ +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/param.h> +#include <netinet/in.h> +#include <stdlib.h> +#include <unistd.h> +#include <stdio.h> +#include <dlfcn.h> +#include "systems.h" +#include "mbuf.h" +#include "log.h" +#include "loadalias.h" +#include "vars.h" + +#define _PATH_ALIAS "/usr/lib/libalias.so.2.1" + +#define off(item) ((int)&(((struct aliasHandlers *)0)->item)) +#define entry(a) { off(a), "_" #a } + +static struct { + int offset; + char *name; +} map[] = { + entry(GetNextFragmentPtr), + entry(GetNextFragmentPtr), + entry(InitPacketAlias), + entry(PacketAliasIn), + entry(PacketAliasOut), + entry(PacketAliasRedirectAddr), + entry(PacketAliasRedirectPort), + entry(SaveFragmentPtr), + entry(SetPacketAliasAddress), + entry(SetPacketAliasMode), + entry(FragmentAliasIn), + { 0, 0 } +}; + +static void *dl; + +int loadAliasHandlers(struct aliasHandlers *h) +{ + char *path; + char *env; + char *err; + int i; + + path = _PATH_ALIAS; + env = getenv("_PATH_ALIAS"); + if (env) + if (OrigUid() == 0) + path = env; + else { + logprintf("Ignoring environment _PATH_ALIAS value (%s)\n", env); + printf("Ignoring environment _PATH_ALIAS value (%s)\n", env); + } + + dl = dlopen(path, RTLD_LAZY); + if (dl == (void *)0) { + err = dlerror(); + logprintf("_PATH_ALIAS (%s): Invalid lib: %s\n", path, err); + printf("_PATH_ALIAS (%s): Invalid lib: %s\n", path, err); + return -1; + } + + for (i = 0; map[i].name; i++) { + *(void **)((char *)h + map[i].offset) = dlsym(dl, map[i].name); + if (*(void **)((char *)h + map[i].offset) == (void *)0) { + err = dlerror(); + logprintf("_PATH_ALIAS (%s): %s: %s\n", path, map[i].name, err); + printf("_PATH_ALIAS (%s): %s: %s\n", path, map[i].name, err); + (void)dlclose(dl); + dl = (void *)0; + return -1; + } + } + + VarInitPacketAlias(); + + return 0; +} + +void unloadAliasHandlers() +{ + if (dl) { + dlclose(dl); + dl = (void *)0; + } +} diff --git a/usr.sbin/ppp/loadalias.h b/usr.sbin/ppp/loadalias.h new file mode 100644 index 0000000..601803d --- /dev/null +++ b/usr.sbin/ppp/loadalias.h @@ -0,0 +1,18 @@ +struct aliasHandlers { + char *(*GetNextFragmentPtr)(char *); + void (*InitPacketAlias)(); + int (*PacketAliasIn)(char *,int); + int (*PacketAliasOut)(char *,int); + struct alias_link *(*PacketAliasRedirectAddr) + (struct in_addr, struct in_addr); + struct alias_link *(*PacketAliasRedirectPort) + (struct in_addr, u_short, struct in_addr, u_short, + struct in_addr, u_short, u_char); + int (*SaveFragmentPtr)(char *); + void (*SetPacketAliasAddress)(struct in_addr); + unsigned (*SetPacketAliasMode)(unsigned, unsigned); + void (*FragmentAliasIn)(char *, char *); +}; + +extern int loadAliasHandlers(struct aliasHandlers *); +extern void unloadAliasHandlers(); diff --git a/usr.sbin/ppp/log.c b/usr.sbin/ppp/log.c index 091289c..0592131 100644 --- a/usr.sbin/ppp/log.c +++ b/usr.sbin/ppp/log.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: log.c,v 1.9 1997/05/04 02:39:03 ache Exp $ + * $Id: log.c,v 1.10 1997/05/07 23:30:48 brian Exp $ * */ #include "defs.h" @@ -151,9 +151,11 @@ vlogprintf(format, ap) char *format; va_list ap; { - vsnprintf(logptr, sizeof(logbuff)-(logptr-logbuff), format, ap); - logptr += strlen(logptr); - LogFlush(); + if (logptr) { + vsnprintf(logptr, sizeof(logbuff)-(logptr-logbuff), format, ap); + logptr += strlen(logptr); + LogFlush(); + } } void diff --git a/usr.sbin/ppp/lqr.c b/usr.sbin/ppp/lqr.c index b66f04e..77713de 100644 --- a/usr.sbin/ppp/lqr.c +++ b/usr.sbin/ppp/lqr.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: lqr.c,v 1.12 1997/05/19 02:00:05 brian Exp $ + * $Id: lqr.c,v 1.13 1997/05/24 17:32:39 brian Exp $ * * o LQR based on RFC1333 * @@ -30,6 +30,7 @@ #include "lqr.h" #include "hdlc.h" #include "lcp.h" +#include "loadalias.h" #include "vars.h" #include "main.h" diff --git a/usr.sbin/ppp/main.c b/usr.sbin/ppp/main.c index 1ff814d..cae2440 100644 --- a/usr.sbin/ppp/main.c +++ b/usr.sbin/ppp/main.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: main.c,v 1.55 1997/05/23 05:22:48 brian Exp $ + * $Id: main.c,v 1.56 1997/05/24 17:32:40 brian Exp $ * * TODO: * o Add commands for traffic summary, version display, etc. @@ -37,13 +37,13 @@ #include <arpa/inet.h> #include <netinet/in_systm.h> #include <netinet/ip.h> -#include <alias.h> #include "modem.h" #include "os.h" #include "hdlc.h" #include "ccp.h" #include "lcp.h" #include "ipcp.h" +#include "loadalias.h" #include "vars.h" #include "auth.h" #include "filter.h" @@ -289,7 +289,10 @@ ProcessArgs(int argc, char **argv) else if (strcmp(cp, "ddial") == 0) mode |= MODE_DDIAL|MODE_AUTO; else if (strcmp(cp, "alias") == 0) { - mode |= MODE_ALIAS; + if (loadAliasHandlers(&VarAliasHandlers) == 0) + mode |= MODE_ALIAS; + else + printf("Cannot load alias library\n"); optc--; /* this option isn't exclusive */ } else @@ -330,7 +333,6 @@ char **argv; Greetings(); GetUid(); IpcpDefAddress(); - InitPacketAlias(); if (SelectSystem("default", CONFFILE) < 0) { fprintf(stderr, "Warning: No default entry is given in config file.\n"); @@ -1026,7 +1028,7 @@ DoLoop() pri = PacketCheck(rbuff, n, FL_DIAL); if (pri >= 0) { if (mode & MODE_ALIAS) { - PacketAliasOut(rbuff, sizeof rbuff); + VarPacketAliasOut(rbuff, sizeof rbuff); n = ntohs(((struct ip *)rbuff)->ip_len); } IpEnqueue(pri, rbuff, n); @@ -1037,7 +1039,7 @@ DoLoop() pri = PacketCheck(rbuff, n, FL_OUT); if (pri >= 0) { if (mode & MODE_ALIAS) { - PacketAliasOut(rbuff, sizeof rbuff); + VarPacketAliasOut(rbuff, sizeof rbuff); n = ntohs(((struct ip *)rbuff)->ip_len); } IpEnqueue(pri, rbuff, n); diff --git a/usr.sbin/ppp/modem.c b/usr.sbin/ppp/modem.c index faea048..7568e2a 100644 --- a/usr.sbin/ppp/modem.c +++ b/usr.sbin/ppp/modem.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: modem.c,v 1.38 1997/05/19 02:00:08 brian Exp $ + * $Id: modem.c,v 1.39 1997/05/24 17:32:41 brian Exp $ * * TODO: */ @@ -33,6 +33,7 @@ #include "lcp.h" #include "ip.h" #include "modem.h" +#include "loadalias.h" #include "vars.h" #ifndef O_NONBLOCK diff --git a/usr.sbin/ppp/nat_cmd.c b/usr.sbin/ppp/nat_cmd.c index 1d99415..0603c7a 100644 --- a/usr.sbin/ppp/nat_cmd.c +++ b/usr.sbin/ppp/nat_cmd.c @@ -8,9 +8,10 @@ #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> -#include <alias.h> +#include "defs.h" #include "command.h" +#include "loadalias.h" #include "vars.h" static int @@ -29,8 +30,9 @@ AliasRedirectPort (struct cmdtab *list, char **argv, void *param) { - if (argc == 3) - { + if (!(mode & MODE_ALIAS)) + printf("alias not enabled\n"); + else if (argc == 3) { char proto_constant; char *proto; u_short local_port; @@ -41,32 +43,25 @@ AliasRedirectPort (struct cmdtab *list, struct alias_link *link; proto = argv[0]; - if (strcmp(proto, "tcp") == 0) - { + if (strcmp(proto, "tcp") == 0) { proto_constant = IPPROTO_TCP; - } - else if (strcmp(proto, "udp") == 0) - { + } else if (strcmp(proto, "udp") == 0) { proto_constant = IPPROTO_UDP; - } - else - { + } else { printf("port redirect: protocol must be tcp or udp\n"); printf("Usage: alias %s %s\n", list->name, list->syntax); return 1; } error = StrToAddrAndPort(argv[1], &local_addr, &local_port, proto); - if (error) - { + if (error) { printf("port redirect: error reading local addr:port\n"); printf("Usage: alias %s %s\n", list->name, list->syntax); return 1; } error = StrToPort(argv[2], &alias_port, proto); - if (error) - { + if (error) { printf("port redirect: error reading alias port\n"); printf("Usage: alias %s %s\n", list->name, list->syntax); return 1; @@ -74,7 +69,7 @@ AliasRedirectPort (struct cmdtab *list, null_addr.s_addr = 0; - link = PacketAliasRedirectPort(local_addr, local_port, + link = VarPacketAliasRedirectPort(local_addr, local_port, null_addr, 0, null_addr, alias_port, proto_constant); @@ -82,11 +77,9 @@ AliasRedirectPort (struct cmdtab *list, if (link == NULL) printf("port redirect: error returned by packed aliasing engine" "(code=%d)\n", error); + } else + printf("Usage: alias %s %s\n", list->name, list->syntax); - return 1; - } - - printf("Usage: alias %s %s\n", list->name, list->syntax); return 1; } @@ -97,39 +90,36 @@ AliasRedirectAddr(struct cmdtab *list, char **argv, void *param) { - if (argc == 2) - { + if (!(mode & MODE_ALIAS)) + printf("alias not enabled\n"); + else if (argc == 2) { int error; struct in_addr local_addr; struct in_addr alias_addr; struct alias_link *link; error = StrToAddr(argv[0], &local_addr); - if (error) - { + if (error) { printf("address redirect: invalid local address\n"); return 1; } error = StrToAddr(argv[1], &alias_addr); - if (error) - { + if (error) { printf("address redirect: invalid alias address\n"); printf("Usage: alias %s %s\n", list->name, list->syntax); return 1; } - link = PacketAliasRedirectAddr(local_addr, alias_addr); - if (link == NULL) - { + link = VarPacketAliasRedirectAddr(local_addr, alias_addr); + if (link == NULL) { printf("address redirect: packet aliasing engine error\n"); printf("Usage: alias %s %s\n", list->name, list->syntax); } - return 1; - } + } else + printf("Usage: alias %s %s\n", list->name, list->syntax); - printf("Usage: alias %s %s\n", list->name, list->syntax); return 1; } diff --git a/usr.sbin/ppp/os.c b/usr.sbin/ppp/os.c index fd2990e..c1a8962 100644 --- a/usr.sbin/ppp/os.c +++ b/usr.sbin/ppp/os.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: os.c,v 1.17 1997/05/19 02:00:10 brian Exp $ + * $Id: os.c,v 1.18 1997/05/24 17:32:41 brian Exp $ * */ #include "fsm.h" @@ -40,6 +40,7 @@ #include "ipcp.h" #include "os.h" +#include "loadalias.h" #include "vars.h" #include "arp.h" #include "systems.h" diff --git a/usr.sbin/ppp/pap.c b/usr.sbin/ppp/pap.c index 4159d12..89c387d 100644 --- a/usr.sbin/ppp/pap.c +++ b/usr.sbin/ppp/pap.c @@ -18,13 +18,14 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: pap.c,v 1.10 1997/05/19 02:00:12 brian Exp $ + * $Id: pap.c,v 1.11 1997/05/24 17:32:42 brian Exp $ * * TODO: */ #include "fsm.h" #include "lcp.h" #include "pap.h" +#include "loadalias.h" #include "vars.h" #include "hdlc.h" #include "lcpproto.h" diff --git a/usr.sbin/ppp/systems.c b/usr.sbin/ppp/systems.c index dc59e3c..57a4e2d 100644 --- a/usr.sbin/ppp/systems.c +++ b/usr.sbin/ppp/systems.c @@ -17,11 +17,12 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: systems.c,v 1.9 1997/02/22 16:10:56 peter Exp $ + * $Id: systems.c,v 1.10 1997/05/10 01:22:19 brian Exp $ * * TODO: */ #include "fsm.h" +#include "loadalias.h" #include "vars.h" #include "ipcp.h" #include "pathnames.h" @@ -33,6 +34,12 @@ static int uid, gid; static int euid, egid; static int usermode; +int +OrigUid() +{ + return uid; +} + void GetUid() { diff --git a/usr.sbin/ppp/systems.h b/usr.sbin/ppp/systems.h index 4c841e4..823bdbb 100644 --- a/usr.sbin/ppp/systems.h +++ b/usr.sbin/ppp/systems.h @@ -17,12 +17,13 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id$ + * $Id: systems.h,v 1.3 1997/02/22 16:10:57 peter Exp $ * */ #ifndef _SYSTEMS_H_ #define _SYSTEMS_H_ +extern int OrigUid __P((void)); extern void GetUid __P((void)); extern int SelectSystem __P((char *, char*)); #endif diff --git a/usr.sbin/ppp/vars.c b/usr.sbin/ppp/vars.c index aca7f6c..2ebc142 100644 --- a/usr.sbin/ppp/vars.c +++ b/usr.sbin/ppp/vars.c @@ -17,19 +17,20 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: vars.c,v 1.15 1997/05/10 03:39:55 brian Exp $ + * $Id: vars.c,v 1.16 1997/05/17 16:08:48 brian Exp $ * */ #include "fsm.h" #include "command.h" #include "hdlc.h" #include "termios.h" +#include "loadalias.h" #include "vars.h" #include "auth.h" #include "defs.h" char VarVersion[] = "Version 0.94"; -char VarLocalVersion[] = "$Date: 1997/05/10 03:39:55 $"; +char VarLocalVersion[] = "$Date: 1997/05/17 16:08:48 $"; /* * Order of conf option is important. See vars.h. diff --git a/usr.sbin/ppp/vars.h b/usr.sbin/ppp/vars.h index 6d6f20f..b9473d2 100644 --- a/usr.sbin/ppp/vars.h +++ b/usr.sbin/ppp/vars.h @@ -15,7 +15,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: vars.h,v 1.14 1997/05/19 02:00:16 brian Exp $ + * $Id: vars.h,v 1.15 1997/05/24 17:32:42 brian Exp $ * * TODO: */ @@ -83,6 +83,7 @@ struct pppvars { char phone_copy[200]; /* copy for strsep() */ char *next_phone; /* Next phone from the list */ char shostname[MAXHOSTNAMELEN];/* Local short Host Name */ + struct aliasHandlers handler; /* Alias function pointers */ }; #define VarAccmap pppVars.var_accmap @@ -111,6 +112,19 @@ struct pppvars { #define VarRedialNextTimeout pppVars.redial_next_timeout #define VarDialTries pppVars.dial_tries +#define VarAliasHandlers pppVars.handler +#define VarGetNextFragmentPtr (*pppVars.handler.GetNextFragmentPtr) +#define VarGetNextFragmentPtr (*pppVars.handler.GetNextFragmentPtr) +#define VarInitPacketAlias (*pppVars.handler.InitPacketAlias) +#define VarPacketAliasIn (*pppVars.handler.PacketAliasIn) +#define VarPacketAliasOut (*pppVars.handler.PacketAliasOut) +#define VarPacketAliasRedirectAddr (*pppVars.handler.PacketAliasRedirectAddr) +#define VarPacketAliasRedirectPort (*pppVars.handler.PacketAliasRedirectPort) +#define VarSaveFragmentPtr (*pppVars.handler.SaveFragmentPtr) +#define VarSetPacketAliasAddress (*pppVars.handler.SetPacketAliasAddress) +#define VarSetPacketAliasMode (*pppVars.handler.SetPacketAliasMode) +#define VarFragmentAliasIn (*pppVars.handler.FragmentAliasIn) + #define DEV_IS_SYNC (VarSpeed == 0) extern struct pppvars pppVars; |