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-06-23 19:18:13 +00:00
|
|
|
* $Id: command.c,v 1.59 1997/06/17 02:04:51 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>
|
1997-05-23 04:54:03 +00:00
|
|
|
#include <netdb.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
#include <paths.h>
|
|
|
|
#include <alias.h>
|
1997-06-09 03:27:43 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.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"
|
1997-05-23 04:54:03 +00:00
|
|
|
#include "alias_cmd.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
#include "hdlc.h"
|
1997-05-26 00:44:10 +00:00
|
|
|
#include "loadalias.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
#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 "os.h"
|
1997-06-09 03:27:43 +00:00
|
|
|
#include "timeout.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
extern void Cleanup(), TtyTermMode(), PacketMode();
|
|
|
|
extern int EnableCommand(), DisableCommand(), DisplayCommand();
|
|
|
|
extern int AcceptCommand(), DenyCommand();
|
1997-05-23 04:54:03 +00:00
|
|
|
static int AliasCommand();
|
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;
|
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
if (!VarTerm)
|
|
|
|
return 0;
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
if (argc > 0) {
|
1997-06-09 03:27:43 +00:00
|
|
|
for (cmd = plist; cmd->name; cmd++)
|
1997-05-08 01:26:31 +00:00
|
|
|
if (strcasecmp(cmd->name, *argv) == 0 && (cmd->lauth & VarLocalAuth)) {
|
1997-06-09 03:27:43 +00:00
|
|
|
fprintf(VarTerm, "%s\n", cmd->syntax);
|
|
|
|
return 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
|
|
|
|
return -1;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
n = 0;
|
1997-06-09 03:27:43 +00:00
|
|
|
for (cmd = plist; cmd->func; cmd++)
|
1995-02-27 10:57:54 +00:00
|
|
|
if (cmd->name && (cmd->lauth & VarLocalAuth)) {
|
1997-06-13 00:09:54 +00:00
|
|
|
fprintf(VarTerm, " %-9s: %-20s\n", cmd->name, cmd->helpmes);
|
1995-01-31 06:29:58 +00:00
|
|
|
n++;
|
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
if (n & 1)
|
1997-06-09 03:27:43 +00:00
|
|
|
fprintf(VarTerm, "\n");
|
|
|
|
|
|
|
|
return 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
IsInteractive()
|
|
|
|
{
|
|
|
|
char *mes = NULL;
|
|
|
|
|
1996-12-03 21:38:52 +00:00
|
|
|
if (mode & MODE_DDIAL)
|
|
|
|
mes = "Working in dedicated dial mode.";
|
1997-05-19 02:00:16 +00:00
|
|
|
else if (mode & MODE_BACKGROUND)
|
|
|
|
mes = "Working in background mode.";
|
1996-12-03 21:38:52 +00:00
|
|
|
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) {
|
1997-06-09 03:27:43 +00:00
|
|
|
if (VarTerm)
|
|
|
|
fprintf(VarTerm, "%s\n", mes);
|
|
|
|
return 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
return 1;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
1997-06-09 03:27:43 +00:00
|
|
|
if (VarTerm)
|
|
|
|
fprintf(VarTerm, "LCP state is [%s]\n", StateNames[LcpFsm.state]);
|
|
|
|
return 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
if (!IsInteractive())
|
|
|
|
return(1);
|
1997-06-09 03:27:43 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
if (argc > 0) {
|
|
|
|
if (SelectSystem(*argv, CONFFILE) < 0) {
|
1997-06-09 03:27:43 +00:00
|
|
|
if (VarTerm)
|
|
|
|
fprintf(VarTerm, "%s: not found.\n", *argv);
|
|
|
|
return -1;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
|
1995-10-08 14:57:32 +00:00
|
|
|
tries = 0;
|
|
|
|
do {
|
1997-06-09 03:27:43 +00:00
|
|
|
if (VarTerm)
|
|
|
|
fprintf(VarTerm, "Dial attempt %u of %d\n", ++tries, VarDialTries);
|
1995-10-08 14:57:32 +00:00
|
|
|
modem = OpenModem(mode);
|
|
|
|
if (modem < 0) {
|
1997-06-09 03:27:43 +00:00
|
|
|
if (VarTerm)
|
|
|
|
fprintf(VarTerm, "Failed to open modem.\n");
|
1995-10-08 14:57:32 +00:00
|
|
|
break;
|
|
|
|
}
|
1997-05-29 02:29:13 +00:00
|
|
|
if (DialModem() == EX_DONE) {
|
1995-10-08 14:57:32 +00:00
|
|
|
sleep(1);
|
|
|
|
ModemTimeout();
|
|
|
|
PacketMode();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (VarDialTries == 0 || tries < VarDialTries);
|
1997-06-09 03:27:43 +00:00
|
|
|
|
|
|
|
return 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
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;
|
1997-06-09 03:27:43 +00:00
|
|
|
FILE *oVarTerm;
|
1996-12-22 17:29:33 +00:00
|
|
|
|
1996-10-10 11:27:35 +00:00
|
|
|
#ifdef SHELL_ONLY_INTERACTIVELY
|
1997-06-09 03:27:43 +00:00
|
|
|
if (mode != MODE_INTER) {
|
|
|
|
LogPrintf(LogWARN, "Can only start a shell in interactive mode\n");
|
|
|
|
return 1;
|
1995-09-02 17:20:54 +00:00
|
|
|
}
|
1996-10-13 15:05:14 +00:00
|
|
|
#else
|
|
|
|
if ((mode & (MODE_AUTO|MODE_INTER)) == (MODE_AUTO|MODE_INTER)) {
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogWARN, "Shell is not allowed interactively in auto mode\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(argc == 0 && !(mode & MODE_INTER)) {
|
|
|
|
LogPrintf(LogWARN, "Can only start an interactive shell in"
|
|
|
|
" interactive mode\n");
|
|
|
|
return 1;
|
1996-10-13 15:05:14 +00:00
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
|
|
|
|
if((shell = getenv("SHELL")) == 0)
|
|
|
|
shell = _PATH_BSHELL;
|
|
|
|
|
1995-09-02 17:20:54 +00:00
|
|
|
if((shpid = fork()) == 0) {
|
1997-06-09 03:27:43 +00:00
|
|
|
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);
|
1996-09-28 11:25:47 +00:00
|
|
|
|
|
|
|
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) {
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogERROR, "setgid: %s\n", strerror(errno));
|
1996-06-09 20:40:58 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (setuid(getuid()) < 0) {
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogERROR, "setuid: %s\n", strerror(errno));
|
1996-06-09 20:40:58 +00:00
|
|
|
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
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogWARN, "exec() of %s failed\n", argc > 0 ? argv[0] : shell);
|
1995-09-02 17:20:54 +00:00
|
|
|
exit(255);
|
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
|
1995-09-02 17:20:54 +00:00
|
|
|
if( shpid == (pid_t)-1 ) {
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogERROR, "Fork failed: %s\n", strerror(errno));
|
1995-09-02 17:20:54 +00:00
|
|
|
} 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);
|
|
|
|
}
|
|
|
|
|
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,
|
1997-06-09 03:27:43 +00:00
|
|
|
"accept option request", "accept option .."},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "add", NULL, AddCommand, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"add route", "add dest mask gateway"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "close", NULL, CloseCommand, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Close connection", "close"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "delete", NULL, DeleteCommand, LOCAL_AUTH,
|
1997-06-13 03:59:36 +00:00
|
|
|
"delete route", "delete ALL | dest [gateway [mask]]"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "deny", NULL, DenyCommand, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Deny option request", "deny option .."},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "dial", "call", DialCommand, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Dial and login", "dial|call [remote]"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "disable", NULL, DisableCommand, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Disable option", "disable option .."},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "display", NULL, DisplayCommand, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Display option configs", "display"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "enable", NULL, EnableCommand, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Enable option", "enable option .."},
|
1995-02-27 10:57:54 +00:00
|
|
|
{ "passwd", NULL, LocalAuthCommand,LOCAL_NO_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Password for manipulation", "passwd option .."},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "load", NULL, LoadCommand, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Load settings", "load [remote]"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "save", NULL, SaveCommand, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Save settings", "save"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "set", "setup", SetCommand, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Set parameters", "set[up] var value"},
|
1995-09-02 17:20:54 +00:00
|
|
|
{ "shell", "!", ShellCommand, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Run a subshell", "shell|! [sh command]"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "show", NULL, ShowCommand, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Show status and statictics", "show var"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "term", NULL, TerminalCommand,LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Enter to terminal mode", "term"},
|
1997-05-23 04:54:03 +00:00
|
|
|
{ "alias", NULL, AliasCommand, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"alias control", "alias option [yes|no]"},
|
1995-02-27 10:57:54 +00:00
|
|
|
{ "quit", "bye", QuitCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Quit PPP program", "quit|bye [all]"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Display this message", "help|? [command]", (void *)Commands },
|
1995-02-26 12:18:08 +00:00
|
|
|
{ NULL, "down", DownCommand, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Generate down event", "down"},
|
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();
|
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
static int ShowLogLevel()
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
if (!VarTerm)
|
|
|
|
return 0;
|
|
|
|
fprintf(VarTerm, "Log:");
|
|
|
|
for (i = LogMIN; i < LogMAXCONF; i++) {
|
|
|
|
if (LogIsKept(i))
|
|
|
|
fprintf(VarTerm, " %s", LogName(i));
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
fprintf(VarTerm, "\n");
|
|
|
|
|
|
|
|
return 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ShowEscape()
|
|
|
|
{
|
|
|
|
int code, bit;
|
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
if (!VarTerm)
|
|
|
|
return 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
if (EscMap[32]) {
|
1997-06-09 03:27:43 +00:00
|
|
|
for (code = 0; code < 32; code++)
|
|
|
|
if (EscMap[code])
|
|
|
|
for (bit = 0; bit < 8; bit++)
|
|
|
|
if (EscMap[code] & (1<<bit))
|
|
|
|
fprintf(VarTerm, " 0x%02x", (code << 3) + bit);
|
|
|
|
fprintf(VarTerm, "\n");
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
return 1;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ShowTimeout()
|
|
|
|
{
|
1997-06-09 03:27:43 +00:00
|
|
|
if (!VarTerm)
|
|
|
|
return 0;
|
|
|
|
fprintf(VarTerm, " Idle Timer: %d secs LQR Timer: %d secs"
|
|
|
|
" Retry Timer: %d secs\n", VarIdleTimeout, VarLqrTimeout,
|
|
|
|
VarRetryTimeout);
|
|
|
|
return 1;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ShowAuthKey()
|
|
|
|
{
|
1997-06-09 03:27:43 +00:00
|
|
|
if (!VarTerm)
|
|
|
|
return 0;
|
|
|
|
fprintf(VarTerm, "AuthName = %s\n", VarAuthName);
|
|
|
|
fprintf(VarTerm, "AuthKey = %s\n", VarAuthKey);
|
|
|
|
return 1;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
if (!VarTerm)
|
|
|
|
return 0;
|
|
|
|
fprintf(VarTerm, "%s - %s \n", VarVersion, VarLocalVersion);
|
|
|
|
return 1;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-06-01 01:13:04 +00:00
|
|
|
static int ShowInitialMRU()
|
|
|
|
{
|
1997-06-09 03:27:43 +00:00
|
|
|
if (!VarTerm)
|
|
|
|
return 0;
|
|
|
|
fprintf(VarTerm, " Initial MRU: %ld\n", VarMRU);
|
|
|
|
return 1;
|
1997-06-01 01:13:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ShowPreferredMTU()
|
|
|
|
{
|
1997-06-09 03:27:43 +00:00
|
|
|
if (!VarTerm)
|
|
|
|
return 0;
|
1997-06-01 01:13:04 +00:00
|
|
|
if (VarPrefMTU)
|
1997-06-09 03:27:43 +00:00
|
|
|
fprintf(VarTerm, " Preferred MTU: %ld\n", VarPrefMTU);
|
1997-06-01 01:13:04 +00:00
|
|
|
else
|
1997-06-09 03:27:43 +00:00
|
|
|
fprintf(VarTerm, " Preferred MTU: unspecified\n");
|
|
|
|
return 1;
|
1997-06-01 01:13:04 +00:00
|
|
|
}
|
|
|
|
|
1997-04-21 01:02:02 +00:00
|
|
|
static int ShowReconnect()
|
|
|
|
{
|
1997-06-09 03:27:43 +00:00
|
|
|
if (!VarTerm)
|
|
|
|
return 0;
|
|
|
|
fprintf(VarTerm, " Reconnect Timer: %d, %d tries\n",
|
1997-04-21 01:02:02 +00:00
|
|
|
VarReconnectTimer, VarReconnectTries);
|
1997-06-09 03:27:43 +00:00
|
|
|
return 1;
|
1997-04-21 01:02:02 +00:00
|
|
|
}
|
|
|
|
|
1995-10-08 14:57:32 +00:00
|
|
|
static int ShowRedial()
|
|
|
|
{
|
1997-06-09 03:27:43 +00:00
|
|
|
if (!VarTerm)
|
|
|
|
return 0;
|
|
|
|
fprintf(VarTerm, " Redial Timer: ");
|
1995-10-08 14:57:32 +00:00
|
|
|
|
|
|
|
if (VarRedialTimeout >= 0) {
|
1997-06-09 03:27:43 +00:00
|
|
|
fprintf(VarTerm, " %d seconds, ", VarRedialTimeout);
|
1995-10-08 14:57:32 +00:00
|
|
|
}
|
|
|
|
else {
|
1997-06-09 03:27:43 +00:00
|
|
|
fprintf(VarTerm, " Random 0 - %d seconds, ", REDIAL_PERIOD);
|
1995-10-08 14:57:32 +00:00
|
|
|
}
|
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
fprintf(VarTerm, " Redial Next Timer: ");
|
1997-04-14 23:48:20 +00:00
|
|
|
|
|
|
|
if (VarRedialNextTimeout >= 0) {
|
1997-06-09 03:27:43 +00:00
|
|
|
fprintf(VarTerm, " %d seconds, ", VarRedialNextTimeout);
|
1997-04-14 23:48:20 +00:00
|
|
|
}
|
|
|
|
else {
|
1997-06-09 03:27:43 +00:00
|
|
|
fprintf(VarTerm, " Random 0 - %d seconds, ", REDIAL_PERIOD);
|
1997-04-14 23:48:20 +00:00
|
|
|
}
|
|
|
|
|
1995-10-08 14:57:32 +00:00
|
|
|
if (VarDialTries)
|
1997-06-09 03:27:43 +00:00
|
|
|
fprintf(VarTerm, "%d dial tries", VarDialTries);
|
1995-10-08 14:57:32 +00:00
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
fprintf(VarTerm, "\n");
|
1995-10-08 14:57:32 +00:00
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
return 1;
|
1995-10-08 14:57:32 +00:00
|
|
|
}
|
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
#ifndef NOMSEXT
|
1996-10-06 13:32:37 +00:00
|
|
|
static int ShowMSExt()
|
|
|
|
{
|
1997-06-09 03:27:43 +00:00
|
|
|
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;
|
1996-10-06 13:32:37 +00:00
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
#endif
|
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,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Show keep Alive filters", "show afilter option .."},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "auth", NULL, ShowAuthKey, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Show auth name/key", "show auth"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "ccp", NULL, ReportCcpStatus, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Show CCP status", "show cpp"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "compress", NULL, ReportCompress, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Show compression statictics", "show compress"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "dfilter", NULL, ShowDfilter, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Show Demand filters", "show dfilteroption .."},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "escape", NULL, ShowEscape, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Show escape characters", "show escape"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "hdlc", NULL, ReportHdlcStatus, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Show HDLC error summary", "show hdlc"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "ifilter", NULL, ShowIfilter, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Show Input filters", "show ifilter option .."},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "ipcp", NULL, ReportIpcpStatus, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Show IPCP status", "show ipcp"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "lcp", NULL, ReportLcpStatus, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Show LCP status", "show lcp"},
|
|
|
|
{ "log", NULL, ShowLogLevel, LOCAL_AUTH,
|
|
|
|
"Show current log level", "show log"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "mem", NULL, ShowMemMap, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Show memory map", "show mem"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "modem", NULL, ShowModemStatus, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Show modem setups", "show modem"},
|
1997-06-01 01:13:04 +00:00
|
|
|
{ "mru", NULL, ShowInitialMRU, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Show Initial MRU", "show mru"},
|
1997-06-01 01:13:04 +00:00
|
|
|
{ "mtu", NULL, ShowPreferredMTU, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Show Preferred MTU", "show mtu"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "ofilter", NULL, ShowOfilter, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Show Output filters", "show ofilter option .."},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "proto", NULL, ReportProtStatus, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Show protocol summary", "show proto"},
|
1997-04-21 01:02:02 +00:00
|
|
|
{ "reconnect",NULL, ShowReconnect, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Show Reconnect timer,tries", "show reconnect"},
|
1997-04-21 01:02:02 +00:00
|
|
|
{ "redial", NULL, ShowRedial, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Show Redial timeout value", "show redial"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "route", NULL, ShowRoute, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Show routing table", "show route"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "timeout", NULL, ShowTimeout, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Show Idle timeout value", "show timeout"},
|
|
|
|
#ifndef NOMSEXT
|
1996-10-06 13:32:37 +00:00
|
|
|
{ "msext", NULL, ShowMSExt, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Show MS PPP extentions", "show msext"},
|
|
|
|
#endif
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "version", NULL, ShowVersion, LOCAL_NO_AUTH | LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Show version string", "show version"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "help", "?", HelpCommand, LOCAL_NO_AUTH | LOCAL_AUTH,
|
1997-06-17 02:04:51 +00:00
|
|
|
"Display this message", "show help|? [command]", (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;
|
|
|
|
{
|
1997-06-09 03:27:43 +00:00
|
|
|
int nmatch;
|
|
|
|
int len;
|
|
|
|
struct cmdtab *found;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
found = NULL;
|
|
|
|
len = strlen(str);
|
|
|
|
nmatch = 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
while (cmds->func) {
|
1997-05-08 01:26:31 +00:00
|
|
|
if (cmds->name && strncasecmp(str, cmds->name, len) == 0) {
|
1997-06-09 03:27:43 +00:00
|
|
|
if (cmds->name[len] == '\0') {
|
|
|
|
*pmatch = 1;
|
|
|
|
return cmds;
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
nmatch++;
|
|
|
|
found = cmds;
|
1997-06-09 03:27:43 +00:00
|
|
|
} else if(cmds->alias && strncasecmp(str, cmds->alias, len) == 0) {
|
|
|
|
if (cmds->alias[len] == '\0') {
|
|
|
|
*pmatch = 1;
|
|
|
|
return cmds;
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
nmatch++;
|
|
|
|
found = cmds;
|
|
|
|
}
|
|
|
|
cmds++;
|
|
|
|
}
|
|
|
|
*pmatch = nmatch;
|
1997-06-09 03:27:43 +00:00
|
|
|
return found;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogWARN, "%s: Ambiguous command\n", *argv);
|
1995-02-26 12:18:08 +00:00
|
|
|
else if (cmd && ( cmd->lauth & VarLocalAuth ) )
|
1995-01-31 06:29:58 +00:00
|
|
|
val = (cmd->func)(cmd, --argc, ++argv, cmd->args);
|
|
|
|
else
|
1997-06-09 03:27:43 +00:00
|
|
|
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;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1996-10-12 16:20:34 +00:00
|
|
|
int aft_cmd = 1;
|
1997-06-09 03:27:43 +00:00
|
|
|
extern int TermMode;
|
1996-10-12 16:20:34 +00:00
|
|
|
|
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;
|
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
if (!(mode & MODE_INTER) || !VarTerm || TermMode)
|
1995-01-31 06:29:58 +00:00
|
|
|
return;
|
1995-02-26 12:18:08 +00:00
|
|
|
|
1996-10-12 16:20:34 +00:00
|
|
|
if (!aft_cmd)
|
1997-06-09 03:27:43 +00:00
|
|
|
fprintf(VarTerm, "\n");
|
1996-10-12 16:20:34 +00:00
|
|
|
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";
|
1997-06-09 03:27:43 +00:00
|
|
|
fprintf(VarTerm, "%s%s%s> ", pconnect, pauth, VarShortHost);
|
|
|
|
fflush(VarTerm);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DecodeCommand(buff, nb, prompt)
|
|
|
|
char *buff;
|
|
|
|
int nb;
|
|
|
|
int prompt;
|
|
|
|
{
|
|
|
|
char *vector[20];
|
|
|
|
char **argv;
|
1997-06-09 03:27:43 +00:00
|
|
|
int argc;
|
1995-01-31 06:29:58 +00:00
|
|
|
char *cp;
|
|
|
|
|
|
|
|
if (nb > 0) {
|
|
|
|
cp = buff + strcspn(buff, "\r\n");
|
|
|
|
if (cp)
|
|
|
|
*cp = '\0';
|
1997-06-09 03:27:43 +00:00
|
|
|
argc = MakeArgs(buff, vector, VECSIZE(vector));
|
|
|
|
argv = vector;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
if (argc > 0)
|
|
|
|
FindExec(Commands, argc, argv);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
if (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;
|
|
|
|
{
|
|
|
|
if (argc > 0)
|
1997-06-09 03:27:43 +00:00
|
|
|
FindExec(ShowCommands, argc, argv);
|
|
|
|
else if (VarTerm)
|
|
|
|
fprintf(VarTerm, "Use ``show ?'' to get a list.\n");
|
1995-01-31 06:29:58 +00:00
|
|
|
else
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogWARN, "show command must have arguments\n");
|
|
|
|
|
|
|
|
return 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
TerminalCommand()
|
|
|
|
{
|
|
|
|
if (LcpFsm.state > ST_CLOSED) {
|
1997-06-09 03:27:43 +00:00
|
|
|
if (VarTerm)
|
|
|
|
fprintf(VarTerm, "LCP state is [%s]\n", StateNames[LcpFsm.state]);
|
|
|
|
return 1;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
if (!IsInteractive())
|
|
|
|
return(1);
|
|
|
|
modem = OpenModem(mode);
|
|
|
|
if (modem < 0) {
|
1997-06-09 03:27:43 +00:00
|
|
|
if (VarTerm)
|
|
|
|
fprintf(VarTerm, "Failed to open modem.\n");
|
1995-01-31 06:29:58 +00:00
|
|
|
return(1);
|
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
if (VarTerm) {
|
|
|
|
fprintf(VarTerm, "Enter to terminal mode.\n");
|
|
|
|
fprintf(VarTerm, "Type `~?' for help.\n");
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
TtyTermMode();
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
QuitCommand(list, argc, argv)
|
|
|
|
struct cmdtab *list;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
1997-06-09 03:27:43 +00:00
|
|
|
FILE *oVarTerm;
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
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;
|
1997-06-09 03:27:43 +00:00
|
|
|
oVarTerm = VarTerm;
|
|
|
|
VarTerm = 0;
|
|
|
|
if (oVarTerm && oVarTerm != stdout)
|
|
|
|
fclose(oVarTerm);
|
1995-01-31 06:29:58 +00:00
|
|
|
} else {
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogPHASE, "Client connection closed.\n");
|
1995-02-26 12:18:08 +00:00
|
|
|
VarLocalAuth = LOCAL_NO_AUTH;
|
1997-06-09 03:27:43 +00:00
|
|
|
mode &= ~MODE_INTER;
|
|
|
|
oVarTerm = VarTerm;
|
|
|
|
VarTerm = 0;
|
|
|
|
if (oVarTerm && oVarTerm != stdout)
|
|
|
|
fclose(oVarTerm);
|
1995-01-31 06:29:58 +00:00
|
|
|
close(netfd);
|
|
|
|
netfd = -1;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
Cleanup(EX_NORMAL);
|
1997-06-09 03:27:43 +00:00
|
|
|
|
|
|
|
return 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
CloseCommand()
|
|
|
|
{
|
1997-05-24 17:32:42 +00:00
|
|
|
reconnect(RECON_FALSE);
|
1995-01-31 06:29:58 +00:00
|
|
|
LcpClose();
|
1997-05-19 02:00:16 +00:00
|
|
|
if (mode & MODE_BACKGROUND)
|
|
|
|
Cleanup(EX_NORMAL);
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
DownCommand()
|
|
|
|
{
|
|
|
|
LcpDown();
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
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;
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
1995-02-26 12:18:08 +00:00
|
|
|
}
|
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;
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogWARN, "%s: Invalid speed\n", *argv);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
return -1;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
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]);
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
1997-04-21 01:02:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
1997-03-10 08:04:15 +00:00
|
|
|
if (!randinit) {
|
|
|
|
randinit = 1;
|
1997-06-14 00:27:03 +00:00
|
|
|
srandomdev();
|
1997-03-10 08:04:15 +00:00
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
} else {
|
1995-10-08 14:57:32 +00:00
|
|
|
timeout = atoi(argv[0]);
|
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
if (timeout >= 0)
|
1995-10-08 14:57:32 +00:00
|
|
|
VarRedialTimeout = timeout;
|
|
|
|
else {
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogWARN, "Invalid redial timeout\n");
|
|
|
|
return -1;
|
1995-10-08 14:57:32 +00:00
|
|
|
}
|
|
|
|
}
|
1997-04-14 23:48:20 +00:00
|
|
|
|
|
|
|
dot = index(argv[0],'.');
|
|
|
|
if (dot) {
|
|
|
|
if (strcasecmp(++dot, "random") == 0) {
|
|
|
|
VarRedialNextTimeout = -1;
|
|
|
|
if (!randinit) {
|
|
|
|
randinit = 1;
|
1997-06-14 00:27:03 +00:00
|
|
|
srandomdev();
|
1997-04-14 23:48:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
timeout = atoi(dot);
|
1997-06-09 03:27:43 +00:00
|
|
|
if (timeout >= 0)
|
1997-04-14 23:48:20 +00:00
|
|
|
VarRedialNextTimeout = timeout;
|
|
|
|
else {
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogWARN, "Invalid next redial timeout\n");
|
|
|
|
return -1;
|
1997-04-14 23:48:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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) {
|
1997-06-09 03:27:43 +00:00
|
|
|
VarDialTries = tries;
|
|
|
|
} else {
|
|
|
|
LogPrintf(LogWARN, "Invalid retry value\n");
|
|
|
|
return 1;
|
1995-10-08 14:57:32 +00:00
|
|
|
}
|
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
1995-10-08 14:57:32 +00:00
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
|
|
|
|
return -1;
|
1995-10-08 14:57:32 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
{
|
1997-06-23 19:18:13 +00:00
|
|
|
return argc > 0 ? ChangeParity(*argv) : -1;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1997-06-09 03:27:43 +00:00
|
|
|
SetLogLevel(list, argc, argv)
|
1995-01-31 06:29:58 +00:00
|
|
|
struct cmdtab *list;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
1997-06-09 03:27:43 +00:00
|
|
|
int i;
|
|
|
|
int res;
|
|
|
|
char *arg;
|
|
|
|
|
|
|
|
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);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
if (i > LogMAX) {
|
|
|
|
LogPrintf(LogWARN, "%s: Invalid log value\n", arg);
|
|
|
|
res = -1;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
argv++;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
return res;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetInitialMRU(list, argc, argv)
|
|
|
|
struct cmdtab *list;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
1997-06-01 01:13:04 +00:00
|
|
|
long mru;
|
1997-06-09 03:27:43 +00:00
|
|
|
char *err;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
if (argc > 0) {
|
1997-06-01 01:13:04 +00:00
|
|
|
mru = atol(*argv);
|
|
|
|
if (mru < MIN_MRU)
|
1997-06-09 03:27:43 +00:00
|
|
|
err = "Given MRU value (%ld) is too small.\n";
|
1995-01-31 06:29:58 +00:00
|
|
|
else if (mru > MAX_MRU)
|
1997-06-09 03:27:43 +00:00
|
|
|
err = "Given MRU value (%ld) is too big.\n";
|
|
|
|
else {
|
1995-01-31 06:29:58 +00:00
|
|
|
VarMRU = mru;
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
LogPrintf(LogWARN, err, mru);
|
|
|
|
}
|
1997-06-01 01:13:04 +00:00
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
return -1;
|
1997-06-01 01:13:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetPreferredMTU(list, argc, argv)
|
|
|
|
struct cmdtab *list;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
long mtu;
|
1997-06-09 03:27:43 +00:00
|
|
|
char *err;
|
1997-06-01 01:13:04 +00:00
|
|
|
|
|
|
|
if (argc > 0) {
|
|
|
|
mtu = atol(*argv);
|
1997-06-09 03:27:43 +00:00
|
|
|
if (mtu == 0) {
|
1997-06-01 01:13:04 +00:00
|
|
|
VarPrefMTU = 0;
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
|
|
|
} else if (mtu < MIN_MTU)
|
|
|
|
err = "Given MTU value (%ld) is too small.\n";
|
1997-06-01 01:13:04 +00:00
|
|
|
else if (mtu > MAX_MTU)
|
1997-06-09 03:27:43 +00:00
|
|
|
err = "Given MTU value (%ld) is too big.\n";
|
|
|
|
else {
|
1997-06-01 01:13:04 +00:00
|
|
|
VarPrefMTU = mtu;
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
LogPrintf(LogWARN, err, mtu);
|
|
|
|
}
|
1997-06-01 01:13:04 +00:00
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
return -1;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetIdleTimeout(list, argc, argv)
|
|
|
|
struct cmdtab *list;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
if (argc-- > 0) {
|
|
|
|
VarIdleTimeout = atoi(*argv++);
|
1997-06-09 03:27:43 +00:00
|
|
|
UpdateIdleTimer(); /* If we're connected, restart the idle timer */
|
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;
|
|
|
|
}
|
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
|
|
|
|
return -1;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-06-09 03:27:43 +00:00
|
|
|
if (argc > 4)
|
|
|
|
return -1;
|
|
|
|
|
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)
|
1997-06-09 03:27:43 +00:00
|
|
|
return 1;
|
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)
|
1997-06-09 03:27:43 +00:00
|
|
|
return 2;
|
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)
|
1997-06-09 03:27:43 +00:00
|
|
|
return 3;
|
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)
|
1997-06-09 03:27:43 +00:00
|
|
|
return 4;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
#ifndef NOMSEXT
|
1996-10-06 13:32:37 +00:00
|
|
|
|
|
|
|
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);
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
1996-10-06 13:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetNBNS(list, argc, argv)
|
|
|
|
struct cmdtab *list;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
SetMSEXT(&nbns_entries[0], &nbns_entries[1], argc, argv);
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
1996-10-06 13:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#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;
|
1997-06-11 03:57:51 +00:00
|
|
|
char *arg;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1997-06-11 03:57:51 +00:00
|
|
|
if (argc > 0)
|
|
|
|
arg = *argv;
|
|
|
|
else
|
|
|
|
arg = "";
|
|
|
|
|
|
|
|
switch (param) {
|
1995-01-31 06:29:58 +00:00
|
|
|
case VAR_AUTHKEY:
|
1997-06-11 03:57:51 +00:00
|
|
|
strncpy(VarAuthKey, arg, 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:
|
1997-06-11 03:57:51 +00:00
|
|
|
strncpy(VarAuthName, arg, 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:
|
1997-06-11 03:57:51 +00:00
|
|
|
strncpy(VarDialScript, arg, 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-06-11 03:57:51 +00:00
|
|
|
strncpy(VarLoginScript, arg, 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:
|
1997-06-09 03:27:43 +00:00
|
|
|
CloseModem();
|
1997-06-11 03:57:51 +00:00
|
|
|
strncpy(VarDevice, arg, sizeof(VarDevice)-1);
|
1997-01-10 07:53:28 +00:00
|
|
|
VarDevice[sizeof(VarDevice)-1] = '\0';
|
1997-05-10 03:39:57 +00:00
|
|
|
VarBaseDevice = rindex(VarDevice, '/');
|
|
|
|
VarBaseDevice = VarBaseDevice ? VarBaseDevice + 1 : "";
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
case VAR_ACCMAP:
|
1997-06-11 03:57:51 +00:00
|
|
|
sscanf(arg, "%lx", &map);
|
1995-01-31 06:29:58 +00:00
|
|
|
VarAccmap = map;
|
|
|
|
break;
|
|
|
|
case VAR_PHONE:
|
1997-06-11 03:57:51 +00:00
|
|
|
strncpy(VarPhoneList, arg, 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;
|
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
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
|
1997-06-09 03:27:43 +00:00
|
|
|
return -1;
|
|
|
|
return 0;
|
1996-12-22 17:09:17 +00:00
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
return -1;
|
1996-12-22 17:09:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
1997-06-09 03:27:43 +00:00
|
|
|
return -1;
|
|
|
|
return 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
return -1;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
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,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Set accmap value", "set accmap hex-value", (void *)VAR_ACCMAP},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "afilter", NULL, SetAfilter, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Set keep Alive filter", "set afilter ..."},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "authkey", "key", SetVariable, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Set authentication key", "set authkey|key key", (void *)VAR_AUTHKEY},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "authname", NULL, SetVariable, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Set authentication name", "set authname name", (void *)VAR_AUTHNAME},
|
1996-12-22 17:09:17 +00:00
|
|
|
{ "ctsrts", NULL, SetCtsRts, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Use CTS/RTS modem signalling", "set ctsrts [on|off]"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "device", "line", SetVariable, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Set modem device name", "set device|line device-name", (void *)VAR_DEVICE},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "dfilter", NULL, SetDfilter, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Set demand filter", "set dfilter ..."},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "dial", NULL, SetVariable, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Set dialing script", "set dial chat-script", (void *)VAR_DIAL},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "escape", NULL, SetEscape, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Set escape characters", "set escape hex-digit ..."},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "ifaddr", NULL, SetInterfaceAddr, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Set destination address", "set ifaddr [src-addr [dst-addr [netmask [trg-addr]]]]"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "ifilter", NULL, SetIfilter, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Set input filter", "set ifilter ..."},
|
|
|
|
{ "log", NULL, SetLogLevel, LOCAL_AUTH,
|
|
|
|
"Set log level", "set log [+|-]value..."},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "login", NULL, SetVariable, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Set login script", "set login chat-script", (void *)VAR_LOGIN },
|
1997-05-31 16:37:19 +00:00
|
|
|
{ "mru", NULL, SetInitialMRU, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Set Initial MRU value", "set mru value" },
|
1997-06-01 01:13:04 +00:00
|
|
|
{ "mtu", NULL, SetPreferredMTU, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Set Preferred MTU value", "set mtu value" },
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "ofilter", NULL, SetOfilter, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Set output filter", "set ofilter ..." },
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "openmode", NULL, SetOpenMode, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Set open mode", "set openmode [active|passive]"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "parity", NULL, SetModemParity, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Set modem parity", "set parity [odd|even|none]"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "phone", NULL, SetVariable, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Set telephone number(s)", "set phone phone1[:phone2[...]]", (void *)VAR_PHONE },
|
1997-04-21 01:02:02 +00:00
|
|
|
{ "reconnect",NULL, SetReconnect, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Set Reconnect timeout", "set reconnect value ntries"},
|
1997-04-21 01:02:02 +00:00
|
|
|
{ "redial", NULL, SetRedialTimeout, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Set Redial timeout", "set redial value|random[.value|random] [dial_attempts]"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "speed", NULL, SetModemSpeed, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Set modem speed", "set speed value"},
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "timeout", NULL, SetIdleTimeout, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Set Idle timeout", "set timeout value"},
|
|
|
|
#ifndef NOMSEXT
|
1996-10-06 13:32:37 +00:00
|
|
|
{ "ns", NULL, SetNS, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Set NameServer", "set ns pri-addr [sec-addr]"},
|
1996-10-06 13:32:37 +00:00
|
|
|
{ "nbns", NULL, SetNBNS, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"Set NetBIOS NameServer", "set nbns pri-addr [sec-addr]"},
|
|
|
|
#endif
|
1995-02-26 12:18:08 +00:00
|
|
|
{ "help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
|
1997-06-17 02:04:51 +00:00
|
|
|
"Display this message", "set help|? [command]", (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;
|
|
|
|
{
|
|
|
|
if (argc > 0)
|
1997-06-09 03:27:43 +00:00
|
|
|
FindExec(SetCommands, argc, argv);
|
|
|
|
else if (VarTerm)
|
|
|
|
fprintf(VarTerm, "Use `set ?' to get a list or `set ? <var>' for"
|
|
|
|
" syntax help.\n");
|
1995-01-31 06:29:58 +00:00
|
|
|
else
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogWARN, "set command must have arguments\n");
|
|
|
|
|
|
|
|
return 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
|
|
|
|
return -1;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
DeleteCommand(list, argc, argv)
|
|
|
|
struct cmdtab *list;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
struct in_addr dest, gateway, netmask;
|
|
|
|
|
1997-06-13 03:59:36 +00:00
|
|
|
if (argc == 1 && strcasecmp(argv[0], "all") == 0)
|
|
|
|
DeleteIfRoutes(0);
|
|
|
|
else if (argc > 0 && argc < 4) {
|
1995-01-31 06:29:58 +00:00
|
|
|
dest = GetIpAddr(argv[0]);
|
1997-06-13 03:59:36 +00:00
|
|
|
netmask.s_addr = INADDR_ANY;
|
|
|
|
if (argc > 1) {
|
|
|
|
if (strcasecmp(argv[1], "HISADDR") == 0)
|
|
|
|
gateway = IpcpInfo.his_ipaddr;
|
|
|
|
else
|
|
|
|
gateway = GetIpAddr(argv[1]);
|
|
|
|
if (argc == 3) {
|
|
|
|
if (inet_aton(argv[2], &netmask) == 0) {
|
|
|
|
LogPrintf(LogWARN, "Bad netmask value.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1997-06-13 03:59:36 +00:00
|
|
|
} else
|
|
|
|
gateway.s_addr = INADDR_ANY;
|
1995-01-31 06:29:58 +00:00
|
|
|
OsSetRoute(RTM_DELETE, dest, gateway, netmask);
|
1997-06-09 03:27:43 +00:00
|
|
|
} else
|
|
|
|
return -1;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1997-05-23 04:54:03 +00:00
|
|
|
|
|
|
|
static int AliasEnable();
|
|
|
|
static int AliasOption();
|
|
|
|
|
|
|
|
static struct cmdtab const AliasCommands[] =
|
|
|
|
{
|
|
|
|
{ "enable", NULL, AliasEnable, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"enable IP aliasing", "alias enable [yes|no]"},
|
1997-05-23 04:54:03 +00:00
|
|
|
{ "port", NULL, AliasRedirectPort, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"port redirection", "alias port [proto addr_local:port_local port_alias]"},
|
1997-05-23 04:54:03 +00:00
|
|
|
{ "addr", NULL, AliasRedirectAddr, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"static address translation", "alias addr [addr_local addr_alias]"},
|
1997-05-23 04:54:03 +00:00
|
|
|
{ "deny_incoming", NULL, AliasOption, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"stop incoming connections", "alias deny_incoming [yes|no]",
|
1997-05-23 04:54:03 +00:00
|
|
|
(void*)PKT_ALIAS_DENY_INCOMING},
|
|
|
|
{ "log", NULL, AliasOption, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"log aliasing link creation", "alias log [yes|no]",
|
1997-05-23 04:54:03 +00:00
|
|
|
(void*)PKT_ALIAS_LOG},
|
|
|
|
{ "same_ports", NULL, AliasOption, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"try to leave port numbers unchanged", "alias same_ports [yes|no]",
|
1997-05-23 04:54:03 +00:00
|
|
|
(void*)PKT_ALIAS_SAME_PORTS},
|
|
|
|
{ "use_sockets", NULL, AliasOption, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"allocate host sockets", "alias use_sockets [yes|no]",
|
1997-05-23 04:54:03 +00:00
|
|
|
(void*)PKT_ALIAS_USE_SOCKETS },
|
|
|
|
{ "unregistered_only", NULL, AliasOption, LOCAL_AUTH,
|
1997-06-09 03:27:43 +00:00
|
|
|
"alias unregistered (private) IP address space only",
|
|
|
|
"alias unregistered_only [yes|no]",
|
1997-05-23 04:54:03 +00:00
|
|
|
(void*)PKT_ALIAS_UNREGISTERED_ONLY},
|
|
|
|
{ "help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
|
1997-06-17 02:04:51 +00:00
|
|
|
"Display this message", "alias help|? [command]",
|
1997-05-23 04:54:03 +00:00
|
|
|
(void *)AliasCommands},
|
|
|
|
{ NULL, NULL, NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
AliasCommand(list, argc, argv)
|
|
|
|
struct cmdtab *list;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
if (argc > 0)
|
1997-06-09 03:27:43 +00:00
|
|
|
FindExec(AliasCommands, argc, argv);
|
|
|
|
else if (VarTerm)
|
|
|
|
fprintf(VarTerm, "Use `alias help' to get a list or `alias help <option>'"
|
|
|
|
" for syntax help.\n");
|
1997-05-23 04:54:03 +00:00
|
|
|
else
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogWARN, "alias command must have arguments\n");
|
1997-05-23 04:54:03 +00:00
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1997-05-23 04:54:03 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
AliasEnable(list, argc, argv)
|
|
|
|
struct cmdtab *list;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
1997-06-09 03:27:43 +00:00
|
|
|
if (argc == 1)
|
|
|
|
if (strcasecmp(argv[0], "yes") == 0) {
|
|
|
|
if (!(mode & MODE_ALIAS)) {
|
|
|
|
if (loadAliasHandlers(&VarAliasHandlers) == 0) {
|
|
|
|
mode |= MODE_ALIAS;
|
|
|
|
return 0;
|
1997-05-26 00:44:10 +00:00
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogWARN, "Cannot load alias library\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
} else if (strcasecmp(argv[0], "no") == 0) {
|
|
|
|
if (mode & MODE_ALIAS) {
|
|
|
|
unloadAliasHandlers();
|
|
|
|
mode &= ~MODE_ALIAS;
|
|
|
|
}
|
|
|
|
return 0;
|
1997-05-26 00:44:10 +00:00
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
|
|
|
|
return -1;
|
1997-05-23 04:54:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
AliasOption(list, argc, argv, param)
|
|
|
|
struct cmdtab *list;
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
void* param;
|
|
|
|
{
|
1997-06-09 03:27:43 +00:00
|
|
|
if (argc == 1)
|
|
|
|
if (strcasecmp(argv[0], "yes") == 0) {
|
|
|
|
if (mode & MODE_ALIAS) {
|
1997-05-26 00:44:10 +00:00
|
|
|
VarSetPacketAliasMode((unsigned)param, (unsigned)param);
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
LogPrintf(LogWARN, "alias not enabled\n");
|
|
|
|
} else if (strcmp(argv[0], "no") == 0) {
|
|
|
|
if (mode & MODE_ALIAS) {
|
1997-05-26 00:44:10 +00:00
|
|
|
VarSetPacketAliasMode(0, (unsigned)param);
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
LogPrintf(LogWARN, "alias not enabled\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
1997-05-23 04:54:03 +00:00
|
|
|
}
|