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.36 1996/10/08 04:35:03 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"
55 #endif /* IPX_CHANGE */
57 #include <net/ppp-comp.h>
62 #if defined(ultrix) || defined(NeXT)
63 char *strdup __P((char *));
67 #define GIDSET_TYPE gid_t
71 * Option variables and default values.
73 int debug = 0; /* Debug flag */
74 int kdebugflag = 0; /* Tell kernel to print debug messages */
75 int default_device = 1; /* Using /dev/tty or equivalent */
76 char devnam[MAXPATHLEN] = "/dev/tty"; /* Device name */
77 int crtscts = 0; /* Use hardware flow control */
78 int modem = 1; /* Use modem control lines */
79 int inspeed = 0; /* Input/Output speed requested */
80 u_int32_t netmask = 0; /* IP netmask to set on interface */
81 int lockflag = 0; /* Create lock file to lock the serial dev */
82 int nodetach = 0; /* Don't detach from controlling tty */
83 char *connector = NULL; /* Script to establish physical link */
84 char *disconnector = NULL; /* Script to disestablish physical link */
85 char *welcomer = NULL; /* Script to run after phys link estab. */
86 int maxconnect = 0; /* Maximum connect time */
87 char user[MAXNAMELEN]; /* Username for PAP */
88 char passwd[MAXSECRETLEN]; /* Password for PAP */
89 int auth_required = 0; /* Peer is required to authenticate */
90 int defaultroute = 0; /* assign default route through interface */
91 int proxyarp = 0; /* Set up proxy ARP entry for peer */
92 int persist = 0; /* Reopen link after it goes down */
93 int uselogin = 0; /* Use /etc/passwd for checking PAP */
94 int lcp_echo_interval = 0; /* Interval between LCP echo-requests */
95 int lcp_echo_fails = 0; /* Tolerance to unanswered echo-requests */
96 char our_name[MAXNAMELEN]; /* Our name for authentication purposes */
97 char remote_name[MAXNAMELEN]; /* Peer's name for authentication */
98 int usehostname = 0; /* Use hostname for our_name */
99 int disable_defaultip = 0; /* Don't use hostname for default IP adrs */
100 int demand = 0; /* do dial-on-demand */
101 char *ipparam = NULL; /* Extra parameter for ip up/down scripts */
102 int cryptpap; /* Passwords in pap-secrets are encrypted */
103 int idle_time_limit = 0; /* Disconnect if idle for this many seconds */
104 int holdoff = 30; /* # seconds to pause before reconnecting */
105 int refuse_pap = 0; /* Set to say we won't do PAP */
106 int refuse_chap = 0; /* Set to say we won't do CHAP */
108 struct option_info auth_req_info;
109 struct option_info connector_info;
110 struct option_info disconnector_info;
111 struct option_info welcomer_info;
112 struct option_info devnam_info;
117 static int setdevname __P((char *, int));
118 static int setipaddr __P((char *));
119 static int setdebug __P((void));
120 static int setkdebug __P((char **));
121 static int setpassive __P((void));
122 static int setsilent __P((void));
123 static int noopt __P((void));
124 static int setnovj __P((void));
125 static int setnovjccomp __P((void));
126 static int setvjslots __P((char **));
127 static int reqpap __P((void));
128 static int nopap __P((void));
130 static int setupapfile __P((char **));
132 static int nochap __P((void));
133 static int reqchap __P((void));
134 static int setspeed __P((char *));
135 static int noaccomp __P((void));
136 static int noasyncmap __P((void));
137 static int noip __P((void));
138 static int nomagicnumber __P((void));
139 static int setasyncmap __P((char **));
140 static int setescape __P((char **));
141 static int setmru __P((char **));
142 static int setmtu __P((char **));
144 static int setcbcp __P((char **));
146 static int nomru __P((void));
147 static int nopcomp __P((void));
148 static int setconnector __P((char **));
149 static int setdisconnector __P((char **));
150 static int setwelcomer __P((char **));
151 static int setmaxconnect __P((char **));
152 static int setdomain __P((char **));
153 static int setnetmask __P((char **));
154 static int setcrtscts __P((void));
155 static int setnocrtscts __P((void));
156 static int setxonxoff __P((void));
157 static int setnodetach __P((void));
158 static int setmodem __P((void));
159 static int setlocal __P((void));
160 static int setlock __P((void));
161 static int setname __P((char **));
162 static int setuser __P((char **));
163 static int setremote __P((char **));
164 static int setauth __P((void));
165 static int setnoauth __P((void));
166 static int readfile __P((char **));
167 static int callfile __P((char **));
168 static int setdefaultroute __P((void));
169 static int setnodefaultroute __P((void));
170 static int setproxyarp __P((void));
171 static int setnoproxyarp __P((void));
172 static int setpersist __P((void));
173 static int setnopersist __P((void));
174 static int setdologin __P((void));
175 static int setusehostname __P((void));
176 static int setnoipdflt __P((void));
177 static int setlcptimeout __P((char **));
178 static int setlcpterm __P((char **));
179 static int setlcpconf __P((char **));
180 static int setlcpfails __P((char **));
181 static int setipcptimeout __P((char **));
182 static int setipcpterm __P((char **));
183 static int setipcpconf __P((char **));
184 static int setipcpfails __P((char **));
185 static int setpaptimeout __P((char **));
186 static int setpapreqs __P((char **));
187 static int setpapreqtime __P((char **));
188 static int setchaptimeout __P((char **));
189 static int setchapchal __P((char **));
190 static int setchapintv __P((char **));
191 static int setipcpaccl __P((void));
192 static int setipcpaccr __P((void));
193 static int setlcpechointv __P((char **));
194 static int setlcpechofails __P((char **));
195 static int noccp __P((void));
196 static int setbsdcomp __P((char **));
197 static int setnobsdcomp __P((void));
198 static int setdeflate __P((char **));
199 static int setnodeflate __P((void));
200 static int setdemand __P((void));
201 static int setpred1comp __P((void));
202 static int setnopred1comp __P((void));
203 static int setipparam __P((char **));
204 static int setpapcrypt __P((void));
205 static int setidle __P((char **));
206 static int setholdoff __P((char **));
207 static int setdnsaddr __P((char **));
208 static int resetipxproto __P((void));
211 static int setipxproto __P((void));
212 static int setipxanet __P((void));
213 static int setipxalcl __P((void));
214 static int setipxarmt __P((void));
215 static int setipxnetwork __P((char **));
216 static int setipxnode __P((char **));
217 static int setipxrouter __P((char **));
218 static int setipxname __P((char **));
219 static int setipxcptimeout __P((char **));
220 static int setipxcpterm __P((char **));
221 static int setipxcpconf __P((char **));
222 static int setipxcpfails __P((char **));
223 #endif /* IPX_CHANGE */
225 static int number_option __P((char *, u_int32_t *, int));
226 static int int_option __P((char *, int *));
227 static int readable __P((int fd));
237 {"-all", 0, noopt}, /* Don't request/allow any options (useless) */
238 {"noaccomp", 0, noaccomp}, /* Disable Address/Control compression */
239 {"-ac", 0, noaccomp}, /* Disable Address/Control compress */
240 {"default-asyncmap", 0, noasyncmap}, /* Disable asyncmap negoatiation */
241 {"-am", 0, noasyncmap}, /* Disable asyncmap negotiation */
242 {"-as", 1, setasyncmap}, /* set the desired async map */
243 {"-d", 0, setdebug}, /* Increase debugging level */
244 {"nodetach", 0, setnodetach}, /* Don't detach from controlling tty */
245 {"-detach", 0, setnodetach}, /* don't fork */
246 {"noip", 0, noip}, /* Disable IP and IPCP */
247 {"-ip", 0, noip}, /* Disable IP and IPCP */
248 {"nomagic", 0, nomagicnumber}, /* Disable magic number negotiation */
249 {"-mn", 0, nomagicnumber}, /* Disable magic number negotiation */
250 {"default-mru", 0, nomru}, /* Disable MRU negotiation */
251 {"-mru", 0, nomru}, /* Disable mru negotiation */
252 {"-p", 0, setpassive}, /* Set passive mode */
253 {"nopcomp", 0, nopcomp}, /* Disable protocol field compression */
254 {"-pc", 0, nopcomp}, /* Disable protocol field compress */
256 {"+ua", 1, setupapfile}, /* Get PAP user and password from file */
258 {"require-pap", 0, reqpap}, /* Require PAP authentication from peer */
259 {"+pap", 0, reqpap}, /* Require PAP auth from peer */
260 {"refuse-pap", 0, nopap}, /* Don't agree to auth to peer with PAP */
261 {"-pap", 0, nopap}, /* Don't allow UPAP authentication with peer */
262 {"require-chap", 0, reqchap}, /* Require CHAP authentication from peer */
263 {"+chap", 0, reqchap}, /* Require CHAP authentication from peer */
264 {"refuse-chap", 0, nochap}, /* Don't agree to auth to peer with CHAP */
265 {"-chap", 0, nochap}, /* Don't allow CHAP authentication with peer */
266 {"novj", 0, setnovj}, /* Disable VJ compression */
267 {"-vj", 0, setnovj}, /* disable VJ compression */
268 {"novjccomp", 0, setnovjccomp}, /* disable VJ connection-ID compression */
269 {"-vjccomp", 0, setnovjccomp}, /* disable VJ connection-ID compression */
270 {"vj-max-slots", 1, setvjslots}, /* Set maximum VJ header slots */
271 {"asyncmap", 1, setasyncmap}, /* set the desired async map */
272 {"escape", 1, setescape}, /* set chars to escape on transmission */
273 {"connect", 1, setconnector}, /* A program to set up a connection */
274 {"disconnect", 1, setdisconnector}, /* program to disconnect serial dev. */
275 {"welcome", 1, setwelcomer},/* Script to welcome client */
276 {"maxconnect", 1, setmaxconnect}, /* specify a maximum connect time */
277 {"crtscts", 0, setcrtscts}, /* set h/w flow control */
278 {"nocrtscts", 0, setnocrtscts}, /* clear h/w flow control */
279 {"-crtscts", 0, setnocrtscts}, /* clear h/w flow control */
280 {"xonxoff", 0, setxonxoff}, /* set s/w flow control */
281 {"debug", 0, setdebug}, /* Increase debugging level */
282 {"kdebug", 1, setkdebug}, /* Enable kernel-level debugging */
283 {"domain", 1, setdomain}, /* Add given domain name to hostname*/
284 {"mru", 1, setmru}, /* Set MRU value for negotiation */
285 {"mtu", 1, setmtu}, /* Set our MTU */
287 {"callback", 1, setcbcp}, /* Ask for callback */
289 {"netmask", 1, setnetmask}, /* set netmask */
290 {"passive", 0, setpassive}, /* Set passive mode */
291 {"silent", 0, setsilent}, /* Set silent mode */
292 {"modem", 0, setmodem}, /* Use modem control lines */
293 {"local", 0, setlocal}, /* Don't use modem control lines */
294 {"lock", 0, setlock}, /* Lock serial device (with lock file) */
295 {"name", 1, setname}, /* Set local name for authentication */
296 {"user", 1, setuser}, /* Set name for auth with peer */
297 {"usehostname", 0, setusehostname}, /* Must use hostname for auth. */
298 {"remotename", 1, setremote}, /* Set remote name for authentication */
299 {"auth", 0, setauth}, /* Require authentication from peer */
300 {"noauth", 0, setnoauth}, /* Don't require peer to authenticate */
301 {"file", 1, readfile}, /* Take options from a file */
302 {"call", 1, callfile}, /* Take options from a privileged file */
303 {"defaultroute", 0, setdefaultroute}, /* Add default route */
304 {"nodefaultroute", 0, setnodefaultroute}, /* disable defaultroute option */
305 {"-defaultroute", 0, setnodefaultroute}, /* disable defaultroute option */
306 {"proxyarp", 0, setproxyarp}, /* Add proxy ARP entry */
307 {"noproxyarp", 0, setnoproxyarp}, /* disable proxyarp option */
308 {"-proxyarp", 0, setnoproxyarp}, /* disable proxyarp option */
309 {"persist", 0, setpersist}, /* Keep on reopening connection after close */
310 {"nopersist", 0, setnopersist}, /* Turn off persist option */
311 {"demand", 0, setdemand}, /* Dial on demand */
312 {"login", 0, setdologin}, /* Use system password database for UPAP */
313 {"noipdefault", 0, setnoipdflt}, /* Don't use name for default IP adrs */
314 {"lcp-echo-failure", 1, setlcpechofails}, /* consecutive echo failures */
315 {"lcp-echo-interval", 1, setlcpechointv}, /* time for lcp echo events */
316 {"lcp-restart", 1, setlcptimeout}, /* Set timeout for LCP */
317 {"lcp-max-terminate", 1, setlcpterm}, /* Set max #xmits for term-reqs */
318 {"lcp-max-configure", 1, setlcpconf}, /* Set max #xmits for conf-reqs */
319 {"lcp-max-failure", 1, setlcpfails}, /* Set max #conf-naks for LCP */
320 {"ipcp-restart", 1, setipcptimeout}, /* Set timeout for IPCP */
321 {"ipcp-max-terminate", 1, setipcpterm}, /* Set max #xmits for term-reqs */
322 {"ipcp-max-configure", 1, setipcpconf}, /* Set max #xmits for conf-reqs */
323 {"ipcp-max-failure", 1, setipcpfails}, /* Set max #conf-naks for IPCP */
324 {"pap-restart", 1, setpaptimeout}, /* Set retransmit timeout for PAP */
325 {"pap-max-authreq", 1, setpapreqs}, /* Set max #xmits for auth-reqs */
326 {"pap-timeout", 1, setpapreqtime}, /* Set time limit for peer PAP auth. */
327 {"chap-restart", 1, setchaptimeout}, /* Set timeout for CHAP */
328 {"chap-max-challenge", 1, setchapchal}, /* Set max #xmits for challenge */
329 {"chap-interval", 1, setchapintv}, /* Set interval for rechallenge */
330 {"ipcp-accept-local", 0, setipcpaccl}, /* Accept peer's address for us */
331 {"ipcp-accept-remote", 0, setipcpaccr}, /* Accept peer's address for it */
332 {"noccp", 0, noccp}, /* Disable CCP negotiation */
333 {"-ccp", 0, noccp}, /* Disable CCP negotiation */
334 {"bsdcomp", 1, setbsdcomp}, /* request BSD-Compress */
335 {"nobsdcomp", 0, setnobsdcomp}, /* don't allow BSD-Compress */
336 {"-bsdcomp", 0, setnobsdcomp}, /* don't allow BSD-Compress */
337 {"deflate", 1, setdeflate}, /* request Deflate compression */
338 {"nodeflate", 0, setnodeflate}, /* don't allow Deflate compression */
339 {"-deflate", 0, setnodeflate}, /* don't allow Deflate compression */
340 {"predictor1", 0, setpred1comp}, /* request Predictor-1 */
341 {"nopredictor1", 0, setnopred1comp},/* don't allow Predictor-1 */
342 {"-predictor1", 0, setnopred1comp}, /* don't allow Predictor-1 */
343 {"ipparam", 1, setipparam}, /* set ip script parameter */
344 {"papcrypt", 0, setpapcrypt}, /* PAP passwords encrypted */
345 {"idle", 1, setidle}, /* idle time limit (seconds) */
346 {"holdoff", 1, setholdoff}, /* set holdoff time (seconds) */
347 {"ms-dns", 1, setdnsaddr}, /* DNS address for the peer's use */
348 {"noipx", 0, resetipxproto}, /* Disable IPXCP (and IPX) */
349 {"-ipx", 0, resetipxproto}, /* Disable IPXCP (and IPX) */
352 {"ipx-network", 1, setipxnetwork}, /* IPX network number */
353 {"ipxcp-accept-network", 0, setipxanet}, /* Accept peer netowrk */
354 {"ipx-node", 1, setipxnode}, /* IPX node number */
355 {"ipxcp-accept-local", 0, setipxalcl}, /* Accept our address */
356 {"ipxcp-accept-remote", 0, setipxarmt}, /* Accept peer's address */
357 {"ipx-routing", 1, setipxrouter}, /* IPX routing proto number */
358 {"ipx-router-name", 1, setipxname}, /* IPX router name */
359 {"ipxcp-restart", 1, setipxcptimeout}, /* Set timeout for IPXCP */
360 {"ipxcp-max-terminate", 1, setipxcpterm}, /* max #xmits for term-reqs */
361 {"ipxcp-max-configure", 1, setipxcpconf}, /* max #xmits for conf-reqs */
362 {"ipxcp-max-failure", 1, setipxcpfails}, /* max #conf-naks for IPXCP */
364 {"ipx-compression", 1, setipxcompression}, /* IPX compression number */
366 {"ipx", 0, setipxproto}, /* Enable IPXCP (and IPX) */
367 {"+ipx", 0, setipxproto}, /* Enable IPXCP (and IPX) */
368 #endif /* IPX_CHANGE */
374 #ifndef IMPLEMENTATION
375 #define IMPLEMENTATION ""
378 static char *usage_string = "\
379 pppd version %s patch level %d%s\n\
380 Usage: %s [ options ], where options are:\n\
381 <device> Communicate over the named device\n\
382 <speed> Set the baud rate to <speed>\n\
383 <loc>:<rem> Set the local and/or remote interface IP\n\
384 addresses. Either one may be omitted.\n\
385 asyncmap <n> Set the desired async map to hex <n>\n\
386 auth Require authentication from peer\n\
387 connect <p> Invoke shell command <p> to set up the serial line\n\
388 crtscts Use hardware RTS/CTS flow control\n\
389 defaultroute Add default route through interface\n\
390 file <f> Take options from file <f>\n\
391 modem Use modem control lines\n\
392 mru <n> Set MRU value to <n> for negotiation\n\
393 netmask <n> Set interface netmask to <n>\n\
394 See pppd(8) for more options.\n\
397 static char *current_option; /* the name of the option being parsed */
398 static int privileged_option; /* set iff the current option came from root */
399 static char *option_source; /* string saying where the option came from */
402 * parse_args - parse a string of arguments from the command line.
405 parse_args(argc, argv)
413 privileged_option = privileged;
414 option_source = "command line";
420 * First see if it's a command.
422 for (cmdp = cmds; cmdp->cmd_name; cmdp++)
423 if (!strcmp(arg, cmdp->cmd_name))
426 if (cmdp->cmd_name != NULL) {
427 if (argc < cmdp->num_args) {
428 option_error("too few parameters for option %s", arg);
431 current_option = arg;
432 if (!(*cmdp->cmd_func)(argv))
434 argc -= cmdp->num_args;
435 argv += cmdp->num_args;
439 * Maybe a tty name, speed or IP address?
441 if ((ret = setdevname(arg, 0)) == 0
442 && (ret = setspeed(arg)) == 0
443 && (ret = setipaddr(arg)) == 0) {
444 option_error("unrecognized option '%s'", arg);
448 if (ret < 0) /* error */
456 * scan_args - scan the command line arguments to get the tty name,
460 scan_args(argc, argv)
471 /* Skip options and their arguments */
472 for (cmdp = cmds; cmdp->cmd_name; cmdp++)
473 if (!strcmp(arg, cmdp->cmd_name))
476 if (cmdp->cmd_name != NULL) {
477 argc -= cmdp->num_args;
478 argv += cmdp->num_args;
482 /* Check if it's a tty name and copy it if so */
483 (void) setdevname(arg, 1);
488 * usage - print out a message telling how to use the program.
493 if (phase == PHASE_INITIALIZE)
494 fprintf(stderr, usage_string, VERSION, PATCHLEVEL, IMPLEMENTATION,
499 * options_from_file - Read a string of options from a file,
500 * and interpret them.
503 options_from_file(filename, must_exist, check_prot, priv)
514 char args[MAXARGS][MAXWORDLEN];
515 char cmd[MAXWORDLEN];
517 if ((f = fopen(filename, "r")) == NULL) {
518 if (!must_exist && errno == ENOENT)
520 option_error("Can't open options file %s: %m", filename);
523 if (check_prot && !readable(fileno(f))) {
524 option_error("Can't open options file %s: access denied", filename);
529 oldpriv = privileged_option;
530 privileged_option = priv;
532 while (getword(f, cmd, &newline, filename)) {
534 * First see if it's a command.
536 for (cmdp = cmds; cmdp->cmd_name; cmdp++)
537 if (!strcmp(cmd, cmdp->cmd_name))
540 if (cmdp->cmd_name != NULL) {
541 for (i = 0; i < cmdp->num_args; ++i) {
542 if (!getword(f, args[i], &newline, filename)) {
544 "In file %s: too few parameters for option '%s'",
550 current_option = cmd;
551 if (!(*cmdp->cmd_func)(argv))
556 * Maybe a tty name, speed or IP address?
558 if ((i = setdevname(cmd, 0)) == 0
559 && (i = setspeed(cmd)) == 0
560 && (i = setipaddr(cmd)) == 0) {
561 option_error("In file %s: unrecognized option '%s'",
565 if (i < 0) /* error */
573 privileged_option = oldpriv;
578 * options_from_user - See if the use has a ~/.ppprc file,
579 * and if so, interpret options from it.
584 char *user, *path, *file;
588 pw = getpwuid(getuid());
589 if (pw == NULL || (user = pw->pw_dir) == NULL || user[0] == 0)
591 file = _PATH_USEROPT;
592 path = malloc(strlen(user) + strlen(file) + 2);
594 novm("init file name");
598 ret = options_from_file(path, 0, 1, privileged);
604 * options_for_tty - See if an options file exists for the serial
605 * device, and if so, interpret options from it.
610 char *dev, *path, *p;
614 if (strncmp(dev, "/dev/", 5) == 0)
616 if (strcmp(dev, "tty") == 0)
617 return 1; /* don't look for /etc/ppp/options.tty */
618 path = malloc(strlen(_PATH_TTYOPT) + strlen(dev) + 1);
620 novm("tty init file name");
621 strcpy(path, _PATH_TTYOPT);
622 /* Turn slashes into dots, for Solaris case (e.g. /dev/term/a) */
623 for (p = path + strlen(path); *dev != 0; ++dev)
624 *p++ = (*dev == '/'? '.': *dev);
626 ret = options_from_file(path, 0, 0, 1);
632 * option_error - print a message about an error in an option.
633 * The message is logged, and also sent to
634 * stderr if phase == PHASE_INITIALIZE.
637 option_error __V((char *fmt, ...))
648 fmt = va_arg(args, char *);
650 vfmtmsg(buf, sizeof(buf), fmt, args);
652 if (phase == PHASE_INITIALIZE)
653 fprintf(stderr, "%s: %s\n", progname, buf);
654 syslog(LOG_ERR, "%s", buf);
658 * readable - check if a file is readable by the real user.
667 GIDSET_TYPE groups[NGROUPS_MAX];
672 if (fstat(fd, &sbuf) != 0)
674 if (sbuf.st_uid == uid)
675 return sbuf.st_mode & S_IRUSR;
676 if (sbuf.st_gid == getgid())
677 return sbuf.st_mode & S_IRGRP;
678 ngroups = getgroups(NGROUPS_MAX, groups);
679 for (i = 0; i < ngroups; ++i)
680 if (sbuf.st_gid == groups[i])
681 return sbuf.st_mode & S_IRGRP;
682 return sbuf.st_mode & S_IROTH;
686 * Read a word from a file.
687 * Words are delimited by white-space or by quotes (" or ').
688 * Quotes, white-space and \ may be escaped with \.
689 * \<newline> is ignored.
692 getword(f, word, newlinep, filename)
700 int value, digit, got, n;
702 #define isoctal(c) ((c) >= '0' && (c) < '8')
710 * First skip white-space and comments.
718 * A newline means the end of a comment; backslash-newline
719 * is ignored. Note that we cannot have escape && comment.
731 * Ignore characters other than newline in a comment.
737 * If this character is escaped, we have a word start.
743 * If this is the escape character, look at the next character.
751 * If this is the start of a comment, ignore the rest of the line.
759 * A non-whitespace character is the start of a word.
766 * Save the delimiter for quoted strings.
768 if (!escape && (c == '"' || c == '\'')) {
775 * Process characters until the end of the word.
780 * This character is escaped: backslash-newline is ignored,
781 * various other characters indicate particular values
782 * as for C backslash-escapes.
817 * \ddd octal sequence
820 for (n = 0; n < 3 && isoctal(c); ++n) {
821 value = (value << 3) + (c & 07);
830 * \x<hex_string> sequence
834 for (n = 0; n < 2 && isxdigit(c); ++n) {
835 digit = toupper(c) - '0';
837 digit += '0' + 10 - 'A';
838 value = (value << 4) + digit;
846 * Otherwise the character stands for itself.
853 * Store the resulting character for the escape sequence.
855 if (len < MAXWORDLEN-1)
866 * Not escaped: see if we've reached the end of the word.
872 if (isspace(c) || c == '#') {
879 * Backslash starts an escape sequence.
888 * An ordinary character: store it in the word and get another.
890 if (len < MAXWORDLEN-1)
898 * End of the word: check for errors.
904 option_error("Error reading %s: %m", filename);
908 * If len is zero, then we didn't find a word before the
916 * Warn if the word was too long, and append a terminating null.
918 if (len >= MAXWORDLEN) {
919 option_error("warning: word in file %s too long (%.20s...)",
921 len = MAXWORDLEN - 1;
932 * number_option - parse an unsigned numeric parameter for an option.
935 number_option(str, valp, base)
942 *valp = strtoul(str, &ptr, base);
944 option_error("invalid numeric parameter '%s' for %s option",
945 str, current_option);
953 * int_option - like number_option, but valp is int *,
954 * the base is assumed to be 0, and *valp is not changed
955 * if there is an error.
958 int_option(str, valp)
964 if (!number_option(str, &v, 0))
972 * The following procedures parse options.
976 * readfile - take commands from a file.
982 return options_from_file(*argv, 1, 1, privileged_option);
986 * callfile - take commands from /etc/ppp/peers/<name>.
987 * Name may not contain /../, start with / or ../, or end in /..
993 char *fname, *arg, *p;
998 if (arg[0] == '/' || arg[0] == 0)
1001 for (p = arg; *p != 0; ) {
1002 if (p[0] == '.' && p[1] == '.' && (p[2] == '/' || p[2] == 0)) {
1006 while (*p != '/' && *p != 0)
1013 option_error("call option value may not contain .. or start with /");
1017 l = strlen(arg) + strlen(_PATH_PEERFILES) + 1;
1018 if ((fname = (char *) malloc(l)) == NULL)
1019 novm("call file name");
1020 strcpy(fname, _PATH_PEERFILES);
1023 ok = options_from_file(fname, 1, 1, 1);
1031 * setdebug - Set debug (command line argument).
1041 * setkdebug - Set kernel debugging level.
1047 return int_option(*argv, &kdebugflag);
1051 * noopt - Disable all options.
1056 BZERO((char *) &lcp_wantoptions[0], sizeof (struct lcp_options));
1057 BZERO((char *) &lcp_allowoptions[0], sizeof (struct lcp_options));
1058 BZERO((char *) &ipcp_wantoptions[0], sizeof (struct ipcp_options));
1059 BZERO((char *) &ipcp_allowoptions[0], sizeof (struct ipcp_options));
1062 BZERO((char *) &ipxcp_wantoptions[0], sizeof (struct ipxcp_options));
1063 BZERO((char *) &ipxcp_allowoptions[0], sizeof (struct ipxcp_options));
1064 #endif /* IPX_CHANGE */
1070 * noaccomp - Disable Address/Control field compression negotiation.
1075 lcp_wantoptions[0].neg_accompression = 0;
1076 lcp_allowoptions[0].neg_accompression = 0;
1082 * noasyncmap - Disable async map negotiation.
1087 lcp_wantoptions[0].neg_asyncmap = 0;
1088 lcp_allowoptions[0].neg_asyncmap = 0;
1094 * noip - Disable IP and IPCP.
1099 ipcp_protent.enabled_flag = 0;
1105 * nomagicnumber - Disable magic number negotiation.
1110 lcp_wantoptions[0].neg_magicnumber = 0;
1111 lcp_allowoptions[0].neg_magicnumber = 0;
1117 * nomru - Disable mru negotiation.
1122 lcp_wantoptions[0].neg_mru = 0;
1123 lcp_allowoptions[0].neg_mru = 0;
1129 * setmru - Set MRU for negotiation.
1137 if (!number_option(*argv, &mru, 0))
1139 lcp_wantoptions[0].mru = mru;
1140 lcp_wantoptions[0].neg_mru = 1;
1146 * setmru - Set the largest MTU we'll use.
1154 if (!number_option(*argv, &mtu, 0))
1156 if (mtu < MINMRU || mtu > MAXMRU) {
1157 option_error("mtu option value of %u is too %s", mtu,
1158 (mtu < MINMRU? "small": "large"));
1161 lcp_allowoptions[0].mru = mtu;
1170 lcp_wantoptions[0].neg_cbcp = 1;
1171 cbcp_protent.enabled_flag = 1;
1172 cbcp[0].us_number = strdup(*argv);
1173 if (cbcp[0].us_number == 0)
1174 novm("callback number");
1175 cbcp[0].us_type |= (1 << CB_CONF_USER);
1176 cbcp[0].us_type |= (1 << CB_CONF_ADMIN);
1182 * nopcomp - Disable Protocol field compression negotiation.
1187 lcp_wantoptions[0].neg_pcompression = 0;
1188 lcp_allowoptions[0].neg_pcompression = 0;
1194 * setpassive - Set passive mode (don't give up if we time out sending
1195 * LCP configure-requests).
1200 lcp_wantoptions[0].passive = 1;
1206 * setsilent - Set silent mode (don't start sending LCP configure-requests
1207 * until we get one from the peer).
1212 lcp_wantoptions[0].silent = 1;
1218 * nopap - Disable PAP authentication with peer.
1229 * reqpap - Require PAP authentication from peer.
1234 lcp_wantoptions[0].neg_upap = 1;
1241 * setupapfile - specifies UPAP info for authenticating with peer.
1250 lcp_allowoptions[0].neg_upap = 1;
1252 /* open user info file */
1253 if ((ufile = fopen(*argv, "r")) == NULL) {
1254 option_error("unable to open user login data file %s", *argv);
1257 if (!readable(fileno(ufile))) {
1258 option_error("%s: access denied", *argv);
1261 check_access(ufile, *argv);
1264 if (fgets(user, MAXNAMELEN - 1, ufile) == NULL
1265 || fgets(passwd, MAXSECRETLEN - 1, ufile) == NULL){
1266 option_error("unable to read user login data file %s", *argv);
1271 /* get rid of newlines */
1273 if (l > 0 && user[l-1] == '\n')
1276 if (l > 0 && passwd[l-1] == '\n')
1284 * nochap - Disable CHAP authentication with peer.
1295 * reqchap - Require CHAP authentication from peer.
1300 lcp_wantoptions[0].neg_chap = 1;
1307 * setnovj - disable vj compression
1312 ipcp_wantoptions[0].neg_vj = 0;
1313 ipcp_allowoptions[0].neg_vj = 0;
1319 * setnovjccomp - disable VJ connection-ID compression
1324 ipcp_wantoptions[0].cflag = 0;
1325 ipcp_allowoptions[0].cflag = 0;
1331 * setvjslots - set maximum number of connection slots for VJ compression
1339 if (!int_option(*argv, &value))
1341 if (value < 2 || value > 16) {
1342 option_error("vj-max-slots value must be between 2 and 16");
1345 ipcp_wantoptions [0].maxslotindex =
1346 ipcp_allowoptions[0].maxslotindex = value - 1;
1352 * setconnector - Set a program to connect to a serial line
1358 connector = strdup(*argv);
1359 if (connector == NULL)
1360 novm("connect script");
1361 connector_info.priv = privileged_option;
1362 connector_info.source = option_source;
1368 * setdisconnector - Set a program to disconnect from the serial line
1371 setdisconnector(argv)
1374 disconnector = strdup(*argv);
1375 if (disconnector == NULL)
1376 novm("disconnect script");
1377 disconnector_info.priv = privileged_option;
1378 disconnector_info.source = option_source;
1384 * setwelcomer - Set a program to welcome a client after connection
1390 welcomer = strdup(*argv);
1391 if (welcomer == NULL)
1392 novm("welcome script");
1393 welcomer_info.priv = privileged_option;
1394 welcomer_info.source = option_source;
1400 * setmaxconnect - Set the maximum connect time
1408 if (!int_option(*argv, &value))
1411 option_error("maxconnect time must be positive");
1414 if (maxconnect > 0 && (value == 0 || value > maxconnect)) {
1415 option_error("maxconnect time cannot be increased");
1423 * setdomain - Set domain name to append to hostname
1429 if (!privileged_option) {
1430 option_error("using the domain option requires root privilege");
1433 gethostname(hostname, MAXNAMELEN);
1436 strncat(hostname, ".", MAXNAMELEN - strlen(hostname));
1437 strncat(hostname, *argv, MAXNAMELEN - strlen(hostname));
1439 hostname[MAXNAMELEN-1] = 0;
1445 * setasyncmap - add bits to asyncmap (what we request peer to escape).
1453 if (!number_option(*argv, &asyncmap, 16))
1455 lcp_wantoptions[0].asyncmap |= asyncmap;
1456 lcp_wantoptions[0].neg_asyncmap = 1;
1462 * setescape - add chars to the set we escape on transmission.
1474 n = strtol(p, &endp, 16);
1476 option_error("escape parameter contains invalid hex number '%s'",
1481 if (n < 0 || 0x20 <= n && n <= 0x3F || n == 0x5E || n > 0xFF) {
1482 option_error("can't escape character 0x%x", n);
1485 xmit_accm[0][n >> 5] |= 1 << (n & 0x1F);
1486 while (*p == ',' || *p == ' ')
1494 * setspeed - Set the speed.
1503 spd = strtol(arg, &ptr, 0);
1504 if (ptr == arg || *ptr != 0 || spd == 0)
1512 * setdevname - Set the device name.
1515 setdevname(cp, quiet)
1519 struct stat statbuf;
1520 char dev[MAXPATHLEN];
1525 if (strncmp("/dev/", cp, 5) != 0) {
1526 strcpy(dev, "/dev/");
1527 strncat(dev, cp, MAXPATHLEN - 5);
1528 dev[MAXPATHLEN-1] = 0;
1533 * Check if there is a device by this name.
1535 if (stat(cp, &statbuf) < 0) {
1536 if (errno == ENOENT || quiet)
1538 option_error("Couldn't stat %s: %m", cp);
1542 (void) strncpy(devnam, cp, MAXPATHLEN);
1543 devnam[MAXPATHLEN-1] = 0;
1544 default_device = FALSE;
1545 devnam_info.priv = privileged_option;
1546 devnam_info.source = option_source;
1553 * setipaddr - Set the IP address
1561 u_int32_t local, remote;
1562 ipcp_options *wo = &ipcp_wantoptions[0];
1565 * IP address pair separated by ":".
1567 if ((colon = strchr(arg, ':')) == NULL)
1571 * If colon first character, then no local addr.
1575 if ((local = inet_addr(arg)) == -1) {
1576 if ((hp = gethostbyname(arg)) == NULL) {
1577 option_error("unknown host: %s", arg);
1580 local = *(u_int32_t *)hp->h_addr;
1583 if (bad_ip_adrs(local)) {
1584 option_error("bad local IP address %s", ip_ntoa(local));
1588 wo->ouraddr = local;
1593 * If colon last character, then no remote addr.
1595 if (*++colon != '\0') {
1596 if ((remote = inet_addr(colon)) == -1) {
1597 if ((hp = gethostbyname(colon)) == NULL) {
1598 option_error("unknown host: %s", colon);
1601 remote = *(u_int32_t *)hp->h_addr;
1602 if (remote_name[0] == 0) {
1603 strncpy(remote_name, colon, MAXNAMELEN);
1604 remote_name[MAXNAMELEN-1] = 0;
1608 if (bad_ip_adrs(remote)) {
1609 option_error("bad remote IP address %s", ip_ntoa(remote));
1613 wo->hisaddr = remote;
1621 * setnoipdflt - disable setipdefault()
1626 disable_defaultip = 1;
1632 * setipcpaccl - accept peer's idea of our address
1637 ipcp_wantoptions[0].accept_local = 1;
1643 * setipcpaccr - accept peer's idea of its address
1648 ipcp_wantoptions[0].accept_remote = 1;
1654 * setnetmask - set the netmask to be used on the interface.
1662 if ((mask = inet_addr(*argv)) == -1 || (netmask & ~mask) != 0) {
1663 option_error("invalid netmask value '%s'", *argv);
1688 lcp_wantoptions[0].asyncmap |= 0x000A0000; /* escape ^S and ^Q */
1689 lcp_wantoptions[0].neg_asyncmap = 1;
1742 if (!privileged_option) {
1743 option_error("using the name option requires root privilege");
1746 strncpy(our_name, argv[0], MAXNAMELEN);
1747 our_name[MAXNAMELEN-1] = 0;
1755 strncpy(user, argv[0], MAXNAMELEN);
1756 user[MAXNAMELEN-1] = 0;
1764 strncpy(remote_name, argv[0], MAXNAMELEN);
1765 remote_name[MAXNAMELEN-1] = 0;
1773 if (privileged_option > auth_req_info.priv) {
1774 auth_req_info.priv = privileged_option;
1775 auth_req_info.source = option_source;
1783 if (auth_required && privileged_option < auth_req_info.priv) {
1784 option_error("cannot override auth option set by %s",
1785 auth_req_info.source);
1795 if (!ipcp_allowoptions[0].default_route) {
1796 option_error("defaultroute option is disabled");
1799 ipcp_wantoptions[0].default_route = 1;
1806 ipcp_allowoptions[0].default_route = 0;
1807 ipcp_wantoptions[0].default_route = 0;
1814 if (!ipcp_allowoptions[0].proxy_arp) {
1815 option_error("proxyarp option is disabled");
1818 ipcp_wantoptions[0].proxy_arp = 1;
1825 ipcp_wantoptions[0].proxy_arp = 0;
1826 ipcp_allowoptions[0].proxy_arp = 0;
1852 * Functions to set the echo interval for modem-less monitors
1856 setlcpechointv(argv)
1859 return int_option(*argv, &lcp_echo_interval);
1863 setlcpechofails(argv)
1866 return int_option(*argv, &lcp_echo_fails);
1870 * Functions to set timeouts, max transmits, etc.
1876 return int_option(*argv, &lcp_fsm[0].timeouttime);
1883 return int_option(*argv, &lcp_fsm[0].maxtermtransmits);
1890 return int_option(*argv, &lcp_fsm[0].maxconfreqtransmits);
1897 return int_option(*argv, &lcp_fsm[0].maxnakloops);
1901 setipcptimeout(argv)
1904 return int_option(*argv, &ipcp_fsm[0].timeouttime);
1911 return int_option(*argv, &ipcp_fsm[0].maxtermtransmits);
1918 return int_option(*argv, &ipcp_fsm[0].maxconfreqtransmits);
1925 return int_option(*argv, &lcp_fsm[0].maxnakloops);
1932 return int_option(*argv, &upap[0].us_timeouttime);
1939 return int_option(*argv, &upap[0].us_reqtimeout);
1946 return int_option(*argv, &upap[0].us_maxtransmits);
1950 setchaptimeout(argv)
1953 return int_option(*argv, &chap[0].timeouttime);
1960 return int_option(*argv, &chap[0].max_transmits);
1967 return int_option(*argv, &chap[0].chal_interval);
1973 ccp_protent.enabled_flag = 0;
1985 abits = rbits = strtol(str, &endp, 0);
1986 if (endp != str && *endp == ',') {
1988 abits = strtol(str, &endp, 0);
1990 if (*endp != 0 || endp == str) {
1991 option_error("invalid parameter '%s' for bsdcomp option", *argv);
1994 if (rbits != 0 && (rbits < BSD_MIN_BITS || rbits > BSD_MAX_BITS)
1995 || abits != 0 && (abits < BSD_MIN_BITS || abits > BSD_MAX_BITS)) {
1996 option_error("bsdcomp option values must be 0 or %d .. %d",
1997 BSD_MIN_BITS, BSD_MAX_BITS);
2001 ccp_wantoptions[0].bsd_compress = 1;
2002 ccp_wantoptions[0].bsd_bits = rbits;
2004 ccp_wantoptions[0].bsd_compress = 0;
2006 ccp_allowoptions[0].bsd_compress = 1;
2007 ccp_allowoptions[0].bsd_bits = abits;
2009 ccp_allowoptions[0].bsd_compress = 0;
2016 ccp_wantoptions[0].bsd_compress = 0;
2017 ccp_allowoptions[0].bsd_compress = 0;
2029 abits = rbits = strtol(str, &endp, 0);
2030 if (endp != str && *endp == ',') {
2032 abits = strtol(str, &endp, 0);
2034 if (*endp != 0 || endp == str) {
2035 option_error("invalid parameter '%s' for deflate option", *argv);
2038 if (rbits != 0 && (rbits < DEFLATE_MIN_SIZE || rbits > DEFLATE_MAX_SIZE)
2039 || abits != 0 && (abits < DEFLATE_MIN_SIZE
2040 || abits > DEFLATE_MAX_SIZE)) {
2041 option_error("deflate option values must be 0 or %d .. %d",
2042 DEFLATE_MIN_SIZE, DEFLATE_MAX_SIZE);
2046 ccp_wantoptions[0].deflate = 1;
2047 ccp_wantoptions[0].deflate_size = rbits;
2049 ccp_wantoptions[0].deflate = 0;
2051 ccp_allowoptions[0].deflate = 1;
2052 ccp_allowoptions[0].deflate_size = abits;
2054 ccp_allowoptions[0].deflate = 0;
2061 ccp_wantoptions[0].deflate = 0;
2062 ccp_allowoptions[0].deflate = 0;
2069 ccp_wantoptions[0].predictor_1 = 1;
2070 ccp_allowoptions[0].predictor_1 = 1;
2077 ccp_wantoptions[0].predictor_1 = 0;
2078 ccp_allowoptions[0].predictor_1 = 0;
2086 ipparam = strdup(*argv);
2087 if (ipparam == NULL)
2088 novm("ipparam string");
2104 return int_option(*argv, &idle_time_limit);
2111 return int_option(*argv, &holdoff);
2115 * setdnsaddr - set the dns address(es)
2124 dns = inet_addr(*argv);
2126 if ((hp = gethostbyname(*argv)) == NULL) {
2127 option_error("invalid address parameter '%s' for ms-dns option",
2131 dns = *(u_int32_t *)hp->h_addr;
2134 if (ipcp_allowoptions[0].dnsaddr[0] == 0) {
2135 ipcp_allowoptions[0].dnsaddr[0] = dns;
2137 ipcp_allowoptions[0].dnsaddr[1] = dns;
2148 ipxcp_wantoptions[0].neg_router = 1;
2149 ipxcp_allowoptions[0].neg_router = 1;
2150 return int_option(*argv, &ipxcp_wantoptions[0].router);
2157 char *dest = ipxcp_wantoptions[0].name;
2162 ipxcp_wantoptions[0].neg_name = 1;
2163 ipxcp_allowoptions[0].neg_name = 1;
2164 memset (dest, '\0', sizeof (ipxcp_wantoptions[0].name));
2169 if (! isalnum (ch) && ch != '_') {
2170 option_error("IPX router name must be alphanumeric or _");
2174 if (count >= sizeof (ipxcp_wantoptions[0].name)) {
2175 option_error("IPX router name is limited to %d characters",
2176 sizeof (ipxcp_wantoptions[0].name) - 1);
2180 dest[count++] = toupper (ch);
2187 setipxcptimeout (argv)
2190 return int_option(*argv, &ipxcp_fsm[0].timeouttime);
2197 return int_option(*argv, &ipxcp_fsm[0].maxtermtransmits);
2204 return int_option(*argv, &ipxcp_fsm[0].maxconfreqtransmits);
2208 setipxcpfails (argv)
2211 return int_option(*argv, &ipxcp_fsm[0].maxnakloops);
2218 ipxcp_wantoptions[0].neg_nn = 1;
2219 return int_option(*argv, &ipxcp_wantoptions[0].our_network);
2225 ipxcp_wantoptions[0].accept_network = 1;
2226 ipxcp_allowoptions[0].accept_network = 1;
2232 ipxcp_wantoptions[0].accept_local = 1;
2233 ipxcp_allowoptions[0].accept_local = 1;
2239 ipxcp_wantoptions[0].accept_remote = 1;
2240 ipxcp_allowoptions[0].accept_remote = 1;
2244 setipxnodevalue(src,dst)
2251 if (!isxdigit (*src))
2254 for (indx = 0; indx < 5; ++indx) {
2256 dst[indx] |= (dst[indx + 1] >> 4) & 0x0F;
2259 item = toupper (*src) - '0';
2263 dst[5] = (dst[5] << 4) | item;
2275 memset (&ipxcp_wantoptions[0].our_node[0], 0, 6);
2276 memset (&ipxcp_wantoptions[0].his_node[0], 0, 6);
2278 end = setipxnodevalue (*argv, &ipxcp_wantoptions[0].our_node[0]);
2280 end = setipxnodevalue (++end, &ipxcp_wantoptions[0].his_node[0]);
2283 ipxcp_wantoptions[0].neg_node = 1;
2287 option_error("invalid parameter '%s' for ipx-node option", *argv);
2294 ipxcp_protent.enabled_flag = 1;
2301 ipxcp_protent.enabled_flag = 0;
2311 #endif /* IPX_CHANGE */