1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
/*
* Part of DNS zone file validator `validns`.
*
* Copyright 2011-2014 Anton Berezin <tobez@tobez.org>
* Modified BSD license.
* (See LICENSE file in the distribution.)
*
*/
#include <ctype.h>
#include <sys/types.h>
#include <stdio.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "common.h"
#include "textparse.h"
#include "mempool.h"
#include "carp.h"
#include "rr.h"
static struct rr *naptr_parse(char *name, long ttl, int type, char *s)
{
struct rr_naptr *rr = getmem(sizeof(*rr));
int i;
struct binary_data text;
i = extract_integer(&s, "order", NULL);
if (i < 0)
return NULL;
if (i >= 65536)
return bitch("order range is not valid");
rr->order = i;
i = extract_integer(&s, "preference", NULL);
if (i < 0)
return NULL;
if (i >= 65536)
return bitch("preference range is not valid");
rr->preference = i;
text = extract_text(&s, "flags");
if (text.length < 0)
return NULL;
for (i = 0; i < text.length; i++) {
if (!isalnum(text.data[i])) {
return bitch("flags contains illegal characters");
}
}
rr->flags = text;
text = extract_text(&s, "services");
if (text.length < 0)
return NULL;
rr->services = text;
text = extract_text(&s, "regexp");
if (text.length < 0)
return NULL;
rr->regexp = text;
rr->replacement = extract_name(&s, "replacement", 0);
if (!rr->replacement)
return NULL;
if (*s) {
return bitch("garbage after valid NAPTR data");
}
return store_record(type, name, ttl, rr);
}
static char* naptr_human(struct rr *rrv)
{
RRCAST(naptr);
char s[1024];
snprintf(s, 1024, "%hu %hu \"%s\" ...",
rr->order, rr->preference, rr->flags.data);
return quickstrdup_temp(s);
}
static struct binary_data naptr_wirerdata(struct rr *rrv)
{
RRCAST(naptr);
return compose_binary_data("22bbbd", 1,
rr->order, rr->preference,
rr->flags, rr->services, rr->regexp,
name2wire_name(rr->replacement));
}
struct rr_methods naptr_methods = { naptr_parse, naptr_human, naptr_wirerdata, NULL, NULL };
|