Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / lib / dns / rdata / generic / soa_6.c
blob3c168fe1432e7bdc9c1ccca30bb6f486f537b017
1 /* $NetBSD: soa_6.c,v 1.6 2014/12/10 04:37:59 christos Exp $ */
3 /*
4 * Copyright (C) 2004, 2007, 2009, 2011, 2012, 2014 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1998-2002 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id */
22 /* Reviewed: Thu Mar 16 15:18:32 PST 2000 by explorer */
24 #ifndef RDATA_GENERIC_SOA_6_C
25 #define RDATA_GENERIC_SOA_6_C
27 #define RRTYPE_SOA_ATTRIBUTES (DNS_RDATATYPEATTR_SINGLETON)
29 static inline isc_result_t
30 fromtext_soa(ARGS_FROMTEXT) {
31 isc_token_t token;
32 dns_name_t name;
33 isc_buffer_t buffer;
34 int i;
35 isc_uint32_t n;
36 isc_boolean_t ok;
38 REQUIRE(type == 6);
40 UNUSED(type);
41 UNUSED(rdclass);
42 UNUSED(callbacks);
44 origin = (origin != NULL) ? origin : dns_rootname;
46 for (i = 0; i < 2; i++) {
47 RETERR(isc_lex_getmastertoken(lexer, &token,
48 isc_tokentype_string,
49 ISC_FALSE));
51 dns_name_init(&name, NULL);
52 buffer_fromregion(&buffer, &token.value.as_region);
53 RETTOK(dns_name_fromtext(&name, &buffer, origin,
54 options, target));
55 ok = ISC_TRUE;
56 if ((options & DNS_RDATA_CHECKNAMES) != 0)
57 switch (i) {
58 case 0:
59 ok = dns_name_ishostname(&name, ISC_FALSE);
60 break;
61 case 1:
62 ok = dns_name_ismailbox(&name);
63 break;
66 if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0)
67 RETTOK(DNS_R_BADNAME);
68 if (!ok && callbacks != NULL)
69 warn_badname(&name, lexer, callbacks);
72 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
73 ISC_FALSE));
74 RETERR(uint32_tobuffer(token.value.as_ulong, target));
76 for (i = 0; i < 4; i++) {
77 RETERR(isc_lex_getmastertoken(lexer, &token,
78 isc_tokentype_string,
79 ISC_FALSE));
80 RETTOK(dns_counter_fromtext(&token.value.as_textregion, &n));
81 RETERR(uint32_tobuffer(n, target));
84 return (ISC_R_SUCCESS);
87 static const char *soa_fieldnames[5] = {
88 "serial", "refresh", "retry", "expire", "minimum"
91 static inline isc_result_t
92 totext_soa(ARGS_TOTEXT) {
93 isc_region_t dregion;
94 dns_name_t mname;
95 dns_name_t rname;
96 dns_name_t prefix;
97 isc_boolean_t sub;
98 int i;
99 isc_boolean_t multiline;
100 isc_boolean_t comment;
102 REQUIRE(rdata->type == 6);
103 REQUIRE(rdata->length != 0);
105 multiline = ISC_TF((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0);
106 if (multiline)
107 comment = ISC_TF((tctx->flags & DNS_STYLEFLAG_RRCOMMENT) != 0);
108 else
109 comment = ISC_FALSE;
112 dns_name_init(&mname, NULL);
113 dns_name_init(&rname, NULL);
114 dns_name_init(&prefix, NULL);
116 dns_rdata_toregion(rdata, &dregion);
118 dns_name_fromregion(&mname, &dregion);
119 isc_region_consume(&dregion, name_length(&mname));
121 dns_name_fromregion(&rname, &dregion);
122 isc_region_consume(&dregion, name_length(&rname));
124 sub = name_prefix(&mname, tctx->origin, &prefix);
125 RETERR(dns_name_totext(&prefix, sub, target));
127 RETERR(str_totext(" ", target));
129 sub = name_prefix(&rname, tctx->origin, &prefix);
130 RETERR(dns_name_totext(&prefix, sub, target));
132 if (multiline)
133 RETERR(str_totext(" (" , target));
134 RETERR(str_totext(tctx->linebreak, target));
136 for (i = 0; i < 5; i++) {
137 char buf[sizeof("0123456789 ; ")];
138 unsigned long num;
139 num = uint32_fromregion(&dregion);
140 isc_region_consume(&dregion, 4);
141 sprintf(buf, comment ? "%-10lu ; " : "%lu", num);
142 RETERR(str_totext(buf, target));
143 if (comment) {
144 RETERR(str_totext(soa_fieldnames[i], target));
145 /* Print times in week/day/hour/minute/second form */
146 if (i >= 1) {
147 RETERR(str_totext(" (", target));
148 RETERR(dns_ttl_totext(num, ISC_TRUE, target));
149 RETERR(str_totext(")", target));
151 RETERR(str_totext(tctx->linebreak, target));
152 } else if (i < 4) {
153 RETERR(str_totext(tctx->linebreak, target));
157 if (multiline)
158 RETERR(str_totext(")", target));
160 return (ISC_R_SUCCESS);
163 static inline isc_result_t
164 fromwire_soa(ARGS_FROMWIRE) {
165 dns_name_t mname;
166 dns_name_t rname;
167 isc_region_t sregion;
168 isc_region_t tregion;
170 REQUIRE(type == 6);
172 UNUSED(type);
173 UNUSED(rdclass);
175 dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
177 dns_name_init(&mname, NULL);
178 dns_name_init(&rname, NULL);
180 RETERR(dns_name_fromwire(&mname, source, dctx, options, target));
181 RETERR(dns_name_fromwire(&rname, source, dctx, options, target));
183 isc_buffer_activeregion(source, &sregion);
184 isc_buffer_availableregion(target, &tregion);
186 if (sregion.length < 20)
187 return (ISC_R_UNEXPECTEDEND);
188 if (tregion.length < 20)
189 return (ISC_R_NOSPACE);
191 memmove(tregion.base, sregion.base, 20);
192 isc_buffer_forward(source, 20);
193 isc_buffer_add(target, 20);
195 return (ISC_R_SUCCESS);
198 static inline isc_result_t
199 towire_soa(ARGS_TOWIRE) {
200 isc_region_t sregion;
201 isc_region_t tregion;
202 dns_name_t mname;
203 dns_name_t rname;
204 dns_offsets_t moffsets;
205 dns_offsets_t roffsets;
207 REQUIRE(rdata->type == 6);
208 REQUIRE(rdata->length != 0);
210 dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
212 dns_name_init(&mname, moffsets);
213 dns_name_init(&rname, roffsets);
215 dns_rdata_toregion(rdata, &sregion);
217 dns_name_fromregion(&mname, &sregion);
218 isc_region_consume(&sregion, name_length(&mname));
219 RETERR(dns_name_towire(&mname, cctx, target));
221 dns_name_fromregion(&rname, &sregion);
222 isc_region_consume(&sregion, name_length(&rname));
223 RETERR(dns_name_towire(&rname, cctx, target));
225 isc_buffer_availableregion(target, &tregion);
226 if (tregion.length < 20)
227 return (ISC_R_NOSPACE);
229 memmove(tregion.base, sregion.base, 20);
230 isc_buffer_add(target, 20);
231 return (ISC_R_SUCCESS);
234 static inline int
235 compare_soa(ARGS_COMPARE) {
236 isc_region_t region1;
237 isc_region_t region2;
238 dns_name_t name1;
239 dns_name_t name2;
240 int order;
242 REQUIRE(rdata1->type == rdata2->type);
243 REQUIRE(rdata1->rdclass == rdata2->rdclass);
244 REQUIRE(rdata1->type == 6);
245 REQUIRE(rdata1->length != 0);
246 REQUIRE(rdata2->length != 0);
248 dns_name_init(&name1, NULL);
249 dns_name_init(&name2, NULL);
251 dns_rdata_toregion(rdata1, &region1);
252 dns_rdata_toregion(rdata2, &region2);
254 dns_name_fromregion(&name1, &region1);
255 dns_name_fromregion(&name2, &region2);
257 order = dns_name_rdatacompare(&name1, &name2);
258 if (order != 0)
259 return (order);
261 isc_region_consume(&region1, name_length(&name1));
262 isc_region_consume(&region2, name_length(&name2));
264 dns_name_init(&name1, NULL);
265 dns_name_init(&name2, NULL);
267 dns_name_fromregion(&name1, &region1);
268 dns_name_fromregion(&name2, &region2);
270 order = dns_name_rdatacompare(&name1, &name2);
271 if (order != 0)
272 return (order);
274 isc_region_consume(&region1, name_length(&name1));
275 isc_region_consume(&region2, name_length(&name2));
277 return (isc_region_compare(&region1, &region2));
280 static inline isc_result_t
281 fromstruct_soa(ARGS_FROMSTRUCT) {
282 dns_rdata_soa_t *soa = source;
283 isc_region_t region;
285 REQUIRE(type == 6);
286 REQUIRE(source != NULL);
287 REQUIRE(soa->common.rdtype == type);
288 REQUIRE(soa->common.rdclass == rdclass);
290 UNUSED(type);
291 UNUSED(rdclass);
293 dns_name_toregion(&soa->origin, &region);
294 RETERR(isc_buffer_copyregion(target, &region));
295 dns_name_toregion(&soa->contact, &region);
296 RETERR(isc_buffer_copyregion(target, &region));
297 RETERR(uint32_tobuffer(soa->serial, target));
298 RETERR(uint32_tobuffer(soa->refresh, target));
299 RETERR(uint32_tobuffer(soa->retry, target));
300 RETERR(uint32_tobuffer(soa->expire, target));
301 return (uint32_tobuffer(soa->minimum, target));
304 static inline isc_result_t
305 tostruct_soa(ARGS_TOSTRUCT) {
306 isc_region_t region;
307 dns_rdata_soa_t *soa = target;
308 dns_name_t name;
309 isc_result_t result;
311 REQUIRE(rdata->type == 6);
312 REQUIRE(target != NULL);
313 REQUIRE(rdata->length != 0);
315 soa->common.rdclass = rdata->rdclass;
316 soa->common.rdtype = rdata->type;
317 ISC_LINK_INIT(&soa->common, link);
320 dns_rdata_toregion(rdata, &region);
322 dns_name_init(&name, NULL);
323 dns_name_fromregion(&name, &region);
324 isc_region_consume(&region, name_length(&name));
325 dns_name_init(&soa->origin, NULL);
326 RETERR(name_duporclone(&name, mctx, &soa->origin));
328 dns_name_fromregion(&name, &region);
329 isc_region_consume(&region, name_length(&name));
330 dns_name_init(&soa->contact, NULL);
331 result = name_duporclone(&name, mctx, &soa->contact);
332 if (result != ISC_R_SUCCESS)
333 goto cleanup;
335 soa->serial = uint32_fromregion(&region);
336 isc_region_consume(&region, 4);
338 soa->refresh = uint32_fromregion(&region);
339 isc_region_consume(&region, 4);
341 soa->retry = uint32_fromregion(&region);
342 isc_region_consume(&region, 4);
344 soa->expire = uint32_fromregion(&region);
345 isc_region_consume(&region, 4);
347 soa->minimum = uint32_fromregion(&region);
349 soa->mctx = mctx;
350 return (ISC_R_SUCCESS);
352 cleanup:
353 if (mctx != NULL)
354 dns_name_free(&soa->origin, mctx);
355 return (ISC_R_NOMEMORY);
358 static inline void
359 freestruct_soa(ARGS_FREESTRUCT) {
360 dns_rdata_soa_t *soa = source;
362 REQUIRE(source != NULL);
363 REQUIRE(soa->common.rdtype == 6);
365 if (soa->mctx == NULL)
366 return;
368 dns_name_free(&soa->origin, soa->mctx);
369 dns_name_free(&soa->contact, soa->mctx);
370 soa->mctx = NULL;
373 static inline isc_result_t
374 additionaldata_soa(ARGS_ADDLDATA) {
375 UNUSED(rdata);
376 UNUSED(add);
377 UNUSED(arg);
379 REQUIRE(rdata->type == 6);
381 return (ISC_R_SUCCESS);
384 static inline isc_result_t
385 digest_soa(ARGS_DIGEST) {
386 isc_region_t r;
387 dns_name_t name;
389 REQUIRE(rdata->type == 6);
391 dns_rdata_toregion(rdata, &r);
393 dns_name_init(&name, NULL);
394 dns_name_fromregion(&name, &r);
395 RETERR(dns_name_digest(&name, digest, arg));
396 isc_region_consume(&r, name_length(&name));
398 dns_name_init(&name, NULL);
399 dns_name_fromregion(&name, &r);
400 RETERR(dns_name_digest(&name, digest, arg));
401 isc_region_consume(&r, name_length(&name));
403 return ((digest)(arg, &r));
406 static inline isc_boolean_t
407 checkowner_soa(ARGS_CHECKOWNER) {
409 REQUIRE(type == 6);
411 UNUSED(name);
412 UNUSED(type);
413 UNUSED(rdclass);
414 UNUSED(wildcard);
416 return (ISC_TRUE);
419 static inline isc_boolean_t
420 checknames_soa(ARGS_CHECKNAMES) {
421 isc_region_t region;
422 dns_name_t name;
424 REQUIRE(rdata->type == 6);
426 UNUSED(owner);
428 dns_rdata_toregion(rdata, &region);
429 dns_name_init(&name, NULL);
430 dns_name_fromregion(&name, &region);
431 if (!dns_name_ishostname(&name, ISC_FALSE)) {
432 if (bad != NULL)
433 dns_name_clone(&name, bad);
434 return (ISC_FALSE);
436 isc_region_consume(&region, name_length(&name));
437 dns_name_fromregion(&name, &region);
438 if (!dns_name_ismailbox(&name)) {
439 if (bad != NULL)
440 dns_name_clone(&name, bad);
441 return (ISC_FALSE);
443 return (ISC_TRUE);
446 static inline int
447 casecompare_soa(ARGS_COMPARE) {
448 return (compare_soa(rdata1, rdata2));
451 #endif /* RDATA_GENERIC_SOA_6_C */