Deleted Added
sdiff udiff text old ( 40482 ) new ( 40561 )
full compact
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.166 1998/09/17 00:45:26 brian Exp $
21 *
22 */
23#include <sys/types.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>

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

78#include "mp.h"
79#include "bundle.h"
80#include "server.h"
81#include "prompt.h"
82#include "chat.h"
83#include "chap.h"
84#include "cbcp.h"
85#include "datalink.h"
86
87/* ``set'' values */
88#define VAR_AUTHKEY 0
89#define VAR_DIAL 1
90#define VAR_LOGIN 2
91#define VAR_AUTHNAME 3
92#define VAR_AUTOLOAD 4
93#define VAR_WINSIZE 5

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

126#define NEG_PPPDDEFLATE 45
127#define NEG_PRED1 46
128#define NEG_PROTOCOMP 47
129#define NEG_SHORTSEQ 48
130#define NEG_VJCOMP 49
131#define NEG_DNS 50
132
133const char Version[] = "2.0";
134const char VersionDate[] = "$Date: 1998/09/17 00:45:26 $";
135
136static int ShowCommand(struct cmdargs const *);
137static int TerminalCommand(struct cmdargs const *);
138static int QuitCommand(struct cmdargs const *);
139static int OpenCommand(struct cmdargs const *);
140static int CloseCommand(struct cmdargs const *);
141static int DownCommand(struct cmdargs const *);
142static int AllowCommand(struct cmdargs const *);
143static int SetCommand(struct cmdargs const *);
144static int LinkCommand(struct cmdargs const *);
145static int AddCommand(struct cmdargs const *);
146static int DeleteCommand(struct cmdargs const *);
147static int NegotiateCommand(struct cmdargs const *);
148static int ClearCommand(struct cmdargs const *);
149#ifndef NOALIAS
150static int AliasCommand(struct cmdargs const *);
151static int AliasEnable(struct cmdargs const *);
152static int AliasOption(struct cmdargs const *);
153#endif
154
155static const char *
156showcx(struct cmdtab const *cmd)
157{
158 if (cmd->lauth & LOCAL_CX)

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

381 int arg;
382
383 nargv[0] = strdup(oargv[0]);
384 for (arg = 1; arg < argc; arg++) {
385 nargv[arg] = strdup(oargv[arg]);
386 nargv[arg] = subst(nargv[arg], "HISADDR",
387 inet_ntoa(bundle->ncp.ipcp.peer_ip));
388 nargv[arg] = subst(nargv[arg], "AUTHNAME", bundle->cfg.auth.name);
389 nargv[arg] = subst(nargv[arg], "INTERFACE", bundle->ifp.Name);
390 nargv[arg] = subst(nargv[arg], "MYADDR", inet_ntoa(bundle->ncp.ipcp.my_ip));
391 nargv[arg] = subst(nargv[arg], "USER", bundle->ncp.mp.peer.authname);
392 nargv[arg] = subst(nargv[arg], "PEER_ENDDISC",
393 mp_Enddisc(bundle->ncp.mp.peer.enddisc.class,
394 bundle->ncp.mp.peer.enddisc.address,
395 bundle->ncp.mp.peer.enddisc.len));
396 nargv[arg] = subst(nargv[arg], "ENDDISC",
397 mp_Enddisc(bundle->ncp.mp.cfg.enddisc.class,

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

508}
509
510static int
511FgShellCommand(struct cmdargs const *arg)
512{
513 return ShellCommand(arg, 0);
514}
515
516static struct cmdtab const Commands[] = {
517 {"accept", NULL, NegotiateCommand, LOCAL_AUTH | LOCAL_CX_OPT,
518 "accept option request", "accept option .."},
519 {"add", NULL, AddCommand, LOCAL_AUTH,
520 "add route", "add dest mask gateway", NULL},
521 {NULL, "add!", AddCommand, LOCAL_AUTH,
522 "add or change route", "add! dest mask gateway", (void *)1},
523#ifndef NOALIAS
524 {"alias", NULL, AliasCommand, LOCAL_AUTH,
525 "alias control", "alias option [yes|no]"},
526#endif
527 {"allow", "auth", AllowCommand, LOCAL_AUTH,
528 "Allow ppp access", "allow users|modes ...."},
529 {"bg", "!bg", BgShellCommand, LOCAL_AUTH,
530 "Run a background command", "[!]bg command"},
531 {"clear", NULL, ClearCommand, LOCAL_AUTH | LOCAL_CX_OPT,
532 "Clear throughput statistics", "clear ipcp|modem [current|overall|peak]..."},
533 {"clone", NULL, CloneCommand, LOCAL_AUTH | LOCAL_CX,
534 "Clone a link", "clone newname..."},
535 {"close", NULL, CloseCommand, LOCAL_AUTH | LOCAL_CX_OPT,
536 "Close an FSM", "close [lcp|ccp]"},

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

543 {"dial", "call", DialCommand, LOCAL_AUTH | LOCAL_CX_OPT,
544 "Dial and login", "dial|call [remote]", NULL},
545 {"disable", NULL, NegotiateCommand, LOCAL_AUTH | LOCAL_CX_OPT,
546 "Disable option", "disable option .."},
547 {"down", NULL, DownCommand, LOCAL_AUTH | LOCAL_CX_OPT,
548 "Generate a down event", "down"},
549 {"enable", NULL, NegotiateCommand, LOCAL_AUTH | LOCAL_CX_OPT,
550 "Enable option", "enable option .."},
551 {"link", "datalink", LinkCommand, LOCAL_AUTH,
552 "Link specific commands", "link name command ..."},
553 {"load", NULL, LoadCommand, LOCAL_AUTH | LOCAL_CX_OPT,
554 "Load settings", "load [remote]"},
555 {"open", NULL, OpenCommand, LOCAL_AUTH | LOCAL_CX_OPT,
556 "Open an FSM", "open! [lcp|ccp|ipcp]", (void *)1},
557 {"passwd", NULL, PasswdCommand, LOCAL_NO_AUTH,
558 "Password for manipulation", "passwd LocalPassword"},

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

650 {"compress", NULL, sl_Show, LOCAL_AUTH,
651 "VJ compression stats", "show compress"},
652 {"escape", NULL, ShowEscape, LOCAL_AUTH | LOCAL_CX,
653 "escape characters", "show escape"},
654 {"filter", NULL, filter_Show, LOCAL_AUTH,
655 "packet filters", "show filter [in|out|dial|alive]"},
656 {"hdlc", NULL, hdlc_ReportStatus, LOCAL_AUTH | LOCAL_CX,
657 "HDLC errors", "show hdlc"},
658 {"ipcp", NULL, ipcp_Show, LOCAL_AUTH,
659 "IPCP status", "show ipcp"},
660 {"lcp", NULL, lcp_ReportStatus, LOCAL_AUTH | LOCAL_CX,
661 "LCP status", "show lcp"},
662 {"link", "datalink", datalink_Show, LOCAL_AUTH | LOCAL_CX,
663 "(high-level) link info", "show link"},
664 {"links", NULL, bundle_ShowLinks, LOCAL_AUTH,
665 "available link names", "show links"},

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

1195}
1196
1197static int
1198SetInterfaceAddr(struct cmdargs const *arg)
1199{
1200 struct ipcp *ipcp = &arg->bundle->ncp.ipcp;
1201 const char *hisaddr;
1202
1203 hisaddr = NULL;
1204 ipcp->cfg.my_range.ipaddr.s_addr = INADDR_ANY;
1205 ipcp->cfg.peer_range.ipaddr.s_addr = INADDR_ANY;
1206
1207 if (arg->argc > arg->argn + 4)
1208 return -1;
1209
1210 ipcp->cfg.HaveTriggerAddress = 0;
1211 ipcp->cfg.netmask.s_addr = INADDR_ANY;
1212 iplist_reset(&ipcp->cfg.peer_list);
1213
1214 if (arg->argc > arg->argn) {
1215 if (!ParseAddr(ipcp, arg->argc - arg->argn, arg->argv + arg->argn,
1216 &ipcp->cfg.my_range.ipaddr, &ipcp->cfg.my_range.mask,
1217 &ipcp->cfg.my_range.width))

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

1223 if (arg->argc > arg->argn+3) {
1224 ipcp->cfg.TriggerAddress = GetIpAddr(arg->argv[arg->argn+3]);
1225 ipcp->cfg.HaveTriggerAddress = 1;
1226 }
1227 }
1228 }
1229 }
1230
1231 /*
1232 * For backwards compatibility, 0.0.0.0 means any address.
1233 */
1234 if (ipcp->cfg.my_range.ipaddr.s_addr == INADDR_ANY) {
1235 ipcp->cfg.my_range.mask.s_addr = INADDR_ANY;
1236 ipcp->cfg.my_range.width = 0;
1237 }
1238 ipcp->my_ip.s_addr = ipcp->cfg.my_range.ipaddr.s_addr;
1239
1240 if (ipcp->cfg.peer_range.ipaddr.s_addr == INADDR_ANY) {
1241 ipcp->cfg.peer_range.mask.s_addr = INADDR_ANY;
1242 ipcp->cfg.peer_range.width = 0;
1243 }
1244
1245 if (hisaddr && !ipcp_UseHisaddr(arg->bundle, hisaddr,
1246 arg->bundle->phys_type.all & PHYS_AUTO))
1247 return 4;
1248
1249 return 0;
1250}
1251
1252static int

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

1712 prompt_Printf(arg->prompt, "Use `set ?' to get a list or `set ? <var>' for"
1713 " syntax help.\n");
1714 else
1715 log_Printf(LogWARN, "set command must have arguments\n");
1716
1717 return 0;
1718}
1719
1720
1721static int
1722AddCommand(struct cmdargs const *arg)
1723{
1724 struct in_addr dest, gateway, netmask;
1725 int gw, addrs;
1726
1727 if (arg->argc != arg->argn+3 && arg->argc != arg->argn+2)
1728 return -1;

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

1754 dest = GetIpAddr(arg->argv[arg->argn]);
1755 netmask = GetIpAddr(arg->argv[arg->argn+1]);
1756 gw = 2;
1757 }
1758
1759 if (strcasecmp(arg->argv[arg->argn+gw], "HISADDR") == 0) {
1760 gateway = arg->bundle->ncp.ipcp.peer_ip;
1761 addrs |= ROUTE_GWHISADDR;
1762 } else if (strcasecmp(arg->argv[arg->argn+gw], "INTERFACE") == 0)
1763 gateway.s_addr = INADDR_ANY;
1764 else
1765 gateway = GetIpAddr(arg->argv[arg->argn+gw]);
1766
1767 if (bundle_SetRoute(arg->bundle, RTM_ADD, dest, gateway, netmask,
1768 arg->cmd->args ? 1 : 0, (addrs & ROUTE_GWHISADDR) ? 1 : 0))
1769 route_Add(&arg->bundle->ncp.ipcp.route, addrs, dest, netmask, gateway);
1770
1771 return 0;
1772}

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

1803 }
1804 } else
1805 return -1;
1806
1807 return 0;
1808}
1809
1810#ifndef NOALIAS
1811static struct cmdtab const AliasCommands[] =
1812{
1813 {"addr", NULL, alias_RedirectAddr, LOCAL_AUTH,
1814 "static address translation", "alias addr [addr_local addr_alias]"},
1815 {"deny_incoming", NULL, AliasOption, LOCAL_AUTH,
1816 "stop incoming connections", "alias deny_incoming [yes|no]",
1817 (const void *) PKT_ALIAS_DENY_INCOMING},
1818 {"enable", NULL, AliasEnable, LOCAL_AUTH,
1819 "enable IP aliasing", "alias enable [yes|no]"},
1820 {"log", NULL, AliasOption, LOCAL_AUTH,
1821 "log aliasing link creation", "alias log [yes|no]",
1822 (const void *) PKT_ALIAS_LOG},
1823 {"port", NULL, alias_RedirectPort, LOCAL_AUTH,
1824 "port redirection", "alias port [proto addr_local:port_local port_alias]"},
1825 {"same_ports", NULL, AliasOption, LOCAL_AUTH,
1826 "try to leave port numbers unchanged", "alias same_ports [yes|no]",
1827 (const void *) PKT_ALIAS_SAME_PORTS},
1828 {"unregistered_only", NULL, AliasOption, LOCAL_AUTH,
1829 "alias unregistered (private) IP address space only",
1830 "alias unregistered_only [yes|no]",
1831 (const void *) PKT_ALIAS_UNREGISTERED_ONLY},
1832 {"use_sockets", NULL, AliasOption, LOCAL_AUTH,
1833 "allocate host sockets", "alias use_sockets [yes|no]",
1834 (const void *) PKT_ALIAS_USE_SOCKETS},
1835 {"help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
1836 "Display this message", "alias help|? [command]", AliasCommands},
1837 {NULL, NULL, NULL},
1838};
1839
1840
1841static int
1842AliasCommand(struct cmdargs const *arg)
1843{
1844 if (arg->argc > arg->argn)
1845 FindExec(arg->bundle, AliasCommands, arg->argc, arg->argn, arg->argv,
1846 arg->prompt, arg->cx);
1847 else if (arg->prompt)
1848 prompt_Printf(arg->prompt, "Use `alias help' to get a list or `alias help"
1849 " <option>' for syntax help.\n");
1850 else
1851 log_Printf(LogWARN, "alias command must have arguments\n");
1852
1853 return 0;
1854}
1855
1856static int
1857AliasEnable(struct cmdargs const *arg)
1858{
1859 if (arg->argc == arg->argn+1) {
1860 if (strcasecmp(arg->argv[arg->argn], "yes") == 0) {
1861 arg->bundle->AliasEnabled = 1;
1862 return 0;
1863 } else if (strcasecmp(arg->argv[arg->argn], "no") == 0) {
1864 arg->bundle->AliasEnabled = 0;
1865 return 0;
1866 }
1867 }
1868
1869 return -1;
1870}
1871
1872

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

1889 }
1890 log_Printf(LogWARN, "alias not enabled\n");
1891 }
1892 }
1893 return -1;
1894}
1895#endif /* #ifndef NOALIAS */
1896
1897static struct cmdtab const AllowCommands[] = {
1898 {"modes", "mode", AllowModes, LOCAL_AUTH,
1899 "Only allow certain ppp modes", "allow modes mode..."},
1900 {"users", "user", AllowUsers, LOCAL_AUTH,
1901 "Allow users access to ppp", "allow users logname..."},
1902 {"help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
1903 "Display this message", "allow help|? [command]", AllowCommands},
1904 {NULL, NULL, NULL},
1905};
1906
1907static int
1908AllowCommand(struct cmdargs const *arg)
1909{
1910 /* arg->bundle may be NULL (see system_IsValid()) ! */
1911 if (arg->argc > arg->argn)
1912 FindExec(arg->bundle, AllowCommands, arg->argc, arg->argn, arg->argv,
1913 arg->prompt, arg->cx);
1914 else if (arg->prompt)
1915 prompt_Printf(arg->prompt, "Use `allow ?' to get a list or `allow ? <cmd>'"
1916 " for syntax help.\n");
1917 else
1918 log_Printf(LogWARN, "allow command must have arguments\n");
1919
1920 return 0;
1921}
1922
1923static int
1924LinkCommand(struct cmdargs const *arg)
1925{
1926 if (arg->argc > arg->argn+1) {
1927 char namelist[LINE_LEN];
1928 struct datalink *cx;
1929 char *name;
1930 int result = 0;
1931

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

2042 if (add)
2043 arg->bundle->cfg.opt |= bit;
2044 else
2045 arg->bundle->cfg.opt &= ~bit;
2046 return 0;
2047}
2048
2049static int
2050NegotiateSet(struct cmdargs const *arg)
2051{
2052 long param = (long)arg->cmd->args;
2053 struct link *l = command_ChooseLink(arg); /* LOCAL_CX_OPT uses this */
2054 struct datalink *cx = arg->cx; /* LOCAL_CX uses this */
2055 const char *cmd;
2056 unsigned keep; /* Keep these bits */
2057 unsigned add; /* Add these bits */

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

2133 {"proxy", NULL, OptSet, LOCAL_AUTH, "Create proxy ARP entry",
2134 "disable|enable", (const void *)OPT_PROXY},
2135 {"sroutes", NULL, OptSet, LOCAL_AUTH, "Use sticky routes",
2136 "disable|enable", (const void *)OPT_SROUTES},
2137 {"throughput", NULL, OptSet, LOCAL_AUTH, "Rolling throughput",
2138 "disable|enable", (const void *)OPT_THROUGHPUT},
2139 {"utmp", NULL, OptSet, LOCAL_AUTH, "Log connections in utmp",
2140 "disable|enable", (const void *)OPT_UTMP},
2141
2142#define OPT_MAX 7 /* accept/deny allowed below and not above */
2143
2144 {"acfcomp", NULL, NegotiateSet, LOCAL_AUTH | LOCAL_CX,
2145 "Address & Control field compression", "accept|deny|disable|enable",
2146 (const void *)NEG_ACFCOMP},
2147 {"chap", NULL, NegotiateSet, LOCAL_AUTH | LOCAL_CX,
2148 "Challenge Handshake Authentication Protocol", "accept|deny|disable|enable",
2149 (const void *)NEG_CHAP},
2150 {"deflate", NULL, NegotiateSet, LOCAL_AUTH | LOCAL_CX_OPT,

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

2253 else
2254 return -1;
2255 } else
2256 clear_type = THROUGHPUT_ALL;
2257
2258 throughput_clear(t, clear_type, arg->prompt);
2259 return 0;
2260}