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.28 1996/01/18 03:22:22 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.
524 dev = strrchr(devnam, '/');
529 if (strcmp(dev, "tty") == 0)
530 return 1; /* don't look for /etc/ppp/options.tty */
531 path = malloc(strlen(_PATH_TTYOPT) + strlen(dev) + 1);
533 novm("tty init file name");
534 strcpy(path, _PATH_TTYOPT);
536 ret = options_from_file(path, 0, 0);
542 * readable - check if a file is readable by the real user.
551 GIDSET_TYPE groups[NGROUPS_MAX];
556 if (fstat(fd, &sbuf) != 0)
558 if (sbuf.st_uid == uid)
559 return sbuf.st_mode & S_IRUSR;
560 if (sbuf.st_gid == getgid())
561 return sbuf.st_mode & S_IRGRP;
562 ngroups = getgroups(NGROUPS_MAX, groups);
563 for (i = 0; i < ngroups; ++i)
564 if (sbuf.st_gid == groups[i])
565 return sbuf.st_mode & S_IRGRP;
566 return sbuf.st_mode & S_IROTH;
570 * Read a word from a file.
571 * Words are delimited by white-space or by quotes (" or ').
572 * Quotes, white-space and \ may be escaped with \.
573 * \<newline> is ignored.
576 getword(f, word, newlinep, filename)
584 int value, digit, got, n;
586 #define isoctal(c) ((c) >= '0' && (c) < '8')
594 * First skip white-space and comments.
602 * A newline means the end of a comment; backslash-newline
603 * is ignored. Note that we cannot have escape && comment.
615 * Ignore characters other than newline in a comment.
621 * If this character is escaped, we have a word start.
627 * If this is the escape character, look at the next character.
635 * If this is the start of a comment, ignore the rest of the line.
643 * A non-whitespace character is the start of a word.
650 * Save the delimiter for quoted strings.
652 if (!escape && (c == '"' || c == '\'')) {
659 * Process characters until the end of the word.
664 * This character is escaped: backslash-newline is ignored,
665 * various other characters indicate particular values
666 * as for C backslash-escapes.
701 * \ddd octal sequence
704 for (n = 0; n < 3 && isoctal(c); ++n) {
705 value = (value << 3) + (c & 07);
714 * \x<hex_string> sequence
718 for (n = 0; n < 2 && isxdigit(c); ++n) {
719 digit = toupper(c) - '0';
721 digit += '0' + 10 - 'A';
722 value = (value << 4) + digit;
730 * Otherwise the character stands for itself.
737 * Store the resulting character for the escape sequence.
739 if (len < MAXWORDLEN-1)
750 * Not escaped: see if we've reached the end of the word.
756 if (isspace(c) || c == '#') {
763 * Backslash starts an escape sequence.
772 * An ordinary character: store it in the word and get another.
774 if (len < MAXWORDLEN-1)
782 * End of the word: check for errors.
792 * If len is zero, then we didn't find a word before the
800 * Warn if the word was too long, and append a terminating null.
802 if (len >= MAXWORDLEN) {
803 fprintf(stderr, "%s: warning: word in file %s too long (%.20s...)\n",
804 progname, filename, word);
805 len = MAXWORDLEN - 1;
816 * number_option - parse an unsigned numeric parameter for an option.
819 number_option(str, valp, base)
826 *valp = strtoul(str, &ptr, base);
828 fprintf(stderr, "%s: invalid number: %s\n", progname, str);
836 * int_option - like number_option, but valp is int *,
837 * the base is assumed to be 0, and *valp is not changed
838 * if there is an error.
841 int_option(str, valp)
847 if (!number_option(str, &v, 0))
855 * The following procedures execute commands.
859 * readfile - take commands from a file.
865 return options_from_file(*argv, 1, 1);
869 * setdebug - Set debug (command line argument).
879 * setkdebug - Set kernel debugging level.
885 return int_option(*argv, &kdebugflag);
889 * noopt - Disable all options.
894 BZERO((char *) &lcp_wantoptions[0], sizeof (struct lcp_options));
895 BZERO((char *) &lcp_allowoptions[0], sizeof (struct lcp_options));
896 BZERO((char *) &ipcp_wantoptions[0], sizeof (struct ipcp_options));
897 BZERO((char *) &ipcp_allowoptions[0], sizeof (struct ipcp_options));
900 BZERO((char *) &ipxcp_wantoptions[0], sizeof (struct ipxcp_options));
901 BZERO((char *) &ipxcp_allowoptions[0], sizeof (struct ipxcp_options));
902 #endif /* IPX_CHANGE */
908 * noaccomp - Disable Address/Control field compression negotiation.
913 lcp_wantoptions[0].neg_accompression = 0;
914 lcp_allowoptions[0].neg_accompression = 0;
920 * noasyncmap - Disable async map negotiation.
925 lcp_wantoptions[0].neg_asyncmap = 0;
926 lcp_allowoptions[0].neg_asyncmap = 0;
932 * noip - Disable IP and IPCP.
937 ipcp_protent.enabled_flag = 0;
943 * nomagicnumber - Disable magic number negotiation.
948 lcp_wantoptions[0].neg_magicnumber = 0;
949 lcp_allowoptions[0].neg_magicnumber = 0;
955 * nomru - Disable mru negotiation.
960 lcp_wantoptions[0].neg_mru = 0;
961 lcp_allowoptions[0].neg_mru = 0;
967 * setmru - Set MRU for negotiation.
975 if (!number_option(*argv, &mru, 0))
977 lcp_wantoptions[0].mru = mru;
978 lcp_wantoptions[0].neg_mru = 1;
984 * setmru - Set the largest MTU we'll use.
992 if (!number_option(*argv, &mtu, 0))
994 if (mtu < MINMRU || mtu > MAXMRU) {
995 fprintf(stderr, "mtu option value of %ld is too %s\n", mtu,
996 (mtu < MINMRU? "small": "large"));
999 lcp_allowoptions[0].mru = mtu;
1005 * nopcomp - Disable Protocol field compression negotiation.
1010 lcp_wantoptions[0].neg_pcompression = 0;
1011 lcp_allowoptions[0].neg_pcompression = 0;
1017 * setpassive - Set passive mode (don't give up if we time out sending
1018 * LCP configure-requests).
1023 lcp_wantoptions[0].passive = 1;
1029 * setsilent - Set silent mode (don't start sending LCP configure-requests
1030 * until we get one from the peer).
1035 lcp_wantoptions[0].silent = 1;
1041 * nopap - Disable PAP authentication with peer.
1046 lcp_allowoptions[0].neg_upap = 0;
1052 * reqpap - Require PAP authentication from peer.
1057 lcp_wantoptions[0].neg_upap = 1;
1064 * setupapfile - specifies UPAP info for authenticating with peer.
1073 lcp_allowoptions[0].neg_upap = 1;
1075 /* open user info file */
1076 if ((ufile = fopen(*argv, "r")) == NULL) {
1077 fprintf(stderr, "unable to open user login data file %s\n", *argv);
1080 if (!readable(fileno(ufile))) {
1081 fprintf(stderr, "%s: access denied\n", *argv);
1084 check_access(ufile, *argv);
1087 if (fgets(user, MAXNAMELEN - 1, ufile) == NULL
1088 || fgets(passwd, MAXSECRETLEN - 1, ufile) == NULL){
1089 fprintf(stderr, "Unable to read user login data file %s.\n", *argv);
1094 /* get rid of newlines */
1096 if (l > 0 && user[l-1] == '\n')
1099 if (l > 0 && passwd[l-1] == '\n')
1107 * nochap - Disable CHAP authentication with peer.
1112 lcp_allowoptions[0].neg_chap = 0;
1118 * reqchap - Require CHAP authentication from peer.
1123 lcp_wantoptions[0].neg_chap = 1;
1130 * setnovj - disable vj compression
1135 ipcp_wantoptions[0].neg_vj = 0;
1136 ipcp_allowoptions[0].neg_vj = 0;
1142 * setnovjccomp - disable VJ connection-ID compression
1147 ipcp_wantoptions[0].cflag = 0;
1148 ipcp_allowoptions[0].cflag = 0;
1154 * setvjslots - set maximum number of connection slots for VJ compression
1162 if (!int_option(*argv, &value))
1164 if (value < 2 || value > 16) {
1165 fprintf(stderr, "pppd: vj-max-slots value must be between 2 and 16\n");
1168 ipcp_wantoptions [0].maxslotindex =
1169 ipcp_allowoptions[0].maxslotindex = value - 1;
1175 * setconnector - Set a program to connect to a serial line
1181 connector = strdup(*argv);
1182 if (connector == NULL)
1183 novm("connect script");
1189 * setdisconnector - Set a program to disconnect from the serial line
1192 setdisconnector(argv)
1195 disconnector = strdup(*argv);
1196 if (disconnector == NULL)
1197 novm("disconnect script");
1203 * setwelcomer - Set a program to welcome a client after connection
1209 welcomer = strdup(*argv);
1210 if (welcomer == NULL)
1211 novm("welcome script");
1217 * setmaxconnect - Set the maximum connect time
1225 if (!int_option(*argv, &value))
1228 fprintf(stderr, "pppd: maxconnect time must be positive\n");
1236 * setdomain - Set domain name to append to hostname
1242 gethostname(hostname, MAXNAMELEN);
1245 strncat(hostname, ".", MAXNAMELEN - strlen(hostname));
1246 strncat(hostname, *argv, MAXNAMELEN - strlen(hostname));
1248 hostname[MAXNAMELEN-1] = 0;
1254 * setasyncmap - add bits to asyncmap (what we request peer to escape).
1262 if (!number_option(*argv, &asyncmap, 16))
1264 lcp_wantoptions[0].asyncmap |= asyncmap;
1265 lcp_wantoptions[0].neg_asyncmap = 1;
1271 * setescape - add chars to the set we escape on transmission.
1283 n = strtol(p, &endp, 16);
1285 fprintf(stderr, "%s: invalid hex number: %s\n", progname, p);
1289 if (n < 0 || 0x20 <= n && n <= 0x3F || n == 0x5E || n > 0xFF) {
1290 fprintf(stderr, "%s: can't escape character 0x%x\n", progname, n);
1293 xmit_accm[0][n >> 5] |= 1 << (n & 0x1F);
1294 while (*p == ',' || *p == ' ')
1302 * setspeed - Set the speed.
1311 spd = strtol(arg, &ptr, 0);
1312 if (ptr == arg || *ptr != 0 || spd == 0)
1320 * setdevname - Set the device name.
1326 struct stat statbuf;
1327 char *tty, *ttyname();
1328 char dev[MAXPATHLEN];
1330 if (strncmp("/dev/", cp, 5) != 0) {
1331 strcpy(dev, "/dev/");
1332 strncat(dev, cp, MAXPATHLEN - 5);
1333 dev[MAXPATHLEN-1] = 0;
1338 * Check if there is a device by this name.
1340 if (stat(cp, &statbuf) < 0) {
1341 if (errno == ENOENT)
1343 syslog(LOG_ERR, cp);
1347 (void) strncpy(devnam, cp, MAXPATHLEN);
1348 devnam[MAXPATHLEN-1] = 0;
1349 default_device = FALSE;
1356 * setipaddr - Set the IP address
1364 u_int32_t local, remote;
1365 ipcp_options *wo = &ipcp_wantoptions[0];
1368 * IP address pair separated by ":".
1370 if ((colon = strchr(arg, ':')) == NULL)
1374 * If colon first character, then no local addr.
1378 if ((local = inet_addr(arg)) == -1) {
1379 if ((hp = gethostbyname(arg)) == NULL) {
1380 fprintf(stderr, "unknown host: %s\n", arg);
1383 local = *(u_int32_t *)hp->h_addr;
1384 if (our_name[0] == 0) {
1385 strncpy(our_name, arg, MAXNAMELEN);
1386 our_name[MAXNAMELEN-1] = 0;
1390 if (bad_ip_adrs(local)) {
1391 fprintf(stderr, "bad local IP address %s\n", ip_ntoa(local));
1395 wo->ouraddr = local;
1400 * If colon last character, then no remote addr.
1402 if (*++colon != '\0') {
1403 if ((remote = inet_addr(colon)) == -1) {
1404 if ((hp = gethostbyname(colon)) == NULL) {
1405 fprintf(stderr, "unknown host: %s\n", colon);
1408 remote = *(u_int32_t *)hp->h_addr;
1409 if (remote_name[0] == 0) {
1410 strncpy(remote_name, colon, MAXNAMELEN);
1411 remote_name[MAXNAMELEN-1] = 0;
1415 if (bad_ip_adrs(remote)) {
1416 fprintf(stderr, "bad remote IP address %s\n", ip_ntoa(remote));
1420 wo->hisaddr = remote;
1428 * setnoipdflt - disable setipdefault()
1433 disable_defaultip = 1;
1439 * setipcpaccl - accept peer's idea of our address
1444 ipcp_wantoptions[0].accept_local = 1;
1450 * setipcpaccr - accept peer's idea of its address
1455 ipcp_wantoptions[0].accept_remote = 1;
1461 * setnetmask - set the netmask to be used on the interface.
1469 if ((mask = inet_addr(*argv)) == -1 || (netmask & ~mask) != 0) {
1470 fprintf(stderr, "Invalid netmask %s\n", *argv);
1495 lcp_wantoptions[0].asyncmap |= 0x000A0000; /* escape ^S and ^Q */
1496 lcp_wantoptions[0].neg_asyncmap = 1;
1548 if (our_name[0] == 0) {
1549 strncpy(our_name, argv[0], MAXNAMELEN);
1550 our_name[MAXNAMELEN-1] = 0;
1559 strncpy(user, argv[0], MAXNAMELEN);
1560 user[MAXNAMELEN-1] = 0;
1568 strncpy(remote_name, argv[0], MAXNAMELEN);
1569 remote_name[MAXNAMELEN-1] = 0;
1583 if (!ipcp_allowoptions[0].default_route) {
1584 fprintf(stderr, "%s: defaultroute option is disabled\n", progname);
1587 ipcp_wantoptions[0].default_route = 1;
1594 ipcp_allowoptions[0].default_route = 0;
1595 ipcp_wantoptions[0].default_route = 0;
1602 if (!ipcp_allowoptions[0].proxy_arp) {
1603 fprintf(stderr, "%s: proxyarp option is disabled\n", progname);
1606 ipcp_wantoptions[0].proxy_arp = 1;
1613 ipcp_wantoptions[0].proxy_arp = 0;
1614 ipcp_allowoptions[0].proxy_arp = 0;
1633 * Functions to set the echo interval for modem-less monitors
1637 setlcpechointv(argv)
1640 return int_option(*argv, &lcp_echo_interval);
1644 setlcpechofails(argv)
1647 return int_option(*argv, &lcp_echo_fails);
1651 * Functions to set timeouts, max transmits, etc.
1657 return int_option(*argv, &lcp_fsm[0].timeouttime);
1664 return int_option(*argv, &lcp_fsm[0].maxtermtransmits);
1671 return int_option(*argv, &lcp_fsm[0].maxconfreqtransmits);
1678 return int_option(*argv, &lcp_fsm[0].maxnakloops);
1682 setipcptimeout(argv)
1685 return int_option(*argv, &ipcp_fsm[0].timeouttime);
1692 return int_option(*argv, &ipcp_fsm[0].maxtermtransmits);
1699 return int_option(*argv, &ipcp_fsm[0].maxconfreqtransmits);
1706 return int_option(*argv, &lcp_fsm[0].maxnakloops);
1713 return int_option(*argv, &upap[0].us_timeouttime);
1720 return int_option(*argv, &upap[0].us_reqtimeout);
1727 return int_option(*argv, &upap[0].us_maxtransmits);
1731 setchaptimeout(argv)
1734 return int_option(*argv, &chap[0].timeouttime);
1741 return int_option(*argv, &chap[0].max_transmits);
1748 return int_option(*argv, &chap[0].chal_interval);
1759 abits = rbits = strtol(str, &endp, 0);
1760 if (endp != str && *endp == ',') {
1762 abits = strtol(str, &endp, 0);
1764 if (*endp != 0 || endp == str) {
1765 fprintf(stderr, "%s: invalid argument format for bsdcomp option\n",
1769 if (rbits != 0 && (rbits < BSD_MIN_BITS || rbits > BSD_MAX_BITS)
1770 || abits != 0 && (abits < BSD_MIN_BITS || abits > BSD_MAX_BITS)) {
1771 fprintf(stderr, "%s: bsdcomp option values must be 0 or %d .. %d\n",
1772 progname, BSD_MIN_BITS, BSD_MAX_BITS);
1776 ccp_wantoptions[0].bsd_compress = 1;
1777 ccp_wantoptions[0].bsd_bits = rbits;
1779 ccp_wantoptions[0].bsd_compress = 0;
1781 ccp_allowoptions[0].bsd_compress = 1;
1782 ccp_allowoptions[0].bsd_bits = abits;
1784 ccp_allowoptions[0].bsd_compress = 0;
1791 ccp_wantoptions[0].bsd_compress = 0;
1792 ccp_allowoptions[0].bsd_compress = 0;
1804 abits = rbits = strtol(str, &endp, 0);
1805 if (endp != str && *endp == ',') {
1807 abits = strtol(str, &endp, 0);
1809 if (*endp != 0 || endp == str) {
1810 fprintf(stderr, "%s: invalid argument format for deflate option\n",
1814 if (rbits != 0 && (rbits < DEFLATE_MIN_SIZE || rbits > DEFLATE_MAX_SIZE)
1815 || abits != 0 && (abits < DEFLATE_MIN_SIZE
1816 || abits > DEFLATE_MAX_SIZE)) {
1817 fprintf(stderr, "%s: deflate option values must be 0 or %d .. %d\n",
1818 progname, DEFLATE_MIN_SIZE, DEFLATE_MAX_SIZE);
1822 ccp_wantoptions[0].deflate = 1;
1823 ccp_wantoptions[0].deflate_size = rbits;
1825 ccp_wantoptions[0].deflate = 0;
1827 ccp_allowoptions[0].deflate = 1;
1828 ccp_allowoptions[0].deflate_size = abits;
1830 ccp_allowoptions[0].deflate = 0;
1837 ccp_wantoptions[0].deflate = 0;
1838 ccp_allowoptions[0].deflate = 0;
1845 ccp_wantoptions[0].predictor_1 = 1;
1846 ccp_allowoptions[0].predictor_1 = 1;
1853 ccp_wantoptions[0].predictor_1 = 0;
1854 ccp_allowoptions[0].predictor_1 = 0;
1862 ipparam = strdup(*argv);
1863 if (ipparam == NULL)
1864 novm("ipparam string");
1880 return int_option(*argv, &idle_time_limit);
1887 return int_option(*argv, &holdoff);
1895 ipxcp_wantoptions[0].neg_router = 1;
1896 ipxcp_allowoptions[0].neg_router = 1;
1897 return int_option(*argv, &ipxcp_wantoptions[0].router);
1904 char *dest = ipxcp_wantoptions[0].name;
1909 ipxcp_wantoptions[0].neg_name = 1;
1910 ipxcp_allowoptions[0].neg_name = 1;
1911 memset (dest, '\0', sizeof (ipxcp_wantoptions[0].name));
1916 if (! isalnum (ch) && ch != '_') {
1918 "%s: IPX router name must be alphanumeric or _\n",
1923 if (count >= sizeof (ipxcp_wantoptions[0].name)) {
1925 "%s: IPX router name is limited to %d characters\n",
1927 sizeof (ipxcp_wantoptions[0].name) - 1);
1931 dest[count++] = toupper (ch);
1938 setipxcptimeout (argv)
1941 return int_option(*argv, &ipxcp_fsm[0].timeouttime);
1948 return int_option(*argv, &ipxcp_fsm[0].maxtermtransmits);
1955 return int_option(*argv, &ipxcp_fsm[0].maxconfreqtransmits);
1959 setipxcpfails (argv)
1962 return int_option(*argv, &ipxcp_fsm[0].maxnakloops);
1969 ipxcp_wantoptions[0].neg_nn = 1;
1970 return int_option(*argv, &ipxcp_wantoptions[0].our_network);
1976 ipxcp_wantoptions[0].accept_network = 1;
1977 ipxcp_allowoptions[0].accept_network = 1;
1983 ipxcp_wantoptions[0].accept_local = 1;
1984 ipxcp_allowoptions[0].accept_local = 1;
1990 ipxcp_wantoptions[0].accept_remote = 1;
1991 ipxcp_allowoptions[0].accept_remote = 1;
1995 setipxnodevalue(src,dst)
2002 if (!isxdigit (*src))
2005 for (indx = 0; indx < 5; ++indx) {
2007 dst[indx] |= (dst[indx + 1] >> 4) & 0x0F;
2010 item = toupper (*src) - '0';
2014 dst[5] = (dst[5] << 4) | item;
2026 memset (&ipxcp_wantoptions[0].our_node[0], 0, 6);
2027 memset (&ipxcp_wantoptions[0].his_node[0], 0, 6);
2029 end = setipxnodevalue (*argv, &ipxcp_wantoptions[0].our_node[0]);
2031 end = setipxnodevalue (++end, &ipxcp_wantoptions[0].his_node[0]);
2034 ipxcp_wantoptions[0].neg_node = 1;
2038 fprintf(stderr, "%s: invalid argument for ipx-node option\n",
2046 ipx_enabled = 1; /* Enable IPXCP and IPX protocol */
2053 ipx_enabled = 0; /* Disable IPXCP and IPX protocol */
2056 #endif /* IPX_CHANGE */
2060 * setdnsaddr - set the dns address(es)
2070 dns = inet_addr(*argv);
2072 if ((hp = gethostbyname(*argv)) == NULL) {
2073 fprintf(stderr, "Invalid DNS Address %s\n", *argv);
2076 dns = *(u_int32_t *)hp->h_addr;
2079 if (ipcp_allowoptions[0].dnsaddr[0] == 0) {
2080 ipcp_allowoptions[0].dnsaddr[0] = dns;
2082 ipcp_allowoptions[0].dnsaddr[1] = dns;
2087 #endif /* USE_MS_DNS */