Pass all command arguments around with struct cmdargs rather

than incrementing argv and decrementing argc.  Now individual
functions can determine their caller.  This also removes the
"prefix" hack in FindExec().
This commit is contained in:
Brian Somers 1998-04-14 23:17:24 +00:00
parent 7f717ec1b8
commit 250920922b
12 changed files with 206 additions and 174 deletions

View File

@ -2,7 +2,7 @@
* The code in this file was written by Eivind Eklund <perhaps@yes.no>,
* who places it in the public domain without restriction.
*
* $Id: alias_cmd.c,v 1.12.2.5 1998/04/07 00:53:12 brian Exp $
* $Id: alias_cmd.c,v 1.12.2.6 1998/04/07 23:45:39 brian Exp $
*/
#include <sys/types.h>
@ -34,7 +34,7 @@ AliasRedirectPort(struct cmdargs const *arg)
if (!AliasEnabled()) {
prompt_Printf(arg->prompt, "Alias not enabled\n");
return 1;
} else if (arg->argc == 3) {
} else if (arg->argc == arg->argn+3) {
char proto_constant;
const char *proto;
u_short local_port;
@ -44,7 +44,7 @@ AliasRedirectPort(struct cmdargs const *arg)
struct in_addr null_addr;
struct alias_link *link;
proto = arg->argv[0];
proto = arg->argv[arg->argn];
if (strcmp(proto, "tcp") == 0) {
proto_constant = IPPROTO_TCP;
} else if (strcmp(proto, "udp") == 0) {
@ -57,7 +57,8 @@ AliasRedirectPort(struct cmdargs const *arg)
return 1;
}
error = StrToAddrAndPort(arg->argv[1], &local_addr, &local_port, proto);
error = StrToAddrAndPort(arg->argv[arg->argn+1], &local_addr, &local_port,
proto);
if (error) {
prompt_Printf(arg->prompt, "port redirect: error reading"
" local addr:port\n");
@ -65,7 +66,7 @@ AliasRedirectPort(struct cmdargs const *arg)
arg->cmd->syntax);
return 1;
}
error = StrToPort(arg->argv[2], &alias_port, proto);
error = StrToPort(arg->argv[arg->argn+2], &alias_port, proto);
if (error) {
prompt_Printf(arg->prompt, "port redirect: error reading alias port\n");
prompt_Printf(arg->prompt, "Usage: alias %s %s\n", arg->cmd->name,
@ -95,18 +96,18 @@ AliasRedirectAddr(struct cmdargs const *arg)
if (!AliasEnabled()) {
prompt_Printf(arg->prompt, "alias not enabled\n");
return 1;
} else if (arg->argc == 2) {
} else if (arg->argc == arg->argn+2) {
int error;
struct in_addr local_addr;
struct in_addr alias_addr;
struct alias_link *link;
error = StrToAddr(arg->argv[0], &local_addr);
error = StrToAddr(arg->argv[arg->argn], &local_addr);
if (error) {
prompt_Printf(arg->prompt, "address redirect: invalid local address\n");
return 1;
}
error = StrToAddr(arg->argv[1], &alias_addr);
error = StrToAddr(arg->argv[arg->argn+1], &alias_addr);
if (error) {
prompt_Printf(arg->prompt, "address redirect: invalid alias address\n");
prompt_Printf(arg->prompt, "Usage: alias %s %s\n", arg->cmd->name,

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: bundle.c,v 1.1.2.44 1998/04/10 13:19:01 brian Exp $
* $Id: bundle.c,v 1.1.2.45 1998/04/11 21:50:37 brian Exp $
*/
#include <sys/types.h>
@ -235,7 +235,6 @@ bundle_LayerDown(void *v, struct fsm *fp)
if (fp->proto == PROTO_IPCP) {
bundle_StopIdleTimer(bundle);
bundle_NewPhase(bundle, PHASE_TERMINATE);
} else if (fp->proto == PROTO_LCP) {
int speed, others_active;
struct datalink *dl;
@ -268,6 +267,7 @@ bundle_LayerFinish(void *v, struct fsm *fp)
struct datalink *dl;
if (fp->proto == PROTO_IPCP) {
bundle_NewPhase(bundle, PHASE_TERMINATE);
for (dl = bundle->links; dl; dl = dl->next)
datalink_Close(dl, 0);
FsmDown(fp);

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: command.c,v 1.131.2.58 1998/04/10 23:51:27 brian Exp $
* $Id: command.c,v 1.131.2.59 1998/04/11 21:50:44 brian Exp $
*
*/
#include <sys/types.h>
@ -108,11 +108,11 @@ HelpCommand(struct cmdargs const *arg)
return 0;
}
if (arg->argc > 0) {
if (arg->argc > arg->argn) {
for (cmd = arg->cmdtab; cmd->name || cmd->alias; cmd++)
if ((cmd->lauth & arg->prompt->auth) &&
((cmd->name && !strcasecmp(cmd->name, *arg->argv)) ||
(cmd->alias && !strcasecmp(cmd->alias, *arg->argv)))) {
((cmd->name && !strcasecmp(cmd->name, arg->argv[arg->argn])) ||
(cmd->alias && !strcasecmp(cmd->alias, arg->argv[arg->argn])))) {
prompt_Printf(arg->prompt, "%s\n", cmd->syntax);
return 0;
}
@ -148,7 +148,7 @@ CloneCommand(struct cmdargs const *arg)
{
int f;
if (arg->argc == 0)
if (arg->argc == arg->argn)
return -1;
if (!arg->bundle->ncp.mp.active) {
@ -156,7 +156,7 @@ CloneCommand(struct cmdargs const *arg)
return 1;
}
for (f = 0; f < arg->argc; f++)
for (f = arg->argn; f < arg->argc; f++)
bundle_DatalinkClone(arg->bundle, arg->cx, arg->argv[f]);
return 0;
}
@ -164,7 +164,7 @@ CloneCommand(struct cmdargs const *arg)
static int
RemoveCommand(struct cmdargs const *arg)
{
if (arg->argc != 0)
if (arg->argc != arg->argn)
return -1;
if (!arg->bundle->ncp.mp.active) {
@ -186,8 +186,8 @@ LoadCommand(struct cmdargs const *arg)
{
const char *name;
if (arg->argc > 0)
name = *arg->argv;
if (arg->argc > arg->argn)
name = arg->argv[arg->argn];
else
name = "default";
@ -198,7 +198,7 @@ LoadCommand(struct cmdargs const *arg)
LogPrintf(LogWARN, "%s: label not found.\n", name);
return -1;
} else
SetLabel(arg->argc ? name : NULL);
SetLabel(arg->argc > arg->argn ? name : NULL);
return 0;
}
@ -221,7 +221,7 @@ DialCommand(struct cmdargs const *arg)
return 1;
}
if (arg->argc > 0 && (res = LoadCommand(arg)) != 0)
if (arg->argc > arg->argn && (res = LoadCommand(arg)) != 0)
return res;
bundle_Open(arg->bundle, arg->cx ? arg->cx->name : NULL, PHYS_ALL);
@ -245,7 +245,7 @@ ShellCommand(struct cmdargs const *arg, int bg)
}
#endif
if (arg->argc == 0)
if (arg->argc == arg->argn)
if (!arg->prompt) {
LogPrintf(LogWARN, "Can't start an interactive shell from"
" a config file\n");
@ -286,10 +286,10 @@ ShellCommand(struct cmdargs const *arg, int bg)
close(i);
setuid(geteuid());
if (arg->argc > 0) {
if (arg->argc > arg->argn) {
/* substitute pseudo args */
argv[0] = strdup(arg->argv[0]);
for (argc = 1; argc < arg->argc; argc++) {
argv[0] = strdup(arg->argv[arg->argn]);
for (argc = arg->argn+1; argc < arg->argc; argc++) {
if (strcasecmp(arg->argv[argc], "HISADDR") == 0)
argv[argc] = strdup(inet_ntoa(arg->bundle->ncp.ipcp.peer_ip));
else if (strcasecmp(arg->argv[argc], "INTERFACE") == 0)
@ -309,7 +309,7 @@ ShellCommand(struct cmdargs const *arg, int bg)
exit(1);
}
} else if (arg->prompt)
printf("ppp: Pausing until %s finishes\n", arg->argv[0]);
printf("ppp: Pausing until %s finishes\n", arg->argv[arg->argn]);
execvp(argv[0], argv);
} else {
if (arg->prompt)
@ -319,7 +319,7 @@ ShellCommand(struct cmdargs const *arg, int bg)
}
LogPrintf(LogWARN, "exec() of %s failed\n",
arg->argc > 0 ? arg->argv[0] : shell);
arg->argc > arg->argn ? arg->argv[arg->argn] : shell);
exit(255);
}
@ -339,7 +339,7 @@ ShellCommand(struct cmdargs const *arg, int bg)
static int
BgShellCommand(struct cmdargs const *arg)
{
if (arg->argc == 0)
if (arg->argc == arg->argn)
return -1;
return ShellCommand(arg, 1);
}
@ -462,7 +462,7 @@ static int
ShowVersion(struct cmdargs const *arg)
{
static char VarVersion[] = "PPP Version 2.0-beta";
static char VarLocalVersion[] = "$Date: 1998/04/10 23:51:27 $";
static char VarLocalVersion[] = "$Date: 1998/04/11 21:50:44 $";
prompt_Printf(arg->prompt, "%s - %s \n", VarVersion, VarLocalVersion);
return 0;
@ -576,49 +576,72 @@ FindCommand(struct cmdtab const *cmds, const char *str, int *pmatch)
return found;
}
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;
}
static int
FindExec(struct bundle *bundle, struct cmdtab const *cmds, int argc,
char const *const *argv, const char *prefix, struct prompt *prompt,
struct datalink *cx)
FindExec(struct bundle *bundle, struct cmdtab const *cmds, int argc, int argn,
char const *const *argv, struct prompt *prompt, struct datalink *cx)
{
struct cmdtab const *cmd;
int val = 1;
int nmatch;
struct cmdargs arg;
char prefix[100];
cmd = FindCommand(cmds, *argv, &nmatch);
cmd = FindCommand(cmds, argv[argn], &nmatch);
if (nmatch > 1)
LogPrintf(LogWARN, "%s%s: Ambiguous command\n", prefix, *argv);
LogPrintf(LogWARN, "%s: Ambiguous command\n",
mkPrefix(argn+1, argv, prefix, sizeof prefix));
else if (cmd && (!prompt || (cmd->lauth & prompt->auth))) {
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);
LogPrintf(LogWARN, "%s: No context (use the `link' command)\n",
mkPrefix(argn+1, argv, prefix, sizeof prefix));
else {
if (cx && !(cmd->lauth & (LOCAL_CX|LOCAL_CX_OPT))) {
LogPrintf(LogWARN, "%s%s: Redundant context (%s) ignored\n",
prefix, *argv, cx->name);
LogPrintf(LogWARN, "%s: Redundant context (%s) ignored\n",
mkPrefix(argn+1, argv, prefix, sizeof prefix), cx->name);
cx = NULL;
}
arg.cmdtab = cmds;
arg.cmd = cmd;
arg.argc = argc-1;
arg.argv = argv+1;
arg.argc = argc;
arg.argn = argn+1;
arg.argv = argv;
arg.bundle = bundle;
arg.cx = cx;
arg.prompt = prompt;
val = (cmd->func) (&arg);
val = (*cmd->func) (&arg);
}
} else
LogPrintf(LogWARN, "%s%s: Invalid command\n", prefix, *argv);
LogPrintf(LogWARN, "%s: Invalid command\n",
mkPrefix(argn+1, argv, prefix, sizeof prefix));
if (val == -1)
LogPrintf(LogWARN, "Usage: %s\n", cmd->syntax);
else if (val)
LogPrintf(LogWARN, "%s%s: Failed %d\n", prefix, *argv, val);
LogPrintf(LogWARN, "%s: Failed %d\n",
mkPrefix(argn+1, argv, prefix, sizeof prefix), val);
return val;
}
@ -684,7 +707,7 @@ RunCommand(struct bundle *bundle, int argc, char const *const *argv,
}
LogPrintf(LogCOMMAND, "%s\n", buf);
}
FindExec(bundle, Commands, argc, argv, "", prompt, NULL);
FindExec(bundle, Commands, argc, 0, argv, prompt, NULL);
}
}
@ -704,8 +727,8 @@ ShowCommand(struct cmdargs const *arg)
{
if (!arg->prompt)
LogPrintf(LogWARN, "show: Cannot show without a prompt\n");
else if (arg->argc > 0)
FindExec(arg->bundle, ShowCommands, arg->argc, arg->argv, "show ",
else if (arg->argc > arg->argn)
FindExec(arg->bundle, ShowCommands, arg->argc, arg->argn, arg->argv,
arg->prompt, arg->cx);
else
prompt_Printf(arg->prompt, "Use ``show ?'' to get a list.\n");
@ -736,7 +759,7 @@ static int
QuitCommand(struct cmdargs const *arg)
{
if (!arg->prompt || prompt_IsController(arg->prompt) ||
(arg->argc > 0 && !strcasecmp(*arg->argv, "all") &&
(arg->argc > arg->argn && !strcasecmp(arg->argv[arg->argn], "all") &&
(arg->prompt->auth & LOCAL_AUTH)))
Cleanup(EX_NORMAL);
if (arg->prompt)
@ -765,24 +788,25 @@ SetModemSpeed(struct cmdargs const *arg)
long speed;
char *end;
if (arg->argc > 0 && **arg->argv) {
if (arg->argc > 1) {
if (arg->argc > arg->argn && *arg->argv[arg->argn]) {
if (arg->argc > arg->argn+1) {
LogPrintf(LogWARN, "SetModemSpeed: Too many arguments");
return -1;
}
if (strcasecmp(*arg->argv, "sync") == 0) {
if (strcasecmp(arg->argv[arg->argn], "sync") == 0) {
Physical_SetSync(arg->cx->physical);
return 0;
}
end = NULL;
speed = strtol(*arg->argv, &end, 10);
speed = strtol(arg->argv[arg->argn], &end, 10);
if (*end) {
LogPrintf(LogWARN, "SetModemSpeed: Bad argument \"%s\"", *arg->argv);
LogPrintf(LogWARN, "SetModemSpeed: Bad argument \"%s\"",
arg->argv[arg->argn]);
return -1;
}
if (Physical_SetSpeed(arg->cx->physical, speed))
return 0;
LogPrintf(LogWARN, "%s: Invalid speed\n", *arg->argv);
LogPrintf(LogWARN, "%s: Invalid speed\n", arg->argv[arg->argn]);
} else
LogPrintf(LogWARN, "SetModemSpeed: No speed specified\n");
@ -796,11 +820,11 @@ SetStoppedTimeout(struct cmdargs const *arg)
l->lcp.fsm.StoppedTimer.load = 0;
l->ccp.fsm.StoppedTimer.load = 0;
if (arg->argc <= 2) {
if (arg->argc > 0) {
l->lcp.fsm.StoppedTimer.load = atoi(arg->argv[0]) * SECTICKS;
if (arg->argc > 1)
l->ccp.fsm.StoppedTimer.load = atoi(arg->argv[1]) * SECTICKS;
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;
}
return 0;
}
@ -815,17 +839,17 @@ SetServer(struct cmdargs const *arg)
{
int res = -1;
if (arg->argc > 0 && arg->argc < 4) {
if (arg->argc > arg->argn && arg->argc < arg->argn+4) {
const char *port, *passwd, *mask;
/* What's what ? */
port = arg->argv[0];
if (arg->argc == 2) {
passwd = arg->argv[1];
port = arg->argv[arg->argn];
if (arg->argc == arg->argn + 2) {
passwd = arg->argv[arg->argn+1];
mask = NULL;
} else if (arg->argc == 3) {
passwd = arg->argv[1];
mask = arg->argv[2];
} else if (arg->argc == arg->argn + 3) {
passwd = arg->argv[arg->argn+1];
mask = arg->argv[arg->argn+2];
if (!ismask(mask))
return -1;
} else if (strcasecmp(port, "none") == 0) {
@ -877,15 +901,16 @@ SetServer(struct cmdargs const *arg)
static int
SetModemParity(struct cmdargs const *arg)
{
return arg->argc > 0 ? modem_SetParity(arg->cx->physical, *arg->argv) : -1;
return arg->argc > arg->argn ? modem_SetParity(arg->cx->physical,
arg->argv[arg->argn]) : -1;
}
static int
SetEscape(struct cmdargs const *arg)
{
int code;
int argc = arg->argc;
char const *const *argv = arg->argv;
int argc = arg->argc - arg->argn;
char const *const *argv = arg->argv + arg->argn;
for (code = 0; code < 33; code++)
arg->cx->physical->async.cfg.EscMap[code] = 0;
@ -925,23 +950,24 @@ SetInterfaceAddr(struct cmdargs const *arg)
ipcp->cfg.my_range.ipaddr.s_addr = INADDR_ANY;
ipcp->cfg.peer_range.ipaddr.s_addr = INADDR_ANY;
if (arg->argc > 4)
if (arg->argc > arg->argn + 4)
return -1;
ipcp->cfg.HaveTriggerAddress = 0;
ipcp->cfg.netmask.s_addr = INADDR_ANY;
iplist_reset(&ipcp->cfg.peer_list);
if (arg->argc > 0) {
if (!ParseAddr(ipcp, arg->argc, arg->argv, &ipcp->cfg.my_range.ipaddr,
&ipcp->cfg.my_range.mask, &ipcp->cfg.my_range.width))
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))
return 1;
if (arg->argc > 1) {
hisaddr = arg->argv[1];
if (arg->argc > 2) {
ipcp->cfg.netmask = GetIpAddr(arg->argv[2]);
if (arg->argc > 3) {
ipcp->cfg.TriggerAddress = GetIpAddr(arg->argv[3]);
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]);
ipcp->cfg.HaveTriggerAddress = 1;
}
}
@ -1001,7 +1027,8 @@ static int
SetNS(struct cmdargs const *arg)
{
SetMSEXT(&arg->bundle->ncp.ipcp, &arg->bundle->ncp.ipcp.cfg.ns_entries[0],
&arg->bundle->ncp.ipcp.cfg.ns_entries[1], arg->argc, arg->argv);
&arg->bundle->ncp.ipcp.cfg.ns_entries[1], arg->argc - arg->argn,
arg->argv + arg->argn);
return 0;
}
@ -1009,7 +1036,8 @@ static int
SetNBNS(struct cmdargs const *arg)
{
SetMSEXT(&arg->bundle->ncp.ipcp, &arg->bundle->ncp.ipcp.cfg.nbns_entries[0],
&arg->bundle->ncp.ipcp.cfg.nbns_entries[1], arg->argc, arg->argv);
&arg->bundle->ncp.ipcp.cfg.nbns_entries[1], arg->argc - arg->argn,
arg->argv + arg->argn);
return 0;
}
@ -1025,8 +1053,8 @@ SetVariable(struct cmdargs const *arg)
const char *err = NULL;
struct link *l = ChooseLink(arg); /* AUTH_CX_OPT uses this */
if (arg->argc > 0)
argp = *arg->argv;
if (arg->argc > arg->argn)
argp = arg->argv[arg->argn];
else
argp = "";
@ -1070,16 +1098,16 @@ SetVariable(struct cmdargs const *arg)
cx->cfg.script.login[sizeof cx->cfg.script.login - 1] = '\0';
break;
case VAR_WINSIZE:
if (arg->argc > 0) {
l->ccp.cfg.deflate.out.winsize = atoi(arg->argv[0]);
if (arg->argc > arg->argn) {
l->ccp.cfg.deflate.out.winsize = atoi(arg->argv[arg->argn]);
if (l->ccp.cfg.deflate.out.winsize < 8 ||
l->ccp.cfg.deflate.out.winsize > 15) {
LogPrintf(LogWARN, "%d: Invalid outgoing window size\n",
l->ccp.cfg.deflate.out.winsize);
l->ccp.cfg.deflate.out.winsize = 15;
}
if (arg->argc > 1) {
l->ccp.cfg.deflate.in.winsize = atoi(arg->argv[1]);
if (arg->argc > arg->argn+1) {
l->ccp.cfg.deflate.in.winsize = atoi(arg->argv[arg->argn+1]);
if (l->ccp.cfg.deflate.in.winsize < 8 ||
l->ccp.cfg.deflate.in.winsize > 15) {
LogPrintf(LogWARN, "%d: Invalid incoming window size\n",
@ -1094,10 +1122,11 @@ SetVariable(struct cmdargs const *arg)
}
break;
case VAR_DEVICE:
Physical_SetDeviceList(cx->physical, arg->argc, arg->argv);
Physical_SetDeviceList(cx->physical, arg->argc - arg->argn,
arg->argv + arg->argn);
break;
case VAR_ACCMAP:
if (arg->argc > 0) {
if (arg->argc > arg->argn) {
sscanf(argp, "%lx", &ulong_val);
cx->physical->link.lcp.cfg.accmap = ulong_val;
} else {
@ -1131,8 +1160,8 @@ SetVariable(struct cmdargs const *arg)
break;
case VAR_OPENMODE:
if (strcasecmp(argp, "active") == 0)
cx->physical->link.lcp.cfg.openmode = arg->argc > 1 ?
atoi(arg->argv[1]) : 1;
cx->physical->link.lcp.cfg.openmode = arg->argc > arg->argn+1 ?
atoi(arg->argv[arg->argn+1]) : 1;
else if (strcasecmp(argp, "passive") == 0)
cx->physical->link.lcp.cfg.openmode = OPEN_PASSIVE;
else {
@ -1149,9 +1178,9 @@ SetVariable(struct cmdargs const *arg)
cx->cfg.script.hangup[sizeof cx->cfg.script.hangup - 1] = '\0';
break;
case VAR_IDLETIMEOUT:
if (arg->argc > 1)
if (arg->argc > arg->argn+1)
err = "Too many idle timeout values\n";
else if (arg->argc == 1)
else if (arg->argc == arg->argn+1)
bundle_SetIdleTimer(arg->bundle, atoi(argp));
if (err)
LogPrintf(LogWARN, err);
@ -1212,10 +1241,10 @@ SetVariable(struct cmdargs const *arg)
static int
SetCtsRts(struct cmdargs const *arg)
{
if (arg->argc == 1) {
if (strcmp(*arg->argv, "on") == 0)
if (arg->argc == arg->argn+1) {
if (strcmp(arg->argv[arg->argn], "on") == 0)
Physical_SetRtsCts(arg->cx->physical, 1);
else if (strcmp(*arg->argv, "off") == 0)
else if (strcmp(arg->argv[arg->argn], "off") == 0)
Physical_SetRtsCts(arg->cx->physical, 0);
else
return -1;
@ -1308,8 +1337,8 @@ static struct cmdtab const SetCommands[] = {
static int
SetCommand(struct cmdargs const *arg)
{
if (arg->argc > 0)
FindExec(arg->bundle, SetCommands, arg->argc, arg->argv, "set ",
if (arg->argc > arg->argn)
FindExec(arg->bundle, SetCommands, arg->argc, arg->argn, arg->argv,
arg->prompt, arg->cx);
else if (arg->prompt)
prompt_Printf(arg->prompt, "Use `set ?' to get a list or `set ? <var>' for"
@ -1327,32 +1356,32 @@ AddCommand(struct cmdargs const *arg)
struct in_addr dest, gateway, netmask;
int gw;
if (arg->argc != 3 && arg->argc != 2)
if (arg->argc != arg->argn+3 && arg->argc != arg->argn+2)
return -1;
if (arg->argc == 2)
if (strcasecmp(arg->argv[0], "default"))
if (arg->argc == arg->argn+2)
if (strcasecmp(arg->argv[arg->argn], "default"))
return -1;
else {
dest.s_addr = netmask.s_addr = INADDR_ANY;
gw = 1;
}
else {
if (strcasecmp(arg->argv[0], "MYADDR") == 0)
if (strcasecmp(arg->argv[arg->argn], "MYADDR") == 0)
dest = arg->bundle->ncp.ipcp.my_ip;
else if (strcasecmp(arg->argv[0], "HISADDR") == 0)
else if (strcasecmp(arg->argv[arg->argn], "HISADDR") == 0)
dest = arg->bundle->ncp.ipcp.peer_ip;
else
dest = GetIpAddr(arg->argv[0]);
netmask = GetIpAddr(arg->argv[1]);
dest = GetIpAddr(arg->argv[arg->argn]);
netmask = GetIpAddr(arg->argv[arg->argn+1]);
gw = 2;
}
if (strcasecmp(arg->argv[gw], "HISADDR") == 0)
if (strcasecmp(arg->argv[arg->argn+gw], "HISADDR") == 0)
gateway = arg->bundle->ncp.ipcp.peer_ip;
else if (strcasecmp(arg->argv[gw], "INTERFACE") == 0)
else if (strcasecmp(arg->argv[arg->argn+gw], "INTERFACE") == 0)
gateway.s_addr = INADDR_ANY;
else
gateway = GetIpAddr(arg->argv[gw]);
gateway = GetIpAddr(arg->argv[arg->argn+gw]);
bundle_SetRoute(arg->bundle, RTM_ADD, dest, gateway, netmask,
arg->cmd->args ? 1 : 0);
return 0;
@ -1363,16 +1392,16 @@ DeleteCommand(struct cmdargs const *arg)
{
struct in_addr dest, none;
if (arg->argc == 1)
if(strcasecmp(arg->argv[0], "all") == 0)
if (arg->argc == arg->argn+1)
if(strcasecmp(arg->argv[arg->argn], "all") == 0)
DeleteIfRoutes(arg->bundle, 0);
else {
if (strcasecmp(arg->argv[0], "MYADDR") == 0)
if (strcasecmp(arg->argv[arg->argn], "MYADDR") == 0)
dest = arg->bundle->ncp.ipcp.my_ip;
else if (strcasecmp(arg->argv[0], "default") == 0)
else if (strcasecmp(arg->argv[arg->argn], "default") == 0)
dest.s_addr = INADDR_ANY;
else
dest = GetIpAddr(arg->argv[0]);
dest = GetIpAddr(arg->argv[arg->argn]);
none.s_addr = INADDR_ANY;
bundle_SetRoute(arg->bundle, RTM_DELETE, dest, none, none,
arg->cmd->args ? 1 : 0);
@ -1417,8 +1446,8 @@ static struct cmdtab const AliasCommands[] =
static int
AliasCommand(struct cmdargs const *arg)
{
if (arg->argc > 0)
FindExec(arg->bundle, AliasCommands, arg->argc, arg->argv, "alias ",
if (arg->argc > arg->argn)
FindExec(arg->bundle, AliasCommands, arg->argc, arg->argn, arg->argv,
arg->prompt, arg->cx);
else if (arg->prompt)
prompt_Printf(arg->prompt, "Use `alias help' to get a list or `alias help"
@ -1432,13 +1461,13 @@ AliasCommand(struct cmdargs const *arg)
static int
AliasEnable(struct cmdargs const *arg)
{
if (arg->argc == 1)
if (strcasecmp(arg->argv[0], "yes") == 0) {
if (arg->argc == arg->argn+1)
if (strcasecmp(arg->argv[arg->argn], "yes") == 0) {
if (loadAliasHandlers() == 0)
return 0;
LogPrintf(LogWARN, "Cannot load alias library\n");
return 1;
} else if (strcasecmp(arg->argv[0], "no") == 0) {
} else if (strcasecmp(arg->argv[arg->argn], "no") == 0) {
unloadAliasHandlers();
return 0;
}
@ -1450,14 +1479,14 @@ static int
AliasOption(struct cmdargs const *arg)
{
unsigned param = (unsigned)arg->cmd->args;
if (arg->argc == 1)
if (strcasecmp(arg->argv[0], "yes") == 0) {
if (arg->argc == arg->argn+1)
if (strcasecmp(arg->argv[arg->argn], "yes") == 0) {
if (AliasEnabled()) {
(*PacketAlias.SetMode)(param, param);
return 0;
}
LogPrintf(LogWARN, "alias not enabled\n");
} else if (strcmp(arg->argv[0], "no") == 0) {
} else if (strcmp(arg->argv[arg->argn], "no") == 0) {
if (AliasEnabled()) {
(*PacketAlias.SetMode)(0, param);
return 0;
@ -1482,8 +1511,8 @@ static int
AllowCommand(struct cmdargs const *arg)
{
/* arg->bundle may be NULL (see ValidSystem()) ! */
if (arg->argc > 0)
FindExec(arg->bundle, AllowCommands, arg->argc, arg->argv, "allow ",
if (arg->argc > arg->argn)
FindExec(arg->bundle, AllowCommands, arg->argc, arg->argn, arg->argv,
arg->prompt, arg->cx);
else if (arg->prompt)
prompt_Printf(arg->prompt, "Use `allow ?' to get a list or `allow ? <cmd>'"
@ -1497,13 +1526,13 @@ AllowCommand(struct cmdargs const *arg)
static int
LinkCommand(struct cmdargs const *arg)
{
if (arg->argc > 1) {
struct datalink *cx = bundle2datalink(arg->bundle, arg->argv[0]);
if (arg->argc > arg->argn+1) {
struct datalink *cx = bundle2datalink(arg->bundle, arg->argv[arg->argn]);
if (cx)
FindExec(arg->bundle, Commands, arg->argc - 1, arg->argv + 1, "",
FindExec(arg->bundle, Commands, arg->argc, arg->argn+1, arg->argv,
arg->prompt, cx);
else {
LogPrintf(LogWARN, "link: %s: Invalid link name\n", arg->argv[0]);
LogPrintf(LogWARN, "link: %s: Invalid link name\n", arg->argv[arg->argn]);
return 1;
}
} else {

View File

@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: command.h,v 1.12.2.8 1998/04/03 19:25:26 brian Exp $
* $Id: command.h,v 1.12.2.9 1998/04/07 00:53:34 brian Exp $
*
* TODO:
*/
@ -29,6 +29,7 @@ struct cmdargs {
struct cmdtab const *cmdtab; /* The entire command table */
struct cmdtab const *cmd; /* This command entry */
int argc; /* Number of arguments (excluding cmd */
int argn; /* Argument to start processing from */
char const *const *argv; /* Arguments */
struct bundle *bundle; /* Our bundle */
struct datalink *cx; /* Our context */

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: datalink.c,v 1.1.2.35 1998/04/07 00:53:35 brian Exp $
* $Id: datalink.c,v 1.1.2.36 1998/04/10 13:19:05 brian Exp $
*/
#include <sys/types.h>
@ -748,9 +748,9 @@ datalink_Show(struct datalink *dl, struct prompt *prompt)
int
datalink_SetReconnect(struct cmdargs const *arg)
{
if (arg->argc == 2) {
arg->cx->cfg.reconnect.timeout = atoi(arg->argv[0]);
arg->cx->cfg.reconnect.max = atoi(arg->argv[1]);
if (arg->argc == arg->argn+2) {
arg->cx->cfg.reconnect.timeout = atoi(arg->argv[arg->argn]);
arg->cx->cfg.reconnect.max = atoi(arg->argv[arg->argn+1]);
return 0;
}
return -1;
@ -763,13 +763,13 @@ datalink_SetRedial(struct cmdargs const *arg)
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] == '.')) {
if (arg->argc == arg->argn+1 || arg->argc == arg->argn+2) {
if (strncasecmp(arg->argv[arg->argn], "random", 6) == 0 &&
(arg->argv[arg->argn][6] == '\0' || arg->argv[arg->argn][6] == '.')) {
arg->cx->cfg.dial.timeout = -1;
randinit();
} else {
timeout = atoi(arg->argv[0]);
timeout = atoi(arg->argv[arg->argn]);
if (timeout >= 0)
arg->cx->cfg.dial.timeout = timeout;
@ -779,7 +779,7 @@ datalink_SetRedial(struct cmdargs const *arg)
}
}
dot = strchr(arg->argv[0], '.');
dot = strchr(arg->argv[arg->argn], '.');
if (dot) {
if (strcasecmp(++dot, "random") == 0) {
arg->cx->cfg.dial.next_timeout = -1;
@ -797,8 +797,8 @@ datalink_SetRedial(struct cmdargs const *arg)
/* Default next timeout */
arg->cx->cfg.dial.next_timeout = DIAL_NEXT_TIMEOUT;
if (arg->argc == 2) {
tries = atoi(arg->argv[1]);
if (arg->argc == arg->argn+2) {
tries = atoi(arg->argv[arg->argn+1]);
if (tries >= 0) {
arg->cx->cfg.dial.max = tries;

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: filter.c,v 1.22.2.13 1998/04/06 09:12:27 brian Exp $
* $Id: filter.c,v 1.22.2.14 1998/04/07 00:53:39 brian Exp $
*
* TODO: Shoud send ICMP error message when we discard packets.
*/
@ -374,21 +374,22 @@ SetFilter(struct cmdargs const *arg)
{
struct filter *filter;
if (arg->argc < 2)
if (arg->argc < arg->argn+2)
return -1;
if (!strcmp(arg->argv[0], "in"))
if (!strcmp(arg->argv[arg->argn], "in"))
filter = &arg->bundle->filter.in;
else if (!strcmp(arg->argv[0], "out"))
else if (!strcmp(arg->argv[arg->argn], "out"))
filter = &arg->bundle->filter.out;
else if (!strcmp(arg->argv[0], "dial"))
else if (!strcmp(arg->argv[arg->argn], "dial"))
filter = &arg->bundle->filter.dial;
else if (!strcmp(arg->argv[0], "alive"))
else if (!strcmp(arg->argv[arg->argn], "alive"))
filter = &arg->bundle->filter.alive;
else
return -1;
Parse(&arg->bundle->ncp.ipcp, arg->argc - 1, arg->argv + 1, filter->rule);
Parse(&arg->bundle->ncp.ipcp, arg->argc - arg->argn - 1,
arg->argv + arg->argn + 1, filter->rule);
return 0;
}
@ -436,19 +437,19 @@ doShowFilter(struct filterent *fp, struct prompt *prompt)
int
ShowFilter(struct cmdargs const *arg)
{
if (arg->argc > 1)
if (arg->argc > arg->argn+1)
return -1;
if (arg->argc == 1) {
if (arg->argc == arg->argn+1) {
struct filter *filter;
if (!strcmp(arg->argv[0], "in"))
if (!strcmp(arg->argv[arg->argn], "in"))
filter = &arg->bundle->filter.in;
else if (!strcmp(arg->argv[0], "out"))
else if (!strcmp(arg->argv[arg->argn], "out"))
filter = &arg->bundle->filter.out;
else if (!strcmp(arg->argv[0], "dial"))
else if (!strcmp(arg->argv[arg->argn], "dial"))
filter = &arg->bundle->filter.dial;
else if (!strcmp(arg->argv[0], "alive"))
else if (!strcmp(arg->argv[arg->argn], "alive"))
filter = &arg->bundle->filter.alive;
else
return -1;

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: ipcp.c,v 1.50.2.34 1998/04/07 23:45:55 brian Exp $
* $Id: ipcp.c,v 1.50.2.35 1998/04/10 13:19:08 brian Exp $
*
* TODO:
* o More RFC1772 backwoard compatibility
@ -180,20 +180,20 @@ ReportIpcpStatus(struct cmdargs const *arg)
int
SetInitVJ(struct cmdargs const *arg)
{
if (arg->argc != 2)
if (arg->argc != arg->argn+2)
return -1;
if (!strcasecmp(arg->argv[0], "slots")) {
if (!strcasecmp(arg->argv[arg->argn], "slots")) {
int slots;
slots = atoi(arg->argv[1]);
slots = atoi(arg->argv[arg->argn+1]);
if (slots < 4 || slots > 16)
return 1;
arg->bundle->ncp.ipcp.cfg.VJInitSlots = slots;
return 0;
} else if (!strcasecmp(arg->argv[0], "slotcomp")) {
if (!strcasecmp(arg->argv[1], "on"))
} else if (!strcasecmp(arg->argv[arg->argn], "slotcomp")) {
if (!strcasecmp(arg->argv[arg->argn+1], "on"))
arg->bundle->ncp.ipcp.cfg.VJInitComp = 1;
else if (!strcasecmp(arg->argv[1], "off"))
else if (!strcasecmp(arg->argv[arg->argn+1], "off"))
arg->bundle->ncp.ipcp.cfg.VJInitComp = 0;
else
return 2;

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: log.c,v 1.25.2.6 1998/04/07 00:54:00 brian Exp $
* $Id: log.c,v 1.25.2.7 1998/04/10 13:19:10 brian Exp $
*/
#include <sys/types.h>
@ -327,8 +327,8 @@ log_SetLevel(struct cmdargs const *arg)
int i, res, argc, local;
char const *const *argv, *argp;
argc = arg->argc;
argv = arg->argv;
argc = arg->argc - arg->argn;
argv = arg->argv + arg->argn;
res = 0;
if (argc == 0 || strcasecmp(argv[0], "local"))

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: mp.c,v 1.1.2.1 1998/04/03 19:21:44 brian Exp $
* $Id: mp.c,v 1.1.2.2 1998/04/06 09:12:34 brian Exp $
*/
#include <sys/types.h>
@ -441,10 +441,10 @@ mp_SetDatalinkWeight(struct cmdargs const *arg)
{
int val;
if (arg->argc != 1)
if (arg->argc != arg->argn+1)
return -1;
val = atoi(arg->argv[0]);
val = atoi(arg->argv[arg->argn]);
if (val < LINK_MINWEIGHT) {
LogPrintf(LogWARN, "Link weights must not be less than %d\n",
LINK_MINWEIGHT);

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: prompt.c,v 1.1.2.24 1998/04/08 18:27:29 brian Exp $
* $Id: prompt.c,v 1.1.2.25 1998/04/10 13:19:18 brian Exp $
*/
#include <sys/param.h>
@ -469,12 +469,12 @@ PasswdCommand(struct cmdargs const *arg)
return 0;
}
if (arg->argc == 0)
if (arg->argc == arg->argn)
pass = "";
else if (arg->argc > 1)
else if (arg->argc > arg->argn+1)
return -1;
else
pass = *arg->argv;
pass = arg->argv[arg->argn];
if (!strcmp(arg->prompt->owner->passwd, pass))
arg->prompt->auth = LOCAL_AUTH;

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: systems.c,v 1.35.2.5 1998/04/06 09:12:37 brian Exp $
* $Id: systems.c,v 1.35.2.6 1998/04/10 13:19:21 brian Exp $
*
* TODO:
*/
@ -172,7 +172,7 @@ AllowUsers(struct cmdargs const *arg)
userok = 0;
user = getlogin();
if (user && *user)
for (f = 0; f < arg->argc; f++)
for (f = arg->argn; f < arg->argc; f++)
if (!strcmp("*", arg->argv[f]) || !strcmp(user, arg->argv[f])) {
userok = 1;
break;
@ -216,7 +216,7 @@ AllowModes(struct cmdargs const *arg)
int allowed;
allowed = 0;
for (f = 0; f < arg->argc; f++) {
for (f = arg->argn; f < arg->argc; f++) {
for (m = 0; modes[m].mode; m++)
if (!strcasecmp(modes[m].name, arg->argv[f])) {
allowed |= modes[m].mode;

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: vars.c,v 1.45.2.25 1998/04/06 09:12:38 brian Exp $
* $Id: vars.c,v 1.45.2.26 1998/04/07 00:54:24 brian Exp $
*
*/
#include <sys/types.h>
@ -78,9 +78,9 @@ ConfigCommand(struct cmdargs const *arg, int mine, int val)
{
int f;
int err;
int narg = 0;
int narg = arg->argn;
if (arg->argc < 1)
if (arg->argc < narg+1)
return -1;
err = 0;