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.34 1996/09/14 05:16:56 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 */
105 struct option_info auth_req_info;
106 struct option_info connector_info;
107 struct option_info disconnector_info;
108 struct option_info welcomer_info;
109 struct option_info devnam_info;
114 static int setdevname __P((char *, int));
115 static int setipaddr __P((char *));
116 static int setdebug __P((void));
117 static int setkdebug __P((char **));
118 static int setpassive __P((void));
119 static int setsilent __P((void));
120 static int noopt __P((void));
121 static int setnovj __P((void));
122 static int setnovjccomp __P((void));
123 static int setvjslots __P((char **));
124 static int reqpap __P((void));
125 static int nopap __P((void));
127 static int setupapfile __P((char **));
129 static int nochap __P((void));
130 static int reqchap __P((void));
131 static int setspeed __P((char *));
132 static int noaccomp __P((void));
133 static int noasyncmap __P((void));
134 static int noip __P((void));
135 static int nomagicnumber __P((void));
136 static int setasyncmap __P((char **));
137 static int setescape __P((char **));
138 static int setmru __P((char **));
139 static int setmtu __P((char **));
140 static int nomru __P((void));
141 static int nopcomp __P((void));
142 static int setconnector __P((char **));
143 static int setdisconnector __P((char **));
144 static int setwelcomer __P((char **));
145 static int setmaxconnect __P((char **));
146 static int setdomain __P((char **));
147 static int setnetmask __P((char **));
148 static int setcrtscts __P((void));
149 static int setnocrtscts __P((void));
150 static int setxonxoff __P((void));
151 static int setnodetach __P((void));
152 static int setmodem __P((void));
153 static int setlocal __P((void));
154 static int setlock __P((void));
155 static int setname __P((char **));
156 static int setuser __P((char **));
157 static int setremote __P((char **));
158 static int setauth __P((void));
159 static int setnoauth __P((void));
160 static int readfile __P((char **));
161 static int callfile __P((char **));
162 static int setdefaultroute __P((void));
163 static int setnodefaultroute __P((void));
164 static int setproxyarp __P((void));
165 static int setnoproxyarp __P((void));
166 static int setpersist __P((void));
167 static int setnopersist __P((void));
168 static int setdologin __P((void));
169 static int setusehostname __P((void));
170 static int setnoipdflt __P((void));
171 static int setlcptimeout __P((char **));
172 static int setlcpterm __P((char **));
173 static int setlcpconf __P((char **));
174 static int setlcpfails __P((char **));
175 static int setipcptimeout __P((char **));
176 static int setipcpterm __P((char **));
177 static int setipcpconf __P((char **));
178 static int setipcpfails __P((char **));
179 static int setpaptimeout __P((char **));
180 static int setpapreqs __P((char **));
181 static int setpapreqtime __P((char **));
182 static int setchaptimeout __P((char **));
183 static int setchapchal __P((char **));
184 static int setchapintv __P((char **));
185 static int setipcpaccl __P((void));
186 static int setipcpaccr __P((void));
187 static int setlcpechointv __P((char **));
188 static int setlcpechofails __P((char **));
189 static int noccp __P((void));
190 static int setbsdcomp __P((char **));
191 static int setnobsdcomp __P((void));
192 static int setdeflate __P((char **));
193 static int setnodeflate __P((void));
194 static int setdemand __P((void));
195 static int setpred1comp __P((void));
196 static int setnopred1comp __P((void));
197 static int setipparam __P((char **));
198 static int setpapcrypt __P((void));
199 static int setidle __P((char **));
200 static int setholdoff __P((char **));
203 static int setipxproto __P((void));
204 static int resetipxproto __P((void));
205 static int setipxanet __P((void));
206 static int setipxalcl __P((void));
207 static int setipxarmt __P((void));
208 static int setipxnetwork __P((char **));
209 static int setipxnode __P((char **));
210 static int setipxrouter __P((char **));
211 static int setipxname __P((char **));
212 static int setipxcptimeout __P((char **));
213 static int setipxcpterm __P((char **));
214 static int setipxcpconf __P((char **));
215 static int setipxcpfails __P((char **));
216 #endif /* IPX_CHANGE */
219 static int setdnsaddr __P((char **));
222 static int number_option __P((char *, u_int32_t *, int));
223 static int int_option __P((char *, int *));
224 static int readable __P((int fd));
234 {"-all", 0, noopt}, /* Don't request/allow any options (useless) */
235 {"noaccomp", 0, noaccomp}, /* Disable Address/Control compression */
236 {"-ac", 0, noaccomp}, /* Disable Address/Control compress */
237 {"default-asyncmap", 0, noasyncmap}, /* Disable asyncmap negoatiation */
238 {"-am", 0, noasyncmap}, /* Disable asyncmap negotiation */
239 {"-as", 1, setasyncmap}, /* set the desired async map */
240 {"-d", 0, setdebug}, /* Increase debugging level */
241 {"nodetach", 0, setnodetach}, /* Don't detach from controlling tty */
242 {"-detach", 0, setnodetach}, /* don't fork */
243 {"noip", 0, noip}, /* Disable IP and IPCP */
244 {"-ip", 0, noip}, /* Disable IP and IPCP */
245 {"nomagic", 0, nomagicnumber}, /* Disable magic number negotiation */
246 {"-mn", 0, nomagicnumber}, /* Disable magic number negotiation */
247 {"default-mru", 0, nomru}, /* Disable MRU negotiation */
248 {"-mru", 0, nomru}, /* Disable mru negotiation */
249 {"-p", 0, setpassive}, /* Set passive mode */
250 {"nopcomp", 0, nopcomp}, /* Disable protocol field compression */
251 {"-pc", 0, nopcomp}, /* Disable protocol field compress */
253 {"+ua", 1, setupapfile}, /* Get PAP user and password from file */
255 {"require-pap", 0, reqpap}, /* Require PAP authentication from peer */
256 {"+pap", 0, reqpap}, /* Require PAP auth from peer */
257 {"refuse-pap", 0, nopap}, /* Don't agree to auth to peer with PAP */
258 {"-pap", 0, nopap}, /* Don't allow UPAP authentication with peer */
259 {"require-chap", 0, reqchap}, /* Require CHAP authentication from peer */
260 {"+chap", 0, reqchap}, /* Require CHAP authentication from peer */
261 {"refuse-chap", 0, nochap}, /* Don't agree to auth to peer with CHAP */
262 {"-chap", 0, nochap}, /* Don't allow CHAP authentication with peer */
263 {"novj", 0, setnovj}, /* Disable VJ compression */
264 {"-vj", 0, setnovj}, /* disable VJ compression */
265 {"novjccomp", 0, setnovjccomp}, /* disable VJ connection-ID compression */
266 {"-vjccomp", 0, setnovjccomp}, /* disable VJ connection-ID compression */
267 {"vj-max-slots", 1, setvjslots}, /* Set maximum VJ header slots */
268 {"asyncmap", 1, setasyncmap}, /* set the desired async map */
269 {"escape", 1, setescape}, /* set chars to escape on transmission */
270 {"connect", 1, setconnector}, /* A program to set up a connection */
271 {"disconnect", 1, setdisconnector}, /* program to disconnect serial dev. */
272 {"welcome", 1, setwelcomer},/* Script to welcome client */
273 {"maxconnect", 1, setmaxconnect}, /* specify a maximum connect time */
274 {"crtscts", 0, setcrtscts}, /* set h/w flow control */
275 {"nocrtscts", 0, setnocrtscts}, /* clear h/w flow control */
276 {"-crtscts", 0, setnocrtscts}, /* clear h/w flow control */
277 {"xonxoff", 0, setxonxoff}, /* set s/w flow control */
278 {"debug", 0, setdebug}, /* Increase debugging level */
279 {"kdebug", 1, setkdebug}, /* Enable kernel-level debugging */
280 {"domain", 1, setdomain}, /* Add given domain name to hostname*/
281 {"mru", 1, setmru}, /* Set MRU value for negotiation */
282 {"mtu", 1, setmtu}, /* Set our MTU */
283 {"netmask", 1, setnetmask}, /* set netmask */
284 {"passive", 0, setpassive}, /* Set passive mode */
285 {"silent", 0, setsilent}, /* Set silent mode */
286 {"modem", 0, setmodem}, /* Use modem control lines */
287 {"local", 0, setlocal}, /* Don't use modem control lines */
288 {"lock", 0, setlock}, /* Lock serial device (with lock file) */
289 {"name", 1, setname}, /* Set local name for authentication */
290 {"user", 1, setuser}, /* Set name for auth with peer */
291 {"usehostname", 0, setusehostname}, /* Must use hostname for auth. */
292 {"remotename", 1, setremote}, /* Set remote name for authentication */
293 {"auth", 0, setauth}, /* Require authentication from peer */
294 {"noauth", 0, setnoauth}, /* Don't require peer to authenticate */
295 {"file", 1, readfile}, /* Take options from a file */
296 {"call", 1, callfile}, /* Take options from a privileged file */
297 {"defaultroute", 0, setdefaultroute}, /* Add default route */
298 {"nodefaultroute", 0, setnodefaultroute}, /* disable defaultroute option */
299 {"-defaultroute", 0, setnodefaultroute}, /* disable defaultroute option */
300 {"proxyarp", 0, setproxyarp}, /* Add proxy ARP entry */
301 {"noproxyarp", 0, setnoproxyarp}, /* disable proxyarp option */
302 {"-proxyarp", 0, setnoproxyarp}, /* disable proxyarp option */
303 {"persist", 0, setpersist}, /* Keep on reopening connection after close */
304 {"nopersist", 0, setnopersist}, /* Turn off persist option */
305 {"demand", 0, setdemand}, /* Dial on demand */
306 {"login", 0, setdologin}, /* Use system password database for UPAP */
307 {"noipdefault", 0, setnoipdflt}, /* Don't use name for default IP adrs */
308 {"lcp-echo-failure", 1, setlcpechofails}, /* consecutive echo failures */
309 {"lcp-echo-interval", 1, setlcpechointv}, /* time for lcp echo events */
310 {"lcp-restart", 1, setlcptimeout}, /* Set timeout for LCP */
311 {"lcp-max-terminate", 1, setlcpterm}, /* Set max #xmits for term-reqs */
312 {"lcp-max-configure", 1, setlcpconf}, /* Set max #xmits for conf-reqs */
313 {"lcp-max-failure", 1, setlcpfails}, /* Set max #conf-naks for LCP */
314 {"ipcp-restart", 1, setipcptimeout}, /* Set timeout for IPCP */
315 {"ipcp-max-terminate", 1, setipcpterm}, /* Set max #xmits for term-reqs */
316 {"ipcp-max-configure", 1, setipcpconf}, /* Set max #xmits for conf-reqs */
317 {"ipcp-max-failure", 1, setipcpfails}, /* Set max #conf-naks for IPCP */
318 {"pap-restart", 1, setpaptimeout}, /* Set retransmit timeout for PAP */
319 {"pap-max-authreq", 1, setpapreqs}, /* Set max #xmits for auth-reqs */
320 {"pap-timeout", 1, setpapreqtime}, /* Set time limit for peer PAP auth. */
321 {"chap-restart", 1, setchaptimeout}, /* Set timeout for CHAP */
322 {"chap-max-challenge", 1, setchapchal}, /* Set max #xmits for challenge */
323 {"chap-interval", 1, setchapintv}, /* Set interval for rechallenge */
324 {"ipcp-accept-local", 0, setipcpaccl}, /* Accept peer's address for us */
325 {"ipcp-accept-remote", 0, setipcpaccr}, /* Accept peer's address for it */
326 {"noccp", 0, noccp}, /* Disable CCP negotiation */
327 {"-ccp", 0, noccp}, /* Disable CCP negotiation */
328 {"bsdcomp", 1, setbsdcomp}, /* request BSD-Compress */
329 {"nobsdcomp", 0, setnobsdcomp}, /* don't allow BSD-Compress */
330 {"-bsdcomp", 0, setnobsdcomp}, /* don't allow BSD-Compress */
331 {"deflate", 1, setdeflate}, /* request Deflate compression */
332 {"nodeflate", 0, setnodeflate}, /* don't allow Deflate compression */
333 {"-deflate", 0, setnodeflate}, /* don't allow Deflate compression */
334 {"predictor1", 0, setpred1comp}, /* request Predictor-1 */
335 {"nopredictor1", 0, setnopred1comp},/* don't allow Predictor-1 */
336 {"-predictor1", 0, setnopred1comp}, /* don't allow Predictor-1 */
337 {"ipparam", 1, setipparam}, /* set ip script parameter */
338 {"papcrypt", 0, setpapcrypt}, /* PAP passwords encrypted */
339 {"idle", 1, setidle}, /* idle time limit (seconds) */
340 {"holdoff", 1, setholdoff}, /* set holdoff time (seconds) */
343 {"ipx-network", 1, setipxnetwork}, /* IPX network number */
344 {"ipxcp-accept-network", 0, setipxanet}, /* Accept peer netowrk */
345 {"ipx-node", 1, setipxnode}, /* IPX node number */
346 {"ipxcp-accept-local", 0, setipxalcl}, /* Accept our address */
347 {"ipxcp-accept-remote", 0, setipxarmt}, /* Accept peer's address */
348 {"ipx-routing", 1, setipxrouter}, /* IPX routing proto number */
349 {"ipx-router-name", 1, setipxname}, /* IPX router name */
350 {"ipxcp-restart", 1, setipxcptimeout}, /* Set timeout for IPXCP */
351 {"ipxcp-max-terminate", 1, setipxcpterm}, /* max #xmits for term-reqs */
352 {"ipxcp-max-configure", 1, setipxcpconf}, /* max #xmits for conf-reqs */
353 {"ipxcp-max-failure", 1, setipxcpfails}, /* max #conf-naks for IPXCP */
355 {"ipx-compression", 1, setipxcompression}, /* IPX compression number */
357 {"ipx", 0, setipxproto}, /* Enable IPXCP (and IPX) */
358 {"noipx", 0, resetipxproto}, /* Disable IPXCP (and IPX) */
359 {"+ipx", 0, setipxproto}, /* Enable IPXCP (and IPX) */
360 {"-ipx", 0, resetipxproto}, /* Disable IPXCP (and IPX) */
361 #endif /* IPX_CHANGE */
364 {"ms-dns", 1, setdnsaddr}, /* DNS address(es) for the peer's use */
371 #ifndef IMPLEMENTATION
372 #define IMPLEMENTATION ""
375 static char *usage_string = "\
376 pppd version %s patch level %d%s\n\
377 Usage: %s [ options ], where options are:\n\
378 <device> Communicate over the named device\n\
379 <speed> Set the baud rate to <speed>\n\
380 <loc>:<rem> Set the local and/or remote interface IP\n\
381 addresses. Either one may be omitted.\n\
382 asyncmap <n> Set the desired async map to hex <n>\n\
383 auth Require authentication from peer\n\
384 connect <p> Invoke shell command <p> to set up the serial line\n\
385 crtscts Use hardware RTS/CTS flow control\n\
386 defaultroute Add default route through interface\n\
387 file <f> Take options from file <f>\n\
388 modem Use modem control lines\n\
389 mru <n> Set MRU value to <n> for negotiation\n\
390 netmask <n> Set interface netmask to <n>\n\
391 See pppd(8) for more options.\n\
394 static char *current_option; /* the name of the option being parsed */
395 static int privileged_option; /* set iff the current option came from root */
396 static char *option_source; /* string saying where the option came from */
399 * parse_args - parse a string of arguments from the command line.
402 parse_args(argc, argv)
410 privileged_option = privileged;
411 option_source = "command line";
417 * First see if it's a command.
419 for (cmdp = cmds; cmdp->cmd_name; cmdp++)
420 if (!strcmp(arg, cmdp->cmd_name))
423 if (cmdp->cmd_name != NULL) {
424 if (argc < cmdp->num_args) {
425 option_error("too few parameters for option %s", arg);
428 current_option = arg;
429 if (!(*cmdp->cmd_func)(argv))
431 argc -= cmdp->num_args;
432 argv += cmdp->num_args;
436 * Maybe a tty name, speed or IP address?
438 if ((ret = setdevname(arg, 0)) == 0
439 && (ret = setspeed(arg)) == 0
440 && (ret = setipaddr(arg)) == 0) {
441 option_error("unrecognized option '%s'", arg);
445 if (ret < 0) /* error */
453 * scan_args - scan the command line arguments to get the tty name,
457 scan_args(argc, argv)
468 /* Skip options and their arguments */
469 for (cmdp = cmds; cmdp->cmd_name; cmdp++)
470 if (!strcmp(arg, cmdp->cmd_name))
473 if (cmdp->cmd_name != NULL) {
474 argc -= cmdp->num_args;
475 argv += cmdp->num_args;
479 /* Check if it's a tty name and copy it if so */
480 (void) setdevname(arg, 1);
485 * usage - print out a message telling how to use the program.
490 if (phase == PHASE_INITIALIZE)
491 fprintf(stderr, usage_string, VERSION, PATCHLEVEL, IMPLEMENTATION,
496 * options_from_file - Read a string of options from a file,
497 * and interpret them.
500 options_from_file(filename, must_exist, check_prot, priv)
511 char args[MAXARGS][MAXWORDLEN];
512 char cmd[MAXWORDLEN];
514 if ((f = fopen(filename, "r")) == NULL) {
515 if (!must_exist && errno == ENOENT)
517 option_error("Can't open options file %s: %m", filename);
520 if (check_prot && !readable(fileno(f))) {
521 option_error("Can't open options file %s: access denied", filename);
526 oldpriv = privileged_option;
527 privileged_option = priv;
529 while (getword(f, cmd, &newline, filename)) {
531 * First see if it's a command.
533 for (cmdp = cmds; cmdp->cmd_name; cmdp++)
534 if (!strcmp(cmd, cmdp->cmd_name))
537 if (cmdp->cmd_name != NULL) {
538 for (i = 0; i < cmdp->num_args; ++i) {
539 if (!getword(f, args[i], &newline, filename)) {
541 "In file %s: too few parameters for option '%s'",
547 current_option = cmd;
548 if (!(*cmdp->cmd_func)(argv))
553 * Maybe a tty name, speed or IP address?
555 if ((i = setdevname(cmd, 0)) == 0
556 && (i = setspeed(cmd)) == 0
557 && (i = setipaddr(cmd)) == 0) {
558 option_error("In file %s: unrecognized option '%s'",
562 if (i < 0) /* error */
570 privileged_option = oldpriv;
575 * options_from_user - See if the use has a ~/.ppprc file,
576 * and if so, interpret options from it.
581 char *user, *path, *file;
585 pw = getpwuid(getuid());
586 if (pw == NULL || (user = pw->pw_dir) == NULL || user[0] == 0)
588 file = _PATH_USEROPT;
589 path = malloc(strlen(user) + strlen(file) + 2);
591 novm("init file name");
595 ret = options_from_file(path, 0, 1, privileged);
601 * options_for_tty - See if an options file exists for the serial
602 * device, and if so, interpret options from it.
607 char *dev, *path, *p;
611 if (strncmp(dev, "/dev/", 5) == 0)
613 if (strcmp(dev, "tty") == 0)
614 return 1; /* don't look for /etc/ppp/options.tty */
615 path = malloc(strlen(_PATH_TTYOPT) + strlen(dev) + 1);
617 novm("tty init file name");
618 strcpy(path, _PATH_TTYOPT);
619 /* Turn slashes into dots, for Solaris case (e.g. /dev/term/a) */
620 for (p = path + strlen(path); *dev != 0; ++dev)
621 *p++ = (*dev == '/'? '.': *dev);
623 ret = options_from_file(path, 0, 0, 1);
629 * option_error - print a message about an error in an option.
630 * The message is logged, and also sent to
631 * stderr if phase == PHASE_INITIALIZE.
634 option_error __V((char *fmt, ...))
645 fmt = va_arg(args, char *);
647 vfmtmsg(buf, sizeof(buf), fmt, args);
649 if (phase == PHASE_INITIALIZE)
650 fprintf(stderr, "%s: %s\n", progname, buf);
651 syslog(LOG_ERR, "%s", buf);
655 * readable - check if a file is readable by the real user.
664 GIDSET_TYPE groups[NGROUPS_MAX];
669 if (fstat(fd, &sbuf) != 0)
671 if (sbuf.st_uid == uid)
672 return sbuf.st_mode & S_IRUSR;
673 if (sbuf.st_gid == getgid())
674 return sbuf.st_mode & S_IRGRP;
675 ngroups = getgroups(NGROUPS_MAX, groups);
676 for (i = 0; i < ngroups; ++i)
677 if (sbuf.st_gid == groups[i])
678 return sbuf.st_mode & S_IRGRP;
679 return sbuf.st_mode & S_IROTH;
683 * Read a word from a file.
684 * Words are delimited by white-space or by quotes (" or ').
685 * Quotes, white-space and \ may be escaped with \.
686 * \<newline> is ignored.
689 getword(f, word, newlinep, filename)
697 int value, digit, got, n;
699 #define isoctal(c) ((c) >= '0' && (c) < '8')
707 * First skip white-space and comments.
715 * A newline means the end of a comment; backslash-newline
716 * is ignored. Note that we cannot have escape && comment.
728 * Ignore characters other than newline in a comment.
734 * If this character is escaped, we have a word start.
740 * If this is the escape character, look at the next character.
748 * If this is the start of a comment, ignore the rest of the line.
756 * A non-whitespace character is the start of a word.
763 * Save the delimiter for quoted strings.
765 if (!escape && (c == '"' || c == '\'')) {
772 * Process characters until the end of the word.
777 * This character is escaped: backslash-newline is ignored,
778 * various other characters indicate particular values
779 * as for C backslash-escapes.
814 * \ddd octal sequence
817 for (n = 0; n < 3 && isoctal(c); ++n) {
818 value = (value << 3) + (c & 07);
827 * \x<hex_string> sequence
831 for (n = 0; n < 2 && isxdigit(c); ++n) {
832 digit = toupper(c) - '0';
834 digit += '0' + 10 - 'A';
835 value = (value << 4) + digit;
843 * Otherwise the character stands for itself.
850 * Store the resulting character for the escape sequence.
852 if (len < MAXWORDLEN-1)
863 * Not escaped: see if we've reached the end of the word.
869 if (isspace(c) || c == '#') {
876 * Backslash starts an escape sequence.
885 * An ordinary character: store it in the word and get another.
887 if (len < MAXWORDLEN-1)
895 * End of the word: check for errors.
901 option_error("Error reading %s: %m", filename);
905 * If len is zero, then we didn't find a word before the
913 * Warn if the word was too long, and append a terminating null.
915 if (len >= MAXWORDLEN) {
916 option_error("warning: word in file %s too long (%.20s...)",
918 len = MAXWORDLEN - 1;
929 * number_option - parse an unsigned numeric parameter for an option.
932 number_option(str, valp, base)
939 *valp = strtoul(str, &ptr, base);
941 option_error("invalid numeric parameter '%s' for %s option",
942 str, current_option);
950 * int_option - like number_option, but valp is int *,
951 * the base is assumed to be 0, and *valp is not changed
952 * if there is an error.
955 int_option(str, valp)
961 if (!number_option(str, &v, 0))
969 * The following procedures parse options.
973 * readfile - take commands from a file.
979 return options_from_file(*argv, 1, 1, privileged_option);
983 * callfile - take commands from /etc/ppp/peers/<name>.
984 * Name may not contain /../, start with / or ../, or end in /..
990 char *fname, *arg, *p;
995 if (arg[0] == '/' || arg[0] == 0)
998 for (p = arg; *p != 0; ) {
999 if (p[0] == '.' && p[1] == '.' && (p[2] == '/' || p[2] == 0)) {
1003 while (*p != '/' && *p != 0)
1010 option_error("call option value may not contain .. or start with /");
1014 l = strlen(arg) + strlen(_PATH_PEERFILES) + 1;
1015 if ((fname = (char *) malloc(l)) == NULL)
1016 novm("call file name");
1017 strcpy(fname, _PATH_PEERFILES);
1020 ok = options_from_file(fname, 1, 1, 1);
1028 * setdebug - Set debug (command line argument).
1038 * setkdebug - Set kernel debugging level.
1044 return int_option(*argv, &kdebugflag);
1048 * noopt - Disable all options.
1053 BZERO((char *) &lcp_wantoptions[0], sizeof (struct lcp_options));
1054 BZERO((char *) &lcp_allowoptions[0], sizeof (struct lcp_options));
1055 BZERO((char *) &ipcp_wantoptions[0], sizeof (struct ipcp_options));
1056 BZERO((char *) &ipcp_allowoptions[0], sizeof (struct ipcp_options));
1059 BZERO((char *) &ipxcp_wantoptions[0], sizeof (struct ipxcp_options));
1060 BZERO((char *) &ipxcp_allowoptions[0], sizeof (struct ipxcp_options));
1061 #endif /* IPX_CHANGE */
1067 * noaccomp - Disable Address/Control field compression negotiation.
1072 lcp_wantoptions[0].neg_accompression = 0;
1073 lcp_allowoptions[0].neg_accompression = 0;
1079 * noasyncmap - Disable async map negotiation.
1084 lcp_wantoptions[0].neg_asyncmap = 0;
1085 lcp_allowoptions[0].neg_asyncmap = 0;
1091 * noip - Disable IP and IPCP.
1096 ipcp_protent.enabled_flag = 0;
1102 * nomagicnumber - Disable magic number negotiation.
1107 lcp_wantoptions[0].neg_magicnumber = 0;
1108 lcp_allowoptions[0].neg_magicnumber = 0;
1114 * nomru - Disable mru negotiation.
1119 lcp_wantoptions[0].neg_mru = 0;
1120 lcp_allowoptions[0].neg_mru = 0;
1126 * setmru - Set MRU for negotiation.
1134 if (!number_option(*argv, &mru, 0))
1136 lcp_wantoptions[0].mru = mru;
1137 lcp_wantoptions[0].neg_mru = 1;
1143 * setmru - Set the largest MTU we'll use.
1151 if (!number_option(*argv, &mtu, 0))
1153 if (mtu < MINMRU || mtu > MAXMRU) {
1154 option_error("mtu option value of %u is too %s", mtu,
1155 (mtu < MINMRU? "small": "large"));
1158 lcp_allowoptions[0].mru = mtu;
1164 * nopcomp - Disable Protocol field compression negotiation.
1169 lcp_wantoptions[0].neg_pcompression = 0;
1170 lcp_allowoptions[0].neg_pcompression = 0;
1176 * setpassive - Set passive mode (don't give up if we time out sending
1177 * LCP configure-requests).
1182 lcp_wantoptions[0].passive = 1;
1188 * setsilent - Set silent mode (don't start sending LCP configure-requests
1189 * until we get one from the peer).
1194 lcp_wantoptions[0].silent = 1;
1200 * nopap - Disable PAP authentication with peer.
1211 * reqpap - Require PAP authentication from peer.
1216 lcp_wantoptions[0].neg_upap = 1;
1223 * setupapfile - specifies UPAP info for authenticating with peer.
1232 lcp_allowoptions[0].neg_upap = 1;
1234 /* open user info file */
1235 if ((ufile = fopen(*argv, "r")) == NULL) {
1236 option_error("unable to open user login data file %s", *argv);
1239 if (!readable(fileno(ufile))) {
1240 option_error("%s: access denied", *argv);
1243 check_access(ufile, *argv);
1246 if (fgets(user, MAXNAMELEN - 1, ufile) == NULL
1247 || fgets(passwd, MAXSECRETLEN - 1, ufile) == NULL){
1248 option_error("unable to read user login data file %s", *argv);
1253 /* get rid of newlines */
1255 if (l > 0 && user[l-1] == '\n')
1258 if (l > 0 && passwd[l-1] == '\n')
1266 * nochap - Disable CHAP authentication with peer.
1277 * reqchap - Require CHAP authentication from peer.
1282 lcp_wantoptions[0].neg_chap = 1;
1289 * setnovj - disable vj compression
1294 ipcp_wantoptions[0].neg_vj = 0;
1295 ipcp_allowoptions[0].neg_vj = 0;
1301 * setnovjccomp - disable VJ connection-ID compression
1306 ipcp_wantoptions[0].cflag = 0;
1307 ipcp_allowoptions[0].cflag = 0;
1313 * setvjslots - set maximum number of connection slots for VJ compression
1321 if (!int_option(*argv, &value))
1323 if (value < 2 || value > 16) {
1324 option_error("vj-max-slots value must be between 2 and 16");
1327 ipcp_wantoptions [0].maxslotindex =
1328 ipcp_allowoptions[0].maxslotindex = value - 1;
1334 * setconnector - Set a program to connect to a serial line
1340 connector = strdup(*argv);
1341 if (connector == NULL)
1342 novm("connect script");
1343 connector_info.priv = privileged_option;
1344 connector_info.source = option_source;
1350 * setdisconnector - Set a program to disconnect from the serial line
1353 setdisconnector(argv)
1356 disconnector = strdup(*argv);
1357 if (disconnector == NULL)
1358 novm("disconnect script");
1359 disconnector_info.priv = privileged_option;
1360 disconnector_info.source = option_source;
1366 * setwelcomer - Set a program to welcome a client after connection
1372 welcomer = strdup(*argv);
1373 if (welcomer == NULL)
1374 novm("welcome script");
1375 welcomer_info.priv = privileged_option;
1376 welcomer_info.source = option_source;
1382 * setmaxconnect - Set the maximum connect time
1390 if (!int_option(*argv, &value))
1393 option_error("maxconnect time must be positive");
1396 if (maxconnect > 0 && (value == 0 || value > maxconnect)) {
1397 option_error("maxconnect time cannot be increased");
1405 * setdomain - Set domain name to append to hostname
1411 if (!privileged_option) {
1412 option_error("using the domain option requires root privilege");
1415 gethostname(hostname, MAXNAMELEN);
1418 strncat(hostname, ".", MAXNAMELEN - strlen(hostname));
1419 strncat(hostname, *argv, MAXNAMELEN - strlen(hostname));
1421 hostname[MAXNAMELEN-1] = 0;
1427 * setasyncmap - add bits to asyncmap (what we request peer to escape).
1435 if (!number_option(*argv, &asyncmap, 16))
1437 lcp_wantoptions[0].asyncmap |= asyncmap;
1438 lcp_wantoptions[0].neg_asyncmap = 1;
1444 * setescape - add chars to the set we escape on transmission.
1456 n = strtol(p, &endp, 16);
1458 option_error("escape parameter contains invalid hex number '%s'",
1463 if (n < 0 || 0x20 <= n && n <= 0x3F || n == 0x5E || n > 0xFF) {
1464 option_error("can't escape character 0x%x", n);
1467 xmit_accm[0][n >> 5] |= 1 << (n & 0x1F);
1468 while (*p == ',' || *p == ' ')
1476 * setspeed - Set the speed.
1485 spd = strtol(arg, &ptr, 0);
1486 if (ptr == arg || *ptr != 0 || spd == 0)
1494 * setdevname - Set the device name.
1497 setdevname(cp, quiet)
1501 struct stat statbuf;
1502 char dev[MAXPATHLEN];
1507 if (strncmp("/dev/", cp, 5) != 0) {
1508 strcpy(dev, "/dev/");
1509 strncat(dev, cp, MAXPATHLEN - 5);
1510 dev[MAXPATHLEN-1] = 0;
1515 * Check if there is a device by this name.
1517 if (stat(cp, &statbuf) < 0) {
1518 if (errno == ENOENT || quiet)
1520 option_error("Couldn't stat %s: %m", cp);
1524 (void) strncpy(devnam, cp, MAXPATHLEN);
1525 devnam[MAXPATHLEN-1] = 0;
1526 default_device = FALSE;
1527 devnam_info.priv = privileged_option;
1528 devnam_info.source = option_source;
1535 * setipaddr - Set the IP address
1543 u_int32_t local, remote;
1544 ipcp_options *wo = &ipcp_wantoptions[0];
1547 * IP address pair separated by ":".
1549 if ((colon = strchr(arg, ':')) == NULL)
1553 * If colon first character, then no local addr.
1557 if ((local = inet_addr(arg)) == -1) {
1558 if ((hp = gethostbyname(arg)) == NULL) {
1559 option_error("unknown host: %s", arg);
1562 local = *(u_int32_t *)hp->h_addr;
1565 if (bad_ip_adrs(local)) {
1566 option_error("bad local IP address %s", ip_ntoa(local));
1570 wo->ouraddr = local;
1575 * If colon last character, then no remote addr.
1577 if (*++colon != '\0') {
1578 if ((remote = inet_addr(colon)) == -1) {
1579 if ((hp = gethostbyname(colon)) == NULL) {
1580 option_error("unknown host: %s", colon);
1583 remote = *(u_int32_t *)hp->h_addr;
1584 if (remote_name[0] == 0) {
1585 strncpy(remote_name, colon, MAXNAMELEN);
1586 remote_name[MAXNAMELEN-1] = 0;
1590 if (bad_ip_adrs(remote)) {
1591 option_error("bad remote IP address %s", ip_ntoa(remote));
1595 wo->hisaddr = remote;
1603 * setnoipdflt - disable setipdefault()
1608 disable_defaultip = 1;
1614 * setipcpaccl - accept peer's idea of our address
1619 ipcp_wantoptions[0].accept_local = 1;
1625 * setipcpaccr - accept peer's idea of its address
1630 ipcp_wantoptions[0].accept_remote = 1;
1636 * setnetmask - set the netmask to be used on the interface.
1644 if ((mask = inet_addr(*argv)) == -1 || (netmask & ~mask) != 0) {
1645 option_error("invalid netmask value '%s'", *argv);
1670 lcp_wantoptions[0].asyncmap |= 0x000A0000; /* escape ^S and ^Q */
1671 lcp_wantoptions[0].neg_asyncmap = 1;
1724 if (!privileged_option) {
1725 option_error("using the name option requires root privilege");
1728 if (our_name[0] == 0) {
1729 strncpy(our_name, argv[0], MAXNAMELEN);
1730 our_name[MAXNAMELEN-1] = 0;
1739 strncpy(user, argv[0], MAXNAMELEN);
1740 user[MAXNAMELEN-1] = 0;
1748 strncpy(remote_name, argv[0], MAXNAMELEN);
1749 remote_name[MAXNAMELEN-1] = 0;
1757 if (privileged_option > auth_req_info.priv) {
1758 auth_req_info.priv = privileged_option;
1759 auth_req_info.source = option_source;
1767 if (auth_required && privileged_option < auth_req_info.priv) {
1768 option_error("cannot override auth option set by %s",
1769 auth_req_info.source);
1779 if (!ipcp_allowoptions[0].default_route) {
1780 option_error("defaultroute option is disabled");
1783 ipcp_wantoptions[0].default_route = 1;
1790 ipcp_allowoptions[0].default_route = 0;
1791 ipcp_wantoptions[0].default_route = 0;
1798 if (!ipcp_allowoptions[0].proxy_arp) {
1799 option_error("proxyarp option is disabled");
1802 ipcp_wantoptions[0].proxy_arp = 1;
1809 ipcp_wantoptions[0].proxy_arp = 0;
1810 ipcp_allowoptions[0].proxy_arp = 0;
1836 * Functions to set the echo interval for modem-less monitors
1840 setlcpechointv(argv)
1843 return int_option(*argv, &lcp_echo_interval);
1847 setlcpechofails(argv)
1850 return int_option(*argv, &lcp_echo_fails);
1854 * Functions to set timeouts, max transmits, etc.
1860 return int_option(*argv, &lcp_fsm[0].timeouttime);
1867 return int_option(*argv, &lcp_fsm[0].maxtermtransmits);
1874 return int_option(*argv, &lcp_fsm[0].maxconfreqtransmits);
1881 return int_option(*argv, &lcp_fsm[0].maxnakloops);
1885 setipcptimeout(argv)
1888 return int_option(*argv, &ipcp_fsm[0].timeouttime);
1895 return int_option(*argv, &ipcp_fsm[0].maxtermtransmits);
1902 return int_option(*argv, &ipcp_fsm[0].maxconfreqtransmits);
1909 return int_option(*argv, &lcp_fsm[0].maxnakloops);
1916 return int_option(*argv, &upap[0].us_timeouttime);
1923 return int_option(*argv, &upap[0].us_reqtimeout);
1930 return int_option(*argv, &upap[0].us_maxtransmits);
1934 setchaptimeout(argv)
1937 return int_option(*argv, &chap[0].timeouttime);
1944 return int_option(*argv, &chap[0].max_transmits);
1951 return int_option(*argv, &chap[0].chal_interval);
1957 ccp_protent.enabled_flag = 0;
1969 abits = rbits = strtol(str, &endp, 0);
1970 if (endp != str && *endp == ',') {
1972 abits = strtol(str, &endp, 0);
1974 if (*endp != 0 || endp == str) {
1975 option_error("invalid parameter '%s' for bsdcomp option", *argv);
1978 if (rbits != 0 && (rbits < BSD_MIN_BITS || rbits > BSD_MAX_BITS)
1979 || abits != 0 && (abits < BSD_MIN_BITS || abits > BSD_MAX_BITS)) {
1980 option_error("bsdcomp option values must be 0 or %d .. %d",
1981 BSD_MIN_BITS, BSD_MAX_BITS);
1985 ccp_wantoptions[0].bsd_compress = 1;
1986 ccp_wantoptions[0].bsd_bits = rbits;
1988 ccp_wantoptions[0].bsd_compress = 0;
1990 ccp_allowoptions[0].bsd_compress = 1;
1991 ccp_allowoptions[0].bsd_bits = abits;
1993 ccp_allowoptions[0].bsd_compress = 0;
2000 ccp_wantoptions[0].bsd_compress = 0;
2001 ccp_allowoptions[0].bsd_compress = 0;
2013 abits = rbits = strtol(str, &endp, 0);
2014 if (endp != str && *endp == ',') {
2016 abits = strtol(str, &endp, 0);
2018 if (*endp != 0 || endp == str) {
2019 option_error("invalid parameter '%s' for deflate option", *argv);
2022 if (rbits != 0 && (rbits < DEFLATE_MIN_SIZE || rbits > DEFLATE_MAX_SIZE)
2023 || abits != 0 && (abits < DEFLATE_MIN_SIZE
2024 || abits > DEFLATE_MAX_SIZE)) {
2025 option_error("deflate option values must be 0 or %d .. %d",
2026 DEFLATE_MIN_SIZE, DEFLATE_MAX_SIZE);
2030 ccp_wantoptions[0].deflate = 1;
2031 ccp_wantoptions[0].deflate_size = rbits;
2033 ccp_wantoptions[0].deflate = 0;
2035 ccp_allowoptions[0].deflate = 1;
2036 ccp_allowoptions[0].deflate_size = abits;
2038 ccp_allowoptions[0].deflate = 0;
2045 ccp_wantoptions[0].deflate = 0;
2046 ccp_allowoptions[0].deflate = 0;
2053 ccp_wantoptions[0].predictor_1 = 1;
2054 ccp_allowoptions[0].predictor_1 = 1;
2061 ccp_wantoptions[0].predictor_1 = 0;
2062 ccp_allowoptions[0].predictor_1 = 0;
2070 ipparam = strdup(*argv);
2071 if (ipparam == NULL)
2072 novm("ipparam string");
2088 return int_option(*argv, &idle_time_limit);
2095 return int_option(*argv, &holdoff);
2103 ipxcp_wantoptions[0].neg_router = 1;
2104 ipxcp_allowoptions[0].neg_router = 1;
2105 return int_option(*argv, &ipxcp_wantoptions[0].router);
2112 char *dest = ipxcp_wantoptions[0].name;
2117 ipxcp_wantoptions[0].neg_name = 1;
2118 ipxcp_allowoptions[0].neg_name = 1;
2119 memset (dest, '\0', sizeof (ipxcp_wantoptions[0].name));
2124 if (! isalnum (ch) && ch != '_') {
2125 option_error("IPX router name must be alphanumeric or _");
2129 if (count >= sizeof (ipxcp_wantoptions[0].name)) {
2130 option_error("IPX router name is limited to %d characters",
2131 sizeof (ipxcp_wantoptions[0].name) - 1);
2135 dest[count++] = toupper (ch);
2142 setipxcptimeout (argv)
2145 return int_option(*argv, &ipxcp_fsm[0].timeouttime);
2152 return int_option(*argv, &ipxcp_fsm[0].maxtermtransmits);
2159 return int_option(*argv, &ipxcp_fsm[0].maxconfreqtransmits);
2163 setipxcpfails (argv)
2166 return int_option(*argv, &ipxcp_fsm[0].maxnakloops);
2173 ipxcp_wantoptions[0].neg_nn = 1;
2174 return int_option(*argv, &ipxcp_wantoptions[0].our_network);
2180 ipxcp_wantoptions[0].accept_network = 1;
2181 ipxcp_allowoptions[0].accept_network = 1;
2187 ipxcp_wantoptions[0].accept_local = 1;
2188 ipxcp_allowoptions[0].accept_local = 1;
2194 ipxcp_wantoptions[0].accept_remote = 1;
2195 ipxcp_allowoptions[0].accept_remote = 1;
2199 setipxnodevalue(src,dst)
2206 if (!isxdigit (*src))
2209 for (indx = 0; indx < 5; ++indx) {
2211 dst[indx] |= (dst[indx + 1] >> 4) & 0x0F;
2214 item = toupper (*src) - '0';
2218 dst[5] = (dst[5] << 4) | item;
2230 memset (&ipxcp_wantoptions[0].our_node[0], 0, 6);
2231 memset (&ipxcp_wantoptions[0].his_node[0], 0, 6);
2233 end = setipxnodevalue (*argv, &ipxcp_wantoptions[0].our_node[0]);
2235 end = setipxnodevalue (++end, &ipxcp_wantoptions[0].his_node[0]);
2238 ipxcp_wantoptions[0].neg_node = 1;
2242 option_error("invalid parameter '%s' for ipx-node option", *argv);
2249 ipxcp_protent.enabled_flag = 1;
2256 ipxcp_protent.enabled_flag = 0;
2259 #endif /* IPX_CHANGE */
2263 * setdnsaddr - set the dns address(es)
2273 dns = inet_addr(*argv);
2275 if ((hp = gethostbyname(*argv)) == NULL) {
2276 option_error("invalid address parameter '%s' for ms-dns option",
2280 dns = *(u_int32_t *)hp->h_addr;
2283 if (ipcp_allowoptions[0].dnsaddr[0] == 0) {
2284 ipcp_allowoptions[0].dnsaddr[0] = dns;
2286 ipcp_allowoptions[0].dnsaddr[1] = dns;
2291 #endif /* USE_MS_DNS */