]> git.ozlabs.org Git - ppp.git/blob - pppd/options.c
Set current_option for error reporting. Bug and fix by Clive Nicolson.
[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.89 2002/10/27 13:00:13 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     current_option = opt->name;
606     if ((opt->flags & OPT_PRIVFIX) && privileged_option)
607         prio += OPRIO_ROOT;
608     while (mainopt->flags & OPT_PRIOSUB)
609         --mainopt;
610     if (mainopt->flags & OPT_PRIO) {
611         if (prio < mainopt->priority) {
612             /* new value doesn't override old */
613             if (prio == OPRIO_CMDLINE && mainopt->priority > OPRIO_ROOT) {
614                 option_error("%s%s set in %s cannot be overridden\n",
615                              opt->name, optopt, mainopt->source);
616                 return 0;
617             }
618             return 1;
619         }
620         if (prio > OPRIO_ROOT && mainopt->priority == OPRIO_CMDLINE)
621             warn("%s%s from %s overrides command line",
622                  opt->name, optopt, option_source);
623     }
624
625     if ((opt->flags & OPT_INITONLY) && phase != PHASE_INITIALIZE) {
626         option_error("%s%s cannot be changed after initialization",
627                      opt->name, optopt);
628         return 0;
629     }
630     if ((opt->flags & OPT_PRIV) && !privileged_option) {
631         option_error("using the %s%s requires root privilege",
632                      opt->name, optopt);
633         return 0;
634     }
635     if ((opt->flags & OPT_ENABLE) && *(bool *)(opt->addr2) == 0) {
636         option_error("%s%s is disabled", opt->name, optopt);
637         return 0;
638     }
639     if ((opt->flags & OPT_DEVEQUIV) && devnam_fixed) {
640         option_error("the %s%s may not be changed in %s",
641                      opt->name, optopt, option_source);
642         return 0;
643     }
644
645     switch (opt->type) {
646     case o_bool:
647         v = opt->flags & OPT_VALUE;
648         *(bool *)(opt->addr) = v;
649         if (opt->addr2 && (opt->flags & OPT_A2COPY))
650             *(bool *)(opt->addr2) = v;
651         else if (opt->addr2 && (opt->flags & OPT_A2CLR))
652             *(bool *)(opt->addr2) = 0;
653         else if (opt->addr2 && (opt->flags & OPT_A2CLRB))
654             *(u_char *)(opt->addr2) &= ~v;
655         else if (opt->addr2 && (opt->flags & OPT_A2OR))
656             *(u_char *)(opt->addr2) |= v;
657         break;
658
659     case o_int:
660         iv = 0;
661         if ((opt->flags & OPT_NOARG) == 0) {
662             if (!int_option(*argv, &iv))
663                 return 0;
664             if ((((opt->flags & OPT_LLIMIT) && iv < opt->lower_limit)
665                  || ((opt->flags & OPT_ULIMIT) && iv > opt->upper_limit))
666                 && !((opt->flags & OPT_ZEROOK && iv == 0))) {
667                 char *zok = (opt->flags & OPT_ZEROOK)? " zero or": "";
668                 switch (opt->flags & OPT_LIMITS) {
669                 case OPT_LLIMIT:
670                     option_error("%s value must be%s >= %d",
671                                  opt->name, zok, opt->lower_limit);
672                     break;
673                 case OPT_ULIMIT:
674                     option_error("%s value must be%s <= %d",
675                                  opt->name, zok, opt->upper_limit);
676                     break;
677                 case OPT_LIMITS:
678                     option_error("%s value must be%s between %d and %d",
679                                 opt->name, zok, opt->lower_limit, opt->upper_limit);
680                     break;
681                 }
682                 return 0;
683             }
684         }
685         a = opt->flags & OPT_VALUE;
686         if (a >= 128)
687             a -= 256;           /* sign extend */
688         iv += a;
689         if (opt->flags & OPT_INC)
690             iv += *(int *)(opt->addr);
691         if ((opt->flags & OPT_NOINCR) && !privileged_option) {
692             int oldv = *(int *)(opt->addr);
693             if ((opt->flags & OPT_ZEROINF) ?
694                 (oldv != 0 && (iv == 0 || iv > oldv)) : (iv > oldv)) {
695                 option_error("%s value cannot be increased", opt->name);
696                 return 0;
697             }
698         }
699         *(int *)(opt->addr) = iv;
700         if (opt->addr2 && (opt->flags & OPT_A2COPY))
701             *(int *)(opt->addr2) = iv;
702         break;
703
704     case o_uint32:
705         if (opt->flags & OPT_NOARG) {
706             v = opt->flags & OPT_VALUE;
707             if (v & 0x80)
708                     v |= 0xffffff00U;
709         } else if (!number_option(*argv, &v, 16))
710             return 0;
711         if (opt->flags & OPT_OR)
712             v |= *(u_int32_t *)(opt->addr);
713         *(u_int32_t *)(opt->addr) = v;
714         if (opt->addr2 && (opt->flags & OPT_A2COPY))
715             *(u_int32_t *)(opt->addr2) = v;
716         break;
717
718     case o_string:
719         if (opt->flags & OPT_STATIC) {
720             strlcpy((char *)(opt->addr), *argv, opt->upper_limit);
721         } else {
722             sv = strdup(*argv);
723             if (sv == NULL)
724                 novm("option argument");
725             *(char **)(opt->addr) = sv;
726         }
727         break;
728
729     case o_special_noarg:
730     case o_special:
731         parser = (int (*) __P((char **))) opt->addr;
732         if (!(*parser)(argv))
733             return 0;
734         if (opt->flags & OPT_A2LIST) {
735             struct option_value *ovp, **pp;
736
737             ovp = malloc(sizeof(*ovp) + strlen(*argv));
738             if (ovp != 0) {
739                 strcpy(ovp->value, *argv);
740                 ovp->source = option_source;
741                 ovp->next = NULL;
742                 pp = (struct option_value **) &opt->addr2;
743                 while (*pp != 0)
744                     pp = &(*pp)->next;
745                 *pp = ovp;
746             }
747         }
748         break;
749
750     case o_wild:
751         wildp = (int (*) __P((char *, char **, int))) opt->addr;
752         if (!(*wildp)(cmd, argv, 1))
753             return 0;
754         break;
755     }
756
757     if (opt->addr2 && (opt->flags & (OPT_A2COPY|OPT_ENABLE
758                 |OPT_A2PRINTER|OPT_A2STRVAL|OPT_A2LIST|OPT_A2OR)) == 0)
759         *(bool *)(opt->addr2) = !(opt->flags & OPT_A2CLR);
760
761     mainopt->source = option_source;
762     mainopt->priority = prio;
763     mainopt->winner = opt - mainopt;
764
765     return 1;
766 }
767
768 /*
769  * override_value - if the option priorities would permit us to
770  * override the value of option, return 1 and update the priority
771  * and source of the option value.  Otherwise returns 0.
772  */
773 int
774 override_value(option, priority, source)
775     const char *option;
776     int priority;
777     const char *source;
778 {
779         option_t *opt;
780
781         opt = find_option(option);
782         if (opt == NULL)
783                 return 0;
784         while (opt->flags & OPT_PRIOSUB)
785                 --opt;
786         if ((opt->flags & OPT_PRIO) && priority < opt->priority)
787                 return 0;
788         opt->priority = priority;
789         opt->source = source;
790         opt->winner = -1;
791         return 1;
792 }
793
794 /*
795  * n_arguments - tell how many arguments an option takes
796  */
797 static int
798 n_arguments(opt)
799     option_t *opt;
800 {
801         return (opt->type == o_bool || opt->type == o_special_noarg
802                 || (opt->flags & OPT_NOARG))? 0: 1;
803 }
804
805 /*
806  * add_options - add a list of options to the set we grok.
807  */
808 void
809 add_options(opt)
810     option_t *opt;
811 {
812     struct option_list *list;
813
814     list = malloc(sizeof(*list));
815     if (list == 0)
816         novm("option list entry");
817     list->options = opt;
818     list->next = extra_options;
819     extra_options = list;
820 }
821
822 /*
823  * check_options - check that options are valid and consistent.
824  */
825 void
826 check_options()
827 {
828         if (logfile_fd >= 0 && logfile_fd != log_to_fd)
829                 close(logfile_fd);
830 }
831
832 /*
833  * print_option - print out an option and its value
834  */
835 static void
836 print_option(opt, mainopt, printer, arg)
837     option_t *opt, *mainopt;
838     void (*printer) __P((void *, char *, ...));
839     void *arg;
840 {
841         int i, v;
842         char *p;
843
844         if (opt->flags & OPT_NOPRINT)
845                 return;
846         switch (opt->type) {
847         case o_bool:
848                 v = opt->flags & OPT_VALUE;
849                 if (*(bool *)opt->addr != v)
850                         /* this can happen legitimately, e.g. lock
851                            option turned off for default device */
852                         break;
853                 printer(arg, "%s", opt->name);
854                 break;
855         case o_int:
856                 v = opt->flags & OPT_VALUE;
857                 if (v >= 128)
858                         v -= 256;
859                 i = *(int *)opt->addr;
860                 if (opt->flags & OPT_NOARG) {
861                         printer(arg, "%s", opt->name);
862                         if (i != v) {
863                                 if (opt->flags & OPT_INC) {
864                                         for (; i > v; i -= v)
865                                                 printer(arg, " %s", opt->name);
866                                 } else
867                                         printer(arg, " # oops: %d not %d\n",
868                                                 i, v);
869                         }
870                 } else {
871                         printer(arg, "%s %d", opt->name, i);
872                 }
873                 break;
874         case o_uint32:
875                 printer(arg, "%s", opt->name);
876                 if ((opt->flags & OPT_NOARG) == 0)
877                         printer(arg, " %x", *(u_int32_t *)opt->addr);
878                 break;
879
880         case o_string:
881                 if (opt->flags & OPT_HIDE) {
882                         p = "??????";
883                 } else {
884                         p = (char *) opt->addr;
885                         if ((opt->flags & OPT_STATIC) == 0)
886                                 p = *(char **)p;
887                 }
888                 printer(arg, "%s %q", opt->name, p);
889                 break;
890
891         case o_special:
892         case o_special_noarg:
893         case o_wild:
894                 if (opt->type != o_wild) {
895                         printer(arg, "%s", opt->name);
896                         if (n_arguments(opt) == 0)
897                                 break;
898                         printer(arg, " ");
899                 }
900                 if (opt->flags & OPT_A2PRINTER) {
901                         void (*oprt) __P((option_t *,
902                                           void ((*)__P((void *, char *, ...))),
903                                           void *));
904                         oprt = (void (*) __P((option_t *,
905                                          void ((*)__P((void *, char *, ...))),
906                                          void *)))opt->addr2;
907                         (*oprt)(opt, printer, arg);
908                 } else if (opt->flags & OPT_A2STRVAL) {
909                         p = (char *) opt->addr2;
910                         if ((opt->flags & OPT_STATIC) == 0)
911                                 p = *(char **)p;
912                         printer("%q", p);
913                 } else if (opt->flags & OPT_A2LIST) {
914                         struct option_value *ovp;
915
916                         ovp = (struct option_value *) opt->addr2;
917                         for (;;) {
918                                 printer(arg, "%q", ovp->value);
919                                 if ((ovp = ovp->next) == NULL)
920                                         break;
921                                 printer(arg, "\t\t# (from %s)\n%s ",
922                                         ovp->source, opt->name);
923                         }
924                 } else {
925                         printer(arg, "xxx # [don't know how to print value]");
926                 }
927                 break;
928
929         default:
930                 printer(arg, "# %s value (type %d\?\?)", opt->name, opt->type);
931                 break;
932         }
933         printer(arg, "\t\t# (from %s)\n", mainopt->source);
934 }
935
936 /*
937  * print_option_list - print out options in effect from an
938  * array of options.
939  */
940 static void
941 print_option_list(opt, printer, arg)
942     option_t *opt;
943     void (*printer) __P((void *, char *, ...));
944     void *arg;
945 {
946         while (opt->name != NULL) {
947                 if (opt->priority != OPRIO_DEFAULT
948                     && opt->winner != (short int) -1)
949                         print_option(opt + opt->winner, opt, printer, arg);
950                 do {
951                         ++opt;
952                 } while (opt->flags & OPT_PRIOSUB);
953         }
954 }
955
956 /*
957  * print_options - print out what options are in effect.
958  */
959 void
960 print_options(printer, arg)
961     void (*printer) __P((void *, char *, ...));
962     void *arg;
963 {
964         struct option_list *list;
965         int i;
966
967         printer(arg, "pppd options in effect:\n");
968         print_option_list(general_options, printer, arg);
969         print_option_list(auth_options, printer, arg);
970         for (list = extra_options; list != NULL; list = list->next)
971                 print_option_list(list->options, printer, arg);
972         print_option_list(the_channel->options, printer, arg);
973         for (i = 0; protocols[i] != NULL; ++i)
974                 print_option_list(protocols[i]->options, printer, arg);
975 }
976
977 /*
978  * usage - print out a message telling how to use the program.
979  */
980 static void
981 usage()
982 {
983     if (phase == PHASE_INITIALIZE)
984         fprintf(stderr, usage_string, VERSION, progname);
985 }
986
987 /*
988  * showhelp - print out usage message and exit.
989  */
990 static int
991 showhelp(argv)
992     char **argv;
993 {
994     if (phase == PHASE_INITIALIZE) {
995         usage();
996         exit(0);
997     }
998     return 0;
999 }
1000
1001 /*
1002  * showversion - print out the version number and exit.
1003  */
1004 static int
1005 showversion(argv)
1006     char **argv;
1007 {
1008     if (phase == PHASE_INITIALIZE) {
1009         fprintf(stderr, "pppd version %s\n", VERSION);
1010         exit(0);
1011     }
1012     return 0;
1013 }
1014
1015 /*
1016  * option_error - print a message about an error in an option.
1017  * The message is logged, and also sent to
1018  * stderr if phase == PHASE_INITIALIZE.
1019  */
1020 void
1021 option_error __V((char *fmt, ...))
1022 {
1023     va_list args;
1024     char buf[1024];
1025
1026 #if defined(__STDC__)
1027     va_start(args, fmt);
1028 #else
1029     char *fmt;
1030     va_start(args);
1031     fmt = va_arg(args, char *);
1032 #endif
1033     vslprintf(buf, sizeof(buf), fmt, args);
1034     va_end(args);
1035     if (phase == PHASE_INITIALIZE)
1036         fprintf(stderr, "%s: %s\n", progname, buf);
1037     syslog(LOG_ERR, "%s", buf);
1038 }
1039
1040 #if 0
1041 /*
1042  * readable - check if a file is readable by the real user.
1043  */
1044 int
1045 readable(fd)
1046     int fd;
1047 {
1048     uid_t uid;
1049     int i;
1050     struct stat sbuf;
1051
1052     uid = getuid();
1053     if (uid == 0)
1054         return 1;
1055     if (fstat(fd, &sbuf) != 0)
1056         return 0;
1057     if (sbuf.st_uid == uid)
1058         return sbuf.st_mode & S_IRUSR;
1059     if (sbuf.st_gid == getgid())
1060         return sbuf.st_mode & S_IRGRP;
1061     for (i = 0; i < ngroups; ++i)
1062         if (sbuf.st_gid == groups[i])
1063             return sbuf.st_mode & S_IRGRP;
1064     return sbuf.st_mode & S_IROTH;
1065 }
1066 #endif
1067
1068 /*
1069  * Read a word from a file.
1070  * Words are delimited by white-space or by quotes (" or ').
1071  * Quotes, white-space and \ may be escaped with \.
1072  * \<newline> is ignored.
1073  */
1074 int
1075 getword(f, word, newlinep, filename)
1076     FILE *f;
1077     char *word;
1078     int *newlinep;
1079     char *filename;
1080 {
1081     int c, len, escape;
1082     int quoted, comment;
1083     int value, digit, got, n;
1084
1085 #define isoctal(c) ((c) >= '0' && (c) < '8')
1086
1087     *newlinep = 0;
1088     len = 0;
1089     escape = 0;
1090     comment = 0;
1091
1092     /*
1093      * First skip white-space and comments.
1094      */
1095     for (;;) {
1096         c = getc(f);
1097         if (c == EOF)
1098             break;
1099
1100         /*
1101          * A newline means the end of a comment; backslash-newline
1102          * is ignored.  Note that we cannot have escape && comment.
1103          */
1104         if (c == '\n') {
1105             if (!escape) {
1106                 *newlinep = 1;
1107                 comment = 0;
1108             } else
1109                 escape = 0;
1110             continue;
1111         }
1112
1113         /*
1114          * Ignore characters other than newline in a comment.
1115          */
1116         if (comment)
1117             continue;
1118
1119         /*
1120          * If this character is escaped, we have a word start.
1121          */
1122         if (escape)
1123             break;
1124
1125         /*
1126          * If this is the escape character, look at the next character.
1127          */
1128         if (c == '\\') {
1129             escape = 1;
1130             continue;
1131         }
1132
1133         /*
1134          * If this is the start of a comment, ignore the rest of the line.
1135          */
1136         if (c == '#') {
1137             comment = 1;
1138             continue;
1139         }
1140
1141         /*
1142          * A non-whitespace character is the start of a word.
1143          */
1144         if (!isspace(c))
1145             break;
1146     }
1147
1148     /*
1149      * Save the delimiter for quoted strings.
1150      */
1151     if (!escape && (c == '"' || c == '\'')) {
1152         quoted = c;
1153         c = getc(f);
1154     } else
1155         quoted = 0;
1156
1157     /*
1158      * Process characters until the end of the word.
1159      */
1160     while (c != EOF) {
1161         if (escape) {
1162             /*
1163              * This character is escaped: backslash-newline is ignored,
1164              * various other characters indicate particular values
1165              * as for C backslash-escapes.
1166              */
1167             escape = 0;
1168             if (c == '\n') {
1169                 c = getc(f);
1170                 continue;
1171             }
1172
1173             got = 0;
1174             switch (c) {
1175             case 'a':
1176                 value = '\a';
1177                 break;
1178             case 'b':
1179                 value = '\b';
1180                 break;
1181             case 'f':
1182                 value = '\f';
1183                 break;
1184             case 'n':
1185                 value = '\n';
1186                 break;
1187             case 'r':
1188                 value = '\r';
1189                 break;
1190             case 's':
1191                 value = ' ';
1192                 break;
1193             case 't':
1194                 value = '\t';
1195                 break;
1196
1197             default:
1198                 if (isoctal(c)) {
1199                     /*
1200                      * \ddd octal sequence
1201                      */
1202                     value = 0;
1203                     for (n = 0; n < 3 && isoctal(c); ++n) {
1204                         value = (value << 3) + (c & 07);
1205                         c = getc(f);
1206                     }
1207                     got = 1;
1208                     break;
1209                 }
1210
1211                 if (c == 'x') {
1212                     /*
1213                      * \x<hex_string> sequence
1214                      */
1215                     value = 0;
1216                     c = getc(f);
1217                     for (n = 0; n < 2 && isxdigit(c); ++n) {
1218                         digit = toupper(c) - '0';
1219                         if (digit > 10)
1220                             digit += '0' + 10 - 'A';
1221                         value = (value << 4) + digit;
1222                         c = getc (f);
1223                     }
1224                     got = 1;
1225                     break;
1226                 }
1227
1228                 /*
1229                  * Otherwise the character stands for itself.
1230                  */
1231                 value = c;
1232                 break;
1233             }
1234
1235             /*
1236              * Store the resulting character for the escape sequence.
1237              */
1238             if (len < MAXWORDLEN-1)
1239                 word[len] = value;
1240             ++len;
1241
1242             if (!got)
1243                 c = getc(f);
1244             continue;
1245
1246         }
1247
1248         /*
1249          * Not escaped: see if we've reached the end of the word.
1250          */
1251         if (quoted) {
1252             if (c == quoted)
1253                 break;
1254         } else {
1255             if (isspace(c) || c == '#') {
1256                 ungetc (c, f);
1257                 break;
1258             }
1259         }
1260
1261         /*
1262          * Backslash starts an escape sequence.
1263          */
1264         if (c == '\\') {
1265             escape = 1;
1266             c = getc(f);
1267             continue;
1268         }
1269
1270         /*
1271          * An ordinary character: store it in the word and get another.
1272          */
1273         if (len < MAXWORDLEN-1)
1274             word[len] = c;
1275         ++len;
1276
1277         c = getc(f);
1278     }
1279
1280     /*
1281      * End of the word: check for errors.
1282      */
1283     if (c == EOF) {
1284         if (ferror(f)) {
1285             if (errno == 0)
1286                 errno = EIO;
1287             option_error("Error reading %s: %m", filename);
1288             die(1);
1289         }
1290         /*
1291          * If len is zero, then we didn't find a word before the
1292          * end of the file.
1293          */
1294         if (len == 0)
1295             return 0;
1296     }
1297
1298     /*
1299      * Warn if the word was too long, and append a terminating null.
1300      */
1301     if (len >= MAXWORDLEN) {
1302         option_error("warning: word in file %s too long (%.20s...)",
1303                      filename, word);
1304         len = MAXWORDLEN - 1;
1305     }
1306     word[len] = 0;
1307
1308     return 1;
1309
1310 #undef isoctal
1311
1312 }
1313
1314 /*
1315  * number_option - parse an unsigned numeric parameter for an option.
1316  */
1317 static int
1318 number_option(str, valp, base)
1319     char *str;
1320     u_int32_t *valp;
1321     int base;
1322 {
1323     char *ptr;
1324
1325     *valp = strtoul(str, &ptr, base);
1326     if (ptr == str) {
1327         option_error("invalid numeric parameter '%s' for %s option",
1328                      str, current_option);
1329         return 0;
1330     }
1331     return 1;
1332 }
1333
1334
1335 /*
1336  * int_option - like number_option, but valp is int *,
1337  * the base is assumed to be 0, and *valp is not changed
1338  * if there is an error.
1339  */
1340 int
1341 int_option(str, valp)
1342     char *str;
1343     int *valp;
1344 {
1345     u_int32_t v;
1346
1347     if (!number_option(str, &v, 0))
1348         return 0;
1349     *valp = (int) v;
1350     return 1;
1351 }
1352
1353
1354 /*
1355  * The following procedures parse options.
1356  */
1357
1358 /*
1359  * readfile - take commands from a file.
1360  */
1361 static int
1362 readfile(argv)
1363     char **argv;
1364 {
1365     return options_from_file(*argv, 1, 1, privileged_option);
1366 }
1367
1368 /*
1369  * callfile - take commands from /etc/ppp/peers/<name>.
1370  * Name may not contain /../, start with / or ../, or end in /..
1371  */
1372 static int
1373 callfile(argv)
1374     char **argv;
1375 {
1376     char *fname, *arg, *p;
1377     int l, ok;
1378
1379     arg = *argv;
1380     ok = 1;
1381     if (arg[0] == '/' || arg[0] == 0)
1382         ok = 0;
1383     else {
1384         for (p = arg; *p != 0; ) {
1385             if (p[0] == '.' && p[1] == '.' && (p[2] == '/' || p[2] == 0)) {
1386                 ok = 0;
1387                 break;
1388             }
1389             while (*p != '/' && *p != 0)
1390                 ++p;
1391             if (*p == '/')
1392                 ++p;
1393         }
1394     }
1395     if (!ok) {
1396         option_error("call option value may not contain .. or start with /");
1397         return 0;
1398     }
1399
1400     l = strlen(arg) + strlen(_PATH_PEERFILES) + 1;
1401     if ((fname = (char *) malloc(l)) == NULL)
1402         novm("call file name");
1403     slprintf(fname, l, "%s%s", _PATH_PEERFILES, arg);
1404
1405     ok = options_from_file(fname, 1, 1, 1);
1406
1407     free(fname);
1408     return ok;
1409 }
1410
1411 #ifdef PPP_FILTER
1412 /*
1413  * setpassfilter - Set the pass filter for packets
1414  */
1415 static int
1416 setpassfilter(argv)
1417     char **argv;
1418 {
1419     pc.linktype = DLT_PPP;
1420     pc.snapshot = PPP_HDRLEN;
1421  
1422     if (pcap_compile(&pc, &pass_filter, *argv, 1, netmask) == 0)
1423         return 1;
1424     option_error("error in pass-filter expression: %s\n", pcap_geterr(&pc));
1425     return 0;
1426 }
1427
1428 /*
1429  * setactivefilter - Set the active filter for packets
1430  */
1431 static int
1432 setactivefilter(argv)
1433     char **argv;
1434 {
1435     pc.linktype = DLT_PPP;
1436     pc.snapshot = PPP_HDRLEN;
1437  
1438     if (pcap_compile(&pc, &active_filter, *argv, 1, netmask) == 0)
1439         return 1;
1440     option_error("error in active-filter expression: %s\n", pcap_geterr(&pc));
1441     return 0;
1442 }
1443 #endif
1444
1445 /*
1446  * setdomain - Set domain name to append to hostname 
1447  */
1448 static int
1449 setdomain(argv)
1450     char **argv;
1451 {
1452     gethostname(hostname, MAXNAMELEN);
1453     if (**argv != 0) {
1454         if (**argv != '.')
1455             strncat(hostname, ".", MAXNAMELEN - strlen(hostname));
1456         domain = hostname + strlen(hostname);
1457         strncat(hostname, *argv, MAXNAMELEN - strlen(hostname));
1458     }
1459     hostname[MAXNAMELEN-1] = 0;
1460     return (1);
1461 }
1462
1463
1464 static int
1465 setlogfile(argv)
1466     char **argv;
1467 {
1468     int fd, err;
1469
1470     if (!privileged_option)
1471         seteuid(getuid());
1472     fd = open(*argv, O_WRONLY | O_APPEND | O_CREAT | O_EXCL, 0644);
1473     if (fd < 0 && errno == EEXIST)
1474         fd = open(*argv, O_WRONLY | O_APPEND);
1475     err = errno;
1476     if (!privileged_option)
1477         seteuid(0);
1478     if (fd < 0) {
1479         errno = err;
1480         option_error("Can't open log file %s: %m", *argv);
1481         return 0;
1482     }
1483     strlcpy(logfile_name, *argv, sizeof(logfile_name));
1484     if (logfile_fd >= 0)
1485         close(logfile_fd);
1486     logfile_fd = fd;
1487     log_to_fd = fd;
1488     log_default = 0;
1489     return 1;
1490 }
1491 #ifdef MAXOCTETS
1492 static int
1493 setmodir(argv)
1494     char **argv;
1495 {
1496     if(*argv == NULL)
1497         return 0;
1498     if(!strcmp(*argv,"in")) {
1499         maxoctets_dir = PPP_OCTETS_DIRECTION_IN;
1500     } else if (!strcmp(*argv,"out")) {
1501         maxoctets_dir = PPP_OCTETS_DIRECTION_OUT;
1502     } else if (!strcmp(*argv,"max")) {
1503         maxoctets_dir = PPP_OCTETS_DIRECTION_MAXOVERAL;
1504     } else {
1505         maxoctets_dir = PPP_OCTETS_DIRECTION_SUM;
1506     }
1507     return 1;
1508 }
1509 #endif
1510
1511 #ifdef PLUGIN
1512 static int
1513 loadplugin(argv)
1514     char **argv;
1515 {
1516     char *arg = *argv;
1517     void *handle;
1518     const char *err;
1519     void (*init) __P((void));
1520     char *path = arg;
1521     const char *vers;
1522
1523     if (strchr(arg, '/') == 0) {
1524         const char *base = _PATH_PLUGIN;
1525         int l = strlen(base) + strlen(arg) + 2;
1526         path = malloc(l);
1527         if (path == 0)
1528             novm("plugin file path");
1529         strlcpy(path, base, l);
1530         strlcat(path, "/", l);
1531         strlcat(path, arg, l);
1532     }
1533     handle = dlopen(path, RTLD_GLOBAL | RTLD_NOW);
1534     if (handle == 0) {
1535         err = dlerror();
1536         if (err != 0)
1537             option_error("%s", err);
1538         option_error("Couldn't load plugin %s", arg);
1539         goto err;
1540     }
1541     init = (void (*)(void))dlsym(handle, "plugin_init");
1542     if (init == 0) {
1543         option_error("%s has no initialization entry point", arg);
1544         goto errclose;
1545     }
1546     vers = (const char *) dlsym(handle, "pppd_version");
1547     if (vers == 0) {
1548         warn("Warning: plugin %s has no version information", arg);
1549     } else if (strcmp(vers, VERSION) != 0) {
1550         option_error("Plugin %s is for pppd version %s, this is %s",
1551                      arg, vers, VERSION);
1552         goto errclose;
1553     }
1554     info("Plugin %s loaded.", arg);
1555     (*init)();
1556     return 1;
1557
1558  errclose:
1559     dlclose(handle);
1560  err:
1561     if (path != arg)
1562         free(path);
1563     return 0;
1564 }
1565 #endif /* PLUGIN */