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-05-01 19:26:12 +00:00
|
|
|
* $Id: command.c,v 1.131.2.76 1998/05/01 19:22:16 brian Exp $
|
1998-01-29 00:44:16 +00:00
|
|
|
*
|
|
|
|
*/
|
1998-04-07 00:54:26 +00:00
|
|
|
#include <sys/types.h>
|
1998-01-29 00:44:16 +00:00
|
|
|
#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>
|
1998-04-10 13:19:23 +00:00
|
|
|
#include <sys/un.h>
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
#ifndef NOALIAS
|
|
|
|
#include <alias.h>
|
|
|
|
#endif
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <paths.h>
|
1998-04-07 00:54:26 +00:00
|
|
|
#include <signal.h>
|
1998-01-29 00:44:16 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <termios.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-03-16 22:54:35 +00:00
|
|
|
#include "slcompress.h"
|
1998-01-29 00:44:16 +00:00
|
|
|
#include "ipcp.h"
|
|
|
|
#include "modem.h"
|
|
|
|
#ifndef NOALIAS
|
|
|
|
#include "alias_cmd.h"
|
|
|
|
#endif
|
1998-03-13 00:44:26 +00:00
|
|
|
#include "lqr.h"
|
1998-01-29 00:44:16 +00:00
|
|
|
#include "hdlc.h"
|
|
|
|
#include "loadalias.h"
|
|
|
|
#include "systems.h"
|
1998-03-16 22:52:54 +00:00
|
|
|
#include "filter.h"
|
1998-03-20 19:48:28 +00:00
|
|
|
#include "descriptor.h"
|
1998-01-29 00:44:16 +00:00
|
|
|
#include "main.h"
|
|
|
|
#include "route.h"
|
|
|
|
#include "ccp.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-01-29 00:49:32 +00:00
|
|
|
#include "physical.h"
|
1998-04-03 19:21:56 +00:00
|
|
|
#include "mp.h"
|
|
|
|
#include "bundle.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-03-01 01:07:49 +00:00
|
|
|
#include "chap.h"
|
1998-02-16 00:01:12 +00:00
|
|
|
#include "datalink.h"
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-04-16 00:26:21 +00:00
|
|
|
/* ``set'' values */
|
|
|
|
#define VAR_AUTHKEY 0
|
|
|
|
#define VAR_DIAL 1
|
|
|
|
#define VAR_LOGIN 2
|
|
|
|
#define VAR_AUTHNAME 3
|
|
|
|
#define VAR_WINSIZE 4
|
|
|
|
#define VAR_DEVICE 5
|
|
|
|
#define VAR_ACCMAP 6
|
1998-04-23 03:23:03 +00:00
|
|
|
#define VAR_MRRU 7
|
|
|
|
#define VAR_MRU 8
|
|
|
|
#define VAR_MTU 9
|
|
|
|
#define VAR_OPENMODE 10
|
|
|
|
#define VAR_PHONE 11
|
|
|
|
#define VAR_HANGUP 12
|
|
|
|
#define VAR_ENC 13
|
|
|
|
#define VAR_IDLETIMEOUT 14
|
|
|
|
#define VAR_LQRPERIOD 15
|
|
|
|
#define VAR_LCPRETRY 16
|
|
|
|
#define VAR_CHAPRETRY 17
|
|
|
|
#define VAR_PAPRETRY 18
|
|
|
|
#define VAR_CCPRETRY 19
|
|
|
|
#define VAR_IPCPRETRY 20
|
|
|
|
#define VAR_DNS 21
|
|
|
|
#define VAR_NBNS 22
|
1998-04-16 00:26:21 +00:00
|
|
|
|
|
|
|
/* ``accept|deny|disable|enable'' masks */
|
|
|
|
#define NEG_HISMASK (1)
|
|
|
|
#define NEG_MYMASK (2)
|
|
|
|
|
|
|
|
/* ``accept|deny|disable|enable'' values */
|
|
|
|
#define NEG_ACFCOMP 40
|
|
|
|
#define NEG_CHAP 41
|
|
|
|
#define NEG_DEFLATE 42
|
|
|
|
#define NEG_LQR 43
|
|
|
|
#define NEG_PAP 44
|
|
|
|
#define NEG_PPPDDEFLATE 45
|
|
|
|
#define NEG_PRED1 46
|
|
|
|
#define NEG_PROTOCOMP 47
|
1998-04-23 03:23:03 +00:00
|
|
|
#define NEG_SHORTSEQ 48
|
|
|
|
#define NEG_VJCOMP 49
|
|
|
|
#define NEG_DNS 50
|
1998-04-16 00:26:21 +00:00
|
|
|
|
1998-04-30 23:53:56 +00:00
|
|
|
const char Version[] = "2.0-beta";
|
1998-05-01 19:26:12 +00:00
|
|
|
const char VersionDate[] = "$Date: 1998/05/01 19:22:16 $";
|
1998-04-30 23:53:56 +00:00
|
|
|
|
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 *);
|
1998-04-19 02:23:21 +00:00
|
|
|
static int OpenCommand(struct cmdargs const *);
|
1998-02-17 19:28:01 +00:00
|
|
|
static int CloseCommand(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 *);
|
1998-04-16 00:26:21 +00:00
|
|
|
static int NegotiateCommand(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;
|
|
|
|
|
1998-04-03 19:26:02 +00:00
|
|
|
if (!arg->prompt) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "help: Cannot help without a prompt\n");
|
1998-04-03 19:26:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-04-14 23:17:24 +00:00
|
|
|
if (arg->argc > arg->argn) {
|
1998-04-03 19:24:31 +00:00
|
|
|
for (cmd = arg->cmdtab; cmd->name || cmd->alias; cmd++)
|
1998-04-03 19:26:02 +00:00
|
|
|
if ((cmd->lauth & arg->prompt->auth) &&
|
1998-04-14 23:17:24 +00:00
|
|
|
((cmd->name && !strcasecmp(cmd->name, arg->argv[arg->argn])) ||
|
|
|
|
(cmd->alias && !strcasecmp(cmd->alias, arg->argv[arg->argn])))) {
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, "%s\n", cmd->syntax);
|
1998-01-29 00:44:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
1998-04-03 19:26:02 +00:00
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
cmax = dmax = 0;
|
1998-02-17 19:28:01 +00:00
|
|
|
for (cmd = arg->cmdtab; cmd->func; cmd++)
|
1998-04-03 19:26:02 +00:00
|
|
|
if (cmd->name && (cmd->lauth & arg->prompt->auth)) {
|
1998-01-29 00:44:16 +00:00
|
|
|
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-04-03 19:26:02 +00:00
|
|
|
if (cmd->name && (cmd->lauth & arg->prompt->auth)) {
|
|
|
|
prompt_Printf(arg->prompt, " %-*.*s: %-*.*s",
|
1998-01-29 00:44:16 +00:00
|
|
|
cmax, cmax, cmd->name, dmax, dmax, cmd->helpmes);
|
|
|
|
if (++n % cols == 0)
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, "\n");
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
if (n % cols != 0)
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, "\n");
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-04-05 22:48:25 +00:00
|
|
|
static int
|
|
|
|
CloneCommand(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
int f;
|
|
|
|
|
1998-04-14 23:17:24 +00:00
|
|
|
if (arg->argc == arg->argn)
|
1998-04-05 22:48:25 +00:00
|
|
|
return -1;
|
|
|
|
|
1998-04-24 19:16:15 +00:00
|
|
|
if (!arg->bundle->ncp.mp.cfg.mrru) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "clone: Only available in multilink mode\n");
|
1998-04-05 22:48:25 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1998-04-14 23:17:24 +00:00
|
|
|
for (f = arg->argn; f < arg->argc; f++)
|
1998-04-05 22:48:25 +00:00
|
|
|
bundle_DatalinkClone(arg->bundle, arg->cx, arg->argv[f]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
RemoveCommand(struct cmdargs const *arg)
|
|
|
|
{
|
1998-04-14 23:17:24 +00:00
|
|
|
if (arg->argc != arg->argn)
|
1998-04-05 22:48:25 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (arg->cx->state != DATALINK_CLOSED) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "remove: Cannot delete links that aren't closed\n");
|
1998-04-05 22:48:25 +00:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
bundle_DatalinkRemove(arg->bundle, arg->cx);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-04-10 13:19:23 +00:00
|
|
|
int
|
|
|
|
LoadCommand(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
|
1998-04-14 23:17:24 +00:00
|
|
|
if (arg->argc > arg->argn)
|
|
|
|
name = arg->argv[arg->argn];
|
1998-04-10 13:19:23 +00:00
|
|
|
else
|
|
|
|
name = "default";
|
|
|
|
|
1998-05-01 19:26:12 +00:00
|
|
|
if (!system_IsValid(name, arg->prompt, arg->bundle->phys_type)) {
|
|
|
|
log_Printf(LogERROR, "%s: Label not allowed\n", name);
|
1998-04-10 13:19:23 +00:00
|
|
|
return 1;
|
1998-04-23 03:23:03 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Set the label before & after so that `set enddisc' works and
|
|
|
|
* we handle nested `load' commands.
|
|
|
|
*/
|
|
|
|
bundle_SetLabel(arg->bundle, arg->argc > arg->argn ? name : NULL);
|
1998-05-01 19:26:12 +00:00
|
|
|
if (system_Select(arg->bundle, name, CONFFILE, arg->prompt) < 0) {
|
1998-04-23 03:23:03 +00:00
|
|
|
bundle_SetLabel(arg->bundle, NULL);
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "%s: label not found.\n", name);
|
1998-04-23 03:23:03 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
bundle_SetLabel(arg->bundle, arg->argc > arg->argn ? name : NULL);
|
|
|
|
}
|
1998-04-10 13:19:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SaveCommand(struct cmdargs const *arg)
|
|
|
|
{
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "save command is not implemented (yet).\n");
|
1998-04-10 13:19:23 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
static int
|
|
|
|
DialCommand(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
|
1998-04-10 13:19:23 +00:00
|
|
|
if ((arg->cx && !(arg->cx->physical->type & (PHYS_MANUAL|PHYS_DEMAND)))
|
|
|
|
|| (!arg->cx && (arg->bundle->phys_type & ~(PHYS_MANUAL|PHYS_DEMAND)))) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "Manual dial is only available for auto and"
|
1998-04-19 02:23:21 +00:00
|
|
|
" interactive links\n");
|
1998-01-29 00:44:16 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1998-04-14 23:17:24 +00:00
|
|
|
if (arg->argc > arg->argn && (res = LoadCommand(arg)) != 0)
|
1998-01-29 00:44:16 +00:00
|
|
|
return res;
|
|
|
|
|
1998-04-10 13:19:23 +00:00
|
|
|
bundle_Open(arg->bundle, arg->cx ? arg->cx->name : NULL, PHYS_ALL);
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 */
|
1998-04-10 13:19:23 +00:00
|
|
|
if (arg->prompt && arg->prompt->owner) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "Can't start a shell from a network connection\n");
|
1998-01-29 00:44:16 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-04-25 10:49:52 +00:00
|
|
|
if (arg->argc == arg->argn) {
|
1998-04-10 13:19:23 +00:00
|
|
|
if (!arg->prompt) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "Can't start an interactive shell from"
|
1998-04-10 13:19:23 +00:00
|
|
|
" a config file\n");
|
|
|
|
return 1;
|
|
|
|
} else if (arg->prompt->owner) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "Can't start an interactive shell from"
|
1998-04-10 13:19:23 +00:00
|
|
|
" a socket connection\n");
|
1998-01-29 00:44:16 +00:00
|
|
|
return 1;
|
|
|
|
} else if (bg) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "Can only start an interactive shell in"
|
1998-01-29 00:44:16 +00:00
|
|
|
" the foreground mode\n");
|
|
|
|
return 1;
|
|
|
|
}
|
1998-04-25 10:49:52 +00:00
|
|
|
}
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
if ((shpid = fork()) == 0) {
|
1998-04-30 23:53:56 +00:00
|
|
|
int i, fd;
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-04-10 13:19:23 +00:00
|
|
|
if ((shell = getenv("SHELL")) == 0)
|
|
|
|
shell = _PATH_BSHELL;
|
|
|
|
|
1998-05-01 19:26:12 +00:00
|
|
|
timer_TermService();
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-04-03 19:26:02 +00:00
|
|
|
if (arg->prompt)
|
|
|
|
fd = arg->prompt->fd_out;
|
1998-05-01 19:20:09 +00:00
|
|
|
else if ((fd = open(_PATH_DEVNULL, O_RDWR)) == -1) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogALERT, "Failed to open %s: %s\n",
|
1998-05-01 19:20:09 +00:00
|
|
|
_PATH_DEVNULL, strerror(errno));
|
1998-01-29 00:44:16 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
dup2(fd, i);
|
|
|
|
|
1998-05-01 19:22:23 +00:00
|
|
|
fcntl(3, F_SETFD, 1); /* Set close-on-exec flag */
|
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
setuid(geteuid());
|
1998-04-14 23:17:24 +00:00
|
|
|
if (arg->argc > arg->argn) {
|
1998-01-29 00:44:16 +00:00
|
|
|
/* substitute pseudo args */
|
1998-04-14 23:17:24 +00:00
|
|
|
argv[0] = strdup(arg->argv[arg->argn]);
|
1998-04-19 07:22:31 +00:00
|
|
|
for (argc = 1; argc < arg->argc - arg->argn; argc++) {
|
|
|
|
if (strcasecmp(arg->argv[argc + arg->argn], "HISADDR") == 0)
|
1998-03-13 21:07:46 +00:00
|
|
|
argv[argc] = strdup(inet_ntoa(arg->bundle->ncp.ipcp.peer_ip));
|
1998-04-19 07:22:31 +00:00
|
|
|
else if (strcasecmp(arg->argv[argc + arg->argn], "INTERFACE") == 0)
|
1998-02-02 19:32:16 +00:00
|
|
|
argv[argc] = strdup(arg->bundle->ifname);
|
1998-04-19 07:22:31 +00:00
|
|
|
else if (strcasecmp(arg->argv[argc + arg->argn], "MYADDR") == 0)
|
1998-03-13 21:07:46 +00:00
|
|
|
argv[argc] = strdup(inet_ntoa(arg->bundle->ncp.ipcp.my_ip));
|
1998-01-29 00:44:16 +00:00
|
|
|
else
|
1998-04-19 07:22:31 +00:00
|
|
|
argv[argc] = strdup(arg->argv[argc + arg->argn]);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
argv[argc] = NULL;
|
|
|
|
if (bg) {
|
|
|
|
pid_t p;
|
|
|
|
|
|
|
|
p = getpid();
|
|
|
|
if (daemon(1, 1) == -1) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogERROR, "%d: daemon: %s\n", p, strerror(errno));
|
1998-01-29 00:44:16 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
1998-04-03 19:26:02 +00:00
|
|
|
} else if (arg->prompt)
|
1998-04-14 23:17:24 +00:00
|
|
|
printf("ppp: Pausing until %s finishes\n", arg->argv[arg->argn]);
|
1998-01-29 00:44:16 +00:00
|
|
|
execvp(argv[0], argv);
|
|
|
|
} else {
|
1998-04-03 19:26:02 +00:00
|
|
|
if (arg->prompt)
|
1998-01-29 00:44:16 +00:00
|
|
|
printf("ppp: Pausing until %s finishes\n", shell);
|
1998-04-10 13:19:23 +00:00
|
|
|
prompt_TtyOldMode(arg->prompt);
|
1998-01-29 00:44:16 +00:00
|
|
|
execl(shell, shell, NULL);
|
|
|
|
}
|
|
|
|
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "exec() of %s failed\n",
|
1998-04-14 23:17:24 +00:00
|
|
|
arg->argc > arg->argn ? arg->argv[arg->argn] : shell);
|
1998-01-29 00:44:16 +00:00
|
|
|
exit(255);
|
|
|
|
}
|
1998-04-10 13:19:23 +00:00
|
|
|
|
|
|
|
if (shpid == (pid_t) - 1)
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogERROR, "Fork failed: %s\n", strerror(errno));
|
1998-04-10 13:19:23 +00:00
|
|
|
else {
|
1998-01-29 00:44:16 +00:00
|
|
|
int status;
|
|
|
|
waitpid(shpid, &status, 0);
|
|
|
|
}
|
|
|
|
|
1998-04-10 13:19:23 +00:00
|
|
|
if (arg->prompt && !arg->prompt->owner)
|
1998-04-04 10:34:28 +00:00
|
|
|
prompt_TtyCommandMode(arg->prompt);
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-04-10 13:19:23 +00:00
|
|
|
return 0;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
BgShellCommand(struct cmdargs const *arg)
|
|
|
|
{
|
1998-04-14 23:17:24 +00:00
|
|
|
if (arg->argc == arg->argn)
|
1998-01-29 00:44:16 +00:00
|
|
|
return -1;
|
|
|
|
return ShellCommand(arg, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
FgShellCommand(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
return ShellCommand(arg, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct cmdtab const Commands[] = {
|
1998-04-16 00:26:21 +00:00
|
|
|
{"accept", NULL, NegotiateCommand, LOCAL_AUTH | LOCAL_CX_OPT,
|
1998-01-29 00:44:16 +00:00
|
|
|
"accept option request", "accept option .."},
|
|
|
|
{"add", NULL, AddCommand, LOCAL_AUTH,
|
|
|
|
"add route", "add dest mask gateway", NULL},
|
1998-04-03 19:24:31 +00:00
|
|
|
{NULL, "add!", AddCommand, LOCAL_AUTH,
|
1998-01-29 00:44:16 +00:00
|
|
|
"add or change route", "add! dest mask gateway", (void *)1},
|
1998-04-03 19:24:31 +00:00
|
|
|
#ifndef NOALIAS
|
|
|
|
{"alias", NULL, AliasCommand, LOCAL_AUTH,
|
|
|
|
"alias control", "alias option [yes|no]"},
|
|
|
|
#endif
|
1998-01-29 00:44:16 +00:00
|
|
|
{"allow", "auth", AllowCommand, LOCAL_AUTH,
|
|
|
|
"Allow ppp access", "allow users|modes ...."},
|
|
|
|
{"bg", "!bg", BgShellCommand, LOCAL_AUTH,
|
|
|
|
"Run a background command", "[!]bg command"},
|
1998-04-05 22:48:25 +00:00
|
|
|
{"clone", NULL, CloneCommand, LOCAL_AUTH | LOCAL_CX,
|
|
|
|
"Clone a link", "clone newname..."},
|
1998-02-17 19:28:35 +00:00
|
|
|
{"close", NULL, CloseCommand, LOCAL_AUTH | LOCAL_CX_OPT,
|
1998-04-19 02:23:21 +00:00
|
|
|
"Close an FSM", "close [lcp|ccp]"},
|
1998-01-29 00:44:16 +00:00
|
|
|
{"delete", NULL, DeleteCommand, LOCAL_AUTH,
|
|
|
|
"delete route", "delete dest", NULL},
|
1998-04-03 19:24:31 +00:00
|
|
|
{NULL, "delete!", DeleteCommand, LOCAL_AUTH,
|
1998-01-29 00:44:16 +00:00
|
|
|
"delete a route if it exists", "delete! dest", (void *)1},
|
1998-04-16 00:26:21 +00:00
|
|
|
{"deny", NULL, NegotiateCommand, LOCAL_AUTH | LOCAL_CX_OPT,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Deny option request", "deny option .."},
|
1998-03-13 00:44:51 +00:00
|
|
|
{"dial", "call", DialCommand, LOCAL_AUTH | LOCAL_CX_OPT,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Dial and login", "dial|call [remote]"},
|
1998-04-16 00:26:21 +00:00
|
|
|
{"disable", NULL, NegotiateCommand, LOCAL_AUTH | LOCAL_CX_OPT,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Disable option", "disable option .."},
|
1998-04-03 19:24:31 +00:00
|
|
|
{"down", NULL, DownCommand, LOCAL_AUTH | LOCAL_CX,
|
|
|
|
"Generate a down event", "down"},
|
1998-04-16 00:26:21 +00:00
|
|
|
{"enable", NULL, NegotiateCommand, LOCAL_AUTH | LOCAL_CX_OPT,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Enable option", "enable option .."},
|
1998-04-10 13:19:23 +00:00
|
|
|
{"link", "datalink", LinkCommand, LOCAL_AUTH,
|
1998-02-17 19:28:01 +00:00
|
|
|
"Link specific commands", "link name command ..."},
|
1998-01-29 00:44:16 +00:00
|
|
|
{"load", NULL, LoadCommand, LOCAL_AUTH,
|
|
|
|
"Load settings", "load [remote]"},
|
1998-04-19 02:23:21 +00:00
|
|
|
{"open", NULL, OpenCommand, LOCAL_AUTH | LOCAL_CX_OPT,
|
|
|
|
"Open an FSM", "open [lcp|ccp]"},
|
1998-04-03 19:26:02 +00:00
|
|
|
{"passwd", NULL, PasswdCommand, LOCAL_NO_AUTH,
|
1998-04-03 19:24:31 +00:00
|
|
|
"Password for manipulation", "passwd LocalPassword"},
|
|
|
|
{"quit", "bye", QuitCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
|
|
|
|
"Quit PPP program", "quit|bye [all]"},
|
1998-04-30 23:53:56 +00:00
|
|
|
{"remove", "rm", RemoveCommand, LOCAL_AUTH | LOCAL_CX,
|
1998-04-05 22:48:25 +00:00
|
|
|
"Remove a link", "remove"},
|
1998-01-29 00:44:16 +00:00
|
|
|
{"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]"},
|
1998-04-24 19:15:48 +00:00
|
|
|
{"show", NULL, ShowCommand, LOCAL_AUTH | LOCAL_CX_OPT,
|
1998-01-29 00:44:16 +00:00
|
|
|
"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"},
|
|
|
|
{"help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
|
|
|
|
"Display this message", "help|? [command]", Commands},
|
|
|
|
{NULL, NULL, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
1998-04-18 01:01:28 +00:00
|
|
|
const 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)) {
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, "%s0x%02x", sep, (code << 3) + bit);
|
1998-02-18 19:35:20 +00:00
|
|
|
sep = ", ";
|
|
|
|
}
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, "\n");
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-04-03 19:21:56 +00:00
|
|
|
static int
|
|
|
|
ShowTimerList(struct cmdargs const *arg)
|
|
|
|
{
|
1998-05-01 19:26:12 +00:00
|
|
|
timer_Show(0, arg->prompt);
|
1998-04-03 19:21:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
static int
|
|
|
|
ShowStopped(struct cmdargs const *arg)
|
|
|
|
{
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, " Stopped Timer: LCP: ");
|
1998-04-03 19:21:56 +00:00
|
|
|
if (!arg->cx->physical->link.lcp.fsm.StoppedTimer.load)
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, "Disabled");
|
1998-01-29 00:44:16 +00:00
|
|
|
else
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, "%ld secs",
|
1998-04-03 19:21:56 +00:00
|
|
|
arg->cx->physical->link.lcp.fsm.StoppedTimer.load / SECTICKS);
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, ", CCP: ");
|
1998-04-03 19:21:56 +00:00
|
|
|
if (!arg->cx->physical->link.ccp.fsm.StoppedTimer.load)
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, "Disabled");
|
1998-01-29 00:44:16 +00:00
|
|
|
else
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, "%ld secs",
|
1998-04-03 19:21:56 +00:00
|
|
|
arg->cx->physical->link.ccp.fsm.StoppedTimer.load / SECTICKS);
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, "\n");
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ShowVersion(struct cmdargs const *arg)
|
|
|
|
{
|
1998-04-30 23:53:56 +00:00
|
|
|
prompt_Printf(arg->prompt, "PPP Version %s - %s\n", Version, VersionDate);
|
1998-01-29 00:44:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-04-18 01:01:28 +00:00
|
|
|
static int
|
1998-04-03 19:21:56 +00:00
|
|
|
ShowProtocolStats(struct cmdargs const *arg)
|
|
|
|
{
|
1998-05-01 19:26:12 +00:00
|
|
|
struct link *l = command_ChooseLink(arg);
|
1998-04-03 19:24:07 +00:00
|
|
|
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, "%s:\n", l->name);
|
|
|
|
link_ReportProtocolStatus(l, arg->prompt);
|
1998-04-03 19:21:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
static struct cmdtab const ShowCommands[] = {
|
1998-04-11 21:50:47 +00:00
|
|
|
{"bundle", NULL, bundle_ShowStatus, LOCAL_AUTH,
|
|
|
|
"Show bundle details", "show bundle"},
|
1998-02-21 01:45:26 +00:00
|
|
|
{"ccp", NULL, ccp_ReportStatus, LOCAL_AUTH | LOCAL_CX_OPT,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Show CCP status", "show cpp"},
|
1998-05-01 19:26:12 +00:00
|
|
|
{"compress", NULL, sl_Show, LOCAL_AUTH,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Show compression stats", "show compress"},
|
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"},
|
1998-05-01 19:26:12 +00:00
|
|
|
{"filter", NULL, filter_Show, LOCAL_AUTH,
|
1998-03-16 22:52:54 +00:00
|
|
|
"Show packet filters", "show filter [in|out|dial|alive]"},
|
1998-04-03 19:24:31 +00:00
|
|
|
{"hdlc", NULL, hdlc_ReportStatus, LOCAL_AUTH | LOCAL_CX,
|
|
|
|
"Show HDLC errors", "show hdlc"},
|
1998-05-01 19:26:12 +00:00
|
|
|
{"ipcp", NULL, ipcp_Show, LOCAL_AUTH,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Show IPCP status", "show ipcp"},
|
1998-04-24 19:16:15 +00:00
|
|
|
{"lcp", NULL, lcp_ReportStatus, LOCAL_AUTH | LOCAL_CX,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Show LCP status", "show lcp"},
|
1998-04-24 19:16:15 +00:00
|
|
|
{"link", "datalink", datalink_Show, LOCAL_AUTH | LOCAL_CX,
|
|
|
|
"Show (high-level) link info", "show link"},
|
|
|
|
{"links", NULL, bundle_ShowLinks, LOCAL_AUTH,
|
1998-02-17 19:28:01 +00:00
|
|
|
"Show available link names", "show links"},
|
1998-04-03 19:26:02 +00:00
|
|
|
{"log", NULL, log_ShowLevel, LOCAL_AUTH,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Show log levels", "show log"},
|
1998-05-01 19:26:12 +00:00
|
|
|
{"mem", NULL, mbuf_Show, LOCAL_AUTH,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Show memory map", "show mem"},
|
1998-02-17 19:28:01 +00:00
|
|
|
{"modem", NULL, modem_ShowStatus, LOCAL_AUTH | LOCAL_CX,
|
1998-04-24 19:16:15 +00:00
|
|
|
"Show (low-level) link info", "show modem"},
|
1998-04-23 03:23:03 +00:00
|
|
|
{"mp", "multilink", mp_ShowStatus, LOCAL_AUTH,
|
|
|
|
"Show multilink setup", "show mp"},
|
1998-04-03 19:21:56 +00:00
|
|
|
{"proto", NULL, ShowProtocolStats, LOCAL_AUTH | LOCAL_CX_OPT,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Show protocol summary", "show proto"},
|
1998-05-01 19:26:12 +00:00
|
|
|
{"route", NULL, route_Show, LOCAL_AUTH,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Show routing table", "show route"},
|
1998-04-03 19:24:31 +00:00
|
|
|
{"stopped", NULL, ShowStopped, LOCAL_AUTH | LOCAL_CX,
|
|
|
|
"Show STOPPED timeout", "show stopped"},
|
1998-04-03 19:21:56 +00:00
|
|
|
{"timers", NULL, ShowTimerList, LOCAL_AUTH,
|
|
|
|
"Show alarm timers", "show timers"},
|
1998-01-29 00:44:16 +00:00
|
|
|
{"version", NULL, ShowVersion, LOCAL_NO_AUTH | LOCAL_AUTH,
|
|
|
|
"Show version string", "show version"},
|
1998-04-03 19:26:02 +00:00
|
|
|
{"who", NULL, log_ShowWho, LOCAL_AUTH,
|
|
|
|
"Show client list", "show who"},
|
1998-01-29 00:44:16 +00:00
|
|
|
{"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;
|
|
|
|
}
|
|
|
|
|
1998-04-14 23:17:24 +00:00
|
|
|
static const char *
|
|
|
|
mkPrefix(int argc, char const *const *argv, char *tgt, int sz)
|
|
|
|
{
|
|
|
|
int f, tlen, len;
|
|
|
|
|
|
|
|
tlen = 0;
|
|
|
|
for (f = 0; f < argc && tlen < sz - 2; f++) {
|
|
|
|
if (f)
|
|
|
|
tgt[tlen++] = ' ';
|
|
|
|
len = strlen(argv[f]);
|
|
|
|
if (len > sz - tlen - 1)
|
|
|
|
len = sz - tlen - 1;
|
|
|
|
strncpy(tgt+tlen, argv[f], len);
|
|
|
|
tlen += len;
|
|
|
|
}
|
|
|
|
tgt[tlen] = '\0';
|
|
|
|
return tgt;
|
|
|
|
}
|
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
static int
|
1998-04-14 23:17:24 +00:00
|
|
|
FindExec(struct bundle *bundle, struct cmdtab const *cmds, int argc, int argn,
|
|
|
|
char const *const *argv, struct prompt *prompt, struct datalink *cx)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
|
|
|
struct cmdtab const *cmd;
|
|
|
|
int val = 1;
|
|
|
|
int nmatch;
|
|
|
|
struct cmdargs arg;
|
1998-04-14 23:17:24 +00:00
|
|
|
char prefix[100];
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-04-14 23:17:24 +00:00
|
|
|
cmd = FindCommand(cmds, argv[argn], &nmatch);
|
1998-01-29 00:44:16 +00:00
|
|
|
if (nmatch > 1)
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "%s: Ambiguous command\n",
|
1998-04-14 23:17:24 +00:00
|
|
|
mkPrefix(argn+1, argv, prefix, sizeof prefix));
|
1998-04-03 19:26:02 +00:00
|
|
|
else if (cmd && (!prompt || (cmd->lauth & prompt->auth))) {
|
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)
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "%s: No context (use the `link' command)\n",
|
1998-04-14 23:17:24 +00:00
|
|
|
mkPrefix(argn+1, argv, prefix, sizeof prefix));
|
1998-02-17 19:28:01 +00:00
|
|
|
else {
|
|
|
|
if (cx && !(cmd->lauth & (LOCAL_CX|LOCAL_CX_OPT))) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "%s: Redundant context (%s) ignored\n",
|
1998-04-14 23:17:24 +00:00
|
|
|
mkPrefix(argn+1, argv, prefix, sizeof prefix), cx->name);
|
1998-02-17 19:28:01 +00:00
|
|
|
cx = NULL;
|
|
|
|
}
|
|
|
|
arg.cmdtab = cmds;
|
|
|
|
arg.cmd = cmd;
|
1998-04-14 23:17:24 +00:00
|
|
|
arg.argc = argc;
|
|
|
|
arg.argn = argn+1;
|
|
|
|
arg.argv = argv;
|
1998-02-17 19:28:01 +00:00
|
|
|
arg.bundle = bundle;
|
|
|
|
arg.cx = cx;
|
1998-04-03 19:26:02 +00:00
|
|
|
arg.prompt = prompt;
|
1998-04-14 23:17:24 +00:00
|
|
|
val = (*cmd->func) (&arg);
|
1998-02-17 19:28:01 +00:00
|
|
|
}
|
1998-01-29 00:44:16 +00:00
|
|
|
} else
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "%s: Invalid command\n",
|
1998-04-14 23:17:24 +00:00
|
|
|
mkPrefix(argn+1, argv, prefix, sizeof prefix));
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
if (val == -1)
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "Usage: %s\n", cmd->syntax);
|
1998-01-29 00:44:16 +00:00
|
|
|
else if (val)
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "%s: Failed %d\n",
|
1998-04-14 23:17:24 +00:00
|
|
|
mkPrefix(argn+1, argv, prefix, sizeof prefix), val);
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-05-01 19:26:12 +00:00
|
|
|
command_Interpret(char *buff, int nb, int *argc, char ***argv)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
|
|
|
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-05-01 19:26:12 +00:00
|
|
|
command_Run(struct bundle *bundle, int argc, char const *const *argv,
|
1998-04-03 19:26:02 +00:00
|
|
|
struct prompt *prompt, const char *label)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
|
|
|
if (argc > 0) {
|
1998-05-01 19:26:12 +00:00
|
|
|
if (log_IsKept(LogCOMMAND)) {
|
1998-01-29 00:44:16 +00:00
|
|
|
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))
|
1998-04-11 21:50:47 +00:00
|
|
|
strncpy(buf+n, "********", sizeof buf - n - 1);
|
1998-01-29 00:44:16 +00:00
|
|
|
else
|
|
|
|
strncpy(buf+n, argv[f], sizeof buf - n - 1);
|
|
|
|
n += strlen(buf+n);
|
|
|
|
}
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogCOMMAND, "%s\n", buf);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
1998-04-14 23:17:24 +00:00
|
|
|
FindExec(bundle, Commands, argc, 0, argv, prompt, NULL);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-05-01 19:26:12 +00:00
|
|
|
command_Decode(struct bundle *bundle, char *buff, int nb, struct prompt *prompt,
|
1998-04-03 19:26:02 +00:00
|
|
|
const char *label)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
|
1998-05-01 19:26:12 +00:00
|
|
|
command_Interpret(buff, nb, &argc, &argv);
|
|
|
|
command_Run(bundle, argc, (char const *const *)argv, prompt, label);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ShowCommand(struct cmdargs const *arg)
|
|
|
|
{
|
1998-04-03 19:26:02 +00:00
|
|
|
if (!arg->prompt)
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "show: Cannot show without a prompt\n");
|
1998-04-14 23:17:24 +00:00
|
|
|
else if (arg->argc > arg->argn)
|
|
|
|
FindExec(arg->bundle, ShowCommands, arg->argc, arg->argn, arg->argv,
|
1998-04-03 19:26:02 +00:00
|
|
|
arg->prompt, arg->cx);
|
1998-01-29 00:44:16 +00:00
|
|
|
else
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, "Use ``show ?'' to get a list.\n");
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
TerminalCommand(struct cmdargs const *arg)
|
|
|
|
{
|
1998-04-03 19:26:02 +00:00
|
|
|
if (!arg->prompt) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "term: Need a prompt\n");
|
1998-04-03 19:26:02 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1998-04-03 19:21:56 +00:00
|
|
|
if (arg->cx->physical->link.lcp.fsm.state > ST_CLOSED) {
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, "LCP state is [%s]\n",
|
1998-04-03 19:21:56 +00:00
|
|
|
State2Nam(arg->cx->physical->link.lcp.fsm.state));
|
1998-01-29 00:44:16 +00:00
|
|
|
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-04-03 19:26:02 +00:00
|
|
|
prompt_TtyTermMode(arg->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-04-03 19:26:02 +00:00
|
|
|
if (!arg->prompt || prompt_IsController(arg->prompt) ||
|
1998-04-14 23:17:24 +00:00
|
|
|
(arg->argc > arg->argn && !strcasecmp(arg->argv[arg->argn], "all") &&
|
1998-04-03 19:26:02 +00:00
|
|
|
(arg->prompt->auth & LOCAL_AUTH)))
|
|
|
|
Cleanup(EX_NORMAL);
|
|
|
|
if (arg->prompt)
|
|
|
|
prompt_Destroy(arg->prompt, 1);
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-04-19 02:23:21 +00:00
|
|
|
static int
|
|
|
|
OpenCommand(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
if (arg->argc == arg->argn ||
|
|
|
|
(arg->argc == arg->argn+1 && !strcasecmp(arg->argv[arg->argn], "lcp")))
|
|
|
|
bundle_Open(arg->bundle, arg->cx ? arg->cx->name : NULL, PHYS_ALL);
|
|
|
|
else if (arg->argc == arg->argn+1 &&
|
|
|
|
!strcasecmp(arg->argv[arg->argn], "ccp")) {
|
1998-05-01 19:26:12 +00:00
|
|
|
struct fsm *fp = &command_ChooseLink(arg)->ccp.fsm;
|
1998-04-19 02:23:21 +00:00
|
|
|
|
1998-04-27 01:40:38 +00:00
|
|
|
if (fp->link->lcp.fsm.state != ST_OPENED)
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "open: LCP must be open before opening CCP\n");
|
1998-04-27 01:40:38 +00:00
|
|
|
else if (fp->state != ST_OPENED) {
|
1998-05-01 19:26:12 +00:00
|
|
|
fsm_Up(fp);
|
|
|
|
fsm_Open(fp);
|
1998-04-19 02:23:21 +00:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
static int
|
|
|
|
CloseCommand(struct cmdargs const *arg)
|
|
|
|
{
|
1998-04-19 02:23:21 +00:00
|
|
|
if (arg->argc == arg->argn ||
|
|
|
|
(arg->argc == arg->argn+1 && !strcasecmp(arg->argv[arg->argn], "lcp")))
|
|
|
|
bundle_Close(arg->bundle, arg->cx ? arg->cx->name : NULL, 1);
|
|
|
|
else if (arg->argc == arg->argn+1 &&
|
|
|
|
!strcasecmp(arg->argv[arg->argn], "ccp")) {
|
1998-05-01 19:26:12 +00:00
|
|
|
struct fsm *fp = &command_ChooseLink(arg)->ccp.fsm;
|
1998-04-19 02:23:21 +00:00
|
|
|
|
|
|
|
if (fp->state == ST_OPENED)
|
1998-05-01 19:26:12 +00:00
|
|
|
fsm_Close(fp);
|
1998-04-19 02:23:21 +00:00
|
|
|
} else
|
|
|
|
return -1;
|
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
DownCommand(struct cmdargs const *arg)
|
|
|
|
{
|
1998-04-03 19:21:56 +00:00
|
|
|
datalink_Down(arg->cx, 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-04-14 23:17:24 +00:00
|
|
|
if (arg->argc > arg->argn && *arg->argv[arg->argn]) {
|
|
|
|
if (arg->argc > arg->argn+1) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "SetModemSpeed: Too many arguments");
|
1998-02-06 02:22:28 +00:00
|
|
|
return -1;
|
|
|
|
}
|
1998-04-14 23:17:24 +00:00
|
|
|
if (strcasecmp(arg->argv[arg->argn], "sync") == 0) {
|
1998-05-01 19:26:12 +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-04-14 23:17:24 +00:00
|
|
|
speed = strtol(arg->argv[arg->argn], &end, 10);
|
1998-02-06 02:22:28 +00:00
|
|
|
if (*end) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "SetModemSpeed: Bad argument \"%s\"",
|
1998-04-14 23:17:24 +00:00
|
|
|
arg->argv[arg->argn]);
|
1998-02-06 02:22:28 +00:00
|
|
|
return -1;
|
|
|
|
}
|
1998-05-01 19:26:12 +00:00
|
|
|
if (physical_SetSpeed(arg->cx->physical, speed))
|
1998-02-06 02:22:28 +00:00
|
|
|
return 0;
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "%s: Invalid speed\n", arg->argv[arg->argn]);
|
1998-02-06 02:22:28 +00:00
|
|
|
} else
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(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
|
|
|
|
SetStoppedTimeout(struct cmdargs const *arg)
|
|
|
|
{
|
1998-04-03 19:21:56 +00:00
|
|
|
struct link *l = &arg->cx->physical->link;
|
|
|
|
|
|
|
|
l->lcp.fsm.StoppedTimer.load = 0;
|
|
|
|
l->ccp.fsm.StoppedTimer.load = 0;
|
1998-04-14 23:17:24 +00:00
|
|
|
if (arg->argc <= arg->argn+2) {
|
|
|
|
if (arg->argc > arg->argn) {
|
|
|
|
l->lcp.fsm.StoppedTimer.load = atoi(arg->argv[arg->argn]) * SECTICKS;
|
|
|
|
if (arg->argc > arg->argn+1)
|
|
|
|
l->ccp.fsm.StoppedTimer.load = atoi(arg->argv[arg->argn+1]) * 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;
|
|
|
|
|
1998-04-14 23:17:24 +00:00
|
|
|
if (arg->argc > arg->argn && arg->argc < arg->argn+4) {
|
1998-01-29 00:44:16 +00:00
|
|
|
const char *port, *passwd, *mask;
|
|
|
|
|
|
|
|
/* What's what ? */
|
1998-04-14 23:17:24 +00:00
|
|
|
port = arg->argv[arg->argn];
|
|
|
|
if (arg->argc == arg->argn + 2) {
|
|
|
|
passwd = arg->argv[arg->argn+1];
|
1998-04-03 19:26:02 +00:00
|
|
|
mask = NULL;
|
1998-04-14 23:17:24 +00:00
|
|
|
} else if (arg->argc == arg->argn + 3) {
|
|
|
|
passwd = arg->argv[arg->argn+1];
|
|
|
|
mask = arg->argv[arg->argn+2];
|
1998-01-29 00:44:16 +00:00
|
|
|
if (!ismask(mask))
|
|
|
|
return -1;
|
1998-04-03 19:26:02 +00:00
|
|
|
} else if (strcasecmp(port, "none") == 0) {
|
1998-05-01 19:26:12 +00:00
|
|
|
if (server_Close(arg->bundle))
|
|
|
|
log_Printf(LogPHASE, "Disabled server port.\n");
|
1998-04-03 19:26:02 +00:00
|
|
|
return 0;
|
|
|
|
} else
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
strncpy(server.passwd, passwd, sizeof server.passwd - 1);
|
|
|
|
server.passwd[sizeof server.passwd - 1] = '\0';
|
|
|
|
|
|
|
|
if (*port == '/') {
|
1998-01-29 00:44:16 +00:00
|
|
|
mode_t imask;
|
|
|
|
|
|
|
|
if (mask != NULL) {
|
|
|
|
unsigned m;
|
|
|
|
|
|
|
|
if (sscanf(mask, "%o", &m) == 1)
|
|
|
|
imask = m;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
} else
|
|
|
|
imask = (mode_t)-1;
|
1998-05-01 19:26:12 +00:00
|
|
|
res = server_LocalOpen(arg->bundle, port, imask);
|
1998-01-29 00:44:16 +00:00
|
|
|
} 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;
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "%s: Invalid port or service\n", port);
|
1998-01-29 00:44:16 +00:00
|
|
|
} else
|
|
|
|
iport = ntohs(s->s_port);
|
|
|
|
} else
|
|
|
|
iport = atoi(port);
|
1998-05-01 19:26:12 +00:00
|
|
|
res = iport ? server_TcpOpen(arg->bundle, iport) : -1;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetModemParity(struct cmdargs const *arg)
|
|
|
|
{
|
1998-04-14 23:17:24 +00:00
|
|
|
return arg->argc > arg->argn ? modem_SetParity(arg->cx->physical,
|
|
|
|
arg->argv[arg->argn]) : -1;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetEscape(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
int code;
|
1998-04-14 23:17:24 +00:00
|
|
|
int argc = arg->argc - arg->argn;
|
|
|
|
char const *const *argv = arg->argv + arg->argn;
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
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 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)
|
|
|
|
{
|
1998-03-13 21:07:46 +00:00
|
|
|
struct ipcp *ipcp = &arg->bundle->ncp.ipcp;
|
1998-01-29 00:44:16 +00:00
|
|
|
const char *hisaddr;
|
|
|
|
|
|
|
|
hisaddr = NULL;
|
1998-03-13 21:07:46 +00:00
|
|
|
ipcp->cfg.my_range.ipaddr.s_addr = INADDR_ANY;
|
|
|
|
ipcp->cfg.peer_range.ipaddr.s_addr = INADDR_ANY;
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-04-14 23:17:24 +00:00
|
|
|
if (arg->argc > arg->argn + 4)
|
1998-01-29 00:44:16 +00:00
|
|
|
return -1;
|
|
|
|
|
1998-03-13 21:07:46 +00:00
|
|
|
ipcp->cfg.HaveTriggerAddress = 0;
|
1998-03-13 21:08:05 +00:00
|
|
|
ipcp->cfg.netmask.s_addr = INADDR_ANY;
|
1998-03-13 21:07:46 +00:00
|
|
|
iplist_reset(&ipcp->cfg.peer_list);
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-04-14 23:17:24 +00:00
|
|
|
if (arg->argc > arg->argn) {
|
|
|
|
if (!ParseAddr(ipcp, arg->argc - arg->argn, arg->argv + arg->argn,
|
|
|
|
&ipcp->cfg.my_range.ipaddr, &ipcp->cfg.my_range.mask,
|
|
|
|
&ipcp->cfg.my_range.width))
|
1998-01-29 00:44:16 +00:00
|
|
|
return 1;
|
1998-04-14 23:17:24 +00:00
|
|
|
if (arg->argc > arg->argn+1) {
|
|
|
|
hisaddr = arg->argv[arg->argn+1];
|
|
|
|
if (arg->argc > arg->argn+2) {
|
|
|
|
ipcp->cfg.netmask = GetIpAddr(arg->argv[arg->argn+2]);
|
|
|
|
if (arg->argc > arg->argn+3) {
|
|
|
|
ipcp->cfg.TriggerAddress = GetIpAddr(arg->argv[arg->argn+3]);
|
1998-03-13 21:07:46 +00:00
|
|
|
ipcp->cfg.HaveTriggerAddress = 1;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For backwards compatibility, 0.0.0.0 means any address.
|
|
|
|
*/
|
1998-03-13 21:07:46 +00:00
|
|
|
if (ipcp->cfg.my_range.ipaddr.s_addr == INADDR_ANY) {
|
|
|
|
ipcp->cfg.my_range.mask.s_addr = INADDR_ANY;
|
|
|
|
ipcp->cfg.my_range.width = 0;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
1998-03-13 21:07:46 +00:00
|
|
|
ipcp->my_ip.s_addr = ipcp->cfg.my_range.ipaddr.s_addr;
|
1998-01-29 23:11:44 +00:00
|
|
|
|
1998-03-13 21:07:46 +00:00
|
|
|
if (ipcp->cfg.peer_range.ipaddr.s_addr == INADDR_ANY) {
|
|
|
|
ipcp->cfg.peer_range.mask.s_addr = INADDR_ANY;
|
|
|
|
ipcp->cfg.peer_range.width = 0;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
1998-04-10 13:19:23 +00:00
|
|
|
if (hisaddr &&
|
1998-05-01 19:26:12 +00:00
|
|
|
!ipcp_UseHisaddr(arg->bundle, hisaddr, arg->bundle->phys_type & PHYS_DEMAND))
|
1998-01-29 00:44:16 +00:00
|
|
|
return 4;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-02-17 19:28:01 +00:00
|
|
|
static int
|
1998-01-29 00:44:16 +00:00
|
|
|
SetVariable(struct cmdargs const *arg)
|
|
|
|
{
|
1998-04-03 19:24:07 +00:00
|
|
|
u_long ulong_val;
|
1998-01-29 00:44:16 +00:00
|
|
|
const char *argp;
|
1998-02-17 19:28:01 +00:00
|
|
|
int param = (int)arg->cmd->args;
|
1998-04-03 19:24:07 +00:00
|
|
|
struct datalink *cx = arg->cx; /* AUTH_CX uses this */
|
|
|
|
const char *err = NULL;
|
1998-05-01 19:26:12 +00:00
|
|
|
struct link *l = command_ChooseLink(arg); /* AUTH_CX_OPT uses this */
|
1998-04-17 22:05:37 +00:00
|
|
|
int dummyint;
|
|
|
|
struct in_addr dummyaddr, *addr;
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-04-14 23:17:24 +00:00
|
|
|
if (arg->argc > arg->argn)
|
|
|
|
argp = arg->argv[arg->argn];
|
1998-01-29 00:44:16 +00:00
|
|
|
else
|
|
|
|
argp = "";
|
|
|
|
|
1998-02-17 19:28:01 +00:00
|
|
|
if ((arg->cmd->lauth & LOCAL_CX) && !cx) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "set %s: No context (use the `link' command)\n",
|
1998-02-17 19:28:01 +00:00
|
|
|
arg->cmd->name);
|
|
|
|
return 1;
|
|
|
|
} else if (cx && !(arg->cmd->lauth & (LOCAL_CX|LOCAL_CX_OPT))) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "set %s: Redundant context (%s) ignored\n",
|
1998-02-17 19:28:01 +00:00
|
|
|
arg->cmd->name, cx->name);
|
|
|
|
cx = NULL;
|
|
|
|
}
|
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
switch (param) {
|
|
|
|
case VAR_AUTHKEY:
|
1998-04-03 19:24:49 +00:00
|
|
|
if (bundle_Phase(arg->bundle) == PHASE_DEAD) {
|
|
|
|
strncpy(arg->bundle->cfg.auth.key, argp,
|
|
|
|
sizeof arg->bundle->cfg.auth.key - 1);
|
|
|
|
arg->bundle->cfg.auth.key[sizeof arg->bundle->cfg.auth.key - 1] = '\0';
|
|
|
|
} else {
|
|
|
|
err = "set authkey: Only available at phase DEAD\n";
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, err);
|
1998-04-03 19:24:49 +00:00
|
|
|
}
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
case VAR_AUTHNAME:
|
1998-04-03 19:24:49 +00:00
|
|
|
if (bundle_Phase(arg->bundle) == PHASE_DEAD) {
|
|
|
|
strncpy(arg->bundle->cfg.auth.name, argp,
|
|
|
|
sizeof arg->bundle->cfg.auth.name - 1);
|
|
|
|
arg->bundle->cfg.auth.name[sizeof arg->bundle->cfg.auth.name - 1] = '\0';
|
|
|
|
} else {
|
|
|
|
err = "set authname: Only available at phase DEAD\n";
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, err);
|
1998-04-03 19:24:49 +00:00
|
|
|
}
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
case VAR_DIAL:
|
1998-04-10 13:19:23 +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-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
case VAR_LOGIN:
|
1998-04-10 13:19:23 +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-01-29 00:44:16 +00:00
|
|
|
break;
|
1998-03-17 22:29:12 +00:00
|
|
|
case VAR_WINSIZE:
|
1998-04-14 23:17:24 +00:00
|
|
|
if (arg->argc > arg->argn) {
|
|
|
|
l->ccp.cfg.deflate.out.winsize = atoi(arg->argv[arg->argn]);
|
1998-04-03 19:21:56 +00:00
|
|
|
if (l->ccp.cfg.deflate.out.winsize < 8 ||
|
|
|
|
l->ccp.cfg.deflate.out.winsize > 15) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "%d: Invalid outgoing window size\n",
|
1998-04-03 19:21:56 +00:00
|
|
|
l->ccp.cfg.deflate.out.winsize);
|
|
|
|
l->ccp.cfg.deflate.out.winsize = 15;
|
1998-03-17 22:29:12 +00:00
|
|
|
}
|
1998-04-14 23:17:24 +00:00
|
|
|
if (arg->argc > arg->argn+1) {
|
|
|
|
l->ccp.cfg.deflate.in.winsize = atoi(arg->argv[arg->argn+1]);
|
1998-04-03 19:21:56 +00:00
|
|
|
if (l->ccp.cfg.deflate.in.winsize < 8 ||
|
|
|
|
l->ccp.cfg.deflate.in.winsize > 15) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "%d: Invalid incoming window size\n",
|
1998-04-03 19:21:56 +00:00
|
|
|
l->ccp.cfg.deflate.in.winsize);
|
|
|
|
l->ccp.cfg.deflate.in.winsize = 15;
|
1998-03-17 22:29:12 +00:00
|
|
|
}
|
|
|
|
} else
|
1998-04-03 19:21:56 +00:00
|
|
|
l->ccp.cfg.deflate.in.winsize = 0;
|
1998-04-03 19:24:07 +00:00
|
|
|
} else {
|
|
|
|
err = "No window size specified\n";
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, err);
|
1998-03-17 22:29:12 +00:00
|
|
|
}
|
|
|
|
break;
|
1998-01-29 00:44:16 +00:00
|
|
|
case VAR_DEVICE:
|
1998-05-01 19:26:12 +00:00
|
|
|
physical_SetDeviceList(cx->physical, arg->argc - arg->argn,
|
1998-04-14 23:17:24 +00:00
|
|
|
arg->argv + arg->argn);
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
case VAR_ACCMAP:
|
1998-04-14 23:17:24 +00:00
|
|
|
if (arg->argc > arg->argn) {
|
1998-04-03 19:24:07 +00:00
|
|
|
sscanf(argp, "%lx", &ulong_val);
|
|
|
|
cx->physical->link.lcp.cfg.accmap = ulong_val;
|
|
|
|
} else {
|
|
|
|
err = "No accmap specified\n";
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, err);
|
1998-04-03 19:24:07 +00:00
|
|
|
}
|
|
|
|
break;
|
1998-04-23 03:23:03 +00:00
|
|
|
case VAR_MRRU:
|
|
|
|
if (bundle_Phase(arg->bundle) != PHASE_DEAD)
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "mrru: Only changable at phase DEAD\n");
|
1998-04-23 03:23:03 +00:00
|
|
|
else {
|
|
|
|
ulong_val = atol(argp);
|
|
|
|
if (ulong_val < MIN_MRU)
|
|
|
|
err = "Given MRRU value (%lu) is too small.\n";
|
|
|
|
else if (ulong_val > MAX_MRU)
|
|
|
|
err = "Given MRRU value (%lu) is too big.\n";
|
|
|
|
else
|
|
|
|
arg->bundle->ncp.mp.cfg.mrru = ulong_val;
|
|
|
|
if (err)
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, err, ulong_val);
|
1998-04-23 03:23:03 +00:00
|
|
|
}
|
|
|
|
break;
|
1998-04-03 19:24:07 +00:00
|
|
|
case VAR_MRU:
|
|
|
|
ulong_val = atol(argp);
|
|
|
|
if (ulong_val < MIN_MRU)
|
|
|
|
err = "Given MRU value (%lu) is too small.\n";
|
|
|
|
else if (ulong_val > MAX_MRU)
|
|
|
|
err = "Given MRU value (%lu) is too big.\n";
|
|
|
|
else
|
|
|
|
l->lcp.cfg.mru = ulong_val;
|
|
|
|
if (err)
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, err, ulong_val);
|
1998-04-03 19:24:07 +00:00
|
|
|
break;
|
|
|
|
case VAR_MTU:
|
|
|
|
ulong_val = atol(argp);
|
|
|
|
if (ulong_val == 0)
|
1998-04-23 03:23:03 +00:00
|
|
|
arg->bundle->cfg.mtu = 0;
|
1998-04-03 19:24:07 +00:00
|
|
|
else if (ulong_val < MIN_MTU)
|
|
|
|
err = "Given MTU value (%lu) is too small.\n";
|
|
|
|
else if (ulong_val > MAX_MTU)
|
|
|
|
err = "Given MTU value (%lu) is too big.\n";
|
|
|
|
else
|
1998-04-23 03:23:03 +00:00
|
|
|
arg->bundle->cfg.mtu = ulong_val;
|
1998-04-03 19:24:07 +00:00
|
|
|
if (err)
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, err, ulong_val);
|
1998-04-03 19:24:07 +00:00
|
|
|
break;
|
|
|
|
case VAR_OPENMODE:
|
|
|
|
if (strcasecmp(argp, "active") == 0)
|
1998-04-14 23:17:24 +00:00
|
|
|
cx->physical->link.lcp.cfg.openmode = arg->argc > arg->argn+1 ?
|
|
|
|
atoi(arg->argv[arg->argn+1]) : 1;
|
1998-04-03 19:24:07 +00:00
|
|
|
else if (strcasecmp(argp, "passive") == 0)
|
|
|
|
cx->physical->link.lcp.cfg.openmode = OPEN_PASSIVE;
|
|
|
|
else {
|
|
|
|
err = "%s: Invalid openmode\n";
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, err, argp);
|
1998-04-03 19:24:07 +00:00
|
|
|
}
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
case VAR_PHONE:
|
1998-03-09 19:24:58 +00:00
|
|
|
strncpy(cx->cfg.phone.list, argp, sizeof cx->cfg.phone.list - 1);
|
|
|
|
cx->cfg.phone.list[sizeof cx->cfg.phone.list - 1] = '\0';
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
case VAR_HANGUP:
|
1998-04-10 13:19:23 +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-01-29 00:44:16 +00:00
|
|
|
break;
|
1998-04-03 19:24:07 +00:00
|
|
|
case VAR_IDLETIMEOUT:
|
1998-04-14 23:17:24 +00:00
|
|
|
if (arg->argc > arg->argn+1)
|
1998-04-03 19:25:07 +00:00
|
|
|
err = "Too many idle timeout values\n";
|
1998-04-14 23:17:24 +00:00
|
|
|
else if (arg->argc == arg->argn+1)
|
1998-04-03 19:24:07 +00:00
|
|
|
bundle_SetIdleTimer(arg->bundle, atoi(argp));
|
|
|
|
if (err)
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, err);
|
1998-04-03 19:24:07 +00:00
|
|
|
break;
|
|
|
|
case VAR_LQRPERIOD:
|
|
|
|
ulong_val = atol(argp);
|
|
|
|
if (ulong_val <= 0) {
|
|
|
|
err = "%s: Invalid lqr period\n";
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, err, argp);
|
1998-04-03 19:24:07 +00:00
|
|
|
} else
|
|
|
|
l->lcp.cfg.lqrperiod = ulong_val;
|
|
|
|
break;
|
|
|
|
case VAR_LCPRETRY:
|
|
|
|
ulong_val = atol(argp);
|
|
|
|
if (ulong_val <= 0) {
|
|
|
|
err = "%s: Invalid LCP FSM retry period\n";
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, err, argp);
|
1998-04-03 19:24:07 +00:00
|
|
|
} else
|
|
|
|
cx->physical->link.lcp.cfg.fsmretry = ulong_val;
|
|
|
|
break;
|
|
|
|
case VAR_CHAPRETRY:
|
|
|
|
ulong_val = atol(argp);
|
|
|
|
if (ulong_val <= 0) {
|
|
|
|
err = "%s: Invalid CHAP retry period\n";
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, err, argp);
|
1998-04-03 19:24:07 +00:00
|
|
|
} else
|
|
|
|
cx->chap.auth.cfg.fsmretry = ulong_val;
|
|
|
|
break;
|
|
|
|
case VAR_PAPRETRY:
|
|
|
|
ulong_val = atol(argp);
|
|
|
|
if (ulong_val <= 0) {
|
|
|
|
err = "%s: Invalid PAP retry period\n";
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, err, argp);
|
1998-04-03 19:24:07 +00:00
|
|
|
} else
|
|
|
|
cx->pap.cfg.fsmretry = ulong_val;
|
|
|
|
break;
|
|
|
|
case VAR_CCPRETRY:
|
|
|
|
ulong_val = atol(argp);
|
|
|
|
if (ulong_val <= 0) {
|
|
|
|
err = "%s: Invalid CCP FSM retry period\n";
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, err, argp);
|
1998-04-03 19:24:07 +00:00
|
|
|
} else
|
|
|
|
l->ccp.cfg.fsmretry = ulong_val;
|
|
|
|
break;
|
|
|
|
case VAR_IPCPRETRY:
|
|
|
|
ulong_val = atol(argp);
|
|
|
|
if (ulong_val <= 0) {
|
|
|
|
err = "%s: Invalid IPCP FSM retry period\n";
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, err, argp);
|
1998-04-03 19:24:07 +00:00
|
|
|
} else
|
|
|
|
arg->bundle->ncp.ipcp.cfg.fsmretry = ulong_val;
|
|
|
|
break;
|
1998-04-17 22:05:37 +00:00
|
|
|
case VAR_NBNS:
|
|
|
|
case VAR_DNS:
|
|
|
|
if (param == VAR_DNS)
|
|
|
|
addr = arg->bundle->ncp.ipcp.cfg.ns.dns;
|
|
|
|
else
|
|
|
|
addr = arg->bundle->ncp.ipcp.cfg.ns.nbns;
|
|
|
|
|
|
|
|
addr[0].s_addr = addr[1].s_addr = INADDR_ANY;
|
|
|
|
|
|
|
|
if (arg->argc > arg->argn) {
|
|
|
|
ParseAddr(&arg->bundle->ncp.ipcp, 1, arg->argv + arg->argn,
|
|
|
|
addr, &dummyaddr, &dummyint);
|
|
|
|
if (arg->argc > arg->argn+1)
|
|
|
|
ParseAddr(&arg->bundle->ncp.ipcp, 1, arg->argv + arg->argn + 1,
|
|
|
|
addr + 1, &dummyaddr, &dummyint);
|
|
|
|
|
|
|
|
if (addr[1].s_addr == INADDR_ANY)
|
|
|
|
addr[1].s_addr = addr[0].s_addr;
|
|
|
|
if (addr[0].s_addr == INADDR_ANY)
|
|
|
|
addr[0].s_addr = addr[1].s_addr;
|
|
|
|
}
|
|
|
|
break;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
1998-04-03 19:24:07 +00:00
|
|
|
|
|
|
|
return err ? 1 : 0;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetCtsRts(struct cmdargs const *arg)
|
|
|
|
{
|
1998-04-14 23:17:24 +00:00
|
|
|
if (arg->argc == arg->argn+1) {
|
|
|
|
if (strcmp(arg->argv[arg->argn], "on") == 0)
|
1998-05-01 19:26:12 +00:00
|
|
|
physical_SetRtsCts(arg->cx->physical, 1);
|
1998-04-14 23:17:24 +00:00
|
|
|
else if (strcmp(arg->argv[arg->argn], "off") == 0)
|
1998-05-01 19:26:12 +00:00
|
|
|
physical_SetRtsCts(arg->cx->physical, 0);
|
1998-01-29 00:44:16 +00:00
|
|
|
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-04-03 19:24:07 +00:00
|
|
|
"Set accmap value", "set accmap hex-value", (const void *)VAR_ACCMAP},
|
1998-01-29 00:44:16 +00:00
|
|
|
{"authkey", "key", SetVariable, LOCAL_AUTH,
|
1998-04-03 19:24:07 +00:00
|
|
|
"Set authentication key", "set authkey|key key", (const void *)VAR_AUTHKEY},
|
1998-01-29 00:44:16 +00:00
|
|
|
{"authname", NULL, SetVariable, LOCAL_AUTH,
|
1998-04-03 19:24:07 +00:00
|
|
|
"Set authentication name", "set authname name", (const void *)VAR_AUTHNAME},
|
1998-04-03 19:24:31 +00:00
|
|
|
{"ccpretry", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX_OPT,
|
|
|
|
"Set FSM retry period", "set ccpretry value", (const void *)VAR_CCPRETRY},
|
|
|
|
{"chapretry", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX,
|
|
|
|
"Set CHAP retry period", "set chapretry value", (const void *)VAR_CHAPRETRY},
|
|
|
|
{"ctsrts", "crtscts", SetCtsRts, LOCAL_AUTH | LOCAL_CX,
|
1998-04-03 19:24:07 +00:00
|
|
|
"Use hardware flow control", "set ctsrts [on|off]"},
|
1998-04-03 19:21:56 +00:00
|
|
|
{"deflate", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX_OPT,
|
1998-03-17 22:29:12 +00:00
|
|
|
"Set deflate window sizes", "set deflate out-winsize in-winsize",
|
|
|
|
(const void *) VAR_WINSIZE},
|
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},
|
|
|
|
{"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},
|
1998-04-17 22:05:37 +00:00
|
|
|
{"dns", NULL, SetVariable, LOCAL_AUTH, "Set Domain Name Server",
|
|
|
|
"set dns pri-addr [sec-addr]", (const void *)VAR_DNS},
|
1998-04-03 19:26:29 +00:00
|
|
|
{"encrypt", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX,
|
|
|
|
"Select CHAP encryption type", "set encrypt MSChap|MD5",
|
|
|
|
(const void *)VAR_ENC},
|
1998-04-23 03:23:03 +00:00
|
|
|
{"enddisc", NULL, mp_SetEnddisc, LOCAL_AUTH,
|
|
|
|
"Set Endpoint Discriminator", "set enddisc [IP|magic|label|psn value]"},
|
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-05-01 19:26:12 +00:00
|
|
|
{"filter", NULL, filter_Set, LOCAL_AUTH,
|
1998-04-16 18:30:54 +00:00
|
|
|
"Set packet filters", "set filter alive|dial|in|out rule-no permit|deny "
|
|
|
|
"[src_addr[/width]] [dst_addr[/width]] [tcp|udp|icmp [src [lt|eq|gt port]] "
|
|
|
|
"[dst [lt|eq|gt port]] [estab] [syn] [finrst]]"},
|
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]]]]"},
|
1998-04-03 19:24:31 +00:00
|
|
|
{"ipcpretry", NULL, SetVariable, LOCAL_AUTH,
|
|
|
|
"Set FSM retry period", "set ipcpretry value", (const void *)VAR_IPCPRETRY},
|
|
|
|
{"lcpretry", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX,
|
|
|
|
"Set FSM retry period", "set lcpretry value", (const void *)VAR_LCPRETRY},
|
1998-04-03 19:26:02 +00:00
|
|
|
{"log", NULL, log_SetLevel, LOCAL_AUTH,
|
1998-01-29 00:44:16 +00:00
|
|
|
"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},
|
1998-04-03 19:24:31 +00:00
|
|
|
{"lqrperiod", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX_OPT,
|
|
|
|
"Set LQR period", "set lqrperiod value", (const void *)VAR_LQRPERIOD},
|
1998-04-24 19:16:15 +00:00
|
|
|
{"mrru", NULL, SetVariable, LOCAL_AUTH, "Set MRRU value",
|
1998-04-23 03:23:03 +00:00
|
|
|
"set mrru value", (const void *)VAR_MRRU},
|
1998-04-03 19:24:07 +00:00
|
|
|
{"mru", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX_OPT,
|
|
|
|
"Set MRU value", "set mru value", (const void *)VAR_MRU},
|
1998-04-23 03:23:03 +00:00
|
|
|
{"mtu", NULL, SetVariable, LOCAL_AUTH,
|
|
|
|
"Set interface MTU value", "set mtu value", (const void *)VAR_MTU},
|
1998-04-17 22:05:37 +00:00
|
|
|
{"nbns", NULL, SetVariable, LOCAL_AUTH, "Set NetBIOS Name Server",
|
|
|
|
"set nbns pri-addr [sec-addr]", (const void *)VAR_NBNS},
|
1998-04-03 19:24:07 +00:00
|
|
|
{"openmode", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX, "Set open mode",
|
|
|
|
"set openmode active|passive [secs]", (const void *)VAR_OPENMODE},
|
1998-04-03 19:24:31 +00:00
|
|
|
{"papretry", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX,
|
|
|
|
"Set PAP retry period", "set papretry value", (const void *)VAR_PAPRETRY},
|
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]"},
|
1998-03-09 19:24:58 +00:00
|
|
|
{"phone", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX, "Set telephone number(s)",
|
1998-04-03 19:24:07 +00:00
|
|
|
"set phone phone1[:phone2[...]]", (const void *)VAR_PHONE},
|
1998-04-10 13:19:23 +00:00
|
|
|
{"reconnect", NULL, datalink_SetReconnect, LOCAL_AUTH | LOCAL_CX,
|
1998-01-29 00:44:16 +00:00
|
|
|
"Set Reconnect timeout", "set reconnect value ntries"},
|
1998-04-10 13:19:23 +00:00
|
|
|
{"redial", NULL, datalink_SetRedial, LOCAL_AUTH | LOCAL_CX,
|
1998-02-17 19:28:01 +00:00
|
|
|
"Set Redial timeout", "set redial value|random[.value|random] [attempts]"},
|
1998-01-29 00:44:16 +00:00
|
|
|
{"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"},
|
1998-04-03 19:24:31 +00:00
|
|
|
{"stopped", NULL, SetStoppedTimeout, LOCAL_AUTH | LOCAL_CX,
|
|
|
|
"Set STOPPED timeouts", "set stopped [LCPseconds [CCPseconds]]"},
|
1998-04-03 19:24:07 +00:00
|
|
|
{"timeout", NULL, SetVariable, LOCAL_AUTH, "Set Idle timeout",
|
|
|
|
"set timeout idletime", (const void *)VAR_IDLETIMEOUT},
|
1998-05-01 19:26:12 +00:00
|
|
|
{"vj", NULL, ipcp_vjset, LOCAL_AUTH,
|
1998-04-03 19:26:29 +00:00
|
|
|
"Set vj values", "set vj slots|slotcomp [value]"},
|
1998-04-03 19:21:56 +00:00
|
|
|
{"weight", NULL, mp_SetDatalinkWeight, LOCAL_AUTH | LOCAL_CX,
|
|
|
|
"Set datalink weighting", "set weight n"},
|
1998-01-29 00:44:16 +00:00
|
|
|
{"help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
|
|
|
|
"Display this message", "set help|? [command]", SetCommands},
|
|
|
|
{NULL, NULL, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
SetCommand(struct cmdargs const *arg)
|
|
|
|
{
|
1998-04-14 23:17:24 +00:00
|
|
|
if (arg->argc > arg->argn)
|
|
|
|
FindExec(arg->bundle, SetCommands, arg->argc, arg->argn, arg->argv,
|
1998-04-03 19:26:02 +00:00
|
|
|
arg->prompt, arg->cx);
|
|
|
|
else if (arg->prompt)
|
|
|
|
prompt_Printf(arg->prompt, "Use `set ?' to get a list or `set ? <var>' for"
|
1998-01-29 00:44:16 +00:00
|
|
|
" syntax help.\n");
|
|
|
|
else
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "set command must have arguments\n");
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
AddCommand(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
struct in_addr dest, gateway, netmask;
|
|
|
|
int gw;
|
|
|
|
|
1998-04-14 23:17:24 +00:00
|
|
|
if (arg->argc != arg->argn+3 && arg->argc != arg->argn+2)
|
1998-01-29 00:44:16 +00:00
|
|
|
return -1;
|
|
|
|
|
1998-04-25 10:49:52 +00:00
|
|
|
if (arg->argc == arg->argn+2) {
|
1998-04-14 23:17:24 +00:00
|
|
|
if (strcasecmp(arg->argv[arg->argn], "default"))
|
1998-01-29 00:44:16 +00:00
|
|
|
return -1;
|
|
|
|
else {
|
|
|
|
dest.s_addr = netmask.s_addr = INADDR_ANY;
|
|
|
|
gw = 1;
|
|
|
|
}
|
1998-04-25 10:49:52 +00:00
|
|
|
} else {
|
1998-04-14 23:17:24 +00:00
|
|
|
if (strcasecmp(arg->argv[arg->argn], "MYADDR") == 0)
|
1998-03-13 21:07:46 +00:00
|
|
|
dest = arg->bundle->ncp.ipcp.my_ip;
|
1998-04-14 23:17:24 +00:00
|
|
|
else if (strcasecmp(arg->argv[arg->argn], "HISADDR") == 0)
|
1998-03-13 21:07:46 +00:00
|
|
|
dest = arg->bundle->ncp.ipcp.peer_ip;
|
1998-01-29 00:44:16 +00:00
|
|
|
else
|
1998-04-14 23:17:24 +00:00
|
|
|
dest = GetIpAddr(arg->argv[arg->argn]);
|
|
|
|
netmask = GetIpAddr(arg->argv[arg->argn+1]);
|
1998-01-29 00:44:16 +00:00
|
|
|
gw = 2;
|
|
|
|
}
|
1998-04-14 23:17:24 +00:00
|
|
|
if (strcasecmp(arg->argv[arg->argn+gw], "HISADDR") == 0)
|
1998-03-13 21:07:46 +00:00
|
|
|
gateway = arg->bundle->ncp.ipcp.peer_ip;
|
1998-04-14 23:17:24 +00:00
|
|
|
else if (strcasecmp(arg->argv[arg->argn+gw], "INTERFACE") == 0)
|
1998-01-29 00:44:16 +00:00
|
|
|
gateway.s_addr = INADDR_ANY;
|
|
|
|
else
|
1998-04-14 23:17:24 +00:00
|
|
|
gateway = GetIpAddr(arg->argv[arg->argn+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;
|
|
|
|
|
1998-04-25 10:49:52 +00:00
|
|
|
if (arg->argc == arg->argn+1) {
|
1998-04-14 23:17:24 +00:00
|
|
|
if(strcasecmp(arg->argv[arg->argn], "all") == 0)
|
1998-05-01 19:26:12 +00:00
|
|
|
route_IfDelete(arg->bundle, 0);
|
1998-01-29 00:44:16 +00:00
|
|
|
else {
|
1998-04-14 23:17:24 +00:00
|
|
|
if (strcasecmp(arg->argv[arg->argn], "MYADDR") == 0)
|
1998-03-13 21:07:46 +00:00
|
|
|
dest = arg->bundle->ncp.ipcp.my_ip;
|
1998-04-14 23:17:24 +00:00
|
|
|
else if (strcasecmp(arg->argv[arg->argn], "default") == 0)
|
1998-01-29 00:44:16 +00:00
|
|
|
dest.s_addr = INADDR_ANY;
|
|
|
|
else
|
1998-04-14 23:17:24 +00:00
|
|
|
dest = GetIpAddr(arg->argv[arg->argn]);
|
1998-01-29 00:44:16 +00:00
|
|
|
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
|
|
|
}
|
1998-04-25 10:49:52 +00:00
|
|
|
} else
|
1998-01-29 00:44:16 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NOALIAS
|
|
|
|
static struct cmdtab const AliasCommands[] =
|
|
|
|
{
|
1998-05-01 19:26:12 +00:00
|
|
|
{"addr", NULL, alias_RedirectAddr, LOCAL_AUTH,
|
1998-04-03 19:24:31 +00:00
|
|
|
"static address translation", "alias addr [addr_local addr_alias]"},
|
1998-01-29 00:44:16 +00:00
|
|
|
{"deny_incoming", NULL, AliasOption, LOCAL_AUTH,
|
1998-04-03 19:24:31 +00:00
|
|
|
"stop incoming connections", "alias deny_incoming [yes|no]",
|
|
|
|
(const void *) PKT_ALIAS_DENY_INCOMING},
|
|
|
|
{"enable", NULL, AliasEnable, LOCAL_AUTH,
|
|
|
|
"enable IP aliasing", "alias enable [yes|no]"},
|
1998-01-29 00:44:16 +00:00
|
|
|
{"log", NULL, AliasOption, LOCAL_AUTH,
|
1998-04-03 19:24:31 +00:00
|
|
|
"log aliasing link creation", "alias log [yes|no]",
|
|
|
|
(const void *) PKT_ALIAS_LOG},
|
1998-05-01 19:26:12 +00:00
|
|
|
{"port", NULL, alias_RedirectPort, LOCAL_AUTH,
|
1998-04-03 19:24:31 +00:00
|
|
|
"port redirection", "alias port [proto addr_local:port_local port_alias]"},
|
1998-01-29 00:44:16 +00:00
|
|
|
{"same_ports", NULL, AliasOption, LOCAL_AUTH,
|
1998-04-03 19:24:31 +00:00
|
|
|
"try to leave port numbers unchanged", "alias same_ports [yes|no]",
|
|
|
|
(const void *) PKT_ALIAS_SAME_PORTS},
|
1998-01-29 00:44:16 +00:00
|
|
|
{"unregistered_only", NULL, AliasOption, LOCAL_AUTH,
|
1998-04-03 19:24:31 +00:00
|
|
|
"alias unregistered (private) IP address space only",
|
|
|
|
"alias unregistered_only [yes|no]",
|
|
|
|
(const void *) PKT_ALIAS_UNREGISTERED_ONLY},
|
|
|
|
{"use_sockets", NULL, AliasOption, LOCAL_AUTH,
|
|
|
|
"allocate host sockets", "alias use_sockets [yes|no]",
|
|
|
|
(const void *) PKT_ALIAS_USE_SOCKETS},
|
1998-01-29 00:44:16 +00:00
|
|
|
{"help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
|
1998-04-03 19:24:31 +00:00
|
|
|
"Display this message", "alias help|? [command]", AliasCommands},
|
1998-01-29 00:44:16 +00:00
|
|
|
{NULL, NULL, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
AliasCommand(struct cmdargs const *arg)
|
|
|
|
{
|
1998-04-14 23:17:24 +00:00
|
|
|
if (arg->argc > arg->argn)
|
|
|
|
FindExec(arg->bundle, AliasCommands, arg->argc, arg->argn, arg->argv,
|
1998-04-03 19:26:02 +00:00
|
|
|
arg->prompt, arg->cx);
|
|
|
|
else if (arg->prompt)
|
|
|
|
prompt_Printf(arg->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
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "alias command must have arguments\n");
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
AliasEnable(struct cmdargs const *arg)
|
|
|
|
{
|
1998-04-25 10:49:52 +00:00
|
|
|
if (arg->argc == arg->argn+1) {
|
1998-04-14 23:17:24 +00:00
|
|
|
if (strcasecmp(arg->argv[arg->argn], "yes") == 0) {
|
1998-05-01 19:26:12 +00:00
|
|
|
if (alias_Load() == 0)
|
1998-04-07 23:46:09 +00:00
|
|
|
return 0;
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "Cannot load alias library\n");
|
1998-04-07 23:46:09 +00:00
|
|
|
return 1;
|
1998-04-14 23:17:24 +00:00
|
|
|
} else if (strcasecmp(arg->argv[arg->argn], "no") == 0) {
|
1998-05-01 19:26:12 +00:00
|
|
|
alias_Unload();
|
1998-01-29 00:44:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1998-04-25 10:49:52 +00:00
|
|
|
}
|
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
AliasOption(struct cmdargs const *arg)
|
|
|
|
{
|
1998-02-17 19:28:01 +00:00
|
|
|
unsigned param = (unsigned)arg->cmd->args;
|
1998-04-25 10:49:52 +00:00
|
|
|
if (arg->argc == arg->argn+1) {
|
1998-04-14 23:17:24 +00:00
|
|
|
if (strcasecmp(arg->argv[arg->argn], "yes") == 0) {
|
1998-05-01 19:26:12 +00:00
|
|
|
if (alias_IsEnabled()) {
|
1998-04-07 00:54:26 +00:00
|
|
|
(*PacketAlias.SetMode)(param, param);
|
1998-01-29 00:44:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "alias not enabled\n");
|
1998-04-14 23:17:24 +00:00
|
|
|
} else if (strcmp(arg->argv[arg->argn], "no") == 0) {
|
1998-05-01 19:26:12 +00:00
|
|
|
if (alias_IsEnabled()) {
|
1998-04-07 00:54:26 +00:00
|
|
|
(*PacketAlias.SetMode)(0, param);
|
1998-01-29 00:44:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "alias not enabled\n");
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
1998-04-25 10:49:52 +00:00
|
|
|
}
|
1998-01-29 00:44:16 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif /* #ifndef NOALIAS */
|
|
|
|
|
|
|
|
static struct cmdtab const AllowCommands[] = {
|
|
|
|
{"modes", "mode", AllowModes, LOCAL_AUTH,
|
|
|
|
"Only allow certain ppp modes", "allow modes mode..."},
|
1998-04-03 19:24:31 +00:00
|
|
|
{"users", "user", AllowUsers, LOCAL_AUTH,
|
|
|
|
"Allow users access to ppp", "allow users logname..."},
|
1998-01-29 00:44:16 +00:00
|
|
|
{"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-05-01 19:26:12 +00:00
|
|
|
/* arg->bundle may be NULL (see system_IsValid()) ! */
|
1998-04-14 23:17:24 +00:00
|
|
|
if (arg->argc > arg->argn)
|
|
|
|
FindExec(arg->bundle, AllowCommands, arg->argc, arg->argn, arg->argv,
|
1998-04-03 19:26:02 +00:00
|
|
|
arg->prompt, arg->cx);
|
|
|
|
else if (arg->prompt)
|
|
|
|
prompt_Printf(arg->prompt, "Use `allow ?' to get a list or `allow ? <cmd>'"
|
|
|
|
" for syntax help.\n");
|
1998-01-29 00:44:16 +00:00
|
|
|
else
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "allow command must have arguments\n");
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
1998-02-17 19:28:01 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
LinkCommand(struct cmdargs const *arg)
|
|
|
|
{
|
1998-04-14 23:17:24 +00:00
|
|
|
if (arg->argc > arg->argn+1) {
|
|
|
|
struct datalink *cx = bundle2datalink(arg->bundle, arg->argv[arg->argn]);
|
1998-02-17 19:28:01 +00:00
|
|
|
if (cx)
|
1998-04-14 23:17:24 +00:00
|
|
|
FindExec(arg->bundle, Commands, arg->argc, arg->argn+1, arg->argv,
|
1998-04-03 19:26:02 +00:00
|
|
|
arg->prompt, cx);
|
1998-02-17 19:28:01 +00:00
|
|
|
else {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "link: %s: Invalid link name\n", arg->argv[arg->argn]);
|
1998-02-17 19:28:01 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} else {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "Usage: %s\n", arg->cmd->syntax);
|
1998-02-17 19:28:01 +00:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
1998-04-03 19:21:56 +00:00
|
|
|
|
|
|
|
struct link *
|
1998-05-01 19:26:12 +00:00
|
|
|
command_ChooseLink(struct cmdargs const *arg)
|
1998-04-03 19:21:56 +00:00
|
|
|
{
|
|
|
|
if (arg->cx)
|
|
|
|
return &arg->cx->physical->link;
|
1998-04-24 19:15:48 +00:00
|
|
|
else if (arg->bundle->ncp.mp.cfg.mrru)
|
1998-04-03 19:21:56 +00:00
|
|
|
return &arg->bundle->ncp.mp.link;
|
|
|
|
else {
|
1998-04-03 19:26:29 +00:00
|
|
|
struct datalink *dl = bundle2datalink(arg->bundle, NULL);
|
|
|
|
return dl ? &dl->physical->link : NULL;
|
1998-04-03 19:21:56 +00:00
|
|
|
}
|
|
|
|
}
|
1998-04-16 00:26:21 +00:00
|
|
|
|
|
|
|
static const char *
|
|
|
|
ident_cmd(const char *cmd, unsigned *keep, unsigned *add)
|
|
|
|
{
|
|
|
|
const char *result;
|
|
|
|
|
|
|
|
switch (*cmd) {
|
|
|
|
case 'A':
|
|
|
|
case 'a':
|
|
|
|
result = "accept";
|
|
|
|
*keep = NEG_MYMASK;
|
|
|
|
*add = NEG_ACCEPTED;
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
case 'd':
|
|
|
|
switch (cmd[1]) {
|
|
|
|
case 'E':
|
|
|
|
case 'e':
|
|
|
|
result = "deny";
|
|
|
|
*keep = NEG_MYMASK;
|
|
|
|
*add = 0;
|
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
case 'i':
|
|
|
|
result = "disable";
|
|
|
|
*keep = NEG_HISMASK;
|
|
|
|
*add = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'E':
|
|
|
|
case 'e':
|
|
|
|
result = "enable";
|
|
|
|
*keep = NEG_HISMASK;
|
|
|
|
*add = NEG_ENABLED;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
OptSet(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
int bit = (int)arg->cmd->args;
|
|
|
|
const char *cmd;
|
|
|
|
unsigned keep; /* Keep these bits */
|
|
|
|
unsigned add; /* Add these bits */
|
|
|
|
|
|
|
|
if ((cmd = ident_cmd(arg->argv[arg->argn-2], &keep, &add)) == NULL)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (add)
|
|
|
|
arg->bundle->cfg.opt |= bit;
|
|
|
|
else
|
|
|
|
arg->bundle->cfg.opt &= ~bit;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
NegotiateSet(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
int param = (int)arg->cmd->args;
|
1998-05-01 19:26:12 +00:00
|
|
|
struct link *l = command_ChooseLink(arg); /* AUTH_CX_OPT uses this */
|
1998-04-16 00:26:21 +00:00
|
|
|
struct datalink *cx = arg->cx; /* AUTH_CX uses this */
|
|
|
|
const char *cmd;
|
|
|
|
unsigned keep; /* Keep these bits */
|
|
|
|
unsigned add; /* Add these bits */
|
|
|
|
|
|
|
|
if ((cmd = ident_cmd(arg->argv[arg->argn-2], &keep, &add)) == NULL)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if ((arg->cmd->lauth & LOCAL_CX) && !cx) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "%s %s: No context (use the `link' command)\n",
|
1998-04-16 00:26:21 +00:00
|
|
|
cmd, arg->cmd->name);
|
|
|
|
return 2;
|
|
|
|
} else if (cx && !(arg->cmd->lauth & (LOCAL_CX|LOCAL_CX_OPT))) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "%s %s: Redundant context (%s) ignored\n",
|
1998-04-16 00:26:21 +00:00
|
|
|
cmd, arg->cmd->name, cx->name);
|
|
|
|
cx = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (param) {
|
|
|
|
case NEG_ACFCOMP:
|
|
|
|
cx->physical->link.lcp.cfg.acfcomp &= keep;
|
|
|
|
cx->physical->link.lcp.cfg.acfcomp |= add;
|
|
|
|
break;
|
|
|
|
case NEG_CHAP:
|
|
|
|
cx->physical->link.lcp.cfg.chap &= keep;
|
|
|
|
cx->physical->link.lcp.cfg.chap |= add;
|
|
|
|
break;
|
|
|
|
case NEG_DEFLATE:
|
|
|
|
l->ccp.cfg.neg[CCP_NEG_DEFLATE] &= keep;
|
|
|
|
l->ccp.cfg.neg[CCP_NEG_DEFLATE] |= add;
|
|
|
|
break;
|
1998-04-17 22:05:37 +00:00
|
|
|
case NEG_DNS:
|
|
|
|
arg->bundle->ncp.ipcp.cfg.ns.dns_neg &= keep;
|
|
|
|
arg->bundle->ncp.ipcp.cfg.ns.dns_neg |= add;
|
|
|
|
break;
|
1998-04-16 00:26:21 +00:00
|
|
|
case NEG_LQR:
|
|
|
|
cx->physical->link.lcp.cfg.lqr &= keep;
|
|
|
|
cx->physical->link.lcp.cfg.lqr |= add;
|
|
|
|
break;
|
|
|
|
case NEG_PAP:
|
|
|
|
cx->physical->link.lcp.cfg.pap &= keep;
|
|
|
|
cx->physical->link.lcp.cfg.pap |= add;
|
|
|
|
break;
|
|
|
|
case NEG_PPPDDEFLATE:
|
|
|
|
l->ccp.cfg.neg[CCP_NEG_DEFLATE24] &= keep;
|
|
|
|
l->ccp.cfg.neg[CCP_NEG_DEFLATE24] |= add;
|
|
|
|
break;
|
|
|
|
case NEG_PRED1:
|
|
|
|
l->ccp.cfg.neg[CCP_NEG_PRED1] &= keep;
|
|
|
|
l->ccp.cfg.neg[CCP_NEG_PRED1] |= add;
|
|
|
|
break;
|
|
|
|
case NEG_PROTOCOMP:
|
|
|
|
cx->physical->link.lcp.cfg.protocomp &= keep;
|
|
|
|
cx->physical->link.lcp.cfg.protocomp |= add;
|
|
|
|
break;
|
1998-04-23 03:23:03 +00:00
|
|
|
case NEG_SHORTSEQ:
|
|
|
|
if (bundle_Phase(arg->bundle) != PHASE_DEAD)
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "shortseq: Only changable at phase DEAD\n");
|
1998-04-23 03:23:03 +00:00
|
|
|
else {
|
|
|
|
arg->bundle->ncp.mp.cfg.shortseq &= keep;
|
|
|
|
arg->bundle->ncp.mp.cfg.shortseq |= add;
|
|
|
|
}
|
|
|
|
break;
|
1998-04-16 00:26:21 +00:00
|
|
|
case NEG_VJCOMP:
|
|
|
|
arg->bundle->ncp.ipcp.cfg.vj.neg &= keep;
|
|
|
|
arg->bundle->ncp.ipcp.cfg.vj.neg |= add;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct cmdtab const NegotiateCommands[] = {
|
1998-04-17 22:05:37 +00:00
|
|
|
{"idcheck", NULL, OptSet, LOCAL_AUTH, "Check FSM reply ids",
|
1998-04-16 00:26:21 +00:00
|
|
|
"disable|enable", (const void *)OPT_IDCHECK},
|
|
|
|
{"loopback", NULL, OptSet, LOCAL_AUTH, "Loop packets for local iface",
|
|
|
|
"disable|enable", (const void *)OPT_LOOPBACK},
|
|
|
|
{"passwdauth", NULL, OptSet, LOCAL_AUTH, "Use passwd file",
|
|
|
|
"disable|enable", (const void *)OPT_PASSWDAUTH},
|
|
|
|
{"proxy", NULL, OptSet, LOCAL_AUTH, "Create proxy ARP entry",
|
|
|
|
"disable|enable", (const void *)OPT_PROXY},
|
|
|
|
{"throughput", NULL, OptSet, LOCAL_AUTH, "Rolling throughput",
|
|
|
|
"disable|enable", (const void *)OPT_THROUGHPUT},
|
|
|
|
{"utmp", NULL, OptSet, LOCAL_AUTH, "Log connections in utmp",
|
|
|
|
"disable|enable", (const void *)OPT_UTMP},
|
|
|
|
|
1998-04-17 22:05:37 +00:00
|
|
|
#define OPT_MAX 6 /* accept/deny allowed below and not above */
|
1998-04-16 00:26:21 +00:00
|
|
|
|
|
|
|
{"acfcomp", NULL, NegotiateSet, LOCAL_AUTH | LOCAL_CX,
|
|
|
|
"Address & Control field compression", "accept|deny|disable|enable",
|
|
|
|
(const void *)NEG_ACFCOMP},
|
|
|
|
{"chap", NULL, NegotiateSet, LOCAL_AUTH | LOCAL_CX,
|
|
|
|
"Challenge Handshake Authentication Protocol", "accept|deny|disable|enable",
|
|
|
|
(const void *)NEG_CHAP},
|
|
|
|
{"deflate", NULL, NegotiateSet, LOCAL_AUTH | LOCAL_CX_OPT,
|
|
|
|
"Deflate compression", "accept|deny|disable|enable",
|
|
|
|
(const void *)NEG_DEFLATE},
|
1998-04-17 22:05:37 +00:00
|
|
|
{"deflate24", NULL, NegotiateSet, LOCAL_AUTH | LOCAL_CX_OPT,
|
|
|
|
"Deflate (type 24) compression", "accept|deny|disable|enable",
|
|
|
|
(const void *)NEG_PPPDDEFLATE},
|
|
|
|
{"dns", NULL, NegotiateSet, LOCAL_AUTH,
|
|
|
|
"DNS specification", "accept|deny|disable|enable", (const void *)NEG_DNS},
|
1998-04-16 00:26:21 +00:00
|
|
|
{"lqr", NULL, NegotiateSet, LOCAL_AUTH | LOCAL_CX,
|
|
|
|
"Link Quality Reports", "accept|deny|disable|enable",
|
|
|
|
(const void *)NEG_LQR},
|
|
|
|
{"pap", NULL, NegotiateSet, LOCAL_AUTH | LOCAL_CX,
|
|
|
|
"Password Authentication protocol", "accept|deny|disable|enable",
|
|
|
|
(const void *)NEG_PAP},
|
1998-04-19 03:41:01 +00:00
|
|
|
{"pred1", "predictor1", NegotiateSet, LOCAL_AUTH | LOCAL_CX_OPT,
|
1998-04-16 00:26:21 +00:00
|
|
|
"Predictor 1 compression", "accept|deny|disable|enable",
|
|
|
|
(const void *)NEG_PRED1},
|
|
|
|
{"protocomp", NULL, NegotiateSet, LOCAL_AUTH | LOCAL_CX,
|
|
|
|
"Protocol field compression", "accept|deny|disable|enable",
|
|
|
|
(const void *)NEG_PROTOCOMP},
|
1998-04-23 03:23:03 +00:00
|
|
|
{"shortseq", NULL, NegotiateSet, LOCAL_AUTH,
|
|
|
|
"MP Short Sequence Numbers", "accept|deny|disable|enable",
|
|
|
|
(const void *)NEG_SHORTSEQ},
|
1998-04-16 00:26:21 +00:00
|
|
|
{"vjcomp", NULL, NegotiateSet, LOCAL_AUTH,
|
|
|
|
"Van Jacobson header compression", "accept|deny|disable|enable",
|
|
|
|
(const void *)NEG_VJCOMP},
|
|
|
|
{"help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
|
|
|
|
"Display this message", "accept|deny|disable|enable help|? [value]",
|
|
|
|
NegotiateCommands},
|
|
|
|
{NULL, NULL, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
NegotiateCommand(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
if (arg->argc > arg->argn) {
|
|
|
|
char const *argv[3];
|
|
|
|
unsigned keep, add;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
if ((argv[0] = ident_cmd(arg->argv[arg->argn-1], &keep, &add)) == NULL)
|
|
|
|
return -1;
|
|
|
|
argv[2] = NULL;
|
|
|
|
|
|
|
|
for (n = arg->argn; n < arg->argc; n++) {
|
|
|
|
argv[1] = arg->argv[n];
|
|
|
|
FindExec(arg->bundle, NegotiateCommands + (keep == NEG_HISMASK ?
|
|
|
|
0 : OPT_MAX), 2, 1, argv, arg->prompt, arg->cx);
|
|
|
|
}
|
|
|
|
} else if (arg->prompt)
|
1998-04-17 22:05:37 +00:00
|
|
|
prompt_Printf(arg->prompt, "Use `%s ?' to get a list.\n",
|
|
|
|
arg->argv[arg->argn-1]);
|
1998-04-16 00:26:21 +00:00
|
|
|
else
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "%s command must have arguments\n",
|
1998-04-16 00:26:21 +00:00
|
|
|
arg->argv[arg->argn] );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
command_ShowNegval(unsigned val)
|
|
|
|
{
|
|
|
|
switch (val&3) {
|
|
|
|
case 1: return "disabled & accepted";
|
|
|
|
case 2: return "enabled & denied";
|
|
|
|
case 3: return "enabled & accepted";
|
|
|
|
}
|
|
|
|
return "disabled & denied";
|
|
|
|
}
|