Bug Summary

File:build-scan/../src/resolve/resolved-link-bus.c
Warning:line 715, column 33
Potential leak of memory pointed to by 'l'

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-link-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-link-bus.c
1/* SPDX-License-Identifier: LGPL-2.1+ */
2
3#include <net/if.h>
4#include <netinet/in.h>
5#include <sys/capability.h>
6
7#include "alloc-util.h"
8#include "bus-common-errors.h"
9#include "bus-util.h"
10#include "parse-util.h"
11#include "resolve-util.h"
12#include "resolved-bus.h"
13#include "resolved-link-bus.h"
14#include "resolved-resolv-conf.h"
15#include "strv.h"
16#include "user-util.h"
17
18static BUS_DEFINE_PROPERTY_GET(property_get_dnssec_supported, "b", Link, link_dnssec_supported)int 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) { Link *data = userdata
; do { if ((__builtin_expect(!!(!(bus)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("bus"), "../src/resolve/resolved-link-bus.c"
, 18, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect
(!!(!(reply)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD,
("reply"), "../src/resolve/resolved-link-bus.c", 18, __PRETTY_FUNCTION__
); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("data"), "../src/resolve/resolved-link-bus.c"
, 18, __PRETTY_FUNCTION__); } while (0); return sd_bus_message_append
(reply, "b", (link_dnssec_supported(data))); }
;
19static BUS_DEFINE_PROPERTY_GET2(property_get_dnssec_mode, "s", Link, link_get_dnssec_mode, dnssec_mode_to_string)int 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) { Link *data = userdata
; do { if ((__builtin_expect(!!(!(bus)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("bus"), "../src/resolve/resolved-link-bus.c"
, 19, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect
(!!(!(reply)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD,
("reply"), "../src/resolve/resolved-link-bus.c", 19, __PRETTY_FUNCTION__
); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("data"), "../src/resolve/resolved-link-bus.c"
, 19, __PRETTY_FUNCTION__); } while (0); return sd_bus_message_append
(reply, "s", dnssec_mode_to_string(link_get_dnssec_mode(data)
)); }
;
20
21static int property_get_dns_over_tls_mode(
22 sd_bus *bus,
23 const char *path,
24 const char *interface,
25 const char *property,
26 sd_bus_message *reply,
27 void *userdata,
28 sd_bus_error *error) {
29
30 Link *l = userdata;
31
32 assert(reply)do { if ((__builtin_expect(!!(!(reply)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("reply"), "../src/resolve/resolved-link-bus.c"
, 32, __PRETTY_FUNCTION__); } while (0)
;
33 assert(l)do { if ((__builtin_expect(!!(!(l)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("l"), "../src/resolve/resolved-link-bus.c"
, 33, __PRETTY_FUNCTION__); } while (0)
;
34
35 return sd_bus_message_append(reply, "s", dns_over_tls_mode_to_string(link_get_dns_over_tls_mode(l)));
36}
37
38static int property_get_dns(
39 sd_bus *bus,
40 const char *path,
41 const char *interface,
42 const char *property,
43 sd_bus_message *reply,
44 void *userdata,
45 sd_bus_error *error) {
46
47 Link *l = userdata;
48 DnsServer *s;
49 int r;
50
51 assert(reply)do { if ((__builtin_expect(!!(!(reply)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("reply"), "../src/resolve/resolved-link-bus.c"
, 51, __PRETTY_FUNCTION__); } while (0)
;
52 assert(l)do { if ((__builtin_expect(!!(!(l)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("l"), "../src/resolve/resolved-link-bus.c"
, 52, __PRETTY_FUNCTION__); } while (0)
;
53
54 r = sd_bus_message_open_container(reply, 'a', "(iay)");
55 if (r < 0)
56 return r;
57
58 LIST_FOREACH(servers, s, l->dns_servers)for ((s) = (l->dns_servers); (s); (s) = (s)->servers_next
)
{
59 r = bus_dns_server_append(reply, s, false0);
60 if (r < 0)
61 return r;
62 }
63
64 return sd_bus_message_close_container(reply);
65}
66
67static int property_get_current_dns_server(
68 sd_bus *bus,
69 const char *path,
70 const char *interface,
71 const char *property,
72 sd_bus_message *reply,
73 void *userdata,
74 sd_bus_error *error) {
75
76 DnsServer *s;
77
78 assert(reply)do { if ((__builtin_expect(!!(!(reply)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("reply"), "../src/resolve/resolved-link-bus.c"
, 78, __PRETTY_FUNCTION__); } while (0)
;
79 assert(userdata)do { if ((__builtin_expect(!!(!(userdata)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("userdata"), "../src/resolve/resolved-link-bus.c"
, 79, __PRETTY_FUNCTION__); } while (0)
;
80
81 s = *(DnsServer **) userdata;
82
83 return bus_dns_server_append(reply, s, false0);
84}
85
86static int property_get_domains(
87 sd_bus *bus,
88 const char *path,
89 const char *interface,
90 const char *property,
91 sd_bus_message *reply,
92 void *userdata,
93 sd_bus_error *error) {
94
95 Link *l = userdata;
96 DnsSearchDomain *d;
97 int r;
98
99 assert(reply)do { if ((__builtin_expect(!!(!(reply)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("reply"), "../src/resolve/resolved-link-bus.c"
, 99, __PRETTY_FUNCTION__); } while (0)
;
100 assert(l)do { if ((__builtin_expect(!!(!(l)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("l"), "../src/resolve/resolved-link-bus.c"
, 100, __PRETTY_FUNCTION__); } while (0)
;
101
102 r = sd_bus_message_open_container(reply, 'a', "(sb)");
103 if (r < 0)
104 return r;
105
106 LIST_FOREACH(domains, d, l->search_domains)for ((d) = (l->search_domains); (d); (d) = (d)->domains_next
)
{
107 r = sd_bus_message_append(reply, "(sb)", d->name, d->route_only);
108 if (r < 0)
109 return r;
110 }
111
112 return sd_bus_message_close_container(reply);
113}
114
115static int property_get_scopes_mask(
116 sd_bus *bus,
117 const char *path,
118 const char *interface,
119 const char *property,
120 sd_bus_message *reply,
121 void *userdata,
122 sd_bus_error *error) {
123
124 Link *l = userdata;
125 uint64_t mask;
126
127 assert(reply)do { if ((__builtin_expect(!!(!(reply)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("reply"), "../src/resolve/resolved-link-bus.c"
, 127, __PRETTY_FUNCTION__); } while (0)
;
128 assert(l)do { if ((__builtin_expect(!!(!(l)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("l"), "../src/resolve/resolved-link-bus.c"
, 128, __PRETTY_FUNCTION__); } while (0)
;
129
130 mask = (l->unicast_scope ? SD_RESOLVED_DNS(1UL << 0) : 0) |
131 (l->llmnr_ipv4_scope ? SD_RESOLVED_LLMNR_IPV4(1UL << 1) : 0) |
132 (l->llmnr_ipv6_scope ? SD_RESOLVED_LLMNR_IPV6(1UL << 2) : 0) |
133 (l->mdns_ipv4_scope ? SD_RESOLVED_MDNS_IPV4(1UL << 3) : 0) |
134 (l->mdns_ipv6_scope ? SD_RESOLVED_MDNS_IPV6(1UL << 4) : 0);
135
136 return sd_bus_message_append(reply, "t", mask);
137}
138
139static int property_get_ntas(
140 sd_bus *bus,
141 const char *path,
142 const char *interface,
143 const char *property,
144 sd_bus_message *reply,
145 void *userdata,
146 sd_bus_error *error) {
147
148 Link *l = userdata;
149 const char *name;
150 Iterator i;
151 int r;
152
153 assert(reply)do { if ((__builtin_expect(!!(!(reply)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("reply"), "../src/resolve/resolved-link-bus.c"
, 153, __PRETTY_FUNCTION__); } while (0)
;
154 assert(l)do { if ((__builtin_expect(!!(!(l)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("l"), "../src/resolve/resolved-link-bus.c"
, 154, __PRETTY_FUNCTION__); } while (0)
;
155
156 r = sd_bus_message_open_container(reply, 'a', "s");
157 if (r < 0)
158 return r;
159
160 SET_FOREACH(name, l->dnssec_negative_trust_anchors, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), .
next_key = ((void*)0) }); set_iterate((l->dnssec_negative_trust_anchors
), &(i), (void**)&(name)); )
{
161 r = sd_bus_message_append(reply, "s", name);
162 if (r < 0)
163 return r;
164 }
165
166 return sd_bus_message_close_container(reply);
167}
168
169static int verify_unmanaged_link(Link *l, sd_bus_error *error) {
170 assert(l)do { if ((__builtin_expect(!!(!(l)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("l"), "../src/resolve/resolved-link-bus.c"
, 170, __PRETTY_FUNCTION__); } while (0)
;
171
172 if (l->flags & IFF_LOOPBACKIFF_LOOPBACK)
173 return sd_bus_error_setf(error, BUS_ERROR_LINK_BUSY"org.freedesktop.resolve1.LinkBusy", "Link %s is loopback device.", l->name);
174 if (l->is_managed)
175 return sd_bus_error_setf(error, BUS_ERROR_LINK_BUSY"org.freedesktop.resolve1.LinkBusy", "Link %s is managed.", l->name);
176
177 return 0;
178}
179
180int bus_link_method_set_dns_servers(sd_bus_message *message, void *userdata, sd_bus_error *error) {
181 _cleanup_free___attribute__((cleanup(freep))) struct in_addr_data *dns = NULL((void*)0);
182 size_t allocated = 0, n = 0;
183 Link *l = userdata;
184 unsigned i;
185 int r;
186
187 assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("message"), "../src/resolve/resolved-link-bus.c"
, 187, __PRETTY_FUNCTION__); } while (0)
;
188 assert(l)do { if ((__builtin_expect(!!(!(l)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("l"), "../src/resolve/resolved-link-bus.c"
, 188, __PRETTY_FUNCTION__); } while (0)
;
189
190 r = verify_unmanaged_link(l, error);
191 if (r < 0)
192 return r;
193
194 r = sd_bus_message_enter_container(message, 'a', "(iay)");
195 if (r < 0)
196 return r;
197
198 for (;;) {
199 int family;
200 size_t sz;
201 const void *d;
202
203 assert_cc(sizeof(int) == sizeof(int32_t))GCC diagnostic push ; GCC diagnostic ignored "-Wdeclaration-after-statement"
; struct _assert_struct_22 { char x[(sizeof(int) == sizeof(int32_t
)) ? 0 : -1]; }; GCC diagnostic pop
;
204
205 r = sd_bus_message_enter_container(message, 'r', "iay");
206 if (r < 0)
207 return r;
208 if (r == 0)
209 break;
210
211 r = sd_bus_message_read(message, "i", &family);
212 if (r < 0)
213 return r;
214
215 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; })
)
216 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Unknown address family %i", family);
217
218 r = sd_bus_message_read_array(message, 'y', &d, &sz);
219 if (r < 0)
220 return r;
221 if (sz != FAMILY_ADDRESS_SIZE(family))
222 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid address size");
223
224 if (!dns_server_address_valid(family, d))
225 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid DNS server address");
226
227 r = sd_bus_message_exit_container(message);
228 if (r < 0)
229 return r;
230
231 if (!GREEDY_REALLOC(dns, allocated, n+1)greedy_realloc((void**) &(dns), &(allocated), (n+1), sizeof
((dns)[0]))
)
232 return -ENOMEM12;
233
234 dns[n].family = family;
235 memcpy(&dns[n].address, d, sz);
236 n++;
237 }
238
239 r = sd_bus_message_exit_container(message);
240 if (r < 0)
241 return r;
242
243 r = bus_verify_polkit_async(message, CAP_NET_ADMIN12,
244 "org.freedesktop.resolve1.set-dns-servers",
245 NULL((void*)0), true1, UID_INVALID((uid_t) -1),
246 &l->manager->polkit_registry, error);
247 if (r < 0)
248 return r;
249 if (r == 0)
250 return 1; /* Polkit will call us back */
251
252 dns_server_mark_all(l->dns_servers);
253
254 for (i = 0; i < n; i++) {
255 DnsServer *s;
256
257 s = dns_server_find(l->dns_servers, dns[i].family, &dns[i].address, 0);
258 if (s)
259 dns_server_move_back_and_unmark(s);
260 else {
261 r = dns_server_new(l->manager, NULL((void*)0), DNS_SERVER_LINK, l, dns[i].family, &dns[i].address, 0);
262 if (r < 0)
263 goto clear;
264 }
265
266 }
267
268 dns_server_unlink_marked(l->dns_servers);
269 link_allocate_scopes(l);
270
271 (void) link_save_user(l);
272 (void) manager_write_resolv_conf(l->manager);
273
274 return sd_bus_reply_method_return(message, NULL((void*)0));
275
276clear:
277 dns_server_unlink_all(l->dns_servers);
278 return r;
279}
280
281int bus_link_method_set_domains(sd_bus_message *message, void *userdata, sd_bus_error *error) {
282 Link *l = userdata;
283 int r;
284
285 assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("message"), "../src/resolve/resolved-link-bus.c"
, 285, __PRETTY_FUNCTION__); } while (0)
;
286 assert(l)do { if ((__builtin_expect(!!(!(l)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("l"), "../src/resolve/resolved-link-bus.c"
, 286, __PRETTY_FUNCTION__); } while (0)
;
287
288 r = verify_unmanaged_link(l, error);
289 if (r < 0)
290 return r;
291
292 r = sd_bus_message_enter_container(message, 'a', "(sb)");
293 if (r < 0)
294 return r;
295
296 for (;;) {
297 const char *name;
298 int route_only;
299
300 r = sd_bus_message_read(message, "(sb)", &name, &route_only);
301 if (r < 0)
302 return r;
303 if (r == 0)
304 break;
305
306 r = dns_name_is_valid(name);
307 if (r < 0)
308 return r;
309 if (r == 0)
310 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid search domain %s", name);
311 if (!route_only && dns_name_is_root(name))
312 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Root domain is not suitable as search domain");
313 }
314
315 r = sd_bus_message_rewind(message, false0);
316 if (r < 0)
317 return r;
318
319 r = bus_verify_polkit_async(message, CAP_NET_ADMIN12,
320 "org.freedesktop.resolve1.set-domains",
321 NULL((void*)0), true1, UID_INVALID((uid_t) -1),
322 &l->manager->polkit_registry, error);
323 if (r < 0)
324 return r;
325 if (r == 0)
326 return 1; /* Polkit will call us back */
327
328 dns_search_domain_mark_all(l->search_domains);
329
330 for (;;) {
331 DnsSearchDomain *d;
332 const char *name;
333 int route_only;
334
335 r = sd_bus_message_read(message, "(sb)", &name, &route_only);
336 if (r < 0)
337 goto clear;
338 if (r == 0)
339 break;
340
341 r = dns_search_domain_find(l->search_domains, name, &d);
342 if (r < 0)
343 goto clear;
344
345 if (r > 0)
346 dns_search_domain_move_back_and_unmark(d);
347 else {
348 r = dns_search_domain_new(l->manager, &d, DNS_SEARCH_DOMAIN_LINK, l, name);
349 if (r < 0)
350 goto clear;
351 }
352
353 d->route_only = route_only;
354 }
355
356 r = sd_bus_message_exit_container(message);
357 if (r < 0)
358 goto clear;
359
360 dns_search_domain_unlink_marked(l->search_domains);
361
362 (void) link_save_user(l);
363 (void) manager_write_resolv_conf(l->manager);
364
365 return sd_bus_reply_method_return(message, NULL((void*)0));
366
367clear:
368 dns_search_domain_unlink_all(l->search_domains);
369 return r;
370}
371
372int bus_link_method_set_llmnr(sd_bus_message *message, void *userdata, sd_bus_error *error) {
373 Link *l = userdata;
374 ResolveSupport mode;
375 const char *llmnr;
376 int r;
377
378 assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("message"), "../src/resolve/resolved-link-bus.c"
, 378, __PRETTY_FUNCTION__); } while (0)
;
379 assert(l)do { if ((__builtin_expect(!!(!(l)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("l"), "../src/resolve/resolved-link-bus.c"
, 379, __PRETTY_FUNCTION__); } while (0)
;
380
381 r = verify_unmanaged_link(l, error);
382 if (r < 0)
383 return r;
384
385 r = sd_bus_message_read(message, "s", &llmnr);
386 if (r < 0)
387 return r;
388
389 if (isempty(llmnr))
390 mode = RESOLVE_SUPPORT_YES;
391 else {
392 mode = resolve_support_from_string(llmnr);
393 if (mode < 0)
394 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid LLMNR setting: %s", llmnr);
395 }
396
397 r = bus_verify_polkit_async(message, CAP_NET_ADMIN12,
398 "org.freedesktop.resolve1.set-llmnr",
399 NULL((void*)0), true1, UID_INVALID((uid_t) -1),
400 &l->manager->polkit_registry, error);
401 if (r < 0)
402 return r;
403 if (r == 0)
404 return 1; /* Polkit will call us back */
405
406 l->llmnr_support = mode;
407 link_allocate_scopes(l);
408 link_add_rrs(l, false0);
409
410 (void) link_save_user(l);
411
412 return sd_bus_reply_method_return(message, NULL((void*)0));
413}
414
415int bus_link_method_set_mdns(sd_bus_message *message, void *userdata, sd_bus_error *error) {
416 Link *l = userdata;
417 ResolveSupport mode;
418 const char *mdns;
419 int r;
420
421 assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("message"), "../src/resolve/resolved-link-bus.c"
, 421, __PRETTY_FUNCTION__); } while (0)
;
422 assert(l)do { if ((__builtin_expect(!!(!(l)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("l"), "../src/resolve/resolved-link-bus.c"
, 422, __PRETTY_FUNCTION__); } while (0)
;
423
424 r = verify_unmanaged_link(l, error);
425 if (r < 0)
426 return r;
427
428 r = sd_bus_message_read(message, "s", &mdns);
429 if (r < 0)
430 return r;
431
432 if (isempty(mdns))
433 mode = RESOLVE_SUPPORT_NO;
434 else {
435 mode = resolve_support_from_string(mdns);
436 if (mode < 0)
437 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid MulticastDNS setting: %s", mdns);
438 }
439
440 r = bus_verify_polkit_async(message, CAP_NET_ADMIN12,
441 "org.freedesktop.resolve1.set-mdns",
442 NULL((void*)0), true1, UID_INVALID((uid_t) -1),
443 &l->manager->polkit_registry, error);
444 if (r < 0)
445 return r;
446 if (r == 0)
447 return 1; /* Polkit will call us back */
448
449 l->mdns_support = mode;
450 link_allocate_scopes(l);
451 link_add_rrs(l, false0);
452
453 (void) link_save_user(l);
454
455 return sd_bus_reply_method_return(message, NULL((void*)0));
456}
457
458int bus_link_method_set_dns_over_tls(sd_bus_message *message, void *userdata, sd_bus_error *error) {
459 Link *l = userdata;
460 const char *dns_over_tls;
461 DnsOverTlsMode mode;
462 int r;
463
464 assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("message"), "../src/resolve/resolved-link-bus.c"
, 464, __PRETTY_FUNCTION__); } while (0)
;
465 assert(l)do { if ((__builtin_expect(!!(!(l)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("l"), "../src/resolve/resolved-link-bus.c"
, 465, __PRETTY_FUNCTION__); } while (0)
;
466
467 r = verify_unmanaged_link(l, error);
468 if (r < 0)
469 return r;
470
471 r = sd_bus_message_read(message, "s", &dns_over_tls);
472 if (r < 0)
473 return r;
474
475 if (isempty(dns_over_tls))
476 mode = _DNS_OVER_TLS_MODE_INVALID;
477 else {
478 mode = dns_over_tls_mode_from_string(dns_over_tls);
479 if (mode < 0)
480 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid DNSOverTLS setting: %s", dns_over_tls);
481 }
482
483 r = bus_verify_polkit_async(message, CAP_NET_ADMIN12,
484 "org.freedesktop.resolve1.set-dns-over-tls",
485 NULL((void*)0), true1, UID_INVALID((uid_t) -1),
486 &l->manager->polkit_registry, error);
487 if (r < 0)
488 return r;
489 if (r == 0)
490 return 1; /* Polkit will call us back */
491
492 link_set_dns_over_tls_mode(l, mode);
493
494 (void) link_save_user(l);
495
496 return sd_bus_reply_method_return(message, NULL((void*)0));
497}
498
499int bus_link_method_set_dnssec(sd_bus_message *message, void *userdata, sd_bus_error *error) {
500 Link *l = userdata;
501 const char *dnssec;
502 DnssecMode mode;
503 int r;
504
505 assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("message"), "../src/resolve/resolved-link-bus.c"
, 505, __PRETTY_FUNCTION__); } while (0)
;
506 assert(l)do { if ((__builtin_expect(!!(!(l)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("l"), "../src/resolve/resolved-link-bus.c"
, 506, __PRETTY_FUNCTION__); } while (0)
;
507
508 r = verify_unmanaged_link(l, error);
509 if (r < 0)
510 return r;
511
512 r = sd_bus_message_read(message, "s", &dnssec);
513 if (r < 0)
514 return r;
515
516 if (isempty(dnssec))
517 mode = _DNSSEC_MODE_INVALID;
518 else {
519 mode = dnssec_mode_from_string(dnssec);
520 if (mode < 0)
521 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid DNSSEC setting: %s", dnssec);
522 }
523
524 r = bus_verify_polkit_async(message, CAP_NET_ADMIN12,
525 "org.freedesktop.resolve1.set-dnssec",
526 NULL((void*)0), true1, UID_INVALID((uid_t) -1),
527 &l->manager->polkit_registry, error);
528 if (r < 0)
529 return r;
530 if (r == 0)
531 return 1; /* Polkit will call us back */
532
533 link_set_dnssec_mode(l, mode);
534
535 (void) link_save_user(l);
536
537 return sd_bus_reply_method_return(message, NULL((void*)0));
538}
539
540int bus_link_method_set_dnssec_negative_trust_anchors(sd_bus_message *message, void *userdata, sd_bus_error *error) {
541 _cleanup_set_free_free___attribute__((cleanup(set_free_freep))) Set *ns = NULL((void*)0);
542 _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **ntas = NULL((void*)0);
543 Link *l = userdata;
544 int r;
545 char **i;
546
547 assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("message"), "../src/resolve/resolved-link-bus.c"
, 547, __PRETTY_FUNCTION__); } while (0)
;
548 assert(l)do { if ((__builtin_expect(!!(!(l)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("l"), "../src/resolve/resolved-link-bus.c"
, 548, __PRETTY_FUNCTION__); } while (0)
;
549
550 r = verify_unmanaged_link(l, error);
551 if (r < 0)
552 return r;
553
554 ns = set_new(&dns_name_hash_ops)internal_set_new(&dns_name_hash_ops );
555 if (!ns)
556 return -ENOMEM12;
557
558 r = sd_bus_message_read_strv(message, &ntas);
559 if (r < 0)
560 return r;
561
562 STRV_FOREACH(i, ntas)for ((i) = (ntas); (i) && *(i); (i)++) {
563 r = dns_name_is_valid(*i);
564 if (r < 0)
565 return r;
566 if (r == 0)
567 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs",
568 "Invalid negative trust anchor domain: %s", *i);
569
570 r = set_put_strdup(ns, *i);
571 if (r < 0)
572 return r;
573 }
574
575 r = bus_verify_polkit_async(message, CAP_NET_ADMIN12,
576 "org.freedesktop.resolve1.set-dnssec-negative-trust-anchors",
577 NULL((void*)0), true1, UID_INVALID((uid_t) -1),
578 &l->manager->polkit_registry, error);
579 if (r < 0)
580 return r;
581 if (r == 0)
582 return 1; /* Polkit will call us back */
583
584 set_free_free(l->dnssec_negative_trust_anchors);
585 l->dnssec_negative_trust_anchors = TAKE_PTR(ns)({ typeof(ns) _ptr_ = (ns); (ns) = ((void*)0); _ptr_; });
586
587 (void) link_save_user(l);
588
589 return sd_bus_reply_method_return(message, NULL((void*)0));
590}
591
592int bus_link_method_revert(sd_bus_message *message, void *userdata, sd_bus_error *error) {
593 Link *l = userdata;
594 int r;
595
596 assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("message"), "../src/resolve/resolved-link-bus.c"
, 596, __PRETTY_FUNCTION__); } while (0)
;
597 assert(l)do { if ((__builtin_expect(!!(!(l)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("l"), "../src/resolve/resolved-link-bus.c"
, 597, __PRETTY_FUNCTION__); } while (0)
;
598
599 r = verify_unmanaged_link(l, error);
600 if (r < 0)
601 return r;
602
603 r = bus_verify_polkit_async(message, CAP_NET_ADMIN12,
604 "org.freedesktop.resolve1.revert",
605 NULL((void*)0), true1, UID_INVALID((uid_t) -1),
606 &l->manager->polkit_registry, error);
607 if (r < 0)
608 return r;
609 if (r == 0)
610 return 1; /* Polkit will call us back */
611
612 link_flush_settings(l);
613 link_allocate_scopes(l);
614 link_add_rrs(l, false0);
615
616 (void) link_save_user(l);
617 (void) manager_write_resolv_conf(l->manager);
618
619 return sd_bus_reply_method_return(message, NULL((void*)0));
620}
621
622const sd_bus_vtable link_vtable[] = {
623 SD_BUS_VTABLE_START(0){ .type = _SD_BUS_VTABLE_START, .flags = 0, .x = { .start = {
.element_size = sizeof(sd_bus_vtable) }, }, }
,
624
625 SD_BUS_PROPERTY("ScopesMask", "t", property_get_scopes_mask, 0, 0){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = 0, .x = { .property
= { .member = "ScopesMask", .signature = "t", .get = property_get_scopes_mask
, .set = ((void*)0), .offset = 0, }, }, }
,
626 SD_BUS_PROPERTY("DNS", "a(iay)", property_get_dns, 0, 0){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = 0, .x = { .property
= { .member = "DNS", .signature = "a(iay)", .get = property_get_dns
, .set = ((void*)0), .offset = 0, }, }, }
,
627 SD_BUS_PROPERTY("CurrentDNSServer", "(iay)", property_get_current_dns_server, offsetof(Link, current_dns_server), 0){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = 0, .x = { .property
= { .member = "CurrentDNSServer", .signature = "(iay)", .get
= property_get_current_dns_server, .set = ((void*)0), .offset
= __builtin_offsetof(Link, current_dns_server), }, }, }
,
628 SD_BUS_PROPERTY("Domains", "a(sb)", property_get_domains, 0, 0){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = 0, .x = { .property
= { .member = "Domains", .signature = "a(sb)", .get = property_get_domains
, .set = ((void*)0), .offset = 0, }, }, }
,
629 SD_BUS_PROPERTY("LLMNR", "s", bus_property_get_resolve_support, offsetof(Link, 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(Link, llmnr_support
), }, }, }
,
630 SD_BUS_PROPERTY("MulticastDNS", "s", bus_property_get_resolve_support, offsetof(Link, 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(Link, mdns_support
), }, }, }
,
631 SD_BUS_PROPERTY("DNSOverTLS", "s", property_get_dns_over_tls_mode, 0, 0){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = 0, .x = { .property
= { .member = "DNSOverTLS", .signature = "s", .get = property_get_dns_over_tls_mode
, .set = ((void*)0), .offset = 0, }, }, }
,
632 SD_BUS_PROPERTY("DNSSEC", "s", property_get_dnssec_mode, 0, 0){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = 0, .x = { .property
= { .member = "DNSSEC", .signature = "s", .get = property_get_dnssec_mode
, .set = ((void*)0), .offset = 0, }, }, }
,
633 SD_BUS_PROPERTY("DNSSECNegativeTrustAnchors", "as", property_get_ntas, 0, 0){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = 0, .x = { .property
= { .member = "DNSSECNegativeTrustAnchors", .signature = "as"
, .get = property_get_ntas, .set = ((void*)0), .offset = 0, }
, }, }
,
634 SD_BUS_PROPERTY("DNSSECSupported", "b", property_get_dnssec_supported, 0, 0){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = 0, .x = { .property
= { .member = "DNSSECSupported", .signature = "b", .get = property_get_dnssec_supported
, .set = ((void*)0), .offset = 0, }, }, }
,
635
636 SD_BUS_METHOD("SetDNS", "a(iay)", NULL, bus_link_method_set_dns_servers, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "SetDNS", .signature = "a(iay)"
, .result = ((void*)0), .handler = bus_link_method_set_dns_servers
, .offset = 0, }, }, }
,
637 SD_BUS_METHOD("SetDomains", "a(sb)", NULL, bus_link_method_set_domains, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "SetDomains", .signature = "a(sb)"
, .result = ((void*)0), .handler = bus_link_method_set_domains
, .offset = 0, }, }, }
,
638 SD_BUS_METHOD("SetLLMNR", "s", NULL, bus_link_method_set_llmnr, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "SetLLMNR", .signature = "s", .
result = ((void*)0), .handler = bus_link_method_set_llmnr, .offset
= 0, }, }, }
,
639 SD_BUS_METHOD("SetMulticastDNS", "s", NULL, bus_link_method_set_mdns, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "SetMulticastDNS", .signature =
"s", .result = ((void*)0), .handler = bus_link_method_set_mdns
, .offset = 0, }, }, }
,
640 SD_BUS_METHOD("SetDNSOverTLS", "s", NULL, bus_link_method_set_dns_over_tls, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "SetDNSOverTLS", .signature = "s"
, .result = ((void*)0), .handler = bus_link_method_set_dns_over_tls
, .offset = 0, }, }, }
,
641 SD_BUS_METHOD("SetDNSSEC", "s", NULL, bus_link_method_set_dnssec, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "SetDNSSEC", .signature = "s",
.result = ((void*)0), .handler = bus_link_method_set_dnssec,
.offset = 0, }, }, }
,
642 SD_BUS_METHOD("SetDNSSECNegativeTrustAnchors", "as", NULL, bus_link_method_set_dnssec_negative_trust_anchors, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "SetDNSSECNegativeTrustAnchors"
, .signature = "as", .result = ((void*)0), .handler = bus_link_method_set_dnssec_negative_trust_anchors
, .offset = 0, }, }, }
,
643 SD_BUS_METHOD("Revert", NULL, NULL, bus_link_method_revert, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED
, .x = { .method = { .member = "Revert", .signature = ((void*
)0), .result = ((void*)0), .handler = bus_link_method_revert,
.offset = 0, }, }, }
,
644
645 SD_BUS_VTABLE_END{ .type = _SD_BUS_VTABLE_END, .flags = 0, .x = { { 0 } }, }
646};
647
648int link_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
649 _cleanup_free___attribute__((cleanup(freep))) char *e = NULL((void*)0);
650 Manager *m = userdata;
651 int ifindex;
652 Link *link;
653 int r;
654
655 assert(bus)do { if ((__builtin_expect(!!(!(bus)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("bus"), "../src/resolve/resolved-link-bus.c"
, 655, __PRETTY_FUNCTION__); } while (0)
;
656 assert(path)do { if ((__builtin_expect(!!(!(path)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("path"), "../src/resolve/resolved-link-bus.c"
, 656, __PRETTY_FUNCTION__); } while (0)
;
657 assert(interface)do { if ((__builtin_expect(!!(!(interface)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("interface"), "../src/resolve/resolved-link-bus.c"
, 657, __PRETTY_FUNCTION__); } while (0)
;
658 assert(found)do { if ((__builtin_expect(!!(!(found)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("found"), "../src/resolve/resolved-link-bus.c"
, 658, __PRETTY_FUNCTION__); } while (0)
;
659 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/resolve/resolved-link-bus.c"
, 659, __PRETTY_FUNCTION__); } while (0)
;
660
661 r = sd_bus_path_decode(path, "/org/freedesktop/resolve1/link", &e);
662 if (r <= 0)
663 return 0;
664
665 r = parse_ifindex(e, &ifindex);
666 if (r < 0)
667 return 0;
668
669 link = hashmap_get(m->links, INT_TO_PTR(ifindex)((void *) ((intptr_t) (ifindex))));
670 if (!link)
671 return 0;
672
673 *found = link;
674 return 1;
675}
676
677char *link_bus_path(Link *link) {
678 _cleanup_free___attribute__((cleanup(freep))) char *ifindex = NULL((void*)0);
679 char *p;
680 int r;
681
682 assert(link)do { if ((__builtin_expect(!!(!(link)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("link"), "../src/resolve/resolved-link-bus.c"
, 682, __PRETTY_FUNCTION__); } while (0)
;
683
684 if (asprintf(&ifindex, "%i", link->ifindex) < 0)
685 return NULL((void*)0);
686
687 r = sd_bus_path_encode("/org/freedesktop/resolve1/link", ifindex, &p);
688 if (r < 0)
689 return NULL((void*)0);
690
691 return p;
692}
693
694int link_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
695 _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **l = NULL((void*)0);
696 Manager *m = userdata;
697 Link *link;
698 Iterator i;
699 unsigned c = 0;
700
701 assert(bus)do { if ((__builtin_expect(!!(!(bus)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("bus"), "../src/resolve/resolved-link-bus.c"
, 701, __PRETTY_FUNCTION__); } while (0)
;
1
Assuming 'bus' is non-null
2
Taking false branch
3
Loop condition is false. Exiting loop
702 assert(path)do { if ((__builtin_expect(!!(!(path)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("path"), "../src/resolve/resolved-link-bus.c"
, 702, __PRETTY_FUNCTION__); } while (0)
;
4
Assuming 'path' is non-null
5
Taking false branch
6
Loop condition is false. Exiting loop
703 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/resolve/resolved-link-bus.c"
, 703, __PRETTY_FUNCTION__); } while (0)
;
7
Assuming 'm' is non-null
8
Taking false branch
9
Loop condition is false. Exiting loop
704 assert(nodes)do { if ((__builtin_expect(!!(!(nodes)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("nodes"), "../src/resolve/resolved-link-bus.c"
, 704, __PRETTY_FUNCTION__); } while (0)
;
10
Assuming 'nodes' is non-null
11
Taking false branch
12
Loop condition is false. Exiting loop
705
706 l = new0(char*, hashmap_size(m->links) + 1)((char**) calloc((hashmap_size(m->links) + 1), sizeof(char
*)))
;
13
Memory is allocated
707 if (!l)
14
Assuming 'l' is non-null
15
Taking false branch
708 return -ENOMEM12;
709
710 HASHMAP_FOREACH(link, m->links, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), .
next_key = ((void*)0) }); hashmap_iterate((m->links), &
(i), (void**)&(link), ((void*)0)); )
{
16
Loop condition is true. Entering loop body
711 char *p;
712
713 p = link_bus_path(link);
714 if (!p
16.1
'p' is null
)
17
Taking true branch
715 return -ENOMEM12;
18
Potential leak of memory pointed to by 'l'
716
717 l[c++] = p;
718 }
719
720 l[c] = NULL((void*)0);
721 *nodes = TAKE_PTR(l)({ typeof(l) _ptr_ = (l); (l) = ((void*)0); _ptr_; });
722
723 return 1;
724}