17#define WHO "rbldns-data"
19int rename(
const char *,
const char *);
23 logmsg(
WHO,111,FATAL,
"out of memory");
28 logmsg(
WHO,111,FATAL,
"parsing error");
47 logmsg(
WHO,-99,WARN,B(
"unable to parse data line: ",
strnum,why));
51 logmsg(
WHO,111,FATAL,
"unable to create data.tmp");
66 stralloc ipstring = {0};
70 fd = open_read(
"data");
71 if (
fd == -1) logmsg(
WHO,111,FATAL,
"unable to open data");
74 fdcdb = open_trunc(
"data.tmp");
81 logmsg(
WHO,111,FATAL,
"unable to read line");
85 if ((ch !=
' ') && (ch !=
'\t') && (ch !=
'\n'))
break;
88 if (!
line.len)
continue;
96 j = byte_chr(
line.s + 1,
line.len - 1,
':');
98 if (ip4_scan(
line.s + 1,ipout) != j)
syntaxerror(
": malformed IPv4 address");
99 if (!stralloc_copyb(&
tmp,ipout,4))
nomem();
101 if (cdb_make_add(&
cdb,
"",0,
tmp.s,
tmp.len) == -1)
104 case '0':
case '1':
case '2':
case '3':
case '4':
105 case '5':
case '6':
case '7':
case '8':
case '9':
case ':':
106 case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
112 i = byte_chr(
line.s + 1,
line.len - 1,
':');
113 if (i <
line.len - 1) flagip6 = 1;
114 if (byte_equal(
line.s,7,V4MAPPREFIX)) { k = 7; flagip6 = 0; }
119 if (!stralloc_copys(&
tmp,
"^"))
nomem();
120 if (ip6_bytestring(&ipstring,
ip6,plen))
nomem();
121 if (!stralloc_catb(&
tmp,ipstring.s,plen))
nomem();
126 if (!stralloc_copys(&
tmp,
""))
nomem();
127 if (ip4_bytestring(&ipstring,
ip4,plen))
nomem();
128 if (!stralloc_catb(&
tmp,ipstring.s,plen))
nomem();
131 if (cdb_make_add(&
cdb,
tmp.s,plen,
"",0) == -1)
140 if (
rename(
"data.tmp",
"data.cdb") == -1)
141 logmsg(
WHO,111,FATAL,
"unable to move data.tmp to data.cdb");
int rename(const char *, const char *)
void syntaxerror(const char *why)