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-11-08 00:28:11 +00:00
|
|
|
* $Id: command.c,v 1.90 1997/11/04 01:16:59 brian Exp $
|
1995-05-30 03:57:47 +00:00
|
|
|
*
|
1995-01-31 06:29:58 +00:00
|
|
|
*/
|
1997-10-26 01:04:02 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <netinet/in_systm.h>
|
1997-05-23 04:54:03 +00:00
|
|
|
#include <netinet/in.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
#include <netinet/ip.h>
|
1997-05-23 04:54:03 +00:00
|
|
|
#include <arpa/inet.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
#include <sys/socket.h>
|
1997-05-23 04:54:03 +00:00
|
|
|
#include <net/route.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
#include <netdb.h>
|
|
|
|
|
1997-05-23 04:54:03 +00:00
|
|
|
#include <alias.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
#include <ctype.h>
|
1997-06-09 03:27:43 +00:00
|
|
|
#include <errno.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <paths.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <termios.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "mbuf.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "defs.h"
|
|
|
|
#include "timer.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
#include "fsm.h"
|
|
|
|
#include "phase.h"
|
|
|
|
#include "lcp.h"
|
|
|
|
#include "ipcp.h"
|
|
|
|
#include "modem.h"
|
|
|
|
#include "command.h"
|
1997-10-26 01:04:02 +00:00
|
|
|
#include "filter.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-25 19:30:05 +00:00
|
|
|
#include "server.h"
|
1997-10-26 01:04:02 +00:00
|
|
|
#include "main.h"
|
|
|
|
#include "route.h"
|
|
|
|
#include "ccp.h"
|
1997-10-26 12:42:13 +00:00
|
|
|
#include "ip.h"
|
1997-10-26 01:04:02 +00:00
|
|
|
#include "slcompress.h"
|
1997-02-22 09:12:36 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
struct in_addr ifnetmask;
|
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
static int ShowCommand(struct cmdtab const *, int, char **);
|
|
|
|
static int TerminalCommand(struct cmdtab const *, int, char **);
|
|
|
|
static int QuitCommand(struct cmdtab const *, int, char **);
|
|
|
|
static int CloseCommand(struct cmdtab const *, int, char **);
|
|
|
|
static int DialCommand(struct cmdtab const *, int, char **);
|
|
|
|
static int DownCommand(struct cmdtab const *, int, char **);
|
|
|
|
static int SetCommand(struct cmdtab const *, int, char **);
|
|
|
|
static int AddCommand(struct cmdtab const *, int, char **);
|
|
|
|
static int DeleteCommand(struct cmdtab const *, int, char **);
|
|
|
|
static int BgShellCommand(struct cmdtab const *, int, char **);
|
|
|
|
static int FgShellCommand(struct cmdtab const *, int, char **);
|
|
|
|
static int ShellCommand(struct cmdtab const *, int, char **, int);
|
1997-10-26 01:04:02 +00:00
|
|
|
static int AliasCommand(struct cmdtab const *, int, char **);
|
|
|
|
static int AliasEnable(struct cmdtab const *, int, char **);
|
|
|
|
static int AliasOption(struct cmdtab const *, int, char **, void *);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
static int
|
1997-08-25 00:29:32 +00:00
|
|
|
HelpCommand(struct cmdtab const * list,
|
|
|
|
int argc,
|
|
|
|
char **argv,
|
|
|
|
struct cmdtab const * plist)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1997-08-25 00:29:32 +00:00
|
|
|
struct cmdtab const *cmd;
|
1995-01-31 06:29:58 +00:00
|
|
|
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-08-25 00:29:32 +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
|
|
|
}
|
|
|
|
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++;
|
|
|
|
}
|
|
|
|
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
|
1997-11-04 01:17:05 +00:00
|
|
|
IsInteractive(int Display)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
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-11-04 01:17:05 +00:00
|
|
|
if (Display && VarTerm)
|
1997-06-09 03:27:43 +00:00
|
|
|
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
|
1997-08-25 00:29:32 +00:00
|
|
|
DialCommand(struct cmdtab const * cmdlist, int argc, char **argv)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1995-10-08 14:57:32 +00:00
|
|
|
int tries;
|
1997-06-23 23:10:13 +00:00
|
|
|
int res;
|
1995-10-08 14:57:32 +00:00
|
|
|
|
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 (argc > 0) {
|
|
|
|
if (SelectSystem(*argv, CONFFILE) < 0) {
|
1997-06-09 03:27:43 +00:00
|
|
|
if (VarTerm)
|
1997-08-25 00:29:32 +00:00
|
|
|
fprintf(VarTerm, "%s: not found.\n", *argv);
|
1997-06-09 03:27:43 +00:00
|
|
|
return -1;
|
1995-01-31 06:29:58 +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);
|
1997-11-08 00:28:11 +00:00
|
|
|
if (OpenModem() < 0) {
|
1997-06-09 03:27:43 +00:00
|
|
|
if (VarTerm)
|
1997-08-25 00:29:32 +00:00
|
|
|
fprintf(VarTerm, "Failed to open modem.\n");
|
1995-10-08 14:57:32 +00:00
|
|
|
break;
|
|
|
|
}
|
1997-06-23 23:10:13 +00:00
|
|
|
if ((res = DialModem()) == EX_DONE) {
|
1997-10-24 22:36:31 +00:00
|
|
|
nointr_sleep(1);
|
1995-10-08 14:57:32 +00:00
|
|
|
ModemTimeout();
|
|
|
|
PacketMode();
|
|
|
|
break;
|
1997-06-23 23:10:13 +00:00
|
|
|
} else if (res == EX_SIG)
|
|
|
|
return 1;
|
1995-10-08 14:57:32 +00:00
|
|
|
} while (VarDialTries == 0 || tries < VarDialTries);
|
1997-06-09 03:27:43 +00:00
|
|
|
|
|
|
|
return 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-08-21 16:21:39 +00:00
|
|
|
static int
|
1997-08-25 00:29:32 +00:00
|
|
|
SetLoopback(struct cmdtab const * cmdlist, int argc, char **argv)
|
1997-08-21 16:21:39 +00:00
|
|
|
{
|
|
|
|
if (argc == 1)
|
|
|
|
if (!strcasecmp(*argv, "on"))
|
|
|
|
VarLoopback = 1;
|
|
|
|
else if (!strcasecmp(*argv, "off"))
|
|
|
|
VarLoopback = 0;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1995-09-02 17:20:54 +00:00
|
|
|
static int
|
1997-08-25 00:29:32 +00:00
|
|
|
BgShellCommand(struct cmdtab const * cmdlist, int argc, char **argv)
|
1997-08-18 20:15:10 +00:00
|
|
|
{
|
|
|
|
if (argc == 0)
|
|
|
|
return -1;
|
|
|
|
return ShellCommand(cmdlist, argc, argv, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1997-08-25 00:29:32 +00:00
|
|
|
FgShellCommand(struct cmdtab const * cmdlist, int argc, char **argv)
|
1997-08-18 20:15:10 +00:00
|
|
|
{
|
|
|
|
return ShellCommand(cmdlist, argc, argv, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1997-08-25 00:29:32 +00:00
|
|
|
ShellCommand(struct cmdtab const * cmdlist, int argc, char **argv, int bg)
|
1995-09-02 17:20:54 +00:00
|
|
|
{
|
|
|
|
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-25 02:04:35 +00:00
|
|
|
/* we're only allowed to shell when we run ppp 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
|
|
|
}
|
1997-06-25 02:04:35 +00:00
|
|
|
#endif
|
|
|
|
#ifdef NO_SHELL_IN_AUTO_INTERACTIVE
|
1997-08-25 00:29:32 +00:00
|
|
|
|
1997-06-25 02:04:35 +00:00
|
|
|
/*
|
1997-08-25 00:29:32 +00:00
|
|
|
* we want to stop shell commands when we've got a telnet connection to an
|
|
|
|
* auto mode ppp
|
1997-06-25 02:04:35 +00:00
|
|
|
*/
|
1997-08-25 00:29:32 +00:00
|
|
|
if ((mode & (MODE_AUTO | MODE_INTER)) == (MODE_AUTO | MODE_INTER)) {
|
|
|
|
LogPrintf(LogWARN, "Shell is not allowed interactively in auto mode\n");
|
1997-06-09 03:27:43 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
if (argc == 0)
|
1997-08-18 20:15:10 +00:00
|
|
|
if (!(mode & MODE_INTER)) {
|
|
|
|
LogPrintf(LogWARN, "Can only start an interactive shell in"
|
1997-08-25 00:29:32 +00:00
|
|
|
" interactive mode\n");
|
1997-08-18 20:15:10 +00:00
|
|
|
return 1;
|
|
|
|
} else if (bg) {
|
|
|
|
LogPrintf(LogWARN, "Can only start an interactive shell in"
|
1997-08-25 00:29:32 +00:00
|
|
|
" the foreground mode\n");
|
1997-08-18 20:15:10 +00:00
|
|
|
return 1;
|
1997-09-09 23:13:31 +00:00
|
|
|
} else if (mode&(MODE_AUTO|MODE_DEDICATED|MODE_DIRECT)) {
|
|
|
|
LogPrintf(LogWARN, "Can't start an interactive shell from"
|
|
|
|
" a telnet session\n");
|
|
|
|
return 1;
|
1997-08-18 20:15:10 +00:00
|
|
|
}
|
1997-08-25 00:29:32 +00:00
|
|
|
if ((shell = getenv("SHELL")) == 0)
|
1997-06-09 03:27:43 +00:00
|
|
|
shell = _PATH_BSHELL;
|
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
if ((shpid = fork()) == 0) {
|
|
|
|
int dtablesize, i, fd;
|
1997-06-09 03:27:43 +00:00
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
if (VarTerm)
|
|
|
|
fd = fileno(VarTerm);
|
|
|
|
else if ((fd = open("/dev/null", O_RDWR)) == -1) {
|
|
|
|
LogPrintf(LogALERT, "Failed to open /dev/null: %s\n", strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
dup2(fd, i);
|
|
|
|
|
|
|
|
if (fd > 2)
|
|
|
|
if (VarTerm) {
|
|
|
|
oVarTerm = VarTerm;
|
|
|
|
VarTerm = 0;
|
|
|
|
if (oVarTerm && oVarTerm != stdout)
|
|
|
|
fclose(oVarTerm);
|
|
|
|
} else
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
for (dtablesize = getdtablesize(), i = 3; i < dtablesize; i++)
|
|
|
|
(void) close(i);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We are running setuid, we should change to real user for avoiding
|
|
|
|
* security problems.
|
|
|
|
*/
|
|
|
|
if (setgid(getgid()) < 0) {
|
|
|
|
LogPrintf(LogERROR, "setgid: %s\n", strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (setuid(getuid()) < 0) {
|
|
|
|
LogPrintf(LogERROR, "setuid: %s\n", strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
TtyOldMode();
|
|
|
|
if (argc > 0) {
|
|
|
|
/* substitute pseudo args */
|
|
|
|
for (i = 1; i < argc; i++)
|
|
|
|
if (strcasecmp(argv[i], "HISADDR") == 0)
|
|
|
|
argv[i] = strdup(inet_ntoa(IpcpInfo.his_ipaddr));
|
|
|
|
else if (strcasecmp(argv[i], "INTERFACE") == 0)
|
|
|
|
argv[i] = strdup(IfDevName);
|
|
|
|
else if (strcasecmp(argv[i], "MYADDR") == 0)
|
|
|
|
argv[i] = strdup(inet_ntoa(IpcpInfo.want_ipaddr));
|
|
|
|
if (bg) {
|
|
|
|
pid_t p;
|
|
|
|
|
|
|
|
p = getpid();
|
|
|
|
if (daemon(1, 1) == -1) {
|
1997-08-31 22:59:49 +00:00
|
|
|
LogPrintf(LogERROR, "%d: daemon: %s\n", p, strerror(errno));
|
1997-08-25 00:29:32 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
1997-10-12 01:49:37 +00:00
|
|
|
if (VarTerm)
|
|
|
|
fprintf(VarTerm, "ppp: Pausing until %s finishes\n", argv[0]);
|
1997-08-25 00:29:32 +00:00
|
|
|
(void) execvp(argv[0], argv);
|
1997-10-12 01:49:37 +00:00
|
|
|
} else {
|
|
|
|
if (VarTerm)
|
|
|
|
fprintf(VarTerm, "ppp: Pausing until %s finishes\n", shell);
|
1997-08-25 00:29:32 +00:00
|
|
|
(void) execl(shell, shell, NULL);
|
1997-10-12 01:49:37 +00:00
|
|
|
}
|
1997-08-25 00:29:32 +00:00
|
|
|
|
|
|
|
LogPrintf(LogWARN, "exec() of %s failed\n", argc > 0 ? argv[0] : shell);
|
|
|
|
exit(255);
|
|
|
|
}
|
|
|
|
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;
|
1997-08-25 00:29:32 +00:00
|
|
|
|
|
|
|
(void) waitpid(shpid, &status, 0);
|
1995-09-02 17:20:54 +00:00
|
|
|
}
|
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
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
return (0);
|
1995-09-02 17:20:54 +00:00
|
|
|
}
|
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
static struct cmdtab const Commands[] = {
|
1997-08-25 00:29:32 +00:00
|
|
|
{"accept", NULL, AcceptCommand, LOCAL_AUTH,
|
|
|
|
"accept option request", "accept option .."},
|
|
|
|
{"add", NULL, AddCommand, LOCAL_AUTH,
|
|
|
|
"add route", "add dest mask gateway"},
|
|
|
|
{"bg", "!bg", BgShellCommand, LOCAL_AUTH,
|
|
|
|
"Run a command in the background", "[!]bg command"},
|
|
|
|
{"close", NULL, CloseCommand, LOCAL_AUTH,
|
|
|
|
"Close connection", "close"},
|
|
|
|
{"delete", NULL, DeleteCommand, LOCAL_AUTH,
|
|
|
|
"delete route", "delete ALL | dest [gateway [mask]]"},
|
|
|
|
{"deny", NULL, DenyCommand, LOCAL_AUTH,
|
|
|
|
"Deny option request", "deny option .."},
|
|
|
|
{"dial", "call", DialCommand, LOCAL_AUTH,
|
|
|
|
"Dial and login", "dial|call [remote]"},
|
|
|
|
{"disable", NULL, DisableCommand, LOCAL_AUTH,
|
|
|
|
"Disable option", "disable option .."},
|
|
|
|
{"display", NULL, DisplayCommand, LOCAL_AUTH,
|
|
|
|
"Display option configs", "display"},
|
|
|
|
{"enable", NULL, EnableCommand, LOCAL_AUTH,
|
|
|
|
"Enable option", "enable option .."},
|
|
|
|
{"passwd", NULL, LocalAuthCommand, LOCAL_NO_AUTH,
|
1997-09-04 00:38:22 +00:00
|
|
|
"Password for manipulation", "passwd LocalPassword"},
|
1997-08-25 00:29:32 +00:00
|
|
|
{"load", NULL, LoadCommand, LOCAL_AUTH,
|
|
|
|
"Load settings", "load [remote]"},
|
|
|
|
{"save", NULL, SaveCommand, LOCAL_AUTH,
|
|
|
|
"Save settings", "save"},
|
|
|
|
{"set", "setup", SetCommand, LOCAL_AUTH,
|
|
|
|
"Set parameters", "set[up] var value"},
|
|
|
|
{"shell", "!", FgShellCommand, LOCAL_AUTH,
|
|
|
|
"Run a subshell", "shell|! [sh command]"},
|
|
|
|
{"show", NULL, ShowCommand, LOCAL_AUTH,
|
1997-09-21 13:08:00 +00:00
|
|
|
"Show status and statistics", "show var"},
|
1997-08-25 00:29:32 +00:00
|
|
|
{"term", NULL, TerminalCommand, LOCAL_AUTH,
|
|
|
|
"Enter to terminal mode", "term"},
|
|
|
|
{"alias", NULL, AliasCommand, LOCAL_AUTH,
|
|
|
|
"alias control", "alias option [yes|no]"},
|
|
|
|
{"quit", "bye", QuitCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
|
|
|
|
"Quit PPP program", "quit|bye [all]"},
|
|
|
|
{"help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
|
|
|
|
"Display this message", "help|? [command]", (void *) Commands},
|
|
|
|
{NULL, "down", DownCommand, LOCAL_AUTH,
|
|
|
|
"Generate down event", "down"},
|
|
|
|
{NULL, NULL, NULL},
|
1995-01-31 06:29:58 +00:00
|
|
|
};
|
|
|
|
|
1997-08-21 16:21:39 +00:00
|
|
|
static int
|
|
|
|
ShowLoopback()
|
|
|
|
{
|
|
|
|
if (VarTerm)
|
|
|
|
fprintf(VarTerm, "Local loopback is %s\n", VarLoopback ? "on" : "off");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1997-08-25 00:29:32 +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;
|
1997-11-04 01:17:05 +00:00
|
|
|
|
|
|
|
fprintf(VarTerm, "Log: ");
|
|
|
|
for (i = LogMIN; i <= LogMAX; i++)
|
|
|
|
if (LogIsKept(i) & LOG_KEPT_SYSLOG)
|
1997-06-09 03:27:43 +00:00
|
|
|
fprintf(VarTerm, " %s", LogName(i));
|
1997-11-04 01:17:05 +00:00
|
|
|
|
|
|
|
fprintf(VarTerm, "\nLocal:");
|
|
|
|
for (i = LogMIN; i <= LogMAX; i++)
|
|
|
|
if (LogIsKept(i) & LOG_KEPT_LOCAL)
|
|
|
|
fprintf(VarTerm, " %s", LogName(i));
|
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
fprintf(VarTerm, "\n");
|
|
|
|
|
|
|
|
return 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
static int
|
|
|
|
ShowEscape()
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
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])
|
1997-08-25 00:29:32 +00:00
|
|
|
for (bit = 0; bit < 8; bit++)
|
|
|
|
if (EscMap[code] & (1 << bit))
|
|
|
|
fprintf(VarTerm, " 0x%02x", (code << 3) + bit);
|
1997-06-09 03:27:43 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
static int
|
|
|
|
ShowTimeout()
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1997-06-09 03:27:43 +00:00
|
|
|
if (!VarTerm)
|
|
|
|
return 0;
|
|
|
|
fprintf(VarTerm, " Idle Timer: %d secs LQR Timer: %d secs"
|
1997-08-25 00:29:32 +00:00
|
|
|
" Retry Timer: %d secs\n", VarIdleTimeout, VarLqrTimeout,
|
|
|
|
VarRetryTimeout);
|
1997-06-09 03:27:43 +00:00
|
|
|
return 1;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
static int
|
|
|
|
ShowStopped()
|
1997-08-17 20:45:50 +00:00
|
|
|
{
|
|
|
|
if (!VarTerm)
|
|
|
|
return 0;
|
1997-08-20 23:47:53 +00:00
|
|
|
|
|
|
|
fprintf(VarTerm, " Stopped Timer: LCP: ");
|
|
|
|
if (!LcpFsm.StoppedTimer.load)
|
|
|
|
fprintf(VarTerm, "Disabled");
|
|
|
|
else
|
|
|
|
fprintf(VarTerm, "%ld secs", LcpFsm.StoppedTimer.load / SECTICKS);
|
|
|
|
|
|
|
|
fprintf(VarTerm, ", IPCP: ");
|
|
|
|
if (!IpcpFsm.StoppedTimer.load)
|
|
|
|
fprintf(VarTerm, "Disabled");
|
|
|
|
else
|
|
|
|
fprintf(VarTerm, "%ld secs", IpcpFsm.StoppedTimer.load / SECTICKS);
|
|
|
|
|
|
|
|
fprintf(VarTerm, ", CCP: ");
|
|
|
|
if (!CcpFsm.StoppedTimer.load)
|
|
|
|
fprintf(VarTerm, "Disabled");
|
1997-08-17 20:45:50 +00:00
|
|
|
else
|
1997-08-20 23:47:53 +00:00
|
|
|
fprintf(VarTerm, "%ld secs", CcpFsm.StoppedTimer.load / SECTICKS);
|
|
|
|
|
|
|
|
fprintf(VarTerm, "\n");
|
|
|
|
|
1997-08-17 20:45:50 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
static int
|
|
|
|
ShowAuthKey()
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1997-06-09 03:27:43 +00:00
|
|
|
if (!VarTerm)
|
|
|
|
return 0;
|
|
|
|
fprintf(VarTerm, "AuthName = %s\n", VarAuthName);
|
|
|
|
fprintf(VarTerm, "AuthKey = %s\n", VarAuthKey);
|
1997-09-25 00:52:37 +00:00
|
|
|
#ifdef HAVE_DES
|
|
|
|
fprintf(VarTerm, "Encrypt = %s\n", VarMSChap ? "MSChap" : "MD5" );
|
|
|
|
#endif
|
1997-06-09 03:27:43 +00:00
|
|
|
return 1;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
static int
|
|
|
|
ShowVersion()
|
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-08-25 00:29:32 +00:00
|
|
|
static int
|
|
|
|
ShowInitialMRU()
|
1997-06-01 01:13:04 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
static int
|
|
|
|
ShowPreferredMTU()
|
1997-06-01 01:13:04 +00:00
|
|
|
{
|
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-08-25 00:29:32 +00:00
|
|
|
static int
|
|
|
|
ShowReconnect()
|
1997-04-21 01:02:02 +00:00
|
|
|
{
|
1997-06-09 03:27:43 +00:00
|
|
|
if (!VarTerm)
|
|
|
|
return 0;
|
|
|
|
fprintf(VarTerm, " Reconnect Timer: %d, %d tries\n",
|
1997-08-25 00:29:32 +00:00
|
|
|
VarReconnectTimer, VarReconnectTries);
|
1997-06-09 03:27:43 +00:00
|
|
|
return 1;
|
1997-04-21 01:02:02 +00:00
|
|
|
}
|
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
static int
|
|
|
|
ShowRedial()
|
1995-10-08 14:57:32 +00:00
|
|
|
{
|
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);
|
1997-08-25 00:29: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-08-25 00:29:32 +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-08-25 00:29:32 +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
|
1997-08-25 00:29:32 +00:00
|
|
|
static int
|
|
|
|
ShowMSExt()
|
1996-10-06 13:32:37 +00:00
|
|
|
{
|
1997-06-09 03:27:43 +00:00
|
|
|
if (!VarTerm)
|
|
|
|
return 0;
|
1997-08-25 00:29:32 +00:00
|
|
|
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]));
|
1997-06-09 03:27:43 +00:00
|
|
|
return 1;
|
1996-10-06 13:32:37 +00:00
|
|
|
}
|
1997-08-25 00:29:32 +00:00
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
#endif
|
1995-10-08 14:57:32 +00:00
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
static struct cmdtab const ShowCommands[] = {
|
1997-08-25 00:29:32 +00:00
|
|
|
{"afilter", NULL, ShowAfilter, LOCAL_AUTH,
|
|
|
|
"Show keep Alive filters", "show afilter option .."},
|
|
|
|
{"auth", NULL, ShowAuthKey, LOCAL_AUTH,
|
1997-09-17 23:17:57 +00:00
|
|
|
"Show auth name, key and algorithm", "show auth"},
|
1997-08-25 00:29:32 +00:00
|
|
|
{"ccp", NULL, ReportCcpStatus, LOCAL_AUTH,
|
|
|
|
"Show CCP status", "show cpp"},
|
|
|
|
{"compress", NULL, ReportCompress, LOCAL_AUTH,
|
1997-09-21 13:08:00 +00:00
|
|
|
"Show compression statistics", "show compress"},
|
1997-08-25 00:29:32 +00:00
|
|
|
{"dfilter", NULL, ShowDfilter, LOCAL_AUTH,
|
|
|
|
"Show Demand filters", "show dfilteroption .."},
|
|
|
|
{"escape", NULL, ShowEscape, LOCAL_AUTH,
|
|
|
|
"Show escape characters", "show escape"},
|
|
|
|
{"hdlc", NULL, ReportHdlcStatus, LOCAL_AUTH,
|
|
|
|
"Show HDLC error summary", "show hdlc"},
|
|
|
|
{"ifilter", NULL, ShowIfilter, LOCAL_AUTH,
|
|
|
|
"Show Input filters", "show ifilter option .."},
|
|
|
|
{"ipcp", NULL, ReportIpcpStatus, LOCAL_AUTH,
|
|
|
|
"Show IPCP status", "show ipcp"},
|
|
|
|
{"lcp", NULL, ReportLcpStatus, LOCAL_AUTH,
|
|
|
|
"Show LCP status", "show lcp"},
|
|
|
|
{"loopback", NULL, ShowLoopback, LOCAL_AUTH,
|
|
|
|
"Show current loopback setting", "show loopback"},
|
|
|
|
{"log", NULL, ShowLogLevel, LOCAL_AUTH,
|
|
|
|
"Show current log level", "show log"},
|
|
|
|
{"mem", NULL, ShowMemMap, LOCAL_AUTH,
|
|
|
|
"Show memory map", "show mem"},
|
|
|
|
{"modem", NULL, ShowModemStatus, LOCAL_AUTH,
|
|
|
|
"Show modem setups", "show modem"},
|
|
|
|
{"mru", NULL, ShowInitialMRU, LOCAL_AUTH,
|
|
|
|
"Show Initial MRU", "show mru"},
|
|
|
|
{"mtu", NULL, ShowPreferredMTU, LOCAL_AUTH,
|
|
|
|
"Show Preferred MTU", "show mtu"},
|
|
|
|
{"ofilter", NULL, ShowOfilter, LOCAL_AUTH,
|
|
|
|
"Show Output filters", "show ofilter option .."},
|
|
|
|
{"proto", NULL, ReportProtStatus, LOCAL_AUTH,
|
|
|
|
"Show protocol summary", "show proto"},
|
|
|
|
{"reconnect", NULL, ShowReconnect, LOCAL_AUTH,
|
|
|
|
"Show Reconnect timer,tries", "show reconnect"},
|
|
|
|
{"redial", NULL, ShowRedial, LOCAL_AUTH,
|
|
|
|
"Show Redial timeout value", "show redial"},
|
|
|
|
{"route", NULL, ShowRoute, LOCAL_AUTH,
|
|
|
|
"Show routing table", "show route"},
|
|
|
|
{"timeout", NULL, ShowTimeout, LOCAL_AUTH,
|
|
|
|
"Show Idle timeout value", "show timeout"},
|
|
|
|
{"stopped", NULL, ShowStopped, LOCAL_AUTH,
|
|
|
|
"Show STOPPED timeout value", "show stopped"},
|
1997-06-09 03:27:43 +00:00
|
|
|
#ifndef NOMSEXT
|
1997-08-25 00:29:32 +00:00
|
|
|
{"msext", NULL, ShowMSExt, LOCAL_AUTH,
|
|
|
|
"Show MS PPP extentions", "show msext"},
|
1997-06-09 03:27:43 +00:00
|
|
|
#endif
|
1997-08-25 00:29:32 +00:00
|
|
|
{"version", NULL, ShowVersion, LOCAL_NO_AUTH | LOCAL_AUTH,
|
|
|
|
"Show version string", "show version"},
|
|
|
|
{"help", "?", HelpCommand, LOCAL_NO_AUTH | LOCAL_AUTH,
|
|
|
|
"Display this message", "show help|? [command]", (void *) ShowCommands},
|
|
|
|
{NULL, NULL, NULL},
|
1995-01-31 06:29:58 +00:00
|
|
|
};
|
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
static struct cmdtab const *
|
1997-08-25 00:29:32 +00:00
|
|
|
FindCommand(struct cmdtab const * cmds, char *str, int *pmatch)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1997-06-09 03:27:43 +00:00
|
|
|
int nmatch;
|
|
|
|
int len;
|
1997-08-25 00:29:32 +00:00
|
|
|
struct cmdtab const *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') {
|
1997-08-25 00:29:32 +00:00
|
|
|
*pmatch = 1;
|
|
|
|
return cmds;
|
1997-06-09 03:27:43 +00:00
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
nmatch++;
|
|
|
|
found = cmds;
|
1997-08-25 00:29:32 +00:00
|
|
|
} else if (cmds->alias && strncasecmp(str, cmds->alias, len) == 0) {
|
1997-06-09 03:27:43 +00:00
|
|
|
if (cmds->alias[len] == '\0') {
|
1997-08-25 00:29:32 +00:00
|
|
|
*pmatch = 1;
|
|
|
|
return cmds;
|
1997-06-09 03:27:43 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
static int
|
1997-08-25 00:29:32 +00:00
|
|
|
FindExec(struct cmdtab const * cmdlist, int argc, char **argv)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1997-08-25 00:29:32 +00:00
|
|
|
struct cmdtab const *cmd;
|
1995-01-31 06:29:58 +00:00
|
|
|
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);
|
1997-08-25 00:29:32 +00:00
|
|
|
else if (cmd && (cmd->lauth & VarLocalAuth))
|
1997-09-09 23:23:24 +00:00
|
|
|
val = (cmd->func) (cmd, argc-1, argv+1, cmd->args);
|
1995-01-31 06:29:58 +00:00
|
|
|
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);
|
1997-08-25 00:29:32 +00:00
|
|
|
else if (val)
|
1997-06-09 03:27:43 +00:00
|
|
|
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;
|
|
|
|
|
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
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
if (VarLocalAuth == LOCAL_AUTH)
|
1995-02-26 12:18:08 +00:00
|
|
|
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
|
1997-08-25 00:29:32 +00:00
|
|
|
DecodeCommand(char *buff, int nb, int prompt)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
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
|
1997-08-25 00:29:32 +00:00
|
|
|
ShowCommand(struct cmdtab const * list, int argc, char **argv)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
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
|
1997-08-25 00:29:32 +00:00
|
|
|
TerminalCommand(struct cmdtab const * list, int argc, char **argv)
|
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 1;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1997-11-04 01:17:05 +00:00
|
|
|
if (!IsInteractive(1))
|
1997-08-25 00:29:32 +00:00
|
|
|
return (1);
|
1997-11-08 00:28:11 +00:00
|
|
|
if (OpenModem() < 0) {
|
1997-06-09 03:27:43 +00:00
|
|
|
if (VarTerm)
|
|
|
|
fprintf(VarTerm, "Failed to open modem.\n");
|
1997-08-25 00:29:32 +00:00
|
|
|
return (1);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
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();
|
1997-08-25 00:29:32 +00:00
|
|
|
return (0);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1997-08-25 00:29:32 +00:00
|
|
|
QuitCommand(struct cmdtab const * list, int argc, char **argv)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1997-06-09 03:27:43 +00:00
|
|
|
FILE *oVarTerm;
|
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
if (mode & (MODE_DIRECT | MODE_DEDICATED | MODE_AUTO)) {
|
1997-09-04 00:38:22 +00:00
|
|
|
if (argc > 0 && !strcasecmp(*argv, "all") && (VarLocalAuth & LOCAL_AUTH)) {
|
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)
|
1997-08-25 00:29:32 +00:00
|
|
|
fclose(oVarTerm);
|
1997-09-04 00:38:22 +00:00
|
|
|
Cleanup(EX_NORMAL);
|
|
|
|
} else if (VarTerm) {
|
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)
|
1997-08-25 00:29:32 +00:00
|
|
|
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
|
1997-08-25 00:29:32 +00:00
|
|
|
CloseCommand(struct cmdtab const * list, int argc, char **argv)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
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)
|
1997-08-25 00:29:32 +00:00
|
|
|
Cleanup(EX_NORMAL);
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1997-08-25 00:29:32 +00:00
|
|
|
DownCommand(struct cmdtab const * list, int argc, char **argv)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
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
|
1997-08-25 00:29:32 +00:00
|
|
|
SetModemSpeed(struct cmdtab const * list, int argc, char **argv)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
int speed;
|
|
|
|
|
|
|
|
if (argc > 0) {
|
1997-09-16 23:15:16 +00:00
|
|
|
if (strcasecmp(*argv, "sync") == 0) {
|
1995-02-26 12:18:08 +00:00
|
|
|
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
|
1997-08-25 00:29:32 +00:00
|
|
|
SetReconnect(struct cmdtab const * list, int argc, char **argv)
|
1997-04-21 01:02:02 +00:00
|
|
|
{
|
|
|
|
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
|
1997-08-25 00:29:32 +00:00
|
|
|
SetRedialTimeout(struct cmdtab const * list, int argc, char **argv)
|
1995-10-08 14:57:32 +00:00
|
|
|
{
|
|
|
|
int timeout;
|
|
|
|
int tries;
|
1997-04-14 23:48:20 +00:00
|
|
|
char *dot;
|
1995-10-08 14:57:32 +00:00
|
|
|
|
1997-08-25 00:29: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-10-26 01:04:02 +00:00
|
|
|
randinit();
|
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");
|
1997-08-25 00:29:32 +00:00
|
|
|
return -1;
|
1995-10-08 14:57:32 +00:00
|
|
|
}
|
|
|
|
}
|
1997-04-14 23:48:20 +00:00
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
dot = strchr(argv[0], '.');
|
1997-04-14 23:48:20 +00:00
|
|
|
if (dot) {
|
|
|
|
if (strcasecmp(++dot, "random") == 0) {
|
1997-08-25 00:29:32 +00:00
|
|
|
VarRedialNextTimeout = -1;
|
1997-10-26 01:04:02 +00:00
|
|
|
randinit();
|
1997-08-25 00:29:32 +00:00
|
|
|
} else {
|
|
|
|
timeout = atoi(dot);
|
|
|
|
if (timeout >= 0)
|
|
|
|
VarRedialNextTimeout = timeout;
|
|
|
|
else {
|
|
|
|
LogPrintf(LogWARN, "Invalid next redial timeout\n");
|
1997-06-09 03:27:43 +00:00
|
|
|
return -1;
|
1997-08-25 00:29:32 +00:00
|
|
|
}
|
1997-04-14 23:48:20 +00:00
|
|
|
}
|
1997-08-25 00:29:32 +00:00
|
|
|
} else
|
|
|
|
VarRedialNextTimeout = NEXT_REDIAL_PERIOD; /* Default next timeout */
|
1997-04-14 23:48:20 +00:00
|
|
|
|
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-08-17 20:45:50 +00:00
|
|
|
static int
|
1997-08-25 00:29:32 +00:00
|
|
|
SetStoppedTimeout(struct cmdtab const * list, int argc, char **argv)
|
1997-08-17 20:45:50 +00:00
|
|
|
{
|
1997-08-20 23:47:53 +00:00
|
|
|
LcpFsm.StoppedTimer.load = 0;
|
|
|
|
IpcpFsm.StoppedTimer.load = 0;
|
|
|
|
CcpFsm.StoppedTimer.load = 0;
|
|
|
|
if (argc <= 3) {
|
|
|
|
if (argc > 0) {
|
|
|
|
LcpFsm.StoppedTimer.load = atoi(argv[0]) * SECTICKS;
|
|
|
|
if (argc > 1) {
|
1997-08-25 00:29:32 +00:00
|
|
|
IpcpFsm.StoppedTimer.load = atoi(argv[1]) * SECTICKS;
|
|
|
|
if (argc > 2)
|
|
|
|
CcpFsm.StoppedTimer.load = atoi(argv[2]) * SECTICKS;
|
1997-08-20 23:47:53 +00:00
|
|
|
}
|
|
|
|
}
|
1997-08-17 20:45:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1997-06-25 19:30:05 +00:00
|
|
|
static int
|
1997-08-25 00:29:32 +00:00
|
|
|
SetServer(struct cmdtab const * list, int argc, char **argv)
|
1997-06-25 19:30:05 +00:00
|
|
|
{
|
|
|
|
int res = -1;
|
|
|
|
|
1997-06-30 03:03:38 +00:00
|
|
|
if (argc > 0 && argc < 3)
|
1997-06-25 19:30:05 +00:00
|
|
|
if (strcasecmp(argv[0], "none") == 0) {
|
|
|
|
ServerClose();
|
|
|
|
LogPrintf(LogPHASE, "Disabling server port.\n");
|
|
|
|
res = 0;
|
1997-06-30 03:03:38 +00:00
|
|
|
} else if (*argv[0] == '/') {
|
|
|
|
mode_t mask;
|
1997-08-25 00:29:32 +00:00
|
|
|
|
1997-06-30 03:03:38 +00:00
|
|
|
umask(mask = umask(0));
|
|
|
|
if (argc == 2) {
|
1997-08-25 00:29:32 +00:00
|
|
|
unsigned m;
|
|
|
|
|
|
|
|
if (sscanf(argv[1], "%o", &m) == 1)
|
|
|
|
mask = m;
|
1997-06-30 03:03:38 +00:00
|
|
|
}
|
|
|
|
res = ServerLocalOpen(argv[0], mask);
|
1997-07-12 19:22:34 +00:00
|
|
|
} else {
|
|
|
|
int port;
|
1997-08-25 00:29:32 +00:00
|
|
|
|
1997-07-12 19:22:34 +00:00
|
|
|
if (strspn(argv[0], "0123456789") != strlen(argv[0])) {
|
1997-08-25 00:29:32 +00:00
|
|
|
struct servent *s;
|
|
|
|
|
|
|
|
if ((s = getservbyname(argv[0], "tcp")) == NULL) {
|
|
|
|
port = 0;
|
|
|
|
LogPrintf(LogWARN, "%s: Invalid port or service\n", argv[0]);
|
|
|
|
} else
|
|
|
|
port = ntohs(s->s_port);
|
1997-07-12 19:22:34 +00:00
|
|
|
} else
|
1997-08-25 00:29:32 +00:00
|
|
|
port = atoi(argv[0]);
|
1997-07-12 19:22:34 +00:00
|
|
|
if (port)
|
1997-08-25 00:29:32 +00:00
|
|
|
res = ServerTcpOpen(port);
|
1997-07-12 19:22:34 +00:00
|
|
|
}
|
1997-06-25 19:30:05 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
1997-04-21 01:02:02 +00:00
|
|
|
static int
|
1997-08-25 00:29:32 +00:00
|
|
|
SetModemParity(struct cmdtab const * list, int argc, char **argv)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
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-08-25 00:29:32 +00:00
|
|
|
SetLogLevel(struct cmdtab const * list, int argc, char **argv)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1997-06-09 03:27:43 +00:00
|
|
|
int i;
|
|
|
|
int res;
|
|
|
|
char *arg;
|
1997-11-04 01:17:05 +00:00
|
|
|
void (*Discard)(int), (*Keep)(int);
|
|
|
|
void (*DiscardAll)(void);
|
1997-06-09 03:27:43 +00:00
|
|
|
|
|
|
|
res = 0;
|
1997-11-04 01:17:05 +00:00
|
|
|
if (strcasecmp(argv[0], "local")) {
|
|
|
|
Discard = LogDiscard;
|
|
|
|
Keep = LogKeep;
|
|
|
|
DiscardAll = LogDiscardAll;
|
|
|
|
} else {
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
Discard = LogDiscardLocal;
|
|
|
|
Keep = LogKeepLocal;
|
|
|
|
DiscardAll = LogDiscardAllLocal;
|
|
|
|
}
|
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
if (argc == 0 || (argv[0][0] != '+' && argv[0][0] != '-'))
|
1997-11-04 01:17:05 +00:00
|
|
|
(*DiscardAll)();
|
1997-06-09 03:27:43 +00:00
|
|
|
while (argc--) {
|
|
|
|
arg = **argv == '+' || **argv == '-' ? *argv + 1 : *argv;
|
|
|
|
for (i = LogMIN; i <= LogMAX; i++)
|
|
|
|
if (strcasecmp(arg, LogName(i)) == 0) {
|
1997-08-25 00:29:32 +00:00
|
|
|
if (**argv == '-')
|
1997-11-04 01:17:05 +00:00
|
|
|
(*Discard)(i);
|
1997-08-25 00:29:32 +00:00
|
|
|
else
|
1997-11-04 01:17:05 +00:00
|
|
|
(*Keep)(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
|
1997-08-25 00:29:32 +00:00
|
|
|
SetEscape(struct cmdtab const * list, int argc, char **argv)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
int code;
|
|
|
|
|
|
|
|
for (code = 0; code < 33; code++)
|
|
|
|
EscMap[code] = 0;
|
|
|
|
while (argc-- > 0) {
|
|
|
|
sscanf(*argv++, "%x", &code);
|
|
|
|
code &= 0xff;
|
1997-08-25 00:29:32 +00:00
|
|
|
EscMap[code >> 3] |= (1 << (code & 7));
|
1995-01-31 06:29:58 +00:00
|
|
|
EscMap[32] = 1;
|
|
|
|
}
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1997-08-25 00:29:32 +00:00
|
|
|
SetInitialMRU(struct cmdtab const * list, int argc, char **argv)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
return -1;
|
1997-06-01 01:13:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1997-08-25 00:29:32 +00:00
|
|
|
SetPreferredMTU(struct cmdtab const * list, int argc, char **argv)
|
1997-06-01 01:13:04 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
return -1;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1997-08-25 00:29:32 +00:00
|
|
|
SetIdleTimeout(struct cmdtab const * list, int argc, char **argv)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
if (argc-- > 0) {
|
|
|
|
VarIdleTimeout = atoi(*argv++);
|
1997-08-25 00:29:32 +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
|
|
|
}
|
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
static struct in_addr
|
1997-08-25 00:29:32 +00:00
|
|
|
GetIpAddr(char *cp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
struct hostent *hp;
|
|
|
|
struct in_addr ipaddr;
|
|
|
|
|
|
|
|
hp = gethostbyname(cp);
|
|
|
|
if (hp && hp->h_addrtype == AF_INET)
|
1997-10-26 01:04:02 +00:00
|
|
|
memcpy(&ipaddr, hp->h_addr, hp->h_length);
|
1995-01-31 06:29:58 +00:00
|
|
|
else if (inet_aton(cp, &ipaddr) == 0)
|
|
|
|
ipaddr.s_addr = 0;
|
1997-08-25 00:29:32 +00:00
|
|
|
return (ipaddr);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1997-08-25 00:29:32 +00:00
|
|
|
SetInterfaceAddr(struct cmdtab const * list, int argc, char **argv)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
DefMyAddress.ipaddr.s_addr = DefHisAddress.ipaddr.s_addr = 0L;
|
1997-08-19 01:10:24 +00:00
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
if (argc > 4)
|
1997-08-25 00:29:32 +00:00
|
|
|
return -1;
|
1997-06-09 03:27:43 +00:00
|
|
|
|
1997-08-19 01:10:24 +00:00
|
|
|
HaveTriggerAddress = 0;
|
|
|
|
ifnetmask.s_addr = 0;
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
if (argc > 0) {
|
1997-05-10 01:22:19 +00:00
|
|
|
if (ParseAddr(argc, argv++,
|
1997-08-25 00:29:32 +00:00
|
|
|
&DefMyAddress.ipaddr,
|
|
|
|
&DefMyAddress.mask,
|
|
|
|
&DefMyAddress.width) == 0)
|
|
|
|
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-08-25 00:29:32 +00:00
|
|
|
return 2;
|
1995-01-31 06:29:58 +00:00
|
|
|
if (--argc > 0) {
|
1997-08-25 00:29:32 +00:00
|
|
|
ifnetmask = GetIpAddr(*argv);
|
|
|
|
if (--argc > 0) {
|
|
|
|
TriggerAddress = GetIpAddr(*argv);
|
|
|
|
HaveTriggerAddress = 1;
|
1995-07-08 08:28:10 +00:00
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1997-08-19 01:10:24 +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;
|
|
|
|
}
|
1997-08-21 17:07:30 +00:00
|
|
|
IpcpInfo.want_ipaddr.s_addr = DefMyAddress.ipaddr.s_addr;
|
|
|
|
IpcpInfo.his_ipaddr.s_addr = DefHisAddress.ipaddr.s_addr;
|
|
|
|
|
1995-02-26 12:18:08 +00:00
|
|
|
if ((mode & MODE_AUTO) ||
|
1997-08-25 00:29:32 +00:00
|
|
|
((mode & MODE_DEDICATED) && dstsystem)) {
|
1997-05-10 01:22:19 +00:00
|
|
|
if (OsSetIpaddress(DefMyAddress.ipaddr, DefHisAddress.ipaddr, ifnetmask) < 0)
|
1997-08-25 00:29:32 +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
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
static void
|
1997-08-25 00:29:32 +00:00
|
|
|
SetMSEXT(struct in_addr * pri_addr,
|
|
|
|
struct in_addr * sec_addr,
|
|
|
|
int argc,
|
|
|
|
char **argv)
|
1996-10-06 13:32:37 +00:00
|
|
|
{
|
|
|
|
int dummyint;
|
|
|
|
struct in_addr dummyaddr;
|
|
|
|
|
|
|
|
pri_addr->s_addr = sec_addr->s_addr = 0L;
|
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
if (argc > 0) {
|
1996-10-06 13:32:37 +00:00
|
|
|
ParseAddr(argc, argv++, pri_addr, &dummyaddr, &dummyint);
|
1997-08-25 00:29:32 +00:00
|
|
|
if (--argc > 0)
|
1996-10-06 13:32:37 +00:00
|
|
|
ParseAddr(argc, argv++, sec_addr, &dummyaddr, &dummyint);
|
|
|
|
else
|
|
|
|
sec_addr->s_addr = pri_addr->s_addr;
|
|
|
|
}
|
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
/*
|
|
|
|
* 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...
|
|
|
|
*/
|
1996-10-06 13:32:37 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1997-08-25 00:29:32 +00:00
|
|
|
SetNS(struct cmdtab const * list, int argc, char **argv)
|
1996-10-06 13:32:37 +00:00
|
|
|
{
|
|
|
|
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
|
1997-08-25 00:29:32 +00:00
|
|
|
SetNBNS(struct cmdtab const * list, int argc, char **argv)
|
1996-10-06 13:32:37 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
#endif /* MS_EXT */
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1997-09-22 00:46:56 +00:00
|
|
|
int
|
1997-08-25 00:29:32 +00:00
|
|
|
SetVariable(struct cmdtab const * list, int argc, char **argv, int param)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
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) {
|
1997-08-25 00:29:32 +00:00
|
|
|
case VAR_AUTHKEY:
|
|
|
|
strncpy(VarAuthKey, arg, sizeof(VarAuthKey) - 1);
|
|
|
|
VarAuthKey[sizeof(VarAuthKey) - 1] = '\0';
|
|
|
|
break;
|
|
|
|
case VAR_AUTHNAME:
|
|
|
|
strncpy(VarAuthName, arg, sizeof(VarAuthName) - 1);
|
|
|
|
VarAuthName[sizeof(VarAuthName) - 1] = '\0';
|
|
|
|
break;
|
|
|
|
case VAR_DIAL:
|
|
|
|
strncpy(VarDialScript, arg, sizeof(VarDialScript) - 1);
|
|
|
|
VarDialScript[sizeof(VarDialScript) - 1] = '\0';
|
|
|
|
break;
|
|
|
|
case VAR_LOGIN:
|
|
|
|
strncpy(VarLoginScript, arg, sizeof(VarLoginScript) - 1);
|
|
|
|
VarLoginScript[sizeof(VarLoginScript) - 1] = '\0';
|
|
|
|
break;
|
|
|
|
case VAR_DEVICE:
|
1997-09-22 00:46:56 +00:00
|
|
|
if (modem != -1)
|
|
|
|
LogPrintf(LogWARN, "Cannot change device to \"%s\" when \"%s\" is open\n",
|
|
|
|
arg, VarDevice);
|
|
|
|
else {
|
|
|
|
strncpy(VarDevice, arg, sizeof(VarDevice) - 1);
|
|
|
|
VarDevice[sizeof(VarDevice) - 1] = '\0';
|
1997-10-26 01:04:02 +00:00
|
|
|
VarBaseDevice = strrchr(VarDevice, '/');
|
1997-09-22 00:46:56 +00:00
|
|
|
VarBaseDevice = VarBaseDevice ? VarBaseDevice + 1 : "";
|
|
|
|
}
|
1997-08-25 00:29:32 +00:00
|
|
|
break;
|
|
|
|
case VAR_ACCMAP:
|
|
|
|
sscanf(arg, "%lx", &map);
|
|
|
|
VarAccmap = map;
|
|
|
|
break;
|
|
|
|
case VAR_PHONE:
|
|
|
|
strncpy(VarPhoneList, arg, sizeof(VarPhoneList) - 1);
|
|
|
|
VarPhoneList[sizeof(VarPhoneList) - 1] = '\0';
|
|
|
|
strcpy(VarPhoneCopy, VarPhoneList);
|
|
|
|
VarNextPhone = VarPhoneCopy;
|
|
|
|
break;
|
|
|
|
case VAR_HANGUP:
|
|
|
|
strncpy(VarHangupScript, arg, sizeof(VarHangupScript) - 1);
|
|
|
|
VarHangupScript[sizeof(VarHangupScript) - 1] = '\0';
|
|
|
|
break;
|
1997-09-25 00:52:37 +00:00
|
|
|
#ifdef HAVE_DES
|
1997-09-17 23:17:57 +00:00
|
|
|
case VAR_ENC:
|
1997-09-25 00:52:37 +00:00
|
|
|
VarMSChap = !strcasecmp(arg, "mschap");
|
1997-09-17 23:17:57 +00:00
|
|
|
break;
|
1997-09-25 00:52:37 +00:00
|
|
|
#endif
|
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-08-25 00:29:32 +00:00
|
|
|
static int
|
|
|
|
SetCtsRts(struct cmdtab const * list, int argc, char **argv)
|
1996-12-22 17:09:17 +00:00
|
|
|
{
|
|
|
|
if (argc > 0) {
|
|
|
|
if (strcmp(*argv, "on") == 0)
|
1997-10-26 01:04:02 +00:00
|
|
|
VarCtsRts = 1;
|
1996-12-22 17:09:17 +00:00
|
|
|
else if (strcmp(*argv, "off") == 0)
|
1997-10-26 01:04:02 +00:00
|
|
|
VarCtsRts = 0;
|
1996-12-22 17:09:17 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
static int
|
|
|
|
SetOpenMode(struct cmdtab const * list, int argc, char **argv)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
static struct cmdtab const SetCommands[] = {
|
1997-08-25 00:29:32 +00:00
|
|
|
{"accmap", NULL, SetVariable, LOCAL_AUTH,
|
|
|
|
"Set accmap value", "set accmap hex-value", (void *) VAR_ACCMAP},
|
|
|
|
{"afilter", NULL, SetAfilter, LOCAL_AUTH,
|
|
|
|
"Set keep Alive filter", "set afilter ..."},
|
|
|
|
{"authkey", "key", SetVariable, LOCAL_AUTH,
|
|
|
|
"Set authentication key", "set authkey|key key", (void *) VAR_AUTHKEY},
|
|
|
|
{"authname", NULL, SetVariable, LOCAL_AUTH,
|
|
|
|
"Set authentication name", "set authname name", (void *) VAR_AUTHNAME},
|
|
|
|
{"ctsrts", NULL, SetCtsRts, LOCAL_AUTH,
|
|
|
|
"Use CTS/RTS modem signalling", "set ctsrts [on|off]"},
|
|
|
|
{"device", "line", SetVariable, LOCAL_AUTH,
|
|
|
|
"Set modem device name", "set device|line device-name", (void *) VAR_DEVICE},
|
|
|
|
{"dfilter", NULL, SetDfilter, LOCAL_AUTH,
|
|
|
|
"Set demand filter", "set dfilter ..."},
|
|
|
|
{"dial", NULL, SetVariable, LOCAL_AUTH,
|
|
|
|
"Set dialing script", "set dial chat-script", (void *) VAR_DIAL},
|
1997-09-25 00:52:37 +00:00
|
|
|
#ifdef HAVE_DES
|
1997-09-17 23:17:57 +00:00
|
|
|
{"encrypt", NULL, SetVariable, LOCAL_AUTH,
|
1997-09-25 00:52:37 +00:00
|
|
|
"Set CHAP encryption algorithm", "set encrypt MSChap|MD5", (void *) VAR_ENC},
|
|
|
|
#endif
|
1997-08-25 00:29:32 +00:00
|
|
|
{"escape", NULL, SetEscape, LOCAL_AUTH,
|
|
|
|
"Set escape characters", "set escape hex-digit ..."},
|
|
|
|
{"hangup", NULL, SetVariable, LOCAL_AUTH,
|
|
|
|
"Set hangup script", "set hangup chat-script", (void *) VAR_HANGUP},
|
|
|
|
{"ifaddr", NULL, SetInterfaceAddr, LOCAL_AUTH,
|
|
|
|
"Set destination address", "set ifaddr [src-addr [dst-addr [netmask [trg-addr]]]]"},
|
|
|
|
{"ifilter", NULL, SetIfilter, LOCAL_AUTH,
|
|
|
|
"Set input filter", "set ifilter ..."},
|
|
|
|
{"loopback", NULL, SetLoopback, LOCAL_AUTH,
|
|
|
|
"Set loopback facility", "set loopback on|off"},
|
|
|
|
{"log", NULL, SetLogLevel, LOCAL_AUTH,
|
1997-11-04 01:17:05 +00:00
|
|
|
"Set log level", "set log [local] [+|-]value..."},
|
1997-08-25 00:29:32 +00:00
|
|
|
{"login", NULL, SetVariable, LOCAL_AUTH,
|
|
|
|
"Set login script", "set login chat-script", (void *) VAR_LOGIN},
|
|
|
|
{"mru", NULL, SetInitialMRU, LOCAL_AUTH,
|
|
|
|
"Set Initial MRU value", "set mru value"},
|
|
|
|
{"mtu", NULL, SetPreferredMTU, LOCAL_AUTH,
|
|
|
|
"Set Preferred MTU value", "set mtu value"},
|
|
|
|
{"ofilter", NULL, SetOfilter, LOCAL_AUTH,
|
|
|
|
"Set output filter", "set ofilter ..."},
|
|
|
|
{"openmode", NULL, SetOpenMode, LOCAL_AUTH,
|
|
|
|
"Set open mode", "set openmode [active|passive]"},
|
|
|
|
{"parity", NULL, SetModemParity, LOCAL_AUTH,
|
|
|
|
"Set modem parity", "set parity [odd|even|none]"},
|
|
|
|
{"phone", NULL, SetVariable, LOCAL_AUTH,
|
|
|
|
"Set telephone number(s)", "set phone phone1[:phone2[...]]", (void *) VAR_PHONE},
|
|
|
|
{"reconnect", NULL, SetReconnect, LOCAL_AUTH,
|
|
|
|
"Set Reconnect timeout", "set reconnect value ntries"},
|
|
|
|
{"redial", NULL, SetRedialTimeout, LOCAL_AUTH,
|
|
|
|
"Set Redial timeout", "set redial value|random[.value|random] [dial_attempts]"},
|
|
|
|
{"stopped", NULL, SetStoppedTimeout, LOCAL_AUTH,
|
|
|
|
"Set STOPPED timeouts", "set stopped [LCPseconds [IPCPseconds [CCPseconds]]]"},
|
|
|
|
{"server", "socket", SetServer, LOCAL_AUTH,
|
|
|
|
"Set server port", "set server|socket TcpPort|LocalName|none [mask]"},
|
|
|
|
{"speed", NULL, SetModemSpeed, LOCAL_AUTH,
|
|
|
|
"Set modem speed", "set speed value"},
|
|
|
|
{"timeout", NULL, SetIdleTimeout, LOCAL_AUTH,
|
|
|
|
"Set Idle timeout", "set timeout value"},
|
1997-06-09 03:27:43 +00:00
|
|
|
#ifndef NOMSEXT
|
1997-08-25 00:29:32 +00:00
|
|
|
{"ns", NULL, SetNS, LOCAL_AUTH,
|
|
|
|
"Set NameServer", "set ns pri-addr [sec-addr]"},
|
|
|
|
{"nbns", NULL, SetNBNS, LOCAL_AUTH,
|
|
|
|
"Set NetBIOS NameServer", "set nbns pri-addr [sec-addr]"},
|
1997-06-09 03:27:43 +00:00
|
|
|
#endif
|
1997-08-25 00:29:32 +00:00
|
|
|
{"help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
|
|
|
|
"Display this message", "set help|? [command]", (void *) SetCommands},
|
|
|
|
{NULL, NULL, NULL},
|
1995-01-31 06:29:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
1997-08-25 00:29:32 +00:00
|
|
|
SetCommand(struct cmdtab const * list, int argc, char **argv)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
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
|
1997-08-25 00:29:32 +00:00
|
|
|
AddCommand(struct cmdtab const * list, int argc, char **argv)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
struct in_addr dest, gateway, netmask;
|
|
|
|
|
|
|
|
if (argc == 3) {
|
1997-06-28 01:34:03 +00:00
|
|
|
if (strcasecmp(argv[0], "MYADDR") == 0)
|
|
|
|
dest = IpcpInfo.want_ipaddr;
|
|
|
|
else
|
|
|
|
dest = GetIpAddr(argv[0]);
|
1995-01-31 06:29:58 +00:00
|
|
|
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
|
1997-08-25 00:29:32 +00:00
|
|
|
DeleteCommand(struct cmdtab const * list, int argc, char **argv)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
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) {
|
1997-06-28 01:34:03 +00:00
|
|
|
if (strcasecmp(argv[0], "MYADDR") == 0)
|
|
|
|
dest = IpcpInfo.want_ipaddr;
|
|
|
|
else
|
|
|
|
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)
|
1997-08-25 00:29:32 +00:00
|
|
|
gateway = IpcpInfo.his_ipaddr;
|
1997-06-13 03:59:36 +00:00
|
|
|
else
|
1997-08-25 00:29:32 +00:00
|
|
|
gateway = GetIpAddr(argv[1]);
|
1997-06-13 03:59:36 +00:00
|
|
|
if (argc == 3) {
|
1997-08-25 00:29:32 +00:00
|
|
|
if (inet_aton(argv[2], &netmask) == 0) {
|
1997-06-13 03:59:36 +00:00
|
|
|
LogPrintf(LogWARN, "Bad netmask value.\n");
|
|
|
|
return -1;
|
1997-08-25 00:29:32 +00:00
|
|
|
}
|
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 struct cmdtab const AliasCommands[] =
|
|
|
|
{
|
1997-08-25 00:29:32 +00:00
|
|
|
{"enable", NULL, AliasEnable, LOCAL_AUTH,
|
|
|
|
"enable IP aliasing", "alias enable [yes|no]"},
|
|
|
|
{"port", NULL, AliasRedirectPort, LOCAL_AUTH,
|
|
|
|
"port redirection", "alias port [proto addr_local:port_local port_alias]"},
|
|
|
|
{"addr", NULL, AliasRedirectAddr, LOCAL_AUTH,
|
|
|
|
"static address translation", "alias addr [addr_local addr_alias]"},
|
|
|
|
{"deny_incoming", NULL, AliasOption, LOCAL_AUTH,
|
|
|
|
"stop incoming connections", "alias deny_incoming [yes|no]",
|
|
|
|
(void *) PKT_ALIAS_DENY_INCOMING},
|
|
|
|
{"log", NULL, AliasOption, LOCAL_AUTH,
|
|
|
|
"log aliasing link creation", "alias log [yes|no]",
|
|
|
|
(void *) PKT_ALIAS_LOG},
|
|
|
|
{"same_ports", NULL, AliasOption, LOCAL_AUTH,
|
|
|
|
"try to leave port numbers unchanged", "alias same_ports [yes|no]",
|
|
|
|
(void *) PKT_ALIAS_SAME_PORTS},
|
|
|
|
{"use_sockets", NULL, AliasOption, LOCAL_AUTH,
|
|
|
|
"allocate host sockets", "alias use_sockets [yes|no]",
|
|
|
|
(void *) PKT_ALIAS_USE_SOCKETS},
|
|
|
|
{"unregistered_only", NULL, AliasOption, LOCAL_AUTH,
|
|
|
|
"alias unregistered (private) IP address space only",
|
|
|
|
"alias unregistered_only [yes|no]",
|
|
|
|
(void *) PKT_ALIAS_UNREGISTERED_ONLY},
|
|
|
|
{"help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
|
|
|
|
"Display this message", "alias help|? [command]",
|
|
|
|
(void *) AliasCommands},
|
|
|
|
{NULL, NULL, NULL},
|
1997-05-23 04:54:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
1997-08-25 00:29:32 +00:00
|
|
|
AliasCommand(struct cmdtab const * list, int argc, char **argv)
|
1997-05-23 04:54:03 +00:00
|
|
|
{
|
|
|
|
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
|
1997-08-25 00:29:32 +00:00
|
|
|
AliasEnable(struct cmdtab const * list, int argc, char **argv)
|
1997-05-23 04:54:03 +00:00
|
|
|
{
|
1997-06-09 03:27:43 +00:00
|
|
|
if (argc == 1)
|
|
|
|
if (strcasecmp(argv[0], "yes") == 0) {
|
|
|
|
if (!(mode & MODE_ALIAS)) {
|
1997-08-25 00:29:32 +00:00
|
|
|
if (loadAliasHandlers(&VarAliasHandlers) == 0) {
|
|
|
|
mode |= MODE_ALIAS;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
LogPrintf(LogWARN, "Cannot load alias library\n");
|
|
|
|
return 1;
|
1997-06-09 03:27:43 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
} else if (strcasecmp(argv[0], "no") == 0) {
|
|
|
|
if (mode & MODE_ALIAS) {
|
1997-08-25 00:29:32 +00:00
|
|
|
unloadAliasHandlers();
|
|
|
|
mode &= ~MODE_ALIAS;
|
1997-06-09 03:27:43 +00:00
|
|
|
}
|
|
|
|
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
|
1997-08-25 00:29:32 +00:00
|
|
|
AliasOption(struct cmdtab const * list, int argc, char **argv, void *param)
|
1997-05-23 04:54:03 +00:00
|
|
|
{
|
1997-08-25 00:29:32 +00:00
|
|
|
if (argc == 1)
|
|
|
|
if (strcasecmp(argv[0], "yes") == 0) {
|
|
|
|
if (mode & MODE_ALIAS) {
|
|
|
|
VarPacketAliasSetMode((unsigned) param, (unsigned) param);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
LogPrintf(LogWARN, "alias not enabled\n");
|
|
|
|
} else if (strcmp(argv[0], "no") == 0) {
|
|
|
|
if (mode & MODE_ALIAS) {
|
|
|
|
VarPacketAliasSetMode(0, (unsigned) param);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
LogPrintf(LogWARN, "alias not enabled\n");
|
|
|
|
}
|
|
|
|
return -1;
|
1997-05-23 04:54:03 +00:00
|
|
|
}
|