options.c revision 084c18406d32a8fbb6b9a40d864e7c7ddb5b4d9d
/*
* options.c - handles option processing for PPP.
*
* Copyright (c) 2000-2001 by Sun Microsystems, Inc.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, provided that the above copyright
* notice appears in all copies.
*
* SUN MAKES NO REPRESENTATION OR WARRANTIES ABOUT THE SUITABILITY OF
* THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES
*
* Copyright (c) 1989 Carnegie Mellon University.
* All rights reserved.
*
* 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 Carnegie Mellon University. The name of the
* University 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.
*/
#include <ctype.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <syslog.h>
#include <string.h>
#include <netdb.h>
#include <pwd.h>
#ifdef PLUGIN
#include <dlfcn.h>
#endif /* PLUGIN */
#ifdef PPP_FILTER
#include <pcap.h>
#include <pcap-int.h> /* XXX: To get struct pcap */
#endif /* PPP_FILTER */
#include "pppd.h"
#include "pathnames.h"
#include "patchlevel.h"
#include "fsm.h"
#include "lcp.h"
#include "ipcp.h"
#endif
#endif
/*
* Option variables and default values.
*/
#ifdef PPP_FILTER
int dflag = 0; /* Tell libpcap we want debugging */
#endif /* PPP_FILTER */
int debug = 0; /* Debug flag */
int kdebugflag = 0; /* Tell kernel to print debug messages */
int crtscts = 0; /* Use hardware flow control */
bool lockflag = 0; /* Create lock file to lock the serial dev */
bool nodetach = 0; /* Don't detach from controlling tty */
bool updetach = 0; /* Detach once link is up */
int maxconnect = 0; /* Maximum connect time */
bool persist = 0; /* Reopen link after it goes down */
bool demand = 0; /* do dial-on-demand */
int idle_time_limit = 0; /* Disconnect if idle for this many seconds */
bool holdoff_specified; /* true if a holdoff value has been given */
int using_pty = 0;
bool sync_serial = 0; /* Device is synchronous serial device */
bool tune_kernel; /* may alter kernel settings */
int max_data_rate; /* max bytes/sec through charshunt */
bool multilink = 0; /* Enable multilink operation */
bool direct_tty = 0; /* use standard input directly; not a tty */
/* Maximum depth of include files; prevents looping. */
#define MAXFILENESTING 10
struct option_info initializer_info;
struct option_info connect_script_info;
struct option_info disconnect_script_info;
struct option_info welcomer_info;
struct option_info devnam_info;
struct option_info ptycommand_info;
struct option_info ipsrc_info;
struct option_info ipdst_info;
struct option_info speed_info;
#ifdef PPP_FILTER
#endif /* PPP_FILTER */
char *current_option; /* the name of the option being parsed */
bool privileged_option; /* set iff the current option came from root */
int option_line = 0; /* line number in file */
bool log_to_file; /* log_to_fd is a file opened by us */
bool log_to_specific_fd; /* log_to_fd was specified by user option */
/*
* Prototypes.
*/
static int setdevname __P((char *));
#ifdef PLUGIN
#endif
#ifdef PPP_FILTER
#endif /* PPP_FILTER */
typedef struct _opt_t {
option_t *p;
} opt_t;
typedef struct _hashentry_t {
struct _hashentry_t *next;
} hashentry_t;
/*
* A prime number describing the size of hash table.
*/
#define OPTHASH_TBLSIZE 101
/*
* Chained hash table containing pointers to available options.
*/
/*
* Total number of entries in the hash table.
*/
int hash_tblcnt = 0;
/*
* Valid arguments.
*/
option_t general_options[] = {
"Set kernel driver debug level" },
"Don't detach from controlling tty", 1 },
"Don't detach from controlling tty", 1 },
"Detach from controlling tty once link is up", 1 },
"Set time in seconds before retrying connection" },
"Set time in seconds before disconnecting idle link" },
"Lock serial device with UUCP-style lock file", 1 },
"A program to initialize the device",
"A program to set up a connection",
"Program to disconnect serial device",
"Script to welcome client",
"Script to run on pseudo-tty master side",
"Send and receive over socket, arg is host:port", OPT_DEVNAM },
"Add given domain name to hostname" },
"set netmask" },
"Use modem control lines", 1 },
"Don't use modem control lines" },
"Take options from a file", OPT_PREPASS },
"Take options from a privileged file", OPT_PREPASS },
"Keep on reopening connection after close", 1 },
"Turn off persist option" },
"Show version number" },
"Show brief listing of options" },
"Show brief listing of options" },
"Show full listing of options" },
"Use synchronous HDLC serial encoding", 1 },
"Send log messages to this file descriptor",
0, &log_to_specific_fd },
"Append log messages to this file" },
"Don't send log messages to any file",
"Don't send log messages to any file descriptor",
"Set logical name for link",
"Number of unsuccessful connection attempts to allow" },
"Alter kernel settings as necessary", 1 },
"Don't alter kernel settings", 0 },
"Maximum wait time (msec) after connect script finishes" },
"PPP interface unit number to use if possible", OPT_LLIMIT, 0, 0 },
#ifdef HAVE_MULTILINK
"Enable multilink operation", 1 },
"Disable multilink operation", 0 },
"Enable multilink operation", 1 },
"Disable multilink operation", 0 },
"Bundle name for multilink" },
#endif /* HAVE_MULTILINK */
#ifdef PLUGIN
"Load a plug-in module into pppd", OPT_PRIV },
#endif /* PLUGIN */
#ifdef PPP_FILTER
"libpcap debugging" },
"set filter for packets to pass" },
"set filter for active pkts" },
#endif /* PPP_FILTER */
{ NULL }
};
/*
* This string gets printed out when "options" is given on the command
* line. Following this string, all of the available options and
* their descriptions are printed out as well. Certain options which
* are not available as part of the option_t structure are placed in
* the "dummy" option structure.
*/
static const char pre_allopt_string[] = "\
pppd version %s.%d%s\n\
Usage: %s [ options ], where options are:\n\n\
";
/* Do not call add_options() on this structure */
static option_t dummy_options[] = {
"Communicate over the named device" },
"Set the baud rate to <speed>" },
{ NULL }
};
static const char post_allopt_string[] = "\
\n\
Notes:\
\t<n>\tinteger type argument\n\
\t<s>\tstring type argument\n\
\t<r>\tspecial type argument\n\
\t(!)\tprivileged option available only when pppd is executed by root\n\
\t\t\"--\" in /etc/ppp/pap-secrets or /etc/ppp/chap-secrets).\n\
\t(#)\tdisabled option\n\
\n\
Please see the pppd man page for details.\n";
/*
* parse_args - parse a string of arguments from the command line. If prepass
* is true, we are scanning for the device name and only processing a few
* options, so error messages are suppressed. Returns 1 upon successful
* processing of options, and 0 otherwise.
*/
int
int argc;
char **argv;
{
char *arg;
int ret;
option_source = "command line";
option_line = 0;
while (argc > 0) {
--argc;
/*
* First check to see if it's a known option name. If so, parse the
* argument(s) and set the option.
*/
int n = n_arguments(opt);
if (argc < n) {
return (0);
}
return (0);
argc -= n;
argv += n;
continue;
}
/*
* Maybe a tty name, speed or IP address ?
*/
usage();
return (0);
}
if (ret < 0) /* error */
return (0);
}
return (1);
}
/*
* options_from_file - read a string of options from a file, and
* interpret them. Returns 1 upon successful processing of options,
* and 0 otherwise.
*/
int
#ifdef __STDC__
#else
char *filename;
bool must_exist;
bool check_prot;
bool priv;
#endif
{
FILE *f;
bool oldpriv;
char *oldsource;
char cmd[MAXWORDLEN];
static bool firsterr = 1;
static int nestlevel = 0;
if (nestlevel >= MAXFILENESTING) {
option_error("file nesting too deep");
return (0);
}
if (check_prot)
errno = 0;
if (check_prot)
(void) seteuid(0);
if (f == NULL) {
return (1);
return (0);
}
nestlevel++;
/*
* strdup() is used here because the pointer might refer to the
* caller's automatic (stack) storage, and the option_info array
* records the source file name.
*/
option_line = 1;
if (option_source == NULL)
option_source = "file";
ret = 0;
sline = option_line;
/*
* First see if it's a command.
*/
int n = n_arguments(opt);
for (i = 0; i < n; ++i) {
goto err;
}
}
goto err;
}
goto err;
continue;
}
/*
* Maybe a tty name, speed or IP address ?
*/
if (((i = setdevname(cmd)) == 0) &&
goto err;
}
if (i < 0) /* error */
goto err;
}
ret = 1;
err:
(void) fclose(f);
/* We assume here that we abort all processing on the first error. */
if (firsterr)
firsterr = 0;
option_error("error in included file");
/*
* Cannot free option_source because it might be referenced in one
* or more option_info structures now.
*/
nestlevel--;
return (ret);
}
/*
* options_from_user - see if the user has a ~/.ppprc file, and if so,
* interpret options from it. Returns 1 upon successful processing of
* options, and 0 otherwise.
*/
int
{
int ret;
return (1);
novm("init file name");
return (ret);
}
/*
* options_for_tty - see if an options file exists for the serial device, and
* if so, interpret options from it. Returns 1 upon successful processing of
* options, and 0 otherwise.
*/
int
{
int ret;
dev += 5;
return (1); /* don't look for /etc/ppp/options.tty */
novm("tty init file name");
if (*p == '/')
*p = '.';
return (ret);
}
/*
* options_from_list - process a string of options in a wordlist. Returns 1
* upon successful processing of options, and 0 otherwise.
*/
int
#ifdef __STDC__
#else
(w, priv)
struct wordlist *w;
bool priv;
#endif
{
int i, ret = 0;
/* Caller is expected to set option_source and option_line. */
while (w != NULL) {
/*
* First see if it's a command.
*/
int n = n_arguments(opt);
for (i = 0; i < n; ++i) {
w = w->next;
if (w == NULL) {
option_error("too few parameters for option '%s'",
goto err;
}
}
goto err;
continue;
}
/*
* Options from the {p,ch}ap-secrets files can't change the device
* name nor the speed. Therefore, calls to setdevname() and
* setspeed() were removed.
*/
goto err;
}
if (i < 0) /* error */
goto err;
}
ret = 1;
err:
return (ret);
}
/*
* find_option - scan the option lists for the various protocols looking for an
* entry with the given name. Returns a pointer to the matching option_t
* structure upon successful processing of options, and NULL otherwise.
*/
static option_t *
char *name;
{
}
}
}
return (NULL);
}
/*
* process_option - process one new-style option (something other than a
* port name, bit rate, or IP address). Returns 1 upon successful
* processing of options, and 0 otherwise.
*/
static int
char **argv;
int sline;
{
u_int32_t v;
int iv, a;
char *sv;
return (1);
return (0);
}
option_error("using the '%s' option requires root privilege",
return (0);
}
return (0);
}
return (0);
}
}
case o_bool:
break;
case o_int:
iv = 0;
return (0);
case OPT_LLIMIT:
option_error("%s value must be%s >= %d",
break;
case OPT_ULIMIT:
option_error("%s value must be%s <= %d",
break;
case OPT_LIMITS:
option_error("%s value must be%s between %d and %d",
break;
}
return (0);
}
}
if (a >= 128)
a -= 256; /* sign extend */
iv += a;
if (oldv > 0) {
option_error("%s value cannot be set to infinity; limited to %d",
return (0);
}
option_error("%s value cannot be increased beyond %d",
return (0);
}
}
break;
case o_uint32:
return (0);
break;
case o_string:
}
} else {
novm("option argument");
}
break;
case o_special_noarg:
case o_special:
return (0);
break;
}
}
return (1);
}
/*
* n_arguments - tell how many arguments an option takes. Returns 1 upon
* successful processing of options, and 0 otherwise.
*/
static int
{
}
/*
* opt_hash - a hash function that works quite well for strings. Returns
* the hash key of the supplied string.
*/
static u_int32_t
const void *key;
{
register const char *ptr;
val = 0;
while (*ptr != '\0') {
int tmp;
if (tmp) {
}
ptr++;
}
return (val % OPTHASH_TBLSIZE);
}
/*
* add_options - add a list of options to the chained hash table.
* Also detect duplicate options, and if found, disable the older
* definition and log it as an error.
*/
void
{
register hashentry_t *bucket;
/* fill hash-table */
/* first, allocate a hash entry */
novm("option hash table entry");
}
/*
* fill the chained hash table and take care of any collisions or
* duplicate items.
*/
for (;;) {
info("option '%s' redefined; old definition disabled",
}
break;
}
} else {
}
}
}
/*
* remove_option - disable an option. Returns the option_t structure
* of the disabled option, or NULL if the option name is invalid or if
* the option has already been disabled.
*/
option_t *
char *name;
{
}
return (opt);
}
/*
* opt_compare - a compare function supplied to the quicksort routine.
* Returns an integer less than, equal to, or greater than zero to indicate
* if the first argument is considered less than, equal to, or greater
* than the second argument.
*/
static int
const void *p1;
const void *p2;
{
}
/*ARGSUSED*/
static int
char **argv;
{
#define MAXOPTSTRLEN 257
#define PRINTOPTIONS() { \
} \
} \
}
char opt_str[MAXOPTSTRLEN];
int i, sofar;
if (phase != PHASE_INITIALIZE) {
return (0);
}
progname);
PRINTOPTIONS();
}
novm("sorted option table");
}
sofar = 0;
for (i = 0; i < OPTHASH_TBLSIZE; i++) {
if (sofar >= hash_tblcnt) {
fatal("options hash table corrupted; size mismatch");
}
}
}
for (i = 0; i < sofar; i++) {
PRINTOPTIONS();
}
(void) printf(post_allopt_string);
return (0);
}
/*
* usage - print out a message telling how to use the program.
* This string gets printed out when either "--help" or an invalid option
* is specified.
*/
static void
usage()
{
static const char usage_string[] = "\
pppd version %s.%d%s\n\
Usage: %s [ options ], where options are:\n\
\t<device>\tCommunicate over the named device\n\
\t<speed>\t\tSet the baud rate to <speed>\n\
\t\t\taddresses. Either one may be omitted.\n\
\tnoauth\t\tDon't require authentication from peer\n\
\tconnect <p>\tInvoke shell command <p> to set up the serial line\n\
\tdefaultroute\tAdd default route through interface\n\
Use \"%s options\" or \"man pppd\" for more options.\n\
";
if (phase == PHASE_INITIALIZE)
}
/*
* showhelp - print out usage message and exit program upon success, or
* return 0 otherwise.
*/
/*ARGSUSED*/
static int
char **argv;
{
if (phase == PHASE_INITIALIZE) {
usage();
exit(0);
}
return (0);
}
/*
* showversion - print out the version number and exit program upon success,
* or return 0 otherwise.
*/
/*ARGSUSED*/
static int
char **argv;
{
if (phase == PHASE_INITIALIZE) {
exit(0);
}
return (0);
}
/*
* option_error - print a message about an error in an option. The message is
* logged, and also sent to stderr if phase == PHASE_INITIALIZE.
*/
void
{
char buf[256];
int i, err;
#if defined(__STDC__)
#else
char *fmt;
#endif
if (prepass) {
return;
}
if (option_source == NULL) {
i = 0;
} else if (option_line <= 0) {
} else {
}
if (i != 0) {
i += 2;
}
}
/*
* getword - read a word from a file. Words are delimited by white-space or by
* quotes (" or '). Quotes, white-space and \ may be escaped with \.
* \<newline> is ignored. Returns 1 upon successful processing of options,
* and 0 otherwise.
*/
int
FILE *f;
char *word;
int *newlinep;
char *filename;
{
*newlinep = 0;
len = 0;
escape = 0;
comment = 0;
/*
* First skip white-space and comments.
*/
for (;;) {
c = getc(f);
if (c == EOF)
break;
/*
* A newline means the end of a comment; backslash-newline
* is ignored. Note that we cannot have escape && comment.
*/
if (c == '\n') {
option_line++;
if (!escape) {
*newlinep = 1;
comment = 0;
} else
escape = 0;
continue;
}
/*
* Ignore characters other than newline in a comment.
*/
if (comment)
continue;
/*
* If this character is escaped, we have a word start.
*/
if (escape)
break;
/*
* If this is the escape character, look at the next character.
*/
if (c == '\\') {
escape = 1;
continue;
}
/*
* If this is the start of a comment, ignore the rest of the line.
*/
if (c == '#') {
comment = 1;
continue;
}
/*
* A non-whitespace character is the start of a word.
*/
if (!isspace(c))
break;
}
/*
* Save the delimiter for quoted strings.
*/
quoted = c;
c = getc(f);
} else
quoted = 0;
/*
* Process characters until the end of the word.
*/
while (c != EOF) {
if (escape) {
/*
* This character is escaped: backslash-newline is ignored,
* various other characters indicate particular values
* as for C backslash-escapes.
*/
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)) {
/*
* \ddd octal sequence
*/
value = 0;
for (n = 0; n < 3 && isoctal(c); ++n) {
c = getc(f);
}
got = 1;
break;
}
if (c == 'x') {
/*
* \x<hex_string> sequence
*/
value = 0;
c = getc(f);
for (n = 0; n < 2 && isxdigit(c); ++n) {
c = getc (f);
}
got = 1;
break;
}
/*
* Otherwise the character stands for itself.
*/
value = c;
break;
}
/*
* Store the resulting character for the escape sequence.
*/
if (len < MAXWORDLEN) {
++len;
}
if (!got)
c = getc(f);
continue;
}
/*
* Not escaped: see if we've reached the end of the word.
*/
if (quoted) {
if (c == quoted)
break;
} else {
if (isspace(c) || c == '#') {
(void) ungetc (c, f);
break;
}
}
/*
* Backslash starts an escape sequence.
*/
if (c == '\\') {
escape = 1;
c = getc(f);
continue;
}
/*
* An ordinary character: store it in the word and get another.
*/
if (len < MAXWORDLEN) {
++len;
}
c = getc(f);
}
/*
* End of the word: check for errors.
*/
if (c == EOF) {
if (ferror(f)) {
if (errno == 0)
die(1);
}
/*
* If len is zero, then we didn't find a word before the
* end of the file.
*/
if (len == 0)
return (0);
}
/*
* Warn if the word was too long, and append a terminating null.
*/
if (len >= MAXWORDLEN) {
option_error("warning: word in file %s too long (%.20s...)",
}
return (1);
}
/*
* number_option - parse an unsigned numeric parameter for an option.
* Returns 1 upon successful processing of options, and 0 otherwise.
*/
static int
char *str;
int base;
{
char *ptr;
option_error("invalid numeric parameter '%s' for '%s' option",
return (0);
}
return (1);
}
/*
* save_source - store option source, line, and privilege into an
* option_info structure.
*/
void
struct option_info *info;
{
}
/*
* set_source - set option source, line, and privilege from an
* option_info structure.
*/
void
struct option_info *info;
{
}
/*
* name_source - return string containing option source and line. Can
* be used as part of an option_error call.
*/
const char *
struct option_info *info;
{
static char buf[MAXPATHLEN];
return "none";
return (const char *)buf;
}
/*
* int_option - like number_option, but valp is int *, the base is assumed to
* be 0, and *valp is not changed if there is an error. Returns 1 upon
* successful processing of options, and 0 otherwise.
*/
int
char *str;
int *valp;
{
u_int32_t v;
if (!number_option(str, &v, 0))
return (0);
*valp = (int) v;
return (1);
}
/*
* The following procedures parse options.
*/
/*
* readfile - take commands from a file.
*/
/*ARGSUSED*/
static int
char **argv;
{
}
/*
* /../, start with / or ../, or end in /. Returns 1 upon successful
* processing of options, and 0 otherwise.
*/
/*ARGSUSED*/
static int
char **argv;
{
int l, ok;
ok = 1;
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);
}
novm("call file name");
return (ok);
}
#ifdef PPP_FILTER
/*
* setpdebug - set libpcap debugging level. Returns 1 upon successful
* processing of options, and 0 otherwise.
*/
static int
char **argv;
{
}
/*
* setpassfilter - set the pass filter for packets. Returns 1 upon successful
* processing of options, and 0 otherwise.
*/
/*ARGSUSED*/
static int
char **argv;
{
return (1);
return (0);
}
/*
* setactivefilter - set the active filter for packets. Returns 1 upon
* successful processing of options, and 0 otherwise.
*/
/*ARGSUSED*/
static int
char **argv;
{
return (1);
return (0);
}
#endif /* PPP_FILTER */
/*
* noopt - disable all options. Returns 1 upon successful processing of
* options, and 0 otherwise.
*/
/*ARGSUSED*/
static int
char **argv;
{
return (1);
}
/*
* setdomain - set domain name to append to hostname. Returns 1 upon
* successful processing of options, and 0 otherwise.
*/
/*ARGSUSED*/
static int
char **argv;
{
if (!privileged_option) {
option_error("using the domain option requires root privilege");
return (0);
}
if (**argv != '\0') {
if (**argv != '.')
}
return (1);
}
/*
* setspeed - set the speed. Returns 1 upon successful processing of options,
* and 0 otherwise.
*/
static int
char *arg;
{
char *ptr;
int spd;
if (prepass)
return (1);
return (0);
return (1);
}
/*
* setdevname - set the device name. Returns 1 upon successful processing of
* options, 0 when the device does not exist, and -1 when an error is
* encountered.
*/
static int
char *cp;
{
char dev[MAXPATHLEN];
if (*cp == '\0')
return (0);
}
/*
* Check if there is a character device by this name.
*/
return (0);
}
return (-1);
}
return (-1);
}
if (phase != PHASE_INITIALIZE) {
option_error("device name cannot be changed after initialization");
return (-1);
} else if (devnam_fixed) {
option_error("per-tty options file may not specify device name");
return (-1);
}
option_error("device name %s from %s cannot be overridden",
return (-1);
}
default_device = 0;
return (1);
}
/*
* setipaddr - set the IP address. Returns 1 upon successful processing of
* options, 0 when the argument does not contain a `:', and -1 for error.
*/
static int
char *arg;
{
char *colon;
/*
* IP address pair separated by ":".
*/
return (0);
if (prepass)
return (1);
/*
* If colon first character, then no local addr.
*/
*colon = '\0';
return (-1);
} else {
}
}
if (bad_ip_adrs(local)) {
return (-1);
}
if (local != 0) {
}
*colon = ':';
}
/*
* If colon last character, then no remote addr.
*/
if (*++colon != '\0') {
return (-1);
} else {
if (remote_name[0] == '\0')
}
}
if (bad_ip_adrs(remote)) {
return (-1);
}
if (remote != 0) {
}
}
return (1);
}
/*
* setnetmask - set the netmask to be used on the interface. Returns 1 upon
* successful processing of options, and 0 otherwise.
*/
/*ARGSUSED*/
static int
char **argv;
{
int n;
char *p;
/*
* Unfortunately, if we use inet_addr, we can't tell whether
* a result of all 1s is an error or a valid 255.255.255.255.
*/
p = *argv;
n = parse_dotted_ip(p, &mask);
return (0);
}
return (1);
}
/*
* parse_dotted_ip - parse and convert the IP address string to make
* sure it conforms to the dotted notation. Returns the length of
* processed characters upon success, and 0 otherwise. If successful,
* the converted IP address number is stored in vp, in the host byte
* order.
*/
int
register char *cp;
{
register char c;
return (0); /* disallow null string in cp */
*vp = 0;
/*
* Collect number up to ``.''. Values are specified as for C:
* 0x=hex, 0=octal, other=decimal.
*/
if (*cp == '0') {
else
base = 8;
}
while ((c = *cp) != '\0') {
if (isdigit(c)) {
if ((c - '0') >= base)
break;
cp++;
continue;
}
cp++;
continue;
}
break;
}
if (*cp == '.') {
/*
* Internet format:
* a.b.c.d
* a.b.c (with c treated as 16-bits)
* a.b (with b treated as 24 bits)
*/
return (0);
}
cp++;
goto again;
}
/*
* Check for trailing characters.
*/
return (0);
}
/*
* Concoct the address according to the number of parts specified.
*/
switch (n) {
case 0: /* a -- 32 bits */
break;
case 1: /* a.b -- 8.24 bits */
if (val > 0xffffff)
return (0);
break;
case 2: /* a.b.c -- 8.8.16 bits */
if (val > 0xffff)
return (0);
break;
case 3: /* a.b.c.d -- 8.8.8.8 bits */
if (val > 0xff)
return (0);
break;
default:
return (0);
}
}
/*
* setxonxoff - modify the asyncmap to include escaping XON and XOFF
* characters used for software flow control. Returns 1 upon successful
* processing of options, and 0 otherwise.
*/
/*ARGSUSED*/
static int
char **argv;
{
int xonxoff = 0x000A0000;
crtscts = -2;
return (1);
}
/*
* setlogfile - open (or create) a file used for logging purposes. Returns 1
* upon success, and 0 otherwise.
*/
/*ARGSUSED*/
static int
char **argv;
{
if (!privileged_option)
if (!privileged_option)
(void) seteuid(0);
if (fd < 0) {
return (0);
}
if (log_to_file && log_to_fd >= 0)
log_to_file = 1;
early_log = 0;
return (1);
}
#ifdef PLUGIN
/*
* loadplugin - load and initialize the plugin. Returns 1 upon successful
* processing of the plugin, and 0 otherwise.
*/
/*ARGSUSED*/
static int
char **argv;
{
void *handle;
const char *err;
return (0);
}
return (0);
}
(*init)();
return (1);
}
#endif /* PLUGIN */