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.32 1996/07/01 01:18:23 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 */
102 int refuse_pap = 0; /* Set to say we won't do PAP */
103 int refuse_chap = 0; /* Set to say we won't do CHAP */
108 static int setdevname __P((char *, int));
109 static int setipaddr __P((char *));
110 static int setdebug __P((void));
111 static int setkdebug __P((char **));
112 static int setpassive __P((void));
113 static int setsilent __P((void));
114 static int noopt __P((void));
115 static int setnovj __P((void));
116 static int setnovjccomp __P((void));
117 static int setvjslots __P((char **));
118 static int reqpap __P((void));
119 static int nopap __P((void));
121 static int setupapfile __P((char **));
123 static int nochap __P((void));
124 static int reqchap __P((void));
125 static int setspeed __P((char *));
126 static int noaccomp __P((void));
127 static int noasyncmap __P((void));
128 static int noip __P((void));
129 static int nomagicnumber __P((void));
130 static int setasyncmap __P((char **));
131 static int setescape __P((char **));
132 static int setmru __P((char **));
133 static int setmtu __P((char **));
134 static int nomru __P((void));
135 static int nopcomp __P((void));
136 static int setconnector __P((char **));
137 static int setdisconnector __P((char **));
138 static int setwelcomer __P((char **));
139 static int setmaxconnect __P((char **));
140 static int setdomain __P((char **));
141 static int setnetmask __P((char **));
142 static int setcrtscts __P((void));
143 static int setnocrtscts __P((void));
144 static int setxonxoff __P((void));
145 static int setnodetach __P((void));
146 static int setmodem __P((void));
147 static int setlocal __P((void));
148 static int setlock __P((void));
149 static int setname __P((char **));
150 static int setuser __P((char **));
151 static int setremote __P((char **));
152 static int setauth __P((void));
153 static int readfile __P((char **));
154 static int setdefaultroute __P((void));
155 static int setnodefaultroute __P((void));
156 static int setproxyarp __P((void));
157 static int setnoproxyarp __P((void));
158 static int setpersist __P((void));
159 static int setdologin __P((void));
160 static int setusehostname __P((void));
161 static int setnoipdflt __P((void));
162 static int setlcptimeout __P((char **));
163 static int setlcpterm __P((char **));
164 static int setlcpconf __P((char **));
165 static int setlcpfails __P((char **));
166 static int setipcptimeout __P((char **));
167 static int setipcpterm __P((char **));
168 static int setipcpconf __P((char **));
169 static int setipcpfails __P((char **));
170 static int setpaptimeout __P((char **));
171 static int setpapreqs __P((char **));
172 static int setpapreqtime __P((char **));
173 static int setchaptimeout __P((char **));
174 static int setchapchal __P((char **));
175 static int setchapintv __P((char **));
176 static int setipcpaccl __P((void));
177 static int setipcpaccr __P((void));
178 static int setlcpechointv __P((char **));
179 static int setlcpechofails __P((char **));
180 static int noccp __P((void));
181 static int setbsdcomp __P((char **));
182 static int setnobsdcomp __P((void));
183 static int setdeflate __P((char **));
184 static int setnodeflate __P((void));
185 static int setdemand __P((void));
186 static int setpred1comp __P((void));
187 static int setnopred1comp __P((void));
188 static int setipparam __P((char **));
189 static int setpapcrypt __P((void));
190 static int setidle __P((char **));
191 static int setholdoff __P((char **));
194 static int setipxproto __P((void));
195 static int resetipxproto __P((void));
196 static int setipxanet __P((void));
197 static int setipxalcl __P((void));
198 static int setipxarmt __P((void));
199 static int setipxnetwork __P((char **));
200 static int setipxnode __P((char **));
201 static int setipxrouter __P((char **));
202 static int setipxname __P((char **));
203 static int setipxcptimeout __P((char **));
204 static int setipxcpterm __P((char **));
205 static int setipxcpconf __P((char **));
206 static int setipxcpfails __P((char **));
207 #endif /* IPX_CHANGE */
210 static int setdnsaddr __P((char **));
213 static int number_option __P((char *, u_int32_t *, int));
214 static int int_option __P((char *, int *));
215 static int readable __P((int fd));
216 static void option_error __P((char *fmt, ...));
226 {"-all", 0, noopt}, /* Don't request/allow any options (useless) */
227 {"noaccomp", 0, noaccomp}, /* Disable Address/Control compression */
228 {"-ac", 0, noaccomp}, /* Disable Address/Control compress */
229 {"default-asyncmap", 0, noasyncmap}, /* Disable asyncmap negoatiation */
230 {"-am", 0, noasyncmap}, /* Disable asyncmap negotiation */
231 {"-as", 1, setasyncmap}, /* set the desired async map */
232 {"-d", 0, setdebug}, /* Increase debugging level */
233 {"nodetach", 0, setnodetach}, /* Don't detach from controlling tty */
234 {"-detach", 0, setnodetach}, /* don't fork */
235 {"noip", 0, noip}, /* Disable IP and IPCP */
236 {"-ip", 0, noip}, /* Disable IP and IPCP */
237 {"nomagic", 0, nomagicnumber}, /* Disable magic number negotiation */
238 {"-mn", 0, nomagicnumber}, /* Disable magic number negotiation */
239 {"default-mru", 0, nomru}, /* Disable MRU negotiation */
240 {"-mru", 0, nomru}, /* Disable mru negotiation */
241 {"-p", 0, setpassive}, /* Set passive mode */
242 {"nopcomp", 0, nopcomp}, /* Disable protocol field compression */
243 {"-pc", 0, nopcomp}, /* Disable protocol field compress */
245 {"+ua", 1, setupapfile}, /* Get PAP user and password from file */
247 {"require-pap", 0, reqpap}, /* Require PAP authentication from peer */
248 {"+pap", 0, reqpap}, /* Require PAP auth from peer */
249 {"refuse-pap", 0, nopap}, /* Don't agree to auth to peer with PAP */
250 {"-pap", 0, nopap}, /* Don't allow UPAP authentication with peer */
251 {"require-chap", 0, reqchap}, /* Require CHAP authentication from peer */
252 {"+chap", 0, reqchap}, /* Require CHAP authentication from peer */
253 {"refuse-chap", 0, nochap}, /* Don't agree to auth to peer with CHAP */
254 {"-chap", 0, nochap}, /* Don't allow CHAP authentication with peer */
255 {"novj", 0, setnovj}, /* Disable VJ compression */
256 {"-vj", 0, setnovj}, /* disable VJ compression */
257 {"novjccomp", 0, setnovjccomp}, /* disable VJ connection-ID compression */
258 {"-vjccomp", 0, setnovjccomp}, /* disable VJ connection-ID compression */
259 {"vj-max-slots", 1, setvjslots}, /* Set maximum VJ header slots */
260 {"asyncmap", 1, setasyncmap}, /* set the desired async map */
261 {"escape", 1, setescape}, /* set chars to escape on transmission */
262 {"connect", 1, setconnector}, /* A program to set up a connection */
263 {"disconnect", 1, setdisconnector}, /* program to disconnect serial dev. */
264 {"welcome", 1, setwelcomer},/* Script to welcome client */
265 {"maxconnect", 1, setmaxconnect}, /* specify a maximum connect time */
266 {"crtscts", 0, setcrtscts}, /* set h/w flow control */
267 {"nocrtscts", 0, setnocrtscts}, /* clear h/w flow control */
268 {"-crtscts", 0, setnocrtscts}, /* clear h/w flow control */
269 {"xonxoff", 0, setxonxoff}, /* set s/w flow control */
270 {"debug", 0, setdebug}, /* Increase debugging level */
271 {"kdebug", 1, setkdebug}, /* Enable kernel-level debugging */
272 {"domain", 1, setdomain}, /* Add given domain name to hostname*/
273 {"mru", 1, setmru}, /* Set MRU value for negotiation */
274 {"mtu", 1, setmtu}, /* Set our MTU */
275 {"netmask", 1, setnetmask}, /* set netmask */
276 {"passive", 0, setpassive}, /* Set passive mode */
277 {"silent", 0, setsilent}, /* Set silent mode */
278 {"modem", 0, setmodem}, /* Use modem control lines */
279 {"local", 0, setlocal}, /* Don't use modem control lines */
280 {"lock", 0, setlock}, /* Lock serial device (with lock file) */
281 {"name", 1, setname}, /* Set local name for authentication */
282 {"user", 1, setuser}, /* Set username for PAP auth with peer */
283 {"usehostname", 0, setusehostname}, /* Must use hostname for auth. */
284 {"remotename", 1, setremote}, /* Set remote name for authentication */
285 {"auth", 0, setauth}, /* Require authentication from peer */
286 {"file", 1, readfile}, /* Take options from a file */
287 {"defaultroute", 0, setdefaultroute}, /* Add default route */
288 {"nodefaultroute", 0, setnodefaultroute}, /* disable defaultroute option */
289 {"-defaultroute", 0, setnodefaultroute}, /* disable defaultroute option */
290 {"proxyarp", 0, setproxyarp}, /* Add proxy ARP entry */
291 {"noproxyarp", 0, setnoproxyarp}, /* disable proxyarp option */
292 {"-proxyarp", 0, setnoproxyarp}, /* disable proxyarp option */
293 {"persist", 0, setpersist}, /* Keep on reopening connection after close */
294 {"demand", 0, setdemand}, /* Dial on demand */
295 {"login", 0, setdologin}, /* Use system password database for UPAP */
296 {"noipdefault", 0, setnoipdflt}, /* Don't use name for default IP adrs */
297 {"lcp-echo-failure", 1, setlcpechofails}, /* consecutive echo failures */
298 {"lcp-echo-interval", 1, setlcpechointv}, /* time for lcp echo events */
299 {"lcp-restart", 1, setlcptimeout}, /* Set timeout for LCP */
300 {"lcp-max-terminate", 1, setlcpterm}, /* Set max #xmits for term-reqs */
301 {"lcp-max-configure", 1, setlcpconf}, /* Set max #xmits for conf-reqs */
302 {"lcp-max-failure", 1, setlcpfails}, /* Set max #conf-naks for LCP */
303 {"ipcp-restart", 1, setipcptimeout}, /* Set timeout for IPCP */
304 {"ipcp-max-terminate", 1, setipcpterm}, /* Set max #xmits for term-reqs */
305 {"ipcp-max-configure", 1, setipcpconf}, /* Set max #xmits for conf-reqs */
306 {"ipcp-max-failure", 1, setipcpfails}, /* Set max #conf-naks for IPCP */
307 {"pap-restart", 1, setpaptimeout}, /* Set retransmit timeout for PAP */
308 {"pap-max-authreq", 1, setpapreqs}, /* Set max #xmits for auth-reqs */
309 {"pap-timeout", 1, setpapreqtime}, /* Set time limit for peer PAP auth. */
310 {"chap-restart", 1, setchaptimeout}, /* Set timeout for CHAP */
311 {"chap-max-challenge", 1, setchapchal}, /* Set max #xmits for challenge */
312 {"chap-interval", 1, setchapintv}, /* Set interval for rechallenge */
313 {"ipcp-accept-local", 0, setipcpaccl}, /* Accept peer's address for us */
314 {"ipcp-accept-remote", 0, setipcpaccr}, /* Accept peer's address for it */
315 {"noccp", 0, noccp}, /* Disable CCP negotiation */
316 {"-ccp", 0, noccp}, /* Disable CCP negotiation */
317 {"bsdcomp", 1, setbsdcomp}, /* request BSD-Compress */
318 {"nobsdcomp", 0, setnobsdcomp}, /* don't allow BSD-Compress */
319 {"-bsdcomp", 0, setnobsdcomp}, /* don't allow BSD-Compress */
320 {"deflate", 1, setdeflate}, /* request Deflate compression */
321 {"nodeflate", 0, setnodeflate}, /* don't allow Deflate compression */
322 {"-deflate", 0, setnodeflate}, /* don't allow Deflate compression */
323 {"predictor1", 0, setpred1comp}, /* request Predictor-1 */
324 {"nopredictor1", 0, setnopred1comp},/* don't allow Predictor-1 */
325 {"-predictor1", 0, setnopred1comp}, /* don't allow Predictor-1 */
326 {"ipparam", 1, setipparam}, /* set ip script parameter */
327 {"papcrypt", 0, setpapcrypt}, /* PAP passwords encrypted */
328 {"idle", 1, setidle}, /* idle time limit (seconds) */
329 {"holdoff", 1, setholdoff}, /* set holdoff time (seconds) */
332 {"ipx-network", 1, setipxnetwork}, /* IPX network number */
333 {"ipxcp-accept-network", 0, setipxanet}, /* Accept peer netowrk */
334 {"ipx-node", 1, setipxnode}, /* IPX node number */
335 {"ipxcp-accept-local", 0, setipxalcl}, /* Accept our address */
336 {"ipxcp-accept-remote", 0, setipxarmt}, /* Accept peer's address */
337 {"ipx-routing", 1, setipxrouter}, /* IPX routing proto number */
338 {"ipx-router-name", 1, setipxname}, /* IPX router name */
339 {"ipxcp-restart", 1, setipxcptimeout}, /* Set timeout for IPXCP */
340 {"ipxcp-max-terminate", 1, setipxcpterm}, /* max #xmits for term-reqs */
341 {"ipxcp-max-configure", 1, setipxcpconf}, /* max #xmits for conf-reqs */
342 {"ipxcp-max-failure", 1, setipxcpfails}, /* max #conf-naks for IPXCP */
344 {"ipx-compression", 1, setipxcompression}, /* IPX compression number */
346 {"ipx", 0, setipxproto}, /* Enable IPXCP (and IPX) */
347 {"noipx", 0, resetipxproto}, /* Disable IPXCP (and IPX) */
348 {"+ipx", 0, setipxproto}, /* Enable IPXCP (and IPX) */
349 {"-ipx", 0, resetipxproto}, /* Disable IPXCP (and IPX) */
350 #endif /* IPX_CHANGE */
353 {"ms-dns", 1, setdnsaddr}, /* DNS address(es) for the peer's use */
360 #ifndef IMPLEMENTATION
361 #define IMPLEMENTATION ""
364 static char *usage_string = "\
365 pppd version %s patch level %d%s\n\
366 Usage: %s [ options ], where options are:\n\
367 <device> Communicate over the named device\n\
368 <speed> Set the baud rate to <speed>\n\
369 <loc>:<rem> Set the local and/or remote interface IP\n\
370 addresses. Either one may be omitted.\n\
371 asyncmap <n> Set the desired async map to hex <n>\n\
372 auth Require authentication from peer\n\
373 connect <p> Invoke shell command <p> to set up the serial line\n\
374 crtscts Use hardware RTS/CTS flow control\n\
375 defaultroute Add default route through interface\n\
376 file <f> Take options from file <f>\n\
377 modem Use modem control lines\n\
378 mru <n> Set MRU value to <n> for negotiation\n\
379 netmask <n> Set interface netmask to <n>\n\
380 See pppd(8) for more options.\n\
383 static char *current_option; /* the name of the option being parsed */
387 * parse_args - parse a string of arguments, from the command
388 * line or from a file.
391 parse_args(argc, argv)
404 * First see if it's a command.
406 for (cmdp = cmds; cmdp->cmd_name; cmdp++)
407 if (!strcmp(arg, cmdp->cmd_name))
410 if (cmdp->cmd_name != NULL) {
411 if (argc < cmdp->num_args) {
412 option_error("too few parameters for option %s", arg);
415 current_option = arg;
416 if (!(*cmdp->cmd_func)(argv))
418 argc -= cmdp->num_args;
419 argv += cmdp->num_args;
423 * Maybe a tty name, speed or IP address?
425 if ((ret = setdevname(arg, 0)) == 0
426 && (ret = setspeed(arg)) == 0
427 && (ret = setipaddr(arg)) == 0) {
428 option_error("unrecognized option '%s'", arg);
432 if (ret < 0) /* error */
440 * scan_args - scan the command line arguments to get the tty name,
444 scan_args(argc, argv)
455 /* Skip options and their arguments */
456 for (cmdp = cmds; cmdp->cmd_name; cmdp++)
457 if (!strcmp(arg, cmdp->cmd_name))
460 if (cmdp->cmd_name != NULL) {
461 argc -= cmdp->num_args;
462 argv += cmdp->num_args;
466 /* Check if it's a tty name and copy it if so */
467 (void) setdevname(arg, 1);
472 * usage - print out a message telling how to use the program.
477 if (phase == PHASE_INITIALIZE)
478 fprintf(stderr, usage_string, VERSION, PATCHLEVEL, IMPLEMENTATION,
483 * options_from_file - Read a string of options from a file,
484 * and interpret them.
487 options_from_file(filename, must_exist, check_prot)
496 char args[MAXARGS][MAXWORDLEN];
497 char cmd[MAXWORDLEN];
499 if ((f = fopen(filename, "r")) == NULL) {
500 if (!must_exist && errno == ENOENT)
502 option_error("Can't open options file %s: %m", filename);
505 if (check_prot && !readable(fileno(f))) {
506 option_error("Can't open options file %s: access denied", filename);
511 while (getword(f, cmd, &newline, filename)) {
513 * First see if it's a command.
515 for (cmdp = cmds; cmdp->cmd_name; cmdp++)
516 if (!strcmp(cmd, cmdp->cmd_name))
519 if (cmdp->cmd_name != NULL) {
520 for (i = 0; i < cmdp->num_args; ++i) {
521 if (!getword(f, args[i], &newline, filename)) {
523 "In file %s: too few parameters for option '%s'",
530 current_option = cmd;
531 if (!(*cmdp->cmd_func)(argv)) {
538 * Maybe a tty name, speed or IP address?
540 if ((ret = setdevname(cmd, 0)) == 0
541 && (ret = setspeed(cmd)) == 0
542 && (ret = setipaddr(cmd)) == 0) {
543 option_error("In file %s: unrecognized option '%s'",
548 if (ret < 0) /* error */
556 * options_from_user - See if the use has a ~/.ppprc file,
557 * and if so, interpret options from it.
562 char *user, *path, *file;
566 pw = getpwuid(getuid());
567 if (pw == NULL || (user = pw->pw_dir) == NULL || user[0] == 0)
569 file = _PATH_USEROPT;
570 path = malloc(strlen(user) + strlen(file) + 2);
572 novm("init file name");
576 ret = options_from_file(path, 0, 1);
582 * options_for_tty - See if an options file exists for the serial
583 * device, and if so, interpret options from it.
588 char *dev, *path, *p;
592 if (strncmp(dev, "/dev/", 5) == 0)
594 if (strcmp(dev, "tty") == 0)
595 return 1; /* don't look for /etc/ppp/options.tty */
596 path = malloc(strlen(_PATH_TTYOPT) + strlen(dev) + 1);
598 novm("tty init file name");
599 strcpy(path, _PATH_TTYOPT);
600 /* Turn slashes into dots, for Solaris case (e.g. /dev/term/a) */
601 for (p = path + strlen(path); *dev != 0; ++dev)
602 *p++ = (*dev == '/'? '.': *dev);
604 ret = options_from_file(path, 0, 0);
610 * option_error - print a message about an error in an option.
611 * The message is logged, and also sent to
612 * stderr if phase == PHASE_INITIALIZE.
615 option_error __V((char *fmt, ...))
626 fmt = va_arg(args, char *);
628 vfmtmsg(buf, sizeof(buf), fmt, args);
630 if (phase == PHASE_INITIALIZE)
631 fprintf(stderr, "%s: %s\n", progname, buf);
632 syslog(LOG_ERR, "%s", buf);
636 * readable - check if a file is readable by the real user.
645 GIDSET_TYPE groups[NGROUPS_MAX];
650 if (fstat(fd, &sbuf) != 0)
652 if (sbuf.st_uid == uid)
653 return sbuf.st_mode & S_IRUSR;
654 if (sbuf.st_gid == getgid())
655 return sbuf.st_mode & S_IRGRP;
656 ngroups = getgroups(NGROUPS_MAX, groups);
657 for (i = 0; i < ngroups; ++i)
658 if (sbuf.st_gid == groups[i])
659 return sbuf.st_mode & S_IRGRP;
660 return sbuf.st_mode & S_IROTH;
664 * Read a word from a file.
665 * Words are delimited by white-space or by quotes (" or ').
666 * Quotes, white-space and \ may be escaped with \.
667 * \<newline> is ignored.
670 getword(f, word, newlinep, filename)
678 int value, digit, got, n;
680 #define isoctal(c) ((c) >= '0' && (c) < '8')
688 * First skip white-space and comments.
696 * A newline means the end of a comment; backslash-newline
697 * is ignored. Note that we cannot have escape && comment.
709 * Ignore characters other than newline in a comment.
715 * If this character is escaped, we have a word start.
721 * If this is the escape character, look at the next character.
729 * If this is the start of a comment, ignore the rest of the line.
737 * A non-whitespace character is the start of a word.
744 * Save the delimiter for quoted strings.
746 if (!escape && (c == '"' || c == '\'')) {
753 * Process characters until the end of the word.
758 * This character is escaped: backslash-newline is ignored,
759 * various other characters indicate particular values
760 * as for C backslash-escapes.
795 * \ddd octal sequence
798 for (n = 0; n < 3 && isoctal(c); ++n) {
799 value = (value << 3) + (c & 07);
808 * \x<hex_string> sequence
812 for (n = 0; n < 2 && isxdigit(c); ++n) {
813 digit = toupper(c) - '0';
815 digit += '0' + 10 - 'A';
816 value = (value << 4) + digit;
824 * Otherwise the character stands for itself.
831 * Store the resulting character for the escape sequence.
833 if (len < MAXWORDLEN-1)
844 * Not escaped: see if we've reached the end of the word.
850 if (isspace(c) || c == '#') {
857 * Backslash starts an escape sequence.
866 * An ordinary character: store it in the word and get another.
868 if (len < MAXWORDLEN-1)
876 * End of the word: check for errors.
882 option_error("Error reading %s: %m", filename);
886 * If len is zero, then we didn't find a word before the
894 * Warn if the word was too long, and append a terminating null.
896 if (len >= MAXWORDLEN) {
897 option_error("warning: word in file %s too long (%.20s...)",
899 len = MAXWORDLEN - 1;
910 * number_option - parse an unsigned numeric parameter for an option.
913 number_option(str, valp, base)
920 *valp = strtoul(str, &ptr, base);
922 option_error("invalid numeric parameter '%s' for %s option",
923 str, current_option);
931 * int_option - like number_option, but valp is int *,
932 * the base is assumed to be 0, and *valp is not changed
933 * if there is an error.
936 int_option(str, valp)
942 if (!number_option(str, &v, 0))
950 * The following procedures parse options.
954 * readfile - take commands from a file.
960 return options_from_file(*argv, 1, 1);
964 * setdebug - Set debug (command line argument).
974 * setkdebug - Set kernel debugging level.
980 return int_option(*argv, &kdebugflag);
984 * noopt - Disable all options.
989 BZERO((char *) &lcp_wantoptions[0], sizeof (struct lcp_options));
990 BZERO((char *) &lcp_allowoptions[0], sizeof (struct lcp_options));
991 BZERO((char *) &ipcp_wantoptions[0], sizeof (struct ipcp_options));
992 BZERO((char *) &ipcp_allowoptions[0], sizeof (struct ipcp_options));
995 BZERO((char *) &ipxcp_wantoptions[0], sizeof (struct ipxcp_options));
996 BZERO((char *) &ipxcp_allowoptions[0], sizeof (struct ipxcp_options));
997 #endif /* IPX_CHANGE */
1003 * noaccomp - Disable Address/Control field compression negotiation.
1008 lcp_wantoptions[0].neg_accompression = 0;
1009 lcp_allowoptions[0].neg_accompression = 0;
1015 * noasyncmap - Disable async map negotiation.
1020 lcp_wantoptions[0].neg_asyncmap = 0;
1021 lcp_allowoptions[0].neg_asyncmap = 0;
1027 * noip - Disable IP and IPCP.
1032 ipcp_protent.enabled_flag = 0;
1038 * nomagicnumber - Disable magic number negotiation.
1043 lcp_wantoptions[0].neg_magicnumber = 0;
1044 lcp_allowoptions[0].neg_magicnumber = 0;
1050 * nomru - Disable mru negotiation.
1055 lcp_wantoptions[0].neg_mru = 0;
1056 lcp_allowoptions[0].neg_mru = 0;
1062 * setmru - Set MRU for negotiation.
1070 if (!number_option(*argv, &mru, 0))
1072 lcp_wantoptions[0].mru = mru;
1073 lcp_wantoptions[0].neg_mru = 1;
1079 * setmru - Set the largest MTU we'll use.
1087 if (!number_option(*argv, &mtu, 0))
1089 if (mtu < MINMRU || mtu > MAXMRU) {
1090 option_error("mtu option value of %u is too %s", mtu,
1091 (mtu < MINMRU? "small": "large"));
1094 lcp_allowoptions[0].mru = mtu;
1100 * nopcomp - Disable Protocol field compression negotiation.
1105 lcp_wantoptions[0].neg_pcompression = 0;
1106 lcp_allowoptions[0].neg_pcompression = 0;
1112 * setpassive - Set passive mode (don't give up if we time out sending
1113 * LCP configure-requests).
1118 lcp_wantoptions[0].passive = 1;
1124 * setsilent - Set silent mode (don't start sending LCP configure-requests
1125 * until we get one from the peer).
1130 lcp_wantoptions[0].silent = 1;
1136 * nopap - Disable PAP authentication with peer.
1147 * reqpap - Require PAP authentication from peer.
1152 lcp_wantoptions[0].neg_upap = 1;
1159 * setupapfile - specifies UPAP info for authenticating with peer.
1168 lcp_allowoptions[0].neg_upap = 1;
1170 /* open user info file */
1171 if ((ufile = fopen(*argv, "r")) == NULL) {
1172 option_error("unable to open user login data file %s", *argv);
1175 if (!readable(fileno(ufile))) {
1176 option_error("%s: access denied", *argv);
1179 check_access(ufile, *argv);
1182 if (fgets(user, MAXNAMELEN - 1, ufile) == NULL
1183 || fgets(passwd, MAXSECRETLEN - 1, ufile) == NULL){
1184 option_error("unable to read user login data file %s", *argv);
1189 /* get rid of newlines */
1191 if (l > 0 && user[l-1] == '\n')
1194 if (l > 0 && passwd[l-1] == '\n')
1202 * nochap - Disable CHAP authentication with peer.
1213 * reqchap - Require CHAP authentication from peer.
1218 lcp_wantoptions[0].neg_chap = 1;
1225 * setnovj - disable vj compression
1230 ipcp_wantoptions[0].neg_vj = 0;
1231 ipcp_allowoptions[0].neg_vj = 0;
1237 * setnovjccomp - disable VJ connection-ID compression
1242 ipcp_wantoptions[0].cflag = 0;
1243 ipcp_allowoptions[0].cflag = 0;
1249 * setvjslots - set maximum number of connection slots for VJ compression
1257 if (!int_option(*argv, &value))
1259 if (value < 2 || value > 16) {
1260 option_error("vj-max-slots value must be between 2 and 16");
1263 ipcp_wantoptions [0].maxslotindex =
1264 ipcp_allowoptions[0].maxslotindex = value - 1;
1270 * setconnector - Set a program to connect to a serial line
1276 connector = strdup(*argv);
1277 if (connector == NULL)
1278 novm("connect script");
1284 * setdisconnector - Set a program to disconnect from the serial line
1287 setdisconnector(argv)
1290 disconnector = strdup(*argv);
1291 if (disconnector == NULL)
1292 novm("disconnect script");
1298 * setwelcomer - Set a program to welcome a client after connection
1304 welcomer = strdup(*argv);
1305 if (welcomer == NULL)
1306 novm("welcome script");
1312 * setmaxconnect - Set the maximum connect time
1320 if (!int_option(*argv, &value))
1323 option_error("maxconnect time must be positive");
1331 * setdomain - Set domain name to append to hostname
1337 gethostname(hostname, MAXNAMELEN);
1340 strncat(hostname, ".", MAXNAMELEN - strlen(hostname));
1341 strncat(hostname, *argv, MAXNAMELEN - strlen(hostname));
1343 hostname[MAXNAMELEN-1] = 0;
1349 * setasyncmap - add bits to asyncmap (what we request peer to escape).
1357 if (!number_option(*argv, &asyncmap, 16))
1359 lcp_wantoptions[0].asyncmap |= asyncmap;
1360 lcp_wantoptions[0].neg_asyncmap = 1;
1366 * setescape - add chars to the set we escape on transmission.
1378 n = strtol(p, &endp, 16);
1380 option_error("escape parameter contains invalid hex number '%s'",
1385 if (n < 0 || 0x20 <= n && n <= 0x3F || n == 0x5E || n > 0xFF) {
1386 option_error("can't escape character 0x%x", n);
1389 xmit_accm[0][n >> 5] |= 1 << (n & 0x1F);
1390 while (*p == ',' || *p == ' ')
1398 * setspeed - Set the speed.
1407 spd = strtol(arg, &ptr, 0);
1408 if (ptr == arg || *ptr != 0 || spd == 0)
1416 * setdevname - Set the device name.
1419 setdevname(cp, quiet)
1423 struct stat statbuf;
1424 char dev[MAXPATHLEN];
1429 if (strncmp("/dev/", cp, 5) != 0) {
1430 strcpy(dev, "/dev/");
1431 strncat(dev, cp, MAXPATHLEN - 5);
1432 dev[MAXPATHLEN-1] = 0;
1437 * Check if there is a device by this name.
1439 if (stat(cp, &statbuf) < 0) {
1440 if (errno == ENOENT || quiet)
1442 option_error("Couldn't stat %s: %m", cp);
1446 (void) strncpy(devnam, cp, MAXPATHLEN);
1447 devnam[MAXPATHLEN-1] = 0;
1448 default_device = FALSE;
1455 * setipaddr - Set the IP address
1463 u_int32_t local, remote;
1464 ipcp_options *wo = &ipcp_wantoptions[0];
1467 * IP address pair separated by ":".
1469 if ((colon = strchr(arg, ':')) == NULL)
1473 * If colon first character, then no local addr.
1477 if ((local = inet_addr(arg)) == -1) {
1478 if ((hp = gethostbyname(arg)) == NULL) {
1479 option_error("unknown host: %s", arg);
1482 local = *(u_int32_t *)hp->h_addr;
1483 if (our_name[0] == 0) {
1484 strncpy(our_name, arg, MAXNAMELEN);
1485 our_name[MAXNAMELEN-1] = 0;
1489 if (bad_ip_adrs(local)) {
1490 option_error("bad local IP address %s", ip_ntoa(local));
1494 wo->ouraddr = local;
1499 * If colon last character, then no remote addr.
1501 if (*++colon != '\0') {
1502 if ((remote = inet_addr(colon)) == -1) {
1503 if ((hp = gethostbyname(colon)) == NULL) {
1504 option_error("unknown host: %s", colon);
1507 remote = *(u_int32_t *)hp->h_addr;
1508 if (remote_name[0] == 0) {
1509 strncpy(remote_name, colon, MAXNAMELEN);
1510 remote_name[MAXNAMELEN-1] = 0;
1514 if (bad_ip_adrs(remote)) {
1515 option_error("bad remote IP address %s", ip_ntoa(remote));
1519 wo->hisaddr = remote;
1527 * setnoipdflt - disable setipdefault()
1532 disable_defaultip = 1;
1538 * setipcpaccl - accept peer's idea of our address
1543 ipcp_wantoptions[0].accept_local = 1;
1549 * setipcpaccr - accept peer's idea of its address
1554 ipcp_wantoptions[0].accept_remote = 1;
1560 * setnetmask - set the netmask to be used on the interface.
1568 if ((mask = inet_addr(*argv)) == -1 || (netmask & ~mask) != 0) {
1569 option_error("invalid netmask value '%s'", *argv);
1594 lcp_wantoptions[0].asyncmap |= 0x000A0000; /* escape ^S and ^Q */
1595 lcp_wantoptions[0].neg_asyncmap = 1;
1647 if (our_name[0] == 0) {
1648 strncpy(our_name, argv[0], MAXNAMELEN);
1649 our_name[MAXNAMELEN-1] = 0;
1658 strncpy(user, argv[0], MAXNAMELEN);
1659 user[MAXNAMELEN-1] = 0;
1667 strncpy(remote_name, argv[0], MAXNAMELEN);
1668 remote_name[MAXNAMELEN-1] = 0;
1682 if (!ipcp_allowoptions[0].default_route) {
1683 option_error("defaultroute option is disabled");
1686 ipcp_wantoptions[0].default_route = 1;
1693 ipcp_allowoptions[0].default_route = 0;
1694 ipcp_wantoptions[0].default_route = 0;
1701 if (!ipcp_allowoptions[0].proxy_arp) {
1702 option_error("proxyarp option is disabled");
1705 ipcp_wantoptions[0].proxy_arp = 1;
1712 ipcp_wantoptions[0].proxy_arp = 0;
1713 ipcp_allowoptions[0].proxy_arp = 0;
1732 * Functions to set the echo interval for modem-less monitors
1736 setlcpechointv(argv)
1739 return int_option(*argv, &lcp_echo_interval);
1743 setlcpechofails(argv)
1746 return int_option(*argv, &lcp_echo_fails);
1750 * Functions to set timeouts, max transmits, etc.
1756 return int_option(*argv, &lcp_fsm[0].timeouttime);
1763 return int_option(*argv, &lcp_fsm[0].maxtermtransmits);
1770 return int_option(*argv, &lcp_fsm[0].maxconfreqtransmits);
1777 return int_option(*argv, &lcp_fsm[0].maxnakloops);
1781 setipcptimeout(argv)
1784 return int_option(*argv, &ipcp_fsm[0].timeouttime);
1791 return int_option(*argv, &ipcp_fsm[0].maxtermtransmits);
1798 return int_option(*argv, &ipcp_fsm[0].maxconfreqtransmits);
1805 return int_option(*argv, &lcp_fsm[0].maxnakloops);
1812 return int_option(*argv, &upap[0].us_timeouttime);
1819 return int_option(*argv, &upap[0].us_reqtimeout);
1826 return int_option(*argv, &upap[0].us_maxtransmits);
1830 setchaptimeout(argv)
1833 return int_option(*argv, &chap[0].timeouttime);
1840 return int_option(*argv, &chap[0].max_transmits);
1847 return int_option(*argv, &chap[0].chal_interval);
1853 ccp_protent.enabled_flag = 0;
1865 abits = rbits = strtol(str, &endp, 0);
1866 if (endp != str && *endp == ',') {
1868 abits = strtol(str, &endp, 0);
1870 if (*endp != 0 || endp == str) {
1871 option_error("invalid parameter '%s' for bsdcomp option", *argv);
1874 if (rbits != 0 && (rbits < BSD_MIN_BITS || rbits > BSD_MAX_BITS)
1875 || abits != 0 && (abits < BSD_MIN_BITS || abits > BSD_MAX_BITS)) {
1876 option_error("bsdcomp option values must be 0 or %d .. %d",
1877 BSD_MIN_BITS, BSD_MAX_BITS);
1881 ccp_wantoptions[0].bsd_compress = 1;
1882 ccp_wantoptions[0].bsd_bits = rbits;
1884 ccp_wantoptions[0].bsd_compress = 0;
1886 ccp_allowoptions[0].bsd_compress = 1;
1887 ccp_allowoptions[0].bsd_bits = abits;
1889 ccp_allowoptions[0].bsd_compress = 0;
1896 ccp_wantoptions[0].bsd_compress = 0;
1897 ccp_allowoptions[0].bsd_compress = 0;
1909 abits = rbits = strtol(str, &endp, 0);
1910 if (endp != str && *endp == ',') {
1912 abits = strtol(str, &endp, 0);
1914 if (*endp != 0 || endp == str) {
1915 option_error("invalid parameter '%s' for deflate option", *argv);
1918 if (rbits != 0 && (rbits < DEFLATE_MIN_SIZE || rbits > DEFLATE_MAX_SIZE)
1919 || abits != 0 && (abits < DEFLATE_MIN_SIZE
1920 || abits > DEFLATE_MAX_SIZE)) {
1921 option_error("deflate option values must be 0 or %d .. %d",
1922 DEFLATE_MIN_SIZE, DEFLATE_MAX_SIZE);
1926 ccp_wantoptions[0].deflate = 1;
1927 ccp_wantoptions[0].deflate_size = rbits;
1929 ccp_wantoptions[0].deflate = 0;
1931 ccp_allowoptions[0].deflate = 1;
1932 ccp_allowoptions[0].deflate_size = abits;
1934 ccp_allowoptions[0].deflate = 0;
1941 ccp_wantoptions[0].deflate = 0;
1942 ccp_allowoptions[0].deflate = 0;
1949 ccp_wantoptions[0].predictor_1 = 1;
1950 ccp_allowoptions[0].predictor_1 = 1;
1957 ccp_wantoptions[0].predictor_1 = 0;
1958 ccp_allowoptions[0].predictor_1 = 0;
1966 ipparam = strdup(*argv);
1967 if (ipparam == NULL)
1968 novm("ipparam string");
1984 return int_option(*argv, &idle_time_limit);
1991 return int_option(*argv, &holdoff);
1999 ipxcp_wantoptions[0].neg_router = 1;
2000 ipxcp_allowoptions[0].neg_router = 1;
2001 return int_option(*argv, &ipxcp_wantoptions[0].router);
2008 char *dest = ipxcp_wantoptions[0].name;
2013 ipxcp_wantoptions[0].neg_name = 1;
2014 ipxcp_allowoptions[0].neg_name = 1;
2015 memset (dest, '\0', sizeof (ipxcp_wantoptions[0].name));
2020 if (! isalnum (ch) && ch != '_') {
2021 option_error("IPX router name must be alphanumeric or _");
2025 if (count >= sizeof (ipxcp_wantoptions[0].name)) {
2026 option_error("IPX router name is limited to %d characters",
2027 sizeof (ipxcp_wantoptions[0].name) - 1);
2031 dest[count++] = toupper (ch);
2038 setipxcptimeout (argv)
2041 return int_option(*argv, &ipxcp_fsm[0].timeouttime);
2048 return int_option(*argv, &ipxcp_fsm[0].maxtermtransmits);
2055 return int_option(*argv, &ipxcp_fsm[0].maxconfreqtransmits);
2059 setipxcpfails (argv)
2062 return int_option(*argv, &ipxcp_fsm[0].maxnakloops);
2069 ipxcp_wantoptions[0].neg_nn = 1;
2070 return int_option(*argv, &ipxcp_wantoptions[0].our_network);
2076 ipxcp_wantoptions[0].accept_network = 1;
2077 ipxcp_allowoptions[0].accept_network = 1;
2083 ipxcp_wantoptions[0].accept_local = 1;
2084 ipxcp_allowoptions[0].accept_local = 1;
2090 ipxcp_wantoptions[0].accept_remote = 1;
2091 ipxcp_allowoptions[0].accept_remote = 1;
2095 setipxnodevalue(src,dst)
2102 if (!isxdigit (*src))
2105 for (indx = 0; indx < 5; ++indx) {
2107 dst[indx] |= (dst[indx + 1] >> 4) & 0x0F;
2110 item = toupper (*src) - '0';
2114 dst[5] = (dst[5] << 4) | item;
2126 memset (&ipxcp_wantoptions[0].our_node[0], 0, 6);
2127 memset (&ipxcp_wantoptions[0].his_node[0], 0, 6);
2129 end = setipxnodevalue (*argv, &ipxcp_wantoptions[0].our_node[0]);
2131 end = setipxnodevalue (++end, &ipxcp_wantoptions[0].his_node[0]);
2134 ipxcp_wantoptions[0].neg_node = 1;
2138 option_error("invalid parameter '%s' for ipx-node option", *argv);
2145 ipxcp_protent.enabled_flag = 1;
2152 ipxcp_protent.enabled_flag = 0;
2155 #endif /* IPX_CHANGE */
2159 * setdnsaddr - set the dns address(es)
2169 dns = inet_addr(*argv);
2171 if ((hp = gethostbyname(*argv)) == NULL) {
2172 option_error("invalid address parameter '%s' for ms-dns option",
2176 dns = *(u_int32_t *)hp->h_addr;
2179 if (ipcp_allowoptions[0].dnsaddr[0] == 0) {
2180 ipcp_allowoptions[0].dnsaddr[0] = dns;
2182 ipcp_allowoptions[0].dnsaddr[1] = dns;
2187 #endif /* USE_MS_DNS */