]> git.ozlabs.org Git - ppp.git/blob - pppd/options.c
e7f95bf54f83d79b00370865febad357ab514c2f
[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.25 1995/10/27 03:39:14 paulus Exp $";
22 #endif
23
24 #include <stdio.h>
25 #include <errno.h>
26 #include <unistd.h>
27 #include <limits.h>
28 #include <stdlib.h>
29 #include <termios.h>
30 #include <syslog.h>
31 #include <string.h>
32 #include <netdb.h>
33 #include <pwd.h>
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include <netinet/in.h>
37
38 #include "pppd.h"
39 #include "pathnames.h"
40 #include "patchlevel.h"
41 #include "fsm.h"
42 #include "lcp.h"
43 #include "ipcp.h"
44 #include "upap.h"
45 #include "chap.h"
46 #include "ccp.h"
47
48 #include <net/ppp-comp.h>
49
50 #define FALSE   0
51 #define TRUE    1
52
53 #if defined(ultrix) || defined(NeXT)
54 char *strdup __P((char *));
55 #endif
56
57 #ifndef GIDSET_TYPE
58 #define GIDSET_TYPE     gid_t
59 #endif
60
61 /*
62  * Option variables and default values.
63  */
64 int     debug = 0;              /* Debug flag */
65 int     kdebugflag = 0;         /* Tell kernel to print debug messages */
66 int     default_device = 1;     /* Using /dev/tty or equivalent */
67 char    devnam[MAXPATHLEN] = "/dev/tty";        /* Device name */
68 int     crtscts = 0;            /* Use hardware flow control */
69 int     modem = 1;              /* Use modem control lines */
70 int     inspeed = 0;            /* Input/Output speed requested */
71 u_int32_t netmask = 0;          /* IP netmask to set on interface */
72 int     lockflag = 0;           /* Create lock file to lock the serial dev */
73 int     nodetach = 0;           /* Don't detach from controlling tty */
74 char    *connector = NULL;      /* Script to establish physical link */
75 char    *disconnector = NULL;   /* Script to disestablish physical link */
76 char    user[MAXNAMELEN];       /* Username for PAP */
77 char    passwd[MAXSECRETLEN];   /* Password for PAP */
78 int     auth_required = 0;      /* Peer is required to authenticate */
79 int     defaultroute = 0;       /* assign default route through interface */
80 int     proxyarp = 0;           /* Set up proxy ARP entry for peer */
81 int     persist = 0;            /* Reopen link after it goes down */
82 int     uselogin = 0;           /* Use /etc/passwd for checking PAP */
83 int     lcp_echo_interval = 0;  /* Interval between LCP echo-requests */
84 int     lcp_echo_fails = 0;     /* Tolerance to unanswered echo-requests */
85 char    our_name[MAXNAMELEN];   /* Our name for authentication purposes */
86 char    remote_name[MAXNAMELEN]; /* Peer's name for authentication */
87 int     usehostname = 0;        /* Use hostname for our_name */
88 int     disable_defaultip = 0;  /* Don't use hostname for default IP adrs */
89 char    *ipparam = NULL;        /* Extra parameter for ip up/down scripts */
90 int     cryptpap;               /* Passwords in pap-secrets are encrypted */
91
92 #ifdef _linux_
93 int idle_time_limit = 0;
94 static int setidle __P((char **));
95 #endif
96
97 /*
98  * Prototypes
99  */
100 static int setdebug __P((void));
101 static int setkdebug __P((char **));
102 static int setpassive __P((void));
103 static int setsilent __P((void));
104 static int noopt __P((void));
105 static int setnovj __P((void));
106 static int setnovjccomp __P((void));
107 static int setvjslots __P((char **));
108 static int reqpap __P((void));
109 static int nopap __P((void));
110 static int setupapfile __P((char **));
111 static int nochap __P((void));
112 static int reqchap __P((void));
113 static int setspeed __P((char *));
114 static int noaccomp __P((void));
115 static int noasyncmap __P((void));
116 static int noipaddr __P((void));
117 static int nomagicnumber __P((void));
118 static int setasyncmap __P((char **));
119 static int setescape __P((char **));
120 static int setmru __P((char **));
121 static int setmtu __P((char **));
122 static int nomru __P((void));
123 static int nopcomp __P((void));
124 static int setconnector __P((char **));
125 static int setdisconnector __P((char **));
126 static int setdomain __P((char **));
127 static int setnetmask __P((char **));
128 static int setcrtscts __P((void));
129 static int setnocrtscts __P((void));
130 static int setxonxoff __P((void));
131 static int setnodetach __P((void));
132 static int setmodem __P((void));
133 static int setlocal __P((void));
134 static int setlock __P((void));
135 static int setname __P((char **));
136 static int setuser __P((char **));
137 static int setremote __P((char **));
138 static int setauth __P((void));
139 static int readfile __P((char **));
140 static int setdefaultroute __P((void));
141 static int setnodefaultroute __P((void));
142 static int setproxyarp __P((void));
143 static int setnoproxyarp __P((void));
144 static int setpersist __P((void));
145 static int setdologin __P((void));
146 static int setusehostname __P((void));
147 static int setnoipdflt __P((void));
148 static int setlcptimeout __P((char **));
149 static int setlcpterm __P((char **));
150 static int setlcpconf __P((char **));
151 static int setlcpfails __P((char **));
152 static int setipcptimeout __P((char **));
153 static int setipcpterm __P((char **));
154 static int setipcpconf __P((char **));
155 static int setipcpfails __P((char **));
156 static int setpaptimeout __P((char **));
157 static int setpapreqs __P((char **));
158 static int setpapreqtime __P((char **));
159 static int setchaptimeout __P((char **));
160 static int setchapchal __P((char **));
161 static int setchapintv __P((char **));
162 static int setipcpaccl __P((void));
163 static int setipcpaccr __P((void));
164 static int setlcpechointv __P((char **));
165 static int setlcpechofails __P((char **));
166 static int setbsdcomp __P((char **));
167 static int setnobsdcomp __P((void));
168 static int setipparam __P((char **));
169 static int setpapcrypt __P((void));
170
171 static int number_option __P((char *, u_int32_t *, int));
172 static int readable __P((int fd));
173
174 void usage();
175
176 /*
177  * Valid arguments.
178  */
179 static struct cmd {
180     char *cmd_name;
181     int num_args;
182     int (*cmd_func)();
183 } cmds[] = {
184     {"-all", 0, noopt},         /* Don't request/allow any options */
185     {"-ac", 0, noaccomp},       /* Disable Address/Control compress */
186     {"-am", 0, noasyncmap},     /* Disable asyncmap negotiation */
187     {"-as", 1, setasyncmap},    /* set the desired async map */
188     {"-d", 0, setdebug},        /* Increase debugging level */
189     {"-detach", 0, setnodetach}, /* don't fork */
190     {"-ip", 0, noipaddr},       /* Disable IP address negotiation */
191     {"-mn", 0, nomagicnumber},  /* Disable magic number negotiation */
192     {"-mru", 0, nomru},         /* Disable mru negotiation */
193     {"-p", 0, setpassive},      /* Set passive mode */
194     {"-pc", 0, nopcomp},        /* Disable protocol field compress */
195     {"+ua", 1, setupapfile},    /* Get PAP user and password from file */
196     {"+pap", 0, reqpap},        /* Require PAP auth from peer */
197     {"-pap", 0, nopap},         /* Don't allow UPAP authentication with peer */
198     {"+chap", 0, reqchap},      /* Require CHAP authentication from peer */
199     {"-chap", 0, nochap},       /* Don't allow CHAP authentication with peer */
200     {"-vj", 0, setnovj},        /* disable VJ compression */
201     {"-vjccomp", 0, setnovjccomp}, /* disable VJ connection-ID compression */
202     {"vj-max-slots", 1, setvjslots}, /* Set maximum VJ header slots */
203     {"asyncmap", 1, setasyncmap}, /* set the desired async map */
204     {"escape", 1, setescape},   /* set chars to escape on transmission */
205     {"connect", 1, setconnector}, /* A program to set up a connection */
206     {"disconnect", 1, setdisconnector}, /* program to disconnect serial dev. */
207     {"crtscts", 0, setcrtscts}, /* set h/w flow control */
208     {"-crtscts", 0, setnocrtscts}, /* clear h/w flow control */
209     {"xonxoff", 0, setxonxoff}, /* set s/w flow control */
210     {"debug", 0, setdebug},     /* Increase debugging level */
211     {"kdebug", 1, setkdebug},   /* Enable kernel-level debugging */
212     {"domain", 1, setdomain},   /* Add given domain name to hostname*/
213     {"mru", 1, setmru},         /* Set MRU value for negotiation */
214     {"mtu", 1, setmtu},         /* Set our MTU */
215     {"netmask", 1, setnetmask}, /* set netmask */
216     {"passive", 0, setpassive}, /* Set passive mode */
217     {"silent", 0, setsilent},   /* Set silent mode */
218     {"modem", 0, setmodem},     /* Use modem control lines */
219     {"local", 0, setlocal},     /* Don't use modem control lines */
220     {"lock", 0, setlock},       /* Lock serial device (with lock file) */
221     {"name", 1, setname},       /* Set local name for authentication */
222     {"user", 1, setuser},       /* Set username for PAP auth with peer */
223     {"usehostname", 0, setusehostname}, /* Must use hostname for auth. */
224     {"remotename", 1, setremote}, /* Set remote name for authentication */
225     {"auth", 0, setauth},       /* Require authentication from peer */
226     {"file", 1, readfile},      /* Take options from a file */
227     {"defaultroute", 0, setdefaultroute}, /* Add default route */
228     {"-defaultroute", 0, setnodefaultroute}, /* disable defaultroute option */
229     {"proxyarp", 0, setproxyarp}, /* Add proxy ARP entry */
230     {"-proxyarp", 0, setnoproxyarp}, /* disable proxyarp option */
231     {"persist", 0, setpersist}, /* Keep on reopening connection after close */
232     {"login", 0, setdologin},   /* Use system password database for UPAP */
233     {"noipdefault", 0, setnoipdflt}, /* Don't use name for default IP adrs */
234     {"lcp-echo-failure", 1, setlcpechofails}, /* consecutive echo failures */
235     {"lcp-echo-interval", 1, setlcpechointv}, /* time for lcp echo events */
236     {"lcp-restart", 1, setlcptimeout}, /* Set timeout for LCP */
237     {"lcp-max-terminate", 1, setlcpterm}, /* Set max #xmits for term-reqs */
238     {"lcp-max-configure", 1, setlcpconf}, /* Set max #xmits for conf-reqs */
239     {"lcp-max-failure", 1, setlcpfails}, /* Set max #conf-naks for LCP */
240     {"ipcp-restart", 1, setipcptimeout}, /* Set timeout for IPCP */
241     {"ipcp-max-terminate", 1, setipcpterm}, /* Set max #xmits for term-reqs */
242     {"ipcp-max-configure", 1, setipcpconf}, /* Set max #xmits for conf-reqs */
243     {"ipcp-max-failure", 1, setipcpfails}, /* Set max #conf-naks for IPCP */
244     {"pap-restart", 1, setpaptimeout},  /* Set retransmit timeout for PAP */
245     {"pap-max-authreq", 1, setpapreqs}, /* Set max #xmits for auth-reqs */
246     {"pap-timeout", 1, setpapreqtime},  /* Set time limit for peer PAP auth. */
247     {"chap-restart", 1, setchaptimeout}, /* Set timeout for CHAP */
248     {"chap-max-challenge", 1, setchapchal}, /* Set max #xmits for challenge */
249     {"chap-interval", 1, setchapintv}, /* Set interval for rechallenge */
250     {"ipcp-accept-local", 0, setipcpaccl}, /* Accept peer's address for us */
251     {"ipcp-accept-remote", 0, setipcpaccr}, /* Accept peer's address for it */
252     {"bsdcomp", 1, setbsdcomp},         /* request BSD-Compress */
253     {"-bsdcomp", 0, setnobsdcomp},      /* don't allow BSD-Compress */
254     {"ipparam", 1, setipparam},         /* set ip script parameter */
255     {"papcrypt", 0, setpapcrypt},       /* PAP passwords encrypted */
256 #ifdef _linux_
257     {"idle-disconnect", 1, setidle}, /* seconds for disconnect of idle IP */
258 #endif
259     {NULL, 0, NULL}
260 };
261
262
263 #ifndef IMPLEMENTATION
264 #define IMPLEMENTATION ""
265 #endif
266
267 static char *usage_string = "\
268 pppd version %s patch level %d%s\n\
269 Usage: %s [ arguments ], where arguments are:\n\
270         <device>        Communicate over the named device\n\
271         <speed>         Set the baud rate to <speed>\n\
272         <loc>:<rem>     Set the local and/or remote interface IP\n\
273                         addresses.  Either one may be omitted.\n\
274         asyncmap <n>    Set the desired async map to hex <n>\n\
275         auth            Require authentication from peer\n\
276         connect <p>     Invoke shell command <p> to set up the serial line\n\
277         crtscts         Use hardware RTS/CTS flow control\n\
278         defaultroute    Add default route through interface\n\
279         file <f>        Take options from file <f>\n\
280         modem           Use modem control lines\n\
281         mru <n>         Set MRU value to <n> for negotiation\n\
282         netmask <n>     Set interface netmask to <n>\n\
283 See pppd(8) for more options.\n\
284 ";
285
286
287 /*
288  * parse_args - parse a string of arguments, from the command
289  * line or from a file.
290  */
291 int
292 parse_args(argc, argv)
293     int argc;
294     char **argv;
295 {
296     char *arg, *val;
297     struct cmd *cmdp;
298     int ret;
299
300     while (argc > 0) {
301         arg = *argv++;
302         --argc;
303
304         /*
305          * First see if it's a command.
306          */
307         for (cmdp = cmds; cmdp->cmd_name; cmdp++)
308             if (!strcmp(arg, cmdp->cmd_name))
309                 break;
310
311         if (cmdp->cmd_name != NULL) {
312             if (argc < cmdp->num_args) {
313                 fprintf(stderr, "Too few parameters for command %s\n", arg);
314                 return 0;
315             }
316             if (!(*cmdp->cmd_func)(argv))
317                 return 0;
318             argc -= cmdp->num_args;
319             argv += cmdp->num_args;
320
321         } else {
322             /*
323              * Maybe a tty name, speed or IP address?
324              */
325             if ((ret = setdevname(arg)) == 0
326                 && (ret = setspeed(arg)) == 0
327                 && (ret = setipaddr(arg)) == 0) {
328                 fprintf(stderr, "%s: unrecognized command\n", arg);
329                 usage();
330                 return 0;
331             }
332             if (ret < 0)        /* error */
333                 return 0;
334         }
335     }
336     return 1;
337 }
338
339 /*
340  * usage - print out a message telling how to use the program.
341  */
342 void
343 usage()
344 {
345     fprintf(stderr, usage_string, VERSION, PATCHLEVEL, IMPLEMENTATION,
346             progname);
347 }
348
349 /*
350  * options_from_file - Read a string of options from a file,
351  * and interpret them.
352  */
353 int
354 options_from_file(filename, must_exist, check_prot)
355     char *filename;
356     int must_exist;
357     int check_prot;
358 {
359     FILE *f;
360     int i, newline, ret;
361     struct cmd *cmdp;
362     char *argv[MAXARGS];
363     char args[MAXARGS][MAXWORDLEN];
364     char cmd[MAXWORDLEN];
365
366     if ((f = fopen(filename, "r")) == NULL) {
367         if (!must_exist && errno == ENOENT)
368             return 1;
369         perror(filename);
370         return 0;
371     }
372     if (check_prot && !readable(fileno(f))) {
373         fprintf(stderr, "%s: access denied\n", filename);
374         fclose(f);
375         return 0;
376     }
377
378     while (getword(f, cmd, &newline, filename)) {
379         /*
380          * First see if it's a command.
381          */
382         for (cmdp = cmds; cmdp->cmd_name; cmdp++)
383             if (!strcmp(cmd, cmdp->cmd_name))
384                 break;
385
386         if (cmdp->cmd_name != NULL) {
387             for (i = 0; i < cmdp->num_args; ++i) {
388                 if (!getword(f, args[i], &newline, filename)) {
389                     fprintf(stderr,
390                             "In file %s: too few parameters for command %s\n",
391                             filename, cmd);
392                     fclose(f);
393                     return 0;
394                 }
395                 argv[i] = args[i];
396             }
397             if (!(*cmdp->cmd_func)(argv)) {
398                 fclose(f);
399                 return 0;
400             }
401
402         } else {
403             /*
404              * Maybe a tty name, speed or IP address?
405              */
406             if ((ret = setdevname(cmd)) == 0
407                 && (ret = setspeed(cmd)) == 0
408                 && (ret = setipaddr(cmd)) == 0) {
409                 fprintf(stderr, "In file %s: unrecognized command %s\n",
410                         filename, cmd);
411                 fclose(f);
412                 return 0;
413             }
414             if (ret < 0)        /* error */
415                 return 0;
416         }
417     }
418     return 1;
419 }
420
421 /*
422  * options_from_user - See if the use has a ~/.ppprc file,
423  * and if so, interpret options from it.
424  */
425 int
426 options_from_user()
427 {
428     char *user, *path, *file;
429     int ret;
430     struct passwd *pw;
431
432     pw = getpwuid(getuid());
433     if (pw == NULL || (user = pw->pw_dir) == NULL || user[0] == 0)
434         return 1;
435     file = _PATH_USEROPT;
436     path = malloc(strlen(user) + strlen(file) + 2);
437     if (path == NULL)
438         novm("init file name");
439     strcpy(path, user);
440     strcat(path, "/");
441     strcat(path, file);
442     ret = options_from_file(path, 0, 1);
443     free(path);
444     return ret;
445 }
446
447 /*
448  * options_for_tty - See if an options file exists for the serial
449  * device, and if so, interpret options from it.
450  */
451 int
452 options_for_tty()
453 {
454     char *dev, *path;
455     int ret;
456
457     dev = strrchr(devnam, '/');
458     if (dev == NULL)
459         dev = devnam;
460     else
461         ++dev;
462     if (strcmp(dev, "tty") == 0)
463         return 1;               /* don't look for /etc/ppp/options.tty */
464     path = malloc(strlen(_PATH_TTYOPT) + strlen(dev) + 1);
465     if (path == NULL)
466         novm("tty init file name");
467     strcpy(path, _PATH_TTYOPT);
468     strcat(path, dev);
469     ret = options_from_file(path, 0, 0);
470     free(path);
471     return ret;
472 }
473
474 /*
475  * readable - check if a file is readable by the real user.
476  */
477 static int
478 readable(fd)
479     int fd;
480 {
481     uid_t uid;
482     int ngroups, i;
483     struct stat sbuf;
484     GIDSET_TYPE groups[NGROUPS_MAX];
485
486     uid = getuid();
487     if (uid == 0)
488         return 1;
489     if (fstat(fd, &sbuf) != 0)
490         return 0;
491     if (sbuf.st_uid == uid)
492         return sbuf.st_mode & S_IRUSR;
493     if (sbuf.st_gid == getgid())
494         return sbuf.st_mode & S_IRGRP;
495     ngroups = getgroups(NGROUPS_MAX, groups);
496     for (i = 0; i < ngroups; ++i)
497         if (sbuf.st_gid == groups[i])
498             return sbuf.st_mode & S_IRGRP;
499     return sbuf.st_mode & S_IROTH;
500 }
501
502 /*
503  * Read a word from a file.
504  * Words are delimited by white-space or by quotes (" or ').
505  * Quotes, white-space and \ may be escaped with \.
506  * \<newline> is ignored.
507  */
508
509 int
510 getword(f, word, newlinep, filename)
511     FILE *f;
512     char *word;
513     int *newlinep;
514     char *filename;
515 {
516     int c, len, escape;
517     int quoted, comment;
518     int value, digit, got, n;
519
520 #define isoctal(c) ((c) >= '0' && (c) < '8')
521
522     *newlinep = 0;
523     len = 0;
524     escape = 0;
525     comment = 0;
526
527     /*
528      * First skip white-space and comments.
529      */
530     for (;;) {
531         c = getc(f);
532         if (c == EOF)
533             break;
534
535         /*
536          * A newline means the end of a comment; backslash-newline
537          * is ignored.  Note that we cannot have escape && comment.
538          */
539         if (c == '\n') {
540             if (!escape) {
541                 *newlinep = 1;
542                 comment = 0;
543             } else
544                 escape = 0;
545             continue;
546         }
547
548         /*
549          * Ignore characters other than newline in a comment.
550          */
551         if (comment)
552             continue;
553
554         /*
555          * If this character is escaped, we have a word start.
556          */
557         if (escape)
558             break;
559
560         /*
561          * If this is the escape character, look at the next character.
562          */
563         if (c == '\\') {
564             escape = 1;
565             continue;
566         }
567
568         /*
569          * If this is the start of a comment, ignore the rest of the line.
570          */
571         if (c == '#') {
572             comment = 1;
573             continue;
574         }
575
576         /*
577          * A non-whitespace character is the start of a word.
578          */
579         if (!isspace(c))
580             break;
581     }
582
583     /*
584      * Save the delimiter for quoted strings.
585      */
586     if (!escape && (c == '"' || c == '\'')) {
587         quoted = c;
588         c = getc(f);
589     } else
590         quoted = 0;
591
592     /*
593      * Process characters until the end of the word.
594      */
595     while (c != EOF) {
596         if (escape) {
597             /*
598              * This character is escaped: backslash-newline is ignored,
599              * various other characters indicate particular values
600              * as for C backslash-escapes.
601              */
602             escape = 0;
603             if (c == '\n') {
604                 c = getc(f);
605                 continue;
606             }
607
608             got = 0;
609             switch (c) {
610             case 'a':
611                 value = '\a';
612                 break;
613             case 'b':
614                 value = '\b';
615                 break;
616             case 'f':
617                 value = '\f';
618                 break;
619             case 'n':
620                 value = '\n';
621                 break;
622             case 'r':
623                 value = '\r';
624                 break;
625             case 's':
626                 value = ' ';
627                 break;
628             case 't':
629                 value = '\t';
630                 break;
631
632             default:
633                 if (isoctal(c)) {
634                     /*
635                      * \ddd octal sequence
636                      */
637                     value = 0;
638                     for (n = 0; n < 3 && isoctal(c); ++n) {
639                         value = (value << 3) + (c & 07);
640                         c = getc(f);
641                     }
642                     got = 1;
643                     break;
644                 }
645
646                 if (c == 'x') {
647                     /*
648                      * \x<hex_string> sequence
649                      */
650                     value = 0;
651                     c = getc(f);
652                     for (n = 0; n < 2 && isxdigit(c); ++n) {
653                         digit = toupper(c) - '0';
654                         if (digit > 10)
655                             digit += '0' + 10 - 'A';
656                         value = (value << 4) + digit;
657                         c = getc (f);
658                     }
659                     got = 1;
660                     break;
661                 }
662
663                 /*
664                  * Otherwise the character stands for itself.
665                  */
666                 value = c;
667                 break;
668             }
669
670             /*
671              * Store the resulting character for the escape sequence.
672              */
673             if (len < MAXWORDLEN-1)
674                 word[len] = value;
675             ++len;
676
677             if (!got)
678                 c = getc(f);
679             continue;
680
681         }
682
683         /*
684          * Not escaped: see if we've reached the end of the word.
685          */
686         if (quoted) {
687             if (c == quoted)
688                 break;
689         } else {
690             if (isspace(c) || c == '#') {
691                 ungetc (c, f);
692                 break;
693             }
694         }
695
696         /*
697          * Backslash starts an escape sequence.
698          */
699         if (c == '\\') {
700             escape = 1;
701             c = getc(f);
702             continue;
703         }
704
705         /*
706          * An ordinary character: store it in the word and get another.
707          */
708         if (len < MAXWORDLEN-1)
709             word[len] = c;
710         ++len;
711
712         c = getc(f);
713     }
714
715     /*
716      * End of the word: check for errors.
717      */
718     if (c == EOF) {
719         if (ferror(f)) {
720             if (errno == 0)
721                 errno = EIO;
722             perror(filename);
723             die(1);
724         }
725         /*
726          * If len is zero, then we didn't find a word before the
727          * end of the file.
728          */
729         if (len == 0)
730             return 0;
731     }
732
733     /*
734      * Warn if the word was too long, and append a terminating null.
735      */
736     if (len >= MAXWORDLEN) {
737         fprintf(stderr, "%s: warning: word in file %s too long (%.20s...)\n",
738                 progname, filename, word);
739         len = MAXWORDLEN - 1;
740     }
741     word[len] = 0;
742
743     return 1;
744
745 #undef isoctal
746
747 }
748
749 /*
750  * number_option - parse an unsigned numeric parameter for an option.
751  */
752 static int
753 number_option(str, valp, base)
754     char *str;
755     u_int32_t *valp;
756     int base;
757 {
758     char *ptr;
759
760     *valp = strtoul(str, &ptr, base);
761     if (ptr == str) {
762         fprintf(stderr, "%s: invalid number: %s\n", progname, str);
763         return 0;
764     }
765     return 1;
766 }
767
768
769 /*
770  * int_option - like number_option, but valp is int *,
771  * the base is assumed to be 0, and *valp is not changed
772  * if there is an error.
773  */
774 static int
775 int_option(str, valp)
776     char *str;
777     int *valp;
778 {
779     u_int32_t v;
780
781     if (!number_option(str, &v, 0))
782         return 0;
783     *valp = (int) v;
784     return 1;
785 }
786
787
788 /*
789  * The following procedures execute commands.
790  */
791
792 /*
793  * readfile - take commands from a file.
794  */
795 static int
796 readfile(argv)
797     char **argv;
798 {
799     return options_from_file(*argv, 1, 1);
800 }
801
802 /*
803  * setdebug - Set debug (command line argument).
804  */
805 static int
806 setdebug()
807 {
808     debug++;
809     return (1);
810 }
811
812 /*
813  * setkdebug - Set kernel debugging level.
814  */
815 static int
816 setkdebug(argv)
817     char **argv;
818 {
819     return int_option(*argv, &kdebugflag);
820 }
821
822 /*
823  * noopt - Disable all options.
824  */
825 static int
826 noopt()
827 {
828     BZERO((char *) &lcp_wantoptions[0], sizeof (struct lcp_options));
829     BZERO((char *) &lcp_allowoptions[0], sizeof (struct lcp_options));
830     BZERO((char *) &ipcp_wantoptions[0], sizeof (struct ipcp_options));
831     BZERO((char *) &ipcp_allowoptions[0], sizeof (struct ipcp_options));
832     return (1);
833 }
834
835 /*
836  * noaccomp - Disable Address/Control field compression negotiation.
837  */
838 static int
839 noaccomp()
840 {
841     lcp_wantoptions[0].neg_accompression = 0;
842     lcp_allowoptions[0].neg_accompression = 0;
843     return (1);
844 }
845
846
847 /*
848  * noasyncmap - Disable async map negotiation.
849  */
850 static int
851 noasyncmap()
852 {
853     lcp_wantoptions[0].neg_asyncmap = 0;
854     lcp_allowoptions[0].neg_asyncmap = 0;
855     return (1);
856 }
857
858
859 /*
860  * noipaddr - Disable IP address negotiation.
861  */
862 static int
863 noipaddr()
864 {
865     ipcp_wantoptions[0].neg_addr = 0;
866     ipcp_allowoptions[0].neg_addr = 0;
867     return (1);
868 }
869
870
871 /*
872  * nomagicnumber - Disable magic number negotiation.
873  */
874 static int
875 nomagicnumber()
876 {
877     lcp_wantoptions[0].neg_magicnumber = 0;
878     lcp_allowoptions[0].neg_magicnumber = 0;
879     return (1);
880 }
881
882
883 /*
884  * nomru - Disable mru negotiation.
885  */
886 static int
887 nomru()
888 {
889     lcp_wantoptions[0].neg_mru = 0;
890     lcp_allowoptions[0].neg_mru = 0;
891     return (1);
892 }
893
894
895 /*
896  * setmru - Set MRU for negotiation.
897  */
898 static int
899 setmru(argv)
900     char **argv;
901 {
902     u_int32_t mru;
903
904     if (!number_option(*argv, &mru, 0))
905         return 0;
906     lcp_wantoptions[0].mru = mru;
907     lcp_wantoptions[0].neg_mru = 1;
908     return (1);
909 }
910
911
912 /*
913  * setmru - Set the largest MTU we'll use.
914  */
915 static int
916 setmtu(argv)
917     char **argv;
918 {
919     u_int32_t mtu;
920
921     if (!number_option(*argv, &mtu, 0))
922         return 0;
923     if (mtu < MINMRU || mtu > MAXMRU) {
924         fprintf(stderr, "mtu option value of %ld is too %s\n", mtu,
925                 (mtu < MINMRU? "small": "large"));
926         return 0;
927     }
928     lcp_allowoptions[0].mru = mtu;
929     return (1);
930 }
931
932
933 /*
934  * nopcomp - Disable Protocol field compression negotiation.
935  */
936 static int
937 nopcomp()
938 {
939     lcp_wantoptions[0].neg_pcompression = 0;
940     lcp_allowoptions[0].neg_pcompression = 0;
941     return (1);
942 }
943
944
945 /*
946  * setpassive - Set passive mode (don't give up if we time out sending
947  * LCP configure-requests).
948  */
949 static int
950 setpassive()
951 {
952     lcp_wantoptions[0].passive = 1;
953     return (1);
954 }
955
956
957 /*
958  * setsilent - Set silent mode (don't start sending LCP configure-requests
959  * until we get one from the peer).
960  */
961 static int
962 setsilent()
963 {
964     lcp_wantoptions[0].silent = 1;
965     return 1;
966 }
967
968
969 /*
970  * nopap - Disable PAP authentication with peer.
971  */
972 static int
973 nopap()
974 {
975     lcp_allowoptions[0].neg_upap = 0;
976     return (1);
977 }
978
979
980 /*
981  * reqpap - Require PAP authentication from peer.
982  */
983 static int
984 reqpap()
985 {
986     lcp_wantoptions[0].neg_upap = 1;
987     auth_required = 1;
988     return 1;
989 }
990
991
992 /*
993  * setupapfile - specifies UPAP info for authenticating with peer.
994  */
995 static int
996 setupapfile(argv)
997     char **argv;
998 {
999     FILE * ufile;
1000     int l;
1001
1002     lcp_allowoptions[0].neg_upap = 1;
1003
1004     /* open user info file */
1005     if ((ufile = fopen(*argv, "r")) == NULL) {
1006         fprintf(stderr, "unable to open user login data file %s\n", *argv);
1007         return 0;
1008     }
1009     if (!readable(fileno(ufile))) {
1010         fprintf(stderr, "%s: access denied\n", *argv);
1011         return 0;
1012     }
1013     check_access(ufile, *argv);
1014
1015     /* get username */
1016     if (fgets(user, MAXNAMELEN - 1, ufile) == NULL
1017         || fgets(passwd, MAXSECRETLEN - 1, ufile) == NULL){
1018         fprintf(stderr, "Unable to read user login data file %s.\n", *argv);
1019         return 0;
1020     }
1021     fclose(ufile);
1022
1023     /* get rid of newlines */
1024     l = strlen(user);
1025     if (l > 0 && user[l-1] == '\n')
1026         user[l-1] = 0;
1027     l = strlen(passwd);
1028     if (l > 0 && passwd[l-1] == '\n')
1029         passwd[l-1] = 0;
1030
1031     return (1);
1032 }
1033
1034
1035 /*
1036  * nochap - Disable CHAP authentication with peer.
1037  */
1038 static int
1039 nochap()
1040 {
1041     lcp_allowoptions[0].neg_chap = 0;
1042     return (1);
1043 }
1044
1045
1046 /*
1047  * reqchap - Require CHAP authentication from peer.
1048  */
1049 static int
1050 reqchap()
1051 {
1052     lcp_wantoptions[0].neg_chap = 1;
1053     auth_required = 1;
1054     return (1);
1055 }
1056
1057
1058 /*
1059  * setnovj - disable vj compression
1060  */
1061 static int
1062 setnovj()
1063 {
1064     ipcp_wantoptions[0].neg_vj = 0;
1065     ipcp_allowoptions[0].neg_vj = 0;
1066     return (1);
1067 }
1068
1069
1070 /*
1071  * setnovjccomp - disable VJ connection-ID compression
1072  */
1073 static int
1074 setnovjccomp()
1075 {
1076     ipcp_wantoptions[0].cflag = 0;
1077     ipcp_allowoptions[0].cflag = 0;
1078     return 1;
1079 }
1080
1081
1082 /*
1083  * setvjslots - set maximum number of connection slots for VJ compression
1084  */
1085 static int
1086 setvjslots(argv)
1087     char **argv;
1088 {
1089     int value;
1090
1091     if (!int_option(*argv, &value))
1092         return 0;
1093     if (value < 2 || value > 16) {
1094         fprintf(stderr, "pppd: vj-max-slots value must be between 2 and 16\n");
1095         return 0;
1096     }
1097     ipcp_wantoptions [0].maxslotindex =
1098         ipcp_allowoptions[0].maxslotindex = value - 1;
1099     return 1;
1100 }
1101
1102
1103 /*
1104  * setconnector - Set a program to connect to a serial line
1105  */
1106 static int
1107 setconnector(argv)
1108     char **argv;
1109 {
1110     connector = strdup(*argv);
1111     if (connector == NULL)
1112         novm("connector string");
1113   
1114     return (1);
1115 }
1116
1117 /*
1118  * setdisconnector - Set a program to disconnect from the serial line
1119  */
1120 static int
1121 setdisconnector(argv)
1122     char **argv;
1123 {
1124     disconnector = strdup(*argv);
1125     if (disconnector == NULL)
1126         novm("disconnector string");
1127   
1128     return (1);
1129 }
1130
1131
1132 /*
1133  * setdomain - Set domain name to append to hostname 
1134  */
1135 static int
1136 setdomain(argv)
1137     char **argv;
1138 {
1139     gethostname(hostname, MAXNAMELEN);
1140     if (**argv != 0) {
1141         if (**argv != '.')
1142             strncat(hostname, ".", MAXNAMELEN - strlen(hostname));
1143         strncat(hostname, *argv, MAXNAMELEN - strlen(hostname));
1144     }
1145     hostname[MAXNAMELEN-1] = 0;
1146     return (1);
1147 }
1148
1149
1150 /*
1151  * setasyncmap - add bits to asyncmap (what we request peer to escape).
1152  */
1153 static int
1154 setasyncmap(argv)
1155     char **argv;
1156 {
1157     u_int32_t asyncmap;
1158
1159     if (!number_option(*argv, &asyncmap, 16))
1160         return 0;
1161     lcp_wantoptions[0].asyncmap |= asyncmap;
1162     lcp_wantoptions[0].neg_asyncmap = 1;
1163     return(1);
1164 }
1165
1166
1167 /*
1168  * setescape - add chars to the set we escape on transmission.
1169  */
1170 static int
1171 setescape(argv)
1172     char **argv;
1173 {
1174     int n, ret;
1175     char *p, *endp;
1176
1177     p = *argv;
1178     ret = 1;
1179     while (*p) {
1180         n = strtol(p, &endp, 16);
1181         if (p == endp) {
1182             fprintf(stderr, "%s: invalid hex number: %s\n", progname, p);
1183             return 0;
1184         }
1185         p = endp;
1186         if (n < 0 || 0x20 <= n && n <= 0x3F || n == 0x5E || n > 0xFF) {
1187             fprintf(stderr, "%s: can't escape character 0x%x\n", progname, n);
1188             ret = 0;
1189         } else
1190             xmit_accm[0][n >> 5] |= 1 << (n & 0x1F);
1191         while (*p == ',' || *p == ' ')
1192             ++p;
1193     }
1194     return ret;
1195 }
1196
1197
1198 /*
1199  * setspeed - Set the speed.
1200  */
1201 static int
1202 setspeed(arg)
1203     char *arg;
1204 {
1205     char *ptr;
1206     int spd;
1207
1208     spd = strtol(arg, &ptr, 0);
1209     if (ptr == arg || *ptr != 0 || spd == 0)
1210         return 0;
1211     inspeed = spd;
1212     return 1;
1213 }
1214
1215
1216 /*
1217  * setdevname - Set the device name.
1218  */
1219 int
1220 setdevname(cp)
1221     char *cp;
1222 {
1223     struct stat statbuf;
1224     char *tty, *ttyname();
1225     char dev[MAXPATHLEN];
1226   
1227     if (strncmp("/dev/", cp, 5) != 0) {
1228         strcpy(dev, "/dev/");
1229         strncat(dev, cp, MAXPATHLEN - 5);
1230         dev[MAXPATHLEN-1] = 0;
1231         cp = dev;
1232     }
1233
1234     /*
1235      * Check if there is a device by this name.
1236      */
1237     if (stat(cp, &statbuf) < 0) {
1238         if (errno == ENOENT)
1239             return 0;
1240         syslog(LOG_ERR, cp);
1241         return -1;
1242     }
1243   
1244     (void) strncpy(devnam, cp, MAXPATHLEN);
1245     devnam[MAXPATHLEN-1] = 0;
1246     default_device = FALSE;
1247   
1248     return 1;
1249 }
1250
1251
1252 /*
1253  * setipaddr - Set the IP address
1254  */
1255 int
1256 setipaddr(arg)
1257     char *arg;
1258 {
1259     struct hostent *hp;
1260     char *colon;
1261     u_int32_t local, remote;
1262     ipcp_options *wo = &ipcp_wantoptions[0];
1263   
1264     /*
1265      * IP address pair separated by ":".
1266      */
1267     if ((colon = strchr(arg, ':')) == NULL)
1268         return 0;
1269   
1270     /*
1271      * If colon first character, then no local addr.
1272      */
1273     if (colon != arg) {
1274         *colon = '\0';
1275         if ((local = inet_addr(arg)) == -1) {
1276             if ((hp = gethostbyname(arg)) == NULL) {
1277                 fprintf(stderr, "unknown host: %s\n", arg);
1278                 return -1;
1279             } else {
1280                 local = *(u_int32_t *)hp->h_addr;
1281                 if (our_name[0] == 0) {
1282                     strncpy(our_name, arg, MAXNAMELEN);
1283                     our_name[MAXNAMELEN-1] = 0;
1284                 }
1285             }
1286         }
1287         if (bad_ip_adrs(local)) {
1288             fprintf(stderr, "bad local IP address %s\n", ip_ntoa(local));
1289             return -1;
1290         }
1291         if (local != 0)
1292             wo->ouraddr = local;
1293         *colon = ':';
1294     }
1295   
1296     /*
1297      * If colon last character, then no remote addr.
1298      */
1299     if (*++colon != '\0') {
1300         if ((remote = inet_addr(colon)) == -1) {
1301             if ((hp = gethostbyname(colon)) == NULL) {
1302                 fprintf(stderr, "unknown host: %s\n", colon);
1303                 return -1;
1304             } else {
1305                 remote = *(u_int32_t *)hp->h_addr;
1306                 if (remote_name[0] == 0) {
1307                     strncpy(remote_name, colon, MAXNAMELEN);
1308                     remote_name[MAXNAMELEN-1] = 0;
1309                 }
1310             }
1311         }
1312         if (bad_ip_adrs(remote)) {
1313             fprintf(stderr, "bad remote IP address %s\n", ip_ntoa(remote));
1314             return -1;
1315         }
1316         if (remote != 0)
1317             wo->hisaddr = remote;
1318     }
1319
1320     return 1;
1321 }
1322
1323
1324 /*
1325  * setnoipdflt - disable setipdefault()
1326  */
1327 static int
1328 setnoipdflt()
1329 {
1330     disable_defaultip = 1;
1331     return 1;
1332 }
1333
1334
1335 /*
1336  * setipcpaccl - accept peer's idea of our address
1337  */
1338 static int
1339 setipcpaccl()
1340 {
1341     ipcp_wantoptions[0].accept_local = 1;
1342     return 1;
1343 }
1344
1345
1346 /*
1347  * setipcpaccr - accept peer's idea of its address
1348  */
1349 static int
1350 setipcpaccr()
1351 {
1352     ipcp_wantoptions[0].accept_remote = 1;
1353     return 1;
1354 }
1355
1356
1357 /*
1358  * setipdefault - default our local IP address based on our hostname.
1359  */
1360 void
1361 setipdefault()
1362 {
1363     struct hostent *hp;
1364     u_int32_t local;
1365     ipcp_options *wo = &ipcp_wantoptions[0];
1366
1367     /*
1368      * If local IP address already given, don't bother.
1369      */
1370     if (wo->ouraddr != 0 || disable_defaultip)
1371         return;
1372
1373     /*
1374      * Look up our hostname (possibly with domain name appended)
1375      * and take the first IP address as our local IP address.
1376      * If there isn't an IP address for our hostname, too bad.
1377      */
1378     wo->accept_local = 1;       /* don't insist on this default value */
1379     if ((hp = gethostbyname(hostname)) == NULL)
1380         return;
1381     local = *(u_int32_t *)hp->h_addr;
1382     if (local != 0 && !bad_ip_adrs(local))
1383         wo->ouraddr = local;
1384 }
1385
1386
1387 /*
1388  * setnetmask - set the netmask to be used on the interface.
1389  */
1390 static int
1391 setnetmask(argv)
1392     char **argv;
1393 {
1394     u_int32_t mask;
1395
1396     if ((mask = inet_addr(*argv)) == -1 || (netmask & ~mask) != 0) {
1397         fprintf(stderr, "Invalid netmask %s\n", *argv);
1398         return 0;
1399     }
1400
1401     netmask = mask;
1402     return (1);
1403 }
1404
1405 static int
1406 setcrtscts()
1407 {
1408     crtscts = 1;
1409     return (1);
1410 }
1411
1412 static int
1413 setnocrtscts()
1414 {
1415     crtscts = -1;
1416     return (1);
1417 }
1418
1419 static int
1420 setxonxoff()
1421 {
1422     lcp_wantoptions[0].asyncmap |= 0x000A0000;  /* escape ^S and ^Q */
1423     lcp_wantoptions[0].neg_asyncmap = 1;
1424
1425     crtscts = -2;
1426     return (1);
1427 }
1428
1429 static int
1430 setnodetach()
1431 {
1432     nodetach = 1;
1433     return (1);
1434 }
1435
1436 static int
1437 setmodem()
1438 {
1439     modem = 1;
1440     return 1;
1441 }
1442
1443 static int
1444 setlocal()
1445 {
1446     modem = 0;
1447     return 1;
1448 }
1449
1450 static int
1451 setlock()
1452 {
1453     lockflag = 1;
1454     return 1;
1455 }
1456
1457 static int
1458 setusehostname()
1459 {
1460     usehostname = 1;
1461     return 1;
1462 }
1463
1464 static int
1465 setname(argv)
1466     char **argv;
1467 {
1468     if (our_name[0] == 0) {
1469         strncpy(our_name, argv[0], MAXNAMELEN);
1470         our_name[MAXNAMELEN-1] = 0;
1471     }
1472     return 1;
1473 }
1474
1475 static int
1476 setuser(argv)
1477     char **argv;
1478 {
1479     strncpy(user, argv[0], MAXNAMELEN);
1480     user[MAXNAMELEN-1] = 0;
1481     return 1;
1482 }
1483
1484 static int
1485 setremote(argv)
1486     char **argv;
1487 {
1488     strncpy(remote_name, argv[0], MAXNAMELEN);
1489     remote_name[MAXNAMELEN-1] = 0;
1490     return 1;
1491 }
1492
1493 static int
1494 setauth()
1495 {
1496     auth_required = 1;
1497     return 1;
1498 }
1499
1500 static int
1501 setdefaultroute()
1502 {
1503     if (!ipcp_allowoptions[0].default_route) {
1504         fprintf(stderr, "%s: defaultroute option is disabled\n", progname);
1505         return 0;
1506     }
1507     ipcp_wantoptions[0].default_route = 1;
1508     return 1;
1509 }
1510
1511 static int
1512 setnodefaultroute()
1513 {
1514     ipcp_allowoptions[0].default_route = 0;
1515     ipcp_wantoptions[0].default_route = 0;
1516     return 1;
1517 }
1518
1519 static int
1520 setproxyarp()
1521 {
1522     if (!ipcp_allowoptions[0].proxy_arp) {
1523         fprintf(stderr, "%s: proxyarp option is disabled\n", progname);
1524         return 0;
1525     }
1526     ipcp_wantoptions[0].proxy_arp = 1;
1527     return 1;
1528 }
1529
1530 static int
1531 setnoproxyarp()
1532 {
1533     ipcp_wantoptions[0].proxy_arp = 0;
1534     ipcp_allowoptions[0].proxy_arp = 0;
1535     return 1;
1536 }
1537
1538 static int
1539 setpersist()
1540 {
1541     persist = 1;
1542     return 1;
1543 }
1544
1545 static int
1546 setdologin()
1547 {
1548     uselogin = 1;
1549     return 1;
1550 }
1551
1552 /*
1553  * Functions to set the echo interval for modem-less monitors
1554  */
1555
1556 static int
1557 setlcpechointv(argv)
1558     char **argv;
1559 {
1560     return int_option(*argv, &lcp_echo_interval);
1561 }
1562
1563 static int
1564 setlcpechofails(argv)
1565     char **argv;
1566 {
1567     return int_option(*argv, &lcp_echo_fails);
1568 }
1569
1570 /*
1571  * Functions to set timeouts, max transmits, etc.
1572  */
1573 static int
1574 setlcptimeout(argv)
1575     char **argv;
1576 {
1577     return int_option(*argv, &lcp_fsm[0].timeouttime);
1578 }
1579
1580 static int
1581 setlcpterm(argv)
1582     char **argv;
1583 {
1584     return int_option(*argv, &lcp_fsm[0].maxtermtransmits);
1585 }
1586
1587 static int
1588 setlcpconf(argv)
1589     char **argv;
1590 {
1591     return int_option(*argv, &lcp_fsm[0].maxconfreqtransmits);
1592 }
1593
1594 static int
1595 setlcpfails(argv)
1596     char **argv;
1597 {
1598     return int_option(*argv, &lcp_fsm[0].maxnakloops);
1599 }
1600
1601 static int
1602 setipcptimeout(argv)
1603     char **argv;
1604 {
1605     return int_option(*argv, &ipcp_fsm[0].timeouttime);
1606 }
1607
1608 static int
1609 setipcpterm(argv)
1610     char **argv;
1611 {
1612     return int_option(*argv, &ipcp_fsm[0].maxtermtransmits);
1613 }
1614
1615 static int
1616 setipcpconf(argv)
1617     char **argv;
1618 {
1619     return int_option(*argv, &ipcp_fsm[0].maxconfreqtransmits);
1620 }
1621
1622 static int
1623 setipcpfails(argv)
1624     char **argv;
1625 {
1626     return int_option(*argv, &lcp_fsm[0].maxnakloops);
1627 }
1628
1629 static int
1630 setpaptimeout(argv)
1631     char **argv;
1632 {
1633     return int_option(*argv, &upap[0].us_timeouttime);
1634 }
1635
1636 static int
1637 setpapreqtime(argv)
1638     char **argv;
1639 {
1640     return int_option(*argv, &upap[0].us_reqtimeout);
1641 }
1642
1643 static int
1644 setpapreqs(argv)
1645     char **argv;
1646 {
1647     return int_option(*argv, &upap[0].us_maxtransmits);
1648 }
1649
1650 static int
1651 setchaptimeout(argv)
1652     char **argv;
1653 {
1654     return int_option(*argv, &chap[0].timeouttime);
1655 }
1656
1657 static int
1658 setchapchal(argv)
1659     char **argv;
1660 {
1661     return int_option(*argv, &chap[0].max_transmits);
1662 }
1663
1664 static int
1665 setchapintv(argv)
1666     char **argv;
1667 {
1668     return int_option(*argv, &chap[0].chal_interval);
1669 }
1670
1671 static int
1672 setbsdcomp(argv)
1673     char **argv;
1674 {
1675     int rbits, abits;
1676     char *str, *endp;
1677
1678     str = *argv;
1679     abits = rbits = strtol(str, &endp, 0);
1680     if (endp != str && *endp == ',') {
1681         str = endp + 1;
1682         abits = strtol(str, &endp, 0);
1683     }
1684     if (*endp != 0 || endp == str) {
1685         fprintf(stderr, "%s: invalid argument format for bsdcomp option\n",
1686                 progname);
1687         return 0;
1688     }
1689     if (rbits != 0 && (rbits < BSD_MIN_BITS || rbits > BSD_MAX_BITS)
1690         || abits != 0 && (abits < BSD_MIN_BITS || abits > BSD_MAX_BITS)) {
1691         fprintf(stderr, "%s: bsdcomp option values must be 0 or %d .. %d\n",
1692                 progname, BSD_MIN_BITS, BSD_MAX_BITS);
1693         return 0;
1694     }
1695     if (rbits > 0) {
1696         ccp_wantoptions[0].bsd_compress = 1;
1697         ccp_wantoptions[0].bsd_bits = rbits;
1698     } else
1699         ccp_wantoptions[0].bsd_compress = 0;
1700     if (abits > 0) {
1701         ccp_allowoptions[0].bsd_compress = 1;
1702         ccp_allowoptions[0].bsd_bits = abits;
1703     } else
1704         ccp_allowoptions[0].bsd_compress = 0;
1705     return 1;
1706 }
1707
1708 static int
1709 setnobsdcomp()
1710 {
1711     ccp_wantoptions[0].bsd_compress = 0;
1712     ccp_allowoptions[0].bsd_compress = 0;
1713     return 1;
1714 }
1715
1716 static int
1717 setipparam(argv)
1718     char **argv;
1719 {
1720     ipparam = strdup(*argv);
1721     if (ipparam == NULL)
1722         novm("ipparam string");
1723
1724     return 1;
1725 }
1726
1727 static int
1728 setpapcrypt()
1729 {
1730     cryptpap = 1;
1731     return 1;
1732 }
1733
1734 #ifdef _linux_
1735 static int setidle (argv)
1736     char **argv;
1737 {
1738     return int_option(*argv, &idle_time_limit);
1739 }
1740 #endif