line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
/* |
2
|
|
|
|
|
|
|
* host2str.c |
3
|
|
|
|
|
|
|
* |
4
|
|
|
|
|
|
|
* conversion routines from the host format |
5
|
|
|
|
|
|
|
* to the presentation format (strings) |
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
|
|
|
|
|
|
|
#include |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#ifdef HAVE_SYS_SOCKET_H |
20
|
|
|
|
|
|
|
#include |
21
|
|
|
|
|
|
|
#endif |
22
|
|
|
|
|
|
|
#ifdef HAVE_ARPA_INET_H |
23
|
|
|
|
|
|
|
#include |
24
|
|
|
|
|
|
|
#endif |
25
|
|
|
|
|
|
|
#ifdef HAVE_NETDB_H |
26
|
|
|
|
|
|
|
#include |
27
|
|
|
|
|
|
|
#endif |
28
|
|
|
|
|
|
|
#include |
29
|
|
|
|
|
|
|
#include |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
#ifndef INET_ADDRSTRLEN |
32
|
|
|
|
|
|
|
#define INET_ADDRSTRLEN 16 |
33
|
|
|
|
|
|
|
#endif |
34
|
|
|
|
|
|
|
#ifndef INET6_ADDRSTRLEN |
35
|
|
|
|
|
|
|
#define INET6_ADDRSTRLEN 46 |
36
|
|
|
|
|
|
|
#endif |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
/* lookup tables for standard DNS stuff */ |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
/* Taken from RFC 2535, section 7. */ |
41
|
|
|
|
|
|
|
ldns_lookup_table ldns_algorithms[] = { |
42
|
|
|
|
|
|
|
{ LDNS_RSAMD5, "RSAMD5" }, |
43
|
|
|
|
|
|
|
{ LDNS_DH, "DH" }, |
44
|
|
|
|
|
|
|
{ LDNS_DSA, "DSA" }, |
45
|
|
|
|
|
|
|
{ LDNS_ECC, "ECC" }, |
46
|
|
|
|
|
|
|
{ LDNS_RSASHA1, "RSASHA1" }, |
47
|
|
|
|
|
|
|
{ LDNS_DSA_NSEC3, "DSA-NSEC3-SHA1" }, |
48
|
|
|
|
|
|
|
{ LDNS_RSASHA1_NSEC3, "RSASHA1-NSEC3-SHA1" }, |
49
|
|
|
|
|
|
|
#ifdef USE_SHA2 |
50
|
|
|
|
|
|
|
{ LDNS_RSASHA256, "RSASHA256"}, |
51
|
|
|
|
|
|
|
{ LDNS_RSASHA512, "RSASHA512"}, |
52
|
|
|
|
|
|
|
#endif |
53
|
|
|
|
|
|
|
#ifdef USE_GOST |
54
|
|
|
|
|
|
|
{ LDNS_ECC_GOST, "ECC-GOST"}, |
55
|
|
|
|
|
|
|
#endif |
56
|
|
|
|
|
|
|
#ifdef USE_ECDSA |
57
|
|
|
|
|
|
|
{ LDNS_ECDSAP256SHA256, "ECDSAP256SHA256"}, |
58
|
|
|
|
|
|
|
{ LDNS_ECDSAP384SHA384, "ECDSAP384SHA384"}, |
59
|
|
|
|
|
|
|
#endif |
60
|
|
|
|
|
|
|
{ LDNS_INDIRECT, "INDIRECT" }, |
61
|
|
|
|
|
|
|
{ LDNS_PRIVATEDNS, "PRIVATEDNS" }, |
62
|
|
|
|
|
|
|
{ LDNS_PRIVATEOID, "PRIVATEOID" }, |
63
|
|
|
|
|
|
|
{ 0, NULL } |
64
|
|
|
|
|
|
|
}; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
/* Taken from RFC 4398 */ |
67
|
|
|
|
|
|
|
ldns_lookup_table ldns_cert_algorithms[] = { |
68
|
|
|
|
|
|
|
{ LDNS_CERT_PKIX, "PKIX" }, |
69
|
|
|
|
|
|
|
{ LDNS_CERT_SPKI, "SPKI" }, |
70
|
|
|
|
|
|
|
{ LDNS_CERT_PGP, "PGP" }, |
71
|
|
|
|
|
|
|
{ LDNS_CERT_IPKIX, "IPKIX" }, |
72
|
|
|
|
|
|
|
{ LDNS_CERT_ISPKI, "ISPKI" }, |
73
|
|
|
|
|
|
|
{ LDNS_CERT_IPGP, "IPGP" }, |
74
|
|
|
|
|
|
|
{ LDNS_CERT_ACPKIX, "ACPKIX" }, |
75
|
|
|
|
|
|
|
{ LDNS_CERT_IACPKIX, "IACPKIX" }, |
76
|
|
|
|
|
|
|
{ LDNS_CERT_URI, "URI" }, |
77
|
|
|
|
|
|
|
{ LDNS_CERT_OID, "OID" }, |
78
|
|
|
|
|
|
|
{ 0, NULL } |
79
|
|
|
|
|
|
|
}; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
/* classes */ |
82
|
|
|
|
|
|
|
ldns_lookup_table ldns_rr_classes[] = { |
83
|
|
|
|
|
|
|
{ LDNS_RR_CLASS_IN, "IN" }, |
84
|
|
|
|
|
|
|
{ LDNS_RR_CLASS_CH, "CH" }, |
85
|
|
|
|
|
|
|
{ LDNS_RR_CLASS_HS, "HS" }, |
86
|
|
|
|
|
|
|
{ LDNS_RR_CLASS_NONE, "NONE" }, |
87
|
|
|
|
|
|
|
{ LDNS_RR_CLASS_ANY, "ANY" }, |
88
|
|
|
|
|
|
|
{ 0, NULL } |
89
|
|
|
|
|
|
|
}; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
/* if these are used elsewhere */ |
92
|
|
|
|
|
|
|
ldns_lookup_table ldns_rcodes[] = { |
93
|
|
|
|
|
|
|
{ LDNS_RCODE_NOERROR, "NOERROR" }, |
94
|
|
|
|
|
|
|
{ LDNS_RCODE_FORMERR, "FORMERR" }, |
95
|
|
|
|
|
|
|
{ LDNS_RCODE_SERVFAIL, "SERVFAIL" }, |
96
|
|
|
|
|
|
|
{ LDNS_RCODE_NXDOMAIN, "NXDOMAIN" }, |
97
|
|
|
|
|
|
|
{ LDNS_RCODE_NOTIMPL, "NOTIMPL" }, |
98
|
|
|
|
|
|
|
{ LDNS_RCODE_REFUSED, "REFUSED" }, |
99
|
|
|
|
|
|
|
{ LDNS_RCODE_YXDOMAIN, "YXDOMAIN" }, |
100
|
|
|
|
|
|
|
{ LDNS_RCODE_YXRRSET, "YXRRSET" }, |
101
|
|
|
|
|
|
|
{ LDNS_RCODE_NXRRSET, "NXRRSET" }, |
102
|
|
|
|
|
|
|
{ LDNS_RCODE_NOTAUTH, "NOTAUTH" }, |
103
|
|
|
|
|
|
|
{ LDNS_RCODE_NOTZONE, "NOTZONE" }, |
104
|
|
|
|
|
|
|
{ 0, NULL } |
105
|
|
|
|
|
|
|
}; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
ldns_lookup_table ldns_opcodes[] = { |
108
|
|
|
|
|
|
|
{ LDNS_PACKET_QUERY, "QUERY" }, |
109
|
|
|
|
|
|
|
{ LDNS_PACKET_IQUERY, "IQUERY" }, |
110
|
|
|
|
|
|
|
{ LDNS_PACKET_STATUS, "STATUS" }, |
111
|
|
|
|
|
|
|
{ LDNS_PACKET_NOTIFY, "NOTIFY" }, |
112
|
|
|
|
|
|
|
{ LDNS_PACKET_UPDATE, "UPDATE" }, |
113
|
|
|
|
|
|
|
{ 0, NULL } |
114
|
|
|
|
|
|
|
}; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
const ldns_output_format ldns_output_format_nocomments_record = { 0, NULL }; |
117
|
|
|
|
|
|
|
const ldns_output_format *ldns_output_format_nocomments |
118
|
|
|
|
|
|
|
= &ldns_output_format_nocomments_record; |
119
|
|
|
|
|
|
|
const ldns_output_format ldns_output_format_onlykeyids_record = { |
120
|
|
|
|
|
|
|
LDNS_COMMENT_KEY, NULL |
121
|
|
|
|
|
|
|
}; |
122
|
|
|
|
|
|
|
const ldns_output_format *ldns_output_format_onlykeyids |
123
|
|
|
|
|
|
|
= &ldns_output_format_onlykeyids_record; |
124
|
|
|
|
|
|
|
const ldns_output_format *ldns_output_format_default |
125
|
|
|
|
|
|
|
= &ldns_output_format_onlykeyids_record; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
const ldns_output_format ldns_output_format_bubblebabble_record = { |
128
|
|
|
|
|
|
|
LDNS_COMMENT_KEY | LDNS_COMMENT_BUBBLEBABBLE | LDNS_COMMENT_FLAGS, NULL |
129
|
|
|
|
|
|
|
}; |
130
|
|
|
|
|
|
|
const ldns_output_format *ldns_output_format_bubblebabble |
131
|
|
|
|
|
|
|
= &ldns_output_format_bubblebabble_record; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
static bool |
134
|
48
|
|
|
|
|
|
ldns_output_format_covers_type(const ldns_output_format* fmt, ldns_rr_type t) |
135
|
|
|
|
|
|
|
{ |
136
|
96
|
50
|
|
|
|
|
return fmt && (fmt->flags & LDNS_FMT_RFC3597) && |
|
|
0
|
|
|
|
|
|
137
|
96
|
|
|
|
|
|
((ldns_output_format_storage*)fmt)->bitmap && |
138
|
0
|
|
|
|
|
|
ldns_nsec_bitmap_covers_type( |
139
|
0
|
|
|
|
|
|
((ldns_output_format_storage*)fmt)->bitmap, t); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
ldns_status |
143
|
0
|
|
|
|
|
|
ldns_output_format_set_type(ldns_output_format* fmt, ldns_rr_type t) |
144
|
|
|
|
|
|
|
{ |
145
|
0
|
|
|
|
|
|
ldns_output_format_storage* fmt_st = (ldns_output_format_storage*)fmt; |
146
|
|
|
|
|
|
|
ldns_status s; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
assert(fmt != NULL); |
149
|
|
|
|
|
|
|
|
150
|
0
|
0
|
|
|
|
|
if (!(fmt_st->flags & LDNS_FMT_RFC3597)) { |
151
|
0
|
|
|
|
|
|
ldns_output_format_set(fmt, LDNS_FMT_RFC3597); |
152
|
|
|
|
|
|
|
} |
153
|
0
|
0
|
|
|
|
|
if (! fmt_st->bitmap) { |
154
|
0
|
|
|
|
|
|
s = ldns_rdf_bitmap_known_rr_types_space(&fmt_st->bitmap); |
155
|
0
|
0
|
|
|
|
|
if (s != LDNS_STATUS_OK) { |
156
|
0
|
|
|
|
|
|
return s; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
} |
159
|
0
|
|
|
|
|
|
return ldns_nsec_bitmap_set_type(fmt_st->bitmap, t); |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
ldns_status |
163
|
0
|
|
|
|
|
|
ldns_output_format_clear_type(ldns_output_format* fmt, ldns_rr_type t) |
164
|
|
|
|
|
|
|
{ |
165
|
0
|
|
|
|
|
|
ldns_output_format_storage* fmt_st = (ldns_output_format_storage*)fmt; |
166
|
|
|
|
|
|
|
ldns_status s; |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
assert(fmt != NULL); |
169
|
|
|
|
|
|
|
|
170
|
0
|
0
|
|
|
|
|
if (!(fmt_st->flags & LDNS_FMT_RFC3597)) { |
171
|
0
|
|
|
|
|
|
ldns_output_format_set(fmt, LDNS_FMT_RFC3597); |
172
|
|
|
|
|
|
|
} |
173
|
0
|
0
|
|
|
|
|
if (! fmt_st->bitmap) { |
174
|
0
|
|
|
|
|
|
s = ldns_rdf_bitmap_known_rr_types(&fmt_st->bitmap); |
175
|
0
|
0
|
|
|
|
|
if (s != LDNS_STATUS_OK) { |
176
|
0
|
|
|
|
|
|
return s; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
} |
179
|
0
|
|
|
|
|
|
return ldns_nsec_bitmap_clear_type(fmt_st->bitmap, t); |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
ldns_status |
183
|
8
|
|
|
|
|
|
ldns_pkt_opcode2buffer_str(ldns_buffer *output, ldns_pkt_opcode opcode) |
184
|
|
|
|
|
|
|
{ |
185
|
8
|
|
|
|
|
|
ldns_lookup_table *lt = ldns_lookup_by_id(ldns_opcodes, opcode); |
186
|
8
|
50
|
|
|
|
|
if (lt && lt->name) { |
|
|
50
|
|
|
|
|
|
187
|
8
|
|
|
|
|
|
ldns_buffer_printf(output, "%s", lt->name); |
188
|
|
|
|
|
|
|
} else { |
189
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "OPCODE%u", opcode); |
190
|
|
|
|
|
|
|
} |
191
|
8
|
|
|
|
|
|
return ldns_buffer_status(output); |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
ldns_status |
195
|
16
|
|
|
|
|
|
ldns_pkt_rcode2buffer_str(ldns_buffer *output, ldns_pkt_rcode rcode) |
196
|
|
|
|
|
|
|
{ |
197
|
16
|
|
|
|
|
|
ldns_lookup_table *lt = ldns_lookup_by_id(ldns_rcodes, rcode); |
198
|
16
|
50
|
|
|
|
|
if (lt && lt->name) { |
|
|
50
|
|
|
|
|
|
199
|
16
|
|
|
|
|
|
ldns_buffer_printf(output, "%s", lt->name); |
200
|
|
|
|
|
|
|
} else { |
201
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "RCODE%u", rcode); |
202
|
|
|
|
|
|
|
} |
203
|
16
|
|
|
|
|
|
return ldns_buffer_status(output); |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
ldns_status |
207
|
0
|
|
|
|
|
|
ldns_algorithm2buffer_str(ldns_buffer *output, |
208
|
|
|
|
|
|
|
ldns_algorithm algorithm) |
209
|
|
|
|
|
|
|
{ |
210
|
0
|
|
|
|
|
|
ldns_lookup_table *lt = ldns_lookup_by_id(ldns_algorithms, |
211
|
|
|
|
|
|
|
algorithm); |
212
|
0
|
0
|
|
|
|
|
if (lt && lt->name) { |
|
|
0
|
|
|
|
|
|
213
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%s", lt->name); |
214
|
|
|
|
|
|
|
} else { |
215
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "ALG%u", algorithm); |
216
|
|
|
|
|
|
|
} |
217
|
0
|
|
|
|
|
|
return ldns_buffer_status(output); |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
ldns_status |
221
|
0
|
|
|
|
|
|
ldns_cert_algorithm2buffer_str(ldns_buffer *output, |
222
|
|
|
|
|
|
|
ldns_cert_algorithm cert_algorithm) |
223
|
|
|
|
|
|
|
{ |
224
|
0
|
|
|
|
|
|
ldns_lookup_table *lt = ldns_lookup_by_id(ldns_cert_algorithms, |
225
|
|
|
|
|
|
|
cert_algorithm); |
226
|
0
|
0
|
|
|
|
|
if (lt && lt->name) { |
|
|
0
|
|
|
|
|
|
227
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%s", lt->name); |
228
|
|
|
|
|
|
|
} else { |
229
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "CERT_ALG%u", |
230
|
|
|
|
|
|
|
cert_algorithm); |
231
|
|
|
|
|
|
|
} |
232
|
0
|
|
|
|
|
|
return ldns_buffer_status(output); |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
char * |
236
|
8
|
|
|
|
|
|
ldns_pkt_opcode2str(ldns_pkt_opcode opcode) |
237
|
|
|
|
|
|
|
{ |
238
|
|
|
|
|
|
|
char *str; |
239
|
|
|
|
|
|
|
ldns_buffer *buf; |
240
|
|
|
|
|
|
|
|
241
|
8
|
|
|
|
|
|
buf = ldns_buffer_new(12); |
242
|
8
|
50
|
|
|
|
|
if (!buf) { |
243
|
0
|
|
|
|
|
|
return NULL; |
244
|
|
|
|
|
|
|
} |
245
|
|
|
|
|
|
|
|
246
|
8
|
|
|
|
|
|
str = NULL; |
247
|
8
|
50
|
|
|
|
|
if (ldns_pkt_opcode2buffer_str(buf, opcode) == LDNS_STATUS_OK) { |
248
|
8
|
|
|
|
|
|
str = ldns_buffer_export2str(buf); |
249
|
|
|
|
|
|
|
} |
250
|
|
|
|
|
|
|
|
251
|
8
|
|
|
|
|
|
ldns_buffer_free(buf); |
252
|
8
|
|
|
|
|
|
return str; |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
char * |
256
|
16
|
|
|
|
|
|
ldns_pkt_rcode2str(ldns_pkt_rcode rcode) |
257
|
|
|
|
|
|
|
{ |
258
|
|
|
|
|
|
|
char *str; |
259
|
|
|
|
|
|
|
ldns_buffer *buf; |
260
|
|
|
|
|
|
|
|
261
|
16
|
|
|
|
|
|
buf = ldns_buffer_new(10); |
262
|
16
|
50
|
|
|
|
|
if (!buf) { |
263
|
0
|
|
|
|
|
|
return NULL; |
264
|
|
|
|
|
|
|
} |
265
|
|
|
|
|
|
|
|
266
|
16
|
|
|
|
|
|
str = NULL; |
267
|
16
|
50
|
|
|
|
|
if (ldns_pkt_rcode2buffer_str(buf, rcode) == LDNS_STATUS_OK) { |
268
|
16
|
|
|
|
|
|
str = ldns_buffer_export2str(buf); |
269
|
|
|
|
|
|
|
} |
270
|
|
|
|
|
|
|
|
271
|
16
|
|
|
|
|
|
ldns_buffer_free(buf); |
272
|
16
|
|
|
|
|
|
return str; |
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
char * |
276
|
0
|
|
|
|
|
|
ldns_pkt_algorithm2str(ldns_algorithm algorithm) |
277
|
|
|
|
|
|
|
{ |
278
|
|
|
|
|
|
|
char *str; |
279
|
|
|
|
|
|
|
ldns_buffer *buf; |
280
|
|
|
|
|
|
|
|
281
|
0
|
|
|
|
|
|
buf = ldns_buffer_new(10); |
282
|
0
|
0
|
|
|
|
|
if (!buf) { |
283
|
0
|
|
|
|
|
|
return NULL; |
284
|
|
|
|
|
|
|
} |
285
|
|
|
|
|
|
|
|
286
|
0
|
|
|
|
|
|
str = NULL; |
287
|
0
|
0
|
|
|
|
|
if (ldns_algorithm2buffer_str(buf, algorithm) |
288
|
|
|
|
|
|
|
== LDNS_STATUS_OK) { |
289
|
0
|
|
|
|
|
|
str = ldns_buffer_export2str(buf); |
290
|
|
|
|
|
|
|
} |
291
|
|
|
|
|
|
|
|
292
|
0
|
|
|
|
|
|
ldns_buffer_free(buf); |
293
|
0
|
|
|
|
|
|
return str; |
294
|
|
|
|
|
|
|
} |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
char * |
297
|
0
|
|
|
|
|
|
ldns_pkt_cert_algorithm2str(ldns_cert_algorithm cert_algorithm) |
298
|
|
|
|
|
|
|
{ |
299
|
|
|
|
|
|
|
char *str; |
300
|
|
|
|
|
|
|
ldns_buffer *buf; |
301
|
|
|
|
|
|
|
|
302
|
0
|
|
|
|
|
|
buf = ldns_buffer_new(10); |
303
|
0
|
0
|
|
|
|
|
if (!buf) { |
304
|
0
|
|
|
|
|
|
return NULL; |
305
|
|
|
|
|
|
|
} |
306
|
|
|
|
|
|
|
|
307
|
0
|
|
|
|
|
|
str = NULL; |
308
|
0
|
0
|
|
|
|
|
if (ldns_cert_algorithm2buffer_str(buf, cert_algorithm) |
309
|
|
|
|
|
|
|
== LDNS_STATUS_OK) { |
310
|
0
|
|
|
|
|
|
str = ldns_buffer_export2str(buf); |
311
|
|
|
|
|
|
|
} |
312
|
|
|
|
|
|
|
|
313
|
0
|
|
|
|
|
|
ldns_buffer_free(buf); |
314
|
0
|
|
|
|
|
|
return str; |
315
|
|
|
|
|
|
|
} |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
/* do NOT pass compressed data here :p */ |
319
|
|
|
|
|
|
|
ldns_status |
320
|
40
|
|
|
|
|
|
ldns_rdf2buffer_str_dname(ldns_buffer *output, const ldns_rdf *dname) |
321
|
|
|
|
|
|
|
{ |
322
|
|
|
|
|
|
|
/* can we do with 1 pos var? or without at all? */ |
323
|
40
|
|
|
|
|
|
uint8_t src_pos = 0; |
324
|
|
|
|
|
|
|
uint8_t len; |
325
|
|
|
|
|
|
|
uint8_t *data; |
326
|
|
|
|
|
|
|
uint8_t i; |
327
|
|
|
|
|
|
|
unsigned char c; |
328
|
|
|
|
|
|
|
|
329
|
40
|
|
|
|
|
|
data = (uint8_t*)ldns_rdf_data(dname); |
330
|
40
|
|
|
|
|
|
len = data[src_pos]; |
331
|
|
|
|
|
|
|
|
332
|
40
|
50
|
|
|
|
|
if (ldns_rdf_size(dname) > LDNS_MAX_DOMAINLEN) { |
333
|
|
|
|
|
|
|
/* too large, return */ |
334
|
0
|
|
|
|
|
|
return LDNS_STATUS_DOMAINNAME_OVERFLOW; |
335
|
|
|
|
|
|
|
} |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
/* special case: root label */ |
338
|
40
|
50
|
|
|
|
|
if (1 == ldns_rdf_size(dname)) { |
339
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "."); |
340
|
|
|
|
|
|
|
} else { |
341
|
133
|
100
|
|
|
|
|
while ((len > 0) && src_pos < ldns_rdf_size(dname)) { |
|
|
50
|
|
|
|
|
|
342
|
93
|
|
|
|
|
|
src_pos++; |
343
|
355
|
100
|
|
|
|
|
for(i = 0; i < len; i++) { |
344
|
|
|
|
|
|
|
/* paranoia check for various 'strange' |
345
|
|
|
|
|
|
|
characters in dnames |
346
|
|
|
|
|
|
|
*/ |
347
|
262
|
|
|
|
|
|
c = (unsigned char) data[src_pos]; |
348
|
262
|
50
|
|
|
|
|
if(c == '.' || c == ';' || |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
349
|
262
|
50
|
|
|
|
|
c == '(' || c == ')' || |
|
|
50
|
|
|
|
|
|
350
|
|
|
|
|
|
|
c == '\\') { |
351
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\\%c", |
352
|
0
|
|
|
|
|
|
data[src_pos]); |
353
|
262
|
50
|
|
|
|
|
} else if (!(isascii(c) && isgraph(c))) { |
|
|
50
|
|
|
|
|
|
354
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\\%03u", |
355
|
0
|
|
|
|
|
|
data[src_pos]); |
356
|
|
|
|
|
|
|
} else { |
357
|
262
|
|
|
|
|
|
ldns_buffer_printf(output, "%c", data[src_pos]); |
358
|
|
|
|
|
|
|
} |
359
|
262
|
|
|
|
|
|
src_pos++; |
360
|
|
|
|
|
|
|
} |
361
|
|
|
|
|
|
|
|
362
|
93
|
50
|
|
|
|
|
if (src_pos < ldns_rdf_size(dname)) { |
363
|
93
|
|
|
|
|
|
ldns_buffer_printf(output, "."); |
364
|
|
|
|
|
|
|
} |
365
|
93
|
|
|
|
|
|
len = data[src_pos]; |
366
|
|
|
|
|
|
|
} |
367
|
|
|
|
|
|
|
} |
368
|
40
|
|
|
|
|
|
return ldns_buffer_status(output); |
369
|
|
|
|
|
|
|
} |
370
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
ldns_status |
372
|
18
|
|
|
|
|
|
ldns_rdf2buffer_str_int8(ldns_buffer *output, const ldns_rdf *rdf) |
373
|
|
|
|
|
|
|
{ |
374
|
18
|
|
|
|
|
|
uint8_t data = ldns_rdf_data(rdf)[0]; |
375
|
18
|
|
|
|
|
|
ldns_buffer_printf(output, "%lu", (unsigned long) data); |
376
|
18
|
|
|
|
|
|
return ldns_buffer_status(output); |
377
|
|
|
|
|
|
|
} |
378
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
ldns_status |
380
|
9
|
|
|
|
|
|
ldns_rdf2buffer_str_int16(ldns_buffer *output, const ldns_rdf *rdf) |
381
|
|
|
|
|
|
|
{ |
382
|
9
|
|
|
|
|
|
uint16_t data = ldns_read_uint16(ldns_rdf_data(rdf)); |
383
|
9
|
|
|
|
|
|
ldns_buffer_printf(output, "%lu", (unsigned long) data); |
384
|
9
|
|
|
|
|
|
return ldns_buffer_status(output); |
385
|
|
|
|
|
|
|
} |
386
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
ldns_status |
388
|
0
|
|
|
|
|
|
ldns_rdf2buffer_str_int32(ldns_buffer *output, const ldns_rdf *rdf) |
389
|
|
|
|
|
|
|
{ |
390
|
0
|
|
|
|
|
|
uint32_t data = ldns_read_uint32(ldns_rdf_data(rdf)); |
391
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%lu", (unsigned long) data); |
392
|
0
|
|
|
|
|
|
return ldns_buffer_status(output); |
393
|
|
|
|
|
|
|
} |
394
|
|
|
|
|
|
|
|
395
|
|
|
|
|
|
|
ldns_status |
396
|
0
|
|
|
|
|
|
ldns_rdf2buffer_str_time(ldns_buffer *output, const ldns_rdf *rdf) |
397
|
|
|
|
|
|
|
{ |
398
|
|
|
|
|
|
|
/* create a YYYYMMDDHHMMSS string if possible */ |
399
|
|
|
|
|
|
|
struct tm tm; |
400
|
|
|
|
|
|
|
char date_buf[16]; |
401
|
|
|
|
|
|
|
|
402
|
0
|
|
|
|
|
|
memset(&tm, 0, sizeof(tm)); |
403
|
0
|
0
|
|
|
|
|
if (ldns_serial_arithmitics_gmtime_r(ldns_rdf2native_int32(rdf), time(NULL), &tm) |
404
|
0
|
0
|
|
|
|
|
&& strftime(date_buf, 15, "%Y%m%d%H%M%S", &tm)) { |
405
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%s", date_buf); |
406
|
|
|
|
|
|
|
} |
407
|
0
|
|
|
|
|
|
return ldns_buffer_status(output); |
408
|
|
|
|
|
|
|
} |
409
|
|
|
|
|
|
|
|
410
|
|
|
|
|
|
|
ldns_status |
411
|
14
|
|
|
|
|
|
ldns_rdf2buffer_str_a(ldns_buffer *output, const ldns_rdf *rdf) |
412
|
|
|
|
|
|
|
{ |
413
|
|
|
|
|
|
|
char str[INET_ADDRSTRLEN]; |
414
|
|
|
|
|
|
|
|
415
|
14
|
50
|
|
|
|
|
if (inet_ntop(AF_INET, ldns_rdf_data(rdf), str, INET_ADDRSTRLEN)) { |
416
|
14
|
|
|
|
|
|
ldns_buffer_printf(output, "%s", str); |
417
|
|
|
|
|
|
|
} |
418
|
14
|
|
|
|
|
|
return ldns_buffer_status(output); |
419
|
|
|
|
|
|
|
} |
420
|
|
|
|
|
|
|
|
421
|
|
|
|
|
|
|
ldns_status |
422
|
2
|
|
|
|
|
|
ldns_rdf2buffer_str_aaaa(ldns_buffer *output, const ldns_rdf *rdf) |
423
|
|
|
|
|
|
|
{ |
424
|
|
|
|
|
|
|
char str[INET6_ADDRSTRLEN]; |
425
|
|
|
|
|
|
|
|
426
|
2
|
50
|
|
|
|
|
if (inet_ntop(AF_INET6, ldns_rdf_data(rdf), str, INET6_ADDRSTRLEN)) { |
427
|
2
|
|
|
|
|
|
ldns_buffer_printf(output, "%s", str); |
428
|
|
|
|
|
|
|
} |
429
|
|
|
|
|
|
|
|
430
|
2
|
|
|
|
|
|
return ldns_buffer_status(output); |
431
|
|
|
|
|
|
|
} |
432
|
|
|
|
|
|
|
|
433
|
|
|
|
|
|
|
static void |
434
|
2
|
|
|
|
|
|
ldns_characters2buffer_str(ldns_buffer* output, |
435
|
|
|
|
|
|
|
size_t amount, const uint8_t* characters) |
436
|
|
|
|
|
|
|
{ |
437
|
|
|
|
|
|
|
uint8_t ch; |
438
|
143
|
100
|
|
|
|
|
while (amount > 0) { |
439
|
141
|
|
|
|
|
|
ch = *characters++; |
440
|
141
|
50
|
|
|
|
|
if (isprint((int)ch) || ch == '\t') { |
|
|
0
|
|
|
|
|
|
441
|
282
|
50
|
|
|
|
|
if (ch == '\"' || ch == '\\') |
|
|
50
|
|
|
|
|
|
442
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\\%c", ch); |
443
|
|
|
|
|
|
|
else |
444
|
141
|
|
|
|
|
|
ldns_buffer_printf(output, "%c", ch); |
445
|
|
|
|
|
|
|
} else { |
446
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\\%03u", |
447
|
|
|
|
|
|
|
(unsigned)(uint8_t) ch); |
448
|
|
|
|
|
|
|
} |
449
|
141
|
|
|
|
|
|
amount--; |
450
|
|
|
|
|
|
|
} |
451
|
2
|
|
|
|
|
|
} |
452
|
|
|
|
|
|
|
|
453
|
|
|
|
|
|
|
ldns_status |
454
|
2
|
|
|
|
|
|
ldns_rdf2buffer_str_str(ldns_buffer *output, const ldns_rdf *rdf) |
455
|
|
|
|
|
|
|
{ |
456
|
2
|
50
|
|
|
|
|
if(ldns_rdf_size(rdf) < 1) { |
457
|
0
|
|
|
|
|
|
return LDNS_STATUS_WIRE_RDATA_ERR; |
458
|
|
|
|
|
|
|
} |
459
|
2
|
50
|
|
|
|
|
if((int)ldns_rdf_size(rdf) < (int)ldns_rdf_data(rdf)[0] + 1) { |
460
|
0
|
|
|
|
|
|
return LDNS_STATUS_WIRE_RDATA_ERR; |
461
|
|
|
|
|
|
|
} |
462
|
2
|
|
|
|
|
|
ldns_buffer_printf(output, "\""); |
463
|
2
|
|
|
|
|
|
ldns_characters2buffer_str(output, |
464
|
2
|
|
|
|
|
|
ldns_rdf_data(rdf)[0], ldns_rdf_data(rdf) + 1); |
465
|
2
|
|
|
|
|
|
ldns_buffer_printf(output, "\""); |
466
|
2
|
|
|
|
|
|
return ldns_buffer_status(output); |
467
|
|
|
|
|
|
|
} |
468
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
ldns_status |
470
|
0
|
|
|
|
|
|
ldns_rdf2buffer_str_b64(ldns_buffer *output, const ldns_rdf *rdf) |
471
|
|
|
|
|
|
|
{ |
472
|
0
|
|
|
|
|
|
size_t size = ldns_b64_ntop_calculate_size(ldns_rdf_size(rdf)); |
473
|
0
|
|
|
|
|
|
char *b64 = LDNS_XMALLOC(char, size); |
474
|
0
|
0
|
|
|
|
|
if(!b64) return LDNS_STATUS_MEM_ERR; |
475
|
0
|
0
|
|
|
|
|
if (ldns_b64_ntop(ldns_rdf_data(rdf), ldns_rdf_size(rdf), b64, size)) { |
476
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%s", b64); |
477
|
|
|
|
|
|
|
} |
478
|
0
|
|
|
|
|
|
LDNS_FREE(b64); |
479
|
0
|
|
|
|
|
|
return ldns_buffer_status(output); |
480
|
|
|
|
|
|
|
} |
481
|
|
|
|
|
|
|
|
482
|
|
|
|
|
|
|
ldns_status |
483
|
1
|
|
|
|
|
|
ldns_rdf2buffer_str_b32_ext(ldns_buffer *output, const ldns_rdf *rdf) |
484
|
|
|
|
|
|
|
{ |
485
|
|
|
|
|
|
|
size_t size; |
486
|
|
|
|
|
|
|
char *b32; |
487
|
1
|
50
|
|
|
|
|
if(ldns_rdf_size(rdf) == 0) |
488
|
0
|
|
|
|
|
|
return LDNS_STATUS_OK; |
489
|
|
|
|
|
|
|
/* remove -1 for the b32-hash-len octet */ |
490
|
1
|
|
|
|
|
|
size = ldns_b32_ntop_calculate_size(ldns_rdf_size(rdf) - 1); |
491
|
|
|
|
|
|
|
/* add one for the end nul for the string */ |
492
|
1
|
|
|
|
|
|
b32 = LDNS_XMALLOC(char, size + 1); |
493
|
1
|
50
|
|
|
|
|
if(!b32) return LDNS_STATUS_MEM_ERR; |
494
|
1
|
|
|
|
|
|
size = (size_t) ldns_b32_ntop_extended_hex(ldns_rdf_data(rdf) + 1, |
495
|
1
|
|
|
|
|
|
ldns_rdf_size(rdf) - 1, b32, size+1); |
496
|
1
|
50
|
|
|
|
|
if (size > 0) { |
497
|
1
|
|
|
|
|
|
ldns_buffer_printf(output, "%s", b32); |
498
|
|
|
|
|
|
|
} |
499
|
1
|
|
|
|
|
|
LDNS_FREE(b32); |
500
|
1
|
|
|
|
|
|
return ldns_buffer_status(output); |
501
|
|
|
|
|
|
|
} |
502
|
|
|
|
|
|
|
|
503
|
|
|
|
|
|
|
ldns_status |
504
|
12
|
|
|
|
|
|
ldns_rdf2buffer_str_hex(ldns_buffer *output, const ldns_rdf *rdf) |
505
|
|
|
|
|
|
|
{ |
506
|
|
|
|
|
|
|
size_t i; |
507
|
380
|
100
|
|
|
|
|
for (i = 0; i < ldns_rdf_size(rdf); i++) { |
508
|
368
|
|
|
|
|
|
ldns_buffer_printf(output, "%02x", ldns_rdf_data(rdf)[i]); |
509
|
|
|
|
|
|
|
} |
510
|
|
|
|
|
|
|
|
511
|
12
|
|
|
|
|
|
return ldns_buffer_status(output); |
512
|
|
|
|
|
|
|
} |
513
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
static ldns_status |
515
|
5
|
|
|
|
|
|
ldns_rdf2buffer_str_type_fmt(ldns_buffer *output, |
516
|
|
|
|
|
|
|
const ldns_output_format* fmt, const ldns_rdf *rdf) |
517
|
|
|
|
|
|
|
{ |
518
|
5
|
|
|
|
|
|
uint16_t data = ldns_read_uint16(ldns_rdf_data(rdf)); |
519
|
|
|
|
|
|
|
|
520
|
10
|
|
|
|
|
|
if (! ldns_output_format_covers_type(fmt, data) && |
521
|
10
|
50
|
|
|
|
|
ldns_rr_descript(data) && |
522
|
5
|
|
|
|
|
|
ldns_rr_descript(data)->_name) { |
523
|
|
|
|
|
|
|
|
524
|
5
|
|
|
|
|
|
ldns_buffer_printf(output, "%s",ldns_rr_descript(data)->_name); |
525
|
|
|
|
|
|
|
} else { |
526
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "TYPE%u", data); |
527
|
|
|
|
|
|
|
} |
528
|
5
|
|
|
|
|
|
return ldns_buffer_status(output); |
529
|
|
|
|
|
|
|
} |
530
|
|
|
|
|
|
|
|
531
|
|
|
|
|
|
|
ldns_status |
532
|
0
|
|
|
|
|
|
ldns_rdf2buffer_str_type(ldns_buffer *output, const ldns_rdf *rdf) |
533
|
|
|
|
|
|
|
{ |
534
|
0
|
|
|
|
|
|
return ldns_rdf2buffer_str_type_fmt(output, |
535
|
|
|
|
|
|
|
ldns_output_format_default, rdf); |
536
|
|
|
|
|
|
|
} |
537
|
|
|
|
|
|
|
|
538
|
|
|
|
|
|
|
ldns_status |
539
|
0
|
|
|
|
|
|
ldns_rdf2buffer_str_class(ldns_buffer *output, const ldns_rdf *rdf) |
540
|
|
|
|
|
|
|
{ |
541
|
0
|
|
|
|
|
|
uint16_t data = ldns_read_uint16(ldns_rdf_data(rdf)); |
542
|
|
|
|
|
|
|
ldns_lookup_table *lt; |
543
|
|
|
|
|
|
|
|
544
|
0
|
|
|
|
|
|
lt = ldns_lookup_by_id(ldns_rr_classes, (int) data); |
545
|
0
|
0
|
|
|
|
|
if (lt) { |
546
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\t%s", lt->name); |
547
|
|
|
|
|
|
|
} else { |
548
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\tCLASS%d", data); |
549
|
|
|
|
|
|
|
} |
550
|
0
|
|
|
|
|
|
return ldns_buffer_status(output); |
551
|
|
|
|
|
|
|
} |
552
|
|
|
|
|
|
|
|
553
|
|
|
|
|
|
|
ldns_status |
554
|
0
|
|
|
|
|
|
ldns_rdf2buffer_str_cert_alg(ldns_buffer *output, const ldns_rdf *rdf) |
555
|
|
|
|
|
|
|
{ |
556
|
0
|
|
|
|
|
|
uint16_t data = ldns_read_uint16(ldns_rdf_data(rdf)); |
557
|
|
|
|
|
|
|
ldns_lookup_table *lt; |
558
|
0
|
|
|
|
|
|
lt = ldns_lookup_by_id(ldns_cert_algorithms, (int) data); |
559
|
0
|
0
|
|
|
|
|
if (lt) { |
560
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%s", lt->name); |
561
|
|
|
|
|
|
|
} else { |
562
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%d", data); |
563
|
|
|
|
|
|
|
} |
564
|
0
|
|
|
|
|
|
return ldns_buffer_status(output); |
565
|
|
|
|
|
|
|
} |
566
|
|
|
|
|
|
|
|
567
|
|
|
|
|
|
|
ldns_status |
568
|
0
|
|
|
|
|
|
ldns_rdf2buffer_str_alg(ldns_buffer *output, const ldns_rdf *rdf) |
569
|
|
|
|
|
|
|
{ |
570
|
0
|
|
|
|
|
|
return ldns_rdf2buffer_str_int8(output, rdf); |
571
|
|
|
|
|
|
|
} |
572
|
|
|
|
|
|
|
|
573
|
|
|
|
|
|
|
static void |
574
|
0
|
|
|
|
|
|
loc_cm_print(ldns_buffer *output, uint8_t mantissa, uint8_t exponent) |
575
|
|
|
|
|
|
|
{ |
576
|
|
|
|
|
|
|
uint8_t i; |
577
|
|
|
|
|
|
|
/* is it 0. ? */ |
578
|
0
|
0
|
|
|
|
|
if(exponent < 2) { |
579
|
0
|
0
|
|
|
|
|
if(exponent == 1) |
580
|
0
|
|
|
|
|
|
mantissa *= 10; |
581
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "0.%02ld", (long)mantissa); |
582
|
0
|
|
|
|
|
|
return; |
583
|
|
|
|
|
|
|
} |
584
|
|
|
|
|
|
|
/* always */ |
585
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%d", (int)mantissa); |
586
|
0
|
0
|
|
|
|
|
for(i=0; i
|
587
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "0"); |
588
|
|
|
|
|
|
|
} |
589
|
|
|
|
|
|
|
|
590
|
|
|
|
|
|
|
ldns_status |
591
|
147
|
|
|
|
|
|
ldns_rr_type2buffer_str(ldns_buffer *output, const ldns_rr_type type) |
592
|
|
|
|
|
|
|
{ |
593
|
|
|
|
|
|
|
const ldns_rr_descriptor *descriptor; |
594
|
|
|
|
|
|
|
|
595
|
147
|
|
|
|
|
|
descriptor = ldns_rr_descript(type); |
596
|
|
|
|
|
|
|
|
597
|
147
|
|
|
|
|
|
switch (type) { |
598
|
|
|
|
|
|
|
case LDNS_RR_TYPE_IXFR: |
599
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "IXFR"); |
600
|
0
|
|
|
|
|
|
break; |
601
|
|
|
|
|
|
|
case LDNS_RR_TYPE_AXFR: |
602
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "AXFR"); |
603
|
0
|
|
|
|
|
|
break; |
604
|
|
|
|
|
|
|
case LDNS_RR_TYPE_MAILA: |
605
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "MAILA"); |
606
|
0
|
|
|
|
|
|
break; |
607
|
|
|
|
|
|
|
case LDNS_RR_TYPE_MAILB: |
608
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "MAILB"); |
609
|
0
|
|
|
|
|
|
break; |
610
|
|
|
|
|
|
|
case LDNS_RR_TYPE_ANY: |
611
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "ANY"); |
612
|
0
|
|
|
|
|
|
break; |
613
|
|
|
|
|
|
|
default: |
614
|
147
|
50
|
|
|
|
|
if (descriptor && descriptor->_name) { |
|
|
50
|
|
|
|
|
|
615
|
147
|
|
|
|
|
|
ldns_buffer_printf(output, "%s", descriptor->_name); |
616
|
|
|
|
|
|
|
} else { |
617
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "TYPE%u", type); |
618
|
|
|
|
|
|
|
} |
619
|
|
|
|
|
|
|
} |
620
|
147
|
|
|
|
|
|
return ldns_buffer_status(output); |
621
|
|
|
|
|
|
|
} |
622
|
|
|
|
|
|
|
|
623
|
|
|
|
|
|
|
char * |
624
|
134
|
|
|
|
|
|
ldns_rr_type2str(const ldns_rr_type type) |
625
|
|
|
|
|
|
|
{ |
626
|
|
|
|
|
|
|
char *str; |
627
|
|
|
|
|
|
|
ldns_buffer *buf; |
628
|
|
|
|
|
|
|
|
629
|
134
|
|
|
|
|
|
buf = ldns_buffer_new(10); |
630
|
134
|
50
|
|
|
|
|
if (!buf) { |
631
|
0
|
|
|
|
|
|
return NULL; |
632
|
|
|
|
|
|
|
} |
633
|
|
|
|
|
|
|
|
634
|
134
|
|
|
|
|
|
str = NULL; |
635
|
134
|
50
|
|
|
|
|
if (ldns_rr_type2buffer_str(buf, type) == LDNS_STATUS_OK) { |
636
|
134
|
|
|
|
|
|
str = ldns_buffer_export2str(buf); |
637
|
|
|
|
|
|
|
} |
638
|
|
|
|
|
|
|
|
639
|
134
|
|
|
|
|
|
ldns_buffer_free(buf); |
640
|
134
|
|
|
|
|
|
return str; |
641
|
|
|
|
|
|
|
} |
642
|
|
|
|
|
|
|
|
643
|
|
|
|
|
|
|
|
644
|
|
|
|
|
|
|
ldns_status |
645
|
16
|
|
|
|
|
|
ldns_rr_class2buffer_str(ldns_buffer *output, |
646
|
|
|
|
|
|
|
const ldns_rr_class klass) |
647
|
|
|
|
|
|
|
{ |
648
|
|
|
|
|
|
|
ldns_lookup_table *lt; |
649
|
|
|
|
|
|
|
|
650
|
16
|
|
|
|
|
|
lt = ldns_lookup_by_id(ldns_rr_classes, klass); |
651
|
16
|
50
|
|
|
|
|
if (lt) { |
652
|
16
|
|
|
|
|
|
ldns_buffer_printf(output, "%s", lt->name); |
653
|
|
|
|
|
|
|
} else { |
654
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "CLASS%d", klass); |
655
|
|
|
|
|
|
|
} |
656
|
16
|
|
|
|
|
|
return ldns_buffer_status(output); |
657
|
|
|
|
|
|
|
} |
658
|
|
|
|
|
|
|
|
659
|
|
|
|
|
|
|
char * |
660
|
3
|
|
|
|
|
|
ldns_rr_class2str(const ldns_rr_class klass) |
661
|
|
|
|
|
|
|
{ |
662
|
|
|
|
|
|
|
ldns_buffer *buf; |
663
|
|
|
|
|
|
|
char *str; |
664
|
|
|
|
|
|
|
|
665
|
3
|
|
|
|
|
|
buf = ldns_buffer_new(10); |
666
|
3
|
50
|
|
|
|
|
if (!buf) { |
667
|
0
|
|
|
|
|
|
return NULL; |
668
|
|
|
|
|
|
|
} |
669
|
|
|
|
|
|
|
|
670
|
3
|
|
|
|
|
|
str = NULL; |
671
|
3
|
50
|
|
|
|
|
if (ldns_rr_class2buffer_str(buf, klass) == LDNS_STATUS_OK) { |
672
|
3
|
|
|
|
|
|
str = ldns_buffer_export2str(buf); |
673
|
|
|
|
|
|
|
} |
674
|
3
|
|
|
|
|
|
ldns_buffer_free(buf); |
675
|
3
|
|
|
|
|
|
return str; |
676
|
|
|
|
|
|
|
} |
677
|
|
|
|
|
|
|
|
678
|
|
|
|
|
|
|
ldns_status |
679
|
0
|
|
|
|
|
|
ldns_rdf2buffer_str_loc(ldns_buffer *output, const ldns_rdf *rdf) |
680
|
|
|
|
|
|
|
{ |
681
|
|
|
|
|
|
|
/* we could do checking (ie degrees < 90 etc)? */ |
682
|
|
|
|
|
|
|
uint8_t version; |
683
|
|
|
|
|
|
|
uint8_t size; |
684
|
|
|
|
|
|
|
uint8_t horizontal_precision; |
685
|
|
|
|
|
|
|
uint8_t vertical_precision; |
686
|
|
|
|
|
|
|
uint32_t longitude; |
687
|
|
|
|
|
|
|
uint32_t latitude; |
688
|
|
|
|
|
|
|
uint32_t altitude; |
689
|
|
|
|
|
|
|
char northerness; |
690
|
|
|
|
|
|
|
char easterness; |
691
|
|
|
|
|
|
|
uint32_t h; |
692
|
|
|
|
|
|
|
uint32_t m; |
693
|
|
|
|
|
|
|
double s; |
694
|
|
|
|
|
|
|
|
695
|
0
|
|
|
|
|
|
uint32_t equator = (uint32_t) ldns_power(2, 31); |
696
|
|
|
|
|
|
|
|
697
|
0
|
0
|
|
|
|
|
if(ldns_rdf_size(rdf) < 1) { |
698
|
0
|
|
|
|
|
|
return LDNS_STATUS_WIRE_RDATA_ERR; |
699
|
|
|
|
|
|
|
} |
700
|
0
|
|
|
|
|
|
version = ldns_rdf_data(rdf)[0]; |
701
|
0
|
0
|
|
|
|
|
if (version == 0) { |
702
|
0
|
0
|
|
|
|
|
if(ldns_rdf_size(rdf) < 16) { |
703
|
0
|
|
|
|
|
|
return LDNS_STATUS_WIRE_RDATA_ERR; |
704
|
|
|
|
|
|
|
} |
705
|
0
|
|
|
|
|
|
size = ldns_rdf_data(rdf)[1]; |
706
|
0
|
|
|
|
|
|
horizontal_precision = ldns_rdf_data(rdf)[2]; |
707
|
0
|
|
|
|
|
|
vertical_precision = ldns_rdf_data(rdf)[3]; |
708
|
|
|
|
|
|
|
|
709
|
0
|
|
|
|
|
|
latitude = ldns_read_uint32(&ldns_rdf_data(rdf)[4]); |
710
|
0
|
|
|
|
|
|
longitude = ldns_read_uint32(&ldns_rdf_data(rdf)[8]); |
711
|
0
|
|
|
|
|
|
altitude = ldns_read_uint32(&ldns_rdf_data(rdf)[12]); |
712
|
|
|
|
|
|
|
|
713
|
0
|
0
|
|
|
|
|
if (latitude > equator) { |
714
|
0
|
|
|
|
|
|
northerness = 'N'; |
715
|
0
|
|
|
|
|
|
latitude = latitude - equator; |
716
|
|
|
|
|
|
|
} else { |
717
|
0
|
|
|
|
|
|
northerness = 'S'; |
718
|
0
|
|
|
|
|
|
latitude = equator - latitude; |
719
|
|
|
|
|
|
|
} |
720
|
0
|
|
|
|
|
|
h = latitude / (1000 * 60 * 60); |
721
|
0
|
|
|
|
|
|
latitude = latitude % (1000 * 60 * 60); |
722
|
0
|
|
|
|
|
|
m = latitude / (1000 * 60); |
723
|
0
|
|
|
|
|
|
latitude = latitude % (1000 * 60); |
724
|
0
|
|
|
|
|
|
s = (double) latitude / 1000.0; |
725
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%02u %02u %0.3f %c ", |
726
|
|
|
|
|
|
|
h, m, s, northerness); |
727
|
|
|
|
|
|
|
|
728
|
0
|
0
|
|
|
|
|
if (longitude > equator) { |
729
|
0
|
|
|
|
|
|
easterness = 'E'; |
730
|
0
|
|
|
|
|
|
longitude = longitude - equator; |
731
|
|
|
|
|
|
|
} else { |
732
|
0
|
|
|
|
|
|
easterness = 'W'; |
733
|
0
|
|
|
|
|
|
longitude = equator - longitude; |
734
|
|
|
|
|
|
|
} |
735
|
0
|
|
|
|
|
|
h = longitude / (1000 * 60 * 60); |
736
|
0
|
|
|
|
|
|
longitude = longitude % (1000 * 60 * 60); |
737
|
0
|
|
|
|
|
|
m = longitude / (1000 * 60); |
738
|
0
|
|
|
|
|
|
longitude = longitude % (1000 * 60); |
739
|
0
|
|
|
|
|
|
s = (double) longitude / (1000.0); |
740
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%02u %02u %0.3f %c ", |
741
|
|
|
|
|
|
|
h, m, s, easterness); |
742
|
|
|
|
|
|
|
|
743
|
|
|
|
|
|
|
|
744
|
0
|
|
|
|
|
|
s = ((double) altitude) / 100; |
745
|
0
|
|
|
|
|
|
s -= 100000; |
746
|
|
|
|
|
|
|
|
747
|
0
|
0
|
|
|
|
|
if(altitude%100 != 0) |
748
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%.2f", s); |
749
|
|
|
|
|
|
|
else |
750
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%.0f", s); |
751
|
|
|
|
|
|
|
|
752
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "m "); |
753
|
|
|
|
|
|
|
|
754
|
0
|
|
|
|
|
|
loc_cm_print(output, (size & 0xf0) >> 4, size & 0x0f); |
755
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "m "); |
756
|
|
|
|
|
|
|
|
757
|
0
|
|
|
|
|
|
loc_cm_print(output, (horizontal_precision & 0xf0) >> 4, |
758
|
|
|
|
|
|
|
horizontal_precision & 0x0f); |
759
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "m "); |
760
|
|
|
|
|
|
|
|
761
|
0
|
|
|
|
|
|
loc_cm_print(output, (vertical_precision & 0xf0) >> 4, |
762
|
|
|
|
|
|
|
vertical_precision & 0x0f); |
763
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "m"); |
764
|
|
|
|
|
|
|
|
765
|
0
|
|
|
|
|
|
return ldns_buffer_status(output); |
766
|
|
|
|
|
|
|
} else { |
767
|
0
|
|
|
|
|
|
return ldns_rdf2buffer_str_hex(output, rdf); |
768
|
|
|
|
|
|
|
} |
769
|
|
|
|
|
|
|
} |
770
|
|
|
|
|
|
|
|
771
|
|
|
|
|
|
|
ldns_status |
772
|
0
|
|
|
|
|
|
ldns_rdf2buffer_str_unknown(ldns_buffer *output, const ldns_rdf *rdf) |
773
|
|
|
|
|
|
|
{ |
774
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\\# %u ", ldns_rdf_size(rdf)); |
775
|
0
|
|
|
|
|
|
return ldns_rdf2buffer_str_hex(output, rdf); |
776
|
|
|
|
|
|
|
} |
777
|
|
|
|
|
|
|
|
778
|
|
|
|
|
|
|
ldns_status |
779
|
0
|
|
|
|
|
|
ldns_rdf2buffer_str_nsap(ldns_buffer *output, const ldns_rdf *rdf) |
780
|
|
|
|
|
|
|
{ |
781
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "0x"); |
782
|
0
|
|
|
|
|
|
return ldns_rdf2buffer_str_hex(output, rdf); |
783
|
|
|
|
|
|
|
} |
784
|
|
|
|
|
|
|
|
785
|
|
|
|
|
|
|
ldns_status |
786
|
0
|
|
|
|
|
|
ldns_rdf2buffer_str_atma(ldns_buffer *output, const ldns_rdf *rdf) |
787
|
|
|
|
|
|
|
{ |
788
|
0
|
|
|
|
|
|
return ldns_rdf2buffer_str_hex(output, rdf); |
789
|
|
|
|
|
|
|
} |
790
|
|
|
|
|
|
|
|
791
|
|
|
|
|
|
|
ldns_status |
792
|
0
|
|
|
|
|
|
ldns_rdf2buffer_str_wks(ldns_buffer *output, const ldns_rdf *rdf) |
793
|
|
|
|
|
|
|
{ |
794
|
|
|
|
|
|
|
/* protocol, followed by bitmap of services */ |
795
|
|
|
|
|
|
|
struct protoent *protocol; |
796
|
0
|
|
|
|
|
|
char *proto_name = NULL; |
797
|
|
|
|
|
|
|
uint8_t protocol_nr; |
798
|
|
|
|
|
|
|
struct servent *service; |
799
|
|
|
|
|
|
|
uint16_t current_service; |
800
|
|
|
|
|
|
|
|
801
|
0
|
0
|
|
|
|
|
if(ldns_rdf_size(rdf) < 1) { |
802
|
0
|
|
|
|
|
|
return LDNS_STATUS_WIRE_RDATA_ERR; |
803
|
|
|
|
|
|
|
} |
804
|
0
|
|
|
|
|
|
protocol_nr = ldns_rdf_data(rdf)[0]; |
805
|
0
|
|
|
|
|
|
protocol = getprotobynumber((int) protocol_nr); |
806
|
0
|
0
|
|
|
|
|
if (protocol && (protocol->p_name != NULL)) { |
|
|
0
|
|
|
|
|
|
807
|
0
|
|
|
|
|
|
proto_name = protocol->p_name; |
808
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%s ", protocol->p_name); |
809
|
|
|
|
|
|
|
} else { |
810
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%u ", protocol_nr); |
811
|
|
|
|
|
|
|
} |
812
|
|
|
|
|
|
|
|
813
|
|
|
|
|
|
|
#ifdef HAVE_ENDPROTOENT |
814
|
0
|
|
|
|
|
|
endprotoent(); |
815
|
|
|
|
|
|
|
#endif |
816
|
|
|
|
|
|
|
|
817
|
0
|
0
|
|
|
|
|
for (current_service = 0; |
818
|
0
|
|
|
|
|
|
current_service < (ldns_rdf_size(rdf)-1)*8; current_service++) { |
819
|
0
|
0
|
|
|
|
|
if (ldns_get_bit(&(ldns_rdf_data(rdf)[1]), current_service)) { |
820
|
0
|
|
|
|
|
|
service = getservbyport((int) htons(current_service), |
821
|
|
|
|
|
|
|
proto_name); |
822
|
0
|
0
|
|
|
|
|
if (service && service->s_name) { |
|
|
0
|
|
|
|
|
|
823
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%s ", service->s_name); |
824
|
|
|
|
|
|
|
} else { |
825
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%u ", current_service); |
826
|
|
|
|
|
|
|
} |
827
|
|
|
|
|
|
|
#ifdef HAVE_ENDSERVENT |
828
|
0
|
|
|
|
|
|
endservent(); |
829
|
|
|
|
|
|
|
#endif |
830
|
|
|
|
|
|
|
} |
831
|
|
|
|
|
|
|
} |
832
|
0
|
|
|
|
|
|
return ldns_buffer_status(output); |
833
|
|
|
|
|
|
|
} |
834
|
|
|
|
|
|
|
|
835
|
|
|
|
|
|
|
static ldns_status |
836
|
6
|
|
|
|
|
|
ldns_rdf2buffer_str_nsec_fmt(ldns_buffer *output, |
837
|
|
|
|
|
|
|
const ldns_output_format* fmt, const ldns_rdf *rdf) |
838
|
|
|
|
|
|
|
{ |
839
|
|
|
|
|
|
|
/* Note: this code is duplicated in higher.c in |
840
|
|
|
|
|
|
|
* ldns_nsec_type_check() function |
841
|
|
|
|
|
|
|
*/ |
842
|
|
|
|
|
|
|
uint8_t window_block_nr; |
843
|
|
|
|
|
|
|
uint8_t bitmap_length; |
844
|
|
|
|
|
|
|
uint16_t type; |
845
|
6
|
|
|
|
|
|
uint16_t pos = 0; |
846
|
|
|
|
|
|
|
uint16_t bit_pos; |
847
|
6
|
|
|
|
|
|
uint8_t *data = ldns_rdf_data(rdf); |
848
|
|
|
|
|
|
|
|
849
|
12
|
100
|
|
|
|
|
while((size_t)(pos + 2) < ldns_rdf_size(rdf)) { |
850
|
6
|
|
|
|
|
|
window_block_nr = data[pos]; |
851
|
6
|
|
|
|
|
|
bitmap_length = data[pos + 1]; |
852
|
6
|
|
|
|
|
|
pos += 2; |
853
|
6
|
50
|
|
|
|
|
if (ldns_rdf_size(rdf) < pos + bitmap_length) { |
854
|
0
|
|
|
|
|
|
return LDNS_STATUS_WIRE_RDATA_ERR; |
855
|
|
|
|
|
|
|
} |
856
|
326
|
100
|
|
|
|
|
for (bit_pos = 0; bit_pos < (bitmap_length) * 8; bit_pos++) { |
857
|
320
|
100
|
|
|
|
|
if (! ldns_get_bit(&data[pos], bit_pos)) { |
858
|
290
|
|
|
|
|
|
continue; |
859
|
|
|
|
|
|
|
} |
860
|
30
|
|
|
|
|
|
type = 256 * (uint16_t) window_block_nr + bit_pos; |
861
|
|
|
|
|
|
|
|
862
|
60
|
|
|
|
|
|
if (! ldns_output_format_covers_type(fmt, type) && |
863
|
60
|
50
|
|
|
|
|
ldns_rr_descript(type) && |
864
|
30
|
|
|
|
|
|
ldns_rr_descript(type)->_name){ |
865
|
|
|
|
|
|
|
|
866
|
30
|
|
|
|
|
|
ldns_buffer_printf(output, "%s ", |
867
|
30
|
|
|
|
|
|
ldns_rr_descript(type)->_name); |
868
|
|
|
|
|
|
|
} else { |
869
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "TYPE%u ", type); |
870
|
|
|
|
|
|
|
} |
871
|
|
|
|
|
|
|
} |
872
|
6
|
|
|
|
|
|
pos += (uint16_t) bitmap_length; |
873
|
|
|
|
|
|
|
} |
874
|
6
|
|
|
|
|
|
return ldns_buffer_status(output); |
875
|
|
|
|
|
|
|
} |
876
|
|
|
|
|
|
|
|
877
|
|
|
|
|
|
|
ldns_status |
878
|
0
|
|
|
|
|
|
ldns_rdf2buffer_str_nsec(ldns_buffer *output, const ldns_rdf *rdf) |
879
|
|
|
|
|
|
|
{ |
880
|
0
|
|
|
|
|
|
return ldns_rdf2buffer_str_nsec_fmt(output, |
881
|
|
|
|
|
|
|
ldns_output_format_default, rdf); |
882
|
|
|
|
|
|
|
} |
883
|
|
|
|
|
|
|
|
884
|
|
|
|
|
|
|
ldns_status |
885
|
0
|
|
|
|
|
|
ldns_rdf2buffer_str_nsec3_salt(ldns_buffer *output, const ldns_rdf *rdf) |
886
|
|
|
|
|
|
|
{ |
887
|
|
|
|
|
|
|
uint8_t salt_length; |
888
|
|
|
|
|
|
|
uint8_t salt_pos; |
889
|
|
|
|
|
|
|
|
890
|
0
|
|
|
|
|
|
uint8_t *data = ldns_rdf_data(rdf); |
891
|
|
|
|
|
|
|
|
892
|
0
|
0
|
|
|
|
|
if(ldns_rdf_size(rdf) < 1) { |
893
|
0
|
|
|
|
|
|
return LDNS_STATUS_WIRE_RDATA_ERR; |
894
|
|
|
|
|
|
|
} |
895
|
0
|
|
|
|
|
|
salt_length = data[0]; |
896
|
|
|
|
|
|
|
/* from now there are variable length entries so remember pos */ |
897
|
0
|
0
|
|
|
|
|
if (salt_length == 0 || ((size_t)salt_length)+1 > ldns_rdf_size(rdf)) { |
|
|
0
|
|
|
|
|
|
898
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "- "); |
899
|
|
|
|
|
|
|
} else { |
900
|
0
|
0
|
|
|
|
|
for (salt_pos = 0; salt_pos < salt_length; salt_pos++) { |
901
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%02x", data[1 + salt_pos]); |
902
|
|
|
|
|
|
|
} |
903
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, " "); |
904
|
|
|
|
|
|
|
} |
905
|
|
|
|
|
|
|
|
906
|
0
|
|
|
|
|
|
return ldns_buffer_status(output); |
907
|
|
|
|
|
|
|
} |
908
|
|
|
|
|
|
|
|
909
|
|
|
|
|
|
|
ldns_status |
910
|
0
|
|
|
|
|
|
ldns_rdf2buffer_str_period(ldns_buffer *output, const ldns_rdf *rdf) |
911
|
|
|
|
|
|
|
{ |
912
|
|
|
|
|
|
|
/* period is the number of seconds */ |
913
|
0
|
0
|
|
|
|
|
if (ldns_rdf_size(rdf) != 4) { |
914
|
0
|
|
|
|
|
|
return LDNS_STATUS_WIRE_RDATA_ERR; |
915
|
|
|
|
|
|
|
} |
916
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%u", ldns_read_uint32(ldns_rdf_data(rdf))); |
917
|
0
|
|
|
|
|
|
return ldns_buffer_status(output); |
918
|
|
|
|
|
|
|
} |
919
|
|
|
|
|
|
|
|
920
|
|
|
|
|
|
|
ldns_status |
921
|
0
|
|
|
|
|
|
ldns_rdf2buffer_str_tsigtime(ldns_buffer *output,const ldns_rdf *rdf) |
922
|
|
|
|
|
|
|
{ |
923
|
|
|
|
|
|
|
/* tsigtime is 48 bits network order unsigned integer */ |
924
|
0
|
|
|
|
|
|
uint64_t tsigtime = 0; |
925
|
0
|
|
|
|
|
|
uint8_t *data = ldns_rdf_data(rdf); |
926
|
|
|
|
|
|
|
uint64_t d0, d1, d2, d3, d4, d5; |
927
|
|
|
|
|
|
|
|
928
|
0
|
0
|
|
|
|
|
if (ldns_rdf_size(rdf) < 6) { |
929
|
0
|
|
|
|
|
|
return LDNS_STATUS_WIRE_RDATA_ERR; |
930
|
|
|
|
|
|
|
} |
931
|
0
|
|
|
|
|
|
d0 = data[0]; /* cast to uint64 for shift operations */ |
932
|
0
|
|
|
|
|
|
d1 = data[1]; |
933
|
0
|
|
|
|
|
|
d2 = data[2]; |
934
|
0
|
|
|
|
|
|
d3 = data[3]; |
935
|
0
|
|
|
|
|
|
d4 = data[4]; |
936
|
0
|
|
|
|
|
|
d5 = data[5]; |
937
|
0
|
|
|
|
|
|
tsigtime = (d0<<40) | (d1<<32) | (d2<<24) | (d3<<16) | (d4<<8) | d5; |
938
|
|
|
|
|
|
|
|
939
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%llu ", (long long)tsigtime); |
940
|
|
|
|
|
|
|
|
941
|
0
|
|
|
|
|
|
return ldns_buffer_status(output); |
942
|
|
|
|
|
|
|
} |
943
|
|
|
|
|
|
|
|
944
|
|
|
|
|
|
|
ldns_status |
945
|
0
|
|
|
|
|
|
ldns_rdf2buffer_str_apl(ldns_buffer *output, const ldns_rdf *rdf) |
946
|
|
|
|
|
|
|
{ |
947
|
0
|
|
|
|
|
|
uint8_t *data = ldns_rdf_data(rdf); |
948
|
|
|
|
|
|
|
uint16_t address_family; |
949
|
|
|
|
|
|
|
uint8_t prefix; |
950
|
|
|
|
|
|
|
bool negation; |
951
|
|
|
|
|
|
|
uint8_t adf_length; |
952
|
|
|
|
|
|
|
size_t i; |
953
|
0
|
|
|
|
|
|
size_t pos = 0; |
954
|
|
|
|
|
|
|
|
955
|
0
|
0
|
|
|
|
|
while (pos < (unsigned int) ldns_rdf_size(rdf)) { |
956
|
0
|
0
|
|
|
|
|
if(pos + 3 >= (unsigned)ldns_rdf_size(rdf)) |
957
|
0
|
|
|
|
|
|
return LDNS_STATUS_WIRE_RDATA_ERR; |
958
|
0
|
|
|
|
|
|
address_family = ldns_read_uint16(&data[pos]); |
959
|
0
|
|
|
|
|
|
prefix = data[pos + 2]; |
960
|
0
|
|
|
|
|
|
negation = data[pos + 3] & LDNS_APL_NEGATION; |
961
|
0
|
|
|
|
|
|
adf_length = data[pos + 3] & LDNS_APL_MASK; |
962
|
0
|
0
|
|
|
|
|
if (address_family == LDNS_APL_IP4) { |
963
|
|
|
|
|
|
|
/* check if prefix < 32? */ |
964
|
0
|
0
|
|
|
|
|
if (negation) { |
965
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "!"); |
966
|
|
|
|
|
|
|
} |
967
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%u:", address_family); |
968
|
|
|
|
|
|
|
/* address is variable length 0 - 4 */ |
969
|
0
|
0
|
|
|
|
|
for (i = 0; i < 4; i++) { |
970
|
0
|
0
|
|
|
|
|
if (i > 0) { |
971
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "."); |
972
|
|
|
|
|
|
|
} |
973
|
0
|
0
|
|
|
|
|
if (i < (unsigned short) adf_length) { |
974
|
0
|
0
|
|
|
|
|
if(pos+i+4 >= ldns_rdf_size(rdf)) |
975
|
0
|
|
|
|
|
|
return LDNS_STATUS_WIRE_RDATA_ERR; |
976
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%d", |
977
|
0
|
|
|
|
|
|
data[pos + i + 4]); |
978
|
|
|
|
|
|
|
} else { |
979
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "0"); |
980
|
|
|
|
|
|
|
} |
981
|
|
|
|
|
|
|
} |
982
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "/%u ", prefix); |
983
|
0
|
0
|
|
|
|
|
} else if (address_family == LDNS_APL_IP6) { |
984
|
|
|
|
|
|
|
/* check if prefix < 128? */ |
985
|
0
|
0
|
|
|
|
|
if (negation) { |
986
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "!"); |
987
|
|
|
|
|
|
|
} |
988
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%u:", address_family); |
989
|
|
|
|
|
|
|
/* address is variable length 0 - 16 */ |
990
|
0
|
0
|
|
|
|
|
for (i = 0; i < 16; i++) { |
991
|
0
|
0
|
|
|
|
|
if (i % 2 == 0 && i > 0) { |
|
|
0
|
|
|
|
|
|
992
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, ":"); |
993
|
|
|
|
|
|
|
} |
994
|
0
|
0
|
|
|
|
|
if (i < (unsigned short) adf_length) { |
995
|
0
|
0
|
|
|
|
|
if(pos+i+4 >= ldns_rdf_size(rdf)) |
996
|
0
|
|
|
|
|
|
return LDNS_STATUS_WIRE_RDATA_ERR; |
997
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%02x", |
998
|
0
|
|
|
|
|
|
data[pos + i + 4]); |
999
|
|
|
|
|
|
|
} else { |
1000
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "00"); |
1001
|
|
|
|
|
|
|
} |
1002
|
|
|
|
|
|
|
} |
1003
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "/%u ", prefix); |
1004
|
|
|
|
|
|
|
|
1005
|
|
|
|
|
|
|
} else { |
1006
|
|
|
|
|
|
|
/* unknown address family */ |
1007
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, |
1008
|
|
|
|
|
|
|
"Unknown address family: %u data: ", |
1009
|
|
|
|
|
|
|
address_family); |
1010
|
0
|
0
|
|
|
|
|
for (i = 1; i < (unsigned short) (4 + adf_length); i++) { |
1011
|
0
|
0
|
|
|
|
|
if(pos+i >= ldns_rdf_size(rdf)) |
1012
|
0
|
|
|
|
|
|
return LDNS_STATUS_WIRE_RDATA_ERR; |
1013
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%02x", data[i]); |
1014
|
|
|
|
|
|
|
} |
1015
|
|
|
|
|
|
|
} |
1016
|
0
|
|
|
|
|
|
pos += 4 + adf_length; |
1017
|
|
|
|
|
|
|
} |
1018
|
0
|
|
|
|
|
|
return ldns_buffer_status(output); |
1019
|
|
|
|
|
|
|
} |
1020
|
|
|
|
|
|
|
|
1021
|
|
|
|
|
|
|
ldns_status |
1022
|
0
|
|
|
|
|
|
ldns_rdf2buffer_str_int16_data(ldns_buffer *output, const ldns_rdf *rdf) |
1023
|
|
|
|
|
|
|
{ |
1024
|
|
|
|
|
|
|
size_t size; |
1025
|
|
|
|
|
|
|
char *b64; |
1026
|
0
|
0
|
|
|
|
|
if (ldns_rdf_size(rdf) < 2) { |
1027
|
0
|
|
|
|
|
|
return LDNS_STATUS_WIRE_RDATA_ERR; |
1028
|
|
|
|
|
|
|
} |
1029
|
|
|
|
|
|
|
/* Subtract the size (2) of the number that specifies the length */ |
1030
|
0
|
|
|
|
|
|
size = ldns_b64_ntop_calculate_size(ldns_rdf_size(rdf) - 2); |
1031
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%u ", ldns_rdf_size(rdf) - 2); |
1032
|
0
|
0
|
|
|
|
|
if (ldns_rdf_size(rdf) > 2) { |
1033
|
0
|
|
|
|
|
|
b64 = LDNS_XMALLOC(char, size); |
1034
|
0
|
0
|
|
|
|
|
if(!b64) |
1035
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
1036
|
|
|
|
|
|
|
|
1037
|
0
|
|
|
|
|
|
if (ldns_rdf_size(rdf) > 2 && |
1038
|
0
|
|
|
|
|
|
ldns_b64_ntop(ldns_rdf_data(rdf) + 2, |
1039
|
0
|
|
|
|
|
|
ldns_rdf_size(rdf) - 2, |
1040
|
|
|
|
|
|
|
b64, size)) { |
1041
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%s", b64); |
1042
|
|
|
|
|
|
|
} |
1043
|
0
|
|
|
|
|
|
LDNS_FREE(b64); |
1044
|
|
|
|
|
|
|
} |
1045
|
0
|
|
|
|
|
|
return ldns_buffer_status(output); |
1046
|
|
|
|
|
|
|
} |
1047
|
|
|
|
|
|
|
|
1048
|
|
|
|
|
|
|
ldns_status |
1049
|
0
|
|
|
|
|
|
ldns_rdf2buffer_str_ipseckey(ldns_buffer *output, const ldns_rdf *rdf) |
1050
|
|
|
|
|
|
|
{ |
1051
|
|
|
|
|
|
|
/* wire format from |
1052
|
|
|
|
|
|
|
http://www.ietf.org/internet-drafts/draft-ietf-ipseckey-rr-12.txt |
1053
|
|
|
|
|
|
|
*/ |
1054
|
0
|
|
|
|
|
|
uint8_t *data = ldns_rdf_data(rdf); |
1055
|
|
|
|
|
|
|
uint8_t precedence; |
1056
|
|
|
|
|
|
|
uint8_t gateway_type; |
1057
|
|
|
|
|
|
|
uint8_t algorithm; |
1058
|
|
|
|
|
|
|
|
1059
|
0
|
|
|
|
|
|
ldns_rdf *gateway = NULL; |
1060
|
|
|
|
|
|
|
uint8_t *gateway_data; |
1061
|
|
|
|
|
|
|
|
1062
|
|
|
|
|
|
|
size_t public_key_size; |
1063
|
|
|
|
|
|
|
uint8_t *public_key_data; |
1064
|
|
|
|
|
|
|
ldns_rdf *public_key; |
1065
|
|
|
|
|
|
|
|
1066
|
0
|
|
|
|
|
|
size_t offset = 0; |
1067
|
|
|
|
|
|
|
ldns_status status; |
1068
|
|
|
|
|
|
|
|
1069
|
0
|
0
|
|
|
|
|
if (ldns_rdf_size(rdf) < 3) { |
1070
|
0
|
|
|
|
|
|
return LDNS_STATUS_WIRE_RDATA_ERR; |
1071
|
|
|
|
|
|
|
} |
1072
|
0
|
|
|
|
|
|
precedence = data[0]; |
1073
|
0
|
|
|
|
|
|
gateway_type = data[1]; |
1074
|
0
|
|
|
|
|
|
algorithm = data[2]; |
1075
|
0
|
|
|
|
|
|
offset = 3; |
1076
|
|
|
|
|
|
|
|
1077
|
0
|
|
|
|
|
|
switch (gateway_type) { |
1078
|
|
|
|
|
|
|
case 0: |
1079
|
|
|
|
|
|
|
/* no gateway */ |
1080
|
0
|
|
|
|
|
|
break; |
1081
|
|
|
|
|
|
|
case 1: |
1082
|
0
|
|
|
|
|
|
gateway_data = LDNS_XMALLOC(uint8_t, LDNS_IP4ADDRLEN); |
1083
|
0
|
0
|
|
|
|
|
if(!gateway_data) |
1084
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
1085
|
0
|
0
|
|
|
|
|
if (ldns_rdf_size(rdf) < offset + LDNS_IP4ADDRLEN) { |
1086
|
0
|
|
|
|
|
|
return LDNS_STATUS_ERR; |
1087
|
|
|
|
|
|
|
} |
1088
|
0
|
|
|
|
|
|
memcpy(gateway_data, &data[offset], LDNS_IP4ADDRLEN); |
1089
|
0
|
|
|
|
|
|
gateway = ldns_rdf_new(LDNS_RDF_TYPE_A, |
1090
|
|
|
|
|
|
|
LDNS_IP4ADDRLEN , gateway_data); |
1091
|
0
|
|
|
|
|
|
offset += LDNS_IP4ADDRLEN; |
1092
|
0
|
0
|
|
|
|
|
if(!gateway) { |
1093
|
0
|
|
|
|
|
|
LDNS_FREE(gateway_data); |
1094
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
1095
|
|
|
|
|
|
|
} |
1096
|
0
|
|
|
|
|
|
break; |
1097
|
|
|
|
|
|
|
case 2: |
1098
|
0
|
|
|
|
|
|
gateway_data = LDNS_XMALLOC(uint8_t, LDNS_IP6ADDRLEN); |
1099
|
0
|
0
|
|
|
|
|
if(!gateway_data) |
1100
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
1101
|
0
|
0
|
|
|
|
|
if (ldns_rdf_size(rdf) < offset + LDNS_IP6ADDRLEN) { |
1102
|
0
|
|
|
|
|
|
return LDNS_STATUS_ERR; |
1103
|
|
|
|
|
|
|
} |
1104
|
0
|
|
|
|
|
|
memcpy(gateway_data, &data[offset], LDNS_IP6ADDRLEN); |
1105
|
0
|
|
|
|
|
|
offset += LDNS_IP6ADDRLEN; |
1106
|
0
|
|
|
|
|
|
gateway = |
1107
|
0
|
|
|
|
|
|
ldns_rdf_new(LDNS_RDF_TYPE_AAAA, |
1108
|
|
|
|
|
|
|
LDNS_IP6ADDRLEN, gateway_data); |
1109
|
0
|
0
|
|
|
|
|
if(!gateway) { |
1110
|
0
|
|
|
|
|
|
LDNS_FREE(gateway_data); |
1111
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
1112
|
|
|
|
|
|
|
} |
1113
|
0
|
|
|
|
|
|
break; |
1114
|
|
|
|
|
|
|
case 3: |
1115
|
0
|
|
|
|
|
|
status = ldns_wire2dname(&gateway, data, |
1116
|
|
|
|
|
|
|
ldns_rdf_size(rdf), &offset); |
1117
|
0
|
0
|
|
|
|
|
if(status != LDNS_STATUS_OK) |
1118
|
0
|
|
|
|
|
|
return status; |
1119
|
0
|
|
|
|
|
|
break; |
1120
|
|
|
|
|
|
|
default: |
1121
|
|
|
|
|
|
|
/* error? */ |
1122
|
0
|
|
|
|
|
|
break; |
1123
|
|
|
|
|
|
|
} |
1124
|
|
|
|
|
|
|
|
1125
|
0
|
0
|
|
|
|
|
if (ldns_rdf_size(rdf) <= offset) { |
1126
|
0
|
|
|
|
|
|
return LDNS_STATUS_ERR; |
1127
|
|
|
|
|
|
|
} |
1128
|
0
|
|
|
|
|
|
public_key_size = ldns_rdf_size(rdf) - offset; |
1129
|
0
|
|
|
|
|
|
public_key_data = LDNS_XMALLOC(uint8_t, public_key_size); |
1130
|
0
|
0
|
|
|
|
|
if(!public_key_data) { |
1131
|
0
|
|
|
|
|
|
ldns_rdf_free(gateway); |
1132
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
1133
|
|
|
|
|
|
|
} |
1134
|
0
|
|
|
|
|
|
memcpy(public_key_data, &data[offset], public_key_size); |
1135
|
0
|
|
|
|
|
|
public_key = ldns_rdf_new(LDNS_RDF_TYPE_B64, |
1136
|
|
|
|
|
|
|
public_key_size, public_key_data); |
1137
|
0
|
0
|
|
|
|
|
if(!public_key) { |
1138
|
0
|
|
|
|
|
|
LDNS_FREE(public_key_data); |
1139
|
0
|
|
|
|
|
|
ldns_rdf_free(gateway); |
1140
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
1141
|
|
|
|
|
|
|
} |
1142
|
|
|
|
|
|
|
|
1143
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%u %u %u ", precedence, gateway_type, algorithm); |
1144
|
0
|
0
|
|
|
|
|
if (gateway) |
1145
|
0
|
|
|
|
|
|
(void) ldns_rdf2buffer_str(output, gateway); |
1146
|
|
|
|
|
|
|
else |
1147
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "."); |
1148
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, " "); |
1149
|
0
|
|
|
|
|
|
(void) ldns_rdf2buffer_str(output, public_key); |
1150
|
|
|
|
|
|
|
|
1151
|
0
|
|
|
|
|
|
ldns_rdf_free(gateway); |
1152
|
0
|
|
|
|
|
|
ldns_rdf_free(public_key); |
1153
|
|
|
|
|
|
|
|
1154
|
0
|
|
|
|
|
|
return ldns_buffer_status(output); |
1155
|
|
|
|
|
|
|
} |
1156
|
|
|
|
|
|
|
|
1157
|
|
|
|
|
|
|
ldns_status |
1158
|
0
|
|
|
|
|
|
ldns_rdf2buffer_str_ilnp64(ldns_buffer *output, const ldns_rdf *rdf) |
1159
|
|
|
|
|
|
|
{ |
1160
|
0
|
0
|
|
|
|
|
if (ldns_rdf_size(rdf) != 8) { |
1161
|
0
|
|
|
|
|
|
return LDNS_STATUS_WIRE_RDATA_ERR; |
1162
|
|
|
|
|
|
|
} |
1163
|
0
|
|
|
|
|
|
ldns_buffer_printf(output,"%.4x:%.4x:%.4x:%.4x", |
1164
|
0
|
|
|
|
|
|
ldns_read_uint16(ldns_rdf_data(rdf)), |
1165
|
0
|
|
|
|
|
|
ldns_read_uint16(ldns_rdf_data(rdf)+2), |
1166
|
0
|
|
|
|
|
|
ldns_read_uint16(ldns_rdf_data(rdf)+4), |
1167
|
0
|
|
|
|
|
|
ldns_read_uint16(ldns_rdf_data(rdf)+6)); |
1168
|
0
|
|
|
|
|
|
return ldns_buffer_status(output); |
1169
|
|
|
|
|
|
|
} |
1170
|
|
|
|
|
|
|
|
1171
|
|
|
|
|
|
|
ldns_status |
1172
|
0
|
|
|
|
|
|
ldns_rdf2buffer_str_eui48(ldns_buffer *output, const ldns_rdf *rdf) |
1173
|
|
|
|
|
|
|
{ |
1174
|
0
|
0
|
|
|
|
|
if (ldns_rdf_size(rdf) != 6) { |
1175
|
0
|
|
|
|
|
|
return LDNS_STATUS_WIRE_RDATA_ERR; |
1176
|
|
|
|
|
|
|
} |
1177
|
0
|
|
|
|
|
|
ldns_buffer_printf(output,"%.2x-%.2x-%.2x-%.2x-%.2x-%.2x", |
1178
|
0
|
|
|
|
|
|
ldns_rdf_data(rdf)[0], ldns_rdf_data(rdf)[1], |
1179
|
0
|
|
|
|
|
|
ldns_rdf_data(rdf)[2], ldns_rdf_data(rdf)[3], |
1180
|
0
|
|
|
|
|
|
ldns_rdf_data(rdf)[4], ldns_rdf_data(rdf)[5]); |
1181
|
0
|
|
|
|
|
|
return ldns_buffer_status(output); |
1182
|
|
|
|
|
|
|
} |
1183
|
|
|
|
|
|
|
|
1184
|
|
|
|
|
|
|
ldns_status |
1185
|
0
|
|
|
|
|
|
ldns_rdf2buffer_str_eui64(ldns_buffer *output, const ldns_rdf *rdf) |
1186
|
|
|
|
|
|
|
{ |
1187
|
0
|
0
|
|
|
|
|
if (ldns_rdf_size(rdf) != 8) { |
1188
|
0
|
|
|
|
|
|
return LDNS_STATUS_WIRE_RDATA_ERR; |
1189
|
|
|
|
|
|
|
} |
1190
|
0
|
|
|
|
|
|
ldns_buffer_printf(output,"%.2x-%.2x-%.2x-%.2x-%.2x-%.2x-%.2x-%.2x", |
1191
|
0
|
|
|
|
|
|
ldns_rdf_data(rdf)[0], ldns_rdf_data(rdf)[1], |
1192
|
0
|
|
|
|
|
|
ldns_rdf_data(rdf)[2], ldns_rdf_data(rdf)[3], |
1193
|
0
|
|
|
|
|
|
ldns_rdf_data(rdf)[4], ldns_rdf_data(rdf)[5], |
1194
|
0
|
|
|
|
|
|
ldns_rdf_data(rdf)[6], ldns_rdf_data(rdf)[7]); |
1195
|
0
|
|
|
|
|
|
return ldns_buffer_status(output); |
1196
|
|
|
|
|
|
|
} |
1197
|
|
|
|
|
|
|
|
1198
|
|
|
|
|
|
|
ldns_status |
1199
|
0
|
|
|
|
|
|
ldns_rdf2buffer_str_tag(ldns_buffer *output, const ldns_rdf *rdf) |
1200
|
|
|
|
|
|
|
{ |
1201
|
|
|
|
|
|
|
size_t nchars; |
1202
|
|
|
|
|
|
|
const uint8_t* chars; |
1203
|
|
|
|
|
|
|
char ch; |
1204
|
0
|
0
|
|
|
|
|
if (ldns_rdf_size(rdf) < 2) { |
1205
|
0
|
|
|
|
|
|
return LDNS_STATUS_WIRE_RDATA_ERR; |
1206
|
|
|
|
|
|
|
} |
1207
|
0
|
|
|
|
|
|
nchars = ldns_rdf_data(rdf)[0]; |
1208
|
0
|
0
|
|
|
|
|
if (nchars >= ldns_rdf_size(rdf) || /* should be rdf_size - 1 */ |
|
|
0
|
|
|
|
|
|
1209
|
|
|
|
|
|
|
nchars < 1) { |
1210
|
0
|
|
|
|
|
|
return LDNS_STATUS_WIRE_RDATA_ERR; |
1211
|
|
|
|
|
|
|
} |
1212
|
0
|
|
|
|
|
|
chars = ldns_rdf_data(rdf) + 1; |
1213
|
0
|
0
|
|
|
|
|
while (nchars > 0) { |
1214
|
0
|
|
|
|
|
|
ch = (char)*chars++; |
1215
|
0
|
0
|
|
|
|
|
if (! isalnum(ch)) { |
1216
|
0
|
|
|
|
|
|
return LDNS_STATUS_WIRE_RDATA_ERR; |
1217
|
|
|
|
|
|
|
} |
1218
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%c", ch); |
1219
|
0
|
|
|
|
|
|
nchars--; |
1220
|
|
|
|
|
|
|
} |
1221
|
0
|
|
|
|
|
|
return ldns_buffer_status(output); |
1222
|
|
|
|
|
|
|
} |
1223
|
|
|
|
|
|
|
|
1224
|
|
|
|
|
|
|
ldns_status |
1225
|
0
|
|
|
|
|
|
ldns_rdf2buffer_str_long_str(ldns_buffer *output, const ldns_rdf *rdf) |
1226
|
|
|
|
|
|
|
{ |
1227
|
|
|
|
|
|
|
|
1228
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\""); |
1229
|
0
|
|
|
|
|
|
ldns_characters2buffer_str(output, |
1230
|
0
|
|
|
|
|
|
ldns_rdf_size(rdf), ldns_rdf_data(rdf)); |
1231
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\""); |
1232
|
0
|
|
|
|
|
|
return ldns_buffer_status(output); |
1233
|
|
|
|
|
|
|
} |
1234
|
|
|
|
|
|
|
|
1235
|
|
|
|
|
|
|
ldns_status |
1236
|
0
|
|
|
|
|
|
ldns_rdf2buffer_str_hip(ldns_buffer *output, const ldns_rdf *rdf) |
1237
|
|
|
|
|
|
|
{ |
1238
|
0
|
|
|
|
|
|
uint8_t *data = ldns_rdf_data(rdf); |
1239
|
0
|
|
|
|
|
|
size_t rdf_size = ldns_rdf_size(rdf); |
1240
|
|
|
|
|
|
|
uint8_t hit_size; |
1241
|
|
|
|
|
|
|
uint16_t pk_size; |
1242
|
|
|
|
|
|
|
int written; |
1243
|
|
|
|
|
|
|
|
1244
|
0
|
0
|
|
|
|
|
if (rdf_size < 6) { |
1245
|
0
|
|
|
|
|
|
return LDNS_STATUS_WIRE_RDATA_ERR; |
1246
|
|
|
|
|
|
|
} |
1247
|
0
|
0
|
|
|
|
|
if ((hit_size = data[0]) == 0 || |
|
|
0
|
|
|
|
|
|
1248
|
0
|
0
|
|
|
|
|
(pk_size = ldns_read_uint16(data + 2)) == 0 || |
1249
|
0
|
|
|
|
|
|
rdf_size < (size_t) hit_size + pk_size + 4) { |
1250
|
|
|
|
|
|
|
|
1251
|
0
|
|
|
|
|
|
return LDNS_STATUS_WIRE_RDATA_ERR; |
1252
|
|
|
|
|
|
|
} |
1253
|
|
|
|
|
|
|
|
1254
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%d ", (int) data[1]); |
1255
|
|
|
|
|
|
|
|
1256
|
0
|
0
|
|
|
|
|
for (data += 4; hit_size > 0; hit_size--, data++) { |
1257
|
|
|
|
|
|
|
|
1258
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%02x", (int) *data); |
1259
|
|
|
|
|
|
|
} |
1260
|
0
|
|
|
|
|
|
ldns_buffer_write_u8(output, (uint8_t) ' '); |
1261
|
|
|
|
|
|
|
|
1262
|
0
|
0
|
|
|
|
|
if (ldns_buffer_reserve(output, |
1263
|
|
|
|
|
|
|
ldns_b64_ntop_calculate_size(pk_size))) { |
1264
|
|
|
|
|
|
|
|
1265
|
0
|
|
|
|
|
|
written = ldns_b64_ntop(data, pk_size, |
1266
|
0
|
|
|
|
|
|
(char *) ldns_buffer_current(output), |
1267
|
|
|
|
|
|
|
ldns_buffer_remaining(output)); |
1268
|
|
|
|
|
|
|
|
1269
|
0
|
|
|
|
|
|
if (written > 0 && |
1270
|
0
|
|
|
|
|
|
written < (int) ldns_buffer_remaining(output)) { |
1271
|
|
|
|
|
|
|
|
1272
|
0
|
|
|
|
|
|
output->_position += written; |
1273
|
|
|
|
|
|
|
} |
1274
|
|
|
|
|
|
|
} |
1275
|
0
|
|
|
|
|
|
return ldns_buffer_status(output); |
1276
|
|
|
|
|
|
|
} |
1277
|
|
|
|
|
|
|
|
1278
|
|
|
|
|
|
|
static ldns_status |
1279
|
97
|
|
|
|
|
|
ldns_rdf2buffer_str_fmt(ldns_buffer *buffer, |
1280
|
|
|
|
|
|
|
const ldns_output_format* fmt, const ldns_rdf *rdf) |
1281
|
|
|
|
|
|
|
{ |
1282
|
97
|
|
|
|
|
|
ldns_status res = LDNS_STATUS_OK; |
1283
|
|
|
|
|
|
|
|
1284
|
|
|
|
|
|
|
/*ldns_buffer_printf(buffer, "%u:", ldns_rdf_get_type(rdf));*/ |
1285
|
97
|
100
|
|
|
|
|
if (rdf) { |
1286
|
96
|
|
|
|
|
|
switch(ldns_rdf_get_type(rdf)) { |
1287
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_NONE: |
1288
|
0
|
|
|
|
|
|
break; |
1289
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_DNAME: |
1290
|
27
|
|
|
|
|
|
res = ldns_rdf2buffer_str_dname(buffer, rdf); |
1291
|
27
|
|
|
|
|
|
break; |
1292
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_INT8: /* Don't output mnemonics for these */ |
1293
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_ALG: |
1294
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_CERTIFICATE_USAGE: |
1295
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_SELECTOR: |
1296
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_MATCHING_TYPE: |
1297
|
18
|
|
|
|
|
|
res = ldns_rdf2buffer_str_int8(buffer, rdf); |
1298
|
18
|
|
|
|
|
|
break; |
1299
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_INT16: |
1300
|
9
|
|
|
|
|
|
res = ldns_rdf2buffer_str_int16(buffer, rdf); |
1301
|
9
|
|
|
|
|
|
break; |
1302
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_INT32: |
1303
|
0
|
|
|
|
|
|
res = ldns_rdf2buffer_str_int32(buffer, rdf); |
1304
|
0
|
|
|
|
|
|
break; |
1305
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_PERIOD: |
1306
|
0
|
|
|
|
|
|
res = ldns_rdf2buffer_str_period(buffer, rdf); |
1307
|
0
|
|
|
|
|
|
break; |
1308
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_TSIGTIME: |
1309
|
0
|
|
|
|
|
|
res = ldns_rdf2buffer_str_tsigtime(buffer, rdf); |
1310
|
0
|
|
|
|
|
|
break; |
1311
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_A: |
1312
|
14
|
|
|
|
|
|
res = ldns_rdf2buffer_str_a(buffer, rdf); |
1313
|
14
|
|
|
|
|
|
break; |
1314
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_AAAA: |
1315
|
2
|
|
|
|
|
|
res = ldns_rdf2buffer_str_aaaa(buffer, rdf); |
1316
|
2
|
|
|
|
|
|
break; |
1317
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_STR: |
1318
|
2
|
|
|
|
|
|
res = ldns_rdf2buffer_str_str(buffer, rdf); |
1319
|
2
|
|
|
|
|
|
break; |
1320
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_APL: |
1321
|
0
|
|
|
|
|
|
res = ldns_rdf2buffer_str_apl(buffer, rdf); |
1322
|
0
|
|
|
|
|
|
break; |
1323
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_B32_EXT: |
1324
|
0
|
|
|
|
|
|
res = ldns_rdf2buffer_str_b32_ext(buffer, rdf); |
1325
|
0
|
|
|
|
|
|
break; |
1326
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_B64: |
1327
|
0
|
|
|
|
|
|
res = ldns_rdf2buffer_str_b64(buffer, rdf); |
1328
|
0
|
|
|
|
|
|
break; |
1329
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_HEX: |
1330
|
12
|
|
|
|
|
|
res = ldns_rdf2buffer_str_hex(buffer, rdf); |
1331
|
12
|
|
|
|
|
|
break; |
1332
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_NSEC: |
1333
|
6
|
|
|
|
|
|
res = ldns_rdf2buffer_str_nsec_fmt(buffer, fmt, rdf); |
1334
|
6
|
|
|
|
|
|
break; |
1335
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_NSEC3_SALT: |
1336
|
0
|
|
|
|
|
|
res = ldns_rdf2buffer_str_nsec3_salt(buffer, rdf); |
1337
|
0
|
|
|
|
|
|
break; |
1338
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_TYPE: |
1339
|
5
|
|
|
|
|
|
res = ldns_rdf2buffer_str_type_fmt(buffer, fmt, rdf); |
1340
|
5
|
|
|
|
|
|
break; |
1341
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_CLASS: |
1342
|
0
|
|
|
|
|
|
res = ldns_rdf2buffer_str_class(buffer, rdf); |
1343
|
0
|
|
|
|
|
|
break; |
1344
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_CERT_ALG: |
1345
|
0
|
|
|
|
|
|
res = ldns_rdf2buffer_str_cert_alg(buffer, rdf); |
1346
|
0
|
|
|
|
|
|
break; |
1347
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_UNKNOWN: |
1348
|
0
|
|
|
|
|
|
res = ldns_rdf2buffer_str_unknown(buffer, rdf); |
1349
|
0
|
|
|
|
|
|
break; |
1350
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_TIME: |
1351
|
0
|
|
|
|
|
|
res = ldns_rdf2buffer_str_time(buffer, rdf); |
1352
|
0
|
|
|
|
|
|
break; |
1353
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_HIP: |
1354
|
0
|
|
|
|
|
|
res = ldns_rdf2buffer_str_hip(buffer, rdf); |
1355
|
0
|
|
|
|
|
|
break; |
1356
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_LOC: |
1357
|
0
|
|
|
|
|
|
res = ldns_rdf2buffer_str_loc(buffer, rdf); |
1358
|
0
|
|
|
|
|
|
break; |
1359
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_WKS: |
1360
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_SERVICE: |
1361
|
0
|
|
|
|
|
|
res = ldns_rdf2buffer_str_wks(buffer, rdf); |
1362
|
0
|
|
|
|
|
|
break; |
1363
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_NSAP: |
1364
|
0
|
|
|
|
|
|
res = ldns_rdf2buffer_str_nsap(buffer, rdf); |
1365
|
0
|
|
|
|
|
|
break; |
1366
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_ATMA: |
1367
|
0
|
|
|
|
|
|
res = ldns_rdf2buffer_str_atma(buffer, rdf); |
1368
|
0
|
|
|
|
|
|
break; |
1369
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_IPSECKEY: |
1370
|
0
|
|
|
|
|
|
res = ldns_rdf2buffer_str_ipseckey(buffer, rdf); |
1371
|
0
|
|
|
|
|
|
break; |
1372
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_INT16_DATA: |
1373
|
0
|
|
|
|
|
|
res = ldns_rdf2buffer_str_int16_data(buffer, rdf); |
1374
|
0
|
|
|
|
|
|
break; |
1375
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_NSEC3_NEXT_OWNER: |
1376
|
1
|
|
|
|
|
|
res = ldns_rdf2buffer_str_b32_ext(buffer, rdf); |
1377
|
1
|
|
|
|
|
|
break; |
1378
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_ILNP64: |
1379
|
0
|
|
|
|
|
|
res = ldns_rdf2buffer_str_ilnp64(buffer, rdf); |
1380
|
0
|
|
|
|
|
|
break; |
1381
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_EUI48: |
1382
|
0
|
|
|
|
|
|
res = ldns_rdf2buffer_str_eui48(buffer, rdf); |
1383
|
0
|
|
|
|
|
|
break; |
1384
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_EUI64: |
1385
|
0
|
|
|
|
|
|
res = ldns_rdf2buffer_str_eui64(buffer, rdf); |
1386
|
0
|
|
|
|
|
|
break; |
1387
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_TAG: |
1388
|
0
|
|
|
|
|
|
res = ldns_rdf2buffer_str_tag(buffer, rdf); |
1389
|
0
|
|
|
|
|
|
break; |
1390
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_LONG_STR: |
1391
|
0
|
|
|
|
|
|
res = ldns_rdf2buffer_str_long_str(buffer, rdf); |
1392
|
96
|
|
|
|
|
|
break; |
1393
|
|
|
|
|
|
|
} |
1394
|
|
|
|
|
|
|
} else { |
1395
|
|
|
|
|
|
|
/** This will write mangled RRs */ |
1396
|
1
|
|
|
|
|
|
ldns_buffer_printf(buffer, "(null) "); |
1397
|
1
|
|
|
|
|
|
res = LDNS_STATUS_ERR; |
1398
|
|
|
|
|
|
|
} |
1399
|
97
|
|
|
|
|
|
return res; |
1400
|
|
|
|
|
|
|
} |
1401
|
|
|
|
|
|
|
|
1402
|
|
|
|
|
|
|
ldns_status |
1403
|
57
|
|
|
|
|
|
ldns_rdf2buffer_str(ldns_buffer *buffer, const ldns_rdf *rdf) |
1404
|
|
|
|
|
|
|
{ |
1405
|
57
|
|
|
|
|
|
return ldns_rdf2buffer_str_fmt(buffer,ldns_output_format_default,rdf); |
1406
|
|
|
|
|
|
|
} |
1407
|
|
|
|
|
|
|
|
1408
|
|
|
|
|
|
|
static ldns_rdf * |
1409
|
0
|
|
|
|
|
|
ldns_b32_ext2dname(const ldns_rdf *rdf) |
1410
|
|
|
|
|
|
|
{ |
1411
|
|
|
|
|
|
|
size_t size; |
1412
|
|
|
|
|
|
|
char *b32; |
1413
|
|
|
|
|
|
|
ldns_rdf *out; |
1414
|
0
|
0
|
|
|
|
|
if(ldns_rdf_size(rdf) == 0) |
1415
|
0
|
|
|
|
|
|
return NULL; |
1416
|
|
|
|
|
|
|
/* remove -1 for the b32-hash-len octet */ |
1417
|
0
|
|
|
|
|
|
size = ldns_b32_ntop_calculate_size(ldns_rdf_size(rdf) - 1); |
1418
|
|
|
|
|
|
|
/* add one for the end nul for the string */ |
1419
|
0
|
|
|
|
|
|
b32 = LDNS_XMALLOC(char, size + 2); |
1420
|
0
|
0
|
|
|
|
|
if (b32) { |
1421
|
0
|
0
|
|
|
|
|
if (ldns_b32_ntop_extended_hex(ldns_rdf_data(rdf) + 1, |
1422
|
0
|
|
|
|
|
|
ldns_rdf_size(rdf) - 1, b32, size+1) > 0) { |
1423
|
0
|
|
|
|
|
|
b32[size] = '.'; |
1424
|
0
|
|
|
|
|
|
b32[size+1] = '\0'; |
1425
|
0
|
0
|
|
|
|
|
if (ldns_str2rdf_dname(&out, b32) == LDNS_STATUS_OK) { |
1426
|
0
|
|
|
|
|
|
LDNS_FREE(b32); |
1427
|
0
|
|
|
|
|
|
return out; |
1428
|
|
|
|
|
|
|
} |
1429
|
|
|
|
|
|
|
} |
1430
|
0
|
|
|
|
|
|
LDNS_FREE(b32); |
1431
|
|
|
|
|
|
|
} |
1432
|
0
|
|
|
|
|
|
return NULL; |
1433
|
|
|
|
|
|
|
} |
1434
|
|
|
|
|
|
|
|
1435
|
|
|
|
|
|
|
static ldns_status |
1436
|
0
|
|
|
|
|
|
ldns_rr2buffer_str_rfc3597(ldns_buffer *output, const ldns_rr *rr) |
1437
|
|
|
|
|
|
|
{ |
1438
|
0
|
|
|
|
|
|
size_t total_rdfsize = 0; |
1439
|
|
|
|
|
|
|
size_t i, j; |
1440
|
|
|
|
|
|
|
|
1441
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "TYPE%u\t", ldns_rr_get_type(rr)); |
1442
|
0
|
0
|
|
|
|
|
for (i = 0; i < ldns_rr_rd_count(rr); i++) { |
1443
|
0
|
|
|
|
|
|
total_rdfsize += ldns_rdf_size(ldns_rr_rdf(rr, i)); |
1444
|
|
|
|
|
|
|
} |
1445
|
0
|
0
|
|
|
|
|
if (total_rdfsize == 0) { |
1446
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\\# 0\n"); |
1447
|
0
|
|
|
|
|
|
return ldns_buffer_status(output); |
1448
|
|
|
|
|
|
|
} |
1449
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\\# %d ", total_rdfsize); |
1450
|
0
|
0
|
|
|
|
|
for (i = 0; i < ldns_rr_rd_count(rr); i++) { |
1451
|
0
|
0
|
|
|
|
|
for (j = 0; j < ldns_rdf_size(ldns_rr_rdf(rr, i)); j++) { |
1452
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%.2x", |
1453
|
0
|
|
|
|
|
|
ldns_rdf_data(ldns_rr_rdf(rr, i))[j]); |
1454
|
|
|
|
|
|
|
} |
1455
|
|
|
|
|
|
|
} |
1456
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\n"); |
1457
|
0
|
|
|
|
|
|
return ldns_buffer_status(output); |
1458
|
|
|
|
|
|
|
} |
1459
|
|
|
|
|
|
|
|
1460
|
|
|
|
|
|
|
ldns_status |
1461
|
13
|
|
|
|
|
|
ldns_rr2buffer_str_fmt(ldns_buffer *output, |
1462
|
|
|
|
|
|
|
const ldns_output_format *fmt, const ldns_rr *rr) |
1463
|
|
|
|
|
|
|
{ |
1464
|
|
|
|
|
|
|
uint16_t i, flags; |
1465
|
13
|
|
|
|
|
|
ldns_status status = LDNS_STATUS_OK; |
1466
|
13
|
|
|
|
|
|
ldns_output_format_storage* fmt_st = (ldns_output_format_storage*)fmt; |
1467
|
|
|
|
|
|
|
|
1468
|
13
|
50
|
|
|
|
|
if (fmt_st == NULL) { |
1469
|
0
|
|
|
|
|
|
fmt_st = (ldns_output_format_storage*) |
1470
|
|
|
|
|
|
|
ldns_output_format_default; |
1471
|
|
|
|
|
|
|
} |
1472
|
13
|
50
|
|
|
|
|
if (!rr) { |
1473
|
0
|
0
|
|
|
|
|
if (LDNS_COMMENT_NULLS & fmt_st->flags) { |
1474
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "; (null)\n"); |
1475
|
|
|
|
|
|
|
} |
1476
|
0
|
|
|
|
|
|
return ldns_buffer_status(output); |
1477
|
|
|
|
|
|
|
} |
1478
|
13
|
50
|
|
|
|
|
if (ldns_rr_owner(rr)) { |
1479
|
13
|
|
|
|
|
|
status = ldns_rdf2buffer_str_dname(output, ldns_rr_owner(rr)); |
1480
|
|
|
|
|
|
|
} |
1481
|
13
|
50
|
|
|
|
|
if (status != LDNS_STATUS_OK) { |
1482
|
0
|
|
|
|
|
|
return status; |
1483
|
|
|
|
|
|
|
} |
1484
|
|
|
|
|
|
|
|
1485
|
|
|
|
|
|
|
/* TTL should NOT be printed if it is a question */ |
1486
|
13
|
50
|
|
|
|
|
if (!ldns_rr_is_question(rr)) { |
1487
|
13
|
|
|
|
|
|
ldns_buffer_printf(output, "\t%d", ldns_rr_ttl(rr)); |
1488
|
|
|
|
|
|
|
} |
1489
|
|
|
|
|
|
|
|
1490
|
13
|
|
|
|
|
|
ldns_buffer_printf(output, "\t"); |
1491
|
13
|
|
|
|
|
|
status = ldns_rr_class2buffer_str(output, ldns_rr_get_class(rr)); |
1492
|
13
|
50
|
|
|
|
|
if (status != LDNS_STATUS_OK) { |
1493
|
0
|
|
|
|
|
|
return status; |
1494
|
|
|
|
|
|
|
} |
1495
|
13
|
|
|
|
|
|
ldns_buffer_printf(output, "\t"); |
1496
|
|
|
|
|
|
|
|
1497
|
13
|
50
|
|
|
|
|
if (ldns_output_format_covers_type(fmt, ldns_rr_get_type(rr))) { |
1498
|
0
|
|
|
|
|
|
return ldns_rr2buffer_str_rfc3597(output, rr); |
1499
|
|
|
|
|
|
|
} |
1500
|
13
|
|
|
|
|
|
status = ldns_rr_type2buffer_str(output, ldns_rr_get_type(rr)); |
1501
|
13
|
50
|
|
|
|
|
if (status != LDNS_STATUS_OK) { |
1502
|
0
|
|
|
|
|
|
return status; |
1503
|
|
|
|
|
|
|
} |
1504
|
|
|
|
|
|
|
|
1505
|
13
|
50
|
|
|
|
|
if (ldns_rr_rd_count(rr) > 0) { |
1506
|
13
|
|
|
|
|
|
ldns_buffer_printf(output, "\t"); |
1507
|
0
|
0
|
|
|
|
|
} else if (!ldns_rr_is_question(rr)) { |
1508
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\t\\# 0"); |
1509
|
|
|
|
|
|
|
} |
1510
|
|
|
|
|
|
|
|
1511
|
53
|
100
|
|
|
|
|
for (i = 0; i < ldns_rr_rd_count(rr); i++) { |
1512
|
|
|
|
|
|
|
/* ldns_rdf2buffer_str handles NULL input fine! */ |
1513
|
40
|
|
|
|
|
|
if ((fmt_st->flags & LDNS_FMT_ZEROIZE_RRSIGS) && |
1514
|
0
|
0
|
|
|
|
|
(ldns_rr_get_type(rr) == LDNS_RR_TYPE_RRSIG) && |
1515
|
0
|
0
|
|
|
|
|
((/* inception */ i == 4 && |
1516
|
0
|
|
|
|
|
|
ldns_rdf_get_type(ldns_rr_rdf(rr, 4)) == |
1517
|
0
|
0
|
|
|
|
|
LDNS_RDF_TYPE_TIME) || |
1518
|
0
|
0
|
|
|
|
|
(/* expiration */ i == 5 && |
1519
|
0
|
|
|
|
|
|
ldns_rdf_get_type(ldns_rr_rdf(rr, 5)) == |
1520
|
0
|
0
|
|
|
|
|
LDNS_RDF_TYPE_TIME) || |
1521
|
0
|
0
|
|
|
|
|
(/* signature */ i == 8 && |
1522
|
0
|
|
|
|
|
|
ldns_rdf_get_type(ldns_rr_rdf(rr, 8)) == |
1523
|
|
|
|
|
|
|
LDNS_RDF_TYPE_B64))) { |
1524
|
|
|
|
|
|
|
|
1525
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "(null)"); |
1526
|
0
|
|
|
|
|
|
status = ldns_buffer_status(output); |
1527
|
40
|
|
|
|
|
|
} else if ((fmt_st->flags & LDNS_FMT_PAD_SOA_SERIAL) && |
1528
|
0
|
0
|
|
|
|
|
(ldns_rr_get_type(rr) == LDNS_RR_TYPE_SOA) && |
1529
|
0
|
0
|
|
|
|
|
/* serial */ i == 2 && |
1530
|
0
|
|
|
|
|
|
ldns_rdf_get_type(ldns_rr_rdf(rr, 2)) == |
1531
|
|
|
|
|
|
|
LDNS_RDF_TYPE_INT32) { |
1532
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "%10lu", |
1533
|
0
|
|
|
|
|
|
(unsigned long) ldns_read_uint32( |
1534
|
0
|
|
|
|
|
|
ldns_rdf_data(ldns_rr_rdf(rr, 2)))); |
1535
|
0
|
|
|
|
|
|
status = ldns_buffer_status(output); |
1536
|
|
|
|
|
|
|
} else { |
1537
|
40
|
|
|
|
|
|
status = ldns_rdf2buffer_str_fmt(output, |
1538
|
40
|
|
|
|
|
|
fmt, ldns_rr_rdf(rr, i)); |
1539
|
|
|
|
|
|
|
} |
1540
|
40
|
50
|
|
|
|
|
if(status != LDNS_STATUS_OK) |
1541
|
0
|
|
|
|
|
|
return status; |
1542
|
40
|
100
|
|
|
|
|
if (i < ldns_rr_rd_count(rr) - 1) { |
1543
|
27
|
|
|
|
|
|
ldns_buffer_printf(output, " "); |
1544
|
|
|
|
|
|
|
} |
1545
|
|
|
|
|
|
|
} |
1546
|
|
|
|
|
|
|
/* per RR special comments - handy for DNSSEC types */ |
1547
|
|
|
|
|
|
|
/* check to prevent question sec. rr from |
1548
|
|
|
|
|
|
|
* getting here */ |
1549
|
13
|
50
|
|
|
|
|
if (ldns_rr_rd_count(rr) > 0) { |
1550
|
13
|
|
|
|
|
|
switch (ldns_rr_get_type(rr)) { |
1551
|
|
|
|
|
|
|
case LDNS_RR_TYPE_DNSKEY: |
1552
|
|
|
|
|
|
|
/* if ldns_rr_rd_count(rr) > 0 |
1553
|
|
|
|
|
|
|
then ldns_rr_rdf(rr, 0) exists! */ |
1554
|
0
|
0
|
|
|
|
|
if (! (fmt_st->flags & LDNS_COMMENT_KEY)) { |
1555
|
0
|
|
|
|
|
|
break; |
1556
|
|
|
|
|
|
|
} |
1557
|
0
|
|
|
|
|
|
flags = ldns_rdf2native_int16(ldns_rr_rdf(rr, 0)); |
1558
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, " ;{"); |
1559
|
0
|
0
|
|
|
|
|
if (fmt_st->flags & LDNS_COMMENT_KEY_ID) { |
1560
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "id = %u", |
1561
|
0
|
|
|
|
|
|
(unsigned int) ldns_calc_keytag(rr)); |
1562
|
|
|
|
|
|
|
} |
1563
|
0
|
0
|
|
|
|
|
if ((fmt_st->flags & LDNS_COMMENT_KEY_TYPE) && |
|
|
0
|
|
|
|
|
|
1564
|
0
|
|
|
|
|
|
(flags & LDNS_KEY_ZONE_KEY)){ |
1565
|
|
|
|
|
|
|
|
1566
|
0
|
0
|
|
|
|
|
if (flags & LDNS_KEY_SEP_KEY) { |
1567
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, " (ksk)"); |
1568
|
|
|
|
|
|
|
} else { |
1569
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, " (zsk)"); |
1570
|
|
|
|
|
|
|
} |
1571
|
0
|
0
|
|
|
|
|
if (fmt_st->flags & LDNS_COMMENT_KEY_SIZE){ |
1572
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, ", "); |
1573
|
|
|
|
|
|
|
} |
1574
|
0
|
0
|
|
|
|
|
} else if (fmt_st->flags |
1575
|
0
|
|
|
|
|
|
& (LDNS_COMMENT_KEY_ID |
1576
|
|
|
|
|
|
|
|LDNS_COMMENT_KEY_SIZE)) { |
1577
|
0
|
|
|
|
|
|
ldns_buffer_printf( output, ", "); |
1578
|
|
|
|
|
|
|
} |
1579
|
0
|
0
|
|
|
|
|
if (fmt_st->flags & LDNS_COMMENT_KEY_SIZE) { |
1580
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "size = %db", |
1581
|
|
|
|
|
|
|
ldns_rr_dnskey_key_size(rr)); |
1582
|
|
|
|
|
|
|
} |
1583
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "}"); |
1584
|
0
|
|
|
|
|
|
break; |
1585
|
|
|
|
|
|
|
case LDNS_RR_TYPE_RRSIG: |
1586
|
0
|
0
|
|
|
|
|
if ((fmt_st->flags & LDNS_COMMENT_KEY) |
1587
|
0
|
0
|
|
|
|
|
&& (fmt_st->flags& LDNS_COMMENT_RRSIGS) |
1588
|
0
|
0
|
|
|
|
|
&& ldns_rr_rdf(rr, 6) != NULL) { |
1589
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, " ;{id = %d}", |
1590
|
0
|
|
|
|
|
|
ldns_rdf2native_int16( |
1591
|
0
|
|
|
|
|
|
ldns_rr_rdf(rr, 6))); |
1592
|
|
|
|
|
|
|
} |
1593
|
0
|
|
|
|
|
|
break; |
1594
|
|
|
|
|
|
|
case LDNS_RR_TYPE_DS: |
1595
|
9
|
|
|
|
|
|
if ((fmt_st->flags & LDNS_COMMENT_BUBBLEBABBLE) && |
1596
|
0
|
|
|
|
|
|
ldns_rr_rdf(rr, 3) != NULL) { |
1597
|
|
|
|
|
|
|
|
1598
|
0
|
|
|
|
|
|
uint8_t *data = ldns_rdf_data( |
1599
|
0
|
|
|
|
|
|
ldns_rr_rdf(rr, 3)); |
1600
|
0
|
|
|
|
|
|
size_t len = ldns_rdf_size(ldns_rr_rdf(rr, 3)); |
1601
|
0
|
|
|
|
|
|
char *babble = ldns_bubblebabble(data, len); |
1602
|
0
|
0
|
|
|
|
|
if(babble) { |
1603
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, |
1604
|
|
|
|
|
|
|
" ;{%s}", babble); |
1605
|
|
|
|
|
|
|
} |
1606
|
0
|
|
|
|
|
|
LDNS_FREE(babble); |
1607
|
|
|
|
|
|
|
} |
1608
|
9
|
|
|
|
|
|
break; |
1609
|
|
|
|
|
|
|
case LDNS_RR_TYPE_NSEC3: |
1610
|
0
|
0
|
|
|
|
|
if (! (fmt_st->flags & LDNS_COMMENT_FLAGS) && |
|
|
0
|
|
|
|
|
|
1611
|
0
|
|
|
|
|
|
! (fmt_st->flags & LDNS_COMMENT_NSEC3_CHAIN)) { |
1612
|
0
|
|
|
|
|
|
break; |
1613
|
|
|
|
|
|
|
} |
1614
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, " ;{"); |
1615
|
0
|
0
|
|
|
|
|
if ((fmt_st->flags & LDNS_COMMENT_FLAGS)) { |
1616
|
0
|
0
|
|
|
|
|
if (ldns_nsec3_optout(rr)) { |
1617
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, |
1618
|
|
|
|
|
|
|
" flags: optout"); |
1619
|
|
|
|
|
|
|
} else { |
1620
|
0
|
|
|
|
|
|
ldns_buffer_printf(output," flags: -"); |
1621
|
|
|
|
|
|
|
} |
1622
|
0
|
0
|
|
|
|
|
if (fmt_st->flags & LDNS_COMMENT_NSEC3_CHAIN && |
|
|
0
|
|
|
|
|
|
1623
|
0
|
|
|
|
|
|
fmt_st->hashmap != NULL) { |
1624
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, ", "); |
1625
|
|
|
|
|
|
|
} |
1626
|
|
|
|
|
|
|
} |
1627
|
0
|
0
|
|
|
|
|
if (fmt_st->flags & LDNS_COMMENT_NSEC3_CHAIN && |
|
|
0
|
|
|
|
|
|
1628
|
0
|
|
|
|
|
|
fmt_st->hashmap != NULL) { |
1629
|
|
|
|
|
|
|
ldns_rbnode_t *node; |
1630
|
0
|
|
|
|
|
|
ldns_rdf *key = ldns_dname_label( |
1631
|
0
|
|
|
|
|
|
ldns_rr_owner(rr), 0); |
1632
|
0
|
0
|
|
|
|
|
if (key) { |
1633
|
0
|
|
|
|
|
|
node = ldns_rbtree_search( |
1634
|
|
|
|
|
|
|
fmt_st->hashmap, |
1635
|
|
|
|
|
|
|
(void *) key); |
1636
|
0
|
0
|
|
|
|
|
if (node->data) { |
1637
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, |
1638
|
|
|
|
|
|
|
"from: "); |
1639
|
0
|
|
|
|
|
|
(void) ldns_rdf2buffer_str( |
1640
|
|
|
|
|
|
|
output, |
1641
|
0
|
|
|
|
|
|
ldns_dnssec_name_name( |
1642
|
|
|
|
|
|
|
(ldns_dnssec_name*) |
1643
|
0
|
|
|
|
|
|
node->data |
1644
|
|
|
|
|
|
|
)); |
1645
|
|
|
|
|
|
|
} |
1646
|
0
|
|
|
|
|
|
ldns_rdf_free(key); |
1647
|
|
|
|
|
|
|
} |
1648
|
0
|
|
|
|
|
|
key = ldns_b32_ext2dname( |
1649
|
0
|
|
|
|
|
|
ldns_nsec3_next_owner(rr)); |
1650
|
0
|
0
|
|
|
|
|
if (key) { |
1651
|
0
|
|
|
|
|
|
node = ldns_rbtree_search( |
1652
|
|
|
|
|
|
|
fmt_st->hashmap, |
1653
|
|
|
|
|
|
|
(void *) key); |
1654
|
0
|
0
|
|
|
|
|
if (node->data) { |
1655
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, |
1656
|
|
|
|
|
|
|
" to: "); |
1657
|
0
|
|
|
|
|
|
(void) ldns_rdf2buffer_str( |
1658
|
|
|
|
|
|
|
output, |
1659
|
0
|
|
|
|
|
|
ldns_dnssec_name_name( |
1660
|
|
|
|
|
|
|
(ldns_dnssec_name*) |
1661
|
0
|
|
|
|
|
|
node->data |
1662
|
|
|
|
|
|
|
)); |
1663
|
|
|
|
|
|
|
} |
1664
|
0
|
|
|
|
|
|
ldns_rdf_free(key); |
1665
|
|
|
|
|
|
|
} |
1666
|
|
|
|
|
|
|
} |
1667
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "}"); |
1668
|
0
|
|
|
|
|
|
break; |
1669
|
|
|
|
|
|
|
default: |
1670
|
4
|
|
|
|
|
|
break; |
1671
|
|
|
|
|
|
|
|
1672
|
|
|
|
|
|
|
} |
1673
|
|
|
|
|
|
|
} |
1674
|
|
|
|
|
|
|
/* last */ |
1675
|
13
|
|
|
|
|
|
ldns_buffer_printf(output, "\n"); |
1676
|
13
|
|
|
|
|
|
return ldns_buffer_status(output); |
1677
|
|
|
|
|
|
|
} |
1678
|
|
|
|
|
|
|
|
1679
|
|
|
|
|
|
|
ldns_status |
1680
|
0
|
|
|
|
|
|
ldns_rr2buffer_str(ldns_buffer *output, const ldns_rr *rr) |
1681
|
|
|
|
|
|
|
{ |
1682
|
0
|
|
|
|
|
|
return ldns_rr2buffer_str_fmt(output, ldns_output_format_default, rr); |
1683
|
|
|
|
|
|
|
} |
1684
|
|
|
|
|
|
|
|
1685
|
|
|
|
|
|
|
ldns_status |
1686
|
0
|
|
|
|
|
|
ldns_rr_list2buffer_str_fmt(ldns_buffer *output, |
1687
|
|
|
|
|
|
|
const ldns_output_format *fmt, const ldns_rr_list *list) |
1688
|
|
|
|
|
|
|
{ |
1689
|
|
|
|
|
|
|
uint16_t i; |
1690
|
|
|
|
|
|
|
|
1691
|
0
|
0
|
|
|
|
|
for(i = 0; i < ldns_rr_list_rr_count(list); i++) { |
1692
|
0
|
|
|
|
|
|
(void) ldns_rr2buffer_str_fmt(output, fmt, |
1693
|
0
|
|
|
|
|
|
ldns_rr_list_rr(list, i)); |
1694
|
|
|
|
|
|
|
} |
1695
|
0
|
|
|
|
|
|
return ldns_buffer_status(output); |
1696
|
|
|
|
|
|
|
} |
1697
|
|
|
|
|
|
|
|
1698
|
|
|
|
|
|
|
ldns_status |
1699
|
0
|
|
|
|
|
|
ldns_rr_list2buffer_str(ldns_buffer *output, const ldns_rr_list *list) |
1700
|
|
|
|
|
|
|
{ |
1701
|
0
|
|
|
|
|
|
return ldns_rr_list2buffer_str_fmt( |
1702
|
|
|
|
|
|
|
output, ldns_output_format_default, list); |
1703
|
|
|
|
|
|
|
} |
1704
|
|
|
|
|
|
|
|
1705
|
|
|
|
|
|
|
ldns_status |
1706
|
0
|
|
|
|
|
|
ldns_pktheader2buffer_str(ldns_buffer *output, const ldns_pkt *pkt) |
1707
|
|
|
|
|
|
|
{ |
1708
|
0
|
|
|
|
|
|
ldns_lookup_table *opcode = ldns_lookup_by_id(ldns_opcodes, |
1709
|
0
|
|
|
|
|
|
(int) ldns_pkt_get_opcode(pkt)); |
1710
|
0
|
|
|
|
|
|
ldns_lookup_table *rcode = ldns_lookup_by_id(ldns_rcodes, |
1711
|
0
|
|
|
|
|
|
(int) ldns_pkt_get_rcode(pkt)); |
1712
|
|
|
|
|
|
|
|
1713
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, ";; ->>HEADER<<- "); |
1714
|
0
|
0
|
|
|
|
|
if (opcode) { |
1715
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "opcode: %s, ", opcode->name); |
1716
|
|
|
|
|
|
|
} else { |
1717
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "opcode: ?? (%u), ", |
1718
|
0
|
|
|
|
|
|
ldns_pkt_get_opcode(pkt)); |
1719
|
|
|
|
|
|
|
} |
1720
|
0
|
0
|
|
|
|
|
if (rcode) { |
1721
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "rcode: %s, ", rcode->name); |
1722
|
|
|
|
|
|
|
} else { |
1723
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "rcode: ?? (%u), ", ldns_pkt_get_rcode(pkt)); |
1724
|
|
|
|
|
|
|
} |
1725
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "id: %d\n", ldns_pkt_id(pkt)); |
1726
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, ";; flags: "); |
1727
|
|
|
|
|
|
|
|
1728
|
0
|
0
|
|
|
|
|
if (ldns_pkt_qr(pkt)) { |
1729
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "qr "); |
1730
|
|
|
|
|
|
|
} |
1731
|
0
|
0
|
|
|
|
|
if (ldns_pkt_aa(pkt)) { |
1732
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "aa "); |
1733
|
|
|
|
|
|
|
} |
1734
|
0
|
0
|
|
|
|
|
if (ldns_pkt_tc(pkt)) { |
1735
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "tc "); |
1736
|
|
|
|
|
|
|
} |
1737
|
0
|
0
|
|
|
|
|
if (ldns_pkt_rd(pkt)) { |
1738
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "rd "); |
1739
|
|
|
|
|
|
|
} |
1740
|
0
|
0
|
|
|
|
|
if (ldns_pkt_cd(pkt)) { |
1741
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "cd "); |
1742
|
|
|
|
|
|
|
} |
1743
|
0
|
0
|
|
|
|
|
if (ldns_pkt_ra(pkt)) { |
1744
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "ra "); |
1745
|
|
|
|
|
|
|
} |
1746
|
0
|
0
|
|
|
|
|
if (ldns_pkt_ad(pkt)) { |
1747
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "ad "); |
1748
|
|
|
|
|
|
|
} |
1749
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "; "); |
1750
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "QUERY: %u, ", ldns_pkt_qdcount(pkt)); |
1751
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "ANSWER: %u, ", ldns_pkt_ancount(pkt)); |
1752
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "AUTHORITY: %u, ", ldns_pkt_nscount(pkt)); |
1753
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "ADDITIONAL: %u ", ldns_pkt_arcount(pkt)); |
1754
|
0
|
|
|
|
|
|
return ldns_buffer_status(output); |
1755
|
|
|
|
|
|
|
} |
1756
|
|
|
|
|
|
|
|
1757
|
|
|
|
|
|
|
ldns_status |
1758
|
0
|
|
|
|
|
|
ldns_pkt2buffer_str_fmt(ldns_buffer *output, |
1759
|
|
|
|
|
|
|
const ldns_output_format *fmt, const ldns_pkt *pkt) |
1760
|
|
|
|
|
|
|
{ |
1761
|
|
|
|
|
|
|
uint16_t i; |
1762
|
0
|
|
|
|
|
|
ldns_status status = LDNS_STATUS_OK; |
1763
|
|
|
|
|
|
|
char *tmp; |
1764
|
|
|
|
|
|
|
struct timeval time; |
1765
|
|
|
|
|
|
|
time_t time_tt; |
1766
|
|
|
|
|
|
|
|
1767
|
0
|
0
|
|
|
|
|
if (!pkt) { |
1768
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "null"); |
1769
|
0
|
|
|
|
|
|
return LDNS_STATUS_OK; |
1770
|
|
|
|
|
|
|
} |
1771
|
|
|
|
|
|
|
|
1772
|
0
|
0
|
|
|
|
|
if (ldns_buffer_status_ok(output)) { |
1773
|
0
|
|
|
|
|
|
status = ldns_pktheader2buffer_str(output, pkt); |
1774
|
0
|
0
|
|
|
|
|
if (status != LDNS_STATUS_OK) { |
1775
|
0
|
|
|
|
|
|
return status; |
1776
|
|
|
|
|
|
|
} |
1777
|
|
|
|
|
|
|
|
1778
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\n"); |
1779
|
|
|
|
|
|
|
|
1780
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, ";; QUESTION SECTION:\n;; "); |
1781
|
|
|
|
|
|
|
|
1782
|
|
|
|
|
|
|
|
1783
|
0
|
0
|
|
|
|
|
for (i = 0; i < ldns_pkt_qdcount(pkt); i++) { |
1784
|
0
|
|
|
|
|
|
status = ldns_rr2buffer_str_fmt(output, fmt, |
1785
|
0
|
|
|
|
|
|
ldns_rr_list_rr( |
1786
|
0
|
|
|
|
|
|
ldns_pkt_question(pkt), i)); |
1787
|
0
|
0
|
|
|
|
|
if (status != LDNS_STATUS_OK) { |
1788
|
0
|
|
|
|
|
|
return status; |
1789
|
|
|
|
|
|
|
} |
1790
|
|
|
|
|
|
|
} |
1791
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\n"); |
1792
|
|
|
|
|
|
|
|
1793
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, ";; ANSWER SECTION:\n"); |
1794
|
0
|
0
|
|
|
|
|
for (i = 0; i < ldns_pkt_ancount(pkt); i++) { |
1795
|
0
|
|
|
|
|
|
status = ldns_rr2buffer_str_fmt(output, fmt, |
1796
|
0
|
|
|
|
|
|
ldns_rr_list_rr( |
1797
|
0
|
|
|
|
|
|
ldns_pkt_answer(pkt), i)); |
1798
|
0
|
0
|
|
|
|
|
if (status != LDNS_STATUS_OK) { |
1799
|
0
|
|
|
|
|
|
return status; |
1800
|
|
|
|
|
|
|
} |
1801
|
|
|
|
|
|
|
|
1802
|
|
|
|
|
|
|
} |
1803
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\n"); |
1804
|
|
|
|
|
|
|
|
1805
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, ";; AUTHORITY SECTION:\n"); |
1806
|
|
|
|
|
|
|
|
1807
|
0
|
0
|
|
|
|
|
for (i = 0; i < ldns_pkt_nscount(pkt); i++) { |
1808
|
0
|
|
|
|
|
|
status = ldns_rr2buffer_str_fmt(output, fmt, |
1809
|
0
|
|
|
|
|
|
ldns_rr_list_rr( |
1810
|
0
|
|
|
|
|
|
ldns_pkt_authority(pkt), i)); |
1811
|
0
|
0
|
|
|
|
|
if (status != LDNS_STATUS_OK) { |
1812
|
0
|
|
|
|
|
|
return status; |
1813
|
|
|
|
|
|
|
} |
1814
|
|
|
|
|
|
|
} |
1815
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\n"); |
1816
|
|
|
|
|
|
|
|
1817
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, ";; ADDITIONAL SECTION:\n"); |
1818
|
0
|
0
|
|
|
|
|
for (i = 0; i < ldns_pkt_arcount(pkt); i++) { |
1819
|
0
|
|
|
|
|
|
status = ldns_rr2buffer_str_fmt(output, fmt, |
1820
|
0
|
|
|
|
|
|
ldns_rr_list_rr( |
1821
|
0
|
|
|
|
|
|
ldns_pkt_additional(pkt), i)); |
1822
|
0
|
0
|
|
|
|
|
if (status != LDNS_STATUS_OK) { |
1823
|
0
|
|
|
|
|
|
return status; |
1824
|
|
|
|
|
|
|
} |
1825
|
|
|
|
|
|
|
|
1826
|
|
|
|
|
|
|
} |
1827
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\n"); |
1828
|
|
|
|
|
|
|
/* add some futher fields */ |
1829
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, ";; Query time: %d msec\n", |
1830
|
|
|
|
|
|
|
ldns_pkt_querytime(pkt)); |
1831
|
0
|
0
|
|
|
|
|
if (ldns_pkt_edns(pkt)) { |
1832
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, |
1833
|
|
|
|
|
|
|
";; EDNS: version %u; flags:", |
1834
|
0
|
|
|
|
|
|
ldns_pkt_edns_version(pkt)); |
1835
|
0
|
0
|
|
|
|
|
if (ldns_pkt_edns_do(pkt)) { |
1836
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, " do"); |
1837
|
|
|
|
|
|
|
} |
1838
|
|
|
|
|
|
|
/* the extended rcode is the value set, shifted four bits, |
1839
|
|
|
|
|
|
|
* and or'd with the original rcode */ |
1840
|
0
|
0
|
|
|
|
|
if (ldns_pkt_edns_extended_rcode(pkt)) { |
1841
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, " ; ext-rcode: %d", |
1842
|
0
|
|
|
|
|
|
(ldns_pkt_edns_extended_rcode(pkt) << 4 | ldns_pkt_get_rcode(pkt))); |
1843
|
|
|
|
|
|
|
} |
1844
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, " ; udp: %u\n", |
1845
|
0
|
|
|
|
|
|
ldns_pkt_edns_udp_size(pkt)); |
1846
|
|
|
|
|
|
|
|
1847
|
0
|
0
|
|
|
|
|
if (ldns_pkt_edns_data(pkt)) { |
1848
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, ";; Data: "); |
1849
|
0
|
|
|
|
|
|
(void)ldns_rdf2buffer_str(output, |
1850
|
0
|
|
|
|
|
|
ldns_pkt_edns_data(pkt)); |
1851
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\n"); |
1852
|
|
|
|
|
|
|
} |
1853
|
|
|
|
|
|
|
} |
1854
|
0
|
0
|
|
|
|
|
if (ldns_pkt_tsig(pkt)) { |
1855
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, ";; TSIG:\n;; "); |
1856
|
0
|
|
|
|
|
|
(void) ldns_rr2buffer_str_fmt( |
1857
|
0
|
|
|
|
|
|
output, fmt, ldns_pkt_tsig(pkt)); |
1858
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\n"); |
1859
|
|
|
|
|
|
|
} |
1860
|
0
|
0
|
|
|
|
|
if (ldns_pkt_answerfrom(pkt)) { |
1861
|
0
|
|
|
|
|
|
tmp = ldns_rdf2str(ldns_pkt_answerfrom(pkt)); |
1862
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, ";; SERVER: %s\n", tmp); |
1863
|
0
|
|
|
|
|
|
LDNS_FREE(tmp); |
1864
|
|
|
|
|
|
|
} |
1865
|
0
|
|
|
|
|
|
time = ldns_pkt_timestamp(pkt); |
1866
|
0
|
|
|
|
|
|
time_tt = (time_t)time.tv_sec; |
1867
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, ";; WHEN: %s", |
1868
|
|
|
|
|
|
|
(char*)ctime(&time_tt)); |
1869
|
|
|
|
|
|
|
|
1870
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, ";; MSG SIZE rcvd: %d\n", |
1871
|
0
|
|
|
|
|
|
(int)ldns_pkt_size(pkt)); |
1872
|
|
|
|
|
|
|
} else { |
1873
|
0
|
|
|
|
|
|
return ldns_buffer_status(output); |
1874
|
|
|
|
|
|
|
} |
1875
|
0
|
|
|
|
|
|
return status; |
1876
|
|
|
|
|
|
|
} |
1877
|
|
|
|
|
|
|
|
1878
|
|
|
|
|
|
|
ldns_status |
1879
|
0
|
|
|
|
|
|
ldns_pkt2buffer_str(ldns_buffer *output, const ldns_pkt *pkt) |
1880
|
|
|
|
|
|
|
{ |
1881
|
0
|
|
|
|
|
|
return ldns_pkt2buffer_str_fmt(output, ldns_output_format_default, pkt); |
1882
|
|
|
|
|
|
|
} |
1883
|
|
|
|
|
|
|
|
1884
|
|
|
|
|
|
|
|
1885
|
|
|
|
|
|
|
#ifdef HAVE_SSL |
1886
|
|
|
|
|
|
|
static ldns_status |
1887
|
0
|
|
|
|
|
|
ldns_hmac_key2buffer_str(ldns_buffer *output, const ldns_key *k) |
1888
|
|
|
|
|
|
|
{ |
1889
|
|
|
|
|
|
|
ldns_status status; |
1890
|
|
|
|
|
|
|
size_t i; |
1891
|
|
|
|
|
|
|
ldns_rdf *b64_bignum; |
1892
|
|
|
|
|
|
|
|
1893
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "Key: "); |
1894
|
|
|
|
|
|
|
|
1895
|
0
|
|
|
|
|
|
i = ldns_key_hmac_size(k); |
1896
|
0
|
|
|
|
|
|
b64_bignum = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_B64, i, ldns_key_hmac_key(k)); |
1897
|
0
|
|
|
|
|
|
status = ldns_rdf2buffer_str(output, b64_bignum); |
1898
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(b64_bignum); |
1899
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\n"); |
1900
|
0
|
|
|
|
|
|
return status; |
1901
|
|
|
|
|
|
|
} |
1902
|
|
|
|
|
|
|
#endif |
1903
|
|
|
|
|
|
|
|
1904
|
|
|
|
|
|
|
#if defined(HAVE_SSL) && defined(USE_GOST) |
1905
|
|
|
|
|
|
|
static ldns_status |
1906
|
0
|
|
|
|
|
|
ldns_gost_key2buffer_str(ldns_buffer *output, EVP_PKEY *p) |
1907
|
|
|
|
|
|
|
{ |
1908
|
0
|
|
|
|
|
|
unsigned char* pp = NULL; |
1909
|
|
|
|
|
|
|
int ret; |
1910
|
|
|
|
|
|
|
ldns_rdf *b64_bignum; |
1911
|
|
|
|
|
|
|
ldns_status status; |
1912
|
|
|
|
|
|
|
|
1913
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "GostAsn1: "); |
1914
|
|
|
|
|
|
|
|
1915
|
0
|
|
|
|
|
|
ret = i2d_PrivateKey(p, &pp); |
1916
|
0
|
|
|
|
|
|
b64_bignum = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_B64, (size_t)ret, pp); |
1917
|
0
|
|
|
|
|
|
status = ldns_rdf2buffer_str(output, b64_bignum); |
1918
|
|
|
|
|
|
|
|
1919
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(b64_bignum); |
1920
|
0
|
|
|
|
|
|
OPENSSL_free(pp); |
1921
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\n"); |
1922
|
0
|
|
|
|
|
|
return status; |
1923
|
|
|
|
|
|
|
} |
1924
|
|
|
|
|
|
|
#endif |
1925
|
|
|
|
|
|
|
|
1926
|
|
|
|
|
|
|
ldns_status |
1927
|
0
|
|
|
|
|
|
ldns_key2buffer_str(ldns_buffer *output, const ldns_key *k) |
1928
|
|
|
|
|
|
|
{ |
1929
|
0
|
|
|
|
|
|
ldns_status status = LDNS_STATUS_OK; |
1930
|
|
|
|
|
|
|
unsigned char *bignum; |
1931
|
|
|
|
|
|
|
#ifdef HAVE_SSL |
1932
|
|
|
|
|
|
|
# ifndef S_SPLINT_S |
1933
|
|
|
|
|
|
|
uint16_t i; |
1934
|
|
|
|
|
|
|
# endif |
1935
|
|
|
|
|
|
|
/* not used when ssl is not defined */ |
1936
|
|
|
|
|
|
|
/*@unused@*/ |
1937
|
0
|
|
|
|
|
|
ldns_rdf *b64_bignum = NULL; |
1938
|
|
|
|
|
|
|
|
1939
|
|
|
|
|
|
|
RSA *rsa; |
1940
|
|
|
|
|
|
|
DSA *dsa; |
1941
|
|
|
|
|
|
|
#endif /* HAVE_SSL */ |
1942
|
|
|
|
|
|
|
|
1943
|
0
|
0
|
|
|
|
|
if (!k) { |
1944
|
0
|
|
|
|
|
|
return LDNS_STATUS_ERR; |
1945
|
|
|
|
|
|
|
} |
1946
|
|
|
|
|
|
|
|
1947
|
0
|
|
|
|
|
|
bignum = LDNS_XMALLOC(unsigned char, LDNS_MAX_KEYLEN); |
1948
|
0
|
0
|
|
|
|
|
if (!bignum) { |
1949
|
0
|
|
|
|
|
|
return LDNS_STATUS_ERR; |
1950
|
|
|
|
|
|
|
} |
1951
|
|
|
|
|
|
|
|
1952
|
0
|
0
|
|
|
|
|
if (ldns_buffer_status_ok(output)) { |
1953
|
|
|
|
|
|
|
#ifdef HAVE_SSL |
1954
|
0
|
|
|
|
|
|
switch(ldns_key_algorithm(k)) { |
1955
|
|
|
|
|
|
|
case LDNS_SIGN_RSASHA1: |
1956
|
|
|
|
|
|
|
case LDNS_SIGN_RSASHA1_NSEC3: |
1957
|
|
|
|
|
|
|
case LDNS_SIGN_RSASHA256: |
1958
|
|
|
|
|
|
|
case LDNS_SIGN_RSASHA512: |
1959
|
|
|
|
|
|
|
case LDNS_SIGN_RSAMD5: |
1960
|
|
|
|
|
|
|
/* copied by looking at dnssec-keygen output */ |
1961
|
|
|
|
|
|
|
/* header */ |
1962
|
0
|
|
|
|
|
|
rsa = ldns_key_rsa_key(k); |
1963
|
|
|
|
|
|
|
|
1964
|
0
|
|
|
|
|
|
ldns_buffer_printf(output,"Private-key-format: v1.2\n"); |
1965
|
0
|
|
|
|
|
|
switch(ldns_key_algorithm(k)) { |
1966
|
|
|
|
|
|
|
case LDNS_SIGN_RSAMD5: |
1967
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, |
1968
|
|
|
|
|
|
|
"Algorithm: %u (RSA)\n", |
1969
|
|
|
|
|
|
|
LDNS_RSAMD5); |
1970
|
0
|
|
|
|
|
|
break; |
1971
|
|
|
|
|
|
|
case LDNS_SIGN_RSASHA1: |
1972
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, |
1973
|
|
|
|
|
|
|
"Algorithm: %u (RSASHA1)\n", |
1974
|
|
|
|
|
|
|
LDNS_RSASHA1); |
1975
|
0
|
|
|
|
|
|
break; |
1976
|
|
|
|
|
|
|
case LDNS_SIGN_RSASHA1_NSEC3: |
1977
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, |
1978
|
|
|
|
|
|
|
"Algorithm: %u (RSASHA1_NSEC3)\n", |
1979
|
|
|
|
|
|
|
LDNS_RSASHA1_NSEC3); |
1980
|
0
|
|
|
|
|
|
break; |
1981
|
|
|
|
|
|
|
#ifdef USE_SHA2 |
1982
|
|
|
|
|
|
|
case LDNS_SIGN_RSASHA256: |
1983
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, |
1984
|
|
|
|
|
|
|
"Algorithm: %u (RSASHA256)\n", |
1985
|
|
|
|
|
|
|
LDNS_RSASHA256); |
1986
|
0
|
|
|
|
|
|
break; |
1987
|
|
|
|
|
|
|
case LDNS_SIGN_RSASHA512: |
1988
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, |
1989
|
|
|
|
|
|
|
"Algorithm: %u (RSASHA512)\n", |
1990
|
|
|
|
|
|
|
LDNS_RSASHA512); |
1991
|
0
|
|
|
|
|
|
break; |
1992
|
|
|
|
|
|
|
#endif |
1993
|
|
|
|
|
|
|
default: |
1994
|
|
|
|
|
|
|
#ifdef STDERR_MSGS |
1995
|
|
|
|
|
|
|
fprintf(stderr, "Warning: unknown signature "); |
1996
|
|
|
|
|
|
|
fprintf(stderr, |
1997
|
|
|
|
|
|
|
"algorithm type %u\n", |
1998
|
|
|
|
|
|
|
ldns_key_algorithm(k)); |
1999
|
|
|
|
|
|
|
#endif |
2000
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, |
2001
|
|
|
|
|
|
|
"Algorithm: %u (Unknown)\n", |
2002
|
0
|
|
|
|
|
|
ldns_key_algorithm(k)); |
2003
|
0
|
|
|
|
|
|
break; |
2004
|
|
|
|
|
|
|
} |
2005
|
|
|
|
|
|
|
|
2006
|
|
|
|
|
|
|
/* print to buf, convert to bin, convert to b64, |
2007
|
|
|
|
|
|
|
* print to buf */ |
2008
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "Modulus: "); |
2009
|
|
|
|
|
|
|
#ifndef S_SPLINT_S |
2010
|
0
|
|
|
|
|
|
i = (uint16_t)BN_bn2bin(rsa->n, bignum); |
2011
|
0
|
0
|
|
|
|
|
if (i > LDNS_MAX_KEYLEN) { |
2012
|
0
|
|
|
|
|
|
goto error; |
2013
|
|
|
|
|
|
|
} |
2014
|
0
|
|
|
|
|
|
b64_bignum = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_B64, i, bignum); |
2015
|
0
|
0
|
|
|
|
|
if (ldns_rdf2buffer_str(output, b64_bignum) != LDNS_STATUS_OK) { |
2016
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(b64_bignum); |
2017
|
0
|
|
|
|
|
|
goto error; |
2018
|
|
|
|
|
|
|
} |
2019
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(b64_bignum); |
2020
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\n"); |
2021
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "PublicExponent: "); |
2022
|
0
|
|
|
|
|
|
i = (uint16_t)BN_bn2bin(rsa->e, bignum); |
2023
|
0
|
0
|
|
|
|
|
if (i > LDNS_MAX_KEYLEN) { |
2024
|
0
|
|
|
|
|
|
goto error; |
2025
|
|
|
|
|
|
|
} |
2026
|
0
|
|
|
|
|
|
b64_bignum = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_B64, i, bignum); |
2027
|
0
|
0
|
|
|
|
|
if (ldns_rdf2buffer_str(output, b64_bignum) != LDNS_STATUS_OK) { |
2028
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(b64_bignum); |
2029
|
0
|
|
|
|
|
|
goto error; |
2030
|
|
|
|
|
|
|
} |
2031
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(b64_bignum); |
2032
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\n"); |
2033
|
|
|
|
|
|
|
|
2034
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "PrivateExponent: "); |
2035
|
0
|
0
|
|
|
|
|
if (rsa->d) { |
2036
|
0
|
|
|
|
|
|
i = (uint16_t)BN_bn2bin(rsa->d, bignum); |
2037
|
0
|
0
|
|
|
|
|
if (i > LDNS_MAX_KEYLEN) { |
2038
|
0
|
|
|
|
|
|
goto error; |
2039
|
|
|
|
|
|
|
} |
2040
|
0
|
|
|
|
|
|
b64_bignum = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_B64, i, bignum); |
2041
|
0
|
0
|
|
|
|
|
if (ldns_rdf2buffer_str(output, b64_bignum) != LDNS_STATUS_OK) { |
2042
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(b64_bignum); |
2043
|
0
|
|
|
|
|
|
goto error; |
2044
|
|
|
|
|
|
|
} |
2045
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(b64_bignum); |
2046
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\n"); |
2047
|
|
|
|
|
|
|
} else { |
2048
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "(Not available)\n"); |
2049
|
|
|
|
|
|
|
} |
2050
|
|
|
|
|
|
|
|
2051
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "Prime1: "); |
2052
|
0
|
0
|
|
|
|
|
if (rsa->p) { |
2053
|
0
|
|
|
|
|
|
i = (uint16_t)BN_bn2bin(rsa->p, bignum); |
2054
|
0
|
0
|
|
|
|
|
if (i > LDNS_MAX_KEYLEN) { |
2055
|
0
|
|
|
|
|
|
goto error; |
2056
|
|
|
|
|
|
|
} |
2057
|
0
|
|
|
|
|
|
b64_bignum = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_B64, i, bignum); |
2058
|
0
|
0
|
|
|
|
|
if (ldns_rdf2buffer_str(output, b64_bignum) != LDNS_STATUS_OK) { |
2059
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(b64_bignum); |
2060
|
0
|
|
|
|
|
|
goto error; |
2061
|
|
|
|
|
|
|
} |
2062
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(b64_bignum); |
2063
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\n"); |
2064
|
|
|
|
|
|
|
} else { |
2065
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "(Not available)\n"); |
2066
|
|
|
|
|
|
|
} |
2067
|
|
|
|
|
|
|
|
2068
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "Prime2: "); |
2069
|
0
|
0
|
|
|
|
|
if (rsa->q) { |
2070
|
0
|
|
|
|
|
|
i = (uint16_t)BN_bn2bin(rsa->q, bignum); |
2071
|
0
|
0
|
|
|
|
|
if (i > LDNS_MAX_KEYLEN) { |
2072
|
0
|
|
|
|
|
|
goto error; |
2073
|
|
|
|
|
|
|
} |
2074
|
0
|
|
|
|
|
|
b64_bignum = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_B64, i, bignum); |
2075
|
0
|
0
|
|
|
|
|
if (ldns_rdf2buffer_str(output, b64_bignum) != LDNS_STATUS_OK) { |
2076
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(b64_bignum); |
2077
|
0
|
|
|
|
|
|
goto error; |
2078
|
|
|
|
|
|
|
} |
2079
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(b64_bignum); |
2080
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\n"); |
2081
|
|
|
|
|
|
|
} else { |
2082
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "(Not available)\n"); |
2083
|
|
|
|
|
|
|
} |
2084
|
|
|
|
|
|
|
|
2085
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "Exponent1: "); |
2086
|
0
|
0
|
|
|
|
|
if (rsa->dmp1) { |
2087
|
0
|
|
|
|
|
|
i = (uint16_t)BN_bn2bin(rsa->dmp1, bignum); |
2088
|
0
|
0
|
|
|
|
|
if (i > LDNS_MAX_KEYLEN) { |
2089
|
0
|
|
|
|
|
|
goto error; |
2090
|
|
|
|
|
|
|
} |
2091
|
0
|
|
|
|
|
|
b64_bignum = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_B64, i, bignum); |
2092
|
0
|
0
|
|
|
|
|
if (ldns_rdf2buffer_str(output, b64_bignum) != LDNS_STATUS_OK) { |
2093
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(b64_bignum); |
2094
|
0
|
|
|
|
|
|
goto error; |
2095
|
|
|
|
|
|
|
} |
2096
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(b64_bignum); |
2097
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\n"); |
2098
|
|
|
|
|
|
|
} else { |
2099
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "(Not available)\n"); |
2100
|
|
|
|
|
|
|
} |
2101
|
|
|
|
|
|
|
|
2102
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "Exponent2: "); |
2103
|
0
|
0
|
|
|
|
|
if (rsa->dmq1) { |
2104
|
0
|
|
|
|
|
|
i = (uint16_t)BN_bn2bin(rsa->dmq1, bignum); |
2105
|
0
|
0
|
|
|
|
|
if (i > LDNS_MAX_KEYLEN) { |
2106
|
0
|
|
|
|
|
|
goto error; |
2107
|
|
|
|
|
|
|
} |
2108
|
0
|
|
|
|
|
|
b64_bignum = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_B64, i, bignum); |
2109
|
0
|
0
|
|
|
|
|
if (ldns_rdf2buffer_str(output, b64_bignum) != LDNS_STATUS_OK) { |
2110
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(b64_bignum); |
2111
|
0
|
|
|
|
|
|
goto error; |
2112
|
|
|
|
|
|
|
} |
2113
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(b64_bignum); |
2114
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\n"); |
2115
|
|
|
|
|
|
|
} else { |
2116
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "(Not available)\n"); |
2117
|
|
|
|
|
|
|
} |
2118
|
|
|
|
|
|
|
|
2119
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "Coefficient: "); |
2120
|
0
|
0
|
|
|
|
|
if (rsa->iqmp) { |
2121
|
0
|
|
|
|
|
|
i = (uint16_t)BN_bn2bin(rsa->iqmp, bignum); |
2122
|
0
|
0
|
|
|
|
|
if (i > LDNS_MAX_KEYLEN) { |
2123
|
0
|
|
|
|
|
|
goto error; |
2124
|
|
|
|
|
|
|
} |
2125
|
0
|
|
|
|
|
|
b64_bignum = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_B64, i, bignum); |
2126
|
0
|
0
|
|
|
|
|
if (ldns_rdf2buffer_str(output, b64_bignum) != LDNS_STATUS_OK) { |
2127
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(b64_bignum); |
2128
|
0
|
|
|
|
|
|
goto error; |
2129
|
|
|
|
|
|
|
} |
2130
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(b64_bignum); |
2131
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\n"); |
2132
|
|
|
|
|
|
|
} else { |
2133
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "(Not available)\n"); |
2134
|
|
|
|
|
|
|
} |
2135
|
|
|
|
|
|
|
#endif /* splint */ |
2136
|
|
|
|
|
|
|
|
2137
|
0
|
|
|
|
|
|
RSA_free(rsa); |
2138
|
0
|
|
|
|
|
|
break; |
2139
|
|
|
|
|
|
|
case LDNS_SIGN_DSA: |
2140
|
|
|
|
|
|
|
case LDNS_SIGN_DSA_NSEC3: |
2141
|
0
|
|
|
|
|
|
dsa = ldns_key_dsa_key(k); |
2142
|
|
|
|
|
|
|
|
2143
|
0
|
|
|
|
|
|
ldns_buffer_printf(output,"Private-key-format: v1.2\n"); |
2144
|
0
|
0
|
|
|
|
|
if (ldns_key_algorithm(k) == LDNS_SIGN_DSA) { |
2145
|
0
|
|
|
|
|
|
ldns_buffer_printf(output,"Algorithm: 3 (DSA)\n"); |
2146
|
0
|
0
|
|
|
|
|
} else if (ldns_key_algorithm(k) == LDNS_SIGN_DSA_NSEC3) { |
2147
|
0
|
|
|
|
|
|
ldns_buffer_printf(output,"Algorithm: 6 (DSA_NSEC3)\n"); |
2148
|
|
|
|
|
|
|
} |
2149
|
|
|
|
|
|
|
|
2150
|
|
|
|
|
|
|
/* print to buf, convert to bin, convert to b64, |
2151
|
|
|
|
|
|
|
* print to buf */ |
2152
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "Prime(p): "); |
2153
|
|
|
|
|
|
|
#ifndef S_SPLINT_S |
2154
|
0
|
0
|
|
|
|
|
if (dsa->p) { |
2155
|
0
|
|
|
|
|
|
i = (uint16_t)BN_bn2bin(dsa->p, bignum); |
2156
|
0
|
0
|
|
|
|
|
if (i > LDNS_MAX_KEYLEN) { |
2157
|
0
|
|
|
|
|
|
goto error; |
2158
|
|
|
|
|
|
|
} |
2159
|
0
|
|
|
|
|
|
b64_bignum = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_B64, i, bignum); |
2160
|
0
|
0
|
|
|
|
|
if (ldns_rdf2buffer_str(output, b64_bignum) != LDNS_STATUS_OK) { |
2161
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(b64_bignum); |
2162
|
0
|
|
|
|
|
|
goto error; |
2163
|
|
|
|
|
|
|
} |
2164
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(b64_bignum); |
2165
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\n"); |
2166
|
|
|
|
|
|
|
} else { |
2167
|
0
|
|
|
|
|
|
printf("(Not available)\n"); |
2168
|
|
|
|
|
|
|
} |
2169
|
|
|
|
|
|
|
|
2170
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "Subprime(q): "); |
2171
|
0
|
0
|
|
|
|
|
if (dsa->q) { |
2172
|
0
|
|
|
|
|
|
i = (uint16_t)BN_bn2bin(dsa->q, bignum); |
2173
|
0
|
0
|
|
|
|
|
if (i > LDNS_MAX_KEYLEN) { |
2174
|
0
|
|
|
|
|
|
goto error; |
2175
|
|
|
|
|
|
|
} |
2176
|
0
|
|
|
|
|
|
b64_bignum = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_B64, i, bignum); |
2177
|
0
|
0
|
|
|
|
|
if (ldns_rdf2buffer_str(output, b64_bignum) != LDNS_STATUS_OK) { |
2178
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(b64_bignum); |
2179
|
0
|
|
|
|
|
|
goto error; |
2180
|
|
|
|
|
|
|
} |
2181
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(b64_bignum); |
2182
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\n"); |
2183
|
|
|
|
|
|
|
} else { |
2184
|
0
|
|
|
|
|
|
printf("(Not available)\n"); |
2185
|
|
|
|
|
|
|
} |
2186
|
|
|
|
|
|
|
|
2187
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "Base(g): "); |
2188
|
0
|
0
|
|
|
|
|
if (dsa->g) { |
2189
|
0
|
|
|
|
|
|
i = (uint16_t)BN_bn2bin(dsa->g, bignum); |
2190
|
0
|
0
|
|
|
|
|
if (i > LDNS_MAX_KEYLEN) { |
2191
|
0
|
|
|
|
|
|
goto error; |
2192
|
|
|
|
|
|
|
} |
2193
|
0
|
|
|
|
|
|
b64_bignum = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_B64, i, bignum); |
2194
|
0
|
0
|
|
|
|
|
if (ldns_rdf2buffer_str(output, b64_bignum) != LDNS_STATUS_OK) { |
2195
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(b64_bignum); |
2196
|
0
|
|
|
|
|
|
goto error; |
2197
|
|
|
|
|
|
|
} |
2198
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(b64_bignum); |
2199
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\n"); |
2200
|
|
|
|
|
|
|
} else { |
2201
|
0
|
|
|
|
|
|
printf("(Not available)\n"); |
2202
|
|
|
|
|
|
|
} |
2203
|
|
|
|
|
|
|
|
2204
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "Private_value(x): "); |
2205
|
0
|
0
|
|
|
|
|
if (dsa->priv_key) { |
2206
|
0
|
|
|
|
|
|
i = (uint16_t)BN_bn2bin(dsa->priv_key, bignum); |
2207
|
0
|
0
|
|
|
|
|
if (i > LDNS_MAX_KEYLEN) { |
2208
|
0
|
|
|
|
|
|
goto error; |
2209
|
|
|
|
|
|
|
} |
2210
|
0
|
|
|
|
|
|
b64_bignum = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_B64, i, bignum); |
2211
|
0
|
0
|
|
|
|
|
if (ldns_rdf2buffer_str(output, b64_bignum) != LDNS_STATUS_OK) { |
2212
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(b64_bignum); |
2213
|
0
|
|
|
|
|
|
goto error; |
2214
|
|
|
|
|
|
|
} |
2215
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(b64_bignum); |
2216
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\n"); |
2217
|
|
|
|
|
|
|
} else { |
2218
|
0
|
|
|
|
|
|
printf("(Not available)\n"); |
2219
|
|
|
|
|
|
|
} |
2220
|
|
|
|
|
|
|
|
2221
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "Public_value(y): "); |
2222
|
0
|
0
|
|
|
|
|
if (dsa->pub_key) { |
2223
|
0
|
|
|
|
|
|
i = (uint16_t)BN_bn2bin(dsa->pub_key, bignum); |
2224
|
0
|
0
|
|
|
|
|
if (i > LDNS_MAX_KEYLEN) { |
2225
|
0
|
|
|
|
|
|
goto error; |
2226
|
|
|
|
|
|
|
} |
2227
|
0
|
|
|
|
|
|
b64_bignum = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_B64, i, bignum); |
2228
|
0
|
0
|
|
|
|
|
if (ldns_rdf2buffer_str(output, b64_bignum) != LDNS_STATUS_OK) { |
2229
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(b64_bignum); |
2230
|
0
|
|
|
|
|
|
goto error; |
2231
|
|
|
|
|
|
|
} |
2232
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(b64_bignum); |
2233
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\n"); |
2234
|
|
|
|
|
|
|
} else { |
2235
|
0
|
|
|
|
|
|
printf("(Not available)\n"); |
2236
|
|
|
|
|
|
|
} |
2237
|
|
|
|
|
|
|
#endif /* splint */ |
2238
|
0
|
|
|
|
|
|
break; |
2239
|
|
|
|
|
|
|
case LDNS_SIGN_ECC_GOST: |
2240
|
|
|
|
|
|
|
/* no format defined, use blob */ |
2241
|
|
|
|
|
|
|
#if defined(HAVE_SSL) && defined(USE_GOST) |
2242
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "Private-key-format: v1.2\n"); |
2243
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "Algorithm: %d (ECC-GOST)\n", LDNS_SIGN_ECC_GOST); |
2244
|
0
|
|
|
|
|
|
status = ldns_gost_key2buffer_str(output, |
2245
|
|
|
|
|
|
|
#ifndef S_SPLINT_S |
2246
|
|
|
|
|
|
|
k->_key.key |
2247
|
|
|
|
|
|
|
#else |
2248
|
|
|
|
|
|
|
NULL |
2249
|
|
|
|
|
|
|
#endif |
2250
|
|
|
|
|
|
|
); |
2251
|
|
|
|
|
|
|
#else |
2252
|
|
|
|
|
|
|
goto error; |
2253
|
|
|
|
|
|
|
#endif /* GOST */ |
2254
|
0
|
|
|
|
|
|
break; |
2255
|
|
|
|
|
|
|
case LDNS_SIGN_ECDSAP256SHA256: |
2256
|
|
|
|
|
|
|
case LDNS_SIGN_ECDSAP384SHA384: |
2257
|
|
|
|
|
|
|
#ifdef USE_ECDSA |
2258
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "Private-key-format: v1.2\n"); |
2259
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "Algorithm: %d (", ldns_key_algorithm(k)); |
2260
|
0
|
|
|
|
|
|
status=ldns_algorithm2buffer_str(output, (ldns_algorithm)ldns_key_algorithm(k)); |
2261
|
|
|
|
|
|
|
#ifndef S_SPLINT_S |
2262
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, ")\n"); |
2263
|
0
|
0
|
|
|
|
|
if(k->_key.key) { |
2264
|
0
|
|
|
|
|
|
EC_KEY* ec = EVP_PKEY_get1_EC_KEY(k->_key.key); |
2265
|
0
|
|
|
|
|
|
const BIGNUM* b = EC_KEY_get0_private_key(ec); |
2266
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "PrivateKey: "); |
2267
|
0
|
|
|
|
|
|
i = (uint16_t)BN_bn2bin(b, bignum); |
2268
|
0
|
0
|
|
|
|
|
if (i > LDNS_MAX_KEYLEN) { |
2269
|
0
|
|
|
|
|
|
goto error; |
2270
|
|
|
|
|
|
|
} |
2271
|
0
|
|
|
|
|
|
b64_bignum = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_B64, i, bignum); |
2272
|
0
|
0
|
|
|
|
|
if (ldns_rdf2buffer_str(output, b64_bignum) != LDNS_STATUS_OK) { |
2273
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(b64_bignum); |
2274
|
0
|
|
|
|
|
|
goto error; |
2275
|
|
|
|
|
|
|
} |
2276
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(b64_bignum); |
2277
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "\n"); |
2278
|
|
|
|
|
|
|
/* down reference count in EC_KEY |
2279
|
|
|
|
|
|
|
* its still assigned to the PKEY */ |
2280
|
0
|
|
|
|
|
|
EC_KEY_free(ec); |
2281
|
|
|
|
|
|
|
} |
2282
|
|
|
|
|
|
|
#endif /* splint */ |
2283
|
|
|
|
|
|
|
#else |
2284
|
|
|
|
|
|
|
goto error; |
2285
|
|
|
|
|
|
|
#endif /* ECDSA */ |
2286
|
0
|
|
|
|
|
|
break; |
2287
|
|
|
|
|
|
|
case LDNS_SIGN_HMACMD5: |
2288
|
|
|
|
|
|
|
/* there's not much of a format defined for TSIG */ |
2289
|
|
|
|
|
|
|
/* It's just a binary blob, Same for all algorithms */ |
2290
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "Private-key-format: v1.2\n"); |
2291
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "Algorithm: 157 (HMAC_MD5)\n"); |
2292
|
0
|
|
|
|
|
|
status = ldns_hmac_key2buffer_str(output, k); |
2293
|
0
|
|
|
|
|
|
break; |
2294
|
|
|
|
|
|
|
case LDNS_SIGN_HMACSHA1: |
2295
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "Private-key-format: v1.2\n"); |
2296
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "Algorithm: 158 (HMAC_SHA1)\n"); |
2297
|
0
|
|
|
|
|
|
status = ldns_hmac_key2buffer_str(output, k); |
2298
|
0
|
|
|
|
|
|
break; |
2299
|
|
|
|
|
|
|
case LDNS_SIGN_HMACSHA256: |
2300
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "Private-key-format: v1.2\n"); |
2301
|
0
|
|
|
|
|
|
ldns_buffer_printf(output, "Algorithm: 159 (HMAC_SHA256)\n"); |
2302
|
0
|
|
|
|
|
|
status = ldns_hmac_key2buffer_str(output, k); |
2303
|
0
|
|
|
|
|
|
break; |
2304
|
|
|
|
|
|
|
} |
2305
|
|
|
|
|
|
|
#endif /* HAVE_SSL */ |
2306
|
|
|
|
|
|
|
} else { |
2307
|
0
|
|
|
|
|
|
LDNS_FREE(bignum); |
2308
|
0
|
|
|
|
|
|
return ldns_buffer_status(output); |
2309
|
|
|
|
|
|
|
} |
2310
|
0
|
|
|
|
|
|
LDNS_FREE(bignum); |
2311
|
0
|
|
|
|
|
|
return status; |
2312
|
|
|
|
|
|
|
|
2313
|
|
|
|
|
|
|
#ifdef HAVE_SSL |
2314
|
|
|
|
|
|
|
/* compiles warn the label isn't used */ |
2315
|
|
|
|
|
|
|
error: |
2316
|
0
|
|
|
|
|
|
LDNS_FREE(bignum); |
2317
|
0
|
|
|
|
|
|
return LDNS_STATUS_ERR; |
2318
|
|
|
|
|
|
|
#endif /* HAVE_SSL */ |
2319
|
|
|
|
|
|
|
|
2320
|
|
|
|
|
|
|
} |
2321
|
|
|
|
|
|
|
|
2322
|
|
|
|
|
|
|
/* |
2323
|
|
|
|
|
|
|
* Zero terminate the buffer and copy data. |
2324
|
|
|
|
|
|
|
*/ |
2325
|
|
|
|
|
|
|
char * |
2326
|
0
|
|
|
|
|
|
ldns_buffer2str(ldns_buffer *buffer) |
2327
|
|
|
|
|
|
|
{ |
2328
|
|
|
|
|
|
|
char *str; |
2329
|
|
|
|
|
|
|
|
2330
|
|
|
|
|
|
|
/* check if buffer ends with \0, if not, and |
2331
|
|
|
|
|
|
|
if there is space, add it */ |
2332
|
0
|
0
|
|
|
|
|
if (*(ldns_buffer_at(buffer, ldns_buffer_position(buffer))) != 0) { |
2333
|
0
|
0
|
|
|
|
|
if (!ldns_buffer_reserve(buffer, 1)) { |
2334
|
0
|
|
|
|
|
|
return NULL; |
2335
|
|
|
|
|
|
|
} |
2336
|
0
|
|
|
|
|
|
ldns_buffer_write_u8(buffer, (uint8_t) '\0'); |
2337
|
0
|
0
|
|
|
|
|
if (!ldns_buffer_set_capacity(buffer, ldns_buffer_position(buffer))) { |
2338
|
0
|
|
|
|
|
|
return NULL; |
2339
|
|
|
|
|
|
|
} |
2340
|
|
|
|
|
|
|
} |
2341
|
|
|
|
|
|
|
|
2342
|
0
|
|
|
|
|
|
str = strdup((const char *)ldns_buffer_begin(buffer)); |
2343
|
0
|
0
|
|
|
|
|
if(!str) { |
2344
|
0
|
|
|
|
|
|
return NULL; |
2345
|
|
|
|
|
|
|
} |
2346
|
0
|
|
|
|
|
|
return str; |
2347
|
|
|
|
|
|
|
} |
2348
|
|
|
|
|
|
|
|
2349
|
|
|
|
|
|
|
/* |
2350
|
|
|
|
|
|
|
* Zero terminate the buffer and export data. |
2351
|
|
|
|
|
|
|
*/ |
2352
|
|
|
|
|
|
|
char * |
2353
|
230
|
|
|
|
|
|
ldns_buffer_export2str(ldns_buffer *buffer) |
2354
|
|
|
|
|
|
|
{ |
2355
|
|
|
|
|
|
|
/* Append '\0' as string terminator */ |
2356
|
230
|
50
|
|
|
|
|
if (! ldns_buffer_reserve(buffer, 1)) { |
2357
|
0
|
|
|
|
|
|
return NULL; |
2358
|
|
|
|
|
|
|
} |
2359
|
230
|
|
|
|
|
|
ldns_buffer_write_u8(buffer, 0); |
2360
|
|
|
|
|
|
|
|
2361
|
|
|
|
|
|
|
/* reallocate memory to the size of the string and export */ |
2362
|
230
|
|
|
|
|
|
ldns_buffer_set_capacity(buffer, ldns_buffer_position(buffer)); |
2363
|
230
|
|
|
|
|
|
return ldns_buffer_export(buffer); |
2364
|
|
|
|
|
|
|
} |
2365
|
|
|
|
|
|
|
|
2366
|
|
|
|
|
|
|
char * |
2367
|
57
|
|
|
|
|
|
ldns_rdf2str(const ldns_rdf *rdf) |
2368
|
|
|
|
|
|
|
{ |
2369
|
57
|
|
|
|
|
|
char *result = NULL; |
2370
|
57
|
|
|
|
|
|
ldns_buffer *tmp_buffer = ldns_buffer_new(LDNS_MAX_PACKETLEN); |
2371
|
|
|
|
|
|
|
|
2372
|
57
|
50
|
|
|
|
|
if (!tmp_buffer) { |
2373
|
0
|
|
|
|
|
|
return NULL; |
2374
|
|
|
|
|
|
|
} |
2375
|
57
|
100
|
|
|
|
|
if (ldns_rdf2buffer_str(tmp_buffer, rdf) == LDNS_STATUS_OK) { |
2376
|
|
|
|
|
|
|
/* export and return string, destroy rest */ |
2377
|
56
|
|
|
|
|
|
result = ldns_buffer_export2str(tmp_buffer); |
2378
|
|
|
|
|
|
|
} |
2379
|
57
|
|
|
|
|
|
ldns_buffer_free(tmp_buffer); |
2380
|
57
|
|
|
|
|
|
return result; |
2381
|
|
|
|
|
|
|
} |
2382
|
|
|
|
|
|
|
|
2383
|
|
|
|
|
|
|
char * |
2384
|
13
|
|
|
|
|
|
ldns_rr2str_fmt(const ldns_output_format *fmt, const ldns_rr *rr) |
2385
|
|
|
|
|
|
|
{ |
2386
|
13
|
|
|
|
|
|
char *result = NULL; |
2387
|
13
|
|
|
|
|
|
ldns_buffer *tmp_buffer = ldns_buffer_new(LDNS_MAX_PACKETLEN); |
2388
|
|
|
|
|
|
|
|
2389
|
13
|
50
|
|
|
|
|
if (!tmp_buffer) { |
2390
|
0
|
|
|
|
|
|
return NULL; |
2391
|
|
|
|
|
|
|
} |
2392
|
13
|
50
|
|
|
|
|
if (ldns_rr2buffer_str_fmt(tmp_buffer, fmt, rr) |
2393
|
|
|
|
|
|
|
== LDNS_STATUS_OK) { |
2394
|
|
|
|
|
|
|
/* export and return string, destroy rest */ |
2395
|
13
|
|
|
|
|
|
result = ldns_buffer_export2str(tmp_buffer); |
2396
|
|
|
|
|
|
|
} |
2397
|
13
|
|
|
|
|
|
ldns_buffer_free(tmp_buffer); |
2398
|
13
|
|
|
|
|
|
return result; |
2399
|
|
|
|
|
|
|
} |
2400
|
|
|
|
|
|
|
|
2401
|
|
|
|
|
|
|
char * |
2402
|
13
|
|
|
|
|
|
ldns_rr2str(const ldns_rr *rr) |
2403
|
|
|
|
|
|
|
{ |
2404
|
13
|
|
|
|
|
|
return ldns_rr2str_fmt(ldns_output_format_default, rr); |
2405
|
|
|
|
|
|
|
} |
2406
|
|
|
|
|
|
|
|
2407
|
|
|
|
|
|
|
char * |
2408
|
0
|
|
|
|
|
|
ldns_pkt2str_fmt(const ldns_output_format *fmt, const ldns_pkt *pkt) |
2409
|
|
|
|
|
|
|
{ |
2410
|
0
|
|
|
|
|
|
char *result = NULL; |
2411
|
0
|
|
|
|
|
|
ldns_buffer *tmp_buffer = ldns_buffer_new(LDNS_MAX_PACKETLEN); |
2412
|
|
|
|
|
|
|
|
2413
|
0
|
0
|
|
|
|
|
if (!tmp_buffer) { |
2414
|
0
|
|
|
|
|
|
return NULL; |
2415
|
|
|
|
|
|
|
} |
2416
|
0
|
0
|
|
|
|
|
if (ldns_pkt2buffer_str_fmt(tmp_buffer, fmt, pkt) |
2417
|
|
|
|
|
|
|
== LDNS_STATUS_OK) { |
2418
|
|
|
|
|
|
|
/* export and return string, destroy rest */ |
2419
|
0
|
|
|
|
|
|
result = ldns_buffer_export2str(tmp_buffer); |
2420
|
|
|
|
|
|
|
} |
2421
|
|
|
|
|
|
|
|
2422
|
0
|
|
|
|
|
|
ldns_buffer_free(tmp_buffer); |
2423
|
0
|
|
|
|
|
|
return result; |
2424
|
|
|
|
|
|
|
} |
2425
|
|
|
|
|
|
|
|
2426
|
|
|
|
|
|
|
char * |
2427
|
0
|
|
|
|
|
|
ldns_pkt2str(const ldns_pkt *pkt) |
2428
|
|
|
|
|
|
|
{ |
2429
|
0
|
|
|
|
|
|
return ldns_pkt2str_fmt(ldns_output_format_default, pkt); |
2430
|
|
|
|
|
|
|
} |
2431
|
|
|
|
|
|
|
|
2432
|
|
|
|
|
|
|
char * |
2433
|
0
|
|
|
|
|
|
ldns_key2str(const ldns_key *k) |
2434
|
|
|
|
|
|
|
{ |
2435
|
0
|
|
|
|
|
|
char *result = NULL; |
2436
|
0
|
|
|
|
|
|
ldns_buffer *tmp_buffer = ldns_buffer_new(LDNS_MAX_PACKETLEN); |
2437
|
|
|
|
|
|
|
|
2438
|
0
|
0
|
|
|
|
|
if (!tmp_buffer) { |
2439
|
0
|
|
|
|
|
|
return NULL; |
2440
|
|
|
|
|
|
|
} |
2441
|
0
|
0
|
|
|
|
|
if (ldns_key2buffer_str(tmp_buffer, k) == LDNS_STATUS_OK) { |
2442
|
|
|
|
|
|
|
/* export and return string, destroy rest */ |
2443
|
0
|
|
|
|
|
|
result = ldns_buffer_export2str(tmp_buffer); |
2444
|
|
|
|
|
|
|
} |
2445
|
0
|
|
|
|
|
|
ldns_buffer_free(tmp_buffer); |
2446
|
0
|
|
|
|
|
|
return result; |
2447
|
|
|
|
|
|
|
} |
2448
|
|
|
|
|
|
|
|
2449
|
|
|
|
|
|
|
char * |
2450
|
0
|
|
|
|
|
|
ldns_rr_list2str_fmt(const ldns_output_format *fmt, const ldns_rr_list *list) |
2451
|
|
|
|
|
|
|
{ |
2452
|
0
|
|
|
|
|
|
char *result = NULL; |
2453
|
0
|
|
|
|
|
|
ldns_buffer *tmp_buffer = ldns_buffer_new(LDNS_MAX_PACKETLEN); |
2454
|
|
|
|
|
|
|
|
2455
|
0
|
0
|
|
|
|
|
if (!tmp_buffer) { |
2456
|
0
|
|
|
|
|
|
return NULL; |
2457
|
|
|
|
|
|
|
} |
2458
|
0
|
0
|
|
|
|
|
if (list) { |
2459
|
0
|
|
|
|
|
|
if (ldns_rr_list2buffer_str_fmt( |
2460
|
|
|
|
|
|
|
tmp_buffer, fmt, list) |
2461
|
|
|
|
|
|
|
== LDNS_STATUS_OK) { |
2462
|
|
|
|
|
|
|
} |
2463
|
|
|
|
|
|
|
} else { |
2464
|
0
|
0
|
|
|
|
|
if (fmt == NULL) { |
2465
|
0
|
|
|
|
|
|
fmt = ldns_output_format_default; |
2466
|
|
|
|
|
|
|
} |
2467
|
0
|
0
|
|
|
|
|
if (fmt->flags & LDNS_COMMENT_NULLS) { |
2468
|
0
|
|
|
|
|
|
ldns_buffer_printf(tmp_buffer, "; (null)\n"); |
2469
|
|
|
|
|
|
|
} |
2470
|
|
|
|
|
|
|
} |
2471
|
|
|
|
|
|
|
|
2472
|
|
|
|
|
|
|
/* export and return string, destroy rest */ |
2473
|
0
|
|
|
|
|
|
result = ldns_buffer_export2str(tmp_buffer); |
2474
|
0
|
|
|
|
|
|
ldns_buffer_free(tmp_buffer); |
2475
|
0
|
|
|
|
|
|
return result; |
2476
|
|
|
|
|
|
|
} |
2477
|
|
|
|
|
|
|
|
2478
|
|
|
|
|
|
|
char * |
2479
|
0
|
|
|
|
|
|
ldns_rr_list2str(const ldns_rr_list *list) |
2480
|
|
|
|
|
|
|
{ |
2481
|
0
|
|
|
|
|
|
return ldns_rr_list2str_fmt(ldns_output_format_default, list); |
2482
|
|
|
|
|
|
|
} |
2483
|
|
|
|
|
|
|
|
2484
|
|
|
|
|
|
|
void |
2485
|
0
|
|
|
|
|
|
ldns_rdf_print(FILE *output, const ldns_rdf *rdf) |
2486
|
|
|
|
|
|
|
{ |
2487
|
0
|
|
|
|
|
|
char *str = ldns_rdf2str(rdf); |
2488
|
0
|
0
|
|
|
|
|
if (str) { |
2489
|
0
|
|
|
|
|
|
fprintf(output, "%s", str); |
2490
|
|
|
|
|
|
|
} else { |
2491
|
0
|
|
|
|
|
|
fprintf(output, ";Unable to convert rdf to string\n"); |
2492
|
|
|
|
|
|
|
} |
2493
|
0
|
|
|
|
|
|
LDNS_FREE(str); |
2494
|
0
|
|
|
|
|
|
} |
2495
|
|
|
|
|
|
|
|
2496
|
|
|
|
|
|
|
void |
2497
|
0
|
|
|
|
|
|
ldns_rr_print_fmt(FILE *output, |
2498
|
|
|
|
|
|
|
const ldns_output_format *fmt, const ldns_rr *rr) |
2499
|
|
|
|
|
|
|
{ |
2500
|
0
|
|
|
|
|
|
char *str = ldns_rr2str_fmt(fmt, rr); |
2501
|
0
|
0
|
|
|
|
|
if (str) { |
2502
|
0
|
|
|
|
|
|
fprintf(output, "%s", str); |
2503
|
|
|
|
|
|
|
} else { |
2504
|
0
|
|
|
|
|
|
fprintf(output, ";Unable to convert rr to string\n"); |
2505
|
|
|
|
|
|
|
} |
2506
|
0
|
|
|
|
|
|
LDNS_FREE(str); |
2507
|
0
|
|
|
|
|
|
} |
2508
|
|
|
|
|
|
|
|
2509
|
|
|
|
|
|
|
void |
2510
|
0
|
|
|
|
|
|
ldns_rr_print(FILE *output, const ldns_rr *rr) |
2511
|
|
|
|
|
|
|
{ |
2512
|
0
|
|
|
|
|
|
ldns_rr_print_fmt(output, ldns_output_format_default, rr); |
2513
|
0
|
|
|
|
|
|
} |
2514
|
|
|
|
|
|
|
|
2515
|
|
|
|
|
|
|
void |
2516
|
0
|
|
|
|
|
|
ldns_pkt_print_fmt(FILE *output, |
2517
|
|
|
|
|
|
|
const ldns_output_format *fmt, const ldns_pkt *pkt) |
2518
|
|
|
|
|
|
|
{ |
2519
|
0
|
|
|
|
|
|
char *str = ldns_pkt2str_fmt(fmt, pkt); |
2520
|
0
|
0
|
|
|
|
|
if (str) { |
2521
|
0
|
|
|
|
|
|
fprintf(output, "%s", str); |
2522
|
|
|
|
|
|
|
} else { |
2523
|
0
|
|
|
|
|
|
fprintf(output, ";Unable to convert packet to string\n"); |
2524
|
|
|
|
|
|
|
} |
2525
|
0
|
|
|
|
|
|
LDNS_FREE(str); |
2526
|
0
|
|
|
|
|
|
} |
2527
|
|
|
|
|
|
|
|
2528
|
|
|
|
|
|
|
void |
2529
|
0
|
|
|
|
|
|
ldns_pkt_print(FILE *output, const ldns_pkt *pkt) |
2530
|
|
|
|
|
|
|
{ |
2531
|
0
|
|
|
|
|
|
ldns_pkt_print_fmt(output, ldns_output_format_default, pkt); |
2532
|
0
|
|
|
|
|
|
} |
2533
|
|
|
|
|
|
|
|
2534
|
|
|
|
|
|
|
void |
2535
|
0
|
|
|
|
|
|
ldns_rr_list_print_fmt(FILE *output, |
2536
|
|
|
|
|
|
|
const ldns_output_format *fmt, const ldns_rr_list *lst) |
2537
|
|
|
|
|
|
|
{ |
2538
|
|
|
|
|
|
|
size_t i; |
2539
|
0
|
0
|
|
|
|
|
for (i = 0; i < ldns_rr_list_rr_count(lst); i++) { |
2540
|
0
|
|
|
|
|
|
ldns_rr_print_fmt(output, fmt, ldns_rr_list_rr(lst, i)); |
2541
|
|
|
|
|
|
|
} |
2542
|
0
|
|
|
|
|
|
} |
2543
|
|
|
|
|
|
|
|
2544
|
|
|
|
|
|
|
void |
2545
|
0
|
|
|
|
|
|
ldns_rr_list_print(FILE *output, const ldns_rr_list *lst) |
2546
|
|
|
|
|
|
|
{ |
2547
|
0
|
|
|
|
|
|
ldns_rr_list_print_fmt(output, ldns_output_format_default, lst); |
2548
|
0
|
|
|
|
|
|
} |
2549
|
|
|
|
|
|
|
|
2550
|
|
|
|
|
|
|
void |
2551
|
0
|
|
|
|
|
|
ldns_resolver_print_fmt(FILE *output, |
2552
|
|
|
|
|
|
|
const ldns_output_format *fmt, const ldns_resolver *r) |
2553
|
|
|
|
|
|
|
{ |
2554
|
|
|
|
|
|
|
uint16_t i; |
2555
|
|
|
|
|
|
|
ldns_rdf **n; |
2556
|
|
|
|
|
|
|
ldns_rdf **s; |
2557
|
|
|
|
|
|
|
size_t *rtt; |
2558
|
0
|
0
|
|
|
|
|
if (!r) { |
2559
|
0
|
|
|
|
|
|
return; |
2560
|
|
|
|
|
|
|
} |
2561
|
0
|
|
|
|
|
|
n = ldns_resolver_nameservers(r); |
2562
|
0
|
|
|
|
|
|
s = ldns_resolver_searchlist(r); |
2563
|
0
|
|
|
|
|
|
rtt = ldns_resolver_rtt(r); |
2564
|
|
|
|
|
|
|
|
2565
|
0
|
|
|
|
|
|
fprintf(output, "port: %d\n", (int)ldns_resolver_port(r)); |
2566
|
0
|
|
|
|
|
|
fprintf(output, "edns0 size: %d\n", (int)ldns_resolver_edns_udp_size(r)); |
2567
|
0
|
|
|
|
|
|
fprintf(output, "use ip6: %d\n", (int)ldns_resolver_ip6(r)); |
2568
|
|
|
|
|
|
|
|
2569
|
0
|
|
|
|
|
|
fprintf(output, "recursive: %d\n", ldns_resolver_recursive(r)); |
2570
|
0
|
|
|
|
|
|
fprintf(output, "usevc: %d\n", ldns_resolver_usevc(r)); |
2571
|
0
|
|
|
|
|
|
fprintf(output, "igntc: %d\n", ldns_resolver_igntc(r)); |
2572
|
0
|
|
|
|
|
|
fprintf(output, "fail: %d\n", ldns_resolver_fail(r)); |
2573
|
0
|
|
|
|
|
|
fprintf(output, "retry: %d\n", (int)ldns_resolver_retry(r)); |
2574
|
0
|
|
|
|
|
|
fprintf(output, "retrans: %d\n", (int)ldns_resolver_retrans(r)); |
2575
|
0
|
|
|
|
|
|
fprintf(output, "fallback: %d\n", ldns_resolver_fallback(r)); |
2576
|
0
|
|
|
|
|
|
fprintf(output, "random: %d\n", ldns_resolver_random(r)); |
2577
|
0
|
|
|
|
|
|
fprintf(output, "timeout: %d\n", (int)ldns_resolver_timeout(r).tv_sec); |
2578
|
0
|
|
|
|
|
|
fprintf(output, "dnssec: %d\n", ldns_resolver_dnssec(r)); |
2579
|
0
|
|
|
|
|
|
fprintf(output, "dnssec cd: %d\n", ldns_resolver_dnssec_cd(r)); |
2580
|
0
|
|
|
|
|
|
fprintf(output, "trust anchors (%d listed):\n", |
2581
|
0
|
|
|
|
|
|
(int)ldns_rr_list_rr_count(ldns_resolver_dnssec_anchors(r))); |
2582
|
0
|
|
|
|
|
|
ldns_rr_list_print_fmt(output, fmt, ldns_resolver_dnssec_anchors(r)); |
2583
|
0
|
0
|
|
|
|
|
fprintf(output, "tsig: %s %s\n", |
|
|
0
|
|
|
|
|
|
2584
|
0
|
|
|
|
|
|
ldns_resolver_tsig_keyname(r)?ldns_resolver_tsig_keyname(r):"-", |
2585
|
0
|
|
|
|
|
|
ldns_resolver_tsig_algorithm(r)?ldns_resolver_tsig_algorithm(r):"-"); |
2586
|
0
|
|
|
|
|
|
fprintf(output, "debug: %d\n", ldns_resolver_debug(r)); |
2587
|
|
|
|
|
|
|
|
2588
|
0
|
|
|
|
|
|
fprintf(output, "default domain: "); |
2589
|
0
|
|
|
|
|
|
ldns_rdf_print(output, ldns_resolver_domain(r)); |
2590
|
0
|
|
|
|
|
|
fprintf(output, "\n"); |
2591
|
0
|
|
|
|
|
|
fprintf(output, "apply default domain: %d\n", ldns_resolver_defnames(r)); |
2592
|
|
|
|
|
|
|
|
2593
|
0
|
|
|
|
|
|
fprintf(output, "searchlist (%d listed):\n", (int)ldns_resolver_searchlist_count(r)); |
2594
|
0
|
0
|
|
|
|
|
for (i = 0; i < ldns_resolver_searchlist_count(r); i++) { |
2595
|
0
|
|
|
|
|
|
fprintf(output, "\t"); |
2596
|
0
|
|
|
|
|
|
ldns_rdf_print(output, s[i]); |
2597
|
0
|
|
|
|
|
|
fprintf(output, "\n"); |
2598
|
|
|
|
|
|
|
} |
2599
|
0
|
|
|
|
|
|
fprintf(output, "apply search list: %d\n", ldns_resolver_dnsrch(r)); |
2600
|
|
|
|
|
|
|
|
2601
|
0
|
|
|
|
|
|
fprintf(output, "nameservers (%d listed):\n", (int)ldns_resolver_nameserver_count(r)); |
2602
|
0
|
0
|
|
|
|
|
for (i = 0; i < ldns_resolver_nameserver_count(r); i++) { |
2603
|
0
|
|
|
|
|
|
fprintf(output, "\t"); |
2604
|
0
|
|
|
|
|
|
ldns_rdf_print(output, n[i]); |
2605
|
|
|
|
|
|
|
|
2606
|
0
|
|
|
|
|
|
switch ((int)rtt[i]) { |
2607
|
|
|
|
|
|
|
case LDNS_RESOLV_RTT_MIN: |
2608
|
0
|
|
|
|
|
|
fprintf(output, " - reachable\n"); |
2609
|
0
|
|
|
|
|
|
break; |
2610
|
|
|
|
|
|
|
case LDNS_RESOLV_RTT_INF: |
2611
|
0
|
|
|
|
|
|
fprintf(output, " - unreachable\n"); |
2612
|
0
|
|
|
|
|
|
break; |
2613
|
|
|
|
|
|
|
} |
2614
|
|
|
|
|
|
|
} |
2615
|
|
|
|
|
|
|
} |
2616
|
|
|
|
|
|
|
|
2617
|
|
|
|
|
|
|
void |
2618
|
0
|
|
|
|
|
|
ldns_resolver_print(FILE *output, const ldns_resolver *r) |
2619
|
|
|
|
|
|
|
{ |
2620
|
0
|
|
|
|
|
|
ldns_resolver_print_fmt(output, ldns_output_format_default, r); |
2621
|
0
|
|
|
|
|
|
} |
2622
|
|
|
|
|
|
|
|
2623
|
|
|
|
|
|
|
void |
2624
|
0
|
|
|
|
|
|
ldns_zone_print_fmt(FILE *output, |
2625
|
|
|
|
|
|
|
const ldns_output_format *fmt, const ldns_zone *z) |
2626
|
|
|
|
|
|
|
{ |
2627
|
0
|
0
|
|
|
|
|
if(ldns_zone_soa(z)) |
2628
|
0
|
|
|
|
|
|
ldns_rr_print_fmt(output, fmt, ldns_zone_soa(z)); |
2629
|
0
|
|
|
|
|
|
ldns_rr_list_print_fmt(output, fmt, ldns_zone_rrs(z)); |
2630
|
0
|
|
|
|
|
|
} |
2631
|
|
|
|
|
|
|
void |
2632
|
0
|
|
|
|
|
|
ldns_zone_print(FILE *output, const ldns_zone *z) |
2633
|
|
|
|
|
|
|
{ |
2634
|
0
|
|
|
|
|
|
ldns_zone_print_fmt(output, ldns_output_format_default, z); |
2635
|
0
|
|
|
|
|
|
} |