1995-01-31 06:29:58 +00:00
|
|
|
/*
|
|
|
|
* PPP User command processing module
|
|
|
|
*
|
|
|
|
* 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, Inc. 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.
|
1995-05-30 03:57:47 +00:00
|
|
|
*
|
1997-05-10 01:22:19 +00:00
|
|
|
* $Id: command.c,v 1.42 1997/05/09 23:34:56 brian Exp $
|
1995-05-30 03:57:47 +00:00
|
|
|
*
|
1995-01-31 06:29:58 +00:00
|
|
|
*/
|
1996-01-10 21:28:04 +00:00
|
|
|
#include <sys/types.h>
|
1995-01-31 06:29:58 +00:00
|
|
|
#include <ctype.h>
|
1995-02-26 12:18:08 +00:00
|
|
|
#include <termios.h>
|
1996-01-11 05:58:59 +00:00
|
|
|
#include <sys/wait.h>
|
1996-01-10 21:28:04 +00:00
|
|
|
#include <time.h>
|
1995-01-31 06:29:58 +00:00
|
|
|
#include "fsm.h"
|
|
|
|
#include "phase.h"
|
|
|
|
#include "lcp.h"
|
|
|
|
#include "ipcp.h"
|
|
|
|
#include "modem.h"
|
1996-01-11 17:48:59 +00:00
|
|
|
#include "filter.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
#include "command.h"
|
|
|
|
#include "hdlc.h"
|
|
|
|
#include "vars.h"
|
1997-05-10 01:22:19 +00:00
|
|
|
#include "systems.h"
|
|
|
|
#include "chat.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
#include <netdb.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
#include "os.h"
|
1995-09-02 17:20:54 +00:00
|
|
|
#include <paths.h>
|
1997-05-07 23:01:25 +00:00
|
|
|
#include "chat.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
extern void Cleanup(), TtyTermMode(), PacketMode();
|
|
|
|
extern int EnableCommand(), DisableCommand(), DisplayCommand();
|
|
|
|
extern int AcceptCommand(), DenyCommand();
|
1995-02-26 12:18:08 +00:00
|
|
|
extern int LocalAuthCommand();
|
1995-01-31 06:29:58 +00:00
|
|
|
extern int LoadCommand(), SaveCommand();
|
|
|
|
extern int ChangeParity(char *);
|
|
|
|
extern int SelectSystem();
|
|
|
|
extern int ShowRoute();
|
1995-09-02 17:20:54 +00:00
|
|
|
extern void TtyOldMode(), TtyCommandMode();
|
1995-02-26 12:18:08 +00:00
|
|
|
extern struct pppvars pppVars;
|
1996-03-08 09:03:09 +00:00
|
|
|
extern struct cmdtab const SetCommands[];
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1997-02-22 09:12:36 +00:00
|
|
|
extern char *IfDevName;
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
struct in_addr ifnetmask;
|
1997-03-10 08:04:15 +00:00
|
|
|
int randinit;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
static int ShowCommand(), TerminalCommand(), QuitCommand();
|
|
|
|
static int CloseCommand(), DialCommand(), DownCommand();
|
|
|
|
static int SetCommand(), AddCommand(), DeleteCommand();
|
1995-09-02 17:20:54 +00:00
|
|
|
static int ShellCommand();
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
HelpCommand(list, argc, argv, plist)
|
|
|
|
struct cmdtab *list;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
struct cmdtab *plist;
|
|
|
|
{
|
|
|
|
struct cmdtab *cmd;
|
|
|
|
int n;
|
|
|
|
char c;
|
|
|
|
|
|
|
|
if (argc > 0) {
|
|
|
|
for (cmd = plist; cmd->name; cmd++) {
|
1997-05-08 01:26:31 +00:00
|
|
|
if (strcasecmp(cmd->name, *argv) == 0 && (cmd->lauth & VarLocalAuth)) {
|
1996-03-08 09:03:09 +00:00
|
|
|
if (plist == SetCommands)
|
|
|
|
printf("set ");
|
1995-01-31 06:29:58 +00:00
|
|
|
printf("%s %s\n", cmd->name, cmd->syntax);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
n = 0;
|
|
|
|
for (cmd = plist; cmd->func; cmd++) {
|
1995-02-27 10:57:54 +00:00
|
|
|
if (cmd->name && (cmd->lauth & VarLocalAuth)) {
|
|
|
|
c = (n & 1)? '\n' : '\t';
|
1995-01-31 06:29:58 +00:00
|
|
|
printf(" %-8s: %-20s%c", cmd->name, cmd->helpmes, c);
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (n & 1)
|
|
|
|
printf("\n");
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
IsInteractive()
|
|
|
|
{
|
|
|
|
char *mes = NULL;
|
|
|
|
|
1996-12-03 21:38:52 +00:00
|
|
|
if (mode & MODE_DDIAL)
|
|
|
|
mes = "Working in dedicated dial mode.";
|
|
|
|
else if (mode & MODE_AUTO)
|
1995-09-02 17:20:54 +00:00
|
|
|
mes = "Working in auto mode.";
|
1995-01-31 06:29:58 +00:00
|
|
|
else if (mode & MODE_DIRECT)
|
1995-09-02 17:20:54 +00:00
|
|
|
mes = "Working in direct mode.";
|
1995-01-31 06:29:58 +00:00
|
|
|
else if (mode & MODE_DEDICATED)
|
1995-09-02 17:20:54 +00:00
|
|
|
mes = "Working in dedicated mode.";
|
1995-01-31 06:29:58 +00:00
|
|
|
if (mes) {
|
|
|
|
printf("%s\n", mes);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
DialCommand(cmdlist, argc, argv)
|
|
|
|
struct cmdtab *cmdlist;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
1995-10-08 14:57:32 +00:00
|
|
|
int tries;
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
if (LcpFsm.state > ST_CLOSED) {
|
|
|
|
printf("LCP state is [%s]\n", StateNames[LcpFsm.state]);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
if (!IsInteractive())
|
|
|
|
return(1);
|
|
|
|
if (argc > 0) {
|
|
|
|
if (SelectSystem(*argv, CONFFILE) < 0) {
|
|
|
|
printf("%s: not found.\n", *argv);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
}
|
1995-10-08 14:57:32 +00:00
|
|
|
tries = 0;
|
|
|
|
do {
|
|
|
|
printf("Dial attempt %u\n", ++tries);
|
|
|
|
modem = OpenModem(mode);
|
|
|
|
if (modem < 0) {
|
|
|
|
printf("failed to open modem.\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (DialModem()) {
|
|
|
|
sleep(1);
|
|
|
|
ModemTimeout();
|
|
|
|
PacketMode();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (VarDialTries == 0 || tries < VarDialTries);
|
1995-01-31 06:29:58 +00:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
1995-09-02 17:20:54 +00:00
|
|
|
static int
|
|
|
|
ShellCommand(cmdlist, argc, argv)
|
|
|
|
struct cmdtab *cmdlist;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
const char *shell;
|
|
|
|
pid_t shpid;
|
1996-12-22 17:29:33 +00:00
|
|
|
|
1995-09-02 17:20:54 +00:00
|
|
|
if((shell = getenv("SHELL")) == 0) {
|
|
|
|
shell = _PATH_BSHELL;
|
|
|
|
}
|
1996-10-10 11:27:35 +00:00
|
|
|
#ifdef SHELL_ONLY_INTERACTIVELY
|
1995-09-02 17:20:54 +00:00
|
|
|
#ifndef HAVE_SHELL_CMD_WITH_ANY_MODE
|
|
|
|
if( mode != MODE_INTER) {
|
|
|
|
fprintf(stdout,
|
1996-10-13 15:05:14 +00:00
|
|
|
"Can only start a shell in interactive mode\n");
|
1995-09-02 17:20:54 +00:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if(argc == 0 && !(mode & MODE_INTER)) {
|
|
|
|
fprintf(stderr,
|
1996-10-13 15:05:14 +00:00
|
|
|
"Can only start an interactive shell in interactive mode\n");
|
1995-09-02 17:20:54 +00:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_SHELL_CMD_WITH_ANY_MODE */
|
1996-10-13 15:05:14 +00:00
|
|
|
#else
|
|
|
|
if ((mode & (MODE_AUTO|MODE_INTER)) == (MODE_AUTO|MODE_INTER)) {
|
|
|
|
fprintf(stdout,
|
|
|
|
"Shell is not allowed interactively in auto mode\n");
|
|
|
|
return(1);
|
|
|
|
}
|
1996-10-10 11:27:35 +00:00
|
|
|
#endif /* SHELL_ONLY_INTERACTIVELY */
|
1995-09-02 17:20:54 +00:00
|
|
|
if((shpid = fork()) == 0) {
|
1996-09-28 11:25:47 +00:00
|
|
|
int dtablesize, i ;
|
|
|
|
|
|
|
|
for (dtablesize = getdtablesize(), i = 3; i < dtablesize; i++)
|
1995-09-02 17:20:54 +00:00
|
|
|
(void)close(i);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We are running setuid, we should change to
|
|
|
|
* real user for avoiding security problems.
|
|
|
|
*/
|
1996-06-09 20:40:58 +00:00
|
|
|
if (setgid(getgid()) < 0) {
|
|
|
|
perror("setgid");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (setuid(getuid()) < 0) {
|
|
|
|
perror("setuid");
|
|
|
|
exit(1);
|
|
|
|
}
|
1995-09-02 17:20:54 +00:00
|
|
|
TtyOldMode();
|
1996-10-07 10:01:17 +00:00
|
|
|
if(argc > 0) {
|
|
|
|
/* substitute pseudo args */
|
|
|
|
for (i=1; i<argc; i++) {
|
1997-05-08 01:26:31 +00:00
|
|
|
if (strcasecmp(argv[i], "HISADDR") == 0) {
|
1996-10-07 10:01:17 +00:00
|
|
|
argv[i] = strdup(inet_ntoa(IpcpInfo.his_ipaddr));
|
|
|
|
}
|
1997-05-08 01:26:31 +00:00
|
|
|
if (strcasecmp(argv[i], "INTERFACE") == 0) {
|
1997-02-22 09:12:36 +00:00
|
|
|
argv[i] = strdup(IfDevName);
|
|
|
|
}
|
1997-05-08 01:26:31 +00:00
|
|
|
if (strcasecmp(argv[i], "MYADDR") == 0) {
|
1996-10-07 10:01:17 +00:00
|
|
|
argv[i] = strdup(inet_ntoa(IpcpInfo.want_ipaddr));
|
|
|
|
}
|
|
|
|
}
|
1997-05-10 01:22:19 +00:00
|
|
|
(void)execvp(argv[0], argv);
|
1996-10-07 10:01:17 +00:00
|
|
|
}
|
1995-09-02 17:20:54 +00:00
|
|
|
else
|
1997-05-10 01:22:19 +00:00
|
|
|
(void)execl(shell, shell, NULL);
|
1996-12-22 17:29:33 +00:00
|
|
|
|
1995-09-02 17:20:54 +00:00
|
|
|
fprintf(stdout, "exec() of %s failed\n", argc > 0? argv[0]: shell);
|
|
|
|
exit(255);
|
|
|
|
}
|
|
|
|
if( shpid == (pid_t)-1 ) {
|
|
|
|
fprintf(stdout, "Fork failed\n");
|
|
|
|
} else {
|
|
|
|
int status;
|
|
|
|
(void)waitpid(shpid, &status, 0);
|
|
|
|
}
|
1996-12-22 17:29:33 +00:00
|
|
|
|
1995-09-02 17:20:54 +00:00
|
|
|
TtyCommandMode(1);
|
1996-12-22 17:29:33 +00:00
|
|
|
|
1995-09-02 17:20:54 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
static char StrOption[] = "option ..";
|
|
|
|
static char StrRemote[] = "[remote]";
|
|
|
|
char StrNull[] = "";
|
|
|
|
|
1996-01-30 20:04:34 +00:00
|
|
|
struct cmdtab const Commands[] = {
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "accept", NULL, AcceptCommand, LOCAL_AUTH,
|
|
|
|
"accept option request", StrOption},
|
|
|
|
{ "add", NULL, AddCommand, LOCAL_AUTH,
|
|
|
|
"add route", "dest mask gateway"},
|
|
|
|
{ "close", NULL, CloseCommand, LOCAL_AUTH,
|
|
|
|
"Close connection", StrNull},
|
|
|
|
{ "delete", NULL, DeleteCommand, LOCAL_AUTH,
|
1996-03-08 09:03:09 +00:00
|
|
|
"delete route", "ALL | dest gateway [mask]"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "deny", NULL, DenyCommand, LOCAL_AUTH,
|
|
|
|
"Deny option request", StrOption},
|
|
|
|
{ "dial", "call", DialCommand, LOCAL_AUTH,
|
|
|
|
"Dial and login", StrRemote},
|
|
|
|
{ "disable", NULL, DisableCommand, LOCAL_AUTH,
|
|
|
|
"Disable option", StrOption},
|
|
|
|
{ "display", NULL, DisplayCommand, LOCAL_AUTH,
|
|
|
|
"Display option configs", StrNull},
|
|
|
|
{ "enable", NULL, EnableCommand, LOCAL_AUTH,
|
|
|
|
"Enable option", StrOption},
|
1995-02-27 10:57:54 +00:00
|
|
|
{ "passwd", NULL, LocalAuthCommand,LOCAL_NO_AUTH,
|
1995-06-16 07:07:56 +00:00
|
|
|
"Password for manipulation", StrOption},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "load", NULL, LoadCommand, LOCAL_AUTH,
|
|
|
|
"Load settings", StrRemote},
|
|
|
|
{ "save", NULL, SaveCommand, LOCAL_AUTH,
|
|
|
|
"Save settings", StrNull},
|
|
|
|
{ "set", "setup", SetCommand, LOCAL_AUTH,
|
|
|
|
"Set parameters", "var value"},
|
1995-09-02 17:20:54 +00:00
|
|
|
{ "shell", "!", ShellCommand, LOCAL_AUTH,
|
|
|
|
"Run a subshell", "[sh command]"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "show", NULL, ShowCommand, LOCAL_AUTH,
|
|
|
|
"Show status and statictics", "var"},
|
|
|
|
{ "term", NULL, TerminalCommand,LOCAL_AUTH,
|
|
|
|
"Enter to terminal mode", StrNull},
|
1995-02-27 10:57:54 +00:00
|
|
|
{ "quit", "bye", QuitCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
|
1996-03-08 09:03:09 +00:00
|
|
|
"Quit PPP program", "[all]"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
|
1995-01-31 06:29:58 +00:00
|
|
|
"Display this message", "[command]", (void *)Commands },
|
1995-02-26 12:18:08 +00:00
|
|
|
{ NULL, "down", DownCommand, LOCAL_AUTH,
|
|
|
|
"Generate down event", StrNull},
|
1995-01-31 06:29:58 +00:00
|
|
|
{ NULL, NULL, NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
extern int ReportCcpStatus();
|
|
|
|
extern int ReportLcpStatus();
|
|
|
|
extern int ReportIpcpStatus();
|
|
|
|
extern int ReportProtStatus();
|
|
|
|
extern int ReportCompress();
|
|
|
|
extern int ShowModemStatus();
|
|
|
|
extern int ReportHdlcStatus();
|
|
|
|
extern int ShowMemMap();
|
|
|
|
|
|
|
|
static char *LogLevelName[] = {
|
1996-05-11 20:48:42 +00:00
|
|
|
LM_PHASE, LM_CHAT, LM_LQM, LM_LCP,
|
|
|
|
LM_TCPIP, LM_HDLC, LM_ASYNC, LM_LINK,
|
|
|
|
LM_CONNECT, LM_CARRIER,
|
1995-01-31 06:29:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int ShowDebugLevel()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
printf("%02x: ", loglevel);
|
|
|
|
for (i = LOG_PHASE; i < MAXLOGLEVEL; i++) {
|
|
|
|
if (loglevel & (1 << i))
|
|
|
|
printf("%s ", LogLevelName[i]);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ShowEscape()
|
|
|
|
{
|
|
|
|
int code, bit;
|
|
|
|
|
|
|
|
if (EscMap[32]) {
|
|
|
|
for (code = 0; code < 32; code++) {
|
|
|
|
if (EscMap[code]) {
|
|
|
|
for (bit = 0; bit < 8; bit++) {
|
|
|
|
if (EscMap[code] & (1<<bit)) {
|
|
|
|
printf(" 0x%02x", (code << 3) + bit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ShowTimeout()
|
|
|
|
{
|
1995-02-26 12:18:08 +00:00
|
|
|
printf(" Idle Timer: %d secs LQR Timer: %d secs Retry Timer: %d secs\n",
|
|
|
|
VarIdleTimeout, VarLqrTimeout, VarRetryTimeout);
|
1995-01-31 06:29:58 +00:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ShowAuthKey()
|
|
|
|
{
|
|
|
|
printf("AuthName = %s\n", VarAuthName);
|
|
|
|
printf("AuthKey = %s\n", VarAuthKey);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ShowVersion()
|
|
|
|
{
|
1996-01-11 17:48:59 +00:00
|
|
|
extern char VarVersion[];
|
|
|
|
extern char VarLocalVersion[];
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1995-07-08 17:46:56 +00:00
|
|
|
printf("%s - %s \n", VarVersion, VarLocalVersion);
|
1995-01-31 06:29:58 +00:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ShowLogList()
|
|
|
|
{
|
|
|
|
ListLog();
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
1997-04-21 01:02:02 +00:00
|
|
|
static int ShowReconnect()
|
|
|
|
{
|
|
|
|
printf(" Reconnect Timer: %d, %d tries\n",
|
|
|
|
VarReconnectTimer, VarReconnectTries);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
1995-10-08 14:57:32 +00:00
|
|
|
static int ShowRedial()
|
|
|
|
{
|
|
|
|
printf(" Redial Timer: ");
|
|
|
|
|
|
|
|
if (VarRedialTimeout >= 0) {
|
|
|
|
printf(" %d seconds, ", VarRedialTimeout);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf(" Random 0 - %d seconds, ", REDIAL_PERIOD);
|
|
|
|
}
|
|
|
|
|
1997-04-14 23:48:20 +00:00
|
|
|
printf(" Redial Next Timer: ");
|
|
|
|
|
|
|
|
if (VarRedialNextTimeout >= 0) {
|
|
|
|
printf(" %d seconds, ", VarRedialNextTimeout);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf(" Random 0 - %d seconds, ", REDIAL_PERIOD);
|
|
|
|
}
|
|
|
|
|
1995-10-08 14:57:32 +00:00
|
|
|
if (VarDialTries)
|
|
|
|
printf("%d dial tries", VarDialTries);
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
1996-10-06 13:32:37 +00:00
|
|
|
#ifdef MSEXT
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
#endif /* MSEXT */
|
1995-10-08 14:57:32 +00:00
|
|
|
|
1995-02-26 12:18:08 +00:00
|
|
|
extern int ShowIfilter(), ShowOfilter(), ShowDfilter(), ShowAfilter();
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1996-01-30 20:04:34 +00:00
|
|
|
struct cmdtab const ShowCommands[] = {
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "afilter", NULL, ShowAfilter, LOCAL_AUTH,
|
|
|
|
"Show keep Alive filters", StrOption},
|
|
|
|
{ "auth", NULL, ShowAuthKey, LOCAL_AUTH,
|
|
|
|
"Show auth name/key", StrNull},
|
|
|
|
{ "ccp", NULL, ReportCcpStatus, LOCAL_AUTH,
|
|
|
|
"Show CCP status", StrNull},
|
|
|
|
{ "compress", NULL, ReportCompress, LOCAL_AUTH,
|
|
|
|
"Show compression statictics", StrNull},
|
|
|
|
{ "debug", NULL, ShowDebugLevel, LOCAL_AUTH,
|
|
|
|
"Show current debug level", StrNull},
|
|
|
|
{ "dfilter", NULL, ShowDfilter, LOCAL_AUTH,
|
|
|
|
"Show Demand filters", StrOption},
|
|
|
|
{ "escape", NULL, ShowEscape, LOCAL_AUTH,
|
|
|
|
"Show escape characters", StrNull},
|
|
|
|
{ "hdlc", NULL, ReportHdlcStatus, LOCAL_AUTH,
|
|
|
|
"Show HDLC error summary", StrNull},
|
|
|
|
{ "ifilter", NULL, ShowIfilter, LOCAL_AUTH,
|
|
|
|
"Show Input filters", StrOption},
|
|
|
|
{ "ipcp", NULL, ReportIpcpStatus, LOCAL_AUTH,
|
|
|
|
"Show IPCP status", StrNull},
|
|
|
|
{ "lcp", NULL, ReportLcpStatus, LOCAL_AUTH,
|
|
|
|
"Show LCP status", StrNull},
|
|
|
|
{ "log", NULL, ShowLogList, LOCAL_AUTH,
|
|
|
|
"Show log records", StrNull},
|
|
|
|
{ "mem", NULL, ShowMemMap, LOCAL_AUTH,
|
|
|
|
"Show memory map", StrNull},
|
|
|
|
{ "modem", NULL, ShowModemStatus, LOCAL_AUTH,
|
|
|
|
"Show modem setups", StrNull},
|
|
|
|
{ "ofilter", NULL, ShowOfilter, LOCAL_AUTH,
|
|
|
|
"Show Output filters", StrOption},
|
|
|
|
{ "proto", NULL, ReportProtStatus, LOCAL_AUTH,
|
|
|
|
"Show protocol summary", StrNull},
|
1997-04-21 01:02:02 +00:00
|
|
|
{ "reconnect",NULL, ShowReconnect, LOCAL_AUTH,
|
|
|
|
"Show Reconnect timer ntries", StrNull},
|
|
|
|
{ "redial", NULL, ShowRedial, LOCAL_AUTH,
|
|
|
|
"Show Redial timeout value", StrNull},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "route", NULL, ShowRoute, LOCAL_AUTH,
|
|
|
|
"Show routing table", StrNull},
|
|
|
|
{ "timeout", NULL, ShowTimeout, LOCAL_AUTH,
|
|
|
|
"Show Idle timeout value", StrNull},
|
1996-10-06 13:32:37 +00:00
|
|
|
#ifdef MSEXT
|
|
|
|
{ "msext", NULL, ShowMSExt, LOCAL_AUTH,
|
1997-03-10 06:21:02 +00:00
|
|
|
"Show MS PPP extentions", StrNull},
|
1996-10-06 13:32:37 +00:00
|
|
|
#endif /* MSEXT */
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "version", NULL, ShowVersion, LOCAL_NO_AUTH | LOCAL_AUTH,
|
|
|
|
"Show version string", StrNull},
|
|
|
|
{ "help", "?", HelpCommand, LOCAL_NO_AUTH | LOCAL_AUTH,
|
|
|
|
"Display this message", StrNull, (void *)ShowCommands},
|
1995-01-31 06:29:58 +00:00
|
|
|
{ NULL, NULL, NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cmdtab *
|
|
|
|
FindCommand(cmds, str, pmatch)
|
|
|
|
struct cmdtab *cmds;
|
|
|
|
char *str;
|
|
|
|
int *pmatch;
|
|
|
|
{
|
|
|
|
int nmatch = 0;
|
|
|
|
int len = strlen(str);
|
|
|
|
struct cmdtab *found = NULL;
|
|
|
|
|
|
|
|
while (cmds->func) {
|
1997-05-08 01:26:31 +00:00
|
|
|
if (cmds->name && strncasecmp(str, cmds->name, len) == 0) {
|
1995-01-31 06:29:58 +00:00
|
|
|
nmatch++;
|
|
|
|
found = cmds;
|
1997-05-08 01:26:31 +00:00
|
|
|
} else if (cmds->alias && strncasecmp(str, cmds->alias, len) == 0) {
|
1995-01-31 06:29:58 +00:00
|
|
|
nmatch++;
|
|
|
|
found = cmds;
|
|
|
|
}
|
|
|
|
cmds++;
|
|
|
|
}
|
|
|
|
*pmatch = nmatch;
|
|
|
|
return(found);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
FindExec(cmdlist, argc, argv)
|
|
|
|
struct cmdtab *cmdlist;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
struct cmdtab *cmd;
|
|
|
|
int val = 1;
|
|
|
|
int nmatch;
|
|
|
|
|
|
|
|
cmd = FindCommand(cmdlist, *argv, &nmatch);
|
|
|
|
if (nmatch > 1)
|
1995-02-26 12:18:08 +00:00
|
|
|
printf("Ambiguous.\n");
|
|
|
|
else if (cmd && ( cmd->lauth & VarLocalAuth ) )
|
1995-01-31 06:29:58 +00:00
|
|
|
val = (cmd->func)(cmd, --argc, ++argv, cmd->args);
|
|
|
|
else
|
|
|
|
printf("what?\n");
|
|
|
|
return(val);
|
|
|
|
}
|
|
|
|
|
1996-10-12 16:20:34 +00:00
|
|
|
int aft_cmd = 1;
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
void
|
1996-10-12 16:20:34 +00:00
|
|
|
Prompt()
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1995-02-26 12:18:08 +00:00
|
|
|
char *pconnect, *pauth;
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
if (!(mode & MODE_INTER))
|
|
|
|
return;
|
1995-02-26 12:18:08 +00:00
|
|
|
|
1996-10-12 16:20:34 +00:00
|
|
|
if (!aft_cmd)
|
|
|
|
printf("\n");
|
|
|
|
else
|
|
|
|
aft_cmd = 0;
|
1995-02-26 12:18:08 +00:00
|
|
|
|
|
|
|
if ( VarLocalAuth == LOCAL_AUTH )
|
|
|
|
pauth = " ON ";
|
|
|
|
else
|
|
|
|
pauth = " on ";
|
1995-01-31 06:29:58 +00:00
|
|
|
if (IpcpFsm.state == ST_OPENED && phase == PHASE_NETWORK)
|
1995-02-26 12:18:08 +00:00
|
|
|
pconnect = "PPP";
|
1995-01-31 06:29:58 +00:00
|
|
|
else
|
1995-02-26 12:18:08 +00:00
|
|
|
pconnect = "ppp";
|
|
|
|
printf("%s%s%s> ", pconnect, pauth, VarShortHost);
|
1995-01-31 06:29:58 +00:00
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DecodeCommand(buff, nb, prompt)
|
|
|
|
char *buff;
|
|
|
|
int nb;
|
|
|
|
int prompt;
|
|
|
|
{
|
|
|
|
char *vector[20];
|
|
|
|
char **argv;
|
|
|
|
int argc, val;
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
val = 1;
|
|
|
|
if (nb > 0) {
|
|
|
|
cp = buff + strcspn(buff, "\r\n");
|
|
|
|
if (cp)
|
|
|
|
*cp = '\0';
|
|
|
|
{
|
1997-05-07 23:01:25 +00:00
|
|
|
argc = MakeArgs(buff, vector, VECSIZE(vector));
|
1995-01-31 06:29:58 +00:00
|
|
|
argv = vector;
|
|
|
|
|
|
|
|
if (argc > 0)
|
|
|
|
val = FindExec(Commands, argc, argv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (val && prompt)
|
1997-05-10 01:22:19 +00:00
|
|
|
Prompt();
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ShowCommand(list, argc, argv)
|
|
|
|
struct cmdtab *list;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
int val = 1;
|
|
|
|
|
|
|
|
if (argc > 0)
|
|
|
|
val = FindExec(ShowCommands, argc, argv);
|
|
|
|
else
|
|
|
|
printf("Use ``show ?'' to get a list.\n");
|
|
|
|
return(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
TerminalCommand()
|
|
|
|
{
|
|
|
|
if (LcpFsm.state > ST_CLOSED) {
|
|
|
|
printf("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");
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
printf("Enter to terminal mode.\n");
|
|
|
|
printf("Type `~?' for help.\n");
|
|
|
|
TtyTermMode();
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
QuitCommand(list, argc, argv)
|
|
|
|
struct cmdtab *list;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
if (mode & (MODE_DIRECT|MODE_DEDICATED|MODE_AUTO)) {
|
1995-02-27 10:57:54 +00:00
|
|
|
if (argc > 0 && (VarLocalAuth & LOCAL_AUTH)) {
|
1995-01-31 06:29:58 +00:00
|
|
|
Cleanup(EX_NORMAL);
|
1996-10-13 15:05:14 +00:00
|
|
|
mode &= ~MODE_INTER;
|
1995-01-31 06:29:58 +00:00
|
|
|
} else {
|
1997-04-09 17:35:54 +00:00
|
|
|
LogPrintf(LOG_PHASE_BIT, "client connection closed.\n");
|
1995-02-26 12:18:08 +00:00
|
|
|
VarLocalAuth = LOCAL_NO_AUTH;
|
1995-01-31 06:29:58 +00:00
|
|
|
close(netfd);
|
|
|
|
close(1);
|
1995-04-16 13:38:39 +00:00
|
|
|
dup2(2, 1); /* Have to have something here or the modem will be 1 */
|
1995-01-31 06:29:58 +00:00
|
|
|
netfd = -1;
|
|
|
|
mode &= ~MODE_INTER;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
Cleanup(EX_NORMAL);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
CloseCommand()
|
|
|
|
{
|
|
|
|
LcpClose();
|
1997-05-09 23:34:56 +00:00
|
|
|
lostCarrier = 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
DownCommand()
|
|
|
|
{
|
|
|
|
LcpDown();
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
1997-04-21 01:02:02 +00:00
|
|
|
static int
|
|
|
|
SetModemSpeed(list, argc, argv)
|
1995-01-31 06:29:58 +00:00
|
|
|
struct cmdtab *list;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
int speed;
|
|
|
|
|
|
|
|
if (argc > 0) {
|
1995-02-26 12:18:08 +00:00
|
|
|
if (strcmp(*argv, "sync") == 0) {
|
|
|
|
VarSpeed = 0;
|
|
|
|
return(1);
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
speed = atoi(*argv);
|
1995-02-26 12:18:08 +00:00
|
|
|
if (IntToSpeed(speed) != B0) {
|
|
|
|
VarSpeed = speed;
|
|
|
|
return(1);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
printf("invalid speed.\n");
|
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
1997-04-21 01:02:02 +00:00
|
|
|
static int
|
|
|
|
SetReconnect(list, argc, argv)
|
|
|
|
struct cmdtab *list;
|
|
|
|
int argc;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetRedialTimeout(list, argc, argv)
|
1995-10-08 14:57:32 +00:00
|
|
|
struct cmdtab *list;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
int timeout;
|
|
|
|
int tries;
|
1997-04-14 23:48:20 +00:00
|
|
|
char *dot;
|
1995-10-08 14:57:32 +00:00
|
|
|
|
|
|
|
if (argc == 1 || argc == 2 ) {
|
1997-04-14 23:48:20 +00:00
|
|
|
if (strncasecmp(argv[0], "random", 6) == 0 &&
|
|
|
|
(argv[0][6] == '\0' || argv[0][6] == '.')) {
|
1995-10-08 14:57:32 +00:00
|
|
|
VarRedialTimeout = -1;
|
|
|
|
printf("Using random redial timeout.\n");
|
1997-03-10 08:04:15 +00:00
|
|
|
if (!randinit) {
|
|
|
|
randinit = 1;
|
1997-03-24 16:01:46 +00:00
|
|
|
if (srandomdev() < 0)
|
|
|
|
srandom((unsigned long)(time(NULL) ^ getpid()));
|
1997-03-10 08:04:15 +00:00
|
|
|
}
|
1995-10-08 14:57:32 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
timeout = atoi(argv[0]);
|
|
|
|
|
|
|
|
if (timeout >= 0) {
|
|
|
|
VarRedialTimeout = timeout;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("invalid redial timeout\n");
|
|
|
|
printf("Usage: %s %s\n", list->name, list->syntax);
|
|
|
|
}
|
|
|
|
}
|
1997-04-14 23:48:20 +00:00
|
|
|
|
|
|
|
dot = index(argv[0],'.');
|
|
|
|
if (dot) {
|
|
|
|
if (strcasecmp(++dot, "random") == 0) {
|
|
|
|
VarRedialNextTimeout = -1;
|
|
|
|
printf("Using random next redial timeout.\n");
|
|
|
|
if (!randinit) {
|
|
|
|
randinit = 1;
|
|
|
|
if (srandomdev() < 0)
|
|
|
|
srandom((unsigned long)(time(NULL) ^ getpid()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
timeout = atoi(dot);
|
|
|
|
if (timeout >= 0) {
|
|
|
|
VarRedialNextTimeout = timeout;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("invalid next redial timeout\n");
|
|
|
|
printf("Usage: %s %s\n", list->name, list->syntax);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
VarRedialNextTimeout = NEXT_REDIAL_PERIOD; /* Default next timeout */
|
|
|
|
|
1995-10-08 14:57:32 +00:00
|
|
|
if (argc == 2) {
|
|
|
|
tries = atoi(argv[1]);
|
|
|
|
|
|
|
|
if (tries >= 0) {
|
|
|
|
VarDialTries = tries;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("invalid retry value\n");
|
|
|
|
printf("Usage: %s %s\n", list->name, list->syntax);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("Usage: %s %s\n", list->name, list->syntax);
|
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
1997-04-21 01:02:02 +00:00
|
|
|
static int
|
|
|
|
SetModemParity(list, argc, argv)
|
1995-01-31 06:29:58 +00:00
|
|
|
struct cmdtab *list;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
int parity;
|
|
|
|
|
|
|
|
if (argc > 0) {
|
|
|
|
parity = ChangeParity(*argv);
|
|
|
|
if (parity < 0)
|
|
|
|
printf("Invalid parity.\n");
|
|
|
|
else
|
|
|
|
VarParity = parity;
|
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetDebugLevel(list, argc, argv)
|
|
|
|
struct cmdtab *list;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
int level, w;
|
|
|
|
|
|
|
|
for (level = 0; argc-- > 0; argv++) {
|
|
|
|
if (isdigit(**argv)) {
|
|
|
|
w = atoi(*argv);
|
|
|
|
if (w < 0 || w >= MAXLOGLEVEL) {
|
|
|
|
printf("invalid log level.\n");
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
level |= (1 << w);
|
|
|
|
} else {
|
|
|
|
for (w = 0; w < MAXLOGLEVEL; w++) {
|
|
|
|
if (strcasecmp(*argv, LogLevelName[w]) == 0) {
|
|
|
|
level |= (1 << w);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
loglevel = level;
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetEscape(list, argc, argv)
|
|
|
|
struct cmdtab *list;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
int code;
|
|
|
|
|
|
|
|
for (code = 0; code < 33; code++)
|
|
|
|
EscMap[code] = 0;
|
|
|
|
while (argc-- > 0) {
|
|
|
|
sscanf(*argv++, "%x", &code);
|
|
|
|
code &= 0xff;
|
|
|
|
EscMap[code >> 3] |= (1 << (code&7));
|
|
|
|
EscMap[32] = 1;
|
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetInitialMRU(list, argc, argv)
|
|
|
|
struct cmdtab *list;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
int mru;
|
|
|
|
|
|
|
|
if (argc > 0) {
|
|
|
|
mru = atoi(*argv);
|
|
|
|
if (mru < 100)
|
|
|
|
printf("given value is too small.\n");
|
|
|
|
else if (mru > MAX_MRU)
|
|
|
|
printf("given value is too big.\n");
|
|
|
|
else
|
|
|
|
VarMRU = mru;
|
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetIdleTimeout(list, argc, argv)
|
|
|
|
struct cmdtab *list;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
if (argc-- > 0) {
|
|
|
|
VarIdleTimeout = atoi(*argv++);
|
1995-02-26 12:18:08 +00:00
|
|
|
if (argc-- > 0) {
|
|
|
|
VarLqrTimeout = atoi(*argv++);
|
|
|
|
if (VarLqrTimeout < 1)
|
|
|
|
VarLqrTimeout = 30;
|
|
|
|
if (argc > 0) {
|
|
|
|
VarRetryTimeout = atoi(*argv);
|
|
|
|
if (VarRetryTimeout < 1 || VarRetryTimeout > 10)
|
|
|
|
VarRetryTimeout = 3;
|
|
|
|
}
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct in_addr
|
|
|
|
GetIpAddr(cp)
|
|
|
|
char *cp;
|
|
|
|
{
|
|
|
|
struct hostent *hp;
|
|
|
|
struct in_addr ipaddr;
|
|
|
|
|
|
|
|
hp = gethostbyname(cp);
|
|
|
|
if (hp && hp->h_addrtype == AF_INET)
|
|
|
|
bcopy(hp->h_addr, &ipaddr, hp->h_length);
|
|
|
|
else if (inet_aton(cp, &ipaddr) == 0)
|
|
|
|
ipaddr.s_addr = 0;
|
|
|
|
return(ipaddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetInterfaceAddr(list, argc, argv)
|
|
|
|
struct cmdtab *list;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
|
|
|
|
DefMyAddress.ipaddr.s_addr = DefHisAddress.ipaddr.s_addr = 0L;
|
1997-05-10 01:22:19 +00:00
|
|
|
if (argc > 4) {
|
|
|
|
printf("set ifaddr: too many arguments (%d > 4)\n", argc);
|
|
|
|
return(0);
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
if (argc > 0) {
|
1997-05-10 01:22:19 +00:00
|
|
|
if (ParseAddr(argc, argv++,
|
|
|
|
&DefMyAddress.ipaddr,
|
|
|
|
&DefMyAddress.mask,
|
|
|
|
&DefMyAddress.width) == 0)
|
|
|
|
return(0);
|
1995-01-31 06:29:58 +00:00
|
|
|
if (--argc > 0) {
|
1997-05-10 01:22:19 +00:00
|
|
|
if (ParseAddr(argc, argv++,
|
|
|
|
&DefHisAddress.ipaddr,
|
|
|
|
&DefHisAddress.mask,
|
|
|
|
&DefHisAddress.width) == 0)
|
|
|
|
return(0);
|
1995-01-31 06:29:58 +00:00
|
|
|
if (--argc > 0) {
|
|
|
|
ifnetmask = GetIpAddr(*argv);
|
1995-07-08 08:28:10 +00:00
|
|
|
if (--argc > 0) {
|
1997-05-10 01:22:19 +00:00
|
|
|
if (ParseAddr(argc, argv++,
|
|
|
|
&DefTriggerAddress.ipaddr,
|
|
|
|
&DefTriggerAddress.mask,
|
|
|
|
&DefTriggerAddress.width) == 0)
|
|
|
|
return(0);
|
1995-07-08 08:28:10 +00:00
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* For backwards compatibility, 0.0.0.0 means any address.
|
|
|
|
*/
|
|
|
|
if (DefMyAddress.ipaddr.s_addr == 0) {
|
|
|
|
DefMyAddress.mask.s_addr = 0;
|
|
|
|
DefMyAddress.width = 0;
|
|
|
|
}
|
|
|
|
if (DefHisAddress.ipaddr.s_addr == 0) {
|
|
|
|
DefHisAddress.mask.s_addr = 0;
|
|
|
|
DefHisAddress.width = 0;
|
|
|
|
}
|
|
|
|
|
1995-02-26 12:18:08 +00:00
|
|
|
if ((mode & MODE_AUTO) ||
|
1995-01-31 06:29:58 +00:00
|
|
|
((mode & MODE_DEDICATED) && dstsystem)) {
|
1997-05-10 01:22:19 +00:00
|
|
|
if (OsSetIpaddress(DefMyAddress.ipaddr, DefHisAddress.ipaddr, ifnetmask) < 0)
|
|
|
|
return(0);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
1996-10-06 13:32:37 +00:00
|
|
|
#ifdef MSEXT
|
|
|
|
|
|
|
|
void
|
|
|
|
SetMSEXT(pri_addr, sec_addr, argc, argv)
|
|
|
|
struct in_addr *pri_addr;
|
|
|
|
struct in_addr *sec_addr;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
int dummyint;
|
|
|
|
struct in_addr dummyaddr;
|
|
|
|
|
|
|
|
pri_addr->s_addr = sec_addr->s_addr = 0L;
|
|
|
|
|
|
|
|
if( argc > 0 ) {
|
|
|
|
ParseAddr(argc, argv++, pri_addr, &dummyaddr, &dummyint);
|
|
|
|
if( --argc > 0 )
|
|
|
|
ParseAddr(argc, argv++, sec_addr, &dummyaddr, &dummyint);
|
|
|
|
else
|
|
|
|
sec_addr->s_addr = pri_addr->s_addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if the primary/secondary ns entries are 0.0.0.0 we should
|
|
|
|
* set them to either the localhost's ip, or the values in
|
|
|
|
* /etc/resolv.conf ??
|
|
|
|
*
|
|
|
|
* up to you if you want to implement this...
|
|
|
|
*/
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetNS(list, argc, argv)
|
|
|
|
struct cmdtab *list;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
SetMSEXT(&ns_entries[0], &ns_entries[1], argc, argv);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetNBNS(list, argc, argv)
|
|
|
|
struct cmdtab *list;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
SetMSEXT(&nbns_entries[0], &nbns_entries[1], argc, argv);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* MS_EXT */
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
#define VAR_AUTHKEY 0
|
|
|
|
#define VAR_DIAL 1
|
|
|
|
#define VAR_LOGIN 2
|
|
|
|
#define VAR_AUTHNAME 3
|
|
|
|
#define VAR_DEVICE 4
|
|
|
|
#define VAR_ACCMAP 5
|
|
|
|
#define VAR_PHONE 6
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetVariable(list, argc, argv, param)
|
|
|
|
struct cmdtab *list;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
int param;
|
|
|
|
{
|
|
|
|
u_long map;
|
|
|
|
|
|
|
|
if (argc > 0) {
|
|
|
|
switch (param) {
|
|
|
|
case VAR_AUTHKEY:
|
|
|
|
strncpy(VarAuthKey, *argv, sizeof(VarAuthKey)-1);
|
1997-01-10 07:53:28 +00:00
|
|
|
VarAuthKey[sizeof(VarAuthKey)-1] = '\0';
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
case VAR_AUTHNAME:
|
|
|
|
strncpy(VarAuthName, *argv, sizeof(VarAuthName)-1);
|
1997-01-10 07:53:28 +00:00
|
|
|
VarAuthName[sizeof(VarAuthName)-1] = '\0';
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
case VAR_DIAL:
|
|
|
|
strncpy(VarDialScript, *argv, sizeof(VarDialScript)-1);
|
1997-01-10 07:53:28 +00:00
|
|
|
VarDialScript[sizeof(VarDialScript)-1] = '\0';
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
case VAR_LOGIN:
|
1997-02-02 19:13:25 +00:00
|
|
|
strncpy(VarLoginScript, *argv, sizeof(VarLoginScript)-1);
|
1997-01-10 07:53:28 +00:00
|
|
|
VarLoginScript[sizeof(VarLoginScript)-1] = '\0';
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
case VAR_DEVICE:
|
|
|
|
strncpy(VarDevice, *argv, sizeof(VarDevice)-1);
|
1997-01-10 07:53:28 +00:00
|
|
|
VarDevice[sizeof(VarDevice)-1] = '\0';
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
case VAR_ACCMAP:
|
1996-01-11 17:48:59 +00:00
|
|
|
sscanf(*argv, "%lx", &map);
|
1995-01-31 06:29:58 +00:00
|
|
|
VarAccmap = map;
|
|
|
|
break;
|
|
|
|
case VAR_PHONE:
|
1996-03-08 09:03:09 +00:00
|
|
|
strncpy(VarPhoneList, *argv, sizeof(VarPhoneList)-1);
|
1997-01-10 07:53:28 +00:00
|
|
|
VarPhoneList[sizeof(VarPhoneList)-1] = '\0';
|
1996-03-08 13:22:23 +00:00
|
|
|
strcpy(VarPhoneCopy, VarPhoneList);
|
|
|
|
VarNextPhone = VarPhoneCopy;
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
1996-12-22 17:09:17 +00:00
|
|
|
static int SetCtsRts(list, argc, argv)
|
|
|
|
struct cmdtab *list;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
if (argc > 0) {
|
|
|
|
if (strcmp(*argv, "on") == 0)
|
|
|
|
VarCtsRts = TRUE;
|
|
|
|
else if (strcmp(*argv, "off") == 0)
|
|
|
|
VarCtsRts = FALSE;
|
|
|
|
else
|
|
|
|
printf("usage: set ctsrts [on|off].\n");
|
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
static int SetOpenMode(list, argc, argv)
|
|
|
|
struct cmdtab *list;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
if (argc > 0) {
|
|
|
|
if (strcmp(*argv, "active") == 0)
|
|
|
|
VarOpenMode = OPEN_ACTIVE;
|
|
|
|
else if (strcmp(*argv, "passive") == 0)
|
|
|
|
VarOpenMode = OPEN_PASSIVE;
|
|
|
|
else
|
|
|
|
printf("Invalid mode.\n");
|
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
static char StrChatStr[] = "chat-script";
|
|
|
|
static char StrValue[] = "value";
|
|
|
|
|
1995-02-26 12:18:08 +00:00
|
|
|
extern int SetIfilter(), SetOfilter(), SetDfilter(), SetAfilter();
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1996-01-30 20:04:34 +00:00
|
|
|
struct cmdtab const SetCommands[] = {
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "accmap", NULL, SetVariable, LOCAL_AUTH,
|
|
|
|
"Set accmap value", "hex-value", (void *)VAR_ACCMAP},
|
|
|
|
{ "afilter", NULL, SetAfilter, LOCAL_AUTH,
|
|
|
|
"Set keep Alive filter", "..."},
|
|
|
|
{ "authkey", "key", SetVariable, LOCAL_AUTH,
|
|
|
|
"Set authentication key", "key", (void *)VAR_AUTHKEY},
|
|
|
|
{ "authname", NULL, SetVariable, LOCAL_AUTH,
|
|
|
|
"Set authentication name", "name", (void *)VAR_AUTHNAME},
|
1996-12-22 17:09:17 +00:00
|
|
|
{ "ctsrts", NULL, SetCtsRts, LOCAL_AUTH,
|
|
|
|
"Use CTS/RTS modem signalling", "[on|off]"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "debug", NULL, SetDebugLevel, LOCAL_AUTH,
|
|
|
|
"Set debug level", StrValue},
|
|
|
|
{ "device", "line", SetVariable, LOCAL_AUTH,
|
|
|
|
"Set modem device name", "device-name", (void *)VAR_DEVICE},
|
|
|
|
{ "dfilter", NULL, SetDfilter, LOCAL_AUTH,
|
|
|
|
"Set demand filter", "..."},
|
|
|
|
{ "dial", NULL, SetVariable, LOCAL_AUTH,
|
|
|
|
"Set dialing script", StrChatStr, (void *)VAR_DIAL},
|
|
|
|
{ "escape", NULL, SetEscape, LOCAL_AUTH,
|
|
|
|
"Set escape characters", "hex-digit ..."},
|
|
|
|
{ "ifaddr", NULL, SetInterfaceAddr, LOCAL_AUTH,
|
1996-03-08 09:03:09 +00:00
|
|
|
"Set destination address", "[src-addr [dst-addr [netmask [trg-addr]]]]"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "ifilter", NULL, SetIfilter, LOCAL_AUTH,
|
|
|
|
"Set input filter", "..."},
|
|
|
|
{ "login", NULL, SetVariable, LOCAL_AUTH,
|
|
|
|
"Set login script", StrChatStr, (void *)VAR_LOGIN },
|
|
|
|
{ "mru", "mtu", SetInitialMRU, LOCAL_AUTH,
|
|
|
|
"Set Initial MRU value", StrValue },
|
|
|
|
{ "ofilter", NULL, SetOfilter, LOCAL_AUTH,
|
|
|
|
"Set output filter", "..." },
|
|
|
|
{ "openmode", NULL, SetOpenMode, LOCAL_AUTH,
|
|
|
|
"Set open mode", "[active|passive]"},
|
|
|
|
{ "parity", NULL, SetModemParity, LOCAL_AUTH,
|
|
|
|
"Set modem parity", "[odd|even|none]"},
|
|
|
|
{ "phone", NULL, SetVariable, LOCAL_AUTH,
|
1996-03-08 09:03:09 +00:00
|
|
|
"Set telephone number(s)", "phone1[:phone2[...]]", (void *)VAR_PHONE },
|
1997-04-21 01:02:02 +00:00
|
|
|
{ "reconnect",NULL, SetReconnect, LOCAL_AUTH,
|
|
|
|
"Set Reconnect timeout", "value ntries"},
|
|
|
|
{ "redial", NULL, SetRedialTimeout, LOCAL_AUTH,
|
|
|
|
"Set Redial timeout", "value|random[.value|random] [dial_attempts]"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "speed", NULL, SetModemSpeed, LOCAL_AUTH,
|
|
|
|
"Set modem speed", "speed"},
|
|
|
|
{ "timeout", NULL, SetIdleTimeout, LOCAL_AUTH,
|
|
|
|
"Set Idle timeout", StrValue},
|
1996-10-06 13:32:37 +00:00
|
|
|
#ifdef MSEXT
|
|
|
|
{ "ns", NULL, SetNS, LOCAL_AUTH,
|
|
|
|
"Set NameServer", "pri-addr [sec-addr]"},
|
|
|
|
{ "nbns", NULL, SetNBNS, LOCAL_AUTH,
|
|
|
|
"Set NetBIOS NameServer", "pri-addr [sec-addr]"},
|
|
|
|
#endif /* MSEXT */
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
|
|
|
|
"Display this message", StrNull, (void *)SetCommands},
|
1995-01-31 06:29:58 +00:00
|
|
|
{ NULL, NULL, NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetCommand(list, argc, argv)
|
|
|
|
struct cmdtab *list;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
int val = 1;
|
|
|
|
|
|
|
|
if (argc > 0)
|
|
|
|
val = FindExec(SetCommands, argc, argv);
|
|
|
|
else
|
1996-03-08 09:03:09 +00:00
|
|
|
printf("Use `set ?' to get a list or `set ? <var>' for syntax help.\n");
|
1995-01-31 06:29:58 +00:00
|
|
|
return(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
AddCommand(list, argc, argv)
|
|
|
|
struct cmdtab *list;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
struct in_addr dest, gateway, netmask;
|
|
|
|
|
|
|
|
if (argc == 3) {
|
|
|
|
dest = GetIpAddr(argv[0]);
|
|
|
|
netmask = GetIpAddr(argv[1]);
|
1997-05-08 01:26:31 +00:00
|
|
|
if (strcasecmp(argv[2], "HISADDR") == 0)
|
1995-01-31 06:29:58 +00:00
|
|
|
gateway = IpcpInfo.his_ipaddr;
|
|
|
|
else
|
|
|
|
gateway = GetIpAddr(argv[2]);
|
|
|
|
OsSetRoute(RTM_ADD, dest, gateway, netmask);
|
|
|
|
} else {
|
|
|
|
printf("Usage: %s %s\n", list->name, list->syntax);
|
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
DeleteCommand(list, argc, argv)
|
|
|
|
struct cmdtab *list;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
struct in_addr dest, gateway, netmask;
|
|
|
|
|
|
|
|
if (argc >= 2) {
|
|
|
|
dest = GetIpAddr(argv[0]);
|
1997-05-08 01:26:31 +00:00
|
|
|
if (strcasecmp(argv[1], "HISADDR") == 0)
|
1995-01-31 06:29:58 +00:00
|
|
|
gateway = IpcpInfo.his_ipaddr;
|
|
|
|
else
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OsSetRoute(RTM_DELETE, dest, gateway, netmask);
|
1997-05-08 01:26:31 +00:00
|
|
|
} else if (argc == 1 && strcasecmp(argv[0], "ALL") == 0) {
|
1995-01-31 06:29:58 +00:00
|
|
|
DeleteIfRoutes(0);
|
|
|
|
} else {
|
|
|
|
printf("Usage: %s %s\n", list->name, list->syntax);
|
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|