2 * options.c - handles option processing for PPP.
4 * Copyright (c) 1989 Carnegie Mellon University.
7 * Redistribution and use in source and binary forms are permitted
8 * provided that the above copyright notice and this paragraph are
9 * duplicated in all such forms and that any documentation,
10 * advertising materials, and other materials related to such
11 * distribution and use acknowledge that the software was developed
12 * by Carnegie Mellon University. The name of the
13 * University may not be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 static char rcsid[] = "$Id: options.c,v 1.31 1996/05/27 00:04:47 paulus Exp $";
35 #include <sys/types.h>
37 #include <netinet/in.h>
38 #include <arpa/inet.h>
41 #include "pathnames.h"
42 #include "patchlevel.h"
52 #endif /* IPX_CHANGE */
54 #include <net/ppp-comp.h>
59 #if defined(ultrix) || defined(NeXT)
60 char *strdup __P((char *));
64 #define GIDSET_TYPE gid_t
68 * Option variables and default values.
70 int debug = 0; /* Debug flag */
71 int kdebugflag = 0; /* Tell kernel to print debug messages */
72 int default_device = 1; /* Using /dev/tty or equivalent */
73 char devnam[MAXPATHLEN] = "/dev/tty"; /* Device name */
74 int crtscts = 0; /* Use hardware flow control */
75 int modem = 1; /* Use modem control lines */
76 int inspeed = 0; /* Input/Output speed requested */
77 u_int32_t netmask = 0; /* IP netmask to set on interface */
78 int lockflag = 0; /* Create lock file to lock the serial dev */
79 int nodetach = 0; /* Don't detach from controlling tty */
80 char *connector = NULL; /* Script to establish physical link */
81 char *disconnector = NULL; /* Script to disestablish physical link */
82 char *welcomer = NULL; /* Script to run after phys link estab. */
83 int maxconnect = 0; /* Maximum connect time */
84 char user[MAXNAMELEN]; /* Username for PAP */
85 char passwd[MAXSECRETLEN]; /* Password for PAP */
86 int auth_required = 0; /* Peer is required to authenticate */
87 int defaultroute = 0; /* assign default route through interface */
88 int proxyarp = 0; /* Set up proxy ARP entry for peer */
89 int persist = 0; /* Reopen link after it goes down */
90 int uselogin = 0; /* Use /etc/passwd for checking PAP */
91 int lcp_echo_interval = 0; /* Interval between LCP echo-requests */
92 int lcp_echo_fails = 0; /* Tolerance to unanswered echo-requests */
93 char our_name[MAXNAMELEN]; /* Our name for authentication purposes */
94 char remote_name[MAXNAMELEN]; /* Peer's name for authentication */
95 int usehostname = 0; /* Use hostname for our_name */
96 int disable_defaultip = 0; /* Don't use hostname for default IP adrs */
97 int demand = 0; /* do dial-on-demand */
98 char *ipparam = NULL; /* Extra parameter for ip up/down scripts */
99 int cryptpap; /* Passwords in pap-secrets are encrypted */
100 int idle_time_limit = 0; /* Disconnect if idle for this many seconds */
101 int holdoff = 30; /* # seconds to pause before reconnecting */
106 static int setdevname __P((char *));
107 static int setipaddr __P((char *));
108 static int setdebug __P((void));
109 static int setkdebug __P((char **));
110 static int setpassive __P((void));
111 static int setsilent __P((void));
112 static int noopt __P((void));
113 static int setnovj __P((void));
114 static int setnovjccomp __P((void));
115 static int setvjslots __P((char **));
116 static int reqpap __P((void));
117 static int nopap __P((void));
119 static int setupapfile __P((char **));
121 static int nochap __P((void));
122 static int reqchap __P((void));
123 static int setspeed __P((char *));
124 static int noaccomp __P((void));
125 static int noasyncmap __P((void));
126 static int noip __P((void));
127 static int nomagicnumber __P((void));
128 static int setasyncmap __P((char **));
129 static int setescape __P((char **));
130 static int setmru __P((char **));
131 static int setmtu __P((char **));
132 static int nomru __P((void));
133 static int nopcomp __P((void));
134 static int setconnector __P((char **));
135 static int setdisconnector __P((char **));
136 static int setwelcomer __P((char **));
137 static int setmaxconnect __P((char **));
138 static int setdomain __P((char **));
139 static int setnetmask __P((char **));
140 static int setcrtscts __P((void));
141 static int setnocrtscts __P((void));
142 static int setxonxoff __P((void));
143 static int setnodetach __P((void));
144 static int setmodem __P((void));
145 static int setlocal __P((void));
146 static int setlock __P((void));
147 static int setname __P((char **));
148 static int setuser __P((char **));
149 static int setremote __P((char **));
150 static int setauth __P((void));
151 static int readfile __P((char **));
152 static int setdefaultroute __P((void));
153 static int setnodefaultroute __P((void));
154 static int setproxyarp __P((void));
155 static int setnoproxyarp __P((void));
156 static int setpersist __P((void));
157 static int setdologin __P((void));
158 static int setusehostname __P((void));
159 static int setnoipdflt __P((void));
160 static int setlcptimeout __P((char **));
161 static int setlcpterm __P((char **));
162 static int setlcpconf __P((char **));
163 static int setlcpfails __P((char **));
164 static int setipcptimeout __P((char **));
165 static int setipcpterm __P((char **));
166 static int setipcpconf __P((char **));
167 static int setipcpfails __P((char **));
168 static int setpaptimeout __P((char **));
169 static int setpapreqs __P((char **));
170 static int setpapreqtime __P((char **));
171 static int setchaptimeout __P((char **));
172 static int setchapchal __P((char **));
173 static int setchapintv __P((char **));
174 static int setipcpaccl __P((void));
175 static int setipcpaccr __P((void));
176 static int setlcpechointv __P((char **));
177 static int setlcpechofails __P((char **));
178 static int noccp __P((void));
179 static int setbsdcomp __P((char **));
180 static int setnobsdcomp __P((void));
181 static int setdeflate __P((char **));
182 static int setnodeflate __P((void));
183 static int setdemand __P((void));
184 static int setpred1comp __P((void));
185 static int setnopred1comp __P((void));
186 static int setipparam __P((char **));
187 static int setpapcrypt __P((void));
188 static int setidle __P((char **));
189 static int setholdoff __P((char **));
191 static int setpassfilter __P((char **));
192 static int setactivefilter __P((char **));
196 static int setipxproto __P((void));
197 static int resetipxproto __P((void));
198 static int setipxanet __P((void));
199 static int setipxalcl __P((void));
200 static int setipxarmt __P((void));
201 static int setipxnetwork __P((char **));
202 static int setipxnode __P((char **));
203 static int setipxrouter __P((char **));
204 static int setipxname __P((char **));
205 static int setipxcptimeout __P((char **));
206 static int setipxcpterm __P((char **));
207 static int setipxcpconf __P((char **));
208 static int setipxcpfails __P((char **));
209 #endif /* IPX_CHANGE */
212 static int setdnsaddr __P((char **));
215 static int number_option __P((char *, u_int32_t *, int));
216 static int int_option __P((char *, int *));
217 static int readable __P((int fd));
218 static void option_error __P((char *fmt, ...));
228 {"-all", 0, noopt}, /* Don't request/allow any options (useless) */
229 {"noaccomp", 0, noaccomp}, /* Disable Address/Control compression */
230 {"-ac", 0, noaccomp}, /* Disable Address/Control compress */
231 {"default-asyncmap", 0, noasyncmap}, /* Disable asyncmap negoatiation */
232 {"-am", 0, noasyncmap}, /* Disable asyncmap negotiation */
233 {"-as", 1, setasyncmap}, /* set the desired async map */
234 {"-d", 0, setdebug}, /* Increase debugging level */
235 {"nodetach", 0, setnodetach}, /* Don't detach from controlling tty */
236 {"-detach", 0, setnodetach}, /* don't fork */
237 {"noip", 0, noip}, /* Disable IP and IPCP */
238 {"-ip", 0, noip}, /* Disable IP and IPCP */
239 {"nomagic", 0, nomagicnumber}, /* Disable magic number negotiation */
240 {"-mn", 0, nomagicnumber}, /* Disable magic number negotiation */
241 {"default-mru", 0, nomru}, /* Disable MRU negotiation */
242 {"-mru", 0, nomru}, /* Disable mru negotiation */
243 {"-p", 0, setpassive}, /* Set passive mode */
244 {"nopcomp", 0, nopcomp}, /* Disable protocol field compression */
245 {"-pc", 0, nopcomp}, /* Disable protocol field compress */
247 {"+ua", 1, setupapfile}, /* Get PAP user and password from file */
249 {"require-pap", 0, reqpap}, /* Require PAP authentication from peer */
250 {"+pap", 0, reqpap}, /* Require PAP auth from peer */
251 {"refuse-pap", 0, nopap}, /* Don't agree to auth to peer with PAP */
252 {"-pap", 0, nopap}, /* Don't allow UPAP authentication with peer */
253 {"require-chap", 0, reqchap}, /* Require CHAP authentication from peer */
254 {"+chap", 0, reqchap}, /* Require CHAP authentication from peer */
255 {"refuse-chap", 0, nochap}, /* Don't agree to auth to peer with CHAP */
256 {"-chap", 0, nochap}, /* Don't allow CHAP authentication with peer */
257 {"novj", 0, setnovj}, /* Disable VJ compression */
258 {"-vj", 0, setnovj}, /* disable VJ compression */
259 {"novjccomp", 0, setnovjccomp}, /* disable VJ connection-ID compression */
260 {"-vjccomp", 0, setnovjccomp}, /* disable VJ connection-ID compression */
261 {"vj-max-slots", 1, setvjslots}, /* Set maximum VJ header slots */
262 {"asyncmap", 1, setasyncmap}, /* set the desired async map */
263 {"escape", 1, setescape}, /* set chars to escape on transmission */
264 {"connect", 1, setconnector}, /* A program to set up a connection */
265 {"disconnect", 1, setdisconnector}, /* program to disconnect serial dev. */
266 {"welcome", 1, setwelcomer},/* Script to welcome client */
267 {"maxconnect", 1, setmaxconnect}, /* specify a maximum connect time */
268 {"crtscts", 0, setcrtscts}, /* set h/w flow control */
269 {"nocrtscts", 0, setnocrtscts}, /* clear h/w flow control */
270 {"-crtscts", 0, setnocrtscts}, /* clear h/w flow control */
271 {"xonxoff", 0, setxonxoff}, /* set s/w flow control */
272 {"debug", 0, setdebug}, /* Increase debugging level */
273 {"kdebug", 1, setkdebug}, /* Enable kernel-level debugging */
274 {"domain", 1, setdomain}, /* Add given domain name to hostname*/
275 {"mru", 1, setmru}, /* Set MRU value for negotiation */
276 {"mtu", 1, setmtu}, /* Set our MTU */
277 {"netmask", 1, setnetmask}, /* set netmask */
278 {"passive", 0, setpassive}, /* Set passive mode */
279 {"silent", 0, setsilent}, /* Set silent mode */
280 {"modem", 0, setmodem}, /* Use modem control lines */
281 {"local", 0, setlocal}, /* Don't use modem control lines */
282 {"lock", 0, setlock}, /* Lock serial device (with lock file) */
283 {"name", 1, setname}, /* Set local name for authentication */
284 {"user", 1, setuser}, /* Set username for PAP auth with peer */
285 {"usehostname", 0, setusehostname}, /* Must use hostname for auth. */
286 {"remotename", 1, setremote}, /* Set remote name for authentication */
287 {"auth", 0, setauth}, /* Require authentication from peer */
288 {"file", 1, readfile}, /* Take options from a file */
289 {"defaultroute", 0, setdefaultroute}, /* Add default route */
290 {"nodefaultroute", 0, setnodefaultroute}, /* disable defaultroute option */
291 {"-defaultroute", 0, setnodefaultroute}, /* disable defaultroute option */
292 {"proxyarp", 0, setproxyarp}, /* Add proxy ARP entry */
293 {"noproxyarp", 0, setnoproxyarp}, /* disable proxyarp option */
294 {"-proxyarp", 0, setnoproxyarp}, /* disable proxyarp option */
295 {"persist", 0, setpersist}, /* Keep on reopening connection after close */
296 {"demand", 0, setdemand}, /* Dial on demand */
297 {"login", 0, setdologin}, /* Use system password database for UPAP */
298 {"noipdefault", 0, setnoipdflt}, /* Don't use name for default IP adrs */
299 {"lcp-echo-failure", 1, setlcpechofails}, /* consecutive echo failures */
300 {"lcp-echo-interval", 1, setlcpechointv}, /* time for lcp echo events */
301 {"lcp-restart", 1, setlcptimeout}, /* Set timeout for LCP */
302 {"lcp-max-terminate", 1, setlcpterm}, /* Set max #xmits for term-reqs */
303 {"lcp-max-configure", 1, setlcpconf}, /* Set max #xmits for conf-reqs */
304 {"lcp-max-failure", 1, setlcpfails}, /* Set max #conf-naks for LCP */
305 {"ipcp-restart", 1, setipcptimeout}, /* Set timeout for IPCP */
306 {"ipcp-max-terminate", 1, setipcpterm}, /* Set max #xmits for term-reqs */
307 {"ipcp-max-configure", 1, setipcpconf}, /* Set max #xmits for conf-reqs */
308 {"ipcp-max-failure", 1, setipcpfails}, /* Set max #conf-naks for IPCP */
309 {"pap-restart", 1, setpaptimeout}, /* Set retransmit timeout for PAP */
310 {"pap-max-authreq", 1, setpapreqs}, /* Set max #xmits for auth-reqs */
311 {"pap-timeout", 1, setpapreqtime}, /* Set time limit for peer PAP auth. */
312 {"chap-restart", 1, setchaptimeout}, /* Set timeout for CHAP */
313 {"chap-max-challenge", 1, setchapchal}, /* Set max #xmits for challenge */
314 {"chap-interval", 1, setchapintv}, /* Set interval for rechallenge */
315 {"ipcp-accept-local", 0, setipcpaccl}, /* Accept peer's address for us */
316 {"ipcp-accept-remote", 0, setipcpaccr}, /* Accept peer's address for it */
317 {"noccp", 0, noccp}, /* Disable CCP negotiation */
318 {"-ccp", 0, noccp}, /* Disable CCP negotiation */
319 {"bsdcomp", 1, setbsdcomp}, /* request BSD-Compress */
320 {"nobsdcomp", 0, setnobsdcomp}, /* don't allow BSD-Compress */
321 {"-bsdcomp", 0, setnobsdcomp}, /* don't allow BSD-Compress */
322 {"deflate", 1, setdeflate}, /* request Deflate compression */
323 {"nodeflate", 0, setnodeflate}, /* don't allow Deflate compression */
324 {"-deflate", 0, setnodeflate}, /* don't allow Deflate compression */
325 {"predictor1", 0, setpred1comp}, /* request Predictor-1 */
326 {"nopredictor1", 0, setnopred1comp},/* don't allow Predictor-1 */
327 {"-predictor1", 0, setnopred1comp}, /* don't allow Predictor-1 */
328 {"ipparam", 1, setipparam}, /* set ip script parameter */
329 {"papcrypt", 0, setpapcrypt}, /* PAP passwords encrypted */
330 {"idle", 1, setidle}, /* idle time limit (seconds) */
331 {"holdoff", 1, setholdoff}, /* set holdoff time (seconds) */
333 {"pass-filter", 1, setpassfilter}, /* set filter for packets to pass */
334 {"active-filter", 1, setactivefilter}, /* set filter for active pkts */
338 {"ipx-network", 1, setipxnetwork}, /* IPX network number */
339 {"ipxcp-accept-network", 0, setipxanet}, /* Accept peer netowrk */
340 {"ipx-node", 1, setipxnode}, /* IPX node number */
341 {"ipxcp-accept-local", 0, setipxalcl}, /* Accept our address */
342 {"ipxcp-accept-remote", 0, setipxarmt}, /* Accept peer's address */
343 {"ipx-routing", 1, setipxrouter}, /* IPX routing proto number */
344 {"ipx-router-name", 1, setipxname}, /* IPX router name */
345 {"ipxcp-restart", 1, setipxcptimeout}, /* Set timeout for IPXCP */
346 {"ipxcp-max-terminate", 1, setipxcpterm}, /* max #xmits for term-reqs */
347 {"ipxcp-max-configure", 1, setipxcpconf}, /* max #xmits for conf-reqs */
348 {"ipxcp-max-failure", 1, setipxcpfails}, /* max #conf-naks for IPXCP */
350 {"ipx-compression", 1, setipxcompression}, /* IPX compression number */
352 {"ipx", 0, setipxproto}, /* Enable IPXCP (and IPX) */
353 {"noipx", 0, resetipxproto}, /* Disable IPXCP (and IPX) */
354 {"+ipx", 0, setipxproto}, /* Enable IPXCP (and IPX) */
355 {"-ipx", 0, resetipxproto}, /* Disable IPXCP (and IPX) */
356 #endif /* IPX_CHANGE */
359 {"ms-dns", 1, setdnsaddr}, /* DNS address(es) for the peer's use */
366 #ifndef IMPLEMENTATION
367 #define IMPLEMENTATION ""
370 static char *usage_string = "\
371 pppd version %s patch level %d%s\n\
372 Usage: %s [ options ], where options are:\n\
373 <device> Communicate over the named device\n\
374 <speed> Set the baud rate to <speed>\n\
375 <loc>:<rem> Set the local and/or remote interface IP\n\
376 addresses. Either one may be omitted.\n\
377 asyncmap <n> Set the desired async map to hex <n>\n\
378 auth Require authentication from peer\n\
379 connect <p> Invoke shell command <p> to set up the serial line\n\
380 crtscts Use hardware RTS/CTS flow control\n\
381 defaultroute Add default route through interface\n\
382 file <f> Take options from file <f>\n\
383 modem Use modem control lines\n\
384 mru <n> Set MRU value to <n> for negotiation\n\
385 netmask <n> Set interface netmask to <n>\n\
386 See pppd(8) for more options.\n\
389 static char *current_option; /* the name of the option being parsed */
393 * parse_args - parse a string of arguments, from the command
394 * line or from a file.
397 parse_args(argc, argv)
410 * First see if it's a command.
412 for (cmdp = cmds; cmdp->cmd_name; cmdp++)
413 if (!strcmp(arg, cmdp->cmd_name))
416 if (cmdp->cmd_name != NULL) {
417 if (argc < cmdp->num_args) {
418 option_error("too few parameters for option %s", arg);
421 current_option = arg;
422 if (!(*cmdp->cmd_func)(argv))
424 argc -= cmdp->num_args;
425 argv += cmdp->num_args;
429 * Maybe a tty name, speed or IP address?
431 if ((ret = setdevname(arg)) == 0
432 && (ret = setspeed(arg)) == 0
433 && (ret = setipaddr(arg)) == 0) {
434 option_error("unrecognized option '%s'", arg);
438 if (ret < 0) /* error */
446 * usage - print out a message telling how to use the program.
451 if (phase == PHASE_INITIALIZE)
452 fprintf(stderr, usage_string, VERSION, PATCHLEVEL, IMPLEMENTATION,
457 * options_from_file - Read a string of options from a file,
458 * and interpret them.
461 options_from_file(filename, must_exist, check_prot)
470 char args[MAXARGS][MAXWORDLEN];
471 char cmd[MAXWORDLEN];
473 if ((f = fopen(filename, "r")) == NULL) {
474 if (!must_exist && errno == ENOENT)
476 option_error("Can't open options file %s: %m", filename);
479 if (check_prot && !readable(fileno(f))) {
480 option_error("Can't open options file %s: access denied", filename);
485 while (getword(f, cmd, &newline, filename)) {
487 * First see if it's a command.
489 for (cmdp = cmds; cmdp->cmd_name; cmdp++)
490 if (!strcmp(cmd, cmdp->cmd_name))
493 if (cmdp->cmd_name != NULL) {
494 for (i = 0; i < cmdp->num_args; ++i) {
495 if (!getword(f, args[i], &newline, filename)) {
497 "In file %s: too few parameters for option '%s'",
504 current_option = cmd;
505 if (!(*cmdp->cmd_func)(argv)) {
512 * Maybe a tty name, speed or IP address?
514 if ((ret = setdevname(cmd)) == 0
515 && (ret = setspeed(cmd)) == 0
516 && (ret = setipaddr(cmd)) == 0) {
517 option_error("In file %s: unrecognized option '%s'",
522 if (ret < 0) /* error */
530 * options_from_user - See if the use has a ~/.ppprc file,
531 * and if so, interpret options from it.
536 char *user, *path, *file;
540 pw = getpwuid(getuid());
541 if (pw == NULL || (user = pw->pw_dir) == NULL || user[0] == 0)
543 file = _PATH_USEROPT;
544 path = malloc(strlen(user) + strlen(file) + 2);
546 novm("init file name");
550 ret = options_from_file(path, 0, 1);
556 * options_for_tty - See if an options file exists for the serial
557 * device, and if so, interpret options from it.
562 char *dev, *path, *p;
566 if (strncmp(dev, "/dev/", 5) == 0)
568 if (strcmp(dev, "tty") == 0)
569 return 1; /* don't look for /etc/ppp/options.tty */
570 path = malloc(strlen(_PATH_TTYOPT) + strlen(dev) + 1);
572 novm("tty init file name");
573 strcpy(path, _PATH_TTYOPT);
574 /* Turn slashes into dots, for Solaris case (e.g. /dev/term/a) */
575 for (p = path + strlen(path); *dev != 0; ++dev)
576 *p++ = (*dev == '/'? '.': *dev);
578 ret = options_from_file(path, 0, 0);
584 * option_error - print a message about an error in an option.
585 * The message is logged, and also sent to
586 * stderr if phase == PHASE_INITIALIZE.
589 option_error __V((char *fmt, ...))
600 fmt = va_arg(args, char *);
602 vfmtmsg(buf, sizeof(buf), fmt, args);
604 if (phase == PHASE_INITIALIZE)
605 fprintf(stderr, "%s: %s\n", progname, buf);
606 syslog(LOG_ERR, "%s", buf);
610 * readable - check if a file is readable by the real user.
619 GIDSET_TYPE groups[NGROUPS_MAX];
624 if (fstat(fd, &sbuf) != 0)
626 if (sbuf.st_uid == uid)
627 return sbuf.st_mode & S_IRUSR;
628 if (sbuf.st_gid == getgid())
629 return sbuf.st_mode & S_IRGRP;
630 ngroups = getgroups(NGROUPS_MAX, groups);
631 for (i = 0; i < ngroups; ++i)
632 if (sbuf.st_gid == groups[i])
633 return sbuf.st_mode & S_IRGRP;
634 return sbuf.st_mode & S_IROTH;
638 * Read a word from a file.
639 * Words are delimited by white-space or by quotes (" or ').
640 * Quotes, white-space and \ may be escaped with \.
641 * \<newline> is ignored.
644 getword(f, word, newlinep, filename)
652 int value, digit, got, n;
654 #define isoctal(c) ((c) >= '0' && (c) < '8')
662 * First skip white-space and comments.
670 * A newline means the end of a comment; backslash-newline
671 * is ignored. Note that we cannot have escape && comment.
683 * Ignore characters other than newline in a comment.
689 * If this character is escaped, we have a word start.
695 * If this is the escape character, look at the next character.
703 * If this is the start of a comment, ignore the rest of the line.
711 * A non-whitespace character is the start of a word.
718 * Save the delimiter for quoted strings.
720 if (!escape && (c == '"' || c == '\'')) {
727 * Process characters until the end of the word.
732 * This character is escaped: backslash-newline is ignored,
733 * various other characters indicate particular values
734 * as for C backslash-escapes.
769 * \ddd octal sequence
772 for (n = 0; n < 3 && isoctal(c); ++n) {
773 value = (value << 3) + (c & 07);
782 * \x<hex_string> sequence
786 for (n = 0; n < 2 && isxdigit(c); ++n) {
787 digit = toupper(c) - '0';
789 digit += '0' + 10 - 'A';
790 value = (value << 4) + digit;
798 * Otherwise the character stands for itself.
805 * Store the resulting character for the escape sequence.
807 if (len < MAXWORDLEN-1)
818 * Not escaped: see if we've reached the end of the word.
824 if (isspace(c) || c == '#') {
831 * Backslash starts an escape sequence.
840 * An ordinary character: store it in the word and get another.
842 if (len < MAXWORDLEN-1)
850 * End of the word: check for errors.
856 option_error("Error reading %s: %m", filename);
860 * If len is zero, then we didn't find a word before the
868 * Warn if the word was too long, and append a terminating null.
870 if (len >= MAXWORDLEN) {
871 option_error("warning: word in file %s too long (%.20s...)",
873 len = MAXWORDLEN - 1;
884 * number_option - parse an unsigned numeric parameter for an option.
887 number_option(str, valp, base)
894 *valp = strtoul(str, &ptr, base);
896 option_error("invalid numeric parameter '%s' for %s option",
897 str, current_option);
905 * int_option - like number_option, but valp is int *,
906 * the base is assumed to be 0, and *valp is not changed
907 * if there is an error.
910 int_option(str, valp)
916 if (!number_option(str, &v, 0))
924 * The following procedures parse options.
928 * readfile - take commands from a file.
934 return options_from_file(*argv, 1, 1);
938 * setdebug - Set debug (command line argument).
948 * setkdebug - Set kernel debugging level.
954 return int_option(*argv, &kdebugflag);
958 * noopt - Disable all options.
963 BZERO((char *) &lcp_wantoptions[0], sizeof (struct lcp_options));
964 BZERO((char *) &lcp_allowoptions[0], sizeof (struct lcp_options));
965 BZERO((char *) &ipcp_wantoptions[0], sizeof (struct ipcp_options));
966 BZERO((char *) &ipcp_allowoptions[0], sizeof (struct ipcp_options));
969 BZERO((char *) &ipxcp_wantoptions[0], sizeof (struct ipxcp_options));
970 BZERO((char *) &ipxcp_allowoptions[0], sizeof (struct ipxcp_options));
971 #endif /* IPX_CHANGE */
977 * noaccomp - Disable Address/Control field compression negotiation.
982 lcp_wantoptions[0].neg_accompression = 0;
983 lcp_allowoptions[0].neg_accompression = 0;
989 * noasyncmap - Disable async map negotiation.
994 lcp_wantoptions[0].neg_asyncmap = 0;
995 lcp_allowoptions[0].neg_asyncmap = 0;
1001 * noip - Disable IP and IPCP.
1006 ipcp_protent.enabled_flag = 0;
1012 * nomagicnumber - Disable magic number negotiation.
1017 lcp_wantoptions[0].neg_magicnumber = 0;
1018 lcp_allowoptions[0].neg_magicnumber = 0;
1024 * nomru - Disable mru negotiation.
1029 lcp_wantoptions[0].neg_mru = 0;
1030 lcp_allowoptions[0].neg_mru = 0;
1036 * setmru - Set MRU for negotiation.
1044 if (!number_option(*argv, &mru, 0))
1046 lcp_wantoptions[0].mru = mru;
1047 lcp_wantoptions[0].neg_mru = 1;
1053 * setmru - Set the largest MTU we'll use.
1061 if (!number_option(*argv, &mtu, 0))
1063 if (mtu < MINMRU || mtu > MAXMRU) {
1064 option_error("mtu option value of %u is too %s", mtu,
1065 (mtu < MINMRU? "small": "large"));
1068 lcp_allowoptions[0].mru = mtu;
1074 * nopcomp - Disable Protocol field compression negotiation.
1079 lcp_wantoptions[0].neg_pcompression = 0;
1080 lcp_allowoptions[0].neg_pcompression = 0;
1086 * setpassive - Set passive mode (don't give up if we time out sending
1087 * LCP configure-requests).
1092 lcp_wantoptions[0].passive = 1;
1098 * setsilent - Set silent mode (don't start sending LCP configure-requests
1099 * until we get one from the peer).
1104 lcp_wantoptions[0].silent = 1;
1110 * nopap - Disable PAP authentication with peer.
1115 lcp_allowoptions[0].neg_upap = 0;
1121 * reqpap - Require PAP authentication from peer.
1126 lcp_wantoptions[0].neg_upap = 1;
1133 * setupapfile - specifies UPAP info for authenticating with peer.
1142 lcp_allowoptions[0].neg_upap = 1;
1144 /* open user info file */
1145 if ((ufile = fopen(*argv, "r")) == NULL) {
1146 option_error("unable to open user login data file %s", *argv);
1149 if (!readable(fileno(ufile))) {
1150 option_error("%s: access denied", *argv);
1153 check_access(ufile, *argv);
1156 if (fgets(user, MAXNAMELEN - 1, ufile) == NULL
1157 || fgets(passwd, MAXSECRETLEN - 1, ufile) == NULL){
1158 option_error("unable to read user login data file %s", *argv);
1163 /* get rid of newlines */
1165 if (l > 0 && user[l-1] == '\n')
1168 if (l > 0 && passwd[l-1] == '\n')
1176 * nochap - Disable CHAP authentication with peer.
1181 lcp_allowoptions[0].neg_chap = 0;
1187 * reqchap - Require CHAP authentication from peer.
1192 lcp_wantoptions[0].neg_chap = 1;
1199 * setnovj - disable vj compression
1204 ipcp_wantoptions[0].neg_vj = 0;
1205 ipcp_allowoptions[0].neg_vj = 0;
1211 * setnovjccomp - disable VJ connection-ID compression
1216 ipcp_wantoptions[0].cflag = 0;
1217 ipcp_allowoptions[0].cflag = 0;
1223 * setvjslots - set maximum number of connection slots for VJ compression
1231 if (!int_option(*argv, &value))
1233 if (value < 2 || value > 16) {
1234 option_error("vj-max-slots value must be between 2 and 16");
1237 ipcp_wantoptions [0].maxslotindex =
1238 ipcp_allowoptions[0].maxslotindex = value - 1;
1244 * setconnector - Set a program to connect to a serial line
1250 connector = strdup(*argv);
1251 if (connector == NULL)
1252 novm("connect script");
1258 * setdisconnector - Set a program to disconnect from the serial line
1261 setdisconnector(argv)
1264 disconnector = strdup(*argv);
1265 if (disconnector == NULL)
1266 novm("disconnect script");
1272 * setwelcomer - Set a program to welcome a client after connection
1278 welcomer = strdup(*argv);
1279 if (welcomer == NULL)
1280 novm("welcome script");
1286 * setmaxconnect - Set the maximum connect time
1294 if (!int_option(*argv, &value))
1297 option_error("maxconnect time must be positive");
1305 * setdomain - Set domain name to append to hostname
1311 gethostname(hostname, MAXNAMELEN);
1314 strncat(hostname, ".", MAXNAMELEN - strlen(hostname));
1315 strncat(hostname, *argv, MAXNAMELEN - strlen(hostname));
1317 hostname[MAXNAMELEN-1] = 0;
1323 * setasyncmap - add bits to asyncmap (what we request peer to escape).
1331 if (!number_option(*argv, &asyncmap, 16))
1333 lcp_wantoptions[0].asyncmap |= asyncmap;
1334 lcp_wantoptions[0].neg_asyncmap = 1;
1340 * setescape - add chars to the set we escape on transmission.
1352 n = strtol(p, &endp, 16);
1354 option_error("escape parameter contains invalid hex number '%s'",
1359 if (n < 0 || 0x20 <= n && n <= 0x3F || n == 0x5E || n > 0xFF) {
1360 option_error("can't escape character 0x%x", n);
1363 xmit_accm[0][n >> 5] |= 1 << (n & 0x1F);
1364 while (*p == ',' || *p == ' ')
1372 * setspeed - Set the speed.
1381 spd = strtol(arg, &ptr, 0);
1382 if (ptr == arg || *ptr != 0 || spd == 0)
1390 * setdevname - Set the device name.
1396 struct stat statbuf;
1397 char dev[MAXPATHLEN];
1402 if (strncmp("/dev/", cp, 5) != 0) {
1403 strcpy(dev, "/dev/");
1404 strncat(dev, cp, MAXPATHLEN - 5);
1405 dev[MAXPATHLEN-1] = 0;
1410 * Check if there is a device by this name.
1412 if (stat(cp, &statbuf) < 0) {
1413 if (errno == ENOENT)
1415 option_error("Couldn't stat %s: %m", cp);
1419 (void) strncpy(devnam, cp, MAXPATHLEN);
1420 devnam[MAXPATHLEN-1] = 0;
1421 default_device = FALSE;
1428 * setipaddr - Set the IP address
1436 u_int32_t local, remote;
1437 ipcp_options *wo = &ipcp_wantoptions[0];
1440 * IP address pair separated by ":".
1442 if ((colon = strchr(arg, ':')) == NULL)
1446 * If colon first character, then no local addr.
1450 if ((local = inet_addr(arg)) == -1) {
1451 if ((hp = gethostbyname(arg)) == NULL) {
1452 option_error("unknown host: %s", arg);
1455 local = *(u_int32_t *)hp->h_addr;
1456 if (our_name[0] == 0) {
1457 strncpy(our_name, arg, MAXNAMELEN);
1458 our_name[MAXNAMELEN-1] = 0;
1462 if (bad_ip_adrs(local)) {
1463 option_error("bad local IP address %s", ip_ntoa(local));
1467 wo->ouraddr = local;
1472 * If colon last character, then no remote addr.
1474 if (*++colon != '\0') {
1475 if ((remote = inet_addr(colon)) == -1) {
1476 if ((hp = gethostbyname(colon)) == NULL) {
1477 option_error("unknown host: %s", colon);
1480 remote = *(u_int32_t *)hp->h_addr;
1481 if (remote_name[0] == 0) {
1482 strncpy(remote_name, colon, MAXNAMELEN);
1483 remote_name[MAXNAMELEN-1] = 0;
1487 if (bad_ip_adrs(remote)) {
1488 option_error("bad remote IP address %s", ip_ntoa(remote));
1492 wo->hisaddr = remote;
1500 * setnoipdflt - disable setipdefault()
1505 disable_defaultip = 1;
1511 * setipcpaccl - accept peer's idea of our address
1516 ipcp_wantoptions[0].accept_local = 1;
1522 * setipcpaccr - accept peer's idea of its address
1527 ipcp_wantoptions[0].accept_remote = 1;
1533 * setnetmask - set the netmask to be used on the interface.
1541 if ((mask = inet_addr(*argv)) == -1 || (netmask & ~mask) != 0) {
1542 option_error("invalid netmask value '%s'", *argv);
1567 lcp_wantoptions[0].asyncmap |= 0x000A0000; /* escape ^S and ^Q */
1568 lcp_wantoptions[0].neg_asyncmap = 1;
1620 if (our_name[0] == 0) {
1621 strncpy(our_name, argv[0], MAXNAMELEN);
1622 our_name[MAXNAMELEN-1] = 0;
1631 strncpy(user, argv[0], MAXNAMELEN);
1632 user[MAXNAMELEN-1] = 0;
1640 strncpy(remote_name, argv[0], MAXNAMELEN);
1641 remote_name[MAXNAMELEN-1] = 0;
1655 if (!ipcp_allowoptions[0].default_route) {
1656 option_error("defaultroute option is disabled");
1659 ipcp_wantoptions[0].default_route = 1;
1666 ipcp_allowoptions[0].default_route = 0;
1667 ipcp_wantoptions[0].default_route = 0;
1674 if (!ipcp_allowoptions[0].proxy_arp) {
1675 option_error("proxyarp option is disabled");
1678 ipcp_wantoptions[0].proxy_arp = 1;
1685 ipcp_wantoptions[0].proxy_arp = 0;
1686 ipcp_allowoptions[0].proxy_arp = 0;
1705 * Functions to set the echo interval for modem-less monitors
1709 setlcpechointv(argv)
1712 return int_option(*argv, &lcp_echo_interval);
1716 setlcpechofails(argv)
1719 return int_option(*argv, &lcp_echo_fails);
1723 * Functions to set timeouts, max transmits, etc.
1729 return int_option(*argv, &lcp_fsm[0].timeouttime);
1736 return int_option(*argv, &lcp_fsm[0].maxtermtransmits);
1743 return int_option(*argv, &lcp_fsm[0].maxconfreqtransmits);
1750 return int_option(*argv, &lcp_fsm[0].maxnakloops);
1754 setipcptimeout(argv)
1757 return int_option(*argv, &ipcp_fsm[0].timeouttime);
1764 return int_option(*argv, &ipcp_fsm[0].maxtermtransmits);
1771 return int_option(*argv, &ipcp_fsm[0].maxconfreqtransmits);
1778 return int_option(*argv, &lcp_fsm[0].maxnakloops);
1785 return int_option(*argv, &upap[0].us_timeouttime);
1792 return int_option(*argv, &upap[0].us_reqtimeout);
1799 return int_option(*argv, &upap[0].us_maxtransmits);
1803 setchaptimeout(argv)
1806 return int_option(*argv, &chap[0].timeouttime);
1813 return int_option(*argv, &chap[0].max_transmits);
1820 return int_option(*argv, &chap[0].chal_interval);
1826 ccp_protent.enabled_flag = 0;
1838 abits = rbits = strtol(str, &endp, 0);
1839 if (endp != str && *endp == ',') {
1841 abits = strtol(str, &endp, 0);
1843 if (*endp != 0 || endp == str) {
1844 option_error("invalid parameter '%s' for bsdcomp option", *argv);
1847 if (rbits != 0 && (rbits < BSD_MIN_BITS || rbits > BSD_MAX_BITS)
1848 || abits != 0 && (abits < BSD_MIN_BITS || abits > BSD_MAX_BITS)) {
1849 option_error("bsdcomp option values must be 0 or %d .. %d",
1850 BSD_MIN_BITS, BSD_MAX_BITS);
1854 ccp_wantoptions[0].bsd_compress = 1;
1855 ccp_wantoptions[0].bsd_bits = rbits;
1857 ccp_wantoptions[0].bsd_compress = 0;
1859 ccp_allowoptions[0].bsd_compress = 1;
1860 ccp_allowoptions[0].bsd_bits = abits;
1862 ccp_allowoptions[0].bsd_compress = 0;
1869 ccp_wantoptions[0].bsd_compress = 0;
1870 ccp_allowoptions[0].bsd_compress = 0;
1882 abits = rbits = strtol(str, &endp, 0);
1883 if (endp != str && *endp == ',') {
1885 abits = strtol(str, &endp, 0);
1887 if (*endp != 0 || endp == str) {
1888 option_error("invalid parameter '%s' for deflate option", *argv);
1891 if (rbits != 0 && (rbits < DEFLATE_MIN_SIZE || rbits > DEFLATE_MAX_SIZE)
1892 || abits != 0 && (abits < DEFLATE_MIN_SIZE
1893 || abits > DEFLATE_MAX_SIZE)) {
1894 option_error("deflate option values must be 0 or %d .. %d",
1895 DEFLATE_MIN_SIZE, DEFLATE_MAX_SIZE);
1899 ccp_wantoptions[0].deflate = 1;
1900 ccp_wantoptions[0].deflate_size = rbits;
1902 ccp_wantoptions[0].deflate = 0;
1904 ccp_allowoptions[0].deflate = 1;
1905 ccp_allowoptions[0].deflate_size = abits;
1907 ccp_allowoptions[0].deflate = 0;
1914 ccp_wantoptions[0].deflate = 0;
1915 ccp_allowoptions[0].deflate = 0;
1922 ccp_wantoptions[0].predictor_1 = 1;
1923 ccp_allowoptions[0].predictor_1 = 1;
1930 ccp_wantoptions[0].predictor_1 = 0;
1931 ccp_allowoptions[0].predictor_1 = 0;
1939 ipparam = strdup(*argv);
1940 if (ipparam == NULL)
1941 novm("ipparam string");
1957 return int_option(*argv, &idle_time_limit);
1964 return int_option(*argv, &holdoff);
1972 ipxcp_wantoptions[0].neg_router = 1;
1973 ipxcp_allowoptions[0].neg_router = 1;
1974 return int_option(*argv, &ipxcp_wantoptions[0].router);
1981 char *dest = ipxcp_wantoptions[0].name;
1986 ipxcp_wantoptions[0].neg_name = 1;
1987 ipxcp_allowoptions[0].neg_name = 1;
1988 memset (dest, '\0', sizeof (ipxcp_wantoptions[0].name));
1993 if (! isalnum (ch) && ch != '_') {
1994 option_error("IPX router name must be alphanumeric or _");
1998 if (count >= sizeof (ipxcp_wantoptions[0].name)) {
1999 option_error("IPX router name is limited to %d characters",
2000 sizeof (ipxcp_wantoptions[0].name) - 1);
2004 dest[count++] = toupper (ch);
2011 setipxcptimeout (argv)
2014 return int_option(*argv, &ipxcp_fsm[0].timeouttime);
2021 return int_option(*argv, &ipxcp_fsm[0].maxtermtransmits);
2028 return int_option(*argv, &ipxcp_fsm[0].maxconfreqtransmits);
2032 setipxcpfails (argv)
2035 return int_option(*argv, &ipxcp_fsm[0].maxnakloops);
2042 ipxcp_wantoptions[0].neg_nn = 1;
2043 return int_option(*argv, &ipxcp_wantoptions[0].our_network);
2049 ipxcp_wantoptions[0].accept_network = 1;
2050 ipxcp_allowoptions[0].accept_network = 1;
2056 ipxcp_wantoptions[0].accept_local = 1;
2057 ipxcp_allowoptions[0].accept_local = 1;
2063 ipxcp_wantoptions[0].accept_remote = 1;
2064 ipxcp_allowoptions[0].accept_remote = 1;
2068 setipxnodevalue(src,dst)
2075 if (!isxdigit (*src))
2078 for (indx = 0; indx < 5; ++indx) {
2080 dst[indx] |= (dst[indx + 1] >> 4) & 0x0F;
2083 item = toupper (*src) - '0';
2087 dst[5] = (dst[5] << 4) | item;
2099 memset (&ipxcp_wantoptions[0].our_node[0], 0, 6);
2100 memset (&ipxcp_wantoptions[0].his_node[0], 0, 6);
2102 end = setipxnodevalue (*argv, &ipxcp_wantoptions[0].our_node[0]);
2104 end = setipxnodevalue (++end, &ipxcp_wantoptions[0].his_node[0]);
2107 ipxcp_wantoptions[0].neg_node = 1;
2111 option_error("invalid parameter '%s' for ipx-node option", *argv);
2118 ipx_enabled = 1; /* Enable IPXCP and IPX protocol */
2125 ipx_enabled = 0; /* Disable IPXCP and IPX protocol */
2128 #endif /* IPX_CHANGE */
2132 * setdnsaddr - set the dns address(es)
2142 dns = inet_addr(*argv);
2144 if ((hp = gethostbyname(*argv)) == NULL) {
2145 option_error("invalid address parameter '%s' for ms-dns option",
2149 dns = *(u_int32_t *)hp->h_addr;
2152 if (ipcp_allowoptions[0].dnsaddr[0] == 0) {
2153 ipcp_allowoptions[0].dnsaddr[0] = dns;
2155 ipcp_allowoptions[0].dnsaddr[1] = dns;
2160 #endif /* USE_MS_DNS */