]> git.ozlabs.org Git - ppp.git/blob - pppd/options.c
update_link_stats(): treat link stats as unsigned, not signed
[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 #define RCSID   "$Id: options.c,v 1.88 2002/09/24 11:35:22 fcusack Exp $"
21
22 #include <ctype.h>
23 #include <stdio.h>
24 #include <errno.h>
25 #include <unistd.h>
26 #include <fcntl.h>
27 #include <stdlib.h>
28 #include <syslog.h>
29 #include <string.h>
30 #include <pwd.h>
31 #ifdef PLUGIN
32 #include <dlfcn.h>
33 #endif
34 #ifdef PPP_FILTER
35 #include <pcap.h>
36 #include <pcap-int.h>   /* XXX: To get struct pcap */
37 #endif
38
39 #include "pppd.h"
40 #include "pathnames.h"
41
42 #if defined(ultrix) || defined(NeXT)
43 char *strdup __P((char *));
44 #endif
45
46 static const char rcsid[] = RCSID;
47
48 struct option_value {
49     struct option_value *next;
50     const char *source;
51     char value[1];
52 };
53
54 /*
55  * Option variables and default values.
56  */
57 #ifdef PPP_FILTER
58 int     dflag = 0;              /* Tell libpcap we want debugging */
59 #endif
60 int     debug = 0;              /* Debug flag */
61 int     kdebugflag = 0;         /* Tell kernel to print debug messages */
62 int     default_device = 1;     /* Using /dev/tty or equivalent */
63 char    devnam[MAXPATHLEN];     /* Device name */
64 bool    nodetach = 0;           /* Don't detach from controlling tty */
65 bool    updetach = 0;           /* Detach once link is up */
66 int     maxconnect = 0;         /* Maximum connect time */
67 char    user[MAXNAMELEN];       /* Username for PAP */
68 char    passwd[MAXSECRETLEN];   /* Password for PAP */
69 bool    persist = 0;            /* Reopen link after it goes down */
70 char    our_name[MAXNAMELEN];   /* Our name for authentication purposes */
71 bool    demand = 0;             /* do dial-on-demand */
72 char    *ipparam = NULL;        /* Extra parameter for ip up/down scripts */
73 int     idle_time_limit = 0;    /* Disconnect if idle for this many seconds */
74 int     holdoff = 30;           /* # seconds to pause before reconnecting */
75 bool    holdoff_specified;      /* true if a holdoff value has been given */
76 int     log_to_fd = 1;          /* send log messages to this fd too */
77 bool    log_default = 1;        /* log_to_fd is default (stdout) */
78 int     maxfail = 10;           /* max # of unsuccessful connection attempts */
79 char    linkname[MAXPATHLEN];   /* logical name for link */
80 bool    tune_kernel;            /* may alter kernel settings */
81 int     connect_delay = 1000;   /* wait this many ms after connect script */
82 int     req_unit = -1;          /* requested interface unit */
83 bool    multilink = 0;          /* Enable multilink operation */
84 char    *bundle_name = NULL;    /* bundle name for multilink */
85 bool    dump_options;           /* print out option values */
86 bool    dryrun;                 /* print out option values and exit */
87 char    *domain;                /* domain name set by domain option */
88
89 #ifdef MAXOCTETS
90 unsigned int  maxoctets = 0;    /* default - no limit */
91 int maxoctets_dir = 0;       /* default - sum of traffic */
92 int maxoctets_timeout = 1;   /* default 1 second */ 
93 #endif
94
95
96 extern option_t auth_options[];
97 extern struct stat devstat;
98
99 #ifdef PPP_FILTER
100 struct  bpf_program pass_filter;/* Filter program for packets to pass */
101 struct  bpf_program active_filter; /* Filter program for link-active pkts */
102 pcap_t  pc;                     /* Fake struct pcap so we can compile expr */
103 #endif
104
105 char *current_option;           /* the name of the option being parsed */
106 int  privileged_option;         /* set iff the current option came from root */
107 char *option_source;            /* string saying where the option came from */
108 int  option_priority = OPRIO_CFGFILE; /* priority of the current options */
109 bool devnam_fixed;              /* can no longer change device name */
110
111 static int logfile_fd = -1;     /* fd opened for log file */
112 static char logfile_name[MAXPATHLEN];   /* name of log file */
113
114 /*
115  * Prototypes
116  */
117 static int setdomain __P((char **));
118 static int readfile __P((char **));
119 static int callfile __P((char **));
120 static int showversion __P((char **));
121 static int showhelp __P((char **));
122 static void usage __P((void));
123 static int setlogfile __P((char **));
124 #ifdef PLUGIN
125 static int loadplugin __P((char **));
126 #endif
127
128 #ifdef PPP_FILTER
129 static int setpassfilter __P((char **));
130 static int setactivefilter __P((char **));
131 #endif
132
133 #ifdef MAXOCTETS
134 static int setmodir __P((char **));
135 #endif
136
137 static option_t *find_option __P((const char *name));
138 static int process_option __P((option_t *, char *, char **));
139 static int n_arguments __P((option_t *));
140 static int number_option __P((char *, u_int32_t *, int));
141
142 /*
143  * Structure to store extra lists of options.
144  */
145 struct option_list {
146     option_t *options;
147     struct option_list *next;
148 };
149
150 static struct option_list *extra_options = NULL;
151
152 /*
153  * Valid arguments.
154  */
155 option_t general_options[] = {
156     { "debug", o_int, &debug,
157       "Increase debugging level", OPT_INC | OPT_NOARG | 1 },
158     { "-d", o_int, &debug,
159       "Increase debugging level",
160       OPT_ALIAS | OPT_INC | OPT_NOARG | 1 },
161
162     { "kdebug", o_int, &kdebugflag,
163       "Set kernel driver debug level", OPT_PRIO },
164
165     { "nodetach", o_bool, &nodetach,
166       "Don't detach from controlling tty", OPT_PRIO | 1 },
167     { "-detach", o_bool, &nodetach,
168       "Don't detach from controlling tty", OPT_ALIAS | OPT_PRIOSUB | 1 },
169     { "updetach", o_bool, &updetach,
170       "Detach from controlling tty once link is up",
171       OPT_PRIOSUB | OPT_A2CLR | 1, &nodetach },
172
173     { "holdoff", o_int, &holdoff,
174       "Set time in seconds before retrying connection", OPT_PRIO },
175
176     { "idle", o_int, &idle_time_limit,
177       "Set time in seconds before disconnecting idle link", OPT_PRIO },
178
179     { "maxconnect", o_int, &maxconnect,
180       "Set connection time limit",
181       OPT_PRIO | OPT_LLIMIT | OPT_NOINCR | OPT_ZEROINF },
182
183     { "domain", o_special, (void *)setdomain,
184       "Add given domain name to hostname",
185       OPT_PRIO | OPT_PRIV | OPT_A2STRVAL, &domain },
186
187     { "file", o_special, (void *)readfile,
188       "Take options from a file", OPT_NOPRINT },
189     { "call", o_special, (void *)callfile,
190       "Take options from a privileged file", OPT_NOPRINT },
191
192     { "persist", o_bool, &persist,
193       "Keep on reopening connection after close", OPT_PRIO | 1 },
194     { "nopersist", o_bool, &persist,
195       "Turn off persist option", OPT_PRIOSUB },
196
197     { "demand", o_bool, &demand,
198       "Dial on demand", OPT_INITONLY | 1, &persist },
199
200     { "--version", o_special_noarg, (void *)showversion,
201       "Show version number" },
202     { "--help", o_special_noarg, (void *)showhelp,
203       "Show brief listing of options" },
204     { "-h", o_special_noarg, (void *)showhelp,
205       "Show brief listing of options", OPT_ALIAS },
206
207     { "logfile", o_special, (void *)setlogfile,
208       "Append log messages to this file",
209       OPT_PRIO | OPT_A2STRVAL | OPT_STATIC, &logfile_name },
210     { "logfd", o_int, &log_to_fd,
211       "Send log messages to this file descriptor",
212       OPT_PRIOSUB | OPT_A2CLR, &log_default },
213     { "nolog", o_int, &log_to_fd,
214       "Don't send log messages to any file",
215       OPT_PRIOSUB | OPT_NOARG | OPT_VAL(-1) },
216     { "nologfd", o_int, &log_to_fd,
217       "Don't send log messages to any file descriptor",
218       OPT_PRIOSUB | OPT_ALIAS | OPT_NOARG | OPT_VAL(-1) },
219
220     { "linkname", o_string, linkname,
221       "Set logical name for link",
222       OPT_PRIO | OPT_PRIV | OPT_STATIC, NULL, MAXPATHLEN },
223
224     { "maxfail", o_int, &maxfail,
225       "Maximum number of unsuccessful connection attempts to allow",
226       OPT_PRIO },
227
228     { "ktune", o_bool, &tune_kernel,
229       "Alter kernel settings as necessary", OPT_PRIO | 1 },
230     { "noktune", o_bool, &tune_kernel,
231       "Don't alter kernel settings", OPT_PRIOSUB },
232
233     { "connect-delay", o_int, &connect_delay,
234       "Maximum time (in ms) to wait after connect script finishes",
235       OPT_PRIO },
236
237     { "unit", o_int, &req_unit,
238       "PPP interface unit number to use if possible",
239       OPT_PRIO | OPT_LLIMIT, 0, 0 },
240
241     { "dump", o_bool, &dump_options,
242       "Print out option values after parsing all options", 1 },
243     { "dryrun", o_bool, &dryrun,
244       "Stop after parsing, printing, and checking options", 1 },
245
246 #ifdef HAVE_MULTILINK
247     { "multilink", o_bool, &multilink,
248       "Enable multilink operation", OPT_PRIO | 1 },
249     { "mp", o_bool, &multilink,
250       "Enable multilink operation", OPT_PRIOSUB | OPT_ALIAS | 1 },
251     { "nomultilink", o_bool, &multilink,
252       "Disable multilink operation", OPT_PRIOSUB | 0 },
253     { "nomp", o_bool, &multilink,
254       "Disable multilink operation", OPT_PRIOSUB | OPT_ALIAS | 0 },
255
256     { "bundle", o_string, &bundle_name,
257       "Bundle name for multilink", OPT_PRIO },
258 #endif /* HAVE_MULTILINK */
259
260 #ifdef PLUGIN
261     { "plugin", o_special, (void *)loadplugin,
262       "Load a plug-in module into pppd", OPT_PRIV | OPT_A2LIST },
263 #endif
264
265 #ifdef PPP_FILTER
266     { "pdebug", o_int, &dflag,
267       "libpcap debugging", OPT_PRIO },
268
269     { "pass-filter", 1, setpassfilter,
270       "set filter for packets to pass", OPT_PRIO },
271
272     { "active-filter", 1, setactivefilter,
273       "set filter for active pkts", OPT_PRIO },
274 #endif
275
276 #ifdef MAXOCTETS
277     { "maxoctets", o_int, &maxoctets,
278       "Set connection traffic limit",
279       OPT_PRIO | OPT_LLIMIT | OPT_NOINCR | OPT_ZEROINF },
280     { "mo", o_int, &maxoctets,
281       "Set connection traffic limit",
282       OPT_ALIAS | OPT_PRIO | OPT_LLIMIT | OPT_NOINCR | OPT_ZEROINF },
283     { "mo-direction", o_special, setmodir,
284       "Set direction for limit traffic (sum,in,out,max)" },
285     { "mo-timeout", o_int, &maxoctets_timeout,
286       "Check for traffic limit every N seconds", OPT_PRIO | OPT_LLIMIT | 1 },
287 #endif
288
289     { NULL }
290 };
291
292 #ifndef IMPLEMENTATION
293 #define IMPLEMENTATION ""
294 #endif
295
296 static char *usage_string = "\
297 pppd version %s\n\
298 Usage: %s [ options ], where options are:\n\
299         <device>        Communicate over the named device\n\
300         <speed>         Set the baud rate to <speed>\n\
301         <loc>:<rem>     Set the local and/or remote interface IP\n\
302                         addresses.  Either one may be omitted.\n\
303         asyncmap <n>    Set the desired async map to hex <n>\n\
304         auth            Require authentication from peer\n\
305         connect <p>     Invoke shell command <p> to set up the serial line\n\
306         crtscts         Use hardware RTS/CTS flow control\n\
307         defaultroute    Add default route through interface\n\
308         file <f>        Take options from file <f>\n\
309         modem           Use modem control lines\n\
310         mru <n>         Set MRU value to <n> for negotiation\n\
311 See pppd(8) for more options.\n\
312 ";
313
314 /*
315  * parse_args - parse a string of arguments from the command line.
316  */
317 int
318 parse_args(argc, argv)
319     int argc;
320     char **argv;
321 {
322     char *arg;
323     option_t *opt;
324     int n;
325
326     privileged_option = privileged;
327     option_source = "command line";
328     option_priority = OPRIO_CMDLINE;
329     while (argc > 0) {
330         arg = *argv++;
331         --argc;
332         opt = find_option(arg);
333         if (opt == NULL) {
334             option_error("unrecognized option '%s'", arg);
335             usage();
336             return 0;
337         }
338         n = n_arguments(opt);
339         if (argc < n) {
340             option_error("too few parameters for option %s", arg);
341             return 0;
342         }
343         if (!process_option(opt, arg, argv))
344             return 0;
345         argc -= n;
346         argv += n;
347     }
348     return 1;
349 }
350
351 /*
352  * options_from_file - Read a string of options from a file,
353  * and interpret them.
354  */
355 int
356 options_from_file(filename, must_exist, check_prot, priv)
357     char *filename;
358     int must_exist;
359     int check_prot;
360     int priv;
361 {
362     FILE *f;
363     int i, newline, ret, err;
364     option_t *opt;
365     int oldpriv, n;
366     char *oldsource;
367     char *argv[MAXARGS];
368     char args[MAXARGS][MAXWORDLEN];
369     char cmd[MAXWORDLEN];
370
371     if (check_prot)
372         seteuid(getuid());
373     f = fopen(filename, "r");
374     err = errno;
375     if (check_prot)
376         seteuid(0);
377     if (f == NULL) {
378         errno = err;
379         if (!must_exist) {
380             if (err != ENOENT && err != ENOTDIR)
381                 warn("Warning: can't open options file %s: %m", filename);
382             return 1;
383         }
384         option_error("Can't open options file %s: %m", filename);
385         return 0;
386     }
387
388     oldpriv = privileged_option;
389     privileged_option = priv;
390     oldsource = option_source;
391     option_source = strdup(filename);
392     if (option_source == NULL)
393         option_source = "file";
394     ret = 0;
395     while (getword(f, cmd, &newline, filename)) {
396         opt = find_option(cmd);
397         if (opt == NULL) {
398             option_error("In file %s: unrecognized option '%s'",
399                          filename, cmd);
400             goto err;
401         }
402         n = n_arguments(opt);
403         for (i = 0; i < n; ++i) {
404             if (!getword(f, args[i], &newline, filename)) {
405                 option_error(
406                         "In file %s: too few parameters for option '%s'",
407                         filename, cmd);
408                 goto err;
409             }
410             argv[i] = args[i];
411         }
412         if (!process_option(opt, cmd, argv))
413             goto err;
414     }
415     ret = 1;
416
417 err:
418     fclose(f);
419     privileged_option = oldpriv;
420     option_source = oldsource;
421     return ret;
422 }
423
424 /*
425  * options_from_user - See if the use has a ~/.ppprc file,
426  * and if so, interpret options from it.
427  */
428 int
429 options_from_user()
430 {
431     char *user, *path, *file;
432     int ret;
433     struct passwd *pw;
434     size_t pl;
435
436     pw = getpwuid(getuid());
437     if (pw == NULL || (user = pw->pw_dir) == NULL || user[0] == 0)
438         return 1;
439     file = _PATH_USEROPT;
440     pl = strlen(user) + strlen(file) + 2;
441     path = malloc(pl);
442     if (path == NULL)
443         novm("init file name");
444     slprintf(path, pl, "%s/%s", user, file);
445     option_priority = OPRIO_CFGFILE;
446     ret = options_from_file(path, 0, 1, privileged);
447     free(path);
448     return ret;
449 }
450
451 /*
452  * options_for_tty - See if an options file exists for the serial
453  * device, and if so, interpret options from it.
454  * We only allow the per-tty options file to override anything from
455  * the command line if it is something that the user can't override
456  * once it has been set by root; this is done by giving configuration
457  * files a lower priority than the command line.
458  */
459 int
460 options_for_tty()
461 {
462     char *dev, *path, *p;
463     int ret;
464     size_t pl;
465
466     dev = devnam;
467     if (strncmp(dev, "/dev/", 5) == 0)
468         dev += 5;
469     if (dev[0] == 0 || strcmp(dev, "tty") == 0)
470         return 1;               /* don't look for /etc/ppp/options.tty */
471     pl = strlen(_PATH_TTYOPT) + strlen(dev) + 1;
472     path = malloc(pl);
473     if (path == NULL)
474         novm("tty init file name");
475     slprintf(path, pl, "%s%s", _PATH_TTYOPT, dev);
476     /* Turn slashes into dots, for Solaris case (e.g. /dev/term/a) */
477     for (p = path + strlen(_PATH_TTYOPT); *p != 0; ++p)
478         if (*p == '/')
479             *p = '.';
480     option_priority = OPRIO_CFGFILE;
481     ret = options_from_file(path, 0, 0, 1);
482     free(path);
483     return ret;
484 }
485
486 /*
487  * options_from_list - process a string of options in a wordlist.
488  */
489 int
490 options_from_list(w, priv)
491     struct wordlist *w;
492     int priv;
493 {
494     char *argv[MAXARGS];
495     option_t *opt;
496     int i, n, ret = 0;
497     struct wordlist *w0;
498
499     privileged_option = priv;
500     option_source = "secrets file";
501     option_priority = OPRIO_SECFILE;
502
503     while (w != NULL) {
504         opt = find_option(w->word);
505         if (opt == NULL) {
506             option_error("In secrets file: unrecognized option '%s'",
507                          w->word);
508             goto err;
509         }
510         n = n_arguments(opt);
511         w0 = w;
512         for (i = 0; i < n; ++i) {
513             w = w->next;
514             if (w == NULL) {
515                 option_error(
516                         "In secrets file: too few parameters for option '%s'",
517                         w0->word);
518                 goto err;
519             }
520             argv[i] = w->word;
521         }
522         if (!process_option(opt, w0->word, argv))
523             goto err;
524         w = w->next;
525     }
526     ret = 1;
527
528 err:
529     return ret;
530 }
531
532 /*
533  * match_option - see if this option matches an option_t structure.
534  */
535 static int
536 match_option(name, opt, dowild)
537     char *name;
538     option_t *opt;
539     int dowild;
540 {
541         int (*match) __P((char *, char **, int));
542
543         if (dowild != (opt->type == o_wild))
544                 return 0;
545         if (!dowild)
546                 return strcmp(name, opt->name) == 0;
547         match = (int (*) __P((char *, char **, int))) opt->addr;
548         return (*match)(name, NULL, 0);
549 }
550
551 /*
552  * find_option - scan the option lists for the various protocols
553  * looking for an entry with the given name.
554  * This could be optimized by using a hash table.
555  */
556 static option_t *
557 find_option(name)
558     const char *name;
559 {
560         option_t *opt;
561         struct option_list *list;
562         int i, dowild;
563
564         for (dowild = 0; dowild <= 1; ++dowild) {
565                 for (opt = general_options; opt->name != NULL; ++opt)
566                         if (match_option(name, opt, dowild))
567                                 return opt;
568                 for (opt = auth_options; opt->name != NULL; ++opt)
569                         if (match_option(name, opt, dowild))
570                                 return opt;
571                 for (list = extra_options; list != NULL; list = list->next)
572                         for (opt = list->options; opt->name != NULL; ++opt)
573                                 if (match_option(name, opt, dowild))
574                                         return opt;
575                 for (opt = the_channel->options; opt->name != NULL; ++opt)
576                         if (match_option(name, opt, dowild))
577                                 return opt;
578                 for (i = 0; protocols[i] != NULL; ++i)
579                         if ((opt = protocols[i]->options) != NULL)
580                                 for (; opt->name != NULL; ++opt)
581                                         if (match_option(name, opt, dowild))
582                                                 return opt;
583         }
584         return NULL;
585 }
586
587 /*
588  * process_option - process one new-style option.
589  */
590 static int
591 process_option(opt, cmd, argv)
592     option_t *opt;
593     char *cmd;
594     char **argv;
595 {
596     u_int32_t v;
597     int iv, a;
598     char *sv;
599     int (*parser) __P((char **));
600     int (*wildp) __P((char *, char **, int));
601     char *optopt = (opt->type == o_wild)? "": " option";
602     int prio = option_priority;
603     option_t *mainopt = opt;
604
605     if ((opt->flags & OPT_PRIVFIX) && privileged_option)
606         prio += OPRIO_ROOT;
607     while (mainopt->flags & OPT_PRIOSUB)
608         --mainopt;
609     if (mainopt->flags & OPT_PRIO) {
610         if (prio < mainopt->priority) {
611             /* new value doesn't override old */
612             if (prio == OPRIO_CMDLINE && mainopt->priority > OPRIO_ROOT) {
613                 option_error("%s%s set in %s cannot be overridden\n",
614                              opt->name, optopt, mainopt->source);
615                 return 0;
616             }
617             return 1;
618         }
619         if (prio > OPRIO_ROOT && mainopt->priority == OPRIO_CMDLINE)
620             warn("%s%s from %s overrides command line",
621                  opt->name, optopt, option_source);
622     }
623
624     if ((opt->flags & OPT_INITONLY) && phase != PHASE_INITIALIZE) {
625         option_error("%s%s cannot be changed after initialization",
626                      opt->name, optopt);
627         return 0;
628     }
629     if ((opt->flags & OPT_PRIV) && !privileged_option) {
630         option_error("using the %s%s requires root privilege",
631                      opt->name, optopt);
632         return 0;
633     }
634     if ((opt->flags & OPT_ENABLE) && *(bool *)(opt->addr2) == 0) {
635         option_error("%s%s is disabled", opt->name, optopt);
636         return 0;
637     }
638     if ((opt->flags & OPT_DEVEQUIV) && devnam_fixed) {
639         option_error("the %s%s may not be changed in %s",
640                      opt->name, optopt, option_source);
641         return 0;
642     }
643
644     switch (opt->type) {
645     case o_bool:
646         v = opt->flags & OPT_VALUE;
647         *(bool *)(opt->addr) = v;
648         if (opt->addr2 && (opt->flags & OPT_A2COPY))
649             *(bool *)(opt->addr2) = v;
650         else if (opt->addr2 && (opt->flags & OPT_A2CLR))
651             *(bool *)(opt->addr2) = 0;
652         else if (opt->addr2 && (opt->flags & OPT_A2CLRB))
653             *(u_char *)(opt->addr2) &= ~v;
654         else if (opt->addr2 && (opt->flags & OPT_A2OR))
655             *(u_char *)(opt->addr2) |= v;
656         break;
657
658     case o_int:
659         iv = 0;
660         if ((opt->flags & OPT_NOARG) == 0) {
661             if (!int_option(*argv, &iv))
662                 return 0;
663             if ((((opt->flags & OPT_LLIMIT) && iv < opt->lower_limit)
664                  || ((opt->flags & OPT_ULIMIT) && iv > opt->upper_limit))
665                 && !((opt->flags & OPT_ZEROOK && iv == 0))) {
666                 char *zok = (opt->flags & OPT_ZEROOK)? " zero or": "";
667                 switch (opt->flags & OPT_LIMITS) {
668                 case OPT_LLIMIT:
669                     option_error("%s value must be%s >= %d",
670                                  opt->name, zok, opt->lower_limit);
671                     break;
672                 case OPT_ULIMIT:
673                     option_error("%s value must be%s <= %d",
674                                  opt->name, zok, opt->upper_limit);
675                     break;
676                 case OPT_LIMITS:
677                     option_error("%s value must be%s between %d and %d",
678                                 opt->name, zok, opt->lower_limit, opt->upper_limit);
679                     break;
680                 }
681                 return 0;
682             }
683         }
684         a = opt->flags & OPT_VALUE;
685         if (a >= 128)
686             a -= 256;           /* sign extend */
687         iv += a;
688         if (opt->flags & OPT_INC)
689             iv += *(int *)(opt->addr);
690         if ((opt->flags & OPT_NOINCR) && !privileged_option) {
691             int oldv = *(int *)(opt->addr);
692             if ((opt->flags & OPT_ZEROINF) ?
693                 (oldv != 0 && (iv == 0 || iv > oldv)) : (iv > oldv)) {
694                 option_error("%s value cannot be increased", opt->name);
695                 return 0;
696             }
697         }
698         *(int *)(opt->addr) = iv;
699         if (opt->addr2 && (opt->flags & OPT_A2COPY))
700             *(int *)(opt->addr2) = iv;
701         break;
702
703     case o_uint32:
704         if (opt->flags & OPT_NOARG) {
705             v = opt->flags & OPT_VALUE;
706             if (v & 0x80)
707                     v |= 0xffffff00U;
708         } else if (!number_option(*argv, &v, 16))
709             return 0;
710         if (opt->flags & OPT_OR)
711             v |= *(u_int32_t *)(opt->addr);
712         *(u_int32_t *)(opt->addr) = v;
713         if (opt->addr2 && (opt->flags & OPT_A2COPY))
714             *(u_int32_t *)(opt->addr2) = v;
715         break;
716
717     case o_string:
718         if (opt->flags & OPT_STATIC) {
719             strlcpy((char *)(opt->addr), *argv, opt->upper_limit);
720         } else {
721             sv = strdup(*argv);
722             if (sv == NULL)
723                 novm("option argument");
724             *(char **)(opt->addr) = sv;
725         }
726         break;
727
728     case o_special_noarg:
729     case o_special:
730         parser = (int (*) __P((char **))) opt->addr;
731         if (!(*parser)(argv))
732             return 0;
733         if (opt->flags & OPT_A2LIST) {
734             struct option_value *ovp, **pp;
735
736             ovp = malloc(sizeof(*ovp) + strlen(*argv));
737             if (ovp != 0) {
738                 strcpy(ovp->value, *argv);
739                 ovp->source = option_source;
740                 ovp->next = NULL;
741                 pp = (struct option_value **) &opt->addr2;
742                 while (*pp != 0)
743                     pp = &(*pp)->next;
744                 *pp = ovp;
745             }
746         }
747         break;
748
749     case o_wild:
750         wildp = (int (*) __P((char *, char **, int))) opt->addr;
751         if (!(*wildp)(cmd, argv, 1))
752             return 0;
753         break;
754     }
755
756     if (opt->addr2 && (opt->flags & (OPT_A2COPY|OPT_ENABLE
757                 |OPT_A2PRINTER|OPT_A2STRVAL|OPT_A2LIST|OPT_A2OR)) == 0)
758         *(bool *)(opt->addr2) = !(opt->flags & OPT_A2CLR);
759
760     mainopt->source = option_source;
761     mainopt->priority = prio;
762     mainopt->winner = opt - mainopt;
763
764     return 1;
765 }
766
767 /*
768  * override_value - if the option priorities would permit us to
769  * override the value of option, return 1 and update the priority
770  * and source of the option value.  Otherwise returns 0.
771  */
772 int
773 override_value(option, priority, source)
774     const char *option;
775     int priority;
776     const char *source;
777 {
778         option_t *opt;
779
780         opt = find_option(option);
781         if (opt == NULL)
782                 return 0;
783         while (opt->flags & OPT_PRIOSUB)
784                 --opt;
785         if ((opt->flags & OPT_PRIO) && priority < opt->priority)
786                 return 0;
787         opt->priority = priority;
788         opt->source = source;
789         opt->winner = -1;
790         return 1;
791 }
792
793 /*
794  * n_arguments - tell how many arguments an option takes
795  */
796 static int
797 n_arguments(opt)
798     option_t *opt;
799 {
800         return (opt->type == o_bool || opt->type == o_special_noarg
801                 || (opt->flags & OPT_NOARG))? 0: 1;
802 }
803
804 /*
805  * add_options - add a list of options to the set we grok.
806  */
807 void
808 add_options(opt)
809     option_t *opt;
810 {
811     struct option_list *list;
812
813     list = malloc(sizeof(*list));
814     if (list == 0)
815         novm("option list entry");
816     list->options = opt;
817     list->next = extra_options;
818     extra_options = list;
819 }
820
821 /*
822  * check_options - check that options are valid and consistent.
823  */
824 void
825 check_options()
826 {
827         if (logfile_fd >= 0 && logfile_fd != log_to_fd)
828                 close(logfile_fd);
829 }
830
831 /*
832  * print_option - print out an option and its value
833  */
834 static void
835 print_option(opt, mainopt, printer, arg)
836     option_t *opt, *mainopt;
837     void (*printer) __P((void *, char *, ...));
838     void *arg;
839 {
840         int i, v;
841         char *p;
842
843         if (opt->flags & OPT_NOPRINT)
844                 return;
845         switch (opt->type) {
846         case o_bool:
847                 v = opt->flags & OPT_VALUE;
848                 if (*(bool *)opt->addr != v)
849                         /* this can happen legitimately, e.g. lock
850                            option turned off for default device */
851                         break;
852                 printer(arg, "%s", opt->name);
853                 break;
854         case o_int:
855                 v = opt->flags & OPT_VALUE;
856                 if (v >= 128)
857                         v -= 256;
858                 i = *(int *)opt->addr;
859                 if (opt->flags & OPT_NOARG) {
860                         printer(arg, "%s", opt->name);
861                         if (i != v) {
862                                 if (opt->flags & OPT_INC) {
863                                         for (; i > v; i -= v)
864                                                 printer(arg, " %s", opt->name);
865                                 } else
866                                         printer(arg, " # oops: %d not %d\n",
867                                                 i, v);
868                         }
869                 } else {
870                         printer(arg, "%s %d", opt->name, i);
871                 }
872                 break;
873         case o_uint32:
874                 printer(arg, "%s", opt->name);
875                 if ((opt->flags & OPT_NOARG) == 0)
876                         printer(arg, " %x", *(u_int32_t *)opt->addr);
877                 break;
878
879         case o_string:
880                 if (opt->flags & OPT_HIDE) {
881                         p = "??????";
882                 } else {
883                         p = (char *) opt->addr;
884                         if ((opt->flags & OPT_STATIC) == 0)
885                                 p = *(char **)p;
886                 }
887                 printer(arg, "%s %q", opt->name, p);
888                 break;
889
890         case o_special:
891         case o_special_noarg:
892         case o_wild:
893                 if (opt->type != o_wild) {
894                         printer(arg, "%s", opt->name);
895                         if (n_arguments(opt) == 0)
896                                 break;
897                         printer(arg, " ");
898                 }
899                 if (opt->flags & OPT_A2PRINTER) {
900                         void (*oprt) __P((option_t *,
901                                           void ((*)__P((void *, char *, ...))),
902                                           void *));
903                         oprt = (void (*) __P((option_t *,
904                                          void ((*)__P((void *, char *, ...))),
905                                          void *)))opt->addr2;
906                         (*oprt)(opt, printer, arg);
907                 } else if (opt->flags & OPT_A2STRVAL) {
908                         p = (char *) opt->addr2;
909                         if ((opt->flags & OPT_STATIC) == 0)
910                                 p = *(char **)p;
911                         printer("%q", p);
912                 } else if (opt->flags & OPT_A2LIST) {
913                         struct option_value *ovp;
914
915                         ovp = (struct option_value *) opt->addr2;
916                         for (;;) {
917                                 printer(arg, "%q", ovp->value);
918                                 if ((ovp = ovp->next) == NULL)
919                                         break;
920                                 printer(arg, "\t\t# (from %s)\n%s ",
921                                         ovp->source, opt->name);
922                         }
923                 } else {
924                         printer(arg, "xxx # [don't know how to print value]");
925                 }
926                 break;
927
928         default:
929                 printer(arg, "# %s value (type %d\?\?)", opt->name, opt->type);
930                 break;
931         }
932         printer(arg, "\t\t# (from %s)\n", mainopt->source);
933 }
934
935 /*
936  * print_option_list - print out options in effect from an
937  * array of options.
938  */
939 static void
940 print_option_list(opt, printer, arg)
941     option_t *opt;
942     void (*printer) __P((void *, char *, ...));
943     void *arg;
944 {
945         while (opt->name != NULL) {
946                 if (opt->priority != OPRIO_DEFAULT
947                     && opt->winner != (short int) -1)
948                         print_option(opt + opt->winner, opt, printer, arg);
949                 do {
950                         ++opt;
951                 } while (opt->flags & OPT_PRIOSUB);
952         }
953 }
954
955 /*
956  * print_options - print out what options are in effect.
957  */
958 void
959 print_options(printer, arg)
960     void (*printer) __P((void *, char *, ...));
961     void *arg;
962 {
963         struct option_list *list;
964         int i;
965
966         printer(arg, "pppd options in effect:\n");
967         print_option_list(general_options, printer, arg);
968         print_option_list(auth_options, printer, arg);
969         for (list = extra_options; list != NULL; list = list->next)
970                 print_option_list(list->options, printer, arg);
971         print_option_list(the_channel->options, printer, arg);
972         for (i = 0; protocols[i] != NULL; ++i)
973                 print_option_list(protocols[i]->options, printer, arg);
974 }
975
976 /*
977  * usage - print out a message telling how to use the program.
978  */
979 static void
980 usage()
981 {
982     if (phase == PHASE_INITIALIZE)
983         fprintf(stderr, usage_string, VERSION, progname);
984 }
985
986 /*
987  * showhelp - print out usage message and exit.
988  */
989 static int
990 showhelp(argv)
991     char **argv;
992 {
993     if (phase == PHASE_INITIALIZE) {
994         usage();
995         exit(0);
996     }
997     return 0;
998 }
999
1000 /*
1001  * showversion - print out the version number and exit.
1002  */
1003 static int
1004 showversion(argv)
1005     char **argv;
1006 {
1007     if (phase == PHASE_INITIALIZE) {
1008         fprintf(stderr, "pppd version %s\n", VERSION);
1009         exit(0);
1010     }
1011     return 0;
1012 }
1013
1014 /*
1015  * option_error - print a message about an error in an option.
1016  * The message is logged, and also sent to
1017  * stderr if phase == PHASE_INITIALIZE.
1018  */
1019 void
1020 option_error __V((char *fmt, ...))
1021 {
1022     va_list args;
1023     char buf[1024];
1024
1025 #if defined(__STDC__)
1026     va_start(args, fmt);
1027 #else
1028     char *fmt;
1029     va_start(args);
1030     fmt = va_arg(args, char *);
1031 #endif
1032     vslprintf(buf, sizeof(buf), fmt, args);
1033     va_end(args);
1034     if (phase == PHASE_INITIALIZE)
1035         fprintf(stderr, "%s: %s\n", progname, buf);
1036     syslog(LOG_ERR, "%s", buf);
1037 }
1038
1039 #if 0
1040 /*
1041  * readable - check if a file is readable by the real user.
1042  */
1043 int
1044 readable(fd)
1045     int fd;
1046 {
1047     uid_t uid;
1048     int i;
1049     struct stat sbuf;
1050
1051     uid = getuid();
1052     if (uid == 0)
1053         return 1;
1054     if (fstat(fd, &sbuf) != 0)
1055         return 0;
1056     if (sbuf.st_uid == uid)
1057         return sbuf.st_mode & S_IRUSR;
1058     if (sbuf.st_gid == getgid())
1059         return sbuf.st_mode & S_IRGRP;
1060     for (i = 0; i < ngroups; ++i)
1061         if (sbuf.st_gid == groups[i])
1062             return sbuf.st_mode & S_IRGRP;
1063     return sbuf.st_mode & S_IROTH;
1064 }
1065 #endif
1066
1067 /*
1068  * Read a word from a file.
1069  * Words are delimited by white-space or by quotes (" or ').
1070  * Quotes, white-space and \ may be escaped with \.
1071  * \<newline> is ignored.
1072  */
1073 int
1074 getword(f, word, newlinep, filename)
1075     FILE *f;
1076     char *word;
1077     int *newlinep;
1078     char *filename;
1079 {
1080     int c, len, escape;
1081     int quoted, comment;
1082     int value, digit, got, n;
1083
1084 #define isoctal(c) ((c) >= '0' && (c) < '8')
1085
1086     *newlinep = 0;
1087     len = 0;
1088     escape = 0;
1089     comment = 0;
1090
1091     /*
1092      * First skip white-space and comments.
1093      */
1094     for (;;) {
1095         c = getc(f);
1096         if (c == EOF)
1097             break;
1098
1099         /*
1100          * A newline means the end of a comment; backslash-newline
1101          * is ignored.  Note that we cannot have escape && comment.
1102          */
1103         if (c == '\n') {
1104             if (!escape) {
1105                 *newlinep = 1;
1106                 comment = 0;
1107             } else
1108                 escape = 0;
1109             continue;
1110         }
1111
1112         /*
1113          * Ignore characters other than newline in a comment.
1114          */
1115         if (comment)
1116             continue;
1117
1118         /*
1119          * If this character is escaped, we have a word start.
1120          */
1121         if (escape)
1122             break;
1123
1124         /*
1125          * If this is the escape character, look at the next character.
1126          */
1127         if (c == '\\') {
1128             escape = 1;
1129             continue;
1130         }
1131
1132         /*
1133          * If this is the start of a comment, ignore the rest of the line.
1134          */
1135         if (c == '#') {
1136             comment = 1;
1137             continue;
1138         }
1139
1140         /*
1141          * A non-whitespace character is the start of a word.
1142          */
1143         if (!isspace(c))
1144             break;
1145     }
1146
1147     /*
1148      * Save the delimiter for quoted strings.
1149      */
1150     if (!escape && (c == '"' || c == '\'')) {
1151         quoted = c;
1152         c = getc(f);
1153     } else
1154         quoted = 0;
1155
1156     /*
1157      * Process characters until the end of the word.
1158      */
1159     while (c != EOF) {
1160         if (escape) {
1161             /*
1162              * This character is escaped: backslash-newline is ignored,
1163              * various other characters indicate particular values
1164              * as for C backslash-escapes.
1165              */
1166             escape = 0;
1167             if (c == '\n') {
1168                 c = getc(f);
1169                 continue;
1170             }
1171
1172             got = 0;
1173             switch (c) {
1174             case 'a':
1175                 value = '\a';
1176                 break;
1177             case 'b':
1178                 value = '\b';
1179                 break;
1180             case 'f':
1181                 value = '\f';
1182                 break;
1183             case 'n':
1184                 value = '\n';
1185                 break;
1186             case 'r':
1187                 value = '\r';
1188                 break;
1189             case 's':
1190                 value = ' ';
1191                 break;
1192             case 't':
1193                 value = '\t';
1194                 break;
1195
1196             default:
1197                 if (isoctal(c)) {
1198                     /*
1199                      * \ddd octal sequence
1200                      */
1201                     value = 0;
1202                     for (n = 0; n < 3 && isoctal(c); ++n) {
1203                         value = (value << 3) + (c & 07);
1204                         c = getc(f);
1205                     }
1206                     got = 1;
1207                     break;
1208                 }
1209
1210                 if (c == 'x') {
1211                     /*
1212                      * \x<hex_string> sequence
1213                      */
1214                     value = 0;
1215                     c = getc(f);
1216                     for (n = 0; n < 2 && isxdigit(c); ++n) {
1217                         digit = toupper(c) - '0';
1218                         if (digit > 10)
1219                             digit += '0' + 10 - 'A';
1220                         value = (value << 4) + digit;
1221                         c = getc (f);
1222                     }
1223                     got = 1;
1224                     break;
1225                 }
1226
1227                 /*
1228                  * Otherwise the character stands for itself.
1229                  */
1230                 value = c;
1231                 break;
1232             }
1233
1234             /*
1235              * Store the resulting character for the escape sequence.
1236              */
1237             if (len < MAXWORDLEN-1)
1238                 word[len] = value;
1239             ++len;
1240
1241             if (!got)
1242                 c = getc(f);
1243             continue;
1244
1245         }
1246
1247         /*
1248          * Not escaped: see if we've reached the end of the word.
1249          */
1250         if (quoted) {
1251             if (c == quoted)
1252                 break;
1253         } else {
1254             if (isspace(c) || c == '#') {
1255                 ungetc (c, f);
1256                 break;
1257             }
1258         }
1259
1260         /*
1261          * Backslash starts an escape sequence.
1262          */
1263         if (c == '\\') {
1264             escape = 1;
1265             c = getc(f);
1266             continue;
1267         }
1268
1269         /*
1270          * An ordinary character: store it in the word and get another.
1271          */
1272         if (len < MAXWORDLEN-1)
1273             word[len] = c;
1274         ++len;
1275
1276         c = getc(f);
1277     }
1278
1279     /*
1280      * End of the word: check for errors.
1281      */
1282     if (c == EOF) {
1283         if (ferror(f)) {
1284             if (errno == 0)
1285                 errno = EIO;
1286             option_error("Error reading %s: %m", filename);
1287             die(1);
1288         }
1289         /*
1290          * If len is zero, then we didn't find a word before the
1291          * end of the file.
1292          */
1293         if (len == 0)
1294             return 0;
1295     }
1296
1297     /*
1298      * Warn if the word was too long, and append a terminating null.
1299      */
1300     if (len >= MAXWORDLEN) {
1301         option_error("warning: word in file %s too long (%.20s...)",
1302                      filename, word);
1303         len = MAXWORDLEN - 1;
1304     }
1305     word[len] = 0;
1306
1307     return 1;
1308
1309 #undef isoctal
1310
1311 }
1312
1313 /*
1314  * number_option - parse an unsigned numeric parameter for an option.
1315  */
1316 static int
1317 number_option(str, valp, base)
1318     char *str;
1319     u_int32_t *valp;
1320     int base;
1321 {
1322     char *ptr;
1323
1324     *valp = strtoul(str, &ptr, base);
1325     if (ptr == str) {
1326         option_error("invalid numeric parameter '%s' for %s option",
1327                      str, current_option);
1328         return 0;
1329     }
1330     return 1;
1331 }
1332
1333
1334 /*
1335  * int_option - like number_option, but valp is int *,
1336  * the base is assumed to be 0, and *valp is not changed
1337  * if there is an error.
1338  */
1339 int
1340 int_option(str, valp)
1341     char *str;
1342     int *valp;
1343 {
1344     u_int32_t v;
1345
1346     if (!number_option(str, &v, 0))
1347         return 0;
1348     *valp = (int) v;
1349     return 1;
1350 }
1351
1352
1353 /*
1354  * The following procedures parse options.
1355  */
1356
1357 /*
1358  * readfile - take commands from a file.
1359  */
1360 static int
1361 readfile(argv)
1362     char **argv;
1363 {
1364     return options_from_file(*argv, 1, 1, privileged_option);
1365 }
1366
1367 /*
1368  * callfile - take commands from /etc/ppp/peers/<name>.
1369  * Name may not contain /../, start with / or ../, or end in /..
1370  */
1371 static int
1372 callfile(argv)
1373     char **argv;
1374 {
1375     char *fname, *arg, *p;
1376     int l, ok;
1377
1378     arg = *argv;
1379     ok = 1;
1380     if (arg[0] == '/' || arg[0] == 0)
1381         ok = 0;
1382     else {
1383         for (p = arg; *p != 0; ) {
1384             if (p[0] == '.' && p[1] == '.' && (p[2] == '/' || p[2] == 0)) {
1385                 ok = 0;
1386                 break;
1387             }
1388             while (*p != '/' && *p != 0)
1389                 ++p;
1390             if (*p == '/')
1391                 ++p;
1392         }
1393     }
1394     if (!ok) {
1395         option_error("call option value may not contain .. or start with /");
1396         return 0;
1397     }
1398
1399     l = strlen(arg) + strlen(_PATH_PEERFILES) + 1;
1400     if ((fname = (char *) malloc(l)) == NULL)
1401         novm("call file name");
1402     slprintf(fname, l, "%s%s", _PATH_PEERFILES, arg);
1403
1404     ok = options_from_file(fname, 1, 1, 1);
1405
1406     free(fname);
1407     return ok;
1408 }
1409
1410 #ifdef PPP_FILTER
1411 /*
1412  * setpassfilter - Set the pass filter for packets
1413  */
1414 static int
1415 setpassfilter(argv)
1416     char **argv;
1417 {
1418     pc.linktype = DLT_PPP;
1419     pc.snapshot = PPP_HDRLEN;
1420  
1421     if (pcap_compile(&pc, &pass_filter, *argv, 1, netmask) == 0)
1422         return 1;
1423     option_error("error in pass-filter expression: %s\n", pcap_geterr(&pc));
1424     return 0;
1425 }
1426
1427 /*
1428  * setactivefilter - Set the active filter for packets
1429  */
1430 static int
1431 setactivefilter(argv)
1432     char **argv;
1433 {
1434     pc.linktype = DLT_PPP;
1435     pc.snapshot = PPP_HDRLEN;
1436  
1437     if (pcap_compile(&pc, &active_filter, *argv, 1, netmask) == 0)
1438         return 1;
1439     option_error("error in active-filter expression: %s\n", pcap_geterr(&pc));
1440     return 0;
1441 }
1442 #endif
1443
1444 /*
1445  * setdomain - Set domain name to append to hostname 
1446  */
1447 static int
1448 setdomain(argv)
1449     char **argv;
1450 {
1451     gethostname(hostname, MAXNAMELEN);
1452     if (**argv != 0) {
1453         if (**argv != '.')
1454             strncat(hostname, ".", MAXNAMELEN - strlen(hostname));
1455         domain = hostname + strlen(hostname);
1456         strncat(hostname, *argv, MAXNAMELEN - strlen(hostname));
1457     }
1458     hostname[MAXNAMELEN-1] = 0;
1459     return (1);
1460 }
1461
1462
1463 static int
1464 setlogfile(argv)
1465     char **argv;
1466 {
1467     int fd, err;
1468
1469     if (!privileged_option)
1470         seteuid(getuid());
1471     fd = open(*argv, O_WRONLY | O_APPEND | O_CREAT | O_EXCL, 0644);
1472     if (fd < 0 && errno == EEXIST)
1473         fd = open(*argv, O_WRONLY | O_APPEND);
1474     err = errno;
1475     if (!privileged_option)
1476         seteuid(0);
1477     if (fd < 0) {
1478         errno = err;
1479         option_error("Can't open log file %s: %m", *argv);
1480         return 0;
1481     }
1482     strlcpy(logfile_name, *argv, sizeof(logfile_name));
1483     if (logfile_fd >= 0)
1484         close(logfile_fd);
1485     logfile_fd = fd;
1486     log_to_fd = fd;
1487     log_default = 0;
1488     return 1;
1489 }
1490 #ifdef MAXOCTETS
1491 static int
1492 setmodir(argv)
1493     char **argv;
1494 {
1495     if(*argv == NULL)
1496         return 0;
1497     if(!strcmp(*argv,"in")) {
1498         maxoctets_dir = PPP_OCTETS_DIRECTION_IN;
1499     } else if (!strcmp(*argv,"out")) {
1500         maxoctets_dir = PPP_OCTETS_DIRECTION_OUT;
1501     } else if (!strcmp(*argv,"max")) {
1502         maxoctets_dir = PPP_OCTETS_DIRECTION_MAXOVERAL;
1503     } else {
1504         maxoctets_dir = PPP_OCTETS_DIRECTION_SUM;
1505     }
1506     return 1;
1507 }
1508 #endif
1509
1510 #ifdef PLUGIN
1511 static int
1512 loadplugin(argv)
1513     char **argv;
1514 {
1515     char *arg = *argv;
1516     void *handle;
1517     const char *err;
1518     void (*init) __P((void));
1519     char *path = arg;
1520     const char *vers;
1521
1522     if (strchr(arg, '/') == 0) {
1523         const char *base = _PATH_PLUGIN;
1524         int l = strlen(base) + strlen(arg) + 2;
1525         path = malloc(l);
1526         if (path == 0)
1527             novm("plugin file path");
1528         strlcpy(path, base, l);
1529         strlcat(path, "/", l);
1530         strlcat(path, arg, l);
1531     }
1532     handle = dlopen(path, RTLD_GLOBAL | RTLD_NOW);
1533     if (handle == 0) {
1534         err = dlerror();
1535         if (err != 0)
1536             option_error("%s", err);
1537         option_error("Couldn't load plugin %s", arg);
1538         goto err;
1539     }
1540     init = (void (*)(void))dlsym(handle, "plugin_init");
1541     if (init == 0) {
1542         option_error("%s has no initialization entry point", arg);
1543         goto errclose;
1544     }
1545     vers = (const char *) dlsym(handle, "pppd_version");
1546     if (vers == 0) {
1547         warn("Warning: plugin %s has no version information", arg);
1548     } else if (strcmp(vers, VERSION) != 0) {
1549         option_error("Plugin %s is for pppd version %s, this is %s",
1550                      arg, vers, VERSION);
1551         goto errclose;
1552     }
1553     info("Plugin %s loaded.", arg);
1554     (*init)();
1555     return 1;
1556
1557  errclose:
1558     dlclose(handle);
1559  err:
1560     if (path != arg)
1561         free(path);
1562     return 0;
1563 }
1564 #endif /* PLUGIN */