-
Notifications
You must be signed in to change notification settings - Fork 26
/
caa.c
90 lines (77 loc) · 2.19 KB
/
caa.c
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
/*
* Part of DNS zone file validator `validns`.
*
* Copyright 2011-2017 Anton Berezin <[email protected]>
* Modified BSD license.
* (See LICENSE file in the distribution.)
*
*/
#include <sys/types.h>
#include <stdio.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include "common.h"
#include "textparse.h"
#include "mempool.h"
#include "carp.h"
#include "rr.h"
static struct rr* caa_parse(char *name, long ttl, int type, char *s)
{
struct rr_caa *rr = getmem(sizeof(*rr));
int flags;
char *str_tag;
flags = extract_integer(&s, "CAA flags", NULL);
if (flags < 0) return NULL;
if (flags != 0 && flags != 128)
return bitch("CAA unrecognized flags value");
rr->flags = flags;
str_tag = extract_label(&s, "CAA tag", "temporary");
if (!str_tag) return NULL;
if (strcmp(str_tag, "issue") == 0) {
/* ok */
} else if (strcmp(str_tag, "issuewild") == 0) {
/* ok */
} else if (strcmp(str_tag, "iodef") == 0) {
/* ok */
} else if (strcmp(str_tag, "auth") == 0)
return bitch("CAA reserved tag name");
else if (strcmp(str_tag, "path") == 0)
return bitch("CAA reserved tag name");
else if (strcmp(str_tag, "policy") == 0)
return bitch("CAA reserved tag name");
else
return bitch("CAA unrecognized tag name");
rr->tag = compose_binary_data("s", 0, str_tag);
rr->value = extract_text(&s, "CAA tag value");
if (rr->value.length <= 0)
return bitch("CAA missing tag value");
if (*s) {
return bitch("garbage after valid CAA data");
}
return store_record(type, name, ttl, rr);
}
static char* caa_human(struct rr *rrv)
{
RRCAST(caa);
char ss[4096];
char *s = ss;
int l;
/* incomplete */
l = snprintf(s, 4096, "%u", rr->flags);
s += l;
return quickstrdup_temp(ss);
}
static struct binary_data caa_wirerdata(struct rr *rrv)
{
RRCAST(caa);
return compose_binary_data("1dd", 1, rr->flags, rr->tag, rr->value);
}
/*
static void *caa_validate(struct rr *rrv)
{
dump_binary_data(stderr, call_get_wired(rrv));
return NULL;
}
*/
struct rr_methods caa_methods = { caa_parse, caa_human, caa_wirerdata, NULL, NULL };