soa_6.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004, 2007, 2009, 2011, 2012, 2014, 2015  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 1998-2002  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 /* $Id$ */
00019 
00020 /* Reviewed: Thu Mar 16 15:18:32 PST 2000 by explorer */
00021 
00022 #ifndef RDATA_GENERIC_SOA_6_C
00023 #define RDATA_GENERIC_SOA_6_C
00024 
00025 #define RRTYPE_SOA_ATTRIBUTES (DNS_RDATATYPEATTR_SINGLETON)
00026 
00027 static inline isc_result_t
00028 fromtext_soa(ARGS_FROMTEXT) {
00029         isc_token_t token;
00030         dns_name_t name;
00031         isc_buffer_t buffer;
00032         int i;
00033         isc_uint32_t n;
00034         isc_boolean_t ok;
00035 
00036         REQUIRE(type == 6);
00037 
00038         UNUSED(type);
00039         UNUSED(rdclass);
00040         UNUSED(callbacks);
00041 
00042         origin = (origin != NULL) ? origin : dns_rootname;
00043 
00044         for (i = 0; i < 2; i++) {
00045                 RETERR(isc_lex_getmastertoken(lexer, &token,
00046                                               isc_tokentype_string,
00047                                               ISC_FALSE));
00048 
00049                 dns_name_init(&name, NULL);
00050                 buffer_fromregion(&buffer, &token.value.as_region);
00051                 RETTOK(dns_name_fromtext(&name, &buffer, origin,
00052                                          options, target));
00053                 ok = ISC_TRUE;
00054                 if ((options & DNS_RDATA_CHECKNAMES) != 0)
00055                         switch (i) {
00056                         case 0:
00057                                 ok = dns_name_ishostname(&name, ISC_FALSE);
00058                                 break;
00059                         case 1:
00060                                 ok = dns_name_ismailbox(&name);
00061                                 break;
00062 
00063                         }
00064                 if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0)
00065                         RETTOK(DNS_R_BADNAME);
00066                 if (!ok && callbacks != NULL)
00067                         warn_badname(&name, lexer, callbacks);
00068         }
00069 
00070         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
00071                                       ISC_FALSE));
00072         RETERR(uint32_tobuffer(token.value.as_ulong, target));
00073 
00074         for (i = 0; i < 4; i++) {
00075                 RETERR(isc_lex_getmastertoken(lexer, &token,
00076                                               isc_tokentype_string,
00077                                               ISC_FALSE));
00078                 RETTOK(dns_counter_fromtext(&token.value.as_textregion, &n));
00079                 RETERR(uint32_tobuffer(n, target));
00080         }
00081 
00082         return (ISC_R_SUCCESS);
00083 }
00084 
00085 static const char *soa_fieldnames[5] = {
00086         "serial", "refresh", "retry", "expire", "minimum"
00087 };
00088 
00089 static inline isc_result_t
00090 totext_soa(ARGS_TOTEXT) {
00091         isc_region_t dregion;
00092         dns_name_t mname;
00093         dns_name_t rname;
00094         dns_name_t prefix;
00095         isc_boolean_t sub;
00096         int i;
00097         isc_boolean_t multiline;
00098         isc_boolean_t comm;
00099 
00100         REQUIRE(rdata->type == 6);
00101         REQUIRE(rdata->length != 0);
00102 
00103         multiline = ISC_TF((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0);
00104         if (multiline)
00105                 comm = ISC_TF((tctx->flags & DNS_STYLEFLAG_RRCOMMENT) != 0);
00106         else
00107                 comm = ISC_FALSE;
00108 
00109 
00110         dns_name_init(&mname, NULL);
00111         dns_name_init(&rname, NULL);
00112         dns_name_init(&prefix, NULL);
00113 
00114         dns_rdata_toregion(rdata, &dregion);
00115 
00116         dns_name_fromregion(&mname, &dregion);
00117         isc_region_consume(&dregion, name_length(&mname));
00118 
00119         dns_name_fromregion(&rname, &dregion);
00120         isc_region_consume(&dregion, name_length(&rname));
00121 
00122         sub = name_prefix(&mname, tctx->origin, &prefix);
00123         RETERR(dns_name_totext(&prefix, sub, target));
00124 
00125         RETERR(str_totext(" ", target));
00126 
00127         sub = name_prefix(&rname, tctx->origin, &prefix);
00128         RETERR(dns_name_totext(&prefix, sub, target));
00129 
00130         if (multiline)
00131                 RETERR(str_totext(" (" , target));
00132         RETERR(str_totext(tctx->linebreak, target));
00133 
00134         for (i = 0; i < 5; i++) {
00135                 char buf[sizeof("0123456789 ; ")];
00136                 unsigned long num;
00137                 num = uint32_fromregion(&dregion);
00138                 isc_region_consume(&dregion, 4);
00139                 sprintf(buf, comm ? "%-10lu ; " : "%lu", num);
00140                 RETERR(str_totext(buf, target));
00141                 if (comm) {
00142                         RETERR(str_totext(soa_fieldnames[i], target));
00143                         /* Print times in week/day/hour/minute/second form */
00144                         if (i >= 1) {
00145                                 RETERR(str_totext(" (", target));
00146                                 RETERR(dns_ttl_totext(num, ISC_TRUE, target));
00147                                 RETERR(str_totext(")", target));
00148                         }
00149                         RETERR(str_totext(tctx->linebreak, target));
00150                 } else if (i < 4) {
00151                         RETERR(str_totext(tctx->linebreak, target));
00152                 }
00153         }
00154 
00155         if (multiline)
00156                 RETERR(str_totext(")", target));
00157 
00158         return (ISC_R_SUCCESS);
00159 }
00160 
00161 static inline isc_result_t
00162 fromwire_soa(ARGS_FROMWIRE) {
00163         dns_name_t mname;
00164         dns_name_t rname;
00165         isc_region_t sregion;
00166         isc_region_t tregion;
00167 
00168         REQUIRE(type == 6);
00169 
00170         UNUSED(type);
00171         UNUSED(rdclass);
00172 
00173         dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
00174 
00175         dns_name_init(&mname, NULL);
00176         dns_name_init(&rname, NULL);
00177 
00178         RETERR(dns_name_fromwire(&mname, source, dctx, options, target));
00179         RETERR(dns_name_fromwire(&rname, source, dctx, options, target));
00180 
00181         isc_buffer_activeregion(source, &sregion);
00182         isc_buffer_availableregion(target, &tregion);
00183 
00184         if (sregion.length < 20)
00185                 return (ISC_R_UNEXPECTEDEND);
00186         if (tregion.length < 20)
00187                 return (ISC_R_NOSPACE);
00188 
00189         memmove(tregion.base, sregion.base, 20);
00190         isc_buffer_forward(source, 20);
00191         isc_buffer_add(target, 20);
00192 
00193         return (ISC_R_SUCCESS);
00194 }
00195 
00196 static inline isc_result_t
00197 towire_soa(ARGS_TOWIRE) {
00198         isc_region_t sregion;
00199         isc_region_t tregion;
00200         dns_name_t mname;
00201         dns_name_t rname;
00202         dns_offsets_t moffsets;
00203         dns_offsets_t roffsets;
00204 
00205         REQUIRE(rdata->type == 6);
00206         REQUIRE(rdata->length != 0);
00207 
00208         dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
00209 
00210         dns_name_init(&mname, moffsets);
00211         dns_name_init(&rname, roffsets);
00212 
00213         dns_rdata_toregion(rdata, &sregion);
00214 
00215         dns_name_fromregion(&mname, &sregion);
00216         isc_region_consume(&sregion, name_length(&mname));
00217         RETERR(dns_name_towire(&mname, cctx, target));
00218 
00219         dns_name_fromregion(&rname, &sregion);
00220         isc_region_consume(&sregion, name_length(&rname));
00221         RETERR(dns_name_towire(&rname, cctx, target));
00222 
00223         isc_buffer_availableregion(target, &tregion);
00224         if (tregion.length < 20)
00225                 return (ISC_R_NOSPACE);
00226 
00227         memmove(tregion.base, sregion.base, 20);
00228         isc_buffer_add(target, 20);
00229         return (ISC_R_SUCCESS);
00230 }
00231 
00232 static inline int
00233 compare_soa(ARGS_COMPARE) {
00234         isc_region_t region1;
00235         isc_region_t region2;
00236         dns_name_t name1;
00237         dns_name_t name2;
00238         int order;
00239 
00240         REQUIRE(rdata1->type == rdata2->type);
00241         REQUIRE(rdata1->rdclass == rdata2->rdclass);
00242         REQUIRE(rdata1->type == 6);
00243         REQUIRE(rdata1->length != 0);
00244         REQUIRE(rdata2->length != 0);
00245 
00246         dns_name_init(&name1, NULL);
00247         dns_name_init(&name2, NULL);
00248 
00249         dns_rdata_toregion(rdata1, &region1);
00250         dns_rdata_toregion(rdata2, &region2);
00251 
00252         dns_name_fromregion(&name1, &region1);
00253         dns_name_fromregion(&name2, &region2);
00254 
00255         order = dns_name_rdatacompare(&name1, &name2);
00256         if (order != 0)
00257                 return (order);
00258 
00259         isc_region_consume(&region1, name_length(&name1));
00260         isc_region_consume(&region2, name_length(&name2));
00261 
00262         dns_name_init(&name1, NULL);
00263         dns_name_init(&name2, NULL);
00264 
00265         dns_name_fromregion(&name1, &region1);
00266         dns_name_fromregion(&name2, &region2);
00267 
00268         order = dns_name_rdatacompare(&name1, &name2);
00269         if (order != 0)
00270                 return (order);
00271 
00272         isc_region_consume(&region1, name_length(&name1));
00273         isc_region_consume(&region2, name_length(&name2));
00274 
00275         return (isc_region_compare(&region1, &region2));
00276 }
00277 
00278 static inline isc_result_t
00279 fromstruct_soa(ARGS_FROMSTRUCT) {
00280         dns_rdata_soa_t *soa = source;
00281         isc_region_t region;
00282 
00283         REQUIRE(type == 6);
00284         REQUIRE(source != NULL);
00285         REQUIRE(soa->common.rdtype == type);
00286         REQUIRE(soa->common.rdclass == rdclass);
00287 
00288         UNUSED(type);
00289         UNUSED(rdclass);
00290 
00291         dns_name_toregion(&soa->origin, &region);
00292         RETERR(isc_buffer_copyregion(target, &region));
00293         dns_name_toregion(&soa->contact, &region);
00294         RETERR(isc_buffer_copyregion(target, &region));
00295         RETERR(uint32_tobuffer(soa->serial, target));
00296         RETERR(uint32_tobuffer(soa->refresh, target));
00297         RETERR(uint32_tobuffer(soa->retry, target));
00298         RETERR(uint32_tobuffer(soa->expire, target));
00299         return (uint32_tobuffer(soa->minimum, target));
00300 }
00301 
00302 static inline isc_result_t
00303 tostruct_soa(ARGS_TOSTRUCT) {
00304         isc_region_t region;
00305         dns_rdata_soa_t *soa = target;
00306         dns_name_t name;
00307         isc_result_t result;
00308 
00309         REQUIRE(rdata->type == 6);
00310         REQUIRE(target != NULL);
00311         REQUIRE(rdata->length != 0);
00312 
00313         soa->common.rdclass = rdata->rdclass;
00314         soa->common.rdtype = rdata->type;
00315         ISC_LINK_INIT(&soa->common, link);
00316 
00317 
00318         dns_rdata_toregion(rdata, &region);
00319 
00320         dns_name_init(&name, NULL);
00321         dns_name_fromregion(&name, &region);
00322         isc_region_consume(&region, name_length(&name));
00323         dns_name_init(&soa->origin, NULL);
00324         RETERR(name_duporclone(&name, mctx, &soa->origin));
00325 
00326         dns_name_fromregion(&name, &region);
00327         isc_region_consume(&region, name_length(&name));
00328         dns_name_init(&soa->contact, NULL);
00329         result = name_duporclone(&name, mctx, &soa->contact);
00330         if (result != ISC_R_SUCCESS)
00331                 goto cleanup;
00332 
00333         soa->serial = uint32_fromregion(&region);
00334         isc_region_consume(&region, 4);
00335 
00336         soa->refresh = uint32_fromregion(&region);
00337         isc_region_consume(&region, 4);
00338 
00339         soa->retry = uint32_fromregion(&region);
00340         isc_region_consume(&region, 4);
00341 
00342         soa->expire = uint32_fromregion(&region);
00343         isc_region_consume(&region, 4);
00344 
00345         soa->minimum = uint32_fromregion(&region);
00346 
00347         soa->mctx = mctx;
00348         return (ISC_R_SUCCESS);
00349 
00350  cleanup:
00351         if (mctx != NULL)
00352                 dns_name_free(&soa->origin, mctx);
00353         return (ISC_R_NOMEMORY);
00354 }
00355 
00356 static inline void
00357 freestruct_soa(ARGS_FREESTRUCT) {
00358         dns_rdata_soa_t *soa = source;
00359 
00360         REQUIRE(source != NULL);
00361         REQUIRE(soa->common.rdtype == 6);
00362 
00363         if (soa->mctx == NULL)
00364                 return;
00365 
00366         dns_name_free(&soa->origin, soa->mctx);
00367         dns_name_free(&soa->contact, soa->mctx);
00368         soa->mctx = NULL;
00369 }
00370 
00371 static inline isc_result_t
00372 additionaldata_soa(ARGS_ADDLDATA) {
00373         UNUSED(rdata);
00374         UNUSED(add);
00375         UNUSED(arg);
00376 
00377         REQUIRE(rdata->type == 6);
00378 
00379         return (ISC_R_SUCCESS);
00380 }
00381 
00382 static inline isc_result_t
00383 digest_soa(ARGS_DIGEST) {
00384         isc_region_t r;
00385         dns_name_t name;
00386 
00387         REQUIRE(rdata->type == 6);
00388 
00389         dns_rdata_toregion(rdata, &r);
00390 
00391         dns_name_init(&name, NULL);
00392         dns_name_fromregion(&name, &r);
00393         RETERR(dns_name_digest(&name, digest, arg));
00394         isc_region_consume(&r, name_length(&name));
00395 
00396         dns_name_init(&name, NULL);
00397         dns_name_fromregion(&name, &r);
00398         RETERR(dns_name_digest(&name, digest, arg));
00399         isc_region_consume(&r, name_length(&name));
00400 
00401         return ((digest)(arg, &r));
00402 }
00403 
00404 static inline isc_boolean_t
00405 checkowner_soa(ARGS_CHECKOWNER) {
00406 
00407         REQUIRE(type == 6);
00408 
00409         UNUSED(name);
00410         UNUSED(type);
00411         UNUSED(rdclass);
00412         UNUSED(wildcard);
00413 
00414         return (ISC_TRUE);
00415 }
00416 
00417 static inline isc_boolean_t
00418 checknames_soa(ARGS_CHECKNAMES) {
00419         isc_region_t region;
00420         dns_name_t name;
00421 
00422         REQUIRE(rdata->type == 6);
00423 
00424         UNUSED(owner);
00425 
00426         dns_rdata_toregion(rdata, &region);
00427         dns_name_init(&name, NULL);
00428         dns_name_fromregion(&name, &region);
00429         if (!dns_name_ishostname(&name, ISC_FALSE)) {
00430                 if (bad != NULL)
00431                         dns_name_clone(&name, bad);
00432                 return (ISC_FALSE);
00433         }
00434         isc_region_consume(&region, name_length(&name));
00435         dns_name_fromregion(&name, &region);
00436         if (!dns_name_ismailbox(&name)) {
00437                 if (bad != NULL)
00438                         dns_name_clone(&name, bad);
00439                 return (ISC_FALSE);
00440         }
00441         return (ISC_TRUE);
00442 }
00443 
00444 static inline int
00445 casecompare_soa(ARGS_COMPARE) {
00446         return (compare_soa(rdata1, rdata2));
00447 }
00448 
00449 #endif  /* RDATA_GENERIC_SOA_6_C */

Generated on Tue Apr 28 17:41:00 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha