📄 options.c
字号:
word[len] = c; ++len; c = getc(f); } /* * End of the word: check for errors. */ if (c == EOF) { if (ferror(f)) { if (errno == 0) errno = EIO; option_error("Error reading %s: %m", filename); die(1); } /* * If len is zero, then we didn't find a word before the * end of the file. */ if (len == 0) return 0; } /* * Warn if the word was too long, and append a terminating null. */ if (len >= MAXWORDLEN) { option_error("warning: word in file %s too long (%.20s...)", filename, word); len = MAXWORDLEN - 1; } word[len] = 0; return 1;#undef isoctal}/* * number_option - parse an unsigned numeric parameter for an option. */static intnumber_option(str, valp, base) char *str; u_int32_t *valp; int base;{ char *ptr; *valp = strtoul(str, &ptr, base); if (ptr == str) { option_error("invalid numeric parameter '%s' for %s option", str, current_option); return 0; } return 1;}/* * int_option - like number_option, but valp is int *, * the base is assumed to be 0, and *valp is not changed * if there is an error. */intint_option(str, valp) char *str; int *valp;{ u_int32_t v; if (!number_option(str, &v, 0)) return 0; *valp = (int) v; return 1;}/* * The following procedures parse options. *//* * readfile - take commands from a file. */static intreadfile(argv) char **argv;{ return options_from_file(*argv, 1, 1, privileged_option);}/* * callfile - take commands from /etc/ppp/peers/<name>. * Name may not contain /../, start with / or ../, or end in /.. */static intcallfile(argv) char **argv;{ char *fname, *arg, *p; int l, ok; arg = *argv; ok = 1; if (arg[0] == '/' || arg[0] == 0) ok = 0; else { for (p = arg; *p != 0; ) { if (p[0] == '.' && p[1] == '.' && (p[2] == '/' || p[2] == 0)) { ok = 0; break; } while (*p != '/' && *p != 0) ++p; if (*p == '/') ++p; } } if (!ok) { option_error("call option value may not contain .. or start with /"); return 0; } l = strlen(arg) + strlen(_PATH_PEERFILES) + 1; if ((fname = (char *) malloc(l)) == NULL) novm("call file name"); slprintf(fname, l, "%s%s", _PATH_PEERFILES, arg); ok = options_from_file(fname, 1, 1, 1); free(fname); return ok;}#ifdef PPP_FILTER/* * setpdebug - Set libpcap debugging level. */static intsetpdebug(argv) char **argv;{ return int_option(*argv, &dflag);}/* * setpassfilter - Set the pass filter for packets */static intsetpassfilter(argv) char **argv;{ pc.linktype = DLT_PPP; pc.snapshot = PPP_HDRLEN; if (pcap_compile(&pc, &pass_filter, *argv, 1, netmask) == 0) return 1; option_error("error in pass-filter expression: %s\n", pcap_geterr(&pc)); return 0;}/* * setactivefilter - Set the active filter for packets */static intsetactivefilter(argv) char **argv;{ pc.linktype = DLT_PPP; pc.snapshot = PPP_HDRLEN; if (pcap_compile(&pc, &active_filter, *argv, 1, netmask) == 0) return 1; option_error("error in active-filter expression: %s\n", pcap_geterr(&pc)); return 0;}#endif/* * noopt - Disable all options. */static intnoopt(argv) char **argv;{ BZERO((char *) &lcp_wantoptions[0], sizeof (struct lcp_options)); BZERO((char *) &lcp_allowoptions[0], sizeof (struct lcp_options)); BZERO((char *) &ipcp_wantoptions[0], sizeof (struct ipcp_options)); BZERO((char *) &ipcp_allowoptions[0], sizeof (struct ipcp_options)); return (1);}/* * setdomain - Set domain name to append to hostname */static intsetdomain(argv) char **argv;{ if (!privileged_option) { option_error("using the domain option requires root privilege"); return 0; } gethostname(hostname, MAXNAMELEN); if (**argv != 0) { if (**argv != '.') strncat(hostname, ".", MAXNAMELEN - strlen(hostname)); strncat(hostname, *argv, MAXNAMELEN - strlen(hostname)); } hostname[MAXNAMELEN-1] = 0; return (1);}/* * setspeed - Set the speed. */static intsetspeed(arg) char *arg;{ int spd; int ret = (int )1; speed_t spdValue = (speed_t)0; char *ptr; if ( !prepass ) { spd = strtol(arg, &ptr, 0); if (ptr == arg || *ptr != 0 || spd == 0) { ret = (int)0; } else { switch ( spd ) { case 2400: spdValue = B2400; break; case 4800: spdValue = B4800; break; case 9600: spdValue = B9600; break; case 19200: spdValue = B19200; break; case 38400: spdValue = B38400; break; case 57600: spdValue = B57600; break; case 115200: spdValue = B115200; break; default: ret = (int)0; break; } if ( spdValue ) { inspeed = spdValue; } } } return ( ret );}/* * setdevname - Set the device name. */static intsetdevname(cp) char *cp;{ struct stat statbuf; char dev[MAXPATHLEN]; if (*cp == 0) return 0; if (strncmp("/dev/", cp, 5) != 0) { strlcpy(dev, "/dev/", sizeof(dev)); strlcat(dev, cp, sizeof(dev)); cp = dev; } /* * Check if there is a character device by this name. */ if (stat(cp, &statbuf) < 0) { if (errno == ENOENT) return 0; option_error("Couldn't stat %s: %m", cp); return -1; } if (!S_ISCHR(statbuf.st_mode)) { option_error("%s is not a character device", cp); return -1; } if (pppd_phase != PHASE_INITIALIZE) { option_error("device name cannot be changed after initialization"); return -1; } else if (devnam_fixed) { option_error("per-tty options file may not specify device name"); return -1; } if (devnam_info.priv && !privileged_option) { option_error("device name cannot be overridden"); return -1; } strlcpy(devnam, cp, sizeof(devnam)); devstat = statbuf; default_device = 0; devnam_info.priv = privileged_option; devnam_info.source = option_source; return 1;}/* * setipaddr - Set the IP address */static intsetipaddr(arg) char *arg;{ struct hostent *hp; char *colon; u_int32_t local, remote; ipcp_options *wo = &ipcp_wantoptions[0]; /* * IP address pair separated by ":". */ if ((colon = strchr(arg, ':')) == NULL) return 0; if (prepass) return 1; /* * If colon first character, then no local addr. */ if (colon != arg) { *colon = '\0'; if ((local = inet_addr(arg)) == (u_int32_t) -1) { if ((hp = gethostbyname(arg)) == NULL) { option_error("unknown host: %s", arg); return -1; } else { local = *(u_int32_t *)hp->h_addr; } } if (bad_ip_adrs(local)) { option_error("bad local IP address %s", ip_ntoa(local)); return -1; } if (local != 0) wo->ouraddr = local; *colon = ':'; } /* * If colon last character, then no remote addr. */ if (*++colon != '\0') { if ((remote = inet_addr(colon)) == (u_int32_t) -1) { if ((hp = gethostbyname(colon)) == NULL) { option_error("unknown host: %s", colon); return -1; } else { remote = *(u_int32_t *)hp->h_addr; if (remote_name[0] == 0) strlcpy(remote_name, colon, sizeof(remote_name)); } } if (bad_ip_adrs(remote)) { option_error("bad remote IP address %s", ip_ntoa(remote)); return -1; } if (remote != 0) wo->hisaddr = remote; } return 1;}/* * setnetmask - set the netmask to be used on the interface. */static intsetnetmask(argv) char **argv;{ u_int32_t mask, b; int n, ok; char *p, *endp; /* * Unfortunately, if we use inet_addr, we can't tell whether * a result of all 1s is an error or a valid 255.255.255.255. */ p = *argv; ok = 0; mask = 0; for (n = 3;; --n) { b = strtoul(p, &endp, 0); if (endp == p) break; if (b > 255) { if (n == 3) { /* accept e.g. 0xffffff00 */ p = endp; mask = b; } break; } mask |= b << (n * 8); p = endp; if (*p != '.' || n == 0) break; ++p; } mask = htonl(mask); if (*p != 0 || (netmask & ~mask) != 0) { option_error("invalid netmask value '%s'", *argv); return 0; } netmask = mask; return (1);}static intsetxonxoff(argv) char **argv;{ lcp_wantoptions[0].asyncmap |= 0x000A0000; /* escape ^S and ^Q */ lcp_wantoptions[0].neg_asyncmap = 1; crtscts = -2; return (1);}static intsetlogfile(argv) char **argv;{ int fd, err; fd = open(*argv, O_WRONLY | O_APPEND | O_CREAT | O_EXCL, 0644); if (fd < 0 && errno == EEXIST) fd = open(*argv, O_WRONLY | O_APPEND); err = errno; if (fd < 0) { errno = err; option_error("Can't open log file %s: %m", *argv); return 0; } if (log_to_file && log_to_fd >= 0) close(log_to_fd); log_to_fd = fd; log_to_file = 1; return 1;}#ifdef PLUGINstatic intloadplugin(argv) char **argv;{ char *arg = *argv; void *handle; const char *err; void (*init) __P((void)); handle = dlopen(arg, RTLD_GLOBAL | RTLD_NOW); if (handle == 0) { err = dlerror(); if (err != 0) option_error("%s", err); option_error("Couldn't load plugin %s", arg); return 0; } init = dlsym(handle, "plugin_init"); if (init == 0) { option_error("%s has no initialization entry point", arg); dlclose(handle); return 0; } info("Plugin %s loaded.", arg); (*init)(); return 1;}#endif /* PLUGIN */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -