📄 options.c
字号:
if (!strcmp(cmd, cmdp->cmd_name)) break; if (cmdp->cmd_name != NULL) { for (i = 0; i < cmdp->num_args; ++i) { if (!getword(f, args[i], &newline, fileName)) { syslog(LOG_ERR, "In file %s: too few parameters for command %s\n", fileName, cmd); fclose(f); return 0; } argv[i] = args[i]; } if (!(*cmdp->cmd_func)(argv[0])) { fclose(f); return 0; } } else { syslog(LOG_ERR, "In file %s: unrecognized command %s\n", fileName, cmd); fclose(f); return 0; } } fclose(f); return 1;}#ifdef notyet/* * options_from_user - See if the use has a ~/.ppprc file, * and if so, interpret options from it. */intoptions_from_user(){ char *user, *path, *file; int ret; if (user[0] == 0) return 1; file = _PATH_USEROPT; path = (char *)malloc(strlen(user) + strlen(file) + 2); if (path == NULL) novm("init file name"); strcpy(path, user); strcat(path, "/"); strcat(path, file); ret = options_from_file(path, 0, 1); free(path); return ret;}/* * options_for_tty - See if an options file exists for the serial * device, and if so, interpret options from it. */intoptions_for_tty(devname) char *devname;{ char *dev, *path; int ret; dev = strrchr(devname, '/'); if (dev == NULL) dev = devname; else ++dev; if (strcmp(dev, "tty") == 0) return 1; /* don't look for /etc/ppp/options.tty */ path = (char *)malloc(strlen(_PATH_TTYOPT) + strlen(dev) + 1); if (path == NULL) novm("tty init file name"); strcpy(path, _PATH_TTYOPT); strcat(path, dev); ret = options_from_file(path, 0, 0); free(path); return ret;}#endif /* notyet *//* * readable - check if a file is readable by the real user. */static intreadable(fd) int fd;{#ifdef notyet uid_t uid; int ngroups, i; struct stat sbuf; GIDSET_TYPE groups[NGROUPS_MAX]; uid = getuid(); if (uid == 0) return 1; if (fstat(fd, &sbuf) != 0) return 0; if (sbuf.st_uid == uid) return sbuf.st_mode & S_IRUSR; if (sbuf.st_gid == getgid()) return sbuf.st_mode & S_IRGRP; ngroups = getgroups(NGROUPS_MAX, groups); for (i = 0; i < ngroups; ++i) if (sbuf.st_gid == groups[i]) return sbuf.st_mode & S_IRGRP; return sbuf.st_mode & S_IROTH;#else /* notyet */ return 1;#endif /* notyet */}/* * Read a word from a file. * Words are delimited by white-space or by quotes ("). * Quotes, white-space and \ may be escaped with \. * \<newline> is ignored. */intgetword(f, word, newlinep, fileName) FILE *f; char *word; int *newlinep; char *fileName;{ int c, len, escape; int quoted; *newlinep = 0; len = 0; escape = 0; quoted = 0; /* * First skip white-space and comments */ while ((c = getc(f)) != EOF) { if (c == '\\') { /* * \<newline> is ignored; \ followed by anything else * starts a word. */ if ((c = getc(f)) == '\n') continue; word[len++] = '\\'; escape = 1; break; } if (c == '\n') *newlinep = 1; /* next word starts a line */ else if (c == '#') { /* comment - ignore until EOF or \n */ while ((c = getc(f)) != EOF && c != '\n') ; if (c == EOF) break; *newlinep = 1; } else if (!isspace(c)) break; } /* * End of file or error - fail */ if (c == EOF) { if (ferror(f)) { syslog(LOG_ERR, "%s: EOF\n", fileName); die(ppp_unit, 1); } *newlinep = 0; /* added to make sure scan_authfile() exits -dzb */ return 0; } for (;;) { /* * Is this character escaped by \ ? */ if (escape) { if (c == '\n') --len; /* ignore \<newline> */ else if (c == '"' || isspace(c) || c == '\\') word[len-1] = c; /* put special char in word */ else { if (len < MAXWORDLEN-1) word[len] = c; ++len; } escape = 0; } else if (c == '"') { quoted = !quoted; } else if (!quoted && (isspace(c) || c == '#')) { ungetc(c, f); break; } else { if (len < MAXWORDLEN-1) word[len] = c; ++len; if (c == '\\') escape = 1; } if ((c = getc(f)) == EOF) break; } if (ferror(f)) { syslog(LOG_ERR, "%s: error\n", fileName); die(ppp_unit, 1); } if (len >= MAXWORDLEN) { word[MAXWORDLEN-1] = 0; syslog(LOG_WARNING, "warning: word in file %s too long (%.20s...)\n", fileName, word); } else word[len] = 0; return 1;}/* * number_option - parse a numeric parameter for an option */static intnumber_option(str, valp, base) char *str; long *valp; int base;{ char *ptr; *valp = strtoul(str, &ptr, base); if (errno == ERANGE) { syslog(LOG_ERR, "invalid number: %s", str); 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. */static intint_option(str, valp) char *str; int *valp;{ long v; if (!number_option(str, &v, 0)) return 0; *valp = (int) v; return 1;}/* * The following procedures execute commands. *//* * readfile - take commands from a file. */static intreadfile(argv) char *argv;{ return options_from_file(argv, 1, 1);}/* * setdebug - Set debug (command line argument). */static intsetdebug(){ ppp_if[ppp_unit]->debug = 1; return (1);}/* * setkdebug - Set kernel debugging level. */static intsetkdebug(){ ppp_if[ppp_unit]->kdebugflag = 1; return (1);}/* * noopt - Disable all options. */static intnoopt(){ BZERO((char *) &ppp_if[ppp_unit]->lcp_wantoptions, sizeof (struct lcp_options)); BZERO((char *) &ppp_if[ppp_unit]->lcp_allowoptions, sizeof (struct lcp_options)); BZERO((char *) &ppp_if[ppp_unit]->ipcp_wantoptions, sizeof (struct ipcp_options)); BZERO((char *) &ppp_if[ppp_unit]->ipcp_allowoptions, sizeof (struct ipcp_options)); return (1);}/* * noaccomp - Disable Address/Control field compression negotiation. */static intnoaccomp(){ ppp_if[ppp_unit]->lcp_wantoptions.neg_accompression = 0; ppp_if[ppp_unit]->lcp_allowoptions.neg_accompression = 0; return (1);}/* * noasyncmap - Disable async map negotiation. */static intnoasyncmap(){ ppp_if[ppp_unit]->lcp_wantoptions.neg_asyncmap = 0; ppp_if[ppp_unit]->lcp_allowoptions.neg_asyncmap = 0; return (1);}/* * noipaddr - Disable IP address negotiation. */static intnoipaddr(){ ppp_if[ppp_unit]->ipcp_wantoptions.neg_addr = 0; ppp_if[ppp_unit]->ipcp_allowoptions.neg_addr = 0; return (1);}/* * nomagicnumber - Disable magic number negotiation. */static intnomagicnumber(){ ppp_if[ppp_unit]->lcp_wantoptions.neg_magicnumber = 0; ppp_if[ppp_unit]->lcp_allowoptions.neg_magicnumber = 0; return (1);}/* * nomru - Disable mru negotiation. */static intnomru(){ ppp_if[ppp_unit]->lcp_wantoptions.neg_mru = 0; ppp_if[ppp_unit]->lcp_allowoptions.neg_mru = 0; return (1);}/* * setmru - Set MRU for negotiation. */static intsetmru(argv) char *argv;{ long mru; if (!number_option(argv, &mru, 0)) return 0; ppp_if[ppp_unit]->lcp_wantoptions.mru = mru; ppp_if[ppp_unit]->lcp_wantoptions.neg_mru = 1; return (1);}/* * setmtu - Set the largest MTU we'll use. */static intsetmtu(argv) char *argv;{ long mtu; if (!number_option(argv, &mtu, 0)) return 0; if (mtu < MINMRU || mtu > MAXMRU) { syslog(LOG_ERR, "mtu option value of %d is too %s\n", mtu, (mtu < MINMRU? "small": "large")); return 0; } ppp_if[ppp_unit]->lcp_allowoptions.mru = mtu; return (1);}/* * nopcomp - Disable Protocol field compression negotiation. */static intnopcomp(){ ppp_if[ppp_unit]->lcp_wantoptions.neg_pcompression = 0; ppp_if[ppp_unit]->lcp_allowoptions.neg_pcompression = 0; return (1);}/* * setpassive - Set passive mode (don't give up if we time out sending * LCP configure-requests). */static intsetpassive(){ ppp_if[ppp_unit]->lcp_wantoptions.passive = 1; return (1);}/* * setsilent - Set silent mode (don't start sending LCP configure-requests * until we get one from the peer). */static intsetsilent(){ ppp_if[ppp_unit]->lcp_wantoptions.silent = 1; return (1);}/* * nopap - Disable PAP authentication with peer. */static intnopap(){ ppp_if[ppp_unit]->lcp_allowoptions.neg_upap = 0; return (1);}/* * reqpap - Require PAP authentication from peer. */static intreqpap(){ ppp_if[ppp_unit]->lcp_wantoptions.neg_upap = 1; ppp_if[ppp_unit]->auth_required = 1; return (1);}/* * setupapfile - specifies UPAP info for authenticating with peer. */static intsetupapfile(argv) char *argv;{ FILE * ufile; ppp_if[ppp_unit]->lcp_allowoptions.neg_upap = 1; ppp_if[ppp_unit]->options->pap_file = (char *)stringdup(argv); /* open user info file */ if ((ufile = fopen(argv, "r")) == NULL) { syslog(LOG_ERR, "unable to open PAP secrets file %s", argv); return 0; } if (!readable(fileno(ufile))) { syslog(LOG_ERR, "%s: access denied", argv); fclose(ufile); return 0; } check_access(ufile, argv); fclose(ufile); return (1);}/* * nochap - Disable CHAP authentication with peer. */static intnochap(){ ppp_if[ppp_unit]->lcp_allowoptions.neg_chap = 0; return (1);}/* * reqchap - Require CHAP authentication from peer. */static intreqchap(){ ppp_if[ppp_unit]->lcp_wantoptions.neg_chap = 1; ppp_if[ppp_unit]->auth_required = 1; return (1);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -