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.29 1996/01/18 03:35:38 paulus Exp $";
34 #include <sys/types.h>
36 #include <netinet/in.h>
39 #include "pathnames.h"
40 #include "patchlevel.h"
50 #endif /* IPX_CHANGE */
52 #include <net/ppp-comp.h>
57 #if defined(ultrix) || defined(NeXT)
58 char *strdup __P((char *));
62 #define GIDSET_TYPE gid_t
66 * Option variables and default values.
68 int debug = 0; /* Debug flag */
69 int kdebugflag = 0; /* Tell kernel to print debug messages */
70 int default_device = 1; /* Using /dev/tty or equivalent */
71 char devnam[MAXPATHLEN] = "/dev/tty"; /* Device name */
72 int crtscts = 0; /* Use hardware flow control */
73 int modem = 1; /* Use modem control lines */
74 int inspeed = 0; /* Input/Output speed requested */
75 u_int32_t netmask = 0; /* IP netmask to set on interface */
76 int lockflag = 0; /* Create lock file to lock the serial dev */
77 int nodetach = 0; /* Don't detach from controlling tty */
78 char *connector = NULL; /* Script to establish physical link */
79 char *disconnector = NULL; /* Script to disestablish physical link */
80 char *welcomer = NULL; /* Script to run after phys link estab. */
81 int maxconnect = 0; /* Maximum connect time */
82 char user[MAXNAMELEN]; /* Username for PAP */
83 char passwd[MAXSECRETLEN]; /* Password for PAP */
84 int auth_required = 0; /* Peer is required to authenticate */
85 int defaultroute = 0; /* assign default route through interface */
86 int proxyarp = 0; /* Set up proxy ARP entry for peer */
87 int persist = 0; /* Reopen link after it goes down */
88 int uselogin = 0; /* Use /etc/passwd for checking PAP */
89 int lcp_echo_interval = 0; /* Interval between LCP echo-requests */
90 int lcp_echo_fails = 0; /* Tolerance to unanswered echo-requests */
91 char our_name[MAXNAMELEN]; /* Our name for authentication purposes */
92 char remote_name[MAXNAMELEN]; /* Peer's name for authentication */
93 int usehostname = 0; /* Use hostname for our_name */
94 int disable_defaultip = 0; /* Don't use hostname for default IP adrs */
95 int demand = 0; /* do dial-on-demand */
96 char *ipparam = NULL; /* Extra parameter for ip up/down scripts */
97 int cryptpap; /* Passwords in pap-secrets are encrypted */
98 int idle_time_limit = 0; /* Disconnect if idle for this many seconds */
99 int holdoff = 30; /* # seconds to pause before reconnecting */
104 static int setdebug __P((void));
105 static int setkdebug __P((char **));
106 static int setpassive __P((void));
107 static int setsilent __P((void));
108 static int noopt __P((void));
109 static int setnovj __P((void));
110 static int setnovjccomp __P((void));
111 static int setvjslots __P((char **));
112 static int reqpap __P((void));
113 static int nopap __P((void));
114 static int setupapfile __P((char **));
115 static int nochap __P((void));
116 static int reqchap __P((void));
117 static int setspeed __P((char *));
118 static int noaccomp __P((void));
119 static int noasyncmap __P((void));
120 static int noip __P((void));
121 static int nomagicnumber __P((void));
122 static int setasyncmap __P((char **));
123 static int setescape __P((char **));
124 static int setmru __P((char **));
125 static int setmtu __P((char **));
126 static int nomru __P((void));
127 static int nopcomp __P((void));
128 static int setconnector __P((char **));
129 static int setdisconnector __P((char **));
130 static int setwelcomer __P((char **));
131 static int setmaxconnect __P((char **));
132 static int setdomain __P((char **));
133 static int setnetmask __P((char **));
134 static int setcrtscts __P((void));
135 static int setnocrtscts __P((void));
136 static int setxonxoff __P((void));
137 static int setnodetach __P((void));
138 static int setmodem __P((void));
139 static int setlocal __P((void));
140 static int setlock __P((void));
141 static int setname __P((char **));
142 static int setuser __P((char **));
143 static int setremote __P((char **));
144 static int setauth __P((void));
145 static int readfile __P((char **));
146 static int setdefaultroute __P((void));
147 static int setnodefaultroute __P((void));
148 static int setproxyarp __P((void));
149 static int setnoproxyarp __P((void));
150 static int setpersist __P((void));
151 static int setdologin __P((void));
152 static int setusehostname __P((void));
153 static int setnoipdflt __P((void));
154 static int setlcptimeout __P((char **));
155 static int setlcpterm __P((char **));
156 static int setlcpconf __P((char **));
157 static int setlcpfails __P((char **));
158 static int setipcptimeout __P((char **));
159 static int setipcpterm __P((char **));
160 static int setipcpconf __P((char **));
161 static int setipcpfails __P((char **));
162 static int setpaptimeout __P((char **));
163 static int setpapreqs __P((char **));
164 static int setpapreqtime __P((char **));
165 static int setchaptimeout __P((char **));
166 static int setchapchal __P((char **));
167 static int setchapintv __P((char **));
168 static int setipcpaccl __P((void));
169 static int setipcpaccr __P((void));
170 static int setlcpechointv __P((char **));
171 static int setlcpechofails __P((char **));
172 static int setbsdcomp __P((char **));
173 static int setnobsdcomp __P((void));
174 static int setdeflate __P((char **));
175 static int setnodeflate __P((void));
176 static int setdemand __P((void));
177 static int setpred1comp __P((void));
178 static int setnopred1comp __P((void));
179 static int setipparam __P((char **));
180 static int setpapcrypt __P((void));
181 static int setidle __P((char **));
182 static int setholdoff __P((char **));
185 static int setipxproto __P((void));
186 static int resetipxproto __P((void));
187 static int setipxanet __P((void));
188 static int setipxalcl __P((void));
189 static int setipxarmt __P((void));
190 static int setipxnetwork __P((char **));
191 static int setipxnode __P((char **));
192 static int setipxrouter __P((char **));
193 static int setipxname __P((char **));
194 static int setipxcptimeout __P((char **));
195 static int setipxcpterm __P((char **));
196 static int setipxcpconf __P((char **));
197 static int setipxcpfails __P((char **));
198 #endif /* IPX_CHANGE */
201 static int setdnsaddr __P((char **));
204 static int number_option __P((char *, u_int32_t *, int));
205 static int readable __P((int fd));
217 {"-all", 0, noopt}, /* Don't request/allow any options */
218 {"-ac", 0, noaccomp}, /* Disable Address/Control compress */
219 {"-am", 0, noasyncmap}, /* Disable asyncmap negotiation */
220 {"-as", 1, setasyncmap}, /* set the desired async map */
221 {"-d", 0, setdebug}, /* Increase debugging level */
222 {"-detach", 0, setnodetach}, /* don't fork */
223 {"-ip", 0, noip}, /* Disable IP and IPCP */
224 {"-mn", 0, nomagicnumber}, /* Disable magic number negotiation */
225 {"-mru", 0, nomru}, /* Disable mru negotiation */
226 {"-p", 0, setpassive}, /* Set passive mode */
227 {"-pc", 0, nopcomp}, /* Disable protocol field compress */
228 {"+ua", 1, setupapfile}, /* Get PAP user and password from file */
229 {"+pap", 0, reqpap}, /* Require PAP auth from peer */
230 {"-pap", 0, nopap}, /* Don't allow UPAP authentication with peer */
231 {"+chap", 0, reqchap}, /* Require CHAP authentication from peer */
232 {"-chap", 0, nochap}, /* Don't allow CHAP authentication with peer */
233 {"-vj", 0, setnovj}, /* disable VJ compression */
234 {"-vjccomp", 0, setnovjccomp}, /* disable VJ connection-ID compression */
235 {"vj-max-slots", 1, setvjslots}, /* Set maximum VJ header slots */
236 {"asyncmap", 1, setasyncmap}, /* set the desired async map */
237 {"escape", 1, setescape}, /* set chars to escape on transmission */
238 {"connect", 1, setconnector}, /* A program to set up a connection */
239 {"disconnect", 1, setdisconnector}, /* program to disconnect serial dev. */
240 {"welcome", 1, setwelcomer},/* Script to welcome client */
241 {"maxconnect", 1, setmaxconnect}, /* specify a maximum connect time */
242 {"crtscts", 0, setcrtscts}, /* set h/w flow control */
243 {"-crtscts", 0, setnocrtscts}, /* clear h/w flow control */
244 {"xonxoff", 0, setxonxoff}, /* set s/w flow control */
245 {"debug", 0, setdebug}, /* Increase debugging level */
246 {"kdebug", 1, setkdebug}, /* Enable kernel-level debugging */
247 {"domain", 1, setdomain}, /* Add given domain name to hostname*/
248 {"mru", 1, setmru}, /* Set MRU value for negotiation */
249 {"mtu", 1, setmtu}, /* Set our MTU */
250 {"netmask", 1, setnetmask}, /* set netmask */
251 {"passive", 0, setpassive}, /* Set passive mode */
252 {"silent", 0, setsilent}, /* Set silent mode */
253 {"modem", 0, setmodem}, /* Use modem control lines */
254 {"local", 0, setlocal}, /* Don't use modem control lines */
255 {"lock", 0, setlock}, /* Lock serial device (with lock file) */
256 {"name", 1, setname}, /* Set local name for authentication */
257 {"user", 1, setuser}, /* Set username for PAP auth with peer */
258 {"usehostname", 0, setusehostname}, /* Must use hostname for auth. */
259 {"remotename", 1, setremote}, /* Set remote name for authentication */
260 {"auth", 0, setauth}, /* Require authentication from peer */
261 {"file", 1, readfile}, /* Take options from a file */
262 {"defaultroute", 0, setdefaultroute}, /* Add default route */
263 {"-defaultroute", 0, setnodefaultroute}, /* disable defaultroute option */
264 {"proxyarp", 0, setproxyarp}, /* Add proxy ARP entry */
265 {"-proxyarp", 0, setnoproxyarp}, /* disable proxyarp option */
266 {"persist", 0, setpersist}, /* Keep on reopening connection after close */
267 {"demand", 0, setdemand}, /* Dial on demand */
268 {"login", 0, setdologin}, /* Use system password database for UPAP */
269 {"noipdefault", 0, setnoipdflt}, /* Don't use name for default IP adrs */
270 {"lcp-echo-failure", 1, setlcpechofails}, /* consecutive echo failures */
271 {"lcp-echo-interval", 1, setlcpechointv}, /* time for lcp echo events */
272 {"lcp-restart", 1, setlcptimeout}, /* Set timeout for LCP */
273 {"lcp-max-terminate", 1, setlcpterm}, /* Set max #xmits for term-reqs */
274 {"lcp-max-configure", 1, setlcpconf}, /* Set max #xmits for conf-reqs */
275 {"lcp-max-failure", 1, setlcpfails}, /* Set max #conf-naks for LCP */
276 {"ipcp-restart", 1, setipcptimeout}, /* Set timeout for IPCP */
277 {"ipcp-max-terminate", 1, setipcpterm}, /* Set max #xmits for term-reqs */
278 {"ipcp-max-configure", 1, setipcpconf}, /* Set max #xmits for conf-reqs */
279 {"ipcp-max-failure", 1, setipcpfails}, /* Set max #conf-naks for IPCP */
280 {"pap-restart", 1, setpaptimeout}, /* Set retransmit timeout for PAP */
281 {"pap-max-authreq", 1, setpapreqs}, /* Set max #xmits for auth-reqs */
282 {"pap-timeout", 1, setpapreqtime}, /* Set time limit for peer PAP auth. */
283 {"chap-restart", 1, setchaptimeout}, /* Set timeout for CHAP */
284 {"chap-max-challenge", 1, setchapchal}, /* Set max #xmits for challenge */
285 {"chap-interval", 1, setchapintv}, /* Set interval for rechallenge */
286 {"ipcp-accept-local", 0, setipcpaccl}, /* Accept peer's address for us */
287 {"ipcp-accept-remote", 0, setipcpaccr}, /* Accept peer's address for it */
288 {"bsdcomp", 1, setbsdcomp}, /* request BSD-Compress */
289 {"-bsdcomp", 0, setnobsdcomp}, /* don't allow BSD-Compress */
290 {"deflate", 1, setdeflate}, /* request Deflate compression */
291 {"-deflate", 0, setnodeflate}, /* don't allow Deflate compression */
292 {"predictor1", 0, setpred1comp}, /* request Predictor-1 */
293 {"-predictor1", 0, setnopred1comp}, /* don't allow Predictor-1 */
294 {"ipparam", 1, setipparam}, /* set ip script parameter */
295 {"papcrypt", 0, setpapcrypt}, /* PAP passwords encrypted */
296 {"idle", 1, setidle}, /* idle time limit (seconds) */
297 {"holdoff", 1, setholdoff}, /* set holdoff time (seconds) */
300 {"ipx-network", 1, setipxnetwork}, /* IPX network number */
301 {"ipxcp-accept-network", 0, setipxanet}, /* Accept peer netowrk */
302 {"ipx-node", 1, setipxnode}, /* IPX node number */
303 {"ipxcp-accept-local", 0, setipxalcl}, /* Accept our address */
304 {"ipxcp-accept-remote", 0, setipxarmt}, /* Accept peer's address */
305 {"ipx-routing", 1, setipxrouter}, /* IPX routing proto number */
306 {"ipx-router-name", 1, setipxname}, /* IPX router name */
307 {"ipxcp-restart", 1, setipxcptimeout}, /* Set timeout for IPXCP */
308 {"ipxcp-max-terminate", 1, setipxcpterm}, /* max #xmits for term-reqs */
309 {"ipxcp-max-configure", 1, setipxcpconf}, /* max #xmits for conf-reqs */
310 {"ipxcp-max-failure", 1, setipxcpfails}, /* max #conf-naks for IPXCP */
312 {"ipx-compression", 1, setipxcompression}, /* IPX compression number */
314 {"+ipx", 0, setipxproto}, /* Enable IPXCP (and IPX) */
315 {"-ipx", 0, resetipxproto}, /* Disable IPXCP (and IPX) */
316 #endif /* IPX_CHANGE */
319 {"idle-disconnect", 1, setidle}, /* seconds for disconnect of idle IP */
323 {"ms-dns", 1, setdnsaddr}, /* DNS address(es) for the peer's use */
330 #ifndef IMPLEMENTATION
331 #define IMPLEMENTATION ""
334 static char *usage_string = "\
335 pppd version %s patch level %d%s\n\
336 Usage: %s [ arguments ], where arguments are:\n\
337 <device> Communicate over the named device\n\
338 <speed> Set the baud rate to <speed>\n\
339 <loc>:<rem> Set the local and/or remote interface IP\n\
340 addresses. Either one may be omitted.\n\
341 asyncmap <n> Set the desired async map to hex <n>\n\
342 auth Require authentication from peer\n\
343 connect <p> Invoke shell command <p> to set up the serial line\n\
344 crtscts Use hardware RTS/CTS flow control\n\
345 defaultroute Add default route through interface\n\
346 file <f> Take options from file <f>\n\
347 modem Use modem control lines\n\
348 mru <n> Set MRU value to <n> for negotiation\n\
349 netmask <n> Set interface netmask to <n>\n\
350 See pppd(8) for more options.\n\
355 * parse_args - parse a string of arguments, from the command
356 * line or from a file.
359 parse_args(argc, argv)
372 * First see if it's a command.
374 for (cmdp = cmds; cmdp->cmd_name; cmdp++)
375 if (!strcmp(arg, cmdp->cmd_name))
378 if (cmdp->cmd_name != NULL) {
379 if (argc < cmdp->num_args) {
380 fprintf(stderr, "Too few parameters for command %s\n", arg);
383 if (!(*cmdp->cmd_func)(argv))
385 argc -= cmdp->num_args;
386 argv += cmdp->num_args;
390 * Maybe a tty name, speed or IP address?
392 if ((ret = setdevname(arg)) == 0
393 && (ret = setspeed(arg)) == 0
394 && (ret = setipaddr(arg)) == 0) {
395 fprintf(stderr, "%s: unrecognized command\n", arg);
399 if (ret < 0) /* error */
407 * usage - print out a message telling how to use the program.
412 fprintf(stderr, usage_string, VERSION, PATCHLEVEL, IMPLEMENTATION,
417 * options_from_file - Read a string of options from a file,
418 * and interpret them.
421 options_from_file(filename, must_exist, check_prot)
430 char args[MAXARGS][MAXWORDLEN];
431 char cmd[MAXWORDLEN];
433 if ((f = fopen(filename, "r")) == NULL) {
434 if (!must_exist && errno == ENOENT)
439 if (check_prot && !readable(fileno(f))) {
440 fprintf(stderr, "%s: access denied\n", filename);
445 while (getword(f, cmd, &newline, filename)) {
447 * First see if it's a command.
449 for (cmdp = cmds; cmdp->cmd_name; cmdp++)
450 if (!strcmp(cmd, cmdp->cmd_name))
453 if (cmdp->cmd_name != NULL) {
454 for (i = 0; i < cmdp->num_args; ++i) {
455 if (!getword(f, args[i], &newline, filename)) {
457 "In file %s: too few parameters for command %s\n",
464 if (!(*cmdp->cmd_func)(argv)) {
471 * Maybe a tty name, speed or IP address?
473 if ((ret = setdevname(cmd)) == 0
474 && (ret = setspeed(cmd)) == 0
475 && (ret = setipaddr(cmd)) == 0) {
476 fprintf(stderr, "In file %s: unrecognized command %s\n",
481 if (ret < 0) /* error */
489 * options_from_user - See if the use has a ~/.ppprc file,
490 * and if so, interpret options from it.
495 char *user, *path, *file;
499 pw = getpwuid(getuid());
500 if (pw == NULL || (user = pw->pw_dir) == NULL || user[0] == 0)
502 file = _PATH_USEROPT;
503 path = malloc(strlen(user) + strlen(file) + 2);
505 novm("init file name");
509 ret = options_from_file(path, 0, 1);
515 * options_for_tty - See if an options file exists for the serial
516 * device, and if so, interpret options from it.
521 char *dev, *path, *p;
525 if (strncmp(dev, "/dev/", 5) == 0)
527 if (strcmp(dev, "tty") == 0)
528 return 1; /* don't look for /etc/ppp/options.tty */
529 path = malloc(strlen(_PATH_TTYOPT) + strlen(dev) + 1);
531 novm("tty init file name");
532 strcpy(path, _PATH_TTYOPT);
533 /* Turn slashes into dots, for Solaris case (e.g. /dev/term/a) */
534 for (p = path + strlen(path); *dev != 0; ++dev)
535 *p++ = (*dev == '/'? '.': *dev);
537 ret = options_from_file(path, 0, 0);
543 * readable - check if a file is readable by the real user.
552 GIDSET_TYPE groups[NGROUPS_MAX];
557 if (fstat(fd, &sbuf) != 0)
559 if (sbuf.st_uid == uid)
560 return sbuf.st_mode & S_IRUSR;
561 if (sbuf.st_gid == getgid())
562 return sbuf.st_mode & S_IRGRP;
563 ngroups = getgroups(NGROUPS_MAX, groups);
564 for (i = 0; i < ngroups; ++i)
565 if (sbuf.st_gid == groups[i])
566 return sbuf.st_mode & S_IRGRP;
567 return sbuf.st_mode & S_IROTH;
571 * Read a word from a file.
572 * Words are delimited by white-space or by quotes (" or ').
573 * Quotes, white-space and \ may be escaped with \.
574 * \<newline> is ignored.
577 getword(f, word, newlinep, filename)
585 int value, digit, got, n;
587 #define isoctal(c) ((c) >= '0' && (c) < '8')
595 * First skip white-space and comments.
603 * A newline means the end of a comment; backslash-newline
604 * is ignored. Note that we cannot have escape && comment.
616 * Ignore characters other than newline in a comment.
622 * If this character is escaped, we have a word start.
628 * If this is the escape character, look at the next character.
636 * If this is the start of a comment, ignore the rest of the line.
644 * A non-whitespace character is the start of a word.
651 * Save the delimiter for quoted strings.
653 if (!escape && (c == '"' || c == '\'')) {
660 * Process characters until the end of the word.
665 * This character is escaped: backslash-newline is ignored,
666 * various other characters indicate particular values
667 * as for C backslash-escapes.
702 * \ddd octal sequence
705 for (n = 0; n < 3 && isoctal(c); ++n) {
706 value = (value << 3) + (c & 07);
715 * \x<hex_string> sequence
719 for (n = 0; n < 2 && isxdigit(c); ++n) {
720 digit = toupper(c) - '0';
722 digit += '0' + 10 - 'A';
723 value = (value << 4) + digit;
731 * Otherwise the character stands for itself.
738 * Store the resulting character for the escape sequence.
740 if (len < MAXWORDLEN-1)
751 * Not escaped: see if we've reached the end of the word.
757 if (isspace(c) || c == '#') {
764 * Backslash starts an escape sequence.
773 * An ordinary character: store it in the word and get another.
775 if (len < MAXWORDLEN-1)
783 * End of the word: check for errors.
793 * If len is zero, then we didn't find a word before the
801 * Warn if the word was too long, and append a terminating null.
803 if (len >= MAXWORDLEN) {
804 fprintf(stderr, "%s: warning: word in file %s too long (%.20s...)\n",
805 progname, filename, word);
806 len = MAXWORDLEN - 1;
817 * number_option - parse an unsigned numeric parameter for an option.
820 number_option(str, valp, base)
827 *valp = strtoul(str, &ptr, base);
829 fprintf(stderr, "%s: invalid number: %s\n", progname, str);
837 * int_option - like number_option, but valp is int *,
838 * the base is assumed to be 0, and *valp is not changed
839 * if there is an error.
842 int_option(str, valp)
848 if (!number_option(str, &v, 0))
856 * The following procedures execute commands.
860 * readfile - take commands from a file.
866 return options_from_file(*argv, 1, 1);
870 * setdebug - Set debug (command line argument).
880 * setkdebug - Set kernel debugging level.
886 return int_option(*argv, &kdebugflag);
890 * noopt - Disable all options.
895 BZERO((char *) &lcp_wantoptions[0], sizeof (struct lcp_options));
896 BZERO((char *) &lcp_allowoptions[0], sizeof (struct lcp_options));
897 BZERO((char *) &ipcp_wantoptions[0], sizeof (struct ipcp_options));
898 BZERO((char *) &ipcp_allowoptions[0], sizeof (struct ipcp_options));
901 BZERO((char *) &ipxcp_wantoptions[0], sizeof (struct ipxcp_options));
902 BZERO((char *) &ipxcp_allowoptions[0], sizeof (struct ipxcp_options));
903 #endif /* IPX_CHANGE */
909 * noaccomp - Disable Address/Control field compression negotiation.
914 lcp_wantoptions[0].neg_accompression = 0;
915 lcp_allowoptions[0].neg_accompression = 0;
921 * noasyncmap - Disable async map negotiation.
926 lcp_wantoptions[0].neg_asyncmap = 0;
927 lcp_allowoptions[0].neg_asyncmap = 0;
933 * noip - Disable IP and IPCP.
938 ipcp_protent.enabled_flag = 0;
944 * nomagicnumber - Disable magic number negotiation.
949 lcp_wantoptions[0].neg_magicnumber = 0;
950 lcp_allowoptions[0].neg_magicnumber = 0;
956 * nomru - Disable mru negotiation.
961 lcp_wantoptions[0].neg_mru = 0;
962 lcp_allowoptions[0].neg_mru = 0;
968 * setmru - Set MRU for negotiation.
976 if (!number_option(*argv, &mru, 0))
978 lcp_wantoptions[0].mru = mru;
979 lcp_wantoptions[0].neg_mru = 1;
985 * setmru - Set the largest MTU we'll use.
993 if (!number_option(*argv, &mtu, 0))
995 if (mtu < MINMRU || mtu > MAXMRU) {
996 fprintf(stderr, "mtu option value of %ld is too %s\n", mtu,
997 (mtu < MINMRU? "small": "large"));
1000 lcp_allowoptions[0].mru = mtu;
1006 * nopcomp - Disable Protocol field compression negotiation.
1011 lcp_wantoptions[0].neg_pcompression = 0;
1012 lcp_allowoptions[0].neg_pcompression = 0;
1018 * setpassive - Set passive mode (don't give up if we time out sending
1019 * LCP configure-requests).
1024 lcp_wantoptions[0].passive = 1;
1030 * setsilent - Set silent mode (don't start sending LCP configure-requests
1031 * until we get one from the peer).
1036 lcp_wantoptions[0].silent = 1;
1042 * nopap - Disable PAP authentication with peer.
1047 lcp_allowoptions[0].neg_upap = 0;
1053 * reqpap - Require PAP authentication from peer.
1058 lcp_wantoptions[0].neg_upap = 1;
1065 * setupapfile - specifies UPAP info for authenticating with peer.
1074 lcp_allowoptions[0].neg_upap = 1;
1076 /* open user info file */
1077 if ((ufile = fopen(*argv, "r")) == NULL) {
1078 fprintf(stderr, "unable to open user login data file %s\n", *argv);
1081 if (!readable(fileno(ufile))) {
1082 fprintf(stderr, "%s: access denied\n", *argv);
1085 check_access(ufile, *argv);
1088 if (fgets(user, MAXNAMELEN - 1, ufile) == NULL
1089 || fgets(passwd, MAXSECRETLEN - 1, ufile) == NULL){
1090 fprintf(stderr, "Unable to read user login data file %s.\n", *argv);
1095 /* get rid of newlines */
1097 if (l > 0 && user[l-1] == '\n')
1100 if (l > 0 && passwd[l-1] == '\n')
1108 * nochap - Disable CHAP authentication with peer.
1113 lcp_allowoptions[0].neg_chap = 0;
1119 * reqchap - Require CHAP authentication from peer.
1124 lcp_wantoptions[0].neg_chap = 1;
1131 * setnovj - disable vj compression
1136 ipcp_wantoptions[0].neg_vj = 0;
1137 ipcp_allowoptions[0].neg_vj = 0;
1143 * setnovjccomp - disable VJ connection-ID compression
1148 ipcp_wantoptions[0].cflag = 0;
1149 ipcp_allowoptions[0].cflag = 0;
1155 * setvjslots - set maximum number of connection slots for VJ compression
1163 if (!int_option(*argv, &value))
1165 if (value < 2 || value > 16) {
1166 fprintf(stderr, "pppd: vj-max-slots value must be between 2 and 16\n");
1169 ipcp_wantoptions [0].maxslotindex =
1170 ipcp_allowoptions[0].maxslotindex = value - 1;
1176 * setconnector - Set a program to connect to a serial line
1182 connector = strdup(*argv);
1183 if (connector == NULL)
1184 novm("connect script");
1190 * setdisconnector - Set a program to disconnect from the serial line
1193 setdisconnector(argv)
1196 disconnector = strdup(*argv);
1197 if (disconnector == NULL)
1198 novm("disconnect script");
1204 * setwelcomer - Set a program to welcome a client after connection
1210 welcomer = strdup(*argv);
1211 if (welcomer == NULL)
1212 novm("welcome script");
1218 * setmaxconnect - Set the maximum connect time
1226 if (!int_option(*argv, &value))
1229 fprintf(stderr, "pppd: maxconnect time must be positive\n");
1237 * setdomain - Set domain name to append to hostname
1243 gethostname(hostname, MAXNAMELEN);
1246 strncat(hostname, ".", MAXNAMELEN - strlen(hostname));
1247 strncat(hostname, *argv, MAXNAMELEN - strlen(hostname));
1249 hostname[MAXNAMELEN-1] = 0;
1255 * setasyncmap - add bits to asyncmap (what we request peer to escape).
1263 if (!number_option(*argv, &asyncmap, 16))
1265 lcp_wantoptions[0].asyncmap |= asyncmap;
1266 lcp_wantoptions[0].neg_asyncmap = 1;
1272 * setescape - add chars to the set we escape on transmission.
1284 n = strtol(p, &endp, 16);
1286 fprintf(stderr, "%s: invalid hex number: %s\n", progname, p);
1290 if (n < 0 || 0x20 <= n && n <= 0x3F || n == 0x5E || n > 0xFF) {
1291 fprintf(stderr, "%s: can't escape character 0x%x\n", progname, n);
1294 xmit_accm[0][n >> 5] |= 1 << (n & 0x1F);
1295 while (*p == ',' || *p == ' ')
1303 * setspeed - Set the speed.
1312 spd = strtol(arg, &ptr, 0);
1313 if (ptr == arg || *ptr != 0 || spd == 0)
1321 * setdevname - Set the device name.
1327 struct stat statbuf;
1328 char *tty, *ttyname();
1329 char dev[MAXPATHLEN];
1331 if (strncmp("/dev/", cp, 5) != 0) {
1332 strcpy(dev, "/dev/");
1333 strncat(dev, cp, MAXPATHLEN - 5);
1334 dev[MAXPATHLEN-1] = 0;
1339 * Check if there is a device by this name.
1341 if (stat(cp, &statbuf) < 0) {
1342 if (errno == ENOENT)
1344 syslog(LOG_ERR, cp);
1348 (void) strncpy(devnam, cp, MAXPATHLEN);
1349 devnam[MAXPATHLEN-1] = 0;
1350 default_device = FALSE;
1357 * setipaddr - Set the IP address
1365 u_int32_t local, remote;
1366 ipcp_options *wo = &ipcp_wantoptions[0];
1369 * IP address pair separated by ":".
1371 if ((colon = strchr(arg, ':')) == NULL)
1375 * If colon first character, then no local addr.
1379 if ((local = inet_addr(arg)) == -1) {
1380 if ((hp = gethostbyname(arg)) == NULL) {
1381 fprintf(stderr, "unknown host: %s\n", arg);
1384 local = *(u_int32_t *)hp->h_addr;
1385 if (our_name[0] == 0) {
1386 strncpy(our_name, arg, MAXNAMELEN);
1387 our_name[MAXNAMELEN-1] = 0;
1391 if (bad_ip_adrs(local)) {
1392 fprintf(stderr, "bad local IP address %s\n", ip_ntoa(local));
1396 wo->ouraddr = local;
1401 * If colon last character, then no remote addr.
1403 if (*++colon != '\0') {
1404 if ((remote = inet_addr(colon)) == -1) {
1405 if ((hp = gethostbyname(colon)) == NULL) {
1406 fprintf(stderr, "unknown host: %s\n", colon);
1409 remote = *(u_int32_t *)hp->h_addr;
1410 if (remote_name[0] == 0) {
1411 strncpy(remote_name, colon, MAXNAMELEN);
1412 remote_name[MAXNAMELEN-1] = 0;
1416 if (bad_ip_adrs(remote)) {
1417 fprintf(stderr, "bad remote IP address %s\n", ip_ntoa(remote));
1421 wo->hisaddr = remote;
1429 * setnoipdflt - disable setipdefault()
1434 disable_defaultip = 1;
1440 * setipcpaccl - accept peer's idea of our address
1445 ipcp_wantoptions[0].accept_local = 1;
1451 * setipcpaccr - accept peer's idea of its address
1456 ipcp_wantoptions[0].accept_remote = 1;
1462 * setnetmask - set the netmask to be used on the interface.
1470 if ((mask = inet_addr(*argv)) == -1 || (netmask & ~mask) != 0) {
1471 fprintf(stderr, "Invalid netmask %s\n", *argv);
1496 lcp_wantoptions[0].asyncmap |= 0x000A0000; /* escape ^S and ^Q */
1497 lcp_wantoptions[0].neg_asyncmap = 1;
1549 if (our_name[0] == 0) {
1550 strncpy(our_name, argv[0], MAXNAMELEN);
1551 our_name[MAXNAMELEN-1] = 0;
1560 strncpy(user, argv[0], MAXNAMELEN);
1561 user[MAXNAMELEN-1] = 0;
1569 strncpy(remote_name, argv[0], MAXNAMELEN);
1570 remote_name[MAXNAMELEN-1] = 0;
1584 if (!ipcp_allowoptions[0].default_route) {
1585 fprintf(stderr, "%s: defaultroute option is disabled\n", progname);
1588 ipcp_wantoptions[0].default_route = 1;
1595 ipcp_allowoptions[0].default_route = 0;
1596 ipcp_wantoptions[0].default_route = 0;
1603 if (!ipcp_allowoptions[0].proxy_arp) {
1604 fprintf(stderr, "%s: proxyarp option is disabled\n", progname);
1607 ipcp_wantoptions[0].proxy_arp = 1;
1614 ipcp_wantoptions[0].proxy_arp = 0;
1615 ipcp_allowoptions[0].proxy_arp = 0;
1634 * Functions to set the echo interval for modem-less monitors
1638 setlcpechointv(argv)
1641 return int_option(*argv, &lcp_echo_interval);
1645 setlcpechofails(argv)
1648 return int_option(*argv, &lcp_echo_fails);
1652 * Functions to set timeouts, max transmits, etc.
1658 return int_option(*argv, &lcp_fsm[0].timeouttime);
1665 return int_option(*argv, &lcp_fsm[0].maxtermtransmits);
1672 return int_option(*argv, &lcp_fsm[0].maxconfreqtransmits);
1679 return int_option(*argv, &lcp_fsm[0].maxnakloops);
1683 setipcptimeout(argv)
1686 return int_option(*argv, &ipcp_fsm[0].timeouttime);
1693 return int_option(*argv, &ipcp_fsm[0].maxtermtransmits);
1700 return int_option(*argv, &ipcp_fsm[0].maxconfreqtransmits);
1707 return int_option(*argv, &lcp_fsm[0].maxnakloops);
1714 return int_option(*argv, &upap[0].us_timeouttime);
1721 return int_option(*argv, &upap[0].us_reqtimeout);
1728 return int_option(*argv, &upap[0].us_maxtransmits);
1732 setchaptimeout(argv)
1735 return int_option(*argv, &chap[0].timeouttime);
1742 return int_option(*argv, &chap[0].max_transmits);
1749 return int_option(*argv, &chap[0].chal_interval);
1760 abits = rbits = strtol(str, &endp, 0);
1761 if (endp != str && *endp == ',') {
1763 abits = strtol(str, &endp, 0);
1765 if (*endp != 0 || endp == str) {
1766 fprintf(stderr, "%s: invalid argument format for bsdcomp option\n",
1770 if (rbits != 0 && (rbits < BSD_MIN_BITS || rbits > BSD_MAX_BITS)
1771 || abits != 0 && (abits < BSD_MIN_BITS || abits > BSD_MAX_BITS)) {
1772 fprintf(stderr, "%s: bsdcomp option values must be 0 or %d .. %d\n",
1773 progname, BSD_MIN_BITS, BSD_MAX_BITS);
1777 ccp_wantoptions[0].bsd_compress = 1;
1778 ccp_wantoptions[0].bsd_bits = rbits;
1780 ccp_wantoptions[0].bsd_compress = 0;
1782 ccp_allowoptions[0].bsd_compress = 1;
1783 ccp_allowoptions[0].bsd_bits = abits;
1785 ccp_allowoptions[0].bsd_compress = 0;
1792 ccp_wantoptions[0].bsd_compress = 0;
1793 ccp_allowoptions[0].bsd_compress = 0;
1805 abits = rbits = strtol(str, &endp, 0);
1806 if (endp != str && *endp == ',') {
1808 abits = strtol(str, &endp, 0);
1810 if (*endp != 0 || endp == str) {
1811 fprintf(stderr, "%s: invalid argument format for deflate option\n",
1815 if (rbits != 0 && (rbits < DEFLATE_MIN_SIZE || rbits > DEFLATE_MAX_SIZE)
1816 || abits != 0 && (abits < DEFLATE_MIN_SIZE
1817 || abits > DEFLATE_MAX_SIZE)) {
1818 fprintf(stderr, "%s: deflate option values must be 0 or %d .. %d\n",
1819 progname, DEFLATE_MIN_SIZE, DEFLATE_MAX_SIZE);
1823 ccp_wantoptions[0].deflate = 1;
1824 ccp_wantoptions[0].deflate_size = rbits;
1826 ccp_wantoptions[0].deflate = 0;
1828 ccp_allowoptions[0].deflate = 1;
1829 ccp_allowoptions[0].deflate_size = abits;
1831 ccp_allowoptions[0].deflate = 0;
1838 ccp_wantoptions[0].deflate = 0;
1839 ccp_allowoptions[0].deflate = 0;
1846 ccp_wantoptions[0].predictor_1 = 1;
1847 ccp_allowoptions[0].predictor_1 = 1;
1854 ccp_wantoptions[0].predictor_1 = 0;
1855 ccp_allowoptions[0].predictor_1 = 0;
1863 ipparam = strdup(*argv);
1864 if (ipparam == NULL)
1865 novm("ipparam string");
1881 return int_option(*argv, &idle_time_limit);
1888 return int_option(*argv, &holdoff);
1896 ipxcp_wantoptions[0].neg_router = 1;
1897 ipxcp_allowoptions[0].neg_router = 1;
1898 return int_option(*argv, &ipxcp_wantoptions[0].router);
1905 char *dest = ipxcp_wantoptions[0].name;
1910 ipxcp_wantoptions[0].neg_name = 1;
1911 ipxcp_allowoptions[0].neg_name = 1;
1912 memset (dest, '\0', sizeof (ipxcp_wantoptions[0].name));
1917 if (! isalnum (ch) && ch != '_') {
1919 "%s: IPX router name must be alphanumeric or _\n",
1924 if (count >= sizeof (ipxcp_wantoptions[0].name)) {
1926 "%s: IPX router name is limited to %d characters\n",
1928 sizeof (ipxcp_wantoptions[0].name) - 1);
1932 dest[count++] = toupper (ch);
1939 setipxcptimeout (argv)
1942 return int_option(*argv, &ipxcp_fsm[0].timeouttime);
1949 return int_option(*argv, &ipxcp_fsm[0].maxtermtransmits);
1956 return int_option(*argv, &ipxcp_fsm[0].maxconfreqtransmits);
1960 setipxcpfails (argv)
1963 return int_option(*argv, &ipxcp_fsm[0].maxnakloops);
1970 ipxcp_wantoptions[0].neg_nn = 1;
1971 return int_option(*argv, &ipxcp_wantoptions[0].our_network);
1977 ipxcp_wantoptions[0].accept_network = 1;
1978 ipxcp_allowoptions[0].accept_network = 1;
1984 ipxcp_wantoptions[0].accept_local = 1;
1985 ipxcp_allowoptions[0].accept_local = 1;
1991 ipxcp_wantoptions[0].accept_remote = 1;
1992 ipxcp_allowoptions[0].accept_remote = 1;
1996 setipxnodevalue(src,dst)
2003 if (!isxdigit (*src))
2006 for (indx = 0; indx < 5; ++indx) {
2008 dst[indx] |= (dst[indx + 1] >> 4) & 0x0F;
2011 item = toupper (*src) - '0';
2015 dst[5] = (dst[5] << 4) | item;
2027 memset (&ipxcp_wantoptions[0].our_node[0], 0, 6);
2028 memset (&ipxcp_wantoptions[0].his_node[0], 0, 6);
2030 end = setipxnodevalue (*argv, &ipxcp_wantoptions[0].our_node[0]);
2032 end = setipxnodevalue (++end, &ipxcp_wantoptions[0].his_node[0]);
2035 ipxcp_wantoptions[0].neg_node = 1;
2039 fprintf(stderr, "%s: invalid argument for ipx-node option\n",
2047 ipx_enabled = 1; /* Enable IPXCP and IPX protocol */
2054 ipx_enabled = 0; /* Disable IPXCP and IPX protocol */
2057 #endif /* IPX_CHANGE */
2061 * setdnsaddr - set the dns address(es)
2071 dns = inet_addr(*argv);
2073 if ((hp = gethostbyname(*argv)) == NULL) {
2074 fprintf(stderr, "Invalid DNS Address %s\n", *argv);
2077 dns = *(u_int32_t *)hp->h_addr;
2080 if (ipcp_allowoptions[0].dnsaddr[0] == 0) {
2081 ipcp_allowoptions[0].dnsaddr[0] = dns;
2083 ipcp_allowoptions[0].dnsaddr[1] = dns;
2088 #endif /* USE_MS_DNS */