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