17#define WHO "tinydns-edit"
20#define TTL_POSITIVE 86400
25int rename(
const char *,
const char *);
29 logmsg(
WHO,100,USAGE,
"tinydns-edit data data.new add [ns|childns|host|alias|mx] domain a.b.c.d\n"
30 "tinydns-edit data data.new add [ns|childns|host6|alias6|mx] domain a:b:c:d:e:f:g:h");
34 logmsg(
WHO,111,FATAL,
"out of memory");
38 logmsg(
WHO,100,FATAL,B(
"fatal: unable to read: ",
fn));
42 logmsg(
WHO,111,FATAL,B(
"fatal: unable to write: ",
fnnew));
72static char *names[26];
80int main(
int argc,
char **argv)
102 if (str_equal(*argv,
"ns"))
mode =
'.';
103 else if (str_equal(*argv,
"childns"))
mode =
'&';
104 else if (str_equal(*argv,
"host"))
mode =
'=';
105 else if (str_equal(*argv,
"host6"))
mode =
':';
106 else if (str_equal(*argv,
"alias"))
mode =
'+';
107 else if (str_equal(*argv,
"alias6"))
mode =
'~';
108 else if (str_equal(*argv,
"mx"))
mode =
'@';
115 if (ip6_scan(*argv,
targetip6)) ipflag = 2;
116 if (ip4_scan(*argv,
targetip4)) ipflag = 1;
134 for (i = 0; i < 26; ++i) {
136 if (!stralloc_copyb(&f[0],&ch,1))
nomem();
137 if (!stralloc_cats(&f[0],
".ns."))
nomem();
142 case '+':
case '=':
case ':':
case '~':
147 for (i = 0; i < 26; ++i) {
149 if (!stralloc_copyb(&f[0],&ch,1))
nomem();
150 if (!stralloc_cats(&f[0],
".mx."))
nomem();
165 if ((ch !=
' ') && (ch !=
'\t') && (ch !=
'\n'))
break;
168 if (!
line.len)
continue;
169 if (
line.s[0] ==
'#')
continue;
174 if (!stralloc_copys(&f[i],
""))
nomem();
177 k = byte_chr(
line.s + j,
line.len - j,
'|');
178 if (!stralloc_copyb(&f[i],
line.s + j,k))
nomem();
188 if (byte_chr(f[2].s,f[2].
len,
'.') >= f[2].
len) {
189 if (!stralloc_cats(&f[2],
".ns."))
nomem();
190 if (!stralloc_catb(&f[2],f[0].s,f[0].
len))
nomem();
193 if (!stralloc_0(&f[3]))
nomem();
194 if (!scan_ulong(f[3].s,&ttl)) ttl =
TTL_NS;
195 for (i = 0; i < 26; ++i)
205 if (
line.s[0] ==
'=') {
208 logmsg(
WHO,100,FATAL,
"host name already used");
209 if (!stralloc_0(&f[1]))
nomem();
210 if (ip4_scan(f[1].s,
ip4))
212 logmsg(
WHO,100,FATAL,
"IP address already used");
217 if (
line.s[0] ==
':') {
220 logmsg(
WHO,100,FATAL,
"host name already used");
221 if (!stralloc_0(&f[1]))
nomem();
222 if (ip6_scan(f[1].s,
ip6))
224 logmsg(
WHO,100,FATAL,
"IPv6 address already used");
229 if (
line.s[0] ==
'@') {
232 if (byte_chr(f[2].s,f[2].
len,
'.') >= f[2].
len) {
233 if (!stralloc_cats(&f[2],
".mx."))
nomem();
234 if (!stralloc_catb(&f[2],f[0].s,f[0].
len))
nomem();
237 if (!stralloc_0(&f[4]))
nomem();
239 for (i = 0; i < 26; ++i)
250 if (!stralloc_copyb(&f[0],&
mode,1))
nomem();
252 if (!stralloc_cats(&f[0],
"|"))
nomem();
259 case '.':
case '&':
case '@':
260 for (i = 0; i < 26; ++i)
264 logmsg(
WHO,100,FATAL,
"too many records for that domain");
266 if (!stralloc_cats(&f[0],
"|"))
nomem();
267 if (!stralloc_catb(&f[0],&ch,1))
nomem();
269 if (!stralloc_cats(&f[0],
"|"))
nomem();
272 if (!stralloc_cats(&f[0],
"|"))
nomem();
274 if (!stralloc_cats(&f[0],
"\n"))
nomem();
281 logmsg(
WHO,111,FATAL,B(
"unable to move ",
fnnew,
" to: ",
fn));
int dns_domain_fromdot(char **out, const char *buf, unsigned int n)
int dns_domain_equal(const char *dn1, const char *dn2)
int dns_domain_todot_cat(stralloc *out, const char *d)
int rename(const char *, const char *)
void put(const char *buf, unsigned int len)