mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-22 18:19:42 +00:00
add "delv +yaml" output format
This commit is contained in:
parent
5aa375f0d8
commit
241cf78fee
141
bin/delv/delv.c
141
bin/delv/delv.c
@ -111,7 +111,8 @@ static bool
|
|||||||
nottl = false,
|
nottl = false,
|
||||||
multiline = false,
|
multiline = false,
|
||||||
short_form = false,
|
short_form = false,
|
||||||
print_unknown_format = false;
|
print_unknown_format = false,
|
||||||
|
yaml = false;
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
resolve_trace = false,
|
resolve_trace = false,
|
||||||
@ -353,52 +354,80 @@ setup_logging(FILE *errout) {
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
print_status(dns_rdataset_t *rdataset) {
|
print_status(dns_rdataset_t *rdataset) {
|
||||||
const char *astr = "", *tstr = "";
|
char buf[1024] = { 0 };
|
||||||
|
|
||||||
REQUIRE(rdataset != NULL);
|
REQUIRE(rdataset != NULL);
|
||||||
|
|
||||||
if (!showtrust || !dns_rdataset_isassociated(rdataset))
|
if (!showtrust || !dns_rdataset_isassociated(rdataset)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ((rdataset->attributes & DNS_RDATASETATTR_NEGATIVE) != 0)
|
buf[0] = '\0';
|
||||||
astr = "negative response, ";
|
|
||||||
|
if ((rdataset->attributes & DNS_RDATASETATTR_NEGATIVE) != 0) {
|
||||||
|
strlcat(buf, "negative response", sizeof(buf));
|
||||||
|
strlcat(buf, (yaml ? "_" : ", "), sizeof(buf));
|
||||||
|
}
|
||||||
|
|
||||||
switch (rdataset->trust) {
|
switch (rdataset->trust) {
|
||||||
case dns_trust_none:
|
case dns_trust_none:
|
||||||
tstr = "untrusted";
|
strlcat(buf, "untrusted", sizeof(buf));
|
||||||
break;
|
break;
|
||||||
case dns_trust_pending_additional:
|
case dns_trust_pending_additional:
|
||||||
tstr = "signed additional data, pending validation";
|
strlcat(buf, "signed additional data", sizeof(buf));
|
||||||
|
if (!yaml) {
|
||||||
|
strlcat(buf, ", ", sizeof(buf));
|
||||||
|
}
|
||||||
|
strlcat(buf, "pending validation", sizeof(buf));
|
||||||
break;
|
break;
|
||||||
case dns_trust_pending_answer:
|
case dns_trust_pending_answer:
|
||||||
tstr = "signed answer, pending validation";
|
strlcat(buf, "signed answer", sizeof(buf));
|
||||||
|
if (!yaml) {
|
||||||
|
strlcat(buf, ", ", sizeof(buf));
|
||||||
|
}
|
||||||
|
strlcat(buf, "pending validation", sizeof(buf));
|
||||||
break;
|
break;
|
||||||
case dns_trust_additional:
|
case dns_trust_additional:
|
||||||
tstr = "unsigned additional data";
|
strlcat(buf, "unsigned additional data", sizeof(buf));
|
||||||
break;
|
break;
|
||||||
case dns_trust_glue:
|
case dns_trust_glue:
|
||||||
tstr = "glue data";
|
strlcat(buf, "glue data", sizeof(buf));
|
||||||
break;
|
break;
|
||||||
case dns_trust_answer:
|
case dns_trust_answer:
|
||||||
if (root_validation) {
|
if (root_validation) {
|
||||||
tstr = "unsigned answer";
|
strlcat(buf, "unsigned answer", sizeof(buf));
|
||||||
|
} else {
|
||||||
|
strlcat(buf, "answer not validated", sizeof(buf));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case dns_trust_authauthority:
|
case dns_trust_authauthority:
|
||||||
tstr = "authority data";
|
strlcat(buf, "authority data", sizeof(buf));
|
||||||
break;
|
break;
|
||||||
case dns_trust_authanswer:
|
case dns_trust_authanswer:
|
||||||
tstr = "authoritative";
|
strlcat(buf, "authoritative", sizeof(buf));
|
||||||
break;
|
break;
|
||||||
case dns_trust_secure:
|
case dns_trust_secure:
|
||||||
tstr = "fully validated";
|
strlcat(buf, "fully validated", sizeof(buf));
|
||||||
break;
|
break;
|
||||||
case dns_trust_ultimate:
|
case dns_trust_ultimate:
|
||||||
tstr = "ultimate trust";
|
strlcat(buf, "ultimate trust", sizeof(buf));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("; %s%s\n", astr, tstr);
|
if (yaml) {
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
/* Convert spaces to underscores for YAML */
|
||||||
|
for (p = buf; p != NULL && *p != '\0'; p++) {
|
||||||
|
if (*p == ' ') {
|
||||||
|
*p = '_';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(" - %s:\n", buf);
|
||||||
|
} else {
|
||||||
|
printf("; %s\n", buf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static isc_result_t
|
static isc_result_t
|
||||||
@ -425,8 +454,9 @@ printdata(dns_rdataset_t *rdataset, dns_name_t *owner,
|
|||||||
return (ISC_R_SUCCESS);
|
return (ISC_R_SUCCESS);
|
||||||
|
|
||||||
if (first || rdataset->trust != trust) {
|
if (first || rdataset->trust != trust) {
|
||||||
if (!first && showtrust && !short_form)
|
if (!first && showtrust && !short_form && !yaml) {
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
|
}
|
||||||
print_status(rdataset);
|
print_status(rdataset);
|
||||||
trust = rdataset->trust;
|
trust = rdataset->trust;
|
||||||
first = false;
|
first = false;
|
||||||
@ -465,9 +495,11 @@ printdata(dns_rdataset_t *rdataset, dns_name_t *owner,
|
|||||||
dns_rdata_reset(&rdata);
|
dns_rdata_reset(&rdata);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ((rdataset->attributes &
|
if (!yaml && (rdataset->attributes &
|
||||||
DNS_RDATASETATTR_NEGATIVE) != 0)
|
DNS_RDATASETATTR_NEGATIVE) != 0)
|
||||||
|
{
|
||||||
isc_buffer_putstr(&target, "; ");
|
isc_buffer_putstr(&target, "; ");
|
||||||
|
}
|
||||||
|
|
||||||
result = dns_master_rdatasettotext(owner, rdataset,
|
result = dns_master_rdatasettotext(owner, rdataset,
|
||||||
style, &target);
|
style, &target);
|
||||||
@ -500,38 +532,52 @@ setup_style(dns_master_style_t **stylep) {
|
|||||||
REQUIRE(stylep != NULL || *stylep == NULL);
|
REQUIRE(stylep != NULL || *stylep == NULL);
|
||||||
|
|
||||||
styleflags |= DNS_STYLEFLAG_REL_OWNER;
|
styleflags |= DNS_STYLEFLAG_REL_OWNER;
|
||||||
if (showcomments)
|
if (yaml) {
|
||||||
styleflags |= DNS_STYLEFLAG_COMMENT;
|
styleflags |= DNS_STYLEFLAG_YAML;
|
||||||
if (print_unknown_format)
|
dns_master_indentstr = " ";
|
||||||
styleflags |= DNS_STYLEFLAG_UNKNOWNFORMAT;
|
dns_master_indent = 2;
|
||||||
if (rrcomments)
|
} else {
|
||||||
styleflags |= DNS_STYLEFLAG_RRCOMMENT;
|
if (showcomments) {
|
||||||
if (nottl)
|
styleflags |= DNS_STYLEFLAG_COMMENT;
|
||||||
styleflags |= DNS_STYLEFLAG_NO_TTL;
|
}
|
||||||
if (noclass)
|
if (print_unknown_format) {
|
||||||
styleflags |= DNS_STYLEFLAG_NO_CLASS;
|
styleflags |= DNS_STYLEFLAG_UNKNOWNFORMAT;
|
||||||
if (nocrypto)
|
}
|
||||||
styleflags |= DNS_STYLEFLAG_NOCRYPTO;
|
if (rrcomments) {
|
||||||
if (multiline) {
|
styleflags |= DNS_STYLEFLAG_RRCOMMENT;
|
||||||
styleflags |= DNS_STYLEFLAG_MULTILINE;
|
}
|
||||||
styleflags |= DNS_STYLEFLAG_COMMENT;
|
if (nottl) {
|
||||||
|
styleflags |= DNS_STYLEFLAG_NO_TTL;
|
||||||
|
}
|
||||||
|
if (noclass) {
|
||||||
|
styleflags |= DNS_STYLEFLAG_NO_CLASS;
|
||||||
|
}
|
||||||
|
if (nocrypto) {
|
||||||
|
styleflags |= DNS_STYLEFLAG_NOCRYPTO;
|
||||||
|
}
|
||||||
|
if (multiline) {
|
||||||
|
styleflags |= DNS_STYLEFLAG_MULTILINE;
|
||||||
|
styleflags |= DNS_STYLEFLAG_COMMENT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (multiline || (nottl && noclass))
|
if (multiline || (nottl && noclass)) {
|
||||||
result = dns_master_stylecreate(&style, styleflags,
|
result = dns_master_stylecreate(&style, styleflags,
|
||||||
24, 24, 24, 32, 80, 8,
|
24, 24, 24, 32, 80, 8,
|
||||||
splitwidth, mctx);
|
splitwidth, mctx);
|
||||||
else if (nottl || noclass)
|
} else if (nottl || noclass) {
|
||||||
result = dns_master_stylecreate(&style, styleflags,
|
result = dns_master_stylecreate(&style, styleflags,
|
||||||
24, 24, 32, 40, 80, 8,
|
24, 24, 32, 40, 80, 8,
|
||||||
splitwidth, mctx);
|
splitwidth, mctx);
|
||||||
else
|
} else {
|
||||||
result = dns_master_stylecreate(&style, styleflags,
|
result = dns_master_stylecreate(&style, styleflags,
|
||||||
24, 32, 40, 48, 80, 8,
|
24, 32, 40, 48, 80, 8,
|
||||||
splitwidth, mctx);
|
splitwidth, mctx);
|
||||||
|
}
|
||||||
|
|
||||||
if (result == ISC_R_SUCCESS)
|
if (result == ISC_R_SUCCESS) {
|
||||||
*stylep = style;
|
*stylep = style;
|
||||||
|
}
|
||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1139,6 +1185,13 @@ plus_option(char *option) {
|
|||||||
if (state)
|
if (state)
|
||||||
resolve_trace = state;
|
resolve_trace = state;
|
||||||
break;
|
break;
|
||||||
|
case 'y': /* yaml */
|
||||||
|
FULLCHECK("yaml");
|
||||||
|
yaml = state;
|
||||||
|
if (state) {
|
||||||
|
rrcomments = false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
invalid_option:
|
invalid_option:
|
||||||
/*
|
/*
|
||||||
@ -1565,6 +1618,7 @@ main(int argc, char *argv[]) {
|
|||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
dns_fixedname_t qfn;
|
dns_fixedname_t qfn;
|
||||||
dns_name_t *query_name, *response_name;
|
dns_name_t *query_name, *response_name;
|
||||||
|
char namestr[DNS_NAME_FORMATSIZE];
|
||||||
dns_rdataset_t *rdataset;
|
dns_rdataset_t *rdataset;
|
||||||
dns_namelist_t namelist;
|
dns_namelist_t namelist;
|
||||||
unsigned int resopt, clopt;
|
unsigned int resopt, clopt;
|
||||||
@ -1653,9 +1707,18 @@ main(int argc, char *argv[]) {
|
|||||||
ISC_LIST_INIT(namelist);
|
ISC_LIST_INIT(namelist);
|
||||||
result = dns_client_resolve(client, query_name, dns_rdataclass_in,
|
result = dns_client_resolve(client, query_name, dns_rdataclass_in,
|
||||||
qtype, resopt, &namelist);
|
qtype, resopt, &namelist);
|
||||||
if (result != ISC_R_SUCCESS)
|
if (result != ISC_R_SUCCESS && !yaml) {
|
||||||
delv_log(ISC_LOG_ERROR, "resolution failed: %s",
|
delv_log(ISC_LOG_ERROR, "resolution failed: %s",
|
||||||
isc_result_totext(result));
|
isc_result_totext(result));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (yaml) {
|
||||||
|
printf("type: DELV_RESULT\n");
|
||||||
|
dns_name_format(query_name, namestr, sizeof(namestr));
|
||||||
|
printf("query_name: %s\n", namestr);
|
||||||
|
printf("status: %s\n", isc_result_totext(result));
|
||||||
|
printf("records:\n");
|
||||||
|
}
|
||||||
|
|
||||||
for (response_name = ISC_LIST_HEAD(namelist);
|
for (response_name = ISC_LIST_HEAD(namelist);
|
||||||
response_name != NULL;
|
response_name != NULL;
|
||||||
|
@ -427,7 +427,7 @@ str_totext(const char *source, isc_buffer_t *target) {
|
|||||||
|
|
||||||
static isc_result_t
|
static isc_result_t
|
||||||
ncache_summary(dns_rdataset_t *rdataset, bool omit_final_dot,
|
ncache_summary(dns_rdataset_t *rdataset, bool omit_final_dot,
|
||||||
isc_buffer_t *target)
|
dns_totext_ctx_t *ctx, isc_buffer_t *target)
|
||||||
{
|
{
|
||||||
isc_result_t result = ISC_R_SUCCESS;
|
isc_result_t result = ISC_R_SUCCESS;
|
||||||
dns_rdataset_t rds;
|
dns_rdataset_t rds;
|
||||||
@ -441,7 +441,22 @@ ncache_summary(dns_rdataset_t *rdataset, bool omit_final_dot,
|
|||||||
for (result = dns_rdataset_first(&rds);
|
for (result = dns_rdataset_first(&rds);
|
||||||
result == ISC_R_SUCCESS;
|
result == ISC_R_SUCCESS;
|
||||||
result = dns_rdataset_next(&rds)) {
|
result = dns_rdataset_next(&rds)) {
|
||||||
CHECK(str_totext("; ", target));
|
if ((ctx->style.flags & DNS_STYLEFLAG_INDENT) != 0 ||
|
||||||
|
(ctx->style.flags & DNS_STYLEFLAG_YAML) != 0)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
for (i = 0; i < dns_master_indent; i++) {
|
||||||
|
CHECK(str_totext(dns_master_indentstr,
|
||||||
|
target));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((ctx->style.flags & DNS_STYLEFLAG_YAML) != 0) {
|
||||||
|
CHECK(str_totext("- ", target));
|
||||||
|
} else {
|
||||||
|
CHECK(str_totext("; ", target));
|
||||||
|
}
|
||||||
|
|
||||||
CHECK(dns_name_totext(&name, omit_final_dot, target));
|
CHECK(dns_name_totext(&name, omit_final_dot, target));
|
||||||
CHECK(str_totext(" ", target));
|
CHECK(str_totext(" ", target));
|
||||||
CHECK(dns_rdatatype_totext(rds.type, target));
|
CHECK(dns_rdatatype_totext(rds.type, target));
|
||||||
@ -518,22 +533,21 @@ rdataset_totext(dns_rdataset_t *rdataset,
|
|||||||
*/
|
*/
|
||||||
if ((ctx->style.flags & DNS_STYLEFLAG_INDENT) != 0 ||
|
if ((ctx->style.flags & DNS_STYLEFLAG_INDENT) != 0 ||
|
||||||
(ctx->style.flags & DNS_STYLEFLAG_YAML) != 0)
|
(ctx->style.flags & DNS_STYLEFLAG_YAML) != 0)
|
||||||
|
{
|
||||||
for (i = 0; i < dns_master_indent; i++)
|
for (i = 0; i < dns_master_indent; i++)
|
||||||
RETERR(str_totext(dns_master_indentstr,
|
RETERR(str_totext(dns_master_indentstr,
|
||||||
target));
|
target));
|
||||||
|
|
||||||
/*
|
|
||||||
* YAML enumerator?
|
|
||||||
*/
|
|
||||||
if ((ctx->style.flags & DNS_STYLEFLAG_YAML) != 0) {
|
|
||||||
RETERR(str_totext("- ", target));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Comment?
|
* YAML or comment prefix?
|
||||||
*/
|
*/
|
||||||
if ((ctx->style.flags & DNS_STYLEFLAG_COMMENTDATA) != 0)
|
if ((ctx->style.flags & DNS_STYLEFLAG_YAML) != 0) {
|
||||||
|
RETERR(str_totext("- ", target));
|
||||||
|
} else if ((ctx->style.flags & DNS_STYLEFLAG_COMMENTDATA) != 0)
|
||||||
|
{
|
||||||
RETERR(str_totext(";", target));
|
RETERR(str_totext(";", target));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Owner name.
|
* Owner name.
|
||||||
@ -651,23 +665,17 @@ rdataset_totext(dns_rdataset_t *rdataset,
|
|||||||
*/
|
*/
|
||||||
INDENT_TO(rdata_column);
|
INDENT_TO(rdata_column);
|
||||||
if ((rdataset->attributes & DNS_RDATASETATTR_NEGATIVE) != 0) {
|
if ((rdataset->attributes & DNS_RDATASETATTR_NEGATIVE) != 0) {
|
||||||
if ((ctx->style.flags & DNS_STYLEFLAG_INDENT) != 0 ||
|
if (NXDOMAIN(rdataset)) {
|
||||||
(ctx->style.flags & DNS_STYLEFLAG_YAML) != 0)
|
|
||||||
{
|
|
||||||
for (i = 0; i < dns_master_indent; i++)
|
|
||||||
RETERR(str_totext(dns_master_indentstr,
|
|
||||||
target));
|
|
||||||
}
|
|
||||||
if (NXDOMAIN(rdataset))
|
|
||||||
RETERR(str_totext(";-$NXDOMAIN\n", target));
|
RETERR(str_totext(";-$NXDOMAIN\n", target));
|
||||||
else
|
} else {
|
||||||
RETERR(str_totext(";-$NXRRSET\n", target));
|
RETERR(str_totext(";-$NXRRSET\n", target));
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* Print a summary of the cached records which make
|
* Print a summary of the cached records which make
|
||||||
* up the negative response.
|
* up the negative response.
|
||||||
*/
|
*/
|
||||||
RETERR(ncache_summary(rdataset, omit_final_dot,
|
RETERR(ncache_summary(rdataset, omit_final_dot,
|
||||||
target));
|
ctx, target));
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
dns_rdata_t rdata = DNS_RDATA_INIT;
|
dns_rdata_t rdata = DNS_RDATA_INIT;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user