Deleted Added
full compact
command.c (31791) command.c (31822)
1/*
2 * PPP User command processing module
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan, Inc. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 *
1/*
2 * PPP User command processing module
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan, Inc. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 *
20 * $Id: command.c,v 1.110 1997/12/15 20:21:46 brian Exp $
20 * $Id: command.c,v 1.111 1997/12/17 00:19:22 brian Exp $
21 *
22 */
23#include <sys/param.h>
24#include <netinet/in_systm.h>
25#include <netinet/in.h>
26#include <netinet/ip.h>
27#include <arpa/inet.h>
28#include <sys/socket.h>

--- 41 unchanged lines hidden (view full) ---

70#include "main.h"
71#include "route.h"
72#include "ccp.h"
73#include "ip.h"
74#include "slcompress.h"
75#include "auth.h"
76
77struct in_addr ifnetmask;
21 *
22 */
23#include <sys/param.h>
24#include <netinet/in_systm.h>
25#include <netinet/in.h>
26#include <netinet/ip.h>
27#include <arpa/inet.h>
28#include <sys/socket.h>

--- 41 unchanged lines hidden (view full) ---

70#include "main.h"
71#include "route.h"
72#include "ccp.h"
73#include "ip.h"
74#include "slcompress.h"
75#include "auth.h"
76
77struct in_addr ifnetmask;
78static const char *HIDDEN = "********";
78
79static int ShowCommand(struct cmdargs const *arg);
80static int TerminalCommand(struct cmdargs const *arg);
81static int QuitCommand(struct cmdargs const *arg);
82static int CloseCommand(struct cmdargs const *arg);
83static int DialCommand(struct cmdargs const *arg);
84static int DownCommand(struct cmdargs const *arg);
85static int AllowCommand(struct cmdargs const *arg);

--- 396 unchanged lines hidden (view full) ---

482}
483
484static int
485ShowAuthKey(struct cmdargs const *arg)
486{
487 if (!VarTerm)
488 return 0;
489 fprintf(VarTerm, "AuthName = %s\n", VarAuthName);
79
80static int ShowCommand(struct cmdargs const *arg);
81static int TerminalCommand(struct cmdargs const *arg);
82static int QuitCommand(struct cmdargs const *arg);
83static int CloseCommand(struct cmdargs const *arg);
84static int DialCommand(struct cmdargs const *arg);
85static int DownCommand(struct cmdargs const *arg);
86static int AllowCommand(struct cmdargs const *arg);

--- 396 unchanged lines hidden (view full) ---

483}
484
485static int
486ShowAuthKey(struct cmdargs const *arg)
487{
488 if (!VarTerm)
489 return 0;
490 fprintf(VarTerm, "AuthName = %s\n", VarAuthName);
490 fprintf(VarTerm, "AuthKey = %s\n", VarAuthKey);
491 fprintf(VarTerm, "AuthKey = %s\n", HIDDEN);
491#ifdef HAVE_DES
492 fprintf(VarTerm, "Encrypt = %s\n", VarMSChap ? "MSChap" : "MD5" );
493#endif
494 return 0;
495}
496
497static int
498ShowVersion(struct cmdargs const *arg)

--- 162 unchanged lines hidden (view full) ---

661 }
662 cmds++;
663 }
664 *pmatch = nmatch;
665 return found;
666}
667
668static int
492#ifdef HAVE_DES
493 fprintf(VarTerm, "Encrypt = %s\n", VarMSChap ? "MSChap" : "MD5" );
494#endif
495 return 0;
496}
497
498static int
499ShowVersion(struct cmdargs const *arg)

--- 162 unchanged lines hidden (view full) ---

662 }
663 cmds++;
664 }
665 *pmatch = nmatch;
666 return found;
667}
668
669static int
669FindExec(struct cmdtab const *cmds, int argc, char const *const *argv)
670FindExec(struct cmdtab const *cmds, int argc, char const *const *argv,
671 const char *prefix)
670{
671 struct cmdtab const *cmd;
672 int val = 1;
673 int nmatch;
674 struct cmdargs arg;
675
676 cmd = FindCommand(cmds, *argv, &nmatch);
677 if (nmatch > 1)
672{
673 struct cmdtab const *cmd;
674 int val = 1;
675 int nmatch;
676 struct cmdargs arg;
677
678 cmd = FindCommand(cmds, *argv, &nmatch);
679 if (nmatch > 1)
678 LogPrintf(LogWARN, "%s: Ambiguous command\n", *argv);
680 LogPrintf(LogWARN, "%s%s: Ambiguous command\n", prefix, *argv);
679 else if (cmd && (cmd->lauth & VarLocalAuth)) {
680 arg.cmd = cmds;
681 arg.argc = argc-1;
682 arg.argv = argv+1;
683 arg.data = cmd->args;
684 val = (cmd->func) (&arg);
685 } else
681 else if (cmd && (cmd->lauth & VarLocalAuth)) {
682 arg.cmd = cmds;
683 arg.argc = argc-1;
684 arg.argv = argv+1;
685 arg.data = cmd->args;
686 val = (cmd->func) (&arg);
687 } else
686 LogPrintf(LogWARN, "%s: Invalid command\n", *argv);
688 LogPrintf(LogWARN, "%s%s: Invalid command\n", prefix, *argv);
687
688 if (val == -1)
689 LogPrintf(LogWARN, "Usage: %s\n", cmd->syntax);
690 else if (val)
689
690 if (val == -1)
691 LogPrintf(LogWARN, "Usage: %s\n", cmd->syntax);
692 else if (val)
691 LogPrintf(LogWARN, "%s: Failed %d\n", *argv, val);
693 LogPrintf(LogWARN, "%s%s: Failed %d\n", prefix, *argv, val);
692
693 return val;
694}
695
696int aft_cmd = 1;
697
698void
699Prompt()

--- 31 unchanged lines hidden (view full) ---

731 if (cp)
732 *cp = '\0';
733 *argc = MakeArgs(buff, vector, VECSIZE(vector));
734 *argv = vector;
735 } else
736 *argc = 0;
737}
738
694
695 return val;
696}
697
698int aft_cmd = 1;
699
700void
701Prompt()

--- 31 unchanged lines hidden (view full) ---

733 if (cp)
734 *cp = '\0';
735 *argc = MakeArgs(buff, vector, VECSIZE(vector));
736 *argv = vector;
737 } else
738 *argc = 0;
739}
740
741static int
742arghidden(int argc, char const *const *argv, int n)
743{
744 /* Is arg n of the given command to be hidden from the log ? */
745 if (n == 2 && !strncasecmp(argv[0], "se", 2) &&
746 (!strncasecmp(argv[1], "authk", 5) || !strncasecmp(argv[1], "ke", 2)))
747 return 1;
748
749 return 0;
750}
751
739void
740RunCommand(int argc, char const *const *argv, const char *label)
741{
742 if (argc > 0) {
743 if (LogIsKept(LogCOMMAND)) {
744 static char buf[LINE_LEN];
745 int f, n;
746
747 *buf = '\0';
748 if (label) {
749 strncpy(buf, label, sizeof buf);
750 buf[sizeof(buf)-3] = '\0';
751 strcat(buf, ": ");
752 }
753 n = strlen(buf);
754 for (f = 0; f < argc; f++) {
755 if (n < sizeof(buf)-1 && f)
756 buf[n++] = ' ';
752void
753RunCommand(int argc, char const *const *argv, const char *label)
754{
755 if (argc > 0) {
756 if (LogIsKept(LogCOMMAND)) {
757 static char buf[LINE_LEN];
758 int f, n;
759
760 *buf = '\0';
761 if (label) {
762 strncpy(buf, label, sizeof buf);
763 buf[sizeof(buf)-3] = '\0';
764 strcat(buf, ": ");
765 }
766 n = strlen(buf);
767 for (f = 0; f < argc; f++) {
768 if (n < sizeof(buf)-1 && f)
769 buf[n++] = ' ';
757 strncpy(buf+n, argv[f], sizeof(buf)-n-1);
770 if (arghidden(argc, argv, f))
771 strncpy(buf+n, HIDDEN, sizeof(buf)-n-1);
772 else
773 strncpy(buf+n, argv[f], sizeof(buf)-n-1);
758 n += strlen(buf+n);
759 }
760 LogPrintf(LogCOMMAND, "%s\n", buf);
761 }
774 n += strlen(buf+n);
775 }
776 LogPrintf(LogCOMMAND, "%s\n", buf);
777 }
762 FindExec(Commands, argc, argv);
778 FindExec(Commands, argc, argv, "");
763 }
764}
765
766void
767DecodeCommand(char *buff, int nb, const char *label)
768{
769 int argc;
770 char **argv;
771
772 InterpretCommand(buff, nb, &argc, &argv);
773 RunCommand(argc, (char const *const *)argv, label);
774}
775
776static int
777ShowCommand(struct cmdargs const *arg)
778{
779 if (arg->argc > 0)
779 }
780}
781
782void
783DecodeCommand(char *buff, int nb, const char *label)
784{
785 int argc;
786 char **argv;
787
788 InterpretCommand(buff, nb, &argc, &argv);
789 RunCommand(argc, (char const *const *)argv, label);
790}
791
792static int
793ShowCommand(struct cmdargs const *arg)
794{
795 if (arg->argc > 0)
780 FindExec(ShowCommands, arg->argc, arg->argv);
796 FindExec(ShowCommands, arg->argc, arg->argv, "show ");
781 else if (VarTerm)
782 fprintf(VarTerm, "Use ``show ?'' to get a arg->cmd.\n");
783 else
784 LogPrintf(LogWARN, "show command must have arguments\n");
785
786 return 0;
787}
788

--- 665 unchanged lines hidden (view full) ---

1454 "Display this message", "set help|? [command]", SetCommands},
1455 {NULL, NULL, NULL},
1456};
1457
1458static int
1459SetCommand(struct cmdargs const *arg)
1460{
1461 if (arg->argc > 0)
797 else if (VarTerm)
798 fprintf(VarTerm, "Use ``show ?'' to get a arg->cmd.\n");
799 else
800 LogPrintf(LogWARN, "show command must have arguments\n");
801
802 return 0;
803}
804

--- 665 unchanged lines hidden (view full) ---

1470 "Display this message", "set help|? [command]", SetCommands},
1471 {NULL, NULL, NULL},
1472};
1473
1474static int
1475SetCommand(struct cmdargs const *arg)
1476{
1477 if (arg->argc > 0)
1462 FindExec(SetCommands, arg->argc, arg->argv);
1478 FindExec(SetCommands, arg->argc, arg->argv, "set ");
1463 else if (VarTerm)
1464 fprintf(VarTerm, "Use `set ?' to get a arg->cmd or `set ? <var>' for"
1465 " syntax help.\n");
1466 else
1467 LogPrintf(LogWARN, "set command must have arguments\n");
1468
1469 return 0;
1470}

--- 87 unchanged lines hidden (view full) ---

1558 {NULL, NULL, NULL},
1559};
1560
1561
1562static int
1563AliasCommand(struct cmdargs const *arg)
1564{
1565 if (arg->argc > 0)
1479 else if (VarTerm)
1480 fprintf(VarTerm, "Use `set ?' to get a arg->cmd or `set ? <var>' for"
1481 " syntax help.\n");
1482 else
1483 LogPrintf(LogWARN, "set command must have arguments\n");
1484
1485 return 0;
1486}

--- 87 unchanged lines hidden (view full) ---

1574 {NULL, NULL, NULL},
1575};
1576
1577
1578static int
1579AliasCommand(struct cmdargs const *arg)
1580{
1581 if (arg->argc > 0)
1566 FindExec(AliasCommands, arg->argc, arg->argv);
1582 FindExec(AliasCommands, arg->argc, arg->argv, "alias ");
1567 else if (VarTerm)
1568 fprintf(VarTerm, "Use `alias help' to get a arg->cmd or `alias help <option>'"
1569 " for syntax help.\n");
1570 else
1571 LogPrintf(LogWARN, "alias command must have arguments\n");
1572
1573 return 0;
1574}

--- 54 unchanged lines hidden (view full) ---

1629 "Display this message", "allow help|? [command]", AllowCommands},
1630 {NULL, NULL, NULL},
1631};
1632
1633static int
1634AllowCommand(struct cmdargs const *arg)
1635{
1636 if (arg->argc > 0)
1583 else if (VarTerm)
1584 fprintf(VarTerm, "Use `alias help' to get a arg->cmd or `alias help <option>'"
1585 " for syntax help.\n");
1586 else
1587 LogPrintf(LogWARN, "alias command must have arguments\n");
1588
1589 return 0;
1590}

--- 54 unchanged lines hidden (view full) ---

1645 "Display this message", "allow help|? [command]", AllowCommands},
1646 {NULL, NULL, NULL},
1647};
1648
1649static int
1650AllowCommand(struct cmdargs const *arg)
1651{
1652 if (arg->argc > 0)
1637 FindExec(AllowCommands, arg->argc, arg->argv);
1653 FindExec(AllowCommands, arg->argc, arg->argv, "allow ");
1638 else if (VarTerm)
1639 fprintf(VarTerm, "Use `allow ?' to get a arg->cmd or `allow ? <cmd>' for"
1640 " syntax help.\n");
1641 else
1642 LogPrintf(LogWARN, "allow command must have arguments\n");
1643
1644 return 0;
1645}
1654 else if (VarTerm)
1655 fprintf(VarTerm, "Use `allow ?' to get a arg->cmd or `allow ? <cmd>' for"
1656 " syntax help.\n");
1657 else
1658 LogPrintf(LogWARN, "allow command must have arguments\n");
1659
1660 return 0;
1661}