shithub: plan9front

Download patch

ref: 20cff04fd22649c4588bd9088e697a9e54a5c21a
parent: c2661f86fc9fc228581547067aa571ff57bc9332
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Oct 24 18:15:26 EDT 2021

ndb/dns: implement caa record type in ndb

this allows the caa records to be specified
in ndb as:

caa=<value> tag=<tag> flags=<flags>

where tag defaults to "issue" and flags to 0
when omited.

--- a/sys/man/2/ndb	Sun Oct 24 10:37:36 2021
+++ b/sys/man/2/ndb	Sun Oct 24 18:15:26 2021
@@ -411,6 +411,13 @@
 .RI ( dom )
 and name server
 .RI ( ns ).
+.TP
+.B caa
+get the certificate authority records.
+Returns the
+.RI ( tag )
+and
+.RI ( flags ).
 .PP
 .I Ndbfindattr
 searches
--- a/sys/src/cmd/ndb/dblookup.c	Sun Oct 24 10:37:36 2021
+++ b/sys/src/cmd/ndb/dblookup.c	Sun Oct 24 18:15:26 2021
@@ -41,6 +41,7 @@
 static RR*	soarr(Ndbtuple*, Ndbtuple*);
 static RR*	srvrr(Ndbtuple*, Ndbtuple*);
 static RR*	txtrr(Ndbtuple*, Ndbtuple*);
+static RR*	caarr(Ndbtuple*, Ndbtuple*);
 
 static int	implemented[] =
 {
@@ -54,6 +55,7 @@
 	[Tsoa]		1,
 	[Tsrv]		1,
 	[Ttxt]		1,
+	[Tcaa]		1,
 };
 
 /* straddle server configuration */
@@ -258,6 +260,10 @@
 	case Taxfr:
 	case Tixfr:
 		return doaxfr(db, name);
+	case Tcaa:
+		attr = "caa";
+		f = caarr;
+		break;
 	default:
 //		dnslog("dblookup1(%s) bad type", name);
 		return nil;
@@ -590,6 +596,23 @@
 	return rp;
 }
 
+static RR*
+caarr(Ndbtuple *entry, Ndbtuple *pair)
+{
+	Ndbtuple *tag;
+	RR *rp;
+
+	rp = rralloc(Tcaa);
+	rp->caa->flags = intval(entry, pair, "flags", 0);
+	rp->caa->data = (uchar*)estrdup(pair->val);
+	rp->caa->dlen = strlen((char*)rp->caa->data);
+	if((tag = look(entry, pair, "tag")) != nil)
+		rp->caa->tag = dnlookup(tag->val, Cin, 1);
+	else
+		rp->caa->tag = dnlookup("issue", Cin, 1);
+	return rp;
+}
+
 /*
  *  Look for a pair with the given attribute.  look first on the same line,
  *  then in the whole entry.
@@ -655,6 +678,8 @@
 		rp = txtrr(entry, pair);
 	else if(strcmp(pair->attr, "txt") == 0)
 		rp = txtrr(entry, pair);
+	else if(strcmp(pair->attr, "caa") == 0)
+		rp = caarr(entry, pair);
 	if(rp == nil)
 		return;