]> git.ozlabs.org Git - ppp.git/blob - pppd/options.c
Initial revision
[ppp.git] / pppd / options.c
1 /*
2  * options.c - handles option processing for PPP.
3  *
4  * Copyright (c) 1989 Carnegie Mellon University.
5  * All rights reserved.
6  *
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.
18  */
19
20 #ifndef lint
21 static char rcsid[] = "$Id: options.c,v 1.4 1994/02/08 23:48:50 paulus Exp $";
22 #endif
23
24 #include <stdio.h>
25 #include <errno.h>
26 #include <unistd.h>
27 #include <stdlib.h>
28 #include <termios.h>
29 #include <syslog.h>
30 #include <string.h>
31 #include <netdb.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34
35 #include "ppp.h"
36 #include "pppd.h"
37 #include "pathnames.h"
38 #include "patchlevel.h"
39 #include "fsm.h"
40 #include "lcp.h"
41 #include "ipcp.h"
42 #include "upap.h"
43 #include "chap.h"
44
45 #define FALSE   0
46 #define TRUE    1
47
48
49 /*
50  * Prototypes
51  */
52 static int setdebug __ARGS((void));
53 static int setpassive __ARGS((void));
54 static int setsilent __ARGS((void));
55 static int noopt __ARGS((void));
56 static int setnovj __ARGS((void));
57 static int reqpap __ARGS((void));
58 static int nopap __ARGS((void));
59 static int setupapfile __ARGS((char **));
60 static int nochap __ARGS((void));
61 static int reqchap __ARGS((void));
62 static int setspeed __ARGS((char *));
63 static int noaccomp __ARGS((void));
64 static int noasyncmap __ARGS((void));
65 static int noipaddr __ARGS((void));
66 static int nomagicnumber __ARGS((void));
67 static int setasyncmap __ARGS((char **));
68 static int setmru __ARGS((char **));
69 static int nomru __ARGS((void));
70 static int nopcomp __ARGS((void));
71 static int setconnector __ARGS((char **));
72 static int setdomain __ARGS((char **));
73 static int setnetmask __ARGS((char **));
74 static int setcrtscts __ARGS((void));
75 static int setnodetach __ARGS((void));
76 static int setmodem __ARGS((void));
77 static int setlocal __ARGS((void));
78 static int setname __ARGS((char **));
79 static int setuser __ARGS((char **));
80 static int setremote __ARGS((char **));
81 static int setauth __ARGS((void));
82 static int readfile __ARGS((char **));
83 static int setdefaultroute __ARGS((void));
84 static int setproxyarp __ARGS((void));
85 static int setpersist __ARGS((void));
86 static int setdologin __ARGS((void));
87 static int setusehostname __ARGS((void));
88 static int setnoipdflt __ARGS((void));
89 static int setlcptimeout __ARGS((char **));
90 static int setlcpterm __ARGS((char **));
91 static int setlcpconf __ARGS((char **));
92 static int setlcpfails __ARGS((char **));
93 static int setipcptimeout __ARGS((char **));
94 static int setipcpterm __ARGS((char **));
95 static int setipcpconf __ARGS((char **));
96 static int setipcpfails __ARGS((char **));
97 static int setpaptimeout __ARGS((char **));
98 static int setpapreqs __ARGS((char **));
99 static int setchaptimeout __ARGS((char **));
100 static int setchapchal __ARGS((char **));
101 static int setchapintv __ARGS((char **));
102 static int setipcpaccl __ARGS((void));
103 static int setipcpaccr __ARGS((void));
104
105 static int number_option __ARGS((char *, long *, int));
106
107
108 /*
109  * Option variables
110  */
111 extern char *progname;
112 extern int debug;
113 extern int modem;
114 extern int crtscts;
115 extern int nodetach;
116 extern char *connector;
117 extern int inspeed;
118 extern char devname[];
119 extern int default_device;
120 extern u_long netmask;
121 extern int detach;
122 extern char user[];
123 extern char passwd[];
124 extern int auth_required;
125 extern int proxyarp;
126 extern int persist;
127 extern int uselogin;
128 extern char our_name[];
129 extern char remote_name[];
130 int usehostname;
131 int disable_defaultip;
132
133 /*
134  * Valid arguments.
135  */
136 static struct cmd {
137     char *cmd_name;
138     int num_args;
139     int (*cmd_func)();
140 } cmds[] = {
141     "-all", 0, noopt,           /* Don't request/allow any options */
142     "-ac", 0, noaccomp,         /* Disable Address/Control compress */
143     "-am", 0, noasyncmap,       /* Disable asyncmap negotiation */
144     "-as", 1, setasyncmap,      /* set the desired async map */
145     "-d", 0, setdebug,          /* Increase debugging level */
146     "-detach", 0, setnodetach,  /* don't fork */
147     "-ip", 0, noipaddr,         /* Disable IP address negotiation */
148     "-mn", 0, nomagicnumber,    /* Disable magic number negotiation */
149     "-mru", 0, nomru,           /* Disable mru negotiation */
150     "-p", 0, setpassive,        /* Set passive mode */
151     "-pc", 0, nopcomp,          /* Disable protocol field compress */
152     "+ua", 1, setupapfile,      /* Get PAP user and password from file */
153     "+pap", 0, reqpap,          /* Require PAP auth from peer */
154     "-pap", 0, nopap,           /* Don't allow UPAP authentication with peer */
155     "+chap", 0, reqchap,        /* Require CHAP authentication from peer */
156     "-chap", 0, nochap,         /* Don't allow CHAP authentication with peer */
157     "-vj", 0, setnovj,          /* disable VJ compression */
158     "asyncmap", 1, setasyncmap, /* set the desired async map */
159     "connect", 1, setconnector, /* A program to set up a connection */
160     "crtscts", 0, setcrtscts,   /* set h/w flow control */
161     "debug", 0, setdebug,       /* Increase debugging level */
162     "domain", 1, setdomain,     /* Add given domain name to hostname*/
163     "mru", 1, setmru,           /* Set MRU value for negotiation */
164     "netmask", 1, setnetmask,   /* set netmask */
165     "passive", 0, setpassive,   /* Set passive mode */
166     "silent", 0, setsilent,     /* Set silent mode */
167     "modem", 0, setmodem,       /* Use modem control lines */
168     "local", 0, setlocal,       /* Don't use modem control lines */
169     "name", 1, setname,         /* Set local name for authentication */
170     "user", 1, setuser,         /* Set username for PAP auth with peer */
171     "usehostname", 0, setusehostname,   /* Must use hostname for auth. */
172     "remotename", 1, setremote, /* Set remote name for authentication */
173     "auth", 0, setauth,         /* Require authentication from peer */
174     "file", 1, readfile,        /* Take options from a file */
175     "defaultroute", 0, setdefaultroute, /* Add default route */
176     "proxyarp", 0, setproxyarp, /* Add proxy ARP entry */
177     "persist", 0, setpersist,   /* Keep on reopening connection after close */
178     "login", 0, setdologin,     /* Use system password database for UPAP */
179     "noipdefault", 0, setnoipdflt, /* Don't use name for default IP adrs */
180     "lcp-restart", 1, setlcptimeout,    /* Set timeout for LCP */
181     "lcp-max-terminate", 1, setlcpterm, /* Set max #xmits for term-reqs */
182     "lcp-max-configure", 1, setlcpconf, /* Set max #xmits for conf-reqs */
183     "lcp-max-failure", 1, setlcpfails,  /* Set max #conf-naks for LCP */
184     "ipcp-restart", 1, setipcptimeout,  /* Set timeout for IPCP */
185     "ipcp-max-terminate", 1, setipcpterm, /* Set max #xmits for term-reqs */
186     "ipcp-max-configure", 1, setipcpconf, /* Set max #xmits for conf-reqs */
187     "ipcp-max-failure", 1, setipcpfails,  /* Set max #conf-naks for IPCP */
188     "pap-restart", 1, setpaptimeout,    /* Set timeout for UPAP */
189     "pap-max-authreq", 1, setpapreqs,   /* Set max #xmits for auth-reqs */
190     "chap-restart", 1, setchaptimeout,  /* Set timeout for CHAP */
191     "chap-max-challenge", 1, setchapchal, /* Set max #xmits for challenge */
192     "chap-interval", 1, setchapintv,    /* Set interval for rechallenge */
193     "ipcp-accept-local", 0, setipcpaccl, /* Accept peer's address for us */
194     "ipcp-accept-remote", 0, setipcpaccr, /* Accept peer's address for it */
195     NULL
196 };
197
198
199 static char *usage_string = "\
200 pppd version %s patch level %d\n\
201 Usage: %s [ arguments ], where arguments are:\n\
202         <device>        Communicate over the named device\n\
203         <speed>         Set the baud rate to <speed>\n\
204         <loc>:<rem>     Set the local and/or remote interface IP\n\
205                         addresses.  Either one may be omitted.\n\
206         asyncmap <n>    Set the desired async map to hex <n>\n\
207         auth            Require authentication from peer\n\
208         connect <p>     Invoke shell command <p> to set up the serial line\n\
209         crtscts         Use hardware RTS/CTS flow control\n\
210         defaultroute    Add default route through interface\n\
211         file <f>        Take options from file <f>\n\
212         modem           Use modem control lines\n\
213         mru <n>         Set MRU value to <n> for negotiation\n\
214         netmask <n>     Set interface netmask to <n>\n\
215 See pppd(8) for more options.\n\
216 ";
217
218 /*
219 Options omitted:
220         -all            Don't request/allow any options\n\
221         -ac             Disable Address/Control compression\n\
222         -am             Disable asyncmap negotiation\n\
223         -as <n>         Set the desired async map to hex <n>\n\
224         -d              Increase debugging level\n\
225         -detach         Don't fork to background\n\
226         -ip             Disable IP address negotiation\n\
227         -mn             Disable magic number negotiation\n\
228         -mru            Disable mru negotiation\n\
229         -p              Set passive mode\n\
230         -pc             Disable protocol field compression\n\
231         +ua <f>         Get username and password for authenticating\n\
232                         with peer using PAP from file <f>\n\
233         +pap            Require PAP authentication from peer\n\
234         -pap            Don't agree to authenticating with peer using PAP\n\
235         +chap           Require CHAP authentication from peer\n\
236         -chap           Don't agree to authenticating with peer using CHAP\n\
237         -vj             disable VJ compression\n\
238         -auth           Don't agree to authenticate with peer\n\
239         debug           Increase debugging level\n\
240         domain <d>      Append domain name <d> to hostname for authentication\n\
241         passive         Set passive mode\n\
242         local           Don't use modem control lines\n\
243         proxyarp        Add proxy ARP entry\n\
244 */
245
246
247 /*
248  * parse_args - parse a string of arguments, from the command
249  * line or from a file.
250  */
251 int
252 parse_args(argc, argv)
253     int argc;
254     char **argv;
255 {
256     char *arg, *val;
257     struct cmd *cmdp;
258
259     while (argc > 0) {
260         arg = *argv++;
261         --argc;
262
263         /*
264          * First see if it's a command.
265          */
266         for (cmdp = cmds; cmdp->cmd_name; cmdp++)
267             if (!strcmp(arg, cmdp->cmd_name))
268                 break;
269
270         if (cmdp->cmd_name != NULL) {
271             if (argc < cmdp->num_args) {
272                 fprintf(stderr, "Too few parameters for command %s\n", arg);
273                 return 0;
274             }
275             if (!(*cmdp->cmd_func)(argv))
276                 return 0;
277             argc -= cmdp->num_args;
278             argv += cmdp->num_args;
279
280         } else {
281             /*
282              * Maybe a tty name, speed or IP address?
283              */
284             if (!setdevname(arg) && !setspeed(arg) && !setipaddr(arg)) {
285                 fprintf(stderr, "%s: unrecognized command\n", arg);
286                 usage();
287                 return 0;
288             }
289         }
290     }
291     return 1;
292 }
293
294 /*
295  * usage - print out a message telling how to use the program.
296  */
297 usage()
298 {
299     fprintf(stderr, usage_string, VERSION, PATCHLEVEL, progname);
300 }
301
302 /*
303  * options_from_file - Read a string of options from a file,
304  * and interpret them.
305  */
306 int
307 options_from_file(filename, must_exist)
308     char *filename;
309     int must_exist;
310 {
311     FILE *f;
312     int i, newline;
313     struct cmd *cmdp;
314     char *argv[MAXARGS];
315     char args[MAXARGS][MAXWORDLEN];
316     char cmd[MAXWORDLEN];
317
318     if ((f = fopen(filename, "r")) == NULL) {
319         if (!must_exist && errno == ENOENT)
320             return 1;
321         perror(filename);
322         exit(1);
323     }
324     while (getword(f, cmd, &newline, filename)) {
325         /*
326          * First see if it's a command.
327          */
328         for (cmdp = cmds; cmdp->cmd_name; cmdp++)
329             if (!strcmp(cmd, cmdp->cmd_name))
330                 break;
331
332         if (cmdp->cmd_name != NULL) {
333             for (i = 0; i < cmdp->num_args; ++i) {
334                 if (!getword(f, args[i], &newline, filename)) {
335                     fprintf(stderr,
336                             "In file %s: too few parameters for command %s\n",
337                             filename, cmd);
338                     fclose(f);
339                     return 0;
340                 }
341                 argv[i] = args[i];
342             }
343             if (!(*cmdp->cmd_func)(argv)) {
344                 fclose(f);
345                 return 0;
346             }
347
348         } else {
349             /*
350              * Maybe a tty name, speed or IP address?
351              */
352             if (!setdevname(cmd) && !setspeed(cmd) && !setipaddr(cmd)) {
353                 fprintf(stderr, "In file %s: unrecognized command %s\n",
354                         filename, cmd);
355                 fclose(f);
356                 return 0;
357             }
358         }
359     }
360     return 1;
361 }
362
363 /*
364  * options_from_user - See if the use has a ~/.ppprc file,
365  * and if so, interpret options from it.
366  */
367 int
368 options_from_user()
369 {
370     char *user, *path, *file;
371     int ret;
372
373     if ((user = getenv("HOME")) == NULL)
374         return;
375     file = "/.ppprc";
376     path = malloc(strlen(user) + strlen(file) + 1);
377     if (path == NULL)
378         novm("init file name");
379     strcpy(path, user);
380     strcat(path, file);
381     ret = options_from_file(path, 0);
382     free(path);
383     return ret;
384 }
385
386 /*
387  * Read a word from a file.
388  * Words are delimited by white-space or by quotes (").
389  * Quotes, white-space and \ may be escaped with \.
390  * \<newline> is ignored.
391  */
392 int
393 getword(f, word, newlinep, filename)
394     FILE *f;
395     char *word;
396     int *newlinep;
397     char *filename;
398 {
399     int c, len, escape;
400     int quoted;
401
402     *newlinep = 0;
403     len = 0;
404     escape = 0;
405     quoted = 0;
406
407     /*
408      * First skip white-space and comments
409      */
410     while ((c = getc(f)) != EOF) {
411         if (c == '\\') {
412             /*
413              * \<newline> is ignored; \ followed by anything else
414              * starts a word.
415              */
416             if ((c = getc(f)) == '\n')
417                 continue;
418             word[len++] = '\\';
419             escape = 1;
420             break;
421         }
422         if (c == '\n')
423             *newlinep = 1;      /* next word starts a line */
424         else if (c == '#') {
425             /* comment - ignore until EOF or \n */
426             while ((c = getc(f)) != EOF && c != '\n')
427                 ;
428             if (c == EOF)
429                 break;
430             *newlinep = 1;
431         } else if (!isspace(c))
432             break;
433     }
434
435     /*
436      * End of file or error - fail
437      */
438     if (c == EOF) {
439         if (ferror(f)) {
440             perror(filename);
441             die(1);
442         }
443         return 0;
444     }
445
446     for (;;) {
447         /*
448          * Is this character escaped by \ ?
449          */
450         if (escape) {
451             if (c == '\n')
452                 --len;                  /* ignore \<newline> */
453             else if (c == '"' || isspace(c) || c == '\\')
454                 word[len-1] = c;        /* put special char in word */
455             else {
456                 if (len < MAXWORDLEN-1)
457                     word[len] = c;
458                 ++len;
459             }
460             escape = 0;
461         } else if (c == '"') {
462             quoted = !quoted;
463         } else if (!quoted && (isspace(c) || c == '#')) {
464             ungetc(c, f);
465             break;
466         } else {
467             if (len < MAXWORDLEN-1)
468                 word[len] = c;
469             ++len;
470             if (c == '\\')
471                 escape = 1;
472         }
473         if ((c = getc(f)) == EOF)
474             break;
475     }
476
477     if (ferror(f)) {
478         perror(filename);
479         die(1);
480     }
481
482     if (len >= MAXWORDLEN) {
483         word[MAXWORDLEN-1] = 0;
484         fprintf(stderr, "%s: warning: word in file %s too long (%.20s...)\n",
485                 progname, filename, word);
486     } else
487         word[len] = 0;
488
489     return 1;
490 }
491
492 /*
493  * number_option - parse a numeric parameter for an option
494  */
495 static int
496 number_option(str, valp, base)
497     char *str;
498     long *valp;
499     int base;
500 {
501     char *ptr;
502
503     *valp = strtol(str, &ptr, base);
504     if (ptr == str) {
505         fprintf(stderr, "%s: invalid number: %s\n", progname, str);
506         return 0;
507     }
508     return 1;
509 }
510
511
512 /*
513  * int_option - like number_option, but valp is int *,
514  * the base is assumed to be 0, and *valp is not changed
515  * if there is an error.
516  */
517 static int
518 int_option(str, valp)
519     char *str;
520     int *valp;
521 {
522     long v;
523
524     if (!number_option(str, &v, 0))
525         return 0;
526     *valp = (int) v;
527     return 1;
528 }
529
530
531 /*
532  * The following procedures execute commands.
533  */
534
535 /*
536  * readfile - take commands from a file.
537  */
538 static int
539 readfile(argv)
540     char **argv;
541 {
542     return options_from_file(*argv, 1);
543 }
544
545 /*
546  * setdebug - Set debug (command line argument).
547  */
548 static int
549 setdebug()
550 {
551     debug++;
552     setlogmask(LOG_UPTO(LOG_DEBUG));
553     return (1);
554 }
555
556 /*
557  * noopt - Disable all options.
558  */
559 static int
560 noopt()
561 {
562     BZERO((char *) &lcp_wantoptions[0], sizeof (struct lcp_options));
563     BZERO((char *) &lcp_allowoptions[0], sizeof (struct lcp_options));
564     BZERO((char *) &ipcp_wantoptions[0], sizeof (struct ipcp_options));
565     BZERO((char *) &ipcp_allowoptions[0], sizeof (struct ipcp_options));
566     return (1);
567 }
568
569 /*
570  * noaccomp - Disable Address/Control field compression negotiation.
571  */
572 static int
573 noaccomp()
574 {
575     lcp_wantoptions[0].neg_accompression = 0;
576     lcp_allowoptions[0].neg_accompression = 0;
577     return (1);
578 }
579
580
581 /*
582  * noasyncmap - Disable async map negotiation.
583  */
584 static int
585 noasyncmap()
586 {
587     lcp_wantoptions[0].neg_asyncmap = 0;
588     lcp_allowoptions[0].neg_asyncmap = 0;
589     return (1);
590 }
591
592
593 /*
594  * noipaddr - Disable IP address negotiation.
595  */
596 static int
597 noipaddr()
598 {
599     ipcp_wantoptions[0].neg_addr = 0;
600     ipcp_allowoptions[0].neg_addr = 0;
601     return (1);
602 }
603
604
605 /*
606  * nomagicnumber - Disable magic number negotiation.
607  */
608 static int
609 nomagicnumber()
610 {
611     lcp_wantoptions[0].neg_magicnumber = 0;
612     lcp_allowoptions[0].neg_magicnumber = 0;
613     return (1);
614 }
615
616
617 /*
618  * nomru - Disable mru negotiation.
619  */
620 static int
621 nomru()
622 {
623     lcp_wantoptions[0].neg_mru = 0;
624     lcp_allowoptions[0].neg_mru = 0;
625     return (1);
626 }
627
628
629 /*
630  * setmru - Set MRU for negotiation.
631  */
632 static int
633 setmru(argv)
634     char **argv;
635 {
636     long mru;
637
638     if (!number_option(*argv, &mru, 0))
639         return 0;
640     lcp_wantoptions[0].mru = mru;
641     lcp_wantoptions[0].neg_mru = 1;
642     return (1);
643 }
644
645
646 /*
647  * nopcomp - Disable Protocol field compression negotiation.
648  */
649 static int
650 nopcomp()
651 {
652     lcp_wantoptions[0].neg_pcompression = 0;
653     lcp_allowoptions[0].neg_pcompression = 0;
654     return (1);
655 }
656
657
658 /*
659  * setpassive - Set passive mode (don't give up if we time out sending
660  * LCP configure-requests).
661  */
662 static int
663 setpassive()
664 {
665     lcp_wantoptions[0].passive = 1;
666     return (1);
667 }
668
669
670 /*
671  * setsilent - Set silent mode (don't start sending LCP configure-requests
672  * until we get one from the peer).
673  */
674 static int
675 setsilent()
676 {
677     lcp_wantoptions[0].silent = 1;
678     return 1;
679 }
680
681
682 /*
683  * nopap - Disable PAP authentication with peer.
684  */
685 static int
686 nopap()
687 {
688     lcp_allowoptions[0].neg_upap = 0;
689     return (1);
690 }
691
692
693 /*
694  * reqpap - Require PAP authentication from peer.
695  */
696 static int
697 reqpap()
698 {
699     lcp_wantoptions[0].neg_upap = 1;
700     auth_required = 1;
701 }
702
703
704 /*
705  * setupapfile - specifies UPAP info for authenticating with peer.
706  */
707 static int
708 setupapfile(argv)
709     char **argv;
710 {
711     FILE * ufile;
712     int l;
713
714     lcp_allowoptions[0].neg_upap = 1;
715
716     /* open user info file */
717     if ((ufile = fopen(*argv, "r")) == NULL) {
718         fprintf(stderr, "unable to open user login data file %s\n", *argv);
719         exit(1);
720     }
721     check_access(ufile, *argv);
722
723     /* get username */
724     if (fgets(user, MAXNAMELEN - 1, ufile) == NULL
725         || fgets(passwd, MAXSECRETLEN - 1, ufile) == NULL){
726         fprintf(stderr, "Unable to read user login data file %s.\n", *argv);
727         exit(2);
728     }
729     fclose(ufile);
730
731     /* get rid of newlines */
732     l = strlen(user);
733     if (l > 0 && user[l-1] == '\n')
734         user[l-1] = 0;
735     l = strlen(passwd);
736     if (l > 0 && passwd[l-1] == '\n')
737         passwd[l-1] = 0;
738
739     return (1);
740 }
741
742
743 /*
744  * nochap - Disable CHAP authentication with peer.
745  */
746 static int
747 nochap()
748 {
749     lcp_allowoptions[0].neg_chap = 0;
750     return (1);
751 }
752
753
754 /*
755  * reqchap - Require CHAP authentication from peer.
756  */
757 static int
758 reqchap()
759 {
760     lcp_wantoptions[0].neg_chap = 1;
761     auth_required = 1;
762     return (1);
763 }
764
765
766 /*
767  * setnovj - diable vj compression
768  */
769 static int
770 setnovj()
771 {
772     ipcp_wantoptions[0].neg_vj = 0;
773     ipcp_allowoptions[0].neg_vj = 0;
774     return (1);
775 }
776
777 /*
778  * setconnector - Set a program to connect to a serial line
779  */
780 static int
781 setconnector(argv)
782     char **argv;
783 {
784     connector = strdup(*argv);
785     if (connector == NULL)
786         novm("connector string");
787   
788     return (1);
789 }
790
791
792 /*
793  * setdomain - Set domain name to append to hostname 
794  */
795 static int
796 setdomain(argv)
797     char **argv;
798 {
799     strncat(hostname, *argv, MAXNAMELEN - strlen(hostname));
800     hostname[MAXNAMELEN-1] = 0;
801     return (1);
802 }
803
804 static int
805 setasyncmap(argv)
806     char **argv;
807 {
808     long asyncmap;
809
810     if (!number_option(*argv, &asyncmap, 16))
811         return 0;
812     lcp_wantoptions[0].asyncmap |= asyncmap;
813     lcp_wantoptions[0].neg_asyncmap = 1;
814     return(1);
815 }
816
817 /*
818  * setspeed - Set the speed.
819  */
820 static int
821 setspeed(arg)
822     char *arg;
823 {
824     char *ptr;
825     int spd;
826
827     spd = strtol(arg, &ptr, 0);
828     if (ptr == arg || *ptr != 0 || spd == 0)
829         return 0;
830     inspeed = spd;
831     return 1;
832 }
833
834
835 /*
836  * setdevname - Set the device name.
837  */
838 int
839 setdevname(cp)
840     char *cp;
841 {
842     struct stat statbuf;
843     char *tty, *ttyname();
844     char dev[MAXPATHLEN];
845   
846     if (strncmp("/dev/", cp, 5) != 0) {
847         strcpy(dev, "/dev/");
848         strncat(dev, cp, MAXPATHLEN - 5);
849         dev[MAXPATHLEN-1] = 0;
850         cp = dev;
851     }
852
853     /*
854      * Check if there is a device by this name.
855      */
856     if (stat(cp, &statbuf) < 0) {
857         if (errno == ENOENT)
858             return (0);
859         syslog(LOG_ERR, cp);
860         exit(1);
861     }
862   
863     (void) strncpy(devname, cp, MAXPATHLEN);
864     devname[MAXPATHLEN-1] = 0;
865     default_device = FALSE;
866   
867     return (1);
868 }
869
870
871 /*
872  * setipaddr - Set the IP address
873  */
874 int
875 setipaddr(arg)
876     char *arg;
877 {
878     struct hostent *hp;
879     char *colon, *index();
880     u_long local, remote;
881     ipcp_options *wo = &ipcp_wantoptions[0];
882   
883     /*
884      * IP address pair separated by ":".
885      */
886     if ((colon = index(arg, ':')) == NULL)
887         return (0);
888   
889     /*
890      * If colon first character, then no local addr.
891      */
892     if (colon != arg) {
893         *colon = '\0';
894         if ((local = inet_addr(arg)) == -1) {
895             if ((hp = gethostbyname(arg)) == NULL) {
896                 fprintf(stderr, "unknown host: %s", arg);
897                 local = 0;
898             } else {
899                 local = *(long *)hp->h_addr;
900                 if (our_name[0] == 0) {
901                     strncpy(our_name, arg, MAXNAMELEN);
902                     our_name[MAXNAMELEN-1] = 0;
903                 }
904             }
905         }
906         if (local != 0)
907             wo->ouraddr = local;
908         *colon = ':';
909     }
910   
911     /*
912      * If colon last character, then no remote addr.
913      */
914     if (*++colon != '\0') {
915         if ((remote = inet_addr(colon)) == -1) {
916             if ((hp = gethostbyname(colon)) == NULL) {
917                 fprintf(stderr, "unknown host: %s", colon);
918                 remote = 0;
919             } else {
920                 remote = *(long *)hp->h_addr;
921                 if (remote_name[0] == 0) {
922                     strncpy(remote_name, colon, MAXNAMELEN);
923                     remote_name[MAXNAMELEN-1] = 0;
924                 }
925             }
926         }
927         if (remote != 0)
928             wo->hisaddr = remote;
929     }
930
931     return (1);
932 }
933
934
935 /*
936  * setnoipdflt - disable setipdefault()
937  */
938 static int
939 setnoipdflt()
940 {
941     disable_defaultip = 1;
942     return 1;
943 }
944
945
946 /*
947  * setipcpaccl - accept peer's idea of our address
948  */
949 static int
950 setipcpaccl()
951 {
952     ipcp_wantoptions[0].accept_local = 1;
953     return 1;
954 }
955
956
957 /*
958  * setipcpaccr - accept peer's idea of its address
959  */
960 static int
961 setipcpaccr()
962 {
963     ipcp_wantoptions[0].accept_remote = 1;
964     return 1;
965 }
966
967
968 /*
969  * setipdefault - default our local IP address based on our hostname.
970  */
971 void
972 setipdefault()
973 {
974     struct hostent *hp;
975     u_long local;
976     ipcp_options *wo = &ipcp_wantoptions[0];
977
978     /*
979      * If local IP address already given, don't bother.
980      */
981     if (wo->ouraddr != 0 || disable_defaultip)
982         return;
983
984     /*
985      * Look up our hostname (possibly with domain name appended)
986      * and take the first IP address as our local IP address.
987      * If there isn't an IP address for our hostname, too bad.
988      */
989     wo->accept_local = 1;       /* don't insist on this default value */
990     if ((hp = gethostbyname(hostname)) == NULL)
991         return;
992     local = *(long *)hp->h_addr;
993     if (local != 0)
994         wo->ouraddr = local;
995 }
996
997
998 /*
999  * setnetmask - set the netmask to be used on the interface.
1000  */
1001 static int
1002 setnetmask(argv)
1003     char **argv;
1004 {
1005     u_long mask;
1006         
1007     if ((mask = inet_addr(*argv)) == -1) {
1008         fprintf(stderr, "Invalid netmask %s\n", *argv);
1009         exit(1);
1010     }
1011
1012     netmask = mask;
1013     return (1);
1014 }
1015
1016 static int
1017 setcrtscts()
1018 {
1019     crtscts = 1;
1020     return (1);
1021 }
1022
1023 static int
1024 setnodetach()
1025 {
1026     nodetach = 1;
1027     return (1);
1028 }
1029
1030 static int
1031 setmodem()
1032 {
1033     modem = 1;
1034     return 1;
1035 }
1036
1037 static int
1038 setlocal()
1039 {
1040     modem = 0;
1041     return 1;
1042 }
1043
1044 static int
1045 setusehostname()
1046 {
1047     usehostname = 1;
1048     return 1;
1049 }
1050
1051 static int
1052 setname(argv)
1053     char **argv;
1054 {
1055     if (our_name[0] == 0) {
1056         strncpy(our_name, argv[0], MAXNAMELEN);
1057         our_name[MAXNAMELEN-1] = 0;
1058     }
1059     return 1;
1060 }
1061
1062 static int
1063 setuser(argv)
1064     char **argv;
1065 {
1066     strncpy(user, argv[0], MAXNAMELEN);
1067     user[MAXNAMELEN-1] = 0;
1068     return 1;
1069 }
1070
1071 static int
1072 setremote(argv)
1073     char **argv;
1074 {
1075     strncpy(remote_name, argv[0], MAXNAMELEN);
1076     remote_name[MAXNAMELEN-1] = 0;
1077     return 1;
1078 }
1079
1080 static int
1081 setauth()
1082 {
1083     auth_required = 1;
1084     return 1;
1085 }
1086
1087 static int
1088 setdefaultroute()
1089 {
1090     ipcp_wantoptions[0].default_route = 1;
1091     return 1;
1092 }
1093
1094 static int
1095 setproxyarp()
1096 {
1097     ipcp_wantoptions[0].proxy_arp = 1;
1098     return 1;
1099 }
1100
1101 static int
1102 setpersist()
1103 {
1104     persist = 1;
1105     return 1;
1106 }
1107
1108 static int
1109 setdologin()
1110 {
1111     uselogin = 1;
1112     return 1;
1113 }
1114
1115 /*
1116  * Functions to set timeouts, max transmits, etc.
1117  */
1118 static int
1119 setlcptimeout(argv)
1120     char **argv;
1121 {
1122     return int_option(*argv, &lcp_fsm[0].timeouttime, 0);
1123 }
1124
1125 static int setlcpterm(argv)
1126     char **argv;
1127 {
1128     return int_option(*argv, &lcp_fsm[0].maxtermtransmits, 0);
1129 }
1130
1131 static int setlcpconf(argv)
1132     char **argv;
1133 {
1134     return int_option(*argv, &lcp_fsm[0].maxconfreqtransmits, 0);
1135 }
1136
1137 static int setlcpfails(argv)
1138     char **argv;
1139 {
1140     return int_option(*argv, &lcp_fsm[0].maxnakloops, 0);
1141 }
1142
1143 static int setipcptimeout(argv)
1144     char **argv;
1145 {
1146     return int_option(*argv, &ipcp_fsm[0].timeouttime, 0);
1147 }
1148
1149 static int setipcpterm(argv)
1150     char **argv;
1151 {
1152     return int_option(*argv, &ipcp_fsm[0].maxtermtransmits, 0);
1153 }
1154
1155 static int setipcpconf(argv)
1156     char **argv;
1157 {
1158     return int_option(*argv, &ipcp_fsm[0].maxconfreqtransmits, 0);
1159 }
1160
1161 static int setipcpfails(argv)
1162     char **argv;
1163 {
1164     return int_option(*argv, &lcp_fsm[0].maxnakloops, 0);
1165 }
1166
1167 static int setpaptimeout(argv)
1168     char **argv;
1169 {
1170     return int_option(*argv, &upap[0].us_timeouttime, 0);
1171 }
1172
1173 static int setpapreqs(argv)
1174     char **argv;
1175 {
1176     return int_option(*argv, &upap[0].us_maxtransmits, 0);
1177 }
1178
1179 static int setchaptimeout(argv)
1180     char **argv;
1181 {
1182     return int_option(*argv, &chap[0].timeouttime, 0);
1183 }
1184
1185 static int setchapchal(argv)
1186     char **argv;
1187 {
1188     return int_option(*argv, &chap[0].max_transmits, 0);
1189 }
1190
1191 static int setchapintv(argv)
1192     char **argv;
1193 {
1194     return int_option(*argv, &chap[0].chal_interval, 0);
1195 }