1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2016 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 #include "alloc-util.h"
25 #include "bus-common-errors.h"
27 #include "random-util.h"
28 #include "string-util.h"
29 #include "time-util.h"
31 #define DNS_CALL_TIMEOUT_USEC (45*USEC_PER_SEC)
33 static void test_lookup(sd_bus
*bus
, const char *name
, uint16_t type
, const char *result
) {
34 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*req
= NULL
, *reply
= NULL
;
35 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
36 _cleanup_free_
char *m
= NULL
;
39 /* If the name starts with a dot, we prefix one to three random labels */
40 if (startswith(name
, ".")) {
43 u
= 1 + (random_u64() & 3);
46 for (i
= 0; i
< u
; i
++) {
47 _cleanup_free_
char *b
= NULL
;
50 assert_se(asprintf(&b
, "x%" PRIu64
"x", random_u64()));
51 x
= strjoin(b
, ".", name
, NULL
);
58 assert_se(sd_bus_message_new_method_call(
61 "org.freedesktop.resolve1",
62 "/org/freedesktop/resolve1",
63 "org.freedesktop.resolve1.Manager",
64 "ResolveRecord") >= 0);
66 assert_se(sd_bus_message_append(req
, "isqqt", 0, name
, DNS_CLASS_IN
, type
, UINT64_C(0)) >= 0);
68 r
= sd_bus_call(bus
, req
, DNS_CALL_TIMEOUT_USEC
, &error
, &reply
);
72 assert_se(sd_bus_error_has_name(&error
, result
));
73 log_info("[OK] %s/%s resulted in <%s>.", name
, dns_type_to_string(type
), error
.name
);
76 log_info("[OK] %s/%s succeeded.", name
, dns_type_to_string(type
));
80 int main(int argc
, char* argv
[]) {
81 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
83 /* Note that this is a manual test as it requires:
86 * A DNSSEC capable DNS server
87 * That zones contacted are still set up as they were when I wrote this.
90 assert_se(sd_bus_open_system(&bus
) >= 0);
93 test_lookup(bus
, "www.eurid.eu", DNS_TYPE_A
, NULL
);
94 test_lookup(bus
, "sigok.verteiltesysteme.net", DNS_TYPE_A
, NULL
);
96 /* Normally signed, NODATA */
97 test_lookup(bus
, "www.eurid.eu", DNS_TYPE_RP
, BUS_ERROR_NO_SUCH_RR
);
98 test_lookup(bus
, "sigok.verteiltesysteme.net", DNS_TYPE_RP
, BUS_ERROR_NO_SUCH_RR
);
100 /* Invalid signature */
101 test_lookup(bus
, "sigfail.verteiltesysteme.net", DNS_TYPE_A
, BUS_ERROR_DNSSEC_FAILED
);
103 /* Invalid signature, RSA, wildcard */
104 test_lookup(bus
, ".wilda.rhybar.0skar.cz", DNS_TYPE_A
, BUS_ERROR_DNSSEC_FAILED
);
106 /* Invalid signature, ECDSA, wildcard */
107 test_lookup(bus
, ".wilda.rhybar.ecdsa.0skar.cz", DNS_TYPE_A
, BUS_ERROR_DNSSEC_FAILED
);
109 /* NXDOMAIN in NSEC domain */
110 test_lookup(bus
, "hhh.nasa.gov", DNS_TYPE_A
, _BUS_ERROR_DNS
"NXDOMAIN");
112 /* wildcard, NSEC zone */
113 test_lookup(bus
, ".wilda.nsec.0skar.cz", DNS_TYPE_A
, NULL
);
115 /* wildcard, NSEC zone, NODATA */
116 test_lookup(bus
, ".wilda.nsec.0skar.cz", DNS_TYPE_RP
, BUS_ERROR_NO_SUCH_RR
);
118 /* wildcard, NSEC3 zone */
119 test_lookup(bus
, ".wilda.0skar.cz", DNS_TYPE_A
, NULL
);
121 /* wildcard, NSEC3 zone, NODATA */
122 test_lookup(bus
, ".wilda.0skar.cz", DNS_TYPE_RP
, BUS_ERROR_NO_SUCH_RR
);
124 /* wildcard, NSEC zone, CNAME */
125 test_lookup(bus
, ".wild.nsec.0skar.cz", DNS_TYPE_A
, NULL
);
127 /* wildcard, NSEC zone, NODATA, CNAME */
128 test_lookup(bus
, ".wild.nsec.0skar.cz", DNS_TYPE_RP
, BUS_ERROR_NO_SUCH_RR
);
130 /* wildcard, NSEC3 zone, CNAME */
131 test_lookup(bus
, ".wild.0skar.cz", DNS_TYPE_A
, NULL
);
133 /* wildcard, NSEC3 zone, NODATA, CNAME */
134 test_lookup(bus
, ".wild.0skar.cz", DNS_TYPE_RP
, BUS_ERROR_NO_SUCH_RR
);
136 /* NODATA due to empty non-terminal in NSEC domain */
137 test_lookup(bus
, "herndon.nasa.gov", DNS_TYPE_A
, BUS_ERROR_NO_SUCH_RR
);
139 /* NXDOMAIN in NSEC root zone: */
140 test_lookup(bus
, "jasdhjas.kjkfgjhfjg", DNS_TYPE_A
, _BUS_ERROR_DNS
"NXDOMAIN");
142 /* NXDOMAIN in NSEC3 .com zone: */
143 test_lookup(bus
, "kjkfgjhfjgsdfdsfd.com", DNS_TYPE_A
, _BUS_ERROR_DNS
"NXDOMAIN");