#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <ctype.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <limits.h>
#include <stdlib.h>
#include <termios.h>
#include <syslog.h>
#include <string.h>
#include <netdb.h>
#include <pwd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#ifdef PPP_FILTER
#include <pcap.h>
#include <pcap-int.h>
#endif
#include "pppd.h"
#include "pathnames.h"
#include "patchlevel.h"
#include "fsm.h"
#include "lcp.h"
#include "ipcp.h"
#include "upap.h"
#include "chap.h"
#include "ccp.h"
#ifdef CBCP_SUPPORT
#include "cbcp.h"
#endif
#include <net/ppp-comp.h>
#define FALSE 0
#define TRUE 1
#if defined(ultrix) || defined(NeXT)
char *strdup(char *);
#endif
#ifndef GIDSET_TYPE
#define GIDSET_TYPE gid_t
#endif
#ifdef PPP_FILTER
int dflag = 0;
#endif
int debug = 0;
int kdebugflag = 0;
int default_device = 1;
char devnam[PATH_MAX] = "/dev/tty";
int crtscts = 0;
int modem = 1;
int modem_chat = 0;
int inspeed = 0;
u_int32_t netmask = 0;
int lockflag = 0;
int nodetach = 0;
char *connector = NULL;
char *disconnector = NULL;
char *welcomer = NULL;
int maxconnect = 0;
char user[MAXNAMELEN];
char passwd[MAXSECRETLEN];
int auth_required = 0;
volatile sig_atomic_t persist = 0;
int uselogin = 0;
int lcp_echo_interval = 0;
int lcp_echo_fails = 0;
char our_name[MAXNAMELEN];
char remote_name[MAXNAMELEN];
int explicit_remote = 0;
int usehostname = 0;
int disable_defaultip = 0;
int demand = 0;
char *ipparam = NULL;
int cryptpap;
int idle_time_limit = 0;
int holdoff = 30;
int refuse_pap = 0;
int refuse_chap = 0;
#ifdef MSLANMAN
int ms_lanman = 0;
#endif
struct option_info auth_req_info;
struct option_info connector_info;
struct option_info disconnector_info;
struct option_info welcomer_info;
struct option_info devnam_info;
#ifdef PPP_FILTER
struct bpf_program pass_filter;
struct bpf_program active_filter;
pcap_t pc;
#endif
static int setdevname(char *, int);
static int setipaddr(char *);
static int setspeed(char *);
static int setdebug(char **);
static int setkdebug(char **);
static int setpassive(char **);
static int setsilent(char **);
static int noopt(char **);
static int setnovj(char **);
static int setnovjccomp(char **);
static int setvjslots(char **);
static int reqpap(char **);
static int nopap(char **);
static int nochap(char **);
static int reqchap(char **);
static int noaccomp(char **);
static int noasyncmap(char **);
static int noip(char **);
static int nomagicnumber(char **);
static int setasyncmap(char **);
static int setescape(char **);
static int setmru(char **);
static int setmtu(char **);
#ifdef CBCP_SUPPORT
static int setcbcp(char **);
#endif
static int nomru(char **);
static int nopcomp(char **);
static int setconnector(char **);
static int setdisconnector(char **);
static int setwelcomer(char **);
static int setmaxconnect(char **);
static int setdomain(char **);
static int setnetmask(char **);
static int setcrtscts(char **);
static int setnocrtscts(char **);
static int setxonxoff(char **);
static int setnodetach(char **);
static int setupdetach(char **);
static int setmodem(char **);
static int setmodem_chat(char **);
static int setlocal(char **);
static int setlock(char **);
static int setname(char **);
static int setuser(char **);
static int setremote(char **);
static int setauth(char **);
static int setnoauth(char **);
static int readfile(char **);
static int callfile(char **);
static int setdefaultroute(char **);
static int setnodefaultroute(char **);
static int setproxyarp(char **);
static int setnoproxyarp(char **);
static int setpersist(char **);
static int setnopersist(char **);
static int setdologin(char **);
static int setusehostname(char **);
static int setnoipdflt(char **);
static int setlcptimeout(char **);
static int setlcpterm(char **);
static int setlcpconf(char **);
static int setlcpfails(char **);
static int setipcptimeout(char **);
static int setipcpterm(char **);
static int setipcpconf(char **);
static int setipcpfails(char **);
static int setpaptimeout(char **);
static int setpapreqs(char **);
static int setpapreqtime(char **);
static int setchaptimeout(char **);
static int setchapchal(char **);
static int setchapintv(char **);
static int setipcpaccl(char **);
static int setipcpaccr(char **);
static int setlcpechointv(char **);
static int setlcpechofails(char **);
static int noccp(char **);
static int setbsdcomp(char **);
static int setnobsdcomp(char **);
static int setdeflate(char **);
static int setnodeflate(char **);
static int setnodeflatedraft(char **);
static int setdemand(char **);
static int setpred1comp(char **);
static int setnopred1comp(char **);
static int setipparam(char **);
static int setpapcrypt(char **);
static int setidle(char **);
static int setholdoff(char **);
static int setdnsaddr(char **);
static int setwinsaddr(char **);
static int showversion(char **);
static int showhelp(char **);
#ifdef PPP_FILTER
static int setpdebug(char **);
static int setpassfilter(char **);
static int setactivefilter(char **);
#endif
#ifdef MSLANMAN
static int setmslanman(char **);
#endif
static int number_option(char *, u_int32_t *, int);
static int int_option(char *, int *);
static int readable(int fd);
static struct cmd {
char *cmd_name;
int num_args;
int (*cmd_func)(char **);
} cmds[] = {
{"-all", 0, noopt},
{"noaccomp", 0, noaccomp},
{"-ac", 0, noaccomp},
{"default-asyncmap", 0, noasyncmap},
{"-am", 0, noasyncmap},
{"-as", 1, setasyncmap},
{"-d", 0, setdebug},
{"nodetach", 0, setnodetach},
{"-detach", 0, setnodetach},
{"updetach", 0, setupdetach},
{"noip", 0, noip},
{"-ip", 0, noip},
{"nomagic", 0, nomagicnumber},
{"-mn", 0, nomagicnumber},
{"default-mru", 0, nomru},
{"-mru", 0, nomru},
{"-p", 0, setpassive},
{"nopcomp", 0, nopcomp},
{"-pc", 0, nopcomp},
{"require-pap", 0, reqpap},
{"+pap", 0, reqpap},
{"refuse-pap", 0, nopap},
{"-pap", 0, nopap},
{"require-chap", 0, reqchap},
{"+chap", 0, reqchap},
{"refuse-chap", 0, nochap},
{"-chap", 0, nochap},
{"novj", 0, setnovj},
{"-vj", 0, setnovj},
{"novjccomp", 0, setnovjccomp},
{"-vjccomp", 0, setnovjccomp},
{"vj-max-slots", 1, setvjslots},
{"asyncmap", 1, setasyncmap},
{"escape", 1, setescape},
{"connect", 1, setconnector},
{"disconnect", 1, setdisconnector},
{"welcome", 1, setwelcomer},
{"maxconnect", 1, setmaxconnect},
{"crtscts", 0, setcrtscts},
{"nocrtscts", 0, setnocrtscts},
{"-crtscts", 0, setnocrtscts},
{"xonxoff", 0, setxonxoff},
{"debug", 0, setdebug},
{"kdebug", 1, setkdebug},
{"domain", 1, setdomain},
{"mru", 1, setmru},
{"mtu", 1, setmtu},
#ifdef CBCP_SUPPORT
{"callback", 1, setcbcp},
#endif
{"netmask", 1, setnetmask},
{"passive", 0, setpassive},
{"silent", 0, setsilent},
{"modem", 0, setmodem},
{"modem_chat", 0, setmodem_chat},
{"local", 0, setlocal},
{"lock", 0, setlock},
{"name", 1, setname},
{"user", 1, setuser},
{"usehostname", 0, setusehostname},
{"remotename", 1, setremote},
{"auth", 0, setauth},
{"noauth", 0, setnoauth},
{"file", 1, readfile},
{"call", 1, callfile},
{"defaultroute", 0, setdefaultroute},
{"nodefaultroute", 0, setnodefaultroute},
{"-defaultroute", 0, setnodefaultroute},
{"proxyarp", 0, setproxyarp},
{"noproxyarp", 0, setnoproxyarp},
{"-proxyarp", 0, setnoproxyarp},
{"persist", 0, setpersist},
{"nopersist", 0, setnopersist},
{"demand", 0, setdemand},
{"login", 0, setdologin},
{"noipdefault", 0, setnoipdflt},
{"lcp-echo-failure", 1, setlcpechofails},
{"lcp-echo-interval", 1, setlcpechointv},
{"lcp-restart", 1, setlcptimeout},
{"lcp-max-terminate", 1, setlcpterm},
{"lcp-max-configure", 1, setlcpconf},
{"lcp-max-failure", 1, setlcpfails},
{"ipcp-restart", 1, setipcptimeout},
{"ipcp-max-terminate", 1, setipcpterm},
{"ipcp-max-configure", 1, setipcpconf},
{"ipcp-max-failure", 1, setipcpfails},
{"pap-restart", 1, setpaptimeout},
{"pap-max-authreq", 1, setpapreqs},
{"pap-timeout", 1, setpapreqtime},
{"chap-restart", 1, setchaptimeout},
{"chap-max-challenge", 1, setchapchal},
{"chap-interval", 1, setchapintv},
{"ipcp-accept-local", 0, setipcpaccl},
{"ipcp-accept-remote", 0, setipcpaccr},
{"noccp", 0, noccp},
{"-ccp", 0, noccp},
{"bsdcomp", 1, setbsdcomp},
{"nobsdcomp", 0, setnobsdcomp},
{"-bsdcomp", 0, setnobsdcomp},
{"deflate", 1, setdeflate},
{"nodeflate", 0, setnodeflate},
{"-deflate", 0, setnodeflate},
{"nodeflatedraft", 0, setnodeflatedraft},
{"predictor1", 0, setpred1comp},
{"nopredictor1", 0, setnopred1comp},
{"-predictor1", 0, setnopred1comp},
{"ipparam", 1, setipparam},
{"papcrypt", 0, setpapcrypt},
{"idle", 1, setidle},
{"holdoff", 1, setholdoff},
{"ms-dns", 1, setdnsaddr},
{"ms-wins", 1, setwinsaddr},
{"--version", 0, showversion},
{"--help", 0, showhelp},
{"-h", 0, showhelp},
#ifdef PPP_FILTER
{"pdebug", 1, setpdebug},
{"pass-filter", 1, setpassfilter},
{"active-filter", 1, setactivefilter},
#endif
#ifdef MSLANMAN
{"ms-lanman", 0, setmslanman},
#endif
{NULL, 0, NULL}
};
#ifndef IMPLEMENTATION
#define IMPLEMENTATION ""
#endif
static const char usage_string[] = "\
pppd version %s patch level %d%s\n\
Usage: %s [ options ], where options are:\n\
<device> Communicate over the named device\n\
<speed> Set the baud rate to <speed>\n\
<loc>:<rem> Set the local and/or remote interface IP\n\
addresses. Either one may be omitted.\n\
asyncmap <n> Set the desired async map to hex <n>\n\
auth Require authentication from peer\n\
connect <p> Invoke shell command <p> to set up the serial line\n\
crtscts Use hardware RTS/CTS flow control\n\
defaultroute Add default route through interface\n\
file <f> Take options from file <f>\n\
modem Use modem control lines\n\
modem_chat Use modem control lines during chat\n\
mru <n> Set MRU value to <n> for negotiation\n\
netmask <n> Set interface netmask to <n>\n\
See pppd(8) for more options.\n\
";
static char *current_option;
static int privileged_option;
static char *option_source;
int
parse_args(int argc, char **argv)
{
char *arg;
struct cmd *cmdp;
int ret;
privileged_option = privileged;
option_source = "command line";
while (argc > 0) {
arg = *argv++;
--argc;
for (cmdp = cmds; cmdp->cmd_name; cmdp++)
if (!strcmp(arg, cmdp->cmd_name))
break;
if (cmdp->cmd_name != NULL) {
if (argc < cmdp->num_args) {
option_error("too few parameters for option %s", arg);
return 0;
}
current_option = arg;
if (!(*cmdp->cmd_func)(argv))
return 0;
argc -= cmdp->num_args;
argv += cmdp->num_args;
} else {
if ((ret = setdevname(arg, 0)) == 0
&& (ret = setspeed(arg)) == 0
&& (ret = setipaddr(arg)) == 0) {
option_error("unrecognized option '%s'", arg);
usage();
return 0;
}
if (ret < 0)
return 0;
}
}
return 1;
}
void
scan_args(int argc, char **argv)
{
char *arg;
struct cmd *cmdp;
while (argc > 0) {
arg = *argv++;
--argc;
for (cmdp = cmds; cmdp->cmd_name; cmdp++)
if (!strcmp(arg, cmdp->cmd_name))
break;
if (cmdp->cmd_name != NULL) {
argc -= cmdp->num_args;
argv += cmdp->num_args;
continue;
}
(void) setdevname(arg, 1);
}
}
void
usage(void)
{
if (phase == PHASE_INITIALIZE)
fprintf(stderr, usage_string, VERSION, PATCHLEVEL, IMPLEMENTATION,
__progname);
}
static int
showhelp(char **argv)
{
if (phase == PHASE_INITIALIZE) {
usage();
exit(0);
}
return 0;
}
static int
showversion(char **argv)
{
if (phase == PHASE_INITIALIZE) {
fprintf(stderr, "pppd version %s patch level %d%s\n",
VERSION, PATCHLEVEL, IMPLEMENTATION);
exit(0);
}
return 0;
}
int
options_from_file(char *filename, int must_exist, int check_prot, int priv)
{
FILE *f;
int i, newline, ret;
struct cmd *cmdp;
int oldpriv;
char *argv[MAXARGS];
char args[MAXARGS][MAXWORDLEN];
char cmd[MAXWORDLEN];
if ((f = fopen(filename, "r")) == NULL) {
if (!must_exist && errno == ENOENT)
return 1;
option_error("Can't open options file %s: %m", filename);
return 0;
}
if (check_prot && !readable(fileno(f))) {
option_error("Can't open options file %s: access denied", filename);
fclose(f);
return 0;
}
oldpriv = privileged_option;
privileged_option = priv;
ret = 0;
while (getword(f, cmd, &newline, filename)) {
for (cmdp = cmds; cmdp->cmd_name; cmdp++)
if (!strcmp(cmd, cmdp->cmd_name))
break;
if (cmdp->cmd_name != NULL) {
for (i = 0; i < cmdp->num_args; ++i) {
if (!getword(f, args[i], &newline, filename)) {
option_error(
"In file %s: too few parameters for option '%s'",
filename, cmd);
goto err;
}
argv[i] = args[i];
}
current_option = cmd;
if (!(*cmdp->cmd_func)(argv))
goto err;
} else {
if ((i = setdevname(cmd, 0)) == 0
&& (i = setspeed(cmd)) == 0
&& (i = setipaddr(cmd)) == 0) {
option_error("In file %s: unrecognized option '%s'",
filename, cmd);
goto err;
}
if (i < 0)
goto err;
}
}
ret = 1;
err:
fclose(f);
privileged_option = oldpriv;
return ret;
}
int
options_from_user(void)
{
char *user, *path, *file;
int ret;
struct passwd *pw;
pw = getpwuid(getuid());
if (pw == NULL || (user = pw->pw_dir) == NULL || user[0] == 0)
return 1;
file = _PATH_USEROPT;
if (asprintf(&path, "%s/%s", user, file) == -1)
novm("init file name");
ret = options_from_file(path, 0, 1, privileged);
free(path);
return ret;
}
int
options_for_tty(void)
{
char *dev, *path;
int ret;
dev = devnam;
if (strncmp(dev, "/dev/", 5) == 0)
dev += 5;
if (strcmp(dev, "tty") == 0)
return 1;
if (asprintf(&path, "%s%s", _PATH_TTYOPT, dev) == -1)
novm("tty init file name");
ret = options_from_file(path, 0, 0, 1);
free(path);
return ret;
}
void
option_error(char *fmt, ...)
{
va_list args;
char buf[256];
va_start(args, fmt);
vfmtmsg(buf, sizeof(buf), fmt, args);
va_end(args);
if (phase == PHASE_INITIALIZE)
fprintf(stderr, "%s: %s\n", __progname, buf);
syslog(LOG_ERR, "%s", buf);
}
static int
readable(int fd)
{
uid_t uid;
int ngroups, i;
struct stat sbuf;
GIDSET_TYPE groups[NGROUPS_MAX];
uid = getuid();
if (uid == 0)
return 1;
if (fstat(fd, &sbuf) != 0)
return 0;
if (sbuf.st_uid == uid)
return sbuf.st_mode & S_IRUSR;
if (sbuf.st_gid == getgid())
return sbuf.st_mode & S_IRGRP;
ngroups = getgroups(NGROUPS_MAX, groups);
for (i = 0; i < ngroups; ++i)
if (sbuf.st_gid == groups[i])
return sbuf.st_mode & S_IRGRP;
return sbuf.st_mode & S_IROTH;
}
int
getword(FILE *f, char *word, int *newlinep, char *filename)
{
int c, len, escape;
int quoted, comment;
int value, digit, got, n;
#define isoctal(c) ((c) >= '0' && (c) < '8')
*newlinep = 0;
len = 0;
escape = 0;
comment = 0;
for (;;) {
c = getc(f);
if (c == EOF)
break;
if (c == '\n') {
if (!escape) {
*newlinep = 1;
comment = 0;
} else
escape = 0;
continue;
}
if (comment)
continue;
if (escape)
break;
if (c == '\\') {
escape = 1;
continue;
}
if (c == '#') {
comment = 1;
continue;
}
if (!isspace(c))
break;
}
if (!escape && (c == '"' || c == '\'')) {
quoted = c;
c = getc(f);
} else
quoted = 0;
while (c != EOF) {
if (escape) {
escape = 0;
if (c == '\n') {
c = getc(f);
continue;
}
got = 0;
switch (c) {
case 'a':
value = '\a';
break;
case 'b':
value = '\b';
break;
case 'f':
value = '\f';
break;
case 'n':
value = '\n';
break;
case 'r':
value = '\r';
break;
case 's':
value = ' ';
break;
case 't':
value = '\t';
break;
default:
if (isoctal(c)) {
value = 0;
for (n = 0; n < 3 && isoctal(c); ++n) {
value = (value << 3) + (c & 07);
c = getc(f);
}
got = 1;
break;
}
if (c == 'x') {
value = 0;
c = getc(f);
for (n = 0; n < 2 && isxdigit(c); ++n) {
digit = toupper(c) - '0';
if (digit > 10)
digit += '0' + 10 - 'A';
value = (value << 4) + digit;
c = getc (f);
}
got = 1;
break;
}
value = c;
break;
}
if (len < MAXWORDLEN) {
word[len] = value;
++len;
}
if (!got)
c = getc(f);
continue;
}
if (quoted) {
if (c == quoted)
break;
} else {
if (isspace(c) || c == '#') {
ungetc (c, f);
break;
}
}
if (c == '\\') {
escape = 1;
c = getc(f);
continue;
}
if (len < MAXWORDLEN) {
word[len] = c;
++len;
}
c = getc(f);
}
if (c == EOF) {
if (ferror(f)) {
if (errno == 0)
errno = EIO;
option_error("Error reading %s: %m", filename);
die(1);
}
if (len == 0)
return 0;
}
if (len >= MAXWORDLEN) {
option_error("warning: word in file %s too long (%.20s...)",
filename, word);
len = MAXWORDLEN - 1;
}
word[len] = 0;
return 1;
#undef isoctal
}
static int
number_option(char *str, u_int32_t *valp, int base)
{
char *ptr;
*valp = strtoul(str, &ptr, base);
if (ptr == str) {
option_error("invalid numeric parameter '%s' for %s option",
str, current_option);
return 0;
}
return 1;
}
static int
int_option(char *str, int *valp)
{
u_int32_t v;
if (!number_option(str, &v, 0))
return 0;
*valp = (int) v;
return 1;
}
static int
readfile(char **argv)
{
return options_from_file(*argv, 1, 1, privileged_option);
}
static int
callfile(char **argv)
{
char *fname, *arg, *p;
int l, ok;
arg = *argv;
ok = 1;
if (arg[0] == '/' || arg[0] == 0)
ok = 0;
else {
for (p = arg; *p != 0; ) {
if (p[0] == '.' && p[1] == '.' && (p[2] == '/' || p[2] == 0)) {
ok = 0;
break;
}
while (*p != '/' && *p != 0)
++p;
if (*p == '/')
++p;
}
}
if (!ok) {
option_error("call option value may not contain .. or start with /");
return 0;
}
l = strlen(arg) + strlen(_PATH_PEERFILES) + 1;
if ((fname = (char *) malloc(l)) == NULL)
novm("call file name");
strlcpy(fname, _PATH_PEERFILES, l);
strlcat(fname, arg, l);
ok = options_from_file(fname, 1, 1, 1);
free(fname);
return ok;
}
static int
setdebug(char **argv)
{
debug++;
return (1);
}
static int
setkdebug(char **argv)
{
return int_option(*argv, &kdebugflag);
}
#ifdef PPP_FILTER
static int
setpdebug(char **argv)
{
return int_option(*argv, &dflag);
}
static int
setpassfilter(char **argv)
{
pc.linktype = DLT_PPP;
pc.snapshot = PPP_HDRLEN;
if (pcap_compile(&pc, &pass_filter, *argv, 1, netmask) == 0)
return 1;
option_error("error in pass-filter expression: %s\n", pcap_geterr(&pc));
return 0;
}
static int
setactivefilter(char **argv)
{
pc.linktype = DLT_PPP;
pc.snapshot = PPP_HDRLEN;
if (pcap_compile(&pc, &active_filter, *argv, 1, netmask) == 0)
return 1;
option_error("error in active-filter expression: %s\n", pcap_geterr(&pc));
return 0;
}
#endif
static int
noopt(char **argv)
{
BZERO((char *) &lcp_wantoptions[0], sizeof (struct lcp_options));
BZERO((char *) &lcp_allowoptions[0], sizeof (struct lcp_options));
BZERO((char *) &ipcp_wantoptions[0], sizeof (struct ipcp_options));
BZERO((char *) &ipcp_allowoptions[0], sizeof (struct ipcp_options));
return (1);
}
static int
noaccomp(char **argv)
{
lcp_wantoptions[0].neg_accompression = 0;
lcp_allowoptions[0].neg_accompression = 0;
return (1);
}
static int
noasyncmap(char **argv)
{
lcp_wantoptions[0].neg_asyncmap = 0;
lcp_allowoptions[0].neg_asyncmap = 0;
return (1);
}
static int
noip(char **argv)
{
ipcp_protent.enabled_flag = 0;
return (1);
}
static int
nomagicnumber(char **argv)
{
lcp_wantoptions[0].neg_magicnumber = 0;
lcp_allowoptions[0].neg_magicnumber = 0;
return (1);
}
static int
nomru(char **argv)
{
lcp_wantoptions[0].neg_mru = 0;
lcp_allowoptions[0].neg_mru = 0;
return (1);
}
static int
setmru(char **argv)
{
u_int32_t mru;
if (!number_option(*argv, &mru, 0))
return 0;
lcp_wantoptions[0].mru = mru;
lcp_wantoptions[0].neg_mru = 1;
return (1);
}
static int
setmtu(char **argv)
{
u_int32_t mtu;
if (!number_option(*argv, &mtu, 0))
return 0;
if (mtu < MINMRU || mtu > MAXMRU) {
option_error("mtu option value of %u is too %s", mtu,
(mtu < MINMRU? "small": "large"));
return 0;
}
lcp_allowoptions[0].mru = mtu;
return (1);
}
#ifdef CBCP_SUPPORT
static int
setcbcp(argv)
char **argv;
{
lcp_wantoptions[0].neg_cbcp = 1;
cbcp_protent.enabled_flag = 1;
cbcp[0].us_number = strdup(*argv);
if (cbcp[0].us_number == 0)
novm("callback number");
cbcp[0].us_type |= (1 << CB_CONF_USER);
cbcp[0].us_type |= (1 << CB_CONF_ADMIN);
return (1);
}
#endif
static int
nopcomp(char **argv)
{
lcp_wantoptions[0].neg_pcompression = 0;
lcp_allowoptions[0].neg_pcompression = 0;
return (1);
}
static int
setpassive(char **argv)
{
lcp_wantoptions[0].passive = 1;
return (1);
}
static int
setsilent(char **argv)
{
lcp_wantoptions[0].silent = 1;
return 1;
}
static int
nopap(char **argv)
{
refuse_pap = 1;
return (1);
}
static int
reqpap(char **argv)
{
lcp_wantoptions[0].neg_upap = 1;
setauth(NULL);
return 1;
}
static int
nochap(char **argv)
{
refuse_chap = 1;
return (1);
}
static int
reqchap(char **argv)
{
lcp_wantoptions[0].neg_chap = 1;
setauth(NULL);
return (1);
}
static int
setnovj(char **argv)
{
ipcp_wantoptions[0].neg_vj = 0;
ipcp_allowoptions[0].neg_vj = 0;
return (1);
}
static int
setnovjccomp(char **argv)
{
ipcp_wantoptions[0].cflag = 0;
ipcp_allowoptions[0].cflag = 0;
return 1;
}
static int
setvjslots(char **argv)
{
int value;
if (!int_option(*argv, &value))
return 0;
if (value < 2 || value > 16) {
option_error("vj-max-slots value must be between 2 and 16");
return 0;
}
ipcp_wantoptions [0].maxslotindex =
ipcp_allowoptions[0].maxslotindex = value - 1;
return 1;
}
static int
setconnector(char **argv)
{
connector = strdup(*argv);
if (connector == NULL)
novm("connect script");
connector_info.priv = privileged_option;
connector_info.source = option_source;
return (1);
}
static int
setdisconnector(char **argv)
{
disconnector = strdup(*argv);
if (disconnector == NULL)
novm("disconnect script");
disconnector_info.priv = privileged_option;
disconnector_info.source = option_source;
return (1);
}
static int
setwelcomer(char **argv)
{
welcomer = strdup(*argv);
if (welcomer == NULL)
novm("welcome script");
welcomer_info.priv = privileged_option;
welcomer_info.source = option_source;
return (1);
}
static int
setmaxconnect(char **argv)
{
int value;
if (!int_option(*argv, &value))
return 0;
if (value < 0) {
option_error("maxconnect time must be positive");
return 0;
}
if (maxconnect > 0 && (value == 0 || value > maxconnect)) {
option_error("maxconnect time cannot be increased");
return 0;
}
maxconnect = value;
return 1;
}
static int
setdomain(char **argv)
{
if (!privileged_option) {
option_error("using the domain option requires root privilege");
return 0;
}
gethostname(hostname, MAXNAMELEN);
if (**argv != 0) {
if (**argv != '.')
strlcat(hostname, ".", MAXNAMELEN);
strlcat(hostname, *argv, MAXNAMELEN);
}
hostname[MAXNAMELEN-1] = 0;
return (1);
}
static int
setasyncmap(char **argv)
{
u_int32_t asyncmap;
if (!number_option(*argv, &asyncmap, 16))
return 0;
lcp_wantoptions[0].asyncmap |= asyncmap;
lcp_wantoptions[0].neg_asyncmap = 1;
return(1);
}
static int
setescape(char **argv)
{
int n, ret;
char *p, *endp;
p = *argv;
ret = 1;
while (*p) {
n = strtol(p, &endp, 16);
if (p == endp) {
option_error("escape parameter contains invalid hex number '%s'",
p);
return 0;
}
p = endp;
if (n < 0 || (0x20 <= n && n <= 0x3F) || n == 0x5E || n > 0xFF) {
option_error("can't escape character 0x%x", n);
ret = 0;
} else
xmit_accm[0][n >> 5] |= 1 << (n & 0x1F);
while (*p == ',' || *p == ' ')
++p;
}
return ret;
}
static int
setspeed(char *arg)
{
char *ptr;
int spd;
spd = strtol(arg, &ptr, 0);
if (ptr == arg || *ptr != 0 || spd == 0)
return 0;
inspeed = spd;
return 1;
}
static int
setdevname(char *cp, int quiet)
{
struct stat statbuf;
char dev[PATH_MAX];
if (*cp == 0)
return 0;
if (strncmp("/dev/", cp, 5) != 0) {
strlcpy(dev, "/dev/", sizeof dev);
strlcat(dev, cp, sizeof dev);
cp = dev;
}
if (stat(cp, &statbuf) < 0) {
if (errno == ENOENT || quiet)
return 0;
option_error("Couldn't stat %s: %m", cp);
return -1;
}
(void) strlcpy(devnam, cp, PATH_MAX);
default_device = FALSE;
devnam_info.priv = privileged_option;
devnam_info.source = option_source;
return 1;
}
static int
setipaddr(char *arg)
{
struct hostent *hp;
char *colon;
struct in_addr ina;
u_int32_t local, remote;
ipcp_options *wo = &ipcp_wantoptions[0];
if ((colon = strchr(arg, ':')) == NULL)
return 0;
if (colon != arg) {
*colon = '\0';
if (inet_pton(AF_INET, arg, &ina) != 1) {
if ((hp = gethostbyname(arg)) == NULL) {
option_error("unknown host: %s", arg);
return -1;
} else {
local = *(u_int32_t *)hp->h_addr;
if (our_name[0] == 0)
strlcpy(our_name, arg, MAXNAMELEN);
}
} else
local = ina.s_addr;
if (bad_ip_adrs(local)) {
option_error("bad local IP address %s", ip_ntoa(local));
return -1;
}
if (local != 0)
wo->ouraddr = local;
*colon = ':';
}
if (*++colon != '\0') {
if (inet_pton(AF_INET, colon, &ina) != 1) {
if ((hp = gethostbyname(colon)) == NULL) {
option_error("unknown host: %s", colon);
return -1;
} else {
remote = *(u_int32_t *)hp->h_addr;
if (remote_name[0] == 0)
strlcpy(remote_name, colon, MAXNAMELEN);
}
} else
remote = ina.s_addr;
if (bad_ip_adrs(remote)) {
option_error("bad remote IP address %s", ip_ntoa(remote));
return -1;
}
if (remote != 0)
wo->hisaddr = remote;
}
return 1;
}
static int
setnoipdflt(char **argv)
{
disable_defaultip = 1;
return 1;
}
static int
setipcpaccl(char **argv)
{
ipcp_wantoptions[0].accept_local = 1;
return 1;
}
static int
setipcpaccr(char **argv)
{
ipcp_wantoptions[0].accept_remote = 1;
return 1;
}
static int
setnetmask(char **argv)
{
struct in_addr ina;
if (inet_pton(AF_INET, *argv, &ina) != 1 || (netmask & ~ina.s_addr) != 0) {
option_error("invalid netmask value '%s'", *argv);
return (0);
}
netmask = ina.s_addr;
return (1);
}
static int
setcrtscts(char **argv)
{
crtscts = 1;
return (1);
}
static int
setnocrtscts(char **argv)
{
crtscts = -1;
return (1);
}
static int
setxonxoff(char **argv)
{
lcp_wantoptions[0].asyncmap |= 0x000A0000;
lcp_wantoptions[0].neg_asyncmap = 1;
crtscts = -2;
return (1);
}
static int
setnodetach(char **argv)
{
nodetach = 1;
return (1);
}
static int
setupdetach(char **argv)
{
nodetach = -1;
return (1);
}
static int
setdemand(char **argv)
{
demand = 1;
persist = 1;
return 1;
}
static int
setmodem(char **argv)
{
modem = 1;
return 1;
}
static int
setmodem_chat(char **argv)
{
modem_chat = 1;
return 1;
}
static int
setlocal(char **argv)
{
modem = 0;
return 1;
}
static int
setlock(char **argv)
{
lockflag = 1;
return 1;
}
static int
setusehostname(char **argv)
{
usehostname = 1;
return 1;
}
static int
setname(char **argv)
{
if (!privileged_option) {
option_error("using the name option requires root privilege");
return 0;
}
strlcpy(our_name, argv[0], MAXNAMELEN);
return 1;
}
static int
setuser(char **argv)
{
strlcpy(user, argv[0], MAXNAMELEN);
return 1;
}
static int
setremote(char **argv)
{
strlcpy(remote_name, argv[0], MAXNAMELEN);
return 1;
}
static int
setauth(char **argv)
{
auth_required = 1;
if (privileged_option > auth_req_info.priv) {
auth_req_info.priv = privileged_option;
auth_req_info.source = option_source;
}
return 1;
}
static int
setnoauth(char **argv)
{
if (auth_required && privileged_option < auth_req_info.priv) {
if (auth_req_info.source == NULL)
option_error("cannot override default auth option");
else
option_error("cannot override auth option set by %s",
auth_req_info.source);
return 0;
}
auth_required = 0;
return 1;
}
static int
setdefaultroute(char **argv)
{
if (!ipcp_allowoptions[0].default_route) {
option_error("defaultroute option is disabled");
return 0;
}
ipcp_wantoptions[0].default_route = 1;
return 1;
}
static int
setnodefaultroute(char **argv)
{
ipcp_allowoptions[0].default_route = 0;
ipcp_wantoptions[0].default_route = 0;
return 1;
}
static int
setproxyarp(char **argv)
{
if (!ipcp_allowoptions[0].proxy_arp) {
option_error("proxyarp option is disabled");
return 0;
}
ipcp_wantoptions[0].proxy_arp = 1;
return 1;
}
static int
setnoproxyarp(char **argv)
{
ipcp_wantoptions[0].proxy_arp = 0;
ipcp_allowoptions[0].proxy_arp = 0;
return 1;
}
static int
setpersist(char **argv)
{
persist = 1;
return 1;
}
static int
setnopersist(char **argv)
{
persist = 0;
return 1;
}
static int
setdologin(char **argv)
{
uselogin = 1;
return 1;
}
static int
setlcpechointv(char **argv)
{
return int_option(*argv, &lcp_echo_interval);
}
static int
setlcpechofails(char **argv)
{
return int_option(*argv, &lcp_echo_fails);
}
static int
setlcptimeout(char **argv)
{
return int_option(*argv, &lcp_fsm[0].timeouttime);
}
static int
setlcpterm(char **argv)
{
return int_option(*argv, &lcp_fsm[0].maxtermtransmits);
}
static int
setlcpconf(char **argv)
{
return int_option(*argv, &lcp_fsm[0].maxconfreqtransmits);
}
static int
setlcpfails(char **argv)
{
return int_option(*argv, &lcp_fsm[0].maxnakloops);
}
static int
setipcptimeout(char **argv)
{
return int_option(*argv, &ipcp_fsm[0].timeouttime);
}
static int
setipcpterm(char **argv)
{
return int_option(*argv, &ipcp_fsm[0].maxtermtransmits);
}
static int
setipcpconf(char **argv)
{
return int_option(*argv, &ipcp_fsm[0].maxconfreqtransmits);
}
static int
setipcpfails(char **argv)
{
return int_option(*argv, &lcp_fsm[0].maxnakloops);
}
static int
setpaptimeout(char **argv)
{
return int_option(*argv, &upap[0].us_timeouttime);
}
static int
setpapreqtime(char **argv)
{
return int_option(*argv, &upap[0].us_reqtimeout);
}
static int
setpapreqs(char **argv)
{
return int_option(*argv, &upap[0].us_maxtransmits);
}
static int
setchaptimeout(char **argv)
{
return int_option(*argv, &chap[0].timeouttime);
}
static int
setchapchal(char **argv)
{
return int_option(*argv, &chap[0].max_transmits);
}
static int
setchapintv(char **argv)
{
return int_option(*argv, &chap[0].chal_interval);
}
static int
noccp(char **argv)
{
ccp_protent.enabled_flag = 0;
return 1;
}
static int
setbsdcomp(char **argv)
{
int rbits, abits;
char *str, *endp;
str = *argv;
abits = rbits = strtol(str, &endp, 0);
if (endp != str && *endp == ',') {
str = endp + 1;
abits = strtol(str, &endp, 0);
}
if (*endp != 0 || endp == str) {
option_error("invalid parameter '%s' for bsdcomp option", *argv);
return 0;
}
if ((rbits != 0 && (rbits < BSD_MIN_BITS || rbits > BSD_MAX_BITS))
|| (abits != 0 && (abits < BSD_MIN_BITS || abits > BSD_MAX_BITS))) {
option_error("bsdcomp option values must be 0 or %d .. %d",
BSD_MIN_BITS, BSD_MAX_BITS);
return 0;
}
if (rbits > 0) {
ccp_wantoptions[0].bsd_compress = 1;
ccp_wantoptions[0].bsd_bits = rbits;
} else
ccp_wantoptions[0].bsd_compress = 0;
if (abits > 0) {
ccp_allowoptions[0].bsd_compress = 1;
ccp_allowoptions[0].bsd_bits = abits;
} else
ccp_allowoptions[0].bsd_compress = 0;
return 1;
}
static int
setnobsdcomp(char **argv)
{
ccp_wantoptions[0].bsd_compress = 0;
ccp_allowoptions[0].bsd_compress = 0;
return 1;
}
static int
setdeflate(char **argv)
{
int rbits, abits;
char *str, *endp;
str = *argv;
abits = rbits = strtol(str, &endp, 0);
if (endp != str && *endp == ',') {
str = endp + 1;
abits = strtol(str, &endp, 0);
}
if (*endp != 0 || endp == str) {
option_error("invalid parameter '%s' for deflate option", *argv);
return 0;
}
if ((rbits != 0 && (rbits < DEFLATE_MIN_SIZE || rbits > DEFLATE_MAX_SIZE))
|| (abits != 0 && (abits < DEFLATE_MIN_SIZE
|| abits > DEFLATE_MAX_SIZE))) {
option_error("deflate option values must be 0 or %d .. %d",
DEFLATE_MIN_SIZE, DEFLATE_MAX_SIZE);
return 0;
}
if (rbits > 0) {
ccp_wantoptions[0].deflate = 1;
ccp_wantoptions[0].deflate_size = rbits;
} else
ccp_wantoptions[0].deflate = 0;
if (abits > 0) {
ccp_allowoptions[0].deflate = 1;
ccp_allowoptions[0].deflate_size = abits;
} else
ccp_allowoptions[0].deflate = 0;
return 1;
}
static int
setnodeflate(char **argv)
{
ccp_wantoptions[0].deflate = 0;
ccp_allowoptions[0].deflate = 0;
return 1;
}
static int
setnodeflatedraft(char **argv)
{
ccp_wantoptions[0].deflate_draft = 0;
ccp_allowoptions[0].deflate_draft = 0;
return 1;
}
static int
setpred1comp(char **argv)
{
ccp_wantoptions[0].predictor_1 = 1;
ccp_allowoptions[0].predictor_1 = 1;
return 1;
}
static int
setnopred1comp(char **argv)
{
ccp_wantoptions[0].predictor_1 = 0;
ccp_allowoptions[0].predictor_1 = 0;
return 1;
}
static int
setipparam(char **argv)
{
ipparam = strdup(*argv);
if (ipparam == NULL)
novm("ipparam string");
return 1;
}
static int
setpapcrypt(char **argv)
{
cryptpap = 1;
return 1;
}
static int
setidle(char **argv)
{
return int_option(*argv, &idle_time_limit);
}
static int
setholdoff(char **argv)
{
return int_option(*argv, &holdoff);
}
static int
setdnsaddr(char **argv)
{
struct in_addr ina;
struct hostent *hp;
if (inet_pton(AF_INET, *argv, &ina) != 1) {
if ((hp = gethostbyname(*argv)) == NULL) {
option_error("invalid address parameter '%s' for ms-dns option",
*argv);
return (0);
}
ina.s_addr = *(u_int32_t *)hp->h_addr;
}
if (ipcp_allowoptions[0].dnsaddr[0] == 0)
ipcp_allowoptions[0].dnsaddr[0] = ina.s_addr;
ipcp_allowoptions[0].dnsaddr[1] = ina.s_addr;
return (1);
}
static int
setwinsaddr(char **argv)
{
struct in_addr ina;
struct hostent *hp;
if (inet_pton(AF_INET, *argv, &ina) != 1) {
if ((hp = gethostbyname(*argv)) == NULL) {
option_error("invalid address parameter '%s' for ms-wins option",
*argv);
return (0);
}
ina.s_addr = *(u_int32_t *)hp->h_addr;
}
if (ipcp_allowoptions[0].winsaddr[0] == 0)
ipcp_allowoptions[0].winsaddr[0] = ina.s_addr;
ipcp_allowoptions[0].winsaddr[1] = ina.s_addr;
return (1);
}
#ifdef MSLANMAN
static int
setmslanman(char **argv)
{
ms_lanman = 1;
return (1);
}
#endif