📄 db_load.c
字号:
#ifdef CRED dp->d_cred = DB_C_AUTH; dp->d_clev = clev;#endif /*CRED*/ if ((c = db_update(domain, dp, dp, dbflags, (zp->z_type == Z_CACHE)? fcachetab : hashtab)) < 0) {#ifdef DEBUG if (debug && (c != DATAEXISTS)) fprintf(ddt, "update failed %s %d\n", domain, type);#endif free((char*) dp); /* vix@dec mar92 */ } continue; case ERROR: break; } err: errs++; syslog(LOG_ERR, "%s: line %d: database format error (%s)", filename, empty_token ? (lineno - 1) : lineno, buf); dprintf(1, (ddt, "%s: line %d: database format error ('%s', %d)\n", filename, empty_token ? (lineno - 1) : lineno, buf, n)); while ((c = getc(fp)) != EOF && c != '\n') ; if (c == '\n') lineno++; } (void) my_fclose(fp); lineno = slineno; if (doinginclude == 0) { if (didinclude) { zp->z_state |= Z_INCLUDE; zp->z_ftime = 0; } else zp->z_ftime = sb.st_mtime; zp->z_lastupdate = sb.st_mtime; if (zp->z_type != Z_CACHE && read_soa != 1) { errs++; if (read_soa == 0) syslog(LOG_ERR, "%s: no SOA record", filename); else syslog(LOG_ERR, "%s: multiple SOA records", filename); } }#ifdef SECURE_ZONES build_secure_netlist(zp);#endif if (errs) zp->z_state |= Z_DB_BAD; return (errs);}static intgettoken(fp, src) register FILE *fp; char *src;{ register int c; char op[32]; for (;;) { c = getc(fp); top: switch (c) { case EOF: return (EOF); case '$': if (getword(op, sizeof(op), fp)) { if (!strcasecmp("include", op)) return (INCLUDE); if (!strcasecmp("origin", op)) return (ORIGIN); } dprintf(1, (ddt, "%s: line %d: Unknown $ option: $%s\n", src, lineno, op)); syslog(LOG_ERR,"%s: line %d: Unknown $ option: $%s\n", src, lineno, op); return (ERROR); case ';': while ((c = getc(fp)) != EOF && c != '\n') ; goto top; case ' ': case '\t': return (CURRENT); case '.': return (DOT); case '@': return (AT); case '\n': lineno++; continue; default: (void) ungetc(c, fp); return (DNAME); } }}/* int * getword(buf, size, fp) * get next word, skipping blanks & comments. * parameters: * buf - destination * size - of destination * fp - file to read from * return value: * 0 = word was read * 1 = no word; perhaps EOL or EOF */intgetword(buf, size, fp) char *buf; int size; FILE *fp;{ register char *cp; register int c; empty_token = 0; for (cp = buf; (c = getc(fp)) != EOF; ) { if (c == ';') { while ((c = getc(fp)) != EOF && c != '\n') ; c = '\n'; } if (c == '\n') { if (cp != buf) ungetc(c, fp); else lineno++; break; } if (isspace(c)) { while (isspace(c = getc(fp)) && c != '\n') ; ungetc(c, fp); if (cp != buf) /* Trailing whitespace */ break; continue; /* Leading whitespace */ } if (c == '"') { while ((c = getc(fp)) != EOF && c != '"' && c != '\n') { if (c == '\\') { if ((c = getc(fp)) == EOF) c = '\\'; if (c == '\n') lineno++; } if (cp >= buf+size-1) break; *cp++ = c; } if (c == '\n') { lineno++; break; } continue; } if (c == '\\') { if ((c = getc(fp)) == EOF) c = '\\'; if (c == '\n') lineno++; } if (cp >= buf+size-1) break; *cp++ = (char)c; } *cp = '\0'; if (cp == buf) empty_token = 1; return (cp != buf);}/*From: kagotani@cs.titech.ac.jpMessage-Id: <9007040716.AA26646@saeko.cs.titech.ac.jp>Subject: named bug report and fixDate: Wed, 04 Jul 90 16:16:52 JSTI found a bug in the BIND source code. Named with this bug parsesthe serial_no field of SOA records incorrectly. For example: expression internal in files expression I expect 1. 1000 10000 1.2 10002 10002 1.23 100023 10023 2.3 20003 20003Especially I can not accept that "2.3" is treated as if it issmaller than "1.23" in their internal expressions.[ if you define SENSIBLE_DOTS in ../conf/options.h, you get m. kagotani's expected behaviour. this is NOT compatible with pre-4.9 versions of BIND. --vix ]*/static intgetnum(fp, src, is_serial) FILE *fp; char *src; int is_serial;{ register int c, n; int seendigit = 0; int seendecimal = 0; int m = 0; int allow_dots = 0;#ifdef DOTTED_SERIAL allow_dots += is_serial;#endif for (n = 0; (c = getc(fp)) != EOF; ) { if (isspace(c)) { if (c == '\n') lineno++; if (seendigit) break; continue; } if (c == ';') { while ((c = getc(fp)) != EOF && c != '\n') ; if (c == '\n') lineno++; if (seendigit) break; continue; } if (!isdigit(c)) { if (c == ')' && seendigit) { (void) ungetc(c, fp); break; } if (seendecimal || c != '.' || !allow_dots) { syslog(LOG_ERR, "%s:%d: expected a number", src, lineno); dprintf(1, (ddt, "%s:%d: expected a number", src, lineno)); exit(1); /* XXX why exit here?? */ } else { if (!seendigit) n = 1;#ifdef SENSIBLE_DOTS n = n * 10000;#else n = n * 1000;#endif seendigit = 1; seendecimal = 1; } continue; }#ifdef SENSIBLE_DOTS if (seendecimal) m = m * 10 + (c - '0'); else n = n * 10 + (c - '0');#else n = n * 10 + (c - '0');#endif seendigit = 1; } if (m > 9999) { syslog(LOG_ERR, "%s:%d: number after the decimal point exceeds 9999", src, lineno); dprintf(1, (ddt, "%s:%d: number after the decimal point exceeds 9999", src, lineno)); exit(1); /* XXX why exit here?? */ } if (seendecimal) { syslog(LOG_INFO, "%s:%d: decimal serial number interpreted as %d", src, lineno, n+m); } return (n + m);}static intgetnonblank(fp, src) FILE *fp; char *src;{ register int c; while ( (c = getc(fp)) != EOF ) { if (isspace(c)) { if (c == '\n') lineno++; continue; } if (c == ';') { while ((c = getc(fp)) != EOF && c != '\n') ; if (c == '\n') lineno++; continue; } return(c); } syslog(LOG_ERR, "%s: line %d: unexpected EOF", src, lineno); dprintf(1, (ddt, "%s: line %d: unexpected EOF", src, lineno)); return (EOF);}/* * Take name and fix it according to following rules: * "." means root. * "@" means current origin. * "name." means no changes. * "name" means append origin. */static voidmakename(name, origin) char *name, *origin;{ int n; if (origin[0] == '.') origin++; n = strlen(name); if (n == 1) { if (name[0] == '.') { name[0] = '\0'; return; } if (name[0] == '@') { (void) strcpy(name, origin); return; } } if (n > 0) { if (name[n - 1] == '.') name[n - 1] = '\0'; else if (origin[0] != '\0') { name[n] = '.'; (void) strcpy(name + n + 1, origin); } }}voidendline(fp) register FILE *fp;{ register int c; while (c = getc(fp)) { if (c == '\n') { (void) ungetc(c,fp); break; } else if (c == EOF) { break; } }}#define MAXPORT 256#define MAXLEN 24static intgetprotocol(fp, src) FILE *fp; char *src;{ int k; char b[MAXLEN]; (void) getword(b, sizeof(b), fp); k = protocolnumber(b); if(k == -1) syslog(LOG_ERR, "%s: line %d: unknown protocol: %s.", src, lineno, b); return(k);}static intgetservices(n, data, fp, src) int n; char *data, *src; FILE *fp;{ int j, ch; int k; int maxl; int bracket; char b[MAXLEN]; char bm[MAXPORT/8]; for (j = 0; j < MAXPORT/8; j++) bm[j] = 0; maxl = 0; bracket = 0; while (getword(b, sizeof(b), fp) || bracket) { if (feof(fp) || ferror(fp)) break; if (strlen(b) == 0) continue; if ( b[0] == '(') { bracket++; continue; } if ( b[0] == ')') { bracket = 0; while ((ch = getc(fp)) != EOF && ch != '\n') ; if (ch == '\n') lineno++; break; } k = servicenumber(b); if (k == -1) { syslog(LOG_WARNING, "%s: line %d: Unknown service '%s'", src, lineno, b); continue; } if ((k < MAXPORT) && (k)) { bm[k/8] |= (0x80>>(k%8)); if (k > maxl) maxl=k; } else { syslog(LOG_WARNING, "%s: line %d: port no. (%d) too big\n", src, lineno, k); dprintf(1, (ddt, "%s: line %d: port no. (%d) too big\n", src, lineno, k)); } } if (bracket) syslog(LOG_WARNING, "%s: line %d: missing close paren\n", src, lineno); maxl = maxl/8+1; bcopy(bm, data+n, maxl); return(maxl+n);}/* get_netlist(fp, netlistp, allow) * get list of nets from 'fp', put on *netlistp, 'allow' controls * whether hosts, nets, or both shall be accepted without warnings. * (note that they are always accepted; 'allow' just controls the * warnings.) */voidget_netlist(fp, netlistp, allow, print_tag) FILE *fp; struct netinfo **netlistp; int allow; char *print_tag;{ struct netinfo *ntp = NULL, **end = netlistp; char buf[BUFSIZ]; dprintf(1, (ddt, "get_netlist(%s)", print_tag)); while (getword(buf, sizeof(buf), fp)) { if (strlen(buf) == 0) break; dprintf(1, (ddt," %s", buf)); if (ntp == NULL) { ntp = (struct netinfo *)malloc(sizeof(struct netinfo)); } if (!inet_aton(buf, &ntp->my_addr)) { syslog(LOG_ERR, "netlist contains bogus element (%s)", buf); continue; } ntp->next = NULL; ntp->mask = net_mask(ntp->my_addr); /* subnet faking XXX */ ntp->net = ntp->my_addr.s_addr & ntp->mask; /* Check for duplicates */ if (net_on_netlist(ntp->my_addr, *netlistp)) continue; if (!(allow & ALLOW_HOSTS)) { if (ntp->net != ntp->my_addr.s_addr) { struct in_addr tmpaddr; tmpaddr.s_addr = ntp->net; syslog(LOG_WARNING, "get_netlist(%s): addr(%s) != net(%s)", print_tag, buf, inet_ntoa(tmpaddr)); dprintf(1, (ddt, "\nget_netlist(%s): addr(%s) != net(%s)\n", print_tag, buf, inet_ntoa(tmpaddr))); } } *end = ntp; end = &ntp->next; ntp = NULL; } if (ntp) free((char *)ntp); dprintf(1, (ddt, "\n"));#ifdef DEBUG if (debug > 2) for (ntp = *netlistp; ntp != NULL; ntp = ntp->next) { fprintf(ddt, "ntp x%x net x%x mask x%x", ntp, ntp->net, ntp->mask); fprintf(ddt, " my_addr x%x", ntp->my_addr); fprintf(ddt, " %s", inet_ntoa(ntp->my_addr)); fprintf(ddt, " next x%x\n", ntp->next); }#endif}struct netinfo *net_on_netlist(addr, netlist) struct in_addr addr; struct netinfo *netlist;{ u_int32_t a = addr.s_addr; struct netinfo *t; for (t = netlist; t != NULL; t = t->next) if (t->net == (a & t->mask)) return t; return NULL;}intposition_on_netlist(addr, netlist) struct in_addr addr; struct netinfo *netlist;{ u_int32_t a = addr.s_addr; struct netinfo *t; int position = 0; for (t = netlist; t != NULL; t = t->next) if (t->net == (a & t->mask)) break; else position++; return position;}voidfree_netlist(netlistp) struct netinfo **netlistp;{ register struct netinfo *ntp, *next; for (ntp = *netlistp; ntp != NULL; ntp = next) { next = ntp->next; free((char *)ntp); } *netlistp = NULL;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -