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.30 1996/04/04 04:00:24 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"
49 #include "bpf_compile.h"
53 #endif /* IPX_CHANGE */
55 #include <net/ppp-comp.h>
60 #if defined(ultrix) || defined(NeXT)
61 char *strdup __P((char *));
65 #define GIDSET_TYPE gid_t
69 * Option variables and default values.
71 int debug = 0; /* Debug flag */
72 int kdebugflag = 0; /* Tell kernel to print debug messages */
73 int default_device = 1; /* Using /dev/tty or equivalent */
74 char devnam[MAXPATHLEN] = "/dev/tty"; /* Device name */
75 int crtscts = 0; /* Use hardware flow control */
76 int modem = 1; /* Use modem control lines */
77 int inspeed = 0; /* Input/Output speed requested */
78 u_int32_t netmask = 0; /* IP netmask to set on interface */
79 int lockflag = 0; /* Create lock file to lock the serial dev */
80 int nodetach = 0; /* Don't detach from controlling tty */
81 char *connector = NULL; /* Script to establish physical link */
82 char *disconnector = NULL; /* Script to disestablish physical link */
83 char *welcomer = NULL; /* Script to run after phys link estab. */
84 int maxconnect = 0; /* Maximum connect time */
85 char user[MAXNAMELEN]; /* Username for PAP */
86 char passwd[MAXSECRETLEN]; /* Password for PAP */
87 int auth_required = 0; /* Peer is required to authenticate */
88 int defaultroute = 0; /* assign default route through interface */
89 int proxyarp = 0; /* Set up proxy ARP entry for peer */
90 int persist = 0; /* Reopen link after it goes down */
91 int uselogin = 0; /* Use /etc/passwd for checking PAP */
92 int lcp_echo_interval = 0; /* Interval between LCP echo-requests */
93 int lcp_echo_fails = 0; /* Tolerance to unanswered echo-requests */
94 char our_name[MAXNAMELEN]; /* Our name for authentication purposes */
95 char remote_name[MAXNAMELEN]; /* Peer's name for authentication */
96 int usehostname = 0; /* Use hostname for our_name */
97 int disable_defaultip = 0; /* Don't use hostname for default IP adrs */
98 int demand = 0; /* do dial-on-demand */
99 char *ipparam = NULL; /* Extra parameter for ip up/down scripts */
100 int cryptpap; /* Passwords in pap-secrets are encrypted */
101 int idle_time_limit = 0; /* Disconnect if idle for this many seconds */
102 int holdoff = 30; /* # seconds to pause before reconnecting */
103 struct bpf_program pass_filter;/* Filter program for packets to pass */
104 struct bpf_program active_filter; /* Filter program for link-active pkts */
109 static int setdevname __P((char *));
110 static int setipaddr __P((char *));
111 static int setdebug __P((void));
112 static int setkdebug __P((char **));
113 static int setpassive __P((void));
114 static int setsilent __P((void));
115 static int noopt __P((void));
116 static int setnovj __P((void));
117 static int setnovjccomp __P((void));
118 static int setvjslots __P((char **));
119 static int reqpap __P((void));
120 static int nopap __P((void));
121 static int setupapfile __P((char **));
122 static int nochap __P((void));
123 static int reqchap __P((void));
124 static int setspeed __P((char *));
125 static int noaccomp __P((void));
126 static int noasyncmap __P((void));
127 static int noip __P((void));
128 static int nomagicnumber __P((void));
129 static int setasyncmap __P((char **));
130 static int setescape __P((char **));
131 static int setmru __P((char **));
132 static int setmtu __P((char **));
133 static int nomru __P((void));
134 static int nopcomp __P((void));
135 static int setconnector __P((char **));
136 static int setdisconnector __P((char **));
137 static int setwelcomer __P((char **));
138 static int setmaxconnect __P((char **));
139 static int setdomain __P((char **));
140 static int setnetmask __P((char **));
141 static int setcrtscts __P((void));
142 static int setnocrtscts __P((void));
143 static int setxonxoff __P((void));
144 static int setnodetach __P((void));
145 static int setmodem __P((void));
146 static int setlocal __P((void));
147 static int setlock __P((void));
148 static int setname __P((char **));
149 static int setuser __P((char **));
150 static int setremote __P((char **));
151 static int setauth __P((void));
152 static int readfile __P((char **));
153 static int setdefaultroute __P((void));
154 static int setnodefaultroute __P((void));
155 static int setproxyarp __P((void));
156 static int setnoproxyarp __P((void));
157 static int setpersist __P((void));
158 static int setdologin __P((void));
159 static int setusehostname __P((void));
160 static int setnoipdflt __P((void));
161 static int setlcptimeout __P((char **));
162 static int setlcpterm __P((char **));
163 static int setlcpconf __P((char **));
164 static int setlcpfails __P((char **));
165 static int setipcptimeout __P((char **));
166 static int setipcpterm __P((char **));
167 static int setipcpconf __P((char **));
168 static int setipcpfails __P((char **));
169 static int setpaptimeout __P((char **));
170 static int setpapreqs __P((char **));
171 static int setpapreqtime __P((char **));
172 static int setchaptimeout __P((char **));
173 static int setchapchal __P((char **));
174 static int setchapintv __P((char **));
175 static int setipcpaccl __P((void));
176 static int setipcpaccr __P((void));
177 static int setlcpechointv __P((char **));
178 static int setlcpechofails __P((char **));
179 static int noccp __P((void));
180 static int setbsdcomp __P((char **));
181 static int setnobsdcomp __P((void));
182 static int setdeflate __P((char **));
183 static int setnodeflate __P((void));
184 static int setdemand __P((void));
185 static int setpred1comp __P((void));
186 static int setnopred1comp __P((void));
187 static int setipparam __P((char **));
188 static int setpapcrypt __P((void));
189 static int setidle __P((char **));
190 static int setholdoff __P((char **));
191 static int setpassfilter __P((char **));
192 static int setactivefilter __P((char **));
195 static int setipxproto __P((void));
196 static int resetipxproto __P((void));
197 static int setipxanet __P((void));
198 static int setipxalcl __P((void));
199 static int setipxarmt __P((void));
200 static int setipxnetwork __P((char **));
201 static int setipxnode __P((char **));
202 static int setipxrouter __P((char **));
203 static int setipxname __P((char **));
204 static int setipxcptimeout __P((char **));
205 static int setipxcpterm __P((char **));
206 static int setipxcpconf __P((char **));
207 static int setipxcpfails __P((char **));
208 #endif /* IPX_CHANGE */
211 static int setdnsaddr __P((char **));
214 static int number_option __P((char *, u_int32_t *, int));
215 static int readable __P((int fd));
227 {"-all", 0, noopt}, /* Don't request/allow any options (useless) */
228 {"noaccomp", 0, noaccomp}, /* Disable Address/Control compression */
229 {"-ac", 0, noaccomp}, /* Disable Address/Control compress */
230 {"default-asyncmap", 0, noasyncmap}, /* Disable asyncmap negoatiation */
231 {"-am", 0, noasyncmap}, /* Disable asyncmap negotiation */
232 {"-as", 1, setasyncmap}, /* set the desired async map */
233 {"-d", 0, setdebug}, /* Increase debugging level */
234 {"nodetach", 0, setnodetach}, /* Don't detach from controlling tty */
235 {"-detach", 0, setnodetach}, /* don't fork */
236 {"noip", 0, noip}, /* Disable IP and IPCP */
237 {"-ip", 0, noip}, /* Disable IP and IPCP */
238 {"nomagic", 0, nomagicnumber}, /* Disable magic number negotiation */
239 {"-mn", 0, nomagicnumber}, /* Disable magic number negotiation */
240 {"default-mru", 0, nomru}, /* Disable MRU negotiation */
241 {"-mru", 0, nomru}, /* Disable mru negotiation */
242 {"-p", 0, setpassive}, /* Set passive mode */
243 {"nopcomp", 0, nopcomp}, /* Disable protocol field compression */
244 {"-pc", 0, nopcomp}, /* Disable protocol field compress */
245 {"+ua", 1, setupapfile}, /* Get PAP user and password from file */
246 {"require-pap", 0, reqpap}, /* Require PAP authentication from peer */
247 {"+pap", 0, reqpap}, /* Require PAP auth from peer */
248 {"refuse-pap", 0, nopap}, /* Don't agree to auth to peer with PAP */
249 {"-pap", 0, nopap}, /* Don't allow UPAP authentication with peer */
250 {"require-chap", 0, reqchap}, /* Require CHAP authentication from peer */
251 {"+chap", 0, reqchap}, /* Require CHAP authentication from peer */
252 {"refuse-chap", 0, nochap}, /* Don't agree to auth to peer with CHAP */
253 {"-chap", 0, nochap}, /* Don't allow CHAP authentication with peer */
254 {"novj", 0, setnovj}, /* Disable VJ compression */
255 {"-vj", 0, setnovj}, /* disable VJ compression */
256 {"novjccomp", 0, setnovjccomp}, /* disable VJ connection-ID compression */
257 {"-vjccomp", 0, setnovjccomp}, /* disable VJ connection-ID compression */
258 {"vj-max-slots", 1, setvjslots}, /* Set maximum VJ header slots */
259 {"asyncmap", 1, setasyncmap}, /* set the desired async map */
260 {"escape", 1, setescape}, /* set chars to escape on transmission */
261 {"connect", 1, setconnector}, /* A program to set up a connection */
262 {"disconnect", 1, setdisconnector}, /* program to disconnect serial dev. */
263 {"welcome", 1, setwelcomer},/* Script to welcome client */
264 {"maxconnect", 1, setmaxconnect}, /* specify a maximum connect time */
265 {"crtscts", 0, setcrtscts}, /* set h/w flow control */
266 {"nocrtscts", 0, setnocrtscts}, /* clear h/w flow control */
267 {"-crtscts", 0, setnocrtscts}, /* clear h/w flow control */
268 {"xonxoff", 0, setxonxoff}, /* set s/w flow control */
269 {"debug", 0, setdebug}, /* Increase debugging level */
270 {"kdebug", 1, setkdebug}, /* Enable kernel-level debugging */
271 {"domain", 1, setdomain}, /* Add given domain name to hostname*/
272 {"mru", 1, setmru}, /* Set MRU value for negotiation */
273 {"mtu", 1, setmtu}, /* Set our MTU */
274 {"netmask", 1, setnetmask}, /* set netmask */
275 {"passive", 0, setpassive}, /* Set passive mode */
276 {"silent", 0, setsilent}, /* Set silent mode */
277 {"modem", 0, setmodem}, /* Use modem control lines */
278 {"local", 0, setlocal}, /* Don't use modem control lines */
279 {"lock", 0, setlock}, /* Lock serial device (with lock file) */
280 {"name", 1, setname}, /* Set local name for authentication */
281 {"user", 1, setuser}, /* Set username for PAP auth with peer */
282 {"usehostname", 0, setusehostname}, /* Must use hostname for auth. */
283 {"remotename", 1, setremote}, /* Set remote name for authentication */
284 {"auth", 0, setauth}, /* Require authentication from peer */
285 {"file", 1, readfile}, /* Take options from a file */
286 {"defaultroute", 0, setdefaultroute}, /* Add default route */
287 {"nodefaultroute", 0, setnodefaultroute}, /* disable defaultroute option */
288 {"-defaultroute", 0, setnodefaultroute}, /* disable defaultroute option */
289 {"proxyarp", 0, setproxyarp}, /* Add proxy ARP entry */
290 {"noproxyarp", 0, setnoproxyarp}, /* disable proxyarp option */
291 {"-proxyarp", 0, setnoproxyarp}, /* disable proxyarp option */
292 {"persist", 0, setpersist}, /* Keep on reopening connection after close */
293 {"demand", 0, setdemand}, /* Dial on demand */
294 {"login", 0, setdologin}, /* Use system password database for UPAP */
295 {"noipdefault", 0, setnoipdflt}, /* Don't use name for default IP adrs */
296 {"lcp-echo-failure", 1, setlcpechofails}, /* consecutive echo failures */
297 {"lcp-echo-interval", 1, setlcpechointv}, /* time for lcp echo events */
298 {"lcp-restart", 1, setlcptimeout}, /* Set timeout for LCP */
299 {"lcp-max-terminate", 1, setlcpterm}, /* Set max #xmits for term-reqs */
300 {"lcp-max-configure", 1, setlcpconf}, /* Set max #xmits for conf-reqs */
301 {"lcp-max-failure", 1, setlcpfails}, /* Set max #conf-naks for LCP */
302 {"ipcp-restart", 1, setipcptimeout}, /* Set timeout for IPCP */
303 {"ipcp-max-terminate", 1, setipcpterm}, /* Set max #xmits for term-reqs */
304 {"ipcp-max-configure", 1, setipcpconf}, /* Set max #xmits for conf-reqs */
305 {"ipcp-max-failure", 1, setipcpfails}, /* Set max #conf-naks for IPCP */
306 {"pap-restart", 1, setpaptimeout}, /* Set retransmit timeout for PAP */
307 {"pap-max-authreq", 1, setpapreqs}, /* Set max #xmits for auth-reqs */
308 {"pap-timeout", 1, setpapreqtime}, /* Set time limit for peer PAP auth. */
309 {"chap-restart", 1, setchaptimeout}, /* Set timeout for CHAP */
310 {"chap-max-challenge", 1, setchapchal}, /* Set max #xmits for challenge */
311 {"chap-interval", 1, setchapintv}, /* Set interval for rechallenge */
312 {"ipcp-accept-local", 0, setipcpaccl}, /* Accept peer's address for us */
313 {"ipcp-accept-remote", 0, setipcpaccr}, /* Accept peer's address for it */
314 {"noccp", 0, noccp}, /* Disable CCP negotiation */
315 {"-ccp", 0, noccp}, /* Disable CCP negotiation */
316 {"bsdcomp", 1, setbsdcomp}, /* request BSD-Compress */
317 {"nobsdcomp", 0, setnobsdcomp}, /* don't allow BSD-Compress */
318 {"-bsdcomp", 0, setnobsdcomp}, /* don't allow BSD-Compress */
319 {"deflate", 1, setdeflate}, /* request Deflate compression */
320 {"nodeflate", 0, setnodeflate}, /* don't allow Deflate compression */
321 {"-deflate", 0, setnodeflate}, /* don't allow Deflate compression */
322 {"predictor1", 0, setpred1comp}, /* request Predictor-1 */
323 {"nopredictor1", 0, setnopred1comp},/* don't allow Predictor-1 */
324 {"-predictor1", 0, setnopred1comp}, /* don't allow Predictor-1 */
325 {"ipparam", 1, setipparam}, /* set ip script parameter */
326 {"papcrypt", 0, setpapcrypt}, /* PAP passwords encrypted */
327 {"idle", 1, setidle}, /* idle time limit (seconds) */
328 {"holdoff", 1, setholdoff}, /* set holdoff time (seconds) */
329 {"pass-filter", 1, setpassfilter}, /* set filter for packets to pass */
330 {"active-filter", 1, setactivefilter}, /* set filter for active pkts */
333 {"ipx-network", 1, setipxnetwork}, /* IPX network number */
334 {"ipxcp-accept-network", 0, setipxanet}, /* Accept peer netowrk */
335 {"ipx-node", 1, setipxnode}, /* IPX node number */
336 {"ipxcp-accept-local", 0, setipxalcl}, /* Accept our address */
337 {"ipxcp-accept-remote", 0, setipxarmt}, /* Accept peer's address */
338 {"ipx-routing", 1, setipxrouter}, /* IPX routing proto number */
339 {"ipx-router-name", 1, setipxname}, /* IPX router name */
340 {"ipxcp-restart", 1, setipxcptimeout}, /* Set timeout for IPXCP */
341 {"ipxcp-max-terminate", 1, setipxcpterm}, /* max #xmits for term-reqs */
342 {"ipxcp-max-configure", 1, setipxcpconf}, /* max #xmits for conf-reqs */
343 {"ipxcp-max-failure", 1, setipxcpfails}, /* max #conf-naks for IPXCP */
345 {"ipx-compression", 1, setipxcompression}, /* IPX compression number */
347 {"ipx", 0, setipxproto}, /* Enable IPXCP (and IPX) */
348 {"noipx", 0, resetipxproto}, /* Disable IPXCP (and IPX) */
349 {"+ipx", 0, setipxproto}, /* Enable IPXCP (and IPX) */
350 {"-ipx", 0, resetipxproto}, /* Disable IPXCP (and IPX) */
351 #endif /* IPX_CHANGE */
354 {"ms-dns", 1, setdnsaddr}, /* DNS address(es) for the peer's use */
361 #ifndef IMPLEMENTATION
362 #define IMPLEMENTATION ""
365 static char *usage_string = "\
366 pppd version %s patch level %d%s\n\
367 Usage: %s [ arguments ], where arguments are:\n\
368 <device> Communicate over the named device\n\
369 <speed> Set the baud rate to <speed>\n\
370 <loc>:<rem> Set the local and/or remote interface IP\n\
371 addresses. Either one may be omitted.\n\
372 asyncmap <n> Set the desired async map to hex <n>\n\
373 auth Require authentication from peer\n\
374 connect <p> Invoke shell command <p> to set up the serial line\n\
375 crtscts Use hardware RTS/CTS flow control\n\
376 defaultroute Add default route through interface\n\
377 file <f> Take options from file <f>\n\
378 modem Use modem control lines\n\
379 mru <n> Set MRU value to <n> for negotiation\n\
380 netmask <n> Set interface netmask to <n>\n\
381 See pppd(8) for more options.\n\
386 * parse_args - parse a string of arguments, from the command
387 * line or from a file.
390 parse_args(argc, argv)
403 * First see if it's a command.
405 for (cmdp = cmds; cmdp->cmd_name; cmdp++)
406 if (!strcmp(arg, cmdp->cmd_name))
409 if (cmdp->cmd_name != NULL) {
410 if (argc < cmdp->num_args) {
411 fprintf(stderr, "Too few parameters for command %s\n", arg);
414 if (!(*cmdp->cmd_func)(argv))
416 argc -= cmdp->num_args;
417 argv += cmdp->num_args;
421 * Maybe a tty name, speed or IP address?
423 if ((ret = setdevname(arg)) == 0
424 && (ret = setspeed(arg)) == 0
425 && (ret = setipaddr(arg)) == 0) {
426 fprintf(stderr, "%s: unrecognized command\n", arg);
430 if (ret < 0) /* error */
438 * usage - print out a message telling how to use the program.
443 fprintf(stderr, usage_string, VERSION, PATCHLEVEL, IMPLEMENTATION,
448 * options_from_file - Read a string of options from a file,
449 * and interpret them.
452 options_from_file(filename, must_exist, check_prot)
461 char args[MAXARGS][MAXWORDLEN];
462 char cmd[MAXWORDLEN];
464 if ((f = fopen(filename, "r")) == NULL) {
465 if (!must_exist && errno == ENOENT)
470 if (check_prot && !readable(fileno(f))) {
471 fprintf(stderr, "%s: access denied\n", filename);
476 while (getword(f, cmd, &newline, filename)) {
478 * First see if it's a command.
480 for (cmdp = cmds; cmdp->cmd_name; cmdp++)
481 if (!strcmp(cmd, cmdp->cmd_name))
484 if (cmdp->cmd_name != NULL) {
485 for (i = 0; i < cmdp->num_args; ++i) {
486 if (!getword(f, args[i], &newline, filename)) {
488 "In file %s: too few parameters for command %s\n",
495 if (!(*cmdp->cmd_func)(argv)) {
502 * Maybe a tty name, speed or IP address?
504 if ((ret = setdevname(cmd)) == 0
505 && (ret = setspeed(cmd)) == 0
506 && (ret = setipaddr(cmd)) == 0) {
507 fprintf(stderr, "In file %s: unrecognized command %s\n",
512 if (ret < 0) /* error */
520 * options_from_user - See if the use has a ~/.ppprc file,
521 * and if so, interpret options from it.
526 char *user, *path, *file;
530 pw = getpwuid(getuid());
531 if (pw == NULL || (user = pw->pw_dir) == NULL || user[0] == 0)
533 file = _PATH_USEROPT;
534 path = malloc(strlen(user) + strlen(file) + 2);
536 novm("init file name");
540 ret = options_from_file(path, 0, 1);
546 * options_for_tty - See if an options file exists for the serial
547 * device, and if so, interpret options from it.
552 char *dev, *path, *p;
556 if (strncmp(dev, "/dev/", 5) == 0)
558 if (strcmp(dev, "tty") == 0)
559 return 1; /* don't look for /etc/ppp/options.tty */
560 path = malloc(strlen(_PATH_TTYOPT) + strlen(dev) + 1);
562 novm("tty init file name");
563 strcpy(path, _PATH_TTYOPT);
564 /* Turn slashes into dots, for Solaris case (e.g. /dev/term/a) */
565 for (p = path + strlen(path); *dev != 0; ++dev)
566 *p++ = (*dev == '/'? '.': *dev);
568 ret = options_from_file(path, 0, 0);
574 * readable - check if a file is readable by the real user.
583 GIDSET_TYPE groups[NGROUPS_MAX];
588 if (fstat(fd, &sbuf) != 0)
590 if (sbuf.st_uid == uid)
591 return sbuf.st_mode & S_IRUSR;
592 if (sbuf.st_gid == getgid())
593 return sbuf.st_mode & S_IRGRP;
594 ngroups = getgroups(NGROUPS_MAX, groups);
595 for (i = 0; i < ngroups; ++i)
596 if (sbuf.st_gid == groups[i])
597 return sbuf.st_mode & S_IRGRP;
598 return sbuf.st_mode & S_IROTH;
602 * Read a word from a file.
603 * Words are delimited by white-space or by quotes (" or ').
604 * Quotes, white-space and \ may be escaped with \.
605 * \<newline> is ignored.
608 getword(f, word, newlinep, filename)
616 int value, digit, got, n;
618 #define isoctal(c) ((c) >= '0' && (c) < '8')
626 * First skip white-space and comments.
634 * A newline means the end of a comment; backslash-newline
635 * is ignored. Note that we cannot have escape && comment.
647 * Ignore characters other than newline in a comment.
653 * If this character is escaped, we have a word start.
659 * If this is the escape character, look at the next character.
667 * If this is the start of a comment, ignore the rest of the line.
675 * A non-whitespace character is the start of a word.
682 * Save the delimiter for quoted strings.
684 if (!escape && (c == '"' || c == '\'')) {
691 * Process characters until the end of the word.
696 * This character is escaped: backslash-newline is ignored,
697 * various other characters indicate particular values
698 * as for C backslash-escapes.
733 * \ddd octal sequence
736 for (n = 0; n < 3 && isoctal(c); ++n) {
737 value = (value << 3) + (c & 07);
746 * \x<hex_string> sequence
750 for (n = 0; n < 2 && isxdigit(c); ++n) {
751 digit = toupper(c) - '0';
753 digit += '0' + 10 - 'A';
754 value = (value << 4) + digit;
762 * Otherwise the character stands for itself.
769 * Store the resulting character for the escape sequence.
771 if (len < MAXWORDLEN-1)
782 * Not escaped: see if we've reached the end of the word.
788 if (isspace(c) || c == '#') {
795 * Backslash starts an escape sequence.
804 * An ordinary character: store it in the word and get another.
806 if (len < MAXWORDLEN-1)
814 * End of the word: check for errors.
824 * If len is zero, then we didn't find a word before the
832 * Warn if the word was too long, and append a terminating null.
834 if (len >= MAXWORDLEN) {
835 fprintf(stderr, "%s: warning: word in file %s too long (%.20s...)\n",
836 progname, filename, word);
837 len = MAXWORDLEN - 1;
848 * number_option - parse an unsigned numeric parameter for an option.
851 number_option(str, valp, base)
858 *valp = strtoul(str, &ptr, base);
860 fprintf(stderr, "%s: invalid number: %s\n", progname, str);
868 * int_option - like number_option, but valp is int *,
869 * the base is assumed to be 0, and *valp is not changed
870 * if there is an error.
873 int_option(str, valp)
879 if (!number_option(str, &v, 0))
887 * The following procedures execute commands.
891 * readfile - take commands from a file.
897 return options_from_file(*argv, 1, 1);
901 * setdebug - Set debug (command line argument).
911 * setkdebug - Set kernel debugging level.
917 return int_option(*argv, &kdebugflag);
921 * noopt - Disable all options.
926 BZERO((char *) &lcp_wantoptions[0], sizeof (struct lcp_options));
927 BZERO((char *) &lcp_allowoptions[0], sizeof (struct lcp_options));
928 BZERO((char *) &ipcp_wantoptions[0], sizeof (struct ipcp_options));
929 BZERO((char *) &ipcp_allowoptions[0], sizeof (struct ipcp_options));
932 BZERO((char *) &ipxcp_wantoptions[0], sizeof (struct ipxcp_options));
933 BZERO((char *) &ipxcp_allowoptions[0], sizeof (struct ipxcp_options));
934 #endif /* IPX_CHANGE */
940 * noaccomp - Disable Address/Control field compression negotiation.
945 lcp_wantoptions[0].neg_accompression = 0;
946 lcp_allowoptions[0].neg_accompression = 0;
952 * noasyncmap - Disable async map negotiation.
957 lcp_wantoptions[0].neg_asyncmap = 0;
958 lcp_allowoptions[0].neg_asyncmap = 0;
964 * noip - Disable IP and IPCP.
969 ipcp_protent.enabled_flag = 0;
975 * nomagicnumber - Disable magic number negotiation.
980 lcp_wantoptions[0].neg_magicnumber = 0;
981 lcp_allowoptions[0].neg_magicnumber = 0;
987 * nomru - Disable mru negotiation.
992 lcp_wantoptions[0].neg_mru = 0;
993 lcp_allowoptions[0].neg_mru = 0;
999 * setmru - Set MRU for negotiation.
1007 if (!number_option(*argv, &mru, 0))
1009 lcp_wantoptions[0].mru = mru;
1010 lcp_wantoptions[0].neg_mru = 1;
1016 * setmru - Set the largest MTU we'll use.
1024 if (!number_option(*argv, &mtu, 0))
1026 if (mtu < MINMRU || mtu > MAXMRU) {
1027 fprintf(stderr, "mtu option value of %ld is too %s\n", mtu,
1028 (mtu < MINMRU? "small": "large"));
1031 lcp_allowoptions[0].mru = mtu;
1037 * nopcomp - Disable Protocol field compression negotiation.
1042 lcp_wantoptions[0].neg_pcompression = 0;
1043 lcp_allowoptions[0].neg_pcompression = 0;
1049 * setpassive - Set passive mode (don't give up if we time out sending
1050 * LCP configure-requests).
1055 lcp_wantoptions[0].passive = 1;
1061 * setsilent - Set silent mode (don't start sending LCP configure-requests
1062 * until we get one from the peer).
1067 lcp_wantoptions[0].silent = 1;
1073 * nopap - Disable PAP authentication with peer.
1078 lcp_allowoptions[0].neg_upap = 0;
1084 * reqpap - Require PAP authentication from peer.
1089 lcp_wantoptions[0].neg_upap = 1;
1096 * setupapfile - specifies UPAP info for authenticating with peer.
1105 lcp_allowoptions[0].neg_upap = 1;
1107 /* open user info file */
1108 if ((ufile = fopen(*argv, "r")) == NULL) {
1109 fprintf(stderr, "unable to open user login data file %s\n", *argv);
1112 if (!readable(fileno(ufile))) {
1113 fprintf(stderr, "%s: access denied\n", *argv);
1116 check_access(ufile, *argv);
1119 if (fgets(user, MAXNAMELEN - 1, ufile) == NULL
1120 || fgets(passwd, MAXSECRETLEN - 1, ufile) == NULL){
1121 fprintf(stderr, "Unable to read user login data file %s.\n", *argv);
1126 /* get rid of newlines */
1128 if (l > 0 && user[l-1] == '\n')
1131 if (l > 0 && passwd[l-1] == '\n')
1139 * nochap - Disable CHAP authentication with peer.
1144 lcp_allowoptions[0].neg_chap = 0;
1150 * reqchap - Require CHAP authentication from peer.
1155 lcp_wantoptions[0].neg_chap = 1;
1162 * setnovj - disable vj compression
1167 ipcp_wantoptions[0].neg_vj = 0;
1168 ipcp_allowoptions[0].neg_vj = 0;
1174 * setnovjccomp - disable VJ connection-ID compression
1179 ipcp_wantoptions[0].cflag = 0;
1180 ipcp_allowoptions[0].cflag = 0;
1186 * setvjslots - set maximum number of connection slots for VJ compression
1194 if (!int_option(*argv, &value))
1196 if (value < 2 || value > 16) {
1197 fprintf(stderr, "pppd: vj-max-slots value must be between 2 and 16\n");
1200 ipcp_wantoptions [0].maxslotindex =
1201 ipcp_allowoptions[0].maxslotindex = value - 1;
1207 * setconnector - Set a program to connect to a serial line
1213 connector = strdup(*argv);
1214 if (connector == NULL)
1215 novm("connect script");
1221 * setdisconnector - Set a program to disconnect from the serial line
1224 setdisconnector(argv)
1227 disconnector = strdup(*argv);
1228 if (disconnector == NULL)
1229 novm("disconnect script");
1235 * setwelcomer - Set a program to welcome a client after connection
1241 welcomer = strdup(*argv);
1242 if (welcomer == NULL)
1243 novm("welcome script");
1249 * setmaxconnect - Set the maximum connect time
1257 if (!int_option(*argv, &value))
1260 fprintf(stderr, "pppd: maxconnect time must be positive\n");
1268 * setdomain - Set domain name to append to hostname
1274 gethostname(hostname, MAXNAMELEN);
1277 strncat(hostname, ".", MAXNAMELEN - strlen(hostname));
1278 strncat(hostname, *argv, MAXNAMELEN - strlen(hostname));
1280 hostname[MAXNAMELEN-1] = 0;
1286 * setasyncmap - add bits to asyncmap (what we request peer to escape).
1294 if (!number_option(*argv, &asyncmap, 16))
1296 lcp_wantoptions[0].asyncmap |= asyncmap;
1297 lcp_wantoptions[0].neg_asyncmap = 1;
1303 * setescape - add chars to the set we escape on transmission.
1315 n = strtol(p, &endp, 16);
1317 fprintf(stderr, "%s: invalid hex number: %s\n", progname, p);
1321 if (n < 0 || 0x20 <= n && n <= 0x3F || n == 0x5E || n > 0xFF) {
1322 fprintf(stderr, "%s: can't escape character 0x%x\n", progname, n);
1325 xmit_accm[0][n >> 5] |= 1 << (n & 0x1F);
1326 while (*p == ',' || *p == ' ')
1334 * setspeed - Set the speed.
1343 spd = strtol(arg, &ptr, 0);
1344 if (ptr == arg || *ptr != 0 || spd == 0)
1352 * setdevname - Set the device name.
1358 struct stat statbuf;
1359 char dev[MAXPATHLEN];
1361 if (strncmp("/dev/", cp, 5) != 0) {
1362 strcpy(dev, "/dev/");
1363 strncat(dev, cp, MAXPATHLEN - 5);
1364 dev[MAXPATHLEN-1] = 0;
1369 * Check if there is a device by this name.
1371 if (stat(cp, &statbuf) < 0) {
1372 if (errno == ENOENT)
1374 syslog(LOG_ERR, cp);
1378 (void) strncpy(devnam, cp, MAXPATHLEN);
1379 devnam[MAXPATHLEN-1] = 0;
1380 default_device = FALSE;
1387 * setipaddr - Set the IP address
1395 u_int32_t local, remote;
1396 ipcp_options *wo = &ipcp_wantoptions[0];
1399 * IP address pair separated by ":".
1401 if ((colon = strchr(arg, ':')) == NULL)
1405 * If colon first character, then no local addr.
1409 if ((local = inet_addr(arg)) == -1) {
1410 if ((hp = gethostbyname(arg)) == NULL) {
1411 fprintf(stderr, "unknown host: %s\n", arg);
1414 local = *(u_int32_t *)hp->h_addr;
1415 if (our_name[0] == 0) {
1416 strncpy(our_name, arg, MAXNAMELEN);
1417 our_name[MAXNAMELEN-1] = 0;
1421 if (bad_ip_adrs(local)) {
1422 fprintf(stderr, "bad local IP address %s\n", ip_ntoa(local));
1426 wo->ouraddr = local;
1431 * If colon last character, then no remote addr.
1433 if (*++colon != '\0') {
1434 if ((remote = inet_addr(colon)) == -1) {
1435 if ((hp = gethostbyname(colon)) == NULL) {
1436 fprintf(stderr, "unknown host: %s\n", colon);
1439 remote = *(u_int32_t *)hp->h_addr;
1440 if (remote_name[0] == 0) {
1441 strncpy(remote_name, colon, MAXNAMELEN);
1442 remote_name[MAXNAMELEN-1] = 0;
1446 if (bad_ip_adrs(remote)) {
1447 fprintf(stderr, "bad remote IP address %s\n", ip_ntoa(remote));
1451 wo->hisaddr = remote;
1459 * setnoipdflt - disable setipdefault()
1464 disable_defaultip = 1;
1470 * setipcpaccl - accept peer's idea of our address
1475 ipcp_wantoptions[0].accept_local = 1;
1481 * setipcpaccr - accept peer's idea of its address
1486 ipcp_wantoptions[0].accept_remote = 1;
1492 * setnetmask - set the netmask to be used on the interface.
1500 if ((mask = inet_addr(*argv)) == -1 || (netmask & ~mask) != 0) {
1501 fprintf(stderr, "Invalid netmask %s\n", *argv);
1526 lcp_wantoptions[0].asyncmap |= 0x000A0000; /* escape ^S and ^Q */
1527 lcp_wantoptions[0].neg_asyncmap = 1;
1579 if (our_name[0] == 0) {
1580 strncpy(our_name, argv[0], MAXNAMELEN);
1581 our_name[MAXNAMELEN-1] = 0;
1590 strncpy(user, argv[0], MAXNAMELEN);
1591 user[MAXNAMELEN-1] = 0;
1599 strncpy(remote_name, argv[0], MAXNAMELEN);
1600 remote_name[MAXNAMELEN-1] = 0;
1614 if (!ipcp_allowoptions[0].default_route) {
1615 fprintf(stderr, "%s: defaultroute option is disabled\n", progname);
1618 ipcp_wantoptions[0].default_route = 1;
1625 ipcp_allowoptions[0].default_route = 0;
1626 ipcp_wantoptions[0].default_route = 0;
1633 if (!ipcp_allowoptions[0].proxy_arp) {
1634 fprintf(stderr, "%s: proxyarp option is disabled\n", progname);
1637 ipcp_wantoptions[0].proxy_arp = 1;
1644 ipcp_wantoptions[0].proxy_arp = 0;
1645 ipcp_allowoptions[0].proxy_arp = 0;
1664 * Functions to set the echo interval for modem-less monitors
1668 setlcpechointv(argv)
1671 return int_option(*argv, &lcp_echo_interval);
1675 setlcpechofails(argv)
1678 return int_option(*argv, &lcp_echo_fails);
1682 * Functions to set timeouts, max transmits, etc.
1688 return int_option(*argv, &lcp_fsm[0].timeouttime);
1695 return int_option(*argv, &lcp_fsm[0].maxtermtransmits);
1702 return int_option(*argv, &lcp_fsm[0].maxconfreqtransmits);
1709 return int_option(*argv, &lcp_fsm[0].maxnakloops);
1713 setipcptimeout(argv)
1716 return int_option(*argv, &ipcp_fsm[0].timeouttime);
1723 return int_option(*argv, &ipcp_fsm[0].maxtermtransmits);
1730 return int_option(*argv, &ipcp_fsm[0].maxconfreqtransmits);
1737 return int_option(*argv, &lcp_fsm[0].maxnakloops);
1744 return int_option(*argv, &upap[0].us_timeouttime);
1751 return int_option(*argv, &upap[0].us_reqtimeout);
1758 return int_option(*argv, &upap[0].us_maxtransmits);
1762 setchaptimeout(argv)
1765 return int_option(*argv, &chap[0].timeouttime);
1772 return int_option(*argv, &chap[0].max_transmits);
1779 return int_option(*argv, &chap[0].chal_interval);
1785 ccp_protent.enabled_flag = 0;
1797 abits = rbits = strtol(str, &endp, 0);
1798 if (endp != str && *endp == ',') {
1800 abits = strtol(str, &endp, 0);
1802 if (*endp != 0 || endp == str) {
1803 fprintf(stderr, "%s: invalid argument format for bsdcomp option\n",
1807 if (rbits != 0 && (rbits < BSD_MIN_BITS || rbits > BSD_MAX_BITS)
1808 || abits != 0 && (abits < BSD_MIN_BITS || abits > BSD_MAX_BITS)) {
1809 fprintf(stderr, "%s: bsdcomp option values must be 0 or %d .. %d\n",
1810 progname, BSD_MIN_BITS, BSD_MAX_BITS);
1814 ccp_wantoptions[0].bsd_compress = 1;
1815 ccp_wantoptions[0].bsd_bits = rbits;
1817 ccp_wantoptions[0].bsd_compress = 0;
1819 ccp_allowoptions[0].bsd_compress = 1;
1820 ccp_allowoptions[0].bsd_bits = abits;
1822 ccp_allowoptions[0].bsd_compress = 0;
1829 ccp_wantoptions[0].bsd_compress = 0;
1830 ccp_allowoptions[0].bsd_compress = 0;
1842 abits = rbits = strtol(str, &endp, 0);
1843 if (endp != str && *endp == ',') {
1845 abits = strtol(str, &endp, 0);
1847 if (*endp != 0 || endp == str) {
1848 fprintf(stderr, "%s: invalid argument format for deflate option\n",
1852 if (rbits != 0 && (rbits < DEFLATE_MIN_SIZE || rbits > DEFLATE_MAX_SIZE)
1853 || abits != 0 && (abits < DEFLATE_MIN_SIZE
1854 || abits > DEFLATE_MAX_SIZE)) {
1855 fprintf(stderr, "%s: deflate option values must be 0 or %d .. %d\n",
1856 progname, DEFLATE_MIN_SIZE, DEFLATE_MAX_SIZE);
1860 ccp_wantoptions[0].deflate = 1;
1861 ccp_wantoptions[0].deflate_size = rbits;
1863 ccp_wantoptions[0].deflate = 0;
1865 ccp_allowoptions[0].deflate = 1;
1866 ccp_allowoptions[0].deflate_size = abits;
1868 ccp_allowoptions[0].deflate = 0;
1875 ccp_wantoptions[0].deflate = 0;
1876 ccp_allowoptions[0].deflate = 0;
1883 ccp_wantoptions[0].predictor_1 = 1;
1884 ccp_allowoptions[0].predictor_1 = 1;
1891 ccp_wantoptions[0].predictor_1 = 0;
1892 ccp_allowoptions[0].predictor_1 = 0;
1900 ipparam = strdup(*argv);
1901 if (ipparam == NULL)
1902 novm("ipparam string");
1918 return int_option(*argv, &idle_time_limit);
1925 return int_option(*argv, &holdoff);
1932 if (bpf_compile(&pass_filter, *argv, 1) == 0)
1934 fprintf(stderr, "%s: error in pass-filter expression: %s\n",
1935 progname, bpf_geterr());
1940 setactivefilter(argv)
1943 if (bpf_compile(&active_filter, *argv, 1) == 0)
1945 fprintf(stderr, "%s: error in active-filter expression: %s\n",
1946 progname, bpf_geterr());
1955 ipxcp_wantoptions[0].neg_router = 1;
1956 ipxcp_allowoptions[0].neg_router = 1;
1957 return int_option(*argv, &ipxcp_wantoptions[0].router);
1964 char *dest = ipxcp_wantoptions[0].name;
1969 ipxcp_wantoptions[0].neg_name = 1;
1970 ipxcp_allowoptions[0].neg_name = 1;
1971 memset (dest, '\0', sizeof (ipxcp_wantoptions[0].name));
1976 if (! isalnum (ch) && ch != '_') {
1978 "%s: IPX router name must be alphanumeric or _\n",
1983 if (count >= sizeof (ipxcp_wantoptions[0].name)) {
1985 "%s: IPX router name is limited to %d characters\n",
1987 sizeof (ipxcp_wantoptions[0].name) - 1);
1991 dest[count++] = toupper (ch);
1998 setipxcptimeout (argv)
2001 return int_option(*argv, &ipxcp_fsm[0].timeouttime);
2008 return int_option(*argv, &ipxcp_fsm[0].maxtermtransmits);
2015 return int_option(*argv, &ipxcp_fsm[0].maxconfreqtransmits);
2019 setipxcpfails (argv)
2022 return int_option(*argv, &ipxcp_fsm[0].maxnakloops);
2029 ipxcp_wantoptions[0].neg_nn = 1;
2030 return int_option(*argv, &ipxcp_wantoptions[0].our_network);
2036 ipxcp_wantoptions[0].accept_network = 1;
2037 ipxcp_allowoptions[0].accept_network = 1;
2043 ipxcp_wantoptions[0].accept_local = 1;
2044 ipxcp_allowoptions[0].accept_local = 1;
2050 ipxcp_wantoptions[0].accept_remote = 1;
2051 ipxcp_allowoptions[0].accept_remote = 1;
2055 setipxnodevalue(src,dst)
2062 if (!isxdigit (*src))
2065 for (indx = 0; indx < 5; ++indx) {
2067 dst[indx] |= (dst[indx + 1] >> 4) & 0x0F;
2070 item = toupper (*src) - '0';
2074 dst[5] = (dst[5] << 4) | item;
2086 memset (&ipxcp_wantoptions[0].our_node[0], 0, 6);
2087 memset (&ipxcp_wantoptions[0].his_node[0], 0, 6);
2089 end = setipxnodevalue (*argv, &ipxcp_wantoptions[0].our_node[0]);
2091 end = setipxnodevalue (++end, &ipxcp_wantoptions[0].his_node[0]);
2094 ipxcp_wantoptions[0].neg_node = 1;
2098 fprintf(stderr, "%s: invalid argument for ipx-node option\n",
2106 ipx_enabled = 1; /* Enable IPXCP and IPX protocol */
2113 ipx_enabled = 0; /* Disable IPXCP and IPX protocol */
2116 #endif /* IPX_CHANGE */
2120 * setdnsaddr - set the dns address(es)
2130 dns = inet_addr(*argv);
2132 if ((hp = gethostbyname(*argv)) == NULL) {
2133 fprintf(stderr, "Invalid DNS Address %s\n", *argv);
2136 dns = *(u_int32_t *)hp->h_addr;
2139 if (ipcp_allowoptions[0].dnsaddr[0] == 0) {
2140 ipcp_allowoptions[0].dnsaddr[0] = dns;
2142 ipcp_allowoptions[0].dnsaddr[1] = dns;
2147 #endif /* USE_MS_DNS */