line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
/* |
2
|
|
|
|
|
|
|
* str2host.c |
3
|
|
|
|
|
|
|
* |
4
|
|
|
|
|
|
|
* conversion routines from the presentation format |
5
|
|
|
|
|
|
|
* to the host format |
6
|
|
|
|
|
|
|
* |
7
|
|
|
|
|
|
|
* a Net::DNS like library for C |
8
|
|
|
|
|
|
|
* |
9
|
|
|
|
|
|
|
* (c) NLnet Labs, 2004-2006 |
10
|
|
|
|
|
|
|
* |
11
|
|
|
|
|
|
|
* See the file LICENSE for the license |
12
|
|
|
|
|
|
|
*/ |
13
|
|
|
|
|
|
|
#include |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#include |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
#ifdef HAVE_SYS_SOCKET_H |
18
|
|
|
|
|
|
|
#include |
19
|
|
|
|
|
|
|
#endif |
20
|
|
|
|
|
|
|
#ifdef HAVE_ARPA_INET_H |
21
|
|
|
|
|
|
|
#include |
22
|
|
|
|
|
|
|
#endif |
23
|
|
|
|
|
|
|
#include |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#include |
26
|
|
|
|
|
|
|
#ifdef HAVE_NETDB_H |
27
|
|
|
|
|
|
|
#include |
28
|
|
|
|
|
|
|
#endif |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
#include |
31
|
|
|
|
|
|
|
#ifdef HAVE_SYS_PARAM_H |
32
|
|
|
|
|
|
|
#include |
33
|
|
|
|
|
|
|
#endif |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
ldns_status |
36
|
11
|
|
|
|
|
|
ldns_str2rdf_int16(ldns_rdf **rd, const char *shortstr) |
37
|
|
|
|
|
|
|
{ |
38
|
11
|
|
|
|
|
|
char *end = NULL; |
39
|
|
|
|
|
|
|
uint16_t *r; |
40
|
11
|
|
|
|
|
|
r = LDNS_MALLOC(uint16_t); |
41
|
11
|
50
|
|
|
|
|
if(!r) return LDNS_STATUS_MEM_ERR; |
42
|
|
|
|
|
|
|
|
43
|
11
|
|
|
|
|
|
*r = htons((uint16_t)strtol((char *)shortstr, &end, 10)); |
44
|
|
|
|
|
|
|
|
45
|
11
|
50
|
|
|
|
|
if(*end != 0) { |
46
|
0
|
|
|
|
|
|
LDNS_FREE(r); |
47
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_INT; |
48
|
|
|
|
|
|
|
} else { |
49
|
11
|
|
|
|
|
|
*rd = ldns_rdf_new_frm_data( |
50
|
|
|
|
|
|
|
LDNS_RDF_TYPE_INT16, sizeof(uint16_t), r); |
51
|
11
|
|
|
|
|
|
LDNS_FREE(r); |
52
|
11
|
50
|
|
|
|
|
return *rd?LDNS_STATUS_OK:LDNS_STATUS_MEM_ERR; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
ldns_status |
57
|
2
|
|
|
|
|
|
ldns_str2rdf_time(ldns_rdf **rd, const char *time) |
58
|
|
|
|
|
|
|
{ |
59
|
|
|
|
|
|
|
/* convert a time YYYYDDMMHHMMSS to wireformat */ |
60
|
2
|
|
|
|
|
|
uint16_t *r = NULL; |
61
|
|
|
|
|
|
|
struct tm tm; |
62
|
|
|
|
|
|
|
uint32_t l; |
63
|
|
|
|
|
|
|
char *end; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
/* Try to scan the time... */ |
66
|
2
|
|
|
|
|
|
r = (uint16_t*)LDNS_MALLOC(uint32_t); |
67
|
2
|
50
|
|
|
|
|
if(!r) return LDNS_STATUS_MEM_ERR; |
68
|
|
|
|
|
|
|
|
69
|
2
|
|
|
|
|
|
memset(&tm, 0, sizeof(tm)); |
70
|
|
|
|
|
|
|
|
71
|
2
|
50
|
|
|
|
|
if (strlen(time) == 14 && |
|
|
50
|
|
|
|
|
|
72
|
2
|
|
|
|
|
|
sscanf(time, "%4d%2d%2d%2d%2d%2d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec) == 6 |
73
|
|
|
|
|
|
|
) { |
74
|
2
|
|
|
|
|
|
tm.tm_year -= 1900; |
75
|
2
|
|
|
|
|
|
tm.tm_mon--; |
76
|
|
|
|
|
|
|
/* Check values */ |
77
|
2
|
50
|
|
|
|
|
if (tm.tm_year < 70) { |
78
|
0
|
|
|
|
|
|
goto bad_format; |
79
|
|
|
|
|
|
|
} |
80
|
2
|
50
|
|
|
|
|
if (tm.tm_mon < 0 || tm.tm_mon > 11) { |
|
|
50
|
|
|
|
|
|
81
|
|
|
|
|
|
|
goto bad_format; |
82
|
|
|
|
|
|
|
} |
83
|
2
|
50
|
|
|
|
|
if (tm.tm_mday < 1 || tm.tm_mday > 31) { |
|
|
50
|
|
|
|
|
|
84
|
|
|
|
|
|
|
goto bad_format; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
2
|
50
|
|
|
|
|
if (tm.tm_hour < 0 || tm.tm_hour > 23) { |
|
|
50
|
|
|
|
|
|
88
|
|
|
|
|
|
|
goto bad_format; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
2
|
50
|
|
|
|
|
if (tm.tm_min < 0 || tm.tm_min > 59) { |
|
|
50
|
|
|
|
|
|
92
|
|
|
|
|
|
|
goto bad_format; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
2
|
50
|
|
|
|
|
if (tm.tm_sec < 0 || tm.tm_sec > 59) { |
|
|
50
|
|
|
|
|
|
96
|
|
|
|
|
|
|
goto bad_format; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
2
|
|
|
|
|
|
l = htonl(ldns_mktime_from_utc(&tm)); |
100
|
2
|
|
|
|
|
|
memcpy(r, &l, sizeof(uint32_t)); |
101
|
2
|
|
|
|
|
|
*rd = ldns_rdf_new_frm_data( |
102
|
|
|
|
|
|
|
LDNS_RDF_TYPE_TIME, sizeof(uint32_t), r); |
103
|
2
|
|
|
|
|
|
LDNS_FREE(r); |
104
|
2
|
50
|
|
|
|
|
return *rd?LDNS_STATUS_OK:LDNS_STATUS_MEM_ERR; |
105
|
|
|
|
|
|
|
} else { |
106
|
|
|
|
|
|
|
/* handle it as 32 bits timestamp */ |
107
|
0
|
|
|
|
|
|
l = htonl((uint32_t)strtol((char*)time, &end, 10)); |
108
|
0
|
0
|
|
|
|
|
if(*end != 0) { |
109
|
0
|
|
|
|
|
|
LDNS_FREE(r); |
110
|
0
|
|
|
|
|
|
return LDNS_STATUS_ERR; |
111
|
|
|
|
|
|
|
} else { |
112
|
0
|
|
|
|
|
|
memcpy(r, &l, sizeof(uint32_t)); |
113
|
0
|
|
|
|
|
|
*rd = ldns_rdf_new_frm_data( |
114
|
|
|
|
|
|
|
LDNS_RDF_TYPE_INT32, sizeof(uint32_t), r); |
115
|
0
|
|
|
|
|
|
LDNS_FREE(r); |
116
|
0
|
0
|
|
|
|
|
return *rd?LDNS_STATUS_OK:LDNS_STATUS_MEM_ERR; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
bad_format: |
121
|
0
|
|
|
|
|
|
LDNS_FREE(r); |
122
|
2
|
|
|
|
|
|
return LDNS_STATUS_INVALID_TIME; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
ldns_status |
126
|
3
|
|
|
|
|
|
ldns_str2rdf_nsec3_salt(ldns_rdf **rd, const char *salt_str) |
127
|
|
|
|
|
|
|
{ |
128
|
|
|
|
|
|
|
uint8_t salt_length; |
129
|
|
|
|
|
|
|
int c; |
130
|
|
|
|
|
|
|
int salt_length_str; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
uint8_t *salt; |
133
|
|
|
|
|
|
|
uint8_t *data; |
134
|
3
|
50
|
|
|
|
|
if(rd == NULL) { |
135
|
0
|
|
|
|
|
|
return LDNS_STATUS_NULL; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
3
|
|
|
|
|
|
salt_length_str = (int)strlen(salt_str); |
139
|
3
|
100
|
|
|
|
|
if (salt_length_str == 1 && salt_str[0] == '-') { |
|
|
50
|
|
|
|
|
|
140
|
2
|
|
|
|
|
|
salt_length_str = 0; |
141
|
1
|
50
|
|
|
|
|
} else if (salt_length_str % 2 != 0) { |
142
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_HEX; |
143
|
|
|
|
|
|
|
} |
144
|
3
|
50
|
|
|
|
|
if (salt_length_str > 512) { |
145
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_HEX; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
3
|
|
|
|
|
|
salt = LDNS_XMALLOC(uint8_t, salt_length_str / 2); |
149
|
3
|
50
|
|
|
|
|
if(!salt) { |
150
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
151
|
|
|
|
|
|
|
} |
152
|
11
|
100
|
|
|
|
|
for (c = 0; c < salt_length_str; c += 2) { |
153
|
8
|
50
|
|
|
|
|
if (isxdigit((int) salt_str[c]) && isxdigit((int) salt_str[c+1])) { |
|
|
50
|
|
|
|
|
|
154
|
8
|
|
|
|
|
|
salt[c/2] = (uint8_t) ldns_hexdigit_to_int(salt_str[c]) * 16 + |
155
|
8
|
|
|
|
|
|
ldns_hexdigit_to_int(salt_str[c+1]); |
156
|
|
|
|
|
|
|
} else { |
157
|
0
|
|
|
|
|
|
LDNS_FREE(salt); |
158
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_HEX; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
} |
161
|
3
|
|
|
|
|
|
salt_length = (uint8_t) (salt_length_str / 2); |
162
|
|
|
|
|
|
|
|
163
|
3
|
|
|
|
|
|
data = LDNS_XMALLOC(uint8_t, 1 + salt_length); |
164
|
3
|
50
|
|
|
|
|
if(!data) { |
165
|
0
|
|
|
|
|
|
LDNS_FREE(salt); |
166
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
167
|
|
|
|
|
|
|
} |
168
|
3
|
|
|
|
|
|
data[0] = salt_length; |
169
|
3
|
|
|
|
|
|
memcpy(&data[1], salt, salt_length); |
170
|
3
|
|
|
|
|
|
*rd = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_NSEC3_SALT, 1 + salt_length, data); |
171
|
3
|
|
|
|
|
|
LDNS_FREE(data); |
172
|
3
|
|
|
|
|
|
LDNS_FREE(salt); |
173
|
|
|
|
|
|
|
|
174
|
3
|
50
|
|
|
|
|
return *rd?LDNS_STATUS_OK:LDNS_STATUS_MEM_ERR; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
ldns_status |
178
|
12
|
|
|
|
|
|
ldns_str2rdf_period(ldns_rdf **rd,const char *period) |
179
|
|
|
|
|
|
|
{ |
180
|
|
|
|
|
|
|
uint32_t p; |
181
|
|
|
|
|
|
|
const char *end; |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
/* Allocate required space... */ |
184
|
12
|
|
|
|
|
|
p = ldns_str2period(period, &end); |
185
|
|
|
|
|
|
|
|
186
|
12
|
50
|
|
|
|
|
if (*end != 0) { |
187
|
0
|
|
|
|
|
|
return LDNS_STATUS_ERR; |
188
|
|
|
|
|
|
|
} else { |
189
|
12
|
|
|
|
|
|
p = (uint32_t) htonl(p); |
190
|
12
|
|
|
|
|
|
*rd = ldns_rdf_new_frm_data( |
191
|
|
|
|
|
|
|
LDNS_RDF_TYPE_PERIOD, sizeof(uint32_t), &p); |
192
|
|
|
|
|
|
|
} |
193
|
12
|
50
|
|
|
|
|
return *rd?LDNS_STATUS_OK:LDNS_STATUS_MEM_ERR; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
ldns_status |
197
|
4
|
|
|
|
|
|
ldns_str2rdf_int32(ldns_rdf **rd, const char *longstr) |
198
|
|
|
|
|
|
|
{ |
199
|
|
|
|
|
|
|
char *end; |
200
|
4
|
|
|
|
|
|
uint16_t *r = NULL; |
201
|
|
|
|
|
|
|
uint32_t l; |
202
|
|
|
|
|
|
|
|
203
|
4
|
|
|
|
|
|
r = (uint16_t*)LDNS_MALLOC(uint32_t); |
204
|
4
|
50
|
|
|
|
|
if(!r) return LDNS_STATUS_MEM_ERR; |
205
|
4
|
|
|
|
|
|
errno = 0; /* must set to zero before call, |
206
|
|
|
|
|
|
|
note race condition on errno */ |
207
|
4
|
50
|
|
|
|
|
if(*longstr == '-') |
208
|
0
|
|
|
|
|
|
l = htonl((uint32_t)strtol((char*)longstr, &end, 10)); |
209
|
4
|
|
|
|
|
|
else l = htonl((uint32_t)strtoul((char*)longstr, &end, 10)); |
210
|
|
|
|
|
|
|
|
211
|
4
|
50
|
|
|
|
|
if(*end != 0) { |
212
|
0
|
|
|
|
|
|
LDNS_FREE(r); |
213
|
0
|
|
|
|
|
|
return LDNS_STATUS_ERR; |
214
|
|
|
|
|
|
|
} else { |
215
|
4
|
50
|
|
|
|
|
if (errno == ERANGE) { |
216
|
0
|
|
|
|
|
|
LDNS_FREE(r); |
217
|
0
|
|
|
|
|
|
return LDNS_STATUS_SYNTAX_INTEGER_OVERFLOW; |
218
|
|
|
|
|
|
|
} |
219
|
4
|
|
|
|
|
|
memcpy(r, &l, sizeof(uint32_t)); |
220
|
4
|
|
|
|
|
|
*rd = ldns_rdf_new_frm_data( |
221
|
|
|
|
|
|
|
LDNS_RDF_TYPE_INT32, sizeof(uint32_t), r); |
222
|
4
|
|
|
|
|
|
LDNS_FREE(r); |
223
|
4
|
50
|
|
|
|
|
return *rd?LDNS_STATUS_OK:LDNS_STATUS_MEM_ERR; |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
ldns_status |
228
|
14
|
|
|
|
|
|
ldns_str2rdf_int8(ldns_rdf **rd, const char *bytestr) |
229
|
|
|
|
|
|
|
{ |
230
|
|
|
|
|
|
|
char *end; |
231
|
14
|
|
|
|
|
|
uint8_t *r = NULL; |
232
|
|
|
|
|
|
|
|
233
|
14
|
|
|
|
|
|
r = LDNS_MALLOC(uint8_t); |
234
|
14
|
50
|
|
|
|
|
if(!r) return LDNS_STATUS_MEM_ERR; |
235
|
|
|
|
|
|
|
|
236
|
14
|
|
|
|
|
|
*r = (uint8_t)strtol((char*)bytestr, &end, 10); |
237
|
|
|
|
|
|
|
|
238
|
14
|
50
|
|
|
|
|
if(*end != 0) { |
239
|
0
|
|
|
|
|
|
LDNS_FREE(r); |
240
|
0
|
|
|
|
|
|
return LDNS_STATUS_ERR; |
241
|
|
|
|
|
|
|
} else { |
242
|
14
|
|
|
|
|
|
*rd = ldns_rdf_new_frm_data( |
243
|
|
|
|
|
|
|
LDNS_RDF_TYPE_INT8, sizeof(uint8_t), r); |
244
|
14
|
|
|
|
|
|
LDNS_FREE(r); |
245
|
14
|
50
|
|
|
|
|
return *rd?LDNS_STATUS_OK:LDNS_STATUS_MEM_ERR; |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
/* |
251
|
|
|
|
|
|
|
* Checks whether the escaped value at **s is an decimal value or |
252
|
|
|
|
|
|
|
* a 'normally' escaped character (and not eos) |
253
|
|
|
|
|
|
|
* |
254
|
|
|
|
|
|
|
* The string pointer at *s is increased by either 0 (on error), 1 (on |
255
|
|
|
|
|
|
|
* normal escapes), or 3 (on decimals) |
256
|
|
|
|
|
|
|
* |
257
|
|
|
|
|
|
|
* Returns the number of bytes read from the escaped string, or |
258
|
|
|
|
|
|
|
* 0 on error |
259
|
|
|
|
|
|
|
*/ |
260
|
|
|
|
|
|
|
INLINE bool |
261
|
0
|
|
|
|
|
|
parse_escape(uint8_t *ch_p, const char** str_p) |
262
|
|
|
|
|
|
|
{ |
263
|
|
|
|
|
|
|
uint16_t val; |
264
|
|
|
|
|
|
|
|
265
|
0
|
0
|
|
|
|
|
if ((*str_p)[0] && isdigit((*str_p)[0]) && |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
266
|
0
|
0
|
|
|
|
|
(*str_p)[1] && isdigit((*str_p)[1]) && |
|
|
0
|
|
|
|
|
|
267
|
0
|
0
|
|
|
|
|
(*str_p)[2] && isdigit((*str_p)[2])) { |
268
|
|
|
|
|
|
|
|
269
|
0
|
|
|
|
|
|
val = (uint16_t)(((*str_p)[0] - '0') * 100 + |
270
|
0
|
|
|
|
|
|
((*str_p)[1] - '0') * 10 + |
271
|
0
|
|
|
|
|
|
((*str_p)[2] - '0')); |
272
|
|
|
|
|
|
|
|
273
|
0
|
0
|
|
|
|
|
if (val > 255) { |
274
|
0
|
|
|
|
|
|
goto error; |
275
|
|
|
|
|
|
|
} |
276
|
0
|
|
|
|
|
|
*ch_p = (uint8_t)val; |
277
|
0
|
|
|
|
|
|
*str_p += 3; |
278
|
0
|
|
|
|
|
|
return true; |
279
|
|
|
|
|
|
|
|
280
|
0
|
0
|
|
|
|
|
} else if ((*str_p)[0] && !isdigit((*str_p)[0])) { |
|
|
0
|
|
|
|
|
|
281
|
|
|
|
|
|
|
|
282
|
0
|
|
|
|
|
|
*ch_p = (uint8_t)*(*str_p)++; |
283
|
0
|
|
|
|
|
|
return true; |
284
|
|
|
|
|
|
|
} |
285
|
|
|
|
|
|
|
error: |
286
|
0
|
|
|
|
|
|
*str_p = NULL; |
287
|
0
|
|
|
|
|
|
return false; /* LDNS_STATUS_SYNTAX_BAD_ESCAPE */ |
288
|
|
|
|
|
|
|
} |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
INLINE bool |
291
|
143
|
|
|
|
|
|
parse_char(uint8_t *ch_p, const char** str_p) |
292
|
|
|
|
|
|
|
{ |
293
|
143
|
|
|
|
|
|
switch (**str_p) { |
294
|
|
|
|
|
|
|
|
295
|
2
|
|
|
|
|
|
case '\0': return false; |
296
|
|
|
|
|
|
|
|
297
|
0
|
|
|
|
|
|
case '\\': *str_p += 1; |
298
|
0
|
|
|
|
|
|
return parse_escape(ch_p, str_p); |
299
|
|
|
|
|
|
|
|
300
|
141
|
|
|
|
|
|
default: *ch_p = (uint8_t)*(*str_p)++; |
301
|
141
|
|
|
|
|
|
return true; |
302
|
|
|
|
|
|
|
} |
303
|
|
|
|
|
|
|
} |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
/* |
306
|
|
|
|
|
|
|
* No special care is taken, all dots are translated into |
307
|
|
|
|
|
|
|
* label seperators. |
308
|
|
|
|
|
|
|
* Could be made more efficient....we do 3 memcpy's in total... |
309
|
|
|
|
|
|
|
*/ |
310
|
|
|
|
|
|
|
ldns_status |
311
|
116
|
|
|
|
|
|
ldns_str2rdf_dname(ldns_rdf **d, const char *str) |
312
|
|
|
|
|
|
|
{ |
313
|
|
|
|
|
|
|
size_t len; |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
const char *s; |
316
|
|
|
|
|
|
|
uint8_t *q, *pq, label_len; |
317
|
|
|
|
|
|
|
uint8_t buf[LDNS_MAX_DOMAINLEN + 1]; |
318
|
116
|
|
|
|
|
|
*d = NULL; |
319
|
|
|
|
|
|
|
|
320
|
116
|
|
|
|
|
|
len = strlen((char*)str); |
321
|
|
|
|
|
|
|
/* octet representation can make strings a lot longer than actual length */ |
322
|
116
|
50
|
|
|
|
|
if (len > LDNS_MAX_DOMAINLEN * 4) { |
323
|
0
|
|
|
|
|
|
return LDNS_STATUS_DOMAINNAME_OVERFLOW; |
324
|
|
|
|
|
|
|
} |
325
|
116
|
50
|
|
|
|
|
if (0 == len) { |
326
|
0
|
|
|
|
|
|
return LDNS_STATUS_DOMAINNAME_UNDERFLOW; |
327
|
|
|
|
|
|
|
} |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
/* root label */ |
330
|
116
|
100
|
|
|
|
|
if (1 == len && *str == '.') { |
|
|
50
|
|
|
|
|
|
331
|
5
|
|
|
|
|
|
*d = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_DNAME, 1, "\0"); |
332
|
5
|
|
|
|
|
|
return LDNS_STATUS_OK; |
333
|
|
|
|
|
|
|
} |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
/* get on with the rest */ |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
/* s is on the current character in the string |
338
|
|
|
|
|
|
|
* pq points to where the labellength is going to go |
339
|
|
|
|
|
|
|
* label_len keeps track of the current label's length |
340
|
|
|
|
|
|
|
* q builds the dname inside the buf array |
341
|
|
|
|
|
|
|
*/ |
342
|
111
|
|
|
|
|
|
len = 0; |
343
|
111
|
|
|
|
|
|
q = buf+1; |
344
|
111
|
|
|
|
|
|
pq = buf; |
345
|
111
|
|
|
|
|
|
label_len = 0; |
346
|
1278
|
100
|
|
|
|
|
for (s = str; *s; s++, q++) { |
347
|
1168
|
50
|
|
|
|
|
if (q > buf + LDNS_MAX_DOMAINLEN) { |
348
|
0
|
|
|
|
|
|
return LDNS_STATUS_DOMAINNAME_OVERFLOW; |
349
|
|
|
|
|
|
|
} |
350
|
1168
|
|
|
|
|
|
*q = 0; |
351
|
1168
|
|
|
|
|
|
switch (*s) { |
352
|
|
|
|
|
|
|
case '.': |
353
|
141
|
50
|
|
|
|
|
if (label_len > LDNS_MAX_LABELLEN) { |
354
|
0
|
|
|
|
|
|
return LDNS_STATUS_LABEL_OVERFLOW; |
355
|
|
|
|
|
|
|
} |
356
|
141
|
100
|
|
|
|
|
if (label_len == 0) { |
357
|
1
|
|
|
|
|
|
return LDNS_STATUS_EMPTY_LABEL; |
358
|
|
|
|
|
|
|
} |
359
|
140
|
|
|
|
|
|
len += label_len + 1; |
360
|
140
|
|
|
|
|
|
*pq = label_len; |
361
|
140
|
|
|
|
|
|
label_len = 0; |
362
|
140
|
|
|
|
|
|
pq = q; |
363
|
140
|
|
|
|
|
|
break; |
364
|
|
|
|
|
|
|
case '\\': |
365
|
|
|
|
|
|
|
/* octet value or literal char */ |
366
|
0
|
|
|
|
|
|
s += 1; |
367
|
0
|
0
|
|
|
|
|
if (! parse_escape(q, &s)) { |
368
|
0
|
|
|
|
|
|
return LDNS_STATUS_SYNTAX_BAD_ESCAPE; |
369
|
|
|
|
|
|
|
} |
370
|
0
|
|
|
|
|
|
s -= 1; |
371
|
0
|
|
|
|
|
|
label_len++; |
372
|
0
|
|
|
|
|
|
break; |
373
|
|
|
|
|
|
|
default: |
374
|
1027
|
|
|
|
|
|
*q = (uint8_t)*s; |
375
|
1027
|
|
|
|
|
|
label_len++; |
376
|
|
|
|
|
|
|
} |
377
|
|
|
|
|
|
|
} |
378
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
/* add root label if last char was not '.' */ |
380
|
110
|
100
|
|
|
|
|
if (!ldns_dname_str_absolute(str)) { |
381
|
80
|
50
|
|
|
|
|
if (q > buf + LDNS_MAX_DOMAINLEN) { |
382
|
0
|
|
|
|
|
|
return LDNS_STATUS_DOMAINNAME_OVERFLOW; |
383
|
|
|
|
|
|
|
} |
384
|
80
|
50
|
|
|
|
|
if (label_len > LDNS_MAX_LABELLEN) { |
385
|
0
|
|
|
|
|
|
return LDNS_STATUS_LABEL_OVERFLOW; |
386
|
|
|
|
|
|
|
} |
387
|
80
|
50
|
|
|
|
|
if (label_len == 0) { /* label_len 0 but not . at end? */ |
388
|
0
|
|
|
|
|
|
return LDNS_STATUS_EMPTY_LABEL; |
389
|
|
|
|
|
|
|
} |
390
|
80
|
|
|
|
|
|
len += label_len + 1; |
391
|
80
|
|
|
|
|
|
*pq = label_len; |
392
|
80
|
|
|
|
|
|
*q = 0; |
393
|
|
|
|
|
|
|
} |
394
|
110
|
|
|
|
|
|
len++; |
395
|
|
|
|
|
|
|
|
396
|
110
|
|
|
|
|
|
*d = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_DNAME, len, buf); |
397
|
116
|
|
|
|
|
|
return LDNS_STATUS_OK; |
398
|
|
|
|
|
|
|
} |
399
|
|
|
|
|
|
|
|
400
|
|
|
|
|
|
|
ldns_status |
401
|
40
|
|
|
|
|
|
ldns_str2rdf_a(ldns_rdf **rd, const char *str) |
402
|
|
|
|
|
|
|
{ |
403
|
|
|
|
|
|
|
in_addr_t address; |
404
|
40
|
100
|
|
|
|
|
if (inet_pton(AF_INET, (char*)str, &address) != 1) { |
405
|
1
|
|
|
|
|
|
return LDNS_STATUS_INVALID_IP4; |
406
|
|
|
|
|
|
|
} else { |
407
|
39
|
|
|
|
|
|
*rd = ldns_rdf_new_frm_data( |
408
|
|
|
|
|
|
|
LDNS_RDF_TYPE_A, sizeof(address), &address); |
409
|
|
|
|
|
|
|
} |
410
|
40
|
50
|
|
|
|
|
return *rd?LDNS_STATUS_OK:LDNS_STATUS_MEM_ERR; |
411
|
|
|
|
|
|
|
} |
412
|
|
|
|
|
|
|
|
413
|
|
|
|
|
|
|
ldns_status |
414
|
32
|
|
|
|
|
|
ldns_str2rdf_aaaa(ldns_rdf **rd, const char *str) |
415
|
|
|
|
|
|
|
{ |
416
|
|
|
|
|
|
|
uint8_t address[LDNS_IP6ADDRLEN + 1]; |
417
|
|
|
|
|
|
|
|
418
|
32
|
100
|
|
|
|
|
if (inet_pton(AF_INET6, (char*)str, address) != 1) { |
419
|
7
|
|
|
|
|
|
return LDNS_STATUS_INVALID_IP6; |
420
|
|
|
|
|
|
|
} else { |
421
|
25
|
|
|
|
|
|
*rd = ldns_rdf_new_frm_data( |
422
|
|
|
|
|
|
|
LDNS_RDF_TYPE_AAAA, sizeof(address) - 1, &address); |
423
|
|
|
|
|
|
|
} |
424
|
32
|
50
|
|
|
|
|
return *rd?LDNS_STATUS_OK:LDNS_STATUS_MEM_ERR; |
425
|
|
|
|
|
|
|
} |
426
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
ldns_status |
428
|
2
|
|
|
|
|
|
ldns_str2rdf_str(ldns_rdf **rd, const char *str) |
429
|
|
|
|
|
|
|
{ |
430
|
2
|
|
|
|
|
|
uint8_t *data, *dp, ch = 0; |
431
|
|
|
|
|
|
|
size_t length; |
432
|
|
|
|
|
|
|
|
433
|
|
|
|
|
|
|
/* Worst case space requirement. We'll realloc to actual size later. */ |
434
|
2
|
50
|
|
|
|
|
dp = data = LDNS_XMALLOC(uint8_t, strlen(str) > 255 ? 256 : (strlen(str) + 1)); |
435
|
2
|
50
|
|
|
|
|
if (! data) { |
436
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
437
|
|
|
|
|
|
|
} |
438
|
|
|
|
|
|
|
|
439
|
|
|
|
|
|
|
/* Fill data (up to 255 characters) */ |
440
|
143
|
100
|
|
|
|
|
while (parse_char(&ch, &str)) { |
441
|
141
|
50
|
|
|
|
|
if (dp - data >= 255) { |
442
|
0
|
|
|
|
|
|
LDNS_FREE(data); |
443
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_STR; |
444
|
|
|
|
|
|
|
} |
445
|
141
|
|
|
|
|
|
*++dp = ch; |
446
|
|
|
|
|
|
|
} |
447
|
2
|
50
|
|
|
|
|
if (! str) { |
448
|
0
|
|
|
|
|
|
return LDNS_STATUS_SYNTAX_BAD_ESCAPE; |
449
|
|
|
|
|
|
|
} |
450
|
2
|
|
|
|
|
|
length = (size_t)(dp - data); |
451
|
|
|
|
|
|
|
/* Fix last length byte */ |
452
|
2
|
|
|
|
|
|
data[0] = (uint8_t)length; |
453
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
/* Lose the overmeasure */ |
455
|
2
|
|
|
|
|
|
data = LDNS_XREALLOC(dp = data, uint8_t, length + 1); |
456
|
2
|
50
|
|
|
|
|
if (! data) { |
457
|
0
|
|
|
|
|
|
LDNS_FREE(dp); |
458
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
459
|
|
|
|
|
|
|
} |
460
|
|
|
|
|
|
|
|
461
|
|
|
|
|
|
|
/* Create rdf */ |
462
|
2
|
|
|
|
|
|
*rd = ldns_rdf_new(LDNS_RDF_TYPE_STR, length + 1, data); |
463
|
2
|
50
|
|
|
|
|
if (! *rd) { |
464
|
0
|
|
|
|
|
|
LDNS_FREE(data); |
465
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
466
|
|
|
|
|
|
|
} |
467
|
2
|
|
|
|
|
|
return LDNS_STATUS_OK; |
468
|
|
|
|
|
|
|
} |
469
|
|
|
|
|
|
|
|
470
|
|
|
|
|
|
|
ldns_status |
471
|
0
|
|
|
|
|
|
ldns_str2rdf_apl(ldns_rdf **rd, const char *str) |
472
|
|
|
|
|
|
|
{ |
473
|
0
|
|
|
|
|
|
const char *my_str = str; |
474
|
|
|
|
|
|
|
|
475
|
|
|
|
|
|
|
char *my_ip_str; |
476
|
|
|
|
|
|
|
size_t ip_str_len; |
477
|
|
|
|
|
|
|
|
478
|
|
|
|
|
|
|
uint16_t family; |
479
|
|
|
|
|
|
|
bool negation; |
480
|
0
|
|
|
|
|
|
uint8_t afdlength = 0; |
481
|
|
|
|
|
|
|
uint8_t *afdpart; |
482
|
|
|
|
|
|
|
uint8_t prefix; |
483
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
uint8_t *data; |
485
|
|
|
|
|
|
|
|
486
|
0
|
|
|
|
|
|
size_t i = 0; |
487
|
|
|
|
|
|
|
|
488
|
|
|
|
|
|
|
/* [!]afi:address/prefix */ |
489
|
0
|
0
|
|
|
|
|
if (strlen(my_str) < 2 |
490
|
0
|
0
|
|
|
|
|
|| strchr(my_str, ':') == NULL |
491
|
0
|
0
|
|
|
|
|
|| strchr(my_str, '/') == NULL |
492
|
0
|
0
|
|
|
|
|
|| strchr(my_str, ':') > strchr(my_str, '/')) { |
493
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_STR; |
494
|
|
|
|
|
|
|
} |
495
|
|
|
|
|
|
|
|
496
|
0
|
0
|
|
|
|
|
if (my_str[0] == '!') { |
497
|
0
|
|
|
|
|
|
negation = true; |
498
|
0
|
|
|
|
|
|
my_str += 1; |
499
|
|
|
|
|
|
|
} else { |
500
|
0
|
|
|
|
|
|
negation = false; |
501
|
|
|
|
|
|
|
} |
502
|
|
|
|
|
|
|
|
503
|
0
|
|
|
|
|
|
family = (uint16_t) atoi(my_str); |
504
|
|
|
|
|
|
|
|
505
|
0
|
|
|
|
|
|
my_str = strchr(my_str, ':') + 1; |
506
|
|
|
|
|
|
|
|
507
|
|
|
|
|
|
|
/* need ip addr and only ip addr for inet_pton */ |
508
|
0
|
|
|
|
|
|
ip_str_len = (size_t) (strchr(my_str, '/') - my_str); |
509
|
0
|
|
|
|
|
|
my_ip_str = LDNS_XMALLOC(char, ip_str_len + 1); |
510
|
0
|
0
|
|
|
|
|
if(!my_ip_str) return LDNS_STATUS_MEM_ERR; |
511
|
0
|
|
|
|
|
|
strncpy(my_ip_str, my_str, ip_str_len + 1); |
512
|
0
|
|
|
|
|
|
my_ip_str[ip_str_len] = '\0'; |
513
|
|
|
|
|
|
|
|
514
|
0
|
0
|
|
|
|
|
if (family == 1) { |
515
|
|
|
|
|
|
|
/* ipv4 */ |
516
|
0
|
|
|
|
|
|
afdpart = LDNS_XMALLOC(uint8_t, 4); |
517
|
0
|
0
|
|
|
|
|
if(!afdpart) { |
518
|
0
|
|
|
|
|
|
LDNS_FREE(my_ip_str); |
519
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
520
|
|
|
|
|
|
|
} |
521
|
0
|
0
|
|
|
|
|
if (inet_pton(AF_INET, my_ip_str, afdpart) == 0) { |
522
|
0
|
|
|
|
|
|
LDNS_FREE(my_ip_str); |
523
|
0
|
|
|
|
|
|
LDNS_FREE(afdpart); |
524
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_STR; |
525
|
|
|
|
|
|
|
} |
526
|
0
|
0
|
|
|
|
|
for (i = 0; i < 4; i++) { |
527
|
0
|
0
|
|
|
|
|
if (afdpart[i] != 0) { |
528
|
0
|
|
|
|
|
|
afdlength = i + 1; |
529
|
|
|
|
|
|
|
} |
530
|
|
|
|
|
|
|
} |
531
|
0
|
0
|
|
|
|
|
} else if (family == 2) { |
532
|
|
|
|
|
|
|
/* ipv6 */ |
533
|
0
|
|
|
|
|
|
afdpart = LDNS_XMALLOC(uint8_t, 16); |
534
|
0
|
0
|
|
|
|
|
if(!afdpart) { |
535
|
0
|
|
|
|
|
|
LDNS_FREE(my_ip_str); |
536
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
537
|
|
|
|
|
|
|
} |
538
|
0
|
0
|
|
|
|
|
if (inet_pton(AF_INET6, my_ip_str, afdpart) == 0) { |
539
|
0
|
|
|
|
|
|
LDNS_FREE(my_ip_str); |
540
|
0
|
|
|
|
|
|
LDNS_FREE(afdpart); |
541
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_STR; |
542
|
|
|
|
|
|
|
} |
543
|
0
|
0
|
|
|
|
|
for (i = 0; i < 16; i++) { |
544
|
0
|
0
|
|
|
|
|
if (afdpart[i] != 0) { |
545
|
0
|
|
|
|
|
|
afdlength = i + 1; |
546
|
|
|
|
|
|
|
} |
547
|
|
|
|
|
|
|
} |
548
|
|
|
|
|
|
|
} else { |
549
|
|
|
|
|
|
|
/* unknown family */ |
550
|
0
|
|
|
|
|
|
LDNS_FREE(my_ip_str); |
551
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_STR; |
552
|
|
|
|
|
|
|
} |
553
|
|
|
|
|
|
|
|
554
|
0
|
|
|
|
|
|
my_str = strchr(my_str, '/') + 1; |
555
|
0
|
|
|
|
|
|
prefix = (uint8_t) atoi(my_str); |
556
|
|
|
|
|
|
|
|
557
|
0
|
|
|
|
|
|
data = LDNS_XMALLOC(uint8_t, 4 + afdlength); |
558
|
0
|
0
|
|
|
|
|
if(!data) { |
559
|
0
|
|
|
|
|
|
LDNS_FREE(afdpart); |
560
|
0
|
|
|
|
|
|
LDNS_FREE(my_ip_str); |
561
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_STR; |
562
|
|
|
|
|
|
|
} |
563
|
0
|
|
|
|
|
|
ldns_write_uint16(data, family); |
564
|
0
|
|
|
|
|
|
data[2] = prefix; |
565
|
0
|
|
|
|
|
|
data[3] = afdlength; |
566
|
0
|
0
|
|
|
|
|
if (negation) { |
567
|
|
|
|
|
|
|
/* set bit 1 of byte 3 */ |
568
|
0
|
|
|
|
|
|
data[3] = data[3] | 0x80; |
569
|
|
|
|
|
|
|
} |
570
|
|
|
|
|
|
|
|
571
|
0
|
|
|
|
|
|
memcpy(data + 4, afdpart, afdlength); |
572
|
|
|
|
|
|
|
|
573
|
0
|
|
|
|
|
|
*rd = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_APL, afdlength + 4, data); |
574
|
0
|
|
|
|
|
|
LDNS_FREE(afdpart); |
575
|
0
|
|
|
|
|
|
LDNS_FREE(data); |
576
|
0
|
|
|
|
|
|
LDNS_FREE(my_ip_str); |
577
|
|
|
|
|
|
|
|
578
|
0
|
0
|
|
|
|
|
return *rd?LDNS_STATUS_OK:LDNS_STATUS_MEM_ERR; |
579
|
|
|
|
|
|
|
} |
580
|
|
|
|
|
|
|
|
581
|
|
|
|
|
|
|
ldns_status |
582
|
4
|
|
|
|
|
|
ldns_str2rdf_b64(ldns_rdf **rd, const char *str) |
583
|
|
|
|
|
|
|
{ |
584
|
|
|
|
|
|
|
uint8_t *buffer; |
585
|
|
|
|
|
|
|
int16_t i; |
586
|
|
|
|
|
|
|
|
587
|
4
|
|
|
|
|
|
buffer = LDNS_XMALLOC(uint8_t, ldns_b64_ntop_calculate_size(strlen(str))); |
588
|
4
|
50
|
|
|
|
|
if(!buffer) { |
589
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
590
|
|
|
|
|
|
|
} |
591
|
|
|
|
|
|
|
|
592
|
4
|
|
|
|
|
|
i = (uint16_t)ldns_b64_pton((const char*)str, buffer, |
593
|
|
|
|
|
|
|
ldns_b64_ntop_calculate_size(strlen(str))); |
594
|
4
|
50
|
|
|
|
|
if (-1 == i) { |
595
|
0
|
|
|
|
|
|
LDNS_FREE(buffer); |
596
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_B64; |
597
|
|
|
|
|
|
|
} else { |
598
|
4
|
|
|
|
|
|
*rd = ldns_rdf_new_frm_data( |
599
|
4
|
|
|
|
|
|
LDNS_RDF_TYPE_B64, (uint16_t) i, buffer); |
600
|
|
|
|
|
|
|
} |
601
|
4
|
|
|
|
|
|
LDNS_FREE(buffer); |
602
|
|
|
|
|
|
|
|
603
|
4
|
50
|
|
|
|
|
return *rd?LDNS_STATUS_OK:LDNS_STATUS_MEM_ERR; |
604
|
|
|
|
|
|
|
} |
605
|
|
|
|
|
|
|
|
606
|
|
|
|
|
|
|
ldns_status |
607
|
2
|
|
|
|
|
|
ldns_str2rdf_b32_ext(ldns_rdf **rd, const char *str) |
608
|
|
|
|
|
|
|
{ |
609
|
|
|
|
|
|
|
uint8_t *buffer; |
610
|
|
|
|
|
|
|
int i; |
611
|
|
|
|
|
|
|
/* first byte contains length of actual b32 data */ |
612
|
2
|
|
|
|
|
|
uint8_t len = ldns_b32_pton_calculate_size(strlen(str)); |
613
|
2
|
|
|
|
|
|
buffer = LDNS_XMALLOC(uint8_t, len + 1); |
614
|
2
|
50
|
|
|
|
|
if(!buffer) { |
615
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
616
|
|
|
|
|
|
|
} |
617
|
2
|
|
|
|
|
|
buffer[0] = len; |
618
|
|
|
|
|
|
|
|
619
|
2
|
|
|
|
|
|
i = ldns_b32_pton_extended_hex((const char*)str, strlen(str), buffer + 1, |
620
|
|
|
|
|
|
|
ldns_b32_ntop_calculate_size(strlen(str))); |
621
|
2
|
50
|
|
|
|
|
if (i < 0) { |
622
|
0
|
|
|
|
|
|
LDNS_FREE(buffer); |
623
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_B32_EXT; |
624
|
|
|
|
|
|
|
} else { |
625
|
2
|
|
|
|
|
|
*rd = ldns_rdf_new_frm_data( |
626
|
2
|
|
|
|
|
|
LDNS_RDF_TYPE_B32_EXT, (uint16_t) i + 1, buffer); |
627
|
|
|
|
|
|
|
} |
628
|
2
|
|
|
|
|
|
LDNS_FREE(buffer); |
629
|
|
|
|
|
|
|
|
630
|
2
|
50
|
|
|
|
|
return *rd?LDNS_STATUS_OK:LDNS_STATUS_MEM_ERR; |
631
|
|
|
|
|
|
|
} |
632
|
|
|
|
|
|
|
|
633
|
|
|
|
|
|
|
ldns_status |
634
|
0
|
|
|
|
|
|
ldns_str2rdf_hex(ldns_rdf **rd, const char *str) |
635
|
|
|
|
|
|
|
{ |
636
|
|
|
|
|
|
|
uint8_t *t, *t_orig; |
637
|
|
|
|
|
|
|
int i; |
638
|
|
|
|
|
|
|
size_t len; |
639
|
|
|
|
|
|
|
|
640
|
0
|
|
|
|
|
|
len = strlen(str); |
641
|
|
|
|
|
|
|
|
642
|
0
|
0
|
|
|
|
|
if (len > LDNS_MAX_RDFLEN * 2) { |
643
|
0
|
|
|
|
|
|
return LDNS_STATUS_LABEL_OVERFLOW; |
644
|
|
|
|
|
|
|
} else { |
645
|
0
|
|
|
|
|
|
t = LDNS_XMALLOC(uint8_t, (len / 2) + 1); |
646
|
0
|
0
|
|
|
|
|
if(!t) { |
647
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
648
|
|
|
|
|
|
|
} |
649
|
0
|
|
|
|
|
|
t_orig = t; |
650
|
|
|
|
|
|
|
/* Now process octet by octet... */ |
651
|
0
|
0
|
|
|
|
|
while (*str) { |
652
|
0
|
|
|
|
|
|
*t = 0; |
653
|
0
|
0
|
|
|
|
|
if (isspace((int) *str)) { |
654
|
0
|
|
|
|
|
|
str++; |
655
|
|
|
|
|
|
|
} else { |
656
|
0
|
0
|
|
|
|
|
for (i = 16; i >= 1; i -= 15) { |
657
|
0
|
0
|
|
|
|
|
while (*str && isspace((int) *str)) { str++; } |
|
|
0
|
|
|
|
|
|
658
|
0
|
0
|
|
|
|
|
if (*str) { |
659
|
0
|
0
|
|
|
|
|
if (isxdigit((int) *str)) { |
660
|
0
|
|
|
|
|
|
*t += ldns_hexdigit_to_int(*str) * i; |
661
|
|
|
|
|
|
|
} else { |
662
|
0
|
|
|
|
|
|
LDNS_FREE(t_orig); |
663
|
0
|
|
|
|
|
|
return LDNS_STATUS_ERR; |
664
|
|
|
|
|
|
|
} |
665
|
0
|
|
|
|
|
|
++str; |
666
|
|
|
|
|
|
|
} |
667
|
|
|
|
|
|
|
} |
668
|
0
|
|
|
|
|
|
++t; |
669
|
|
|
|
|
|
|
} |
670
|
|
|
|
|
|
|
} |
671
|
0
|
|
|
|
|
|
*rd = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_HEX, |
672
|
0
|
|
|
|
|
|
(size_t) (t - t_orig), |
673
|
|
|
|
|
|
|
t_orig); |
674
|
0
|
|
|
|
|
|
LDNS_FREE(t_orig); |
675
|
|
|
|
|
|
|
} |
676
|
0
|
0
|
|
|
|
|
return *rd?LDNS_STATUS_OK:LDNS_STATUS_MEM_ERR; |
677
|
|
|
|
|
|
|
} |
678
|
|
|
|
|
|
|
|
679
|
|
|
|
|
|
|
ldns_status |
680
|
3
|
|
|
|
|
|
ldns_str2rdf_nsec(ldns_rdf **rd, const char *str) |
681
|
|
|
|
|
|
|
{ |
682
|
3
|
|
|
|
|
|
const char *delimiters = "\n\t "; |
683
|
3
|
|
|
|
|
|
char *token = LDNS_XMALLOC(char, LDNS_MAX_RDFLEN); |
684
|
|
|
|
|
|
|
ldns_buffer *str_buf; |
685
|
|
|
|
|
|
|
ssize_t c; |
686
|
|
|
|
|
|
|
uint16_t cur_type; |
687
|
3
|
|
|
|
|
|
size_t type_count = 0; |
688
|
|
|
|
|
|
|
ldns_rr_type type_list[65536]; |
689
|
3
|
50
|
|
|
|
|
if(!token) return LDNS_STATUS_MEM_ERR; |
690
|
3
|
50
|
|
|
|
|
if(rd == NULL) { |
691
|
0
|
|
|
|
|
|
LDNS_FREE(token); |
692
|
0
|
|
|
|
|
|
return LDNS_STATUS_NULL; |
693
|
|
|
|
|
|
|
} |
694
|
|
|
|
|
|
|
|
695
|
3
|
|
|
|
|
|
str_buf = LDNS_MALLOC(ldns_buffer); |
696
|
3
|
50
|
|
|
|
|
if(!str_buf) { |
697
|
0
|
|
|
|
|
|
LDNS_FREE(token); |
698
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
699
|
|
|
|
|
|
|
} |
700
|
3
|
|
|
|
|
|
ldns_buffer_new_frm_data(str_buf, (char *)str, strlen(str)); |
701
|
3
|
50
|
|
|
|
|
if(ldns_buffer_status(str_buf) != LDNS_STATUS_OK) { |
702
|
0
|
|
|
|
|
|
LDNS_FREE(str_buf); |
703
|
0
|
|
|
|
|
|
LDNS_FREE(token); |
704
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
705
|
|
|
|
|
|
|
} |
706
|
|
|
|
|
|
|
|
707
|
12
|
100
|
|
|
|
|
while ((c = ldns_bget_token(str_buf, token, delimiters, LDNS_MAX_RDFLEN)) != -1 && c != 0) { |
|
|
50
|
|
|
|
|
|
708
|
9
|
50
|
|
|
|
|
if(type_count >= sizeof(type_list)) { |
709
|
0
|
|
|
|
|
|
LDNS_FREE(str_buf); |
710
|
0
|
|
|
|
|
|
LDNS_FREE(token); |
711
|
0
|
|
|
|
|
|
return LDNS_STATUS_ERR; |
712
|
|
|
|
|
|
|
} |
713
|
9
|
|
|
|
|
|
cur_type = ldns_get_rr_type_by_name(token); |
714
|
9
|
|
|
|
|
|
type_list[type_count] = cur_type; |
715
|
9
|
|
|
|
|
|
type_count++; |
716
|
|
|
|
|
|
|
} |
717
|
|
|
|
|
|
|
|
718
|
3
|
|
|
|
|
|
*rd = ldns_dnssec_create_nsec_bitmap(type_list, |
719
|
|
|
|
|
|
|
type_count, |
720
|
|
|
|
|
|
|
LDNS_RR_TYPE_NSEC); |
721
|
|
|
|
|
|
|
|
722
|
3
|
|
|
|
|
|
LDNS_FREE(token); |
723
|
3
|
|
|
|
|
|
ldns_buffer_free(str_buf); |
724
|
3
|
50
|
|
|
|
|
return *rd?LDNS_STATUS_OK:LDNS_STATUS_MEM_ERR; |
725
|
|
|
|
|
|
|
} |
726
|
|
|
|
|
|
|
|
727
|
|
|
|
|
|
|
ldns_status |
728
|
1
|
|
|
|
|
|
ldns_str2rdf_type(ldns_rdf **rd, const char *str) |
729
|
|
|
|
|
|
|
{ |
730
|
|
|
|
|
|
|
uint16_t type; |
731
|
1
|
|
|
|
|
|
type = htons(ldns_get_rr_type_by_name(str)); |
732
|
|
|
|
|
|
|
/* ldns_rr_type is a 16 bit value */ |
733
|
1
|
|
|
|
|
|
*rd = ldns_rdf_new_frm_data( |
734
|
|
|
|
|
|
|
LDNS_RDF_TYPE_TYPE, sizeof(uint16_t), &type); |
735
|
1
|
50
|
|
|
|
|
return *rd?LDNS_STATUS_OK:LDNS_STATUS_MEM_ERR; |
736
|
|
|
|
|
|
|
} |
737
|
|
|
|
|
|
|
|
738
|
|
|
|
|
|
|
ldns_status |
739
|
0
|
|
|
|
|
|
ldns_str2rdf_class(ldns_rdf **rd, const char *str) |
740
|
|
|
|
|
|
|
{ |
741
|
|
|
|
|
|
|
uint16_t klass; |
742
|
0
|
|
|
|
|
|
klass = htons(ldns_get_rr_class_by_name(str)); |
743
|
|
|
|
|
|
|
/* class is 16 bit */ |
744
|
0
|
|
|
|
|
|
*rd = ldns_rdf_new_frm_data( |
745
|
|
|
|
|
|
|
LDNS_RDF_TYPE_CLASS, sizeof(uint16_t), &klass); |
746
|
0
|
0
|
|
|
|
|
return *rd?LDNS_STATUS_OK:LDNS_STATUS_MEM_ERR; |
747
|
|
|
|
|
|
|
} |
748
|
|
|
|
|
|
|
|
749
|
|
|
|
|
|
|
/* An certificate alg field can either be specified as a 8 bits number |
750
|
|
|
|
|
|
|
* or by its symbolic name. Handle both |
751
|
|
|
|
|
|
|
*/ |
752
|
|
|
|
|
|
|
ldns_status |
753
|
0
|
|
|
|
|
|
ldns_str2rdf_cert_alg(ldns_rdf **rd, const char *str) |
754
|
|
|
|
|
|
|
{ |
755
|
|
|
|
|
|
|
ldns_lookup_table *lt; |
756
|
|
|
|
|
|
|
ldns_status st; |
757
|
|
|
|
|
|
|
uint8_t idd[2]; |
758
|
0
|
|
|
|
|
|
lt = ldns_lookup_by_name(ldns_cert_algorithms, str); |
759
|
0
|
|
|
|
|
|
st = LDNS_STATUS_OK; |
760
|
|
|
|
|
|
|
|
761
|
0
|
0
|
|
|
|
|
if (lt) { |
762
|
0
|
|
|
|
|
|
ldns_write_uint16(idd, (uint16_t) lt->id); |
763
|
0
|
|
|
|
|
|
*rd = ldns_rdf_new_frm_data( |
764
|
|
|
|
|
|
|
LDNS_RDF_TYPE_INT16, sizeof(uint16_t), idd); |
765
|
0
|
0
|
|
|
|
|
if (!*rd) { |
766
|
0
|
|
|
|
|
|
st = LDNS_STATUS_ERR; |
767
|
|
|
|
|
|
|
} |
768
|
|
|
|
|
|
|
} else { |
769
|
|
|
|
|
|
|
/* try as-is (a number) */ |
770
|
0
|
|
|
|
|
|
st = ldns_str2rdf_int16(rd, str); |
771
|
0
|
|
|
|
|
|
if (st == LDNS_STATUS_OK && |
772
|
0
|
|
|
|
|
|
ldns_rdf2native_int16(*rd) == 0) { |
773
|
0
|
|
|
|
|
|
st = LDNS_STATUS_CERT_BAD_ALGORITHM; |
774
|
|
|
|
|
|
|
} |
775
|
|
|
|
|
|
|
} |
776
|
|
|
|
|
|
|
|
777
|
0
|
|
|
|
|
|
return st; |
778
|
|
|
|
|
|
|
} |
779
|
|
|
|
|
|
|
|
780
|
|
|
|
|
|
|
static ldns_lookup_table ldns_tlsa_certificate_usages[] = { |
781
|
|
|
|
|
|
|
{ LDNS_TLSA_USAGE_PKIX_TA , "PKIX-TA" }, |
782
|
|
|
|
|
|
|
{ LDNS_TLSA_USAGE_PKIX_EE , "PKIX-EE" }, |
783
|
|
|
|
|
|
|
{ LDNS_TLSA_USAGE_DANE_TA , "DANE-TA" }, |
784
|
|
|
|
|
|
|
{ LDNS_TLSA_USAGE_DANE_EE , "DANE-EE" }, |
785
|
|
|
|
|
|
|
{ LDNS_TLSA_USAGE_PRIVCERT , "PrivCert" } |
786
|
|
|
|
|
|
|
}; |
787
|
|
|
|
|
|
|
|
788
|
|
|
|
|
|
|
static ldns_lookup_table ldns_tlsa_selectors[] = { |
789
|
|
|
|
|
|
|
{ LDNS_TLSA_SELECTOR_CERT , "Cert" }, |
790
|
|
|
|
|
|
|
{ LDNS_TLSA_SELECTOR_SPKI , "SPKI" }, |
791
|
|
|
|
|
|
|
{ LDNS_TLSA_SELECTOR_PRIVSEL , "PrivSel" } |
792
|
|
|
|
|
|
|
}; |
793
|
|
|
|
|
|
|
|
794
|
|
|
|
|
|
|
static ldns_lookup_table ldns_tlsa_matching_types[] = { |
795
|
|
|
|
|
|
|
{ LDNS_TLSA_MATCHING_TYPE_FULL , "Full" }, |
796
|
|
|
|
|
|
|
{ LDNS_TLSA_MATCHING_TYPE_SHA2_256 , "SHA2-256" }, |
797
|
|
|
|
|
|
|
{ LDNS_TLSA_MATCHING_TYPE_SHA2_512 , "SHA2-512" }, |
798
|
|
|
|
|
|
|
{ LDNS_TLSA_MATCHING_TYPE_PRIVMATCH , "PrivMatch" } |
799
|
|
|
|
|
|
|
}; |
800
|
|
|
|
|
|
|
|
801
|
|
|
|
|
|
|
static ldns_status |
802
|
4
|
|
|
|
|
|
ldns_str2rdf_mnemonic4int8(ldns_lookup_table *lt, |
803
|
|
|
|
|
|
|
ldns_rdf **rd, const char *str) |
804
|
|
|
|
|
|
|
{ |
805
|
4
|
50
|
|
|
|
|
if ((lt = ldns_lookup_by_name(lt, str))) { |
806
|
|
|
|
|
|
|
/* it was given as a integer */ |
807
|
0
|
|
|
|
|
|
*rd = ldns_native2rdf_int8(LDNS_RDF_TYPE_INT8, (uint8_t) lt->id); |
808
|
0
|
0
|
|
|
|
|
if (!*rd) |
809
|
0
|
|
|
|
|
|
return LDNS_STATUS_ERR; |
810
|
|
|
|
|
|
|
else |
811
|
0
|
|
|
|
|
|
return LDNS_STATUS_OK; |
812
|
|
|
|
|
|
|
} |
813
|
4
|
|
|
|
|
|
return ldns_str2rdf_int8(rd, str); |
814
|
|
|
|
|
|
|
} |
815
|
|
|
|
|
|
|
|
816
|
|
|
|
|
|
|
/* An alg field can either be specified as a 8 bits number |
817
|
|
|
|
|
|
|
* or by its symbolic name. Handle both |
818
|
|
|
|
|
|
|
*/ |
819
|
|
|
|
|
|
|
ldns_status |
820
|
4
|
|
|
|
|
|
ldns_str2rdf_alg(ldns_rdf **rd, const char *str) |
821
|
|
|
|
|
|
|
{ |
822
|
4
|
|
|
|
|
|
return ldns_str2rdf_mnemonic4int8(ldns_algorithms, rd, str); |
823
|
|
|
|
|
|
|
} |
824
|
|
|
|
|
|
|
|
825
|
|
|
|
|
|
|
ldns_status |
826
|
0
|
|
|
|
|
|
ldns_str2rdf_certificate_usage(ldns_rdf **rd, const char *str) |
827
|
|
|
|
|
|
|
{ |
828
|
0
|
|
|
|
|
|
return ldns_str2rdf_mnemonic4int8( |
829
|
|
|
|
|
|
|
ldns_tlsa_certificate_usages, rd, str); |
830
|
|
|
|
|
|
|
} |
831
|
|
|
|
|
|
|
|
832
|
|
|
|
|
|
|
ldns_status |
833
|
0
|
|
|
|
|
|
ldns_str2rdf_selector(ldns_rdf **rd, const char *str) |
834
|
|
|
|
|
|
|
{ |
835
|
0
|
|
|
|
|
|
return ldns_str2rdf_mnemonic4int8(ldns_tlsa_selectors, rd, str); |
836
|
|
|
|
|
|
|
} |
837
|
|
|
|
|
|
|
|
838
|
|
|
|
|
|
|
ldns_status |
839
|
0
|
|
|
|
|
|
ldns_str2rdf_matching_type(ldns_rdf **rd, const char *str) |
840
|
|
|
|
|
|
|
{ |
841
|
0
|
|
|
|
|
|
return ldns_str2rdf_mnemonic4int8(ldns_tlsa_matching_types, rd, str); |
842
|
|
|
|
|
|
|
} |
843
|
|
|
|
|
|
|
|
844
|
|
|
|
|
|
|
ldns_status |
845
|
0
|
|
|
|
|
|
ldns_str2rdf_unknown( ATTR_UNUSED(ldns_rdf **rd) |
846
|
|
|
|
|
|
|
, ATTR_UNUSED(const char *str) |
847
|
|
|
|
|
|
|
) |
848
|
|
|
|
|
|
|
{ |
849
|
|
|
|
|
|
|
/* this should be caught in an earlier time (general str2host for |
850
|
|
|
|
|
|
|
rr's */ |
851
|
0
|
|
|
|
|
|
return LDNS_STATUS_NOT_IMPL; |
852
|
|
|
|
|
|
|
} |
853
|
|
|
|
|
|
|
|
854
|
|
|
|
|
|
|
ldns_status |
855
|
0
|
|
|
|
|
|
ldns_str2rdf_service( ATTR_UNUSED(ldns_rdf **rd) |
856
|
|
|
|
|
|
|
, ATTR_UNUSED(const char *str) |
857
|
|
|
|
|
|
|
) |
858
|
|
|
|
|
|
|
{ |
859
|
|
|
|
|
|
|
/* is this used? is this actually WKS? or SRV? */ |
860
|
0
|
|
|
|
|
|
return LDNS_STATUS_NOT_IMPL; |
861
|
|
|
|
|
|
|
} |
862
|
|
|
|
|
|
|
|
863
|
|
|
|
|
|
|
static int |
864
|
0
|
|
|
|
|
|
loc_parse_cm(char* my_str, char** endstr, uint8_t* m, uint8_t* e) |
865
|
|
|
|
|
|
|
{ |
866
|
|
|
|
|
|
|
/* read [.][mM] */ |
867
|
|
|
|
|
|
|
/* into mantissa exponent format for LOC type */ |
868
|
0
|
|
|
|
|
|
uint32_t meters = 0, cm = 0, val; |
869
|
0
|
0
|
|
|
|
|
while (isblank(*my_str)) { |
870
|
0
|
|
|
|
|
|
my_str++; |
871
|
|
|
|
|
|
|
} |
872
|
0
|
|
|
|
|
|
meters = (uint32_t)strtol(my_str, &my_str, 10); |
873
|
0
|
0
|
|
|
|
|
if (*my_str == '.') { |
874
|
0
|
|
|
|
|
|
my_str++; |
875
|
0
|
|
|
|
|
|
cm = (uint32_t)strtol(my_str, &my_str, 10); |
876
|
|
|
|
|
|
|
} |
877
|
0
|
0
|
|
|
|
|
if (meters >= 1) { |
878
|
0
|
|
|
|
|
|
*e = 2; |
879
|
0
|
|
|
|
|
|
val = meters; |
880
|
|
|
|
|
|
|
} else { |
881
|
0
|
|
|
|
|
|
*e = 0; |
882
|
0
|
|
|
|
|
|
val = cm; |
883
|
|
|
|
|
|
|
} |
884
|
0
|
0
|
|
|
|
|
while(val >= 10) { |
885
|
0
|
|
|
|
|
|
(*e)++; |
886
|
0
|
|
|
|
|
|
val /= 10; |
887
|
|
|
|
|
|
|
} |
888
|
0
|
|
|
|
|
|
*m = (uint8_t)val; |
889
|
|
|
|
|
|
|
|
890
|
0
|
0
|
|
|
|
|
if (*e > 9) |
891
|
0
|
|
|
|
|
|
return 0; |
892
|
0
|
0
|
|
|
|
|
if (*my_str == 'm' || *my_str == 'M') { |
|
|
0
|
|
|
|
|
|
893
|
0
|
|
|
|
|
|
my_str++; |
894
|
|
|
|
|
|
|
} |
895
|
0
|
|
|
|
|
|
*endstr = my_str; |
896
|
0
|
|
|
|
|
|
return 1; |
897
|
|
|
|
|
|
|
} |
898
|
|
|
|
|
|
|
|
899
|
|
|
|
|
|
|
ldns_status |
900
|
0
|
|
|
|
|
|
ldns_str2rdf_loc(ldns_rdf **rd, const char *str) |
901
|
|
|
|
|
|
|
{ |
902
|
0
|
|
|
|
|
|
uint32_t latitude = 0; |
903
|
0
|
|
|
|
|
|
uint32_t longitude = 0; |
904
|
0
|
|
|
|
|
|
uint32_t altitude = 0; |
905
|
|
|
|
|
|
|
|
906
|
|
|
|
|
|
|
uint8_t *data; |
907
|
0
|
|
|
|
|
|
uint32_t equator = (uint32_t) ldns_power(2, 31); |
908
|
|
|
|
|
|
|
|
909
|
0
|
|
|
|
|
|
uint32_t h = 0; |
910
|
0
|
|
|
|
|
|
uint32_t m = 0; |
911
|
0
|
|
|
|
|
|
uint8_t size_b = 1, size_e = 2; |
912
|
0
|
|
|
|
|
|
uint8_t horiz_pre_b = 1, horiz_pre_e = 6; |
913
|
0
|
|
|
|
|
|
uint8_t vert_pre_b = 1, vert_pre_e = 3; |
914
|
|
|
|
|
|
|
|
915
|
0
|
|
|
|
|
|
double s = 0.0; |
916
|
|
|
|
|
|
|
bool northerness; |
917
|
|
|
|
|
|
|
bool easterness; |
918
|
|
|
|
|
|
|
|
919
|
0
|
|
|
|
|
|
char *my_str = (char *) str; |
920
|
|
|
|
|
|
|
|
921
|
|
|
|
|
|
|
/* only support version 0 */ |
922
|
0
|
0
|
|
|
|
|
if (isdigit((int) *my_str)) { |
923
|
0
|
|
|
|
|
|
h = (uint32_t) strtol(my_str, &my_str, 10); |
924
|
|
|
|
|
|
|
} else { |
925
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_STR; |
926
|
|
|
|
|
|
|
} |
927
|
|
|
|
|
|
|
|
928
|
0
|
0
|
|
|
|
|
while (isblank((int) *my_str)) { |
929
|
0
|
|
|
|
|
|
my_str++; |
930
|
|
|
|
|
|
|
} |
931
|
|
|
|
|
|
|
|
932
|
0
|
0
|
|
|
|
|
if (isdigit((int) *my_str)) { |
933
|
0
|
|
|
|
|
|
m = (uint32_t) strtol(my_str, &my_str, 10); |
934
|
0
|
0
|
|
|
|
|
} else if (*my_str == 'N' || *my_str == 'S') { |
|
|
0
|
|
|
|
|
|
935
|
|
|
|
|
|
|
goto north; |
936
|
|
|
|
|
|
|
} else { |
937
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_STR; |
938
|
|
|
|
|
|
|
} |
939
|
|
|
|
|
|
|
|
940
|
0
|
0
|
|
|
|
|
while (isblank((int) *my_str)) { |
941
|
0
|
|
|
|
|
|
my_str++; |
942
|
|
|
|
|
|
|
} |
943
|
|
|
|
|
|
|
|
944
|
0
|
0
|
|
|
|
|
if (isdigit((int) *my_str)) { |
945
|
0
|
|
|
|
|
|
s = strtod(my_str, &my_str); |
946
|
|
|
|
|
|
|
} |
947
|
|
|
|
|
|
|
north: |
948
|
0
|
0
|
|
|
|
|
while (isblank((int) *my_str)) { |
949
|
0
|
|
|
|
|
|
my_str++; |
950
|
|
|
|
|
|
|
} |
951
|
|
|
|
|
|
|
|
952
|
0
|
0
|
|
|
|
|
if (*my_str == 'N') { |
953
|
0
|
|
|
|
|
|
northerness = true; |
954
|
0
|
0
|
|
|
|
|
} else if (*my_str == 'S') { |
955
|
0
|
|
|
|
|
|
northerness = false; |
956
|
|
|
|
|
|
|
} else { |
957
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_STR; |
958
|
|
|
|
|
|
|
} |
959
|
|
|
|
|
|
|
|
960
|
0
|
|
|
|
|
|
my_str++; |
961
|
|
|
|
|
|
|
|
962
|
|
|
|
|
|
|
/* store number */ |
963
|
0
|
|
|
|
|
|
s = 1000.0 * s; |
964
|
|
|
|
|
|
|
/* add a little to make floor in conversion a round */ |
965
|
0
|
|
|
|
|
|
s += 0.0005; |
966
|
0
|
|
|
|
|
|
latitude = (uint32_t) s; |
967
|
0
|
|
|
|
|
|
latitude += 1000 * 60 * m; |
968
|
0
|
|
|
|
|
|
latitude += 1000 * 60 * 60 * h; |
969
|
0
|
0
|
|
|
|
|
if (northerness) { |
970
|
0
|
|
|
|
|
|
latitude = equator + latitude; |
971
|
|
|
|
|
|
|
} else { |
972
|
0
|
|
|
|
|
|
latitude = equator - latitude; |
973
|
|
|
|
|
|
|
} |
974
|
0
|
0
|
|
|
|
|
while (isblank(*my_str)) { |
975
|
0
|
|
|
|
|
|
my_str++; |
976
|
|
|
|
|
|
|
} |
977
|
|
|
|
|
|
|
|
978
|
0
|
0
|
|
|
|
|
if (isdigit((int) *my_str)) { |
979
|
0
|
|
|
|
|
|
h = (uint32_t) strtol(my_str, &my_str, 10); |
980
|
|
|
|
|
|
|
} else { |
981
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_STR; |
982
|
|
|
|
|
|
|
} |
983
|
|
|
|
|
|
|
|
984
|
0
|
0
|
|
|
|
|
while (isblank((int) *my_str)) { |
985
|
0
|
|
|
|
|
|
my_str++; |
986
|
|
|
|
|
|
|
} |
987
|
|
|
|
|
|
|
|
988
|
0
|
0
|
|
|
|
|
if (isdigit((int) *my_str)) { |
989
|
0
|
|
|
|
|
|
m = (uint32_t) strtol(my_str, &my_str, 10); |
990
|
0
|
0
|
|
|
|
|
} else if (*my_str == 'E' || *my_str == 'W') { |
|
|
0
|
|
|
|
|
|
991
|
|
|
|
|
|
|
goto east; |
992
|
|
|
|
|
|
|
} else { |
993
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_STR; |
994
|
|
|
|
|
|
|
} |
995
|
|
|
|
|
|
|
|
996
|
0
|
0
|
|
|
|
|
while (isblank(*my_str)) { |
997
|
0
|
|
|
|
|
|
my_str++; |
998
|
|
|
|
|
|
|
} |
999
|
|
|
|
|
|
|
|
1000
|
0
|
0
|
|
|
|
|
if (isdigit((int) *my_str)) { |
1001
|
0
|
|
|
|
|
|
s = strtod(my_str, &my_str); |
1002
|
|
|
|
|
|
|
} |
1003
|
|
|
|
|
|
|
|
1004
|
|
|
|
|
|
|
east: |
1005
|
0
|
0
|
|
|
|
|
while (isblank(*my_str)) { |
1006
|
0
|
|
|
|
|
|
my_str++; |
1007
|
|
|
|
|
|
|
} |
1008
|
|
|
|
|
|
|
|
1009
|
0
|
0
|
|
|
|
|
if (*my_str == 'E') { |
1010
|
0
|
|
|
|
|
|
easterness = true; |
1011
|
0
|
0
|
|
|
|
|
} else if (*my_str == 'W') { |
1012
|
0
|
|
|
|
|
|
easterness = false; |
1013
|
|
|
|
|
|
|
} else { |
1014
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_STR; |
1015
|
|
|
|
|
|
|
} |
1016
|
|
|
|
|
|
|
|
1017
|
0
|
|
|
|
|
|
my_str++; |
1018
|
|
|
|
|
|
|
|
1019
|
|
|
|
|
|
|
/* store number */ |
1020
|
0
|
|
|
|
|
|
s *= 1000.0; |
1021
|
|
|
|
|
|
|
/* add a little to make floor in conversion a round */ |
1022
|
0
|
|
|
|
|
|
s += 0.0005; |
1023
|
0
|
|
|
|
|
|
longitude = (uint32_t) s; |
1024
|
0
|
|
|
|
|
|
longitude += 1000 * 60 * m; |
1025
|
0
|
|
|
|
|
|
longitude += 1000 * 60 * 60 * h; |
1026
|
|
|
|
|
|
|
|
1027
|
0
|
0
|
|
|
|
|
if (easterness) { |
1028
|
0
|
|
|
|
|
|
longitude += equator; |
1029
|
|
|
|
|
|
|
} else { |
1030
|
0
|
|
|
|
|
|
longitude = equator - longitude; |
1031
|
|
|
|
|
|
|
} |
1032
|
|
|
|
|
|
|
|
1033
|
0
|
|
|
|
|
|
altitude = (uint32_t)(strtod(my_str, &my_str)*100.0 + |
1034
|
0
|
|
|
|
|
|
10000000.0 + 0.5); |
1035
|
0
|
0
|
|
|
|
|
if (*my_str == 'm' || *my_str == 'M') { |
|
|
0
|
|
|
|
|
|
1036
|
0
|
|
|
|
|
|
my_str++; |
1037
|
|
|
|
|
|
|
} |
1038
|
|
|
|
|
|
|
|
1039
|
0
|
0
|
|
|
|
|
if (strlen(my_str) > 0) { |
1040
|
0
|
0
|
|
|
|
|
if(!loc_parse_cm(my_str, &my_str, &size_b, &size_e)) |
1041
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_STR; |
1042
|
|
|
|
|
|
|
} |
1043
|
|
|
|
|
|
|
|
1044
|
0
|
0
|
|
|
|
|
if (strlen(my_str) > 0) { |
1045
|
0
|
0
|
|
|
|
|
if(!loc_parse_cm(my_str, &my_str, &horiz_pre_b, &horiz_pre_e)) |
1046
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_STR; |
1047
|
|
|
|
|
|
|
} |
1048
|
|
|
|
|
|
|
|
1049
|
0
|
0
|
|
|
|
|
if (strlen(my_str) > 0) { |
1050
|
0
|
0
|
|
|
|
|
if(!loc_parse_cm(my_str, &my_str, &vert_pre_b, &vert_pre_e)) |
1051
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_STR; |
1052
|
|
|
|
|
|
|
} |
1053
|
|
|
|
|
|
|
|
1054
|
0
|
|
|
|
|
|
data = LDNS_XMALLOC(uint8_t, 16); |
1055
|
0
|
0
|
|
|
|
|
if(!data) { |
1056
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
1057
|
|
|
|
|
|
|
} |
1058
|
0
|
|
|
|
|
|
data[0] = 0; |
1059
|
0
|
|
|
|
|
|
data[1] = 0; |
1060
|
0
|
|
|
|
|
|
data[1] = ((size_b << 4) & 0xf0) | (size_e & 0x0f); |
1061
|
0
|
|
|
|
|
|
data[2] = ((horiz_pre_b << 4) & 0xf0) | (horiz_pre_e & 0x0f); |
1062
|
0
|
|
|
|
|
|
data[3] = ((vert_pre_b << 4) & 0xf0) | (vert_pre_e & 0x0f); |
1063
|
0
|
|
|
|
|
|
ldns_write_uint32(data + 4, latitude); |
1064
|
0
|
|
|
|
|
|
ldns_write_uint32(data + 8, longitude); |
1065
|
0
|
|
|
|
|
|
ldns_write_uint32(data + 12, altitude); |
1066
|
|
|
|
|
|
|
|
1067
|
0
|
|
|
|
|
|
*rd = ldns_rdf_new_frm_data( |
1068
|
|
|
|
|
|
|
LDNS_RDF_TYPE_LOC, 16, data); |
1069
|
|
|
|
|
|
|
|
1070
|
0
|
|
|
|
|
|
LDNS_FREE(data); |
1071
|
0
|
0
|
|
|
|
|
return *rd?LDNS_STATUS_OK:LDNS_STATUS_MEM_ERR; |
1072
|
|
|
|
|
|
|
} |
1073
|
|
|
|
|
|
|
|
1074
|
|
|
|
|
|
|
ldns_status |
1075
|
0
|
|
|
|
|
|
ldns_str2rdf_wks(ldns_rdf **rd, const char *str) |
1076
|
|
|
|
|
|
|
{ |
1077
|
0
|
|
|
|
|
|
uint8_t *bitmap = NULL; |
1078
|
|
|
|
|
|
|
uint8_t *data; |
1079
|
0
|
|
|
|
|
|
int bm_len = 0; |
1080
|
|
|
|
|
|
|
|
1081
|
0
|
|
|
|
|
|
struct protoent *proto = NULL; |
1082
|
0
|
|
|
|
|
|
struct servent *serv = NULL; |
1083
|
|
|
|
|
|
|
int serv_port; |
1084
|
|
|
|
|
|
|
|
1085
|
|
|
|
|
|
|
ldns_buffer *str_buf; |
1086
|
|
|
|
|
|
|
|
1087
|
0
|
|
|
|
|
|
char *proto_str = NULL; |
1088
|
|
|
|
|
|
|
char *token; |
1089
|
0
|
0
|
|
|
|
|
if(strlen(str) == 0) |
1090
|
0
|
|
|
|
|
|
token = LDNS_XMALLOC(char, 50); |
1091
|
0
|
|
|
|
|
|
else token = LDNS_XMALLOC(char, strlen(str)+2); |
1092
|
0
|
0
|
|
|
|
|
if(!token) return LDNS_STATUS_MEM_ERR; |
1093
|
|
|
|
|
|
|
|
1094
|
0
|
|
|
|
|
|
str_buf = LDNS_MALLOC(ldns_buffer); |
1095
|
0
|
0
|
|
|
|
|
if(!str_buf) {LDNS_FREE(token); return LDNS_STATUS_MEM_ERR;} |
1096
|
0
|
|
|
|
|
|
ldns_buffer_new_frm_data(str_buf, (char *)str, strlen(str)); |
1097
|
0
|
0
|
|
|
|
|
if(ldns_buffer_status(str_buf) != LDNS_STATUS_OK) { |
1098
|
0
|
|
|
|
|
|
LDNS_FREE(str_buf); |
1099
|
0
|
|
|
|
|
|
LDNS_FREE(token); |
1100
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
1101
|
|
|
|
|
|
|
} |
1102
|
|
|
|
|
|
|
|
1103
|
0
|
0
|
|
|
|
|
while(ldns_bget_token(str_buf, token, "\t\n ", strlen(str)) > 0) { |
1104
|
0
|
0
|
|
|
|
|
if (!proto_str) { |
1105
|
0
|
|
|
|
|
|
proto_str = strdup(token); |
1106
|
0
|
0
|
|
|
|
|
if (!proto_str) { |
1107
|
0
|
|
|
|
|
|
LDNS_FREE(bitmap); |
1108
|
0
|
|
|
|
|
|
LDNS_FREE(token); |
1109
|
0
|
|
|
|
|
|
ldns_buffer_free(str_buf); |
1110
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_STR; |
1111
|
|
|
|
|
|
|
} |
1112
|
|
|
|
|
|
|
} else { |
1113
|
0
|
|
|
|
|
|
serv = getservbyname(token, proto_str); |
1114
|
0
|
0
|
|
|
|
|
if (serv) { |
1115
|
0
|
|
|
|
|
|
serv_port = (int) ntohs((uint16_t) serv->s_port); |
1116
|
|
|
|
|
|
|
} else { |
1117
|
0
|
|
|
|
|
|
serv_port = atoi(token); |
1118
|
|
|
|
|
|
|
} |
1119
|
0
|
0
|
|
|
|
|
if (serv_port / 8 >= bm_len) { |
1120
|
0
|
|
|
|
|
|
uint8_t *b2 = LDNS_XREALLOC(bitmap, uint8_t, (serv_port / 8) + 1); |
1121
|
0
|
0
|
|
|
|
|
if(!b2) { |
1122
|
0
|
|
|
|
|
|
LDNS_FREE(bitmap); |
1123
|
0
|
|
|
|
|
|
LDNS_FREE(token); |
1124
|
0
|
|
|
|
|
|
ldns_buffer_free(str_buf); |
1125
|
0
|
|
|
|
|
|
free(proto_str); |
1126
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_STR; |
1127
|
|
|
|
|
|
|
} |
1128
|
0
|
|
|
|
|
|
bitmap = b2; |
1129
|
|
|
|
|
|
|
/* set to zero to be sure */ |
1130
|
0
|
0
|
|
|
|
|
for (; bm_len <= serv_port / 8; bm_len++) { |
1131
|
0
|
|
|
|
|
|
bitmap[bm_len] = 0; |
1132
|
|
|
|
|
|
|
} |
1133
|
|
|
|
|
|
|
} |
1134
|
0
|
|
|
|
|
|
ldns_set_bit(bitmap + (serv_port / 8), 7 - (serv_port % 8), true); |
1135
|
|
|
|
|
|
|
} |
1136
|
|
|
|
|
|
|
} |
1137
|
|
|
|
|
|
|
|
1138
|
0
|
0
|
|
|
|
|
if (!proto_str || !bitmap) { |
|
|
0
|
|
|
|
|
|
1139
|
0
|
|
|
|
|
|
LDNS_FREE(bitmap); |
1140
|
0
|
|
|
|
|
|
LDNS_FREE(token); |
1141
|
0
|
|
|
|
|
|
ldns_buffer_free(str_buf); |
1142
|
0
|
|
|
|
|
|
free(proto_str); |
1143
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_STR; |
1144
|
|
|
|
|
|
|
} |
1145
|
|
|
|
|
|
|
|
1146
|
0
|
|
|
|
|
|
data = LDNS_XMALLOC(uint8_t, bm_len + 1); |
1147
|
0
|
0
|
|
|
|
|
if(!data) { |
1148
|
0
|
|
|
|
|
|
LDNS_FREE(token); |
1149
|
0
|
|
|
|
|
|
ldns_buffer_free(str_buf); |
1150
|
0
|
|
|
|
|
|
LDNS_FREE(bitmap); |
1151
|
0
|
|
|
|
|
|
free(proto_str); |
1152
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_STR; |
1153
|
|
|
|
|
|
|
} |
1154
|
0
|
0
|
|
|
|
|
if (proto_str) |
1155
|
0
|
|
|
|
|
|
proto = getprotobyname(proto_str); |
1156
|
0
|
0
|
|
|
|
|
if (proto) { |
1157
|
0
|
|
|
|
|
|
data[0] = (uint8_t) proto->p_proto; |
1158
|
0
|
0
|
|
|
|
|
} else if (proto_str) { |
1159
|
0
|
|
|
|
|
|
data[0] = (uint8_t) atoi(proto_str); |
1160
|
|
|
|
|
|
|
} |
1161
|
0
|
|
|
|
|
|
memcpy(data + 1, bitmap, (size_t) bm_len); |
1162
|
|
|
|
|
|
|
|
1163
|
0
|
|
|
|
|
|
*rd = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_WKS, (uint16_t) (bm_len + 1), data); |
1164
|
|
|
|
|
|
|
|
1165
|
0
|
|
|
|
|
|
LDNS_FREE(data); |
1166
|
0
|
|
|
|
|
|
LDNS_FREE(token); |
1167
|
0
|
|
|
|
|
|
ldns_buffer_free(str_buf); |
1168
|
0
|
|
|
|
|
|
LDNS_FREE(bitmap); |
1169
|
0
|
|
|
|
|
|
free(proto_str); |
1170
|
|
|
|
|
|
|
#ifdef HAVE_ENDSERVENT |
1171
|
0
|
|
|
|
|
|
endservent(); |
1172
|
|
|
|
|
|
|
#endif |
1173
|
|
|
|
|
|
|
#ifdef HAVE_ENDPROTOENT |
1174
|
0
|
|
|
|
|
|
endprotoent(); |
1175
|
|
|
|
|
|
|
#endif |
1176
|
|
|
|
|
|
|
|
1177
|
0
|
0
|
|
|
|
|
if(!*rd) return LDNS_STATUS_MEM_ERR; |
1178
|
|
|
|
|
|
|
|
1179
|
0
|
|
|
|
|
|
return LDNS_STATUS_OK; |
1180
|
|
|
|
|
|
|
} |
1181
|
|
|
|
|
|
|
|
1182
|
|
|
|
|
|
|
ldns_status |
1183
|
0
|
|
|
|
|
|
ldns_str2rdf_nsap(ldns_rdf **rd, const char *str) |
1184
|
|
|
|
|
|
|
{ |
1185
|
|
|
|
|
|
|
size_t len, i; |
1186
|
0
|
|
|
|
|
|
char* nsap_str = (char*) str; |
1187
|
|
|
|
|
|
|
|
1188
|
|
|
|
|
|
|
/* just a hex string with optional dots? */ |
1189
|
0
|
0
|
|
|
|
|
if (str[0] != '0' || str[1] != 'x') { |
|
|
0
|
|
|
|
|
|
1190
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_STR; |
1191
|
|
|
|
|
|
|
} else { |
1192
|
0
|
|
|
|
|
|
len = strlen(str); |
1193
|
0
|
0
|
|
|
|
|
for (i=0; i < len; i++) { |
1194
|
0
|
0
|
|
|
|
|
if (nsap_str[i] == '.') |
1195
|
0
|
|
|
|
|
|
nsap_str[i] = ' '; |
1196
|
|
|
|
|
|
|
} |
1197
|
0
|
|
|
|
|
|
return ldns_str2rdf_hex(rd, str+2); |
1198
|
|
|
|
|
|
|
} |
1199
|
|
|
|
|
|
|
} |
1200
|
|
|
|
|
|
|
|
1201
|
|
|
|
|
|
|
ldns_status |
1202
|
0
|
|
|
|
|
|
ldns_str2rdf_atma(ldns_rdf **rd, const char *str) |
1203
|
|
|
|
|
|
|
{ |
1204
|
|
|
|
|
|
|
size_t len, i; |
1205
|
0
|
|
|
|
|
|
char* atma_str = (char*) str; |
1206
|
|
|
|
|
|
|
ldns_status status; |
1207
|
|
|
|
|
|
|
|
1208
|
|
|
|
|
|
|
/* just a hex string with optional dots? */ |
1209
|
0
|
|
|
|
|
|
len = strlen(str); |
1210
|
0
|
0
|
|
|
|
|
for (i=0; i < len; i++) { |
1211
|
0
|
0
|
|
|
|
|
if (atma_str[i] == '.') |
1212
|
0
|
|
|
|
|
|
atma_str[i] = ' '; |
1213
|
|
|
|
|
|
|
} |
1214
|
0
|
|
|
|
|
|
status = ldns_str2rdf_hex(rd, str); |
1215
|
|
|
|
|
|
|
if (status != LDNS_STATUS_OK) { |
1216
|
|
|
|
|
|
|
; /* probably in e.164 format than */ |
1217
|
|
|
|
|
|
|
} |
1218
|
0
|
|
|
|
|
|
return status; |
1219
|
|
|
|
|
|
|
} |
1220
|
|
|
|
|
|
|
|
1221
|
|
|
|
|
|
|
ldns_status |
1222
|
0
|
|
|
|
|
|
ldns_str2rdf_ipseckey(ldns_rdf **rd, const char *str) |
1223
|
|
|
|
|
|
|
{ |
1224
|
0
|
|
|
|
|
|
uint8_t precedence = 0; |
1225
|
0
|
|
|
|
|
|
uint8_t gateway_type = 0; |
1226
|
0
|
|
|
|
|
|
uint8_t algorithm = 0; |
1227
|
0
|
|
|
|
|
|
char* gateway = NULL; |
1228
|
0
|
|
|
|
|
|
char* publickey = NULL; |
1229
|
|
|
|
|
|
|
uint8_t *data; |
1230
|
|
|
|
|
|
|
ldns_buffer *str_buf; |
1231
|
|
|
|
|
|
|
char *token; |
1232
|
0
|
|
|
|
|
|
int token_count = 0; |
1233
|
0
|
|
|
|
|
|
int ipseckey_len = 0; |
1234
|
0
|
|
|
|
|
|
ldns_rdf* gateway_rdf = NULL; |
1235
|
0
|
|
|
|
|
|
ldns_rdf* publickey_rdf = NULL; |
1236
|
0
|
|
|
|
|
|
ldns_status status = LDNS_STATUS_OK; |
1237
|
|
|
|
|
|
|
|
1238
|
0
|
0
|
|
|
|
|
if(strlen(str) == 0) |
1239
|
0
|
|
|
|
|
|
token = LDNS_XMALLOC(char, 256); |
1240
|
0
|
|
|
|
|
|
else token = LDNS_XMALLOC(char, strlen(str)+2); |
1241
|
0
|
0
|
|
|
|
|
if(!token) return LDNS_STATUS_MEM_ERR; |
1242
|
|
|
|
|
|
|
|
1243
|
0
|
|
|
|
|
|
str_buf = LDNS_MALLOC(ldns_buffer); |
1244
|
0
|
0
|
|
|
|
|
if(!str_buf) {LDNS_FREE(token); return LDNS_STATUS_MEM_ERR;} |
1245
|
0
|
|
|
|
|
|
ldns_buffer_new_frm_data(str_buf, (char *)str, strlen(str)); |
1246
|
0
|
0
|
|
|
|
|
if(ldns_buffer_status(str_buf) != LDNS_STATUS_OK) { |
1247
|
0
|
|
|
|
|
|
LDNS_FREE(str_buf); |
1248
|
0
|
|
|
|
|
|
LDNS_FREE(token); |
1249
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
1250
|
|
|
|
|
|
|
} |
1251
|
0
|
0
|
|
|
|
|
while(ldns_bget_token(str_buf, token, "\t\n ", strlen(str)) > 0) { |
1252
|
0
|
|
|
|
|
|
switch (token_count) { |
1253
|
|
|
|
|
|
|
case 0: |
1254
|
0
|
|
|
|
|
|
precedence = (uint8_t)atoi(token); |
1255
|
0
|
|
|
|
|
|
break; |
1256
|
|
|
|
|
|
|
case 1: |
1257
|
0
|
|
|
|
|
|
gateway_type = (uint8_t)atoi(token); |
1258
|
0
|
|
|
|
|
|
break; |
1259
|
|
|
|
|
|
|
case 2: |
1260
|
0
|
|
|
|
|
|
algorithm = (uint8_t)atoi(token); |
1261
|
0
|
|
|
|
|
|
break; |
1262
|
|
|
|
|
|
|
case 3: |
1263
|
0
|
|
|
|
|
|
gateway = strdup(token); |
1264
|
0
|
0
|
|
|
|
|
if (!gateway || (gateway_type == 0 && |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1265
|
0
|
0
|
|
|
|
|
(token[0] != '.' || token[1] != '\0'))) { |
1266
|
0
|
|
|
|
|
|
LDNS_FREE(gateway); |
1267
|
0
|
|
|
|
|
|
LDNS_FREE(token); |
1268
|
0
|
|
|
|
|
|
ldns_buffer_free(str_buf); |
1269
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_STR; |
1270
|
|
|
|
|
|
|
} |
1271
|
0
|
|
|
|
|
|
break; |
1272
|
|
|
|
|
|
|
case 4: |
1273
|
0
|
|
|
|
|
|
publickey = strdup(token); |
1274
|
0
|
|
|
|
|
|
break; |
1275
|
|
|
|
|
|
|
default: |
1276
|
0
|
|
|
|
|
|
LDNS_FREE(token); |
1277
|
0
|
|
|
|
|
|
ldns_buffer_free(str_buf); |
1278
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_STR; |
1279
|
|
|
|
|
|
|
break; |
1280
|
|
|
|
|
|
|
} |
1281
|
0
|
|
|
|
|
|
token_count++; |
1282
|
|
|
|
|
|
|
} |
1283
|
|
|
|
|
|
|
|
1284
|
0
|
0
|
|
|
|
|
if (!gateway || !publickey) { |
|
|
0
|
|
|
|
|
|
1285
|
0
|
0
|
|
|
|
|
if (gateway) |
1286
|
0
|
|
|
|
|
|
LDNS_FREE(gateway); |
1287
|
0
|
0
|
|
|
|
|
if (publickey) |
1288
|
0
|
|
|
|
|
|
LDNS_FREE(publickey); |
1289
|
0
|
|
|
|
|
|
LDNS_FREE(token); |
1290
|
0
|
|
|
|
|
|
ldns_buffer_free(str_buf); |
1291
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_STR; |
1292
|
|
|
|
|
|
|
} |
1293
|
|
|
|
|
|
|
|
1294
|
0
|
0
|
|
|
|
|
if (gateway_type == 1) { |
1295
|
0
|
|
|
|
|
|
status = ldns_str2rdf_a(&gateway_rdf, gateway); |
1296
|
0
|
0
|
|
|
|
|
} else if (gateway_type == 2) { |
1297
|
0
|
|
|
|
|
|
status = ldns_str2rdf_aaaa(&gateway_rdf, gateway); |
1298
|
0
|
0
|
|
|
|
|
} else if (gateway_type == 3) { |
1299
|
0
|
|
|
|
|
|
status = ldns_str2rdf_dname(&gateway_rdf, gateway); |
1300
|
|
|
|
|
|
|
} |
1301
|
|
|
|
|
|
|
|
1302
|
0
|
0
|
|
|
|
|
if (status != LDNS_STATUS_OK) { |
1303
|
0
|
0
|
|
|
|
|
if (gateway) |
1304
|
0
|
|
|
|
|
|
LDNS_FREE(gateway); |
1305
|
0
|
0
|
|
|
|
|
if (publickey) |
1306
|
0
|
|
|
|
|
|
LDNS_FREE(publickey); |
1307
|
0
|
|
|
|
|
|
LDNS_FREE(token); |
1308
|
0
|
|
|
|
|
|
ldns_buffer_free(str_buf); |
1309
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_STR; |
1310
|
|
|
|
|
|
|
} |
1311
|
|
|
|
|
|
|
|
1312
|
0
|
|
|
|
|
|
status = ldns_str2rdf_b64(&publickey_rdf, publickey); |
1313
|
|
|
|
|
|
|
|
1314
|
0
|
0
|
|
|
|
|
if (status != LDNS_STATUS_OK) { |
1315
|
0
|
0
|
|
|
|
|
if (gateway) |
1316
|
0
|
|
|
|
|
|
LDNS_FREE(gateway); |
1317
|
0
|
0
|
|
|
|
|
if (publickey) |
1318
|
0
|
|
|
|
|
|
LDNS_FREE(publickey); |
1319
|
0
|
|
|
|
|
|
LDNS_FREE(token); |
1320
|
0
|
|
|
|
|
|
ldns_buffer_free(str_buf); |
1321
|
0
|
0
|
|
|
|
|
if (gateway_rdf) ldns_rdf_free(gateway_rdf); |
1322
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_STR; |
1323
|
|
|
|
|
|
|
} |
1324
|
|
|
|
|
|
|
|
1325
|
|
|
|
|
|
|
/* now copy all into one ipseckey rdf */ |
1326
|
0
|
0
|
|
|
|
|
if (gateway_type) |
1327
|
0
|
|
|
|
|
|
ipseckey_len = 3 + (int)ldns_rdf_size(gateway_rdf) + (int)ldns_rdf_size(publickey_rdf); |
1328
|
|
|
|
|
|
|
else |
1329
|
0
|
|
|
|
|
|
ipseckey_len = 3 + (int)ldns_rdf_size(publickey_rdf); |
1330
|
|
|
|
|
|
|
|
1331
|
0
|
|
|
|
|
|
data = LDNS_XMALLOC(uint8_t, ipseckey_len); |
1332
|
0
|
0
|
|
|
|
|
if(!data) { |
1333
|
0
|
0
|
|
|
|
|
if (gateway) |
1334
|
0
|
|
|
|
|
|
LDNS_FREE(gateway); |
1335
|
0
|
0
|
|
|
|
|
if (publickey) |
1336
|
0
|
|
|
|
|
|
LDNS_FREE(publickey); |
1337
|
0
|
|
|
|
|
|
LDNS_FREE(token); |
1338
|
0
|
|
|
|
|
|
ldns_buffer_free(str_buf); |
1339
|
0
|
0
|
|
|
|
|
if (gateway_rdf) ldns_rdf_free(gateway_rdf); |
1340
|
0
|
0
|
|
|
|
|
if (publickey_rdf) ldns_rdf_free(publickey_rdf); |
1341
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
1342
|
|
|
|
|
|
|
} |
1343
|
|
|
|
|
|
|
|
1344
|
0
|
|
|
|
|
|
data[0] = precedence; |
1345
|
0
|
|
|
|
|
|
data[1] = gateway_type; |
1346
|
0
|
|
|
|
|
|
data[2] = algorithm; |
1347
|
|
|
|
|
|
|
|
1348
|
0
|
0
|
|
|
|
|
if (gateway_type) { |
1349
|
0
|
|
|
|
|
|
memcpy(data + 3, |
1350
|
0
|
|
|
|
|
|
ldns_rdf_data(gateway_rdf), ldns_rdf_size(gateway_rdf)); |
1351
|
0
|
|
|
|
|
|
memcpy(data + 3 + ldns_rdf_size(gateway_rdf), |
1352
|
0
|
|
|
|
|
|
ldns_rdf_data(publickey_rdf), ldns_rdf_size(publickey_rdf)); |
1353
|
|
|
|
|
|
|
} else { |
1354
|
0
|
|
|
|
|
|
memcpy(data + 3, |
1355
|
0
|
|
|
|
|
|
ldns_rdf_data(publickey_rdf), ldns_rdf_size(publickey_rdf)); |
1356
|
|
|
|
|
|
|
} |
1357
|
|
|
|
|
|
|
|
1358
|
0
|
|
|
|
|
|
*rd = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_IPSECKEY, (uint16_t) ipseckey_len, data); |
1359
|
|
|
|
|
|
|
|
1360
|
0
|
0
|
|
|
|
|
if (gateway) |
1361
|
0
|
|
|
|
|
|
LDNS_FREE(gateway); |
1362
|
0
|
0
|
|
|
|
|
if (publickey) |
1363
|
0
|
|
|
|
|
|
LDNS_FREE(publickey); |
1364
|
0
|
|
|
|
|
|
LDNS_FREE(token); |
1365
|
0
|
|
|
|
|
|
ldns_buffer_free(str_buf); |
1366
|
0
|
|
|
|
|
|
ldns_rdf_free(gateway_rdf); |
1367
|
0
|
|
|
|
|
|
ldns_rdf_free(publickey_rdf); |
1368
|
0
|
|
|
|
|
|
LDNS_FREE(data); |
1369
|
0
|
0
|
|
|
|
|
if(!*rd) return LDNS_STATUS_MEM_ERR; |
1370
|
0
|
|
|
|
|
|
return LDNS_STATUS_OK; |
1371
|
|
|
|
|
|
|
} |
1372
|
|
|
|
|
|
|
|
1373
|
|
|
|
|
|
|
ldns_status |
1374
|
0
|
|
|
|
|
|
ldns_str2rdf_ilnp64(ldns_rdf **rd, const char *str) |
1375
|
|
|
|
|
|
|
{ |
1376
|
|
|
|
|
|
|
unsigned int a, b, c, d; |
1377
|
|
|
|
|
|
|
uint16_t shorts[4]; |
1378
|
|
|
|
|
|
|
int l; |
1379
|
|
|
|
|
|
|
|
1380
|
0
|
0
|
|
|
|
|
if (sscanf(str, "%4x:%4x:%4x:%4x%n", &a, &b, &c, &d, &l) != 4 || |
|
|
0
|
|
|
|
|
|
1381
|
0
|
0
|
|
|
|
|
l != (int)strlen(str) || /* more data to read */ |
1382
|
0
|
|
|
|
|
|
strpbrk(str, "+-") /* signed hexes */ |
1383
|
|
|
|
|
|
|
) { |
1384
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_ILNP64; |
1385
|
|
|
|
|
|
|
} else { |
1386
|
0
|
|
|
|
|
|
shorts[0] = htons(a); |
1387
|
0
|
|
|
|
|
|
shorts[1] = htons(b); |
1388
|
0
|
|
|
|
|
|
shorts[2] = htons(c); |
1389
|
0
|
|
|
|
|
|
shorts[3] = htons(d); |
1390
|
0
|
|
|
|
|
|
*rd = ldns_rdf_new_frm_data( |
1391
|
|
|
|
|
|
|
LDNS_RDF_TYPE_ILNP64, 4 * sizeof(uint16_t), &shorts); |
1392
|
|
|
|
|
|
|
} |
1393
|
0
|
0
|
|
|
|
|
return *rd ? LDNS_STATUS_OK : LDNS_STATUS_MEM_ERR; |
1394
|
|
|
|
|
|
|
} |
1395
|
|
|
|
|
|
|
|
1396
|
|
|
|
|
|
|
ldns_status |
1397
|
0
|
|
|
|
|
|
ldns_str2rdf_eui48(ldns_rdf **rd, const char *str) |
1398
|
|
|
|
|
|
|
{ |
1399
|
|
|
|
|
|
|
unsigned int a, b, c, d, e, f; |
1400
|
|
|
|
|
|
|
uint8_t bytes[6]; |
1401
|
|
|
|
|
|
|
int l; |
1402
|
|
|
|
|
|
|
|
1403
|
0
|
0
|
|
|
|
|
if (sscanf(str, "%2x-%2x-%2x-%2x-%2x-%2x%n", |
1404
|
0
|
0
|
|
|
|
|
&a, &b, &c, &d, &e, &f, &l) != 6 || |
1405
|
0
|
|
|
|
|
|
l != (int)strlen(str)) { |
1406
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_EUI48; |
1407
|
|
|
|
|
|
|
} else { |
1408
|
0
|
|
|
|
|
|
bytes[0] = a; |
1409
|
0
|
|
|
|
|
|
bytes[1] = b; |
1410
|
0
|
|
|
|
|
|
bytes[2] = c; |
1411
|
0
|
|
|
|
|
|
bytes[3] = d; |
1412
|
0
|
|
|
|
|
|
bytes[4] = e; |
1413
|
0
|
|
|
|
|
|
bytes[5] = f; |
1414
|
0
|
|
|
|
|
|
*rd = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_EUI48, 6, &bytes); |
1415
|
|
|
|
|
|
|
} |
1416
|
0
|
0
|
|
|
|
|
return *rd ? LDNS_STATUS_OK : LDNS_STATUS_MEM_ERR; |
1417
|
|
|
|
|
|
|
} |
1418
|
|
|
|
|
|
|
|
1419
|
|
|
|
|
|
|
ldns_status |
1420
|
0
|
|
|
|
|
|
ldns_str2rdf_eui64(ldns_rdf **rd, const char *str) |
1421
|
|
|
|
|
|
|
{ |
1422
|
|
|
|
|
|
|
unsigned int a, b, c, d, e, f, g, h; |
1423
|
|
|
|
|
|
|
uint8_t bytes[8]; |
1424
|
|
|
|
|
|
|
int l; |
1425
|
|
|
|
|
|
|
|
1426
|
0
|
0
|
|
|
|
|
if (sscanf(str, "%2x-%2x-%2x-%2x-%2x-%2x-%2x-%2x%n", |
1427
|
0
|
0
|
|
|
|
|
&a, &b, &c, &d, &e, &f, &g, &h, &l) != 8 || |
1428
|
0
|
|
|
|
|
|
l != (int)strlen(str)) { |
1429
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_EUI64; |
1430
|
|
|
|
|
|
|
} else { |
1431
|
0
|
|
|
|
|
|
bytes[0] = a; |
1432
|
0
|
|
|
|
|
|
bytes[1] = b; |
1433
|
0
|
|
|
|
|
|
bytes[2] = c; |
1434
|
0
|
|
|
|
|
|
bytes[3] = d; |
1435
|
0
|
|
|
|
|
|
bytes[4] = e; |
1436
|
0
|
|
|
|
|
|
bytes[5] = f; |
1437
|
0
|
|
|
|
|
|
bytes[6] = g; |
1438
|
0
|
|
|
|
|
|
bytes[7] = h; |
1439
|
0
|
|
|
|
|
|
*rd = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_EUI64, 8, &bytes); |
1440
|
|
|
|
|
|
|
} |
1441
|
0
|
0
|
|
|
|
|
return *rd ? LDNS_STATUS_OK : LDNS_STATUS_MEM_ERR; |
1442
|
|
|
|
|
|
|
} |
1443
|
|
|
|
|
|
|
|
1444
|
|
|
|
|
|
|
ldns_status |
1445
|
0
|
|
|
|
|
|
ldns_str2rdf_tag(ldns_rdf **rd, const char *str) |
1446
|
|
|
|
|
|
|
{ |
1447
|
|
|
|
|
|
|
uint8_t *data; |
1448
|
|
|
|
|
|
|
const char* ptr; |
1449
|
|
|
|
|
|
|
|
1450
|
0
|
0
|
|
|
|
|
if (strlen(str) > 255) { |
1451
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_TAG; |
1452
|
|
|
|
|
|
|
} |
1453
|
0
|
0
|
|
|
|
|
for (ptr = str; *ptr; ptr++) { |
1454
|
0
|
0
|
|
|
|
|
if (! isalnum(*ptr)) { |
1455
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_TAG; |
1456
|
|
|
|
|
|
|
} |
1457
|
|
|
|
|
|
|
} |
1458
|
0
|
|
|
|
|
|
data = LDNS_XMALLOC(uint8_t, strlen(str) + 1); |
1459
|
0
|
0
|
|
|
|
|
if (!data) { |
1460
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
1461
|
|
|
|
|
|
|
} |
1462
|
0
|
|
|
|
|
|
data[0] = strlen(str); |
1463
|
0
|
|
|
|
|
|
memcpy(data + 1, str, strlen(str)); |
1464
|
|
|
|
|
|
|
|
1465
|
0
|
|
|
|
|
|
*rd = ldns_rdf_new(LDNS_RDF_TYPE_TAG, strlen(str) + 1, data); |
1466
|
0
|
0
|
|
|
|
|
if (!*rd) { |
1467
|
0
|
|
|
|
|
|
LDNS_FREE(data); |
1468
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
1469
|
|
|
|
|
|
|
} |
1470
|
0
|
|
|
|
|
|
return LDNS_STATUS_OK; |
1471
|
|
|
|
|
|
|
} |
1472
|
|
|
|
|
|
|
|
1473
|
|
|
|
|
|
|
ldns_status |
1474
|
0
|
|
|
|
|
|
ldns_str2rdf_long_str(ldns_rdf **rd, const char *str) |
1475
|
|
|
|
|
|
|
{ |
1476
|
0
|
|
|
|
|
|
uint8_t *data, *dp, ch = 0; |
1477
|
|
|
|
|
|
|
size_t length; |
1478
|
|
|
|
|
|
|
|
1479
|
|
|
|
|
|
|
/* Worst case space requirement. We'll realloc to actual size later. */ |
1480
|
0
|
|
|
|
|
|
dp = data = LDNS_XMALLOC(uint8_t, strlen(str)); |
1481
|
0
|
0
|
|
|
|
|
if (! data) { |
1482
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
1483
|
|
|
|
|
|
|
} |
1484
|
|
|
|
|
|
|
|
1485
|
|
|
|
|
|
|
/* Fill data with parsed bytes */ |
1486
|
0
|
0
|
|
|
|
|
while (parse_char(&ch, &str)) { |
1487
|
0
|
|
|
|
|
|
*dp++ = ch; |
1488
|
0
|
0
|
|
|
|
|
if (dp - data > LDNS_MAX_RDFLEN) { |
1489
|
0
|
|
|
|
|
|
LDNS_FREE(data); |
1490
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_STR; |
1491
|
|
|
|
|
|
|
} |
1492
|
|
|
|
|
|
|
} |
1493
|
0
|
0
|
|
|
|
|
if (! str) { |
1494
|
0
|
|
|
|
|
|
return LDNS_STATUS_SYNTAX_BAD_ESCAPE; |
1495
|
|
|
|
|
|
|
} |
1496
|
0
|
|
|
|
|
|
length = (size_t)(dp - data); |
1497
|
|
|
|
|
|
|
|
1498
|
|
|
|
|
|
|
/* Lose the overmeasure */ |
1499
|
0
|
|
|
|
|
|
data = LDNS_XREALLOC(dp = data, uint8_t, length); |
1500
|
0
|
0
|
|
|
|
|
if (! data) { |
1501
|
0
|
|
|
|
|
|
LDNS_FREE(dp); |
1502
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
1503
|
|
|
|
|
|
|
} |
1504
|
|
|
|
|
|
|
|
1505
|
|
|
|
|
|
|
/* Create rdf */ |
1506
|
0
|
|
|
|
|
|
*rd = ldns_rdf_new(LDNS_RDF_TYPE_LONG_STR, length, data); |
1507
|
0
|
0
|
|
|
|
|
if (! *rd) { |
1508
|
0
|
|
|
|
|
|
LDNS_FREE(data); |
1509
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
1510
|
|
|
|
|
|
|
} |
1511
|
0
|
|
|
|
|
|
return LDNS_STATUS_OK; |
1512
|
|
|
|
|
|
|
} |
1513
|
|
|
|
|
|
|
|
1514
|
|
|
|
|
|
|
ldns_status |
1515
|
0
|
|
|
|
|
|
ldns_str2rdf_hip(ldns_rdf **rd, const char *str) |
1516
|
|
|
|
|
|
|
{ |
1517
|
0
|
|
|
|
|
|
const char *hit = strchr(str, ' ') + 1; |
1518
|
0
|
0
|
|
|
|
|
const char *pk = hit == NULL ? NULL : strchr(hit, ' ') + 1; |
1519
|
0
|
|
|
|
|
|
size_t hit_size = hit == NULL ? 0 |
1520
|
0
|
0
|
|
|
|
|
: pk == NULL ? strlen(hit) : (size_t) (pk - hit) - 1; |
|
|
0
|
|
|
|
|
|
1521
|
0
|
0
|
|
|
|
|
size_t pk_size = pk == NULL ? 0 : strlen(pk); |
1522
|
0
|
|
|
|
|
|
size_t hit_wire_size = (hit_size + 1) / 2; |
1523
|
0
|
|
|
|
|
|
size_t pk_wire_size = ldns_b64_pton_calculate_size(pk_size); |
1524
|
0
|
|
|
|
|
|
size_t rdf_size = 4 + hit_wire_size + pk_wire_size; |
1525
|
|
|
|
|
|
|
|
1526
|
|
|
|
|
|
|
char *endptr; /* utility var for strtol usage */ |
1527
|
0
|
|
|
|
|
|
int algorithm = strtol(str, &endptr, 10); |
1528
|
|
|
|
|
|
|
|
1529
|
|
|
|
|
|
|
uint8_t *data, *dp; |
1530
|
|
|
|
|
|
|
int hi, lo, written; |
1531
|
|
|
|
|
|
|
|
1532
|
0
|
0
|
|
|
|
|
if (hit_size == 0 || pk_size == 0 || (hit_size + 1) / 2 > 255 |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1533
|
0
|
0
|
|
|
|
|
|| rdf_size > LDNS_MAX_RDFLEN |
1534
|
0
|
0
|
|
|
|
|
|| algorithm < 0 || algorithm > 255 |
|
|
0
|
|
|
|
|
|
1535
|
0
|
0
|
|
|
|
|
|| (errno != 0 && algorithm == 0) /* out of range */ |
|
|
0
|
|
|
|
|
|
1536
|
0
|
0
|
|
|
|
|
|| endptr == str /* no digits */) { |
1537
|
|
|
|
|
|
|
|
1538
|
0
|
|
|
|
|
|
return LDNS_STATUS_SYNTAX_ERR; |
1539
|
|
|
|
|
|
|
} |
1540
|
0
|
0
|
|
|
|
|
if ((data = LDNS_XMALLOC(uint8_t, rdf_size)) == NULL) { |
1541
|
|
|
|
|
|
|
|
1542
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
1543
|
|
|
|
|
|
|
} |
1544
|
|
|
|
|
|
|
/* From RFC 5205 section 5. HIP RR Storage Format: |
1545
|
|
|
|
|
|
|
************************************************* |
1546
|
|
|
|
|
|
|
|
1547
|
|
|
|
|
|
|
0 1 2 3 |
1548
|
|
|
|
|
|
|
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
1549
|
|
|
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
1550
|
|
|
|
|
|
|
| HIT length | PK algorithm | PK length | |
1551
|
|
|
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
1552
|
|
|
|
|
|
|
| | |
1553
|
|
|
|
|
|
|
~ HIT ~ |
1554
|
|
|
|
|
|
|
| | |
1555
|
|
|
|
|
|
|
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
1556
|
|
|
|
|
|
|
| | | |
1557
|
|
|
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+ + |
1558
|
|
|
|
|
|
|
| Public Key | |
1559
|
|
|
|
|
|
|
~ ~ |
1560
|
|
|
|
|
|
|
| | |
1561
|
|
|
|
|
|
|
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
1562
|
|
|
|
|
|
|
| | | |
1563
|
|
|
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + |
1564
|
|
|
|
|
|
|
| | |
1565
|
|
|
|
|
|
|
~ Rendezvous Servers ~ |
1566
|
|
|
|
|
|
|
| | |
1567
|
|
|
|
|
|
|
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
1568
|
|
|
|
|
|
|
| | |
1569
|
|
|
|
|
|
|
+-+-+-+-+-+-+-+ */ |
1570
|
|
|
|
|
|
|
|
1571
|
0
|
|
|
|
|
|
data[0] = (uint8_t) hit_wire_size; |
1572
|
0
|
|
|
|
|
|
data[1] = (uint8_t) algorithm; |
1573
|
|
|
|
|
|
|
|
1574
|
0
|
0
|
|
|
|
|
for (dp = data + 4; *hit && *hit != ' '; dp++) { |
|
|
0
|
|
|
|
|
|
1575
|
|
|
|
|
|
|
|
1576
|
0
|
0
|
|
|
|
|
if ((hi = ldns_hexdigit_to_int(*hit++)) == -1 || |
|
|
0
|
|
|
|
|
|
1577
|
0
|
|
|
|
|
|
(lo = ldns_hexdigit_to_int(*hit++)) == -1) { |
1578
|
|
|
|
|
|
|
|
1579
|
0
|
|
|
|
|
|
LDNS_FREE(data); |
1580
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_HEX; |
1581
|
|
|
|
|
|
|
} |
1582
|
0
|
|
|
|
|
|
*dp = (uint8_t) hi << 4 | lo; |
1583
|
|
|
|
|
|
|
} |
1584
|
0
|
0
|
|
|
|
|
if ((written = ldns_b64_pton(pk, dp, pk_wire_size)) <= 0) { |
1585
|
|
|
|
|
|
|
|
1586
|
0
|
|
|
|
|
|
LDNS_FREE(data); |
1587
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_B64; |
1588
|
|
|
|
|
|
|
} |
1589
|
|
|
|
|
|
|
|
1590
|
|
|
|
|
|
|
/* Because ldns_b64_pton_calculate_size isn't always correct: |
1591
|
|
|
|
|
|
|
* (we have to fix it at some point) |
1592
|
|
|
|
|
|
|
*/ |
1593
|
0
|
|
|
|
|
|
pk_wire_size = (uint16_t) written; |
1594
|
0
|
|
|
|
|
|
ldns_write_uint16(data + 2, pk_wire_size); |
1595
|
0
|
|
|
|
|
|
rdf_size = 4 + hit_wire_size + pk_wire_size; |
1596
|
|
|
|
|
|
|
|
1597
|
|
|
|
|
|
|
/* Create rdf */ |
1598
|
0
|
0
|
|
|
|
|
if (! (*rd = ldns_rdf_new(LDNS_RDF_TYPE_HIP, rdf_size, data))) { |
1599
|
|
|
|
|
|
|
|
1600
|
0
|
|
|
|
|
|
LDNS_FREE(data); |
1601
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
1602
|
|
|
|
|
|
|
} |
1603
|
0
|
|
|
|
|
|
return LDNS_STATUS_OK; |
1604
|
|
|
|
|
|
|
} |