Bug Summary

File:build-scan/../src/resolve/resolved-bus.c
Warning:line 1521, column 16
2nd function call argument is an uninitialized value

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name resolved-bus.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -menable-no-infs -menable-no-nans -menable-unsafe-fp-math -fno-signed-zeros -mreassociate -freciprocal-math -fdenormal-fp-math=preserve-sign,preserve-sign -ffp-contract=fast -fno-rounding-math -ffast-math -ffinite-math-only -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/12.0.0 -include config.h -I systemd-resolved.p -I . -I .. -I src/basic -I ../src/basic -I src/shared -I ../src/shared -I src/systemd -I ../src/systemd -I src/journal -I ../src/journal -I src/journal-remote -I ../src/journal-remote -I src/nspawn -I ../src/nspawn -I src/resolve -I ../src/resolve -I src/timesync -I ../src/timesync -I ../src/time-wait-sync -I src/login -I ../src/login -I src/udev -I ../src/udev -I src/libudev -I ../src/libudev -I src/core -I ../src/core -I ../src/libsystemd/sd-bus -I ../src/libsystemd/sd-device -I ../src/libsystemd/sd-hwdb -I ../src/libsystemd/sd-id128 -I ../src/libsystemd/sd-netlink -I ../src/libsystemd/sd-network -I src/libsystemd-network -I ../src/libsystemd-network -I /usr/include/p11-kit-1 -D _FILE_OFFSET_BITS=64 -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/12.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wwrite-strings -Wno-unused-parameter -Wno-missing-field-initializers -Wno-unused-result -Wno-format-signedness -Wno-error=nonnull -std=gnu99 -fconst-strings -fdebug-compilation-dir /home/mrc0mmand/repos/@redhat-plumbers/systemd-rhel8/build-scan -ferror-limit 19 -fvisibility hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcolor-diagnostics -analyzer-output=html -faddrsig -o /tmp/scan-build-2021-07-16-221226-1465241-1 -x c ../src/resolve/resolved-bus.c
1/* SPDX-License-Identifier: LGPL-2.1+ */
2
3#include "alloc-util.h"
4#include "bus-common-errors.h"
5#include "bus-util.h"
6#include "dns-domain.h"
7#include "resolved-bus.h"
8#include "resolved-def.h"
9#include "resolved-dns-synthesize.h"
10#include "resolved-dnssd.h"
11#include "resolved-dnssd-bus.h"
12#include "resolved-link-bus.h"
13#include "user-util.h"
14#include "utf8.h"
15
16BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_resolve_support, resolve_support, ResolveSupport)int bus_property_get_resolve_support(sd_bus *bus, const char *
path, const char *interface, const char *property, sd_bus_message
*reply, void *userdata, sd_bus_error *error) { ResolveSupport
*data = userdata; do { if ((__builtin_expect(!!(!(bus)),0)))
log_assert_failed_realm(LOG_REALM_SYSTEMD, ("bus"), "../src/resolve/resolved-bus.c"
, 16, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect
(!!(!(reply)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD,
("reply"), "../src/resolve/resolved-bus.c", 16, __PRETTY_FUNCTION__
); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("data"), "../src/resolve/resolved-bus.c"
, 16, __PRETTY_FUNCTION__); } while (0); return sd_bus_message_append
(reply, "s", resolve_support_to_string((*(data)))); }
;
17
18static int reply_query_state(DnsQuery *q) {
19
20 switch (q->state) {
21
22 case DNS_TRANSACTION_NO_SERVERS:
23 return sd_bus_reply_method_errorf(q->request, BUS_ERROR_NO_NAME_SERVERS"org.freedesktop.resolve1.NoNameServers", "No appropriate name servers or networks for name found");
24
25 case DNS_TRANSACTION_TIMEOUT:
26 return sd_bus_reply_method_errorf(q->request, SD_BUS_ERROR_TIMEOUT"org.freedesktop.DBus.Error.Timeout", "Query timed out");
27
28 case DNS_TRANSACTION_ATTEMPTS_MAX_REACHED:
29 return sd_bus_reply_method_errorf(q->request, SD_BUS_ERROR_TIMEOUT"org.freedesktop.DBus.Error.Timeout", "All attempts to contact name servers or networks failed");
30
31 case DNS_TRANSACTION_INVALID_REPLY:
32 return sd_bus_reply_method_errorf(q->request, BUS_ERROR_INVALID_REPLY"org.freedesktop.resolve1.InvalidReply", "Received invalid reply");
33
34 case DNS_TRANSACTION_ERRNO:
35 return sd_bus_reply_method_errnof(q->request, q->answer_errno, "Lookup failed due to system error: %m");
36
37 case DNS_TRANSACTION_ABORTED:
38 return sd_bus_reply_method_errorf(q->request, BUS_ERROR_ABORTED"org.freedesktop.resolve1.Aborted", "Query aborted");
39
40 case DNS_TRANSACTION_DNSSEC_FAILED:
41 return sd_bus_reply_method_errorf(q->request, BUS_ERROR_DNSSEC_FAILED"org.freedesktop.resolve1.DnssecFailed", "DNSSEC validation failed: %s",
42 dnssec_result_to_string(q->answer_dnssec_result));
43
44 case DNS_TRANSACTION_NO_TRUST_ANCHOR:
45 return sd_bus_reply_method_errorf(q->request, BUS_ERROR_NO_TRUST_ANCHOR"org.freedesktop.resolve1.NoTrustAnchor", "No suitable trust anchor known");
46
47 case DNS_TRANSACTION_RR_TYPE_UNSUPPORTED:
48 return sd_bus_reply_method_errorf(q->request, BUS_ERROR_RR_TYPE_UNSUPPORTED"org.freedesktop.resolve1.ResourceRecordTypeUnsupported", "Server does not support requested resource record type");
49
50 case DNS_TRANSACTION_NETWORK_DOWN:
51 return sd_bus_reply_method_errorf(q->request, BUS_ERROR_NETWORK_DOWN"org.freedesktop.resolve1.NetworkDown", "Network is down");
52
53 case DNS_TRANSACTION_NOT_FOUND:
54 /* We return this as NXDOMAIN. This is only generated when a host doesn't implement LLMNR/TCP, and we
55 * thus quickly know that we cannot resolve an in-addr.arpa or ip6.arpa address. */
56 return sd_bus_reply_method_errorf(q->request, _BUS_ERROR_DNS"org.freedesktop.resolve1.DnsError." "NXDOMAIN", "'%s' not found", dns_query_string(q));
57
58 case DNS_TRANSACTION_RCODE_FAILURE: {
59 _cleanup_(sd_bus_error_free)__attribute__((cleanup(sd_bus_error_free))) sd_bus_error error = SD_BUS_ERROR_NULL((const sd_bus_error) {(((void*)0)), (((void*)0)), 0});
60
61 if (q->answer_rcode == DNS_RCODE_NXDOMAIN)
62 sd_bus_error_setf(&error, _BUS_ERROR_DNS"org.freedesktop.resolve1.DnsError." "NXDOMAIN", "'%s' not found", dns_query_string(q));
63 else {
64 const char *rc, *n;
65 char p[DECIMAL_STR_MAX(q->answer_rcode)(2+(sizeof(q->answer_rcode) <= 1 ? 3 : sizeof(q->answer_rcode
) <= 2 ? 5 : sizeof(q->answer_rcode) <= 4 ? 10 : sizeof
(q->answer_rcode) <= 8 ? 20 : sizeof(int[-2*(sizeof(q->
answer_rcode) > 8)])))
];
66
67 rc = dns_rcode_to_string(q->answer_rcode);
68 if (!rc) {
69 sprintf(p, "%i", q->answer_rcode);
70 rc = p;
71 }
72
73 n = strjoina(_BUS_ERROR_DNS, rc)({ const char *_appendees_[] = { "org.freedesktop.resolve1.DnsError."
, rc }; char *_d_, *_p_; size_t _len_ = 0; size_t _i_; for (_i_
= 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p
(typeof(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_
)/sizeof((_appendees_)[0]), ((void)0))) && _appendees_
[_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca
(_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr
( !__builtin_types_compatible_p(typeof(_appendees_), typeof(&
*(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0]
), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy
(_p_, _appendees_[_i_]); *_p_ = 0; _d_; })
;
74 sd_bus_error_setf(&error, n, "Could not resolve '%s', server or network returned error %s", dns_query_string(q), rc);
75 }
76
77 return sd_bus_reply_method_error(q->request, &error);
78 }
79
80 case DNS_TRANSACTION_NULL:
81 case DNS_TRANSACTION_PENDING:
82 case DNS_TRANSACTION_VALIDATING:
83 case DNS_TRANSACTION_SUCCESS:
84 default:
85 assert_not_reached("Impossible state")do { log_assert_failed_unreachable_realm(LOG_REALM_SYSTEMD, (
"Impossible state"), "../src/resolve/resolved-bus.c", 85, __PRETTY_FUNCTION__
); } while (0)
;
86 }
87}
88
89static int append_address(sd_bus_message *reply, DnsResourceRecord *rr, int ifindex) {
90 int r;
91
92 assert(reply)do { if ((__builtin_expect(!!(!(reply)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("reply"), "../src/resolve/resolved-bus.c"
, 92, __PRETTY_FUNCTION__); } while (0)
;
93 assert(rr)do { if ((__builtin_expect(!!(!(rr)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("rr"), "../src/resolve/resolved-bus.c", 93
, __PRETTY_FUNCTION__); } while (0)
;
94
95 r = sd_bus_message_open_container(reply, 'r', "iiay");
96 if (r < 0)
97 return r;
98
99 r = sd_bus_message_append(reply, "i", ifindex);
100 if (r < 0)
101 return r;
102
103 if (rr->key->type == DNS_TYPE_A) {
104 r = sd_bus_message_append(reply, "i", AF_INET2);
105 if (r < 0)
106 return r;
107
108 r = sd_bus_message_append_array(reply, 'y', &rr->a.in_addr, sizeof(struct in_addr));
109
110 } else if (rr->key->type == DNS_TYPE_AAAA) {
111 r = sd_bus_message_append(reply, "i", AF_INET610);
112 if (r < 0)
113 return r;
114
115 r = sd_bus_message_append_array(reply, 'y', &rr->aaaa.in6_addr, sizeof(struct in6_addr));
116 } else
117 return -EAFNOSUPPORT97;
118
119 if (r < 0)
120 return r;
121
122 r = sd_bus_message_close_container(reply);
123 if (r < 0)
124 return r;
125
126 return 0;
127}
128
129static void bus_method_resolve_hostname_complete(DnsQuery *q) {
130 _cleanup_(dns_resource_record_unrefp)__attribute__((cleanup(dns_resource_record_unrefp))) DnsResourceRecord *canonical = NULL((void*)0);
131 _cleanup_(sd_bus_message_unrefp)__attribute__((cleanup(sd_bus_message_unrefp))) sd_bus_message *reply = NULL((void*)0);
132 _cleanup_free___attribute__((cleanup(freep))) char *normalized = NULL((void*)0);
133 DnsResourceRecord *rr;
134 unsigned added = 0;
135 int ifindex, r;
136
137 assert(q)do { if ((__builtin_expect(!!(!(q)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("q"), "../src/resolve/resolved-bus.c", 137
, __PRETTY_FUNCTION__); } while (0)
;
138
139 if (q->state != DNS_TRANSACTION_SUCCESS) {
140 r = reply_query_state(q);
141 goto finish;
142 }
143
144 r = dns_query_process_cname(q);
145 if (r == -ELOOP40) {
146 r = sd_bus_reply_method_errorf(q->request, BUS_ERROR_CNAME_LOOP"org.freedesktop.resolve1.CNameLoop", "CNAME loop detected, or CNAME resolving disabled on '%s'", dns_query_string(q));
147 goto finish;
148 }
149 if (r < 0)
150 goto finish;
151 if (r == DNS_QUERY_RESTARTED) /* This was a cname, and the query was restarted. */
152 return;
153
154 r = sd_bus_message_new_method_return(q->request, &reply);
155 if (r < 0)
156 goto finish;
157
158 r = sd_bus_message_open_container(reply, 'a', "(iiay)");
159 if (r < 0)
160 goto finish;
161
162 DNS_ANSWER_FOREACH_IFINDEX(rr, ifindex, q->answer)for (size_t __unique_prefix_i27 = ({ (rr) = ((q->answer) &&
(q->answer)->n_rrs > 0) ? (q->answer)->items[
0].rr : ((void*)0); (ifindex) = ((q->answer) && (q
->answer)->n_rrs > 0) ? (q->answer)->items[0].
ifindex : 0; 0; }); (q->answer) && (__unique_prefix_i27
< (q->answer)->n_rrs); __unique_prefix_i27++, (rr) =
((__unique_prefix_i27 < (q->answer)->n_rrs) ? (q->
answer)->items[__unique_prefix_i27].rr : ((void*)0)), (ifindex
) = ((__unique_prefix_i27 < (q->answer)->n_rrs) ? (q
->answer)->items[__unique_prefix_i27].ifindex : 0))
{
163 DnsQuestion *question;
164
165 question = dns_query_question_for_protocol(q, q->answer_protocol);
166
167 r = dns_question_matches_rr(question, rr, DNS_SEARCH_DOMAIN_NAME(q->answer_search_domain));
168 if (r < 0)
169 goto finish;
170 if (r == 0)
171 continue;
172
173 r = append_address(reply, rr, ifindex);
174 if (r < 0)
175 goto finish;
176
177 if (!canonical)
178 canonical = dns_resource_record_ref(rr);
179
180 added++;
181 }
182
183 if (added <= 0) {
184 r = sd_bus_reply_method_errorf(q->request, BUS_ERROR_NO_SUCH_RR"org.freedesktop.resolve1.NoSuchRR", "'%s' does not have any RR of the requested type", dns_query_string(q));
185 goto finish;
186 }
187
188 r = sd_bus_message_close_container(reply);
189 if (r < 0)
190 goto finish;
191
192 /* The key names are not necessarily normalized, make sure that they are when we return them to our bus
193 * clients. */
194 r = dns_name_normalize(dns_resource_key_name(canonical->key), &normalized);
195 if (r < 0)
196 goto finish;
197
198 /* Return the precise spelling and uppercasing and CNAME target reported by the server */
199 assert(canonical)do { if ((__builtin_expect(!!(!(canonical)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("canonical"), "../src/resolve/resolved-bus.c"
, 199, __PRETTY_FUNCTION__); } while (0)
;
200 r = sd_bus_message_append(
201 reply, "st",
202 normalized,
203 SD_RESOLVED_FLAGS_MAKE(q->answer_protocol, q->answer_family, dns_query_fully_authenticated(q)));
204 if (r < 0)
205 goto finish;
206
207 r = sd_bus_send(q->manager->bus, reply, NULL((void*)0));
208
209finish:
210 if (r < 0) {
211 log_error_errno(r, "Failed to send hostname reply: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/resolve/resolved-bus.c", 211, __func__, "Failed to send hostname reply: %m"
) : -abs(_e); })
;
212 sd_bus_reply_method_errno(q->request, r, NULL((void*)0));
213 }
214
215 dns_query_free(q);
216}
217
218static int check_ifindex_flags(int ifindex, uint64_t *flags, uint64_t ok, sd_bus_error *error) {
219 assert(flags)do { if ((__builtin_expect(!!(!(flags)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("flags"), "../src/resolve/resolved-bus.c"
, 219, __PRETTY_FUNCTION__); } while (0)
;
220
221 if (ifindex < 0)
222 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid interface index");
223
224 if (*flags & ~(SD_RESOLVED_PROTOCOLS_ALL(((1UL << 3)|(1UL << 4))|((1UL << 1)|(1UL <<
2))|(1UL << 0))
|SD_RESOLVED_NO_CNAME(1UL << 5)|ok))
225 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid flags parameter");
226
227 if ((*flags & SD_RESOLVED_PROTOCOLS_ALL(((1UL << 3)|(1UL << 4))|((1UL << 1)|(1UL <<
2))|(1UL << 0))
) == 0) /* If no protocol is enabled, enable all */
228 *flags |= SD_RESOLVED_PROTOCOLS_ALL(((1UL << 3)|(1UL << 4))|((1UL << 1)|(1UL <<
2))|(1UL << 0))
;
229
230 return 0;
231}
232
233static int parse_as_address(sd_bus_message *m, int ifindex, const char *hostname, int family, uint64_t flags) {
234 _cleanup_(sd_bus_message_unrefp)__attribute__((cleanup(sd_bus_message_unrefp))) sd_bus_message *reply = NULL((void*)0);
235 _cleanup_free___attribute__((cleanup(freep))) char *canonical = NULL((void*)0);
236 union in_addr_union parsed;
237 int r, ff, parsed_ifindex = 0;
238
239 /* Check if the hostname is actually already an IP address formatted as string. In that case just parse it,
240 * let's not attempt to look it up. */
241
242 r = in_addr_ifindex_from_string_auto(hostname, &ff, &parsed, &parsed_ifindex);
243 if (r < 0) /* not an address */
244 return 0;
245
246 if (family != AF_UNSPEC0 && ff != family)
247 return sd_bus_reply_method_errorf(m, BUS_ERROR_NO_SUCH_RR"org.freedesktop.resolve1.NoSuchRR", "The specified address is not of the requested family.");
248 if (ifindex > 0 && parsed_ifindex > 0 && parsed_ifindex != ifindex)
249 return sd_bus_reply_method_errorf(m, BUS_ERROR_NO_SUCH_RR"org.freedesktop.resolve1.NoSuchRR", "The specified address interface index does not match requested interface.");
250
251 if (parsed_ifindex > 0)
252 ifindex = parsed_ifindex;
253
254 r = sd_bus_message_new_method_return(m, &reply);
255 if (r < 0)
256 return r;
257
258 r = sd_bus_message_open_container(reply, 'a', "(iiay)");
259 if (r < 0)
260 return r;
261
262 r = sd_bus_message_open_container(reply, 'r', "iiay");
263 if (r < 0)
264 return r;
265
266 r = sd_bus_message_append(reply, "ii", ifindex, ff);
267 if (r < 0)
268 return r;
269
270 r = sd_bus_message_append_array(reply, 'y', &parsed, FAMILY_ADDRESS_SIZE(ff));
271 if (r < 0)
272 return r;
273
274 r = sd_bus_message_close_container(reply);
275 if (r < 0)
276 return r;
277
278 r = sd_bus_message_close_container(reply);
279 if (r < 0)
280 return r;
281
282 /* When an IP address is specified we just return it as canonical name, in order to avoid a DNS
283 * look-up. However, we reformat it to make sure it's in a truly canonical form (i.e. on IPv6 the inner
284 * omissions are always done the same way). */
285 r = in_addr_ifindex_to_string(ff, &parsed, ifindex, &canonical);
286 if (r < 0)
287 return r;
288
289 r = sd_bus_message_append(reply, "st", canonical,
290 SD_RESOLVED_FLAGS_MAKE(dns_synthesize_protocol(flags), ff, true1));
291 if (r < 0)
292 return r;
293
294 return sd_bus_send(sd_bus_message_get_bus(m), reply, NULL((void*)0));
295}
296
297static int bus_method_resolve_hostname(sd_bus_message *message, void *userdata, sd_bus_error *error) {
298 _cleanup_(dns_question_unrefp)__attribute__((cleanup(dns_question_unrefp))) DnsQuestion *question_idna = NULL((void*)0), *question_utf8 = NULL((void*)0);
299 Manager *m = userdata;
300 const char *hostname;
301 int family, ifindex;
302 uint64_t flags;
303 DnsQuery *q;
304 int r;
305
306 assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("message"), "../src/resolve/resolved-bus.c"
, 306, __PRETTY_FUNCTION__); } while (0)
;
307 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/resolve/resolved-bus.c", 307
, __PRETTY_FUNCTION__); } while (0)
;
308
309 assert_cc(sizeof(int) == sizeof(int32_t))GCC diagnostic push ; GCC diagnostic ignored "-Wdeclaration-after-statement"
; struct _assert_struct_28 { char x[(sizeof(int) == sizeof(int32_t
)) ? 0 : -1]; }; GCC diagnostic pop
;
310
311 r = sd_bus_message_read(message, "isit", &ifindex, &hostname, &family, &flags);
312 if (r < 0)
313 return r;
314
315 if (!IN_SET(family, AF_INET, AF_INET6, AF_UNSPEC)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){2, 10, 0})/sizeof(int)]; switch(family) {
case 2: case 10: case 0: _found = 1; break; default: break; }
_found; })
)
316 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Unknown address family %i", family);
317
318 r = check_ifindex_flags(ifindex, &flags, SD_RESOLVED_NO_SEARCH(1UL << 8), error);
319 if (r < 0)
320 return r;
321
322 r = parse_as_address(message, ifindex, hostname, family, flags);
323 if (r != 0)
324 return r;
325
326 r = dns_name_is_valid(hostname);
327 if (r < 0)
328 return r;
329 if (r == 0)
330 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid hostname '%s'", hostname);
331
332 r = dns_question_new_address(&question_utf8, family, hostname, false0);
333 if (r < 0)
334 return r;
335
336 r = dns_question_new_address(&question_idna, family, hostname, true1);
337 if (r < 0 && r != -EALREADY114)
338 return r;
339
340 r = dns_query_new(m, &q, question_utf8, question_idna ?: question_utf8, ifindex, flags);
341 if (r < 0)
342 return r;
343
344 q->request = sd_bus_message_ref(message);
345 q->request_family = family;
346 q->complete = bus_method_resolve_hostname_complete;
347 q->suppress_unroutable_family = family == AF_UNSPEC0;
348
349 r = dns_query_bus_track(q, message);
350 if (r < 0)
351 goto fail;
352
353 r = dns_query_go(q);
354 if (r < 0)
355 goto fail;
356
357 return 1;
358
359fail:
360 dns_query_free(q);
361 return r;
362}
363
364static void bus_method_resolve_address_complete(DnsQuery *q) {
365 _cleanup_(sd_bus_message_unrefp)__attribute__((cleanup(sd_bus_message_unrefp))) sd_bus_message *reply = NULL((void*)0);
366 DnsQuestion *question;
367 DnsResourceRecord *rr;
368 unsigned added = 0;
369 int ifindex, r;
370
371 assert(q)do { if ((__builtin_expect(!!(!(q)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("q"), "../src/resolve/resolved-bus.c", 371
, __PRETTY_FUNCTION__); } while (0)
;
372
373 if (q->state != DNS_TRANSACTION_SUCCESS) {
374 r = reply_query_state(q);
375 goto finish;
376 }
377
378 r = dns_query_process_cname(q);
379 if (r == -ELOOP40) {
380 r = sd_bus_reply_method_errorf(q->request, BUS_ERROR_CNAME_LOOP"org.freedesktop.resolve1.CNameLoop", "CNAME loop detected, or CNAME resolving disabled on '%s'", dns_query_string(q));
381 goto finish;
382 }
383 if (r < 0)
384 goto finish;
385 if (r == DNS_QUERY_RESTARTED) /* This was a cname, and the query was restarted. */
386 return;
387
388 r = sd_bus_message_new_method_return(q->request, &reply);
389 if (r < 0)
390 goto finish;
391
392 r = sd_bus_message_open_container(reply, 'a', "(is)");
393 if (r < 0)
394 goto finish;
395
396 question = dns_query_question_for_protocol(q, q->answer_protocol);
397
398 DNS_ANSWER_FOREACH_IFINDEX(rr, ifindex, q->answer)for (size_t __unique_prefix_i29 = ({ (rr) = ((q->answer) &&
(q->answer)->n_rrs > 0) ? (q->answer)->items[
0].rr : ((void*)0); (ifindex) = ((q->answer) && (q
->answer)->n_rrs > 0) ? (q->answer)->items[0].
ifindex : 0; 0; }); (q->answer) && (__unique_prefix_i29
< (q->answer)->n_rrs); __unique_prefix_i29++, (rr) =
((__unique_prefix_i29 < (q->answer)->n_rrs) ? (q->
answer)->items[__unique_prefix_i29].rr : ((void*)0)), (ifindex
) = ((__unique_prefix_i29 < (q->answer)->n_rrs) ? (q
->answer)->items[__unique_prefix_i29].ifindex : 0))
{
399 _cleanup_free___attribute__((cleanup(freep))) char *normalized = NULL((void*)0);
400
401 r = dns_question_matches_rr(question, rr, NULL((void*)0));
402 if (r < 0)
403 goto finish;
404 if (r == 0)
405 continue;
406
407 r = dns_name_normalize(rr->ptr.name, &normalized);
408 if (r < 0)
409 goto finish;
410
411 r = sd_bus_message_append(reply, "(is)", ifindex, normalized);
412 if (r < 0)
413 goto finish;
414
415 added++;
416 }
417
418 if (added <= 0) {
419 _cleanup_free___attribute__((cleanup(freep))) char *ip = NULL((void*)0);
420
421 (void) in_addr_to_string(q->request_family, &q->request_address, &ip);
422 r = sd_bus_reply_method_errorf(q->request, BUS_ERROR_NO_SUCH_RR"org.freedesktop.resolve1.NoSuchRR",
423 "Address '%s' does not have any RR of requested type", strnull(ip));
424 goto finish;
425 }
426
427 r = sd_bus_message_close_container(reply);
428 if (r < 0)
429 goto finish;
430
431 r = sd_bus_message_append(reply, "t", SD_RESOLVED_FLAGS_MAKE(q->answer_protocol, q->answer_family, dns_query_fully_authenticated(q)));
432 if (r < 0)
433 goto finish;
434
435 r = sd_bus_send(q->manager->bus, reply, NULL((void*)0));
436
437finish:
438 if (r < 0) {
439 log_error_errno(r, "Failed to send address reply: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/resolve/resolved-bus.c", 439, __func__, "Failed to send address reply: %m"
) : -abs(_e); })
;
440 sd_bus_reply_method_errno(q->request, r, NULL((void*)0));
441 }
442
443 dns_query_free(q);
444}
445
446static int bus_method_resolve_address(sd_bus_message *message, void *userdata, sd_bus_error *error) {
447 _cleanup_(dns_question_unrefp)__attribute__((cleanup(dns_question_unrefp))) DnsQuestion *question = NULL((void*)0);
448 Manager *m = userdata;
449 int family, ifindex;
450 uint64_t flags;
451 const void *d;
452 DnsQuery *q;
453 size_t sz;
454 int r;
455
456 assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("message"), "../src/resolve/resolved-bus.c"
, 456, __PRETTY_FUNCTION__); } while (0)
;
457 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/resolve/resolved-bus.c", 457
, __PRETTY_FUNCTION__); } while (0)
;
458
459 assert_cc(sizeof(int) == sizeof(int32_t))GCC diagnostic push ; GCC diagnostic ignored "-Wdeclaration-after-statement"
; struct _assert_struct_30 { char x[(sizeof(int) == sizeof(int32_t
)) ? 0 : -1]; }; GCC diagnostic pop
;
460
461 r = sd_bus_message_read(message, "ii", &ifindex, &family);
462 if (r < 0)
463 return r;
464
465 if (!IN_SET(family, AF_INET, AF_INET6)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){2, 10})/sizeof(int)]; switch(family) { case
2: case 10: _found = 1; break; default: break; } _found; })
)
466 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Unknown address family %i", family);
467
468 r = sd_bus_message_read_array(message, 'y', &d, &sz);
469 if (r < 0)
470 return r;
471
472 if (sz != FAMILY_ADDRESS_SIZE(family))
473 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid address size");
474
475 r = sd_bus_message_read(message, "t", &flags);
476 if (r < 0)
477 return r;
478
479 r = check_ifindex_flags(ifindex, &flags, 0, error);
480 if (r < 0)
481 return r;
482
483 r = dns_question_new_reverse(&question, family, d);
484 if (r < 0)
485 return r;
486
487 r = dns_query_new(m, &q, question, question, ifindex, flags|SD_RESOLVED_NO_SEARCH(1UL << 8));
488 if (r < 0)
489 return r;
490
491 q->request = sd_bus_message_ref(message);
492 q->request_family = family;
493 memcpy(&q->request_address, d, sz);
494 q->complete = bus_method_resolve_address_complete;
495
496 r = dns_query_bus_track(q, message);
497 if (r < 0)
498 goto fail;
499
500 r = dns_query_go(q);
501 if (r < 0)
502 goto fail;
503
504 return 1;
505
506fail:
507 dns_query_free(q);
508 return r;
509}
510
511static int bus_message_append_rr(sd_bus_message *m, DnsResourceRecord *rr, int ifindex) {
512 int r;
513
514 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/resolve/resolved-bus.c", 514
, __PRETTY_FUNCTION__); } while (0)
;
515 assert(rr)do { if ((__builtin_expect(!!(!(rr)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("rr"), "../src/resolve/resolved-bus.c", 515
, __PRETTY_FUNCTION__); } while (0)
;
516
517 r = sd_bus_message_open_container(m, 'r', "iqqay");
518 if (r < 0)
519 return r;
520
521 r = sd_bus_message_append(m, "iqq",
522 ifindex,
523 rr->key->class,
524 rr->key->type);
525 if (r < 0)
526 return r;
527
528 r = dns_resource_record_to_wire_format(rr, false0);
529 if (r < 0)
530 return r;
531
532 r = sd_bus_message_append_array(m, 'y', rr->wire_format, rr->wire_format_size);
533 if (r < 0)
534 return r;
535
536 return sd_bus_message_close_container(m);
537}
538
539static void bus_method_resolve_record_complete(DnsQuery *q) {
540 _cleanup_(sd_bus_message_unrefp)__attribute__((cleanup(sd_bus_message_unrefp))) sd_bus_message *reply = NULL((void*)0);
541 DnsResourceRecord *rr;
542 DnsQuestion *question;
543 unsigned added = 0;
544 int ifindex;
545 int r;
546
547 assert(q)do { if ((__builtin_expect(!!(!(q)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("q"), "../src/resolve/resolved-bus.c", 547
, __PRETTY_FUNCTION__); } while (0)
;
548
549 if (q->state != DNS_TRANSACTION_SUCCESS) {
550 r = reply_query_state(q);
551 goto finish;
552 }
553
554 r = dns_query_process_cname(q);
555 if (r == -ELOOP40) {
556 r = sd_bus_reply_method_errorf(q->request, BUS_ERROR_CNAME_LOOP"org.freedesktop.resolve1.CNameLoop", "CNAME loop detected, or CNAME resolving disabled on '%s'", dns_query_string(q));
557 goto finish;
558 }
559 if (r < 0)
560 goto finish;
561 if (r == DNS_QUERY_RESTARTED) /* This was a cname, and the query was restarted. */
562 return;
563
564 r = sd_bus_message_new_method_return(q->request, &reply);
565 if (r < 0)
566 goto finish;
567
568 r = sd_bus_message_open_container(reply, 'a', "(iqqay)");
569 if (r < 0)
570 goto finish;
571
572 question = dns_query_question_for_protocol(q, q->answer_protocol);
573
574 DNS_ANSWER_FOREACH_IFINDEX(rr, ifindex, q->answer)for (size_t __unique_prefix_i31 = ({ (rr) = ((q->answer) &&
(q->answer)->n_rrs > 0) ? (q->answer)->items[
0].rr : ((void*)0); (ifindex) = ((q->answer) && (q
->answer)->n_rrs > 0) ? (q->answer)->items[0].
ifindex : 0; 0; }); (q->answer) && (__unique_prefix_i31
< (q->answer)->n_rrs); __unique_prefix_i31++, (rr) =
((__unique_prefix_i31 < (q->answer)->n_rrs) ? (q->
answer)->items[__unique_prefix_i31].rr : ((void*)0)), (ifindex
) = ((__unique_prefix_i31 < (q->answer)->n_rrs) ? (q
->answer)->items[__unique_prefix_i31].ifindex : 0))
{
575 r = dns_question_matches_rr(question, rr, NULL((void*)0));
576 if (r < 0)
577 goto finish;
578 if (r == 0)
579 continue;
580
581 r = bus_message_append_rr(reply, rr, ifindex);
582 if (r < 0)
583 goto finish;
584
585 added++;
586 }
587
588 if (added <= 0) {
589 r = sd_bus_reply_method_errorf(q->request, BUS_ERROR_NO_SUCH_RR"org.freedesktop.resolve1.NoSuchRR", "Name '%s' does not have any RR of the requested type", dns_query_string(q));
590 goto finish;
591 }
592
593 r = sd_bus_message_close_container(reply);
594 if (r < 0)
595 goto finish;
596
597 r = sd_bus_message_append(reply, "t", SD_RESOLVED_FLAGS_MAKE(q->answer_protocol, q->answer_family, dns_query_fully_authenticated(q)));
598 if (r < 0)
599 goto finish;
600
601 r = sd_bus_send(q->manager->bus, reply, NULL((void*)0));
602
603finish:
604 if (r < 0) {
605 log_error_errno(r, "Failed to send record reply: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/resolve/resolved-bus.c", 605, __func__, "Failed to send record reply: %m"
) : -abs(_e); })
;
606 sd_bus_reply_method_errno(q->request, r, NULL((void*)0));
607 }
608
609 dns_query_free(q);
610}
611
612static int bus_method_resolve_record(sd_bus_message *message, void *userdata, sd_bus_error *error) {
613 _cleanup_(dns_resource_key_unrefp)__attribute__((cleanup(dns_resource_key_unrefp))) DnsResourceKey *key = NULL((void*)0);
614 _cleanup_(dns_question_unrefp)__attribute__((cleanup(dns_question_unrefp))) DnsQuestion *question = NULL((void*)0);
615 Manager *m = userdata;
616 uint16_t class, type;
617 const char *name;
618 int r, ifindex;
619 uint64_t flags;
620 DnsQuery *q;
621
622 assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("message"), "../src/resolve/resolved-bus.c"
, 622, __PRETTY_FUNCTION__); } while (0)
;
623 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/resolve/resolved-bus.c", 623
, __PRETTY_FUNCTION__); } while (0)
;
624
625 assert_cc(sizeof(int) == sizeof(int32_t))GCC diagnostic push ; GCC diagnostic ignored "-Wdeclaration-after-statement"
; struct _assert_struct_32 { char x[(sizeof(int) == sizeof(int32_t
)) ? 0 : -1]; }; GCC diagnostic pop
;
626
627 r = sd_bus_message_read(message, "isqqt", &ifindex, &name, &class, &type, &flags);
628 if (r < 0)
629 return r;
630
631 r = dns_name_is_valid(name);
632 if (r < 0)
633 return r;
634 if (r == 0)
635 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid name '%s'", name);
636
637 if (!dns_type_is_valid_query(type))
638 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Specified resource record type %" PRIu16"u" " may not be used in a query.", type);
639 if (dns_type_is_zone_transer(type))
640 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED"org.freedesktop.DBus.Error.NotSupported", "Zone transfers not permitted via this programming interface.");
641 if (dns_type_is_obsolete(type))
642 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED"org.freedesktop.DBus.Error.NotSupported", "Specified DNS resource record type %" PRIu16"u" " is obsolete.", type);
643
644 r = check_ifindex_flags(ifindex, &flags, 0, error);
645 if (r < 0)
646 return r;
647
648 question = dns_question_new(1);
649 if (!question)
650 return -ENOMEM12;
651
652 key = dns_resource_key_new(class, type, name);
653 if (!key)
654 return -ENOMEM12;
655
656 r = dns_question_add(question, key);
657 if (r < 0)
658 return r;
659
660 r = dns_query_new(m, &q, question, question, ifindex, flags|SD_RESOLVED_NO_SEARCH(1UL << 8));
661 if (r < 0)
662 return r;
663
664 /* Let's request that the TTL is fixed up for locally cached entries, after all we return it in the wire format
665 * blob */
666 q->clamp_ttl = true1;
667
668 q->request = sd_bus_message_ref(message);
669 q->complete = bus_method_resolve_record_complete;
670
671 r = dns_query_bus_track(q, message);
672 if (r < 0)
673 goto fail;
674
675 r = dns_query_go(q);
676 if (r < 0)
677 goto fail;
678
679 return 1;
680
681fail:
682 dns_query_free(q);
683 return r;
684}
685
686static int append_srv(DnsQuery *q, sd_bus_message *reply, DnsResourceRecord *rr) {
687 _cleanup_(dns_resource_record_unrefp)__attribute__((cleanup(dns_resource_record_unrefp))) DnsResourceRecord *canonical = NULL((void*)0);
688 _cleanup_free___attribute__((cleanup(freep))) char *normalized = NULL((void*)0);
689 DnsQuery *aux;
690 int r;
691
692 assert(q)do { if ((__builtin_expect(!!(!(q)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("q"), "../src/resolve/resolved-bus.c", 692
, __PRETTY_FUNCTION__); } while (0)
;
693 assert(reply)do { if ((__builtin_expect(!!(!(reply)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("reply"), "../src/resolve/resolved-bus.c"
, 693, __PRETTY_FUNCTION__); } while (0)
;
694 assert(rr)do { if ((__builtin_expect(!!(!(rr)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("rr"), "../src/resolve/resolved-bus.c", 694
, __PRETTY_FUNCTION__); } while (0)
;
695 assert(rr->key)do { if ((__builtin_expect(!!(!(rr->key)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("rr->key"), "../src/resolve/resolved-bus.c"
, 695, __PRETTY_FUNCTION__); } while (0)
;
696
697 if (rr->key->type != DNS_TYPE_SRV)
698 return 0;
699
700 if ((q->flags & SD_RESOLVED_NO_ADDRESS(1UL << 7)) == 0) {
701 /* First, let's see if we could find an appropriate A or AAAA
702 * record for the SRV record */
703 LIST_FOREACH(auxiliary_queries, aux, q->auxiliary_queries)for ((aux) = (q->auxiliary_queries); (aux); (aux) = (aux)->
auxiliary_queries_next)
{
704 DnsResourceRecord *zz;
705 DnsQuestion *question;
706
707 if (aux->state != DNS_TRANSACTION_SUCCESS)
708 continue;
709 if (aux->auxiliary_result != 0)
710 continue;
711
712 question = dns_query_question_for_protocol(aux, aux->answer_protocol);
713
714 r = dns_name_equal(dns_question_first_name(question), rr->srv.name);
715 if (r < 0)
716 return r;
717 if (r == 0)
718 continue;
719
720 DNS_ANSWER_FOREACH(zz, aux->answer)for (size_t __unique_prefix_i33 = ({ (zz) = ((aux->answer)
&& (aux->answer)->n_rrs > 0) ? (aux->answer
)->items[0].rr : ((void*)0); 0; }); (aux->answer) &&
(__unique_prefix_i33 < (aux->answer)->n_rrs); __unique_prefix_i33
++, (zz) = (__unique_prefix_i33 < (aux->answer)->n_rrs
? (aux->answer)->items[__unique_prefix_i33].rr : ((void
*)0)))
{
721
722 r = dns_question_matches_rr(question, zz, NULL((void*)0));
723 if (r < 0)
724 return r;
725 if (r == 0)
726 continue;
727
728 canonical = dns_resource_record_ref(zz);
729 break;
730 }
731
732 if (canonical)
733 break;
734 }
735
736 /* Is there are successful A/AAAA lookup for this SRV RR? If not, don't add it */
737 if (!canonical)
738 return 0;
739 }
740
741 r = sd_bus_message_open_container(reply, 'r', "qqqsa(iiay)s");
742 if (r < 0)
743 return r;
744
745 r = dns_name_normalize(rr->srv.name, &normalized);
746 if (r < 0)
747 return r;
748
749 r = sd_bus_message_append(
750 reply,
751 "qqqs",
752 rr->srv.priority, rr->srv.weight, rr->srv.port, normalized);
753 if (r < 0)
754 return r;
755
756 r = sd_bus_message_open_container(reply, 'a', "(iiay)");
757 if (r < 0)
758 return r;
759
760 if ((q->flags & SD_RESOLVED_NO_ADDRESS(1UL << 7)) == 0) {
761 LIST_FOREACH(auxiliary_queries, aux, q->auxiliary_queries)for ((aux) = (q->auxiliary_queries); (aux); (aux) = (aux)->
auxiliary_queries_next)
{
762 DnsResourceRecord *zz;
763 DnsQuestion *question;
764 int ifindex;
765
766 if (aux->state != DNS_TRANSACTION_SUCCESS)
767 continue;
768 if (aux->auxiliary_result != 0)
769 continue;
770
771 question = dns_query_question_for_protocol(aux, aux->answer_protocol);
772
773 r = dns_name_equal(dns_question_first_name(question), rr->srv.name);
774 if (r < 0)
775 return r;
776 if (r == 0)
777 continue;
778
779 DNS_ANSWER_FOREACH_IFINDEX(zz, ifindex, aux->answer)for (size_t __unique_prefix_i34 = ({ (zz) = ((aux->answer)
&& (aux->answer)->n_rrs > 0) ? (aux->answer
)->items[0].rr : ((void*)0); (ifindex) = ((aux->answer)
&& (aux->answer)->n_rrs > 0) ? (aux->answer
)->items[0].ifindex : 0; 0; }); (aux->answer) &&
(__unique_prefix_i34 < (aux->answer)->n_rrs); __unique_prefix_i34
++, (zz) = ((__unique_prefix_i34 < (aux->answer)->n_rrs
) ? (aux->answer)->items[__unique_prefix_i34].rr : ((void
*)0)), (ifindex) = ((__unique_prefix_i34 < (aux->answer
)->n_rrs) ? (aux->answer)->items[__unique_prefix_i34
].ifindex : 0))
{
780
781 r = dns_question_matches_rr(question, zz, NULL((void*)0));
782 if (r < 0)
783 return r;
784 if (r == 0)
785 continue;
786
787 r = append_address(reply, zz, ifindex);
788 if (r < 0)
789 return r;
790 }
791 }
792 }
793
794 r = sd_bus_message_close_container(reply);
795 if (r < 0)
796 return r;
797
798 if (canonical) {
799 normalized = mfree(normalized);
800
801 r = dns_name_normalize(dns_resource_key_name(canonical->key), &normalized);
802 if (r < 0)
803 return r;
804 }
805
806 /* Note that above we appended the hostname as encoded in the
807 * SRV, and here the canonical hostname this maps to. */
808 r = sd_bus_message_append(reply, "s", normalized);
809 if (r < 0)
810 return r;
811
812 r = sd_bus_message_close_container(reply);
813 if (r < 0)
814 return r;
815
816 return 1;
817}
818
819static int append_txt(sd_bus_message *reply, DnsResourceRecord *rr) {
820 DnsTxtItem *i;
821 int r;
822
823 assert(reply)do { if ((__builtin_expect(!!(!(reply)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("reply"), "../src/resolve/resolved-bus.c"
, 823, __PRETTY_FUNCTION__); } while (0)
;
824 assert(rr)do { if ((__builtin_expect(!!(!(rr)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("rr"), "../src/resolve/resolved-bus.c", 824
, __PRETTY_FUNCTION__); } while (0)
;
825 assert(rr->key)do { if ((__builtin_expect(!!(!(rr->key)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("rr->key"), "../src/resolve/resolved-bus.c"
, 825, __PRETTY_FUNCTION__); } while (0)
;
826
827 if (rr->key->type != DNS_TYPE_TXT)
828 return 0;
829
830 LIST_FOREACH(items, i, rr->txt.items)for ((i) = (rr->txt.items); (i); (i) = (i)->items_next) {
831
832 if (i->length <= 0)
833 continue;
834
835 r = sd_bus_message_append_array(reply, 'y', i->data, i->length);
836 if (r < 0)
837 return r;
838 }
839
840 return 1;
841}
842
843static void resolve_service_all_complete(DnsQuery *q) {
844 _cleanup_(dns_resource_record_unrefp)__attribute__((cleanup(dns_resource_record_unrefp))) DnsResourceRecord *canonical = NULL((void*)0);
845 _cleanup_(sd_bus_message_unrefp)__attribute__((cleanup(sd_bus_message_unrefp))) sd_bus_message *reply = NULL((void*)0);
846 _cleanup_free___attribute__((cleanup(freep))) char *name = NULL((void*)0), *type = NULL((void*)0), *domain = NULL((void*)0);
847 DnsQuestion *question;
848 DnsResourceRecord *rr;
849 unsigned added = 0;
850 DnsQuery *aux;
851 int r;
852
853 assert(q)do { if ((__builtin_expect(!!(!(q)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("q"), "../src/resolve/resolved-bus.c", 853
, __PRETTY_FUNCTION__); } while (0)
;
854
855 if (q->block_all_complete > 0)
856 return;
857
858 if ((q->flags & SD_RESOLVED_NO_ADDRESS(1UL << 7)) == 0) {
859 DnsQuery *bad = NULL((void*)0);
860 bool_Bool have_success = false0;
861
862 LIST_FOREACH(auxiliary_queries, aux, q->auxiliary_queries)for ((aux) = (q->auxiliary_queries); (aux); (aux) = (aux)->
auxiliary_queries_next)
{
863
864 switch (aux->state) {
865
866 case DNS_TRANSACTION_PENDING:
867 /* If an auxiliary query is still pending, let's wait */
868 return;
869
870 case DNS_TRANSACTION_SUCCESS:
871 if (aux->auxiliary_result == 0)
872 have_success = true1;
873 else
874 bad = aux;
875 break;
876
877 default:
878 bad = aux;
879 break;
880 }
881 }
882
883 if (!have_success) {
884 /* We can only return one error, hence pick the last error we encountered */
885
886 assert(bad)do { if ((__builtin_expect(!!(!(bad)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("bad"), "../src/resolve/resolved-bus.c",
886, __PRETTY_FUNCTION__); } while (0)
;
887
888 if (bad->state == DNS_TRANSACTION_SUCCESS) {
889 assert(bad->auxiliary_result != 0)do { if ((__builtin_expect(!!(!(bad->auxiliary_result != 0
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("bad->auxiliary_result != 0"
), "../src/resolve/resolved-bus.c", 889, __PRETTY_FUNCTION__)
; } while (0)
;
890
891 if (bad->auxiliary_result == -ELOOP40) {
892 r = sd_bus_reply_method_errorf(q->request, BUS_ERROR_CNAME_LOOP"org.freedesktop.resolve1.CNameLoop", "CNAME loop detected, or CNAME resolving disabled on '%s'", dns_query_string(bad));
893 goto finish;
894 }
895
896 r = bad->auxiliary_result;
897 goto finish;
898 }
899
900 r = reply_query_state(bad);
901 goto finish;
902 }
903 }
904
905 r = sd_bus_message_new_method_return(q->request, &reply);
906 if (r < 0)
907 goto finish;
908
909 r = sd_bus_message_open_container(reply, 'a', "(qqqsa(iiay)s)");
910 if (r < 0)
911 goto finish;
912
913 question = dns_query_question_for_protocol(q, q->answer_protocol);
914 DNS_ANSWER_FOREACH(rr, q->answer)for (size_t __unique_prefix_i35 = ({ (rr) = ((q->answer) &&
(q->answer)->n_rrs > 0) ? (q->answer)->items[
0].rr : ((void*)0); 0; }); (q->answer) && (__unique_prefix_i35
< (q->answer)->n_rrs); __unique_prefix_i35++, (rr) =
(__unique_prefix_i35 < (q->answer)->n_rrs ? (q->
answer)->items[__unique_prefix_i35].rr : ((void*)0)))
{
915 r = dns_question_matches_rr(question, rr, NULL((void*)0));
916 if (r < 0)
917 goto finish;
918 if (r == 0)
919 continue;
920
921 r = append_srv(q, reply, rr);
922 if (r < 0)
923 goto finish;
924 if (r == 0) /* not an SRV record */
925 continue;
926
927 if (!canonical)
928 canonical = dns_resource_record_ref(rr);
929
930 added++;
931 }
932
933 if (added <= 0) {
934 r = sd_bus_reply_method_errorf(q->request, BUS_ERROR_NO_SUCH_RR"org.freedesktop.resolve1.NoSuchRR", "'%s' does not have any RR of the requested type", dns_query_string(q));
935 goto finish;
936 }
937
938 r = sd_bus_message_close_container(reply);
939 if (r < 0)
940 goto finish;
941
942 r = sd_bus_message_open_container(reply, 'a', "ay");
943 if (r < 0)
944 goto finish;
945
946 DNS_ANSWER_FOREACH(rr, q->answer)for (size_t __unique_prefix_i36 = ({ (rr) = ((q->answer) &&
(q->answer)->n_rrs > 0) ? (q->answer)->items[
0].rr : ((void*)0); 0; }); (q->answer) && (__unique_prefix_i36
< (q->answer)->n_rrs); __unique_prefix_i36++, (rr) =
(__unique_prefix_i36 < (q->answer)->n_rrs ? (q->
answer)->items[__unique_prefix_i36].rr : ((void*)0)))
{
947 r = dns_question_matches_rr(question, rr, NULL((void*)0));
948 if (r < 0)
949 goto finish;
950 if (r == 0)
951 continue;
952
953 r = append_txt(reply, rr);
954 if (r < 0)
955 goto finish;
956 }
957
958 r = sd_bus_message_close_container(reply);
959 if (r < 0)
960 goto finish;
961
962 assert(canonical)do { if ((__builtin_expect(!!(!(canonical)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("canonical"), "../src/resolve/resolved-bus.c"
, 962, __PRETTY_FUNCTION__); } while (0)
;
963 r = dns_service_split(dns_resource_key_name(canonical->key), &name, &type, &domain);
964 if (r < 0)
965 goto finish;
966
967 r = sd_bus_message_append(
968 reply,
969 "ssst",
970 name, type, domain,
971 SD_RESOLVED_FLAGS_MAKE(q->answer_protocol, q->answer_family, dns_query_fully_authenticated(q)));
972 if (r < 0)
973 goto finish;
974
975 r = sd_bus_send(q->manager->bus, reply, NULL((void*)0));
976
977finish:
978 if (r < 0) {
979 log_error_errno(r, "Failed to send service reply: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/resolve/resolved-bus.c", 979, __func__, "Failed to send service reply: %m"
) : -abs(_e); })
;
980 sd_bus_reply_method_errno(q->request, r, NULL((void*)0));
981 }
982
983 dns_query_free(q);
984}
985
986static void resolve_service_hostname_complete(DnsQuery *q) {
987 int r;
988
989 assert(q)do { if ((__builtin_expect(!!(!(q)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("q"), "../src/resolve/resolved-bus.c", 989
, __PRETTY_FUNCTION__); } while (0)
;
990 assert(q->auxiliary_for)do { if ((__builtin_expect(!!(!(q->auxiliary_for)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("q->auxiliary_for"), "../src/resolve/resolved-bus.c"
, 990, __PRETTY_FUNCTION__); } while (0)
;
991
992 if (q->state != DNS_TRANSACTION_SUCCESS) {
993 resolve_service_all_complete(q->auxiliary_for);
994 return;
995 }
996
997 r = dns_query_process_cname(q);
998 if (r == DNS_QUERY_RESTARTED) /* This was a cname, and the query was restarted. */
999 return;
1000
1001 /* This auxiliary lookup is finished or failed, let's see if all are finished now. */
1002 q->auxiliary_result = r;
1003 resolve_service_all_complete(q->auxiliary_for);
1004}
1005
1006static int resolve_service_hostname(DnsQuery *q, DnsResourceRecord *rr, int ifindex) {
1007 _cleanup_(dns_question_unrefp)__attribute__((cleanup(dns_question_unrefp))) DnsQuestion *question = NULL((void*)0);
1008 DnsQuery *aux;
1009 int r;
1010
1011 assert(q)do { if ((__builtin_expect(!!(!(q)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("q"), "../src/resolve/resolved-bus.c", 1011
, __PRETTY_FUNCTION__); } while (0)
;
1012 assert(rr)do { if ((__builtin_expect(!!(!(rr)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("rr"), "../src/resolve/resolved-bus.c", 1012
, __PRETTY_FUNCTION__); } while (0)
;
1013 assert(rr->key)do { if ((__builtin_expect(!!(!(rr->key)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("rr->key"), "../src/resolve/resolved-bus.c"
, 1013, __PRETTY_FUNCTION__); } while (0)
;
1014 assert(rr->key->type == DNS_TYPE_SRV)do { if ((__builtin_expect(!!(!(rr->key->type == DNS_TYPE_SRV
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("rr->key->type == DNS_TYPE_SRV"
), "../src/resolve/resolved-bus.c", 1014, __PRETTY_FUNCTION__
); } while (0)
;
1015
1016 /* OK, we found an SRV record for the service. Let's resolve
1017 * the hostname included in it */
1018
1019 r = dns_question_new_address(&question, q->request_family, rr->srv.name, false0);
1020 if (r < 0)
1021 return r;
1022
1023 r = dns_query_new(q->manager, &aux, question, question, ifindex, q->flags|SD_RESOLVED_NO_SEARCH(1UL << 8));
1024 if (r < 0)
1025 return r;
1026
1027 aux->request_family = q->request_family;
1028 aux->complete = resolve_service_hostname_complete;
1029
1030 r = dns_query_make_auxiliary(aux, q);
1031 if (r == -EAGAIN11) {
1032 /* Too many auxiliary lookups? If so, don't complain,
1033 * let's just not add this one, we already have more
1034 * than enough */
1035
1036 dns_query_free(aux);
1037 return 0;
1038 }
1039 if (r < 0)
1040 goto fail;
1041
1042 /* Note that auxiliary queries do not track the original bus
1043 * client, only the primary request does that. */
1044
1045 r = dns_query_go(aux);
1046 if (r < 0)
1047 goto fail;
1048
1049 return 1;
1050
1051fail:
1052 dns_query_free(aux);
1053 return r;
1054}
1055
1056static void bus_method_resolve_service_complete(DnsQuery *q) {
1057 bool_Bool has_root_domain = false0;
1058 DnsResourceRecord *rr;
1059 DnsQuestion *question;
1060 unsigned found = 0;
1061 int ifindex, r;
1062
1063 assert(q)do { if ((__builtin_expect(!!(!(q)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("q"), "../src/resolve/resolved-bus.c", 1063
, __PRETTY_FUNCTION__); } while (0)
;
1064
1065 if (q->state != DNS_TRANSACTION_SUCCESS) {
1066 r = reply_query_state(q);
1067 goto finish;
1068 }
1069
1070 r = dns_query_process_cname(q);
1071 if (r == -ELOOP40) {
1072 r = sd_bus_reply_method_errorf(q->request, BUS_ERROR_CNAME_LOOP"org.freedesktop.resolve1.CNameLoop", "CNAME loop detected, or CNAME resolving disabled on '%s'", dns_query_string(q));
1073 goto finish;
1074 }
1075 if (r < 0)
1076 goto finish;
1077 if (r == DNS_QUERY_RESTARTED) /* This was a cname, and the query was restarted. */
1078 return;
1079
1080 question = dns_query_question_for_protocol(q, q->answer_protocol);
1081
1082 DNS_ANSWER_FOREACH_IFINDEX(rr, ifindex, q->answer)for (size_t __unique_prefix_i37 = ({ (rr) = ((q->answer) &&
(q->answer)->n_rrs > 0) ? (q->answer)->items[
0].rr : ((void*)0); (ifindex) = ((q->answer) && (q
->answer)->n_rrs > 0) ? (q->answer)->items[0].
ifindex : 0; 0; }); (q->answer) && (__unique_prefix_i37
< (q->answer)->n_rrs); __unique_prefix_i37++, (rr) =
((__unique_prefix_i37 < (q->answer)->n_rrs) ? (q->
answer)->items[__unique_prefix_i37].rr : ((void*)0)), (ifindex
) = ((__unique_prefix_i37 < (q->answer)->n_rrs) ? (q
->answer)->items[__unique_prefix_i37].ifindex : 0))
{
1083 r = dns_question_matches_rr(question, rr, NULL((void*)0));
1084 if (r < 0)
1085 goto finish;
1086 if (r == 0)
1087 continue;
1088
1089 if (rr->key->type != DNS_TYPE_SRV)
1090 continue;
1091
1092 if (dns_name_is_root(rr->srv.name)) {
1093 has_root_domain = true1;
1094 continue;
1095 }
1096
1097 if ((q->flags & SD_RESOLVED_NO_ADDRESS(1UL << 7)) == 0) {
1098 q->block_all_complete++;
1099 r = resolve_service_hostname(q, rr, ifindex);
1100 q->block_all_complete--;
1101
1102 if (r < 0)
1103 goto finish;
1104 }
1105
1106 found++;
1107 }
1108
1109 if (has_root_domain && found <= 0) {
1110 /* If there's exactly one SRV RR and it uses
1111 * the root domain as host name, then the
1112 * service is explicitly not offered on the
1113 * domain. Report this as a recognizable
1114 * error. See RFC 2782, Section "Usage
1115 * Rules". */
1116 r = sd_bus_reply_method_errorf(q->request, BUS_ERROR_NO_SUCH_SERVICE"org.freedesktop.resolve1.NoSuchService", "'%s' does not provide the requested service", dns_query_string(q));
1117 goto finish;
1118 }
1119
1120 if (found <= 0) {
1121 r = sd_bus_reply_method_errorf(q->request, BUS_ERROR_NO_SUCH_RR"org.freedesktop.resolve1.NoSuchRR", "'%s' does not have any RR of the requested type", dns_query_string(q));
1122 goto finish;
1123 }
1124
1125 /* Maybe we are already finished? check now... */
1126 resolve_service_all_complete(q);
1127 return;
1128
1129finish:
1130 if (r < 0) {
1131 log_error_errno(r, "Failed to send service reply: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/resolve/resolved-bus.c", 1131, __func__, "Failed to send service reply: %m"
) : -abs(_e); })
;
1132 sd_bus_reply_method_errno(q->request, r, NULL((void*)0));
1133 }
1134
1135 dns_query_free(q);
1136}
1137
1138static int bus_method_resolve_service(sd_bus_message *message, void *userdata, sd_bus_error *error) {
1139 _cleanup_(dns_question_unrefp)__attribute__((cleanup(dns_question_unrefp))) DnsQuestion *question_idna = NULL((void*)0), *question_utf8 = NULL((void*)0);
1140 const char *name, *type, *domain;
1141 Manager *m = userdata;
1142 int family, ifindex;
1143 uint64_t flags;
1144 DnsQuery *q;
1145 int r;
1146
1147 assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("message"), "../src/resolve/resolved-bus.c"
, 1147, __PRETTY_FUNCTION__); } while (0)
;
1148 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/resolve/resolved-bus.c", 1148
, __PRETTY_FUNCTION__); } while (0)
;
1149
1150 assert_cc(sizeof(int) == sizeof(int32_t))GCC diagnostic push ; GCC diagnostic ignored "-Wdeclaration-after-statement"
; struct _assert_struct_38 { char x[(sizeof(int) == sizeof(int32_t
)) ? 0 : -1]; }; GCC diagnostic pop
;
1151
1152 r = sd_bus_message_read(message, "isssit", &ifindex, &name, &type, &domain, &family, &flags);
1153 if (r < 0)
1154 return r;
1155
1156 if (!IN_SET(family, AF_INET, AF_INET6, AF_UNSPEC)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){2, 10, 0})/sizeof(int)]; switch(family) {
case 2: case 10: case 0: _found = 1; break; default: break; }
_found; })
)
1157 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Unknown address family %i", family);
1158
1159 if (isempty(name))
1160 name = NULL((void*)0);
1161 else if (!dns_service_name_is_valid(name))
1162 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid service name '%s'", name);
1163
1164 if (isempty(type))
1165 type = NULL((void*)0);
1166 else if (!dns_srv_type_is_valid(type))
1167 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid SRV service type '%s'", type);
1168
1169 r = dns_name_is_valid(domain);
1170 if (r < 0)
1171 return r;
1172 if (r == 0)
1173 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid domain '%s'", domain);
1174
1175 if (name && !type)
1176 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Service name cannot be specified without service type.");
1177
1178 r = check_ifindex_flags(ifindex, &flags, SD_RESOLVED_NO_TXT(1UL << 6)|SD_RESOLVED_NO_ADDRESS(1UL << 7), error);
1179 if (r < 0)
1180 return r;
1181
1182 r = dns_question_new_service(&question_utf8, name, type, domain, !(flags & SD_RESOLVED_NO_TXT(1UL << 6)), false0);
1183 if (r < 0)
1184 return r;
1185
1186 r = dns_question_new_service(&question_idna, name, type, domain, !(flags & SD_RESOLVED_NO_TXT(1UL << 6)), true1);
1187 if (r < 0)
1188 return r;
1189
1190 r = dns_query_new(m, &q, question_utf8, question_idna, ifindex, flags|SD_RESOLVED_NO_SEARCH(1UL << 8));
1191 if (r < 0)
1192 return r;
1193
1194 q->request = sd_bus_message_ref(message);
1195 q->request_family = family;
1196 q->complete = bus_method_resolve_service_complete;
1197
1198 r = dns_query_bus_track(q, message);
1199 if (r < 0)
1200 goto fail;
1201
1202 r = dns_query_go(q);
1203 if (r < 0)
1204 goto fail;
1205
1206 return 1;
1207
1208fail:
1209 dns_query_free(q);
1210 return r;
1211}
1212
1213int bus_dns_server_append(sd_bus_message *reply, DnsServer *s, bool_Bool with_ifindex) {
1214 int r;
1215
1216 assert(reply)do { if ((__builtin_expect(!!(!(reply)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("reply"), "../src/resolve/resolved-bus.c"
, 1216, __PRETTY_FUNCTION__); } while (0)
;
1217
1218 if (!s) {
1219 if (with_ifindex)
1220 return sd_bus_message_append(reply, "(iiay)", 0, AF_UNSPEC0, 0);
1221 else
1222 return sd_bus_message_append(reply, "(iay)", AF_UNSPEC0, 0);
1223 }
1224
1225 r = sd_bus_message_open_container(reply, 'r', with_ifindex ? "iiay" : "iay");
1226 if (r < 0)
1227 return r;
1228
1229 if (with_ifindex) {
1230 r = sd_bus_message_append(reply, "i", dns_server_ifindex(s));
1231 if (r < 0)
1232 return r;
1233 }
1234
1235 r = sd_bus_message_append(reply, "i", s->family);
1236 if (r < 0)
1237 return r;
1238
1239 r = sd_bus_message_append_array(reply, 'y', &s->address, FAMILY_ADDRESS_SIZE(s->family));
1240 if (r < 0)
1241 return r;
1242
1243 return sd_bus_message_close_container(reply);
1244}
1245
1246static int bus_property_get_dns_servers(
1247 sd_bus *bus,
1248 const char *path,
1249 const char *interface,
1250 const char *property,
1251 sd_bus_message *reply,
1252 void *userdata,
1253 sd_bus_error *error) {
1254
1255 Manager *m = userdata;
1256 DnsServer *s;
1257 Iterator i;
1258 Link *l;
1259 int r;
1260
1261 assert(reply)do { if ((__builtin_expect(!!(!(reply)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("reply"), "../src/resolve/resolved-bus.c"
, 1261, __PRETTY_FUNCTION__); } while (0)
;
1262 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/resolve/resolved-bus.c", 1262
, __PRETTY_FUNCTION__); } while (0)
;
1263
1264 r = sd_bus_message_open_container(reply, 'a', "(iiay)");
1265 if (r < 0)
1266 return r;
1267
1268 LIST_FOREACH(servers, s, m->dns_servers)for ((s) = (m->dns_servers); (s); (s) = (s)->servers_next
)
{
1269 r = bus_dns_server_append(reply, s, true1);
1270 if (r < 0)
1271 return r;
1272 }
1273
1274 HASHMAP_FOREACH(l, m->links, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), .
next_key = ((void*)0) }); hashmap_iterate((m->links), &
(i), (void**)&(l), ((void*)0)); )
{
1275 LIST_FOREACH(servers, s, l->dns_servers)for ((s) = (l->dns_servers); (s); (s) = (s)->servers_next
)
{
1276 r = bus_dns_server_append(reply, s, true1);
1277 if (r < 0)
1278 return r;
1279 }
1280 }
1281
1282 return sd_bus_message_close_container(reply);
1283}
1284
1285static int bus_property_get_fallback_dns_servers(
1286 sd_bus *bus,
1287 const char *path,
1288 const char *interface,
1289 const char *property,
1290 sd_bus_message *reply,
1291 void *userdata,
1292 sd_bus_error *error) {
1293
1294 DnsServer *s, **f = userdata;
1295 int r;
1296
1297 assert(reply)do { if ((__builtin_expect(!!(!(reply)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("reply"), "../src/resolve/resolved-bus.c"
, 1297, __PRETTY_FUNCTION__); } while (0)
;
1298 assert(f)do { if ((__builtin_expect(!!(!(f)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("f"), "../src/resolve/resolved-bus.c", 1298
, __PRETTY_FUNCTION__); } while (0)
;
1299
1300 r = sd_bus_message_open_container(reply, 'a', "(iiay)");
1301 if (r < 0)
1302 return r;
1303
1304 LIST_FOREACH(servers, s, *f)for ((s) = (*f); (s); (s) = (s)->servers_next) {
1305 r = bus_dns_server_append(reply, s, true1);
1306 if (r < 0)
1307 return r;
1308 }
1309
1310 return sd_bus_message_close_container(reply);
1311}
1312
1313static int bus_property_get_current_dns_server(
1314 sd_bus *bus,
1315 const char *path,
1316 const char *interface,
1317 const char *property,
1318 sd_bus_message *reply,
1319 void *userdata,
1320 sd_bus_error *error) {
1321
1322 DnsServer *s;
1323
1324 assert(reply)do { if ((__builtin_expect(!!(!(reply)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("reply"), "../src/resolve/resolved-bus.c"
, 1324, __PRETTY_FUNCTION__); } while (0)
;
1325 assert(userdata)do { if ((__builtin_expect(!!(!(userdata)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("userdata"), "../src/resolve/resolved-bus.c"
, 1325, __PRETTY_FUNCTION__); } while (0)
;
1326
1327 s = *(DnsServer **) userdata;
1328
1329 return bus_dns_server_append(reply, s, true1);
1330}
1331
1332static int bus_property_get_domains(
1333 sd_bus *bus,
1334 const char *path,
1335 const char *interface,
1336 const char *property,
1337 sd_bus_message *reply,
1338 void *userdata,
1339 sd_bus_error *error) {
1340
1341 Manager *m = userdata;
1342 DnsSearchDomain *d;
1343 Iterator i;
1344 Link *l;
1345 int r;
1346
1347 assert(reply)do { if ((__builtin_expect(!!(!(reply)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("reply"), "../src/resolve/resolved-bus.c"
, 1347, __PRETTY_FUNCTION__); } while (0)
;
1348 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/resolve/resolved-bus.c", 1348
, __PRETTY_FUNCTION__); } while (0)
;
1349
1350 r = sd_bus_message_open_container(reply, 'a', "(isb)");
1351 if (r < 0)
1352 return r;
1353
1354 LIST_FOREACH(domains, d, m->search_domains)for ((d) = (m->search_domains); (d); (d) = (d)->domains_next
)
{
1355 r = sd_bus_message_append(reply, "(isb)", 0, d->name, d->route_only);
1356 if (r < 0)
1357 return r;
1358 }
1359
1360 HASHMAP_FOREACH(l, m->links, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), .
next_key = ((void*)0) }); hashmap_iterate((m->links), &
(i), (void**)&(l), ((void*)0)); )
{
1361 LIST_FOREACH(domains, d, l->search_domains)for ((d) = (l->search_domains); (d); (d) = (d)->domains_next
)
{
1362 r = sd_bus_message_append(reply, "(isb)", l->ifindex, d->name, d->route_only);
1363 if (r < 0)
1364 return r;
1365 }
1366 }
1367
1368 return sd_bus_message_close_container(reply);
1369}
1370
1371static int bus_property_get_transaction_statistics(
1372 sd_bus *bus,
1373 const char *path,
1374 const char *interface,
1375 const char *property,
1376 sd_bus_message *reply,
1377 void *userdata,
1378 sd_bus_error *error) {
1379
1380 Manager *m = userdata;
1381
1382 assert(reply)do { if ((__builtin_expect(!!(!(reply)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("reply"), "../src/resolve/resolved-bus.c"
, 1382, __PRETTY_FUNCTION__); } while (0)
;
1383 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/resolve/resolved-bus.c", 1383
, __PRETTY_FUNCTION__); } while (0)
;
1384
1385 return sd_bus_message_append(reply, "(tt)",
1386 (uint64_t) hashmap_size(m->dns_transactions),
1387 (uint64_t) m->n_transactions_total);
1388}
1389
1390static int bus_property_get_cache_statistics(
1391 sd_bus *bus,
1392 const char *path,
1393 const char *interface,
1394 const char *property,
1395 sd_bus_message *reply,
1396 void *userdata,
1397 sd_bus_error *error) {
1398
1399 uint64_t size = 0, hit = 0, miss = 0;
1400 Manager *m = userdata;
1401 DnsScope *s;
1402
1403 assert(reply)do { if ((__builtin_expect(!!(!(reply)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("reply"), "../src/resolve/resolved-bus.c"
, 1403, __PRETTY_FUNCTION__); } while (0)
;
1404 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/resolve/resolved-bus.c", 1404
, __PRETTY_FUNCTION__); } while (0)
;
1405
1406 LIST_FOREACH(scopes, s, m->dns_scopes)for ((s) = (m->dns_scopes); (s); (s) = (s)->scopes_next
)
{
1407 size += dns_cache_size(&s->cache);
1408 hit += s->cache.n_hit;
1409 miss += s->cache.n_miss;
1410 }
1411
1412 return sd_bus_message_append(reply, "(ttt)", size, hit, miss);
1413}
1414
1415static int bus_property_get_dnssec_statistics(
1416 sd_bus *bus,
1417 const char *path,
1418 const char *interface,
1419 const char *property,
1420 sd_bus_message *reply,
1421 void *userdata,
1422 sd_bus_error *error) {
1423
1424 Manager *m = userdata;
1425
1426 assert(reply)do { if ((__builtin_expect(!!(!(reply)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("reply"), "../src/resolve/resolved-bus.c"
, 1426, __PRETTY_FUNCTION__); } while (0)
;
1427 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/resolve/resolved-bus.c", 1427
, __PRETTY_FUNCTION__); } while (0)
;
1428
1429 return sd_bus_message_append(reply, "(tttt)",
1430 (uint64_t) m->n_dnssec_verdict[DNSSEC_SECURE],
1431 (uint64_t) m->n_dnssec_verdict[DNSSEC_INSECURE],
1432 (uint64_t) m->n_dnssec_verdict[DNSSEC_BOGUS],
1433 (uint64_t) m->n_dnssec_verdict[DNSSEC_INDETERMINATE]);
1434}
1435
1436static int bus_property_get_ntas(
1437 sd_bus *bus,
1438 const char *path,
1439 const char *interface,
1440 const char *property,
1441 sd_bus_message *reply,
1442 void *userdata,
1443 sd_bus_error *error) {
1444
1445 Manager *m = userdata;
1446 const char *domain;
1447 Iterator i;
1448 int r;
1449
1450 assert(reply)do { if ((__builtin_expect(!!(!(reply)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("reply"), "../src/resolve/resolved-bus.c"
, 1450, __PRETTY_FUNCTION__); } while (0)
;
1451 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/resolve/resolved-bus.c", 1451
, __PRETTY_FUNCTION__); } while (0)
;
1452
1453 r = sd_bus_message_open_container(reply, 'a', "s");
1454 if (r < 0)
1455 return r;
1456
1457 SET_FOREACH(domain, m->trust_anchor.negative_by_name, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), .
next_key = ((void*)0) }); set_iterate((m->trust_anchor.negative_by_name
), &(i), (void**)&(domain)); )
{
1458 r = sd_bus_message_append(reply, "s", domain);
1459 if (r < 0)
1460 return r;
1461 }
1462
1463 return sd_bus_message_close_container(reply);
1464}
1465
1466static BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_dns_stub_listener_mode, dns_stub_listener_mode, DnsStubListenerMode)int bus_property_get_dns_stub_listener_mode(sd_bus *bus, const
char *path, const char *interface, const char *property, sd_bus_message
*reply, void *userdata, sd_bus_error *error) { DnsStubListenerMode
*data = userdata; do { if ((__builtin_expect(!!(!(bus)),0)))
log_assert_failed_realm(LOG_REALM_SYSTEMD, ("bus"), "../src/resolve/resolved-bus.c"
, 1466, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect
(!!(!(reply)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD,
("reply"), "../src/resolve/resolved-bus.c", 1466, __PRETTY_FUNCTION__
); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("data"), "../src/resolve/resolved-bus.c"
, 1466, __PRETTY_FUNCTION__); } while (0); return sd_bus_message_append
(reply, "s", dns_stub_listener_mode_to_string((*(data)))); }
;
1467static BUS_DEFINE_PROPERTY_GET(bus_property_get_dnssec_supported, "b", Manager, manager_dnssec_supported)int bus_property_get_dnssec_supported(sd_bus *bus, const char
*path, const char *interface, const char *property, sd_bus_message
*reply, void *userdata, sd_bus_error *error) { Manager *data
= userdata; do { if ((__builtin_expect(!!(!(bus)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("bus"), "../src/resolve/resolved-bus.c",
1467, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect
(!!(!(reply)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD,
("reply"), "../src/resolve/resolved-bus.c", 1467, __PRETTY_FUNCTION__
); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("data"), "../src/resolve/resolved-bus.c"
, 1467, __PRETTY_FUNCTION__); } while (0); return sd_bus_message_append
(reply, "b", (manager_dnssec_supported(data))); }
;
1468static BUS_DEFINE_PROPERTY_GET2(bus_property_get_dnssec_mode, "s", Manager, manager_get_dnssec_mode, dnssec_mode_to_string)int bus_property_get_dnssec_mode(sd_bus *bus, const char *path
, const char *interface, const char *property, sd_bus_message
*reply, void *userdata, sd_bus_error *error) { Manager *data
= userdata; do { if ((__builtin_expect(!!(!(bus)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("bus"), "../src/resolve/resolved-bus.c",
1468, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect
(!!(!(reply)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD,
("reply"), "../src/resolve/resolved-bus.c", 1468, __PRETTY_FUNCTION__
); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("data"), "../src/resolve/resolved-bus.c"
, 1468, __PRETTY_FUNCTION__); } while (0); return sd_bus_message_append
(reply, "s", dnssec_mode_to_string(manager_get_dnssec_mode(data
))); }
;
1469static BUS_DEFINE_PROPERTY_GET2(bus_property_get_dns_over_tls_mode, "s", Manager, manager_get_dns_over_tls_mode, dns_over_tls_mode_to_string)int bus_property_get_dns_over_tls_mode(sd_bus *bus, const char
*path, const char *interface, const char *property, sd_bus_message
*reply, void *userdata, sd_bus_error *error) { Manager *data
= userdata; do { if ((__builtin_expect(!!(!(bus)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("bus"), "../src/resolve/resolved-bus.c",
1469, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect
(!!(!(reply)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD,
("reply"), "../src/resolve/resolved-bus.c", 1469, __PRETTY_FUNCTION__
); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("data"), "../src/resolve/resolved-bus.c"
, 1469, __PRETTY_FUNCTION__); } while (0); return sd_bus_message_append
(reply, "s", dns_over_tls_mode_to_string(manager_get_dns_over_tls_mode
(data))); }
;
1470
1471static int bus_method_reset_statistics(sd_bus_message *message, void *userdata, sd_bus_error *error) {
1472 Manager *m = userdata;
1473 DnsScope *s;
1474
1475 assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("message"), "../src/resolve/resolved-bus.c"
, 1475, __PRETTY_FUNCTION__); } while (0)
;
1476 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/resolve/resolved-bus.c", 1476
, __PRETTY_FUNCTION__); } while (0)
;
1477
1478 LIST_FOREACH(scopes, s, m->dns_scopes)for ((s) = (m->dns_scopes); (s); (s) = (s)->scopes_next
)
1479 s->cache.n_hit = s->cache.n_miss = 0;
1480
1481 m->n_transactions_total = 0;
1482 zero(m->n_dnssec_verdict)(({ size_t _l_ = (sizeof(m->n_dnssec_verdict)); void *_x_ =
(&(m->n_dnssec_verdict)); _l_ == 0 ? _x_ : memset(_x_
, 0, _l_); }))
;
1483
1484 return sd_bus_reply_method_return(message, NULL((void*)0));
1485}
1486
1487static int get_any_link(Manager *m, int ifindex, Link **ret, sd_bus_error *error) {
1488 Link *l;
1489
1490 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/resolve/resolved-bus.c", 1490
, __PRETTY_FUNCTION__); } while (0)
;
14
Taking false branch
15
Loop condition is false. Exiting loop
1491 assert(ret)do { if ((__builtin_expect(!!(!(ret)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("ret"), "../src/resolve/resolved-bus.c",
1491, __PRETTY_FUNCTION__); } while (0)
;
16
Taking false branch
17
Loop condition is false. Exiting loop
1492
1493 if (ifindex <= 0)
18
Assuming 'ifindex' is <= 0
19
Taking true branch
1494 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid interface index");
20
Returning without writing to '*ret'
1495
1496 l = hashmap_get(m->links, INT_TO_PTR(ifindex)((void *) ((intptr_t) (ifindex))));
1497 if (!l)
1498 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_LINK"org.freedesktop.resolve1.NoSuchLink", "Link %i not known", ifindex);
1499
1500 *ret = l;
1501 return 0;
1502}
1503
1504static int call_link_method(Manager *m, sd_bus_message *message, sd_bus_message_handler_t handler, sd_bus_error *error) {
1505 int ifindex, r;
1506 Link *l;
2
'l' declared without an initial value
1507
1508 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/resolve/resolved-bus.c", 1508
, __PRETTY_FUNCTION__); } while (0)
;
3
Assuming 'm' is non-null
4
Taking false branch
5
Loop condition is false. Exiting loop
1509 assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("message"), "../src/resolve/resolved-bus.c"
, 1509, __PRETTY_FUNCTION__); } while (0)
;
6
Assuming 'message' is non-null
7
Taking false branch
8
Loop condition is false. Exiting loop
1510 assert(handler)do { if ((__builtin_expect(!!(!(handler)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("handler"), "../src/resolve/resolved-bus.c"
, 1510, __PRETTY_FUNCTION__); } while (0)
;
9
Taking false branch
10
Loop condition is false. Exiting loop
1511
1512 assert_cc(sizeof(int) == sizeof(int32_t))GCC diagnostic push ; GCC diagnostic ignored "-Wdeclaration-after-statement"
; struct _assert_struct_39 { char x[(sizeof(int) == sizeof(int32_t
)) ? 0 : -1]; }; GCC diagnostic pop
;
1513 r = sd_bus_message_read(message, "i", &ifindex);
1514 if (r < 0)
11
Assuming 'r' is >= 0
12
Taking false branch
1515 return r;
1516
1517 r = get_any_link(m, ifindex, &l, error);
13
Calling 'get_any_link'
21
Returning from 'get_any_link'
1518 if (r < 0)
22
Assuming 'r' is >= 0
23
Taking false branch
1519 return r;
1520
1521 return handler(message, l, error);
24
2nd function call argument is an uninitialized value
1522}
1523
1524static int bus_method_set_link_dns_servers(sd_bus_message *message, void *userdata, sd_bus_error *error) {
1525 return call_link_method(userdata, message, bus_link_method_set_dns_servers, error);
1526}
1527
1528static int bus_method_set_link_domains(sd_bus_message *message, void *userdata, sd_bus_error *error) {
1529 return call_link_method(userdata, message, bus_link_method_set_domains, error);
1530}
1531
1532static int bus_method_set_link_llmnr(sd_bus_message *message, void *userdata, sd_bus_error *error) {
1533 return call_link_method(userdata, message, bus_link_method_set_llmnr, error);
1534}
1535
1536static int bus_method_set_link_mdns(sd_bus_message *message, void *userdata, sd_bus_error *error) {
1537 return call_link_method(userdata, message, bus_link_method_set_mdns, error);
1538}
1539
1540static int bus_method_set_link_dns_over_tls(sd_bus_message *message, void *userdata, sd_bus_error *error) {
1541 return call_link_method(userdata, message, bus_link_method_set_dns_over_tls, error);
1542}
1543
1544static int bus_method_set_link_dnssec(sd_bus_message *message, void *userdata, sd_bus_error *error) {
1545 return call_link_method(userdata, message, bus_link_method_set_dnssec, error);
1546}
1547
1548static int bus_method_set_link_dnssec_negative_trust_anchors(sd_bus_message *message, void *userdata, sd_bus_error *error) {
1549 return call_link_method(userdata, message, bus_link_method_set_dnssec_negative_trust_anchors, error);
1550}
1551
1552static int bus_method_revert_link(sd_bus_message *message, void *userdata, sd_bus_error *error) {
1553 return call_link_method(userdata, message, bus_link_method_revert, error);
1
Calling 'call_link_method'
1554}
1555
1556static int bus_method_get_link(sd_bus_message *message, void *userdata, sd_bus_error *error) {
1557 _cleanup_free___attribute__((cleanup(freep))) char *p = NULL((void*)0);
1558 Manager *m = userdata;
1559 int r, ifindex;
1560 Link *l;
1561
1562 assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("message"), "../src/resolve/resolved-bus.c"
, 1562, __PRETTY_FUNCTION__); } while (0)
;
1563 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/resolve/resolved-bus.c", 1563
, __PRETTY_FUNCTION__); } while (0)
;
1564
1565 assert_cc(sizeof(int) == sizeof(int32_t))GCC diagnostic push ; GCC diagnostic ignored "-Wdeclaration-after-statement"
; struct _assert_struct_40 { char x[(sizeof(int) == sizeof(int32_t
)) ? 0 : -1]; }; GCC diagnostic pop
;
1566 r = sd_bus_message_read(message, "i", &ifindex);
1567 if (r < 0)
1568 return r;
1569
1570 r = get_any_link(m, ifindex, &l, error);
1571 if (r < 0)
1572 return r;
1573
1574 p = link_bus_path(l);
1575 if (!p)
1576 return -ENOMEM12;
1577
1578 return sd_bus_reply_method_return(message, "o", p);
1579}
1580
1581static int bus_method_flush_caches(sd_bus_message *message, void *userdata, sd_bus_error *error) {
1582 Manager *m = userdata;
1583
1584 assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("message"), "../src/resolve/resolved-bus.c"
, 1584, __PRETTY_FUNCTION__); } while (0)
;
1585 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/resolve/resolved-bus.c", 1585
, __PRETTY_FUNCTION__); } while (0)
;
1586
1587 manager_flush_caches(m);
1588
1589 return sd_bus_reply_method_return(message, NULL((void*)0));
1590}
1591
1592static int bus_method_reset_server_features(sd_bus_message *message, void *userdata, sd_bus_error *error) {
1593 Manager *m = userdata;
1594
1595 assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("message"), "../src/resolve/resolved-bus.c"
, 1595, __PRETTY_FUNCTION__); } while (0)
;
1596 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/resolve/resolved-bus.c", 1596
, __PRETTY_FUNCTION__); } while (0)
;
1597
1598 manager_reset_server_features(m);
1599
1600 return sd_bus_reply_method_return(message, NULL((void*)0));
1601}
1602
1603static int on_bus_track(sd_bus_track *t, void *userdata) {
1604 DnssdService *s = userdata;
1605
1606 assert(t)do { if ((__builtin_expect(!!(!(t)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("t"), "../src/resolve/resolved-bus.c", 1606
, __PRETTY_FUNCTION__); } while (0)
;
1607 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/resolve/resolved-bus.c", 1607
, __PRETTY_FUNCTION__); } while (0)
;
1608
1609 log_debug("Client of active request vanished, destroying DNS-SD service.")({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/resolve/resolved-bus.c", 1609, __func__, "Client of active request vanished, destroying DNS-SD service."
) : -abs(_e); })
;
1610 dnssd_service_free(s);
1611
1612 return 0;
1613}
1614
1615static int bus_method_register_service(sd_bus_message *message, void *userdata, sd_bus_error *error) {
1616 _cleanup_(sd_bus_creds_unrefp)__attribute__((cleanup(sd_bus_creds_unrefp))) sd_bus_creds *creds = NULL((void*)0);
1617 _cleanup_(dnssd_service_freep)__attribute__((cleanup(dnssd_service_freep))) DnssdService *service = NULL((void*)0);
1618 _cleanup_(sd_bus_track_unrefp)__attribute__((cleanup(sd_bus_track_unrefp))) sd_bus_track *bus_track = NULL((void*)0);
1619 _cleanup_free___attribute__((cleanup(freep))) char *path = NULL((void*)0);
1620 _cleanup_free___attribute__((cleanup(freep))) char *instance_name = NULL((void*)0);
1621 Manager *m = userdata;
1622 DnssdService *s = NULL((void*)0);
1623 const char *name;
1624 const char *name_template;
1625 const char *type;
1626 uid_t euid;
1627 int r;
1628
1629 assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("message"), "../src/resolve/resolved-bus.c"
, 1629, __PRETTY_FUNCTION__); } while (0)
;
1630 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/resolve/resolved-bus.c", 1630
, __PRETTY_FUNCTION__); } while (0)
;
1631
1632 if (m->mdns_support != RESOLVE_SUPPORT_YES)
1633 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED"org.freedesktop.DBus.Error.NotSupported", "Support for MulticastDNS is disabled");
1634
1635 service = new0(DnssdService, 1)((DnssdService*) calloc((1), sizeof(DnssdService)));
1636 if (!service)
1637 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/resolve/resolved-bus.c"
, 1637, __func__)
;
1638
1639 r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_EUID, &creds);
1640 if (r < 0)
1641 return r;
1642
1643 r = sd_bus_creds_get_euid(creds, &euid);
1644 if (r < 0)
1645 return r;
1646 service->originator = euid;
1647
1648 r = sd_bus_message_read(message, "sssqqq", &name, &name_template, &type,
1649 &service->port, &service->priority,
1650 &service->weight);
1651 if (r < 0)
1652 return r;
1653
1654 s = hashmap_get(m->dnssd_services, name);
1655 if (s)
1656 return sd_bus_error_setf(error, BUS_ERROR_DNSSD_SERVICE_EXISTS"org.freedesktop.resolve1.DnssdServiceExists", "DNS-SD service '%s' exists already", name);
1657
1658 if (!dnssd_srv_type_is_valid(type))
1659 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "DNS-SD service type '%s' is invalid", type);
1660
1661 service->name = strdup(name);
1662 if (!service->name)
1663 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/resolve/resolved-bus.c"
, 1663, __func__)
;
1664
1665 service->name_template = strdup(name_template);
1666 if (!service->name_template)
1667 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/resolve/resolved-bus.c"
, 1667, __func__)
;
1668
1669 service->type = strdup(type);
1670 if (!service->type)
1671 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/resolve/resolved-bus.c"
, 1671, __func__)
;
1672
1673 r = dnssd_render_instance_name(service, &instance_name);
1674 if (r < 0)
1675 return r;
1676
1677 r = sd_bus_message_enter_container(message, SD_BUS_TYPE_ARRAY, "a{say}");
1678 if (r < 0)
1679 return r;
1680
1681 while ((r = sd_bus_message_enter_container(message, SD_BUS_TYPE_ARRAY, "{say}")) > 0) {
1682 _cleanup_(dnssd_txtdata_freep)__attribute__((cleanup(dnssd_txtdata_freep))) DnssdTxtData *txt_data = NULL((void*)0);
1683 DnsTxtItem *last = NULL((void*)0);
1684
1685 txt_data = new0(DnssdTxtData, 1)((DnssdTxtData*) calloc((1), sizeof(DnssdTxtData)));
1686 if (!txt_data)
1687 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/resolve/resolved-bus.c"
, 1687, __func__)
;
1688
1689 while ((r = sd_bus_message_enter_container(message, SD_BUS_TYPE_DICT_ENTRY, "say")) > 0) {
1690 const char *key;
1691 const void *value;
1692 size_t size;
1693 DnsTxtItem *i;
1694
1695 r = sd_bus_message_read(message, "s", &key);
1696 if (r < 0)
1697 return r;
1698
1699 if (isempty(key))
1700 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Keys in DNS-SD TXT RRs can't be empty");
1701
1702 if (!ascii_is_valid(key))
1703 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "TXT key '%s' contains non-ASCII symbols", key);
1704
1705 r = sd_bus_message_read_array(message, 'y', &value, &size);
1706 if (r < 0)
1707 return r;
1708
1709 r = dnssd_txt_item_new_from_data(key, value, size, &i);
1710 if (r < 0)
1711 return r;
1712
1713 LIST_INSERT_AFTER(items, txt_data->txt, last, i)do { typeof(*(txt_data->txt)) **_head = &(txt_data->
txt), *_a = (last), *_b = (i); do { if ((__builtin_expect(!!(
!(_b)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("_b")
, "../src/resolve/resolved-bus.c", 1713, __PRETTY_FUNCTION__)
; } while (0); if (!_a) { if ((_b->items_next = *_head)) _b
->items_next->items_prev = _b; _b->items_prev = ((void
*)0); *_head = _b; } else { if ((_b->items_next = _a->items_next
)) _b->items_next->items_prev = _b; _b->items_prev =
_a; _a->items_next = _b; } } while (0)
;
1714 last = i;
1715
1716 r = sd_bus_message_exit_container(message);
1717 if (r < 0)
1718 return r;
1719
1720 }
1721 if (r < 0)
1722 return r;
1723
1724 r = sd_bus_message_exit_container(message);
1725 if (r < 0)
1726 return r;
1727
1728 if (txt_data->txt) {
1729 LIST_PREPEND(items, service->txt_data_items, txt_data)do { typeof(*(service->txt_data_items)) **_head = &(service
->txt_data_items), *_item = (txt_data); do { if ((__builtin_expect
(!!(!(_item)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD,
("_item"), "../src/resolve/resolved-bus.c", 1729, __PRETTY_FUNCTION__
); } while (0); if ((_item->items_next = *_head)) _item->
items_next->items_prev = _item; _item->items_prev = ((void
*)0); *_head = _item; } while (0)
;
1730 txt_data = NULL((void*)0);
1731 }
1732 }
1733 if (r < 0)
1734 return r;
1735
1736 r = sd_bus_message_exit_container(message);
1737 if (r < 0)
1738 return r;
1739
1740 if (!service->txt_data_items) {
1741 _cleanup_(dnssd_txtdata_freep)__attribute__((cleanup(dnssd_txtdata_freep))) DnssdTxtData *txt_data = NULL((void*)0);
1742
1743 txt_data = new0(DnssdTxtData, 1)((DnssdTxtData*) calloc((1), sizeof(DnssdTxtData)));
1744 if (!txt_data)
1745 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/resolve/resolved-bus.c"
, 1745, __func__)
;
1746
1747 r = dns_txt_item_new_empty(&txt_data->txt);
1748 if (r < 0)
1749 return r;
1750
1751 LIST_PREPEND(items, service->txt_data_items, txt_data)do { typeof(*(service->txt_data_items)) **_head = &(service
->txt_data_items), *_item = (txt_data); do { if ((__builtin_expect
(!!(!(_item)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD,
("_item"), "../src/resolve/resolved-bus.c", 1751, __PRETTY_FUNCTION__
); } while (0); if ((_item->items_next = *_head)) _item->
items_next->items_prev = _item; _item->items_prev = ((void
*)0); *_head = _item; } while (0)
;
1752 txt_data = NULL((void*)0);
1753 }
1754
1755 r = sd_bus_path_encode("/org/freedesktop/resolve1/dnssd", service->name, &path);
1756 if (r < 0)
1757 return r;
1758
1759 r = bus_verify_polkit_async(message, CAP_SYS_ADMIN21,
1760 "org.freedesktop.resolve1.register-service",
1761 NULL((void*)0), false0, UID_INVALID((uid_t) -1),
1762 &m->polkit_registry, error);
1763 if (r < 0)
1764 return r;
1765 if (r == 0)
1766 return 1; /* Polkit will call us back */
1767
1768 r = hashmap_ensure_allocated(&m->dnssd_services, &string_hash_ops)internal_hashmap_ensure_allocated(&m->dnssd_services, &
string_hash_ops )
;
1769 if (r < 0)
1770 return r;
1771
1772 r = hashmap_put(m->dnssd_services, service->name, service);
1773 if (r < 0)
1774 return r;
1775
1776 r = sd_bus_track_new(sd_bus_message_get_bus(message), &bus_track, on_bus_track, service);
1777 if (r < 0)
1778 return r;
1779
1780 r = sd_bus_track_add_sender(bus_track, message);
1781 if (r < 0)
1782 return r;
1783
1784 service->manager = m;
1785
1786 service = NULL((void*)0);
1787
1788 manager_refresh_rrs(m);
1789
1790 return sd_bus_reply_method_return(message, "o", path);
1791}
1792
1793static int call_dnssd_method(Manager *m, sd_bus_message *message, sd_bus_message_handler_t handler, sd_bus_error *error) {
1794 _cleanup_free___attribute__((cleanup(freep))) char *name = NULL((void*)0);
1795 DnssdService *s = NULL((void*)0);
1796 const char *path;
1797 int r;
1798
1799 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/resolve/resolved-bus.c", 1799
, __PRETTY_FUNCTION__); } while (0)
;
1800 assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("message"), "../src/resolve/resolved-bus.c"
, 1800, __PRETTY_FUNCTION__); } while (0)
;
1801 assert(handler)do { if ((__builtin_expect(!!(!(handler)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("handler"), "../src/resolve/resolved-bus.c"
, 1801, __PRETTY_FUNCTION__); } while (0)
;
1802
1803 r = sd_bus_message_read(message, "o", &path);
1804 if (r < 0)
1805 return r;
1806
1807 r = sd_bus_path_decode(path, "/org/freedesktop/resolve1/dnssd", &name);
1808 if (r == 0)
1809 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_DNSSD_SERVICE"org.freedesktop.resolve1.NoSuchDnssdService", "DNS-SD service with object path '%s' does not exist", path);
1810 if (r < 0)
1811 return r;
1812
1813 s = hashmap_get(m->dnssd_services, name);
1814 if (!s)
1815 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_DNSSD_SERVICE"org.freedesktop.resolve1.NoSuchDnssdService", "DNS-SD service '%s' not known", name);
1816
1817 return handler(message, s, error);
1818}
1819
1820static int bus_method_unregister_service(sd_bus_message *message, void *userdata, sd_bus_error *error) {
1821 Manager *m = userdata;
1822
1823 assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("message"), "../src/resolve/resolved-bus.c"
, 1823, __PRETTY_FUNCTION__); } while (0)
;
1824 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/resolve/resolved-bus.c", 1824
, __PRETTY_FUNCTION__); } while (0)
;
1825
1826 return call_dnssd_method(m, message, bus_dnssd_method_unregister, error);
1827}
1828
1829static const sd_bus_vtable resolve_vtable[] = {
1830 SD_BUS_VTABLE_START(0){ .type = _SD_BUS_VTABLE_START, .flags = 0, .x = { .start = {
.element_size = sizeof(sd_bus_vtable) }, }, }
,
1831 SD_BUS_PROPERTY("LLMNRHostname", "s", NULL, offsetof(Manager, llmnr_hostname), 0){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = 0, .x = { .property
= { .member = "LLMNRHostname", .signature = "s", .get = ((void
*)0), .set = ((void*)0), .offset = __builtin_offsetof(Manager
, llmnr_hostname), }, }, }
,
1832 SD_BUS_PROPERTY("LLMNR", "s", bus_property_get_resolve_support, offsetof(Manager, llmnr_support), 0){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = 0, .x = { .property
= { .member = "LLMNR", .signature = "s", .get = bus_property_get_resolve_support
, .set = ((void*)0), .offset = __builtin_offsetof(Manager, llmnr_support
), }, }, }
,
1833 SD_BUS_PROPERTY("MulticastDNS", "s", bus_property_get_resolve_support, offsetof(Manager, mdns_support), 0){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = 0, .x = { .property
= { .member = "MulticastDNS", .signature = "s", .get = bus_property_get_resolve_support
, .set = ((void*)0), .offset = __builtin_offsetof(Manager, mdns_support
), }, }, }
,
1834 SD_BUS_PROPERTY("DNSOverTLS", "s", bus_property_get_dns_over_tls_mode, 0, 0){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = 0, .x = { .property
= { .member = "DNSOverTLS", .signature = "s", .get = bus_property_get_dns_over_tls_mode
, .set = ((void*)0), .offset = 0, }, }, }
,
1835 SD_BUS_PROPERTY("DNS", "a(iiay)", bus_property_get_dns_servers, 0, 0){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = 0, .x = { .property
= { .member = "DNS", .signature = "a(iiay)", .get = bus_property_get_dns_servers
, .set = ((void*)0), .offset = 0, }, }, }
,
1836 SD_BUS_PROPERTY("FallbackDNS", "a(iiay)", bus_property_get_fallback_dns_servers, offsetof(Manager, fallback_dns_servers), SD_BUS_VTABLE_PROPERTY_CONST){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_CONST
, .x = { .property = { .member = "FallbackDNS", .signature = "a(iiay)"
, .get = bus_property_get_fallback_dns_servers, .set = ((void
*)0), .offset = __builtin_offsetof(Manager, fallback_dns_servers
), }, }, }
,
1837 SD_BUS_PROPERTY("CurrentDNSServer", "(iiay)", bus_property_get_current_dns_server, offsetof(Manager, current_dns_server), 0){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = 0, .x = { .property
= { .member = "CurrentDNSServer", .signature = "(iiay)", .get
= bus_property_get_current_dns_server, .set = ((void*)0), .offset
= __builtin_offsetof(Manager, current_dns_server), }, }, }
,
1838 SD_BUS_PROPERTY("Domains", "a(isb)", bus_property_get_domains, 0, 0){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = 0, .x = { .property
= { .member = "Domains", .signature = "a(isb)", .get = bus_property_get_domains
, .set = ((void*)0), .offset = 0, }, }, }
,
1839 SD_BUS_PROPERTY("TransactionStatistics", "(tt)", bus_property_get_transaction_statistics, 0, 0){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = 0, .x = { .property
= { .member = "TransactionStatistics", .signature = "(tt)", .
get = bus_property_get_transaction_statistics, .set = ((void*
)0), .offset = 0, }, }, }
,
1840 SD_BUS_PROPERTY("CacheStatistics", "(ttt)", bus_property_get_cache_statistics, 0, 0){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = 0, .x = { .property
= { .member = "CacheStatistics", .signature = "(ttt)", .get =
bus_property_get_cache_statistics, .set = ((void*)0), .offset
= 0, }, }, }
,
1841 SD_BUS_PROPERTY("DNSSEC", "s", bus_property_get_dnssec_mode, 0, 0){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = 0, .x = { .property
= { .member = "DNSSEC", .signature = "s", .get = bus_property_get_dnssec_mode
, .set = ((void*)0), .offset = 0, }, }, }
,
1842 SD_BUS_PROPERTY("DNSSECStatistics", "(tttt)", bus_property_get_dnssec_statistics, 0, 0){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = 0, .x = { .property
= { .member = "DNSSECStatistics", .signature = "(tttt)", .get
= bus_property_get_dnssec_statistics, .set = ((void*)0), .offset
= 0, }, }, }
,
1843 SD_BUS_PROPERTY("DNSSECSupported", "b", bus_property_get_dnssec_supported, 0, 0){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = 0, .x = { .property
= { .member = "DNSSECSupported", .signature = "b", .get = bus_property_get_dnssec_supported
, .set = ((void*)0), .offset = 0, }, }, }
,
1844 SD_BUS_PROPERTY("DNSSECNegativeTrustAnchors", "as", bus_property_get_ntas, 0, 0){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = 0, .x = { .property
= { .member = "DNSSECNegativeTrustAnchors", .signature = "as"
, .get = bus_property_get_ntas, .set = ((void*)0), .offset = 0
, }, }, }
,
1845 SD_BUS_PROPERTY("DNSStubListener", "s", bus_property_get_dns_stub_listener_mode, offsetof(Manager, dns_stub_listener_mode), 0){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = 0, .x = { .property
= { .member = "DNSStubListener", .signature = "s", .get = bus_property_get_dns_stub_listener_mode
, .set = ((void*)0), .offset = __builtin_offsetof(Manager, dns_stub_listener_mode
), }, }, }
,
1846
1847 SD_BUS_METHOD("ResolveHostname", "isit", "a(iiay)st", bus_method_resolve_hostname, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "ResolveHostname", .signature =
"isit", .result = "a(iiay)st", .handler = bus_method_resolve_hostname
, .offset = 0, }, }, }
,
1848 SD_BUS_METHOD("ResolveAddress", "iiayt", "a(is)t", bus_method_resolve_address, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "ResolveAddress", .signature =
"iiayt", .result = "a(is)t", .handler = bus_method_resolve_address
, .offset = 0, }, }, }
,
1849 SD_BUS_METHOD("ResolveRecord", "isqqt", "a(iqqay)t", bus_method_resolve_record, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "ResolveRecord", .signature = "isqqt"
, .result = "a(iqqay)t", .handler = bus_method_resolve_record
, .offset = 0, }, }, }
,
1850 SD_BUS_METHOD("ResolveService", "isssit", "a(qqqsa(iiay)s)aayssst", bus_method_resolve_service, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "ResolveService", .signature =
"isssit", .result = "a(qqqsa(iiay)s)aayssst", .handler = bus_method_resolve_service
, .offset = 0, }, }, }
,
1851 SD_BUS_METHOD("ResetStatistics", NULL, NULL, bus_method_reset_statistics, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "ResetStatistics", .signature =
((void*)0), .result = ((void*)0), .handler = bus_method_reset_statistics
, .offset = 0, }, }, }
,
1852 SD_BUS_METHOD("FlushCaches", NULL, NULL, bus_method_flush_caches, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "FlushCaches", .signature = ((
void*)0), .result = ((void*)0), .handler = bus_method_flush_caches
, .offset = 0, }, }, }
,
1853 SD_BUS_METHOD("ResetServerFeatures", NULL, NULL, bus_method_reset_server_features, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "ResetServerFeatures", .signature
= ((void*)0), .result = ((void*)0), .handler = bus_method_reset_server_features
, .offset = 0, }, }, }
,
1854 SD_BUS_METHOD("GetLink", "i", "o", bus_method_get_link, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "GetLink", .signature = "i", .
result = "o", .handler = bus_method_get_link, .offset = 0, },
}, }
,
1855 SD_BUS_METHOD("SetLinkDNS", "ia(iay)", NULL, bus_method_set_link_dns_servers, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "SetLinkDNS", .signature = "ia(iay)"
, .result = ((void*)0), .handler = bus_method_set_link_dns_servers
, .offset = 0, }, }, }
,
1856 SD_BUS_METHOD("SetLinkDomains", "ia(sb)", NULL, bus_method_set_link_domains, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "SetLinkDomains", .signature =
"ia(sb)", .result = ((void*)0), .handler = bus_method_set_link_domains
, .offset = 0, }, }, }
,
1857 SD_BUS_METHOD("SetLinkLLMNR", "is", NULL, bus_method_set_link_llmnr, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "SetLinkLLMNR", .signature = "is"
, .result = ((void*)0), .handler = bus_method_set_link_llmnr,
.offset = 0, }, }, }
,
1858 SD_BUS_METHOD("SetLinkMulticastDNS", "is", NULL, bus_method_set_link_mdns, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "SetLinkMulticastDNS", .signature
= "is", .result = ((void*)0), .handler = bus_method_set_link_mdns
, .offset = 0, }, }, }
,
1859 SD_BUS_METHOD("SetLinkDNSOverTLS", "is", NULL, bus_method_set_link_dns_over_tls, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "SetLinkDNSOverTLS", .signature
= "is", .result = ((void*)0), .handler = bus_method_set_link_dns_over_tls
, .offset = 0, }, }, }
,
1860 SD_BUS_METHOD("SetLinkDNSSEC", "is", NULL, bus_method_set_link_dnssec, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "SetLinkDNSSEC", .signature = "is"
, .result = ((void*)0), .handler = bus_method_set_link_dnssec
, .offset = 0, }, }, }
,
1861 SD_BUS_METHOD("SetLinkDNSSECNegativeTrustAnchors", "ias", NULL, bus_method_set_link_dnssec_negative_trust_anchors, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "SetLinkDNSSECNegativeTrustAnchors"
, .signature = "ias", .result = ((void*)0), .handler = bus_method_set_link_dnssec_negative_trust_anchors
, .offset = 0, }, }, }
,
1862 SD_BUS_METHOD("RevertLink", "i", NULL, bus_method_revert_link, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "RevertLink", .signature = "i"
, .result = ((void*)0), .handler = bus_method_revert_link, .offset
= 0, }, }, }
,
1863
1864 SD_BUS_METHOD("RegisterService", "sssqqqaa{say}", "o", bus_method_register_service, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "RegisterService", .signature =
"sssqqqaa{say}", .result = "o", .handler = bus_method_register_service
, .offset = 0, }, }, }
,
1865 SD_BUS_METHOD("UnregisterService", "o", NULL, bus_method_unregister_service, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "UnregisterService", .signature
= "o", .result = ((void*)0), .handler = bus_method_unregister_service
, .offset = 0, }, }, }
,
1866 SD_BUS_VTABLE_END{ .type = _SD_BUS_VTABLE_END, .flags = 0, .x = { { 0 } }, },
1867};
1868
1869static int match_prepare_for_sleep(sd_bus_message *message, void *userdata, sd_bus_error *ret_error) {
1870 Manager *m = userdata;
1871 int b, r;
1872
1873 assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("message"), "../src/resolve/resolved-bus.c"
, 1873, __PRETTY_FUNCTION__); } while (0)
;
1874 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/resolve/resolved-bus.c", 1874
, __PRETTY_FUNCTION__); } while (0)
;
1875
1876 r = sd_bus_message_read(message, "b", &b);
1877 if (r < 0) {
1878 log_debug_errno(r, "Failed to parse PrepareForSleep signal: %m")({ int _level = ((7)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/resolve/resolved-bus.c", 1878, __func__, "Failed to parse PrepareForSleep signal: %m"
) : -abs(_e); })
;
1879 return 0;
1880 }
1881
1882 if (b)
1883 return 0;
1884
1885 log_debug("Coming back from suspend, verifying all RRs...")({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/resolve/resolved-bus.c", 1885, __func__, "Coming back from suspend, verifying all RRs..."
) : -abs(_e); })
;
1886
1887 manager_verify_all(m);
1888 return 0;
1889}
1890
1891int manager_connect_bus(Manager *m) {
1892 int r;
1893
1894 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/resolve/resolved-bus.c", 1894
, __PRETTY_FUNCTION__); } while (0)
;
1895
1896 if (m->bus)
1897 return 0;
1898
1899 r = bus_open_system_watch_bind_with_description(&m->bus, "bus-api-resolve");
1900 if (r < 0)
1901 return log_error_errno(r, "Failed to connect to system bus: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/resolve/resolved-bus.c", 1901, __func__, "Failed to connect to system bus: %m"
) : -abs(_e); })
;
1902
1903 r = sd_bus_add_object_vtable(m->bus, NULL((void*)0), "/org/freedesktop/resolve1", "org.freedesktop.resolve1.Manager", resolve_vtable, m);
1904 if (r < 0)
1905 return log_error_errno(r, "Failed to register object: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/resolve/resolved-bus.c", 1905, __func__, "Failed to register object: %m"
) : -abs(_e); })
;
1906
1907 r = sd_bus_add_fallback_vtable(m->bus, NULL((void*)0), "/org/freedesktop/resolve1/link", "org.freedesktop.resolve1.Link", link_vtable, link_object_find, m);
1908 if (r < 0)
1909 return log_error_errno(r, "Failed to register link objects: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/resolve/resolved-bus.c", 1909, __func__, "Failed to register link objects: %m"
) : -abs(_e); })
;
1910
1911 r = sd_bus_add_node_enumerator(m->bus, NULL((void*)0), "/org/freedesktop/resolve1/link", link_node_enumerator, m);
1912 if (r < 0)
1913 return log_error_errno(r, "Failed to register link enumerator: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/resolve/resolved-bus.c", 1913, __func__, "Failed to register link enumerator: %m"
) : -abs(_e); })
;
1914
1915 r = sd_bus_add_fallback_vtable(m->bus, NULL((void*)0), "/org/freedesktop/resolve1/dnssd", "org.freedesktop.resolve1.DnssdService", dnssd_vtable, dnssd_object_find, m);
1916 if (r < 0)
1917 return log_error_errno(r, "Failed to register dnssd objects: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/resolve/resolved-bus.c", 1917, __func__, "Failed to register dnssd objects: %m"
) : -abs(_e); })
;
1918
1919 r = sd_bus_add_node_enumerator(m->bus, NULL((void*)0), "/org/freedesktop/resolve1/dnssd", dnssd_node_enumerator, m);
1920 if (r < 0)
1921 return log_error_errno(r, "Failed to register dnssd enumerator: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/resolve/resolved-bus.c", 1921, __func__, "Failed to register dnssd enumerator: %m"
) : -abs(_e); })
;
1922
1923 r = bus_request_name_async_may_reload_dbus(m->bus, NULL((void*)0), "org.freedesktop.resolve1", 0, NULL((void*)0));
1924 if (r < 0)
1925 return log_error_errno(r, "Failed to request name: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/resolve/resolved-bus.c", 1925, __func__, "Failed to request name: %m"
) : -abs(_e); })
;
1926
1927 r = sd_bus_attach_event(m->bus, m->event, 0);
1928 if (r < 0)
1929 return log_error_errno(r, "Failed to attach bus to event loop: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/resolve/resolved-bus.c", 1929, __func__, "Failed to attach bus to event loop: %m"
) : -abs(_e); })
;
1930
1931 r = sd_bus_match_signal_async(
1932 m->bus,
1933 &m->prepare_for_sleep_slot,
1934 "org.freedesktop.login1",
1935 "/org/freedesktop/login1",
1936 "org.freedesktop.login1.Manager",
1937 "PrepareForSleep",
1938 match_prepare_for_sleep,
1939 NULL((void*)0),
1940 m);
1941 if (r < 0)
1942 log_warning_errno(r, "Failed to request match for PrepareForSleep, ignoring: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/resolve/resolved-bus.c", 1942, __func__, "Failed to request match for PrepareForSleep, ignoring: %m"
) : -abs(_e); })
;
1943
1944 return 0;
1945}