/* * Puts resource record data on 'db'. */ isc_result_t bdb_putrdata(DB *db, dns_name_t *name, dns_ttl_t ttl, dns_rdata_t *rdata) { static DBT key, data; isc_buffer_t keybuf, databuf; char nametext[DNS_NAME_MAXTEXT]; char rdatatext[MAX_RDATATEXT]; isc_buffer_init(&keybuf, nametext, DNS_NAME_MAXTEXT); dns_name_totext(name, ISC_TRUE, &keybuf); key.data = isc_buffer_base(&keybuf); key.size = isc_buffer_usedlength(&keybuf); isc_buffer_init(&databuf, rdatatext, MAX_RDATATEXT); dns_ttl_totext(ttl, ISC_FALSE, &databuf); *(char *)isc_buffer_used(&databuf) = ' '; isc_buffer_add(&databuf, 1); dns_rdatatype_totext(rdata->type, &databuf); /* XXX private data */ *(char *)isc_buffer_used(&databuf) = ' '; isc_buffer_add(&databuf, 1); dns_rdata_totext(rdata, NULL, &databuf); data.data = isc_buffer_base(&databuf); data.size = isc_buffer_usedlength(&databuf); REQUIRE(db->put(db, NULL, &key, &data, 0) == 0); return ISC_R_SUCCESS; }
static inline isc_result_t totext_soa(ARGS_TOTEXT) { isc_region_t dregion; dns_name_t mname; dns_name_t rname; dns_name_t prefix; isc_boolean_t sub; int i; isc_boolean_t multiline; isc_boolean_t comment; REQUIRE(rdata->type == 6); REQUIRE(rdata->length != 0); multiline = ISC_TF((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0); if (multiline) comment = ISC_TF((tctx->flags & DNS_STYLEFLAG_RRCOMMENT) != 0); else comment = ISC_FALSE; dns_name_init(&mname, NULL); dns_name_init(&rname, NULL); dns_name_init(&prefix, NULL); dns_rdata_toregion(rdata, &dregion); dns_name_fromregion(&mname, &dregion); isc_region_consume(&dregion, name_length(&mname)); dns_name_fromregion(&rname, &dregion); isc_region_consume(&dregion, name_length(&rname)); sub = name_prefix(&mname, tctx->origin, &prefix); RETERR(dns_name_totext(&prefix, sub, target)); RETERR(str_totext(" ", target)); sub = name_prefix(&rname, tctx->origin, &prefix); RETERR(dns_name_totext(&prefix, sub, target)); if (multiline) RETERR(str_totext(" (" , target)); RETERR(str_totext(tctx->linebreak, target)); for (i = 0; i < 5; i++) { unsigned long num; unsigned int len = target->used; num = uint32_fromregion(&dregion); isc_region_consume(&dregion, 4); if (i >= 1 && (tctx->flags & DNS_STYLEFLAG_TTL_UNITS) != 0) { RETERR(dns_ttl_totext(num, ISC_FALSE, target)); } else { char buf[12]; sprintf(buf, "%lu", num); RETERR(str_totext(buf, target)); } if (comment) { len = target->used - len; INSIST(len <= 10); /* "0123456789 ; " */ RETERR(str_totext(len+" ; ", target)); RETERR(str_totext(soa_fieldnames[i], target)); /* Print times in week/day/hour/minute/second form */ if (i >= 1) { RETERR(str_totext(" (", target)); RETERR(dns_ttl_totext(num, ISC_TRUE, target)); RETERR(str_totext(")", target)); } RETERR(str_totext(tctx->linebreak, target)); } else if (i < 4) { RETERR(str_totext(tctx->linebreak, target)); } } if (multiline) RETERR(str_totext(")", target)); return (ISC_R_SUCCESS); }
static inline isc_result_t totext_soa(ARGS_TOTEXT) { isc_region_t dregion; dns_name_t mname; dns_name_t rname; dns_name_t prefix; isc_boolean_t sub; int i; isc_boolean_t multiline; isc_boolean_t comment; REQUIRE(rdata->type == 6); REQUIRE(rdata->length != 0); multiline = ISC_TF((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0); comment = ISC_TF((tctx->flags & DNS_STYLEFLAG_COMMENT) != 0); dns_name_init(&mname, NULL); dns_name_init(&rname, NULL); dns_name_init(&prefix, NULL); dns_rdata_toregion(rdata, &dregion); dns_name_fromregion(&mname, &dregion); isc_region_consume(&dregion, name_length(&mname)); dns_name_fromregion(&rname, &dregion); isc_region_consume(&dregion, name_length(&rname)); sub = name_prefix(&mname, tctx->origin, &prefix); RETERR(dns_name_totext(&prefix, sub, target)); RETERR(str_totext(" ", target)); sub = name_prefix(&rname, tctx->origin, &prefix); RETERR(dns_name_totext(&prefix, sub, target)); if (multiline) RETERR(str_totext(" (" , target)); RETERR(str_totext(tctx->linebreak, target)); for (i = 0; i < 5; i++) { char buf[sizeof("2147483647")]; unsigned long num; int numlen; num = uint32_fromregion(&dregion); isc_region_consume(&dregion, 4); numlen = snprintf(buf, sizeof(buf), "%lu", num); INSIST(numlen != -1 && (size_t)numlen < sizeof(buf)); RETERR(str_totext(buf, target)); if (multiline && comment) { RETERR(str_totext(" ; " + (unsigned int)numlen, target)); RETERR(str_totext(soa_fieldnames[i], target)); /* Print times in week/day/hour/minute/second form */ if (i >= 1) { RETERR(str_totext(" (", target)); RETERR(dns_ttl_totext(num, ISC_TRUE, target)); RETERR(str_totext(")", target)); } RETERR(str_totext(tctx->linebreak, target)); } else if (i < 4) { RETERR(str_totext(tctx->linebreak, target)); } } if (multiline) RETERR(str_totext(")", target)); return (ISC_R_SUCCESS); }