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.26 1995/12/18 03:49:06 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 int maxconnect = 0; /* Maximum connect time */
81 char user[MAXNAMELEN]; /* Username for PAP */
82 char passwd[MAXSECRETLEN]; /* Password for PAP */
83 int auth_required = 0; /* Peer is required to authenticate */
84 int defaultroute = 0; /* assign default route through interface */
85 int proxyarp = 0; /* Set up proxy ARP entry for peer */
86 int persist = 0; /* Reopen link after it goes down */
87 int uselogin = 0; /* Use /etc/passwd for checking PAP */
88 int lcp_echo_interval = 0; /* Interval between LCP echo-requests */
89 int lcp_echo_fails = 0; /* Tolerance to unanswered echo-requests */
90 char our_name[MAXNAMELEN]; /* Our name for authentication purposes */
91 char remote_name[MAXNAMELEN]; /* Peer's name for authentication */
92 int usehostname = 0; /* Use hostname for our_name */
93 int disable_defaultip = 0; /* Don't use hostname for default IP adrs */
94 char *ipparam = NULL; /* Extra parameter for ip up/down scripts */
95 int cryptpap; /* Passwords in pap-secrets are encrypted */
98 int idle_time_limit = 0;
99 static int setidle __P((char **));
105 static int setdebug __P((void));
106 static int setkdebug __P((char **));
107 static int setpassive __P((void));
108 static int setsilent __P((void));
109 static int noopt __P((void));
110 static int setnovj __P((void));
111 static int setnovjccomp __P((void));
112 static int setvjslots __P((char **));
113 static int reqpap __P((void));
114 static int nopap __P((void));
115 static int setupapfile __P((char **));
116 static int nochap __P((void));
117 static int reqchap __P((void));
118 static int setspeed __P((char *));
119 static int noaccomp __P((void));
120 static int noasyncmap __P((void));
121 static int noip __P((void));
122 static int nomagicnumber __P((void));
123 static int setasyncmap __P((char **));
124 static int setescape __P((char **));
125 static int setmru __P((char **));
126 static int setmtu __P((char **));
127 static int nomru __P((void));
128 static int nopcomp __P((void));
129 static int setconnector __P((char **));
130 static int setdisconnector __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 setpred1comp __P((void));
175 static int setnopred1comp __P((void));
176 static int setipparam __P((char **));
177 static int setpapcrypt __P((void));
180 static int setipxproto __P((void));
181 static int resetipxproto __P((void));
182 static int setipxanet __P((void));
183 static int setipxalcl __P((void));
184 static int setipxarmt __P((void));
185 static int setipxnetwork __P((char **));
186 static int setipxnode __P((char **));
187 static int setipxrouter __P((char **));
188 static int setipxname __P((char **));
189 static int setipxcptimeout __P((char **));
190 static int setipxcpterm __P((char **));
191 static int setipxcpconf __P((char **));
192 static int setipxcpfails __P((char **));
193 #endif /* IPX_CHANGE */
196 static int setdnsaddr __P((char **));
199 static int number_option __P((char *, u_int32_t *, int));
200 static int readable __P((int fd));
212 {"-all", 0, noopt}, /* Don't request/allow any options */
213 {"-ac", 0, noaccomp}, /* Disable Address/Control compress */
214 {"-am", 0, noasyncmap}, /* Disable asyncmap negotiation */
215 {"-as", 1, setasyncmap}, /* set the desired async map */
216 {"-d", 0, setdebug}, /* Increase debugging level */
217 {"-detach", 0, setnodetach}, /* don't fork */
218 {"-ip", 0, noip}, /* Disable IP and IPCP */
219 {"-mn", 0, nomagicnumber}, /* Disable magic number negotiation */
220 {"-mru", 0, nomru}, /* Disable mru negotiation */
221 {"-p", 0, setpassive}, /* Set passive mode */
222 {"-pc", 0, nopcomp}, /* Disable protocol field compress */
223 {"+ua", 1, setupapfile}, /* Get PAP user and password from file */
224 {"+pap", 0, reqpap}, /* Require PAP auth from peer */
225 {"-pap", 0, nopap}, /* Don't allow UPAP authentication with peer */
226 {"+chap", 0, reqchap}, /* Require CHAP authentication from peer */
227 {"-chap", 0, nochap}, /* Don't allow CHAP authentication with peer */
228 {"-vj", 0, setnovj}, /* disable VJ compression */
229 {"-vjccomp", 0, setnovjccomp}, /* disable VJ connection-ID compression */
230 {"vj-max-slots", 1, setvjslots}, /* Set maximum VJ header slots */
231 {"asyncmap", 1, setasyncmap}, /* set the desired async map */
232 {"escape", 1, setescape}, /* set chars to escape on transmission */
233 {"connect", 1, setconnector}, /* A program to set up a connection */
234 {"disconnect", 1, setdisconnector}, /* program to disconnect serial dev. */
235 {"maxconnect", 1, setmaxconnect}, /* specify a maximum connect time */
236 {"crtscts", 0, setcrtscts}, /* set h/w flow control */
237 {"-crtscts", 0, setnocrtscts}, /* clear h/w flow control */
238 {"xonxoff", 0, setxonxoff}, /* set s/w flow control */
239 {"debug", 0, setdebug}, /* Increase debugging level */
240 {"kdebug", 1, setkdebug}, /* Enable kernel-level debugging */
241 {"domain", 1, setdomain}, /* Add given domain name to hostname*/
242 {"mru", 1, setmru}, /* Set MRU value for negotiation */
243 {"mtu", 1, setmtu}, /* Set our MTU */
244 {"netmask", 1, setnetmask}, /* set netmask */
245 {"passive", 0, setpassive}, /* Set passive mode */
246 {"silent", 0, setsilent}, /* Set silent mode */
247 {"modem", 0, setmodem}, /* Use modem control lines */
248 {"local", 0, setlocal}, /* Don't use modem control lines */
249 {"lock", 0, setlock}, /* Lock serial device (with lock file) */
250 {"name", 1, setname}, /* Set local name for authentication */
251 {"user", 1, setuser}, /* Set username for PAP auth with peer */
252 {"usehostname", 0, setusehostname}, /* Must use hostname for auth. */
253 {"remotename", 1, setremote}, /* Set remote name for authentication */
254 {"auth", 0, setauth}, /* Require authentication from peer */
255 {"file", 1, readfile}, /* Take options from a file */
256 {"defaultroute", 0, setdefaultroute}, /* Add default route */
257 {"-defaultroute", 0, setnodefaultroute}, /* disable defaultroute option */
258 {"proxyarp", 0, setproxyarp}, /* Add proxy ARP entry */
259 {"-proxyarp", 0, setnoproxyarp}, /* disable proxyarp option */
260 {"persist", 0, setpersist}, /* Keep on reopening connection after close */
261 {"login", 0, setdologin}, /* Use system password database for UPAP */
262 {"noipdefault", 0, setnoipdflt}, /* Don't use name for default IP adrs */
263 {"lcp-echo-failure", 1, setlcpechofails}, /* consecutive echo failures */
264 {"lcp-echo-interval", 1, setlcpechointv}, /* time for lcp echo events */
265 {"lcp-restart", 1, setlcptimeout}, /* Set timeout for LCP */
266 {"lcp-max-terminate", 1, setlcpterm}, /* Set max #xmits for term-reqs */
267 {"lcp-max-configure", 1, setlcpconf}, /* Set max #xmits for conf-reqs */
268 {"lcp-max-failure", 1, setlcpfails}, /* Set max #conf-naks for LCP */
269 {"ipcp-restart", 1, setipcptimeout}, /* Set timeout for IPCP */
270 {"ipcp-max-terminate", 1, setipcpterm}, /* Set max #xmits for term-reqs */
271 {"ipcp-max-configure", 1, setipcpconf}, /* Set max #xmits for conf-reqs */
272 {"ipcp-max-failure", 1, setipcpfails}, /* Set max #conf-naks for IPCP */
273 {"pap-restart", 1, setpaptimeout}, /* Set retransmit timeout for PAP */
274 {"pap-max-authreq", 1, setpapreqs}, /* Set max #xmits for auth-reqs */
275 {"pap-timeout", 1, setpapreqtime}, /* Set time limit for peer PAP auth. */
276 {"chap-restart", 1, setchaptimeout}, /* Set timeout for CHAP */
277 {"chap-max-challenge", 1, setchapchal}, /* Set max #xmits for challenge */
278 {"chap-interval", 1, setchapintv}, /* Set interval for rechallenge */
279 {"ipcp-accept-local", 0, setipcpaccl}, /* Accept peer's address for us */
280 {"ipcp-accept-remote", 0, setipcpaccr}, /* Accept peer's address for it */
281 {"bsdcomp", 1, setbsdcomp}, /* request BSD-Compress */
282 {"-bsdcomp", 0, setnobsdcomp}, /* don't allow BSD-Compress */
283 {"predictor1", 0, setpred1comp}, /* request Predictor-1 */
284 {"-predictor1", 0, setnopred1comp}, /* don't allow Predictor-1 */
285 {"ipparam", 1, setipparam}, /* set ip script parameter */
286 {"papcrypt", 0, setpapcrypt}, /* PAP passwords encrypted */
289 {"ipx-network", 1, setipxnetwork}, /* IPX network number */
290 {"ipxcp-accept-network", 0, setipxanet}, /* Accept peer netowrk */
291 {"ipx-node", 1, setipxnode}, /* IPX node number */
292 {"ipxcp-accept-local", 0, setipxalcl}, /* Accept our address */
293 {"ipxcp-accept-remote", 0, setipxarmt}, /* Accept peer's address */
294 {"ipx-routing", 1, setipxrouter}, /* IPX routing proto number */
295 {"ipx-router-name", 1, setipxname}, /* IPX router name */
296 {"ipxcp-restart", 1, setipxcptimeout}, /* Set timeout for IPXCP */
297 {"ipxcp-max-terminate", 1, setipxcpterm}, /* max #xmits for term-reqs */
298 {"ipxcp-max-configure", 1, setipxcpconf}, /* max #xmits for conf-reqs */
299 {"ipxcp-max-failure", 1, setipxcpfails}, /* max #conf-naks for IPXCP */
301 {"ipx-compression", 1, setipxcompression}, /* IPX compression number */
303 {"+ipx", 0, setipxproto}, /* Enable IPXCP (and IPX) */
304 {"-ipx", 0, resetipxproto}, /* Disable IPXCP (and IPX) */
305 #endif /* IPX_CHANGE */
308 {"idle-disconnect", 1, setidle}, /* seconds for disconnect of idle IP */
312 {"ms-dns", 1, setdnsaddr}, /* DNS address(es) for the peer's use */
319 #ifndef IMPLEMENTATION
320 #define IMPLEMENTATION ""
323 static char *usage_string = "\
324 pppd version %s patch level %d%s\n\
325 Usage: %s [ arguments ], where arguments are:\n\
326 <device> Communicate over the named device\n\
327 <speed> Set the baud rate to <speed>\n\
328 <loc>:<rem> Set the local and/or remote interface IP\n\
329 addresses. Either one may be omitted.\n\
330 asyncmap <n> Set the desired async map to hex <n>\n\
331 auth Require authentication from peer\n\
332 connect <p> Invoke shell command <p> to set up the serial line\n\
333 crtscts Use hardware RTS/CTS flow control\n\
334 defaultroute Add default route through interface\n\
335 file <f> Take options from file <f>\n\
336 modem Use modem control lines\n\
337 mru <n> Set MRU value to <n> for negotiation\n\
338 netmask <n> Set interface netmask to <n>\n\
339 See pppd(8) for more options.\n\
344 * parse_args - parse a string of arguments, from the command
345 * line or from a file.
348 parse_args(argc, argv)
361 * First see if it's a command.
363 for (cmdp = cmds; cmdp->cmd_name; cmdp++)
364 if (!strcmp(arg, cmdp->cmd_name))
367 if (cmdp->cmd_name != NULL) {
368 if (argc < cmdp->num_args) {
369 fprintf(stderr, "Too few parameters for command %s\n", arg);
372 if (!(*cmdp->cmd_func)(argv))
374 argc -= cmdp->num_args;
375 argv += cmdp->num_args;
379 * Maybe a tty name, speed or IP address?
381 if ((ret = setdevname(arg)) == 0
382 && (ret = setspeed(arg)) == 0
383 && (ret = setipaddr(arg)) == 0) {
384 fprintf(stderr, "%s: unrecognized command\n", arg);
388 if (ret < 0) /* error */
396 * usage - print out a message telling how to use the program.
401 fprintf(stderr, usage_string, VERSION, PATCHLEVEL, IMPLEMENTATION,
406 * options_from_file - Read a string of options from a file,
407 * and interpret them.
410 options_from_file(filename, must_exist, check_prot)
419 char args[MAXARGS][MAXWORDLEN];
420 char cmd[MAXWORDLEN];
422 if ((f = fopen(filename, "r")) == NULL) {
423 if (!must_exist && errno == ENOENT)
428 if (check_prot && !readable(fileno(f))) {
429 fprintf(stderr, "%s: access denied\n", filename);
434 while (getword(f, cmd, &newline, filename)) {
436 * First see if it's a command.
438 for (cmdp = cmds; cmdp->cmd_name; cmdp++)
439 if (!strcmp(cmd, cmdp->cmd_name))
442 if (cmdp->cmd_name != NULL) {
443 for (i = 0; i < cmdp->num_args; ++i) {
444 if (!getword(f, args[i], &newline, filename)) {
446 "In file %s: too few parameters for command %s\n",
453 if (!(*cmdp->cmd_func)(argv)) {
460 * Maybe a tty name, speed or IP address?
462 if ((ret = setdevname(cmd)) == 0
463 && (ret = setspeed(cmd)) == 0
464 && (ret = setipaddr(cmd)) == 0) {
465 fprintf(stderr, "In file %s: unrecognized command %s\n",
470 if (ret < 0) /* error */
478 * options_from_user - See if the use has a ~/.ppprc file,
479 * and if so, interpret options from it.
484 char *user, *path, *file;
488 pw = getpwuid(getuid());
489 if (pw == NULL || (user = pw->pw_dir) == NULL || user[0] == 0)
491 file = _PATH_USEROPT;
492 path = malloc(strlen(user) + strlen(file) + 2);
494 novm("init file name");
498 ret = options_from_file(path, 0, 1);
504 * options_for_tty - See if an options file exists for the serial
505 * device, and if so, interpret options from it.
513 dev = strrchr(devnam, '/');
518 if (strcmp(dev, "tty") == 0)
519 return 1; /* don't look for /etc/ppp/options.tty */
520 path = malloc(strlen(_PATH_TTYOPT) + strlen(dev) + 1);
522 novm("tty init file name");
523 strcpy(path, _PATH_TTYOPT);
525 ret = options_from_file(path, 0, 0);
531 * readable - check if a file is readable by the real user.
540 GIDSET_TYPE groups[NGROUPS_MAX];
545 if (fstat(fd, &sbuf) != 0)
547 if (sbuf.st_uid == uid)
548 return sbuf.st_mode & S_IRUSR;
549 if (sbuf.st_gid == getgid())
550 return sbuf.st_mode & S_IRGRP;
551 ngroups = getgroups(NGROUPS_MAX, groups);
552 for (i = 0; i < ngroups; ++i)
553 if (sbuf.st_gid == groups[i])
554 return sbuf.st_mode & S_IRGRP;
555 return sbuf.st_mode & S_IROTH;
559 * Read a word from a file.
560 * Words are delimited by white-space or by quotes (" or ').
561 * Quotes, white-space and \ may be escaped with \.
562 * \<newline> is ignored.
566 getword(f, word, newlinep, filename)
574 int value, digit, got, n;
576 #define isoctal(c) ((c) >= '0' && (c) < '8')
584 * First skip white-space and comments.
592 * A newline means the end of a comment; backslash-newline
593 * is ignored. Note that we cannot have escape && comment.
605 * Ignore characters other than newline in a comment.
611 * If this character is escaped, we have a word start.
617 * If this is the escape character, look at the next character.
625 * If this is the start of a comment, ignore the rest of the line.
633 * A non-whitespace character is the start of a word.
640 * Save the delimiter for quoted strings.
642 if (!escape && (c == '"' || c == '\'')) {
649 * Process characters until the end of the word.
654 * This character is escaped: backslash-newline is ignored,
655 * various other characters indicate particular values
656 * as for C backslash-escapes.
691 * \ddd octal sequence
694 for (n = 0; n < 3 && isoctal(c); ++n) {
695 value = (value << 3) + (c & 07);
704 * \x<hex_string> sequence
708 for (n = 0; n < 2 && isxdigit(c); ++n) {
709 digit = toupper(c) - '0';
711 digit += '0' + 10 - 'A';
712 value = (value << 4) + digit;
720 * Otherwise the character stands for itself.
727 * Store the resulting character for the escape sequence.
729 if (len < MAXWORDLEN-1)
740 * Not escaped: see if we've reached the end of the word.
746 if (isspace(c) || c == '#') {
753 * Backslash starts an escape sequence.
762 * An ordinary character: store it in the word and get another.
764 if (len < MAXWORDLEN-1)
772 * End of the word: check for errors.
782 * If len is zero, then we didn't find a word before the
790 * Warn if the word was too long, and append a terminating null.
792 if (len >= MAXWORDLEN) {
793 fprintf(stderr, "%s: warning: word in file %s too long (%.20s...)\n",
794 progname, filename, word);
795 len = MAXWORDLEN - 1;
806 * number_option - parse an unsigned numeric parameter for an option.
809 number_option(str, valp, base)
816 *valp = strtoul(str, &ptr, base);
818 fprintf(stderr, "%s: invalid number: %s\n", progname, str);
826 * int_option - like number_option, but valp is int *,
827 * the base is assumed to be 0, and *valp is not changed
828 * if there is an error.
831 int_option(str, valp)
837 if (!number_option(str, &v, 0))
845 * The following procedures execute commands.
849 * readfile - take commands from a file.
855 return options_from_file(*argv, 1, 1);
859 * setdebug - Set debug (command line argument).
869 * setkdebug - Set kernel debugging level.
875 return int_option(*argv, &kdebugflag);
879 * noopt - Disable all options.
884 BZERO((char *) &lcp_wantoptions[0], sizeof (struct lcp_options));
885 BZERO((char *) &lcp_allowoptions[0], sizeof (struct lcp_options));
886 BZERO((char *) &ipcp_wantoptions[0], sizeof (struct ipcp_options));
887 BZERO((char *) &ipcp_allowoptions[0], sizeof (struct ipcp_options));
890 BZERO((char *) &ipxcp_wantoptions[0], sizeof (struct ipxcp_options));
891 BZERO((char *) &ipxcp_allowoptions[0], sizeof (struct ipxcp_options));
892 #endif /* IPX_CHANGE */
898 * noaccomp - Disable Address/Control field compression negotiation.
903 lcp_wantoptions[0].neg_accompression = 0;
904 lcp_allowoptions[0].neg_accompression = 0;
910 * noasyncmap - Disable async map negotiation.
915 lcp_wantoptions[0].neg_asyncmap = 0;
916 lcp_allowoptions[0].neg_asyncmap = 0;
922 * noip - Disable IP and IPCP.
927 ipcp_protent.enabled_flag = 0;
933 * nomagicnumber - Disable magic number negotiation.
938 lcp_wantoptions[0].neg_magicnumber = 0;
939 lcp_allowoptions[0].neg_magicnumber = 0;
945 * nomru - Disable mru negotiation.
950 lcp_wantoptions[0].neg_mru = 0;
951 lcp_allowoptions[0].neg_mru = 0;
957 * setmru - Set MRU for negotiation.
965 if (!number_option(*argv, &mru, 0))
967 lcp_wantoptions[0].mru = mru;
968 lcp_wantoptions[0].neg_mru = 1;
974 * setmru - Set the largest MTU we'll use.
982 if (!number_option(*argv, &mtu, 0))
984 if (mtu < MINMRU || mtu > MAXMRU) {
985 fprintf(stderr, "mtu option value of %ld is too %s\n", mtu,
986 (mtu < MINMRU? "small": "large"));
989 lcp_allowoptions[0].mru = mtu;
995 * nopcomp - Disable Protocol field compression negotiation.
1000 lcp_wantoptions[0].neg_pcompression = 0;
1001 lcp_allowoptions[0].neg_pcompression = 0;
1007 * setpassive - Set passive mode (don't give up if we time out sending
1008 * LCP configure-requests).
1013 lcp_wantoptions[0].passive = 1;
1019 * setsilent - Set silent mode (don't start sending LCP configure-requests
1020 * until we get one from the peer).
1025 lcp_wantoptions[0].silent = 1;
1031 * nopap - Disable PAP authentication with peer.
1036 lcp_allowoptions[0].neg_upap = 0;
1042 * reqpap - Require PAP authentication from peer.
1047 lcp_wantoptions[0].neg_upap = 1;
1054 * setupapfile - specifies UPAP info for authenticating with peer.
1063 lcp_allowoptions[0].neg_upap = 1;
1065 /* open user info file */
1066 if ((ufile = fopen(*argv, "r")) == NULL) {
1067 fprintf(stderr, "unable to open user login data file %s\n", *argv);
1070 if (!readable(fileno(ufile))) {
1071 fprintf(stderr, "%s: access denied\n", *argv);
1074 check_access(ufile, *argv);
1077 if (fgets(user, MAXNAMELEN - 1, ufile) == NULL
1078 || fgets(passwd, MAXSECRETLEN - 1, ufile) == NULL){
1079 fprintf(stderr, "Unable to read user login data file %s.\n", *argv);
1084 /* get rid of newlines */
1086 if (l > 0 && user[l-1] == '\n')
1089 if (l > 0 && passwd[l-1] == '\n')
1097 * nochap - Disable CHAP authentication with peer.
1102 lcp_allowoptions[0].neg_chap = 0;
1108 * reqchap - Require CHAP authentication from peer.
1113 lcp_wantoptions[0].neg_chap = 1;
1120 * setnovj - disable vj compression
1125 ipcp_wantoptions[0].neg_vj = 0;
1126 ipcp_allowoptions[0].neg_vj = 0;
1132 * setnovjccomp - disable VJ connection-ID compression
1137 ipcp_wantoptions[0].cflag = 0;
1138 ipcp_allowoptions[0].cflag = 0;
1144 * setvjslots - set maximum number of connection slots for VJ compression
1152 if (!int_option(*argv, &value))
1154 if (value < 2 || value > 16) {
1155 fprintf(stderr, "pppd: vj-max-slots value must be between 2 and 16\n");
1158 ipcp_wantoptions [0].maxslotindex =
1159 ipcp_allowoptions[0].maxslotindex = value - 1;
1165 * setconnector - Set a program to connect to a serial line
1171 connector = strdup(*argv);
1172 if (connector == NULL)
1173 novm("connector string");
1179 * setdisconnector - Set a program to disconnect from the serial line
1182 setdisconnector(argv)
1185 disconnector = strdup(*argv);
1186 if (disconnector == NULL)
1187 novm("disconnector string");
1193 * setmaxconnect - Set the maximum connect time
1201 if (!int_option(*argv, &value))
1204 fprintf(stderr, "pppd: maxconnect time must be positive\n");
1212 * setdomain - Set domain name to append to hostname
1218 gethostname(hostname, MAXNAMELEN);
1221 strncat(hostname, ".", MAXNAMELEN - strlen(hostname));
1222 strncat(hostname, *argv, MAXNAMELEN - strlen(hostname));
1224 hostname[MAXNAMELEN-1] = 0;
1230 * setasyncmap - add bits to asyncmap (what we request peer to escape).
1238 if (!number_option(*argv, &asyncmap, 16))
1240 lcp_wantoptions[0].asyncmap |= asyncmap;
1241 lcp_wantoptions[0].neg_asyncmap = 1;
1247 * setescape - add chars to the set we escape on transmission.
1259 n = strtol(p, &endp, 16);
1261 fprintf(stderr, "%s: invalid hex number: %s\n", progname, p);
1265 if (n < 0 || 0x20 <= n && n <= 0x3F || n == 0x5E || n > 0xFF) {
1266 fprintf(stderr, "%s: can't escape character 0x%x\n", progname, n);
1269 xmit_accm[0][n >> 5] |= 1 << (n & 0x1F);
1270 while (*p == ',' || *p == ' ')
1278 * setspeed - Set the speed.
1287 spd = strtol(arg, &ptr, 0);
1288 if (ptr == arg || *ptr != 0 || spd == 0)
1296 * setdevname - Set the device name.
1302 struct stat statbuf;
1303 char *tty, *ttyname();
1304 char dev[MAXPATHLEN];
1306 if (strncmp("/dev/", cp, 5) != 0) {
1307 strcpy(dev, "/dev/");
1308 strncat(dev, cp, MAXPATHLEN - 5);
1309 dev[MAXPATHLEN-1] = 0;
1314 * Check if there is a device by this name.
1316 if (stat(cp, &statbuf) < 0) {
1317 if (errno == ENOENT)
1319 syslog(LOG_ERR, cp);
1323 (void) strncpy(devnam, cp, MAXPATHLEN);
1324 devnam[MAXPATHLEN-1] = 0;
1325 default_device = FALSE;
1332 * setipaddr - Set the IP address
1340 u_int32_t local, remote;
1341 ipcp_options *wo = &ipcp_wantoptions[0];
1344 * IP address pair separated by ":".
1346 if ((colon = strchr(arg, ':')) == NULL)
1350 * If colon first character, then no local addr.
1354 if ((local = inet_addr(arg)) == -1) {
1355 if ((hp = gethostbyname(arg)) == NULL) {
1356 fprintf(stderr, "unknown host: %s\n", arg);
1359 local = *(u_int32_t *)hp->h_addr;
1360 if (our_name[0] == 0) {
1361 strncpy(our_name, arg, MAXNAMELEN);
1362 our_name[MAXNAMELEN-1] = 0;
1366 if (bad_ip_adrs(local)) {
1367 fprintf(stderr, "bad local IP address %s\n", ip_ntoa(local));
1371 wo->ouraddr = local;
1376 * If colon last character, then no remote addr.
1378 if (*++colon != '\0') {
1379 if ((remote = inet_addr(colon)) == -1) {
1380 if ((hp = gethostbyname(colon)) == NULL) {
1381 fprintf(stderr, "unknown host: %s\n", colon);
1384 remote = *(u_int32_t *)hp->h_addr;
1385 if (remote_name[0] == 0) {
1386 strncpy(remote_name, colon, MAXNAMELEN);
1387 remote_name[MAXNAMELEN-1] = 0;
1391 if (bad_ip_adrs(remote)) {
1392 fprintf(stderr, "bad remote IP address %s\n", ip_ntoa(remote));
1396 wo->hisaddr = remote;
1404 * setnoipdflt - disable setipdefault()
1409 disable_defaultip = 1;
1415 * setipcpaccl - accept peer's idea of our address
1420 ipcp_wantoptions[0].accept_local = 1;
1426 * setipcpaccr - accept peer's idea of its address
1431 ipcp_wantoptions[0].accept_remote = 1;
1437 * setipdefault - default our local IP address based on our hostname.
1444 ipcp_options *wo = &ipcp_wantoptions[0];
1447 * If local IP address already given, don't bother.
1449 if (wo->ouraddr != 0 || disable_defaultip)
1453 * Look up our hostname (possibly with domain name appended)
1454 * and take the first IP address as our local IP address.
1455 * If there isn't an IP address for our hostname, too bad.
1457 wo->accept_local = 1; /* don't insist on this default value */
1458 if ((hp = gethostbyname(hostname)) == NULL)
1460 local = *(u_int32_t *)hp->h_addr;
1461 if (local != 0 && !bad_ip_adrs(local))
1462 wo->ouraddr = local;
1467 * setnetmask - set the netmask to be used on the interface.
1475 if ((mask = inet_addr(*argv)) == -1 || (netmask & ~mask) != 0) {
1476 fprintf(stderr, "Invalid netmask %s\n", *argv);
1501 lcp_wantoptions[0].asyncmap |= 0x000A0000; /* escape ^S and ^Q */
1502 lcp_wantoptions[0].neg_asyncmap = 1;
1547 if (our_name[0] == 0) {
1548 strncpy(our_name, argv[0], MAXNAMELEN);
1549 our_name[MAXNAMELEN-1] = 0;
1558 strncpy(user, argv[0], MAXNAMELEN);
1559 user[MAXNAMELEN-1] = 0;
1567 strncpy(remote_name, argv[0], MAXNAMELEN);
1568 remote_name[MAXNAMELEN-1] = 0;
1582 if (!ipcp_allowoptions[0].default_route) {
1583 fprintf(stderr, "%s: defaultroute option is disabled\n", progname);
1586 ipcp_wantoptions[0].default_route = 1;
1593 ipcp_allowoptions[0].default_route = 0;
1594 ipcp_wantoptions[0].default_route = 0;
1601 if (!ipcp_allowoptions[0].proxy_arp) {
1602 fprintf(stderr, "%s: proxyarp option is disabled\n", progname);
1605 ipcp_wantoptions[0].proxy_arp = 1;
1612 ipcp_wantoptions[0].proxy_arp = 0;
1613 ipcp_allowoptions[0].proxy_arp = 0;
1632 * Functions to set the echo interval for modem-less monitors
1636 setlcpechointv(argv)
1639 return int_option(*argv, &lcp_echo_interval);
1643 setlcpechofails(argv)
1646 return int_option(*argv, &lcp_echo_fails);
1650 * Functions to set timeouts, max transmits, etc.
1656 return int_option(*argv, &lcp_fsm[0].timeouttime);
1663 return int_option(*argv, &lcp_fsm[0].maxtermtransmits);
1670 return int_option(*argv, &lcp_fsm[0].maxconfreqtransmits);
1677 return int_option(*argv, &lcp_fsm[0].maxnakloops);
1681 setipcptimeout(argv)
1684 return int_option(*argv, &ipcp_fsm[0].timeouttime);
1691 return int_option(*argv, &ipcp_fsm[0].maxtermtransmits);
1698 return int_option(*argv, &ipcp_fsm[0].maxconfreqtransmits);
1705 return int_option(*argv, &lcp_fsm[0].maxnakloops);
1712 return int_option(*argv, &upap[0].us_timeouttime);
1719 return int_option(*argv, &upap[0].us_reqtimeout);
1726 return int_option(*argv, &upap[0].us_maxtransmits);
1730 setchaptimeout(argv)
1733 return int_option(*argv, &chap[0].timeouttime);
1740 return int_option(*argv, &chap[0].max_transmits);
1747 return int_option(*argv, &chap[0].chal_interval);
1758 abits = rbits = strtol(str, &endp, 0);
1759 if (endp != str && *endp == ',') {
1761 abits = strtol(str, &endp, 0);
1763 if (*endp != 0 || endp == str) {
1764 fprintf(stderr, "%s: invalid argument format for bsdcomp option\n",
1768 if (rbits != 0 && (rbits < BSD_MIN_BITS || rbits > BSD_MAX_BITS)
1769 || abits != 0 && (abits < BSD_MIN_BITS || abits > BSD_MAX_BITS)) {
1770 fprintf(stderr, "%s: bsdcomp option values must be 0 or %d .. %d\n",
1771 progname, BSD_MIN_BITS, BSD_MAX_BITS);
1775 ccp_wantoptions[0].bsd_compress = 1;
1776 ccp_wantoptions[0].bsd_bits = rbits;
1778 ccp_wantoptions[0].bsd_compress = 0;
1780 ccp_allowoptions[0].bsd_compress = 1;
1781 ccp_allowoptions[0].bsd_bits = abits;
1783 ccp_allowoptions[0].bsd_compress = 0;
1790 ccp_wantoptions[0].bsd_compress = 0;
1791 ccp_allowoptions[0].bsd_compress = 0;
1798 ccp_wantoptions[0].predictor_1 = 1;
1799 ccp_allowoptions[0].predictor_1 = 1;
1806 ccp_wantoptions[0].predictor_1 = 0;
1807 ccp_allowoptions[0].predictor_1 = 0;
1815 ipparam = strdup(*argv);
1816 if (ipparam == NULL)
1817 novm("ipparam string");
1830 static int setidle (argv)
1833 return int_option(*argv, &idle_time_limit);
1843 ipxcp_wantoptions[0].neg_router = 1;
1844 ipxcp_allowoptions[0].neg_router = 1;
1845 return int_option(*argv, &ipxcp_wantoptions[0].router);
1852 char *dest = ipxcp_wantoptions[0].name;
1857 ipxcp_wantoptions[0].neg_name = 1;
1858 ipxcp_allowoptions[0].neg_name = 1;
1859 memset (dest, '\0', sizeof (ipxcp_wantoptions[0].name));
1864 if (! isalnum (ch) && ch != '_') {
1866 "%s: IPX router name must be alphanumeric or _\n",
1871 if (count >= sizeof (ipxcp_wantoptions[0].name)) {
1873 "%s: IPX router name is limited to %d characters\n",
1875 sizeof (ipxcp_wantoptions[0].name) - 1);
1879 dest[count++] = toupper (ch);
1886 setipxcptimeout (argv)
1889 return int_option(*argv, &ipxcp_fsm[0].timeouttime);
1896 return int_option(*argv, &ipxcp_fsm[0].maxtermtransmits);
1903 return int_option(*argv, &ipxcp_fsm[0].maxconfreqtransmits);
1907 setipxcpfails (argv)
1910 return int_option(*argv, &ipxcp_fsm[0].maxnakloops);
1917 ipxcp_wantoptions[0].neg_nn = 1;
1918 return int_option(*argv, &ipxcp_wantoptions[0].our_network);
1924 ipxcp_wantoptions[0].accept_network = 1;
1925 ipxcp_allowoptions[0].accept_network = 1;
1931 ipxcp_wantoptions[0].accept_local = 1;
1932 ipxcp_allowoptions[0].accept_local = 1;
1938 ipxcp_wantoptions[0].accept_remote = 1;
1939 ipxcp_allowoptions[0].accept_remote = 1;
1943 setipxnodevalue(src,dst)
1950 if (!isxdigit (*src))
1953 for (indx = 0; indx < 5; ++indx) {
1955 dst[indx] |= (dst[indx + 1] >> 4) & 0x0F;
1958 item = toupper (*src) - '0';
1962 dst[5] = (dst[5] << 4) | item;
1974 memset (&ipxcp_wantoptions[0].our_node[0], 0, 6);
1975 memset (&ipxcp_wantoptions[0].his_node[0], 0, 6);
1977 end = setipxnodevalue (*argv, &ipxcp_wantoptions[0].our_node[0]);
1979 end = setipxnodevalue (++end, &ipxcp_wantoptions[0].his_node[0]);
1982 ipxcp_wantoptions[0].neg_node = 1;
1986 fprintf(stderr, "%s: invalid argument for ipx-node option\n",
1994 ipx_enabled = 1; /* Enable IPXCP and IPX protocol */
2001 ipx_enabled = 0; /* Disable IPXCP and IPX protocol */
2004 #endif /* IPX_CHANGE */
2008 * setdnsaddr - set the dns address(es)
2018 dns = inet_addr(*argv);
2020 if ((hp = gethostbyname(*argv)) == NULL) {
2021 fprintf(stderr, "Invalid DNS Address %s\n", *argv);
2024 dns = *(u_int32_t *)hp->h_addr;
2027 if (ipcp_allowoptions[0].dnsaddr[0] == 0) {
2028 ipcp_allowoptions[0].dnsaddr[0] = dns;
2030 ipcp_allowoptions[0].dnsaddr[1] = dns;
2035 #endif /* USE_MS_DNS */