/***
This file is part of systemd.
Copyright 2014 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <math.h>
#include "alloc-util.h"
#include "dns-domain.h"
#include "dns-type.h"
#include "hexdecoct.h"
#include "resolved-dns-dnssec.h"
#include "resolved-dns-packet.h"
#include "resolved-dns-rr.h"
#include "string-table.h"
#include "string-util.h"
#include "strv.h"
#include "terminal-util.h"
DnsResourceKey *k;
size_t l;
if (!k)
return NULL;
k->n_ref = 1;
return k;
}
DnsResourceKey* dns_resource_key_new_redirect(const DnsResourceKey *key, const DnsResourceRecord *cname) {
int r;
else {
DnsResourceKey *k;
r = dns_name_change_suffix(DNS_RESOURCE_KEY_NAME(key), DNS_RESOURCE_KEY_NAME(cname->key), cname->dname.name, &destination);
if (r < 0)
return NULL;
if (r == 0)
if (!k) {
return NULL;
}
return k;
}
}
char *joined;
int r;
if (dns_name_is_root(name)) {
return 0;
}
if (r < 0)
return r;
if (!new_key) {
return -ENOMEM;
}
return 0;
}
DnsResourceKey *k;
if (!k)
return NULL;
k->n_ref = 1;
return k;
}
if (!k)
return NULL;
k->n_ref++;
return k;
}
if (!k)
return NULL;
if (k->n_ref == 1) {
free(k);
} else
k->n_ref--;
return NULL;
}
/* Check if this is an A or AAAA resource key */
}
int r;
if (a == b)
return 1;
if (r <= 0)
return r;
return 0;
return 0;
return 1;
}
int dns_resource_key_match_rr(const DnsResourceKey *key, DnsResourceRecord *rr, const char *search_domain) {
int r;
return 1;
/* Checks if an rr matches the specified key. If a search
* domain is specified, it will also be checked if the key
* with the search domain suffixed might match the RR. */
return 0;
return 0;
if (r != 0)
return r;
if (search_domain) {
if (r < 0)
return r;
}
return 0;
}
int dns_resource_key_match_cname_or_dname(const DnsResourceKey *key, const DnsResourceKey *cname, const char *search_domain) {
int r;
return 0;
else
return 0;
if (r != 0)
return r;
if (search_domain) {
if (r < 0)
return r;
}
return 0;
}
/* Checks whether 'soa' is a SOA record for the specified key. */
return 0;
return 0;
}
const DnsResourceKey *k = i;
assert(k);
}
static int dns_resource_key_compare_func(const void *a, const void *b) {
const DnsResourceKey *x = a, *y = b;
int ret;
if (ret != 0)
return ret;
return -1;
return 1;
return -1;
return 1;
return 0;
}
};
char cbuf[strlen("CLASS") + DECIMAL_STR_MAX(uint16_t)], tbuf[strlen("TYPE") + DECIMAL_STR_MAX(uint16_t)];
const char *c, *t, *n;
char *s;
use the format recommended by RFC 3597, Section 5. */
if (!c) {
c = cbuf;
}
if (!t){
t = tbuf;
}
n = DNS_RESOURCE_KEY_NAME(key);
return -ENOMEM;
*ret = s;
return 0;
}
assert(a);
assert(b);
/* Try to replace one RR key by another if they are identical, thus saving a bit of memory. Note that we do
* this only for RR keys, not for RRs themselves, as they carry a lot of additional metadata (where they come
* from, validity data, and suchlike), and cannot be replaced so easily by other RRs that have the same
* superficial data. */
if (!*a)
return false;
if (!*b)
return false;
/* We refuse merging const keys */
if ((*a)->n_ref == (unsigned) -1)
return false;
if ((*b)->n_ref == (unsigned) -1)
return false;
/* Already the same? */
if (*a == *b)
return true;
/* Are they really identical? */
if (dns_resource_key_equal(*a, *b) <= 0)
return false;
/* Keep the one which already has more references. */
*b = dns_resource_key_ref(*a);
} else {
*a = dns_resource_key_ref(*b);
}
return true;
}
if (!rr)
return NULL;
return rr;
}
if (!key)
return NULL;
return dns_resource_record_new(key);
}
if (!rr)
return NULL;
return rr;
}
if (!rr)
return NULL;
return NULL;
}
case DNS_TYPE_SRV:
break;
case DNS_TYPE_PTR:
case DNS_TYPE_NS:
case DNS_TYPE_CNAME:
case DNS_TYPE_DNAME:
break;
case DNS_TYPE_HINFO:
break;
case DNS_TYPE_TXT:
case DNS_TYPE_SPF:
break;
case DNS_TYPE_SOA:
break;
case DNS_TYPE_MX:
break;
case DNS_TYPE_DS:
break;
case DNS_TYPE_SSHFP:
break;
case DNS_TYPE_DNSKEY:
break;
case DNS_TYPE_RRSIG:
break;
case DNS_TYPE_NSEC:
break;
case DNS_TYPE_NSEC3:
break;
case DNS_TYPE_LOC:
case DNS_TYPE_A:
case DNS_TYPE_AAAA:
break;
case DNS_TYPE_TLSA:
break;
case DNS_TYPE_OPENPGPKEY:
default:
}
}
return NULL;
}
int dns_resource_record_new_reverse(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *hostname) {
int r;
if (r < 0)
return r;
if (!key)
return -ENOMEM;
if (!rr)
return -ENOMEM;
return -ENOMEM;
return 0;
}
int dns_resource_record_new_address(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *name) {
if (!rr)
return -ENOMEM;
if (!rr)
return -ENOMEM;
} else
return -EAFNOSUPPORT;
return 0;
}
int r;
assert(a);
assert(b);
if (a == b)
return 1;
if (r <= 0)
return r;
if (a->unparseable != b->unparseable)
return 0;
case DNS_TYPE_SRV:
if (r <= 0)
return r;
case DNS_TYPE_PTR:
case DNS_TYPE_NS:
case DNS_TYPE_CNAME:
case DNS_TYPE_DNAME:
case DNS_TYPE_HINFO:
case DNS_TYPE_SPF: /* exactly the same as TXT */
case DNS_TYPE_TXT:
case DNS_TYPE_A:
case DNS_TYPE_AAAA:
case DNS_TYPE_SOA:
if (r <= 0)
return r;
if (r <= 0)
return r;
case DNS_TYPE_MX:
return 0;
case DNS_TYPE_LOC:
case DNS_TYPE_DS:
case DNS_TYPE_SSHFP:
case DNS_TYPE_DNSKEY:
case DNS_TYPE_RRSIG:
/* do the fast comparisons first */
case DNS_TYPE_NSEC:
case DNS_TYPE_NSEC3:
case DNS_TYPE_TLSA:
default:
}
}
char *s;
if (asprintf(&s, "%d %d %.3f %c %d %d %.3f %c %.2fm %.2fm %.2fm %.2fm",
NS,
EW,
alt / 100.,
siz / 100.,
hor / 100.,
ver / 100.) < 0)
return NULL;
return s;
}
return -EINVAL;
return -EINVAL;
return 0;
}
Iterator i;
unsigned type;
int r;
if (dns_type_to_string(type)) {
if (r < 0)
return NULL;
} else {
char *t;
if (r < 0)
return NULL;
r = strv_consume(&strv, t);
if (r < 0)
return NULL;
}
}
if (!str)
return NULL;
}
DnsTxtItem *i;
size_t c = 1;
char *p, *s;
p = s = new(char, c);
if (!s)
return NULL;
size_t j;
if (i != first)
*(p++) = ' ';
*(p++) = '"';
for (j = 0; j < i->length; j++) {
*(p++) = '\\';
} else
*(p++) = i->data[j];
}
*(p++) = '"';
}
*p = 0;
return s;
}
char *s;
int r;
if (r < 0)
return NULL;
case DNS_TYPE_SRV:
r = asprintf(&s, "%s %u %u %u %s",
k,
if (r < 0)
return NULL;
break;
case DNS_TYPE_PTR:
case DNS_TYPE_NS:
case DNS_TYPE_CNAME:
case DNS_TYPE_DNAME:
if (!s)
return NULL;
break;
case DNS_TYPE_HINFO:
if (!s)
return NULL;
break;
case DNS_TYPE_SPF: /* exactly the same as TXT */
case DNS_TYPE_TXT:
if (!t)
return NULL;
if (!s)
return NULL;
break;
case DNS_TYPE_A: {
_cleanup_free_ char *x = NULL;
if (r < 0)
return NULL;
if (!s)
return NULL;
break;
}
case DNS_TYPE_AAAA:
if (r < 0)
return NULL;
if (!s)
return NULL;
break;
case DNS_TYPE_SOA:
r = asprintf(&s, "%s %s %s %u %u %u %u %u",
k,
if (r < 0)
return NULL;
break;
case DNS_TYPE_MX:
r = asprintf(&s, "%s %u %s",
k,
if (r < 0)
return NULL;
break;
case DNS_TYPE_LOC:
if (!t)
return NULL;
if (!s)
return NULL;
break;
case DNS_TYPE_DS:
if (!t)
return NULL;
r = asprintf(&s, "%s %u %u %u %s",
k,
t);
if (r < 0)
return NULL;
break;
case DNS_TYPE_SSHFP:
if (!t)
return NULL;
r = asprintf(&s, "%s %u %u %s",
k,
t);
if (r < 0)
return NULL;
break;
case DNS_TYPE_DNSKEY: {
char *ss;
int n, n1;
if (r < 0)
return NULL;
r = asprintf(&s, "%s %n%u %u %s %n",
k,
&n1,
alg,
&n);
if (r < 0)
return NULL;
r = base64_append(&s, n,
8, columns());
if (r < 0)
return NULL;
"%*s-- Flags:%s%s%s\n"
"%*s-- Key tag: %u",
s,
n1, "",
n1, "",
key_tag);
if (r < 0)
return NULL;
free(s);
s = ss;
break;
}
case DNS_TYPE_RRSIG: {
const char *type;
int n;
if (r < 0)
return NULL;
if (r < 0)
return NULL;
if (r < 0)
return NULL;
/* TYPE?? follows
* http://tools.ietf.org/html/rfc3597#section-5 */
r = asprintf(&s, "%s %s%.*u %s %u %u %s %s %u %s %n",
k,
type ?: "TYPE",
alg,
&n);
if (r < 0)
return NULL;
r = base64_append(&s, n,
8, columns());
if (r < 0)
return NULL;
break;
}
case DNS_TYPE_NSEC:
if (!t)
return NULL;
r = asprintf(&s, "%s %s %s",
k,
t);
if (r < 0)
return NULL;
break;
case DNS_TYPE_NSEC3: {
if (!salt)
return NULL;
}
if (!hash)
return NULL;
if (!t)
return NULL;
k,
hash,
t);
if (r < 0)
return NULL;
break;
}
case DNS_TYPE_TLSA: {
char *ss;
int n;
r = asprintf(&s, "%s %u %u %u %n",
k,
&n);
if (r < 0)
return NULL;
r = base64_append(&s, n,
8, columns());
if (r < 0)
return NULL;
"%*s-- Cert. usage: %s\n"
"%*s-- Selector: %s\n"
"%*s-- Matching type: %s",
s,
if (r < 0)
return NULL;
free(s);
s = ss;
break;
}
case DNS_TYPE_OPENPGPKEY: {
int n;
r = asprintf(&s, "%s %n",
k,
&n);
if (r < 0)
return NULL;
r = base64_append(&s, n,
8, columns());
if (r < 0)
return NULL;
break;
}
default:
if (!t)
return NULL;
/* Format as documented in RFC 3597, Section 5 */
if (r < 0)
return NULL;
break;
}
return s;
}
.n_ref = 1,
.on_stack = true,
.refuse_compression = true,
};
int r;
/* Generates the RR in wire-format, optionally in the
* canonical form as discussed in the DNSSEC RFC 4034, Section
* 6.2. We allocate a throw-away DnsPacket object on the stack
* here, because we need some book-keeping for memory
* management, and can reuse the DnsPacket serializer, that
* can generate the canonical form, too, but also knows label
* compression and suchlike. */
return 0;
if (r < 0)
return r;
return 0;
}
const char *n;
int r;
/* Returns the RRset's signer, if it is known. */
return -ENODATA;
if (r < 0)
return r;
if (r == 0)
return -EINVAL;
*ret = n;
return 0;
}
const char *n;
int r;
/* Returns the RRset's synthesizing source, if it is known. */
return -ENODATA;
if (r < 0)
return r;
if (r == 0)
return -EINVAL;
*ret = n;
return 0;
}
const char *signer;
int r;
if (r < 0)
return r;
}
int r;
/* Returns > 0 if the RR is generated from a wildcard, and is not the asterisk name itself */
return -ENODATA;
if (rr->n_skip_labels_source == 0)
return 0;
return 1;
if (r < 0)
return r;
return !r;
}
case DNS_TYPE_SRV:
break;
case DNS_TYPE_PTR:
case DNS_TYPE_NS:
case DNS_TYPE_CNAME:
case DNS_TYPE_DNAME:
break;
case DNS_TYPE_HINFO:
break;
case DNS_TYPE_TXT:
case DNS_TYPE_SPF: {
DnsTxtItem *j;
/* Add an extra NUL byte, so that "a" followed by "b" doesn't result in the same hash as "ab"
* followed by "". */
}
break;
}
case DNS_TYPE_A:
break;
case DNS_TYPE_AAAA:
break;
case DNS_TYPE_SOA:
break;
case DNS_TYPE_MX:
break;
case DNS_TYPE_LOC:
break;
case DNS_TYPE_SSHFP:
break;
case DNS_TYPE_DNSKEY:
break;
case DNS_TYPE_RRSIG:
break;
case DNS_TYPE_NSEC:
/* FIXME: we leave out the type bitmap here. Hash
* would be better if we'd take it into account
* too. */
break;
case DNS_TYPE_DS:
break;
case DNS_TYPE_NSEC3:
/* FIXME: We leave the bitmaps out */
break;
case DNS_TYPE_TLSA:
break;
case DNS_TYPE_OPENPGPKEY:
default:
break;
}
}
static int dns_resource_record_compare_func(const void *a, const void *b) {
const DnsResourceRecord *x = a, *y = b;
int ret;
if (ret != 0)
return ret;
if (dns_resource_record_equal(x, y))
return 0;
/* This is a bit dirty, we don't implement proper ordering, but
* the hashtable doesn't need ordering anyway, hence we don't
* care. */
return x < y ? -1 : 1;
}
};
DnsTxtItem *n;
if (!i)
return NULL;
n = i->items_next;
free(i);
return dns_txt_item_free_all(n);
}
if (a == b)
return true;
if (!a != !b)
return false;
if (!a)
return true;
return false;
return false;
}
/* Mnemonics as listed on https://www.iana.org/assignments/dns-sec-alg-numbers/dns-sec-alg-numbers.xhtml */
[DNSSEC_ALGORITHM_RSAMD5] = "RSAMD5",
[DNSSEC_ALGORITHM_DH] = "DH",
[DNSSEC_ALGORITHM_DSA] = "DSA",
[DNSSEC_ALGORITHM_ECC] = "ECC",
[DNSSEC_ALGORITHM_RSASHA1] = "RSASHA1",
[DNSSEC_ALGORITHM_DSA_NSEC3_SHA1] = "DSA-NSEC3-SHA1",
[DNSSEC_ALGORITHM_RSASHA1_NSEC3_SHA1] = "RSASHA1-NSEC3-SHA1",
[DNSSEC_ALGORITHM_RSASHA256] = "RSASHA256",
[DNSSEC_ALGORITHM_RSASHA512] = "RSASHA512",
[DNSSEC_ALGORITHM_ECC_GOST] = "ECC-GOST",
[DNSSEC_ALGORITHM_ECDSAP256SHA256] = "ECDSAP256SHA256",
[DNSSEC_ALGORITHM_ECDSAP384SHA384] = "ECDSAP384SHA384",
[DNSSEC_ALGORITHM_INDIRECT] = "INDIRECT",
[DNSSEC_ALGORITHM_PRIVATEDNS] = "PRIVATEDNS",
[DNSSEC_ALGORITHM_PRIVATEOID] = "PRIVATEOID",
};
/* Names as listed on https://www.iana.org/assignments/ds-rr-types/ds-rr-types.xhtml */
[DNSSEC_DIGEST_SHA1] = "SHA-1",
[DNSSEC_DIGEST_SHA256] = "SHA-256",
[DNSSEC_DIGEST_GOST_R_34_11_94] = "GOST_R_34.11-94",
[DNSSEC_DIGEST_SHA384] = "SHA-384",
};