From 927145be97d8d5b69a0a1a86dc7e9d637102c7d0 Mon Sep 17 00:00:00 2001 From: Brian Somers Date: Mon, 9 Jun 1997 03:27:43 +0000 Subject: [PATCH] Overhaul ppp: o Use syslog o Remove references to stdout/stderr (incl perror()) o Introduce VarTerm - the interactive terminal or zero o Allow "set timeout" to affect current session o Change "set debug" to "set log" o Allow "set log [+|-]flag" o Make MSEXT and PASSWDAUTH stuff the default o Move all #ifdef DEBUG stuff into the code - this shouldn't be too much overhead. It's now controlled with "set log +debug" o Add "set log command, debug, tun, warn, error, alert" o Remove cdefs.h, and assume an ansi compiler. o Improve all diagnostic output o Don't trap SIGSEGV o SIGHUP now terminates again (log files are controlled by syslog) o Call CloseModem() when changing devices o Fix parsing of third arg of "delete" I think this fixes the "magic is same" problems that some people have been experiencing. The man page is being rewritten. It'll follow soon. --- usr.sbin/ppp/Makefile | 9 +- usr.sbin/ppp/alias_cmd.c | 78 ++-- usr.sbin/ppp/arp.c | 39 +- usr.sbin/ppp/arp.h | 6 +- usr.sbin/ppp/async.c | 6 +- usr.sbin/ppp/auth.c | 6 +- usr.sbin/ppp/auth.h | 14 +- usr.sbin/ppp/ccp.c | 58 ++- usr.sbin/ppp/ccp.h | 14 +- usr.sbin/ppp/cdefs.h | 33 -- usr.sbin/ppp/chap.c | 51 +-- usr.sbin/ppp/chap.h | 4 +- usr.sbin/ppp/chat.c | 68 ++-- usr.sbin/ppp/chat.h | 7 +- usr.sbin/ppp/command.c | 825 +++++++++++++++++++++----------------- usr.sbin/ppp/defs.h | 3 +- usr.sbin/ppp/filter.c | 125 +++--- usr.sbin/ppp/filter.h | 4 +- usr.sbin/ppp/fsm.c | 82 ++-- usr.sbin/ppp/fsm.h | 49 ++- usr.sbin/ppp/hdlc.c | 50 +-- usr.sbin/ppp/hdlc.h | 16 +- usr.sbin/ppp/ip.c | 86 ++-- usr.sbin/ppp/ip.h | 8 +- usr.sbin/ppp/ipcp.c | 124 +++--- usr.sbin/ppp/ipcp.h | 18 +- usr.sbin/ppp/lcp.c | 117 +++--- usr.sbin/ppp/lcp.h | 15 +- usr.sbin/ppp/lcpproto.h | 19 +- usr.sbin/ppp/loadalias.c | 18 +- usr.sbin/ppp/log.c | 383 +++++------------- usr.sbin/ppp/log.h | 103 ++--- usr.sbin/ppp/lqr.c | 62 ++- usr.sbin/ppp/lqr.h | 14 +- usr.sbin/ppp/main.c | 271 ++++++------- usr.sbin/ppp/main.h | 4 +- usr.sbin/ppp/mbuf.c | 66 +-- usr.sbin/ppp/mbuf.h | 22 +- usr.sbin/ppp/modem.c | 203 ++++------ usr.sbin/ppp/modem.h | 35 +- usr.sbin/ppp/nat_cmd.c | 78 ++-- usr.sbin/ppp/os.c | 79 ++-- usr.sbin/ppp/os.h | 24 +- usr.sbin/ppp/pap.c | 30 +- usr.sbin/ppp/passwdauth.c | 12 +- usr.sbin/ppp/passwdauth.h | 2 +- usr.sbin/ppp/phase.h | 5 +- usr.sbin/ppp/pred.c | 17 +- usr.sbin/ppp/pred.h | 8 +- usr.sbin/ppp/route.c | 140 +++---- usr.sbin/ppp/route.h | 4 +- usr.sbin/ppp/sig.c | 6 +- usr.sbin/ppp/sig.h | 6 +- usr.sbin/ppp/slcompress.c | 53 ++- usr.sbin/ppp/slcompress.h | 9 +- usr.sbin/ppp/systems.c | 40 +- usr.sbin/ppp/systems.h | 8 +- usr.sbin/ppp/timeout.h | 17 +- usr.sbin/ppp/timer.c | 58 ++- usr.sbin/ppp/vars.c | 165 +++----- usr.sbin/ppp/vars.h | 14 +- usr.sbin/ppp/vjcomp.c | 20 +- 62 files changed, 1750 insertions(+), 2160 deletions(-) delete mode 100644 usr.sbin/ppp/cdefs.h diff --git a/usr.sbin/ppp/Makefile b/usr.sbin/ppp/Makefile index b11a51155097..05173f3a2d71 100644 --- a/usr.sbin/ppp/Makefile +++ b/usr.sbin/ppp/Makefile @@ -1,14 +1,13 @@ -# $Id: Makefile,v 1.19 1997/05/23 04:53:49 brian Exp $ +# $Id: Makefile,v 1.20 1997/05/26 00:43:54 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 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 -DPADD += ${LIBMD} ${LIBCRYPT} ${LIBUTIL} +CFLAGS+=-Wall +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 0603c7ae75cc..f6aa1be2d2f9 100644 --- a/usr.sbin/ppp/alias_cmd.c +++ b/usr.sbin/ppp/alias_cmd.c @@ -30,9 +30,10 @@ AliasRedirectPort (struct cmdtab *list, char **argv, void *param) { - if (!(mode & MODE_ALIAS)) - printf("alias not enabled\n"); - else if (argc == 3) { + if (!(mode & MODE_ALIAS)) { + if (VarTerm) + fprintf(VarTerm, "Alias not enabled\n"); + } else if (argc == 3) { char proto_constant; char *proto; u_short local_port; @@ -48,23 +49,30 @@ AliasRedirectPort (struct cmdtab *list, } else if (strcmp(proto, "udp") == 0) { proto_constant = IPPROTO_UDP; } else { - printf("port redirect: protocol must be tcp or udp\n"); - printf("Usage: alias %s %s\n", list->name, list->syntax); + if (VarTerm) { + fprintf(VarTerm, "port redirect: protocol must be tcp or udp\n"); + fprintf(VarTerm, "Usage: alias %s %s\n", list->name, + list->syntax); + } return 1; } error = StrToAddrAndPort(argv[1], &local_addr, &local_port, proto); if (error) { - printf("port redirect: error reading local addr:port\n"); - printf("Usage: alias %s %s\n", list->name, list->syntax); - return 1; + if (VarTerm) { + fprintf(VarTerm, "port redirect: error reading local addr:port\n"); + fprintf(VarTerm, "Usage: alias %s %s\n", list->name, list->syntax); + } + return 1; } error = StrToPort(argv[2], &alias_port, proto); if (error) { - printf("port redirect: error reading alias port\n"); - printf("Usage: alias %s %s\n", list->name, list->syntax); - return 1; + if (VarTerm) { + fprintf(VarTerm, "port redirect: error reading alias port\n"); + fprintf(VarTerm, "Usage: alias %s %s\n", list->name, list->syntax); + } + return 1; } null_addr.s_addr = 0; @@ -74,11 +82,11 @@ AliasRedirectPort (struct cmdtab *list, null_addr, alias_port, proto_constant); - 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); + if (link == NULL && VarTerm) + fprintf(VarTerm, "port redirect: error returned by packed" + " aliasing engine (code=%d)\n", error); + } else if (VarTerm) + fprintf(VarTerm, "Usage: alias %s %s\n", list->name, list->syntax); return 1; } @@ -90,9 +98,10 @@ AliasRedirectAddr(struct cmdtab *list, char **argv, void *param) { - if (!(mode & MODE_ALIAS)) - printf("alias not enabled\n"); - else if (argc == 2) { + if (!(mode & MODE_ALIAS)) { + if (VarTerm) + fprintf(VarTerm, "alias not enabled\n"); + } else if (argc == 2) { int error; struct in_addr local_addr; struct in_addr alias_addr; @@ -100,25 +109,27 @@ AliasRedirectAddr(struct cmdtab *list, error = StrToAddr(argv[0], &local_addr); if (error) { - printf("address redirect: invalid local address\n"); + if (VarTerm) + fprintf(VarTerm, "address redirect: invalid local address\n"); return 1; } error = StrToAddr(argv[1], &alias_addr); if (error) { - printf("address redirect: invalid alias address\n"); - printf("Usage: alias %s %s\n", list->name, list->syntax); - return 1; + if (VarTerm) { + fprintf(VarTerm, "address redirect: invalid alias address\n"); + fprintf(VarTerm, "Usage: alias %s %s\n", list->name, list->syntax); + } + return 1; } 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); + if (link == NULL && VarTerm) { + fprintf(VarTerm, "address redirect: packet aliasing engine error\n"); + fprintf(VarTerm, "Usage: alias %s %s\n", list->name, list->syntax); } - - } else - printf("Usage: alias %s %s\n", list->name, list->syntax); + } else if (VarTerm) + fprintf(VarTerm, "Usage: alias %s %s\n", list->name, list->syntax); return 1; } @@ -136,7 +147,7 @@ StrToAddr (char* str, hp = gethostbyname (str); if (!hp) { - fprintf (stderr, "Unknown host %s.\n", str); + LogPrintf(LogWARN, "StrToAddr: Unknown host %s.\n", str); return -1; } @@ -164,8 +175,8 @@ StrToPort (char *str, sp = getservbyname (str, proto); if (!sp) { - fprintf (stderr, "Unknown port or service %s/%s.\n", - str, proto); + LogPrintf(LogWARN, "StrToAddr: Unknown port or service %s/%s.\n", + str, proto); return -1; } @@ -185,7 +196,8 @@ StrToAddrAndPort (char* str, ptr = strchr (str, ':'); if (!ptr) { - fprintf (stderr, "%s is missing port number.\n", str); + LogPrintf(LogWARN, "StrToAddrAndPort: %s is missing port number.\n", + str); return -1; } diff --git a/usr.sbin/ppp/arp.c b/usr.sbin/ppp/arp.c index d816be3e3ae6..24f691c78659 100644 --- a/usr.sbin/ppp/arp.c +++ b/usr.sbin/ppp/arp.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: arp.c,v 1.10 1997/02/25 14:04:50 brian Exp $ + * $Id: arp.c,v 1.11 1997/04/15 00:03:35 brian Exp $ * */ @@ -55,7 +55,7 @@ static int rtm_seq; -static int get_ether_addr __P((int, u_long, struct sockaddr_dl *)); +static int get_ether_addr(int, u_long, struct sockaddr_dl *); #define BCOPY(s, d, l) memcpy(d, s, l) #define BZERO(s, n) memset(s, 0, n) @@ -96,12 +96,14 @@ sifproxyarp(unit, hisaddr) */ memset(&arpmsg, 0, sizeof(arpmsg)); if (!get_ether_addr(unit, hisaddr, &arpmsg.hwa)) { - logprintf("Cannot determine ethernet address for proxy ARP\n"); + LogPrintf(LogERROR, "Cannot determine ethernet address" + " for proxy ARP\n"); return 0; } if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) { - logprintf("sifproxyarp: opening routing socket: \n"); + LogPrintf(LogERROR, "sifproxyarp: opening routing socket: %s\n", + strerror(errno)); return 0; } @@ -119,7 +121,7 @@ sifproxyarp(unit, hisaddr) arpmsg.hdr.rtm_msglen = (char *) &arpmsg.hwa - (char *) &arpmsg + arpmsg.hwa.sdl_len; if (write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0) { - logprintf("add proxy arp entry: \n"); + LogPrintf(LogERROR, "Add proxy arp entry: %s\n", strerror(errno)); close(routes); return 0; } @@ -147,12 +149,13 @@ cifproxyarp(unit, hisaddr) arpmsg.hdr.rtm_seq = ++rtm_seq; if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) { - logprintf("sifproxyarp: opening routing socket: \n"); + LogPrintf(LogERROR, "sifproxyarp: opening routing socket: %s\n", + strerror(errno)); return 0; } if (write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0) { - logprintf("delete proxy arp entry: \n"); + LogPrintf(LogERROR, "Delete proxy arp entry: %s\n", strerror(errno)); close(routes); return 0; } @@ -195,7 +198,7 @@ sifproxyarp(unit, hisaddr) ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr; arpreq.arp_flags = ATF_PERM | ATF_PUBL; if (ioctl(unit, SIOCSARP, (caddr_t)&arpreq) < 0) { - fprintf(stderr, "ioctl(SIOCSARP): \n"); + LogPrintf(LogERROR, "sifproxyarp: ioctl(SIOCSARP): \n"); return 0; } @@ -216,7 +219,7 @@ cifproxyarp(unit, hisaddr) SET_SA_FAMILY(arpreq.arp_pa, AF_INET); ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr; if (ioctl(unit, SIOCDARP, (caddr_t)&arpreq) < 0) { - fprintf(stderr, "ioctl(SIOCDARP): \n"); + LogPrintf(LogERROR, "cifproxyarp: ioctl(SIOCDARP): \n"); return 0; } return 1; @@ -246,7 +249,7 @@ get_ether_addr(s, ipaddr, hwaddr) ifc.ifc_len = sizeof(ifs); ifc.ifc_req = ifs; if (ioctl(s, SIOCGIFCONF, &ifc) < 0) { - fprintf(stderr, "ioctl(SIOCGIFCONF): \n"); + LogPrintf(LogERROR, "get_ether_addr: ioctl(SIOCGIFCONF): \n"); return 0; } @@ -287,7 +290,7 @@ get_ether_addr(s, ipaddr, hwaddr) if (ifr >= ifend) return 0; - LogPrintf(LOG_PHASE_BIT, "found interface %s for proxy arp\n", ifr->ifr_name); + LogPrintf(LogPHASE, "Found interface %s for proxy arp\n", ifr->ifr_name); /* * Now scan through again looking for a link-level address @@ -335,14 +338,12 @@ kread(addr, buf, size) char *buf; int size; { - - if (kvm_read(kvmd, addr, buf, size) != size) { - /* XXX this duplicates kvm_read's error printout */ - (void)fprintf(stderr, "kvm_read %s\n", - kvm_geterr(kvmd)); - return (-1); - } - return (0); + if (kvm_read(kvmd, addr, buf, size) != size) { + /* XXX this duplicates kvm_read's error printout */ + LogPrintf(LogERROR, "kvm_read %s\n", kvm_geterr(kvmd)); + return -1; + } + return 0; } kmemgetether(ifname, dlo) diff --git a/usr.sbin/ppp/arp.h b/usr.sbin/ppp/arp.h index 52737167f11d..b2e38e658a4f 100644 --- a/usr.sbin/ppp/arp.h +++ b/usr.sbin/ppp/arp.h @@ -17,12 +17,12 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id$ + * $Id: arp.h,v 1.3 1997/02/22 16:09:57 peter Exp $ * */ #ifndef _ARP_H_ #define _ARP_H_ -extern int cifproxyarp __P((int, u_long)); -extern int sifproxyarp __P((int, u_long)); +extern int cifproxyarp(int, u_long); +extern int sifproxyarp(int, u_long); #endif diff --git a/usr.sbin/ppp/async.c b/usr.sbin/ppp/async.c index f122c4008c51..c4a101b0e23f 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: async.c,v 1.7 1997/02/22 16:09:59 peter Exp $ + * $Id: async.c,v 1.8 1997/05/26 00:43:55 brian Exp $ * */ #include "fsm.h" @@ -121,7 +121,7 @@ int proto; *cp ++ = HDLC_SYN; cnt = cp - hs->xbuff; - LogDumpBuff(LOG_ASYNC, "WriteModem", hs->xbuff, cnt); + LogDumpBuff(LogASYNC, "WriteModem", hs->xbuff, cnt); WriteModem(pri, (char *)hs->xbuff, cnt); OsAddOutOctets(cnt); pfree(bp); @@ -156,7 +156,7 @@ u_char c; default: if (hs->length >= HDLCSIZE) { /* packet is too large, discard it */ - logprintf("too large, diacarding.\n"); + LogPrintf(LogERROR, "Packet too large (%d), diacarding.\n", hs->length); hs->length = 0; hs->mode = MODE_HUNT; break; diff --git a/usr.sbin/ppp/auth.c b/usr.sbin/ppp/auth.c index af99f045cf9c..17b34240a41e 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.12 1997/05/10 01:22:05 brian Exp $ + * $Id: auth.c,v 1.13 1997/05/26 00:43:55 brian Exp $ * * TODO: * o Implement check against with registered IP addresses. @@ -158,9 +158,7 @@ int len, setaddr; } n -= 2; if (n > 0 && setaddr) { -#ifdef DEBUG - LogPrintf(LOG_LCP_BIT, "*** n = %d, %s\n", n, vector[2]); -#endif + LogPrintf(LogDEBUG, "AuthGetSecret: n = %d, %s\n", n, vector[2]); if (ParseAddr(n--, &vector[2], &DefHisAddress.ipaddr, &DefHisAddress.mask, diff --git a/usr.sbin/ppp/auth.h b/usr.sbin/ppp/auth.h index 169f84c99554..4ca72ae98c12 100644 --- a/usr.sbin/ppp/auth.h +++ b/usr.sbin/ppp/auth.h @@ -15,7 +15,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id$ + * $Id: auth.h,v 1.5 1997/02/22 16:10:02 peter Exp $ * * TODO: */ @@ -35,10 +35,10 @@ struct authinfo { extern struct authinfo AuthPapInfo; extern struct authinfo AuthChapInfo; -extern void SendPapChallenge __P((int)); -extern void SendChapChallenge __P((int)); -extern void StopAuthTimer __P((struct authinfo *)); -extern void StartAuthChallenge __P((struct authinfo *)); -extern LOCAL_AUTH_VALID LocalAuthInit __P((void)); -extern int AuthValidate __P((char *, char *, char *)); +extern void SendPapChallenge(int); +extern void SendChapChallenge(int); +extern void StopAuthTimer(struct authinfo *); +extern void StartAuthChallenge(struct authinfo *); +extern LOCAL_AUTH_VALID LocalAuthInit(void); +extern int AuthValidate(char *, char *, char *); #endif diff --git a/usr.sbin/ppp/ccp.c b/usr.sbin/ppp/ccp.c index 5b11272410c1..bee71312c0f5 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.11 1997/05/10 01:22:06 brian Exp $ + * $Id: ccp.c,v 1.12 1997/05/26 00:43:56 brian Exp $ * * TODO: * o Support other compression protocols @@ -30,19 +30,18 @@ #include "loadalias.h" #include "vars.h" #include "pred.h" -#include "cdefs.h" struct ccpstate CcpInfo; -static void CcpSendConfigReq __P((struct fsm *)); -static void CcpSendTerminateReq __P((struct fsm *fp)); -static void CcpSendTerminateAck __P((struct fsm *fp)); -static void CcpDecodeConfig __P((u_char *cp, int flen, int mode)); -static void CcpLayerStart __P((struct fsm *)); -static void CcpLayerFinish __P((struct fsm *)); -static void CcpLayerUp __P((struct fsm *)); -static void CcpLayerDown __P((struct fsm *)); -static void CcpInitRestartCounter __P((struct fsm *)); +static void CcpSendConfigReq(struct fsm *); +static void CcpSendTerminateReq(struct fsm *fp); +static void CcpSendTerminateAck(struct fsm *fp); +static void CcpDecodeConfig(u_char *cp, int flen, int mode); +static void CcpLayerStart(struct fsm *); +static void CcpLayerFinish(struct fsm *); +static void CcpLayerUp(struct fsm *); +static void CcpLayerDown(struct fsm *); +static void CcpInitRestartCounter(struct fsm *); #define REJECTED(p, x) (p->his_reject & (1<name, StateNames[fp->state]); - printf("myproto = %s, hisproto = %s\n", - cftypes[icp->want_proto], cftypes[icp->his_proto]); - printf("Input: %ld --> %ld, Output: %ld --> %ld\n", - icp->orgin, icp->compin, icp->orgout, icp->compout); + if (VarTerm) { + fprintf(VarTerm, "%s [%s]\n", fp->name, StateNames[fp->state]); + fprintf(VarTerm, "myproto = %s, hisproto = %s\n", + cftypes[icp->want_proto], cftypes[icp->his_proto]); + fprintf(VarTerm, "Input: %ld --> %ld, Output: %ld --> %ld\n", + icp->orgin, icp->compin, icp->orgout, icp->compout); + } return 0; } @@ -119,7 +120,7 @@ struct fsm *fp; struct ccpstate *icp = &CcpInfo; cp = ReqBuff; - LogPrintf(LOG_LCP_BIT, "%s: SendConfigReq\n", fp->name); + LogPrintf(LogLCP, "CcpSendConfigReq\n"); if (icp->want_proto && !REJECTED(icp, TY_PRED1)) { *cp++ = TY_PRED1; *cp++ = 2; } @@ -131,7 +132,7 @@ CcpSendResetReq(fp) struct fsm *fp; { Pred1Init(1); /* Initialize Input part */ - LogPrintf(LOG_LCP_BIT, "%s: SendResetReq\n", fp->name); + LogPrintf(LogLCP, "CcpSendResetReq\n"); FsmOutput(fp, CODE_RESETREQ, fp->reqid, NULL, 0); } @@ -146,7 +147,7 @@ static void CcpSendTerminateAck(fp) struct fsm *fp; { - LogPrintf(LOG_LCP_BIT, " %s: SendTerminateAck\n", fp->name); + LogPrintf(LogLCP, "CcpSendTerminateAck\n"); FsmOutput(fp, CODE_TERMACK, fp->reqid++, NULL, 0); } @@ -161,21 +162,21 @@ static void CcpLayerStart(fp) struct fsm *fp; { - LogPrintf(LOG_LCP_BIT, "%s: LayerStart.\n", fp->name); + LogPrintf(LogLCP, "CcpLayerStart.\n"); } static void CcpLayerFinish(fp) struct fsm *fp; { - LogPrintf(LOG_LCP_BIT, "%s: LayerFinish.\n", fp->name); + LogPrintf(LogLCP, "CcpLayerFinish.\n"); } static void CcpLayerDown(fp) struct fsm *fp; { - LogPrintf(LOG_LCP_BIT, "%s: LayerDown.\n", fp->name); + LogPrintf(LogLCP, "CcpLayerDown.\n"); } /* @@ -185,11 +186,8 @@ static void CcpLayerUp(fp) struct fsm *fp; { -#ifdef VERBOSE - fprintf(stderr, "%s: LayerUp(%d).\r\n", fp->name, fp->state); -#endif - LogPrintf(LOG_LCP_BIT, "%s: LayerUp.\n", fp->name); - LogPrintf(LOG_LCP_BIT, "myproto = %d, hisproto = %d\n", + LogPrintf(LogLCP, "CcpLayerUp(%d).\n", fp->state); + LogPrintf(LogLCP, "myproto = %d, hisproto = %d\n", CcpInfo.want_proto, CcpInfo.his_proto); Pred1Init(3); /* Initialize Input and Output */ } @@ -198,7 +196,7 @@ void CcpUp() { FsmUp(&CcpFsm); - LogPrintf(LOG_LCP_BIT, "CCP Up event!!\n"); + LogPrintf(LogLCP, "CCP Up event!!\n"); } void @@ -231,7 +229,7 @@ int mode; else snprintf(tbuff, sizeof(tbuff), " "); - LogPrintf(LOG_LCP_BIT, "%s\n", tbuff); + LogPrintf(LogLCP, "%s\n", tbuff); switch (type) { case TY_PRED1: @@ -271,7 +269,7 @@ CcpInput(struct mbuf *bp) if (phase == PHASE_NETWORK) FsmInput(&CcpFsm, bp); else { - logprintf("ccp in phase %d\n", phase); + LogPrintf(LogERROR, "Unexpected CCP in phase %d\n", phase); pfree(bp); } } diff --git a/usr.sbin/ppp/ccp.h b/usr.sbin/ppp/ccp.h index 785c5731b2e7..acb2a1b9b212 100644 --- a/usr.sbin/ppp/ccp.h +++ b/usr.sbin/ppp/ccp.h @@ -15,7 +15,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id$ + * $Id: ccp.h,v 1.5 1997/02/22 16:10:03 peter Exp $ * * TODO: */ @@ -49,10 +49,10 @@ struct ccpstate { extern struct ccpstate CcpInfo; -void CcpRecvResetReq __P((struct fsm *)); -void CcpSendResetReq __P((struct fsm *)); -void CcpInput __P((struct mbuf *)); -void CcpUp __P((void)); -void CcpOpen __P((void)); -void CcpInit __P((void)); +void CcpRecvResetReq(struct fsm *); +void CcpSendResetReq(struct fsm *); +void CcpInput(struct mbuf *); +void CcpUp(void); +void CcpOpen(void); +void CcpInit(void); #endif diff --git a/usr.sbin/ppp/cdefs.h b/usr.sbin/ppp/cdefs.h deleted file mode 100644 index 540905d7b7e8..000000000000 --- a/usr.sbin/ppp/cdefs.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Written by Toshiharu OHNO (tony-o@iij.ad.jp) - * - * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd. - * - * Redistribution and use in source and binary forms are permitted - * provided that the above copyright notice and this paragraph are - * duplicated in all such forms and that any documentation, - * advertising materials, and other materials related to such - * distribution and use acknowledge that the software was developed - * by the Internet Initiative Japan. The name of the - * IIJ may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id: cdefs.h,v 1.3 1997/02/22 16:10:04 peter Exp $ - * - * TODO: - */ - -#ifndef __P -#if defined(__bsdi__) || defined(__FreeBSD__) -#include -#else -#ifdef __STDC__ -#define __P(arg) arg -#else -#define __P(arg) () -#endif /* __STDC__ */ -#endif /* __bsdi__ */ -#endif /* __P */ diff --git a/usr.sbin/ppp/chap.c b/usr.sbin/ppp/chap.c index ee404219c8c0..0ca0c7f61f45 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.16 1997/05/24 17:32:32 brian Exp $ + * $Id: chap.c,v 1.17 1997/05/26 00:43:56 brian Exp $ * * TODO: */ @@ -62,10 +62,8 @@ int count; bcopy(&lh, MBUF_CTOP(bp), sizeof(struct fsmheader)); if (count) bcopy(ptr, MBUF_CTOP(bp) + sizeof(struct fsmheader), count); -#ifdef DEBUG - DumpBp(bp); -#endif - LogPrintf(LOG_LCP_BIT, "ChapOutput: %s\n", chapcodes[code]); + LogDumpBp(LogDEBUG, "ChapOutput", bp); + LogPrintf(LogLCP, "ChapOutput: %s\n", chapcodes[code]); HdlcOutput(PRI_LINK, PROTO_CHAP, bp); } @@ -96,23 +94,6 @@ int chapid; ChapOutput(CHAP_CHALLENGE, chapid, challenge_data, cp - challenge_data); } -#ifdef DEBUG -void -DumpDigest(mes, cp, len) -char *mes; -char *cp; -int len; -{ - int i; - - logprintf("%s: ", mes); - for (i = 0; i < len; i++) { - logprintf(" %02x", *cp++ & 0xff); - } - logprintf("\n"); -} -#endif - void RecvChapTalk(chp, bp) struct fsmheader *chp; @@ -127,16 +108,14 @@ struct mbuf *bp; char cdigest[16]; len = ntohs(chp->length); -#ifdef DEBUG - logprintf("length: %d\n", len); -#endif + LogPrintf(LogDEBUG, "RecvChapTalk: length: %d\n", len); arglen = len - sizeof(struct fsmheader); cp = (char *)MBUF_CTOP(bp); valsize = *cp++ & 255; name = cp + valsize; namelen = arglen - valsize - 1; name[namelen] = 0; - LogPrintf(LOG_PHASE_BIT, " Valsize = %d, Name = %s\n", valsize, name); + LogPrintf(LogPHASE, " Valsize = %d, Name = %s\n", valsize, name); /* * Get a secret key corresponds to the peer @@ -165,16 +144,12 @@ struct mbuf *bp; bcopy(keyp, ap, keylen); ap += keylen; bcopy(cp, ap, valsize); -#ifdef DEBUG - DumpDigest("recv", ap, valsize); -#endif + LogDumpBuff(LogDEBUG, "recv", ap, valsize); ap += valsize; MD5Init(&context); MD5Update(&context, answer, ap - answer); MD5Final(digest, &context); -#ifdef DEBUG - DumpDigest("answer", digest, 16); -#endif + LogDumpBuff(LogDEBUG, "answer", digest, 16); bcopy(name, digest + 16, namelen); ap += namelen; /* Send answer to the peer */ @@ -195,10 +170,8 @@ struct mbuf *bp; MD5Update(&context, answer, ap - answer); MD5Update(&context, challenge_data+1, challenge_len); MD5Final(cdigest, &context); -#ifdef DEBUG - DumpDigest("got", cp, 16); - DumpDigest("expect", cdigest, 16); -#endif + LogDumpBuff(LogDEBUG, "got", cp, 16); + LogDumpBuff(LogDEBUG, "expect", cdigest, 16); /* * Compare with the response */ @@ -227,9 +200,7 @@ struct mbuf *bp; struct lcpstate *lcp = &LcpInfo; len = ntohs(chp->length); -#ifdef DEBUG - logprintf("length: %d\n", len); -#endif + LogPrintf(LogDEBUG, "RecvChapResult: length: %d\n", len); if (chp->code == CHAP_SUCCESS) { if (lcp->auth_iwait == PROTO_CHAP) { lcp->auth_iwait = 0; @@ -255,7 +226,7 @@ ChapInput(struct mbuf *bp) if (len >= ntohs(chp->length)) { if (chp->code < 1 || chp->code > 4) chp->code = 0; - LogPrintf(LOG_LCP_BIT, "ChapInput: %s\n", chapcodes[chp->code]); + LogPrintf(LogLCP, "ChapInput: %s\n", chapcodes[chp->code]); bp->offset += sizeof(struct fsmheader); bp->cnt -= sizeof(struct fsmheader); diff --git a/usr.sbin/ppp/chap.h b/usr.sbin/ppp/chap.h index 6c992a51fff7..acb5585283f8 100644 --- a/usr.sbin/ppp/chap.h +++ b/usr.sbin/ppp/chap.h @@ -15,15 +15,15 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id$ + * $Id: chap.h,v 1.5 1997/02/22 16:10:06 peter Exp $ * * TODO: */ #ifndef _CHAP_H_ #define _CHAP_H_ -#include "global.h" #include +#include "global.h" #define CHAP_CHALLENGE 1 #define CHAP_RESPONSE 2 diff --git a/usr.sbin/ppp/chat.c b/usr.sbin/ppp/chat.c index 6659ee29cb73..6ba72e41c311 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.24 1997/05/10 01:22:07 brian Exp $ + * $Id: chat.c,v 1.25 1997/05/26 00:43:57 brian Exp $ * * TODO: * o Support more UUCP compatible control sequences. @@ -180,9 +180,9 @@ int sendmode; strncpy(result, phone, reslen); reslen -= strlen(result); result += strlen(result); - if ((mode & (MODE_INTER|MODE_AUTO)) == MODE_INTER) - fprintf(stderr, "Phone: %s\n", phone); - LogPrintf(LOG_PHASE_BIT, "Phone: %s\n", phone); + if (VarTerm) + fprintf(VarTerm, "Phone: %s\n", phone); + LogPrintf(LogPHASE, "Phone: %s", phone); break; case 'U': strncpy(result, VarAuthName, reslen); @@ -229,11 +229,11 @@ static void clear_log() { } static void flush_log() { - if ((loglevel & LOG_CONNECT_BIT) - || ((loglevel & LOG_CARRIER_BIT) - && strstr(logbuff,"CARRIER"))) { - LogPrintf(LOG_CONNECT_BIT|LOG_CARRIER_BIT,"Chat: %s\n",logbuff); - } + if (LogIsKept(LogCONNECT)) + LogPrintf(LogCONNECT,"%s", logbuff); + else if (LogIsKept(LogCARRIER) && strstr(logbuff,"CARRIER")) + LogPrintf(LogCARRIER,"%s", logbuff); + clear_log(); } @@ -271,13 +271,13 @@ char *estr; #endif clear_log(); (void) ExpandString(estr, buff, sizeof(buff), 0); - LogPrintf(LOG_CHAT_BIT, "Wait for (%d): %s --> %s\n", TimeoutSec, estr, buff); + LogPrintf(LogCHAT, "Wait for (%d): %s --> %s", TimeoutSec, estr, buff); str = buff; inp = inbuff; if (strlen(str)>=IBSIZE){ str[IBSIZE-1]=0; - LogPrintf(LOG_CHAT_BIT, "Truncating String to %d character: %s\n", IBSIZE, str); + LogPrintf(LogCHAT, "Truncating String to %d character: %s", IBSIZE, str); } nfds = modem + 1; @@ -301,14 +301,14 @@ char *estr; continue; sigsetmask(omask); #endif - perror("select"); + LogPrintf(LogERROR, "select: %s", strerror(errno)); *inp = 0; return(NOMATCH); } else if (i == 0) { /* Timeout reached! */ *inp = 0; if (inp != inbuff) - LogPrintf(LOG_CHAT_BIT, "got: %s\n", inbuff); - LogPrintf(LOG_CHAT_BIT, "can't get (%d).\n", timeout.tv_sec); + LogPrintf(LogCHAT, "Got: %s", inbuff); + LogPrintf(LogCHAT, "Can't get (%d).", timeout.tv_sec); #ifdef SIGALRM sigsetmask(omask); #endif @@ -333,7 +333,7 @@ char *estr; } for (i = 0; i < numaborts; i++) { if (strstr(inbuff, AbortStrings[i])) { - LogPrintf(LOG_CHAT_BIT, "Abort: %s\n", AbortStrings[i]); + LogPrintf(LogCHAT, "Abort: %s", AbortStrings[i]); #ifdef SIGALRM sigsetmask(omask); #endif @@ -343,7 +343,7 @@ char *estr; } } else { if (read(modem, &ch, 1) < 0) { - perror("read error"); + LogPrintf(LogERROR, "read error: %s", strerror(errno)); *inp = '\0'; return(NOMATCH); } @@ -372,7 +372,7 @@ char *estr; s1 = AbortStrings[i]; len = strlen(s1); if ((len <= inp - inbuff) && (strncmp(inp - len, s1, len) == 0)) { - LogPrintf(LOG_CHAT_BIT, "Abort: %s\n", s1); + LogPrintf(LogCHAT, "Abort: %s", s1); *inp = 0; #ifdef SIGALRM sigsetmask(omask); @@ -408,15 +408,13 @@ char *command, *out; cp--; } if (snprintf(tmp, sizeof tmp, "%s %s", command, cp) >= sizeof tmp) { - LogPrintf(LOG_CHAT_BIT, "Too long string to ExecStr: \"%s\"\n", - command); + LogPrintf(LogCHAT, "Too long string to ExecStr: \"%s\"", command); return; } (void) MakeArgs(tmp, vector, VECSIZE(vector)); if (pipe(fids) < 0) { - LogPrintf(LOG_CHAT_BIT, "Unable to create pipe in ExecStr: %s\n", - strerror(errno)); + LogPrintf(LogCHAT, "Unable to create pipe in ExecStr: %s", strerror(errno)); return; } @@ -430,29 +428,27 @@ char *command, *out; signal(SIGALRM, SIG_DFL); close(fids[0]); if (dup2(fids[1], 1) < 0) { - LogPrintf(LOG_CHAT_BIT, "dup2(fids[1], 1) in ExecStr: %s\n", - strerror(errno)); + LogPrintf(LogCHAT, "dup2(fids[1], 1) in ExecStr: %s", strerror(errno)); return; } close(fids[1]); nb = open("/dev/tty", O_RDWR); if (dup2(nb, 0) < 0) { - LogPrintf(LOG_CHAT_BIT, "dup2(nb, 0) in ExecStr: %s\n", - strerror(errno)); + LogPrintf(LogCHAT, "dup2(nb, 0) in ExecStr: %s", strerror(errno)); return; } - LogPrintf(LOG_CHAT_BIT, "exec: %s\n", command); + LogPrintf(LogCHAT, "exec: %s", command); /* switch back to original privileges */ if (setgid(getgid()) < 0) { - LogPrintf(LOG_CHAT_BIT, "setgid: %s\n", strerror(errno)); + LogPrintf(LogCHAT, "setgid: %s", strerror(errno)); exit(1); } if (setuid(getuid()) < 0) { - LogPrintf(LOG_CHAT_BIT, "setuid: %s\n", strerror(errno)); + LogPrintf(LogCHAT, "setuid: %s", strerror(errno)); exit(1); } pid = execvp(command, vector); - LogPrintf(LOG_CHAT_BIT, "execvp failed for (%d/%d): %s\n", pid, errno, command); + LogPrintf(LogCHAT, "execvp failed for (%d/%d): %s", pid, errno, command); exit(127); } else { close(fids[1]); @@ -494,9 +490,9 @@ char *str; (void) ExpandString(str, buff+2, sizeof(buff)-2, 1); } if (strstr(str, "\\P")) { /* Do not log the password itself. */ - LogPrintf(LOG_CHAT_BIT, "sending: %s\n", str); + LogPrintf(LogCHAT, "sending: %s", str); } else { - LogPrintf(LOG_CHAT_BIT, "sending: %s\n", buff+2); + LogPrintf(LogCHAT, "sending: %s", buff+2); } cp = buff; if (DEV_IS_SYNC) @@ -523,7 +519,7 @@ char *str; ++timeout_next; return(MATCH); } - LogPrintf(LOG_CHAT_BIT, "Expecting %s\n", str); + LogPrintf(LogCHAT, "Expecting %s", str); while (*str) { /* * Check whether if string contains sub-send-expect. @@ -574,9 +570,6 @@ char *script; char *vector[40]; char **argv; int argc, n, state; -#ifdef DEBUG - int i; -#endif timeout_next = abort_next = 0; for (n = 0; AbortStrings[n]; n++) { @@ -587,11 +580,6 @@ char *script; bzero(vector, sizeof(vector)); n = MakeArgs(script, vector, VECSIZE(vector)); -#ifdef DEBUG - logprintf("n = %d\n", n); - for (i = 0; i < n; i++) - logprintf(" %s\n", vector[i]); -#endif argc = n; argv = vector; TimeoutSec = 30; diff --git a/usr.sbin/ppp/chat.h b/usr.sbin/ppp/chat.h index 14ddc396cb3d..cdb032f9eb11 100644 --- a/usr.sbin/ppp/chat.h +++ b/usr.sbin/ppp/chat.h @@ -18,13 +18,12 @@ * Columbus, OH 43221 * (614)451-1883 * - * $Id: chat.h,v 1.4 1997/02/22 16:10:07 peter Exp $ + * $Id: chat.h,v 1.5 1997/05/07 23:01:24 brian Exp $ * */ #ifndef _CHAT_H_ #define _CHAT_H_ -#include "cdefs.h" -extern char * ExpandString __P((char *, char *, int, int)); -extern int MakeArgs __P((char *, char **, int)); +extern char * ExpandString(char *, char *, int, int); +extern int MakeArgs(char *, char **, int); #define VECSIZE(v) (sizeof(v) / sizeof(v[0])) #endif diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c index 85bea9720e2f..e314d57992db 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.52 1997/05/31 16:37:19 brian Exp $ + * $Id: command.c,v 1.53 1997/06/01 01:13:00 brian Exp $ * */ #include @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include "fsm.h" #include "phase.h" #include "lcp.h" @@ -46,6 +48,7 @@ #include "systems.h" #include "chat.h" #include "os.h" +#include "timeout.h" extern void Cleanup(), TtyTermMode(), PacketMode(); extern int EnableCommand(), DisableCommand(), DisplayCommand(); @@ -80,27 +83,32 @@ struct cmdtab *plist; struct cmdtab *cmd; int n; + if (!VarTerm) + return 0; + if (argc > 0) { - for (cmd = plist; cmd->name; cmd++) { + for (cmd = plist; cmd->name; cmd++) if (strcasecmp(cmd->name, *argv) == 0 && (cmd->lauth & VarLocalAuth)) { if (plist == SetCommands) - printf("set "); - printf("%s %s\n", cmd->name, cmd->syntax); - return(1); + fprintf(VarTerm, "set "); + fprintf(VarTerm, "%s\n", cmd->syntax); + return 0; } - } - return(1); + + return -1; } + n = 0; - for (cmd = plist; cmd->func; cmd++) { + for (cmd = plist; cmd->func; cmd++) if (cmd->name && (cmd->lauth & VarLocalAuth)) { - printf(" %-8s: %-20s\n", cmd->name, cmd->helpmes); + fprintf(VarTerm, " %-8s: %-20s\n", cmd->name, cmd->helpmes); n++; } - } + if (n & 1) - printf("\n"); - return(1); + fprintf(VarTerm, "\n"); + + return 0; } int @@ -119,10 +127,11 @@ IsInteractive() else if (mode & MODE_DEDICATED) mes = "Working in dedicated mode."; if (mes) { - printf("%s\n", mes); - return(0); + if (VarTerm) + fprintf(VarTerm, "%s\n", mes); + return 0; } - return(1); + return 1; } static int @@ -134,23 +143,30 @@ char **argv; int tries; if (LcpFsm.state > ST_CLOSED) { - printf("LCP state is [%s]\n", StateNames[LcpFsm.state]); - return(1); + if (VarTerm) + fprintf(VarTerm, "LCP state is [%s]\n", StateNames[LcpFsm.state]); + return 0; } + if (!IsInteractive()) return(1); + if (argc > 0) { if (SelectSystem(*argv, CONFFILE) < 0) { - printf("%s: not found.\n", *argv); - return(1); + if (VarTerm) + fprintf(VarTerm, "%s: not found.\n", *argv); + return -1; } } + tries = 0; do { - printf("Dial attempt %u of %d\n", ++tries, VarDialTries); + if (VarTerm) + fprintf(VarTerm, "Dial attempt %u of %d\n", ++tries, VarDialTries); modem = OpenModem(mode); if (modem < 0) { - printf("failed to open modem.\n"); + if (VarTerm) + fprintf(VarTerm, "Failed to open modem.\n"); break; } if (DialModem() == EX_DONE) { @@ -160,7 +176,8 @@ char **argv; break; } } while (VarDialTries == 0 || tries < VarDialTries); - return(1); + + return 0; } static int @@ -171,33 +188,50 @@ char **argv; { const char *shell; pid_t shpid; + FILE *oVarTerm; - if((shell = getenv("SHELL")) == 0) { - shell = _PATH_BSHELL; - } #ifdef SHELL_ONLY_INTERACTIVELY -#ifndef HAVE_SHELL_CMD_WITH_ANY_MODE - if( mode != MODE_INTER) { - fprintf(stdout, - "Can only start a shell in interactive mode\n"); - return(1); + if (mode != MODE_INTER) { + LogPrintf(LogWARN, "Can only start a shell in interactive mode\n"); + return 1; } -#else - if(argc == 0 && !(mode & MODE_INTER)) { - fprintf(stderr, - "Can only start an interactive shell in interactive mode\n"); - return(1); - } -#endif /* HAVE_SHELL_CMD_WITH_ANY_MODE */ #else if ((mode & (MODE_AUTO|MODE_INTER)) == (MODE_AUTO|MODE_INTER)) { - fprintf(stdout, - "Shell is not allowed interactively in auto mode\n"); - return(1); + LogPrintf(LogWARN, "Shell is not allowed interactively in auto mode\n"); + return 1; } -#endif /* SHELL_ONLY_INTERACTIVELY */ +#endif + + if(argc == 0 && !(mode & MODE_INTER)) { + LogPrintf(LogWARN, "Can only start an interactive shell in" + " interactive mode\n"); + return 1; + } + + if((shell = getenv("SHELL")) == 0) + shell = _PATH_BSHELL; + if((shpid = fork()) == 0) { - int dtablesize, i ; + int dtablesize, i, fd; + + if (VarTerm) + fd = fileno(VarTerm); + else if ((fd = open("/dev/null", O_RDWR)) == -1) { + LogPrintf(LogALERT, "Failed to open /dev/null: %s\n", strerror(errno)); + exit(1); + } + + for (i = 0; i < 3; i++) + dup2(fd, i); + + if (fd > 2) + if (VarTerm) { + oVarTerm = VarTerm; + VarTerm = 0; + if (oVarTerm && oVarTerm != stdout) + fclose(oVarTerm); + } else + close(fd); for (dtablesize = getdtablesize(), i = 3; i < dtablesize; i++) (void)close(i); @@ -207,11 +241,11 @@ char **argv; * real user for avoiding security problems. */ if (setgid(getgid()) < 0) { - perror("setgid"); + LogPrintf(LogERROR, "setgid: %s\n", strerror(errno)); exit(1); } if (setuid(getuid()) < 0) { - perror("setuid"); + LogPrintf(LogERROR, "setuid: %s\n", strerror(errno)); exit(1); } TtyOldMode(); @@ -233,11 +267,12 @@ char **argv; else (void)execl(shell, shell, NULL); - fprintf(stdout, "exec() of %s failed\n", argc > 0? argv[0]: shell); + LogPrintf(LogWARN, "exec() of %s failed\n", argc > 0 ? argv[0] : shell); exit(255); } + if( shpid == (pid_t)-1 ) { - fprintf(stdout, "Fork failed\n"); + LogPrintf(LogERROR, "Fork failed: %s\n", strerror(errno)); } else { int status; (void)waitpid(shpid, &status, 0); @@ -248,51 +283,47 @@ char **argv; return(0); } -static char StrOption[] = "option .."; -static char StrRemote[] = "[remote]"; -char StrNull[] = ""; - struct cmdtab const Commands[] = { { "accept", NULL, AcceptCommand, LOCAL_AUTH, - "accept option request", StrOption}, + "accept option request", "accept option .."}, { "add", NULL, AddCommand, LOCAL_AUTH, - "add route", "dest mask gateway"}, + "add route", "add dest mask gateway"}, { "close", NULL, CloseCommand, LOCAL_AUTH, - "Close connection", StrNull}, + "Close connection", "close"}, { "delete", NULL, DeleteCommand, LOCAL_AUTH, - "delete route", "ALL | dest gateway [mask]"}, + "delete route", "delete ALL | dest gateway [mask]"}, { "deny", NULL, DenyCommand, LOCAL_AUTH, - "Deny option request", StrOption}, + "Deny option request", "deny option .."}, { "dial", "call", DialCommand, LOCAL_AUTH, - "Dial and login", StrRemote}, + "Dial and login", "dial|call [remote]"}, { "disable", NULL, DisableCommand, LOCAL_AUTH, - "Disable option", StrOption}, + "Disable option", "disable option .."}, { "display", NULL, DisplayCommand, LOCAL_AUTH, - "Display option configs", StrNull}, + "Display option configs", "display"}, { "enable", NULL, EnableCommand, LOCAL_AUTH, - "Enable option", StrOption}, + "Enable option", "enable option .."}, { "passwd", NULL, LocalAuthCommand,LOCAL_NO_AUTH, - "Password for manipulation", StrOption}, + "Password for manipulation", "passwd option .."}, { "load", NULL, LoadCommand, LOCAL_AUTH, - "Load settings", StrRemote}, + "Load settings", "load [remote]"}, { "save", NULL, SaveCommand, LOCAL_AUTH, - "Save settings", StrNull}, + "Save settings", "save"}, { "set", "setup", SetCommand, LOCAL_AUTH, - "Set parameters", "var value"}, + "Set parameters", "set[up] var value"}, { "shell", "!", ShellCommand, LOCAL_AUTH, - "Run a subshell", "[sh command]"}, + "Run a subshell", "shell|! [sh command]"}, { "show", NULL, ShowCommand, LOCAL_AUTH, - "Show status and statictics", "var"}, + "Show status and statictics", "show var"}, { "term", NULL, TerminalCommand,LOCAL_AUTH, - "Enter to terminal mode", StrNull}, + "Enter to terminal mode", "term"}, { "alias", NULL, AliasCommand, LOCAL_AUTH, - "alias control", "option [yes|no]"}, + "alias control", "alias option [yes|no]"}, { "quit", "bye", QuitCommand, LOCAL_AUTH | LOCAL_NO_AUTH, - "Quit PPP program", "[all]"}, + "Quit PPP program", "quit|bye [all]"}, { "help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH, - "Display this message", "[command]", (void *)Commands }, + "Display this message", "help|? [command]", (void *)Commands }, { NULL, "down", DownCommand, LOCAL_AUTH, - "Generate down event", StrNull}, + "Generate down event", "down"}, { NULL, NULL, NULL }, }; @@ -305,56 +336,56 @@ extern int ShowModemStatus(); extern int ReportHdlcStatus(); extern int ShowMemMap(); -static char *LogLevelName[] = { - LM_PHASE, LM_CHAT, LM_LQM, LM_LCP, - LM_TCPIP, LM_HDLC, LM_ASYNC, LM_LINK, - LM_CONNECT, LM_CARRIER, -}; - -static int ShowDebugLevel() +static int ShowLogLevel() { int i; - printf("%02x: ", loglevel); - for (i = LOG_PHASE; i < MAXLOGLEVEL; i++) { - if (loglevel & (1 << i)) - printf("%s ", LogLevelName[i]); + if (!VarTerm) + return 0; + fprintf(VarTerm, "Log:"); + for (i = LogMIN; i < LogMAXCONF; i++) { + if (LogIsKept(i)) + fprintf(VarTerm, " %s", LogName(i)); } - printf("\n"); - return(1); + fprintf(VarTerm, "\n"); + + return 0; } static int ShowEscape() { int code, bit; + if (!VarTerm) + return 0; if (EscMap[32]) { - for (code = 0; code < 32; code++) { - if (EscMap[code]) { - for (bit = 0; bit < 8; bit++) { - if (EscMap[code] & (1<= 0) { - printf(" %d seconds, ", VarRedialTimeout); + fprintf(VarTerm, " %d seconds, ", VarRedialTimeout); } else { - printf(" Random 0 - %d seconds, ", REDIAL_PERIOD); + fprintf(VarTerm, " Random 0 - %d seconds, ", REDIAL_PERIOD); } - printf(" Redial Next Timer: "); + fprintf(VarTerm, " Redial Next Timer: "); if (VarRedialNextTimeout >= 0) { - printf(" %d seconds, ", VarRedialNextTimeout); + fprintf(VarTerm, " %d seconds, ", VarRedialNextTimeout); } else { - printf(" Random 0 - %d seconds, ", REDIAL_PERIOD); + fprintf(VarTerm, " Random 0 - %d seconds, ", REDIAL_PERIOD); } if (VarDialTries) - printf("%d dial tries", VarDialTries); + fprintf(VarTerm, "%d dial tries", VarDialTries); - printf("\n"); + fprintf(VarTerm, "\n"); - return(1); + return 1; } -#ifdef MSEXT +#ifndef NOMSEXT static int ShowMSExt() { - printf(" MS PPP extention values \n" ); - printf(" Primary NS : %s\n", inet_ntoa( ns_entries[0] )); - printf(" Secondary NS : %s\n", inet_ntoa( ns_entries[1] )); - printf(" Primary NBNS : %s\n", inet_ntoa( nbns_entries[0] )); - printf(" Secondary NBNS : %s\n", inet_ntoa( nbns_entries[1] )); - - return(1); + if (!VarTerm) + return 0; + fprintf(VarTerm, " MS PPP extention values \n" ); + fprintf(VarTerm, " Primary NS : %s\n", inet_ntoa( ns_entries[0] )); + fprintf(VarTerm, " Secondary NS : %s\n", inet_ntoa( ns_entries[1] )); + fprintf(VarTerm, " Primary NBNS : %s\n", inet_ntoa( nbns_entries[0] )); + fprintf(VarTerm, " Secondary NBNS : %s\n", inet_ntoa( nbns_entries[1] )); + return 1; } -#endif /* MSEXT */ +#endif extern int ShowIfilter(), ShowOfilter(), ShowDfilter(), ShowAfilter(); struct cmdtab const ShowCommands[] = { { "afilter", NULL, ShowAfilter, LOCAL_AUTH, - "Show keep Alive filters", StrOption}, + "Show keep Alive filters", "show afilter option .."}, { "auth", NULL, ShowAuthKey, LOCAL_AUTH, - "Show auth name/key", StrNull}, + "Show auth name/key", "show auth"}, { "ccp", NULL, ReportCcpStatus, LOCAL_AUTH, - "Show CCP status", StrNull}, + "Show CCP status", "show cpp"}, { "compress", NULL, ReportCompress, LOCAL_AUTH, - "Show compression statictics", StrNull}, - { "debug", NULL, ShowDebugLevel, LOCAL_AUTH, - "Show current debug level", StrNull}, + "Show compression statictics", "show compress"}, { "dfilter", NULL, ShowDfilter, LOCAL_AUTH, - "Show Demand filters", StrOption}, + "Show Demand filters", "show dfilteroption .."}, { "escape", NULL, ShowEscape, LOCAL_AUTH, - "Show escape characters", StrNull}, + "Show escape characters", "show escape"}, { "hdlc", NULL, ReportHdlcStatus, LOCAL_AUTH, - "Show HDLC error summary", StrNull}, + "Show HDLC error summary", "show hdlc"}, { "ifilter", NULL, ShowIfilter, LOCAL_AUTH, - "Show Input filters", StrOption}, + "Show Input filters", "show ifilter option .."}, { "ipcp", NULL, ReportIpcpStatus, LOCAL_AUTH, - "Show IPCP status", StrNull}, + "Show IPCP status", "show ipcp"}, { "lcp", NULL, ReportLcpStatus, LOCAL_AUTH, - "Show LCP status", StrNull}, - { "log", NULL, ShowLogList, LOCAL_AUTH, - "Show log records", StrNull}, + "Show LCP status", "show lcp"}, + { "log", NULL, ShowLogLevel, LOCAL_AUTH, + "Show current log level", "show log"}, { "mem", NULL, ShowMemMap, LOCAL_AUTH, - "Show memory map", StrNull}, + "Show memory map", "show mem"}, { "modem", NULL, ShowModemStatus, LOCAL_AUTH, - "Show modem setups", StrNull}, + "Show modem setups", "show modem"}, { "mru", NULL, ShowInitialMRU, LOCAL_AUTH, - "Show Initial MRU", StrNull}, + "Show Initial MRU", "show mru"}, { "mtu", NULL, ShowPreferredMTU, LOCAL_AUTH, - "Show Preferred MTU", StrNull}, + "Show Preferred MTU", "show mtu"}, { "ofilter", NULL, ShowOfilter, LOCAL_AUTH, - "Show Output filters", StrOption}, + "Show Output filters", "show ofilter option .."}, { "proto", NULL, ReportProtStatus, LOCAL_AUTH, - "Show protocol summary", StrNull}, + "Show protocol summary", "show proto"}, { "reconnect",NULL, ShowReconnect, LOCAL_AUTH, - "Show Reconnect timer,tries", StrNull}, + "Show Reconnect timer,tries", "show reconnect"}, { "redial", NULL, ShowRedial, LOCAL_AUTH, - "Show Redial timeout value", StrNull}, + "Show Redial timeout value", "show redial"}, { "route", NULL, ShowRoute, LOCAL_AUTH, - "Show routing table", StrNull}, + "Show routing table", "show route"}, { "timeout", NULL, ShowTimeout, LOCAL_AUTH, - "Show Idle timeout value", StrNull}, -#ifdef MSEXT + "Show Idle timeout value", "show timeout"}, +#ifndef NOMSEXT { "msext", NULL, ShowMSExt, LOCAL_AUTH, - "Show MS PPP extentions", StrNull}, -#endif /* MSEXT */ + "Show MS PPP extentions", "show msext"}, +#endif { "version", NULL, ShowVersion, LOCAL_NO_AUTH | LOCAL_AUTH, - "Show version string", StrNull}, + "Show version string", "show version"}, { "help", "?", HelpCommand, LOCAL_NO_AUTH | LOCAL_AUTH, - "Display this message", StrNull, (void *)ShowCommands}, + "Display this message", "show help|?", (void *)ShowCommands}, { NULL, NULL, NULL }, }; @@ -499,22 +533,33 @@ struct cmdtab *cmds; char *str; int *pmatch; { - int nmatch = 0; - int len = strlen(str); - struct cmdtab *found = NULL; + int nmatch; + int len; + struct cmdtab *found; + found = NULL; + len = strlen(str); + nmatch = 0; while (cmds->func) { if (cmds->name && strncasecmp(str, cmds->name, len) == 0) { + if (cmds->name[len] == '\0') { + *pmatch = 1; + return cmds; + } nmatch++; found = cmds; - } else if (cmds->alias && strncasecmp(str, cmds->alias, len) == 0) { + } else if(cmds->alias && strncasecmp(str, cmds->alias, len) == 0) { + if (cmds->alias[len] == '\0') { + *pmatch = 1; + return cmds; + } nmatch++; found = cmds; } cmds++; } *pmatch = nmatch; - return(found); + return found; } int @@ -529,26 +574,33 @@ char **argv; cmd = FindCommand(cmdlist, *argv, &nmatch); if (nmatch > 1) - printf("Ambiguous.\n"); + LogPrintf(LogWARN, "%s: Ambiguous command\n", *argv); else if (cmd && ( cmd->lauth & VarLocalAuth ) ) val = (cmd->func)(cmd, --argc, ++argv, cmd->args); else - printf("what?\n"); - return(val); + LogPrintf(LogWARN, "%s: Invalid command\n", *argv); + + if (val == -1) + LogPrintf(LogWARN, "Usage: %s\n", cmd->syntax); + else if(val) + LogPrintf(LogCOMMAND, "%s: Failed %d\n", *argv, val); + + return val; } int aft_cmd = 1; +extern int TermMode; void Prompt() { char *pconnect, *pauth; - if (!(mode & MODE_INTER)) + if (!(mode & MODE_INTER) || !VarTerm || TermMode) return; if (!aft_cmd) - printf("\n"); + fprintf(VarTerm, "\n"); else aft_cmd = 0; @@ -560,8 +612,8 @@ Prompt() pconnect = "PPP"; else pconnect = "ppp"; - printf("%s%s%s> ", pconnect, pauth, VarShortHost); - fflush(stdout); + fprintf(VarTerm, "%s%s%s> ", pconnect, pauth, VarShortHost); + fflush(VarTerm); } void @@ -572,23 +624,20 @@ int prompt; { char *vector[20]; char **argv; - int argc, val; + int argc; char *cp; - val = 1; if (nb > 0) { cp = buff + strcspn(buff, "\r\n"); if (cp) *cp = '\0'; - { - argc = MakeArgs(buff, vector, VECSIZE(vector)); - argv = vector; + argc = MakeArgs(buff, vector, VECSIZE(vector)); + argv = vector; - if (argc > 0) - val = FindExec(Commands, argc, argv); - } + if (argc > 0) + FindExec(Commands, argc, argv); } - if (val && prompt) + if (prompt) Prompt(); } @@ -598,31 +647,36 @@ struct cmdtab *list; int argc; char **argv; { - int val = 1; - if (argc > 0) - val = FindExec(ShowCommands, argc, argv); + FindExec(ShowCommands, argc, argv); + else if (VarTerm) + fprintf(VarTerm, "Use ``show ?'' to get a list.\n"); else - printf("Use ``show ?'' to get a list.\n"); - return(val); + LogPrintf(LogWARN, "show command must have arguments\n"); + + return 0; } static int TerminalCommand() { if (LcpFsm.state > ST_CLOSED) { - printf("LCP state is [%s]\n", StateNames[LcpFsm.state]); - return(1); + if (VarTerm) + fprintf(VarTerm, "LCP state is [%s]\n", StateNames[LcpFsm.state]); + return 1; } if (!IsInteractive()) return(1); modem = OpenModem(mode); if (modem < 0) { - printf("failed to open modem.\n"); + if (VarTerm) + fprintf(VarTerm, "Failed to open modem.\n"); return(1); } - printf("Enter to terminal mode.\n"); - printf("Type `~?' for help.\n"); + if (VarTerm) { + fprintf(VarTerm, "Enter to terminal mode.\n"); + fprintf(VarTerm, "Type `~?' for help.\n"); + } TtyTermMode(); return(0); } @@ -633,22 +687,31 @@ struct cmdtab *list; int argc; char **argv; { + FILE *oVarTerm; + if (mode & (MODE_DIRECT|MODE_DEDICATED|MODE_AUTO)) { if (argc > 0 && (VarLocalAuth & LOCAL_AUTH)) { Cleanup(EX_NORMAL); mode &= ~MODE_INTER; + oVarTerm = VarTerm; + VarTerm = 0; + if (oVarTerm && oVarTerm != stdout) + fclose(oVarTerm); } else { - LogPrintf(LOG_PHASE_BIT, "client connection closed.\n"); + LogPrintf(LogPHASE, "Client connection closed.\n"); VarLocalAuth = LOCAL_NO_AUTH; - close(netfd); - close(1); - dup2(2, 1); /* Have to have something here or the modem will be 1 */ - netfd = -1; mode &= ~MODE_INTER; + oVarTerm = VarTerm; + VarTerm = 0; + if (oVarTerm && oVarTerm != stdout) + fclose(oVarTerm); + close(netfd); + netfd = -1; } } else Cleanup(EX_NORMAL); - return(1); + + return 0; } static int @@ -658,14 +721,14 @@ CloseCommand() LcpClose(); if (mode & MODE_BACKGROUND) Cleanup(EX_NORMAL); - return(1); + return 0; } static int DownCommand() { LcpDown(); - return(1); + return 0; } static int @@ -679,16 +742,16 @@ char **argv; if (argc > 0) { if (strcmp(*argv, "sync") == 0) { VarSpeed = 0; - return(1); + return 0; } speed = atoi(*argv); if (IntToSpeed(speed) != B0) { VarSpeed = speed; - return(1); + return 0; } - printf("invalid speed.\n"); + LogPrintf(LogWARN, "%s: Invalid speed\n", *argv); } - return(1); + return -1; } static int @@ -700,9 +763,10 @@ char **argv; if (argc == 2) { VarReconnectTimer = atoi(argv[0]); VarReconnectTries = atoi(argv[1]); - } else - printf("Usage: %s %s\n", list->name, list->syntax); - return(1); + return 0; + } + + return -1; } static int @@ -719,22 +783,19 @@ char **argv; if (strncasecmp(argv[0], "random", 6) == 0 && (argv[0][6] == '\0' || argv[0][6] == '.')) { VarRedialTimeout = -1; - printf("Using random redial timeout.\n"); if (!randinit) { randinit = 1; if (srandomdev() < 0) srandom((unsigned long)(time(NULL) ^ getpid())); } - } - else { + } else { timeout = atoi(argv[0]); - if (timeout >= 0) { + if (timeout >= 0) VarRedialTimeout = timeout; - } else { - printf("invalid redial timeout\n"); - printf("Usage: %s %s\n", list->name, list->syntax); + LogPrintf(LogWARN, "Invalid redial timeout\n"); + return -1; } } @@ -742,7 +803,6 @@ char **argv; if (dot) { if (strcasecmp(++dot, "random") == 0) { VarRedialNextTimeout = -1; - printf("Using random next redial timeout.\n"); if (!randinit) { randinit = 1; if (srandomdev() < 0) @@ -751,12 +811,11 @@ char **argv; } else { timeout = atoi(dot); - if (timeout >= 0) { + if (timeout >= 0) VarRedialNextTimeout = timeout; - } else { - printf("invalid next redial timeout\n"); - printf("Usage: %s %s\n", list->name, list->syntax); + LogPrintf(LogWARN, "Invalid next redial timeout\n"); + return -1; } } } @@ -767,18 +826,16 @@ char **argv; tries = atoi(argv[1]); if (tries >= 0) { - VarDialTries = tries; - } - else { - printf("invalid retry value\n"); - printf("Usage: %s %s\n", list->name, list->syntax); + VarDialTries = tries; + } else { + LogPrintf(LogWARN, "Invalid retry value\n"); + return 1; } } + return 0; } - else { - printf("Usage: %s %s\n", list->name, list->syntax); - } - return(1); + + return -1; } static int @@ -792,40 +849,46 @@ char **argv; if (argc > 0) { parity = ChangeParity(*argv); if (parity < 0) - printf("Invalid parity.\n"); - else + LogPrintf(LogWARN, "Invalid parity.\n"); + else { VarParity = parity; + return 0; + } } - return(1); + + return -1; } static int -SetDebugLevel(list, argc, argv) +SetLogLevel(list, argc, argv) struct cmdtab *list; int argc; char **argv; { - int level, w; + int i; + int res; + char *arg; - for (level = 0; argc-- > 0; argv++) { - if (isdigit(**argv)) { - w = atoi(*argv); - if (w < 0 || w >= MAXLOGLEVEL) { - printf("invalid log level.\n"); + res = 0; + if (argc == 0 || (argv[0][0] != '+' && argv[0][0] != '-')) + LogDiscardAll(); + while (argc--) { + arg = **argv == '+' || **argv == '-' ? *argv + 1 : *argv; + for (i = LogMIN; i <= LogMAX; i++) + if (strcasecmp(arg, LogName(i)) == 0) { + if (**argv == '-') + LogDiscard(i); + else + LogKeep(i); break; - } else - level |= (1 << w); - } else { - for (w = 0; w < MAXLOGLEVEL; w++) { - if (strcasecmp(*argv, LogLevelName[w]) == 0) { - level |= (1 << w); - continue; - } } + if (i > LogMAX) { + LogPrintf(LogWARN, "%s: Invalid log value\n", arg); + res = -1; } + argv++; } - loglevel = level; - return(1); + return res; } static int @@ -844,7 +907,7 @@ char **argv; EscMap[code >> 3] |= (1 << (code&7)); EscMap[32] = 1; } - return(1); + return 0; } static int @@ -854,19 +917,22 @@ int argc; char **argv; { long mru; + char *err; if (argc > 0) { mru = atol(*argv); if (mru < MIN_MRU) - printf("Given MRU value (%ld) is too small.\n", mru); + err = "Given MRU value (%ld) is too small.\n"; else if (mru > MAX_MRU) - printf("Given MRU value (%ld) is too big.\n", mru); - else + err = "Given MRU value (%ld) is too big.\n"; + else { VarMRU = mru; - } else - printf("Usage: %s %s\n", list->name, list->syntax); + return 0; + } + LogPrintf(LogWARN, err, mru); + } - return(1); + return -1; } static int @@ -876,21 +942,25 @@ int argc; char **argv; { long mtu; + char *err; if (argc > 0) { mtu = atol(*argv); - if (mtu == 0) + if (mtu == 0) { VarPrefMTU = 0; - else if (mtu < MIN_MTU) - printf("Given MTU value (%ld) is too small.\n", mtu); + return 0; + } else if (mtu < MIN_MTU) + err = "Given MTU value (%ld) is too small.\n"; else if (mtu > MAX_MTU) - printf("Given MTU value (%ld) is too big.\n", mtu); - else + err = "Given MTU value (%ld) is too big.\n"; + else { VarPrefMTU = mtu; - } else - printf("Usage: %s %s\n", list->name, list->syntax); + return 0; + } + LogPrintf(LogWARN, err, mtu); + } - return(1); + return -1; } static int @@ -901,6 +971,7 @@ char **argv; { if (argc-- > 0) { VarIdleTimeout = atoi(*argv++); + UpdateIdleTimer(); /* If we're connected, restart the idle timer */ if (argc-- > 0) { VarLqrTimeout = atoi(*argv++); if (VarLqrTimeout < 1) @@ -911,8 +982,10 @@ char **argv; VarRetryTimeout = 3; } } + return 0; } - return(1); + + return -1; } struct in_addr @@ -938,22 +1011,21 @@ char **argv; { DefMyAddress.ipaddr.s_addr = DefHisAddress.ipaddr.s_addr = 0L; - if (argc > 4) { - printf("set ifaddr: too many arguments (%d > 4)\n", argc); - return(0); - } + if (argc > 4) + return -1; + if (argc > 0) { if (ParseAddr(argc, argv++, &DefMyAddress.ipaddr, &DefMyAddress.mask, &DefMyAddress.width) == 0) - return(0); + return 1; if (--argc > 0) { if (ParseAddr(argc, argv++, &DefHisAddress.ipaddr, &DefHisAddress.mask, &DefHisAddress.width) == 0) - return(0); + return 2; if (--argc > 0) { ifnetmask = GetIpAddr(*argv); if (--argc > 0) { @@ -961,7 +1033,7 @@ char **argv; &DefTriggerAddress.ipaddr, &DefTriggerAddress.mask, &DefTriggerAddress.width) == 0) - return(0); + return 3; } } } @@ -981,12 +1053,12 @@ char **argv; if ((mode & MODE_AUTO) || ((mode & MODE_DEDICATED) && dstsystem)) { if (OsSetIpaddress(DefMyAddress.ipaddr, DefHisAddress.ipaddr, ifnetmask) < 0) - return(0); + return 4; } - return(1); + return 0; } -#ifdef MSEXT +#ifndef NOMSEXT void SetMSEXT(pri_addr, sec_addr, argc, argv) @@ -1025,7 +1097,7 @@ int argc; char **argv; { SetMSEXT(&ns_entries[0], &ns_entries[1], argc, argv); - return(1); + return 0; } static int @@ -1035,7 +1107,7 @@ int argc; char **argv; { SetMSEXT(&nbns_entries[0], &nbns_entries[1], argc, argv); - return(1); + return 0; } #endif /* MS_EXT */ @@ -1076,6 +1148,7 @@ int param; VarLoginScript[sizeof(VarLoginScript)-1] = '\0'; break; case VAR_DEVICE: + CloseModem(); strncpy(VarDevice, *argv, sizeof(VarDevice)-1); VarDevice[sizeof(VarDevice)-1] = '\0'; VarBaseDevice = rindex(VarDevice, '/'); @@ -1093,7 +1166,7 @@ int param; break; } } - return(1); + return 0; } static int SetCtsRts(list, argc, argv) @@ -1107,9 +1180,10 @@ char **argv; else if (strcmp(*argv, "off") == 0) VarCtsRts = FALSE; else - printf("usage: set ctsrts [on|off].\n"); + return -1; + return 0; } - return(1); + return -1; } @@ -1124,70 +1198,69 @@ char **argv; else if (strcmp(*argv, "passive") == 0) VarOpenMode = OPEN_PASSIVE; else - printf("Invalid mode.\n"); + return -1; + return 0; } - return(1); + return -1; } -static char StrChatStr[] = "chat-script"; -static char StrValue[] = "value"; extern int SetIfilter(), SetOfilter(), SetDfilter(), SetAfilter(); struct cmdtab const SetCommands[] = { { "accmap", NULL, SetVariable, LOCAL_AUTH, - "Set accmap value", "hex-value", (void *)VAR_ACCMAP}, + "Set accmap value", "set accmap hex-value", (void *)VAR_ACCMAP}, { "afilter", NULL, SetAfilter, LOCAL_AUTH, - "Set keep Alive filter", "..."}, + "Set keep Alive filter", "set afilter ..."}, { "authkey", "key", SetVariable, LOCAL_AUTH, - "Set authentication key", "key", (void *)VAR_AUTHKEY}, + "Set authentication key", "set authkey|key key", (void *)VAR_AUTHKEY}, { "authname", NULL, SetVariable, LOCAL_AUTH, - "Set authentication name", "name", (void *)VAR_AUTHNAME}, + "Set authentication name", "set authname name", (void *)VAR_AUTHNAME}, { "ctsrts", NULL, SetCtsRts, LOCAL_AUTH, - "Use CTS/RTS modem signalling", "[on|off]"}, - { "debug", NULL, SetDebugLevel, LOCAL_AUTH, - "Set debug level", StrValue}, + "Use CTS/RTS modem signalling", "set ctsrts [on|off]"}, { "device", "line", SetVariable, LOCAL_AUTH, - "Set modem device name", "device-name", (void *)VAR_DEVICE}, + "Set modem device name", "set device|line device-name", (void *)VAR_DEVICE}, { "dfilter", NULL, SetDfilter, LOCAL_AUTH, - "Set demand filter", "..."}, + "Set demand filter", "set dfilter ..."}, { "dial", NULL, SetVariable, LOCAL_AUTH, - "Set dialing script", StrChatStr, (void *)VAR_DIAL}, + "Set dialing script", "set dial chat-script", (void *)VAR_DIAL}, { "escape", NULL, SetEscape, LOCAL_AUTH, - "Set escape characters", "hex-digit ..."}, + "Set escape characters", "set escape hex-digit ..."}, { "ifaddr", NULL, SetInterfaceAddr, LOCAL_AUTH, - "Set destination address", "[src-addr [dst-addr [netmask [trg-addr]]]]"}, + "Set destination address", "set ifaddr [src-addr [dst-addr [netmask [trg-addr]]]]"}, { "ifilter", NULL, SetIfilter, LOCAL_AUTH, - "Set input filter", "..."}, + "Set input filter", "set ifilter ..."}, + { "log", NULL, SetLogLevel, LOCAL_AUTH, + "Set log level", "set log [+|-]value..."}, { "login", NULL, SetVariable, LOCAL_AUTH, - "Set login script", StrChatStr, (void *)VAR_LOGIN }, + "Set login script", "set login chat-script", (void *)VAR_LOGIN }, { "mru", NULL, SetInitialMRU, LOCAL_AUTH, - "Set Initial MRU value", StrValue }, + "Set Initial MRU value", "set mru value" }, { "mtu", NULL, SetPreferredMTU, LOCAL_AUTH, - "Set Preferred MTU value", StrValue }, + "Set Preferred MTU value", "set mtu value" }, { "ofilter", NULL, SetOfilter, LOCAL_AUTH, - "Set output filter", "..." }, + "Set output filter", "set ofilter ..." }, { "openmode", NULL, SetOpenMode, LOCAL_AUTH, - "Set open mode", "[active|passive]"}, + "Set open mode", "set openmode [active|passive]"}, { "parity", NULL, SetModemParity, LOCAL_AUTH, - "Set modem parity", "[odd|even|none]"}, + "Set modem parity", "set parity [odd|even|none]"}, { "phone", NULL, SetVariable, LOCAL_AUTH, - "Set telephone number(s)", "phone1[:phone2[...]]", (void *)VAR_PHONE }, + "Set telephone number(s)", "set phone phone1[:phone2[...]]", (void *)VAR_PHONE }, { "reconnect",NULL, SetReconnect, LOCAL_AUTH, - "Set Reconnect timeout", "value ntries"}, + "Set Reconnect timeout", "set reconnect value ntries"}, { "redial", NULL, SetRedialTimeout, LOCAL_AUTH, - "Set Redial timeout", "value|random[.value|random] [dial_attempts]"}, + "Set Redial timeout", "set redial value|random[.value|random] [dial_attempts]"}, { "speed", NULL, SetModemSpeed, LOCAL_AUTH, - "Set modem speed", "speed"}, + "Set modem speed", "set speed value"}, { "timeout", NULL, SetIdleTimeout, LOCAL_AUTH, - "Set Idle timeout", StrValue}, -#ifdef MSEXT + "Set Idle timeout", "set timeout value"}, +#ifndef NOMSEXT { "ns", NULL, SetNS, LOCAL_AUTH, - "Set NameServer", "pri-addr [sec-addr]"}, + "Set NameServer", "set ns pri-addr [sec-addr]"}, { "nbns", NULL, SetNBNS, LOCAL_AUTH, - "Set NetBIOS NameServer", "pri-addr [sec-addr]"}, -#endif /* MSEXT */ + "Set NetBIOS NameServer", "set nbns pri-addr [sec-addr]"}, +#endif { "help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH, - "Display this message", StrNull, (void *)SetCommands}, + "Display this message", "set help|?", (void *)SetCommands}, { NULL, NULL, NULL }, }; @@ -1197,13 +1270,15 @@ struct cmdtab *list; int argc; char **argv; { - int val = 1; - if (argc > 0) - val = FindExec(SetCommands, argc, argv); + FindExec(SetCommands, argc, argv); + else if (VarTerm) + fprintf(VarTerm, "Use `set ?' to get a list or `set ? ' for" + " syntax help.\n"); else - printf("Use `set ?' to get a list or `set ? ' for syntax help.\n"); - return(val); + LogPrintf(LogWARN, "set command must have arguments\n"); + + return 0; } @@ -1223,10 +1298,10 @@ char **argv; else gateway = GetIpAddr(argv[2]); OsSetRoute(RTM_ADD, dest, gateway, netmask); - } else { - printf("Usage: %s %s\n", list->name, list->syntax); + return 0; } - return(1); + + return -1; } static int @@ -1245,50 +1320,49 @@ char **argv; gateway = GetIpAddr(argv[1]); netmask.s_addr = 0; if (argc == 3) { - if (inet_aton(argv[1], &netmask) == 0) { - printf("bad netmask value.\n"); - return(1); + if (inet_aton(argv[2], &netmask) == 0) { + LogPrintf(LogWARN, "Bad netmask value.\n"); + return -1; } } OsSetRoute(RTM_DELETE, dest, gateway, netmask); - } else if (argc == 1 && strcasecmp(argv[0], "ALL") == 0) { + } else if (argc == 1 && strcasecmp(argv[0], "all") == 0) { DeleteIfRoutes(0); - } else { - printf("Usage: %s %s\n", list->name, list->syntax); - } - return(1); -} + } else + return -1; + return 0; +} static int AliasEnable(); static int AliasOption(); - static struct cmdtab const AliasCommands[] = { { "enable", NULL, AliasEnable, LOCAL_AUTH, - "enable IP aliasing", "[yes|no]"}, + "enable IP aliasing", "alias enable [yes|no]"}, { "port", NULL, AliasRedirectPort, LOCAL_AUTH, - "port redirection", "[proto addr_local:port_local port_alias]"}, + "port redirection", "alias port [proto addr_local:port_local port_alias]"}, { "addr", NULL, AliasRedirectAddr, LOCAL_AUTH, - "static address translation", "[addr_local addr_alias]"}, + "static address translation", "alias addr [addr_local addr_alias]"}, { "deny_incoming", NULL, AliasOption, LOCAL_AUTH, - "stop incoming connections", "[yes|no]", + "stop incoming connections", "alias deny_incoming [yes|no]", (void*)PKT_ALIAS_DENY_INCOMING}, { "log", NULL, AliasOption, LOCAL_AUTH, - "log aliasing link creation", "[yes|no]", + "log aliasing link creation", "alias log [yes|no]", (void*)PKT_ALIAS_LOG}, { "same_ports", NULL, AliasOption, LOCAL_AUTH, - "try to leave port numbers unchanged", "[yes|no]", + "try to leave port numbers unchanged", "alias same_ports [yes|no]", (void*)PKT_ALIAS_SAME_PORTS}, { "use_sockets", NULL, AliasOption, LOCAL_AUTH, - "allocate host sockets", "[yes|no]", + "allocate host sockets", "alias use_sockets [yes|no]", (void*)PKT_ALIAS_USE_SOCKETS }, { "unregistered_only", NULL, AliasOption, LOCAL_AUTH, - "alias unregistered (private) IP address space only", "[yes|no]", + "alias unregistered (private) IP address space only", + "alias unregistered_only [yes|no]", (void*)PKT_ALIAS_UNREGISTERED_ONLY}, { "help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH, - "Display this message", StrNull, + "Display this message", "alias help|?", (void *)AliasCommands}, { NULL, NULL, NULL }, }; @@ -1300,16 +1374,16 @@ struct cmdtab *list; int argc; char **argv; { - int val = 1; - if (argc > 0) - val = FindExec(AliasCommands, argc, argv); + FindExec(AliasCommands, argc, argv); + else if (VarTerm) + fprintf(VarTerm, "Use `alias help' to get a list or `alias help