2 * options.c - handles option processing for PPP.
4 * Copyright (c) 1989 Carnegie Mellon University.
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.
20 #define RCSID "$Id: options.c,v 1.3 2006/09/06 11:01:34 wilson Exp $"
38 #include <pcap-int.h> /* XXX: To get struct pcap */
42 #include "pathnames.h"
46 extern int DEB_DISC,DEB_DISC2;
48 #if defined(ultrix) || defined(NeXT)
49 char *strdup __P((char *));
52 static const char rcsid[] = RCSID;
55 struct option_value *next;
61 * Option variables and default values.
64 int dflag = 0; /* Tell libpcap we want debugging */
68 int debug = 0; /* Debug flag */
69 int kdebugflag = 0; /* Tell kernel to print debug messages */
70 int default_device = 1; /* Using /dev/tty or equivalent */
71 char devnam[MAXPATHLEN]; /* Device name */
72 bool nodetach = 1; /* Don't detach from controlling tty */
73 bool updetach = 0; /* Detach once link is up */
74 int maxconnect = 0; /* Maximum connect time */
75 char user[MAXNAMELEN]=""; /* Username for PAP */
76 char passwd[MAXSECRETLEN]=""; /* Password for PAP */
77 bool persist = 1; /* Reopen link after it goes down */
78 char our_name[MAXNAMELEN]; /* Our name for authentication purposes */
79 bool demand = 0; /* do dial-on-demand */
80 char *ipparam = NULL; /* Extra parameter for ip up/down scripts */
81 int idle_time_limit = 0; /* Disconnect if idle for this many seconds */
82 int holdoff = 3; /* # seconds to pause before reconnecting */
83 bool holdoff_specified; /* true if a holdoff value has been given */
84 int log_to_fd = 1; /* send log messages to this fd too */
85 bool log_default = 1; /* log_to_fd is default (stdout) */
86 int maxfail = 10; /* max # of unsuccessful connection attempts */
87 char linkname[MAXPATHLEN]; /* logical name for link */
88 bool tune_kernel; /* may alter kernel settings */
89 int connect_delay = 1000; /* wait this many ms after connect script */
90 int req_unit = -1; /* requested interface unit */
91 bool multilink = 0; /* Enable multilink operation */
92 char *bundle_name = NULL; /* bundle name for multilink */
93 bool dump_options; /* print out option values */
94 bool dryrun; /* print out option values and exit */
95 char *domain; /* domain name set by domain option */
102 char session_path[32]="";
103 char oldsession[MAXPATHLEN]=""; /* Mac address and session ID of the previous session */
105 char req_name[MAXPATHLEN] = ""; /* logical name for link */
106 static char ip_addr[MAXPATHLEN] = ""; /* IP address */
110 extern option_t auth_options[];
111 extern struct stat devstat;
112 extern int setipaddr(char *arg, char **argv, int doit);
113 extern int setdevname_pppoe(const char *cp);
114 extern int setdevname_pppoatm(const char *cp);
115 //Charles 11/30/2003, add for unnumbered PPP (declared in ipcp.c)
116 extern bool unnumbered;
117 extern char wan_IP[];
118 extern char wan_submask[];
121 struct bpf_program pass_filter;/* Filter program for packets to pass */
122 struct bpf_program active_filter; /* Filter program for link-active pkts */
123 pcap_t pc; /* Fake struct pcap so we can compile expr */
126 char *current_option; /* the name of the option being parsed */
127 int privileged_option; /* set iff the current option came from root */
128 char *option_source; /* string saying where the option came from */
129 int option_priority = OPRIO_CFGFILE; /* priority of the current options */
130 bool devnam_fixed; /* can no longer change device name */
132 static int logfile_fd = -1; /* fd opened for log file */
133 static char logfile_name[MAXPATHLEN]; /* name of log file */
135 #if defined(INCLUDE_MTU_LAN_PPP)
136 int glb_CONFIG_PPP_MTU = 0;
139 #ifdef BUILD_DOMAIN_LOCK
140 int wsnCheckStrTail(char *username, char *validDomain);
141 int wsnIsValidPppUser(char *pppUser);
147 static int setdomain __P((char **));
148 static int readfile __P((char **));
149 static int callfile __P((char **));
150 static int showversion __P((char **));
151 static int showhelp __P((char **));
152 static void usage __P((void));
153 static int setlogfile __P((char **));
155 static int loadplugin __P((char **));
159 static int setpassfilter __P((char **));
160 static int setactivefilter __P((char **));
163 static option_t *find_option __P((const char *name));
164 static int process_option __P((option_t *, char *, char **));
165 static int n_arguments __P((option_t *));
166 static int number_option __P((char *, u_int32_t *, int));
169 * Structure to store extra lists of options.
173 struct option_list *next;
176 static struct option_list *extra_options = NULL;
181 option_t general_options[] = {
182 { "debug", o_int, &debug,
183 "Increase debugging level", OPT_INC | OPT_NOARG | 1 },
184 { "-d", o_int, &debug,
185 "Increase debugging level",
186 OPT_ALIAS | OPT_INC | OPT_NOARG | 1 },
188 { "kdebug", o_int, &kdebugflag,
189 "Set kernel driver debug level", OPT_PRIO },
191 { "nodetach", o_bool, &nodetach,
192 "Don't detach from controlling tty", OPT_PRIO | 1 },
193 { "-detach", o_bool, &nodetach,
194 "Don't detach from controlling tty", OPT_ALIAS | OPT_PRIOSUB | 1 },
195 { "updetach", o_bool, &updetach,
196 "Detach from controlling tty once link is up",
197 OPT_PRIOSUB | OPT_A2CLR | 1, &nodetach },
199 { "holdoff", o_int, &holdoff,
200 "Set time in seconds before retrying connection", OPT_PRIO },
202 { "idle", o_int, &idle_time_limit,
203 "Set time in seconds before disconnecting idle link", OPT_PRIO },
205 { "maxconnect", o_int, &maxconnect,
206 "Set connection time limit",
207 OPT_PRIO | OPT_LLIMIT | OPT_NOINCR | OPT_ZEROINF },
209 { "domain", o_special, (void *)setdomain,
210 "Add given domain name to hostname",
211 OPT_PRIO | OPT_PRIV | OPT_A2STRVAL, &domain },
213 { "file", o_special, (void *)readfile,
214 "Take options from a file", OPT_NOPRINT },
215 { "call", o_special, (void *)callfile,
216 "Take options from a privileged file", OPT_NOPRINT },
218 { "persist", o_bool, &persist,
219 "Keep on reopening connection after close", OPT_PRIO | 1 },
220 { "nopersist", o_bool, &persist,
221 "Turn off persist option", OPT_PRIOSUB },
223 { "demand", o_bool, &demand,
224 "Dial on demand", OPT_INITONLY | 1, &persist },
226 { "--version", o_special_noarg, (void *)showversion,
227 "Show version number" },
228 { "--help", o_special_noarg, (void *)showhelp,
229 "Show brief listing of options" },
230 { "-h", o_special_noarg, (void *)showhelp,
231 "Show brief listing of options", OPT_ALIAS },
233 { "logfile", o_special, (void *)setlogfile,
234 "Append log messages to this file",
235 OPT_PRIO | OPT_A2STRVAL | OPT_STATIC, &logfile_name },
236 { "logfd", o_int, &log_to_fd,
237 "Send log messages to this file descriptor",
238 OPT_PRIOSUB | OPT_A2CLR, &log_default },
239 { "nolog", o_int, &log_to_fd,
240 "Don't send log messages to any file",
241 OPT_PRIOSUB | OPT_NOARG | OPT_VAL(-1) },
242 { "nologfd", o_int, &log_to_fd,
243 "Don't send log messages to any file descriptor",
244 OPT_PRIOSUB | OPT_ALIAS | OPT_NOARG | OPT_VAL(-1) },
246 { "linkname", o_string, linkname,
247 "Set logical name for link",
248 OPT_PRIO | OPT_PRIV | OPT_STATIC, NULL, MAXPATHLEN },
250 { "maxfail", o_int, &maxfail,
251 "Maximum number of unsuccessful connection attempts to allow",
254 { "ktune", o_bool, &tune_kernel,
255 "Alter kernel settings as necessary", OPT_PRIO | 1 },
256 { "noktune", o_bool, &tune_kernel,
257 "Don't alter kernel settings", OPT_PRIOSUB },
259 { "connect-delay", o_int, &connect_delay,
260 "Maximum time (in ms) to wait after connect script finishes",
263 { "unit", o_int, &req_unit,
264 "PPP interface unit number to use if possible",
265 OPT_PRIO | OPT_LLIMIT, 0, 0 },
267 { "dump", o_bool, &dump_options,
268 "Print out option values after parsing all options", 1 },
269 { "dryrun", o_bool, &dryrun,
270 "Stop after parsing, printing, and checking options", 1 },
272 #ifdef HAVE_MULTILINK
273 { "multilink", o_bool, &multilink,
274 "Enable multilink operation", OPT_PRIO | 1 },
275 { "mp", o_bool, &multilink,
276 "Enable multilink operation", OPT_PRIOSUB | OPT_ALIAS | 1 },
277 { "nomultilink", o_bool, &multilink,
278 "Disable multilink operation", OPT_PRIOSUB | 0 },
279 { "nomp", o_bool, &multilink,
280 "Disable multilink operation", OPT_PRIOSUB | OPT_ALIAS | 0 },
282 { "bundle", o_string, &bundle_name,
283 "Bundle name for multilink", OPT_PRIO },
284 #endif /* HAVE_MULTILINK */
287 { "plugin", o_special, (void *)loadplugin,
288 "Load a plug-in module into pppd", OPT_PRIV | OPT_A2LIST },
292 { "pdebug", o_int, &dflag,
293 "libpcap debugging", OPT_PRIO },
295 { "pass-filter", 1, setpassfilter,
296 "set filter for packets to pass", OPT_PRIO },
298 { "active-filter", 1, setactivefilter,
299 "set filter for active pkts", OPT_PRIO },
305 #ifndef IMPLEMENTATION
306 #define IMPLEMENTATION ""
309 static char *usage_string = "\
311 Usage: %s [ options ], where options are:\n\
312 <device> Communicate over the named device\n\
313 <speed> Set the baud rate to <speed>\n\
314 <loc>:<rem> Set the local and/or remote interface IP\n\
315 addresses. Either one may be omitted.\n\
316 asyncmap <n> Set the desired async map to hex <n>\n\
317 auth Require authentication from peer\n\
318 connect <p> Invoke shell command <p> to set up the serial line\n\
319 crtscts Use hardware RTS/CTS flow control\n\
320 defaultroute Add default route through interface\n\
321 file <f> Take options from file <f>\n\
322 modem Use modem control lines\n\
323 mru <n> Set MRU value to <n> for negotiation\n\
324 See pppd(8) for more options.\n\
327 #ifdef SUPPORT_PPP_SCHEDULE
328 extern int ppp_runonce;
334 parse_args(argc, argv)
341 while ((opt = getopt(argc, argv, "nbsxda:e:g:i:ku:p:o:lc:m:f:r:q:RA:w:zjh")) != -1) {
343 #ifdef SUPPORT_PPP_SCHEDULE
348 //ODM Charles, add for manual conn/disconn
354 //Charles 11/30/2003, add unnumbered PPP
358 //IP for unnumbered PPP, in a.b.c.d format
360 strncpy(wan_IP, optarg, 16);
362 //subnet mask for unnumbered PPP, in a.b.c.d format
364 strncpy(wan_submask, optarg, 16);
369 //autoscanP2 = atoi(optarg);
375 debug = nodetach = 1;
379 setdevname_pppoatm(optarg);
383 setdevname_pppoe(optarg);
389 strncpy(user, optarg, MAXNAMELEN);
390 strncpy(our_name, optarg, MAXNAMELEN);
391 #ifdef BUILD_DOMAIN_LOCK
392 if(wsnIsValidPppUser(user)==0){ // 0: FALSE
393 printf("PPP username is out of valid domains.\n");
395 //strcpy(our_name, "");
400 strncpy(passwd, optarg, MAXSECRETLEN);
403 idle_time_limit = atoi(optarg);
410 strncpy(req_name, optarg, MAXPATHLEN);
411 retval = sscanf(req_name, "%d.%d.%d", num, num+1, num+2);
412 sprintf(req_name, "%d_%d_%d", num[0], num[1], num[2]);
413 sprintf(session_path, "ppp_%s", req_name);
416 strncpy(oldsession, optarg, MAXPATHLEN);
419 opflag = atoi(optarg);
422 strncpy(pppoe_srv_name, optarg, MAXPATHLEN);
425 strncpy(pppoe_ac_name, optarg, MAXPATHLEN);
430 #if defined(INCLUDE_MTU_LAN_PPP)
432 lcp_allowoptions[0].mru = atoi(optarg);
433 glb_CONFIG_PPP_MTU = atoi(optarg);
443 strncpy(ip_addr, optarg, MAXPATHLEN);
444 ip_addr[strlen(ip_addr)] = ':';
445 setipaddr (ip_addr, NULL, 1);
448 fprintf(stderr, "usage: %s [-s] [-b] [-d] [-i interface] [-a vcc] [-u username] [-p passwd] [-o idle] [-m prevmac/prevsid] [-A ipaddr]\n", argv[0]);
459 parse_args(argc, argv)
467 privileged_option = privileged;
468 option_source = "command line";
469 option_priority = OPRIO_CMDLINE;
473 opt = find_option(arg);
475 option_error("unrecognized option '%s'", arg);
479 n = n_arguments(opt);
481 option_error("too few parameters for option %s", arg);
484 if (!process_option(opt, arg, argv))
494 * options_from_file - Read a string of options from a file,
495 * and interpret them.
498 options_from_file(filename, must_exist, check_prot, priv)
505 int i, newline, ret, err;
510 char args[MAXARGS][MAXWORDLEN];
511 char cmd[MAXWORDLEN];
515 f = fopen(filename, "r");
522 if (err != ENOENT && err != ENOTDIR)
523 warn("Warning: can't open options file %s: %m", filename);
526 option_error("Can't open options file %s: %m", filename);
530 oldpriv = privileged_option;
531 privileged_option = priv;
532 oldsource = option_source;
533 option_source = strdup(filename);
534 if (option_source == NULL)
535 option_source = "file";
537 while (getword(f, cmd, &newline, filename)) {
538 opt = find_option(cmd);
540 option_error("In file %s: unrecognized option '%s'",
544 n = n_arguments(opt);
545 for (i = 0; i < n; ++i) {
546 if (!getword(f, args[i], &newline, filename)) {
548 "In file %s: too few parameters for option '%s'",
554 if (!process_option(opt, cmd, argv))
561 privileged_option = oldpriv;
562 option_source = oldsource;
567 * options_from_user - See if the use has a ~/.ppprc file,
568 * and if so, interpret options from it.
573 char *user, *path, *file;
578 pw = getpwuid(getuid());
579 if (pw == NULL || (user = pw->pw_dir) == NULL || user[0] == 0)
581 file = _PATH_USEROPT;
582 pl = strlen(user) + strlen(file) + 2;
585 novm("init file name");
586 slprintf(path, pl, "%s/%s", user, file);
587 option_priority = OPRIO_CFGFILE;
588 ret = options_from_file(path, 0, 1, privileged);
594 * options_for_tty - See if an options file exists for the serial
595 * device, and if so, interpret options from it.
596 * We only allow the per-tty options file to override anything from
597 * the command line if it is something that the user can't override
598 * once it has been set by root; this is done by giving configuration
599 * files a lower priority than the command line.
604 char *dev, *path, *p;
609 if (strncmp(dev, "/dev/", 5) == 0)
611 if (dev[0] == 0 || strcmp(dev, "tty") == 0)
612 return 1; /* don't look for /etc/ppp/options.tty */
613 pl = strlen(_PATH_TTYOPT) + strlen(dev) + 1;
616 novm("tty init file name");
617 slprintf(path, pl, "%s%s", _PATH_TTYOPT, dev);
618 /* Turn slashes into dots, for Solaris case (e.g. /dev/term/a) */
619 for (p = path + strlen(_PATH_TTYOPT); *p != 0; ++p)
622 option_priority = OPRIO_CFGFILE;
623 ret = options_from_file(path, 0, 0, 1);
629 * options_from_list - process a string of options in a wordlist.
632 options_from_list(w, priv)
641 privileged_option = priv;
642 option_source = "secrets file";
643 option_priority = OPRIO_SECFILE;
646 opt = find_option(w->word);
648 option_error("In secrets file: unrecognized option '%s'",
652 n = n_arguments(opt);
654 for (i = 0; i < n; ++i) {
658 "In secrets file: too few parameters for option '%s'",
664 if (!process_option(opt, w0->word, argv))
675 * match_option - see if this option matches an option_t structure.
678 match_option(name, opt, dowild)
683 int (*match) __P((char *, char **, int));
685 if (dowild != (opt->type == o_wild))
688 return strcmp(name, opt->name) == 0;
689 match = (int (*) __P((char *, char **, int))) opt->addr;
690 return (*match)(name, NULL, 0);
694 * find_option - scan the option lists for the various protocols
695 * looking for an entry with the given name.
696 * This could be optimized by using a hash table.
703 struct option_list *list;
706 for (dowild = 0; dowild <= 1; ++dowild) {
707 for (opt = general_options; opt->name != NULL; ++opt)
708 if (match_option(name, opt, dowild))
710 for (opt = auth_options; opt->name != NULL; ++opt)
711 if (match_option(name, opt, dowild))
713 for (list = extra_options; list != NULL; list = list->next)
714 for (opt = list->options; opt->name != NULL; ++opt)
715 if (match_option(name, opt, dowild))
717 for (opt = the_channel->options; opt->name != NULL; ++opt)
718 if (match_option(name, opt, dowild))
720 for (i = 0; protocols[i] != NULL; ++i)
721 if ((opt = protocols[i]->options) != NULL)
722 for (; opt->name != NULL; ++opt)
723 if (match_option(name, opt, dowild))
730 * process_option - process one new-style option.
733 process_option(opt, cmd, argv)
741 int (*parser) __P((char **));
742 int (*wildp) __P((char *, char **, int));
743 char *optopt = (opt->type == o_wild)? "": " option";
744 int prio = option_priority;
745 option_t *mainopt = opt;
747 if ((opt->flags & OPT_PRIVFIX) && privileged_option)
749 while (mainopt->flags & OPT_PRIOSUB)
751 if (mainopt->flags & OPT_PRIO) {
752 if (prio < mainopt->priority) {
753 /* new value doesn't override old */
754 if (prio == OPRIO_CMDLINE && mainopt->priority > OPRIO_ROOT) {
755 option_error("%s%s set in %s cannot be overridden\n",
756 opt->name, optopt, mainopt->source);
761 if (prio > OPRIO_ROOT && mainopt->priority == OPRIO_CMDLINE)
762 warn("%s%s from %s overrides command line",
763 opt->name, optopt, option_source);
766 if ((opt->flags & OPT_INITONLY) && phase != PHASE_INITIALIZE) {
767 option_error("%s%s cannot be changed after initialization",
771 if ((opt->flags & OPT_PRIV) && !privileged_option) {
772 option_error("using the %s%s requires root privilege",
776 if ((opt->flags & OPT_ENABLE) && *(bool *)(opt->addr2) == 0) {
777 option_error("%s%s is disabled", opt->name, optopt);
780 if ((opt->flags & OPT_DEVEQUIV) && devnam_fixed) {
781 option_error("the %s%s may not be changed in %s",
782 opt->name, optopt, option_source);
788 v = opt->flags & OPT_VALUE;
789 *(bool *)(opt->addr) = v;
790 if (opt->addr2 && (opt->flags & OPT_A2COPY))
791 *(bool *)(opt->addr2) = v;
796 if ((opt->flags & OPT_NOARG) == 0) {
797 if (!int_option(*argv, &iv))
799 if ((((opt->flags & OPT_LLIMIT) && iv < opt->lower_limit)
800 || ((opt->flags & OPT_ULIMIT) && iv > opt->upper_limit))
801 && !((opt->flags & OPT_ZEROOK && iv == 0))) {
802 char *zok = (opt->flags & OPT_ZEROOK)? " zero or": "";
803 switch (opt->flags & OPT_LIMITS) {
805 option_error("%s value must be%s >= %d",
806 opt->name, zok, opt->lower_limit);
809 option_error("%s value must be%s <= %d",
810 opt->name, zok, opt->upper_limit);
813 option_error("%s value must be%s between %d and %d",
814 opt->name, opt->lower_limit, opt->upper_limit);
820 a = opt->flags & OPT_VALUE;
822 a -= 256; /* sign extend */
824 if (opt->flags & OPT_INC)
825 iv += *(int *)(opt->addr);
826 if ((opt->flags & OPT_NOINCR) && !privileged_option) {
827 int oldv = *(int *)(opt->addr);
828 if ((opt->flags & OPT_ZEROINF) ?
829 (oldv != 0 && (iv == 0 || iv > oldv)) : (iv > oldv)) {
830 option_error("%s value cannot be increased", opt->name);
834 *(int *)(opt->addr) = iv;
835 if (opt->addr2 && (opt->flags & OPT_A2COPY))
836 *(int *)(opt->addr2) = iv;
840 if (opt->flags & OPT_NOARG) {
841 v = opt->flags & OPT_VALUE;
844 } else if (!number_option(*argv, &v, 16))
846 if (opt->flags & OPT_OR)
847 v |= *(u_int32_t *)(opt->addr);
848 *(u_int32_t *)(opt->addr) = v;
849 if (opt->addr2 && (opt->flags & OPT_A2COPY))
850 *(u_int32_t *)(opt->addr2) = v;
854 if (opt->flags & OPT_STATIC) {
855 strlcpy((char *)(opt->addr), *argv, opt->upper_limit);
859 novm("option argument");
860 *(char **)(opt->addr) = sv;
864 case o_special_noarg:
866 parser = (int (*) __P((char **))) opt->addr;
867 if (!(*parser)(argv))
869 if (opt->flags & OPT_A2LIST) {
870 struct option_value *ovp, **pp;
872 ovp = malloc(sizeof(*ovp) + strlen(*argv));
874 strcpy(ovp->value, *argv);
875 ovp->source = option_source;
877 pp = (struct option_value **) &opt->addr2;
886 wildp = (int (*) __P((char *, char **, int))) opt->addr;
887 if (!(*wildp)(cmd, argv, 1))
892 if (opt->addr2 && (opt->flags & (OPT_A2COPY|OPT_ENABLE
893 |OPT_A2PRINTER|OPT_A2STRVAL|OPT_A2LIST)) == 0)
894 *(bool *)(opt->addr2) = !(opt->flags & OPT_A2CLR);
896 mainopt->source = option_source;
897 mainopt->priority = prio;
898 mainopt->winner = opt - mainopt;
904 * override_value - if the option priorities would permit us to
905 * override the value of option, return 1 and update the priority
906 * and source of the option value. Otherwise returns 0.
909 override_value(option, priority, source)
916 opt = find_option(option);
919 while (opt->flags & OPT_PRIOSUB)
921 if ((opt->flags & OPT_PRIO) && priority < opt->priority)
923 opt->priority = priority;
924 opt->source = source;
930 * n_arguments - tell how many arguments an option takes
936 return (opt->type == o_bool || opt->type == o_special_noarg
937 || (opt->flags & OPT_NOARG))? 0: 1;
941 * add_options - add a list of options to the set we grok.
947 struct option_list *list;
949 list = malloc(sizeof(*list));
951 novm("option list entry");
953 list->next = extra_options;
954 extra_options = list;
958 * remove_option - permanently remove an option from consideration...
959 * for use by modules to remove choices which no longer make sense.
960 * returns true if found an option
967 o = find_option(name);
975 * check_options - check that options are valid and consistent.
980 if (logfile_fd >= 0 && logfile_fd != log_to_fd)
985 * print_option - print out an option and its value
988 print_option(opt, mainopt, printer, arg)
989 option_t *opt, *mainopt;
990 void (*printer) __P((void *, char *, ...));
996 if (opt->flags & OPT_NOPRINT)
1000 v = opt->flags & OPT_VALUE;
1001 if (*(bool *)opt->addr != v)
1002 /* this can happen legitimately, e.g. lock
1003 option turned off for default device */
1005 printer(arg, "%s", opt->name);
1008 v = opt->flags & OPT_VALUE;
1011 i = *(int *)opt->addr;
1012 if (opt->flags & OPT_NOARG) {
1013 printer(arg, "%s", opt->name);
1015 if (opt->flags & OPT_INC) {
1016 for (; i > v; i -= v)
1017 printer(arg, " %s", opt->name);
1019 printer(arg, " # oops: %d not %d\n",
1023 printer(arg, "%s %d", opt->name, i);
1027 printer(arg, "%s", opt->name);
1028 if ((opt->flags & OPT_NOARG) == 0)
1029 printer(arg, " %x", *(u_int32_t *)opt->addr);
1033 if (opt->flags & OPT_HIDE) {
1036 p = (char *) opt->addr;
1037 if ((opt->flags & OPT_STATIC) == 0)
1040 printer(arg, "%s %q", opt->name, p);
1044 case o_special_noarg:
1046 if (opt->type != o_wild) {
1047 printer(arg, "%s", opt->name);
1048 if (n_arguments(opt) == 0)
1052 if (opt->flags & OPT_A2PRINTER) {
1053 void (*oprt) __P((option_t *,
1054 void ((*)__P((void *, char *, ...))),
1057 (*oprt)(opt, printer, arg);
1058 } else if (opt->flags & OPT_A2STRVAL) {
1059 p = (char *) opt->addr2;
1060 if ((opt->flags & OPT_STATIC) == 0)
1063 } else if (opt->flags & OPT_A2LIST) {
1064 struct option_value *ovp;
1066 ovp = (struct option_value *) opt->addr2;
1068 printer(arg, "%q", ovp->value);
1069 if ((ovp = ovp->next) == NULL)
1071 printer(arg, "\t\t# (from %s)\n%s ",
1072 ovp->source, opt->name);
1075 printer(arg, "xxx # [don't know how to print value]");
1080 printer(arg, "# %s value (type %d)", opt->name, opt->type);
1083 printer(arg, "\t\t# (from %s)\n", mainopt->source);
1087 * print_option_list - print out options in effect from an
1091 print_option_list(opt, printer, arg)
1093 void (*printer) __P((void *, char *, ...));
1096 while (opt->name != NULL) {
1097 if (opt->priority != OPRIO_DEFAULT
1098 && opt->winner != (short int) -1)
1099 print_option(opt + opt->winner, opt, printer, arg);
1102 } while (opt->flags & OPT_PRIOSUB);
1107 * print_options - print out what options are in effect.
1110 print_options(printer, arg)
1111 void (*printer) __P((void *, char *, ...));
1114 struct option_list *list;
1117 printer(arg, "pppd options in effect:\n");
1118 print_option_list(general_options, printer, arg);
1119 print_option_list(auth_options, printer, arg);
1120 for (list = extra_options; list != NULL; list = list->next)
1121 print_option_list(list->options, printer, arg);
1122 print_option_list(the_channel->options, printer, arg);
1123 for (i = 0; protocols[i] != NULL; ++i)
1124 print_option_list(protocols[i]->options, printer, arg);
1128 * usage - print out a message telling how to use the program.
1133 if (phase == PHASE_INITIALIZE)
1134 fprintf(stderr, usage_string, VERSION, progname);
1138 * showhelp - print out usage message and exit.
1144 if (phase == PHASE_INITIALIZE) {
1152 * showversion - print out the version number and exit.
1158 if (phase == PHASE_INITIALIZE) {
1159 fprintf(stderr, "pppd version %s\n", VERSION);
1166 * option_error - print a message about an error in an option.
1167 * The message is logged, and also sent to
1168 * stderr if phase == PHASE_INITIALIZE.
1171 option_error __V((char *fmt, ...))
1176 #if defined(__STDC__)
1177 va_start(args, fmt);
1181 fmt = va_arg(args, char *);
1183 vslprintf(buf, sizeof(buf), fmt, args);
1185 if (phase == PHASE_INITIALIZE)
1186 fprintf(stderr, "%s: %s\n", progname, buf);
1187 syslog(LOG_ERR, "%s", buf);
1192 * readable - check if a file is readable by the real user.
1205 if (fstat(fd, &sbuf) != 0)
1207 if (sbuf.st_uid == uid)
1208 return sbuf.st_mode & S_IRUSR;
1209 if (sbuf.st_gid == getgid())
1210 return sbuf.st_mode & S_IRGRP;
1211 for (i = 0; i < ngroups; ++i)
1212 if (sbuf.st_gid == groups[i])
1213 return sbuf.st_mode & S_IRGRP;
1214 return sbuf.st_mode & S_IROTH;
1219 * Read a word from a file.
1220 * Words are delimited by white-space or by quotes (" or ').
1221 * Quotes, white-space and \ may be escaped with \.
1222 * \<newline> is ignored.
1225 getword(f, word, newlinep, filename)
1232 int quoted, comment;
1233 int value, digit, got, n;
1235 #define isoctal(c) ((c) >= '0' && (c) < '8')
1243 * First skip white-space and comments.
1251 * A newline means the end of a comment; backslash-newline
1252 * is ignored. Note that we cannot have escape && comment.
1264 * Ignore characters other than newline in a comment.
1270 * If this character is escaped, we have a word start.
1276 * If this is the escape character, look at the next character.
1284 * If this is the start of a comment, ignore the rest of the line.
1292 * A non-whitespace character is the start of a word.
1299 * Save the delimiter for quoted strings.
1301 if (!escape && (c == '"' || c == '\'')) {
1308 * Process characters until the end of the word.
1313 * This character is escaped: backslash-newline is ignored,
1314 * various other characters indicate particular values
1315 * as for C backslash-escapes.
1350 * \ddd octal sequence
1353 for (n = 0; n < 3 && isoctal(c); ++n) {
1354 value = (value << 3) + (c & 07);
1363 * \x<hex_string> sequence
1367 for (n = 0; n < 2 && isxdigit(c); ++n) {
1368 digit = toupper(c) - '0';
1370 digit += '0' + 10 - 'A';
1371 value = (value << 4) + digit;
1379 * Otherwise the character stands for itself.
1386 * Store the resulting character for the escape sequence.
1388 if (len < MAXWORDLEN-1)
1399 * Not escaped: see if we've reached the end of the word.
1405 if (isspace(c) || c == '#') {
1412 * Backslash starts an escape sequence.
1421 * An ordinary character: store it in the word and get another.
1423 if (len < MAXWORDLEN-1)
1431 * End of the word: check for errors.
1437 option_error("Error reading %s: %m", filename);
1441 * If len is zero, then we didn't find a word before the
1449 * Warn if the word was too long, and append a terminating null.
1451 if (len >= MAXWORDLEN) {
1452 option_error("warning: word in file %s too long (%.20s...)",
1454 len = MAXWORDLEN - 1;
1465 * number_option - parse an unsigned numeric parameter for an option.
1468 number_option(str, valp, base)
1475 *valp = strtoul(str, &ptr, base);
1477 option_error("invalid numeric parameter '%s' for %s option",
1478 str, current_option);
1486 * int_option - like number_option, but valp is int *,
1487 * the base is assumed to be 0, and *valp is not changed
1488 * if there is an error.
1491 int_option(str, valp)
1497 if (!number_option(str, &v, 0))
1505 * The following procedures parse options.
1509 * readfile - take commands from a file.
1515 return options_from_file(*argv, 1, 1, privileged_option);
1519 * callfile - take commands from /etc/ppp/peers/<name>.
1520 * Name may not contain /../, start with / or ../, or end in /..
1526 char *fname, *arg, *p;
1531 if (arg[0] == '/' || arg[0] == 0)
1534 for (p = arg; *p != 0; ) {
1535 if (p[0] == '.' && p[1] == '.' && (p[2] == '/' || p[2] == 0)) {
1539 while (*p != '/' && *p != 0)
1546 option_error("call option value may not contain .. or start with /");
1550 l = strlen(arg) + strlen(_PATH_PEERFILES) + 1;
1551 if ((fname = (char *) malloc(l)) == NULL)
1552 novm("call file name");
1553 slprintf(fname, l, "%s%s", _PATH_PEERFILES, arg);
1555 ok = options_from_file(fname, 1, 1, 1);
1563 * setpassfilter - Set the pass filter for packets
1569 pc.linktype = DLT_PPP;
1570 pc.snapshot = PPP_HDRLEN;
1572 if (pcap_compile(&pc, &pass_filter, *argv, 1, netmask) == 0)
1574 option_error("error in pass-filter expression: %s\n", pcap_geterr(&pc));
1579 * setactivefilter - Set the active filter for packets
1582 setactivefilter(argv)
1585 pc.linktype = DLT_PPP;
1586 pc.snapshot = PPP_HDRLEN;
1588 if (pcap_compile(&pc, &active_filter, *argv, 1, netmask) == 0)
1590 option_error("error in active-filter expression: %s\n", pcap_geterr(&pc));
1596 * setdomain - Set domain name to append to hostname
1602 gethostname(hostname, MAXNAMELEN);
1605 strncat(hostname, ".", MAXNAMELEN - strlen(hostname));
1606 domain = hostname + strlen(hostname);
1607 strncat(hostname, *argv, MAXNAMELEN - strlen(hostname));
1609 hostname[MAXNAMELEN-1] = 0;
1620 if (!privileged_option)
1622 fd = open(*argv, O_WRONLY | O_APPEND | O_CREAT | O_EXCL, 0644);
1623 if (fd < 0 && errno == EEXIST)
1624 fd = open(*argv, O_WRONLY | O_APPEND);
1626 if (!privileged_option)
1630 option_error("Can't open log file %s: %m", *argv);
1633 strlcpy(logfile_name, *argv, sizeof(logfile_name));
1634 if (logfile_fd >= 0)
1650 void (*init) __P((void));
1654 if (strchr(arg, '/') == 0) {
1655 const char *base = _PATH_PLUGIN;
1656 int l = strlen(base) + strlen(arg) + 2;
1659 novm("plugin file path");
1660 strlcpy(path, base, l);
1661 strlcat(path, "/", l);
1662 strlcat(path, arg, l);
1664 handle = dlopen(path, RTLD_GLOBAL | RTLD_NOW);
1668 option_error("%s", err);
1669 option_error("Couldn't load plugin %s", arg);
1672 init = (void (*)(void))dlsym(handle, "plugin_init");
1674 option_error("%s has no initialization entry point", arg);
1677 vers = (const char *) dlsym(handle, "pppd_version");
1679 warn("Warning: plugin %s has no version information", arg);
1680 } else if (strcmp(vers, VERSION) != 0) {
1681 option_error("Plugin %s is for pppd version %s, this is %s",
1685 info("Plugin %s loaded.", arg);
1698 #ifdef BUILD_DOMAIN_LOCK
1699 int wsnCheckStrTail(char *username, char *validDomain){
1701 unsigned int domainLen=strlen(validDomain);
1703 if(strlen(username) < domainLen){
1704 //printf("Length of ppp username [%s] is less than valid domain name [%s].\n", username, validDomain);
1705 return 0; // 0: FALSE
1708 ptr = username + strlen(username) - domainLen;
1709 //printf("check string..., orig = [%s], tail = [%s]\n", username, ptr);
1711 if(strcmp(ptr, validDomain)==0)
1712 return 1; // 1: TRUE
1714 return 0; // 0: FALSE
1718 /***************************************************************************
1719 // Function Name: wsnIsValidPppUser().
1720 // Description : check whether the ppp username is valid or not.
1721 // Valid domain: @hgxx.btclick.com
1722 @hgxx.btinternet.com
1730 // Parameters : ppp username.
1731 // Returns : TRUE: valid FALSE:invalid
1732 ****************************************************************************/
1733 int wsnIsValidPppUser(char *pppUser){
1734 char *domainPtr=NULL;
1737 if(wsnCheckStrTail(pppUser, "@dataone"))
1738 return 1; // 1: TRUE
1739 if(wsnCheckStrTail(pppUser, "@touchtelindia.net"))
1740 return 1; // 1: TRUE
1741 if(wsnCheckStrTail(pppUser, "@startup_domain"))
1742 return 1; // 1: TRUE
1743 if(wsnCheckStrTail(pppUser, "@speedtest_domain"))
1744 return 1; // 1: TRUE
1745 if(wsnCheckStrTail(pppUser, "ras@teleworker"))
1746 return 1; // 1: TRUE
1747 if(wsnCheckStrTail(pppUser, "@btinternet.com"))
1748 return 1; // 1: TRUE
1749 if(wsnCheckStrTail(pppUser, "@btbroadband.com"))
1750 return 1; // 1: TRUE
1752 if(wsnCheckStrTail(pppUser, ".btclick.com")){
1753 domainPtr = pppUser + strlen(pppUser) - strlen(".btclick.com");
1754 chrDigit = domainPtr-1;
1755 if(isdigit(chrDigit[0])==0){
1756 //printf("char [%c] is not a digit.\n", chrDigit[0]);
1757 return 0; // 0: FALSE
1760 if(isdigit(chrDigit[0])==0){
1761 domainPtr = chrDigit - strlen("@hg") + 1;
1762 if(strncmp(domainPtr, "@hg", strlen("@hg"))==0)
1763 return 1; // 1: TRUE
1765 domainPtr = chrDigit - strlen("@hg");
1766 if(strncmp(domainPtr, "@hg", strlen("@hg"))==0)
1767 return 1; // 1: TRUE
1771 if(wsnCheckStrTail(pppUser, ".btinternet.com")){
1772 domainPtr = pppUser + strlen(pppUser) - strlen(".btinternet.com");
1773 chrDigit = domainPtr - 1;
1774 if(isdigit(chrDigit[0])==0){
1775 //printf("char [%c] is not a digit.\n", chrDigit[0]);
1776 return 0; // 0: FALSE
1779 if(isdigit(chrDigit[0])==0){
1780 domainPtr = chrDigit - strlen("@hg") + 1;
1781 if(strncmp(domainPtr, "@hg", strlen("@hg"))==0)
1782 return 1; // 1: TRUE
1784 domainPtr = chrDigit - strlen("@hg");
1785 if(strncmp(domainPtr, "@hg", strlen("@hg"))==0)
1786 return 1; // 1: TRUE
1790 //printf("Invalid domain = [%s]\n", pppUser);
1791 return 0; // 0: FALSE