1998-01-29 00:44:16 +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.
|
|
|
|
*
|
1998-02-18 19:35:20 +00:00
|
|
|
* $Id: command.c,v 1.131.2.25 1998/02/17 19:28:42 brian Exp $
|
1998-01-29 00:44:16 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
|
|
|
|
#ifndef NOALIAS
|
|
|
|
#include <alias.h>
|
|
|
|
#endif
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#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 "command.h"
|
|
|
|
#include "mbuf.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "defs.h"
|
|
|
|
#include "timer.h"
|
|
|
|
#include "fsm.h"
|
|
|
|
#include "lcp.h"
|
|
|
|
#include "iplist.h"
|
1998-01-29 23:11:44 +00:00
|
|
|
#include "throughput.h"
|
1998-01-29 00:44:16 +00:00
|
|
|
#include "ipcp.h"
|
|
|
|
#include "modem.h"
|
|
|
|
#include "filter.h"
|
|
|
|
#ifndef NOALIAS
|
|
|
|
#include "alias_cmd.h"
|
|
|
|
#endif
|
|
|
|
#include "hdlc.h"
|
|
|
|
#include "loadalias.h"
|
|
|
|
#include "vars.h"
|
|
|
|
#include "systems.h"
|
1998-02-02 19:32:16 +00:00
|
|
|
#include "bundle.h"
|
1998-01-29 00:44:16 +00:00
|
|
|
#include "main.h"
|
|
|
|
#include "route.h"
|
|
|
|
#include "ccp.h"
|
|
|
|
#include "ip.h"
|
|
|
|
#include "slcompress.h"
|
|
|
|
#include "auth.h"
|
1998-02-02 19:33:40 +00:00
|
|
|
#include "async.h"
|
1998-01-30 19:46:07 +00:00
|
|
|
#include "link.h"
|
1998-02-09 19:21:11 +00:00
|
|
|
#include "descriptor.h"
|
1998-01-29 00:49:32 +00:00
|
|
|
#include "physical.h"
|
1998-02-09 19:24:03 +00:00
|
|
|
#include "server.h"
|
1998-02-10 03:23:50 +00:00
|
|
|
#include "prompt.h"
|
1998-02-13 05:10:26 +00:00
|
|
|
#include "chat.h"
|
1998-02-16 00:01:12 +00:00
|
|
|
#include "datalink.h"
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
struct in_addr ifnetmask;
|
|
|
|
static const char *HIDDEN = "********";
|
|
|
|
|
1998-02-17 19:28:01 +00:00
|
|
|
static int ShowCommand(struct cmdargs const *);
|
|
|
|
static int TerminalCommand(struct cmdargs const *);
|
|
|
|
static int QuitCommand(struct cmdargs const *);
|
|
|
|
static int CloseCommand(struct cmdargs const *);
|
|
|
|
static int DialCommand(struct cmdargs const *);
|
|
|
|
static int DownCommand(struct cmdargs const *);
|
|
|
|
static int AllowCommand(struct cmdargs const *);
|
|
|
|
static int SetCommand(struct cmdargs const *);
|
|
|
|
static int LinkCommand(struct cmdargs const *);
|
|
|
|
static int AddCommand(struct cmdargs const *);
|
|
|
|
static int DeleteCommand(struct cmdargs const *);
|
|
|
|
static int BgShellCommand(struct cmdargs const *);
|
|
|
|
static int FgShellCommand(struct cmdargs const *);
|
1998-01-29 00:44:16 +00:00
|
|
|
#ifndef NOALIAS
|
1998-02-17 19:28:01 +00:00
|
|
|
static int AliasCommand(struct cmdargs const *);
|
|
|
|
static int AliasEnable(struct cmdargs const *);
|
|
|
|
static int AliasOption(struct cmdargs const *);
|
1998-01-29 00:44:16 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static int
|
|
|
|
HelpCommand(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
struct cmdtab const *cmd;
|
|
|
|
int n, cmax, dmax, cols;
|
|
|
|
|
|
|
|
if (arg->argc > 0) {
|
1998-02-17 19:28:01 +00:00
|
|
|
for (cmd = arg->cmdtab; cmd->name; cmd++)
|
1998-01-29 00:44:16 +00:00
|
|
|
if (strcasecmp(cmd->name, *arg->argv) == 0 &&
|
|
|
|
(cmd->lauth & VarLocalAuth)) {
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, "%s\n", cmd->syntax);
|
1998-01-29 00:44:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
cmax = dmax = 0;
|
1998-02-17 19:28:01 +00:00
|
|
|
for (cmd = arg->cmdtab; cmd->func; cmd++)
|
1998-01-29 00:44:16 +00:00
|
|
|
if (cmd->name && (cmd->lauth & VarLocalAuth)) {
|
|
|
|
if ((n = strlen(cmd->name)) > cmax)
|
|
|
|
cmax = n;
|
|
|
|
if ((n = strlen(cmd->helpmes)) > dmax)
|
|
|
|
dmax = n;
|
|
|
|
}
|
|
|
|
|
|
|
|
cols = 80 / (dmax + cmax + 3);
|
|
|
|
n = 0;
|
1998-02-17 19:28:01 +00:00
|
|
|
for (cmd = arg->cmdtab; cmd->func; cmd++)
|
1998-01-29 00:44:16 +00:00
|
|
|
if (cmd->name && (cmd->lauth & VarLocalAuth)) {
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, " %-*.*s: %-*.*s",
|
1998-01-29 00:44:16 +00:00
|
|
|
cmax, cmax, cmd->name, dmax, dmax, cmd->helpmes);
|
|
|
|
if (++n % cols == 0)
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, "\n");
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
if (n % cols != 0)
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, "\n");
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
IsInteractive(int Display)
|
|
|
|
{
|
|
|
|
const char *m = NULL;
|
|
|
|
|
|
|
|
if (mode & MODE_DDIAL)
|
|
|
|
m = "direct dial";
|
|
|
|
else if (mode & MODE_BACKGROUND)
|
|
|
|
m = "background";
|
|
|
|
else if (mode & MODE_AUTO)
|
|
|
|
m = "auto";
|
|
|
|
else if (mode & MODE_DIRECT)
|
|
|
|
m = "direct";
|
|
|
|
else if (mode & MODE_DEDICATED)
|
|
|
|
m = "dedicated";
|
|
|
|
else if (mode & MODE_INTER)
|
|
|
|
m = "interactive";
|
|
|
|
if (m) {
|
1998-02-10 03:23:50 +00:00
|
|
|
if (Display)
|
|
|
|
prompt_Printf(&prompt, "Working in %s mode\n", m);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
return mode & MODE_INTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
DialCommand(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
|
1998-01-31 02:48:30 +00:00
|
|
|
if (LcpInfo.fsm.state > ST_CLOSED) {
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, "LCP state is [%s]\n",
|
|
|
|
StateNames[LcpInfo.fsm.state]);
|
1998-01-29 00:44:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((mode & MODE_DAEMON) && !(mode & MODE_AUTO)) {
|
|
|
|
LogPrintf(LogWARN,
|
|
|
|
"Manual dial is only available in auto and interactive mode\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arg->argc > 0 && (res = LoadCommand(arg)) != 0)
|
|
|
|
return res;
|
|
|
|
|
1998-02-16 00:01:12 +00:00
|
|
|
bundle_Open(arg->bundle, NULL);
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetLoopback(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
if (arg->argc == 1)
|
|
|
|
if (!strcasecmp(*arg->argv, "on")) {
|
|
|
|
VarLoopback = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (!strcasecmp(*arg->argv, "off")) {
|
|
|
|
VarLoopback = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ShellCommand(struct cmdargs const *arg, int bg)
|
|
|
|
{
|
|
|
|
const char *shell;
|
|
|
|
pid_t shpid;
|
|
|
|
int argc;
|
|
|
|
char *argv[MAXARGS];
|
|
|
|
|
|
|
|
#ifdef SHELL_ONLY_INTERACTIVELY
|
|
|
|
/* we're only allowed to shell when we run ppp interactively */
|
|
|
|
if (mode != MODE_INTER) {
|
|
|
|
LogPrintf(LogWARN, "Can only start a shell in interactive mode\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef NO_SHELL_IN_AUTO_INTERACTIVE
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we want to stop shell commands when we've got a telnet connection to an
|
|
|
|
* auto mode ppp
|
|
|
|
*/
|
1998-02-10 03:23:50 +00:00
|
|
|
if (prompt_Active(&prompt) && !(mode & MODE_INTER)) {
|
1998-01-29 00:44:16 +00:00
|
|
|
LogPrintf(LogWARN, "Shell is not allowed interactively in auto mode\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (arg->argc == 0)
|
|
|
|
if (!(mode & MODE_INTER)) {
|
1998-02-10 03:23:50 +00:00
|
|
|
if (prompt_Active(&prompt))
|
1998-01-29 00:44:16 +00:00
|
|
|
LogPrintf(LogWARN, "Can't start an interactive shell from"
|
|
|
|
" a telnet session\n");
|
|
|
|
else
|
|
|
|
LogPrintf(LogWARN, "Can only start an interactive shell in"
|
|
|
|
" interactive mode\n");
|
|
|
|
return 1;
|
|
|
|
} else if (bg) {
|
|
|
|
LogPrintf(LogWARN, "Can only start an interactive shell in"
|
|
|
|
" the foreground mode\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if ((shell = getenv("SHELL")) == 0)
|
|
|
|
shell = _PATH_BSHELL;
|
|
|
|
|
|
|
|
if ((shpid = fork()) == 0) {
|
|
|
|
int dtablesize, i, fd;
|
|
|
|
|
|
|
|
TermTimerService();
|
|
|
|
signal(SIGINT, SIG_DFL);
|
|
|
|
signal(SIGQUIT, SIG_DFL);
|
|
|
|
signal(SIGTERM, SIG_DFL);
|
|
|
|
signal(SIGHUP, SIG_DFL);
|
|
|
|
signal(SIGALRM, SIG_DFL);
|
|
|
|
|
1998-02-10 03:23:50 +00:00
|
|
|
if (prompt_Active(&prompt))
|
|
|
|
fd = prompt.fd_out;
|
1998-01-29 00:44:16 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
for (dtablesize = getdtablesize(), i = 3; i < dtablesize; i++)
|
|
|
|
close(i);
|
|
|
|
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_TtyOldMode(&prompt);
|
1998-01-29 00:44:16 +00:00
|
|
|
setuid(geteuid());
|
|
|
|
if (arg->argc > 0) {
|
|
|
|
/* substitute pseudo args */
|
|
|
|
argv[0] = strdup(arg->argv[0]);
|
|
|
|
for (argc = 1; argc < arg->argc; argc++) {
|
|
|
|
if (strcasecmp(arg->argv[argc], "HISADDR") == 0)
|
|
|
|
argv[argc] = strdup(inet_ntoa(IpcpInfo.his_ipaddr));
|
|
|
|
else if (strcasecmp(arg->argv[argc], "INTERFACE") == 0)
|
1998-02-02 19:32:16 +00:00
|
|
|
argv[argc] = strdup(arg->bundle->ifname);
|
1998-01-29 00:44:16 +00:00
|
|
|
else if (strcasecmp(arg->argv[argc], "MYADDR") == 0)
|
|
|
|
argv[argc] = strdup(inet_ntoa(IpcpInfo.want_ipaddr));
|
|
|
|
else
|
|
|
|
argv[argc] = strdup(arg->argv[argc]);
|
|
|
|
}
|
|
|
|
argv[argc] = NULL;
|
|
|
|
if (bg) {
|
|
|
|
pid_t p;
|
|
|
|
|
|
|
|
p = getpid();
|
|
|
|
if (daemon(1, 1) == -1) {
|
|
|
|
LogPrintf(LogERROR, "%d: daemon: %s\n", p, strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
1998-02-10 03:23:50 +00:00
|
|
|
} else if (prompt_Active(&prompt))
|
1998-01-29 00:44:16 +00:00
|
|
|
printf("ppp: Pausing until %s finishes\n", arg->argv[0]);
|
|
|
|
execvp(argv[0], argv);
|
|
|
|
} else {
|
1998-02-10 03:23:50 +00:00
|
|
|
if (prompt_Active(&prompt))
|
1998-01-29 00:44:16 +00:00
|
|
|
printf("ppp: Pausing until %s finishes\n", shell);
|
|
|
|
execl(shell, shell, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
LogPrintf(LogWARN, "exec() of %s failed\n",
|
|
|
|
arg->argc > 0 ? arg->argv[0] : shell);
|
|
|
|
exit(255);
|
|
|
|
}
|
|
|
|
if (shpid == (pid_t) - 1) {
|
|
|
|
LogPrintf(LogERROR, "Fork failed: %s\n", strerror(errno));
|
|
|
|
} else {
|
|
|
|
int status;
|
|
|
|
|
|
|
|
waitpid(shpid, &status, 0);
|
|
|
|
}
|
|
|
|
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_TtyCommandMode(&prompt);
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
BgShellCommand(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
if (arg->argc == 0)
|
|
|
|
return -1;
|
|
|
|
return ShellCommand(arg, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
FgShellCommand(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
return ShellCommand(arg, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct cmdtab const Commands[] = {
|
|
|
|
{"accept", NULL, AcceptCommand, LOCAL_AUTH,
|
|
|
|
"accept option request", "accept option .."},
|
|
|
|
{"add", NULL, AddCommand, LOCAL_AUTH,
|
|
|
|
"add route", "add dest mask gateway", NULL},
|
|
|
|
{"add!", NULL, AddCommand, LOCAL_AUTH,
|
|
|
|
"add or change route", "add! dest mask gateway", (void *)1},
|
|
|
|
{"allow", "auth", AllowCommand, LOCAL_AUTH,
|
|
|
|
"Allow ppp access", "allow users|modes ...."},
|
|
|
|
{"bg", "!bg", BgShellCommand, LOCAL_AUTH,
|
|
|
|
"Run a background command", "[!]bg command"},
|
1998-02-17 19:28:35 +00:00
|
|
|
{"close", NULL, CloseCommand, LOCAL_AUTH | LOCAL_CX_OPT,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Close connection", "close"},
|
|
|
|
{"delete", NULL, DeleteCommand, LOCAL_AUTH,
|
|
|
|
"delete route", "delete dest", NULL},
|
|
|
|
{"delete!", NULL, DeleteCommand, LOCAL_AUTH,
|
|
|
|
"delete a route if it exists", "delete! dest", (void *)1},
|
|
|
|
{"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,
|
|
|
|
"Password for manipulation", "passwd LocalPassword"},
|
1998-02-17 19:28:01 +00:00
|
|
|
{"link", NULL, LinkCommand, LOCAL_AUTH,
|
|
|
|
"Link specific commands", "link name command ..."},
|
1998-01-29 00:44:16 +00:00
|
|
|
{"load", NULL, LoadCommand, LOCAL_AUTH,
|
|
|
|
"Load settings", "load [remote]"},
|
|
|
|
{"save", NULL, SaveCommand, LOCAL_AUTH,
|
|
|
|
"Save settings", "save"},
|
1998-02-17 19:28:01 +00:00
|
|
|
{"set", "setup", SetCommand, LOCAL_AUTH | LOCAL_CX_OPT,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Set parameters", "set[up] var value"},
|
|
|
|
{"shell", "!", FgShellCommand, LOCAL_AUTH,
|
|
|
|
"Run a subshell", "shell|! [sh command]"},
|
|
|
|
{"show", NULL, ShowCommand, LOCAL_AUTH,
|
|
|
|
"Show status and stats", "show var"},
|
1998-02-17 19:28:01 +00:00
|
|
|
{"term", NULL, TerminalCommand, LOCAL_AUTH | LOCAL_CX,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Enter terminal mode", "term"},
|
|
|
|
#ifndef NOALIAS
|
|
|
|
{"alias", NULL, AliasCommand, LOCAL_AUTH,
|
|
|
|
"alias control", "alias option [yes|no]"},
|
|
|
|
#endif
|
|
|
|
{"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]", Commands},
|
1998-02-17 19:28:35 +00:00
|
|
|
{NULL, "down", DownCommand, LOCAL_AUTH | LOCAL_CX,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Generate down event", "down"},
|
|
|
|
{NULL, NULL, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
ShowLoopback(struct cmdargs const *arg)
|
|
|
|
{
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, "Local loopback is %s\n", VarLoopback ? "on" : "off");
|
1998-01-29 00:44:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ShowLogLevel(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, "Log: ");
|
1998-01-29 00:44:16 +00:00
|
|
|
for (i = LogMIN; i <= LogMAX; i++)
|
|
|
|
if (LogIsKept(i) & LOG_KEPT_SYSLOG)
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, " %s", LogName(i));
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, "\nLocal:");
|
1998-01-29 00:44:16 +00:00
|
|
|
for (i = LogMIN; i <= LogMAX; i++)
|
|
|
|
if (LogIsKept(i) & LOG_KEPT_LOCAL)
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, " %s", LogName(i));
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, "\n");
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ShowEscape(struct cmdargs const *arg)
|
|
|
|
{
|
1998-02-18 19:35:20 +00:00
|
|
|
if (arg->cx->physical->async.cfg.EscMap[32]) {
|
|
|
|
int code, bit;
|
|
|
|
char *sep = "";
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
for (code = 0; code < 32; code++)
|
1998-02-18 19:35:20 +00:00
|
|
|
if (arg->cx->physical->async.cfg.EscMap[code])
|
1998-01-29 00:44:16 +00:00
|
|
|
for (bit = 0; bit < 8; bit++)
|
1998-02-18 19:35:20 +00:00
|
|
|
if (arg->cx->physical->async.cfg.EscMap[code] & (1 << bit)) {
|
|
|
|
prompt_Printf(&prompt, "%s0x%02x", sep, (code << 3) + bit);
|
|
|
|
sep = ", ";
|
|
|
|
}
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, "\n");
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ShowTimeout(struct cmdargs const *arg)
|
|
|
|
{
|
1998-02-10 03:23:50 +00:00
|
|
|
int remaining;
|
|
|
|
|
|
|
|
prompt_Printf(&prompt, " Idle Timer: %d secs LQR Timer: %d secs"
|
|
|
|
" Retry Timer: %d secs\n", VarIdleTimeout, VarLqrTimeout,
|
|
|
|
VarRetryTimeout);
|
|
|
|
remaining = RemainingIdleTime();
|
|
|
|
if (remaining != -1)
|
|
|
|
prompt_Printf(&prompt, " %d secs remaining\n", remaining);
|
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ShowStopped(struct cmdargs const *arg)
|
|
|
|
{
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, " Stopped Timer: LCP: ");
|
1998-01-31 02:48:30 +00:00
|
|
|
if (!LcpInfo.fsm.StoppedTimer.load)
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, "Disabled");
|
1998-01-29 00:44:16 +00:00
|
|
|
else
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, "%ld secs",
|
|
|
|
LcpInfo.fsm.StoppedTimer.load / SECTICKS);
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, ", IPCP: ");
|
1998-01-31 02:48:30 +00:00
|
|
|
if (!IpcpInfo.fsm.StoppedTimer.load)
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, "Disabled");
|
1998-01-29 00:44:16 +00:00
|
|
|
else
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, "%ld secs",
|
|
|
|
IpcpInfo.fsm.StoppedTimer.load / SECTICKS);
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, ", CCP: ");
|
1998-01-31 02:48:30 +00:00
|
|
|
if (!CcpInfo.fsm.StoppedTimer.load)
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, "Disabled");
|
1998-01-29 00:44:16 +00:00
|
|
|
else
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, "%ld secs",
|
|
|
|
CcpInfo.fsm.StoppedTimer.load / SECTICKS);
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, "\n");
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ShowAuthKey(struct cmdargs const *arg)
|
|
|
|
{
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, "AuthName = %s\n", VarAuthName);
|
|
|
|
prompt_Printf(&prompt, "AuthKey = %s\n", HIDDEN);
|
1998-01-29 00:44:16 +00:00
|
|
|
#ifdef HAVE_DES
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, "Encrypt = %s\n", VarMSChap ? "MSChap" : "MD5" );
|
1998-01-29 00:44:16 +00:00
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ShowVersion(struct cmdargs const *arg)
|
|
|
|
{
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, "%s - %s \n", VarVersion, VarLocalVersion);
|
1998-01-29 00:44:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ShowInitialMRU(struct cmdargs const *arg)
|
|
|
|
{
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, " Initial MRU: %d\n", VarMRU);
|
1998-01-29 00:44:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ShowPreferredMTU(struct cmdargs const *arg)
|
|
|
|
{
|
1998-02-10 03:23:50 +00:00
|
|
|
if (VarPrefMTU)
|
|
|
|
prompt_Printf(&prompt, " Preferred MTU: %d\n", VarPrefMTU);
|
|
|
|
else
|
|
|
|
prompt_Printf(&prompt, " Preferred MTU: unspecified\n");
|
1998-01-29 00:44:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ShowReconnect(struct cmdargs const *arg)
|
|
|
|
{
|
1998-02-16 19:10:44 +00:00
|
|
|
prompt_Printf(&prompt, "%s: Reconnect Timer: %d, %d tries\n",
|
1998-02-17 19:28:49 +00:00
|
|
|
arg->cx->name, arg->cx->cfg.reconnect_timeout,
|
|
|
|
arg->cx->cfg.max_reconnect);
|
1998-01-29 00:44:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ShowRedial(struct cmdargs const *arg)
|
|
|
|
{
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, " Redial Timer: ");
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-02-17 19:28:49 +00:00
|
|
|
if (arg->cx->cfg.dial_timeout >= 0)
|
|
|
|
prompt_Printf(&prompt, " %d seconds, ", arg->cx->cfg.dial_timeout);
|
1998-02-10 03:23:50 +00:00
|
|
|
else
|
1998-02-16 19:11:10 +00:00
|
|
|
prompt_Printf(&prompt, " Random 0 - %d seconds, ", DIAL_TIMEOUT);
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, " Redial Next Timer: ");
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-02-17 19:28:49 +00:00
|
|
|
if (arg->cx->cfg.dial_next_timeout >= 0)
|
|
|
|
prompt_Printf(&prompt, " %d seconds, ", arg->cx->cfg.dial_next_timeout);
|
1998-02-10 03:23:50 +00:00
|
|
|
else
|
1998-02-16 19:11:10 +00:00
|
|
|
prompt_Printf(&prompt, " Random 0 - %d seconds, ", DIAL_TIMEOUT);
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-02-17 19:28:49 +00:00
|
|
|
if (arg->cx->cfg.max_dial)
|
|
|
|
prompt_Printf(&prompt, "%d dial tries", arg->cx->cfg.max_dial);
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, "\n");
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NOMSEXT
|
|
|
|
static int
|
|
|
|
ShowMSExt(struct cmdargs const *arg)
|
|
|
|
{
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, " MS PPP extention values \n");
|
|
|
|
prompt_Printf(&prompt, " Primary NS : %s\n",
|
|
|
|
inet_ntoa(IpcpInfo.ns_entries[0]));
|
|
|
|
prompt_Printf(&prompt, " Secondary NS : %s\n",
|
|
|
|
inet_ntoa(IpcpInfo.ns_entries[1]));
|
|
|
|
prompt_Printf(&prompt, " Primary NBNS : %s\n",
|
|
|
|
inet_ntoa(IpcpInfo.nbns_entries[0]));
|
|
|
|
prompt_Printf(&prompt, " Secondary NBNS : %s\n",
|
|
|
|
inet_ntoa(IpcpInfo.nbns_entries[1]));
|
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static struct cmdtab const ShowCommands[] = {
|
|
|
|
{"afilter", NULL, ShowAfilter, LOCAL_AUTH,
|
|
|
|
"Show keep-alive filters", "show afilter option .."},
|
|
|
|
{"auth", NULL, ShowAuthKey, LOCAL_AUTH,
|
|
|
|
"Show auth details", "show auth"},
|
|
|
|
{"ccp", NULL, ReportCcpStatus, LOCAL_AUTH,
|
|
|
|
"Show CCP status", "show cpp"},
|
|
|
|
{"compress", NULL, ReportCompress, LOCAL_AUTH,
|
|
|
|
"Show compression stats", "show compress"},
|
|
|
|
{"dfilter", NULL, ShowDfilter, LOCAL_AUTH,
|
|
|
|
"Show Demand filters", "show dfilteroption .."},
|
1998-02-18 19:35:20 +00:00
|
|
|
{"escape", NULL, ShowEscape, LOCAL_AUTH | LOCAL_CX,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Show escape characters", "show escape"},
|
|
|
|
{"hdlc", NULL, ReportHdlcStatus, LOCAL_AUTH,
|
|
|
|
"Show HDLC errors", "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"},
|
1998-02-17 19:28:01 +00:00
|
|
|
{"links", "link", bundle_ShowLinks, LOCAL_AUTH,
|
|
|
|
"Show available link names", "show links"},
|
1998-01-29 00:44:16 +00:00
|
|
|
{"loopback", NULL, ShowLoopback, LOCAL_AUTH,
|
|
|
|
"Show loopback setting", "show loopback"},
|
|
|
|
{"log", NULL, ShowLogLevel, LOCAL_AUTH,
|
|
|
|
"Show log levels", "show log"},
|
|
|
|
{"mem", NULL, ShowMemMap, LOCAL_AUTH,
|
|
|
|
"Show memory map", "show mem"},
|
1998-02-17 19:28:01 +00:00
|
|
|
{"modem", NULL, modem_ShowStatus, LOCAL_AUTH | LOCAL_CX,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Show modem setups", "show modem"},
|
|
|
|
{"mru", NULL, ShowInitialMRU, LOCAL_AUTH,
|
|
|
|
"Show Initial MRU", "show mru"},
|
|
|
|
#ifndef NOMSEXT
|
|
|
|
{"msext", NULL, ShowMSExt, LOCAL_AUTH,
|
|
|
|
"Show MS PPP extentions", "show msext"},
|
|
|
|
#endif
|
|
|
|
{"mtu", NULL, ShowPreferredMTU, LOCAL_AUTH,
|
|
|
|
"Show Preferred MTU", "show mtu"},
|
|
|
|
{"ofilter", NULL, ShowOfilter, LOCAL_AUTH,
|
|
|
|
"Show Output filters", "show ofilter option .."},
|
1998-02-06 02:22:28 +00:00
|
|
|
{"proto", NULL, Physical_ReportProtocolStatus, LOCAL_AUTH,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Show protocol summary", "show proto"},
|
1998-02-17 19:28:01 +00:00
|
|
|
{"reconnect", NULL, ShowReconnect, LOCAL_AUTH | LOCAL_CX,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Show reconnect timer", "show reconnect"},
|
1998-02-17 19:28:01 +00:00
|
|
|
{"redial", NULL, ShowRedial, LOCAL_AUTH | LOCAL_CX,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Show Redial timeout", "show redial"},
|
|
|
|
{"route", NULL, ShowRoute, LOCAL_AUTH,
|
|
|
|
"Show routing table", "show route"},
|
|
|
|
{"timeout", NULL, ShowTimeout, LOCAL_AUTH,
|
|
|
|
"Show Idle timeout", "show timeout"},
|
|
|
|
{"stopped", NULL, ShowStopped, LOCAL_AUTH,
|
|
|
|
"Show STOPPED timeout", "show stopped"},
|
|
|
|
{"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]", ShowCommands},
|
|
|
|
{NULL, NULL, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct cmdtab const *
|
|
|
|
FindCommand(struct cmdtab const *cmds, const char *str, int *pmatch)
|
|
|
|
{
|
|
|
|
int nmatch;
|
|
|
|
int len;
|
|
|
|
struct cmdtab const *found;
|
|
|
|
|
|
|
|
found = NULL;
|
|
|
|
len = strlen(str);
|
|
|
|
nmatch = 0;
|
|
|
|
while (cmds->func) {
|
|
|
|
if (cmds->name && strncasecmp(str, cmds->name, len) == 0) {
|
|
|
|
if (cmds->name[len] == '\0') {
|
|
|
|
*pmatch = 1;
|
|
|
|
return cmds;
|
|
|
|
}
|
|
|
|
nmatch++;
|
|
|
|
found = cmds;
|
|
|
|
} else if (cmds->alias && strncasecmp(str, cmds->alias, len) == 0) {
|
|
|
|
if (cmds->alias[len] == '\0') {
|
|
|
|
*pmatch = 1;
|
|
|
|
return cmds;
|
|
|
|
}
|
|
|
|
nmatch++;
|
|
|
|
found = cmds;
|
|
|
|
}
|
|
|
|
cmds++;
|
|
|
|
}
|
|
|
|
*pmatch = nmatch;
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1998-02-02 19:32:16 +00:00
|
|
|
FindExec(struct bundle *bundle, struct cmdtab const *cmds, int argc,
|
1998-02-17 19:28:01 +00:00
|
|
|
char const *const *argv, const char *prefix, struct datalink *cx)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
|
|
|
struct cmdtab const *cmd;
|
|
|
|
int val = 1;
|
|
|
|
int nmatch;
|
|
|
|
struct cmdargs arg;
|
|
|
|
|
|
|
|
cmd = FindCommand(cmds, *argv, &nmatch);
|
|
|
|
if (nmatch > 1)
|
|
|
|
LogPrintf(LogWARN, "%s%s: Ambiguous command\n", prefix, *argv);
|
|
|
|
else if (cmd && (cmd->lauth & VarLocalAuth)) {
|
1998-02-17 19:28:01 +00:00
|
|
|
if ((cmd->lauth & LOCAL_CX) && !cx)
|
|
|
|
/* We've got no context, but we require it */
|
|
|
|
cx = bundle2datalink(bundle, NULL);
|
|
|
|
|
|
|
|
if ((cmd->lauth & LOCAL_CX) && !cx)
|
|
|
|
LogPrintf(LogWARN, "%s%s: No context (use the `link' command)\n",
|
|
|
|
prefix, *argv);
|
|
|
|
else {
|
|
|
|
if (cx && !(cmd->lauth & (LOCAL_CX|LOCAL_CX_OPT))) {
|
|
|
|
LogPrintf(LogWARN, "%s%s: Redundant context (%s) ignored\n",
|
|
|
|
prefix, *argv, cx->name);
|
|
|
|
cx = NULL;
|
|
|
|
}
|
|
|
|
arg.cmdtab = cmds;
|
|
|
|
arg.cmd = cmd;
|
|
|
|
arg.argc = argc-1;
|
|
|
|
arg.argv = argv+1;
|
|
|
|
arg.bundle = bundle;
|
|
|
|
arg.cx = cx;
|
|
|
|
val = (cmd->func) (&arg);
|
|
|
|
}
|
1998-01-29 00:44:16 +00:00
|
|
|
} else
|
|
|
|
LogPrintf(LogWARN, "%s%s: Invalid command\n", prefix, *argv);
|
|
|
|
|
|
|
|
if (val == -1)
|
|
|
|
LogPrintf(LogWARN, "Usage: %s\n", cmd->syntax);
|
|
|
|
else if (val)
|
|
|
|
LogPrintf(LogWARN, "%s%s: Failed %d\n", prefix, *argv, val);
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
InterpretCommand(char *buff, int nb, int *argc, char ***argv)
|
|
|
|
{
|
|
|
|
static char *vector[MAXARGS];
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
if (nb > 0) {
|
|
|
|
cp = buff + strcspn(buff, "\r\n");
|
|
|
|
if (cp)
|
|
|
|
*cp = '\0';
|
|
|
|
*argc = MakeArgs(buff, vector, VECSIZE(vector));
|
|
|
|
*argv = vector;
|
|
|
|
} else
|
|
|
|
*argc = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
arghidden(int argc, char const *const *argv, int n)
|
|
|
|
{
|
|
|
|
/* Is arg n of the given command to be hidden from the log ? */
|
|
|
|
|
|
|
|
/* set authkey xxxxx */
|
|
|
|
/* set key xxxxx */
|
|
|
|
if (n == 2 && !strncasecmp(argv[0], "se", 2) &&
|
|
|
|
(!strncasecmp(argv[1], "authk", 5) || !strncasecmp(argv[1], "ke", 2)))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* passwd xxxxx */
|
|
|
|
if (n == 1 && !strncasecmp(argv[0], "p", 1))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-02-02 19:32:16 +00:00
|
|
|
RunCommand(struct bundle *bundle, int argc, char const *const *argv,
|
|
|
|
const char *label)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
|
|
|
if (argc > 0) {
|
|
|
|
if (LogIsKept(LogCOMMAND)) {
|
|
|
|
static char buf[LINE_LEN];
|
|
|
|
int f, n;
|
|
|
|
|
|
|
|
*buf = '\0';
|
|
|
|
if (label) {
|
|
|
|
strncpy(buf, label, sizeof buf - 3);
|
|
|
|
buf[sizeof buf - 3] = '\0';
|
|
|
|
strcat(buf, ": ");
|
|
|
|
}
|
|
|
|
n = strlen(buf);
|
|
|
|
for (f = 0; f < argc; f++) {
|
|
|
|
if (n < sizeof buf - 1 && f)
|
|
|
|
buf[n++] = ' ';
|
|
|
|
if (arghidden(argc, argv, f))
|
|
|
|
strncpy(buf+n, HIDDEN, sizeof buf - n - 1);
|
|
|
|
else
|
|
|
|
strncpy(buf+n, argv[f], sizeof buf - n - 1);
|
|
|
|
n += strlen(buf+n);
|
|
|
|
}
|
|
|
|
LogPrintf(LogCOMMAND, "%s\n", buf);
|
|
|
|
}
|
1998-02-17 19:28:01 +00:00
|
|
|
FindExec(bundle, Commands, argc, argv, "", NULL);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-02-02 19:32:16 +00:00
|
|
|
DecodeCommand(struct bundle *bundle, char *buff, int nb, const char *label)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
|
|
|
|
InterpretCommand(buff, nb, &argc, &argv);
|
1998-02-02 19:32:16 +00:00
|
|
|
RunCommand(bundle, argc, (char const *const *)argv, label);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ShowCommand(struct cmdargs const *arg)
|
|
|
|
{
|
1998-02-10 03:23:50 +00:00
|
|
|
if (!prompt_Active(&prompt))
|
|
|
|
LogPrintf(LogWARN, "show: Cannot show without a prompt\n");
|
|
|
|
else if (arg->argc > 0)
|
1998-02-17 19:28:01 +00:00
|
|
|
FindExec(arg->bundle, ShowCommands, arg->argc, arg->argv, "show ", arg->cx);
|
1998-02-10 03:23:50 +00:00
|
|
|
else if (prompt_Active(&prompt))
|
|
|
|
prompt_Printf(&prompt, "Use ``show ?'' to get a list.\n");
|
1998-01-29 00:44:16 +00:00
|
|
|
else
|
|
|
|
LogPrintf(LogWARN, "show command must have arguments\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
TerminalCommand(struct cmdargs const *arg)
|
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
if (LcpInfo.fsm.state > ST_CLOSED) {
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, "LCP state is [%s]\n",
|
|
|
|
StateNames[LcpInfo.fsm.state]);
|
1998-01-29 00:44:16 +00:00
|
|
|
return 1;
|
|
|
|
}
|
1998-02-17 01:05:47 +00:00
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
if (!IsInteractive(1))
|
|
|
|
return (1);
|
1998-02-17 01:05:47 +00:00
|
|
|
|
1998-02-17 19:28:01 +00:00
|
|
|
datalink_Up(arg->cx, 0, 0);
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, "Entering terminal mode.\n");
|
|
|
|
prompt_Printf(&prompt, "Type `~?' for help.\n");
|
1998-02-17 19:28:13 +00:00
|
|
|
prompt_TtyTermMode(&prompt, arg->cx);
|
1998-02-10 03:23:50 +00:00
|
|
|
return 0;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
QuitCommand(struct cmdargs const *arg)
|
|
|
|
{
|
1998-02-10 03:23:50 +00:00
|
|
|
if (prompt_Active(&prompt)) {
|
|
|
|
prompt_Drop(&prompt, 1);
|
1998-01-31 02:48:30 +00:00
|
|
|
if ((mode & MODE_INTER) ||
|
|
|
|
(arg->argc > 0 && !strcasecmp(*arg->argv, "all") &&
|
1998-02-07 20:50:08 +00:00
|
|
|
(VarLocalAuth & LOCAL_AUTH)))
|
1998-01-29 00:44:16 +00:00
|
|
|
Cleanup(EX_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
CloseCommand(struct cmdargs const *arg)
|
|
|
|
{
|
1998-02-17 19:28:35 +00:00
|
|
|
bundle_Close(LcpInfo.fsm.bundle, arg->cx ? arg->cx->name : NULL, 1);
|
1998-01-29 00:44:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
DownCommand(struct cmdargs const *arg)
|
|
|
|
{
|
1998-02-17 19:28:35 +00:00
|
|
|
link_Close(&arg->cx->physical->link, arg->bundle, 0, 1);
|
1998-01-29 00:44:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetModemSpeed(struct cmdargs const *arg)
|
|
|
|
{
|
1998-01-29 00:49:32 +00:00
|
|
|
long speed;
|
|
|
|
char *end;
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-01-29 00:49:32 +00:00
|
|
|
if (arg->argc > 0 && **arg->argv) {
|
1998-02-06 02:22:28 +00:00
|
|
|
if (arg->argc > 1) {
|
|
|
|
LogPrintf(LogWARN, "SetModemSpeed: Too many arguments");
|
|
|
|
return -1;
|
|
|
|
}
|
1998-01-29 00:44:16 +00:00
|
|
|
if (strcasecmp(*arg->argv, "sync") == 0) {
|
1998-02-17 19:28:35 +00:00
|
|
|
Physical_SetSync(arg->cx->physical);
|
1998-01-29 00:44:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1998-02-06 02:22:28 +00:00
|
|
|
end = NULL;
|
1998-01-29 00:49:32 +00:00
|
|
|
speed = strtol(*arg->argv, &end, 10);
|
1998-02-06 02:22:28 +00:00
|
|
|
if (*end) {
|
|
|
|
LogPrintf(LogWARN, "SetModemSpeed: Bad argument \"%s\"", *arg->argv);
|
|
|
|
return -1;
|
|
|
|
}
|
1998-02-17 19:28:35 +00:00
|
|
|
if (Physical_SetSpeed(arg->cx->physical, speed))
|
1998-02-06 02:22:28 +00:00
|
|
|
return 0;
|
1998-01-29 00:44:16 +00:00
|
|
|
LogPrintf(LogWARN, "%s: Invalid speed\n", *arg->argv);
|
1998-02-06 02:22:28 +00:00
|
|
|
} else
|
1998-01-29 00:49:32 +00:00
|
|
|
LogPrintf(LogWARN, "SetModemSpeed: No speed specified\n");
|
1998-02-06 02:22:28 +00:00
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetReconnect(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
if (arg->argc == 2) {
|
1998-02-17 19:28:49 +00:00
|
|
|
arg->cx->cfg.reconnect_timeout = atoi(arg->argv[0]);
|
|
|
|
arg->cx->cfg.max_reconnect = (mode & MODE_DIRECT) ? 0 : atoi(arg->argv[1]);
|
1998-01-29 00:44:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetRedialTimeout(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
int timeout;
|
|
|
|
int tries;
|
|
|
|
char *dot;
|
|
|
|
|
|
|
|
if (arg->argc == 1 || arg->argc == 2) {
|
|
|
|
if (strncasecmp(arg->argv[0], "random", 6) == 0 &&
|
|
|
|
(arg->argv[0][6] == '\0' || arg->argv[0][6] == '.')) {
|
1998-02-17 19:28:49 +00:00
|
|
|
arg->cx->cfg.dial_timeout = -1;
|
1998-01-29 00:44:16 +00:00
|
|
|
randinit();
|
|
|
|
} else {
|
|
|
|
timeout = atoi(arg->argv[0]);
|
|
|
|
|
|
|
|
if (timeout >= 0)
|
1998-02-17 19:28:49 +00:00
|
|
|
arg->cx->cfg.dial_timeout = timeout;
|
1998-01-29 00:44:16 +00:00
|
|
|
else {
|
|
|
|
LogPrintf(LogWARN, "Invalid redial timeout\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dot = strchr(arg->argv[0], '.');
|
|
|
|
if (dot) {
|
|
|
|
if (strcasecmp(++dot, "random") == 0) {
|
1998-02-17 19:28:49 +00:00
|
|
|
arg->cx->cfg.dial_next_timeout = -1;
|
1998-01-29 00:44:16 +00:00
|
|
|
randinit();
|
|
|
|
} else {
|
|
|
|
timeout = atoi(dot);
|
|
|
|
if (timeout >= 0)
|
1998-02-17 19:28:49 +00:00
|
|
|
arg->cx->cfg.dial_next_timeout = timeout;
|
1998-01-29 00:44:16 +00:00
|
|
|
else {
|
|
|
|
LogPrintf(LogWARN, "Invalid next redial timeout\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
1998-02-17 19:28:01 +00:00
|
|
|
/* Default next timeout */
|
1998-02-17 19:28:49 +00:00
|
|
|
arg->cx->cfg.dial_next_timeout = DIAL_NEXT_TIMEOUT;
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
if (arg->argc == 2) {
|
|
|
|
tries = atoi(arg->argv[1]);
|
|
|
|
|
|
|
|
if (tries >= 0) {
|
1998-02-17 19:28:49 +00:00
|
|
|
arg->cx->cfg.max_dial = tries;
|
1998-01-29 00:44:16 +00:00
|
|
|
} else {
|
|
|
|
LogPrintf(LogWARN, "Invalid retry value\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetStoppedTimeout(struct cmdargs const *arg)
|
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
LcpInfo.fsm.StoppedTimer.load = 0;
|
|
|
|
IpcpInfo.fsm.StoppedTimer.load = 0;
|
|
|
|
CcpInfo.fsm.StoppedTimer.load = 0;
|
1998-01-29 00:44:16 +00:00
|
|
|
if (arg->argc <= 3) {
|
|
|
|
if (arg->argc > 0) {
|
1998-01-31 02:48:30 +00:00
|
|
|
LcpInfo.fsm.StoppedTimer.load = atoi(arg->argv[0]) * SECTICKS;
|
1998-01-29 00:44:16 +00:00
|
|
|
if (arg->argc > 1) {
|
1998-01-31 02:48:30 +00:00
|
|
|
IpcpInfo.fsm.StoppedTimer.load = atoi(arg->argv[1]) * SECTICKS;
|
1998-01-29 00:44:16 +00:00
|
|
|
if (arg->argc > 2)
|
1998-01-31 02:48:30 +00:00
|
|
|
CcpInfo.fsm.StoppedTimer.load = atoi(arg->argv[2]) * SECTICKS;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ismask(x) \
|
|
|
|
(*x == '0' && strlen(x) == 4 && strspn(x+1, "0123456789.") == 3)
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetServer(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
int res = -1;
|
|
|
|
|
|
|
|
if (arg->argc > 0 && arg->argc < 4) {
|
|
|
|
const char *port, *passwd, *mask;
|
|
|
|
|
|
|
|
/* What's what ? */
|
|
|
|
port = arg->argv[0];
|
|
|
|
if (arg->argc == 2)
|
|
|
|
if (ismask(arg->argv[1])) {
|
|
|
|
passwd = NULL;
|
|
|
|
mask = arg->argv[1];
|
|
|
|
} else {
|
|
|
|
passwd = arg->argv[1];
|
|
|
|
mask = NULL;
|
|
|
|
}
|
|
|
|
else if (arg->argc == 3) {
|
|
|
|
passwd = arg->argv[1];
|
|
|
|
mask = arg->argv[2];
|
|
|
|
if (!ismask(mask))
|
|
|
|
return -1;
|
|
|
|
} else
|
|
|
|
passwd = mask = NULL;
|
|
|
|
|
|
|
|
if (passwd == NULL)
|
|
|
|
VarHaveLocalAuthKey = 0;
|
|
|
|
else {
|
|
|
|
strncpy(VarLocalAuthKey, passwd, sizeof VarLocalAuthKey - 1);
|
|
|
|
VarLocalAuthKey[sizeof VarLocalAuthKey - 1] = '\0';
|
|
|
|
VarHaveLocalAuthKey = 1;
|
|
|
|
}
|
|
|
|
LocalAuthInit();
|
|
|
|
|
|
|
|
if (strcasecmp(port, "none") == 0) {
|
|
|
|
if (mask != NULL || passwd != NULL)
|
|
|
|
return -1;
|
1998-02-09 19:24:03 +00:00
|
|
|
|
|
|
|
if (ServerClose())
|
|
|
|
LogPrintf(LogPHASE, "Disabled server port.\n");
|
1998-01-29 00:44:16 +00:00
|
|
|
res = 0;
|
|
|
|
} else if (*port == '/') {
|
|
|
|
mode_t imask;
|
|
|
|
|
|
|
|
if (mask != NULL) {
|
|
|
|
unsigned m;
|
|
|
|
|
|
|
|
if (sscanf(mask, "%o", &m) == 1)
|
|
|
|
imask = m;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
} else
|
|
|
|
imask = (mode_t)-1;
|
|
|
|
res = ServerLocalOpen(port, imask);
|
|
|
|
} else {
|
|
|
|
int iport;
|
|
|
|
|
|
|
|
if (mask != NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (strspn(port, "0123456789") != strlen(port)) {
|
|
|
|
struct servent *s;
|
|
|
|
|
|
|
|
if ((s = getservbyname(port, "tcp")) == NULL) {
|
|
|
|
iport = 0;
|
|
|
|
LogPrintf(LogWARN, "%s: Invalid port or service\n", port);
|
|
|
|
} else
|
|
|
|
iport = ntohs(s->s_port);
|
|
|
|
} else
|
|
|
|
iport = atoi(port);
|
|
|
|
res = iport ? ServerTcpOpen(iport) : -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetModemParity(struct cmdargs const *arg)
|
|
|
|
{
|
1998-02-17 19:28:35 +00:00
|
|
|
return arg->argc > 0 ? modem_SetParity(arg->cx->physical, *arg->argv) : -1;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetLogLevel(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int res;
|
|
|
|
int argc;
|
|
|
|
char const *const *argv, *argp;
|
|
|
|
void (*Discard)(int), (*Keep)(int);
|
|
|
|
void (*DiscardAll)(void);
|
|
|
|
|
|
|
|
argc = arg->argc;
|
|
|
|
argv = arg->argv;
|
|
|
|
res = 0;
|
|
|
|
if (argc == 0 || strcasecmp(argv[0], "local")) {
|
|
|
|
Discard = LogDiscard;
|
|
|
|
Keep = LogKeep;
|
|
|
|
DiscardAll = LogDiscardAll;
|
|
|
|
} else {
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
Discard = LogDiscardLocal;
|
|
|
|
Keep = LogKeepLocal;
|
|
|
|
DiscardAll = LogDiscardAllLocal;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc == 0 || (argv[0][0] != '+' && argv[0][0] != '-'))
|
|
|
|
DiscardAll();
|
|
|
|
while (argc--) {
|
|
|
|
argp = **argv == '+' || **argv == '-' ? *argv + 1 : *argv;
|
|
|
|
for (i = LogMIN; i <= LogMAX; i++)
|
|
|
|
if (strcasecmp(argp, LogName(i)) == 0) {
|
|
|
|
if (**argv == '-')
|
|
|
|
(*Discard)(i);
|
|
|
|
else
|
|
|
|
(*Keep)(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i > LogMAX) {
|
|
|
|
LogPrintf(LogWARN, "%s: Invalid log value\n", argp);
|
|
|
|
res = -1;
|
|
|
|
}
|
|
|
|
argv++;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetEscape(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
int code;
|
|
|
|
int argc = arg->argc;
|
|
|
|
char const *const *argv = arg->argv;
|
|
|
|
|
|
|
|
for (code = 0; code < 33; code++)
|
1998-02-18 19:35:20 +00:00
|
|
|
arg->cx->physical->async.cfg.EscMap[code] = 0;
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
while (argc-- > 0) {
|
|
|
|
sscanf(*argv++, "%x", &code);
|
|
|
|
code &= 0xff;
|
1998-02-18 19:35:20 +00:00
|
|
|
arg->cx->physical->async.cfg.EscMap[code >> 3] |= (1 << (code & 7));
|
|
|
|
arg->cx->physical->async.cfg.EscMap[32] = 1;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetInitialMRU(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
long mru;
|
|
|
|
const char *err;
|
|
|
|
|
|
|
|
if (arg->argc > 0) {
|
|
|
|
mru = atol(*arg->argv);
|
|
|
|
if (mru < MIN_MRU)
|
|
|
|
err = "Given MRU value (%ld) is too small.\n";
|
|
|
|
else if (mru > MAX_MRU)
|
|
|
|
err = "Given MRU value (%ld) is too big.\n";
|
|
|
|
else {
|
|
|
|
VarMRU = mru;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
LogPrintf(LogWARN, err, mru);
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetPreferredMTU(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
long mtu;
|
|
|
|
const char *err;
|
|
|
|
|
|
|
|
if (arg->argc > 0) {
|
|
|
|
mtu = atol(*arg->argv);
|
|
|
|
if (mtu == 0) {
|
|
|
|
VarPrefMTU = 0;
|
|
|
|
return 0;
|
|
|
|
} else if (mtu < MIN_MTU)
|
|
|
|
err = "Given MTU value (%ld) is too small.\n";
|
|
|
|
else if (mtu > MAX_MTU)
|
|
|
|
err = "Given MTU value (%ld) is too big.\n";
|
|
|
|
else {
|
|
|
|
VarPrefMTU = mtu;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
LogPrintf(LogWARN, err, mtu);
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetIdleTimeout(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
if (arg->argc > 0) {
|
|
|
|
VarIdleTimeout = atoi(arg->argv[0]);
|
1998-02-02 19:32:16 +00:00
|
|
|
/* If we're connected, restart the idle timer */
|
|
|
|
UpdateIdleTimer(arg->bundle);
|
1998-01-29 00:44:16 +00:00
|
|
|
if (arg->argc > 1) {
|
|
|
|
VarLqrTimeout = atoi(arg->argv[1]);
|
|
|
|
if (VarLqrTimeout < 1)
|
|
|
|
VarLqrTimeout = 30;
|
|
|
|
if (arg->argc > 2) {
|
|
|
|
VarRetryTimeout = atoi(arg->argv[2]);
|
|
|
|
if (VarRetryTimeout < 1 || VarRetryTimeout > 10)
|
|
|
|
VarRetryTimeout = 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct in_addr
|
|
|
|
GetIpAddr(const char *cp)
|
|
|
|
{
|
|
|
|
struct hostent *hp;
|
|
|
|
struct in_addr ipaddr;
|
|
|
|
|
|
|
|
if (inet_aton(cp, &ipaddr) == 0) {
|
|
|
|
hp = gethostbyname(cp);
|
|
|
|
if (hp && hp->h_addrtype == AF_INET)
|
|
|
|
memcpy(&ipaddr, hp->h_addr, hp->h_length);
|
|
|
|
else
|
|
|
|
ipaddr.s_addr = 0;
|
|
|
|
}
|
|
|
|
return (ipaddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetInterfaceAddr(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
const char *hisaddr;
|
|
|
|
|
|
|
|
hisaddr = NULL;
|
1998-01-29 23:11:44 +00:00
|
|
|
IpcpInfo.DefMyAddress.ipaddr.s_addr = INADDR_ANY;
|
|
|
|
IpcpInfo.DefHisAddress.ipaddr.s_addr = INADDR_ANY;
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
if (arg->argc > 4)
|
|
|
|
return -1;
|
|
|
|
|
1998-01-29 23:11:44 +00:00
|
|
|
IpcpInfo.HaveTriggerAddress = 0;
|
1998-01-29 00:44:16 +00:00
|
|
|
ifnetmask.s_addr = 0;
|
1998-01-29 23:11:44 +00:00
|
|
|
iplist_reset(&IpcpInfo.DefHisChoice);
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
if (arg->argc > 0) {
|
1998-01-29 23:11:44 +00:00
|
|
|
if (!ParseAddr(arg->argc, arg->argv, &IpcpInfo.DefMyAddress.ipaddr,
|
|
|
|
&IpcpInfo.DefMyAddress.mask, &IpcpInfo.DefMyAddress.width))
|
1998-01-29 00:44:16 +00:00
|
|
|
return 1;
|
|
|
|
if (arg->argc > 1) {
|
|
|
|
hisaddr = arg->argv[1];
|
|
|
|
if (arg->argc > 2) {
|
|
|
|
ifnetmask = GetIpAddr(arg->argv[2]);
|
|
|
|
if (arg->argc > 3) {
|
1998-01-29 23:11:44 +00:00
|
|
|
IpcpInfo.TriggerAddress = GetIpAddr(arg->argv[3]);
|
|
|
|
IpcpInfo.HaveTriggerAddress = 1;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For backwards compatibility, 0.0.0.0 means any address.
|
|
|
|
*/
|
1998-01-29 23:11:44 +00:00
|
|
|
if (IpcpInfo.DefMyAddress.ipaddr.s_addr == INADDR_ANY) {
|
|
|
|
IpcpInfo.DefMyAddress.mask.s_addr = INADDR_ANY;
|
|
|
|
IpcpInfo.DefMyAddress.width = 0;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
1998-01-29 23:11:44 +00:00
|
|
|
IpcpInfo.want_ipaddr.s_addr = IpcpInfo.DefMyAddress.ipaddr.s_addr;
|
|
|
|
|
|
|
|
if (IpcpInfo.DefHisAddress.ipaddr.s_addr == INADDR_ANY) {
|
|
|
|
IpcpInfo.DefHisAddress.mask.s_addr = INADDR_ANY;
|
|
|
|
IpcpInfo.DefHisAddress.width = 0;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
1998-02-02 19:32:16 +00:00
|
|
|
if (hisaddr && !UseHisaddr(arg->bundle, hisaddr, mode & MODE_AUTO))
|
1998-01-29 00:44:16 +00:00
|
|
|
return 4;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NOMSEXT
|
|
|
|
|
|
|
|
static void
|
|
|
|
SetMSEXT(struct in_addr * pri_addr,
|
|
|
|
struct in_addr * sec_addr,
|
|
|
|
int argc,
|
|
|
|
char const *const *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(struct cmdargs const *arg)
|
|
|
|
{
|
1998-01-29 23:11:44 +00:00
|
|
|
SetMSEXT(&IpcpInfo.ns_entries[0], &IpcpInfo.ns_entries[1],
|
|
|
|
arg->argc, arg->argv);
|
1998-01-29 00:44:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetNBNS(struct cmdargs const *arg)
|
|
|
|
{
|
1998-01-29 23:11:44 +00:00
|
|
|
SetMSEXT(&IpcpInfo.nbns_entries[0], &IpcpInfo.nbns_entries[1],
|
|
|
|
arg->argc, arg->argv);
|
1998-01-29 00:44:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* MS_EXT */
|
|
|
|
|
1998-02-17 19:28:01 +00:00
|
|
|
static int
|
1998-01-29 00:44:16 +00:00
|
|
|
SetVariable(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
u_long map;
|
|
|
|
const char *argp;
|
1998-02-17 19:28:01 +00:00
|
|
|
int param = (int)arg->cmd->args;
|
|
|
|
struct datalink *cx = arg->cx;
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
if (arg->argc > 0)
|
|
|
|
argp = *arg->argv;
|
|
|
|
else
|
|
|
|
argp = "";
|
|
|
|
|
1998-02-17 19:28:01 +00:00
|
|
|
if ((arg->cmd->lauth & LOCAL_CX) && !cx) {
|
|
|
|
LogPrintf(LogWARN, "set %s: No context (use the `link' command)\n",
|
|
|
|
arg->cmd->name);
|
|
|
|
return 1;
|
|
|
|
} else if (cx && !(arg->cmd->lauth & (LOCAL_CX|LOCAL_CX_OPT))) {
|
|
|
|
LogPrintf(LogWARN, "set %s: Redundant context (%s) ignored\n",
|
|
|
|
arg->cmd->name, cx->name);
|
|
|
|
cx = NULL;
|
|
|
|
}
|
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
switch (param) {
|
|
|
|
case VAR_AUTHKEY:
|
|
|
|
strncpy(VarAuthKey, argp, sizeof VarAuthKey - 1);
|
|
|
|
VarAuthKey[sizeof VarAuthKey - 1] = '\0';
|
|
|
|
break;
|
|
|
|
case VAR_AUTHNAME:
|
|
|
|
strncpy(VarAuthName, argp, sizeof VarAuthName - 1);
|
|
|
|
VarAuthName[sizeof VarAuthName - 1] = '\0';
|
|
|
|
break;
|
|
|
|
case VAR_DIAL:
|
1998-02-16 19:10:03 +00:00
|
|
|
if (!(mode & (MODE_DIRECT|MODE_DEDICATED))) {
|
1998-02-17 19:28:49 +00:00
|
|
|
strncpy(cx->cfg.script.dial, argp, sizeof cx->cfg.script.dial - 1);
|
|
|
|
cx->cfg.script.dial[sizeof cx->cfg.script.dial - 1] = '\0';
|
1998-02-16 19:10:03 +00:00
|
|
|
}
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
case VAR_LOGIN:
|
1998-02-16 19:10:03 +00:00
|
|
|
if (!(mode & (MODE_DIRECT|MODE_DEDICATED))) {
|
1998-02-17 19:28:49 +00:00
|
|
|
strncpy(cx->cfg.script.login, argp, sizeof cx->cfg.script.login - 1);
|
|
|
|
cx->cfg.script.login[sizeof cx->cfg.script.login - 1] = '\0';
|
1998-02-16 19:10:03 +00:00
|
|
|
}
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
case VAR_DEVICE:
|
1998-02-17 19:28:01 +00:00
|
|
|
modem_SetDeviceName(cx->physical, argp);
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
case VAR_ACCMAP:
|
|
|
|
sscanf(argp, "%lx", &map);
|
|
|
|
VarAccmap = map;
|
|
|
|
break;
|
|
|
|
case VAR_PHONE:
|
|
|
|
strncpy(VarPhoneList, argp, sizeof VarPhoneList - 1);
|
|
|
|
VarPhoneList[sizeof VarPhoneList - 1] = '\0';
|
|
|
|
strncpy(VarPhoneCopy, VarPhoneList, sizeof VarPhoneCopy - 1);
|
|
|
|
VarPhoneCopy[sizeof VarPhoneCopy - 1] = '\0';
|
|
|
|
VarNextPhone = VarPhoneCopy;
|
|
|
|
VarAltPhone = NULL;
|
|
|
|
break;
|
|
|
|
case VAR_HANGUP:
|
1998-02-16 19:10:03 +00:00
|
|
|
if (!(mode & (MODE_DIRECT|MODE_DEDICATED))) {
|
1998-02-17 19:28:49 +00:00
|
|
|
strncpy(cx->cfg.script.hangup, argp, sizeof cx->cfg.script.hangup - 1);
|
|
|
|
cx->cfg.script.hangup[sizeof cx->cfg.script.hangup - 1] = '\0';
|
1998-02-16 19:10:03 +00:00
|
|
|
}
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
#ifdef HAVE_DES
|
|
|
|
case VAR_ENC:
|
|
|
|
VarMSChap = !strcasecmp(argp, "mschap");
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetCtsRts(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
if (arg->argc > 0) {
|
1998-01-29 00:49:32 +00:00
|
|
|
if (arg->argc > 1) {
|
|
|
|
LogPrintf(LogWARN, "SetCtsRts: Too many arguments\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
if (strcmp(*arg->argv, "on") == 0)
|
1998-02-16 00:01:12 +00:00
|
|
|
Physical_SetRtsCts(bundle2physical(arg->bundle, NULL), 1);
|
1998-01-29 00:44:16 +00:00
|
|
|
else if (strcmp(*arg->argv, "off") == 0)
|
1998-02-16 00:01:12 +00:00
|
|
|
Physical_SetRtsCts(bundle2physical(arg->bundle, NULL), 0);
|
1998-01-29 00:44:16 +00:00
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetOpenMode(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
if (arg->argc > 0) {
|
|
|
|
if (strcasecmp(*arg->argv, "active") == 0)
|
|
|
|
VarOpenMode = arg->argc > 1 ? atoi(arg->argv[1]) : 1;
|
|
|
|
else if (strcasecmp(*arg->argv, "passive") == 0)
|
|
|
|
VarOpenMode = OPEN_PASSIVE;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct cmdtab const SetCommands[] = {
|
1998-02-17 19:28:01 +00:00
|
|
|
{"accmap", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Set accmap value", "set accmap hex-value", (const 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", (const void *) VAR_AUTHKEY},
|
|
|
|
{"authname", NULL, SetVariable, LOCAL_AUTH,
|
|
|
|
"Set authentication name", "set authname name", (const void *) VAR_AUTHNAME},
|
1998-02-17 19:28:01 +00:00
|
|
|
{"ctsrts", NULL, SetCtsRts, LOCAL_AUTH | LOCAL_CX,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Use CTS/RTS modem signalling", "set ctsrts [on|off]"},
|
1998-02-17 19:28:01 +00:00
|
|
|
{"device", "line", SetVariable, LOCAL_AUTH | LOCAL_CX,
|
|
|
|
"Set modem device name", "set device|line device-name[,device-name]",
|
|
|
|
(const void *) VAR_DEVICE},
|
1998-01-29 00:44:16 +00:00
|
|
|
{"dfilter", NULL, SetDfilter, LOCAL_AUTH,
|
|
|
|
"Set demand filter", "set dfilter ..."},
|
1998-02-17 19:28:01 +00:00
|
|
|
{"dial", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Set dialing script", "set dial chat-script", (const void *) VAR_DIAL},
|
|
|
|
#ifdef HAVE_DES
|
|
|
|
{"encrypt", NULL, SetVariable, LOCAL_AUTH, "Set CHAP encryption algorithm",
|
|
|
|
"set encrypt MSChap|MD5", (const void *) VAR_ENC},
|
|
|
|
#endif
|
1998-02-17 19:28:01 +00:00
|
|
|
{"escape", NULL, SetEscape, LOCAL_AUTH | LOCAL_CX,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Set escape characters", "set escape hex-digit ..."},
|
1998-02-17 19:28:01 +00:00
|
|
|
{"hangup", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Set hangup script", "set hangup chat-script", (const 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,
|
|
|
|
"Set log level", "set log [local] [+|-]value..."},
|
1998-02-17 19:28:01 +00:00
|
|
|
{"login", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Set login script", "set login chat-script", (const 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"},
|
|
|
|
#ifndef NOMSEXT
|
|
|
|
{"nbns", NULL, SetNBNS, LOCAL_AUTH,
|
|
|
|
"Set NetBIOS NameServer", "set nbns pri-addr [sec-addr]"},
|
|
|
|
{"ns", NULL, SetNS, LOCAL_AUTH,
|
|
|
|
"Set NameServer", "set ns pri-addr [sec-addr]"},
|
|
|
|
#endif
|
|
|
|
{"ofilter", NULL, SetOfilter, LOCAL_AUTH,
|
|
|
|
"Set output filter", "set ofilter ..."},
|
1998-02-17 19:28:01 +00:00
|
|
|
{"openmode", NULL, SetOpenMode, LOCAL_AUTH | LOCAL_CX,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Set open mode", "set openmode [active|passive]"},
|
1998-02-17 19:28:01 +00:00
|
|
|
{"parity", NULL, SetModemParity, LOCAL_AUTH | LOCAL_CX,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Set modem parity", "set parity [odd|even|none]"},
|
|
|
|
{"phone", NULL, SetVariable, LOCAL_AUTH, "Set telephone number(s)",
|
|
|
|
"set phone phone1[:phone2[...]]", (const void *) VAR_PHONE},
|
1998-02-17 19:28:01 +00:00
|
|
|
{"reconnect", NULL, SetReconnect, LOCAL_AUTH | LOCAL_CX,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Set Reconnect timeout", "set reconnect value ntries"},
|
1998-02-17 19:28:01 +00:00
|
|
|
{"redial", NULL, SetRedialTimeout, LOCAL_AUTH | LOCAL_CX,
|
|
|
|
"Set Redial timeout", "set redial value|random[.value|random] [attempts]"},
|
1998-01-29 00:44:16 +00:00
|
|
|
{"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]"},
|
1998-02-17 19:28:01 +00:00
|
|
|
{"speed", NULL, SetModemSpeed, LOCAL_AUTH | LOCAL_CX,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Set modem speed", "set speed value"},
|
|
|
|
{"timeout", NULL, SetIdleTimeout, LOCAL_AUTH,
|
|
|
|
"Set Idle timeout", "set timeout value"},
|
|
|
|
{"vj", NULL, SetInitVJ, LOCAL_AUTH,
|
|
|
|
"Set vj values", "set vj slots|slotcomp"},
|
|
|
|
{"help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
|
|
|
|
"Display this message", "set help|? [command]", SetCommands},
|
|
|
|
{NULL, NULL, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetCommand(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
if (arg->argc > 0)
|
1998-02-17 19:28:01 +00:00
|
|
|
FindExec(arg->bundle, SetCommands, arg->argc, arg->argv, "set ", arg->cx);
|
1998-02-10 03:23:50 +00:00
|
|
|
else if (prompt_Active(&prompt))
|
|
|
|
prompt_Printf(&prompt, "Use `set ?' to get a list or `set ? <var>' for"
|
1998-01-29 00:44:16 +00:00
|
|
|
" syntax help.\n");
|
|
|
|
else
|
|
|
|
LogPrintf(LogWARN, "set command must have arguments\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
AddCommand(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
struct in_addr dest, gateway, netmask;
|
|
|
|
int gw;
|
|
|
|
|
|
|
|
if (arg->argc != 3 && arg->argc != 2)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (arg->argc == 2)
|
|
|
|
if (strcasecmp(arg->argv[0], "default"))
|
|
|
|
return -1;
|
|
|
|
else {
|
|
|
|
dest.s_addr = netmask.s_addr = INADDR_ANY;
|
|
|
|
gw = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (strcasecmp(arg->argv[0], "MYADDR") == 0)
|
|
|
|
dest = IpcpInfo.want_ipaddr;
|
|
|
|
else if (strcasecmp(arg->argv[0], "HISADDR") == 0)
|
|
|
|
dest = IpcpInfo.his_ipaddr;
|
|
|
|
else
|
|
|
|
dest = GetIpAddr(arg->argv[0]);
|
|
|
|
netmask = GetIpAddr(arg->argv[1]);
|
|
|
|
gw = 2;
|
|
|
|
}
|
|
|
|
if (strcasecmp(arg->argv[gw], "HISADDR") == 0)
|
|
|
|
gateway = IpcpInfo.his_ipaddr;
|
|
|
|
else if (strcasecmp(arg->argv[gw], "INTERFACE") == 0)
|
|
|
|
gateway.s_addr = INADDR_ANY;
|
|
|
|
else
|
|
|
|
gateway = GetIpAddr(arg->argv[gw]);
|
1998-02-02 19:32:16 +00:00
|
|
|
bundle_SetRoute(arg->bundle, RTM_ADD, dest, gateway, netmask,
|
1998-02-17 19:28:01 +00:00
|
|
|
arg->cmd->args ? 1 : 0);
|
1998-01-29 00:44:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
DeleteCommand(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
struct in_addr dest, none;
|
|
|
|
|
|
|
|
if (arg->argc == 1)
|
|
|
|
if(strcasecmp(arg->argv[0], "all") == 0)
|
1998-02-02 19:32:16 +00:00
|
|
|
DeleteIfRoutes(arg->bundle, 0);
|
1998-01-29 00:44:16 +00:00
|
|
|
else {
|
|
|
|
if (strcasecmp(arg->argv[0], "MYADDR") == 0)
|
|
|
|
dest = IpcpInfo.want_ipaddr;
|
|
|
|
else if (strcasecmp(arg->argv[0], "default") == 0)
|
|
|
|
dest.s_addr = INADDR_ANY;
|
|
|
|
else
|
|
|
|
dest = GetIpAddr(arg->argv[0]);
|
|
|
|
none.s_addr = INADDR_ANY;
|
1998-02-02 19:32:16 +00:00
|
|
|
bundle_SetRoute(arg->bundle, RTM_DELETE, dest, none, none,
|
1998-02-17 19:28:01 +00:00
|
|
|
arg->cmd->args ? 1 : 0);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NOALIAS
|
|
|
|
static struct cmdtab const AliasCommands[] =
|
|
|
|
{
|
|
|
|
{"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]",
|
|
|
|
(const void *) PKT_ALIAS_DENY_INCOMING},
|
|
|
|
{"log", NULL, AliasOption, LOCAL_AUTH,
|
|
|
|
"log aliasing link creation", "alias log [yes|no]",
|
|
|
|
(const void *) PKT_ALIAS_LOG},
|
|
|
|
{"same_ports", NULL, AliasOption, LOCAL_AUTH,
|
|
|
|
"try to leave port numbers unchanged", "alias same_ports [yes|no]",
|
|
|
|
(const void *) PKT_ALIAS_SAME_PORTS},
|
|
|
|
{"use_sockets", NULL, AliasOption, LOCAL_AUTH,
|
|
|
|
"allocate host sockets", "alias use_sockets [yes|no]",
|
|
|
|
(const void *) PKT_ALIAS_USE_SOCKETS},
|
|
|
|
{"unregistered_only", NULL, AliasOption, LOCAL_AUTH,
|
|
|
|
"alias unregistered (private) IP address space only",
|
|
|
|
"alias unregistered_only [yes|no]",
|
|
|
|
(const void *) PKT_ALIAS_UNREGISTERED_ONLY},
|
|
|
|
{"help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
|
|
|
|
"Display this message", "alias help|? [command]", AliasCommands},
|
|
|
|
{NULL, NULL, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
AliasCommand(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
if (arg->argc > 0)
|
1998-02-17 19:28:01 +00:00
|
|
|
FindExec(arg->bundle, AliasCommands, arg->argc, arg->argv, "alias ", arg->cx);
|
1998-02-10 03:23:50 +00:00
|
|
|
else if (prompt_Active(&prompt))
|
|
|
|
prompt_Printf(&prompt, "Use `alias help' to get a list or `alias help"
|
1998-02-02 19:32:16 +00:00
|
|
|
" <option>' for syntax help.\n");
|
1998-01-29 00:44:16 +00:00
|
|
|
else
|
|
|
|
LogPrintf(LogWARN, "alias command must have arguments\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
AliasEnable(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
if (arg->argc == 1)
|
|
|
|
if (strcasecmp(arg->argv[0], "yes") == 0) {
|
|
|
|
if (!(mode & MODE_ALIAS)) {
|
|
|
|
if (loadAliasHandlers(&VarAliasHandlers) == 0) {
|
|
|
|
mode |= MODE_ALIAS;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
LogPrintf(LogWARN, "Cannot load alias library\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
} else if (strcasecmp(arg->argv[0], "no") == 0) {
|
|
|
|
if (mode & MODE_ALIAS) {
|
|
|
|
unloadAliasHandlers();
|
|
|
|
mode &= ~MODE_ALIAS;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
AliasOption(struct cmdargs const *arg)
|
|
|
|
{
|
1998-02-17 19:28:01 +00:00
|
|
|
unsigned param = (unsigned)arg->cmd->args;
|
1998-01-29 00:44:16 +00:00
|
|
|
if (arg->argc == 1)
|
|
|
|
if (strcasecmp(arg->argv[0], "yes") == 0) {
|
|
|
|
if (mode & MODE_ALIAS) {
|
|
|
|
VarPacketAliasSetMode(param, param);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
LogPrintf(LogWARN, "alias not enabled\n");
|
|
|
|
} else if (strcmp(arg->argv[0], "no") == 0) {
|
|
|
|
if (mode & MODE_ALIAS) {
|
|
|
|
VarPacketAliasSetMode(0, param);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
LogPrintf(LogWARN, "alias not enabled\n");
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif /* #ifndef NOALIAS */
|
|
|
|
|
|
|
|
static struct cmdtab const AllowCommands[] = {
|
|
|
|
{"users", "user", AllowUsers, LOCAL_AUTH,
|
|
|
|
"Allow users access to ppp", "allow users logname..."},
|
|
|
|
{"modes", "mode", AllowModes, LOCAL_AUTH,
|
|
|
|
"Only allow certain ppp modes", "allow modes mode..."},
|
|
|
|
{"help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
|
|
|
|
"Display this message", "allow help|? [command]", AllowCommands},
|
|
|
|
{NULL, NULL, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
AllowCommand(struct cmdargs const *arg)
|
|
|
|
{
|
1998-02-02 19:32:16 +00:00
|
|
|
/* arg->bundle may be NULL (see ValidSystem()) ! */
|
1998-01-29 00:44:16 +00:00
|
|
|
if (arg->argc > 0)
|
1998-02-17 19:28:01 +00:00
|
|
|
FindExec(arg->bundle, AllowCommands, arg->argc, arg->argv, "allow ", arg->cx);
|
1998-02-10 03:23:50 +00:00
|
|
|
else if (prompt_Active(&prompt))
|
|
|
|
prompt_Printf(&prompt, "Use `allow ?' to get a list or `allow ? <cmd>' for"
|
1998-01-29 00:44:16 +00:00
|
|
|
" syntax help.\n");
|
|
|
|
else
|
|
|
|
LogPrintf(LogWARN, "allow command must have arguments\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
1998-02-17 19:28:01 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
LinkCommand(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
if (arg->argc > 1) {
|
|
|
|
struct datalink *cx = bundle2datalink(arg->bundle, arg->argv[0]);
|
|
|
|
if (cx)
|
|
|
|
FindExec(arg->bundle, Commands, arg->argc - 1, arg->argv + 1, "", cx);
|
|
|
|
else {
|
|
|
|
LogPrintf(LogWARN, "link: %s: Invalid link name\n", arg->argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LogPrintf(LogWARN, "Usage: %s\n", arg->cmd->syntax);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|